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