Advertisement
Guest User

Untitled

a guest
Jan 9th, 2014
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.77 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Prerequisites (debian): sudo apt-get install gcc make texinfo ed
  4. # seems you'll need termcap-dev for gdb (optional, commented out below)
  5. #
  6. # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45174
  7. # attachment 21387
  8. # http://gcc.gnu.org/bugzilla/attachment.cgi?id=21387
  9. #
  10. # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
  11. # Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
  12.  
  13. # Modified by Roel Verdult <roel@libnfc.org>, released as public domain.
  14. # - Removed manufacture (STM) specific libraries
  15. # - Added parameters for install location
  16. # - Optimized for building smallest firmware size
  17. # - Added windows (MinGW) build compatibility
  18.  
  19. # Modified by Donald Schlicht, released as public domain.
  20. # - Added optional third command argument for number of processors
  21. # - Modified source download so script can be run multiple times
  22. # - Modified linux GCCFLAGS to set CC variable correctly
  23. # - Modified gcc compile configuration under linux
  24.  
  25. # Modified by Matti Kariluoma <matti@kariluo.ma>, released as public domain.
  26. # - Added gcc-4.6.4, binutils-2.23.2, gdb-7.5
  27. # - Commented out --enable-multilib for both configure gcc
  28. # - - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45174#c26
  29. # - Changed enable-languages to "c" only for final gcc build
  30. # - Added call to contrib/download_prerequisites
  31. # - Added --disable-libssp or both configure gcc
  32. # - commented out gdb section
  33. # - moved INSTALL to a separate dir, changed name to 'work'
  34. # - changed SOURCE to 'src'
  35. # - changed DOWNLOAD out of home directory (wtf?), changed to 'pkg'
  36. # - modified checks on dirs at beginning
  37. # - added patch for gcc/config/arm/t-arm-elf
  38.  
  39. if [ $# -lt 2 ]; then
  40. echo "Public GNU GCC ARM toolchain building script";
  41. echo "usage: $0 <prefix> <arm-elf|arm-none-eabi> <optional number of cores>";
  42. exit 0;
  43. fi
  44.  
  45. # Version configuration
  46. BINUTILS=binutils-2.21.1 # 2.20.1 # 2.18
  47. GCC=gcc-4.6.4 # 4.5.1 # 4.2.2
  48. NEWLIB=newlib-1.18.0 # 1.16.0
  49. #GDB=gdb-7.5 # 7.1 # 6.8
  50.  
  51. DARWIN_OPT_PATH=/opt/local # Path in which MacPorts or Fink is installed
  52. MINGW_PATH=/mingw # Path in which MacPorts or Fink is installed
  53.  
  54. # Command-line parameters
  55. BASE=$1 # Base location for install
  56. TARGET=$2 # TARGET = arm-elf | arm-none-eabi
  57. PREFIX=${BASE}/${TARGET} # binary location of your toolchain (e.g. ${HOME})
  58. INSTALL=${BASE}/work # creation location
  59. DOWNLOAD=${BASE}/pkg # Location of downloaded tarballs
  60. SOURCE=${INSTALL}/src # location of uncompressed source files
  61. BUILD=${INSTALL}/build # location of compile files
  62.  
  63. # Added by DJS optional third parameter for cpu cores# Advanced options
  64. PARALLEL="" # PARALLEL = "-j 5" for 4 CPU's
  65. if [ $# -eq 3 ]; then
  66. PARALLEL="-j $3";
  67. fi
  68.  
  69. export PATH="${PREFIX}/bin:${PATH}"
  70.  
  71. # Modified by DJS to set linux GCCFLAGS
  72. case "$(uname)" in
  73. Linux)
  74. echo "Found Linux OS."
  75. GCCFLAGS= #"CC=gcc \
  76. #--with-system-zlib"
  77. NEWLIBFLAGS= # "CC=gcc"
  78. GDBFLAGS=
  79. ;;
  80. Darwin)
  81. echo "Found Darwin OS."
  82. GCCFLAGS="--with-gmp=${DARWIN_OPT_PATH} \
  83. --with-mpfr=${DARWIN_OPT_PATH} \
  84. -with-libiconv-prefix=${DARWIN_OPT_PATH}"
  85. NEWLIBFLAGS="--enable-newlib-reent-small \"
  86. GDBFLAGS="--disable-werror"
  87. ;;
  88. MINGW*)
  89. echo "Found Windows OS."
  90. GCCFLAGS="--with-gmp=${MINGW_PATH} \
  91. --with-mpfr=${MINGW_PATH} \
  92. -with-libiconv-prefix=${MINGW_PATH}"
  93. NEWLIBFLAGS="--enable-newlib-reent-small \"
  94. GDBFLAGS="--disable-werror"
  95. ;;
  96. *)
  97. echo "Found unknown OS. Aborting!"
  98. exit 1
  99. ;;
  100. esac
  101.  
  102. echo "Creating installation directories..."
  103. if [ ! -e ${BASE} ]; then
  104. mkdir ${BASE} || exit
  105. fi
  106. # Modified DJS delete all old installation directories
  107. if [ -e ${PREFIX} ]; then
  108. rm -r -f ${PREFIX} || exit
  109. fi
  110. if [ -e ${INSTALL} ]; then
  111. rm -r -f ${INSTALL} || exit
  112. fi
  113. mkdir ${PREFIX} || exit
  114. mkdir ${INSTALL} || exit
  115.  
  116. if [ ! -e ${SOURCE} ]; then
  117. mkdir ${SOURCE} || exit
  118. fi
  119.  
  120. if [ ! -e ${BUILD} ]; then
  121. mkdir ${BUILD} || exit
  122. fi
  123.  
  124. echo "Downloading sources...."
  125. # Modified by DJS, create a Downloads directory
  126. if [ ! -e ${DOWNLOAD} ]; then
  127. mkdir ${DOWNLOAD} || exit
  128. fi
  129. cd ${DOWNLOAD}
  130. # Modified by DJS, download tarballs to Download directory if not already there
  131. if [ ! -e ${BINUTILS}.tar.bz2 ]; then
  132. echo "Downloading binutils sources...";
  133. wget -c http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2 || exit
  134. fi
  135. if [ ! -e ${GCC}.tar.bz2 ]; then
  136. echo "Downloading gcc sources...";
  137. wget -c ftp://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2 || exit
  138. fi
  139. if [ ! -e ${NEWLIB}.tar.gz ]; then
  140. echo "Downloading newlib sources...";
  141. wget -c ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz || exit
  142. fi
  143. #~ if [ ! -e ${GDB}.tar.bz2 ]; then
  144. #~ echo "Downloading gdb sources...";
  145. #~ wget -c ftp://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2;
  146. #~ fi
  147.  
  148. cd ${SOURCE}
  149. echo "******************************************************************"
  150. echo "* Unpacking ${BINUTILS}"
  151. echo "******************************************************************"
  152. tar xfvj ${DOWNLOAD}/${BINUTILS}.tar.bz2 > ${INSTALL}/${BINUTILS}_tar.log || exit
  153. cd ${BUILD}
  154. mkdir ${BINUTILS} || exit
  155. cd ${BINUTILS} # in ${BUILD}
  156. echo "******************************************************************"
  157. echo "* Configuring ${BINUTILS}"
  158. echo "******************************************************************"
  159. ${SOURCE}/${BINUTILS}/configure --target=${TARGET} \
  160. --prefix=${PREFIX} \
  161. --enable-interwork \
  162. --enable-multilib \
  163. --with-gnu-as \
  164. --with-gnu-ld \
  165. --disable-werror \
  166. --disable-nls > ${INSTALL}/${BINUTILS}_configure.log || exit
  167. echo "******************************************************************"
  168. echo "* Building ${BINUTILS}"
  169. echo "******************************************************************"
  170. make MAKEINFO=makeinfo ${PARALLEL} > ${INSTALL}/${BINUTILS}_make.log || exit
  171. echo "******************************************************************"
  172. echo "* Installing ${BINUTILS}"
  173. echo "******************************************************************"
  174. make install > ${INSTALL}/${BINUTILS}_install.log || exit
  175.  
  176. cd ${SOURCE}
  177. echo "******************************************************************"
  178. echo "* Unpacking ${GCC}"
  179. echo "******************************************************************"
  180. tar xfvj ${DOWNLOAD}/${GCC}.tar.bz2 > ${INSTALL}/${GCC}-boot_tar.log || exit
  181. echo "******************************************************************"
  182. echo "* Downloading prerequisites for ${GCC}"
  183. echo "******************************************************************"
  184. cd ${SOURCE}/${GCC}
  185. contrib/download_prerequisites > ${INSTALL}/${GCC}-boot_preqs.log || exit
  186. if [ "$TARGET" == "arm-elf" ]; then
  187. echo "******************************************************************"
  188. echo "* Patching ${GCC}"
  189. echo "******************************************************************"
  190. ed ${SOURCE}/${GCC}/gcc/config/arm/t-arm-elf << EOF > ${INSTALL}/${GCC}-boot_patch.log
  191. /MULTILIB_OPTIONS/s/^M/# M/
  192. /MULTILIB_DIRNAMES/s/^M/# M/
  193. /mno-thumb-interwork/s/^# //
  194. /normal interwork/s/^# //
  195. wq
  196. EOF
  197. [ $? -eq 0 ] || exit
  198. fi
  199. cd ${BUILD}
  200. mkdir ${GCC}-boot || exit
  201. cd ${GCC}-boot
  202. echo "******************************************************************"
  203. echo "* Configuring ${GCC}-boot"
  204. echo "******************************************************************"
  205. ${SOURCE}/${GCC}/configure --target=${TARGET} \
  206. --prefix=${PREFIX} \
  207. --enable-interwork \
  208. --enable-languages="c" \
  209. --with-newlib \
  210. --without-headers \
  211. --disable-shared \
  212. --with-gnu-as \
  213. --with-gnu-ld \
  214. --disable-nls \
  215. --disable-libssp \
  216. ${GCCFLAGS} > ${INSTALL}/${GCC}-boot_configure.log || exit
  217. # --enable-multilib
  218. echo "******************************************************************"
  219. echo "* Building ${GCC}-boot"
  220. echo "******************************************************************"
  221. make ${PARALLEL} > ${INSTALL}/${GCC}-boot_make.log || exit
  222. echo "******************************************************************"
  223. echo "* Installing ${GCC}-boot"
  224. echo "******************************************************************"
  225. make install > ${INSTALL}/${GCC}-boot_install.log || exit
  226.  
  227. cd ${SOURCE}
  228. echo "******************************************************************"
  229. echo "* Unpacking ${NEWLIB}"
  230. echo "******************************************************************"
  231. tar xfvz ${DOWNLOAD}/${NEWLIB}.tar.gz > ${INSTALL}/${NEWLIB}_tar.log || exit
  232. cd ${BUILD}
  233. mkdir ${NEWLIB} || exit
  234. cd ${NEWLIB}
  235. echo "******************************************************************"
  236. echo "* Configuring ${NEWLIB}"
  237. echo "******************************************************************"
  238. ${SOURCE}/${NEWLIB}/configure --target=${TARGET} \
  239. --prefix=${PREFIX} \
  240. --enable-interwork \
  241. --enable-multilib \
  242. --with-gnu-as \
  243. --with-gnu-ld \
  244. --disable-nls \
  245. --enable-target-optspace \
  246. --enable-newlib-io-c99-formats \
  247. --enable-newlib-io-long-long \
  248. --disable-newlib-multithread \
  249. --disable-newlib-supplied-syscalls \
  250. CFLAGS="-DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY" \
  251. ${NEWLIBFLAGS} > ${INSTALL}/${NEWLIB}_configure.log || exit
  252. echo "******************************************************************"
  253. echo "* Building ${NEWLIB}"
  254. echo "******************************************************************"
  255. make ${PARALLEL} > ${INSTALL}/${NEWLIB}_make.log || exit
  256. echo "******************************************************************"
  257. echo "* Installing ${NEWLIB}"
  258. echo "******************************************************************"
  259. make install > ${INSTALL}/${NEWLIB}_install.log || exit
  260.  
  261. # Yes, you need to build gcc again!
  262. cd ${SOURCE}
  263. echo "******************************************************************"
  264. echo "* Unpacking ${GCC}"
  265. echo "******************************************************************"
  266. tar xfvj ${DOWNLOAD}/${GCC}.tar.bz2 > ${INSTALL}/${GCC}-final_tar.log || exit
  267. cd ${SOURCE}/${GCC}
  268. if [ "$TARGET" == "arm-elf" ]; then
  269. echo "******************************************************************"
  270. echo "* Patching ${GCC}"
  271. echo "******************************************************************"
  272. ed ${SOURCE}/${GCC}/gcc/config/arm/t-arm-elf << EOF > ${INSTALL}/${GCC}-final_patch.log
  273. /MULTILIB_OPTIONS/s/^M/# M/
  274. /MULTILIB_DIRNAMES/s/^M/# M/
  275. /mno-thumb-interwork/s/^# //
  276. /normal interwork/s/^# //
  277. wq
  278. EOF
  279. [ $? -eq 0 ] || exit
  280. fi
  281. cd ${BUILD}
  282. mkdir ${GCC} || exit
  283. cd ${GCC}
  284. echo "******************************************************************"
  285. echo "* Configuring ${GCC}"
  286. echo "******************************************************************"
  287. ${SOURCE}/${GCC}/configure --target=${TARGET} \
  288. --prefix=${PREFIX} \
  289. --enable-interwork \
  290. --enable-languages="c" \
  291. --with-newlib \
  292. --disable-shared \
  293. --with-gnu-as \
  294. --with-gnu-ld \
  295. --disable-nls \
  296. --disable-libssp \
  297. ${GCCFLAGS} > ${INSTALL}/${GCC}-final_configure.log || exit
  298. # --enable-multilib \
  299. # --enable-languages="c,c++,objc" \
  300.  
  301. echo "******************************************************************"
  302. echo "* Building ${GCC}"
  303. echo "******************************************************************"
  304. make ${PARALLEL} > ${INSTALL}/${GCC}-final_make.log || exit
  305. echo "******************************************************************"
  306. echo "* Installing ${GCC}"
  307. echo "******************************************************************"
  308. make install > ${INSTALL}/${GCC}-final_install.log || exit
  309.  
  310. #~ cd ${SOURCE}
  311. #~ echo "******************************************************************"
  312. #~ echo "* Unpacking ${GDB}"
  313. #~ echo "******************************************************************"
  314. #~ tar xfvj ${DOWNLOAD}/${GDB}.tar.bz2 > ${INSTALL}/${GDB}_tar.log || exit
  315. #~ cd ${BUILD}
  316. #~ mkdir ${GDB} || exit
  317. #~ cd ${GDB}
  318. #~ echo "******************************************************************"
  319. #~ echo "* Configuring ${GDB}"
  320. #~ echo "******************************************************************"
  321. #~ ${SOURCE}/${GDB}/configure --target=${TARGET} \
  322. #~ --prefix=${PREFIX} \
  323. #~ --enable-interwork \
  324. #~ --enable-multilib \
  325. #~ --with-libexpat \
  326. #~ --disable-nls \
  327. #~ ${GDBFLAGS} > ${INSTALL}/${GDB}_configure.log || exit
  328. #~ echo "******************************************************************"
  329. #~ echo "* Building ${GDB}"
  330. #~ echo "******************************************************************"
  331. #~ make ${PARALLEL} > ${INSTALL}/${GDB}_make.log || exit
  332. #~ echo "******************************************************************"
  333. #~ echo "* Installing ${GDB}"
  334. #~ echo "******************************************************************"
  335. #~ make install > ${INSTALL}/${GDB}_install.log || exit
  336.  
  337. echo "******************************************************************"
  338. echo "* Finished"
  339. echo "******************************************************************"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement