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 ##############################################################################
105 ##############################################################################
108 ##############################################################################
109 # OS and Tooldetection section
110 # Detects which tools and flags to use
111 ##############################################################################
115 echo "Found Linux OS."
118 echo "Found Darwin OS."
120 # darwin dependencies
123 echo "Installing dependencies ..."
124 if ! which brew > /dev/null; then
125 echo "Homebrew not installed."
127 brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
133 echo "Found CygWin that means Windows most likely."
136 echo "Found unknown OS. Aborting!"
141 ##############################################################################
143 # You probably don't have to touch anything after this
144 ##############################################################################
146 # Fetch a versioned file from a URL
148 if [ ! -e ${STAMPS}/$1.fetch ]; then
149 log "Downloading $1 sources..."
151 touch ${STAMPS}/$1.fetch
155 # Log a message out to the console
157 echo "******************************************************************"
159 echo "******************************************************************"
165 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
166 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
169 echo "archive type bz2"
173 echo "archive type gz"
177 echo "Unknown archive type of $1"
178 echo "leaving the decision to tar"
182 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
188 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
191 if [ ! -d $SUMMON_DIR ]; then
192 mkdir -p ${SUMMON_DIR}
197 mkdir -p ${STAMPS} ${SOURCES}
201 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
202 fetch ${GCC} ${GCCURL}
203 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
204 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
205 fetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
206 fetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
207 fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
211 if [ ! -e build ]; then
215 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
218 log "Configuring ${BINUTILS}"
219 ../${BINUTILS}/configure --target=${TARGET} \
228 log "Building ${BINUTILS}"
230 install ${BINUTILS} install
232 log "Cleaning up ${BINUTILS}"
233 touch ${STAMPS}/${BINUTILS}.build
234 rm -rf build/* ${BINUTILS}
237 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
240 mv ${GMP} ${GCCDIR}/gmp
242 mv ${MPFR} ${GCCDIR}/mpfr
244 mv ${MPC} ${GCCDIR}/mpc
246 log "Configuring ${GCC}-boot"
247 ../${GCCDIR}/configure --target=${TARGET} \
251 --enable-languages="c" \
261 log "Building ${GCC}-boot"
262 make ${MAKEFLAGS} all-gcc
263 install ${GCC}-boot install-gcc
265 log "Cleaning up ${GCC}-boot"
266 touch ${STAMPS}/${GCC}-boot.build
267 rm -rf build/* ${GCCDIR}
270 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
273 log "Configuring ${NEWLIB}"
274 # configuration options and flags partially
275 # from https://github.com/jsnyder/arm-eabi-toolchain
276 ../${NEWLIB}/configure --target=${TARGET} \
284 --disable-newlib-supplied-syscalls \
289 log "Building ${NEWLIB}"
290 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"
291 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
292 install ${NEWLIB} install
294 log "Cleaning up ${NEWLIB}"
295 touch ${STAMPS}/${NEWLIB}.build
296 rm -rf build/* ${NEWLIB}
299 # Yes, you need to build gcc again!
300 if [ ! -e ${STAMPS}/${GCC}.build ]; then
303 mv ${GMP} ${GCCDIR}/gmp
305 mv ${MPFR} ${GCCDIR}/mpfr
307 mv ${MPC} ${GCCDIR}/mpc
309 log "Configuring ${GCC}"
310 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
311 ../${GCCDIR}/configure --target=${TARGET} \
323 log "Building ${GCC}"
325 install ${GCC} install
327 log "Cleaning up ${GCC}"
328 touch ${STAMPS}/${GCC}.build
329 rm -rf build/* ${GCCDIR}
332 if [ ! -e ${STAMPS}/${GDB}.build ]; then
335 log "Configuring ${GDB}"
336 ../${GDB}/configure --target=${TARGET} \
342 log "Building ${GDB}"
344 install ${GDB} install
346 log "Cleaning up ${GDB}"
347 touch ${STAMPS}/${GDB}.build
348 rm -rf build/* ${GDB}
351 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
352 log "Removing work directory"