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 PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
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 build libstm32 provided by ST
33 # Set to 1 to build libopenstm32 an open source library for stm32
35 # Make the gcc default to Cortex-M3
36 DEFAULT_TO_CORTEX_M3=0
38 ##############################################################################
39 # Version and download url settings section
40 ##############################################################################
41 if [ ${USE_LINARO} == 0 ] ; then
45 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
48 GCCVERSION=4.5-2010.08-1
49 GCC=gcc-linaro-${GCCVERSION}
50 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCVERSION}/+download/${GCC}.tar.gz
53 BINUTILS=binutils-2.20
61 ##############################################################################
63 ##############################################################################
68 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
71 # To default to the Cortex-M3:
72 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
75 # Pull in the local configuration, if any
76 if [ -f local.sh ]; then
83 if [ ${QUIET} != 0 ]; then
85 MAKEFLAGS="${MAKEFLAGS} -s"
88 export PATH="${PREFIX}/bin:${PATH}"
91 SOURCES=${SUMMON_DIR}/sources
92 STAMPS=${SUMMON_DIR}/stamps
95 ##############################################################################
97 ##############################################################################
100 ##############################################################################
101 # OS and Tooldetection section
102 # Detects which tools and flags to use
103 ##############################################################################
107 echo "Found Linux OS."
110 echo "Found Darwin OS."
111 GCCFLAGS="${GCCFLAGS} \
112 --with-gmp=${DARWIN_OPT_PATH} \
113 --with-mpfr=${DARWIN_OPT_PATH} \
114 --with-mpc=${DARWIN_OPT_PATH} \
115 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
118 echo "Found unknown OS. Aborting!"
123 ##############################################################################
125 # You probably don't have to touch anything after this
126 ##############################################################################
128 # Fetch a versioned file from a URL
130 if [ ! -e ${STAMPS}/$1.fetch ]; then
131 log "Downloading $1 sources..."
132 wget -c --no-passive-ftp $2
133 touch ${STAMPS}/$1.fetch
137 # Log a message out to the console
139 echo "******************************************************************"
141 echo "******************************************************************"
147 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
148 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
151 echo "archive type bz2"
155 echo "archive type gz"
159 echo "Unknown archive type of $1"
164 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
170 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
174 mkdir -p ${STAMPS} ${SOURCES}
178 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
179 fetch ${GCC} ${GCCURL}
180 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
181 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
183 if [ ${LIBSTM32_EN} != 0 ]; then
184 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
185 log "Cloning libcmsis sources..."
186 git clone git://git.open-bldc.org/libcmsis.git
188 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
189 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
194 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
195 log "Cloning libstm32 sources..."
196 git clone git://git.open-bldc.org/libstm32.git
198 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
199 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
204 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
205 log "Cloning libstm32usb sources..."
206 git clone git://git.open-bldc.org/libstm32usb.git
208 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
209 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
215 if [ ${LIBOPENSTM32_EN} != 0 ]; then
216 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
217 log "Cloning libopenstm32 sources..."
218 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
220 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
221 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
229 if [ ! -e build ]; then
233 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
236 log "Configuring ${BINUTILS}"
237 ../${BINUTILS}/configure --target=${TARGET} \
246 log "Building ${BINUTILS}"
248 install ${BINUTILS} install
250 log "Cleaning up ${BINUTILS}"
251 touch ${STAMPS}/${BINUTILS}.build
252 rm -rf build/* ${BINUTILS}
255 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
258 log "Configuring ${GCC}-boot"
259 ../${GCC}/configure --target=${TARGET} \
263 --enable-languages="c" \
273 log "Building ${GCC}-boot"
274 make ${MAKEFLAGS} all-gcc
275 install ${GCC}-boot install-gcc
277 log "Cleaning up ${GCC}-boot"
278 touch ${STAMPS}/${GCC}-boot.build
279 rm -rf build/* ${GCC}
282 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
285 log "Configuring ${NEWLIB}"
286 ../${NEWLIB}/configure --target=${TARGET} \
294 --disable-newlib-supplied-syscalls \
296 log "Building ${NEWLIB}"
297 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
298 install ${NEWLIB} install
300 log "Cleaning up ${NEWLIB}"
301 touch ${STAMPS}/${NEWLIB}.build
302 rm -rf build/* ${NEWLIB}
305 # Yes, you need to build gcc again!
306 if [ ! -e ${STAMPS}/${GCC}.build ]; then
309 log "Configuring ${GCC}"
310 ../${GCC}/configure --target=${TARGET} \
314 --enable-languages="c,c++" \
323 log "Building ${GCC}"
325 install ${GCC} install
327 log "Cleaning up ${GCC}"
328 touch ${STAMPS}/${GCC}.build
329 rm -rf build/* ${GCC}
332 if [ ! -e ${STAMPS}/${GDB}.build ]; then
335 log "Configuring ${GDB}"
336 ../${GDB}/configure --target=${TARGET} \
342 log "Building ${GDB}"
344 install ${GDB} install
346 log "Cleaning up ${GDB}"
347 touch ${STAMPS}/${GDB}.build
348 rm -rf build/* ${GDB}
351 if [ ${LIBSTM32_EN} != 0 ]; then
352 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
353 unpack libcmsis-${LIBCMSIS}
354 cd libcmsis-${LIBCMSIS}
355 log "Building libcmsis-${LIBCMSIS}"
356 make arch_prefix=${TARGET} prefix=${PREFIX}
357 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
359 log "Cleaning up libcmsis-${LIBCMSIS}"
360 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
361 rm -rf libcmsis-${LIBCMSIS}
364 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
365 unpack libstm32-${LIBSTM32}
366 cd libstm32-${LIBSTM32}
367 log "Building libstm32-${LIBSTM32}"
368 make arch_prefix=${TARGET} prefix=${PREFIX}
369 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
371 log "Cleaning up libstm32-${LIBSTM32}"
372 touch ${STAMPS}/libstm32-${LIBSTM32}.build
373 rm -rf libstm32-${LIBSTM32}
376 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
377 unpack libstm32usb-${LIBSTM32USB}
378 cd libstm32usb-${LIBSTM32USB}
379 log "Building libstm32usb-${LIBSTM32USB}"
380 make arch_prefix=${TARGET} prefix=${PREFIX}
381 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
383 log "Cleaning up libstm32usb-${LIBSTM32USB}"
384 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
385 rm -rf libstm32usb-${LIBSTM32USB}
389 if [ $LIBOPENSTM32_EN != 0 ]; then
390 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
391 unpack libopenstm32-${LIBOPENSTM32}
392 cd libopenstm32-${LIBOPENSTM32}
393 log "Building libopenstm32-${LIBOPENSTM32}"
394 make PREFIX=${TARGET} DESTDIR=${PREFIX}
395 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
397 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
398 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
399 rm -rf libopenstm32-${LIBOPENSTM32}