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
69 ##############################################################################
71 ##############################################################################
73 if which getconf > /dev/null; then
74 CPUS=$(getconf _NPROCESSORS_ONLN)
78 PARALLEL=-j$((CPUS + 1))
79 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
84 if [ ${DEFAULT_TO_CORTEX_M3} = 0 ] ; then
87 # To default to the Cortex-M3:
88 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
91 # Pull in the local configuration, if any
92 if [ -f local.sh ]; then
99 if [ ${QUIET} != 0 ]; then
101 MAKEFLAGS="${MAKEFLAGS} -s"
104 export PATH="${PREFIX}/bin:${PATH}"
106 SUMMON_DIR=${WORKDIR}
107 SOURCES=${SUMMON_DIR}/sources
108 STAMPS=${SUMMON_DIR}/stamps
111 ##############################################################################
113 ##############################################################################
116 ##############################################################################
117 # OS and Tooldetection section
118 # Detects which tools and flags to use
119 ##############################################################################
123 echo "Found Linux OS."
126 echo "Found Darwin OS."
128 # darwin dependencies
129 DARWINDEPS="wget mpfr libmpc gmp"
132 echo "Installing dependencies ..."
133 if ! which brew > /dev/null; then
134 echo "Homebrew not installed."
136 brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
139 GCCFLAGS="${GCCFLAGS} \
140 --with-gmp=$(brew --prefix gmp) \
141 --with-mpfr=$(brew --prefix mpfr) \
142 --with-mpc=$(brew --prefix mpc)
143 -with-libiconv-prefix=$(brew --prefix libiconv)"
147 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
148 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
151 echo "Found CygWin that means Windows most likely."
154 echo "Found unknown OS. Aborting!"
159 ##############################################################################
161 # You probably don't have to touch anything after this
162 ##############################################################################
164 # Fetch a versioned file from a URL
166 if [ ! -e ${STAMPS}/$1.fetch ]; then
167 log "Downloading $1 sources..."
169 touch ${STAMPS}/$1.fetch
173 # Log a message out to the console
175 echo "******************************************************************"
177 echo "******************************************************************"
183 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
184 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
187 echo "archive type bz2"
191 echo "archive type gz"
195 echo "Unknown archive type of $1"
200 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
206 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
209 if [ ! -d $SUMMON_DIR ]; then
210 mkdir -p ${SUMMON_DIR}
215 mkdir -p ${STAMPS} ${SOURCES}
219 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
220 fetch ${GCC} ${GCCURL}
221 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
222 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
224 if [ ${OOCD_EN} != 0 ]; then
225 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
226 log "Cloning OpenOCD sources..."
227 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
231 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
232 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
233 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
234 rm -rf openocd-${OOCD}
238 if [ ${LIBSTM32_EN} != 0 ]; then
239 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
240 log "Cloning libcmsis sources..."
241 git clone git://git.open-bldc.org/libcmsis.git
243 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
244 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
249 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
250 log "Cloning libstm32 sources..."
251 git clone git://git.open-bldc.org/libstm32.git
253 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
254 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
259 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
260 log "Cloning libstm32usb sources..."
261 git clone git://git.open-bldc.org/libstm32usb.git
263 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
264 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
270 if [ ${LIBOPENSTM32_EN} != 0 ]; then
271 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
272 log "Cloning libopenstm32 sources..."
273 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
275 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
276 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
284 if [ ! -e build ]; then
288 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
291 log "Configuring ${BINUTILS}"
292 ../${BINUTILS}/configure --target=${TARGET} \
301 log "Building ${BINUTILS}"
303 install ${BINUTILS} install
305 log "Cleaning up ${BINUTILS}"
306 touch ${STAMPS}/${BINUTILS}.build
307 rm -rf build/* ${BINUTILS}
310 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
313 log "Configuring ${GCC}-boot"
314 ../${GCCDIR}/configure --target=${TARGET} \
318 --enable-languages="c" \
328 log "Building ${GCC}-boot"
329 make ${MAKEFLAGS} all-gcc
330 install ${GCC}-boot install-gcc
332 log "Cleaning up ${GCC}-boot"
333 touch ${STAMPS}/${GCC}-boot.build
334 rm -rf build/* ${GCCDIR}
337 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
340 log "Configuring ${NEWLIB}"
341 # configuration options and flags partially
342 # from https://github.com/jsnyder/arm-eabi-toolchain
343 ../${NEWLIB}/configure --target=${TARGET} \
351 --disable-newlib-supplied-syscalls \
356 log "Building ${NEWLIB}"
357 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"
358 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
359 install ${NEWLIB} install
361 log "Cleaning up ${NEWLIB}"
362 touch ${STAMPS}/${NEWLIB}.build
363 rm -rf build/* ${NEWLIB}
366 # Yes, you need to build gcc again!
367 if [ ! -e ${STAMPS}/${GCC}.build ]; then
370 log "Configuring ${GCC}"
371 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
372 ../${GCCDIR}/configure --target=${TARGET} \
384 log "Building ${GCC}"
386 install ${GCC} install
388 log "Cleaning up ${GCC}"
389 touch ${STAMPS}/${GCC}.build
390 rm -rf build/* ${GCCDIR}
393 if [ ! -e ${STAMPS}/${GDB}.build ]; then
396 log "Configuring ${GDB}"
397 ../${GDB}/configure --target=${TARGET} \
403 log "Building ${GDB}"
405 install ${GDB} install
407 log "Cleaning up ${GDB}"
408 touch ${STAMPS}/${GDB}.build
409 rm -rf build/* ${GDB}
412 if [ ${OOCD_EN} != 0 ]; then
413 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
414 unpack openocd-${OOCD}
416 log "Configuring openocd-${OOCD}"
417 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
418 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
419 ../openocd-${OOCD}/configure --enable-maintainer-mode \
423 --enable-ft2232_libftdi \
424 --enable-usb_blaster_libftdi \
425 --enable-amtjtagaccel \
428 --enable-at91rm9200 \
430 --enable-presto_libftdi \
435 --enable-arm-jtag-ew \
437 log "Building openocd-${OOCD}"
439 install openocd-${OOCD} install
441 log "Cleaning up openocd-${OOCD}"
442 touch ${STAMPS}/openocd-${OOCD}.build
443 rm -rf build/* ${OOCD}
447 if [ ${LIBSTM32_EN} != 0 ]; then
448 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
449 unpack libcmsis-${LIBCMSIS}
450 cd libcmsis-${LIBCMSIS}
451 log "Building libcmsis-${LIBCMSIS}"
452 make arch_prefix=${TARGET} prefix=${PREFIX}
453 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
455 log "Cleaning up libcmsis-${LIBCMSIS}"
456 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
457 rm -rf libcmsis-${LIBCMSIS}
460 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
461 unpack libstm32-${LIBSTM32}
462 cd libstm32-${LIBSTM32}
463 log "Building libstm32-${LIBSTM32}"
464 make arch_prefix=${TARGET} prefix=${PREFIX}
465 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
467 log "Cleaning up libstm32-${LIBSTM32}"
468 touch ${STAMPS}/libstm32-${LIBSTM32}.build
469 rm -rf libstm32-${LIBSTM32}
472 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
473 unpack libstm32usb-${LIBSTM32USB}
474 cd libstm32usb-${LIBSTM32USB}
475 log "Building libstm32usb-${LIBSTM32USB}"
476 make arch_prefix=${TARGET} prefix=${PREFIX}
477 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
479 log "Cleaning up libstm32usb-${LIBSTM32USB}"
480 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
481 rm -rf libstm32usb-${LIBSTM32USB}
485 if [ $LIBOPENSTM32_EN != 0 ]; then
486 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
487 unpack libopenstm32-${LIBOPENSTM32}
488 cd libopenstm32-${LIBOPENSTM32}
489 log "Building libopenstm32-${LIBOPENSTM32}"
490 make PREFIX=${TARGET} DESTDIR=${PREFIX}
491 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
493 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
494 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
495 rm -rf libopenstm32-${LIBOPENSTM32}
499 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
500 log "Removing work directory"