#!/bin/bash
#

if [ $# -gt 1 ]; then
  echo "PHAVer installation script"
  echo "Usage: bash build-phaver.sh [path]"
  echo "   path : directory into which to install"
  echo "          (default: $HOME/local)"
  exit 1
fi


if [ $# -eq 0 ]; then
  echo "Using default path"
fi

# Use second argument as path to install directories
MYPREFIX=$HOME/local
if [ $# -eq 1 ]; then
  MYPREFIX=$1
fi

if [ -d "phaver" ]; then
  echo "PHAVer directory exists, recompiling."
else
  echo "PHAVer directory does not exist, unziping sources..."
#  wget http://www-verimag.imag.fr/~frehse/phaver_web/phaver.zip || exit 1;
  tar zxvf phaver.tgz || exit 1
#  unzip phaver.zip || exit 1;
#  rm phaver.zip || exit 1;
fi

cd phaver || exit 1;
CFLAGS=-I$MYPREFIX/include CXXFLAGS=-I$MYPREFIX/include LDFLAGS="-L$MYPREFIX/lib -lgmp -lgmpxx -lppl -lgmpxx -lgmp -dynamic" ./configure --prefix=$MYPREFIX || exit 1;
make clean || exit 1;
make || exit 1;
make install || exit 1;

echo "----------------------------------------------"
echo "PHAVer is now located in $MYPREFIX/bin."
echo "Please add this directory to your path."

