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
40 ##############################################################################
41 # Parsing command line parameters
42 ##############################################################################
44 while [ $# -gt 0 ]; do
47 TARGET=$(echo $1 | sed 's,^TARGET=,,')
50 PREFIX=$(echo $1 | sed 's,^PREFIX=,,')
53 DARWIN_OPT_PATH=$(echo $1 | sed 's,^DARWIN_OPT_PATH=,,')
56 SUDO=$(echo $1 | sed 's,^SUDO=,,')
59 QUIET=$(echo $1 | sed 's,^QUIET=,,')
62 USE_LINARO=$(echo $1 | sed 's,^USE_LINARO=,,')
65 OOCD_EN=$(echo $1 | sed 's,^OOCD_EN=,,')
68 LIBSTM32_EN=$(echo $1 | sed 's,^LIBSTM32_EN=,,')
71 LIBOPENSTM32_EN=$(echo $1 | sed 's,^LIBOPENSTM32_EN=,,')
73 DEFAULT_TO_CORTEX_M3=*)
74 DEFAULT_TO_CORTEX_M3=$(echo $1 | sed 's,^DEFAULT_TO_CORTEX_M3=,,')
77 echo "Unknown parameter: $1"
82 shift # shifting parameter list to access the next one
85 echo "Settings used for this build are:"
88 echo "DARWIN_OPT_PATH=$DARWIN_OPT_PATH"
91 echo "USE_LINARO=$USE_LINARO"
92 echo "OOCD_EN=$OOCD_EN"
93 echo "LIBSTM32_EN=$LIBSTM32_EN"
94 echo "LIBOPENSTM32_EN=$LIBOPENSTM32_EN"
95 echo "DEFAULT_TO_CORTEX_M3=$DEFAULT_TO_CORTEX_M3"
97 ##############################################################################
98 # Version and download url settings section
99 ##############################################################################
100 if [ ${USE_LINARO} == 0 ] ; then
103 GCC=gcc-${GCCVERSION}
104 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
106 # For the Linaro GCC:
107 GCCRELEASE=4.5-2011.02-0
108 GCCVERSION=4.5-2011.02-0
109 GCC=gcc-linaro-${GCCVERSION}
110 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
113 BINUTILS=binutils-2.21
122 ##############################################################################
124 ##############################################################################
126 if which getconf > /dev/null; then
127 CPUS=$(getconf _NPROCESSORS_ONLN)
131 PARALLEL=-j$((CPUS + 1))
132 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
137 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
140 # To default to the Cortex-M3:
141 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
144 # Pull in the local configuration, if any
145 if [ -f local.sh ]; then
149 MAKEFLAGS=${PARALLEL}
152 if [ ${QUIET} != 0 ]; then
154 MAKEFLAGS="${MAKEFLAGS} -s"
157 export PATH="${PREFIX}/bin:${PATH}"
160 SOURCES=${SUMMON_DIR}/sources
161 STAMPS=${SUMMON_DIR}/stamps
164 ##############################################################################
166 ##############################################################################
169 ##############################################################################
170 # OS and Tooldetection section
171 # Detects which tools and flags to use
172 ##############################################################################
176 echo "Found Linux OS."
179 echo "Found Darwin OS."
180 GCCFLAGS="${GCCFLAGS} \
181 --with-gmp=${DARWIN_OPT_PATH} \
182 --with-mpfr=${DARWIN_OPT_PATH} \
183 --with-mpc=${DARWIN_OPT_PATH} \
184 --with-libiconv-prefix=${DARWIN_OPT_PATH}"
185 OOCD_CFLAGS="-I/opt/mine/include -I/opt/local/include"
186 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
189 echo "Found CygWin that means Windows most likely."
192 echo "Found unknown OS. Aborting!"
197 ##############################################################################
199 # You probably don't have to touch anything after this
200 ##############################################################################
202 # Fetch a versioned file from a URL
204 if [ ! -e ${STAMPS}/$1.fetch ]; then
205 log "Downloading $1 sources..."
206 wget -c --no-passive-ftp $2
207 touch ${STAMPS}/$1.fetch
211 # Log a message out to the console
213 echo "******************************************************************"
215 echo "******************************************************************"
221 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
222 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
225 echo "archive type bz2"
229 echo "archive type gz"
233 echo "Unknown archive type of $1"
238 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
244 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
248 mkdir -p ${STAMPS} ${SOURCES}
252 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
253 fetch ${GCC} ${GCCURL}
254 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
255 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
257 if [ ${OOCD_EN} != 0 ]; then
258 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
259 log "Cloning OpenOCD sources..."
260 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
264 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
265 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
266 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
267 rm -rf openocd-${OOCD}
271 if [ ${LIBSTM32_EN} != 0 ]; then
272 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
273 log "Cloning libcmsis sources..."
274 git clone git://git.open-bldc.org/libcmsis.git
276 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
277 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
282 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
283 log "Cloning libstm32 sources..."
284 git clone git://git.open-bldc.org/libstm32.git
286 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
287 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
292 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
293 log "Cloning libstm32usb sources..."
294 git clone git://git.open-bldc.org/libstm32usb.git
296 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
297 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
303 if [ ${LIBOPENSTM32_EN} != 0 ]; then
304 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
305 log "Cloning libopenstm32 sources..."
306 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
308 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
309 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
317 if [ ! -e build ]; then
321 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
324 log "Configuring ${BINUTILS}"
325 ../${BINUTILS}/configure --target=${TARGET} \
334 log "Building ${BINUTILS}"
336 install ${BINUTILS} install
338 log "Cleaning up ${BINUTILS}"
339 touch ${STAMPS}/${BINUTILS}.build
340 rm -rf build/* ${BINUTILS}
343 if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.build ]; then
347 log "Adding newlib symlink to gcc"
348 ln -f -s `pwd`/${NEWLIB}/newlib ${GCC}
349 log "Adding libgloss symlink to gcc"
350 ln -f -s `pwd`/${NEWLIB}/libgloss ${GCC}
352 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
353 log "Patching gcc to add multilib support"
355 patch -p0 -i ../patches/patch-gcc-config-arm-t-arm-elf.diff
360 log "Configuring ${GCC} and ${NEWLIB}"
361 ../${GCC}/configure --target=${TARGET} \
365 --enable-languages="c,c++" \
372 --with-headers=newlib/libc/include \
374 --disable-libstdcxx-pch \
375 --disable-libmudflap \
379 --disable-newlib-supplied-syscalls \
381 log "Building ${GCC} and ${NEWLIB}"
383 install ${GCC} install
385 log "Cleaning up ${GCC} and ${NEWLIB}"
386 touch ${STAMPS}/${GCC}-${NEWLIB}.build
387 rm -rf build/* ${GCC} ${NEWLIB}
390 if [ ! -e ${STAMPS}/${GDB}.build ]; then
393 log "Configuring ${GDB}"
394 ../${GDB}/configure --target=${TARGET} \
400 log "Building ${GDB}"
402 install ${GDB} install
404 log "Cleaning up ${GDB}"
405 touch ${STAMPS}/${GDB}.build
406 rm -rf build/* ${GDB}
409 if [ ${OOCD_EN} != 0 ]; then
410 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
411 unpack openocd-${OOCD}
413 log "Configuring openocd-${OOCD}"
414 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
415 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
416 ../openocd-${OOCD}/configure --enable-maintainer-mode \
419 --enable-ft2232_libftdi \
420 --enable-usb_blaster_libftdi \
422 --enable-at91rm9200 \
423 --enable-presto_libftdi \
429 log "Building openocd-${OOCD}"
431 install openocd-${OOCD} install
433 log "Cleaning up openocd-${OOCD}"
434 touch ${STAMPS}/openocd-${OOCD}.build
435 rm -rf build/* ${OOCD}
439 if [ ${LIBSTM32_EN} != 0 ]; then
440 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
441 unpack libcmsis-${LIBCMSIS}
442 cd libcmsis-${LIBCMSIS}
443 log "Building libcmsis-${LIBCMSIS}"
444 make arch_prefix=${TARGET} prefix=${PREFIX}
445 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
447 log "Cleaning up libcmsis-${LIBCMSIS}"
448 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
449 rm -rf libcmsis-${LIBCMSIS}
452 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
453 unpack libstm32-${LIBSTM32}
454 cd libstm32-${LIBSTM32}
455 log "Building libstm32-${LIBSTM32}"
456 make arch_prefix=${TARGET} prefix=${PREFIX}
457 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
459 log "Cleaning up libstm32-${LIBSTM32}"
460 touch ${STAMPS}/libstm32-${LIBSTM32}.build
461 rm -rf libstm32-${LIBSTM32}
464 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
465 unpack libstm32usb-${LIBSTM32USB}
466 cd libstm32usb-${LIBSTM32USB}
467 log "Building libstm32usb-${LIBSTM32USB}"
468 make arch_prefix=${TARGET} prefix=${PREFIX}
469 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
471 log "Cleaning up libstm32usb-${LIBSTM32USB}"
472 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
473 rm -rf libstm32usb-${LIBSTM32USB}
477 if [ $LIBOPENSTM32_EN != 0 ]; then
478 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
479 unpack libopenstm32-${LIBOPENSTM32}
480 cd libopenstm32-${LIBOPENSTM32}
481 log "Building libopenstm32-${LIBOPENSTM32}"
482 make PREFIX=${TARGET} DESTDIR=${PREFIX}
483 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
485 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
486 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
487 rm -rf libopenstm32-${LIBOPENSTM32}