1 /* Execute a C# program.
2 Copyright (C) 2003-2004 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "csharpexec.h"
36 /* Handling of MONO_PATH is just like Java CLASSPATH. */
37 #define CLASSPATHVAR "MONO_PATH"
38 #define new_classpath new_monopath
39 #define set_classpath set_monopath
40 #define reset_classpath reset_monopath
41 #include "classpath.h"
42 #include "classpath.c"
44 #define _(str) gettext (str)
47 /* Survey of CIL interpreters.
54 With Mono, the MONO_PATH is a colon separated list of pathnames. (On
55 Windows: semicolon separated list of pathnames.)
57 We try the CIL interpreters in the following order:
58 1. "ilrun", because it is a completely free system.
59 2. "mono", because it is a partially free system but doesn't integrate
61 But the order can be changed through the --enable-csharp configuration
66 execute_csharp_using_pnet (const char *assembly_path,
67 const char * const *libdirs,
68 unsigned int libdirs_count,
69 const char * const *args, unsigned int nargs,
70 bool verbose, bool quiet,
71 execute_fn *executer, void *private_data)
73 static bool ilrun_tested;
74 static bool ilrun_present;
78 /* Test for presence of ilrun:
79 "ilrun --version >/dev/null 2>/dev/null" */
84 argv[1] = "--version";
86 exitstatus = execute ("ilrun", "ilrun", argv, false, false, true, true,
88 ilrun_present = (exitstatus == 0);
100 argc = 1 + 2 * libdirs_count + 1 + nargs;
101 argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
105 for (i = 0; i < libdirs_count; i++)
108 *argp++ = (char *) libdirs[i];
110 *argp++ = (char *) assembly_path;
111 for (i = 0; i < nargs; i++)
112 *argp++ = (char *) args[i];
114 /* Ensure argv length was correctly calculated. */
115 if (argp - argv != argc)
120 char *command = shell_quote_argv (argv);
121 printf ("%s\n", command);
125 err = executer ("ilrun", "ilrun", argv, private_data);
136 execute_csharp_using_mono (const char *assembly_path,
137 const char * const *libdirs,
138 unsigned int libdirs_count,
139 const char * const *args, unsigned int nargs,
140 bool verbose, bool quiet,
141 execute_fn *executer, void *private_data)
143 static bool mono_tested;
144 static bool mono_present;
148 /* Test for presence of mono:
149 "mono --version >/dev/null 2>/dev/null" */
154 argv[1] = "--version";
156 exitstatus = execute ("mono", "mono", argv, false, false, true, true,
158 mono_present = (exitstatus == 0);
165 char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
170 old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);
173 argv[1] = (char *) assembly_path;
174 for (i = 0; i <= nargs; i++)
175 argv[2 + i] = (char *) args[i];
179 char *command = shell_quote_argv (argv);
180 printf ("%s\n", command);
184 err = executer ("mono", "mono", argv, private_data);
186 /* Reset MONO_PATH. */
187 reset_monopath (old_monopath);
198 execute_csharp_program (const char *assembly_path,
199 const char * const *libdirs,
200 unsigned int libdirs_count,
201 const char * const *args,
202 bool verbose, bool quiet,
203 execute_fn *executer, void *private_data)
210 const char * const *arg;
212 for (nargs = 0, arg = args; *arg != NULL; nargs++, arg++)
216 /* First try the C# implementation specified through --enable-csharp. */
217 #if CSHARP_CHOICE_PNET
218 result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count,
219 args, nargs, verbose, quiet,
220 executer, private_data);
222 return (bool) result;
225 #if CSHARP_CHOICE_MONO
226 result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count,
227 args, nargs, verbose, quiet,
228 executer, private_data);
230 return (bool) result;
233 /* Then try the remaining C# implementations in our standard order. */
234 #if !CSHARP_CHOICE_PNET
235 result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count,
236 args, nargs, verbose, quiet,
237 executer, private_data);
239 return (bool) result;
242 #if !CSHARP_CHOICE_MONO
243 result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count,
244 args, nargs, verbose, quiet,
245 executer, private_data);
247 return (bool) result;
251 error (0, 0, _("C# virtual machine not found, try installing pnet"));