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

Julien Fischer jfischer at opturion.com
Thu Jan 10 11:07:58 AEDT 2013


Hi Paul,

On Wed, Jan 9, 2013 at 5:34 PM, Paul Bone <paul at bone.id.au> wrote:

> 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?

I don't.

> 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.

That seems odd, is there somthing weird about your system or is it just a very
old version of mono?

> 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 |  117 ++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 files changed, 91 insertions(+), 26 deletions(-)
>
> diff --git a/m4/mercury.m4 b/m4/mercury.m4
>
> -# 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

You should follow the usual convention used by configuration marcos and
name the file conftest.cs.

> +    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

You need to clean up source file plus any files that may have been generated by
the compilation attempt.

>  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.

Or just:

      Add a new option, --with-csharp-compiler, that allows the user to
      specify what C# compiler to use.
>
> m4/mercury.m4:
>     Determine which C# compilers to try to use based upon the use of the
>     --with-csharp-compiler option.

And:
      If the user specified a C# compiler using the --with-csharp-compiler
      then use that.

...

> diff --git a/configure.ac b/configure.ac
> 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

You should use "=" with test not "==".

> +    CSC_COMPILERS=""
> +elif test "$mercury_cv_with_csharp_compiler" == "yes"; then
> +    CSC_COMPILERS="csc mcs dmcs gmcs cscc"

If the configure is invoked with either --with-csharp-compiler without an
argument or --without-csharp-compiler then that should be an error, just as it
is with --with-cc.  (Have a look at the latter to see how this should be
handled.)

> +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_CSC1 in $CSC_COMPILERS; do

Cheers,
Julien.



More information about the reviews mailing list