]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Add support for --enable-csharp and --disable-csharp.
authorBruno Haible <bruno@clisp.org>
Fri, 16 Jan 2004 10:53:41 +0000 (10:53 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:38 +0000 (12:11 +0200)
gettext-runtime/ChangeLog
gettext-runtime/configure.ac
gettext-tools/ChangeLog
gettext-tools/configure.ac
gettext-tools/lib/ChangeLog
gettext-tools/lib/csharpcomp.c
gettext-tools/lib/csharpexec.c
gettext-tools/m4/ChangeLog
gettext-tools/m4/Makefile.am
gettext-tools/m4/csharpcomp.m4
gettext-tools/m4/csharpexec.m4

index 00f9157ff42b5c15771e7c687324fe414d48a4e7..240ff01ff006a8161b44db8e5ce2f91d0c7356cf 100644 (file)
@@ -1,3 +1,7 @@
+2004-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * configure.ac: When --disable-csharp was given, set BUILDCSHARP=no.
+
 2003-12-26  Bruno Haible  <bruno@clisp.org>
 
        Support for C#.
index 7a4de4e61e028f401e33ce648a4c9c5451433532..cd9bcc75fdb2c068c50d91db386f2af557fae951 100644 (file)
@@ -45,7 +45,7 @@ fi
 AC_SUBST(BUILDJAVA)
 
 gt_CSHARPCOMP
-if test -n "$HAVE_CSHARPCOMP"; then
+if test -n "$HAVE_CSHARPCOMP" && test "$CSHARP_CHOICE" != no; then
   BUILDCSHARP=yes
 else
   BUILDCSHARP=no
index 20c4548c17576df171fc8bee9c0b834dab62b74c..20c51a670b1e5ea018b79ebc500de9444aeea4ff 100644 (file)
@@ -1,3 +1,7 @@
+2004-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * configure.ac: When --disable-csharp was given, set BUILDCSHARP=no.
+
 2003-12-26  Bruno Haible  <bruno@clisp.org>
 
        Support for C#.
index 3a2a999c8a9aa2203ac6bc20d4a283d5a89ac90d..6bbebf43652d3a7dec4fc07b5bb7ed71a1239141 100644 (file)
@@ -62,7 +62,7 @@ fi
 AC_SUBST(TESTJAVA)
 
 gt_CSHARPCOMP
-if test -n "$HAVE_CSHARPCOMP"; then
+if test -n "$HAVE_CSHARPCOMP" && test "$CSHARP_CHOICE" != no; then
   BUILDCSHARP=yes
 else
   BUILDCSHARP=no
index 15089f4d19e4c7b2e5996e501f48f7876748375a..454ce8833722bf16c096c3a45e0295f47685796d 100644 (file)
@@ -1,3 +1,13 @@
+2004-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * csharpcomp.c (compile_csharp_using_pnet, compile_csharp_using_mono,
+       compile_csharp_using_sscli): New functions.
+       (compile_csharp_class): Call them. Respect the CSHARP_CHOICE_* macros.
+       * csharpexec.c (execute_csharp_using_pnet, execute_csharp_using_mono):
+       New functions.
+       (execute_csharp_program): Call them. Respect the CSHARP_CHOICE_*
+       macros.
+
 2004-01-10  Bruno Haible  <bruno@clisp.org>
 
        * csharpcomp.sh.in: Copy the mcs output to stderr, dropping the
index b3b539ae735676eeabb0680f01239c2544284aa0..5a607ba5c0952a7e3e84600b0983f9275f930c91 100644 (file)
         "file(lineno)" instead of "file:lineno:".)
      3. "csc", although it is not free, because it is a kind of "reference
         implementation" of C#.
+   But the order can be changed through the --enable-csharp configuration
+   option.
  */
 
+static int
+compile_csharp_using_pnet (const char * const *sources,
+                          unsigned int sources_count,
+                          const char * const *libdirs,
+                          unsigned int libdirs_count,
+                          const char * const *libraries,
+                          unsigned int libraries_count,
+                          const char *output_file, bool output_is_library,
+                          bool optimize, bool debug,
+                          bool verbose)
+{
+  static bool cscc_tested;
+  static bool cscc_present;
+
+  if (!cscc_tested)
+    {
+      /* Test for presence of cscc:
+        "cscc --version >/dev/null 2>/dev/null"  */
+      char *argv[3];
+      int exitstatus;
+
+      argv[0] = "cscc";
+      argv[1] = "--version";
+      argv[2] = NULL;
+      exitstatus = execute ("cscc", "cscc", argv, false, false, true, true,
+                           true, false);
+      cscc_present = (exitstatus == 0);
+      cscc_tested = true;
+    }
+
+  if (cscc_present)
+    {
+      unsigned int argc;
+      char **argv;
+      char **argp;
+      int exitstatus;
+      unsigned int i;
+
+      argc =
+       1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
+       + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0)
+       + sources_count;
+      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
+
+      argp = argv;
+      *argp++ = "cscc";
+      if (output_is_library)
+       *argp++ = "-shared";
+      *argp++ = "-o";
+      *argp++ = (char *) output_file;
+      for (i = 0; i < libdirs_count; i++)
+       {
+         *argp++ = "-L";
+         *argp++ = (char *) libdirs[i];
+       }
+      for (i = 0; i < libraries_count; i++)
+       {
+         *argp++ = "-l";
+         *argp++ = (char *) libraries[i];
+       }
+      if (optimize)
+       *argp++ = "-O";
+      if (debug)
+       *argp++ = "-g";
+      for (i = 0; i < sources_count; i++)
+       {
+         const char *source_file = sources[i];
+         if (strlen (source_file) >= 9
+             && memcmp (source_file + strlen (source_file) - 9, ".resource",
+                        9) == 0)
+           {
+             char *option = (char *) xallocsa (12 + strlen (source_file) + 1);
+
+             memcpy (option, "-fresources=", 12);
+             strcpy (option + 12, source_file);
+             *argp++ = option;
+           }
+         else
+           *argp++ = (char *) source_file;
+       }
+      *argp = NULL;
+      /* Ensure argv length was correctly calculated.  */
+      if (argp - argv != argc)
+       abort ();
+
+      if (verbose)
+       {
+         char *command = shell_quote_argv (argv);
+         printf ("%s\n", command);
+         free (command);
+       }
+
+      exitstatus = execute ("cscc", "cscc", argv, false, false, false, false,
+                           true, true);
+
+      for (i = 0; i < sources_count; i++)
+       if (argv[argc - sources_count + i] != sources[i])
+         freesa (argv[argc - sources_count + i]);
+      freesa (argv);
+
+      return (exitstatus != 0);
+    }
+  else
+    return -1;
+}
+
+static int
+compile_csharp_using_mono (const char * const *sources,
+                          unsigned int sources_count,
+                          const char * const *libdirs,
+                          unsigned int libdirs_count,
+                          const char * const *libraries,
+                          unsigned int libraries_count,
+                          const char *output_file, bool output_is_library,
+                          bool optimize, bool debug,
+                          bool verbose)
+{
+  static bool mcs_tested;
+  static bool mcs_present;
+
+  if (!mcs_tested)
+    {
+      /* Test for presence of mcs:
+        "mcs --version >/dev/null 2>/dev/null"  */
+      char *argv[3];
+      int exitstatus;
+
+      argv[0] = "mcs";
+      argv[1] = "--version";
+      argv[2] = NULL;
+      exitstatus = execute ("mcs", "mcs", argv, false, false, true, true, true,
+                           false);
+      mcs_present = (exitstatus == 0);
+      mcs_tested = true;
+    }
+
+  if (mcs_present)
+    {
+      unsigned int argc;
+      char **argv;
+      char **argp;
+      pid_t child;
+      int fd[1];
+      FILE *fp;
+      char *line[2];
+      size_t linesize[2];
+      size_t linelen[2];
+      unsigned int l;
+      int exitstatus;
+      unsigned int i;
+
+      argc =
+       1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
+       + 2 * libraries_count + (debug ? 1 : 0) + sources_count;
+      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
+
+      argp = argv;
+      *argp++ = "mcs";
+      if (output_is_library)
+       *argp++ = "-target:library";
+      *argp++ = "-o";
+      *argp++ = (char *) output_file;
+      for (i = 0; i < libdirs_count; i++)
+       {
+         *argp++ = "-L";
+         *argp++ = (char *) libdirs[i];
+       }
+      for (i = 0; i < libraries_count; i++)
+       {
+         *argp++ = "-r";
+         *argp++ = (char *) libraries[i];
+       }
+      if (debug)
+       *argp++ = "-g";
+      for (i = 0; i < sources_count; i++)
+       {
+         const char *source_file = sources[i];
+         if (strlen (source_file) >= 9
+             && memcmp (source_file + strlen (source_file) - 9, ".resource",
+                        9) == 0)
+           {
+             char *option = (char *) xallocsa (10 + strlen (source_file) + 1);
+
+             memcpy (option, "-resource:", 10);
+             strcpy (option + 10, source_file);
+             *argp++ = option;
+           }
+         else
+           *argp++ = (char *) source_file;
+       }
+      *argp = NULL;
+      /* Ensure argv length was correctly calculated.  */
+      if (argp - argv != argc)
+       abort ();
+
+      if (verbose)
+       {
+         char *command = shell_quote_argv (argv);
+         printf ("%s\n", command);
+         free (command);
+       }
+
+      child = create_pipe_in ("mcs", "mcs", argv, NULL, false, true, true, fd);
+
+      /* Read the subprocess output, copying it to stderr.  Drop the last
+        line if it starts with "Compilation succeeded".  */
+      fp = fdopen (fd[0], "r");
+      if (fp == NULL)
+       error (EXIT_FAILURE, errno, _("fdopen() failed"));
+      line[0] = NULL; linesize[0] = 0;
+      line[1] = NULL; linesize[1] = 0;
+      l = 0;
+      for (;;)
+       {
+         linelen[l] = getline (&line[l], &linesize[l], fp);
+         if (linelen[l] == (size_t)(-1))
+           break;
+         l = (l + 1) % 2;
+         if (line[l] != NULL)
+           fwrite (line[l], 1, linelen[l], stderr);
+       }
+      l = (l + 1) % 2;
+      if (line[l] != NULL
+         && !(linelen[l] >= 21
+              && memcmp (line[l], "Compilation succeeded", 21) == 0))
+       fwrite (line[l], 1, linelen[l], stderr);
+      if (line[0] != NULL)
+       free (line[0]);
+      if (line[1] != NULL)
+       free (line[1]);
+      fclose (fp);
+
+      /* Remove zombie process from process list, and retrieve exit status.  */
+      exitstatus = wait_subprocess (child, "mcs", false, false, true, true);
+
+      for (i = 0; i < sources_count; i++)
+       if (argv[argc - sources_count + i] != sources[i])
+         freesa (argv[argc - sources_count + i]);
+      freesa (argv);
+
+      return (exitstatus != 0);
+    }
+  else
+    return -1;
+}
+
+static int
+compile_csharp_using_sscli (const char * const *sources,
+                           unsigned int sources_count,
+                           const char * const *libdirs,
+                           unsigned int libdirs_count,
+                           const char * const *libraries,
+                           unsigned int libraries_count,
+                           const char *output_file, bool output_is_library,
+                           bool optimize, bool debug,
+                           bool verbose)
+{
+  static bool csc_tested;
+  static bool csc_present;
+
+  if (!csc_tested)
+    {
+      /* Test for presence of csc:
+        "csc -help >/dev/null 2>/dev/null"  */
+      char *argv[3];
+      int exitstatus;
+
+      argv[0] = "csc";
+      argv[1] = "-help";
+      argv[2] = NULL;
+      exitstatus = execute ("csc", "csc", argv, false, false, true, true, true,
+                           false);
+      csc_present = (exitstatus == 0);
+      csc_tested = true;
+    }
+
+  if (csc_present)
+    {
+      unsigned int argc;
+      char **argv;
+      char **argp;
+      int exitstatus;
+      unsigned int i;
+
+      argc =
+       1 + 1 + 1 + libdirs_count + libraries_count
+       + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
+      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
+
+      argp = argv;
+      *argp++ = "csc";
+      *argp++ = (output_is_library ? "-target:library" : "-target:exe");
+      {
+       char *option = (char *) xallocsa (5 + strlen (output_file) + 1);
+       memcpy (option, "-out:", 5);
+       strcpy (option + 5, output_file);
+       *argp++ = option;
+      }
+      for (i = 0; i < libdirs_count; i++)
+       {
+         char *option = (char *) xallocsa (5 + strlen (libdirs[i]) + 1);
+         memcpy (option, "-lib:", 5);
+         strcpy (option + 5, libdirs[i]);
+         *argp++ = option;
+       }
+      for (i = 0; i < libraries_count; i++)
+       {
+         char *option = (char *) xallocsa (11 + strlen (libraries[i]) + 1);
+         memcpy (option, "-reference:", 11);
+         strcpy (option + 11, libraries[i]);
+         *argp++ = option;
+       }
+      if (optimize)
+       *argp++ = "-optimize+";
+      if (debug)
+       *argp++ = "-debug+";
+      for (i = 0; i < sources_count; i++)
+       {
+         const char *source_file = sources[i];
+         if (strlen (source_file) >= 9
+             && memcmp (source_file + strlen (source_file) - 9, ".resource",
+                        9) == 0)
+           {
+             char *option = (char *) xallocsa (10 + strlen (source_file) + 1);
+
+             memcpy (option, "-resource:", 10);
+             strcpy (option + 10, source_file);
+             *argp++ = option;
+           }
+         else
+           *argp++ = (char *) source_file;
+       }
+      *argp = NULL;
+      /* Ensure argv length was correctly calculated.  */
+      if (argp - argv != argc)
+       abort ();
+
+      if (verbose)
+       {
+         char *command = shell_quote_argv (argv);
+         printf ("%s\n", command);
+         free (command);
+       }
+
+      exitstatus = execute ("csc", "csc", argv, false, false, false, false,
+                           true, true);
+
+      for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
+       freesa (argv[i]);
+      for (i = 0; i < sources_count; i++)
+       if (argv[argc - sources_count + i] != sources[i])
+         freesa (argv[argc - sources_count + i]);
+      freesa (argv);
+
+      return (exitstatus != 0);
+    }
+  else
+    return -1;
+}
+
 bool
 compile_csharp_class (const char * const *sources,
                      unsigned int sources_count,
@@ -73,336 +435,58 @@ compile_csharp_class (const char * const *sources,
   bool output_is_library =
     (strlen (output_file) >= 4
      && memcmp (output_file + strlen (output_file) - 4, ".dll", 4) == 0);
+  int result;
+
+  /* First try the C# implementation specified through --enable-csharp.  */
+#if CSHARP_CHOICE_PNET
+  result = compile_csharp_using_pnet (sources, sources_count,
+                                     libdirs, libdirs_count,
+                                     libraries, libraries_count,
+                                     output_file, output_is_library,
+                                     optimize, debug, verbose);
+  if (result >= 0)
+    return (bool) result;
+#endif
 
-  {
-    static bool cscc_tested;
-    static bool cscc_present;
-
-    if (!cscc_tested)
-      {
-       /* Test for presence of cscc:
-          "cscc --version >/dev/null 2>/dev/null"  */
-       char *argv[3];
-       int exitstatus;
-
-       argv[0] = "cscc";
-       argv[1] = "--version";
-       argv[2] = NULL;
-       exitstatus = execute ("cscc", "cscc", argv, false, false, true, true,
-                             true, false);
-       cscc_present = (exitstatus == 0);
-       cscc_tested = true;
-      }
-
-    if (cscc_present)
-      {
-       unsigned int argc;
-       char **argv;
-       char **argp;
-       int exitstatus;
-       unsigned int i;
-
-       argc =
-         1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
-         + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0)
-         + sources_count;
-       argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
-
-       argp = argv;
-       *argp++ = "cscc";
-       if (output_is_library)
-         *argp++ = "-shared";
-       *argp++ = "-o";
-       *argp++ = (char *) output_file;
-       for (i = 0; i < libdirs_count; i++)
-         {
-           *argp++ = "-L";
-           *argp++ = (char *) libdirs[i];
-         }
-       for (i = 0; i < libraries_count; i++)
-         {
-           *argp++ = "-l";
-           *argp++ = (char *) libraries[i];
-         }
-       if (optimize)
-         *argp++ = "-O";
-       if (debug)
-         *argp++ = "-g";
-       for (i = 0; i < sources_count; i++)
-         {
-           const char *source_file = sources[i];
-           if (strlen (source_file) >= 9
-               && memcmp (source_file + strlen (source_file) - 9, ".resource",
-                          9) == 0)
-             {
-               char *option =
-                 (char *) xallocsa (12 + strlen (source_file) + 1);
-
-               memcpy (option, "-fresources=", 12);
-               strcpy (option + 12, source_file);
-               *argp++ = option;
-             }
-           else
-             *argp++ = (char *) source_file;
-         }
-       *argp = NULL;
-       /* Ensure argv length was correctly calculated.  */
-       if (argp - argv != argc)
-         abort ();
-
-       if (verbose)
-         {
-           char *command = shell_quote_argv (argv);
-           printf ("%s\n", command);
-           free (command);
-         }
-
-       exitstatus = execute ("cscc", "cscc", argv, false, false, false, false,
-                             true, true);
-
-       for (i = 0; i < sources_count; i++)
-         if (argv[argc - sources_count + i] != sources[i])
-           freesa (argv[argc - sources_count + i]);
-       freesa (argv);
-
-       return (exitstatus != 0);
-      }
-  }
-
-  {
-    static bool mcs_tested;
-    static bool mcs_present;
-
-    if (!mcs_tested)
-      {
-       /* Test for presence of mcs:
-          "mcs --version >/dev/null 2>/dev/null"  */
-       char *argv[3];
-       int exitstatus;
-
-       argv[0] = "mcs";
-       argv[1] = "--version";
-       argv[2] = NULL;
-       exitstatus = execute ("mcs", "mcs", argv, false, false, true, true,
-                             true, false);
-       mcs_present = (exitstatus == 0);
-       mcs_tested = true;
-      }
-
-    if (mcs_present)
-      {
-       unsigned int argc;
-       char **argv;
-       char **argp;
-       pid_t child;
-       int fd[1];
-       FILE *fp;
-       char *line[2];
-       size_t linesize[2];
-       size_t linelen[2];
-       unsigned int l;
-       int exitstatus;
-       unsigned int i;
-
-       argc =
-         1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
-         + 2 * libraries_count + (debug ? 1 : 0) + sources_count;
-       argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
-
-       argp = argv;
-       *argp++ = "mcs";
-       if (output_is_library)
-         *argp++ = "-target:library";
-       *argp++ = "-o";
-       *argp++ = (char *) output_file;
-       for (i = 0; i < libdirs_count; i++)
-         {
-           *argp++ = "-L";
-           *argp++ = (char *) libdirs[i];
-         }
-        for (i = 0; i < libraries_count; i++)
-         {
-           *argp++ = "-r";
-           *argp++ = (char *) libraries[i];
-         }
-       if (debug)
-         *argp++ = "-g";
-       for (i = 0; i < sources_count; i++)
-         {
-           const char *source_file = sources[i];
-           if (strlen (source_file) >= 9
-               && memcmp (source_file + strlen (source_file) - 9, ".resource",
-                          9) == 0)
-             {
-               char *option =
-                 (char *) xallocsa (10 + strlen (source_file) + 1);
-
-               memcpy (option, "-resource:", 10);
-               strcpy (option + 10, source_file);
-               *argp++ = option;
-             }
-           else
-             *argp++ = (char *) source_file;
-         }
-       *argp = NULL;
-       /* Ensure argv length was correctly calculated.  */
-       if (argp - argv != argc)
-         abort ();
-
-       if (verbose)
-         {
-           char *command = shell_quote_argv (argv);
-           printf ("%s\n", command);
-           free (command);
-         }
-
-       child = create_pipe_in ("mcs", "mcs", argv, NULL, false, true, true,
-                               fd);
-
-       /* Read the subprocess output, copying it to stderr.  Drop the last
-          line if it starts with "Compilation succeeded".  */
-       fp = fdopen (fd[0], "r");
-       if (fp == NULL)
-         error (EXIT_FAILURE, errno, _("fdopen() failed"));
-       line[0] = NULL; linesize[0] = 0;
-       line[1] = NULL; linesize[1] = 0;
-       l = 0;
-       for (;;)
-         {
-           linelen[l] = getline (&line[l], &linesize[l], fp);
-           if (linelen[l] == (size_t)(-1))
-             break;
-           l = (l + 1) % 2;
-           if (line[l] != NULL)
-             fwrite (line[l], 1, linelen[l], stderr);
-         }
-       l = (l + 1) % 2;
-       if (line[l] != NULL
-           && !(linelen[l] >= 21
-                && memcmp (line[l], "Compilation succeeded", 21) == 0))
-         fwrite (line[l], 1, linelen[l], stderr);
-       if (line[0] != NULL)
-         free (line[0]);
-       if (line[1] != NULL)
-         free (line[1]);
-       fclose (fp);
-
-       /* Remove zombie process from process list, and retrieve exit
-          status.  */
-       exitstatus = wait_subprocess (child, "mcs", false, false, true, true);
-
-       for (i = 0; i < sources_count; i++)
-         if (argv[argc - sources_count + i] != sources[i])
-           freesa (argv[argc - sources_count + i]);
-       freesa (argv);
-
-       return (exitstatus != 0);
-      }
-  }
+#if CSHARP_CHOICE_MONO
+  result = compile_csharp_using_mono (sources, sources_count,
+                                     libdirs, libdirs_count,
+                                     libraries, libraries_count,
+                                     output_file, output_is_library,
+                                     optimize, debug, verbose);
+  if (result >= 0)
+    return (bool) result;
+#endif
 
-  {
-    static bool csc_tested;
-    static bool csc_present;
+  /* Then try the remaining C# implementations in our standard order.  */
+#if !CSHARP_CHOICE_PNET
+  result = compile_csharp_using_pnet (sources, sources_count,
+                                     libdirs, libdirs_count,
+                                     libraries, libraries_count,
+                                     output_file, output_is_library,
+                                     optimize, debug, verbose);
+  if (result >= 0)
+    return (bool) result;
+#endif
 
-    if (!csc_tested)
-      {
-       /* Test for presence of csc:
-          "csc -help >/dev/null 2>/dev/null"  */
-       char *argv[3];
-       int exitstatus;
-
-       argv[0] = "csc";
-       argv[1] = "-help";
-       argv[2] = NULL;
-       exitstatus = execute ("csc", "csc", argv, false, false, true, true,
-                             true, false);
-       csc_present = (exitstatus == 0);
-       csc_tested = true;
-      }
+#if !CSHARP_CHOICE_MONO
+  result = compile_csharp_using_mono (sources, sources_count,
+                                     libdirs, libdirs_count,
+                                     libraries, libraries_count,
+                                     output_file, output_is_library,
+                                     optimize, debug, verbose);
+  if (result >= 0)
+    return (bool) result;
+#endif
 
-    if (csc_present)
-      {
-       unsigned int argc;
-       char **argv;
-       char **argp;
-       int exitstatus;
-       unsigned int i;
-
-       argc =
-         1 + 1 + 1 + libdirs_count + libraries_count
-         + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
-       argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
-
-       argp = argv;
-       *argp++ = "csc";
-       *argp++ = (output_is_library ? "-target:library" : "-target:exe");
-       {
-         char *option = (char *) xallocsa (5 + strlen (output_file) + 1);
-         memcpy (option, "-out:", 5);
-         strcpy (option + 5, output_file);
-         *argp++ = option;
-       }
-       for (i = 0; i < libdirs_count; i++)
-         {
-           char *option = (char *) xallocsa (5 + strlen (libdirs[i]) + 1);
-           memcpy (option, "-lib:", 5);
-           strcpy (option + 5, libdirs[i]);
-           *argp++ = option;
-         }
-        for (i = 0; i < libraries_count; i++)
-         {
-           char *option = (char *) xallocsa (11 + strlen (libraries[i]) + 1);
-           memcpy (option, "-reference:", 11);
-           strcpy (option + 11, libraries[i]);
-           *argp++ = option;
-         }
-       if (optimize)
-         *argp++ = "-optimize+";
-       if (debug)
-         *argp++ = "-debug+";
-       for (i = 0; i < sources_count; i++)
-         {
-           const char *source_file = sources[i];
-           if (strlen (source_file) >= 9
-               && memcmp (source_file + strlen (source_file) - 9, ".resource",
-                          9) == 0)
-             {
-               char *option =
-                 (char *) xallocsa (10 + strlen (source_file) + 1);
-
-               memcpy (option, "-resource:", 10);
-               strcpy (option + 10, source_file);
-               *argp++ = option;
-             }
-           else
-             *argp++ = (char *) source_file;
-         }
-       *argp = NULL;
-       /* Ensure argv length was correctly calculated.  */
-       if (argp - argv != argc)
-         abort ();
-
-       if (verbose)
-         {
-           char *command = shell_quote_argv (argv);
-           printf ("%s\n", command);
-           free (command);
-         }
-
-       exitstatus = execute ("csc", "csc", argv, false, false, false, false,
-                             true, true);
-
-       for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
-         freesa (argv[i]);
-       for (i = 0; i < sources_count; i++)
-         if (argv[argc - sources_count + i] != sources[i])
-           freesa (argv[argc - sources_count + i]);
-       freesa (argv);
-
-       return (exitstatus != 0);
-      }
-  }
+  result = compile_csharp_using_sscli (sources, sources_count,
+                                      libdirs, libdirs_count,
+                                      libraries, libraries_count,
+                                      output_file, output_is_library,
+                                      optimize, debug, verbose);
+  if (result >= 0)
+    return (bool) result;
 
-  error (0, 0, _("'C# compiler not found, try installing pnet"));
+  error (0, 0, _("C# compiler not found, try installing pnet"));
   return true;
 }
index e4a203498982ebe3d7fa93c3f9a1d90244a018a6..b369f88fd2c85bae30aff5ed0cf7d42cf8056e48 100644 (file)
@@ -1,5 +1,5 @@
 /* Execute a C# program.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003-2004 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
      1. "ilrun", because it is a completely free system.
      2. "mono", because it is a partially free system but doesn't integrate
         well with Unix.
+   But the order can be changed through the --enable-csharp configuration
+   option.
  */
 
+static int
+execute_csharp_using_pnet (const char *assembly_path,
+                          const char * const *libdirs,
+                          unsigned int libdirs_count,
+                          const char * const *args, unsigned int nargs,
+                          bool verbose, bool quiet,
+                          execute_fn *executer, void *private_data)
+{
+  static bool ilrun_tested;
+  static bool ilrun_present;
+
+  if (!ilrun_tested)
+    {
+      /* Test for presence of ilrun:
+        "ilrun --version >/dev/null 2>/dev/null"  */
+      char *argv[3];
+      int exitstatus;
+
+      argv[0] = "ilrun";
+      argv[1] = "--version";
+      argv[2] = NULL;
+      exitstatus = execute ("ilrun", "ilrun", argv, false, false, true, true,
+                           true, false);
+      ilrun_present = (exitstatus == 0);
+      ilrun_tested = true;
+    }
+
+  if (ilrun_present)
+    {
+      unsigned int argc;
+      char **argv;
+      char **argp;
+      unsigned int i;
+      bool err;
+
+      argc = 1 + 2 * libdirs_count + 1 + nargs;
+      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
+
+      argp = argv;
+      *argp++ = "ilrun";
+      for (i = 0; i < libdirs_count; i++)
+       {
+         *argp++ = "-L";
+         *argp++ = (char *) libdirs[i];
+       }
+      *argp++ = (char *) assembly_path;
+      for (i = 0; i < nargs; i++)
+       *argp++ = (char *) args[i];
+      *argp = NULL;
+      /* Ensure argv length was correctly calculated.  */
+      if (argp - argv != argc)
+       abort ();
+
+      if (verbose)
+       {
+         char *command = shell_quote_argv (argv);
+         printf ("%s\n", command);
+         free (command);
+       }
+
+      err = executer ("ilrun", "ilrun", argv, private_data);
+
+      freesa (argv);
+
+      return err;
+    }
+  else
+    return -1;
+}
+
+static int
+execute_csharp_using_mono (const char *assembly_path,
+                          const char * const *libdirs,
+                          unsigned int libdirs_count,
+                          const char * const *args, unsigned int nargs,
+                          bool verbose, bool quiet,
+                          execute_fn *executer, void *private_data)
+{
+  static bool mono_tested;
+  static bool mono_present;
+
+  if (!mono_tested)
+    {
+      /* Test for presence of mono:
+        "mono --version >/dev/null 2>/dev/null"  */
+      char *argv[3];
+      int exitstatus;
+
+      argv[0] = "mono";
+      argv[1] = "--version";
+      argv[2] = NULL;
+      exitstatus = execute ("mono", "mono", argv, false, false, true, true,
+                           true, false);
+      mono_present = (exitstatus == 0);
+      mono_tested = true;
+    }
+
+  if (mono_present)
+    {
+      char *old_monopath;
+      char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
+      unsigned int i;
+      bool err;
+
+      /* Set MONO_PATH.  */
+      old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);
+
+      argv[0] = "mono";
+      argv[1] = (char *) assembly_path;
+      for (i = 0; i <= nargs; i++)
+       argv[2 + i] = (char *) args[i];
+
+      if (verbose)
+       {
+         char *command = shell_quote_argv (argv);
+         printf ("%s\n", command);
+         free (command);
+       }
+
+      err = executer ("mono", "mono", argv, private_data);
+
+      /* Reset MONO_PATH.  */
+      reset_monopath (old_monopath);
+
+      freesa (argv);
+
+      return err;
+    }
+  else
+    return -1;
+}
+
 bool
 execute_csharp_program (const char *assembly_path,
                        const char * const *libdirs,
@@ -69,6 +203,7 @@ execute_csharp_program (const char *assembly_path,
                        execute_fn *executer, void *private_data)
 {
   unsigned int nargs;
+  int result;
 
   /* Count args.  */
   {
@@ -78,119 +213,39 @@ execute_csharp_program (const char *assembly_path,
      ;
   }
 
-  {
-    static bool ilrun_tested;
-    static bool ilrun_present;
-
-    if (!ilrun_tested)
-      {
-       /* Test for presence of ilrun:
-          "ilrun --version >/dev/null 2>/dev/null"  */
-       char *argv[3];
-       int exitstatus;
-
-       argv[0] = "ilrun";
-       argv[1] = "--version";
-       argv[2] = NULL;
-       exitstatus = execute ("ilrun", "ilrun", argv, false, false, true, true,
-                             true, false);
-       ilrun_present = (exitstatus == 0);
-       ilrun_tested = true;
-      }
-
-    if (ilrun_present)
-      {
-       unsigned int argc;
-       char **argv;
-       char **argp;
-       unsigned int i;
-       bool err;
-
-       argc = 1 + 2 * libdirs_count + 1 + nargs;
-       argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
-
-       argp = argv;
-       *argp++ = "ilrun";
-       for (i = 0; i < libdirs_count; i++)
-         {
-           *argp++ = "-L";
-           *argp++ = (char *) libdirs[i];
-         }
-       *argp++ = (char *) assembly_path;
-       for (i = 0; i < nargs; i++)
-         *argp++ = (char *) args[i];
-       *argp = NULL;
-       /* Ensure argv length was correctly calculated.  */
-       if (argp - argv != argc)
-         abort ();
-
-       if (verbose)
-         {
-           char *command = shell_quote_argv (argv);
-           printf ("%s\n", command);
-           free (command);
-         }
-
-       err = executer ("ilrun", "ilrun", argv, private_data);
-
-       freesa (argv);
-
-       return err;
-      }
-  }
+  /* First try the C# implementation specified through --enable-csharp.  */
+#if CSHARP_CHOICE_PNET
+  result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count,
+                                     args, nargs, verbose, quiet,
+                                     executer, private_data);
+  if (result >= 0)
+    return (bool) result;
+#endif
 
-  {
-    static bool mono_tested;
-    static bool mono_present;
-
-    if (!mono_tested)
-      {
-       /* Test for presence of mono:
-          "mono --version >/dev/null 2>/dev/null"  */
-       char *argv[3];
-       int exitstatus;
-
-       argv[0] = "mono";
-       argv[1] = "--version";
-       argv[2] = NULL;
-       exitstatus = execute ("mono", "mono", argv, false, false, true, true,
-                             true, false);
-       mono_present = (exitstatus == 0);
-       mono_tested = true;
-      }
-
-    if (mono_present)
-      {
-       char *old_monopath;
-       char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
-       unsigned int i;
-       bool err;
-
-       /* Set MONO_PATH.  */
-       old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);
-
-       argv[0] = "mono";
-       argv[1] = (char *) assembly_path;
-       for (i = 0; i <= nargs; i++)
-         argv[2 + i] = (char *) args[i];
-
-       if (verbose)
-         {
-           char *command = shell_quote_argv (argv);
-           printf ("%s\n", command);
-           free (command);
-         }
-
-       err = executer ("mono", "mono", argv, private_data);
-
-       /* Reset MONO_PATH.  */
-       reset_monopath (old_monopath);
-
-       freesa (argv);
-
-       return err;
-      }
-  }
+#if CSHARP_CHOICE_MONO
+  result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count,
+                                     args, nargs, verbose, quiet,
+                                     executer, private_data);
+  if (result >= 0)
+    return (bool) result;
+#endif
+
+  /* Then try the remaining C# implementations in our standard order.  */
+#if !CSHARP_CHOICE_PNET
+  result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count,
+                                     args, nargs, verbose, quiet,
+                                     executer, private_data);
+  if (result >= 0)
+    return (bool) result;
+#endif
+
+#if !CSHARP_CHOICE_MONO
+  result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count,
+                                     args, nargs, verbose, quiet,
+                                     executer, private_data);
+  if (result >= 0)
+    return (bool) result;
+#endif
 
   if (!quiet)
     error (0, 0, _("C# virtual machine not found, try installing pnet"));
index 96ac0d00ae92236d546d2dac69c33c7d0972a3a4..db1d1d3bcac79b4483026491cac2be7daa46f2f0 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * csharp.m4: New file.
+       * csharpcomp.m4 (gt_CSHARPCOMP): Require gt_CSHARP_CHOICE. Respect the
+       CSHARP_CHOICE given by the --enable-csharp option.
+       * csharpexec.m4 (gt_CSHARPEXEC): Require gt_CSHARP_CHOICE. Respect the
+       CSHARP_CHOICE given by the --enable-csharp option.
+       * Makefile.am (EXTRA_DIST): Add csharp.m4.
+
 2003-12-26  Bruno Haible  <bruno@clisp.org>
 
        Support for C#.
index a376494244e8a23ecc056b91e57c4e4be971f354..caf0496449b01a8f4d1f1298f33ab25f24dc1c09 100644 (file)
@@ -48,6 +48,7 @@ alloca.m4 \
 allocsa.m4 \
 backupfile.m4 \
 canonicalize.m4 \
+csharp.m4 \
 csharpcomp.m4 \
 csharpexec.m4 \
 eaccess.m4 \
index c862365e67b08261fe8e9e5d92900946371ca603..b71dce8534bdd3ca9fc481d000a3aa9fc49f9e96 100644 (file)
@@ -1,5 +1,5 @@
 # csharpcomp.m4 serial 1 (gettext-0.13.2)
-dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl Copyright (C) 2003-2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -11,6 +11,7 @@ dnl the same distribution terms as the rest of that program.
 
 AC_DEFUN([gt_CSHARPCOMP],
 [
+  AC_REQUIRE([gt_CSHARP_CHOICE])
   AC_MSG_CHECKING([for C[#] compiler])
   HAVE_CSHARPCOMP=1
   pushdef([AC_MSG_CHECKING],[:])dnl
@@ -22,26 +23,39 @@ AC_DEFUN([gt_CSHARPCOMP],
   popdef([AC_MSG_RESULT])dnl
   popdef([AC_CHECKING])dnl
   popdef([AC_MSG_CHECKING])dnl
-  if test -n "$HAVE_CSCC_IN_PATH" \
-     && cscc --version >/dev/null 2>/dev/null; then
-    HAVE_CSCC=1
-    ac_result="cscc"
-  else
-    if test -n "$HAVE_MCS_IN_PATH" \
-       && mcs --version >/dev/null 2>/dev/null; then
-      HAVE_MCS=1
-      ac_result="mcs"
-    else
-      if test -n "$HAVE_CSC_IN_PATH" \
-         && csc -help >/dev/null 2>/dev/null; then
-        HAVE_CSC=1
-        ac_result="csc"
-      else
+  for impl in "$CSHARP_CHOICE" pnet mono sscli no; do
+    case "$impl" in
+      pnet)
+        if test -n "$HAVE_CSCC_IN_PATH" \
+           && cscc --version >/dev/null 2>/dev/null; then
+          HAVE_CSCC=1
+          ac_result="cscc"
+          break
+        fi
+        ;;
+      mono)
+        if test -n "$HAVE_MCS_IN_PATH" \
+           && mcs --version >/dev/null 2>/dev/null; then
+          HAVE_MCS=1
+          ac_result="mcs"
+          break
+        fi
+        ;;
+      sscli)
+        if test -n "$HAVE_CSC_IN_PATH" \
+           && csc -help >/dev/null 2>/dev/null; then
+          HAVE_CSC=1
+          ac_result="csc"
+          break
+        fi
+        ;;
+      no)
         HAVE_CSHARPEXEC=
         ac_result="no"
-      fi
-    fi
-  fi
+        break
+        ;;
+    esac
+  done
   AC_MSG_RESULT([$ac_result])
   AC_SUBST(HAVE_CSCC)
   AC_SUBST(HAVE_MCS)
index 33c94a47b76815783261ccddac720ca94b440d64..adb3e69964c36d7634096644b391760cb87ac494 100644 (file)
@@ -1,5 +1,5 @@
 # csharpexec.m4 serial 1 (gettext-0.13.2)
-dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl Copyright (C) 2003-2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -11,6 +11,7 @@ dnl the same distribution terms as the rest of that program.
 
 AC_DEFUN([gt_CSHARPEXEC],
 [
+  AC_REQUIRE([gt_CSHARP_CHOICE])
   AC_MSG_CHECKING([for C[#] program execution engine])
   AC_EGREP_CPP(yes, [
 #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
@@ -26,20 +27,31 @@ AC_DEFUN([gt_CSHARPEXEC],
   popdef([AC_MSG_RESULT])dnl
   popdef([AC_CHECKING])dnl
   popdef([AC_MSG_CHECKING])dnl
-  if test -n "$HAVE_ILRUN_IN_PATH" \
-     && ilrun --version >/dev/null 2>/dev/null; then
-    HAVE_ILRUN=1
-    ac_result="ilrun"
-  else
-    if test -n "$HAVE_MONO_IN_PATH" \
-       && mono --version >/dev/null 2>/dev/null; then
-      HAVE_MONO=1
-      ac_result="mono"
-    else
-      HAVE_CSHARPEXEC=
-      ac_result="no"
-    fi
-  fi
+  for impl in "$CSHARP_CHOICE" pnet mono no; do
+    case "$impl" in
+      pnet)
+        if test -n "$HAVE_ILRUN_IN_PATH" \
+           && ilrun --version >/dev/null 2>/dev/null; then
+          HAVE_ILRUN=1
+          ac_result="ilrun"
+          break
+        fi
+        ;;  
+      mono)
+        if test -n "$HAVE_MONO_IN_PATH" \
+           && mono --version >/dev/null 2>/dev/null; then
+          HAVE_MONO=1
+          ac_result="mono"
+          break
+        fi
+        ;;
+      no)
+        HAVE_CSHARPEXEC=
+        ac_result="no"
+        break
+        ;;
+    esac
+  done
   AC_MSG_RESULT([$ac_result])
   AC_SUBST(MONO_PATH)
   AC_SUBST(MONO_PATH_SEPARATOR)