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>
8 # Stop if any command fails
11 ##############################################################################
13 # You probably want to customize those
14 ##############################################################################
15 TARGET=arm-eabi # Or: TARGET=arm-elf
16 PREFIX=${HOME}/arm # Install location of your final toolchain
17 PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
18 DARWIN_CELLAR=$(brew --cellar) # Path in which MacPorts or Fink is installed
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
41 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
44 GCCRELEASE=4.6-2011.07
45 GCCVERSION=${GCCRELEASE}
46 GCC=gcc-linaro-${GCCVERSION}
47 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
50 BINUTILS=binutils-2.21
59 ##############################################################################
61 ##############################################################################
63 if which getconf > /dev/null; then
64 CPUS=$(getconf _NPROCESSORS_ONLN)
68 PARALLEL=-j$((CPUS + 1))
69 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
74 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
77 # To default to the Cortex-M3:
78 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
81 # Pull in the local configuration, if any
82 if [ -f local.sh ]; then
89 if [ ${QUIET} != 0 ]; then
91 MAKEFLAGS="${MAKEFLAGS} -s"
94 export PATH="${PREFIX}/bin:${PATH}"
97 SOURCES=${SUMMON_DIR}/sources
98 STAMPS=${SUMMON_DIR}/stamps
101 ##############################################################################
103 ##############################################################################
106 ##############################################################################
107 # OS and Tooldetection section
108 # Detects which tools and flags to use
109 ##############################################################################
113 echo "Found Linux OS."
116 echo "Found Darwin OS."
118 # darwin dependencies
119 DARWINDEPS="gnutar mpfr libmpc gmp"
122 GCCFLAGS="${GCCFLAGS} \
123 --with-gmp=${DARWIN_OPT_PATH} \
124 --with-mpfr=${DARWIN_OPT_PATH} \
125 --with-mpc=${DARWIN_OPT_PATH} \
126 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
128 echo "Attempting to automatically check if common dependencies are installed on your system"
129 if ! which port > /dev/null; then
130 echo "MacPorts not installed."
132 pc=`port installed ${DARWINDEPS} | wc -l | tr -d " "`
133 if [ ${pc} -lt $[${DARWINDEPSCOUNT}+1] ];
135 echo "Something is missing, do you want to install everything needed?"
136 echo "(You need super user rights to do this.)"
138 if [ read = "y" || read = "yes" ];
140 sudo port install ${DARWINDEPS}
143 echo "Found: "${DARWINDEPS}"!"
149 --with-libiconv-prefix=${DARWIN_OPT_PATH}"
150 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
151 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
154 echo "Found CygWin that means Windows most likely."
157 echo "Found unknown OS. Aborting!"
162 ##############################################################################
164 # You probably don't have to touch anything after this
165 ##############################################################################
167 # Fetch a versioned file from a URL
169 if [ ! -e ${STAMPS}/$1.fetch ]; then
170 log "Downloading $1 sources..."
171 wget -c --no-passive-ftp $2
172 touch ${STAMPS}/$1.fetch
176 # Log a message out to the console
178 echo "******************************************************************"
180 echo "******************************************************************"
186 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
187 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
190 echo "archive type bz2"
194 echo "archive type gz"
198 echo "Unknown archive type of $1"
203 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
209 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
213 mkdir -p ${STAMPS} ${SOURCES}
217 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
218 fetch ${GCC} ${GCCURL}
219 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
220 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
222 if [ ${OOCD_EN} != 0 ]; then
223 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
224 log "Cloning OpenOCD sources..."
225 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
229 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
230 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
231 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
232 rm -rf openocd-${OOCD}
236 if [ ${LIBSTM32_EN} != 0 ]; then
237 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
238 log "Cloning libcmsis sources..."
239 git clone git://git.open-bldc.org/libcmsis.git
241 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
242 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
247 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
248 log "Cloning libstm32 sources..."
249 git clone git://git.open-bldc.org/libstm32.git
251 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
252 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
257 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
258 log "Cloning libstm32usb sources..."
259 git clone git://git.open-bldc.org/libstm32usb.git
261 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
262 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
268 if [ ${LIBOPENSTM32_EN} != 0 ]; then
269 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
270 log "Cloning libopenstm32 sources..."
271 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
273 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
274 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
282 if [ ! -e build ]; then
286 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
289 log "Configuring ${BINUTILS}"
290 ../${BINUTILS}/configure --target=${TARGET} \
299 log "Building ${BINUTILS}"
301 install ${BINUTILS} install
303 log "Cleaning up ${BINUTILS}"
304 touch ${STAMPS}/${BINUTILS}.build
305 rm -rf build/* ${BINUTILS}
308 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
311 log "Configuring ${GCC}-boot"
312 ../${GCC}/configure --target=${TARGET} \
316 --enable-languages="c" \
326 log "Building ${GCC}-boot"
327 make ${MAKEFLAGS} all-gcc
328 install ${GCC}-boot install-gcc
330 log "Cleaning up ${GCC}-boot"
331 touch ${STAMPS}/${GCC}-boot.build
332 rm -rf build/* ${GCC}
335 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
338 log "Configuring ${NEWLIB}"
339 ../${NEWLIB}/configure --target=${TARGET} \
347 --disable-newlib-supplied-syscalls \
349 log "Building ${NEWLIB}"
350 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
351 install ${NEWLIB} install
353 log "Cleaning up ${NEWLIB}"
354 touch ${STAMPS}/${NEWLIB}.build
355 rm -rf build/* ${NEWLIB}
358 # Yes, you need to build gcc again!
359 if [ ! -e ${STAMPS}/${GCC}.build ]; then
362 log "Configuring ${GCC}"
363 ../${GCC}/configure --target=${TARGET} \
367 --enable-languages="c,c++" \
376 log "Building ${GCC}"
378 install ${GCC} install
380 log "Cleaning up ${GCC}"
381 touch ${STAMPS}/${GCC}.build
382 rm -rf build/* ${GCC}
385 if [ ! -e ${STAMPS}/${GDB}.build ]; then
388 log "Configuring ${GDB}"
389 ../${GDB}/configure --target=${TARGET} \
395 log "Building ${GDB}"
397 install ${GDB} install
399 log "Cleaning up ${GDB}"
400 touch ${STAMPS}/${GDB}.build
401 rm -rf build/* ${GDB}
404 if [ ${OOCD_EN} != 0 ]; then
405 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
406 unpack openocd-${OOCD}
408 log "Configuring openocd-${OOCD}"
409 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
410 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
411 ../openocd-${OOCD}/configure --enable-maintainer-mode \
415 --enable-ft2232_libftdi \
416 --enable-usb_blaster_libftdi \
417 --enable-amtjtagaccel \
420 --enable-at91rm9200 \
422 --enable-presto_libftdi \
427 --enable-arm-jtag-ew \
429 log "Building openocd-${OOCD}"
431 install openocd-${OOCD} install
433 log "Cleaning up openocd-${OOCD}"
434 touch ${STAMPS}/openocd-${OOCD}.build
435 rm -rf build/* ${OOCD}
439 if [ ${LIBSTM32_EN} != 0 ]; then
440 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
441 unpack libcmsis-${LIBCMSIS}
442 cd libcmsis-${LIBCMSIS}
443 log "Building libcmsis-${LIBCMSIS}"
444 make arch_prefix=${TARGET} prefix=${PREFIX}
445 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
447 log "Cleaning up libcmsis-${LIBCMSIS}"
448 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
449 rm -rf libcmsis-${LIBCMSIS}
452 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
453 unpack libstm32-${LIBSTM32}
454 cd libstm32-${LIBSTM32}
455 log "Building libstm32-${LIBSTM32}"
456 make arch_prefix=${TARGET} prefix=${PREFIX}
457 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
459 log "Cleaning up libstm32-${LIBSTM32}"
460 touch ${STAMPS}/libstm32-${LIBSTM32}.build
461 rm -rf libstm32-${LIBSTM32}
464 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
465 unpack libstm32usb-${LIBSTM32USB}
466 cd libstm32usb-${LIBSTM32USB}
467 log "Building libstm32usb-${LIBSTM32USB}"
468 make arch_prefix=${TARGET} prefix=${PREFIX}
469 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
471 log "Cleaning up libstm32usb-${LIBSTM32USB}"
472 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
473 rm -rf libstm32usb-${LIBSTM32USB}
477 if [ $LIBOPENSTM32_EN != 0 ]; then
478 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
479 unpack libopenstm32-${LIBOPENSTM32}
480 cd libopenstm32-${LIBOPENSTM32}
481 log "Building libopenstm32-${LIBOPENSTM32}"
482 make PREFIX=${TARGET} DESTDIR=${PREFIX}
483 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
485 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
486 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
487 rm -rf libopenstm32-${LIBOPENSTM32}