#!/bin/sh
#
# log/script for building arm-uclinux cross toolchain
# all files downloaded from ftp://ftp.wirespeed.com/uclinux
#
#	arm_uclinux_binutils_10_31_2000.tar.gz
#	arm_uclinux_gcc_10_31_2000.tar.gz
#	uC-glibc-2.1.3-10112000.tar.gz
#	ldelf2flt-12192000.tar.gz
#
# Download all files to one directory and run script there
#
# Must run as root or chmod 777 /usr/local
#  do to install into default prefix=/usr/local
#
# -jea 6/12/2001
#
# default install directory was already in my path
#export PATH=/usr/local/bin:$PATH
export KERNEL_SRC=/home/johnea/TA7Lx/kernel/linux
export PREFIX=/usr/local/arm-wirespeed-uclinux

echo "#########################################################"
echo "#"
echo "# Building arm-uclinux in " `pwd`
echo "#  Install Prefix = ${PREFIX}"
echo "#  Kernel Source = ${KERNEL_SRC}"
echo "#"
echo "# Copying uClinux headers"
echo "#########################################################"
# make dir and create kernel header links into install dir
mkdir -p ${PREFIX}/arm-uclinux/include 
cp -r ${KERNEL_SRC}/include/linux ${PREFIX}/arm-uclinux/include
cp -r ${KERNEL_SRC}/include/asm-armnommu ${PREFIX}/arm-uclinux/include/asm
#ln -s ${KERNEL_SRC}/include/linux ${PREFIX}/arm-uclinux/include/linux
#ln -s ${KERNEL_SRC}/include/asm-armnommu ${PREFIX}/arm-uclinux/include/asm

# configure, compile and install binutils
tar xzf arm_uclinux_binutils_10_31_2000.tar.gz
mkdir build-binutils
cd build-binutils
echo "#########################################################"
echo "#"
echo "# Building binutils in " `pwd`
echo "#"
echo "#########################################################"
# configure
../arm_uclinux_binutils/configure --target=arm-uclinux --prefix=$PREFIX 2>&1 | tee configure.log
# compile
make all 2>&1 | tee make.log
if [ $? != 0 ]; then
    echo "Compiling binutils failed." && exit 1;
fi

# install
make install 2>&1 | tee install.log
cd ..

# make a bootstrap gcc with no lib support
tar xzf arm_uclinux_gcc_10_31_2000.tar.gz
mkdir build-boot-gcc
cd build-boot-gcc
echo "#########################################################"
echo "#"
echo "# Building bootstrap-gcc in " `pwd`
echo "#"
echo "#########################################################"
## configure
../arm_uclinux_gcc/configure --target=arm-uclinux --prefix=$PREFIX --with-local-prefix=${PREFIX}/arm-uclinux --enable-languages=c 2>&1 | tee boot-configure.log.bs
# compile with CFLAGS+=-Dinhibit_libc to avoid uninstalled headers
make all-gcc CFLAGS+=-Dinhibit_libc 2>&1 | tee boot-make.log.bs
if [ $? != 0 ]; then
    echo "Compiling bootstrap-gcc failed." && exit 1;
fi
# install
make install-gcc 2>&1 | tee boot-install.log.bs
cd ..

# config, make and install glibc
tar xzf uC-glibc-2.1.3-10112000.tar.gz
mkdir build-glibc
cd build-glibc
echo "#########################################################"
echo "#"
echo "# Building glibc in " `pwd`
echo "#"
echo "#########################################################"
## configure
../glibc-2.1.3-uclinux-arm/configure --host=arm-uclinux --enable-add-ons --prefix=${PREFIX}/arm-uclinux --with-headers=${PREFIX}/arm-uclinux/include --without-fp --program-prefix="arm-uclinux-" --disable-profile --enable-omit-fp --disable-shared --enable-static-nss --disable-libio  2>&1 | tee configure.log
if [ $? != 0 ]; then
    echo "Configuring glibc failed." && exit 1;
fi
# compile
make all 2>&1 | tee make.log
if [ $? != 0 ]; then
    echo "Compiling glibc failed." && exit 1;
fi
# install
make install -v 2>&1 | tee install.log
cd ..

# cleanup, recompile and install a full gcc now that glibc headers are installed
tar xzf arm_uclinux_gcc_10_31_2000.tar.gz
mkdir build-gcc
cd build-gcc
echo "#########################################################"
echo "#"
echo "# Building gcc in " `pwd`
echo "#"
echo "#########################################################"
# configure
../arm_uclinux_gcc/configure --target=arm-uclinux --prefix=$PREFIX --with-local-prefix=${PREFIX}/arm-uclinux --enable-languages=c,c++ 2>&1 | tee configure.log
if [ $? != 0 ]; then
    echo "Configuring gcc failed." && exit 1;
fi
# compile
make all 2>&1 | tee make.log
if [ $? != 0 ]; then
    echo "Compiling gcc failed." && exit 1;
fi
# install
make install 2>&1 | tee install.log
cd ..


# configure, compile and install elf2flt
tar xzf ldelf2flt-12192000.tar.gz
cd ldelf2flt
# configure
./configure
# compile 
make
# install
make install
cd ..

# ready to build a kernel and apps!



