#!/bin/sh
#
# Constants that must be adjusted
#
SRC_DIR=Src
TOOL_DIR=Tools
#
#######################################################################
echo "This script should make it easier for you to install Cubpack++."
echo "An appropriate makefile is selected based on the brand of unix"
echo "you use."
echo "Available are"
echo "               (1) IBM RS6000 - AIX - XlC compiler"
echo "               (2) DEC alpha - DEC OSF - cxx compiler"
echo "               (3) Unix gnu - gcc or g++ compiler"
echo "               (4) Solaris 2.* - CC compiler version 4.*"
echo
echo "Make your choice. \c"
read x
case $x in
    1)
      cp $TOOL_DIR/mkfile.rs6000 $SRC_DIR/makefile;;
    2)
      cp $TOOL_DIR/mkfile.decalpha $SRC_DIR/makefile;;
    3)
      OLDVERSION1=2.6.0
      OLDVERSION2=2.7.0
      gcc -v 2> tmp$$
      v=`tail -1 tmp$$ | sed "s/^.*version //" | sed "s/ .*$//"`
      /bin/rm tmp$$
      echo "You are using gcc version $v"
      a=`expr "$v" ">" "$OLDVERSION2"`
      if test $a =  "1"
        then
           cp $TOOL_DIR/mkfile.gn3 $SRC_DIR/makefile
        else
           a=`expr "$v" ">" "$OLDVERSION1"`
           if test $a =  "1"
             then
                cp $TOOL_DIR/mkfile.gn2 $SRC_DIR/makefile
             else
                cp $TOOL_DIR/mkfile.gn1 $SRC_DIR/makefile
           fi
      fi;;
    4)
      cp $TOOL_DIR/mkfile.solaris $SRC_DIR/makefile;;
    *)
      echo "This was an illegal choice!"
      exit 1 ;;
esac
#######################################################################
if test -f .lastinstall
  then
     y=`cat .lastinstall`
     /bin/rm -f .lastinstall
     if test $x != $y 
       then 
           echo "Removing the remains of a previous compilation which might interfere ..."
           cd $SRC_DIR
           make clean
           cd ..
           echo "... Done."
     fi
fi
echo $x > .lastinstall
#######################################################################
echo "Do you want to edit the makefile first? [n/y] \c"
read a
case $a in
    [Yy]*)
          vi $SRC_DIR/makefile ;;
esac
#######################################################################
#
echo
echo "Compilation will now start. This will take a while."
echo
cd $SRC_DIR
make all
