2 # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
3 # Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
5 # adapted for r0ket <http://r0ket.badge.events.ccc.de> development by
6 # Matthias Rampke <matthias@rampke.de>
7 # requires Homebrew <https://mxcl.github.com/homebrew>
9 # Stop if any command fails
12 ##############################################################################
14 # You probably want to customize those
15 ##############################################################################
16 TARGET=arm-none-eabi # Or: TARGET=arm-elf
17 [ -z $PREFIX ] && PREFIX=${HOME}/arm # Install location of your final toolchain
18 [ -z $WORKDIR ] && WORKDIR=$PREFIX/work #temporary directory
19 PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
20 # Set to 'sudo' if you need superuser privileges while installing
22 # Set to 1 to be quieter while running
24 # Set to 1 to use linaro gcc instead of the FSF gcc
26 # Set to 1 to enable C++
28 # Make the gcc default to Cortex-M3
29 DEFAULT_TO_CORTEX_M3=1
31 ##############################################################################
32 # Version and download url settings section
33 ##############################################################################
34 if [ ${USE_LINARO} = 0 ] ; then
37 if [ ${USE_CPP} = 0 ]; then
38 GCC=gcc-core-${GCCVERSION}
39 GCCDIR=gcc-${GCCVERSION}
44 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCCDIR}/${GCC}.tar.bz2
47 GCCRELEASE=4.6-2011.07
48 GCCVERSION=4.6-2011.07-0
49 GCC=gcc-linaro-${GCCRELEASE}
50 GCCDIR=gcc-linaro-${GCCVERSION}
51 GCCURL=http://launchpad.net/gcc-linaro/4.6/${GCCRELEASE}/+download/gcc-linaro-${GCCRELEASE}.tar.bz2
54 BINUTILS=binutils-2.21
61 SHA1SUMS="ef93235588eb443e4c4a77f229a8d131bccaecc6 binutils-2.21.tar.bz2
62 8bf66f7a71534ba564563a0ba0b2517aead8ac30 gcc-4.6.1.tar.bz2
63 9b766705f051ffb7321de58f247688b0ae661b98 gcc-core-4.6.1.tar.bz2
64 828d99a63e0578879150f5681d234763cff69313 gcc-linaro-4.6-2011.07.tar.bz2
65 fefd90275d6decdca00c5c29c533e2ef3d439664 gdb-7.3.tar.bz2
66 2968220e1988eabb61f921d11e5d2db5431e0a35 gmp-5.0.2.tar.bz2
67 229722d553030734d49731844abfef7617b64f1a mpc-0.9.tar.gz
68 fbf402fc196724ae60ef01eb6ca8490b1ea4db69 mpfr-3.0.1.tar.bz2
69 b2269d30ce7b93b7c714b90ef2f40221c2df0fcd newlib-1.19.0.tar.gz"
71 ##############################################################################
73 ##############################################################################
75 if which getconf > /dev/null && getconf _NPROCESSORS_ONLN > /dev/null; then
76 CPUS=$(getconf _NPROCESSORS_ONLN)
77 elif which sysctl > /dev/null && sysctl hw.ncpu > /dev/null; then
78 CPUS=$(sysctl hw.ncpu | sed -E -e 's/^hw\.ncpu(: | = )//')
82 PARALLEL=-j$((CPUS + 1))
83 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
88 if [ ${DEFAULT_TO_CORTEX_M3} = 0 ] ; then
91 # To default to the Cortex-M3:
92 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
95 # Pull in the local configuration, if any
96 if [ -f local.sh ]; then
100 MAKEFLAGS=${PARALLEL} ${MAKESILENT}
104 if [ ${QUIET} != 0 ]; then
109 export PATH="${PREFIX}/bin:${PATH}"
111 SUMMON_DIR=${WORKDIR}
112 SOURCES=${SUMMON_DIR}/sources
113 STAMPS=${SUMMON_DIR}/stamps
116 ##############################################################################
117 # OS and Tooldetection section
118 # Detects which tools and flags to use
119 ##############################################################################
121 # normalized fetching with whatever we can find
122 if which fetch > /dev/null; then
124 elif which wget > /dev/null; then
126 elif which curl > /dev/null; then
127 FETCHCMD="curl -C - -O -L"
129 FETCHCMD=ftp # the only HTTP client on some BSD
132 if [ USE_LINARO = 1 ]; then
133 if which gnutar > /dev/null; then
135 elif which gtar > /dev/null; then
137 else # hopefully it understands the GNU format
141 TAR=tar # use the system tar
144 ##############################################################################
146 # You probably don't have to touch anything after this
147 ##############################################################################
149 # Fetch a versioned file from a URL
151 if [ ! -e ${STAMPS}/$1.fetch ]; then
152 log "Downloading $1 sources..."
154 touch ${STAMPS}/$1.fetch
158 # Log a message out to the console
160 echo "******************************************************************"
162 echo "******************************************************************"
168 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
169 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
172 echo "archive type bz2"
176 echo "archive type gz"
180 echo "Unknown archive type of $1"
181 echo "leaving the decision to tar"
185 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
191 ${SUDO} make ${MAKESILENT} $2 $3 $4 $5 $6 $7 $8
194 if [ ! -d $SUMMON_DIR ]; then
195 mkdir -p ${SUMMON_DIR}
200 mkdir -p ${STAMPS} ${SOURCES}
204 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
205 fetch ${GCC} ${GCCURL}
206 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
207 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
208 fetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
209 fetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
210 fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
212 if which sha1sum > /dev/null; then
213 for f in ${BINUTILS} ${GCC} ${NEWLIB} ${GDB} ${GMP} ${MPFR} ${MPC}; do
214 ( echo "$SHA1SUMS" | grep -F $f | sha1sum -c - ) || ( log 'ERROR: Checksum fail!'; exit 1 )
217 log "WARING: skipping checksum checks due to missing sha1sum"
222 if [ ! -e build ]; then
226 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
229 log "Configuring ${BINUTILS}"
230 ../${BINUTILS}/configure --target=${TARGET} \
239 log "Building ${BINUTILS}"
241 doinstall ${BINUTILS} install
243 log "Cleaning up ${BINUTILS}"
244 touch ${STAMPS}/${BINUTILS}.build
245 rm -rf build/* ${BINUTILS}
248 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
251 mv ${GMP} ${GCCDIR}/gmp
253 mv ${MPFR} ${GCCDIR}/mpfr
255 mv ${MPC} ${GCCDIR}/mpc
257 log "Configuring ${GCC}-boot"
258 ../${GCCDIR}/configure --target=${TARGET} \
262 --enable-languages="c" \
272 log "Building ${GCC}-boot"
273 make ${MAKEFLAGS} all-gcc
274 doinstall ${GCC}-boot install-gcc
276 log "Cleaning up ${GCC}-boot"
277 touch ${STAMPS}/${GCC}-boot.build
278 rm -rf build/* ${GCCDIR}
281 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
284 log "Configuring ${NEWLIB}"
285 # configuration options and flags partially
286 # from https://github.com/jsnyder/arm-eabi-toolchain
287 ../${NEWLIB}/configure --target=${TARGET} \
295 --disable-newlib-supplied-syscalls \
300 log "Building ${NEWLIB}"
301 NEWLIB_FLAGS="-ffunction-sections -fdata-sections -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -Os -fomit-frame-pointer -fno-unroll-loops -D__BUFSIZ__=256 -mabi=aapcs"
302 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
303 doinstall ${NEWLIB} install
305 log "Cleaning up ${NEWLIB}"
306 touch ${STAMPS}/${NEWLIB}.build
307 rm -rf build/* ${NEWLIB}
310 # Yes, you need to build gcc again!
311 if [ ! -e ${STAMPS}/${GCC}.build ]; then
314 mv ${GMP} ${GCCDIR}/gmp
316 mv ${MPFR} ${GCCDIR}/mpfr
318 mv ${MPC} ${GCCDIR}/mpc
320 log "Configuring ${GCC}"
321 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
322 ../${GCCDIR}/configure --target=${TARGET} \
334 log "Building ${GCC}"
336 doinstall ${GCC} install
338 log "Cleaning up ${GCC}"
339 touch ${STAMPS}/${GCC}.build
340 rm -rf build/* ${GCCDIR}
343 if [ ! -e ${STAMPS}/${GDB}.build ]; then
346 log "Configuring ${GDB}"
347 ../${GDB}/configure --target=${TARGET} \
353 log "Building ${GDB}"
355 doinstall ${GDB} install
357 log "Cleaning up ${GDB}"
358 touch ${STAMPS}/${GDB}.build
359 rm -rf build/* ${GDB}
362 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
363 log "Removing work directory"