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
23 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
26 # GCCVERSION=4.5-2010.08-1
27 # GCC=gcc-linaro-${GCCVERSION}
28 # GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCVERSION}/+download/${GCC}.tar.gz
30 BINUTILS=binutils-2.20
42 SOURCES=${SUMMON_DIR}/sources
43 STAMPS=${SUMMON_DIR}/stamps
45 export PATH="${PREFIX}/bin:${PATH}"
51 # To default to the Cortex-M3:
52 # GCCFLAGS="--with-arch=armv7-m --with-mode=thumb"
54 # Fetch a versioned file from a URL
56 if [ ! -e ${STAMPS}/$1.fetch ]; then
57 log "Downloading $1 sources..."
58 wget -c --no-passive-ftp $2
59 touch ${STAMPS}/$1.fetch
63 # Log a message out to the console
65 echo "******************************************************************"
67 echo "******************************************************************"
73 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
74 tar xvaf ${SOURCES}/$1.tar.*
80 ${SUDO} make ${PARALLEL} $2 $3 $4 $5 $6 $7 $8
85 echo "Found Linux OS."
88 echo "Found Darwin OS."
89 GCCFLAGS="${GCCFLAGS} \
90 --with-gmp=${DARWIN_OPT_PATH} \
91 --with-mpfr=${DARWIN_OPT_PATH} \
92 --with-mpc=${DARWIN_OPT_PATH} \
93 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
96 echo "Found unknown OS. Aborting!"
101 mkdir -p ${STAMPS} ${SOURCES}
105 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
106 fetch ${GCC} ${GCCURL}
107 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
108 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
110 if [ ${LIBSTM32_EN} != 0 ]; then
111 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
112 log "Cloning libcmsis sources..."
113 git clone git://git.open-bldc.org/libcmsis.git
115 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
116 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
121 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
122 log "Cloning libstm32 sources..."
123 git clone git://git.open-bldc.org/libstm32.git
125 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
126 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
131 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
132 log "Cloning libstm32usb sources..."
133 git clone git://git.open-bldc.org/libstm32usb.git
135 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
136 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
142 if [ ${LIBOPENSTM32_EN} != 0 ]; then
143 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
144 log "Cloning libopenstm32 sources..."
145 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
147 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
148 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
156 if [ ! -e build ]; then
160 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
163 log "Configuring ${BINUTILS}"
164 ../${BINUTILS}/configure --target=${TARGET} \
173 log "Building ${BINUTILS}"
175 install ${BINUTILS} install
177 log "Cleaning up ${BINUTILS}"
178 touch ${STAMPS}/${BINUTILS}.build
179 rm -rf build/* ${BINUTILS}
182 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
185 log "Configuring ${GCC}-boot"
186 ../${GCC}/configure --target=${TARGET} \
190 --enable-languages="c" \
199 log "Building ${GCC}-boot"
200 make ${PARALLEL} all-gcc
201 install ${GCC}-boot install-gcc
203 log "Cleaning up ${GCC}-boot"
204 touch ${STAMPS}/${GCC}-boot.build
205 rm -rf build/* ${GCC}
208 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
211 log "Configuring ${NEWLIB}"
212 ../${NEWLIB}/configure --target=${TARGET} \
220 --disable-newlib-supplied-syscalls
221 log "Building ${NEWLIB}"
223 install ${NEWLIB} install
225 log "Cleaning up ${NEWLIB}"
226 touch ${STAMPS}/${NEWLIB}.build
227 rm -rf build/* ${NEWLIB}
230 # Yes, you need to build gcc again!
231 if [ ! -e ${STAMPS}/${GCC}.build ]; then
234 log "Configuring ${GCC}"
235 ../${GCC}/configure --target=${TARGET} \
239 --enable-languages="c,c++" \
247 log "Building ${GCC}"
249 install ${GCC} install
251 log "Cleaning up ${GCC}"
252 touch ${STAMPS}/${GCC}.build
253 rm -rf build/* ${GCC}
256 if [ ! -e ${STAMPS}/${GDB}.build ]; then
259 log "Configuring ${GDB}"
260 ../${GDB}/configure --target=${TARGET} \
266 log "Building ${GDB}"
268 install ${GDB} install
270 log "Cleaning up ${GDB}"
271 touch ${STAMPS}/${GDB}.build
272 rm -rf build/* ${GDB}
275 if [ ${LIBSTM32_EN} != 0 ]; then
276 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
277 unpack libcmsis-${LIBCMSIS}
278 cd libcmsis-${LIBCMSIS}
279 log "Building libcmsis-${LIBCMSIS}"
280 make arch_prefix=${TARGET} prefix=${PREFIX}
281 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
283 log "Cleaning up libcmsis-${LIBCMSIS}"
284 touch .libcmsis-${LIBCMSIS}.build
285 rm -rf libcmsis-${LIBCMSIS}
288 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
289 unpack libstm32-${LIBSTM32}
290 cd libstm32-${LIBSTM32}
291 log "Building libstm32-${LIBSTM32}"
292 make arch_prefix=${TARGET} prefix=${PREFIX}
293 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
295 log "Cleaning up libstm32-${LIBSTM32}"
296 touch .libstm32-${LIBSTM32}.build
297 rm -rf libstm32-${LIBSTM32}
300 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
301 unpack libstm32usb-${LIBSTM32USB}
302 cd libstm32usb-${LIBSTM32USB}
303 log "Building libstm32usb-${LIBSTM32USB}"
304 make arch_prefix=${TARGET} prefix=${PREFIX}
305 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
307 log "Cleaning up libstm32usb-${LIBSTM32USB}"
308 touch .libstm32usb-${LIBSTM32USB}.build
309 rm -rf libstm32usb-${LIBSTM32USB}
313 if [ $LIBOPENSTM32_EN != 0 ]; then
314 unpack libopenstm32-${LIBOPENSTM32}
315 cd libopenstm32-${LIBOPENSTM32}
316 log "Building libopenstm32-${LIBOPENSTM32}"
317 make PREFIX=${TARGET} DESTDIR=${PREFIX}
318 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
320 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
321 touch .libopenstm32-${LIBOPENSTM32}.build
322 rm -rf libopenstm32-${LIBOPENSTM32}