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"
131 echo "Installing dependencies ..."
132 if ! which brew > /dev/null; then
133 echo "Homebrew not installed."
135 brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
138 GCCFLAGS="${GCCFLAGS} \
139 --with-gmp=$(brew --prefix gmp) \
140 --with-mpfr=$(brew --prefix mpfr) \
141 --with-mpc=$(brew --prefix mpc)
142 -with-libiconv-prefix=$(brew --prefix libiconv)"
146 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
147 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
150 echo "Found CygWin that means Windows most likely."
153 echo "Found unknown OS. Aborting!"
158 ##############################################################################
160 # You probably don't have to touch anything after this
161 ##############################################################################
163 # Fetch a versioned file from a URL
165 if [ ! -e ${STAMPS}/$1.fetch ]; then
166 log "Downloading $1 sources..."
168 touch ${STAMPS}/$1.fetch
172 # Log a message out to the console
174 echo "******************************************************************"
176 echo "******************************************************************"
182 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
183 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
186 echo "archive type bz2"
190 echo "archive type gz"
194 echo "Unknown archive type of $1"
199 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
205 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
208 if [ ! -d $SUMMON_DIR ]; then
209 mkdir -p ${SUMMON_DIR}
214 mkdir -p ${STAMPS} ${SOURCES}
218 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
219 fetch ${GCC} ${GCCURL}
220 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
221 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
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 log "Configuring ${GCC}-boot"
313 ../${GCCDIR}/configure --target=${TARGET} \
317 --enable-languages="c" \
327 log "Building ${GCC}-boot"
328 make ${MAKEFLAGS} all-gcc
329 install ${GCC}-boot install-gcc
331 log "Cleaning up ${GCC}-boot"
332 touch ${STAMPS}/${GCC}-boot.build
333 rm -rf build/* ${GCCDIR}
336 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
339 log "Configuring ${NEWLIB}"
340 # configuration options and flags partially
341 # from https://github.com/jsnyder/arm-eabi-toolchain
342 ../${NEWLIB}/configure --target=${TARGET} \
350 --disable-newlib-supplied-syscalls \
355 log "Building ${NEWLIB}"
356 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"
357 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
358 install ${NEWLIB} install
360 log "Cleaning up ${NEWLIB}"
361 touch ${STAMPS}/${NEWLIB}.build
362 rm -rf build/* ${NEWLIB}
365 # Yes, you need to build gcc again!
366 if [ ! -e ${STAMPS}/${GCC}.build ]; then
369 log "Configuring ${GCC}"
370 [ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
371 ../${GCCDIR}/configure --target=${TARGET} \
383 log "Building ${GCC}"
385 install ${GCC} install
387 log "Cleaning up ${GCC}"
388 touch ${STAMPS}/${GCC}.build
389 rm -rf build/* ${GCCDIR}
392 if [ ! -e ${STAMPS}/${GDB}.build ]; then
395 log "Configuring ${GDB}"
396 ../${GDB}/configure --target=${TARGET} \
402 log "Building ${GDB}"
404 install ${GDB} install
406 log "Cleaning up ${GDB}"
407 touch ${STAMPS}/${GDB}.build
408 rm -rf build/* ${GDB}
411 if [ ${OOCD_EN} != 0 ]; then
412 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
413 unpack openocd-${OOCD}
415 log "Configuring openocd-${OOCD}"
416 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
417 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
418 ../openocd-${OOCD}/configure --enable-maintainer-mode \
422 --enable-ft2232_libftdi \
423 --enable-usb_blaster_libftdi \
424 --enable-amtjtagaccel \
427 --enable-at91rm9200 \
429 --enable-presto_libftdi \
434 --enable-arm-jtag-ew \
436 log "Building openocd-${OOCD}"
438 install openocd-${OOCD} install
440 log "Cleaning up openocd-${OOCD}"
441 touch ${STAMPS}/openocd-${OOCD}.build
442 rm -rf build/* ${OOCD}
446 if [ ${LIBSTM32_EN} != 0 ]; then
447 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
448 unpack libcmsis-${LIBCMSIS}
449 cd libcmsis-${LIBCMSIS}
450 log "Building libcmsis-${LIBCMSIS}"
451 make arch_prefix=${TARGET} prefix=${PREFIX}
452 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
454 log "Cleaning up libcmsis-${LIBCMSIS}"
455 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
456 rm -rf libcmsis-${LIBCMSIS}
459 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
460 unpack libstm32-${LIBSTM32}
461 cd libstm32-${LIBSTM32}
462 log "Building libstm32-${LIBSTM32}"
463 make arch_prefix=${TARGET} prefix=${PREFIX}
464 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
466 log "Cleaning up libstm32-${LIBSTM32}"
467 touch ${STAMPS}/libstm32-${LIBSTM32}.build
468 rm -rf libstm32-${LIBSTM32}
471 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
472 unpack libstm32usb-${LIBSTM32USB}
473 cd libstm32usb-${LIBSTM32USB}
474 log "Building libstm32usb-${LIBSTM32USB}"
475 make arch_prefix=${TARGET} prefix=${PREFIX}
476 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
478 log "Cleaning up libstm32usb-${LIBSTM32USB}"
479 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
480 rm -rf libstm32usb-${LIBSTM32USB}
484 if [ $LIBOPENSTM32_EN != 0 ]; then
485 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
486 unpack libopenstm32-${LIBOPENSTM32}
487 cd libopenstm32-${LIBOPENSTM32}
488 log "Building libopenstm32-${LIBOPENSTM32}"
489 make PREFIX=${TARGET} DESTDIR=${PREFIX}
490 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
492 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
493 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
494 rm -rf libopenstm32-${LIBOPENSTM32}
498 if [ ${SUMMON_DIR_CREATED} = 1 ]; then
499 log "Removing work directory"