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 build libstm32 provided by ST
32 # Set to 1 to build libopenstm32 an open source library for stm32
34 # Make the gcc default to Cortex-M3
35 DEFAULT_TO_CORTEX_M3=0
37 ##############################################################################
38 # Version and download url settings section
39 ##############################################################################
40 if [ ${USE_LINARO} == 0 ] ; then
44 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
47 GCCRELEASE=4.5-2010.11-0
48 GCCVERSION=4.5-2010.11-1
49 GCC=gcc-linaro-${GCCVERSION}
50 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
53 BINUTILS=binutils-2.20
61 ##############################################################################
63 ##############################################################################
65 CPUS=$(getconf _NPROCESSORS_ONLN)
66 PARALLEL=-j$((CPUS + 1))
67 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
72 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
75 # To default to the Cortex-M3:
76 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
79 # Pull in the local configuration, if any
80 if [ -f local.sh ]; then
87 if [ ${QUIET} != 0 ]; then
89 MAKEFLAGS="${MAKEFLAGS} -s"
92 export PATH="${PREFIX}/bin:${PATH}"
95 SOURCES=${SUMMON_DIR}/sources
96 STAMPS=${SUMMON_DIR}/stamps
99 ##############################################################################
101 ##############################################################################
104 ##############################################################################
105 # OS and Tooldetection section
106 # Detects which tools and flags to use
107 ##############################################################################
111 echo "Found Linux OS."
114 echo "Found Darwin OS."
115 GCCFLAGS="${GCCFLAGS} \
116 --with-gmp=${DARWIN_OPT_PATH} \
117 --with-mpfr=${DARWIN_OPT_PATH} \
118 --with-mpc=${DARWIN_OPT_PATH} \
119 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
122 echo "Found unknown OS. Aborting!"
127 ##############################################################################
129 # You probably don't have to touch anything after this
130 ##############################################################################
132 # Fetch a versioned file from a URL
134 if [ ! -e ${STAMPS}/$1.fetch ]; then
135 log "Downloading $1 sources..."
136 wget -c --no-passive-ftp $2
137 touch ${STAMPS}/$1.fetch
141 # Log a message out to the console
143 echo "******************************************************************"
145 echo "******************************************************************"
151 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
152 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
155 echo "archive type bz2"
159 echo "archive type gz"
163 echo "Unknown archive type of $1"
168 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
174 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
178 mkdir -p ${STAMPS} ${SOURCES}
182 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
183 fetch ${GCC} ${GCCURL}
184 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
185 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
187 if [ ${LIBSTM32_EN} != 0 ]; then
188 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
189 log "Cloning libcmsis sources..."
190 git clone git://git.open-bldc.org/libcmsis.git
192 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
193 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
198 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
199 log "Cloning libstm32 sources..."
200 git clone git://git.open-bldc.org/libstm32.git
202 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
203 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
208 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
209 log "Cloning libstm32usb sources..."
210 git clone git://git.open-bldc.org/libstm32usb.git
212 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
213 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
219 if [ ${LIBOPENSTM32_EN} != 0 ]; then
220 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
221 log "Cloning libopenstm32 sources..."
222 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
224 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
225 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
233 if [ ! -e build ]; then
237 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
240 log "Configuring ${BINUTILS}"
241 ../${BINUTILS}/configure --target=${TARGET} \
250 log "Building ${BINUTILS}"
252 install ${BINUTILS} install
254 log "Cleaning up ${BINUTILS}"
255 touch ${STAMPS}/${BINUTILS}.build
256 rm -rf build/* ${BINUTILS}
259 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
262 log "Configuring ${GCC}-boot"
263 ../${GCC}/configure --target=${TARGET} \
267 --enable-languages="c" \
277 log "Building ${GCC}-boot"
278 make ${MAKEFLAGS} all-gcc
279 install ${GCC}-boot install-gcc
281 log "Cleaning up ${GCC}-boot"
282 touch ${STAMPS}/${GCC}-boot.build
283 rm -rf build/* ${GCC}
286 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
289 log "Configuring ${NEWLIB}"
290 ../${NEWLIB}/configure --target=${TARGET} \
298 --disable-newlib-supplied-syscalls \
300 log "Building ${NEWLIB}"
301 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
302 install ${NEWLIB} install
304 log "Cleaning up ${NEWLIB}"
305 touch ${STAMPS}/${NEWLIB}.build
306 rm -rf build/* ${NEWLIB}
309 # Yes, you need to build gcc again!
310 if [ ! -e ${STAMPS}/${GCC}.build ]; then
313 log "Configuring ${GCC}"
314 ../${GCC}/configure --target=${TARGET} \
318 --enable-languages="c,c++" \
327 log "Building ${GCC}"
329 install ${GCC} install
331 log "Cleaning up ${GCC}"
332 touch ${STAMPS}/${GCC}.build
333 rm -rf build/* ${GCC}
336 if [ ! -e ${STAMPS}/${GDB}.build ]; then
339 log "Configuring ${GDB}"
340 ../${GDB}/configure --target=${TARGET} \
346 log "Building ${GDB}"
348 install ${GDB} install
350 log "Cleaning up ${GDB}"
351 touch ${STAMPS}/${GDB}.build
352 rm -rf build/* ${GDB}
355 if [ ${LIBSTM32_EN} != 0 ]; then
356 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
357 unpack libcmsis-${LIBCMSIS}
358 cd libcmsis-${LIBCMSIS}
359 log "Building libcmsis-${LIBCMSIS}"
360 make arch_prefix=${TARGET} prefix=${PREFIX}
361 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
363 log "Cleaning up libcmsis-${LIBCMSIS}"
364 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
365 rm -rf libcmsis-${LIBCMSIS}
368 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
369 unpack libstm32-${LIBSTM32}
370 cd libstm32-${LIBSTM32}
371 log "Building libstm32-${LIBSTM32}"
372 make arch_prefix=${TARGET} prefix=${PREFIX}
373 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
375 log "Cleaning up libstm32-${LIBSTM32}"
376 touch ${STAMPS}/libstm32-${LIBSTM32}.build
377 rm -rf libstm32-${LIBSTM32}
380 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
381 unpack libstm32usb-${LIBSTM32USB}
382 cd libstm32usb-${LIBSTM32USB}
383 log "Building libstm32usb-${LIBSTM32USB}"
384 make arch_prefix=${TARGET} prefix=${PREFIX}
385 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
387 log "Cleaning up libstm32usb-${LIBSTM32USB}"
388 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
389 rm -rf libstm32usb-${LIBSTM32USB}
393 if [ $LIBOPENSTM32_EN != 0 ]; then
394 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
395 unpack libopenstm32-${LIBOPENSTM32}
396 cd libopenstm32-${LIBOPENSTM32}
397 log "Building libopenstm32-${LIBOPENSTM32}"
398 make PREFIX=${TARGET} DESTDIR=${PREFIX}
399 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
401 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
402 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
403 rm -rf libopenstm32-${LIBOPENSTM32}