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 if which getconf > /dev/null; then
66 CPUS=$(getconf _NPROCESSORS_ONLN)
70 PARALLEL=-j$((CPUS + 1))
71 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
76 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
79 # To default to the Cortex-M3:
80 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
83 # Pull in the local configuration, if any
84 if [ -f local.sh ]; then
91 if [ ${QUIET} != 0 ]; then
93 MAKEFLAGS="${MAKEFLAGS} -s"
96 export PATH="${PREFIX}/bin:${PATH}"
99 SOURCES=${SUMMON_DIR}/sources
100 STAMPS=${SUMMON_DIR}/stamps
103 ##############################################################################
105 ##############################################################################
108 ##############################################################################
109 # OS and Tooldetection section
110 # Detects which tools and flags to use
111 ##############################################################################
115 echo "Found Linux OS."
118 echo "Found Darwin OS."
119 GCCFLAGS="${GCCFLAGS} \
120 --with-gmp=${DARWIN_OPT_PATH} \
121 --with-mpfr=${DARWIN_OPT_PATH} \
122 --with-mpc=${DARWIN_OPT_PATH} \
123 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
126 echo "Found CygWin that means Windows most likely."
129 echo "Found unknown OS. Aborting!"
134 ##############################################################################
136 # You probably don't have to touch anything after this
137 ##############################################################################
139 # Fetch a versioned file from a URL
141 if [ ! -e ${STAMPS}/$1.fetch ]; then
142 log "Downloading $1 sources..."
143 wget -c --no-passive-ftp $2
144 touch ${STAMPS}/$1.fetch
148 # Log a message out to the console
150 echo "******************************************************************"
152 echo "******************************************************************"
158 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
159 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
162 echo "archive type bz2"
166 echo "archive type gz"
170 echo "Unknown archive type of $1"
175 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
181 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
185 mkdir -p ${STAMPS} ${SOURCES}
189 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
190 fetch ${GCC} ${GCCURL}
191 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
192 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
194 if [ ${LIBSTM32_EN} != 0 ]; then
195 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
196 log "Cloning libcmsis sources..."
197 git clone git://git.open-bldc.org/libcmsis.git
199 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
200 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
205 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
206 log "Cloning libstm32 sources..."
207 git clone git://git.open-bldc.org/libstm32.git
209 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
210 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
215 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
216 log "Cloning libstm32usb sources..."
217 git clone git://git.open-bldc.org/libstm32usb.git
219 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
220 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
226 if [ ${LIBOPENSTM32_EN} != 0 ]; then
227 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
228 log "Cloning libopenstm32 sources..."
229 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
231 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
232 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
240 if [ ! -e build ]; then
244 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
247 log "Configuring ${BINUTILS}"
248 ../${BINUTILS}/configure --target=${TARGET} \
257 log "Building ${BINUTILS}"
259 install ${BINUTILS} install
261 log "Cleaning up ${BINUTILS}"
262 touch ${STAMPS}/${BINUTILS}.build
263 rm -rf build/* ${BINUTILS}
266 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
269 log "Configuring ${GCC}-boot"
270 ../${GCC}/configure --target=${TARGET} \
274 --enable-languages="c" \
284 log "Building ${GCC}-boot"
285 make ${MAKEFLAGS} all-gcc
286 install ${GCC}-boot install-gcc
288 log "Cleaning up ${GCC}-boot"
289 touch ${STAMPS}/${GCC}-boot.build
290 rm -rf build/* ${GCC}
293 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
296 log "Configuring ${NEWLIB}"
297 ../${NEWLIB}/configure --target=${TARGET} \
305 --disable-newlib-supplied-syscalls \
307 log "Building ${NEWLIB}"
308 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
309 install ${NEWLIB} install
311 log "Cleaning up ${NEWLIB}"
312 touch ${STAMPS}/${NEWLIB}.build
313 rm -rf build/* ${NEWLIB}
316 # Yes, you need to build gcc again!
317 if [ ! -e ${STAMPS}/${GCC}.build ]; then
320 log "Configuring ${GCC}"
321 ../${GCC}/configure --target=${TARGET} \
325 --enable-languages="c,c++" \
334 log "Building ${GCC}"
336 install ${GCC} install
338 log "Cleaning up ${GCC}"
339 touch ${STAMPS}/${GCC}.build
340 rm -rf build/* ${GCC}
343 if [ ! -e ${STAMPS}/${GDB}.build ]; then
346 log "Configuring ${GDB}"
347 ../${GDB}/configure --target=${TARGET} \
353 log "Building ${GDB}"
355 install ${GDB} install
357 log "Cleaning up ${GDB}"
358 touch ${STAMPS}/${GDB}.build
359 rm -rf build/* ${GDB}
362 if [ ${LIBSTM32_EN} != 0 ]; then
363 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
364 unpack libcmsis-${LIBCMSIS}
365 cd libcmsis-${LIBCMSIS}
366 log "Building libcmsis-${LIBCMSIS}"
367 make arch_prefix=${TARGET} prefix=${PREFIX}
368 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
370 log "Cleaning up libcmsis-${LIBCMSIS}"
371 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
372 rm -rf libcmsis-${LIBCMSIS}
375 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
376 unpack libstm32-${LIBSTM32}
377 cd libstm32-${LIBSTM32}
378 log "Building libstm32-${LIBSTM32}"
379 make arch_prefix=${TARGET} prefix=${PREFIX}
380 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
382 log "Cleaning up libstm32-${LIBSTM32}"
383 touch ${STAMPS}/libstm32-${LIBSTM32}.build
384 rm -rf libstm32-${LIBSTM32}
387 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
388 unpack libstm32usb-${LIBSTM32USB}
389 cd libstm32usb-${LIBSTM32USB}
390 log "Building libstm32usb-${LIBSTM32USB}"
391 make arch_prefix=${TARGET} prefix=${PREFIX}
392 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
394 log "Cleaning up libstm32usb-${LIBSTM32USB}"
395 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
396 rm -rf libstm32usb-${LIBSTM32USB}
400 if [ $LIBOPENSTM32_EN != 0 ]; then
401 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
402 unpack libopenstm32-${LIBOPENSTM32}
403 cd libopenstm32-${LIBOPENSTM32}
404 log "Building libopenstm32-${LIBOPENSTM32}"
405 make PREFIX=${TARGET} DESTDIR=${PREFIX}
406 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
408 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
409 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
410 rm -rf libopenstm32-${LIBOPENSTM32}