container-apps-functions-source.sh 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. # -----------------------------------------------------------------------------
  2. # This file is part of the xPacks distribution.
  3. # (https://xpack.github.io)
  4. # Copyright (c) 2019 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 container build scripts.
  12. # -----------------------------------------------------------------------------
  13. function download_binutils()
  14. {
  15. if [ ! -d "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}" ]
  16. then
  17. (
  18. cd "${SOURCES_FOLDER_PATH}"
  19. if [ -n "${BINUTILS_GIT_URL}" ]
  20. then
  21. git_clone "${BINUTILS_GIT_URL}" "${BINUTILS_GIT_BRANCH}" \
  22. "${BINUTILS_GIT_COMMIT}" "${BINUTILS_SRC_FOLDER_NAME}"
  23. cd "${BINUTILS_SRC_FOLDER_NAME}"
  24. do_patch "${BINUTILS_PATCH}"
  25. elif [ -n "${BINUTILS_ARCHIVE_URL}" ]
  26. then
  27. download_and_extract "${BINUTILS_ARCHIVE_URL}" \
  28. "${BINUTILS_ARCHIVE_NAME}" "${BINUTILS_SRC_FOLDER_NAME}" \
  29. "${BINUTILS_PATCH}"
  30. fi
  31. )
  32. fi
  33. }
  34. function download_gcc()
  35. {
  36. if [ ! -d "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}" ]
  37. then
  38. (
  39. cd "${SOURCES_FOLDER_PATH}"
  40. if [ -n "${GCC_GIT_URL}" ]
  41. then
  42. git_clone "${GCC_GIT_URL}" "${GCC_GIT_BRANCH}" \
  43. "${GCC_GIT_COMMIT}" "${GCC_SRC_FOLDER_NAME}"
  44. elif [ -n "${GCC_ARCHIVE_URL}" ]
  45. then
  46. download_and_extract "${GCC_ARCHIVE_URL}" \
  47. "${GCC_ARCHIVE_NAME}" "${GCC_SRC_FOLDER_NAME}"
  48. fi
  49. )
  50. fi
  51. }
  52. function download_newlib()
  53. {
  54. if [ ! -d "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}" ]
  55. then
  56. (
  57. cd "${SOURCES_FOLDER_PATH}"
  58. if [ -n "${NEWLIB_GIT_URL}" ]
  59. then
  60. git_clone "${NEWLIB_GIT_URL}" "${NEWLIB_GIT_BRANCH}" \
  61. "${NEWLIB_GIT_COMMIT}" "${NEWLIB_SRC_FOLDER_NAME}"
  62. elif [ -n "${NEWLIB_ARCHIVE_URL}" ]
  63. then
  64. download_and_extract "${NEWLIB_ARCHIVE_URL}" \
  65. "${NEWLIB_ARCHIVE_NAME}" "${NEWLIB_SRC_FOLDER_NAME}"
  66. fi
  67. )
  68. fi
  69. }
  70. function download_gdb()
  71. {
  72. # Same package as binutils.
  73. if [ ! -d "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}" ]
  74. then
  75. (
  76. cd "${SOURCES_FOLDER_PATH}"
  77. if [ -n "${GDB_GIT_URL}" ]
  78. then
  79. git_clone "${GDB_GIT_URL}" "${GDB_GIT_BRANCH}" \
  80. "${GDB_GIT_COMMIT}" "${GDB_SRC_FOLDER_NAME}"
  81. cd "${GDB_SRC_FOLDER_NAME}"
  82. do_patch "${GDB_PATCH}"
  83. elif [ -n "${GDB_ARCHIVE_URL}" ]
  84. then
  85. download_and_extract "${GDB_ARCHIVE_URL}" \
  86. "${GDB_ARCHIVE_NAME}" "${GDB_SRC_FOLDER_NAME}" \
  87. "${GDB_PATCH}"
  88. fi
  89. )
  90. fi
  91. }
  92. # -----------------------------------------------------------------------------
  93. function build_binutils()
  94. {
  95. # https://ftp.gnu.org/gnu/binutils/
  96. # https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=binutils-git
  97. # https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=gdb-git
  98. local binutils_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-${BINUTILS_FOLDER_NAME}-installed"
  99. if [ ! -f "${binutils_stamp_file_path}" ]
  100. then
  101. download_binutils
  102. mkdir -pv "${LOGS_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}"
  103. (
  104. mkdir -pv "${BUILD_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}"
  105. cd "${BUILD_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}"
  106. xbb_activate
  107. xbb_activate_installed_dev
  108. CPPFLAGS="${XBB_CPPFLAGS}"
  109. CFLAGS="${XBB_CFLAGS_NO_W}"
  110. CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
  111. LDFLAGS="${XBB_LDFLAGS_APP}"
  112. if [ "${TARGET_PLATFORM}" == "win32" ]
  113. then
  114. LDFLAGS+=" -Wl,${XBB_FOLDER_PATH}/mingw/lib/CRT_glob.o"
  115. fi
  116. if [ "${IS_DEVELOP}" == "y" ]
  117. then
  118. LDFLAGS+=" -v"
  119. fi
  120. export CPPFLAGS
  121. export CFLAGS
  122. export CXXFLAGS
  123. export LDFLAGS
  124. env | sort
  125. if [ ! -f "config.status" ]
  126. then
  127. (
  128. echo
  129. echo "Running binutils configure..."
  130. bash "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}/configure" --help
  131. # ? --without-python --without-curses, --with-expat
  132. # Note that GDB is disabled here, will be build later, possibly from
  133. # different sources.
  134. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}/configure" \
  135. --prefix="${APP_PREFIX}" \
  136. --infodir="${APP_PREFIX_DOC}/info" \
  137. --mandir="${APP_PREFIX_DOC}/man" \
  138. --htmldir="${APP_PREFIX_DOC}/html" \
  139. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  140. \
  141. --build=${BUILD} \
  142. --host=${HOST} \
  143. --target=${GCC_TARGET} \
  144. \
  145. --with-pkgversion="${BRANDING}" \
  146. --with-bugurl="${BUGURL}" \
  147. \
  148. --disable-nls \
  149. --disable-werror \
  150. --disable-sim \
  151. --disable-gdb \
  152. --enable-interwork \
  153. --enable-plugins \
  154. --disable-libdecnumber \
  155. --disable-libreadline \
  156. --with-sysroot="${APP_PREFIX}/${GCC_TARGET}" \
  157. \
  158. --enable-build-warnings=no \
  159. --disable-rpath \
  160. --with-system-zlib \
  161. cp "config.log" "${LOGS_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}/config-log.txt"
  162. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}/configure-output.txt"
  163. fi
  164. (
  165. echo
  166. echo "Running binutils make..."
  167. # Build.
  168. run_verbose make -j ${JOBS}
  169. if false # [ "${WITH_STRIP}" == "y" ]
  170. then
  171. # For -strip, readline needs a patch.
  172. run_verbose make install-strip
  173. else
  174. run_verbose make install
  175. fi
  176. (
  177. xbb_activate_tex
  178. if [ "${WITH_PDF}" == "y" ]
  179. then
  180. run_verbose make pdf
  181. run_verbose make install-pdf
  182. fi
  183. if [ "${WITH_HTML}" == "y" ]
  184. then
  185. run_verbose make html
  186. run_verbose make install-html
  187. fi
  188. )
  189. # Without this copy, the build for the nano version of the GCC second
  190. # step fails with unexpected errors, like "cannot compute suffix of
  191. # object files: cannot compile".
  192. copy_dir "${APP_PREFIX}" "${APP_PREFIX_NANO}"
  193. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-ar"
  194. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-as"
  195. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-ld"
  196. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-nm"
  197. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-objcopy"
  198. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-objdump"
  199. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-ranlib"
  200. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-size"
  201. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-strings"
  202. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-strip"
  203. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}/make-output.txt"
  204. copy_license \
  205. "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}" \
  206. "${BINUTILS_FOLDER_NAME}"
  207. )
  208. touch "${binutils_stamp_file_path}"
  209. else
  210. echo "Component binutils already installed."
  211. fi
  212. tests_add "test_binutils"
  213. }
  214. function test_binutils()
  215. {
  216. (
  217. xbb_activate_installed_bin
  218. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-ar"
  219. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-as"
  220. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-ld"
  221. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-nm"
  222. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-objcopy"
  223. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-objdump"
  224. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-ranlib"
  225. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-size"
  226. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-strings"
  227. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-strip"
  228. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-ar" --version
  229. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-as" --version
  230. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-ld" --version
  231. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-nm" --version
  232. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-objcopy" --version
  233. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-objdump" --version
  234. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-ranlib" --version
  235. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-size" --version
  236. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-strings" --version
  237. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-strip" --version
  238. )
  239. }
  240. function build_gcc_first()
  241. {
  242. local gcc_first_folder_name="${GCC_FOLDER_NAME}-first"
  243. local gcc_first_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-${gcc_first_folder_name}-installed"
  244. if [ ! -f "${gcc_first_stamp_file_path}" ]
  245. then
  246. download_gcc
  247. mkdir -pv "${LOGS_FOLDER_PATH}/${gcc_first_folder_name}"
  248. if [ -n "${GCC_MULTILIB}" ]
  249. then
  250. (
  251. echo
  252. echo "Running the multilib generator..."
  253. cd "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/gcc/config/riscv"
  254. xbb_activate
  255. xbb_activate_installed_dev
  256. # Be sure the ${GCC_MULTILIB} has no quotes, since it defines
  257. # multiple strings.
  258. # Change IFS temporarily so that we can pass a simple string of
  259. # whitespace delimited multilib tokens to multilib-generator
  260. local IFS=$' '
  261. ./multilib-generator ${GCC_MULTILIB} > "${GCC_MULTILIB_FILE}"
  262. cat "${GCC_MULTILIB_FILE}"
  263. )
  264. fi
  265. (
  266. mkdir -pv "${BUILD_FOLDER_PATH}/${gcc_first_folder_name}"
  267. cd "${BUILD_FOLDER_PATH}/${gcc_first_folder_name}"
  268. xbb_activate
  269. xbb_activate_installed_dev
  270. CPPFLAGS="${XBB_CPPFLAGS}"
  271. CFLAGS="${XBB_CFLAGS_NO_W}"
  272. CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
  273. LDFLAGS="${XBB_LDFLAGS_APP}"
  274. if [ "${IS_DEVELOP}" == "y" ]
  275. then
  276. LDFLAGS+=" -v"
  277. fi
  278. CFLAGS_FOR_TARGET="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  279. CXXFLAGS_FOR_TARGET="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  280. export CPPFLAGS
  281. export CFLAGS
  282. export CXXFLAGS
  283. export LDFLAGS
  284. export CFLAGS_FOR_TARGET
  285. export CXXFLAGS_FOR_TARGET
  286. env | sort
  287. if [ ! -f "config.status" ]
  288. then
  289. (
  290. echo
  291. echo "Running gcc first stage configure..."
  292. bash "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" --help
  293. # https://gcc.gnu.org/install/configure.html
  294. # --enable-shared[=package[,…]] build shared versions of libraries
  295. # --enable-tls specify that the target supports TLS (Thread Local Storage).
  296. # --enable-nls enables Native Language Support (NLS)
  297. # --enable-checking=list the compiler is built to perform internal consistency checks of the requested complexity. ‘yes’ (most common checks)
  298. # --with-headers=dir specify that target headers are available when building a cross compiler
  299. # --with-newlib Specifies that ‘newlib’ is being used as the target C library. This causes `__eprintf`` to be omitted from `libgcc.a`` on the assumption that it will be provided by newlib.
  300. # --enable-languages=c newlib does not use C++, so C should be enough
  301. # --enable-checking=no ???
  302. # --with-native-system-header-dir="/include" \
  303. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" \
  304. --prefix="${APP_PREFIX}" \
  305. --infodir="${APP_PREFIX_DOC}/info" \
  306. --mandir="${APP_PREFIX_DOC}/man" \
  307. --htmldir="${APP_PREFIX_DOC}/html" \
  308. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  309. \
  310. --build=${BUILD} \
  311. --host=${HOST} \
  312. --target=${GCC_TARGET} \
  313. \
  314. --with-pkgversion="${BRANDING}" \
  315. --with-bugurl="${BUGURL}" \
  316. \
  317. --enable-languages=c \
  318. --enable-lto \
  319. --disable-decimal-float \
  320. --disable-libffi \
  321. --disable-libgomp \
  322. --disable-libmudflap \
  323. --disable-libquadmath \
  324. --disable-libssp \
  325. --disable-libstdcxx-pch \
  326. --disable-nls \
  327. --disable-threads \
  328. --disable-tls \
  329. --enable-checking=yes \
  330. --with-newlib \
  331. --without-headers \
  332. --with-gnu-as \
  333. --with-gnu-ld \
  334. --with-python-dir=share/gcc-${GCC_TARGET} \
  335. --with-sysroot="${APP_PREFIX}/${GCC_TARGET}" \
  336. \
  337. ${MULTILIB_FLAGS} \
  338. --with-abi="${GCC_ABI}" \
  339. --with-arch="${GCC_ARCH}" \
  340. \
  341. --disable-rpath \
  342. --disable-build-format-warnings \
  343. --with-system-zlib
  344. cp "config.log" "${LOGS_FOLDER_PATH}/${gcc_first_folder_name}/config-log.txt"
  345. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${gcc_first_folder_name}/configure-output.txt"
  346. fi
  347. (
  348. # Partial build, without documentation.
  349. echo
  350. echo "Running gcc first stage make..."
  351. # Build.
  352. # No need to make 'all', 'all-gcc' is enough to compile the libraries.
  353. run_verbose make -j ${JOBS} all-gcc
  354. # No -strip available here.
  355. run_verbose make install-gcc
  356. # Strip?
  357. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${gcc_first_folder_name}/make-output.txt"
  358. )
  359. touch "${gcc_first_stamp_file_path}"
  360. else
  361. echo "Component gcc first stage already installed."
  362. fi
  363. }
  364. # For the nano build, call it with "-nano".
  365. # $1="" or $1="-nano"
  366. function build_newlib()
  367. {
  368. local newlib_folder_name="${NEWLIB_FOLDER_NAME}$1"
  369. local newlib_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-${newlib_folder_name}-installed"
  370. if [ ! -f "${newlib_stamp_file_path}" ]
  371. then
  372. download_newlib
  373. mkdir -pv "${LOGS_FOLDER_PATH}/${newlib_folder_name}"
  374. (
  375. mkdir -pv "${BUILD_FOLDER_PATH}/${newlib_folder_name}"
  376. cd "${BUILD_FOLDER_PATH}/${newlib_folder_name}"
  377. xbb_activate
  378. xbb_activate_installed_dev
  379. # Add the gcc first stage binaries to the path.
  380. PATH="${APP_PREFIX}/bin:${PATH}"
  381. local optimize="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  382. if [ "$1" == "-nano" ]
  383. then
  384. # For newlib-nano optimize for size.
  385. optimize="$(echo ${optimize} | sed -e 's/-O[123]/-Os/')"
  386. fi
  387. CPPFLAGS="${XBB_CPPFLAGS}"
  388. CFLAGS="${XBB_CFLAGS_NO_W}"
  389. CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
  390. # Note the intentional `-g`.
  391. CFLAGS_FOR_TARGET="${optimize} -g"
  392. CXXFLAGS_FOR_TARGET="${optimize} -g"
  393. export CPPFLAGS
  394. export CFLAGS
  395. export CXXFLAGS
  396. export CFLAGS_FOR_TARGET
  397. export CXXFLAGS_FOR_TARGET
  398. env | sort
  399. if [ ! -f "config.status" ]
  400. then
  401. (
  402. # --disable-nls do not use Native Language Support
  403. # --enable-newlib-io-long-double enable long double type support in IO functions printf/scanf
  404. # --enable-newlib-io-long-long enable long long type support in IO functions like printf/scanf
  405. # --enable-newlib-io-c99-formats enable C99 support in IO functions like printf/scanf
  406. # --enable-newlib-register-fini enable finalization function registration using atexit
  407. # --disable-newlib-supplied-syscalls disable newlib from supplying syscalls (__NO_SYSCALLS__)
  408. # --disable-newlib-fvwrite-in-streamio disable iov in streamio
  409. # --disable-newlib-fseek-optimization disable fseek optimization
  410. # --disable-newlib-wide-orient Turn off wide orientation in streamio
  411. # --disable-newlib-unbuf-stream-opt disable unbuffered stream optimization in streamio
  412. # --enable-newlib-nano-malloc use small-footprint nano-malloc implementation
  413. # --enable-lite-exit enable light weight exit
  414. # --enable-newlib-global-atexit enable atexit data structure as global
  415. # --enable-newlib-nano-formatted-io Use nano version formatted IO
  416. # --enable-newlib-reent-small
  417. # --enable-newlib-retargetable-locking ???
  418. echo
  419. echo "Running newlib$1 configure..."
  420. bash "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}/configure" --help
  421. # I still did not figure out how to define a variable with
  422. # the list of options, such that it can be extended, so the
  423. # brute force approach is to duplicate the entire call.
  424. if [ "$1" == "" ]
  425. then
  426. # Extra options to ARM distribution:
  427. # --enable-newlib-io-long-long
  428. # --enable-newlib-io-c99-formats
  429. # --enable-newlib-reent-check-verify
  430. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}/configure" \
  431. --prefix="${APP_PREFIX}" \
  432. --infodir="${APP_PREFIX_DOC}/info" \
  433. --mandir="${APP_PREFIX_DOC}/man" \
  434. --htmldir="${APP_PREFIX_DOC}/html" \
  435. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  436. \
  437. --build=${BUILD} \
  438. --host=${HOST} \
  439. --target="${GCC_TARGET}" \
  440. \
  441. --enable-newlib-io-long-double \
  442. --enable-newlib-register-fini \
  443. --enable-newlib-retargetable-locking \
  444. --disable-newlib-supplied-syscalls \
  445. --disable-nls \
  446. \
  447. --enable-newlib-io-long-long \
  448. --enable-newlib-io-c99-formats
  449. elif [ "$1" == "-nano" ]
  450. then
  451. # --enable-newlib-io-long-long and --enable-newlib-io-c99-formats
  452. # are currently ignored if --enable-newlib-nano-formatted-io.
  453. # --enable-newlib-register-fini is debatable, was removed.
  454. # --enable-newlib-reent-check-verify
  455. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}/configure" \
  456. --prefix="${APP_PREFIX_NANO}" \
  457. \
  458. --build=${BUILD} \
  459. --host=${HOST} \
  460. --target="${GCC_TARGET}" \
  461. \
  462. --disable-newlib-supplied-syscalls \
  463. --enable-newlib-reent-small \
  464. --disable-newlib-fvwrite-in-streamio \
  465. --disable-newlib-fseek-optimization \
  466. --disable-newlib-wide-orient \
  467. --enable-newlib-nano-malloc \
  468. --disable-newlib-unbuf-stream-opt \
  469. --enable-lite-exit \
  470. --enable-newlib-global-atexit \
  471. --enable-newlib-nano-formatted-io \
  472. --disable-nls \
  473. --enable-newlib-register-fini
  474. else
  475. echo "Unsupported build_newlib arg $1"
  476. exit 1
  477. fi
  478. cp "config.log" "${LOGS_FOLDER_PATH}/${newlib_folder_name}/config-log.txt"
  479. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${newlib_folder_name}/configure-output.txt"
  480. fi
  481. (
  482. # Partial build, without documentation.
  483. echo
  484. echo "Running newlib$1 make..."
  485. # Build.
  486. run_verbose make -j ${JOBS}
  487. # make
  488. # Top make fails with install-strip due to libgloss make.
  489. run_verbose make install
  490. if [ "$1" == "" ]
  491. then
  492. if [ "${WITH_PDF}" == "y" ]
  493. then
  494. # Warning, parallel build failed on Debian 32-bit.
  495. (
  496. if [[ "${RELEASE_VERSION}" =~ 5\.4\.1-* ]]
  497. then
  498. hack_pdfetex
  499. fi
  500. xbb_activate_tex
  501. run_verbose make pdf
  502. )
  503. install -v -d "${APP_PREFIX_DOC}/pdf"
  504. install -v -c -m 644 \
  505. "${GCC_TARGET}/libgloss/doc/porting.pdf" "${APP_PREFIX_DOC}/pdf"
  506. install -v -c -m 644 \
  507. "${GCC_TARGET}/newlib/libc/libc.pdf" "${APP_PREFIX_DOC}/pdf"
  508. install -v -c -m 644 \
  509. "${GCC_TARGET}/newlib/libm/libm.pdf" "${APP_PREFIX_DOC}/pdf"
  510. fi
  511. if [ "${WITH_HTML}" == "y" ]
  512. then
  513. run_verbose make html
  514. install -v -d "${APP_PREFIX_DOC}/html"
  515. copy_dir "${GCC_TARGET}/newlib/libc/libc.html" "${APP_PREFIX_DOC}/html/libc"
  516. copy_dir "${GCC_TARGET}/newlib/libm/libm.html" "${APP_PREFIX_DOC}/html/libm"
  517. fi
  518. fi
  519. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${newlib_folder_name}/make-output.txt"
  520. if [ "$1" == "" ]
  521. then
  522. copy_license \
  523. "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}" \
  524. "${NEWLIB_FOLDER_NAME}"
  525. fi
  526. )
  527. touch "${newlib_stamp_file_path}"
  528. else
  529. echo "Component newlib$1 already installed."
  530. fi
  531. }
  532. # -----------------------------------------------------------------------------
  533. function copy_nano_libs()
  534. {
  535. local src_folder="$1"
  536. local dst_folder="$2"
  537. if [ -f "${src_folder}/libstdc++.a" ]
  538. then
  539. cp -v -f "${src_folder}/libstdc++.a" "${dst_folder}/libstdc++_nano.a"
  540. fi
  541. if [ -f "${src_folder}/libsupc++.a" ]
  542. then
  543. cp -v -f "${src_folder}/libsupc++.a" "${dst_folder}/libsupc++_nano.a"
  544. fi
  545. cp -v -f "${src_folder}/libc.a" "${dst_folder}/libc_nano.a"
  546. cp -v -f "${src_folder}/libg.a" "${dst_folder}/libg_nano.a"
  547. if [ -f "${src_folder}/librdimon.a" ]
  548. then
  549. cp -v -f "${src_folder}/librdimon.a" "${dst_folder}/librdimon_nano.a"
  550. fi
  551. cp -v -f "${src_folder}/nano.specs" "${dst_folder}/"
  552. if [ -f "${src_folder}/rdimon.specs" ]
  553. then
  554. cp -v -f "${src_folder}/rdimon.specs" "${dst_folder}/"
  555. fi
  556. cp -v -f "${src_folder}/nosys.specs" "${dst_folder}/"
  557. cp -v -f "${src_folder}"/*crt0.o "${dst_folder}/"
  558. }
  559. # Copy target libraries from each multilib folders.
  560. # $1=source
  561. # $2=destination
  562. # $3=target gcc
  563. function copy_multi_libs()
  564. {
  565. local -a multilibs
  566. local multilib
  567. local multi_folder
  568. local src_folder="$1"
  569. local dst_folder="$2"
  570. local gcc_target="$3"
  571. echo ${gcc_target}
  572. multilibs=( $("${gcc_target}" -print-multi-lib 2>/dev/null) )
  573. if [ ${#multilibs[@]} -gt 0 ]
  574. then
  575. for multilib in "${multilibs[@]}"
  576. do
  577. multi_folder="${multilib%%;*}"
  578. copy_nano_libs "${src_folder}/${multi_folder}" \
  579. "${dst_folder}/${multi_folder}"
  580. done
  581. else
  582. copy_nano_libs "${src_folder}" "${dst_folder}"
  583. fi
  584. }
  585. # -----------------------------------------------------------------------------
  586. function copy_linux_libs()
  587. {
  588. local copy_linux_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-copy-linux-completed"
  589. if [ ! -f "${copy_linux_stamp_file_path}" ]
  590. then
  591. local linux_path="${LINUX_INSTALL_PATH}"
  592. (
  593. cd "${WORK_FOLDER_PATH}"
  594. copy_dir "${linux_path}/${GCC_TARGET}/lib" "${APP_PREFIX}/${GCC_TARGET}/lib"
  595. copy_dir "${linux_path}/${GCC_TARGET}/include" "${APP_PREFIX}/${GCC_TARGET}/include"
  596. copy_dir "${linux_path}/include" "${APP_PREFIX}/include"
  597. copy_dir "${linux_path}/lib" "${APP_PREFIX}/lib"
  598. copy_dir "${linux_path}/share" "${APP_PREFIX}/share"
  599. )
  600. (
  601. cd "${APP_PREFIX}"
  602. find "${GCC_TARGET}/lib" "${GCC_TARGET}/include" "include" "lib" "share" \
  603. -perm /111 -and ! -type d \
  604. -exec rm '{}' ';'
  605. )
  606. touch "${copy_linux_stamp_file_path}"
  607. else
  608. echo "Component copy-linux-libs already processed."
  609. fi
  610. }
  611. # -----------------------------------------------------------------------------
  612. # For the nano build, call it with "-nano".
  613. # $1="" or $1="-nano"
  614. function build_gcc_final()
  615. {
  616. local gcc_final_folder_name="${GCC_FOLDER_NAME}-final$1"
  617. local gcc_final_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-${gcc_final_folder_name}-installed"
  618. if [ ! -f "${gcc_final_stamp_file_path}" ]
  619. then
  620. download_gcc
  621. mkdir -pv "${LOGS_FOLDER_PATH}/${gcc_final_folder_name}"
  622. (
  623. mkdir -pv "${BUILD_FOLDER_PATH}/${gcc_final_folder_name}"
  624. cd "${BUILD_FOLDER_PATH}/${gcc_final_folder_name}"
  625. xbb_activate
  626. xbb_activate_installed_dev
  627. CPPFLAGS="${XBB_CPPFLAGS}"
  628. CFLAGS="${XBB_CFLAGS_NO_W}"
  629. CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
  630. LDFLAGS="${XBB_LDFLAGS_APP}"
  631. # Do not add CRT_glob.o here, it will fail with already defined,
  632. # since it is already handled by --enable-mingw-wildcard.
  633. if [ "${IS_DEVELOP}" == "y" ]
  634. then
  635. LDFLAGS+=" -v"
  636. fi
  637. local optimize="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  638. if [ "$1" == "-nano" ]
  639. then
  640. # For newlib-nano optimize for size.
  641. optimize="$(echo ${optimize} | sed -e 's/-O[123]/-Os/')"
  642. fi
  643. # Note the intentional `-g`.
  644. CFLAGS_FOR_TARGET="${optimize} -g"
  645. CXXFLAGS_FOR_TARGET="${optimize} -fno-exceptions -g"
  646. export CPPFLAGS
  647. export CFLAGS
  648. export CXXFLAGS
  649. export LDFLAGS
  650. export CFLAGS_FOR_TARGET
  651. export CXXFLAGS_FOR_TARGET
  652. local mingw_wildcard="--disable-mingw-wildcard"
  653. if [ "${TARGET_PLATFORM}" == "win32" ]
  654. then
  655. add_linux_install_path
  656. mingw_wildcard="--enable-mingw-wildcard"
  657. export AR_FOR_TARGET="${GCC_TARGET}-ar"
  658. export NM_FOR_TARGET="${GCC_TARGET}-nm"
  659. export OBJDUMP_FOR_TARET="${GCC_TARGET}-objdump"
  660. export STRIP_FOR_TARGET="${GCC_TARGET}-strip"
  661. export CC_FOR_TARGET="${GCC_TARGET}-gcc"
  662. export GCC_FOR_TARGET="${GCC_TARGET}-gcc"
  663. export CXX_FOR_TARGET="${GCC_TARGET}-g++"
  664. fi
  665. env | sort
  666. if [ ! -f "config.status" ]
  667. then
  668. (
  669. echo
  670. echo "Running gcc$1 final stage configure..."
  671. bash "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" --help
  672. # https://gcc.gnu.org/install/configure.html
  673. # --enable-shared[=package[,…]] build shared versions of libraries
  674. # --enable-tls specify that the target supports TLS (Thread Local Storage).
  675. # --enable-nls enables Native Language Support (NLS)
  676. # --enable-checking=list the compiler is built to perform internal consistency checks of the requested complexity. ‘yes’ (most common checks)
  677. # --with-headers=dir specify that target headers are available when building a cross compiler
  678. # --with-newlib Specifies that ‘newlib’ is being used as the target C library. This causes `__eprintf`` to be omitted from `libgcc.a`` on the assumption that it will be provided by newlib.
  679. # --enable-languages=c,c++ Support only C/C++, ignore all other.
  680. if [ "$1" == "" ]
  681. then
  682. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" \
  683. --prefix="${APP_PREFIX}" \
  684. --infodir="${APP_PREFIX_DOC}/info" \
  685. --mandir="${APP_PREFIX_DOC}/man" \
  686. --htmldir="${APP_PREFIX_DOC}/html" \
  687. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  688. \
  689. --build=${BUILD} \
  690. --host=${HOST} \
  691. --target=${GCC_TARGET} \
  692. \
  693. --with-pkgversion="${BRANDING}" \
  694. --with-bugurl="${BUGURL}" \
  695. \
  696. --enable-languages=c,c++ \
  697. ${mingw_wildcard} \
  698. --enable-plugins \
  699. --enable-lto \
  700. --disable-decimal-float \
  701. --disable-libffi \
  702. --disable-libgomp \
  703. --disable-libmudflap \
  704. --disable-libquadmath \
  705. --disable-libssp \
  706. --disable-libstdcxx-pch \
  707. --disable-nls \
  708. --disable-threads \
  709. --disable-tls \
  710. --enable-checking=yes \
  711. --with-gnu-as \
  712. --with-gnu-ld \
  713. --with-newlib \
  714. --with-headers=yes \
  715. --with-python-dir="share/gcc-${GCC_TARGET}" \
  716. --with-sysroot="${APP_PREFIX}/${GCC_TARGET}" \
  717. --with-native-system-header-dir="/include" \
  718. \
  719. ${MULTILIB_FLAGS} \
  720. --with-abi="${GCC_ABI}" \
  721. --with-arch="${GCC_ARCH}" \
  722. \
  723. --disable-rpath \
  724. --disable-build-format-warnings \
  725. --with-system-zlib
  726. elif [ "$1" == "-nano" ]
  727. then
  728. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" \
  729. --prefix="${APP_PREFIX_NANO}" \
  730. \
  731. --build=${BUILD} \
  732. --host=${HOST} \
  733. --target=${GCC_TARGET} \
  734. \
  735. --with-pkgversion="${BRANDING}" \
  736. --with-bugurl="${BUGURL}" \
  737. \
  738. --enable-languages=c,c++ \
  739. --disable-decimal-float \
  740. --disable-libffi \
  741. --disable-libgomp \
  742. --disable-libmudflap \
  743. --disable-libquadmath \
  744. --disable-libssp \
  745. --disable-libstdcxx-pch \
  746. --disable-libstdcxx-verbose \
  747. --disable-nls \
  748. --disable-threads \
  749. --disable-tls \
  750. --with-gnu-as \
  751. --with-gnu-ld \
  752. --with-newlib \
  753. --with-headers=yes \
  754. --with-python-dir="share/gcc-${GCC_TARGET}" \
  755. --with-sysroot="${APP_PREFIX_NANO}/${GCC_TARGET}" \
  756. --with-native-system-header-dir="/include" \
  757. ${MULTILIB_FLAGS} \
  758. \
  759. --disable-rpath \
  760. --disable-build-format-warnings \
  761. --with-system-zlib
  762. fi
  763. cp "config.log" "${LOGS_FOLDER_PATH}/${gcc_final_folder_name}/config-log.txt"
  764. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${gcc_final_folder_name}/configure-output.txt"
  765. fi
  766. (
  767. # Partial build, without documentation.
  768. echo
  769. echo "Running gcc$1 final stage make..."
  770. if [ "${TARGET_PLATFORM}" != "win32" ]
  771. then
  772. # Passing USE_TM_CLONE_REGISTRY=0 via INHIBIT_LIBC_CFLAGS to disable
  773. # transactional memory related code in crtbegin.o.
  774. # This is a workaround. Better approach is have a t-* to set this flag via
  775. # CRTSTUFF_T_CFLAGS
  776. # Parallel builds may fail.
  777. run_verbose make -j ${JOBS} INHIBIT_LIBC_CFLAGS="-DUSE_TM_CLONE_REGISTRY=0"
  778. # make INHIBIT_LIBC_CFLAGS="-DUSE_TM_CLONE_REGISTRY=0"
  779. if [ "${WITH_STRIP}" == "y" ]
  780. then
  781. run_verbose make install-strip
  782. else
  783. run_verbose make install
  784. fi
  785. if [ "$1" == "-nano" ]
  786. then
  787. local target_gcc=""
  788. if [ "${TARGET_PLATFORM}" == "win32" ]
  789. then
  790. target_gcc="${GCC_TARGET}-gcc"
  791. else
  792. target_gcc="${APP_PREFIX_NANO}/bin/${GCC_TARGET}-gcc"
  793. fi
  794. # Copy the libraries after appending the `_nano` suffix.
  795. # Iterate through all multilib names.
  796. copy_multi_libs \
  797. "${APP_PREFIX_NANO}/${GCC_TARGET}/lib" \
  798. "${APP_PREFIX}/${GCC_TARGET}/lib" \
  799. "${target_gcc}"
  800. # Copy the nano configured newlib.h file into the location that nano.specs
  801. # expects it to be.
  802. mkdir -pv "${APP_PREFIX}/${GCC_TARGET}/include/newlib-nano"
  803. cp -v -f "${APP_PREFIX_NANO}/${GCC_TARGET}/include/newlib.h" \
  804. "${APP_PREFIX}/${GCC_TARGET}/include/newlib-nano/newlib.h"
  805. fi
  806. else
  807. # Build.
  808. # For Windows build only the GCC binaries, the libraries were copied
  809. # from the Linux build.
  810. run_verbose make -j ${JOBS} all-gcc
  811. # make all-gcc
  812. # No -strip here.
  813. run_verbose make install-gcc
  814. # Strip?
  815. fi
  816. if [ "$1" == "" ]
  817. then
  818. (
  819. xbb_activate_tex
  820. # Full build, with documentation.
  821. if [ "${WITH_PDF}" == "y" ]
  822. then
  823. run_verbose make pdf
  824. run_verbose make install-pdf
  825. fi
  826. if [ "${WITH_HTML}" == "y" ]
  827. then
  828. run_verbose make html
  829. run_verbose make install-html
  830. fi
  831. )
  832. fi
  833. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${gcc_final_folder_name}/make-output.txt"
  834. if [ "$1" == "" ]
  835. then
  836. copy_license \
  837. "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}" \
  838. "${GCC_FOLDER_NAME}"
  839. fi
  840. )
  841. touch "${gcc_final_stamp_file_path}"
  842. else
  843. echo "Component gcc$1 final stage already installed."
  844. fi
  845. if [ "$1" == "" ]
  846. then
  847. tests_add "test_gcc"
  848. fi
  849. }
  850. function test_gcc()
  851. {
  852. (
  853. xbb_activate_installed_bin
  854. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-gcc"
  855. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-g++"
  856. show_libs "${APP_PREFIX}/libexec/gcc/${GCC_TARGET}/${GCC_VERSION}/cc1"
  857. show_libs "${APP_PREFIX}/libexec/gcc/${GCC_TARGET}/${GCC_VERSION}/cc1plus"
  858. show_libs "${APP_PREFIX}/libexec/gcc/${GCC_TARGET}/${GCC_VERSION}/collect2"
  859. show_libs "${APP_PREFIX}/libexec/gcc/${GCC_TARGET}/${GCC_VERSION}/lto-wrapper"
  860. show_libs "${APP_PREFIX}/libexec/gcc/${GCC_TARGET}/${GCC_VERSION}/lto1"
  861. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" --help
  862. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -dumpversion
  863. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -dumpmachine
  864. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -print-multi-lib
  865. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -dumpspecs | wc -l
  866. local tmp=$(mktemp /tmp/gcc-test.XXXXX)
  867. rm -rf "${tmp}"
  868. mkdir -pv "${tmp}"
  869. cd "${tmp}"
  870. # Note: __EOF__ is quoted to prevent substitutions here.
  871. cat <<'__EOF__' > hello.c
  872. #include <stdio.h>
  873. int
  874. main(int argc, char* argv[])
  875. {
  876. printf("Hello World\n");
  877. }
  878. __EOF__
  879. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -o hello-c.elf -specs=nosys.specs hello.c
  880. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -o hello.c.o -c -flto hello.c
  881. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -o hello-c-lto.elf -specs=nosys.specs -flto -v hello.c.o
  882. # Note: __EOF__ is quoted to prevent substitutions here.
  883. cat <<'__EOF__' > hello.cpp
  884. #include <iostream>
  885. int
  886. main(int argc, char* argv[])
  887. {
  888. std::cout << "Hello World" << std::endl;
  889. }
  890. extern "C" void __sync_synchronize();
  891. void
  892. __sync_synchronize()
  893. {
  894. }
  895. __EOF__
  896. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-g++" -o hello-cpp.elf -specs=nosys.specs hello.cpp
  897. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-g++" -o hello.cpp.o -c -flto hello.cpp
  898. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-g++" -o hello-cpp-lto.elf -specs=nosys.specs -flto -v hello.cpp.o
  899. cd ..
  900. rm -rf "${tmp}"
  901. )
  902. }
  903. # Called multile times, with and without python support.
  904. # $1="" or $1="-py" or $1="-py3"
  905. function build_gdb()
  906. {
  907. local gdb_folder_name="${GDB_FOLDER_NAME}$1"
  908. local gdb_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-${gdb_folder_name}-installed"
  909. if [ ! -f "${gdb_stamp_file_path}" ]
  910. then
  911. download_gdb
  912. mkdir -pv "${LOGS_FOLDER_PATH}/${gdb_folder_name}"
  913. (
  914. mkdir -pv "${BUILD_FOLDER_PATH}/${gdb_folder_name}"
  915. cd "${BUILD_FOLDER_PATH}/${gdb_folder_name}"
  916. local platform_python2
  917. if [ -x "/Library/Frameworks/Python.framework/Versions/2.7/bin/python" ]
  918. then
  919. platform_python2="/Library/Frameworks/Python.framework/Versions/2.7/bin/python2"
  920. elif [ -x "/usr/bin/python2.7" ]
  921. then
  922. platform_python2="/usr/bin/python2.7"
  923. elif [ -x "/usr/bin/python2.6" ]
  924. then
  925. platform_python2="/usr/bin/python2.6"
  926. else
  927. set +e
  928. platform_python2="$(which python)"
  929. set -e
  930. fi
  931. local platform_python3
  932. if [ -x "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3" ]
  933. then
  934. platform_python3="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
  935. elif [ -x "/usr/bin/python3.7" ]
  936. then
  937. platform_python3="/usr/bin/python3.7"
  938. elif [ -x "/usr/bin/python3.6" ]
  939. then
  940. platform_python3="/usr/bin/python3.6"
  941. else
  942. set +e
  943. platform_python3="$(which python3)"
  944. set -e
  945. fi
  946. xbb_activate
  947. xbb_activate_installed_dev
  948. if false # [ "${TARGET_PLATFORM}" == "darwin" ]
  949. then
  950. # When compiled with GCC-7 it fails to run, due to
  951. # some problems with exceptions unwind.
  952. export CC=clang
  953. export CXX=clang++
  954. unset AR
  955. unset LD
  956. unset NM
  957. unset RANLIB
  958. fi
  959. CPPFLAGS="${XBB_CPPFLAGS}"
  960. CFLAGS="${XBB_CFLAGS_NO_W}"
  961. CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
  962. # libiconv is used by Python3.
  963. # export LIBS="-liconv"
  964. if [ "${TARGET_PLATFORM}" == "win32" ]
  965. then
  966. # https://stackoverflow.com/questions/44150871/embeded-python3-6-with-mingw-in-c-fail-on-linking
  967. # ???
  968. CPPFLAGS+=" -DPy_BUILD_CORE_BUILTIN=1"
  969. if [ "$1" == "-py" ]
  970. then
  971. # Definition required by python-config.sh.
  972. export GNURM_PYTHON_WIN_DIR="${SOURCES_FOLDER_PATH}/${PYTHON2_SRC_FOLDER_NAME}"
  973. fi
  974. # From Arm script.
  975. LDFLAGS="${XBB_LDFLAGS_APP} -Wl,${XBB_FOLDER_PATH}/mingw/lib/CRT_glob.o"
  976. # Workaround for undefined reference to `__strcpy_chk' in GCC 9.
  977. # https://sourceforge.net/p/mingw-w64/bugs/818/
  978. LIBS="-lssp -liconv"
  979. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  980. then
  981. # This makes gdb-py fail!
  982. # Pick some system libraries from XBB, to avoid rebuilding them here.
  983. # CPPFLAGS+=" -I${XBB_FOLDER_PATH}/include"
  984. # LDFLAGS+=" -L${XBB_FOLDER_PATH}/lib"
  985. LDFLAGS="${XBB_LDFLAGS_APP}"
  986. LIBS="-liconv -lncurses"
  987. elif [ "${TARGET_PLATFORM}" == "linux" ]
  988. then
  989. LDFLAGS="${XBB_LDFLAGS_APP}"
  990. LIBS=""
  991. fi
  992. if [ "${IS_DEVELOP}" == "y" ]
  993. then
  994. LDFLAGS+=" -v"
  995. fi
  996. if [ "${TARGET_PLATFORM}" == "darwin" ]
  997. then
  998. # Pick some system libraries from XBB, to avoid rebuilding them here.
  999. # Otherwise configure will not identify that Python is present.
  1000. CPPFLAGS+=" -I${XBB_FOLDER_PATH}/include"
  1001. LDFLAGS+=" -L${XBB_FOLDER_PATH}/lib"
  1002. fi
  1003. # Not yet used, requires patching the python-config.py.
  1004. # See the arm-none-eabi script.
  1005. CONFIG_PYTHON_PREFIX=""
  1006. local extra_python_opts="--with-python=no"
  1007. if [ "$1" == "-py" ]
  1008. then
  1009. if [ "${TARGET_PLATFORM}" == "win32" ]
  1010. then
  1011. extra_python_opts="--with-python=${SOURCES_FOLDER_PATH}/${GCC_COMBO_FOLDER_NAME}/python-config.sh"
  1012. else
  1013. if [ "${USE_PLATFORM_PYTHON2}" == "y" ]
  1014. then
  1015. extra_python_opts="--with-python=${platform_python2}"
  1016. else
  1017. extra_python_opts="--with-python=$(which python2)"
  1018. fi
  1019. if [ "${TARGET_PLATFORM}" == "darwin" ]
  1020. then
  1021. # Use the custom path, 2.7 will be removed from future macOS.
  1022. CONFIG_PYTHON_PREFIX="/Library/Frameworks/Python.framework/Versions/2.7"
  1023. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1024. then
  1025. CONFIG_PYTHON_PREFIX="/usr/local"
  1026. fi
  1027. fi
  1028. elif [ "$1" == "-py3" ]
  1029. then
  1030. if [ "${TARGET_PLATFORM}" == "win32" ]
  1031. then
  1032. extra_python_opts="--with-python=${BUILD_GIT_PATH}/patches/python3-config.sh"
  1033. else
  1034. if [ "${USE_PLATFORM_PYTHON3}" == "y" ]
  1035. then
  1036. extra_python_opts="--with-python=${platform_python3}"
  1037. else
  1038. extra_python_opts="--with-python=$(which python3)"
  1039. fi
  1040. if [ "${TARGET_PLATFORM}" == "darwin" ]
  1041. then
  1042. CONFIG_PYTHON_PREFIX="/Library/Frameworks/Python.framework/Versions/3.7"
  1043. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1044. then
  1045. CONFIG_PYTHON_PREFIX="/usr/local"
  1046. fi
  1047. fi
  1048. fi
  1049. local tui_option
  1050. if [ "${TARGET_PLATFORM}" == "win32" ]
  1051. then
  1052. tui_option="--disable-tui"
  1053. else
  1054. tui_option="--enable-tui"
  1055. fi
  1056. export CPPFLAGS
  1057. export CFLAGS
  1058. export CXXFLAGS
  1059. export LDFLAGS
  1060. export LIBS
  1061. export CONFIG_PYTHON_PREFIX
  1062. env | sort
  1063. if [ ! -f "config.status" ]
  1064. then
  1065. (
  1066. echo
  1067. echo "Running gdb$1 configure..."
  1068. bash "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}/configure" --help
  1069. # Note that all components are disabled, except GDB.
  1070. run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}/configure" \
  1071. --prefix="${APP_PREFIX}" \
  1072. --infodir="${APP_PREFIX_DOC}/info" \
  1073. --mandir="${APP_PREFIX_DOC}/man" \
  1074. --htmldir="${APP_PREFIX_DOC}/html" \
  1075. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  1076. \
  1077. --build=${BUILD} \
  1078. --host=${HOST} \
  1079. --target=${GCC_TARGET} \
  1080. \
  1081. --with-pkgversion="${BRANDING}" \
  1082. --with-bugurl="${BUGURL}" \
  1083. \
  1084. --enable-gdb \
  1085. --disable-nls \
  1086. --disable-sim \
  1087. --disable-gas \
  1088. --disable-binutils \
  1089. --disable-ld \
  1090. --disable-gold \
  1091. --disable-gprof \
  1092. --with-expat \
  1093. --with-lzma=yes \
  1094. --with-system-gdbinit="${APP_PREFIX}/${GCC_TARGET}/lib/gdbinit" \
  1095. --with-gdb-datadir="${APP_PREFIX}/${GCC_TARGET}/share/gdb" \
  1096. \
  1097. ${extra_python_opts} \
  1098. --program-prefix="${GCC_TARGET}-" \
  1099. --program-suffix="$1" \
  1100. \
  1101. --disable-werror \
  1102. --enable-build-warnings=no \
  1103. --disable-rpath \
  1104. --with-system-zlib \
  1105. --without-guile \
  1106. --without-babeltrace \
  1107. --without-libunwind-ia64 \
  1108. ${tui_option} \
  1109. cp "config.log" "${LOGS_FOLDER_PATH}/${gdb_folder_name}/config-log.txt"
  1110. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${gdb_folder_name}/configure-output.txt"
  1111. fi
  1112. (
  1113. echo
  1114. echo "Running gdb$1 make..."
  1115. # Build.
  1116. run_verbose make -j ${JOBS}
  1117. # make
  1118. # install-strip fails, not only because of readline has no install-strip
  1119. # but even after patching it tries to strip a non elf file
  1120. # strip:.../install/riscv-none-gcc/bin/_inst.672_: file format not recognized
  1121. run_verbose make install
  1122. if [ "$1" == "" ]
  1123. then
  1124. (
  1125. xbb_activate_tex
  1126. if [ "${WITH_PDF}" == "y" ]
  1127. then
  1128. run_verbose make pdf
  1129. run_verbose make install-pdf
  1130. fi
  1131. if [ "${WITH_HTML}" == "y" ]
  1132. then
  1133. run_verbose make html
  1134. run_verbose make install-html
  1135. fi
  1136. )
  1137. fi
  1138. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/${gdb_folder_name}/make-output.txt"
  1139. if [ "$1" == "" ]
  1140. then
  1141. copy_license \
  1142. "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}/gdb" \
  1143. "${GDB_FOLDER_NAME}"
  1144. fi
  1145. )
  1146. touch "${gdb_stamp_file_path}"
  1147. else
  1148. echo "Component gdb$1 already installed."
  1149. fi
  1150. tests_add "test_gdb$1"
  1151. }
  1152. function test_gdb_py()
  1153. {
  1154. test_gdb "-py"
  1155. }
  1156. function test_gdb_py3()
  1157. {
  1158. test_gdb "-py3"
  1159. }
  1160. function test_gdb()
  1161. {
  1162. local suffix=""
  1163. if [ $# -ge 1 ]
  1164. then
  1165. suffix="$1"
  1166. fi
  1167. if [ "${suffix}" != "" -a "${TARGET_PLATFORM}" == "win32" ]
  1168. then
  1169. (
  1170. xbb_activate
  1171. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}"
  1172. # Fails on Wine
  1173. # ImportError: No module named site
  1174. # 007b:fixme:msvcrt:__clean_type_info_names_internal (0x1e31e2e8) stub
  1175. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" --version || true
  1176. )
  1177. return 0
  1178. fi
  1179. # error while loading shared libraries: /Host/home/ilg/Work/arm-none-eabi-gcc-8.2.1-1.5/linux-x32/install/arm-none-eabi-gcc/bin/libpython3.7m.so.1.0: unsupported version 0 of Verneed record
  1180. if [ "${suffix}" == "-py3" -a "${TARGET_PLATFORM}" == "linux" -a "${TARGET_ARCH}" == "x32" ]
  1181. then
  1182. return 0
  1183. fi
  1184. (
  1185. # Required by gdb-py to access the python shared library.
  1186. xbb_activate_installed_bin
  1187. show_libs "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}"
  1188. # The original Python in Ubunutu XBB is too old and the test fails.
  1189. # Use the XBB modern Python.
  1190. if [ "${suffix}" == "-py" ]
  1191. then
  1192. echo
  1193. python2 --version
  1194. if [ "${TARGET_PLATFORM}" == "linux" ]
  1195. then
  1196. export PYTHONHOME="${XBB_FOLDER_PATH}"
  1197. elif [ "${TARGET_PLATFORM}" == "win32" ]
  1198. then
  1199. # export PYTHONHOME="${XBB_FOLDER_PATH}"
  1200. export PYTHONPATH="${XBB_FOLDER_PATH}/lib/python2.7"
  1201. fi
  1202. elif [ "${suffix}" == "-py3" ]
  1203. then
  1204. echo
  1205. python3 --version
  1206. if [ "${TARGET_PLATFORM}" == "linux" ]
  1207. then
  1208. export PYTHONHOME="${XBB_FOLDER_PATH}"
  1209. fi
  1210. fi
  1211. set +u
  1212. echo "PYTHONHOME=${PYTHONHOME}"
  1213. echo "PYTHONPATH=${PYTHONPATH}"
  1214. set -u
  1215. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" --version
  1216. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" --config
  1217. # This command is known to fail with 'Abort trap: 6' (SIGABRT)
  1218. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" \
  1219. --nh \
  1220. --nx \
  1221. -ex='show language' \
  1222. -ex='set language auto' \
  1223. -ex='quit'
  1224. )
  1225. }
  1226. # -----------------------------------------------------------------------------
  1227. function tidy_up()
  1228. {
  1229. (
  1230. xbb_activate
  1231. echo
  1232. echo "Tidying up..."
  1233. cd "${WORK_FOLDER_PATH}"
  1234. find "${APP_PREFIX}" -name "libiberty.a" -exec rm -v '{}' ';'
  1235. find "${APP_PREFIX}" -name '*.la' -exec rm -v '{}' ';'
  1236. if [ "${TARGET_PLATFORM}" == "win32" ]
  1237. then
  1238. find "${APP_PREFIX}" -name "liblto_plugin.a" -exec rm -v '{}' ';'
  1239. find "${APP_PREFIX}" -name "liblto_plugin.dll.a" -exec rm -v '{}' ';'
  1240. fi
  1241. )
  1242. }
  1243. function strip_binaries()
  1244. {
  1245. local folder_path="${APP_PREFIX}"
  1246. if [ $# -ge 1 ]
  1247. then
  1248. folder_path="$1"
  1249. fi
  1250. if [ "${WITH_STRIP}" == "y" ]
  1251. then
  1252. (
  1253. xbb_activate
  1254. echo
  1255. echo "Stripping binaries..."
  1256. # Otherwise `find` may fail.
  1257. cd "${WORK_FOLDER_PATH}"
  1258. local binaries
  1259. if [ "${TARGET_PLATFORM}" == "win32" ]
  1260. then
  1261. which "${CROSS_COMPILE_PREFIX}-strip"
  1262. binaries=$(find "${folder_path}" -name \*.exe)
  1263. for bin in ${binaries}
  1264. do
  1265. strip_binary2 "${CROSS_COMPILE_PREFIX}-strip" "${bin}"
  1266. done
  1267. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1268. then
  1269. which strip
  1270. binaries=$(find "${folder_path}" -name \* -perm +111 -and ! -type d)
  1271. for bin in ${binaries}
  1272. do
  1273. if is_elf "${bin}"
  1274. then
  1275. strip_binary2 strip "${bin}"
  1276. fi
  1277. done
  1278. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1279. then
  1280. which strip
  1281. binaries=$(find "${folder_path}" -name \* -perm /111 -and ! -type d)
  1282. for bin in ${binaries}
  1283. do
  1284. if is_elf "${bin}"
  1285. then
  1286. strip_binary2 strip "${bin}"
  1287. fi
  1288. done
  1289. fi
  1290. )
  1291. fi
  1292. }
  1293. function strip_libs()
  1294. {
  1295. if [ "${WITH_STRIP}" == "y" ]
  1296. then
  1297. (
  1298. xbb_activate
  1299. PATH="${APP_PREFIX}/bin:${PATH}"
  1300. echo
  1301. echo "Stripping libraries..."
  1302. cd "${WORK_FOLDER_PATH}"
  1303. # which "${GCC_TARGET}-objcopy"
  1304. local libs=$(find "${APP_PREFIX}" -name '*.[ao]')
  1305. for lib in ${libs}
  1306. do
  1307. echo "${GCC_TARGET}-objcopy -R ... ${lib}"
  1308. "${APP_PREFIX}/bin/${GCC_TARGET}-objcopy" -R .comment -R .note -R .debug_info -R .debug_aranges -R .debug_pubnames -R .debug_pubtypes -R .debug_abbrev -R .debug_line -R .debug_str -R .debug_ranges -R .debug_loc "${lib}" || true
  1309. done
  1310. )
  1311. fi
  1312. }
  1313. function copy_distro_files()
  1314. {
  1315. (
  1316. xbb_activate
  1317. rm -rf "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1318. mkdir -pv "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1319. copy_build_files
  1320. echo
  1321. echo "Copying distro files..."
  1322. cd "${BUILD_GIT_PATH}"
  1323. install -v -c -m 644 "scripts/${README_OUT_FILE_NAME}" \
  1324. "${APP_PREFIX}/README.md"
  1325. )
  1326. }
  1327. function final_tunings()
  1328. {
  1329. # Create the missing LTO plugin links.
  1330. # For `ar` to work with LTO objects, it needs the plugin in lib/bfd-plugins,
  1331. # but the build leaves it where `ld` needs it. On POSIX, make a soft link.
  1332. if [ "${FIX_LTO_PLUGIN}" == "y" ]
  1333. then
  1334. (
  1335. cd "${APP_PREFIX}"
  1336. echo
  1337. if [ "${TARGET_PLATFORM}" == "win32" ]
  1338. then
  1339. echo
  1340. echo "Copying ${LTO_PLUGIN_ORIGINAL_NAME}..."
  1341. mkdir -pv "$(dirname ${LTO_PLUGIN_BFD_PATH})"
  1342. if [ ! -f "${LTO_PLUGIN_BFD_PATH}" ]
  1343. then
  1344. local plugin_path="$(find * -type f -name ${LTO_PLUGIN_ORIGINAL_NAME})"
  1345. if [ ! -z "${plugin_path}" ]
  1346. then
  1347. cp -v "${plugin_path}" "${LTO_PLUGIN_BFD_PATH}"
  1348. else
  1349. echo "${LTO_PLUGIN_ORIGINAL_NAME} not found."
  1350. exit 1
  1351. fi
  1352. fi
  1353. else
  1354. echo
  1355. echo "Creating ${LTO_PLUGIN_ORIGINAL_NAME} link..."
  1356. mkdir -pv "$(dirname ${LTO_PLUGIN_BFD_PATH})"
  1357. if [ ! -f "${LTO_PLUGIN_BFD_PATH}" ]
  1358. then
  1359. local plugin_path="$(find * -type f -name ${LTO_PLUGIN_ORIGINAL_NAME})"
  1360. if [ ! -z "${plugin_path}" ]
  1361. then
  1362. ln -s -v "../../${plugin_path}" "${LTO_PLUGIN_BFD_PATH}"
  1363. else
  1364. echo "${LTO_PLUGIN_ORIGINAL_NAME} not found."
  1365. exit 1
  1366. fi
  1367. fi
  1368. fi
  1369. )
  1370. fi
  1371. }
  1372. # -----------------------------------------------------------------------------