#!/bin/sh -e
PREFIX=~/arm-linux
KERNEL=/home/rmk/v2.5/linux-rpc/
#HOST=sparc-linux
HOST=
mkdir -p $PREFIX
if [ "$KERNEL" = "" -o ! -f "$KERNEL/Documentation/arm/README" ]; then
  echo "You haven't changed KERNEL to point at a valid kernel tree"
  exit 1
fi
if [ ! -f binutils-2.11.2.tar.gz ]; then
  echo Binutils 2.11.2 seems to be missing
  exit 1
fi
if [ ! -f gcc-2.95.3.tar.gz ]; then
  echo GCC 2.95.3 seems to be missing
  exit 1
fi
if [ ! -f gcc-2.95.3.diff.bz2 ]; then
  echo GCC 2.95.3 diff seems to be missing
  exit 1
fi
tar zxf binutils-2.11.2.tar.gz
pushd binutils-2.11.2
./configure --target=arm-linux --prefix=$PREFIX
make 
make install
popd
rm -rf binutils-2.11.2
PATH=$PATH:$PREFIX/bin
rm -rf gcc-2.95.3
tar zxf gcc-2.95.3.tar.gz
pushd gcc-2.95.3
bzcat ../gcc-2.95.3.diff.bz2 | patch -p1
perl -pi -e 's/^(TARGET_LIBGCC2_CFLAGS.*)/$1 -Dinhibit_libc -D__gthr_posix_h/' gcc/config/arm/t-linux
echo 'T_CFLAGS = -Dinhibit_libc -D__gthr_posix_h' >> gcc/config/arm/t-linux
./configure --target=arm-linux --prefix=$PREFIX $HOST --with-headers=$KERNEL/include
make LANGUAGES=c
make install LANGUAGES=c
popd
rm -rf gcc-2.95.3
