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)
85 #define exit __posix_exit
88 /* Define O_RDONLY if the system hasn't defined it for us. */
97 /* Test if something is a normal file. */
99 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
102 /* Test if something is a directory. */
104 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
107 /* By default there is no special suffix for executables. */
108 #ifdef EXECUTABLE_SUFFIX
109 #define HAVE_EXECUTABLE_SUFFIX
111 #define EXECUTABLE_SUFFIX ""
114 /* By default, the suffix for object files is ".o". */
116 #define HAVE_OBJECT_SUFFIX
118 #define OBJECT_SUFFIX ".o"
121 /* By default, colon separates directories in a path. */
122 #ifndef PATH_SEPARATOR
123 #define PATH_SEPARATOR ':'
126 #ifndef DIR_SEPARATOR
127 #define DIR_SEPARATOR '/'
130 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
132 #define obstack_chunk_alloc xmalloc
133 #define obstack_chunk_free free
136 extern char *getenv ();
138 extern char *choose_temp_base PROTO((void));
144 #ifndef HAVE_STRERROR
147 extern const char *const sys_errlist[];
149 extern char *sys_errlist[];
152 extern char *strerror();
155 /* If a stage of compilation returns an exit status >= 1,
156 compilation of that file ceases. */
158 #define MIN_FATAL_STATUS 1
160 /* Flag saying to print the directories gcc will search through looking for
161 programs, libraries, etc. */
163 static int print_search_dirs;
165 /* Flag saying to print the full filename of this file
166 as found through our usual search mechanism. */
168 static char *print_file_name = NULL;
170 /* As print_file_name, but search for executable file. */
172 static char *print_prog_name = NULL;
174 /* Flag saying to print the relative path we'd use to
175 find libgcc.a given the current compiler flags. */
177 static int print_multi_directory;
179 /* Flag saying to print the list of subdirectories and
180 compiler flags used to select them in a standard form. */
182 static int print_multi_lib;
184 /* Flag indicating whether we should print the command and arguments */
186 static int verbose_flag;
188 /* Nonzero means write "temp" files in source directory
189 and use the source file's name in them, and don't delete them. */
191 static int save_temps_flag;
193 /* The compiler version. */
195 static char *compiler_version;
197 /* The target version specified with -V */
199 static char *spec_version = DEFAULT_TARGET_VERSION;
201 /* The target machine specified with -b. */
203 static char *spec_machine = DEFAULT_TARGET_MACHINE;
205 /* Nonzero if cross-compiling.
206 When -b is used, the value comes from the `specs' file. */
209 static int cross_compile = 1;
211 static int cross_compile = 0;
214 /* The number of errors that have occurred; the link phase will not be
215 run if this is non-zero. */
216 static int error_count = 0;
218 /* This is the obstack which we use to allocate many strings. */
220 static struct obstack obstack;
222 /* This is the obstack to build an environment variable to pass to
223 collect2 that describes all of the relevant switches of what to
224 pass the compiler in building the list of pointers to constructors
227 static struct obstack collect_obstack;
229 extern char *version_string;
231 /* Forward declaration for prototypes. */
234 static void set_spec PROTO((char *, char *));
235 static struct compiler *lookup_compiler PROTO((char *, int, char *));
236 static char *build_search_list PROTO((struct path_prefix *, char *, int));
237 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
238 static char *find_a_file PROTO((struct path_prefix *, char *, int));
239 static void add_prefix PROTO((struct path_prefix *, char *, int, int, int *));
240 static char *skip_whitespace PROTO((char *));
241 static void record_temp_file PROTO((char *, int, int));
242 static void delete_if_ordinary PROTO((char *));
243 static void delete_temp_files PROTO((void));
244 static void delete_failure_queue PROTO((void));
245 static void clear_failure_queue PROTO((void));
246 static int check_live_switch PROTO((int, int));
247 static char *handle_braces PROTO((char *));
248 static char *save_string PROTO((char *, int));
249 static char *concat PVPROTO((char *, ...));
250 static int do_spec PROTO((char *));
251 static int do_spec_1 PROTO((char *, int, char *));
252 static char *find_file PROTO((char *));
253 static int is_directory PROTO((char *, char *, int));
254 static void validate_switches PROTO((char *));
255 static void validate_all_switches PROTO((void));
256 static void give_switch PROTO((int, int));
257 static int used_arg PROTO((char *, int));
258 static int default_arg PROTO((char *, int));
259 static void set_multilib_dir PROTO((void));
260 static void print_multilib_info PROTO((void));
261 static void pfatal_with_name PROTO((char *));
262 static void perror_with_name PROTO((char *));
263 static void pfatal_pexecute PROTO((char *, char *));
265 static void fatal PVPROTO((char *, ...));
266 static void error PVPROTO((char *, ...));
268 /* We must not provide any prototype here, even if ANSI C. */
269 static void fatal PROTO(());
270 static void error PROTO(());
277 /* Specs are strings containing lines, each of which (if not blank)
278 is made up of a program name, and arguments separated by spaces.
279 The program name must be exact and start from root, since no path
280 is searched and it is unreliable to depend on the current working directory.
281 Redirection of input or output is not supported; the subprograms must
282 accept filenames saying what files to read and write.
284 In addition, the specs can contain %-sequences to substitute variable text
285 or for conditional text. Here is a table of all defined %-sequences.
286 Note that spaces are not generated automatically around the results of
287 expanding these sequences; therefore, you can concatenate them together
288 or with constant text in a single argument.
290 %% substitute one % into the program name or argument.
291 %i substitute the name of the input file being processed.
292 %b substitute the basename of the input file being processed.
293 This is the substring up to (and not including) the last period
294 and not including the directory.
295 %g substitute the temporary-file-name-base. This is a string chosen
296 once per compilation. Different temporary file names are made by
297 concatenation of constant strings on the end, as in `%g.s'.
298 %g also has the same effect of %d.
299 %u like %g, but make the temporary file name unique.
300 %U returns the last file name generated with %u.
301 %d marks the argument containing or following the %d as a
302 temporary file name, so that that file will be deleted if CC exits
303 successfully. Unlike %g, this contributes no text to the argument.
304 %w marks the argument containing or following the %w as the
305 "output file" of this compilation. This puts the argument
306 into the sequence of arguments that %o will substitute later.
308 like %{...} but mark last argument supplied within
309 as a file to be deleted on failure.
310 %o substitutes the names of all the output files, with spaces
311 automatically placed around them. You should write spaces
312 around the %o as well or the results are undefined.
313 %o is for use in the specs for running the linker.
314 Input files whose names have no recognized suffix are not compiled
315 at all, but they are included among the output files, so they will
317 %O substitutes the suffix for object files.
318 %p substitutes the standard macro predefinitions for the
319 current target machine. Use this when running cpp.
320 %P like %p, but puts `__' before and after the name of each macro.
321 (Except macros that already have __.)
323 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
324 %s current argument is the name of a library or startup file of some sort.
325 Search for that file in a standard list of directories
326 and substitute the full name found.
327 %eSTR Print STR as an error message. STR is terminated by a newline.
328 Use this when inconsistent options are detected.
329 %x{OPTION} Accumulate an option for %X.
330 %X Output the accumulated linker options specified by compilations.
331 %Y Output the accumulated assembler options specified by compilations.
332 %Z Output the accumulated preprocessor options specified by compilations.
333 %v1 Substitute the major version number of GCC.
334 (For version 2.5.n, this is 2.)
335 %v2 Substitute the minor version number of GCC.
336 (For version 2.5.n, this is 5.)
337 %a process ASM_SPEC as a spec.
338 This allows config.h to specify part of the spec for running as.
339 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
340 used here. This can be used to run a post-processor after the
341 assembler has done it's job.
342 %D Dump out a -L option for each directory in startfile_prefixes.
343 If multilib_dir is set, extra entries are generated with it affixed.
344 %l process LINK_SPEC as a spec.
345 %L process LIB_SPEC as a spec.
346 %G process LIBGCC_SPEC as a spec.
347 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
348 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
349 %c process SIGNED_CHAR_SPEC as a spec.
350 %C process CPP_SPEC as a spec. A capital C is actually used here.
351 %1 process CC1_SPEC as a spec.
352 %2 process CC1PLUS_SPEC as a spec.
353 %| output "-" if the input for the current command is coming from a pipe.
354 %* substitute the variable part of a matched option. (See below.)
355 Note that each comma in the substituted string is replaced by
357 %{S} substitutes the -S switch, if that switch was given to CC.
358 If that switch was not specified, this substitutes nothing.
359 Here S is a metasyntactic variable.
360 %{S*} substitutes all the switches specified to CC whose names start
361 with -S. This is used for -o, -D, -I, etc; switches that take
362 arguments. CC considers `-o foo' as being one switch whose
363 name starts with `o'. %{o*} would substitute this text,
364 including the space; thus, two arguments would be generated.
365 %{S*:X} substitutes X if one or more switches whose names start with -S are
366 specified to CC. Note that the tail part of the -S option
367 (i.e. the part matched by the `*') will be substituted for each
368 occurrence of %* within X.
369 %{S:X} substitutes X, but only if the -S switch was given to CC.
370 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
371 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
372 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
373 %{.S:X} substitutes X, but only if processing a file with suffix S.
374 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
375 %(Spec) processes a specification defined in a specs file as *Spec:
376 %[Spec] as above, but put __ around -D arguments
378 The conditional text X in a %{S:X} or %{!S:X} construct may contain
379 other nested % constructs or spaces, or even newlines. They are
380 processed as usual, as described above.
382 The -O, -f, -m, and -W switches are handled specifically in these
383 constructs. If another value of -O or the negated form of a -f, -m, or
384 -W switch is found later in the command line, the earlier switch
385 value is ignored, except with {S*} where S is just one letter; this
386 passes all matching options.
388 The character | is used to indicate that a command should be piped to
389 the following command, but only if -pipe is specified.
391 Note that it is built into CC which switches take arguments and which
392 do not. You might think it would be useful to generalize this to
393 allow each compiler's spec to say which switches take arguments. But
394 this cannot be done in a consistent fashion. CC cannot even decide
395 which input files have been specified without knowing which switches
396 take arguments, and it must know which input files to compile in order
397 to tell which compilers to run.
399 CC also knows implicitly that arguments starting in `-l' are to be
400 treated as compiler output files, and passed to the linker in their
401 proper position among the other output files. */
403 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
405 /* config.h can define ASM_SPEC to provide extra args to the assembler
406 or extra switch-translations. */
411 /* config.h can define ASM_FINAL_SPEC to run a post processor after
412 the assembler has run. */
413 #ifndef ASM_FINAL_SPEC
414 #define ASM_FINAL_SPEC ""
417 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
418 or extra switch-translations. */
423 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
424 or extra switch-translations. */
429 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
430 or extra switch-translations. */
432 #define CC1PLUS_SPEC ""
435 /* config.h can define LINK_SPEC to provide extra args to the linker
436 or extra switch-translations. */
441 /* config.h can define LIB_SPEC to override the default libraries. */
443 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
446 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
449 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
450 /* Have gcc do the search for libgcc.a. */
451 #define LIBGCC_SPEC "libgcc.a%s"
453 #define LIBGCC_SPEC "-lgcc"
457 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
458 #ifndef STARTFILE_SPEC
459 #define STARTFILE_SPEC \
460 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
463 /* config.h can define SWITCHES_NEED_SPACES to control which options
464 require spaces between the option and the argument. */
465 #ifndef SWITCHES_NEED_SPACES
466 #define SWITCHES_NEED_SPACES ""
469 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
471 #define ENDFILE_SPEC ""
474 /* This spec is used for telling cpp whether char is signed or not. */
475 #ifndef SIGNED_CHAR_SPEC
476 /* Use #if rather than ?:
477 because MIPS C compiler rejects like ?: in initializers. */
478 #if DEFAULT_SIGNED_CHAR
479 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
481 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
485 static char *cpp_spec = CPP_SPEC;
486 static char *cpp_predefines = CPP_PREDEFINES;
487 static char *cc1_spec = CC1_SPEC;
488 static char *cc1plus_spec = CC1PLUS_SPEC;
489 static char *signed_char_spec = SIGNED_CHAR_SPEC;
490 static char *asm_spec = ASM_SPEC;
491 static char *asm_final_spec = ASM_FINAL_SPEC;
492 static char *link_spec = LINK_SPEC;
493 static char *lib_spec = LIB_SPEC;
494 static char *libgcc_spec = LIBGCC_SPEC;
495 static char *endfile_spec = ENDFILE_SPEC;
496 static char *startfile_spec = STARTFILE_SPEC;
497 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
499 /* Some compilers have limits on line lengths, and the multilib_select
500 and/or multilib_matches strings can be very long, so we build them at
502 static struct obstack multilib_obstack;
503 static char *multilib_select;
504 static char *multilib_matches;
505 static char *multilib_defaults;
506 #include "multilib.h"
508 /* Check whether a particular argument is a default argument. */
510 #ifndef MULTILIB_DEFAULTS
511 #define MULTILIB_DEFAULTS { "" }
514 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
517 static struct { char *name, *spec; } extra_specs[] = { EXTRA_SPECS };
521 struct user_specs *next;
525 static struct user_specs *user_specs_head, *user_specs_tail;
527 /* This defines which switch letters take arguments. */
529 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
530 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
531 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
532 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
533 || (CHAR) == 'L' || (CHAR) == 'A')
535 #ifndef SWITCH_TAKES_ARG
536 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
539 /* This defines which multi-letter switches take arguments. */
541 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
542 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
543 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
544 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
545 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
546 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
547 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
549 #ifndef WORD_SWITCH_TAKES_ARG
550 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
553 /* Record the mapping from file suffixes for compilation specs. */
557 char *suffix; /* Use this compiler for input files
558 whose names end in this suffix. */
560 char *spec[4]; /* To use this compiler, concatenate these
561 specs and pass to do_spec. */
564 /* Pointer to a vector of `struct compiler' that gives the spec for
565 compiling a file, based on its suffix.
566 A file that does not end in any of these suffixes will be passed
567 unchanged to the loader and nothing else will be done to it.
569 An entry containing two 0s is used to terminate the vector.
571 If multiple entries match a file, the last matching one is used. */
573 static struct compiler *compilers;
575 /* Number of entries in `compilers', not counting the null terminator. */
577 static int n_compilers;
579 /* The default list of file name suffixes and their compilation specs. */
581 static struct compiler default_compilers[] =
583 /* Add lists of suffixes of known languages here. If those languages
584 were no present when we built the driver, we will hit these copies
585 and given a more meaningful error than "file not used since
586 linking is not done". */
587 {".cc", "#C++"}, {".cxx", "#C++"}, {".cpp", "#C++"}, {".c++", "#C++"},
588 {".C", "#C++"}, {".ads", "#Ada"}, {".adb", "#Ada"}, {".ada", "#Ada"},
589 {".f", "#Fortran"}, {".for", "#Fortran"}, {".F", "#Fortran"},
590 {".fpp", "#Fortran"},
591 /* Next come the entries for C. */
594 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
595 %{C:%{!E:%eGNU C does not support -C without using -E}}\
596 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
597 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
598 %{ansi:-trigraphs -D__STRICT_ANSI__}\
599 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
600 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
601 %{traditional-cpp:-traditional}\
602 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
603 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
604 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
605 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
606 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
607 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
609 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
610 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
612 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
613 %{!pipe:%g.s} %A\n }}}}"},
615 "%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
616 %{C:%{!E:%eGNU C does not support -C without using -E}}\
617 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
618 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
619 %{ansi:-trigraphs -D__STRICT_ANSI__}\
620 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
621 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
622 %{traditional-cpp:-traditional}\
623 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
625 %{!E:%e-E required when input is from standard input}"},
626 {".m", "@objective-c"},
628 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
629 %{C:%{!E:%eGNU C does not support -C without using -E}}\
630 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
631 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
632 %{ansi:-trigraphs -D__STRICT_ANSI__}\
633 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
634 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
635 %{traditional-cpp:-traditional}\
636 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
637 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
638 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
639 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
640 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
641 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
642 -lang-objc %{gen-decls} \
644 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
645 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
647 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
648 %{!pipe:%g.s} %A\n }}}}"},
651 "%{!E:%eCompilation of header file requested} \
652 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
653 %{C:%{!E:%eGNU C does not support -C without using -E}}\
654 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
655 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
656 %{ansi:-trigraphs -D__STRICT_ANSI__}\
657 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
658 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
659 %{traditional-cpp:-traditional}\
660 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
662 {".i", "@cpp-output"},
664 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
665 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
666 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
668 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
669 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
671 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
672 %{!pipe:%g.s} %A\n }}}}"},
673 {".s", "@assembler"},
675 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
676 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
678 {".S", "@assembler-with-cpp"},
679 {"@assembler-with-cpp",
680 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
681 %{C:%{!E:%eGNU C does not support -C without using -E}}\
682 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
683 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
684 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
685 %{traditional-cpp:-traditional}\
686 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
687 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
688 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
689 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
690 %{!pipe:%g.s} %A\n }}}}"},
692 /* Mark end of table */
696 /* Number of elements in default_compilers, not counting the terminator. */
698 static int n_default_compilers
699 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
701 /* Here is the spec for running the linker, after compiling all files. */
703 /* -u* was put back because both BSD and SysV seem to support it. */
704 /* %{static:} simply prevents an error message if the target machine
705 doesn't handle -static. */
706 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
707 scripts which exist in user specified directories, or in standard
709 #ifdef LINK_LIBGCC_SPECIAL
710 /* Don't generate -L options. */
711 static char *link_command_spec = "\
713 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
714 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
715 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
717 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
718 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
723 static char *link_command_spec = "\
725 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
726 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
727 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
728 %{static:} %{L*} %D %o\
729 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
730 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
735 /* A vector of options to give to the linker.
736 These options are accumulated by %x,
737 and substituted into the linker command with %X. */
738 static int n_linker_options;
739 static char **linker_options;
741 /* A vector of options to give to the assembler.
742 These options are accumulated by -Wa,
743 and substituted into the assembler command with %Y. */
744 static int n_assembler_options;
745 static char **assembler_options;
747 /* A vector of options to give to the preprocessor.
748 These options are accumulated by -Wp,
749 and substituted into the preprocessor command with %Z. */
750 static int n_preprocessor_options;
751 static char **preprocessor_options;
753 /* Define how to map long options into short ones. */
755 /* This structure describes one mapping. */
758 /* The long option's name. */
760 /* The equivalent short option. */
762 /* Argument info. A string of flag chars; NULL equals no options.
763 a => argument required.
764 o => argument optional.
765 j => join argument to equivalent, making one word.
766 * => require other text after NAME as an argument. */
770 /* This is the table of mappings. Mappings are tried sequentially
771 for each option encountered; the first one that matches, wins. */
773 struct option_map option_map[] =
775 {"--all-warnings", "-Wall", 0},
776 {"--ansi", "-ansi", 0},
777 {"--assemble", "-S", 0},
778 {"--assert", "-A", "a"},
779 {"--comments", "-C", 0},
780 {"--compile", "-c", 0},
781 {"--debug", "-g", "oj"},
782 {"--define-macro", "-D", "aj"},
783 {"--dependencies", "-M", 0},
784 {"--dump", "-d", "a"},
785 {"--dumpbase", "-dumpbase", "a"},
786 {"--entry", "-e", 0},
787 {"--extra-warnings", "-W", 0},
788 {"--for-assembler", "-Wa", "a"},
789 {"--for-linker", "-Xlinker", "a"},
790 {"--force-link", "-u", "a"},
791 {"--imacros", "-imacros", "a"},
792 {"--include", "-include", "a"},
793 {"--include-barrier", "-I-", 0},
794 {"--include-directory", "-I", "aj"},
795 {"--include-directory-after", "-idirafter", "a"},
796 {"--include-prefix", "-iprefix", "a"},
797 {"--include-with-prefix", "-iwithprefix", "a"},
798 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
799 {"--include-with-prefix-after", "-iwithprefix", "a"},
800 {"--language", "-x", "a"},
801 {"--library-directory", "-L", "a"},
802 {"--machine", "-m", "aj"},
803 {"--machine-", "-m", "*j"},
804 {"--no-line-commands", "-P", 0},
805 {"--no-precompiled-includes", "-noprecomp", 0},
806 {"--no-standard-includes", "-nostdinc", 0},
807 {"--no-standard-libraries", "-nostdlib", 0},
808 {"--no-warnings", "-w", 0},
809 {"--optimize", "-O", "oj"},
810 {"--output", "-o", "a"},
811 {"--pedantic", "-pedantic", 0},
812 {"--pedantic-errors", "-pedantic-errors", 0},
813 {"--pipe", "-pipe", 0},
814 {"--prefix", "-B", "a"},
815 {"--preprocess", "-E", 0},
816 {"--print-search-dirs", "-print-search-dirs", 0},
817 {"--print-file-name", "-print-file-name=", "aj"},
818 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
819 {"--print-missing-file-dependencies", "-MG", 0},
820 {"--print-multi-lib", "-print-multi-lib", 0},
821 {"--print-multi-directory", "-print-multi-directory", 0},
822 {"--print-prog-name", "-print-prog-name=", "aj"},
823 {"--profile", "-p", 0},
824 {"--profile-blocks", "-a", 0},
825 {"--quiet", "-q", 0},
826 {"--save-temps", "-save-temps", 0},
827 {"--shared", "-shared", 0},
828 {"--silent", "-q", 0},
829 {"--specs", "-specs=", "aj"},
830 {"--static", "-static", 0},
831 {"--symbolic", "-symbolic", 0},
832 {"--target", "-b", "a"},
833 {"--trace-includes", "-H", 0},
834 {"--traditional", "-traditional", 0},
835 {"--traditional-cpp", "-traditional-cpp", 0},
836 {"--trigraphs", "-trigraphs", 0},
837 {"--undefine-macro", "-U", "aj"},
838 {"--use-version", "-V", "a"},
839 {"--user-dependencies", "-MM", 0},
840 {"--verbose", "-v", 0},
841 {"--version", "-dumpversion", 0},
842 {"--warn-", "-W", "*j"},
843 {"--write-dependencies", "-MD", 0},
844 {"--write-user-dependencies", "-MMD", 0},
848 /* Translate the options described by *ARGCP and *ARGVP.
849 Make a new vector and store it back in *ARGVP,
850 and store its length in *ARGVC. */
853 translate_options (argcp, argvp)
859 char **argv = *argvp;
860 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
864 newv[newindex++] = argv[i++];
868 /* Translate -- options. */
869 if (argv[i][0] == '-' && argv[i][1] == '-')
871 /* Find a mapping that applies to this option. */
872 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
874 int optlen = strlen (option_map[j].name);
875 int arglen = strlen (argv[i]);
876 int complen = arglen > optlen ? optlen : arglen;
877 char *arginfo = option_map[j].arg_info;
882 if (!strncmp (argv[i], option_map[j].name, complen))
889 k < sizeof (option_map) / sizeof (option_map[0]);
891 if (strlen (option_map[k].name) >= arglen
892 && !strncmp (argv[i], option_map[k].name, arglen))
894 error ("Ambiguous abbreviation %s", argv[i]);
898 if (k != sizeof (option_map) / sizeof (option_map[0]))
904 /* If the option has an argument, accept that. */
905 if (argv[i][optlen] == '=')
906 arg = argv[i] + optlen + 1;
908 /* If this mapping requires extra text at end of name,
909 accept that as "argument". */
910 else if (index (arginfo, '*') != 0)
911 arg = argv[i] + optlen;
913 /* Otherwise, extra text at end means mismatch.
914 Try other mappings. */
919 else if (index (arginfo, '*') != 0)
921 error ("Incomplete `%s' option", option_map[j].name);
925 /* Handle arguments. */
926 if (index (arginfo, 'a') != 0)
932 error ("Missing argument to `%s' option",
940 else if (index (arginfo, '*') != 0)
942 else if (index (arginfo, 'o') == 0)
945 error ("Extraneous argument to `%s' option",
950 /* Store the translation as one argv elt or as two. */
951 if (arg != 0 && index (arginfo, 'j') != 0)
952 newv[newindex++] = concat (option_map[j].equivalent, arg,
956 newv[newindex++] = option_map[j].equivalent;
957 newv[newindex++] = arg;
960 newv[newindex++] = option_map[j].equivalent;
968 /* Handle old-fashioned options--just copy them through,
969 with their arguments. */
970 else if (argv[i][0] == '-')
972 char *p = argv[i] + 1;
976 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
977 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
978 else if (WORD_SWITCH_TAKES_ARG (p))
979 nskip += WORD_SWITCH_TAKES_ARG (p);
980 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
983 else if (! strcmp (p, "Xlinker"))
986 /* Watch out for an option at the end of the command line that
987 is missing arguments, and avoid skipping past the end of the
989 if (nskip + i > argc)
994 newv[newindex++] = argv[i++];
999 /* Ordinary operands, or +e options. */
1000 newv[newindex++] = argv[i++];
1013 #ifdef HAVE_STRERROR
1019 static char buffer[30];
1021 return "cannot access";
1023 if (e > 0 && e < sys_nerr)
1024 return sys_errlist[e];
1026 sprintf (buffer, "Unknown error %d", e);
1031 /* Read compilation specs from a file named FILENAME,
1032 replacing the default ones.
1034 A suffix which starts with `*' is a definition for
1035 one of the machine-specific sub-specs. The "suffix" should be
1036 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1037 The corresponding spec is stored in asm_spec, etc.,
1038 rather than in the `compilers' vector.
1040 Anything invalid in the file is a fatal error. */
1043 read_specs (filename)
1048 struct stat statbuf;
1053 fprintf (stderr, "Reading specs from %s\n", filename);
1055 /* Open and stat the file. */
1056 desc = open (filename, O_RDONLY, 0);
1058 pfatal_with_name (filename);
1059 if (stat (filename, &statbuf) < 0)
1060 pfatal_with_name (filename);
1062 /* Read contents of file into BUFFER. */
1063 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1064 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1066 pfatal_with_name (filename);
1067 buffer[readlen] = 0;
1070 /* Scan BUFFER for specs, putting them in the vector. */
1076 char *in, *out, *p1, *p2;
1078 /* Advance P in BUFFER to the next nonblank nocomment line. */
1079 p = skip_whitespace (p);
1083 /* Find the colon that should end the suffix. */
1085 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
1086 /* The colon shouldn't be missing. */
1088 fatal ("specs file malformed after %d characters", p1 - buffer);
1089 /* Skip back over trailing whitespace. */
1091 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
1092 /* Copy the suffix to a string. */
1093 suffix = save_string (p, p2 - p);
1094 /* Find the next line. */
1095 p = skip_whitespace (p1 + 1);
1097 fatal ("specs file malformed after %d characters", p - buffer);
1099 /* Find next blank line. */
1100 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
1101 /* Specs end at the blank line and do not include the newline. */
1102 spec = save_string (p, p1 - p);
1105 /* Delete backslash-newline sequences from the spec. */
1110 if (in[0] == '\\' && in[1] == '\n')
1112 else if (in[0] == '#')
1114 while (*in && *in != '\n') in++;
1121 if (suffix[0] == '*')
1123 if (! strcmp (suffix, "*link_command"))
1124 link_command_spec = spec;
1126 set_spec (suffix + 1, spec);
1130 /* Add this pair to the vector. */
1132 = ((struct compiler *)
1133 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
1134 compilers[n_compilers].suffix = suffix;
1135 bzero ((char *) compilers[n_compilers].spec,
1136 sizeof compilers[n_compilers].spec);
1137 compilers[n_compilers].spec[0] = spec;
1139 bzero ((char *) &compilers[n_compilers],
1140 sizeof compilers[n_compilers]);
1144 link_command_spec = spec;
1147 if (link_command_spec == 0)
1148 fatal ("spec file has no spec for linking");
1157 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1158 be considered whitespace. */
1159 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1161 else if (*p == '\n' || *p == ' ' || *p == '\t')
1165 while (*p != '\n') p++;
1175 /* Structure to keep track of the specs that have been defined so far.
1176 These are accessed using %(specname) or %[specname] in a compiler
1181 char *name; /* Name of the spec. */
1182 char *spec; /* The spec itself. */
1183 struct spec_list *next; /* Next spec in linked list. */
1186 /* List of specs that have been defined so far. */
1188 static struct spec_list *specs = (struct spec_list *) 0;
1190 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1191 removed; If the spec starts with a + then SPEC is added to the end of the
1195 set_spec (name, spec)
1199 struct spec_list *sl;
1202 /* See if the spec already exists */
1203 for (sl = specs; sl; sl = sl->next)
1204 if (strcmp (sl->name, name) == 0)
1209 /* Not found - make it */
1210 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1211 sl->name = save_string (name, strlen (name));
1212 sl->spec = save_string ("", 0);
1217 old_spec = sl->spec;
1218 if (name && spec[0] == '+' && isspace (spec[1]))
1219 sl->spec = concat (old_spec, spec + 1, NULL_PTR);
1221 sl->spec = save_string (spec, strlen (spec));
1223 if (! strcmp (name, "asm"))
1224 asm_spec = sl->spec;
1225 else if (! strcmp (name, "asm_final"))
1226 asm_final_spec = sl->spec;
1227 else if (! strcmp (name, "cc1"))
1228 cc1_spec = sl->spec;
1229 else if (! strcmp (name, "cc1plus"))
1230 cc1plus_spec = sl->spec;
1231 else if (! strcmp (name, "cpp"))
1232 cpp_spec = sl->spec;
1233 else if (! strcmp (name, "endfile"))
1234 endfile_spec = sl->spec;
1235 else if (! strcmp (name, "lib"))
1236 lib_spec = sl->spec;
1237 else if (! strcmp (name, "libgcc"))
1238 libgcc_spec = sl->spec;
1239 else if (! strcmp (name, "link"))
1240 link_spec = sl->spec;
1241 else if (! strcmp (name, "predefines"))
1242 cpp_predefines = sl->spec;
1243 else if (! strcmp (name, "signed_char"))
1244 signed_char_spec = sl->spec;
1245 else if (! strcmp (name, "startfile"))
1246 startfile_spec = sl->spec;
1247 else if (! strcmp (name, "switches_need_spaces"))
1248 switches_need_spaces = sl->spec;
1249 else if (! strcmp (name, "cross_compile"))
1250 cross_compile = atoi (sl->spec);
1251 else if (! strcmp (name, "multilib"))
1252 multilib_select = sl->spec;
1253 else if (! strcmp (name, "multilib_matches"))
1254 multilib_matches = sl->spec;
1255 else if (! strcmp (name, "multilib_extra"))
1256 multilib_extra = sl->spec;
1257 else if (! strcmp (name, "multilib_defaults"))
1258 multilib_defaults = sl->spec;
1259 else if (! strcmp (name, "version"))
1260 compiler_version = sl->spec;
1265 for (i = 0; i < sizeof (extra_specs) / sizeof (extra_specs[0]); i++)
1267 if (! strcmp (name, extra_specs[i].name))
1269 extra_specs[i].spec = sl->spec;
1276 /* Free the old spec */
1281 /* Accumulate a command (program name and args), and run it. */
1283 /* Vector of pointers to arguments in the current line of specifications. */
1285 static char **argbuf;
1287 /* Number of elements allocated in argbuf. */
1289 static int argbuf_length;
1291 /* Number of elements in argbuf currently in use (containing args). */
1293 static int argbuf_index;
1295 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1296 temp file. Used only if MKTEMP_EACH_FILE. */
1298 static struct temp_name {
1299 char *suffix; /* suffix associated with the code. */
1300 int length; /* strlen (suffix). */
1301 int unique; /* Indicates whether %g or %u/%U was used. */
1302 char *filename; /* associated filename. */
1303 int filename_length; /* strlen (filename). */
1304 struct temp_name *next;
1307 /* Number of commands executed so far. */
1309 static int execution_count;
1311 /* Number of commands that exited with a signal. */
1313 static int signal_count;
1315 /* Name with which this program was invoked. */
1317 static char *programname;
1319 /* Structures to keep track of prefixes to try when looking for files. */
1323 char *prefix; /* String to prepend to the path. */
1324 struct prefix_list *next; /* Next in linked list. */
1325 int require_machine_suffix; /* Don't use without machine_suffix. */
1326 /* 2 means try both machine_suffix and just_machine_suffix. */
1327 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1332 struct prefix_list *plist; /* List of prefixes to try */
1333 int max_len; /* Max length of a prefix in PLIST */
1334 char *name; /* Name of this list (used in config stuff) */
1337 /* List of prefixes to try when looking for executables. */
1339 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1341 /* List of prefixes to try when looking for startup (crt0) files. */
1343 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1345 /* List of prefixes to try when looking for include files. */
1347 static struct path_prefix include_prefixes = { 0, 0, "include" };
1349 /* Suffix to attach to directories searched for commands.
1350 This looks like `MACHINE/VERSION/'. */
1352 static char *machine_suffix = 0;
1354 /* Suffix to attach to directories searched for commands.
1355 This is just `MACHINE/'. */
1357 static char *just_machine_suffix = 0;
1359 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1361 static char *gcc_exec_prefix;
1363 /* Default prefixes to attach to command names. */
1365 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1366 #undef MD_EXEC_PREFIX
1367 #undef MD_STARTFILE_PREFIX
1368 #undef MD_STARTFILE_PREFIX_1
1371 #ifndef STANDARD_EXEC_PREFIX
1372 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1373 #endif /* !defined STANDARD_EXEC_PREFIX */
1375 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1376 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1377 #ifdef MD_EXEC_PREFIX
1378 static char *md_exec_prefix = MD_EXEC_PREFIX;
1381 #ifndef STANDARD_STARTFILE_PREFIX
1382 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1383 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1385 #ifdef MD_STARTFILE_PREFIX
1386 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1388 #ifdef MD_STARTFILE_PREFIX_1
1389 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1391 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1392 static char *standard_startfile_prefix_1 = "/lib/";
1393 static char *standard_startfile_prefix_2 = "/usr/lib/";
1395 #ifndef TOOLDIR_BASE_PREFIX
1396 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1398 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1399 static char *tooldir_prefix;
1401 /* Subdirectory to use for locating libraries. Set by
1402 set_multilib_dir based on the compilation options. */
1404 static char *multilib_dir;
1406 /* Clear out the vector of arguments (after a command is executed). */
1414 /* Add one argument to the vector at the end.
1415 This is done when a space is seen or at the end of the line.
1416 If DELETE_ALWAYS is nonzero, the arg is a filename
1417 and the file should be deleted eventually.
1418 If DELETE_FAILURE is nonzero, the arg is a filename
1419 and the file should be deleted if this compilation fails. */
1422 store_arg (arg, delete_always, delete_failure)
1424 int delete_always, delete_failure;
1426 if (argbuf_index + 1 == argbuf_length)
1428 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1431 argbuf[argbuf_index++] = arg;
1432 argbuf[argbuf_index] = 0;
1434 if (delete_always || delete_failure)
1435 record_temp_file (arg, delete_always, delete_failure);
1438 /* Record the names of temporary files we tell compilers to write,
1439 and delete them at the end of the run. */
1441 /* This is the common prefix we use to make temp file names.
1442 It is chosen once for each run of this program.
1443 It is substituted into a spec by %g.
1444 Thus, all temp file names contain this prefix.
1445 In practice, all temp file names start with this prefix.
1447 This prefix comes from the envvar TMPDIR if it is defined;
1448 otherwise, from the P_tmpdir macro if that is defined;
1449 otherwise, in /usr/tmp or /tmp;
1450 or finally the current directory if all else fails. */
1452 static char *temp_filename;
1454 /* Length of the prefix. */
1456 static int temp_filename_length;
1458 /* Define the list of temporary files to delete. */
1463 struct temp_file *next;
1466 /* Queue of files to delete on success or failure of compilation. */
1467 static struct temp_file *always_delete_queue;
1468 /* Queue of files to delete on failure of compilation. */
1469 static struct temp_file *failure_delete_queue;
1471 /* Record FILENAME as a file to be deleted automatically.
1472 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1473 otherwise delete it in any case.
1474 FAIL_DELETE nonzero means delete it if a compilation step fails;
1475 otherwise delete it in any case. */
1478 record_temp_file (filename, always_delete, fail_delete)
1483 register char *name;
1484 name = xmalloc (strlen (filename) + 1);
1485 strcpy (name, filename);
1489 register struct temp_file *temp;
1490 for (temp = always_delete_queue; temp; temp = temp->next)
1491 if (! strcmp (name, temp->name))
1493 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1494 temp->next = always_delete_queue;
1496 always_delete_queue = temp;
1502 register struct temp_file *temp;
1503 for (temp = failure_delete_queue; temp; temp = temp->next)
1504 if (! strcmp (name, temp->name))
1506 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1507 temp->next = failure_delete_queue;
1509 failure_delete_queue = temp;
1514 /* Delete all the temporary files whose names we previously recorded. */
1517 delete_if_ordinary (name)
1524 printf ("Delete %s? (y or n) ", name);
1528 while ((c = getchar ()) != '\n' && c != EOF) ;
1529 if (i == 'y' || i == 'Y')
1531 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1532 if (unlink (name) < 0)
1534 perror_with_name (name);
1538 delete_temp_files ()
1540 register struct temp_file *temp;
1542 for (temp = always_delete_queue; temp; temp = temp->next)
1543 delete_if_ordinary (temp->name);
1544 always_delete_queue = 0;
1547 /* Delete all the files to be deleted on error. */
1550 delete_failure_queue ()
1552 register struct temp_file *temp;
1554 for (temp = failure_delete_queue; temp; temp = temp->next)
1555 delete_if_ordinary (temp->name);
1559 clear_failure_queue ()
1561 failure_delete_queue = 0;
1564 /* Routine to add variables to the environment. We do this to pass
1565 the pathname of the gcc driver, and the directories search to the
1566 collect2 program, which is being run as ld. This way, we can be
1567 sure of executing the right compiler when collect2 wants to build
1568 constructors and destructors. Since the environment variables we
1569 use come from an obstack, we don't have to worry about allocating
1578 #ifndef VMS /* nor about VMS */
1580 extern char **environ;
1581 char **old_environ = environ;
1585 int str_len = strlen (str);
1589 while ((ch = *p++) != '\0' && ch != '=')
1595 /* Search for replacing an existing environment variable, and
1596 count the number of total environment variables. */
1597 for (envp = old_environ; *envp; envp++)
1600 if (!strncmp (str, *envp, name_len))
1607 /* Add a new environment variable */
1608 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1610 bcopy ((char *) old_environ, (char *) (environ + 1),
1611 sizeof (char *) * (num_envs+1));
1616 #endif /* HAVE_PUTENV */
1619 /* Build a list of search directories from PATHS.
1620 PREFIX is a string to prepend to the list.
1621 If CHECK_DIR_P is non-zero we ensure the directory exists.
1622 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1623 It is also used by the --print-search-dirs flag. */
1626 build_search_list (paths, prefix, check_dir_p)
1627 struct path_prefix *paths;
1631 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1633 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1634 int first_time = TRUE;
1635 struct prefix_list *pprefix;
1637 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1639 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1641 int len = strlen (pprefix->prefix);
1645 || is_directory (pprefix->prefix, machine_suffix, 0)))
1648 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1651 obstack_grow (&collect_obstack, pprefix->prefix, len);
1652 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1655 if (just_machine_suffix
1656 && pprefix->require_machine_suffix == 2
1658 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1661 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1664 obstack_grow (&collect_obstack, pprefix->prefix, len);
1665 obstack_grow (&collect_obstack, just_machine_suffix,
1669 if (!pprefix->require_machine_suffix)
1672 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1675 obstack_grow (&collect_obstack, pprefix->prefix, len);
1678 obstack_1grow (&collect_obstack, '\0');
1679 return obstack_finish (&collect_obstack);
1682 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1686 putenv_from_prefixes (paths, env_var)
1687 struct path_prefix *paths;
1690 putenv (build_search_list (paths, env_var, 1));
1693 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1694 access to check permissions.
1695 Return 0 if not found, otherwise return its name, allocated with malloc. */
1698 find_a_file (pprefix, name, mode)
1699 struct path_prefix *pprefix;
1704 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1705 struct prefix_list *pl;
1706 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1709 len += strlen (machine_suffix);
1711 temp = xmalloc (len);
1713 /* Determine the filename to execute (special case for absolute paths). */
1715 if (*name == '/' || *name == DIR_SEPARATOR)
1717 if (access (name, mode))
1719 strcpy (temp, name);
1724 for (pl = pprefix->plist; pl; pl = pl->next)
1728 /* Some systems have a suffix for executable files.
1729 So try appending that first. */
1730 if (file_suffix[0] != 0)
1732 strcpy (temp, pl->prefix);
1733 strcat (temp, machine_suffix);
1734 strcat (temp, name);
1735 strcat (temp, file_suffix);
1736 if (access (temp, mode) == 0)
1738 if (pl->used_flag_ptr != 0)
1739 *pl->used_flag_ptr = 1;
1744 /* Now try just the name. */
1745 strcpy (temp, pl->prefix);
1746 strcat (temp, machine_suffix);
1747 strcat (temp, name);
1748 if (access (temp, mode) == 0)
1750 if (pl->used_flag_ptr != 0)
1751 *pl->used_flag_ptr = 1;
1756 /* Certain prefixes are tried with just the machine type,
1757 not the version. This is used for finding as, ld, etc. */
1758 if (just_machine_suffix && pl->require_machine_suffix == 2)
1760 /* Some systems have a suffix for executable files.
1761 So try appending that first. */
1762 if (file_suffix[0] != 0)
1764 strcpy (temp, pl->prefix);
1765 strcat (temp, just_machine_suffix);
1766 strcat (temp, name);
1767 strcat (temp, file_suffix);
1768 if (access (temp, mode) == 0)
1770 if (pl->used_flag_ptr != 0)
1771 *pl->used_flag_ptr = 1;
1776 strcpy (temp, pl->prefix);
1777 strcat (temp, just_machine_suffix);
1778 strcat (temp, name);
1779 if (access (temp, mode) == 0)
1781 if (pl->used_flag_ptr != 0)
1782 *pl->used_flag_ptr = 1;
1787 /* Certain prefixes can't be used without the machine suffix
1788 when the machine or version is explicitly specified. */
1789 if (!pl->require_machine_suffix)
1791 /* Some systems have a suffix for executable files.
1792 So try appending that first. */
1793 if (file_suffix[0] != 0)
1795 strcpy (temp, pl->prefix);
1796 strcat (temp, name);
1797 strcat (temp, file_suffix);
1798 if (access (temp, mode) == 0)
1800 if (pl->used_flag_ptr != 0)
1801 *pl->used_flag_ptr = 1;
1806 strcpy (temp, pl->prefix);
1807 strcat (temp, name);
1808 if (access (temp, mode) == 0)
1810 if (pl->used_flag_ptr != 0)
1811 *pl->used_flag_ptr = 1;
1821 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1822 at the start of the list, otherwise it goes at the end.
1824 If WARN is nonzero, we will warn if no file is found
1825 through this prefix. WARN should point to an int
1826 which will be set to 1 if this entry is used.
1828 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1829 the complete value of machine_suffix.
1830 2 means try both machine_suffix and just_machine_suffix. */
1833 add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1834 struct path_prefix *pprefix;
1837 int require_machine_suffix;
1840 struct prefix_list *pl, **prev;
1843 if (!first && pprefix->plist)
1845 for (pl = pprefix->plist; pl->next; pl = pl->next)
1850 prev = &pprefix->plist;
1852 /* Keep track of the longest prefix */
1854 len = strlen (prefix);
1855 if (len > pprefix->max_len)
1856 pprefix->max_len = len;
1858 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1859 pl->prefix = save_string (prefix, len);
1860 pl->require_machine_suffix = require_machine_suffix;
1861 pl->used_flag_ptr = warn;
1868 pl->next = (struct prefix_list *) 0;
1872 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1875 unused_prefix_warnings (pprefix)
1876 struct path_prefix *pprefix;
1878 struct prefix_list *pl = pprefix->plist;
1882 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1884 if (pl->require_machine_suffix && machine_suffix)
1885 error ("file path prefix `%s%s' never used", pl->prefix,
1888 error ("file path prefix `%s' never used", pl->prefix);
1890 /* Prevent duplicate warnings. */
1891 *pl->used_flag_ptr = 1;
1897 /* Get rid of all prefixes built up so far in *PLISTP. */
1900 free_path_prefix (pprefix)
1901 struct path_prefix *pprefix;
1903 struct prefix_list *pl = pprefix->plist;
1904 struct prefix_list *temp;
1910 free (temp->prefix);
1911 free ((char *) temp);
1913 pprefix->plist = (struct prefix_list *) 0;
1916 /* Execute the command specified by the arguments on the current line of spec.
1917 When using pipes, this includes several piped-together commands
1918 with `|' between them.
1920 Return 0 if successful, -1 if failed. */
1926 int n_commands; /* # of command. */
1930 char *prog; /* program name. */
1931 char **argv; /* vector of args. */
1932 int pid; /* pid of process for this command. */
1935 struct command *commands; /* each command buffer with above info. */
1937 /* Count # of piped commands. */
1938 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1939 if (strcmp (argbuf[i], "|") == 0)
1942 /* Get storage for each command. */
1944 = (struct command *) alloca (n_commands * sizeof (struct command));
1946 /* Split argbuf into its separate piped processes,
1947 and record info about each one.
1948 Also search for the programs that are to be run. */
1950 commands[0].prog = argbuf[0]; /* first command. */
1951 commands[0].argv = &argbuf[0];
1952 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
1954 commands[0].argv[0] = string;
1956 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1957 if (strcmp (argbuf[i], "|") == 0)
1958 { /* each command. */
1959 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) || defined (OS2)
1960 fatal ("-pipe not supported");
1962 argbuf[i] = 0; /* termination of command args. */
1963 commands[n_commands].prog = argbuf[i + 1];
1964 commands[n_commands].argv = &argbuf[i + 1];
1965 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
1967 commands[n_commands].argv[0] = string;
1971 argbuf[argbuf_index] = 0;
1973 /* If -v, print what we are about to do, and maybe query. */
1977 /* Print each piped command as a separate line. */
1978 for (i = 0; i < n_commands ; i++)
1982 for (j = commands[i].argv; *j; j++)
1983 fprintf (stderr, " %s", *j);
1985 /* Print a pipe symbol after all but the last command. */
1986 if (i + 1 != n_commands)
1987 fprintf (stderr, " |");
1988 fprintf (stderr, "\n");
1992 fprintf (stderr, "\nGo ahead? (y or n) ");
1996 while (getchar () != '\n') ;
1997 if (i != 'y' && i != 'Y')
2002 /* Run each piped subprocess. */
2004 for (i = 0; i < n_commands; i++)
2006 char *errmsg_fmt, *errmsg_arg;
2007 char *string = commands[i].argv[0];
2009 commands[i].pid = pexecute (string, commands[i].argv,
2010 programname, temp_filename,
2011 &errmsg_fmt, &errmsg_arg,
2012 ((i == 0 ? PEXECUTE_FIRST : 0)
2013 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2014 | (string == commands[i].prog
2015 ? PEXECUTE_SEARCH : 0)
2016 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2018 if (commands[i].pid == -1)
2019 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2021 if (string != commands[i].prog)
2027 /* Wait for all the subprocesses to finish.
2028 We don't care what order they finish in;
2029 we know that N_COMMANDS waits will get them all.
2030 Ignore subprocesses that we don't know about,
2031 since they can be spawned by the process that exec'ed us. */
2036 for (i = 0; i < n_commands; )
2042 pid = pwait (commands[i].pid, &status, 0);
2046 for (j = 0; j < n_commands; j++)
2047 if (commands[j].pid == pid)
2052 if (WIFSIGNALED (status))
2054 fatal ("Internal compiler error: program %s got fatal signal %d",
2055 commands[j].prog, WTERMSIG (status));
2059 else if (WIFEXITED (status)
2060 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2070 /* Find all the switches given to us
2071 and make a vector describing them.
2072 The elements of the vector are strings, one per switch given.
2073 If a switch uses following arguments, then the `part1' field
2074 is the switch itself and the `args' field
2075 is a null-terminated vector containing the following arguments.
2076 The `live_cond' field is 1 if the switch is true in a conditional spec,
2077 -1 if false (overridden by a later switch), and is initialized to zero.
2078 The `valid' field is nonzero if any spec has looked at this switch;
2079 if it remains zero at the end of the run, it must be meaningless. */
2089 static struct switchstr *switches;
2091 static int n_switches;
2099 /* Also a vector of input files specified. */
2101 static struct infile *infiles;
2103 static int n_infiles;
2105 /* And a vector of corresponding output files is made up later. */
2107 static char **outfiles;
2109 /* Used to track if none of the -B paths are used. */
2112 /* Used to track if standard path isn't used and -b or -V is specified. */
2113 static int warn_std;
2115 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2116 static int *warn_std_ptr = 0;
2119 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2121 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2122 is true if we should look for an executable suffix as well. */
2125 convert_filename (name, do_exe)
2130 int len = strlen (name);
2132 #ifdef HAVE_OBJECT_SUFFIX
2133 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2135 && name[len - 2] == '.'
2136 && name[len - 1] == 'o')
2138 obstack_grow (&obstack, name[i], len - 2);
2139 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2140 name = obstack_finish (&obstack);
2144 #ifdef HAVE_EXECUTABLE_SUFFIX
2145 /* If there is no filetype, make it the executable suffix (which includes
2146 the "."). But don't get confused if we have just "-o". */
2147 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2150 for (i = len - 1; i >= 0; i--)
2151 if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2154 for (i++; i < len; i++)
2158 obstack_grow (&obstack, name, len);
2159 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2160 name = obstack_finish (&obstack);
2167 /* Create the vector `switches' and its contents.
2168 Store its length in `n_switches'. */
2171 process_command (argc, argv)
2177 char *spec_lang = 0;
2178 int last_language_n_infiles;
2181 int lang_n_infiles = 0;
2183 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
2188 /* Figure compiler version from version string. */
2190 compiler_version = save_string (version_string, strlen (version_string));
2191 for (temp = compiler_version; *temp; ++temp)
2200 /* Set up the default search paths. */
2202 if (gcc_exec_prefix)
2204 add_prefix (&exec_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2205 add_prefix (&startfile_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2208 /* COMPILER_PATH and LIBRARY_PATH have values
2209 that are lists of directory names with colons. */
2211 temp = getenv ("COMPILER_PATH");
2214 char *startp, *endp;
2215 char *nstore = (char *) alloca (strlen (temp) + 3);
2217 startp = endp = temp;
2220 if (*endp == PATH_SEPARATOR || *endp == 0)
2222 strncpy (nstore, startp, endp-startp);
2224 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2225 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2227 nstore[endp-startp] = DIR_SEPARATOR;
2228 nstore[endp-startp+1] = 0;
2231 nstore[endp-startp] = 0;
2232 add_prefix (&exec_prefixes, nstore, 0, 0, NULL_PTR);
2235 endp = startp = endp + 1;
2242 temp = getenv ("LIBRARY_PATH");
2243 if (temp && ! cross_compile)
2245 char *startp, *endp;
2246 char *nstore = (char *) alloca (strlen (temp) + 3);
2248 startp = endp = temp;
2251 if (*endp == PATH_SEPARATOR || *endp == 0)
2253 strncpy (nstore, startp, endp-startp);
2255 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2256 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2258 nstore[endp-startp] = DIR_SEPARATOR;
2259 nstore[endp-startp+1] = 0;
2262 nstore[endp-startp] = 0;
2263 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2266 endp = startp = endp + 1;
2273 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2274 temp = getenv ("LPATH");
2275 if (temp && ! cross_compile)
2277 char *startp, *endp;
2278 char *nstore = (char *) alloca (strlen (temp) + 3);
2280 startp = endp = temp;
2283 if (*endp == PATH_SEPARATOR || *endp == 0)
2285 strncpy (nstore, startp, endp-startp);
2287 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2288 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2290 nstore[endp-startp] = DIR_SEPARATOR;
2291 nstore[endp-startp+1] = 0;
2294 nstore[endp-startp] = 0;
2295 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2298 endp = startp = endp + 1;
2305 /* Convert new-style -- options to old-style. */
2306 translate_options (&argc, &argv);
2308 #ifdef LANG_SPECIFIC_DRIVER
2309 /* Do language-specific adjustment/addition of flags. */
2310 lang_specific_driver (&fatal, &argc, &argv);
2313 /* Scan argv twice. Here, the first time, just count how many switches
2314 there will be in their vector, and how many input files in theirs.
2315 Here we also parse the switches that cc itself uses (e.g. -v). */
2317 for (i = 1; i < argc; i++)
2319 if (! strcmp (argv[i], "-dumpspecs"))
2321 printf ("*asm:\n%s\n\n", asm_spec);
2322 printf ("*asm_final:\n%s\n\n", asm_final_spec);
2323 printf ("*cpp:\n%s\n\n", cpp_spec);
2324 printf ("*cc1:\n%s\n\n", cc1_spec);
2325 printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
2326 printf ("*endfile:\n%s\n\n", endfile_spec);
2327 printf ("*link:\n%s\n\n", link_spec);
2328 printf ("*lib:\n%s\n\n", lib_spec);
2329 printf ("*libgcc:\n%s\n\n", libgcc_spec);
2330 printf ("*startfile:\n%s\n\n", startfile_spec);
2331 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
2332 printf ("*signed_char:\n%s\n\n", signed_char_spec);
2333 printf ("*predefines:\n%s\n\n", cpp_predefines);
2334 printf ("*cross_compile:\n%d\n\n", cross_compile);
2335 printf ("*version:\n%s\n\n", compiler_version);
2336 printf ("*multilib:\n%s\n\n", multilib_select);
2337 printf ("*multilib_defaults:\n%s\n\n", multilib_defaults);
2338 printf ("*multilib_extra:\n%s\n\n", multilib_extra);
2339 printf ("*multilib_matches:\n%s\n\n", multilib_matches);
2344 for (j = 0; j < sizeof (extra_specs) / sizeof (extra_specs[0]); j++)
2345 printf ("*%s:\n%s\n\n", extra_specs[j].name,
2346 (extra_specs[j].spec) ? extra_specs[j].spec : "");
2351 else if (! strcmp (argv[i], "-dumpversion"))
2353 printf ("%s\n", version_string);
2356 else if (! strcmp (argv[i], "-dumpmachine"))
2358 printf ("%s\n", spec_machine);
2361 else if (! strcmp (argv[i], "-print-search-dirs"))
2362 print_search_dirs = 1;
2363 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2364 print_file_name = "libgcc.a";
2365 else if (! strncmp (argv[i], "-print-file-name=", 17))
2366 print_file_name = argv[i] + 17;
2367 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2368 print_prog_name = argv[i] + 17;
2369 else if (! strcmp (argv[i], "-print-multi-lib"))
2370 print_multi_lib = 1;
2371 else if (! strcmp (argv[i], "-print-multi-directory"))
2372 print_multi_directory = 1;
2373 else if (! strncmp (argv[i], "-Wa,", 4))
2376 /* Pass the rest of this option to the assembler. */
2378 n_assembler_options++;
2379 if (!assembler_options)
2381 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2384 = (char **) xrealloc (assembler_options,
2385 n_assembler_options * sizeof (char **));
2387 /* Split the argument at commas. */
2389 for (j = 4; argv[i][j]; j++)
2390 if (argv[i][j] == ',')
2392 assembler_options[n_assembler_options - 1]
2393 = save_string (argv[i] + prev, j - prev);
2394 n_assembler_options++;
2396 = (char **) xrealloc (assembler_options,
2397 n_assembler_options * sizeof (char **));
2400 /* Record the part after the last comma. */
2401 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2403 else if (! strncmp (argv[i], "-Wp,", 4))
2406 /* Pass the rest of this option to the preprocessor. */
2408 n_preprocessor_options++;
2409 if (!preprocessor_options)
2410 preprocessor_options
2411 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2413 preprocessor_options
2414 = (char **) xrealloc (preprocessor_options,
2415 n_preprocessor_options * sizeof (char **));
2417 /* Split the argument at commas. */
2419 for (j = 4; argv[i][j]; j++)
2420 if (argv[i][j] == ',')
2422 preprocessor_options[n_preprocessor_options - 1]
2423 = save_string (argv[i] + prev, j - prev);
2424 n_preprocessor_options++;
2425 preprocessor_options
2426 = (char **) xrealloc (preprocessor_options,
2427 n_preprocessor_options * sizeof (char **));
2430 /* Record the part after the last comma. */
2431 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2433 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2434 /* The +e options to the C++ front-end. */
2436 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2439 /* Split the argument at commas. */
2440 for (j = 3; argv[i][j]; j++)
2441 n_infiles += (argv[i][j] == ',');
2443 else if (strcmp (argv[i], "-Xlinker") == 0)
2446 fatal ("argument to `-Xlinker' is missing");
2451 else if (strncmp (argv[i], "-l", 2) == 0)
2453 else if (strcmp (argv[i], "-save-temps") == 0)
2455 save_temps_flag = 1;
2458 else if (strcmp (argv[i], "-specs") == 0)
2460 struct user_specs *user = (struct user_specs *)
2461 xmalloc (sizeof (struct user_specs));
2463 fatal ("argument to `-specs' is missing");
2465 user->next = (struct user_specs *)0;
2466 user->filename = argv[i];
2467 if (user_specs_tail)
2468 user_specs_tail->next = user;
2470 user_specs_head = user;
2471 user_specs_tail = user;
2473 else if (strncmp (argv[i], "-specs=", 7) == 0)
2475 struct user_specs *user = (struct user_specs *)
2476 xmalloc (sizeof (struct user_specs));
2477 if (strlen (argv[i]) == 7)
2478 fatal ("argument to `-specs=' is missing");
2480 user->next = (struct user_specs *)0;
2481 user->filename = argv[i]+7;
2482 if (user_specs_tail)
2483 user_specs_tail->next = user;
2485 user_specs_head = user;
2486 user_specs_tail = user;
2488 else if (argv[i][0] == '-' && argv[i][1] != 0)
2490 register char *p = &argv[i][1];
2491 register int c = *p;
2496 if (p[1] == 0 && i + 1 == argc)
2497 fatal ("argument to `-b' is missing");
2499 spec_machine = argv[++i];
2501 spec_machine = p + 1;
2503 warn_std_ptr = &warn_std;
2508 int *temp = (int *) xmalloc (sizeof (int));
2510 if (p[1] == 0 && i + 1 == argc)
2511 fatal ("argument to `-B' is missing");
2516 add_prefix (&exec_prefixes, value, 1, 0, &warn_B);
2517 add_prefix (&startfile_prefixes, value, 1, 0, &warn_B);
2518 add_prefix (&include_prefixes, concat (value, "include", NULL_PTR),
2521 /* As a kludge, if the arg is "[foo/]stageN/", just add
2522 "[foo/]include" to the include prefix. */
2524 int len = strlen (value);
2527 && (value[len - 8] == '/'
2528 || value[len - 8] == DIR_SEPARATOR)))
2529 && strncmp (value + len - 7, "stage", 5) == 0
2530 && isdigit (value[len - 2])
2531 && (value[len - 1] == '/'
2532 || value[len - 1] == DIR_SEPARATOR))
2535 add_prefix (&include_prefixes, "include",
2539 char *string = xmalloc (len + 1);
2540 strncpy (string, value, len-7);
2541 strcat (string, "include");
2542 add_prefix (&include_prefixes, string,
2550 case 'v': /* Print our subcommands and print versions. */
2552 /* If they do anything other than exactly `-v', don't set
2553 verbose_flag; rather, continue on to give the error. */
2560 if (p[1] == 0 && i + 1 == argc)
2561 fatal ("argument to `-V' is missing");
2563 spec_version = argv[++i];
2565 spec_version = p + 1;
2566 compiler_version = spec_version;
2567 warn_std_ptr = &warn_std;
2581 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2582 argv[i] = convert_filename (argv[i], 1);
2584 argv[i+1] = convert_filename (argv[i+1], 1);
2592 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2593 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2594 else if (WORD_SWITCH_TAKES_ARG (p))
2595 i += WORD_SWITCH_TAKES_ARG (p);
2605 if (have_c && have_o && lang_n_infiles > 1)
2606 fatal ("cannot specify -o with -c and multiple compilations");
2608 /* Set up the search paths before we go looking for config files. */
2610 /* These come before the md prefixes so that we will find gcc's subcommands
2611 (such as cpp) rather than those of the host system. */
2612 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2613 as well as trying the machine and the version. */
2615 add_prefix (&exec_prefixes, standard_exec_prefix, 0, 2, warn_std_ptr);
2616 add_prefix (&exec_prefixes, standard_exec_prefix_1, 0, 2, warn_std_ptr);
2619 add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, warn_std_ptr);
2620 add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, warn_std_ptr);
2622 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
2623 dir_separator_str, NULL_PTR);
2625 /* If tooldir is relative, base it on exec_prefixes. A relative
2626 tooldir lets us move the installed tree as a unit.
2628 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2629 directories, so that we can search both the user specified directory
2630 and the standard place. */
2632 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2634 if (gcc_exec_prefix)
2636 char *gcc_exec_tooldir_prefix
2637 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2638 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2640 add_prefix (&exec_prefixes,
2641 concat (gcc_exec_tooldir_prefix, "bin",
2642 dir_separator_str, NULL_PTR),
2644 add_prefix (&startfile_prefixes,
2645 concat (gcc_exec_tooldir_prefix, "lib",
2646 dir_separator_str, NULL_PTR),
2650 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2651 dir_separator_str, spec_version,
2652 dir_separator_str, tooldir_prefix, NULL_PTR);
2655 add_prefix (&exec_prefixes,
2656 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2658 add_prefix (&startfile_prefixes,
2659 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2662 /* More prefixes are enabled in main, after we read the specs file
2663 and determine whether this is cross-compilation or not. */
2666 /* Then create the space for the vectors and scan again. */
2668 switches = ((struct switchstr *)
2669 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2670 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2673 last_language_n_infiles = -1;
2675 /* This, time, copy the text of each switch and store a pointer
2676 to the copy in the vector of switches.
2677 Store all the infiles in their vector. */
2679 for (i = 1; i < argc; i++)
2681 /* Just skip the switches that were handled by the preceding loop. */
2682 if (! strncmp (argv[i], "-Wa,", 4))
2684 else if (! strncmp (argv[i], "-Wp,", 4))
2686 else if (! strcmp (argv[i], "-print-search-dirs"))
2688 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2690 else if (! strncmp (argv[i], "-print-file-name=", 17))
2692 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2694 else if (! strcmp (argv[i], "-print-multi-lib"))
2696 else if (! strcmp (argv[i], "-print-multi-directory"))
2698 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2700 /* Compensate for the +e options to the C++ front-end;
2701 they're there simply for cfront call-compatibility. We do
2702 some magic in default_compilers to pass them down properly.
2703 Note we deliberately start at the `+' here, to avoid passing
2704 -e0 or -e1 down into the linker. */
2705 switches[n_switches].part1 = &argv[i][0];
2706 switches[n_switches].args = 0;
2707 switches[n_switches].live_cond = 0;
2708 switches[n_switches].valid = 0;
2711 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2714 /* Split the argument at commas. */
2716 for (j = 4; argv[i][j]; j++)
2717 if (argv[i][j] == ',')
2719 infiles[n_infiles].language = 0;
2720 infiles[n_infiles++].name
2721 = save_string (argv[i] + prev, j - prev);
2724 /* Record the part after the last comma. */
2725 infiles[n_infiles].language = 0;
2726 infiles[n_infiles++].name = argv[i] + prev;
2728 else if (strcmp (argv[i], "-Xlinker") == 0)
2730 infiles[n_infiles].language = 0;
2731 infiles[n_infiles++].name = argv[++i];
2733 else if (strncmp (argv[i], "-l", 2) == 0)
2735 infiles[n_infiles].language = 0;
2736 infiles[n_infiles++].name = argv[i];
2738 else if (strcmp (argv[i], "-specs") == 0)
2740 else if (strncmp (argv[i], "-specs=", 7) == 0)
2742 else if (argv[i][0] == '-' && argv[i][1] != 0)
2744 register char *p = &argv[i][1];
2745 register int c = *p;
2747 if (c == 'B' || c == 'b' || c == 'V')
2749 /* Skip a separate arg, if any. */
2756 if (p[1] == 0 && i + 1 == argc)
2757 fatal ("argument to `-x' is missing");
2759 spec_lang = argv[++i];
2762 if (! strcmp (spec_lang, "none"))
2763 /* Suppress the warning if -xnone comes after the last input
2764 file, because alternate command interfaces like g++ might
2765 find it useful to place -xnone after each input file. */
2768 last_language_n_infiles = n_infiles;
2771 switches[n_switches].part1 = p;
2772 /* Deal with option arguments in separate argv elements. */
2773 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2774 || WORD_SWITCH_TAKES_ARG (p))
2777 int n_args = WORD_SWITCH_TAKES_ARG (p);
2781 /* Count only the option arguments in separate argv elements. */
2782 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2784 if (i + n_args >= argc)
2785 fatal ("argument to `-%s' is missing", p);
2786 switches[n_switches].args
2787 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2789 switches[n_switches].args[j++] = argv[++i];
2790 /* Null-terminate the vector. */
2791 switches[n_switches].args[j] = 0;
2793 else if (index (switches_need_spaces, c))
2795 /* On some systems, ld cannot handle some options without
2796 a space. So split the option from its argument. */
2797 char *part1 = (char *) xmalloc (2);
2801 switches[n_switches].part1 = part1;
2802 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2803 switches[n_switches].args[0] = xmalloc (strlen (p));
2804 strcpy (switches[n_switches].args[0], &p[1]);
2805 switches[n_switches].args[1] = 0;
2808 switches[n_switches].args = 0;
2810 switches[n_switches].live_cond = 0;
2811 switches[n_switches].valid = 0;
2812 /* This is always valid, since gcc.c itself understands it. */
2813 if (!strcmp (p, "save-temps"))
2814 switches[n_switches].valid = 1;
2819 #ifdef HAVE_OBJECT_SUFFIX
2820 argv[i] = convert_filename (argv[i], 0);
2823 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
2825 perror_with_name (argv[i]);
2830 infiles[n_infiles].language = spec_lang;
2831 infiles[n_infiles++].name = argv[i];
2836 if (n_infiles == last_language_n_infiles && spec_lang != 0)
2837 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2839 switches[n_switches].part1 = 0;
2840 infiles[n_infiles].name = 0;
2843 /* Process a spec string, accumulating and running commands. */
2845 /* These variables describe the input file name.
2846 input_file_number is the index on outfiles of this file,
2847 so that the output file name can be stored for later use by %o.
2848 input_basename is the start of the part of the input file
2849 sans all directory names, and basename_length is the number
2850 of characters starting there excluding the suffix .c or whatever. */
2852 static char *input_filename;
2853 static int input_file_number;
2854 static int input_filename_length;
2855 static int basename_length;
2856 static char *input_basename;
2857 static char *input_suffix;
2859 /* These are variables used within do_spec and do_spec_1. */
2861 /* Nonzero if an arg has been started and not yet terminated
2862 (with space, tab or newline). */
2863 static int arg_going;
2865 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2866 is a temporary file name. */
2867 static int delete_this_arg;
2869 /* Nonzero means %w has been seen; the next arg to be terminated
2870 is the output file name of this compilation. */
2871 static int this_is_output_file;
2873 /* Nonzero means %s has been seen; the next arg to be terminated
2874 is the name of a library file and we should try the standard
2875 search dirs for it. */
2876 static int this_is_library_file;
2878 /* Nonzero means that the input of this command is coming from a pipe. */
2879 static int input_from_pipe;
2881 /* Process the spec SPEC and run the commands specified therein.
2882 Returns 0 if the spec is successfully processed; -1 if failed. */
2892 delete_this_arg = 0;
2893 this_is_output_file = 0;
2894 this_is_library_file = 0;
2895 input_from_pipe = 0;
2897 value = do_spec_1 (spec, 0, NULL_PTR);
2899 /* Force out any unfinished command.
2900 If -pipe, this forces out the last command if it ended in `|'. */
2903 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2906 if (argbuf_index > 0)
2913 /* Process the sub-spec SPEC as a portion of a larger spec.
2914 This is like processing a whole spec except that we do
2915 not initialize at the beginning and we do not supply a
2916 newline by default at the end.
2917 INSWITCH nonzero means don't process %-sequences in SPEC;
2918 in this case, % is treated as an ordinary character.
2919 This is used while substituting switches.
2920 INSWITCH nonzero also causes SPC not to terminate an argument.
2922 Value is zero unless a line was finished
2923 and the command on that line reported an error. */
2926 do_spec_1 (spec, inswitch, soft_matched_part)
2929 char *soft_matched_part;
2931 register char *p = spec;
2938 /* If substituting a switch, treat all chars like letters.
2939 Otherwise, NL, SPC, TAB and % are special. */
2940 switch (inswitch ? 'a' : c)
2943 /* End of line: finish any pending argument,
2944 then run the pending command if one has been started. */
2947 obstack_1grow (&obstack, 0);
2948 string = obstack_finish (&obstack);
2949 if (this_is_library_file)
2950 string = find_file (string);
2951 store_arg (string, delete_this_arg, this_is_output_file);
2952 if (this_is_output_file)
2953 outfiles[input_file_number] = string;
2957 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2959 for (i = 0; i < n_switches; i++)
2960 if (!strcmp (switches[i].part1, "pipe"))
2963 /* A `|' before the newline means use a pipe here,
2964 but only if -pipe was specified.
2965 Otherwise, execute now and don't pass the `|' as an arg. */
2968 input_from_pipe = 1;
2969 switches[i].valid = 1;
2976 if (argbuf_index > 0)
2982 /* Reinitialize for a new command, and for a new argument. */
2985 delete_this_arg = 0;
2986 this_is_output_file = 0;
2987 this_is_library_file = 0;
2988 input_from_pipe = 0;
2992 /* End any pending argument. */
2995 obstack_1grow (&obstack, 0);
2996 string = obstack_finish (&obstack);
2997 if (this_is_library_file)
2998 string = find_file (string);
2999 store_arg (string, delete_this_arg, this_is_output_file);
3000 if (this_is_output_file)
3001 outfiles[input_file_number] = string;
3005 obstack_1grow (&obstack, c);
3011 /* Space or tab ends an argument if one is pending. */
3014 obstack_1grow (&obstack, 0);
3015 string = obstack_finish (&obstack);
3016 if (this_is_library_file)
3017 string = find_file (string);
3018 store_arg (string, delete_this_arg, this_is_output_file);
3019 if (this_is_output_file)
3020 outfiles[input_file_number] = string;
3022 /* Reinitialize for a new argument. */
3024 delete_this_arg = 0;
3025 this_is_output_file = 0;
3026 this_is_library_file = 0;
3033 fatal ("Invalid specification! Bug in cc.");
3036 obstack_grow (&obstack, input_basename, basename_length);
3041 delete_this_arg = 2;
3044 /* Dump out the directories specified with LIBRARY_PATH,
3045 followed by the absolute directories
3046 that we search for startfiles. */
3049 struct prefix_list *pl = startfile_prefixes.plist;
3051 char *buffer = (char *) xmalloc (bufsize);
3054 for (; pl; pl = pl->next)
3056 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3057 /* Used on systems which record the specified -L dirs
3058 and use them to search for dynamic linking. */
3059 /* Relative directories always come from -B,
3060 and it is better not to use them for searching
3061 at run time. In particular, stage1 loses */
3062 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3065 /* Try subdirectory if there is one. */
3066 if (multilib_dir != NULL)
3070 if (strlen (pl->prefix) + strlen (machine_suffix)
3072 bufsize = (strlen (pl->prefix)
3073 + strlen (machine_suffix)) * 2 + 1;
3074 buffer = (char *) xrealloc (buffer, bufsize);
3075 strcpy (buffer, pl->prefix);
3076 strcat (buffer, machine_suffix);
3077 if (is_directory (buffer, multilib_dir, 1))
3079 do_spec_1 ("-L", 0, NULL_PTR);
3080 #ifdef SPACE_AFTER_L_OPTION
3081 do_spec_1 (" ", 0, NULL_PTR);
3083 do_spec_1 (buffer, 1, NULL_PTR);
3084 do_spec_1 (multilib_dir, 1, NULL_PTR);
3085 /* Make this a separate argument. */
3086 do_spec_1 (" ", 0, NULL_PTR);
3089 if (!pl->require_machine_suffix)
3091 if (is_directory (pl->prefix, multilib_dir, 1))
3093 do_spec_1 ("-L", 0, NULL_PTR);
3094 #ifdef SPACE_AFTER_L_OPTION
3095 do_spec_1 (" ", 0, NULL_PTR);
3097 do_spec_1 (pl->prefix, 1, NULL_PTR);
3098 do_spec_1 (multilib_dir, 1, NULL_PTR);
3099 /* Make this a separate argument. */
3100 do_spec_1 (" ", 0, NULL_PTR);
3106 if (is_directory (pl->prefix, machine_suffix, 1))
3108 do_spec_1 ("-L", 0, NULL_PTR);
3109 #ifdef SPACE_AFTER_L_OPTION
3110 do_spec_1 (" ", 0, NULL_PTR);
3112 do_spec_1 (pl->prefix, 1, NULL_PTR);
3113 /* Remove slash from machine_suffix. */
3114 if (strlen (machine_suffix) >= bufsize)
3115 bufsize = strlen (machine_suffix) * 2 + 1;
3116 buffer = (char *) xrealloc (buffer, bufsize);
3117 strcpy (buffer, machine_suffix);
3118 idx = strlen (buffer);
3119 if (buffer[idx - 1] == '/'
3120 || buffer[idx - 1] == DIR_SEPARATOR)
3121 buffer[idx - 1] = 0;
3122 do_spec_1 (buffer, 1, NULL_PTR);
3123 /* Make this a separate argument. */
3124 do_spec_1 (" ", 0, NULL_PTR);
3127 if (!pl->require_machine_suffix)
3129 if (is_directory (pl->prefix, "", 1))
3131 do_spec_1 ("-L", 0, NULL_PTR);
3132 #ifdef SPACE_AFTER_L_OPTION
3133 do_spec_1 (" ", 0, NULL_PTR);
3135 /* Remove slash from pl->prefix. */
3136 if (strlen (pl->prefix) >= bufsize)
3137 bufsize = strlen (pl->prefix) * 2 + 1;
3138 buffer = (char *) xrealloc (buffer, bufsize);
3139 strcpy (buffer, pl->prefix);
3140 idx = strlen (buffer);
3141 if (buffer[idx - 1] == '/'
3142 || buffer[idx - 1] == DIR_SEPARATOR)
3143 buffer[idx - 1] = 0;
3144 do_spec_1 (buffer, 1, NULL_PTR);
3145 /* Make this a separate argument. */
3146 do_spec_1 (" ", 0, NULL_PTR);
3155 /* {...:%efoo} means report an error with `foo' as error message
3156 and don't execute any more commands for this file. */
3160 while (*p != 0 && *p != '\n') p++;
3161 buf = (char *) alloca (p - q + 1);
3162 strncpy (buf, q, p - q);
3172 if (save_temps_flag)
3174 obstack_grow (&obstack, input_basename, basename_length);
3175 delete_this_arg = 0;
3179 #ifdef MKTEMP_EACH_FILE
3180 /* ??? This has a problem: the total number of
3181 values mktemp can return is limited.
3182 That matters for the names of object files.
3183 In 2.4, do something about that. */
3184 struct temp_name *t;
3186 while (*p == '.' || isalpha (*p)
3187 || (p[0] == '%' && p[1] == 'O'))
3190 /* See if we already have an association of %g/%u/%U and
3192 for (t = temp_names; t; t = t->next)
3193 if (t->length == p - suffix
3194 && strncmp (t->suffix, suffix, p - suffix) == 0
3195 && t->unique == (c != 'g'))
3198 /* Make a new association if needed. %u requires one. */
3199 if (t == 0 || c == 'u')
3203 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3204 t->next = temp_names;
3207 t->length = p - suffix;
3208 t->suffix = save_string (suffix, p - suffix);
3209 t->unique = (c != 'g');
3210 temp_filename = choose_temp_base ();
3211 temp_filename_length = strlen (temp_filename);
3212 t->filename = temp_filename;
3213 t->filename_length = temp_filename_length;
3216 obstack_grow (&obstack, t->filename, t->filename_length);
3217 delete_this_arg = 1;
3219 obstack_grow (&obstack, temp_filename, temp_filename_length);
3220 if (c == 'u' || c == 'U')
3226 sprintf (buff, "%d", unique);
3227 obstack_grow (&obstack, buff, strlen (buff));
3230 delete_this_arg = 1;
3236 obstack_grow (&obstack, input_filename, input_filename_length);
3242 struct prefix_list *pl = include_prefixes.plist;
3244 if (gcc_exec_prefix)
3246 do_spec_1 ("-iprefix", 1, NULL_PTR);
3247 /* Make this a separate argument. */
3248 do_spec_1 (" ", 0, NULL_PTR);
3249 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3250 do_spec_1 (" ", 0, NULL_PTR);
3253 for (; pl; pl = pl->next)
3255 do_spec_1 ("-isystem", 1, NULL_PTR);
3256 /* Make this a separate argument. */
3257 do_spec_1 (" ", 0, NULL_PTR);
3258 do_spec_1 (pl->prefix, 1, NULL_PTR);
3259 do_spec_1 (" ", 0, NULL_PTR);
3265 for (i = 0; i < n_infiles; i++)
3266 store_arg (outfiles[i], 0, 0);
3270 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3275 this_is_library_file = 1;
3279 this_is_output_file = 1;
3284 int cur_index = argbuf_index;
3285 /* Handle the {...} following the %W. */
3288 p = handle_braces (p + 1);
3291 /* If any args were output, mark the last one for deletion
3293 if (argbuf_index != cur_index)
3294 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3298 /* %x{OPTION} records OPTION for %X to output. */
3304 /* Skip past the option value and make a copy. */
3309 string = save_string (p1 + 1, p - p1 - 2);
3311 /* See if we already recorded this option. */
3312 for (i = 0; i < n_linker_options; i++)
3313 if (! strcmp (string, linker_options[i]))
3319 /* This option is new; add it. */
3321 if (!linker_options)
3323 = (char **) xmalloc (n_linker_options * sizeof (char **));
3326 = (char **) xrealloc (linker_options,
3327 n_linker_options * sizeof (char **));
3329 linker_options[n_linker_options - 1] = string;
3333 /* Dump out the options accumulated previously using %x. */
3335 for (i = 0; i < n_linker_options; i++)
3337 do_spec_1 (linker_options[i], 1, NULL_PTR);
3338 /* Make each accumulated option a separate argument. */
3339 do_spec_1 (" ", 0, NULL_PTR);
3343 /* Dump out the options accumulated previously using -Wa,. */
3345 for (i = 0; i < n_assembler_options; i++)
3347 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3348 /* Make each accumulated option a separate argument. */
3349 do_spec_1 (" ", 0, NULL_PTR);
3353 /* Dump out the options accumulated previously using -Wp,. */
3355 for (i = 0; i < n_preprocessor_options; i++)
3357 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3358 /* Make each accumulated option a separate argument. */
3359 do_spec_1 (" ", 0, NULL_PTR);
3363 /* Here are digits and numbers that just process
3364 a certain constant string as a spec. */
3367 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3373 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3379 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3385 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3391 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3397 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3403 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3409 value = do_spec_1 (link_spec, 0, NULL_PTR);
3415 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3421 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3428 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3432 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3436 if (! strncmp (y, "-D", 2))
3437 /* Copy the whole option. */
3438 while (*y && *y != ' ' && *y != '\t')
3440 else if (*y == ' ' || *y == '\t')
3441 /* Copy whitespace to the result. */
3443 /* Don't copy other options. */
3450 value = do_spec_1 (buf, 0, NULL_PTR);
3458 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3462 /* Copy all of CPP_PREDEFINES into BUF,
3463 but put __ after every -D and at the end of each arg. */
3467 if (! strncmp (y, "-D", 2))
3475 || (*(y+1) != '_' && ! isupper (*(y+1))))
3477 /* Stick __ at front of macro name. */
3480 /* Arrange to stick __ at the end as well. */
3484 /* Copy the macro name. */
3485 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3494 /* Copy the value given, if any. */
3495 while (*y && *y != ' ' && *y != '\t')
3498 else if (*y == ' ' || *y == '\t')
3499 /* Copy whitespace to the result. */
3501 /* Don't copy -A options */
3507 /* Copy all of CPP_PREDEFINES into BUF,
3508 but put __ after every -D. */
3512 if (! strncmp (y, "-D", 2))
3517 || (*(y+1) != '_' && ! isupper (*(y+1))))
3519 /* Stick -D__ at front of macro name. */
3525 /* Copy the macro name. */
3526 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3529 /* Copy the value given, if any. */
3530 while (*y && *y != ' ' && *y != '\t')
3535 /* Do not copy this macro - we have just done it before */
3536 while (*y && *y != ' ' && *y != '\t')
3540 else if (*y == ' ' || *y == '\t')
3541 /* Copy whitespace to the result. */
3543 /* Don't copy -A options */
3549 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3553 if (! strncmp (y, "-A", 2))
3554 /* Copy the whole option. */
3555 while (*y && *y != ' ' && *y != '\t')
3557 else if (*y == ' ' || *y == '\t')
3558 /* Copy whitespace to the result. */
3560 /* Don't copy other options. */
3567 value = do_spec_1 (buf, 0, NULL_PTR);
3574 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3579 /* Here we define characters other than letters and digits. */
3582 p = handle_braces (p);
3588 obstack_1grow (&obstack, '%');
3592 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3593 do_spec_1 (" ", 0, NULL_PTR);
3596 /* Process a string found as the value of a spec given by name.
3597 This feature allows individual machine descriptions
3598 to add and use their own specs.
3599 %[...] modifies -D options the way %P does;
3600 %(...) uses the spec unmodified. */
3605 struct spec_list *sl;
3608 /* The string after the S/P is the name of a spec that is to be
3610 while (*p && *p != ')' && *p != ']')
3613 /* See if it's in the list */
3614 for (len = p - name, sl = specs; sl; sl = sl->next)
3615 if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
3625 value = do_spec_1 (name, 0, NULL_PTR);
3631 char *x = (char *) alloca (strlen (name) * 2 + 1);
3635 /* Copy all of NAME into BUF, but put __ after
3636 every -D and at the end of each arg, */
3641 if (! strncmp (y, "-D", 2))
3651 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
3652 || *y == '}' || *y == 0))
3665 value = do_spec_1 (buf, 0, NULL_PTR);
3671 /* Discard the closing paren or bracket. */
3679 int c1 = *p++; /* Select first or second version number. */
3680 char *v = compiler_version;
3683 /* The format of the version string is
3684 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3686 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3687 while (! isdigit (*v))
3689 if (v > compiler_version && v[-1] != '-')
3692 /* If desired, advance to second version number. */
3695 /* Set V after the first period. */
3696 while (isdigit (*v))
3703 /* Set Q at the next period or at the end. */
3705 while (isdigit (*q))
3707 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3710 /* Put that part into the command. */
3711 obstack_grow (&obstack, v, q - v);
3717 if (input_from_pipe)
3718 do_spec_1 ("-", 0, NULL_PTR);
3727 /* Backslash: treat next character as ordinary. */
3732 /* Ordinary character: put it into the current argument. */
3733 obstack_1grow (&obstack, c);
3737 return 0; /* End of string */
3740 /* Return 0 if we call do_spec_1 and that returns -1. */
3753 /* A `|' after the open-brace means,
3754 if the test fails, output a single minus sign rather than nothing.
3755 This is used in %{|!pipe:...}. */
3759 /* A `!' after the open-brace negates the condition:
3760 succeed if the specified switch is not present. */
3764 /* A `.' after the open-brace means test against the current suffix. */
3774 while (*p != ':' && *p != '}') p++;
3777 register int count = 1;
3795 int found = (input_suffix != 0
3796 && strlen (input_suffix) == p - filter
3797 && strncmp (input_suffix, filter, p - filter) == 0);
3803 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3808 else if (p[-1] == '*' && p[0] == '}')
3810 /* Substitute all matching switches as separate args. */
3813 for (i = 0; i < n_switches; i++)
3814 if (!strncmp (switches[i].part1, filter, p - filter)
3815 && check_live_switch (i, p - filter))
3820 /* Test for presence of the specified switch. */
3824 /* If name specified ends in *, as in {x*:...},
3825 check for %* and handle that case. */
3826 if (p[-1] == '*' && !negate)
3831 /* First see whether we have %*. */
3835 if (*r == '%' && r[1] == '*')
3839 /* If we do, handle that case. */
3842 /* Substitute all matching switches as separate args.
3843 But do this by substituting for %*
3844 in the text that follows the colon. */
3846 unsigned hard_match_len = p - filter - 1;
3847 char *string = save_string (p + 1, q - p - 2);
3849 for (i = 0; i < n_switches; i++)
3850 if (!strncmp (switches[i].part1, filter, hard_match_len)
3851 && check_live_switch (i, -1))
3853 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
3854 /* Pass any arguments this switch has. */
3862 /* If name specified ends in *, as in {x*:...},
3863 check for presence of any switch name starting with x. */
3866 for (i = 0; i < n_switches; i++)
3868 unsigned hard_match_len = p - filter - 1;
3870 if (!strncmp (switches[i].part1, filter, hard_match_len)
3871 && check_live_switch (i, hard_match_len))
3877 /* Otherwise, check for presence of exact name specified. */
3880 for (i = 0; i < n_switches; i++)
3882 if (!strncmp (switches[i].part1, filter, p - filter)
3883 && switches[i].part1[p - filter] == 0
3884 && check_live_switch (i, -1))
3892 /* If it is as desired (present for %{s...}, absent for %{-s...})
3893 then substitute either the switch or the specified
3894 conditional text. */
3895 if (present != negate)
3903 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3909 /* Here if a %{|...} conditional fails: output a minus sign,
3910 which means "standard output" or "standard input". */
3911 do_spec_1 ("-", 0, NULL_PTR);
3918 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3919 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3920 spec, or -1 if either exact match or %* is used.
3922 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3923 whose value does not begin with "no-" is obsoleted by the same value
3924 with the "no-", similarly for a switch with the "no-" prefix. */
3927 check_live_switch (switchnum, prefix_length)
3931 char *name = switches[switchnum].part1;
3934 /* In the common case of {<at-most-one-letter>*}, a negating
3935 switch would always match, so ignore that case. We will just
3936 send the conflicting switches to the compiler phase. */
3937 if (prefix_length >= 0 && prefix_length <= 1)
3940 /* If we already processed this switch and determined if it was
3941 live or not, return our past determination. */
3942 if (switches[switchnum].live_cond != 0)
3943 return switches[switchnum].live_cond > 0;
3945 /* Now search for duplicate in a manner that depends on the name. */
3949 for (i = switchnum + 1; i < n_switches; i++)
3950 if (switches[i].part1[0] == 'O')
3952 switches[switchnum].valid = 1;
3953 switches[switchnum].live_cond = -1;
3958 case 'W': case 'f': case 'm':
3959 if (! strncmp (name + 1, "no-", 3))
3961 /* We have Xno-YYY, search for XYYY. */
3962 for (i = switchnum + 1; i < n_switches; i++)
3963 if (switches[i].part1[0] == name[0]
3964 && ! strcmp (&switches[i].part1[1], &name[4]))
3966 switches[switchnum].valid = 1;
3967 switches[switchnum].live_cond = -1;
3973 /* We have XYYY, search for Xno-YYY. */
3974 for (i = switchnum + 1; i < n_switches; i++)
3975 if (switches[i].part1[0] == name[0]
3976 && switches[i].part1[1] == 'n'
3977 && switches[i].part1[2] == 'o'
3978 && switches[i].part1[3] == '-'
3979 && !strcmp (&switches[i].part1[4], &name[1]))
3981 switches[switchnum].valid = 1;
3982 switches[switchnum].live_cond = -1;
3989 /* Otherwise the switch is live. */
3990 switches[switchnum].live_cond = 1;
3994 /* Pass a switch to the current accumulating command
3995 in the same form that we received it.
3996 SWITCHNUM identifies the switch; it is an index into
3997 the vector of switches gcc received, which is `switches'.
3998 This cannot fail since it never finishes a command line.
4000 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
4003 give_switch (switchnum, omit_first_word)
4005 int omit_first_word;
4007 if (!omit_first_word)
4009 do_spec_1 ("-", 0, NULL_PTR);
4010 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4012 do_spec_1 (" ", 0, NULL_PTR);
4013 if (switches[switchnum].args != 0)
4016 for (p = switches[switchnum].args; *p; p++)
4018 do_spec_1 (*p, 1, NULL_PTR);
4019 do_spec_1 (" ", 0, NULL_PTR);
4022 switches[switchnum].valid = 1;
4025 /* Search for a file named NAME trying various prefixes including the
4026 user's -B prefix and some standard ones.
4027 Return the absolute file name found. If nothing is found, return NAME. */
4035 /* Try multilib_dir if it is defined. */
4036 if (multilib_dir != NULL)
4040 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4041 strcpy (try, multilib_dir);
4042 strcat (try, dir_separator_str);
4045 newname = find_a_file (&startfile_prefixes, try, R_OK);
4047 /* If we don't find it in the multi library dir, then fall
4048 through and look for it in the normal places. */
4049 if (newname != NULL)
4053 newname = find_a_file (&startfile_prefixes, name, R_OK);
4054 return newname ? newname : name;
4057 /* Determine whether a directory exists. If LINKER, return 0 for
4058 certain fixed names not needed by the linker. If not LINKER, it is
4059 only important to return 0 if the host machine has a small ARG_MAX
4063 is_directory (path1, path2, linker)
4068 int len1 = strlen (path1);
4069 int len2 = strlen (path2);
4070 char *path = (char *) alloca (3 + len1 + len2);
4074 #ifndef SMALL_ARG_MAX
4079 /* Construct the path from the two parts. Ensure the string ends with "/.".
4080 The resulting path will be a directory even if the given path is a
4082 bcopy (path1, path, len1);
4083 bcopy (path2, path + len1, len2);
4084 cp = path + len1 + len2;
4085 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4086 *cp++ = DIR_SEPARATOR;
4090 /* Exclude directories that the linker is known to search. */
4093 && strcmp (path, concat (dir_separator_str, "lib",
4094 dir_separator_str, ".", NULL_PTR)) == 0)
4096 && strcmp (path, concat (dir_separator_str, "usr",
4097 dir_separator_str, "lib",
4098 dir_separator_str, ".", NULL_PTR)) == 0)))
4101 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4104 /* On fatal signals, delete all the temporary files. */
4107 fatal_error (signum)
4110 signal (signum, SIG_DFL);
4111 delete_failure_queue ();
4112 delete_temp_files ();
4113 /* Get the same signal again, this time not handled,
4114 so its normal effect occurs. */
4115 kill (getpid (), signum);
4126 int linker_was_run = 0;
4127 char *explicit_link_files;
4130 struct user_specs *uptr;
4132 p = argv[0] + strlen (argv[0]);
4133 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4136 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4137 signal (SIGINT, fatal_error);
4139 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4140 signal (SIGHUP, fatal_error);
4142 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4143 signal (SIGTERM, fatal_error);
4145 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4146 signal (SIGPIPE, fatal_error);
4150 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4152 obstack_init (&obstack);
4154 /* Build multilib_select, et. al from the separate lines that make up each
4155 multilib selection. */
4157 char **q = multilib_raw;
4160 obstack_init (&multilib_obstack);
4161 while ((p = *q++) != (char *) 0)
4162 obstack_grow (&multilib_obstack, p, strlen (p));
4164 obstack_1grow (&multilib_obstack, 0);
4165 multilib_select = obstack_finish (&multilib_obstack);
4167 q = multilib_matches_raw;
4168 while ((p = *q++) != (char *) 0)
4169 obstack_grow (&multilib_obstack, p, strlen (p));
4171 obstack_1grow (&multilib_obstack, 0);
4172 multilib_matches = obstack_finish (&multilib_obstack);
4176 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4180 obstack_1grow (&multilib_obstack, ' ');
4181 obstack_grow (&multilib_obstack,
4182 multilib_defaults_raw[i],
4183 strlen (multilib_defaults_raw[i]));
4187 obstack_1grow (&multilib_obstack, 0);
4188 multilib_defaults = obstack_finish (&multilib_obstack);
4191 /* Set up to remember the pathname of gcc and any options
4192 needed for collect. We use argv[0] instead of programname because
4193 we need the complete pathname. */
4194 obstack_init (&collect_obstack);
4195 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4196 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4197 putenv (obstack_finish (&collect_obstack));
4199 #ifdef INIT_ENVIRONMENT
4200 /* Set up any other necessary machine specific environment variables. */
4201 putenv (INIT_ENVIRONMENT);
4204 /* Choose directory for temp files. */
4206 temp_filename = choose_temp_base ();
4207 temp_filename_length = strlen (temp_filename);
4209 /* Make a table of what switches there are (switches, n_switches).
4210 Make a table of specified input files (infiles, n_infiles).
4211 Decode switches that are handled locally. */
4213 process_command (argc, argv);
4215 /* Initialize the vector of specs to just the default.
4216 This means one element containing 0s, as a terminator. */
4218 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4219 bcopy ((char *) default_compilers, (char *) compilers,
4220 sizeof default_compilers);
4221 n_compilers = n_default_compilers;
4223 /* Read specs from a file if there is one. */
4225 machine_suffix = concat (spec_machine, dir_separator_str,
4226 spec_version, dir_separator_str, NULL_PTR);
4227 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4229 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4230 /* Read the specs file unless it is a default one. */
4231 if (specs_file != 0 && strcmp (specs_file, "specs"))
4232 read_specs (specs_file);
4238 for (k = 0; k < sizeof (extra_specs) / sizeof (extra_specs[0]); k++)
4239 set_spec (extra_specs[k].name, extra_specs[k].spec);
4243 /* Process any user specified specs in the order given on the command
4245 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4247 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4248 read_specs (filename ? filename : uptr->filename);
4251 /* If not cross-compiling, look for startfiles in the standard places. */
4252 /* The fact that these are done here, after reading the specs file,
4253 means that it cannot be found in these directories.
4254 But that's okay. It should never be there anyway. */
4257 #ifdef MD_EXEC_PREFIX
4258 add_prefix (&exec_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4259 add_prefix (&startfile_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4262 #ifdef MD_STARTFILE_PREFIX
4263 add_prefix (&startfile_prefixes, md_startfile_prefix, 0, 0, NULL_PTR);
4266 #ifdef MD_STARTFILE_PREFIX_1
4267 add_prefix (&startfile_prefixes, md_startfile_prefix_1, 0, 0, NULL_PTR);
4270 /* If standard_startfile_prefix is relative, base it on
4271 standard_exec_prefix. This lets us move the installed tree
4272 as a unit. If GCC_EXEC_PREFIX is defined, base
4273 standard_startfile_prefix on that as well. */
4274 if (*standard_startfile_prefix == '/'
4275 || *standard_startfile_prefix == DIR_SEPARATOR)
4276 add_prefix (&startfile_prefixes, standard_startfile_prefix, 0, 0,
4280 if (gcc_exec_prefix)
4281 add_prefix (&startfile_prefixes,
4282 concat (gcc_exec_prefix, machine_suffix,
4283 standard_startfile_prefix, NULL_PTR),
4285 add_prefix (&startfile_prefixes,
4286 concat (standard_exec_prefix,
4288 standard_startfile_prefix, NULL_PTR),
4292 add_prefix (&startfile_prefixes, standard_startfile_prefix_1, 0, 0,
4294 add_prefix (&startfile_prefixes, standard_startfile_prefix_2, 0, 0,
4296 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4297 add_prefix (&startfile_prefixes, "./", 0, 1, NULL_PTR);
4302 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4303 add_prefix (&startfile_prefixes,
4304 concat (gcc_exec_prefix, machine_suffix,
4305 standard_startfile_prefix, NULL_PTR),
4309 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4310 if (gcc_exec_prefix)
4312 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4313 + strlen (spec_version)
4314 + strlen (spec_machine) + 3);
4315 strcpy (temp, gcc_exec_prefix);
4316 strcat (temp, spec_machine);
4317 strcat (temp, dir_separator_str);
4318 strcat (temp, spec_version);
4319 strcat (temp, dir_separator_str);
4320 gcc_exec_prefix = temp;
4323 /* Now we have the specs.
4324 Set the `valid' bits for switches that match anything in any spec. */
4326 validate_all_switches ();
4328 /* Now that we have the switches and the specs, set
4329 the subdirectory based on the options. */
4330 set_multilib_dir ();
4332 /* Warn about any switches that no pass was interested in. */
4334 for (i = 0; i < n_switches; i++)
4335 if (! switches[i].valid)
4336 error ("unrecognized option `-%s'", switches[i].part1);
4338 /* Obey some of the options. */
4340 if (print_search_dirs)
4342 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4343 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4344 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4348 if (print_file_name)
4350 printf ("%s\n", find_file (print_file_name));
4354 if (print_prog_name)
4356 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4357 printf ("%s\n", (newname ? newname : print_prog_name));
4361 if (print_multi_lib)
4363 print_multilib_info ();
4367 if (print_multi_directory)
4369 if (multilib_dir == NULL)
4372 printf ("%s\n", multilib_dir);
4378 if (! strcmp (version_string, compiler_version))
4379 fprintf (stderr, "gcc version %s\n", version_string);
4381 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4382 version_string, compiler_version);
4389 fatal ("No input files");
4391 /* Make a place to record the compiler output file names
4392 that correspond to the input files. */
4394 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4395 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4397 /* Record which files were specified explicitly as link input. */
4399 explicit_link_files = xmalloc (n_infiles);
4400 bzero (explicit_link_files, n_infiles);
4402 for (i = 0; i < n_infiles; i++)
4404 register struct compiler *cp = 0;
4405 int this_file_error = 0;
4407 /* Tell do_spec what to substitute for %i. */
4409 input_filename = infiles[i].name;
4410 input_filename_length = strlen (input_filename);
4411 input_file_number = i;
4413 /* Use the same thing in %o, unless cp->spec says otherwise. */
4415 outfiles[i] = input_filename;
4417 /* Figure out which compiler from the file's suffix. */
4419 cp = lookup_compiler (infiles[i].name, input_filename_length,
4420 infiles[i].language);
4424 /* Ok, we found an applicable compiler. Run its spec. */
4425 /* First say how much of input_filename to substitute for %b */
4429 if (cp->spec[0][0] == '#')
4430 error ("%s: %s compiler not installed on this system",
4431 input_filename, &cp->spec[0][1]);
4433 input_basename = input_filename;
4434 for (p = input_filename; *p; p++)
4435 if (*p == '/' || *p == DIR_SEPARATOR)
4436 input_basename = p + 1;
4438 /* Find a suffix starting with the last period,
4439 and set basename_length to exclude that suffix. */
4440 basename_length = strlen (input_basename);
4441 p = input_basename + basename_length;
4442 while (p != input_basename && *p != '.') --p;
4443 if (*p == '.' && p != input_basename)
4445 basename_length = p - input_basename;
4446 input_suffix = p + 1;
4452 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4454 len += strlen (cp->spec[j]);
4456 p = (char *) xmalloc (len + 1);
4459 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4462 strcpy (p + len, cp->spec[j]);
4463 len += strlen (cp->spec[j]);
4466 value = do_spec (p);
4469 this_file_error = 1;
4472 /* If this file's name does not contain a recognized suffix,
4473 record it as explicit linker input. */
4476 explicit_link_files[i] = 1;
4478 /* Clear the delete-on-failure queue, deleting the files in it
4479 if this compilation failed. */
4481 if (this_file_error)
4483 delete_failure_queue ();
4486 /* If this compilation succeeded, don't delete those files later. */
4487 clear_failure_queue ();
4490 /* Run ld to link all the compiler output files. */
4492 if (error_count == 0)
4494 int tmp = execution_count;
4498 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4500 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4501 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4503 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4505 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4506 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4509 for (i = 0; i < n_switches; i++)
4513 obstack_grow (&collect_obstack, " ", 1);
4516 obstack_grow (&collect_obstack, "-", 1);
4517 obstack_grow (&collect_obstack, switches[i].part1,
4518 strlen (switches[i].part1));
4520 for (args = switches[i].args; args && *args; args++)
4522 obstack_grow (&collect_obstack, " ", 1);
4523 obstack_grow (&collect_obstack, *args, strlen (*args));
4526 obstack_grow (&collect_obstack, "\0", 1);
4527 putenv (obstack_finish (&collect_obstack));
4529 value = do_spec (link_command_spec);
4532 linker_was_run = (tmp != execution_count);
4535 /* Warn if a -B option was specified but the prefix was never used. */
4536 unused_prefix_warnings (&exec_prefixes);
4537 unused_prefix_warnings (&startfile_prefixes);
4539 /* If options said don't run linker,
4540 complain about input files to be given to the linker. */
4542 if (! linker_was_run && error_count == 0)
4543 for (i = 0; i < n_infiles; i++)
4544 if (explicit_link_files[i])
4545 error ("%s: linker input file unused since linking not done",
4548 /* Delete some or all of the temporary files we made. */
4551 delete_failure_queue ();
4552 delete_temp_files ();
4554 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4559 /* Find the proper compilation spec for the file name NAME,
4560 whose length is LENGTH. LANGUAGE is the specified language,
4561 or 0 if none specified. */
4563 static struct compiler *
4564 lookup_compiler (name, length, language)
4569 struct compiler *cp;
4571 /* Look for the language, if one is spec'd. */
4574 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4578 if (cp->suffix[0] == '@'
4579 && !strcmp (cp->suffix + 1, language))
4583 error ("language %s not recognized", language);
4586 /* Look for a suffix. */
4587 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4589 if (/* The suffix `-' matches only the file name `-'. */
4590 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4592 (strlen (cp->suffix) < length
4593 /* See if the suffix matches the end of NAME. */
4595 && (!strcmp (cp->suffix,
4596 name + length - strlen (cp->suffix))
4597 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4598 && !strcasecmp (cp->suffix,
4599 name + length - strlen (cp->suffix)))))
4601 && !strcmp (cp->suffix,
4602 name + length - strlen (cp->suffix))))
4605 if (cp->spec[0][0] == '@')
4607 struct compiler *new;
4608 /* An alias entry maps a suffix to a language.
4609 Search for the language; pass 0 for NAME and LENGTH
4610 to avoid infinite recursion if language not found.
4611 Construct the new compiler spec. */
4612 language = cp->spec[0] + 1;
4613 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4614 new->suffix = cp->suffix;
4615 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4616 (char *) new->spec, sizeof new->spec);
4619 /* A non-alias entry: return it. */
4631 register char *value = (char *) malloc (size);
4633 fatal ("virtual memory exhausted");
4638 xrealloc (ptr, size)
4642 register char *value = (char *) realloc (ptr, size);
4644 fatal ("virtual memory exhausted");
4648 /* This function is based on the one in libiberty. */
4651 concat VPROTO((char *first, ...))
4653 register int length;
4654 register char *newstr;
4662 /* First compute the size of the result and get sufficient memory. */
4664 VA_START (args, first);
4666 first = va_arg (args, char *);
4674 length += strlen (arg);
4675 arg = va_arg (args, char *);
4678 newstr = (char *) xmalloc (length + 1);
4681 /* Now copy the individual pieces to the result string. */
4683 VA_START (args, first);
4685 first = va_arg (args, char *);
4694 arg = va_arg (args, char *);
4703 save_string (s, len)
4707 register char *result = xmalloc (len + 1);
4709 bcopy (s, result, len);
4715 pfatal_with_name (name)
4718 fatal ("%s: %s", name, my_strerror (errno));
4722 perror_with_name (name)
4725 error ("%s: %s", name, my_strerror (errno));
4729 pfatal_pexecute (errmsg_fmt, errmsg_arg)
4735 /* Space for trailing '\0' is in %s. */
4736 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
4737 sprintf (msg, errmsg_fmt, errmsg_arg);
4741 fatal ("%s: %s", errmsg_fmt, my_strerror (errno));
4744 /* More 'friendly' abort that prints the line and file.
4745 config.h can #define abort fancy_abort if you like that sort of thing. */
4750 fatal ("Internal gcc abort.");
4755 /* Output an error message and exit */
4758 fatal VPROTO((char *format, ...))
4765 VA_START (ap, format);
4768 format = va_arg (ap, char *);
4771 fprintf (stderr, "%s: ", programname);
4772 vfprintf (stderr, format, ap);
4774 fprintf (stderr, "\n");
4775 delete_temp_files ();
4780 error VPROTO((char *format, ...))
4787 VA_START (ap, format);
4790 format = va_arg (ap, char *);
4793 fprintf (stderr, "%s: ", programname);
4794 vfprintf (stderr, format, ap);
4797 fprintf (stderr, "\n");
4800 #else /* not HAVE_VPRINTF */
4803 fatal (msg, arg1, arg2)
4804 char *msg, *arg1, *arg2;
4806 error (msg, arg1, arg2);
4807 delete_temp_files ();
4812 error (msg, arg1, arg2)
4813 char *msg, *arg1, *arg2;
4815 fprintf (stderr, "%s: ", programname);
4816 fprintf (stderr, msg, arg1, arg2);
4817 fprintf (stderr, "\n");
4820 #endif /* not HAVE_VPRINTF */
4824 validate_all_switches ()
4826 struct compiler *comp;
4829 struct spec_list *spec;
4831 for (comp = compilers; comp->spec[0]; comp++)
4834 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
4838 if (c == '%' && *p == '{')
4839 /* We have a switch spec. */
4840 validate_switches (p + 1);
4844 /* look through the linked list of extra specs read from the specs file */
4845 for (spec = specs; spec ; spec = spec->next)
4849 if (c == '%' && *p == '{')
4850 /* We have a switch spec. */
4851 validate_switches (p + 1);
4854 p = link_command_spec;
4856 if (c == '%' && *p == '{')
4857 /* We have a switch spec. */
4858 validate_switches (p + 1);
4860 /* Now notice switches mentioned in the machine-specific specs. */
4864 if (c == '%' && *p == '{')
4865 /* We have a switch spec. */
4866 validate_switches (p + 1);
4870 if (c == '%' && *p == '{')
4871 /* We have a switch spec. */
4872 validate_switches (p + 1);
4876 if (c == '%' && *p == '{')
4877 /* We have a switch spec. */
4878 validate_switches (p + 1);
4880 p = signed_char_spec;
4882 if (c == '%' && *p == '{')
4883 /* We have a switch spec. */
4884 validate_switches (p + 1);
4888 if (c == '%' && *p == '{')
4889 /* We have a switch spec. */
4890 validate_switches (p + 1);
4894 if (c == '%' && *p == '{')
4895 /* We have a switch spec. */
4896 validate_switches (p + 1);
4900 if (c == '%' && *p == '{')
4901 /* We have a switch spec. */
4902 validate_switches (p + 1);
4906 if (c == '%' && *p == '{')
4907 /* We have a switch spec. */
4908 validate_switches (p + 1);
4912 if (c == '%' && *p == '{')
4913 /* We have a switch spec. */
4914 validate_switches (p + 1);
4918 if (c == '%' && *p == '{')
4919 /* We have a switch spec. */
4920 validate_switches (p + 1);
4925 for (i = 0; i < sizeof (extra_specs) / sizeof (extra_specs[0]); i++)
4927 p = extra_specs[i].spec;
4929 if (c == '%' && *p == '{')
4930 /* We have a switch spec. */
4931 validate_switches (p + 1);
4938 /* Look at the switch-name that comes after START
4939 and mark as valid all supplied switches that match it. */
4942 validate_switches (start)
4945 register char *p = start;
4960 while (*p != ':' && *p != '}') p++;
4964 else if (p[-1] == '*')
4966 /* Mark all matching switches as valid. */
4968 for (i = 0; i < n_switches; i++)
4969 if (!strncmp (switches[i].part1, filter, p - filter))
4970 switches[i].valid = 1;
4974 /* Mark an exact matching switch as valid. */
4975 for (i = 0; i < n_switches; i++)
4977 if (!strncmp (switches[i].part1, filter, p - filter)
4978 && switches[i].part1[p - filter] == 0)
4979 switches[i].valid = 1;
4984 /* Check whether a particular argument was used. The first time we
4985 canonialize the switches to keep only the ones we care about. */
4999 static struct mswitchstr *mswitches;
5000 static int n_mswitches;
5005 struct mswitchstr *matches;
5009 /* Break multilib_matches into the component strings of string and replacement
5011 for (q = multilib_matches; *q != '\0'; q++)
5015 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5017 q = multilib_matches;
5028 matches[i].len = q - matches[i].str;
5030 matches[i].replace = ++q;
5031 while (*q != ';' && *q != '\0')
5037 matches[i].rep_len = q - matches[i].replace;
5045 /* Now build a list of the replacement string for switches that we care
5046 about. Make sure we allocate at least one entry. This prevents
5047 xmalloc from calling fatal, and prevents us from re-executing this
5050 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5051 * (n_switches ? n_switches : 1));
5052 for (i = 0; i < n_switches; i++)
5054 int xlen = strlen (switches[i].part1);
5055 for (j = 0; j < cnt; j++)
5056 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5058 mswitches[n_mswitches].str = matches[j].replace;
5059 mswitches[n_mswitches].len = matches[j].rep_len;
5060 mswitches[n_mswitches].replace = (char *)0;
5061 mswitches[n_mswitches].rep_len = 0;
5068 for (i = 0; i < n_mswitches; i++)
5069 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5076 default_arg (p, len)
5083 for (start = multilib_defaults; *start != '\0'; start = end+1)
5085 while (*start == ' ' || *start == '\t')
5091 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5094 if ((end - start) == len && strncmp (p, start, len) == 0)
5101 /* Work out the subdirectory to use based on the
5102 options. The format of multilib_select is a list of elements.
5103 Each element is a subdirectory name followed by a list of options
5104 followed by a semicolon. gcc will consider each line in turn. If
5105 none of the options beginning with an exclamation point are
5106 present, and all of the other options are present, that
5107 subdirectory will be used. */
5112 char *p = multilib_select;
5114 char *this_path, *this_arg;
5120 /* Ignore newlines. */
5127 /* Get the initial path. */
5135 this_path_len = p - this_path;
5137 /* Check the arguments. */
5152 while (*p != ' ' && *p != ';')
5159 if (*this_arg != '!')
5167 /* If this is a default argument, we can just ignore it.
5168 This is true even if this_arg begins with '!'. Beginning
5169 with '!' does not mean that this argument is necessarily
5170 inappropriate for this library: it merely means that
5171 there is a more specific library which uses this
5172 argument. If this argument is a default, we need not
5173 consider that more specific library. */
5174 if (! default_arg (this_arg, p - this_arg))
5176 ok = used_arg (this_arg, p - this_arg);
5187 if (this_path_len != 1
5188 || this_path[0] != '.')
5190 multilib_dir = xmalloc (this_path_len + 1);
5191 strncpy (multilib_dir, this_path, this_path_len);
5192 multilib_dir[this_path_len] = '\0';
5201 /* Print out the multiple library subdirectory selection
5202 information. This prints out a series of lines. Each line looks
5203 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5204 required. Only the desired options are printed out, the negative
5205 matches. The options are print without a leading dash. There are
5206 no spaces to make it easy to use the information in the shell.
5207 Each subdirectory is printed only once. This assumes the ordering
5208 generated by the genmultilib script. */
5211 print_multilib_info ()
5213 char *p = multilib_select;
5214 char *last_path = 0, *this_path;
5216 int last_path_len = 0;
5220 /* Ignore newlines. */
5227 /* Get the initial path. */
5236 /* If this is a duplicate, skip it. */
5237 skip = (last_path != 0 && p - this_path == last_path_len
5238 && ! strncmp (last_path, this_path, last_path_len));
5240 last_path = this_path;
5241 last_path_len = p - this_path;
5243 /* If this directory requires any default arguments, we can skip
5244 it. We will already have printed a directory identical to
5245 this one which does not require that default argument. */
5263 while (*q != ' ' && *q != ';')
5271 && default_arg (arg, q - arg))
5286 for (p1 = last_path; p1 < p; p1++)
5305 use_arg = *p != '!';
5310 while (*p != ' ' && *p != ';')
5325 /* If there are extra options, print them now */
5326 if (multilib_extra && *multilib_extra)
5328 int print_at = TRUE;
5331 for (q = multilib_extra; *q != '\0'; q++)