xref: /openbsd/gnu/usr.bin/gcc/gcc/java/jvspec.c (revision c87b03e5)
1*c87b03e5Sespie /* Specific flags and argument handling of the front-end of the
2*c87b03e5Sespie    GNU compiler for the Java(TM) language.
3*c87b03e5Sespie    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4*c87b03e5Sespie 
5*c87b03e5Sespie This file is part of GNU CC.
6*c87b03e5Sespie 
7*c87b03e5Sespie GNU CC is free software; you can redistribute it and/or modify
8*c87b03e5Sespie it under the terms of the GNU General Public License as published by
9*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
10*c87b03e5Sespie any later version.
11*c87b03e5Sespie 
12*c87b03e5Sespie GNU CC is distributed in the hope that it will be useful,
13*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c87b03e5Sespie GNU General Public License for more details.
16*c87b03e5Sespie 
17*c87b03e5Sespie You should have received a copy of the GNU General Public License
18*c87b03e5Sespie along with GNU CC; see the file COPYING.  If not, write to
19*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
20*c87b03e5Sespie Boston, MA 02111-1307, USA.
21*c87b03e5Sespie 
22*c87b03e5Sespie Java and all Java-based marks are trademarks or registered trademarks
23*c87b03e5Sespie of Sun Microsystems, Inc. in the United States and other countries.
24*c87b03e5Sespie The Free Software Foundation is independent of Sun Microsystems, Inc.  */
25*c87b03e5Sespie 
26*c87b03e5Sespie #include "config.h"
27*c87b03e5Sespie #include "system.h"
28*c87b03e5Sespie #include "gcc.h"
29*c87b03e5Sespie 
30*c87b03e5Sespie /* Name of spec file.  */
31*c87b03e5Sespie #define SPEC_FILE "libgcj.spec"
32*c87b03e5Sespie 
33*c87b03e5Sespie /* This bit is set if we saw a `-xfoo' language specification.  */
34*c87b03e5Sespie #define LANGSPEC	(1<<1)
35*c87b03e5Sespie /* True if this arg is a parameter to the previous option-taking arg. */
36*c87b03e5Sespie #define PARAM_ARG	(1<<2)
37*c87b03e5Sespie /* True if this arg is a .java input file name. */
38*c87b03e5Sespie #define JAVA_FILE_ARG	(1<<3)
39*c87b03e5Sespie /* True if this arg is a .class input file name. */
40*c87b03e5Sespie #define CLASS_FILE_ARG	(1<<4)
41*c87b03e5Sespie /* True if this arg is a .zip or .jar input file name. */
42*c87b03e5Sespie #define ZIP_FILE_ARG	(1<<5)
43*c87b03e5Sespie /* True if this arg is @FILE - where FILE contains a list of filenames. */
44*c87b03e5Sespie #define INDIRECT_FILE_ARG (1<<6)
45*c87b03e5Sespie /* True if this arg is a resource file.  */
46*c87b03e5Sespie #define RESOURCE_FILE_ARG (1<<7)
47*c87b03e5Sespie 
48*c87b03e5Sespie static char *find_spec_file	PARAMS ((const char *));
49*c87b03e5Sespie static int verify_class_name    PARAMS ((const char *));
50*c87b03e5Sespie 
51*c87b03e5Sespie static const char *main_class_name = NULL;
52*c87b03e5Sespie int lang_specific_extra_outfiles = 0;
53*c87b03e5Sespie 
54*c87b03e5Sespie /* True if we should add -shared-libgcc to the command-line.  */
55*c87b03e5Sespie int shared_libgcc = 1;
56*c87b03e5Sespie 
57*c87b03e5Sespie static const char jvgenmain_spec[] =
58*c87b03e5Sespie   "jvgenmain %{D*} %b %{!pipe:%u.i} |\n\
59*c87b03e5Sespie    cc1 %{!pipe:%U.i} %1 \
60*c87b03e5Sespie 		   %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
61*c87b03e5Sespie 		   %{g*} %{O*} \
62*c87b03e5Sespie 		   %{v:-version} %{pg:-p} %{p}\
63*c87b03e5Sespie 		   %{<fbounds-check} %{<fno-bounds-check}\
64*c87b03e5Sespie 		   %{<fassume-compiled} %{<fno-assume-compiled}\
65*c87b03e5Sespie                    %{<fcompile-resource*} %{<fassert} %{<fno-assert} \
66*c87b03e5Sespie 		   %{<femit-class-file} %{<femit-class-files} %{<fencoding*}\
67*c87b03e5Sespie 		   %{<fuse-boehm-gc} %{<fhash-synchronization} %{<fjni}\
68*c87b03e5Sespie 		   %{<findirect-dispatch} \
69*c87b03e5Sespie 		   %{<fno-store-check} %{<foutput-class-dir}\
70*c87b03e5Sespie 		   %{<fclasspath*} %{<fCLASSPATH*} %{<fbootclasspath*}\
71*c87b03e5Sespie 		   %{<fextdirs*}\
72*c87b03e5Sespie 		   %{<fuse-divide-subroutine} %{<fno-use-divide-subroutine}\
73*c87b03e5Sespie 		   %{<fcheck-references} %{<fno-check-references}\
74*c87b03e5Sespie 		   %{<ffilelist-file}\
75*c87b03e5Sespie 		   %{f*} -fdollars-in-identifiers\
76*c87b03e5Sespie 		   %{aux-info*}\
77*c87b03e5Sespie 		   %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
78*c87b03e5Sespie 		   %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
79*c87b03e5Sespie               %{!S:as %a %Y -o %d%w%u%O %{!pipe:%g.s} %A\n }";
80*c87b03e5Sespie 
81*c87b03e5Sespie /* Return full path name of spec file if it is in DIR, or NULL if
82*c87b03e5Sespie    not.  */
83*c87b03e5Sespie static char *
find_spec_file(dir)84*c87b03e5Sespie find_spec_file (dir)
85*c87b03e5Sespie      const char *dir;
86*c87b03e5Sespie {
87*c87b03e5Sespie   char *spec;
88*c87b03e5Sespie   int x;
89*c87b03e5Sespie   struct stat sb;
90*c87b03e5Sespie 
91*c87b03e5Sespie   spec = xmalloc (strlen (dir) + sizeof (SPEC_FILE)
92*c87b03e5Sespie 		  + sizeof ("-specs=") + 4);
93*c87b03e5Sespie   strcpy (spec, "-specs=");
94*c87b03e5Sespie   x = strlen (spec);
95*c87b03e5Sespie   strcat (spec, dir);
96*c87b03e5Sespie   strcat (spec, "/");
97*c87b03e5Sespie   strcat (spec, SPEC_FILE);
98*c87b03e5Sespie   if (! stat (spec + x, &sb))
99*c87b03e5Sespie     return spec;
100*c87b03e5Sespie   free (spec);
101*c87b03e5Sespie   return NULL;
102*c87b03e5Sespie }
103*c87b03e5Sespie 
104*c87b03e5Sespie /* FIXME: these should come from lex.h.  */
105*c87b03e5Sespie #define JAVA_START_CHAR_P(c) (c < 128 && (ISIDST (c) || c == '$'))
106*c87b03e5Sespie #define JAVA_PART_CHAR_P(c) (c < 128					      \
107*c87b03e5Sespie 			     && (ISIDNUM (c)				      \
108*c87b03e5Sespie 				 || c == '$'				      \
109*c87b03e5Sespie 				 || (c >= 0x00 && c <= 0x08)		      \
110*c87b03e5Sespie 				 || (c >= 0x0e && c <= 0x1b)		      \
111*c87b03e5Sespie 				 || c == 0x7f))
112*c87b03e5Sespie 
113*c87b03e5Sespie /* Verify that NAME is a valid Java class name that might contain
114*c87b03e5Sespie    `main'.  Return 0 on failure.  */
115*c87b03e5Sespie static int
verify_class_name(name)116*c87b03e5Sespie verify_class_name (name)
117*c87b03e5Sespie      const char *name;
118*c87b03e5Sespie {
119*c87b03e5Sespie   /* FIXME: what encoding do we use for command-line arguments?  For
120*c87b03e5Sespie      now we assume plain ASCII, which of course is wrong.  */
121*c87b03e5Sespie   while (*name)
122*c87b03e5Sespie     {
123*c87b03e5Sespie       int ch = *name++;
124*c87b03e5Sespie       if (ch < 0 || ! JAVA_START_CHAR_P (ch))
125*c87b03e5Sespie 	return 0;
126*c87b03e5Sespie       while (*name)
127*c87b03e5Sespie 	{
128*c87b03e5Sespie 	  ch = *name++;
129*c87b03e5Sespie 	  if (ch < 0)
130*c87b03e5Sespie 	    return 0;
131*c87b03e5Sespie 	  /* We found a break between class names.  Next character
132*c87b03e5Sespie 	     must be an identifier start again.  */
133*c87b03e5Sespie 	  if (ch == '.')
134*c87b03e5Sespie 	    break;
135*c87b03e5Sespie 	  if (! JAVA_PART_CHAR_P (ch))
136*c87b03e5Sespie 	    return 0;
137*c87b03e5Sespie 	}
138*c87b03e5Sespie     }
139*c87b03e5Sespie 
140*c87b03e5Sespie   return 1;
141*c87b03e5Sespie }
142*c87b03e5Sespie 
143*c87b03e5Sespie void
lang_specific_driver(in_argc,in_argv,in_added_libraries)144*c87b03e5Sespie lang_specific_driver (in_argc, in_argv, in_added_libraries)
145*c87b03e5Sespie      int *in_argc;
146*c87b03e5Sespie      const char *const **in_argv;
147*c87b03e5Sespie      int *in_added_libraries;
148*c87b03e5Sespie {
149*c87b03e5Sespie   int i, j;
150*c87b03e5Sespie 
151*c87b03e5Sespie   /* If nonzero, the user gave us the `-v' flag.  */
152*c87b03e5Sespie   int saw_verbose_flag = 0;
153*c87b03e5Sespie 
154*c87b03e5Sespie   int saw_save_temps = 0;
155*c87b03e5Sespie 
156*c87b03e5Sespie   /* This will be 0 if we encounter a situation where we should not
157*c87b03e5Sespie      link in libgcj.  */
158*c87b03e5Sespie   int library = 1;
159*c87b03e5Sespie 
160*c87b03e5Sespie   /* This will be 1 if multiple input files (.class and/or .java)
161*c87b03e5Sespie      should be passed to a single jc1 invocation. */
162*c87b03e5Sespie   int combine_inputs = 0;
163*c87b03e5Sespie 
164*c87b03e5Sespie   /* Index of last .java or .class argument. */
165*c87b03e5Sespie   int last_input_index;
166*c87b03e5Sespie 
167*c87b03e5Sespie   /* Number of .java and .class source file arguments seen. */
168*c87b03e5Sespie   int java_files_count = 0;
169*c87b03e5Sespie   int class_files_count = 0;
170*c87b03e5Sespie   /* Number of .zip or .jar file arguments seen. */
171*c87b03e5Sespie   int zip_files_count = 0;
172*c87b03e5Sespie   /* Number of '@FILES' arguments seen. */
173*c87b03e5Sespie   int indirect_files_count = 0;
174*c87b03e5Sespie 
175*c87b03e5Sespie   /* Name of file containing list of files to compile. */
176*c87b03e5Sespie   char *filelist_filename = 0;
177*c87b03e5Sespie 
178*c87b03e5Sespie   FILE *filelist_file = 0;
179*c87b03e5Sespie 
180*c87b03e5Sespie   /* The number of arguments being added to what's in argv, other than
181*c87b03e5Sespie      libraries.  */
182*c87b03e5Sespie   int added = 2;
183*c87b03e5Sespie 
184*c87b03e5Sespie   /* Used to track options that take arguments, so we don't go wrapping
185*c87b03e5Sespie      those with -xc++/-xnone.  */
186*c87b03e5Sespie   const char *quote = NULL;
187*c87b03e5Sespie 
188*c87b03e5Sespie   /* The new argument list will be contained in this.  */
189*c87b03e5Sespie   const char **arglist;
190*c87b03e5Sespie 
191*c87b03e5Sespie   /* Nonzero if we saw a `-xfoo' language specification on the
192*c87b03e5Sespie      command line.  Used to avoid adding our own -xc++ if the user
193*c87b03e5Sespie      already gave a language for the file.  */
194*c87b03e5Sespie   int saw_speclang = 0;
195*c87b03e5Sespie 
196*c87b03e5Sespie #if 0
197*c87b03e5Sespie   /* "-lm" or "-lmath" if it appears on the command line.  */
198*c87b03e5Sespie   const char *saw_math ATTRIBUTE_UNUSED = 0;
199*c87b03e5Sespie 
200*c87b03e5Sespie   /* "-lc" if it appears on the command line.  */
201*c87b03e5Sespie   const char *saw_libc ATTRIBUTE_UNUSED = 0;
202*c87b03e5Sespie 
203*c87b03e5Sespie   /* "-lgcjgc" if it appears on the command line.  */
204*c87b03e5Sespie   const char *saw_gc ATTRIBUTE_UNUSED = 0;
205*c87b03e5Sespie 
206*c87b03e5Sespie   /* Saw `-l' option for the thread library.  */
207*c87b03e5Sespie   const char *saw_threadlib ATTRIBUTE_UNUSED = 0;
208*c87b03e5Sespie 
209*c87b03e5Sespie   /* Saw `-lgcj' on command line.  */
210*c87b03e5Sespie   int saw_libgcj ATTRIBUTE_UNUSED = 0;
211*c87b03e5Sespie #endif
212*c87b03e5Sespie 
213*c87b03e5Sespie   /* Saw --resource, -C or -o options, respectively. */
214*c87b03e5Sespie   int saw_resource = 0;
215*c87b03e5Sespie   int saw_C = 0;
216*c87b03e5Sespie   int saw_o = 0;
217*c87b03e5Sespie 
218*c87b03e5Sespie   /* Saw some -O* or -g* option, respectively. */
219*c87b03e5Sespie   int saw_O = 0;
220*c87b03e5Sespie   int saw_g = 0;
221*c87b03e5Sespie 
222*c87b03e5Sespie   /* Saw a `-D' option.  */
223*c87b03e5Sespie   int saw_D = 0;
224*c87b03e5Sespie 
225*c87b03e5Sespie   /* An array used to flag each argument that needs a bit set for
226*c87b03e5Sespie      LANGSPEC, MATHLIB, WITHLIBC, or GCLIB.  */
227*c87b03e5Sespie   int *args;
228*c87b03e5Sespie 
229*c87b03e5Sespie   /* The total number of arguments with the new stuff.  */
230*c87b03e5Sespie   int argc;
231*c87b03e5Sespie 
232*c87b03e5Sespie   /* The argument list.  */
233*c87b03e5Sespie   const char *const *argv;
234*c87b03e5Sespie 
235*c87b03e5Sespie   /* The number of libraries added in.  */
236*c87b03e5Sespie   int added_libraries;
237*c87b03e5Sespie 
238*c87b03e5Sespie   /* The total number of arguments with the new stuff.  */
239*c87b03e5Sespie   int num_args = 1;
240*c87b03e5Sespie 
241*c87b03e5Sespie   /* Nonzero if linking is supposed to happen.  */
242*c87b03e5Sespie   int will_link = 1;
243*c87b03e5Sespie 
244*c87b03e5Sespie   /* Nonzero if we want to find the spec file.  */
245*c87b03e5Sespie   int want_spec_file = 1;
246*c87b03e5Sespie 
247*c87b03e5Sespie   /* The argument we use to specify the spec file.  */
248*c87b03e5Sespie   char *spec_file = NULL;
249*c87b03e5Sespie 
250*c87b03e5Sespie   argc = *in_argc;
251*c87b03e5Sespie   argv = *in_argv;
252*c87b03e5Sespie   added_libraries = *in_added_libraries;
253*c87b03e5Sespie 
254*c87b03e5Sespie   args = xcalloc (argc, sizeof (int));
255*c87b03e5Sespie 
256*c87b03e5Sespie   for (i = 1; i < argc; i++)
257*c87b03e5Sespie     {
258*c87b03e5Sespie       /* If the previous option took an argument, we swallow it here.  */
259*c87b03e5Sespie       if (quote)
260*c87b03e5Sespie 	{
261*c87b03e5Sespie 	  quote = NULL;
262*c87b03e5Sespie 	  args[i] |= PARAM_ARG;
263*c87b03e5Sespie 	  continue;
264*c87b03e5Sespie 	}
265*c87b03e5Sespie 
266*c87b03e5Sespie       /* We don't do this anymore, since we don't get them with minus
267*c87b03e5Sespie 	 signs on them.  */
268*c87b03e5Sespie       if (argv[i][0] == '\0' || argv[i][1] == '\0')
269*c87b03e5Sespie 	continue;
270*c87b03e5Sespie 
271*c87b03e5Sespie       if (argv[i][0] == '-')
272*c87b03e5Sespie 	{
273*c87b03e5Sespie 	  if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
274*c87b03e5Sespie 			       || strcmp (argv[i], "-nodefaultlibs") == 0))
275*c87b03e5Sespie 	    {
276*c87b03e5Sespie 	      library = 0;
277*c87b03e5Sespie 	    }
278*c87b03e5Sespie 	  else if (strncmp (argv[i], "-fmain=", 7) == 0)
279*c87b03e5Sespie 	    {
280*c87b03e5Sespie 	      main_class_name = argv[i] + 7;
281*c87b03e5Sespie 	      added--;
282*c87b03e5Sespie 	    }
283*c87b03e5Sespie 	  else if (strcmp (argv[i], "-fhelp") == 0)
284*c87b03e5Sespie 	    want_spec_file = 0;
285*c87b03e5Sespie 	  else if (strcmp (argv[i], "-v") == 0)
286*c87b03e5Sespie 	    {
287*c87b03e5Sespie 	      saw_verbose_flag = 1;
288*c87b03e5Sespie 	      if (argc == 2)
289*c87b03e5Sespie 		{
290*c87b03e5Sespie 		  /* If they only gave us `-v', don't try to link
291*c87b03e5Sespie 		     in libgcj.  */
292*c87b03e5Sespie 		  library = 0;
293*c87b03e5Sespie 		}
294*c87b03e5Sespie 	    }
295*c87b03e5Sespie 	  else if (strncmp (argv[i], "-x", 2) == 0)
296*c87b03e5Sespie 	    saw_speclang = 1;
297*c87b03e5Sespie 	  else if (strcmp (argv[i], "-C") == 0)
298*c87b03e5Sespie 	    {
299*c87b03e5Sespie 	      saw_C = 1;
300*c87b03e5Sespie 	      want_spec_file = 0;
301*c87b03e5Sespie 	      if (library != 0)
302*c87b03e5Sespie 		added -= 2;
303*c87b03e5Sespie 	      library = 0;
304*c87b03e5Sespie 	      will_link = 0;
305*c87b03e5Sespie 	    }
306*c87b03e5Sespie 	  else if (strncmp (argv[i], "-fcompile-resource=", 19) == 0)
307*c87b03e5Sespie 	    {
308*c87b03e5Sespie 	      saw_resource = 1;
309*c87b03e5Sespie 	      want_spec_file = 0;
310*c87b03e5Sespie 	      if (library != 0)
311*c87b03e5Sespie 		--added;
312*c87b03e5Sespie 	      library = 0;
313*c87b03e5Sespie 	      will_link = 0;
314*c87b03e5Sespie 	    }
315*c87b03e5Sespie 	  else if (argv[i][1] == 'D')
316*c87b03e5Sespie 	    saw_D = 1;
317*c87b03e5Sespie 	  else if (argv[i][1] == 'g')
318*c87b03e5Sespie 	    saw_g = 1;
319*c87b03e5Sespie 	  else if (argv[i][1] == 'O')
320*c87b03e5Sespie 	    saw_O = 1;
321*c87b03e5Sespie 	  else if ((argv[i][2] == '\0'
322*c87b03e5Sespie 		    && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
323*c87b03e5Sespie 		   || strcmp (argv[i], "-Tdata") == 0
324*c87b03e5Sespie 		   || strcmp (argv[i], "-MT") == 0
325*c87b03e5Sespie 		   || strcmp (argv[i], "-MF") == 0)
326*c87b03e5Sespie 	    {
327*c87b03e5Sespie 	      if (strcmp (argv[i], "-o") == 0)
328*c87b03e5Sespie 		saw_o = 1;
329*c87b03e5Sespie 	      quote = argv[i];
330*c87b03e5Sespie 	    }
331*c87b03e5Sespie 	  else if (strcmp(argv[i], "-classpath") == 0
332*c87b03e5Sespie 		   || strcmp(argv[i], "-bootclasspath") == 0
333*c87b03e5Sespie 		   || strcmp(argv[i], "-CLASSPATH") == 0)
334*c87b03e5Sespie 	    {
335*c87b03e5Sespie 	      quote = argv[i];
336*c87b03e5Sespie 	      added -= 1;
337*c87b03e5Sespie 	    }
338*c87b03e5Sespie 	  else if (library != 0
339*c87b03e5Sespie 		   && ((argv[i][2] == '\0'
340*c87b03e5Sespie 			&& (char *) strchr ("cSEM", argv[i][1]) != NULL)
341*c87b03e5Sespie 		       || strcmp (argv[i], "-MM") == 0))
342*c87b03e5Sespie 	    {
343*c87b03e5Sespie 	      /* Don't specify libraries if we won't link, since that would
344*c87b03e5Sespie 		 cause a warning.  */
345*c87b03e5Sespie 	      library = 0;
346*c87b03e5Sespie 	      added -= 2;
347*c87b03e5Sespie 
348*c87b03e5Sespie 	      /* Remember this so we can confirm -fmain option.  */
349*c87b03e5Sespie 	      will_link = 0;
350*c87b03e5Sespie 	    }
351*c87b03e5Sespie 	  else if (strcmp (argv[i], "-d") == 0)
352*c87b03e5Sespie 	    {
353*c87b03e5Sespie 	      /* `-d' option is for javac compatibility.  */
354*c87b03e5Sespie 	      quote = argv[i];
355*c87b03e5Sespie 	      added -= 1;
356*c87b03e5Sespie 	    }
357*c87b03e5Sespie 	  else if (strcmp (argv[i], "-fsyntax-only") == 0
358*c87b03e5Sespie 		   || strcmp (argv[i], "--syntax-only") == 0)
359*c87b03e5Sespie 	    {
360*c87b03e5Sespie 	      want_spec_file = 0;
361*c87b03e5Sespie 	      library = 0;
362*c87b03e5Sespie 	      will_link = 0;
363*c87b03e5Sespie 	      continue;
364*c87b03e5Sespie 	    }
365*c87b03e5Sespie           else if (strcmp (argv[i], "-save-temps") == 0)
366*c87b03e5Sespie 	    saw_save_temps = 1;
367*c87b03e5Sespie           else if (strcmp (argv[i], "-static-libgcc") == 0
368*c87b03e5Sespie                    || strcmp (argv[i], "-static") == 0)
369*c87b03e5Sespie 	    shared_libgcc = 0;
370*c87b03e5Sespie 	  else
371*c87b03e5Sespie 	    /* Pass other options through.  */
372*c87b03e5Sespie 	    continue;
373*c87b03e5Sespie 	}
374*c87b03e5Sespie       else
375*c87b03e5Sespie 	{
376*c87b03e5Sespie 	  int len;
377*c87b03e5Sespie 
378*c87b03e5Sespie 	  if (saw_speclang)
379*c87b03e5Sespie 	    {
380*c87b03e5Sespie 	      saw_speclang = 0;
381*c87b03e5Sespie 	      continue;
382*c87b03e5Sespie 	    }
383*c87b03e5Sespie 
384*c87b03e5Sespie 	  if (saw_resource)
385*c87b03e5Sespie 	    {
386*c87b03e5Sespie 	      args[i] |= RESOURCE_FILE_ARG;
387*c87b03e5Sespie 	      last_input_index = i;
388*c87b03e5Sespie 	      added += 2;  /* for -xjava and -xnone */
389*c87b03e5Sespie 	    }
390*c87b03e5Sespie 
391*c87b03e5Sespie 	  if (argv[i][0] == '@')
392*c87b03e5Sespie 	    {
393*c87b03e5Sespie 	      args[i] |= INDIRECT_FILE_ARG;
394*c87b03e5Sespie 	      indirect_files_count++;
395*c87b03e5Sespie 	      added += 2;  /* for -xjava and -xnone */
396*c87b03e5Sespie 	    }
397*c87b03e5Sespie 
398*c87b03e5Sespie 	  len = strlen (argv[i]);
399*c87b03e5Sespie 	  if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0)
400*c87b03e5Sespie 	    {
401*c87b03e5Sespie 	      args[i] |= JAVA_FILE_ARG;
402*c87b03e5Sespie 	      java_files_count++;
403*c87b03e5Sespie 	      last_input_index = i;
404*c87b03e5Sespie 	    }
405*c87b03e5Sespie 	  if (len > 6 && strcmp (argv[i] + len - 6, ".class") == 0)
406*c87b03e5Sespie 	    {
407*c87b03e5Sespie 	      args[i] |= CLASS_FILE_ARG;
408*c87b03e5Sespie 	      class_files_count++;
409*c87b03e5Sespie 	      last_input_index = i;
410*c87b03e5Sespie 	    }
411*c87b03e5Sespie 	  if (len > 4
412*c87b03e5Sespie 	      && (strcmp (argv[i] + len - 4, ".zip") == 0
413*c87b03e5Sespie 		  || strcmp (argv[i] + len - 4, ".jar") == 0))
414*c87b03e5Sespie 	    {
415*c87b03e5Sespie 	      args[i] |= ZIP_FILE_ARG;
416*c87b03e5Sespie 	      zip_files_count++;
417*c87b03e5Sespie 	      last_input_index = i;
418*c87b03e5Sespie 	    }
419*c87b03e5Sespie 	}
420*c87b03e5Sespie     }
421*c87b03e5Sespie 
422*c87b03e5Sespie   if (quote)
423*c87b03e5Sespie     fatal ("argument to `%s' missing\n", quote);
424*c87b03e5Sespie 
425*c87b03e5Sespie   if (saw_D && ! main_class_name)
426*c87b03e5Sespie     fatal ("can't specify `-D' without `--main'\n");
427*c87b03e5Sespie 
428*c87b03e5Sespie   if (main_class_name && ! verify_class_name (main_class_name))
429*c87b03e5Sespie     fatal ("`%s' is not a valid class name", main_class_name);
430*c87b03e5Sespie 
431*c87b03e5Sespie   num_args = argc + added;
432*c87b03e5Sespie   if (saw_resource)
433*c87b03e5Sespie     {
434*c87b03e5Sespie       if (! saw_o)
435*c87b03e5Sespie 	fatal ("--resource requires -o");
436*c87b03e5Sespie     }
437*c87b03e5Sespie   if (saw_C)
438*c87b03e5Sespie     {
439*c87b03e5Sespie       num_args += 3;
440*c87b03e5Sespie       if (class_files_count + zip_files_count > 0)
441*c87b03e5Sespie 	{
442*c87b03e5Sespie 	  error ("warning: already-compiled .class files ignored with -C");
443*c87b03e5Sespie 	  num_args -= class_files_count + zip_files_count;
444*c87b03e5Sespie 	  class_files_count = 0;
445*c87b03e5Sespie 	  zip_files_count = 0;
446*c87b03e5Sespie 	}
447*c87b03e5Sespie       num_args += 2;  /* For -o NONE. */
448*c87b03e5Sespie       if (saw_o)
449*c87b03e5Sespie 	fatal ("cannot specify both -C and -o");
450*c87b03e5Sespie     }
451*c87b03e5Sespie   if ((saw_o && java_files_count + class_files_count + zip_files_count > 1)
452*c87b03e5Sespie       || (saw_C && java_files_count > 1)
453*c87b03e5Sespie       || (indirect_files_count > 0
454*c87b03e5Sespie 	  && java_files_count + class_files_count + zip_files_count > 0))
455*c87b03e5Sespie     combine_inputs = 1;
456*c87b03e5Sespie 
457*c87b03e5Sespie   if (combine_inputs)
458*c87b03e5Sespie     {
459*c87b03e5Sespie       filelist_filename = make_temp_file ("jx");
460*c87b03e5Sespie       if (filelist_filename == NULL)
461*c87b03e5Sespie 	fatal ("cannot create temporary file");
462*c87b03e5Sespie       record_temp_file (filelist_filename, ! saw_save_temps, 0);
463*c87b03e5Sespie       filelist_file = fopen (filelist_filename, "w");
464*c87b03e5Sespie       if (filelist_file == NULL)
465*c87b03e5Sespie 	pfatal_with_name (filelist_filename);
466*c87b03e5Sespie       num_args -= java_files_count + class_files_count + zip_files_count;
467*c87b03e5Sespie       num_args += 2;  /* for the combined arg and "-xjava" */
468*c87b03e5Sespie     }
469*c87b03e5Sespie   /* If we know we don't have to do anything, bail now.  */
470*c87b03e5Sespie #if 0
471*c87b03e5Sespie   if (! added && ! library && main_class_name == NULL && ! saw_C)
472*c87b03e5Sespie     {
473*c87b03e5Sespie       free (args);
474*c87b03e5Sespie       return;
475*c87b03e5Sespie     }
476*c87b03e5Sespie #endif
477*c87b03e5Sespie 
478*c87b03e5Sespie   if (main_class_name)
479*c87b03e5Sespie     {
480*c87b03e5Sespie       lang_specific_extra_outfiles++;
481*c87b03e5Sespie     }
482*c87b03e5Sespie   if (saw_g + saw_O == 0)
483*c87b03e5Sespie     num_args++;
484*c87b03e5Sespie   num_args++;
485*c87b03e5Sespie 
486*c87b03e5Sespie   if (combine_inputs || indirect_files_count > 0)
487*c87b03e5Sespie     num_args += 1; /* for "-ffilelist-file" */
488*c87b03e5Sespie   if (combine_inputs && indirect_files_count > 0)
489*c87b03e5Sespie     fatal("using both @FILE with multiple files not implemented");
490*c87b03e5Sespie 
491*c87b03e5Sespie   /* There's no point adding -shared-libgcc if we don't have a shared
492*c87b03e5Sespie      libgcc.  */
493*c87b03e5Sespie #ifndef ENABLE_SHARED_LIBGCC
494*c87b03e5Sespie   shared_libgcc = 0;
495*c87b03e5Sespie #endif
496*c87b03e5Sespie 
497*c87b03e5Sespie   num_args += shared_libgcc;
498*c87b03e5Sespie 
499*c87b03e5Sespie   arglist = xmalloc ((num_args + 1) * sizeof (char *));
500*c87b03e5Sespie   j = 0;
501*c87b03e5Sespie 
502*c87b03e5Sespie   for (i = 0; i < argc; i++, j++)
503*c87b03e5Sespie     {
504*c87b03e5Sespie       arglist[j] = argv[i];
505*c87b03e5Sespie 
506*c87b03e5Sespie       if ((args[i] & PARAM_ARG) || i == 0)
507*c87b03e5Sespie 	continue;
508*c87b03e5Sespie 
509*c87b03e5Sespie       if ((args[i] & RESOURCE_FILE_ARG) != 0)
510*c87b03e5Sespie 	{
511*c87b03e5Sespie 	  arglist[j++] = "-xjava";
512*c87b03e5Sespie 	  arglist[j++] = argv[i];
513*c87b03e5Sespie 	  arglist[j] = "-xnone";
514*c87b03e5Sespie 	}
515*c87b03e5Sespie 
516*c87b03e5Sespie       if (strcmp (argv[i], "-classpath") == 0
517*c87b03e5Sespie 	  || strcmp (argv[i], "-bootclasspath") == 0
518*c87b03e5Sespie 	  || strcmp (argv[i], "-CLASSPATH") == 0)
519*c87b03e5Sespie 	{
520*c87b03e5Sespie 	  arglist[j] = concat ("-f", argv[i]+1, "=", argv[i+1], NULL);
521*c87b03e5Sespie 	  i++;
522*c87b03e5Sespie 	  continue;
523*c87b03e5Sespie 	}
524*c87b03e5Sespie 
525*c87b03e5Sespie       if (strcmp (argv[i], "-d") == 0)
526*c87b03e5Sespie 	{
527*c87b03e5Sespie 	  arglist[j] = concat ("-foutput-class-dir=", argv[i + 1], NULL);
528*c87b03e5Sespie 	  ++i;
529*c87b03e5Sespie 	  continue;
530*c87b03e5Sespie 	}
531*c87b03e5Sespie 
532*c87b03e5Sespie       if (spec_file == NULL && strncmp (argv[i], "-L", 2) == 0)
533*c87b03e5Sespie 	spec_file = find_spec_file (argv[i] + 2);
534*c87b03e5Sespie 
535*c87b03e5Sespie       if (strncmp (argv[i], "-fmain=", 7) == 0)
536*c87b03e5Sespie 	{
537*c87b03e5Sespie 	  if (! will_link)
538*c87b03e5Sespie 	    fatal ("cannot specify `main' class when not linking");
539*c87b03e5Sespie 	  --j;
540*c87b03e5Sespie 	  continue;
541*c87b03e5Sespie 	}
542*c87b03e5Sespie 
543*c87b03e5Sespie       if ((args[i] & INDIRECT_FILE_ARG) != 0)
544*c87b03e5Sespie 	{
545*c87b03e5Sespie 	  arglist[j++] = "-xjava";
546*c87b03e5Sespie 	  arglist[j++] = argv[i]+1;  /* Drop '@'. */
547*c87b03e5Sespie 	  arglist[j] = "-xnone";
548*c87b03e5Sespie 	}
549*c87b03e5Sespie 
550*c87b03e5Sespie       if ((args[i] & (CLASS_FILE_ARG|ZIP_FILE_ARG)) && saw_C)
551*c87b03e5Sespie 	{
552*c87b03e5Sespie 	  --j;
553*c87b03e5Sespie 	  continue;
554*c87b03e5Sespie 	}
555*c87b03e5Sespie 
556*c87b03e5Sespie       if (combine_inputs
557*c87b03e5Sespie 	  && (args[i] & (CLASS_FILE_ARG|JAVA_FILE_ARG|ZIP_FILE_ARG)) != 0)
558*c87b03e5Sespie 	{
559*c87b03e5Sespie 	  fputs (argv[i], filelist_file);
560*c87b03e5Sespie 	  fputc ('\n', filelist_file);
561*c87b03e5Sespie 	  --j;
562*c87b03e5Sespie 	  continue;
563*c87b03e5Sespie 	}
564*c87b03e5Sespie   }
565*c87b03e5Sespie 
566*c87b03e5Sespie   if (combine_inputs || indirect_files_count > 0)
567*c87b03e5Sespie     arglist[j++] = "-ffilelist-file";
568*c87b03e5Sespie 
569*c87b03e5Sespie   if (combine_inputs)
570*c87b03e5Sespie     {
571*c87b03e5Sespie       if (fclose (filelist_file))
572*c87b03e5Sespie 	pfatal_with_name (filelist_filename);
573*c87b03e5Sespie       arglist[j++] = "-xjava";
574*c87b03e5Sespie       arglist[j++] = filelist_filename;
575*c87b03e5Sespie     }
576*c87b03e5Sespie 
577*c87b03e5Sespie   /* If we saw no -O or -g option, default to -g1, for javac compatibility. */
578*c87b03e5Sespie   if (saw_g + saw_O == 0)
579*c87b03e5Sespie     arglist[j++] = "-g1";
580*c87b03e5Sespie 
581*c87b03e5Sespie   /* Read the specs file corresponding to libgcj.
582*c87b03e5Sespie      If we didn't find the spec file on the -L path, then we hope it
583*c87b03e5Sespie      is somewhere in the standard install areas.  */
584*c87b03e5Sespie   if (want_spec_file)
585*c87b03e5Sespie     arglist[j++] = spec_file == NULL ? "-specs=libgcj.spec" : spec_file;
586*c87b03e5Sespie 
587*c87b03e5Sespie   if (saw_C)
588*c87b03e5Sespie     {
589*c87b03e5Sespie       arglist[j++] = "-fsyntax-only";
590*c87b03e5Sespie       arglist[j++] = "-femit-class-files";
591*c87b03e5Sespie       arglist[j++] = "-S";
592*c87b03e5Sespie       arglist[j++] = "-o";
593*c87b03e5Sespie       arglist[j++] = "NONE";
594*c87b03e5Sespie     }
595*c87b03e5Sespie 
596*c87b03e5Sespie   if (shared_libgcc)
597*c87b03e5Sespie     arglist[j++] = "-shared-libgcc";
598*c87b03e5Sespie 
599*c87b03e5Sespie   arglist[j] = NULL;
600*c87b03e5Sespie 
601*c87b03e5Sespie   *in_argc = j;
602*c87b03e5Sespie   *in_argv = arglist;
603*c87b03e5Sespie   *in_added_libraries = added_libraries;
604*c87b03e5Sespie }
605*c87b03e5Sespie 
606*c87b03e5Sespie int
lang_specific_pre_link()607*c87b03e5Sespie lang_specific_pre_link ()
608*c87b03e5Sespie {
609*c87b03e5Sespie   int err;
610*c87b03e5Sespie   if (main_class_name == NULL)
611*c87b03e5Sespie     return 0;
612*c87b03e5Sespie   /* Append `main' to make the filename unique and allow
613*c87b03e5Sespie 
614*c87b03e5Sespie 	gcj --main=hello -save-temps hello.java
615*c87b03e5Sespie 
616*c87b03e5Sespie      to work.  jvgenmain needs to strip this `main' to arrive at the correct
617*c87b03e5Sespie      class name.  Append dummy `.c' that can be stripped by set_input so %b
618*c87b03e5Sespie      is correct.  */
619*c87b03e5Sespie   set_input (concat (main_class_name, "main.c", NULL));
620*c87b03e5Sespie   err = do_spec (jvgenmain_spec);
621*c87b03e5Sespie   if (err == 0)
622*c87b03e5Sespie     {
623*c87b03e5Sespie       /* Shift the outfiles array so the generated main comes first.
624*c87b03e5Sespie 	 This is important when linking against (non-shared) libraries,
625*c87b03e5Sespie 	 since otherwise we risk (a) nothing getting linked or
626*c87b03e5Sespie 	 (b) 'main' getting picked up from a library. */
627*c87b03e5Sespie       int i = n_infiles;
628*c87b03e5Sespie       const char *generated = outfiles[i];
629*c87b03e5Sespie       while (--i >= 0)
630*c87b03e5Sespie 	outfiles[i + 1] = outfiles[i];
631*c87b03e5Sespie       outfiles[0] = generated;
632*c87b03e5Sespie     }
633*c87b03e5Sespie   return err;
634*c87b03e5Sespie }
635*c87b03e5Sespie 
636*c87b03e5Sespie /* Table of language-specific spec functions.  */
637*c87b03e5Sespie const struct spec_function lang_specific_spec_functions[] =
638*c87b03e5Sespie {
639*c87b03e5Sespie   { 0, 0 }
640*c87b03e5Sespie };
641