#!/bin/sh

##################################
#
#  Configuration script for otags
# 
##################################
root=/usr/local
bindir=$root/bin
bindir_spec=no
libdir=$root/lib/ocaml/camlp4
#libdir=`camlp4 -where`
libdir_spec=no
#splaydir=$root/lib/ocaml
#splaydir_spec=no

usage (){
    echo "Usage:"
#    echo "./configure [--prefix <path>] [--bindir <path>] [--libdir <path>] [--splaydir <path>] "
    echo "./configure [--prefix <path>] [--bindir <path>] [--libdir <path>]"
    echo "./configure --prefix /foo is equivalent to"
#    echo "./configure --bindir /foo/bin --libdir /foo/lib/ocaml --splaydir /foo/lib/ocaml"
    echo "./configure --bindir /foo/bin --libdir /foo/lib/ocaml"
    echo "Default: prefix = /usr/local"
}

while : ; do
  case "$1" in
    "") break;;
    -help|--help) usage; exit 2;;
    -prefix|--prefix) bindir_spec=yes
                      bindir=$2/bin
                      libdir_spec=yes
                      libdir=$2/lib/ocaml
#                      splaydir_spec=yes
#                      splaydir=$2/lib/ocaml
		      shift;;
    -bindir|--bindir) bindir_spec=yes
                      bindir=$2
		      shift;;
    -libdir|--libdir) libdir_spec=yes
                      libdir=$2
		      shift;;
#    -splaydir|--splaydir) splaydir_spec=yes
#                      splaydir=$2
#		      shift;;
     *) echo "Unknown option \"$1\"." 1>&2; exit 2;;
  esac
  shift
done

#  if [ -f $splaydir/splay.cma ]
#      then echo "splay trees found in $splaydir"
#      else
#        echo "No splay lib in $splaydir";
#        echo "use ./configure --splaydir <dir>";
#        exit
#  fi

./mk_config $libdir $bindir > config.ml

# Summary of the configuration
echo
echo "  Paths for true installation:"
echo "    binaries   will be copied in $bindir"
echo "    library    will be copied in $libdir"

sed -e "s|tplbin|$bindir|" \
    -e "s|tpllib|$libdir|" \
    Makefile.here.tpl > Makefile.here
#    -e "s|tplsplay|$splaydir|" \
