1 /* Specific flags and argument handling of the front-end of the
2 GNU compiler for the Java(TM) language.
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
30 /* Name of spec file. */
31 #define SPEC_FILE "libgcj.spec"
33 /* This bit is set if we saw a `-xfoo' language specification. */
34 #define LANGSPEC (1<<1)
35 /* True if this arg is a parameter to the previous option-taking arg. */
36 #define PARAM_ARG (1<<2)
37 /* True if this arg is a .java input file name. */
38 #define JAVA_FILE_ARG (1<<3)
39 /* True if this arg is a .class input file name. */
40 #define CLASS_FILE_ARG (1<<4)
42 static char *find_spec_file PARAMS ((const char *));
44 static const char *main_class_name = NULL;
45 int lang_specific_extra_outfiles = 0;
47 /* True if we should add -shared-libgcc to the command-line. */
48 int shared_libgcc = 1;
50 /* Once we have the proper support in jc1 (and gcc.c) working,
51 set COMBINE_INPUTS to one. This enables combining multiple *.java
52 and *.class input files to be passed to a single jc1 invocation. */
53 #define COMBINE_INPUTS 0
55 const char jvgenmain_spec[] =
56 "jvgenmain %{D*} %i %{!pipe:%umain.i} |\n\
57 cc1 %{!pipe:%Umain.i} %1 \
58 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
60 %{v:-version} %{pg:-p} %{p}\
61 %{<fbounds-check} %{<fno-bounds-check}\
62 %{<fassume-compiled} %{<fno-assume-compiled}\
63 %{<femit-class-file} %{<femit-class-files} %{<fencoding*}\
64 %{<fuse-boehm-gc} %{<fhash-synchronization} %{<fjni}\
65 %{<fclasspath*} %{<fCLASSPATH*} %{<foutput-class-dir}\
66 %{<fuse-divide-subroutine} %{<fno-use-divide-subroutine}\
67 %{f*} -fdollars-in-identifiers\
69 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
70 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%Umain.s}} |\n\
71 %{!S:as %a %Y -o %d%w%umain%O %{!pipe:%Umain.s} %A\n }";
73 /* Return full path name of spec file if it is in DIR, or NULL if
83 spec = (char *) xmalloc (strlen (dir) + sizeof (SPEC_FILE)
84 + sizeof ("-specs=") + 4);
85 strcpy (spec, "-specs=");
89 strcat (spec, SPEC_FILE);
90 if (! stat (spec + x, &sb))
97 lang_specific_driver (in_argc, in_argv, in_added_libraries)
99 const char *const **in_argv;
100 int *in_added_libraries;
104 /* If non-zero, the user gave us the `-v' flag. */
105 int saw_verbose_flag = 0;
107 /* This will be 0 if we encounter a situation where we should not
112 /* This will be 1 if multiple input files (.class and/or .java)
113 should be passed to a single jc1 invocation. */
114 int combine_inputs = 0;
116 /* Index of last .java or .class argument. */
117 int last_input_index;
119 /* A buffer containing the concatenation of the inputs files
120 (e.g. "foo.java&bar.class&baz.class"). if combine_inputs. */
121 char* combined_inputs_buffer;
123 /* Next available location in combined_inputs_buffer. */
124 int combined_inputs_pos;
126 /* Number of .java and .class source file arguments seen. */
127 int java_files_count = 0;
128 int class_files_count = 0;
130 /* Cumulative length of the .java and .class source file names. */
131 int java_files_length = 0;
132 int class_files_length = 0;
135 /* The number of arguments being added to what's in argv, other than
136 libraries. We use this to track the number of times we've inserted
140 /* Used to track options that take arguments, so we don't go wrapping
141 those with -xc++/-xnone. */
142 const char *quote = NULL;
144 /* The new argument list will be contained in this. */
145 const char **arglist;
147 /* Non-zero if we saw a `-xfoo' language specification on the
148 command line. Used to avoid adding our own -xc++ if the user
149 already gave a language for the file. */
150 int saw_speclang = 0;
152 /* "-lm" or "-lmath" if it appears on the command line. */
153 const char *saw_math ATTRIBUTE_UNUSED = 0;
155 /* "-lc" if it appears on the command line. */
156 const char *saw_libc ATTRIBUTE_UNUSED = 0;
158 /* "-lgcjgc" if it appears on the command line. */
159 const char *saw_gc ATTRIBUTE_UNUSED = 0;
161 /* Saw `-l' option for the thread library. */
162 const char *saw_threadlib ATTRIBUTE_UNUSED = 0;
164 /* Saw `-lgcj' on command line. */
165 int saw_libgcj ATTRIBUTE_UNUSED = 0;
167 /* Saw -C or -o option, respectively. */
171 /* Saw some -O* or -g* option, respectively. */
175 /* Saw a `-D' option. */
178 /* An array used to flag each argument that needs a bit set for
179 LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */
182 /* The total number of arguments with the new stuff. */
185 /* The argument list. */
186 const char *const *argv;
188 /* The number of libraries added in. */
191 /* The total number of arguments with the new stuff. */
194 /* Non-zero if linking is supposed to happen. */
197 /* Non-zero if we want to find the spec file. */
198 int want_spec_file = 1;
200 /* The argument we use to specify the spec file. */
201 char *spec_file = NULL;
205 added_libraries = *in_added_libraries;
207 args = (int *) xcalloc (argc, sizeof (int));
209 for (i = 1; i < argc; i++)
211 /* If the previous option took an argument, we swallow it here. */
215 args[i] |= PARAM_ARG;
219 /* We don't do this anymore, since we don't get them with minus
221 if (argv[i][0] == '\0' || argv[i][1] == '\0')
224 if (argv[i][0] == '-')
226 if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
227 || strcmp (argv[i], "-nodefaultlibs") == 0))
231 else if (strncmp (argv[i], "-fmain=", 7) == 0)
233 main_class_name = argv[i] + 7;
236 else if (strcmp (argv[i], "-fhelp") == 0)
238 else if (strcmp (argv[i], "-v") == 0)
240 saw_verbose_flag = 1;
243 /* If they only gave us `-v', don't try to link
248 else if (strncmp (argv[i], "-x", 2) == 0)
250 else if (strcmp (argv[i], "-C") == 0)
262 else if (argv[i][1] == 'D')
264 else if (argv[i][1] == 'g')
266 else if (argv[i][1] == 'O')
268 else if ((argv[i][2] == '\0'
269 && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
270 || strcmp (argv[i], "-Tdata") == 0
271 || strcmp (argv[i], "-MT") == 0
272 || strcmp (argv[i], "-MF") == 0)
274 if (strcmp (argv[i], "-o") == 0)
278 else if (strcmp(argv[i], "-classpath") == 0
279 || strcmp(argv[i], "-CLASSPATH") == 0)
284 else if (library != 0
285 && ((argv[i][2] == '\0'
286 && (char *) strchr ("cSEM", argv[i][1]) != NULL)
287 || strcmp (argv[i], "-MM") == 0))
289 /* Don't specify libraries if we won't link, since that would
294 /* Remember this so we can confirm -fmain option. */
297 else if (strcmp (argv[i], "-d") == 0)
299 /* `-d' option is for javac compatibility. */
303 else if (strcmp (argv[i], "-fsyntax-only") == 0
304 || strcmp (argv[i], "--syntax-only") == 0)
311 else if (strcmp (argv[i], "-static-libgcc") == 0
312 || strcmp (argv[i], "-static") == 0)
315 /* Pass other options through. */
331 len = strlen (argv[i]);
332 if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0)
334 args[i] |= JAVA_FILE_ARG;
336 java_files_length += len;
337 last_input_index = i;
339 if (len > 6 && strcmp (argv[i] + len - 6, ".class") == 0)
341 args[i] |= CLASS_FILE_ARG;
343 class_files_length += len;
344 last_input_index = i;
351 fatal ("argument to `%s' missing\n", quote);
353 if (saw_D && ! main_class_name)
354 fatal ("can't specify `-D' without `--main'\n");
356 num_args = argc + added;
361 class_files_length = 0;
362 num_args -= class_files_count;
363 num_args += 2; /* For -o NONE. */
366 fatal ("cannot specify both -C and -o");
369 if (saw_o && java_files_count + (saw_C ? 0 : class_files_count) > 1)
374 int len = java_files_length + java_files_count - 1;
375 num_args -= java_files_count;
376 num_args++; /* Add one for the combined arg. */
377 if (class_files_length > 0)
379 len += class_files_length + class_files_count - 1;
380 num_args -= class_files_count;
382 combined_inputs_buffer = (char*) xmalloc (len);
383 combined_inputs_pos = 0;
385 /* If we know we don't have to do anything, bail now. */
388 if (! added && ! library && main_class_name == NULL && ! saw_C)
397 lang_specific_extra_outfiles++;
399 if (saw_g + saw_O == 0)
403 /* There's no point adding -shared-libgcc if we don't have a shared
405 #ifndef ENABLE_SHARED_LIBGCC
409 num_args += shared_libgcc;
411 arglist = (const char **) xmalloc ((num_args + 1) * sizeof (char *));
413 for (i = 0, j = 0; i < argc; i++, j++)
415 arglist[j] = argv[i];
417 if ((args[i] & PARAM_ARG) || i == 0)
420 if (strcmp (argv[i], "-classpath") == 0
421 || strcmp (argv[i], "-CLASSPATH") == 0)
424 = (char*) xmalloc (strlen (argv[i]) + strlen (argv[i+1]) + 3);
425 sprintf (patharg, "-f%s=%s", argv[i]+1, argv[i+1]);
426 arglist[j] = patharg;
431 if (strcmp (argv[i], "-d") == 0)
433 char *patharg = (char *) xmalloc (sizeof ("-foutput-class-dir=")
434 + strlen (argv[i + 1]) + 1);
435 sprintf (patharg, "-foutput-class-dir=%s", argv[i + 1]);
436 arglist[j] = patharg;
441 if (spec_file == NULL && strncmp (argv[i], "-L", 2) == 0)
442 spec_file = find_spec_file (argv[i] + 2);
444 if (strncmp (argv[i], "-fmain=", 7) == 0)
447 fatal ("cannot specify `main' class when not linking");
452 if ((args[i] & CLASS_FILE_ARG) && saw_C)
459 if (combine_inputs && (args[i] & (CLASS_FILE_ARG|JAVA_FILE_ARG)) != 0)
461 if (combined_inputs_pos > 0)
462 combined_inputs_buffer[combined_inputs_pos++] = '&';
463 strcpy (&combined_inputs_buffer[combined_inputs_pos], argv[i]);
464 combined_inputs_pos += strlen (argv[i]);
474 combined_inputs_buffer[combined_inputs_pos] = '\0';
478 arglist[j++] = combined_inputs_buffer;
482 /* If we saw no -O or -g option, default to -g1, for javac compatibility. */
483 if (saw_g + saw_O == 0)
484 arglist[j++] = "-g1";
486 /* Read the specs file corresponding to libgcj.
487 If we didn't find the spec file on the -L path, then we hope it
488 is somewhere in the standard install areas. */
490 arglist[j++] = spec_file == NULL ? "-specs=libgcj.spec" : spec_file;
494 arglist[j++] = "-fsyntax-only";
495 arglist[j++] = "-femit-class-files";
499 arglist[j++] = "NONE";
504 arglist[j++] = "-shared-libgcc";
510 *in_added_libraries = added_libraries;
514 lang_specific_pre_link ()
516 if (main_class_name == NULL)
518 input_filename = main_class_name;
519 input_filename_length = strlen (main_class_name);
520 return do_spec (jvgenmain_spec);