/* Compile a C# program.
- Copyright (C) 2003-2005 Free Software Foundation, Inc.
+ Copyright (C) 2003-2008 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
#include <alloca.h>
/* Specification. */
#include "execute.h"
#include "pipe.h"
#include "wait-process.h"
-#include "getline.h"
#include "sh-quote.h"
#include "safe-read.h"
-#include "xallocsa.h"
+#include "xmalloca.h"
#include "error.h"
#include "gettext.h"
argv[1] = "--version";
argv[2] = NULL;
exitstatus = execute ("cscc", "cscc", argv, false, false, true, true,
- true, false);
+ true, false, NULL);
cscc_present = (exitstatus == 0);
cscc_tested = true;
}
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 *));
+ argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
argp = argv;
*argp++ = "cscc";
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)
+ if (strlen (source_file) >= 10
+ && memcmp (source_file + strlen (source_file) - 10, ".resources",
+ 10) == 0)
{
- char *option = (char *) xallocsa (12 + strlen (source_file) + 1);
+ char *option = (char *) xmalloca (12 + strlen (source_file) + 1);
memcpy (option, "-fresources=", 12);
strcpy (option + 12, source_file);
}
exitstatus = execute ("cscc", "cscc", argv, false, false, false, false,
- true, true);
+ true, true, NULL);
for (i = 0; i < sources_count; i++)
if (argv[argc - sources_count + i] != sources[i])
- freesa (argv[argc - sources_count + i]);
- freesa (argv);
+ freea (argv[argc - sources_count + i]);
+ freea (argv);
return (exitstatus != 0);
}
if (!mcs_tested)
{
/* Test for presence of mcs:
- "mcs --version >/dev/null 2>/dev/null" */
+ "mcs --version >/dev/null 2>/dev/null"
+ and (to exclude an unrelated 'mcs' program on QNX 6)
+ "mcs --version 2>/dev/null | grep Mono >/dev/null" */
char *argv[3];
+ pid_t child;
+ int fd[1];
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);
+ child = create_pipe_in ("mcs", "mcs", argv, DEV_NULL, true, true, false,
+ fd);
+ mcs_present = false;
+ if (child != -1)
+ {
+ /* Read the subprocess output, and test whether it contains the
+ string "Mono". */
+ char c[4];
+ size_t count = 0;
+
+ while (safe_read (fd[0], &c[count], 1) > 0)
+ {
+ count++;
+ if (count == 4)
+ {
+ if (memcmp (c, "Mono", 4) == 0)
+ mcs_present = true;
+ c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
+ count--;
+ }
+ }
+
+ close (fd[0]);
+
+ /* Remove zombie process from process list, and retrieve exit
+ status. */
+ exitstatus =
+ wait_subprocess (child, "mcs", false, true, true, false, NULL);
+ if (exitstatus != 0)
+ mcs_present = false;
+ }
mcs_tested = true;
}
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 *));
+ 1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count
+ + (debug ? 1 : 0) + sources_count;
+ argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
argp = argv;
*argp++ = "mcs";
if (output_is_library)
*argp++ = "-target:library";
- *argp++ = "-o";
- *argp++ = (char *) output_file;
+ {
+ char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
+ memcpy (option, "-out:", 5);
+ strcpy (option + 5, output_file);
+ *argp++ = option;
+ }
for (i = 0; i < libdirs_count; i++)
{
- *argp++ = "-L";
- *argp++ = (char *) libdirs[i];
+ char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
+ memcpy (option, "-lib:", 5);
+ strcpy (option + 5, libdirs[i]);
+ *argp++ = option;
}
for (i = 0; i < libraries_count; i++)
{
- *argp++ = "-r";
- *argp++ = (char *) libraries[i];
+ char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
+ memcpy (option, "-reference:", 11);
+ memcpy (option + 11, libraries[i], strlen (libraries[i]));
+ strcpy (option + 11 + strlen (libraries[i]), ".dll");
+ *argp++ = option;
}
if (debug)
- *argp++ = "-g";
+ *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)
+ if (strlen (source_file) >= 10
+ && memcmp (source_file + strlen (source_file) - 10, ".resources",
+ 10) == 0)
{
- char *option = (char *) xallocsa (10 + strlen (source_file) + 1);
+ char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
memcpy (option, "-resource:", 10);
strcpy (option + 10, source_file);
fclose (fp);
/* Remove zombie process from process list, and retrieve exit status. */
- exitstatus = wait_subprocess (child, "mcs", NULL, false, false, true,
- true);
-
+ exitstatus =
+ wait_subprocess (child, "mcs", false, false, true, true, NULL);
+
+ for (i = 1 + (output_is_library ? 1 : 0);
+ i < 1 + (output_is_library ? 1 : 0)
+ + 1 + libdirs_count + libraries_count;
+ i++)
+ freea (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);
+ freea (argv[argc - sources_count + i]);
+ freea (argv);
return (exitstatus != 0);
}
/* Remove zombie process from process list, and retrieve exit
status. */
exitstatus =
- wait_subprocess (child, "csc", NULL, false, true, true, false);
+ wait_subprocess (child, "csc", false, true, true, false, NULL);
if (exitstatus != 0)
csc_present = false;
}
argc =
1 + 1 + 1 + libdirs_count + libraries_count
+ (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
- argv = (char **) xallocsa ((argc + 1) * sizeof (char *));
+ argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
argp = argv;
*argp++ = "csc";
- *argp++ = (output_is_library ? "-target:library" : "-target:exe");
+ *argp++ =
+ (char *) (output_is_library ? "-target:library" : "-target:exe");
{
- char *option = (char *) xallocsa (5 + strlen (output_file) + 1);
+ char *option = (char *) xmalloca (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);
+ char *option = (char *) xmalloca (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]) + 4 + 1);
+ char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
memcpy (option, "-reference:", 11);
memcpy (option + 11, libraries[i], strlen (libraries[i]));
strcpy (option + 11 + strlen (libraries[i]), ".dll");
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)
+ if (strlen (source_file) >= 10
+ && memcmp (source_file + strlen (source_file) - 10, ".resources",
+ 10) == 0)
{
- char *option = (char *) xallocsa (10 + strlen (source_file) + 1);
+ char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
memcpy (option, "-resource:", 10);
strcpy (option + 10, source_file);
}
exitstatus = execute ("csc", "csc", argv, false, false, false, false,
- true, true);
+ true, true, NULL);
for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
- freesa (argv[i]);
+ freea (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);
+ freea (argv[argc - sources_count + i]);
+ freea (argv);
return (exitstatus != 0);
}