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 [ -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 building of OpenOCD
28 # Set to 1 to build libstm32 provided by ST
30 # Set to 1 to build libopenstm32 an open source library for stm32
32 # Make the gcc default to Cortex-M3
33 DEFAULT_TO_CORTEX_M3=1
35 ##############################################################################
36 # Version and download url settings section
37 ##############################################################################
38 if [ ${USE_LINARO} == 0 ] ; then
43 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
46 GCCRELEASE=4.6-2011.07
47 GCCVERSION=4.6-2011.07-0
48 GCC=gcc-linaro-${GCCRELEASE}
49 GCCDIR=gcc-linaro-${GCCVERSION}
50 GCCURL=http://launchpad.net/gcc-linaro/4.6/${GCCRELEASE}/+download/gcc-linaro-${GCCRELEASE}.tar.bz2
53 BINUTILS=binutils-2.21
62 ##############################################################################
64 ##############################################################################
66 if which getconf > /dev/null; then
67 CPUS=$(getconf _NPROCESSORS_ONLN)
71 PARALLEL=-j$((CPUS + 1))
72 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
77 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
80 # To default to the Cortex-M3:
81 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
84 # Pull in the local configuration, if any
85 if [ -f local.sh ]; then
92 if [ ${QUIET} != 0 ]; then
94 MAKEFLAGS="${MAKEFLAGS} -s"
97 export PATH="${PREFIX}/bin:${PATH}"
100 SOURCES=${SUMMON_DIR}/sources
101 STAMPS=${SUMMON_DIR}/stamps
104 ##############################################################################
106 ##############################################################################
109 ##############################################################################
110 # OS and Tooldetection section
111 # Detects which tools and flags to use
112 ##############################################################################
116 echo "Found Linux OS."
119 echo "Found Darwin OS."
121 # darwin dependencies
122 DARWINDEPS="wget mpfr libmpc gmp"
125 echo "Installing dependencies ..."
126 if ! which brew > /dev/null; then
127 echo "Homebrew not installed."
129 brew install ${DARWINDEPS} | (grep -v '^Warning: Formula already installed: ' || true)
132 GCCFLAGS="${GCCFLAGS} \
133 --with-gmp=$(brew --prefix gmp) \
134 --with-mpfr=$(brew --prefix mpfr) \
135 --with-mpc=$(brew --prefix mpc)
136 -with-libiconv-prefix=$(brew --prefix libiconv)"
140 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
141 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
144 echo "Found CygWin that means Windows most likely."
147 echo "Found unknown OS. Aborting!"
152 ##############################################################################
154 # You probably don't have to touch anything after this
155 ##############################################################################
157 # Fetch a versioned file from a URL
159 if [ ! -e ${STAMPS}/$1.fetch ]; then
160 log "Downloading $1 sources..."
162 touch ${STAMPS}/$1.fetch
166 # Log a message out to the console
168 echo "******************************************************************"
170 echo "******************************************************************"
176 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
177 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
180 echo "archive type bz2"
184 echo "archive type gz"
188 echo "Unknown archive type of $1"
193 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
199 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
203 mkdir -p ${STAMPS} ${SOURCES}
207 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
208 fetch ${GCC} ${GCCURL}
209 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
210 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
212 if [ ${OOCD_EN} != 0 ]; then
213 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
214 log "Cloning OpenOCD sources..."
215 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
219 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
220 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
221 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
222 rm -rf openocd-${OOCD}
226 if [ ${LIBSTM32_EN} != 0 ]; then
227 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
228 log "Cloning libcmsis sources..."
229 git clone git://git.open-bldc.org/libcmsis.git
231 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
232 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
237 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
238 log "Cloning libstm32 sources..."
239 git clone git://git.open-bldc.org/libstm32.git
241 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
242 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
247 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
248 log "Cloning libstm32usb sources..."
249 git clone git://git.open-bldc.org/libstm32usb.git
251 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
252 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
258 if [ ${LIBOPENSTM32_EN} != 0 ]; then
259 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
260 log "Cloning libopenstm32 sources..."
261 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
263 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
264 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
270 mkdir -p ${SUMMON_DIR}
273 if [ ! -e build ]; then
277 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
280 log "Configuring ${BINUTILS}"
281 ../${BINUTILS}/configure --target=${TARGET} \
290 log "Building ${BINUTILS}"
292 install ${BINUTILS} install
294 log "Cleaning up ${BINUTILS}"
295 touch ${STAMPS}/${BINUTILS}.build
296 rm -rf build/* ${BINUTILS}
299 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
302 log "Configuring ${GCC}-boot"
303 ../${GCCDIR}/configure --target=${TARGET} \
307 --enable-languages="c" \
317 log "Building ${GCC}-boot"
318 make ${MAKEFLAGS} all-gcc
319 install ${GCC}-boot install-gcc
321 log "Cleaning up ${GCC}-boot"
322 touch ${STAMPS}/${GCC}-boot.build
323 rm -rf build/* ${GCCDIR}
326 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
329 log "Configuring ${NEWLIB}"
330 ../${NEWLIB}/configure --target=${TARGET} \
338 --disable-newlib-supplied-syscalls \
340 log "Building ${NEWLIB}"
341 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
342 install ${NEWLIB} install
344 log "Cleaning up ${NEWLIB}"
345 touch ${STAMPS}/${NEWLIB}.build
346 rm -rf build/* ${NEWLIB}
349 # Yes, you need to build gcc again!
350 if [ ! -e ${STAMPS}/${GCC}.build ]; then
353 log "Configuring ${GCC}"
354 ../${GCCDIR}/configure --target=${TARGET} \
358 --enable-languages="c,c++" \
367 log "Building ${GCC}"
369 install ${GCC} install
371 log "Cleaning up ${GCC}"
372 touch ${STAMPS}/${GCC}.build
373 rm -rf build/* ${GCCDIR}
376 if [ ! -e ${STAMPS}/${GDB}.build ]; then
379 log "Configuring ${GDB}"
380 ../${GDB}/configure --target=${TARGET} \
386 log "Building ${GDB}"
388 install ${GDB} install
390 log "Cleaning up ${GDB}"
391 touch ${STAMPS}/${GDB}.build
392 rm -rf build/* ${GDB}
395 if [ ${OOCD_EN} != 0 ]; then
396 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
397 unpack openocd-${OOCD}
399 log "Configuring openocd-${OOCD}"
400 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
401 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
402 ../openocd-${OOCD}/configure --enable-maintainer-mode \
406 --enable-ft2232_libftdi \
407 --enable-usb_blaster_libftdi \
408 --enable-amtjtagaccel \
411 --enable-at91rm9200 \
413 --enable-presto_libftdi \
418 --enable-arm-jtag-ew \
420 log "Building openocd-${OOCD}"
422 install openocd-${OOCD} install
424 log "Cleaning up openocd-${OOCD}"
425 touch ${STAMPS}/openocd-${OOCD}.build
426 rm -rf build/* ${OOCD}
430 if [ ${LIBSTM32_EN} != 0 ]; then
431 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
432 unpack libcmsis-${LIBCMSIS}
433 cd libcmsis-${LIBCMSIS}
434 log "Building libcmsis-${LIBCMSIS}"
435 make arch_prefix=${TARGET} prefix=${PREFIX}
436 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
438 log "Cleaning up libcmsis-${LIBCMSIS}"
439 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
440 rm -rf libcmsis-${LIBCMSIS}
443 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
444 unpack libstm32-${LIBSTM32}
445 cd libstm32-${LIBSTM32}
446 log "Building libstm32-${LIBSTM32}"
447 make arch_prefix=${TARGET} prefix=${PREFIX}
448 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
450 log "Cleaning up libstm32-${LIBSTM32}"
451 touch ${STAMPS}/libstm32-${LIBSTM32}.build
452 rm -rf libstm32-${LIBSTM32}
455 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
456 unpack libstm32usb-${LIBSTM32USB}
457 cd libstm32usb-${LIBSTM32USB}
458 log "Building libstm32usb-${LIBSTM32USB}"
459 make arch_prefix=${TARGET} prefix=${PREFIX}
460 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
462 log "Cleaning up libstm32usb-${LIBSTM32USB}"
463 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
464 rm -rf libstm32usb-${LIBSTM32USB}
468 if [ $LIBOPENSTM32_EN != 0 ]; then
469 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
470 unpack libopenstm32-${LIBOPENSTM32}
471 cd libopenstm32-${LIBOPENSTM32}
472 log "Building libopenstm32-${LIBOPENSTM32}"
473 make PREFIX=${TARGET} DESTDIR=${PREFIX}
474 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
476 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
477 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
478 rm -rf libopenstm32-${LIBOPENSTM32}