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>
53 /* On MSDOS, write temp files in current dir
54 because there's no place else we can expect to use. */
61 /* Test if something is a normal file. */
63 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
66 /* Test if something is a directory. */
68 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
71 /* By default there is no special suffix for executables. */
72 #ifndef EXECUTABLE_SUFFIX
73 #define EXECUTABLE_SUFFIX ""
76 /* By default, colon separates directories in a path. */
77 #ifndef PATH_SEPARATOR
78 #define PATH_SEPARATOR ':'
81 #define obstack_chunk_alloc xmalloc
82 #define obstack_chunk_free free
85 extern char *getenv ();
87 extern int errno
, sys_nerr
;
88 extern char *sys_errlist
[];
90 extern int execv (), execvp ();
92 /* If a stage of compilation returns an exit status >= 1,
93 compilation of that file ceases. */
95 #define MIN_FATAL_STATUS 1
97 /* Flag saying to print the full filename of libgcc.a
98 as found through our usual search mechanism. */
100 static int print_libgcc_file_name
;
102 /* Flag indicating whether we should print the command and arguments */
104 static int verbose_flag
;
106 /* Nonzero means write "temp" files in source directory
107 and use the source file's name in them, and don't delete them. */
109 static int save_temps_flag
;
111 /* The compiler version specified with -V */
113 static char *spec_version
;
115 /* The target machine specified with -b. */
117 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
119 /* Nonzero if cross-compiling.
120 When -b is used, the value comes from the `specs' file. */
123 static int cross_compile
= 1;
125 static int cross_compile
= 0;
128 /* This is the obstack which we use to allocate many strings. */
130 static struct obstack obstack
;
132 /* This is the obstack to build an environment variable to pass to
133 collect2 that describes all of the relevant switches of what to
134 pass the compiler in building the list of pointers to constructors
137 static struct obstack collect_obstack
;
139 extern char *version_string
;
141 static void set_spec ();
142 static struct compiler
*lookup_compiler ();
143 static char *find_a_file ();
144 static void add_prefix ();
145 static char *skip_whitespace ();
146 static void record_temp_file ();
147 static char *handle_braces ();
148 static char *save_string ();
149 static char *concat ();
150 static int do_spec ();
151 static int do_spec_1 ();
152 static char *find_file ();
153 static int is_linker_dir ();
154 static void validate_switches ();
155 static void validate_all_switches ();
156 static void give_switch ();
157 static void pfatal_with_name ();
158 static void perror_with_name ();
159 static void perror_exec ();
160 static void fatal ();
161 static void error ();
166 /* Specs are strings containing lines, each of which (if not blank)
167 is made up of a program name, and arguments separated by spaces.
168 The program name must be exact and start from root, since no path
169 is searched and it is unreliable to depend on the current working directory.
170 Redirection of input or output is not supported; the subprograms must
171 accept filenames saying what files to read and write.
173 In addition, the specs can contain %-sequences to substitute variable text
174 or for conditional text. Here is a table of all defined %-sequences.
175 Note that spaces are not generated automatically around the results of
176 expanding these sequences; therefore, you can concatenate them together
177 or with constant text in a single argument.
179 %% substitute one % into the program name or argument.
180 %i substitute the name of the input file being processed.
181 %b substitute the basename of the input file being processed.
182 This is the substring up to (and not including) the last period
183 and not including the directory.
184 %g substitute the temporary-file-name-base. This is a string chosen
185 once per compilation. Different temporary file names are made by
186 concatenation of constant strings on the end, as in `%g.s'.
187 %g also has the same effect of %d.
188 %d marks the argument containing or following the %d as a
189 temporary file name, so that that file will be deleted if CC exits
190 successfully. Unlike %g, this contributes no text to the argument.
191 %w marks the argument containing or following the %w as the
192 "output file" of this compilation. This puts the argument
193 into the sequence of arguments that %o will substitute later.
195 like %{...} but mark last argument supplied within
196 as a file to be deleted on failure.
197 %o substitutes the names of all the output files, with spaces
198 automatically placed around them. You should write spaces
199 around the %o as well or the results are undefined.
200 %o is for use in the specs for running the linker.
201 Input files whose names have no recognized suffix are not compiled
202 at all, but they are included among the output files, so they will
204 %p substitutes the standard macro predefinitions for the
205 current target machine. Use this when running cpp.
206 %P like %p, but puts `__' before and after the name of each macro.
207 (Except macros that already have __.)
209 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
210 %s current argument is the name of a library or startup file of some sort.
211 Search for that file in a standard list of directories
212 and substitute the full name found.
213 %eSTR Print STR as an error message. STR is terminated by a newline.
214 Use this when inconsistent options are detected.
215 %x{OPTION} Accumulate an option for %X.
216 %X Output the accumulated linker options specified by compilations.
217 %a process ASM_SPEC as a spec.
218 This allows config.h to specify part of the spec for running as.
219 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
220 used here. This can be used to run a post-processor after the
221 assembler has done it's job.
222 %D Dump out a -L option for each directory in library_prefix,
223 followed by a -L option for each directory in startfile_prefix.
224 %l process LINK_SPEC as a spec.
225 %L process LIB_SPEC as a spec.
226 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
227 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
228 %c process SIGNED_CHAR_SPEC as a spec.
229 %C process CPP_SPEC as a spec. A capital C is actually used here.
230 %1 process CC1_SPEC as a spec.
231 %2 process CC1PLUS_SPEC as a spec.
232 %* substitute the variable part of a matched option. (See below.)
233 Note that each comma in the substituted string is replaced by
235 %{S} substitutes the -S switch, if that switch was given to CC.
236 If that switch was not specified, this substitutes nothing.
237 Here S is a metasyntactic variable.
238 %{S*} substitutes all the switches specified to CC whose names start
239 with -S. This is used for -o, -D, -I, etc; switches that take
240 arguments. CC considers `-o foo' as being one switch whose
241 name starts with `o'. %{o*} would substitute this text,
242 including the space; thus, two arguments would be generated.
243 %{S*:X} substitutes X if one or more switches whose names with -S are
244 specified to CC. Note that the tail part of the -S option
245 (i.e. the part matched by the `*') will be substituted for each
246 occurrence of %* within X.
247 %{S:X} substitutes X, but only if the -S switch was given to CC.
248 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
249 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
250 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
251 %{.S:X} substitutes X, but only if processing a file with suffix S.
252 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
253 %(Spec) processes a specification defined in a specs file as *Spec:
254 %[Spec] as above, but put __ around -D arguments
256 The conditional text X in a %{S:X} or %{!S:X} construct may contain
257 other nested % constructs or spaces, or even newlines. They are
258 processed as usual, as described above.
260 The character | is used to indicate that a command should be piped to
261 the following command, but only if -pipe is specified.
263 Note that it is built into CC which switches take arguments and which
264 do not. You might think it would be useful to generalize this to
265 allow each compiler's spec to say which switches take arguments. But
266 this cannot be done in a consistent fashion. CC cannot even decide
267 which input files have been specified without knowing which switches
268 take arguments, and it must know which input files to compile in order
269 to tell which compilers to run.
271 CC also knows implicitly that arguments starting in `-l' are to be
272 treated as compiler output files, and passed to the linker in their
273 proper position among the other output files. */
275 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
277 /* config.h can define ASM_SPEC to provide extra args to the assembler
278 or extra switch-translations. */
283 /* config.h can define ASM_FINAL_SPEC to run a post processor after
284 the assembler has run. */
285 #ifndef ASM_FINAL_SPEC
286 #define ASM_FINAL_SPEC ""
289 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
290 or extra switch-translations. */
295 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
296 or extra switch-translations. */
301 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
302 or extra switch-translations. */
304 #define CC1PLUS_SPEC ""
307 /* config.h can define LINK_SPEC to provide extra args to the linker
308 or extra switch-translations. */
313 /* config.h can define LIB_SPEC to override the default libraries. */
315 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
318 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
319 #ifndef STARTFILE_SPEC
320 #define STARTFILE_SPEC \
321 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
324 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
325 Make the string nonempty to require spaces there. */
326 #ifndef SWITCHES_NEED_SPACES
327 #define SWITCHES_NEED_SPACES ""
330 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
332 #define ENDFILE_SPEC ""
335 /* This spec is used for telling cpp whether char is signed or not. */
336 #ifndef SIGNED_CHAR_SPEC
337 #define SIGNED_CHAR_SPEC \
338 (DEFAULT_SIGNED_CHAR ? "%{funsigned-char:-D__CHAR_UNSIGNED__}" \
339 : "%{!fsigned-char:-D__CHAR_UNSIGNED__}")
342 static char *cpp_spec
= CPP_SPEC
;
343 static char *cpp_predefines
= CPP_PREDEFINES
;
344 static char *cc1_spec
= CC1_SPEC
;
345 static char *cc1plus_spec
= CC1PLUS_SPEC
;
346 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
347 static char *asm_spec
= ASM_SPEC
;
348 static char *asm_final_spec
= ASM_FINAL_SPEC
;
349 static char *link_spec
= LINK_SPEC
;
350 static char *lib_spec
= LIB_SPEC
;
351 static char *endfile_spec
= ENDFILE_SPEC
;
352 static char *startfile_spec
= STARTFILE_SPEC
;
353 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
355 /* This defines which switch letters take arguments. */
357 #ifndef SWITCH_TAKES_ARG
358 #define SWITCH_TAKES_ARG(CHAR) \
359 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
360 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
361 || (CHAR) == 'I' || (CHAR) == 'm' \
362 || (CHAR) == 'L' || (CHAR) == 'A')
365 /* This defines which multi-letter switches take arguments. */
367 #ifndef WORD_SWITCH_TAKES_ARG
368 #define WORD_SWITCH_TAKES_ARG(STR) \
369 (!strcmp (STR, "Tdata") || !strcmp (STR, "include") \
370 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info"))
373 /* Record the mapping from file suffixes for compilation specs. */
377 char *suffix
; /* Use this compiler for input files
378 whose names end in this suffix. */
379 char *spec
; /* To use this compiler, pass this spec
383 /* Pointer to a vector of `struct compiler' that gives the spec for
384 compiling a file, based on its suffix.
385 A file that does not end in any of these suffixes will be passed
386 unchanged to the loader and nothing else will be done to it.
388 An entry containing two 0s is used to terminate the vector.
390 If multiple entries match a file, the last matching one is used. */
392 static struct compiler
*compilers
;
394 /* Number of entries in `compilers', not counting the null terminator. */
396 static int n_compilers
;
398 /* The default list of file name suffixes and their compilation specs. */
400 static struct compiler default_compilers
[] =
404 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
405 %{C:%{!E:%eGNU C does not support -C without using -E}}\
406 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
407 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
408 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
409 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
410 %{traditional-cpp:-traditional}\
411 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
412 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
413 %{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
414 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
415 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
416 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
418 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
419 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
420 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
421 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
422 %{!pipe:%g.s} %A\n }}}}"},
424 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
425 %{C:%{!E:%eGNU C does not support -C without using -E}}\
426 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
427 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
428 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
429 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
430 %{traditional-cpp:-traditional}\
431 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
433 %{!E:%e-E required when input is from standard input}"},
434 {".m", "@objective-c"},
436 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
437 %{C:%{!E:%eGNU C does not support -C without using -E}}\
438 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
439 -undef -D__OBJC__ -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
440 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
441 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
442 %{traditional-cpp:-traditional}\
443 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
444 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
445 %{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
446 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
447 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
448 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
449 -lang-objc %{gen-decls} \
451 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
452 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
453 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
454 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
455 %{!pipe:%g.s} %A\n }}}}"},
458 "%{!E:%eCompilation of header file requested} \
459 cpp %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
460 %{C:%{!E:%eGNU C does not support -C without using -E}}\
461 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
462 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
463 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
464 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
465 %{traditional-cpp:-traditional}\
466 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
472 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
473 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
474 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
475 -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus \
476 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
477 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
478 %{traditional-cpp:-traditional} %{trigraphs}\
479 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
480 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
481 %{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.i} %1 %2\
482 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
483 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
484 %{v:-version} %{pg:-p} %{p} %{f*}\
486 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
487 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
488 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
489 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
490 %{!pipe:%g.s} %A\n }}}}"},
491 {".i", "@cpp-output"},
493 "cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
494 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
495 %{v:-version} %{pg:-p} %{p} %{f*}\
497 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
498 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
499 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
500 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %{!pipe:%g.s} %A\n }"},
501 {".ii", "@c++-cpp-output"},
503 "cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
504 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
505 %{v:-version} %{pg:-p} %{p} %{f*}\
507 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
508 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
509 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
510 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
511 %{!pipe:%g.s} %A\n }"},
512 {".s", "@assembler"},
514 "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
515 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %i %A\n }"},
516 {".S", "@assembler-with-cpp"},
517 {"@assembler-with-cpp",
518 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P} %I\
519 %{C:%{!E:%eGNU C does not support -C without using -E}}\
520 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \
521 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
522 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
523 %{traditional-cpp:-traditional}\
524 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
525 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
526 %{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
527 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
528 %{!pipe:%g.s} %A\n }}}}"},
529 /* Mark end of table */
533 /* Number of elements in default_compilers, not counting the terminator. */
535 static int n_default_compilers
536 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
538 /* Here is the spec for running the linker, after compiling all files. */
540 #ifdef LINK_LIBGCC_SPECIAL
541 /* Have gcc do the search. */
542 /* -u* was put back because both BSD and SysV seem to support it. */
543 static char *link_command_spec
= "\
544 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
545 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
546 %{!A:%{!nostdlib:%S}} \
547 %{L*} %D %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}";
549 /* Use -l and have the linker do the search. */
550 static char *link_command_spec
= "\
551 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
552 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
553 %{!A:%{!nostdlib:%S}} \
554 %{L*} %D %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}";
557 /* A vector of options to give to the linker.
558 These options are accumulated by %x
559 and substituted into the linker command with %X. */
560 static int n_linker_options
;
561 static char **linker_options
;
563 /* Read compilation specs from a file named FILENAME,
564 replacing the default ones.
566 A suffix which starts with `*' is a definition for
567 one of the machine-specific sub-specs. The "suffix" should be
568 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
569 The corresponding spec is stored in asm_spec, etc.,
570 rather than in the `compilers' vector.
572 Anything invalid in the file is a fatal error. */
575 read_specs (filename
)
584 fprintf (stderr
, "Reading specs from %s\n", filename
);
586 /* Open and stat the file. */
587 desc
= open (filename
, 0, 0);
589 pfatal_with_name (filename
);
590 if (stat (filename
, &statbuf
) < 0)
591 pfatal_with_name (filename
);
593 /* Read contents of file into BUFFER. */
594 buffer
= xmalloc (statbuf
.st_size
+ 1);
595 read (desc
, buffer
, statbuf
.st_size
);
596 buffer
[statbuf
.st_size
] = 0;
599 /* Scan BUFFER for specs, putting them in the vector. */
605 char *in
, *out
, *p1
, *p2
;
607 /* Advance P in BUFFER to the next nonblank nocomment line. */
608 p
= skip_whitespace (p
);
612 /* Find the colon that should end the suffix. */
614 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
615 /* The colon shouldn't be missing. */
617 fatal ("specs file malformed after %d characters", p1
- buffer
);
618 /* Skip back over trailing whitespace. */
620 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
621 /* Copy the suffix to a string. */
622 suffix
= save_string (p
, p2
- p
);
623 /* Find the next line. */
624 p
= skip_whitespace (p1
+ 1);
626 fatal ("specs file malformed after %d characters", p
- buffer
);
628 /* Find next blank line. */
629 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
630 /* Specs end at the blank line and do not include the newline. */
631 spec
= save_string (p
, p1
- p
);
634 /* Delete backslash-newline sequences from the spec. */
639 if (in
[0] == '\\' && in
[1] == '\n')
641 else if (in
[0] == '#')
643 while (*in
&& *in
!= '\n') in
++;
650 if (suffix
[0] == '*')
652 if (! strcmp (suffix
, "*link_command"))
653 link_command_spec
= spec
;
655 set_spec (suffix
+ 1, spec
);
659 /* Add this pair to the vector. */
661 = ((struct compiler
*)
662 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
663 compilers
[n_compilers
].suffix
= suffix
;
664 compilers
[n_compilers
].spec
= spec
;
669 link_command_spec
= spec
;
672 if (link_command_spec
== 0)
673 fatal ("spec file has no spec for linking");
682 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
683 be considered whitespace. */
684 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
686 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
690 while (*p
!= '\n') p
++;
700 /* Structure to keep track of the specs that have been defined so far. These
701 are accessed using %(specname) or %[specname] in a compiler or link spec. */
705 char *name
; /* Name of the spec. */
706 char *spec
; /* The spec itself. */
707 struct spec_list
*next
; /* Next spec in linked list. */
710 /* List of specs that have been defined so far. */
712 static struct spec_list
*specs
= (struct spec_list
*) 0;
714 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
715 removed; If the spec starts with a + then SPEC is added to the end of the
719 set_spec (name
, spec
)
723 struct spec_list
*sl
;
726 /* See if the spec already exists */
727 for (sl
= specs
; sl
; sl
= sl
->next
)
728 if (strcmp (sl
->name
, name
) == 0)
733 /* Not found - make it */
734 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
735 sl
->name
= save_string (name
, strlen (name
));
736 sl
->spec
= save_string ("", 0);
742 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
743 sl
->spec
= concat (name
, spec
+ 1, "");
745 sl
->spec
= save_string (spec
, strlen (spec
));
747 if (! strcmp (name
, "asm"))
749 else if (! strcmp (name
, "asm_final"))
750 asm_final_spec
= sl
->spec
;
751 else if (! strcmp (name
, "cc1"))
753 else if (! strcmp (name
, "cc1plus"))
754 cc1plus_spec
= sl
->spec
;
755 else if (! strcmp (name
, "cpp"))
757 else if (! strcmp (name
, "endfile"))
758 endfile_spec
= sl
->spec
;
759 else if (! strcmp (name
, "lib"))
761 else if (! strcmp (name
, "link"))
762 link_spec
= sl
->spec
;
763 else if (! strcmp (name
, "predefines"))
764 cpp_predefines
= sl
->spec
;
765 else if (! strcmp (name
, "signed_char"))
766 signed_char_spec
= sl
->spec
;
767 else if (! strcmp (name
, "startfile"))
768 startfile_spec
= sl
->spec
;
769 else if (! strcmp (name
, "switches_need_spaces"))
770 switches_need_spaces
= sl
->spec
;
771 else if (! strcmp (name
, "cross_compile"))
772 cross_compile
= atoi (sl
->spec
);
773 /* Free the old spec */
778 /* Accumulate a command (program name and args), and run it. */
780 /* Vector of pointers to arguments in the current line of specifications. */
782 static char **argbuf
;
784 /* Number of elements allocated in argbuf. */
786 static int argbuf_length
;
788 /* Number of elements in argbuf currently in use (containing args). */
790 static int argbuf_index
;
792 /* Number of commands executed so far. */
794 static int execution_count
;
796 /* Name with which this program was invoked. */
798 static char *programname
;
800 /* Structures to keep track of prefixes to try when looking for files. */
804 char *prefix
; /* String to prepend to the path. */
805 struct prefix_list
*next
; /* Next in linked list. */
806 int require_machine_suffix
; /* Don't use without machine_suffix. */
807 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
812 struct prefix_list
*plist
; /* List of prefixes to try */
813 int max_len
; /* Max length of a prefix in PLIST */
814 char *name
; /* Name of this list (used in config stuff) */
817 /* List of prefixes to try when looking for executables. */
819 static struct path_prefix exec_prefix
= { 0, 0, "exec" };
821 /* List of prefixes to try when looking for startup (crt0) files. */
823 static struct path_prefix startfile_prefix
= { 0, 0, "startfile" };
825 /* List of prefixes to try when looking for libraries. */
827 static struct path_prefix library_prefix
= { 0, 0, "libraryfile" };
829 /* Suffix to attach to directories searched for commands. */
831 static char *machine_suffix
= 0;
833 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
835 static char *gcc_exec_prefix
;
837 /* Default prefixes to attach to command names. */
839 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
840 #undef MD_EXEC_PREFIX
841 #undef MD_STARTFILE_PREFIX
844 #ifndef STANDARD_EXEC_PREFIX
845 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
846 #endif /* !defined STANDARD_EXEC_PREFIX */
848 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
849 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
850 #ifdef MD_EXEC_PREFIX
851 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
854 #ifndef STANDARD_STARTFILE_PREFIX
855 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
856 #endif /* !defined STANDARD_STARTFILE_PREFIX */
858 #ifdef MD_STARTFILE_PREFIX
859 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
861 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
862 static char *standard_startfile_prefix_1
= "/lib/";
863 static char *standard_startfile_prefix_2
= "/usr/lib/";
865 /* Clear out the vector of arguments (after a command is executed). */
873 /* Add one argument to the vector at the end.
874 This is done when a space is seen or at the end of the line.
875 If DELETE_ALWAYS is nonzero, the arg is a filename
876 and the file should be deleted eventually.
877 If DELETE_FAILURE is nonzero, the arg is a filename
878 and the file should be deleted if this compilation fails. */
881 store_arg (arg
, delete_always
, delete_failure
)
883 int delete_always
, delete_failure
;
885 if (argbuf_index
+ 1 == argbuf_length
)
887 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
890 argbuf
[argbuf_index
++] = arg
;
891 argbuf
[argbuf_index
] = 0;
893 if (delete_always
|| delete_failure
)
894 record_temp_file (arg
, delete_always
, delete_failure
);
897 /* Record the names of temporary files we tell compilers to write,
898 and delete them at the end of the run. */
900 /* This is the common prefix we use to make temp file names.
901 It is chosen once for each run of this program.
902 It is substituted into a spec by %g.
903 Thus, all temp file names contain this prefix.
904 In practice, all temp file names start with this prefix.
906 This prefix comes from the envvar TMPDIR if it is defined;
907 otherwise, from the P_tmpdir macro if that is defined;
908 otherwise, in /usr/tmp or /tmp. */
910 static char *temp_filename
;
912 /* Length of the prefix. */
914 static int temp_filename_length
;
916 /* Define the list of temporary files to delete. */
921 struct temp_file
*next
;
924 /* Queue of files to delete on success or failure of compilation. */
925 static struct temp_file
*always_delete_queue
;
926 /* Queue of files to delete on failure of compilation. */
927 static struct temp_file
*failure_delete_queue
;
929 /* Record FILENAME as a file to be deleted automatically.
930 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
931 otherwise delete it in any case.
932 FAIL_DELETE nonzero means delete it if a compilation step fails;
933 otherwise delete it in any case. */
936 record_temp_file (filename
, always_delete
, fail_delete
)
942 name
= xmalloc (strlen (filename
) + 1);
943 strcpy (name
, filename
);
947 register struct temp_file
*temp
;
948 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
949 if (! strcmp (name
, temp
->name
))
951 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
952 temp
->next
= always_delete_queue
;
954 always_delete_queue
= temp
;
960 register struct temp_file
*temp
;
961 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
962 if (! strcmp (name
, temp
->name
))
964 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
965 temp
->next
= failure_delete_queue
;
967 failure_delete_queue
= temp
;
972 /* Delete all the temporary files whose names we previously recorded. */
977 register struct temp_file
*temp
;
979 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
983 printf ("Delete %s? (y or n) ", temp
->name
);
987 while (getchar () != '\n') ;
988 if (i
== 'y' || i
== 'Y')
992 if (stat (temp
->name
, &st
) >= 0)
994 /* Delete only ordinary files. */
995 if (S_ISREG (st
.st_mode
))
996 if (unlink (temp
->name
) < 0)
998 perror_with_name (temp
->name
);
1003 always_delete_queue
= 0;
1006 /* Delete all the files to be deleted on error. */
1009 delete_failure_queue ()
1011 register struct temp_file
*temp
;
1013 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1017 printf ("Delete %s? (y or n) ", temp
->name
);
1021 while (getchar () != '\n') ;
1022 if (i
== 'y' || i
== 'Y')
1025 if (unlink (temp
->name
) < 0)
1027 perror_with_name (temp
->name
);
1033 clear_failure_queue ()
1035 failure_delete_queue
= 0;
1038 /* Compute a string to use as the base of all temporary file names.
1039 It is substituted for %g. */
1044 char *base
= getenv ("TMPDIR");
1047 if (base
== (char *)0)
1050 if (access (P_tmpdir
, R_OK
| W_OK
) == 0)
1053 if (base
== (char *)0)
1055 if (access ("/usr/tmp", R_OK
| W_OK
) == 0)
1062 len
= strlen (base
);
1063 temp_filename
= xmalloc (len
+ sizeof("/ccXXXXXX"));
1064 strcpy (temp_filename
, base
);
1065 if (len
> 0 && temp_filename
[len
-1] != '/')
1066 temp_filename
[len
++] = '/';
1067 strcpy (temp_filename
+ len
, "ccXXXXXX");
1069 mktemp (temp_filename
);
1070 temp_filename_length
= strlen (temp_filename
);
1074 /* Routine to add variables to the environment. We do this to pass
1075 the pathname of the gcc driver, and the directories search to the
1076 collect2 program, which is being run as ld. This way, we can be
1077 sure of executing the right compiler when collect2 wants to build
1078 constructors and destructors. Since the environment variables we
1079 use come from an obstack, we don't have to worry about allocating
1087 #ifndef VMS /* nor about VMS */
1089 extern char **environ
;
1090 char **old_environ
= environ
;
1094 int str_len
= strlen (str
);
1098 while ((ch
= *p
++) != '\0' && ch
!= '=')
1104 /* Search for replacing an existing environment variable, and
1105 count the number of total environment variables. */
1106 for (envp
= old_environ
; *envp
; envp
++)
1109 if (!strncmp (str
, *envp
, name_len
))
1116 /* Add a new environment variable */
1117 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1119 bcopy (old_environ
, environ
+1, sizeof (char *) * (num_envs
+1));
1124 #endif /* HAVE_PUTENV */
1127 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1130 putenv_from_prefixes (paths
, env_var
)
1131 struct path_prefix
*paths
;
1134 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1135 int first_time
= TRUE
;
1136 struct prefix_list
*pprefix
;
1138 obstack_grow (&collect_obstack
, env_var
, strlen (env_var
));
1140 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1142 int len
= strlen (pprefix
->prefix
);
1147 obstack_grow (&collect_obstack
, ":", 1);
1150 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1151 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1154 if (!pprefix
->require_machine_suffix
)
1157 obstack_grow (&collect_obstack
, ":", 1);
1160 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1163 obstack_grow (&collect_obstack
, "\0", 1);
1164 putenv (obstack_finish (&collect_obstack
));
1168 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1169 access to check permissions.
1170 Return 0 if not found, otherwise return its name, allocated with malloc. */
1173 find_a_file (pprefix
, name
, mode
)
1174 struct path_prefix
*pprefix
;
1179 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1180 struct prefix_list
*pl
;
1181 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1184 len
+= strlen (machine_suffix
);
1186 temp
= xmalloc (len
);
1188 /* Determine the filename to execute (special case for absolute paths). */
1192 if (access (name
, mode
))
1194 strcpy (temp
, name
);
1199 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1203 strcpy (temp
, pl
->prefix
);
1204 strcat (temp
, machine_suffix
);
1205 strcat (temp
, name
);
1206 if (access (temp
, mode
) == 0)
1208 if (pl
->used_flag_ptr
!= 0)
1209 *pl
->used_flag_ptr
= 1;
1212 /* Some systems have a suffix for executable files.
1213 So try appending that. */
1214 if (file_suffix
[0] != 0)
1216 strcat (temp
, file_suffix
);
1217 if (access (temp
, mode
) == 0)
1219 if (pl
->used_flag_ptr
!= 0)
1220 *pl
->used_flag_ptr
= 1;
1225 /* Certain prefixes can't be used without the machine suffix
1226 when the machine or version is explicitly specified. */
1227 if (!pl
->require_machine_suffix
)
1229 strcpy (temp
, pl
->prefix
);
1230 strcat (temp
, name
);
1231 if (access (temp
, mode
) == 0)
1233 if (pl
->used_flag_ptr
!= 0)
1234 *pl
->used_flag_ptr
= 1;
1237 /* Some systems have a suffix for executable files.
1238 So try appending that. */
1239 if (file_suffix
[0] != 0)
1241 strcat (temp
, file_suffix
);
1242 if (access (temp
, mode
) == 0)
1244 if (pl
->used_flag_ptr
!= 0)
1245 *pl
->used_flag_ptr
= 1;
1256 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1257 at the start of the list, otherwise it goes at the end.
1259 If WARN is nonzero, we will warn if no file is found
1260 through this prefix. WARN should point to an int
1261 which will be set to 1 if this entry is used. */
1264 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1265 struct path_prefix
*pprefix
;
1268 int require_machine_suffix
;
1271 struct prefix_list
*pl
, **prev
;
1274 if (!first
&& pprefix
->plist
)
1276 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1281 prev
= &pprefix
->plist
;
1283 /* Keep track of the longest prefix */
1285 len
= strlen (prefix
);
1286 if (len
> pprefix
->max_len
)
1287 pprefix
->max_len
= len
;
1289 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1290 pl
->prefix
= save_string (prefix
, len
);
1291 pl
->require_machine_suffix
= require_machine_suffix
;
1292 pl
->used_flag_ptr
= warn
;
1299 pl
->next
= (struct prefix_list
*) 0;
1303 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1306 unused_prefix_warnings (pprefix
)
1307 struct path_prefix
*pprefix
;
1309 struct prefix_list
*pl
= pprefix
->plist
;
1313 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1315 error ("file path prefix `%s' never used",
1317 /* Prevent duplicate warnings. */
1318 *pl
->used_flag_ptr
= 1;
1324 /* Get rid of all prefixes built up so far in *PLISTP. */
1327 free_path_prefix (pprefix
)
1328 struct path_prefix
*pprefix
;
1330 struct prefix_list
*pl
= pprefix
->plist
;
1331 struct prefix_list
*temp
;
1337 free (temp
->prefix
);
1338 free ((char *) temp
);
1340 pprefix
->plist
= (struct prefix_list
*) 0;
1343 /* stdin file number. */
1344 #define STDIN_FILE_NO 0
1346 /* stdout file number. */
1347 #define STDOUT_FILE_NO 1
1349 /* value of `pipe': port index for reading. */
1352 /* value of `pipe': port index for writing. */
1353 #define WRITE_PORT 1
1355 /* Pipe waiting from last process, to be used as input for the next one.
1356 Value is STDIN_FILE_NO if no pipe is waiting
1357 (i.e. the next command is the first of a group). */
1359 static int last_pipe_input
;
1361 /* Fork one piped subcommand. FUNC is the system call to use
1362 (either execv or execvp). ARGV is the arg vector to use.
1363 NOT_LAST is nonzero if this is not the last subcommand
1364 (i.e. its output should be piped to the next one.) */
1368 /* Declare these to avoid compilation error. They won't be called. */
1369 int execv(const char *a
, const char **b
){}
1370 int execvp(const char *a
, const char **b
){}
1373 pexecute (func
, program
, argv
, not_last
)
1383 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6);
1384 sprintf (scmd
, "%s @%s.gp", program
, temp_filename
);
1385 argfile
= fopen (scmd
+strlen (program
) + 2, "w");
1387 pfatal_with_name (scmd
+ strlen (program
) + 2);
1389 for (i
=1; argv
[i
]; i
++)
1392 for (cp
= argv
[i
]; *cp
; cp
++)
1394 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
1395 fputc ('\\', argfile
);
1396 fputc (*cp
, argfile
);
1398 fputc ('\n', argfile
);
1404 remove (scmd
+ strlen (program
) + 2);
1408 #else /* not __MSDOS__ */
1411 pexecute (func
, program
, argv
, not_last
)
1419 int input_desc
= last_pipe_input
;
1420 int output_desc
= STDOUT_FILE_NO
;
1421 int retries
, sleep_interval
;
1423 /* If this isn't the last process, make a pipe for its output,
1424 and record it as waiting to be the input to the next process. */
1428 if (pipe (pdes
) < 0)
1429 pfatal_with_name ("pipe");
1430 output_desc
= pdes
[WRITE_PORT
];
1431 last_pipe_input
= pdes
[READ_PORT
];
1434 last_pipe_input
= STDIN_FILE_NO
;
1436 /* Fork a subprocess; wait and retry if it fails. */
1438 for (retries
= 0; retries
< 4; retries
++)
1443 sleep (sleep_interval
);
1444 sleep_interval
*= 2;
1451 pfatal_with_name ("fork");
1453 pfatal_with_name ("vfork");
1459 /* Move the input and output pipes into place, if nec. */
1460 if (input_desc
!= STDIN_FILE_NO
)
1462 close (STDIN_FILE_NO
);
1466 if (output_desc
!= STDOUT_FILE_NO
)
1468 close (STDOUT_FILE_NO
);
1470 close (output_desc
);
1473 /* Close the parent's descs that aren't wanted here. */
1474 if (last_pipe_input
!= STDIN_FILE_NO
)
1475 close (last_pipe_input
);
1477 /* Exec the program. */
1478 (*func
) (program
, argv
);
1479 perror_exec (program
);
1485 /* In the parent, after forking.
1486 Close the descriptors that we made for this child. */
1487 if (input_desc
!= STDIN_FILE_NO
)
1489 if (output_desc
!= STDOUT_FILE_NO
)
1490 close (output_desc
);
1492 /* Return child's process number. */
1497 #endif /* not __MSDOS__ */
1499 /* Execute the command specified by the arguments on the current line of spec.
1500 When using pipes, this includes several piped-together commands
1501 with `|' between them.
1503 Return 0 if successful, -1 if failed. */
1509 int n_commands
; /* # of command. */
1513 char *prog
; /* program name. */
1514 char **argv
; /* vector of args. */
1515 int pid
; /* pid of process for this command. */
1518 struct command
*commands
; /* each command buffer with above info. */
1520 /* Count # of piped commands. */
1521 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
1522 if (strcmp (argbuf
[i
], "|") == 0)
1525 /* Get storage for each command. */
1527 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
1529 /* Split argbuf into its separate piped processes,
1530 and record info about each one.
1531 Also search for the programs that are to be run. */
1533 commands
[0].prog
= argbuf
[0]; /* first command. */
1534 commands
[0].argv
= &argbuf
[0];
1535 string
= find_a_file (&exec_prefix
, commands
[0].prog
, X_OK
);
1537 commands
[0].argv
[0] = string
;
1539 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
1540 if (strcmp (argbuf
[i
], "|") == 0)
1541 { /* each command. */
1543 fatal ("-pipe not supported under MS-DOS");
1545 argbuf
[i
] = 0; /* termination of command args. */
1546 commands
[n_commands
].prog
= argbuf
[i
+ 1];
1547 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
1548 string
= find_a_file (&exec_prefix
, commands
[n_commands
].prog
, X_OK
);
1550 commands
[n_commands
].argv
[0] = string
;
1554 argbuf
[argbuf_index
] = 0;
1556 /* If -v, print what we are about to do, and maybe query. */
1560 /* Print each piped command as a separate line. */
1561 for (i
= 0; i
< n_commands
; i
++)
1565 for (j
= commands
[i
].argv
; *j
; j
++)
1566 fprintf (stderr
, " %s", *j
);
1568 /* Print a pipe symbol after all but the last command. */
1569 if (i
+ 1 != n_commands
)
1570 fprintf (stderr
, " |");
1571 fprintf (stderr
, "\n");
1575 fprintf (stderr
, "\nGo ahead? (y or n) ");
1579 while (getchar () != '\n') ;
1580 if (i
!= 'y' && i
!= 'Y')
1585 /* Run each piped subprocess. */
1587 last_pipe_input
= STDIN_FILE_NO
;
1588 for (i
= 0; i
< n_commands
; i
++)
1590 char *string
= commands
[i
].argv
[0];
1592 commands
[i
].pid
= pexecute ((string
!= commands
[i
].prog
? execv
: execvp
),
1593 string
, commands
[i
].argv
,
1594 i
+ 1 < n_commands
);
1596 if (string
!= commands
[i
].prog
)
1602 /* Wait for all the subprocesses to finish.
1603 We don't care what order they finish in;
1604 we know that N_COMMANDS waits will get them all. */
1609 for (i
= 0; i
< n_commands
; i
++)
1616 status
= pid
= commands
[i
].pid
;
1618 pid
= wait (&status
);
1626 for (j
= 0; j
< n_commands
; j
++)
1627 if (commands
[j
].pid
== pid
)
1628 prog
= commands
[j
].prog
;
1630 if ((status
& 0x7F) != 0)
1631 fatal ("Internal compiler error: program %s got fatal signal %d",
1632 prog
, (status
& 0x7F));
1633 if (((status
& 0xFF00) >> 8) >= MIN_FATAL_STATUS
)
1641 /* Find all the switches given to us
1642 and make a vector describing them.
1643 The elements of the vector are strings, one per switch given.
1644 If a switch uses following arguments, then the `part1' field
1645 is the switch itself and the `args' field
1646 is a null-terminated vector containing the following arguments.
1647 The `valid' field is nonzero if any spec has looked at this switch;
1648 if it remains zero at the end of the run, it must be meaningless. */
1657 static struct switchstr
*switches
;
1659 static int n_switches
;
1667 /* Also a vector of input files specified. */
1669 static struct infile
*infiles
;
1671 static int n_infiles
;
1673 /* And a vector of corresponding output files is made up later. */
1675 static char **outfiles
;
1677 /* Create the vector `switches' and its contents.
1678 Store its length in `n_switches'. */
1681 process_command (argc
, argv
)
1687 char *spec_lang
= 0;
1688 int last_language_n_infiles
;
1690 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
1694 spec_version
= version_string
;
1696 /* Set up the default search paths. */
1698 if (gcc_exec_prefix
)
1700 add_prefix (&exec_prefix
, gcc_exec_prefix
, 0, 0, 0);
1701 add_prefix (&startfile_prefix
, gcc_exec_prefix
, 0, 0, 0);
1704 /* COMPILER_PATH and LIBRARY_PATH have values
1705 that are lists of directory names with colons. */
1707 temp
= getenv ("COMPILER_PATH");
1710 char *startp
, *endp
;
1711 char *nstore
= (char *) alloca (strlen (temp
) + 3);
1713 startp
= endp
= temp
;
1716 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
1718 strncpy (nstore
, startp
, endp
-startp
);
1721 strcpy (nstore
, "./");
1723 else if (endp
[-1] != '/')
1725 nstore
[endp
-startp
] = '/';
1726 nstore
[endp
-startp
+1] = 0;
1729 nstore
[endp
-startp
] = 0;
1730 add_prefix (&exec_prefix
, nstore
, 0, 0, 0);
1733 endp
= startp
= endp
+ 1;
1740 temp
= getenv ("LIBRARY_PATH");
1743 char *startp
, *endp
;
1744 char *nstore
= (char *) alloca (strlen (temp
) + 3);
1746 startp
= endp
= temp
;
1749 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
1751 strncpy (nstore
, startp
, endp
-startp
);
1754 strcpy (nstore
, "./");
1756 else if (endp
[-1] != '/')
1758 nstore
[endp
-startp
] = '/';
1759 nstore
[endp
-startp
+1] = 0;
1762 nstore
[endp
-startp
] = 0;
1763 add_prefix (&startfile_prefix
, nstore
, 0, 0, 0);
1764 /* Make separate list of dirs that came from LIBRARY_PATH. */
1765 add_prefix (&library_prefix
, nstore
, 0, 0, 0);
1768 endp
= startp
= endp
+ 1;
1775 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
1776 temp
= getenv ("LPATH");
1779 char *startp
, *endp
;
1780 char *nstore
= (char *) alloca (strlen (temp
) + 3);
1782 startp
= endp
= temp
;
1785 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
1787 strncpy (nstore
, startp
, endp
-startp
);
1790 strcpy (nstore
, "./");
1792 else if (endp
[-1] != '/')
1794 nstore
[endp
-startp
] = '/';
1795 nstore
[endp
-startp
+1] = 0;
1798 nstore
[endp
-startp
] = 0;
1799 add_prefix (&startfile_prefix
, nstore
, 0, 0, 0);
1800 /* Make separate list of dirs that came from LIBRARY_PATH. */
1801 add_prefix (&library_prefix
, nstore
, 0, 0, 0);
1804 endp
= startp
= endp
+ 1;
1811 /* Scan argv twice. Here, the first time, just count how many switches
1812 there will be in their vector, and how many input files in theirs.
1813 Here we also parse the switches that cc itself uses (e.g. -v). */
1815 for (i
= 1; i
< argc
; i
++)
1817 if (! strcmp (argv
[i
], "-dumpspecs"))
1819 printf ("*asm:\n%s\n\n", asm_spec
);
1820 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
1821 printf ("*cpp:\n%s\n\n", cpp_spec
);
1822 printf ("*cc1:\n%s\n\n", cc1_spec
);
1823 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
1824 printf ("*endfile:\n%s\n\n", endfile_spec
);
1825 printf ("*link:\n%s\n\n", link_spec
);
1826 printf ("*lib:\n%s\n\n", lib_spec
);
1827 printf ("*startfile:\n%s\n\n", startfile_spec
);
1828 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
1829 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
1830 printf ("*predefines:\n%s\n\n", cpp_predefines
);
1831 printf ("*cross_compile:\n%d\n\n", cross_compile
);
1835 else if (! strcmp (argv
[i
], "-dumpversion"))
1837 printf ("%s\n", version_string
);
1840 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
1842 print_libgcc_file_name
= 1;
1844 else if (! strcmp (argv
[i
], "-Xlinker"))
1846 /* Pass the argument of this option to the linker when we link. */
1849 fatal ("argument to `-Xlinker' is missing");
1852 if (!linker_options
)
1854 = (char **) xmalloc (n_linker_options
* sizeof (char **));
1857 = (char **) xrealloc (linker_options
,
1858 n_linker_options
* sizeof (char **));
1860 linker_options
[n_linker_options
- 1] = argv
[++i
];
1862 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
1864 register char *p
= &argv
[i
][1];
1865 register int c
= *p
;
1870 if (p
[1] == 0 && i
+ 1 == argc
)
1871 fatal ("argument to `-b' is missing");
1873 spec_machine
= argv
[++i
];
1875 spec_machine
= p
+ 1;
1880 int *temp
= (int *) xmalloc (sizeof (int));
1882 if (p
[1] == 0 && i
+ 1 == argc
)
1883 fatal ("argument to `-B' is missing");
1888 add_prefix (&exec_prefix
, value
, 1, 0, temp
);
1889 add_prefix (&startfile_prefix
, value
, 1, 0, temp
);
1893 case 'v': /* Print our subcommands and print versions. */
1899 if (p
[1] == 0 && i
+ 1 == argc
)
1900 fatal ("argument to `-V' is missing");
1902 spec_version
= argv
[++i
];
1904 spec_version
= p
+ 1;
1908 if (!strcmp (p
, "save-temps"))
1910 save_temps_flag
= 1;
1917 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1918 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1919 else if (WORD_SWITCH_TAKES_ARG (p
))
1920 i
+= WORD_SWITCH_TAKES_ARG (p
);
1927 /* Set up the search paths before we go looking for config files. */
1929 /* These come before the md prefixes so that we will find gcc's subcommands
1930 (such as cpp) rather than those of the host system. */
1931 add_prefix (&exec_prefix
, standard_exec_prefix
, 0, 1, 0);
1932 add_prefix (&exec_prefix
, standard_exec_prefix_1
, 0, 1, 0);
1934 add_prefix (&startfile_prefix
, standard_exec_prefix
, 0, 1, 0);
1935 add_prefix (&startfile_prefix
, standard_exec_prefix_1
, 0, 1, 0);
1937 /* More prefixes are enabled in main, after we read the specs file
1938 and determine whether this is cross-compilation or not. */
1941 /* Then create the space for the vectors and scan again. */
1943 switches
= ((struct switchstr
*)
1944 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
1945 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
1948 last_language_n_infiles
= -1;
1950 /* This, time, copy the text of each switch and store a pointer
1951 to the copy in the vector of switches.
1952 Store all the infiles in their vector. */
1954 for (i
= 1; i
< argc
; i
++)
1956 if (!strcmp (argv
[i
], "-Xlinker"))
1958 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
1960 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
1962 register char *p
= &argv
[i
][1];
1963 register int c
= *p
;
1965 if (c
== 'B' || c
== 'b' || c
== 'V')
1967 /* Skip a separate arg, if any. */
1974 if (p
[1] == 0 && i
+ 1 == argc
)
1975 fatal ("argument to `-x' is missing");
1977 spec_lang
= argv
[++i
];
1980 if (! strcmp (spec_lang
, "none"))
1981 /* Suppress the warning if -xnone comes after the last input file,
1982 because alternate command interfaces like g++ might find it
1983 useful to place -xnone after each input file. */
1986 last_language_n_infiles
= n_infiles
;
1989 switches
[n_switches
].part1
= p
;
1990 /* Deal with option arguments in separate argv elements. */
1991 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1992 || WORD_SWITCH_TAKES_ARG (p
)) {
1994 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
1997 /* Count only the option arguments in separate argv elements. */
1998 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2000 switches
[n_switches
].args
2001 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2003 switches
[n_switches
].args
[j
++] = argv
[++i
];
2004 /* Null-terminate the vector. */
2005 switches
[n_switches
].args
[j
] = 0;
2006 } else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L')) {
2007 /* On some systems, ld cannot handle -o or -L without space.
2008 So split the -o or -L from its argument. */
2009 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2010 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2011 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2012 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2013 switches
[n_switches
].args
[1] = 0;
2015 switches
[n_switches
].args
= 0;
2016 switches
[n_switches
].valid
= 0;
2017 /* This is always valid, since gcc.c itself understands it. */
2018 if (!strcmp (p
, "save-temps"))
2019 switches
[n_switches
].valid
= 1;
2024 infiles
[n_infiles
].language
= spec_lang
;
2025 infiles
[n_infiles
++].name
= argv
[i
];
2029 if (n_infiles
== last_language_n_infiles
)
2030 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2032 switches
[n_switches
].part1
= 0;
2033 infiles
[n_infiles
].name
= 0;
2035 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2036 if (gcc_exec_prefix
)
2038 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2039 + strlen (spec_machine
) + 3);
2040 strcpy (temp
, gcc_exec_prefix
);
2041 strcat (temp
, spec_version
);
2043 strcat (temp
, spec_machine
);
2045 gcc_exec_prefix
= temp
;
2049 /* Process a spec string, accumulating and running commands. */
2051 /* These variables describe the input file name.
2052 input_file_number is the index on outfiles of this file,
2053 so that the output file name can be stored for later use by %o.
2054 input_basename is the start of the part of the input file
2055 sans all directory names, and basename_length is the number
2056 of characters starting there excluding the suffix .c or whatever. */
2058 static char *input_filename
;
2059 static int input_file_number
;
2060 static int input_filename_length
;
2061 static int basename_length
;
2062 static char *input_basename
;
2063 static char *input_suffix
;
2065 /* These are variables used within do_spec and do_spec_1. */
2067 /* Nonzero if an arg has been started and not yet terminated
2068 (with space, tab or newline). */
2069 static int arg_going
;
2071 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2072 is a temporary file name. */
2073 static int delete_this_arg
;
2075 /* Nonzero means %w has been seen; the next arg to be terminated
2076 is the output file name of this compilation. */
2077 static int this_is_output_file
;
2079 /* Nonzero means %s has been seen; the next arg to be terminated
2080 is the name of a library file and we should try the standard
2081 search dirs for it. */
2082 static int this_is_library_file
;
2084 /* Process the spec SPEC and run the commands specified therein.
2085 Returns 0 if the spec is successfully processed; -1 if failed. */
2095 delete_this_arg
= 0;
2096 this_is_output_file
= 0;
2097 this_is_library_file
= 0;
2099 value
= do_spec_1 (spec
, 0, NULL
);
2101 /* Force out any unfinished command.
2102 If -pipe, this forces out the last command if it ended in `|'. */
2105 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2108 if (argbuf_index
> 0)
2115 /* Process the sub-spec SPEC as a portion of a larger spec.
2116 This is like processing a whole spec except that we do
2117 not initialize at the beginning and we do not supply a
2118 newline by default at the end.
2119 INSWITCH nonzero means don't process %-sequences in SPEC;
2120 in this case, % is treated as an ordinary character.
2121 This is used while substituting switches.
2122 INSWITCH nonzero also causes SPC not to terminate an argument.
2124 Value is zero unless a line was finished
2125 and the command on that line reported an error. */
2128 do_spec_1 (spec
, inswitch
, soft_matched_part
)
2131 char *soft_matched_part
;
2133 register char *p
= spec
;
2139 /* If substituting a switch, treat all chars like letters.
2140 Otherwise, NL, SPC, TAB and % are special. */
2141 switch (inswitch
? 'a' : c
)
2144 /* End of line: finish any pending argument,
2145 then run the pending command if one has been started. */
2148 obstack_1grow (&obstack
, 0);
2149 string
= obstack_finish (&obstack
);
2150 if (this_is_library_file
)
2151 string
= find_file (string
);
2152 store_arg (string
, delete_this_arg
, this_is_output_file
);
2153 if (this_is_output_file
)
2154 outfiles
[input_file_number
] = string
;
2158 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2161 for (i
= 0; i
< n_switches
; i
++)
2162 if (!strcmp (switches
[i
].part1
, "pipe"))
2165 /* A `|' before the newline means use a pipe here,
2166 but only if -pipe was specified.
2167 Otherwise, execute now and don't pass the `|' as an arg. */
2170 switches
[i
].valid
= 1;
2177 if (argbuf_index
> 0)
2179 int value
= execute ();
2183 /* Reinitialize for a new command, and for a new argument. */
2186 delete_this_arg
= 0;
2187 this_is_output_file
= 0;
2188 this_is_library_file
= 0;
2192 /* End any pending argument. */
2195 obstack_1grow (&obstack
, 0);
2196 string
= obstack_finish (&obstack
);
2197 if (this_is_library_file
)
2198 string
= find_file (string
);
2199 store_arg (string
, delete_this_arg
, this_is_output_file
);
2200 if (this_is_output_file
)
2201 outfiles
[input_file_number
] = string
;
2205 obstack_1grow (&obstack
, c
);
2211 /* Space or tab ends an argument if one is pending. */
2214 obstack_1grow (&obstack
, 0);
2215 string
= obstack_finish (&obstack
);
2216 if (this_is_library_file
)
2217 string
= find_file (string
);
2218 store_arg (string
, delete_this_arg
, this_is_output_file
);
2219 if (this_is_output_file
)
2220 outfiles
[input_file_number
] = string
;
2222 /* Reinitialize for a new argument. */
2224 delete_this_arg
= 0;
2225 this_is_output_file
= 0;
2226 this_is_library_file
= 0;
2233 fatal ("Invalid specification! Bug in cc.");
2236 obstack_grow (&obstack
, input_basename
, basename_length
);
2241 delete_this_arg
= 2;
2244 /* Dump out the directories specified with LIBRARY_PATH,
2245 followed by the absolute directories
2246 that we search for startfiles. */
2248 for (i
= 0; i
< 2; i
++)
2250 struct prefix_list
*pl
2251 = (i
== 0 ? library_prefix
.plist
: startfile_prefix
.plist
);
2253 char *buffer
= (char *) xmalloc (bufsize
);
2256 for (; pl
; pl
= pl
->next
)
2258 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2259 /* Used on systems which record the specified -L dirs
2260 and use them to search for dynamic linking. */
2261 /* Relative directories always come from -B,
2262 and it is better not to use them for searching
2263 at run time. In particular, stage1 loses */
2264 if (pl
->prefix
[0] != '/')
2269 if (is_linker_dir (pl
->prefix
, machine_suffix
))
2271 do_spec_1 ("-L", 0, 0);
2272 #ifdef SPACE_AFTER_L_OPTION
2273 do_spec_1 (" ", 0, 0);
2275 do_spec_1 (pl
->prefix
, 1, 0);
2276 /* Remove slash from machine_suffix. */
2277 if (strlen (machine_suffix
) >= bufsize
)
2278 bufsize
= strlen (machine_suffix
) * 2 + 1;
2279 buffer
= (char *) xrealloc (buffer
, bufsize
);
2280 strcpy (buffer
, machine_suffix
);
2281 idx
= strlen (buffer
);
2282 if (buffer
[idx
- 1] == '/')
2283 buffer
[idx
- 1] = 0;
2284 do_spec_1 (buffer
, 1, 0);
2285 /* Make this a separate argument. */
2286 do_spec_1 (" ", 0, 0);
2289 if (!pl
->require_machine_suffix
)
2291 if (is_linker_dir (pl
->prefix
, ""))
2293 do_spec_1 ("-L", 0, 0);
2294 #ifdef SPACE_AFTER_L_OPTION
2295 do_spec_1 (" ", 0, 0);
2297 /* Remove slash from pl->prefix. */
2298 if (strlen (pl
->prefix
) >= bufsize
)
2299 bufsize
= strlen (pl
->prefix
) * 2 + 1;
2300 buffer
= (char *) xrealloc (buffer
, bufsize
);
2301 strcpy (buffer
, pl
->prefix
);
2302 idx
= strlen (buffer
);
2303 if (buffer
[idx
- 1] == '/')
2304 buffer
[idx
- 1] = 0;
2305 do_spec_1 (buffer
, 1, 0);
2306 /* Make this a separate argument. */
2307 do_spec_1 (" ", 0, 0);
2316 /* {...:%efoo} means report an error with `foo' as error message
2317 and don't execute any more commands for this file. */
2321 while (*p
!= 0 && *p
!= '\n') p
++;
2322 buf
= (char *) alloca (p
- q
+ 1);
2323 strncpy (buf
, q
, p
- q
);
2331 if (save_temps_flag
)
2332 obstack_grow (&obstack
, input_basename
, basename_length
);
2335 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
2336 delete_this_arg
= 1;
2342 obstack_grow (&obstack
, input_filename
, input_filename_length
);
2347 if (gcc_exec_prefix
)
2349 do_spec_1 ("-imacros", 1, 0);
2350 /* Make this a separate argument. */
2351 do_spec_1 (" ", 0, 0);
2352 do_spec_1 (gcc_exec_prefix
, 1, 0);
2353 do_spec_1 (" ", 0, 0);
2360 for (f
= 0; f
< n_infiles
; f
++)
2361 store_arg (outfiles
[f
], 0, 0);
2366 this_is_library_file
= 1;
2370 this_is_output_file
= 1;
2375 int index
= argbuf_index
;
2376 /* Handle the {...} following the %W. */
2379 p
= handle_braces (p
+ 1);
2382 /* If any args were output, mark the last one for deletion
2384 if (argbuf_index
!= index
)
2385 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
2389 /* %x{OPTION} records OPTION for %X to output. */
2395 /* Skip past the option value and make a copy. */
2400 string
= save_string (p1
+ 1, p
- p1
- 2);
2402 /* See if we already recorded this option. */
2403 for (i
= 0; i
< n_linker_options
; i
++)
2404 if (! strcmp (string
, linker_options
[i
]))
2410 /* This option is new; add it. */
2412 if (!linker_options
)
2414 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2417 = (char **) xrealloc (linker_options
,
2418 n_linker_options
* sizeof (char **));
2420 linker_options
[n_linker_options
- 1] = string
;
2424 /* Dump out the options accumulated previously using %x. */
2426 for (i
= 0; i
< n_linker_options
; i
++)
2428 do_spec_1 (linker_options
[i
], 1, NULL
);
2429 /* Make each accumulated option a separate argument. */
2430 do_spec_1 (" ", 0, NULL
);
2434 /* Here are digits and numbers that just process
2435 a certain constant string as a spec. */
2438 do_spec_1 (cc1_spec
, 0, NULL
);
2442 do_spec_1 (cc1plus_spec
, 0, NULL
);
2446 do_spec_1 (asm_spec
, 0, NULL
);
2450 do_spec_1 (asm_final_spec
, 0, NULL
);
2454 do_spec_1 (signed_char_spec
, 0, NULL
);
2458 do_spec_1 (cpp_spec
, 0, NULL
);
2462 do_spec_1 (endfile_spec
, 0, NULL
);
2466 do_spec_1 (link_spec
, 0, NULL
);
2470 do_spec_1 (lib_spec
, 0, NULL
);
2475 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
2479 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
2483 if (! strncmp (y
, "-D", 2))
2484 /* Copy the whole option. */
2485 while (*y
&& *y
!= ' ' && *y
!= '\t')
2487 else if (*y
== ' ' || *y
== '\t')
2488 /* Copy whitespace to the result. */
2490 /* Don't copy other options. */
2497 do_spec_1 (buf
, 0, NULL
);
2503 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
2507 /* Copy all of CPP_PREDEFINES into BUF,
2508 but put __ after every -D and at the end of each arg. */
2512 if (! strncmp (y
, "-D", 2))
2519 if (strncmp (y
, "__", 2))
2521 /* Stick __ at front of macro name. */
2524 /* Arrange to stick __ at the end as well. */
2528 /* Copy the macro name. */
2529 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
2538 /* Copy the value given, if any. */
2539 while (*y
&& *y
!= ' ' && *y
!= '\t')
2542 else if (*y
== ' ' || *y
== '\t')
2543 /* Copy whitespace to the result. */
2545 /* Don't copy -A options */
2551 /* Copy all of CPP_PREDEFINES into BUF,
2552 but put __ after every -D. */
2556 if (! strncmp (y
, "-D", 2))
2561 if (strncmp (y
, "__", 2))
2563 /* Stick __ at front of macro name. */
2568 /* Copy the macro name. */
2569 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
2572 /* Copy the value given, if any. */
2573 while (*y
&& *y
!= ' ' && *y
!= '\t')
2576 else if (*y
== ' ' || *y
== '\t')
2577 /* Copy whitespace to the result. */
2579 /* Don't copy -A options */
2585 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
2589 if (! strncmp (y
, "-A", 2))
2590 /* Copy the whole option. */
2591 while (*y
&& *y
!= ' ' && *y
!= '\t')
2593 else if (*y
== ' ' || *y
== '\t')
2594 /* Copy whitespace to the result. */
2596 /* Don't copy other options. */
2603 do_spec_1 (buf
, 0, NULL
);
2608 do_spec_1 (startfile_spec
, 0, NULL
);
2611 /* Here we define characters other than letters and digits. */
2614 p
= handle_braces (p
);
2620 obstack_1grow (&obstack
, '%');
2624 do_spec_1 (soft_matched_part
, 1, NULL
);
2625 do_spec_1 (" ", 0, NULL
);
2628 /* Process a string found as the value of a spec given by name.
2629 This feature allows individual machine descriptions
2630 to add and use their own specs.
2631 %[...] modifies -D options the way %P does;
2632 %(...) uses the spec unmodified. */
2637 struct spec_list
*sl
;
2640 /* The string after the S/P is the name of a spec that is to be
2642 while (*p
&& *p
!= ')' && *p
!= ']')
2645 /* See if it's in the list */
2646 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
2647 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
2656 do_spec_1 (name
, 0, NULL
);
2659 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
2663 /* Copy all of NAME into BUF, but put __ after
2664 every -D and at the end of each arg, */
2667 if (! strncmp (y
, "-D", 2))
2675 else if (*y
== ' ' || *y
== 0)
2689 do_spec_1 (buf
, 0, NULL
);
2693 /* Discard the closing paren or bracket. */
2705 /* Backslash: treat next character as ordinary. */
2710 /* Ordinary character: put it into the current argument. */
2711 obstack_1grow (&obstack
, c
);
2715 return 0; /* End of string */
2718 /* Return 0 if we call do_spec_1 and that returns -1. */
2731 /* A `|' after the open-brace means,
2732 if the test fails, output a single minus sign rather than nothing.
2733 This is used in %{|!pipe:...}. */
2737 /* A `!' after the open-brace negates the condition:
2738 succeed if the specified switch is not present. */
2742 /* A `.' after the open-brace means test against the current suffix. */
2752 while (*p
!= ':' && *p
!= '}') p
++;
2755 register int count
= 1;
2773 int found
= (input_suffix
!= 0
2774 && strlen (input_suffix
) == p
- filter
2775 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
2781 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL
) < 0)
2786 else if (p
[-1] == '*' && p
[0] == '}')
2788 /* Substitute all matching switches as separate args. */
2791 for (i
= 0; i
< n_switches
; i
++)
2792 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
2797 /* Test for presence of the specified switch. */
2801 /* If name specified ends in *, as in {x*:...},
2802 check for %* and handle that case. */
2803 if (p
[-1] == '*' && !negate
)
2808 /* First see whether we have %*. */
2812 if (*r
== '%' && r
[1] == '*')
2816 /* If we do, handle that case. */
2819 /* Substitute all matching switches as separate args.
2820 But do this by substituting for %*
2821 in the text that follows the colon. */
2823 unsigned hard_match_len
= p
- filter
- 1;
2824 char *string
= save_string (p
+ 1, q
- p
- 2);
2826 for (i
= 0; i
< n_switches
; i
++)
2827 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
))
2829 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
2830 /* Pass any arguments this switch has. */
2838 /* If name specified ends in *, as in {x*:...},
2839 check for presence of any switch name starting with x. */
2842 for (i
= 0; i
< n_switches
; i
++)
2844 unsigned hard_match_len
= p
- filter
- 1;
2846 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
))
2848 switches
[i
].valid
= 1;
2853 /* Otherwise, check for presence of exact name specified. */
2856 for (i
= 0; i
< n_switches
; i
++)
2858 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
2859 && switches
[i
].part1
[p
- filter
] == 0)
2861 switches
[i
].valid
= 1;
2868 /* If it is as desired (present for %{s...}, absent for %{-s...})
2869 then substitute either the switch or the specified
2870 conditional text. */
2871 if (present
!= negate
)
2879 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL
) < 0)
2885 /* Here if a %{|...} conditional fails: output a minus sign,
2886 which means "standard output" or "standard input". */
2887 do_spec_1 ("-", 0, NULL
);
2894 /* Pass a switch to the current accumulating command
2895 in the same form that we received it.
2896 SWITCHNUM identifies the switch; it is an index into
2897 the vector of switches gcc received, which is `switches'.
2898 This cannot fail since it never finishes a command line.
2900 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
2903 give_switch (switchnum
, omit_first_word
)
2905 int omit_first_word
;
2907 if (!omit_first_word
)
2909 do_spec_1 ("-", 0, NULL
);
2910 do_spec_1 (switches
[switchnum
].part1
, 1, NULL
);
2912 do_spec_1 (" ", 0, NULL
);
2913 if (switches
[switchnum
].args
!= 0)
2916 for (p
= switches
[switchnum
].args
; *p
; p
++)
2918 do_spec_1 (*p
, 1, NULL
);
2919 do_spec_1 (" ", 0, NULL
);
2922 switches
[switchnum
].valid
= 1;
2925 /* Search for a file named NAME trying various prefixes including the
2926 user's -B prefix and some standard ones.
2927 Return the absolute file name found. If nothing is found, return NAME. */
2935 newname
= find_a_file (&startfile_prefix
, name
, R_OK
);
2936 return newname
? newname
: name
;
2939 /* Determine whether a -L option is relevant. Not required for certain
2940 fixed names and for directories that don't exist. */
2943 is_linker_dir (path1
, path2
)
2947 int len1
= strlen (path1
);
2948 int len2
= strlen (path2
);
2949 char *path
= (char *) alloca (3 + len1
+ len2
);
2953 /* Construct the path from the two parts. Ensure the string ends with "/.".
2954 The resulting path will be a directory even if the given path is a
2956 bcopy (path1
, path
, len1
);
2957 bcopy (path2
, path
+ len1
, len2
);
2958 cp
= path
+ len1
+ len2
;
2964 /* Exclude directories that the linker is known to search. */
2965 if ((cp
- path
== 6 && strcmp (path
, "/lib/.") == 0)
2966 || (cp
- path
== 10 && strcmp (path
, "/usr/lib/.") == 0))
2969 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
2972 /* On fatal signals, delete all the temporary files. */
2975 fatal_error (signum
)
2978 signal (signum
, SIG_DFL
);
2979 delete_failure_queue ();
2980 delete_temp_files ();
2981 /* Get the same signal again, this time not handled,
2982 so its normal effect occurs. */
2983 kill (getpid (), signum
);
2993 int error_count
= 0;
2994 int linker_was_run
= 0;
2995 char *explicit_link_files
;
2998 programname
= argv
[0];
3000 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
3001 signal (SIGINT
, fatal_error
);
3002 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
3003 signal (SIGHUP
, fatal_error
);
3004 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
3005 signal (SIGTERM
, fatal_error
);
3007 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
3008 signal (SIGPIPE
, fatal_error
);
3012 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
3014 obstack_init (&obstack
);
3016 /* Set up to remember the pathname of gcc and any options
3017 needed for collect. */
3018 obstack_init (&collect_obstack
);
3019 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
3020 obstack_grow (&collect_obstack
, programname
, strlen (programname
)+1);
3021 putenv (obstack_finish (&collect_obstack
));
3023 /* Choose directory for temp files. */
3025 choose_temp_base ();
3027 /* Make a table of what switches there are (switches, n_switches).
3028 Make a table of specified input files (infiles, n_infiles).
3029 Decode switches that are handled locally. */
3031 process_command (argc
, argv
);
3033 /* Initialize the vector of specs to just the default.
3034 This means one element containing 0s, as a terminator. */
3036 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
3037 bcopy (default_compilers
, compilers
, sizeof default_compilers
);
3038 n_compilers
= n_default_compilers
;
3040 /* Read specs from a file if there is one. */
3042 machine_suffix
= concat (spec_machine
, "/", concat (spec_version
, "/", ""));
3044 specs_file
= find_a_file (&startfile_prefix
, "specs", R_OK
);
3045 /* Read the specs file unless it is a default one. */
3046 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
3047 read_specs (specs_file
);
3049 /* If not cross-compiling, look for startfiles in the standard places. */
3050 /* The fact that these are done here, after reading the specs file,
3051 means that it cannot be found in these directories.
3052 But that's okay. It should never be there anyway. */
3055 #ifdef MD_EXEC_PREFIX
3056 add_prefix (&exec_prefix
, md_exec_prefix
, 0, 0, 0);
3057 add_prefix (&startfile_prefix
, md_exec_prefix
, 0, 0, 0);
3060 #ifdef MD_STARTFILE_PREFIX
3061 add_prefix (&startfile_prefix
, md_startfile_prefix
, 0, 0, 0);
3064 add_prefix (&startfile_prefix
, standard_startfile_prefix
, 0, 0, 0);
3065 add_prefix (&startfile_prefix
, standard_startfile_prefix_1
, 0, 0, 0);
3066 add_prefix (&startfile_prefix
, standard_startfile_prefix_2
, 0, 0, 0);
3067 #if 0 /* Can cause surprises, and one can use -B./ instead. */
3068 add_prefix (&startfile_prefix
, "./", 0, 1, 0);
3072 /* Now we have the specs.
3073 Set the `valid' bits for switches that match anything in any spec. */
3075 validate_all_switches ();
3077 /* Warn about any switches that no pass was interested in. */
3079 for (i
= 0; i
< n_switches
; i
++)
3080 if (! switches
[i
].valid
)
3081 error ("unrecognized option `-%s'", switches
[i
].part1
);
3083 if (print_libgcc_file_name
)
3085 printf ("%s\n", find_file ("libgcc.a"));
3089 /* Obey some of the options. */
3093 fprintf (stderr
, "gcc version %s\n", version_string
);
3099 fatal ("No input files specified.");
3101 /* Make a place to record the compiler output file names
3102 that correspond to the input files. */
3104 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
3105 bzero (outfiles
, n_infiles
* sizeof (char *));
3107 /* Record which files were specified explicitly as link input. */
3109 explicit_link_files
= xmalloc (n_infiles
);
3110 bzero (explicit_link_files
, n_infiles
);
3112 for (i
= 0; i
< n_infiles
; i
++)
3114 register struct compiler
*cp
= 0;
3115 int this_file_error
= 0;
3117 /* Tell do_spec what to substitute for %i. */
3119 input_filename
= infiles
[i
].name
;
3120 input_filename_length
= strlen (input_filename
);
3121 input_file_number
= i
;
3123 /* Use the same thing in %o, unless cp->spec says otherwise. */
3125 outfiles
[i
] = input_filename
;
3127 /* Figure out which compiler from the file's suffix. */
3129 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
3130 infiles
[i
].language
);
3134 /* Ok, we found an applicable compiler. Run its spec. */
3135 /* First say how much of input_filename to substitute for %b */
3138 input_basename
= input_filename
;
3139 for (p
= input_filename
; *p
; p
++)
3141 input_basename
= p
+ 1;
3143 /* Find a suffix starting with the last period,
3144 and set basename_length to exclude that suffix. */
3145 basename_length
= strlen (input_basename
);
3146 p
= input_basename
+ basename_length
;
3147 while (p
!= input_basename
&& *p
!= '.') --p
;
3148 if (*p
== '.' && p
!= input_basename
)
3150 basename_length
= p
- input_basename
;
3151 input_suffix
= p
+ 1;
3156 value
= do_spec (cp
->spec
);
3158 this_file_error
= 1;
3161 /* If this file's name does not contain a recognized suffix,
3162 record it as explicit linker input. */
3165 explicit_link_files
[i
] = 1;
3167 /* Clear the delete-on-failure queue, deleting the files in it
3168 if this compilation failed. */
3170 if (this_file_error
)
3172 delete_failure_queue ();
3175 /* If this compilation succeeded, don't delete those files later. */
3176 clear_failure_queue ();
3179 /* Run ld to link all the compiler output files. */
3181 if (error_count
== 0)
3183 int tmp
= execution_count
;
3187 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
3189 putenv_from_prefixes (&exec_prefix
, "COMPILER_PATH=");
3190 putenv_from_prefixes (&startfile_prefix
, "LIBRARY_PATH=");
3192 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
3194 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
3195 sizeof ("COLLECT_GCC_OPTIONS=")-1);
3198 for (i
= 0; i
< n_switches
; i
++)
3202 obstack_grow (&collect_obstack
, " ", 1);
3205 obstack_grow (&collect_obstack
, "-", 1);
3206 obstack_grow (&collect_obstack
, switches
[i
].part1
,
3207 strlen (switches
[i
].part1
));
3209 for (args
= switches
[i
].args
; args
&& *args
; args
++)
3211 obstack_grow (&collect_obstack
, " ", 1);
3212 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
3215 obstack_grow (&collect_obstack
, "\0", 1);
3216 putenv (obstack_finish (&collect_obstack
));
3218 value
= do_spec (link_command_spec
);
3221 linker_was_run
= (tmp
!= execution_count
);
3224 /* Warn if a -B option was specified but the prefix was never used. */
3225 unused_prefix_warnings (&exec_prefix
);
3226 unused_prefix_warnings (&startfile_prefix
);
3228 /* If options said don't run linker,
3229 complain about input files to be given to the linker. */
3231 if (! linker_was_run
&& error_count
== 0)
3232 for (i
= 0; i
< n_infiles
; i
++)
3233 if (explicit_link_files
[i
])
3234 error ("%s: linker input file unused since linking not done",
3237 /* Delete some or all of the temporary files we made. */
3240 delete_failure_queue ();
3241 delete_temp_files ();
3248 /* Find the proper compilation spec for the file name NAME,
3249 whose length is LENGTH. LANGUAGE is the specified language,
3250 or 0 if none specified. */
3252 static struct compiler
*
3253 lookup_compiler (name
, length
, language
)
3258 struct compiler
*cp
;
3260 /* Look for the language, if one is spec'd. */
3263 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
3267 if (cp
->suffix
[0] == '@'
3268 && !strcmp (cp
->suffix
+ 1, language
))
3272 error ("language %s not recognized", language
);
3275 /* Look for a suffix. */
3276 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
3278 if (strlen (cp
->suffix
) < length
3279 /* See if the suffix matches the end of NAME. */
3280 && !strcmp (cp
->suffix
,
3281 name
+ length
- strlen (cp
->suffix
))
3282 /* The suffix `-' matches only the file name `-'. */
3283 && !(!strcmp (cp
->suffix
, "-") && length
!= 1))
3285 if (cp
->spec
[0] == '@')
3287 struct compiler
*new;
3288 /* An alias entry maps a suffix to a language.
3289 Search for the language; pass 0 for NAME and LENGTH
3290 to avoid infinite recursion if language not found.
3291 Construct the new compiler spec. */
3292 language
= cp
->spec
+ 1;
3293 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
3294 new->suffix
= cp
->suffix
;
3295 new->spec
= lookup_compiler (0, 0, language
)->spec
;
3298 /* A non-alias entry: return it. */
3310 register char *value
= (char *) malloc (size
);
3312 fatal ("virtual memory exhausted");
3317 xrealloc (ptr
, size
)
3321 register char *value
= (char *) realloc (ptr
, size
);
3323 fatal ("virtual memory exhausted");
3327 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
3333 int len1
= strlen (s1
), len2
= strlen (s2
), len3
= strlen (s3
);
3334 char *result
= xmalloc (len1
+ len2
+ len3
+ 1);
3336 strcpy (result
, s1
);
3337 strcpy (result
+ len1
, s2
);
3338 strcpy (result
+ len1
+ len2
, s3
);
3339 *(result
+ len1
+ len2
+ len3
) = 0;
3345 save_string (s
, len
)
3349 register char *result
= xmalloc (len
+ 1);
3351 bcopy (s
, result
, len
);
3357 pfatal_with_name (name
)
3362 if (errno
< sys_nerr
)
3363 s
= concat ("%s: ", sys_errlist
[errno
], "");
3365 s
= "cannot open %s";
3370 perror_with_name (name
)
3375 if (errno
< sys_nerr
)
3376 s
= concat ("%s: ", sys_errlist
[errno
], "");
3378 s
= "cannot open %s";
3388 if (errno
< sys_nerr
)
3389 s
= concat ("installation problem, cannot exec %s: ",
3390 sys_errlist
[errno
], "");
3392 s
= "installation problem, cannot exec %s";
3396 /* More 'friendly' abort that prints the line and file.
3397 config.h can #define abort fancy_abort if you like that sort of thing. */
3402 fatal ("Internal gcc abort.");
3407 /* Output an error message and exit */
3417 format
= va_arg (ap
, char *);
3418 fprintf (stderr
, "%s: ", programname
);
3419 vfprintf (stderr
, format
, ap
);
3421 fprintf (stderr
, "\n");
3422 delete_temp_files ();
3434 format
= va_arg (ap
, char *);
3435 fprintf (stderr
, "%s: ", programname
);
3436 vfprintf (stderr
, format
, ap
);
3439 fprintf (stderr
, "\n");
3442 #else /* not HAVE_VPRINTF */
3445 fatal (msg
, arg1
, arg2
)
3446 char *msg
, *arg1
, *arg2
;
3448 error (msg
, arg1
, arg2
);
3449 delete_temp_files ();
3454 error (msg
, arg1
, arg2
)
3455 char *msg
, *arg1
, *arg2
;
3457 fprintf (stderr
, "%s: ", programname
);
3458 fprintf (stderr
, msg
, arg1
, arg2
);
3459 fprintf (stderr
, "\n");
3462 #endif /* not HAVE_VPRINTF */
3466 validate_all_switches ()
3468 struct compiler
*comp
;
3471 struct spec_list
*spec
;
3473 for (comp
= compilers
; comp
->spec
; comp
++)
3477 if (c
== '%' && *p
== '{')
3478 /* We have a switch spec. */
3479 validate_switches (p
+ 1);
3482 /* look through the linked list of extra specs read from the specs file */
3483 for (spec
= specs
; spec
; spec
= spec
->next
)
3487 if (c
== '%' && *p
== '{')
3488 /* We have a switch spec. */
3489 validate_switches (p
+ 1);
3492 p
= link_command_spec
;
3494 if (c
== '%' && *p
== '{')
3495 /* We have a switch spec. */
3496 validate_switches (p
+ 1);
3498 /* Now notice switches mentioned in the machine-specific specs. */
3502 if (c
== '%' && *p
== '{')
3503 /* We have a switch spec. */
3504 validate_switches (p
+ 1);
3508 if (c
== '%' && *p
== '{')
3509 /* We have a switch spec. */
3510 validate_switches (p
+ 1);
3514 if (c
== '%' && *p
== '{')
3515 /* We have a switch spec. */
3516 validate_switches (p
+ 1);
3518 p
= signed_char_spec
;
3520 if (c
== '%' && *p
== '{')
3521 /* We have a switch spec. */
3522 validate_switches (p
+ 1);
3526 if (c
== '%' && *p
== '{')
3527 /* We have a switch spec. */
3528 validate_switches (p
+ 1);
3532 if (c
== '%' && *p
== '{')
3533 /* We have a switch spec. */
3534 validate_switches (p
+ 1);
3538 if (c
== '%' && *p
== '{')
3539 /* We have a switch spec. */
3540 validate_switches (p
+ 1);
3544 if (c
== '%' && *p
== '{')
3545 /* We have a switch spec. */
3546 validate_switches (p
+ 1);
3550 if (c
== '%' && *p
== '{')
3551 /* We have a switch spec. */
3552 validate_switches (p
+ 1);
3555 /* Look at the switch-name that comes after START
3556 and mark as valid all supplied switches that match it. */
3559 validate_switches (start
)
3562 register char *p
= start
;
3577 while (*p
!= ':' && *p
!= '}') p
++;
3581 else if (p
[-1] == '*')
3583 /* Mark all matching switches as valid. */
3585 for (i
= 0; i
< n_switches
; i
++)
3586 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
3587 switches
[i
].valid
= 1;
3591 /* Mark an exact matching switch as valid. */
3592 for (i
= 0; i
< n_switches
; i
++)
3594 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3595 && switches
[i
].part1
[p
- filter
] == 0)
3596 switches
[i
].valid
= 1;