#!/bin/sh
# (C) Frank Lübeck 2011
# configure script for Browse, EDIM and other packages
# usage: ./configure [GAPPATH]
# this script creates a "Makefile-myconf" from "Makefile.in" with
# a link to "Makefile"

# GAP path
if [ $# = 0 ]; then
  GAPPATH="../../"
else
  GAPPATH=$1
fi
echo "Using $GAPPATH as GAP build directory."

if [ ! -e $GAPPATH/sysinfo.gap ]; then
    echo
    echo "No file $GAPPATH/sysinfo.gap found."
    echo
    echo "Usage: ./configure [GAPPATH]"
    echo "       where GAPPATH is a path to your GAP installation"
    echo "       and confnam is the name of the GAP configuration to use."
    echo "       (The default for GAPPATH is \"../..\" and default confignam"
    echo "       is \"default64\" if it exists, otherwise \"default32\".)"
    echo
    echo "Either your GAPPATH is incorrect or the GAP it is pointing to"
    echo "is not properly compiled (do \"./configure ; make\" there first)."
    echo
    echo Aborting... No Makefile is generated.
    echo
    exit 1
fi

echo "Using config in $GAPPATH/sysinfo.gap"

rm -f Makefile
. $GAPPATH/sysinfo.gap
sed \
    -e 's|@GAPPATH@|'$GAPPATH'|g' \
    -e 's/@GAPARCH@/'$GAParch'/g' \
  Makefile.in > Makefile
