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-elf # Or: TARGET=arm-elf
22 PREFIX=/arm # 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."
107 # darwin dependencies
108 DARWINDEPS="gnutar mpfr libmpc gmp"
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}"
117 echo "Attempting to automatically check if common dependencies are installed on your system"
118 if ! which port > /dev/null; then
119 echo "MacPorts not installed."
121 pc=`port installed ${DARWINDEPS} | wc -l | tr -d " "`
122 if [ ${pc} -lt $[{DARWINDEPSCOUNT}+1] ];
124 echo "Something is missing, do you want to install everything needed?"
125 echo "(You need super user rights to do this.)"
127 if [ read = "y" || read = "yes" ];
129 sudo port install ${DARWINDEPS}
132 echo "Found: "${DARWINDEPS}"!"
141 echo "Found unknown OS. Aborting!"
146 ##############################################################################
148 # You probably don't have to touch anything after this
149 ##############################################################################
151 # Fetch a versioned file from a URL
153 if [ ! -e ${STAMPS}/$1.fetch ]; then
154 log "Downloading $1 sources..."
155 wget -c --no-passive-ftp $2
156 touch ${STAMPS}/$1.fetch
160 # Log a message out to the console
162 echo "******************************************************************"
164 echo "******************************************************************"
170 if [ -f ${SOURCES}/$1.tar.gz ];
172 ${TAR} xfz${TARFLAGS} ${SOURCES}/$1.tar.gz
174 ${TAR} xfj${TARFLAGS} ${SOURCES}/$1.tar.bz2
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
306 log "Building ${NEWLIB}"
308 install ${NEWLIB} install
310 log "Cleaning up ${NEWLIB}"
311 touch ${STAMPS}/${NEWLIB}.build
312 rm -rf build/* ${NEWLIB}
315 # Yes, you need to build gcc again!
316 if [ ! -e ${STAMPS}/${GCC}.build ]; then
319 log "Configuring ${GCC}"
320 ../${GCC}/configure --target=${TARGET} \
324 --enable-languages="c,c++" \
333 log "Building ${GCC}"
335 install ${GCC} install
337 log "Cleaning up ${GCC}"
338 touch ${STAMPS}/${GCC}.build
339 rm -rf build/* ${GCC}
342 if [ ! -e ${STAMPS}/${GDB}.build ]; then
345 log "Configuring ${GDB}"
346 ../${GDB}/configure --target=${TARGET} \
352 log "Building ${GDB}"
354 install ${GDB} install
356 log "Cleaning up ${GDB}"
357 touch ${STAMPS}/${GDB}.build
358 rm -rf build/* ${GDB}
361 if [ ${LIBSTM32_EN} != 0 ]; then
362 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
363 unpack libcmsis-${LIBCMSIS}
364 cd libcmsis-${LIBCMSIS}
365 log "Building libcmsis-${LIBCMSIS}"
366 make arch_prefix=${TARGET} prefix=${PREFIX}
367 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
369 log "Cleaning up libcmsis-${LIBCMSIS}"
370 touch .libcmsis-${LIBCMSIS}.build
371 rm -rf libcmsis-${LIBCMSIS}
374 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
375 unpack libstm32-${LIBSTM32}
376 cd libstm32-${LIBSTM32}
377 log "Building libstm32-${LIBSTM32}"
378 make arch_prefix=${TARGET} prefix=${PREFIX}
379 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
381 log "Cleaning up libstm32-${LIBSTM32}"
382 touch .libstm32-${LIBSTM32}.build
383 rm -rf libstm32-${LIBSTM32}
386 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
387 unpack libstm32usb-${LIBSTM32USB}
388 cd libstm32usb-${LIBSTM32USB}
389 log "Building libstm32usb-${LIBSTM32USB}"
390 make arch_prefix=${TARGET} prefix=${PREFIX}
391 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
393 log "Cleaning up libstm32usb-${LIBSTM32USB}"
394 touch .libstm32usb-${LIBSTM32USB}.build
395 rm -rf libstm32usb-${LIBSTM32USB}
399 if [ $LIBOPENSTM32_EN != 0 ]; then
400 unpack libopenstm32-${LIBOPENSTM32}
401 cd libopenstm32-${LIBOPENSTM32}
402 log "Building libopenstm32-${LIBOPENSTM32}"
403 make PREFIX=${TARGET} DESTDIR=${PREFIX}
404 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
406 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
407 touch .libopenstm32-${LIBOPENSTM32}.build
408 rm -rf libopenstm32-${LIBOPENSTM32}