#! /bin/sh
#
# Copyright (c) 2003-2005 The University of Wroclaw.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#    2. Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#    3. The name of the University may not be used to endorse or promote
#       products derived from this software without specific prior
#       written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
# NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

############################################################
# VARIABLES
############################################################

# frequently changed stuff
nem_version=0.9
nem_revision=3
use_ngen=0

# this variable is used to return values from functions
result=

config_log="configure.log"

python=
install="install"

prefix="/usr/local"
bindir="$prefix/bin"
scrdir="$prefix/bin"
mandir="$prefix/man/man1"
libdir="$prefix/lib"
pkgconfig_dir=

dll_path=
nem_tmp_file=
mono_libdir=

time=
peverify=
quiet=@
bar=true
ignore_errors=no
netSDK=
netFRAMEWORK=
netVERSION="2.0"
generics=true
force_old=0
broken_swf=0
monopath=
antlr=
antlr_path=antlr
nant_path=nant
mono_gacutil=no

############################################################
# FUNCTIONS
############################################################

abort () {

    echo
    echo
    echo "*** $@ ***"
    if test -f $config_log; then
	echo "*** Check $config_log for details. ***"
    fi
    echo
    if [ "$ignore_errors" = yes ] ; then
      echo "*** Ignoring error. ***"
    else
      echo "Aborting..."
      rm -f $config_mak
      exit 1
    fi
}

echo_check_for () {

    echo "--------------- Checking for $@ ---------------" >> $config_log
    echo -n "Checking for $@... "
}


echo_check_if () {

    echo "--------------- Checking if $@ ----------------" >> $config_log
    echo -n "Checking if $@... "
}


echo_result () {

    echo "Result: $@" >> $config_log
    echo "-----------------------------------------------" >> $config_log
    echo >> $config_log
    echo "$@"
}


# This function tries to execute command given as an argument and returns
# shell exit code.  If the program doesn't exist in a path shell returns
# 127.  If the program is not a valid executable shell returns 126.
# If the program lacks some arguments it usually returns 1, otherwise
# this function should return 0.
#
# E.g.
# try_execute cc --version
# if test $? = 0; then
#    echo "found"
# else
#    echo "not found"
# fi
try_execute () {

    echo "Trying execute: $@" >> $config_log
    $@ >> $config_log 2>&1
    ret=$?
    echo "Execution status code: $ret." >> $config_log
    return $ret;
}


nem_try_compile () {
    echo "<<<<<<<<<<<<<<<" >> $config_log
    cat $nem_tmp_file >> $config_log
    echo ">>>>>>>>>>>>>>>" >> $config_log

    old_mono_path=$MONO_PATH
    MONO_PATH=boot

    $engine $net_flags boot/ncc.exe -q -no-color -texe -out:out.exe "$@" $nem_tmp_file_aux >> $config_log 2>&1

    MONO_PATH=$old_mono_path
    
    if test -f out.exe; then
	rm -f out.exe
	echo_result "yes"
	return 0
    else
	echo_result "no"
	return 1
    fi
}


############################################################
# PARAMETERS SCAN
############################################################

for i in $@; do
    if test "$i" = "--help" || test "$i" = "-help" || test "$i" = "-h"; then
        if [ $use_ngen = 0 ] ; then
          ngen_yes=
	  ngen_no="(default)"
	else
          ngen_yes="(default)"
	  ngen_no=
	fi

	cat << EOF

Usage: $0 [OPTIONS]...

Defaults for the options are specified in brackets.

Configuration:
  -h, --help            display this help and exit

Installation directories:
  --prefix=DIR          use this prefix for installing Nemerle [/usr/local]
  --bindir=DIR          use this prefix for installing executables 
                        [PREFIX/bin]
  --scrdir=DIR          use this prefix for installing shell wrappers for CLI
                        binaries [PREFIX/bin]
  --mandir=DIR          use this prefix for installing manpages 
                        [PREFIX/man/man1]
  --libdir=DIR          object code libraries [PREFIX/lib]
  --pkgconfigdir=DIR    specify directory where nemerle.pc is to be installed
                        [LIBDIR/pkgconfig]

Miscellaneous options:
  --nemerle-flags=FLAGS pass these flags to nemerle compiler
  --net-engine=ENGINE   use this .NET engine
  --net-version=[1.1|2.0] use tools from this .NET runtime version  
  --net-flags=FLAGS     pass these flags to .NET engine
  --install-path=PATH   the path to a custom install program
  --dll-path=PATH       the path to dlls directory
  --antlr-path=PATH     how to execute AntLR [default: antlr]
  --nant-path=PATH      how to execute NAnt [default: nant]
  --force-old-mono      use this switch to force using your version of
                        Mono .NET environment or if you don't use Mono
                        at all but have it installed
  --mono-from=PATH      use this path prefix when referencing tools from
                        mono, like /usr/local/bin/ [default empty]
  --ignore-errors       do not exit on errors
  --disable-aot         do not try to mono --aot/ngen the assemblies $ngen_no
  --enable-aot          try to mono --aot/ngen the assemblies $ngen_yes

Optional features:
  --enable-debug        adds --debug to net-flags and -debug to compiler flags
  --enable-time         enable compilation times statistics
  --disable-quiet       disable beautiful output
  --disable-bar         disable progress bar

EOF
	exit 0
    fi
done



for ac_option do

    case "$ac_option" in

	--prefix=*)
	    prefix=`echo $ac_option | cut -d '=' -f 2`
	    bindir="$prefix/bin"
	    mandir="$prefix/man/man1"
	    libdir="$prefix/lib"
	    scrdir="$bindir"
	    ;;
	--bindir=*)
	    bindir=`echo $ac_option | cut -d '=' -f 2`
	    ;;
        --scrdir=*)
            scrdir=`echo $ac_option | cut -d '=' -f 2`
	    ;;
	--mandir=*)
	    mandir=`echo $ac_option | cut -d '=' -f 2`
	    ;;
        --libdir=*)
	    libdir=`echo $ac_option | cut -d '=' -f 2`
	    mono_libdir="$libdir"
	    ;;
	--pkgconfigdir=*)
	    pkgconfig_dir=`echo $ac_option | cut -d '=' -f 2`
	    ;;
	--nemerle-flags=*)
	    nem_flags=`echo $ac_option | cut -d '=' -f 2`
	    ;;
	--net-engine=*)
	    engine=`echo $ac_option | cut -d '=' -f 2`
	    ;;
	--net-flags=*)
	    net_flags=`echo $ac_option | cut -d '=' -f 2`
	    ;;
	--install-path=*)
	    install=`echo $ac_option | cut -d '=' -f 2 | sed 's/\/$//'`"/install"
	    ;;
	--dll-path=*)
            dll_path=`echo $ac_option | cut -d '=' -f 2`
            ;;        
	--antlr-path=*)
            antlr_path=`echo $ac_option | cut -d '=' -f 2`
            ;;        
	--nant-path=*)
            nant_path=`echo $ac_option | cut -d '=' -f 2`
            ;;        
	--enable-debug)
	    csc_flags="$csc_flags -debug+"
	    net_flags="$net_flags --debug"
	    nem_flags="$nem_flags -debug -def:DEBUG"
	    ;;
	--force-old-mono)
	    force_old=1
	    ;;
	--enable-time)
	    time=time
	    ;;
        --disable-quiet)
	    quiet=
	    ;;
	--disable-aot)
	    use_ngen=0
	    ;;
	--disable-bar)
	    bar=false
	    ;;
	--enable-aot)
	    use_ngen=1
	    ;;
	--ignore-errors)
	    ignore_errors=yes
	    ;;
	--mono-from=*)
	    monopath=`echo $ac_option | cut -d '=' -f 2`"/"
	    engine="$monopath/mono"
	    ;;

	*)
	    echo "Unknown parameter: $ac_option"
	    echo "Try: ./configure --help"
	    exit 1
	    ;;
    esac
done
	    


############################################################
# INITIALIZATION
############################################################

rm -f $config_log $config_mak

if [ "$pkgconfig_dir" = "" ] ; then
  pkgconfig_dir="$libdir/pkgconfig"
fi

nem_tmp_file="`pwd`/config-tmp.n"
trap "rm -f $nem_tmp_file" EXIT

if [ "X`cygpath -wp ${nem_tmp_file} 2>/dev/null`" != "X" ] ; then
  nem_tmp_file_aux=`cygpath -wp ${nem_tmp_file}`
else
  nem_tmp_file_aux=${nem_tmp_file}
fi

############################################################
# TESTS
############################################################


# Step 1.
# Check if user has any nemerle compiler.  Don't run it yet
# as we don't know how to do it yet.
if test -f boot/ncc.exe; then
    true
elif test -f boot/ncc-boot.exe; then
    mv boot/ncc-boot.exe boot/ncc.exe
else
    echo "*** You need a working Nemerle compiler. ***"
    echo "*** http://nemerle.org/download/ncc-boot.exe ***"
    echo "*** Place it in boot/ncc.exe ***"
    abort "Haven't found Nemerle compiler."
fi


# Step 2.
# Determine how to invoke .NET binaries.
if test -z "$engine"; then
    echo_check_for ".NET environment"
    if test -x boot/ncc.exe; then
	true
    else
	chmod u+x boot/ncc.exe 2> /dev/null
    fi
    if test -x boot/true.exe; then
	true
    else
	chmod u+x boot/true.exe 2> /dev/null
    fi
    if try_execute boot/true.exe; then
	engine=none
	echo_result "none required"
    elif try_execute "${monopath}mono" boot/true.exe; then
	engine="${monopath}mono"
	echo_result "${monopath}mono"
    fi
fi
if test -z "$engine"; then
    abort "Haven't found any .NET environment on your system."
elif test "$engine" = none; then
    engine=
    net_flags=
fi

# Step 3.
# Require MONO >= 1.1.13
echo_check_if "we are using Mono < 1.1.13"
version=`"${monopath}mono" --version 2> /dev/null`
if test "$?" = 0; then
    ver=`echo $version | sed 's/.* \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/g'`
    m_major=`echo $ver | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\1/g'`
    m_minor=`echo $ver | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2/g'`
    m_revision=`echo $ver | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\3/g'`

    if ((m_major < 1 ||
         m_major == 1 && m_minor < 1 ||
         m_major == 1 && m_minor == 1 && m_revision < 13)); then
	     echo_result "yes"
	     if test "$force_old" = 1; then
		    echo "Forcing Mono ${ver}...  "
		    echo "Hope you know, what you are doing..."
	     else
		    echo "*** Mono $ver is unsupported. ***"
		    echo "*** If you still want to try running Nemerle ***"
		    echo "*** please use --force-old-mono switch. ***"
		    abort "Too old version of Mono."
	     fi
    else
	    echo_result "no"
    fi
else 
	echo_result "no"
fi

# Step 3a.
# Check if there is regtool.exe available in the system and configure paths
# to .NET SDK and Framework according to choosen version
echo_check_for "presence of regtool in the system"
try_execute regtool
if test $? -lt 126; then
   echo_result "found"

   echo_check_for ".NET SDK path"
  
   try_execute "regtool.exe get "/machine/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv${netVERSION}""
   if test "$?" != 127 -a "$?" != 1; then
     echo_result "found"
     netSDK="`regtool.exe get "/machine/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv${netVERSION}"`Bin\\"
   else
     echo_result "not found"  
   fi
       
   echo_check_for ".NET Framework path"
  
   try_execute "regtool.exe get "/machine/SOFTWARE/Microsoft/.NETFramework/InstallRoot""
   if test "$?" != 127 -a "$?" != 1; then
     echo_result "found"
     netFRAMEWORK="`regtool.exe get "/machine/SOFTWARE/Microsoft/.NETFramework/InstallRoot"`v${netVERSION}."
     netFRAMEWORK="`cygpath $netFRAMEWORK`"*"/"
   else
     echo_result "not found"  
   fi
   
else
   echo_result "not found"
fi


# Step 4.
# Check how to invoke .NET disassembler
echo_check_for ".NET disassembler"

try_execute "cygpath ${netSDK}ildasm.exe -?"
if test "$?" != 127 -a "$?" != 126; then
    echo_result "ildasm"
    dasm="\""`cygpath "${netSDK}ildasm.exe"`"\" -text"
else
    try_execute "${monopath}monodis"
    if test "$?" != 127 -a "$?" != 126; then
	echo_result "${monopath}monodis"
	dasm="${monopath}monodis"
    else
    	try_execute "${netSDK}ildasm.exe -text"
    	if test "$?" != 127 -a "$?" != 126; then
	    echo "ildasm [PATH]"
	    dasm="ildasm.exe -text"
	else
	    echo_result "not found"
	    echo "*** Please make sure that the .Net disassembler is ***"
	    echo "*** available somewhere in PATH. ***"
	    abort "Haven't found any disassembler on your system."
	fi
    fi
fi


# Step 5.
# Check how to invoke native image generator.
echo_check_for "native image generator"

if test "$use_ngen" = 0 ; then
    echo_result disabled
    ngen="true"
else
    try_execute "${netFRAMEWORK}ngen.exe"
    if test "$?" != 127 -a "$?" != 126; then
        echo_result "ngen.exe"
        ngen="${netFRAMEWORK}ngen.exe"
    else
        try_execute "${monopath}mono --aot"
        if test "$?" != 127 -a "$?" != 126; then
    	    echo_result "${monopath}mono --aot"
    	    ngen="${monopath}mono --aot"
        else
    	    echo_result "not found"
    	    echo "*** Please make sure that the native image generator is ***"
    	    echo "*** available as a single executable file, somewhere in PATH. ***"
	    ngen="true"
	    use_ngen=0
        fi
    fi
fi


# Step 6.
# Try to compile an empty program with nemerle compiler to be sure,
# that it works.
echo_check_if "Nemerle compiler works"
cat > $nem_tmp_file << EOF
class M {
    public static Main () : void {}
}
EOF
nem_try_compile
if test "$?" = 1; then
    if test "$force_old" = 1; then
        echo "*** You have requested to force old version of Mono. ***"
        echo "*** Please don't submit bugs. ***"
    fi
    abort "Nemerle compiler seems to be broken."
fi


# Step 7.
# Check things for gacutil installation.
echo_check_for "gacutil"

try_execute "${monopath}${netFRAMEWORK}gacutil"
if test $? -lt 126; then
  echo_result found
 
  echo_check_if "we are using mono gacutil"
  if "${monopath}${netFRAMEWORK}gacutil" --help 2>/dev/null | grep -q Mono ; then
    echo_result yes

    if [ "X$mono_libdir" = "X" -a "X$monopath" != "X" ] ; then
      case $monopath in
        */bin | */bin/ )
	  mono_libdir=$(echo $monopath | sed -e 's/bin\/\?$/lib/')
	  ;;
      esac
    fi

    if [ "X$mono_libdir" = "X" ] ; then
    echo_check_for "mono libdir"
    if pkg-config --version >/dev/null 2>&1 ; then
      mono_libdir=`pkg-config --variable=libdir mono 2>/dev/null`
      if [ "X$mono_libdir" = "X" ] ; then
        echo_result "no mono.pc, forcing /usr/lib"
        mono_libdir=/usr/lib
      else
        if test -d $mono_libdir/mono/gac ; then
          echo_result "$mono_libdir"
	else
          mono_libdir="`pkg-config --variable=prefix mono 2>/dev/null`/lib"
          if test -d $mono_libdir/mono/gac ; then
            echo_result "$mono_libdir"
	  else
            mono_libdir=/usr/lib
            echo_result "none is valid, forcing /usr/lib"
	  fi
	fi
      fi
    else
      echo_result "no pkg-config found, forcing /usr/lib"
      mono_libdir=/usr/lib
    fi
    fi

    gacutil_base="${monopath}gacutil -root \$(DESTDIR)$mono_libdir"
    gacutil_command="$gacutil_base -package nemerle -i"
    gacutil_uninstall_command="$gacutil_base -package nemerle -u"
    if [ "$use_ngen" = "0" ] ; then
      ngen_gac="true"
    else
      #ngen_gac="for f in \$(DESTDIR)$mono_libdir/mono/gac/Nemerle*/*/*.dll ; do mono --aot \$\$f ; done"
      ngen_gac="true"
    fi

    mono_gacutil=yes
  else
    echo_result no
    gacutil_command="${netFRAMEWORK}gacutil.exe -f -i"
    gacutil_uninstall_command="${netFRAMEWORK}gacutil.exe -f -u"
    ngen_gac="true"
  fi
else
  try_execute "cygpath ${netSDK}gacutil.exe"
  if test $? -lt 126; then
    echo_result found
    dasm="\""`cygpath "${netSDK}ildasm.exe"`"\" -text"
    gacutil_command="\""`cygpath "${netSDK}gacutil.exe"`"\" -f -i" 
    gacutil_uninstall_command="\""`cygpath "${netSDK}gacutil.exe"`"\" -f -u" 
    ngen_gac="true"
  else
    echo_result "not found"
    echo "*** ''make install'' won't work for you ***"
    gacutil_command="echo 'gacutil has not been found, installation can not continue'; false"
  fi
fi

# Step 8.
# Check if we have PEVerify.exe tool available
echo_check_for "PEVerify"

try_execute "cygpath ${netSDK}PEVerify.exe"
if test $? -lt 126; then
   echo_result found
   peverify="\""`cygpath "${netSDK}PEVerify.exe"`"\""
else
   echo_result "not found"
fi

# Step 9.
# Check if we have ilasm tool available
echo_check_for "ilasm2"

try_execute "${monopath}${netFRAMEWORK}ilasm2"
if test $? -lt 126; then
   echo_result found
   asm="${monopath}${netFRAMEWORK}ilasm2"
else
   echo_result "not found"
   
   echo_check_for "ilasm"
   try_execute "${monopath}${netFRAMEWORK}ilasm"
   if test $? -lt 126; then
       echo_result found
       asm="${monopath}${netFRAMEWORK}ilasm"
   else
       echo_result "not found"
   fi
fi


# Step 10.
# Check if we have C# compiler available
echo_check_for "C# compiler"

cat > conftest.cs <<EOF
class M {
  public static void foo<T>() { }
  public static void Main () {}
}
EOF

if try_execute "${netFRAMEWORK}csc conftest.cs" ; then
   echo_result "found, csc"
   csc="${netFRAMEWORK}csc"
else
  
  if try_execute "${monopath}gmcs conftest.cs" ; then
    echo_result "found, gmcs"
    csc="${monopath}gmcs"
  else
    echo_result "not found"
  fi
fi

rm -f conftest.cs conftest.exe

# Step 11.
# Check for Python >= 2.3, and other programs required to build
# complete documentation.
echo_check_for "Python version"
for i in python2.3 python; do
    str=`$i -V 2>&1`
    if test "$?" -gt 0; then
	continue
    fi
    
    ver=`echo $str | sed 's/.* \([0-9]\.[0-9]\).*/\1/g'`

    case $ver in
	2.3 | 2.4)
	    echo_result "$ver, ok"
	    python=$i
	    ;;
	*)
	    echo_result "$ver, too_old"
	    ;;
    esac
    break
done
if test -z $ver; then
  echo_result "none"
fi

# Step 12.
# check for antlr for generating cs2n C# parser
echo_check_for "antlr >= 2.7.5"
  # the debian antlr package uses a `runantlr' binary
  antlrcommand=`which $antlr_path 2>/dev/null || which runantlr 2>/dev/null`

  # and the debian antlr version also didn't match with this
  # ver=`antlr 2>&1| head -1 | sed 's/.* \([0-9]*\.[0-9]\.[0-9]*\).*/\1/g'`
  # this should be more general
  ver=`"$antlrcommand" 2>&1 | grep -i version | sed 's/.*\([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*/\1/g'`

    case $ver in  
	2.7.[5-9])
	    antlr="$antlrcommand"
	    cp tools/cs2n/antlr/antlr.runtime-2.7.5.dll tools/cs2n/antlr/antlr.runtime.dll
	    echo_result "yes, 2.7.5+" 
	    ;;
	*) 
	    # also copy it for pregenerated parser!
	    cp tools/cs2n/antlr/antlr.runtime-2.7.5.dll tools/cs2n/antlr/antlr.runtime.dll
	    echo_result "not supported" 
	    if find tools/cs2n/CSharpParser.cs -cnewer tools/cs2n/csharpgrammar.g | grep -q "" ; then
	      :
	    else
	      echo "*** You won't be able to build CS2N! ***"
	    fi
	    ;; 
    esac 

# Step 13.
echo_check_for "nant"
try_execute $nant_path
if test $? -lt 126; then
    echo_result yes
    nant=$nant_path
    echo_check_for "nant plugin directory"
    rm -f misc/nant.dir
    try_execute $nant_path -buildfile:misc/print-dir.build
    nant_dir=`cat misc/nant.dir 2>/dev/null`
    rm -f misc/nant.dir
    if test "$nant_dir" ; then
      echo "found, $nant_dir"
    else
      echo_result "not found, plugin disabled"
      nant=
    fi
else
    echo_result no
    nant=
fi

try_nunit_version_2 () {
  echo "Trying execute: $@" >> $config_log
  eval "$@ /help | grep 'Version: 2'" >> $config_log 2>&1
  ret=$?
  echo "Execution status code: $ret." >> $config_log
  if test $ret -eq 0; then
    nunit="$@"
  fi
}

# Step 14.
echo_check_for "nunit-console for .NET 2.0"
try_nunit_version_2 nunit-console;
try_nunit_version_2 nunit-console2;
try_nunit_version_2 "${monopath}nunit-console";
try_nunit_version_2 "${monopath}nunit-console2";
if test "$nunit"; then
  echo_result "found, $nunit"
  if pkgconfig --exists mono-nunit 2>/dev/null; then
    nunit_lib="-pkg:mono-nunit.pc"
  else
    np=`which nunit-console | sed 's/\(.*\)nunit-conso.*/\1nunit.framework.dll/'`; np=`cygpath -w "$np"`;
    nunit_lib="-r:\"$np\""
  fi
else
  echo_result "not found, some tests will be disabled"
fi


# Step 15.
# Check if we have MSBuild available
echo_check_for "MSBuild"

try_execute "${netFRAMEWORK}MSBuild.exe"
if (($? < 126)); then
   echo_result found
   msbuild="${netFRAMEWORK}MSBuild.exe"
else
  try_execute "${monopath}xbuild"
  res=$?
  if ((res < 126 && res != 2)); then
    if ((m_major > 1 || m_major == 1 && m_minor > 2 || m_major == 1 && m_minor == 1 && m_revision > 14)); then
      echo_result found
      msbuild="${monopath}xbuild"
    else
      echo_result "found, but mono is too old (at least 1.1.15 required), won't use it"
    fi
  else
    echo_result "not found"
  fi
fi


if test -d .svn; then
    svn_revision=`svn info . | awk '/^Revision:/ { print $2 }'`
else
    svn_revision=
fi

if test $bar = "true"; then
  nem_flags="$nem_flags -bar+"
fi

case "$csc" in
*csc) nem_flags="$nem_flags -def:RUNTIME_MS";;
*gmcs) nem_flags="$nem_flags -def:RUNTIME_MONO";;
*cscc) nem_flags="$nem_flags -def:RUNTIME_PNET";;
*) ;;
esac

############################################################
# CONFIG GENERATION
############################################################

echo "Creating config.mak"

cat > config.mak <<EOF
# Generated by configure

Q          = $quiet

PACKAGE    = nemerle
VERSION    = $nem_version
REVISION   = $nem_revision
SVN_REV    = $svn_revision

NET_ENGINE = $engine
NET_VERSION = $netVERSION
NET_FLAGS  = $net_flags
DLL_PATH   = $dll_path
NGEN       = $ngen
DASM       = $dasm
ASM        = $asm
CSC        = $csc
PEVERIFY   = $peverify
TIME       = $time
ANTLR      = $antlr
MSBUILD    = $msbuild

MONO_GACUTIL = $mono_gacutil

NANT       = $nant
NANT_DIR   = $nant_dir

NUNIT_CONSOLE = $nunit
NUNIT_LIB_FLAG = $nunit_lib

NEM_FLAGS  = $nem_flags

PYTHON  = $python
XSPP    = $xspp
XSLT    = $xsltproc

INSTALL = $install

prefix = $prefix
BINDIR = $bindir
SCRDIR = $scrdir
MANDIR = $mandir
LIBDIR = $libdir
PKGCONFIGDIR = $pkgconfig_dir
GACUTIL_COMMAND = $gacutil_command
GACUTIL_UNINSTALL_COMMAND = $gacutil_uninstall_command
NGEN_GAC = $ngen_gac

EOF

echo "Creating nemerle.pc"

cat > nemerle.pc <<EOF
prefix=${prefix}
exec_prefix=\${prefix}
libdir=${libdir}

Name: Nemerle
Description: Nemerle - a .NET object-functional language
Version: $nem_version.$nem_revision
Libs: -r:${mono_libdir}/mono/nemerle/Nemerle.dll -r:${mono_libdir}/mono/nemerle/Nemerle.Compiler.dll -r:${mono_libdir}/mono/nemerle/Nemerle.Macros.dll
EOF

