container-apps-functions-source.sh 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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 GNU MCU Eclipse 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_gcc_combo()
  14. {
  15. # https://developer.arm.com/open-source/gnu-toolchain/gnu-rm
  16. # https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
  17. cd "${SOURCES_FOLDER_PATH}"
  18. download_and_extract "${GCC_COMBO_URL}" "${GCC_COMBO_ARCHIVE}" \
  19. "${GCC_COMBO_FOLDER_NAME}"
  20. }
  21. function download_gdb()
  22. {
  23. # Same package as binutils.
  24. if [ ! -d "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}" ]
  25. then
  26. cd "${SOURCES_FOLDER_PATH}"
  27. if [ -n "${GDB_GIT_URL}" ]
  28. then
  29. git_clone "${GDB_GIT_URL}" "${GDB_GIT_BRANCH}" \
  30. "${GDB_GIT_COMMIT}" "${GDB_SRC_FOLDER_NAME}"
  31. cd "${GDB_SRC_FOLDER_NAME}"
  32. do_patch "${GDB_PATCH}"
  33. else
  34. extract "${GCC_COMBO_FOLDER_NAME}/src/gdb.tar.bz2" \
  35. "${GDB_SRC_FOLDER_NAME}" "${GDB_PATCH}"
  36. fi
  37. fi
  38. }
  39. # -----------------------------------------------------------------------------
  40. function download_python_win()
  41. {
  42. # https://www.python.org/downloads/release/python-2714/
  43. # https://www.python.org/ftp/python/2.7.14/python-2.7.14.msi
  44. # https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi
  45. PYTHON_WIN_PACK="${PYTHON_WIN}.msi"
  46. PYTHON_WIN_URL="https://www.python.org/ftp/python/${PYTHON_WIN_VERSION}/${PYTHON_WIN_PACK}"
  47. cd "${SOURCES_FOLDER_PATH}"
  48. download "${PYTHON_WIN_URL}" "${PYTHON_WIN_PACK}"
  49. (
  50. xbb_activate
  51. if [ ! -d "${PYTHON_WIN}" ]
  52. then
  53. cd "${SOURCES_FOLDER_PATH}"
  54. # Include only the headers and the python library and executable.
  55. echo '*.h' >"/tmp/included"
  56. echo 'python*.dll' >>"/tmp/included"
  57. echo 'python*.lib' >>"/tmp/included"
  58. 7za x -o"${PYTHON_WIN}" "${DOWNLOAD_FOLDER_PATH}/${PYTHON_WIN_PACK}" -i@"/tmp/included"
  59. # Patch to disable the macro that renames hypot.
  60. local patch_path="${BUILD_GIT_PATH}/patches/${PYTHON_WIN}.patch"
  61. if [ -f "${patch_path}" ]
  62. then
  63. (
  64. cd "${PYTHON_WIN}"
  65. patch -p0 <"${patch_path}"
  66. )
  67. fi
  68. else
  69. echo "Folder ${PYTHON_WIN} already present."
  70. fi
  71. echo "Copying python27.dll..."
  72. # From here it'll be copied as dependency.
  73. mkdir -p "${LIBS_INSTALL_FOLDER_PATH}/bin/"
  74. install -v -c -m 644 "${PYTHON_WIN}/python27.dll" \
  75. "${LIBS_INSTALL_FOLDER_PATH}/bin/"
  76. )
  77. }
  78. function download_python3_win()
  79. {
  80. # https://www.python.org/downloads/windows/
  81. # https://www.python.org/downloads/release/python-372/
  82. # https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip
  83. # https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-amd64.zip
  84. # https://www.python.org/ftp/python/3.7.2/python-3.7.2.exe
  85. # https://www.python.org/ftp/python/3.7.2/python-3.7.2-amd64.exe
  86. # https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
  87. PYTHON3_WIN_EMBED_PACK="${PYTHON3_WIN_EMBED_FOLDER_NAME}.zip"
  88. PYTHON3_WIN_EMBED_URL="https://www.python.org/ftp/python/${PYTHON3_VERSION}/${PYTHON3_WIN_EMBED_PACK}"
  89. (
  90. xbb_activate
  91. if [ ! -d "${SOURCES_FOLDER_PATH}/${PYTHON3_WIN_EMBED_FOLDER_NAME}" ]
  92. then
  93. mkdir -p "${SOURCES_FOLDER_PATH}/${PYTHON3_WIN_EMBED_FOLDER_NAME}"
  94. cd "${SOURCES_FOLDER_PATH}/${PYTHON3_WIN_EMBED_FOLDER_NAME}"
  95. download_and_extract "${PYTHON3_WIN_EMBED_URL}" "${PYTHON3_WIN_EMBED_PACK}" "${PYTHON3_WIN_EMBED_FOLDER_NAME}"
  96. else
  97. echo "Folder ${PYTHON3_WIN_EMBED_FOLDER_NAME} already present."
  98. fi
  99. cd "${SOURCES_FOLDER_PATH}/${PYTHON3_WIN_EMBED_FOLDER_NAME}"
  100. echo "Copying python${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR}.dll..."
  101. # From here it'll be copied as dependency.
  102. mkdir -p "${LIBS_INSTALL_FOLDER_PATH}/bin/"
  103. install -v -c -m 644 "python${PYTHON3_VERSION_MAJOR}.dll" \
  104. "${LIBS_INSTALL_FOLDER_PATH}/bin/"
  105. install -v -c -m 644 "python${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR}.dll" \
  106. "${LIBS_INSTALL_FOLDER_PATH}/bin/"
  107. )
  108. PYTHON3_ARCHIVE="${PYTHON3_SRC_FOLDER_NAME}.tar.xz"
  109. PYTHON3_URL="https://www.python.org/ftp/python/${PYTHON3_VERSION}/${PYTHON3_ARCHIVE}"
  110. PYTHON3_FOLDER_NAME="python-${PYTHON3_VERSION}"
  111. if [ ! -d "${SOURCES_FOLDER_PATH}/${PYTHON3_SRC_FOLDER_NAME}" ]
  112. then
  113. cd "${SOURCES_FOLDER_PATH}"
  114. download_and_extract "${PYTHON3_URL}" "${PYTHON3_ARCHIVE}" \
  115. "${PYTHON3_SRC_FOLDER_NAME}"
  116. # The source archive includes only the pyconfig.h.in, which needs
  117. # to be configured, which is not an easy task. Thus add the file copied
  118. # from a Windows install.
  119. cp "${BUILD_GIT_PATH}/patches/pyconfig-${PYTHON3_VERSION}.h" Include/pyconfig.h
  120. fi
  121. }
  122. # -----------------------------------------------------------------------------
  123. function download_binutils()
  124. {
  125. if [ ! -d "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}" ]
  126. then
  127. (
  128. xbb_activate
  129. cd "${SOURCES_FOLDER_PATH}"
  130. if [ -n "${BINUTILS_GIT_URL}" ]
  131. then
  132. git_clone "${BINUTILS_GIT_URL}" "${BINUTILS_GIT_BRANCH}" \
  133. "${BINUTILS_GIT_COMMIT}" "${BINUTILS_SRC_FOLDER_NAME}"
  134. cd "${BINUTILS_SRC_FOLDER_NAME}"
  135. do_patch "${BINUTILS_PATCH}"
  136. else
  137. # Note: define BINUTILS_PATCH to the patch file name.
  138. extract "${GCC_COMBO_FOLDER_NAME}/src/binutils.tar.bz2" \
  139. "${BINUTILS_SRC_FOLDER_NAME}" "${BINUTILS_PATCH}"
  140. fi
  141. )
  142. fi
  143. }
  144. # -----------------------------------------------------------------------------
  145. function do_binutils()
  146. {
  147. # https://ftp.gnu.org/gnu/binutils/
  148. # https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=binutils-git
  149. # https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=gdb-git
  150. BINUTILS_FOLDER_NAME="binutils-${BINUTILS_VERSION}"
  151. local binutils_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-binutils-${BINUTILS_VERSION}-installed"
  152. if [ ! -f "${binutils_stamp_file_path}" ]
  153. then
  154. download_binutils
  155. (
  156. mkdir -p "${BUILD_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}"
  157. cd "${BUILD_FOLDER_PATH}/${BINUTILS_FOLDER_NAME}"
  158. xbb_activate
  159. xbb_activate_installed_dev
  160. export CFLAGS="${XBB_CFLAGS} -Wno-deprecated-declarations -Wno-implicit-function-declaration -Wno-parentheses -Wno-format-nonliteral -Wno-shift-count-overflow -Wno-shift-negative-value -Wno-format -Wno-implicit-fallthrough"
  161. export CXXFLAGS="${XBB_CXXFLAGS} -Wno-format-nonliteral -Wno-format-security -Wno-deprecated -Wno-c++11-narrowing"
  162. export CPPFLAGS="${XBB_CPPFLAGS}"
  163. LDFLAGS="${XBB_LDFLAGS_APP}"
  164. if [ "${TARGET_PLATFORM}" == "win32" ]
  165. then
  166. LDFLAGS="${LDFLAGS} -Wl,${XBB_FOLDER}/${CROSS_COMPILE_PREFIX}/lib/CRT_glob.o"
  167. fi
  168. export LDFLAGS
  169. if [ ! -f "config.status" ]
  170. then
  171. (
  172. echo
  173. echo "Running binutils configure..."
  174. bash "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}/configure" --help
  175. # ? --without-python --without-curses, --with-expat
  176. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}/configure" \
  177. --prefix="${APP_PREFIX}" \
  178. --infodir="${APP_PREFIX_DOC}/info" \
  179. --mandir="${APP_PREFIX_DOC}/man" \
  180. --htmldir="${APP_PREFIX_DOC}/html" \
  181. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  182. \
  183. --build=${BUILD} \
  184. --host=${HOST} \
  185. --target=${GCC_TARGET} \
  186. \
  187. --with-pkgversion="${BRANDING}" \
  188. \
  189. --disable-nls \
  190. --disable-werror \
  191. --disable-sim \
  192. --disable-gdb \
  193. --enable-interwork \
  194. --enable-plugins \
  195. --with-sysroot="${APP_PREFIX}/${GCC_TARGET}" \
  196. \
  197. --enable-build-warnings=no \
  198. --disable-rpath \
  199. --with-system-zlib \
  200. cp "config.log" "${LOGS_FOLDER_PATH}/config-binutils-log.txt"
  201. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/configure-binutils-output.txt"
  202. fi
  203. (
  204. echo
  205. echo "Running binutils make..."
  206. # Build.
  207. make -j ${JOBS}
  208. if [ "${WITH_STRIP}" == "y" ]
  209. then
  210. # For -strip, readline needs a patch.
  211. make install-strip
  212. else
  213. make install
  214. fi
  215. (
  216. xbb_activate_tex
  217. if [ "${WITH_PDF}" == "y" ]
  218. then
  219. make pdf
  220. make install-pdf
  221. fi
  222. if [ "${WITH_HTML}" == "y" ]
  223. then
  224. make html
  225. make install-html
  226. fi
  227. )
  228. # Without this copy, the build for the nano version of the GCC second
  229. # step fails with unexpected errors, like "cannot compute suffix of
  230. # object files: cannot compile".
  231. copy_dir "${APP_PREFIX}" "${APP_PREFIX_NANO}"
  232. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/make-binutils-output.txt"
  233. )
  234. touch "${binutils_stamp_file_path}"
  235. else
  236. echo "Component binutils already installed."
  237. fi
  238. }
  239. function run_binutils()
  240. {
  241. (
  242. xbb_activate_installed_bin
  243. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-ar" --version
  244. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-as" --version
  245. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-ld" --version
  246. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-nm" --version
  247. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-objcopy" --version
  248. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-objdump" --version
  249. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-ranlib" --version
  250. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-size" --version
  251. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-strings" --version
  252. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-strip" --version
  253. )
  254. }
  255. function do_gcc_first()
  256. {
  257. local gcc_first_folder_name="gcc-${GCC_VERSION}-first"
  258. local gcc_first_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-gcc-${GCC_VERSION}-first-installed"
  259. if [ ! -f "${gcc_first_stamp_file_path}" ]
  260. then
  261. cd "${SOURCES_FOLDER_PATH}"
  262. extract "${GCC_COMBO_FOLDER_NAME}/src/gcc.tar.bz2" \
  263. "${GCC_SRC_FOLDER_NAME}" "${GCC_PATCH}"
  264. (
  265. mkdir -p "${BUILD_FOLDER_PATH}/${gcc_first_folder_name}"
  266. cd "${BUILD_FOLDER_PATH}/${gcc_first_folder_name}"
  267. xbb_activate
  268. xbb_activate_installed_dev
  269. export GCC_WARN_CFLAGS="-Wno-tautological-compare -Wno-deprecated-declarations -Wno-unused-value -Wno-implicit-fallthrough -Wno-implicit-function-declaration -Wno-unused-but-set-variable -Wno-shift-negative-value -Wno-misleading-indentation"
  270. export CFLAGS="${XBB_CFLAGS} ${GCC_WARN_CFLAGS}"
  271. export GCC_WARN_CXXFLAGS="-Wno-format-security -Wno-char-subscripts -Wno-deprecated -Wno-array-bounds -Wno-invalid-offsetof -Wno-implicit-fallthrough -Wno-format-security -Wno-suggest-attribute=format -Wno-format-extra-args -Wno-format -Wno-varargs -Wno-shift-count-overflow -Wno-ignored-attributes -Wno-tautological-compare -Wno-unused-label -Wno-unused-parameter -Wno-literal-suffix -Wno-expansion-to-defined -Wno-maybe-uninitialized -Wno-shift-negative-value -Wno-memset-elt-size -Wno-dangling-else -Wno-sequence-point -Wno-misleading-indentation -Wno-int-in-bool-context"
  272. export CXXFLAGS="${XBB_CXXFLAGS} ${GCC_WARN_CXXFLAGS}"
  273. export CPPFLAGS="${XBB_CPPFLAGS}"
  274. export LDFLAGS="${XBB_LDFLAGS_APP}"
  275. export CFLAGS_FOR_TARGET="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  276. export CXXFLAGS_FOR_TARGET="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  277. if [ ! -f "config.status" ]
  278. then
  279. (
  280. echo
  281. echo "Running gcc first stage configure..."
  282. bash "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" --help
  283. # https://gcc.gnu.org/install/configure.html
  284. # --enable-shared[=package[,…]] build shared versions of libraries
  285. # --enable-tls specify that the target supports TLS (Thread Local Storage).
  286. # --enable-nls enables Native Language Support (NLS)
  287. # --enable-checking=list the compiler is built to perform internal consistency checks of the requested complexity. ‘yes’ (most common checks)
  288. # --with-headers=dir specify that target headers are available when building a cross compiler
  289. # --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.
  290. # --enable-languages=c newlib does not use C++, so C should be enough
  291. # --enable-checking=no ???
  292. # --enable-lto make it explicit, Arm uses the default.
  293. # Prefer an explicit libexec folder.
  294. # --libexecdir="${APP_PREFIX}/lib"
  295. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" \
  296. --prefix="${APP_PREFIX}" \
  297. --infodir="${APP_PREFIX_DOC}/info" \
  298. --mandir="${APP_PREFIX_DOC}/man" \
  299. --htmldir="${APP_PREFIX_DOC}/html" \
  300. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  301. \
  302. --build=${BUILD} \
  303. --host=${HOST} \
  304. --target=${GCC_TARGET} \
  305. \
  306. --with-pkgversion="${BRANDING}" \
  307. \
  308. --enable-languages=c \
  309. --enable-lto \
  310. --disable-decimal-float \
  311. --disable-libffi \
  312. --disable-libgomp \
  313. --disable-libmudflap \
  314. --disable-libquadmath \
  315. --disable-libssp \
  316. --disable-libstdcxx-pch \
  317. --disable-nls \
  318. --disable-threads \
  319. --disable-tls \
  320. --with-newlib \
  321. --without-headers \
  322. --with-gnu-as \
  323. --with-gnu-ld \
  324. --with-python-dir=share/gcc-${GCC_TARGET} \
  325. --with-sysroot="${APP_PREFIX}/${GCC_TARGET}" \
  326. ${MULTILIB_FLAGS} \
  327. \
  328. --disable-rpath \
  329. --disable-build-format-warnings \
  330. --with-system-zlib \
  331. cp "config.log" "${LOGS_FOLDER_PATH}/config-gcc-first-log.txt"
  332. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/configure-gcc-first-output.txt"
  333. fi
  334. (
  335. # Partial build, without documentation.
  336. echo
  337. echo "Running gcc first stage make..."
  338. # No need to make 'all', 'all-gcc' is enough to compile the libraries.
  339. # Parallel builds may fail.
  340. make -j ${JOBS} all-gcc
  341. # make all-gcc
  342. # No -strip available here.
  343. make install-gcc
  344. # Strip?
  345. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/make-gcc-first-output.txt"
  346. )
  347. touch "${gcc_first_stamp_file_path}"
  348. else
  349. echo "Component gcc first stage already installed."
  350. fi
  351. }
  352. # For the nano build, call it with "-nano".
  353. # $1="" or $1="-nano"
  354. function do_newlib()
  355. {
  356. local newlib_folder_name="newlib-${NEWLIB_VERSION}$1"
  357. local newlib_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-newlib$1-${NEWLIB_VERSION}-installed"
  358. if [ ! -f "${newlib_stamp_file_path}" ]
  359. then
  360. cd "${SOURCES_FOLDER_PATH}"
  361. extract "${GCC_COMBO_FOLDER_NAME}/src/newlib.tar.bz2" "${NEWLIB_SRC_FOLDER_NAME}"
  362. (
  363. mkdir -p "${BUILD_FOLDER_PATH}/${newlib_folder_name}"
  364. cd "${BUILD_FOLDER_PATH}/${newlib_folder_name}"
  365. xbb_activate
  366. xbb_activate_installed_dev
  367. # Add the gcc first stage binaries to the path.
  368. PATH="${APP_PREFIX}/bin:${PATH}"
  369. local optimize="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  370. if [ "$1" == "-nano" ]
  371. then
  372. # For newlib-nano optimize for size.
  373. optimize="$(echo ${optimize} | sed -e 's/-O2/-Os/')"
  374. fi
  375. export CFLAGS="${XBB_CFLAGS}"
  376. export CXXFLAGS="${XBB_CXXFLAGS}"
  377. export CPPFLAGS="${XBB_CPPFLAGS}"
  378. # Note the intentional `-g`.
  379. CFLAGS_FOR_TARGET="${optimize} -g -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Wno-int-conversion -Wno-logical-not-parentheses -Wno-implicit-int -Wno-expansion-to-defined"
  380. CXXFLAGS_FOR_TARGET="${optimize} -g"
  381. if [ "${WITH_NEWLIB_LTO}" == "y" ]
  382. then
  383. CFLAGS_FOR_TARGET+=" -flto -ffat-lto-objects"
  384. CXXFLAGS_FOR_TARGET+=" -flto -ffat-lto-objects"
  385. fi
  386. export CFLAGS_FOR_TARGET
  387. export CXXFLAGS_FOR_TARGET
  388. if [ ! -f "config.status" ]
  389. then
  390. (
  391. # --disable-nls do not use Native Language Support
  392. # --enable-newlib-io-long-double enable long double type support in IO functions printf/scanf
  393. # --enable-newlib-io-long-long enable long long type support in IO functions like printf/scanf
  394. # --enable-newlib-io-c99-formats enable C99 support in IO functions like printf/scanf
  395. # --enable-newlib-register-fini enable finalization function registration using atexit
  396. # --disable-newlib-supplied-syscalls disable newlib from supplying syscalls (__NO_SYSCALLS__)
  397. # --disable-newlib-fvwrite-in-streamio disable iov in streamio
  398. # --disable-newlib-fseek-optimization disable fseek optimization
  399. # --disable-newlib-wide-orient Turn off wide orientation in streamio
  400. # --disable-newlib-unbuf-stream-opt disable unbuffered stream optimization in streamio
  401. # --enable-newlib-nano-malloc use small-footprint nano-malloc implementation
  402. # --enable-lite-exit enable light weight exit
  403. # --enable-newlib-global-atexit enable atexit data structure as global
  404. # --enable-newlib-nano-formatted-io Use nano version formatted IO
  405. # --enable-newlib-reent-small
  406. # --enable-newlib-retargetable-locking ???
  407. echo
  408. echo "Running newlib$1 configure..."
  409. bash "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}/configure" --help
  410. # I still did not figure out how to define a variable with
  411. # the list of options, such that it can be extended, so the
  412. # brute force approach is to duplicate the entire call.
  413. if [ "$1" == "" ]
  414. then
  415. # Extra options to Arm distribution:
  416. # --enable-newlib-io-long-long
  417. # --enable-newlib-io-c99-formats
  418. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}/configure" \
  419. --prefix="${APP_PREFIX}" \
  420. --infodir="${APP_PREFIX_DOC}/info" \
  421. --mandir="${APP_PREFIX_DOC}/man" \
  422. --htmldir="${APP_PREFIX_DOC}/html" \
  423. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  424. \
  425. --build=${BUILD} \
  426. --host=${HOST} \
  427. --target="${GCC_TARGET}" \
  428. \
  429. --enable-newlib-io-long-double \
  430. --enable-newlib-register-fini \
  431. --enable-newlib-retargetable-locking \
  432. --disable-newlib-supplied-syscalls \
  433. --disable-nls \
  434. \
  435. --enable-newlib-io-long-long \
  436. --enable-newlib-io-c99-formats \
  437. elif [ "$1" == "-nano" ]
  438. then
  439. # --enable-newlib-io-long-long and --enable-newlib-io-c99-formats
  440. # are currently ignored if --enable-newlib-nano-formatted-io.
  441. # --enable-newlib-register-fini is debatable, was removed.
  442. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}/configure" \
  443. --prefix="${APP_PREFIX_NANO}" \
  444. \
  445. --build=${BUILD} \
  446. --host=${HOST} \
  447. --target="${GCC_TARGET}" \
  448. \
  449. --disable-newlib-supplied-syscalls \
  450. --enable-newlib-reent-small \
  451. --enable-newlib-retargetable-locking \
  452. --disable-newlib-fvwrite-in-streamio \
  453. --disable-newlib-fseek-optimization \
  454. --disable-newlib-wide-orient \
  455. --enable-newlib-nano-malloc \
  456. --disable-newlib-unbuf-stream-opt \
  457. --enable-lite-exit \
  458. --enable-newlib-global-atexit \
  459. --enable-newlib-nano-formatted-io \
  460. --disable-nls \
  461. else
  462. echo "Unsupported do_newlib arg $1"
  463. exit 1
  464. fi
  465. cp "config.log" "${LOGS_FOLDER_PATH}/config-newlib$1-log.txt"
  466. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/configure-newlib$1-output.txt"
  467. fi
  468. (
  469. # Partial build, without documentation.
  470. echo
  471. echo "Running newlib$1 make..."
  472. # Parallel builds may fail.
  473. make -j ${JOBS}
  474. # make
  475. # Top make fails with install-strip due to libgloss make.
  476. make install
  477. if [ "$1" == "" ]
  478. then
  479. if [ "${WITH_PDF}" == "y" ]
  480. then
  481. # Warning, parallel build failed on Debian 32-bit.
  482. (
  483. if [[ "${RELEASE_VERSION}" =~ 5\.4\.1-* ]]
  484. then
  485. hack_pdfetex
  486. fi
  487. xbb_activate_tex
  488. make pdf
  489. )
  490. install -v -d "${APP_PREFIX_DOC}/pdf"
  491. install -v -c -m 644 \
  492. "${GCC_TARGET}/libgloss/doc/porting.pdf" "${APP_PREFIX_DOC}/pdf"
  493. install -v -c -m 644 \
  494. "${GCC_TARGET}/newlib/libc/libc.pdf" "${APP_PREFIX_DOC}/pdf"
  495. install -v -c -m 644 \
  496. "${GCC_TARGET}/newlib/libm/libm.pdf" "${APP_PREFIX_DOC}/pdf"
  497. fi
  498. if [ "${WITH_HTML}" == "y" ]
  499. then
  500. make html
  501. install -v -d "${APP_PREFIX_DOC}/html"
  502. copy_dir "${GCC_TARGET}/newlib/libc/libc.html" "${APP_PREFIX_DOC}/html/libc"
  503. copy_dir "${GCC_TARGET}/newlib/libm/libm.html" "${APP_PREFIX_DOC}/html/libm"
  504. fi
  505. fi
  506. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/make-newlib$1-output.txt"
  507. )
  508. touch "${newlib_stamp_file_path}"
  509. else
  510. echo "Component newlib$1 already installed."
  511. fi
  512. }
  513. # -----------------------------------------------------------------------------
  514. function copy_nano_libs()
  515. {
  516. local src_folder="$1"
  517. local dst_folder="$2"
  518. if [ -f "${src_folder}/libstdc++.a" ]
  519. then
  520. cp -v -f "${src_folder}/libstdc++.a" "${dst_folder}/libstdc++_nano.a"
  521. fi
  522. if [ -f "${src_folder}/libsupc++.a" ]
  523. then
  524. cp -v -f "${src_folder}/libsupc++.a" "${dst_folder}/libsupc++_nano.a"
  525. fi
  526. cp -v -f "${src_folder}/libc.a" "${dst_folder}/libc_nano.a"
  527. cp -v -f "${src_folder}/libg.a" "${dst_folder}/libg_nano.a"
  528. if [ -f "${src_folder}/librdimon.a" ]
  529. then
  530. cp -v -f "${src_folder}/librdimon.a" "${dst_folder}/librdimon_nano.a"
  531. fi
  532. cp -v -f "${src_folder}/nano.specs" "${dst_folder}/"
  533. if [ -f "${src_folder}/rdimon.specs" ]
  534. then
  535. cp -v -f "${src_folder}/rdimon.specs" "${dst_folder}/"
  536. fi
  537. cp -v -f "${src_folder}/nosys.specs" "${dst_folder}/"
  538. cp -v -f "${src_folder}"/*crt0.o "${dst_folder}/"
  539. }
  540. # Copy target libraries from each multilib folders.
  541. # $1=source
  542. # $2=destination
  543. # $3=target gcc
  544. function copy_multi_libs()
  545. {
  546. local -a multilibs
  547. local multilib
  548. local multi_folder
  549. local src_folder="$1"
  550. local dst_folder="$2"
  551. local gcc_target="$3"
  552. echo ${gcc_target}
  553. multilibs=( $("${gcc_target}" -print-multi-lib 2>/dev/null) )
  554. if [ ${#multilibs[@]} -gt 0 ]
  555. then
  556. for multilib in "${multilibs[@]}"
  557. do
  558. multi_folder="${multilib%%;*}"
  559. copy_nano_libs "${src_folder}/${multi_folder}" \
  560. "${dst_folder}/${multi_folder}"
  561. done
  562. else
  563. copy_nano_libs "${src_folder}" "${dst_folder}"
  564. fi
  565. }
  566. # -----------------------------------------------------------------------------
  567. function copy_linux_libs()
  568. {
  569. local copy_linux_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-copy-linux-completed"
  570. if [ ! -f "${copy_linux_stamp_file_path}" ]
  571. then
  572. local linux_path="${LINUX_INSTALL_PATH}"
  573. (
  574. cd "${WORK_FOLDER_PATH}"
  575. copy_dir "${linux_path}/${GCC_TARGET}/lib" "${APP_PREFIX}/${GCC_TARGET}/lib"
  576. copy_dir "${linux_path}/${GCC_TARGET}/include" "${APP_PREFIX}/${GCC_TARGET}/include"
  577. copy_dir "${linux_path}/include" "${APP_PREFIX}/include"
  578. copy_dir "${linux_path}/lib" "${APP_PREFIX}/lib"
  579. copy_dir "${linux_path}/share" "${APP_PREFIX}/share"
  580. )
  581. (
  582. cd "${APP_PREFIX}"
  583. find "${GCC_TARGET}/lib" "${GCC_TARGET}/include" "include" "lib" "share" \
  584. -perm /111 -and ! -type d \
  585. -exec rm '{}' ';'
  586. )
  587. touch "${copy_linux_stamp_file_path}"
  588. else
  589. echo "Component copy-linux-libs already processed."
  590. fi
  591. }
  592. # -----------------------------------------------------------------------------
  593. # For the nano build, call it with "-nano".
  594. # $1="" or $1="-nano"
  595. function do_gcc_final()
  596. {
  597. local gcc_final_folder_name="gcc-${GCC_VERSION}-final$1"
  598. local gcc_final_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-gcc$1-final-${GCC_VERSION}-installed"
  599. if [ ! -f "${gcc_final_stamp_file_path}" ]
  600. then
  601. cd "${SOURCES_FOLDER_PATH}"
  602. extract "${GCC_COMBO_FOLDER_NAME}/src/gcc.tar.bz2" \
  603. "${GCC_SRC_FOLDER_NAME}" "${GCC_PATCH}"
  604. (
  605. mkdir -p "${BUILD_FOLDER_PATH}/${gcc_final_folder_name}"
  606. cd "${BUILD_FOLDER_PATH}/${gcc_final_folder_name}"
  607. xbb_activate
  608. xbb_activate_installed_dev
  609. export GCC_WARN_CFLAGS="-Wno-tautological-compare -Wno-deprecated-declarations -Wno-unused-value -Wno-implicit-fallthrough -Wno-implicit-function-declaration -Wno-unused-but-set-variable -Wno-shift-negative-value -Wno-expansion-to-defined"
  610. export CFLAGS="${XBB_CFLAGS} ${GCC_WARN_CFLAGS}"
  611. export GCC_WARN_CXXFLAGS="-Wno-format-security -Wno-char-subscripts -Wno-deprecated -Wno-array-bounds -Wno-invalid-offsetof -Wno-implicit-fallthrough -Wno-format-security -Wno-suggest-attribute=format -Wno-format-extra-args -Wno-format -Wno-unused-function -Wno-attributes -Wno-maybe-uninitialized -Wno-expansion-to-defined -Wno-misleading-indentation -Wno-literal-suffix -Wno-int-in-bool-context -Wno-memset-elt-size -Wno-shift-negative-value -Wno-dangling-else -Wno-sequence-point -Wno-nonnull"
  612. export CXXFLAGS="${XBB_CXXFLAGS} ${GCC_WARN_CXXFLAGS}"
  613. export CPPFLAGS="${XBB_CPPFLAGS}"
  614. export LDFLAGS="${XBB_LDFLAGS_APP}"
  615. # Do not add CRT_glob.o here, it will fail with already defined,
  616. # since it is already handled by --enable-mingw-wildcard.
  617. local optimize="${CFLAGS_OPTIMIZATIONS_FOR_TARGET}"
  618. if [ "$1" == "-nano" ]
  619. then
  620. # For newlib-nano optimize for size.
  621. optimize="$(echo ${optimize} | sed -e 's/-O2/-Os/')"
  622. fi
  623. # Note the intentional `-g`.
  624. CFLAGS_FOR_TARGET="${optimize} -g"
  625. CXXFLAGS_FOR_TARGET="${optimize} -fno-exceptions -g"
  626. if [ "${WITH_LIBS_LTO}" == "y" ]
  627. then
  628. CFLAGS_FOR_TARGET+=" -flto -ffat-lto-objects"
  629. CXXFLAGS_FOR_TARGET+=" -flto -ffat-lto-objects"
  630. fi
  631. export CFLAGS_FOR_TARGET
  632. export CXXFLAGS_FOR_TARGET
  633. local mingw_wildcard="--disable-mingw-wildcard"
  634. if [ "${TARGET_PLATFORM}" == "win32" ]
  635. then
  636. add_linux_install_path
  637. mingw_wildcard="--enable-mingw-wildcard"
  638. export AR_FOR_TARGET=${GCC_TARGET}-ar
  639. export NM_FOR_TARGET=${GCC_TARGET}-nm
  640. export OBJDUMP_FOR_TARET=${GCC_TARGET}-objdump
  641. export STRIP_FOR_TARGET=${GCC_TARGET}-strip
  642. export CC_FOR_TARGET=${GCC_TARGET}-gcc
  643. export GCC_FOR_TARGET=${GCC_TARGET}-gcc
  644. export CXX_FOR_TARGET=${GCC_TARGET}-g++
  645. fi
  646. if [ ! -f "config.status" ]
  647. then
  648. (
  649. echo
  650. echo "Running gcc$1 final stage configure..."
  651. bash "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" --help
  652. # https://gcc.gnu.org/install/configure.html
  653. # --enable-shared[=package[,…]] build shared versions of libraries
  654. # --enable-tls specify that the target supports TLS (Thread Local Storage).
  655. # --enable-nls enables Native Language Support (NLS)
  656. # --enable-checking=list the compiler is built to perform internal consistency checks of the requested complexity. ‘yes’ (most common checks)
  657. # --with-headers=dir specify that target headers are available when building a cross compiler
  658. # --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.
  659. # --enable-languages=c,c++ Support only C/C++, ignore all other.
  660. # Prefer an explicit libexec folder.
  661. # --libexecdir="${APP_PREFIX}/lib" \
  662. # --enable-lto make it explicit, Arm uses the default.
  663. # --with-native-system-header-dir is needed to locate stdio.h, to
  664. # prevent -Dinhibit_libc, which will skip some functionality,
  665. # like libgcov.
  666. if [ "$1" == "" ]
  667. then
  668. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" \
  669. --prefix="${APP_PREFIX}" \
  670. --infodir="${APP_PREFIX_DOC}/info" \
  671. --mandir="${APP_PREFIX_DOC}/man" \
  672. --htmldir="${APP_PREFIX_DOC}/html" \
  673. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  674. \
  675. --build=${BUILD} \
  676. --host=${HOST} \
  677. --target=${GCC_TARGET} \
  678. \
  679. --with-pkgversion="${BRANDING}" \
  680. \
  681. --enable-languages=c,c++ \
  682. ${mingw_wildcard} \
  683. --enable-plugins \
  684. --enable-lto \
  685. --disable-decimal-float \
  686. --disable-libffi \
  687. --disable-libgomp \
  688. --disable-libmudflap \
  689. --disable-libquadmath \
  690. --disable-libssp \
  691. --disable-libstdcxx-pch \
  692. --disable-nls \
  693. --disable-threads \
  694. --disable-tls \
  695. --with-gnu-as \
  696. --with-gnu-ld \
  697. --with-newlib \
  698. --with-headers=yes \
  699. --with-python-dir="share/gcc-${GCC_TARGET}" \
  700. --with-sysroot="${APP_PREFIX}/${GCC_TARGET}" \
  701. --with-native-system-header-dir="/include" \
  702. ${MULTILIB_FLAGS} \
  703. \
  704. --disable-rpath \
  705. --disable-build-format-warnings \
  706. --with-system-zlib
  707. elif [ "$1" == "-nano" ]
  708. then
  709. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}/configure" \
  710. --prefix="${APP_PREFIX_NANO}" \
  711. \
  712. --build=${BUILD} \
  713. --host=${HOST} \
  714. --target=${GCC_TARGET} \
  715. \
  716. --with-pkgversion="${BRANDING}" \
  717. \
  718. --enable-languages=c,c++ \
  719. --disable-decimal-float \
  720. --disable-libffi \
  721. --disable-libgomp \
  722. --disable-libmudflap \
  723. --disable-libquadmath \
  724. --disable-libssp \
  725. --disable-libstdcxx-pch \
  726. --disable-libstdcxx-verbose \
  727. --disable-nls \
  728. --disable-threads \
  729. --disable-tls \
  730. --with-gnu-as \
  731. --with-gnu-ld \
  732. --with-newlib \
  733. --with-headers=yes \
  734. --with-python-dir="share/gcc-${GCC_TARGET}" \
  735. --with-sysroot="${APP_PREFIX_NANO}/${GCC_TARGET}" \
  736. --with-native-system-header-dir="/include" \
  737. ${MULTILIB_FLAGS} \
  738. \
  739. --disable-rpath \
  740. --disable-build-format-warnings \
  741. --with-system-zlib
  742. fi
  743. cp "config.log" "${LOGS_FOLDER_PATH}/config-gcc$1-final-log.txt"
  744. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/configure-gcc$1-final-output.txt"
  745. fi
  746. (
  747. # Partial build, without documentation.
  748. echo
  749. echo "Running gcc$1 final stage make..."
  750. if [ "${TARGET_PLATFORM}" != "win32" ]
  751. then
  752. # Passing USE_TM_CLONE_REGISTRY=0 via INHIBIT_LIBC_CFLAGS to disable
  753. # transactional memory related code in crtbegin.o.
  754. # This is a workaround. Better approach is have a t-* to set this flag via
  755. # CRTSTUFF_T_CFLAGS
  756. # Parallel builds may fail.
  757. make -j ${JOBS} INHIBIT_LIBC_CFLAGS="-DUSE_TM_CLONE_REGISTRY=0"
  758. # make INHIBIT_LIBC_CFLAGS="-DUSE_TM_CLONE_REGISTRY=0"
  759. if [ "${WITH_STRIP}" == "y" ]
  760. then
  761. make install-strip
  762. else
  763. make install
  764. fi
  765. if [ "$1" == "-nano" ]
  766. then
  767. local target_gcc=""
  768. if [ "${TARGET_PLATFORM}" == "win32" ]
  769. then
  770. target_gcc="${GCC_TARGET}-gcc"
  771. else
  772. target_gcc="${APP_PREFIX_NANO}/bin/${GCC_TARGET}-gcc"
  773. fi
  774. # Copy the libraries after appending the `_nano` suffix.
  775. # Iterate through all multilib names.
  776. copy_multi_libs \
  777. "${APP_PREFIX_NANO}/${GCC_TARGET}/lib" \
  778. "${APP_PREFIX}/${GCC_TARGET}/lib" \
  779. "${target_gcc}"
  780. # Copy the nano configured newlib.h file into the location that nano.specs
  781. # expects it to be.
  782. mkdir -p "${APP_PREFIX}/${GCC_TARGET}/include/newlib-nano"
  783. cp -v -f "${APP_PREFIX_NANO}/${GCC_TARGET}/include/newlib.h" \
  784. "${APP_PREFIX}/${GCC_TARGET}/include/newlib-nano/newlib.h"
  785. fi
  786. else
  787. # For Windows build only the GCC binaries, the libraries were copied
  788. # from the Linux build.
  789. # Parallel builds may fail.
  790. make -j ${JOBS} all-gcc
  791. # make all-gcc
  792. # No -strip here.
  793. make install-gcc
  794. # Strip?
  795. fi
  796. if [ "$1" == "" ]
  797. then
  798. (
  799. xbb_activate_tex
  800. # Full build, with documentation.
  801. if [ "${WITH_PDF}" == "y" ]
  802. then
  803. make pdf
  804. make install-pdf
  805. fi
  806. if [ "${WITH_HTML}" == "y" ]
  807. then
  808. make html
  809. make install-html
  810. fi
  811. )
  812. fi
  813. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/make-gcc$1-final-output.txt"
  814. )
  815. touch "${gcc_final_stamp_file_path}"
  816. else
  817. echo "Component gcc$1 final stage already installed."
  818. fi
  819. }
  820. function run_gcc()
  821. {
  822. (
  823. xbb_activate
  824. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" --help
  825. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -dumpversion
  826. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -dumpmachine
  827. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -print-multi-lib
  828. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -dumpspecs | wc -l
  829. local tmp=$(mktemp /tmp/gcc-test.XXXXX)
  830. rm -rf "${tmp}"
  831. mkdir -p "${tmp}"
  832. cd "${tmp}"
  833. # Note: __EOF__ is quoted to prevent substitutions here.
  834. cat <<'__EOF__' > hello.c
  835. #include <stdio.h>
  836. int
  837. main(int argc, char* argv[])
  838. {
  839. printf("Hello World\n");
  840. }
  841. __EOF__
  842. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -o hello-c.elf -specs=nosys.specs hello.c
  843. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -o hello.c.o -c -flto hello.c
  844. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gcc" -o hello-c-lto.elf -specs=nosys.specs -flto -v hello.c.o
  845. # Note: __EOF__ is quoted to prevent substitutions here.
  846. cat <<'__EOF__' > hello.cpp
  847. #include <iostream>
  848. int
  849. main(int argc, char* argv[])
  850. {
  851. std::cout << "Hello World" << std::endl;
  852. }
  853. extern "C" void __sync_synchronize();
  854. void
  855. __sync_synchronize()
  856. {
  857. }
  858. __EOF__
  859. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-g++" -o hello-cpp.elf -specs=nosys.specs hello.cpp
  860. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-g++" -o hello.cpp.o -c -flto hello.cpp
  861. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-g++" -o hello-cpp-lto.elf -specs=nosys.specs -flto -v hello.cpp.o
  862. cd ..
  863. rm -rf "${tmp}"
  864. )
  865. }
  866. # Called multile times, with and without python support.
  867. # $1="" or $1="-py" or $1="-py3"
  868. function do_gdb()
  869. {
  870. local gdb_folder_name="gdb-${GDB_VERSION}$1"
  871. local gdb_stamp_file_path="${INSTALL_FOLDER_PATH}/stamp-gdb$1-${GDB_VERSION}-installed"
  872. if [ ! -f "${gdb_stamp_file_path}" ]
  873. then
  874. cd "${SOURCES_FOLDER_PATH}"
  875. download_gdb
  876. (
  877. mkdir -p "${BUILD_FOLDER_PATH}/${gdb_folder_name}"
  878. cd "${BUILD_FOLDER_PATH}/${gdb_folder_name}"
  879. local platform_python2
  880. if [ -x "/usr/bin/python2.7" ]
  881. then
  882. platform_python2="/usr/bin/python2.7"
  883. elif [ -x "/usr/bin/python2.6" ]
  884. then
  885. platform_python2="/usr/bin/python2.6"
  886. else
  887. set +e
  888. platform_python2="$(which python)"
  889. set -e
  890. fi
  891. local platform_python3
  892. if [ -x "/usr/bin/python3.6" ]
  893. then
  894. platform_python3="/usr/bin/python3.6"
  895. else
  896. set +e
  897. platform_python3="$(which python3)"
  898. set -e
  899. fi
  900. xbb_activate
  901. xbb_activate_installed_dev
  902. if [ "${TARGET_PLATFORM}" == "win32" ]
  903. then
  904. # Definition required by python-config.sh.
  905. export GNURM_PYTHON_WIN_DIR="${SOURCES_FOLDER_PATH}/${PYTHON_WIN}"
  906. fi
  907. GCC_WARN_CFLAGS="-Wno-implicit-function-declaration -Wno-parentheses -Wno-format -Wno-deprecated-declarations -Wno-implicit-fallthrough -Wno-format-nonliteral"
  908. GCC_WARN_CXXFLAGS="-Wno-deprecated-declarations"
  909. if [ "${TARGET_PLATFORM}" == "darwin" ]
  910. then
  911. GCC_WARN_CXXFLAGS+=" -Wno-c++11-narrowing"
  912. else
  913. GCC_WARN_CFLAGS+=" -Wno-maybe-uninitialized -Wno-int-in-bool-context -Wno-misleading-indentation"
  914. fi
  915. export GCC_WARN_CFLAGS
  916. export GCC_WARN_CXXFLAGS
  917. export CFLAGS="${XBB_CFLAGS} ${GCC_WARN_CFLAGS}"
  918. export CXXFLAGS="${XBB_CXXFLAGS} ${GCC_WARN_CXXFLAGS}"
  919. export CPPFLAGS="${XBB_CPPFLAGS}"
  920. export LDFLAGS="${XBB_LDFLAGS_APP}"
  921. # libiconv is used by Python3.
  922. export LIBS="-liconv"
  923. if [ "${TARGET_PLATFORM}" == "darwin" ]
  924. then
  925. # When compiled with GCC-7 it fails to run, due to
  926. # some problems with exceptions unwind.
  927. export CC=clang
  928. export CXX=clang++
  929. fi
  930. local extra_python_opts="--with-python=no"
  931. if [ "$1" == "-py" ]
  932. then
  933. if [ "${TARGET_PLATFORM}" == "win32" ]
  934. then
  935. extra_python_opts="--with-python=${SOURCES_FOLDER_PATH}/${GCC_COMBO_FOLDER_NAME}/python-config.sh"
  936. elif [ "${USE_PLATFORM_PYTHON}" == "y" ]
  937. then
  938. extra_python_opts="--with-python=${platform_python2}"
  939. else
  940. extra_python_opts="--with-python=$(which python2)"
  941. fi
  942. elif [ "$1" == "-py3" ]
  943. then
  944. if [ "${TARGET_PLATFORM}" == "win32" ]
  945. then
  946. extra_python_opts="--with-python=${BUILD_GIT_PATH}/patches/python3-config.sh"
  947. elif [ "${USE_PLATFORM_PYTHON3}" == "y" ]
  948. then
  949. extra_python_opts="--with-python=${platform_python3}"
  950. else
  951. extra_python_opts="--with-python=$(which python3)"
  952. fi
  953. fi
  954. if [ ! -f "config.status" ]
  955. then
  956. (
  957. echo
  958. echo "Running gdb$1 configure..."
  959. bash "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}/gdb/configure" --help
  960. # Note that all components are disabled, except GDB.
  961. bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}/configure" \
  962. --prefix="${APP_PREFIX}" \
  963. --infodir="${APP_PREFIX_DOC}/info" \
  964. --mandir="${APP_PREFIX_DOC}/man" \
  965. --htmldir="${APP_PREFIX_DOC}/html" \
  966. --pdfdir="${APP_PREFIX_DOC}/pdf" \
  967. \
  968. --build=${BUILD} \
  969. --host=${HOST} \
  970. --target=${GCC_TARGET} \
  971. \
  972. --with-pkgversion="${BRANDING}" \
  973. \
  974. --disable-nls \
  975. --disable-sim \
  976. --disable-gas \
  977. --disable-binutils \
  978. --disable-ld \
  979. --disable-gprof \
  980. --with-expat \
  981. --with-lzma=yes \
  982. --with-system-gdbinit="${APP_PREFIX}/${GCC_TARGET}/lib/gdbinit" \
  983. --with-gdb-datadir="${APP_PREFIX}/${GCC_TARGET}/share/gdb" \
  984. \
  985. ${extra_python_opts} \
  986. --program-prefix="${GCC_TARGET}-" \
  987. --program-suffix="$1" \
  988. \
  989. --disable-werror \
  990. --enable-build-warnings=no \
  991. --disable-rpath \
  992. --with-system-zlib \
  993. --without-guile \
  994. --without-babeltrace \
  995. --without-libunwind-ia64
  996. cp "config.log" "${LOGS_FOLDER_PATH}/config-gdb$1-log.txt"
  997. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/configure-gdb$1-output.txt"
  998. fi
  999. (
  1000. echo
  1001. echo "Running gdb$1 make..."
  1002. # Parallel builds may fail.
  1003. make -j ${JOBS}
  1004. # make
  1005. # install-strip fails, not only because of readline has no install-strip
  1006. # but even after patching it tries to strip a non elf file
  1007. # strip:.../install/riscv-none-gcc/bin/_inst.672_: file format not recognized
  1008. make install
  1009. if [ "$1" == "" ]
  1010. then
  1011. (
  1012. xbb_activate_tex
  1013. if [ "${WITH_PDF}" == "y" ]
  1014. then
  1015. make pdf
  1016. make install-pdf
  1017. fi
  1018. if [ "${WITH_HTML}" == "y" ]
  1019. then
  1020. make html
  1021. make install-html
  1022. fi
  1023. )
  1024. fi
  1025. ) 2>&1 | tee "${LOGS_FOLDER_PATH}/make-gdb$1-output.txt"
  1026. )
  1027. touch "${gdb_stamp_file_path}"
  1028. else
  1029. echo "Component gdb$1 already installed."
  1030. fi
  1031. }
  1032. function run_gdb()
  1033. {
  1034. local suffix=""
  1035. if [ $# -ge 1 ]
  1036. then
  1037. suffix="$1"
  1038. fi
  1039. # 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
  1040. if [ "${suffix}" == "-py3" -a "${TARGET_PLATFORM}" == "linux" -a "${TARGET_ARCH}" == "x32" ]
  1041. then
  1042. return 0
  1043. fi
  1044. (
  1045. # Required by gdb-py to access the python shared library.
  1046. xbb_activate_installed_bin
  1047. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" --version
  1048. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" --config
  1049. # This command is known to fail with 'Abort trap: 6' (SIGABRT)
  1050. run_app "${APP_PREFIX}/bin/${GCC_TARGET}-gdb${suffix}" \
  1051. --nh \
  1052. --nx \
  1053. -ex='show language' \
  1054. -ex='set language auto' \
  1055. -ex='quit'
  1056. )
  1057. }
  1058. function tidy_up()
  1059. {
  1060. (
  1061. xbb_activate
  1062. echo
  1063. echo "Tidying up..."
  1064. find "${APP_PREFIX}" -name "libiberty.a" -exec rm -v '{}' ';'
  1065. find "${APP_PREFIX}" -name '*.la' -exec rm -v '{}' ';'
  1066. if [ "${TARGET_PLATFORM}" == "win32" ]
  1067. then
  1068. find "${APP_PREFIX}" -name "liblto_plugin.a" -exec rm -v '{}' ';'
  1069. find "${APP_PREFIX}" -name "liblto_plugin.dll.a" -exec rm -v '{}' ';'
  1070. fi
  1071. )
  1072. }
  1073. function strip_binaries()
  1074. {
  1075. local folder_path="${APP_PREFIX}"
  1076. if [ $# -ge 1 ]
  1077. then
  1078. folder_path="$1"
  1079. fi
  1080. if [ "${WITH_STRIP}" == "y" ]
  1081. then
  1082. (
  1083. xbb_activate
  1084. echo
  1085. echo "Stripping binaries..."
  1086. local binaries
  1087. if [ "${TARGET_PLATFORM}" == "win32" ]
  1088. then
  1089. binaries=$(find "${folder_path}" -name \*.exe)
  1090. for bin in ${binaries}
  1091. do
  1092. strip_binary2 "${CROSS_COMPILE_PREFIX}"-strip "${bin}"
  1093. done
  1094. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  1095. then
  1096. binaries=$(find "${folder_path}" -name \* -perm +111 -and ! -type d)
  1097. for bin in ${binaries}
  1098. do
  1099. if is_elf "${bin}"
  1100. then
  1101. strip_binary2 strip "${bin}"
  1102. fi
  1103. done
  1104. elif [ "${TARGET_PLATFORM}" == "linux" ]
  1105. then
  1106. binaries=$(find "${folder_path}" -name \* -perm /111 -and ! -type d)
  1107. for bin in ${binaries}
  1108. do
  1109. if is_elf "${bin}"
  1110. then
  1111. strip_binary2 strip "${bin}"
  1112. fi
  1113. done
  1114. fi
  1115. )
  1116. fi
  1117. }
  1118. function strip_libs()
  1119. {
  1120. if [ "${WITH_STRIP}" == "y" ]
  1121. then
  1122. (
  1123. xbb_activate
  1124. PATH="${APP_PREFIX}/bin:${PATH}"
  1125. echo
  1126. echo "Stripping libraries..."
  1127. cd "${WORK_FOLDER_PATH}"
  1128. # which "${GCC_TARGET}-objcopy"
  1129. local libs=$(find "${APP_PREFIX}" -name '*.[ao]')
  1130. for lib in ${libs}
  1131. do
  1132. echo "${GCC_TARGET}-objcopy -R ... ${lib}"
  1133. "${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
  1134. done
  1135. )
  1136. fi
  1137. }
  1138. function copy_distro_files()
  1139. {
  1140. (
  1141. xbb_activate
  1142. rm -rf "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1143. mkdir -p "${APP_PREFIX}/${DISTRO_INFO_NAME}"
  1144. echo
  1145. echo "Copying license files..."
  1146. copy_license \
  1147. "${SOURCES_FOLDER_PATH}/${ZLIB_FOLDER_NAME}" \
  1148. "${ZLIB_FOLDER_NAME}"
  1149. copy_license \
  1150. "${SOURCES_FOLDER_PATH}/${GMP_FOLDER_NAME}" \
  1151. "${GMP_FOLDER_NAME}"
  1152. copy_license \
  1153. "${SOURCES_FOLDER_PATH}/${MPFR_FOLDER_NAME}" \
  1154. "${MPFR_FOLDER_NAME}"
  1155. copy_license \
  1156. "${SOURCES_FOLDER_PATH}/${MPC_FOLDER_NAME}" \
  1157. "${MPC_FOLDER_NAME}"
  1158. copy_license \
  1159. "${SOURCES_FOLDER_PATH}/${ISL_FOLDER_NAME}" \
  1160. "${ISL_FOLDER_NAME}"
  1161. copy_license \
  1162. "${SOURCES_FOLDER_PATH}/${LIBELF_FOLDER_NAME}" \
  1163. "${LIBELF_FOLDER_NAME}"
  1164. copy_license \
  1165. "${SOURCES_FOLDER_PATH}/${EXPAT_FOLDER_NAME}" \
  1166. "${EXPAT_FOLDER_NAME}"
  1167. copy_license \
  1168. "${SOURCES_FOLDER_PATH}/${LIBICONV_FOLDER_NAME}" \
  1169. "${LIBICONV_FOLDER_NAME}"
  1170. copy_license \
  1171. "${SOURCES_FOLDER_PATH}/${XZ_FOLDER_NAME}" \
  1172. "${XZ_FOLDER_NAME}"
  1173. copy_license \
  1174. "${SOURCES_FOLDER_PATH}/${BINUTILS_SRC_FOLDER_NAME}" \
  1175. "${BINUTILS_SRC_FOLDER_NAME}-${BINUTILS_VERSION}"
  1176. copy_license \
  1177. "${SOURCES_FOLDER_PATH}/${GCC_SRC_FOLDER_NAME}" \
  1178. "${GCC_SRC_FOLDER_NAME}-${GCC_VERSION}"
  1179. copy_license \
  1180. "${SOURCES_FOLDER_PATH}/${NEWLIB_SRC_FOLDER_NAME}" \
  1181. "${NEWLIB_SRC_FOLDER_NAME}-${NEWLIB_VERSION}"
  1182. copy_license \
  1183. "${SOURCES_FOLDER_PATH}/${GDB_SRC_FOLDER_NAME}" \
  1184. "${GDB_SRC_FOLDER_NAME}-${GDB_VERSION}"
  1185. copy_build_files
  1186. echo
  1187. echo "Copying Arm files..."
  1188. cd "${SOURCES_FOLDER_PATH}/${GCC_COMBO_FOLDER_NAME}"
  1189. install -v -c -m 644 "readme.txt" \
  1190. "${APP_PREFIX}/${DISTRO_INFO_NAME}/arm-readme.txt"
  1191. install -v -c -m 644 "release.txt" \
  1192. "${APP_PREFIX}/${DISTRO_INFO_NAME}/arm-release.txt"
  1193. echo
  1194. echo "Copying distro files..."
  1195. cd "${BUILD_GIT_PATH}"
  1196. install -v -c -m 644 "scripts/${README_OUT_FILE_NAME}" \
  1197. "${APP_PREFIX}/README.md"
  1198. )
  1199. }
  1200. function final_tunings()
  1201. {
  1202. # Create the missing LTO plugin links.
  1203. # For `ar` to work with LTO objects, it needs the plugin in lib/bfd-plugins,
  1204. # but the build leaves it where `ld` needs it. On POSIX, make a soft link.
  1205. if [ "${FIX_LTO_PLUGIN}" == "y" ]
  1206. then
  1207. (
  1208. cd "${APP_PREFIX}"
  1209. echo
  1210. if [ "${TARGET_PLATFORM}" == "win32" ]
  1211. then
  1212. echo
  1213. echo "Copying ${LTO_PLUGIN_ORIGINAL_NAME}..."
  1214. mkdir -p "$(dirname ${LTO_PLUGIN_BFD_PATH})"
  1215. if [ ! -f "${LTO_PLUGIN_BFD_PATH}" ]
  1216. then
  1217. local plugin_path="$(find * -type f -name ${LTO_PLUGIN_ORIGINAL_NAME})"
  1218. if [ ! -z "${plugin_path}" ]
  1219. then
  1220. cp -v "${plugin_path}" "${LTO_PLUGIN_BFD_PATH}"
  1221. else
  1222. echo "${LTO_PLUGIN_ORIGINAL_NAME} not found."
  1223. exit 1
  1224. fi
  1225. fi
  1226. else
  1227. echo
  1228. echo "Creating ${LTO_PLUGIN_ORIGINAL_NAME} link..."
  1229. mkdir -p "$(dirname ${LTO_PLUGIN_BFD_PATH})"
  1230. if [ ! -f "${LTO_PLUGIN_BFD_PATH}" ]
  1231. then
  1232. local plugin_path="$(find * -type f -name ${LTO_PLUGIN_ORIGINAL_NAME})"
  1233. if [ ! -z "${plugin_path}" ]
  1234. then
  1235. ln -s -v "../../${plugin_path}" "${LTO_PLUGIN_BFD_PATH}"
  1236. else
  1237. echo "${LTO_PLUGIN_ORIGINAL_NAME} not found."
  1238. exit 1
  1239. fi
  1240. fi
  1241. fi
  1242. )
  1243. fi
  1244. }