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} ];
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}"!"
139 echo "Found unknown OS. Aborting!"
144 ##############################################################################
146 # You probably don't have to touch anything after this
147 ##############################################################################
149 # Fetch a versioned file from a URL
151 if [ ! -e ${STAMPS}/$1.fetch ]; then
152 log "Downloading $1 sources..."
153 wget -c --no-passive-ftp $2
154 touch ${STAMPS}/$1.fetch
158 # Log a message out to the console
160 echo "******************************************************************"
162 echo "******************************************************************"
168 if [ -f ${SOURCES}/$1.tar.gz ];
170 ${TAR} xfz${TARFLAGS} ${SOURCES}/$1.tar.gz
172 ${TAR} xfj${TARFLAGS} ${SOURCES}/$1.tar.bz2
179 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
183 mkdir -p ${STAMPS} ${SOURCES}
187 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
188 fetch ${GCC} ${GCCURL}
189 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
190 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
192 if [ ${LIBSTM32_EN} != 0 ]; then
193 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
194 log "Cloning libcmsis sources..."
195 git clone git://git.open-bldc.org/libcmsis.git
197 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
198 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
203 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
204 log "Cloning libstm32 sources..."
205 git clone git://git.open-bldc.org/libstm32.git
207 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
208 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
213 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
214 log "Cloning libstm32usb sources..."
215 git clone git://git.open-bldc.org/libstm32usb.git
217 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
218 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
224 if [ ${LIBOPENSTM32_EN} != 0 ]; then
225 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
226 log "Cloning libopenstm32 sources..."
227 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
229 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
230 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
238 if [ ! -e build ]; then
242 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
245 log "Configuring ${BINUTILS}"
246 ../${BINUTILS}/configure --target=${TARGET} \
255 log "Building ${BINUTILS}"
257 install ${BINUTILS} install
259 log "Cleaning up ${BINUTILS}"
260 touch ${STAMPS}/${BINUTILS}.build
261 rm -rf build/* ${BINUTILS}
264 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
267 log "Configuring ${GCC}-boot"
268 ../${GCC}/configure --target=${TARGET} \
272 --enable-languages="c" \
282 log "Building ${GCC}-boot"
283 make ${MAKEFLAGS} all-gcc
284 install ${GCC}-boot install-gcc
286 log "Cleaning up ${GCC}-boot"
287 touch ${STAMPS}/${GCC}-boot.build
288 rm -rf build/* ${GCC}
291 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
294 log "Configuring ${NEWLIB}"
295 ../${NEWLIB}/configure --target=${TARGET} \
303 --disable-newlib-supplied-syscalls
304 log "Building ${NEWLIB}"
306 install ${NEWLIB} install
308 log "Cleaning up ${NEWLIB}"
309 touch ${STAMPS}/${NEWLIB}.build
310 rm -rf build/* ${NEWLIB}
313 # Yes, you need to build gcc again!
314 if [ ! -e ${STAMPS}/${GCC}.build ]; then
317 log "Configuring ${GCC}"
318 ../${GCC}/configure --target=${TARGET} \
322 --enable-languages="c,c++" \
331 log "Building ${GCC}"
333 install ${GCC} install
335 log "Cleaning up ${GCC}"
336 touch ${STAMPS}/${GCC}.build
337 rm -rf build/* ${GCC}
340 if [ ! -e ${STAMPS}/${GDB}.build ]; then
343 log "Configuring ${GDB}"
344 ../${GDB}/configure --target=${TARGET} \
350 log "Building ${GDB}"
352 install ${GDB} install
354 log "Cleaning up ${GDB}"
355 touch ${STAMPS}/${GDB}.build
356 rm -rf build/* ${GDB}
359 if [ ${LIBSTM32_EN} != 0 ]; then
360 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
361 unpack libcmsis-${LIBCMSIS}
362 cd libcmsis-${LIBCMSIS}
363 log "Building libcmsis-${LIBCMSIS}"
364 make arch_prefix=${TARGET} prefix=${PREFIX}
365 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
367 log "Cleaning up libcmsis-${LIBCMSIS}"
368 touch .libcmsis-${LIBCMSIS}.build
369 rm -rf libcmsis-${LIBCMSIS}
372 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
373 unpack libstm32-${LIBSTM32}
374 cd libstm32-${LIBSTM32}
375 log "Building libstm32-${LIBSTM32}"
376 make arch_prefix=${TARGET} prefix=${PREFIX}
377 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
379 log "Cleaning up libstm32-${LIBSTM32}"
380 touch .libstm32-${LIBSTM32}.build
381 rm -rf libstm32-${LIBSTM32}
384 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
385 unpack libstm32usb-${LIBSTM32USB}
386 cd libstm32usb-${LIBSTM32USB}
387 log "Building libstm32usb-${LIBSTM32USB}"
388 make arch_prefix=${TARGET} prefix=${PREFIX}
389 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
391 log "Cleaning up libstm32usb-${LIBSTM32USB}"
392 touch .libstm32usb-${LIBSTM32USB}.build
393 rm -rf libstm32usb-${LIBSTM32USB}
397 if [ $LIBOPENSTM32_EN != 0 ]; then
398 unpack libopenstm32-${LIBOPENSTM32}
399 cd libopenstm32-${LIBOPENSTM32}
400 log "Building libopenstm32-${LIBOPENSTM32}"
401 make PREFIX=${TARGET} DESTDIR=${PREFIX}
402 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
404 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
405 touch .libopenstm32-${LIBOPENSTM32}.build
406 rm -rf libopenstm32-${LIBOPENSTM32}