1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-96, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!! */
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers. It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec". */
34 #include <sys/types.h>
41 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
46 #include "gansidecl.h"
61 /* ??? Need to find a GCC header to put these in. */
62 extern int pexecute PROTO ((const char *, char * const *, const char *,
63 const char *, char **, char **, int));
64 extern int pwait PROTO ((int, int *, int));
65 /* Flag arguments to pexecute. */
66 #define PEXECUTE_FIRST 1
67 #define PEXECUTE_LAST 2
68 #define PEXECUTE_SEARCH 4
69 #define PEXECUTE_VERBOSE 8
72 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
75 #define WTERMSIG(S) ((S) & 0x7f)
78 #define WIFEXITED(S) (((S) & 0xff) == 0)
81 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
85 #define exit __posix_exit
88 /* Define O_RDONLY if the system hasn't defined it for us. */
97 /* Test if something is a normal file. */
99 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
102 /* Test if something is a directory. */
104 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
107 /* By default there is no special suffix for executables. */
108 #ifdef EXECUTABLE_SUFFIX
109 #define HAVE_EXECUTABLE_SUFFIX
111 #define EXECUTABLE_SUFFIX ""
114 /* By default, the suffix for object files is ".o". */
116 #define HAVE_OBJECT_SUFFIX
118 #define OBJECT_SUFFIX ".o"
121 /* By default, colon separates directories in a path. */
122 #ifndef PATH_SEPARATOR
123 #define PATH_SEPARATOR ':'
126 #ifndef DIR_SEPARATOR
127 #define DIR_SEPARATOR '/'
130 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
132 #define obstack_chunk_alloc xmalloc
133 #define obstack_chunk_free free
136 extern char *getenv ();
138 extern char *choose_temp_base PROTO((void));
144 #ifndef HAVE_STRERROR
147 extern const char *const sys_errlist[];
149 extern char *sys_errlist[];
152 extern char *strerror();
155 /* If a stage of compilation returns an exit status >= 1,
156 compilation of that file ceases. */
158 #define MIN_FATAL_STATUS 1
160 /* Flag saying to print the directories gcc will search through looking for
161 programs, libraries, etc. */
163 static int print_search_dirs;
165 /* Flag saying to print the full filename of this file
166 as found through our usual search mechanism. */
168 static char *print_file_name = NULL;
170 /* As print_file_name, but search for executable file. */
172 static char *print_prog_name = NULL;
174 /* Flag saying to print the relative path we'd use to
175 find libgcc.a given the current compiler flags. */
177 static int print_multi_directory;
179 /* Flag saying to print the list of subdirectories and
180 compiler flags used to select them in a standard form. */
182 static int print_multi_lib;
184 /* Flag indicating whether we should print the command and arguments */
186 static int verbose_flag;
188 /* Nonzero means write "temp" files in source directory
189 and use the source file's name in them, and don't delete them. */
191 static int save_temps_flag;
193 /* The compiler version. */
195 static char *compiler_version;
197 /* The target version specified with -V */
199 static char *spec_version = DEFAULT_TARGET_VERSION;
201 /* The target machine specified with -b. */
203 static char *spec_machine = DEFAULT_TARGET_MACHINE;
205 /* Nonzero if cross-compiling.
206 When -b is used, the value comes from the `specs' file. */
209 static char *cross_compile = "1";
211 static char *cross_compile = "0";
214 /* The number of errors that have occurred; the link phase will not be
215 run if this is non-zero. */
216 static int error_count = 0;
218 /* This is the obstack which we use to allocate many strings. */
220 static struct obstack obstack;
222 /* This is the obstack to build an environment variable to pass to
223 collect2 that describes all of the relevant switches of what to
224 pass the compiler in building the list of pointers to constructors
227 static struct obstack collect_obstack;
229 extern char *version_string;
231 /* Forward declaration for prototypes. */
234 static void init_spec PROTO((int));
235 static void set_spec PROTO((char *, char *));
236 static struct compiler *lookup_compiler PROTO((char *, int, char *));
237 static char *build_search_list PROTO((struct path_prefix *, char *, int));
238 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
239 static char *find_a_file PROTO((struct path_prefix *, char *, int));
240 static void add_prefix PROTO((struct path_prefix *, char *, int, int, int *));
241 static char *skip_whitespace PROTO((char *));
242 static void record_temp_file PROTO((char *, int, int));
243 static void delete_if_ordinary PROTO((char *));
244 static void delete_temp_files PROTO((void));
245 static void delete_failure_queue PROTO((void));
246 static void clear_failure_queue PROTO((void));
247 static int check_live_switch PROTO((int, int));
248 static char *handle_braces PROTO((char *));
249 static char *save_string PROTO((char *, int));
250 static char *concat PVPROTO((char *, ...));
251 static int do_spec PROTO((char *));
252 static int do_spec_1 PROTO((char *, int, char *));
253 static char *find_file PROTO((char *));
254 static int is_directory PROTO((char *, char *, int));
255 static void validate_switches PROTO((char *));
256 static void validate_all_switches PROTO((void));
257 static void give_switch PROTO((int, int, int));
258 static int used_arg PROTO((char *, int));
259 static int default_arg PROTO((char *, int));
260 static void set_multilib_dir PROTO((void));
261 static void print_multilib_info PROTO((void));
262 static void pfatal_with_name PROTO((char *));
263 static void perror_with_name PROTO((char *));
264 static void pfatal_pexecute PROTO((char *, char *));
266 static void fatal PVPROTO((char *, ...));
267 static void error PVPROTO((char *, ...));
269 /* We must not provide any prototype here, even if ANSI C. */
270 static void fatal PROTO(());
271 static void error PROTO(());
278 /* Specs are strings containing lines, each of which (if not blank)
279 is made up of a program name, and arguments separated by spaces.
280 The program name must be exact and start from root, since no path
281 is searched and it is unreliable to depend on the current working directory.
282 Redirection of input or output is not supported; the subprograms must
283 accept filenames saying what files to read and write.
285 In addition, the specs can contain %-sequences to substitute variable text
286 or for conditional text. Here is a table of all defined %-sequences.
287 Note that spaces are not generated automatically around the results of
288 expanding these sequences; therefore, you can concatenate them together
289 or with constant text in a single argument.
291 %% substitute one % into the program name or argument.
292 %i substitute the name of the input file being processed.
293 %b substitute the basename of the input file being processed.
294 This is the substring up to (and not including) the last period
295 and not including the directory.
296 %g substitute the temporary-file-name-base. This is a string chosen
297 once per compilation. Different temporary file names are made by
298 concatenation of constant strings on the end, as in `%g.s'.
299 %g also has the same effect of %d.
300 %u like %g, but make the temporary file name unique.
301 %U returns the last file name generated with %u.
302 %d marks the argument containing or following the %d as a
303 temporary file name, so that that file will be deleted if CC exits
304 successfully. Unlike %g, this contributes no text to the argument.
305 %w marks the argument containing or following the %w as the
306 "output file" of this compilation. This puts the argument
307 into the sequence of arguments that %o will substitute later.
309 like %{...} but mark last argument supplied within
310 as a file to be deleted on failure.
311 %o substitutes the names of all the output files, with spaces
312 automatically placed around them. You should write spaces
313 around the %o as well or the results are undefined.
314 %o is for use in the specs for running the linker.
315 Input files whose names have no recognized suffix are not compiled
316 at all, but they are included among the output files, so they will
318 %O substitutes the suffix for object files.
319 %p substitutes the standard macro predefinitions for the
320 current target machine. Use this when running cpp.
321 %P like %p, but puts `__' before and after the name of each macro.
322 (Except macros that already have __.)
324 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
325 %s current argument is the name of a library or startup file of some sort.
326 Search for that file in a standard list of directories
327 and substitute the full name found.
328 %eSTR Print STR as an error message. STR is terminated by a newline.
329 Use this when inconsistent options are detected.
330 %x{OPTION} Accumulate an option for %X.
331 %X Output the accumulated linker options specified by compilations.
332 %Y Output the accumulated assembler options specified by compilations.
333 %Z Output the accumulated preprocessor options specified by compilations.
334 %v1 Substitute the major version number of GCC.
335 (For version 2.5.n, this is 2.)
336 %v2 Substitute the minor version number of GCC.
337 (For version 2.5.n, this is 5.)
338 %a process ASM_SPEC as a spec.
339 This allows config.h to specify part of the spec for running as.
340 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
341 used here. This can be used to run a post-processor after the
342 assembler has done it's job.
343 %D Dump out a -L option for each directory in startfile_prefixes.
344 If multilib_dir is set, extra entries are generated with it affixed.
345 %l process LINK_SPEC as a spec.
346 %L process LIB_SPEC as a spec.
347 %G process LIBGCC_SPEC as a spec.
348 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
349 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
350 %c process SIGNED_CHAR_SPEC as a spec.
351 %C process CPP_SPEC as a spec. A capital C is actually used here.
352 %1 process CC1_SPEC as a spec.
353 %2 process CC1PLUS_SPEC as a spec.
354 %| output "-" if the input for the current command is coming from a pipe.
355 %* substitute the variable part of a matched option. (See below.)
356 Note that each comma in the substituted string is replaced by
358 %{S} substitutes the -S switch, if that switch was given to CC.
359 If that switch was not specified, this substitutes nothing.
360 Here S is a metasyntactic variable.
361 %{S*} substitutes all the switches specified to CC whose names start
362 with -S. This is used for -o, -D, -I, etc; switches that take
363 arguments. CC considers `-o foo' as being one switch whose
364 name starts with `o'. %{o*} would substitute this text,
365 including the space; thus, two arguments would be generated.
366 %{^S*} likewise, but don't put a blank between a switch and any args.
367 %{S*:X} substitutes X if one or more switches whose names start with -S are
368 specified to CC. Note that the tail part of the -S option
369 (i.e. the part matched by the `*') will be substituted for each
370 occurrence of %* within X.
371 %{S:X} substitutes X, but only if the -S switch was given to CC.
372 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
373 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
374 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
375 %{.S:X} substitutes X, but only if processing a file with suffix S.
376 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
377 %(Spec) processes a specification defined in a specs file as *Spec:
378 %[Spec] as above, but put __ around -D arguments
380 The conditional text X in a %{S:X} or %{!S:X} construct may contain
381 other nested % constructs or spaces, or even newlines. They are
382 processed as usual, as described above.
384 The -O, -f, -m, and -W switches are handled specifically in these
385 constructs. If another value of -O or the negated form of a -f, -m, or
386 -W switch is found later in the command line, the earlier switch
387 value is ignored, except with {S*} where S is just one letter; this
388 passes all matching options.
390 The character | is used to indicate that a command should be piped to
391 the following command, but only if -pipe is specified.
393 Note that it is built into CC which switches take arguments and which
394 do not. You might think it would be useful to generalize this to
395 allow each compiler's spec to say which switches take arguments. But
396 this cannot be done in a consistent fashion. CC cannot even decide
397 which input files have been specified without knowing which switches
398 take arguments, and it must know which input files to compile in order
399 to tell which compilers to run.
401 CC also knows implicitly that arguments starting in `-l' are to be
402 treated as compiler output files, and passed to the linker in their
403 proper position among the other output files. */
405 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
407 /* config.h can define ASM_SPEC to provide extra args to the assembler
408 or extra switch-translations. */
413 /* config.h can define ASM_FINAL_SPEC to run a post processor after
414 the assembler has run. */
415 #ifndef ASM_FINAL_SPEC
416 #define ASM_FINAL_SPEC ""
419 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
420 or extra switch-translations. */
425 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
426 or extra switch-translations. */
431 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
432 or extra switch-translations. */
434 #define CC1PLUS_SPEC ""
437 /* config.h can define LINK_SPEC to provide extra args to the linker
438 or extra switch-translations. */
443 /* config.h can define LIB_SPEC to override the default libraries. */
445 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
448 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
451 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
452 /* Have gcc do the search for libgcc.a. */
453 #define LIBGCC_SPEC "libgcc.a%s"
455 #define LIBGCC_SPEC "-lgcc"
459 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
460 #ifndef STARTFILE_SPEC
461 #define STARTFILE_SPEC \
462 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
465 /* config.h can define SWITCHES_NEED_SPACES to control which options
466 require spaces between the option and the argument. */
467 #ifndef SWITCHES_NEED_SPACES
468 #define SWITCHES_NEED_SPACES ""
471 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
473 #define ENDFILE_SPEC ""
476 /* This spec is used for telling cpp whether char is signed or not. */
477 #ifndef SIGNED_CHAR_SPEC
478 /* Use #if rather than ?:
479 because MIPS C compiler rejects like ?: in initializers. */
480 #if DEFAULT_SIGNED_CHAR
481 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
483 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
487 static char *cpp_spec = CPP_SPEC;
488 static char *cpp_predefines = CPP_PREDEFINES;
489 static char *cc1_spec = CC1_SPEC;
490 static char *cc1plus_spec = CC1PLUS_SPEC;
491 static char *signed_char_spec = SIGNED_CHAR_SPEC;
492 static char *asm_spec = ASM_SPEC;
493 static char *asm_final_spec = ASM_FINAL_SPEC;
494 static char *link_spec = LINK_SPEC;
495 static char *lib_spec = LIB_SPEC;
496 static char *libgcc_spec = LIBGCC_SPEC;
497 static char *endfile_spec = ENDFILE_SPEC;
498 static char *startfile_spec = STARTFILE_SPEC;
499 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
501 /* Some compilers have limits on line lengths, and the multilib_select
502 and/or multilib_matches strings can be very long, so we build them at
504 static struct obstack multilib_obstack;
505 static char *multilib_select;
506 static char *multilib_matches;
507 static char *multilib_defaults;
508 #include "multilib.h"
510 /* Check whether a particular argument is a default argument. */
512 #ifndef MULTILIB_DEFAULTS
513 #define MULTILIB_DEFAULTS { "" }
516 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
519 struct user_specs *next;
523 static struct user_specs *user_specs_head, *user_specs_tail;
525 /* This defines which switch letters take arguments. */
527 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
528 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
529 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
530 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
531 || (CHAR) == 'L' || (CHAR) == 'A')
533 #ifndef SWITCH_TAKES_ARG
534 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
537 /* This defines which multi-letter switches take arguments. */
539 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
540 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
541 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
542 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
543 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
544 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
545 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
547 #ifndef WORD_SWITCH_TAKES_ARG
548 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
551 /* Record the mapping from file suffixes for compilation specs. */
555 char *suffix; /* Use this compiler for input files
556 whose names end in this suffix. */
558 char *spec[4]; /* To use this compiler, concatenate these
559 specs and pass to do_spec. */
562 /* Pointer to a vector of `struct compiler' that gives the spec for
563 compiling a file, based on its suffix.
564 A file that does not end in any of these suffixes will be passed
565 unchanged to the loader and nothing else will be done to it.
567 An entry containing two 0s is used to terminate the vector.
569 If multiple entries match a file, the last matching one is used. */
571 static struct compiler *compilers;
573 /* Number of entries in `compilers', not counting the null terminator. */
575 static int n_compilers;
577 /* The default list of file name suffixes and their compilation specs. */
579 static struct compiler default_compilers[] =
581 /* Add lists of suffixes of known languages here. If those languages
582 were no present when we built the driver, we will hit these copies
583 and given a more meaningful error than "file not used since
584 linking is not done". */
585 {".cc", "#C++"}, {".cxx", "#C++"}, {".cpp", "#C++"}, {".c++", "#C++"},
586 {".C", "#C++"}, {".ads", "#Ada"}, {".adb", "#Ada"}, {".ada", "#Ada"},
587 {".f", "#Fortran"}, {".for", "#Fortran"}, {".F", "#Fortran"},
588 {".fpp", "#Fortran"},
589 /* Next come the entries for C. */
592 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
593 %{C:%{!E:%eGNU C does not support -C without using -E}}\
594 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
595 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
596 %{ansi:-trigraphs -D__STRICT_ANSI__}\
597 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
598 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
599 %{traditional-cpp:-traditional}\
600 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
601 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
602 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
603 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
604 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
605 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
607 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
608 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
610 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
611 %{!pipe:%g.s} %A\n }}}}"},
613 "%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
614 %{C:%{!E:%eGNU C does not support -C without using -E}}\
615 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
616 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
617 %{ansi:-trigraphs -D__STRICT_ANSI__}\
618 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
619 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
620 %{traditional-cpp:-traditional}\
621 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
623 %{!E:%e-E required when input is from standard input}"},
624 {".m", "@objective-c"},
626 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
627 %{C:%{!E:%eGNU C does not support -C without using -E}}\
628 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
629 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
630 %{ansi:-trigraphs -D__STRICT_ANSI__}\
631 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
632 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
633 %{traditional-cpp:-traditional}\
634 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
635 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
636 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
637 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
638 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
639 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
640 -lang-objc %{gen-decls} \
642 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
643 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
645 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
646 %{!pipe:%g.s} %A\n }}}}"},
649 "%{!E:%eCompilation of header file requested} \
650 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
651 %{C:%{!E:%eGNU C does not support -C without using -E}}\
652 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
653 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
654 %{ansi:-trigraphs -D__STRICT_ANSI__}\
655 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
656 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
657 %{traditional-cpp:-traditional}\
658 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
660 {".i", "@cpp-output"},
662 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
663 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
664 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
666 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
667 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
669 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
670 %{!pipe:%g.s} %A\n }}}}"},
671 {".s", "@assembler"},
673 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
674 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
676 {".S", "@assembler-with-cpp"},
677 {"@assembler-with-cpp",
678 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
679 %{C:%{!E:%eGNU C does not support -C without using -E}}\
680 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
681 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
682 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{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 int optlen = strlen (option_map[j].name);
873 int arglen = strlen (argv[i]);
874 int 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);
1029 /* Read compilation specs from a file named FILENAME,
1030 replacing the default ones.
1032 A suffix which starts with `*' is a definition for
1033 one of the machine-specific sub-specs. The "suffix" should be
1034 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1035 The corresponding spec is stored in asm_spec, etc.,
1036 rather than in the `compilers' vector.
1038 Anything invalid in the file is a fatal error. */
1041 read_specs (filename)
1046 struct stat statbuf;
1051 fprintf (stderr, "Reading specs from %s\n", filename);
1053 /* Open and stat the file. */
1054 desc = open (filename, O_RDONLY, 0);
1056 pfatal_with_name (filename);
1057 if (stat (filename, &statbuf) < 0)
1058 pfatal_with_name (filename);
1060 /* Read contents of file into BUFFER. */
1061 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1062 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1064 pfatal_with_name (filename);
1065 buffer[readlen] = 0;
1068 /* Scan BUFFER for specs, putting them in the vector. */
1074 char *in, *out, *p1, *p2;
1076 /* Advance P in BUFFER to the next nonblank nocomment line. */
1077 p = skip_whitespace (p);
1081 /* Find the colon that should end the suffix. */
1083 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
1084 /* The colon shouldn't be missing. */
1086 fatal ("specs file malformed after %d characters", p1 - buffer);
1087 /* Skip back over trailing whitespace. */
1089 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
1090 /* Copy the suffix to a string. */
1091 suffix = save_string (p, p2 - p);
1092 /* Find the next line. */
1093 p = skip_whitespace (p1 + 1);
1095 fatal ("specs file malformed after %d characters", p - buffer);
1097 /* Find next blank line. */
1098 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
1099 /* Specs end at the blank line and do not include the newline. */
1100 spec = save_string (p, p1 - p);
1103 /* Delete backslash-newline sequences from the spec. */
1108 if (in[0] == '\\' && in[1] == '\n')
1110 else if (in[0] == '#')
1112 while (*in && *in != '\n') in++;
1119 if (suffix[0] == '*')
1121 if (! strcmp (suffix, "*link_command"))
1122 link_command_spec = spec;
1124 set_spec (suffix + 1, spec);
1128 /* Add this pair to the vector. */
1130 = ((struct compiler *)
1131 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
1132 compilers[n_compilers].suffix = suffix;
1133 bzero ((char *) compilers[n_compilers].spec,
1134 sizeof compilers[n_compilers].spec);
1135 compilers[n_compilers].spec[0] = spec;
1137 bzero ((char *) &compilers[n_compilers],
1138 sizeof compilers[n_compilers]);
1142 link_command_spec = spec;
1145 if (link_command_spec == 0)
1146 fatal ("spec file has no spec for linking");
1155 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1156 be considered whitespace. */
1157 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1159 else if (*p == '\n' || *p == ' ' || *p == '\t')
1163 while (*p != '\n') p++;
1173 /* Structure to keep track of the specs that have been defined so far.
1174 These are accessed using %(specname) or %[specname] in a compiler
1179 /* The following 2 fields must be first */
1180 /* to allow EXTRA_SPECS to be initialized */
1181 char *name; /* name of the spec. */
1182 char *ptr; /* available ptr if no static pointer */
1184 /* The following fields are not initialized */
1185 /* by EXTRA_SPECS */
1186 char **ptr_spec; /* pointer to the spec itself. */
1187 struct spec_list *next; /* Next spec in linked list. */
1188 int name_len; /* length of the name */
1189 int alloc_p; /* whether string was allocated */
1192 #define INIT_STATIC_SPEC(NAME,PTR) \
1193 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1195 /* List of statically defined specs */
1196 static struct spec_list static_specs[] = {
1197 INIT_STATIC_SPEC ("asm", &asm_spec),
1198 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1199 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1200 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1201 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1202 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1203 INIT_STATIC_SPEC ("link", &link_spec),
1204 INIT_STATIC_SPEC ("lib", &lib_spec),
1205 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1206 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1207 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1208 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1209 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1210 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1211 INIT_STATIC_SPEC ("version", &compiler_version),
1212 INIT_STATIC_SPEC ("multilib", &multilib_select),
1213 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1214 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1215 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1218 #ifdef EXTRA_SPECS /* additional specs needed */
1219 static struct spec_list extra_specs[] = { EXTRA_SPECS };
1222 /* List of dynamically allocates specs that have been defined so far. */
1224 static struct spec_list *specs = (struct spec_list *)0;
1227 /* Initialize the specs lookup routines. */
1230 init_spec (use_extra_p)
1233 struct spec_list *next = (struct spec_list *)0;
1234 struct spec_list *sl = (struct spec_list *)0;
1238 return; /* already initialized */
1242 for (i = (sizeof (extra_specs) / sizeof (extra_specs[0])) - 1; i >= 0; i--)
1244 sl = &extra_specs[i];
1246 sl->name_len = strlen (sl->name);
1247 sl->ptr_spec = &sl->ptr;
1252 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1254 sl = &static_specs[i];
1263 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1264 removed; If the spec starts with a + then SPEC is added to the end of the
1268 set_spec (name, spec)
1272 struct spec_list *sl;
1274 int name_len = strlen (name);
1277 /* See if the spec already exists */
1278 for (sl = specs; sl; sl = sl->next)
1279 if (name_len == sl->name_len && !strcmp (sl->name, name))
1284 /* Not found - make it */
1285 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1286 sl->name = save_string (name, strlen (name));
1287 sl->name_len = name_len;
1288 sl->ptr_spec = &sl->ptr;
1290 *(sl->ptr_spec) = "";
1295 old_spec = *(sl->ptr_spec);
1296 *(sl->ptr_spec) = ((spec[0] == '+' && isspace (spec[1]))
1297 ? concat (old_spec, spec + 1, NULL_PTR)
1298 : save_string (spec, strlen (spec)));
1300 /* Free the old spec */
1301 if (old_spec && sl->alloc_p)
1307 /* Accumulate a command (program name and args), and run it. */
1309 /* Vector of pointers to arguments in the current line of specifications. */
1311 static char **argbuf;
1313 /* Number of elements allocated in argbuf. */
1315 static int argbuf_length;
1317 /* Number of elements in argbuf currently in use (containing args). */
1319 static int argbuf_index;
1321 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1322 temp file. Used only if MKTEMP_EACH_FILE. */
1324 static struct temp_name {
1325 char *suffix; /* suffix associated with the code. */
1326 int length; /* strlen (suffix). */
1327 int unique; /* Indicates whether %g or %u/%U was used. */
1328 char *filename; /* associated filename. */
1329 int filename_length; /* strlen (filename). */
1330 struct temp_name *next;
1333 /* Number of commands executed so far. */
1335 static int execution_count;
1337 /* Number of commands that exited with a signal. */
1339 static int signal_count;
1341 /* Name with which this program was invoked. */
1343 static char *programname;
1345 /* Structures to keep track of prefixes to try when looking for files. */
1349 char *prefix; /* String to prepend to the path. */
1350 struct prefix_list *next; /* Next in linked list. */
1351 int require_machine_suffix; /* Don't use without machine_suffix. */
1352 /* 2 means try both machine_suffix and just_machine_suffix. */
1353 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1358 struct prefix_list *plist; /* List of prefixes to try */
1359 int max_len; /* Max length of a prefix in PLIST */
1360 char *name; /* Name of this list (used in config stuff) */
1363 /* List of prefixes to try when looking for executables. */
1365 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1367 /* List of prefixes to try when looking for startup (crt0) files. */
1369 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1371 /* List of prefixes to try when looking for include files. */
1373 static struct path_prefix include_prefixes = { 0, 0, "include" };
1375 /* Suffix to attach to directories searched for commands.
1376 This looks like `MACHINE/VERSION/'. */
1378 static char *machine_suffix = 0;
1380 /* Suffix to attach to directories searched for commands.
1381 This is just `MACHINE/'. */
1383 static char *just_machine_suffix = 0;
1385 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1387 static char *gcc_exec_prefix;
1389 /* Default prefixes to attach to command names. */
1391 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1392 #undef MD_EXEC_PREFIX
1393 #undef MD_STARTFILE_PREFIX
1394 #undef MD_STARTFILE_PREFIX_1
1397 #ifndef STANDARD_EXEC_PREFIX
1398 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1399 #endif /* !defined STANDARD_EXEC_PREFIX */
1401 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1402 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1403 #ifdef MD_EXEC_PREFIX
1404 static char *md_exec_prefix = MD_EXEC_PREFIX;
1407 #ifndef STANDARD_STARTFILE_PREFIX
1408 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1409 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1411 #ifdef MD_STARTFILE_PREFIX
1412 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1414 #ifdef MD_STARTFILE_PREFIX_1
1415 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1417 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1418 static char *standard_startfile_prefix_1 = "/lib/";
1419 static char *standard_startfile_prefix_2 = "/usr/lib/";
1421 #ifndef TOOLDIR_BASE_PREFIX
1422 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1424 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1425 static char *tooldir_prefix;
1427 /* Subdirectory to use for locating libraries. Set by
1428 set_multilib_dir based on the compilation options. */
1430 static char *multilib_dir;
1432 /* Clear out the vector of arguments (after a command is executed). */
1440 /* Add one argument to the vector at the end.
1441 This is done when a space is seen or at the end of the line.
1442 If DELETE_ALWAYS is nonzero, the arg is a filename
1443 and the file should be deleted eventually.
1444 If DELETE_FAILURE is nonzero, the arg is a filename
1445 and the file should be deleted if this compilation fails. */
1448 store_arg (arg, delete_always, delete_failure)
1450 int delete_always, delete_failure;
1452 if (argbuf_index + 1 == argbuf_length)
1454 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1457 argbuf[argbuf_index++] = arg;
1458 argbuf[argbuf_index] = 0;
1460 if (delete_always || delete_failure)
1461 record_temp_file (arg, delete_always, delete_failure);
1464 /* Record the names of temporary files we tell compilers to write,
1465 and delete them at the end of the run. */
1467 /* This is the common prefix we use to make temp file names.
1468 It is chosen once for each run of this program.
1469 It is substituted into a spec by %g.
1470 Thus, all temp file names contain this prefix.
1471 In practice, all temp file names start with this prefix.
1473 This prefix comes from the envvar TMPDIR if it is defined;
1474 otherwise, from the P_tmpdir macro if that is defined;
1475 otherwise, in /usr/tmp or /tmp;
1476 or finally the current directory if all else fails. */
1478 static char *temp_filename;
1480 /* Length of the prefix. */
1482 static int temp_filename_length;
1484 /* Define the list of temporary files to delete. */
1489 struct temp_file *next;
1492 /* Queue of files to delete on success or failure of compilation. */
1493 static struct temp_file *always_delete_queue;
1494 /* Queue of files to delete on failure of compilation. */
1495 static struct temp_file *failure_delete_queue;
1497 /* Record FILENAME as a file to be deleted automatically.
1498 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1499 otherwise delete it in any case.
1500 FAIL_DELETE nonzero means delete it if a compilation step fails;
1501 otherwise delete it in any case. */
1504 record_temp_file (filename, always_delete, fail_delete)
1509 register char *name;
1510 name = xmalloc (strlen (filename) + 1);
1511 strcpy (name, filename);
1515 register struct temp_file *temp;
1516 for (temp = always_delete_queue; temp; temp = temp->next)
1517 if (! strcmp (name, temp->name))
1519 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1520 temp->next = always_delete_queue;
1522 always_delete_queue = temp;
1528 register struct temp_file *temp;
1529 for (temp = failure_delete_queue; temp; temp = temp->next)
1530 if (! strcmp (name, temp->name))
1532 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1533 temp->next = failure_delete_queue;
1535 failure_delete_queue = temp;
1540 /* Delete all the temporary files whose names we previously recorded. */
1543 delete_if_ordinary (name)
1550 printf ("Delete %s? (y or n) ", name);
1554 while ((c = getchar ()) != '\n' && c != EOF) ;
1555 if (i == 'y' || i == 'Y')
1557 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1558 if (unlink (name) < 0)
1560 perror_with_name (name);
1564 delete_temp_files ()
1566 register struct temp_file *temp;
1568 for (temp = always_delete_queue; temp; temp = temp->next)
1569 delete_if_ordinary (temp->name);
1570 always_delete_queue = 0;
1573 /* Delete all the files to be deleted on error. */
1576 delete_failure_queue ()
1578 register struct temp_file *temp;
1580 for (temp = failure_delete_queue; temp; temp = temp->next)
1581 delete_if_ordinary (temp->name);
1585 clear_failure_queue ()
1587 failure_delete_queue = 0;
1590 /* Routine to add variables to the environment. We do this to pass
1591 the pathname of the gcc driver, and the directories search to the
1592 collect2 program, which is being run as ld. This way, we can be
1593 sure of executing the right compiler when collect2 wants to build
1594 constructors and destructors. Since the environment variables we
1595 use come from an obstack, we don't have to worry about allocating
1604 #ifndef VMS /* nor about VMS */
1606 extern char **environ;
1607 char **old_environ = environ;
1611 int str_len = strlen (str);
1615 while ((ch = *p++) != '\0' && ch != '=')
1621 /* Search for replacing an existing environment variable, and
1622 count the number of total environment variables. */
1623 for (envp = old_environ; *envp; envp++)
1626 if (!strncmp (str, *envp, name_len))
1633 /* Add a new environment variable */
1634 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1636 bcopy ((char *) old_environ, (char *) (environ + 1),
1637 sizeof (char *) * (num_envs+1));
1642 #endif /* HAVE_PUTENV */
1645 /* Build a list of search directories from PATHS.
1646 PREFIX is a string to prepend to the list.
1647 If CHECK_DIR_P is non-zero we ensure the directory exists.
1648 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1649 It is also used by the --print-search-dirs flag. */
1652 build_search_list (paths, prefix, check_dir_p)
1653 struct path_prefix *paths;
1657 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1659 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1660 int first_time = TRUE;
1661 struct prefix_list *pprefix;
1663 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1665 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1667 int len = strlen (pprefix->prefix);
1671 || is_directory (pprefix->prefix, machine_suffix, 0)))
1674 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1677 obstack_grow (&collect_obstack, pprefix->prefix, len);
1678 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1681 if (just_machine_suffix
1682 && pprefix->require_machine_suffix == 2
1684 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1687 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1690 obstack_grow (&collect_obstack, pprefix->prefix, len);
1691 obstack_grow (&collect_obstack, just_machine_suffix,
1695 if (!pprefix->require_machine_suffix)
1698 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1701 obstack_grow (&collect_obstack, pprefix->prefix, len);
1704 obstack_1grow (&collect_obstack, '\0');
1705 return obstack_finish (&collect_obstack);
1708 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1712 putenv_from_prefixes (paths, env_var)
1713 struct path_prefix *paths;
1716 putenv (build_search_list (paths, env_var, 1));
1719 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1720 access to check permissions.
1721 Return 0 if not found, otherwise return its name, allocated with malloc. */
1724 find_a_file (pprefix, name, mode)
1725 struct path_prefix *pprefix;
1730 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1731 struct prefix_list *pl;
1732 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1735 len += strlen (machine_suffix);
1737 temp = xmalloc (len);
1739 /* Determine the filename to execute (special case for absolute paths). */
1741 if (*name == '/' || *name == DIR_SEPARATOR)
1743 if (access (name, mode))
1745 strcpy (temp, name);
1750 for (pl = pprefix->plist; pl; pl = pl->next)
1754 /* Some systems have a suffix for executable files.
1755 So try appending that first. */
1756 if (file_suffix[0] != 0)
1758 strcpy (temp, pl->prefix);
1759 strcat (temp, machine_suffix);
1760 strcat (temp, name);
1761 strcat (temp, file_suffix);
1762 if (access (temp, mode) == 0)
1764 if (pl->used_flag_ptr != 0)
1765 *pl->used_flag_ptr = 1;
1770 /* Now try just the name. */
1771 strcpy (temp, pl->prefix);
1772 strcat (temp, machine_suffix);
1773 strcat (temp, name);
1774 if (access (temp, mode) == 0)
1776 if (pl->used_flag_ptr != 0)
1777 *pl->used_flag_ptr = 1;
1782 /* Certain prefixes are tried with just the machine type,
1783 not the version. This is used for finding as, ld, etc. */
1784 if (just_machine_suffix && pl->require_machine_suffix == 2)
1786 /* Some systems have a suffix for executable files.
1787 So try appending that first. */
1788 if (file_suffix[0] != 0)
1790 strcpy (temp, pl->prefix);
1791 strcat (temp, just_machine_suffix);
1792 strcat (temp, name);
1793 strcat (temp, file_suffix);
1794 if (access (temp, mode) == 0)
1796 if (pl->used_flag_ptr != 0)
1797 *pl->used_flag_ptr = 1;
1802 strcpy (temp, pl->prefix);
1803 strcat (temp, just_machine_suffix);
1804 strcat (temp, name);
1805 if (access (temp, mode) == 0)
1807 if (pl->used_flag_ptr != 0)
1808 *pl->used_flag_ptr = 1;
1813 /* Certain prefixes can't be used without the machine suffix
1814 when the machine or version is explicitly specified. */
1815 if (!pl->require_machine_suffix)
1817 /* Some systems have a suffix for executable files.
1818 So try appending that first. */
1819 if (file_suffix[0] != 0)
1821 strcpy (temp, pl->prefix);
1822 strcat (temp, name);
1823 strcat (temp, file_suffix);
1824 if (access (temp, mode) == 0)
1826 if (pl->used_flag_ptr != 0)
1827 *pl->used_flag_ptr = 1;
1832 strcpy (temp, pl->prefix);
1833 strcat (temp, name);
1834 if (access (temp, mode) == 0)
1836 if (pl->used_flag_ptr != 0)
1837 *pl->used_flag_ptr = 1;
1847 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1848 at the start of the list, otherwise it goes at the end.
1850 If WARN is nonzero, we will warn if no file is found
1851 through this prefix. WARN should point to an int
1852 which will be set to 1 if this entry is used.
1854 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1855 the complete value of machine_suffix.
1856 2 means try both machine_suffix and just_machine_suffix. */
1859 add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1860 struct path_prefix *pprefix;
1863 int require_machine_suffix;
1866 struct prefix_list *pl, **prev;
1869 if (!first && pprefix->plist)
1871 for (pl = pprefix->plist; pl->next; pl = pl->next)
1876 prev = &pprefix->plist;
1878 /* Keep track of the longest prefix */
1880 len = strlen (prefix);
1881 if (len > pprefix->max_len)
1882 pprefix->max_len = len;
1884 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1885 pl->prefix = save_string (prefix, len);
1886 pl->require_machine_suffix = require_machine_suffix;
1887 pl->used_flag_ptr = warn;
1894 pl->next = (struct prefix_list *) 0;
1898 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1901 unused_prefix_warnings (pprefix)
1902 struct path_prefix *pprefix;
1904 struct prefix_list *pl = pprefix->plist;
1908 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1910 if (pl->require_machine_suffix && machine_suffix)
1911 error ("file path prefix `%s%s' never used", pl->prefix,
1914 error ("file path prefix `%s' never used", pl->prefix);
1916 /* Prevent duplicate warnings. */
1917 *pl->used_flag_ptr = 1;
1923 /* Get rid of all prefixes built up so far in *PLISTP. */
1926 free_path_prefix (pprefix)
1927 struct path_prefix *pprefix;
1929 struct prefix_list *pl = pprefix->plist;
1930 struct prefix_list *temp;
1936 free (temp->prefix);
1937 free ((char *) temp);
1939 pprefix->plist = (struct prefix_list *) 0;
1942 /* Execute the command specified by the arguments on the current line of spec.
1943 When using pipes, this includes several piped-together commands
1944 with `|' between them.
1946 Return 0 if successful, -1 if failed. */
1952 int n_commands; /* # of command. */
1956 char *prog; /* program name. */
1957 char **argv; /* vector of args. */
1958 int pid; /* pid of process for this command. */
1961 struct command *commands; /* each command buffer with above info. */
1963 /* Count # of piped commands. */
1964 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1965 if (strcmp (argbuf[i], "|") == 0)
1968 /* Get storage for each command. */
1970 = (struct command *) alloca (n_commands * sizeof (struct command));
1972 /* Split argbuf into its separate piped processes,
1973 and record info about each one.
1974 Also search for the programs that are to be run. */
1976 commands[0].prog = argbuf[0]; /* first command. */
1977 commands[0].argv = &argbuf[0];
1978 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
1980 commands[0].argv[0] = string;
1982 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1983 if (strcmp (argbuf[i], "|") == 0)
1984 { /* each command. */
1985 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) || defined (OS2)
1986 fatal ("-pipe not supported");
1988 argbuf[i] = 0; /* termination of command args. */
1989 commands[n_commands].prog = argbuf[i + 1];
1990 commands[n_commands].argv = &argbuf[i + 1];
1991 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
1993 commands[n_commands].argv[0] = string;
1997 argbuf[argbuf_index] = 0;
1999 /* If -v, print what we are about to do, and maybe query. */
2003 /* Print each piped command as a separate line. */
2004 for (i = 0; i < n_commands ; i++)
2008 for (j = commands[i].argv; *j; j++)
2009 fprintf (stderr, " %s", *j);
2011 /* Print a pipe symbol after all but the last command. */
2012 if (i + 1 != n_commands)
2013 fprintf (stderr, " |");
2014 fprintf (stderr, "\n");
2018 fprintf (stderr, "\nGo ahead? (y or n) ");
2022 while (getchar () != '\n') ;
2023 if (i != 'y' && i != 'Y')
2028 /* Run each piped subprocess. */
2030 for (i = 0; i < n_commands; i++)
2032 char *errmsg_fmt, *errmsg_arg;
2033 char *string = commands[i].argv[0];
2035 commands[i].pid = pexecute (string, commands[i].argv,
2036 programname, temp_filename,
2037 &errmsg_fmt, &errmsg_arg,
2038 ((i == 0 ? PEXECUTE_FIRST : 0)
2039 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2040 | (string == commands[i].prog
2041 ? PEXECUTE_SEARCH : 0)
2042 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2044 if (commands[i].pid == -1)
2045 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2047 if (string != commands[i].prog)
2053 /* Wait for all the subprocesses to finish.
2054 We don't care what order they finish in;
2055 we know that N_COMMANDS waits will get them all.
2056 Ignore subprocesses that we don't know about,
2057 since they can be spawned by the process that exec'ed us. */
2062 for (i = 0; i < n_commands; )
2068 pid = pwait (commands[i].pid, &status, 0);
2072 for (j = 0; j < n_commands; j++)
2073 if (commands[j].pid == pid)
2078 if (WIFSIGNALED (status))
2080 fatal ("Internal compiler error: program %s got fatal signal %d",
2081 commands[j].prog, WTERMSIG (status));
2085 else if (WIFEXITED (status)
2086 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2096 /* Find all the switches given to us
2097 and make a vector describing them.
2098 The elements of the vector are strings, one per switch given.
2099 If a switch uses following arguments, then the `part1' field
2100 is the switch itself and the `args' field
2101 is a null-terminated vector containing the following arguments.
2102 The `live_cond' field is 1 if the switch is true in a conditional spec,
2103 -1 if false (overridden by a later switch), and is initialized to zero.
2104 The `valid' field is nonzero if any spec has looked at this switch;
2105 if it remains zero at the end of the run, it must be meaningless. */
2115 static struct switchstr *switches;
2117 static int n_switches;
2125 /* Also a vector of input files specified. */
2127 static struct infile *infiles;
2129 static int n_infiles;
2131 /* And a vector of corresponding output files is made up later. */
2133 static char **outfiles;
2135 /* Used to track if none of the -B paths are used. */
2138 /* Used to track if standard path isn't used and -b or -V is specified. */
2139 static int warn_std;
2141 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2142 static int *warn_std_ptr = 0;
2145 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2147 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2148 is true if we should look for an executable suffix as well. */
2151 convert_filename (name, do_exe)
2156 int len = strlen (name);
2158 #ifdef HAVE_OBJECT_SUFFIX
2159 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2161 && name[len - 2] == '.'
2162 && name[len - 1] == 'o')
2164 obstack_grow (&obstack, name[i], len - 2);
2165 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2166 name = obstack_finish (&obstack);
2170 #ifdef HAVE_EXECUTABLE_SUFFIX
2171 /* If there is no filetype, make it the executable suffix (which includes
2172 the "."). But don't get confused if we have just "-o". */
2173 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2176 for (i = len - 1; i >= 0; i--)
2177 if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2180 for (i++; i < len; i++)
2184 obstack_grow (&obstack, name, len);
2185 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2186 name = obstack_finish (&obstack);
2193 /* Create the vector `switches' and its contents.
2194 Store its length in `n_switches'. */
2197 process_command (argc, argv)
2203 char *spec_lang = 0;
2204 int last_language_n_infiles;
2207 int lang_n_infiles = 0;
2209 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
2214 /* Figure compiler version from version string. */
2216 compiler_version = save_string (version_string, strlen (version_string));
2217 for (temp = compiler_version; *temp; ++temp)
2226 /* Set up the default search paths. */
2228 if (gcc_exec_prefix)
2230 add_prefix (&exec_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2231 add_prefix (&startfile_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2234 /* COMPILER_PATH and LIBRARY_PATH have values
2235 that are lists of directory names with colons. */
2237 temp = getenv ("COMPILER_PATH");
2240 char *startp, *endp;
2241 char *nstore = (char *) alloca (strlen (temp) + 3);
2243 startp = endp = temp;
2246 if (*endp == PATH_SEPARATOR || *endp == 0)
2248 strncpy (nstore, startp, endp-startp);
2250 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2251 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2253 nstore[endp-startp] = DIR_SEPARATOR;
2254 nstore[endp-startp+1] = 0;
2257 nstore[endp-startp] = 0;
2258 add_prefix (&exec_prefixes, nstore, 0, 0, NULL_PTR);
2261 endp = startp = endp + 1;
2268 temp = getenv ("LIBRARY_PATH");
2269 if (temp && *cross_compile == '0')
2271 char *startp, *endp;
2272 char *nstore = (char *) alloca (strlen (temp) + 3);
2274 startp = endp = temp;
2277 if (*endp == PATH_SEPARATOR || *endp == 0)
2279 strncpy (nstore, startp, endp-startp);
2281 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2282 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2284 nstore[endp-startp] = DIR_SEPARATOR;
2285 nstore[endp-startp+1] = 0;
2288 nstore[endp-startp] = 0;
2289 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2292 endp = startp = endp + 1;
2299 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2300 temp = getenv ("LPATH");
2301 if (temp && *cross_compile == '0')
2303 char *startp, *endp;
2304 char *nstore = (char *) alloca (strlen (temp) + 3);
2306 startp = endp = temp;
2309 if (*endp == PATH_SEPARATOR || *endp == 0)
2311 strncpy (nstore, startp, endp-startp);
2313 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2314 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2316 nstore[endp-startp] = DIR_SEPARATOR;
2317 nstore[endp-startp+1] = 0;
2320 nstore[endp-startp] = 0;
2321 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2324 endp = startp = endp + 1;
2331 /* Convert new-style -- options to old-style. */
2332 translate_options (&argc, &argv);
2334 #ifdef LANG_SPECIFIC_DRIVER
2335 /* Do language-specific adjustment/addition of flags. */
2336 lang_specific_driver (&fatal, &argc, &argv);
2339 /* Scan argv twice. Here, the first time, just count how many switches
2340 there will be in their vector, and how many input files in theirs.
2341 Here we also parse the switches that cc itself uses (e.g. -v). */
2343 for (i = 1; i < argc; i++)
2345 if (! strcmp (argv[i], "-dumpspecs"))
2347 struct spec_list *sl;
2349 for (sl = specs; sl; sl = sl->next)
2350 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2353 else if (! strcmp (argv[i], "-dumpversion"))
2355 printf ("%s\n", version_string);
2358 else if (! strcmp (argv[i], "-dumpmachine"))
2360 printf ("%s\n", spec_machine);
2363 else if (! strcmp (argv[i], "-print-search-dirs"))
2364 print_search_dirs = 1;
2365 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2366 print_file_name = "libgcc.a";
2367 else if (! strncmp (argv[i], "-print-file-name=", 17))
2368 print_file_name = argv[i] + 17;
2369 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2370 print_prog_name = argv[i] + 17;
2371 else if (! strcmp (argv[i], "-print-multi-lib"))
2372 print_multi_lib = 1;
2373 else if (! strcmp (argv[i], "-print-multi-directory"))
2374 print_multi_directory = 1;
2375 else if (! strncmp (argv[i], "-Wa,", 4))
2378 /* Pass the rest of this option to the assembler. */
2380 n_assembler_options++;
2381 if (!assembler_options)
2383 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2386 = (char **) xrealloc (assembler_options,
2387 n_assembler_options * sizeof (char **));
2389 /* Split the argument at commas. */
2391 for (j = 4; argv[i][j]; j++)
2392 if (argv[i][j] == ',')
2394 assembler_options[n_assembler_options - 1]
2395 = save_string (argv[i] + prev, j - prev);
2396 n_assembler_options++;
2398 = (char **) xrealloc (assembler_options,
2399 n_assembler_options * sizeof (char **));
2402 /* Record the part after the last comma. */
2403 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2405 else if (! strncmp (argv[i], "-Wp,", 4))
2408 /* Pass the rest of this option to the preprocessor. */
2410 n_preprocessor_options++;
2411 if (!preprocessor_options)
2412 preprocessor_options
2413 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2415 preprocessor_options
2416 = (char **) xrealloc (preprocessor_options,
2417 n_preprocessor_options * sizeof (char **));
2419 /* Split the argument at commas. */
2421 for (j = 4; argv[i][j]; j++)
2422 if (argv[i][j] == ',')
2424 preprocessor_options[n_preprocessor_options - 1]
2425 = save_string (argv[i] + prev, j - prev);
2426 n_preprocessor_options++;
2427 preprocessor_options
2428 = (char **) xrealloc (preprocessor_options,
2429 n_preprocessor_options * sizeof (char **));
2432 /* Record the part after the last comma. */
2433 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2435 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2436 /* The +e options to the C++ front-end. */
2438 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2441 /* Split the argument at commas. */
2442 for (j = 3; argv[i][j]; j++)
2443 n_infiles += (argv[i][j] == ',');
2445 else if (strcmp (argv[i], "-Xlinker") == 0)
2448 fatal ("argument to `-Xlinker' is missing");
2453 else if (strncmp (argv[i], "-l", 2) == 0)
2455 else if (strcmp (argv[i], "-save-temps") == 0)
2457 save_temps_flag = 1;
2460 else if (strcmp (argv[i], "-specs") == 0)
2462 struct user_specs *user = (struct user_specs *)
2463 xmalloc (sizeof (struct user_specs));
2465 fatal ("argument to `-specs' is missing");
2467 user->next = (struct user_specs *)0;
2468 user->filename = argv[i];
2469 if (user_specs_tail)
2470 user_specs_tail->next = user;
2472 user_specs_head = user;
2473 user_specs_tail = user;
2475 else if (strncmp (argv[i], "-specs=", 7) == 0)
2477 struct user_specs *user = (struct user_specs *)
2478 xmalloc (sizeof (struct user_specs));
2479 if (strlen (argv[i]) == 7)
2480 fatal ("argument to `-specs=' is missing");
2482 user->next = (struct user_specs *)0;
2483 user->filename = argv[i]+7;
2484 if (user_specs_tail)
2485 user_specs_tail->next = user;
2487 user_specs_head = user;
2488 user_specs_tail = user;
2490 else if (argv[i][0] == '-' && argv[i][1] != 0)
2492 register char *p = &argv[i][1];
2493 register int c = *p;
2498 if (p[1] == 0 && i + 1 == argc)
2499 fatal ("argument to `-b' is missing");
2501 spec_machine = argv[++i];
2503 spec_machine = p + 1;
2505 warn_std_ptr = &warn_std;
2510 int *temp = (int *) xmalloc (sizeof (int));
2512 if (p[1] == 0 && i + 1 == argc)
2513 fatal ("argument to `-B' is missing");
2518 add_prefix (&exec_prefixes, value, 1, 0, &warn_B);
2519 add_prefix (&startfile_prefixes, value, 1, 0, &warn_B);
2520 add_prefix (&include_prefixes, concat (value, "include", NULL_PTR),
2523 /* As a kludge, if the arg is "[foo/]stageN/", just add
2524 "[foo/]include" to the include prefix. */
2526 int len = strlen (value);
2529 && (value[len - 8] == '/'
2530 || value[len - 8] == DIR_SEPARATOR)))
2531 && strncmp (value + len - 7, "stage", 5) == 0
2532 && isdigit (value[len - 2])
2533 && (value[len - 1] == '/'
2534 || value[len - 1] == DIR_SEPARATOR))
2537 add_prefix (&include_prefixes, "include",
2541 char *string = xmalloc (len + 1);
2542 strncpy (string, value, len-7);
2543 strcpy (string+len-7, "include");
2544 add_prefix (&include_prefixes, string,
2552 case 'v': /* Print our subcommands and print versions. */
2554 /* If they do anything other than exactly `-v', don't set
2555 verbose_flag; rather, continue on to give the error. */
2562 if (p[1] == 0 && i + 1 == argc)
2563 fatal ("argument to `-V' is missing");
2565 spec_version = argv[++i];
2567 spec_version = p + 1;
2568 compiler_version = spec_version;
2569 warn_std_ptr = &warn_std;
2583 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2584 argv[i] = convert_filename (argv[i], 1);
2586 argv[i+1] = convert_filename (argv[i+1], 1);
2594 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2595 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2596 else if (WORD_SWITCH_TAKES_ARG (p))
2597 i += WORD_SWITCH_TAKES_ARG (p);
2607 if (have_c && have_o && lang_n_infiles > 1)
2608 fatal ("cannot specify -o with -c and multiple compilations");
2610 /* Set up the search paths before we go looking for config files. */
2612 /* These come before the md prefixes so that we will find gcc's subcommands
2613 (such as cpp) rather than those of the host system. */
2614 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2615 as well as trying the machine and the version. */
2617 add_prefix (&exec_prefixes, standard_exec_prefix, 0, 2, warn_std_ptr);
2618 add_prefix (&exec_prefixes, standard_exec_prefix_1, 0, 2, warn_std_ptr);
2621 add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, warn_std_ptr);
2622 add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, warn_std_ptr);
2624 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
2625 dir_separator_str, NULL_PTR);
2627 /* If tooldir is relative, base it on exec_prefixes. A relative
2628 tooldir lets us move the installed tree as a unit.
2630 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2631 directories, so that we can search both the user specified directory
2632 and the standard place. */
2634 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2636 if (gcc_exec_prefix)
2638 char *gcc_exec_tooldir_prefix
2639 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2640 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2642 add_prefix (&exec_prefixes,
2643 concat (gcc_exec_tooldir_prefix, "bin",
2644 dir_separator_str, NULL_PTR),
2646 add_prefix (&startfile_prefixes,
2647 concat (gcc_exec_tooldir_prefix, "lib",
2648 dir_separator_str, NULL_PTR),
2652 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2653 dir_separator_str, spec_version,
2654 dir_separator_str, tooldir_prefix, NULL_PTR);
2657 add_prefix (&exec_prefixes,
2658 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2660 add_prefix (&startfile_prefixes,
2661 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2664 /* More prefixes are enabled in main, after we read the specs file
2665 and determine whether this is cross-compilation or not. */
2668 /* Then create the space for the vectors and scan again. */
2670 switches = ((struct switchstr *)
2671 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2672 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2675 last_language_n_infiles = -1;
2677 /* This, time, copy the text of each switch and store a pointer
2678 to the copy in the vector of switches.
2679 Store all the infiles in their vector. */
2681 for (i = 1; i < argc; i++)
2683 /* Just skip the switches that were handled by the preceding loop. */
2684 if (! strncmp (argv[i], "-Wa,", 4))
2686 else if (! strncmp (argv[i], "-Wp,", 4))
2688 else if (! strcmp (argv[i], "-print-search-dirs"))
2690 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2692 else if (! strncmp (argv[i], "-print-file-name=", 17))
2694 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2696 else if (! strcmp (argv[i], "-print-multi-lib"))
2698 else if (! strcmp (argv[i], "-print-multi-directory"))
2700 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2702 /* Compensate for the +e options to the C++ front-end;
2703 they're there simply for cfront call-compatibility. We do
2704 some magic in default_compilers to pass them down properly.
2705 Note we deliberately start at the `+' here, to avoid passing
2706 -e0 or -e1 down into the linker. */
2707 switches[n_switches].part1 = &argv[i][0];
2708 switches[n_switches].args = 0;
2709 switches[n_switches].live_cond = 0;
2710 switches[n_switches].valid = 0;
2713 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2716 /* Split the argument at commas. */
2718 for (j = 4; argv[i][j]; j++)
2719 if (argv[i][j] == ',')
2721 infiles[n_infiles].language = 0;
2722 infiles[n_infiles++].name
2723 = save_string (argv[i] + prev, j - prev);
2726 /* Record the part after the last comma. */
2727 infiles[n_infiles].language = 0;
2728 infiles[n_infiles++].name = argv[i] + prev;
2730 else if (strcmp (argv[i], "-Xlinker") == 0)
2732 infiles[n_infiles].language = 0;
2733 infiles[n_infiles++].name = argv[++i];
2735 else if (strncmp (argv[i], "-l", 2) == 0)
2737 infiles[n_infiles].language = 0;
2738 infiles[n_infiles++].name = argv[i];
2740 else if (strcmp (argv[i], "-specs") == 0)
2742 else if (strncmp (argv[i], "-specs=", 7) == 0)
2744 else if (argv[i][0] == '-' && argv[i][1] != 0)
2746 register char *p = &argv[i][1];
2747 register int c = *p;
2749 if (c == 'B' || c == 'b' || c == 'V')
2751 /* Skip a separate arg, if any. */
2758 if (p[1] == 0 && i + 1 == argc)
2759 fatal ("argument to `-x' is missing");
2761 spec_lang = argv[++i];
2764 if (! strcmp (spec_lang, "none"))
2765 /* Suppress the warning if -xnone comes after the last input
2766 file, because alternate command interfaces like g++ might
2767 find it useful to place -xnone after each input file. */
2770 last_language_n_infiles = n_infiles;
2773 switches[n_switches].part1 = p;
2774 /* Deal with option arguments in separate argv elements. */
2775 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2776 || WORD_SWITCH_TAKES_ARG (p))
2779 int n_args = WORD_SWITCH_TAKES_ARG (p);
2783 /* Count only the option arguments in separate argv elements. */
2784 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2786 if (i + n_args >= argc)
2787 fatal ("argument to `-%s' is missing", p);
2788 switches[n_switches].args
2789 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2791 switches[n_switches].args[j++] = argv[++i];
2792 /* Null-terminate the vector. */
2793 switches[n_switches].args[j] = 0;
2795 else if (index (switches_need_spaces, c))
2797 /* On some systems, ld cannot handle some options without
2798 a space. So split the option from its argument. */
2799 char *part1 = (char *) xmalloc (2);
2803 switches[n_switches].part1 = part1;
2804 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2805 switches[n_switches].args[0] = xmalloc (strlen (p));
2806 strcpy (switches[n_switches].args[0], &p[1]);
2807 switches[n_switches].args[1] = 0;
2810 switches[n_switches].args = 0;
2812 switches[n_switches].live_cond = 0;
2813 switches[n_switches].valid = 0;
2814 /* This is always valid, since gcc.c itself understands it. */
2815 if (!strcmp (p, "save-temps"))
2816 switches[n_switches].valid = 1;
2821 #ifdef HAVE_OBJECT_SUFFIX
2822 argv[i] = convert_filename (argv[i], 0);
2825 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
2827 perror_with_name (argv[i]);
2832 infiles[n_infiles].language = spec_lang;
2833 infiles[n_infiles++].name = argv[i];
2838 if (n_infiles == last_language_n_infiles && spec_lang != 0)
2839 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2841 switches[n_switches].part1 = 0;
2842 infiles[n_infiles].name = 0;
2845 /* Process a spec string, accumulating and running commands. */
2847 /* These variables describe the input file name.
2848 input_file_number is the index on outfiles of this file,
2849 so that the output file name can be stored for later use by %o.
2850 input_basename is the start of the part of the input file
2851 sans all directory names, and basename_length is the number
2852 of characters starting there excluding the suffix .c or whatever. */
2854 static char *input_filename;
2855 static int input_file_number;
2856 static int input_filename_length;
2857 static int basename_length;
2858 static char *input_basename;
2859 static char *input_suffix;
2861 /* These are variables used within do_spec and do_spec_1. */
2863 /* Nonzero if an arg has been started and not yet terminated
2864 (with space, tab or newline). */
2865 static int arg_going;
2867 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2868 is a temporary file name. */
2869 static int delete_this_arg;
2871 /* Nonzero means %w has been seen; the next arg to be terminated
2872 is the output file name of this compilation. */
2873 static int this_is_output_file;
2875 /* Nonzero means %s has been seen; the next arg to be terminated
2876 is the name of a library file and we should try the standard
2877 search dirs for it. */
2878 static int this_is_library_file;
2880 /* Nonzero means that the input of this command is coming from a pipe. */
2881 static int input_from_pipe;
2883 /* Process the spec SPEC and run the commands specified therein.
2884 Returns 0 if the spec is successfully processed; -1 if failed. */
2894 delete_this_arg = 0;
2895 this_is_output_file = 0;
2896 this_is_library_file = 0;
2897 input_from_pipe = 0;
2899 value = do_spec_1 (spec, 0, NULL_PTR);
2901 /* Force out any unfinished command.
2902 If -pipe, this forces out the last command if it ended in `|'. */
2905 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2908 if (argbuf_index > 0)
2915 /* Process the sub-spec SPEC as a portion of a larger spec.
2916 This is like processing a whole spec except that we do
2917 not initialize at the beginning and we do not supply a
2918 newline by default at the end.
2919 INSWITCH nonzero means don't process %-sequences in SPEC;
2920 in this case, % is treated as an ordinary character.
2921 This is used while substituting switches.
2922 INSWITCH nonzero also causes SPC not to terminate an argument.
2924 Value is zero unless a line was finished
2925 and the command on that line reported an error. */
2928 do_spec_1 (spec, inswitch, soft_matched_part)
2931 char *soft_matched_part;
2933 register char *p = spec;
2940 /* If substituting a switch, treat all chars like letters.
2941 Otherwise, NL, SPC, TAB and % are special. */
2942 switch (inswitch ? 'a' : c)
2945 /* End of line: finish any pending argument,
2946 then run the pending command if one has been started. */
2949 obstack_1grow (&obstack, 0);
2950 string = obstack_finish (&obstack);
2951 if (this_is_library_file)
2952 string = find_file (string);
2953 store_arg (string, delete_this_arg, this_is_output_file);
2954 if (this_is_output_file)
2955 outfiles[input_file_number] = string;
2959 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2961 for (i = 0; i < n_switches; i++)
2962 if (!strcmp (switches[i].part1, "pipe"))
2965 /* A `|' before the newline means use a pipe here,
2966 but only if -pipe was specified.
2967 Otherwise, execute now and don't pass the `|' as an arg. */
2970 input_from_pipe = 1;
2971 switches[i].valid = 1;
2978 if (argbuf_index > 0)
2984 /* Reinitialize for a new command, and for a new argument. */
2987 delete_this_arg = 0;
2988 this_is_output_file = 0;
2989 this_is_library_file = 0;
2990 input_from_pipe = 0;
2994 /* End any pending argument. */
2997 obstack_1grow (&obstack, 0);
2998 string = obstack_finish (&obstack);
2999 if (this_is_library_file)
3000 string = find_file (string);
3001 store_arg (string, delete_this_arg, this_is_output_file);
3002 if (this_is_output_file)
3003 outfiles[input_file_number] = string;
3007 obstack_1grow (&obstack, c);
3013 /* Space or tab ends an argument if one is pending. */
3016 obstack_1grow (&obstack, 0);
3017 string = obstack_finish (&obstack);
3018 if (this_is_library_file)
3019 string = find_file (string);
3020 store_arg (string, delete_this_arg, this_is_output_file);
3021 if (this_is_output_file)
3022 outfiles[input_file_number] = string;
3024 /* Reinitialize for a new argument. */
3026 delete_this_arg = 0;
3027 this_is_output_file = 0;
3028 this_is_library_file = 0;
3035 fatal ("Invalid specification! Bug in cc.");
3038 obstack_grow (&obstack, input_basename, basename_length);
3043 delete_this_arg = 2;
3046 /* Dump out the directories specified with LIBRARY_PATH,
3047 followed by the absolute directories
3048 that we search for startfiles. */
3051 struct prefix_list *pl = startfile_prefixes.plist;
3053 char *buffer = (char *) xmalloc (bufsize);
3056 for (; pl; pl = pl->next)
3058 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3059 /* Used on systems which record the specified -L dirs
3060 and use them to search for dynamic linking. */
3061 /* Relative directories always come from -B,
3062 and it is better not to use them for searching
3063 at run time. In particular, stage1 loses */
3064 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3067 /* Try subdirectory if there is one. */
3068 if (multilib_dir != NULL)
3072 if (strlen (pl->prefix) + strlen (machine_suffix)
3074 bufsize = (strlen (pl->prefix)
3075 + strlen (machine_suffix)) * 2 + 1;
3076 buffer = (char *) xrealloc (buffer, bufsize);
3077 strcpy (buffer, pl->prefix);
3078 strcat (buffer, machine_suffix);
3079 if (is_directory (buffer, multilib_dir, 1))
3081 do_spec_1 ("-L", 0, NULL_PTR);
3082 #ifdef SPACE_AFTER_L_OPTION
3083 do_spec_1 (" ", 0, NULL_PTR);
3085 do_spec_1 (buffer, 1, NULL_PTR);
3086 do_spec_1 (multilib_dir, 1, NULL_PTR);
3087 /* Make this a separate argument. */
3088 do_spec_1 (" ", 0, NULL_PTR);
3091 if (!pl->require_machine_suffix)
3093 if (is_directory (pl->prefix, multilib_dir, 1))
3095 do_spec_1 ("-L", 0, NULL_PTR);
3096 #ifdef SPACE_AFTER_L_OPTION
3097 do_spec_1 (" ", 0, NULL_PTR);
3099 do_spec_1 (pl->prefix, 1, NULL_PTR);
3100 do_spec_1 (multilib_dir, 1, NULL_PTR);
3101 /* Make this a separate argument. */
3102 do_spec_1 (" ", 0, NULL_PTR);
3108 if (is_directory (pl->prefix, machine_suffix, 1))
3110 do_spec_1 ("-L", 0, NULL_PTR);
3111 #ifdef SPACE_AFTER_L_OPTION
3112 do_spec_1 (" ", 0, NULL_PTR);
3114 do_spec_1 (pl->prefix, 1, NULL_PTR);
3115 /* Remove slash from machine_suffix. */
3116 if (strlen (machine_suffix) >= bufsize)
3117 bufsize = strlen (machine_suffix) * 2 + 1;
3118 buffer = (char *) xrealloc (buffer, bufsize);
3119 strcpy (buffer, machine_suffix);
3120 idx = strlen (buffer);
3121 if (buffer[idx - 1] == '/'
3122 || buffer[idx - 1] == DIR_SEPARATOR)
3123 buffer[idx - 1] = 0;
3124 do_spec_1 (buffer, 1, NULL_PTR);
3125 /* Make this a separate argument. */
3126 do_spec_1 (" ", 0, NULL_PTR);
3129 if (!pl->require_machine_suffix)
3131 if (is_directory (pl->prefix, "", 1))
3133 do_spec_1 ("-L", 0, NULL_PTR);
3134 #ifdef SPACE_AFTER_L_OPTION
3135 do_spec_1 (" ", 0, NULL_PTR);
3137 /* Remove slash from pl->prefix. */
3138 if (strlen (pl->prefix) >= bufsize)
3139 bufsize = strlen (pl->prefix) * 2 + 1;
3140 buffer = (char *) xrealloc (buffer, bufsize);
3141 strcpy (buffer, pl->prefix);
3142 idx = strlen (buffer);
3143 if (buffer[idx - 1] == '/'
3144 || buffer[idx - 1] == DIR_SEPARATOR)
3145 buffer[idx - 1] = 0;
3146 do_spec_1 (buffer, 1, NULL_PTR);
3147 /* Make this a separate argument. */
3148 do_spec_1 (" ", 0, NULL_PTR);
3157 /* {...:%efoo} means report an error with `foo' as error message
3158 and don't execute any more commands for this file. */
3162 while (*p != 0 && *p != '\n') p++;
3163 buf = (char *) alloca (p - q + 1);
3164 strncpy (buf, q, p - q);
3174 if (save_temps_flag)
3176 obstack_grow (&obstack, input_basename, basename_length);
3177 delete_this_arg = 0;
3181 #ifdef MKTEMP_EACH_FILE
3182 /* ??? This has a problem: the total number of
3183 values mktemp can return is limited.
3184 That matters for the names of object files.
3185 In 2.4, do something about that. */
3186 struct temp_name *t;
3188 while (*p == '.' || isalpha (*p)
3189 || (p[0] == '%' && p[1] == 'O'))
3192 /* See if we already have an association of %g/%u/%U and
3194 for (t = temp_names; t; t = t->next)
3195 if (t->length == p - suffix
3196 && strncmp (t->suffix, suffix, p - suffix) == 0
3197 && t->unique == (c != 'g'))
3200 /* Make a new association if needed. %u requires one. */
3201 if (t == 0 || c == 'u')
3205 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3206 t->next = temp_names;
3209 t->length = p - suffix;
3210 t->suffix = save_string (suffix, p - suffix);
3211 t->unique = (c != 'g');
3212 temp_filename = choose_temp_base ();
3213 temp_filename_length = strlen (temp_filename);
3214 t->filename = temp_filename;
3215 t->filename_length = temp_filename_length;
3218 obstack_grow (&obstack, t->filename, t->filename_length);
3219 delete_this_arg = 1;
3221 obstack_grow (&obstack, temp_filename, temp_filename_length);
3222 if (c == 'u' || c == 'U')
3228 sprintf (buff, "%d", unique);
3229 obstack_grow (&obstack, buff, strlen (buff));
3232 delete_this_arg = 1;
3238 obstack_grow (&obstack, input_filename, input_filename_length);
3244 struct prefix_list *pl = include_prefixes.plist;
3246 if (gcc_exec_prefix)
3248 do_spec_1 ("-iprefix", 1, NULL_PTR);
3249 /* Make this a separate argument. */
3250 do_spec_1 (" ", 0, NULL_PTR);
3251 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3252 do_spec_1 (" ", 0, NULL_PTR);
3255 for (; pl; pl = pl->next)
3257 do_spec_1 ("-isystem", 1, NULL_PTR);
3258 /* Make this a separate argument. */
3259 do_spec_1 (" ", 0, NULL_PTR);
3260 do_spec_1 (pl->prefix, 1, NULL_PTR);
3261 do_spec_1 (" ", 0, NULL_PTR);
3267 for (i = 0; i < n_infiles; i++)
3268 store_arg (outfiles[i], 0, 0);
3272 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3277 this_is_library_file = 1;
3281 this_is_output_file = 1;
3286 int cur_index = argbuf_index;
3287 /* Handle the {...} following the %W. */
3290 p = handle_braces (p + 1);
3293 /* If any args were output, mark the last one for deletion
3295 if (argbuf_index != cur_index)
3296 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3300 /* %x{OPTION} records OPTION for %X to output. */
3306 /* Skip past the option value and make a copy. */
3311 string = save_string (p1 + 1, p - p1 - 2);
3313 /* See if we already recorded this option. */
3314 for (i = 0; i < n_linker_options; i++)
3315 if (! strcmp (string, linker_options[i]))
3321 /* This option is new; add it. */
3323 if (!linker_options)
3325 = (char **) xmalloc (n_linker_options * sizeof (char **));
3328 = (char **) xrealloc (linker_options,
3329 n_linker_options * sizeof (char **));
3331 linker_options[n_linker_options - 1] = string;
3335 /* Dump out the options accumulated previously using %x. */
3337 for (i = 0; i < n_linker_options; i++)
3339 do_spec_1 (linker_options[i], 1, NULL_PTR);
3340 /* Make each accumulated option a separate argument. */
3341 do_spec_1 (" ", 0, NULL_PTR);
3345 /* Dump out the options accumulated previously using -Wa,. */
3347 for (i = 0; i < n_assembler_options; i++)
3349 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3350 /* Make each accumulated option a separate argument. */
3351 do_spec_1 (" ", 0, NULL_PTR);
3355 /* Dump out the options accumulated previously using -Wp,. */
3357 for (i = 0; i < n_preprocessor_options; i++)
3359 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3360 /* Make each accumulated option a separate argument. */
3361 do_spec_1 (" ", 0, NULL_PTR);
3365 /* Here are digits and numbers that just process
3366 a certain constant string as a spec. */
3369 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3375 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3381 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3387 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3393 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3399 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3405 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3411 value = do_spec_1 (link_spec, 0, NULL_PTR);
3417 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3423 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3430 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3434 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3438 if (! strncmp (y, "-D", 2))
3439 /* Copy the whole option. */
3440 while (*y && *y != ' ' && *y != '\t')
3442 else if (*y == ' ' || *y == '\t')
3443 /* Copy whitespace to the result. */
3445 /* Don't copy other options. */
3452 value = do_spec_1 (buf, 0, NULL_PTR);
3460 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3464 /* Copy all of CPP_PREDEFINES into BUF,
3465 but put __ after every -D and at the end of each arg. */
3469 if (! strncmp (y, "-D", 2))
3477 || (*(y+1) != '_' && ! isupper (*(y+1))))
3479 /* Stick __ at front of macro name. */
3482 /* Arrange to stick __ at the end as well. */
3486 /* Copy the macro name. */
3487 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3496 /* Copy the value given, if any. */
3497 while (*y && *y != ' ' && *y != '\t')
3500 else if (*y == ' ' || *y == '\t')
3501 /* Copy whitespace to the result. */
3503 /* Don't copy -A options */
3509 /* Copy all of CPP_PREDEFINES into BUF,
3510 but put __ after every -D. */
3514 if (! strncmp (y, "-D", 2))
3519 || (*(y+1) != '_' && ! isupper (*(y+1))))
3521 /* Stick -D__ at front of macro name. */
3527 /* Copy the macro name. */
3528 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3531 /* Copy the value given, if any. */
3532 while (*y && *y != ' ' && *y != '\t')
3537 /* Do not copy this macro - we have just done it before */
3538 while (*y && *y != ' ' && *y != '\t')
3542 else if (*y == ' ' || *y == '\t')
3543 /* Copy whitespace to the result. */
3545 /* Don't copy -A options */
3551 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3555 if (! strncmp (y, "-A", 2))
3556 /* Copy the whole option. */
3557 while (*y && *y != ' ' && *y != '\t')
3559 else if (*y == ' ' || *y == '\t')
3560 /* Copy whitespace to the result. */
3562 /* Don't copy other options. */
3569 value = do_spec_1 (buf, 0, NULL_PTR);
3576 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3581 /* Here we define characters other than letters and digits. */
3584 p = handle_braces (p);
3590 obstack_1grow (&obstack, '%');
3594 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3595 do_spec_1 (" ", 0, NULL_PTR);
3598 /* Process a string found as the value of a spec given by name.
3599 This feature allows individual machine descriptions
3600 to add and use their own specs.
3601 %[...] modifies -D options the way %P does;
3602 %(...) uses the spec unmodified. */
3607 struct spec_list *sl;
3610 /* The string after the S/P is the name of a spec that is to be
3612 while (*p && *p != ')' && *p != ']')
3615 /* See if it's in the list */
3616 for (len = p - name, sl = specs; sl; sl = sl->next)
3617 if (sl->name_len == len && !strncmp (sl->name, name, len))
3619 name = *(sl->ptr_spec);
3627 value = do_spec_1 (name, 0, NULL_PTR);
3633 char *x = (char *) alloca (strlen (name) * 2 + 1);
3637 /* Copy all of NAME into BUF, but put __ after
3638 every -D and at the end of each arg, */
3643 if (! strncmp (y, "-D", 2))
3653 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
3654 || *y == '}' || *y == 0))
3667 value = do_spec_1 (buf, 0, NULL_PTR);
3673 /* Discard the closing paren or bracket. */
3681 int c1 = *p++; /* Select first or second version number. */
3682 char *v = compiler_version;
3685 /* The format of the version string is
3686 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3688 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3689 while (! isdigit (*v))
3691 if (v > compiler_version && v[-1] != '-')
3694 /* If desired, advance to second version number. */
3697 /* Set V after the first period. */
3698 while (isdigit (*v))
3705 /* Set Q at the next period or at the end. */
3707 while (isdigit (*q))
3709 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3712 /* Put that part into the command. */
3713 obstack_grow (&obstack, v, q - v);
3719 if (input_from_pipe)
3720 do_spec_1 ("-", 0, NULL_PTR);
3729 /* Backslash: treat next character as ordinary. */
3734 /* Ordinary character: put it into the current argument. */
3735 obstack_1grow (&obstack, c);
3739 return 0; /* End of string */
3742 /* Return 0 if we call do_spec_1 and that returns -1. */
3753 int include_blanks = 1;
3756 /* A '^' after the open-brace means to not give blanks before args. */
3757 include_blanks = 0, ++p;
3760 /* A `|' after the open-brace means,
3761 if the test fails, output a single minus sign rather than nothing.
3762 This is used in %{|!pipe:...}. */
3766 /* A `!' after the open-brace negates the condition:
3767 succeed if the specified switch is not present. */
3771 /* A `.' after the open-brace means test against the current suffix. */
3781 while (*p != ':' && *p != '}') p++;
3784 register int count = 1;
3802 int found = (input_suffix != 0
3803 && strlen (input_suffix) == p - filter
3804 && strncmp (input_suffix, filter, p - filter) == 0);
3810 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3815 else if (p[-1] == '*' && p[0] == '}')
3817 /* Substitute all matching switches as separate args. */
3820 for (i = 0; i < n_switches; i++)
3821 if (!strncmp (switches[i].part1, filter, p - filter)
3822 && check_live_switch (i, p - filter))
3823 give_switch (i, 0, include_blanks);
3827 /* Test for presence of the specified switch. */
3831 /* If name specified ends in *, as in {x*:...},
3832 check for %* and handle that case. */
3833 if (p[-1] == '*' && !negate)
3838 /* First see whether we have %*. */
3842 if (*r == '%' && r[1] == '*')
3846 /* If we do, handle that case. */
3849 /* Substitute all matching switches as separate args.
3850 But do this by substituting for %*
3851 in the text that follows the colon. */
3853 unsigned hard_match_len = p - filter - 1;
3854 char *string = save_string (p + 1, q - p - 2);
3856 for (i = 0; i < n_switches; i++)
3857 if (!strncmp (switches[i].part1, filter, hard_match_len)
3858 && check_live_switch (i, -1))
3860 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
3861 /* Pass any arguments this switch has. */
3862 give_switch (i, 1, 1);
3869 /* If name specified ends in *, as in {x*:...},
3870 check for presence of any switch name starting with x. */
3873 for (i = 0; i < n_switches; i++)
3875 unsigned hard_match_len = p - filter - 1;
3877 if (!strncmp (switches[i].part1, filter, hard_match_len)
3878 && check_live_switch (i, hard_match_len))
3884 /* Otherwise, check for presence of exact name specified. */
3887 for (i = 0; i < n_switches; i++)
3889 if (!strncmp (switches[i].part1, filter, p - filter)
3890 && switches[i].part1[p - filter] == 0
3891 && check_live_switch (i, -1))
3899 /* If it is as desired (present for %{s...}, absent for %{-s...})
3900 then substitute either the switch or the specified
3901 conditional text. */
3902 if (present != negate)
3906 give_switch (i, 0, include_blanks);
3910 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3916 /* Here if a %{|...} conditional fails: output a minus sign,
3917 which means "standard output" or "standard input". */
3918 do_spec_1 ("-", 0, NULL_PTR);
3925 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3926 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3927 spec, or -1 if either exact match or %* is used.
3929 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3930 whose value does not begin with "no-" is obsoleted by the same value
3931 with the "no-", similarly for a switch with the "no-" prefix. */
3934 check_live_switch (switchnum, prefix_length)
3938 char *name = switches[switchnum].part1;
3941 /* In the common case of {<at-most-one-letter>*}, a negating
3942 switch would always match, so ignore that case. We will just
3943 send the conflicting switches to the compiler phase. */
3944 if (prefix_length >= 0 && prefix_length <= 1)
3947 /* If we already processed this switch and determined if it was
3948 live or not, return our past determination. */
3949 if (switches[switchnum].live_cond != 0)
3950 return switches[switchnum].live_cond > 0;
3952 /* Now search for duplicate in a manner that depends on the name. */
3956 for (i = switchnum + 1; i < n_switches; i++)
3957 if (switches[i].part1[0] == 'O')
3959 switches[switchnum].valid = 1;
3960 switches[switchnum].live_cond = -1;
3965 case 'W': case 'f': case 'm':
3966 if (! strncmp (name + 1, "no-", 3))
3968 /* We have Xno-YYY, search for XYYY. */
3969 for (i = switchnum + 1; i < n_switches; i++)
3970 if (switches[i].part1[0] == name[0]
3971 && ! strcmp (&switches[i].part1[1], &name[4]))
3973 switches[switchnum].valid = 1;
3974 switches[switchnum].live_cond = -1;
3980 /* We have XYYY, search for Xno-YYY. */
3981 for (i = switchnum + 1; i < n_switches; i++)
3982 if (switches[i].part1[0] == name[0]
3983 && switches[i].part1[1] == 'n'
3984 && switches[i].part1[2] == 'o'
3985 && switches[i].part1[3] == '-'
3986 && !strcmp (&switches[i].part1[4], &name[1]))
3988 switches[switchnum].valid = 1;
3989 switches[switchnum].live_cond = -1;
3996 /* Otherwise the switch is live. */
3997 switches[switchnum].live_cond = 1;
4001 /* Pass a switch to the current accumulating command
4002 in the same form that we received it.
4003 SWITCHNUM identifies the switch; it is an index into
4004 the vector of switches gcc received, which is `switches'.
4005 This cannot fail since it never finishes a command line.
4007 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4009 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4013 give_switch (switchnum, omit_first_word, include_blanks)
4015 int omit_first_word;
4018 if (!omit_first_word)
4020 do_spec_1 ("-", 0, NULL_PTR);
4021 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4024 if (switches[switchnum].args != 0)
4027 for (p = switches[switchnum].args; *p; p++)
4030 do_spec_1 (" ", 0, NULL_PTR);
4031 do_spec_1 (*p, 1, NULL_PTR);
4035 do_spec_1 (" ", 0, NULL_PTR);
4036 switches[switchnum].valid = 1;
4039 /* Search for a file named NAME trying various prefixes including the
4040 user's -B prefix and some standard ones.
4041 Return the absolute file name found. If nothing is found, return NAME. */
4049 /* Try multilib_dir if it is defined. */
4050 if (multilib_dir != NULL)
4054 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4055 strcpy (try, multilib_dir);
4056 strcat (try, dir_separator_str);
4059 newname = find_a_file (&startfile_prefixes, try, R_OK);
4061 /* If we don't find it in the multi library dir, then fall
4062 through and look for it in the normal places. */
4063 if (newname != NULL)
4067 newname = find_a_file (&startfile_prefixes, name, R_OK);
4068 return newname ? newname : name;
4071 /* Determine whether a directory exists. If LINKER, return 0 for
4072 certain fixed names not needed by the linker. If not LINKER, it is
4073 only important to return 0 if the host machine has a small ARG_MAX
4077 is_directory (path1, path2, linker)
4082 int len1 = strlen (path1);
4083 int len2 = strlen (path2);
4084 char *path = (char *) alloca (3 + len1 + len2);
4088 #ifndef SMALL_ARG_MAX
4093 /* Construct the path from the two parts. Ensure the string ends with "/.".
4094 The resulting path will be a directory even if the given path is a
4096 bcopy (path1, path, len1);
4097 bcopy (path2, path + len1, len2);
4098 cp = path + len1 + len2;
4099 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4100 *cp++ = DIR_SEPARATOR;
4104 /* Exclude directories that the linker is known to search. */
4107 && strcmp (path, concat (dir_separator_str, "lib",
4108 dir_separator_str, ".", NULL_PTR)) == 0)
4110 && strcmp (path, concat (dir_separator_str, "usr",
4111 dir_separator_str, "lib",
4112 dir_separator_str, ".", NULL_PTR)) == 0)))
4115 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4118 /* On fatal signals, delete all the temporary files. */
4121 fatal_error (signum)
4124 signal (signum, SIG_DFL);
4125 delete_failure_queue ();
4126 delete_temp_files ();
4127 /* Get the same signal again, this time not handled,
4128 so its normal effect occurs. */
4129 kill (getpid (), signum);
4140 int linker_was_run = 0;
4141 char *explicit_link_files;
4144 struct user_specs *uptr;
4146 p = argv[0] + strlen (argv[0]);
4147 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4150 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4151 signal (SIGINT, fatal_error);
4153 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4154 signal (SIGHUP, fatal_error);
4156 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4157 signal (SIGTERM, fatal_error);
4159 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4160 signal (SIGPIPE, fatal_error);
4164 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4166 obstack_init (&obstack);
4168 /* Build multilib_select, et. al from the separate lines that make up each
4169 multilib selection. */
4171 char **q = multilib_raw;
4174 obstack_init (&multilib_obstack);
4175 while ((p = *q++) != (char *) 0)
4176 obstack_grow (&multilib_obstack, p, strlen (p));
4178 obstack_1grow (&multilib_obstack, 0);
4179 multilib_select = obstack_finish (&multilib_obstack);
4181 q = multilib_matches_raw;
4182 while ((p = *q++) != (char *) 0)
4183 obstack_grow (&multilib_obstack, p, strlen (p));
4185 obstack_1grow (&multilib_obstack, 0);
4186 multilib_matches = obstack_finish (&multilib_obstack);
4190 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4194 obstack_1grow (&multilib_obstack, ' ');
4195 obstack_grow (&multilib_obstack,
4196 multilib_defaults_raw[i],
4197 strlen (multilib_defaults_raw[i]));
4201 obstack_1grow (&multilib_obstack, 0);
4202 multilib_defaults = obstack_finish (&multilib_obstack);
4205 /* Set up to remember the pathname of gcc and any options
4206 needed for collect. We use argv[0] instead of programname because
4207 we need the complete pathname. */
4208 obstack_init (&collect_obstack);
4209 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4210 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4211 putenv (obstack_finish (&collect_obstack));
4213 #ifdef INIT_ENVIRONMENT
4214 /* Set up any other necessary machine specific environment variables. */
4215 putenv (INIT_ENVIRONMENT);
4218 /* Choose directory for temp files. */
4220 temp_filename = choose_temp_base ();
4221 temp_filename_length = strlen (temp_filename);
4223 /* Make a table of what switches there are (switches, n_switches).
4224 Make a table of specified input files (infiles, n_infiles).
4225 Decode switches that are handled locally. */
4227 process_command (argc, argv);
4229 /* Initialize the vector of specs to just the default.
4230 This means one element containing 0s, as a terminator. */
4232 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4233 bcopy ((char *) default_compilers, (char *) compilers,
4234 sizeof default_compilers);
4235 n_compilers = n_default_compilers;
4237 /* Read specs from a file if there is one. */
4239 machine_suffix = concat (spec_machine, dir_separator_str,
4240 spec_version, dir_separator_str, NULL_PTR);
4241 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4243 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4244 /* Read the specs file unless it is a default one. */
4245 if (specs_file != 0 && strcmp (specs_file, "specs"))
4248 read_specs (specs_file);
4253 /* Process any user specified specs in the order given on the command
4255 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4257 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4258 read_specs (filename ? filename : uptr->filename);
4261 /* If not cross-compiling, look for startfiles in the standard places. */
4262 /* The fact that these are done here, after reading the specs file,
4263 means that it cannot be found in these directories.
4264 But that's okay. It should never be there anyway. */
4265 if (*cross_compile == '0')
4267 #ifdef MD_EXEC_PREFIX
4268 add_prefix (&exec_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4269 add_prefix (&startfile_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4272 #ifdef MD_STARTFILE_PREFIX
4273 add_prefix (&startfile_prefixes, md_startfile_prefix, 0, 0, NULL_PTR);
4276 #ifdef MD_STARTFILE_PREFIX_1
4277 add_prefix (&startfile_prefixes, md_startfile_prefix_1, 0, 0, NULL_PTR);
4280 /* If standard_startfile_prefix is relative, base it on
4281 standard_exec_prefix. This lets us move the installed tree
4282 as a unit. If GCC_EXEC_PREFIX is defined, base
4283 standard_startfile_prefix on that as well. */
4284 if (*standard_startfile_prefix == '/'
4285 || *standard_startfile_prefix == DIR_SEPARATOR)
4286 add_prefix (&startfile_prefixes, standard_startfile_prefix, 0, 0,
4290 if (gcc_exec_prefix)
4291 add_prefix (&startfile_prefixes,
4292 concat (gcc_exec_prefix, machine_suffix,
4293 standard_startfile_prefix, NULL_PTR),
4295 add_prefix (&startfile_prefixes,
4296 concat (standard_exec_prefix,
4298 standard_startfile_prefix, NULL_PTR),
4302 add_prefix (&startfile_prefixes, standard_startfile_prefix_1, 0, 0,
4304 add_prefix (&startfile_prefixes, standard_startfile_prefix_2, 0, 0,
4306 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4307 add_prefix (&startfile_prefixes, "./", 0, 1, NULL_PTR);
4312 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4313 add_prefix (&startfile_prefixes,
4314 concat (gcc_exec_prefix, machine_suffix,
4315 standard_startfile_prefix, NULL_PTR),
4319 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4320 if (gcc_exec_prefix)
4322 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4323 + strlen (spec_version)
4324 + strlen (spec_machine) + 3);
4325 strcpy (temp, gcc_exec_prefix);
4326 strcat (temp, spec_machine);
4327 strcat (temp, dir_separator_str);
4328 strcat (temp, spec_version);
4329 strcat (temp, dir_separator_str);
4330 gcc_exec_prefix = temp;
4333 /* Now we have the specs.
4334 Set the `valid' bits for switches that match anything in any spec. */
4336 validate_all_switches ();
4338 /* Now that we have the switches and the specs, set
4339 the subdirectory based on the options. */
4340 set_multilib_dir ();
4342 /* Warn about any switches that no pass was interested in. */
4344 for (i = 0; i < n_switches; i++)
4345 if (! switches[i].valid)
4346 error ("unrecognized option `-%s'", switches[i].part1);
4348 /* Obey some of the options. */
4350 if (print_search_dirs)
4352 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4353 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4354 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4358 if (print_file_name)
4360 printf ("%s\n", find_file (print_file_name));
4364 if (print_prog_name)
4366 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4367 printf ("%s\n", (newname ? newname : print_prog_name));
4371 if (print_multi_lib)
4373 print_multilib_info ();
4377 if (print_multi_directory)
4379 if (multilib_dir == NULL)
4382 printf ("%s\n", multilib_dir);
4388 if (! strcmp (version_string, compiler_version))
4389 fprintf (stderr, "gcc version %s\n", version_string);
4391 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4392 version_string, compiler_version);
4399 fatal ("No input files");
4401 /* Make a place to record the compiler output file names
4402 that correspond to the input files. */
4404 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4405 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4407 /* Record which files were specified explicitly as link input. */
4409 explicit_link_files = xmalloc (n_infiles);
4410 bzero (explicit_link_files, n_infiles);
4412 for (i = 0; i < n_infiles; i++)
4414 register struct compiler *cp = 0;
4415 int this_file_error = 0;
4417 /* Tell do_spec what to substitute for %i. */
4419 input_filename = infiles[i].name;
4420 input_filename_length = strlen (input_filename);
4421 input_file_number = i;
4423 /* Use the same thing in %o, unless cp->spec says otherwise. */
4425 outfiles[i] = input_filename;
4427 /* Figure out which compiler from the file's suffix. */
4429 cp = lookup_compiler (infiles[i].name, input_filename_length,
4430 infiles[i].language);
4434 /* Ok, we found an applicable compiler. Run its spec. */
4435 /* First say how much of input_filename to substitute for %b */
4439 if (cp->spec[0][0] == '#')
4440 error ("%s: %s compiler not installed on this system",
4441 input_filename, &cp->spec[0][1]);
4443 input_basename = input_filename;
4444 for (p = input_filename; *p; p++)
4445 if (*p == '/' || *p == DIR_SEPARATOR)
4446 input_basename = p + 1;
4448 /* Find a suffix starting with the last period,
4449 and set basename_length to exclude that suffix. */
4450 basename_length = strlen (input_basename);
4451 p = input_basename + basename_length;
4452 while (p != input_basename && *p != '.') --p;
4453 if (*p == '.' && p != input_basename)
4455 basename_length = p - input_basename;
4456 input_suffix = p + 1;
4462 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4464 len += strlen (cp->spec[j]);
4466 p = (char *) xmalloc (len + 1);
4469 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4472 strcpy (p + len, cp->spec[j]);
4473 len += strlen (cp->spec[j]);
4476 value = do_spec (p);
4479 this_file_error = 1;
4482 /* If this file's name does not contain a recognized suffix,
4483 record it as explicit linker input. */
4486 explicit_link_files[i] = 1;
4488 /* Clear the delete-on-failure queue, deleting the files in it
4489 if this compilation failed. */
4491 if (this_file_error)
4493 delete_failure_queue ();
4496 /* If this compilation succeeded, don't delete those files later. */
4497 clear_failure_queue ();
4500 /* Run ld to link all the compiler output files. */
4502 if (error_count == 0)
4504 int tmp = execution_count;
4508 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4510 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4511 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4513 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4515 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4516 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4519 for (i = 0; i < n_switches; i++)
4523 obstack_grow (&collect_obstack, " ", 1);
4526 obstack_grow (&collect_obstack, "-", 1);
4527 obstack_grow (&collect_obstack, switches[i].part1,
4528 strlen (switches[i].part1));
4530 for (args = switches[i].args; args && *args; args++)
4532 obstack_grow (&collect_obstack, " ", 1);
4533 obstack_grow (&collect_obstack, *args, strlen (*args));
4536 obstack_grow (&collect_obstack, "\0", 1);
4537 putenv (obstack_finish (&collect_obstack));
4539 value = do_spec (link_command_spec);
4542 linker_was_run = (tmp != execution_count);
4545 /* Warn if a -B option was specified but the prefix was never used. */
4546 unused_prefix_warnings (&exec_prefixes);
4547 unused_prefix_warnings (&startfile_prefixes);
4549 /* If options said don't run linker,
4550 complain about input files to be given to the linker. */
4552 if (! linker_was_run && error_count == 0)
4553 for (i = 0; i < n_infiles; i++)
4554 if (explicit_link_files[i])
4555 error ("%s: linker input file unused since linking not done",
4558 /* Delete some or all of the temporary files we made. */
4561 delete_failure_queue ();
4562 delete_temp_files ();
4564 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4569 /* Find the proper compilation spec for the file name NAME,
4570 whose length is LENGTH. LANGUAGE is the specified language,
4571 or 0 if none specified. */
4573 static struct compiler *
4574 lookup_compiler (name, length, language)
4579 struct compiler *cp;
4581 /* Look for the language, if one is spec'd. */
4584 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4588 if (cp->suffix[0] == '@'
4589 && !strcmp (cp->suffix + 1, language))
4593 error ("language %s not recognized", language);
4596 /* Look for a suffix. */
4597 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4599 if (/* The suffix `-' matches only the file name `-'. */
4600 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4602 (strlen (cp->suffix) < length
4603 /* See if the suffix matches the end of NAME. */
4605 && (!strcmp (cp->suffix,
4606 name + length - strlen (cp->suffix))
4607 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4608 && !strcasecmp (cp->suffix,
4609 name + length - strlen (cp->suffix)))))
4611 && !strcmp (cp->suffix,
4612 name + length - strlen (cp->suffix))))
4615 if (cp->spec[0][0] == '@')
4617 struct compiler *new;
4618 /* An alias entry maps a suffix to a language.
4619 Search for the language; pass 0 for NAME and LENGTH
4620 to avoid infinite recursion if language not found.
4621 Construct the new compiler spec. */
4622 language = cp->spec[0] + 1;
4623 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4624 new->suffix = cp->suffix;
4625 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4626 (char *) new->spec, sizeof new->spec);
4629 /* A non-alias entry: return it. */
4641 register char *value = (char *) malloc (size);
4643 fatal ("virtual memory exhausted");
4648 xrealloc (ptr, size)
4652 register char *value = (char *) realloc (ptr, size);
4654 fatal ("virtual memory exhausted");
4658 /* This function is based on the one in libiberty. */
4661 concat VPROTO((char *first, ...))
4663 register int length;
4664 register char *newstr;
4672 /* First compute the size of the result and get sufficient memory. */
4674 VA_START (args, first);
4676 first = va_arg (args, char *);
4684 length += strlen (arg);
4685 arg = va_arg (args, char *);
4688 newstr = (char *) xmalloc (length + 1);
4691 /* Now copy the individual pieces to the result string. */
4693 VA_START (args, first);
4695 first = va_arg (args, char *);
4704 arg = va_arg (args, char *);
4713 save_string (s, len)
4717 register char *result = xmalloc (len + 1);
4719 bcopy (s, result, len);
4725 pfatal_with_name (name)
4728 fatal ("%s: %s", name, my_strerror (errno));
4732 perror_with_name (name)
4735 error ("%s: %s", name, my_strerror (errno));
4739 pfatal_pexecute (errmsg_fmt, errmsg_arg)
4745 /* Space for trailing '\0' is in %s. */
4746 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
4747 sprintf (msg, errmsg_fmt, errmsg_arg);
4751 fatal ("%s: %s", errmsg_fmt, my_strerror (errno));
4754 /* More 'friendly' abort that prints the line and file.
4755 config.h can #define abort fancy_abort if you like that sort of thing. */
4760 fatal ("Internal gcc abort.");
4765 /* Output an error message and exit */
4768 fatal VPROTO((char *format, ...))
4775 VA_START (ap, format);
4778 format = va_arg (ap, char *);
4781 fprintf (stderr, "%s: ", programname);
4782 vfprintf (stderr, format, ap);
4784 fprintf (stderr, "\n");
4785 delete_temp_files ();
4790 error VPROTO((char *format, ...))
4797 VA_START (ap, format);
4800 format = va_arg (ap, char *);
4803 fprintf (stderr, "%s: ", programname);
4804 vfprintf (stderr, format, ap);
4807 fprintf (stderr, "\n");
4810 #else /* not HAVE_VPRINTF */
4813 fatal (msg, arg1, arg2)
4814 char *msg, *arg1, *arg2;
4816 error (msg, arg1, arg2);
4817 delete_temp_files ();
4822 error (msg, arg1, arg2)
4823 char *msg, *arg1, *arg2;
4825 fprintf (stderr, "%s: ", programname);
4826 fprintf (stderr, msg, arg1, arg2);
4827 fprintf (stderr, "\n");
4830 #endif /* not HAVE_VPRINTF */
4834 validate_all_switches ()
4836 struct compiler *comp;
4839 struct spec_list *spec;
4841 for (comp = compilers; comp->spec[0]; comp++)
4844 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
4848 if (c == '%' && *p == '{')
4849 /* We have a switch spec. */
4850 validate_switches (p + 1);
4854 /* look through the linked list of specs read from the specs file */
4855 for (spec = specs; spec ; spec = spec->next)
4857 p = *(spec->ptr_spec);
4859 if (c == '%' && *p == '{')
4860 /* We have a switch spec. */
4861 validate_switches (p + 1);
4864 p = link_command_spec;
4866 if (c == '%' && *p == '{')
4867 /* We have a switch spec. */
4868 validate_switches (p + 1);
4871 /* Look at the switch-name that comes after START
4872 and mark as valid all supplied switches that match it. */
4875 validate_switches (start)
4878 register char *p = start;
4893 while (*p != ':' && *p != '}') p++;
4897 else if (p[-1] == '*')
4899 /* Mark all matching switches as valid. */
4901 for (i = 0; i < n_switches; i++)
4902 if (!strncmp (switches[i].part1, filter, p - filter))
4903 switches[i].valid = 1;
4907 /* Mark an exact matching switch as valid. */
4908 for (i = 0; i < n_switches; i++)
4910 if (!strncmp (switches[i].part1, filter, p - filter)
4911 && switches[i].part1[p - filter] == 0)
4912 switches[i].valid = 1;
4917 /* Check whether a particular argument was used. The first time we
4918 canonialize the switches to keep only the ones we care about. */
4932 static struct mswitchstr *mswitches;
4933 static int n_mswitches;
4938 struct mswitchstr *matches;
4942 /* Break multilib_matches into the component strings of string and replacement
4944 for (q = multilib_matches; *q != '\0'; q++)
4948 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
4950 q = multilib_matches;
4961 matches[i].len = q - matches[i].str;
4963 matches[i].replace = ++q;
4964 while (*q != ';' && *q != '\0')
4970 matches[i].rep_len = q - matches[i].replace;
4978 /* Now build a list of the replacement string for switches that we care
4979 about. Make sure we allocate at least one entry. This prevents
4980 xmalloc from calling fatal, and prevents us from re-executing this
4983 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
4984 * (n_switches ? n_switches : 1));
4985 for (i = 0; i < n_switches; i++)
4987 int xlen = strlen (switches[i].part1);
4988 for (j = 0; j < cnt; j++)
4989 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
4991 mswitches[n_mswitches].str = matches[j].replace;
4992 mswitches[n_mswitches].len = matches[j].rep_len;
4993 mswitches[n_mswitches].replace = (char *)0;
4994 mswitches[n_mswitches].rep_len = 0;
5001 for (i = 0; i < n_mswitches; i++)
5002 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5009 default_arg (p, len)
5016 for (start = multilib_defaults; *start != '\0'; start = end+1)
5018 while (*start == ' ' || *start == '\t')
5024 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5027 if ((end - start) == len && strncmp (p, start, len) == 0)
5034 /* Work out the subdirectory to use based on the
5035 options. The format of multilib_select is a list of elements.
5036 Each element is a subdirectory name followed by a list of options
5037 followed by a semicolon. gcc will consider each line in turn. If
5038 none of the options beginning with an exclamation point are
5039 present, and all of the other options are present, that
5040 subdirectory will be used. */
5045 char *p = multilib_select;
5047 char *this_path, *this_arg;
5053 /* Ignore newlines. */
5060 /* Get the initial path. */
5068 this_path_len = p - this_path;
5070 /* Check the arguments. */
5085 while (*p != ' ' && *p != ';')
5092 if (*this_arg != '!')
5100 /* If this is a default argument, we can just ignore it.
5101 This is true even if this_arg begins with '!'. Beginning
5102 with '!' does not mean that this argument is necessarily
5103 inappropriate for this library: it merely means that
5104 there is a more specific library which uses this
5105 argument. If this argument is a default, we need not
5106 consider that more specific library. */
5107 if (! default_arg (this_arg, p - this_arg))
5109 ok = used_arg (this_arg, p - this_arg);
5120 if (this_path_len != 1
5121 || this_path[0] != '.')
5123 multilib_dir = xmalloc (this_path_len + 1);
5124 strncpy (multilib_dir, this_path, this_path_len);
5125 multilib_dir[this_path_len] = '\0';
5134 /* Print out the multiple library subdirectory selection
5135 information. This prints out a series of lines. Each line looks
5136 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5137 required. Only the desired options are printed out, the negative
5138 matches. The options are print without a leading dash. There are
5139 no spaces to make it easy to use the information in the shell.
5140 Each subdirectory is printed only once. This assumes the ordering
5141 generated by the genmultilib script. */
5144 print_multilib_info ()
5146 char *p = multilib_select;
5147 char *last_path = 0, *this_path;
5149 int last_path_len = 0;
5153 /* Ignore newlines. */
5160 /* Get the initial path. */
5169 /* If this is a duplicate, skip it. */
5170 skip = (last_path != 0 && p - this_path == last_path_len
5171 && ! strncmp (last_path, this_path, last_path_len));
5173 last_path = this_path;
5174 last_path_len = p - this_path;
5176 /* If this directory requires any default arguments, we can skip
5177 it. We will already have printed a directory identical to
5178 this one which does not require that default argument. */
5196 while (*q != ' ' && *q != ';')
5204 && default_arg (arg, q - arg))
5219 for (p1 = last_path; p1 < p; p1++)
5238 use_arg = *p != '!';
5243 while (*p != ' ' && *p != ';')
5258 /* If there are extra options, print them now */
5259 if (multilib_extra && *multilib_extra)
5261 int print_at = TRUE;
5264 for (q = multilib_extra; *q != '\0'; q++)