#!/bin/sh
# version $Id$

while [ $# -ne 0 ]; do
   case $1 in 
     --prefix=*)
         prefix=`echo $1 | sed 's/--prefix=//'` ;
         ;;
     --prefix)
         shift;
         prefix="$1";
         ;;
     --libdir=*)
         libdir=`echo $1 | sed 's/--libdir=//'` ;
         ;;
     --libdir)
         shift;
         libdir="$1";
         ;;
     --includedir=*)
         includedir=`echo $1 | sed 's/--includedir=//'` ;
         ;;
     --includedir)
         shift;
         includedir="$1";
         ;;
     *)
         : ignore all other options
         ;;
  esac;
  shift;
done

if test -r ../config.cache; then
  . ../config.cache
fi

if test set${ac_cv_singuname} = set; then
  :
else
  ac_cv_singuname="unknown"
  if test -r "../singuname.sh"; then
    if (/bin/sh ../singuname.sh >/dev/null 2>&1) then
      ac_cv_singuname=`/bin/sh ../singuname.sh`
    fi
  fi
fi

if test "x$SING_CC" = x
then
  SING_CC=gcc
  if test "x$CFLAGS" = x
  then
    CFLAGS="-O2 -fomit-frame-pointer"
  fi
else
  if test "x$CFLAGS" = x
  then
    CFLAGS="-O2"
  fi
fi

if test "x$SING_CXX" = x
then
  SING_CXX=g++
  if test "x$CXXFLAGS" = x
  then
    if test x$ac_cv_cxx_have_exception = xyes
    then
      CXXFLAGS="-O2 -fomit-frame-pointer -fno-rtti -fno-exceptions"
    else
      CXXFLAGS="-O2 -fomit-frame-pointer -fno-rtti"
    fi
  fi
else
  if test "x$CXXFLAGS" = x
  then
    if test x$ac_cv_cxx_have_exception = xyes
    then
      CXXFLAGS="-O2 -fomit-frame-pointer -fno-rtti -fno-exceptions"
    else
      CXXFLAGS="-O2"
    fi
  fi
fi

if test x$ac_cv_header_iostream = xyes
then
  NTL_STD_CXX=on
else
  NTL_STD_CXX=off
fi

CFLAGS="$CPPFLAGS $CFLAGS"
CXXFLAGS="$CPPFLAGS $CXXFLAGS"
DOCDIR=`pwd`/../doc
echo "#!/bin/sh" >config.status
echo "cd src" >>config.status
echo ./configure CC=\"$SING_CC\" CXX=\"$SING_CXX\" LIBDIR=$libdir INCLUDEDIR=$includedir PREFIX=$prefix NTL_GMP_LIP=on GMP_PREFIX=$prefix/${ac_cv_singuname} CFLAGS=\"$CFLAGS\" CXXFLAGS=\"$CXXFLAGS\" LDFLAGS=\"$LDFLAGS\" NTL_STD_CXX=$NTL_STD_CXX DOCDIR=\"$DOCDIR\" >>config.status
echo "cd .." >>config.status

chmod +rx config.status

. ./config.status
