]> gcc.gnu.org Git - gcc.git/blame - gcc/java/jvspec.c
buffer.h: PROTO -> PARAMS.
[gcc.git] / gcc / java / jvspec.c
CommitLineData
1938bea6 1 /* Specific flags and argument handling of the front-end of the
e04a16fb 2 GNU compiler for the Java(TM) language.
df32d2ce 3 Copyright (C) 1996, 97-99, 2000 Free Software Foundation, Inc.
e04a16fb
AG
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.
21
22Java and all Java-based marks are trademarks or registered trademarks
23of Sun Microsystems, Inc. in the United States and other countries.
24The Free Software Foundation is independent of Sun Microsystems, Inc. */
25
26#include "config.h"
e04a16fb 27#include "system.h"
9257393c 28#include "gcc.h"
e04a16fb 29
6a09296d
TT
30/* Name of spec file. */
31#define SPEC_FILE "libgcj.spec"
aaff4ee4 32
e04a16fb
AG
33/* This bit is set if we saw a `-xfoo' language specification. */
34#define LANGSPEC (1<<1)
1938bea6 35/* True if this arg is a parameter to the previous option-taking arg. */
6a09296d 36#define PARAM_ARG (1<<2)
1938bea6 37/* True if this arg is a .java input file name. */
6a09296d 38#define JAVA_FILE_ARG (1<<3)
1938bea6 39/* True if this arg is a .class input file name. */
6a09296d 40#define CLASS_FILE_ARG (1<<4)
e04a16fb 41
df32d2ce 42static char *find_spec_file PARAMS ((const char *));
9257393c
KG
43
44static const char *main_class_name = NULL;
e04a16fb
AG
45int lang_specific_extra_outfiles = 0;
46
1938bea6
PB
47/* Once we have the proper support in jc1 (and gcc.c) working,
48 set COMBINE_INPUTS to one. This enables combining multiple *.java
49 and *.class input files to be passed to a single jc1 invocation. */
50#define COMBINE_INPUTS 0
51
9257393c 52const char jvgenmain_spec[] =
7cf41963 53 "jvgenmain %{D*} %i %{!pipe:%umain.i} |\n\
8f426586 54 cc1 %{!pipe:%Umain.i} %1 \
e04a16fb
AG
55 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
56 %{g*} %{O*} \
57 %{v:-version} %{pg:-p} %{p} %{f*}\
58 %{aux-info*}\
59 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
8f426586
TT
60 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%Umain.s}} |\n\
61 %{!S:as %a %Y -o %d%w%umain%O %{!pipe:%Umain.s} %A\n }";
e04a16fb 62
6a09296d
TT
63/* Return full path name of spec file if it is in DIR, or NULL if
64 not. */
65static char *
66find_spec_file (dir)
be245ac0 67 const char *dir;
6a09296d
TT
68{
69 char *spec;
70 int x;
71 struct stat sb;
72
73 spec = (char *) xmalloc (strlen (dir) + sizeof (SPEC_FILE)
74 + sizeof ("-specs=") + 4);
75 strcpy (spec, "-specs=");
76 x = strlen (spec);
77 strcat (spec, dir);
78 strcat (spec, "/");
79 strcat (spec, SPEC_FILE);
80 if (! stat (spec + x, &sb))
81 return spec;
82 free (spec);
83 return NULL;
84}
85
e04a16fb 86void
9257393c 87lang_specific_driver (in_argc, in_argv, in_added_libraries)
e04a16fb
AG
88 int *in_argc;
89 char ***in_argv;
90 int *in_added_libraries;
91{
92 int i, j;
93
94 /* If non-zero, the user gave us the `-v' flag. */
95 int saw_verbose_flag = 0;
96
97 /* This will be 0 if we encounter a situation where we should not
00368bdd 98 link in libgcj. */
e04a16fb
AG
99 int library = 1;
100
1938bea6
PB
101#if COMBINE_INPUTS
102 /* This will be 1 if multiple input files (.class and/or .java)
103 should be passed to a single jc1 invocation. */
104 int combine_inputs = 0;
105
106 /* Index of last .java or .class argument. */
107 int last_input_index;
108
109 /* A buffer containing the concatenation of the inputs files
110 (e.g. "foo.java&bar.class&baz.class"). if combine_inputs. */
111 char* combined_inputs_buffer;
112
113 /* Next available location in combined_inputs_buffer. */
114 int combined_inputs_pos;
115
116 /* Number of .java and .class source file arguments seen. */
117 int java_files_count = 0;
118 int class_files_count = 0;
119
120 /* Cumulative length of the .java and .class source file names. */
121 int java_files_length = 0;
122 int class_files_length = 0;
123#endif
124
e04a16fb
AG
125 /* The number of arguments being added to what's in argv, other than
126 libraries. We use this to track the number of times we've inserted
127 -xc++/-xnone. */
128 int added = 2;
129
130 /* Used to track options that take arguments, so we don't go wrapping
131 those with -xc++/-xnone. */
9257393c 132 const char *quote = NULL;
e04a16fb
AG
133
134 /* The new argument list will be contained in this. */
9257393c
KG
135 char **real_arglist;
136 const char **arglist;
e04a16fb
AG
137
138 /* Non-zero if we saw a `-xfoo' language specification on the
139 command line. Used to avoid adding our own -xc++ if the user
140 already gave a language for the file. */
141 int saw_speclang = 0;
142
143 /* "-lm" or "-lmath" if it appears on the command line. */
9257393c 144 const char *saw_math ATTRIBUTE_UNUSED = 0;
e04a16fb
AG
145
146 /* "-lc" if it appears on the command line. */
9257393c 147 const char *saw_libc ATTRIBUTE_UNUSED = 0;
e04a16fb 148
0ffe9eea 149 /* "-lgcjgc" if it appears on the command line. */
9257393c 150 const char *saw_gc ATTRIBUTE_UNUSED = 0;
e04a16fb
AG
151
152 /* Saw `-l' option for the thread library. */
9257393c 153 const char *saw_threadlib ATTRIBUTE_UNUSED = 0;
e04a16fb 154
00368bdd 155 /* Saw `-lgcj' on command line. */
ab3a6dd6 156 int saw_libgcj ATTRIBUTE_UNUSED = 0;
e04a16fb 157
1938bea6
PB
158 /* Saw -C or -o option, respectively. */
159 int saw_C = 0;
160 int saw_o = 0;
161
e77dbc56 162 /* Saw some -O* or -g* option, respectively. */
743b0973
PB
163 int saw_O = 0;
164 int saw_g = 0;
165
7cf41963
TT
166 /* Saw a `-D' option. */
167 int saw_D = 0;
168
e04a16fb
AG
169 /* An array used to flag each argument that needs a bit set for
170 LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */
171 int *args;
172
e04a16fb
AG
173 /* The total number of arguments with the new stuff. */
174 int argc;
175
176 /* The argument list. */
177 char **argv;
178
179 /* The number of libraries added in. */
180 int added_libraries;
181
182 /* The total number of arguments with the new stuff. */
183 int num_args = 1;
184
8376a32e
PB
185 /* Non-zero if linking is supposed to happen. */
186 int will_link = 1;
187
20c96b2a
TT
188 /* Non-zero if we want to find the spec file. */
189 int want_spec_file = 1;
190
6a09296d
TT
191 /* The argument we use to specify the spec file. */
192 char *spec_file = NULL;
193
e04a16fb
AG
194 argc = *in_argc;
195 argv = *in_argv;
196 added_libraries = *in_added_libraries;
197
c2e3db92 198 args = (int *) xcalloc (argc, sizeof (int));
e04a16fb
AG
199
200 for (i = 1; i < argc; i++)
201 {
202 /* If the previous option took an argument, we swallow it here. */
203 if (quote)
204 {
205 quote = NULL;
1938bea6 206 args[i] |= PARAM_ARG;
e04a16fb
AG
207 continue;
208 }
209
210 /* We don't do this anymore, since we don't get them with minus
211 signs on them. */
212 if (argv[i][0] == '\0' || argv[i][1] == '\0')
213 continue;
214
215 if (argv[i][0] == '-')
216 {
217 if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
218 || strcmp (argv[i], "-nodefaultlibs") == 0))
219 {
220 library = 0;
221 }
e04a16fb 222 else if (strncmp (argv[i], "-fmain=", 7) == 0)
1938bea6
PB
223 {
224 main_class_name = argv[i] + 7;
225 added--;
226 }
4198d734 227 else if (strcmp (argv[i], "-fhelp") == 0)
20c96b2a 228 want_spec_file = 0;
e04a16fb
AG
229 else if (strcmp (argv[i], "-v") == 0)
230 {
231 saw_verbose_flag = 1;
232 if (argc == 2)
233 {
234 /* If they only gave us `-v', don't try to link
00368bdd 235 in libgcj. */
e04a16fb
AG
236 library = 0;
237 }
238 }
239 else if (strncmp (argv[i], "-x", 2) == 0)
240 saw_speclang = 1;
1938bea6
PB
241 else if (strcmp (argv[i], "-C") == 0)
242 {
243 saw_C = 1;
20c96b2a 244 want_spec_file = 0;
1938bea6
PB
245#if COMBINE_INPUTS
246 combine_inputs = 1;
247#endif
248 if (library != 0)
249 added -= 2;
250 library = 0;
251 will_link = 0;
252 }
7cf41963
TT
253 else if (argv[i][1] == 'D')
254 saw_D = 1;
743b0973
PB
255 else if (argv[i][1] == 'g')
256 saw_g = 1;
257 else if (argv[i][1] == 'O')
258 saw_O = 1;
e04a16fb
AG
259 else if (((argv[i][2] == '\0'
260 && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
261 || strcmp (argv[i], "-Tdata") == 0))
1938bea6
PB
262 {
263 if (strcmp (argv[i], "-o") == 0)
264 saw_o = 1;
265 quote = argv[i];
266 }
267 else if (strcmp(argv[i], "-classpath") == 0
268 || strcmp(argv[i], "-CLASSPATH") == 0)
269 {
270 quote = argv[i];
271 added -= 1;
272 }
8376a32e
PB
273 else if (library != 0
274 && ((argv[i][2] == '\0'
275 && (char *) strchr ("cSEM", argv[i][1]) != NULL)
276 || strcmp (argv[i], "-MM") == 0))
e04a16fb
AG
277 {
278 /* Don't specify libraries if we won't link, since that would
279 cause a warning. */
280 library = 0;
281 added -= 2;
8376a32e
PB
282
283 /* Remember this so we can confirm -fmain option. */
284 will_link = 0;
e04a16fb 285 }
df66b566
TT
286 else if (strcmp (argv[i], "-d") == 0)
287 {
288 /* `-d' option is for javac compatibility. */
289 quote = argv[i];
290 added -= 1;
291 }
4e2e5821
TT
292 else if (strcmp (argv[i], "-fsyntax-only") == 0
293 || strcmp (argv[i], "--syntax-only") == 0)
294 {
0cffaca3 295 want_spec_file = 0;
4e2e5821
TT
296 library = 0;
297 will_link = 0;
298 continue;
299 }
e04a16fb
AG
300 else
301 /* Pass other options through. */
302 continue;
303 }
304 else
305 {
9ee9b555 306#if COMBINE_INPUTS
e04a16fb 307 int len;
9ee9b555 308#endif
e04a16fb
AG
309
310 if (saw_speclang)
311 {
312 saw_speclang = 0;
313 continue;
314 }
315
1938bea6 316#if COMBINE_INPUTS
e04a16fb 317 len = strlen (argv[i]);
1938bea6
PB
318 if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0)
319 {
320 args[i] |= JAVA_FILE_ARG;
321 java_files_count++;
322 java_files_length += len;
323 last_input_index = i;
324 }
325 if (len > 6 && strcmp (argv[i] + len - 6, ".class") == 0)
e04a16fb 326 {
1938bea6
PB
327 args[i] |= CLASS_FILE_ARG;
328 class_files_count++;
329 class_files_length += len;
330 last_input_index = i;
e04a16fb 331 }
1938bea6 332#endif
e04a16fb
AG
333 }
334 }
335
336 if (quote)
9257393c 337 fatal ("argument to `%s' missing\n", quote);
e04a16fb 338
7cf41963
TT
339 if (saw_D && ! main_class_name)
340 fatal ("can't specify `-D' without `--main'\n");
341
1938bea6 342 num_args = argc + added;
1938bea6
PB
343 if (saw_C)
344 {
345 num_args += 3;
346#if COMBINE_INPUTS
347 class_files_length = 0;
348 num_args -= class_files_count;
349 num_args += 2; /* For -o NONE. */
350#endif
351 if (saw_o)
9257393c 352 fatal ("cannot specify both -C and -o");
1938bea6
PB
353 }
354#if COMBINE_INPUTS
355 if (saw_o && java_files_count + (saw_C ? 0 : class_files_count) > 1)
356 combine_inputs = 1;
357
358 if (combine_inputs)
359 {
360 int len = java_files_length + java_files_count - 1;
361 num_args -= java_files_count;
362 num_args++; /* Add one for the combined arg. */
363 if (class_files_length > 0)
364 {
365 len += class_files_length + class_files_count - 1;
366 num_args -= class_files_count;
367 }
368 combined_inputs_buffer = (char*) xmalloc (len);
369 combined_inputs_pos = 0;
370 }
e04a16fb 371 /* If we know we don't have to do anything, bail now. */
1938bea6
PB
372#endif
373#if 0
374 if (! added && ! library && main_class_name == NULL && ! saw_C)
e04a16fb
AG
375 {
376 free (args);
377 return;
378 }
1938bea6 379#endif
e04a16fb 380
e04a16fb
AG
381 if (main_class_name)
382 {
383 lang_specific_extra_outfiles++;
384 }
743b0973
PB
385 if (saw_g + saw_O == 0)
386 num_args++;
0b094f65 387 num_args++;
9257393c
KG
388 arglist = (const char **)
389 (real_arglist = (char **) xmalloc ((num_args + 1) * sizeof (char *)));
e04a16fb 390
e04a16fb
AG
391 for (i = 0, j = 0; i < argc; i++, j++)
392 {
393 arglist[j] = argv[i];
394
1938bea6
PB
395 if ((args[i] & PARAM_ARG) || i == 0)
396 continue;
397
398 if (strcmp (argv[i], "-classpath") == 0
399 || strcmp (argv[i], "-CLASSPATH") == 0)
400 {
401 char* patharg
402 = (char*) xmalloc (strlen (argv[i]) + strlen (argv[i+1]) + 3);
403 sprintf (patharg, "-f%s=%s", argv[i]+1, argv[i+1]);
404 arglist[j] = patharg;
405 i++;
406 continue;
407 }
408
df66b566
TT
409 if (strcmp (argv[i], "-d") == 0)
410 {
411 char *patharg = (char *) xmalloc (sizeof ("-foutput-class-dir=")
412 + strlen (argv[i + 1]) + 1);
413 sprintf (patharg, "-foutput-class-dir=%s", argv[i + 1]);
414 arglist[j] = patharg;
415 ++i;
416 continue;
417 }
418
0b094f65 419 if (spec_file == NULL && strncmp (argv[i], "-L", 2) == 0)
6a09296d
TT
420 spec_file = find_spec_file (argv[i] + 2);
421
e04a16fb
AG
422 if (strncmp (argv[i], "-fmain=", 7) == 0)
423 {
8376a32e 424 if (! will_link)
9257393c 425 fatal ("cannot specify `main' class when not linking");
e04a16fb
AG
426 --j;
427 continue;
428 }
429
1938bea6
PB
430 if ((args[i] & CLASS_FILE_ARG) && saw_C)
431 {
432 --j;
433 continue;
434 }
435
436#if COMBINE_INPUTS
437 if (combine_inputs && (args[i] & (CLASS_FILE_ARG|JAVA_FILE_ARG)) != 0)
438 {
439 if (combined_inputs_pos > 0)
440 combined_inputs_buffer[combined_inputs_pos++] = '&';
441 strcpy (&combined_inputs_buffer[combined_inputs_pos], argv[i]);
442 combined_inputs_pos += strlen (argv[i]);
443 --j;
444 continue;
445 }
446#endif
e04a16fb
AG
447 }
448
1938bea6
PB
449#if COMBINE_INPUTS
450 if (combine_inputs)
451 {
452 combined_inputs_buffer[combined_inputs_pos] = '\0';
453#if 0
454 if (! saw_C)
455#endif
456 arglist[j++] = combined_inputs_buffer;
457 }
458#endif
459
743b0973
PB
460 /* If we saw no -O or -g option, default to -g1, for javac compatibility. */
461 if (saw_g + saw_O == 0)
462 arglist[j++] = "-g1";
463
0b094f65 464 /* Read the specs file corresponding to libgcj.
6a09296d
TT
465 If we didn't find the spec file on the -L path, then we hope it
466 is somewhere in the standard install areas. */
20c96b2a 467 if (want_spec_file)
6a09296d 468 arglist[j++] = spec_file == NULL ? "-specs=libgcj.spec" : spec_file;
e04a16fb 469
1938bea6
PB
470 if (saw_C)
471 {
472 arglist[j++] = "-fsyntax-only";
473 arglist[j++] = "-femit-class-files";
474 arglist[j++] = "-S";
475#if COMBINE_INPUTS
476 arglist[j++] = "-o";
477 arglist[j++] = "NONE";
478#endif
479 }
480
e04a16fb
AG
481 arglist[j] = NULL;
482
483 *in_argc = j;
9257393c 484 *in_argv = real_arglist;
e04a16fb
AG
485 *in_added_libraries = added_libraries;
486}
487
488int
489lang_specific_pre_link ()
490{
491 if (main_class_name == NULL)
492 return 0;
493 input_filename = main_class_name;
494 input_filename_length = strlen (main_class_name);
495 return do_spec (jvgenmain_spec);
496}
This page took 0.363951 seconds and 5 git commands to generate.