#!/bin/bash -x # Written by Uwe Hermann , released as public domain. # Modified by Piotr Esden-Tempski , released as public domain. # # Requirements (example is for Debian, replace package names as needed): # # apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev \ # libmpc-dev autoconf texinfo build-essential # # Or on Ubuntu Maverick give `apt-get build-dep gcc-4.5` a try. # # Stop if any command fails set -e ############################################################################## # Settings section # You probably want to customize those ############################################################################## TARGET=arm-none-eabi PREFIX=/usr/local # Install location of your final toolchain # Set to 'sudo' if you need superuser privileges while installing SUDO=sudo # Set to 1 to be quieter while running QUIET=0 # Set to 1 to use linaro gcc instead of the FSF gcc USE_LINARO=1 # Set to 1 to enable building of OpenOCD OOCD_EN=1 # Make the gcc default to Cortex-M3 DEFAULT_TO_CORTEX_M3=1 ############################################################################## # Version and download url settings section ############################################################################## if [ ${USE_LINARO} == 0 ] ; then # For FSF GCC: GCCVERSION=4.5.1 GCC=gcc-${GCCVERSION} GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz else # For the Linaro GCC: GCCRELEASE=4.5-2010.11-0 GCCVERSION=4.5-2010.11-1 GCC=gcc-linaro-${GCCVERSION} GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2 fi BINUTILS=binutils-2.20 GDB=gdb-7.2 OOCD=master GMP=gmp-4.2.4 MPFR=mpfr-2.4.2 MPC=mpc-0.8.2 ############################################################################## # Flags section ############################################################################## if which getconf > /dev/null; then CPUS=$(getconf _NPROCESSORS_ONLN) else CPUS=1 fi PARALLEL=-j$((CPUS + 1)) echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag" GDBFLAGS= BINUTILFLAGS= if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then GCCFLAGS= else # To default to the Cortex-M3: GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft" fi GCCFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections -fomit-frame-pointer -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -g -Os -fshort-wchar -fno-unroll-loops -mabi=aapcs" # Pull in the local configuration, if any if [ -f local.sh ]; then . ./local.sh fi MAKEFLAGS=${PARALLEL} TARFLAGS=v if [ ${QUIET} != 0 ]; then TARFLAGS= MAKEFLAGS="${MAKEFLAGS} -s" fi export PATH="${PREFIX}/bin:${PATH}" SUMMON_DIR=$(pwd) SOURCES=${SUMMON_DIR}/sources STAMPS=${SUMMON_DIR}/stamps ############################################################################## # Tool section ############################################################################## TAR=tar ############################################################################## # OS and Tooldetection section # Detects which tools and flags to use ############################################################################## case "$(uname)" in Linux) echo "Found Linux OS." GCCFLAGS="--with-system-zlib" ;; Darwin) echo "Found Darwin OS." GCCFLAGS="--with-system-zlib" ;; MINGW32*) echo "Found Mingw32" OOCD_EN=0 SUDO= ;; *) echo "Found unknown OS. Aborting!" exit 1 ;; esac ############################################################################## # Building section # You probably don't have to touch anything after this ############################################################################## # Fetch a versioned file from a URL function fetch { if [ ! -e ${STAMPS}/$1.fetch ]; then log "Downloading $1 sources..." wget -c --no-passive-ftp $2 touch ${STAMPS}/$1.fetch fi } # Log a message out to the console function log { echo "******************************************************************" echo "* $*" echo "******************************************************************" } # Unpack an archive function unpack { log Unpacking $* # Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a ARCHIVE=$(ls ${SOURCES}/$1.tar.*) case ${ARCHIVE} in *.bz2) echo "archive type bz2" TYPE=j ;; *.gz) echo "archive type gz" TYPE=z ;; *) echo "Unknown archive type of $1" echo ${ARCHIVE} exit 1 ;; esac ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.* } # Install a build function install { log $1 ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8 } mkdir -p ${STAMPS} ${SOURCES} cd ${SOURCES} fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2 fetch ${GCC} ${GCCURL} fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2 fetch ${GMP} http://mirrors.kernel.org/gnu/gmp/${GMP}.tar.bz2 fetch ${MPFR} http://mirrors.kernel.org/gnu/mpfr/${MPFR}.tar.bz2 fetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz if [ ${OOCD_EN} != 0 ]; then if [ ! -e openocd-${OOCD}.tar.bz2 ]; then log "Cloning OpenOCD sources..." git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD} cd openocd-${OOCD} git am ../../0001-Adding-windows-support-for-BusPirate.patch ./bootstrap rm -rf .git cd .. tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD} rm -rf openocd-${OOCD} fi fi cd ${SUMMON_DIR} if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then unpack ${BINUTILS} rm -rf build-${BINUTILS} mkdir -p build-${BINUTILS} cd build-${BINUTILS} log "Configuring ${BINUTILS}" ../${BINUTILS}/configure --target=${TARGET} \ --prefix=${PREFIX} \ --enable-interwork \ --enable-multilib \ --with-gnu-as \ --with-gnu-ld \ --disable-nls \ --disable-werror \ ${BINUTILFLAGS} log "Building ${BINUTILS}" make ${MAKEFLAGS} install ${BINUTILS} install cd .. touch ${STAMPS}/${BINUTILS}.build fi cd ${SUMMON_DIR} if [ ! -e ${STAMPS}/${GCC}.build ]; then unpack ${GCC} gcc unpack ${GMP} gmp unpack ${MPFR} mpfr unpack ${MPC} mpc mv ${GMP} ${GCC}/gmp mv ${MPFR} ${GCC}/mpfr mv ${MPC} ${GCC}/mpc cd ${GCC} patch -p 1 < ../gcc.patch rm -rf libstdc++-v3 cd .. mkdir -p build-${GCC} cd build-${GCC} log "Configuring ${GCC}" LDFLAGS="${GCC_LDFLAGS}" CPPFLAGS="${GCC_CPPFLAGS}" ../${GCC}/configure --target=${TARGET} \ --prefix=${PREFIX} \ --enable-interwork \ --enable-multilib \ --enable-languages="c,c++" \ --with-newlib \ --without-headers \ --disable-shared \ --with-gnu-as \ --with-gnu-ld \ --disable-nls \ --disable-werror \ --disable-libssp \ --enable-target-optspace \ --disable-threads \ --disable-libmudflap \ --disable-libgomp \ --disable-libstdcxx-pch \ --disable-libunwind-exceptions \ --disable-libffi \ --enable-extra-sgxxlite-multilibs \ --enable-libstdcxx-allocator=malloc \ --disable-lto \ --enable-cxx-flags="${GCCFLAGS_FOR_TARGET}" \ ${GCCFLAGS} log "Building ${GCC}" LDFLAGS="${GCC_LDFLAGS}" CPPFLAGS="${GCC_CPPFLAGS}" make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${GCCFLAGS_FOR_TARGET}" install ${GCC} install cd .. log "Cleaning up ${GCC}-boot" touch ${STAMPS}/${GCC}.build fi cd ${SUMMON_DIR} if [ ! -e ${STAMPS}/${GDB}.build ]; then unpack ${GDB} mkdir -p build-${GDB} cd build-${GDB} log "Configuring ${GDB}" ../${GDB}/configure --target=${TARGET} \ --prefix=${PREFIX} \ --enable-interwork \ --enable-multilib \ --disable-werror \ ${GDBFLAGS} log "Building ${GDB}" make ${MAKEFLAGS} install ${GDB} install cd .. touch ${STAMPS}/${GDB}.build fi if [ ${OOCD_EN} != 0 ]; then cd ${SUMMON_DIR} if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then unpack openocd-${OOCD} mkdir build-${OOCD} cd build-${OOCD} log "Configuring openocd-${OOCD}" CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \ LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \ ../openocd-${OOCD}/configure --enable-maintainer-mode \ --prefix=${PREFIX} \ --enable-dummy \ --enable-parport \ --enable-ft2232_libftdi \ --enable-usb_blaster_libftdi \ --enable-amtjtagaccel \ --enable-zy1000 \ --enable-ep93xx \ --enable-at91rm9200 \ --enable-gw16012 \ --enable-presto_libftdi \ --enable-usbprog \ --enable-jlink \ --enable-vsllink \ --enable-rlink \ --enable-arm-jtag-ew \ --enable-buspirate log "Building openocd-${OOCD}" make ${MAKEFLAGS} install openocd-${OOCD} install cd .. touch ${STAMPS}/openocd-${OOCD}.build fi fi