#! /bin/sh
## For the time being, this is a simple shell script ...

## Test whether a complete GLPK library environment is available,
## e.g. ftp://ftp.gnu.org/gnu/glpk/

## Find the R home directory.
: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
  echo "Could not determine R_HOME."
  exit 1
fi

R="${R_HOME}/bin/R"

##SYMPHONY_LIBS="-l"

## Test whether we can compile and link a minimal program.
#3rm -f conftest.*

##cat > conftest.cc <<EOF
#include <glpk.h>
##extern "C"
##int
##main ()
##{
##   sym_environment *env = sym_open_environment();
##    sym_close_environment(env);
##    return 0;
##}
##EOF

##${R} CMD SHLIB conftest.cc ${SYMPHONY_LIBS} >/dev/null 2>&1
##status=${?}

##rm -f conftest.*

##if test ${status} -eq 0; then
##    SYMPHONY_INCLUDE_PATH=
##    SYMPHONY_LIB_PATH=
##    SYMPHONY_TS=
##else    
    (cd src/GLPK && \
	./configure \
	--enable-static --disable-shared --with-pic \
        --disable-dependency-tracking \
	CC="`${R} CMD config CC`" \
	CPP="`${R} CMD config CPP`" \
	CXX="`${R} CMD config CXX`" \
	CXXCPP="`${R} CMD config CXXCPP`" \
	F77="`${R} CMD config F77`" \
	FLIBS="`${R} CMD config FLIBS`")
    GLPK_INCLUDE_PATH="-IGLPK/include"
    GLPK_LIB_PATH="-LGLPK/src/.libs"
    GLPK_TS="GLPK.ts"
##fi

sed -e "s|@GLPK_INCLUDE_PATH@|${GLPK_INCLUDE_PATH}|" \
    -e "s|@GLPK_LIB_PATH@|${GLPK_LIB_PATH}|" \
    -e "s|@GLPK_TS@|${GLPK_TS}|" \
    src/Makevars.in > src/Makevars
