annotate lib/csharpcomp.c @ 9352:970d5cb5b003

Relax the license.
author Bruno Haible <bruno@clisp.org>
date Wed, 17 Oct 2007 02:11:05 +0200
parents bbbbbf4cd1c5
children d079dd7b69bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Compile a C# program.
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
2 Copyright (C) 2003-2007 Free Software Foundation, Inc.
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9173
diff changeset
5 This program is free software: you can redistribute it and/or modify
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9173
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9173
diff changeset
8 (at your option) any later version.
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9173
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
7304
1c4ed7637c24 Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 7011
diff changeset
18 #include <config.h>
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <alloca.h>
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Specification. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "csharpcomp.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <errno.h>
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdio.h>
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdlib.h>
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <string.h>
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "execute.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include "pipe.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include "wait-process.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include "sh-quote.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include "safe-read.h"
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
34 #include "xmalloca.h"
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #include "error.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #include "gettext.h"
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #define _(str) gettext (str)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 /* Survey of C# compilers.
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 Program from
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 cscc pnet
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 mcs mono
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 csc sscli
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 We try the CIL interpreters in the following order:
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 1. "cscc", because it is a completely free system.
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 2. "mcs", because it is a free system but doesn't integrate so well
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 with Unix. (Command line options start with / instead of -. Errors go
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 to stdout instead of stderr. Source references are printed as
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 "file(lineno)" instead of "file:lineno:".)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 3. "csc", although it is not free, because it is a kind of "reference
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 implementation" of C#.
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 But the order can be changed through the --enable-csharp configuration
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 option.
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 static int
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 compile_csharp_using_pnet (const char * const *sources,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 unsigned int sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 const char * const *libdirs,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 unsigned int libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 const char * const *libraries,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 unsigned int libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 const char *output_file, bool output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 bool optimize, bool debug,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 bool verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 static bool cscc_tested;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 static bool cscc_present;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 if (!cscc_tested)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* Test for presence of cscc:
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 "cscc --version >/dev/null 2>/dev/null" */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 char *argv[3];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 int exitstatus;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 argv[0] = "cscc";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 argv[1] = "--version";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 argv[2] = NULL;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 exitstatus = execute ("cscc", "cscc", argv, false, false, true, true,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 true, false);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 cscc_present = (exitstatus == 0);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 cscc_tested = true;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 if (cscc_present)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 unsigned int argc;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 char **argv;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 char **argp;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 int exitstatus;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 unsigned int i;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 argc =
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 + sources_count;
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
103 argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 argp = argv;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 *argp++ = "cscc";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 if (output_is_library)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 *argp++ = "-shared";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 *argp++ = "-o";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 *argp++ = (char *) output_file;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 for (i = 0; i < libdirs_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 *argp++ = "-L";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 *argp++ = (char *) libdirs[i];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 for (i = 0; i < libraries_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 *argp++ = "-l";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 *argp++ = (char *) libraries[i];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 if (optimize)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 *argp++ = "-O";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 if (debug)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 *argp++ = "-g";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 for (i = 0; i < sources_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 const char *source_file = sources[i];
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
128 if (strlen (source_file) >= 10
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
129 && memcmp (source_file + strlen (source_file) - 10, ".resources",
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
130 10) == 0)
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
132 char *option = (char *) xmalloca (12 + strlen (source_file) + 1);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 memcpy (option, "-fresources=", 12);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 strcpy (option + 12, source_file);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 *argp++ = option;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 else
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 *argp++ = (char *) source_file;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 *argp = NULL;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 /* Ensure argv length was correctly calculated. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 if (argp - argv != argc)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 abort ();
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 if (verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 char *command = shell_quote_argv (argv);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 printf ("%s\n", command);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 free (command);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 exitstatus = execute ("cscc", "cscc", argv, false, false, false, false,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 true, true);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 for (i = 0; i < sources_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 if (argv[argc - sources_count + i] != sources[i])
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
158 freea (argv[argc - sources_count + i]);
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
159 freea (argv);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 return (exitstatus != 0);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 else
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 return -1;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 static int
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 compile_csharp_using_mono (const char * const *sources,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 unsigned int sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 const char * const *libdirs,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 unsigned int libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 const char * const *libraries,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 unsigned int libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 const char *output_file, bool output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 bool optimize, bool debug,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 bool verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 static bool mcs_tested;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 static bool mcs_present;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 if (!mcs_tested)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 /* Test for presence of mcs:
9173
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
184 "mcs --version >/dev/null 2>/dev/null"
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
185 and (to exclude an unrelated 'mcs' program on QNX 6)
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
186 "mcs --version 2>/dev/null | grep Mono >/dev/null" */
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 char *argv[3];
9173
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
188 pid_t child;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
189 int fd[1];
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 int exitstatus;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 argv[0] = "mcs";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 argv[1] = "--version";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 argv[2] = NULL;
9173
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
195 child = create_pipe_in ("mcs", "mcs", argv, DEV_NULL, true, true, false,
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
196 fd);
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
197 mcs_present = false;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
198 if (child != -1)
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
199 {
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
200 /* Read the subprocess output, and test whether it contains the
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
201 string "Mono". */
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
202 char c[4];
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
203 size_t count = 0;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
204
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
205 while (safe_read (fd[0], &c[count], 1) > 0)
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
206 {
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
207 count++;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
208 if (count == 4)
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
209 {
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
210 if (memcmp (c, "Mono", 4) == 0)
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
211 mcs_present = true;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
212 c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
213 count--;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
214 }
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
215 }
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
216
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
217 close (fd[0]);
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
218
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
219 /* Remove zombie process from process list, and retrieve exit
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
220 status. */
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
221 exitstatus =
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
222 wait_subprocess (child, "mcs", false, true, true, false);
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
223 if (exitstatus != 0)
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
224 mcs_present = false;
6d92d3b331ed Fix mis-recognition of 'mcs' on QNX 6.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
225 }
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 mcs_tested = true;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 if (mcs_present)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 unsigned int argc;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 char **argv;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 char **argp;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 pid_t child;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 int fd[1];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 FILE *fp;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 char *line[2];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 size_t linesize[2];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 size_t linelen[2];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 unsigned int l;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 int exitstatus;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 unsigned int i;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 argc =
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
245 1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
246 + (debug ? 1 : 0) + sources_count;
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
247 argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 argp = argv;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 *argp++ = "mcs";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 if (output_is_library)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 *argp++ = "-target:library";
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
253 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
254 char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
255 memcpy (option, "-out:", 5);
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
256 strcpy (option + 5, output_file);
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
257 *argp++ = option;
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
258 }
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 for (i = 0; i < libdirs_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
261 char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
262 memcpy (option, "-lib:", 5);
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
263 strcpy (option + 5, libdirs[i]);
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
264 *argp++ = option;
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 for (i = 0; i < libraries_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
268 char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
269 memcpy (option, "-reference:", 11);
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
270 memcpy (option + 11, libraries[i], strlen (libraries[i]));
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
271 strcpy (option + 11 + strlen (libraries[i]), ".dll");
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
272 *argp++ = option;
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 if (debug)
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
275 *argp++ = "-debug";
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 for (i = 0; i < sources_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 const char *source_file = sources[i];
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
279 if (strlen (source_file) >= 10
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
280 && memcmp (source_file + strlen (source_file) - 10, ".resources",
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
281 10) == 0)
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
283 char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 memcpy (option, "-resource:", 10);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 strcpy (option + 10, source_file);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 *argp++ = option;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 else
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 *argp++ = (char *) source_file;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 *argp = NULL;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 /* Ensure argv length was correctly calculated. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 if (argp - argv != argc)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 abort ();
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 if (verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 char *command = shell_quote_argv (argv);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 printf ("%s\n", command);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 free (command);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 child = create_pipe_in ("mcs", "mcs", argv, NULL, false, true, true, fd);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 /* Read the subprocess output, copying it to stderr. Drop the last
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 line if it starts with "Compilation succeeded". */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 fp = fdopen (fd[0], "r");
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 if (fp == NULL)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 error (EXIT_FAILURE, errno, _("fdopen() failed"));
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 line[0] = NULL; linesize[0] = 0;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 line[1] = NULL; linesize[1] = 0;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 l = 0;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 for (;;)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 linelen[l] = getline (&line[l], &linesize[l], fp);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 if (linelen[l] == (size_t)(-1))
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 break;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 l = (l + 1) % 2;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 if (line[l] != NULL)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 fwrite (line[l], 1, linelen[l], stderr);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 l = (l + 1) % 2;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 if (line[l] != NULL
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 && !(linelen[l] >= 21
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 && memcmp (line[l], "Compilation succeeded", 21) == 0))
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 fwrite (line[l], 1, linelen[l], stderr);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 if (line[0] != NULL)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 free (line[0]);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 if (line[1] != NULL)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 free (line[1]);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 fclose (fp);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 /* Remove zombie process from process list, and retrieve exit status. */
6761
14eb5491c867 * lib/wait-process.c, lib/wait-process.h, lib/csharpcomp.c,
Derek R. Price <derek@ximbiot.com>
parents: 6759
diff changeset
335 exitstatus = wait_subprocess (child, "mcs", false, false, true, true);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
337 for (i = 1 + (output_is_library ? 1 : 0);
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
338 i < 1 + (output_is_library ? 1 : 0)
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
339 + 1 + libdirs_count + libraries_count;
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
340 i++)
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
341 freea (argv[i]);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 for (i = 0; i < sources_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 if (argv[argc - sources_count + i] != sources[i])
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
344 freea (argv[argc - sources_count + i]);
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
345 freea (argv);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 return (exitstatus != 0);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 else
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 return -1;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 static int
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 compile_csharp_using_sscli (const char * const *sources,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 unsigned int sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 const char * const *libdirs,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 unsigned int libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 const char * const *libraries,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 unsigned int libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 const char *output_file, bool output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 bool optimize, bool debug,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 bool verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 static bool csc_tested;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 static bool csc_present;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 if (!csc_tested)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 /* Test for presence of csc:
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 "csc -help >/dev/null 2>/dev/null \
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 && ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }" */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 char *argv[3];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 pid_t child;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 int fd[1];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 int exitstatus;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 argv[0] = "csc";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 argv[1] = "-help";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 argv[2] = NULL;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 child = create_pipe_in ("csc", "csc", argv, DEV_NULL, true, true, false,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 fd);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 csc_present = false;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 if (child != -1)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 /* Read the subprocess output, and test whether it contains the
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 string "chicken". */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 char c[7];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 size_t count = 0;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 csc_present = true;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 while (safe_read (fd[0], &c[count], 1) > 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 if (c[count] >= 'A' && c[count] <= 'Z')
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 c[count] += 'a' - 'A';
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 count++;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396 if (count == 7)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 if (memcmp (c, "chicken", 7) == 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 csc_present = false;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 c[3] = c[4]; c[4] = c[5]; c[5] = c[6];
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 count--;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 close (fd[0]);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 /* Remove zombie process from process list, and retrieve exit
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 status. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 exitstatus =
6761
14eb5491c867 * lib/wait-process.c, lib/wait-process.h, lib/csharpcomp.c,
Derek R. Price <derek@ximbiot.com>
parents: 6759
diff changeset
411 wait_subprocess (child, "csc", false, true, true, false);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 if (exitstatus != 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 csc_present = false;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 csc_tested = true;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 if (csc_present)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 unsigned int argc;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 char **argv;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 char **argp;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 int exitstatus;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 unsigned int i;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 argc =
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 1 + 1 + 1 + libdirs_count + libraries_count
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
429 argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 argp = argv;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 *argp++ = "csc";
7586
4a8b5467d8b2 Make it compile in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 7304
diff changeset
433 *argp++ =
4a8b5467d8b2 Make it compile in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 7304
diff changeset
434 (char *) (output_is_library ? "-target:library" : "-target:exe");
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
436 char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 memcpy (option, "-out:", 5);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 strcpy (option + 5, output_file);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 *argp++ = option;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 for (i = 0; i < libdirs_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
443 char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 memcpy (option, "-lib:", 5);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 strcpy (option + 5, libdirs[i]);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 *argp++ = option;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448 for (i = 0; i < libraries_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
450 char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 memcpy (option, "-reference:", 11);
6465
8fc725193330 Fix portability bug w.r.t. Microsoft's csc compiler.
Bruno Haible <bruno@clisp.org>
parents: 5913
diff changeset
452 memcpy (option + 11, libraries[i], strlen (libraries[i]));
8fc725193330 Fix portability bug w.r.t. Microsoft's csc compiler.
Bruno Haible <bruno@clisp.org>
parents: 5913
diff changeset
453 strcpy (option + 11 + strlen (libraries[i]), ".dll");
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 *argp++ = option;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456 if (optimize)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 *argp++ = "-optimize+";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 if (debug)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 *argp++ = "-debug+";
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460 for (i = 0; i < sources_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 const char *source_file = sources[i];
7011
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
463 if (strlen (source_file) >= 10
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
464 && memcmp (source_file + strlen (source_file) - 10, ".resources",
c91111628d88 Update csharpcomp module from GNU gettext 0.15.
Bruno Haible <bruno@clisp.org>
parents: 6761
diff changeset
465 10) == 0)
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 {
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
467 char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 memcpy (option, "-resource:", 10);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 strcpy (option + 10, source_file);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 *argp++ = option;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 else
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474 *argp++ = (char *) source_file;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 *argp = NULL;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 /* Ensure argv length was correctly calculated. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 if (argp - argv != argc)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479 abort ();
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 if (verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 char *command = shell_quote_argv (argv);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 printf ("%s\n", command);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 free (command);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 exitstatus = execute ("csc", "csc", argv, false, false, false, false,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 true, true);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
490
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491 for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
492 freea (argv[i]);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 for (i = 0; i < sources_count; i++)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 if (argv[argc - sources_count + i] != sources[i])
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
495 freea (argv[argc - sources_count + i]);
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 7586
diff changeset
496 freea (argv);
5913
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 return (exitstatus != 0);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 else
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 return -1;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 }
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 bool
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 compile_csharp_class (const char * const *sources,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 unsigned int sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 const char * const *libdirs,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 unsigned int libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 const char * const *libraries,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 unsigned int libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511 const char *output_file,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 bool optimize, bool debug,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 bool verbose)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 {
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 bool output_is_library =
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 (strlen (output_file) >= 4
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 && memcmp (output_file + strlen (output_file) - 4, ".dll", 4) == 0);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518 int result;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 /* First try the C# implementation specified through --enable-csharp. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521 #if CSHARP_CHOICE_PNET
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 result = compile_csharp_using_pnet (sources, sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 libdirs, libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 libraries, libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 output_file, output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 optimize, debug, verbose);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 if (result >= 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 return (bool) result;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 #endif
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 #if CSHARP_CHOICE_MONO
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 result = compile_csharp_using_mono (sources, sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 libdirs, libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 libraries, libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 output_file, output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
536 optimize, debug, verbose);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
537 if (result >= 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 return (bool) result;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 #endif
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 /* Then try the remaining C# implementations in our standard order. */
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 #if !CSHARP_CHOICE_PNET
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 result = compile_csharp_using_pnet (sources, sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 libdirs, libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545 libraries, libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 output_file, output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547 optimize, debug, verbose);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
548 if (result >= 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 return (bool) result;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 #endif
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 #if !CSHARP_CHOICE_MONO
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 result = compile_csharp_using_mono (sources, sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 libdirs, libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 libraries, libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556 output_file, output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 optimize, debug, verbose);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
558 if (result >= 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559 return (bool) result;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560 #endif
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 result = compile_csharp_using_sscli (sources, sources_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 libdirs, libdirs_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 libraries, libraries_count,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565 output_file, output_is_library,
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 optimize, debug, verbose);
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 if (result >= 0)
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
568 return (bool) result;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
569
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 error (0, 0, _("C# compiler not found, try installing pnet"));
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 return true;
3b9706263c44 New module 'csharpcomp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }