GNU Cross Tool-chain Building Instructions

These are instruction to build a GNU cross tool-chain from your host system to a target system whose architecture is $ARCH. The tool-chain will be installed under /usr/local/$ARCH.

#/bin/sh
# GNU Tool-chain for EPOS

ARCH=avr
BINUTILS=binutils-2.16.1
GCC=gcc-4.0.2
NEWLIB=newlib-1.14.0

TARGET=$ARCH-elf
PREFIX=/usr/local/$ARCH/$GCC
PROG_PREFIX=$ARCH-

BUILD=/tmp
CONTRIB=/tmp


# Wget
cd $CONTRIB
if [ ! -e $BINUTILS.tar.bz2 ] ; then
    wget ftp://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
fi
if [ ! -e $GCC.tar.bz2 ] ; then
    wget ftp://ftp.gnu.org/gnu/gcc/$GCC.tar.bz2
fi
if [ ! -e $NEWLIB.tar.gz ] ; then
    wget ftp://sources.redhat.com/pub/newlib/$NEWLIB.tar.gz
fi

# Unpack
cd $BUILD
tar jxf $CONTRIB/$BINUTILS.tar.bz2 
tar jxf $CONTRIB/$GCC.tar.bz2
tar zxf $CONTRIB/$NEWLIB-1.14.0.tar.gz

# Binutils
cd $BUILD
mkdir $TARGET-binutils-build
cd $TARGET-binutils-build
../$BINUTILS/configure --target=$TARGET --prefix=$PREFIX --program-prefix=$PROG_PREFIX 
make
make install
ln -s $PREFIX/bin/$PROG_PREFIX""ar $PREFIX/bin/$TARGET-ar
ln -s $PREFIX/bin/$PROG_PREFIX""as $PREFIX/bin/$TARGET-as
ln -s $PREFIX/bin/$PROG_PREFIX""ld $PREFIX/bin/$TARGET-ld
ln -s $PREFIX/bin/$PROG_PREFIX""ranlib $PREFIX/bin/$TARGET-ranlib
cd $BUILD
rm -rf $TARGET-binutils-build

# GCC (C-only)
cd $BUILD
mkdir $TARGET-gcc-build
cd $TARGET-gcc-build
export PATH=$PATH:$PREFIX/bin
../$GCC/configure --target=$TARGET --prefix=$PREFIX --program-prefix=$PROG_PREFIX --enable-languages=c
make
make install
ln -s $PREFIX/bin/$PROG_PREFIX""gcc $PREFIX/bin/$TARGET-cc
cd $BUILD
rm -rf $TARGET-gcc-build

# Newlib
cd $BUILD
cd $NEWLIB
./configure --target=$TARGET --prefix=$PREFIX
make
make install

# GCC (C and C++)
cd $BUILD
mkdir $TARGET-gcc-build
cd $TARGET-gcc-build
../$GCC/configure --target=$TARGET --prefix=$PREFIX --program-prefix=$PROG_PREFIX --enable-languages=c,c++ --disable-nls --disable-multilib --with-newlib --disable-shared --enable-target-optspace --with-gnu-as --with-gnu-ld --without-headers   
make
make install
cd $BUILD
rm -rf $TARGET-gcc-build

# Clean up
find $PREFIX/bin -type l -exec rm \{} \;
cd $BUILD
rm -rf $BINUTILS
rm -rf $GCC
rm -rf $NEWLIB