#!/bin/sh
# configure script for Gauss package,
# usage: ./configure gappath
# this script creates a `Makefile' from `Makefile.in'
for argument in $@; do
  case "$argument" in
    *--without-gac*)
      GAC=0;;
    *)
      GAPPATH="$argument";;
  esac;
done

if [ x"$GAPPATH" = "x" ]; then
    GAPPATH=../..; echo "Using ../.. as default GAP path"
fi

if [ x"$GAC" = "x" ]; then
    GAC=1; echo "Using gac to compile.
If you do not want this, run this script with --without-gac."
else
    echo "Using the old scripts to compile. 
If you run GAP 4.5 or higher, this wont work."
fi

rm -f makefile Makefile
. "$GAPPATH"/sysinfo.gap
case "$GAParch" in
  i?86*)
    EXTRA_COPTS=-m32
    ;;
  x86_64*)
    EXTRA_COPTS=-m64
    ;;
esac
echo "GAPPATH=$GAPPATH" > Makefile

cleanGAParch=$(echo $GAParch | sed 's|:|\\:|g')
cleanEXTRA_COPTS=$(echo $EXTRA_COPTS | sed 's|:|\\:|g')
sed -e "s:@GAPARCH@:$GAParch:g" -e "s:@EXTRACOPTS@:$EXTRA_COPTS:g" Makefile.in >> Makefile

# We let gac do the work for us!
 case "$GAParch" in
   *apple-darwin*)
     case "$GAC" in
      *1*)
        sed -e "s:@GAPARCH@:$GAParch:g" -e "s:@EXTRACOPTS@:$EXTRA_COPTS:g" Makefile.darwin.in >> Makefile
        ;;
      *)
        sed -e "s:@GAPARCH@:$GAParch:g" -e "s:@EXTRACOPTS@:$EXTRA_COPTS:g" Makefile.darwin.4.4.in >> Makefile
        ;;
      esac
    ;;
   *)
     case "$GAC" in
      *1*)
        sed -e "s:@GAPARCH@:$GAParch:g" -e "s:@EXTRACOPTS@:$EXTRA_COPTS:g" Makefile.linux.in >> Makefile
        ;;
      *)
        sed -e "s:@GAPARCH@:$GAParch:g" -e "s:@EXTRACOPTS@:$EXTRA_COPTS:g" Makefile.linux.4.4.in >> Makefile
        ;;
      esac
    ;;
 esac
