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 ##############################################################################
63 ##############################################################################
65 if which getconf > /dev/null; then
66 CPUS=$(getconf _NPROCESSORS_ONLN)
70 PARALLEL=-j$((CPUS + 1))
71 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
76 if [ ${DEFAULT_TO_CORTEX_M3} = 0 ] ; then
79 # To default to the Cortex-M3:
80 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
83 # Pull in the local configuration, if any
84 if [ -f local.sh ]; then
91 if [ ${QUIET} != 0 ]; then
93 MAKEFLAGS="${MAKEFLAGS} -s"
96 export PATH="${PREFIX}/bin:${PATH}"
99 SOURCES=${SUMMON_DIR}/sources
100 STAMPS=${SUMMON_DIR}/stamps
103 ##############################################################################
104 # OS and Tooldetection section
105 # Detects which tools and flags to use
106 ##############################################################################
108 # normalized fetching with whatever we can find
109 if which fetch > /dev/null; then
111 elif which wget > /dev/null; then
113 elif which curl > /dev/null; then
116 FETCHCMD=ftp # the only HTTP client on some BSD
119 if [ USE_LINARO = 1 ]; then
120 if which gnutar > /dev/null; then
122 elif which gtar > /dev/null; then
124 else # hopefully it understands the GNU format
128 TAR=tar # use the system tar
131 ##############################################################################
133 # You probably don't have to touch anything after this
134 ##############################################################################
136 # Fetch a versioned file from a URL
138 if [ ! -e ${STAMPS}/$1.fetch ]; then
139 log "Downloading $1 sources..."
141 touch ${STAMPS}/$1.fetch
145 # Log a message out to the console
147 echo "******************************************************************"
149 echo "******************************************************************"
155 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
156 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
159 echo "archive type bz2"
163 echo "archive type gz"
167 echo "Unknown archive type of $1"
168 echo "leaving the decision to tar"
172 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
178 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
181 if [ ! -d $SUMMON_DIR ]; then
182 mkdir -p ${SUMMON_DIR}
187 mkdir -p ${STAMPS} ${SOURCES}
191 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
192 fetch ${GCC} ${GCCURL}
193 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
194 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
195 fetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
196 fetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
197 fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
201 if [ ! -e build ]; then
205 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
208 log "Configuring ${BINUTILS}"
209 ../${BINUTILS}/configure --target=${TARGET} \
218 log "Building ${BINUTILS}"
220 doinstall ${BINUTILS} install
222 log "Cleaning up ${BINUTILS}"
223 touch ${STAMPS}/${BINUTILS}.build
224 rm -rf build/* ${BINUTILS}
227 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
230 mv ${GMP} ${GCCDIR}/gmp
232 mv ${MPFR} ${GCCDIR}/mpfr
234 mv ${MPC} ${GCCDIR}/mpc
236 log "Configuring ${GCC}-boot"
237 ../${GCCDIR}/configure --target=${TARGET} \
241 --enable-languages="c" \
251 log "Building ${GCC}-boot"
252 make ${MAKEFLAGS} all-gcc
253 doinstall ${GCC}-boot install-gcc
255 log "Cleaning up ${GCC}-boot"
256 touch ${STAMPS}/${GCC}-boot.build
257 rm -rf build/* ${GCCDIR}
260 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
263 log "Configuring ${NEWLIB}"
264 # configuration options and flags partially
265 # from https://github.com/jsnyder/arm-eabi-toolchain
266 ../${NEWLIB}/configure --target=${TARGET} \
274 --disable-newlib-supplied-syscalls \
279 log "Building ${NEWLIB}"
280 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"
281 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
282 doinstall ${NEWLIB} install
284 log "Cleaning up ${NEWLIB}"
285 touch ${STAMPS}/${NEWLIB}.build
286 rm -rf build/* ${NEWLIB}
289 # Yes, you need to build gcc again!
290 if [ ! -e ${STAMPS}/${GCC}.build ]; then
293 mv ${GMP} ${GCCDIR}/gmp
295 mv ${MPFR} ${GCCDIR}/mpfr
297 mv ${MPC} ${GCCDIR}/mpc
299 log "Configuring ${GCC}"
300 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
301 ../${GCCDIR}/configure --target=${TARGET} \
313 log "Building ${GCC}"
315 doinstall ${GCC} install
317 log "Cleaning up ${GCC}"
318 touch ${STAMPS}/${GCC}.build
319 rm -rf build/* ${GCCDIR}
322 if [ ! -e ${STAMPS}/${GDB}.build ]; then
325 log "Configuring ${GDB}"
326 ../${GDB}/configure --target=${TARGET} \
332 log "Building ${GDB}"
334 doinstall ${GDB} install
336 log "Cleaning up ${GDB}"
337 touch ${STAMPS}/${GDB}.build
338 rm -rf build/* ${GDB}
341 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
342 log "Removing work directory"