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. */
401 char *spec; /* To use this compiler, pass this spec
405 /* Pointer to a vector of `struct compiler' that gives the spec for
406 compiling a file, based on its suffix.
407 A file that does not end in any of these suffixes will be passed
408 unchanged to the loader and nothing else will be done to it.
410 An entry containing two 0s is used to terminate the vector.
412 If multiple entries match a file, the last matching one is used. */
414 static struct compiler *compilers;
416 /* Number of entries in `compilers', not counting the null terminator. */
418 static int n_compilers;
420 /* The default list of file name suffixes and their compilation specs. */
422 static struct compiler default_compilers[] =
426 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
427 %{C:%{!E:%eGNU C does not support -C without using -E}}\
428 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
429 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
430 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
431 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
432 %{traditional-cpp:-traditional}\
433 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
434 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
435 %{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
436 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
437 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
438 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
440 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
441 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
442 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
443 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
444 %{!pipe:%g.s} %A\n }}}}"},
446 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
447 %{C:%{!E:%eGNU C does not support -C without using -E}}\
448 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
449 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
450 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
451 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
452 %{traditional-cpp:-traditional}\
453 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
455 %{!E:%e-E required when input is from standard input}"},
456 {".m", "@objective-c"},
458 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
459 %{C:%{!E:%eGNU C does not support -C without using -E}}\
460 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
461 -undef -D__OBJC__ -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
462 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
463 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
464 %{traditional-cpp:-traditional}\
465 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
466 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
467 %{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
468 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
469 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
470 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
471 -lang-objc %{gen-decls} \
473 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
474 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
475 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
476 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
477 %{!pipe:%g.s} %A\n }}}}"},
480 "%{!E:%eCompilation of header file requested} \
481 cpp %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
482 %{C:%{!E:%eGNU C does not support -C without using -E}}\
483 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
484 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
485 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
486 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
487 %{traditional-cpp:-traditional}\
488 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
494 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
495 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
496 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
497 -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus \
498 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
499 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
500 %{traditional-cpp:-traditional} %{trigraphs}\
501 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
502 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
503 %{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.i} %1 %2\
504 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
505 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
506 %{v:-version} %{pg:-p} %{p} %{f*}\
508 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
509 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
510 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
511 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
512 %{!pipe:%g.s} %A\n }}}}"},
513 {".i", "@cpp-output"},
515 "cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
516 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
517 %{v:-version} %{pg:-p} %{p} %{f*}\
519 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
520 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
521 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
522 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n }"},
523 {".ii", "@c++-cpp-output"},
525 "cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
526 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
527 %{v:-version} %{pg:-p} %{p} %{f*}\
529 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
530 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
531 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
532 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
533 %{!pipe:%g.s} %A\n }"},
534 {".s", "@assembler"},
536 "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
537 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o} %i %A\n }"},
538 {".S", "@assembler-with-cpp"},
539 {"@assembler-with-cpp",
540 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
541 %{C:%{!E:%eGNU C does not support -C without using -E}}\
542 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \
543 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
544 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
545 %{traditional-cpp:-traditional}\
546 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
547 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
548 %{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
549 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
550 %{!pipe:%g.s} %A\n }}}}"},
551 /* Mark end of table */
555 /* Number of elements in default_compilers, not counting the terminator. */
557 static int n_default_compilers
558 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
560 /* Here is the spec for running the linker, after compiling all files. */
562 #ifdef LINK_LIBGCC_SPECIAL
563 /* Have gcc do the search for libgcc.a. */
564 /* -u* was put back because both BSD and SysV seem to support it. */
565 /* %{static:} simply prevents an error message if the target machine
566 doesn't handle -static. */
567 static char *link_command_spec = "\
568 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
569 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
570 %{!A:%{!nostdlib:%S}} %{static:}\
571 %{L*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}";
573 /* Use -L and have the linker do the search for -lgcc. */
574 static char *link_command_spec = "\
575 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
576 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
577 %{!A:%{!nostdlib:%S}} %{static:}\
578 %{L*} %D %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}";
581 /* A vector of options to give to the linker.
582 These options are accumulated by -Xlinker and -Wl,
583 and substituted into the linker command with %X. */
584 static int n_linker_options;
585 static char **linker_options;
587 /* A vector of options to give to the assembler.
588 These options are accumulated by -Wa,
589 and substituted into the assembler command with %X. */
590 static int n_assembler_options;
591 static char **assembler_options;
593 /* Read compilation specs from a file named FILENAME,
594 replacing the default ones.
596 A suffix which starts with `*' is a definition for
597 one of the machine-specific sub-specs. The "suffix" should be
598 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
599 The corresponding spec is stored in asm_spec, etc.,
600 rather than in the `compilers' vector.
602 Anything invalid in the file is a fatal error. */
605 read_specs (filename)
614 fprintf (stderr, "Reading specs from %s\n", filename);
616 /* Open and stat the file. */
617 desc = open (filename, 0, 0);
619 pfatal_with_name (filename);
620 if (stat (filename, &statbuf) < 0)
621 pfatal_with_name (filename);
623 /* Read contents of file into BUFFER. */
624 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
625 read (desc, buffer, (unsigned) statbuf.st_size);
626 buffer[statbuf.st_size] = 0;
629 /* Scan BUFFER for specs, putting them in the vector. */
635 char *in, *out, *p1, *p2;
637 /* Advance P in BUFFER to the next nonblank nocomment line. */
638 p = skip_whitespace (p);
642 /* Find the colon that should end the suffix. */
644 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
645 /* The colon shouldn't be missing. */
647 fatal ("specs file malformed after %d characters", p1 - buffer);
648 /* Skip back over trailing whitespace. */
650 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
651 /* Copy the suffix to a string. */
652 suffix = save_string (p, p2 - p);
653 /* Find the next line. */
654 p = skip_whitespace (p1 + 1);
656 fatal ("specs file malformed after %d characters", p - buffer);
658 /* Find next blank line. */
659 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
660 /* Specs end at the blank line and do not include the newline. */
661 spec = save_string (p, p1 - p);
664 /* Delete backslash-newline sequences from the spec. */
669 if (in[0] == '\\' && in[1] == '\n')
671 else if (in[0] == '#')
673 while (*in && *in != '\n') in++;
680 if (suffix[0] == '*')
682 if (! strcmp (suffix, "*link_command"))
683 link_command_spec = spec;
685 set_spec (suffix + 1, spec);
689 /* Add this pair to the vector. */
691 = ((struct compiler *)
692 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
693 compilers[n_compilers].suffix = suffix;
694 compilers[n_compilers].spec = spec;
699 link_command_spec = spec;
702 if (link_command_spec == 0)
703 fatal ("spec file has no spec for linking");
712 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
713 be considered whitespace. */
714 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
716 else if (*p == '\n' || *p == ' ' || *p == '\t')
720 while (*p != '\n') p++;
730 /* Structure to keep track of the specs that have been defined so far. These
731 are accessed using %(specname) or %[specname] in a compiler or link spec. */
735 char *name; /* Name of the spec. */
736 char *spec; /* The spec itself. */
737 struct spec_list *next; /* Next spec in linked list. */
740 /* List of specs that have been defined so far. */
742 static struct spec_list *specs = (struct spec_list *) 0;
744 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
745 removed; If the spec starts with a + then SPEC is added to the end of the
749 set_spec (name, spec)
753 struct spec_list *sl;
756 /* See if the spec already exists */
757 for (sl = specs; sl; sl = sl->next)
758 if (strcmp (sl->name, name) == 0)
763 /* Not found - make it */
764 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
765 sl->name = save_string (name, strlen (name));
766 sl->spec = save_string ("", 0);
772 if (name && spec[0] == '+' && isspace (spec[1]))
773 sl->spec = concat (old_spec, spec + 1, "");
775 sl->spec = save_string (spec, strlen (spec));
777 if (! strcmp (name, "asm"))
779 else if (! strcmp (name, "asm_final"))
780 asm_final_spec = sl->spec;
781 else if (! strcmp (name, "cc1"))
783 else if (! strcmp (name, "cc1plus"))
784 cc1plus_spec = sl->spec;
785 else if (! strcmp (name, "cpp"))
787 else if (! strcmp (name, "endfile"))
788 endfile_spec = sl->spec;
789 else if (! strcmp (name, "lib"))
791 else if (! strcmp (name, "link"))
792 link_spec = sl->spec;
793 else if (! strcmp (name, "predefines"))
794 cpp_predefines = sl->spec;
795 else if (! strcmp (name, "signed_char"))
796 signed_char_spec = sl->spec;
797 else if (! strcmp (name, "startfile"))
798 startfile_spec = sl->spec;
799 else if (! strcmp (name, "switches_need_spaces"))
800 switches_need_spaces = sl->spec;
801 else if (! strcmp (name, "cross_compile"))
802 cross_compile = atoi (sl->spec);
803 /* Free the old spec */
808 /* Accumulate a command (program name and args), and run it. */
810 /* Vector of pointers to arguments in the current line of specifications. */
812 static char **argbuf;
814 /* Number of elements allocated in argbuf. */
816 static int argbuf_length;
818 /* Number of elements in argbuf currently in use (containing args). */
820 static int argbuf_index;
822 /* Number of commands executed so far. */
824 static int execution_count;
826 /* Name with which this program was invoked. */
828 static char *programname;
830 /* Structures to keep track of prefixes to try when looking for files. */
834 char *prefix; /* String to prepend to the path. */
835 struct prefix_list *next; /* Next in linked list. */
836 int require_machine_suffix; /* Don't use without machine_suffix. */
837 /* 2 means try both machine_suffix and just_machine_suffix. */
838 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
843 struct prefix_list *plist; /* List of prefixes to try */
844 int max_len; /* Max length of a prefix in PLIST */
845 char *name; /* Name of this list (used in config stuff) */
848 /* List of prefixes to try when looking for executables. */
850 static struct path_prefix exec_prefix = { 0, 0, "exec" };
852 /* List of prefixes to try when looking for startup (crt0) files. */
854 static struct path_prefix startfile_prefix = { 0, 0, "startfile" };
856 /* List of prefixes to try when looking for libraries. */
858 static struct path_prefix library_prefix = { 0, 0, "libraryfile" };
860 /* Suffix to attach to directories searched for commands.
861 This looks like `MACHINE/VERSION/'. */
863 static char *machine_suffix = 0;
865 /* Suffix to attach to directories searched for commands.
866 This is just `MACHINE/'. */
868 static char *just_machine_suffix = 0;
870 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
872 static char *gcc_exec_prefix;
874 /* Default prefixes to attach to command names. */
876 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
877 #undef MD_EXEC_PREFIX
878 #undef MD_STARTFILE_PREFIX
879 #undef MD_STARTFILE_PREFIX_1
882 #ifndef STANDARD_EXEC_PREFIX
883 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
884 #endif /* !defined STANDARD_EXEC_PREFIX */
886 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
887 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
888 #ifdef MD_EXEC_PREFIX
889 static char *md_exec_prefix = MD_EXEC_PREFIX;
892 #ifndef STANDARD_STARTFILE_PREFIX
893 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
894 #endif /* !defined STANDARD_STARTFILE_PREFIX */
896 #ifdef MD_STARTFILE_PREFIX
897 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
899 #ifdef MD_STARTFILE_PREFIX_1
900 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
902 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
903 static char *standard_startfile_prefix_1 = "/lib/";
904 static char *standard_startfile_prefix_2 = "/usr/lib/";
906 /* Clear out the vector of arguments (after a command is executed). */
914 /* Add one argument to the vector at the end.
915 This is done when a space is seen or at the end of the line.
916 If DELETE_ALWAYS is nonzero, the arg is a filename
917 and the file should be deleted eventually.
918 If DELETE_FAILURE is nonzero, the arg is a filename
919 and the file should be deleted if this compilation fails. */
922 store_arg (arg, delete_always, delete_failure)
924 int delete_always, delete_failure;
926 if (argbuf_index + 1 == argbuf_length)
928 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
931 argbuf[argbuf_index++] = arg;
932 argbuf[argbuf_index] = 0;
934 if (delete_always || delete_failure)
935 record_temp_file (arg, delete_always, delete_failure);
938 /* Record the names of temporary files we tell compilers to write,
939 and delete them at the end of the run. */
941 /* This is the common prefix we use to make temp file names.
942 It is chosen once for each run of this program.
943 It is substituted into a spec by %g.
944 Thus, all temp file names contain this prefix.
945 In practice, all temp file names start with this prefix.
947 This prefix comes from the envvar TMPDIR if it is defined;
948 otherwise, from the P_tmpdir macro if that is defined;
949 otherwise, in /usr/tmp or /tmp. */
951 static char *temp_filename;
953 /* Length of the prefix. */
955 static int temp_filename_length;
957 /* Define the list of temporary files to delete. */
962 struct temp_file *next;
965 /* Queue of files to delete on success or failure of compilation. */
966 static struct temp_file *always_delete_queue;
967 /* Queue of files to delete on failure of compilation. */
968 static struct temp_file *failure_delete_queue;
970 /* Record FILENAME as a file to be deleted automatically.
971 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
972 otherwise delete it in any case.
973 FAIL_DELETE nonzero means delete it if a compilation step fails;
974 otherwise delete it in any case. */
977 record_temp_file (filename, always_delete, fail_delete)
983 name = xmalloc (strlen (filename) + 1);
984 strcpy (name, filename);
988 register struct temp_file *temp;
989 for (temp = always_delete_queue; temp; temp = temp->next)
990 if (! strcmp (name, temp->name))
992 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
993 temp->next = always_delete_queue;
995 always_delete_queue = temp;
1001 register struct temp_file *temp;
1002 for (temp = failure_delete_queue; temp; temp = temp->next)
1003 if (! strcmp (name, temp->name))
1005 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1006 temp->next = failure_delete_queue;
1008 failure_delete_queue = temp;
1013 /* Delete all the temporary files whose names we previously recorded. */
1016 delete_temp_files ()
1018 register struct temp_file *temp;
1020 for (temp = always_delete_queue; temp; temp = temp->next)
1024 printf ("Delete %s? (y or n) ", temp->name);
1028 while (getchar () != '\n') ;
1029 if (i == 'y' || i == 'Y')
1033 if (stat (temp->name, &st) >= 0)
1035 /* Delete only ordinary files. */
1036 if (S_ISREG (st.st_mode))
1037 if (unlink (temp->name) < 0)
1039 perror_with_name (temp->name);
1044 always_delete_queue = 0;
1047 /* Delete all the files to be deleted on error. */
1050 delete_failure_queue ()
1052 register struct temp_file *temp;
1054 for (temp = failure_delete_queue; temp; temp = temp->next)
1058 printf ("Delete %s? (y or n) ", temp->name);
1062 while (getchar () != '\n') ;
1063 if (i == 'y' || i == 'Y')
1066 if (unlink (temp->name) < 0)
1068 perror_with_name (temp->name);
1074 clear_failure_queue ()
1076 failure_delete_queue = 0;
1079 /* Compute a string to use as the base of all temporary file names.
1080 It is substituted for %g. */
1085 char *base = getenv ("TMPDIR");
1088 if (base == (char *)0)
1091 if (access (P_tmpdir, R_OK | W_OK) == 0)
1094 if (base == (char *)0)
1096 if (access ("/usr/tmp", R_OK | W_OK) == 0)
1103 len = strlen (base);
1104 temp_filename = xmalloc (len + sizeof("/ccXXXXXX"));
1105 strcpy (temp_filename, base);
1106 if (len > 0 && temp_filename[len-1] != '/')
1107 temp_filename[len++] = '/';
1108 strcpy (temp_filename + len, "ccXXXXXX");
1110 mktemp (temp_filename);
1111 temp_filename_length = strlen (temp_filename);
1115 /* Routine to add variables to the environment. We do this to pass
1116 the pathname of the gcc driver, and the directories search to the
1117 collect2 program, which is being run as ld. This way, we can be
1118 sure of executing the right compiler when collect2 wants to build
1119 constructors and destructors. Since the environment variables we
1120 use come from an obstack, we don't have to worry about allocating
1128 #ifndef VMS /* nor about VMS */
1130 extern char **environ;
1131 char **old_environ = environ;
1135 int str_len = strlen (str);
1139 while ((ch = *p++) != '\0' && ch != '=')
1145 /* Search for replacing an existing environment variable, and
1146 count the number of total environment variables. */
1147 for (envp = old_environ; *envp; envp++)
1150 if (!strncmp (str, *envp, name_len))
1157 /* Add a new environment variable */
1158 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1160 bcopy (old_environ, environ+1, sizeof (char *) * (num_envs+1));
1165 #endif /* HAVE_PUTENV */
1168 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1171 putenv_from_prefixes (paths, env_var)
1172 struct path_prefix *paths;
1175 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1176 int first_time = TRUE;
1177 struct prefix_list *pprefix;
1179 obstack_grow (&collect_obstack, env_var, strlen (env_var));
1181 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1183 int len = strlen (pprefix->prefix);
1188 obstack_grow (&collect_obstack, ":", 1);
1191 obstack_grow (&collect_obstack, pprefix->prefix, len);
1192 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1195 if (just_machine_suffix && pprefix->require_machine_suffix == 2)
1198 obstack_grow (&collect_obstack, ":", 1);
1201 obstack_grow (&collect_obstack, pprefix->prefix, len);
1202 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1205 if (!pprefix->require_machine_suffix)
1208 obstack_grow (&collect_obstack, ":", 1);
1211 obstack_grow (&collect_obstack, pprefix->prefix, len);
1214 obstack_grow (&collect_obstack, "\0", 1);
1215 putenv (obstack_finish (&collect_obstack));
1219 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1220 access to check permissions.
1221 Return 0 if not found, otherwise return its name, allocated with malloc. */
1224 find_a_file (pprefix, name, mode)
1225 struct path_prefix *pprefix;
1230 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1231 struct prefix_list *pl;
1232 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1235 len += strlen (machine_suffix);
1237 temp = xmalloc (len);
1239 /* Determine the filename to execute (special case for absolute paths). */
1243 if (access (name, mode))
1245 strcpy (temp, name);
1250 for (pl = pprefix->plist; pl; pl = pl->next)
1254 strcpy (temp, pl->prefix);
1255 strcat (temp, machine_suffix);
1256 strcat (temp, name);
1257 if (access (temp, mode) == 0)
1259 if (pl->used_flag_ptr != 0)
1260 *pl->used_flag_ptr = 1;
1263 /* Some systems have a suffix for executable files.
1264 So try appending that. */
1265 if (file_suffix[0] != 0)
1267 strcat (temp, file_suffix);
1268 if (access (temp, mode) == 0)
1270 if (pl->used_flag_ptr != 0)
1271 *pl->used_flag_ptr = 1;
1276 /* Certain prefixes are tried with just the machine type,
1277 not the version. This is used for finding as, ld, etc. */
1278 if (just_machine_suffix && pl->require_machine_suffix == 2)
1280 strcpy (temp, pl->prefix);
1281 strcat (temp, just_machine_suffix);
1282 strcat (temp, name);
1283 if (access (temp, mode) == 0)
1285 if (pl->used_flag_ptr != 0)
1286 *pl->used_flag_ptr = 1;
1289 /* Some systems have a suffix for executable files.
1290 So try appending that. */
1291 if (file_suffix[0] != 0)
1293 strcat (temp, file_suffix);
1294 if (access (temp, mode) == 0)
1296 if (pl->used_flag_ptr != 0)
1297 *pl->used_flag_ptr = 1;
1302 /* Certain prefixes can't be used without the machine suffix
1303 when the machine or version is explicitly specified. */
1304 if (!pl->require_machine_suffix)
1306 strcpy (temp, pl->prefix);
1307 strcat (temp, name);
1308 if (access (temp, mode) == 0)
1310 if (pl->used_flag_ptr != 0)
1311 *pl->used_flag_ptr = 1;
1314 /* Some systems have a suffix for executable files.
1315 So try appending that. */
1316 if (file_suffix[0] != 0)
1318 strcat (temp, file_suffix);
1319 if (access (temp, mode) == 0)
1321 if (pl->used_flag_ptr != 0)
1322 *pl->used_flag_ptr = 1;
1333 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1334 at the start of the list, otherwise it goes at the end.
1336 If WARN is nonzero, we will warn if no file is found
1337 through this prefix. WARN should point to an int
1338 which will be set to 1 if this entry is used.
1340 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1341 the complete value of machine_suffix.
1342 2 means try both machine_suffix and just_machine_suffix. */
1345 add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1346 struct path_prefix *pprefix;
1349 int require_machine_suffix;
1352 struct prefix_list *pl, **prev;
1355 if (!first && pprefix->plist)
1357 for (pl = pprefix->plist; pl->next; pl = pl->next)
1362 prev = &pprefix->plist;
1364 /* Keep track of the longest prefix */
1366 len = strlen (prefix);
1367 if (len > pprefix->max_len)
1368 pprefix->max_len = len;
1370 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1371 pl->prefix = save_string (prefix, len);
1372 pl->require_machine_suffix = require_machine_suffix;
1373 pl->used_flag_ptr = warn;
1380 pl->next = (struct prefix_list *) 0;
1384 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1387 unused_prefix_warnings (pprefix)
1388 struct path_prefix *pprefix;
1390 struct prefix_list *pl = pprefix->plist;
1394 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1396 error ("file path prefix `%s' never used",
1398 /* Prevent duplicate warnings. */
1399 *pl->used_flag_ptr = 1;
1405 /* Get rid of all prefixes built up so far in *PLISTP. */
1408 free_path_prefix (pprefix)
1409 struct path_prefix *pprefix;
1411 struct prefix_list *pl = pprefix->plist;
1412 struct prefix_list *temp;
1418 free (temp->prefix);
1419 free ((char *) temp);
1421 pprefix->plist = (struct prefix_list *) 0;
1424 /* stdin file number. */
1425 #define STDIN_FILE_NO 0
1427 /* stdout file number. */
1428 #define STDOUT_FILE_NO 1
1430 /* value of `pipe': port index for reading. */
1433 /* value of `pipe': port index for writing. */
1434 #define WRITE_PORT 1
1436 /* Pipe waiting from last process, to be used as input for the next one.
1437 Value is STDIN_FILE_NO if no pipe is waiting
1438 (i.e. the next command is the first of a group). */
1440 static int last_pipe_input;
1442 /* Fork one piped subcommand. FUNC is the system call to use
1443 (either execv or execvp). ARGV is the arg vector to use.
1444 NOT_LAST is nonzero if this is not the last subcommand
1445 (i.e. its output should be piped to the next one.) */
1450 /* Declare these to avoid compilation error. They won't be called. */
1451 int execv(const char *a, const char **b){}
1452 int execvp(const char *a, const char **b){}
1455 pexecute (search_flag, program, argv, not_last)
1465 scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6);
1466 sprintf (scmd, "%s @%s.gp", program, temp_filename);
1467 argfile = fopen (scmd+strlen (program) + 2, "w");
1469 pfatal_with_name (scmd + strlen (program) + 2);
1471 for (i=1; argv[i]; i++)
1474 for (cp = argv[i]; *cp; cp++)
1476 if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
1477 fputc ('\\', argfile);
1478 fputc (*cp, argfile);
1480 fputc ('\n', argfile);
1486 remove (scmd + strlen (program) + 2);
1490 #else /* not __MSDOS__ */
1493 pexecute (search_flag, program, argv, not_last)
1499 int (*func)() = (search_flag ? execv : execvp);
1502 int input_desc = last_pipe_input;
1503 int output_desc = STDOUT_FILE_NO;
1504 int retries, sleep_interval;
1506 /* If this isn't the last process, make a pipe for its output,
1507 and record it as waiting to be the input to the next process. */
1511 if (pipe (pdes) < 0)
1512 pfatal_with_name ("pipe");
1513 output_desc = pdes[WRITE_PORT];
1514 last_pipe_input = pdes[READ_PORT];
1517 last_pipe_input = STDIN_FILE_NO;
1519 /* Fork a subprocess; wait and retry if it fails. */
1521 for (retries = 0; retries < 4; retries++)
1526 sleep (sleep_interval);
1527 sleep_interval *= 2;
1534 pfatal_with_name ("fork");
1536 pfatal_with_name ("vfork");
1542 /* Move the input and output pipes into place, if nec. */
1543 if (input_desc != STDIN_FILE_NO)
1545 close (STDIN_FILE_NO);
1549 if (output_desc != STDOUT_FILE_NO)
1551 close (STDOUT_FILE_NO);
1553 close (output_desc);
1556 /* Close the parent's descs that aren't wanted here. */
1557 if (last_pipe_input != STDIN_FILE_NO)
1558 close (last_pipe_input);
1560 /* Exec the program. */
1561 (*func) (program, argv);
1562 perror_exec (program);
1568 /* In the parent, after forking.
1569 Close the descriptors that we made for this child. */
1570 if (input_desc != STDIN_FILE_NO)
1572 if (output_desc != STDOUT_FILE_NO)
1573 close (output_desc);
1575 /* Return child's process number. */
1580 #endif /* not __MSDOS__ */
1584 pexecute (search_flag, program, argv, not_last)
1590 return (search_flag ? spawnv : spawnvp) (1, program, argv);
1592 #endif /* not OS2 */
1594 /* Execute the command specified by the arguments on the current line of spec.
1595 When using pipes, this includes several piped-together commands
1596 with `|' between them.
1598 Return 0 if successful, -1 if failed. */
1604 int n_commands; /* # of command. */
1608 char *prog; /* program name. */
1609 char **argv; /* vector of args. */
1610 int pid; /* pid of process for this command. */
1613 struct command *commands; /* each command buffer with above info. */
1615 /* Count # of piped commands. */
1616 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1617 if (strcmp (argbuf[i], "|") == 0)
1620 /* Get storage for each command. */
1622 = (struct command *) alloca (n_commands * sizeof (struct command));
1624 /* Split argbuf into its separate piped processes,
1625 and record info about each one.
1626 Also search for the programs that are to be run. */
1628 commands[0].prog = argbuf[0]; /* first command. */
1629 commands[0].argv = &argbuf[0];
1630 string = find_a_file (&exec_prefix, commands[0].prog, X_OK);
1632 commands[0].argv[0] = string;
1634 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1635 if (strcmp (argbuf[i], "|") == 0)
1636 { /* each command. */
1638 fatal ("-pipe not supported under MS-DOS");
1640 argbuf[i] = 0; /* termination of command args. */
1641 commands[n_commands].prog = argbuf[i + 1];
1642 commands[n_commands].argv = &argbuf[i + 1];
1643 string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK);
1645 commands[n_commands].argv[0] = string;
1649 argbuf[argbuf_index] = 0;
1651 /* If -v, print what we are about to do, and maybe query. */
1655 /* Print each piped command as a separate line. */
1656 for (i = 0; i < n_commands ; i++)
1660 for (j = commands[i].argv; *j; j++)
1661 fprintf (stderr, " %s", *j);
1663 /* Print a pipe symbol after all but the last command. */
1664 if (i + 1 != n_commands)
1665 fprintf (stderr, " |");
1666 fprintf (stderr, "\n");
1670 fprintf (stderr, "\nGo ahead? (y or n) ");
1674 while (getchar () != '\n') ;
1675 if (i != 'y' && i != 'Y')
1680 /* Run each piped subprocess. */
1682 last_pipe_input = STDIN_FILE_NO;
1683 for (i = 0; i < n_commands; i++)
1685 char *string = commands[i].argv[0];
1687 commands[i].pid = pexecute (string != commands[i].prog,
1688 string, commands[i].argv,
1689 i + 1 < n_commands);
1691 if (string != commands[i].prog)
1697 /* Wait for all the subprocesses to finish.
1698 We don't care what order they finish in;
1699 we know that N_COMMANDS waits will get them all. */
1704 for (i = 0; i < n_commands; i++)
1711 status = pid = commands[i].pid;
1713 pid = wait (&status);
1721 for (j = 0; j < n_commands; j++)
1722 if (commands[j].pid == pid)
1723 prog = commands[j].prog;
1725 if ((status & 0x7F) != 0)
1726 fatal ("Internal compiler error: program %s got fatal signal %d",
1727 prog, (status & 0x7F));
1728 if (((status & 0xFF00) >> 8) >= MIN_FATAL_STATUS)
1736 /* Find all the switches given to us
1737 and make a vector describing them.
1738 The elements of the vector are strings, one per switch given.
1739 If a switch uses following arguments, then the `part1' field
1740 is the switch itself and the `args' field
1741 is a null-terminated vector containing the following arguments.
1742 The `valid' field is nonzero if any spec has looked at this switch;
1743 if it remains zero at the end of the run, it must be meaningless. */
1752 static struct switchstr *switches;
1754 static int n_switches;
1762 /* Also a vector of input files specified. */
1764 static struct infile *infiles;
1766 static int n_infiles;
1768 /* And a vector of corresponding output files is made up later. */
1770 static char **outfiles;
1772 /* Create the vector `switches' and its contents.
1773 Store its length in `n_switches'. */
1776 process_command (argc, argv)
1782 char *spec_lang = 0;
1783 int last_language_n_infiles;
1785 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
1789 spec_version = version_string;
1791 /* Set up the default search paths. */
1793 if (gcc_exec_prefix)
1795 add_prefix (&exec_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
1796 add_prefix (&startfile_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
1799 /* COMPILER_PATH and LIBRARY_PATH have values
1800 that are lists of directory names with colons. */
1802 temp = getenv ("COMPILER_PATH");
1805 char *startp, *endp;
1806 char *nstore = (char *) alloca (strlen (temp) + 3);
1808 startp = endp = temp;
1811 if (*endp == PATH_SEPARATOR || *endp == 0)
1813 strncpy (nstore, startp, endp-startp);
1816 strcpy (nstore, "./");
1818 else if (endp[-1] != '/')
1820 nstore[endp-startp] = '/';
1821 nstore[endp-startp+1] = 0;
1824 nstore[endp-startp] = 0;
1825 add_prefix (&exec_prefix, nstore, 0, 0, NULL_PTR);
1828 endp = startp = endp + 1;
1835 temp = getenv ("LIBRARY_PATH");
1838 char *startp, *endp;
1839 char *nstore = (char *) alloca (strlen (temp) + 3);
1841 startp = endp = temp;
1844 if (*endp == PATH_SEPARATOR || *endp == 0)
1846 strncpy (nstore, startp, endp-startp);
1849 strcpy (nstore, "./");
1851 else if (endp[-1] != '/')
1853 nstore[endp-startp] = '/';
1854 nstore[endp-startp+1] = 0;
1857 nstore[endp-startp] = 0;
1858 add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
1859 /* Make separate list of dirs that came from LIBRARY_PATH. */
1860 add_prefix (&library_prefix, nstore, 0, 0, NULL_PTR);
1863 endp = startp = endp + 1;
1870 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
1871 temp = getenv ("LPATH");
1874 char *startp, *endp;
1875 char *nstore = (char *) alloca (strlen (temp) + 3);
1877 startp = endp = temp;
1880 if (*endp == PATH_SEPARATOR || *endp == 0)
1882 strncpy (nstore, startp, endp-startp);
1885 strcpy (nstore, "./");
1887 else if (endp[-1] != '/')
1889 nstore[endp-startp] = '/';
1890 nstore[endp-startp+1] = 0;
1893 nstore[endp-startp] = 0;
1894 add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
1895 /* Make separate list of dirs that came from LIBRARY_PATH. */
1896 add_prefix (&library_prefix, nstore, 0, 0, NULL_PTR);
1899 endp = startp = endp + 1;
1906 /* Scan argv twice. Here, the first time, just count how many switches
1907 there will be in their vector, and how many input files in theirs.
1908 Here we also parse the switches that cc itself uses (e.g. -v). */
1910 for (i = 1; i < argc; i++)
1912 if (! strcmp (argv[i], "-dumpspecs"))
1914 printf ("*asm:\n%s\n\n", asm_spec);
1915 printf ("*asm_final:\n%s\n\n", asm_final_spec);
1916 printf ("*cpp:\n%s\n\n", cpp_spec);
1917 printf ("*cc1:\n%s\n\n", cc1_spec);
1918 printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
1919 printf ("*endfile:\n%s\n\n", endfile_spec);
1920 printf ("*link:\n%s\n\n", link_spec);
1921 printf ("*lib:\n%s\n\n", lib_spec);
1922 printf ("*startfile:\n%s\n\n", startfile_spec);
1923 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
1924 printf ("*signed_char:\n%s\n\n", signed_char_spec);
1925 printf ("*predefines:\n%s\n\n", cpp_predefines);
1926 printf ("*cross_compile:\n%d\n\n", cross_compile);
1930 else if (! strcmp (argv[i], "-dumpversion"))
1932 printf ("%s\n", version_string);
1935 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
1937 print_libgcc_file_name = 1;
1939 else if (! strcmp (argv[i], "-Xlinker"))
1941 /* Pass the argument of this option to the linker when we link. */
1944 fatal ("argument to `-Xlinker' is missing");
1947 if (!linker_options)
1949 = (char **) xmalloc (n_linker_options * sizeof (char **));
1952 = (char **) xrealloc (linker_options,
1953 n_linker_options * sizeof (char **));
1955 linker_options[n_linker_options - 1] = argv[++i];
1957 else if (! strncmp (argv[i], "-Wl,", 4))
1960 /* Pass the rest of this option to the linker when we link. */
1963 if (!linker_options)
1965 = (char **) xmalloc (n_linker_options * sizeof (char **));
1968 = (char **) xrealloc (linker_options,
1969 n_linker_options * sizeof (char **));
1971 /* Split the argument at commas. */
1973 for (j = 4; argv[i][j]; j++)
1974 if (argv[i][j] == ',')
1976 linker_options[n_linker_options - 1]
1977 = save_string (argv[i] + prev, j - prev);
1980 = (char **) xrealloc (linker_options,
1981 n_linker_options * sizeof (char **));
1984 /* Record the part after the last comma. */
1985 linker_options[n_linker_options - 1] = argv[i] + prev;
1987 else if (! strncmp (argv[i], "-Wa,", 4))
1990 /* Pass the rest of this option to the assembler. */
1992 n_assembler_options++;
1993 if (!assembler_options)
1995 = (char **) xmalloc (n_assembler_options * sizeof (char **));
1998 = (char **) xrealloc (assembler_options,
1999 n_assembler_options * sizeof (char **));
2001 /* Split the argument at commas. */
2003 for (j = 4; argv[i][j]; j++)
2004 if (argv[i][j] == ',')
2006 assembler_options[n_assembler_options - 1]
2007 = save_string (argv[i] + prev, j - prev);
2008 n_assembler_options++;
2010 = (char **) xrealloc (assembler_options,
2011 n_assembler_options * sizeof (char **));
2014 /* Record the part after the last comma. */
2015 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2017 else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
2019 register char *p = &argv[i][1];
2020 register int c = *p;
2025 if (p[1] == 0 && i + 1 == argc)
2026 fatal ("argument to `-b' is missing");
2028 spec_machine = argv[++i];
2030 spec_machine = p + 1;
2035 int *temp = (int *) xmalloc (sizeof (int));
2037 if (p[1] == 0 && i + 1 == argc)
2038 fatal ("argument to `-B' is missing");
2043 add_prefix (&exec_prefix, value, 1, 0, temp);
2044 add_prefix (&startfile_prefix, value, 1, 0, temp);
2048 case 'v': /* Print our subcommands and print versions. */
2050 /* If they do anything other than exactly `-v', don't set
2051 verbose_flag; rather, continue on to give the error. */
2058 if (p[1] == 0 && i + 1 == argc)
2059 fatal ("argument to `-V' is missing");
2061 spec_version = argv[++i];
2063 spec_version = p + 1;
2067 if (!strcmp (p, "save-temps"))
2069 save_temps_flag = 1;
2076 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2077 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2078 else if (WORD_SWITCH_TAKES_ARG (p))
2079 i += WORD_SWITCH_TAKES_ARG (p);
2086 /* Set up the search paths before we go looking for config files. */
2088 /* These come before the md prefixes so that we will find gcc's subcommands
2089 (such as cpp) rather than those of the host system. */
2090 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2091 as well as trying the machine and the version. */
2092 add_prefix (&exec_prefix, standard_exec_prefix, 0, 2, NULL_PTR);
2093 add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 2, NULL_PTR);
2095 add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, NULL_PTR);
2096 add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, NULL_PTR);
2098 /* More prefixes are enabled in main, after we read the specs file
2099 and determine whether this is cross-compilation or not. */
2102 /* Then create the space for the vectors and scan again. */
2104 switches = ((struct switchstr *)
2105 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2106 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2109 last_language_n_infiles = -1;
2111 /* This, time, copy the text of each switch and store a pointer
2112 to the copy in the vector of switches.
2113 Store all the infiles in their vector. */
2115 for (i = 1; i < argc; i++)
2117 /* Just skip the switches that were handled by the preceding loop. */
2118 if (!strcmp (argv[i], "-Xlinker"))
2120 else if (! strncmp (argv[i], "-Wl,", 4))
2122 else if (! strncmp (argv[i], "-Wa,", 4))
2124 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2126 else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
2128 register char *p = &argv[i][1];
2129 register int c = *p;
2131 if (c == 'B' || c == 'b' || c == 'V')
2133 /* Skip a separate arg, if any. */
2140 if (p[1] == 0 && i + 1 == argc)
2141 fatal ("argument to `-x' is missing");
2143 spec_lang = argv[++i];
2146 if (! strcmp (spec_lang, "none"))
2147 /* Suppress the warning if -xnone comes after the last input file,
2148 because alternate command interfaces like g++ might find it
2149 useful to place -xnone after each input file. */
2152 last_language_n_infiles = n_infiles;
2155 switches[n_switches].part1 = p;
2156 /* Deal with option arguments in separate argv elements. */
2157 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2158 || WORD_SWITCH_TAKES_ARG (p)) {
2160 int n_args = WORD_SWITCH_TAKES_ARG (p);
2163 /* Count only the option arguments in separate argv elements. */
2164 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2166 switches[n_switches].args
2167 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2169 switches[n_switches].args[j++] = argv[++i];
2170 /* Null-terminate the vector. */
2171 switches[n_switches].args[j] = 0;
2172 } else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L')) {
2173 /* On some systems, ld cannot handle -o or -L without space.
2174 So split the -o or -L from its argument. */
2175 switches[n_switches].part1 = (c == 'o' ? "o" : "L");
2176 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2177 switches[n_switches].args[0] = xmalloc (strlen (p));
2178 strcpy (switches[n_switches].args[0], &p[1]);
2179 switches[n_switches].args[1] = 0;
2181 switches[n_switches].args = 0;
2182 switches[n_switches].valid = 0;
2183 /* This is always valid, since gcc.c itself understands it. */
2184 if (!strcmp (p, "save-temps"))
2185 switches[n_switches].valid = 1;
2190 infiles[n_infiles].language = spec_lang;
2191 infiles[n_infiles++].name = argv[i];
2195 if (n_infiles == last_language_n_infiles)
2196 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2198 switches[n_switches].part1 = 0;
2199 infiles[n_infiles].name = 0;
2201 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2202 if (gcc_exec_prefix)
2204 temp = (char *) xmalloc (strlen (gcc_exec_prefix) + strlen (spec_version)
2205 + strlen (spec_machine) + 3);
2206 strcpy (temp, gcc_exec_prefix);
2207 strcat (temp, spec_machine);
2209 strcat (temp, spec_version);
2211 gcc_exec_prefix = temp;
2215 /* Process a spec string, accumulating and running commands. */
2217 /* These variables describe the input file name.
2218 input_file_number is the index on outfiles of this file,
2219 so that the output file name can be stored for later use by %o.
2220 input_basename is the start of the part of the input file
2221 sans all directory names, and basename_length is the number
2222 of characters starting there excluding the suffix .c or whatever. */
2224 static char *input_filename;
2225 static int input_file_number;
2226 static int input_filename_length;
2227 static int basename_length;
2228 static char *input_basename;
2229 static char *input_suffix;
2231 /* These are variables used within do_spec and do_spec_1. */
2233 /* Nonzero if an arg has been started and not yet terminated
2234 (with space, tab or newline). */
2235 static int arg_going;
2237 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2238 is a temporary file name. */
2239 static int delete_this_arg;
2241 /* Nonzero means %w has been seen; the next arg to be terminated
2242 is the output file name of this compilation. */
2243 static int this_is_output_file;
2245 /* Nonzero means %s has been seen; the next arg to be terminated
2246 is the name of a library file and we should try the standard
2247 search dirs for it. */
2248 static int this_is_library_file;
2250 /* Process the spec SPEC and run the commands specified therein.
2251 Returns 0 if the spec is successfully processed; -1 if failed. */
2261 delete_this_arg = 0;
2262 this_is_output_file = 0;
2263 this_is_library_file = 0;
2265 value = do_spec_1 (spec, 0, NULL_PTR);
2267 /* Force out any unfinished command.
2268 If -pipe, this forces out the last command if it ended in `|'. */
2271 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2274 if (argbuf_index > 0)
2281 /* Process the sub-spec SPEC as a portion of a larger spec.
2282 This is like processing a whole spec except that we do
2283 not initialize at the beginning and we do not supply a
2284 newline by default at the end.
2285 INSWITCH nonzero means don't process %-sequences in SPEC;
2286 in this case, % is treated as an ordinary character.
2287 This is used while substituting switches.
2288 INSWITCH nonzero also causes SPC not to terminate an argument.
2290 Value is zero unless a line was finished
2291 and the command on that line reported an error. */
2294 do_spec_1 (spec, inswitch, soft_matched_part)
2297 char *soft_matched_part;
2299 register char *p = spec;
2305 /* If substituting a switch, treat all chars like letters.
2306 Otherwise, NL, SPC, TAB and % are special. */
2307 switch (inswitch ? 'a' : c)
2310 /* End of line: finish any pending argument,
2311 then run the pending command if one has been started. */
2314 obstack_1grow (&obstack, 0);
2315 string = obstack_finish (&obstack);
2316 if (this_is_library_file)
2317 string = find_file (string);
2318 store_arg (string, delete_this_arg, this_is_output_file);
2319 if (this_is_output_file)
2320 outfiles[input_file_number] = string;
2324 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2327 for (i = 0; i < n_switches; i++)
2328 if (!strcmp (switches[i].part1, "pipe"))
2331 /* A `|' before the newline means use a pipe here,
2332 but only if -pipe was specified.
2333 Otherwise, execute now and don't pass the `|' as an arg. */
2336 switches[i].valid = 1;
2343 if (argbuf_index > 0)
2345 int value = execute ();
2349 /* Reinitialize for a new command, and for a new argument. */
2352 delete_this_arg = 0;
2353 this_is_output_file = 0;
2354 this_is_library_file = 0;
2358 /* End any pending argument. */
2361 obstack_1grow (&obstack, 0);
2362 string = obstack_finish (&obstack);
2363 if (this_is_library_file)
2364 string = find_file (string);
2365 store_arg (string, delete_this_arg, this_is_output_file);
2366 if (this_is_output_file)
2367 outfiles[input_file_number] = string;
2371 obstack_1grow (&obstack, c);
2377 /* Space or tab ends an argument if one is pending. */
2380 obstack_1grow (&obstack, 0);
2381 string = obstack_finish (&obstack);
2382 if (this_is_library_file)
2383 string = find_file (string);
2384 store_arg (string, delete_this_arg, this_is_output_file);
2385 if (this_is_output_file)
2386 outfiles[input_file_number] = string;
2388 /* Reinitialize for a new argument. */
2390 delete_this_arg = 0;
2391 this_is_output_file = 0;
2392 this_is_library_file = 0;
2399 fatal ("Invalid specification! Bug in cc.");
2402 obstack_grow (&obstack, input_basename, basename_length);
2407 delete_this_arg = 2;
2410 /* Dump out the directories specified with LIBRARY_PATH,
2411 followed by the absolute directories
2412 that we search for startfiles. */
2414 for (i = 0; i < 2; i++)
2416 struct prefix_list *pl
2417 = (i == 0 ? library_prefix.plist : startfile_prefix.plist);
2419 char *buffer = (char *) xmalloc (bufsize);
2422 for (; pl; pl = pl->next)
2424 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2425 /* Used on systems which record the specified -L dirs
2426 and use them to search for dynamic linking. */
2427 /* Relative directories always come from -B,
2428 and it is better not to use them for searching
2429 at run time. In particular, stage1 loses */
2430 if (pl->prefix[0] != '/')
2435 if (is_linker_dir (pl->prefix, machine_suffix))
2437 do_spec_1 ("-L", 0, NULL_PTR);
2438 #ifdef SPACE_AFTER_L_OPTION
2439 do_spec_1 (" ", 0, NULL_PTR);
2441 do_spec_1 (pl->prefix, 1, NULL_PTR);
2442 /* Remove slash from machine_suffix. */
2443 if (strlen (machine_suffix) >= bufsize)
2444 bufsize = strlen (machine_suffix) * 2 + 1;
2445 buffer = (char *) xrealloc (buffer, bufsize);
2446 strcpy (buffer, machine_suffix);
2447 idx = strlen (buffer);
2448 if (buffer[idx - 1] == '/')
2449 buffer[idx - 1] = 0;
2450 do_spec_1 (buffer, 1, NULL_PTR);
2451 /* Make this a separate argument. */
2452 do_spec_1 (" ", 0, NULL_PTR);
2455 if (!pl->require_machine_suffix)
2457 if (is_linker_dir (pl->prefix, ""))
2459 do_spec_1 ("-L", 0, NULL_PTR);
2460 #ifdef SPACE_AFTER_L_OPTION
2461 do_spec_1 (" ", 0, NULL_PTR);
2463 /* Remove slash from pl->prefix. */
2464 if (strlen (pl->prefix) >= bufsize)
2465 bufsize = strlen (pl->prefix) * 2 + 1;
2466 buffer = (char *) xrealloc (buffer, bufsize);
2467 strcpy (buffer, pl->prefix);
2468 idx = strlen (buffer);
2469 if (buffer[idx - 1] == '/')
2470 buffer[idx - 1] = 0;
2471 do_spec_1 (buffer, 1, NULL_PTR);
2472 /* Make this a separate argument. */
2473 do_spec_1 (" ", 0, NULL_PTR);
2482 /* {...:%efoo} means report an error with `foo' as error message
2483 and don't execute any more commands for this file. */
2487 while (*p != 0 && *p != '\n') p++;
2488 buf = (char *) alloca (p - q + 1);
2489 strncpy (buf, q, p - q);
2499 if (save_temps_flag)
2500 obstack_grow (&obstack, input_basename, basename_length);
2503 obstack_grow (&obstack, temp_filename, temp_filename_length);
2504 if (c == 'u' || c == 'U')
2510 sprintf (buff, "%d", unique);
2511 obstack_grow (&obstack, buff, strlen (buff));
2513 delete_this_arg = 1;
2519 obstack_grow (&obstack, input_filename, input_filename_length);
2524 if (gcc_exec_prefix)
2526 do_spec_1 ("-iprefix", 1, NULL_PTR);
2527 /* Make this a separate argument. */
2528 do_spec_1 (" ", 0, NULL_PTR);
2529 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
2530 do_spec_1 (" ", 0, NULL_PTR);
2537 for (f = 0; f < n_infiles; f++)
2538 store_arg (outfiles[f], 0, 0);
2543 this_is_library_file = 1;
2547 this_is_output_file = 1;
2552 int index = argbuf_index;
2553 /* Handle the {...} following the %W. */
2556 p = handle_braces (p + 1);
2559 /* If any args were output, mark the last one for deletion
2561 if (argbuf_index != index)
2562 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
2566 /* %x{OPTION} records OPTION for %X to output. */
2572 /* Skip past the option value and make a copy. */
2577 string = save_string (p1 + 1, p - p1 - 2);
2579 /* See if we already recorded this option. */
2580 for (i = 0; i < n_linker_options; i++)
2581 if (! strcmp (string, linker_options[i]))
2587 /* This option is new; add it. */
2589 if (!linker_options)
2591 = (char **) xmalloc (n_linker_options * sizeof (char **));
2594 = (char **) xrealloc (linker_options,
2595 n_linker_options * sizeof (char **));
2597 linker_options[n_linker_options - 1] = string;
2601 /* Dump out the options accumulated previously using %x,
2602 -Xlinker and -Wl,. */
2604 for (i = 0; i < n_linker_options; i++)
2606 do_spec_1 (linker_options[i], 1, NULL_PTR);
2607 /* Make each accumulated option a separate argument. */
2608 do_spec_1 (" ", 0, NULL_PTR);
2612 /* Dump out the options accumulated previously using -Wa,. */
2614 for (i = 0; i < n_assembler_options; i++)
2616 do_spec_1 (assembler_options[i], 1, NULL_PTR);
2617 /* Make each accumulated option a separate argument. */
2618 do_spec_1 (" ", 0, NULL_PTR);
2622 /* Here are digits and numbers that just process
2623 a certain constant string as a spec.
2624 /* Here are digits and numbers that just process
2625 a certain constant string as a spec. */
2628 do_spec_1 (cc1_spec, 0, NULL_PTR);
2632 do_spec_1 (cc1plus_spec, 0, NULL_PTR);
2636 do_spec_1 (asm_spec, 0, NULL_PTR);
2640 do_spec_1 (asm_final_spec, 0, NULL_PTR);
2644 do_spec_1 (signed_char_spec, 0, NULL_PTR);
2648 do_spec_1 (cpp_spec, 0, NULL_PTR);
2652 do_spec_1 (endfile_spec, 0, NULL_PTR);
2656 do_spec_1 (link_spec, 0, NULL_PTR);
2660 do_spec_1 (lib_spec, 0, NULL_PTR);
2665 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
2669 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
2673 if (! strncmp (y, "-D", 2))
2674 /* Copy the whole option. */
2675 while (*y && *y != ' ' && *y != '\t')
2677 else if (*y == ' ' || *y == '\t')
2678 /* Copy whitespace to the result. */
2680 /* Don't copy other options. */
2687 do_spec_1 (buf, 0, NULL_PTR);
2693 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
2697 /* Copy all of CPP_PREDEFINES into BUF,
2698 but put __ after every -D and at the end of each arg. */
2702 if (! strncmp (y, "-D", 2))
2709 if (strncmp (y, "__", 2))
2711 /* Stick __ at front of macro name. */
2714 /* Arrange to stick __ at the end as well. */
2718 /* Copy the macro name. */
2719 while (*y && *y != '=' && *y != ' ' && *y != '\t')
2728 /* Copy the value given, if any. */
2729 while (*y && *y != ' ' && *y != '\t')
2732 else if (*y == ' ' || *y == '\t')
2733 /* Copy whitespace to the result. */
2735 /* Don't copy -A options */
2741 /* Copy all of CPP_PREDEFINES into BUF,
2742 but put __ after every -D. */
2746 if (! strncmp (y, "-D", 2))
2751 if (strncmp (y, "__", 2))
2753 /* Stick __ at front of macro name. */
2758 /* Copy the macro name. */
2759 while (*y && *y != '=' && *y != ' ' && *y != '\t')
2762 /* Copy the value given, if any. */
2763 while (*y && *y != ' ' && *y != '\t')
2766 else if (*y == ' ' || *y == '\t')
2767 /* Copy whitespace to the result. */
2769 /* Don't copy -A options */
2775 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
2779 if (! strncmp (y, "-A", 2))
2780 /* Copy the whole option. */
2781 while (*y && *y != ' ' && *y != '\t')
2783 else if (*y == ' ' || *y == '\t')
2784 /* Copy whitespace to the result. */
2786 /* Don't copy other options. */
2793 do_spec_1 (buf, 0, NULL_PTR);
2798 do_spec_1 (startfile_spec, 0, NULL_PTR);
2801 /* Here we define characters other than letters and digits. */
2804 p = handle_braces (p);
2810 obstack_1grow (&obstack, '%');
2814 do_spec_1 (soft_matched_part, 1, NULL_PTR);
2815 do_spec_1 (" ", 0, NULL_PTR);
2818 /* Process a string found as the value of a spec given by name.
2819 This feature allows individual machine descriptions
2820 to add and use their own specs.
2821 %[...] modifies -D options the way %P does;
2822 %(...) uses the spec unmodified. */
2827 struct spec_list *sl;
2830 /* The string after the S/P is the name of a spec that is to be
2832 while (*p && *p != ')' && *p != ']')
2835 /* See if it's in the list */
2836 for (len = p - name, sl = specs; sl; sl = sl->next)
2837 if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
2846 do_spec_1 (name, 0, NULL_PTR);
2849 char *x = (char *) alloca (strlen (name) * 2 + 1);
2853 /* Copy all of NAME into BUF, but put __ after
2854 every -D and at the end of each arg, */
2857 if (! strncmp (y, "-D", 2))
2865 else if (*y == ' ' || *y == 0)
2879 do_spec_1 (buf, 0, NULL_PTR);
2883 /* Discard the closing paren or bracket. */
2895 /* Backslash: treat next character as ordinary. */
2900 /* Ordinary character: put it into the current argument. */
2901 obstack_1grow (&obstack, c);
2905 return 0; /* End of string */
2908 /* Return 0 if we call do_spec_1 and that returns -1. */
2921 /* A `|' after the open-brace means,
2922 if the test fails, output a single minus sign rather than nothing.
2923 This is used in %{|!pipe:...}. */
2927 /* A `!' after the open-brace negates the condition:
2928 succeed if the specified switch is not present. */
2932 /* A `.' after the open-brace means test against the current suffix. */
2942 while (*p != ':' && *p != '}') p++;
2945 register int count = 1;
2963 int found = (input_suffix != 0
2964 && strlen (input_suffix) == p - filter
2965 && strncmp (input_suffix, filter, p - filter) == 0);
2971 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
2976 else if (p[-1] == '*' && p[0] == '}')
2978 /* Substitute all matching switches as separate args. */
2981 for (i = 0; i < n_switches; i++)
2982 if (!strncmp (switches[i].part1, filter, p - filter))
2987 /* Test for presence of the specified switch. */
2991 /* If name specified ends in *, as in {x*:...},
2992 check for %* and handle that case. */
2993 if (p[-1] == '*' && !negate)
2998 /* First see whether we have %*. */
3002 if (*r == '%' && r[1] == '*')
3006 /* If we do, handle that case. */
3009 /* Substitute all matching switches as separate args.
3010 But do this by substituting for %*
3011 in the text that follows the colon. */
3013 unsigned hard_match_len = p - filter - 1;
3014 char *string = save_string (p + 1, q - p - 2);
3016 for (i = 0; i < n_switches; i++)
3017 if (!strncmp (switches[i].part1, filter, hard_match_len))
3019 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
3020 /* Pass any arguments this switch has. */
3028 /* If name specified ends in *, as in {x*:...},
3029 check for presence of any switch name starting with x. */
3032 for (i = 0; i < n_switches; i++)
3034 unsigned hard_match_len = p - filter - 1;
3036 if (!strncmp (switches[i].part1, filter, hard_match_len))
3038 switches[i].valid = 1;
3043 /* Otherwise, check for presence of exact name specified. */
3046 for (i = 0; i < n_switches; i++)
3048 if (!strncmp (switches[i].part1, filter, p - filter)
3049 && switches[i].part1[p - filter] == 0)
3051 switches[i].valid = 1;
3058 /* If it is as desired (present for %{s...}, absent for %{-s...})
3059 then substitute either the switch or the specified
3060 conditional text. */
3061 if (present != negate)
3069 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3075 /* Here if a %{|...} conditional fails: output a minus sign,
3076 which means "standard output" or "standard input". */
3077 do_spec_1 ("-", 0, NULL_PTR);
3084 /* Pass a switch to the current accumulating command
3085 in the same form that we received it.
3086 SWITCHNUM identifies the switch; it is an index into
3087 the vector of switches gcc received, which is `switches'.
3088 This cannot fail since it never finishes a command line.
3090 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
3093 give_switch (switchnum, omit_first_word)
3095 int omit_first_word;
3097 if (!omit_first_word)
3099 do_spec_1 ("-", 0, NULL_PTR);
3100 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
3102 do_spec_1 (" ", 0, NULL_PTR);
3103 if (switches[switchnum].args != 0)
3106 for (p = switches[switchnum].args; *p; p++)
3108 do_spec_1 (*p, 1, NULL_PTR);
3109 do_spec_1 (" ", 0, NULL_PTR);
3112 switches[switchnum].valid = 1;
3115 /* Search for a file named NAME trying various prefixes including the
3116 user's -B prefix and some standard ones.
3117 Return the absolute file name found. If nothing is found, return NAME. */
3125 newname = find_a_file (&startfile_prefix, name, R_OK);
3126 return newname ? newname : name;
3129 /* Determine whether a -L option is relevant. Not required for certain
3130 fixed names and for directories that don't exist. */
3133 is_linker_dir (path1, path2)
3137 int len1 = strlen (path1);
3138 int len2 = strlen (path2);
3139 char *path = (char *) alloca (3 + len1 + len2);
3143 /* Construct the path from the two parts. Ensure the string ends with "/.".
3144 The resulting path will be a directory even if the given path is a
3146 bcopy (path1, path, len1);
3147 bcopy (path2, path + len1, len2);
3148 cp = path + len1 + len2;
3154 /* Exclude directories that the linker is known to search. */
3155 if ((cp - path == 6 && strcmp (path, "/lib/.") == 0)
3156 || (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0))
3159 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
3162 /* On fatal signals, delete all the temporary files. */
3165 fatal_error (signum)
3168 signal (signum, SIG_DFL);
3169 delete_failure_queue ();
3170 delete_temp_files ();
3171 /* Get the same signal again, this time not handled,
3172 so its normal effect occurs. */
3173 kill (getpid (), signum);
3183 int error_count = 0;
3184 int linker_was_run = 0;
3185 char *explicit_link_files;
3188 programname = argv[0];
3190 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
3191 signal (SIGINT, fatal_error);
3192 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
3193 signal (SIGHUP, fatal_error);
3194 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
3195 signal (SIGTERM, fatal_error);
3197 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
3198 signal (SIGPIPE, fatal_error);
3202 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
3204 obstack_init (&obstack);
3206 /* Set up to remember the pathname of gcc and any options
3207 needed for collect. */
3208 obstack_init (&collect_obstack);
3209 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
3210 obstack_grow (&collect_obstack, programname, strlen (programname)+1);
3211 putenv (obstack_finish (&collect_obstack));
3213 /* Choose directory for temp files. */
3215 choose_temp_base ();
3217 /* Make a table of what switches there are (switches, n_switches).
3218 Make a table of specified input files (infiles, n_infiles).
3219 Decode switches that are handled locally. */
3221 process_command (argc, argv);
3223 /* Initialize the vector of specs to just the default.
3224 This means one element containing 0s, as a terminator. */
3226 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
3227 bcopy (default_compilers, compilers, sizeof default_compilers);
3228 n_compilers = n_default_compilers;
3230 /* Read specs from a file if there is one. */
3232 machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", ""));
3233 just_machine_suffix = concat (spec_machine, "/", "");
3235 specs_file = find_a_file (&startfile_prefix, "specs", R_OK);
3236 /* Read the specs file unless it is a default one. */
3237 if (specs_file != 0 && strcmp (specs_file, "specs"))
3238 read_specs (specs_file);
3240 /* If not cross-compiling, look for startfiles in the standard places. */
3241 /* The fact that these are done here, after reading the specs file,
3242 means that it cannot be found in these directories.
3243 But that's okay. It should never be there anyway. */
3246 #ifdef MD_EXEC_PREFIX
3247 add_prefix (&exec_prefix, md_exec_prefix, 0, 0, NULL_PTR);
3248 add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, NULL_PTR);
3251 #ifdef MD_STARTFILE_PREFIX
3252 add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, NULL_PTR);
3255 #ifdef MD_STARTFILE_PREFIX_1
3256 add_prefix (&startfile_prefix, md_startfile_prefix_1, 0, 0, NULL_PTR);
3259 add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0,
3261 add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0,
3263 add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0,
3265 #if 0 /* Can cause surprises, and one can use -B./ instead. */
3266 add_prefix (&startfile_prefix, "./", 0, 1, NULL_PTR);
3270 /* Now we have the specs.
3271 Set the `valid' bits for switches that match anything in any spec. */
3273 validate_all_switches ();
3275 /* Warn about any switches that no pass was interested in. */
3277 for (i = 0; i < n_switches; i++)
3278 if (! switches[i].valid)
3279 error ("unrecognized option `-%s'", switches[i].part1);
3281 if (print_libgcc_file_name)
3283 printf ("%s\n", find_file ("libgcc.a"));
3287 /* Obey some of the options. */
3291 fprintf (stderr, "gcc version %s\n", version_string);
3297 fatal ("No input files specified.");
3299 /* Make a place to record the compiler output file names
3300 that correspond to the input files. */
3302 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
3303 bzero (outfiles, n_infiles * sizeof (char *));
3305 /* Record which files were specified explicitly as link input. */
3307 explicit_link_files = xmalloc (n_infiles);
3308 bzero (explicit_link_files, n_infiles);
3310 for (i = 0; i < n_infiles; i++)
3312 register struct compiler *cp = 0;
3313 int this_file_error = 0;
3315 /* Tell do_spec what to substitute for %i. */
3317 input_filename = infiles[i].name;
3318 input_filename_length = strlen (input_filename);
3319 input_file_number = i;
3321 /* Use the same thing in %o, unless cp->spec says otherwise. */
3323 outfiles[i] = input_filename;
3325 /* Figure out which compiler from the file's suffix. */
3327 cp = lookup_compiler (infiles[i].name, input_filename_length,
3328 infiles[i].language);
3332 /* Ok, we found an applicable compiler. Run its spec. */
3333 /* First say how much of input_filename to substitute for %b */
3336 input_basename = input_filename;
3337 for (p = input_filename; *p; p++)
3339 input_basename = p + 1;
3341 /* Find a suffix starting with the last period,
3342 and set basename_length to exclude that suffix. */
3343 basename_length = strlen (input_basename);
3344 p = input_basename + basename_length;
3345 while (p != input_basename && *p != '.') --p;
3346 if (*p == '.' && p != input_basename)
3348 basename_length = p - input_basename;
3349 input_suffix = p + 1;
3354 value = do_spec (cp->spec);
3356 this_file_error = 1;
3359 /* If this file's name does not contain a recognized suffix,
3360 record it as explicit linker input. */
3363 explicit_link_files[i] = 1;
3365 /* Clear the delete-on-failure queue, deleting the files in it
3366 if this compilation failed. */
3368 if (this_file_error)
3370 delete_failure_queue ();
3373 /* If this compilation succeeded, don't delete those files later. */
3374 clear_failure_queue ();
3377 /* Run ld to link all the compiler output files. */
3379 if (error_count == 0)
3381 int tmp = execution_count;
3385 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
3387 putenv_from_prefixes (&exec_prefix, "COMPILER_PATH=");
3388 putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH=");
3390 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
3392 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
3393 sizeof ("COLLECT_GCC_OPTIONS=")-1);
3396 for (i = 0; i < n_switches; i++)
3400 obstack_grow (&collect_obstack, " ", 1);
3403 obstack_grow (&collect_obstack, "-", 1);
3404 obstack_grow (&collect_obstack, switches[i].part1,
3405 strlen (switches[i].part1));
3407 for (args = switches[i].args; args && *args; args++)
3409 obstack_grow (&collect_obstack, " ", 1);
3410 obstack_grow (&collect_obstack, *args, strlen (*args));
3413 obstack_grow (&collect_obstack, "\0", 1);
3414 putenv (obstack_finish (&collect_obstack));
3416 value = do_spec (link_command_spec);
3419 linker_was_run = (tmp != execution_count);
3422 /* Warn if a -B option was specified but the prefix was never used. */
3423 unused_prefix_warnings (&exec_prefix);
3424 unused_prefix_warnings (&startfile_prefix);
3426 /* If options said don't run linker,
3427 complain about input files to be given to the linker. */
3429 if (! linker_was_run && error_count == 0)
3430 for (i = 0; i < n_infiles; i++)
3431 if (explicit_link_files[i])
3432 error ("%s: linker input file unused since linking not done",
3435 /* Delete some or all of the temporary files we made. */
3438 delete_failure_queue ();
3439 delete_temp_files ();
3446 /* Find the proper compilation spec for the file name NAME,
3447 whose length is LENGTH. LANGUAGE is the specified language,
3448 or 0 if none specified. */
3450 static struct compiler *
3451 lookup_compiler (name, length, language)
3456 struct compiler *cp;
3458 /* Look for the language, if one is spec'd. */
3461 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
3465 if (cp->suffix[0] == '@'
3466 && !strcmp (cp->suffix + 1, language))
3470 error ("language %s not recognized", language);
3473 /* Look for a suffix. */
3474 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
3476 if (strlen (cp->suffix) < length
3477 /* See if the suffix matches the end of NAME. */
3478 && !strcmp (cp->suffix,
3479 name + length - strlen (cp->suffix))
3480 /* The suffix `-' matches only the file name `-'. */
3481 && !(!strcmp (cp->suffix, "-") && length != 1))
3483 if (cp->spec[0] == '@')
3485 struct compiler *new;
3486 /* An alias entry maps a suffix to a language.
3487 Search for the language; pass 0 for NAME and LENGTH
3488 to avoid infinite recursion if language not found.
3489 Construct the new compiler spec. */
3490 language = cp->spec + 1;
3491 new = (struct compiler *) xmalloc (sizeof (struct compiler));
3492 new->suffix = cp->suffix;
3493 new->spec = lookup_compiler (NULL_PTR, 0, language)->spec;
3496 /* A non-alias entry: return it. */
3508 register char *value = (char *) malloc (size);
3510 fatal ("virtual memory exhausted");
3515 xrealloc (ptr, size)
3519 register char *value = (char *) realloc (ptr, size);
3521 fatal ("virtual memory exhausted");
3525 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
3531 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
3532 char *result = xmalloc (len1 + len2 + len3 + 1);
3534 strcpy (result, s1);
3535 strcpy (result + len1, s2);
3536 strcpy (result + len1 + len2, s3);
3537 *(result + len1 + len2 + len3) = 0;
3543 save_string (s, len)
3547 register char *result = xmalloc (len + 1);
3549 bcopy (s, result, len);
3555 pfatal_with_name (name)
3560 if (errno < sys_nerr)
3561 s = concat ("%s: ", sys_errlist[errno], "");
3563 s = "cannot open %s";
3568 perror_with_name (name)
3573 if (errno < sys_nerr)
3574 s = concat ("%s: ", sys_errlist[errno], "");
3576 s = "cannot open %s";
3586 if (errno < sys_nerr)
3587 s = concat ("installation problem, cannot exec %s: ",
3588 sys_errlist[errno], "");
3590 s = "installation problem, cannot exec %s";
3594 /* More 'friendly' abort that prints the line and file.
3595 config.h can #define abort fancy_abort if you like that sort of thing. */
3600 fatal ("Internal gcc abort.");
3605 /* Output an error message and exit */
3615 format = va_arg (ap, char *);
3616 fprintf (stderr, "%s: ", programname);
3617 vfprintf (stderr, format, ap);
3619 fprintf (stderr, "\n");
3620 delete_temp_files ();
3632 format = va_arg (ap, char *);
3633 fprintf (stderr, "%s: ", programname);
3634 vfprintf (stderr, format, ap);
3637 fprintf (stderr, "\n");
3640 #else /* not HAVE_VPRINTF */
3643 fatal (msg, arg1, arg2)
3644 char *msg, *arg1, *arg2;
3646 error (msg, arg1, arg2);
3647 delete_temp_files ();
3652 error (msg, arg1, arg2)
3653 char *msg, *arg1, *arg2;
3655 fprintf (stderr, "%s: ", programname);
3656 fprintf (stderr, msg, arg1, arg2);
3657 fprintf (stderr, "\n");
3660 #endif /* not HAVE_VPRINTF */
3664 validate_all_switches ()
3666 struct compiler *comp;
3669 struct spec_list *spec;
3671 for (comp = compilers; comp->spec; comp++)
3675 if (c == '%' && *p == '{')
3676 /* We have a switch spec. */
3677 validate_switches (p + 1);
3680 /* look through the linked list of extra specs read from the specs file */
3681 for (spec = specs ; spec ; spec = spec->next)
3685 if (c == '%' && *p == '{')
3686 /* We have a switch spec. */
3687 validate_switches (p + 1);
3690 p = link_command_spec;
3692 if (c == '%' && *p == '{')
3693 /* We have a switch spec. */
3694 validate_switches (p + 1);
3696 /* Now notice switches mentioned in the machine-specific specs. */
3700 if (c == '%' && *p == '{')
3701 /* We have a switch spec. */
3702 validate_switches (p + 1);
3706 if (c == '%' && *p == '{')
3707 /* We have a switch spec. */
3708 validate_switches (p + 1);
3712 if (c == '%' && *p == '{')
3713 /* We have a switch spec. */
3714 validate_switches (p + 1);
3716 p = signed_char_spec;
3718 if (c == '%' && *p == '{')
3719 /* We have a switch spec. */
3720 validate_switches (p + 1);
3724 if (c == '%' && *p == '{')
3725 /* We have a switch spec. */
3726 validate_switches (p + 1);
3730 if (c == '%' && *p == '{')
3731 /* We have a switch spec. */
3732 validate_switches (p + 1);
3736 if (c == '%' && *p == '{')
3737 /* We have a switch spec. */
3738 validate_switches (p + 1);
3742 if (c == '%' && *p == '{')
3743 /* We have a switch spec. */
3744 validate_switches (p + 1);
3748 if (c == '%' && *p == '{')
3749 /* We have a switch spec. */
3750 validate_switches (p + 1);
3753 /* Look at the switch-name that comes after START
3754 and mark as valid all supplied switches that match it. */
3757 validate_switches (start)
3760 register char *p = start;
3775 while (*p != ':' && *p != '}') p++;
3779 else if (p[-1] == '*')
3781 /* Mark all matching switches as valid. */
3783 for (i = 0; i < n_switches; i++)
3784 if (!strncmp (switches[i].part1, filter, p - filter))
3785 switches[i].valid = 1;
3789 /* Mark an exact matching switch as valid. */
3790 for (i = 0; i < n_switches; i++)
3792 if (!strncmp (switches[i].part1, filter, p - filter)
3793 && switches[i].part1[p - filter] == 0)
3794 switches[i].valid = 1;