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="gnu-tar wget mpfr libmpc gmp"
122 echo "Installing dependencies"
123 if ! which brew > /dev/null; then
124 echo "homebrew not installed."
126 brew install ${DARWINDEPS} | grep -v '^Warning: Formula already installed: '
129 GCCFLAGS="${GCCFLAGS} \
130 --with-gmp=$(brew --prefix gmp) \
131 --with-mpfr=$(brew --prefix mpfr) \
132 --with-mpc=$(brew --prefix mpc)
133 -with-libiconv-prefix=$(brew --prefix libiconv)"
137 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
138 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
141 echo "Found CygWin that means Windows most likely."
144 echo "Found unknown OS. Aborting!"
149 ##############################################################################
151 # You probably don't have to touch anything after this
152 ##############################################################################
154 # Fetch a versioned file from a URL
156 if [ ! -e ${STAMPS}/$1.fetch ]; then
157 log "Downloading $1 sources..."
158 wget -c --no-passive-ftp $2
159 touch ${STAMPS}/$1.fetch
163 # Log a message out to the console
165 echo "******************************************************************"
167 echo "******************************************************************"
173 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
174 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
177 echo "archive type bz2"
181 echo "archive type gz"
185 echo "Unknown archive type of $1"
190 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
196 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
200 mkdir -p ${STAMPS} ${SOURCES}
204 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
205 fetch ${GCC} ${GCCURL}
206 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
207 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
209 if [ ${OOCD_EN} != 0 ]; then
210 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
211 log "Cloning OpenOCD sources..."
212 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
216 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
217 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
218 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
219 rm -rf openocd-${OOCD}
223 if [ ${LIBSTM32_EN} != 0 ]; then
224 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
225 log "Cloning libcmsis sources..."
226 git clone git://git.open-bldc.org/libcmsis.git
228 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
229 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
234 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
235 log "Cloning libstm32 sources..."
236 git clone git://git.open-bldc.org/libstm32.git
238 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
239 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
244 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
245 log "Cloning libstm32usb sources..."
246 git clone git://git.open-bldc.org/libstm32usb.git
248 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
249 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
255 if [ ${LIBOPENSTM32_EN} != 0 ]; then
256 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
257 log "Cloning libopenstm32 sources..."
258 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
260 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
261 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
269 if [ ! -e build ]; then
273 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
276 log "Configuring ${BINUTILS}"
277 ../${BINUTILS}/configure --target=${TARGET} \
286 log "Building ${BINUTILS}"
288 install ${BINUTILS} install
290 log "Cleaning up ${BINUTILS}"
291 touch ${STAMPS}/${BINUTILS}.build
292 rm -rf build/* ${BINUTILS}
295 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
298 log "Configuring ${GCC}-boot"
299 ../${GCC}/configure --target=${TARGET} \
303 --enable-languages="c" \
313 log "Building ${GCC}-boot"
314 make ${MAKEFLAGS} all-gcc
315 install ${GCC}-boot install-gcc
317 log "Cleaning up ${GCC}-boot"
318 touch ${STAMPS}/${GCC}-boot.build
319 rm -rf build/* ${GCC}
322 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
325 log "Configuring ${NEWLIB}"
326 ../${NEWLIB}/configure --target=${TARGET} \
334 --disable-newlib-supplied-syscalls \
336 log "Building ${NEWLIB}"
337 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
338 install ${NEWLIB} install
340 log "Cleaning up ${NEWLIB}"
341 touch ${STAMPS}/${NEWLIB}.build
342 rm -rf build/* ${NEWLIB}
345 # Yes, you need to build gcc again!
346 if [ ! -e ${STAMPS}/${GCC}.build ]; then
349 log "Configuring ${GCC}"
350 ../${GCC}/configure --target=${TARGET} \
354 --enable-languages="c,c++" \
363 log "Building ${GCC}"
365 install ${GCC} install
367 log "Cleaning up ${GCC}"
368 touch ${STAMPS}/${GCC}.build
369 rm -rf build/* ${GCC}
372 if [ ! -e ${STAMPS}/${GDB}.build ]; then
375 log "Configuring ${GDB}"
376 ../${GDB}/configure --target=${TARGET} \
382 log "Building ${GDB}"
384 install ${GDB} install
386 log "Cleaning up ${GDB}"
387 touch ${STAMPS}/${GDB}.build
388 rm -rf build/* ${GDB}
391 if [ ${OOCD_EN} != 0 ]; then
392 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
393 unpack openocd-${OOCD}
395 log "Configuring openocd-${OOCD}"
396 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
397 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
398 ../openocd-${OOCD}/configure --enable-maintainer-mode \
402 --enable-ft2232_libftdi \
403 --enable-usb_blaster_libftdi \
404 --enable-amtjtagaccel \
407 --enable-at91rm9200 \
409 --enable-presto_libftdi \
414 --enable-arm-jtag-ew \
416 log "Building openocd-${OOCD}"
418 install openocd-${OOCD} install
420 log "Cleaning up openocd-${OOCD}"
421 touch ${STAMPS}/openocd-${OOCD}.build
422 rm -rf build/* ${OOCD}
426 if [ ${LIBSTM32_EN} != 0 ]; then
427 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
428 unpack libcmsis-${LIBCMSIS}
429 cd libcmsis-${LIBCMSIS}
430 log "Building libcmsis-${LIBCMSIS}"
431 make arch_prefix=${TARGET} prefix=${PREFIX}
432 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
434 log "Cleaning up libcmsis-${LIBCMSIS}"
435 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
436 rm -rf libcmsis-${LIBCMSIS}
439 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
440 unpack libstm32-${LIBSTM32}
441 cd libstm32-${LIBSTM32}
442 log "Building libstm32-${LIBSTM32}"
443 make arch_prefix=${TARGET} prefix=${PREFIX}
444 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
446 log "Cleaning up libstm32-${LIBSTM32}"
447 touch ${STAMPS}/libstm32-${LIBSTM32}.build
448 rm -rf libstm32-${LIBSTM32}
451 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
452 unpack libstm32usb-${LIBSTM32USB}
453 cd libstm32usb-${LIBSTM32USB}
454 log "Building libstm32usb-${LIBSTM32USB}"
455 make arch_prefix=${TARGET} prefix=${PREFIX}
456 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
458 log "Cleaning up libstm32usb-${LIBSTM32USB}"
459 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
460 rm -rf libstm32usb-${LIBSTM32USB}
464 if [ $LIBOPENSTM32_EN != 0 ]; then
465 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
466 unpack libopenstm32-${LIBOPENSTM32}
467 cd libopenstm32-${LIBOPENSTM32}
468 log "Building libopenstm32-${LIBOPENSTM32}"
469 make PREFIX=${TARGET} DESTDIR=${PREFIX}
470 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
472 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
473 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
474 rm -rf libopenstm32-${LIBOPENSTM32}