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". */
34 #include <sys/types.h>
38 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
54 /* On MSDOS, write temp files in current dir
55 because there's no place else we can expect to use. */
62 /* Test if something is a normal file. */
64 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
67 /* Test if something is a directory. */
69 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
72 /* By default there is no special suffix for executables. */
73 #ifndef EXECUTABLE_SUFFIX
74 #define EXECUTABLE_SUFFIX ""
77 /* By default, colon separates directories in a path. */
78 #ifndef PATH_SEPARATOR
79 #define PATH_SEPARATOR ':'
82 #define obstack_chunk_alloc xmalloc
83 #define obstack_chunk_free free
86 extern char *getenv ();
88 extern int errno
, sys_nerr
;
89 extern char *sys_errlist
[];
91 extern int execv (), execvp ();
93 /* If a stage of compilation returns an exit status >= 1,
94 compilation of that file ceases. */
96 #define MIN_FATAL_STATUS 1
98 /* Flag saying to print the full filename of libgcc.a
99 as found through our usual search mechanism. */
101 static int print_libgcc_file_name
;
103 /* Flag indicating whether we should print the command and arguments */
105 static int verbose_flag
;
107 /* Nonzero means write "temp" files in source directory
108 and use the source file's name in them, and don't delete them. */
110 static int save_temps_flag
;
112 /* The compiler version specified with -V */
114 static char *spec_version
;
116 /* The target machine specified with -b. */
118 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
120 /* Nonzero if cross-compiling.
121 When -b is used, the value comes from the `specs' file. */
124 static int cross_compile
= 1;
126 static int cross_compile
= 0;
129 /* This is the obstack which we use to allocate many strings. */
131 static struct obstack obstack
;
133 /* This is the obstack to build an environment variable to pass to
134 collect2 that describes all of the relevant switches of what to
135 pass the compiler in building the list of pointers to constructors
138 static struct obstack collect_obstack
;
140 extern char *version_string
;
142 static void set_spec ();
143 static struct compiler
*lookup_compiler ();
144 static char *find_a_file ();
145 static void add_prefix ();
146 static char *skip_whitespace ();
147 static void record_temp_file ();
148 static char *handle_braces ();
149 static char *save_string ();
150 static char *concat ();
151 static int do_spec ();
152 static int do_spec_1 ();
153 static char *find_file ();
154 static int is_linker_dir ();
155 static void validate_switches ();
156 static void validate_all_switches ();
157 static void give_switch ();
158 static void pfatal_with_name ();
159 static void perror_with_name ();
160 static void perror_exec ();
161 static void fatal ();
162 static void error ();
167 /* Specs are strings containing lines, each of which (if not blank)
168 is made up of a program name, and arguments separated by spaces.
169 The program name must be exact and start from root, since no path
170 is searched and it is unreliable to depend on the current working directory.
171 Redirection of input or output is not supported; the subprograms must
172 accept filenames saying what files to read and write.
174 In addition, the specs can contain %-sequences to substitute variable text
175 or for conditional text. Here is a table of all defined %-sequences.
176 Note that spaces are not generated automatically around the results of
177 expanding these sequences; therefore, you can concatenate them together
178 or with constant text in a single argument.
180 %% substitute one % into the program name or argument.
181 %i substitute the name of the input file being processed.
182 %b substitute the basename of the input file being processed.
183 This is the substring up to (and not including) the last period
184 and not including the directory.
185 %g substitute the temporary-file-name-base. This is a string chosen
186 once per compilation. Different temporary file names are made by
187 concatenation of constant strings on the end, as in `%g.s'.
188 %g also has the same effect of %d.
189 %d marks the argument containing or following the %d as a
190 temporary file name, so that that file will be deleted if CC exits
191 successfully. Unlike %g, this contributes no text to the argument.
192 %w marks the argument containing or following the %w as the
193 "output file" of this compilation. This puts the argument
194 into the sequence of arguments that %o will substitute later.
196 like %{...} but mark last argument supplied within
197 as a file to be deleted on failure.
198 %o substitutes the names of all the output files, with spaces
199 automatically placed around them. You should write spaces
200 around the %o as well or the results are undefined.
201 %o is for use in the specs for running the linker.
202 Input files whose names have no recognized suffix are not compiled
203 at all, but they are included among the output files, so they will
205 %p substitutes the standard macro predefinitions for the
206 current target machine. Use this when running cpp.
207 %P like %p, but puts `__' before and after the name of each macro.
208 (Except macros that already have __.)
210 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
211 %s current argument is the name of a library or startup file of some sort.
212 Search for that file in a standard list of directories
213 and substitute the full name found.
214 %eSTR Print STR as an error message. STR is terminated by a newline.
215 Use this when inconsistent options are detected.
216 %x{OPTION} Accumulate an option for %X.
217 %X Output the accumulated linker options specified by compilations.
218 %a process ASM_SPEC as a spec.
219 This allows config.h to specify part of the spec for running as.
220 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
221 used here. This can be used to run a post-processor after the
222 assembler has done it's job.
223 %D Dump out a -L option for each directory in library_prefix,
224 followed by a -L option for each directory in startfile_prefix.
225 %l process LINK_SPEC as a spec.
226 %L process LIB_SPEC as a spec.
227 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
228 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
229 %c process SIGNED_CHAR_SPEC as a spec.
230 %C process CPP_SPEC as a spec. A capital C is actually used here.
231 %1 process CC1_SPEC as a spec.
232 %2 process CC1PLUS_SPEC as a spec.
233 %* substitute the variable part of a matched option. (See below.)
234 Note that each comma in the substituted string is replaced by
236 %{S} substitutes the -S switch, if that switch was given to CC.
237 If that switch was not specified, this substitutes nothing.
238 Here S is a metasyntactic variable.
239 %{S*} substitutes all the switches specified to CC whose names start
240 with -S. This is used for -o, -D, -I, etc; switches that take
241 arguments. CC considers `-o foo' as being one switch whose
242 name starts with `o'. %{o*} would substitute this text,
243 including the space; thus, two arguments would be generated.
244 %{S*:X} substitutes X if one or more switches whose names with -S are
245 specified to CC. Note that the tail part of the -S option
246 (i.e. the part matched by the `*') will be substituted for each
247 occurrence of %* within X.
248 %{S:X} substitutes X, but only if the -S switch was given to CC.
249 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
250 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
251 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
252 %{.S:X} substitutes X, but only if processing a file with suffix S.
253 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
254 %(Spec) processes a specification defined in a specs file as *Spec:
255 %[Spec] as above, but put __ around -D arguments
257 The conditional text X in a %{S:X} or %{!S:X} construct may contain
258 other nested % constructs or spaces, or even newlines. They are
259 processed as usual, as described above.
261 The character | is used to indicate that a command should be piped to
262 the following command, but only if -pipe is specified.
264 Note that it is built into CC which switches take arguments and which
265 do not. You might think it would be useful to generalize this to
266 allow each compiler's spec to say which switches take arguments. But
267 this cannot be done in a consistent fashion. CC cannot even decide
268 which input files have been specified without knowing which switches
269 take arguments, and it must know which input files to compile in order
270 to tell which compilers to run.
272 CC also knows implicitly that arguments starting in `-l' are to be
273 treated as compiler output files, and passed to the linker in their
274 proper position among the other output files. */
276 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
278 /* config.h can define ASM_SPEC to provide extra args to the assembler
279 or extra switch-translations. */
284 /* config.h can define ASM_FINAL_SPEC to run a post processor after
285 the assembler has run. */
286 #ifndef ASM_FINAL_SPEC
287 #define ASM_FINAL_SPEC ""
290 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
291 or extra switch-translations. */
296 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
297 or extra switch-translations. */
302 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
303 or extra switch-translations. */
305 #define CC1PLUS_SPEC ""
308 /* config.h can define LINK_SPEC to provide extra args to the linker
309 or extra switch-translations. */
314 /* config.h can define LIB_SPEC to override the default libraries. */
316 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
319 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
320 #ifndef STARTFILE_SPEC
321 #define STARTFILE_SPEC \
322 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
325 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
326 Make the string nonempty to require spaces there. */
327 #ifndef SWITCHES_NEED_SPACES
328 #define SWITCHES_NEED_SPACES ""
331 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
333 #define ENDFILE_SPEC ""
336 /* This spec is used for telling cpp whether char is signed or not. */
337 #ifndef SIGNED_CHAR_SPEC
338 #define SIGNED_CHAR_SPEC \
339 (DEFAULT_SIGNED_CHAR ? "%{funsigned-char:-D__CHAR_UNSIGNED__}" \
340 : "%{!fsigned-char:-D__CHAR_UNSIGNED__}")
343 static char *cpp_spec
= CPP_SPEC
;
344 static char *cpp_predefines
= CPP_PREDEFINES
;
345 static char *cc1_spec
= CC1_SPEC
;
346 static char *cc1plus_spec
= CC1PLUS_SPEC
;
347 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
348 static char *asm_spec
= ASM_SPEC
;
349 static char *asm_final_spec
= ASM_FINAL_SPEC
;
350 static char *link_spec
= LINK_SPEC
;
351 static char *lib_spec
= LIB_SPEC
;
352 static char *endfile_spec
= ENDFILE_SPEC
;
353 static char *startfile_spec
= STARTFILE_SPEC
;
354 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
356 /* This defines which switch letters take arguments. */
358 #ifndef SWITCH_TAKES_ARG
359 #define SWITCH_TAKES_ARG(CHAR) \
360 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
361 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
362 || (CHAR) == 'I' || (CHAR) == 'm' \
363 || (CHAR) == 'L' || (CHAR) == 'A')
366 /* This defines which multi-letter switches take arguments. */
368 #ifndef WORD_SWITCH_TAKES_ARG
369 #define WORD_SWITCH_TAKES_ARG(STR) \
370 (!strcmp (STR, "Tdata") || !strcmp (STR, "include") \
371 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info"))
374 /* Record the mapping from file suffixes for compilation specs. */
378 char *suffix
; /* Use this compiler for input files
379 whose names end in this suffix. */
380 char *spec
; /* To use this compiler, pass this spec
384 /* Pointer to a vector of `struct compiler' that gives the spec for
385 compiling a file, based on its suffix.
386 A file that does not end in any of these suffixes will be passed
387 unchanged to the loader and nothing else will be done to it.
389 An entry containing two 0s is used to terminate the vector.
391 If multiple entries match a file, the last matching one is used. */
393 static struct compiler
*compilers
;
395 /* Number of entries in `compilers', not counting the null terminator. */
397 static int n_compilers
;
399 /* The default list of file name suffixes and their compilation specs. */
401 static struct compiler default_compilers
[] =
405 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
406 %{C:%{!E:%eGNU C does not support -C without using -E}}\
407 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
408 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
409 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
410 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
411 %{traditional-cpp:-traditional}\
412 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
413 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
414 %{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
415 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
416 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
417 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
419 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
420 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
421 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
422 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
423 %{!pipe:%g.s} %A\n }}}}"},
425 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
426 %{C:%{!E:%eGNU C does not support -C without using -E}}\
427 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
428 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
429 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
430 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
431 %{traditional-cpp:-traditional}\
432 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
434 %{!E:%e-E required when input is from standard input}"},
435 {".m", "@objective-c"},
437 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
438 %{C:%{!E:%eGNU C does not support -C without using -E}}\
439 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
440 -undef -D__OBJC__ -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
441 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
442 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
443 %{traditional-cpp:-traditional}\
444 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
445 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
446 %{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
447 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
448 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
449 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
450 -lang-objc %{gen-decls} \
452 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
453 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
454 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
455 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
456 %{!pipe:%g.s} %A\n }}}}"},
459 "%{!E:%eCompilation of header file requested} \
460 cpp %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
461 %{C:%{!E:%eGNU C does not support -C without using -E}}\
462 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
463 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
464 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
465 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
466 %{traditional-cpp:-traditional}\
467 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
473 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
474 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
475 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
476 -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus \
477 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
478 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
479 %{traditional-cpp:-traditional} %{trigraphs}\
480 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
481 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
482 %{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.i} %1 %2\
483 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
484 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
485 %{v:-version} %{pg:-p} %{p} %{f*}\
487 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
488 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
489 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
490 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
491 %{!pipe:%g.s} %A\n }}}}"},
492 {".i", "@cpp-output"},
494 "cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
495 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
496 %{v:-version} %{pg:-p} %{p} %{f*}\
498 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
499 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
500 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
501 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %{!pipe:%g.s} %A\n }"},
502 {".ii", "@c++-cpp-output"},
504 "cc1plus %i %1 %2 %{!Q:-quiet} %{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 \
511 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
512 %{!pipe:%g.s} %A\n }"},
513 {".s", "@assembler"},
515 "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
516 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %i %A\n }"},
517 {".S", "@assembler-with-cpp"},
518 {"@assembler-with-cpp",
519 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
520 %{C:%{!E:%eGNU C does not support -C without using -E}}\
521 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \
522 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
523 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
524 %{traditional-cpp:-traditional}\
525 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
526 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
527 %{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
528 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
529 %{!pipe:%g.s} %A\n }}}}"},
530 /* Mark end of table */
534 /* Number of elements in default_compilers, not counting the terminator. */
536 static int n_default_compilers
537 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
539 /* Here is the spec for running the linker, after compiling all files. */
541 #ifdef LINK_LIBGCC_SPECIAL
542 /* Have gcc do the search. */
543 /* -u* was put back because both BSD and SysV seem to support it. */
544 static char *link_command_spec
= "\
545 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
546 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
547 %{!A:%{!nostdlib:%S}} \
548 %{L*} %D %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}";
550 /* Use -l and have the linker do the search. */
551 static char *link_command_spec
= "\
552 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
553 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
554 %{!A:%{!nostdlib:%S}} \
555 %{L*} %D %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}";
558 /* A vector of options to give to the linker.
559 These options are accumulated by %x
560 and substituted into the linker command with %X. */
561 static int n_linker_options
;
562 static char **linker_options
;
564 /* Read compilation specs from a file named FILENAME,
565 replacing the default ones.
567 A suffix which starts with `*' is a definition for
568 one of the machine-specific sub-specs. The "suffix" should be
569 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
570 The corresponding spec is stored in asm_spec, etc.,
571 rather than in the `compilers' vector.
573 Anything invalid in the file is a fatal error. */
576 read_specs (filename
)
585 fprintf (stderr
, "Reading specs from %s\n", filename
);
587 /* Open and stat the file. */
588 desc
= open (filename
, 0, 0);
590 pfatal_with_name (filename
);
591 if (stat (filename
, &statbuf
) < 0)
592 pfatal_with_name (filename
);
594 /* Read contents of file into BUFFER. */
595 buffer
= xmalloc (statbuf
.st_size
+ 1);
596 read (desc
, buffer
, statbuf
.st_size
);
597 buffer
[statbuf
.st_size
] = 0;
600 /* Scan BUFFER for specs, putting them in the vector. */
606 char *in
, *out
, *p1
, *p2
;
608 /* Advance P in BUFFER to the next nonblank nocomment line. */
609 p
= skip_whitespace (p
);
613 /* Find the colon that should end the suffix. */
615 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
616 /* The colon shouldn't be missing. */
618 fatal ("specs file malformed after %d characters", p1
- buffer
);
619 /* Skip back over trailing whitespace. */
621 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
622 /* Copy the suffix to a string. */
623 suffix
= save_string (p
, p2
- p
);
624 /* Find the next line. */
625 p
= skip_whitespace (p1
+ 1);
627 fatal ("specs file malformed after %d characters", p
- buffer
);
629 /* Find next blank line. */
630 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
631 /* Specs end at the blank line and do not include the newline. */
632 spec
= save_string (p
, p1
- p
);
635 /* Delete backslash-newline sequences from the spec. */
640 if (in
[0] == '\\' && in
[1] == '\n')
642 else if (in
[0] == '#')
644 while (*in
&& *in
!= '\n') in
++;
651 if (suffix
[0] == '*')
653 if (! strcmp (suffix
, "*link_command"))
654 link_command_spec
= spec
;
656 set_spec (suffix
+ 1, spec
);
660 /* Add this pair to the vector. */
662 = ((struct compiler
*)
663 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
664 compilers
[n_compilers
].suffix
= suffix
;
665 compilers
[n_compilers
].spec
= spec
;
670 link_command_spec
= spec
;
673 if (link_command_spec
== 0)
674 fatal ("spec file has no spec for linking");
683 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
684 be considered whitespace. */
685 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
687 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
691 while (*p
!= '\n') p
++;
701 /* Structure to keep track of the specs that have been defined so far. These
702 are accessed using %(specname) or %[specname] in a compiler or link spec. */
706 char *name
; /* Name of the spec. */
707 char *spec
; /* The spec itself. */
708 struct spec_list
*next
; /* Next spec in linked list. */
711 /* List of specs that have been defined so far. */
713 static struct spec_list
*specs
= (struct spec_list
*) 0;
715 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
716 removed; If the spec starts with a + then SPEC is added to the end of the
720 set_spec (name
, spec
)
724 struct spec_list
*sl
;
727 /* See if the spec already exists */
728 for (sl
= specs
; sl
; sl
= sl
->next
)
729 if (strcmp (sl
->name
, name
) == 0)
734 /* Not found - make it */
735 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
736 sl
->name
= save_string (name
, strlen (name
));
737 sl
->spec
= save_string ("", 0);
743 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
744 sl
->spec
= concat (name
, spec
+ 1, "");
746 sl
->spec
= save_string (spec
, strlen (spec
));
748 if (! strcmp (name
, "asm"))
750 else if (! strcmp (name
, "asm_final"))
751 asm_final_spec
= sl
->spec
;
752 else if (! strcmp (name
, "cc1"))
754 else if (! strcmp (name
, "cc1plus"))
755 cc1plus_spec
= sl
->spec
;
756 else if (! strcmp (name
, "cpp"))
758 else if (! strcmp (name
, "endfile"))
759 endfile_spec
= sl
->spec
;
760 else if (! strcmp (name
, "lib"))
762 else if (! strcmp (name
, "link"))
763 link_spec
= sl
->spec
;
764 else if (! strcmp (name
, "predefines"))
765 cpp_predefines
= sl
->spec
;
766 else if (! strcmp (name
, "signed_char"))
767 signed_char_spec
= sl
->spec
;
768 else if (! strcmp (name
, "startfile"))
769 startfile_spec
= sl
->spec
;
770 else if (! strcmp (name
, "switches_need_spaces"))
771 switches_need_spaces
= sl
->spec
;
772 else if (! strcmp (name
, "cross_compile"))
773 cross_compile
= atoi (sl
->spec
);
774 /* Free the old spec */
779 /* Accumulate a command (program name and args), and run it. */
781 /* Vector of pointers to arguments in the current line of specifications. */
783 static char **argbuf
;
785 /* Number of elements allocated in argbuf. */
787 static int argbuf_length
;
789 /* Number of elements in argbuf currently in use (containing args). */
791 static int argbuf_index
;
793 /* Number of commands executed so far. */
795 static int execution_count
;
797 /* Name with which this program was invoked. */
799 static char *programname
;
801 /* Structures to keep track of prefixes to try when looking for files. */
805 char *prefix
; /* String to prepend to the path. */
806 struct prefix_list
*next
; /* Next in linked list. */
807 int require_machine_suffix
; /* Don't use without machine_suffix. */
808 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
813 struct prefix_list
*plist
; /* List of prefixes to try */
814 int max_len
; /* Max length of a prefix in PLIST */
815 char *name
; /* Name of this list (used in config stuff) */
818 /* List of prefixes to try when looking for executables. */
820 static struct path_prefix exec_prefix
= { 0, 0, "exec" };
822 /* List of prefixes to try when looking for startup (crt0) files. */
824 static struct path_prefix startfile_prefix
= { 0, 0, "startfile" };
826 /* List of prefixes to try when looking for libraries. */
828 static struct path_prefix library_prefix
= { 0, 0, "libraryfile" };
830 /* Suffix to attach to directories searched for commands. */
832 static char *machine_suffix
= 0;
834 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
836 static char *gcc_exec_prefix
;
838 /* Default prefixes to attach to command names. */
840 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
841 #undef MD_EXEC_PREFIX
842 #undef MD_STARTFILE_PREFIX
843 #undef MD_STARTFILE_PREFIX_1
846 #ifndef STANDARD_EXEC_PREFIX
847 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
848 #endif /* !defined STANDARD_EXEC_PREFIX */
850 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
851 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
852 #ifdef MD_EXEC_PREFIX
853 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
856 #ifndef STANDARD_STARTFILE_PREFIX
857 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
858 #endif /* !defined STANDARD_STARTFILE_PREFIX */
860 #ifdef MD_STARTFILE_PREFIX
861 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
863 #ifdef MD_STARTFILE_PREFIX_1
864 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
866 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
867 static char *standard_startfile_prefix_1
= "/lib/";
868 static char *standard_startfile_prefix_2
= "/usr/lib/";
870 /* Clear out the vector of arguments (after a command is executed). */
878 /* Add one argument to the vector at the end.
879 This is done when a space is seen or at the end of the line.
880 If DELETE_ALWAYS is nonzero, the arg is a filename
881 and the file should be deleted eventually.
882 If DELETE_FAILURE is nonzero, the arg is a filename
883 and the file should be deleted if this compilation fails. */
886 store_arg (arg
, delete_always
, delete_failure
)
888 int delete_always
, delete_failure
;
890 if (argbuf_index
+ 1 == argbuf_length
)
892 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
895 argbuf
[argbuf_index
++] = arg
;
896 argbuf
[argbuf_index
] = 0;
898 if (delete_always
|| delete_failure
)
899 record_temp_file (arg
, delete_always
, delete_failure
);
902 /* Record the names of temporary files we tell compilers to write,
903 and delete them at the end of the run. */
905 /* This is the common prefix we use to make temp file names.
906 It is chosen once for each run of this program.
907 It is substituted into a spec by %g.
908 Thus, all temp file names contain this prefix.
909 In practice, all temp file names start with this prefix.
911 This prefix comes from the envvar TMPDIR if it is defined;
912 otherwise, from the P_tmpdir macro if that is defined;
913 otherwise, in /usr/tmp or /tmp. */
915 static char *temp_filename
;
917 /* Length of the prefix. */
919 static int temp_filename_length
;
921 /* Define the list of temporary files to delete. */
926 struct temp_file
*next
;
929 /* Queue of files to delete on success or failure of compilation. */
930 static struct temp_file
*always_delete_queue
;
931 /* Queue of files to delete on failure of compilation. */
932 static struct temp_file
*failure_delete_queue
;
934 /* Record FILENAME as a file to be deleted automatically.
935 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
936 otherwise delete it in any case.
937 FAIL_DELETE nonzero means delete it if a compilation step fails;
938 otherwise delete it in any case. */
941 record_temp_file (filename
, always_delete
, fail_delete
)
947 name
= xmalloc (strlen (filename
) + 1);
948 strcpy (name
, filename
);
952 register struct temp_file
*temp
;
953 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
954 if (! strcmp (name
, temp
->name
))
956 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
957 temp
->next
= always_delete_queue
;
959 always_delete_queue
= temp
;
965 register struct temp_file
*temp
;
966 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
967 if (! strcmp (name
, temp
->name
))
969 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
970 temp
->next
= failure_delete_queue
;
972 failure_delete_queue
= temp
;
977 /* Delete all the temporary files whose names we previously recorded. */
982 register struct temp_file
*temp
;
984 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
988 printf ("Delete %s? (y or n) ", temp
->name
);
992 while (getchar () != '\n') ;
993 if (i
== 'y' || i
== 'Y')
997 if (stat (temp
->name
, &st
) >= 0)
999 /* Delete only ordinary files. */
1000 if (S_ISREG (st
.st_mode
))
1001 if (unlink (temp
->name
) < 0)
1003 perror_with_name (temp
->name
);
1008 always_delete_queue
= 0;
1011 /* Delete all the files to be deleted on error. */
1014 delete_failure_queue ()
1016 register struct temp_file
*temp
;
1018 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1022 printf ("Delete %s? (y or n) ", temp
->name
);
1026 while (getchar () != '\n') ;
1027 if (i
== 'y' || i
== 'Y')
1030 if (unlink (temp
->name
) < 0)
1032 perror_with_name (temp
->name
);
1038 clear_failure_queue ()
1040 failure_delete_queue
= 0;
1043 /* Compute a string to use as the base of all temporary file names.
1044 It is substituted for %g. */
1049 char *base
= getenv ("TMPDIR");
1052 if (base
== (char *)0)
1055 if (access (P_tmpdir
, R_OK
| W_OK
) == 0)
1058 if (base
== (char *)0)
1060 if (access ("/usr/tmp", R_OK
| W_OK
) == 0)
1067 len
= strlen (base
);
1068 temp_filename
= xmalloc (len
+ sizeof("/ccXXXXXX"));
1069 strcpy (temp_filename
, base
);
1070 if (len
> 0 && temp_filename
[len
-1] != '/')
1071 temp_filename
[len
++] = '/';
1072 strcpy (temp_filename
+ len
, "ccXXXXXX");
1074 mktemp (temp_filename
);
1075 temp_filename_length
= strlen (temp_filename
);
1079 /* Routine to add variables to the environment. We do this to pass
1080 the pathname of the gcc driver, and the directories search to the
1081 collect2 program, which is being run as ld. This way, we can be
1082 sure of executing the right compiler when collect2 wants to build
1083 constructors and destructors. Since the environment variables we
1084 use come from an obstack, we don't have to worry about allocating
1092 #ifndef VMS /* nor about VMS */
1094 extern char **environ
;
1095 char **old_environ
= environ
;
1099 int str_len
= strlen (str
);
1103 while ((ch
= *p
++) != '\0' && ch
!= '=')
1109 /* Search for replacing an existing environment variable, and
1110 count the number of total environment variables. */
1111 for (envp
= old_environ
; *envp
; envp
++)
1114 if (!strncmp (str
, *envp
, name_len
))
1121 /* Add a new environment variable */
1122 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1124 bcopy (old_environ
, environ
+1, sizeof (char *) * (num_envs
+1));
1129 #endif /* HAVE_PUTENV */
1132 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1135 putenv_from_prefixes (paths
, env_var
)
1136 struct path_prefix
*paths
;
1139 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1140 int first_time
= TRUE
;
1141 struct prefix_list
*pprefix
;
1143 obstack_grow (&collect_obstack
, env_var
, strlen (env_var
));
1145 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1147 int len
= strlen (pprefix
->prefix
);
1152 obstack_grow (&collect_obstack
, ":", 1);
1155 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1156 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1159 if (!pprefix
->require_machine_suffix
)
1162 obstack_grow (&collect_obstack
, ":", 1);
1165 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1168 obstack_grow (&collect_obstack
, "\0", 1);
1169 putenv (obstack_finish (&collect_obstack
));
1173 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1174 access to check permissions.
1175 Return 0 if not found, otherwise return its name, allocated with malloc. */
1178 find_a_file (pprefix
, name
, mode
)
1179 struct path_prefix
*pprefix
;
1184 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1185 struct prefix_list
*pl
;
1186 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1189 len
+= strlen (machine_suffix
);
1191 temp
= xmalloc (len
);
1193 /* Determine the filename to execute (special case for absolute paths). */
1197 if (access (name
, mode
))
1199 strcpy (temp
, name
);
1204 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1208 strcpy (temp
, pl
->prefix
);
1209 strcat (temp
, machine_suffix
);
1210 strcat (temp
, name
);
1211 if (access (temp
, mode
) == 0)
1213 if (pl
->used_flag_ptr
!= 0)
1214 *pl
->used_flag_ptr
= 1;
1217 /* Some systems have a suffix for executable files.
1218 So try appending that. */
1219 if (file_suffix
[0] != 0)
1221 strcat (temp
, file_suffix
);
1222 if (access (temp
, mode
) == 0)
1224 if (pl
->used_flag_ptr
!= 0)
1225 *pl
->used_flag_ptr
= 1;
1230 /* Certain prefixes can't be used without the machine suffix
1231 when the machine or version is explicitly specified. */
1232 if (!pl
->require_machine_suffix
)
1234 strcpy (temp
, pl
->prefix
);
1235 strcat (temp
, name
);
1236 if (access (temp
, mode
) == 0)
1238 if (pl
->used_flag_ptr
!= 0)
1239 *pl
->used_flag_ptr
= 1;
1242 /* Some systems have a suffix for executable files.
1243 So try appending that. */
1244 if (file_suffix
[0] != 0)
1246 strcat (temp
, file_suffix
);
1247 if (access (temp
, mode
) == 0)
1249 if (pl
->used_flag_ptr
!= 0)
1250 *pl
->used_flag_ptr
= 1;
1261 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1262 at the start of the list, otherwise it goes at the end.
1264 If WARN is nonzero, we will warn if no file is found
1265 through this prefix. WARN should point to an int
1266 which will be set to 1 if this entry is used. */
1269 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1270 struct path_prefix
*pprefix
;
1273 int require_machine_suffix
;
1276 struct prefix_list
*pl
, **prev
;
1279 if (!first
&& pprefix
->plist
)
1281 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1286 prev
= &pprefix
->plist
;
1288 /* Keep track of the longest prefix */
1290 len
= strlen (prefix
);
1291 if (len
> pprefix
->max_len
)
1292 pprefix
->max_len
= len
;
1294 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1295 pl
->prefix
= save_string (prefix
, len
);
1296 pl
->require_machine_suffix
= require_machine_suffix
;
1297 pl
->used_flag_ptr
= warn
;
1304 pl
->next
= (struct prefix_list
*) 0;
1308 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1311 unused_prefix_warnings (pprefix
)
1312 struct path_prefix
*pprefix
;
1314 struct prefix_list
*pl
= pprefix
->plist
;
1318 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1320 error ("file path prefix `%s' never used",
1322 /* Prevent duplicate warnings. */
1323 *pl
->used_flag_ptr
= 1;
1329 /* Get rid of all prefixes built up so far in *PLISTP. */
1332 free_path_prefix (pprefix
)
1333 struct path_prefix
*pprefix
;
1335 struct prefix_list
*pl
= pprefix
->plist
;
1336 struct prefix_list
*temp
;
1342 free (temp
->prefix
);
1343 free ((char *) temp
);
1345 pprefix
->plist
= (struct prefix_list
*) 0;
1348 /* stdin file number. */
1349 #define STDIN_FILE_NO 0
1351 /* stdout file number. */
1352 #define STDOUT_FILE_NO 1
1354 /* value of `pipe': port index for reading. */
1357 /* value of `pipe': port index for writing. */
1358 #define WRITE_PORT 1
1360 /* Pipe waiting from last process, to be used as input for the next one.
1361 Value is STDIN_FILE_NO if no pipe is waiting
1362 (i.e. the next command is the first of a group). */
1364 static int last_pipe_input
;
1366 /* Fork one piped subcommand. FUNC is the system call to use
1367 (either execv or execvp). ARGV is the arg vector to use.
1368 NOT_LAST is nonzero if this is not the last subcommand
1369 (i.e. its output should be piped to the next one.) */
1373 /* Declare these to avoid compilation error. They won't be called. */
1374 int execv(const char *a
, const char **b
){}
1375 int execvp(const char *a
, const char **b
){}
1378 pexecute (func
, program
, argv
, not_last
)
1388 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6);
1389 sprintf (scmd
, "%s @%s.gp", program
, temp_filename
);
1390 argfile
= fopen (scmd
+strlen (program
) + 2, "w");
1392 pfatal_with_name (scmd
+ strlen (program
) + 2);
1394 for (i
=1; argv
[i
]; i
++)
1397 for (cp
= argv
[i
]; *cp
; cp
++)
1399 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
1400 fputc ('\\', argfile
);
1401 fputc (*cp
, argfile
);
1403 fputc ('\n', argfile
);
1409 remove (scmd
+ strlen (program
) + 2);
1413 #else /* not __MSDOS__ */
1416 pexecute (func
, program
, argv
, not_last
)
1424 int input_desc
= last_pipe_input
;
1425 int output_desc
= STDOUT_FILE_NO
;
1426 int retries
, sleep_interval
;
1428 /* If this isn't the last process, make a pipe for its output,
1429 and record it as waiting to be the input to the next process. */
1433 if (pipe (pdes
) < 0)
1434 pfatal_with_name ("pipe");
1435 output_desc
= pdes
[WRITE_PORT
];
1436 last_pipe_input
= pdes
[READ_PORT
];
1439 last_pipe_input
= STDIN_FILE_NO
;
1441 /* Fork a subprocess; wait and retry if it fails. */
1443 for (retries
= 0; retries
< 4; retries
++)
1448 sleep (sleep_interval
);
1449 sleep_interval
*= 2;
1456 pfatal_with_name ("fork");
1458 pfatal_with_name ("vfork");
1464 /* Move the input and output pipes into place, if nec. */
1465 if (input_desc
!= STDIN_FILE_NO
)
1467 close (STDIN_FILE_NO
);
1471 if (output_desc
!= STDOUT_FILE_NO
)
1473 close (STDOUT_FILE_NO
);
1475 close (output_desc
);
1478 /* Close the parent's descs that aren't wanted here. */
1479 if (last_pipe_input
!= STDIN_FILE_NO
)
1480 close (last_pipe_input
);
1482 /* Exec the program. */
1483 (*func
) (program
, argv
);
1484 perror_exec (program
);
1490 /* In the parent, after forking.
1491 Close the descriptors that we made for this child. */
1492 if (input_desc
!= STDIN_FILE_NO
)
1494 if (output_desc
!= STDOUT_FILE_NO
)
1495 close (output_desc
);
1497 /* Return child's process number. */
1502 #endif /* not __MSDOS__ */
1504 /* Execute the command specified by the arguments on the current line of spec.
1505 When using pipes, this includes several piped-together commands
1506 with `|' between them.
1508 Return 0 if successful, -1 if failed. */
1514 int n_commands
; /* # of command. */
1518 char *prog
; /* program name. */
1519 char **argv
; /* vector of args. */
1520 int pid
; /* pid of process for this command. */
1523 struct command
*commands
; /* each command buffer with above info. */
1525 /* Count # of piped commands. */
1526 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
1527 if (strcmp (argbuf
[i
], "|") == 0)
1530 /* Get storage for each command. */
1532 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
1534 /* Split argbuf into its separate piped processes,
1535 and record info about each one.
1536 Also search for the programs that are to be run. */
1538 commands
[0].prog
= argbuf
[0]; /* first command. */
1539 commands
[0].argv
= &argbuf
[0];
1540 string
= find_a_file (&exec_prefix
, commands
[0].prog
, X_OK
);
1542 commands
[0].argv
[0] = string
;
1544 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
1545 if (strcmp (argbuf
[i
], "|") == 0)
1546 { /* each command. */
1548 fatal ("-pipe not supported under MS-DOS");
1550 argbuf
[i
] = 0; /* termination of command args. */
1551 commands
[n_commands
].prog
= argbuf
[i
+ 1];
1552 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
1553 string
= find_a_file (&exec_prefix
, commands
[n_commands
].prog
, X_OK
);
1555 commands
[n_commands
].argv
[0] = string
;
1559 argbuf
[argbuf_index
] = 0;
1561 /* If -v, print what we are about to do, and maybe query. */
1565 /* Print each piped command as a separate line. */
1566 for (i
= 0; i
< n_commands
; i
++)
1570 for (j
= commands
[i
].argv
; *j
; j
++)
1571 fprintf (stderr
, " %s", *j
);
1573 /* Print a pipe symbol after all but the last command. */
1574 if (i
+ 1 != n_commands
)
1575 fprintf (stderr
, " |");
1576 fprintf (stderr
, "\n");
1580 fprintf (stderr
, "\nGo ahead? (y or n) ");
1584 while (getchar () != '\n') ;
1585 if (i
!= 'y' && i
!= 'Y')
1590 /* Run each piped subprocess. */
1592 last_pipe_input
= STDIN_FILE_NO
;
1593 for (i
= 0; i
< n_commands
; i
++)
1595 char *string
= commands
[i
].argv
[0];
1597 commands
[i
].pid
= pexecute ((string
!= commands
[i
].prog
? execv
: execvp
),
1598 string
, commands
[i
].argv
,
1599 i
+ 1 < n_commands
);
1601 if (string
!= commands
[i
].prog
)
1607 /* Wait for all the subprocesses to finish.
1608 We don't care what order they finish in;
1609 we know that N_COMMANDS waits will get them all. */
1614 for (i
= 0; i
< n_commands
; i
++)
1621 status
= pid
= commands
[i
].pid
;
1623 pid
= wait (&status
);
1631 for (j
= 0; j
< n_commands
; j
++)
1632 if (commands
[j
].pid
== pid
)
1633 prog
= commands
[j
].prog
;
1635 if ((status
& 0x7F) != 0)
1636 fatal ("Internal compiler error: program %s got fatal signal %d",
1637 prog
, (status
& 0x7F));
1638 if (((status
& 0xFF00) >> 8) >= MIN_FATAL_STATUS
)
1646 /* Find all the switches given to us
1647 and make a vector describing them.
1648 The elements of the vector are strings, one per switch given.
1649 If a switch uses following arguments, then the `part1' field
1650 is the switch itself and the `args' field
1651 is a null-terminated vector containing the following arguments.
1652 The `valid' field is nonzero if any spec has looked at this switch;
1653 if it remains zero at the end of the run, it must be meaningless. */
1662 static struct switchstr
*switches
;
1664 static int n_switches
;
1672 /* Also a vector of input files specified. */
1674 static struct infile
*infiles
;
1676 static int n_infiles
;
1678 /* And a vector of corresponding output files is made up later. */
1680 static char **outfiles
;
1682 /* Create the vector `switches' and its contents.
1683 Store its length in `n_switches'. */
1686 process_command (argc
, argv
)
1692 char *spec_lang
= 0;
1693 int last_language_n_infiles
;
1695 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
1699 spec_version
= version_string
;
1701 /* Set up the default search paths. */
1703 if (gcc_exec_prefix
)
1705 add_prefix (&exec_prefix
, gcc_exec_prefix
, 0, 0, 0);
1706 add_prefix (&startfile_prefix
, gcc_exec_prefix
, 0, 0, 0);
1709 /* COMPILER_PATH and LIBRARY_PATH have values
1710 that are lists of directory names with colons. */
1712 temp
= getenv ("COMPILER_PATH");
1715 char *startp
, *endp
;
1716 char *nstore
= (char *) alloca (strlen (temp
) + 3);
1718 startp
= endp
= temp
;
1721 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
1723 strncpy (nstore
, startp
, endp
-startp
);
1726 strcpy (nstore
, "./");
1728 else if (endp
[-1] != '/')
1730 nstore
[endp
-startp
] = '/';
1731 nstore
[endp
-startp
+1] = 0;
1734 nstore
[endp
-startp
] = 0;
1735 add_prefix (&exec_prefix
, nstore
, 0, 0, 0);
1738 endp
= startp
= endp
+ 1;
1745 temp
= getenv ("LIBRARY_PATH");
1748 char *startp
, *endp
;
1749 char *nstore
= (char *) alloca (strlen (temp
) + 3);
1751 startp
= endp
= temp
;
1754 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
1756 strncpy (nstore
, startp
, endp
-startp
);
1759 strcpy (nstore
, "./");
1761 else if (endp
[-1] != '/')
1763 nstore
[endp
-startp
] = '/';
1764 nstore
[endp
-startp
+1] = 0;
1767 nstore
[endp
-startp
] = 0;
1768 add_prefix (&startfile_prefix
, nstore
, 0, 0, 0);
1769 /* Make separate list of dirs that came from LIBRARY_PATH. */
1770 add_prefix (&library_prefix
, nstore
, 0, 0, 0);
1773 endp
= startp
= endp
+ 1;
1780 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
1781 temp
= getenv ("LPATH");
1784 char *startp
, *endp
;
1785 char *nstore
= (char *) alloca (strlen (temp
) + 3);
1787 startp
= endp
= temp
;
1790 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
1792 strncpy (nstore
, startp
, endp
-startp
);
1795 strcpy (nstore
, "./");
1797 else if (endp
[-1] != '/')
1799 nstore
[endp
-startp
] = '/';
1800 nstore
[endp
-startp
+1] = 0;
1803 nstore
[endp
-startp
] = 0;
1804 add_prefix (&startfile_prefix
, nstore
, 0, 0, 0);
1805 /* Make separate list of dirs that came from LIBRARY_PATH. */
1806 add_prefix (&library_prefix
, nstore
, 0, 0, 0);
1809 endp
= startp
= endp
+ 1;
1816 /* Scan argv twice. Here, the first time, just count how many switches
1817 there will be in their vector, and how many input files in theirs.
1818 Here we also parse the switches that cc itself uses (e.g. -v). */
1820 for (i
= 1; i
< argc
; i
++)
1822 if (! strcmp (argv
[i
], "-dumpspecs"))
1824 printf ("*asm:\n%s\n\n", asm_spec
);
1825 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
1826 printf ("*cpp:\n%s\n\n", cpp_spec
);
1827 printf ("*cc1:\n%s\n\n", cc1_spec
);
1828 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
1829 printf ("*endfile:\n%s\n\n", endfile_spec
);
1830 printf ("*link:\n%s\n\n", link_spec
);
1831 printf ("*lib:\n%s\n\n", lib_spec
);
1832 printf ("*startfile:\n%s\n\n", startfile_spec
);
1833 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
1834 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
1835 printf ("*predefines:\n%s\n\n", cpp_predefines
);
1836 printf ("*cross_compile:\n%d\n\n", cross_compile
);
1840 else if (! strcmp (argv
[i
], "-dumpversion"))
1842 printf ("%s\n", version_string
);
1845 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
1847 print_libgcc_file_name
= 1;
1849 else if (! strcmp (argv
[i
], "-Xlinker"))
1851 /* Pass the argument of this option to the linker when we link. */
1854 fatal ("argument to `-Xlinker' is missing");
1857 if (!linker_options
)
1859 = (char **) xmalloc (n_linker_options
* sizeof (char **));
1862 = (char **) xrealloc (linker_options
,
1863 n_linker_options
* sizeof (char **));
1865 linker_options
[n_linker_options
- 1] = argv
[++i
];
1867 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
1869 register char *p
= &argv
[i
][1];
1870 register int c
= *p
;
1875 if (p
[1] == 0 && i
+ 1 == argc
)
1876 fatal ("argument to `-b' is missing");
1878 spec_machine
= argv
[++i
];
1880 spec_machine
= p
+ 1;
1885 int *temp
= (int *) xmalloc (sizeof (int));
1887 if (p
[1] == 0 && i
+ 1 == argc
)
1888 fatal ("argument to `-B' is missing");
1893 add_prefix (&exec_prefix
, value
, 1, 0, temp
);
1894 add_prefix (&startfile_prefix
, value
, 1, 0, temp
);
1898 case 'v': /* Print our subcommands and print versions. */
1904 if (p
[1] == 0 && i
+ 1 == argc
)
1905 fatal ("argument to `-V' is missing");
1907 spec_version
= argv
[++i
];
1909 spec_version
= p
+ 1;
1913 if (!strcmp (p
, "save-temps"))
1915 save_temps_flag
= 1;
1922 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1923 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1924 else if (WORD_SWITCH_TAKES_ARG (p
))
1925 i
+= WORD_SWITCH_TAKES_ARG (p
);
1932 /* Set up the search paths before we go looking for config files. */
1934 /* These come before the md prefixes so that we will find gcc's subcommands
1935 (such as cpp) rather than those of the host system. */
1936 add_prefix (&exec_prefix
, standard_exec_prefix
, 0, 1, 0);
1937 add_prefix (&exec_prefix
, standard_exec_prefix_1
, 0, 1, 0);
1939 add_prefix (&startfile_prefix
, standard_exec_prefix
, 0, 1, 0);
1940 add_prefix (&startfile_prefix
, standard_exec_prefix_1
, 0, 1, 0);
1942 /* More prefixes are enabled in main, after we read the specs file
1943 and determine whether this is cross-compilation or not. */
1946 /* Then create the space for the vectors and scan again. */
1948 switches
= ((struct switchstr
*)
1949 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
1950 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
1953 last_language_n_infiles
= -1;
1955 /* This, time, copy the text of each switch and store a pointer
1956 to the copy in the vector of switches.
1957 Store all the infiles in their vector. */
1959 for (i
= 1; i
< argc
; i
++)
1961 if (!strcmp (argv
[i
], "-Xlinker"))
1963 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
1965 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
1967 register char *p
= &argv
[i
][1];
1968 register int c
= *p
;
1970 if (c
== 'B' || c
== 'b' || c
== 'V')
1972 /* Skip a separate arg, if any. */
1979 if (p
[1] == 0 && i
+ 1 == argc
)
1980 fatal ("argument to `-x' is missing");
1982 spec_lang
= argv
[++i
];
1985 if (! strcmp (spec_lang
, "none"))
1986 /* Suppress the warning if -xnone comes after the last input file,
1987 because alternate command interfaces like g++ might find it
1988 useful to place -xnone after each input file. */
1991 last_language_n_infiles
= n_infiles
;
1994 switches
[n_switches
].part1
= p
;
1995 /* Deal with option arguments in separate argv elements. */
1996 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1997 || WORD_SWITCH_TAKES_ARG (p
)) {
1999 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2002 /* Count only the option arguments in separate argv elements. */
2003 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2005 switches
[n_switches
].args
2006 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2008 switches
[n_switches
].args
[j
++] = argv
[++i
];
2009 /* Null-terminate the vector. */
2010 switches
[n_switches
].args
[j
] = 0;
2011 } else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L')) {
2012 /* On some systems, ld cannot handle -o or -L without space.
2013 So split the -o or -L from its argument. */
2014 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2015 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2016 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2017 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2018 switches
[n_switches
].args
[1] = 0;
2020 switches
[n_switches
].args
= 0;
2021 switches
[n_switches
].valid
= 0;
2022 /* This is always valid, since gcc.c itself understands it. */
2023 if (!strcmp (p
, "save-temps"))
2024 switches
[n_switches
].valid
= 1;
2029 infiles
[n_infiles
].language
= spec_lang
;
2030 infiles
[n_infiles
++].name
= argv
[i
];
2034 if (n_infiles
== last_language_n_infiles
)
2035 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2037 switches
[n_switches
].part1
= 0;
2038 infiles
[n_infiles
].name
= 0;
2040 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2041 if (gcc_exec_prefix
)
2043 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2044 + strlen (spec_machine
) + 3);
2045 strcpy (temp
, gcc_exec_prefix
);
2046 strcat (temp
, spec_version
);
2048 strcat (temp
, spec_machine
);
2050 gcc_exec_prefix
= temp
;
2054 /* Process a spec string, accumulating and running commands. */
2056 /* These variables describe the input file name.
2057 input_file_number is the index on outfiles of this file,
2058 so that the output file name can be stored for later use by %o.
2059 input_basename is the start of the part of the input file
2060 sans all directory names, and basename_length is the number
2061 of characters starting there excluding the suffix .c or whatever. */
2063 static char *input_filename
;
2064 static int input_file_number
;
2065 static int input_filename_length
;
2066 static int basename_length
;
2067 static char *input_basename
;
2068 static char *input_suffix
;
2070 /* These are variables used within do_spec and do_spec_1. */
2072 /* Nonzero if an arg has been started and not yet terminated
2073 (with space, tab or newline). */
2074 static int arg_going
;
2076 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2077 is a temporary file name. */
2078 static int delete_this_arg
;
2080 /* Nonzero means %w has been seen; the next arg to be terminated
2081 is the output file name of this compilation. */
2082 static int this_is_output_file
;
2084 /* Nonzero means %s has been seen; the next arg to be terminated
2085 is the name of a library file and we should try the standard
2086 search dirs for it. */
2087 static int this_is_library_file
;
2089 /* Process the spec SPEC and run the commands specified therein.
2090 Returns 0 if the spec is successfully processed; -1 if failed. */
2100 delete_this_arg
= 0;
2101 this_is_output_file
= 0;
2102 this_is_library_file
= 0;
2104 value
= do_spec_1 (spec
, 0, NULL
);
2106 /* Force out any unfinished command.
2107 If -pipe, this forces out the last command if it ended in `|'. */
2110 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2113 if (argbuf_index
> 0)
2120 /* Process the sub-spec SPEC as a portion of a larger spec.
2121 This is like processing a whole spec except that we do
2122 not initialize at the beginning and we do not supply a
2123 newline by default at the end.
2124 INSWITCH nonzero means don't process %-sequences in SPEC;
2125 in this case, % is treated as an ordinary character.
2126 This is used while substituting switches.
2127 INSWITCH nonzero also causes SPC not to terminate an argument.
2129 Value is zero unless a line was finished
2130 and the command on that line reported an error. */
2133 do_spec_1 (spec
, inswitch
, soft_matched_part
)
2136 char *soft_matched_part
;
2138 register char *p
= spec
;
2144 /* If substituting a switch, treat all chars like letters.
2145 Otherwise, NL, SPC, TAB and % are special. */
2146 switch (inswitch
? 'a' : c
)
2149 /* End of line: finish any pending argument,
2150 then run the pending command if one has been started. */
2153 obstack_1grow (&obstack
, 0);
2154 string
= obstack_finish (&obstack
);
2155 if (this_is_library_file
)
2156 string
= find_file (string
);
2157 store_arg (string
, delete_this_arg
, this_is_output_file
);
2158 if (this_is_output_file
)
2159 outfiles
[input_file_number
] = string
;
2163 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2166 for (i
= 0; i
< n_switches
; i
++)
2167 if (!strcmp (switches
[i
].part1
, "pipe"))
2170 /* A `|' before the newline means use a pipe here,
2171 but only if -pipe was specified.
2172 Otherwise, execute now and don't pass the `|' as an arg. */
2175 switches
[i
].valid
= 1;
2182 if (argbuf_index
> 0)
2184 int value
= execute ();
2188 /* Reinitialize for a new command, and for a new argument. */
2191 delete_this_arg
= 0;
2192 this_is_output_file
= 0;
2193 this_is_library_file
= 0;
2197 /* End any pending argument. */
2200 obstack_1grow (&obstack
, 0);
2201 string
= obstack_finish (&obstack
);
2202 if (this_is_library_file
)
2203 string
= find_file (string
);
2204 store_arg (string
, delete_this_arg
, this_is_output_file
);
2205 if (this_is_output_file
)
2206 outfiles
[input_file_number
] = string
;
2210 obstack_1grow (&obstack
, c
);
2216 /* Space or tab ends an argument if one is pending. */
2219 obstack_1grow (&obstack
, 0);
2220 string
= obstack_finish (&obstack
);
2221 if (this_is_library_file
)
2222 string
= find_file (string
);
2223 store_arg (string
, delete_this_arg
, this_is_output_file
);
2224 if (this_is_output_file
)
2225 outfiles
[input_file_number
] = string
;
2227 /* Reinitialize for a new argument. */
2229 delete_this_arg
= 0;
2230 this_is_output_file
= 0;
2231 this_is_library_file
= 0;
2238 fatal ("Invalid specification! Bug in cc.");
2241 obstack_grow (&obstack
, input_basename
, basename_length
);
2246 delete_this_arg
= 2;
2249 /* Dump out the directories specified with LIBRARY_PATH,
2250 followed by the absolute directories
2251 that we search for startfiles. */
2253 for (i
= 0; i
< 2; i
++)
2255 struct prefix_list
*pl
2256 = (i
== 0 ? library_prefix
.plist
: startfile_prefix
.plist
);
2258 char *buffer
= (char *) xmalloc (bufsize
);
2261 for (; pl
; pl
= pl
->next
)
2263 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2264 /* Used on systems which record the specified -L dirs
2265 and use them to search for dynamic linking. */
2266 /* Relative directories always come from -B,
2267 and it is better not to use them for searching
2268 at run time. In particular, stage1 loses */
2269 if (pl
->prefix
[0] != '/')
2274 if (is_linker_dir (pl
->prefix
, machine_suffix
))
2276 do_spec_1 ("-L", 0, 0);
2277 #ifdef SPACE_AFTER_L_OPTION
2278 do_spec_1 (" ", 0, 0);
2280 do_spec_1 (pl
->prefix
, 1, 0);
2281 /* Remove slash from machine_suffix. */
2282 if (strlen (machine_suffix
) >= bufsize
)
2283 bufsize
= strlen (machine_suffix
) * 2 + 1;
2284 buffer
= (char *) xrealloc (buffer
, bufsize
);
2285 strcpy (buffer
, machine_suffix
);
2286 idx
= strlen (buffer
);
2287 if (buffer
[idx
- 1] == '/')
2288 buffer
[idx
- 1] = 0;
2289 do_spec_1 (buffer
, 1, 0);
2290 /* Make this a separate argument. */
2291 do_spec_1 (" ", 0, 0);
2294 if (!pl
->require_machine_suffix
)
2296 if (is_linker_dir (pl
->prefix
, ""))
2298 do_spec_1 ("-L", 0, 0);
2299 #ifdef SPACE_AFTER_L_OPTION
2300 do_spec_1 (" ", 0, 0);
2302 /* Remove slash from pl->prefix. */
2303 if (strlen (pl
->prefix
) >= bufsize
)
2304 bufsize
= strlen (pl
->prefix
) * 2 + 1;
2305 buffer
= (char *) xrealloc (buffer
, bufsize
);
2306 strcpy (buffer
, pl
->prefix
);
2307 idx
= strlen (buffer
);
2308 if (buffer
[idx
- 1] == '/')
2309 buffer
[idx
- 1] = 0;
2310 do_spec_1 (buffer
, 1, 0);
2311 /* Make this a separate argument. */
2312 do_spec_1 (" ", 0, 0);
2321 /* {...:%efoo} means report an error with `foo' as error message
2322 and don't execute any more commands for this file. */
2326 while (*p
!= 0 && *p
!= '\n') p
++;
2327 buf
= (char *) alloca (p
- q
+ 1);
2328 strncpy (buf
, q
, p
- q
);
2336 if (save_temps_flag
)
2337 obstack_grow (&obstack
, input_basename
, basename_length
);
2340 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
2341 delete_this_arg
= 1;
2347 obstack_grow (&obstack
, input_filename
, input_filename_length
);
2352 if (gcc_exec_prefix
)
2354 do_spec_1 ("-imacros", 1, 0);
2355 /* Make this a separate argument. */
2356 do_spec_1 (" ", 0, 0);
2357 do_spec_1 (gcc_exec_prefix
, 1, 0);
2358 do_spec_1 (" ", 0, 0);
2365 for (f
= 0; f
< n_infiles
; f
++)
2366 store_arg (outfiles
[f
], 0, 0);
2371 this_is_library_file
= 1;
2375 this_is_output_file
= 1;
2380 int index
= argbuf_index
;
2381 /* Handle the {...} following the %W. */
2384 p
= handle_braces (p
+ 1);
2387 /* If any args were output, mark the last one for deletion
2389 if (argbuf_index
!= index
)
2390 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
2394 /* %x{OPTION} records OPTION for %X to output. */
2400 /* Skip past the option value and make a copy. */
2405 string
= save_string (p1
+ 1, p
- p1
- 2);
2407 /* See if we already recorded this option. */
2408 for (i
= 0; i
< n_linker_options
; i
++)
2409 if (! strcmp (string
, linker_options
[i
]))
2415 /* This option is new; add it. */
2417 if (!linker_options
)
2419 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2422 = (char **) xrealloc (linker_options
,
2423 n_linker_options
* sizeof (char **));
2425 linker_options
[n_linker_options
- 1] = string
;
2429 /* Dump out the options accumulated previously using %x. */
2431 for (i
= 0; i
< n_linker_options
; i
++)
2433 do_spec_1 (linker_options
[i
], 1, NULL
);
2434 /* Make each accumulated option a separate argument. */
2435 do_spec_1 (" ", 0, NULL
);
2439 /* Here are digits and numbers that just process
2440 a certain constant string as a spec. */
2443 do_spec_1 (cc1_spec
, 0, NULL
);
2447 do_spec_1 (cc1plus_spec
, 0, NULL
);
2451 do_spec_1 (asm_spec
, 0, NULL
);
2455 do_spec_1 (asm_final_spec
, 0, NULL
);
2459 do_spec_1 (signed_char_spec
, 0, NULL
);
2463 do_spec_1 (cpp_spec
, 0, NULL
);
2467 do_spec_1 (endfile_spec
, 0, NULL
);
2471 do_spec_1 (link_spec
, 0, NULL
);
2475 do_spec_1 (lib_spec
, 0, NULL
);
2480 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
2484 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
2488 if (! strncmp (y
, "-D", 2))
2489 /* Copy the whole option. */
2490 while (*y
&& *y
!= ' ' && *y
!= '\t')
2492 else if (*y
== ' ' || *y
== '\t')
2493 /* Copy whitespace to the result. */
2495 /* Don't copy other options. */
2502 do_spec_1 (buf
, 0, NULL
);
2508 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
2512 /* Copy all of CPP_PREDEFINES into BUF,
2513 but put __ after every -D and at the end of each arg. */
2517 if (! strncmp (y
, "-D", 2))
2524 if (strncmp (y
, "__", 2))
2526 /* Stick __ at front of macro name. */
2529 /* Arrange to stick __ at the end as well. */
2533 /* Copy the macro name. */
2534 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
2543 /* Copy the value given, if any. */
2544 while (*y
&& *y
!= ' ' && *y
!= '\t')
2547 else if (*y
== ' ' || *y
== '\t')
2548 /* Copy whitespace to the result. */
2550 /* Don't copy -A options */
2556 /* Copy all of CPP_PREDEFINES into BUF,
2557 but put __ after every -D. */
2561 if (! strncmp (y
, "-D", 2))
2566 if (strncmp (y
, "__", 2))
2568 /* Stick __ at front of macro name. */
2573 /* Copy the macro name. */
2574 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
2577 /* Copy the value given, if any. */
2578 while (*y
&& *y
!= ' ' && *y
!= '\t')
2581 else if (*y
== ' ' || *y
== '\t')
2582 /* Copy whitespace to the result. */
2584 /* Don't copy -A options */
2590 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
2594 if (! strncmp (y
, "-A", 2))
2595 /* Copy the whole option. */
2596 while (*y
&& *y
!= ' ' && *y
!= '\t')
2598 else if (*y
== ' ' || *y
== '\t')
2599 /* Copy whitespace to the result. */
2601 /* Don't copy other options. */
2608 do_spec_1 (buf
, 0, NULL
);
2613 do_spec_1 (startfile_spec
, 0, NULL
);
2616 /* Here we define characters other than letters and digits. */
2619 p
= handle_braces (p
);
2625 obstack_1grow (&obstack
, '%');
2629 do_spec_1 (soft_matched_part
, 1, NULL
);
2630 do_spec_1 (" ", 0, NULL
);
2633 /* Process a string found as the value of a spec given by name.
2634 This feature allows individual machine descriptions
2635 to add and use their own specs.
2636 %[...] modifies -D options the way %P does;
2637 %(...) uses the spec unmodified. */
2642 struct spec_list
*sl
;
2645 /* The string after the S/P is the name of a spec that is to be
2647 while (*p
&& *p
!= ')' && *p
!= ']')
2650 /* See if it's in the list */
2651 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
2652 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
2661 do_spec_1 (name
, 0, NULL
);
2664 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
2668 /* Copy all of NAME into BUF, but put __ after
2669 every -D and at the end of each arg, */
2672 if (! strncmp (y
, "-D", 2))
2680 else if (*y
== ' ' || *y
== 0)
2694 do_spec_1 (buf
, 0, NULL
);
2698 /* Discard the closing paren or bracket. */
2710 /* Backslash: treat next character as ordinary. */
2715 /* Ordinary character: put it into the current argument. */
2716 obstack_1grow (&obstack
, c
);
2720 return 0; /* End of string */
2723 /* Return 0 if we call do_spec_1 and that returns -1. */
2736 /* A `|' after the open-brace means,
2737 if the test fails, output a single minus sign rather than nothing.
2738 This is used in %{|!pipe:...}. */
2742 /* A `!' after the open-brace negates the condition:
2743 succeed if the specified switch is not present. */
2747 /* A `.' after the open-brace means test against the current suffix. */
2757 while (*p
!= ':' && *p
!= '}') p
++;
2760 register int count
= 1;
2778 int found
= (input_suffix
!= 0
2779 && strlen (input_suffix
) == p
- filter
2780 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
2786 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL
) < 0)
2791 else if (p
[-1] == '*' && p
[0] == '}')
2793 /* Substitute all matching switches as separate args. */
2796 for (i
= 0; i
< n_switches
; i
++)
2797 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
2802 /* Test for presence of the specified switch. */
2806 /* If name specified ends in *, as in {x*:...},
2807 check for %* and handle that case. */
2808 if (p
[-1] == '*' && !negate
)
2813 /* First see whether we have %*. */
2817 if (*r
== '%' && r
[1] == '*')
2821 /* If we do, handle that case. */
2824 /* Substitute all matching switches as separate args.
2825 But do this by substituting for %*
2826 in the text that follows the colon. */
2828 unsigned hard_match_len
= p
- filter
- 1;
2829 char *string
= save_string (p
+ 1, q
- p
- 2);
2831 for (i
= 0; i
< n_switches
; i
++)
2832 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
))
2834 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
2835 /* Pass any arguments this switch has. */
2843 /* If name specified ends in *, as in {x*:...},
2844 check for presence of any switch name starting with x. */
2847 for (i
= 0; i
< n_switches
; i
++)
2849 unsigned hard_match_len
= p
- filter
- 1;
2851 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
))
2853 switches
[i
].valid
= 1;
2858 /* Otherwise, check for presence of exact name specified. */
2861 for (i
= 0; i
< n_switches
; i
++)
2863 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
2864 && switches
[i
].part1
[p
- filter
] == 0)
2866 switches
[i
].valid
= 1;
2873 /* If it is as desired (present for %{s...}, absent for %{-s...})
2874 then substitute either the switch or the specified
2875 conditional text. */
2876 if (present
!= negate
)
2884 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL
) < 0)
2890 /* Here if a %{|...} conditional fails: output a minus sign,
2891 which means "standard output" or "standard input". */
2892 do_spec_1 ("-", 0, NULL
);
2899 /* Pass a switch to the current accumulating command
2900 in the same form that we received it.
2901 SWITCHNUM identifies the switch; it is an index into
2902 the vector of switches gcc received, which is `switches'.
2903 This cannot fail since it never finishes a command line.
2905 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
2908 give_switch (switchnum
, omit_first_word
)
2910 int omit_first_word
;
2912 if (!omit_first_word
)
2914 do_spec_1 ("-", 0, NULL
);
2915 do_spec_1 (switches
[switchnum
].part1
, 1, NULL
);
2917 do_spec_1 (" ", 0, NULL
);
2918 if (switches
[switchnum
].args
!= 0)
2921 for (p
= switches
[switchnum
].args
; *p
; p
++)
2923 do_spec_1 (*p
, 1, NULL
);
2924 do_spec_1 (" ", 0, NULL
);
2927 switches
[switchnum
].valid
= 1;
2930 /* Search for a file named NAME trying various prefixes including the
2931 user's -B prefix and some standard ones.
2932 Return the absolute file name found. If nothing is found, return NAME. */
2940 newname
= find_a_file (&startfile_prefix
, name
, R_OK
);
2941 return newname
? newname
: name
;
2944 /* Determine whether a -L option is relevant. Not required for certain
2945 fixed names and for directories that don't exist. */
2948 is_linker_dir (path1
, path2
)
2952 int len1
= strlen (path1
);
2953 int len2
= strlen (path2
);
2954 char *path
= (char *) alloca (3 + len1
+ len2
);
2958 /* Construct the path from the two parts. Ensure the string ends with "/.".
2959 The resulting path will be a directory even if the given path is a
2961 bcopy (path1
, path
, len1
);
2962 bcopy (path2
, path
+ len1
, len2
);
2963 cp
= path
+ len1
+ len2
;
2969 /* Exclude directories that the linker is known to search. */
2970 if ((cp
- path
== 6 && strcmp (path
, "/lib/.") == 0)
2971 || (cp
- path
== 10 && strcmp (path
, "/usr/lib/.") == 0))
2974 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
2977 /* On fatal signals, delete all the temporary files. */
2980 fatal_error (signum
)
2983 signal (signum
, SIG_DFL
);
2984 delete_failure_queue ();
2985 delete_temp_files ();
2986 /* Get the same signal again, this time not handled,
2987 so its normal effect occurs. */
2988 kill (getpid (), signum
);
2998 int error_count
= 0;
2999 int linker_was_run
= 0;
3000 char *explicit_link_files
;
3003 programname
= argv
[0];
3005 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
3006 signal (SIGINT
, fatal_error
);
3007 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
3008 signal (SIGHUP
, fatal_error
);
3009 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
3010 signal (SIGTERM
, fatal_error
);
3012 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
3013 signal (SIGPIPE
, fatal_error
);
3017 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
3019 obstack_init (&obstack
);
3021 /* Set up to remember the pathname of gcc and any options
3022 needed for collect. */
3023 obstack_init (&collect_obstack
);
3024 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
3025 obstack_grow (&collect_obstack
, programname
, strlen (programname
)+1);
3026 putenv (obstack_finish (&collect_obstack
));
3028 /* Choose directory for temp files. */
3030 choose_temp_base ();
3032 /* Make a table of what switches there are (switches, n_switches).
3033 Make a table of specified input files (infiles, n_infiles).
3034 Decode switches that are handled locally. */
3036 process_command (argc
, argv
);
3038 /* Initialize the vector of specs to just the default.
3039 This means one element containing 0s, as a terminator. */
3041 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
3042 bcopy (default_compilers
, compilers
, sizeof default_compilers
);
3043 n_compilers
= n_default_compilers
;
3045 /* Read specs from a file if there is one. */
3047 machine_suffix
= concat (spec_machine
, "/", concat (spec_version
, "/", ""));
3049 specs_file
= find_a_file (&startfile_prefix
, "specs", R_OK
);
3050 /* Read the specs file unless it is a default one. */
3051 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
3052 read_specs (specs_file
);
3054 /* If not cross-compiling, look for startfiles in the standard places. */
3055 /* The fact that these are done here, after reading the specs file,
3056 means that it cannot be found in these directories.
3057 But that's okay. It should never be there anyway. */
3060 #ifdef MD_EXEC_PREFIX
3061 add_prefix (&exec_prefix
, md_exec_prefix
, 0, 0, 0);
3062 add_prefix (&startfile_prefix
, md_exec_prefix
, 0, 0, 0);
3065 #ifdef MD_STARTFILE_PREFIX
3066 add_prefix (&startfile_prefix
, md_startfile_prefix
, 0, 0, 0);
3069 #ifdef MD_STARTFILE_PREFIX_1
3070 add_prefix (&startfile_prefix
, md_startfile_prefix_1
, 0, 0, 0);
3073 add_prefix (&startfile_prefix
, standard_startfile_prefix
, 0, 0, 0);
3074 add_prefix (&startfile_prefix
, standard_startfile_prefix_1
, 0, 0, 0);
3075 add_prefix (&startfile_prefix
, standard_startfile_prefix_2
, 0, 0, 0);
3076 #if 0 /* Can cause surprises, and one can use -B./ instead. */
3077 add_prefix (&startfile_prefix
, "./", 0, 1, 0);
3081 /* Now we have the specs.
3082 Set the `valid' bits for switches that match anything in any spec. */
3084 validate_all_switches ();
3086 /* Warn about any switches that no pass was interested in. */
3088 for (i
= 0; i
< n_switches
; i
++)
3089 if (! switches
[i
].valid
)
3090 error ("unrecognized option `-%s'", switches
[i
].part1
);
3092 if (print_libgcc_file_name
)
3094 printf ("%s\n", find_file ("libgcc.a"));
3098 /* Obey some of the options. */
3102 fprintf (stderr
, "gcc version %s\n", version_string
);
3108 fatal ("No input files specified.");
3110 /* Make a place to record the compiler output file names
3111 that correspond to the input files. */
3113 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
3114 bzero (outfiles
, n_infiles
* sizeof (char *));
3116 /* Record which files were specified explicitly as link input. */
3118 explicit_link_files
= xmalloc (n_infiles
);
3119 bzero (explicit_link_files
, n_infiles
);
3121 for (i
= 0; i
< n_infiles
; i
++)
3123 register struct compiler
*cp
= 0;
3124 int this_file_error
= 0;
3126 /* Tell do_spec what to substitute for %i. */
3128 input_filename
= infiles
[i
].name
;
3129 input_filename_length
= strlen (input_filename
);
3130 input_file_number
= i
;
3132 /* Use the same thing in %o, unless cp->spec says otherwise. */
3134 outfiles
[i
] = input_filename
;
3136 /* Figure out which compiler from the file's suffix. */
3138 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
3139 infiles
[i
].language
);
3143 /* Ok, we found an applicable compiler. Run its spec. */
3144 /* First say how much of input_filename to substitute for %b */
3147 input_basename
= input_filename
;
3148 for (p
= input_filename
; *p
; p
++)
3150 input_basename
= p
+ 1;
3152 /* Find a suffix starting with the last period,
3153 and set basename_length to exclude that suffix. */
3154 basename_length
= strlen (input_basename
);
3155 p
= input_basename
+ basename_length
;
3156 while (p
!= input_basename
&& *p
!= '.') --p
;
3157 if (*p
== '.' && p
!= input_basename
)
3159 basename_length
= p
- input_basename
;
3160 input_suffix
= p
+ 1;
3165 value
= do_spec (cp
->spec
);
3167 this_file_error
= 1;
3170 /* If this file's name does not contain a recognized suffix,
3171 record it as explicit linker input. */
3174 explicit_link_files
[i
] = 1;
3176 /* Clear the delete-on-failure queue, deleting the files in it
3177 if this compilation failed. */
3179 if (this_file_error
)
3181 delete_failure_queue ();
3184 /* If this compilation succeeded, don't delete those files later. */
3185 clear_failure_queue ();
3188 /* Run ld to link all the compiler output files. */
3190 if (error_count
== 0)
3192 int tmp
= execution_count
;
3196 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
3198 putenv_from_prefixes (&exec_prefix
, "COMPILER_PATH=");
3199 putenv_from_prefixes (&startfile_prefix
, "LIBRARY_PATH=");
3201 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
3203 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
3204 sizeof ("COLLECT_GCC_OPTIONS=")-1);
3207 for (i
= 0; i
< n_switches
; i
++)
3211 obstack_grow (&collect_obstack
, " ", 1);
3214 obstack_grow (&collect_obstack
, "-", 1);
3215 obstack_grow (&collect_obstack
, switches
[i
].part1
,
3216 strlen (switches
[i
].part1
));
3218 for (args
= switches
[i
].args
; args
&& *args
; args
++)
3220 obstack_grow (&collect_obstack
, " ", 1);
3221 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
3224 obstack_grow (&collect_obstack
, "\0", 1);
3225 putenv (obstack_finish (&collect_obstack
));
3227 value
= do_spec (link_command_spec
);
3230 linker_was_run
= (tmp
!= execution_count
);
3233 /* Warn if a -B option was specified but the prefix was never used. */
3234 unused_prefix_warnings (&exec_prefix
);
3235 unused_prefix_warnings (&startfile_prefix
);
3237 /* If options said don't run linker,
3238 complain about input files to be given to the linker. */
3240 if (! linker_was_run
&& error_count
== 0)
3241 for (i
= 0; i
< n_infiles
; i
++)
3242 if (explicit_link_files
[i
])
3243 error ("%s: linker input file unused since linking not done",
3246 /* Delete some or all of the temporary files we made. */
3249 delete_failure_queue ();
3250 delete_temp_files ();
3257 /* Find the proper compilation spec for the file name NAME,
3258 whose length is LENGTH. LANGUAGE is the specified language,
3259 or 0 if none specified. */
3261 static struct compiler
*
3262 lookup_compiler (name
, length
, language
)
3267 struct compiler
*cp
;
3269 /* Look for the language, if one is spec'd. */
3272 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
3276 if (cp
->suffix
[0] == '@'
3277 && !strcmp (cp
->suffix
+ 1, language
))
3281 error ("language %s not recognized", language
);
3284 /* Look for a suffix. */
3285 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
3287 if (strlen (cp
->suffix
) < length
3288 /* See if the suffix matches the end of NAME. */
3289 && !strcmp (cp
->suffix
,
3290 name
+ length
- strlen (cp
->suffix
))
3291 /* The suffix `-' matches only the file name `-'. */
3292 && !(!strcmp (cp
->suffix
, "-") && length
!= 1))
3294 if (cp
->spec
[0] == '@')
3296 struct compiler
*new;
3297 /* An alias entry maps a suffix to a language.
3298 Search for the language; pass 0 for NAME and LENGTH
3299 to avoid infinite recursion if language not found.
3300 Construct the new compiler spec. */
3301 language
= cp
->spec
+ 1;
3302 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
3303 new->suffix
= cp
->suffix
;
3304 new->spec
= lookup_compiler (0, 0, language
)->spec
;
3307 /* A non-alias entry: return it. */
3319 register char *value
= (char *) malloc (size
);
3321 fatal ("virtual memory exhausted");
3326 xrealloc (ptr
, size
)
3330 register char *value
= (char *) realloc (ptr
, size
);
3332 fatal ("virtual memory exhausted");
3336 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
3342 int len1
= strlen (s1
), len2
= strlen (s2
), len3
= strlen (s3
);
3343 char *result
= xmalloc (len1
+ len2
+ len3
+ 1);
3345 strcpy (result
, s1
);
3346 strcpy (result
+ len1
, s2
);
3347 strcpy (result
+ len1
+ len2
, s3
);
3348 *(result
+ len1
+ len2
+ len3
) = 0;
3354 save_string (s
, len
)
3358 register char *result
= xmalloc (len
+ 1);
3360 bcopy (s
, result
, len
);
3366 pfatal_with_name (name
)
3371 if (errno
< sys_nerr
)
3372 s
= concat ("%s: ", sys_errlist
[errno
], "");
3374 s
= "cannot open %s";
3379 perror_with_name (name
)
3384 if (errno
< sys_nerr
)
3385 s
= concat ("%s: ", sys_errlist
[errno
], "");
3387 s
= "cannot open %s";
3397 if (errno
< sys_nerr
)
3398 s
= concat ("installation problem, cannot exec %s: ",
3399 sys_errlist
[errno
], "");
3401 s
= "installation problem, cannot exec %s";
3405 /* More 'friendly' abort that prints the line and file.
3406 config.h can #define abort fancy_abort if you like that sort of thing. */
3411 fatal ("Internal gcc abort.");
3416 /* Output an error message and exit */
3426 format
= va_arg (ap
, char *);
3427 fprintf (stderr
, "%s: ", programname
);
3428 vfprintf (stderr
, format
, ap
);
3430 fprintf (stderr
, "\n");
3431 delete_temp_files ();
3443 format
= va_arg (ap
, char *);
3444 fprintf (stderr
, "%s: ", programname
);
3445 vfprintf (stderr
, format
, ap
);
3448 fprintf (stderr
, "\n");
3451 #else /* not HAVE_VPRINTF */
3454 fatal (msg
, arg1
, arg2
)
3455 char *msg
, *arg1
, *arg2
;
3457 error (msg
, arg1
, arg2
);
3458 delete_temp_files ();
3463 error (msg
, arg1
, arg2
)
3464 char *msg
, *arg1
, *arg2
;
3466 fprintf (stderr
, "%s: ", programname
);
3467 fprintf (stderr
, msg
, arg1
, arg2
);
3468 fprintf (stderr
, "\n");
3471 #endif /* not HAVE_VPRINTF */
3475 validate_all_switches ()
3477 struct compiler
*comp
;
3480 struct spec_list
*spec
;
3482 for (comp
= compilers
; comp
->spec
; comp
++)
3486 if (c
== '%' && *p
== '{')
3487 /* We have a switch spec. */
3488 validate_switches (p
+ 1);
3491 /* look through the linked list of extra specs read from the specs file */
3492 for (spec
= specs
; spec
; spec
= spec
->next
)
3496 if (c
== '%' && *p
== '{')
3497 /* We have a switch spec. */
3498 validate_switches (p
+ 1);
3501 p
= link_command_spec
;
3503 if (c
== '%' && *p
== '{')
3504 /* We have a switch spec. */
3505 validate_switches (p
+ 1);
3507 /* Now notice switches mentioned in the machine-specific specs. */
3511 if (c
== '%' && *p
== '{')
3512 /* We have a switch spec. */
3513 validate_switches (p
+ 1);
3517 if (c
== '%' && *p
== '{')
3518 /* We have a switch spec. */
3519 validate_switches (p
+ 1);
3523 if (c
== '%' && *p
== '{')
3524 /* We have a switch spec. */
3525 validate_switches (p
+ 1);
3527 p
= signed_char_spec
;
3529 if (c
== '%' && *p
== '{')
3530 /* We have a switch spec. */
3531 validate_switches (p
+ 1);
3535 if (c
== '%' && *p
== '{')
3536 /* We have a switch spec. */
3537 validate_switches (p
+ 1);
3541 if (c
== '%' && *p
== '{')
3542 /* We have a switch spec. */
3543 validate_switches (p
+ 1);
3547 if (c
== '%' && *p
== '{')
3548 /* We have a switch spec. */
3549 validate_switches (p
+ 1);
3553 if (c
== '%' && *p
== '{')
3554 /* We have a switch spec. */
3555 validate_switches (p
+ 1);
3559 if (c
== '%' && *p
== '{')
3560 /* We have a switch spec. */
3561 validate_switches (p
+ 1);
3564 /* Look at the switch-name that comes after START
3565 and mark as valid all supplied switches that match it. */
3568 validate_switches (start
)
3571 register char *p
= start
;
3586 while (*p
!= ':' && *p
!= '}') p
++;
3590 else if (p
[-1] == '*')
3592 /* Mark all matching switches as valid. */
3594 for (i
= 0; i
< n_switches
; i
++)
3595 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
3596 switches
[i
].valid
= 1;
3600 /* Mark an exact matching switch as valid. */
3601 for (i
= 0; i
< n_switches
; i
++)
3603 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3604 && switches
[i
].part1
[p
- filter
] == 0)
3605 switches
[i
].valid
= 1;