#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/autoconf/dotnettest                  */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Thu Jan 14 10:31:33 1999                          */
#*    Last change :  Wed Jun 29 16:30:53 2005 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Checking the .NET setting                                        */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
clr=
clropt=
clrld=
cscc=
tmp=/tmp
user=bigloo
cpsep=:

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --user=*)
      user="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --clr=*|-clr=*)
      clr="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --clropt=*|-clropt=*)
      clropt="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cscc=*|-cscc=*)
      cscc="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --clrld=*|-clrld=*)
      clrld="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --tmp=*|-tmp=*)
      tmp="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cpsep=*|-cpsep=*)
      cpsep="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=cstest

#*---------------------------------------------------------------------*/
#*    compile                                                          */
#*---------------------------------------------------------------------*/
compile="$cscc -o $file.exe $csccflags $file.cs >/dev/null 2> /dev/null"
run="$clr $file.exe toto tutu titi >/dev/null 2> /dev/null"

#*---------------------------------------------------------------------*/
#*    The test Class file                                              */
#*---------------------------------------------------------------------*/
if( test -f $file.cs ); then
   rm -f $file.cs || exit $?
fi

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.cs <<EOF
class cstest {
   public static void Main( String[] args ) {
      Console.Error.WriteLine( "Success: " + args[ 0 ] );
   }
}
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval $compile 2> /dev/null; then
   if eval $run 2> /dev/null; then
     \rm -f $file*
     exit 0
   else
     echo ".NET run command [$run] failed" >> configure.log
     echo "" >> configure.log
     echo "$file.cs:" >> configure.log
     cat $file.cs >> configure.log
     \rm -f $file*
     exit 1
   fi
else
   echo "C# compilation command [$compile] failed" >> configure.log
   echo "" >> configure.log
   echo "$file.cs:" >> configure.log
   cat $file.cs >> configure.log
   \rm -f $file*
   exit 2
fi
