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.
6 # Requirements (example is for Debian, replace package names as needed):
8 # apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev \
9 # libmpc-dev autoconf texinfo build-essential
11 # Or on Ubuntu Maverick give `apt-get build-dep gcc-4.5` a try.
14 # Stop if any command fails
17 ##############################################################################
18 # Default settings section
19 # You probably want to customize those
20 # You can also pass them as parameters to the script
21 ##############################################################################
22 TARGET=arm-none-eabi # Or: TARGET=arm-elf
23 PREFIX=${HOME}/sat # Install location of your final toolchain
24 DARWIN_OPT_PATH=/opt/local # Path in which MacPorts or Fink is installed
25 # Set to 'sudo' if you need superuser privileges while installing
27 # Set to 1 to be quieter while running
29 # Set to 1 to use linaro gcc instead of the FSF gcc
31 # Set to 1 to enable building of OpenOCD
33 # Set to 1 to build libstm32 provided by ST
35 # Set to 1 to build libopencm3 an open source library for Cortex M3 and simalar
38 # Make the gcc default to Cortex-M3
39 DEFAULT_TO_CORTEX_M3=0
40 # Override automatic detection of cpus to compile on
43 ##############################################################################
44 # Parsing command line parameters
45 ##############################################################################
47 while [ $# -gt 0 ]; do
50 TARGET=$(echo $1 | sed 's,^TARGET=,,')
53 PREFIX=$(echo $1 | sed 's,^PREFIX=,,')
56 DARWIN_OPT_PATH=$(echo $1 | sed 's,^DARWIN_OPT_PATH=,,')
59 SUDO=$(echo $1 | sed 's,^SUDO=,,')
62 QUIET=$(echo $1 | sed 's,^QUIET=,,')
65 USE_LINARO=$(echo $1 | sed 's,^USE_LINARO=,,')
68 OOCD_EN=$(echo $1 | sed 's,^OOCD_EN=,,')
71 LIBSTM32_EN=$(echo $1 | sed 's,^LIBSTM32_EN=,,')
74 LIBOPENCM3_EN=$(echo $1 | sed 's,^LIBOPENCM3_EN=,,')
76 DEFAULT_TO_CORTEX_M3=*)
77 DEFAULT_TO_CORTEX_M3=$(echo $1 | sed 's,^DEFAULT_TO_CORTEX_M3=,,')
80 CPUS=$(echo $1 | sed 's,^CPUS=,,')
83 echo "Unknown parameter: $1"
88 shift # shifting parameter list to access the next one
91 echo "Settings used for this build are:"
94 echo "DARWIN_OPT_PATH=$DARWIN_OPT_PATH"
97 echo "USE_LINARO=$USE_LINARO"
98 echo "OOCD_EN=$OOCD_EN"
99 echo "LIBSTM32_EN=$LIBSTM32_EN"
100 echo "LIBOPENCM3_EN=$LIBOPENCM3_EN"
101 echo "DEFAULT_TO_CORTEX_M3=$DEFAULT_TO_CORTEX_M3"
104 ##############################################################################
105 # Version and download url settings section
106 ##############################################################################
107 if [ ${USE_LINARO} == 0 ] ; then
110 GCC=gcc-${GCCVERSION}
111 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
113 # For the Linaro GCC:
114 GCCRELEASE=4.5-2011.02-0
115 GCCVERSION=4.5-2011.02-0
116 GCC=gcc-linaro-${GCCVERSION}
117 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
120 BINUTILS=binutils-2.21.1
129 ##############################################################################
131 ##############################################################################
133 if [ "x${CPUS}" == "x" ]; then
134 if which getconf > /dev/null; then
135 CPUS=$(getconf _NPROCESSORS_ONLN)
140 PARALLEL=-j$((CPUS + 1))
145 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
150 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
153 # To default to the Cortex-M3:
154 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
157 # Pull in the local configuration, if any
158 if [ -f local.sh ]; then
162 MAKEFLAGS=${PARALLEL}
165 if [ ${QUIET} != 0 ]; then
167 MAKEFLAGS="${MAKEFLAGS} -s"
170 export PATH="${PREFIX}/bin:${PATH}"
173 SOURCES=${SUMMON_DIR}/sources
174 STAMPS=${SUMMON_DIR}/stamps
177 ##############################################################################
179 ##############################################################################
182 ##############################################################################
183 # OS and Tooldetection section
184 # Detects which tools and flags to use
185 ##############################################################################
189 echo "Found Linux OS."
192 echo "Found Darwin OS."
193 GCCFLAGS="${GCCFLAGS} \
194 --with-gmp=${DARWIN_OPT_PATH} \
195 --with-mpfr=${DARWIN_OPT_PATH} \
196 --with-mpc=${DARWIN_OPT_PATH} \
197 --with-libiconv-prefix=${DARWIN_OPT_PATH}"
198 OOCD_CFLAGS="-I/opt/mine/include -I/opt/local/include"
199 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
200 if gcc --version | grep llvm-gcc > /dev/null ; then
201 echo "Found you are using llvm gcc, switching to clang for gcc compile."
206 echo "Found CygWin that means Windows most likely."
209 echo "Found unknown OS. Aborting!"
214 ##############################################################################
216 # You probably don't have to touch anything after this
217 ##############################################################################
219 # Fetch a versioned file from a URL
221 if [ ! -e ${STAMPS}/$1.fetch ]; then
222 log "Downloading $1 sources..."
223 wget -c --no-passive-ftp $2 && touch ${STAMPS}/$1.fetch
227 # Log a message out to the console
229 echo "******************************************************************"
231 echo "******************************************************************"
237 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
238 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
241 echo "archive type bz2"
245 echo "archive type gz"
249 echo "Unknown archive type of $1"
254 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
260 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
264 mkdir -p ${STAMPS} ${SOURCES}
268 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
269 fetch ${GCC} ${GCCURL}
270 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
271 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
273 if [ ${OOCD_EN} != 0 ]; then
274 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
275 log "Cloning OpenOCD sources..."
276 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
280 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
281 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
282 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
283 rm -rf openocd-${OOCD}
287 if [ ${LIBSTM32_EN} != 0 ]; then
288 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
289 log "Cloning libcmsis sources..."
290 git clone git://git.open-bldc.org/libcmsis.git
292 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
293 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
298 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
299 log "Cloning libstm32 sources..."
300 git clone git://git.open-bldc.org/libstm32.git
302 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
303 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
308 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
309 log "Cloning libstm32usb sources..."
310 git clone git://git.open-bldc.org/libstm32usb.git
312 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
313 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
319 if [ ${LIBOPENCM3_EN} != 0 ]; then
320 if [ ! -e libopencm3-${LIBOPENCM3}.tar.bz2 ]; then
321 log "Cloning libopencm3 sources..."
322 git clone git://libopencm3.git.sourceforge.net/gitroot/libopencm3/libopencm3
324 git archive --format=tar --prefix=libopencm3-${LIBOPENCM3}/ ${LIBOPENCM3} | \
325 bzip2 --stdout > ../libopencm3-${LIBOPENCM3}.tar.bz2
333 if [ ! -e build ]; then
337 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
339 log "Patching binutils to allow SVC support on cortex-m3"
341 patch -p1 -i ../patches/patch-binutils-2.21.1-svc-cortexm3.diff
344 log "Configuring ${BINUTILS}"
345 ../${BINUTILS}/configure --target=${TARGET} \
354 log "Building ${BINUTILS}"
356 install ${BINUTILS} install
358 log "Cleaning up ${BINUTILS}"
359 touch ${STAMPS}/${BINUTILS}.build
360 rm -rf build/* ${BINUTILS}
363 if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.build ]; then
367 log "Adding newlib symlink to gcc"
368 ln -f -s `pwd`/${NEWLIB}/newlib ${GCC}
369 log "Adding libgloss symlink to gcc"
370 ln -f -s `pwd`/${NEWLIB}/libgloss ${GCC}
372 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
373 log "Patching gcc to add multilib support"
375 patch -p0 -i ../patches/patch-gcc-config-arm-t-arm-elf.diff
380 if [ "X${GCC_CC}" != "X" ] ; then
381 export GLOBAL_CC=${CC}
382 log "Overriding the default compiler with: \"${GCC_CC}\""
386 log "Configuring ${GCC} and ${NEWLIB}"
387 ../${GCC}/configure --target=${TARGET} \
391 --enable-languages="c,c++" \
398 --with-headers=newlib/libc/include \
400 --disable-libstdcxx-pch \
401 --disable-libmudflap \
405 --disable-newlib-supplied-syscalls \
407 log "Building ${GCC} and ${NEWLIB}"
409 install ${GCC} install
411 log "Cleaning up ${GCC} and ${NEWLIB}"
413 if [ "X${GCC_CC}" != "X" ] ; then
419 touch ${STAMPS}/${GCC}-${NEWLIB}.build
420 rm -rf build/* ${GCC} ${NEWLIB}
423 if [ ! -e ${STAMPS}/${GDB}.build ]; then
426 log "Configuring ${GDB}"
427 ../${GDB}/configure --target=${TARGET} \
433 log "Building ${GDB}"
435 install ${GDB} install
437 log "Cleaning up ${GDB}"
438 touch ${STAMPS}/${GDB}.build
439 rm -rf build/* ${GDB}
442 if [ ${OOCD_EN} != 0 ]; then
443 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
444 unpack openocd-${OOCD}
446 log "Configuring openocd-${OOCD}"
447 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
448 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
449 ../openocd-${OOCD}/configure --enable-maintainer-mode \
453 --enable-ft2232_libftdi \
454 --enable-usb_blaster_libftdi \
456 --enable-at91rm9200 \
457 --enable-presto_libftdi \
463 log "Building openocd-${OOCD}"
465 install openocd-${OOCD} install
467 log "Cleaning up openocd-${OOCD}"
468 touch ${STAMPS}/openocd-${OOCD}.build
469 rm -rf build/* ${OOCD}
473 if [ ${LIBSTM32_EN} != 0 ]; then
474 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
475 unpack libcmsis-${LIBCMSIS}
476 cd libcmsis-${LIBCMSIS}
477 log "Building libcmsis-${LIBCMSIS}"
478 make arch_prefix=${TARGET} prefix=${PREFIX}
479 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
481 log "Cleaning up libcmsis-${LIBCMSIS}"
482 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
483 rm -rf libcmsis-${LIBCMSIS}
486 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
487 unpack libstm32-${LIBSTM32}
488 cd libstm32-${LIBSTM32}
489 log "Building libstm32-${LIBSTM32}"
490 make arch_prefix=${TARGET} prefix=${PREFIX}
491 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
493 log "Cleaning up libstm32-${LIBSTM32}"
494 touch ${STAMPS}/libstm32-${LIBSTM32}.build
495 rm -rf libstm32-${LIBSTM32}
498 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
499 unpack libstm32usb-${LIBSTM32USB}
500 cd libstm32usb-${LIBSTM32USB}
501 log "Building libstm32usb-${LIBSTM32USB}"
502 make arch_prefix=${TARGET} prefix=${PREFIX}
503 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
505 log "Cleaning up libstm32usb-${LIBSTM32USB}"
506 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
507 rm -rf libstm32usb-${LIBSTM32USB}
511 if [ $LIBOPENCM3_EN != 0 ]; then
512 if [ ! -e ${STAMPS}/libopencm3-${LIBOPENCM3}.build ]; then
513 unpack libopencm3-${LIBOPENCM3}
514 cd libopencm3-${LIBOPENCM3}
515 log "Building libopencm3-${LIBOPENCM3}"
516 make PREFIX=${TARGET} DESTDIR=${PREFIX}
517 install libopencm3-${LIBOPENCM3} PREFIX=${TARGET} DESTDIR=${PREFIX} install
519 log "Cleaning up libopencm3-${LIBOPENCM3}"
520 touch ${STAMPS}/libopencm3-${LIBOPENCM3}.build
521 rm -rf libopencm3-${LIBOPENCM3}