common-functions-source.sh 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  1. # -----------------------------------------------------------------------------
  2. # Helper script used in the second edition of the xPack build
  3. # scripts. As the name implies, it should contain only functions and
  4. # should be included with 'source' by the build scripts (both native
  5. # and container).
  6. # -----------------------------------------------------------------------------
  7. # Default empty definition, if XBB is available, it should
  8. # redefine it.
  9. function xbb_activate()
  10. {
  11. :
  12. }
  13. # Add the freshly built binaries.
  14. function xbb_activate_installed_bin()
  15. {
  16. # Add the XBB bin to the PATH.
  17. PATH="${LIBS_INSTALL_FOLDER_PATH}/bin:${PATH}"
  18. # Add the XBB lib to the LD_LIBRARY_PATH.
  19. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib:${LD_LIBRARY_PATH}"
  20. if [ -d "${LIBS_INSTALL_FOLDER_PATH}/lib64" ]
  21. then
  22. # On 64-bit systems, add lib64 to the LD_LIBRARY_PATH.
  23. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib64:${LD_LIBRARY_PATH}"
  24. fi
  25. export PATH
  26. export LD_LIBRARY_PATH
  27. }
  28. # Add the freshly built headrs and libraries.
  29. function xbb_activate_installed_dev()
  30. {
  31. # Add XBB include in front of XBB_CPPFLAGS.
  32. XBB_CPPFLAGS="-I${LIBS_INSTALL_FOLDER_PATH}/include ${XBB_CPPFLAGS}"
  33. # Add XBB lib in front of XBB_LDFLAGS.
  34. XBB_LDFLAGS="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS}"
  35. XBB_LDFLAGS_LIB="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS_LIB}"
  36. XBB_LDFLAGS_APP="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS_APP}"
  37. XBB_LDFLAGS_APP_STATIC_GCC="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS_APP_STATIC_GCC}"
  38. # Add XBB lib in front of PKG_CONFIG_PATH.
  39. PKG_CONFIG_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}"
  40. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib:${LD_LIBRARY_PATH}"
  41. if [ -d "${LIBS_INSTALL_FOLDER_PATH}/lib64" ]
  42. then
  43. # For 64-bit systems, add XBB lib64 in front of paths.
  44. XBB_LDFLAGS="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_LIB}"
  45. XBB_LDFLAGS_LIB="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_LIB}"
  46. XBB_LDFLAGS_APP="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_APP}"
  47. XBB_LDFLAGS_APP_STATIC_GCC="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_APP_STATIC_GCC}"
  48. PKG_CONFIG_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib64/pkgconfig:${PKG_CONFIG_PATH}"
  49. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib64:${LD_LIBRARY_PATH}"
  50. fi
  51. export XBB_CPPFLAGS
  52. export XBB_LDFLAGS
  53. export XBB_LDFLAGS_LIB
  54. export XBB_LDFLAGS_APP
  55. export XBB_LDFLAGS_APP_STATIC_GCC
  56. export PKG_CONFIG_PATH
  57. export LD_LIBRARY_PATH
  58. }
  59. # -----------------------------------------------------------------------------
  60. function do_config_guess()
  61. {
  62. if [ -f "${XBB_FOLDER}/share/libtool/build-aux/config.guess" ]
  63. then
  64. BUILD="$(${XBB_FOLDER}/share/libtool/build-aux/config.guess)"
  65. elif [ -f "/usr/share/libtool/build-aux/config.guess" ]
  66. then
  67. BUILD="$(/usr/share/libtool/build-aux/config.guess)"
  68. elif [ -f "/usr/share/misc/config.guess" ]
  69. then
  70. BUILD="$(/usr/share/misc/config.guess)"
  71. else
  72. echo "Could not find config.guess."
  73. exit 1
  74. fi
  75. }
  76. function prepare_xbb_env()
  77. {
  78. # Defaults, to ensure the variables are defined.
  79. PATH="${PATH:-""}"
  80. LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-""}"
  81. # Without this, on 32-bit the bootstrap perl fails to find libcrypt.
  82. # LD_LIBRARY_PATH="/lib:${LD_LIBRARY_PATH}"
  83. if [ -f "${HOME}/opt/xbb/xbb-source.sh" ]
  84. then
  85. echo
  86. echo "Sourcing ${HOME}/opt/xbb/xbb-source.sh..."
  87. source "${HOME}/opt/xbb/xbb-source.sh"
  88. elif [ -f "${HOME}/opt/homebrew/xbb/xbb-source.sh" ]
  89. then
  90. # Deprecated, on macOS it was moved to HOME/opt/xbb
  91. echo
  92. echo "Sourcing ${HOME}/opt/homebrew/xbb/xbb-source.sh..."
  93. source "${HOME}/opt/homebrew/xbb/xbb-source.sh"
  94. elif [ -f "/opt/xbb/xbb-source.sh" ]
  95. then
  96. echo
  97. echo "Sourcing /opt/xbb/xbb-source.sh..."
  98. source "/opt/xbb/xbb-source.sh"
  99. fi
  100. TARGET_FOLDER_NAME="${TARGET_PLATFORM}-${TARGET_ARCH}"
  101. # Compute the BUILD/HOST/TARGET for configure.
  102. CROSS_COMPILE_PREFIX=""
  103. if [ "${TARGET_PLATFORM}" == "win32" ]
  104. then
  105. # For Windows targets, decide which cross toolchain to use.
  106. if [ ${TARGET_ARCH} == "x32" ]
  107. then
  108. CROSS_COMPILE_PREFIX="i686-w64-mingw32"
  109. elif [ ${TARGET_ARCH} == "x64" ]
  110. then
  111. CROSS_COMPILE_PREFIX="x86_64-w64-mingw32"
  112. fi
  113. do_config_guess
  114. HOST="${CROSS_COMPILE_PREFIX}"
  115. TARGET="${HOST}"
  116. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  117. then
  118. TARGET_BITS="64" # For now, only 64-bit macOS binaries
  119. do_config_guess
  120. HOST="${BUILD}"
  121. TARGET="${HOST}"
  122. elif [ "${TARGET_PLATFORM}" == "linux" ]
  123. then
  124. do_config_guess
  125. HOST="${BUILD}"
  126. TARGET="${HOST}"
  127. else
  128. echo "Unsupported target platform ${TARGET_PLATFORM}"
  129. exit 1
  130. fi
  131. if [ -f "/.dockerenv" ]
  132. then
  133. WORK_FOLDER_PATH="${CONTAINER_WORK_FOLDER_PATH}"
  134. DOWNLOAD_FOLDER_PATH="${CONTAINER_CACHE_FOLDER_PATH}"
  135. else
  136. WORK_FOLDER_PATH="${HOST_WORK_FOLDER_PATH}"
  137. DOWNLOAD_FOLDER_PATH="${HOST_CACHE_FOLDER_PATH}"
  138. fi
  139. # Develop builds use the host folder.
  140. BUILD_FOLDER_PATH="${WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/build"
  141. if [ -f "/.dockerenv" ]
  142. then
  143. if [ "${IS_DEVELOP}" != "y" ]
  144. then
  145. # Docker builds use a temporary folder.
  146. BUILD_FOLDER_PATH="/tmp/${TARGET_FOLDER_NAME}/build"
  147. fi
  148. fi
  149. LIBS_BUILD_FOLDER_PATH="${BUILD_FOLDER_PATH}/libs"
  150. mkdir -p "${LIBS_BUILD_FOLDER_PATH}"
  151. APP_BUILD_FOLDER_PATH="${BUILD_FOLDER_PATH}/${APP_LC_NAME}"
  152. # Do it later, only if needed.
  153. # mkdir -p "${APP_BUILD_FOLDER_PATH}"
  154. INSTALL_FOLDER_PATH="${WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install"
  155. LIBS_INSTALL_FOLDER_PATH="${INSTALL_FOLDER_PATH}/libs"
  156. mkdir -p "${LIBS_INSTALL_FOLDER_PATH}"
  157. APP_INSTALL_FOLDER_PATH="${INSTALL_FOLDER_PATH}/${APP_LC_NAME}"
  158. mkdir -p "${APP_INSTALL_FOLDER_PATH}"
  159. LOGS_FOLDER_NAME=${LOGS_FOLDER_NAME:-"logs"}
  160. LOGS_FOLDER_PATH="${WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/${LOGS_FOLDER_NAME}"
  161. mkdir -p "${LOGS_FOLDER_PATH}"
  162. DEPLOY_FOLDER_NAME=${DEPLOY_FOLDER_NAME:-"deploy"}
  163. DEPLOY_FOLDER_PATH="${WORK_FOLDER_PATH}/${DEPLOY_FOLDER_NAME}"
  164. # Do it later, only if needed.
  165. # mkdir -p "${DEPLOY_FOLDER_PATH}"
  166. DISTRO_INFO_NAME=${DISTRO_INFO_NAME:-"distro-info"}
  167. BUILD_GIT_PATH="${WORK_FOLDER_PATH}/build.git"
  168. # ---------------------------------------------------------------------------
  169. APP_PREFIX="${INSTALL_FOLDER_PATH}/${APP_LC_NAME}"
  170. # The documentation location is now the same on all platforms.
  171. APP_PREFIX_DOC="${APP_PREFIX}/share/doc"
  172. # ---------------------------------------------------------------------------
  173. SOURCES_FOLDER_PATH=${SOURCES_FOLDER_PATH:-"${WORK_FOLDER_PATH}/sources"}
  174. mkdir -p "${SOURCES_FOLDER_PATH}"
  175. # Empty defaults.
  176. IS_DEVELOP=${IS_DEVELOP:-""}
  177. IS_DEBUG=${IS_DEBUG:-""}
  178. WITH_PDF=${WITH_PDF:-""}
  179. WITH_HTML=${WITH_HTML:-""}
  180. # Redefine this to "y" to create files that include the architecture.
  181. HAS_NAME_ARCH=${HAS_NAME_ARCH:-""}
  182. # ---------------------------------------------------------------------------
  183. export PATH
  184. export LD_LIBRARY_PATH
  185. export SOURCES_FOLDER_PATH
  186. # libtool fails with the Ubuntu /bin/sh.
  187. export SHELL="/bin/bash"
  188. export CONFIG_SHELL="/bin/bash"
  189. }
  190. function prepare_xbb_extras()
  191. {
  192. # ---------------------------------------------------------------------------
  193. XBB_CPPFLAGS=""
  194. XBB_CFLAGS="-ffunction-sections -fdata-sections -m${TARGET_BITS} -pipe"
  195. XBB_CXXFLAGS="-ffunction-sections -fdata-sections -m${TARGET_BITS} -pipe"
  196. XBB_LDFLAGS=""
  197. if [ "${IS_DEBUG}" == "y" ]
  198. then
  199. XBB_CFLAGS+=" -g -O0"
  200. XBB_CXXFLAGS+=" -g -O0"
  201. XBB_LDFLAGS+=" -g -O0"
  202. else
  203. XBB_CFLAGS+=" -O2"
  204. XBB_CXXFLAGS+=" -O2"
  205. XBB_LDFLAGS+=" -O2"
  206. fi
  207. if [ "${TARGET_PLATFORM}" == "linux" ]
  208. then
  209. local which_gcc_7="$(xbb_activate; which "g++-7")"
  210. if [ ! -z "${which_gcc_7}" ]
  211. then
  212. CC="gcc-7"
  213. CXX="g++-7"
  214. else
  215. CC="gcc"
  216. CXX="g++"
  217. fi
  218. # Do not add -static here, it fails.
  219. # Do not try to link pthread statically, it must match the system glibc.
  220. XBB_LDFLAGS_LIB="${XBB_LDFLAGS}"
  221. XBB_LDFLAGS_APP="${XBB_LDFLAGS} -Wl,--gc-sections"
  222. XBB_LDFLAGS_APP_STATIC_GCC="${XBB_LDFLAGS_APP} -static-libgcc -static-libstdc++"
  223. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  224. then
  225. CC="gcc-7"
  226. CXX="g++-7"
  227. # Note: macOS linker ignores -static-libstdc++, so
  228. # libstdc++.6.dylib should be handled.
  229. XBB_LDFLAGS+=" -Wl,-macosx_version_min,10.10"
  230. XBB_LDFLAGS_LIB="${XBB_LDFLAGS}"
  231. XBB_LDFLAGS_APP="${XBB_LDFLAGS} -Wl,-dead_strip"
  232. XBB_LDFLAGS_APP_STATIC_GCC="${XBB_LDFLAGS_APP}"
  233. elif [ "${TARGET_PLATFORM}" == "win32" ]
  234. then
  235. # CRT_glob is from Arm script
  236. # -static avoids libwinpthread-1.dll
  237. # -static-libgcc avoids libgcc_s_sjlj-1.dll
  238. XBB_LDFLAGS_LIB="${XBB_LDFLAGS}"
  239. XBB_LDFLAGS_APP="${XBB_LDFLAGS} -Wl,--gc-sections"
  240. XBB_LDFLAGS_APP_STATIC_GCC="${XBB_LDFLAGS_APP} -static-libgcc -static-libstdc++"
  241. fi
  242. set +u
  243. if [ ! -z "${XBB_FOLDER}" -a -x "${XBB_FOLDER}/bin/pkg-config-verbose" ]
  244. then
  245. PKG_CONFIG="${XBB_FOLDER}/bin/pkg-config-verbose"
  246. fi
  247. set -u
  248. PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-":"}
  249. # Prevent pkg-config to search the system folders (configured in the
  250. # pkg-config at build time).
  251. PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-":"}
  252. set +u
  253. echo
  254. echo "CC=${CC}"
  255. echo "CXX=${CXX}"
  256. echo "XBB_CPPFLAGS=${XBB_CPPFLAGS}"
  257. echo "XBB_CFLAGS=${XBB_CFLAGS}"
  258. echo "XBB_CXXFLAGS=${XBB_CXXFLAGS}"
  259. echo "XBB_LDFLAGS_LIB=${XBB_LDFLAGS_LIB}"
  260. echo "XBB_LDFLAGS_APP=${XBB_LDFLAGS_APP}"
  261. echo "XBB_LDFLAGS_APP_STATIC_GCC=${XBB_LDFLAGS_APP_STATIC_GCC}"
  262. echo "PKG_CONFIG=${PKG_CONFIG}"
  263. echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
  264. echo "PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR}"
  265. set -u
  266. (
  267. xbb_activate
  268. echo
  269. if [ "${TARGET_PLATFORM}" == "win32" ]
  270. then
  271. which ${CROSS_COMPILE_PREFIX}-gcc
  272. ${CROSS_COMPILE_PREFIX}-gcc --version
  273. else
  274. which ${CC}
  275. ${CC} --version
  276. fi
  277. which make
  278. make --version
  279. )
  280. set +u
  281. if [ "${TARGET_PLATFORM}" == "win32" -a ! -z "${CC}" -a ! -z "${CXX}" ]
  282. then
  283. echo "CC and CXX must not be set for cross builds."
  284. exit 1
  285. fi
  286. set -u
  287. # ---------------------------------------------------------------------------
  288. export XBB_CPPFLAGS
  289. export XBB_CFLAGS
  290. export XBB_CXXFLAGS
  291. export XBB_LDFLAGS
  292. export XBB_LDFLAGS_LIB
  293. export XBB_LDFLAGS_APP
  294. export XBB_LDFLAGS_APP_STATIC_GCC
  295. export CC
  296. export CXX
  297. export PKG_CONFIG
  298. export PKG_CONFIG_PATH
  299. export PKG_CONFIG_LIBDIR
  300. }
  301. # -----------------------------------------------------------------------------
  302. function do_actions()
  303. {
  304. if [ "${ACTION}" == "clean" ]
  305. then
  306. echo
  307. if [ "${IS_NATIVE}" == "y" ]
  308. then
  309. echo "Removing the ${TARGET_FOLDER_NAME} build and install ${APP_LC_NAME} folders..."
  310. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/build/${APP_LC_NAME}"
  311. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install/${APP_LC_NAME}"
  312. elif [ ! -z "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}${DO_BUILD_OSX}" ]
  313. then
  314. if [ "${DO_BUILD_WIN32}" == "y" ]
  315. then
  316. echo "Removing the win32-x32 build and install ${APP_LC_NAME} folders..."
  317. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/build/${APP_LC_NAME}"
  318. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/install/${APP_LC_NAME}"
  319. fi
  320. if [ "${DO_BUILD_WIN64}" == "y" ]
  321. then
  322. echo "Removing the win32-x64 build and install ${APP_LC_NAME} folders..."
  323. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/build/${APP_LC_NAME}"
  324. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/install/${APP_LC_NAME}"
  325. fi
  326. if [ "${DO_BUILD_LINUX32}" == "y" ]
  327. then
  328. echo "Removing the linux-x32 build and install ${APP_LC_NAME} folders..."
  329. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/build/${APP_LC_NAME}"
  330. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/install/${APP_LC_NAME}"
  331. fi
  332. if [ "${DO_BUILD_LINUX64}" == "y" ]
  333. then
  334. echo "Removing the linux-x64 build and install ${APP_LC_NAME} folders..."
  335. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/build/${APP_LC_NAME}"
  336. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/install/${APP_LC_NAME}"
  337. fi
  338. if [ "${DO_BUILD_OSX}" == "y" ]
  339. then
  340. echo "Removing the darwin-x64 build and install ${APP_LC_NAME} folders..."
  341. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/build/${APP_LC_NAME}"
  342. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/install/${APP_LC_NAME}"
  343. fi
  344. else
  345. echo "Removing the ${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH} build and install ${APP_LC_NAME} folders..."
  346. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/build/${APP_LC_NAME}"
  347. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/install/${APP_LC_NAME}"
  348. fi
  349. fi
  350. if [ "${ACTION}" == "cleanlibs" ]
  351. then
  352. echo
  353. if [ "${IS_NATIVE}" == "y" ]
  354. then
  355. echo "Removing the ${TARGET_FOLDER_NAME} build and install libs folders..."
  356. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/build/libs"
  357. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install/libs"
  358. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install"/stamp-*-installed
  359. elif [ ! -z "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}${DO_BUILD_OSX}" ]
  360. then
  361. if [ "${DO_BUILD_WIN32}" == "y" ]
  362. then
  363. echo "Removing the win32-x32 build and install libs folders..."
  364. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/build/libs"
  365. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/install/libs"
  366. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/install"/stamp-*-installed
  367. fi
  368. if [ "${DO_BUILD_WIN64}" == "y" ]
  369. then
  370. echo "Removing the win32-x64 build and install libs folders..."
  371. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/build/libs"
  372. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/install/libs"
  373. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/install"/stamp-*-installed
  374. fi
  375. if [ "${DO_BUILD_LINUX32}" == "y" ]
  376. then
  377. echo "Removing the linux-x32 build and install libs folders..."
  378. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/build/libs"
  379. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/install/libs"
  380. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/install"/stamp-*-installed
  381. fi
  382. if [ "${DO_BUILD_LINUX64}" == "y" ]
  383. then
  384. echo "Removing the linux-x64 build and install libs folders..."
  385. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/build/libs"
  386. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/install/libs"
  387. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/install"/stamp-*-installed
  388. fi
  389. if [ "${DO_BUILD_OSX}" == "y" ]
  390. then
  391. echo "Removing the darwin-x64 build and install libs folders..."
  392. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/build/libs"
  393. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/install/libs"
  394. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/install"/stamp-*-installed
  395. fi
  396. else
  397. echo "Removing the ${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH} build and install libs folders..."
  398. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/build/libs"
  399. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/install/libs"
  400. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/install"/stamp-*-installed
  401. fi
  402. fi
  403. if [ "${ACTION}" == "cleanall" ]
  404. then
  405. echo
  406. if [ "${IS_NATIVE}" == "y" ]
  407. then
  408. echo "Removing the ${TARGET_FOLDER_NAME} folder..."
  409. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}"
  410. elif [ ! -z "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}${DO_BUILD_OSX}" ]
  411. then
  412. if [ "${DO_BUILD_WIN32}" == "y" ]
  413. then
  414. echo "Removing the win32-x32 folder..."
  415. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32"
  416. fi
  417. if [ "${DO_BUILD_WIN64}" == "y" ]
  418. then
  419. echo "Removing the win32-x64 folder..."
  420. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64"
  421. fi
  422. if [ "${DO_BUILD_LINUX32}" == "y" ]
  423. then
  424. echo "Removing the linux-x32 folder..."
  425. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32"
  426. fi
  427. if [ "${DO_BUILD_LINUX64}" == "y" ]
  428. then
  429. echo "Removing the linux-x64 folder..."
  430. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64"
  431. fi
  432. if [ "${DO_BUILD_OSX}" == "y" ]
  433. then
  434. echo "Removing the darwin-x64 folder..."
  435. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64"
  436. fi
  437. else
  438. echo "Removing the ${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH} folder..."
  439. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}"
  440. fi
  441. fi
  442. if [ "${ACTION}" == "clean" -o "${ACTION}" == "cleanlibs" -o "${ACTION}" == "cleanall" ]
  443. then
  444. echo
  445. echo "Clean completed. Proceed with a regular build."
  446. exit 0
  447. fi
  448. # Not used for native buils. Otherwise the names of the docker images
  449. # must be set.
  450. if [ "${ACTION}" == "preload-images" ]
  451. then
  452. host_start_timer
  453. host_prepare_docker
  454. echo
  455. echo "Check/Preload Docker images..."
  456. echo
  457. docker run --interactive --tty "${docker_linux64_image}" \
  458. lsb_release --description --short
  459. echo
  460. docker run --interactive --tty "${docker_linux32_image}" \
  461. lsb_release --description --short
  462. echo
  463. docker images
  464. host_stop_timer
  465. exit 0
  466. fi
  467. }
  468. # -----------------------------------------------------------------------------
  469. function run_app()
  470. {
  471. # Does not include the .exe extension.
  472. local app_path=$1
  473. shift
  474. echo
  475. echo "${app_path} $@"
  476. if [ "${TARGET_PLATFORM}" == "linux" ]
  477. then
  478. "${app_path}" $@
  479. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  480. then
  481. "${app_path}" $@
  482. elif [ "${TARGET_PLATFORM}" == "win32" ]
  483. then
  484. local wsl_path=$(which wsl.exe)
  485. if [ ! -z "${wsl_path}" ]
  486. then
  487. "${app_path}.exe" $@
  488. else
  489. (
  490. xbb_activate
  491. local wine_path=$(which wine)
  492. if [ ! -z "${wine_path}" ]
  493. then
  494. wine "${app_path}.exe" $@
  495. else
  496. echo "Install wine if you want to run the .exe binaries on Linux."
  497. fi
  498. )
  499. fi
  500. fi
  501. }
  502. # -----------------------------------------------------------------------------
  503. function do_patch()
  504. {
  505. if [ ! -z "$1" ]
  506. then
  507. local patch_file_name="$1"
  508. local patch_path="${BUILD_GIT_PATH}/patches/${patch_file_name}"
  509. if [ -f "${patch_path}" ]
  510. then
  511. echo "Patching..."
  512. patch -p0 < "${patch_path}"
  513. fi
  514. fi
  515. }
  516. function extract()
  517. {
  518. local archive_name="$1"
  519. local folder_name="$2"
  520. # local patch_file_name="$3"
  521. local pwd="$(pwd)"
  522. if [ ! -d "${folder_name}" ]
  523. then
  524. (
  525. xbb_activate
  526. echo
  527. echo "Extracting \"${archive_name}\"..."
  528. if [[ "${archive_name}" == *zip ]]
  529. then
  530. unzip "${archive_name}"
  531. else
  532. if [ ! -z "${DEBUG}" ]
  533. then
  534. tar -x -v -f "${archive_name}"
  535. else
  536. tar -x -f "${archive_name}"
  537. fi
  538. fi
  539. if [ $# -gt 2 ]
  540. then
  541. cd "${folder_name}"
  542. do_patch "$3"
  543. fi
  544. )
  545. else
  546. echo "Folder \"${pwd}/${folder_name}\" already present."
  547. fi
  548. }
  549. function download()
  550. {
  551. local url="$1"
  552. local archive_name="$2"
  553. if [ ! -f "${DOWNLOAD_FOLDER_PATH}/${archive_name}" ]
  554. then
  555. (
  556. xbb_activate
  557. echo
  558. echo "Downloading \"${archive_name}\" from \"${url}\"..."
  559. rm -f "${DOWNLOAD_FOLDER_PATH}/${archive_name}.download"
  560. mkdir -p "${DOWNLOAD_FOLDER_PATH}"
  561. curl --fail -L -o "${DOWNLOAD_FOLDER_PATH}/${archive_name}.download" "${url}"
  562. mv "${DOWNLOAD_FOLDER_PATH}/${archive_name}.download" "${DOWNLOAD_FOLDER_PATH}/${archive_name}"
  563. )
  564. else
  565. echo "File \"${DOWNLOAD_FOLDER_PATH}/${archive_name}\" already downloaded."
  566. fi
  567. }
  568. function download_and_extract()
  569. {
  570. local url="$1"
  571. local archive_name="$2"
  572. local folder_name="$3"
  573. download "${url}" "${archive_name}"
  574. if [ $# -gt 3 ]
  575. then
  576. extract "${DOWNLOAD_FOLDER_PATH}/${archive_name}" "${folder_name}" "$4"
  577. else
  578. extract "${DOWNLOAD_FOLDER_PATH}/${archive_name}" "${folder_name}"
  579. fi
  580. }
  581. function git_clone()
  582. {
  583. local url="$1"
  584. local branch="$2"
  585. local commit="$3"
  586. local folder_name="$4"
  587. (
  588. echo
  589. echo "Cloning \"${folder_name}\" from \"${url}\"..."
  590. git clone --branch="${branch}" "${url}" "${folder_name}"
  591. if [ -n "${commit}" ]
  592. then
  593. cd "${folder_name}"
  594. git checkout -qf "${commit}"
  595. fi
  596. )
  597. }
  598. # Copy the build files to the Work area, to make them easily available.
  599. function copy_build_git()
  600. {
  601. rm -rf "${HOST_WORK_FOLDER_PATH}/build.git"
  602. mkdir -p "${HOST_WORK_FOLDER_PATH}/build.git"
  603. cp -r "$(dirname ${script_folder_path})"/* "${HOST_WORK_FOLDER_PATH}/build.git"
  604. rm -rf "${HOST_WORK_FOLDER_PATH}/build.git/scripts/helper/.git"
  605. rm -rf "${HOST_WORK_FOLDER_PATH}/build.git/scripts/helper/build-helper.sh"
  606. }
  607. # -----------------------------------------------------------------------------
  608. function check_binary()
  609. {
  610. local file_path="$1"
  611. if [ ! -x "${file_path}" ]
  612. then
  613. return 0
  614. fi
  615. if file --mime "${file_path}" | grep -q text
  616. then
  617. return 0
  618. fi
  619. check_binary_for_libraries "$1"
  620. }
  621. function check_binary_for_libraries()
  622. {
  623. local file_path="$1"
  624. local file_name="$(basename ${file_path})"
  625. local folder_path="$(dirname ${file_path})"
  626. (
  627. xbb_activate
  628. if [ "${TARGET_PLATFORM}" == "win32" ]
  629. then
  630. echo
  631. echo "${file_name}"
  632. set +e
  633. ${CROSS_COMPILE_PREFIX}-objdump -x "${file_path}" | grep -i 'DLL Name'
  634. local dll_names=$(${CROSS_COMPILE_PREFIX}-objdump -x "${file_path}" \
  635. | grep -i 'DLL Name' \
  636. | sed -e 's/.*DLL Name: \(.*\)/\1/' \
  637. )
  638. local n
  639. for n in ${dll_names}
  640. do
  641. if [ ! -f "${folder_path}/${n}" ]
  642. then
  643. if is_win_sys_dll "${n}"
  644. then
  645. :
  646. elif [ "${n}${HAS_WINPTHREAD}" == "libwinpthread-1.dlly" ]
  647. then
  648. :
  649. elif [[ ${n} == python*.dll ]] && [[ ${file_name} == *-gdb-py.exe ]]
  650. then
  651. :
  652. else
  653. echo "Unexpected |${n}|"
  654. exit 1
  655. fi
  656. fi
  657. done
  658. set -e
  659. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  660. then
  661. echo
  662. (
  663. set +e
  664. cd ${folder_path}
  665. otool -L "${file_name}"
  666. set -e
  667. )
  668. set +e
  669. local unxp
  670. if [[ "${file_name}" == *\.dylib ]]
  671. then
  672. unxp=$(otool -L "${file_path}" | sed '1d' | sed '1d' | grep -v "${file_name}" | egrep -e "(macports|homebrew|opt|install)/")
  673. else
  674. unxp=$(otool -L "${file_path}" | sed '1d' | grep -v "${file_name}" | egrep -e "(macports|homebrew|opt|install)/")
  675. fi
  676. set -e
  677. # echo "|${unxp}|"
  678. if [ ! -z "$unxp" ]
  679. then
  680. echo "Unexpected |${unxp}|"
  681. exit 1
  682. fi
  683. elif [ "${TARGET_PLATFORM}" == "linux" ]
  684. then
  685. echo
  686. echo "${file_name}"
  687. set +e
  688. readelf -d "${file_path}" | egrep -i 'library|dynamic'
  689. local so_names=$(readelf -d "${file_path}" \
  690. | grep -i 'Shared library' \
  691. | sed -e 's/.*Shared library: \[\(.*\)\]/\1/' \
  692. )
  693. local n
  694. for n in ${so_names}
  695. do
  696. if [ ! -f "${folder_path}/${n}" ]
  697. then
  698. if is_linux_sys_so "${n}"
  699. then
  700. :
  701. elif [[ ${n} == libpython* ]] && [[ ${file_name} == *-gdb-py ]]
  702. then
  703. :
  704. else
  705. echo "Unexpected |${n}|"
  706. exit 1
  707. fi
  708. fi
  709. done
  710. set -e
  711. fi
  712. )
  713. }
  714. function is_win_sys_dll()
  715. {
  716. local dll_name="$1"
  717. # DLLs that are expected to be present on any Windows.
  718. local sys_dlls=( \
  719. ADVAPI32.dll \
  720. KERNEL32.dll \
  721. msvcrt.dll \
  722. MSVCR90.dll \
  723. SHELL32.dll \
  724. USER32.dll \
  725. WINMM.dll \
  726. WINMM.DLL \
  727. WS2_32.dll \
  728. ole32.dll \
  729. DNSAPI.dll \
  730. IPHLPAPI.dll \
  731. GDI32.dll \
  732. IMM32.dll \
  733. IMM32.DLL \
  734. OLEAUT32.dll \
  735. IPHLPAPI.DLL \
  736. VERSION.dll \
  737. SETUPAPI.dll \
  738. CFGMGR32.dll \
  739. PSAPI.DLL \
  740. USERENV.dll \
  741. python27.dll \
  742. )
  743. # The Python DLL prevents it from being copied.
  744. local dll
  745. for dll in "${sys_dlls[@]}"
  746. do
  747. if [ "${dll}" == "${dll_name}" ]
  748. then
  749. return 0 # True
  750. fi
  751. done
  752. return 1 # False
  753. }
  754. function is_linux_sys_so()
  755. {
  756. local lib_name="$1"
  757. # Do not add these two, they are present if the toolchain is installed,
  758. # but this is not guaranteed, so better copy them from the xbb toolchain.
  759. # libstdc++.so.6
  760. # libgcc_s.so.1
  761. # Shared libraries that are expected to be present on any Linux.
  762. # Note the X11 libraries.
  763. local sys_libs=(\
  764. librt.so.1 \
  765. libm.so.6 \
  766. libc.so.6 \
  767. libutil.so.1 \
  768. libpthread.so.0 \
  769. libdl.so.2 \
  770. ld-linux-x86-64.so.2 \
  771. ld-linux.so.2 \
  772. libX11.so.6 \
  773. libXau.so.6 \
  774. libxcb.so.1 \
  775. )
  776. local lib
  777. for lib in "${sys_libs[@]}"
  778. do
  779. if [ "${lib}" == "${lib_name}" ]
  780. then
  781. return 0 # True
  782. fi
  783. done
  784. return 1 # False
  785. }
  786. function is_darwin_sys_dylib()
  787. {
  788. local lib_name="$1"
  789. if [[ ${lib_name} == /usr/lib* ]]
  790. then
  791. return 0
  792. fi
  793. if [[ ${lib_name} == /System/Library* ]]
  794. then
  795. return 0
  796. fi
  797. return 1
  798. }
  799. # -----------------------------------------------------------------------------
  800. function has_origin()
  801. {
  802. if [ $# -lt 1 ]
  803. then
  804. warning "has_origin: Missing file argument"
  805. exit 1
  806. fi
  807. local bin="$1"
  808. if [ "${TARGET_PLATFORM}" == "linux" ]
  809. then
  810. local origin=$(readelf -d ${bin} | grep 'Library runpath: \[$ORIGIN\]')
  811. if [ ! -z "${origin}" ]
  812. then
  813. return 0 # true
  814. fi
  815. fi
  816. return 1 # false
  817. }
  818. # Strip binary files as in "strip binary" form, for both native
  819. # (linux/mac) and mingw.
  820. function strip_binary2()
  821. {
  822. set +e
  823. if [ $# -lt 2 ]
  824. then
  825. warning "strip_binary: Missing arguments"
  826. exit 1
  827. fi
  828. local strip="$1"
  829. local bin="$2"
  830. if is_elf "${bin}"
  831. then
  832. if has_origin "${bin}"
  833. then
  834. echo "${strip} ${bin} skipped (patched)"
  835. else
  836. echo "${strip} ${bin}"
  837. # ${strip} ${bin} 2>/dev/null || true
  838. "${strip}" -S "${bin}" || true
  839. fi
  840. else
  841. echo $(file "${bin}")
  842. fi
  843. set -e
  844. }
  845. function strip_binary()
  846. {
  847. if [ $# -lt 1 ]
  848. then
  849. warning "strip_binary: Missing file argument"
  850. exit 1
  851. fi
  852. local bin="$1"
  853. local strip="strip"
  854. if [ "${TARGET_PLATFORM}" == "win32" ]
  855. then
  856. strip="${CROSS_COMPILE_PREFIX}-strip"
  857. if [[ "${bin}" != *.exe ]]
  858. then
  859. bin="${bin}.exe"
  860. fi
  861. fi
  862. if has_origin "${bin}"
  863. then
  864. # If the file was patched, skip strip, otherwise
  865. # we may damage the binary due to a bug in strip.
  866. echo "${strip} ${bin} skipped (patched)"
  867. return
  868. fi
  869. echo "${strip} ${bin}"
  870. "${strip}" -S "${bin}" || true
  871. }
  872. function is_elf()
  873. {
  874. if [ $# -lt 1 ]
  875. then
  876. warning "is_elf: Missing arguments"
  877. exit 1
  878. fi
  879. local bin="$1"
  880. # Symlinks do not match.
  881. if [ -L "${bin}" ]
  882. then
  883. return 1
  884. fi
  885. if [ -f "${bin}" -a -x "${bin}" ]
  886. then
  887. # Return 0 (true) if found.
  888. file ${bin} | egrep -q "( ELF )|( PE )|( PE32 )|( PE32\+ )|( Mach-O )"
  889. else
  890. return 1
  891. fi
  892. }
  893. # -----------------------------------------------------------------------------
  894. # Deprecated, use copy_dependencies_recursive().
  895. function copy_win_gcc_dll()
  896. {
  897. local dll_name="$1"
  898. # Identify the current cross gcc version, to locate the specific dll folder.
  899. local cross_gcc_version=$(${CROSS_COMPILE_PREFIX}-gcc --version | grep 'gcc' | sed -e 's/.*\s\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\).*/\1.\2.\3/')
  900. local cross_gcc_version_short=$(echo ${cross_gcc_version} | sed -e 's/\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\).*/\1.\2/')
  901. local SUBLOCATION="-win32"
  902. # First try Ubuntu specific locations,
  903. # then do a long full search.
  904. if [ -f "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/lib/${dll_name}" ]
  905. then
  906. cp -v "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/lib/${dll_name}" \
  907. "${APP_PREFIX}/bin"
  908. elif [ -f "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version}/${dll_name}" ]
  909. then
  910. cp -v "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version}/${dll_name}" \
  911. "${APP_PREFIX}/bin"
  912. elif [ -f "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}/${dll_name}" ]
  913. then
  914. cp -v "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}/${dll_name}" \
  915. "${APP_PREFIX}/bin"
  916. elif [ -f "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}${SUBLOCATION}/${dll_name}" ]
  917. then
  918. cp -v "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}${SUBLOCATION}/${dll_name}" \
  919. "${APP_PREFIX}/bin"
  920. else
  921. echo "Searching /usr for ${dll_name}..."
  922. SJLJ_PATH=$(find "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}" /usr \! -readable -prune -o -name ${dll_name} -print | grep ${CROSS_COMPILE_PREFIX})
  923. cp -v ${SJLJ_PATH} "${APP_PREFIX}/bin"
  924. fi
  925. }
  926. # Deprecated, use copy_dependencies_recursive().
  927. function copy_win_libwinpthread_dll()
  928. {
  929. if [ -f "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/bin/libwinpthread-1.dll" ]
  930. then
  931. cp "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/bin/libwinpthread-1.dll" \
  932. "${APP_PREFIX}/bin"
  933. else
  934. echo "No libwinpthread-1.dll"
  935. exit 1
  936. fi
  937. }
  938. # -----------------------------------------------------------------------------
  939. function change_dylib()
  940. {
  941. local dylib_name="$1"
  942. local file_path="$2"
  943. local dylib_path="$(otool -L "${file_path}" | grep "${dylib_name}" | sed -e 's|[[:space:]]*\(.*\)[[:space:]][(].*[)]|\1|')"
  944. if [ -z "${dylib_path}" ]
  945. then
  946. echo "Dylib ${dylib_name} not used in binary ${file_path}..."
  947. exit 1
  948. fi
  949. # Hack to bring Python library name in line with the other libraries.
  950. if [ "${dylib_name}" == "Python" ]
  951. then
  952. local version="$(otool -L "${file_path}" | grep "${dylib_name}" | sed -e 's|.*current version \([0-9][0-9]*\.[0-9][0-9]*\).*|\1|')"
  953. dylib_name="libpython${version}.dylib"
  954. rm -rf "$(dirname ${file_path})/Python"
  955. fi
  956. chmod +w "${file_path}"
  957. install_name_tool \
  958. -change "${dylib_path}" \
  959. "@executable_path/${dylib_name}" \
  960. "${file_path}"
  961. if [ ! -f "$(dirname ${file_path})/${dylib_name}" ]
  962. then
  963. install -v -c -m 644 "${dylib_path}" "$(dirname ${file_path})/${dylib_name}"
  964. fi
  965. }
  966. # Workaround to Docker error on 32-bit image:
  967. # stat: Value too large for defined data type (requires -D_FILE_OFFSET_BITS=64)
  968. function patch_linux_elf_origin()
  969. {
  970. local file_path="$1"
  971. local tmp_path=$(mktemp)
  972. rm -rf "${tmp_path}"
  973. cp "${file_path}" "${tmp_path}"
  974. patchelf --set-rpath '$ORIGIN' "${tmp_path}"
  975. cp "${tmp_path}" "${file_path}"
  976. rm -rf "${tmp_path}"
  977. }
  978. # $1 - absolute path to executable
  979. function prepare_app_libraries()
  980. {
  981. local app_path="$1"
  982. shift
  983. (
  984. xbb_activate
  985. local app_folder_path="$(dirname "${app_path}")"
  986. if [ "${WITH_STRIP}" == "y" ]
  987. then
  988. strip_binary "${app_path}"
  989. fi
  990. if [ "${TARGET_PLATFORM}" == "linux" ]
  991. then
  992. echo
  993. echo "Shared libraries:"
  994. echo "${app_path}"
  995. readelf -d "${app_path}" | grep 'Shared library:'
  996. echo
  997. echo "Preparing libraries..."
  998. patch_linux_elf_origin "${app_path}"
  999. echo
  1000. copy_dependencies_recursive "${app_path}" "${app_folder_path}"
  1001. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1002. then
  1003. echo
  1004. echo "Initial dynamic libraries:"
  1005. otool -L "${app_path}"
  1006. echo
  1007. echo "Preparing libraries..."
  1008. copy_dependencies_recursive "${app_path}" "${app_folder_path}"
  1009. echo
  1010. echo "Updated dynamic libraries:"
  1011. otool -L "${app_path}"
  1012. elif [ "${TARGET_PLATFORM}" == "win32" ]
  1013. then
  1014. echo
  1015. echo "Dynamic libraries:"
  1016. echo "${app_path}.exe"
  1017. ${CROSS_COMPILE_PREFIX}-objdump -x "${app_path}.exe" | grep -i 'DLL Name'
  1018. echo
  1019. echo "Preparing libraries..."
  1020. copy_dependencies_recursive "${app_path}.exe" "${app_folder_path}"
  1021. fi
  1022. )
  1023. }
  1024. function prepare_app_folder_libraries()
  1025. {
  1026. local folder_path="${APP_PREFIX}"
  1027. if [ $# -ge 1 ]
  1028. then
  1029. folder_path="$1"
  1030. fi
  1031. (
  1032. xbb_activate
  1033. echo
  1034. echo "Preparing ${folder_path} libraries..."
  1035. local binaries
  1036. if [ "${TARGET_PLATFORM}" == "win32" ]
  1037. then
  1038. binaries=$(find "${folder_path}" -name \*.exe)
  1039. for bin in ${binaries}
  1040. do
  1041. echo "Preparing ${bin} libraries..."
  1042. copy_dependencies_recursive "${bin}" "$(dirname "${bin}")"
  1043. done
  1044. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1045. then
  1046. binaries=$(find "${folder_path}" -name \* -perm +111 -and ! -type d)
  1047. for bin in ${binaries}
  1048. do
  1049. if is_elf "${bin}"
  1050. then
  1051. echo "Preparing ${bin} libraries..."
  1052. copy_dependencies_recursive "${bin}" "$(dirname "${bin}")"
  1053. fi
  1054. done
  1055. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1056. then
  1057. binaries=$(find "${folder_path}" -name \* -perm /111 -and ! -type d)
  1058. for bin in ${binaries}
  1059. do
  1060. if is_elf "${bin}"
  1061. then
  1062. echo "Preparing ${bin} libraries..."
  1063. copy_dependencies_recursive "${bin}" "$(dirname "${bin}")"
  1064. fi
  1065. done
  1066. fi
  1067. )
  1068. }
  1069. function copy_dependencies_recursive()
  1070. {
  1071. if [ $# -ne 2 ]
  1072. then
  1073. echo "copy_dependencies_recursive requires 2 args."
  1074. exit 1
  1075. fi
  1076. local file_path="$1"
  1077. local dest_path="$2"
  1078. local file_name="$(basename "${file_path}")"
  1079. local folder_path="$(dirname "${file_path}")"
  1080. if is_elf "${file_path}"
  1081. then
  1082. if [ "${folder_path}" != "${dest_path}" ]
  1083. then
  1084. if [ ! -f "${dest_path}/${file_name}" ]
  1085. then
  1086. install -v -c -m 644 "${file_path}" "${dest_path}"
  1087. if [ "${WITH_STRIP}" == "y" ]
  1088. then
  1089. strip_binary "${dest_path}/${file_name}"
  1090. fi
  1091. fi
  1092. fi
  1093. if [ "${TARGET_PLATFORM}" == "linux" ]
  1094. then
  1095. patch_linux_elf_origin "${dest_path}/${file_name}"
  1096. fi
  1097. else
  1098. if [ "${TARGET_PLATFORM}" == "win32" ]
  1099. then
  1100. # On Windows don't bother with links, simply copy the file.
  1101. local link_path="$(readlink -f "${file_path}")"
  1102. if [ ! -f "${dest_path}/${file_name}" ]
  1103. then
  1104. install -v -c -m 644 "${link_path}" "${dest_path}"
  1105. if [ "${WITH_STRIP}" == "y" ]
  1106. then
  1107. strip_binary "${dest_path}/${file_name}"
  1108. fi
  1109. fi
  1110. else
  1111. # On POSIX preserve symbolic links, since shared libraries can be
  1112. # referred with different names.
  1113. if [ -L "${file_path}" ]
  1114. then
  1115. (
  1116. local which_realpath="$(which "realpath")"
  1117. if [ ! -z "${which_realpath}" ]
  1118. then
  1119. # Resolve only one link level. If there are more, they
  1120. # are resolved recursively.
  1121. local link_path="$(readlink "${file_path}")"
  1122. cd "${folder_path}"
  1123. # Compute the absolute path of the link.
  1124. local real_path="$(realpath "${link_path}")"
  1125. copy_dependencies_recursive "${real_path}" "${dest_path}"
  1126. cd "${dest_path}"
  1127. if [ \( "$(basename "${link_path}")" != "${file_name}" \) -a \( ! -L "${file_name}" \) ]
  1128. then
  1129. rm -rf "${file_name}"
  1130. ln -sv "$(basename "${link_path}")" "${file_name}"
  1131. fi
  1132. else
  1133. # Compute the final absolute path of the link, regardless
  1134. # how many links there are on the way.
  1135. local link_path="$(readlink -f "${file_path}")"
  1136. copy_dependencies_recursive "${link_path}" "${dest_path}"
  1137. cd "${dest_path}"
  1138. if [ \( "$(basename "${link_path}")" != "${file_name}" \) -a \( ! -L "${file_name}" \) ]
  1139. then
  1140. rm -rf "${file_name}"
  1141. ln -sv "$(basename "${link_path}")" "${file_name}"
  1142. fi
  1143. fi
  1144. )
  1145. return
  1146. else
  1147. if [ ! -f "${dest_path}/${file_name}" ]
  1148. then
  1149. install -v -c -m 644 "${file_path}" "${dest_path}"
  1150. if [ "${WITH_STRIP}" == "y" ]
  1151. then
  1152. strip_binary "${dest_path}/${file_name}"
  1153. fi
  1154. fi
  1155. if [ "${TARGET_PLATFORM}" == "linux" ]
  1156. then
  1157. patch_linux_elf_origin "${dest_path}/${file_name}"
  1158. fi
  1159. fi
  1160. fi
  1161. fi
  1162. if [ "${TARGET_PLATFORM}" == "linux" ]
  1163. then
  1164. local libs=$(readelf -d "${dest_path}/${file_name}" \
  1165. | grep -i 'Shared library' \
  1166. | sed -e 's/.*Shared library: \[\(.*\)\]/\1/' \
  1167. )
  1168. local lib
  1169. for lib in ${libs}
  1170. do
  1171. if is_linux_sys_so "${lib}"
  1172. then
  1173. : # System library, no need to copy it.
  1174. else
  1175. if [ -f "${LIBS_INSTALL_FOLDER_PATH}/lib64/${lib}" ]
  1176. then
  1177. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/lib64/${lib}" "${dest_path}"
  1178. elif [ -f "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib}" ]
  1179. then
  1180. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib}" "${dest_path}"
  1181. else
  1182. local full_path=$(${CC} -print-file-name=${lib})
  1183. # -print-file-name outputs back the requested name if not found.
  1184. if [ "${full_path}" != "${lib}" ]
  1185. then
  1186. copy_dependencies_recursive "${full_path}" "${dest_path}"
  1187. else
  1188. if [ -f "${XBB_FOLDER}/lib64/${lib}" ]
  1189. then
  1190. copy_dependencies_recursive "${XBB_FOLDER}/lib64/${lib}" "${dest_path}"
  1191. elif [ -f "${XBB_FOLDER}/lib/${lib}" ]
  1192. then
  1193. copy_dependencies_recursive "${XBB_FOLDER}/lib/${lib}" "${dest_path}"
  1194. else
  1195. echo "${lib} not found"
  1196. exit 1
  1197. fi
  1198. fi
  1199. fi
  1200. fi
  1201. done
  1202. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1203. then
  1204. echo
  1205. otool -L "${dest_path}/${file_name}"
  1206. local libs=$(otool -L "${dest_path}/${file_name}" \
  1207. | sed '1d' \
  1208. | sed -e 's|[[:space:]]*\(.*\) (.*)|\1|' \
  1209. )
  1210. local exec_prefix="@executable_path/"
  1211. local loader_path="@loader_path/"
  1212. local lib
  1213. for lib in ${libs}
  1214. do
  1215. if [ "${lib}" == "${exec_prefix}${file_name}" ]
  1216. then
  1217. :
  1218. elif [ "${lib}" == "${loader_path}${file_name}" ]
  1219. then
  1220. :
  1221. elif [ "$(basename $(readlink -f ${lib}))" == "${file_name}" ]
  1222. then
  1223. : # Libraries return a line with their own name.
  1224. else
  1225. if is_darwin_sys_dylib "${lib}"
  1226. then
  1227. : # System library, no need to copy it.
  1228. else
  1229. # The libs can be relative to @executable_path or absolute.
  1230. if [ "${lib:0:${#exec_prefix}}" == "${exec_prefix}" ]
  1231. then
  1232. :
  1233. else
  1234. if [ -f "${lib}" ]
  1235. then
  1236. copy_dependencies_recursive "${lib}" "${dest_path}"
  1237. elif [ -f "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib}" ]
  1238. then
  1239. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib}" "${dest_path}"
  1240. else
  1241. echo "${lib} not found"
  1242. exit 1
  1243. fi
  1244. # Change library path to '@executable_path' inside the lib or app.
  1245. change_dylib "$(basename "${lib}")" "${dest_path}/${file_name}"
  1246. fi
  1247. fi
  1248. fi
  1249. done
  1250. elif [ "${TARGET_PLATFORM}" == "win32" ]
  1251. then
  1252. local libs=$(${CROSS_COMPILE_PREFIX}-objdump -x "${dest_path}/${file_name}" \
  1253. | grep -i 'DLL Name' \
  1254. | sed -e 's/.*DLL Name: \(.*\)/\1/' \
  1255. )
  1256. local lib
  1257. for lib in ${libs}
  1258. do
  1259. if is_win_sys_dll "${lib}"
  1260. then
  1261. : # System DLL, no need to copy it.
  1262. else
  1263. if [ -f "${LIBS_INSTALL_FOLDER_PATH}/bin/${lib}" ]
  1264. then
  1265. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/bin/${lib}" "${dest_path}"
  1266. elif [ -f "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/bin/${lib}" ]
  1267. then
  1268. copy_dependencies_recursive "${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/bin/${lib}" "${dest_path}"
  1269. else
  1270. local full_path=$(${CROSS_COMPILE_PREFIX}-gcc -print-file-name=${lib})
  1271. # -print-file-name outputs back the requested name if not found.
  1272. if [ "${full_path}" != "${lib}" ]
  1273. then
  1274. copy_dependencies_recursive "${full_path}" "${dest_path}"
  1275. else
  1276. echo "${lib} required by ${file_name}, not found"
  1277. exit 1
  1278. fi
  1279. fi
  1280. fi
  1281. done
  1282. fi
  1283. }
  1284. function check_binaries()
  1285. {
  1286. local folder_path="${APP_PREFIX}"
  1287. if [ $# -ge 1 ]
  1288. then
  1289. folder_path="$1"
  1290. fi
  1291. (
  1292. xbb_activate
  1293. echo
  1294. echo "Checking binaries for unwanted libraries..."
  1295. local binaries
  1296. if [ "${TARGET_PLATFORM}" == "win32" ]
  1297. then
  1298. binaries=$(find "${folder_path}" -name \*.exe)
  1299. for bin in ${binaries}
  1300. do
  1301. check_binary "${bin}"
  1302. done
  1303. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1304. then
  1305. binaries=$(find "${folder_path}" -name \* -perm +111 -and ! -type d)
  1306. for bin in ${binaries}
  1307. do
  1308. if is_elf "${bin}"
  1309. then
  1310. check_binary "${bin}"
  1311. fi
  1312. done
  1313. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1314. then
  1315. binaries=$(find "${folder_path}" -name \* -perm /111 -and ! -type d)
  1316. for bin in ${binaries}
  1317. do
  1318. if is_elf "${bin}"
  1319. then
  1320. check_binary "${bin}"
  1321. fi
  1322. done
  1323. fi
  1324. )
  1325. }
  1326. # -----------------------------------------------------------------------------
  1327. # $1 - absolute path to input folder
  1328. # $2 - name of output folder below INSTALL_FOLDER
  1329. function copy_license()
  1330. {
  1331. # Iterate all files in a folder and install some of them in the
  1332. # destination folder
  1333. echo
  1334. echo "$2"
  1335. (
  1336. cd "$1"
  1337. local f
  1338. for f in *
  1339. do
  1340. if [ -f "$f" ]
  1341. then
  1342. if [[ "$f" =~ AUTHORS.*|NEWS.*|COPYING.*|README.*|LICENSE.*|FAQ.*|DEPENDENCIES.*|THANKS.* ]]
  1343. then
  1344. install -d -m 0755 \
  1345. "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses/$2"
  1346. install -v -c -m 644 "$f" \
  1347. "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses/$2"
  1348. fi
  1349. fi
  1350. done
  1351. )
  1352. (
  1353. xbb_activate
  1354. if [ "${TARGET_PLATFORM}" == "win32" ]
  1355. then
  1356. find "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses" \
  1357. -type f \
  1358. -exec unix2dos '{}' ';'
  1359. fi
  1360. )
  1361. }
  1362. function copy_build_files()
  1363. {
  1364. echo
  1365. echo "Copying build files..."
  1366. (
  1367. cd "${BUILD_GIT_PATH}"
  1368. mkdir -p patches
  1369. find scripts patches -type d \
  1370. -exec install -d -m 0755 \
  1371. "${APP_PREFIX}/${DISTRO_INFO_NAME}"/'{}' ';'
  1372. find scripts patches -type f \
  1373. -exec install -v -c -m 644 \
  1374. '{}' "${APP_PREFIX}/${DISTRO_INFO_NAME}"/'{}' ';'
  1375. if [ -f CHANGELOG.txt ]
  1376. then
  1377. install -v -c -m 644 \
  1378. CHANGELOG.txt "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1379. fi
  1380. if [ -f CHANGELOG.md ]
  1381. then
  1382. install -v -c -m 644 \
  1383. CHANGELOG.md "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1384. fi
  1385. )
  1386. }
  1387. # -----------------------------------------------------------------------------
  1388. # Copy one folder to another
  1389. function copy_dir()
  1390. {
  1391. local from_path="$1"
  1392. local to_path="$2"
  1393. set +u
  1394. # rm -rf "${to_path}"
  1395. mkdir -p "${to_path}"
  1396. (
  1397. cd "${from_path}"
  1398. if [ "${TARGET_PLATFORM}" == "darwin" ]
  1399. then
  1400. find . -xdev -print0 | cpio -oa0 | (cd "${to_path}" && cpio -im)
  1401. else
  1402. find . -xdev -print0 | cpio -oa0V | (cd "${to_path}" && cpio -imuV)
  1403. fi
  1404. )
  1405. set -u
  1406. }
  1407. # -----------------------------------------------------------------------------
  1408. function create_archive()
  1409. {
  1410. (
  1411. xbb_activate
  1412. local distribution_file_version="${RELEASE_VERSION}"
  1413. local target_folder_name=${TARGET_FOLDER_NAME}
  1414. if [ "${HAS_NAME_ARCH}" != "y" ]
  1415. then
  1416. # Pre xPack distributions use the old file name convention.
  1417. distribution_file_version="${RELEASE_VERSION}-${DISTRIBUTION_FILE_DATE}"
  1418. if [ "${TARGET_PLATFORM}" == "win32" ]
  1419. then
  1420. target_folder_name="win${TARGET_BITS}"
  1421. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1422. then
  1423. target_folder_name="macos"
  1424. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1425. then
  1426. target_folder_name="${CONTAINER_DISTRO_LC_NAME}${TARGET_BITS}"
  1427. fi
  1428. fi
  1429. local distribution_file="${DEPLOY_FOLDER_PATH}/${DISTRO_LC_NAME}-${APP_LC_NAME}-${distribution_file_version}-${target_folder_name}"
  1430. local archive_version_path
  1431. archive_version_path="${INSTALL_FOLDER_PATH}/archive/${DISTRO_LC_NAME}-${APP_LC_NAME}-${distribution_file_version}"
  1432. cd "${APP_PREFIX}"
  1433. find . -name '.DS_Store' -exec rm '{}' ';'
  1434. echo
  1435. echo "Creating distribution..."
  1436. mkdir -p "${DEPLOY_FOLDER_PATH}"
  1437. # The folder is temprarily moved into a versioned folder like
  1438. # xpack-<app-name>-<version>, or, in previous versions,
  1439. # in a more elaborate hierarchy like
  1440. # xPacks/<app-name>/<version>.
  1441. # After the archive is created, the folders are moved back.
  1442. # The atempt to transform the tar path fails, since symlinks were
  1443. # also transformed, which is bad.
  1444. if [ "${TARGET_PLATFORM}" == "win32" ]
  1445. then
  1446. local distribution_file="${distribution_file}.zip"
  1447. if [ "${USE_SINGLE_FOLDER}" != "y" ]
  1448. then
  1449. # DEPRECATED!
  1450. archive_version_path="${INSTALL_FOLDER_PATH}/archive/${DISTRO_UC_NAME}/${APP_UC_NAME}/${distribution_file_version}"
  1451. fi
  1452. echo
  1453. echo "ZIP file: \"${distribution_file}\"."
  1454. rm -rf "${INSTALL_FOLDER_PATH}/archive"
  1455. mkdir -p "${archive_version_path}"
  1456. mv "${APP_PREFIX}"/* "${archive_version_path}"
  1457. cd "${INSTALL_FOLDER_PATH}/archive"
  1458. zip -r9 -q "${distribution_file}" *
  1459. # Put folders back.
  1460. mv "${archive_version_path}"/* "${APP_PREFIX}"
  1461. else
  1462. # Unfortunately on node.js, xz & bz2 require native modules, which
  1463. # proved unsafe, some xz versions failed to compile on node.js v9.x,
  1464. # so use the good old .tar.gz.
  1465. local distribution_file
  1466. if [ "${USE_TAR_GZ}" == "y" ]
  1467. then
  1468. # Some platforms (like Arduino) accept only this explicit path.
  1469. distribution_file="${distribution_file}.tar.gz"
  1470. else
  1471. distribution_file="${distribution_file}.tgz"
  1472. fi
  1473. local archive_version_path
  1474. if [ "${USE_SINGLE_FOLDER}" != "y" ]
  1475. then
  1476. # DEPRECATED!
  1477. archive_version_path="${INSTALL_FOLDER_PATH}/archive/${DISTRO_TOP_FOLDER}/${APP_LC_NAME}/${distribution_file_version}"
  1478. fi
  1479. echo "Compressed tarball: \"${distribution_file}\"."
  1480. rm -rf "${INSTALL_FOLDER_PATH}/archive"
  1481. mkdir -p "${archive_version_path}"
  1482. mv -v "${APP_PREFIX}"/* "${archive_version_path}"
  1483. # Without --hard-dereference the hard links may be turned into
  1484. # broken soft links on macOS.
  1485. cd "${INSTALL_FOLDER_PATH}"/archive
  1486. # -J uses xz for compression; best compression ratio.
  1487. # -j uses bz2 for compression; good compression ratio.
  1488. # -z uses gzip for compression; fair compression ratio.
  1489. tar -c -z -f "${distribution_file}" \
  1490. --owner=0 \
  1491. --group=0 \
  1492. --format=posix \
  1493. --hard-dereference \
  1494. *
  1495. # Put folders back.
  1496. mv -v "${archive_version_path}"/* "${APP_PREFIX}"
  1497. fi
  1498. cd "${DEPLOY_FOLDER_PATH}"
  1499. compute_sha shasum -a 256 "$(basename ${distribution_file})"
  1500. )
  1501. }
  1502. # -----------------------------------------------------------------------------
  1503. # $1 = application name
  1504. function check_application()
  1505. {
  1506. local app_name=$1
  1507. if [ "${TARGET_PLATFORM}" == "linux" ]
  1508. then
  1509. echo
  1510. echo "Checking binaries for unwanted shared libraries..."
  1511. check_binary "${APP_PREFIX}/bin/${app_name}"
  1512. local libs=$(find "${APP_PREFIX}/bin" -name \*.so.\* -type f)
  1513. local lib
  1514. for lib in ${libs}
  1515. do
  1516. check_binary_for_libraries "${lib}"
  1517. done
  1518. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1519. then
  1520. echo
  1521. echo "Checking binaries for unwanted dynamic libraries..."
  1522. check_binary "${APP_PREFIX}/bin/${app_name}"
  1523. local libs=$(find "${APP_PREFIX}/bin" -name \*.dylib -type f)
  1524. local lib
  1525. for lib in ${libs}
  1526. do
  1527. check_binary_for_libraries "${lib}"
  1528. done
  1529. elif [ "${TARGET_PLATFORM}" == "win32" ]
  1530. then
  1531. echo
  1532. echo "Checking binaries for unwanted DLLs..."
  1533. check_binary "${APP_PREFIX}/bin/${app_name}.exe"
  1534. local libs=$(find "${APP_PREFIX}/bin" -name \*.dll -type f)
  1535. local lib
  1536. for lib in ${libs}
  1537. do
  1538. check_binary_for_libraries "${lib}"
  1539. done
  1540. else
  1541. echo "Unsupported TARGET_PLATFORM ${TARGET_PLATFORM}"
  1542. exit 1
  1543. fi
  1544. echo
  1545. }
  1546. # -----------------------------------------------------------------------------
  1547. function compute_sha()
  1548. {
  1549. # $1 shasum program
  1550. # $2.. options
  1551. # ${!#} file
  1552. file=${!#}
  1553. sha_file="${file}.sha"
  1554. "$@" >"${sha_file}"
  1555. echo "SHA: $(cat ${sha_file})"
  1556. }
  1557. # -----------------------------------------------------------------------------