#!/bin/bash 

wannacontinue ()
{
 while true
 do
  echo -n -e \\007"Process this step? (Y/N) "  
  read ians
  echo "" 
  case $ians in
   [Yy] ) return 0;;
   [Nn] ) return 1;;
   * ) echo "Answer Y or N";;
  esac
 done 
}

echo "-------------- step1"
echo "fetch source files."
echo ""
echo dans $HOME il doit y avoir:
echo "" 
echo "- cvs tel qu'il a ete telecharge"
echo "- les fichiers include dans cvs"
echo ""
echo "et c tout"


echo "-------------- step2"
echo host system setup
export MACH=i386-linux
export DEST=~/dest
export PATH=$DEST/bin:$PATH
echo MACH=$MACH
echo DEST=$DEST
echo PATH=$PATH

echo "-------------- step3"
echo configure and build binutils
cd

if wannacontinue
then
 ln -s cvs source
 mkdir build
 mkdir dest
 cd ~/build
 mkdir binutils
 cd binutils
 ~/source/binutils/configure --host=$MACH --prefix=$DEST --target=hppa-linux --enable-targets=hppa64-linux --disable-nls 
 make && make install
fi

 echo "------------- step4"
 echo configure and partially build gcc:
if wannacontinue
then
 cd ~/source/gcc
 contrib/gcc_update --touch
 cd ~/build
 mkdir gcc
 cd gcc
 ~/source/gcc/configure --host=$MACH --prefix=$DEST --target=hppa-linux --enable-shared --disable-nls
# We don't want to attempt any target library builds yet, and configure
# currently has no option for this. :-(  Thus zap the directories...
 rm -r zlib hppa-linux
# Only build the C compiler at this stage.  We build the rest after glibc.
 make LANGUAGES=c && make LANGUAGES=c install
fi

 echo "------------- step5"
 echo Unpack and configure the kernel:
if wannacontinue
then
 cd ~/source/linux
 make oldconfig
 make dep
fi

 echo "------------- step6"
 echo Configure and build glibc:
if wannacontinue
then
 cd ~/build
 mkdir glibc
 cd glibc
# Yes, --host and --prefix options are different here.  That's because we are
# compiling glibc for our target machine.  This glibc "runs on" hppa-linux.
 ~/source/glibc/configure --host=hppa-linux --build=$MACH --prefix=$DEST/hppa-linux --with-headers=$HOME/source/linux/include --disable-profile --without-cvs --enable-add-ons
 make && make install
 cd $DEST/hppa-linux/include
 ln -s --force ~/source/linux/include/linux .
 ln -s --force ~/source/linux/include/asm .
fi

 echo "------------- step7"
 echo Reconfigure and fully build gcc:
if wannacontinue
then
 cd ~/build/gcc
 ~/source/gcc/configure --host=$MACH --prefix=$DEST --target=hppa-linux --enable-shared --disable-nls
 make &&  make install
fi

 echo -e \\007
 echo "That's all folks!"







