#!/bin/sh

config=src/util/config.ml
makefileconfig=share/Makefile.config

bindir="\"$BINDIR\""
libdir="\"$LIBDIR/why3\""
datadir="\"$DATADIR/why3\""
ocamllib="\"@OCAMLINSTALLLIB@/why3\""
localdir="None"

if [ "@enable_relocation@" = "yes" ]; then
    libdir='Filename.concat (Filename.concat (Filename.dirname
        (Filename.dirname Sys.executable_name)) "lib") "why3"'
    datadir='Filename.concat (Filename.concat (Filename.dirname
        (Filename.dirname Sys.executable_name)) "share") "why3"'
    localdir="None"
elif [ "@enable_local@" = "yes" ]; then
    bindir="\"@LOCALDIR@/bin\""
    libdir="\"@LOCALDIR@/lib\""
    datadir="\"@LOCALDIR@/share\""
    ocamllib="\"@LOCALDIR@/lib/why3\""
    localdir="Some \"@LOCALDIR@\""
fi

echo "
let version   = \"@VERSION@\"
let editor    = \"@EDITOR@\"

let libdir    = $libdir
let datadir   = $datadir
let localdir  = $localdir
" > $config.new

if cmp -s $config $config.new; then
    rm $config.new
else
    mv $config.new $config
fi

echo "
OCAMLBEST   = @OCAMLBEST@
BIGINTLIB   = @BIGINTLIB@
MPFRLIB     = @MLMPFR@
INFERLIB    = @INFERLIB@
STACKIFY    = @enable_stackify@
INCLUDE     = @BIGINTINCLUDE@ -I $ocamllib
EXTPKGS     = menhirLib @RELIB@ unix num dynlink @ZIPLIB@ @MLMPFR@ @WHY3LIB@ @INFERPKG@ @SEXPLIB@ @SEXPLIBPPX@
" > $makefileconfig

if [ "@enable_ocamlfind@" = "yes" ]; then
echo "OCAMLFIND   = @OCAMLFIND@" >> $makefileconfig
fi

if [ "@enable_relocation@" = "no" ]; then

echo "
BINDIR      = $bindir
LIBDIR      = $libdir
DATADIR     = $datadir
" >> $makefileconfig

fi
