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"
98 ##############################################################################
99 # Version and download url settings section
100 ##############################################################################
101 if [ ${USE_LINARO} == 0 ] ; then
104 GCC=gcc-${GCCVERSION}
105 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
107 # For the Linaro GCC:
108 GCCRELEASE=4.5-2011.02-0
109 GCCVERSION=4.5-2011.02-0
110 GCC=gcc-linaro-${GCCVERSION}
111 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
114 BINUTILS=binutils-2.21
123 ##############################################################################
125 ##############################################################################
127 if which getconf > /dev/null; then
128 CPUS=$(getconf _NPROCESSORS_ONLN)
132 PARALLEL=-j$((CPUS + 1))
133 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
138 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
141 # To default to the Cortex-M3:
142 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
145 # Pull in the local configuration, if any
146 if [ -f local.sh ]; then
150 MAKEFLAGS=${PARALLEL}
153 if [ ${QUIET} != 0 ]; then
155 MAKEFLAGS="${MAKEFLAGS} -s"
158 export PATH="${PREFIX}/bin:${PATH}"
161 SOURCES=${SUMMON_DIR}/sources
162 STAMPS=${SUMMON_DIR}/stamps
165 ##############################################################################
167 ##############################################################################
170 ##############################################################################
171 # OS and Tooldetection section
172 # Detects which tools and flags to use
173 ##############################################################################
177 echo "Found Linux OS."
180 echo "Found Darwin OS."
181 GCCFLAGS="${GCCFLAGS} \
182 --with-gmp=${DARWIN_OPT_PATH} \
183 --with-mpfr=${DARWIN_OPT_PATH} \
184 --with-mpc=${DARWIN_OPT_PATH} \
185 --with-libiconv-prefix=${DARWIN_OPT_PATH}"
186 OOCD_CFLAGS="-I/opt/mine/include -I/opt/local/include"
187 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
190 echo "Found CygWin that means Windows most likely."
193 echo "Found unknown OS. Aborting!"
198 ##############################################################################
200 # You probably don't have to touch anything after this
201 ##############################################################################
203 # Fetch a versioned file from a URL
205 if [ ! -e ${STAMPS}/$1.fetch ]; then
206 log "Downloading $1 sources..."
207 wget -c --no-passive-ftp $2
208 touch ${STAMPS}/$1.fetch
212 # Log a message out to the console
214 echo "******************************************************************"
216 echo "******************************************************************"
222 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
223 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
226 echo "archive type bz2"
230 echo "archive type gz"
234 echo "Unknown archive type of $1"
239 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
245 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
249 mkdir -p ${STAMPS} ${SOURCES}
253 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
254 fetch ${GCC} ${GCCURL}
255 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
256 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
258 if [ ${OOCD_EN} != 0 ]; then
259 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
260 log "Cloning OpenOCD sources..."
261 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
265 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
266 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
267 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
268 rm -rf openocd-${OOCD}
272 if [ ${LIBSTM32_EN} != 0 ]; then
273 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
274 log "Cloning libcmsis sources..."
275 git clone git://git.open-bldc.org/libcmsis.git
277 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
278 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
283 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
284 log "Cloning libstm32 sources..."
285 git clone git://git.open-bldc.org/libstm32.git
287 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
288 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
293 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
294 log "Cloning libstm32usb sources..."
295 git clone git://git.open-bldc.org/libstm32usb.git
297 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
298 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
304 if [ ${LIBOPENSTM32_EN} != 0 ]; then
305 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
306 log "Cloning libopenstm32 sources..."
307 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
309 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
310 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
318 if [ ! -e build ]; then
322 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
325 log "Configuring ${BINUTILS}"
326 ../${BINUTILS}/configure --target=${TARGET} \
335 log "Building ${BINUTILS}"
337 install ${BINUTILS} install
339 log "Cleaning up ${BINUTILS}"
340 touch ${STAMPS}/${BINUTILS}.build
341 rm -rf build/* ${BINUTILS}
344 if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.build ]; then
348 log "Adding newlib symlink to gcc"
349 ln -f -s `pwd`/${NEWLIB}/newlib ${GCC}
350 log "Adding libgloss symlink to gcc"
351 ln -f -s `pwd`/${NEWLIB}/libgloss ${GCC}
353 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
354 log "Patching gcc to add multilib support"
356 patch -p0 -i ../patches/patch-gcc-config-arm-t-arm-elf.diff
361 log "Configuring ${GCC} and ${NEWLIB}"
362 ../${GCC}/configure --target=${TARGET} \
366 --enable-languages="c,c++" \
373 --with-headers=newlib/libc/include \
375 --disable-libstdcxx-pch \
376 --disable-libmudflap \
380 --disable-newlib-supplied-syscalls \
382 log "Building ${GCC} and ${NEWLIB}"
384 install ${GCC} install
386 log "Cleaning up ${GCC} and ${NEWLIB}"
387 touch ${STAMPS}/${GCC}-${NEWLIB}.build
388 rm -rf build/* ${GCC} ${NEWLIB}
391 if [ ! -e ${STAMPS}/${GDB}.build ]; then
394 log "Configuring ${GDB}"
395 ../${GDB}/configure --target=${TARGET} \
401 log "Building ${GDB}"
403 install ${GDB} install
405 log "Cleaning up ${GDB}"
406 touch ${STAMPS}/${GDB}.build
407 rm -rf build/* ${GDB}
410 if [ ${OOCD_EN} != 0 ]; then
411 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
412 unpack openocd-${OOCD}
414 log "Configuring openocd-${OOCD}"
415 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
416 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
417 ../openocd-${OOCD}/configure --enable-maintainer-mode \
420 --enable-ft2232_libftdi \
421 --enable-usb_blaster_libftdi \
423 --enable-at91rm9200 \
424 --enable-presto_libftdi \
430 log "Building openocd-${OOCD}"
432 install openocd-${OOCD} install
434 log "Cleaning up openocd-${OOCD}"
435 touch ${STAMPS}/openocd-${OOCD}.build
436 rm -rf build/* ${OOCD}
440 if [ ${LIBSTM32_EN} != 0 ]; then
441 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
442 unpack libcmsis-${LIBCMSIS}
443 cd libcmsis-${LIBCMSIS}
444 log "Building libcmsis-${LIBCMSIS}"
445 make arch_prefix=${TARGET} prefix=${PREFIX}
446 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
448 log "Cleaning up libcmsis-${LIBCMSIS}"
449 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
450 rm -rf libcmsis-${LIBCMSIS}
453 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
454 unpack libstm32-${LIBSTM32}
455 cd libstm32-${LIBSTM32}
456 log "Building libstm32-${LIBSTM32}"
457 make arch_prefix=${TARGET} prefix=${PREFIX}
458 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
460 log "Cleaning up libstm32-${LIBSTM32}"
461 touch ${STAMPS}/libstm32-${LIBSTM32}.build
462 rm -rf libstm32-${LIBSTM32}
465 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
466 unpack libstm32usb-${LIBSTM32USB}
467 cd libstm32usb-${LIBSTM32USB}
468 log "Building libstm32usb-${LIBSTM32USB}"
469 make arch_prefix=${TARGET} prefix=${PREFIX}
470 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
472 log "Cleaning up libstm32usb-${LIBSTM32USB}"
473 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
474 rm -rf libstm32usb-${LIBSTM32USB}
478 if [ $LIBOPENSTM32_EN != 0 ]; then
479 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
480 unpack libopenstm32-${LIBOPENSTM32}
481 cd libopenstm32-${LIBOPENSTM32}
482 log "Building libopenstm32-${LIBOPENSTM32}"
483 make PREFIX=${TARGET} DESTDIR=${PREFIX}
484 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
486 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
487 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
488 rm -rf libopenstm32-${LIBOPENSTM32}