1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92, 93, 94, 95, 1996 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!! */
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers. It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec". */
34 #include <sys/types.h>
41 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
46 #include "gansidecl.h"
61 /* ??? Need to find a GCC header to put these in. */
62 extern int pexecute PROTO ((const char *, char * const *, const char *,
63 const char *, char **, char **, int));
64 extern int pwait PROTO ((int, int *, int));
65 /* Flag arguments to pexecute. */
66 #define PEXECUTE_FIRST 1
67 #define PEXECUTE_LAST 2
68 #define PEXECUTE_SEARCH 4
69 #define PEXECUTE_VERBOSE 8
72 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
75 #define WTERMSIG(S) ((S) & 0x7f)
78 #define WIFEXITED(S) (((S) & 0xff) == 0)
81 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
84 /* Define O_RDONLY if the system hasn't defined it for us. */
93 /* Test if something is a normal file. */
95 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
98 /* Test if something is a directory. */
100 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
103 /* By default there is no special suffix for executables. */
104 #ifndef EXECUTABLE_SUFFIX
105 #define EXECUTABLE_SUFFIX ""
108 /* By default, the suffix for object files is ".o". */
110 #define HAVE_OBJECT_SUFFIX
112 #define OBJECT_SUFFIX ".o"
115 /* By default, colon separates directories in a path. */
116 #ifndef PATH_SEPARATOR
117 #define PATH_SEPARATOR ':'
120 #ifndef DIR_SEPARATOR
121 #define DIR_SEPARATOR '/'
124 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
126 #define obstack_chunk_alloc xmalloc
127 #define obstack_chunk_free free
130 extern char *getenv ();
132 extern char *choose_temp_base PROTO((void));
138 #ifndef HAVE_STRERROR
141 extern const char *const sys_errlist[];
143 extern char *sys_errlist[];
146 extern char *strerror();
149 /* If a stage of compilation returns an exit status >= 1,
150 compilation of that file ceases. */
152 #define MIN_FATAL_STATUS 1
154 /* Flag saying to print the directories gcc will search through looking for
155 programs, libraries, etc. */
157 static int print_search_dirs;
159 /* Flag saying to print the full filename of this file
160 as found through our usual search mechanism. */
162 static char *print_file_name = NULL;
164 /* As print_file_name, but search for executable file. */
166 static char *print_prog_name = NULL;
168 /* Flag saying to print the relative path we'd use to
169 find libgcc.a given the current compiler flags. */
171 static int print_multi_directory;
173 /* Flag saying to print the list of subdirectories and
174 compiler flags used to select them in a standard form. */
176 static int print_multi_lib;
178 /* Flag indicating whether we should print the command and arguments */
180 static int verbose_flag;
182 /* Nonzero means write "temp" files in source directory
183 and use the source file's name in them, and don't delete them. */
185 static int save_temps_flag;
187 /* The compiler version. */
189 static char *compiler_version;
191 /* The target version specified with -V */
193 static char *spec_version = DEFAULT_TARGET_VERSION;
195 /* The target machine specified with -b. */
197 static char *spec_machine = DEFAULT_TARGET_MACHINE;
199 /* Nonzero if cross-compiling.
200 When -b is used, the value comes from the `specs' file. */
203 static int cross_compile = 1;
205 static int cross_compile = 0;
208 /* The number of errors that have occurred; the link phase will not be
209 run if this is non-zero. */
210 static int error_count = 0;
212 /* This is the obstack which we use to allocate many strings. */
214 static struct obstack obstack;
216 /* This is the obstack to build an environment variable to pass to
217 collect2 that describes all of the relevant switches of what to
218 pass the compiler in building the list of pointers to constructors
221 static struct obstack collect_obstack;
223 extern char *version_string;
225 /* Forward declaration for prototypes. */
228 static void set_spec PROTO((char *, char *));
229 static struct compiler *lookup_compiler PROTO((char *, int, char *));
230 static char *build_search_list PROTO((struct path_prefix *, char *, int));
231 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
232 static char *find_a_file PROTO((struct path_prefix *, char *, int));
233 static void add_prefix PROTO((struct path_prefix *, char *, int, int, int *));
234 static char *skip_whitespace PROTO((char *));
235 static void record_temp_file PROTO((char *, int, int));
236 static void delete_if_ordinary PROTO((char *));
237 static void delete_temp_files PROTO((void));
238 static void delete_failure_queue PROTO((void));
239 static void clear_failure_queue PROTO((void));
240 static int check_live_switch PROTO((int, int));
241 static char *handle_braces PROTO((char *));
242 static char *save_string PROTO((char *, int));
243 static char *concat PVPROTO((char *, ...));
244 static int do_spec PROTO((char *));
245 static int do_spec_1 PROTO((char *, int, char *));
246 static char *find_file PROTO((char *));
247 static int is_directory PROTO((char *, char *, int));
248 static void validate_switches PROTO((char *));
249 static void validate_all_switches PROTO((void));
250 static void give_switch PROTO((int, int));
251 static int used_arg PROTO((char *, int));
252 static int default_arg PROTO((char *, int));
253 static void set_multilib_dir PROTO((void));
254 static void print_multilib_info PROTO((void));
255 static void pfatal_with_name PROTO((char *));
256 static void perror_with_name PROTO((char *));
257 static void pfatal_pexecute PROTO((char *, char *));
259 static void fatal PVPROTO((char *, ...));
260 static void error PVPROTO((char *, ...));
262 /* We must not provide any prototype here, even if ANSI C. */
263 static void fatal PROTO(());
264 static void error PROTO(());
271 /* Specs are strings containing lines, each of which (if not blank)
272 is made up of a program name, and arguments separated by spaces.
273 The program name must be exact and start from root, since no path
274 is searched and it is unreliable to depend on the current working directory.
275 Redirection of input or output is not supported; the subprograms must
276 accept filenames saying what files to read and write.
278 In addition, the specs can contain %-sequences to substitute variable text
279 or for conditional text. Here is a table of all defined %-sequences.
280 Note that spaces are not generated automatically around the results of
281 expanding these sequences; therefore, you can concatenate them together
282 or with constant text in a single argument.
284 %% substitute one % into the program name or argument.
285 %i substitute the name of the input file being processed.
286 %b substitute the basename of the input file being processed.
287 This is the substring up to (and not including) the last period
288 and not including the directory.
289 %g substitute the temporary-file-name-base. This is a string chosen
290 once per compilation. Different temporary file names are made by
291 concatenation of constant strings on the end, as in `%g.s'.
292 %g also has the same effect of %d.
293 %u like %g, but make the temporary file name unique.
294 %U returns the last file name generated with %u.
295 %d marks the argument containing or following the %d as a
296 temporary file name, so that that file will be deleted if CC exits
297 successfully. Unlike %g, this contributes no text to the argument.
298 %w marks the argument containing or following the %w as the
299 "output file" of this compilation. This puts the argument
300 into the sequence of arguments that %o will substitute later.
302 like %{...} but mark last argument supplied within
303 as a file to be deleted on failure.
304 %o substitutes the names of all the output files, with spaces
305 automatically placed around them. You should write spaces
306 around the %o as well or the results are undefined.
307 %o is for use in the specs for running the linker.
308 Input files whose names have no recognized suffix are not compiled
309 at all, but they are included among the output files, so they will
311 %O substitutes the suffix for object files.
312 %p substitutes the standard macro predefinitions for the
313 current target machine. Use this when running cpp.
314 %P like %p, but puts `__' before and after the name of each macro.
315 (Except macros that already have __.)
317 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
318 %s current argument is the name of a library or startup file of some sort.
319 Search for that file in a standard list of directories
320 and substitute the full name found.
321 %eSTR Print STR as an error message. STR is terminated by a newline.
322 Use this when inconsistent options are detected.
323 %x{OPTION} Accumulate an option for %X.
324 %X Output the accumulated linker options specified by compilations.
325 %Y Output the accumulated assembler options specified by compilations.
326 %Z Output the accumulated preprocessor options specified by compilations.
327 %v1 Substitute the major version number of GCC.
328 (For version 2.5.n, this is 2.)
329 %v2 Substitute the minor version number of GCC.
330 (For version 2.5.n, this is 5.)
331 %a process ASM_SPEC as a spec.
332 This allows config.h to specify part of the spec for running as.
333 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
334 used here. This can be used to run a post-processor after the
335 assembler has done it's job.
336 %D Dump out a -L option for each directory in startfile_prefixes.
337 If multilib_dir is set, extra entries are generated with it affixed.
338 %l process LINK_SPEC as a spec.
339 %L process LIB_SPEC as a spec.
340 %G process LIBGCC_SPEC as a spec.
341 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
342 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
343 %c process SIGNED_CHAR_SPEC as a spec.
344 %C process CPP_SPEC as a spec. A capital C is actually used here.
345 %1 process CC1_SPEC as a spec.
346 %2 process CC1PLUS_SPEC as a spec.
347 %| output "-" if the input for the current command is coming from a pipe.
348 %* substitute the variable part of a matched option. (See below.)
349 Note that each comma in the substituted string is replaced by
351 %{S} substitutes the -S switch, if that switch was given to CC.
352 If that switch was not specified, this substitutes nothing.
353 Here S is a metasyntactic variable.
354 %{S*} substitutes all the switches specified to CC whose names start
355 with -S. This is used for -o, -D, -I, etc; switches that take
356 arguments. CC considers `-o foo' as being one switch whose
357 name starts with `o'. %{o*} would substitute this text,
358 including the space; thus, two arguments would be generated.
359 %{S*:X} substitutes X if one or more switches whose names start with -S are
360 specified to CC. Note that the tail part of the -S option
361 (i.e. the part matched by the `*') will be substituted for each
362 occurrence of %* within X.
363 %{S:X} substitutes X, but only if the -S switch was given to CC.
364 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
365 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
366 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
367 %{.S:X} substitutes X, but only if processing a file with suffix S.
368 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
369 %(Spec) processes a specification defined in a specs file as *Spec:
370 %[Spec] as above, but put __ around -D arguments
372 The conditional text X in a %{S:X} or %{!S:X} construct may contain
373 other nested % constructs or spaces, or even newlines. They are
374 processed as usual, as described above.
376 The -O, -f, -m, and -W switches are handled specifically in these
377 constructs. If another value of -O or the negated form of a -f, -m, or
378 -W switch is found later in the command line, the earlier switch
379 value is ignored, except with {S*} where S is just one letter; this
380 passes all matching options.
382 The character | is used to indicate that a command should be piped to
383 the following command, but only if -pipe is specified.
385 Note that it is built into CC which switches take arguments and which
386 do not. You might think it would be useful to generalize this to
387 allow each compiler's spec to say which switches take arguments. But
388 this cannot be done in a consistent fashion. CC cannot even decide
389 which input files have been specified without knowing which switches
390 take arguments, and it must know which input files to compile in order
391 to tell which compilers to run.
393 CC also knows implicitly that arguments starting in `-l' are to be
394 treated as compiler output files, and passed to the linker in their
395 proper position among the other output files. */
397 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
399 /* config.h can define ASM_SPEC to provide extra args to the assembler
400 or extra switch-translations. */
405 /* config.h can define ASM_FINAL_SPEC to run a post processor after
406 the assembler has run. */
407 #ifndef ASM_FINAL_SPEC
408 #define ASM_FINAL_SPEC ""
411 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
412 or extra switch-translations. */
417 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
418 or extra switch-translations. */
423 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
424 or extra switch-translations. */
426 #define CC1PLUS_SPEC ""
429 /* config.h can define LINK_SPEC to provide extra args to the linker
430 or extra switch-translations. */
435 /* config.h can define LIB_SPEC to override the default libraries. */
437 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
440 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
443 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
444 /* Have gcc do the search for libgcc.a. */
445 #define LIBGCC_SPEC "libgcc.a%s"
447 #define LIBGCC_SPEC "-lgcc"
451 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
452 #ifndef STARTFILE_SPEC
453 #define STARTFILE_SPEC \
454 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
457 /* config.h can define SWITCHES_NEED_SPACES to control which options
458 require spaces between the option and the argument. */
459 #ifndef SWITCHES_NEED_SPACES
460 #define SWITCHES_NEED_SPACES ""
463 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
465 #define ENDFILE_SPEC ""
468 /* This spec is used for telling cpp whether char is signed or not. */
469 #ifndef SIGNED_CHAR_SPEC
470 /* Use #if rather than ?:
471 because MIPS C compiler rejects like ?: in initializers. */
472 #if DEFAULT_SIGNED_CHAR
473 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
475 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
479 static char *cpp_spec = CPP_SPEC;
480 static char *cpp_predefines = CPP_PREDEFINES;
481 static char *cc1_spec = CC1_SPEC;
482 static char *cc1plus_spec = CC1PLUS_SPEC;
483 static char *signed_char_spec = SIGNED_CHAR_SPEC;
484 static char *asm_spec = ASM_SPEC;
485 static char *asm_final_spec = ASM_FINAL_SPEC;
486 static char *link_spec = LINK_SPEC;
487 static char *lib_spec = LIB_SPEC;
488 static char *libgcc_spec = LIBGCC_SPEC;
489 static char *endfile_spec = ENDFILE_SPEC;
490 static char *startfile_spec = STARTFILE_SPEC;
491 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
493 /* Some compilers have limits on line lengths, and the multilib_select
494 string can be very long, so we build it at run time. */
495 static struct obstack multilib_obstack;
496 static char *multilib_raw[] = {
497 #include "multilib.h"
499 static char *multilib_select;
502 static struct { char *name, *spec; } extra_specs[] = { EXTRA_SPECS };
505 /* This defines which switch letters take arguments. */
507 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
508 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
509 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
510 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
511 || (CHAR) == 'L' || (CHAR) == 'A')
513 #ifndef SWITCH_TAKES_ARG
514 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
517 /* This defines which multi-letter switches take arguments. */
519 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
520 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
521 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
522 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
523 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
524 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
525 || !strcmp (STR, "isystem"))
527 #ifndef WORD_SWITCH_TAKES_ARG
528 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
531 /* Record the mapping from file suffixes for compilation specs. */
535 char *suffix; /* Use this compiler for input files
536 whose names end in this suffix. */
538 char *spec[4]; /* To use this compiler, concatenate these
539 specs and pass to do_spec. */
542 /* Pointer to a vector of `struct compiler' that gives the spec for
543 compiling a file, based on its suffix.
544 A file that does not end in any of these suffixes will be passed
545 unchanged to the loader and nothing else will be done to it.
547 An entry containing two 0s is used to terminate the vector.
549 If multiple entries match a file, the last matching one is used. */
551 static struct compiler *compilers;
553 /* Number of entries in `compilers', not counting the null terminator. */
555 static int n_compilers;
557 /* The default list of file name suffixes and their compilation specs. */
559 static struct compiler default_compilers[] =
563 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
564 %{C:%{!E:%eGNU C does not support -C without using -E}}\
565 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
566 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
567 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
568 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
569 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
570 %{traditional-cpp:-traditional}\
571 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
572 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
573 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
574 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
575 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
576 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
578 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
579 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
581 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
582 %{!pipe:%g.s} %A\n }}}}"},
584 "%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
585 %{C:%{!E:%eGNU C does not support -C without using -E}}\
586 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
587 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
588 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
589 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
590 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
591 %{traditional-cpp:-traditional}\
592 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
594 %{!E:%e-E required when input is from standard input}"},
595 {".m", "@objective-c"},
597 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
598 %{C:%{!E:%eGNU C does not support -C without using -E}}\
599 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
600 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
601 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
602 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
603 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
604 %{traditional-cpp:-traditional}\
605 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
606 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
607 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
608 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
609 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
610 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
611 -lang-objc %{gen-decls} \
613 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
614 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
616 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
617 %{!pipe:%g.s} %A\n }}}}"},
620 "%{!E:%eCompilation of header file requested} \
621 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
622 %{C:%{!E:%eGNU C does not support -C without using -E}}\
623 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
624 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
625 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
626 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
627 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
628 %{traditional-cpp:-traditional}\
629 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
631 {".i", "@cpp-output"},
633 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
634 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
635 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
637 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
638 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
640 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
641 %{!pipe:%g.s} %A\n }}}}"},
642 {".s", "@assembler"},
644 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
645 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
647 {".S", "@assembler-with-cpp"},
648 {"@assembler-with-cpp",
649 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
650 %{C:%{!E:%eGNU C does not support -C without using -E}}\
651 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
652 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
653 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
654 %{traditional-cpp:-traditional}\
655 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
656 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
657 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
658 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
659 %{!pipe:%g.s} %A\n }}}}"},
661 /* Mark end of table */
665 /* Number of elements in default_compilers, not counting the terminator. */
667 static int n_default_compilers
668 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
670 /* Here is the spec for running the linker, after compiling all files. */
672 /* -u* was put back because both BSD and SysV seem to support it. */
673 /* %{static:} simply prevents an error message if the target machine
674 doesn't handle -static. */
675 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
676 scripts which exist in user specified directories, or in standard
678 #ifdef LINK_LIBGCC_SPECIAL
679 /* Don't generate -L options. */
680 static char *link_command_spec = "\
682 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
683 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
684 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
685 %{static:} %{L*} %{T*} %o\
686 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
687 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\n }}}}}}";
690 static char *link_command_spec = "\
692 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
693 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
694 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
695 %{static:} %{L*} %D %{T*} %o\
696 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
697 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\n }}}}}}";
700 /* A vector of options to give to the linker.
701 These options are accumulated by %x,
702 and substituted into the linker command with %X. */
703 static int n_linker_options;
704 static char **linker_options;
706 /* A vector of options to give to the assembler.
707 These options are accumulated by -Wa,
708 and substituted into the assembler command with %Y. */
709 static int n_assembler_options;
710 static char **assembler_options;
712 /* A vector of options to give to the preprocessor.
713 These options are accumulated by -Wp,
714 and substituted into the preprocessor command with %Z. */
715 static int n_preprocessor_options;
716 static char **preprocessor_options;
718 /* Define how to map long options into short ones. */
720 /* This structure describes one mapping. */
723 /* The long option's name. */
725 /* The equivalent short option. */
727 /* Argument info. A string of flag chars; NULL equals no options.
728 a => argument required.
729 o => argument optional.
730 j => join argument to equivalent, making one word.
731 * => require other text after NAME as an argument. */
735 /* This is the table of mappings. Mappings are tried sequentially
736 for each option encountered; the first one that matches, wins. */
738 struct option_map option_map[] =
740 {"--all-warnings", "-Wall", 0},
741 {"--ansi", "-ansi", 0},
742 {"--assemble", "-S", 0},
743 {"--assert", "-A", "a"},
744 {"--comments", "-C", 0},
745 {"--compile", "-c", 0},
746 {"--debug", "-g", "oj"},
747 {"--define-macro", "-D", "a"},
748 {"--dependencies", "-M", 0},
749 {"--dump", "-d", "a"},
750 {"--dumpbase", "-dumpbase", "a"},
751 {"--entry", "-e", 0},
752 {"--extra-warnings", "-W", 0},
753 {"--for-assembler", "-Wa", "a"},
754 {"--for-linker", "-Xlinker", "a"},
755 {"--force-link", "-u", "a"},
756 {"--imacros", "-imacros", "a"},
757 {"--include", "-include", "a"},
758 {"--include-barrier", "-I-", 0},
759 {"--include-directory", "-I", "a"},
760 {"--include-directory-after", "-idirafter", "a"},
761 {"--include-prefix", "-iprefix", "a"},
762 {"--include-with-prefix", "-iwithprefix", "a"},
763 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
764 {"--include-with-prefix-after", "-iwithprefix", "a"},
765 {"--language", "-x", "a"},
766 {"--library-directory", "-L", "a"},
767 {"--machine", "-m", "aj"},
768 {"--machine-", "-m", "*j"},
769 {"--no-line-commands", "-P", 0},
770 {"--no-precompiled-includes", "-noprecomp", 0},
771 {"--no-standard-includes", "-nostdinc", 0},
772 {"--no-standard-libraries", "-nostdlib", 0},
773 {"--no-warnings", "-w", 0},
774 {"--optimize", "-O", "oj"},
775 {"--output", "-o", "a"},
776 {"--pedantic", "-pedantic", 0},
777 {"--pedantic-errors", "-pedantic-errors", 0},
778 {"--pipe", "-pipe", 0},
779 {"--prefix", "-B", "a"},
780 {"--preprocess", "-E", 0},
781 {"--print-search-dirs", "-print-search-dirs", 0},
782 {"--print-file-name", "-print-file-name=", "aj"},
783 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
784 {"--print-missing-file-dependencies", "-MG", 0},
785 {"--print-multi-lib", "-print-multi-lib", 0},
786 {"--print-multi-directory", "-print-multi-directory", 0},
787 {"--print-prog-name", "-print-prog-name=", "aj"},
788 {"--profile", "-p", 0},
789 {"--profile-blocks", "-a", 0},
790 {"--quiet", "-q", 0},
791 {"--save-temps", "-save-temps", 0},
792 {"--shared", "-shared", 0},
793 {"--silent", "-q", 0},
794 {"--static", "-static", 0},
795 {"--symbolic", "-symbolic", 0},
796 {"--target", "-b", "a"},
797 {"--trace-includes", "-H", 0},
798 {"--traditional", "-traditional", 0},
799 {"--traditional-cpp", "-traditional-cpp", 0},
800 {"--trigraphs", "-trigraphs", 0},
801 {"--undefine-macro", "-U", "a"},
802 {"--use-version", "-V", "a"},
803 {"--user-dependencies", "-MM", 0},
804 {"--verbose", "-v", 0},
805 {"--version", "-dumpversion", 0},
806 {"--warn-", "-W", "*j"},
807 {"--write-dependencies", "-MD", 0},
808 {"--write-user-dependencies", "-MMD", 0},
812 /* Translate the options described by *ARGCP and *ARGVP.
813 Make a new vector and store it back in *ARGVP,
814 and store its length in *ARGVC. */
817 translate_options (argcp, argvp)
823 char **argv = *argvp;
824 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
828 newv[newindex++] = argv[i++];
832 /* Translate -- options. */
833 if (argv[i][0] == '-' && argv[i][1] == '-')
835 /* Find a mapping that applies to this option. */
836 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
838 int optlen = strlen (option_map[j].name);
839 int arglen = strlen (argv[i]);
840 int complen = arglen > optlen ? optlen : arglen;
841 char *arginfo = option_map[j].arg_info;
846 if (!strncmp (argv[i], option_map[j].name, complen))
853 k < sizeof (option_map) / sizeof (option_map[0]);
855 if (strlen (option_map[k].name) >= arglen
856 && !strncmp (argv[i], option_map[k].name, arglen))
858 error ("Ambiguous abbreviation %s", argv[i]);
862 if (k != sizeof (option_map) / sizeof (option_map[0]))
868 /* If the option has an argument, accept that. */
869 if (argv[i][optlen] == '=')
870 arg = argv[i] + optlen + 1;
872 /* If this mapping requires extra text at end of name,
873 accept that as "argument". */
874 else if (index (arginfo, '*') != 0)
875 arg = argv[i] + optlen;
877 /* Otherwise, extra text at end means mismatch.
878 Try other mappings. */
883 else if (index (arginfo, '*') != 0)
885 error ("Incomplete `%s' option", option_map[j].name);
889 /* Handle arguments. */
890 if (index (arginfo, 'a') != 0)
896 error ("Missing argument to `%s' option",
904 else if (index (arginfo, '*') != 0)
906 else if (index (arginfo, 'o') == 0)
909 error ("Extraneous argument to `%s' option",
914 /* Store the translation as one argv elt or as two. */
915 if (arg != 0 && index (arginfo, 'j') != 0)
916 newv[newindex++] = concat (option_map[j].equivalent, arg,
920 newv[newindex++] = option_map[j].equivalent;
921 newv[newindex++] = arg;
924 newv[newindex++] = option_map[j].equivalent;
932 /* Handle old-fashioned options--just copy them through,
933 with their arguments. */
934 else if (argv[i][0] == '-')
936 char *p = argv[i] + 1;
940 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
941 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
942 else if (WORD_SWITCH_TAKES_ARG (p))
943 nskip += WORD_SWITCH_TAKES_ARG (p);
944 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
947 else if (! strcmp (p, "Xlinker"))
950 /* Watch out for an option at the end of the command line that
951 is missing arguments, and avoid skipping past the end of the
953 if (nskip + i > argc)
958 newv[newindex++] = argv[i++];
963 /* Ordinary operands, or +e options. */
964 newv[newindex++] = argv[i++];
983 static char buffer[30];
985 return "cannot access";
987 if (e > 0 && e < sys_nerr)
988 return sys_errlist[e];
990 sprintf (buffer, "Unknown error %d", e);
995 /* Read compilation specs from a file named FILENAME,
996 replacing the default ones.
998 A suffix which starts with `*' is a definition for
999 one of the machine-specific sub-specs. The "suffix" should be
1000 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1001 The corresponding spec is stored in asm_spec, etc.,
1002 rather than in the `compilers' vector.
1004 Anything invalid in the file is a fatal error. */
1007 read_specs (filename)
1012 struct stat statbuf;
1017 fprintf (stderr, "Reading specs from %s\n", filename);
1019 /* Open and stat the file. */
1020 desc = open (filename, O_RDONLY, 0);
1022 pfatal_with_name (filename);
1023 if (stat (filename, &statbuf) < 0)
1024 pfatal_with_name (filename);
1026 /* Read contents of file into BUFFER. */
1027 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1028 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1030 pfatal_with_name (filename);
1031 buffer[readlen] = 0;
1034 /* Scan BUFFER for specs, putting them in the vector. */
1040 char *in, *out, *p1, *p2;
1042 /* Advance P in BUFFER to the next nonblank nocomment line. */
1043 p = skip_whitespace (p);
1047 /* Find the colon that should end the suffix. */
1049 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
1050 /* The colon shouldn't be missing. */
1052 fatal ("specs file malformed after %d characters", p1 - buffer);
1053 /* Skip back over trailing whitespace. */
1055 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
1056 /* Copy the suffix to a string. */
1057 suffix = save_string (p, p2 - p);
1058 /* Find the next line. */
1059 p = skip_whitespace (p1 + 1);
1061 fatal ("specs file malformed after %d characters", p - buffer);
1063 /* Find next blank line. */
1064 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
1065 /* Specs end at the blank line and do not include the newline. */
1066 spec = save_string (p, p1 - p);
1069 /* Delete backslash-newline sequences from the spec. */
1074 if (in[0] == '\\' && in[1] == '\n')
1076 else if (in[0] == '#')
1078 while (*in && *in != '\n') in++;
1085 if (suffix[0] == '*')
1087 if (! strcmp (suffix, "*link_command"))
1088 link_command_spec = spec;
1090 set_spec (suffix + 1, spec);
1094 /* Add this pair to the vector. */
1096 = ((struct compiler *)
1097 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
1098 compilers[n_compilers].suffix = suffix;
1099 bzero ((char *) compilers[n_compilers].spec,
1100 sizeof compilers[n_compilers].spec);
1101 compilers[n_compilers].spec[0] = spec;
1103 bzero ((char *) &compilers[n_compilers],
1104 sizeof compilers[n_compilers]);
1108 link_command_spec = spec;
1111 if (link_command_spec == 0)
1112 fatal ("spec file has no spec for linking");
1121 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1122 be considered whitespace. */
1123 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1125 else if (*p == '\n' || *p == ' ' || *p == '\t')
1129 while (*p != '\n') p++;
1139 /* Structure to keep track of the specs that have been defined so far. These
1140 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1144 char *name; /* Name of the spec. */
1145 char *spec; /* The spec itself. */
1146 struct spec_list *next; /* Next spec in linked list. */
1149 /* List of specs that have been defined so far. */
1151 static struct spec_list *specs = (struct spec_list *) 0;
1153 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1154 removed; If the spec starts with a + then SPEC is added to the end of the
1158 set_spec (name, spec)
1162 struct spec_list *sl;
1165 /* See if the spec already exists */
1166 for (sl = specs; sl; sl = sl->next)
1167 if (strcmp (sl->name, name) == 0)
1172 /* Not found - make it */
1173 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1174 sl->name = save_string (name, strlen (name));
1175 sl->spec = save_string ("", 0);
1180 old_spec = sl->spec;
1181 if (name && spec[0] == '+' && isspace (spec[1]))
1182 sl->spec = concat (old_spec, spec + 1, NULL_PTR);
1184 sl->spec = save_string (spec, strlen (spec));
1186 if (! strcmp (name, "asm"))
1187 asm_spec = sl->spec;
1188 else if (! strcmp (name, "asm_final"))
1189 asm_final_spec = sl->spec;
1190 else if (! strcmp (name, "cc1"))
1191 cc1_spec = sl->spec;
1192 else if (! strcmp (name, "cc1plus"))
1193 cc1plus_spec = sl->spec;
1194 else if (! strcmp (name, "cpp"))
1195 cpp_spec = sl->spec;
1196 else if (! strcmp (name, "endfile"))
1197 endfile_spec = sl->spec;
1198 else if (! strcmp (name, "lib"))
1199 lib_spec = sl->spec;
1200 else if (! strcmp (name, "libgcc"))
1201 libgcc_spec = sl->spec;
1202 else if (! strcmp (name, "link"))
1203 link_spec = sl->spec;
1204 else if (! strcmp (name, "predefines"))
1205 cpp_predefines = sl->spec;
1206 else if (! strcmp (name, "signed_char"))
1207 signed_char_spec = sl->spec;
1208 else if (! strcmp (name, "startfile"))
1209 startfile_spec = sl->spec;
1210 else if (! strcmp (name, "switches_need_spaces"))
1211 switches_need_spaces = sl->spec;
1212 else if (! strcmp (name, "cross_compile"))
1213 cross_compile = atoi (sl->spec);
1214 else if (! strcmp (name, "multilib"))
1215 multilib_select = sl->spec;
1220 for (i = 0; i < sizeof (extra_specs) / sizeof (extra_specs[0]); i++)
1222 if (! strcmp (name, extra_specs[i].name))
1224 extra_specs[i].spec = sl->spec;
1231 /* Free the old spec */
1236 /* Accumulate a command (program name and args), and run it. */
1238 /* Vector of pointers to arguments in the current line of specifications. */
1240 static char **argbuf;
1242 /* Number of elements allocated in argbuf. */
1244 static int argbuf_length;
1246 /* Number of elements in argbuf currently in use (containing args). */
1248 static int argbuf_index;
1250 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1251 temp file. Used only if MKTEMP_EACH_FILE. */
1253 static struct temp_name {
1254 char *suffix; /* suffix associated with the code. */
1255 int length; /* strlen (suffix). */
1256 int unique; /* Indicates whether %g or %u/%U was used. */
1257 char *filename; /* associated filename. */
1258 int filename_length; /* strlen (filename). */
1259 struct temp_name *next;
1262 /* Number of commands executed so far. */
1264 static int execution_count;
1266 /* Number of commands that exited with a signal. */
1268 static int signal_count;
1270 /* Name with which this program was invoked. */
1272 static char *programname;
1274 /* Structures to keep track of prefixes to try when looking for files. */
1278 char *prefix; /* String to prepend to the path. */
1279 struct prefix_list *next; /* Next in linked list. */
1280 int require_machine_suffix; /* Don't use without machine_suffix. */
1281 /* 2 means try both machine_suffix and just_machine_suffix. */
1282 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1287 struct prefix_list *plist; /* List of prefixes to try */
1288 int max_len; /* Max length of a prefix in PLIST */
1289 char *name; /* Name of this list (used in config stuff) */
1292 /* List of prefixes to try when looking for executables. */
1294 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1296 /* List of prefixes to try when looking for startup (crt0) files. */
1298 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1300 /* List of prefixes to try when looking for include files. */
1302 static struct path_prefix include_prefixes = { 0, 0, "include" };
1304 /* Suffix to attach to directories searched for commands.
1305 This looks like `MACHINE/VERSION/'. */
1307 static char *machine_suffix = 0;
1309 /* Suffix to attach to directories searched for commands.
1310 This is just `MACHINE/'. */
1312 static char *just_machine_suffix = 0;
1314 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1316 static char *gcc_exec_prefix;
1318 /* Default prefixes to attach to command names. */
1320 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1321 #undef MD_EXEC_PREFIX
1322 #undef MD_STARTFILE_PREFIX
1323 #undef MD_STARTFILE_PREFIX_1
1326 #ifndef STANDARD_EXEC_PREFIX
1327 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1328 #endif /* !defined STANDARD_EXEC_PREFIX */
1330 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1331 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1332 #ifdef MD_EXEC_PREFIX
1333 static char *md_exec_prefix = MD_EXEC_PREFIX;
1336 #ifndef STANDARD_STARTFILE_PREFIX
1337 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1338 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1340 #ifdef MD_STARTFILE_PREFIX
1341 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1343 #ifdef MD_STARTFILE_PREFIX_1
1344 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1346 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1347 static char *standard_startfile_prefix_1 = "/lib/";
1348 static char *standard_startfile_prefix_2 = "/usr/lib/";
1350 #ifndef TOOLDIR_BASE_PREFIX
1351 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1353 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1354 static char *tooldir_prefix;
1356 /* Subdirectory to use for locating libraries. Set by
1357 set_multilib_dir based on the compilation options. */
1359 static char *multilib_dir;
1361 /* Clear out the vector of arguments (after a command is executed). */
1369 /* Add one argument to the vector at the end.
1370 This is done when a space is seen or at the end of the line.
1371 If DELETE_ALWAYS is nonzero, the arg is a filename
1372 and the file should be deleted eventually.
1373 If DELETE_FAILURE is nonzero, the arg is a filename
1374 and the file should be deleted if this compilation fails. */
1377 store_arg (arg, delete_always, delete_failure)
1379 int delete_always, delete_failure;
1381 if (argbuf_index + 1 == argbuf_length)
1383 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1386 argbuf[argbuf_index++] = arg;
1387 argbuf[argbuf_index] = 0;
1389 if (delete_always || delete_failure)
1390 record_temp_file (arg, delete_always, delete_failure);
1393 /* Record the names of temporary files we tell compilers to write,
1394 and delete them at the end of the run. */
1396 /* This is the common prefix we use to make temp file names.
1397 It is chosen once for each run of this program.
1398 It is substituted into a spec by %g.
1399 Thus, all temp file names contain this prefix.
1400 In practice, all temp file names start with this prefix.
1402 This prefix comes from the envvar TMPDIR if it is defined;
1403 otherwise, from the P_tmpdir macro if that is defined;
1404 otherwise, in /usr/tmp or /tmp;
1405 or finally the current directory if all else fails. */
1407 static char *temp_filename;
1409 /* Length of the prefix. */
1411 static int temp_filename_length;
1413 /* Define the list of temporary files to delete. */
1418 struct temp_file *next;
1421 /* Queue of files to delete on success or failure of compilation. */
1422 static struct temp_file *always_delete_queue;
1423 /* Queue of files to delete on failure of compilation. */
1424 static struct temp_file *failure_delete_queue;
1426 /* Record FILENAME as a file to be deleted automatically.
1427 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1428 otherwise delete it in any case.
1429 FAIL_DELETE nonzero means delete it if a compilation step fails;
1430 otherwise delete it in any case. */
1433 record_temp_file (filename, always_delete, fail_delete)
1438 register char *name;
1439 name = xmalloc (strlen (filename) + 1);
1440 strcpy (name, filename);
1444 register struct temp_file *temp;
1445 for (temp = always_delete_queue; temp; temp = temp->next)
1446 if (! strcmp (name, temp->name))
1448 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1449 temp->next = always_delete_queue;
1451 always_delete_queue = temp;
1457 register struct temp_file *temp;
1458 for (temp = failure_delete_queue; temp; temp = temp->next)
1459 if (! strcmp (name, temp->name))
1461 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1462 temp->next = failure_delete_queue;
1464 failure_delete_queue = temp;
1469 /* Delete all the temporary files whose names we previously recorded. */
1472 delete_if_ordinary (name)
1479 printf ("Delete %s? (y or n) ", name);
1483 while ((c = getchar ()) != '\n' && c != EOF) ;
1484 if (i == 'y' || i == 'Y')
1486 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1487 if (unlink (name) < 0)
1489 perror_with_name (name);
1493 delete_temp_files ()
1495 register struct temp_file *temp;
1497 for (temp = always_delete_queue; temp; temp = temp->next)
1498 delete_if_ordinary (temp->name);
1499 always_delete_queue = 0;
1502 /* Delete all the files to be deleted on error. */
1505 delete_failure_queue ()
1507 register struct temp_file *temp;
1509 for (temp = failure_delete_queue; temp; temp = temp->next)
1510 delete_if_ordinary (temp->name);
1514 clear_failure_queue ()
1516 failure_delete_queue = 0;
1519 /* Routine to add variables to the environment. We do this to pass
1520 the pathname of the gcc driver, and the directories search to the
1521 collect2 program, which is being run as ld. This way, we can be
1522 sure of executing the right compiler when collect2 wants to build
1523 constructors and destructors. Since the environment variables we
1524 use come from an obstack, we don't have to worry about allocating
1533 #ifndef VMS /* nor about VMS */
1535 extern char **environ;
1536 char **old_environ = environ;
1540 int str_len = strlen (str);
1544 while ((ch = *p++) != '\0' && ch != '=')
1550 /* Search for replacing an existing environment variable, and
1551 count the number of total environment variables. */
1552 for (envp = old_environ; *envp; envp++)
1555 if (!strncmp (str, *envp, name_len))
1562 /* Add a new environment variable */
1563 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1565 bcopy ((char *) old_environ, (char *) (environ + 1),
1566 sizeof (char *) * (num_envs+1));
1571 #endif /* HAVE_PUTENV */
1574 /* Build a list of search directories from PATHS.
1575 PREFIX is a string to prepend to the list.
1576 If CHECK_DIR_P is non-zero we ensure the directory exists.
1577 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1578 It is also used by the --print-search-dirs flag. */
1581 build_search_list (paths, prefix, check_dir_p)
1582 struct path_prefix *paths;
1586 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1588 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1589 int first_time = TRUE;
1590 struct prefix_list *pprefix;
1592 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1594 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1596 int len = strlen (pprefix->prefix);
1600 || is_directory (pprefix->prefix, machine_suffix, 0)))
1603 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1606 obstack_grow (&collect_obstack, pprefix->prefix, len);
1607 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1610 if (just_machine_suffix
1611 && pprefix->require_machine_suffix == 2
1613 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1616 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1619 obstack_grow (&collect_obstack, pprefix->prefix, len);
1620 obstack_grow (&collect_obstack, just_machine_suffix,
1624 if (!pprefix->require_machine_suffix)
1627 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1630 obstack_grow (&collect_obstack, pprefix->prefix, len);
1633 obstack_1grow (&collect_obstack, '\0');
1634 return obstack_finish (&collect_obstack);
1637 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1640 putenv_from_prefixes (paths, env_var)
1641 struct path_prefix *paths;
1644 putenv (build_search_list (paths, env_var, 1));
1647 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1648 access to check permissions.
1649 Return 0 if not found, otherwise return its name, allocated with malloc. */
1652 find_a_file (pprefix, name, mode)
1653 struct path_prefix *pprefix;
1658 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1659 struct prefix_list *pl;
1660 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1663 len += strlen (machine_suffix);
1665 temp = xmalloc (len);
1667 /* Determine the filename to execute (special case for absolute paths). */
1669 if (*name == '/' || *name == DIR_SEPARATOR)
1671 if (access (name, mode))
1673 strcpy (temp, name);
1678 for (pl = pprefix->plist; pl; pl = pl->next)
1682 /* Some systems have a suffix for executable files.
1683 So try appending that first. */
1684 if (file_suffix[0] != 0)
1686 strcpy (temp, pl->prefix);
1687 strcat (temp, machine_suffix);
1688 strcat (temp, name);
1689 strcat (temp, file_suffix);
1690 if (access (temp, mode) == 0)
1692 if (pl->used_flag_ptr != 0)
1693 *pl->used_flag_ptr = 1;
1698 /* Now try just the name. */
1699 strcpy (temp, pl->prefix);
1700 strcat (temp, machine_suffix);
1701 strcat (temp, name);
1702 if (access (temp, mode) == 0)
1704 if (pl->used_flag_ptr != 0)
1705 *pl->used_flag_ptr = 1;
1710 /* Certain prefixes are tried with just the machine type,
1711 not the version. This is used for finding as, ld, etc. */
1712 if (just_machine_suffix && pl->require_machine_suffix == 2)
1714 /* Some systems have a suffix for executable files.
1715 So try appending that first. */
1716 if (file_suffix[0] != 0)
1718 strcpy (temp, pl->prefix);
1719 strcat (temp, just_machine_suffix);
1720 strcat (temp, name);
1721 strcat (temp, file_suffix);
1722 if (access (temp, mode) == 0)
1724 if (pl->used_flag_ptr != 0)
1725 *pl->used_flag_ptr = 1;
1730 strcpy (temp, pl->prefix);
1731 strcat (temp, just_machine_suffix);
1732 strcat (temp, name);
1733 if (access (temp, mode) == 0)
1735 if (pl->used_flag_ptr != 0)
1736 *pl->used_flag_ptr = 1;
1741 /* Certain prefixes can't be used without the machine suffix
1742 when the machine or version is explicitly specified. */
1743 if (!pl->require_machine_suffix)
1745 /* Some systems have a suffix for executable files.
1746 So try appending that first. */
1747 if (file_suffix[0] != 0)
1749 strcpy (temp, pl->prefix);
1750 strcat (temp, name);
1751 strcat (temp, file_suffix);
1752 if (access (temp, mode) == 0)
1754 if (pl->used_flag_ptr != 0)
1755 *pl->used_flag_ptr = 1;
1760 strcpy (temp, pl->prefix);
1761 strcat (temp, name);
1762 if (access (temp, mode) == 0)
1764 if (pl->used_flag_ptr != 0)
1765 *pl->used_flag_ptr = 1;
1775 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1776 at the start of the list, otherwise it goes at the end.
1778 If WARN is nonzero, we will warn if no file is found
1779 through this prefix. WARN should point to an int
1780 which will be set to 1 if this entry is used.
1782 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1783 the complete value of machine_suffix.
1784 2 means try both machine_suffix and just_machine_suffix. */
1787 add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1788 struct path_prefix *pprefix;
1791 int require_machine_suffix;
1794 struct prefix_list *pl, **prev;
1797 if (!first && pprefix->plist)
1799 for (pl = pprefix->plist; pl->next; pl = pl->next)
1804 prev = &pprefix->plist;
1806 /* Keep track of the longest prefix */
1808 len = strlen (prefix);
1809 if (len > pprefix->max_len)
1810 pprefix->max_len = len;
1812 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1813 pl->prefix = save_string (prefix, len);
1814 pl->require_machine_suffix = require_machine_suffix;
1815 pl->used_flag_ptr = warn;
1822 pl->next = (struct prefix_list *) 0;
1826 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1829 unused_prefix_warnings (pprefix)
1830 struct path_prefix *pprefix;
1832 struct prefix_list *pl = pprefix->plist;
1836 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1838 if (pl->require_machine_suffix && machine_suffix)
1839 error ("file path prefix `%s%s' never used", pl->prefix,
1842 error ("file path prefix `%s' never used", pl->prefix);
1844 /* Prevent duplicate warnings. */
1845 *pl->used_flag_ptr = 1;
1851 /* Get rid of all prefixes built up so far in *PLISTP. */
1854 free_path_prefix (pprefix)
1855 struct path_prefix *pprefix;
1857 struct prefix_list *pl = pprefix->plist;
1858 struct prefix_list *temp;
1864 free (temp->prefix);
1865 free ((char *) temp);
1867 pprefix->plist = (struct prefix_list *) 0;
1870 /* Execute the command specified by the arguments on the current line of spec.
1871 When using pipes, this includes several piped-together commands
1872 with `|' between them.
1874 Return 0 if successful, -1 if failed. */
1880 int n_commands; /* # of command. */
1884 char *prog; /* program name. */
1885 char **argv; /* vector of args. */
1886 int pid; /* pid of process for this command. */
1889 struct command *commands; /* each command buffer with above info. */
1891 /* Count # of piped commands. */
1892 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1893 if (strcmp (argbuf[i], "|") == 0)
1896 /* Get storage for each command. */
1898 = (struct command *) alloca (n_commands * sizeof (struct command));
1900 /* Split argbuf into its separate piped processes,
1901 and record info about each one.
1902 Also search for the programs that are to be run. */
1904 commands[0].prog = argbuf[0]; /* first command. */
1905 commands[0].argv = &argbuf[0];
1906 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
1908 commands[0].argv[0] = string;
1910 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1911 if (strcmp (argbuf[i], "|") == 0)
1912 { /* each command. */
1913 #if defined (__MSDOS__) || defined (_WIN32) || defined (OS2)
1914 fatal ("-pipe not supported");
1916 argbuf[i] = 0; /* termination of command args. */
1917 commands[n_commands].prog = argbuf[i + 1];
1918 commands[n_commands].argv = &argbuf[i + 1];
1919 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
1921 commands[n_commands].argv[0] = string;
1925 argbuf[argbuf_index] = 0;
1927 /* If -v, print what we are about to do, and maybe query. */
1931 /* Print each piped command as a separate line. */
1932 for (i = 0; i < n_commands ; i++)
1936 for (j = commands[i].argv; *j; j++)
1937 fprintf (stderr, " %s", *j);
1939 /* Print a pipe symbol after all but the last command. */
1940 if (i + 1 != n_commands)
1941 fprintf (stderr, " |");
1942 fprintf (stderr, "\n");
1946 fprintf (stderr, "\nGo ahead? (y or n) ");
1950 while (getchar () != '\n') ;
1951 if (i != 'y' && i != 'Y')
1956 /* Run each piped subprocess. */
1958 for (i = 0; i < n_commands; i++)
1960 char *errmsg_fmt, *errmsg_arg;
1961 char *string = commands[i].argv[0];
1963 commands[i].pid = pexecute (string, commands[i].argv,
1964 programname, temp_filename,
1965 &errmsg_fmt, &errmsg_arg,
1966 ((i == 0 ? PEXECUTE_FIRST : 0)
1967 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
1968 | (string == commands[i].prog
1969 ? PEXECUTE_SEARCH : 0)
1970 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
1972 if (commands[i].pid == -1)
1973 pfatal_pexecute (errmsg_fmt, errmsg_arg);
1975 if (string != commands[i].prog)
1981 /* Wait for all the subprocesses to finish.
1982 We don't care what order they finish in;
1983 we know that N_COMMANDS waits will get them all.
1984 Ignore subprocesses that we don't know about,
1985 since they can be spawned by the process that exec'ed us. */
1990 for (i = 0; i < n_commands; )
1996 pid = pwait (commands[i].pid, &status, 0);
2000 for (j = 0; j < n_commands; j++)
2001 if (commands[j].pid == pid)
2006 if (WIFSIGNALED (status))
2008 fatal ("Internal compiler error: program %s got fatal signal %d",
2009 commands[j].prog, WTERMSIG (status));
2013 else if (WIFEXITED (status)
2014 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2024 /* Find all the switches given to us
2025 and make a vector describing them.
2026 The elements of the vector are strings, one per switch given.
2027 If a switch uses following arguments, then the `part1' field
2028 is the switch itself and the `args' field
2029 is a null-terminated vector containing the following arguments.
2030 The `live_cond' field is 1 if the switch is true in a conditional spec,
2031 -1 if false (overridden by a later switch), and is initialized to zero.
2032 The `valid' field is nonzero if any spec has looked at this switch;
2033 if it remains zero at the end of the run, it must be meaningless. */
2043 static struct switchstr *switches;
2045 static int n_switches;
2053 /* Also a vector of input files specified. */
2055 static struct infile *infiles;
2057 static int n_infiles;
2059 /* And a vector of corresponding output files is made up later. */
2061 static char **outfiles;
2063 /* Used to track if none of the -B paths are used. */
2066 /* Used to track if standard path isn't used and -b or -V is specified. */
2067 static int warn_std;
2069 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2070 static int *warn_std_ptr = 0;
2072 /* Create the vector `switches' and its contents.
2073 Store its length in `n_switches'. */
2076 process_command (argc, argv)
2082 char *spec_lang = 0;
2083 int last_language_n_infiles;
2086 int lang_n_infiles = 0;
2088 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
2093 /* Figure compiler version from version string. */
2095 compiler_version = save_string (version_string, strlen (version_string));
2096 for (temp = compiler_version; *temp; ++temp)
2105 /* Set up the default search paths. */
2107 if (gcc_exec_prefix)
2109 add_prefix (&exec_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2110 add_prefix (&startfile_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2113 /* COMPILER_PATH and LIBRARY_PATH have values
2114 that are lists of directory names with colons. */
2116 temp = getenv ("COMPILER_PATH");
2119 char *startp, *endp;
2120 char *nstore = (char *) alloca (strlen (temp) + 3);
2122 startp = endp = temp;
2125 if (*endp == PATH_SEPARATOR || *endp == 0)
2127 strncpy (nstore, startp, endp-startp);
2129 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2130 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2132 nstore[endp-startp] = DIR_SEPARATOR;
2133 nstore[endp-startp+1] = 0;
2136 nstore[endp-startp] = 0;
2137 add_prefix (&exec_prefixes, nstore, 0, 0, NULL_PTR);
2140 endp = startp = endp + 1;
2147 temp = getenv ("LIBRARY_PATH");
2148 if (temp && ! cross_compile)
2150 char *startp, *endp;
2151 char *nstore = (char *) alloca (strlen (temp) + 3);
2153 startp = endp = temp;
2156 if (*endp == PATH_SEPARATOR || *endp == 0)
2158 strncpy (nstore, startp, endp-startp);
2160 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2161 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2163 nstore[endp-startp] = DIR_SEPARATOR;
2164 nstore[endp-startp+1] = 0;
2167 nstore[endp-startp] = 0;
2168 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2171 endp = startp = endp + 1;
2178 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2179 temp = getenv ("LPATH");
2180 if (temp && ! cross_compile)
2182 char *startp, *endp;
2183 char *nstore = (char *) alloca (strlen (temp) + 3);
2185 startp = endp = temp;
2188 if (*endp == PATH_SEPARATOR || *endp == 0)
2190 strncpy (nstore, startp, endp-startp);
2192 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2193 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2195 nstore[endp-startp] = DIR_SEPARATOR;
2196 nstore[endp-startp+1] = 0;
2199 nstore[endp-startp] = 0;
2200 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2203 endp = startp = endp + 1;
2210 /* Convert new-style -- options to old-style. */
2211 translate_options (&argc, &argv);
2213 /* Scan argv twice. Here, the first time, just count how many switches
2214 there will be in their vector, and how many input files in theirs.
2215 Here we also parse the switches that cc itself uses (e.g. -v). */
2217 for (i = 1; i < argc; i++)
2219 if (! strcmp (argv[i], "-dumpspecs"))
2221 printf ("*asm:\n%s\n\n", asm_spec);
2222 printf ("*asm_final:\n%s\n\n", asm_final_spec);
2223 printf ("*cpp:\n%s\n\n", cpp_spec);
2224 printf ("*cc1:\n%s\n\n", cc1_spec);
2225 printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
2226 printf ("*endfile:\n%s\n\n", endfile_spec);
2227 printf ("*link:\n%s\n\n", link_spec);
2228 printf ("*lib:\n%s\n\n", lib_spec);
2229 printf ("*libgcc:\n%s\n\n", libgcc_spec);
2230 printf ("*startfile:\n%s\n\n", startfile_spec);
2231 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
2232 printf ("*signed_char:\n%s\n\n", signed_char_spec);
2233 printf ("*predefines:\n%s\n\n", cpp_predefines);
2234 printf ("*cross_compile:\n%d\n\n", cross_compile);
2235 printf ("*multilib:\n%s\n\n", multilib_select);
2240 for (j = 0; j < sizeof (extra_specs) / sizeof (extra_specs[0]); j++)
2241 printf ("*%s:\n%s\n\n", extra_specs[j].name,
2242 (extra_specs[j].spec) ? extra_specs[j].spec : "");
2247 else if (! strcmp (argv[i], "-dumpversion"))
2249 printf ("%s\n", version_string);
2252 else if (! strcmp (argv[i], "-dumpmachine"))
2254 printf ("%s\n", spec_machine);
2257 else if (! strcmp (argv[i], "-print-search-dirs"))
2258 print_search_dirs = 1;
2259 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2260 print_file_name = "libgcc.a";
2261 else if (! strncmp (argv[i], "-print-file-name=", 17))
2262 print_file_name = argv[i] + 17;
2263 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2264 print_prog_name = argv[i] + 17;
2265 else if (! strcmp (argv[i], "-print-multi-lib"))
2266 print_multi_lib = 1;
2267 else if (! strcmp (argv[i], "-print-multi-directory"))
2268 print_multi_directory = 1;
2269 else if (! strncmp (argv[i], "-Wa,", 4))
2272 /* Pass the rest of this option to the assembler. */
2274 n_assembler_options++;
2275 if (!assembler_options)
2277 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2280 = (char **) xrealloc (assembler_options,
2281 n_assembler_options * sizeof (char **));
2283 /* Split the argument at commas. */
2285 for (j = 4; argv[i][j]; j++)
2286 if (argv[i][j] == ',')
2288 assembler_options[n_assembler_options - 1]
2289 = save_string (argv[i] + prev, j - prev);
2290 n_assembler_options++;
2292 = (char **) xrealloc (assembler_options,
2293 n_assembler_options * sizeof (char **));
2296 /* Record the part after the last comma. */
2297 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2299 else if (! strncmp (argv[i], "-Wp,", 4))
2302 /* Pass the rest of this option to the preprocessor. */
2304 n_preprocessor_options++;
2305 if (!preprocessor_options)
2306 preprocessor_options
2307 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2309 preprocessor_options
2310 = (char **) xrealloc (preprocessor_options,
2311 n_preprocessor_options * sizeof (char **));
2313 /* Split the argument at commas. */
2315 for (j = 4; argv[i][j]; j++)
2316 if (argv[i][j] == ',')
2318 preprocessor_options[n_preprocessor_options - 1]
2319 = save_string (argv[i] + prev, j - prev);
2320 n_preprocessor_options++;
2321 preprocessor_options
2322 = (char **) xrealloc (preprocessor_options,
2323 n_preprocessor_options * sizeof (char **));
2326 /* Record the part after the last comma. */
2327 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2329 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2330 /* The +e options to the C++ front-end. */
2332 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2335 /* Split the argument at commas. */
2336 for (j = 3; argv[i][j]; j++)
2337 n_infiles += (argv[i][j] == ',');
2339 else if (strcmp (argv[i], "-Xlinker") == 0)
2342 fatal ("argument to `-Xlinker' is missing");
2347 else if (strncmp (argv[i], "-l", 2) == 0)
2349 else if (strcmp (argv[i], "-save-temps") == 0)
2351 save_temps_flag = 1;
2354 else if (argv[i][0] == '-' && argv[i][1] != 0)
2356 register char *p = &argv[i][1];
2357 register int c = *p;
2362 if (p[1] == 0 && i + 1 == argc)
2363 fatal ("argument to `-b' is missing");
2365 spec_machine = argv[++i];
2367 spec_machine = p + 1;
2369 warn_std_ptr = &warn_std;
2374 int *temp = (int *) xmalloc (sizeof (int));
2376 if (p[1] == 0 && i + 1 == argc)
2377 fatal ("argument to `-B' is missing");
2382 add_prefix (&exec_prefixes, value, 1, 0, &warn_B);
2383 add_prefix (&startfile_prefixes, value, 1, 0, &warn_B);
2384 add_prefix (&include_prefixes, concat (value, "include", NULL_PTR),
2387 /* As a kludge, if the arg is "[foo/]stageN/", just add
2388 "[foo/]include" to the include prefix. */
2390 int len = strlen (value);
2393 && (value[len - 8] == '/'
2394 || value[len - 8] == DIR_SEPARATOR)))
2395 && strncmp (value + len - 7, "stage", 5) == 0
2396 && isdigit (value[len - 2])
2397 && (value[len - 1] == '/'
2398 || value[len - 1] == DIR_SEPARATOR))
2401 add_prefix (&include_prefixes, "include",
2405 char *string = xmalloc (len + 1);
2406 strncpy (string, value, len-7);
2407 strcat (string, "include");
2408 add_prefix (&include_prefixes, string,
2416 case 'v': /* Print our subcommands and print versions. */
2418 /* If they do anything other than exactly `-v', don't set
2419 verbose_flag; rather, continue on to give the error. */
2426 if (p[1] == 0 && i + 1 == argc)
2427 fatal ("argument to `-V' is missing");
2429 spec_version = argv[++i];
2431 spec_version = p + 1;
2432 compiler_version = spec_version;
2433 warn_std_ptr = &warn_std;
2453 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2454 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2455 else if (WORD_SWITCH_TAKES_ARG (p))
2456 i += WORD_SWITCH_TAKES_ARG (p);
2466 if (have_c && have_o && lang_n_infiles > 1)
2467 fatal ("cannot specify -o with -c and multiple compilations");
2469 /* Set up the search paths before we go looking for config files. */
2471 /* These come before the md prefixes so that we will find gcc's subcommands
2472 (such as cpp) rather than those of the host system. */
2473 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2474 as well as trying the machine and the version. */
2476 add_prefix (&exec_prefixes, standard_exec_prefix, 0, 2, warn_std_ptr);
2477 add_prefix (&exec_prefixes, standard_exec_prefix_1, 0, 2, warn_std_ptr);
2480 add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, warn_std_ptr);
2481 add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, warn_std_ptr);
2483 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
2484 dir_separator_str, NULL_PTR);
2486 /* If tooldir is relative, base it on exec_prefixes. A relative
2487 tooldir lets us move the installed tree as a unit.
2489 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2490 directories, so that we can search both the user specified directory
2491 and the standard place. */
2493 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2495 if (gcc_exec_prefix)
2497 char *gcc_exec_tooldir_prefix
2498 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2499 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2501 add_prefix (&exec_prefixes,
2502 concat (gcc_exec_tooldir_prefix, "bin",
2503 dir_separator_str, NULL_PTR),
2505 add_prefix (&startfile_prefixes,
2506 concat (gcc_exec_tooldir_prefix, "lib",
2507 dir_separator_str, NULL_PTR),
2511 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2512 dir_separator_str, spec_version,
2513 dir_separator_str, tooldir_prefix, NULL_PTR);
2516 add_prefix (&exec_prefixes,
2517 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2519 add_prefix (&startfile_prefixes,
2520 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2523 /* More prefixes are enabled in main, after we read the specs file
2524 and determine whether this is cross-compilation or not. */
2527 /* Then create the space for the vectors and scan again. */
2529 switches = ((struct switchstr *)
2530 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2531 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2534 last_language_n_infiles = -1;
2536 /* This, time, copy the text of each switch and store a pointer
2537 to the copy in the vector of switches.
2538 Store all the infiles in their vector. */
2540 for (i = 1; i < argc; i++)
2542 /* Just skip the switches that were handled by the preceding loop. */
2543 if (! strncmp (argv[i], "-Wa,", 4))
2545 else if (! strncmp (argv[i], "-Wp,", 4))
2547 else if (! strcmp (argv[i], "-print-search-dirs"))
2549 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2551 else if (! strncmp (argv[i], "-print-file-name=", 17))
2553 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2555 else if (! strcmp (argv[i], "-print-multi-lib"))
2557 else if (! strcmp (argv[i], "-print-multi-directory"))
2559 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2561 /* Compensate for the +e options to the C++ front-end;
2562 they're there simply for cfront call-compatibility. We do
2563 some magic in default_compilers to pass them down properly.
2564 Note we deliberately start at the `+' here, to avoid passing
2565 -e0 or -e1 down into the linker. */
2566 switches[n_switches].part1 = &argv[i][0];
2567 switches[n_switches].args = 0;
2568 switches[n_switches].live_cond = 0;
2569 switches[n_switches].valid = 0;
2572 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2575 /* Split the argument at commas. */
2577 for (j = 4; argv[i][j]; j++)
2578 if (argv[i][j] == ',')
2580 infiles[n_infiles].language = 0;
2581 infiles[n_infiles++].name
2582 = save_string (argv[i] + prev, j - prev);
2585 /* Record the part after the last comma. */
2586 infiles[n_infiles].language = 0;
2587 infiles[n_infiles++].name = argv[i] + prev;
2589 else if (strcmp (argv[i], "-Xlinker") == 0)
2591 infiles[n_infiles].language = 0;
2592 infiles[n_infiles++].name = argv[++i];
2594 else if (strncmp (argv[i], "-l", 2) == 0)
2596 infiles[n_infiles].language = 0;
2597 infiles[n_infiles++].name = argv[i];
2599 else if (argv[i][0] == '-' && argv[i][1] != 0)
2601 register char *p = &argv[i][1];
2602 register int c = *p;
2604 if (c == 'B' || c == 'b' || c == 'V')
2606 /* Skip a separate arg, if any. */
2613 if (p[1] == 0 && i + 1 == argc)
2614 fatal ("argument to `-x' is missing");
2616 spec_lang = argv[++i];
2619 if (! strcmp (spec_lang, "none"))
2620 /* Suppress the warning if -xnone comes after the last input
2621 file, because alternate command interfaces like g++ might
2622 find it useful to place -xnone after each input file. */
2625 last_language_n_infiles = n_infiles;
2628 switches[n_switches].part1 = p;
2629 /* Deal with option arguments in separate argv elements. */
2630 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2631 || WORD_SWITCH_TAKES_ARG (p))
2634 int n_args = WORD_SWITCH_TAKES_ARG (p);
2638 /* Count only the option arguments in separate argv elements. */
2639 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2641 if (i + n_args >= argc)
2642 fatal ("argument to `-%s' is missing", p);
2643 switches[n_switches].args
2644 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2646 switches[n_switches].args[j++] = argv[++i];
2647 /* Null-terminate the vector. */
2648 switches[n_switches].args[j] = 0;
2650 else if (index (switches_need_spaces, c))
2652 /* On some systems, ld cannot handle some options without
2653 a space. So split the option from its argument. */
2654 char *part1 = (char *) xmalloc (2);
2658 switches[n_switches].part1 = part1;
2659 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2660 switches[n_switches].args[0] = xmalloc (strlen (p));
2661 strcpy (switches[n_switches].args[0], &p[1]);
2662 switches[n_switches].args[1] = 0;
2665 switches[n_switches].args = 0;
2667 switches[n_switches].live_cond = 0;
2668 switches[n_switches].valid = 0;
2669 /* This is always valid, since gcc.c itself understands it. */
2670 if (!strcmp (p, "save-temps"))
2671 switches[n_switches].valid = 1;
2676 #ifdef HAVE_OBJECT_SUFFIX
2677 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2678 if (strlen (argv[i]) > 2
2679 && argv[i][strlen (argv[i]) - 2] == '.'
2680 && argv[i][strlen (argv[i]) - 1] == 'o')
2684 for (j = 0; j < strlen (argv[i]) - 2; j++)
2685 obstack_1grow (&obstack, argv[i][j]);
2687 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2688 obstack_1grow (&obstack, 0);
2689 argv[i] = obstack_finish (&obstack);
2693 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
2695 perror_with_name (argv[i]);
2700 infiles[n_infiles].language = spec_lang;
2701 infiles[n_infiles++].name = argv[i];
2706 if (n_infiles == last_language_n_infiles && spec_lang != 0)
2707 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2709 switches[n_switches].part1 = 0;
2710 infiles[n_infiles].name = 0;
2713 /* Process a spec string, accumulating and running commands. */
2715 /* These variables describe the input file name.
2716 input_file_number is the index on outfiles of this file,
2717 so that the output file name can be stored for later use by %o.
2718 input_basename is the start of the part of the input file
2719 sans all directory names, and basename_length is the number
2720 of characters starting there excluding the suffix .c or whatever. */
2722 static char *input_filename;
2723 static int input_file_number;
2724 static int input_filename_length;
2725 static int basename_length;
2726 static char *input_basename;
2727 static char *input_suffix;
2729 /* These are variables used within do_spec and do_spec_1. */
2731 /* Nonzero if an arg has been started and not yet terminated
2732 (with space, tab or newline). */
2733 static int arg_going;
2735 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2736 is a temporary file name. */
2737 static int delete_this_arg;
2739 /* Nonzero means %w has been seen; the next arg to be terminated
2740 is the output file name of this compilation. */
2741 static int this_is_output_file;
2743 /* Nonzero means %s has been seen; the next arg to be terminated
2744 is the name of a library file and we should try the standard
2745 search dirs for it. */
2746 static int this_is_library_file;
2748 /* Nonzero means that the input of this command is coming from a pipe. */
2749 static int input_from_pipe;
2751 /* Process the spec SPEC and run the commands specified therein.
2752 Returns 0 if the spec is successfully processed; -1 if failed. */
2762 delete_this_arg = 0;
2763 this_is_output_file = 0;
2764 this_is_library_file = 0;
2765 input_from_pipe = 0;
2767 value = do_spec_1 (spec, 0, NULL_PTR);
2769 /* Force out any unfinished command.
2770 If -pipe, this forces out the last command if it ended in `|'. */
2773 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2776 if (argbuf_index > 0)
2783 /* Process the sub-spec SPEC as a portion of a larger spec.
2784 This is like processing a whole spec except that we do
2785 not initialize at the beginning and we do not supply a
2786 newline by default at the end.
2787 INSWITCH nonzero means don't process %-sequences in SPEC;
2788 in this case, % is treated as an ordinary character.
2789 This is used while substituting switches.
2790 INSWITCH nonzero also causes SPC not to terminate an argument.
2792 Value is zero unless a line was finished
2793 and the command on that line reported an error. */
2796 do_spec_1 (spec, inswitch, soft_matched_part)
2799 char *soft_matched_part;
2801 register char *p = spec;
2808 /* If substituting a switch, treat all chars like letters.
2809 Otherwise, NL, SPC, TAB and % are special. */
2810 switch (inswitch ? 'a' : c)
2813 /* End of line: finish any pending argument,
2814 then run the pending command if one has been started. */
2817 obstack_1grow (&obstack, 0);
2818 string = obstack_finish (&obstack);
2819 if (this_is_library_file)
2820 string = find_file (string);
2821 store_arg (string, delete_this_arg, this_is_output_file);
2822 if (this_is_output_file)
2823 outfiles[input_file_number] = string;
2827 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2829 for (i = 0; i < n_switches; i++)
2830 if (!strcmp (switches[i].part1, "pipe"))
2833 /* A `|' before the newline means use a pipe here,
2834 but only if -pipe was specified.
2835 Otherwise, execute now and don't pass the `|' as an arg. */
2838 input_from_pipe = 1;
2839 switches[i].valid = 1;
2846 if (argbuf_index > 0)
2852 /* Reinitialize for a new command, and for a new argument. */
2855 delete_this_arg = 0;
2856 this_is_output_file = 0;
2857 this_is_library_file = 0;
2858 input_from_pipe = 0;
2862 /* End any pending argument. */
2865 obstack_1grow (&obstack, 0);
2866 string = obstack_finish (&obstack);
2867 if (this_is_library_file)
2868 string = find_file (string);
2869 store_arg (string, delete_this_arg, this_is_output_file);
2870 if (this_is_output_file)
2871 outfiles[input_file_number] = string;
2875 obstack_1grow (&obstack, c);
2881 /* Space or tab ends an argument if one is pending. */
2884 obstack_1grow (&obstack, 0);
2885 string = obstack_finish (&obstack);
2886 if (this_is_library_file)
2887 string = find_file (string);
2888 store_arg (string, delete_this_arg, this_is_output_file);
2889 if (this_is_output_file)
2890 outfiles[input_file_number] = string;
2892 /* Reinitialize for a new argument. */
2894 delete_this_arg = 0;
2895 this_is_output_file = 0;
2896 this_is_library_file = 0;
2903 fatal ("Invalid specification! Bug in cc.");
2906 obstack_grow (&obstack, input_basename, basename_length);
2911 delete_this_arg = 2;
2914 /* Dump out the directories specified with LIBRARY_PATH,
2915 followed by the absolute directories
2916 that we search for startfiles. */
2919 struct prefix_list *pl = startfile_prefixes.plist;
2921 char *buffer = (char *) xmalloc (bufsize);
2924 for (; pl; pl = pl->next)
2926 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2927 /* Used on systems which record the specified -L dirs
2928 and use them to search for dynamic linking. */
2929 /* Relative directories always come from -B,
2930 and it is better not to use them for searching
2931 at run time. In particular, stage1 loses */
2932 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
2935 /* Try subdirectory if there is one. */
2936 if (multilib_dir != NULL)
2940 if (strlen (pl->prefix) + strlen (machine_suffix)
2942 bufsize = (strlen (pl->prefix)
2943 + strlen (machine_suffix)) * 2 + 1;
2944 buffer = (char *) xrealloc (buffer, bufsize);
2945 strcpy (buffer, pl->prefix);
2946 strcat (buffer, machine_suffix);
2947 if (is_directory (buffer, multilib_dir, 1))
2949 do_spec_1 ("-L", 0, NULL_PTR);
2950 #ifdef SPACE_AFTER_L_OPTION
2951 do_spec_1 (" ", 0, NULL_PTR);
2953 do_spec_1 (buffer, 1, NULL_PTR);
2954 do_spec_1 (multilib_dir, 1, NULL_PTR);
2955 /* Make this a separate argument. */
2956 do_spec_1 (" ", 0, NULL_PTR);
2959 if (!pl->require_machine_suffix)
2961 if (is_directory (pl->prefix, multilib_dir, 1))
2963 do_spec_1 ("-L", 0, NULL_PTR);
2964 #ifdef SPACE_AFTER_L_OPTION
2965 do_spec_1 (" ", 0, NULL_PTR);
2967 do_spec_1 (pl->prefix, 1, NULL_PTR);
2968 do_spec_1 (multilib_dir, 1, NULL_PTR);
2969 /* Make this a separate argument. */
2970 do_spec_1 (" ", 0, NULL_PTR);
2976 if (is_directory (pl->prefix, machine_suffix, 1))
2978 do_spec_1 ("-L", 0, NULL_PTR);
2979 #ifdef SPACE_AFTER_L_OPTION
2980 do_spec_1 (" ", 0, NULL_PTR);
2982 do_spec_1 (pl->prefix, 1, NULL_PTR);
2983 /* Remove slash from machine_suffix. */
2984 if (strlen (machine_suffix) >= bufsize)
2985 bufsize = strlen (machine_suffix) * 2 + 1;
2986 buffer = (char *) xrealloc (buffer, bufsize);
2987 strcpy (buffer, machine_suffix);
2988 idx = strlen (buffer);
2989 if (buffer[idx - 1] == '/'
2990 || buffer[idx - 1] == DIR_SEPARATOR)
2991 buffer[idx - 1] = 0;
2992 do_spec_1 (buffer, 1, NULL_PTR);
2993 /* Make this a separate argument. */
2994 do_spec_1 (" ", 0, NULL_PTR);
2997 if (!pl->require_machine_suffix)
2999 if (is_directory (pl->prefix, "", 1))
3001 do_spec_1 ("-L", 0, NULL_PTR);
3002 #ifdef SPACE_AFTER_L_OPTION
3003 do_spec_1 (" ", 0, NULL_PTR);
3005 /* Remove slash from pl->prefix. */
3006 if (strlen (pl->prefix) >= bufsize)
3007 bufsize = strlen (pl->prefix) * 2 + 1;
3008 buffer = (char *) xrealloc (buffer, bufsize);
3009 strcpy (buffer, pl->prefix);
3010 idx = strlen (buffer);
3011 if (buffer[idx - 1] == '/'
3012 || buffer[idx - 1] == DIR_SEPARATOR)
3013 buffer[idx - 1] = 0;
3014 do_spec_1 (buffer, 1, NULL_PTR);
3015 /* Make this a separate argument. */
3016 do_spec_1 (" ", 0, NULL_PTR);
3025 /* {...:%efoo} means report an error with `foo' as error message
3026 and don't execute any more commands for this file. */
3030 while (*p != 0 && *p != '\n') p++;
3031 buf = (char *) alloca (p - q + 1);
3032 strncpy (buf, q, p - q);
3042 if (save_temps_flag)
3044 obstack_grow (&obstack, input_basename, basename_length);
3045 delete_this_arg = 0;
3049 #ifdef MKTEMP_EACH_FILE
3050 /* ??? This has a problem: the total number of
3051 values mktemp can return is limited.
3052 That matters for the names of object files.
3053 In 2.4, do something about that. */
3054 struct temp_name *t;
3056 while (*p == '.' || isalpha (*p)
3057 || (p[0] == '%' && p[1] == 'O'))
3060 /* See if we already have an association of %g/%u/%U and
3062 for (t = temp_names; t; t = t->next)
3063 if (t->length == p - suffix
3064 && strncmp (t->suffix, suffix, p - suffix) == 0
3065 && t->unique == (c != 'g'))
3068 /* Make a new association if needed. %u requires one. */
3069 if (t == 0 || c == 'u')
3073 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3074 t->next = temp_names;
3077 t->length = p - suffix;
3078 t->suffix = save_string (suffix, p - suffix);
3079 t->unique = (c != 'g');
3080 temp_filename = choose_temp_base ();
3081 temp_filename_length = strlen (temp_filename);
3082 t->filename = temp_filename;
3083 t->filename_length = temp_filename_length;
3086 obstack_grow (&obstack, t->filename, t->filename_length);
3087 delete_this_arg = 1;
3089 obstack_grow (&obstack, temp_filename, temp_filename_length);
3090 if (c == 'u' || c == 'U')
3096 sprintf (buff, "%d", unique);
3097 obstack_grow (&obstack, buff, strlen (buff));
3100 delete_this_arg = 1;
3106 obstack_grow (&obstack, input_filename, input_filename_length);
3112 struct prefix_list *pl = include_prefixes.plist;
3114 if (gcc_exec_prefix)
3116 do_spec_1 ("-iprefix", 1, NULL_PTR);
3117 /* Make this a separate argument. */
3118 do_spec_1 (" ", 0, NULL_PTR);
3119 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3120 do_spec_1 (" ", 0, NULL_PTR);
3123 for (; pl; pl = pl->next)
3125 do_spec_1 ("-isystem", 1, NULL_PTR);
3126 /* Make this a separate argument. */
3127 do_spec_1 (" ", 0, NULL_PTR);
3128 do_spec_1 (pl->prefix, 1, NULL_PTR);
3129 do_spec_1 (" ", 0, NULL_PTR);
3135 for (i = 0; i < n_infiles; i++)
3136 store_arg (outfiles[i], 0, 0);
3140 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3145 this_is_library_file = 1;
3149 this_is_output_file = 1;
3154 int cur_index = argbuf_index;
3155 /* Handle the {...} following the %W. */
3158 p = handle_braces (p + 1);
3161 /* If any args were output, mark the last one for deletion
3163 if (argbuf_index != cur_index)
3164 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3168 /* %x{OPTION} records OPTION for %X to output. */
3174 /* Skip past the option value and make a copy. */
3179 string = save_string (p1 + 1, p - p1 - 2);
3181 /* See if we already recorded this option. */
3182 for (i = 0; i < n_linker_options; i++)
3183 if (! strcmp (string, linker_options[i]))
3189 /* This option is new; add it. */
3191 if (!linker_options)
3193 = (char **) xmalloc (n_linker_options * sizeof (char **));
3196 = (char **) xrealloc (linker_options,
3197 n_linker_options * sizeof (char **));
3199 linker_options[n_linker_options - 1] = string;
3203 /* Dump out the options accumulated previously using %x. */
3205 for (i = 0; i < n_linker_options; i++)
3207 do_spec_1 (linker_options[i], 1, NULL_PTR);
3208 /* Make each accumulated option a separate argument. */
3209 do_spec_1 (" ", 0, NULL_PTR);
3213 /* Dump out the options accumulated previously using -Wa,. */
3215 for (i = 0; i < n_assembler_options; i++)
3217 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3218 /* Make each accumulated option a separate argument. */
3219 do_spec_1 (" ", 0, NULL_PTR);
3223 /* Dump out the options accumulated previously using -Wp,. */
3225 for (i = 0; i < n_preprocessor_options; i++)
3227 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3228 /* Make each accumulated option a separate argument. */
3229 do_spec_1 (" ", 0, NULL_PTR);
3233 /* Here are digits and numbers that just process
3234 a certain constant string as a spec. */
3237 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3243 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3249 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3255 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3261 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3267 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3273 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3279 value = do_spec_1 (link_spec, 0, NULL_PTR);
3285 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3291 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3298 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3302 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3306 if (! strncmp (y, "-D", 2))
3307 /* Copy the whole option. */
3308 while (*y && *y != ' ' && *y != '\t')
3310 else if (*y == ' ' || *y == '\t')
3311 /* Copy whitespace to the result. */
3313 /* Don't copy other options. */
3320 value = do_spec_1 (buf, 0, NULL_PTR);
3328 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3332 /* Copy all of CPP_PREDEFINES into BUF,
3333 but put __ after every -D and at the end of each arg. */
3337 if (! strncmp (y, "-D", 2))
3345 || (*(y+1) != '_' && ! isupper (*(y+1))))
3347 /* Stick __ at front of macro name. */
3350 /* Arrange to stick __ at the end as well. */
3354 /* Copy the macro name. */
3355 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3364 /* Copy the value given, if any. */
3365 while (*y && *y != ' ' && *y != '\t')
3368 else if (*y == ' ' || *y == '\t')
3369 /* Copy whitespace to the result. */
3371 /* Don't copy -A options */
3377 /* Copy all of CPP_PREDEFINES into BUF,
3378 but put __ after every -D. */
3382 if (! strncmp (y, "-D", 2))
3387 || (*(y+1) != '_' && ! isupper (*(y+1))))
3389 /* Stick -D__ at front of macro name. */
3395 /* Copy the macro name. */
3396 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3399 /* Copy the value given, if any. */
3400 while (*y && *y != ' ' && *y != '\t')
3405 /* Do not copy this macro - we have just done it before */
3406 while (*y && *y != ' ' && *y != '\t')
3410 else if (*y == ' ' || *y == '\t')
3411 /* Copy whitespace to the result. */
3413 /* Don't copy -A options */
3419 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3423 if (! strncmp (y, "-A", 2))
3424 /* Copy the whole option. */
3425 while (*y && *y != ' ' && *y != '\t')
3427 else if (*y == ' ' || *y == '\t')
3428 /* Copy whitespace to the result. */
3430 /* Don't copy other options. */
3437 value = do_spec_1 (buf, 0, NULL_PTR);
3444 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3449 /* Here we define characters other than letters and digits. */
3452 p = handle_braces (p);
3458 obstack_1grow (&obstack, '%');
3462 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3463 do_spec_1 (" ", 0, NULL_PTR);
3466 /* Process a string found as the value of a spec given by name.
3467 This feature allows individual machine descriptions
3468 to add and use their own specs.
3469 %[...] modifies -D options the way %P does;
3470 %(...) uses the spec unmodified. */
3475 struct spec_list *sl;
3478 /* The string after the S/P is the name of a spec that is to be
3480 while (*p && *p != ')' && *p != ']')
3483 /* See if it's in the list */
3484 for (len = p - name, sl = specs; sl; sl = sl->next)
3485 if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
3495 value = do_spec_1 (name, 0, NULL_PTR);
3501 char *x = (char *) alloca (strlen (name) * 2 + 1);
3505 /* Copy all of NAME into BUF, but put __ after
3506 every -D and at the end of each arg, */
3509 if (! strncmp (y, "-D", 2))
3517 else if (*y == ' ' || *y == 0)
3531 value = do_spec_1 (buf, 0, NULL_PTR);
3537 /* Discard the closing paren or bracket. */
3545 int c1 = *p++; /* Select first or second version number. */
3546 char *v = compiler_version;
3549 /* The format of the version string is
3550 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3552 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3553 while (! isdigit (*v))
3555 if (v > compiler_version && v[-1] != '-')
3558 /* If desired, advance to second version number. */
3561 /* Set V after the first period. */
3562 while (isdigit (*v))
3569 /* Set Q at the next period or at the end. */
3571 while (isdigit (*q))
3573 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3576 /* Put that part into the command. */
3577 obstack_grow (&obstack, v, q - v);
3583 if (input_from_pipe)
3584 do_spec_1 ("-", 0, NULL_PTR);
3593 /* Backslash: treat next character as ordinary. */
3598 /* Ordinary character: put it into the current argument. */
3599 obstack_1grow (&obstack, c);
3603 return 0; /* End of string */
3606 /* Return 0 if we call do_spec_1 and that returns -1. */
3619 /* A `|' after the open-brace means,
3620 if the test fails, output a single minus sign rather than nothing.
3621 This is used in %{|!pipe:...}. */
3625 /* A `!' after the open-brace negates the condition:
3626 succeed if the specified switch is not present. */
3630 /* A `.' after the open-brace means test against the current suffix. */
3640 while (*p != ':' && *p != '}') p++;
3643 register int count = 1;
3661 int found = (input_suffix != 0
3662 && strlen (input_suffix) == p - filter
3663 && strncmp (input_suffix, filter, p - filter) == 0);
3669 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3674 else if (p[-1] == '*' && p[0] == '}')
3676 /* Substitute all matching switches as separate args. */
3679 for (i = 0; i < n_switches; i++)
3680 if (!strncmp (switches[i].part1, filter, p - filter)
3681 && check_live_switch (i, p - filter))
3686 /* Test for presence of the specified switch. */
3690 /* If name specified ends in *, as in {x*:...},
3691 check for %* and handle that case. */
3692 if (p[-1] == '*' && !negate)
3697 /* First see whether we have %*. */
3701 if (*r == '%' && r[1] == '*')
3705 /* If we do, handle that case. */
3708 /* Substitute all matching switches as separate args.
3709 But do this by substituting for %*
3710 in the text that follows the colon. */
3712 unsigned hard_match_len = p - filter - 1;
3713 char *string = save_string (p + 1, q - p - 2);
3715 for (i = 0; i < n_switches; i++)
3716 if (!strncmp (switches[i].part1, filter, hard_match_len)
3717 && check_live_switch (i, -1))
3719 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
3720 /* Pass any arguments this switch has. */
3728 /* If name specified ends in *, as in {x*:...},
3729 check for presence of any switch name starting with x. */
3732 for (i = 0; i < n_switches; i++)
3734 unsigned hard_match_len = p - filter - 1;
3736 if (!strncmp (switches[i].part1, filter, hard_match_len)
3737 && check_live_switch (i, hard_match_len))
3743 /* Otherwise, check for presence of exact name specified. */
3746 for (i = 0; i < n_switches; i++)
3748 if (!strncmp (switches[i].part1, filter, p - filter)
3749 && switches[i].part1[p - filter] == 0
3750 && check_live_switch (i, -1))
3758 /* If it is as desired (present for %{s...}, absent for %{-s...})
3759 then substitute either the switch or the specified
3760 conditional text. */
3761 if (present != negate)
3769 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3775 /* Here if a %{|...} conditional fails: output a minus sign,
3776 which means "standard output" or "standard input". */
3777 do_spec_1 ("-", 0, NULL_PTR);
3784 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3785 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3786 spec, or -1 if either exact match or %* is used.
3788 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3789 whose value does not begin with "no-" is obsoleted by the same value
3790 with the "no-", similarly for a switch with the "no-" prefix. */
3793 check_live_switch (switchnum, prefix_length)
3797 char *name = switches[switchnum].part1;
3800 /* In the common case of {<at-most-one-letter>*}, a negating
3801 switch would always match, so ignore that case. We will just
3802 send the conflicting switches to the compiler phase. */
3803 if (prefix_length >= 0 && prefix_length <= 1)
3806 /* If we already processed this switch and determined if it was
3807 live or not, return our past determination. */
3808 if (switches[switchnum].live_cond != 0)
3809 return switches[switchnum].live_cond > 0;
3811 /* Now search for duplicate in a manner that depends on the name. */
3815 for (i = switchnum + 1; i < n_switches; i++)
3816 if (switches[i].part1[0] == 'O')
3818 switches[switchnum].valid = 1;
3819 switches[switchnum].live_cond = -1;
3824 case 'W': case 'f': case 'm':
3825 if (! strncmp (name + 1, "no-", 3))
3827 /* We have Xno-YYY, search for XYYY. */
3828 for (i = switchnum + 1; i < n_switches; i++)
3829 if (switches[i].part1[0] == name[0]
3830 && ! strcmp (&switches[i].part1[1], &name[4]))
3832 switches[switchnum].valid = 1;
3833 switches[switchnum].live_cond = -1;
3839 /* We have XYYY, search for Xno-YYY. */
3840 for (i = switchnum + 1; i < n_switches; i++)
3841 if (switches[i].part1[0] == name[0]
3842 && switches[i].part1[1] == 'n'
3843 && switches[i].part1[2] == 'o'
3844 && switches[i].part1[3] == '-'
3845 && !strcmp (&switches[i].part1[4], &name[1]))
3847 switches[switchnum].valid = 1;
3848 switches[switchnum].live_cond = -1;
3855 /* Otherwise the switch is live. */
3856 switches[switchnum].live_cond = 1;
3860 /* Pass a switch to the current accumulating command
3861 in the same form that we received it.
3862 SWITCHNUM identifies the switch; it is an index into
3863 the vector of switches gcc received, which is `switches'.
3864 This cannot fail since it never finishes a command line.
3866 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
3869 give_switch (switchnum, omit_first_word)
3871 int omit_first_word;
3873 if (!omit_first_word)
3875 do_spec_1 ("-", 0, NULL_PTR);
3876 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
3878 do_spec_1 (" ", 0, NULL_PTR);
3879 if (switches[switchnum].args != 0)
3882 for (p = switches[switchnum].args; *p; p++)
3884 do_spec_1 (*p, 1, NULL_PTR);
3885 do_spec_1 (" ", 0, NULL_PTR);
3888 switches[switchnum].valid = 1;
3891 /* Search for a file named NAME trying various prefixes including the
3892 user's -B prefix and some standard ones.
3893 Return the absolute file name found. If nothing is found, return NAME. */
3901 /* Try multilib_dir if it is defined. */
3902 if (multilib_dir != NULL)
3906 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
3907 strcpy (try, multilib_dir);
3908 strcat (try, dir_separator_str);
3911 newname = find_a_file (&startfile_prefixes, try, R_OK);
3913 /* If we don't find it in the multi library dir, then fall
3914 through and look for it in the normal places. */
3915 if (newname != NULL)
3919 newname = find_a_file (&startfile_prefixes, name, R_OK);
3920 return newname ? newname : name;
3923 /* Determine whether a directory exists. If LINKER, return 0 for
3924 certain fixed names not needed by the linker. If not LINKER, it is
3925 only important to return 0 if the host machine has a small ARG_MAX
3929 is_directory (path1, path2, linker)
3934 int len1 = strlen (path1);
3935 int len2 = strlen (path2);
3936 char *path = (char *) alloca (3 + len1 + len2);
3940 #ifndef SMALL_ARG_MAX
3945 /* Construct the path from the two parts. Ensure the string ends with "/.".
3946 The resulting path will be a directory even if the given path is a
3948 bcopy (path1, path, len1);
3949 bcopy (path2, path + len1, len2);
3950 cp = path + len1 + len2;
3951 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
3952 *cp++ = DIR_SEPARATOR;
3956 /* Exclude directories that the linker is known to search. */
3959 && strcmp (path, concat (dir_separator_str, "lib",
3960 dir_separator_str, ".", NULL_PTR)) == 0)
3962 && strcmp (path, concat (dir_separator_str, "usr",
3963 dir_separator_str, "lib",
3964 dir_separator_str, ".", NULL_PTR)) == 0)))
3967 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
3970 /* On fatal signals, delete all the temporary files. */
3973 fatal_error (signum)
3976 signal (signum, SIG_DFL);
3977 delete_failure_queue ();
3978 delete_temp_files ();
3979 /* Get the same signal again, this time not handled,
3980 so its normal effect occurs. */
3981 kill (getpid (), signum);
3992 int linker_was_run = 0;
3993 char *explicit_link_files;
3997 p = argv[0] + strlen (argv[0]);
3998 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4001 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4002 signal (SIGINT, fatal_error);
4004 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4005 signal (SIGHUP, fatal_error);
4007 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4008 signal (SIGTERM, fatal_error);
4010 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4011 signal (SIGPIPE, fatal_error);
4015 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4017 obstack_init (&obstack);
4019 /* Build multilib_select from the separate lines that make up each multilib
4022 char **q = multilib_raw;
4024 obstack_init (&multilib_obstack);
4025 while ((p = *q++) != (char *)0)
4026 obstack_grow (&multilib_obstack, p, strlen (p));
4028 obstack_1grow (&multilib_obstack, 0);
4029 multilib_select = obstack_finish (&multilib_obstack);
4032 /* Set up to remember the pathname of gcc and any options
4033 needed for collect. We use argv[0] instead of programname because
4034 we need the complete pathname. */
4035 obstack_init (&collect_obstack);
4036 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4037 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4038 putenv (obstack_finish (&collect_obstack));
4040 #ifdef INIT_ENVIRONMENT
4041 /* Set up any other necessary machine specific environment variables. */
4042 putenv (INIT_ENVIRONMENT);
4045 /* Choose directory for temp files. */
4047 temp_filename = choose_temp_base ();
4048 temp_filename_length = strlen (temp_filename);
4050 /* Make a table of what switches there are (switches, n_switches).
4051 Make a table of specified input files (infiles, n_infiles).
4052 Decode switches that are handled locally. */
4054 process_command (argc, argv);
4056 /* Initialize the vector of specs to just the default.
4057 This means one element containing 0s, as a terminator. */
4059 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4060 bcopy ((char *) default_compilers, (char *) compilers,
4061 sizeof default_compilers);
4062 n_compilers = n_default_compilers;
4064 /* Read specs from a file if there is one. */
4066 machine_suffix = concat (spec_machine, dir_separator_str,
4067 spec_version, dir_separator_str, NULL_PTR);
4068 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4070 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4071 /* Read the specs file unless it is a default one. */
4072 if (specs_file != 0 && strcmp (specs_file, "specs"))
4073 read_specs (specs_file);
4079 for (k = 0; k < sizeof (extra_specs) / sizeof (extra_specs[0]); k++)
4080 set_spec (extra_specs[k].name, extra_specs[k].spec);
4084 /* If not cross-compiling, look for startfiles in the standard places. */
4085 /* The fact that these are done here, after reading the specs file,
4086 means that it cannot be found in these directories.
4087 But that's okay. It should never be there anyway. */
4090 #ifdef MD_EXEC_PREFIX
4091 add_prefix (&exec_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4092 add_prefix (&startfile_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4095 #ifdef MD_STARTFILE_PREFIX
4096 add_prefix (&startfile_prefixes, md_startfile_prefix, 0, 0, NULL_PTR);
4099 #ifdef MD_STARTFILE_PREFIX_1
4100 add_prefix (&startfile_prefixes, md_startfile_prefix_1, 0, 0, NULL_PTR);
4103 /* If standard_startfile_prefix is relative, base it on
4104 standard_exec_prefix. This lets us move the installed tree
4105 as a unit. If GCC_EXEC_PREFIX is defined, base
4106 standard_startfile_prefix on that as well. */
4107 if (*standard_startfile_prefix == '/'
4108 || *standard_startfile_prefix == DIR_SEPARATOR)
4109 add_prefix (&startfile_prefixes, standard_startfile_prefix, 0, 0,
4113 if (gcc_exec_prefix)
4114 add_prefix (&startfile_prefixes,
4115 concat (gcc_exec_prefix, machine_suffix,
4116 standard_startfile_prefix, NULL_PTR),
4118 add_prefix (&startfile_prefixes,
4119 concat (standard_exec_prefix,
4121 standard_startfile_prefix, NULL_PTR),
4125 add_prefix (&startfile_prefixes, standard_startfile_prefix_1, 0, 0,
4127 add_prefix (&startfile_prefixes, standard_startfile_prefix_2, 0, 0,
4129 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4130 add_prefix (&startfile_prefixes, "./", 0, 1, NULL_PTR);
4135 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4136 add_prefix (&startfile_prefixes,
4137 concat (gcc_exec_prefix, machine_suffix,
4138 standard_startfile_prefix, NULL_PTR),
4142 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4143 if (gcc_exec_prefix)
4145 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4146 + strlen (spec_version)
4147 + strlen (spec_machine) + 3);
4148 strcpy (temp, gcc_exec_prefix);
4149 strcat (temp, spec_machine);
4150 strcat (temp, dir_separator_str);
4151 strcat (temp, spec_version);
4152 strcat (temp, dir_separator_str);
4153 gcc_exec_prefix = temp;
4156 /* Now we have the specs.
4157 Set the `valid' bits for switches that match anything in any spec. */
4159 validate_all_switches ();
4161 /* Now that we have the switches and the specs, set
4162 the subdirectory based on the options. */
4163 set_multilib_dir ();
4165 /* Warn about any switches that no pass was interested in. */
4167 for (i = 0; i < n_switches; i++)
4168 if (! switches[i].valid)
4169 error ("unrecognized option `-%s'", switches[i].part1);
4171 /* Obey some of the options. */
4173 if (print_search_dirs)
4175 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4176 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4177 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4181 if (print_file_name)
4183 printf ("%s\n", find_file (print_file_name));
4187 if (print_prog_name)
4189 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4190 printf ("%s\n", (newname ? newname : print_prog_name));
4194 if (print_multi_lib)
4196 print_multilib_info ();
4200 if (print_multi_directory)
4202 if (multilib_dir == NULL)
4205 printf ("%s\n", multilib_dir);
4211 if (! strcmp (version_string, compiler_version))
4212 fprintf (stderr, "gcc version %s\n", version_string);
4214 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4215 version_string, compiler_version);
4222 fatal ("No input files");
4224 /* Make a place to record the compiler output file names
4225 that correspond to the input files. */
4227 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4228 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4230 /* Record which files were specified explicitly as link input. */
4232 explicit_link_files = xmalloc (n_infiles);
4233 bzero (explicit_link_files, n_infiles);
4235 for (i = 0; i < n_infiles; i++)
4237 register struct compiler *cp = 0;
4238 int this_file_error = 0;
4240 /* Tell do_spec what to substitute for %i. */
4242 input_filename = infiles[i].name;
4243 input_filename_length = strlen (input_filename);
4244 input_file_number = i;
4246 /* Use the same thing in %o, unless cp->spec says otherwise. */
4248 outfiles[i] = input_filename;
4250 /* Figure out which compiler from the file's suffix. */
4252 cp = lookup_compiler (infiles[i].name, input_filename_length,
4253 infiles[i].language);
4257 /* Ok, we found an applicable compiler. Run its spec. */
4258 /* First say how much of input_filename to substitute for %b */
4262 input_basename = input_filename;
4263 for (p = input_filename; *p; p++)
4264 if (*p == '/' || *p == DIR_SEPARATOR)
4265 input_basename = p + 1;
4267 /* Find a suffix starting with the last period,
4268 and set basename_length to exclude that suffix. */
4269 basename_length = strlen (input_basename);
4270 p = input_basename + basename_length;
4271 while (p != input_basename && *p != '.') --p;
4272 if (*p == '.' && p != input_basename)
4274 basename_length = p - input_basename;
4275 input_suffix = p + 1;
4281 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4283 len += strlen (cp->spec[j]);
4285 p = (char *) xmalloc (len + 1);
4288 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4291 strcpy (p + len, cp->spec[j]);
4292 len += strlen (cp->spec[j]);
4295 value = do_spec (p);
4298 this_file_error = 1;
4301 /* If this file's name does not contain a recognized suffix,
4302 record it as explicit linker input. */
4305 explicit_link_files[i] = 1;
4307 /* Clear the delete-on-failure queue, deleting the files in it
4308 if this compilation failed. */
4310 if (this_file_error)
4312 delete_failure_queue ();
4315 /* If this compilation succeeded, don't delete those files later. */
4316 clear_failure_queue ();
4319 /* Run ld to link all the compiler output files. */
4321 if (error_count == 0)
4323 int tmp = execution_count;
4327 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4329 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4330 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4332 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4334 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4335 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4338 for (i = 0; i < n_switches; i++)
4342 obstack_grow (&collect_obstack, " ", 1);
4345 obstack_grow (&collect_obstack, "-", 1);
4346 obstack_grow (&collect_obstack, switches[i].part1,
4347 strlen (switches[i].part1));
4349 for (args = switches[i].args; args && *args; args++)
4351 obstack_grow (&collect_obstack, " ", 1);
4352 obstack_grow (&collect_obstack, *args, strlen (*args));
4355 obstack_grow (&collect_obstack, "\0", 1);
4356 putenv (obstack_finish (&collect_obstack));
4358 value = do_spec (link_command_spec);
4361 linker_was_run = (tmp != execution_count);
4364 /* Warn if a -B option was specified but the prefix was never used. */
4365 unused_prefix_warnings (&exec_prefixes);
4366 unused_prefix_warnings (&startfile_prefixes);
4368 /* If options said don't run linker,
4369 complain about input files to be given to the linker. */
4371 if (! linker_was_run && error_count == 0)
4372 for (i = 0; i < n_infiles; i++)
4373 if (explicit_link_files[i])
4374 error ("%s: linker input file unused since linking not done",
4377 /* Delete some or all of the temporary files we made. */
4380 delete_failure_queue ();
4381 delete_temp_files ();
4383 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4388 /* Find the proper compilation spec for the file name NAME,
4389 whose length is LENGTH. LANGUAGE is the specified language,
4390 or 0 if none specified. */
4392 static struct compiler *
4393 lookup_compiler (name, length, language)
4398 struct compiler *cp;
4400 /* Look for the language, if one is spec'd. */
4403 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4407 if (cp->suffix[0] == '@'
4408 && !strcmp (cp->suffix + 1, language))
4412 error ("language %s not recognized", language);
4415 /* Look for a suffix. */
4416 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4418 if (/* The suffix `-' matches only the file name `-'. */
4419 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4421 (strlen (cp->suffix) < length
4422 /* See if the suffix matches the end of NAME. */
4424 && (!strcmp (cp->suffix,
4425 name + length - strlen (cp->suffix))
4426 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4427 && !strcasecmp (cp->suffix,
4428 name + length - strlen (cp->suffix)))))
4430 && !strcmp (cp->suffix,
4431 name + length - strlen (cp->suffix))))
4434 if (cp->spec[0][0] == '@')
4436 struct compiler *new;
4437 /* An alias entry maps a suffix to a language.
4438 Search for the language; pass 0 for NAME and LENGTH
4439 to avoid infinite recursion if language not found.
4440 Construct the new compiler spec. */
4441 language = cp->spec[0] + 1;
4442 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4443 new->suffix = cp->suffix;
4444 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4445 (char *) new->spec, sizeof new->spec);
4448 /* A non-alias entry: return it. */
4460 register char *value = (char *) malloc (size);
4462 fatal ("virtual memory exhausted");
4467 xrealloc (ptr, size)
4471 register char *value = (char *) realloc (ptr, size);
4473 fatal ("virtual memory exhausted");
4477 /* This function is based on the one in libiberty. */
4480 concat VPROTO((char *first, ...))
4482 register int length;
4483 register char *newstr;
4491 /* First compute the size of the result and get sufficient memory. */
4493 VA_START (args, first);
4495 first = va_arg (args, char *);
4503 length += strlen (arg);
4504 arg = va_arg (args, char *);
4507 newstr = (char *) xmalloc (length + 1);
4510 /* Now copy the individual pieces to the result string. */
4512 VA_START (args, first);
4514 first = va_arg (args, char *);
4523 arg = va_arg (args, char *);
4532 save_string (s, len)
4536 register char *result = xmalloc (len + 1);
4538 bcopy (s, result, len);
4544 pfatal_with_name (name)
4547 fatal ("%s: %s", name, my_strerror (errno));
4551 perror_with_name (name)
4554 error ("%s: %s", name, my_strerror (errno));
4558 pfatal_pexecute (errmsg_fmt, errmsg_arg)
4564 /* Space for trailing '\0' is in %s. */
4565 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
4566 sprintf (msg, errmsg_fmt, errmsg_arg);
4570 fatal ("%s: %s", errmsg_fmt, my_strerror (errno));
4573 /* More 'friendly' abort that prints the line and file.
4574 config.h can #define abort fancy_abort if you like that sort of thing. */
4579 fatal ("Internal gcc abort.");
4584 /* Output an error message and exit */
4587 fatal VPROTO((char *format, ...))
4594 VA_START (ap, format);
4597 format = va_arg (ap, char*);
4600 fprintf (stderr, "%s: ", programname);
4601 vfprintf (stderr, format, ap);
4603 fprintf (stderr, "\n");
4604 delete_temp_files ();
4609 error VPROTO((char *format, ...))
4616 VA_START (ap, format);
4619 format = va_arg (ap, char*);
4622 fprintf (stderr, "%s: ", programname);
4623 vfprintf (stderr, format, ap);
4626 fprintf (stderr, "\n");
4629 #else /* not HAVE_VPRINTF */
4632 fatal (msg, arg1, arg2)
4633 char *msg, *arg1, *arg2;
4635 error (msg, arg1, arg2);
4636 delete_temp_files ();
4641 error (msg, arg1, arg2)
4642 char *msg, *arg1, *arg2;
4644 fprintf (stderr, "%s: ", programname);
4645 fprintf (stderr, msg, arg1, arg2);
4646 fprintf (stderr, "\n");
4649 #endif /* not HAVE_VPRINTF */
4653 validate_all_switches ()
4655 struct compiler *comp;
4658 struct spec_list *spec;
4660 for (comp = compilers; comp->spec[0]; comp++)
4663 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
4667 if (c == '%' && *p == '{')
4668 /* We have a switch spec. */
4669 validate_switches (p + 1);
4673 /* look through the linked list of extra specs read from the specs file */
4674 for (spec = specs; spec ; spec = spec->next)
4678 if (c == '%' && *p == '{')
4679 /* We have a switch spec. */
4680 validate_switches (p + 1);
4683 p = link_command_spec;
4685 if (c == '%' && *p == '{')
4686 /* We have a switch spec. */
4687 validate_switches (p + 1);
4689 /* Now notice switches mentioned in the machine-specific specs. */
4693 if (c == '%' && *p == '{')
4694 /* We have a switch spec. */
4695 validate_switches (p + 1);
4699 if (c == '%' && *p == '{')
4700 /* We have a switch spec. */
4701 validate_switches (p + 1);
4705 if (c == '%' && *p == '{')
4706 /* We have a switch spec. */
4707 validate_switches (p + 1);
4709 p = signed_char_spec;
4711 if (c == '%' && *p == '{')
4712 /* We have a switch spec. */
4713 validate_switches (p + 1);
4717 if (c == '%' && *p == '{')
4718 /* We have a switch spec. */
4719 validate_switches (p + 1);
4723 if (c == '%' && *p == '{')
4724 /* We have a switch spec. */
4725 validate_switches (p + 1);
4729 if (c == '%' && *p == '{')
4730 /* We have a switch spec. */
4731 validate_switches (p + 1);
4735 if (c == '%' && *p == '{')
4736 /* We have a switch spec. */
4737 validate_switches (p + 1);
4741 if (c == '%' && *p == '{')
4742 /* We have a switch spec. */
4743 validate_switches (p + 1);
4747 if (c == '%' && *p == '{')
4748 /* We have a switch spec. */
4749 validate_switches (p + 1);
4754 for (i = 0; i < sizeof (extra_specs) / sizeof (extra_specs[0]); i++)
4756 p = extra_specs[i].spec;
4758 if (c == '%' && *p == '{')
4759 /* We have a switch spec. */
4760 validate_switches (p + 1);
4767 /* Look at the switch-name that comes after START
4768 and mark as valid all supplied switches that match it. */
4771 validate_switches (start)
4774 register char *p = start;
4789 while (*p != ':' && *p != '}') p++;
4793 else if (p[-1] == '*')
4795 /* Mark all matching switches as valid. */
4797 for (i = 0; i < n_switches; i++)
4798 if (!strncmp (switches[i].part1, filter, p - filter))
4799 switches[i].valid = 1;
4803 /* Mark an exact matching switch as valid. */
4804 for (i = 0; i < n_switches; i++)
4806 if (!strncmp (switches[i].part1, filter, p - filter)
4807 && switches[i].part1[p - filter] == 0)
4808 switches[i].valid = 1;
4813 /* Check whether a particular argument was used. */
4822 for (i = 0; i < n_switches; i++)
4823 if (! strncmp (switches[i].part1, p, len)
4824 && strlen (switches[i].part1) == len)
4829 /* Check whether a particular argument is a default argument. */
4831 #ifndef MULTILIB_DEFAULTS
4832 #define MULTILIB_DEFAULTS { NULL }
4835 static char *multilib_defaults[] = MULTILIB_DEFAULTS;
4838 default_arg (p, len)
4842 int count = sizeof multilib_defaults / sizeof multilib_defaults[0];
4845 for (i = 0; i < count; i++)
4846 if (multilib_defaults[i] != NULL
4847 && strncmp (multilib_defaults[i], p, len) == 0
4848 && multilib_defaults[i][len] == '\0')
4854 /* Work out the subdirectory to use based on the
4855 options. The format of multilib_select is a list of elements.
4856 Each element is a subdirectory name followed by a list of options
4857 followed by a semicolon. gcc will consider each line in turn. If
4858 none of the options beginning with an exclamation point are
4859 present, and all of the other options are present, that
4860 subdirectory will be used. */
4865 char *p = multilib_select;
4867 char *this_path, *this_arg;
4873 /* Ignore newlines. */
4880 /* Get the initial path. */
4888 this_path_len = p - this_path;
4890 /* Check the arguments. */
4905 while (*p != ' ' && *p != ';')
4912 if (*this_arg != '!')
4920 /* If this is a default argument, we can just ignore it.
4921 This is true even if this_arg begins with '!'. Beginning
4922 with '!' does not mean that this argument is necessarily
4923 inappropriate for this library: it merely means that
4924 there is a more specific library which uses this
4925 argument. If this argument is a default, we need not
4926 consider that more specific library. */
4927 if (! default_arg (this_arg, p - this_arg))
4929 ok = used_arg (this_arg, p - this_arg);
4940 if (this_path_len != 1
4941 || this_path[0] != '.')
4943 multilib_dir = xmalloc (this_path_len + 1);
4944 strncpy (multilib_dir, this_path, this_path_len);
4945 multilib_dir[this_path_len] = '\0';
4954 /* Print out the multiple library subdirectory selection
4955 information. This prints out a series of lines. Each line looks
4956 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
4957 required. Only the desired options are printed out, the negative
4958 matches. The options are print without a leading dash. There are
4959 no spaces to make it easy to use the information in the shell.
4960 Each subdirectory is printed only once. This assumes the ordering
4961 generated by the genmultilib script. */
4964 print_multilib_info ()
4966 char *p = multilib_select;
4967 char *last_path = 0, *this_path;
4969 int last_path_len = 0;
4973 /* Ignore newlines. */
4980 /* Get the initial path. */
4989 /* If this is a duplicate, skip it. */
4990 skip = (last_path != 0 && p - this_path == last_path_len
4991 && ! strncmp (last_path, this_path, last_path_len));
4993 last_path = this_path;
4994 last_path_len = p - this_path;
4996 /* If this directory requires any default arguments, we can skip
4997 it. We will already have printed a directory identical to
4998 this one which does not require that default argument. */
5016 while (*q != ' ' && *q != ';')
5024 && default_arg (arg, q - arg))
5039 for (p1 = last_path; p1 < p; p1++)
5058 use_arg = *p != '!';
5063 while (*p != ' ' && *p != ';')