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
78 /* Define O_RDONLY if the system hasn't defined it for us. */
87 /* Test if something is a normal file. */
89 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
92 /* Test if something is a directory. */
94 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
97 /* By default there is no special suffix for executables. */
98 #ifdef EXECUTABLE_SUFFIX
99 #define HAVE_EXECUTABLE_SUFFIX
101 #define EXECUTABLE_SUFFIX ""
104 /* By default, the suffix for object files is ".o". */
106 #define HAVE_OBJECT_SUFFIX
108 #define OBJECT_SUFFIX ".o"
111 /* By default, colon separates directories in a path. */
112 #ifndef PATH_SEPARATOR
113 #define PATH_SEPARATOR ':'
116 #ifndef DIR_SEPARATOR
117 #define DIR_SEPARATOR '/'
120 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
122 #define obstack_chunk_alloc xmalloc
123 #define obstack_chunk_free free
125 #ifndef GET_ENVIRONMENT
126 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
129 extern char *choose_temp_base PROTO((void));
131 #ifndef HAVE_STRERROR
133 extern char *sys_errlist[];
135 extern char *strerror();
139 #define kill(p,s) raise(s)
142 /* If a stage of compilation returns an exit status >= 1,
143 compilation of that file ceases. */
145 #define MIN_FATAL_STATUS 1
147 /* Flag saying to print the directories gcc will search through looking for
148 programs, libraries, etc. */
150 static int print_search_dirs;
152 /* Flag saying to print the full filename of this file
153 as found through our usual search mechanism. */
155 static char *print_file_name = NULL;
157 /* As print_file_name, but search for executable file. */
159 static char *print_prog_name = NULL;
161 /* Flag saying to print the relative path we'd use to
162 find libgcc.a given the current compiler flags. */
164 static int print_multi_directory;
166 /* Flag saying to print the list of subdirectories and
167 compiler flags used to select them in a standard form. */
169 static int print_multi_lib;
171 /* Flag indicating whether we should print the command and arguments */
173 static int verbose_flag;
175 /* Nonzero means write "temp" files in source directory
176 and use the source file's name in them, and don't delete them. */
178 static int save_temps_flag;
180 /* The compiler version. */
182 static char *compiler_version;
184 /* The target version specified with -V */
186 static char *spec_version = DEFAULT_TARGET_VERSION;
188 /* The target machine specified with -b. */
190 static char *spec_machine = DEFAULT_TARGET_MACHINE;
192 /* Nonzero if cross-compiling.
193 When -b is used, the value comes from the `specs' file. */
196 static char *cross_compile = "1";
198 static char *cross_compile = "0";
201 /* The number of errors that have occurred; the link phase will not be
202 run if this is non-zero. */
203 static int error_count = 0;
205 /* This is the obstack which we use to allocate many strings. */
207 static struct obstack obstack;
209 /* This is the obstack to build an environment variable to pass to
210 collect2 that describes all of the relevant switches of what to
211 pass the compiler in building the list of pointers to constructors
214 static struct obstack collect_obstack;
216 extern char *version_string;
218 /* Forward declaration for prototypes. */
221 static void init_spec PROTO((void));
222 static void read_specs PROTO((char *, int));
223 static void set_spec PROTO((char *, char *));
224 static struct compiler *lookup_compiler PROTO((char *, size_t, char *));
225 static char *build_search_list PROTO((struct path_prefix *, char *, int));
226 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
227 static char *find_a_file PROTO((struct path_prefix *, char *, int));
228 static void add_prefix PROTO((struct path_prefix *, char *, char *,
230 static char *skip_whitespace PROTO((char *));
231 static void record_temp_file PROTO((char *, int, int));
232 static void delete_if_ordinary PROTO((char *));
233 static void delete_temp_files PROTO((void));
234 static void delete_failure_queue PROTO((void));
235 static void clear_failure_queue PROTO((void));
236 static int check_live_switch PROTO((int, int));
237 static char *handle_braces PROTO((char *));
238 static char *save_string PROTO((char *, int));
239 static char *concat PVPROTO((char *, ...));
240 static int do_spec PROTO((char *));
241 static int do_spec_1 PROTO((char *, int, char *));
242 static char *find_file PROTO((char *));
243 static int is_directory PROTO((char *, char *, int));
244 static void validate_switches PROTO((char *));
245 static void validate_all_switches PROTO((void));
246 static void give_switch PROTO((int, int, int));
247 static int used_arg PROTO((char *, int));
248 static int default_arg PROTO((char *, int));
249 static void set_multilib_dir PROTO((void));
250 static void print_multilib_info PROTO((void));
251 static void pfatal_with_name PROTO((char *));
252 static void perror_with_name PROTO((char *));
253 static void pfatal_pexecute PROTO((char *, char *));
255 static void fatal PVPROTO((char *, ...));
256 static void error PVPROTO((char *, ...));
258 /* We must not provide any prototype here, even if ANSI C. */
259 static void fatal PROTO(());
260 static void error PROTO(());
267 #ifdef LANG_SPECIFIC_DRIVER
268 extern void lang_specific_driver PROTO ((void (*) (), int *, char ***));
271 /* Specs are strings containing lines, each of which (if not blank)
272 is made up of a program name, and arguments separated by spaces.
273 The program name must be exact and start from root, since no path
274 is searched and it is unreliable to depend on the current working directory.
275 Redirection of input or output is not supported; the subprograms must
276 accept filenames saying what files to read and write.
278 In addition, the specs can contain %-sequences to substitute variable text
279 or for conditional text. Here is a table of all defined %-sequences.
280 Note that spaces are not generated automatically around the results of
281 expanding these sequences; therefore, you can concatenate them together
282 or with constant text in a single argument.
284 %% substitute one % into the program name or argument.
285 %i substitute the name of the input file being processed.
286 %b substitute the basename of the input file being processed.
287 This is the substring up to (and not including) the last period
288 and not including the directory.
289 %g substitute the temporary-file-name-base. This is a string chosen
290 once per compilation. Different temporary file names are made by
291 concatenation of constant strings on the end, as in `%g.s'.
292 %g also has the same effect of %d.
293 %u like %g, but make the temporary file name unique.
294 %U returns the last file name generated with %u.
295 %d marks the argument containing or following the %d as a
296 temporary file name, so that that file will be deleted if CC exits
297 successfully. Unlike %g, this contributes no text to the argument.
298 %w marks the argument containing or following the %w as the
299 "output file" of this compilation. This puts the argument
300 into the sequence of arguments that %o will substitute later.
302 like %{...} but mark last argument supplied within
303 as a file to be deleted on failure.
304 %o substitutes the names of all the output files, with spaces
305 automatically placed around them. You should write spaces
306 around the %o as well or the results are undefined.
307 %o is for use in the specs for running the linker.
308 Input files whose names have no recognized suffix are not compiled
309 at all, but they are included among the output files, so they will
311 %O substitutes the suffix for object files.
312 %p substitutes the standard macro predefinitions for the
313 current target machine. Use this when running cpp.
314 %P like %p, but puts `__' before and after the name of each macro.
315 (Except macros that already have __.)
317 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
318 %s current argument is the name of a library or startup file of some sort.
319 Search for that file in a standard list of directories
320 and substitute the full name found.
321 %eSTR Print STR as an error message. STR is terminated by a newline.
322 Use this when inconsistent options are detected.
323 %x{OPTION} Accumulate an option for %X.
324 %X Output the accumulated linker options specified by compilations.
325 %Y Output the accumulated assembler options specified by compilations.
326 %Z Output the accumulated preprocessor options specified by compilations.
327 %v1 Substitute the major version number of GCC.
328 (For version 2.5.n, this is 2.)
329 %v2 Substitute the minor version number of GCC.
330 (For version 2.5.n, this is 5.)
331 %a process ASM_SPEC as a spec.
332 This allows config.h to specify part of the spec for running as.
333 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
334 used here. This can be used to run a post-processor after the
335 assembler has done it's job.
336 %D Dump out a -L option for each directory in startfile_prefixes.
337 If multilib_dir is set, extra entries are generated with it affixed.
338 %l process LINK_SPEC as a spec.
339 %L process LIB_SPEC as a spec.
340 %G process LIBGCC_SPEC as a spec.
341 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
342 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
343 %c process SIGNED_CHAR_SPEC as a spec.
344 %C process CPP_SPEC as a spec. A capital C is actually used here.
345 %1 process CC1_SPEC as a spec.
346 %2 process CC1PLUS_SPEC as a spec.
347 %| output "-" if the input for the current command is coming from a pipe.
348 %* substitute the variable part of a matched option. (See below.)
349 Note that each comma in the substituted string is replaced by
351 %{S} substitutes the -S switch, if that switch was given to CC.
352 If that switch was not specified, this substitutes nothing.
353 Here S is a metasyntactic variable.
354 %{S*} substitutes all the switches specified to CC whose names start
355 with -S. This is used for -o, -D, -I, etc; switches that take
356 arguments. CC considers `-o foo' as being one switch whose
357 name starts with `o'. %{o*} would substitute this text,
358 including the space; thus, two arguments would be generated.
359 %{^S*} likewise, but don't put a blank between a switch and any args.
360 %{S*:X} substitutes X if one or more switches whose names start with -S are
361 specified to CC. Note that the tail part of the -S option
362 (i.e. the part matched by the `*') will be substituted for each
363 occurrence of %* within X.
364 %{S:X} substitutes X, but only if the -S switch was given to CC.
365 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
366 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
367 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
368 %{.S:X} substitutes X, but only if processing a file with suffix S.
369 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
370 %(Spec) processes a specification defined in a specs file as *Spec:
371 %[Spec] as above, but put __ around -D arguments
373 The conditional text X in a %{S:X} or %{!S:X} construct may contain
374 other nested % constructs or spaces, or even newlines. They are
375 processed as usual, as described above.
377 The -O, -f, -m, and -W switches are handled specifically in these
378 constructs. If another value of -O or the negated form of a -f, -m, or
379 -W switch is found later in the command line, the earlier switch
380 value is ignored, except with {S*} where S is just one letter; this
381 passes all matching options.
383 The character | is used to indicate that a command should be piped to
384 the following command, but only if -pipe is specified.
386 Note that it is built into CC which switches take arguments and which
387 do not. You might think it would be useful to generalize this to
388 allow each compiler's spec to say which switches take arguments. But
389 this cannot be done in a consistent fashion. CC cannot even decide
390 which input files have been specified without knowing which switches
391 take arguments, and it must know which input files to compile in order
392 to tell which compilers to run.
394 CC also knows implicitly that arguments starting in `-l' are to be
395 treated as compiler output files, and passed to the linker in their
396 proper position among the other output files. */
398 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
400 /* config.h can define ASM_SPEC to provide extra args to the assembler
401 or extra switch-translations. */
406 /* config.h can define ASM_FINAL_SPEC to run a post processor after
407 the assembler has run. */
408 #ifndef ASM_FINAL_SPEC
409 #define ASM_FINAL_SPEC ""
412 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
413 or extra switch-translations. */
418 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
419 or extra switch-translations. */
424 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
425 or extra switch-translations. */
427 #define CC1PLUS_SPEC ""
430 /* config.h can define LINK_SPEC to provide extra args to the linker
431 or extra switch-translations. */
436 /* config.h can define LIB_SPEC to override the default libraries. */
438 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
441 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
444 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
445 /* Have gcc do the search for libgcc.a. */
446 #define LIBGCC_SPEC "libgcc.a%s"
448 #define LIBGCC_SPEC "-lgcc"
452 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
453 #ifndef STARTFILE_SPEC
454 #define STARTFILE_SPEC \
455 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
458 /* config.h can define SWITCHES_NEED_SPACES to control which options
459 require spaces between the option and the argument. */
460 #ifndef SWITCHES_NEED_SPACES
461 #define SWITCHES_NEED_SPACES ""
464 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
466 #define ENDFILE_SPEC ""
469 /* This spec is used for telling cpp whether char is signed or not. */
470 #ifndef SIGNED_CHAR_SPEC
471 /* Use #if rather than ?:
472 because MIPS C compiler rejects like ?: in initializers. */
473 #if DEFAULT_SIGNED_CHAR
474 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
476 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
480 static char *cpp_spec = CPP_SPEC;
481 static char *cpp_predefines = CPP_PREDEFINES;
482 static char *cc1_spec = CC1_SPEC;
483 static char *cc1plus_spec = CC1PLUS_SPEC;
484 static char *signed_char_spec = SIGNED_CHAR_SPEC;
485 static char *asm_spec = ASM_SPEC;
486 static char *asm_final_spec = ASM_FINAL_SPEC;
487 static char *link_spec = LINK_SPEC;
488 static char *lib_spec = LIB_SPEC;
489 static char *libgcc_spec = LIBGCC_SPEC;
490 static char *endfile_spec = ENDFILE_SPEC;
491 static char *startfile_spec = STARTFILE_SPEC;
492 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
494 /* Some compilers have limits on line lengths, and the multilib_select
495 and/or multilib_matches strings can be very long, so we build them at
497 static struct obstack multilib_obstack;
498 static char *multilib_select;
499 static char *multilib_matches;
500 static char *multilib_defaults;
501 #include "multilib.h"
503 /* Check whether a particular argument is a default argument. */
505 #ifndef MULTILIB_DEFAULTS
506 #define MULTILIB_DEFAULTS { "" }
509 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
512 struct user_specs *next;
516 static struct user_specs *user_specs_head, *user_specs_tail;
518 /* This defines which switch letters take arguments. */
520 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
521 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
522 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
523 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
524 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
525 || (CHAR) == 'B' || (CHAR) == 'b')
527 #ifndef SWITCH_TAKES_ARG
528 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
531 /* This defines which multi-letter switches take arguments. */
533 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
534 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
535 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
536 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
537 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
538 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
539 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
541 #ifndef WORD_SWITCH_TAKES_ARG
542 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
545 /* Record the mapping from file suffixes for compilation specs. */
549 char *suffix; /* Use this compiler for input files
550 whose names end in this suffix. */
552 char *spec[4]; /* To use this compiler, concatenate these
553 specs and pass to do_spec. */
556 /* Pointer to a vector of `struct compiler' that gives the spec for
557 compiling a file, based on its suffix.
558 A file that does not end in any of these suffixes will be passed
559 unchanged to the loader and nothing else will be done to it.
561 An entry containing two 0s is used to terminate the vector.
563 If multiple entries match a file, the last matching one is used. */
565 static struct compiler *compilers;
567 /* Number of entries in `compilers', not counting the null terminator. */
569 static int n_compilers;
571 /* The default list of file name suffixes and their compilation specs. */
573 static struct compiler default_compilers[] =
575 /* Add lists of suffixes of known languages here. If those languages
576 were not present when we built the driver, we will hit these copies
577 and be given a more meaningful error than "file not used since
578 linking is not done". */
579 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}}, {".c++", {"#C++"}},
580 {".C", {"#C++"}}, {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
581 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
582 {".fpp", {"#Fortran"}},
583 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
584 /* Next come the entries for C. */
587 {"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
588 %{C:%{!E:%eGNU C does not support -C without using -E}}\
589 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
590 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
591 %{ansi:-trigraphs -D__STRICT_ANSI__}\
592 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
593 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
594 %{traditional} %{ftraditional:-traditional}\
595 %{traditional-cpp:-traditional}\
596 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
597 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
598 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
599 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
600 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
601 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
603 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
604 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
606 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
607 %{!pipe:%g.s} %A\n }}}}"}},
609 {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
610 %{C:%{!E:%eGNU C does not support -C without using -E}}\
611 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
612 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
613 %{ansi:-trigraphs -D__STRICT_ANSI__}\
614 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
615 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
616 %{traditional} %{ftraditional:-traditional}\
617 %{traditional-cpp:-traditional}\
618 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
620 %{!E:%e-E required when input is from standard input}"}},
621 {".m", {"@objective-c"}},
623 {"cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
624 %{C:%{!E:%eGNU C does not support -C without using -E}}\
625 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
626 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
627 %{ansi:-trigraphs -D__STRICT_ANSI__}\
628 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
629 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
630 %{traditional} %{ftraditional:-traditional}\
631 %{traditional-cpp:-traditional}\
632 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
633 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
634 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
635 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
636 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
637 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
638 -lang-objc %{gen-decls} \
640 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
641 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
643 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
644 %{!pipe:%g.s} %A\n }}}}"}},
645 {".h", {"@c-header"}},
647 {"%{!E:%eCompilation of header file requested} \
648 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
649 %{C:%{!E:%eGNU C does not support -C without using -E}}\
650 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
651 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
652 %{ansi:-trigraphs -D__STRICT_ANSI__}\
653 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
654 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
655 %{traditional} %{ftraditional:-traditional}\
656 %{traditional-cpp:-traditional}\
657 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
659 {".i", {"@cpp-output"}},
661 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
662 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
663 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
665 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
666 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
668 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
669 %{!pipe:%g.s} %A\n }}}}"}},
670 {".s", {"@assembler"}},
672 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
673 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
675 {".S", {"@assembler-with-cpp"}},
676 {"@assembler-with-cpp",
677 {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
678 %{C:%{!E:%eGNU C does not support -C without using -E}}\
679 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
680 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
681 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
682 %{traditional} %{ftraditional:-traditional}\
683 %{traditional-cpp:-traditional}\
684 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
685 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
686 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
687 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
688 %{!pipe:%g.s} %A\n }}}}"}},
690 /* Mark end of table */
694 /* Number of elements in default_compilers, not counting the terminator. */
696 static int n_default_compilers
697 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
699 /* Here is the spec for running the linker, after compiling all files. */
701 /* -u* was put back because both BSD and SysV seem to support it. */
702 /* %{static:} simply prevents an error message if the target machine
703 doesn't handle -static. */
704 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
705 scripts which exist in user specified directories, or in standard
707 #ifdef LINK_LIBGCC_SPECIAL
708 /* Don't generate -L options. */
709 static char *link_command_spec = "\
711 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
712 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
713 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
715 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
716 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
721 static char *link_command_spec = "\
723 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
724 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
725 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
726 %{static:} %{L*} %D %o\
727 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
728 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
733 /* A vector of options to give to the linker.
734 These options are accumulated by %x,
735 and substituted into the linker command with %X. */
736 static int n_linker_options;
737 static char **linker_options;
739 /* A vector of options to give to the assembler.
740 These options are accumulated by -Wa,
741 and substituted into the assembler command with %Y. */
742 static int n_assembler_options;
743 static char **assembler_options;
745 /* A vector of options to give to the preprocessor.
746 These options are accumulated by -Wp,
747 and substituted into the preprocessor command with %Z. */
748 static int n_preprocessor_options;
749 static char **preprocessor_options;
751 /* Define how to map long options into short ones. */
753 /* This structure describes one mapping. */
756 /* The long option's name. */
758 /* The equivalent short option. */
760 /* Argument info. A string of flag chars; NULL equals no options.
761 a => argument required.
762 o => argument optional.
763 j => join argument to equivalent, making one word.
764 * => require other text after NAME as an argument. */
768 /* This is the table of mappings. Mappings are tried sequentially
769 for each option encountered; the first one that matches, wins. */
771 struct option_map option_map[] =
773 {"--all-warnings", "-Wall", 0},
774 {"--ansi", "-ansi", 0},
775 {"--assemble", "-S", 0},
776 {"--assert", "-A", "a"},
777 {"--comments", "-C", 0},
778 {"--compile", "-c", 0},
779 {"--debug", "-g", "oj"},
780 {"--define-macro", "-D", "aj"},
781 {"--dependencies", "-M", 0},
782 {"--dump", "-d", "a"},
783 {"--dumpbase", "-dumpbase", "a"},
784 {"--entry", "-e", 0},
785 {"--extra-warnings", "-W", 0},
786 {"--for-assembler", "-Wa", "a"},
787 {"--for-linker", "-Xlinker", "a"},
788 {"--force-link", "-u", "a"},
789 {"--imacros", "-imacros", "a"},
790 {"--include", "-include", "a"},
791 {"--include-barrier", "-I-", 0},
792 {"--include-directory", "-I", "aj"},
793 {"--include-directory-after", "-idirafter", "a"},
794 {"--include-prefix", "-iprefix", "a"},
795 {"--include-with-prefix", "-iwithprefix", "a"},
796 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
797 {"--include-with-prefix-after", "-iwithprefix", "a"},
798 {"--language", "-x", "a"},
799 {"--library-directory", "-L", "a"},
800 {"--machine", "-m", "aj"},
801 {"--machine-", "-m", "*j"},
802 {"--no-line-commands", "-P", 0},
803 {"--no-precompiled-includes", "-noprecomp", 0},
804 {"--no-standard-includes", "-nostdinc", 0},
805 {"--no-standard-libraries", "-nostdlib", 0},
806 {"--no-warnings", "-w", 0},
807 {"--optimize", "-O", "oj"},
808 {"--output", "-o", "a"},
809 {"--pedantic", "-pedantic", 0},
810 {"--pedantic-errors", "-pedantic-errors", 0},
811 {"--pipe", "-pipe", 0},
812 {"--prefix", "-B", "a"},
813 {"--preprocess", "-E", 0},
814 {"--print-search-dirs", "-print-search-dirs", 0},
815 {"--print-file-name", "-print-file-name=", "aj"},
816 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
817 {"--print-missing-file-dependencies", "-MG", 0},
818 {"--print-multi-lib", "-print-multi-lib", 0},
819 {"--print-multi-directory", "-print-multi-directory", 0},
820 {"--print-prog-name", "-print-prog-name=", "aj"},
821 {"--profile", "-p", 0},
822 {"--profile-blocks", "-a", 0},
823 {"--quiet", "-q", 0},
824 {"--save-temps", "-save-temps", 0},
825 {"--shared", "-shared", 0},
826 {"--silent", "-q", 0},
827 {"--specs", "-specs=", "aj"},
828 {"--static", "-static", 0},
829 {"--symbolic", "-symbolic", 0},
830 {"--target", "-b", "a"},
831 {"--trace-includes", "-H", 0},
832 {"--traditional", "-traditional", 0},
833 {"--traditional-cpp", "-traditional-cpp", 0},
834 {"--trigraphs", "-trigraphs", 0},
835 {"--undefine-macro", "-U", "aj"},
836 {"--use-version", "-V", "a"},
837 {"--user-dependencies", "-MM", 0},
838 {"--verbose", "-v", 0},
839 {"--version", "-dumpversion", 0},
840 {"--warn-", "-W", "*j"},
841 {"--write-dependencies", "-MD", 0},
842 {"--write-user-dependencies", "-MMD", 0},
846 /* Translate the options described by *ARGCP and *ARGVP.
847 Make a new vector and store it back in *ARGVP,
848 and store its length in *ARGVC. */
851 translate_options (argcp, argvp)
857 char **argv = *argvp;
858 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
862 newv[newindex++] = argv[i++];
866 /* Translate -- options. */
867 if (argv[i][0] == '-' && argv[i][1] == '-')
869 /* Find a mapping that applies to this option. */
870 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
872 size_t optlen = strlen (option_map[j].name);
873 size_t arglen = strlen (argv[i]);
874 size_t complen = arglen > optlen ? optlen : arglen;
875 char *arginfo = option_map[j].arg_info;
880 if (!strncmp (argv[i], option_map[j].name, complen))
887 k < sizeof (option_map) / sizeof (option_map[0]);
889 if (strlen (option_map[k].name) >= arglen
890 && !strncmp (argv[i], option_map[k].name, arglen))
892 error ("Ambiguous abbreviation %s", argv[i]);
896 if (k != sizeof (option_map) / sizeof (option_map[0]))
902 /* If the option has an argument, accept that. */
903 if (argv[i][optlen] == '=')
904 arg = argv[i] + optlen + 1;
906 /* If this mapping requires extra text at end of name,
907 accept that as "argument". */
908 else if (index (arginfo, '*') != 0)
909 arg = argv[i] + optlen;
911 /* Otherwise, extra text at end means mismatch.
912 Try other mappings. */
917 else if (index (arginfo, '*') != 0)
919 error ("Incomplete `%s' option", option_map[j].name);
923 /* Handle arguments. */
924 if (index (arginfo, 'a') != 0)
930 error ("Missing argument to `%s' option",
938 else if (index (arginfo, '*') != 0)
940 else if (index (arginfo, 'o') == 0)
943 error ("Extraneous argument to `%s' option",
948 /* Store the translation as one argv elt or as two. */
949 if (arg != 0 && index (arginfo, 'j') != 0)
950 newv[newindex++] = concat (option_map[j].equivalent, arg,
954 newv[newindex++] = option_map[j].equivalent;
955 newv[newindex++] = arg;
958 newv[newindex++] = option_map[j].equivalent;
966 /* Handle old-fashioned options--just copy them through,
967 with their arguments. */
968 else if (argv[i][0] == '-')
970 char *p = argv[i] + 1;
974 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
975 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
976 else if (WORD_SWITCH_TAKES_ARG (p))
977 nskip += WORD_SWITCH_TAKES_ARG (p);
978 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
981 else if (! strcmp (p, "Xlinker"))
984 /* Watch out for an option at the end of the command line that
985 is missing arguments, and avoid skipping past the end of the
987 if (nskip + i > argc)
992 newv[newindex++] = argv[i++];
997 /* Ordinary operands, or +e options. */
998 newv[newindex++] = argv[i++];
1011 #ifdef HAVE_STRERROR
1017 static char buffer[30];
1019 return "cannot access";
1021 if (e > 0 && e < sys_nerr)
1022 return sys_errlist[e];
1024 sprintf (buffer, "Unknown error %d", e);
1035 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1036 be considered whitespace. */
1037 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1039 else if (*p == '\n' || *p == ' ' || *p == '\t')
1043 while (*p != '\n') p++;
1053 /* Structure to keep track of the specs that have been defined so far.
1054 These are accessed using %(specname) or %[specname] in a compiler
1059 /* The following 2 fields must be first */
1060 /* to allow EXTRA_SPECS to be initialized */
1061 char *name; /* name of the spec. */
1062 char *ptr; /* available ptr if no static pointer */
1064 /* The following fields are not initialized */
1065 /* by EXTRA_SPECS */
1066 char **ptr_spec; /* pointer to the spec itself. */
1067 struct spec_list *next; /* Next spec in linked list. */
1068 int name_len; /* length of the name */
1069 int alloc_p; /* whether string was allocated */
1072 #define INIT_STATIC_SPEC(NAME,PTR) \
1073 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1075 /* List of statically defined specs */
1076 static struct spec_list static_specs[] = {
1077 INIT_STATIC_SPEC ("asm", &asm_spec),
1078 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1079 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1080 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1081 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1082 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1083 INIT_STATIC_SPEC ("link", &link_spec),
1084 INIT_STATIC_SPEC ("lib", &lib_spec),
1085 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1086 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1087 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1088 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1089 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1090 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1091 INIT_STATIC_SPEC ("version", &compiler_version),
1092 INIT_STATIC_SPEC ("multilib", &multilib_select),
1093 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1094 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1095 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1098 #ifdef EXTRA_SPECS /* additional specs needed */
1099 static struct spec_list extra_specs[] = { EXTRA_SPECS };
1102 /* List of dynamically allocates specs that have been defined so far. */
1104 static struct spec_list *specs = (struct spec_list *)0;
1107 /* Initialize the specs lookup routines. */
1112 struct spec_list *next = (struct spec_list *)0;
1113 struct spec_list *sl = (struct spec_list *)0;
1117 return; /* already initialized */
1120 fprintf (stderr, "Using builtin specs.\n");
1123 for (i = (sizeof (extra_specs) / sizeof (extra_specs[0])) - 1; i >= 0; i--)
1125 sl = &extra_specs[i];
1127 sl->name_len = strlen (sl->name);
1128 sl->ptr_spec = &sl->ptr;
1133 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1135 sl = &static_specs[i];
1144 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1145 removed; If the spec starts with a + then SPEC is added to the end of the
1149 set_spec (name, spec)
1153 struct spec_list *sl;
1155 int name_len = strlen (name);
1158 /* If this is the first call, initialize the statically allocated specs */
1161 struct spec_list *next = (struct spec_list *)0;
1162 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1165 sl = &static_specs[i];
1172 /* See if the spec already exists */
1173 for (sl = specs; sl; sl = sl->next)
1174 if (name_len == sl->name_len && !strcmp (sl->name, name))
1179 /* Not found - make it */
1180 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1181 sl->name = save_string (name, strlen (name));
1182 sl->name_len = name_len;
1183 sl->ptr_spec = &sl->ptr;
1185 *(sl->ptr_spec) = "";
1190 old_spec = *(sl->ptr_spec);
1191 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE (spec[1]))
1192 ? concat (old_spec, spec + 1, NULL_PTR)
1193 : save_string (spec, strlen (spec)));
1197 fprintf (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1200 /* Free the old spec */
1201 if (old_spec && sl->alloc_p)
1207 /* Accumulate a command (program name and args), and run it. */
1209 /* Vector of pointers to arguments in the current line of specifications. */
1211 static char **argbuf;
1213 /* Number of elements allocated in argbuf. */
1215 static int argbuf_length;
1217 /* Number of elements in argbuf currently in use (containing args). */
1219 static int argbuf_index;
1221 #ifdef MKTEMP_EACH_FILE
1222 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1225 static struct temp_name {
1226 char *suffix; /* suffix associated with the code. */
1227 int length; /* strlen (suffix). */
1228 int unique; /* Indicates whether %g or %u/%U was used. */
1229 char *filename; /* associated filename. */
1230 int filename_length; /* strlen (filename). */
1231 struct temp_name *next;
1235 /* Number of commands executed so far. */
1237 static int execution_count;
1239 /* Number of commands that exited with a signal. */
1241 static int signal_count;
1243 /* Name with which this program was invoked. */
1245 static char *programname;
1247 /* Structures to keep track of prefixes to try when looking for files. */
1251 char *prefix; /* String to prepend to the path. */
1252 struct prefix_list *next; /* Next in linked list. */
1253 int require_machine_suffix; /* Don't use without machine_suffix. */
1254 /* 2 means try both machine_suffix and just_machine_suffix. */
1255 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1260 struct prefix_list *plist; /* List of prefixes to try */
1261 int max_len; /* Max length of a prefix in PLIST */
1262 char *name; /* Name of this list (used in config stuff) */
1265 /* List of prefixes to try when looking for executables. */
1267 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1269 /* List of prefixes to try when looking for startup (crt0) files. */
1271 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1273 /* List of prefixes to try when looking for include files. */
1275 static struct path_prefix include_prefixes = { 0, 0, "include" };
1277 /* Suffix to attach to directories searched for commands.
1278 This looks like `MACHINE/VERSION/'. */
1280 static char *machine_suffix = 0;
1282 /* Suffix to attach to directories searched for commands.
1283 This is just `MACHINE/'. */
1285 static char *just_machine_suffix = 0;
1287 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1289 static char *gcc_exec_prefix;
1291 /* Default prefixes to attach to command names. */
1293 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1294 #undef MD_EXEC_PREFIX
1295 #undef MD_STARTFILE_PREFIX
1296 #undef MD_STARTFILE_PREFIX_1
1299 #ifndef STANDARD_EXEC_PREFIX
1300 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1301 #endif /* !defined STANDARD_EXEC_PREFIX */
1303 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1304 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1305 #ifdef MD_EXEC_PREFIX
1306 static char *md_exec_prefix = MD_EXEC_PREFIX;
1309 #ifndef STANDARD_STARTFILE_PREFIX
1310 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1311 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1313 #ifdef MD_STARTFILE_PREFIX
1314 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1316 #ifdef MD_STARTFILE_PREFIX_1
1317 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1319 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1320 static char *standard_startfile_prefix_1 = "/lib/";
1321 static char *standard_startfile_prefix_2 = "/usr/lib/";
1323 #ifndef TOOLDIR_BASE_PREFIX
1324 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1326 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1327 static char *tooldir_prefix;
1329 /* Subdirectory to use for locating libraries. Set by
1330 set_multilib_dir based on the compilation options. */
1332 static char *multilib_dir;
1334 /* Clear out the vector of arguments (after a command is executed). */
1342 /* Add one argument to the vector at the end.
1343 This is done when a space is seen or at the end of the line.
1344 If DELETE_ALWAYS is nonzero, the arg is a filename
1345 and the file should be deleted eventually.
1346 If DELETE_FAILURE is nonzero, the arg is a filename
1347 and the file should be deleted if this compilation fails. */
1350 store_arg (arg, delete_always, delete_failure)
1352 int delete_always, delete_failure;
1354 if (argbuf_index + 1 == argbuf_length)
1356 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1358 argbuf[argbuf_index++] = arg;
1359 argbuf[argbuf_index] = 0;
1361 if (delete_always || delete_failure)
1362 record_temp_file (arg, delete_always, delete_failure);
1365 /* Read compilation specs from a file named FILENAME,
1366 replacing the default ones.
1368 A suffix which starts with `*' is a definition for
1369 one of the machine-specific sub-specs. The "suffix" should be
1370 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1371 The corresponding spec is stored in asm_spec, etc.,
1372 rather than in the `compilers' vector.
1374 Anything invalid in the file is a fatal error. */
1377 read_specs (filename, main_p)
1383 struct stat statbuf;
1388 fprintf (stderr, "Reading specs from %s\n", filename);
1390 /* Open and stat the file. */
1391 desc = open (filename, O_RDONLY, 0);
1393 pfatal_with_name (filename);
1394 if (stat (filename, &statbuf) < 0)
1395 pfatal_with_name (filename);
1397 /* Read contents of file into BUFFER. */
1398 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1399 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1401 pfatal_with_name (filename);
1402 buffer[readlen] = 0;
1405 /* Scan BUFFER for specs, putting them in the vector. */
1411 char *in, *out, *p1, *p2, *p3;
1413 /* Advance P in BUFFER to the next nonblank nocomment line. */
1414 p = skip_whitespace (p);
1418 /* Is this a special command that starts with '%'? */
1419 /* Don't allow this for the main specs file, since it would
1420 encourage people to overwrite it. */
1421 if (*p == '%' && !main_p)
1424 while (*p && *p != '\n')
1427 p++; /* Skip '\n' */
1429 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1430 && (p1[sizeof "%include" - 1] == ' '
1431 || p1[sizeof "%include" - 1] == '\t'))
1435 p1 += sizeof ("%include");
1436 while (*p1 == ' ' || *p1 == '\t')
1439 if (*p1++ != '<' || p[-2] != '>')
1440 fatal ("specs %%include syntax malformed after %d characters",
1444 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1445 read_specs (new_filename ? new_filename : p1, FALSE);
1448 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1449 && (p1[sizeof "%include_noerr" - 1] == ' '
1450 || p1[sizeof "%include_noerr" - 1] == '\t'))
1454 p1 += sizeof "%include_noerr";
1455 while (*p1 == ' ' || *p1 == '\t') p1++;
1457 if (*p1++ != '<' || p[-2] != '>')
1458 fatal ("specs %%include syntax malformed after %d characters",
1462 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1464 read_specs (new_filename, FALSE);
1465 else if (verbose_flag)
1466 fprintf (stderr, "Could not find specs file %s\n", p1);
1469 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1470 && (p1[sizeof "%rename" - 1] == ' '
1471 || p1[sizeof "%rename" - 1] == '\t'))
1474 struct spec_list *sl;
1476 /* Get original name */
1477 p1 += sizeof "%rename";
1478 while (*p1 == ' ' || *p1 == '\t')
1481 if (! ISALPHA (*p1))
1482 fatal ("specs %%rename syntax malformed after %d characters",
1486 while (*p2 && !ISSPACE (*p2))
1489 if (*p2 != ' ' && *p2 != '\t')
1490 fatal ("specs %%rename syntax malformed after %d characters",
1495 while (*p2 == ' ' || *p2 == '\t')
1498 if (! ISALPHA (*p2))
1499 fatal ("specs %%rename syntax malformed after %d characters",
1502 /* Get new spec name */
1504 while (*p3 && !ISSPACE (*p3))
1508 fatal ("specs %%rename syntax malformed after %d characters",
1512 for (sl = specs; sl; sl = sl->next)
1513 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1517 fatal ("specs %s spec was not found to be renamed", p1);
1519 if (strcmp (p1, p2) == 0)
1524 fprintf (stderr, "rename spec %s to %s\n", p1, p2);
1526 fprintf (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
1530 set_spec (p2, *(sl->ptr_spec));
1532 free (*(sl->ptr_spec));
1534 *(sl->ptr_spec) = "";
1539 fatal ("specs unknown %% command after %d characters",
1543 /* Find the colon that should end the suffix. */
1545 while (*p1 && *p1 != ':' && *p1 != '\n')
1548 /* The colon shouldn't be missing. */
1550 fatal ("specs file malformed after %d characters", p1 - buffer);
1552 /* Skip back over trailing whitespace. */
1554 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1557 /* Copy the suffix to a string. */
1558 suffix = save_string (p, p2 - p);
1559 /* Find the next line. */
1560 p = skip_whitespace (p1 + 1);
1562 fatal ("specs file malformed after %d characters", p - buffer);
1565 /* Find next blank line. */
1566 while (*p1 && !(*p1 == '\n' && p1[1] == '\n'))
1569 /* Specs end at the blank line and do not include the newline. */
1570 spec = save_string (p, p1 - p);
1573 /* Delete backslash-newline sequences from the spec. */
1578 if (in[0] == '\\' && in[1] == '\n')
1580 else if (in[0] == '#')
1581 while (*in && *in != '\n')
1589 if (suffix[0] == '*')
1591 if (! strcmp (suffix, "*link_command"))
1592 link_command_spec = spec;
1594 set_spec (suffix + 1, spec);
1598 /* Add this pair to the vector. */
1600 = ((struct compiler *)
1601 xrealloc (compilers,
1602 (n_compilers + 2) * sizeof (struct compiler)));
1604 compilers[n_compilers].suffix = suffix;
1605 bzero ((char *) compilers[n_compilers].spec,
1606 sizeof compilers[n_compilers].spec);
1607 compilers[n_compilers].spec[0] = spec;
1609 bzero ((char *) &compilers[n_compilers],
1610 sizeof compilers[n_compilers]);
1614 link_command_spec = spec;
1617 if (link_command_spec == 0)
1618 fatal ("spec file has no spec for linking");
1621 /* Record the names of temporary files we tell compilers to write,
1622 and delete them at the end of the run. */
1624 /* This is the common prefix we use to make temp file names.
1625 It is chosen once for each run of this program.
1626 It is substituted into a spec by %g.
1627 Thus, all temp file names contain this prefix.
1628 In practice, all temp file names start with this prefix.
1630 This prefix comes from the envvar TMPDIR if it is defined;
1631 otherwise, from the P_tmpdir macro if that is defined;
1632 otherwise, in /usr/tmp or /tmp;
1633 or finally the current directory if all else fails. */
1635 static char *temp_filename;
1637 /* Length of the prefix. */
1639 static int temp_filename_length;
1641 /* Define the list of temporary files to delete. */
1646 struct temp_file *next;
1649 /* Queue of files to delete on success or failure of compilation. */
1650 static struct temp_file *always_delete_queue;
1651 /* Queue of files to delete on failure of compilation. */
1652 static struct temp_file *failure_delete_queue;
1654 /* Record FILENAME as a file to be deleted automatically.
1655 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1656 otherwise delete it in any case.
1657 FAIL_DELETE nonzero means delete it if a compilation step fails;
1658 otherwise delete it in any case. */
1661 record_temp_file (filename, always_delete, fail_delete)
1666 register char *name;
1667 name = xmalloc (strlen (filename) + 1);
1668 strcpy (name, filename);
1672 register struct temp_file *temp;
1673 for (temp = always_delete_queue; temp; temp = temp->next)
1674 if (! strcmp (name, temp->name))
1677 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1678 temp->next = always_delete_queue;
1680 always_delete_queue = temp;
1687 register struct temp_file *temp;
1688 for (temp = failure_delete_queue; temp; temp = temp->next)
1689 if (! strcmp (name, temp->name))
1692 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1693 temp->next = failure_delete_queue;
1695 failure_delete_queue = temp;
1701 /* Delete all the temporary files whose names we previously recorded. */
1704 delete_if_ordinary (name)
1711 printf ("Delete %s? (y or n) ", name);
1715 while ((c = getchar ()) != '\n' && c != EOF)
1718 if (i == 'y' || i == 'Y')
1720 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1721 if (unlink (name) < 0)
1723 perror_with_name (name);
1727 delete_temp_files ()
1729 register struct temp_file *temp;
1731 for (temp = always_delete_queue; temp; temp = temp->next)
1732 delete_if_ordinary (temp->name);
1733 always_delete_queue = 0;
1736 /* Delete all the files to be deleted on error. */
1739 delete_failure_queue ()
1741 register struct temp_file *temp;
1743 for (temp = failure_delete_queue; temp; temp = temp->next)
1744 delete_if_ordinary (temp->name);
1748 clear_failure_queue ()
1750 failure_delete_queue = 0;
1753 /* Routine to add variables to the environment. We do this to pass
1754 the pathname of the gcc driver, and the directories search to the
1755 collect2 program, which is being run as ld. This way, we can be
1756 sure of executing the right compiler when collect2 wants to build
1757 constructors and destructors. Since the environment variables we
1758 use come from an obstack, we don't have to worry about allocating
1767 #ifndef VMS /* nor about VMS */
1769 extern char **environ;
1770 char **old_environ = environ;
1774 int str_len = strlen (str);
1778 while ((ch = *p++) != '\0' && ch != '=')
1784 /* Search for replacing an existing environment variable, and
1785 count the number of total environment variables. */
1786 for (envp = old_environ; *envp; envp++)
1789 if (!strncmp (str, *envp, name_len))
1796 /* Add a new environment variable */
1797 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1799 bcopy ((char *) old_environ, (char *) (environ + 1),
1800 sizeof (char *) * (num_envs+1));
1805 #endif /* HAVE_PUTENV */
1808 /* Build a list of search directories from PATHS.
1809 PREFIX is a string to prepend to the list.
1810 If CHECK_DIR_P is non-zero we ensure the directory exists.
1811 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1812 It is also used by the --print-search-dirs flag. */
1815 build_search_list (paths, prefix, check_dir_p)
1816 struct path_prefix *paths;
1820 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1822 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1823 int first_time = TRUE;
1824 struct prefix_list *pprefix;
1826 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1828 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1830 int len = strlen (pprefix->prefix);
1834 || is_directory (pprefix->prefix, machine_suffix, 0)))
1837 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1840 obstack_grow (&collect_obstack, pprefix->prefix, len);
1841 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1844 if (just_machine_suffix
1845 && pprefix->require_machine_suffix == 2
1847 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1850 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1853 obstack_grow (&collect_obstack, pprefix->prefix, len);
1854 obstack_grow (&collect_obstack, just_machine_suffix,
1858 if (! pprefix->require_machine_suffix)
1861 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1864 obstack_grow (&collect_obstack, pprefix->prefix, len);
1868 obstack_1grow (&collect_obstack, '\0');
1869 return obstack_finish (&collect_obstack);
1872 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1876 putenv_from_prefixes (paths, env_var)
1877 struct path_prefix *paths;
1880 putenv (build_search_list (paths, env_var, 1));
1883 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1884 access to check permissions.
1885 Return 0 if not found, otherwise return its name, allocated with malloc. */
1888 find_a_file (pprefix, name, mode)
1889 struct path_prefix *pprefix;
1894 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1895 struct prefix_list *pl;
1896 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1899 len += strlen (machine_suffix);
1901 temp = xmalloc (len);
1903 /* Determine the filename to execute (special case for absolute paths). */
1905 if (*name == '/' || *name == DIR_SEPARATOR
1906 /* Check for disk name on MS-DOS-based systems. */
1907 || (DIR_SEPARATOR == '\\' && name[1] == ':'
1908 && (name[2] == DIR_SEPARATOR || name[2] == '/')))
1910 if (access (name, mode))
1912 strcpy (temp, name);
1917 for (pl = pprefix->plist; pl; pl = pl->next)
1921 /* Some systems have a suffix for executable files.
1922 So try appending that first. */
1923 if (file_suffix[0] != 0)
1925 strcpy (temp, pl->prefix);
1926 strcat (temp, machine_suffix);
1927 strcat (temp, name);
1928 strcat (temp, file_suffix);
1929 if (access (temp, mode) == 0)
1931 if (pl->used_flag_ptr != 0)
1932 *pl->used_flag_ptr = 1;
1937 /* Now try just the name. */
1938 strcpy (temp, pl->prefix);
1939 strcat (temp, machine_suffix);
1940 strcat (temp, name);
1941 if (access (temp, mode) == 0)
1943 if (pl->used_flag_ptr != 0)
1944 *pl->used_flag_ptr = 1;
1949 /* Certain prefixes are tried with just the machine type,
1950 not the version. This is used for finding as, ld, etc. */
1951 if (just_machine_suffix && pl->require_machine_suffix == 2)
1953 /* Some systems have a suffix for executable files.
1954 So try appending that first. */
1955 if (file_suffix[0] != 0)
1957 strcpy (temp, pl->prefix);
1958 strcat (temp, just_machine_suffix);
1959 strcat (temp, name);
1960 strcat (temp, file_suffix);
1961 if (access (temp, mode) == 0)
1963 if (pl->used_flag_ptr != 0)
1964 *pl->used_flag_ptr = 1;
1969 strcpy (temp, pl->prefix);
1970 strcat (temp, just_machine_suffix);
1971 strcat (temp, name);
1972 if (access (temp, mode) == 0)
1974 if (pl->used_flag_ptr != 0)
1975 *pl->used_flag_ptr = 1;
1980 /* Certain prefixes can't be used without the machine suffix
1981 when the machine or version is explicitly specified. */
1982 if (! pl->require_machine_suffix)
1984 /* Some systems have a suffix for executable files.
1985 So try appending that first. */
1986 if (file_suffix[0] != 0)
1988 strcpy (temp, pl->prefix);
1989 strcat (temp, name);
1990 strcat (temp, file_suffix);
1991 if (access (temp, mode) == 0)
1993 if (pl->used_flag_ptr != 0)
1994 *pl->used_flag_ptr = 1;
1999 strcpy (temp, pl->prefix);
2000 strcat (temp, name);
2001 if (access (temp, mode) == 0)
2003 if (pl->used_flag_ptr != 0)
2004 *pl->used_flag_ptr = 1;
2014 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2015 at the start of the list, otherwise it goes at the end.
2017 If WARN is nonzero, we will warn if no file is found
2018 through this prefix. WARN should point to an int
2019 which will be set to 1 if this entry is used.
2021 COMPONENT is the value to be passed to update_path.
2023 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2024 the complete value of machine_suffix.
2025 2 means try both machine_suffix and just_machine_suffix. */
2028 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2029 struct path_prefix *pprefix;
2033 int require_machine_suffix;
2036 struct prefix_list *pl, **prev;
2039 if (! first && pprefix->plist)
2041 for (pl = pprefix->plist; pl->next; pl = pl->next)
2046 prev = &pprefix->plist;
2048 /* Keep track of the longest prefix */
2050 prefix = update_path (prefix, component);
2051 len = strlen (prefix);
2052 if (len > pprefix->max_len)
2053 pprefix->max_len = len;
2055 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2056 pl->prefix = save_string (prefix, len);
2057 pl->require_machine_suffix = require_machine_suffix;
2058 pl->used_flag_ptr = warn;
2065 pl->next = (struct prefix_list *) 0;
2069 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2072 unused_prefix_warnings (pprefix)
2073 struct path_prefix *pprefix;
2075 struct prefix_list *pl = pprefix->plist;
2079 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2081 if (pl->require_machine_suffix && machine_suffix)
2082 error ("file path prefix `%s%s' never used", pl->prefix,
2085 error ("file path prefix `%s' never used", pl->prefix);
2087 /* Prevent duplicate warnings. */
2088 *pl->used_flag_ptr = 1;
2096 /* Execute the command specified by the arguments on the current line of spec.
2097 When using pipes, this includes several piped-together commands
2098 with `|' between them.
2100 Return 0 if successful, -1 if failed. */
2106 int n_commands; /* # of command. */
2110 char *prog; /* program name. */
2111 char **argv; /* vector of args. */
2112 int pid; /* pid of process for this command. */
2115 struct command *commands; /* each command buffer with above info. */
2117 /* Count # of piped commands. */
2118 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2119 if (strcmp (argbuf[i], "|") == 0)
2122 /* Get storage for each command. */
2124 = (struct command *) alloca (n_commands * sizeof (struct command));
2126 /* Split argbuf into its separate piped processes,
2127 and record info about each one.
2128 Also search for the programs that are to be run. */
2130 commands[0].prog = argbuf[0]; /* first command. */
2131 commands[0].argv = &argbuf[0];
2132 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2134 commands[0].argv[0] = string;
2136 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2137 if (strcmp (argbuf[i], "|") == 0)
2138 { /* each command. */
2139 #if defined (__MSDOS__) || (defined (_WIN32) && defined (__CYGWIN32_)) || defined (OS2) || defined (VMS)
2140 fatal ("-pipe not supported");
2142 argbuf[i] = 0; /* termination of command args. */
2143 commands[n_commands].prog = argbuf[i + 1];
2144 commands[n_commands].argv = &argbuf[i + 1];
2145 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2147 commands[n_commands].argv[0] = string;
2151 argbuf[argbuf_index] = 0;
2153 /* If -v, print what we are about to do, and maybe query. */
2157 /* Print each piped command as a separate line. */
2158 for (i = 0; i < n_commands ; i++)
2162 for (j = commands[i].argv; *j; j++)
2163 fprintf (stderr, " %s", *j);
2165 /* Print a pipe symbol after all but the last command. */
2166 if (i + 1 != n_commands)
2167 fprintf (stderr, " |");
2168 fprintf (stderr, "\n");
2172 fprintf (stderr, "\nGo ahead? (y or n) ");
2176 while (getchar () != '\n')
2179 if (i != 'y' && i != 'Y')
2184 /* Run each piped subprocess. */
2186 for (i = 0; i < n_commands; i++)
2188 char *errmsg_fmt, *errmsg_arg;
2189 char *string = commands[i].argv[0];
2191 commands[i].pid = pexecute (string, commands[i].argv,
2192 programname, temp_filename,
2193 &errmsg_fmt, &errmsg_arg,
2194 ((i == 0 ? PEXECUTE_FIRST : 0)
2195 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2196 | (string == commands[i].prog
2197 ? PEXECUTE_SEARCH : 0)
2198 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2200 if (commands[i].pid == -1)
2201 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2203 if (string != commands[i].prog)
2209 /* Wait for all the subprocesses to finish.
2210 We don't care what order they finish in;
2211 we know that N_COMMANDS waits will get them all.
2212 Ignore subprocesses that we don't know about,
2213 since they can be spawned by the process that exec'ed us. */
2218 for (i = 0; i < n_commands; )
2224 pid = pwait (commands[i].pid, &status, 0);
2228 for (j = 0; j < n_commands; j++)
2229 if (commands[j].pid == pid)
2234 if (WIFSIGNALED (status))
2236 fatal ("Internal compiler error: program %s got fatal signal %d",
2237 commands[j].prog, WTERMSIG (status));
2241 else if (WIFEXITED (status)
2242 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2252 /* Find all the switches given to us
2253 and make a vector describing them.
2254 The elements of the vector are strings, one per switch given.
2255 If a switch uses following arguments, then the `part1' field
2256 is the switch itself and the `args' field
2257 is a null-terminated vector containing the following arguments.
2258 The `live_cond' field is 1 if the switch is true in a conditional spec,
2259 -1 if false (overridden by a later switch), and is initialized to zero.
2260 The `valid' field is nonzero if any spec has looked at this switch;
2261 if it remains zero at the end of the run, it must be meaningless. */
2271 static struct switchstr *switches;
2273 static int n_switches;
2281 /* Also a vector of input files specified. */
2283 static struct infile *infiles;
2285 static int n_infiles;
2287 /* And a vector of corresponding output files is made up later. */
2289 static char **outfiles;
2291 /* Used to track if none of the -B paths are used. */
2294 /* Used to track if standard path isn't used and -b or -V is specified. */
2295 static int warn_std;
2297 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2298 static int *warn_std_ptr = 0;
2301 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2303 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2304 is true if we should look for an executable suffix as well. */
2307 convert_filename (name, do_exe)
2312 int len = strlen (name);
2314 #ifdef HAVE_OBJECT_SUFFIX
2315 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2317 && name[len - 2] == '.'
2318 && name[len - 1] == 'o')
2320 obstack_grow (&obstack, name, len - 2);
2321 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2322 name = obstack_finish (&obstack);
2326 #ifdef HAVE_EXECUTABLE_SUFFIX
2327 /* If there is no filetype, make it the executable suffix (which includes
2328 the "."). But don't get confused if we have just "-o". */
2329 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2332 for (i = len - 1; i >= 0; i--)
2333 if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2336 for (i++; i < len; i++)
2340 obstack_grow (&obstack, name, len);
2341 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2342 name = obstack_finish (&obstack);
2349 /* Create the vector `switches' and its contents.
2350 Store its length in `n_switches'. */
2353 process_command (argc, argv)
2359 char *spec_lang = 0;
2360 int last_language_n_infiles;
2363 int lang_n_infiles = 0;
2365 GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2370 /* Figure compiler version from version string. */
2372 compiler_version = save_string (version_string, strlen (version_string));
2373 for (temp = compiler_version; *temp; ++temp)
2382 /* Set up the default search paths. */
2384 if (gcc_exec_prefix)
2386 int len = strlen (gcc_exec_prefix);
2387 if (len > sizeof ("/lib/gcc-lib/")-1
2388 && (gcc_exec_prefix[len-1] == '/'
2389 || gcc_exec_prefix[len-1] == DIR_SEPARATOR))
2391 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2392 if ((*temp == '/' || *temp == DIR_SEPARATOR)
2393 && strncmp (temp+1, "lib", 3) == 0
2394 && (temp[4] == '/' || temp[4] == DIR_SEPARATOR)
2395 && strncmp (temp+5, "gcc-lib", 7) == 0)
2396 len -= sizeof ("/lib/gcc-lib/") - 1;
2399 set_std_prefix (gcc_exec_prefix, len);
2400 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2401 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2404 /* COMPILER_PATH and LIBRARY_PATH have values
2405 that are lists of directory names with colons. */
2407 GET_ENVIRONMENT (temp, "COMPILER_PATH");
2410 char *startp, *endp;
2411 char *nstore = (char *) alloca (strlen (temp) + 3);
2413 startp = endp = temp;
2416 if (*endp == PATH_SEPARATOR || *endp == 0)
2418 strncpy (nstore, startp, endp-startp);
2420 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2421 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2423 nstore[endp-startp] = DIR_SEPARATOR;
2424 nstore[endp-startp+1] = 0;
2427 nstore[endp-startp] = 0;
2428 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2429 add_prefix (&include_prefixes,
2430 concat (nstore, "include", NULL_PTR),
2434 endp = startp = endp + 1;
2441 GET_ENVIRONMENT (temp, "LIBRARY_PATH");
2442 if (temp && *cross_compile == '0')
2444 char *startp, *endp;
2445 char *nstore = (char *) alloca (strlen (temp) + 3);
2447 startp = endp = temp;
2450 if (*endp == PATH_SEPARATOR || *endp == 0)
2452 strncpy (nstore, startp, endp-startp);
2454 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2455 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2457 nstore[endp-startp] = DIR_SEPARATOR;
2458 nstore[endp-startp+1] = 0;
2461 nstore[endp-startp] = 0;
2462 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2466 endp = startp = endp + 1;
2473 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2474 GET_ENVIRONMENT (temp, "LPATH");
2475 if (temp && *cross_compile == '0')
2477 char *startp, *endp;
2478 char *nstore = (char *) alloca (strlen (temp) + 3);
2480 startp = endp = temp;
2483 if (*endp == PATH_SEPARATOR || *endp == 0)
2485 strncpy (nstore, startp, endp-startp);
2487 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2488 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2490 nstore[endp-startp] = DIR_SEPARATOR;
2491 nstore[endp-startp+1] = 0;
2494 nstore[endp-startp] = 0;
2495 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2499 endp = startp = endp + 1;
2506 /* Convert new-style -- options to old-style. */
2507 translate_options (&argc, &argv);
2509 #ifdef LANG_SPECIFIC_DRIVER
2510 /* Do language-specific adjustment/addition of flags. */
2511 lang_specific_driver (fatal, &argc, &argv);
2514 /* Scan argv twice. Here, the first time, just count how many switches
2515 there will be in their vector, and how many input files in theirs.
2516 Here we also parse the switches that cc itself uses (e.g. -v). */
2518 for (i = 1; i < argc; i++)
2520 if (! strcmp (argv[i], "-dumpspecs"))
2522 struct spec_list *sl;
2524 for (sl = specs; sl; sl = sl->next)
2525 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2528 else if (! strcmp (argv[i], "-dumpversion"))
2530 printf ("%s\n", spec_version);
2533 else if (! strcmp (argv[i], "-dumpmachine"))
2535 printf ("%s\n", spec_machine);
2538 else if (! strcmp (argv[i], "-print-search-dirs"))
2539 print_search_dirs = 1;
2540 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2541 print_file_name = "libgcc.a";
2542 else if (! strncmp (argv[i], "-print-file-name=", 17))
2543 print_file_name = argv[i] + 17;
2544 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2545 print_prog_name = argv[i] + 17;
2546 else if (! strcmp (argv[i], "-print-multi-lib"))
2547 print_multi_lib = 1;
2548 else if (! strcmp (argv[i], "-print-multi-directory"))
2549 print_multi_directory = 1;
2550 else if (! strncmp (argv[i], "-Wa,", 4))
2553 /* Pass the rest of this option to the assembler. */
2555 n_assembler_options++;
2556 if (!assembler_options)
2558 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2561 = (char **) xrealloc (assembler_options,
2562 n_assembler_options * sizeof (char **));
2564 /* Split the argument at commas. */
2566 for (j = 4; argv[i][j]; j++)
2567 if (argv[i][j] == ',')
2569 assembler_options[n_assembler_options - 1]
2570 = save_string (argv[i] + prev, j - prev);
2571 n_assembler_options++;
2573 = (char **) xrealloc (assembler_options,
2574 n_assembler_options * sizeof (char **));
2577 /* Record the part after the last comma. */
2578 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2580 else if (! strncmp (argv[i], "-Wp,", 4))
2583 /* Pass the rest of this option to the preprocessor. */
2585 n_preprocessor_options++;
2586 if (!preprocessor_options)
2587 preprocessor_options
2588 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2590 preprocessor_options
2591 = (char **) xrealloc (preprocessor_options,
2592 n_preprocessor_options * sizeof (char **));
2594 /* Split the argument at commas. */
2596 for (j = 4; argv[i][j]; j++)
2597 if (argv[i][j] == ',')
2599 preprocessor_options[n_preprocessor_options - 1]
2600 = save_string (argv[i] + prev, j - prev);
2601 n_preprocessor_options++;
2602 preprocessor_options
2603 = (char **) xrealloc (preprocessor_options,
2604 n_preprocessor_options * sizeof (char **));
2607 /* Record the part after the last comma. */
2608 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2610 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2611 /* The +e options to the C++ front-end. */
2613 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2616 /* Split the argument at commas. */
2617 for (j = 3; argv[i][j]; j++)
2618 n_infiles += (argv[i][j] == ',');
2620 else if (strcmp (argv[i], "-Xlinker") == 0)
2623 fatal ("argument to `-Xlinker' is missing");
2628 else if (strncmp (argv[i], "-l", 2) == 0)
2630 else if (strcmp (argv[i], "-save-temps") == 0)
2632 save_temps_flag = 1;
2635 else if (strcmp (argv[i], "-specs") == 0)
2637 struct user_specs *user = (struct user_specs *)
2638 xmalloc (sizeof (struct user_specs));
2640 fatal ("argument to `-specs' is missing");
2642 user->next = (struct user_specs *)0;
2643 user->filename = argv[i];
2644 if (user_specs_tail)
2645 user_specs_tail->next = user;
2647 user_specs_head = user;
2648 user_specs_tail = user;
2650 else if (strncmp (argv[i], "-specs=", 7) == 0)
2652 struct user_specs *user = (struct user_specs *)
2653 xmalloc (sizeof (struct user_specs));
2654 if (strlen (argv[i]) == 7)
2655 fatal ("argument to `-specs=' is missing");
2657 user->next = (struct user_specs *)0;
2658 user->filename = argv[i]+7;
2659 if (user_specs_tail)
2660 user_specs_tail->next = user;
2662 user_specs_head = user;
2663 user_specs_tail = user;
2665 else if (argv[i][0] == '-' && argv[i][1] != 0)
2667 register char *p = &argv[i][1];
2668 register int c = *p;
2674 if (p[1] == 0 && i + 1 == argc)
2675 fatal ("argument to `-b' is missing");
2677 spec_machine = argv[++i];
2679 spec_machine = p + 1;
2681 warn_std_ptr = &warn_std;
2687 if (p[1] == 0 && i + 1 == argc)
2688 fatal ("argument to `-B' is missing");
2693 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2694 add_prefix (&startfile_prefixes, value, NULL_PTR,
2696 add_prefix (&include_prefixes, concat (value, "include",
2698 NULL_PTR, 1, 0, NULL_PTR);
2700 /* As a kludge, if the arg is "[foo/]stageN/", just add
2701 "[foo/]include" to the include prefix. */
2703 int len = strlen (value);
2706 && (value[len - 8] == '/'
2707 || value[len - 8] == DIR_SEPARATOR)))
2708 && strncmp (value + len - 7, "stage", 5) == 0
2709 && ISDIGIT (value[len - 2])
2710 && (value[len - 1] == '/'
2711 || value[len - 1] == DIR_SEPARATOR))
2714 add_prefix (&include_prefixes, "include", NULL_PTR,
2718 char *string = xmalloc (len + 1);
2719 strncpy (string, value, len-7);
2720 strcpy (string+len-7, "include");
2721 add_prefix (&include_prefixes, string, NULL_PTR,
2730 case 'v': /* Print our subcommands and print versions. */
2732 /* If they do anything other than exactly `-v', don't set
2733 verbose_flag; rather, continue on to give the error. */
2741 if (p[1] == 0 && i + 1 == argc)
2742 fatal ("argument to `-V' is missing");
2744 spec_version = argv[++i];
2746 spec_version = p + 1;
2747 compiler_version = spec_version;
2748 warn_std_ptr = &warn_std;
2750 /* Validate the version number. Use the same checks
2751 done when inserting it into a spec.
2753 The format of the version string is
2754 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2756 char *v = compiler_version;
2758 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2759 while (! isdigit (*v))
2762 if (v > compiler_version && v[-1] != '-')
2763 fatal ("invalid version number format");
2765 /* Set V after the first period. */
2766 while (isdigit (*v))
2770 fatal ("invalid version number format");
2773 while (isdigit (*v))
2776 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
2777 fatal ("invalid version number format");
2792 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2793 argv[i] = convert_filename (argv[i], 1);
2795 argv[i+1] = convert_filename (argv[i+1], 1);
2803 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2804 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2805 else if (WORD_SWITCH_TAKES_ARG (p))
2806 i += WORD_SWITCH_TAKES_ARG (p);
2816 if (have_c && have_o && lang_n_infiles > 1)
2817 fatal ("cannot specify -o with -c and multiple compilations");
2819 /* Set up the search paths before we go looking for config files. */
2821 /* These come before the md prefixes so that we will find gcc's subcommands
2822 (such as cpp) rather than those of the host system. */
2823 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2824 as well as trying the machine and the version. */
2826 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
2827 0, 2, warn_std_ptr);
2828 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
2829 0, 2, warn_std_ptr);
2832 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
2833 0, 1, warn_std_ptr);
2834 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
2835 0, 1, warn_std_ptr);
2837 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
2838 dir_separator_str, NULL_PTR);
2840 /* If tooldir is relative, base it on exec_prefixes. A relative
2841 tooldir lets us move the installed tree as a unit.
2843 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2844 directories, so that we can search both the user specified directory
2845 and the standard place. */
2847 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2849 if (gcc_exec_prefix)
2851 char *gcc_exec_tooldir_prefix
2852 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2853 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2855 add_prefix (&exec_prefixes,
2856 concat (gcc_exec_tooldir_prefix, "bin",
2857 dir_separator_str, NULL_PTR),
2858 NULL_PTR, 0, 0, NULL_PTR);
2859 add_prefix (&startfile_prefixes,
2860 concat (gcc_exec_tooldir_prefix, "lib",
2861 dir_separator_str, NULL_PTR),
2862 NULL_PTR, 0, 0, NULL_PTR);
2865 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2866 dir_separator_str, spec_version,
2867 dir_separator_str, tooldir_prefix, NULL_PTR);
2870 add_prefix (&exec_prefixes,
2871 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2872 "BINUTILS", 0, 0, NULL_PTR);
2873 add_prefix (&startfile_prefixes,
2874 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2875 "BINUTILS", 0, 0, NULL_PTR);
2877 /* More prefixes are enabled in main, after we read the specs file
2878 and determine whether this is cross-compilation or not. */
2881 /* Then create the space for the vectors and scan again. */
2883 switches = ((struct switchstr *)
2884 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2885 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2888 last_language_n_infiles = -1;
2890 /* This, time, copy the text of each switch and store a pointer
2891 to the copy in the vector of switches.
2892 Store all the infiles in their vector. */
2894 for (i = 1; i < argc; i++)
2896 /* Just skip the switches that were handled by the preceding loop. */
2897 if (! strncmp (argv[i], "-Wa,", 4))
2899 else if (! strncmp (argv[i], "-Wp,", 4))
2901 else if (! strcmp (argv[i], "-print-search-dirs"))
2903 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2905 else if (! strncmp (argv[i], "-print-file-name=", 17))
2907 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2909 else if (! strcmp (argv[i], "-print-multi-lib"))
2911 else if (! strcmp (argv[i], "-print-multi-directory"))
2913 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2915 /* Compensate for the +e options to the C++ front-end;
2916 they're there simply for cfront call-compatibility. We do
2917 some magic in default_compilers to pass them down properly.
2918 Note we deliberately start at the `+' here, to avoid passing
2919 -e0 or -e1 down into the linker. */
2920 switches[n_switches].part1 = &argv[i][0];
2921 switches[n_switches].args = 0;
2922 switches[n_switches].live_cond = 0;
2923 switches[n_switches].valid = 0;
2926 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2929 /* Split the argument at commas. */
2931 for (j = 4; argv[i][j]; j++)
2932 if (argv[i][j] == ',')
2934 infiles[n_infiles].language = "*";
2935 infiles[n_infiles++].name
2936 = save_string (argv[i] + prev, j - prev);
2939 /* Record the part after the last comma. */
2940 infiles[n_infiles].language = "*";
2941 infiles[n_infiles++].name = argv[i] + prev;
2943 else if (strcmp (argv[i], "-Xlinker") == 0)
2945 infiles[n_infiles].language = "*";
2946 infiles[n_infiles++].name = argv[++i];
2948 else if (strncmp (argv[i], "-l", 2) == 0)
2950 infiles[n_infiles].language = "*";
2951 infiles[n_infiles++].name = argv[i];
2953 else if (strcmp (argv[i], "-specs") == 0)
2955 else if (strncmp (argv[i], "-specs=", 7) == 0)
2957 /* -save-temps overrides -pipe, so that temp files are produced */
2958 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
2959 error ("Warning: -pipe ignored since -save-temps specified");
2960 else if (argv[i][0] == '-' && argv[i][1] != 0)
2962 register char *p = &argv[i][1];
2963 register int c = *p;
2967 if (p[1] == 0 && i + 1 == argc)
2968 fatal ("argument to `-x' is missing");
2970 spec_lang = argv[++i];
2973 if (! strcmp (spec_lang, "none"))
2974 /* Suppress the warning if -xnone comes after the last input
2975 file, because alternate command interfaces like g++ might
2976 find it useful to place -xnone after each input file. */
2979 last_language_n_infiles = n_infiles;
2982 switches[n_switches].part1 = p;
2983 /* Deal with option arguments in separate argv elements. */
2984 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2985 || WORD_SWITCH_TAKES_ARG (p))
2988 int n_args = WORD_SWITCH_TAKES_ARG (p);
2992 /* Count only the option arguments in separate argv elements. */
2993 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2995 if (i + n_args >= argc)
2996 fatal ("argument to `-%s' is missing", p);
2997 switches[n_switches].args
2998 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3000 switches[n_switches].args[j++] = argv[++i];
3001 /* Null-terminate the vector. */
3002 switches[n_switches].args[j] = 0;
3004 else if (index (switches_need_spaces, c))
3006 /* On some systems, ld cannot handle some options without
3007 a space. So split the option from its argument. */
3008 char *part1 = (char *) xmalloc (2);
3012 switches[n_switches].part1 = part1;
3013 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3014 switches[n_switches].args[0] = xmalloc (strlen (p));
3015 strcpy (switches[n_switches].args[0], &p[1]);
3016 switches[n_switches].args[1] = 0;
3019 switches[n_switches].args = 0;
3021 switches[n_switches].live_cond = 0;
3022 switches[n_switches].valid = 0;
3023 /* This is always valid, since gcc.c itself understands it. */
3024 if (!strcmp (p, "save-temps"))
3025 switches[n_switches].valid = 1;
3028 char ch = switches[n_switches].part1[0];
3029 if (ch == 'V' || ch == 'b' || ch == 'B')
3030 switches[n_switches].valid = 1;
3036 #ifdef HAVE_OBJECT_SUFFIX
3037 argv[i] = convert_filename (argv[i], 0);
3040 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3042 perror_with_name (argv[i]);
3047 infiles[n_infiles].language = spec_lang;
3048 infiles[n_infiles++].name = argv[i];
3053 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3054 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3056 switches[n_switches].part1 = 0;
3057 infiles[n_infiles].name = 0;
3060 /* Process a spec string, accumulating and running commands. */
3062 /* These variables describe the input file name.
3063 input_file_number is the index on outfiles of this file,
3064 so that the output file name can be stored for later use by %o.
3065 input_basename is the start of the part of the input file
3066 sans all directory names, and basename_length is the number
3067 of characters starting there excluding the suffix .c or whatever. */
3069 static char *input_filename;
3070 static int input_file_number;
3071 static size_t input_filename_length;
3072 static int basename_length;
3073 static char *input_basename;
3074 static char *input_suffix;
3076 /* These are variables used within do_spec and do_spec_1. */
3078 /* Nonzero if an arg has been started and not yet terminated
3079 (with space, tab or newline). */
3080 static int arg_going;
3082 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3083 is a temporary file name. */
3084 static int delete_this_arg;
3086 /* Nonzero means %w has been seen; the next arg to be terminated
3087 is the output file name of this compilation. */
3088 static int this_is_output_file;
3090 /* Nonzero means %s has been seen; the next arg to be terminated
3091 is the name of a library file and we should try the standard
3092 search dirs for it. */
3093 static int this_is_library_file;
3095 /* Nonzero means that the input of this command is coming from a pipe. */
3096 static int input_from_pipe;
3098 /* Process the spec SPEC and run the commands specified therein.
3099 Returns 0 if the spec is successfully processed; -1 if failed. */
3109 delete_this_arg = 0;
3110 this_is_output_file = 0;
3111 this_is_library_file = 0;
3112 input_from_pipe = 0;
3114 value = do_spec_1 (spec, 0, NULL_PTR);
3116 /* Force out any unfinished command.
3117 If -pipe, this forces out the last command if it ended in `|'. */
3120 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3123 if (argbuf_index > 0)
3130 /* Process the sub-spec SPEC as a portion of a larger spec.
3131 This is like processing a whole spec except that we do
3132 not initialize at the beginning and we do not supply a
3133 newline by default at the end.
3134 INSWITCH nonzero means don't process %-sequences in SPEC;
3135 in this case, % is treated as an ordinary character.
3136 This is used while substituting switches.
3137 INSWITCH nonzero also causes SPC not to terminate an argument.
3139 Value is zero unless a line was finished
3140 and the command on that line reported an error. */
3143 do_spec_1 (spec, inswitch, soft_matched_part)
3146 char *soft_matched_part;
3148 register char *p = spec;
3155 /* If substituting a switch, treat all chars like letters.
3156 Otherwise, NL, SPC, TAB and % are special. */
3157 switch (inswitch ? 'a' : c)
3160 /* End of line: finish any pending argument,
3161 then run the pending command if one has been started. */
3164 obstack_1grow (&obstack, 0);
3165 string = obstack_finish (&obstack);
3166 if (this_is_library_file)
3167 string = find_file (string);
3168 store_arg (string, delete_this_arg, this_is_output_file);
3169 if (this_is_output_file)
3170 outfiles[input_file_number] = string;
3174 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3176 for (i = 0; i < n_switches; i++)
3177 if (!strcmp (switches[i].part1, "pipe"))
3180 /* A `|' before the newline means use a pipe here,
3181 but only if -pipe was specified.
3182 Otherwise, execute now and don't pass the `|' as an arg. */
3185 input_from_pipe = 1;
3186 switches[i].valid = 1;
3193 if (argbuf_index > 0)
3199 /* Reinitialize for a new command, and for a new argument. */
3202 delete_this_arg = 0;
3203 this_is_output_file = 0;
3204 this_is_library_file = 0;
3205 input_from_pipe = 0;
3209 /* End any pending argument. */
3212 obstack_1grow (&obstack, 0);
3213 string = obstack_finish (&obstack);
3214 if (this_is_library_file)
3215 string = find_file (string);
3216 store_arg (string, delete_this_arg, this_is_output_file);
3217 if (this_is_output_file)
3218 outfiles[input_file_number] = string;
3222 obstack_1grow (&obstack, c);
3228 /* Space or tab ends an argument if one is pending. */
3231 obstack_1grow (&obstack, 0);
3232 string = obstack_finish (&obstack);
3233 if (this_is_library_file)
3234 string = find_file (string);
3235 store_arg (string, delete_this_arg, this_is_output_file);
3236 if (this_is_output_file)
3237 outfiles[input_file_number] = string;
3239 /* Reinitialize for a new argument. */
3241 delete_this_arg = 0;
3242 this_is_output_file = 0;
3243 this_is_library_file = 0;
3250 fatal ("Invalid specification! Bug in cc.");
3253 obstack_grow (&obstack, input_basename, basename_length);
3258 delete_this_arg = 2;
3261 /* Dump out the directories specified with LIBRARY_PATH,
3262 followed by the absolute directories
3263 that we search for startfiles. */
3266 struct prefix_list *pl = startfile_prefixes.plist;
3267 size_t bufsize = 100;
3268 char *buffer = (char *) xmalloc (bufsize);
3271 for (; pl; pl = pl->next)
3273 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3274 /* Used on systems which record the specified -L dirs
3275 and use them to search for dynamic linking. */
3276 /* Relative directories always come from -B,
3277 and it is better not to use them for searching
3278 at run time. In particular, stage1 loses */
3279 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3282 /* Try subdirectory if there is one. */
3283 if (multilib_dir != NULL)
3287 if (strlen (pl->prefix) + strlen (machine_suffix)
3289 bufsize = (strlen (pl->prefix)
3290 + strlen (machine_suffix)) * 2 + 1;
3291 buffer = (char *) xrealloc (buffer, bufsize);
3292 strcpy (buffer, pl->prefix);
3293 strcat (buffer, machine_suffix);
3294 if (is_directory (buffer, multilib_dir, 1))
3296 do_spec_1 ("-L", 0, NULL_PTR);
3297 #ifdef SPACE_AFTER_L_OPTION
3298 do_spec_1 (" ", 0, NULL_PTR);
3300 do_spec_1 (buffer, 1, NULL_PTR);
3301 do_spec_1 (multilib_dir, 1, NULL_PTR);
3302 /* Make this a separate argument. */
3303 do_spec_1 (" ", 0, NULL_PTR);
3306 if (!pl->require_machine_suffix)
3308 if (is_directory (pl->prefix, multilib_dir, 1))
3310 do_spec_1 ("-L", 0, NULL_PTR);
3311 #ifdef SPACE_AFTER_L_OPTION
3312 do_spec_1 (" ", 0, NULL_PTR);
3314 do_spec_1 (pl->prefix, 1, NULL_PTR);
3315 do_spec_1 (multilib_dir, 1, NULL_PTR);
3316 /* Make this a separate argument. */
3317 do_spec_1 (" ", 0, NULL_PTR);
3323 if (is_directory (pl->prefix, machine_suffix, 1))
3325 do_spec_1 ("-L", 0, NULL_PTR);
3326 #ifdef SPACE_AFTER_L_OPTION
3327 do_spec_1 (" ", 0, NULL_PTR);
3329 do_spec_1 (pl->prefix, 1, NULL_PTR);
3330 /* Remove slash from machine_suffix. */
3331 if (strlen (machine_suffix) >= bufsize)
3332 bufsize = strlen (machine_suffix) * 2 + 1;
3333 buffer = (char *) xrealloc (buffer, bufsize);
3334 strcpy (buffer, machine_suffix);
3335 idx = strlen (buffer);
3336 if (buffer[idx - 1] == '/'
3337 || buffer[idx - 1] == DIR_SEPARATOR)
3338 buffer[idx - 1] = 0;
3339 do_spec_1 (buffer, 1, NULL_PTR);
3340 /* Make this a separate argument. */
3341 do_spec_1 (" ", 0, NULL_PTR);
3344 if (!pl->require_machine_suffix)
3346 if (is_directory (pl->prefix, "", 1))
3348 do_spec_1 ("-L", 0, NULL_PTR);
3349 #ifdef SPACE_AFTER_L_OPTION
3350 do_spec_1 (" ", 0, NULL_PTR);
3352 /* Remove slash from pl->prefix. */
3353 if (strlen (pl->prefix) >= bufsize)
3354 bufsize = strlen (pl->prefix) * 2 + 1;
3355 buffer = (char *) xrealloc (buffer, bufsize);
3356 strcpy (buffer, pl->prefix);
3357 idx = strlen (buffer);
3358 if (buffer[idx - 1] == '/'
3359 || buffer[idx - 1] == DIR_SEPARATOR)
3360 buffer[idx - 1] = 0;
3361 do_spec_1 (buffer, 1, NULL_PTR);
3362 /* Make this a separate argument. */
3363 do_spec_1 (" ", 0, NULL_PTR);
3372 /* {...:%efoo} means report an error with `foo' as error message
3373 and don't execute any more commands for this file. */
3377 while (*p != 0 && *p != '\n') p++;
3378 buf = (char *) alloca (p - q + 1);
3379 strncpy (buf, q, p - q);
3389 if (save_temps_flag)
3391 obstack_grow (&obstack, input_basename, basename_length);
3392 delete_this_arg = 0;
3396 #ifdef MKTEMP_EACH_FILE
3397 /* ??? This has a problem: the total number of
3398 values mktemp can return is limited.
3399 That matters for the names of object files.
3400 In 2.4, do something about that. */
3401 struct temp_name *t;
3403 while (*p == '.' || ISALPHA (*p)
3404 || (p[0] == '%' && p[1] == 'O'))
3407 /* See if we already have an association of %g/%u/%U and
3409 for (t = temp_names; t; t = t->next)
3410 if (t->length == p - suffix
3411 && strncmp (t->suffix, suffix, p - suffix) == 0
3412 && t->unique == (c != 'g'))
3415 /* Make a new association if needed. %u requires one. */
3416 if (t == 0 || c == 'u')
3420 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3421 t->next = temp_names;
3424 t->length = p - suffix;
3425 t->suffix = save_string (suffix, p - suffix);
3426 t->unique = (c != 'g');
3427 temp_filename = choose_temp_base ();
3428 temp_filename_length = strlen (temp_filename);
3429 t->filename = temp_filename;
3430 t->filename_length = temp_filename_length;
3433 obstack_grow (&obstack, t->filename, t->filename_length);
3434 delete_this_arg = 1;
3436 obstack_grow (&obstack, temp_filename, temp_filename_length);
3437 if (c == 'u' || c == 'U')
3443 sprintf (buff, "%d", unique);
3444 obstack_grow (&obstack, buff, strlen (buff));
3447 delete_this_arg = 1;
3453 obstack_grow (&obstack, input_filename, input_filename_length);
3459 struct prefix_list *pl = include_prefixes.plist;
3461 if (gcc_exec_prefix)
3463 do_spec_1 ("-iprefix", 1, NULL_PTR);
3464 /* Make this a separate argument. */
3465 do_spec_1 (" ", 0, NULL_PTR);
3466 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3467 do_spec_1 (" ", 0, NULL_PTR);
3470 for (; pl; pl = pl->next)
3472 do_spec_1 ("-isystem", 1, NULL_PTR);
3473 /* Make this a separate argument. */
3474 do_spec_1 (" ", 0, NULL_PTR);
3475 do_spec_1 (pl->prefix, 1, NULL_PTR);
3476 do_spec_1 (" ", 0, NULL_PTR);
3482 for (i = 0; i < n_infiles; i++)
3483 store_arg (outfiles[i], 0, 0);
3487 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3492 this_is_library_file = 1;
3496 this_is_output_file = 1;
3501 int cur_index = argbuf_index;
3502 /* Handle the {...} following the %W. */
3505 p = handle_braces (p + 1);
3508 /* If any args were output, mark the last one for deletion
3510 if (argbuf_index != cur_index)
3511 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3515 /* %x{OPTION} records OPTION for %X to output. */
3521 /* Skip past the option value and make a copy. */
3526 string = save_string (p1 + 1, p - p1 - 2);
3528 /* See if we already recorded this option. */
3529 for (i = 0; i < n_linker_options; i++)
3530 if (! strcmp (string, linker_options[i]))
3536 /* This option is new; add it. */
3538 if (!linker_options)
3540 = (char **) xmalloc (n_linker_options * sizeof (char **));
3543 = (char **) xrealloc (linker_options,
3544 n_linker_options * sizeof (char **));
3546 linker_options[n_linker_options - 1] = string;
3550 /* Dump out the options accumulated previously using %x. */
3552 for (i = 0; i < n_linker_options; i++)
3554 do_spec_1 (linker_options[i], 1, NULL_PTR);
3555 /* Make each accumulated option a separate argument. */
3556 do_spec_1 (" ", 0, NULL_PTR);
3560 /* Dump out the options accumulated previously using -Wa,. */
3562 for (i = 0; i < n_assembler_options; i++)
3564 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3565 /* Make each accumulated option a separate argument. */
3566 do_spec_1 (" ", 0, NULL_PTR);
3570 /* Dump out the options accumulated previously using -Wp,. */
3572 for (i = 0; i < n_preprocessor_options; i++)
3574 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3575 /* Make each accumulated option a separate argument. */
3576 do_spec_1 (" ", 0, NULL_PTR);
3580 /* Here are digits and numbers that just process
3581 a certain constant string as a spec. */
3584 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3590 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3596 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3602 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3608 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3614 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3620 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3626 value = do_spec_1 (link_spec, 0, NULL_PTR);
3632 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3638 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3645 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3649 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3653 if (! strncmp (y, "-D", 2))
3654 /* Copy the whole option. */
3655 while (*y && *y != ' ' && *y != '\t')
3657 else if (*y == ' ' || *y == '\t')
3658 /* Copy whitespace to the result. */
3660 /* Don't copy other options. */
3667 value = do_spec_1 (buf, 0, NULL_PTR);
3675 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3679 /* Copy all of CPP_PREDEFINES into BUF,
3680 but put __ after every -D and at the end of each arg. */
3684 if (! strncmp (y, "-D", 2))
3692 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3694 /* Stick __ at front of macro name. */
3697 /* Arrange to stick __ at the end as well. */
3701 /* Copy the macro name. */
3702 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3711 /* Copy the value given, if any. */
3712 while (*y && *y != ' ' && *y != '\t')
3715 else if (*y == ' ' || *y == '\t')
3716 /* Copy whitespace to the result. */
3718 /* Don't copy -A options */
3724 /* Copy all of CPP_PREDEFINES into BUF,
3725 but put __ after every -D. */
3729 if (! strncmp (y, "-D", 2))
3734 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3736 /* Stick -D__ at front of macro name. */
3742 /* Copy the macro name. */
3743 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3746 /* Copy the value given, if any. */
3747 while (*y && *y != ' ' && *y != '\t')
3752 /* Do not copy this macro - we have just done it before */
3753 while (*y && *y != ' ' && *y != '\t')
3757 else if (*y == ' ' || *y == '\t')
3758 /* Copy whitespace to the result. */
3760 /* Don't copy -A options */
3766 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3770 if (! strncmp (y, "-A", 2))
3771 /* Copy the whole option. */
3772 while (*y && *y != ' ' && *y != '\t')
3774 else if (*y == ' ' || *y == '\t')
3775 /* Copy whitespace to the result. */
3777 /* Don't copy other options. */
3784 value = do_spec_1 (buf, 0, NULL_PTR);
3791 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3796 /* Here we define characters other than letters and digits. */
3799 p = handle_braces (p);
3805 obstack_1grow (&obstack, '%');
3809 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3810 do_spec_1 (" ", 0, NULL_PTR);
3813 /* Process a string found as the value of a spec given by name.
3814 This feature allows individual machine descriptions
3815 to add and use their own specs.
3816 %[...] modifies -D options the way %P does;
3817 %(...) uses the spec unmodified. */
3822 struct spec_list *sl;
3825 /* The string after the S/P is the name of a spec that is to be
3827 while (*p && *p != ')' && *p != ']')
3830 /* See if it's in the list */
3831 for (len = p - name, sl = specs; sl; sl = sl->next)
3832 if (sl->name_len == len && !strncmp (sl->name, name, len))
3834 name = *(sl->ptr_spec);
3836 fprintf (stderr, "Processing spec %c%s%c, which is '%s'\n",
3837 c, sl->name, (c == '(') ? ')' : ']', name);
3846 value = do_spec_1 (name, 0, NULL_PTR);
3852 char *x = (char *) alloca (strlen (name) * 2 + 1);
3856 /* Copy all of NAME into BUF, but put __ after
3857 every -D and at the end of each arg, */
3862 if (! strncmp (y, "-D", 2))
3872 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
3873 || *y == '}' || *y == 0))
3886 value = do_spec_1 (buf, 0, NULL_PTR);
3892 /* Discard the closing paren or bracket. */
3900 int c1 = *p++; /* Select first or second version number. */
3901 char *v = compiler_version;
3904 /* The format of the version string is
3905 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3907 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3908 while (! ISDIGIT (*v))
3910 if (v > compiler_version && v[-1] != '-')
3913 /* If desired, advance to second version number. */
3916 /* Set V after the first period. */
3917 while (ISDIGIT (*v))
3924 /* Set Q at the next period or at the end. */
3926 while (ISDIGIT (*q))
3928 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3931 /* Put that part into the command. */
3932 obstack_grow (&obstack, v, q - v);
3938 if (input_from_pipe)
3939 do_spec_1 ("-", 0, NULL_PTR);
3948 /* Backslash: treat next character as ordinary. */
3953 /* Ordinary character: put it into the current argument. */
3954 obstack_1grow (&obstack, c);
3958 return 0; /* End of string */
3961 /* Return 0 if we call do_spec_1 and that returns -1. */
3972 int include_blanks = 1;
3975 /* A '^' after the open-brace means to not give blanks before args. */
3976 include_blanks = 0, ++p;
3979 /* A `|' after the open-brace means,
3980 if the test fails, output a single minus sign rather than nothing.
3981 This is used in %{|!pipe:...}. */
3985 /* A `!' after the open-brace negates the condition:
3986 succeed if the specified switch is not present. */
3990 /* A `.' after the open-brace means test against the current suffix. */
4000 while (*p != ':' && *p != '}') p++;
4003 register int count = 1;
4021 int found = (input_suffix != 0
4022 && strlen (input_suffix) == p - filter
4023 && strncmp (input_suffix, filter, p - filter) == 0);
4029 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4034 else if (p[-1] == '*' && p[0] == '}')
4036 /* Substitute all matching switches as separate args. */
4039 for (i = 0; i < n_switches; i++)
4040 if (!strncmp (switches[i].part1, filter, p - filter)
4041 && check_live_switch (i, p - filter))
4042 give_switch (i, 0, include_blanks);
4046 /* Test for presence of the specified switch. */
4050 /* If name specified ends in *, as in {x*:...},
4051 check for %* and handle that case. */
4052 if (p[-1] == '*' && !negate)
4057 /* First see whether we have %*. */
4061 if (*r == '%' && r[1] == '*')
4065 /* If we do, handle that case. */
4068 /* Substitute all matching switches as separate args.
4069 But do this by substituting for %*
4070 in the text that follows the colon. */
4072 unsigned hard_match_len = p - filter - 1;
4073 char *string = save_string (p + 1, q - p - 2);
4075 for (i = 0; i < n_switches; i++)
4076 if (!strncmp (switches[i].part1, filter, hard_match_len)
4077 && check_live_switch (i, -1))
4079 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4080 /* Pass any arguments this switch has. */
4081 give_switch (i, 1, 1);
4088 /* If name specified ends in *, as in {x*:...},
4089 check for presence of any switch name starting with x. */
4092 for (i = 0; i < n_switches; i++)
4094 unsigned hard_match_len = p - filter - 1;
4096 if (!strncmp (switches[i].part1, filter, hard_match_len)
4097 && check_live_switch (i, hard_match_len))
4103 /* Otherwise, check for presence of exact name specified. */
4106 for (i = 0; i < n_switches; i++)
4108 if (!strncmp (switches[i].part1, filter, p - filter)
4109 && switches[i].part1[p - filter] == 0
4110 && check_live_switch (i, -1))
4118 /* If it is as desired (present for %{s...}, absent for %{-s...})
4119 then substitute either the switch or the specified
4120 conditional text. */
4121 if (present != negate)
4125 give_switch (i, 0, include_blanks);
4129 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4135 /* Here if a %{|...} conditional fails: output a minus sign,
4136 which means "standard output" or "standard input". */
4137 do_spec_1 ("-", 0, NULL_PTR);
4144 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4145 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4146 spec, or -1 if either exact match or %* is used.
4148 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4149 whose value does not begin with "no-" is obsoleted by the same value
4150 with the "no-", similarly for a switch with the "no-" prefix. */
4153 check_live_switch (switchnum, prefix_length)
4157 char *name = switches[switchnum].part1;
4160 /* In the common case of {<at-most-one-letter>*}, a negating
4161 switch would always match, so ignore that case. We will just
4162 send the conflicting switches to the compiler phase. */
4163 if (prefix_length >= 0 && prefix_length <= 1)
4166 /* If we already processed this switch and determined if it was
4167 live or not, return our past determination. */
4168 if (switches[switchnum].live_cond != 0)
4169 return switches[switchnum].live_cond > 0;
4171 /* Now search for duplicate in a manner that depends on the name. */
4175 for (i = switchnum + 1; i < n_switches; i++)
4176 if (switches[i].part1[0] == 'O')
4178 switches[switchnum].valid = 1;
4179 switches[switchnum].live_cond = -1;
4184 case 'W': case 'f': case 'm':
4185 if (! strncmp (name + 1, "no-", 3))
4187 /* We have Xno-YYY, search for XYYY. */
4188 for (i = switchnum + 1; i < n_switches; i++)
4189 if (switches[i].part1[0] == name[0]
4190 && ! strcmp (&switches[i].part1[1], &name[4]))
4192 switches[switchnum].valid = 1;
4193 switches[switchnum].live_cond = -1;
4199 /* We have XYYY, search for Xno-YYY. */
4200 for (i = switchnum + 1; i < n_switches; i++)
4201 if (switches[i].part1[0] == name[0]
4202 && switches[i].part1[1] == 'n'
4203 && switches[i].part1[2] == 'o'
4204 && switches[i].part1[3] == '-'
4205 && !strcmp (&switches[i].part1[4], &name[1]))
4207 switches[switchnum].valid = 1;
4208 switches[switchnum].live_cond = -1;
4215 /* Otherwise the switch is live. */
4216 switches[switchnum].live_cond = 1;
4220 /* Pass a switch to the current accumulating command
4221 in the same form that we received it.
4222 SWITCHNUM identifies the switch; it is an index into
4223 the vector of switches gcc received, which is `switches'.
4224 This cannot fail since it never finishes a command line.
4226 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4228 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4232 give_switch (switchnum, omit_first_word, include_blanks)
4234 int omit_first_word;
4237 if (!omit_first_word)
4239 do_spec_1 ("-", 0, NULL_PTR);
4240 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4243 if (switches[switchnum].args != 0)
4246 for (p = switches[switchnum].args; *p; p++)
4249 do_spec_1 (" ", 0, NULL_PTR);
4250 do_spec_1 (*p, 1, NULL_PTR);
4254 do_spec_1 (" ", 0, NULL_PTR);
4255 switches[switchnum].valid = 1;
4258 /* Search for a file named NAME trying various prefixes including the
4259 user's -B prefix and some standard ones.
4260 Return the absolute file name found. If nothing is found, return NAME. */
4268 /* Try multilib_dir if it is defined. */
4269 if (multilib_dir != NULL)
4273 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4274 strcpy (try, multilib_dir);
4275 strcat (try, dir_separator_str);
4278 newname = find_a_file (&startfile_prefixes, try, R_OK);
4280 /* If we don't find it in the multi library dir, then fall
4281 through and look for it in the normal places. */
4282 if (newname != NULL)
4286 newname = find_a_file (&startfile_prefixes, name, R_OK);
4287 return newname ? newname : name;
4290 /* Determine whether a directory exists. If LINKER, return 0 for
4291 certain fixed names not needed by the linker. If not LINKER, it is
4292 only important to return 0 if the host machine has a small ARG_MAX
4296 is_directory (path1, path2, linker)
4301 int len1 = strlen (path1);
4302 int len2 = strlen (path2);
4303 char *path = (char *) alloca (3 + len1 + len2);
4307 #ifndef SMALL_ARG_MAX
4312 /* Construct the path from the two parts. Ensure the string ends with "/.".
4313 The resulting path will be a directory even if the given path is a
4315 bcopy (path1, path, len1);
4316 bcopy (path2, path + len1, len2);
4317 cp = path + len1 + len2;
4318 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4319 *cp++ = DIR_SEPARATOR;
4323 /* Exclude directories that the linker is known to search. */
4326 && strcmp (path, concat (dir_separator_str, "lib",
4327 dir_separator_str, ".", NULL_PTR)) == 0)
4329 && strcmp (path, concat (dir_separator_str, "usr",
4330 dir_separator_str, "lib",
4331 dir_separator_str, ".", NULL_PTR)) == 0)))
4334 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4337 /* On fatal signals, delete all the temporary files. */
4340 fatal_error (signum)
4343 signal (signum, SIG_DFL);
4344 delete_failure_queue ();
4345 delete_temp_files ();
4346 /* Get the same signal again, this time not handled,
4347 so its normal effect occurs. */
4348 kill (getpid (), signum);
4359 int linker_was_run = 0;
4360 char *explicit_link_files;
4363 struct user_specs *uptr;
4365 p = argv[0] + strlen (argv[0]);
4366 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4369 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4370 signal (SIGINT, fatal_error);
4372 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4373 signal (SIGHUP, fatal_error);
4375 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4376 signal (SIGTERM, fatal_error);
4378 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4379 signal (SIGPIPE, fatal_error);
4383 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4385 obstack_init (&obstack);
4387 /* Build multilib_select, et. al from the separate lines that make up each
4388 multilib selection. */
4390 char **q = multilib_raw;
4393 obstack_init (&multilib_obstack);
4394 while ((p = *q++) != (char *) 0)
4395 obstack_grow (&multilib_obstack, p, strlen (p));
4397 obstack_1grow (&multilib_obstack, 0);
4398 multilib_select = obstack_finish (&multilib_obstack);
4400 q = multilib_matches_raw;
4401 while ((p = *q++) != (char *) 0)
4402 obstack_grow (&multilib_obstack, p, strlen (p));
4404 obstack_1grow (&multilib_obstack, 0);
4405 multilib_matches = obstack_finish (&multilib_obstack);
4409 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4413 obstack_1grow (&multilib_obstack, ' ');
4414 obstack_grow (&multilib_obstack,
4415 multilib_defaults_raw[i],
4416 strlen (multilib_defaults_raw[i]));
4420 obstack_1grow (&multilib_obstack, 0);
4421 multilib_defaults = obstack_finish (&multilib_obstack);
4424 /* Set up to remember the pathname of gcc and any options
4425 needed for collect. We use argv[0] instead of programname because
4426 we need the complete pathname. */
4427 obstack_init (&collect_obstack);
4428 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4429 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4430 putenv (obstack_finish (&collect_obstack));
4432 #ifdef INIT_ENVIRONMENT
4433 /* Set up any other necessary machine specific environment variables. */
4434 putenv (INIT_ENVIRONMENT);
4437 /* Choose directory for temp files. */
4439 temp_filename = choose_temp_base ();
4440 temp_filename_length = strlen (temp_filename);
4442 /* Make a table of what switches there are (switches, n_switches).
4443 Make a table of specified input files (infiles, n_infiles).
4444 Decode switches that are handled locally. */
4446 process_command (argc, argv);
4451 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4453 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4454 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4457 for (i = 0; i < n_switches; i++)
4462 obstack_grow (&collect_obstack, " ", 1);
4465 obstack_grow (&collect_obstack, "'-", 2);
4466 q = switches[i].part1;
4467 while ((p = index (q,'\'')))
4469 obstack_grow (&collect_obstack, q, p-q);
4470 obstack_grow (&collect_obstack, "'\\''", 4);
4473 obstack_grow (&collect_obstack, q, strlen (q));
4474 obstack_grow (&collect_obstack, "'", 1);
4476 for (args = switches[i].args; args && *args; args++)
4478 obstack_grow (&collect_obstack, " '", 2);
4480 while ((p = index (q,'\'')))
4482 obstack_grow (&collect_obstack, q, p-q);
4483 obstack_grow (&collect_obstack, "'\\''", 4);
4486 obstack_grow (&collect_obstack, q, strlen (q));
4487 obstack_grow (&collect_obstack, "'", 1);
4490 obstack_grow (&collect_obstack, "\0", 1);
4491 putenv (obstack_finish (&collect_obstack));
4494 /* Initialize the vector of specs to just the default.
4495 This means one element containing 0s, as a terminator. */
4497 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4498 bcopy ((char *) default_compilers, (char *) compilers,
4499 sizeof default_compilers);
4500 n_compilers = n_default_compilers;
4502 /* Read specs from a file if there is one. */
4504 machine_suffix = concat (spec_machine, dir_separator_str,
4505 spec_version, dir_separator_str, NULL_PTR);
4506 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4508 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4509 /* Read the specs file unless it is a default one. */
4510 if (specs_file != 0 && strcmp (specs_file, "specs"))
4511 read_specs (specs_file, TRUE);
4515 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4516 for any override of as, ld and libraries. */
4517 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4518 + strlen (just_machine_suffix)
4519 + sizeof ("specs"));
4521 strcpy (specs_file, standard_exec_prefix);
4522 strcat (specs_file, just_machine_suffix);
4523 strcat (specs_file, "specs");
4524 if (access (specs_file, R_OK) == 0)
4525 read_specs (specs_file, TRUE);
4527 /* Process any user specified specs in the order given on the command
4529 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4531 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4532 read_specs (filename ? filename : uptr->filename, FALSE);
4535 /* If not cross-compiling, look for startfiles in the standard places. */
4536 /* The fact that these are done here, after reading the specs file,
4537 means that it cannot be found in these directories.
4538 But that's okay. It should never be there anyway. */
4539 if (*cross_compile == '0')
4541 #ifdef MD_EXEC_PREFIX
4542 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4543 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4546 #ifdef MD_STARTFILE_PREFIX
4547 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4551 #ifdef MD_STARTFILE_PREFIX_1
4552 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4556 /* If standard_startfile_prefix is relative, base it on
4557 standard_exec_prefix. This lets us move the installed tree
4558 as a unit. If GCC_EXEC_PREFIX is defined, base
4559 standard_startfile_prefix on that as well. */
4560 if (*standard_startfile_prefix == '/'
4561 || *standard_startfile_prefix == DIR_SEPARATOR
4562 || *standard_startfile_prefix == '$'
4564 /* Check for disk name on MS-DOS-based systems. */
4565 || (standard_startfile_prefix[1] == ':'
4566 && (standard_startfile_prefix[2] == DIR_SEPARATOR
4567 || standard_startfile_prefix[2] == '/'))
4570 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4574 if (gcc_exec_prefix)
4575 add_prefix (&startfile_prefixes,
4576 concat (gcc_exec_prefix, machine_suffix,
4577 standard_startfile_prefix, NULL_PTR),
4578 NULL_PTR, 0, 0, NULL_PTR);
4579 add_prefix (&startfile_prefixes,
4580 concat (standard_exec_prefix,
4582 standard_startfile_prefix, NULL_PTR),
4583 NULL_PTR, 0, 0, NULL_PTR);
4586 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4587 "BINUTILS", 0, 0, NULL_PTR);
4588 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4589 "BINUTILS", 0, 0, NULL_PTR);
4590 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4591 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
4596 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4597 add_prefix (&startfile_prefixes,
4598 concat (gcc_exec_prefix, machine_suffix,
4599 standard_startfile_prefix, NULL_PTR),
4600 "BINUTILS", 0, 0, NULL_PTR);
4603 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4604 if (gcc_exec_prefix)
4606 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4607 + strlen (spec_version)
4608 + strlen (spec_machine) + 3);
4609 strcpy (temp, gcc_exec_prefix);
4610 strcat (temp, spec_machine);
4611 strcat (temp, dir_separator_str);
4612 strcat (temp, spec_version);
4613 strcat (temp, dir_separator_str);
4614 gcc_exec_prefix = temp;
4617 /* Now we have the specs.
4618 Set the `valid' bits for switches that match anything in any spec. */
4620 validate_all_switches ();
4622 /* Now that we have the switches and the specs, set
4623 the subdirectory based on the options. */
4624 set_multilib_dir ();
4626 /* Warn about any switches that no pass was interested in. */
4628 for (i = 0; i < n_switches; i++)
4629 if (! switches[i].valid)
4630 error ("unrecognized option `-%s'", switches[i].part1);
4632 /* Obey some of the options. */
4634 if (print_search_dirs)
4636 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4637 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4638 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4642 if (print_file_name)
4644 printf ("%s\n", find_file (print_file_name));
4648 if (print_prog_name)
4650 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4651 printf ("%s\n", (newname ? newname : print_prog_name));
4655 if (print_multi_lib)
4657 print_multilib_info ();
4661 if (print_multi_directory)
4663 if (multilib_dir == NULL)
4666 printf ("%s\n", multilib_dir);
4674 /* compiler_version is truncated at the first space when initialized
4675 from version string, so truncate version_string at the first space
4676 before comparing. */
4677 for (n = 0; version_string[n]; n++)
4678 if (version_string[n] == ' ')
4681 if (! strncmp (version_string, compiler_version, n)
4682 && compiler_version[n] == 0)
4683 fprintf (stderr, "gcc version %s\n", version_string);
4685 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4686 version_string, compiler_version);
4693 fatal ("No input files");
4695 /* Make a place to record the compiler output file names
4696 that correspond to the input files. */
4698 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4699 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4701 /* Record which files were specified explicitly as link input. */
4703 explicit_link_files = xmalloc (n_infiles);
4704 bzero (explicit_link_files, n_infiles);
4706 for (i = 0; i < n_infiles; i++)
4708 register struct compiler *cp = 0;
4709 int this_file_error = 0;
4711 /* Tell do_spec what to substitute for %i. */
4713 input_filename = infiles[i].name;
4714 input_filename_length = strlen (input_filename);
4715 input_file_number = i;
4717 /* Use the same thing in %o, unless cp->spec says otherwise. */
4719 outfiles[i] = input_filename;
4721 /* Figure out which compiler from the file's suffix. */
4723 cp = lookup_compiler (infiles[i].name, input_filename_length,
4724 infiles[i].language);
4728 /* Ok, we found an applicable compiler. Run its spec. */
4729 /* First say how much of input_filename to substitute for %b */
4733 if (cp->spec[0][0] == '#')
4734 error ("%s: %s compiler not installed on this system",
4735 input_filename, &cp->spec[0][1]);
4737 input_basename = input_filename;
4738 for (p = input_filename; *p; p++)
4739 if (*p == '/' || *p == DIR_SEPARATOR)
4740 input_basename = p + 1;
4742 /* Find a suffix starting with the last period,
4743 and set basename_length to exclude that suffix. */
4744 basename_length = strlen (input_basename);
4745 p = input_basename + basename_length;
4746 while (p != input_basename && *p != '.') --p;
4747 if (*p == '.' && p != input_basename)
4749 basename_length = p - input_basename;
4750 input_suffix = p + 1;
4756 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4758 len += strlen (cp->spec[j]);
4760 p = (char *) xmalloc (len + 1);
4763 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4766 strcpy (p + len, cp->spec[j]);
4767 len += strlen (cp->spec[j]);
4770 value = do_spec (p);
4773 this_file_error = 1;
4776 /* If this file's name does not contain a recognized suffix,
4777 record it as explicit linker input. */
4780 explicit_link_files[i] = 1;
4782 /* Clear the delete-on-failure queue, deleting the files in it
4783 if this compilation failed. */
4785 if (this_file_error)
4787 delete_failure_queue ();
4790 /* If this compilation succeeded, don't delete those files later. */
4791 clear_failure_queue ();
4794 /* Run ld to link all the compiler output files. */
4796 if (error_count == 0)
4798 int tmp = execution_count;
4800 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4802 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4803 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4805 value = do_spec (link_command_spec);
4808 linker_was_run = (tmp != execution_count);
4811 /* Warn if a -B option was specified but the prefix was never used. */
4812 unused_prefix_warnings (&exec_prefixes);
4813 unused_prefix_warnings (&startfile_prefixes);
4815 /* If options said don't run linker,
4816 complain about input files to be given to the linker. */
4818 if (! linker_was_run && error_count == 0)
4819 for (i = 0; i < n_infiles; i++)
4820 if (explicit_link_files[i])
4821 error ("%s: linker input file unused since linking not done",
4824 /* Delete some or all of the temporary files we made. */
4827 delete_failure_queue ();
4828 delete_temp_files ();
4830 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4835 /* Find the proper compilation spec for the file name NAME,
4836 whose length is LENGTH. LANGUAGE is the specified language,
4837 or 0 if this file is to be passed to the linker. */
4839 static struct compiler *
4840 lookup_compiler (name, length, language)
4845 struct compiler *cp;
4847 /* If this was specified by the user to be a linker input, indicate that. */
4848 if (language != 0 && language[0] == '*')
4851 /* Otherwise, look for the language, if one is spec'd. */
4854 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4855 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
4858 error ("language %s not recognized", language);
4862 /* Look for a suffix. */
4863 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4865 if (/* The suffix `-' matches only the file name `-'. */
4866 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4867 || (strlen (cp->suffix) < length
4868 /* See if the suffix matches the end of NAME. */
4870 && ((!strcmp (cp->suffix,
4871 name + length - strlen (cp->suffix))
4872 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
4873 && !strcasecmp (cp->suffix,
4874 name + length - strlen (cp->suffix)))
4876 && !strcmp (cp->suffix,
4877 name + length - strlen (cp->suffix))
4881 if (cp->spec[0][0] == '@')
4883 struct compiler *new;
4885 /* An alias entry maps a suffix to a language.
4886 Search for the language; pass 0 for NAME and LENGTH
4887 to avoid infinite recursion if language not found.
4888 Construct the new compiler spec. */
4889 language = cp->spec[0] + 1;
4890 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4891 new->suffix = cp->suffix;
4892 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4893 (char *) new->spec, sizeof new->spec);
4897 /* A non-alias entry: return it. */
4909 register char *value = (char *) malloc (size);
4911 fatal ("virtual memory exhausted");
4916 xrealloc (ptr, size)
4920 register char *value = (char *) realloc (ptr, size);
4922 fatal ("virtual memory exhausted");
4926 /* This function is based on the one in libiberty. */
4929 concat VPROTO((char *first, ...))
4931 register int length;
4932 register char *newstr;
4940 /* First compute the size of the result and get sufficient memory. */
4942 VA_START (args, first);
4944 first = va_arg (args, char *);
4952 length += strlen (arg);
4953 arg = va_arg (args, char *);
4956 newstr = (char *) xmalloc (length + 1);
4959 /* Now copy the individual pieces to the result string. */
4961 VA_START (args, first);
4963 first = va_arg (args, char *);
4972 arg = va_arg (args, char *);
4981 save_string (s, len)
4985 register char *result = xmalloc (len + 1);
4987 bcopy (s, result, len);
4993 pfatal_with_name (name)
4996 fatal ("%s: %s", name, my_strerror (errno));
5000 perror_with_name (name)
5003 error ("%s: %s", name, my_strerror (errno));
5007 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5011 int save_errno = errno;
5015 /* Space for trailing '\0' is in %s. */
5016 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5017 sprintf (msg, errmsg_fmt, errmsg_arg);
5021 fatal ("%s: %s", errmsg_fmt, my_strerror (save_errno));
5024 /* More 'friendly' abort that prints the line and file.
5025 config.h can #define abort fancy_abort if you like that sort of thing. */
5030 fatal ("Internal gcc abort.");
5035 /* Output an error message and exit */
5038 fatal VPROTO((char *format, ...))
5045 VA_START (ap, format);
5048 format = va_arg (ap, char *);
5051 fprintf (stderr, "%s: ", programname);
5052 vfprintf (stderr, format, ap);
5054 fprintf (stderr, "\n");
5055 delete_temp_files ();
5060 error VPROTO((char *format, ...))
5067 VA_START (ap, format);
5070 format = va_arg (ap, char *);
5073 fprintf (stderr, "%s: ", programname);
5074 vfprintf (stderr, format, ap);
5077 fprintf (stderr, "\n");
5080 #else /* not HAVE_VPRINTF */
5083 fatal (msg, arg1, arg2)
5084 char *msg, *arg1, *arg2;
5086 error (msg, arg1, arg2);
5087 delete_temp_files ();
5092 error (msg, arg1, arg2)
5093 char *msg, *arg1, *arg2;
5095 fprintf (stderr, "%s: ", programname);
5096 fprintf (stderr, msg, arg1, arg2);
5097 fprintf (stderr, "\n");
5100 #endif /* not HAVE_VPRINTF */
5104 validate_all_switches ()
5106 struct compiler *comp;
5109 struct spec_list *spec;
5111 for (comp = compilers; comp->spec[0]; comp++)
5114 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5118 if (c == '%' && *p == '{')
5119 /* We have a switch spec. */
5120 validate_switches (p + 1);
5124 /* look through the linked list of specs read from the specs file */
5125 for (spec = specs; spec ; spec = spec->next)
5127 p = *(spec->ptr_spec);
5129 if (c == '%' && *p == '{')
5130 /* We have a switch spec. */
5131 validate_switches (p + 1);
5134 p = link_command_spec;
5136 if (c == '%' && *p == '{')
5137 /* We have a switch spec. */
5138 validate_switches (p + 1);
5141 /* Look at the switch-name that comes after START
5142 and mark as valid all supplied switches that match it. */
5145 validate_switches (start)
5148 register char *p = start;
5163 while (*p != ':' && *p != '}') p++;
5167 else if (p[-1] == '*')
5169 /* Mark all matching switches as valid. */
5171 for (i = 0; i < n_switches; i++)
5172 if (!strncmp (switches[i].part1, filter, p - filter))
5173 switches[i].valid = 1;
5177 /* Mark an exact matching switch as valid. */
5178 for (i = 0; i < n_switches; i++)
5180 if (!strncmp (switches[i].part1, filter, p - filter)
5181 && switches[i].part1[p - filter] == 0)
5182 switches[i].valid = 1;
5187 /* Check whether a particular argument was used. The first time we
5188 canonicalize the switches to keep only the ones we care about. */
5202 static struct mswitchstr *mswitches;
5203 static int n_mswitches;
5208 struct mswitchstr *matches;
5212 /* Break multilib_matches into the component strings of string and replacement
5214 for (q = multilib_matches; *q != '\0'; q++)
5218 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5220 q = multilib_matches;
5231 matches[i].len = q - matches[i].str;
5233 matches[i].replace = ++q;
5234 while (*q != ';' && *q != '\0')
5240 matches[i].rep_len = q - matches[i].replace;
5248 /* Now build a list of the replacement string for switches that we care
5249 about. Make sure we allocate at least one entry. This prevents
5250 xmalloc from calling fatal, and prevents us from re-executing this
5253 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5254 * (n_switches ? n_switches : 1));
5255 for (i = 0; i < n_switches; i++)
5257 int xlen = strlen (switches[i].part1);
5258 for (j = 0; j < cnt; j++)
5259 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5261 mswitches[n_mswitches].str = matches[j].replace;
5262 mswitches[n_mswitches].len = matches[j].rep_len;
5263 mswitches[n_mswitches].replace = (char *)0;
5264 mswitches[n_mswitches].rep_len = 0;
5271 for (i = 0; i < n_mswitches; i++)
5272 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5279 default_arg (p, len)
5285 for (start = multilib_defaults; *start != '\0'; start = end+1)
5287 while (*start == ' ' || *start == '\t')
5293 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5296 if ((end - start) == len && strncmp (p, start, len) == 0)
5306 /* Work out the subdirectory to use based on the
5307 options. The format of multilib_select is a list of elements.
5308 Each element is a subdirectory name followed by a list of options
5309 followed by a semicolon. gcc will consider each line in turn. If
5310 none of the options beginning with an exclamation point are
5311 present, and all of the other options are present, that
5312 subdirectory will be used. */
5317 char *p = multilib_select;
5319 char *this_path, *this_arg;
5325 /* Ignore newlines. */
5332 /* Get the initial path. */
5340 this_path_len = p - this_path;
5342 /* Check the arguments. */
5357 while (*p != ' ' && *p != ';')
5364 if (*this_arg != '!')
5372 /* If this is a default argument, we can just ignore it.
5373 This is true even if this_arg begins with '!'. Beginning
5374 with '!' does not mean that this argument is necessarily
5375 inappropriate for this library: it merely means that
5376 there is a more specific library which uses this
5377 argument. If this argument is a default, we need not
5378 consider that more specific library. */
5379 if (! default_arg (this_arg, p - this_arg))
5381 ok = used_arg (this_arg, p - this_arg);
5392 if (this_path_len != 1
5393 || this_path[0] != '.')
5395 multilib_dir = xmalloc (this_path_len + 1);
5396 strncpy (multilib_dir, this_path, this_path_len);
5397 multilib_dir[this_path_len] = '\0';
5406 /* Print out the multiple library subdirectory selection
5407 information. This prints out a series of lines. Each line looks
5408 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5409 required. Only the desired options are printed out, the negative
5410 matches. The options are print without a leading dash. There are
5411 no spaces to make it easy to use the information in the shell.
5412 Each subdirectory is printed only once. This assumes the ordering
5413 generated by the genmultilib script. */
5416 print_multilib_info ()
5418 char *p = multilib_select;
5419 char *last_path = 0, *this_path;
5421 int last_path_len = 0;
5425 /* Ignore newlines. */
5432 /* Get the initial path. */
5441 /* If this is a duplicate, skip it. */
5442 skip = (last_path != 0 && p - this_path == last_path_len
5443 && ! strncmp (last_path, this_path, last_path_len));
5445 last_path = this_path;
5446 last_path_len = p - this_path;
5448 /* If this directory requires any default arguments, we can skip
5449 it. We will already have printed a directory identical to
5450 this one which does not require that default argument. */
5468 while (*q != ' ' && *q != ';')
5476 && default_arg (arg, q - arg))
5491 for (p1 = last_path; p1 < p; p1++)
5510 use_arg = *p != '!';
5515 while (*p != ' ' && *p != ';')
5530 /* If there are extra options, print them now */
5531 if (multilib_extra && *multilib_extra)
5533 int print_at = TRUE;
5536 for (q = multilib_extra; *q != '\0'; q++)