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
12 # Stop if any command fails
15 TARGET=arm-none-eabi # Or: TARGET=arm-elf
16 PREFIX=${HOME}/arm-none-eabi # Install location of your final toolchain
17 PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
18 DARWIN_OPT_PATH=/opt/local # Path in which MacPorts or Fink is installed
19 # Set to 'sudo' if you need superuser privileges while installing
21 # Set to 1 to be quieter while running
27 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
30 # GCCVERSION=4.5-2010.08-1
31 # GCC=gcc-linaro-${GCCVERSION}
32 # GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCVERSION}/+download/${GCC}.tar.gz
34 BINUTILS=binutils-2.20
45 SOURCES=${SUMMON_DIR}/sources
46 STAMPS=${SUMMON_DIR}/stamps
51 if [ ${QUIET} != 0 ]; then
53 MAKEFLAGS="${MAKEFLAGS} -s"
56 export PATH="${PREFIX}/bin:${PATH}"
62 # To default to the Cortex-M3:
63 # GCCFLAGS="--with-arch=armv7-m --with-mode=thumb"
65 # Fetch a versioned file from a URL
67 if [ ! -e ${STAMPS}/$1.fetch ]; then
68 log "Downloading $1 sources..."
69 wget -c --no-passive-ftp $2
70 touch ${STAMPS}/$1.fetch
74 # Log a message out to the console
76 echo "******************************************************************"
78 echo "******************************************************************"
84 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
85 tar xaf${TARFLAGS} ${SOURCES}/$1.tar.*
91 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
96 echo "Found Linux OS."
99 echo "Found Darwin OS."
100 GCCFLAGS="${GCCFLAGS} \
101 --with-gmp=${DARWIN_OPT_PATH} \
102 --with-mpfr=${DARWIN_OPT_PATH} \
103 --with-mpc=${DARWIN_OPT_PATH} \
104 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
107 echo "Found unknown OS. Aborting!"
112 mkdir -p ${STAMPS} ${SOURCES}
116 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
117 fetch ${GCC} ${GCCURL}
118 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
119 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
121 if [ ${LIBSTM32_EN} != 0 ]; then
122 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
123 log "Cloning libcmsis sources..."
124 git clone git://git.open-bldc.org/libcmsis.git
126 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
127 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
132 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
133 log "Cloning libstm32 sources..."
134 git clone git://git.open-bldc.org/libstm32.git
136 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
137 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
142 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
143 log "Cloning libstm32usb sources..."
144 git clone git://git.open-bldc.org/libstm32usb.git
146 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
147 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
153 if [ ${LIBOPENSTM32_EN} != 0 ]; then
154 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
155 log "Cloning libopenstm32 sources..."
156 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
158 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
159 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
167 if [ ! -e build ]; then
171 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
174 log "Configuring ${BINUTILS}"
175 ../${BINUTILS}/configure --target=${TARGET} \
184 log "Building ${BINUTILS}"
186 install ${BINUTILS} install
188 log "Cleaning up ${BINUTILS}"
189 touch ${STAMPS}/${BINUTILS}.build
190 rm -rf build/* ${BINUTILS}
193 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
196 log "Configuring ${GCC}-boot"
197 ../${GCC}/configure --target=${TARGET} \
201 --enable-languages="c" \
210 log "Building ${GCC}-boot"
211 make ${MAKEFLAGS} all-gcc
212 install ${GCC}-boot install-gcc
214 log "Cleaning up ${GCC}-boot"
215 touch ${STAMPS}/${GCC}-boot.build
216 rm -rf build/* ${GCC}
219 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
222 log "Configuring ${NEWLIB}"
223 ../${NEWLIB}/configure --target=${TARGET} \
231 --disable-newlib-supplied-syscalls
232 log "Building ${NEWLIB}"
234 install ${NEWLIB} install
236 log "Cleaning up ${NEWLIB}"
237 touch ${STAMPS}/${NEWLIB}.build
238 rm -rf build/* ${NEWLIB}
241 # Yes, you need to build gcc again!
242 if [ ! -e ${STAMPS}/${GCC}.build ]; then
245 log "Configuring ${GCC}"
246 ../${GCC}/configure --target=${TARGET} \
250 --enable-languages="c,c++" \
258 log "Building ${GCC}"
260 install ${GCC} install
262 log "Cleaning up ${GCC}"
263 touch ${STAMPS}/${GCC}.build
264 rm -rf build/* ${GCC}
267 if [ ! -e ${STAMPS}/${GDB}.build ]; then
270 log "Configuring ${GDB}"
271 ../${GDB}/configure --target=${TARGET} \
277 log "Building ${GDB}"
279 install ${GDB} install
281 log "Cleaning up ${GDB}"
282 touch ${STAMPS}/${GDB}.build
283 rm -rf build/* ${GDB}
286 if [ ${LIBSTM32_EN} != 0 ]; then
287 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
288 unpack libcmsis-${LIBCMSIS}
289 cd libcmsis-${LIBCMSIS}
290 log "Building libcmsis-${LIBCMSIS}"
291 make arch_prefix=${TARGET} prefix=${PREFIX}
292 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
294 log "Cleaning up libcmsis-${LIBCMSIS}"
295 touch .libcmsis-${LIBCMSIS}.build
296 rm -rf libcmsis-${LIBCMSIS}
299 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
300 unpack libstm32-${LIBSTM32}
301 cd libstm32-${LIBSTM32}
302 log "Building libstm32-${LIBSTM32}"
303 make arch_prefix=${TARGET} prefix=${PREFIX}
304 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
306 log "Cleaning up libstm32-${LIBSTM32}"
307 touch .libstm32-${LIBSTM32}.build
308 rm -rf libstm32-${LIBSTM32}
311 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
312 unpack libstm32usb-${LIBSTM32USB}
313 cd libstm32usb-${LIBSTM32USB}
314 log "Building libstm32usb-${LIBSTM32USB}"
315 make arch_prefix=${TARGET} prefix=${PREFIX}
316 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
318 log "Cleaning up libstm32usb-${LIBSTM32USB}"
319 touch .libstm32usb-${LIBSTM32USB}.build
320 rm -rf libstm32usb-${LIBSTM32USB}
324 if [ $LIBOPENSTM32_EN != 0 ]; then
325 unpack libopenstm32-${LIBOPENSTM32}
326 cd libopenstm32-${LIBOPENSTM32}
327 log "Building libopenstm32-${LIBOPENSTM32}"
328 make PREFIX=${TARGET} DESTDIR=${PREFIX}
329 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
331 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
332 touch .libopenstm32-${LIBOPENSTM32}.build
333 rm -rf libopenstm32-${LIBOPENSTM32}