#!/bin/bash
# Brif: This is the scrip for build arm-elf tools.
# Source file: binutils-2.17.tar.bz2,gcc-4.1.1.tar.bz2,gdb-6.6.tar.bz2,newlib-1.14.0.tar.gz
#
# Notes: Please run this script with the root account or you can run "sudo bash"
# Express all the compressed file to WORK_PWD below
#
# Author: Volans Wang
# volansw@gmail.com
#
#source directory and target director
WORK_PWD=$(pwd)
echo $WORK_PWD
TARGET_PWD="/usr/local/arm/gnuarm4.1.1"
GCC_SOURCE="/home/volans/gcc4/gcc-4.1.1"
BINUTILS_SOURCE="/home/volans/gcc4/binutils-2.17"
LIB_SOURCE="/home/volans/gcc4/newlib-1.14.0"
GDB_SOURCE="/home/volans/gcc4/gdb-6.6"
#make configure
BINUTILS_CONFIG="--target=arm-elf --prefix=$TARGET_PWD --enable-interwork --enable-multilib --with-float=soft"
GCC_CONFIG="--target=arm-elf --prefix=$TARGET_PWD --enable-interwork --enable-multilib --enable-languages=c,c++ --with-newlib --with-headers=$LIB_SOURCE/newlib/libc/include --with-float=soft"
LIB_CONFIG=$BINUTILS_CONFIG
GDB_CONFIG=$BINUTILS_CONFIG
#export the cross compiler to the PATH
export PATH="$PATH:$TARGET_PWD/bin"
#make target dir for install if possible
if [ -d $TARGET_PWD ]; then
rm -rf $TARGET_PWD
mkdir $TARGET_PWD
else
mkdir $TARGET_PWD
fi
######## make binutils #########################
cd $BINUTILS_SOURCE
#configure
./configure $BINUTILS_CONFIG
#make
make all install
#################################################
######### make gcc for build new lib ############
cd $GCC_SOURCE
#configure
./configure $GCC_CONFIG
#make
make all-gcc install-gcc
#################################################
########## make new lib #########################
cd $LIB_SOURCE
#configure
./configure $LIB_CONFIG
#make
make all install
#################################################
######## make all gcc ###########################
cd $GCC_SOURCE
make all install
#################################################
######### make gdb ##############################
cd $GDB_SOURCE
#configure
./configure $GDB_CONFIG
make all install
#################################################