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 TARGET=arm-none-eabi # Or: TARGET=arm-elf
18 PREFIX=${HOME}/arm-none-eabi # Install location of your final toolchain
19 PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
20 DARWIN_OPT_PATH=/opt/local # Path in which MacPorts or Fink is installed
21 # Set to 'sudo' if you need superuser privileges while installing
23 # Set to 1 to be quieter while running
29 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
32 # GCCVERSION=4.5-2010.08-1
33 # GCC=gcc-linaro-${GCCVERSION}
34 # GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCVERSION}/+download/${GCC}.tar.gz
36 BINUTILS=binutils-2.20
50 # To default to the Cortex-M3:
51 # GCCFLAGS="--with-arch=armv7-m --with-mode=thumb"
53 # Pull in the local configuration, if any
54 if [ -f local.sh ]; then
61 if [ ${QUIET} != 0 ]; then
63 MAKEFLAGS="${MAKEFLAGS} -s"
66 export PATH="${PREFIX}/bin:${PATH}"
69 SOURCES=${SUMMON_DIR}/sources
70 STAMPS=${SUMMON_DIR}/stamps
72 # Fetch a versioned file from a URL
74 if [ ! -e ${STAMPS}/$1.fetch ]; then
75 log "Downloading $1 sources..."
76 wget -c --no-passive-ftp $2
77 touch ${STAMPS}/$1.fetch
81 # Log a message out to the console
83 echo "******************************************************************"
85 echo "******************************************************************"
91 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
92 tar xaf${TARFLAGS} ${SOURCES}/$1.tar.*
98 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
103 echo "Found Linux OS."
106 echo "Found Darwin OS."
107 GCCFLAGS="${GCCFLAGS} \
108 --with-gmp=${DARWIN_OPT_PATH} \
109 --with-mpfr=${DARWIN_OPT_PATH} \
110 --with-mpc=${DARWIN_OPT_PATH} \
111 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
114 echo "Found unknown OS. Aborting!"
119 mkdir -p ${STAMPS} ${SOURCES}
123 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
124 fetch ${GCC} ${GCCURL}
125 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
126 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
128 if [ ${LIBSTM32_EN} != 0 ]; then
129 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
130 log "Cloning libcmsis sources..."
131 git clone git://git.open-bldc.org/libcmsis.git
133 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
134 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
139 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
140 log "Cloning libstm32 sources..."
141 git clone git://git.open-bldc.org/libstm32.git
143 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
144 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
149 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
150 log "Cloning libstm32usb sources..."
151 git clone git://git.open-bldc.org/libstm32usb.git
153 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
154 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
160 if [ ${LIBOPENSTM32_EN} != 0 ]; then
161 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
162 log "Cloning libopenstm32 sources..."
163 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
165 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
166 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
174 if [ ! -e build ]; then
178 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
181 log "Configuring ${BINUTILS}"
182 ../${BINUTILS}/configure --target=${TARGET} \
191 log "Building ${BINUTILS}"
193 install ${BINUTILS} install
195 log "Cleaning up ${BINUTILS}"
196 touch ${STAMPS}/${BINUTILS}.build
197 rm -rf build/* ${BINUTILS}
200 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
203 log "Configuring ${GCC}-boot"
204 ../${GCC}/configure --target=${TARGET} \
208 --enable-languages="c" \
217 log "Building ${GCC}-boot"
218 make ${MAKEFLAGS} all-gcc
219 install ${GCC}-boot install-gcc
221 log "Cleaning up ${GCC}-boot"
222 touch ${STAMPS}/${GCC}-boot.build
223 rm -rf build/* ${GCC}
226 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
229 log "Configuring ${NEWLIB}"
230 ../${NEWLIB}/configure --target=${TARGET} \
238 --disable-newlib-supplied-syscalls
239 log "Building ${NEWLIB}"
241 install ${NEWLIB} install
243 log "Cleaning up ${NEWLIB}"
244 touch ${STAMPS}/${NEWLIB}.build
245 rm -rf build/* ${NEWLIB}
248 # Yes, you need to build gcc again!
249 if [ ! -e ${STAMPS}/${GCC}.build ]; then
252 log "Configuring ${GCC}"
253 ../${GCC}/configure --target=${TARGET} \
257 --enable-languages="c,c++" \
265 log "Building ${GCC}"
267 install ${GCC} install
269 log "Cleaning up ${GCC}"
270 touch ${STAMPS}/${GCC}.build
271 rm -rf build/* ${GCC}
274 if [ ! -e ${STAMPS}/${GDB}.build ]; then
277 log "Configuring ${GDB}"
278 ../${GDB}/configure --target=${TARGET} \
284 log "Building ${GDB}"
286 install ${GDB} install
288 log "Cleaning up ${GDB}"
289 touch ${STAMPS}/${GDB}.build
290 rm -rf build/* ${GDB}
293 if [ ${LIBSTM32_EN} != 0 ]; then
294 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
295 unpack libcmsis-${LIBCMSIS}
296 cd libcmsis-${LIBCMSIS}
297 log "Building libcmsis-${LIBCMSIS}"
298 make arch_prefix=${TARGET} prefix=${PREFIX}
299 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
301 log "Cleaning up libcmsis-${LIBCMSIS}"
302 touch .libcmsis-${LIBCMSIS}.build
303 rm -rf libcmsis-${LIBCMSIS}
306 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
307 unpack libstm32-${LIBSTM32}
308 cd libstm32-${LIBSTM32}
309 log "Building libstm32-${LIBSTM32}"
310 make arch_prefix=${TARGET} prefix=${PREFIX}
311 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
313 log "Cleaning up libstm32-${LIBSTM32}"
314 touch .libstm32-${LIBSTM32}.build
315 rm -rf libstm32-${LIBSTM32}
318 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
319 unpack libstm32usb-${LIBSTM32USB}
320 cd libstm32usb-${LIBSTM32USB}
321 log "Building libstm32usb-${LIBSTM32USB}"
322 make arch_prefix=${TARGET} prefix=${PREFIX}
323 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
325 log "Cleaning up libstm32usb-${LIBSTM32USB}"
326 touch .libstm32usb-${LIBSTM32USB}.build
327 rm -rf libstm32usb-${LIBSTM32USB}
331 if [ $LIBOPENSTM32_EN != 0 ]; then
332 unpack libopenstm32-${LIBOPENSTM32}
333 cd libopenstm32-${LIBOPENSTM32}
334 log "Building libopenstm32-${LIBOPENSTM32}"
335 make PREFIX=${TARGET} DESTDIR=${PREFIX}
336 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
338 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
339 touch .libopenstm32-${LIBOPENSTM32}.build
340 rm -rf libopenstm32-${LIBOPENSTM32}