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 if ! which wget > /dev/null; then
109 echo "Please install wget"
113 if [ USE_LINARO = 1 ]; then
114 if which gnutar > /dev/null; then
116 elif which gtar > /dev/null; then
118 else # hopefully it understands the GNU format
122 TAR=tar # use the system tar
125 ##############################################################################
127 # You probably don't have to touch anything after this
128 ##############################################################################
130 # Fetch a versioned file from a URL
132 if [ ! -e ${STAMPS}/$1.fetch ]; then
133 log "Downloading $1 sources..."
135 touch ${STAMPS}/$1.fetch
139 # Log a message out to the console
141 echo "******************************************************************"
143 echo "******************************************************************"
149 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
150 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
153 echo "archive type bz2"
157 echo "archive type gz"
161 echo "Unknown archive type of $1"
162 echo "leaving the decision to tar"
166 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
172 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
175 if [ ! -d $SUMMON_DIR ]; then
176 mkdir -p ${SUMMON_DIR}
181 mkdir -p ${STAMPS} ${SOURCES}
185 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
186 fetch ${GCC} ${GCCURL}
187 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
188 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
189 fetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
190 fetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
191 fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
195 if [ ! -e build ]; then
199 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
202 log "Configuring ${BINUTILS}"
203 ../${BINUTILS}/configure --target=${TARGET} \
212 log "Building ${BINUTILS}"
214 install ${BINUTILS} install
216 log "Cleaning up ${BINUTILS}"
217 touch ${STAMPS}/${BINUTILS}.build
218 rm -rf build/* ${BINUTILS}
221 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
224 mv ${GMP} ${GCCDIR}/gmp
226 mv ${MPFR} ${GCCDIR}/mpfr
228 mv ${MPC} ${GCCDIR}/mpc
230 log "Configuring ${GCC}-boot"
231 ../${GCCDIR}/configure --target=${TARGET} \
235 --enable-languages="c" \
245 log "Building ${GCC}-boot"
246 make ${MAKEFLAGS} all-gcc
247 install ${GCC}-boot install-gcc
249 log "Cleaning up ${GCC}-boot"
250 touch ${STAMPS}/${GCC}-boot.build
251 rm -rf build/* ${GCCDIR}
254 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
257 log "Configuring ${NEWLIB}"
258 # configuration options and flags partially
259 # from https://github.com/jsnyder/arm-eabi-toolchain
260 ../${NEWLIB}/configure --target=${TARGET} \
268 --disable-newlib-supplied-syscalls \
273 log "Building ${NEWLIB}"
274 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"
275 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
276 install ${NEWLIB} install
278 log "Cleaning up ${NEWLIB}"
279 touch ${STAMPS}/${NEWLIB}.build
280 rm -rf build/* ${NEWLIB}
283 # Yes, you need to build gcc again!
284 if [ ! -e ${STAMPS}/${GCC}.build ]; then
287 mv ${GMP} ${GCCDIR}/gmp
289 mv ${MPFR} ${GCCDIR}/mpfr
291 mv ${MPC} ${GCCDIR}/mpc
293 log "Configuring ${GCC}"
294 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
295 ../${GCCDIR}/configure --target=${TARGET} \
307 log "Building ${GCC}"
309 install ${GCC} install
311 log "Cleaning up ${GCC}"
312 touch ${STAMPS}/${GCC}.build
313 rm -rf build/* ${GCCDIR}
316 if [ ! -e ${STAMPS}/${GDB}.build ]; then
319 log "Configuring ${GDB}"
320 ../${GDB}/configure --target=${TARGET} \
326 log "Building ${GDB}"
328 install ${GDB} install
330 log "Cleaning up ${GDB}"
331 touch ${STAMPS}/${GDB}.build
332 rm -rf build/* ${GDB}
335 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
336 log "Removing work directory"