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 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 /* 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
52 const char jvgenmain_spec[] =
53 "jvgenmain %{D*} %i %{!pipe:%umain.i} |\n\
54 cc1 %{!pipe:%Umain.i} %1 \
55 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
57 %{v:-version} %{pg:-p} %{p}\
58 %{<fbounds-check} %{<fno-bounds-check}\
59 %{<fassume-compiled} %{<fno-assume-compiled}\
60 %{<femit-class-file} %{<femit-class-files}\
61 %{<fuse-boehm-gc} %{<fhash-synchronization} %{<fjni}\
62 %{<fclasspath*} %{<fCLASSPATH*} %{<foutput-class-dir}\
63 %{<fuse-divide-subroutine} %{<fno-use-divide-subroutine}\
64 %{f*} -fdollars-in-identifiers\
66 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
67 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%Umain.s}} |\n\
68 %{!S:as %a %Y -o %d%w%umain%O %{!pipe:%Umain.s} %A\n }";
70 /* Return full path name of spec file if it is in DIR, or NULL if
80 spec = (char *) xmalloc (strlen (dir) + sizeof (SPEC_FILE)
81 + sizeof ("-specs=") + 4);
82 strcpy (spec, "-specs=");
86 strcat (spec, SPEC_FILE);
87 if (! stat (spec + x, &sb))
94 lang_specific_driver (in_argc, in_argv, in_added_libraries)
96 const char *const **in_argv;
97 int *in_added_libraries;
101 /* If non-zero, the user gave us the `-v' flag. */
102 int saw_verbose_flag = 0;
104 /* This will be 0 if we encounter a situation where we should not
109 /* This will be 1 if multiple input files (.class and/or .java)
110 should be passed to a single jc1 invocation. */
111 int combine_inputs = 0;
113 /* Index of last .java or .class argument. */
114 int last_input_index;
116 /* A buffer containing the concatenation of the inputs files
117 (e.g. "foo.java&bar.class&baz.class"). if combine_inputs. */
118 char* combined_inputs_buffer;
120 /* Next available location in combined_inputs_buffer. */
121 int combined_inputs_pos;
123 /* Number of .java and .class source file arguments seen. */
124 int java_files_count = 0;
125 int class_files_count = 0;
127 /* Cumulative length of the .java and .class source file names. */
128 int java_files_length = 0;
129 int class_files_length = 0;
132 /* The number of arguments being added to what's in argv, other than
133 libraries. We use this to track the number of times we've inserted
137 /* Used to track options that take arguments, so we don't go wrapping
138 those with -xc++/-xnone. */
139 const char *quote = NULL;
141 /* The new argument list will be contained in this. */
142 const char **arglist;
144 /* Non-zero if we saw a `-xfoo' language specification on the
145 command line. Used to avoid adding our own -xc++ if the user
146 already gave a language for the file. */
147 int saw_speclang = 0;
149 /* "-lm" or "-lmath" if it appears on the command line. */
150 const char *saw_math ATTRIBUTE_UNUSED = 0;
152 /* "-lc" if it appears on the command line. */
153 const char *saw_libc ATTRIBUTE_UNUSED = 0;
155 /* "-lgcjgc" if it appears on the command line. */
156 const char *saw_gc ATTRIBUTE_UNUSED = 0;
158 /* Saw `-l' option for the thread library. */
159 const char *saw_threadlib ATTRIBUTE_UNUSED = 0;
161 /* Saw `-lgcj' on command line. */
162 int saw_libgcj ATTRIBUTE_UNUSED = 0;
164 /* Saw -C or -o option, respectively. */
168 /* Saw some -O* or -g* option, respectively. */
172 /* Saw a `-D' option. */
175 /* An array used to flag each argument that needs a bit set for
176 LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */
179 /* The total number of arguments with the new stuff. */
182 /* The argument list. */
183 const char *const *argv;
185 /* The number of libraries added in. */
188 /* The total number of arguments with the new stuff. */
191 /* Non-zero if linking is supposed to happen. */
194 /* Non-zero if we want to find the spec file. */
195 int want_spec_file = 1;
197 /* The argument we use to specify the spec file. */
198 char *spec_file = NULL;
202 added_libraries = *in_added_libraries;
204 args = (int *) xcalloc (argc, sizeof (int));
206 for (i = 1; i < argc; i++)
208 /* If the previous option took an argument, we swallow it here. */
212 args[i] |= PARAM_ARG;
216 /* We don't do this anymore, since we don't get them with minus
218 if (argv[i][0] == '\0' || argv[i][1] == '\0')
221 if (argv[i][0] == '-')
223 if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
224 || strcmp (argv[i], "-nodefaultlibs") == 0))
228 else if (strncmp (argv[i], "-fmain=", 7) == 0)
230 main_class_name = argv[i] + 7;
233 else if (strcmp (argv[i], "-fhelp") == 0)
235 else if (strcmp (argv[i], "-v") == 0)
237 saw_verbose_flag = 1;
240 /* If they only gave us `-v', don't try to link
245 else if (strncmp (argv[i], "-x", 2) == 0)
247 else if (strcmp (argv[i], "-C") == 0)
259 else if (argv[i][1] == 'D')
261 else if (argv[i][1] == 'g')
263 else if (argv[i][1] == 'O')
265 else if ((argv[i][2] == '\0'
266 && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
267 || strcmp (argv[i], "-Tdata") == 0
268 || strcmp (argv[i], "-MT") == 0
269 || strcmp (argv[i], "-MF") == 0)
271 if (strcmp (argv[i], "-o") == 0)
275 else if (strcmp(argv[i], "-classpath") == 0
276 || strcmp(argv[i], "-CLASSPATH") == 0)
281 else if (library != 0
282 && ((argv[i][2] == '\0'
283 && (char *) strchr ("cSEM", argv[i][1]) != NULL)
284 || strcmp (argv[i], "-MM") == 0))
286 /* Don't specify libraries if we won't link, since that would
291 /* Remember this so we can confirm -fmain option. */
294 else if (strcmp (argv[i], "-d") == 0)
296 /* `-d' option is for javac compatibility. */
300 else if (strcmp (argv[i], "-fsyntax-only") == 0
301 || strcmp (argv[i], "--syntax-only") == 0)
309 /* Pass other options through. */
325 len = strlen (argv[i]);
326 if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0)
328 args[i] |= JAVA_FILE_ARG;
330 java_files_length += len;
331 last_input_index = i;
333 if (len > 6 && strcmp (argv[i] + len - 6, ".class") == 0)
335 args[i] |= CLASS_FILE_ARG;
337 class_files_length += len;
338 last_input_index = i;
345 fatal ("argument to `%s' missing\n", quote);
347 if (saw_D && ! main_class_name)
348 fatal ("can't specify `-D' without `--main'\n");
350 num_args = argc + added;
355 class_files_length = 0;
356 num_args -= class_files_count;
357 num_args += 2; /* For -o NONE. */
360 fatal ("cannot specify both -C and -o");
363 if (saw_o && java_files_count + (saw_C ? 0 : class_files_count) > 1)
368 int len = java_files_length + java_files_count - 1;
369 num_args -= java_files_count;
370 num_args++; /* Add one for the combined arg. */
371 if (class_files_length > 0)
373 len += class_files_length + class_files_count - 1;
374 num_args -= class_files_count;
376 combined_inputs_buffer = (char*) xmalloc (len);
377 combined_inputs_pos = 0;
379 /* If we know we don't have to do anything, bail now. */
382 if (! added && ! library && main_class_name == NULL && ! saw_C)
391 lang_specific_extra_outfiles++;
393 if (saw_g + saw_O == 0)
397 arglist = (const char **) xmalloc ((num_args + 1) * sizeof (char *));
399 for (i = 0, j = 0; i < argc; i++, j++)
401 arglist[j] = argv[i];
403 if ((args[i] & PARAM_ARG) || i == 0)
406 if (strcmp (argv[i], "-classpath") == 0
407 || strcmp (argv[i], "-CLASSPATH") == 0)
410 = (char*) xmalloc (strlen (argv[i]) + strlen (argv[i+1]) + 3);
411 sprintf (patharg, "-f%s=%s", argv[i]+1, argv[i+1]);
412 arglist[j] = patharg;
417 if (strcmp (argv[i], "-d") == 0)
419 char *patharg = (char *) xmalloc (sizeof ("-foutput-class-dir=")
420 + strlen (argv[i + 1]) + 1);
421 sprintf (patharg, "-foutput-class-dir=%s", argv[i + 1]);
422 arglist[j] = patharg;
427 if (spec_file == NULL && strncmp (argv[i], "-L", 2) == 0)
428 spec_file = find_spec_file (argv[i] + 2);
430 if (strncmp (argv[i], "-fmain=", 7) == 0)
433 fatal ("cannot specify `main' class when not linking");
438 if ((args[i] & CLASS_FILE_ARG) && saw_C)
445 if (combine_inputs && (args[i] & (CLASS_FILE_ARG|JAVA_FILE_ARG)) != 0)
447 if (combined_inputs_pos > 0)
448 combined_inputs_buffer[combined_inputs_pos++] = '&';
449 strcpy (&combined_inputs_buffer[combined_inputs_pos], argv[i]);
450 combined_inputs_pos += strlen (argv[i]);
460 combined_inputs_buffer[combined_inputs_pos] = '\0';
464 arglist[j++] = combined_inputs_buffer;
468 /* If we saw no -O or -g option, default to -g1, for javac compatibility. */
469 if (saw_g + saw_O == 0)
470 arglist[j++] = "-g1";
472 /* Read the specs file corresponding to libgcj.
473 If we didn't find the spec file on the -L path, then we hope it
474 is somewhere in the standard install areas. */
476 arglist[j++] = spec_file == NULL ? "-specs=libgcj.spec" : spec_file;
480 arglist[j++] = "-fsyntax-only";
481 arglist[j++] = "-femit-class-files";
485 arglist[j++] = "NONE";
493 *in_added_libraries = added_libraries;
497 lang_specific_pre_link ()
499 if (main_class_name == NULL)
501 input_filename = main_class_name;
502 input_filename_length = strlen (main_class_name);
503 return do_spec (jvgenmain_spec);