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 DARWIN_CELLAR=$(brew --cellar) # Path in which MacPorts or Fink is installed
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
42 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
45 GCCRELEASE=4.6-2011.07
46 GCCVERSION=${GCCRELEASE}
47 GCC=gcc-linaro-${GCCVERSION}
48 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
51 BINUTILS=binutils-2.21
60 ##############################################################################
62 ##############################################################################
64 if which getconf > /dev/null; then
65 CPUS=$(getconf _NPROCESSORS_ONLN)
69 PARALLEL=-j$((CPUS + 1))
70 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
75 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
78 # To default to the Cortex-M3:
79 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
82 # Pull in the local configuration, if any
83 if [ -f local.sh ]; then
90 if [ ${QUIET} != 0 ]; then
92 MAKEFLAGS="${MAKEFLAGS} -s"
95 export PATH="${PREFIX}/bin:${PATH}"
98 SOURCES=${SUMMON_DIR}/sources
99 STAMPS=${SUMMON_DIR}/stamps
102 ##############################################################################
104 ##############################################################################
107 ##############################################################################
108 # OS and Tooldetection section
109 # Detects which tools and flags to use
110 ##############################################################################
114 echo "Found Linux OS."
117 echo "Found Darwin OS."
119 # darwin dependencies
120 DARWINDEPS="gnu-tar wget mpfr libmpc gmp"
123 echo "Installing dependencies"
124 if ! which brew > /dev/null; then
125 echo "homebrew not installed."
127 brew install ${DARWINDEPS} | grep -v '^Warning: Formula already installed: '
130 GCCFLAGS="${GCCFLAGS} \
131 --with-gmp=$(brew --prefix gmp) \
132 --with-mpfr=$(brew --prefix mpfr) \
133 --with-mpc=$(brew --prefix mpc)
134 -with-libiconv-prefix=$(brew --prefix libiconv)"
138 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
139 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
142 echo "Found CygWin that means Windows most likely."
145 echo "Found unknown OS. Aborting!"
150 ##############################################################################
152 # You probably don't have to touch anything after this
153 ##############################################################################
155 # Fetch a versioned file from a URL
157 if [ ! -e ${STAMPS}/$1.fetch ]; then
158 log "Downloading $1 sources..."
159 wget -c --no-passive-ftp $2
160 touch ${STAMPS}/$1.fetch
164 # Log a message out to the console
166 echo "******************************************************************"
168 echo "******************************************************************"
174 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
175 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
178 echo "archive type bz2"
182 echo "archive type gz"
186 echo "Unknown archive type of $1"
191 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
197 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
201 mkdir -p ${STAMPS} ${SOURCES}
205 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
206 fetch ${GCC} ${GCCURL}
207 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
208 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
210 if [ ${OOCD_EN} != 0 ]; then
211 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
212 log "Cloning OpenOCD sources..."
213 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
217 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
218 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
219 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
220 rm -rf openocd-${OOCD}
224 if [ ${LIBSTM32_EN} != 0 ]; then
225 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
226 log "Cloning libcmsis sources..."
227 git clone git://git.open-bldc.org/libcmsis.git
229 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
230 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
235 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
236 log "Cloning libstm32 sources..."
237 git clone git://git.open-bldc.org/libstm32.git
239 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
240 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
245 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
246 log "Cloning libstm32usb sources..."
247 git clone git://git.open-bldc.org/libstm32usb.git
249 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
250 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
256 if [ ${LIBOPENSTM32_EN} != 0 ]; then
257 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
258 log "Cloning libopenstm32 sources..."
259 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
261 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
262 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
270 if [ ! -e build ]; then
274 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
277 log "Configuring ${BINUTILS}"
278 ../${BINUTILS}/configure --target=${TARGET} \
287 log "Building ${BINUTILS}"
289 install ${BINUTILS} install
291 log "Cleaning up ${BINUTILS}"
292 touch ${STAMPS}/${BINUTILS}.build
293 rm -rf build/* ${BINUTILS}
296 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
299 log "Configuring ${GCC}-boot"
300 ../${GCC}/configure --target=${TARGET} \
304 --enable-languages="c" \
314 log "Building ${GCC}-boot"
315 make ${MAKEFLAGS} all-gcc
316 install ${GCC}-boot install-gcc
318 log "Cleaning up ${GCC}-boot"
319 touch ${STAMPS}/${GCC}-boot.build
320 rm -rf build/* ${GCC}
323 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
326 log "Configuring ${NEWLIB}"
327 ../${NEWLIB}/configure --target=${TARGET} \
335 --disable-newlib-supplied-syscalls \
337 log "Building ${NEWLIB}"
338 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
339 install ${NEWLIB} install
341 log "Cleaning up ${NEWLIB}"
342 touch ${STAMPS}/${NEWLIB}.build
343 rm -rf build/* ${NEWLIB}
346 # Yes, you need to build gcc again!
347 if [ ! -e ${STAMPS}/${GCC}.build ]; then
350 log "Configuring ${GCC}"
351 ../${GCC}/configure --target=${TARGET} \
355 --enable-languages="c,c++" \
364 log "Building ${GCC}"
366 install ${GCC} install
368 log "Cleaning up ${GCC}"
369 touch ${STAMPS}/${GCC}.build
370 rm -rf build/* ${GCC}
373 if [ ! -e ${STAMPS}/${GDB}.build ]; then
376 log "Configuring ${GDB}"
377 ../${GDB}/configure --target=${TARGET} \
383 log "Building ${GDB}"
385 install ${GDB} install
387 log "Cleaning up ${GDB}"
388 touch ${STAMPS}/${GDB}.build
389 rm -rf build/* ${GDB}
392 if [ ${OOCD_EN} != 0 ]; then
393 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
394 unpack openocd-${OOCD}
396 log "Configuring openocd-${OOCD}"
397 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
398 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
399 ../openocd-${OOCD}/configure --enable-maintainer-mode \
403 --enable-ft2232_libftdi \
404 --enable-usb_blaster_libftdi \
405 --enable-amtjtagaccel \
408 --enable-at91rm9200 \
410 --enable-presto_libftdi \
415 --enable-arm-jtag-ew \
417 log "Building openocd-${OOCD}"
419 install openocd-${OOCD} install
421 log "Cleaning up openocd-${OOCD}"
422 touch ${STAMPS}/openocd-${OOCD}.build
423 rm -rf build/* ${OOCD}
427 if [ ${LIBSTM32_EN} != 0 ]; then
428 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
429 unpack libcmsis-${LIBCMSIS}
430 cd libcmsis-${LIBCMSIS}
431 log "Building libcmsis-${LIBCMSIS}"
432 make arch_prefix=${TARGET} prefix=${PREFIX}
433 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
435 log "Cleaning up libcmsis-${LIBCMSIS}"
436 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
437 rm -rf libcmsis-${LIBCMSIS}
440 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
441 unpack libstm32-${LIBSTM32}
442 cd libstm32-${LIBSTM32}
443 log "Building libstm32-${LIBSTM32}"
444 make arch_prefix=${TARGET} prefix=${PREFIX}
445 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
447 log "Cleaning up libstm32-${LIBSTM32}"
448 touch ${STAMPS}/libstm32-${LIBSTM32}.build
449 rm -rf libstm32-${LIBSTM32}
452 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
453 unpack libstm32usb-${LIBSTM32USB}
454 cd libstm32usb-${LIBSTM32USB}
455 log "Building libstm32usb-${LIBSTM32USB}"
456 make arch_prefix=${TARGET} prefix=${PREFIX}
457 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
459 log "Cleaning up libstm32usb-${LIBSTM32USB}"
460 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
461 rm -rf libstm32usb-${LIBSTM32USB}
465 if [ $LIBOPENSTM32_EN != 0 ]; then
466 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
467 unpack libopenstm32-${LIBOPENSTM32}
468 cd libopenstm32-${LIBOPENSTM32}
469 log "Building libopenstm32-${LIBOPENSTM32}"
470 make PREFIX=${TARGET} DESTDIR=${PREFIX}
471 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
473 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
474 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
475 rm -rf libopenstm32-${LIBOPENSTM32}