common-versions-source.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. # -----------------------------------------------------------------------------
  2. # This file is part of the xPacks distribution.
  3. # (https://xpack.github.io)
  4. # Copyright (c) 2020 Liviu Ionescu.
  5. #
  6. # Permission to use, copy, modify, and/or distribute this software
  7. # for any purpose is hereby granted, under the terms of the MIT license.
  8. # -----------------------------------------------------------------------------
  9. # Helper script used in the second edition of the 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 build_versions()
  14. {
  15. APP_PREFIX_NANO="${INSTALL_FOLDER_PATH}/${APP_LC_NAME}-nano"
  16. # The \x2C is a comma in hex; without this trick the regular expression
  17. # that processes this string in the Makefile, silently fails and the
  18. # bfdver.h file remains empty.
  19. BRANDING="${BRANDING}\x2C ${TARGET_BITS}-bit"
  20. CFLAGS_OPTIMIZATIONS_FOR_TARGET="-ffunction-sections -fdata-sections -O2"
  21. # Cannot use medlow with 64 bits, so all must be medany.
  22. CFLAGS_OPTIMIZATIONS_FOR_TARGET+=" -mcmodel=medany"
  23. BINUTILS_PROJECT_NAME="riscv-binutils-gdb"
  24. GCC_PROJECT_NAME="riscv-gcc"
  25. NEWLIB_PROJECT_NAME="riscv-newlib"
  26. GDB_PROJECT_NAME="riscv-binutils-gdb"
  27. # ---------------------------------------------------------------------------
  28. # Defaults. Must be present.
  29. BINUTILS_PATCH=""
  30. GDB_PATCH=""
  31. WITH_GDB_PY2=""
  32. WITH_GDB_PY3=""
  33. USE_PLATFORM_PYTHON2=""
  34. USE_PLATFORM_PYTHON3=""
  35. if [ "${WITHOUT_MULTILIB}" == "y" ]
  36. then
  37. MULTILIB_FLAGS="--disable-multilib"
  38. else
  39. # By default it searches the definitions in "t-elf-multilib"
  40. MULTILIB_FLAGS=""
  41. fi
  42. # ---------------------------------------------------------------------------
  43. # Redefine to "y" to create the LTO plugin links.
  44. FIX_LTO_PLUGIN=""
  45. if [ "${TARGET_PLATFORM}" == "darwin" ]
  46. then
  47. LTO_PLUGIN_ORIGINAL_NAME="liblto_plugin.0.so"
  48. LTO_PLUGIN_BFD_PATH="lib/bfd-plugins/liblto_plugin.so"
  49. elif [ "${TARGET_PLATFORM}" == "linux" ]
  50. then
  51. LTO_PLUGIN_ORIGINAL_NAME="liblto_plugin.so.0.0.0"
  52. LTO_PLUGIN_BFD_PATH="lib/bfd-plugins/liblto_plugin.so"
  53. elif [ "${TARGET_PLATFORM}" == "win32" ]
  54. then
  55. LTO_PLUGIN_ORIGINAL_NAME="liblto_plugin-0.dll"
  56. LTO_PLUGIN_BFD_PATH="lib/bfd-plugins/liblto_plugin-0.dll"
  57. fi
  58. FIX_LTO_PLUGIN="y"
  59. # ---------------------------------------------------------------------------
  60. README_OUT_FILE_NAME="README-${RELEASE_VERSION}.md"
  61. # In reverse chronological order.
  62. # Keep them in sync with https://github.com/sifive/freedom-tools/releases.
  63. if [[ "${RELEASE_VERSION}" =~ 8\.3\.0-* ]]
  64. then
  65. # This is similar to SiFive 2019.08.0 release.
  66. # https://github.com/sifive/freedom-tools/releases
  67. # Binutils 2.32 with SiFive CLIC patches
  68. # https://github.com/sifive/riscv-binutils-gdb/tree/03d23d58701bdd425c613b0be2d458bcde46912b
  69. # GCC 8.3.0 with SiFive CLIC patches
  70. # https://github.com/sifive/riscv-gcc/tree/e195042babe2dc30d9fabb88d336d8c8679b3702
  71. # Newlib 3.1.0 from SiFive branch
  72. # https://github.com/sifive/riscv-newlib/tree/0d24a86822a5ee73d6a6aa69e2a0118aa1e35204
  73. # GDB 8.3 from FSF gdb-8.3-release branch
  74. # riscv-gdb @ 9b40759 (11 May 2019)
  75. # https://sourceware.org/git/?p=binutils-gdb.git
  76. # git://sourceware.org/git/binutils-gdb.git
  77. # -------------------------------------------------------------------------
  78. # Inspired from SiFive
  79. # MULTILIBS_GEN := rv32e-ilp32e--c rv32em-ilp32e--c rv32eac-ilp32e-- rv32emac-ilp32e-- rv32i-ilp32--c rv32im-ilp32--c rv32imf-ilp32f--c rv32iac-ilp32-- rv32imac-ilp32-- rv32imafc-ilp32f-rv32imafdc- rv32imafdc-ilp32d-- rv64i-lp64--c rv64im-lp64--c rv64imf-lp64f--c rv64iac-lp64-- rv64imac-lp64-- rv64imafc-lp64f-rv64imafdc- rv64imafdc-lp64d--
  80. # Minimal list, for tests only. Pass it via the environment.
  81. # GCC_MULTILIB=${GCC_MULTILIB:-"rv32imac-ilp32-- rv64imac-lp64--"}
  82. # New extended list, based on SiFive list.
  83. # Added: rv32imaf-ilp32f--
  84. GCC_MULTILIB=${GCC_MULTILIB:-"\
  85. rv32e-ilp32e--c \
  86. rv32ea-ilp32e--m \
  87. rv32em-ilp32e--c \
  88. rv32eac-ilp32e-- \
  89. rv32emac-ilp32e-- \
  90. rv32i-ilp32--c \
  91. rv32ia-ilp32--m \
  92. rv32im-ilp32--c \
  93. rv32if-ilp32f-rv32ifd-c \
  94. rv32iaf-ilp32f-rv32imaf,rv32iafc-d \
  95. rv32imf-ilp32f-rv32imfd-c \
  96. rv32imaf-ilp32f-- \
  97. rv32iac-ilp32-- \
  98. rv32imac-ilp32-- \
  99. rv32imafc-ilp32f-rv32imafdc- \
  100. rv32ifd-ilp32d--c \
  101. rv32imfd-ilp32d--c \
  102. rv32iafd-ilp32d-rv32imafd,rv32iafdc- \
  103. rv32imafdc-ilp32d-- \
  104. rv64i-lp64--c \
  105. rv64ia-lp64--m \
  106. rv64im-lp64--c \
  107. rv64if-lp64f-rv64ifd-c \
  108. rv64iaf-lp64f-rv64iafc-d \
  109. rv64imf-lp64f-rv64imfd-c \
  110. rv64imaf-lp64f-- \
  111. rv64iac-lp64-- \
  112. rv64imac-lp64-- \
  113. rv64imafc-lp64f-rv64imafdc- \
  114. rv64ifd-lp64d--m,c \
  115. rv64iafd-lp64d-rv64imafd,rv64iafdc- \
  116. rv64imafdc-lp64d-- \
  117. "}
  118. GCC_MULTILIB_FILE=${GCC_MULTILIB_FILE:-"t-elf-multilib"}
  119. # -------------------------------------------------------------------------
  120. BINUTILS_VERSION="2.32"
  121. # From gcc/BASE_VER
  122. GCC_VERSION="8.3.0"
  123. # From newlib/configure, VERSION=
  124. NEWLIB_VERSION="3.1.0"
  125. # From gdb/VERSION.in
  126. GDB_VERSION="8.3"
  127. # -------------------------------------------------------------------------
  128. if [ "${USE_GITS}" != "y" ]
  129. then
  130. # Be sure there is no `v`, it is added in the URL.
  131. GH_RELEASE="8.3.0-1.1"
  132. BINUTILS_GH_RELEASE=${BINUTILS_GH_RELEASE:-"${GH_RELEASE}"}
  133. GCC_GH_RELEASE=${GCC_GH_RELEASE:-"${GH_RELEASE}"}
  134. NEWLIB_GH_RELEASE=${NEWLIB_GH_RELEASE:-"${GH_RELEASE}"}
  135. # Same, with a `-gdb` suffix added.
  136. GDB_GH_RELEASE=${GDB_GH_RELEASE:-"${GH_RELEASE}-gdb"}
  137. else
  138. BINUTILS_GIT_BRANCH=${BINUTILS_GIT_BRANCH:-"sifive-binutils-2.32-xpack"}
  139. # 16 April 2019
  140. BINUTILS_GIT_COMMIT=${BINUTILS_GIT_COMMIT:-"03d23d58701bdd425c613b0be2d458bcde46912b"}
  141. GCC_GIT_BRANCH=${GCC_GIT_BRANCH:-"sifive-gcc-8.3.0-xpack"}
  142. GCC_GIT_COMMIT=${GCC_GIT_COMMIT:-"e195042babe2dc30d9fabb88d336d8c8679b3702"}
  143. NEWLIB_GIT_BRANCH=${NEWLIB_GIT_BRANCH:-"sifive-master-xpack"}
  144. NEWLIB_GIT_COMMIT=${NEWLIB_GIT_COMMIT:-"0d24a86822a5ee73d6a6aa69e2a0118aa1e35204"}
  145. GDB_SRC_FOLDER_NAME=${GDB_SRC_FOLDER_NAME:-"binutils-gdb.git"}
  146. GDB_GIT_BRANCH=${GDB_GIT_BRANCH:-"sifive-gdb-8.3-xpack"}
  147. GDB_GIT_COMMIT=${GDB_GIT_COMMIT:-"9b8cecd18313807ac0cc4d2b1871603279b94244"}
  148. fi
  149. # -------------------------------------------------------------------------
  150. ZLIB_VERSION="1.2.8"
  151. GMP_VERSION="6.1.2"
  152. MPFR_VERSION="3.1.6"
  153. MPC_VERSION="1.0.3"
  154. ISL_VERSION="0.18"
  155. LIBELF_VERSION="0.8.13"
  156. EXPAT_VERSION="2.2.5"
  157. LIBICONV_VERSION="1.15"
  158. XZ_VERSION="5.2.3"
  159. # -------------------------------------------------------------------------
  160. if [ "${RELEASE_VERSION}" == "8.3.0-1.1" ]
  161. then
  162. PYTHON2_WIN_VERSION="2.7.13"
  163. if [ "${TARGET_PLATFORM}" == "darwin" ]
  164. then
  165. USE_PLATFORM_PYTHON2="y"
  166. fi
  167. WITH_GDB_PY2="y"
  168. elif [ "${RELEASE_VERSION}" == "8.3.0-1.2" ]
  169. then
  170. if [ "${TARGET_PLATFORM}" == "win32" ]
  171. then
  172. # On Windows if fails with
  173. # "The procedure entry point ClearCommBreak could not be located
  174. # in the dynamic link library."
  175. # It looks like an incompatibility between Python2 and mingw-w64.
  176. # Given that Python2 is end-of-life, it is not worth to further
  177. # investigate, disable it for now.
  178. WITH_GDB_PY2=""
  179. elif [ "${TARGET_PLATFORM}" == "darwin" ]
  180. then
  181. # ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/operator.so, 2): Symbol not found: __PyUnicodeUCS2_AsDefaultEncodedString
  182. # Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/operator.so
  183. # Expected in: flat namespace
  184. # in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/operator.so
  185. WITH_GDB_PY2=""
  186. else
  187. WITH_GDB_PY2="y"
  188. fi
  189. PYTHON2_WIN_VERSION="2.7.18"
  190. WITH_GDB_PY3="y"
  191. PYTHON3_WIN_VERSION="3.7.6"
  192. else
  193. echo "Unsupported version ${RELEASE_VERSION}."
  194. exit 1
  195. fi
  196. BINUTILS_PATCH="binutils-gdb-${BINUTILS_VERSION}.patch"
  197. GDB_PATCH="binutils-gdb-${BINUTILS_VERSION}.patch"
  198. # -------------------------------------------------------------------------
  199. elif [[ "${RELEASE_VERSION}" =~ 8\.2\.0-3\.* ]]
  200. then
  201. # This is similar to SiFive 2019.05.0 release.
  202. # https://github.com/sifive/freedom-tools/releases
  203. # Binutils 2.32 with SiFive CLIC patches
  204. # https://github.com/sifive/riscv-binutils-gdb/tree/164267155c96f91472a539ca78ac919993bc5b4e
  205. # GCC 8.2.0 with SiFive CLIC patches
  206. # https://github.com/sifive/riscv-gcc/tree/242abcaff697d0a1ea12dccc975465e1bfeb8331
  207. # GDB 8.3 from FSF gdb-8.3-release branch
  208. # riscv-gdb @ 9b40759 (11 May 2019)
  209. # https://sourceware.org/git/?p=binutils-gdb.git
  210. # git://sourceware.org/git/binutils-gdb.git
  211. # Newlib 3.0.0 from SiFive branch
  212. # https://github.com/sifive/riscv-newlib/tree/42c2e3fb9f557d59b76d1a64bb6fb32707ff4530
  213. # -------------------------------------------------------------------------
  214. # Inspired from SiFive
  215. # MULTILIBS_GEN := rv32e-ilp32e--c rv32em-ilp32e--c rv32eac-ilp32e-- rv32emac-ilp32e-- rv32i-ilp32--c rv32im-ilp32--c rv32imf-ilp32f--c rv32iac-ilp32-- rv32imac-ilp32-- rv32imafc-ilp32f-rv32imafdc- rv32imafdc-ilp32d-- rv64i-lp64--c rv64im-lp64--c rv64imf-lp64f--c rv64iac-lp64-- rv64imac-lp64-- rv64imafc-lp64f-rv64imafdc- rv64imafdc-lp64d--
  216. # Minimal list, for tests only. Pass it via the environment.
  217. # GCC_MULTILIB=${GCC_MULTILIB:-"rv32imac-ilp32-- rv64imac-lp64--"}
  218. # New extended list, based on SiFive list.
  219. # Added: rv32imaf-ilp32f--
  220. GCC_MULTILIB=${GCC_MULTILIB:-"rv32e-ilp32e--c rv32em-ilp32e--c rv32eac-ilp32e-- rv32emac-ilp32e-- rv32i-ilp32--c rv32im-ilp32--c rv32imf-ilp32f--c rv32imaf-ilp32f-- rv32iac-ilp32-- rv32imac-ilp32-- rv32imafc-ilp32f-rv32imafdc- rv32imafdc-ilp32d-- rv64i-lp64--c rv64im-lp64--c rv64imf-lp64f--c rv64iac-lp64-- rv64imac-lp64-- rv64imafc-lp64f-rv64imafdc- rv64imafdc-lp64d--"}
  221. GCC_MULTILIB_FILE=${GCC_MULTILIB_FILE:-"t-elf-multilib"}
  222. # -------------------------------------------------------------------------
  223. BINUTILS_VERSION="2.32"
  224. # From gcc/BASE_VER
  225. GCC_VERSION="8.2.0"
  226. # From newlib/configure, VERSION=
  227. NEWLIB_VERSION="3.0.0"
  228. # From gdb/VERSION.in
  229. GDB_VERSION="8.3"
  230. # -------------------------------------------------------------------------
  231. if [ "${USE_GITS}" != "y" ]
  232. then
  233. # Be sure there is no `v`, it is added in the URL.
  234. GH_RELEASE="8.2.0-3.1"
  235. BINUTILS_GH_RELEASE=${BINUTILS_GH_RELEASE:-"${GH_RELEASE}"}
  236. GCC_GH_RELEASE=${GCC_GH_RELEASE:-"${GH_RELEASE}"}
  237. NEWLIB_GH_RELEASE=${NEWLIB_GH_RELEASE:-"${GH_RELEASE}"}
  238. # Same, with a `-gdb` suffix added.
  239. GDB_GH_RELEASE=${GDB_GH_RELEASE:-"${GH_RELEASE}-gdb"}
  240. else
  241. BINUTILS_GIT_BRANCH=${BINUTILS_GIT_BRANCH:-"sifive-binutils-2.32-xpack"}
  242. # 16 April 2019
  243. BINUTILS_GIT_COMMIT=${BINUTILS_GIT_COMMIT:-"82b51c7b5087ddb77988287cd7a2dd8921331bfd"}
  244. GCC_GIT_BRANCH=${GCC_GIT_BRANCH:-"sifive-gcc-8.2.0-xpack"}
  245. GCC_GIT_COMMIT=${GCC_GIT_COMMIT:-"0c7a874f0b6f452eeafde57731646e5f460187e4"}
  246. NEWLIB_GIT_BRANCH=${NEWLIB_GIT_BRANCH:-"sifive-newlib-3.0.0-xpack"}
  247. NEWLIB_GIT_COMMIT=${NEWLIB_GIT_COMMIT:-"1975c561730cbd4b93c491eaadeb6c3b01a89447"}
  248. GDB_SRC_FOLDER_NAME=${GDB_SRC_FOLDER_NAME:-"binutils-gdb.git"}
  249. GDB_GIT_BRANCH=${GDB_GIT_BRANCH:-"sifive-gdb-8.3-xpack"}
  250. GDB_GIT_COMMIT=${GDB_GIT_COMMIT:-"9b8cecd18313807ac0cc4d2b1871603279b94244"}
  251. fi
  252. # -------------------------------------------------------------------------
  253. ZLIB_VERSION="1.2.8"
  254. GMP_VERSION="6.1.2"
  255. MPFR_VERSION="3.1.6"
  256. MPC_VERSION="1.0.3"
  257. ISL_VERSION="0.18"
  258. LIBELF_VERSION="0.8.13"
  259. EXPAT_VERSION="2.2.5"
  260. LIBICONV_VERSION="1.15"
  261. XZ_VERSION="5.2.3"
  262. WITH_GDB_PY2="y"
  263. PYTHON2_WIN_VERSION="2.7.13"
  264. BINUTILS_PATCH="binutils-gdb-${BINUTILS_VERSION}.patch"
  265. GDB_PATCH="binutils-gdb-${BINUTILS_VERSION}.patch"
  266. # -------------------------------------------------------------------------
  267. else
  268. echo "Unsupported version ${RELEASE_VERSION}."
  269. exit 1
  270. fi
  271. prepare_variables
  272. # ---------------------------------------------------------------------------
  273. # Build dependent libraries.
  274. # For better control, without it some components pick the lib packed
  275. # inside the archive.
  276. build_zlib "${ZLIB_VERSION}"
  277. # The classical GCC libraries.
  278. build_gmp "${GMP_VERSION}"
  279. build_mpfr "${MPFR_VERSION}"
  280. build_mpc "${MPC_VERSION}"
  281. build_isl "${ISL_VERSION}"
  282. # More libraries.
  283. # Fails on mingw
  284. ## do_libelf
  285. build_expat "${EXPAT_VERSION}"
  286. build_libiconv "${LIBICONV_VERSION}"
  287. build_xz "${XZ_VERSION}"
  288. build_gettext "0.19.8.1"
  289. if [ "${TARGET_PLATFORM}" != "win32" ]
  290. then
  291. # Used by ncurses. Fails on macOS.
  292. if [ "${TARGET_PLATFORM}" == "linux" ]
  293. then
  294. build_gpm "1.20.7"
  295. fi
  296. build_ncurses "6.2"
  297. fi
  298. # ---------------------------------------------------------------------------
  299. # The task descriptions are from the ARM build script.
  300. # Task [III-0] /$HOST_NATIVE/binutils/
  301. # Task [IV-1] /$HOST_MINGW/binutils/
  302. build_binutils
  303. # copy_dir to libs included above
  304. if [ "${TARGET_PLATFORM}" != "win32" ]
  305. then
  306. # Task [III-1] /$HOST_NATIVE/gcc-first/
  307. build_gcc_first
  308. # Task [III-2] /$HOST_NATIVE/newlib/
  309. build_newlib ""
  310. # Task [III-3] /$HOST_NATIVE/newlib-nano/
  311. build_newlib "-nano"
  312. # Task [III-4] /$HOST_NATIVE/gcc-final/
  313. build_gcc_final ""
  314. # Task [III-5] /$HOST_NATIVE/gcc-size-libstdcxx/
  315. build_gcc_final "-nano"
  316. else
  317. # Task [IV-2] /$HOST_MINGW/copy_libs/
  318. copy_linux_libs
  319. # Task [IV-3] /$HOST_MINGW/gcc-final/
  320. build_gcc_final ""
  321. fi
  322. # Task [III-6] /$HOST_NATIVE/gdb/
  323. # Task [IV-4] /$HOST_MINGW/gdb/
  324. build_gdb ""
  325. if [ "${WITH_GDB_PY2}" == "y" ]
  326. then
  327. # The Windows GDB needs some headers from the Python distribution.
  328. if [ "${TARGET_PLATFORM}" == "win32" ]
  329. then
  330. download_python2_win "${PYTHON2_WIN_VERSION}"
  331. fi
  332. build_gdb "-py"
  333. fi
  334. if [ "${WITH_GDB_PY3}" == "y" ]
  335. then
  336. if [ "${TARGET_PLATFORM}" == "win32" ]
  337. then
  338. download_python3_win "${PYTHON3_WIN_VERSION}"
  339. fi
  340. build_gdb "-py3"
  341. fi
  342. # Task [III-7] /$HOST_NATIVE/build-manual
  343. # Nope, the build process is different.
  344. # ---------------------------------------------------------------------------
  345. # Task [III-8] /$HOST_NATIVE/pretidy/
  346. # Task [IV-5] /$HOST_MINGW/pretidy/
  347. tidy_up
  348. # Task [III-9] /$HOST_NATIVE/strip_host_objects/
  349. # Task [IV-6] /$HOST_MINGW/strip_host_objects/
  350. if [ "${WITH_STRIP}" == "y" ]
  351. then
  352. strip_binaries
  353. fi
  354. # Must be done after gcc 2 make install, otherwise some wrong links
  355. # are created in libexec.
  356. # Must also be done after strip binaries, since strip after patchelf
  357. # damages the binaries.
  358. prepare_app_folder_libraries
  359. if [ "${WITH_STRIP}" == "y" -a "${TARGET_PLATFORM}" != "win32" ]
  360. then
  361. # Task [III-10] /$HOST_NATIVE/strip_target_objects/
  362. strip_libs
  363. fi
  364. final_tunings
  365. # Task [IV-7] /$HOST_MINGW/installation/
  366. # Nope, no setup.exe.
  367. # Task [III-11] /$HOST_NATIVE/package_tbz2/
  368. # Task [IV-8] /Package toolchain in zip format/
  369. check_binaries
  370. }
  371. # -----------------------------------------------------------------------------