
# Usage
# sudo ./build_gcc

# Setup vars
export TARGET=arm-none-eabi
export PREFIX=/gnuarm
export PATH=$PATH:$PREFIX/bin

rm -rf build-*
rm -rf gcc-*
rm -rf binutils-*

# Get archives
wget http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2
wget http://ftp.gnu.org/gnu/gcc/gcc-4.7.0/gcc-4.7.0.tar.bz2

# Extract archives
bzip2 -dc binutils-2.22.tar.bz2 | tar -xf -
bzip2 -dc gcc-4.7.0.tar.bz2 | tar -xf -

# Build binutils
mkdir build-binutils
cd build-binutils
../binutils-2.22/configure --target=$TARGET --prefix=$PREFIX
make all
make install

# Build GCC
mkdir ../build-gcc
cd ../build-gcc
../gcc-4.7.0/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib  --with-gnu-as --with-gnu-ld
make all-gcc
make install-gcc

# Build libgcc.a
make all-target-libgcc CFLAGS_FOR_TARGET="-g -O2"
make install-target-libgcc

