1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-97, 1998 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". */
45 #include "gansidecl.h"
49 /* ??? Need to find a GCC header to put these in. */
50 extern int pexecute PROTO ((const char *, char * const *, const char *,
51 const char *, char **, char **, int));
52 extern int pwait PROTO ((int, int *, int));
53 extern char *update_path PROTO((char *, char *));
54 extern void set_std_prefix PROTO((char *, int));
55 /* Flag arguments to pexecute. */
56 #define PEXECUTE_FIRST 1
57 #define PEXECUTE_LAST 2
58 #define PEXECUTE_SEARCH 4
59 #define PEXECUTE_VERBOSE 8
62 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
65 #define WTERMSIG(S) ((S) & 0x7f)
68 #define WIFEXITED(S) (((S) & 0xff) == 0)
71 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
75 #define exit __posix_exit
82 /* Test if something is a normal file. */
84 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
87 /* Test if something is a directory. */
89 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
92 /* By default there is no special suffix for executables. */
93 #ifdef EXECUTABLE_SUFFIX
94 #define HAVE_EXECUTABLE_SUFFIX
96 #define EXECUTABLE_SUFFIX ""
99 /* By default, the suffix for object files is ".o". */
101 #define HAVE_OBJECT_SUFFIX
103 #define OBJECT_SUFFIX ".o"
106 /* By default, colon separates directories in a path. */
107 #ifndef PATH_SEPARATOR
108 #define PATH_SEPARATOR ':'
111 #ifndef DIR_SEPARATOR
112 #define DIR_SEPARATOR '/'
115 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
117 #define obstack_chunk_alloc xmalloc
118 #define obstack_chunk_free free
120 #ifndef GET_ENVIRONMENT
121 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
124 extern char *my_strerror PROTO((int));
127 #define kill(p,s) raise(s)
130 /* If a stage of compilation returns an exit status >= 1,
131 compilation of that file ceases. */
133 #define MIN_FATAL_STATUS 1
135 /* Flag saying to print the directories gcc will search through looking for
136 programs, libraries, etc. */
138 static int print_search_dirs;
140 /* Flag saying to print the full filename of this file
141 as found through our usual search mechanism. */
143 static char *print_file_name = NULL;
145 /* As print_file_name, but search for executable file. */
147 static char *print_prog_name = NULL;
149 /* Flag saying to print the relative path we'd use to
150 find libgcc.a given the current compiler flags. */
152 static int print_multi_directory;
154 /* Flag saying to print the list of subdirectories and
155 compiler flags used to select them in a standard form. */
157 static int print_multi_lib;
159 /* Flag saying to print the command line options understood by gcc and its
162 static int print_help_list;
164 /* Flag indicating whether we should print the command and arguments */
166 static int verbose_flag;
168 /* Nonzero means write "temp" files in source directory
169 and use the source file's name in them, and don't delete them. */
171 static int save_temps_flag;
173 /* The compiler version. */
175 static char *compiler_version;
177 /* The target version specified with -V */
179 static char *spec_version = DEFAULT_TARGET_VERSION;
181 /* The target machine specified with -b. */
183 static char *spec_machine = DEFAULT_TARGET_MACHINE;
185 /* Nonzero if cross-compiling.
186 When -b is used, the value comes from the `specs' file. */
189 static char *cross_compile = "1";
191 static char *cross_compile = "0";
194 /* The number of errors that have occurred; the link phase will not be
195 run if this is non-zero. */
196 static int error_count = 0;
198 /* This is the obstack which we use to allocate many strings. */
200 static struct obstack obstack;
202 /* This is the obstack to build an environment variable to pass to
203 collect2 that describes all of the relevant switches of what to
204 pass the compiler in building the list of pointers to constructors
207 static struct obstack collect_obstack;
209 extern char *version_string;
211 /* Forward declaration for prototypes. */
214 static void init_spec PROTO((void));
215 static void read_specs PROTO((char *, int));
216 static void set_spec PROTO((char *, char *));
217 static struct compiler *lookup_compiler PROTO((char *, size_t, char *));
218 static char *build_search_list PROTO((struct path_prefix *, char *, int));
219 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
220 static char *find_a_file PROTO((struct path_prefix *, char *, int));
221 static void add_prefix PROTO((struct path_prefix *, char *, char *,
223 static char *skip_whitespace PROTO((char *));
224 static void record_temp_file PROTO((char *, int, int));
225 static void delete_if_ordinary PROTO((char *));
226 static void delete_temp_files PROTO((void));
227 static void delete_failure_queue PROTO((void));
228 static void clear_failure_queue PROTO((void));
229 static int check_live_switch PROTO((int, int));
230 static char *handle_braces PROTO((char *));
231 static char *save_string PROTO((char *, int));
232 static char *concat PVPROTO((char *, ...));
233 extern int do_spec PROTO((char *));
234 static int do_spec_1 PROTO((char *, int, char *));
235 static char *find_file PROTO((char *));
236 static int is_directory PROTO((char *, char *, int));
237 static void validate_switches PROTO((char *));
238 static void validate_all_switches PROTO((void));
239 static void give_switch PROTO((int, int, int));
240 static int used_arg PROTO((char *, int));
241 static int default_arg PROTO((char *, int));
242 static void set_multilib_dir PROTO((void));
243 static void print_multilib_info PROTO((void));
244 static void pfatal_with_name PROTO((char *));
245 static void perror_with_name PROTO((char *));
246 static void pfatal_pexecute PROTO((char *, char *));
247 static void fatal PVPROTO((char *, ...));
248 static void error PVPROTO((char *, ...));
249 static void display_help PROTO((void));
255 #ifdef LANG_SPECIFIC_DRIVER
256 /* Called before processing to change/add/remove arguments. */
257 extern void lang_specific_driver PROTO ((void (*) PVPROTO((char *, ...)), int *, char ***, int *));
259 /* Called before linking. Returns 0 on success and -1 on failure. */
260 extern int lang_specific_pre_link ();
262 /* Number of extra output files that lang_specific_pre_link may generate. */
263 extern int lang_specific_extra_outfiles;
266 /* Specs are strings containing lines, each of which (if not blank)
267 is made up of a program name, and arguments separated by spaces.
268 The program name must be exact and start from root, since no path
269 is searched and it is unreliable to depend on the current working directory.
270 Redirection of input or output is not supported; the subprograms must
271 accept filenames saying what files to read and write.
273 In addition, the specs can contain %-sequences to substitute variable text
274 or for conditional text. Here is a table of all defined %-sequences.
275 Note that spaces are not generated automatically around the results of
276 expanding these sequences; therefore, you can concatenate them together
277 or with constant text in a single argument.
279 %% substitute one % into the program name or argument.
280 %i substitute the name of the input file being processed.
281 %b substitute the basename of the input file being processed.
282 This is the substring up to (and not including) the last period
283 and not including the directory.
284 %g substitute the temporary-file-name-base. This is a string chosen
285 once per compilation. Different temporary file names are made by
286 concatenation of constant strings on the end, as in `%g.s'.
287 %g also has the same effect of %d.
288 %u like %g, but make the temporary file name unique.
289 %U returns the last file name generated with %u.
290 %d marks the argument containing or following the %d as a
291 temporary file name, so that that file will be deleted if CC exits
292 successfully. Unlike %g, this contributes no text to the argument.
293 %w marks the argument containing or following the %w as the
294 "output file" of this compilation. This puts the argument
295 into the sequence of arguments that %o will substitute later.
297 like %{...} but mark last argument supplied within
298 as a file to be deleted on failure.
299 %o substitutes the names of all the output files, with spaces
300 automatically placed around them. You should write spaces
301 around the %o as well or the results are undefined.
302 %o is for use in the specs for running the linker.
303 Input files whose names have no recognized suffix are not compiled
304 at all, but they are included among the output files, so they will
306 %O substitutes the suffix for object files.
307 %p substitutes the standard macro predefinitions for the
308 current target machine. Use this when running cpp.
309 %P like %p, but puts `__' before and after the name of each macro.
310 (Except macros that already have __.)
312 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
313 %s current argument is the name of a library or startup file of some sort.
314 Search for that file in a standard list of directories
315 and substitute the full name found.
316 %eSTR Print STR as an error message. STR is terminated by a newline.
317 Use this when inconsistent options are detected.
318 %x{OPTION} Accumulate an option for %X.
319 %X Output the accumulated linker options specified by compilations.
320 %Y Output the accumulated assembler options specified by compilations.
321 %Z Output the accumulated preprocessor options specified by compilations.
322 %v1 Substitute the major version number of GCC.
323 (For version 2.5.n, this is 2.)
324 %v2 Substitute the minor version number of GCC.
325 (For version 2.5.n, this is 5.)
326 %a process ASM_SPEC as a spec.
327 This allows config.h to specify part of the spec for running as.
328 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
329 used here. This can be used to run a post-processor after the
330 assembler has done its job.
331 %D Dump out a -L option for each directory in startfile_prefixes.
332 If multilib_dir is set, extra entries are generated with it affixed.
333 %l process LINK_SPEC as a spec.
334 %L process LIB_SPEC as a spec.
335 %G process LIBGCC_SPEC as a spec.
336 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
337 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
338 %c process SIGNED_CHAR_SPEC as a spec.
339 %C process CPP_SPEC as a spec. A capital C is actually used here.
340 %1 process CC1_SPEC as a spec.
341 %2 process CC1PLUS_SPEC as a spec.
342 %| output "-" if the input for the current command is coming from a pipe.
343 %* substitute the variable part of a matched option. (See below.)
344 Note that each comma in the substituted string is replaced by
346 %{S} substitutes the -S switch, if that switch was given to CC.
347 If that switch was not specified, this substitutes nothing.
348 Here S is a metasyntactic variable.
349 %{S*} substitutes all the switches specified to CC whose names start
350 with -S. This is used for -o, -D, -I, etc; switches that take
351 arguments. CC considers `-o foo' as being one switch whose
352 name starts with `o'. %{o*} would substitute this text,
353 including the space; thus, two arguments would be generated.
354 %{^S*} likewise, but don't put a blank between a switch and any args.
355 %{S*:X} substitutes X if one or more switches whose names start with -S are
356 specified to CC. Note that the tail part of the -S option
357 (i.e. the part matched by the `*') will be substituted for each
358 occurrence of %* within X.
359 %{S:X} substitutes X, but only if the -S switch was given to CC.
360 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
361 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
362 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
363 %{.S:X} substitutes X, but only if processing a file with suffix S.
364 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
365 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
366 combined with ! and . as above binding stronger than the OR.
367 %(Spec) processes a specification defined in a specs file as *Spec:
368 %[Spec] as above, but put __ around -D arguments
370 The conditional text X in a %{S:X} or %{!S:X} construct may contain
371 other nested % constructs or spaces, or even newlines. They are
372 processed as usual, as described above.
374 The -O, -f, -m, and -W switches are handled specifically in these
375 constructs. If another value of -O or the negated form of a -f, -m, or
376 -W switch is found later in the command line, the earlier switch
377 value is ignored, except with {S*} where S is just one letter; this
378 passes all matching options.
380 The character | at the beginning of the predicate text is used to indicate
381 that a command should be piped to the following command, but only if -pipe
384 Note that it is built into CC which switches take arguments and which
385 do not. You might think it would be useful to generalize this to
386 allow each compiler's spec to say which switches take arguments. But
387 this cannot be done in a consistent fashion. CC cannot even decide
388 which input files have been specified without knowing which switches
389 take arguments, and it must know which input files to compile in order
390 to tell which compilers to run.
392 CC also knows implicitly that arguments starting in `-l' are to be
393 treated as compiler output files, and passed to the linker in their
394 proper position among the other output files. */
396 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
398 /* config.h can define ASM_SPEC to provide extra args to the assembler
399 or extra switch-translations. */
404 /* config.h can define ASM_FINAL_SPEC to run a post processor after
405 the assembler has run. */
406 #ifndef ASM_FINAL_SPEC
407 #define ASM_FINAL_SPEC ""
410 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
411 or extra switch-translations. */
416 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
417 or extra switch-translations. */
422 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
423 or extra switch-translations. */
425 #define CC1PLUS_SPEC ""
428 /* config.h can define LINK_SPEC to provide extra args to the linker
429 or extra switch-translations. */
434 /* config.h can define LIB_SPEC to override the default libraries. */
436 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
439 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
442 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
443 /* Have gcc do the search for libgcc.a. */
444 #define LIBGCC_SPEC "libgcc.a%s"
446 #define LIBGCC_SPEC "-lgcc"
450 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
451 #ifndef STARTFILE_SPEC
452 #define STARTFILE_SPEC \
453 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
456 /* config.h can define SWITCHES_NEED_SPACES to control which options
457 require spaces between the option and the argument. */
458 #ifndef SWITCHES_NEED_SPACES
459 #define SWITCHES_NEED_SPACES ""
462 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
464 #define ENDFILE_SPEC ""
467 /* This spec is used for telling cpp whether char is signed or not. */
468 #ifndef SIGNED_CHAR_SPEC
469 /* Use #if rather than ?:
470 because MIPS C compiler rejects like ?: in initializers. */
471 #if DEFAULT_SIGNED_CHAR
472 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
474 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
479 #define LINKER_NAME "collect2"
482 static char *cpp_spec = CPP_SPEC;
483 static char *cpp_predefines = CPP_PREDEFINES;
484 static char *cc1_spec = CC1_SPEC;
485 static char *cc1plus_spec = CC1PLUS_SPEC;
486 static char *signed_char_spec = SIGNED_CHAR_SPEC;
487 static char *asm_spec = ASM_SPEC;
488 static char *asm_final_spec = ASM_FINAL_SPEC;
489 static char *link_spec = LINK_SPEC;
490 static char *lib_spec = LIB_SPEC;
491 static char *libgcc_spec = LIBGCC_SPEC;
492 static char *endfile_spec = ENDFILE_SPEC;
493 static char *startfile_spec = STARTFILE_SPEC;
494 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
495 static char *linker_name_spec = LINKER_NAME;
497 /* Some compilers have limits on line lengths, and the multilib_select
498 and/or multilib_matches strings can be very long, so we build them at
500 static struct obstack multilib_obstack;
501 static char *multilib_select;
502 static char *multilib_matches;
503 static char *multilib_defaults;
504 #include "multilib.h"
506 /* Check whether a particular argument is a default argument. */
508 #ifndef MULTILIB_DEFAULTS
509 #define MULTILIB_DEFAULTS { "" }
512 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
515 struct user_specs *next;
519 static struct user_specs *user_specs_head, *user_specs_tail;
521 /* This defines which switch letters take arguments. */
523 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
524 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
525 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
526 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
527 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
528 || (CHAR) == 'B' || (CHAR) == 'b')
530 #ifndef SWITCH_TAKES_ARG
531 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
534 /* This defines which multi-letter switches take arguments. */
536 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
537 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
538 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
539 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
540 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
541 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
542 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
544 #ifndef WORD_SWITCH_TAKES_ARG
545 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
549 #ifdef HAVE_EXECUTABLE_SUFFIX
550 /* This defines which switches stop a full compilation. */
551 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
552 ((CHAR) == 'c' || (CHAR) == 'S')
554 #ifndef SWITCH_CURTAILS_COMPILATION
555 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
556 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
560 /* Record the mapping from file suffixes for compilation specs. */
564 char *suffix; /* Use this compiler for input files
565 whose names end in this suffix. */
567 char *spec[4]; /* To use this compiler, concatenate these
568 specs and pass to do_spec. */
571 /* Pointer to a vector of `struct compiler' that gives the spec for
572 compiling a file, based on its suffix.
573 A file that does not end in any of these suffixes will be passed
574 unchanged to the loader and nothing else will be done to it.
576 An entry containing two 0s is used to terminate the vector.
578 If multiple entries match a file, the last matching one is used. */
580 static struct compiler *compilers;
582 /* Number of entries in `compilers', not counting the null terminator. */
584 static int n_compilers;
586 /* The default list of file name suffixes and their compilation specs. */
588 static struct compiler default_compilers[] =
590 /* Add lists of suffixes of known languages here. If those languages
591 were not present when we built the driver, we will hit these copies
592 and be given a more meaningful error than "file not used since
593 linking is not done". */
594 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}}, {".c++", {"#C++"}},
595 {".C", {"#C++"}}, {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
596 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
597 {".fpp", {"#Fortran"}},
598 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
599 /* Next come the entries for C. */
604 "%{E|M|MM:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
605 %{C:%{!E:%eGNU C does not support -C without using -E}}\
606 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
607 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
608 %{ansi:-trigraphs -D__STRICT_ANSI__}\
609 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
610 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
611 %{traditional} %{ftraditional:-traditional}\
612 %{traditional-cpp:-traditional}\
613 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
614 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
615 %{!E:%{!M:%{!MM:cc1 %i %1 \
616 -lang-c%{ansi:89} %{nostdinc*} %{A*} %{I*} %I\
617 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
618 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
619 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
620 %{ansi:-trigraphs -D__STRICT_ANSI__}\
621 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
622 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
623 %{H} %C %{D*} %{U*} %{i*} %Z\
624 %{ftraditional:-traditional}\
625 %{traditional-cpp:-traditional}\
626 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
629 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
630 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
631 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
633 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
634 %{!pipe:%g.s} %A\n }}}}"
636 #else /* ! USE_CPPLIB */
637 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
638 %{C:%{!E:%eGNU C does not support -C without using -E}}\
639 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
640 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
641 %{ansi:-trigraphs -D__STRICT_ANSI__}\
642 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
643 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
644 %{traditional} %{ftraditional:-traditional}\
645 %{traditional-cpp:-traditional}\
646 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
647 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
648 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
649 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
650 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
651 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
654 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
655 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
657 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
658 %{!pipe:%g.s} %A\n }}}}"
660 #endif /* ! USE_CPPLIB */
662 {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
663 %{C:%{!E:%eGNU C does not support -C without using -E}}\
664 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
665 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
666 %{ansi:-trigraphs -D__STRICT_ANSI__}\
667 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
668 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
669 %{traditional} %{ftraditional:-traditional}\
670 %{traditional-cpp:-traditional}\
671 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
673 %{!E:%e-E required when input is from standard input}"}},
674 {".m", {"@objective-c"}},
676 {"cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
677 %{C:%{!E:%eGNU C does not support -C without using -E}}\
678 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
679 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
680 %{ansi:-trigraphs -D__STRICT_ANSI__}\
681 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
682 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
683 %{traditional} %{ftraditional:-traditional}\
684 %{traditional-cpp:-traditional}\
685 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
686 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
687 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
688 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
689 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
690 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
691 -lang-objc %{gen-decls} \
693 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
694 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
696 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
697 %{!pipe:%g.s} %A\n }}}}"}},
698 {".h", {"@c-header"}},
700 {"%{!E:%eCompilation of header file requested} \
701 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
702 %{C:%{!E:%eGNU C does not support -C without using -E}}\
703 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
704 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
705 %{ansi:-trigraphs -D__STRICT_ANSI__}\
706 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
707 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
708 %{traditional} %{ftraditional:-traditional}\
709 %{traditional-cpp:-traditional}\
710 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
712 {".i", {"@cpp-output"}},
714 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
715 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
716 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
718 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
719 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
721 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
722 %{!pipe:%g.s} %A\n }}}}"}},
723 {".s", {"@assembler"}},
725 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
726 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
728 {".S", {"@assembler-with-cpp"}},
729 {"@assembler-with-cpp",
730 {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
731 %{C:%{!E:%eGNU C does not support -C without using -E}}\
732 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
733 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
734 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
735 %{traditional} %{ftraditional:-traditional}\
736 %{traditional-cpp:-traditional}\
737 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
738 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
739 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
740 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
741 %{!pipe:%g.s} %A\n }}}}"}},
743 /* Mark end of table */
747 /* Number of elements in default_compilers, not counting the terminator. */
749 static int n_default_compilers
750 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
752 /* Here is the spec for running the linker, after compiling all files. */
754 /* -u* was put back because both BSD and SysV seem to support it. */
755 /* %{static:} simply prevents an error message if the target machine
756 doesn't handle -static. */
757 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
758 scripts which exist in user specified directories, or in standard
760 #ifdef LINK_COMMAND_SPEC
761 /* Provide option to override link_command_spec from machine specific
762 configuration files. */
763 static char *link_command_spec =
766 #ifdef LINK_LIBGCC_SPECIAL
767 /* Don't generate -L options. */
768 static char *link_command_spec = "\
770 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
771 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
772 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
774 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
775 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
780 static char *link_command_spec = "\
782 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
783 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
784 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
785 %{static:} %{L*} %D %o\
786 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
787 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
793 /* A vector of options to give to the linker.
794 These options are accumulated by %x,
795 and substituted into the linker command with %X. */
796 static int n_linker_options;
797 static char **linker_options;
799 /* A vector of options to give to the assembler.
800 These options are accumulated by -Wa,
801 and substituted into the assembler command with %Y. */
802 static int n_assembler_options;
803 static char **assembler_options;
805 /* A vector of options to give to the preprocessor.
806 These options are accumulated by -Wp,
807 and substituted into the preprocessor command with %Z. */
808 static int n_preprocessor_options;
809 static char **preprocessor_options;
811 /* Define how to map long options into short ones. */
813 /* This structure describes one mapping. */
816 /* The long option's name. */
818 /* The equivalent short option. */
820 /* Argument info. A string of flag chars; NULL equals no options.
821 a => argument required.
822 o => argument optional.
823 j => join argument to equivalent, making one word.
824 * => require other text after NAME as an argument. */
828 /* This is the table of mappings. Mappings are tried sequentially
829 for each option encountered; the first one that matches, wins. */
831 struct option_map option_map[] =
833 {"--all-warnings", "-Wall", 0},
834 {"--ansi", "-ansi", 0},
835 {"--assemble", "-S", 0},
836 {"--assert", "-A", "a"},
837 {"--comments", "-C", 0},
838 {"--compile", "-c", 0},
839 {"--debug", "-g", "oj"},
840 {"--define-macro", "-D", "aj"},
841 {"--dependencies", "-M", 0},
842 {"--dump", "-d", "a"},
843 {"--dumpbase", "-dumpbase", "a"},
844 {"--entry", "-e", 0},
845 {"--extra-warnings", "-W", 0},
846 {"--for-assembler", "-Wa", "a"},
847 {"--for-linker", "-Xlinker", "a"},
848 {"--force-link", "-u", "a"},
849 {"--imacros", "-imacros", "a"},
850 {"--include", "-include", "a"},
851 {"--include-barrier", "-I-", 0},
852 {"--include-directory", "-I", "aj"},
853 {"--include-directory-after", "-idirafter", "a"},
854 {"--include-prefix", "-iprefix", "a"},
855 {"--include-with-prefix", "-iwithprefix", "a"},
856 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
857 {"--include-with-prefix-after", "-iwithprefix", "a"},
858 {"--language", "-x", "a"},
859 {"--library-directory", "-L", "a"},
860 {"--machine", "-m", "aj"},
861 {"--machine-", "-m", "*j"},
862 {"--no-line-commands", "-P", 0},
863 {"--no-precompiled-includes", "-noprecomp", 0},
864 {"--no-standard-includes", "-nostdinc", 0},
865 {"--no-standard-libraries", "-nostdlib", 0},
866 {"--no-warnings", "-w", 0},
867 {"--optimize", "-O", "oj"},
868 {"--output", "-o", "a"},
869 {"--pedantic", "-pedantic", 0},
870 {"--pedantic-errors", "-pedantic-errors", 0},
871 {"--pipe", "-pipe", 0},
872 {"--prefix", "-B", "a"},
873 {"--preprocess", "-E", 0},
874 {"--print-search-dirs", "-print-search-dirs", 0},
875 {"--print-file-name", "-print-file-name=", "aj"},
876 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
877 {"--print-missing-file-dependencies", "-MG", 0},
878 {"--print-multi-lib", "-print-multi-lib", 0},
879 {"--print-multi-directory", "-print-multi-directory", 0},
880 {"--print-prog-name", "-print-prog-name=", "aj"},
881 {"--profile", "-p", 0},
882 {"--profile-blocks", "-a", 0},
883 {"--quiet", "-q", 0},
884 {"--save-temps", "-save-temps", 0},
885 {"--shared", "-shared", 0},
886 {"--silent", "-q", 0},
887 {"--specs", "-specs=", "aj"},
888 {"--static", "-static", 0},
889 {"--symbolic", "-symbolic", 0},
890 {"--target", "-b", "a"},
891 {"--trace-includes", "-H", 0},
892 {"--traditional", "-traditional", 0},
893 {"--traditional-cpp", "-traditional-cpp", 0},
894 {"--trigraphs", "-trigraphs", 0},
895 {"--undefine-macro", "-U", "aj"},
896 {"--use-version", "-V", "a"},
897 {"--user-dependencies", "-MM", 0},
898 {"--verbose", "-v", 0},
899 {"--version", "-dumpversion", 0},
900 {"--warn-", "-W", "*j"},
901 {"--write-dependencies", "-MD", 0},
902 {"--write-user-dependencies", "-MMD", 0},
906 /* Translate the options described by *ARGCP and *ARGVP.
907 Make a new vector and store it back in *ARGVP,
908 and store its length in *ARGVC. */
911 translate_options (argcp, argvp)
917 char **argv = *argvp;
918 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
922 newv[newindex++] = argv[i++];
926 /* Translate -- options. */
927 if (argv[i][0] == '-' && argv[i][1] == '-')
929 /* Find a mapping that applies to this option. */
930 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
932 size_t optlen = strlen (option_map[j].name);
933 size_t arglen = strlen (argv[i]);
934 size_t complen = arglen > optlen ? optlen : arglen;
935 char *arginfo = option_map[j].arg_info;
940 if (!strncmp (argv[i], option_map[j].name, complen))
947 k < sizeof (option_map) / sizeof (option_map[0]);
949 if (strlen (option_map[k].name) >= arglen
950 && !strncmp (argv[i], option_map[k].name, arglen))
952 error ("Ambiguous abbreviation %s", argv[i]);
956 if (k != sizeof (option_map) / sizeof (option_map[0]))
962 /* If the option has an argument, accept that. */
963 if (argv[i][optlen] == '=')
964 arg = argv[i] + optlen + 1;
966 /* If this mapping requires extra text at end of name,
967 accept that as "argument". */
968 else if (index (arginfo, '*') != 0)
969 arg = argv[i] + optlen;
971 /* Otherwise, extra text at end means mismatch.
972 Try other mappings. */
977 else if (index (arginfo, '*') != 0)
979 error ("Incomplete `%s' option", option_map[j].name);
983 /* Handle arguments. */
984 if (index (arginfo, 'a') != 0)
990 error ("Missing argument to `%s' option",
998 else if (index (arginfo, '*') != 0)
1000 else if (index (arginfo, 'o') == 0)
1003 error ("Extraneous argument to `%s' option",
1004 option_map[j].name);
1008 /* Store the translation as one argv elt or as two. */
1009 if (arg != 0 && index (arginfo, 'j') != 0)
1010 newv[newindex++] = concat (option_map[j].equivalent, arg,
1014 newv[newindex++] = option_map[j].equivalent;
1015 newv[newindex++] = arg;
1018 newv[newindex++] = option_map[j].equivalent;
1026 /* Handle old-fashioned options--just copy them through,
1027 with their arguments. */
1028 else if (argv[i][0] == '-')
1030 char *p = argv[i] + 1;
1034 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1035 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1036 else if (WORD_SWITCH_TAKES_ARG (p))
1037 nskip += WORD_SWITCH_TAKES_ARG (p);
1038 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1041 else if (! strcmp (p, "Xlinker"))
1044 /* Watch out for an option at the end of the command line that
1045 is missing arguments, and avoid skipping past the end of the
1047 if (nskip + i > argc)
1052 newv[newindex++] = argv[i++];
1057 /* Ordinary operands, or +e options. */
1058 newv[newindex++] = argv[i++];
1071 #ifdef HAVE_STRERROR
1077 static char buffer[30];
1079 return "cannot access";
1081 if (e > 0 && e < sys_nerr)
1082 return sys_errlist[e];
1084 sprintf (buffer, "Unknown error %d", e);
1095 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1096 be considered whitespace. */
1097 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1099 else if (*p == '\n' || *p == ' ' || *p == '\t')
1103 while (*p != '\n') p++;
1113 /* Structure to keep track of the specs that have been defined so far.
1114 These are accessed using %(specname) or %[specname] in a compiler
1119 /* The following 2 fields must be first */
1120 /* to allow EXTRA_SPECS to be initialized */
1121 char *name; /* name of the spec. */
1122 char *ptr; /* available ptr if no static pointer */
1124 /* The following fields are not initialized */
1125 /* by EXTRA_SPECS */
1126 char **ptr_spec; /* pointer to the spec itself. */
1127 struct spec_list *next; /* Next spec in linked list. */
1128 int name_len; /* length of the name */
1129 int alloc_p; /* whether string was allocated */
1132 #define INIT_STATIC_SPEC(NAME,PTR) \
1133 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1135 /* List of statically defined specs */
1136 static struct spec_list static_specs[] = {
1137 INIT_STATIC_SPEC ("asm", &asm_spec),
1138 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1139 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1140 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1141 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1142 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1143 INIT_STATIC_SPEC ("link", &link_spec),
1144 INIT_STATIC_SPEC ("lib", &lib_spec),
1145 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1146 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1147 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1148 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1149 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1150 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1151 INIT_STATIC_SPEC ("version", &compiler_version),
1152 INIT_STATIC_SPEC ("multilib", &multilib_select),
1153 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1154 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1155 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1156 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1159 #ifdef EXTRA_SPECS /* additional specs needed */
1160 static struct spec_list extra_specs[] = { EXTRA_SPECS };
1163 /* List of dynamically allocates specs that have been defined so far. */
1165 static struct spec_list *specs = (struct spec_list *)0;
1168 /* Initialize the specs lookup routines. */
1173 struct spec_list *next = (struct spec_list *)0;
1174 struct spec_list *sl = (struct spec_list *)0;
1178 return; /* already initialized */
1181 fprintf (stderr, "Using builtin specs.\n");
1184 for (i = (sizeof (extra_specs) / sizeof (extra_specs[0])) - 1; i >= 0; i--)
1186 sl = &extra_specs[i];
1188 sl->name_len = strlen (sl->name);
1189 sl->ptr_spec = &sl->ptr;
1194 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1196 sl = &static_specs[i];
1205 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1206 removed; If the spec starts with a + then SPEC is added to the end of the
1210 set_spec (name, spec)
1214 struct spec_list *sl;
1216 int name_len = strlen (name);
1219 /* If this is the first call, initialize the statically allocated specs */
1222 struct spec_list *next = (struct spec_list *)0;
1223 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1226 sl = &static_specs[i];
1233 /* See if the spec already exists */
1234 for (sl = specs; sl; sl = sl->next)
1235 if (name_len == sl->name_len && !strcmp (sl->name, name))
1240 /* Not found - make it */
1241 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1242 sl->name = save_string (name, strlen (name));
1243 sl->name_len = name_len;
1244 sl->ptr_spec = &sl->ptr;
1246 *(sl->ptr_spec) = "";
1251 old_spec = *(sl->ptr_spec);
1252 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE (spec[1]))
1253 ? concat (old_spec, spec + 1, NULL_PTR)
1254 : save_string (spec, strlen (spec)));
1258 fprintf (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1261 /* Free the old spec */
1262 if (old_spec && sl->alloc_p)
1268 /* Accumulate a command (program name and args), and run it. */
1270 /* Vector of pointers to arguments in the current line of specifications. */
1272 static char **argbuf;
1274 /* Number of elements allocated in argbuf. */
1276 static int argbuf_length;
1278 /* Number of elements in argbuf currently in use (containing args). */
1280 static int argbuf_index;
1282 /* We want this on by default all the time now. */
1283 #define MKTEMP_EACH_FILE
1285 #ifdef MKTEMP_EACH_FILE
1287 extern char *make_temp_file PROTO((char *));
1289 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1292 static struct temp_name {
1293 char *suffix; /* suffix associated with the code. */
1294 int length; /* strlen (suffix). */
1295 int unique; /* Indicates whether %g or %u/%U was used. */
1296 char *filename; /* associated filename. */
1297 int filename_length; /* strlen (filename). */
1298 struct temp_name *next;
1301 extern char *choose_temp_base PROTO((void));
1305 /* Number of commands executed so far. */
1307 static int execution_count;
1309 /* Number of commands that exited with a signal. */
1311 static int signal_count;
1313 /* Name with which this program was invoked. */
1315 static char *programname;
1317 /* Structures to keep track of prefixes to try when looking for files. */
1321 char *prefix; /* String to prepend to the path. */
1322 struct prefix_list *next; /* Next in linked list. */
1323 int require_machine_suffix; /* Don't use without machine_suffix. */
1324 /* 2 means try both machine_suffix and just_machine_suffix. */
1325 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1330 struct prefix_list *plist; /* List of prefixes to try */
1331 int max_len; /* Max length of a prefix in PLIST */
1332 char *name; /* Name of this list (used in config stuff) */
1335 /* List of prefixes to try when looking for executables. */
1337 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1339 /* List of prefixes to try when looking for startup (crt0) files. */
1341 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1343 /* List of prefixes to try when looking for include files. */
1345 static struct path_prefix include_prefixes = { 0, 0, "include" };
1347 /* Suffix to attach to directories searched for commands.
1348 This looks like `MACHINE/VERSION/'. */
1350 static char *machine_suffix = 0;
1352 /* Suffix to attach to directories searched for commands.
1353 This is just `MACHINE/'. */
1355 static char *just_machine_suffix = 0;
1357 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1359 static char *gcc_exec_prefix;
1361 /* Default prefixes to attach to command names. */
1363 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1364 #undef MD_EXEC_PREFIX
1365 #undef MD_STARTFILE_PREFIX
1366 #undef MD_STARTFILE_PREFIX_1
1369 #ifndef STANDARD_EXEC_PREFIX
1370 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1371 #endif /* !defined STANDARD_EXEC_PREFIX */
1373 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1374 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1375 #ifdef MD_EXEC_PREFIX
1376 static char *md_exec_prefix = MD_EXEC_PREFIX;
1379 #ifndef STANDARD_STARTFILE_PREFIX
1380 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1381 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1383 #ifdef MD_STARTFILE_PREFIX
1384 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1386 #ifdef MD_STARTFILE_PREFIX_1
1387 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1389 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1390 static char *standard_startfile_prefix_1 = "/lib/";
1391 static char *standard_startfile_prefix_2 = "/usr/lib/";
1393 #ifndef TOOLDIR_BASE_PREFIX
1394 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1396 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1397 static char *tooldir_prefix;
1399 /* Subdirectory to use for locating libraries. Set by
1400 set_multilib_dir based on the compilation options. */
1402 static char *multilib_dir;
1404 /* Clear out the vector of arguments (after a command is executed). */
1412 /* Add one argument to the vector at the end.
1413 This is done when a space is seen or at the end of the line.
1414 If DELETE_ALWAYS is nonzero, the arg is a filename
1415 and the file should be deleted eventually.
1416 If DELETE_FAILURE is nonzero, the arg is a filename
1417 and the file should be deleted if this compilation fails. */
1420 store_arg (arg, delete_always, delete_failure)
1422 int delete_always, delete_failure;
1424 if (argbuf_index + 1 == argbuf_length)
1426 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1428 argbuf[argbuf_index++] = arg;
1429 argbuf[argbuf_index] = 0;
1431 if (delete_always || delete_failure)
1432 record_temp_file (arg, delete_always, delete_failure);
1435 /* Read compilation specs from a file named FILENAME,
1436 replacing the default ones.
1438 A suffix which starts with `*' is a definition for
1439 one of the machine-specific sub-specs. The "suffix" should be
1440 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1441 The corresponding spec is stored in asm_spec, etc.,
1442 rather than in the `compilers' vector.
1444 Anything invalid in the file is a fatal error. */
1447 read_specs (filename, main_p)
1453 struct stat statbuf;
1458 fprintf (stderr, "Reading specs from %s\n", filename);
1460 /* Open and stat the file. */
1461 desc = open (filename, O_RDONLY, 0);
1463 pfatal_with_name (filename);
1464 if (stat (filename, &statbuf) < 0)
1465 pfatal_with_name (filename);
1467 /* Read contents of file into BUFFER. */
1468 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1469 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1471 pfatal_with_name (filename);
1472 buffer[readlen] = 0;
1475 /* Scan BUFFER for specs, putting them in the vector. */
1481 char *in, *out, *p1, *p2, *p3;
1483 /* Advance P in BUFFER to the next nonblank nocomment line. */
1484 p = skip_whitespace (p);
1488 /* Is this a special command that starts with '%'? */
1489 /* Don't allow this for the main specs file, since it would
1490 encourage people to overwrite it. */
1491 if (*p == '%' && !main_p)
1494 while (*p && *p != '\n')
1497 p++; /* Skip '\n' */
1499 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1500 && (p1[sizeof "%include" - 1] == ' '
1501 || p1[sizeof "%include" - 1] == '\t'))
1505 p1 += sizeof ("%include");
1506 while (*p1 == ' ' || *p1 == '\t')
1509 if (*p1++ != '<' || p[-2] != '>')
1510 fatal ("specs %%include syntax malformed after %d characters",
1514 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1515 read_specs (new_filename ? new_filename : p1, FALSE);
1518 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1519 && (p1[sizeof "%include_noerr" - 1] == ' '
1520 || p1[sizeof "%include_noerr" - 1] == '\t'))
1524 p1 += sizeof "%include_noerr";
1525 while (*p1 == ' ' || *p1 == '\t') p1++;
1527 if (*p1++ != '<' || p[-2] != '>')
1528 fatal ("specs %%include syntax malformed after %d characters",
1532 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1534 read_specs (new_filename, FALSE);
1535 else if (verbose_flag)
1536 fprintf (stderr, "Could not find specs file %s\n", p1);
1539 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1540 && (p1[sizeof "%rename" - 1] == ' '
1541 || p1[sizeof "%rename" - 1] == '\t'))
1544 struct spec_list *sl;
1546 /* Get original name */
1547 p1 += sizeof "%rename";
1548 while (*p1 == ' ' || *p1 == '\t')
1551 if (! ISALPHA (*p1))
1552 fatal ("specs %%rename syntax malformed after %d characters",
1556 while (*p2 && !ISSPACE (*p2))
1559 if (*p2 != ' ' && *p2 != '\t')
1560 fatal ("specs %%rename syntax malformed after %d characters",
1565 while (*p2 == ' ' || *p2 == '\t')
1568 if (! ISALPHA (*p2))
1569 fatal ("specs %%rename syntax malformed after %d characters",
1572 /* Get new spec name */
1574 while (*p3 && !ISSPACE (*p3))
1578 fatal ("specs %%rename syntax malformed after %d characters",
1582 for (sl = specs; sl; sl = sl->next)
1583 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1587 fatal ("specs %s spec was not found to be renamed", p1);
1589 if (strcmp (p1, p2) == 0)
1594 fprintf (stderr, "rename spec %s to %s\n", p1, p2);
1596 fprintf (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
1600 set_spec (p2, *(sl->ptr_spec));
1602 free (*(sl->ptr_spec));
1604 *(sl->ptr_spec) = "";
1609 fatal ("specs unknown %% command after %d characters",
1613 /* Find the colon that should end the suffix. */
1615 while (*p1 && *p1 != ':' && *p1 != '\n')
1618 /* The colon shouldn't be missing. */
1620 fatal ("specs file malformed after %d characters", p1 - buffer);
1622 /* Skip back over trailing whitespace. */
1624 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1627 /* Copy the suffix to a string. */
1628 suffix = save_string (p, p2 - p);
1629 /* Find the next line. */
1630 p = skip_whitespace (p1 + 1);
1632 fatal ("specs file malformed after %d characters", p - buffer);
1635 /* Find next blank line or end of string. */
1636 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1639 /* Specs end at the blank line and do not include the newline. */
1640 spec = save_string (p, p1 - p);
1643 /* Delete backslash-newline sequences from the spec. */
1648 if (in[0] == '\\' && in[1] == '\n')
1650 else if (in[0] == '#')
1651 while (*in && *in != '\n')
1659 if (suffix[0] == '*')
1661 if (! strcmp (suffix, "*link_command"))
1662 link_command_spec = spec;
1664 set_spec (suffix + 1, spec);
1668 /* Add this pair to the vector. */
1670 = ((struct compiler *)
1671 xrealloc (compilers,
1672 (n_compilers + 2) * sizeof (struct compiler)));
1674 compilers[n_compilers].suffix = suffix;
1675 bzero ((char *) compilers[n_compilers].spec,
1676 sizeof compilers[n_compilers].spec);
1677 compilers[n_compilers].spec[0] = spec;
1679 bzero ((char *) &compilers[n_compilers],
1680 sizeof compilers[n_compilers]);
1684 link_command_spec = spec;
1687 if (link_command_spec == 0)
1688 fatal ("spec file has no spec for linking");
1691 /* Record the names of temporary files we tell compilers to write,
1692 and delete them at the end of the run. */
1694 /* This is the common prefix we use to make temp file names.
1695 It is chosen once for each run of this program.
1696 It is substituted into a spec by %g.
1697 Thus, all temp file names contain this prefix.
1698 In practice, all temp file names start with this prefix.
1700 This prefix comes from the envvar TMPDIR if it is defined;
1701 otherwise, from the P_tmpdir macro if that is defined;
1702 otherwise, in /usr/tmp or /tmp;
1703 or finally the current directory if all else fails. */
1705 static char *temp_filename;
1707 /* Length of the prefix. */
1709 static int temp_filename_length;
1711 /* Define the list of temporary files to delete. */
1716 struct temp_file *next;
1719 /* Queue of files to delete on success or failure of compilation. */
1720 static struct temp_file *always_delete_queue;
1721 /* Queue of files to delete on failure of compilation. */
1722 static struct temp_file *failure_delete_queue;
1724 /* Record FILENAME as a file to be deleted automatically.
1725 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1726 otherwise delete it in any case.
1727 FAIL_DELETE nonzero means delete it if a compilation step fails;
1728 otherwise delete it in any case. */
1731 record_temp_file (filename, always_delete, fail_delete)
1736 register char *name;
1737 name = xmalloc (strlen (filename) + 1);
1738 strcpy (name, filename);
1742 register struct temp_file *temp;
1743 for (temp = always_delete_queue; temp; temp = temp->next)
1744 if (! strcmp (name, temp->name))
1747 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1748 temp->next = always_delete_queue;
1750 always_delete_queue = temp;
1757 register struct temp_file *temp;
1758 for (temp = failure_delete_queue; temp; temp = temp->next)
1759 if (! strcmp (name, temp->name))
1762 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1763 temp->next = failure_delete_queue;
1765 failure_delete_queue = temp;
1771 /* Delete all the temporary files whose names we previously recorded. */
1774 delete_if_ordinary (name)
1781 printf ("Delete %s? (y or n) ", name);
1785 while ((c = getchar ()) != '\n' && c != EOF)
1788 if (i == 'y' || i == 'Y')
1790 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1791 if (unlink (name) < 0)
1793 perror_with_name (name);
1797 delete_temp_files ()
1799 register struct temp_file *temp;
1801 for (temp = always_delete_queue; temp; temp = temp->next)
1802 delete_if_ordinary (temp->name);
1803 always_delete_queue = 0;
1806 /* Delete all the files to be deleted on error. */
1809 delete_failure_queue ()
1811 register struct temp_file *temp;
1813 for (temp = failure_delete_queue; temp; temp = temp->next)
1814 delete_if_ordinary (temp->name);
1818 clear_failure_queue ()
1820 failure_delete_queue = 0;
1823 /* Routine to add variables to the environment. We do this to pass
1824 the pathname of the gcc driver, and the directories search to the
1825 collect2 program, which is being run as ld. This way, we can be
1826 sure of executing the right compiler when collect2 wants to build
1827 constructors and destructors. Since the environment variables we
1828 use come from an obstack, we don't have to worry about allocating
1837 #ifndef VMS /* nor about VMS */
1839 extern char **environ;
1840 char **old_environ = environ;
1844 int str_len = strlen (str);
1848 while ((ch = *p++) != '\0' && ch != '=')
1854 /* Search for replacing an existing environment variable, and
1855 count the number of total environment variables. */
1856 for (envp = old_environ; *envp; envp++)
1859 if (!strncmp (str, *envp, name_len))
1866 /* Add a new environment variable */
1867 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1869 bcopy ((char *) old_environ, (char *) (environ + 1),
1870 sizeof (char *) * (num_envs+1));
1875 #endif /* HAVE_PUTENV */
1878 /* Build a list of search directories from PATHS.
1879 PREFIX is a string to prepend to the list.
1880 If CHECK_DIR_P is non-zero we ensure the directory exists.
1881 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1882 It is also used by the --print-search-dirs flag. */
1885 build_search_list (paths, prefix, check_dir_p)
1886 struct path_prefix *paths;
1890 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1892 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1893 int first_time = TRUE;
1894 struct prefix_list *pprefix;
1896 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1898 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1900 int len = strlen (pprefix->prefix);
1904 || is_directory (pprefix->prefix, machine_suffix, 0)))
1907 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1910 obstack_grow (&collect_obstack, pprefix->prefix, len);
1911 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1914 if (just_machine_suffix
1915 && pprefix->require_machine_suffix == 2
1917 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1920 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1923 obstack_grow (&collect_obstack, pprefix->prefix, len);
1924 obstack_grow (&collect_obstack, just_machine_suffix,
1928 if (! pprefix->require_machine_suffix)
1931 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1934 obstack_grow (&collect_obstack, pprefix->prefix, len);
1938 obstack_1grow (&collect_obstack, '\0');
1939 return obstack_finish (&collect_obstack);
1942 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1946 putenv_from_prefixes (paths, env_var)
1947 struct path_prefix *paths;
1950 putenv (build_search_list (paths, env_var, 1));
1953 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1954 access to check permissions.
1955 Return 0 if not found, otherwise return its name, allocated with malloc. */
1958 find_a_file (pprefix, name, mode)
1959 struct path_prefix *pprefix;
1964 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1965 struct prefix_list *pl;
1966 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1969 len += strlen (machine_suffix);
1971 temp = xmalloc (len);
1973 /* Determine the filename to execute (special case for absolute paths). */
1975 if (*name == '/' || *name == DIR_SEPARATOR
1976 /* Check for disk name on MS-DOS-based systems. */
1977 || (DIR_SEPARATOR == '\\' && name[1] == ':'
1978 && (name[2] == DIR_SEPARATOR || name[2] == '/')))
1980 if (access (name, mode))
1982 strcpy (temp, name);
1987 for (pl = pprefix->plist; pl; pl = pl->next)
1991 /* Some systems have a suffix for executable files.
1992 So try appending that first. */
1993 if (file_suffix[0] != 0)
1995 strcpy (temp, pl->prefix);
1996 strcat (temp, machine_suffix);
1997 strcat (temp, name);
1998 strcat (temp, file_suffix);
1999 if (access (temp, mode) == 0)
2001 if (pl->used_flag_ptr != 0)
2002 *pl->used_flag_ptr = 1;
2007 /* Now try just the name. */
2008 strcpy (temp, pl->prefix);
2009 strcat (temp, machine_suffix);
2010 strcat (temp, name);
2011 if (access (temp, mode) == 0)
2013 if (pl->used_flag_ptr != 0)
2014 *pl->used_flag_ptr = 1;
2019 /* Certain prefixes are tried with just the machine type,
2020 not the version. This is used for finding as, ld, etc. */
2021 if (just_machine_suffix && pl->require_machine_suffix == 2)
2023 /* Some systems have a suffix for executable files.
2024 So try appending that first. */
2025 if (file_suffix[0] != 0)
2027 strcpy (temp, pl->prefix);
2028 strcat (temp, just_machine_suffix);
2029 strcat (temp, name);
2030 strcat (temp, file_suffix);
2031 if (access (temp, mode) == 0)
2033 if (pl->used_flag_ptr != 0)
2034 *pl->used_flag_ptr = 1;
2039 strcpy (temp, pl->prefix);
2040 strcat (temp, just_machine_suffix);
2041 strcat (temp, name);
2042 if (access (temp, mode) == 0)
2044 if (pl->used_flag_ptr != 0)
2045 *pl->used_flag_ptr = 1;
2050 /* Certain prefixes can't be used without the machine suffix
2051 when the machine or version is explicitly specified. */
2052 if (! pl->require_machine_suffix)
2054 /* Some systems have a suffix for executable files.
2055 So try appending that first. */
2056 if (file_suffix[0] != 0)
2058 strcpy (temp, pl->prefix);
2059 strcat (temp, name);
2060 strcat (temp, file_suffix);
2061 if (access (temp, mode) == 0)
2063 if (pl->used_flag_ptr != 0)
2064 *pl->used_flag_ptr = 1;
2069 strcpy (temp, pl->prefix);
2070 strcat (temp, name);
2071 if (access (temp, mode) == 0)
2073 if (pl->used_flag_ptr != 0)
2074 *pl->used_flag_ptr = 1;
2084 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2085 at the start of the list, otherwise it goes at the end.
2087 If WARN is nonzero, we will warn if no file is found
2088 through this prefix. WARN should point to an int
2089 which will be set to 1 if this entry is used.
2091 COMPONENT is the value to be passed to update_path.
2093 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2094 the complete value of machine_suffix.
2095 2 means try both machine_suffix and just_machine_suffix. */
2098 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2099 struct path_prefix *pprefix;
2103 int require_machine_suffix;
2106 struct prefix_list *pl, **prev;
2109 if (! first && pprefix->plist)
2111 for (pl = pprefix->plist; pl->next; pl = pl->next)
2116 prev = &pprefix->plist;
2118 /* Keep track of the longest prefix */
2120 prefix = update_path (prefix, component);
2121 len = strlen (prefix);
2122 if (len > pprefix->max_len)
2123 pprefix->max_len = len;
2125 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2126 pl->prefix = save_string (prefix, len);
2127 pl->require_machine_suffix = require_machine_suffix;
2128 pl->used_flag_ptr = warn;
2135 pl->next = (struct prefix_list *) 0;
2139 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2142 unused_prefix_warnings (pprefix)
2143 struct path_prefix *pprefix;
2145 struct prefix_list *pl = pprefix->plist;
2149 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2151 if (pl->require_machine_suffix && machine_suffix)
2152 error ("file path prefix `%s%s' never used", pl->prefix,
2155 error ("file path prefix `%s' never used", pl->prefix);
2157 /* Prevent duplicate warnings. */
2158 *pl->used_flag_ptr = 1;
2166 /* Execute the command specified by the arguments on the current line of spec.
2167 When using pipes, this includes several piped-together commands
2168 with `|' between them.
2170 Return 0 if successful, -1 if failed. */
2176 int n_commands; /* # of command. */
2180 char *prog; /* program name. */
2181 char **argv; /* vector of args. */
2182 int pid; /* pid of process for this command. */
2185 struct command *commands; /* each command buffer with above info. */
2187 /* Count # of piped commands. */
2188 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2189 if (strcmp (argbuf[i], "|") == 0)
2192 /* Get storage for each command. */
2194 = (struct command *) alloca (n_commands * sizeof (struct command));
2196 /* Split argbuf into its separate piped processes,
2197 and record info about each one.
2198 Also search for the programs that are to be run. */
2200 commands[0].prog = argbuf[0]; /* first command. */
2201 commands[0].argv = &argbuf[0];
2202 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2205 commands[0].argv[0] = string;
2207 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2208 if (strcmp (argbuf[i], "|") == 0)
2209 { /* each command. */
2210 #if defined (__MSDOS__) || (defined (_WIN32) && defined (__CYGWIN32_)) || defined (OS2) || defined (VMS)
2211 fatal ("-pipe not supported");
2213 argbuf[i] = 0; /* termination of command args. */
2214 commands[n_commands].prog = argbuf[i + 1];
2215 commands[n_commands].argv = &argbuf[i + 1];
2216 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2218 commands[n_commands].argv[0] = string;
2222 argbuf[argbuf_index] = 0;
2224 /* If -v, print what we are about to do, and maybe query. */
2228 /* For help listings, put a blank line between sub-processes. */
2229 if (print_help_list)
2230 fputc ('\n', stderr);
2232 /* Print each piped command as a separate line. */
2233 for (i = 0; i < n_commands ; i++)
2237 for (j = commands[i].argv; *j; j++)
2238 fprintf (stderr, " %s", *j);
2240 /* Print a pipe symbol after all but the last command. */
2241 if (i + 1 != n_commands)
2242 fprintf (stderr, " |");
2243 fprintf (stderr, "\n");
2247 fprintf (stderr, "\nGo ahead? (y or n) ");
2251 while (getchar () != '\n')
2254 if (i != 'y' && i != 'Y')
2259 /* Run each piped subprocess. */
2261 for (i = 0; i < n_commands; i++)
2263 char *errmsg_fmt, *errmsg_arg;
2264 char *string = commands[i].argv[0];
2266 commands[i].pid = pexecute (string, commands[i].argv,
2267 programname, temp_filename,
2268 &errmsg_fmt, &errmsg_arg,
2269 ((i == 0 ? PEXECUTE_FIRST : 0)
2270 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2271 | (string == commands[i].prog
2272 ? PEXECUTE_SEARCH : 0)
2273 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2275 if (commands[i].pid == -1)
2276 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2278 if (string != commands[i].prog)
2284 /* Wait for all the subprocesses to finish.
2285 We don't care what order they finish in;
2286 we know that N_COMMANDS waits will get them all.
2287 Ignore subprocesses that we don't know about,
2288 since they can be spawned by the process that exec'ed us. */
2293 for (i = 0; i < n_commands; )
2299 pid = pwait (commands[i].pid, &status, 0);
2303 for (j = 0; j < n_commands; j++)
2304 if (commands[j].pid == pid)
2309 if (WIFSIGNALED (status))
2311 fatal ("Internal compiler error: program %s got fatal signal %d",
2312 commands[j].prog, WTERMSIG (status));
2316 else if (WIFEXITED (status)
2317 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2327 /* Find all the switches given to us
2328 and make a vector describing them.
2329 The elements of the vector are strings, one per switch given.
2330 If a switch uses following arguments, then the `part1' field
2331 is the switch itself and the `args' field
2332 is a null-terminated vector containing the following arguments.
2333 The `live_cond' field is 1 if the switch is true in a conditional spec,
2334 -1 if false (overridden by a later switch), and is initialized to zero.
2335 The `valid' field is nonzero if any spec has looked at this switch;
2336 if it remains zero at the end of the run, it must be meaningless. */
2346 static struct switchstr *switches;
2348 static int n_switches;
2356 /* Also a vector of input files specified. */
2358 static struct infile *infiles;
2360 static int n_infiles;
2362 /* This counts the number of libraries added by LANG_SPECIFIC_DRIVER, so that
2363 we can tell if there were any user supplied any files or libraries. */
2365 static int added_libraries;
2367 /* And a vector of corresponding output files is made up later. */
2369 static char **outfiles;
2371 /* Used to track if none of the -B paths are used. */
2374 /* Used to track if standard path isn't used and -b or -V is specified. */
2375 static int warn_std;
2377 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2378 static int *warn_std_ptr = 0;
2381 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2383 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2384 is true if we should look for an executable suffix as well. */
2387 convert_filename (name, do_exe)
2392 int len = strlen (name);
2394 #ifdef HAVE_OBJECT_SUFFIX
2395 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2397 && name[len - 2] == '.'
2398 && name[len - 1] == 'o')
2400 obstack_grow (&obstack, name, len - 2);
2401 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2402 name = obstack_finish (&obstack);
2406 #ifdef HAVE_EXECUTABLE_SUFFIX
2407 /* If there is no filetype, make it the executable suffix (which includes
2408 the "."). But don't get confused if we have just "-o". */
2409 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2412 for (i = len - 1; i >= 0; i--)
2413 if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2416 for (i++; i < len; i++)
2420 obstack_grow (&obstack, name, len);
2421 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2422 name = obstack_finish (&obstack);
2429 /* Display the command line switches accepted by gcc. */
2433 printf ("Usage: %s [options] file...\n", programname);
2434 printf ("Options:\n");
2436 printf (" --help Display this information\n");
2438 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2439 printf (" -dumpspecs Display all of the built in spec strings\n");
2440 printf (" -dumpversion Display the version of the compiler\n");
2441 printf (" -dumpmachine Display the compiler's target processor\n");
2442 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2443 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2444 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2445 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2446 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2447 printf (" -print-multi-lib Display the mapping between command line options and\n");
2448 printf (" multiple library search directories\n");
2449 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2450 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2451 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2452 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2453 printf (" -save-temps Do not delete intermediate files\n");
2454 printf (" -pipe Use pipes rather than intermediate files\n");
2455 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2456 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2457 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2458 printf (" -V <version> Run gcc version number <version>, if installed\n");
2459 printf (" -v Display the programs invoked by the compiler\n");
2460 printf (" -E Preprocess only; do not compile, assemble or link\n");
2461 printf (" -S Compile only; do not assemble or link\n");
2462 printf (" -c Compile and assemble, but do not link\n");
2463 printf (" -o <file> Place the output into <file>\n");
2464 printf (" -x <language> Specify the language of the following input files\n");
2465 printf (" Permissable languages include: c c++ assembler none\n");
2466 printf (" 'none' means revert to the default behaviour of\n");
2467 printf (" guessing the language based on the file's extension\n");
2469 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2470 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2472 printf ("on to these processes the -W<letter> options must be used.\n");
2474 /* The rest of the options are displayed by invocations of the various
2479 add_preprocessor_option (option, len)
2483 n_preprocessor_options++;
2485 if (! preprocessor_options)
2486 preprocessor_options
2487 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2489 preprocessor_options
2490 = (char **) xrealloc (preprocessor_options,
2491 n_preprocessor_options * sizeof (char **));
2493 preprocessor_options [n_preprocessor_options - 1] = save_string (option, len);
2497 add_assembler_option (option, len)
2501 n_assembler_options++;
2503 if (! assembler_options)
2505 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2508 = (char **) xrealloc (assembler_options,
2509 n_assembler_options * sizeof (char **));
2511 assembler_options [n_assembler_options - 1] = save_string (option, len);
2515 add_linker_option (option, len)
2521 if (! linker_options)
2523 = (char **) xmalloc (n_linker_options * sizeof (char **));
2526 = (char **) xrealloc (linker_options,
2527 n_linker_options * sizeof (char **));
2529 linker_options [n_linker_options - 1] = save_string (option, len);
2532 /* Create the vector `switches' and its contents.
2533 Store its length in `n_switches'. */
2536 process_command (argc, argv)
2542 char *spec_lang = 0;
2543 int last_language_n_infiles;
2546 int lang_n_infiles = 0;
2548 GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2552 added_libraries = 0;
2554 /* Figure compiler version from version string. */
2556 compiler_version = save_string (version_string, strlen (version_string));
2557 for (temp = compiler_version; *temp; ++temp)
2566 /* Set up the default search paths. */
2568 if (gcc_exec_prefix)
2570 int len = strlen (gcc_exec_prefix);
2571 if (len > sizeof ("/lib/gcc-lib/")-1
2572 && (gcc_exec_prefix[len-1] == '/'
2573 || gcc_exec_prefix[len-1] == DIR_SEPARATOR))
2575 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2576 if ((*temp == '/' || *temp == DIR_SEPARATOR)
2577 && strncmp (temp+1, "lib", 3) == 0
2578 && (temp[4] == '/' || temp[4] == DIR_SEPARATOR)
2579 && strncmp (temp+5, "gcc-lib", 7) == 0)
2580 len -= sizeof ("/lib/gcc-lib/") - 1;
2583 set_std_prefix (gcc_exec_prefix, len);
2584 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2585 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2588 /* COMPILER_PATH and LIBRARY_PATH have values
2589 that are lists of directory names with colons. */
2591 GET_ENVIRONMENT (temp, "COMPILER_PATH");
2594 char *startp, *endp;
2595 char *nstore = (char *) alloca (strlen (temp) + 3);
2597 startp = endp = temp;
2600 if (*endp == PATH_SEPARATOR || *endp == 0)
2602 strncpy (nstore, startp, endp-startp);
2604 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2605 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2607 nstore[endp-startp] = DIR_SEPARATOR;
2608 nstore[endp-startp+1] = 0;
2611 nstore[endp-startp] = 0;
2612 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2613 add_prefix (&include_prefixes,
2614 concat (nstore, "include", NULL_PTR),
2618 endp = startp = endp + 1;
2625 GET_ENVIRONMENT (temp, "LIBRARY_PATH");
2626 if (temp && *cross_compile == '0')
2628 char *startp, *endp;
2629 char *nstore = (char *) alloca (strlen (temp) + 3);
2631 startp = endp = temp;
2634 if (*endp == PATH_SEPARATOR || *endp == 0)
2636 strncpy (nstore, startp, endp-startp);
2638 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2639 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2641 nstore[endp-startp] = DIR_SEPARATOR;
2642 nstore[endp-startp+1] = 0;
2645 nstore[endp-startp] = 0;
2646 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2650 endp = startp = endp + 1;
2657 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2658 GET_ENVIRONMENT (temp, "LPATH");
2659 if (temp && *cross_compile == '0')
2661 char *startp, *endp;
2662 char *nstore = (char *) alloca (strlen (temp) + 3);
2664 startp = endp = temp;
2667 if (*endp == PATH_SEPARATOR || *endp == 0)
2669 strncpy (nstore, startp, endp-startp);
2671 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2672 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2674 nstore[endp-startp] = DIR_SEPARATOR;
2675 nstore[endp-startp+1] = 0;
2678 nstore[endp-startp] = 0;
2679 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2683 endp = startp = endp + 1;
2690 /* Convert new-style -- options to old-style. */
2691 translate_options (&argc, &argv);
2693 #ifdef LANG_SPECIFIC_DRIVER
2694 /* Do language-specific adjustment/addition of flags. */
2695 lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2698 /* Scan argv twice. Here, the first time, just count how many switches
2699 there will be in their vector, and how many input files in theirs.
2700 Here we also parse the switches that cc itself uses (e.g. -v). */
2702 for (i = 1; i < argc; i++)
2704 if (! strcmp (argv[i], "-dumpspecs"))
2706 struct spec_list *sl;
2708 for (sl = specs; sl; sl = sl->next)
2709 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2712 else if (! strcmp (argv[i], "-dumpversion"))
2714 printf ("%s\n", spec_version);
2717 else if (! strcmp (argv[i], "-dumpmachine"))
2719 printf ("%s\n", spec_machine);
2722 else if (strcmp (argv[i], "-fhelp") == 0)
2724 /* translate_options () has turned --help into -fhelp. */
2725 print_help_list = 1;
2727 /* We will be passing a dummy file on to the sub-processes. */
2731 add_preprocessor_option ("--help", 6);
2732 add_assembler_option ("--help", 6);
2733 add_linker_option ("--help", 6);
2735 else if (! strcmp (argv[i], "-print-search-dirs"))
2736 print_search_dirs = 1;
2737 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2738 print_file_name = "libgcc.a";
2739 else if (! strncmp (argv[i], "-print-file-name=", 17))
2740 print_file_name = argv[i] + 17;
2741 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2742 print_prog_name = argv[i] + 17;
2743 else if (! strcmp (argv[i], "-print-multi-lib"))
2744 print_multi_lib = 1;
2745 else if (! strcmp (argv[i], "-print-multi-directory"))
2746 print_multi_directory = 1;
2747 else if (! strncmp (argv[i], "-Wa,", 4))
2750 /* Pass the rest of this option to the assembler. */
2752 /* Split the argument at commas. */
2754 for (j = 4; argv[i][j]; j++)
2755 if (argv[i][j] == ',')
2757 add_assembler_option (argv[i] + prev, j - prev);
2761 /* Record the part after the last comma. */
2762 add_assembler_option (argv[i] + prev, j - prev);
2764 else if (! strncmp (argv[i], "-Wp,", 4))
2767 /* Pass the rest of this option to the preprocessor. */
2769 /* Split the argument at commas. */
2771 for (j = 4; argv[i][j]; j++)
2772 if (argv[i][j] == ',')
2774 add_preprocessor_option (argv[i] + prev, j - prev);
2778 /* Record the part after the last comma. */
2779 add_preprocessor_option (argv[i] + prev, j - prev);
2781 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2782 /* The +e options to the C++ front-end. */
2784 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2787 /* Split the argument at commas. */
2788 for (j = 3; argv[i][j]; j++)
2789 n_infiles += (argv[i][j] == ',');
2791 else if (strcmp (argv[i], "-Xlinker") == 0)
2794 fatal ("argument to `-Xlinker' is missing");
2799 else if (strncmp (argv[i], "-l", 2) == 0)
2801 else if (strcmp (argv[i], "-save-temps") == 0)
2803 save_temps_flag = 1;
2806 else if (strcmp (argv[i], "-specs") == 0)
2808 struct user_specs *user = (struct user_specs *)
2809 xmalloc (sizeof (struct user_specs));
2811 fatal ("argument to `-specs' is missing");
2813 user->next = (struct user_specs *)0;
2814 user->filename = argv[i];
2815 if (user_specs_tail)
2816 user_specs_tail->next = user;
2818 user_specs_head = user;
2819 user_specs_tail = user;
2821 else if (strncmp (argv[i], "-specs=", 7) == 0)
2823 struct user_specs *user = (struct user_specs *)
2824 xmalloc (sizeof (struct user_specs));
2825 if (strlen (argv[i]) == 7)
2826 fatal ("argument to `-specs=' is missing");
2828 user->next = (struct user_specs *)0;
2829 user->filename = argv[i]+7;
2830 if (user_specs_tail)
2831 user_specs_tail->next = user;
2833 user_specs_head = user;
2834 user_specs_tail = user;
2836 else if (argv[i][0] == '-' && argv[i][1] != 0)
2838 register char *p = &argv[i][1];
2839 register int c = *p;
2845 if (p[1] == 0 && i + 1 == argc)
2846 fatal ("argument to `-b' is missing");
2848 spec_machine = argv[++i];
2850 spec_machine = p + 1;
2852 warn_std_ptr = &warn_std;
2858 if (p[1] == 0 && i + 1 == argc)
2859 fatal ("argument to `-B' is missing");
2864 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2865 add_prefix (&startfile_prefixes, value, NULL_PTR,
2867 add_prefix (&include_prefixes, concat (value, "include",
2869 NULL_PTR, 1, 0, NULL_PTR);
2871 /* As a kludge, if the arg is "[foo/]stageN/", just add
2872 "[foo/]include" to the include prefix. */
2874 int len = strlen (value);
2877 && (value[len - 8] == '/'
2878 || value[len - 8] == DIR_SEPARATOR)))
2879 && strncmp (value + len - 7, "stage", 5) == 0
2880 && ISDIGIT (value[len - 2])
2881 && (value[len - 1] == '/'
2882 || value[len - 1] == DIR_SEPARATOR))
2885 add_prefix (&include_prefixes, "include", NULL_PTR,
2889 char *string = xmalloc (len + 1);
2890 strncpy (string, value, len-7);
2891 strcpy (string+len-7, "include");
2892 add_prefix (&include_prefixes, string, NULL_PTR,
2901 case 'v': /* Print our subcommands and print versions. */
2903 /* If they do anything other than exactly `-v', don't set
2904 verbose_flag; rather, continue on to give the error. */
2912 if (p[1] == 0 && i + 1 == argc)
2913 fatal ("argument to `-V' is missing");
2915 spec_version = argv[++i];
2917 spec_version = p + 1;
2918 compiler_version = spec_version;
2919 warn_std_ptr = &warn_std;
2921 /* Validate the version number. Use the same checks
2922 done when inserting it into a spec.
2924 The format of the version string is
2925 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2927 char *v = compiler_version;
2929 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2930 while (! ISDIGIT (*v))
2933 if (v > compiler_version && v[-1] != '-')
2934 fatal ("invalid version number format");
2936 /* Set V after the first period. */
2937 while (ISDIGIT (*v))
2941 fatal ("invalid version number format");
2944 while (ISDIGIT (*v))
2947 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
2948 fatal ("invalid version number format");
2964 #if defined(HAVE_EXECUTABLE_SUFFIX)
2969 /* Forward scan, just in case -S or -c is specified
2976 if (argv[j][0] == '-')
2978 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
2984 else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
2985 j += skip - (argv[j][2] != 0);
2986 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
2993 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2995 argv[i+1] = convert_filename (argv[i+1], ! have_c);
2997 argv[i] = convert_filename (argv[i], ! have_c);
3005 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3006 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3007 else if (WORD_SWITCH_TAKES_ARG (p))
3008 i += WORD_SWITCH_TAKES_ARG (p);
3018 if (have_c && have_o && lang_n_infiles > 1)
3019 fatal ("cannot specify -o with -c or -S and multiple compilations");
3021 /* Set up the search paths before we go looking for config files. */
3023 /* These come before the md prefixes so that we will find gcc's subcommands
3024 (such as cpp) rather than those of the host system. */
3025 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3026 as well as trying the machine and the version. */
3028 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3029 0, 2, warn_std_ptr);
3030 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3031 0, 2, warn_std_ptr);
3034 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3035 0, 1, warn_std_ptr);
3036 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3037 0, 1, warn_std_ptr);
3039 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3040 dir_separator_str, NULL_PTR);
3042 /* If tooldir is relative, base it on exec_prefixes. A relative
3043 tooldir lets us move the installed tree as a unit.
3045 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3046 directories, so that we can search both the user specified directory
3047 and the standard place. */
3049 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
3051 if (gcc_exec_prefix)
3053 char *gcc_exec_tooldir_prefix
3054 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3055 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
3057 add_prefix (&exec_prefixes,
3058 concat (gcc_exec_tooldir_prefix, "bin",
3059 dir_separator_str, NULL_PTR),
3060 NULL_PTR, 0, 0, NULL_PTR);
3061 add_prefix (&startfile_prefixes,
3062 concat (gcc_exec_tooldir_prefix, "lib",
3063 dir_separator_str, NULL_PTR),
3064 NULL_PTR, 0, 0, NULL_PTR);
3067 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3068 dir_separator_str, spec_version,
3069 dir_separator_str, tooldir_prefix, NULL_PTR);
3072 add_prefix (&exec_prefixes,
3073 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
3074 "BINUTILS", 0, 0, NULL_PTR);
3075 add_prefix (&startfile_prefixes,
3076 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
3077 "BINUTILS", 0, 0, NULL_PTR);
3079 /* More prefixes are enabled in main, after we read the specs file
3080 and determine whether this is cross-compilation or not. */
3083 /* Then create the space for the vectors and scan again. */
3085 switches = ((struct switchstr *)
3086 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3087 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3090 last_language_n_infiles = -1;
3092 /* This, time, copy the text of each switch and store a pointer
3093 to the copy in the vector of switches.
3094 Store all the infiles in their vector. */
3096 for (i = 1; i < argc; i++)
3098 /* Just skip the switches that were handled by the preceding loop. */
3099 if (! strncmp (argv[i], "-Wa,", 4))
3101 else if (! strncmp (argv[i], "-Wp,", 4))
3103 else if (! strcmp (argv[i], "-print-search-dirs"))
3105 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3107 else if (! strncmp (argv[i], "-print-file-name=", 17))
3109 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3111 else if (! strcmp (argv[i], "-print-multi-lib"))
3113 else if (! strcmp (argv[i], "-print-multi-directory"))
3115 else if (strcmp (argv[i], "-fhelp") == 0)
3119 /* Create a dummy input file, so that we can pass --help on to
3120 the various sub-processes. */
3121 infiles[n_infiles].language = "c";
3122 infiles[n_infiles++].name = "help-dummy";
3124 /* Preserve the --help switch so that it can be caught by the
3126 switches[n_switches].part1 = "--help";
3127 switches[n_switches].args = 0;
3128 switches[n_switches].live_cond = 0;
3129 switches[n_switches].valid = 0;
3134 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3136 /* Compensate for the +e options to the C++ front-end;
3137 they're there simply for cfront call-compatibility. We do
3138 some magic in default_compilers to pass them down properly.
3139 Note we deliberately start at the `+' here, to avoid passing
3140 -e0 or -e1 down into the linker. */
3141 switches[n_switches].part1 = &argv[i][0];
3142 switches[n_switches].args = 0;
3143 switches[n_switches].live_cond = 0;
3144 switches[n_switches].valid = 0;
3147 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3150 /* Split the argument at commas. */
3152 for (j = 4; argv[i][j]; j++)
3153 if (argv[i][j] == ',')
3155 infiles[n_infiles].language = "*";
3156 infiles[n_infiles++].name
3157 = save_string (argv[i] + prev, j - prev);
3160 /* Record the part after the last comma. */
3161 infiles[n_infiles].language = "*";
3162 infiles[n_infiles++].name = argv[i] + prev;
3164 else if (strcmp (argv[i], "-Xlinker") == 0)
3166 infiles[n_infiles].language = "*";
3167 infiles[n_infiles++].name = argv[++i];
3169 else if (strncmp (argv[i], "-l", 2) == 0)
3171 infiles[n_infiles].language = "*";
3172 infiles[n_infiles++].name = argv[i];
3174 else if (strcmp (argv[i], "-specs") == 0)
3176 else if (strncmp (argv[i], "-specs=", 7) == 0)
3178 /* -save-temps overrides -pipe, so that temp files are produced */
3179 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
3180 error ("Warning: -pipe ignored since -save-temps specified");
3181 else if (argv[i][0] == '-' && argv[i][1] != 0)
3183 register char *p = &argv[i][1];
3184 register int c = *p;
3188 if (p[1] == 0 && i + 1 == argc)
3189 fatal ("argument to `-x' is missing");
3191 spec_lang = argv[++i];
3194 if (! strcmp (spec_lang, "none"))
3195 /* Suppress the warning if -xnone comes after the last input
3196 file, because alternate command interfaces like g++ might
3197 find it useful to place -xnone after each input file. */
3200 last_language_n_infiles = n_infiles;
3203 switches[n_switches].part1 = p;
3204 /* Deal with option arguments in separate argv elements. */
3205 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3206 || WORD_SWITCH_TAKES_ARG (p))
3209 int n_args = WORD_SWITCH_TAKES_ARG (p);
3213 /* Count only the option arguments in separate argv elements. */
3214 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3216 if (i + n_args >= argc)
3217 fatal ("argument to `-%s' is missing", p);
3218 switches[n_switches].args
3219 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3221 switches[n_switches].args[j++] = argv[++i];
3222 /* Null-terminate the vector. */
3223 switches[n_switches].args[j] = 0;
3225 else if (index (switches_need_spaces, c))
3227 /* On some systems, ld cannot handle some options without
3228 a space. So split the option from its argument. */
3229 char *part1 = (char *) xmalloc (2);
3233 switches[n_switches].part1 = part1;
3234 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3235 switches[n_switches].args[0] = xmalloc (strlen (p));
3236 strcpy (switches[n_switches].args[0], &p[1]);
3237 switches[n_switches].args[1] = 0;
3240 switches[n_switches].args = 0;
3242 switches[n_switches].live_cond = 0;
3243 switches[n_switches].valid = 0;
3244 /* This is always valid, since gcc.c itself understands it. */
3245 if (!strcmp (p, "save-temps"))
3246 switches[n_switches].valid = 1;
3249 char ch = switches[n_switches].part1[0];
3250 if (ch == 'V' || ch == 'b' || ch == 'B')
3251 switches[n_switches].valid = 1;
3257 #ifdef HAVE_OBJECT_SUFFIX
3258 argv[i] = convert_filename (argv[i], 0);
3261 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3263 perror_with_name (argv[i]);
3268 infiles[n_infiles].language = spec_lang;
3269 infiles[n_infiles++].name = argv[i];
3274 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3275 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3277 switches[n_switches].part1 = 0;
3278 infiles[n_infiles].name = 0;
3281 /* Process a spec string, accumulating and running commands. */
3283 /* These variables describe the input file name.
3284 input_file_number is the index on outfiles of this file,
3285 so that the output file name can be stored for later use by %o.
3286 input_basename is the start of the part of the input file
3287 sans all directory names, and basename_length is the number
3288 of characters starting there excluding the suffix .c or whatever. */
3290 char *input_filename;
3291 static int input_file_number;
3292 size_t input_filename_length;
3293 static int basename_length;
3294 static char *input_basename;
3295 static char *input_suffix;
3297 /* These are variables used within do_spec and do_spec_1. */
3299 /* Nonzero if an arg has been started and not yet terminated
3300 (with space, tab or newline). */
3301 static int arg_going;
3303 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3304 is a temporary file name. */
3305 static int delete_this_arg;
3307 /* Nonzero means %w has been seen; the next arg to be terminated
3308 is the output file name of this compilation. */
3309 static int this_is_output_file;
3311 /* Nonzero means %s has been seen; the next arg to be terminated
3312 is the name of a library file and we should try the standard
3313 search dirs for it. */
3314 static int this_is_library_file;
3316 /* Nonzero means that the input of this command is coming from a pipe. */
3317 static int input_from_pipe;
3319 /* Process the spec SPEC and run the commands specified therein.
3320 Returns 0 if the spec is successfully processed; -1 if failed. */
3330 delete_this_arg = 0;
3331 this_is_output_file = 0;
3332 this_is_library_file = 0;
3333 input_from_pipe = 0;
3335 value = do_spec_1 (spec, 0, NULL_PTR);
3337 /* Force out any unfinished command.
3338 If -pipe, this forces out the last command if it ended in `|'. */
3341 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3344 if (argbuf_index > 0)
3351 /* Process the sub-spec SPEC as a portion of a larger spec.
3352 This is like processing a whole spec except that we do
3353 not initialize at the beginning and we do not supply a
3354 newline by default at the end.
3355 INSWITCH nonzero means don't process %-sequences in SPEC;
3356 in this case, % is treated as an ordinary character.
3357 This is used while substituting switches.
3358 INSWITCH nonzero also causes SPC not to terminate an argument.
3360 Value is zero unless a line was finished
3361 and the command on that line reported an error. */
3364 do_spec_1 (spec, inswitch, soft_matched_part)
3367 char *soft_matched_part;
3369 register char *p = spec;
3376 /* If substituting a switch, treat all chars like letters.
3377 Otherwise, NL, SPC, TAB and % are special. */
3378 switch (inswitch ? 'a' : c)
3381 /* End of line: finish any pending argument,
3382 then run the pending command if one has been started. */
3385 obstack_1grow (&obstack, 0);
3386 string = obstack_finish (&obstack);
3387 if (this_is_library_file)
3388 string = find_file (string);
3389 store_arg (string, delete_this_arg, this_is_output_file);
3390 if (this_is_output_file)
3391 outfiles[input_file_number] = string;
3395 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3397 for (i = 0; i < n_switches; i++)
3398 if (!strcmp (switches[i].part1, "pipe"))
3401 /* A `|' before the newline means use a pipe here,
3402 but only if -pipe was specified.
3403 Otherwise, execute now and don't pass the `|' as an arg. */
3406 input_from_pipe = 1;
3407 switches[i].valid = 1;
3414 if (argbuf_index > 0)
3420 /* Reinitialize for a new command, and for a new argument. */
3423 delete_this_arg = 0;
3424 this_is_output_file = 0;
3425 this_is_library_file = 0;
3426 input_from_pipe = 0;
3430 /* End any pending argument. */
3433 obstack_1grow (&obstack, 0);
3434 string = obstack_finish (&obstack);
3435 if (this_is_library_file)
3436 string = find_file (string);
3437 store_arg (string, delete_this_arg, this_is_output_file);
3438 if (this_is_output_file)
3439 outfiles[input_file_number] = string;
3443 obstack_1grow (&obstack, c);
3449 /* Space or tab ends an argument if one is pending. */
3452 obstack_1grow (&obstack, 0);
3453 string = obstack_finish (&obstack);
3454 if (this_is_library_file)
3455 string = find_file (string);
3456 store_arg (string, delete_this_arg, this_is_output_file);
3457 if (this_is_output_file)
3458 outfiles[input_file_number] = string;
3460 /* Reinitialize for a new argument. */
3462 delete_this_arg = 0;
3463 this_is_output_file = 0;
3464 this_is_library_file = 0;
3471 fatal ("Invalid specification! Bug in cc.");
3474 obstack_grow (&obstack, input_basename, basename_length);
3479 delete_this_arg = 2;
3482 /* Dump out the directories specified with LIBRARY_PATH,
3483 followed by the absolute directories
3484 that we search for startfiles. */
3487 struct prefix_list *pl = startfile_prefixes.plist;
3488 size_t bufsize = 100;
3489 char *buffer = (char *) xmalloc (bufsize);
3492 for (; pl; pl = pl->next)
3494 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3495 /* Used on systems which record the specified -L dirs
3496 and use them to search for dynamic linking. */
3497 /* Relative directories always come from -B,
3498 and it is better not to use them for searching
3499 at run time. In particular, stage1 loses */
3500 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3503 /* Try subdirectory if there is one. */
3504 if (multilib_dir != NULL)
3508 if (strlen (pl->prefix) + strlen (machine_suffix)
3510 bufsize = (strlen (pl->prefix)
3511 + strlen (machine_suffix)) * 2 + 1;
3512 buffer = (char *) xrealloc (buffer, bufsize);
3513 strcpy (buffer, pl->prefix);
3514 strcat (buffer, machine_suffix);
3515 if (is_directory (buffer, multilib_dir, 1))
3517 do_spec_1 ("-L", 0, NULL_PTR);
3518 #ifdef SPACE_AFTER_L_OPTION
3519 do_spec_1 (" ", 0, NULL_PTR);
3521 do_spec_1 (buffer, 1, NULL_PTR);
3522 do_spec_1 (multilib_dir, 1, NULL_PTR);
3523 /* Make this a separate argument. */
3524 do_spec_1 (" ", 0, NULL_PTR);
3527 if (!pl->require_machine_suffix)
3529 if (is_directory (pl->prefix, multilib_dir, 1))
3531 do_spec_1 ("-L", 0, NULL_PTR);
3532 #ifdef SPACE_AFTER_L_OPTION
3533 do_spec_1 (" ", 0, NULL_PTR);
3535 do_spec_1 (pl->prefix, 1, NULL_PTR);
3536 do_spec_1 (multilib_dir, 1, NULL_PTR);
3537 /* Make this a separate argument. */
3538 do_spec_1 (" ", 0, NULL_PTR);
3544 if (is_directory (pl->prefix, machine_suffix, 1))
3546 do_spec_1 ("-L", 0, NULL_PTR);
3547 #ifdef SPACE_AFTER_L_OPTION
3548 do_spec_1 (" ", 0, NULL_PTR);
3550 do_spec_1 (pl->prefix, 1, NULL_PTR);
3551 /* Remove slash from machine_suffix. */
3552 if (strlen (machine_suffix) >= bufsize)
3553 bufsize = strlen (machine_suffix) * 2 + 1;
3554 buffer = (char *) xrealloc (buffer, bufsize);
3555 strcpy (buffer, machine_suffix);
3556 idx = strlen (buffer);
3557 if (buffer[idx - 1] == '/'
3558 || buffer[idx - 1] == DIR_SEPARATOR)
3559 buffer[idx - 1] = 0;
3560 do_spec_1 (buffer, 1, NULL_PTR);
3561 /* Make this a separate argument. */
3562 do_spec_1 (" ", 0, NULL_PTR);
3565 if (!pl->require_machine_suffix)
3567 if (is_directory (pl->prefix, "", 1))
3569 do_spec_1 ("-L", 0, NULL_PTR);
3570 #ifdef SPACE_AFTER_L_OPTION
3571 do_spec_1 (" ", 0, NULL_PTR);
3573 /* Remove slash from pl->prefix. */
3574 if (strlen (pl->prefix) >= bufsize)
3575 bufsize = strlen (pl->prefix) * 2 + 1;
3576 buffer = (char *) xrealloc (buffer, bufsize);
3577 strcpy (buffer, pl->prefix);
3578 idx = strlen (buffer);
3579 if (buffer[idx - 1] == '/'
3580 || buffer[idx - 1] == DIR_SEPARATOR)
3581 buffer[idx - 1] = 0;
3582 do_spec_1 (buffer, 1, NULL_PTR);
3583 /* Make this a separate argument. */
3584 do_spec_1 (" ", 0, NULL_PTR);
3593 /* {...:%efoo} means report an error with `foo' as error message
3594 and don't execute any more commands for this file. */
3598 while (*p != 0 && *p != '\n') p++;
3599 buf = (char *) alloca (p - q + 1);
3600 strncpy (buf, q, p - q);
3610 if (save_temps_flag)
3612 obstack_grow (&obstack, input_basename, basename_length);
3613 delete_this_arg = 0;
3617 #ifdef MKTEMP_EACH_FILE
3618 /* ??? This has a problem: the total number of
3619 values mktemp can return is limited.
3620 That matters for the names of object files.
3621 In 2.4, do something about that. */
3622 struct temp_name *t;
3624 while (*p == '.' || ISALPHA (*p)
3625 || (p[0] == '%' && p[1] == 'O'))
3628 /* See if we already have an association of %g/%u/%U and
3630 for (t = temp_names; t; t = t->next)
3631 if (t->length == p - suffix
3632 && strncmp (t->suffix, suffix, p - suffix) == 0
3633 && t->unique == (c != 'g'))
3636 /* Make a new association if needed. %u requires one. */
3637 if (t == 0 || c == 'u')
3641 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3642 t->next = temp_names;
3645 if (strncmp (suffix, "%O", 2) == 0)
3647 t->length = strlen(OBJECT_SUFFIX);
3648 t->suffix = save_string (OBJECT_SUFFIX,
3649 strlen(OBJECT_SUFFIX));
3650 t->unique = (c != 'g');
3651 temp_filename = make_temp_file (OBJECT_SUFFIX);
3655 t->length = p - suffix;
3656 t->suffix = save_string (suffix, p - suffix);
3657 t->unique = (c != 'g');
3658 temp_filename = make_temp_file (t->suffix);
3660 temp_filename_length = strlen (temp_filename);
3661 t->filename = temp_filename;
3662 t->filename_length = temp_filename_length;
3665 obstack_grow (&obstack, t->filename, t->filename_length);
3666 delete_this_arg = 1;
3668 obstack_grow (&obstack, temp_filename, temp_filename_length);
3669 if (c == 'u' || c == 'U')
3675 sprintf (buff, "%d", unique);
3676 obstack_grow (&obstack, buff, strlen (buff));
3679 delete_this_arg = 1;
3685 obstack_grow (&obstack, input_filename, input_filename_length);
3691 struct prefix_list *pl = include_prefixes.plist;
3693 if (gcc_exec_prefix)
3695 do_spec_1 ("-iprefix", 1, NULL_PTR);
3696 /* Make this a separate argument. */
3697 do_spec_1 (" ", 0, NULL_PTR);
3698 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3699 do_spec_1 (" ", 0, NULL_PTR);
3702 for (; pl; pl = pl->next)
3704 do_spec_1 ("-isystem", 1, NULL_PTR);
3705 /* Make this a separate argument. */
3706 do_spec_1 (" ", 0, NULL_PTR);
3707 do_spec_1 (pl->prefix, 1, NULL_PTR);
3708 do_spec_1 (" ", 0, NULL_PTR);
3714 for (i = 0; i < n_infiles; i++)
3715 store_arg (outfiles[i], 0, 0);
3719 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3724 this_is_library_file = 1;
3728 this_is_output_file = 1;
3733 int cur_index = argbuf_index;
3734 /* Handle the {...} following the %W. */
3737 p = handle_braces (p + 1);
3740 /* If any args were output, mark the last one for deletion
3742 if (argbuf_index != cur_index)
3743 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3747 /* %x{OPTION} records OPTION for %X to output. */
3753 /* Skip past the option value and make a copy. */
3758 string = save_string (p1 + 1, p - p1 - 2);
3760 /* See if we already recorded this option. */
3761 for (i = 0; i < n_linker_options; i++)
3762 if (! strcmp (string, linker_options[i]))
3768 /* This option is new; add it. */
3769 add_linker_option (string, strlen (string));
3773 /* Dump out the options accumulated previously using %x. */
3775 for (i = 0; i < n_linker_options; i++)
3777 do_spec_1 (linker_options[i], 1, NULL_PTR);
3778 /* Make each accumulated option a separate argument. */
3779 do_spec_1 (" ", 0, NULL_PTR);
3783 /* Dump out the options accumulated previously using -Wa,. */
3785 for (i = 0; i < n_assembler_options; i++)
3787 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3788 /* Make each accumulated option a separate argument. */
3789 do_spec_1 (" ", 0, NULL_PTR);
3793 /* Dump out the options accumulated previously using -Wp,. */
3795 for (i = 0; i < n_preprocessor_options; i++)
3797 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3798 /* Make each accumulated option a separate argument. */
3799 do_spec_1 (" ", 0, NULL_PTR);
3803 /* Here are digits and numbers that just process
3804 a certain constant string as a spec. */
3807 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3813 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3819 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3825 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3831 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3837 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3843 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3849 value = do_spec_1 (link_spec, 0, NULL_PTR);
3855 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3861 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3868 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3872 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3876 if (! strncmp (y, "-D", 2))
3877 /* Copy the whole option. */
3878 while (*y && *y != ' ' && *y != '\t')
3880 else if (*y == ' ' || *y == '\t')
3881 /* Copy whitespace to the result. */
3883 /* Don't copy other options. */
3890 value = do_spec_1 (buf, 0, NULL_PTR);
3898 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3902 /* Copy all of CPP_PREDEFINES into BUF,
3903 but put __ after every -D and at the end of each arg. */
3907 if (! strncmp (y, "-D", 2))
3915 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3917 /* Stick __ at front of macro name. */
3920 /* Arrange to stick __ at the end as well. */
3924 /* Copy the macro name. */
3925 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3934 /* Copy the value given, if any. */
3935 while (*y && *y != ' ' && *y != '\t')
3938 else if (*y == ' ' || *y == '\t')
3939 /* Copy whitespace to the result. */
3941 /* Don't copy -A options */
3947 /* Copy all of CPP_PREDEFINES into BUF,
3948 but put __ after every -D. */
3952 if (! strncmp (y, "-D", 2))
3957 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3959 /* Stick -D__ at front of macro name. */
3965 /* Copy the macro name. */
3966 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3969 /* Copy the value given, if any. */
3970 while (*y && *y != ' ' && *y != '\t')
3975 /* Do not copy this macro - we have just done it before */
3976 while (*y && *y != ' ' && *y != '\t')
3980 else if (*y == ' ' || *y == '\t')
3981 /* Copy whitespace to the result. */
3983 /* Don't copy -A options */
3989 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3993 if (! strncmp (y, "-A", 2))
3994 /* Copy the whole option. */
3995 while (*y && *y != ' ' && *y != '\t')
3997 else if (*y == ' ' || *y == '\t')
3998 /* Copy whitespace to the result. */
4000 /* Don't copy other options. */
4007 value = do_spec_1 (buf, 0, NULL_PTR);
4014 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
4019 /* Here we define characters other than letters and digits. */
4022 p = handle_braces (p);
4028 obstack_1grow (&obstack, '%');
4032 do_spec_1 (soft_matched_part, 1, NULL_PTR);
4033 do_spec_1 (" ", 0, NULL_PTR);
4036 /* Process a string found as the value of a spec given by name.
4037 This feature allows individual machine descriptions
4038 to add and use their own specs.
4039 %[...] modifies -D options the way %P does;
4040 %(...) uses the spec unmodified. */
4042 warning ("use of obsolete %%[ operator in specs");
4046 struct spec_list *sl;
4049 /* The string after the S/P is the name of a spec that is to be
4051 while (*p && *p != ')' && *p != ']')
4054 /* See if it's in the list */
4055 for (len = p - name, sl = specs; sl; sl = sl->next)
4056 if (sl->name_len == len && !strncmp (sl->name, name, len))
4058 name = *(sl->ptr_spec);
4060 fprintf (stderr, "Processing spec %c%s%c, which is '%s'\n",
4061 c, sl->name, (c == '(') ? ')' : ']', name);
4070 value = do_spec_1 (name, 0, NULL_PTR);
4076 char *x = (char *) alloca (strlen (name) * 2 + 1);
4081 /* Copy all of NAME into BUF, but put __ after
4082 every -D and at the end of each arg, */
4085 if (! strncmp (y, "-D", 2))
4095 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
4096 || *y == '}' || *y == 0))
4109 value = do_spec_1 (buf, 0, NULL_PTR);
4115 /* Discard the closing paren or bracket. */
4123 int c1 = *p++; /* Select first or second version number. */
4124 char *v = compiler_version;
4127 /* The format of the version string is
4128 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4130 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4131 while (! ISDIGIT (*v))
4133 if (v > compiler_version && v[-1] != '-')
4136 /* If desired, advance to second version number. */
4139 /* Set V after the first period. */
4140 while (ISDIGIT (*v))
4147 /* Set Q at the next period or at the end. */
4149 while (ISDIGIT (*q))
4151 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
4154 /* Put that part into the command. */
4155 obstack_grow (&obstack, v, q - v);
4161 if (input_from_pipe)
4162 do_spec_1 ("-", 0, NULL_PTR);
4171 /* Backslash: treat next character as ordinary. */
4176 /* Ordinary character: put it into the current argument. */
4177 obstack_1grow (&obstack, c);
4181 return 0; /* End of string */
4184 /* Return 0 if we call do_spec_1 and that returns -1. */
4190 char *filter, *body = NULL, *endbody;
4194 int include_blanks = 1;
4197 /* A '^' after the open-brace means to not give blanks before args. */
4198 include_blanks = 0, ++p;
4201 /* A `|' after the open-brace means,
4202 if the test fails, output a single minus sign rather than nothing.
4203 This is used in %{|!pipe:...}. */
4207 negate = suffix = 0;
4210 /* A `!' after the open-brace negates the condition:
4211 succeed if the specified switch is not present. */
4215 /* A `.' after the open-brace means test against the current suffix. */
4225 while (*p != ':' && *p != '}' && *p != '|') p++;
4227 if (*p == '|' && pipe_p)
4234 register int count = 1;
4235 register char *q = p;
4237 while (*q++ != ':') continue;
4253 body = p, endbody = p+1;
4258 int found = (input_suffix != 0
4259 && strlen (input_suffix) == p - filter
4260 && strncmp (input_suffix, filter, p - filter) == 0);
4266 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL_PTR) < 0)
4269 else if (p[-1] == '*' && p[0] == '}')
4271 /* Substitute all matching switches as separate args. */
4274 for (i = 0; i < n_switches; i++)
4275 if (!strncmp (switches[i].part1, filter, p - filter)
4276 && check_live_switch (i, p - filter))
4277 give_switch (i, 0, include_blanks);
4281 /* Test for presence of the specified switch. */
4285 /* If name specified ends in *, as in {x*:...},
4286 check for %* and handle that case. */
4287 if (p[-1] == '*' && !negate)
4292 /* First see whether we have %*. */
4296 if (*r == '%' && r[1] == '*')
4300 /* If we do, handle that case. */
4303 /* Substitute all matching switches as separate args.
4304 But do this by substituting for %*
4305 in the text that follows the colon. */
4307 unsigned hard_match_len = p - filter - 1;
4308 char *string = save_string (body, endbody - body - 1);
4310 for (i = 0; i < n_switches; i++)
4311 if (!strncmp (switches[i].part1, filter, hard_match_len)
4312 && check_live_switch (i, -1))
4314 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4315 /* Pass any arguments this switch has. */
4316 give_switch (i, 1, 1);
4319 /* We didn't match. Try again. */
4326 /* If name specified ends in *, as in {x*:...},
4327 check for presence of any switch name starting with x. */
4330 for (i = 0; i < n_switches; i++)
4332 unsigned hard_match_len = p - filter - 1;
4334 if (!strncmp (switches[i].part1, filter, hard_match_len)
4335 && check_live_switch (i, hard_match_len))
4341 /* Otherwise, check for presence of exact name specified. */
4344 for (i = 0; i < n_switches; i++)
4346 if (!strncmp (switches[i].part1, filter, p - filter)
4347 && switches[i].part1[p - filter] == 0
4348 && check_live_switch (i, -1))
4356 /* If it is as desired (present for %{s...}, absent for %{!s...})
4357 then substitute either the switch or the specified
4358 conditional text. */
4359 if (present != negate)
4363 give_switch (i, 0, include_blanks);
4367 if (do_spec_1 (save_string (body, endbody - body - 1),
4374 /* Here if a %{|...} conditional fails: output a minus sign,
4375 which means "standard output" or "standard input". */
4376 do_spec_1 ("-", 0, NULL_PTR);
4381 /* We didn't match; try again. */
4388 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4389 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4390 spec, or -1 if either exact match or %* is used.
4392 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4393 whose value does not begin with "no-" is obsoleted by the same value
4394 with the "no-", similarly for a switch with the "no-" prefix. */
4397 check_live_switch (switchnum, prefix_length)
4401 char *name = switches[switchnum].part1;
4404 /* In the common case of {<at-most-one-letter>*}, a negating
4405 switch would always match, so ignore that case. We will just
4406 send the conflicting switches to the compiler phase. */
4407 if (prefix_length >= 0 && prefix_length <= 1)
4410 /* If we already processed this switch and determined if it was
4411 live or not, return our past determination. */
4412 if (switches[switchnum].live_cond != 0)
4413 return switches[switchnum].live_cond > 0;
4415 /* Now search for duplicate in a manner that depends on the name. */
4419 for (i = switchnum + 1; i < n_switches; i++)
4420 if (switches[i].part1[0] == 'O')
4422 switches[switchnum].valid = 1;
4423 switches[switchnum].live_cond = -1;
4428 case 'W': case 'f': case 'm':
4429 if (! strncmp (name + 1, "no-", 3))
4431 /* We have Xno-YYY, search for XYYY. */
4432 for (i = switchnum + 1; i < n_switches; i++)
4433 if (switches[i].part1[0] == name[0]
4434 && ! strcmp (&switches[i].part1[1], &name[4]))
4436 switches[switchnum].valid = 1;
4437 switches[switchnum].live_cond = -1;
4443 /* We have XYYY, search for Xno-YYY. */
4444 for (i = switchnum + 1; i < n_switches; i++)
4445 if (switches[i].part1[0] == name[0]
4446 && switches[i].part1[1] == 'n'
4447 && switches[i].part1[2] == 'o'
4448 && switches[i].part1[3] == '-'
4449 && !strcmp (&switches[i].part1[4], &name[1]))
4451 switches[switchnum].valid = 1;
4452 switches[switchnum].live_cond = -1;
4459 /* Otherwise the switch is live. */
4460 switches[switchnum].live_cond = 1;
4464 /* Pass a switch to the current accumulating command
4465 in the same form that we received it.
4466 SWITCHNUM identifies the switch; it is an index into
4467 the vector of switches gcc received, which is `switches'.
4468 This cannot fail since it never finishes a command line.
4470 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4472 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4476 give_switch (switchnum, omit_first_word, include_blanks)
4478 int omit_first_word;
4481 if (!omit_first_word)
4483 do_spec_1 ("-", 0, NULL_PTR);
4484 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4487 if (switches[switchnum].args != 0)
4490 for (p = switches[switchnum].args; *p; p++)
4493 do_spec_1 (" ", 0, NULL_PTR);
4494 do_spec_1 (*p, 1, NULL_PTR);
4498 do_spec_1 (" ", 0, NULL_PTR);
4499 switches[switchnum].valid = 1;
4502 /* Search for a file named NAME trying various prefixes including the
4503 user's -B prefix and some standard ones.
4504 Return the absolute file name found. If nothing is found, return NAME. */
4512 /* Try multilib_dir if it is defined. */
4513 if (multilib_dir != NULL)
4517 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4518 strcpy (try, multilib_dir);
4519 strcat (try, dir_separator_str);
4522 newname = find_a_file (&startfile_prefixes, try, R_OK);
4524 /* If we don't find it in the multi library dir, then fall
4525 through and look for it in the normal places. */
4526 if (newname != NULL)
4530 newname = find_a_file (&startfile_prefixes, name, R_OK);
4531 return newname ? newname : name;
4534 /* Determine whether a directory exists. If LINKER, return 0 for
4535 certain fixed names not needed by the linker. If not LINKER, it is
4536 only important to return 0 if the host machine has a small ARG_MAX
4540 is_directory (path1, path2, linker)
4545 int len1 = strlen (path1);
4546 int len2 = strlen (path2);
4547 char *path = (char *) alloca (3 + len1 + len2);
4551 #ifndef SMALL_ARG_MAX
4556 /* Construct the path from the two parts. Ensure the string ends with "/.".
4557 The resulting path will be a directory even if the given path is a
4559 bcopy (path1, path, len1);
4560 bcopy (path2, path + len1, len2);
4561 cp = path + len1 + len2;
4562 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4563 *cp++ = DIR_SEPARATOR;
4567 /* Exclude directories that the linker is known to search. */
4570 && strcmp (path, concat (dir_separator_str, "lib",
4571 dir_separator_str, ".", NULL_PTR)) == 0)
4573 && strcmp (path, concat (dir_separator_str, "usr",
4574 dir_separator_str, "lib",
4575 dir_separator_str, ".", NULL_PTR)) == 0)))
4578 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4581 /* On fatal signals, delete all the temporary files. */
4584 fatal_error (signum)
4587 signal (signum, SIG_DFL);
4588 delete_failure_queue ();
4589 delete_temp_files ();
4590 /* Get the same signal again, this time not handled,
4591 so its normal effect occurs. */
4592 kill (getpid (), signum);
4603 int linker_was_run = 0;
4604 char *explicit_link_files;
4607 struct user_specs *uptr;
4609 p = argv[0] + strlen (argv[0]);
4610 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4613 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4614 signal (SIGINT, fatal_error);
4616 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4617 signal (SIGHUP, fatal_error);
4619 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4620 signal (SIGTERM, fatal_error);
4622 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4623 signal (SIGPIPE, fatal_error);
4627 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4629 obstack_init (&obstack);
4631 /* Build multilib_select, et. al from the separate lines that make up each
4632 multilib selection. */
4634 char **q = multilib_raw;
4637 obstack_init (&multilib_obstack);
4638 while ((p = *q++) != (char *) 0)
4639 obstack_grow (&multilib_obstack, p, strlen (p));
4641 obstack_1grow (&multilib_obstack, 0);
4642 multilib_select = obstack_finish (&multilib_obstack);
4644 q = multilib_matches_raw;
4645 while ((p = *q++) != (char *) 0)
4646 obstack_grow (&multilib_obstack, p, strlen (p));
4648 obstack_1grow (&multilib_obstack, 0);
4649 multilib_matches = obstack_finish (&multilib_obstack);
4653 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4657 obstack_1grow (&multilib_obstack, ' ');
4658 obstack_grow (&multilib_obstack,
4659 multilib_defaults_raw[i],
4660 strlen (multilib_defaults_raw[i]));
4664 obstack_1grow (&multilib_obstack, 0);
4665 multilib_defaults = obstack_finish (&multilib_obstack);
4668 /* Set up to remember the pathname of gcc and any options
4669 needed for collect. We use argv[0] instead of programname because
4670 we need the complete pathname. */
4671 obstack_init (&collect_obstack);
4672 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4673 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4674 putenv (obstack_finish (&collect_obstack));
4676 #ifdef INIT_ENVIRONMENT
4677 /* Set up any other necessary machine specific environment variables. */
4678 putenv (INIT_ENVIRONMENT);
4681 /* Choose directory for temp files. */
4683 #ifndef MKTEMP_EACH_FILE
4684 temp_filename = choose_temp_base ();
4685 temp_filename_length = strlen (temp_filename);
4688 /* Make a table of what switches there are (switches, n_switches).
4689 Make a table of specified input files (infiles, n_infiles).
4690 Decode switches that are handled locally. */
4692 process_command (argc, argv);
4697 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4699 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4700 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4703 for (i = 0; i < n_switches; i++)
4708 obstack_grow (&collect_obstack, " ", 1);
4711 obstack_grow (&collect_obstack, "'-", 2);
4712 q = switches[i].part1;
4713 while ((p = index (q,'\'')))
4715 obstack_grow (&collect_obstack, q, p-q);
4716 obstack_grow (&collect_obstack, "'\\''", 4);
4719 obstack_grow (&collect_obstack, q, strlen (q));
4720 obstack_grow (&collect_obstack, "'", 1);
4722 for (args = switches[i].args; args && *args; args++)
4724 obstack_grow (&collect_obstack, " '", 2);
4726 while ((p = index (q,'\'')))
4728 obstack_grow (&collect_obstack, q, p-q);
4729 obstack_grow (&collect_obstack, "'\\''", 4);
4732 obstack_grow (&collect_obstack, q, strlen (q));
4733 obstack_grow (&collect_obstack, "'", 1);
4736 obstack_grow (&collect_obstack, "\0", 1);
4737 putenv (obstack_finish (&collect_obstack));
4740 /* Initialize the vector of specs to just the default.
4741 This means one element containing 0s, as a terminator. */
4743 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4744 bcopy ((char *) default_compilers, (char *) compilers,
4745 sizeof default_compilers);
4746 n_compilers = n_default_compilers;
4748 /* Read specs from a file if there is one. */
4750 machine_suffix = concat (spec_machine, dir_separator_str,
4751 spec_version, dir_separator_str, NULL_PTR);
4752 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4754 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4755 /* Read the specs file unless it is a default one. */
4756 if (specs_file != 0 && strcmp (specs_file, "specs"))
4757 read_specs (specs_file, TRUE);
4761 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4762 for any override of as, ld and libraries. */
4763 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4764 + strlen (just_machine_suffix)
4765 + sizeof ("specs"));
4767 strcpy (specs_file, standard_exec_prefix);
4768 strcat (specs_file, just_machine_suffix);
4769 strcat (specs_file, "specs");
4770 if (access (specs_file, R_OK) == 0)
4771 read_specs (specs_file, TRUE);
4773 /* Process any user specified specs in the order given on the command
4775 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4777 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4778 read_specs (filename ? filename : uptr->filename, FALSE);
4781 /* If not cross-compiling, look for startfiles in the standard places. */
4782 /* The fact that these are done here, after reading the specs file,
4783 means that it cannot be found in these directories.
4784 But that's okay. It should never be there anyway. */
4785 if (*cross_compile == '0')
4787 #ifdef MD_EXEC_PREFIX
4788 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4789 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4792 #ifdef MD_STARTFILE_PREFIX
4793 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4797 #ifdef MD_STARTFILE_PREFIX_1
4798 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4802 /* If standard_startfile_prefix is relative, base it on
4803 standard_exec_prefix. This lets us move the installed tree
4804 as a unit. If GCC_EXEC_PREFIX is defined, base
4805 standard_startfile_prefix on that as well. */
4806 if (*standard_startfile_prefix == '/'
4807 || *standard_startfile_prefix == DIR_SEPARATOR
4808 || *standard_startfile_prefix == '$'
4810 /* Check for disk name on MS-DOS-based systems. */
4811 || (standard_startfile_prefix[1] == ':'
4812 && (standard_startfile_prefix[2] == DIR_SEPARATOR
4813 || standard_startfile_prefix[2] == '/'))
4816 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4820 if (gcc_exec_prefix)
4821 add_prefix (&startfile_prefixes,
4822 concat (gcc_exec_prefix, machine_suffix,
4823 standard_startfile_prefix, NULL_PTR),
4824 NULL_PTR, 0, 0, NULL_PTR);
4825 add_prefix (&startfile_prefixes,
4826 concat (standard_exec_prefix,
4828 standard_startfile_prefix, NULL_PTR),
4829 NULL_PTR, 0, 0, NULL_PTR);
4832 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4833 "BINUTILS", 0, 0, NULL_PTR);
4834 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4835 "BINUTILS", 0, 0, NULL_PTR);
4836 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4837 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
4842 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4843 add_prefix (&startfile_prefixes,
4844 concat (gcc_exec_prefix, machine_suffix,
4845 standard_startfile_prefix, NULL_PTR),
4846 "BINUTILS", 0, 0, NULL_PTR);
4849 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4850 if (gcc_exec_prefix)
4852 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4853 + strlen (spec_version)
4854 + strlen (spec_machine) + 3);
4855 strcpy (temp, gcc_exec_prefix);
4856 strcat (temp, spec_machine);
4857 strcat (temp, dir_separator_str);
4858 strcat (temp, spec_version);
4859 strcat (temp, dir_separator_str);
4860 gcc_exec_prefix = temp;
4863 /* Now we have the specs.
4864 Set the `valid' bits for switches that match anything in any spec. */
4866 validate_all_switches ();
4868 /* Now that we have the switches and the specs, set
4869 the subdirectory based on the options. */
4870 set_multilib_dir ();
4872 /* Warn about any switches that no pass was interested in. */
4874 for (i = 0; i < n_switches; i++)
4875 if (! switches[i].valid)
4876 error ("unrecognized option `-%s'", switches[i].part1);
4878 /* Obey some of the options. */
4880 if (print_search_dirs)
4882 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4883 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4884 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4888 if (print_file_name)
4890 printf ("%s\n", find_file (print_file_name));
4894 if (print_prog_name)
4896 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4897 printf ("%s\n", (newname ? newname : print_prog_name));
4901 if (print_multi_lib)
4903 print_multilib_info ();
4907 if (print_multi_directory)
4909 if (multilib_dir == NULL)
4912 printf ("%s\n", multilib_dir);
4916 if (print_help_list)
4922 printf ("\nReport bugs to egcs-bugs@cygnus.com.\n");
4923 printf ("Please see the file BUGS (included with the sources) first.\n");
4928 /* We do not exit here. Instead we have created a fake input file
4929 called 'help-dummy' which needs to be compiled, and we pass this
4930 on the the various sub-processes, along with the --help switch. */
4937 /* compiler_version is truncated at the first space when initialized
4938 from version string, so truncate version_string at the first space
4939 before comparing. */
4940 for (n = 0; version_string[n]; n++)
4941 if (version_string[n] == ' ')
4944 if (! strncmp (version_string, compiler_version, n)
4945 && compiler_version[n] == 0)
4946 fprintf (stderr, "gcc version %s\n", version_string);
4948 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4949 version_string, compiler_version);
4955 if (n_infiles == added_libraries)
4956 fatal ("No input files");
4958 /* Make a place to record the compiler output file names
4959 that correspond to the input files. */
4962 #ifdef LANG_SPECIFIC_DRIVER
4963 i += lang_specific_extra_outfiles;
4965 outfiles = (char **) xmalloc (i * sizeof (char *));
4966 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4968 /* Record which files were specified explicitly as link input. */
4970 explicit_link_files = xmalloc (n_infiles);
4971 bzero (explicit_link_files, n_infiles);
4973 for (i = 0; i < n_infiles; i++)
4975 register struct compiler *cp = 0;
4976 int this_file_error = 0;
4978 /* Tell do_spec what to substitute for %i. */
4980 input_filename = infiles[i].name;
4981 input_filename_length = strlen (input_filename);
4982 input_file_number = i;
4984 /* Use the same thing in %o, unless cp->spec says otherwise. */
4986 outfiles[i] = input_filename;
4988 /* Figure out which compiler from the file's suffix. */
4990 cp = lookup_compiler (infiles[i].name, input_filename_length,
4991 infiles[i].language);
4995 /* Ok, we found an applicable compiler. Run its spec. */
4996 /* First say how much of input_filename to substitute for %b */
5000 if (cp->spec[0][0] == '#')
5001 error ("%s: %s compiler not installed on this system",
5002 input_filename, &cp->spec[0][1]);
5004 input_basename = input_filename;
5005 for (p = input_filename; *p; p++)
5006 if (*p == '/' || *p == DIR_SEPARATOR)
5007 input_basename = p + 1;
5009 /* Find a suffix starting with the last period,
5010 and set basename_length to exclude that suffix. */
5011 basename_length = strlen (input_basename);
5012 p = input_basename + basename_length;
5013 while (p != input_basename && *p != '.') --p;
5014 if (*p == '.' && p != input_basename)
5016 basename_length = p - input_basename;
5017 input_suffix = p + 1;
5023 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5025 len += strlen (cp->spec[j]);
5027 p = (char *) xmalloc (len + 1);
5030 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5033 strcpy (p + len, cp->spec[j]);
5034 len += strlen (cp->spec[j]);
5037 value = do_spec (p);
5040 this_file_error = 1;
5043 /* If this file's name does not contain a recognized suffix,
5044 record it as explicit linker input. */
5047 explicit_link_files[i] = 1;
5049 /* Clear the delete-on-failure queue, deleting the files in it
5050 if this compilation failed. */
5052 if (this_file_error)
5054 delete_failure_queue ();
5057 /* If this compilation succeeded, don't delete those files later. */
5058 clear_failure_queue ();
5061 #ifdef LANG_SPECIFIC_DRIVER
5062 if (error_count == 0
5063 && lang_specific_pre_link ())
5067 /* Run ld to link all the compiler output files. */
5069 if (error_count == 0)
5071 int tmp = execution_count;
5073 /* We'll use ld if we can't find collect2. */
5074 if (! strcmp (linker_name_spec, "collect2"))
5076 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
5078 linker_name_spec = "ld";
5080 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5082 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
5083 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
5085 value = do_spec (link_command_spec);
5088 linker_was_run = (tmp != execution_count);
5091 /* Warn if a -B option was specified but the prefix was never used. */
5092 unused_prefix_warnings (&exec_prefixes);
5093 unused_prefix_warnings (&startfile_prefixes);
5095 /* If options said don't run linker,
5096 complain about input files to be given to the linker. */
5098 if (! linker_was_run && error_count == 0)
5099 for (i = 0; i < n_infiles; i++)
5100 if (explicit_link_files[i])
5101 error ("%s: linker input file unused since linking not done",
5104 /* Delete some or all of the temporary files we made. */
5107 delete_failure_queue ();
5108 delete_temp_files ();
5110 if (print_help_list)
5112 printf ("\nReport bugs to egcs-bugs@cygnus.com.\n");
5113 printf ("Please see the file BUGS (included with the sources) first.\n");
5116 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
5121 /* Find the proper compilation spec for the file name NAME,
5122 whose length is LENGTH. LANGUAGE is the specified language,
5123 or 0 if this file is to be passed to the linker. */
5125 static struct compiler *
5126 lookup_compiler (name, length, language)
5131 struct compiler *cp;
5133 /* If this was specified by the user to be a linker input, indicate that. */
5134 if (language != 0 && language[0] == '*')
5137 /* Otherwise, look for the language, if one is spec'd. */
5140 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5141 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
5144 error ("language %s not recognized", language);
5148 /* Look for a suffix. */
5149 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5151 if (/* The suffix `-' matches only the file name `-'. */
5152 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
5153 || (strlen (cp->suffix) < length
5154 /* See if the suffix matches the end of NAME. */
5156 && ((!strcmp (cp->suffix,
5157 name + length - strlen (cp->suffix))
5158 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5159 && !strcasecmp (cp->suffix,
5160 name + length - strlen (cp->suffix)))
5162 && !strcmp (cp->suffix,
5163 name + length - strlen (cp->suffix))
5167 if (cp->spec[0][0] == '@')
5169 struct compiler *new;
5171 /* An alias entry maps a suffix to a language.
5172 Search for the language; pass 0 for NAME and LENGTH
5173 to avoid infinite recursion if language not found.
5174 Construct the new compiler spec. */
5175 language = cp->spec[0] + 1;
5176 new = (struct compiler *) xmalloc (sizeof (struct compiler));
5177 new->suffix = cp->suffix;
5178 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
5179 (char *) new->spec, sizeof new->spec);
5183 /* A non-alias entry: return it. */
5195 register char *value = (char *) malloc (size);
5197 fatal ("virtual memory exhausted");
5202 xrealloc (ptr, size)
5206 register char *value = (char *) realloc (ptr, size);
5208 fatal ("virtual memory exhausted");
5212 /* This function is based on the one in libiberty. */
5215 concat VPROTO((char *first, ...))
5217 register int length;
5218 register char *newstr;
5226 /* First compute the size of the result and get sufficient memory. */
5228 VA_START (args, first);
5230 first = va_arg (args, char *);
5238 length += strlen (arg);
5239 arg = va_arg (args, char *);
5242 newstr = (char *) xmalloc (length + 1);
5245 /* Now copy the individual pieces to the result string. */
5247 VA_START (args, first);
5249 first = va_arg (args, char *);
5258 arg = va_arg (args, char *);
5267 save_string (s, len)
5271 register char *result = xmalloc (len + 1);
5273 bcopy (s, result, len);
5279 pfatal_with_name (name)
5282 fatal ("%s: %s", name, my_strerror (errno));
5286 perror_with_name (name)
5289 error ("%s: %s", name, my_strerror (errno));
5293 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5297 int save_errno = errno;
5301 /* Space for trailing '\0' is in %s. */
5302 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5303 sprintf (msg, errmsg_fmt, errmsg_arg);
5307 fatal ("%s: %s", errmsg_fmt, my_strerror (save_errno));
5310 /* More 'friendly' abort that prints the line and file.
5311 config.h can #define abort fancy_abort if you like that sort of thing. */
5316 fatal ("Internal gcc abort.");
5319 /* Output an error message and exit */
5322 fatal VPROTO((char *format, ...))
5329 VA_START (ap, format);
5332 format = va_arg (ap, char *);
5335 fprintf (stderr, "%s: ", programname);
5336 vfprintf (stderr, format, ap);
5338 fprintf (stderr, "\n");
5339 delete_temp_files ();
5344 error VPROTO((char *format, ...))
5351 VA_START (ap, format);
5354 format = va_arg (ap, char *);
5357 fprintf (stderr, "%s: ", programname);
5358 vfprintf (stderr, format, ap);
5361 fprintf (stderr, "\n");
5365 validate_all_switches ()
5367 struct compiler *comp;
5370 struct spec_list *spec;
5372 for (comp = compilers; comp->spec[0]; comp++)
5375 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5379 if (c == '%' && *p == '{')
5380 /* We have a switch spec. */
5381 validate_switches (p + 1);
5385 /* look through the linked list of specs read from the specs file */
5386 for (spec = specs; spec ; spec = spec->next)
5388 p = *(spec->ptr_spec);
5390 if (c == '%' && *p == '{')
5391 /* We have a switch spec. */
5392 validate_switches (p + 1);
5395 p = link_command_spec;
5397 if (c == '%' && *p == '{')
5398 /* We have a switch spec. */
5399 validate_switches (p + 1);
5402 /* Look at the switch-name that comes after START
5403 and mark as valid all supplied switches that match it. */
5406 validate_switches (start)
5409 register char *p = start;
5424 while (*p != ':' && *p != '}') p++;
5428 else if (p[-1] == '*')
5430 /* Mark all matching switches as valid. */
5432 for (i = 0; i < n_switches; i++)
5433 if (!strncmp (switches[i].part1, filter, p - filter))
5434 switches[i].valid = 1;
5438 /* Mark an exact matching switch as valid. */
5439 for (i = 0; i < n_switches; i++)
5441 if (!strncmp (switches[i].part1, filter, p - filter)
5442 && switches[i].part1[p - filter] == 0)
5443 switches[i].valid = 1;
5448 /* Check whether a particular argument was used. The first time we
5449 canonicalize the switches to keep only the ones we care about. */
5463 static struct mswitchstr *mswitches;
5464 static int n_mswitches;
5469 struct mswitchstr *matches;
5473 /* Break multilib_matches into the component strings of string and replacement
5475 for (q = multilib_matches; *q != '\0'; q++)
5479 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5481 q = multilib_matches;
5492 matches[i].len = q - matches[i].str;
5494 matches[i].replace = ++q;
5495 while (*q != ';' && *q != '\0')
5501 matches[i].rep_len = q - matches[i].replace;
5509 /* Now build a list of the replacement string for switches that we care
5510 about. Make sure we allocate at least one entry. This prevents
5511 xmalloc from calling fatal, and prevents us from re-executing this
5514 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5515 * (n_switches ? n_switches : 1));
5516 for (i = 0; i < n_switches; i++)
5518 int xlen = strlen (switches[i].part1);
5519 for (j = 0; j < cnt; j++)
5520 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5522 mswitches[n_mswitches].str = matches[j].replace;
5523 mswitches[n_mswitches].len = matches[j].rep_len;
5524 mswitches[n_mswitches].replace = (char *)0;
5525 mswitches[n_mswitches].rep_len = 0;
5532 for (i = 0; i < n_mswitches; i++)
5533 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5540 default_arg (p, len)
5546 for (start = multilib_defaults; *start != '\0'; start = end+1)
5548 while (*start == ' ' || *start == '\t')
5554 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5557 if ((end - start) == len && strncmp (p, start, len) == 0)
5567 /* Work out the subdirectory to use based on the
5568 options. The format of multilib_select is a list of elements.
5569 Each element is a subdirectory name followed by a list of options
5570 followed by a semicolon. gcc will consider each line in turn. If
5571 none of the options beginning with an exclamation point are
5572 present, and all of the other options are present, that
5573 subdirectory will be used. */
5578 char *p = multilib_select;
5580 char *this_path, *this_arg;
5586 /* Ignore newlines. */
5593 /* Get the initial path. */
5601 this_path_len = p - this_path;
5603 /* Check the arguments. */
5618 while (*p != ' ' && *p != ';')
5625 if (*this_arg != '!')
5633 /* If this is a default argument, we can just ignore it.
5634 This is true even if this_arg begins with '!'. Beginning
5635 with '!' does not mean that this argument is necessarily
5636 inappropriate for this library: it merely means that
5637 there is a more specific library which uses this
5638 argument. If this argument is a default, we need not
5639 consider that more specific library. */
5640 if (! default_arg (this_arg, p - this_arg))
5642 ok = used_arg (this_arg, p - this_arg);
5653 if (this_path_len != 1
5654 || this_path[0] != '.')
5656 multilib_dir = xmalloc (this_path_len + 1);
5657 strncpy (multilib_dir, this_path, this_path_len);
5658 multilib_dir[this_path_len] = '\0';
5667 /* Print out the multiple library subdirectory selection
5668 information. This prints out a series of lines. Each line looks
5669 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5670 required. Only the desired options are printed out, the negative
5671 matches. The options are print without a leading dash. There are
5672 no spaces to make it easy to use the information in the shell.
5673 Each subdirectory is printed only once. This assumes the ordering
5674 generated by the genmultilib script. */
5677 print_multilib_info ()
5679 char *p = multilib_select;
5680 char *last_path = 0, *this_path;
5682 int last_path_len = 0;
5686 /* Ignore newlines. */
5693 /* Get the initial path. */
5702 /* If this is a duplicate, skip it. */
5703 skip = (last_path != 0 && p - this_path == last_path_len
5704 && ! strncmp (last_path, this_path, last_path_len));
5706 last_path = this_path;
5707 last_path_len = p - this_path;
5709 /* If this directory requires any default arguments, we can skip
5710 it. We will already have printed a directory identical to
5711 this one which does not require that default argument. */
5729 while (*q != ' ' && *q != ';')
5737 && default_arg (arg, q - arg))
5752 for (p1 = last_path; p1 < p; p1++)
5771 use_arg = *p != '!';
5776 while (*p != ' ' && *p != ';')
5791 /* If there are extra options, print them now */
5792 if (multilib_extra && *multilib_extra)
5794 int print_at = TRUE;
5797 for (q = multilib_extra; *q != '\0'; q++)