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 libopenstm32 an open source library for stm32
37 # Make the gcc default to Cortex-M3
38 DEFAULT_TO_CORTEX_M3=0
39 # Override automatic detection of cpus to compile on
42 ##############################################################################
43 # Parsing command line parameters
44 ##############################################################################
46 while [ $# -gt 0 ]; do
49 TARGET=$(echo $1 | sed 's,^TARGET=,,')
52 PREFIX=$(echo $1 | sed 's,^PREFIX=,,')
55 DARWIN_OPT_PATH=$(echo $1 | sed 's,^DARWIN_OPT_PATH=,,')
58 SUDO=$(echo $1 | sed 's,^SUDO=,,')
61 QUIET=$(echo $1 | sed 's,^QUIET=,,')
64 USE_LINARO=$(echo $1 | sed 's,^USE_LINARO=,,')
67 OOCD_EN=$(echo $1 | sed 's,^OOCD_EN=,,')
70 LIBSTM32_EN=$(echo $1 | sed 's,^LIBSTM32_EN=,,')
73 LIBOPENSTM32_EN=$(echo $1 | sed 's,^LIBOPENSTM32_EN=,,')
75 DEFAULT_TO_CORTEX_M3=*)
76 DEFAULT_TO_CORTEX_M3=$(echo $1 | sed 's,^DEFAULT_TO_CORTEX_M3=,,')
79 CPUS=$(echo $1 | sed 's,^CPUS=,,')
82 echo "Unknown parameter: $1"
87 shift # shifting parameter list to access the next one
90 echo "Settings used for this build are:"
93 echo "DARWIN_OPT_PATH=$DARWIN_OPT_PATH"
96 echo "USE_LINARO=$USE_LINARO"
97 echo "OOCD_EN=$OOCD_EN"
98 echo "LIBSTM32_EN=$LIBSTM32_EN"
99 echo "LIBOPENSTM32_EN=$LIBOPENSTM32_EN"
100 echo "DEFAULT_TO_CORTEX_M3=$DEFAULT_TO_CORTEX_M3"
103 ##############################################################################
104 # Version and download url settings section
105 ##############################################################################
106 if [ ${USE_LINARO} == 0 ] ; then
109 GCC=gcc-${GCCVERSION}
110 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
112 # For the Linaro GCC:
113 GCCRELEASE=4.5-2011.02-0
114 GCCVERSION=4.5-2011.02-0
115 GCC=gcc-linaro-${GCCVERSION}
116 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
119 BINUTILS=binutils-2.21.1
128 ##############################################################################
130 ##############################################################################
132 if [ "x${CPUS}" == "x" ]; then
133 if which getconf > /dev/null; then
134 CPUS=$(getconf _NPROCESSORS_ONLN)
139 PARALLEL=-j$((CPUS + 1))
144 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
149 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
152 # To default to the Cortex-M3:
153 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
156 # Pull in the local configuration, if any
157 if [ -f local.sh ]; then
161 MAKEFLAGS=${PARALLEL}
164 if [ ${QUIET} != 0 ]; then
166 MAKEFLAGS="${MAKEFLAGS} -s"
169 export PATH="${PREFIX}/bin:${PATH}"
172 SOURCES=${SUMMON_DIR}/sources
173 STAMPS=${SUMMON_DIR}/stamps
176 ##############################################################################
178 ##############################################################################
181 ##############################################################################
182 # OS and Tooldetection section
183 # Detects which tools and flags to use
184 ##############################################################################
188 echo "Found Linux OS."
191 echo "Found Darwin OS."
192 GCCFLAGS="${GCCFLAGS} \
193 --with-gmp=${DARWIN_OPT_PATH} \
194 --with-mpfr=${DARWIN_OPT_PATH} \
195 --with-mpc=${DARWIN_OPT_PATH} \
196 --with-libiconv-prefix=${DARWIN_OPT_PATH}"
197 OOCD_CFLAGS="-I/opt/mine/include -I/opt/local/include"
198 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
199 if gcc --version | grep llvm-gcc > /dev/null ; then
200 echo "Found you are using llvm gcc, switching to clang for gcc compile."
205 echo "Found CygWin that means Windows most likely."
208 echo "Found unknown OS. Aborting!"
213 ##############################################################################
215 # You probably don't have to touch anything after this
216 ##############################################################################
218 # Fetch a versioned file from a URL
220 if [ ! -e ${STAMPS}/$1.fetch ]; then
221 log "Downloading $1 sources..."
222 wget -c --no-passive-ftp $2 && touch ${STAMPS}/$1.fetch
226 # Log a message out to the console
228 echo "******************************************************************"
230 echo "******************************************************************"
236 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
237 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
240 echo "archive type bz2"
244 echo "archive type gz"
248 echo "Unknown archive type of $1"
253 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
259 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
263 mkdir -p ${STAMPS} ${SOURCES}
267 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
268 fetch ${GCC} ${GCCURL}
269 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
270 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
272 if [ ${OOCD_EN} != 0 ]; then
273 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
274 log "Cloning OpenOCD sources..."
275 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
279 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
280 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
281 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
282 rm -rf openocd-${OOCD}
286 if [ ${LIBSTM32_EN} != 0 ]; then
287 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
288 log "Cloning libcmsis sources..."
289 git clone git://git.open-bldc.org/libcmsis.git
291 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
292 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
297 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
298 log "Cloning libstm32 sources..."
299 git clone git://git.open-bldc.org/libstm32.git
301 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
302 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
307 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
308 log "Cloning libstm32usb sources..."
309 git clone git://git.open-bldc.org/libstm32usb.git
311 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
312 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
318 if [ ${LIBOPENSTM32_EN} != 0 ]; then
319 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
320 log "Cloning libopenstm32 sources..."
321 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
323 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
324 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
332 if [ ! -e build ]; then
336 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
339 log "Configuring ${BINUTILS}"
340 ../${BINUTILS}/configure --target=${TARGET} \
349 log "Building ${BINUTILS}"
351 install ${BINUTILS} install
353 log "Cleaning up ${BINUTILS}"
354 touch ${STAMPS}/${BINUTILS}.build
355 rm -rf build/* ${BINUTILS}
358 if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.build ]; then
362 log "Adding newlib symlink to gcc"
363 ln -f -s `pwd`/${NEWLIB}/newlib ${GCC}
364 log "Adding libgloss symlink to gcc"
365 ln -f -s `pwd`/${NEWLIB}/libgloss ${GCC}
367 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
368 log "Patching gcc to add multilib support"
370 patch -p0 -i ../patches/patch-gcc-config-arm-t-arm-elf.diff
375 if [ "X${GCC_CC}" != "X" ] ; then
376 export GLOBAL_CC=${CC}
377 log "Overriding the default compiler with: \"${GCC_CC}\""
381 log "Configuring ${GCC} and ${NEWLIB}"
382 ../${GCC}/configure --target=${TARGET} \
386 --enable-languages="c,c++" \
393 --with-headers=newlib/libc/include \
395 --disable-libstdcxx-pch \
396 --disable-libmudflap \
400 --disable-newlib-supplied-syscalls \
402 log "Building ${GCC} and ${NEWLIB}"
404 install ${GCC} install
406 log "Cleaning up ${GCC} and ${NEWLIB}"
408 if [ "X${GCC_CC}" != "X" ] ; then
414 touch ${STAMPS}/${GCC}-${NEWLIB}.build
415 rm -rf build/* ${GCC} ${NEWLIB}
418 if [ ! -e ${STAMPS}/${GDB}.build ]; then
421 log "Configuring ${GDB}"
422 ../${GDB}/configure --target=${TARGET} \
428 log "Building ${GDB}"
430 install ${GDB} install
432 log "Cleaning up ${GDB}"
433 touch ${STAMPS}/${GDB}.build
434 rm -rf build/* ${GDB}
437 if [ ${OOCD_EN} != 0 ]; then
438 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
439 unpack openocd-${OOCD}
441 log "Configuring openocd-${OOCD}"
442 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
443 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
444 ../openocd-${OOCD}/configure --enable-maintainer-mode \
447 --enable-ft2232_libftdi \
448 --enable-usb_blaster_libftdi \
450 --enable-at91rm9200 \
451 --enable-presto_libftdi \
457 log "Building openocd-${OOCD}"
459 install openocd-${OOCD} install
461 log "Cleaning up openocd-${OOCD}"
462 touch ${STAMPS}/openocd-${OOCD}.build
463 rm -rf build/* ${OOCD}
467 if [ ${LIBSTM32_EN} != 0 ]; then
468 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
469 unpack libcmsis-${LIBCMSIS}
470 cd libcmsis-${LIBCMSIS}
471 log "Building libcmsis-${LIBCMSIS}"
472 make arch_prefix=${TARGET} prefix=${PREFIX}
473 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
475 log "Cleaning up libcmsis-${LIBCMSIS}"
476 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
477 rm -rf libcmsis-${LIBCMSIS}
480 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
481 unpack libstm32-${LIBSTM32}
482 cd libstm32-${LIBSTM32}
483 log "Building libstm32-${LIBSTM32}"
484 make arch_prefix=${TARGET} prefix=${PREFIX}
485 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
487 log "Cleaning up libstm32-${LIBSTM32}"
488 touch ${STAMPS}/libstm32-${LIBSTM32}.build
489 rm -rf libstm32-${LIBSTM32}
492 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
493 unpack libstm32usb-${LIBSTM32USB}
494 cd libstm32usb-${LIBSTM32USB}
495 log "Building libstm32usb-${LIBSTM32USB}"
496 make arch_prefix=${TARGET} prefix=${PREFIX}
497 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
499 log "Cleaning up libstm32usb-${LIBSTM32USB}"
500 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
501 rm -rf libstm32usb-${LIBSTM32USB}
505 if [ $LIBOPENSTM32_EN != 0 ]; then
506 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
507 unpack libopenstm32-${LIBOPENSTM32}
508 cd libopenstm32-${LIBOPENSTM32}
509 log "Building libopenstm32-${LIBOPENSTM32}"
510 make PREFIX=${TARGET} DESTDIR=${PREFIX}
511 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
513 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
514 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
515 rm -rf libopenstm32-${LIBOPENSTM32}