Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 475 lines (429 sloc) 14.6 KB
#!/bin/sh
# Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
# Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
# adapted for r0ket <http://r0ket.badge.events.ccc.de> development by
# Matthias Rampke <matthias@rampke.de>
# requires Homebrew <https://mxcl.github.com/homebrew>
# Stop if any command fails
set -e
##############################################################################
# Default settings section
##############################################################################
TARGET=arm-none-eabi # Or: TARGET=arm-elf
[ -z $PREFIX ] && PREFIX=${HOME}/arm # Install location of your final toolchain
PARALLEL= # Or: PARALLEL="-j 5" for 4 CPUs
# Set to 'sudo' if you need superuser privileges while installing
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=0
# Set to 1 to enable C++
USE_CPP=0
# Make the gcc default to Cortex-M3
DEFAULT_TO_CORTEX_M3=1
##############################################################################
# parse options
##############################################################################
while getopts c:Chj:st:w: name; do
case ${name} in
c)
if [ ${OPTARG} = 'linaro' ]; then
USE_LINARO=1
elif [ ${OPTARG} = 'fsf' -o ${OPTARG} = 'gnu' ]; then
USE_LINARO=0
else
printf "%s: invalid compiler. Available variants:\n\tfsf\tStandard FSF GCC (default)\n\tlinaro\tLinaro GCC\n" $0
exit 1
fi
;;
C) USE_CPP=1 ;;
j)
if [ ${OPTARG} -gt 0 2> /dev/null ]; then
PARALLEL=-j${OPTARG}
else
printf "%s: invalid number of jobs\n" $0
exit 1
fi
;;
s) SUDO='sudo' ;;
t) PREFIX="${OPTARG}" ;;
w) ARG_WORKDIR="${OPTARG}" ;;
h|?)
printf "Usage:\n\t%s [-Cs] [-c <GCC flavour>] [-j <jobs>] [-t <target directory>] [-w <work directory>]\n\t%s -h\n\n\t-c\tspecify GCC flavour (fsf or linaro, default fsf)\n\t-C\tbuild C++ support\n\t-j\tspecify make(1) parallel jobs (default: no. of CPUs+1)\n\t-s\tuse sudo(1) when installing\n\t-t\tspecify target directory (default: ~/arm)\n\t-w\tspecify work directory (default: <target direcory>/work\n\t-h\tget help\n" $0 $0
exit 1
;;
esac
done
if [ -z $ARG_WORKDIR ]; then
[ -z $WORKDIR ] && WORKDIR=$PREFIX/work
else
WORKDIR=$ARG_WORKDIR
fi
##############################################################################
# Version and download url settings section
##############################################################################
if [ ${USE_LINARO} = 0 ] ; then
# For FSF GCC:
GCCVERSION=4.6.3
if [ ${USE_CPP} = 0 ]; then
GCC=gcc-core-${GCCVERSION}
GCCDIR=gcc-${GCCVERSION}
else
GCC=gcc-${GCCVERSION}
GCCDIR=${GCC}
fi
GCCURL=http://ftp.gnu.org/gnu/gcc/${GCCDIR}/${GCC}.tar.bz2
else
# For the Linaro GCC:
GCCRELEASE=4.6-2012.03
GCCVERSION=${GCCRELEASE}
GCC=gcc-linaro-${GCCRELEASE}
GCCDIR=gcc-linaro-${GCCVERSION}
GCCURL=http://launchpad.net/gcc-linaro/4.6/${GCCRELEASE}/+download/gcc-linaro-${GCCRELEASE}.tar.bz2
fi
BINUTILS=binutils-2.22
NEWLIB=newlib-1.20.0
GDB=gdb-7.3.1
GMP=gmp-5.0.2
MPFR=mpfr-3.0.1
MPC=mpc-0.9
SHA1SUMS="65b304a0b9a53a686ce50a01173d1f40f8efe404 binutils-2.22.tar.bz2
ce317ca5c8185b58bc9300182b534608c578637f gcc-4.6.3.tar.bz2
eaefb90df5a833c94560a8dda177bd1e165c2a88 gcc-core-4.6.3.tar.bz2
99552387d1b4c36e356b59a837911976b08ad926 gcc-linaro-4.6-2012.03.tar.bz2
e57f2c7f93536ef54fab728eb733bf2c36550718 gdb-7.3.1.tar.bz2
2968220e1988eabb61f921d11e5d2db5431e0a35 gmp-5.0.2.tar.bz2
229722d553030734d49731844abfef7617b64f1a mpc-0.9.tar.gz
fbf402fc196724ae60ef01eb6ca8490b1ea4db69 mpfr-3.0.1.tar.bz2
65e7bdbeda0cbbf99c8160df573fd04d1cbe00d1 newlib-1.20.0.tar.gz"
##############################################################################
# Flags section
##############################################################################
if [ "X${PARALLEL}" = "X" ]; then
if which getconf > /dev/null 2> /dev/null && getconf _NPROCESSORS_ONLN > /dev/null 2> /dev/null; then
CPUS=$(getconf _NPROCESSORS_ONLN)
elif which sysctl > /dev/null 2> /dev/null && sysctl hw.ncpu 2> /dev/null > /dev/null; then
CPUS=$(sysctl hw.ncpu | sed -E -e 's/^hw\.ncpu(: | = )//')
else
CPUS=1
fi
PARALLEL=-j$((CPUS + 1))
fi
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
# Pull in the local configuration, if any
if [ -f local.sh ]; then
. ./local.sh
fi
MAKEFLAGS=${PARALLEL} ${MAKESILENT}
TARFLAGS=v
MAKESILENT=
if [ ${QUIET} != 0 ]; then
TARFLAGS=
MAKESILENT="-s"
fi
export PATH="${PREFIX}/bin:${PATH}"
SUMMON_DIR=${WORKDIR}
SOURCES=${SUMMON_DIR}/sources
STAMPS=${SUMMON_DIR}/stamps
##############################################################################
# OS and Tooldetection section
# Detects which tools and flags to use
##############################################################################
# normalized fetching with whatever we can find
if which fetch > /dev/null; then
FETCHCMD="fetch -p"
elif which wget > /dev/null; then
FETCHCMD="wget -c"
elif which curl > /dev/null; then
FETCHCMD="curl -C - -O -L"
else
FETCHCMD=ftp # the only HTTP client on some BSD
fi
if [ USE_LINARO = 1 ]; then
if which gnutar > /dev/null; then
TAR=gnutar
elif which gtar > /dev/null; then
TAR=gtar
else # hopefully it understands the GNU format
TAR=tar
fi
else
TAR=tar # use the system tar
fi
if [ -z ${MAKE} ]; then
if which gnumake > /dev/null; then
export MAKE=gnumake
elif which gmake > /dev/null; then
export MAKE=gmake
else
export MAKE=make # should be GNU make
fi
fi
if which sha1sum > /dev/null; then
SHA1SUM=sha1sum
elif which shasum > /dev/null; then
SHA1SUM="shasum -a 1"
else
SHA1SUM=""
fi
##############################################################################
# Building section
# You probably don't have to touch anything after this
##############################################################################
# Fetch a versioned file from a URL
dofetch() {
if [ ! -e ${STAMPS}/$1.fetch ]; then
log "Downloading $1 sources..."
${FETCHCMD} $2
touch ${STAMPS}/$1.fetch
fi
}
# Log a message out to the console
log() {
echo "******************************************************************"
echo "* $*"
echo "******************************************************************"
}
# Unpack an archive
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 "leaving the decision to tar"
TYPE=
;;
esac
${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
}
# Install a build
doinstall() {
log $1
${SUDO} ${MAKE} ${MAKESILENT} $2 $3 $4 $5 $6 $7 $8
}
if [ ! -d $SUMMON_DIR ]; then
mkdir -p ${SUMMON_DIR}
SUMMON_DIR_CREATED=1
else
SUMMON_DIR_CREATED=0
fi
mkdir -p ${STAMPS} ${SOURCES}
cd ${SOURCES}
dofetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
dofetch ${GCC} ${GCCURL}
dofetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
dofetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
dofetch ${GMP} ftp://ftp.gmplib.org/pub/${GMP}/${GMP}.tar.bz2
dofetch ${MPFR} http://www.mpfr.org/${MPFR}/${MPFR}.tar.bz2
dofetch ${MPC} http://www.multiprecision.org/mpc/download/${MPC}.tar.gz
if [ "X${SHA1SUM}" != "X" ]; then
for f in ${BINUTILS} ${GCC} ${NEWLIB} ${GDB} ${GMP} ${MPFR} ${MPC}; do
( echo "${SHA1SUMS}" | grep -F $f | ${SHA1SUM} -c - ) || ( log 'ERROR: Checksum fail!'; exit 1 )
done
else
log "WARING: skipping checksum checks due to missing sha1sum"
fi
cd ${SUMMON_DIR}
if [ ! -e build ]; then
mkdir build
fi
if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
unpack ${BINUTILS}
cd build
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}
doinstall ${BINUTILS} install
cd ..
log "Cleaning up ${BINUTILS}"
touch ${STAMPS}/${BINUTILS}.build
rm -rf build/* ${BINUTILS}
fi
if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
unpack ${GCC} boot
unpack ${GMP}
mv ${GMP} ${GCCDIR}/gmp
unpack ${MPFR}
mv ${MPFR} ${GCCDIR}/mpfr
unpack ${MPC}
mv ${MPC} ${GCCDIR}/mpc
cd build
log "Configuring ${GCC}-boot"
../${GCCDIR}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--enable-interwork \
--enable-multilib \
--enable-languages="c" \
--with-newlib \
--without-headers \
--disable-shared \
--with-gnu-as \
--with-gnu-ld \
--disable-nls \
--disable-werror \
--with-system-zlib \
${GCCFLAGS}
log "Building ${GCC}-boot"
${MAKE} ${MAKEFLAGS} all-gcc
doinstall ${GCC}-boot install-gcc
cd ..
log "Cleaning up ${GCC}-boot"
touch ${STAMPS}/${GCC}-boot.build
rm -rf build/* ${GCCDIR}
fi
if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
unpack ${NEWLIB}
cd build
log "Configuring ${NEWLIB}"
# configuration options and flags partially
# from https://github.com/jsnyder/arm-eabi-toolchain
../${NEWLIB}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--enable-interwork \
--enable-multilib \
--with-gnu-as \
--with-gnu-ld \
--disable-nls \
--disable-werror \
--disable-newlib-supplied-syscalls \
--enable-newlib-io-long-long \
--disable-shared \
--with-float=soft
log "Building ${NEWLIB}"
NEWLIB_FLAGS="-ffunction-sections -fdata-sections -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -Os -g -fomit-frame-pointer -fno-unroll-loops -D__BUFSIZ__=256 -mabi=aapcs"
${MAKE} ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
doinstall ${NEWLIB} install
cd ..
log "Cleaning up ${NEWLIB}"
touch ${STAMPS}/${NEWLIB}.build
rm -rf build/* ${NEWLIB}
fi
# Yes, you need to build gcc again!
if [ ! -e ${STAMPS}/${GCC}.build ]; then
unpack ${GCC}
unpack ${GMP}
mv ${GMP} ${GCCDIR}/gmp
unpack ${MPFR}
mv ${MPFR} ${GCCDIR}/mpfr
unpack ${MPC}
mv ${MPC} ${GCCDIR}/mpc
cd build
log "Configuring ${GCC}"
[ ${USE_CPP} = 1 ] && GCCFLAGS="--enable-languages='c,c++' ${GCCFLAGS}"
../${GCCDIR}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--enable-interwork \
--enable-multilib \
--with-newlib \
--disable-shared \
--with-gnu-as \
--with-gnu-ld \
--disable-nls \
--disable-werror \
--with-system-zlib \
${GCCFLAGS}
log "Building ${GCC}"
${MAKE} ${MAKEFLAGS}
doinstall ${GCC} install
cd ..
log "Cleaning up ${GCC}"
touch ${STAMPS}/${GCC}.build
rm -rf build/* ${GCCDIR}
fi
if [ ! -e ${STAMPS}/${GDB}.build ]; then
GDB_ETC_PATH="${PREFIX}/etc/gdb"
GDB_INIT_PATH="${GDB_ETC_PATH}/gdbinit"
GDB_TARGET_PATH="${GDB_ETC_PATH}/target.xml"
unpack ${GDB}
cd build
log "Configuring ${GDB}"
../${GDB}/configure --target=${TARGET} \
--prefix=${PREFIX} \
--enable-interwork \
--enable-multilib \
--disable-werror \
--with-system-gdbinit=${GDB_INIT_PATH} \
${GDBFLAGS}
log "Building ${GDB}"
${MAKE} ${MAKEFLAGS}
doinstall ${GDB} install
cd ..
log "Cleaning up ${GDB}"
touch ${STAMPS}/${GDB}.build
rm -rf build/* ${GDB}
# Workaround for OpenOCD 0.5.0 incompatibility with recent
# GDB versions.
#
# Source: http://lists.berlios.de/pipermail/openocd-development/2011-August/020823.html
mkdir -p ${GDB_ETC_PATH}
cat > ${GDB_INIT_PATH} <<END
set tdesc filename ${GDB_TARGET_PATH}
END
cat > ${GDB_TARGET_PATH} <<END
<?xml version="1.0"?>
<!DOCTYPE target SYSTEM "gdb-target.dtd">
<target>
<feature name="org.gnu.gdb.arm.core">
<reg name="r0" bitsize="32" type="uint32"/>
<reg name="r1" bitsize="32" type="uint32"/>
<reg name="r2" bitsize="32" type="uint32"/>
<reg name="r3" bitsize="32" type="uint32"/>
<reg name="r4" bitsize="32" type="uint32"/>
<reg name="r5" bitsize="32" type="uint32"/>
<reg name="r6" bitsize="32" type="uint32"/>
<reg name="r7" bitsize="32" type="uint32"/>
<reg name="r8" bitsize="32" type="uint32"/>
<reg name="r9" bitsize="32" type="uint32"/>
<reg name="r10" bitsize="32" type="uint32"/>
<reg name="r11" bitsize="32" type="uint32"/>
<reg name="r12" bitsize="32" type="uint32"/>
<reg name="sp" bitsize="32" type="data_ptr"/>
<reg name="lr" bitsize="32"/>
<reg name="pc" bitsize="32" type="code_ptr"/>
<reg name="cpsr" bitsize="32" regnum="25"/>
</feature>
<feature name="org.gnu.gdb.arm.fpa">
<reg name="f0" bitsize="96" type="arm_fpa_ext" regnum="16"/>
<reg name="f1" bitsize="96" type="arm_fpa_ext"/>
<reg name="f2" bitsize="96" type="arm_fpa_ext"/>
<reg name="f3" bitsize="96" type="arm_fpa_ext"/>
<reg name="f4" bitsize="96" type="arm_fpa_ext"/>
<reg name="f5" bitsize="96" type="arm_fpa_ext"/>
<reg name="f6" bitsize="96" type="arm_fpa_ext"/>
<reg name="f7" bitsize="96" type="arm_fpa_ext"/>
<reg name="fps" bitsize="32"/>
</feature>
</target>
END
fi
if [ ${SUMMON_DIR_CREATED} = 1 ]; then
log "Removing work directory"
rm -rf ${SUMMON_DIR}
fi