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-eabi # Or: TARGET=arm-elf
17 PREFIX=${HOME}/arm # Install location of your final toolchain
18 PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
19 # Set to 'sudo' if you need superuser privileges while installing
21 # Set to 1 to be quieter while running
23 # Set to 1 to use linaro gcc instead of the FSF gcc
25 # Set to 1 to enable building of OpenOCD
27 # Set to 1 to build libstm32 provided by ST
29 # Set to 1 to build libopenstm32 an open source library for stm32
31 # Make the gcc default to Cortex-M3
32 DEFAULT_TO_CORTEX_M3=1
34 ##############################################################################
35 # Version and download url settings section
36 ##############################################################################
37 if [ ${USE_LINARO} == 0 ] ; then
42 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
45 GCCRELEASE=4.6-2011.07
46 GCCVERSION=4.6-2011.07-0
47 GCC=gcc-linaro-${GCCRELEASE}
48 GCCDIR=gcc-linaro-${GCCVERSION}
49 GCCURL=http://launchpad.net/gcc-linaro/4.6/${GCCRELEASE}/+download/gcc-linaro-${GCCRELEASE}.tar.bz2
52 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
121 DARWINDEPS="wget mpfr libmpc gmp"
124 echo "Installing dependencies ..."
125 if ! which brew > /dev/null; then
126 echo "Homebrew not installed."
128 brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
131 GCCFLAGS="${GCCFLAGS} \
132 --with-gmp=$(brew --prefix gmp) \
133 --with-mpfr=$(brew --prefix mpfr) \
134 --with-mpc=$(brew --prefix mpc)
135 -with-libiconv-prefix=$(brew --prefix libiconv)"
139 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
140 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
143 echo "Found CygWin that means Windows most likely."
146 echo "Found unknown OS. Aborting!"
151 ##############################################################################
153 # You probably don't have to touch anything after this
154 ##############################################################################
156 # Fetch a versioned file from a URL
158 if [ ! -e ${STAMPS}/$1.fetch ]; then
159 log "Downloading $1 sources..."
161 touch ${STAMPS}/$1.fetch
165 # Log a message out to the console
167 echo "******************************************************************"
169 echo "******************************************************************"
175 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
176 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
179 echo "archive type bz2"
183 echo "archive type gz"
187 echo "Unknown archive type of $1"
192 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
198 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
202 mkdir -p ${STAMPS} ${SOURCES}
206 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
207 fetch ${GCC} ${GCCURL}
208 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
209 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
211 if [ ${OOCD_EN} != 0 ]; then
212 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
213 log "Cloning OpenOCD sources..."
214 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
218 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
219 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
220 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
221 rm -rf openocd-${OOCD}
225 if [ ${LIBSTM32_EN} != 0 ]; then
226 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
227 log "Cloning libcmsis sources..."
228 git clone git://git.open-bldc.org/libcmsis.git
230 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
231 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
236 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
237 log "Cloning libstm32 sources..."
238 git clone git://git.open-bldc.org/libstm32.git
240 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
241 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
246 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
247 log "Cloning libstm32usb sources..."
248 git clone git://git.open-bldc.org/libstm32usb.git
250 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
251 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
257 if [ ${LIBOPENSTM32_EN} != 0 ]; then
258 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
259 log "Cloning libopenstm32 sources..."
260 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
262 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
263 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
271 if [ ! -e build ]; then
275 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
278 log "Configuring ${BINUTILS}"
279 ../${BINUTILS}/configure --target=${TARGET} \
288 log "Building ${BINUTILS}"
290 install ${BINUTILS} install
292 log "Cleaning up ${BINUTILS}"
293 touch ${STAMPS}/${BINUTILS}.build
294 rm -rf build/* ${BINUTILS}
297 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
300 log "Configuring ${GCC}-boot"
301 ../${GCCDIR}/configure --target=${TARGET} \
305 --enable-languages="c" \
315 log "Building ${GCC}-boot"
316 make ${MAKEFLAGS} all-gcc
317 install ${GCC}-boot install-gcc
319 log "Cleaning up ${GCC}-boot"
320 touch ${STAMPS}/${GCC}-boot.build
321 rm -rf build/* ${GCCDIR}
324 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
327 log "Configuring ${NEWLIB}"
328 ../${NEWLIB}/configure --target=${TARGET} \
336 --disable-newlib-supplied-syscalls \
338 log "Building ${NEWLIB}"
339 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
340 install ${NEWLIB} install
342 log "Cleaning up ${NEWLIB}"
343 touch ${STAMPS}/${NEWLIB}.build
344 rm -rf build/* ${NEWLIB}
347 # Yes, you need to build gcc again!
348 if [ ! -e ${STAMPS}/${GCC}.build ]; then
351 log "Configuring ${GCC}"
352 ../${GCCDIR}/configure --target=${TARGET} \
356 --enable-languages="c,c++" \
365 log "Building ${GCC}"
367 install ${GCC} install
369 log "Cleaning up ${GCC}"
370 touch ${STAMPS}/${GCC}.build
371 rm -rf build/* ${GCCDIR}
374 if [ ! -e ${STAMPS}/${GDB}.build ]; then
377 log "Configuring ${GDB}"
378 ../${GDB}/configure --target=${TARGET} \
384 log "Building ${GDB}"
386 install ${GDB} install
388 log "Cleaning up ${GDB}"
389 touch ${STAMPS}/${GDB}.build
390 rm -rf build/* ${GDB}
393 if [ ${OOCD_EN} != 0 ]; then
394 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
395 unpack openocd-${OOCD}
397 log "Configuring openocd-${OOCD}"
398 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
399 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
400 ../openocd-${OOCD}/configure --enable-maintainer-mode \
404 --enable-ft2232_libftdi \
405 --enable-usb_blaster_libftdi \
406 --enable-amtjtagaccel \
409 --enable-at91rm9200 \
411 --enable-presto_libftdi \
416 --enable-arm-jtag-ew \
418 log "Building openocd-${OOCD}"
420 install openocd-${OOCD} install
422 log "Cleaning up openocd-${OOCD}"
423 touch ${STAMPS}/openocd-${OOCD}.build
424 rm -rf build/* ${OOCD}
428 if [ ${LIBSTM32_EN} != 0 ]; then
429 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
430 unpack libcmsis-${LIBCMSIS}
431 cd libcmsis-${LIBCMSIS}
432 log "Building libcmsis-${LIBCMSIS}"
433 make arch_prefix=${TARGET} prefix=${PREFIX}
434 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
436 log "Cleaning up libcmsis-${LIBCMSIS}"
437 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
438 rm -rf libcmsis-${LIBCMSIS}
441 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
442 unpack libstm32-${LIBSTM32}
443 cd libstm32-${LIBSTM32}
444 log "Building libstm32-${LIBSTM32}"
445 make arch_prefix=${TARGET} prefix=${PREFIX}
446 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
448 log "Cleaning up libstm32-${LIBSTM32}"
449 touch ${STAMPS}/libstm32-${LIBSTM32}.build
450 rm -rf libstm32-${LIBSTM32}
453 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
454 unpack libstm32usb-${LIBSTM32USB}
455 cd libstm32usb-${LIBSTM32USB}
456 log "Building libstm32usb-${LIBSTM32USB}"
457 make arch_prefix=${TARGET} prefix=${PREFIX}
458 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
460 log "Cleaning up libstm32usb-${LIBSTM32USB}"
461 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
462 rm -rf libstm32usb-${LIBSTM32USB}
466 if [ $LIBOPENSTM32_EN != 0 ]; then
467 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
468 unpack libopenstm32-${LIBOPENSTM32}
469 cd libopenstm32-${LIBOPENSTM32}
470 log "Building libopenstm32-${LIBOPENSTM32}"
471 make PREFIX=${TARGET} DESTDIR=${PREFIX}
472 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
474 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
475 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
476 rm -rf libopenstm32-${LIBOPENSTM32}