[m-rev.] for review: Configuration of C# compiler.

Paul Bone paul at bone.id.au
Wed Jan 9 17:34:09 AEDT 2013


FOr review by Julien.

The first two patches support better selection fo the C# compiler.

The third patch fixes a formatting issue in ./configure --help's output.

If we were using CVS I would normally make this one big patch.  But git
makes it easy to seperate multiple changes that people normally work on at
the same time.  These could be sent in seperate e-mails when sending them
for review.  Do people have a preference?

>From 374605023e2b3a1b33dc82b8f61c334c576d606f Mon Sep 17 00:00:00 2001
From: Paul Bone <paul at bone.id.au>
Date: Wed, 9 Jan 2013 15:01:21 +1100
Subject: [PATCH 1/3] Test each mono C# compiler to determine if it can handle generics.
To: Mercury Reviews <mercury-reviews at lists.unimelb.edu.au>

The 'mcs' compiler on my system cannot handle generics.  This change to the
configure script macros tests each candidate mono C# compiler for generics
support.  If a candidate does not handle generics, then the next candidate
is tested.

m4/mercury.m4:
    As above.

    I have also stripped trailing whitespace the end of lines in this file.
---
 m4/mercury.m4 |  117 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 91 insertions(+), 26 deletions(-)

diff --git a/m4/mercury.m4 b/m4/mercury.m4
index 2435bc1..29e031f 100644
--- a/m4/mercury.m4
+++ b/m4/mercury.m4
@@ -234,9 +234,9 @@ AC_PATH_PROG([GACUTIL], [gacutil])
 AC_MSG_CHECKING([for Microsoft.NET Framework SDK])
 AC_CACHE_VAL([mercury_cv_microsoft_dotnet], [
 if test "$ILASM" != ""; then
-	changequote(<<,>>) 
+	changequote(<<,>>)
 	MS_DOTNET_SDK_DIR=`expr "$ILASM" : '\(.*\)[/\\]*[bB]in[/\\]*ilasm'`
-	changequote([,]) 
+	changequote([,])
 	mercury_cv_microsoft_dotnet="yes"
 else
 	MS_DOTNET_SDK_DIR=""
@@ -252,32 +252,97 @@ GACUTIL=`basename "$GACUTIL"`
 # dmcs is the Mono C# compiler targeting the 4.0 runtime
 # gmcs is the Mono C# compiler targeting the 2.0 runtime (with generics).
 # cscc is the DotGNU C# compiler.
-AC_PATH_PROGS([CANDIDATE_CSC], [csc mcs dmcs gmcs cscc])
-CANDIDATE_CSC=`basename "$CANDIDATE_CSC"`
 
-# The Microsoft C# compiler and the Chicken Scheme compiler share the same
-# executable name so if we find an executable named csc above check that it is
-# actually the Microsoft C# compiler and if it is not then try to use one of
-# the other instead.
-#
-case "$CANDIDATE_CSC" in
+AC_CACHE_SAVE
+CSC_COMPILERS="csc mcs dmcs gmcs cscc"
+AC_MSG_CHECKING([for a C sharp compiler])
+AC_MSG_RESULT()
+for CANDIDATE_CSC0 in $CSC_COMPILERS; do
+    unset CANDIDATE_CSC
+    unset ac_cv_path_CANDIDATE_CSC
+    AC_CACHE_LOAD
+    AC_PATH_PROG([CANDIDATE_CSC], [$CANDIDATE_CSC0])
     
-     csc*)
-        $CANDIDATE_CSC 2>&1 | grep -q "^Microsoft"
-        if test $? -ne 0
-        then
-            AC_MSG_WARN([$CANDIDATE_CSC is not the Microsoft C sharp compiler])
-            AC_PATH_PROGS([CSC], [mcs dmcs gmcs cscc])
-            CSC=`basename "$CSC"`
-        else
-            CSC="$CANDIDATE_CSC"
-        fi
-    ;;
+    if test -z "$CANDIDATE_CSC"; then
+        continue;
+    fi
+    CANDIDATE_CSC=`basename "$CANDIDATE_CSC"`
+
+# Check that the compiler is suitable.
+    case "$CANDIDATE_CSC" in
+         csc*)
+             #
+             # The Microsoft C# compiler and the Chicken Scheme compiler share
+             # the same executable name so if we find an executable named csc
+             # above check that it is actually the Microsoft C# compiler and if
+             # it is not then try to use one of the other instead.
+             #
+             $CANDIDATE_CSC 2>&1 | grep -q "^Microsoft"
+             if test $? -ne 0
+             then
+                 AC_MSG_WARN([$CANDIDATE_CSC is not the Microsoft C sharp compiler])
+                 continue;
+             else
+                 CSC="$CANDIDATE_CSC"
+                 break;
+             fi
+        ;;
 
-    *)
-       CSC="$CANDIDATE_CSC"
-    ;;
-esac
+        *mcs)
+            # We want to check that the 'mcs' compiler supports generics.
+            # We test all the mono C sharp compilers in order to be more
+            # defensive.
+            AC_MSG_CHECKING([whether $CANDIDATE_CSC supports C sharp generics])
+
+            cat > hello.cs << EOF
+    using System;
+    using System.Collections.Generic;
+
+    class Hello
+    {
+        private class ExampleClass { }
+
+        static void Main()
+        {
+            Console.WriteLine("Hello world!");
+
+            // Declare a list of type int.
+            List<int> list1 = new List<int>();
+
+            // Declare a list of type string.
+            List<string> list2 = new List<string>();
+
+            // Declare a list of type ExampleClass.
+            List<ExampleClass> list3 = new List<ExampleClass>();
+        }
+    }
+EOF
+            echo $CANDIDATE_CSC hello.cs >&AC_FD_CC 2>&1
+            OUTPUT=$($CANDIDATE_CSC hello.cs 2>&1)
+            RESULT=$?
+            echo $OUTPUT >&AC_FD_CC
+            echo returned $RESULT >&AC_FD_CC
+            if echo $OUTPUT | grep CS1644 > /dev/null; then
+                # This compiler does not support generics.
+                AC_MSG_RESULT(no)
+                continue;
+            elif test $RESULT -ne 0; then
+                AC_MSG_RESULT(no)
+                AC_MSG_WARN([$CANDIDATE_CSC returned exit code $?])
+                continue;
+            else
+                AC_MSG_RESULT(yes)
+                CSC="$CANDIDATE_CSC"
+                break;
+            fi
+        ;;
+
+        *)
+            CSC="$CANDIDATE_CSC"
+            break;
+        ;;
+    esac
+done
 
 case "$CSC" in
     csc*)
@@ -587,7 +652,7 @@ int main(int argc, char **argv)
     #else
        printf("unknown");
     #endif
-   
+
     return 0;
 }
 EOF
-- 
1.7.2.5

>From a727ec35920e40ed97dd2b617dc80a1faa00e8a9 Mon Sep 17 00:00:00 2001
From: Paul Bone <paul at bone.id.au>
Date: Wed, 9 Jan 2013 17:17:21 +1100
Subject: [PATCH 2/3] Add support to allow the user to specify the C# compiler.
To: Mercury Reviews <mercury-reviews at lists.unimelb.edu.au>

configure.ac:
    Add the AC_ARG_WITH declaration to allow the user to specify the C#
    compiler.

m4/mercury.m4:
    Determine which C# compilers to try to use based upon the use of the
    --with-csharp-compiler option.
---
 configure.ac  |    6 ++++++
 m4/mercury.m4 |   10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6eb9ed0..9a14f2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1217,6 +1217,12 @@ AC_SUBST(MATH_LIB)
 # Microsoft.NET configuration
 #
 
+AC_ARG_WITH(csharp-compiler,
+    AC_HELP_STRING([--with-csharp-compiler=<compiler>],
+                   [Specify which C Sharp compiler should be used (default:
+                   autodetect)]),
+    mercury_cv_with_csharp_compiler="$withval",
+    mercury_cv_with_csharp_compiler="")
 MERCURY_CHECK_DOTNET
 
 #-----------------------------------------------------------------------------#
diff --git a/m4/mercury.m4 b/m4/mercury.m4
index 29e031f..efd8951 100644
--- a/m4/mercury.m4
+++ b/m4/mercury.m4
@@ -254,7 +254,15 @@ GACUTIL=`basename "$GACUTIL"`
 # cscc is the DotGNU C# compiler.
 
 AC_CACHE_SAVE
-CSC_COMPILERS="csc mcs dmcs gmcs cscc"
+if test "$mercury_cv_with_csharp_compiler" == "no"; then
+    CSC_COMPILERS=""
+elif test "$mercury_cv_with_csharp_compiler" == "yes"; then
+    CSC_COMPILERS="csc mcs dmcs gmcs cscc"
+elif test "$mercury_cv_with_csharp_compiler" == ""; then
+    CSC_COMPILERS="csc mcs dmcs gmcs cscc"
+else
+    CSC_COMPILERS="$mercury_cv_with_csharp_compiler"
+fi
 AC_MSG_CHECKING([for a C sharp compiler])
 AC_MSG_RESULT()
 for CANDIDATE_CSC0 in $CSC_COMPILERS; do
-- 
1.7.2.5

>From 6c86871c16cc0ae66df17047c50e5624bb8e4f58 Mon Sep 17 00:00:00 2001
From: Paul Bone <paul at bone.id.au>
Date: Wed, 9 Jan 2013 17:19:06 +1100
Subject: [PATCH 3/3] Fix indentation in configure's help text.
To: Mercury Reviews <mercury-reviews at lists.unimelb.edu.au>

---
 configure.ac |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9a14f2c..36c29e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2958,8 +2958,8 @@ fi
 
 AC_ARG_WITH([gc-pthreads-win32],
    AC_HELP_STRING([--with-gc-pthreads-win32]
-          [Force the use of the pthreads-win32 library with the Boehm GC.
-           This is the default for MinGW]),
+                          [Force the use of the pthreads-win32 library with
+                          the Boehm GC.  This is the default for MinGW]),
    [with_gc_pthreads_win32="$withval"],[with_gc_pthreads_win32="no"])
 
 case "$with_gc_pthreads_win32" in
-- 
1.7.2.5


-- 
Paul Bone
http://www.bone.id.au



More information about the reviews mailing list