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 enable building of OpenOCD
33 # Set to 1 to build libstm32 provided by ST
35 # Set to 1 to build libopenstm32 an open source library for stm32
37 # Make the gcc default to Cortex-M3
38 DEFAULT_TO_CORTEX_M3=0
40 ##############################################################################
41 # Version and download url settings section
42 ##############################################################################
43 if [ ${USE_LINARO} == 0 ] ; then
47 GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
50 GCCRELEASE=4.5-2010.11-0
51 GCCVERSION=4.5-2010.11-1
52 GCC=gcc-linaro-${GCCVERSION}
53 GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
56 BINUTILS=binutils-2.20
65 ##############################################################################
67 ##############################################################################
69 if which getconf > /dev/null; then
70 CPUS=$(getconf _NPROCESSORS_ONLN)
74 PARALLEL=-j$((CPUS + 1))
75 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
80 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
83 # To default to the Cortex-M3:
84 GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
87 # Pull in the local configuration, if any
88 if [ -f local.sh ]; then
95 if [ ${QUIET} != 0 ]; then
97 MAKEFLAGS="${MAKEFLAGS} -s"
100 export PATH="${PREFIX}/bin:${PATH}"
103 SOURCES=${SUMMON_DIR}/sources
104 STAMPS=${SUMMON_DIR}/stamps
107 ##############################################################################
109 ##############################################################################
112 ##############################################################################
113 # OS and Tooldetection section
114 # Detects which tools and flags to use
115 ##############################################################################
119 echo "Found Linux OS."
122 echo "Found Darwin OS."
124 # darwin dependencies
125 DARWINDEPS="gnutar mpfr libmpc gmp"
128 GCCFLAGS="${GCCFLAGS} \
129 --with-gmp=${DARWIN_OPT_PATH} \
130 --with-mpfr=${DARWIN_OPT_PATH} \
131 --with-mpc=${DARWIN_OPT_PATH} \
132 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
134 echo "Attempting to automatically check if common dependencies are installed on your system"
135 if ! which port > /dev/null; then
136 echo "MacPorts not installed."
138 pc=`port installed ${DARWINDEPS} | wc -l | tr -d " "`
139 if [ ${pc} -lt $[${DARWINDEPSCOUNT}+1] ];
141 echo "Something is missing, do you want to install everything needed?"
142 echo "(You need super user rights to do this.)"
144 if [ read = "y" || read = "yes" ];
146 sudo port install ${DARWINDEPS}
149 echo "Found: "${DARWINDEPS}"!"
155 --with-libiconv-prefix=${DARWIN_OPT_PATH}"
156 OOCD_CFLAGS="-m32 -I/opt/mine/include -I/opt/local/include"
157 OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
160 echo "Found CygWin that means Windows most likely."
163 echo "Found unknown OS. Aborting!"
168 ##############################################################################
170 # You probably don't have to touch anything after this
171 ##############################################################################
173 # Fetch a versioned file from a URL
175 if [ ! -e ${STAMPS}/$1.fetch ]; then
176 log "Downloading $1 sources..."
177 wget -c --no-passive-ftp $2
178 touch ${STAMPS}/$1.fetch
182 # Log a message out to the console
184 echo "******************************************************************"
186 echo "******************************************************************"
192 # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
193 ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
196 echo "archive type bz2"
200 echo "archive type gz"
204 echo "Unknown archive type of $1"
209 ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
215 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
219 mkdir -p ${STAMPS} ${SOURCES}
223 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
224 fetch ${GCC} ${GCCURL}
225 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
226 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
228 if [ ${OOCD_EN} != 0 ]; then
229 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
230 log "Cloning OpenOCD sources..."
231 git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
235 tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
236 #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
237 # bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
238 rm -rf openocd-${OOCD}
242 if [ ${LIBSTM32_EN} != 0 ]; then
243 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
244 log "Cloning libcmsis sources..."
245 git clone git://git.open-bldc.org/libcmsis.git
247 git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
248 bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
253 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
254 log "Cloning libstm32 sources..."
255 git clone git://git.open-bldc.org/libstm32.git
257 git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
258 bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
263 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
264 log "Cloning libstm32usb sources..."
265 git clone git://git.open-bldc.org/libstm32usb.git
267 git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
268 bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
274 if [ ${LIBOPENSTM32_EN} != 0 ]; then
275 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
276 log "Cloning libopenstm32 sources..."
277 git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
279 git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
280 bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
288 if [ ! -e build ]; then
292 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
295 log "Configuring ${BINUTILS}"
296 ../${BINUTILS}/configure --target=${TARGET} \
305 log "Building ${BINUTILS}"
307 install ${BINUTILS} install
309 log "Cleaning up ${BINUTILS}"
310 touch ${STAMPS}/${BINUTILS}.build
311 rm -rf build/* ${BINUTILS}
314 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
317 log "Configuring ${GCC}-boot"
318 ../${GCC}/configure --target=${TARGET} \
322 --enable-languages="c" \
332 log "Building ${GCC}-boot"
333 make ${MAKEFLAGS} all-gcc
334 install ${GCC}-boot install-gcc
336 log "Cleaning up ${GCC}-boot"
337 touch ${STAMPS}/${GCC}-boot.build
338 rm -rf build/* ${GCC}
341 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
344 log "Configuring ${NEWLIB}"
345 ../${NEWLIB}/configure --target=${TARGET} \
353 --disable-newlib-supplied-syscalls \
355 log "Building ${NEWLIB}"
356 make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
357 install ${NEWLIB} install
359 log "Cleaning up ${NEWLIB}"
360 touch ${STAMPS}/${NEWLIB}.build
361 rm -rf build/* ${NEWLIB}
364 # Yes, you need to build gcc again!
365 if [ ! -e ${STAMPS}/${GCC}.build ]; then
368 log "Configuring ${GCC}"
369 ../${GCC}/configure --target=${TARGET} \
373 --enable-languages="c,c++" \
382 log "Building ${GCC}"
384 install ${GCC} install
386 log "Cleaning up ${GCC}"
387 touch ${STAMPS}/${GCC}.build
388 rm -rf build/* ${GCC}
391 if [ ! -e ${STAMPS}/${GDB}.build ]; then
394 log "Configuring ${GDB}"
395 ../${GDB}/configure --target=${TARGET} \
401 log "Building ${GDB}"
403 install ${GDB} install
405 log "Cleaning up ${GDB}"
406 touch ${STAMPS}/${GDB}.build
407 rm -rf build/* ${GDB}
410 if [ ${OOCD_EN} != 0 ]; then
411 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
412 unpack openocd-${OOCD}
414 log "Configuring openocd-${OOCD}"
415 CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
416 LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
417 ../openocd-${OOCD}/configure --enable-maintainer-mode \
421 --enable-ft2232_libftdi \
422 --enable-usb_blaster_libftdi \
423 --enable-amtjtagaccel \
426 --enable-at91rm9200 \
428 --enable-presto_libftdi \
433 --enable-arm-jtag-ew \
435 log "Building openocd-${OOCD}"
437 install openocd-${OOCD} install
439 log "Cleaning up openocd-${OOCD}"
440 touch ${STAMPS}/openocd-${OOCD}.build
441 rm -rf build/* ${OOCD}
445 if [ ${LIBSTM32_EN} != 0 ]; then
446 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
447 unpack libcmsis-${LIBCMSIS}
448 cd libcmsis-${LIBCMSIS}
449 log "Building libcmsis-${LIBCMSIS}"
450 make arch_prefix=${TARGET} prefix=${PREFIX}
451 install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
453 log "Cleaning up libcmsis-${LIBCMSIS}"
454 touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
455 rm -rf libcmsis-${LIBCMSIS}
458 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
459 unpack libstm32-${LIBSTM32}
460 cd libstm32-${LIBSTM32}
461 log "Building libstm32-${LIBSTM32}"
462 make arch_prefix=${TARGET} prefix=${PREFIX}
463 install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
465 log "Cleaning up libstm32-${LIBSTM32}"
466 touch ${STAMPS}/libstm32-${LIBSTM32}.build
467 rm -rf libstm32-${LIBSTM32}
470 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
471 unpack libstm32usb-${LIBSTM32USB}
472 cd libstm32usb-${LIBSTM32USB}
473 log "Building libstm32usb-${LIBSTM32USB}"
474 make arch_prefix=${TARGET} prefix=${PREFIX}
475 install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
477 log "Cleaning up libstm32usb-${LIBSTM32USB}"
478 touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
479 rm -rf libstm32usb-${LIBSTM32USB}
483 if [ $LIBOPENSTM32_EN != 0 ]; then
484 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
485 unpack libopenstm32-${LIBOPENSTM32}
486 cd libopenstm32-${LIBOPENSTM32}
487 log "Building libopenstm32-${LIBOPENSTM32}"
488 make PREFIX=${TARGET} DESTDIR=${PREFIX}
489 install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
491 log "Cleaning up libopenstm32-${LIBOPENSTM32}"
492 touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
493 rm -rf libopenstm32-${LIBOPENSTM32}