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 ##############################################################################
19 # You probably want to customize those
20 ##############################################################################
21 TARGET=arm-none-eabi # Or: TARGET=arm-elf
22 PREFIX=${HOME}/sat # Install location of your final toolchain
23 DARWIN_OPT_PATH=/opt/local # Path in which MacPorts or Fink is installed
24 # Set to 'sudo' if you need superuser privileges while installing
26 # Set to 1 to be quieter while running
28 # Set to 1 to use linaro gcc instead of the FSF gcc
30 # Set to 1 to enable building of OpenOCD
32 # Set to 1 to build libstm32 provided by ST
34 # Set to 1 to build libopenstm32 an open source library for stm32
36 # Make the gcc default to Cortex-M3
37 DEFAULT_TO_CORTEX_M3=0
39 ##############################################################################
40 # Version and download url settings section
41 ##############################################################################
42 if [ ${USE_LINARO} == 0 ] ; then
46 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
49 GCCRELEASE=4.5-2010.11-0
50 GCCVERSION=4.5-2010.11-1
51 GCC=gcc-linaro-${GCCVERSION}
52 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
55 BINUTILS=binutils-2.20
64 ##############################################################################
66 ##############################################################################
68 if which getconf > /dev/null; then
69 CPUS=$(getconf _NPROCESSORS_ONLN)
73 PARALLEL=-j$((CPUS + 1))
74 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
79 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
82 # To default to the Cortex-M3:
83 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
86 # Pull in the local configuration, if any
87 if [ -f local.sh ]; then
94 if [ ${QUIET} != 0 ]; then
96 MAKEFLAGS="${MAKEFLAGS} -s"
99 export PATH="${PREFIX}/bin:${PATH}"
102 SOURCES=${SUMMON_DIR}/sources
103 STAMPS=${SUMMON_DIR}/stamps
106 ##############################################################################
108 ##############################################################################
111 ##############################################################################
112 # OS and Tooldetection section
113 # Detects which tools and flags to use
114 ##############################################################################
118 echo "Found Linux OS."
121 echo "Found Darwin OS."
122 GCCFLAGS="${GCCFLAGS} \
123 --with-gmp=${DARWIN_OPT_PATH} \
124 --with-mpfr=${DARWIN_OPT_PATH} \
125 --with-mpc=${DARWIN_OPT_PATH} \
126 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
127 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
128 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
131 echo "Found CygWin that means Windows most likely."
134 echo "Found unknown OS. Aborting!"
139 ##############################################################################
141 # You probably don't have to touch anything after this
142 ##############################################################################
144 # Fetch a versioned file from a URL
146 if [ ! -e ${STAMPS}/$1.fetch ]; then
147 log "Downloading $1 sources..."
148 wget -c --no-passive-ftp $2
149 touch ${STAMPS}/$1.fetch
153 # Log a message out to the console
155 echo "******************************************************************"
157 echo "******************************************************************"
163 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
164 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
167 echo "archive type bz2"
171 echo "archive type gz"
175 echo "Unknown archive type of $1"
180 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
186 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
190 mkdir -p ${STAMPS} ${SOURCES}
194 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
195 fetch ${GCC} ${GCCURL}
196 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
197 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
199 if [ ${OOCD_EN} != 0 ]; then
200 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
201 log "Cloning OpenOCD sources..."
202 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
206 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
207 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
208 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
209 rm -rf openocd-${OOCD}
213 if [ ${LIBSTM32_EN} != 0 ]; then
214 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
215 log "Cloning libcmsis sources..."
216 git clone git://git.open-bldc.org/libcmsis.git
218 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
219 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
224 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
225 log "Cloning libstm32 sources..."
226 git clone git://git.open-bldc.org/libstm32.git
228 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
229 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
234 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
235 log "Cloning libstm32usb sources..."
236 git clone git://git.open-bldc.org/libstm32usb.git
238 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
239 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
245 if [ ${LIBOPENSTM32_EN} != 0 ]; then
246 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
247 log "Cloning libopenstm32 sources..."
248 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
250 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
251 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
259 if [ ! -e build ]; then
263 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
266 log "Configuring ${BINUTILS}"
267 ../${BINUTILS}/configure --target=${TARGET} \
276 log "Building ${BINUTILS}"
278 install ${BINUTILS} install
280 log "Cleaning up ${BINUTILS}"
281 touch ${STAMPS}/${BINUTILS}.build
282 rm -rf build/* ${BINUTILS}
285 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
288 log "Configuring ${GCC}-boot"
289 ../${GCC}/configure --target=${TARGET} \
293 --enable-languages="c" \
303 log "Building ${GCC}-boot"
304 make ${MAKEFLAGS} all-gcc
305 install ${GCC}-boot install-gcc
307 log "Cleaning up ${GCC}-boot"
308 touch ${STAMPS}/${GCC}-boot.build
309 rm -rf build/* ${GCC}
312 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
315 log "Configuring ${NEWLIB}"
316 ../${NEWLIB}/configure --target=${TARGET} \
324 --disable-newlib-supplied-syscalls \
326 log "Building ${NEWLIB}"
327 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
328 install ${NEWLIB} install
330 log "Cleaning up ${NEWLIB}"
331 touch ${STAMPS}/${NEWLIB}.build
332 rm -rf build/* ${NEWLIB}
335 # Yes, you need to build gcc again!
336 if [ ! -e ${STAMPS}/${GCC}.build ]; then
339 log "Configuring ${GCC}"
340 ../${GCC}/configure --target=${TARGET} \
344 --enable-languages="c,c++" \
353 log "Building ${GCC}"
355 install ${GCC} install
357 log "Cleaning up ${GCC}"
358 touch ${STAMPS}/${GCC}.build
359 rm -rf build/* ${GCC}
362 if [ ! -e ${STAMPS}/${GDB}.build ]; then
365 log "Configuring ${GDB}"
366 ../${GDB}/configure --target=${TARGET} \
372 log "Building ${GDB}"
374 install ${GDB} install
376 log "Cleaning up ${GDB}"
377 touch ${STAMPS}/${GDB}.build
378 rm -rf build/* ${GDB}
381 if [ ${OOCD_EN} != 0 ]; then
382 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
383 unpack openocd-${OOCD}
385 log "Configuring openocd-${OOCD}"
386 export CFLAGS="${OOCD_CFLAGS}"
387 export LDFLAGS="${OOCD_LDFLAGS}"
388 ../openocd-${OOCD}/configure --enable-maintainer-mode \
392 --enable-ft2232_libftdi \
393 --enable-usb_blaster_libftdi \
394 --enable-amtjtagaccel \
397 --enable-at91rm9200 \
399 --enable-presto_libftdi \
404 --enable-arm-jtag-ew \
406 log "Building openocd-${OOCD}"
408 install openocd-${OOCD} install
410 log "Cleaning up openocd-${OOCD}"
411 touch ${STAMPS}/openocd-${OOCD}.build
412 rm -rf build/* ${OOCD}
416 if [ ${LIBSTM32_EN} != 0 ]; then
417 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
418 unpack libcmsis-${LIBCMSIS}
419 cd libcmsis-${LIBCMSIS}
420 log "Building libcmsis-${LIBCMSIS}"
421 make arch_prefix=${TARGET} prefix=${PREFIX}
422 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
424 log "Cleaning up libcmsis-${LIBCMSIS}"
425 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
426 rm -rf libcmsis-${LIBCMSIS}
429 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
430 unpack libstm32-${LIBSTM32}
431 cd libstm32-${LIBSTM32}
432 log "Building libstm32-${LIBSTM32}"
433 make arch_prefix=${TARGET} prefix=${PREFIX}
434 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
436 log "Cleaning up libstm32-${LIBSTM32}"
437 touch ${STAMPS}/libstm32-${LIBSTM32}.build
438 rm -rf libstm32-${LIBSTM32}
441 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
442 unpack libstm32usb-${LIBSTM32USB}
443 cd libstm32usb-${LIBSTM32USB}
444 log "Building libstm32usb-${LIBSTM32USB}"
445 make arch_prefix=${TARGET} prefix=${PREFIX}
446 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
448 log "Cleaning up libstm32usb-${LIBSTM32USB}"
449 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
450 rm -rf libstm32usb-${LIBSTM32USB}
454 if [ $LIBOPENSTM32_EN != 0 ]; then
455 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
456 unpack libopenstm32-${LIBOPENSTM32}
457 cd libopenstm32-${LIBOPENSTM32}
458 log "Building libopenstm32-${LIBOPENSTM32}"
459 make PREFIX=${TARGET} DESTDIR=${PREFIX}
460 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
462 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
463 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
464 rm -rf libopenstm32-${LIBOPENSTM32}