common-functions-source.sh 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508
  1. # -----------------------------------------------------------------------------
  2. # This file is part of the xPack distribution.
  3. # (https://xpack.github.io)
  4. # Copyright (c) 2020 Liviu Ionescu.
  5. #
  6. # Permission to use, copy, modify, and/or distribute this software
  7. # for any purpose is hereby granted, under the terms of the MIT license.
  8. # -----------------------------------------------------------------------------
  9. # Helper script used in the second edition of the xPack build
  10. # scripts. As the name implies, it should contain only functions and
  11. # should be included with 'source' by the build scripts (both native
  12. # and container).
  13. # -----------------------------------------------------------------------------
  14. # Default empty definition, if XBB is available, it should
  15. # redefine it.
  16. function xbb_activate()
  17. {
  18. :
  19. }
  20. function xbb_activate_dev()
  21. {
  22. # Add XBB include in front of XBB_CPPFLAGS.
  23. XBB_CPPFLAGS="-I${XBB_FOLDER_PATH}/include ${XBB_CPPFLAGS}"
  24. if [ -d "${XBB_FOLDER_PATH}/lib" ]
  25. then
  26. # Add XBB lib in front of XBB_LDFLAGS.
  27. XBB_LDFLAGS="-L${XBB_FOLDER_PATH}/lib ${XBB_LDFLAGS}"
  28. XBB_LDFLAGS_LIB="-L${XBB_FOLDER_PATH}/lib ${XBB_LDFLAGS_LIB}"
  29. XBB_LDFLAGS_APP="-L${XBB_FOLDER_PATH}/lib ${XBB_LDFLAGS_APP}"
  30. XBB_LDFLAGS_APP_STATIC_GCC="-L${XBB_FOLDER_PATH}/lib ${XBB_LDFLAGS_APP_STATIC_GCC}"
  31. # Add XBB lib in front of PKG_CONFIG_PATH.
  32. if [ -d "${XBB_FOLDER_PATH}/lib/pkgconfig" ]
  33. then
  34. if [ -z "${PKG_CONFIG_PATH}" ]
  35. then
  36. PKG_CONFIG_PATH="${XBB_FOLDER_PATH}/lib/pkgconfig"
  37. else
  38. PKG_CONFIG_PATH="${XBB_FOLDER_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}"
  39. fi
  40. fi
  41. fi
  42. if [ -d "${XBB_FOLDER_PATH}/lib64" ]
  43. then
  44. # For 64-bit systems, add XBB lib64 in front of paths.
  45. XBB_LDFLAGS="-L${XBB_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_LIB}"
  46. XBB_LDFLAGS_LIB="-L${XBB_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_LIB}"
  47. XBB_LDFLAGS_APP="-L${XBB_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_APP}"
  48. XBB_LDFLAGS_APP_STATIC_GCC="-L${XBB_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_APP_STATIC_GCC}"
  49. if [ -d "${XBB_FOLDER_PATH}/lib64/pkgconfig" ]
  50. then
  51. if [ -z "${PKG_CONFIG_PATH}" ]
  52. then
  53. PKG_CONFIG_PATH="${XBB_FOLDER_PATH}/lib64/pkgconfig"
  54. else
  55. PKG_CONFIG_PATH="${XBB_FOLDER_PATH}/lib64/pkgconfig:${PKG_CONFIG_PATH}"
  56. fi
  57. fi
  58. fi
  59. export XBB_CPPFLAGS
  60. export XBB_LDFLAGS
  61. export XBB_LDFLAGS_LIB
  62. export XBB_LDFLAGS_APP
  63. export XBB_LDFLAGS_APP_STATIC_GCC
  64. export PKG_CONFIG_PATH
  65. }
  66. function xbb_activate_libs()
  67. {
  68. LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-""}
  69. if [ -d "${XBB_FOLDER_PATH}/lib" ]
  70. then
  71. if [ -z "${LD_LIBRARY_PATH}" ]
  72. then
  73. LD_LIBRARY_PATH="${XBB_FOLDER_PATH}/lib"
  74. else
  75. LD_LIBRARY_PATH="${XBB_FOLDER_PATH}/lib:${LD_LIBRARY_PATH}"
  76. fi
  77. fi
  78. if [ -d "${XBB_FOLDER_PATH}/lib64" ]
  79. then
  80. if [ -z "${LD_LIBRARY_PATH}" ]
  81. then
  82. LD_LIBRARY_PATH="${XBB_FOLDER_PATH}/lib64"
  83. else
  84. LD_LIBRARY_PATH="${XBB_FOLDER_PATH}/lib64:${LD_LIBRARY_PATH}"
  85. fi
  86. fi
  87. export LD_LIBRARY_PATH
  88. }
  89. # Add the freshly built binaries.
  90. function xbb_activate_installed_bin()
  91. {
  92. # Add the XBB bin to the PATH.
  93. PATH="${LIBS_INSTALL_FOLDER_PATH}/bin:${PATH}"
  94. export PATH
  95. }
  96. # Add the freshly built headrs and libraries.
  97. function xbb_activate_installed_dev()
  98. {
  99. # Add XBB include in front of XBB_CPPFLAGS.
  100. XBB_CPPFLAGS="-I${LIBS_INSTALL_FOLDER_PATH}/include ${XBB_CPPFLAGS}"
  101. if [ -d "${LIBS_INSTALL_FOLDER_PATH}/lib" ]
  102. then
  103. # Add XBB lib in front of XBB_LDFLAGS.
  104. XBB_LDFLAGS="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS}"
  105. XBB_LDFLAGS_LIB="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS_LIB}"
  106. XBB_LDFLAGS_APP="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS_APP}"
  107. XBB_LDFLAGS_APP_STATIC_GCC="-L${LIBS_INSTALL_FOLDER_PATH}/lib ${XBB_LDFLAGS_APP_STATIC_GCC}"
  108. # Add XBB lib in front of PKG_CONFIG_PATH.
  109. PKG_CONFIG_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}"
  110. # Needed by internal binaries, like the bootstrap compiler, which do not
  111. # have a rpath.
  112. if [ -z "${LD_LIBRARY_PATH}" ]
  113. then
  114. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib"
  115. else
  116. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib:${LD_LIBRARY_PATH}"
  117. fi
  118. fi
  119. # For just in case, apparently not used.
  120. if [ -d "${LIBS_INSTALL_FOLDER_PATH}/lib64" ]
  121. then
  122. # For 64-bit systems, add XBB lib64 in front of paths.
  123. XBB_LDFLAGS="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_LIB}"
  124. XBB_LDFLAGS_LIB="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_LIB}"
  125. XBB_LDFLAGS_APP="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_APP}"
  126. XBB_LDFLAGS_APP_STATIC_GCC="-L${LIBS_INSTALL_FOLDER_PATH}/lib64 ${XBB_LDFLAGS_APP_STATIC_GCC}"
  127. PKG_CONFIG_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib64/pkgconfig:${PKG_CONFIG_PATH}"
  128. if [ -z "${LD_LIBRARY_PATH}" ]
  129. then
  130. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib64"
  131. else
  132. LD_LIBRARY_PATH="${LIBS_INSTALL_FOLDER_PATH}/lib64:${LD_LIBRARY_PATH}"
  133. fi
  134. fi
  135. export XBB_CPPFLAGS
  136. export XBB_LDFLAGS
  137. export XBB_LDFLAGS_LIB
  138. export XBB_LDFLAGS_APP
  139. export XBB_LDFLAGS_APP_STATIC_GCC
  140. export PKG_CONFIG_PATH
  141. export LD_LIBRARY_PATH
  142. echo
  143. env | sort
  144. }
  145. function xbb_activate_tex()
  146. {
  147. :
  148. }
  149. # -----------------------------------------------------------------------------
  150. function do_config_guess()
  151. {
  152. if [ -f "${XBB_FOLDER_PATH}/share/libtool/build-aux/config.guess" ]
  153. then
  154. BUILD="$(${XBB_FOLDER_PATH}/share/libtool/build-aux/config.guess)"
  155. elif [ -f "/usr/share/libtool/build-aux/config.guess" ]
  156. then
  157. BUILD="$(/usr/share/libtool/build-aux/config.guess)"
  158. elif [ -f "/usr/share/misc/config.guess" ]
  159. then
  160. BUILD="$(/usr/share/misc/config.guess)"
  161. else
  162. echo "Could not find config.guess."
  163. exit 1
  164. fi
  165. }
  166. function prepare_xbb_env()
  167. {
  168. # Defaults, to ensure the variables are defined.
  169. PATH="${PATH:-""}"
  170. LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-""}"
  171. if [ -f "${HOME}/opt/xbb/xbb-source.sh" ]
  172. then
  173. XBB_FOLDER_PATH="${HOME}/opt/xbb"
  174. echo
  175. echo "Sourcing ${HOME}/opt/xbb/xbb-source.sh..."
  176. source "${HOME}/opt/xbb/xbb-source.sh"
  177. elif [ -f "${HOME}/opt/homebrew/xbb/xbb-source.sh" ]
  178. then
  179. XBB_FOLDER_PATH="${HOME}/opt/homebrew/xbb"
  180. # Deprecated, on macOS it was moved to HOME/opt/xbb
  181. echo
  182. echo "Sourcing ${HOME}/opt/homebrew/xbb/xbb-source.sh..."
  183. source "${HOME}/opt/homebrew/xbb/xbb-source.sh"
  184. elif [ -f "/opt/xbb/xbb-source.sh" ]
  185. then
  186. XBB_FOLDER_PATH="/opt/xbb"
  187. echo
  188. echo "Sourcing /opt/xbb/xbb-source.sh..."
  189. source "/opt/xbb/xbb-source.sh"
  190. else
  191. XBB_FOLDER_PATH=""
  192. fi
  193. TARGET_FOLDER_NAME="${TARGET_PLATFORM}-${TARGET_ARCH}"
  194. # Compute the BUILD/HOST/TARGET for configure.
  195. CROSS_COMPILE_PREFIX=""
  196. if [ "${TARGET_PLATFORM}" == "win32" ]
  197. then
  198. # Disable test when cross compiling for Windows.
  199. WITH_TESTS="n"
  200. # For Windows targets, decide which cross toolchain to use.
  201. if [ ${TARGET_ARCH} == "x32" ]
  202. then
  203. CROSS_COMPILE_PREFIX="i686-w64-mingw32"
  204. elif [ ${TARGET_ARCH} == "x64" ]
  205. then
  206. CROSS_COMPILE_PREFIX="x86_64-w64-mingw32"
  207. else
  208. echo "Oops! Unsupported ${TARGET_ARCH}."
  209. exit 1
  210. fi
  211. do_config_guess
  212. HOST="${CROSS_COMPILE_PREFIX}"
  213. TARGET="${HOST}"
  214. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  215. then
  216. do_config_guess
  217. HOST="${BUILD}"
  218. TARGET="${HOST}"
  219. elif [ "${TARGET_PLATFORM}" == "linux" ]
  220. then
  221. do_config_guess
  222. HOST="${BUILD}"
  223. TARGET="${HOST}"
  224. else
  225. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  226. exit 1
  227. fi
  228. if [ -f "/.dockerenv" ]
  229. then
  230. WORK_FOLDER_PATH="${CONTAINER_WORK_FOLDER_PATH}"
  231. DOWNLOAD_FOLDER_PATH="${CONTAINER_CACHE_FOLDER_PATH}"
  232. else
  233. WORK_FOLDER_PATH="${HOST_WORK_FOLDER_PATH}"
  234. DOWNLOAD_FOLDER_PATH="${HOST_CACHE_FOLDER_PATH}"
  235. fi
  236. # Develop builds use the host folder.
  237. BUILD_FOLDER_PATH="${WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/build"
  238. if [ -f "/.dockerenv" ]
  239. then
  240. if [ "${IS_DEVELOP}" != "y" ]
  241. then
  242. # Docker builds use a temporary folder.
  243. BUILD_FOLDER_PATH="/tmp/${TARGET_FOLDER_NAME}/build"
  244. fi
  245. fi
  246. LIBS_BUILD_FOLDER_PATH="${BUILD_FOLDER_PATH}/libs"
  247. mkdir -pv "${LIBS_BUILD_FOLDER_PATH}"
  248. APP_BUILD_FOLDER_PATH="${BUILD_FOLDER_PATH}/${APP_LC_NAME}"
  249. # Do it later, only if needed.
  250. # mkdir -pv "${APP_BUILD_FOLDER_PATH}"
  251. INSTALL_FOLDER_PATH="${WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install"
  252. STAMPS_FOLDER_PATH="${INSTALL_FOLDER_PATH}"
  253. LIBS_INSTALL_FOLDER_PATH="${INSTALL_FOLDER_PATH}/libs"
  254. # Use explicit include & especially lib, to prevent compiler complaining
  255. # for missing folders.
  256. mkdir -pv "${LIBS_INSTALL_FOLDER_PATH}/include"
  257. mkdir -pv "${LIBS_INSTALL_FOLDER_PATH}/lib"
  258. APP_INSTALL_FOLDER_PATH="${INSTALL_FOLDER_PATH}/${APP_LC_NAME}"
  259. mkdir -pv "${APP_INSTALL_FOLDER_PATH}"
  260. LOGS_FOLDER_NAME=${LOGS_FOLDER_NAME:-"logs"}
  261. LOGS_FOLDER_PATH="${WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/${LOGS_FOLDER_NAME}"
  262. mkdir -pv "${LOGS_FOLDER_PATH}"
  263. DEPLOY_FOLDER_NAME=${DEPLOY_FOLDER_NAME:-"deploy"}
  264. DEPLOY_FOLDER_PATH="${WORK_FOLDER_PATH}/${DEPLOY_FOLDER_NAME}"
  265. # Do it later, only if needed.
  266. # mkdir -pv "${DEPLOY_FOLDER_PATH}"
  267. DISTRO_INFO_NAME=${DISTRO_INFO_NAME:-"distro-info"}
  268. BUILD_GIT_PATH="${WORK_FOLDER_PATH}/build.git"
  269. # ---------------------------------------------------------------------------
  270. APP_PREFIX="${INSTALL_FOLDER_PATH}/${APP_LC_NAME}"
  271. # The documentation location is now the same on all platforms.
  272. APP_PREFIX_DOC="${APP_PREFIX}/share/doc"
  273. # ---------------------------------------------------------------------------
  274. SOURCES_FOLDER_PATH=${SOURCES_FOLDER_PATH:-"${WORK_FOLDER_PATH}/sources"}
  275. mkdir -pv "${SOURCES_FOLDER_PATH}"
  276. # Empty defaults.
  277. IS_DEVELOP=${IS_DEVELOP:-""}
  278. IS_DEBUG=${IS_DEBUG:-""}
  279. WITH_PDF=${WITH_PDF:-""}
  280. WITH_HTML=${WITH_HTML:-""}
  281. WITH_TESTS=${WITH_TESTS:-""}
  282. # Redefine this to "y" to create files that include the architecture.
  283. HAS_NAME_ARCH=${HAS_NAME_ARCH:-""}
  284. USE_TAR_GZ=${USE_TAR_GZ:-"y"}
  285. USE_SINGLE_FOLDER_PATH=${USE_SINGLE_FOLDER_PATH:-"y"}
  286. # ---------------------------------------------------------------------------
  287. export LANGUAGE="en_US:en"
  288. export LANG="en_US.UTF-8"
  289. export LC_ALL="en_US.UTF-8"
  290. export LC_COLLATE="en_US.UTF-8"
  291. export LC_CTYPE="UTF-8"
  292. export LC_MESSAGES="en_US.UTF-8"
  293. export LC_MONETARY="en_US.UTF-8"
  294. export LC_NUMERIC="en_US.UTF-8"
  295. export LC_TIME="en_US.UTF-8"
  296. export PATH
  297. export LD_LIBRARY_PATH
  298. export SOURCES_FOLDER_PATH
  299. # libtool fails with the Ubuntu /bin/sh.
  300. export SHELL="/bin/bash"
  301. export CONFIG_SHELL="/bin/bash"
  302. echo
  303. env | sort
  304. }
  305. function prepare_xbb_extras()
  306. {
  307. # ---------------------------------------------------------------------------
  308. XBB_CPPFLAGS=""
  309. XBB_CFLAGS="-ffunction-sections -fdata-sections -pipe"
  310. XBB_CXXFLAGS="-ffunction-sections -fdata-sections -pipe"
  311. if [ "${TARGET_ARCH}" == "x64" -o "${TARGET_ARCH}" == "x32" ]
  312. then
  313. XBB_CFLAGS+=" -m${TARGET_BITS}"
  314. XBB_CXXFLAGS+=" -m${TARGET_BITS}"
  315. fi
  316. XBB_LDFLAGS=""
  317. if [ "${IS_DEBUG}" == "y" ]
  318. then
  319. XBB_CFLAGS+=" -g -O0"
  320. XBB_CXXFLAGS+=" -g -O0"
  321. XBB_LDFLAGS+=" -g -O0"
  322. else
  323. XBB_CFLAGS+=" -O2"
  324. XBB_CXXFLAGS+=" -O2"
  325. XBB_LDFLAGS+=" -O2"
  326. fi
  327. if [ ! -z "$(xbb_activate; which "g++-xbb")" ]
  328. then
  329. prepare_gcc_env "" "-xbb"
  330. elif [ ! -z "$(xbb_activate; which "g++-9")" ]
  331. then
  332. prepare_gcc_env "" "-9"
  333. elif [ ! -z "$(xbb_activate; which "g++-8")" ]
  334. then
  335. prepare_gcc_env "" "-8"
  336. elif [ ! -z "$(xbb_activate; which "g++-7")" ]
  337. then
  338. prepare_gcc_env "" "-7"
  339. else
  340. prepare_gcc_env "" ""
  341. fi
  342. if [ "${TARGET_PLATFORM}" == "linux" ]
  343. then
  344. # Do not add -static here, it fails.
  345. # Do not try to link pthread statically, it must match the system glibc.
  346. XBB_LDFLAGS_LIB="${XBB_LDFLAGS}"
  347. XBB_LDFLAGS_APP="${XBB_LDFLAGS} -Wl,--gc-sections"
  348. XBB_LDFLAGS_APP_STATIC_GCC="${XBB_LDFLAGS_APP} -static-libgcc -static-libstdc++"
  349. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  350. then
  351. # Note: macOS linker ignores -static-libstdc++, so
  352. # libstdc++.6.dylib should be handled.
  353. XBB_LDFLAGS+=" -Wl,-macosx_version_min,10.10"
  354. XBB_LDFLAGS_LIB="${XBB_LDFLAGS}"
  355. XBB_LDFLAGS_APP="${XBB_LDFLAGS} -Wl,-dead_strip"
  356. XBB_LDFLAGS_APP_STATIC_GCC="${XBB_LDFLAGS_APP}"
  357. elif [ "${TARGET_PLATFORM}" == "win32" ]
  358. then
  359. export NATIVE_CC=${CC}
  360. export NATIVE_CXX=${CXX}
  361. prepare_gcc_env "${CROSS_COMPILE_PREFIX}-"
  362. # CRT_glob is from Arm script
  363. # -static avoids libwinpthread-1.dll
  364. # -static-libgcc avoids libgcc_s_sjlj-1.dll
  365. XBB_LDFLAGS_LIB="${XBB_LDFLAGS}"
  366. XBB_LDFLAGS_APP="${XBB_LDFLAGS} -Wl,--gc-sections"
  367. XBB_LDFLAGS_APP_STATIC_GCC="${XBB_LDFLAGS_APP} -static-libgcc -static-libstdc++"
  368. else
  369. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  370. exit 1
  371. fi
  372. XBB_CFLAGS_NO_W="${XBB_CFLAGS} -w"
  373. XBB_CXXFLAGS_NO_W="${XBB_CXXFLAGS} -w"
  374. set +u
  375. if [ ! -z "${XBB_FOLDER_PATH}" -a -x "${XBB_FOLDER_PATH}/bin/pkg-config-verbose" ]
  376. then
  377. PKG_CONFIG="${XBB_FOLDER_PATH}/bin/pkg-config-verbose"
  378. else
  379. PKG_CONFIG="$(which pkg-config)"
  380. fi
  381. set -u
  382. # Hopefully defining it empty would be enough...
  383. PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-""}
  384. # Prevent pkg-config to search the system folders (configured in the
  385. # pkg-config at build time).
  386. PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-""}
  387. set +u
  388. echo
  389. echo "CC=${CC}"
  390. echo "CXX=${CXX}"
  391. echo "XBB_CPPFLAGS=${XBB_CPPFLAGS}"
  392. echo "XBB_CFLAGS=${XBB_CFLAGS}"
  393. echo "XBB_CXXFLAGS=${XBB_CXXFLAGS}"
  394. echo "XBB_LDFLAGS_LIB=${XBB_LDFLAGS_LIB}"
  395. echo "XBB_LDFLAGS_APP=${XBB_LDFLAGS_APP}"
  396. echo "XBB_LDFLAGS_APP_STATIC_GCC=${XBB_LDFLAGS_APP_STATIC_GCC}"
  397. echo "PKG_CONFIG=${PKG_CONFIG}"
  398. echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
  399. echo "PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR}"
  400. set -u
  401. (
  402. xbb_activate
  403. which ${CC}
  404. ${CC} --version
  405. which make
  406. make --version
  407. )
  408. # ---------------------------------------------------------------------------
  409. # CC & co were exported by prepare_gcc_env.
  410. export XBB_CPPFLAGS
  411. export XBB_CFLAGS
  412. export XBB_CXXFLAGS
  413. export XBB_CFLAGS_NO_W
  414. export XBB_CXXFLAGS_NO_W
  415. export XBB_LDFLAGS
  416. export XBB_LDFLAGS_LIB
  417. export XBB_LDFLAGS_APP
  418. export XBB_LDFLAGS_APP_STATIC_GCC
  419. export PKG_CONFIG
  420. export PKG_CONFIG_PATH
  421. export PKG_CONFIG_LIBDIR
  422. }
  423. function prepare_gcc_env()
  424. {
  425. local prefix="$1"
  426. local suffix
  427. if [ $# -ge 2 ]
  428. then
  429. suffix="$2"
  430. else
  431. suffix=""
  432. fi
  433. export CC="${prefix}gcc${suffix}"
  434. export CXX="${prefix}g++${suffix}"
  435. export AR="${prefix}gcc-ar${suffix}"
  436. export AS="${prefix}as"
  437. export DLLTOOL="${prefix}dlltool"
  438. export LD="${prefix}ld"
  439. export NM="${prefix}gcc-nm${suffix}"
  440. export OBJCOPY="${prefix}objcopy"
  441. export OBJDUMP="${prefix}objdump"
  442. export RANLIB="${prefix}gcc-ranlib${suffix}"
  443. export READELF="${prefix}readelf"
  444. export SIZE="${prefix}size"
  445. export STRIP="${prefix}strip"
  446. export WINDRES="${prefix}windres"
  447. export WINDMC="${prefix}windmc"
  448. export RC="${prefix}windres"
  449. }
  450. function unset_gcc_env()
  451. {
  452. unset CC
  453. unset CXX
  454. unset AR
  455. unset AS
  456. unset DLLTOOL
  457. unset LD
  458. unset NM
  459. unset OBJCOPY
  460. unset OBJDUMP
  461. unset RANLIB
  462. unset READELF
  463. unset SIZE
  464. unset STRIP
  465. unset WINDRES
  466. unset WINDMC
  467. unset RC
  468. }
  469. # -----------------------------------------------------------------------------
  470. function do_actions()
  471. {
  472. if [ "${ACTION}" == "clean" ]
  473. then
  474. echo
  475. if [ "${IS_NATIVE}" == "y" ]
  476. then
  477. echo "Removing the ${TARGET_FOLDER_NAME} build and install ${APP_LC_NAME} folders..."
  478. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/build/${APP_LC_NAME}"
  479. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install/${APP_LC_NAME}"
  480. elif [ ! -z "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}${DO_BUILD_OSX}" ]
  481. then
  482. if [ "${DO_BUILD_WIN32}" == "y" ]
  483. then
  484. echo "Removing the win32-x32 build and install ${APP_LC_NAME} folders..."
  485. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/build/${APP_LC_NAME}"
  486. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/install/${APP_LC_NAME}"
  487. fi
  488. if [ "${DO_BUILD_WIN64}" == "y" ]
  489. then
  490. echo "Removing the win32-x64 build and install ${APP_LC_NAME} folders..."
  491. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/build/${APP_LC_NAME}"
  492. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/install/${APP_LC_NAME}"
  493. fi
  494. if [ "${DO_BUILD_LINUX32}" == "y" ]
  495. then
  496. echo "Removing the linux-x32 build and install ${APP_LC_NAME} folders..."
  497. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/build/${APP_LC_NAME}"
  498. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/install/${APP_LC_NAME}"
  499. fi
  500. if [ "${DO_BUILD_LINUX64}" == "y" ]
  501. then
  502. echo "Removing the linux-x64 build and install ${APP_LC_NAME} folders..."
  503. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/build/${APP_LC_NAME}"
  504. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/install/${APP_LC_NAME}"
  505. fi
  506. if [ "${DO_BUILD_OSX}" == "y" ]
  507. then
  508. echo "Removing the darwin-x64 build and install ${APP_LC_NAME} folders..."
  509. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/build/${APP_LC_NAME}"
  510. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/install/${APP_LC_NAME}"
  511. fi
  512. else
  513. echo "Removing the ${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH} build and install ${APP_LC_NAME} folders..."
  514. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/build/${APP_LC_NAME}"
  515. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/install/${APP_LC_NAME}"
  516. fi
  517. fi
  518. if [ "${ACTION}" == "cleanlibs" ]
  519. then
  520. echo
  521. if [ "${IS_NATIVE}" == "y" ]
  522. then
  523. echo "Removing the ${TARGET_FOLDER_NAME} build and install libs folders..."
  524. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/build/libs"
  525. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install/libs"
  526. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}/install"/stamp-*-installed
  527. elif [ ! -z "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}${DO_BUILD_OSX}" ]
  528. then
  529. if [ "${DO_BUILD_WIN32}" == "y" ]
  530. then
  531. echo "Removing the win32-x32 build and install libs folders..."
  532. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/build/libs"
  533. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/install/libs"
  534. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32/install"/stamp-*-installed
  535. fi
  536. if [ "${DO_BUILD_WIN64}" == "y" ]
  537. then
  538. echo "Removing the win32-x64 build and install libs folders..."
  539. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/build/libs"
  540. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/install/libs"
  541. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64/install"/stamp-*-installed
  542. fi
  543. if [ "${DO_BUILD_LINUX32}" == "y" ]
  544. then
  545. echo "Removing the linux-x32 build and install libs folders..."
  546. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/build/libs"
  547. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/install/libs"
  548. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32/install"/stamp-*-installed
  549. fi
  550. if [ "${DO_BUILD_LINUX64}" == "y" ]
  551. then
  552. echo "Removing the linux-x64 build and install libs folders..."
  553. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/build/libs"
  554. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/install/libs"
  555. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64/install"/stamp-*-installed
  556. fi
  557. if [ "${DO_BUILD_OSX}" == "y" ]
  558. then
  559. echo "Removing the darwin-x64 build and install libs folders..."
  560. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/build/libs"
  561. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/install/libs"
  562. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64/install"/stamp-*-installed
  563. fi
  564. else
  565. echo "Removing the ${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH} build and install libs folders..."
  566. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/build/libs"
  567. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/install/libs"
  568. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}/install"/stamp-*-installed
  569. fi
  570. fi
  571. if [ "${ACTION}" == "cleanall" ]
  572. then
  573. echo
  574. if [ "${IS_NATIVE}" == "y" ]
  575. then
  576. echo "Removing the ${TARGET_FOLDER_NAME} folder..."
  577. rm -rf "${HOST_WORK_FOLDER_PATH}/${TARGET_FOLDER_NAME}"
  578. elif [ ! -z "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}${DO_BUILD_OSX}" ]
  579. then
  580. if [ "${DO_BUILD_WIN32}" == "y" ]
  581. then
  582. echo "Removing the win32-x32 folder..."
  583. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x32"
  584. fi
  585. if [ "${DO_BUILD_WIN64}" == "y" ]
  586. then
  587. echo "Removing the win32-x64 folder..."
  588. rm -rf "${HOST_WORK_FOLDER_PATH}/win32-x64"
  589. fi
  590. if [ "${DO_BUILD_LINUX32}" == "y" ]
  591. then
  592. echo "Removing the linux-x32 folder..."
  593. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x32"
  594. fi
  595. if [ "${DO_BUILD_LINUX64}" == "y" ]
  596. then
  597. echo "Removing the linux-x64 folder..."
  598. rm -rf "${HOST_WORK_FOLDER_PATH}/linux-x64"
  599. fi
  600. if [ "${DO_BUILD_OSX}" == "y" ]
  601. then
  602. echo "Removing the darwin-x64 folder..."
  603. rm -rf "${HOST_WORK_FOLDER_PATH}/darwin-x64"
  604. fi
  605. else
  606. echo "Removing the ${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH} folder..."
  607. rm -rf "${HOST_WORK_FOLDER_PATH}/${HOST_NODE_PLATFORM}-${HOST_NODE_ARCH}"
  608. fi
  609. fi
  610. if [ "${ACTION}" == "clean" -o "${ACTION}" == "cleanlibs" -o "${ACTION}" == "cleanall" ]
  611. then
  612. echo
  613. echo "Clean completed. Proceed with a regular build."
  614. exit 0
  615. fi
  616. # Not used for native buils. Otherwise the names of the docker images
  617. # must be set.
  618. if [ "${ACTION}" == "preload-images" ]
  619. then
  620. host_start_timer
  621. host_prepare_docker
  622. echo
  623. echo "Check/Preload Docker images..."
  624. if [ "${HOST_MACHINE}" == "aarch64" -o "${HOST_MACHINE}" == "armv7l" -o "${HOST_MACHINE}" == "armv8l" ]
  625. then
  626. echo
  627. docker run --interactive --tty "${docker_linux_arm64_image}" \
  628. lsb_release --description --short
  629. echo
  630. docker run --interactive --tty "${docker_linux_arm32_image}" \
  631. lsb_release --description --short
  632. else
  633. echo
  634. docker run --interactive --tty "${docker_linux64_image}" \
  635. lsb_release --description --short
  636. echo
  637. docker run --interactive --tty "${docker_linux32_image}" \
  638. lsb_release --description --short
  639. fi
  640. echo
  641. docker images
  642. host_stop_timer
  643. exit 0
  644. fi
  645. }
  646. # -----------------------------------------------------------------------------
  647. function run_verbose()
  648. {
  649. # Does not include the .exe extension.
  650. local app_path=$1
  651. shift
  652. echo
  653. echo "[${app_path} $@]"
  654. "${app_path}" "$@" 2>&1
  655. }
  656. function run_app()
  657. {
  658. # Does not include the .exe extension.
  659. local app_path=$1
  660. shift
  661. echo
  662. echo "${app_path} $@"
  663. if [ "${TARGET_PLATFORM}" == "linux" ]
  664. then
  665. "${app_path}" "$@"
  666. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  667. then
  668. "${app_path}" "$@"
  669. elif [ "${TARGET_PLATFORM}" == "win32" ]
  670. then
  671. local wsl_path=$(which wsl.exe)
  672. if [ ! -z "${wsl_path}" ]
  673. then
  674. "${app_path}.exe" "$@"
  675. else
  676. (
  677. xbb_activate
  678. local wine_path=$(which wine)
  679. if [ ! -z "${wine_path}" ]
  680. then
  681. wine "${app_path}.exe" "$@"
  682. else
  683. echo "Install wine if you want to run the .exe binaries on Linux."
  684. fi
  685. )
  686. fi
  687. else
  688. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  689. exit 1
  690. fi
  691. }
  692. function show_libs()
  693. {
  694. # Does not include the .exe extension.
  695. local app_path=$1
  696. shift
  697. (
  698. xbb_activate
  699. if [ "${TARGET_PLATFORM}" == "linux" ]
  700. then
  701. echo
  702. echo "readelf -d ${app_path} | grep 'ibrary'"
  703. # Ignore errors in case it is not using shared libraries.
  704. set +e
  705. readelf -d "${app_path}" | grep 'ibrary'
  706. echo "ldd -v ${app_path}"
  707. ldd -v "${app_path}"
  708. set -e
  709. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  710. then
  711. echo
  712. echo "otool -L ${app_path}"
  713. otool -L "${app_path}"
  714. elif [ "${TARGET_PLATFORM}" == "win32" ]
  715. then
  716. echo
  717. echo ${CROSS_COMPILE_PREFIX}-objdump -x ${app_path}.exe
  718. ${CROSS_COMPILE_PREFIX}-objdump -x ${app_path}.exe | grep -i 'DLL Name'
  719. else
  720. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  721. exit 1
  722. fi
  723. )
  724. }
  725. # -----------------------------------------------------------------------------
  726. function do_patch()
  727. {
  728. if [ ! -z "$1" ]
  729. then
  730. local patch_file_name="$1"
  731. local patch_path="${BUILD_GIT_PATH}/patches/${patch_file_name}"
  732. if [ -f "${patch_path}" ]
  733. then
  734. echo "Patching..."
  735. patch -p0 < "${patch_path}"
  736. fi
  737. fi
  738. }
  739. function extract()
  740. {
  741. local archive_name="$1"
  742. local folder_name="$2"
  743. # local patch_file_name="$3"
  744. local pwd="$(pwd)"
  745. if [ ! -d "${folder_name}" ]
  746. then
  747. (
  748. xbb_activate
  749. echo
  750. echo "Extracting \"${archive_name}\" -> \"${pwd}/${folder_name}\"..."
  751. if [[ "${archive_name}" == *zip ]]
  752. then
  753. unzip "${archive_name}"
  754. else
  755. if [ ! -z "${DEBUG}" ]
  756. then
  757. tar -x -v -f "${archive_name}"
  758. else
  759. tar -x -f "${archive_name}"
  760. fi
  761. fi
  762. if [ $# -ge 3 ]
  763. then
  764. cd "${folder_name}"
  765. do_patch "$3"
  766. fi
  767. )
  768. else
  769. echo "Folder \"${pwd}/${folder_name}\" already present."
  770. fi
  771. }
  772. function download()
  773. {
  774. local url="$1"
  775. local archive_name="$2"
  776. if [ ! -f "${DOWNLOAD_FOLDER_PATH}/${archive_name}" ]
  777. then
  778. (
  779. xbb_activate
  780. echo
  781. echo "Downloading \"${archive_name}\" from \"${url}\"..."
  782. rm -f "${DOWNLOAD_FOLDER_PATH}/${archive_name}.download"
  783. mkdir -pv "${DOWNLOAD_FOLDER_PATH}"
  784. curl --fail -L -o "${DOWNLOAD_FOLDER_PATH}/${archive_name}.download" "${url}"
  785. mv "${DOWNLOAD_FOLDER_PATH}/${archive_name}.download" "${DOWNLOAD_FOLDER_PATH}/${archive_name}"
  786. )
  787. else
  788. echo "File \"${DOWNLOAD_FOLDER_PATH}/${archive_name}\" already downloaded."
  789. fi
  790. }
  791. # $4 is the patch file name
  792. function download_and_extract()
  793. {
  794. local url="$1"
  795. local archive_name="$2"
  796. local folder_name="$3"
  797. download "${url}" "${archive_name}"
  798. if [ $# -ge 4 ]
  799. then
  800. extract "${DOWNLOAD_FOLDER_PATH}/${archive_name}" "${folder_name}" "$4"
  801. else
  802. extract "${DOWNLOAD_FOLDER_PATH}/${archive_name}" "${folder_name}"
  803. fi
  804. }
  805. function git_clone()
  806. {
  807. local url="$1"
  808. local branch="$2"
  809. local commit="$3"
  810. local folder_name="$4"
  811. (
  812. echo
  813. echo "Cloning \"${folder_name}\" from \"${url}\"..."
  814. git clone --branch="${branch}" "${url}" "${folder_name}"
  815. if [ -n "${commit}" ]
  816. then
  817. cd "${folder_name}"
  818. git checkout -qf "${commit}"
  819. fi
  820. )
  821. }
  822. # Copy the build files to the Work area, to make them easily available.
  823. function copy_build_git()
  824. {
  825. rm -rf "${HOST_WORK_FOLDER_PATH}/build.git"
  826. mkdir -pv "${HOST_WORK_FOLDER_PATH}/build.git"
  827. cp -r "$(dirname ${script_folder_path})"/* "${HOST_WORK_FOLDER_PATH}/build.git"
  828. rm -rf "${HOST_WORK_FOLDER_PATH}/build.git/scripts/helper/.git"
  829. rm -rf "${HOST_WORK_FOLDER_PATH}/build.git/scripts/helper/build-helper.sh"
  830. }
  831. # -----------------------------------------------------------------------------
  832. function check_binary()
  833. {
  834. local file_path="$1"
  835. if [ ! -x "${file_path}" ]
  836. then
  837. return 0
  838. fi
  839. if file --mime "${file_path}" | grep -q text
  840. then
  841. return 0
  842. fi
  843. check_binary_for_libraries "$1"
  844. }
  845. function check_binary_for_libraries()
  846. {
  847. local file_path="$1"
  848. local file_name="$(basename ${file_path})"
  849. local folder_path="$(dirname ${file_path})"
  850. (
  851. xbb_activate
  852. if [ "${TARGET_PLATFORM}" == "win32" ]
  853. then
  854. echo
  855. echo "${file_name} (${file_path})"
  856. set +e
  857. ${CROSS_COMPILE_PREFIX}-objdump -x "${file_path}" | grep -i 'DLL Name'
  858. local dll_names=$(${CROSS_COMPILE_PREFIX}-objdump -x "${file_path}" \
  859. | grep -i 'DLL Name' \
  860. | sed -e 's/.*DLL Name: \(.*\)/\1/' \
  861. )
  862. local n
  863. for n in ${dll_names}
  864. do
  865. if [ ! -f "${folder_path}/${n}" ]
  866. then
  867. if is_win_sys_dll "${n}"
  868. then
  869. :
  870. elif [ "${n}${HAS_WINPTHREAD}" == "libwinpthread-1.dlly" ]
  871. then
  872. :
  873. elif [[ ${n} == python*.dll ]] && [[ ${file_name} == *-gdb-py.exe ]]
  874. then
  875. :
  876. else
  877. echo "Unexpected |${n}|"
  878. exit 1
  879. fi
  880. fi
  881. done
  882. set -e
  883. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  884. then
  885. echo
  886. (
  887. set +e
  888. cd ${folder_path}
  889. otool -L "${file_name}"
  890. set -e
  891. )
  892. # Skip the first line which is the binary itself.
  893. local libs
  894. if [[ "${file_name}" == *\.dylib ]]
  895. then
  896. # Skip the second line too, which is the library again.
  897. lib_names=$(otool -L "${file_path}" \
  898. | sed '1d' \
  899. | sed '1d' \
  900. | sed -e 's|[[:space:]]*\(.*\) (.*)|\1|' \
  901. )
  902. else
  903. lib_names=$(otool -L "${file_path}" \
  904. | sed '1d' \
  905. | sed -e 's|[[:space:]]*\(.*\) (.*)|\1|' \
  906. )
  907. fi
  908. for lib_name in ${lib_names}
  909. do
  910. if [ "${lib_name:0:1}" != "@" ]
  911. then
  912. if ! is_darwin_allowed_sys_dylib "${lib_name}"
  913. then
  914. echo ">>> \"${lib_name}\" is not expected here"
  915. exit 1
  916. fi
  917. fi
  918. done
  919. # More or less deprecated by the above.
  920. set +e
  921. local unxp
  922. if [[ "${file_name}" == *\.dylib ]]
  923. then
  924. unxp=$(otool -L "${file_path}" | sed '1d' | sed '1d' | grep -v "${file_name}" | egrep -e "(macports|homebrew|opt|install)/")
  925. else
  926. unxp=$(otool -L "${file_path}" | sed '1d' | grep -v "${file_name}" | egrep -e "(macports|homebrew|opt|install)/")
  927. fi
  928. set -e
  929. # echo "|${unxp}|"
  930. if [ ! -z "$unxp" ]
  931. then
  932. echo "Unexpected |${unxp}|"
  933. exit 1
  934. fi
  935. elif [ "${TARGET_PLATFORM}" == "linux" ]
  936. then
  937. echo
  938. echo "${file_name} (${file_path})"
  939. set +e
  940. readelf -d "${file_path}" | egrep -i '(SONAME)'
  941. readelf -d "${file_path}" | egrep -i '(RUNPATH|RPATH)'
  942. readelf -d "${file_path}" | egrep -i '(NEEDED)'
  943. local so_names=$(readelf -d "${file_path}" \
  944. | grep -i 'Shared library' \
  945. | sed -e 's/.*Shared library: \[\(.*\)\]/\1/' \
  946. )
  947. local relative_path=$(readelf -d "${file_path}" | egrep -i '(RUNPATH|RPATH)' | sed -e 's/.*\[\$ORIGIN//' | sed -e 's/\].*//')
  948. # echo $relative_path
  949. for so_name in ${so_names}
  950. do
  951. if [ ! -f "${folder_path}${relative_path}/${so_name}" ]
  952. then
  953. if is_linux_sys_so "${so_name}"
  954. then
  955. :
  956. elif [[ ${so_name} == libpython* ]] && [[ ${file_name} == *-gdb-py ]]
  957. then
  958. :
  959. else
  960. echo "Unexpected |${so_name}|"
  961. exit 1
  962. fi
  963. fi
  964. done
  965. set -e
  966. else
  967. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  968. exit 1
  969. fi
  970. )
  971. }
  972. function is_win_sys_dll()
  973. {
  974. local dll_name="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
  975. # DLLs that are expected to be present on any Windows.
  976. # Be sure all names are lower case!
  977. local sys_dlls=( \
  978. advapi32.dll \
  979. cfgmgr32.dll \
  980. crypt32.dll \
  981. dnsapi.dll \
  982. gdi32.dll \
  983. imm32.dll \
  984. imm32.dll \
  985. iphlpapi.dll \
  986. iphlpapi.dll \
  987. kernel32.dll \
  988. msvcr90.dll \
  989. oleaut32.dll \
  990. psapi.dll \
  991. rpcrt4.dll \
  992. setupapi.dll \
  993. shell32.dll \
  994. shlwapi.dll \
  995. user32.dll \
  996. userenv.dll \
  997. vcruntime140.dll \
  998. version.dll \
  999. winmm.dll \
  1000. winmm.dll \
  1001. ws2_32.dll \
  1002. \
  1003. msvcrt.dll \
  1004. ole32.dll \
  1005. api-ms-win-crt-runtime-l1-1-0.dll \
  1006. api-ms-win-crt-math-l1-1-0.dll \
  1007. api-ms-win-crt-locale-l1-1-0.dll \
  1008. api-ms-win-crt-string-l1-1-0.dll \
  1009. api-ms-win-crt-stdio-l1-1-0.dll \
  1010. api-ms-win-crt-convert-l1-1-0.dll \
  1011. api-ms-win-crt-time-l1-1-0.dll \
  1012. api-ms-win-crt-environment-l1-1-0.dll \
  1013. api-ms-win-crt-process-l1-1-0.dll \
  1014. api-ms-win-crt-heap-l1-1-0.dll \
  1015. api-ms-win-crt-conio-l1-1-0.dll \
  1016. api-ms-win-crt-filesystem-l1-1-0.dll \
  1017. )
  1018. # The Python DLL were a permanent source of trouble.
  1019. # python27.dll \
  1020. # The latest Python 2.7.18 has no DLL at all, so it cannot be skipped.
  1021. # python37.dll \
  1022. # The Python 3 seems better, allow to copy it in the archive,
  1023. # to be sure it matches the version used during build.
  1024. local dll
  1025. for dll in "${sys_dlls[@]}"
  1026. do
  1027. if [ "${dll}" == "${dll_name}" ]
  1028. then
  1029. return 0 # True
  1030. fi
  1031. done
  1032. return 1 # False
  1033. }
  1034. function is_linux_sys_so()
  1035. {
  1036. local lib_name="$1"
  1037. # Do not add these two, they are present if the toolchain is installed,
  1038. # but this is not guaranteed, so better copy them from the xbb toolchain.
  1039. # libstdc++.so.6
  1040. # libgcc_s.so.1
  1041. # Shared libraries that are expected to be present on any Linux.
  1042. # Note the X11 libraries.
  1043. local sys_lib_names=(\
  1044. librt.so.1 \
  1045. libm.so.6 \
  1046. libc.so.6 \
  1047. libutil.so.1 \
  1048. libpthread.so.0 \
  1049. libdl.so.2 \
  1050. ld-linux.so.2 \
  1051. ld-linux.so.3 \
  1052. ld-linux-x86-64.so.2 \
  1053. ld-linux-armhf.so.3 \
  1054. ld-linux-arm64.so.1 \
  1055. ld-linux-aarch64.so.1 \
  1056. libX11.so.6 \
  1057. libXau.so.6 \
  1058. libxcb.so.1 \
  1059. )
  1060. local sys_lib_name
  1061. for sys_lib_name in "${sys_lib_names[@]}"
  1062. do
  1063. if [ "${lib_name}" == "${sys_lib_name}" ]
  1064. then
  1065. return 0 # True
  1066. fi
  1067. done
  1068. return 1 # False
  1069. }
  1070. function is_darwin_sys_dylib()
  1071. {
  1072. local lib_name="$1"
  1073. if [[ ${lib_name} == /usr/lib* ]]
  1074. then
  1075. return 0 # True
  1076. fi
  1077. if [[ ${lib_name} == /System/Library/Frameworks/* ]]
  1078. then
  1079. return 0 # True
  1080. fi
  1081. if [[ ${lib_name} == /Library/Frameworks/* ]]
  1082. then
  1083. return 0 # True
  1084. fi
  1085. return 1 # False
  1086. }
  1087. function is_darwin_allowed_sys_dylib()
  1088. {
  1089. local lib_name="$1"
  1090. # Since there is no -static-libc++, the first attempt was to not
  1091. # define these here and have the 10.10 ones copied to the application.
  1092. # Building CMake proved that this is ok with 10.11 and 10.12, but
  1093. # failes on 10.13 and 10.14 with:
  1094. # dyld: Symbol not found: __ZNSt3__118shared_timed_mutex13unlock_sharedEv
  1095. # Referenced from: /System/Library/Frameworks/CoreDisplay.framework/Versions/A/CoreDisplay
  1096. # Expected in: /Users/travis/test-cmake/xpack-cmake-3.17.1-1/bin/libc++.1.dylib
  1097. # in /System/Library/Frameworks/CoreDisplay.framework/Versions/A/CoreDisplay
  1098. #
  1099. # /usr/lib/libc++.dylib \
  1100. # /usr/lib/libc++.1.dylib \
  1101. # /usr/lib/libc++abi.dylib \
  1102. # Same for -static-libgcc; there were no cases which failed on later releases,
  1103. # but for consistency, they are also included here.
  1104. #
  1105. # /usr/lib/libgcc_s.1.dylib \
  1106. local sys_libs=(\
  1107. /usr/lib/libgcc_s.1.dylib \
  1108. /
  1109. /usr/lib/libc++.dylib \
  1110. /usr/lib/libc++.1.dylib \
  1111. /usr/lib/libc++abi.dylib \
  1112. /
  1113. /usr/lib/libSystem.B.dylib \
  1114. /usr/lib/libobjc.A.dylib \
  1115. )
  1116. if [[ ${lib_name} == /System/Library/Frameworks/* ]]
  1117. then
  1118. # Allow all system frameworks.
  1119. return 0 # True
  1120. fi
  1121. local lib
  1122. for lib in "${sys_libs[@]}"
  1123. do
  1124. if [ "${lib}" == "${lib_name}" ]
  1125. then
  1126. return 0 # True
  1127. fi
  1128. done
  1129. return 1 # False
  1130. }
  1131. # -----------------------------------------------------------------------------
  1132. function has_origin()
  1133. {
  1134. if [ $# -lt 1 ]
  1135. then
  1136. warning "has_origin: Missing file argument"
  1137. exit 1
  1138. fi
  1139. local bin="$1"
  1140. if [ "${TARGET_PLATFORM}" == "linux" ]
  1141. then
  1142. local origin=$(readelf -d ${bin} | grep 'Library runpath: \[$ORIGIN\]')
  1143. if [ ! -z "${origin}" ]
  1144. then
  1145. return 0 # true
  1146. fi
  1147. fi
  1148. return 1 # false
  1149. }
  1150. # Strip binary files as in "strip binary" form, for both native
  1151. # (linux/mac) and mingw.
  1152. function strip_binary2()
  1153. {
  1154. (
  1155. set +e
  1156. if [ $# -lt 2 ]
  1157. then
  1158. warning "strip_binary: Missing arguments"
  1159. exit 1
  1160. fi
  1161. local strip="$1"
  1162. local bin="$2"
  1163. if is_elf "${bin}"
  1164. then
  1165. if has_origin "${bin}"
  1166. then
  1167. echo "${strip} ${bin} skipped (patched)"
  1168. else
  1169. echo "${strip} ${bin}"
  1170. # ${strip} ${bin} 2>/dev/null || true
  1171. "${strip}" -S "${bin}" || true
  1172. fi
  1173. else
  1174. echo $(file "${bin}")
  1175. fi
  1176. set -e
  1177. )
  1178. }
  1179. function strip_binary()
  1180. {
  1181. if [ $# -lt 1 ]
  1182. then
  1183. warning "strip_binary: Missing file argument"
  1184. exit 1
  1185. fi
  1186. local file_path="$1"
  1187. if ! is_elf "${file_path}"
  1188. then
  1189. echo $(file "${file_path}")
  1190. return
  1191. fi
  1192. local strip="strip"
  1193. if [ "${TARGET_PLATFORM}" == "win32" ]
  1194. then
  1195. strip="${CROSS_COMPILE_PREFIX}-strip"
  1196. if [[ "${file_path}" != *.exe ]] && [[ "${file_path}" != *.dll ]]
  1197. then
  1198. bin="${file_path}.exe"
  1199. fi
  1200. fi
  1201. if has_origin "${file_path}"
  1202. then
  1203. # If the file was patched, skip strip, otherwise
  1204. # we may damage the binary due to a bug in strip.
  1205. echo "${strip} ${file_path} skipped (patched)"
  1206. return
  1207. fi
  1208. echo "${strip} ${file_path}"
  1209. "${strip}" -S "${file_path}" || true
  1210. }
  1211. function is_elf()
  1212. {
  1213. if [ $# -lt 1 ]
  1214. then
  1215. warning "is_elf: Missing arguments"
  1216. exit 1
  1217. fi
  1218. local bin_path="$1"
  1219. # Symlinks do not match.
  1220. if [ -L "${bin_path}" ]
  1221. then
  1222. return 1
  1223. fi
  1224. if [ -f "${bin_path}" ]
  1225. then
  1226. # Return 0 (true) if found.
  1227. file ${bin_path} | egrep -q "( ELF )|( PE )|( PE32 )|( PE32\+ )|( Mach-O )"
  1228. else
  1229. return 1
  1230. fi
  1231. }
  1232. function is_ar()
  1233. {
  1234. if [ $# -lt 1 ]
  1235. then
  1236. warning "is_ar: Missing arguments"
  1237. exit 1
  1238. fi
  1239. local bin_path="$1"
  1240. # Symlinks do not match.
  1241. if [ -L "${bin_path}" ]
  1242. then
  1243. return 1
  1244. fi
  1245. if [ -f "${bin_path}" ]
  1246. then
  1247. # Return 0 (true) if found.
  1248. file ${bin_path} | egrep -q "ar archive"
  1249. else
  1250. return 1
  1251. fi
  1252. }
  1253. # -----------------------------------------------------------------------------
  1254. # Deprecated, use copy_dependencies_recursive().
  1255. function copy_win_gcc_dll()
  1256. {
  1257. local dll_name="$1"
  1258. # Identify the current cross gcc version, to locate the specific dll folder.
  1259. local cross_gcc_version=$(${CROSS_COMPILE_PREFIX}-gcc --version | grep 'gcc' | sed -e 's/.*\s\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\).*/\1.\2.\3/')
  1260. local cross_gcc_version_short=$(echo ${cross_gcc_version} | sed -e 's/\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\).*/\1.\2/')
  1261. local SUBLOCATION="-win32"
  1262. # First try Ubuntu specific locations,
  1263. # then do a long full search.
  1264. if [ -f "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}/lib/${dll_name}" ]
  1265. then
  1266. cp -v "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}/lib/${dll_name}" \
  1267. "${APP_PREFIX}/bin"
  1268. elif [ -f "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version}/${dll_name}" ]
  1269. then
  1270. cp -v "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version}/${dll_name}" \
  1271. "${APP_PREFIX}/bin"
  1272. elif [ -f "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}/${dll_name}" ]
  1273. then
  1274. cp -v "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}/${dll_name}" \
  1275. "${APP_PREFIX}/bin"
  1276. elif [ -f "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}${SUBLOCATION}/${dll_name}" ]
  1277. then
  1278. cp -v "/usr/lib/gcc/${CROSS_COMPILE_PREFIX}/${cross_gcc_version_short}${SUBLOCATION}/${dll_name}" \
  1279. "${APP_PREFIX}/bin"
  1280. else
  1281. echo "Searching /usr for ${dll_name}..."
  1282. SJLJ_PATH=$(find "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}" /usr \! -readable -prune -o -name ${dll_name} -print | grep ${CROSS_COMPILE_PREFIX})
  1283. cp -v ${SJLJ_PATH} "${APP_PREFIX}/bin"
  1284. fi
  1285. }
  1286. # Deprecated, use copy_dependencies_recursive().
  1287. function copy_win_libwinpthread_dll()
  1288. {
  1289. if [ -f "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}/bin/libwinpthread-1.dll" ]
  1290. then
  1291. cp "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}/bin/libwinpthread-1.dll" \
  1292. "${APP_PREFIX}/bin"
  1293. else
  1294. echo "No libwinpthread-1.dll"
  1295. exit 1
  1296. fi
  1297. }
  1298. # -----------------------------------------------------------------------------
  1299. function change_dylib()
  1300. {
  1301. local dylib_name="$1"
  1302. local file_path="$2"
  1303. local dylib_path="$(otool -L "${file_path}" | sed '1d' | sed -e 's|[[:space:]]*\(.*\)[[:space:]][(].*[)]|\1|' | grep "${dylib_name}")"
  1304. if [ -z "${dylib_path}" ]
  1305. then
  1306. echo "Dylib ${dylib_name} may not used in binary ${file_path}..."
  1307. # for example libftdi1.2.4.0.dylib has the name libftdi1.2.dylib.
  1308. # exit 1
  1309. elif [ $(printf "${dylib_path}" | wc -l) -gt 1 ]
  1310. then
  1311. echo "${file_path} has multiple ${dylib_name} libraries..."
  1312. exit 1
  1313. fi
  1314. # Hack to bring Python library name in line with the other libraries.
  1315. if [ "${dylib_name}" == "Python" ]
  1316. then
  1317. local version="$(otool -L "${file_path}" | grep "${dylib_name}" | sed -e 's|.*current version \([0-9][0-9]*\.[0-9][0-9]*\).*|\1|')"
  1318. dylib_name="libpython${version}.dylib"
  1319. rm -rf "$(dirname ${file_path})/Python"
  1320. fi
  1321. chmod +w "${file_path}"
  1322. install_name_tool \
  1323. -change "${dylib_path}" \
  1324. "@executable_path/${dylib_name}" \
  1325. "${file_path}"
  1326. if [ ! -f "$(dirname ${file_path})/${dylib_name}" ]
  1327. then
  1328. install -v -c -m 644 "${dylib_path}" "$(dirname ${file_path})/${dylib_name}"
  1329. fi
  1330. }
  1331. # Workaround to Docker error on 32-bit image:
  1332. # stat: Value too large for defined data type (requires -D_FILE_OFFSET_BITS=64)
  1333. function patch_linux_elf_origin()
  1334. {
  1335. if [ $# -lt 1 ]
  1336. then
  1337. echo "patch_linux_elf_origin requires 1 args."
  1338. exit 1
  1339. fi
  1340. local file_path="$1"
  1341. local libexec_path
  1342. if [ $# -ge 2 ]
  1343. then
  1344. libexec_path="$2"
  1345. else
  1346. libexec_path="$(dirname "${file_path}")"
  1347. fi
  1348. local tmp_path=$(mktemp)
  1349. rm -rf "${tmp_path}"
  1350. cp "${file_path}" "${tmp_path}"
  1351. if false
  1352. then
  1353. local relative_path="$(realpath --relative-to="$(dirname ${file_path})" "${libexec_path}")"
  1354. if [ "${IS_DEVELOP}" == "y" ]
  1355. then
  1356. echo "\$ORIGIN/${relative_path}" "${file_path}"
  1357. fi
  1358. patchelf --set-rpath "\$ORIGIN/${relative_path}" "${tmp_path}"
  1359. else
  1360. if file "${tmp_path}" | grep statically
  1361. then
  1362. file "${file_path}"
  1363. else
  1364. patchelf --set-rpath "\$ORIGIN" "${tmp_path}"
  1365. fi
  1366. fi
  1367. cp "${tmp_path}" "${file_path}"
  1368. rm -rf "${tmp_path}"
  1369. }
  1370. # $1 - absolute path to executable
  1371. # Note: must pass libexec path
  1372. # For single apps, otherwise use prepare_app_folder_libraries
  1373. # Does not use libexec.
  1374. function prepare_app_libraries()
  1375. {
  1376. local app_path="$1"
  1377. shift
  1378. (
  1379. xbb_activate
  1380. local app_folder_path="$(dirname "${app_path}")"
  1381. if [ "${WITH_STRIP}" == "y" ]
  1382. then
  1383. strip_binary "${app_path}"
  1384. fi
  1385. if [ "${TARGET_PLATFORM}" == "linux" ]
  1386. then
  1387. echo
  1388. echo "Shared libraries:"
  1389. echo "${app_path}"
  1390. set +e
  1391. readelf -d "${app_path}" | grep 'Shared library:'
  1392. set -e
  1393. echo
  1394. echo "Preparing libraries..."
  1395. patch_linux_elf_origin "${app_path}"
  1396. echo
  1397. copy_dependencies_recursive "${app_path}" "${app_folder_path}"
  1398. echo
  1399. echo "Updated shared libraries:"
  1400. echo ldd -v "${app_path}"
  1401. ldd -v "${app_path}"
  1402. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1403. then
  1404. echo
  1405. echo "Initial dynamic libraries:"
  1406. otool -L "${app_path}"
  1407. echo
  1408. echo "Preparing libraries..."
  1409. copy_dependencies_recursive "${app_path}" "${app_folder_path}"
  1410. echo
  1411. echo "Updated dynamic libraries:"
  1412. otool -L "${app_path}"
  1413. elif [ "${TARGET_PLATFORM}" == "win32" ]
  1414. then
  1415. echo
  1416. echo "Dynamic libraries:"
  1417. echo "${app_path}.exe"
  1418. ${CROSS_COMPILE_PREFIX}-objdump -x "${app_path}.exe" | grep -i 'DLL Name'
  1419. echo
  1420. echo "Preparing libraries..."
  1421. copy_dependencies_recursive "${app_path}.exe" "${app_folder_path}"
  1422. else
  1423. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  1424. exit 1
  1425. fi
  1426. )
  1427. }
  1428. # Process all executables and shared libraries.
  1429. function prepare_app_folder_libraries()
  1430. {
  1431. local folder_path
  1432. if [ $# -ge 1 ]
  1433. then
  1434. folder_path="$1"
  1435. else
  1436. folder_path="${APP_PREFIX}"
  1437. fi
  1438. local libexec_folder_path
  1439. if [ $# -ge 2 ]
  1440. then
  1441. libexec_folder_path="$2"
  1442. else
  1443. libexec_folder_path="${APP_PREFIX}/libexec"
  1444. fi
  1445. (
  1446. xbb_activate
  1447. echo
  1448. echo "Preparing ${folder_path} libraries..."
  1449. # Otherwise `find` may fail.
  1450. cd "${WORK_FOLDER_PATH}"
  1451. local binaries
  1452. if [ "${TARGET_PLATFORM}" == "win32" ]
  1453. then
  1454. binaries=$(find "${folder_path}" -name \*.exe)
  1455. for bin in ${binaries}
  1456. do
  1457. echo
  1458. echo "Preparing $(basename "${bin}") ${bin} libraries..."
  1459. # On Windows the DLLs are copied in the same folder.
  1460. copy_dependencies_recursive "${bin}" "$(dirname "${bin}")"
  1461. done
  1462. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1463. then
  1464. binaries=$(find "${folder_path}" -name \* -perm +111 -and ! -type d)
  1465. for bin in ${binaries}
  1466. do
  1467. if is_elf "${bin}"
  1468. then
  1469. echo
  1470. echo "Preparing $(basename "${bin}") ${bin} libraries..."
  1471. if true
  1472. then
  1473. copy_dependencies_recursive "${bin}" \
  1474. "$(dirname "${bin}")"
  1475. else
  1476. # On macOS the dynamic libraries can be copied in the libexec folder.
  1477. copy_dependencies_recursive "${bin}" \
  1478. "$(dirname "${bin}")" "${libexec_folder_path}"
  1479. fi
  1480. fi
  1481. done
  1482. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1483. then
  1484. binaries=$(find "${folder_path}" -name \* -perm /111 -and ! -type d)
  1485. for bin_path in ${binaries}
  1486. do
  1487. if is_elf "${bin_path}"
  1488. then
  1489. echo
  1490. echo "Preparing $(basename "${bin_path}") (${bin_path}) libraries..."
  1491. # On Linux the shared libraries can be copied in the libexec folder,
  1492. # and links be kept in the current folder, but not for 32-bit
  1493. # Intel distros.
  1494. # For consistency reasons, do the same on all platforms.
  1495. if true # [ "${TARGET_ARCH}" == "x32" ]
  1496. then
  1497. copy_dependencies_recursive "${bin_path}" \
  1498. "$(dirname "${bin_path}")"
  1499. else
  1500. copy_dependencies_recursive "${bin_path}" \
  1501. "$(dirname "${bin_path}")" "${libexec_folder_path}"
  1502. fi
  1503. # echo $(basename "${bin_path}") $(readelf -d "${bin_path}" | egrep -i '(RUNPATH|RPATH)')
  1504. fi
  1505. done
  1506. else
  1507. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  1508. exit 1
  1509. fi
  1510. )
  1511. }
  1512. function copy_dependencies_recursive()
  1513. {
  1514. if [ $# -lt 2 ]
  1515. then
  1516. echo "copy_dependencies_recursive requires at least 2 arg."
  1517. exit 1
  1518. fi
  1519. local source_file_path="$1"
  1520. local dest_folder_path="$2"
  1521. local libexec_folder_path
  1522. if [ $# -ge 3 ]
  1523. then
  1524. libexec_folder_path="$3"
  1525. else
  1526. libexec_folder_path="${dest_folder_path}"
  1527. fi
  1528. # The first step is to copy the file to libexec and link it.
  1529. local source_file_name="$(basename "${source_file_path}")"
  1530. local source_folder_path="$(dirname "${source_file_path}")"
  1531. local actual_source_file_path=""
  1532. local copied_file_path="${dest_folder_path}/${source_file_name}"
  1533. # echo "I. Processing ${source_file_path} itself..."
  1534. if [ ! -f "${dest_folder_path}/${source_file_name}" ]
  1535. then
  1536. if [ "${TARGET_PLATFORM}" == "win32" ]
  1537. then
  1538. # On Windows don't bother with sym links, simply copy the file
  1539. # to the destination.
  1540. actual_source_file_path="$(readlink -f "${source_file_path}")"
  1541. copied_file_path="${dest_folder_path}/${source_file_name}"
  1542. else
  1543. # On POSIX copy to libexec and place a symlink at destination.
  1544. if [ -L "${source_file_path}" ]
  1545. then
  1546. #
  1547. # Compute the final absolute path of the link, regardless
  1548. # how many links there are on the way.
  1549. actual_source_file_path="$(readlink -f "${source_file_path}")"
  1550. copied_file_path="${libexec_folder_path}/$(basename "${actual_source_file_path}")"
  1551. elif is_elf "${source_file_path}"
  1552. then
  1553. if [ "${IS_DEVELOP}" == "y" ]
  1554. then
  1555. # The file is definitelly an elf, not a link.
  1556. echo "is_elf ${source_file_name}"
  1557. fi
  1558. actual_source_file_path="${source_file_path}"
  1559. copied_file_path="${libexec_folder_path}/${source_file_name}"
  1560. else
  1561. # Not a symlink and not an elf. Ignore it.
  1562. echo "!!!!!!!!!!!!!!"
  1563. return
  1564. fi
  1565. fi
  1566. else
  1567. : #echo "${dest_folder_path}/${source_file_name} already there"
  1568. fi
  1569. if [ ! -z "${actual_source_file_path}" ]
  1570. then
  1571. if [ ! -f "${copied_file_path}" ]
  1572. then
  1573. install -v -c -m 644 "${actual_source_file_path}" "${copied_file_path}"
  1574. fi
  1575. else
  1576. actual_source_file_path="${source_file_path}"
  1577. fi
  1578. if [ "${WITH_STRIP}" == "y" ]
  1579. then
  1580. strip_binary "${copied_file_path}"
  1581. fi
  1582. if [ "${TARGET_PLATFORM}" == "linux" ]
  1583. then
  1584. patch_linux_elf_origin "${copied_file_path}"
  1585. fi
  1586. # If libexec is the destination, there is no need to link.
  1587. if [ ! -f "${dest_folder_path}/${source_file_name}" ]
  1588. then
  1589. (
  1590. cd "${dest_folder_path}"
  1591. local link_relative_path="$(realpath --relative-to="${dest_folder_path}" "${copied_file_path}")"
  1592. ln -sv "${link_relative_path}" "${source_file_name}"
  1593. )
  1594. fi
  1595. local actual_dest_file_path="$(realpath "${dest_folder_path}/${source_file_name}")"
  1596. local actual_dest_folder_path="$(dirname "${actual_dest_file_path}")"
  1597. # echo "II. Processing ${source_file_path} dependencies..."
  1598. if [ "${TARGET_PLATFORM}" == "linux" ]
  1599. then
  1600. # The file must be an elf. Get its shared libraries.
  1601. local lib_names=$(readelf -d "${dest_folder_path}/${source_file_name}" \
  1602. | grep -i 'Shared library' \
  1603. | sed -e 's/.*Shared library: \[\(.*\)\]/\1/')
  1604. local lib_name
  1605. for lib_name in ${lib_names}
  1606. do
  1607. if is_linux_sys_so "${lib_name}"
  1608. then
  1609. continue # System library, no need to copy it.
  1610. else
  1611. if [ -f "$(dirname "${actual_source_file_path}")/${lib_name}" ]
  1612. then
  1613. copy_dependencies_recursive "$(dirname "${actual_source_file_path}")/${lib_name}" \
  1614. "${actual_dest_folder_path}" "${libexec_folder_path}"
  1615. elif [ -f "${LIBS_INSTALL_FOLDER_PATH}/lib64/${lib_name}" ]
  1616. then
  1617. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/lib64/${lib_name}" \
  1618. "${actual_dest_folder_path}" "${libexec_folder_path}"
  1619. elif [ -f "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib_name}" ]
  1620. then
  1621. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib_name}" \
  1622. "${actual_dest_folder_path}" "${libexec_folder_path}"
  1623. else
  1624. # Not a compiled dependency, perhas a compiler dependency.
  1625. local full_path=$(${CC} -print-file-name=${lib_name})
  1626. # -print-file-name outputs back the requested name if not found.
  1627. if [ "${full_path}" != "${lib_name}" ]
  1628. then
  1629. copy_dependencies_recursive "${full_path}" \
  1630. "${actual_dest_folder_path}" "${libexec_folder_path}"
  1631. else
  1632. # If no toolchain library either, last chance is the XBB libraries.
  1633. if [ -f "${XBB_FOLDER_PATH}/lib64/${lib_name}" ]
  1634. then
  1635. copy_dependencies_recursive "${XBB_FOLDER_PATH}/lib64/${lib_name}" \
  1636. "${actual_dest_folder_path}" "${libexec_folder_path}"
  1637. elif [ -f "${XBB_FOLDER_PATH}/lib/${lib_name}" ]
  1638. then
  1639. copy_dependencies_recursive "${XBB_FOLDER_PATH}/lib/${lib_name}" \
  1640. "${actual_dest_folder_path}" "${libexec_folder_path}"
  1641. else
  1642. echo "${lib_name} not found in the compiled or XBB libraries."
  1643. exit 1
  1644. fi
  1645. fi
  1646. fi
  1647. if [ ! -f "${actual_dest_folder_path}/${lib_name}" ]
  1648. then
  1649. echo "Oops! Dependency ${actual_dest_folder_path}/${lib_name} of ${source_file_name} not found"
  1650. exit 1
  1651. fi
  1652. fi
  1653. done
  1654. # echo "iterate ${dest_folder_path}/${source_file_name} done"
  1655. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1656. then
  1657. echo
  1658. otool -L "${dest_folder_path}/${source_file_name}"
  1659. local lib_names
  1660. if [[ "${source_file_name}" == *\.dylib ]]
  1661. then
  1662. lib_names=$(otool -L "${dest_folder_path}/${source_file_name}" \
  1663. | sed '1d' \
  1664. | sed '1d' \
  1665. | sed -e 's|[[:space:]]*\(.*\) (.*)|\1|' \
  1666. )
  1667. else
  1668. lib_names=$(otool -L "${dest_folder_path}/${source_file_name}" \
  1669. | sed '1d' \
  1670. | sed -e 's|[[:space:]]*\(.*\) (.*)|\1|' \
  1671. )
  1672. fi
  1673. local exec_prefix="@executable_path/"
  1674. local loader_path="@loader_path/"
  1675. local lib_name
  1676. for lib_name in ${lib_names}
  1677. do
  1678. local lib_link_base=""
  1679. if [ "${lib_name:0:1}" != "@" ]
  1680. then
  1681. lib_link_base="$(basename $(readlink -f ${lib_name}))"
  1682. fi
  1683. if [ "${lib_name}" == "${exec_prefix}${source_file_name}" ]
  1684. then
  1685. :
  1686. elif [ "${lib_name}" == "${loader_path}${source_file_name}" ]
  1687. then
  1688. :
  1689. elif [ "${lib_link_base}" == "${source_file_name}" ]
  1690. then
  1691. : # Libraries return a line with their own name.
  1692. else
  1693. if is_darwin_sys_dylib "${lib_name}"
  1694. then
  1695. : # System library, no need to copy it.
  1696. if ! is_darwin_allowed_sys_dylib "${lib_name}"
  1697. then
  1698. echo "Oops! \"${lib_name}\" should not be there!"
  1699. fi
  1700. else
  1701. # The libs can be relative to @executable_path or absolute.
  1702. if [ "${lib_name:0:${#exec_prefix}}" == "${exec_prefix}" ]
  1703. then
  1704. :
  1705. else
  1706. if [ -f "${lib_name}" ]
  1707. then
  1708. copy_dependencies_recursive "${lib_name}" \
  1709. "${dest_folder_path}" "${libexec_folder_path}"
  1710. elif [ -f "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib_name}" ]
  1711. then
  1712. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/lib/${lib_name}" \
  1713. "${dest_folder_path}" "${libexec_folder_path}"
  1714. else
  1715. echo "${lib_name} not found"
  1716. exit 1
  1717. fi
  1718. # Change library path to '@executable_path' inside the lib or app.
  1719. change_dylib "$(basename "${lib_name}")" \
  1720. "${dest_folder_path}/${source_file_name}"
  1721. fi
  1722. fi
  1723. fi
  1724. done
  1725. elif [ "${TARGET_PLATFORM}" == "win32" ]
  1726. then
  1727. local libs=$(${CROSS_COMPILE_PREFIX}-objdump -x "${dest_folder_path}/${source_file_name}" \
  1728. | grep -i 'DLL Name' \
  1729. | sed -e 's/.*DLL Name: \(.*\)/\1/' \
  1730. )
  1731. local lib_name
  1732. for lib_name in ${libs}
  1733. do
  1734. if is_win_sys_dll "${lib_name}"
  1735. then
  1736. : # System DLL, no need to copy it.
  1737. else
  1738. if [ -f "${LIBS_INSTALL_FOLDER_PATH}/bin/${lib_name}" ]
  1739. then
  1740. copy_dependencies_recursive "${LIBS_INSTALL_FOLDER_PATH}/bin/${lib_name}" \
  1741. "${dest_folder_path}"
  1742. elif [ -f "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}/bin/${lib_name}" ]
  1743. then
  1744. copy_dependencies_recursive "${XBB_FOLDER_PATH}/${CROSS_COMPILE_PREFIX}/bin/${lib_name}" \
  1745. "${dest_folder_path}"
  1746. elif [ -f "${XBB_FOLDER_PATH}/mingw/bin/${lib_name}" ]
  1747. then
  1748. # Mainly to get libwinpthread-1.dll.
  1749. copy_dependencies_recursive "${XBB_FOLDER_PATH}/mingw/bin/${lib_name}" \
  1750. "${dest_folder_path}"
  1751. else
  1752. local full_path=$(${CROSS_COMPILE_PREFIX}-gcc -print-file-name=${lib_name})
  1753. # -print-file-name outputs back the requested name if not found.
  1754. if [ "${full_path}" != "${lib_name}" ]
  1755. then
  1756. copy_dependencies_recursive "${full_path}" "${dest_folder_path}"
  1757. else
  1758. echo "${lib_name} required by ${source_file_name}, not found"
  1759. exit 1
  1760. fi
  1761. fi
  1762. fi
  1763. done
  1764. else
  1765. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  1766. exit 1
  1767. fi
  1768. if [ "${IS_DEVELOP}" == "y" ]
  1769. then
  1770. echo "dependency ${source_file_path} done"
  1771. fi
  1772. }
  1773. function check_binaries()
  1774. {
  1775. local folder_path="${APP_PREFIX}"
  1776. if [ $# -ge 1 ]
  1777. then
  1778. folder_path="$1"
  1779. fi
  1780. (
  1781. xbb_activate
  1782. echo
  1783. echo "Checking binaries for unwanted libraries..."
  1784. # Otherwise `find` may fail.
  1785. cd "${WORK_FOLDER_PATH}"
  1786. local binaries
  1787. if [ "${TARGET_PLATFORM}" == "win32" ]
  1788. then
  1789. binaries=$(find "${folder_path}" -name \*.exe)
  1790. for bin in ${binaries}
  1791. do
  1792. check_binary "${bin}"
  1793. done
  1794. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1795. then
  1796. binaries=$(find "${folder_path}" -name \* -perm +111 -and ! -type d)
  1797. for bin in ${binaries}
  1798. do
  1799. if is_elf "${bin}"
  1800. then
  1801. check_binary "${bin}"
  1802. fi
  1803. done
  1804. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1805. then
  1806. binaries=$(find "${folder_path}" -name \* -perm /111 -and ! -type d)
  1807. for bin in ${binaries}
  1808. do
  1809. if is_elf "${bin}"
  1810. then
  1811. check_binary "${bin}"
  1812. fi
  1813. done
  1814. else
  1815. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  1816. exit 1
  1817. fi
  1818. )
  1819. }
  1820. # -----------------------------------------------------------------------------
  1821. # $1 - absolute path to input folder
  1822. # $2 - name of output folder below INSTALL_FOLDER
  1823. function copy_license()
  1824. {
  1825. # Iterate all files in a folder and install some of them in the
  1826. # destination folder
  1827. (
  1828. if [ -z "$2" ]
  1829. then
  1830. return
  1831. fi
  1832. echo
  1833. echo "Copying license files for $2..."
  1834. cd "$1"
  1835. local f
  1836. for f in *
  1837. do
  1838. if [ -f "$f" ]
  1839. then
  1840. if [[ "$f" =~ AUTHORS.*|NEWS.*|COPYING.*|README.*|LICENSE.*|Copyright.*|COPYRIGHT.*|FAQ.*|DEPENDENCIES.*|THANKS.*|CHANGES.* ]]
  1841. then
  1842. install -d -m 0755 \
  1843. "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses/$2"
  1844. install -v -c -m 644 "$f" \
  1845. "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses/$2"
  1846. fi
  1847. elif [ -d "$f" ] && [[ "$f" =~ [Ll][Ii][Cc][Ee][Nn][Ss][Ee]* ]]
  1848. then
  1849. install -d -m 0755 \
  1850. "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses/$2"
  1851. install -v -c -m 644 "$f"/* \
  1852. "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses/$2"
  1853. fi
  1854. done
  1855. )
  1856. (
  1857. xbb_activate
  1858. if [ "${TARGET_PLATFORM}" == "win32" ]
  1859. then
  1860. find "${APP_PREFIX}/${DISTRO_INFO_NAME}/licenses" \
  1861. -type f \
  1862. -exec unix2dos '{}' ';'
  1863. fi
  1864. )
  1865. }
  1866. function copy_build_files()
  1867. {
  1868. echo
  1869. echo "Copying build files..."
  1870. (
  1871. cd "${BUILD_GIT_PATH}"
  1872. mkdir -pv patches
  1873. find scripts patches -type d \
  1874. -exec install -d -m 0755 \
  1875. "${APP_PREFIX}/${DISTRO_INFO_NAME}"/'{}' ';'
  1876. find scripts patches -type f \
  1877. -exec install -v -c -m 644 \
  1878. '{}' "${APP_PREFIX}/${DISTRO_INFO_NAME}"/'{}' ';'
  1879. if [ -f CHANGELOG.txt ]
  1880. then
  1881. install -v -c -m 644 \
  1882. CHANGELOG.txt "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1883. fi
  1884. if [ -f CHANGELOG.md ]
  1885. then
  1886. install -v -c -m 644 \
  1887. CHANGELOG.md "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1888. fi
  1889. )
  1890. }
  1891. # Must be called in the build folder, like
  1892. # cd "${LIBS_BUILD_FOLDER_PATH}"
  1893. # cd "${UILD_FOLDER_PATH}"
  1894. function copy_cmake_logs()
  1895. {
  1896. local folder_name="$1"
  1897. echo
  1898. echo "Preserving CMake log files..."
  1899. rm -rf "${LOGS_FOLDER_PATH}/${folder_name}"
  1900. mkdir -pv "${LOGS_FOLDER_PATH}/${folder_name}/CMakeFiles"
  1901. (
  1902. cd "${folder_name}"
  1903. cp -v "CMakeCache.txt" "${LOGS_FOLDER_PATH}/${folder_name}"
  1904. cp -v "CMakeFiles"/*.log "${LOGS_FOLDER_PATH}/${folder_name}/CMakeFiles"
  1905. )
  1906. }
  1907. # -----------------------------------------------------------------------------
  1908. # Copy one folder to another
  1909. function copy_dir()
  1910. {
  1911. local from_path="$1"
  1912. local to_path="$2"
  1913. set +u
  1914. # rm -rf "${to_path}"
  1915. mkdir -pv "${to_path}"
  1916. (
  1917. cd "${from_path}"
  1918. if [ "${TARGET_PLATFORM}" == "darwin" ]
  1919. then
  1920. find . -xdev -print0 | cpio -oa0 | (cd "${to_path}" && cpio -im)
  1921. else
  1922. find . -xdev -print0 | cpio -oa0V | (cd "${to_path}" && cpio -imuV)
  1923. fi
  1924. )
  1925. set -u
  1926. }
  1927. # -----------------------------------------------------------------------------
  1928. function create_archive()
  1929. {
  1930. (
  1931. xbb_activate
  1932. local distribution_file_version="${RELEASE_VERSION}"
  1933. local target_folder_name=${TARGET_FOLDER_NAME}
  1934. if [ "${HAS_NAME_ARCH}" != "y" ]
  1935. then
  1936. # Pre xPack distributions use the old file name convention.
  1937. distribution_file_version="${RELEASE_VERSION}-${DISTRIBUTION_FILE_DATE}"
  1938. if [ "${TARGET_PLATFORM}" == "win32" ]
  1939. then
  1940. target_folder_name="win${TARGET_BITS}"
  1941. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1942. then
  1943. target_folder_name="macos"
  1944. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1945. then
  1946. target_folder_name="${CONTAINER_DISTRO_LC_NAME}${TARGET_BITS}"
  1947. else
  1948. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  1949. exit 1
  1950. fi
  1951. fi
  1952. local distribution_file="${DEPLOY_FOLDER_PATH}/${DISTRO_LC_NAME}-${APP_LC_NAME}-${distribution_file_version}-${target_folder_name}"
  1953. local archive_version_path
  1954. archive_version_path="${INSTALL_FOLDER_PATH}/archive/${DISTRO_LC_NAME}-${APP_LC_NAME}-${distribution_file_version}"
  1955. cd "${APP_PREFIX}"
  1956. find . -name '.DS_Store' -exec rm '{}' ';'
  1957. echo
  1958. echo "Creating distribution..."
  1959. mkdir -pv "${DEPLOY_FOLDER_PATH}"
  1960. # The folder is temprarily moved into a versioned folder like
  1961. # xpack-<app-name>-<version>, or, in previous versions,
  1962. # in a more elaborate hierarchy like
  1963. # xPacks/<app-name>/<version>.
  1964. # After the archive is created, the folders are moved back.
  1965. # The atempt to transform the tar path fails, since symlinks were
  1966. # also transformed, which is bad.
  1967. if [ "${TARGET_PLATFORM}" == "win32" ]
  1968. then
  1969. local distribution_file="${distribution_file}.zip"
  1970. if [ "${USE_SINGLE_FOLDER_PATH}" != "y" ]
  1971. then
  1972. # DEPRECATED!
  1973. archive_version_path="${INSTALL_FOLDER_PATH}/archive/${DISTRO_UC_NAME}/${APP_UC_NAME}/${distribution_file_version}"
  1974. fi
  1975. echo
  1976. echo "ZIP file: \"${distribution_file}\"."
  1977. rm -rf "${INSTALL_FOLDER_PATH}/archive"
  1978. mkdir -pv "${archive_version_path}"
  1979. mv "${APP_PREFIX}"/* "${archive_version_path}"
  1980. cd "${INSTALL_FOLDER_PATH}/archive"
  1981. zip -r9 -q "${distribution_file}" *
  1982. # Put folders back.
  1983. mv "${archive_version_path}"/* "${APP_PREFIX}"
  1984. else
  1985. # Unfortunately on node.js, xz & bz2 require native modules, which
  1986. # proved unsafe, some xz versions failed to compile on node.js v9.x,
  1987. # so use the good old .tar.gz.
  1988. local distribution_file
  1989. if [ "${USE_TAR_GZ}" == "y" ]
  1990. then
  1991. # Some platforms (like Arduino) accept only this explicit path.
  1992. distribution_file="${distribution_file}.tar.gz"
  1993. else
  1994. distribution_file="${distribution_file}.tgz"
  1995. fi
  1996. local archive_version_path
  1997. if [ "${USE_SINGLE_FOLDER_PATH}" != "y" ]
  1998. then
  1999. # DEPRECATED!
  2000. archive_version_path="${INSTALL_FOLDER_PATH}/archive/${DISTRO_TOP_FOLDER_PATH}/${APP_LC_NAME}/${distribution_file_version}"
  2001. fi
  2002. echo "Compressed tarball: \"${distribution_file}\"."
  2003. rm -rf "${INSTALL_FOLDER_PATH}/archive"
  2004. mkdir -pv "${archive_version_path}"
  2005. mv -v "${APP_PREFIX}"/* "${archive_version_path}"
  2006. # Without --hard-dereference the hard links may be turned into
  2007. # broken soft links on macOS.
  2008. cd "${INSTALL_FOLDER_PATH}"/archive
  2009. # -J uses xz for compression; best compression ratio.
  2010. # -j uses bz2 for compression; good compression ratio.
  2011. # -z uses gzip for compression; fair compression ratio.
  2012. tar -c -z -f "${distribution_file}" \
  2013. --owner=0 \
  2014. --group=0 \
  2015. --format=posix \
  2016. --hard-dereference \
  2017. *
  2018. # Put folders back.
  2019. mv -v "${archive_version_path}"/* "${APP_PREFIX}"
  2020. fi
  2021. cd "${DEPLOY_FOLDER_PATH}"
  2022. compute_sha shasum -a 256 "$(basename ${distribution_file})"
  2023. )
  2024. }
  2025. # -----------------------------------------------------------------------------
  2026. # $1 = application name
  2027. function check_application()
  2028. {
  2029. local app_name=$1
  2030. if [ "${TARGET_PLATFORM}" == "linux" ]
  2031. then
  2032. echo
  2033. echo "Checking binaries for unwanted shared libraries..."
  2034. check_binary "${APP_PREFIX}/bin/${app_name}"
  2035. local libs=$(find "${APP_PREFIX}/bin" -name \*.so.\* -type f)
  2036. local lib
  2037. for lib in ${libs}
  2038. do
  2039. check_binary_for_libraries "${lib}"
  2040. done
  2041. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  2042. then
  2043. echo
  2044. echo "Checking binaries for unwanted dynamic libraries..."
  2045. check_binary "${APP_PREFIX}/bin/${app_name}"
  2046. local libs=$(find "${APP_PREFIX}/bin" -name \*.dylib -type f)
  2047. local lib
  2048. for lib in ${libs}
  2049. do
  2050. check_binary_for_libraries "${lib}"
  2051. done
  2052. elif [ "${TARGET_PLATFORM}" == "win32" ]
  2053. then
  2054. echo
  2055. echo "Checking binaries for unwanted DLLs..."
  2056. check_binary "${APP_PREFIX}/bin/${app_name}.exe"
  2057. local libs=$(find "${APP_PREFIX}/bin" -name \*.dll -type f)
  2058. local lib
  2059. for lib in ${libs}
  2060. do
  2061. check_binary_for_libraries "${lib}"
  2062. done
  2063. else
  2064. echo "Oops! Unsupported ${TARGET_PLATFORM}."
  2065. exit 1
  2066. fi
  2067. echo
  2068. }
  2069. # -----------------------------------------------------------------------------
  2070. function compute_sha()
  2071. {
  2072. # $1 shasum program
  2073. # $2.. options
  2074. # ${!#} file
  2075. file=${!#}
  2076. sha_file="${file}.sha"
  2077. "$@" >"${sha_file}"
  2078. echo "SHA: $(cat ${sha_file})"
  2079. }
  2080. # -----------------------------------------------------------------------------
  2081. function prime_wine()
  2082. {
  2083. if [ "${TARGET_PLATFORM}" == "win32" ]
  2084. then
  2085. (
  2086. xbb_activate
  2087. echo
  2088. winecfg &>/dev/null
  2089. echo "wine primed, testing..."
  2090. )
  2091. fi
  2092. }
  2093. # -----------------------------------------------------------------------------
  2094. function copy_distro_files()
  2095. {
  2096. (
  2097. xbb_activate
  2098. mkdir -pv "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  2099. copy_build_files
  2100. echo
  2101. echo "Copying xPack files..."
  2102. cd "${WORK_FOLDER_PATH}/build.git"
  2103. README_OUT_FILE_NAME="${README_OUT_FILE_NAME:-README-OUT.md}"
  2104. install -v -c -m 644 "scripts/${README_OUT_FILE_NAME}" \
  2105. "${APP_PREFIX}/README.md"
  2106. )
  2107. }
  2108. # -----------------------------------------------------------------------------
  2109. function tests_initialize()
  2110. {
  2111. test_functions=()
  2112. }
  2113. function tests_add()
  2114. {
  2115. test_functions+=("$1")
  2116. }
  2117. function tests_run()
  2118. {
  2119. echo
  2120. echo "Runnng final tests..."
  2121. for test_function in ${test_functions[@]}
  2122. do
  2123. echo
  2124. local func=$(echo ${test_function} | sed -e 's|-|_|g')
  2125. echo "Running ${func}..."
  2126. ${func}
  2127. done
  2128. }
  2129. # -----------------------------------------------------------------------------