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 ##############################################################################
96 # You probably don't have to touch anything after this
97 ##############################################################################
99 # Fetch a versioned file from a URL
101 if [ ! -e ${STAMPS}/$1.fetch ]; then
102 log "Downloading $1 sources..."
103 wget -c --no-passive-ftp $2
104 touch ${STAMPS}/$1.fetch
108 # Log a message out to the console
110 echo "******************************************************************"
112 echo "******************************************************************"
118 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
119 tar xaf${TARFLAGS} ${SOURCES}/$1.tar.*
125 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
130 echo "Found Linux OS."
133 echo "Found Darwin OS."
134 GCCFLAGS="${GCCFLAGS} \
135 --with-gmp=${DARWIN_OPT_PATH} \
136 --with-mpfr=${DARWIN_OPT_PATH} \
137 --with-mpc=${DARWIN_OPT_PATH} \
138 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
141 echo "Found unknown OS. Aborting!"
146 mkdir -p ${STAMPS} ${SOURCES}
150 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
151 fetch ${GCC} ${GCCURL}
152 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
153 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
155 if [ ${LIBSTM32_EN} != 0 ]; then
156 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
157 log "Cloning libcmsis sources..."
158 git clone git://git.open-bldc.org/libcmsis.git
160 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
161 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
166 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
167 log "Cloning libstm32 sources..."
168 git clone git://git.open-bldc.org/libstm32.git
170 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
171 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
176 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
177 log "Cloning libstm32usb sources..."
178 git clone git://git.open-bldc.org/libstm32usb.git
180 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
181 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
187 if [ ${LIBOPENSTM32_EN} != 0 ]; then
188 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
189 log "Cloning libopenstm32 sources..."
190 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
192 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
193 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
201 if [ ! -e build ]; then
205 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
208 log "Configuring ${BINUTILS}"
209 ../${BINUTILS}/configure --target=${TARGET} \
218 log "Building ${BINUTILS}"
220 install ${BINUTILS} install
222 log "Cleaning up ${BINUTILS}"
223 touch ${STAMPS}/${BINUTILS}.build
224 rm -rf build/* ${BINUTILS}
227 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
230 log "Configuring ${GCC}-boot"
231 ../${GCC}/configure --target=${TARGET} \
235 --enable-languages="c" \
244 log "Building ${GCC}-boot"
245 make ${MAKEFLAGS} all-gcc
246 install ${GCC}-boot install-gcc
248 log "Cleaning up ${GCC}-boot"
249 touch ${STAMPS}/${GCC}-boot.build
250 rm -rf build/* ${GCC}
253 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
256 log "Configuring ${NEWLIB}"
257 ../${NEWLIB}/configure --target=${TARGET} \
265 --disable-newlib-supplied-syscalls
266 log "Building ${NEWLIB}"
268 install ${NEWLIB} install
270 log "Cleaning up ${NEWLIB}"
271 touch ${STAMPS}/${NEWLIB}.build
272 rm -rf build/* ${NEWLIB}
275 # Yes, you need to build gcc again!
276 if [ ! -e ${STAMPS}/${GCC}.build ]; then
279 log "Configuring ${GCC}"
280 ../${GCC}/configure --target=${TARGET} \
284 --enable-languages="c,c++" \
292 log "Building ${GCC}"
294 install ${GCC} install
296 log "Cleaning up ${GCC}"
297 touch ${STAMPS}/${GCC}.build
298 rm -rf build/* ${GCC}
301 if [ ! -e ${STAMPS}/${GDB}.build ]; then
304 log "Configuring ${GDB}"
305 ../${GDB}/configure --target=${TARGET} \
311 log "Building ${GDB}"
313 install ${GDB} install
315 log "Cleaning up ${GDB}"
316 touch ${STAMPS}/${GDB}.build
317 rm -rf build/* ${GDB}
320 if [ ${LIBSTM32_EN} != 0 ]; then
321 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
322 unpack libcmsis-${LIBCMSIS}
323 cd libcmsis-${LIBCMSIS}
324 log "Building libcmsis-${LIBCMSIS}"
325 make arch_prefix=${TARGET} prefix=${PREFIX}
326 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
328 log "Cleaning up libcmsis-${LIBCMSIS}"
329 touch .libcmsis-${LIBCMSIS}.build
330 rm -rf libcmsis-${LIBCMSIS}
333 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
334 unpack libstm32-${LIBSTM32}
335 cd libstm32-${LIBSTM32}
336 log "Building libstm32-${LIBSTM32}"
337 make arch_prefix=${TARGET} prefix=${PREFIX}
338 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
340 log "Cleaning up libstm32-${LIBSTM32}"
341 touch .libstm32-${LIBSTM32}.build
342 rm -rf libstm32-${LIBSTM32}
345 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
346 unpack libstm32usb-${LIBSTM32USB}
347 cd libstm32usb-${LIBSTM32USB}
348 log "Building libstm32usb-${LIBSTM32USB}"
349 make arch_prefix=${TARGET} prefix=${PREFIX}
350 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
352 log "Cleaning up libstm32usb-${LIBSTM32USB}"
353 touch .libstm32usb-${LIBSTM32USB}.build
354 rm -rf libstm32usb-${LIBSTM32USB}
358 if [ $LIBOPENSTM32_EN != 0 ]; then
359 unpack libopenstm32-${LIBOPENSTM32}
360 cd libopenstm32-${LIBOPENSTM32}
361 log "Building libopenstm32-${LIBOPENSTM32}"
362 make PREFIX=${TARGET} DESTDIR=${PREFIX}
363 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
365 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
366 touch .libopenstm32-${LIBOPENSTM32}.build
367 rm -rf libopenstm32-${LIBOPENSTM32}