#!/bin/sh
# 
# The LOOP Project
# 
# The LOOP Team, Dresden University and Nijmegen University
# 
# Copyright (C) 2010
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License in file COPYING in this or one of the
# parent directories for more details.
# 
# Created 19.10.10 by Hendrik
# 
# CCSL configure script
# 
# $Id: configure,v 1.11 2010-10-19 21:13:04 tews Exp $
# 

ccslversion="2.2.8"

prefix=/usr/local
minimal="0"

usage (){
    echo "configure script for CCSL version $ccslversion"
    echo "Usage:"
    echo "./configure [OPTION]..."
    echo
    echo "Recognized options are:"
    echo "  --prefix <path>	installation prefix [/usr/local]"
}

while : ; do
  case "$1" in
    "") break;;
    -help|--help) usage; exit 2;;
    -prefix|--prefix) prefix=$2
		      shift;;
    -minimal)	minimal=1;;
     *) echo "Unknown option \"$1\"." 1>&2; usage; exit 2;;
  esac
  shift
done

OCAMLC_NAME=ocamlc
OCAMLOPT_NAME=

if [ $minimal = "0" ] ; then

    # check for ocamlc.opt
    ocvo=$(ocamlc.opt -version)
    if [ $? -eq 0 ] ; then
	echo ocamlc.opt version $ocvo found.
	OCAMLC_NAME=ocamlc.opt
    else
	true
    fi


    # check for ocamlopt/ocamlopt.opt
    ocvo=$(ocamlopt.opt -version)
    if [ $? -eq 0 ] ; then
	echo ocamlopt.opt version $ocvo found. Native compilation enabled.
	OCAMLOPT_NAME=ocamlopt.opt
    else
	ocvo=$(ocamlopt -version)
	if [ $? -eq 0 ] ; then
	    echo -n "${ocamlbindir}ocamlopt version $ocvo found. "
	    echo Native compilation enabled.
	    OCAMLOPT_NAME=ocamlopt
	else
	    echo ocamlopt not found. Native compilation disabled.
	fi
    fi

fi # minimal


# Summary of the configuration
echo
echo "  Configuration summary:"
echo "    install in $prefix"
echo "    use $OCAMLC_NAME and $OCAMLOPT_NAME for compilation"
echo

for f in Makefile README ccslversion Common/global.ml ; do
    echo creating $f
    sed -e "s|@prefix@|$prefix|" \
	-e "s|@ocamlc_name@|$OCAMLC_NAME|" \
	-e "s|@ocamlopt_name@|$OCAMLOPT_NAME|" \
	-e "s|@PACKAGE_VERSION@|$ccslversion|" \
	$f.in > $f
done