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 # Set to 1 to enable building of OpenOCD
30 # Set to 1 to build libstm32 provided by ST
32 # Set to 1 to build libopenstm32 an open source library for stm32
34 # Make the gcc default to Cortex-M3
35 DEFAULT_TO_CORTEX_M3=1
37 ##############################################################################
38 # Version and download url settings section
39 ##############################################################################
40 if [ ${USE_LINARO} = 0 ] ; then
43 if [ ${USE_CPP} = 0 ]; then
44 GCC=gcc-core-${GCCVERSION}
45 GCCDIR=gcc-${GCCVERSION}
50 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCCDIR}/${GCC}.tar.bz2
53 GCCRELEASE=4.6-2011.07
54 GCCVERSION=4.6-2011.07-0
55 GCC=gcc-linaro-${GCCRELEASE}
56 GCCDIR=gcc-linaro-${GCCVERSION}
57 GCCURL=http://launchpad.net/gcc-linaro/4.6/${GCCRELEASE}/+download/gcc-linaro-${GCCRELEASE}.tar.bz2
60 BINUTILS=binutils-2.21
72 ##############################################################################
74 ##############################################################################
76 if which getconf > /dev/null; then
77 CPUS=$(getconf _NPROCESSORS_ONLN)
81 PARALLEL=-j$((CPUS + 1))
82 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
87 if [ ${DEFAULT_TO_CORTEX_M3} = 0 ] ; then
90 # To default to the Cortex-M3:
91 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
94 # Pull in the local configuration, if any
95 if [ -f local.sh ]; then
102 if [ ${QUIET} != 0 ]; then
104 MAKEFLAGS="${MAKEFLAGS} -s"
107 export PATH="${PREFIX}/bin:${PATH}"
109 SUMMON_DIR=${WORKDIR}
110 SOURCES=${SUMMON_DIR}/sources
111 STAMPS=${SUMMON_DIR}/stamps
114 ##############################################################################
116 ##############################################################################
119 ##############################################################################
120 # OS and Tooldetection section
121 # Detects which tools and flags to use
122 ##############################################################################
126 echo "Found Linux OS."
129 echo "Found Darwin OS."
131 # darwin dependencies
134 echo "Installing dependencies ..."
135 if ! which brew > /dev/null; then
136 echo "Homebrew not installed."
138 brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
143 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
144 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
147 echo "Found CygWin that means Windows most likely."
150 echo "Found unknown OS. Aborting!"
155 ##############################################################################
157 # You probably don't have to touch anything after this
158 ##############################################################################
160 # Fetch a versioned file from a URL
162 if [ ! -e ${STAMPS}/$1.fetch ]; then
163 log "Downloading $1 sources..."
165 touch ${STAMPS}/$1.fetch
169 # Log a message out to the console
171 echo "******************************************************************"
173 echo "******************************************************************"
179 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
180 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
183 echo "archive type bz2"
187 echo "archive type gz"
191 echo "Unknown archive type of $1"
192 echo "leaving the decision to tar"
196 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
202 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
205 if [ ! -d $SUMMON_DIR ]; then
206 mkdir -p ${SUMMON_DIR}
211 mkdir -p ${STAMPS} ${SOURCES}
215 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
216 fetch ${GCC} ${GCCURL}
217 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
218 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
219 fetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
220 fetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
221 fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
223 if [ ${OOCD_EN} != 0 ]; then
224 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
225 log "Cloning OpenOCD sources..."
226 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
230 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
231 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
232 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
233 rm -rf openocd-${OOCD}
237 if [ ${LIBSTM32_EN} != 0 ]; then
238 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
239 log "Cloning libcmsis sources..."
240 git clone git://git.open-bldc.org/libcmsis.git
242 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
243 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
248 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
249 log "Cloning libstm32 sources..."
250 git clone git://git.open-bldc.org/libstm32.git
252 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
253 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
258 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
259 log "Cloning libstm32usb sources..."
260 git clone git://git.open-bldc.org/libstm32usb.git
262 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
263 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
269 if [ ${LIBOPENSTM32_EN} != 0 ]; then
270 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
271 log "Cloning libopenstm32 sources..."
272 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
274 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
275 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
283 if [ ! -e build ]; then
287 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
290 log "Configuring ${BINUTILS}"
291 ../${BINUTILS}/configure --target=${TARGET} \
300 log "Building ${BINUTILS}"
302 install ${BINUTILS} install
304 log "Cleaning up ${BINUTILS}"
305 touch ${STAMPS}/${BINUTILS}.build
306 rm -rf build/* ${BINUTILS}
309 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
312 mv ${GMP} ${GCCDIR}/gmp
314 mv ${MPFR} ${GCCDIR}/mpfr
316 mv ${MPC} ${GCCDIR}/mpc
318 log "Configuring ${GCC}-boot"
319 ../${GCCDIR}/configure --target=${TARGET} \
323 --enable-languages="c" \
333 log "Building ${GCC}-boot"
334 make ${MAKEFLAGS} all-gcc
335 install ${GCC}-boot install-gcc
337 log "Cleaning up ${GCC}-boot"
338 touch ${STAMPS}/${GCC}-boot.build
339 rm -rf build/* ${GCCDIR}
342 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
345 log "Configuring ${NEWLIB}"
346 # configuration options and flags partially
347 # from https://github.com/jsnyder/arm-eabi-toolchain
348 ../${NEWLIB}/configure --target=${TARGET} \
356 --disable-newlib-supplied-syscalls \
361 log "Building ${NEWLIB}"
362 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"
363 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
364 install ${NEWLIB} install
366 log "Cleaning up ${NEWLIB}"
367 touch ${STAMPS}/${NEWLIB}.build
368 rm -rf build/* ${NEWLIB}
371 # Yes, you need to build gcc again!
372 if [ ! -e ${STAMPS}/${GCC}.build ]; then
375 mv ${GMP} ${GCCDIR}/gmp
377 mv ${MPFR} ${GCCDIR}/mpfr
379 mv ${MPC} ${GCCDIR}/mpc
381 log "Configuring ${GCC}"
382 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
383 ../${GCCDIR}/configure --target=${TARGET} \
395 log "Building ${GCC}"
397 install ${GCC} install
399 log "Cleaning up ${GCC}"
400 touch ${STAMPS}/${GCC}.build
401 rm -rf build/* ${GCCDIR}
404 if [ ! -e ${STAMPS}/${GDB}.build ]; then
407 log "Configuring ${GDB}"
408 ../${GDB}/configure --target=${TARGET} \
414 log "Building ${GDB}"
416 install ${GDB} install
418 log "Cleaning up ${GDB}"
419 touch ${STAMPS}/${GDB}.build
420 rm -rf build/* ${GDB}
423 if [ ${OOCD_EN} != 0 ]; then
424 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
425 unpack openocd-${OOCD}
427 log "Configuring openocd-${OOCD}"
428 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
429 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
430 ../openocd-${OOCD}/configure --enable-maintainer-mode \
434 --enable-ft2232_libftdi \
435 --enable-usb_blaster_libftdi \
436 --enable-amtjtagaccel \
439 --enable-at91rm9200 \
441 --enable-presto_libftdi \
446 --enable-arm-jtag-ew \
448 log "Building openocd-${OOCD}"
450 install openocd-${OOCD} install
452 log "Cleaning up openocd-${OOCD}"
453 touch ${STAMPS}/openocd-${OOCD}.build
454 rm -rf build/* ${OOCD}
458 if [ ${LIBSTM32_EN} != 0 ]; then
459 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
460 unpack libcmsis-${LIBCMSIS}
461 cd libcmsis-${LIBCMSIS}
462 log "Building libcmsis-${LIBCMSIS}"
463 make arch_prefix=${TARGET} prefix=${PREFIX}
464 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
466 log "Cleaning up libcmsis-${LIBCMSIS}"
467 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
468 rm -rf libcmsis-${LIBCMSIS}
471 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
472 unpack libstm32-${LIBSTM32}
473 cd libstm32-${LIBSTM32}
474 log "Building libstm32-${LIBSTM32}"
475 make arch_prefix=${TARGET} prefix=${PREFIX}
476 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
478 log "Cleaning up libstm32-${LIBSTM32}"
479 touch ${STAMPS}/libstm32-${LIBSTM32}.build
480 rm -rf libstm32-${LIBSTM32}
483 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
484 unpack libstm32usb-${LIBSTM32USB}
485 cd libstm32usb-${LIBSTM32USB}
486 log "Building libstm32usb-${LIBSTM32USB}"
487 make arch_prefix=${TARGET} prefix=${PREFIX}
488 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
490 log "Cleaning up libstm32usb-${LIBSTM32USB}"
491 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
492 rm -rf libstm32usb-${LIBSTM32USB}
496 if [ $LIBOPENSTM32_EN != 0 ]; then
497 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
498 unpack libopenstm32-${LIBOPENSTM32}
499 cd libopenstm32-${LIBOPENSTM32}
500 log "Building libopenstm32-${LIBOPENSTM32}"
501 make PREFIX=${TARGET} DESTDIR=${PREFIX}
502 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
504 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
505 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
506 rm -rf libopenstm32-${LIBOPENSTM32}
510 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
511 log "Removing work directory"