#!/bin/bash
# configure script for Gauss package, Max Neunhoeffer
# usage: ./configure gappath
# this script creates a `makefile' from `Makefile.in'
if [ x"$1" = "x" ]; then
    GAPPATH=../..; echo "Using ../.. as default GAP path"
else
    GAPPATH="$1"
fi
rm -f makefile Makefile
. "$GAPPATH"/sysinfo.gap
case "$GAParch" in
  *default32*)
    EXTRA_COPTS=-m32
    ;;
  *default64*)
    EXTRA_COPTS=-m64
    ;;
esac
echo "GAPPATH=$GAPPATH" > Makefile
# echo "SRCDIR=$(readlink -f "$(dirname "$0")")" >> Makefile
echo -n "PM_CFLAGS=" >> Makefile
echo -n $(polymake-config --cflags) >> Makefile
echo -n " " >> Makefile
echo $(polymake-config --includes) >> Makefile
echo -n "PM_LDFLAGS=" >> Makefile
echo -n $(polymake-config --libs | sed "s|-lgmp||g") >> Makefile
echo -n " " >> Makefile
echo $(polymake-config --ldflags) >> Makefile
echo -n "CXX=" >> Makefile
echo $(polymake-config --cc) >> Makefile

sed "s/@GAPARCH@/$GAParch/g;s/@EXTRA_COPTS@/$EXTRA_COPTS/g;" Makefile.in >> Makefile
case "$GAParch" in
  *linux*)
    sed "s/@GAPARCH@/$GAParch/g;s/@EXTRA_COPTS@/$EXTRA_COPTS/g;" Makefile.linux.in >> Makefile
    ;;
  *darwin*)
    sed "s/@GAPARCH@/$GAParch/g;s/@EXTRA_COPTS@/$EXTRA_COPTS/g;" Makefile.darwin.in >> Makefile
    ;;
esac
    
# case "$GAParch" in
#   *linux*)
#     sed "s/@GAPARCH@/$GAParch/g;s/@EXTRACOPTS@/$EXTRA_COPTS/g;" Makefile.linux.in >> Makefile
#     ;;
#   *apple-darwin*)
#     sed "s/@GAPARCH@/$GAParch/g;s/@EXTRACOPTS@/$EXTRA_COPTS/g;" Makefile.darwin.in >> Makefile
#     ;;
#   *)
#     echo "Unsupported architecture. If you manage to compile MapleForHomalg on this"
#     echo "architecture, please send a patch to thomas@momo.math.rwth-aachen.de."
#     rm -f Makefile
#     exit 1
# esac

# #!/bin/sh
# # usage: configure gappath
# # this script creates a `Makefile' from `Makefile.in' 
# if test -z $1; then 
#   GAPPATH=../..; echo "Using ../.. as default GAP path"; 
# else 
#   GAPPATH=$1; 
# fi  
# if ! test -e $GAPPATH/sysinfo.gap; then
#   echo "Please give correct GAP path as argument (and make sure that GAP"
#   echo "is already properly installed)."
#   exit
# fi
# rm -f Makefile sedfile
# cat $GAPPATH/sysinfo.gap > Makefile
# echo "echo s/@GAPARCH@/\$GAParch/g >sedfile" >> Makefile
# chmod +x Makefile
# ./Makefile
# rm -f Makefile
# echo "GAPPATH=$GAPPATH" > Makefile
# sed -f sedfile Makefile.in >> Makefile
# rm -f sedfile
# 
