1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 This paragraph is here to try to keep Sun CC from dying.
21 The number of chars here seems crucial!!!! */
23 /* This program is the user interface to the C compiler and possibly to
24 other compilers. It is used because compilation is a complicated procedure
25 which involves running several programs and passing temporary files between
26 them, forwarding the users switches to those programs selectively,
27 and deleting the temporary files at the end.
29 CC recognizes how to compile each input file by suffixes in the file names.
30 Once it knows which kind of compilation to perform, the procedure for
31 compilation is specified by a string called a "spec". */
33 #include <sys/types.h>
37 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
50 /* Define a generic NULL if one hasn't already been defined. */
57 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
58 #define GENERIC_PTR void *
60 #define GENERIC_PTR char *
65 #define NULL_PTR ((GENERIC_PTR)0)
72 /* On MSDOS, write temp files in current dir
73 because there's no place else we can expect to use. */
80 /* Test if something is a normal file. */
82 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
85 /* Test if something is a directory. */
87 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
90 /* By default there is no special suffix for executables. */
91 #ifndef EXECUTABLE_SUFFIX
92 #define EXECUTABLE_SUFFIX ""
95 /* By default, colon separates directories in a path. */
96 #ifndef PATH_SEPARATOR
97 #define PATH_SEPARATOR ':'
100 #define obstack_chunk_alloc xmalloc
101 #define obstack_chunk_free free
104 extern char *getenv ();
106 extern int errno, sys_nerr;
107 extern char *sys_errlist[];
109 extern int execv (), execvp ();
111 /* If a stage of compilation returns an exit status >= 1,
112 compilation of that file ceases. */
114 #define MIN_FATAL_STATUS 1
116 /* Flag saying to print the full filename of libgcc.a
117 as found through our usual search mechanism. */
119 static int print_libgcc_file_name;
121 /* Flag indicating whether we should print the command and arguments */
123 static int verbose_flag;
125 /* Nonzero means write "temp" files in source directory
126 and use the source file's name in them, and don't delete them. */
128 static int save_temps_flag;
130 /* The compiler version specified with -V */
132 static char *spec_version;
134 /* The target machine specified with -b. */
136 static char *spec_machine = DEFAULT_TARGET_MACHINE;
138 /* Nonzero if cross-compiling.
139 When -b is used, the value comes from the `specs' file. */
142 static int cross_compile = 1;
144 static int cross_compile = 0;
147 /* This is the obstack which we use to allocate many strings. */
149 static struct obstack obstack;
151 /* This is the obstack to build an environment variable to pass to
152 collect2 that describes all of the relevant switches of what to
153 pass the compiler in building the list of pointers to constructors
156 static struct obstack collect_obstack;
158 extern char *version_string;
160 static void set_spec ();
161 static struct compiler *lookup_compiler ();
162 static char *find_a_file ();
163 static void add_prefix ();
164 static char *skip_whitespace ();
165 static void record_temp_file ();
166 static char *handle_braces ();
167 static char *save_string ();
168 static char *concat ();
169 static int do_spec ();
170 static int do_spec_1 ();
171 static char *find_file ();
172 static int is_linker_dir ();
173 static void validate_switches ();
174 static void validate_all_switches ();
175 static void give_switch ();
176 static void pfatal_with_name ();
177 static void perror_with_name ();
178 static void perror_exec ();
179 static void fatal ();
180 static void error ();
185 /* Specs are strings containing lines, each of which (if not blank)
186 is made up of a program name, and arguments separated by spaces.
187 The program name must be exact and start from root, since no path
188 is searched and it is unreliable to depend on the current working directory.
189 Redirection of input or output is not supported; the subprograms must
190 accept filenames saying what files to read and write.
192 In addition, the specs can contain %-sequences to substitute variable text
193 or for conditional text. Here is a table of all defined %-sequences.
194 Note that spaces are not generated automatically around the results of
195 expanding these sequences; therefore, you can concatenate them together
196 or with constant text in a single argument.
198 %% substitute one % into the program name or argument.
199 %i substitute the name of the input file being processed.
200 %b substitute the basename of the input file being processed.
201 This is the substring up to (and not including) the last period
202 and not including the directory.
203 %g substitute the temporary-file-name-base. This is a string chosen
204 once per compilation. Different temporary file names are made by
205 concatenation of constant strings on the end, as in `%g.s'.
206 %g also has the same effect of %d.
207 %u like %g, but make the temporary file name unique.
208 %U returns the last file name generated with %u.
209 %d marks the argument containing or following the %d as a
210 temporary file name, so that that file will be deleted if CC exits
211 successfully. Unlike %g, this contributes no text to the argument.
212 %w marks the argument containing or following the %w as the
213 "output file" of this compilation. This puts the argument
214 into the sequence of arguments that %o will substitute later.
216 like %{...} but mark last argument supplied within
217 as a file to be deleted on failure.
218 %o substitutes the names of all the output files, with spaces
219 automatically placed around them. You should write spaces
220 around the %o as well or the results are undefined.
221 %o is for use in the specs for running the linker.
222 Input files whose names have no recognized suffix are not compiled
223 at all, but they are included among the output files, so they will
225 %p substitutes the standard macro predefinitions for the
226 current target machine. Use this when running cpp.
227 %P like %p, but puts `__' before and after the name of each macro.
228 (Except macros that already have __.)
230 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
231 %s current argument is the name of a library or startup file of some sort.
232 Search for that file in a standard list of directories
233 and substitute the full name found.
234 %eSTR Print STR as an error message. STR is terminated by a newline.
235 Use this when inconsistent options are detected.
236 %x{OPTION} Accumulate an option for %X.
237 %X Output the accumulated linker options specified by compilations.
238 %Y Output the accumulated assembler options specified by compilations.
239 %a process ASM_SPEC as a spec.
240 This allows config.h to specify part of the spec for running as.
241 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
242 used here. This can be used to run a post-processor after the
243 assembler has done it's job.
244 %D Dump out a -L option for each directory in library_prefix,
245 followed by a -L option for each directory in startfile_prefix.
246 %l process LINK_SPEC as a spec.
247 %L process LIB_SPEC as a spec.
248 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
249 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
250 %c process SIGNED_CHAR_SPEC as a spec.
251 %C process CPP_SPEC as a spec. A capital C is actually used here.
252 %1 process CC1_SPEC as a spec.
253 %2 process CC1PLUS_SPEC as a spec.
254 %* substitute the variable part of a matched option. (See below.)
255 Note that each comma in the substituted string is replaced by
257 %{S} substitutes the -S switch, if that switch was given to CC.
258 If that switch was not specified, this substitutes nothing.
259 Here S is a metasyntactic variable.
260 %{S*} substitutes all the switches specified to CC whose names start
261 with -S. This is used for -o, -D, -I, etc; switches that take
262 arguments. CC considers `-o foo' as being one switch whose
263 name starts with `o'. %{o*} would substitute this text,
264 including the space; thus, two arguments would be generated.
265 %{S*:X} substitutes X if one or more switches whose names with -S are
266 specified to CC. Note that the tail part of the -S option
267 (i.e. the part matched by the `*') will be substituted for each
268 occurrence of %* within X.
269 %{S:X} substitutes X, but only if the -S switch was given to CC.
270 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
271 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
272 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
273 %{.S:X} substitutes X, but only if processing a file with suffix S.
274 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
275 %(Spec) processes a specification defined in a specs file as *Spec:
276 %[Spec] as above, but put __ around -D arguments
278 The conditional text X in a %{S:X} or %{!S:X} construct may contain
279 other nested % constructs or spaces, or even newlines. They are
280 processed as usual, as described above.
282 The character | is used to indicate that a command should be piped to
283 the following command, but only if -pipe is specified.
285 Note that it is built into CC which switches take arguments and which
286 do not. You might think it would be useful to generalize this to
287 allow each compiler's spec to say which switches take arguments. But
288 this cannot be done in a consistent fashion. CC cannot even decide
289 which input files have been specified without knowing which switches
290 take arguments, and it must know which input files to compile in order
291 to tell which compilers to run.
293 CC also knows implicitly that arguments starting in `-l' are to be
294 treated as compiler output files, and passed to the linker in their
295 proper position among the other output files. */
297 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
299 /* config.h can define ASM_SPEC to provide extra args to the assembler
300 or extra switch-translations. */
305 /* config.h can define ASM_FINAL_SPEC to run a post processor after
306 the assembler has run. */
307 #ifndef ASM_FINAL_SPEC
308 #define ASM_FINAL_SPEC ""
311 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
312 or extra switch-translations. */
317 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
318 or extra switch-translations. */
323 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
324 or extra switch-translations. */
326 #define CC1PLUS_SPEC ""
329 /* config.h can define LINK_SPEC to provide extra args to the linker
330 or extra switch-translations. */
335 /* config.h can define LIB_SPEC to override the default libraries. */
337 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
340 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
341 #ifndef STARTFILE_SPEC
342 #define STARTFILE_SPEC \
343 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
346 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
347 Make the string nonempty to require spaces there. */
348 #ifndef SWITCHES_NEED_SPACES
349 #define SWITCHES_NEED_SPACES ""
352 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
354 #define ENDFILE_SPEC ""
357 /* This spec is used for telling cpp whether char is signed or not. */
358 #ifndef SIGNED_CHAR_SPEC
359 #define SIGNED_CHAR_SPEC \
360 (DEFAULT_SIGNED_CHAR ? "%{funsigned-char:-D__CHAR_UNSIGNED__}" \
361 : "%{!fsigned-char:-D__CHAR_UNSIGNED__}")
364 static char *cpp_spec = CPP_SPEC;
365 static char *cpp_predefines = CPP_PREDEFINES;
366 static char *cc1_spec = CC1_SPEC;
367 static char *cc1plus_spec = CC1PLUS_SPEC;
368 static char *signed_char_spec = SIGNED_CHAR_SPEC;
369 static char *asm_spec = ASM_SPEC;
370 static char *asm_final_spec = ASM_FINAL_SPEC;
371 static char *link_spec = LINK_SPEC;
372 static char *lib_spec = LIB_SPEC;
373 static char *endfile_spec = ENDFILE_SPEC;
374 static char *startfile_spec = STARTFILE_SPEC;
375 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
377 /* This defines which switch letters take arguments. */
379 #ifndef SWITCH_TAKES_ARG
380 #define SWITCH_TAKES_ARG(CHAR) \
381 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
382 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
383 || (CHAR) == 'I' || (CHAR) == 'm' \
384 || (CHAR) == 'L' || (CHAR) == 'A')
387 /* This defines which multi-letter switches take arguments. */
389 #ifndef WORD_SWITCH_TAKES_ARG
390 #define WORD_SWITCH_TAKES_ARG(STR) \
391 (!strcmp (STR, "Tdata") || !strcmp (STR, "include") \
392 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info"))
395 /* Record the mapping from file suffixes for compilation specs. */
399 char *suffix; /* Use this compiler for input files
400 whose names end in this suffix. */
402 char *spec[4]; /* To use this compiler, concatenate these
403 specs and pass to do_spec. */
406 /* Pointer to a vector of `struct compiler' that gives the spec for
407 compiling a file, based on its suffix.
408 A file that does not end in any of these suffixes will be passed
409 unchanged to the loader and nothing else will be done to it.
411 An entry containing two 0s is used to terminate the vector.
413 If multiple entries match a file, the last matching one is used. */
415 static struct compiler *compilers;
417 /* Number of entries in `compilers', not counting the null terminator. */
419 static int n_compilers;
421 /* The default list of file name suffixes and their compilation specs. */
423 static struct compiler default_compilers[] =
427 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
428 %{C:%{!E:%eGNU C does not support -C without using -E}}\
429 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
430 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
431 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
432 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
433 %{traditional-cpp:-traditional}\
434 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
435 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
436 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
437 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
438 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
439 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
441 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
442 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
443 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
444 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
445 %{!pipe:%g.s} %A\n }}}}"},
447 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
448 %{C:%{!E:%eGNU C does not support -C without using -E}}\
449 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
450 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
451 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
452 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
453 %{traditional-cpp:-traditional}\
454 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
456 %{!E:%e-E required when input is from standard input}"},
457 {".m", "@objective-c"},
459 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
460 %{C:%{!E:%eGNU C does not support -C without using -E}}\
461 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
462 -undef -D__OBJC__ -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
463 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
464 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
465 %{traditional-cpp:-traditional}\
466 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
467 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
468 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
469 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
470 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
471 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
472 -lang-objc %{gen-decls} \
474 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
475 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
476 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
477 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
478 %{!pipe:%g.s} %A\n }}}}"},
481 "%{!E:%eCompilation of header file requested} \
482 cpp %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
483 %{C:%{!E:%eGNU C does not support -C without using -E}}\
484 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
485 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
486 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
487 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
488 %{traditional-cpp:-traditional}\
489 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
495 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
496 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
497 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
498 -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus \
499 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
500 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
501 %{traditional-cpp:-traditional} %{trigraphs}\
502 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
503 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
504 "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.i} %1 %2\
505 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
506 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
507 %{v:-version} %{pg:-p} %{p} %{f*} %{+e*}\
509 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
510 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
511 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
512 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
513 %{!pipe:%g.s} %A\n }}}}"},
514 {".i", "@cpp-output"},
516 "cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
517 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
518 %{v:-version} %{pg:-p} %{p} %{f*}\
520 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
521 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
522 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
523 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n }"},
524 {".ii", "@c++-cpp-output"},
526 "cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
527 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
528 %{v:-version} %{pg:-p} %{p} %{f*} %{+e*}\
530 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
531 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
532 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
533 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
534 %{!pipe:%g.s} %A\n }"},
535 {".s", "@assembler"},
537 "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
538 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o} %i %A\n }"},
539 {".S", "@assembler-with-cpp"},
540 {"@assembler-with-cpp",
541 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
542 %{C:%{!E:%eGNU C does not support -C without using -E}}\
543 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \
544 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
545 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
546 %{traditional-cpp:-traditional}\
547 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
548 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
549 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
550 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
551 %{!pipe:%g.s} %A\n }}}}"},
552 /* Mark end of table */
556 /* Number of elements in default_compilers, not counting the terminator. */
558 static int n_default_compilers
559 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
561 /* Here is the spec for running the linker, after compiling all files. */
563 #ifdef LINK_LIBGCC_SPECIAL
564 /* Have gcc do the search for libgcc.a. */
565 /* -u* was put back because both BSD and SysV seem to support it. */
566 /* %{static:} simply prevents an error message if the target machine
567 doesn't handle -static. */
568 static char *link_command_spec = "\
569 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
570 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
571 %{!A:%{!nostdlib:%S}} %{static:}\
572 %{L*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}";
574 /* Use -L and have the linker do the search for -lgcc. */
575 static char *link_command_spec = "\
576 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
577 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
578 %{!A:%{!nostdlib:%S}} %{static:}\
579 %{L*} %D %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}";
582 /* A vector of options to give to the linker.
583 These options are accumulated by -Xlinker and -Wl,
584 and substituted into the linker command with %X. */
585 static int n_linker_options;
586 static char **linker_options;
588 /* A vector of options to give to the assembler.
589 These options are accumulated by -Wa,
590 and substituted into the assembler command with %X. */
591 static int n_assembler_options;
592 static char **assembler_options;
594 /* Read compilation specs from a file named FILENAME,
595 replacing the default ones.
597 A suffix which starts with `*' is a definition for
598 one of the machine-specific sub-specs. The "suffix" should be
599 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
600 The corresponding spec is stored in asm_spec, etc.,
601 rather than in the `compilers' vector.
603 Anything invalid in the file is a fatal error. */
606 read_specs (filename)
615 fprintf (stderr, "Reading specs from %s\n", filename);
617 /* Open and stat the file. */
618 desc = open (filename, 0, 0);
620 pfatal_with_name (filename);
621 if (stat (filename, &statbuf) < 0)
622 pfatal_with_name (filename);
624 /* Read contents of file into BUFFER. */
625 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
626 read (desc, buffer, (unsigned) statbuf.st_size);
627 buffer[statbuf.st_size] = 0;
630 /* Scan BUFFER for specs, putting them in the vector. */
636 char *in, *out, *p1, *p2;
638 /* Advance P in BUFFER to the next nonblank nocomment line. */
639 p = skip_whitespace (p);
643 /* Find the colon that should end the suffix. */
645 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
646 /* The colon shouldn't be missing. */
648 fatal ("specs file malformed after %d characters", p1 - buffer);
649 /* Skip back over trailing whitespace. */
651 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
652 /* Copy the suffix to a string. */
653 suffix = save_string (p, p2 - p);
654 /* Find the next line. */
655 p = skip_whitespace (p1 + 1);
657 fatal ("specs file malformed after %d characters", p - buffer);
659 /* Find next blank line. */
660 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
661 /* Specs end at the blank line and do not include the newline. */
662 spec = save_string (p, p1 - p);
665 /* Delete backslash-newline sequences from the spec. */
670 if (in[0] == '\\' && in[1] == '\n')
672 else if (in[0] == '#')
674 while (*in && *in != '\n') in++;
681 if (suffix[0] == '*')
683 if (! strcmp (suffix, "*link_command"))
684 link_command_spec = spec;
686 set_spec (suffix + 1, spec);
690 /* Add this pair to the vector. */
692 = ((struct compiler *)
693 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
694 compilers[n_compilers].suffix = suffix;
695 bzero (compilers[n_compilers].spec,
696 sizeof compilers[n_compilers].spec);
697 compilers[n_compilers].spec[0] = spec;
702 link_command_spec = spec;
705 if (link_command_spec == 0)
706 fatal ("spec file has no spec for linking");
715 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
716 be considered whitespace. */
717 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
719 else if (*p == '\n' || *p == ' ' || *p == '\t')
723 while (*p != '\n') p++;
733 /* Structure to keep track of the specs that have been defined so far. These
734 are accessed using %(specname) or %[specname] in a compiler or link spec. */
738 char *name; /* Name of the spec. */
739 char *spec; /* The spec itself. */
740 struct spec_list *next; /* Next spec in linked list. */
743 /* List of specs that have been defined so far. */
745 static struct spec_list *specs = (struct spec_list *) 0;
747 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
748 removed; If the spec starts with a + then SPEC is added to the end of the
752 set_spec (name, spec)
756 struct spec_list *sl;
759 /* See if the spec already exists */
760 for (sl = specs; sl; sl = sl->next)
761 if (strcmp (sl->name, name) == 0)
766 /* Not found - make it */
767 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
768 sl->name = save_string (name, strlen (name));
769 sl->spec = save_string ("", 0);
775 if (name && spec[0] == '+' && isspace (spec[1]))
776 sl->spec = concat (old_spec, spec + 1, "");
778 sl->spec = save_string (spec, strlen (spec));
780 if (! strcmp (name, "asm"))
782 else if (! strcmp (name, "asm_final"))
783 asm_final_spec = sl->spec;
784 else if (! strcmp (name, "cc1"))
786 else if (! strcmp (name, "cc1plus"))
787 cc1plus_spec = sl->spec;
788 else if (! strcmp (name, "cpp"))
790 else if (! strcmp (name, "endfile"))
791 endfile_spec = sl->spec;
792 else if (! strcmp (name, "lib"))
794 else if (! strcmp (name, "link"))
795 link_spec = sl->spec;
796 else if (! strcmp (name, "predefines"))
797 cpp_predefines = sl->spec;
798 else if (! strcmp (name, "signed_char"))
799 signed_char_spec = sl->spec;
800 else if (! strcmp (name, "startfile"))
801 startfile_spec = sl->spec;
802 else if (! strcmp (name, "switches_need_spaces"))
803 switches_need_spaces = sl->spec;
804 else if (! strcmp (name, "cross_compile"))
805 cross_compile = atoi (sl->spec);
806 /* Free the old spec */
811 /* Accumulate a command (program name and args), and run it. */
813 /* Vector of pointers to arguments in the current line of specifications. */
815 static char **argbuf;
817 /* Number of elements allocated in argbuf. */
819 static int argbuf_length;
821 /* Number of elements in argbuf currently in use (containing args). */
823 static int argbuf_index;
825 /* Number of commands executed so far. */
827 static int execution_count;
829 /* Name with which this program was invoked. */
831 static char *programname;
833 /* Structures to keep track of prefixes to try when looking for files. */
837 char *prefix; /* String to prepend to the path. */
838 struct prefix_list *next; /* Next in linked list. */
839 int require_machine_suffix; /* Don't use without machine_suffix. */
840 /* 2 means try both machine_suffix and just_machine_suffix. */
841 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
846 struct prefix_list *plist; /* List of prefixes to try */
847 int max_len; /* Max length of a prefix in PLIST */
848 char *name; /* Name of this list (used in config stuff) */
851 /* List of prefixes to try when looking for executables. */
853 static struct path_prefix exec_prefix = { 0, 0, "exec" };
855 /* List of prefixes to try when looking for startup (crt0) files. */
857 static struct path_prefix startfile_prefix = { 0, 0, "startfile" };
859 /* List of prefixes to try when looking for libraries. */
861 static struct path_prefix library_prefix = { 0, 0, "libraryfile" };
863 /* Suffix to attach to directories searched for commands.
864 This looks like `MACHINE/VERSION/'. */
866 static char *machine_suffix = 0;
868 /* Suffix to attach to directories searched for commands.
869 This is just `MACHINE/'. */
871 static char *just_machine_suffix = 0;
873 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
875 static char *gcc_exec_prefix;
877 /* Default prefixes to attach to command names. */
879 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
880 #undef MD_EXEC_PREFIX
881 #undef MD_STARTFILE_PREFIX
882 #undef MD_STARTFILE_PREFIX_1
885 #ifndef STANDARD_EXEC_PREFIX
886 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
887 #endif /* !defined STANDARD_EXEC_PREFIX */
889 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
890 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
891 #ifdef MD_EXEC_PREFIX
892 static char *md_exec_prefix = MD_EXEC_PREFIX;
895 #ifndef STANDARD_STARTFILE_PREFIX
896 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
897 #endif /* !defined STANDARD_STARTFILE_PREFIX */
899 #ifdef MD_STARTFILE_PREFIX
900 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
902 #ifdef MD_STARTFILE_PREFIX_1
903 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
905 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
906 static char *standard_startfile_prefix_1 = "/lib/";
907 static char *standard_startfile_prefix_2 = "/usr/lib/";
909 /* Clear out the vector of arguments (after a command is executed). */
917 /* Add one argument to the vector at the end.
918 This is done when a space is seen or at the end of the line.
919 If DELETE_ALWAYS is nonzero, the arg is a filename
920 and the file should be deleted eventually.
921 If DELETE_FAILURE is nonzero, the arg is a filename
922 and the file should be deleted if this compilation fails. */
925 store_arg (arg, delete_always, delete_failure)
927 int delete_always, delete_failure;
929 if (argbuf_index + 1 == argbuf_length)
931 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
934 argbuf[argbuf_index++] = arg;
935 argbuf[argbuf_index] = 0;
937 if (delete_always || delete_failure)
938 record_temp_file (arg, delete_always, delete_failure);
941 /* Record the names of temporary files we tell compilers to write,
942 and delete them at the end of the run. */
944 /* This is the common prefix we use to make temp file names.
945 It is chosen once for each run of this program.
946 It is substituted into a spec by %g.
947 Thus, all temp file names contain this prefix.
948 In practice, all temp file names start with this prefix.
950 This prefix comes from the envvar TMPDIR if it is defined;
951 otherwise, from the P_tmpdir macro if that is defined;
952 otherwise, in /usr/tmp or /tmp. */
954 static char *temp_filename;
956 /* Length of the prefix. */
958 static int temp_filename_length;
960 /* Define the list of temporary files to delete. */
965 struct temp_file *next;
968 /* Queue of files to delete on success or failure of compilation. */
969 static struct temp_file *always_delete_queue;
970 /* Queue of files to delete on failure of compilation. */
971 static struct temp_file *failure_delete_queue;
973 /* Record FILENAME as a file to be deleted automatically.
974 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
975 otherwise delete it in any case.
976 FAIL_DELETE nonzero means delete it if a compilation step fails;
977 otherwise delete it in any case. */
980 record_temp_file (filename, always_delete, fail_delete)
986 name = xmalloc (strlen (filename) + 1);
987 strcpy (name, filename);
991 register struct temp_file *temp;
992 for (temp = always_delete_queue; temp; temp = temp->next)
993 if (! strcmp (name, temp->name))
995 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
996 temp->next = always_delete_queue;
998 always_delete_queue = temp;
1004 register struct temp_file *temp;
1005 for (temp = failure_delete_queue; temp; temp = temp->next)
1006 if (! strcmp (name, temp->name))
1008 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1009 temp->next = failure_delete_queue;
1011 failure_delete_queue = temp;
1016 /* Delete all the temporary files whose names we previously recorded. */
1019 delete_temp_files ()
1021 register struct temp_file *temp;
1023 for (temp = always_delete_queue; temp; temp = temp->next)
1027 printf ("Delete %s? (y or n) ", temp->name);
1031 while (getchar () != '\n') ;
1032 if (i == 'y' || i == 'Y')
1036 if (stat (temp->name, &st) >= 0)
1038 /* Delete only ordinary files. */
1039 if (S_ISREG (st.st_mode))
1040 if (unlink (temp->name) < 0)
1042 perror_with_name (temp->name);
1047 always_delete_queue = 0;
1050 /* Delete all the files to be deleted on error. */
1053 delete_failure_queue ()
1055 register struct temp_file *temp;
1057 for (temp = failure_delete_queue; temp; temp = temp->next)
1061 printf ("Delete %s? (y or n) ", temp->name);
1065 while (getchar () != '\n') ;
1066 if (i == 'y' || i == 'Y')
1069 if (unlink (temp->name) < 0)
1071 perror_with_name (temp->name);
1077 clear_failure_queue ()
1079 failure_delete_queue = 0;
1082 /* Compute a string to use as the base of all temporary file names.
1083 It is substituted for %g. */
1088 char *base = getenv ("TMPDIR");
1091 if (base == (char *)0)
1094 if (access (P_tmpdir, R_OK | W_OK) == 0)
1097 if (base == (char *)0)
1099 if (access ("/usr/tmp", R_OK | W_OK) == 0)
1106 len = strlen (base);
1107 temp_filename = xmalloc (len + sizeof("/ccXXXXXX"));
1108 strcpy (temp_filename, base);
1109 if (len > 0 && temp_filename[len-1] != '/')
1110 temp_filename[len++] = '/';
1111 strcpy (temp_filename + len, "ccXXXXXX");
1113 mktemp (temp_filename);
1114 temp_filename_length = strlen (temp_filename);
1118 /* Routine to add variables to the environment. We do this to pass
1119 the pathname of the gcc driver, and the directories search to the
1120 collect2 program, which is being run as ld. This way, we can be
1121 sure of executing the right compiler when collect2 wants to build
1122 constructors and destructors. Since the environment variables we
1123 use come from an obstack, we don't have to worry about allocating
1131 #ifndef VMS /* nor about VMS */
1133 extern char **environ;
1134 char **old_environ = environ;
1138 int str_len = strlen (str);
1142 while ((ch = *p++) != '\0' && ch != '=')
1148 /* Search for replacing an existing environment variable, and
1149 count the number of total environment variables. */
1150 for (envp = old_environ; *envp; envp++)
1153 if (!strncmp (str, *envp, name_len))
1160 /* Add a new environment variable */
1161 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1163 bcopy (old_environ, environ+1, sizeof (char *) * (num_envs+1));
1168 #endif /* HAVE_PUTENV */
1171 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1174 putenv_from_prefixes (paths, env_var)
1175 struct path_prefix *paths;
1178 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1179 int first_time = TRUE;
1180 struct prefix_list *pprefix;
1182 obstack_grow (&collect_obstack, env_var, strlen (env_var));
1184 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1186 int len = strlen (pprefix->prefix);
1191 obstack_grow (&collect_obstack, ":", 1);
1194 obstack_grow (&collect_obstack, pprefix->prefix, len);
1195 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1198 if (just_machine_suffix && pprefix->require_machine_suffix == 2)
1201 obstack_grow (&collect_obstack, ":", 1);
1204 obstack_grow (&collect_obstack, pprefix->prefix, len);
1205 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1208 if (!pprefix->require_machine_suffix)
1211 obstack_grow (&collect_obstack, ":", 1);
1214 obstack_grow (&collect_obstack, pprefix->prefix, len);
1217 obstack_grow (&collect_obstack, "\0", 1);
1218 putenv (obstack_finish (&collect_obstack));
1222 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1223 access to check permissions.
1224 Return 0 if not found, otherwise return its name, allocated with malloc. */
1227 find_a_file (pprefix, name, mode)
1228 struct path_prefix *pprefix;
1233 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1234 struct prefix_list *pl;
1235 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1238 len += strlen (machine_suffix);
1240 temp = xmalloc (len);
1242 /* Determine the filename to execute (special case for absolute paths). */
1246 if (access (name, mode))
1248 strcpy (temp, name);
1253 for (pl = pprefix->plist; pl; pl = pl->next)
1257 strcpy (temp, pl->prefix);
1258 strcat (temp, machine_suffix);
1259 strcat (temp, name);
1260 if (access (temp, mode) == 0)
1262 if (pl->used_flag_ptr != 0)
1263 *pl->used_flag_ptr = 1;
1266 /* Some systems have a suffix for executable files.
1267 So try appending that. */
1268 if (file_suffix[0] != 0)
1270 strcat (temp, file_suffix);
1271 if (access (temp, mode) == 0)
1273 if (pl->used_flag_ptr != 0)
1274 *pl->used_flag_ptr = 1;
1279 /* Certain prefixes are tried with just the machine type,
1280 not the version. This is used for finding as, ld, etc. */
1281 if (just_machine_suffix && pl->require_machine_suffix == 2)
1283 strcpy (temp, pl->prefix);
1284 strcat (temp, just_machine_suffix);
1285 strcat (temp, name);
1286 if (access (temp, mode) == 0)
1288 if (pl->used_flag_ptr != 0)
1289 *pl->used_flag_ptr = 1;
1292 /* Some systems have a suffix for executable files.
1293 So try appending that. */
1294 if (file_suffix[0] != 0)
1296 strcat (temp, file_suffix);
1297 if (access (temp, mode) == 0)
1299 if (pl->used_flag_ptr != 0)
1300 *pl->used_flag_ptr = 1;
1305 /* Certain prefixes can't be used without the machine suffix
1306 when the machine or version is explicitly specified. */
1307 if (!pl->require_machine_suffix)
1309 strcpy (temp, pl->prefix);
1310 strcat (temp, name);
1311 if (access (temp, mode) == 0)
1313 if (pl->used_flag_ptr != 0)
1314 *pl->used_flag_ptr = 1;
1317 /* Some systems have a suffix for executable files.
1318 So try appending that. */
1319 if (file_suffix[0] != 0)
1321 strcat (temp, file_suffix);
1322 if (access (temp, mode) == 0)
1324 if (pl->used_flag_ptr != 0)
1325 *pl->used_flag_ptr = 1;
1336 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1337 at the start of the list, otherwise it goes at the end.
1339 If WARN is nonzero, we will warn if no file is found
1340 through this prefix. WARN should point to an int
1341 which will be set to 1 if this entry is used.
1343 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1344 the complete value of machine_suffix.
1345 2 means try both machine_suffix and just_machine_suffix. */
1348 add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1349 struct path_prefix *pprefix;
1352 int require_machine_suffix;
1355 struct prefix_list *pl, **prev;
1358 if (!first && pprefix->plist)
1360 for (pl = pprefix->plist; pl->next; pl = pl->next)
1365 prev = &pprefix->plist;
1367 /* Keep track of the longest prefix */
1369 len = strlen (prefix);
1370 if (len > pprefix->max_len)
1371 pprefix->max_len = len;
1373 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1374 pl->prefix = save_string (prefix, len);
1375 pl->require_machine_suffix = require_machine_suffix;
1376 pl->used_flag_ptr = warn;
1383 pl->next = (struct prefix_list *) 0;
1387 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1390 unused_prefix_warnings (pprefix)
1391 struct path_prefix *pprefix;
1393 struct prefix_list *pl = pprefix->plist;
1397 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1399 error ("file path prefix `%s' never used",
1401 /* Prevent duplicate warnings. */
1402 *pl->used_flag_ptr = 1;
1408 /* Get rid of all prefixes built up so far in *PLISTP. */
1411 free_path_prefix (pprefix)
1412 struct path_prefix *pprefix;
1414 struct prefix_list *pl = pprefix->plist;
1415 struct prefix_list *temp;
1421 free (temp->prefix);
1422 free ((char *) temp);
1424 pprefix->plist = (struct prefix_list *) 0;
1427 /* stdin file number. */
1428 #define STDIN_FILE_NO 0
1430 /* stdout file number. */
1431 #define STDOUT_FILE_NO 1
1433 /* value of `pipe': port index for reading. */
1436 /* value of `pipe': port index for writing. */
1437 #define WRITE_PORT 1
1439 /* Pipe waiting from last process, to be used as input for the next one.
1440 Value is STDIN_FILE_NO if no pipe is waiting
1441 (i.e. the next command is the first of a group). */
1443 static int last_pipe_input;
1445 /* Fork one piped subcommand. FUNC is the system call to use
1446 (either execv or execvp). ARGV is the arg vector to use.
1447 NOT_LAST is nonzero if this is not the last subcommand
1448 (i.e. its output should be piped to the next one.) */
1453 /* Declare these to avoid compilation error. They won't be called. */
1454 int execv(const char *a, const char **b){}
1455 int execvp(const char *a, const char **b){}
1458 pexecute (search_flag, program, argv, not_last)
1468 scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6);
1469 sprintf (scmd, "%s @%s.gp", program, temp_filename);
1470 argfile = fopen (scmd+strlen (program) + 2, "w");
1472 pfatal_with_name (scmd + strlen (program) + 2);
1474 for (i=1; argv[i]; i++)
1477 for (cp = argv[i]; *cp; cp++)
1479 if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
1480 fputc ('\\', argfile);
1481 fputc (*cp, argfile);
1483 fputc ('\n', argfile);
1489 remove (scmd + strlen (program) + 2);
1493 #else /* not __MSDOS__ */
1496 pexecute (search_flag, program, argv, not_last)
1502 int (*func)() = (search_flag ? execv : execvp);
1505 int input_desc = last_pipe_input;
1506 int output_desc = STDOUT_FILE_NO;
1507 int retries, sleep_interval;
1509 /* If this isn't the last process, make a pipe for its output,
1510 and record it as waiting to be the input to the next process. */
1514 if (pipe (pdes) < 0)
1515 pfatal_with_name ("pipe");
1516 output_desc = pdes[WRITE_PORT];
1517 last_pipe_input = pdes[READ_PORT];
1520 last_pipe_input = STDIN_FILE_NO;
1522 /* Fork a subprocess; wait and retry if it fails. */
1524 for (retries = 0; retries < 4; retries++)
1529 sleep (sleep_interval);
1530 sleep_interval *= 2;
1537 pfatal_with_name ("fork");
1539 pfatal_with_name ("vfork");
1545 /* Move the input and output pipes into place, if nec. */
1546 if (input_desc != STDIN_FILE_NO)
1548 close (STDIN_FILE_NO);
1552 if (output_desc != STDOUT_FILE_NO)
1554 close (STDOUT_FILE_NO);
1556 close (output_desc);
1559 /* Close the parent's descs that aren't wanted here. */
1560 if (last_pipe_input != STDIN_FILE_NO)
1561 close (last_pipe_input);
1563 /* Exec the program. */
1564 (*func) (program, argv);
1565 perror_exec (program);
1571 /* In the parent, after forking.
1572 Close the descriptors that we made for this child. */
1573 if (input_desc != STDIN_FILE_NO)
1575 if (output_desc != STDOUT_FILE_NO)
1576 close (output_desc);
1578 /* Return child's process number. */
1583 #endif /* not __MSDOS__ */
1587 pexecute (search_flag, program, argv, not_last)
1593 return (search_flag ? spawnv : spawnvp) (1, program, argv);
1595 #endif /* not OS2 */
1597 /* Execute the command specified by the arguments on the current line of spec.
1598 When using pipes, this includes several piped-together commands
1599 with `|' between them.
1601 Return 0 if successful, -1 if failed. */
1607 int n_commands; /* # of command. */
1611 char *prog; /* program name. */
1612 char **argv; /* vector of args. */
1613 int pid; /* pid of process for this command. */
1616 struct command *commands; /* each command buffer with above info. */
1618 /* Count # of piped commands. */
1619 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1620 if (strcmp (argbuf[i], "|") == 0)
1623 /* Get storage for each command. */
1625 = (struct command *) alloca (n_commands * sizeof (struct command));
1627 /* Split argbuf into its separate piped processes,
1628 and record info about each one.
1629 Also search for the programs that are to be run. */
1631 commands[0].prog = argbuf[0]; /* first command. */
1632 commands[0].argv = &argbuf[0];
1633 string = find_a_file (&exec_prefix, commands[0].prog, X_OK);
1635 commands[0].argv[0] = string;
1637 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1638 if (strcmp (argbuf[i], "|") == 0)
1639 { /* each command. */
1641 fatal ("-pipe not supported under MS-DOS");
1643 argbuf[i] = 0; /* termination of command args. */
1644 commands[n_commands].prog = argbuf[i + 1];
1645 commands[n_commands].argv = &argbuf[i + 1];
1646 string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK);
1648 commands[n_commands].argv[0] = string;
1652 argbuf[argbuf_index] = 0;
1654 /* If -v, print what we are about to do, and maybe query. */
1658 /* Print each piped command as a separate line. */
1659 for (i = 0; i < n_commands ; i++)
1663 for (j = commands[i].argv; *j; j++)
1664 fprintf (stderr, " %s", *j);
1666 /* Print a pipe symbol after all but the last command. */
1667 if (i + 1 != n_commands)
1668 fprintf (stderr, " |");
1669 fprintf (stderr, "\n");
1673 fprintf (stderr, "\nGo ahead? (y or n) ");
1677 while (getchar () != '\n') ;
1678 if (i != 'y' && i != 'Y')
1683 /* Run each piped subprocess. */
1685 last_pipe_input = STDIN_FILE_NO;
1686 for (i = 0; i < n_commands; i++)
1688 char *string = commands[i].argv[0];
1690 commands[i].pid = pexecute (string != commands[i].prog,
1691 string, commands[i].argv,
1692 i + 1 < n_commands);
1694 if (string != commands[i].prog)
1700 /* Wait for all the subprocesses to finish.
1701 We don't care what order they finish in;
1702 we know that N_COMMANDS waits will get them all. */
1707 for (i = 0; i < n_commands; i++)
1714 status = pid = commands[i].pid;
1716 pid = wait (&status);
1724 for (j = 0; j < n_commands; j++)
1725 if (commands[j].pid == pid)
1726 prog = commands[j].prog;
1728 if ((status & 0x7F) != 0)
1729 fatal ("Internal compiler error: program %s got fatal signal %d",
1730 prog, (status & 0x7F));
1731 if (((status & 0xFF00) >> 8) >= MIN_FATAL_STATUS)
1739 /* Find all the switches given to us
1740 and make a vector describing them.
1741 The elements of the vector are strings, one per switch given.
1742 If a switch uses following arguments, then the `part1' field
1743 is the switch itself and the `args' field
1744 is a null-terminated vector containing the following arguments.
1745 The `valid' field is nonzero if any spec has looked at this switch;
1746 if it remains zero at the end of the run, it must be meaningless. */
1755 static struct switchstr *switches;
1757 static int n_switches;
1765 /* Also a vector of input files specified. */
1767 static struct infile *infiles;
1769 static int n_infiles;
1771 /* And a vector of corresponding output files is made up later. */
1773 static char **outfiles;
1775 /* Create the vector `switches' and its contents.
1776 Store its length in `n_switches'. */
1779 process_command (argc, argv)
1785 char *spec_lang = 0;
1786 int last_language_n_infiles;
1788 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
1792 spec_version = version_string;
1794 /* Set up the default search paths. */
1796 if (gcc_exec_prefix)
1798 add_prefix (&exec_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
1799 add_prefix (&startfile_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
1802 /* COMPILER_PATH and LIBRARY_PATH have values
1803 that are lists of directory names with colons. */
1805 temp = getenv ("COMPILER_PATH");
1808 char *startp, *endp;
1809 char *nstore = (char *) alloca (strlen (temp) + 3);
1811 startp = endp = temp;
1814 if (*endp == PATH_SEPARATOR || *endp == 0)
1816 strncpy (nstore, startp, endp-startp);
1819 strcpy (nstore, "./");
1821 else if (endp[-1] != '/')
1823 nstore[endp-startp] = '/';
1824 nstore[endp-startp+1] = 0;
1827 nstore[endp-startp] = 0;
1828 add_prefix (&exec_prefix, nstore, 0, 0, NULL_PTR);
1831 endp = startp = endp + 1;
1838 temp = getenv ("LIBRARY_PATH");
1841 char *startp, *endp;
1842 char *nstore = (char *) alloca (strlen (temp) + 3);
1844 startp = endp = temp;
1847 if (*endp == PATH_SEPARATOR || *endp == 0)
1849 strncpy (nstore, startp, endp-startp);
1852 strcpy (nstore, "./");
1854 else if (endp[-1] != '/')
1856 nstore[endp-startp] = '/';
1857 nstore[endp-startp+1] = 0;
1860 nstore[endp-startp] = 0;
1861 add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
1862 /* Make separate list of dirs that came from LIBRARY_PATH. */
1863 add_prefix (&library_prefix, nstore, 0, 0, NULL_PTR);
1866 endp = startp = endp + 1;
1873 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
1874 temp = getenv ("LPATH");
1877 char *startp, *endp;
1878 char *nstore = (char *) alloca (strlen (temp) + 3);
1880 startp = endp = temp;
1883 if (*endp == PATH_SEPARATOR || *endp == 0)
1885 strncpy (nstore, startp, endp-startp);
1888 strcpy (nstore, "./");
1890 else if (endp[-1] != '/')
1892 nstore[endp-startp] = '/';
1893 nstore[endp-startp+1] = 0;
1896 nstore[endp-startp] = 0;
1897 add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
1898 /* Make separate list of dirs that came from LIBRARY_PATH. */
1899 add_prefix (&library_prefix, nstore, 0, 0, NULL_PTR);
1902 endp = startp = endp + 1;
1909 /* Scan argv twice. Here, the first time, just count how many switches
1910 there will be in their vector, and how many input files in theirs.
1911 Here we also parse the switches that cc itself uses (e.g. -v). */
1913 for (i = 1; i < argc; i++)
1915 if (! strcmp (argv[i], "-dumpspecs"))
1917 printf ("*asm:\n%s\n\n", asm_spec);
1918 printf ("*asm_final:\n%s\n\n", asm_final_spec);
1919 printf ("*cpp:\n%s\n\n", cpp_spec);
1920 printf ("*cc1:\n%s\n\n", cc1_spec);
1921 printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
1922 printf ("*endfile:\n%s\n\n", endfile_spec);
1923 printf ("*link:\n%s\n\n", link_spec);
1924 printf ("*lib:\n%s\n\n", lib_spec);
1925 printf ("*startfile:\n%s\n\n", startfile_spec);
1926 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
1927 printf ("*signed_char:\n%s\n\n", signed_char_spec);
1928 printf ("*predefines:\n%s\n\n", cpp_predefines);
1929 printf ("*cross_compile:\n%d\n\n", cross_compile);
1933 else if (! strcmp (argv[i], "-dumpversion"))
1935 printf ("%s\n", version_string);
1938 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
1940 print_libgcc_file_name = 1;
1942 else if (! strcmp (argv[i], "-Xlinker"))
1944 /* Pass the argument of this option to the linker when we link. */
1947 fatal ("argument to `-Xlinker' is missing");
1950 if (!linker_options)
1952 = (char **) xmalloc (n_linker_options * sizeof (char **));
1955 = (char **) xrealloc (linker_options,
1956 n_linker_options * sizeof (char **));
1958 linker_options[n_linker_options - 1] = argv[++i];
1960 else if (! strncmp (argv[i], "-Wl,", 4))
1963 /* Pass the rest of this option to the linker when we link. */
1966 if (!linker_options)
1968 = (char **) xmalloc (n_linker_options * sizeof (char **));
1971 = (char **) xrealloc (linker_options,
1972 n_linker_options * sizeof (char **));
1974 /* Split the argument at commas. */
1976 for (j = 4; argv[i][j]; j++)
1977 if (argv[i][j] == ',')
1979 linker_options[n_linker_options - 1]
1980 = save_string (argv[i] + prev, j - prev);
1983 = (char **) xrealloc (linker_options,
1984 n_linker_options * sizeof (char **));
1987 /* Record the part after the last comma. */
1988 linker_options[n_linker_options - 1] = argv[i] + prev;
1990 else if (! strncmp (argv[i], "-Wa,", 4))
1993 /* Pass the rest of this option to the assembler. */
1995 n_assembler_options++;
1996 if (!assembler_options)
1998 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2001 = (char **) xrealloc (assembler_options,
2002 n_assembler_options * sizeof (char **));
2004 /* Split the argument at commas. */
2006 for (j = 4; argv[i][j]; j++)
2007 if (argv[i][j] == ',')
2009 assembler_options[n_assembler_options - 1]
2010 = save_string (argv[i] + prev, j - prev);
2011 n_assembler_options++;
2013 = (char **) xrealloc (assembler_options,
2014 n_assembler_options * sizeof (char **));
2017 /* Record the part after the last comma. */
2018 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2020 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2021 /* Compensate for the +e options to the C++ front-end. */
2023 else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
2025 register char *p = &argv[i][1];
2026 register int c = *p;
2031 if (p[1] == 0 && i + 1 == argc)
2032 fatal ("argument to `-b' is missing");
2034 spec_machine = argv[++i];
2036 spec_machine = p + 1;
2041 int *temp = (int *) xmalloc (sizeof (int));
2043 if (p[1] == 0 && i + 1 == argc)
2044 fatal ("argument to `-B' is missing");
2049 add_prefix (&exec_prefix, value, 1, 0, temp);
2050 add_prefix (&startfile_prefix, value, 1, 0, temp);
2054 case 'v': /* Print our subcommands and print versions. */
2056 /* If they do anything other than exactly `-v', don't set
2057 verbose_flag; rather, continue on to give the error. */
2064 if (p[1] == 0 && i + 1 == argc)
2065 fatal ("argument to `-V' is missing");
2067 spec_version = argv[++i];
2069 spec_version = p + 1;
2073 if (!strcmp (p, "save-temps"))
2075 save_temps_flag = 1;
2082 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2083 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2084 else if (WORD_SWITCH_TAKES_ARG (p))
2085 i += WORD_SWITCH_TAKES_ARG (p);
2092 /* Set up the search paths before we go looking for config files. */
2094 /* These come before the md prefixes so that we will find gcc's subcommands
2095 (such as cpp) rather than those of the host system. */
2096 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2097 as well as trying the machine and the version. */
2098 add_prefix (&exec_prefix, standard_exec_prefix, 0, 2, NULL_PTR);
2099 add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 2, NULL_PTR);
2101 add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, NULL_PTR);
2102 add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, NULL_PTR);
2104 /* More prefixes are enabled in main, after we read the specs file
2105 and determine whether this is cross-compilation or not. */
2108 /* Then create the space for the vectors and scan again. */
2110 switches = ((struct switchstr *)
2111 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2112 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2115 last_language_n_infiles = -1;
2117 /* This, time, copy the text of each switch and store a pointer
2118 to the copy in the vector of switches.
2119 Store all the infiles in their vector. */
2121 for (i = 1; i < argc; i++)
2123 /* Just skip the switches that were handled by the preceding loop. */
2124 if (!strcmp (argv[i], "-Xlinker"))
2126 else if (! strncmp (argv[i], "-Wl,", 4))
2128 else if (! strncmp (argv[i], "-Wa,", 4))
2130 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2132 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2134 /* Compensate for the +e options to the C++ front-end;
2135 they're there simply for cfront call-compatability. We do
2136 some magic in default_compilers to pass them down properly.
2137 Note we deliberately start at the `+' here, to avoid passing
2138 -e0 or -e1 down into the linker. */
2139 switches[n_switches].part1 = &argv[i][0];
2140 switches[n_switches].args = 0;
2141 switches[n_switches].valid = 0;
2144 else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
2146 register char *p = &argv[i][1];
2147 register int c = *p;
2149 if (c == 'B' || c == 'b' || c == 'V')
2151 /* Skip a separate arg, if any. */
2158 if (p[1] == 0 && i + 1 == argc)
2159 fatal ("argument to `-x' is missing");
2161 spec_lang = argv[++i];
2164 if (! strcmp (spec_lang, "none"))
2165 /* Suppress the warning if -xnone comes after the last input file,
2166 because alternate command interfaces like g++ might find it
2167 useful to place -xnone after each input file. */
2170 last_language_n_infiles = n_infiles;
2173 switches[n_switches].part1 = p;
2174 /* Deal with option arguments in separate argv elements. */
2175 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2176 || WORD_SWITCH_TAKES_ARG (p)) {
2178 int n_args = WORD_SWITCH_TAKES_ARG (p);
2181 /* Count only the option arguments in separate argv elements. */
2182 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2184 switches[n_switches].args
2185 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2187 switches[n_switches].args[j++] = argv[++i];
2188 /* Null-terminate the vector. */
2189 switches[n_switches].args[j] = 0;
2190 } else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L')) {
2191 /* On some systems, ld cannot handle -o or -L without space.
2192 So split the -o or -L from its argument. */
2193 switches[n_switches].part1 = (c == 'o' ? "o" : "L");
2194 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2195 switches[n_switches].args[0] = xmalloc (strlen (p));
2196 strcpy (switches[n_switches].args[0], &p[1]);
2197 switches[n_switches].args[1] = 0;
2199 switches[n_switches].args = 0;
2200 switches[n_switches].valid = 0;
2201 /* This is always valid, since gcc.c itself understands it. */
2202 if (!strcmp (p, "save-temps"))
2203 switches[n_switches].valid = 1;
2208 infiles[n_infiles].language = spec_lang;
2209 infiles[n_infiles++].name = argv[i];
2213 if (n_infiles == last_language_n_infiles)
2214 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2216 switches[n_switches].part1 = 0;
2217 infiles[n_infiles].name = 0;
2219 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2220 if (gcc_exec_prefix)
2222 temp = (char *) xmalloc (strlen (gcc_exec_prefix) + strlen (spec_version)
2223 + strlen (spec_machine) + 3);
2224 strcpy (temp, gcc_exec_prefix);
2225 strcat (temp, spec_machine);
2227 strcat (temp, spec_version);
2229 gcc_exec_prefix = temp;
2233 /* Process a spec string, accumulating and running commands. */
2235 /* These variables describe the input file name.
2236 input_file_number is the index on outfiles of this file,
2237 so that the output file name can be stored for later use by %o.
2238 input_basename is the start of the part of the input file
2239 sans all directory names, and basename_length is the number
2240 of characters starting there excluding the suffix .c or whatever. */
2242 static char *input_filename;
2243 static int input_file_number;
2244 static int input_filename_length;
2245 static int basename_length;
2246 static char *input_basename;
2247 static char *input_suffix;
2249 /* These are variables used within do_spec and do_spec_1. */
2251 /* Nonzero if an arg has been started and not yet terminated
2252 (with space, tab or newline). */
2253 static int arg_going;
2255 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2256 is a temporary file name. */
2257 static int delete_this_arg;
2259 /* Nonzero means %w has been seen; the next arg to be terminated
2260 is the output file name of this compilation. */
2261 static int this_is_output_file;
2263 /* Nonzero means %s has been seen; the next arg to be terminated
2264 is the name of a library file and we should try the standard
2265 search dirs for it. */
2266 static int this_is_library_file;
2268 /* Process the spec SPEC and run the commands specified therein.
2269 Returns 0 if the spec is successfully processed; -1 if failed. */
2279 delete_this_arg = 0;
2280 this_is_output_file = 0;
2281 this_is_library_file = 0;
2283 value = do_spec_1 (spec, 0, NULL_PTR);
2285 /* Force out any unfinished command.
2286 If -pipe, this forces out the last command if it ended in `|'. */
2289 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2292 if (argbuf_index > 0)
2299 /* Process the sub-spec SPEC as a portion of a larger spec.
2300 This is like processing a whole spec except that we do
2301 not initialize at the beginning and we do not supply a
2302 newline by default at the end.
2303 INSWITCH nonzero means don't process %-sequences in SPEC;
2304 in this case, % is treated as an ordinary character.
2305 This is used while substituting switches.
2306 INSWITCH nonzero also causes SPC not to terminate an argument.
2308 Value is zero unless a line was finished
2309 and the command on that line reported an error. */
2312 do_spec_1 (spec, inswitch, soft_matched_part)
2315 char *soft_matched_part;
2317 register char *p = spec;
2323 /* If substituting a switch, treat all chars like letters.
2324 Otherwise, NL, SPC, TAB and % are special. */
2325 switch (inswitch ? 'a' : c)
2328 /* End of line: finish any pending argument,
2329 then run the pending command if one has been started. */
2332 obstack_1grow (&obstack, 0);
2333 string = obstack_finish (&obstack);
2334 if (this_is_library_file)
2335 string = find_file (string);
2336 store_arg (string, delete_this_arg, this_is_output_file);
2337 if (this_is_output_file)
2338 outfiles[input_file_number] = string;
2342 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2345 for (i = 0; i < n_switches; i++)
2346 if (!strcmp (switches[i].part1, "pipe"))
2349 /* A `|' before the newline means use a pipe here,
2350 but only if -pipe was specified.
2351 Otherwise, execute now and don't pass the `|' as an arg. */
2354 switches[i].valid = 1;
2361 if (argbuf_index > 0)
2363 int value = execute ();
2367 /* Reinitialize for a new command, and for a new argument. */
2370 delete_this_arg = 0;
2371 this_is_output_file = 0;
2372 this_is_library_file = 0;
2376 /* End any pending argument. */
2379 obstack_1grow (&obstack, 0);
2380 string = obstack_finish (&obstack);
2381 if (this_is_library_file)
2382 string = find_file (string);
2383 store_arg (string, delete_this_arg, this_is_output_file);
2384 if (this_is_output_file)
2385 outfiles[input_file_number] = string;
2389 obstack_1grow (&obstack, c);
2395 /* Space or tab ends an argument if one is pending. */
2398 obstack_1grow (&obstack, 0);
2399 string = obstack_finish (&obstack);
2400 if (this_is_library_file)
2401 string = find_file (string);
2402 store_arg (string, delete_this_arg, this_is_output_file);
2403 if (this_is_output_file)
2404 outfiles[input_file_number] = string;
2406 /* Reinitialize for a new argument. */
2408 delete_this_arg = 0;
2409 this_is_output_file = 0;
2410 this_is_library_file = 0;
2417 fatal ("Invalid specification! Bug in cc.");
2420 obstack_grow (&obstack, input_basename, basename_length);
2425 delete_this_arg = 2;
2428 /* Dump out the directories specified with LIBRARY_PATH,
2429 followed by the absolute directories
2430 that we search for startfiles. */
2432 for (i = 0; i < 2; i++)
2434 struct prefix_list *pl
2435 = (i == 0 ? library_prefix.plist : startfile_prefix.plist);
2437 char *buffer = (char *) xmalloc (bufsize);
2440 for (; pl; pl = pl->next)
2442 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2443 /* Used on systems which record the specified -L dirs
2444 and use them to search for dynamic linking. */
2445 /* Relative directories always come from -B,
2446 and it is better not to use them for searching
2447 at run time. In particular, stage1 loses */
2448 if (pl->prefix[0] != '/')
2453 if (is_linker_dir (pl->prefix, machine_suffix))
2455 do_spec_1 ("-L", 0, NULL_PTR);
2456 #ifdef SPACE_AFTER_L_OPTION
2457 do_spec_1 (" ", 0, NULL_PTR);
2459 do_spec_1 (pl->prefix, 1, NULL_PTR);
2460 /* Remove slash from machine_suffix. */
2461 if (strlen (machine_suffix) >= bufsize)
2462 bufsize = strlen (machine_suffix) * 2 + 1;
2463 buffer = (char *) xrealloc (buffer, bufsize);
2464 strcpy (buffer, machine_suffix);
2465 idx = strlen (buffer);
2466 if (buffer[idx - 1] == '/')
2467 buffer[idx - 1] = 0;
2468 do_spec_1 (buffer, 1, NULL_PTR);
2469 /* Make this a separate argument. */
2470 do_spec_1 (" ", 0, NULL_PTR);
2473 if (!pl->require_machine_suffix)
2475 if (is_linker_dir (pl->prefix, ""))
2477 do_spec_1 ("-L", 0, NULL_PTR);
2478 #ifdef SPACE_AFTER_L_OPTION
2479 do_spec_1 (" ", 0, NULL_PTR);
2481 /* Remove slash from pl->prefix. */
2482 if (strlen (pl->prefix) >= bufsize)
2483 bufsize = strlen (pl->prefix) * 2 + 1;
2484 buffer = (char *) xrealloc (buffer, bufsize);
2485 strcpy (buffer, pl->prefix);
2486 idx = strlen (buffer);
2487 if (buffer[idx - 1] == '/')
2488 buffer[idx - 1] = 0;
2489 do_spec_1 (buffer, 1, NULL_PTR);
2490 /* Make this a separate argument. */
2491 do_spec_1 (" ", 0, NULL_PTR);
2500 /* {...:%efoo} means report an error with `foo' as error message
2501 and don't execute any more commands for this file. */
2505 while (*p != 0 && *p != '\n') p++;
2506 buf = (char *) alloca (p - q + 1);
2507 strncpy (buf, q, p - q);
2517 if (save_temps_flag)
2518 obstack_grow (&obstack, input_basename, basename_length);
2521 obstack_grow (&obstack, temp_filename, temp_filename_length);
2522 if (c == 'u' || c == 'U')
2528 sprintf (buff, "%d", unique);
2529 obstack_grow (&obstack, buff, strlen (buff));
2531 delete_this_arg = 1;
2537 obstack_grow (&obstack, input_filename, input_filename_length);
2542 if (gcc_exec_prefix)
2544 do_spec_1 ("-iprefix", 1, NULL_PTR);
2545 /* Make this a separate argument. */
2546 do_spec_1 (" ", 0, NULL_PTR);
2547 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
2548 do_spec_1 (" ", 0, NULL_PTR);
2555 for (f = 0; f < n_infiles; f++)
2556 store_arg (outfiles[f], 0, 0);
2561 this_is_library_file = 1;
2565 this_is_output_file = 1;
2570 int index = argbuf_index;
2571 /* Handle the {...} following the %W. */
2574 p = handle_braces (p + 1);
2577 /* If any args were output, mark the last one for deletion
2579 if (argbuf_index != index)
2580 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
2584 /* %x{OPTION} records OPTION for %X to output. */
2590 /* Skip past the option value and make a copy. */
2595 string = save_string (p1 + 1, p - p1 - 2);
2597 /* See if we already recorded this option. */
2598 for (i = 0; i < n_linker_options; i++)
2599 if (! strcmp (string, linker_options[i]))
2605 /* This option is new; add it. */
2607 if (!linker_options)
2609 = (char **) xmalloc (n_linker_options * sizeof (char **));
2612 = (char **) xrealloc (linker_options,
2613 n_linker_options * sizeof (char **));
2615 linker_options[n_linker_options - 1] = string;
2619 /* Dump out the options accumulated previously using %x,
2620 -Xlinker and -Wl,. */
2622 for (i = 0; i < n_linker_options; i++)
2624 do_spec_1 (linker_options[i], 1, NULL_PTR);
2625 /* Make each accumulated option a separate argument. */
2626 do_spec_1 (" ", 0, NULL_PTR);
2630 /* Dump out the options accumulated previously using -Wa,. */
2632 for (i = 0; i < n_assembler_options; i++)
2634 do_spec_1 (assembler_options[i], 1, NULL_PTR);
2635 /* Make each accumulated option a separate argument. */
2636 do_spec_1 (" ", 0, NULL_PTR);
2640 /* Here are digits and numbers that just process
2641 a certain constant string as a spec.
2642 /* Here are digits and numbers that just process
2643 a certain constant string as a spec. */
2646 do_spec_1 (cc1_spec, 0, NULL_PTR);
2650 do_spec_1 (cc1plus_spec, 0, NULL_PTR);
2654 do_spec_1 (asm_spec, 0, NULL_PTR);
2658 do_spec_1 (asm_final_spec, 0, NULL_PTR);
2662 do_spec_1 (signed_char_spec, 0, NULL_PTR);
2666 do_spec_1 (cpp_spec, 0, NULL_PTR);
2670 do_spec_1 (endfile_spec, 0, NULL_PTR);
2674 do_spec_1 (link_spec, 0, NULL_PTR);
2678 do_spec_1 (lib_spec, 0, NULL_PTR);
2683 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
2687 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
2691 if (! strncmp (y, "-D", 2))
2692 /* Copy the whole option. */
2693 while (*y && *y != ' ' && *y != '\t')
2695 else if (*y == ' ' || *y == '\t')
2696 /* Copy whitespace to the result. */
2698 /* Don't copy other options. */
2705 do_spec_1 (buf, 0, NULL_PTR);
2711 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
2715 /* Copy all of CPP_PREDEFINES into BUF,
2716 but put __ after every -D and at the end of each arg. */
2720 if (! strncmp (y, "-D", 2))
2727 if (strncmp (y, "__", 2))
2729 /* Stick __ at front of macro name. */
2732 /* Arrange to stick __ at the end as well. */
2736 /* Copy the macro name. */
2737 while (*y && *y != '=' && *y != ' ' && *y != '\t')
2746 /* Copy the value given, if any. */
2747 while (*y && *y != ' ' && *y != '\t')
2750 else if (*y == ' ' || *y == '\t')
2751 /* Copy whitespace to the result. */
2753 /* Don't copy -A options */
2759 /* Copy all of CPP_PREDEFINES into BUF,
2760 but put __ after every -D. */
2764 if (! strncmp (y, "-D", 2))
2769 if (strncmp (y, "__", 2))
2771 /* Stick __ at front of macro name. */
2776 /* Copy the macro name. */
2777 while (*y && *y != '=' && *y != ' ' && *y != '\t')
2780 /* Copy the value given, if any. */
2781 while (*y && *y != ' ' && *y != '\t')
2784 else if (*y == ' ' || *y == '\t')
2785 /* Copy whitespace to the result. */
2787 /* Don't copy -A options */
2793 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
2797 if (! strncmp (y, "-A", 2))
2798 /* Copy the whole option. */
2799 while (*y && *y != ' ' && *y != '\t')
2801 else if (*y == ' ' || *y == '\t')
2802 /* Copy whitespace to the result. */
2804 /* Don't copy other options. */
2811 do_spec_1 (buf, 0, NULL_PTR);
2816 do_spec_1 (startfile_spec, 0, NULL_PTR);
2819 /* Here we define characters other than letters and digits. */
2822 p = handle_braces (p);
2828 obstack_1grow (&obstack, '%');
2832 do_spec_1 (soft_matched_part, 1, NULL_PTR);
2833 do_spec_1 (" ", 0, NULL_PTR);
2836 /* Process a string found as the value of a spec given by name.
2837 This feature allows individual machine descriptions
2838 to add and use their own specs.
2839 %[...] modifies -D options the way %P does;
2840 %(...) uses the spec unmodified. */
2845 struct spec_list *sl;
2848 /* The string after the S/P is the name of a spec that is to be
2850 while (*p && *p != ')' && *p != ']')
2853 /* See if it's in the list */
2854 for (len = p - name, sl = specs; sl; sl = sl->next)
2855 if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
2864 do_spec_1 (name, 0, NULL_PTR);
2867 char *x = (char *) alloca (strlen (name) * 2 + 1);
2871 /* Copy all of NAME into BUF, but put __ after
2872 every -D and at the end of each arg, */
2875 if (! strncmp (y, "-D", 2))
2883 else if (*y == ' ' || *y == 0)
2897 do_spec_1 (buf, 0, NULL_PTR);
2901 /* Discard the closing paren or bracket. */
2913 /* Backslash: treat next character as ordinary. */
2918 /* Ordinary character: put it into the current argument. */
2919 obstack_1grow (&obstack, c);
2923 return 0; /* End of string */
2926 /* Return 0 if we call do_spec_1 and that returns -1. */
2939 /* A `|' after the open-brace means,
2940 if the test fails, output a single minus sign rather than nothing.
2941 This is used in %{|!pipe:...}. */
2945 /* A `!' after the open-brace negates the condition:
2946 succeed if the specified switch is not present. */
2950 /* A `.' after the open-brace means test against the current suffix. */
2960 while (*p != ':' && *p != '}') p++;
2963 register int count = 1;
2981 int found = (input_suffix != 0
2982 && strlen (input_suffix) == p - filter
2983 && strncmp (input_suffix, filter, p - filter) == 0);
2989 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
2994 else if (p[-1] == '*' && p[0] == '}')
2996 /* Substitute all matching switches as separate args. */
2999 for (i = 0; i < n_switches; i++)
3000 if (!strncmp (switches[i].part1, filter, p - filter))
3005 /* Test for presence of the specified switch. */
3009 /* If name specified ends in *, as in {x*:...},
3010 check for %* and handle that case. */
3011 if (p[-1] == '*' && !negate)
3016 /* First see whether we have %*. */
3020 if (*r == '%' && r[1] == '*')
3024 /* If we do, handle that case. */
3027 /* Substitute all matching switches as separate args.
3028 But do this by substituting for %*
3029 in the text that follows the colon. */
3031 unsigned hard_match_len = p - filter - 1;
3032 char *string = save_string (p + 1, q - p - 2);
3034 for (i = 0; i < n_switches; i++)
3035 if (!strncmp (switches[i].part1, filter, hard_match_len))
3037 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
3038 /* Pass any arguments this switch has. */
3046 /* If name specified ends in *, as in {x*:...},
3047 check for presence of any switch name starting with x. */
3050 for (i = 0; i < n_switches; i++)
3052 unsigned hard_match_len = p - filter - 1;
3054 if (!strncmp (switches[i].part1, filter, hard_match_len))
3056 switches[i].valid = 1;
3061 /* Otherwise, check for presence of exact name specified. */
3064 for (i = 0; i < n_switches; i++)
3066 if (!strncmp (switches[i].part1, filter, p - filter)
3067 && switches[i].part1[p - filter] == 0)
3069 switches[i].valid = 1;
3076 /* If it is as desired (present for %{s...}, absent for %{-s...})
3077 then substitute either the switch or the specified
3078 conditional text. */
3079 if (present != negate)
3087 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3093 /* Here if a %{|...} conditional fails: output a minus sign,
3094 which means "standard output" or "standard input". */
3095 do_spec_1 ("-", 0, NULL_PTR);
3102 /* Pass a switch to the current accumulating command
3103 in the same form that we received it.
3104 SWITCHNUM identifies the switch; it is an index into
3105 the vector of switches gcc received, which is `switches'.
3106 This cannot fail since it never finishes a command line.
3108 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
3111 give_switch (switchnum, omit_first_word)
3113 int omit_first_word;
3115 if (!omit_first_word)
3117 do_spec_1 ("-", 0, NULL_PTR);
3118 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
3120 do_spec_1 (" ", 0, NULL_PTR);
3121 if (switches[switchnum].args != 0)
3124 for (p = switches[switchnum].args; *p; p++)
3126 do_spec_1 (*p, 1, NULL_PTR);
3127 do_spec_1 (" ", 0, NULL_PTR);
3130 switches[switchnum].valid = 1;
3133 /* Search for a file named NAME trying various prefixes including the
3134 user's -B prefix and some standard ones.
3135 Return the absolute file name found. If nothing is found, return NAME. */
3143 newname = find_a_file (&startfile_prefix, name, R_OK);
3144 return newname ? newname : name;
3147 /* Determine whether a -L option is relevant. Not required for certain
3148 fixed names and for directories that don't exist. */
3151 is_linker_dir (path1, path2)
3155 int len1 = strlen (path1);
3156 int len2 = strlen (path2);
3157 char *path = (char *) alloca (3 + len1 + len2);
3161 /* Construct the path from the two parts. Ensure the string ends with "/.".
3162 The resulting path will be a directory even if the given path is a
3164 bcopy (path1, path, len1);
3165 bcopy (path2, path + len1, len2);
3166 cp = path + len1 + len2;
3172 /* Exclude directories that the linker is known to search. */
3173 if ((cp - path == 6 && strcmp (path, "/lib/.") == 0)
3174 || (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0))
3177 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
3180 /* On fatal signals, delete all the temporary files. */
3183 fatal_error (signum)
3186 signal (signum, SIG_DFL);
3187 delete_failure_queue ();
3188 delete_temp_files ();
3189 /* Get the same signal again, this time not handled,
3190 so its normal effect occurs. */
3191 kill (getpid (), signum);
3202 int error_count = 0;
3203 int linker_was_run = 0;
3204 char *explicit_link_files;
3207 programname = argv[0];
3209 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
3210 signal (SIGINT, fatal_error);
3211 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
3212 signal (SIGHUP, fatal_error);
3213 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
3214 signal (SIGTERM, fatal_error);
3216 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
3217 signal (SIGPIPE, fatal_error);
3221 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
3223 obstack_init (&obstack);
3225 /* Set up to remember the pathname of gcc and any options
3226 needed for collect. */
3227 obstack_init (&collect_obstack);
3228 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
3229 obstack_grow (&collect_obstack, programname, strlen (programname)+1);
3230 putenv (obstack_finish (&collect_obstack));
3232 /* Choose directory for temp files. */
3234 choose_temp_base ();
3236 /* Make a table of what switches there are (switches, n_switches).
3237 Make a table of specified input files (infiles, n_infiles).
3238 Decode switches that are handled locally. */
3240 process_command (argc, argv);
3242 /* Initialize the vector of specs to just the default.
3243 This means one element containing 0s, as a terminator. */
3245 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
3246 bcopy (default_compilers, compilers, sizeof default_compilers);
3247 n_compilers = n_default_compilers;
3249 /* Read specs from a file if there is one. */
3251 machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", ""));
3252 just_machine_suffix = concat (spec_machine, "/", "");
3254 specs_file = find_a_file (&startfile_prefix, "specs", R_OK);
3255 /* Read the specs file unless it is a default one. */
3256 if (specs_file != 0 && strcmp (specs_file, "specs"))
3257 read_specs (specs_file);
3259 /* If not cross-compiling, look for startfiles in the standard places. */
3260 /* The fact that these are done here, after reading the specs file,
3261 means that it cannot be found in these directories.
3262 But that's okay. It should never be there anyway. */
3265 #ifdef MD_EXEC_PREFIX
3266 add_prefix (&exec_prefix, md_exec_prefix, 0, 0, NULL_PTR);
3267 add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, NULL_PTR);
3270 #ifdef MD_STARTFILE_PREFIX
3271 add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, NULL_PTR);
3274 #ifdef MD_STARTFILE_PREFIX_1
3275 add_prefix (&startfile_prefix, md_startfile_prefix_1, 0, 0, NULL_PTR);
3278 add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0,
3280 add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0,
3282 add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0,
3284 #if 0 /* Can cause surprises, and one can use -B./ instead. */
3285 add_prefix (&startfile_prefix, "./", 0, 1, NULL_PTR);
3289 /* Now we have the specs.
3290 Set the `valid' bits for switches that match anything in any spec. */
3292 validate_all_switches ();
3294 /* Warn about any switches that no pass was interested in. */
3296 for (i = 0; i < n_switches; i++)
3297 if (! switches[i].valid)
3298 error ("unrecognized option `-%s'", switches[i].part1);
3300 if (print_libgcc_file_name)
3302 printf ("%s\n", find_file ("libgcc.a"));
3306 /* Obey some of the options. */
3310 fprintf (stderr, "gcc version %s\n", version_string);
3316 fatal ("No input files specified.");
3318 /* Make a place to record the compiler output file names
3319 that correspond to the input files. */
3321 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
3322 bzero (outfiles, n_infiles * sizeof (char *));
3324 /* Record which files were specified explicitly as link input. */
3326 explicit_link_files = xmalloc (n_infiles);
3327 bzero (explicit_link_files, n_infiles);
3329 for (i = 0; i < n_infiles; i++)
3331 register struct compiler *cp = 0;
3332 int this_file_error = 0;
3334 /* Tell do_spec what to substitute for %i. */
3336 input_filename = infiles[i].name;
3337 input_filename_length = strlen (input_filename);
3338 input_file_number = i;
3340 /* Use the same thing in %o, unless cp->spec says otherwise. */
3342 outfiles[i] = input_filename;
3344 /* Figure out which compiler from the file's suffix. */
3346 cp = lookup_compiler (infiles[i].name, input_filename_length,
3347 infiles[i].language);
3351 /* Ok, we found an applicable compiler. Run its spec. */
3352 /* First say how much of input_filename to substitute for %b */
3356 input_basename = input_filename;
3357 for (p = input_filename; *p; p++)
3359 input_basename = p + 1;
3361 /* Find a suffix starting with the last period,
3362 and set basename_length to exclude that suffix. */
3363 basename_length = strlen (input_basename);
3364 p = input_basename + basename_length;
3365 while (p != input_basename && *p != '.') --p;
3366 if (*p == '.' && p != input_basename)
3368 basename_length = p - input_basename;
3369 input_suffix = p + 1;
3375 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
3377 len += strlen (cp->spec[j]);
3379 p = (char *) xmalloc (len + 1);
3382 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
3385 strcpy (p + len, cp->spec[j]);
3386 len += strlen (cp->spec[j]);
3389 value = do_spec (p);
3392 this_file_error = 1;
3395 /* If this file's name does not contain a recognized suffix,
3396 record it as explicit linker input. */
3399 explicit_link_files[i] = 1;
3401 /* Clear the delete-on-failure queue, deleting the files in it
3402 if this compilation failed. */
3404 if (this_file_error)
3406 delete_failure_queue ();
3409 /* If this compilation succeeded, don't delete those files later. */
3410 clear_failure_queue ();
3413 /* Run ld to link all the compiler output files. */
3415 if (error_count == 0)
3417 int tmp = execution_count;
3421 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
3423 putenv_from_prefixes (&exec_prefix, "COMPILER_PATH=");
3424 putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH=");
3426 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
3428 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
3429 sizeof ("COLLECT_GCC_OPTIONS=")-1);
3432 for (i = 0; i < n_switches; i++)
3436 obstack_grow (&collect_obstack, " ", 1);
3439 obstack_grow (&collect_obstack, "-", 1);
3440 obstack_grow (&collect_obstack, switches[i].part1,
3441 strlen (switches[i].part1));
3443 for (args = switches[i].args; args && *args; args++)
3445 obstack_grow (&collect_obstack, " ", 1);
3446 obstack_grow (&collect_obstack, *args, strlen (*args));
3449 obstack_grow (&collect_obstack, "\0", 1);
3450 putenv (obstack_finish (&collect_obstack));
3452 value = do_spec (link_command_spec);
3455 linker_was_run = (tmp != execution_count);
3458 /* Warn if a -B option was specified but the prefix was never used. */
3459 unused_prefix_warnings (&exec_prefix);
3460 unused_prefix_warnings (&startfile_prefix);
3462 /* If options said don't run linker,
3463 complain about input files to be given to the linker. */
3465 if (! linker_was_run && error_count == 0)
3466 for (i = 0; i < n_infiles; i++)
3467 if (explicit_link_files[i])
3468 error ("%s: linker input file unused since linking not done",
3471 /* Delete some or all of the temporary files we made. */
3474 delete_failure_queue ();
3475 delete_temp_files ();
3482 /* Find the proper compilation spec for the file name NAME,
3483 whose length is LENGTH. LANGUAGE is the specified language,
3484 or 0 if none specified. */
3486 static struct compiler *
3487 lookup_compiler (name, length, language)
3492 struct compiler *cp;
3494 /* Look for the language, if one is spec'd. */
3497 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
3501 if (cp->suffix[0] == '@'
3502 && !strcmp (cp->suffix + 1, language))
3506 error ("language %s not recognized", language);
3509 /* Look for a suffix. */
3510 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
3512 if (strlen (cp->suffix) < length
3513 /* See if the suffix matches the end of NAME. */
3514 && !strcmp (cp->suffix,
3515 name + length - strlen (cp->suffix))
3516 /* The suffix `-' matches only the file name `-'. */
3517 && !(!strcmp (cp->suffix, "-") && length != 1))
3519 if (cp->spec[0][0] == '@')
3521 struct compiler *new;
3522 /* An alias entry maps a suffix to a language.
3523 Search for the language; pass 0 for NAME and LENGTH
3524 to avoid infinite recursion if language not found.
3525 Construct the new compiler spec. */
3526 language = cp->spec[0] + 1;
3527 new = (struct compiler *) xmalloc (sizeof (struct compiler));
3528 new->suffix = cp->suffix;
3529 bcopy (lookup_compiler (NULL_PTR, 0, language)->spec,
3530 new->spec, sizeof new->spec);
3533 /* A non-alias entry: return it. */
3545 register char *value = (char *) malloc (size);
3547 fatal ("virtual memory exhausted");
3552 xrealloc (ptr, size)
3556 register char *value = (char *) realloc (ptr, size);
3558 fatal ("virtual memory exhausted");
3562 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
3568 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
3569 char *result = xmalloc (len1 + len2 + len3 + 1);
3571 strcpy (result, s1);
3572 strcpy (result + len1, s2);
3573 strcpy (result + len1 + len2, s3);
3574 *(result + len1 + len2 + len3) = 0;
3580 save_string (s, len)
3584 register char *result = xmalloc (len + 1);
3586 bcopy (s, result, len);
3592 pfatal_with_name (name)
3597 if (errno < sys_nerr)
3598 s = concat ("%s: ", sys_errlist[errno], "");
3600 s = "cannot open %s";
3605 perror_with_name (name)
3610 if (errno < sys_nerr)
3611 s = concat ("%s: ", sys_errlist[errno], "");
3613 s = "cannot open %s";
3623 if (errno < sys_nerr)
3624 s = concat ("installation problem, cannot exec %s: ",
3625 sys_errlist[errno], "");
3627 s = "installation problem, cannot exec %s";
3631 /* More 'friendly' abort that prints the line and file.
3632 config.h can #define abort fancy_abort if you like that sort of thing. */
3637 fatal ("Internal gcc abort.");
3642 /* Output an error message and exit */
3652 format = va_arg (ap, char *);
3653 fprintf (stderr, "%s: ", programname);
3654 vfprintf (stderr, format, ap);
3656 fprintf (stderr, "\n");
3657 delete_temp_files ();
3669 format = va_arg (ap, char *);
3670 fprintf (stderr, "%s: ", programname);
3671 vfprintf (stderr, format, ap);
3674 fprintf (stderr, "\n");
3677 #else /* not HAVE_VPRINTF */
3680 fatal (msg, arg1, arg2)
3681 char *msg, *arg1, *arg2;
3683 error (msg, arg1, arg2);
3684 delete_temp_files ();
3689 error (msg, arg1, arg2)
3690 char *msg, *arg1, *arg2;
3692 fprintf (stderr, "%s: ", programname);
3693 fprintf (stderr, msg, arg1, arg2);
3694 fprintf (stderr, "\n");
3697 #endif /* not HAVE_VPRINTF */
3701 validate_all_switches ()
3703 struct compiler *comp;
3706 struct spec_list *spec;
3708 for (comp = compilers; comp->spec[0]; comp++)
3711 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
3715 if (c == '%' && *p == '{')
3716 /* We have a switch spec. */
3717 validate_switches (p + 1);
3721 /* look through the linked list of extra specs read from the specs file */
3722 for (spec = specs; spec ; spec = spec->next)
3726 if (c == '%' && *p == '{')
3727 /* We have a switch spec. */
3728 validate_switches (p + 1);
3731 p = link_command_spec;
3733 if (c == '%' && *p == '{')
3734 /* We have a switch spec. */
3735 validate_switches (p + 1);
3737 /* Now notice switches mentioned in the machine-specific specs. */
3741 if (c == '%' && *p == '{')
3742 /* We have a switch spec. */
3743 validate_switches (p + 1);
3747 if (c == '%' && *p == '{')
3748 /* We have a switch spec. */
3749 validate_switches (p + 1);
3753 if (c == '%' && *p == '{')
3754 /* We have a switch spec. */
3755 validate_switches (p + 1);
3757 p = signed_char_spec;
3759 if (c == '%' && *p == '{')
3760 /* We have a switch spec. */
3761 validate_switches (p + 1);
3765 if (c == '%' && *p == '{')
3766 /* We have a switch spec. */
3767 validate_switches (p + 1);
3771 if (c == '%' && *p == '{')
3772 /* We have a switch spec. */
3773 validate_switches (p + 1);
3777 if (c == '%' && *p == '{')
3778 /* We have a switch spec. */
3779 validate_switches (p + 1);
3783 if (c == '%' && *p == '{')
3784 /* We have a switch spec. */
3785 validate_switches (p + 1);
3789 if (c == '%' && *p == '{')
3790 /* We have a switch spec. */
3791 validate_switches (p + 1);
3794 /* Look at the switch-name that comes after START
3795 and mark as valid all supplied switches that match it. */
3798 validate_switches (start)
3801 register char *p = start;
3816 while (*p != ':' && *p != '}') p++;
3820 else if (p[-1] == '*')
3822 /* Mark all matching switches as valid. */
3824 for (i = 0; i < n_switches; i++)
3825 if (!strncmp (switches[i].part1, filter, p - filter))
3826 switches[i].valid = 1;
3830 /* Mark an exact matching switch as valid. */
3831 for (i = 0; i < n_switches; i++)
3833 if (!strncmp (switches[i].part1, filter, p - filter)
3834 && switches[i].part1[p - filter] == 0)
3835 switches[i].valid = 1;