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}/arm-none-eabi # 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"
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
94 ##############################################################################
95 # OS and Tooldetection section
96 # Detects which tools to use
97 ##############################################################################
101 echo "Found Linux OS."
105 echo "Found Darwin OS."
106 GCCFLAGS="${GCCFLAGS} \
107 --with-gmp=${DARWIN_OPT_PATH} \
108 --with-mpfr=${DARWIN_OPT_PATH} \
109 --with-mpc=${DARWIN_OPT_PATH} \
110 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
111 if ! which gnutar > /dev/null ; then
112 echo "ERROR: GNU tar not found! (try 'sudo port install gnutar')"
115 echo "GNU tar found!"
120 echo "Found unknown OS. Aborting!"
125 ##############################################################################
127 # You probably don't have to touch anything after this
128 ##############################################################################
130 # Fetch a versioned file from a URL
132 if [ ! -e ${STAMPS}/$1.fetch ]; then
133 log "Downloading $1 sources..."
134 wget -c --no-passive-ftp $2
135 touch ${STAMPS}/$1.fetch
139 # Log a message out to the console
141 echo "******************************************************************"
143 echo "******************************************************************"
149 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
150 ${TAR} xaf${TARFLAGS} ${SOURCES}/$1.tar.*
156 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
160 mkdir -p ${STAMPS} ${SOURCES}
164 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
165 fetch ${GCC} ${GCCURL}
166 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
167 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
169 if [ ${LIBSTM32_EN} != 0 ]; then
170 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
171 log "Cloning libcmsis sources..."
172 git clone git://git.open-bldc.org/libcmsis.git
174 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
175 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
180 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
181 log "Cloning libstm32 sources..."
182 git clone git://git.open-bldc.org/libstm32.git
184 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
185 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
190 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
191 log "Cloning libstm32usb sources..."
192 git clone git://git.open-bldc.org/libstm32usb.git
194 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
195 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
201 if [ ${LIBOPENSTM32_EN} != 0 ]; then
202 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
203 log "Cloning libopenstm32 sources..."
204 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
206 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
207 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
215 if [ ! -e build ]; then
219 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
222 log "Configuring ${BINUTILS}"
223 ../${BINUTILS}/configure --target=${TARGET} \
232 log "Building ${BINUTILS}"
234 install ${BINUTILS} install
236 log "Cleaning up ${BINUTILS}"
237 touch ${STAMPS}/${BINUTILS}.build
238 rm -rf build/* ${BINUTILS}
241 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
244 log "Configuring ${GCC}-boot"
245 ../${GCC}/configure --target=${TARGET} \
249 --enable-languages="c" \
259 log "Building ${GCC}-boot"
260 make ${MAKEFLAGS} all-gcc
261 install ${GCC}-boot install-gcc
263 log "Cleaning up ${GCC}-boot"
264 touch ${STAMPS}/${GCC}-boot.build
265 rm -rf build/* ${GCC}
268 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
271 log "Configuring ${NEWLIB}"
272 ../${NEWLIB}/configure --target=${TARGET} \
280 --disable-newlib-supplied-syscalls
281 log "Building ${NEWLIB}"
283 install ${NEWLIB} install
285 log "Cleaning up ${NEWLIB}"
286 touch ${STAMPS}/${NEWLIB}.build
287 rm -rf build/* ${NEWLIB}
290 # Yes, you need to build gcc again!
291 if [ ! -e ${STAMPS}/${GCC}.build ]; then
294 log "Configuring ${GCC}"
295 ../${GCC}/configure --target=${TARGET} \
299 --enable-languages="c,c++" \
308 log "Building ${GCC}"
310 install ${GCC} install
312 log "Cleaning up ${GCC}"
313 touch ${STAMPS}/${GCC}.build
314 rm -rf build/* ${GCC}
317 if [ ! -e ${STAMPS}/${GDB}.build ]; then
320 log "Configuring ${GDB}"
321 ../${GDB}/configure --target=${TARGET} \
327 log "Building ${GDB}"
329 install ${GDB} install
331 log "Cleaning up ${GDB}"
332 touch ${STAMPS}/${GDB}.build
333 rm -rf build/* ${GDB}
336 if [ ${LIBSTM32_EN} != 0 ]; then
337 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
338 unpack libcmsis-${LIBCMSIS}
339 cd libcmsis-${LIBCMSIS}
340 log "Building libcmsis-${LIBCMSIS}"
341 make arch_prefix=${TARGET} prefix=${PREFIX}
342 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
344 log "Cleaning up libcmsis-${LIBCMSIS}"
345 touch .libcmsis-${LIBCMSIS}.build
346 rm -rf libcmsis-${LIBCMSIS}
349 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
350 unpack libstm32-${LIBSTM32}
351 cd libstm32-${LIBSTM32}
352 log "Building libstm32-${LIBSTM32}"
353 make arch_prefix=${TARGET} prefix=${PREFIX}
354 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
356 log "Cleaning up libstm32-${LIBSTM32}"
357 touch .libstm32-${LIBSTM32}.build
358 rm -rf libstm32-${LIBSTM32}
361 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
362 unpack libstm32usb-${LIBSTM32USB}
363 cd libstm32usb-${LIBSTM32USB}
364 log "Building libstm32usb-${LIBSTM32USB}"
365 make arch_prefix=${TARGET} prefix=${PREFIX}
366 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
368 log "Cleaning up libstm32usb-${LIBSTM32USB}"
369 touch .libstm32usb-${LIBSTM32USB}.build
370 rm -rf libstm32usb-${LIBSTM32USB}
374 if [ $LIBOPENSTM32_EN != 0 ]; then
375 unpack libopenstm32-${LIBOPENSTM32}
376 cd libopenstm32-${LIBOPENSTM32}
377 log "Building libopenstm32-${LIBOPENSTM32}"
378 make PREFIX=${TARGET} DESTDIR=${PREFIX}
379 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
381 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
382 touch .libopenstm32-${LIBOPENSTM32}.build
383 rm -rf libopenstm32-${LIBOPENSTM32}