1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!! */
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers. It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec". */
36 #include "gansidecl.h"
50 /* ??? Need to find a GCC header to put these in. */
51 extern int pexecute PROTO ((const char *, char * const *, const char *,
52 const char *, char **, char **, int));
53 extern int pwait PROTO ((int, int *, int));
54 extern char *update_path PROTO((char *, char *));
55 /* Flag arguments to pexecute. */
56 #define PEXECUTE_FIRST 1
57 #define PEXECUTE_LAST 2
58 #define PEXECUTE_SEARCH 4
59 #define PEXECUTE_VERBOSE 8
62 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
65 #define WTERMSIG(S) ((S) & 0x7f)
68 #define WIFEXITED(S) (((S) & 0xff) == 0)
71 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
75 #define exit __posix_exit
78 /* Define O_RDONLY if the system hasn't defined it for us. */
87 /* Test if something is a normal file. */
89 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
92 /* Test if something is a directory. */
94 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
97 /* By default there is no special suffix for executables. */
98 #ifdef EXECUTABLE_SUFFIX
99 #define HAVE_EXECUTABLE_SUFFIX
101 #define EXECUTABLE_SUFFIX ""
104 /* By default, the suffix for object files is ".o". */
106 #define HAVE_OBJECT_SUFFIX
108 #define OBJECT_SUFFIX ".o"
111 /* By default, colon separates directories in a path. */
112 #ifndef PATH_SEPARATOR
113 #define PATH_SEPARATOR ':'
116 #ifndef DIR_SEPARATOR
117 #define DIR_SEPARATOR '/'
120 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
122 #define obstack_chunk_alloc xmalloc
123 #define obstack_chunk_free free
125 extern char *choose_temp_base PROTO((void));
127 #ifndef HAVE_STRERROR
129 extern char *sys_errlist[];
131 extern char *strerror();
135 #define kill(p,s) raise(s)
138 /* If a stage of compilation returns an exit status >= 1,
139 compilation of that file ceases. */
141 #define MIN_FATAL_STATUS 1
143 /* Flag saying to print the directories gcc will search through looking for
144 programs, libraries, etc. */
146 static int print_search_dirs;
148 /* Flag saying to print the full filename of this file
149 as found through our usual search mechanism. */
151 static char *print_file_name = NULL;
153 /* As print_file_name, but search for executable file. */
155 static char *print_prog_name = NULL;
157 /* Flag saying to print the relative path we'd use to
158 find libgcc.a given the current compiler flags. */
160 static int print_multi_directory;
162 /* Flag saying to print the list of subdirectories and
163 compiler flags used to select them in a standard form. */
165 static int print_multi_lib;
167 /* Flag indicating whether we should print the command and arguments */
169 static int verbose_flag;
171 /* Nonzero means write "temp" files in source directory
172 and use the source file's name in them, and don't delete them. */
174 static int save_temps_flag;
176 /* The compiler version. */
178 static char *compiler_version;
180 /* The target version specified with -V */
182 static char *spec_version = DEFAULT_TARGET_VERSION;
184 /* The target machine specified with -b. */
186 static char *spec_machine = DEFAULT_TARGET_MACHINE;
188 /* Nonzero if cross-compiling.
189 When -b is used, the value comes from the `specs' file. */
192 static char *cross_compile = "1";
194 static char *cross_compile = "0";
197 /* The number of errors that have occurred; the link phase will not be
198 run if this is non-zero. */
199 static int error_count = 0;
201 /* This is the obstack which we use to allocate many strings. */
203 static struct obstack obstack;
205 /* This is the obstack to build an environment variable to pass to
206 collect2 that describes all of the relevant switches of what to
207 pass the compiler in building the list of pointers to constructors
210 static struct obstack collect_obstack;
212 extern char *version_string;
214 /* Forward declaration for prototypes. */
217 static void init_spec PROTO((void));
218 static void read_specs PROTO((char *, int));
219 static void set_spec PROTO((char *, char *));
220 static struct compiler *lookup_compiler PROTO((char *, int, char *));
221 static char *build_search_list PROTO((struct path_prefix *, char *, int));
222 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
223 static char *find_a_file PROTO((struct path_prefix *, char *, int));
224 static void add_prefix PROTO((struct path_prefix *, char *, char *,
226 static char *skip_whitespace PROTO((char *));
227 static void record_temp_file PROTO((char *, int, int));
228 static void delete_if_ordinary PROTO((char *));
229 static void delete_temp_files PROTO((void));
230 static void delete_failure_queue PROTO((void));
231 static void clear_failure_queue PROTO((void));
232 static int check_live_switch PROTO((int, int));
233 static char *handle_braces PROTO((char *));
234 static char *save_string PROTO((char *, int));
235 static char *concat PVPROTO((char *, ...));
236 static int do_spec PROTO((char *));
237 static int do_spec_1 PROTO((char *, int, char *));
238 static char *find_file PROTO((char *));
239 static int is_directory PROTO((char *, char *, int));
240 static void validate_switches PROTO((char *));
241 static void validate_all_switches PROTO((void));
242 static void give_switch PROTO((int, int, int));
243 static int used_arg PROTO((char *, int));
244 static int default_arg PROTO((char *, int));
245 static void set_multilib_dir PROTO((void));
246 static void print_multilib_info PROTO((void));
247 static void pfatal_with_name PROTO((char *));
248 static void perror_with_name PROTO((char *));
249 static void pfatal_pexecute PROTO((char *, char *));
251 static void fatal PVPROTO((char *, ...));
252 static void error PVPROTO((char *, ...));
254 /* We must not provide any prototype here, even if ANSI C. */
255 static void fatal PROTO(());
256 static void error PROTO(());
263 /* Specs are strings containing lines, each of which (if not blank)
264 is made up of a program name, and arguments separated by spaces.
265 The program name must be exact and start from root, since no path
266 is searched and it is unreliable to depend on the current working directory.
267 Redirection of input or output is not supported; the subprograms must
268 accept filenames saying what files to read and write.
270 In addition, the specs can contain %-sequences to substitute variable text
271 or for conditional text. Here is a table of all defined %-sequences.
272 Note that spaces are not generated automatically around the results of
273 expanding these sequences; therefore, you can concatenate them together
274 or with constant text in a single argument.
276 %% substitute one % into the program name or argument.
277 %i substitute the name of the input file being processed.
278 %b substitute the basename of the input file being processed.
279 This is the substring up to (and not including) the last period
280 and not including the directory.
281 %g substitute the temporary-file-name-base. This is a string chosen
282 once per compilation. Different temporary file names are made by
283 concatenation of constant strings on the end, as in `%g.s'.
284 %g also has the same effect of %d.
285 %u like %g, but make the temporary file name unique.
286 %U returns the last file name generated with %u.
287 %d marks the argument containing or following the %d as a
288 temporary file name, so that that file will be deleted if CC exits
289 successfully. Unlike %g, this contributes no text to the argument.
290 %w marks the argument containing or following the %w as the
291 "output file" of this compilation. This puts the argument
292 into the sequence of arguments that %o will substitute later.
294 like %{...} but mark last argument supplied within
295 as a file to be deleted on failure.
296 %o substitutes the names of all the output files, with spaces
297 automatically placed around them. You should write spaces
298 around the %o as well or the results are undefined.
299 %o is for use in the specs for running the linker.
300 Input files whose names have no recognized suffix are not compiled
301 at all, but they are included among the output files, so they will
303 %O substitutes the suffix for object files.
304 %p substitutes the standard macro predefinitions for the
305 current target machine. Use this when running cpp.
306 %P like %p, but puts `__' before and after the name of each macro.
307 (Except macros that already have __.)
309 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
310 %s current argument is the name of a library or startup file of some sort.
311 Search for that file in a standard list of directories
312 and substitute the full name found.
313 %eSTR Print STR as an error message. STR is terminated by a newline.
314 Use this when inconsistent options are detected.
315 %x{OPTION} Accumulate an option for %X.
316 %X Output the accumulated linker options specified by compilations.
317 %Y Output the accumulated assembler options specified by compilations.
318 %Z Output the accumulated preprocessor options specified by compilations.
319 %v1 Substitute the major version number of GCC.
320 (For version 2.5.n, this is 2.)
321 %v2 Substitute the minor version number of GCC.
322 (For version 2.5.n, this is 5.)
323 %a process ASM_SPEC as a spec.
324 This allows config.h to specify part of the spec for running as.
325 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
326 used here. This can be used to run a post-processor after the
327 assembler has done it's job.
328 %D Dump out a -L option for each directory in startfile_prefixes.
329 If multilib_dir is set, extra entries are generated with it affixed.
330 %l process LINK_SPEC as a spec.
331 %L process LIB_SPEC as a spec.
332 %G process LIBGCC_SPEC as a spec.
333 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
334 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
335 %c process SIGNED_CHAR_SPEC as a spec.
336 %C process CPP_SPEC as a spec. A capital C is actually used here.
337 %1 process CC1_SPEC as a spec.
338 %2 process CC1PLUS_SPEC as a spec.
339 %| output "-" if the input for the current command is coming from a pipe.
340 %* substitute the variable part of a matched option. (See below.)
341 Note that each comma in the substituted string is replaced by
343 %{S} substitutes the -S switch, if that switch was given to CC.
344 If that switch was not specified, this substitutes nothing.
345 Here S is a metasyntactic variable.
346 %{S*} substitutes all the switches specified to CC whose names start
347 with -S. This is used for -o, -D, -I, etc; switches that take
348 arguments. CC considers `-o foo' as being one switch whose
349 name starts with `o'. %{o*} would substitute this text,
350 including the space; thus, two arguments would be generated.
351 %{^S*} likewise, but don't put a blank between a switch and any args.
352 %{S*:X} substitutes X if one or more switches whose names start with -S are
353 specified to CC. Note that the tail part of the -S option
354 (i.e. the part matched by the `*') will be substituted for each
355 occurrence of %* within X.
356 %{S:X} substitutes X, but only if the -S switch was given to CC.
357 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
358 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
359 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
360 %{.S:X} substitutes X, but only if processing a file with suffix S.
361 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
362 %(Spec) processes a specification defined in a specs file as *Spec:
363 %[Spec] as above, but put __ around -D arguments
365 The conditional text X in a %{S:X} or %{!S:X} construct may contain
366 other nested % constructs or spaces, or even newlines. They are
367 processed as usual, as described above.
369 The -O, -f, -m, and -W switches are handled specifically in these
370 constructs. If another value of -O or the negated form of a -f, -m, or
371 -W switch is found later in the command line, the earlier switch
372 value is ignored, except with {S*} where S is just one letter; this
373 passes all matching options.
375 The character | is used to indicate that a command should be piped to
376 the following command, but only if -pipe is specified.
378 Note that it is built into CC which switches take arguments and which
379 do not. You might think it would be useful to generalize this to
380 allow each compiler's spec to say which switches take arguments. But
381 this cannot be done in a consistent fashion. CC cannot even decide
382 which input files have been specified without knowing which switches
383 take arguments, and it must know which input files to compile in order
384 to tell which compilers to run.
386 CC also knows implicitly that arguments starting in `-l' are to be
387 treated as compiler output files, and passed to the linker in their
388 proper position among the other output files. */
390 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
392 /* config.h can define ASM_SPEC to provide extra args to the assembler
393 or extra switch-translations. */
398 /* config.h can define ASM_FINAL_SPEC to run a post processor after
399 the assembler has run. */
400 #ifndef ASM_FINAL_SPEC
401 #define ASM_FINAL_SPEC ""
404 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
405 or extra switch-translations. */
410 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
411 or extra switch-translations. */
416 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
417 or extra switch-translations. */
419 #define CC1PLUS_SPEC ""
422 /* config.h can define LINK_SPEC to provide extra args to the linker
423 or extra switch-translations. */
428 /* config.h can define LIB_SPEC to override the default libraries. */
430 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
433 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
436 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
437 /* Have gcc do the search for libgcc.a. */
438 #define LIBGCC_SPEC "libgcc.a%s"
440 #define LIBGCC_SPEC "-lgcc"
444 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
445 #ifndef STARTFILE_SPEC
446 #define STARTFILE_SPEC \
447 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
450 /* config.h can define SWITCHES_NEED_SPACES to control which options
451 require spaces between the option and the argument. */
452 #ifndef SWITCHES_NEED_SPACES
453 #define SWITCHES_NEED_SPACES ""
456 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
458 #define ENDFILE_SPEC ""
461 /* This spec is used for telling cpp whether char is signed or not. */
462 #ifndef SIGNED_CHAR_SPEC
463 /* Use #if rather than ?:
464 because MIPS C compiler rejects like ?: in initializers. */
465 #if DEFAULT_SIGNED_CHAR
466 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
468 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
472 static char *cpp_spec = CPP_SPEC;
473 static char *cpp_predefines = CPP_PREDEFINES;
474 static char *cc1_spec = CC1_SPEC;
475 static char *cc1plus_spec = CC1PLUS_SPEC;
476 static char *signed_char_spec = SIGNED_CHAR_SPEC;
477 static char *asm_spec = ASM_SPEC;
478 static char *asm_final_spec = ASM_FINAL_SPEC;
479 static char *link_spec = LINK_SPEC;
480 static char *lib_spec = LIB_SPEC;
481 static char *libgcc_spec = LIBGCC_SPEC;
482 static char *endfile_spec = ENDFILE_SPEC;
483 static char *startfile_spec = STARTFILE_SPEC;
484 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
486 /* Some compilers have limits on line lengths, and the multilib_select
487 and/or multilib_matches strings can be very long, so we build them at
489 static struct obstack multilib_obstack;
490 static char *multilib_select;
491 static char *multilib_matches;
492 static char *multilib_defaults;
493 #include "multilib.h"
495 /* Check whether a particular argument is a default argument. */
497 #ifndef MULTILIB_DEFAULTS
498 #define MULTILIB_DEFAULTS { "" }
501 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
504 struct user_specs *next;
508 static struct user_specs *user_specs_head, *user_specs_tail;
510 /* This defines which switch letters take arguments. */
512 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
513 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
514 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
515 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
516 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
517 || (CHAR) == 'B' || (CHAR) == 'b')
519 #ifndef SWITCH_TAKES_ARG
520 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
523 /* This defines which multi-letter switches take arguments. */
525 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
526 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
527 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
528 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
529 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
530 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
531 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
533 #ifndef WORD_SWITCH_TAKES_ARG
534 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
537 /* Record the mapping from file suffixes for compilation specs. */
541 char *suffix; /* Use this compiler for input files
542 whose names end in this suffix. */
544 char *spec[4]; /* To use this compiler, concatenate these
545 specs and pass to do_spec. */
548 /* Pointer to a vector of `struct compiler' that gives the spec for
549 compiling a file, based on its suffix.
550 A file that does not end in any of these suffixes will be passed
551 unchanged to the loader and nothing else will be done to it.
553 An entry containing two 0s is used to terminate the vector.
555 If multiple entries match a file, the last matching one is used. */
557 static struct compiler *compilers;
559 /* Number of entries in `compilers', not counting the null terminator. */
561 static int n_compilers;
563 /* The default list of file name suffixes and their compilation specs. */
565 static struct compiler default_compilers[] =
567 /* Add lists of suffixes of known languages here. If those languages
568 were not present when we built the driver, we will hit these copies
569 and be given a more meaningful error than "file not used since
570 linking is not done". */
571 {".cc", "#C++"}, {".cxx", "#C++"}, {".cpp", "#C++"}, {".c++", "#C++"},
572 {".C", "#C++"}, {".ads", "#Ada"}, {".adb", "#Ada"}, {".ada", "#Ada"},
573 {".f", "#Fortran"}, {".for", "#Fortran"}, {".F", "#Fortran"},
574 {".fpp", "#Fortran"},
575 {".p", "#Pascal"}, {".pas", "#Pascal"},
576 /* Next come the entries for C. */
579 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
580 %{C:%{!E:%eGNU C does not support -C without using -E}}\
581 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
582 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
583 %{ansi:-trigraphs -D__STRICT_ANSI__}\
584 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
585 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
586 %{traditional} %{ftraditional:-traditional}\
587 %{traditional-cpp:-traditional}\
588 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
589 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
590 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
591 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
592 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
593 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
595 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
596 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
598 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
599 %{!pipe:%g.s} %A\n }}}}"},
601 "%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
602 %{C:%{!E:%eGNU C does not support -C without using -E}}\
603 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
604 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
605 %{ansi:-trigraphs -D__STRICT_ANSI__}\
606 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
607 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
608 %{traditional} %{ftraditional:-traditional}\
609 %{traditional-cpp:-traditional}\
610 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
612 %{!E:%e-E required when input is from standard input}"},
613 {".m", "@objective-c"},
615 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
616 %{C:%{!E:%eGNU C does not support -C without using -E}}\
617 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
618 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
619 %{ansi:-trigraphs -D__STRICT_ANSI__}\
620 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
621 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
622 %{traditional} %{ftraditional:-traditional}\
623 %{traditional-cpp:-traditional}\
624 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
625 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
626 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
627 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
628 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
629 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
630 -lang-objc %{gen-decls} \
632 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
633 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
635 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
636 %{!pipe:%g.s} %A\n }}}}"},
639 "%{!E:%eCompilation of header file requested} \
640 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
641 %{C:%{!E:%eGNU C does not support -C without using -E}}\
642 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
643 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
644 %{ansi:-trigraphs -D__STRICT_ANSI__}\
645 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
646 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
647 %{traditional} %{ftraditional:-traditional}\
648 %{traditional-cpp:-traditional}\
649 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
651 {".i", "@cpp-output"},
653 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
654 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
655 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
657 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
658 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
660 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
661 %{!pipe:%g.s} %A\n }}}}"},
662 {".s", "@assembler"},
664 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
665 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
667 {".S", "@assembler-with-cpp"},
668 {"@assembler-with-cpp",
669 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
670 %{C:%{!E:%eGNU C does not support -C without using -E}}\
671 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
672 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
673 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
674 %{traditional} %{ftraditional:-traditional}\
675 %{traditional-cpp:-traditional}\
676 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
677 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
678 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
679 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
680 %{!pipe:%g.s} %A\n }}}}"},
682 /* Mark end of table */
686 /* Number of elements in default_compilers, not counting the terminator. */
688 static int n_default_compilers
689 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
691 /* Here is the spec for running the linker, after compiling all files. */
693 /* -u* was put back because both BSD and SysV seem to support it. */
694 /* %{static:} simply prevents an error message if the target machine
695 doesn't handle -static. */
696 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
697 scripts which exist in user specified directories, or in standard
699 #ifdef LINK_LIBGCC_SPECIAL
700 /* Don't generate -L options. */
701 static char *link_command_spec = "\
703 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
704 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
705 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
707 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
708 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
713 static char *link_command_spec = "\
715 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
716 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
717 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
718 %{static:} %{L*} %D %o\
719 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
720 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
725 /* A vector of options to give to the linker.
726 These options are accumulated by %x,
727 and substituted into the linker command with %X. */
728 static int n_linker_options;
729 static char **linker_options;
731 /* A vector of options to give to the assembler.
732 These options are accumulated by -Wa,
733 and substituted into the assembler command with %Y. */
734 static int n_assembler_options;
735 static char **assembler_options;
737 /* A vector of options to give to the preprocessor.
738 These options are accumulated by -Wp,
739 and substituted into the preprocessor command with %Z. */
740 static int n_preprocessor_options;
741 static char **preprocessor_options;
743 /* Define how to map long options into short ones. */
745 /* This structure describes one mapping. */
748 /* The long option's name. */
750 /* The equivalent short option. */
752 /* Argument info. A string of flag chars; NULL equals no options.
753 a => argument required.
754 o => argument optional.
755 j => join argument to equivalent, making one word.
756 * => require other text after NAME as an argument. */
760 /* This is the table of mappings. Mappings are tried sequentially
761 for each option encountered; the first one that matches, wins. */
763 struct option_map option_map[] =
765 {"--all-warnings", "-Wall", 0},
766 {"--ansi", "-ansi", 0},
767 {"--assemble", "-S", 0},
768 {"--assert", "-A", "a"},
769 {"--comments", "-C", 0},
770 {"--compile", "-c", 0},
771 {"--debug", "-g", "oj"},
772 {"--define-macro", "-D", "aj"},
773 {"--dependencies", "-M", 0},
774 {"--dump", "-d", "a"},
775 {"--dumpbase", "-dumpbase", "a"},
776 {"--entry", "-e", 0},
777 {"--extra-warnings", "-W", 0},
778 {"--for-assembler", "-Wa", "a"},
779 {"--for-linker", "-Xlinker", "a"},
780 {"--force-link", "-u", "a"},
781 {"--imacros", "-imacros", "a"},
782 {"--include", "-include", "a"},
783 {"--include-barrier", "-I-", 0},
784 {"--include-directory", "-I", "aj"},
785 {"--include-directory-after", "-idirafter", "a"},
786 {"--include-prefix", "-iprefix", "a"},
787 {"--include-with-prefix", "-iwithprefix", "a"},
788 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
789 {"--include-with-prefix-after", "-iwithprefix", "a"},
790 {"--language", "-x", "a"},
791 {"--library-directory", "-L", "a"},
792 {"--machine", "-m", "aj"},
793 {"--machine-", "-m", "*j"},
794 {"--no-line-commands", "-P", 0},
795 {"--no-precompiled-includes", "-noprecomp", 0},
796 {"--no-standard-includes", "-nostdinc", 0},
797 {"--no-standard-libraries", "-nostdlib", 0},
798 {"--no-warnings", "-w", 0},
799 {"--optimize", "-O", "oj"},
800 {"--output", "-o", "a"},
801 {"--pedantic", "-pedantic", 0},
802 {"--pedantic-errors", "-pedantic-errors", 0},
803 {"--pipe", "-pipe", 0},
804 {"--prefix", "-B", "a"},
805 {"--preprocess", "-E", 0},
806 {"--print-search-dirs", "-print-search-dirs", 0},
807 {"--print-file-name", "-print-file-name=", "aj"},
808 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
809 {"--print-missing-file-dependencies", "-MG", 0},
810 {"--print-multi-lib", "-print-multi-lib", 0},
811 {"--print-multi-directory", "-print-multi-directory", 0},
812 {"--print-prog-name", "-print-prog-name=", "aj"},
813 {"--profile", "-p", 0},
814 {"--profile-blocks", "-a", 0},
815 {"--quiet", "-q", 0},
816 {"--save-temps", "-save-temps", 0},
817 {"--shared", "-shared", 0},
818 {"--silent", "-q", 0},
819 {"--specs", "-specs=", "aj"},
820 {"--static", "-static", 0},
821 {"--symbolic", "-symbolic", 0},
822 {"--target", "-b", "a"},
823 {"--trace-includes", "-H", 0},
824 {"--traditional", "-traditional", 0},
825 {"--traditional-cpp", "-traditional-cpp", 0},
826 {"--trigraphs", "-trigraphs", 0},
827 {"--undefine-macro", "-U", "aj"},
828 {"--use-version", "-V", "a"},
829 {"--user-dependencies", "-MM", 0},
830 {"--verbose", "-v", 0},
831 {"--version", "-dumpversion", 0},
832 {"--warn-", "-W", "*j"},
833 {"--write-dependencies", "-MD", 0},
834 {"--write-user-dependencies", "-MMD", 0},
838 /* Translate the options described by *ARGCP and *ARGVP.
839 Make a new vector and store it back in *ARGVP,
840 and store its length in *ARGVC. */
843 translate_options (argcp, argvp)
849 char **argv = *argvp;
850 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
854 newv[newindex++] = argv[i++];
858 /* Translate -- options. */
859 if (argv[i][0] == '-' && argv[i][1] == '-')
861 /* Find a mapping that applies to this option. */
862 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
864 int optlen = strlen (option_map[j].name);
865 int arglen = strlen (argv[i]);
866 int complen = arglen > optlen ? optlen : arglen;
867 char *arginfo = option_map[j].arg_info;
872 if (!strncmp (argv[i], option_map[j].name, complen))
879 k < sizeof (option_map) / sizeof (option_map[0]);
881 if (strlen (option_map[k].name) >= arglen
882 && !strncmp (argv[i], option_map[k].name, arglen))
884 error ("Ambiguous abbreviation %s", argv[i]);
888 if (k != sizeof (option_map) / sizeof (option_map[0]))
894 /* If the option has an argument, accept that. */
895 if (argv[i][optlen] == '=')
896 arg = argv[i] + optlen + 1;
898 /* If this mapping requires extra text at end of name,
899 accept that as "argument". */
900 else if (index (arginfo, '*') != 0)
901 arg = argv[i] + optlen;
903 /* Otherwise, extra text at end means mismatch.
904 Try other mappings. */
909 else if (index (arginfo, '*') != 0)
911 error ("Incomplete `%s' option", option_map[j].name);
915 /* Handle arguments. */
916 if (index (arginfo, 'a') != 0)
922 error ("Missing argument to `%s' option",
930 else if (index (arginfo, '*') != 0)
932 else if (index (arginfo, 'o') == 0)
935 error ("Extraneous argument to `%s' option",
940 /* Store the translation as one argv elt or as two. */
941 if (arg != 0 && index (arginfo, 'j') != 0)
942 newv[newindex++] = concat (option_map[j].equivalent, arg,
946 newv[newindex++] = option_map[j].equivalent;
947 newv[newindex++] = arg;
950 newv[newindex++] = option_map[j].equivalent;
958 /* Handle old-fashioned options--just copy them through,
959 with their arguments. */
960 else if (argv[i][0] == '-')
962 char *p = argv[i] + 1;
966 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
967 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
968 else if (WORD_SWITCH_TAKES_ARG (p))
969 nskip += WORD_SWITCH_TAKES_ARG (p);
970 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
973 else if (! strcmp (p, "Xlinker"))
976 /* Watch out for an option at the end of the command line that
977 is missing arguments, and avoid skipping past the end of the
979 if (nskip + i > argc)
984 newv[newindex++] = argv[i++];
989 /* Ordinary operands, or +e options. */
990 newv[newindex++] = argv[i++];
1003 #ifdef HAVE_STRERROR
1009 static char buffer[30];
1011 return "cannot access";
1013 if (e > 0 && e < sys_nerr)
1014 return sys_errlist[e];
1016 sprintf (buffer, "Unknown error %d", e);
1027 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1028 be considered whitespace. */
1029 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1031 else if (*p == '\n' || *p == ' ' || *p == '\t')
1035 while (*p != '\n') p++;
1045 /* Structure to keep track of the specs that have been defined so far.
1046 These are accessed using %(specname) or %[specname] in a compiler
1051 /* The following 2 fields must be first */
1052 /* to allow EXTRA_SPECS to be initialized */
1053 char *name; /* name of the spec. */
1054 char *ptr; /* available ptr if no static pointer */
1056 /* The following fields are not initialized */
1057 /* by EXTRA_SPECS */
1058 char **ptr_spec; /* pointer to the spec itself. */
1059 struct spec_list *next; /* Next spec in linked list. */
1060 int name_len; /* length of the name */
1061 int alloc_p; /* whether string was allocated */
1064 #define INIT_STATIC_SPEC(NAME,PTR) \
1065 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1067 /* List of statically defined specs */
1068 static struct spec_list static_specs[] = {
1069 INIT_STATIC_SPEC ("asm", &asm_spec),
1070 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1071 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1072 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1073 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1074 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1075 INIT_STATIC_SPEC ("link", &link_spec),
1076 INIT_STATIC_SPEC ("lib", &lib_spec),
1077 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1078 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1079 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1080 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1081 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1082 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1083 INIT_STATIC_SPEC ("version", &compiler_version),
1084 INIT_STATIC_SPEC ("multilib", &multilib_select),
1085 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1086 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1087 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1090 #ifdef EXTRA_SPECS /* additional specs needed */
1091 static struct spec_list extra_specs[] = { EXTRA_SPECS };
1094 /* List of dynamically allocates specs that have been defined so far. */
1096 static struct spec_list *specs = (struct spec_list *)0;
1099 /* Initialize the specs lookup routines. */
1104 struct spec_list *next = (struct spec_list *)0;
1105 struct spec_list *sl = (struct spec_list *)0;
1109 return; /* already initialized */
1112 fprintf (stderr, "Using builtin specs.\n");
1115 for (i = (sizeof (extra_specs) / sizeof (extra_specs[0])) - 1; i >= 0; i--)
1117 sl = &extra_specs[i];
1119 sl->name_len = strlen (sl->name);
1120 sl->ptr_spec = &sl->ptr;
1125 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1127 sl = &static_specs[i];
1136 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1137 removed; If the spec starts with a + then SPEC is added to the end of the
1141 set_spec (name, spec)
1145 struct spec_list *sl;
1147 int name_len = strlen (name);
1150 /* If this is the first call, initialize the statically allocated specs */
1153 struct spec_list *next = (struct spec_list *)0;
1154 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1157 sl = &static_specs[i];
1164 /* See if the spec already exists */
1165 for (sl = specs; sl; sl = sl->next)
1166 if (name_len == sl->name_len && !strcmp (sl->name, name))
1171 /* Not found - make it */
1172 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1173 sl->name = save_string (name, strlen (name));
1174 sl->name_len = name_len;
1175 sl->ptr_spec = &sl->ptr;
1177 *(sl->ptr_spec) = "";
1182 old_spec = *(sl->ptr_spec);
1183 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE (spec[1]))
1184 ? concat (old_spec, spec + 1, NULL_PTR)
1185 : save_string (spec, strlen (spec)));
1189 fprintf (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1192 /* Free the old spec */
1193 if (old_spec && sl->alloc_p)
1199 /* Accumulate a command (program name and args), and run it. */
1201 /* Vector of pointers to arguments in the current line of specifications. */
1203 static char **argbuf;
1205 /* Number of elements allocated in argbuf. */
1207 static int argbuf_length;
1209 /* Number of elements in argbuf currently in use (containing args). */
1211 static int argbuf_index;
1213 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1214 temp file. Used only if MKTEMP_EACH_FILE. */
1216 static struct temp_name {
1217 char *suffix; /* suffix associated with the code. */
1218 int length; /* strlen (suffix). */
1219 int unique; /* Indicates whether %g or %u/%U was used. */
1220 char *filename; /* associated filename. */
1221 int filename_length; /* strlen (filename). */
1222 struct temp_name *next;
1225 /* Number of commands executed so far. */
1227 static int execution_count;
1229 /* Number of commands that exited with a signal. */
1231 static int signal_count;
1233 /* Name with which this program was invoked. */
1235 static char *programname;
1237 /* Structures to keep track of prefixes to try when looking for files. */
1241 char *prefix; /* String to prepend to the path. */
1242 struct prefix_list *next; /* Next in linked list. */
1243 int require_machine_suffix; /* Don't use without machine_suffix. */
1244 /* 2 means try both machine_suffix and just_machine_suffix. */
1245 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1250 struct prefix_list *plist; /* List of prefixes to try */
1251 int max_len; /* Max length of a prefix in PLIST */
1252 char *name; /* Name of this list (used in config stuff) */
1255 /* List of prefixes to try when looking for executables. */
1257 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1259 /* List of prefixes to try when looking for startup (crt0) files. */
1261 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1263 /* List of prefixes to try when looking for include files. */
1265 static struct path_prefix include_prefixes = { 0, 0, "include" };
1267 /* Suffix to attach to directories searched for commands.
1268 This looks like `MACHINE/VERSION/'. */
1270 static char *machine_suffix = 0;
1272 /* Suffix to attach to directories searched for commands.
1273 This is just `MACHINE/'. */
1275 static char *just_machine_suffix = 0;
1277 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1279 static char *gcc_exec_prefix;
1281 /* Default prefixes to attach to command names. */
1283 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1284 #undef MD_EXEC_PREFIX
1285 #undef MD_STARTFILE_PREFIX
1286 #undef MD_STARTFILE_PREFIX_1
1289 #ifndef STANDARD_EXEC_PREFIX
1290 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1291 #endif /* !defined STANDARD_EXEC_PREFIX */
1293 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1294 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1295 #ifdef MD_EXEC_PREFIX
1296 static char *md_exec_prefix = MD_EXEC_PREFIX;
1299 #ifndef STANDARD_STARTFILE_PREFIX
1300 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1301 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1303 #ifdef MD_STARTFILE_PREFIX
1304 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1306 #ifdef MD_STARTFILE_PREFIX_1
1307 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1309 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1310 static char *standard_startfile_prefix_1 = "/lib/";
1311 static char *standard_startfile_prefix_2 = "/usr/lib/";
1313 #ifndef TOOLDIR_BASE_PREFIX
1314 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1316 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1317 static char *tooldir_prefix;
1319 /* Subdirectory to use for locating libraries. Set by
1320 set_multilib_dir based on the compilation options. */
1322 static char *multilib_dir;
1324 /* Clear out the vector of arguments (after a command is executed). */
1332 /* Add one argument to the vector at the end.
1333 This is done when a space is seen or at the end of the line.
1334 If DELETE_ALWAYS is nonzero, the arg is a filename
1335 and the file should be deleted eventually.
1336 If DELETE_FAILURE is nonzero, the arg is a filename
1337 and the file should be deleted if this compilation fails. */
1340 store_arg (arg, delete_always, delete_failure)
1342 int delete_always, delete_failure;
1344 if (argbuf_index + 1 == argbuf_length)
1346 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1348 argbuf[argbuf_index++] = arg;
1349 argbuf[argbuf_index] = 0;
1351 if (delete_always || delete_failure)
1352 record_temp_file (arg, delete_always, delete_failure);
1355 /* Read compilation specs from a file named FILENAME,
1356 replacing the default ones.
1358 A suffix which starts with `*' is a definition for
1359 one of the machine-specific sub-specs. The "suffix" should be
1360 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1361 The corresponding spec is stored in asm_spec, etc.,
1362 rather than in the `compilers' vector.
1364 Anything invalid in the file is a fatal error. */
1367 read_specs (filename, main_p)
1373 struct stat statbuf;
1378 fprintf (stderr, "Reading specs from %s\n", filename);
1380 /* Open and stat the file. */
1381 desc = open (filename, O_RDONLY, 0);
1383 pfatal_with_name (filename);
1384 if (stat (filename, &statbuf) < 0)
1385 pfatal_with_name (filename);
1387 /* Read contents of file into BUFFER. */
1388 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1389 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1391 pfatal_with_name (filename);
1392 buffer[readlen] = 0;
1395 /* Scan BUFFER for specs, putting them in the vector. */
1401 char *in, *out, *p1, *p2, *p3;
1403 /* Advance P in BUFFER to the next nonblank nocomment line. */
1404 p = skip_whitespace (p);
1408 /* Is this a special command that starts with '%'? */
1409 /* Don't allow this for the main specs file, since it would
1410 encourage people to overwrite it. */
1411 if (*p == '%' && !main_p)
1414 while (*p && *p != '\n')
1417 p++; /* Skip '\n' */
1419 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1420 && (p1[sizeof "%include" - 1] == ' '
1421 || p1[sizeof "%include" - 1] == '\t'))
1425 p1 += sizeof ("%include");
1426 while (*p1 == ' ' || *p1 == '\t')
1429 if (*p1++ != '<' || p[-2] != '>')
1430 fatal ("specs %%include syntax malformed after %d characters",
1434 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1435 read_specs (new_filename ? new_filename : p1, FALSE);
1438 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1439 && (p1[sizeof "%include_noerr" - 1] == ' '
1440 || p1[sizeof "%include_noerr" - 1] == '\t'))
1444 p1 += sizeof "%include_noerr";
1445 while (*p1 == ' ' || *p1 == '\t') p1++;
1447 if (*p1++ != '<' || p[-2] != '>')
1448 fatal ("specs %%include syntax malformed after %d characters",
1452 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1454 read_specs (new_filename, FALSE);
1455 else if (verbose_flag)
1456 fprintf (stderr, "Could not find specs file %s\n", p1);
1459 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1460 && (p1[sizeof "%rename" - 1] == ' '
1461 || p1[sizeof "%rename" - 1] == '\t'))
1464 struct spec_list *sl;
1466 /* Get original name */
1467 p1 += sizeof "%rename";
1468 while (*p1 == ' ' || *p1 == '\t')
1471 if (! ISALPHA (*p1))
1472 fatal ("specs %%rename syntax malformed after %d characters",
1476 while (*p2 && !ISSPACE (*p2))
1479 if (*p2 != ' ' && *p2 != '\t')
1480 fatal ("specs %%rename syntax malformed after %d characters",
1485 while (*p2 == ' ' || *p2 == '\t')
1488 if (! ISALPHA (*p2))
1489 fatal ("specs %%rename syntax malformed after %d characters",
1492 /* Get new spec name */
1494 while (*p3 && !ISSPACE (*p3))
1498 fatal ("specs %%rename syntax malformed after %d characters",
1502 for (sl = specs; sl; sl = sl->next)
1503 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1507 fatal ("specs %s spec was not found to be renamed", p1);
1509 if (strcmp (p1, p2) == 0)
1514 fprintf (stderr, "rename spec %s to %s\n", p1, p2);
1516 fprintf (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
1520 set_spec (p2, *(sl->ptr_spec));
1522 free (*(sl->ptr_spec));
1524 *(sl->ptr_spec) = "";
1529 fatal ("specs unknown %% command after %d characters",
1533 /* Find the colon that should end the suffix. */
1535 while (*p1 && *p1 != ':' && *p1 != '\n')
1538 /* The colon shouldn't be missing. */
1540 fatal ("specs file malformed after %d characters", p1 - buffer);
1542 /* Skip back over trailing whitespace. */
1544 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1547 /* Copy the suffix to a string. */
1548 suffix = save_string (p, p2 - p);
1549 /* Find the next line. */
1550 p = skip_whitespace (p1 + 1);
1552 fatal ("specs file malformed after %d characters", p - buffer);
1555 /* Find next blank line. */
1556 while (*p1 && !(*p1 == '\n' && p1[1] == '\n'))
1559 /* Specs end at the blank line and do not include the newline. */
1560 spec = save_string (p, p1 - p);
1563 /* Delete backslash-newline sequences from the spec. */
1568 if (in[0] == '\\' && in[1] == '\n')
1570 else if (in[0] == '#')
1571 while (*in && *in != '\n')
1579 if (suffix[0] == '*')
1581 if (! strcmp (suffix, "*link_command"))
1582 link_command_spec = spec;
1584 set_spec (suffix + 1, spec);
1588 /* Add this pair to the vector. */
1590 = ((struct compiler *)
1591 xrealloc (compilers,
1592 (n_compilers + 2) * sizeof (struct compiler)));
1594 compilers[n_compilers].suffix = suffix;
1595 bzero ((char *) compilers[n_compilers].spec,
1596 sizeof compilers[n_compilers].spec);
1597 compilers[n_compilers].spec[0] = spec;
1599 bzero ((char *) &compilers[n_compilers],
1600 sizeof compilers[n_compilers]);
1604 link_command_spec = spec;
1607 if (link_command_spec == 0)
1608 fatal ("spec file has no spec for linking");
1611 /* Record the names of temporary files we tell compilers to write,
1612 and delete them at the end of the run. */
1614 /* This is the common prefix we use to make temp file names.
1615 It is chosen once for each run of this program.
1616 It is substituted into a spec by %g.
1617 Thus, all temp file names contain this prefix.
1618 In practice, all temp file names start with this prefix.
1620 This prefix comes from the envvar TMPDIR if it is defined;
1621 otherwise, from the P_tmpdir macro if that is defined;
1622 otherwise, in /usr/tmp or /tmp;
1623 or finally the current directory if all else fails. */
1625 static char *temp_filename;
1627 /* Length of the prefix. */
1629 static int temp_filename_length;
1631 /* Define the list of temporary files to delete. */
1636 struct temp_file *next;
1639 /* Queue of files to delete on success or failure of compilation. */
1640 static struct temp_file *always_delete_queue;
1641 /* Queue of files to delete on failure of compilation. */
1642 static struct temp_file *failure_delete_queue;
1644 /* Record FILENAME as a file to be deleted automatically.
1645 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1646 otherwise delete it in any case.
1647 FAIL_DELETE nonzero means delete it if a compilation step fails;
1648 otherwise delete it in any case. */
1651 record_temp_file (filename, always_delete, fail_delete)
1656 register char *name;
1657 name = xmalloc (strlen (filename) + 1);
1658 strcpy (name, filename);
1662 register struct temp_file *temp;
1663 for (temp = always_delete_queue; temp; temp = temp->next)
1664 if (! strcmp (name, temp->name))
1667 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1668 temp->next = always_delete_queue;
1670 always_delete_queue = temp;
1677 register struct temp_file *temp;
1678 for (temp = failure_delete_queue; temp; temp = temp->next)
1679 if (! strcmp (name, temp->name))
1682 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1683 temp->next = failure_delete_queue;
1685 failure_delete_queue = temp;
1691 /* Delete all the temporary files whose names we previously recorded. */
1694 delete_if_ordinary (name)
1701 printf ("Delete %s? (y or n) ", name);
1705 while ((c = getchar ()) != '\n' && c != EOF)
1708 if (i == 'y' || i == 'Y')
1710 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1711 if (unlink (name) < 0)
1713 perror_with_name (name);
1717 delete_temp_files ()
1719 register struct temp_file *temp;
1721 for (temp = always_delete_queue; temp; temp = temp->next)
1722 delete_if_ordinary (temp->name);
1723 always_delete_queue = 0;
1726 /* Delete all the files to be deleted on error. */
1729 delete_failure_queue ()
1731 register struct temp_file *temp;
1733 for (temp = failure_delete_queue; temp; temp = temp->next)
1734 delete_if_ordinary (temp->name);
1738 clear_failure_queue ()
1740 failure_delete_queue = 0;
1743 /* Routine to add variables to the environment. We do this to pass
1744 the pathname of the gcc driver, and the directories search to the
1745 collect2 program, which is being run as ld. This way, we can be
1746 sure of executing the right compiler when collect2 wants to build
1747 constructors and destructors. Since the environment variables we
1748 use come from an obstack, we don't have to worry about allocating
1757 #ifndef VMS /* nor about VMS */
1759 extern char **environ;
1760 char **old_environ = environ;
1764 int str_len = strlen (str);
1768 while ((ch = *p++) != '\0' && ch != '=')
1774 /* Search for replacing an existing environment variable, and
1775 count the number of total environment variables. */
1776 for (envp = old_environ; *envp; envp++)
1779 if (!strncmp (str, *envp, name_len))
1786 /* Add a new environment variable */
1787 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1789 bcopy ((char *) old_environ, (char *) (environ + 1),
1790 sizeof (char *) * (num_envs+1));
1795 #endif /* HAVE_PUTENV */
1798 /* Build a list of search directories from PATHS.
1799 PREFIX is a string to prepend to the list.
1800 If CHECK_DIR_P is non-zero we ensure the directory exists.
1801 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1802 It is also used by the --print-search-dirs flag. */
1805 build_search_list (paths, prefix, check_dir_p)
1806 struct path_prefix *paths;
1810 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1812 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1813 int first_time = TRUE;
1814 struct prefix_list *pprefix;
1816 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1818 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1820 int len = strlen (pprefix->prefix);
1824 || is_directory (pprefix->prefix, machine_suffix, 0)))
1827 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1830 obstack_grow (&collect_obstack, pprefix->prefix, len);
1831 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1834 if (just_machine_suffix
1835 && pprefix->require_machine_suffix == 2
1837 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1840 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1843 obstack_grow (&collect_obstack, pprefix->prefix, len);
1844 obstack_grow (&collect_obstack, just_machine_suffix,
1848 if (! pprefix->require_machine_suffix)
1851 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1854 obstack_grow (&collect_obstack, pprefix->prefix, len);
1858 obstack_1grow (&collect_obstack, '\0');
1859 return obstack_finish (&collect_obstack);
1862 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1866 putenv_from_prefixes (paths, env_var)
1867 struct path_prefix *paths;
1870 putenv (build_search_list (paths, env_var, 1));
1873 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1874 access to check permissions.
1875 Return 0 if not found, otherwise return its name, allocated with malloc. */
1878 find_a_file (pprefix, name, mode)
1879 struct path_prefix *pprefix;
1884 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1885 struct prefix_list *pl;
1886 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1889 len += strlen (machine_suffix);
1891 temp = xmalloc (len);
1893 /* Determine the filename to execute (special case for absolute paths). */
1895 if (*name == '/' || *name == DIR_SEPARATOR
1896 /* Check for disk name on MS-DOS-based systems. */
1897 || (DIR_SEPARATOR == '\\' && name[1] == ':'
1898 && (name[2] == DIR_SEPARATOR || name[2] == '/')))
1900 if (access (name, mode))
1902 strcpy (temp, name);
1907 for (pl = pprefix->plist; pl; pl = pl->next)
1911 /* Some systems have a suffix for executable files.
1912 So try appending that first. */
1913 if (file_suffix[0] != 0)
1915 strcpy (temp, pl->prefix);
1916 strcat (temp, machine_suffix);
1917 strcat (temp, name);
1918 strcat (temp, file_suffix);
1919 if (access (temp, mode) == 0)
1921 if (pl->used_flag_ptr != 0)
1922 *pl->used_flag_ptr = 1;
1927 /* Now try just the name. */
1928 strcpy (temp, pl->prefix);
1929 strcat (temp, machine_suffix);
1930 strcat (temp, name);
1931 if (access (temp, mode) == 0)
1933 if (pl->used_flag_ptr != 0)
1934 *pl->used_flag_ptr = 1;
1939 /* Certain prefixes are tried with just the machine type,
1940 not the version. This is used for finding as, ld, etc. */
1941 if (just_machine_suffix && pl->require_machine_suffix == 2)
1943 /* Some systems have a suffix for executable files.
1944 So try appending that first. */
1945 if (file_suffix[0] != 0)
1947 strcpy (temp, pl->prefix);
1948 strcat (temp, just_machine_suffix);
1949 strcat (temp, name);
1950 strcat (temp, file_suffix);
1951 if (access (temp, mode) == 0)
1953 if (pl->used_flag_ptr != 0)
1954 *pl->used_flag_ptr = 1;
1959 strcpy (temp, pl->prefix);
1960 strcat (temp, just_machine_suffix);
1961 strcat (temp, name);
1962 if (access (temp, mode) == 0)
1964 if (pl->used_flag_ptr != 0)
1965 *pl->used_flag_ptr = 1;
1970 /* Certain prefixes can't be used without the machine suffix
1971 when the machine or version is explicitly specified. */
1972 if (! pl->require_machine_suffix)
1974 /* Some systems have a suffix for executable files.
1975 So try appending that first. */
1976 if (file_suffix[0] != 0)
1978 strcpy (temp, pl->prefix);
1979 strcat (temp, name);
1980 strcat (temp, file_suffix);
1981 if (access (temp, mode) == 0)
1983 if (pl->used_flag_ptr != 0)
1984 *pl->used_flag_ptr = 1;
1989 strcpy (temp, pl->prefix);
1990 strcat (temp, name);
1991 if (access (temp, mode) == 0)
1993 if (pl->used_flag_ptr != 0)
1994 *pl->used_flag_ptr = 1;
2004 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2005 at the start of the list, otherwise it goes at the end.
2007 If WARN is nonzero, we will warn if no file is found
2008 through this prefix. WARN should point to an int
2009 which will be set to 1 if this entry is used.
2011 COMPONENT is the value to be passed to update_path.
2013 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2014 the complete value of machine_suffix.
2015 2 means try both machine_suffix and just_machine_suffix. */
2018 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2019 struct path_prefix *pprefix;
2023 int require_machine_suffix;
2026 struct prefix_list *pl, **prev;
2029 if (! first && pprefix->plist)
2031 for (pl = pprefix->plist; pl->next; pl = pl->next)
2036 prev = &pprefix->plist;
2038 /* Keep track of the longest prefix */
2040 prefix = update_path (prefix, component);
2041 len = strlen (prefix);
2042 if (len > pprefix->max_len)
2043 pprefix->max_len = len;
2045 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2046 pl->prefix = save_string (prefix, len);
2047 pl->require_machine_suffix = require_machine_suffix;
2048 pl->used_flag_ptr = warn;
2055 pl->next = (struct prefix_list *) 0;
2059 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2062 unused_prefix_warnings (pprefix)
2063 struct path_prefix *pprefix;
2065 struct prefix_list *pl = pprefix->plist;
2069 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2071 if (pl->require_machine_suffix && machine_suffix)
2072 error ("file path prefix `%s%s' never used", pl->prefix,
2075 error ("file path prefix `%s' never used", pl->prefix);
2077 /* Prevent duplicate warnings. */
2078 *pl->used_flag_ptr = 1;
2086 /* Execute the command specified by the arguments on the current line of spec.
2087 When using pipes, this includes several piped-together commands
2088 with `|' between them.
2090 Return 0 if successful, -1 if failed. */
2096 int n_commands; /* # of command. */
2100 char *prog; /* program name. */
2101 char **argv; /* vector of args. */
2102 int pid; /* pid of process for this command. */
2105 struct command *commands; /* each command buffer with above info. */
2107 /* Count # of piped commands. */
2108 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2109 if (strcmp (argbuf[i], "|") == 0)
2112 /* Get storage for each command. */
2114 = (struct command *) alloca (n_commands * sizeof (struct command));
2116 /* Split argbuf into its separate piped processes,
2117 and record info about each one.
2118 Also search for the programs that are to be run. */
2120 commands[0].prog = argbuf[0]; /* first command. */
2121 commands[0].argv = &argbuf[0];
2122 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2124 commands[0].argv[0] = string;
2126 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2127 if (strcmp (argbuf[i], "|") == 0)
2128 { /* each command. */
2129 #if defined (__MSDOS__) || (defined (_WIN32) && defined (__CYGWIN32_)) || defined (OS2) || defined (VMS)
2130 fatal ("-pipe not supported");
2132 argbuf[i] = 0; /* termination of command args. */
2133 commands[n_commands].prog = argbuf[i + 1];
2134 commands[n_commands].argv = &argbuf[i + 1];
2135 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2137 commands[n_commands].argv[0] = string;
2141 argbuf[argbuf_index] = 0;
2143 /* If -v, print what we are about to do, and maybe query. */
2147 /* Print each piped command as a separate line. */
2148 for (i = 0; i < n_commands ; i++)
2152 for (j = commands[i].argv; *j; j++)
2153 fprintf (stderr, " %s", *j);
2155 /* Print a pipe symbol after all but the last command. */
2156 if (i + 1 != n_commands)
2157 fprintf (stderr, " |");
2158 fprintf (stderr, "\n");
2162 fprintf (stderr, "\nGo ahead? (y or n) ");
2166 while (getchar () != '\n')
2169 if (i != 'y' && i != 'Y')
2174 /* Run each piped subprocess. */
2176 for (i = 0; i < n_commands; i++)
2178 char *errmsg_fmt, *errmsg_arg;
2179 char *string = commands[i].argv[0];
2181 commands[i].pid = pexecute (string, commands[i].argv,
2182 programname, temp_filename,
2183 &errmsg_fmt, &errmsg_arg,
2184 ((i == 0 ? PEXECUTE_FIRST : 0)
2185 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2186 | (string == commands[i].prog
2187 ? PEXECUTE_SEARCH : 0)
2188 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2190 if (commands[i].pid == -1)
2191 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2193 if (string != commands[i].prog)
2199 /* Wait for all the subprocesses to finish.
2200 We don't care what order they finish in;
2201 we know that N_COMMANDS waits will get them all.
2202 Ignore subprocesses that we don't know about,
2203 since they can be spawned by the process that exec'ed us. */
2208 for (i = 0; i < n_commands; )
2214 pid = pwait (commands[i].pid, &status, 0);
2218 for (j = 0; j < n_commands; j++)
2219 if (commands[j].pid == pid)
2224 if (WIFSIGNALED (status))
2226 fatal ("Internal compiler error: program %s got fatal signal %d",
2227 commands[j].prog, WTERMSIG (status));
2231 else if (WIFEXITED (status)
2232 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2242 /* Find all the switches given to us
2243 and make a vector describing them.
2244 The elements of the vector are strings, one per switch given.
2245 If a switch uses following arguments, then the `part1' field
2246 is the switch itself and the `args' field
2247 is a null-terminated vector containing the following arguments.
2248 The `live_cond' field is 1 if the switch is true in a conditional spec,
2249 -1 if false (overridden by a later switch), and is initialized to zero.
2250 The `valid' field is nonzero if any spec has looked at this switch;
2251 if it remains zero at the end of the run, it must be meaningless. */
2261 static struct switchstr *switches;
2263 static int n_switches;
2271 /* Also a vector of input files specified. */
2273 static struct infile *infiles;
2275 static int n_infiles;
2277 /* And a vector of corresponding output files is made up later. */
2279 static char **outfiles;
2281 /* Used to track if none of the -B paths are used. */
2284 /* Used to track if standard path isn't used and -b or -V is specified. */
2285 static int warn_std;
2287 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2288 static int *warn_std_ptr = 0;
2291 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2293 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2294 is true if we should look for an executable suffix as well. */
2297 convert_filename (name, do_exe)
2302 int len = strlen (name);
2304 #ifdef HAVE_OBJECT_SUFFIX
2305 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2307 && name[len - 2] == '.'
2308 && name[len - 1] == 'o')
2310 obstack_grow (&obstack, name, len - 2);
2311 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2312 name = obstack_finish (&obstack);
2316 #ifdef HAVE_EXECUTABLE_SUFFIX
2317 /* If there is no filetype, make it the executable suffix (which includes
2318 the "."). But don't get confused if we have just "-o". */
2319 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2322 for (i = len - 1; i >= 0; i--)
2323 if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2326 for (i++; i < len; i++)
2330 obstack_grow (&obstack, name, len);
2331 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2332 name = obstack_finish (&obstack);
2339 /* Create the vector `switches' and its contents.
2340 Store its length in `n_switches'. */
2343 process_command (argc, argv)
2349 char *spec_lang = 0;
2350 int last_language_n_infiles;
2353 int lang_n_infiles = 0;
2355 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
2360 /* Figure compiler version from version string. */
2362 compiler_version = save_string (version_string, strlen (version_string));
2363 for (temp = compiler_version; *temp; ++temp)
2372 /* Set up the default search paths. */
2374 if (gcc_exec_prefix)
2376 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2377 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2380 /* COMPILER_PATH and LIBRARY_PATH have values
2381 that are lists of directory names with colons. */
2383 temp = getenv ("COMPILER_PATH");
2386 char *startp, *endp;
2387 char *nstore = (char *) alloca (strlen (temp) + 3);
2389 startp = endp = temp;
2392 if (*endp == PATH_SEPARATOR || *endp == 0)
2394 strncpy (nstore, startp, endp-startp);
2396 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2397 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2399 nstore[endp-startp] = DIR_SEPARATOR;
2400 nstore[endp-startp+1] = 0;
2403 nstore[endp-startp] = 0;
2404 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2405 add_prefix (&include_prefixes,
2406 concat (nstore, "include", NULL_PTR),
2410 endp = startp = endp + 1;
2417 temp = getenv ("LIBRARY_PATH");
2418 if (temp && *cross_compile == '0')
2420 char *startp, *endp;
2421 char *nstore = (char *) alloca (strlen (temp) + 3);
2423 startp = endp = temp;
2426 if (*endp == PATH_SEPARATOR || *endp == 0)
2428 strncpy (nstore, startp, endp-startp);
2430 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2431 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2433 nstore[endp-startp] = DIR_SEPARATOR;
2434 nstore[endp-startp+1] = 0;
2437 nstore[endp-startp] = 0;
2438 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2442 endp = startp = endp + 1;
2449 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2450 temp = getenv ("LPATH");
2451 if (temp && *cross_compile == '0')
2453 char *startp, *endp;
2454 char *nstore = (char *) alloca (strlen (temp) + 3);
2456 startp = endp = temp;
2459 if (*endp == PATH_SEPARATOR || *endp == 0)
2461 strncpy (nstore, startp, endp-startp);
2463 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2464 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2466 nstore[endp-startp] = DIR_SEPARATOR;
2467 nstore[endp-startp+1] = 0;
2470 nstore[endp-startp] = 0;
2471 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2475 endp = startp = endp + 1;
2482 /* Convert new-style -- options to old-style. */
2483 translate_options (&argc, &argv);
2485 #ifdef LANG_SPECIFIC_DRIVER
2486 /* Do language-specific adjustment/addition of flags. */
2487 lang_specific_driver (fatal, &argc, &argv);
2490 /* Scan argv twice. Here, the first time, just count how many switches
2491 there will be in their vector, and how many input files in theirs.
2492 Here we also parse the switches that cc itself uses (e.g. -v). */
2494 for (i = 1; i < argc; i++)
2496 if (! strcmp (argv[i], "-dumpspecs"))
2498 struct spec_list *sl;
2500 for (sl = specs; sl; sl = sl->next)
2501 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2504 else if (! strcmp (argv[i], "-dumpversion"))
2506 printf ("%s\n", version_string);
2509 else if (! strcmp (argv[i], "-dumpmachine"))
2511 printf ("%s\n", spec_machine);
2514 else if (! strcmp (argv[i], "-print-search-dirs"))
2515 print_search_dirs = 1;
2516 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2517 print_file_name = "libgcc.a";
2518 else if (! strncmp (argv[i], "-print-file-name=", 17))
2519 print_file_name = argv[i] + 17;
2520 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2521 print_prog_name = argv[i] + 17;
2522 else if (! strcmp (argv[i], "-print-multi-lib"))
2523 print_multi_lib = 1;
2524 else if (! strcmp (argv[i], "-print-multi-directory"))
2525 print_multi_directory = 1;
2526 else if (! strncmp (argv[i], "-Wa,", 4))
2529 /* Pass the rest of this option to the assembler. */
2531 n_assembler_options++;
2532 if (!assembler_options)
2534 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2537 = (char **) xrealloc (assembler_options,
2538 n_assembler_options * sizeof (char **));
2540 /* Split the argument at commas. */
2542 for (j = 4; argv[i][j]; j++)
2543 if (argv[i][j] == ',')
2545 assembler_options[n_assembler_options - 1]
2546 = save_string (argv[i] + prev, j - prev);
2547 n_assembler_options++;
2549 = (char **) xrealloc (assembler_options,
2550 n_assembler_options * sizeof (char **));
2553 /* Record the part after the last comma. */
2554 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2556 else if (! strncmp (argv[i], "-Wp,", 4))
2559 /* Pass the rest of this option to the preprocessor. */
2561 n_preprocessor_options++;
2562 if (!preprocessor_options)
2563 preprocessor_options
2564 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2566 preprocessor_options
2567 = (char **) xrealloc (preprocessor_options,
2568 n_preprocessor_options * sizeof (char **));
2570 /* Split the argument at commas. */
2572 for (j = 4; argv[i][j]; j++)
2573 if (argv[i][j] == ',')
2575 preprocessor_options[n_preprocessor_options - 1]
2576 = save_string (argv[i] + prev, j - prev);
2577 n_preprocessor_options++;
2578 preprocessor_options
2579 = (char **) xrealloc (preprocessor_options,
2580 n_preprocessor_options * sizeof (char **));
2583 /* Record the part after the last comma. */
2584 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2586 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2587 /* The +e options to the C++ front-end. */
2589 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2592 /* Split the argument at commas. */
2593 for (j = 3; argv[i][j]; j++)
2594 n_infiles += (argv[i][j] == ',');
2596 else if (strcmp (argv[i], "-Xlinker") == 0)
2599 fatal ("argument to `-Xlinker' is missing");
2604 else if (strncmp (argv[i], "-l", 2) == 0)
2606 else if (strcmp (argv[i], "-save-temps") == 0)
2608 save_temps_flag = 1;
2611 else if (strcmp (argv[i], "-specs") == 0)
2613 struct user_specs *user = (struct user_specs *)
2614 xmalloc (sizeof (struct user_specs));
2616 fatal ("argument to `-specs' is missing");
2618 user->next = (struct user_specs *)0;
2619 user->filename = argv[i];
2620 if (user_specs_tail)
2621 user_specs_tail->next = user;
2623 user_specs_head = user;
2624 user_specs_tail = user;
2626 else if (strncmp (argv[i], "-specs=", 7) == 0)
2628 struct user_specs *user = (struct user_specs *)
2629 xmalloc (sizeof (struct user_specs));
2630 if (strlen (argv[i]) == 7)
2631 fatal ("argument to `-specs=' is missing");
2633 user->next = (struct user_specs *)0;
2634 user->filename = argv[i]+7;
2635 if (user_specs_tail)
2636 user_specs_tail->next = user;
2638 user_specs_head = user;
2639 user_specs_tail = user;
2641 else if (argv[i][0] == '-' && argv[i][1] != 0)
2643 register char *p = &argv[i][1];
2644 register int c = *p;
2650 if (p[1] == 0 && i + 1 == argc)
2651 fatal ("argument to `-b' is missing");
2653 spec_machine = argv[++i];
2655 spec_machine = p + 1;
2657 warn_std_ptr = &warn_std;
2663 if (p[1] == 0 && i + 1 == argc)
2664 fatal ("argument to `-B' is missing");
2669 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2670 add_prefix (&startfile_prefixes, value, NULL_PTR,
2672 add_prefix (&include_prefixes, concat (value, "include",
2674 NULL_PTR, 1, 0, NULL_PTR);
2676 /* As a kludge, if the arg is "[foo/]stageN/", just add
2677 "[foo/]include" to the include prefix. */
2679 int len = strlen (value);
2682 && (value[len - 8] == '/'
2683 || value[len - 8] == DIR_SEPARATOR)))
2684 && strncmp (value + len - 7, "stage", 5) == 0
2685 && ISDIGIT (value[len - 2])
2686 && (value[len - 1] == '/'
2687 || value[len - 1] == DIR_SEPARATOR))
2690 add_prefix (&include_prefixes, "include", NULL_PTR,
2694 char *string = xmalloc (len + 1);
2695 strncpy (string, value, len-7);
2696 strcpy (string+len-7, "include");
2697 add_prefix (&include_prefixes, string, NULL_PTR,
2706 case 'v': /* Print our subcommands and print versions. */
2708 /* If they do anything other than exactly `-v', don't set
2709 verbose_flag; rather, continue on to give the error. */
2717 if (p[1] == 0 && i + 1 == argc)
2718 fatal ("argument to `-V' is missing");
2720 spec_version = argv[++i];
2722 spec_version = p + 1;
2723 compiler_version = spec_version;
2724 warn_std_ptr = &warn_std;
2738 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2739 argv[i] = convert_filename (argv[i], 1);
2741 argv[i+1] = convert_filename (argv[i+1], 1);
2749 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2750 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2751 else if (WORD_SWITCH_TAKES_ARG (p))
2752 i += WORD_SWITCH_TAKES_ARG (p);
2762 if (have_c && have_o && lang_n_infiles > 1)
2763 fatal ("cannot specify -o with -c and multiple compilations");
2765 /* Set up the search paths before we go looking for config files. */
2767 /* These come before the md prefixes so that we will find gcc's subcommands
2768 (such as cpp) rather than those of the host system. */
2769 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2770 as well as trying the machine and the version. */
2772 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
2773 0, 2, warn_std_ptr);
2774 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
2775 0, 2, warn_std_ptr);
2778 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
2779 0, 1, warn_std_ptr);
2780 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
2781 0, 1, warn_std_ptr);
2783 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
2784 dir_separator_str, NULL_PTR);
2786 /* If tooldir is relative, base it on exec_prefixes. A relative
2787 tooldir lets us move the installed tree as a unit.
2789 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2790 directories, so that we can search both the user specified directory
2791 and the standard place. */
2793 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2795 if (gcc_exec_prefix)
2797 char *gcc_exec_tooldir_prefix
2798 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2799 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2801 add_prefix (&exec_prefixes,
2802 concat (gcc_exec_tooldir_prefix, "bin",
2803 dir_separator_str, NULL_PTR),
2804 NULL_PTR, 0, 0, NULL_PTR);
2805 add_prefix (&startfile_prefixes,
2806 concat (gcc_exec_tooldir_prefix, "lib",
2807 dir_separator_str, NULL_PTR),
2808 NULL_PTR, 0, 0, NULL_PTR);
2811 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2812 dir_separator_str, spec_version,
2813 dir_separator_str, tooldir_prefix, NULL_PTR);
2816 add_prefix (&exec_prefixes,
2817 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2818 "BINUTILS", 0, 0, NULL_PTR);
2819 add_prefix (&startfile_prefixes,
2820 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2821 "BINUTILS", 0, 0, NULL_PTR);
2823 /* More prefixes are enabled in main, after we read the specs file
2824 and determine whether this is cross-compilation or not. */
2827 /* Then create the space for the vectors and scan again. */
2829 switches = ((struct switchstr *)
2830 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2831 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2834 last_language_n_infiles = -1;
2836 /* This, time, copy the text of each switch and store a pointer
2837 to the copy in the vector of switches.
2838 Store all the infiles in their vector. */
2840 for (i = 1; i < argc; i++)
2842 /* Just skip the switches that were handled by the preceding loop. */
2843 if (! strncmp (argv[i], "-Wa,", 4))
2845 else if (! strncmp (argv[i], "-Wp,", 4))
2847 else if (! strcmp (argv[i], "-print-search-dirs"))
2849 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2851 else if (! strncmp (argv[i], "-print-file-name=", 17))
2853 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2855 else if (! strcmp (argv[i], "-print-multi-lib"))
2857 else if (! strcmp (argv[i], "-print-multi-directory"))
2859 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2861 /* Compensate for the +e options to the C++ front-end;
2862 they're there simply for cfront call-compatibility. We do
2863 some magic in default_compilers to pass them down properly.
2864 Note we deliberately start at the `+' here, to avoid passing
2865 -e0 or -e1 down into the linker. */
2866 switches[n_switches].part1 = &argv[i][0];
2867 switches[n_switches].args = 0;
2868 switches[n_switches].live_cond = 0;
2869 switches[n_switches].valid = 0;
2872 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2875 /* Split the argument at commas. */
2877 for (j = 4; argv[i][j]; j++)
2878 if (argv[i][j] == ',')
2880 infiles[n_infiles].language = 0;
2881 infiles[n_infiles++].name
2882 = save_string (argv[i] + prev, j - prev);
2885 /* Record the part after the last comma. */
2886 infiles[n_infiles].language = 0;
2887 infiles[n_infiles++].name = argv[i] + prev;
2889 else if (strcmp (argv[i], "-Xlinker") == 0)
2891 infiles[n_infiles].language = 0;
2892 infiles[n_infiles++].name = argv[++i];
2894 else if (strncmp (argv[i], "-l", 2) == 0)
2896 infiles[n_infiles].language = 0;
2897 infiles[n_infiles++].name = argv[i];
2899 else if (strcmp (argv[i], "-specs") == 0)
2901 else if (strncmp (argv[i], "-specs=", 7) == 0)
2903 /* -save-temps overrides -pipe, so that temp files are produced */
2904 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
2905 error ("Warning: -pipe ignored since -save-temps specified");
2906 else if (argv[i][0] == '-' && argv[i][1] != 0)
2908 register char *p = &argv[i][1];
2909 register int c = *p;
2913 if (p[1] == 0 && i + 1 == argc)
2914 fatal ("argument to `-x' is missing");
2916 spec_lang = argv[++i];
2919 if (! strcmp (spec_lang, "none"))
2920 /* Suppress the warning if -xnone comes after the last input
2921 file, because alternate command interfaces like g++ might
2922 find it useful to place -xnone after each input file. */
2925 last_language_n_infiles = n_infiles;
2928 switches[n_switches].part1 = p;
2929 /* Deal with option arguments in separate argv elements. */
2930 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2931 || WORD_SWITCH_TAKES_ARG (p))
2934 int n_args = WORD_SWITCH_TAKES_ARG (p);
2938 /* Count only the option arguments in separate argv elements. */
2939 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2941 if (i + n_args >= argc)
2942 fatal ("argument to `-%s' is missing", p);
2943 switches[n_switches].args
2944 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2946 switches[n_switches].args[j++] = argv[++i];
2947 /* Null-terminate the vector. */
2948 switches[n_switches].args[j] = 0;
2950 else if (index (switches_need_spaces, c))
2952 /* On some systems, ld cannot handle some options without
2953 a space. So split the option from its argument. */
2954 char *part1 = (char *) xmalloc (2);
2958 switches[n_switches].part1 = part1;
2959 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2960 switches[n_switches].args[0] = xmalloc (strlen (p));
2961 strcpy (switches[n_switches].args[0], &p[1]);
2962 switches[n_switches].args[1] = 0;
2965 switches[n_switches].args = 0;
2967 switches[n_switches].live_cond = 0;
2968 switches[n_switches].valid = 0;
2969 /* This is always valid, since gcc.c itself understands it. */
2970 if (!strcmp (p, "save-temps"))
2971 switches[n_switches].valid = 1;
2974 char ch = switches[n_switches].part1[0];
2975 if (ch == 'V' || ch == 'b' || ch == 'B')
2976 switches[n_switches].valid = 1;
2982 #ifdef HAVE_OBJECT_SUFFIX
2983 argv[i] = convert_filename (argv[i], 0);
2986 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
2988 perror_with_name (argv[i]);
2993 infiles[n_infiles].language = spec_lang;
2994 infiles[n_infiles++].name = argv[i];
2999 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3000 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3002 switches[n_switches].part1 = 0;
3003 infiles[n_infiles].name = 0;
3006 /* Process a spec string, accumulating and running commands. */
3008 /* These variables describe the input file name.
3009 input_file_number is the index on outfiles of this file,
3010 so that the output file name can be stored for later use by %o.
3011 input_basename is the start of the part of the input file
3012 sans all directory names, and basename_length is the number
3013 of characters starting there excluding the suffix .c or whatever. */
3015 static char *input_filename;
3016 static int input_file_number;
3017 static int input_filename_length;
3018 static int basename_length;
3019 static char *input_basename;
3020 static char *input_suffix;
3022 /* These are variables used within do_spec and do_spec_1. */
3024 /* Nonzero if an arg has been started and not yet terminated
3025 (with space, tab or newline). */
3026 static int arg_going;
3028 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3029 is a temporary file name. */
3030 static int delete_this_arg;
3032 /* Nonzero means %w has been seen; the next arg to be terminated
3033 is the output file name of this compilation. */
3034 static int this_is_output_file;
3036 /* Nonzero means %s has been seen; the next arg to be terminated
3037 is the name of a library file and we should try the standard
3038 search dirs for it. */
3039 static int this_is_library_file;
3041 /* Nonzero means that the input of this command is coming from a pipe. */
3042 static int input_from_pipe;
3044 /* Process the spec SPEC and run the commands specified therein.
3045 Returns 0 if the spec is successfully processed; -1 if failed. */
3055 delete_this_arg = 0;
3056 this_is_output_file = 0;
3057 this_is_library_file = 0;
3058 input_from_pipe = 0;
3060 value = do_spec_1 (spec, 0, NULL_PTR);
3062 /* Force out any unfinished command.
3063 If -pipe, this forces out the last command if it ended in `|'. */
3066 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3069 if (argbuf_index > 0)
3076 /* Process the sub-spec SPEC as a portion of a larger spec.
3077 This is like processing a whole spec except that we do
3078 not initialize at the beginning and we do not supply a
3079 newline by default at the end.
3080 INSWITCH nonzero means don't process %-sequences in SPEC;
3081 in this case, % is treated as an ordinary character.
3082 This is used while substituting switches.
3083 INSWITCH nonzero also causes SPC not to terminate an argument.
3085 Value is zero unless a line was finished
3086 and the command on that line reported an error. */
3089 do_spec_1 (spec, inswitch, soft_matched_part)
3092 char *soft_matched_part;
3094 register char *p = spec;
3101 /* If substituting a switch, treat all chars like letters.
3102 Otherwise, NL, SPC, TAB and % are special. */
3103 switch (inswitch ? 'a' : c)
3106 /* End of line: finish any pending argument,
3107 then run the pending command if one has been started. */
3110 obstack_1grow (&obstack, 0);
3111 string = obstack_finish (&obstack);
3112 if (this_is_library_file)
3113 string = find_file (string);
3114 store_arg (string, delete_this_arg, this_is_output_file);
3115 if (this_is_output_file)
3116 outfiles[input_file_number] = string;
3120 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3122 for (i = 0; i < n_switches; i++)
3123 if (!strcmp (switches[i].part1, "pipe"))
3126 /* A `|' before the newline means use a pipe here,
3127 but only if -pipe was specified.
3128 Otherwise, execute now and don't pass the `|' as an arg. */
3131 input_from_pipe = 1;
3132 switches[i].valid = 1;
3139 if (argbuf_index > 0)
3145 /* Reinitialize for a new command, and for a new argument. */
3148 delete_this_arg = 0;
3149 this_is_output_file = 0;
3150 this_is_library_file = 0;
3151 input_from_pipe = 0;
3155 /* End any pending argument. */
3158 obstack_1grow (&obstack, 0);
3159 string = obstack_finish (&obstack);
3160 if (this_is_library_file)
3161 string = find_file (string);
3162 store_arg (string, delete_this_arg, this_is_output_file);
3163 if (this_is_output_file)
3164 outfiles[input_file_number] = string;
3168 obstack_1grow (&obstack, c);
3174 /* Space or tab ends an argument if one is pending. */
3177 obstack_1grow (&obstack, 0);
3178 string = obstack_finish (&obstack);
3179 if (this_is_library_file)
3180 string = find_file (string);
3181 store_arg (string, delete_this_arg, this_is_output_file);
3182 if (this_is_output_file)
3183 outfiles[input_file_number] = string;
3185 /* Reinitialize for a new argument. */
3187 delete_this_arg = 0;
3188 this_is_output_file = 0;
3189 this_is_library_file = 0;
3196 fatal ("Invalid specification! Bug in cc.");
3199 obstack_grow (&obstack, input_basename, basename_length);
3204 delete_this_arg = 2;
3207 /* Dump out the directories specified with LIBRARY_PATH,
3208 followed by the absolute directories
3209 that we search for startfiles. */
3212 struct prefix_list *pl = startfile_prefixes.plist;
3214 char *buffer = (char *) xmalloc (bufsize);
3217 for (; pl; pl = pl->next)
3219 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3220 /* Used on systems which record the specified -L dirs
3221 and use them to search for dynamic linking. */
3222 /* Relative directories always come from -B,
3223 and it is better not to use them for searching
3224 at run time. In particular, stage1 loses */
3225 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3228 /* Try subdirectory if there is one. */
3229 if (multilib_dir != NULL)
3233 if (strlen (pl->prefix) + strlen (machine_suffix)
3235 bufsize = (strlen (pl->prefix)
3236 + strlen (machine_suffix)) * 2 + 1;
3237 buffer = (char *) xrealloc (buffer, bufsize);
3238 strcpy (buffer, pl->prefix);
3239 strcat (buffer, machine_suffix);
3240 if (is_directory (buffer, multilib_dir, 1))
3242 do_spec_1 ("-L", 0, NULL_PTR);
3243 #ifdef SPACE_AFTER_L_OPTION
3244 do_spec_1 (" ", 0, NULL_PTR);
3246 do_spec_1 (buffer, 1, NULL_PTR);
3247 do_spec_1 (multilib_dir, 1, NULL_PTR);
3248 /* Make this a separate argument. */
3249 do_spec_1 (" ", 0, NULL_PTR);
3252 if (!pl->require_machine_suffix)
3254 if (is_directory (pl->prefix, multilib_dir, 1))
3256 do_spec_1 ("-L", 0, NULL_PTR);
3257 #ifdef SPACE_AFTER_L_OPTION
3258 do_spec_1 (" ", 0, NULL_PTR);
3260 do_spec_1 (pl->prefix, 1, NULL_PTR);
3261 do_spec_1 (multilib_dir, 1, NULL_PTR);
3262 /* Make this a separate argument. */
3263 do_spec_1 (" ", 0, NULL_PTR);
3269 if (is_directory (pl->prefix, machine_suffix, 1))
3271 do_spec_1 ("-L", 0, NULL_PTR);
3272 #ifdef SPACE_AFTER_L_OPTION
3273 do_spec_1 (" ", 0, NULL_PTR);
3275 do_spec_1 (pl->prefix, 1, NULL_PTR);
3276 /* Remove slash from machine_suffix. */
3277 if (strlen (machine_suffix) >= bufsize)
3278 bufsize = strlen (machine_suffix) * 2 + 1;
3279 buffer = (char *) xrealloc (buffer, bufsize);
3280 strcpy (buffer, machine_suffix);
3281 idx = strlen (buffer);
3282 if (buffer[idx - 1] == '/'
3283 || buffer[idx - 1] == DIR_SEPARATOR)
3284 buffer[idx - 1] = 0;
3285 do_spec_1 (buffer, 1, NULL_PTR);
3286 /* Make this a separate argument. */
3287 do_spec_1 (" ", 0, NULL_PTR);
3290 if (!pl->require_machine_suffix)
3292 if (is_directory (pl->prefix, "", 1))
3294 do_spec_1 ("-L", 0, NULL_PTR);
3295 #ifdef SPACE_AFTER_L_OPTION
3296 do_spec_1 (" ", 0, NULL_PTR);
3298 /* Remove slash from pl->prefix. */
3299 if (strlen (pl->prefix) >= bufsize)
3300 bufsize = strlen (pl->prefix) * 2 + 1;
3301 buffer = (char *) xrealloc (buffer, bufsize);
3302 strcpy (buffer, pl->prefix);
3303 idx = strlen (buffer);
3304 if (buffer[idx - 1] == '/'
3305 || buffer[idx - 1] == DIR_SEPARATOR)
3306 buffer[idx - 1] = 0;
3307 do_spec_1 (buffer, 1, NULL_PTR);
3308 /* Make this a separate argument. */
3309 do_spec_1 (" ", 0, NULL_PTR);
3318 /* {...:%efoo} means report an error with `foo' as error message
3319 and don't execute any more commands for this file. */
3323 while (*p != 0 && *p != '\n') p++;
3324 buf = (char *) alloca (p - q + 1);
3325 strncpy (buf, q, p - q);
3335 if (save_temps_flag)
3337 obstack_grow (&obstack, input_basename, basename_length);
3338 delete_this_arg = 0;
3342 #ifdef MKTEMP_EACH_FILE
3343 /* ??? This has a problem: the total number of
3344 values mktemp can return is limited.
3345 That matters for the names of object files.
3346 In 2.4, do something about that. */
3347 struct temp_name *t;
3349 while (*p == '.' || ISALPHA (*p)
3350 || (p[0] == '%' && p[1] == 'O'))
3353 /* See if we already have an association of %g/%u/%U and
3355 for (t = temp_names; t; t = t->next)
3356 if (t->length == p - suffix
3357 && strncmp (t->suffix, suffix, p - suffix) == 0
3358 && t->unique == (c != 'g'))
3361 /* Make a new association if needed. %u requires one. */
3362 if (t == 0 || c == 'u')
3366 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3367 t->next = temp_names;
3370 t->length = p - suffix;
3371 t->suffix = save_string (suffix, p - suffix);
3372 t->unique = (c != 'g');
3373 temp_filename = choose_temp_base ();
3374 temp_filename_length = strlen (temp_filename);
3375 t->filename = temp_filename;
3376 t->filename_length = temp_filename_length;
3379 obstack_grow (&obstack, t->filename, t->filename_length);
3380 delete_this_arg = 1;
3382 obstack_grow (&obstack, temp_filename, temp_filename_length);
3383 if (c == 'u' || c == 'U')
3389 sprintf (buff, "%d", unique);
3390 obstack_grow (&obstack, buff, strlen (buff));
3393 delete_this_arg = 1;
3399 obstack_grow (&obstack, input_filename, input_filename_length);
3405 struct prefix_list *pl = include_prefixes.plist;
3407 if (gcc_exec_prefix)
3409 do_spec_1 ("-iprefix", 1, NULL_PTR);
3410 /* Make this a separate argument. */
3411 do_spec_1 (" ", 0, NULL_PTR);
3412 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3413 do_spec_1 (" ", 0, NULL_PTR);
3416 for (; pl; pl = pl->next)
3418 do_spec_1 ("-isystem", 1, NULL_PTR);
3419 /* Make this a separate argument. */
3420 do_spec_1 (" ", 0, NULL_PTR);
3421 do_spec_1 (pl->prefix, 1, NULL_PTR);
3422 do_spec_1 (" ", 0, NULL_PTR);
3428 for (i = 0; i < n_infiles; i++)
3429 store_arg (outfiles[i], 0, 0);
3433 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3438 this_is_library_file = 1;
3442 this_is_output_file = 1;
3447 int cur_index = argbuf_index;
3448 /* Handle the {...} following the %W. */
3451 p = handle_braces (p + 1);
3454 /* If any args were output, mark the last one for deletion
3456 if (argbuf_index != cur_index)
3457 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3461 /* %x{OPTION} records OPTION for %X to output. */
3467 /* Skip past the option value and make a copy. */
3472 string = save_string (p1 + 1, p - p1 - 2);
3474 /* See if we already recorded this option. */
3475 for (i = 0; i < n_linker_options; i++)
3476 if (! strcmp (string, linker_options[i]))
3482 /* This option is new; add it. */
3484 if (!linker_options)
3486 = (char **) xmalloc (n_linker_options * sizeof (char **));
3489 = (char **) xrealloc (linker_options,
3490 n_linker_options * sizeof (char **));
3492 linker_options[n_linker_options - 1] = string;
3496 /* Dump out the options accumulated previously using %x. */
3498 for (i = 0; i < n_linker_options; i++)
3500 do_spec_1 (linker_options[i], 1, NULL_PTR);
3501 /* Make each accumulated option a separate argument. */
3502 do_spec_1 (" ", 0, NULL_PTR);
3506 /* Dump out the options accumulated previously using -Wa,. */
3508 for (i = 0; i < n_assembler_options; i++)
3510 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3511 /* Make each accumulated option a separate argument. */
3512 do_spec_1 (" ", 0, NULL_PTR);
3516 /* Dump out the options accumulated previously using -Wp,. */
3518 for (i = 0; i < n_preprocessor_options; i++)
3520 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3521 /* Make each accumulated option a separate argument. */
3522 do_spec_1 (" ", 0, NULL_PTR);
3526 /* Here are digits and numbers that just process
3527 a certain constant string as a spec. */
3530 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3536 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3542 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3548 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3554 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3560 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3566 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3572 value = do_spec_1 (link_spec, 0, NULL_PTR);
3578 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3584 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3591 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3595 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3599 if (! strncmp (y, "-D", 2))
3600 /* Copy the whole option. */
3601 while (*y && *y != ' ' && *y != '\t')
3603 else if (*y == ' ' || *y == '\t')
3604 /* Copy whitespace to the result. */
3606 /* Don't copy other options. */
3613 value = do_spec_1 (buf, 0, NULL_PTR);
3621 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3625 /* Copy all of CPP_PREDEFINES into BUF,
3626 but put __ after every -D and at the end of each arg. */
3630 if (! strncmp (y, "-D", 2))
3638 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3640 /* Stick __ at front of macro name. */
3643 /* Arrange to stick __ at the end as well. */
3647 /* Copy the macro name. */
3648 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3657 /* Copy the value given, if any. */
3658 while (*y && *y != ' ' && *y != '\t')
3661 else if (*y == ' ' || *y == '\t')
3662 /* Copy whitespace to the result. */
3664 /* Don't copy -A options */
3670 /* Copy all of CPP_PREDEFINES into BUF,
3671 but put __ after every -D. */
3675 if (! strncmp (y, "-D", 2))
3680 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3682 /* Stick -D__ at front of macro name. */
3688 /* Copy the macro name. */
3689 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3692 /* Copy the value given, if any. */
3693 while (*y && *y != ' ' && *y != '\t')
3698 /* Do not copy this macro - we have just done it before */
3699 while (*y && *y != ' ' && *y != '\t')
3703 else if (*y == ' ' || *y == '\t')
3704 /* Copy whitespace to the result. */
3706 /* Don't copy -A options */
3712 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3716 if (! strncmp (y, "-A", 2))
3717 /* Copy the whole option. */
3718 while (*y && *y != ' ' && *y != '\t')
3720 else if (*y == ' ' || *y == '\t')
3721 /* Copy whitespace to the result. */
3723 /* Don't copy other options. */
3730 value = do_spec_1 (buf, 0, NULL_PTR);
3737 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3742 /* Here we define characters other than letters and digits. */
3745 p = handle_braces (p);
3751 obstack_1grow (&obstack, '%');
3755 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3756 do_spec_1 (" ", 0, NULL_PTR);
3759 /* Process a string found as the value of a spec given by name.
3760 This feature allows individual machine descriptions
3761 to add and use their own specs.
3762 %[...] modifies -D options the way %P does;
3763 %(...) uses the spec unmodified. */
3768 struct spec_list *sl;
3771 /* The string after the S/P is the name of a spec that is to be
3773 while (*p && *p != ')' && *p != ']')
3776 /* See if it's in the list */
3777 for (len = p - name, sl = specs; sl; sl = sl->next)
3778 if (sl->name_len == len && !strncmp (sl->name, name, len))
3780 name = *(sl->ptr_spec);
3782 fprintf (stderr, "Processing spec %c%s%c, which is '%s'\n",
3783 c, sl->name, (c == '(') ? ')' : ']', name);
3792 value = do_spec_1 (name, 0, NULL_PTR);
3798 char *x = (char *) alloca (strlen (name) * 2 + 1);
3802 /* Copy all of NAME into BUF, but put __ after
3803 every -D and at the end of each arg, */
3808 if (! strncmp (y, "-D", 2))
3818 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
3819 || *y == '}' || *y == 0))
3832 value = do_spec_1 (buf, 0, NULL_PTR);
3838 /* Discard the closing paren or bracket. */
3846 int c1 = *p++; /* Select first or second version number. */
3847 char *v = compiler_version;
3850 /* The format of the version string is
3851 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3853 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3854 while (! ISDIGIT (*v))
3856 if (v > compiler_version && v[-1] != '-')
3859 /* If desired, advance to second version number. */
3862 /* Set V after the first period. */
3863 while (ISDIGIT (*v))
3870 /* Set Q at the next period or at the end. */
3872 while (ISDIGIT (*q))
3874 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3877 /* Put that part into the command. */
3878 obstack_grow (&obstack, v, q - v);
3884 if (input_from_pipe)
3885 do_spec_1 ("-", 0, NULL_PTR);
3894 /* Backslash: treat next character as ordinary. */
3899 /* Ordinary character: put it into the current argument. */
3900 obstack_1grow (&obstack, c);
3904 return 0; /* End of string */
3907 /* Return 0 if we call do_spec_1 and that returns -1. */
3918 int include_blanks = 1;
3921 /* A '^' after the open-brace means to not give blanks before args. */
3922 include_blanks = 0, ++p;
3925 /* A `|' after the open-brace means,
3926 if the test fails, output a single minus sign rather than nothing.
3927 This is used in %{|!pipe:...}. */
3931 /* A `!' after the open-brace negates the condition:
3932 succeed if the specified switch is not present. */
3936 /* A `.' after the open-brace means test against the current suffix. */
3946 while (*p != ':' && *p != '}') p++;
3949 register int count = 1;
3967 int found = (input_suffix != 0
3968 && strlen (input_suffix) == p - filter
3969 && strncmp (input_suffix, filter, p - filter) == 0);
3975 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3980 else if (p[-1] == '*' && p[0] == '}')
3982 /* Substitute all matching switches as separate args. */
3985 for (i = 0; i < n_switches; i++)
3986 if (!strncmp (switches[i].part1, filter, p - filter)
3987 && check_live_switch (i, p - filter))
3988 give_switch (i, 0, include_blanks);
3992 /* Test for presence of the specified switch. */
3996 /* If name specified ends in *, as in {x*:...},
3997 check for %* and handle that case. */
3998 if (p[-1] == '*' && !negate)
4003 /* First see whether we have %*. */
4007 if (*r == '%' && r[1] == '*')
4011 /* If we do, handle that case. */
4014 /* Substitute all matching switches as separate args.
4015 But do this by substituting for %*
4016 in the text that follows the colon. */
4018 unsigned hard_match_len = p - filter - 1;
4019 char *string = save_string (p + 1, q - p - 2);
4021 for (i = 0; i < n_switches; i++)
4022 if (!strncmp (switches[i].part1, filter, hard_match_len)
4023 && check_live_switch (i, -1))
4025 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4026 /* Pass any arguments this switch has. */
4027 give_switch (i, 1, 1);
4034 /* If name specified ends in *, as in {x*:...},
4035 check for presence of any switch name starting with x. */
4038 for (i = 0; i < n_switches; i++)
4040 unsigned hard_match_len = p - filter - 1;
4042 if (!strncmp (switches[i].part1, filter, hard_match_len)
4043 && check_live_switch (i, hard_match_len))
4049 /* Otherwise, check for presence of exact name specified. */
4052 for (i = 0; i < n_switches; i++)
4054 if (!strncmp (switches[i].part1, filter, p - filter)
4055 && switches[i].part1[p - filter] == 0
4056 && check_live_switch (i, -1))
4064 /* If it is as desired (present for %{s...}, absent for %{-s...})
4065 then substitute either the switch or the specified
4066 conditional text. */
4067 if (present != negate)
4071 give_switch (i, 0, include_blanks);
4075 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4081 /* Here if a %{|...} conditional fails: output a minus sign,
4082 which means "standard output" or "standard input". */
4083 do_spec_1 ("-", 0, NULL_PTR);
4090 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4091 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4092 spec, or -1 if either exact match or %* is used.
4094 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4095 whose value does not begin with "no-" is obsoleted by the same value
4096 with the "no-", similarly for a switch with the "no-" prefix. */
4099 check_live_switch (switchnum, prefix_length)
4103 char *name = switches[switchnum].part1;
4106 /* In the common case of {<at-most-one-letter>*}, a negating
4107 switch would always match, so ignore that case. We will just
4108 send the conflicting switches to the compiler phase. */
4109 if (prefix_length >= 0 && prefix_length <= 1)
4112 /* If we already processed this switch and determined if it was
4113 live or not, return our past determination. */
4114 if (switches[switchnum].live_cond != 0)
4115 return switches[switchnum].live_cond > 0;
4117 /* Now search for duplicate in a manner that depends on the name. */
4121 for (i = switchnum + 1; i < n_switches; i++)
4122 if (switches[i].part1[0] == 'O')
4124 switches[switchnum].valid = 1;
4125 switches[switchnum].live_cond = -1;
4130 case 'W': case 'f': case 'm':
4131 if (! strncmp (name + 1, "no-", 3))
4133 /* We have Xno-YYY, search for XYYY. */
4134 for (i = switchnum + 1; i < n_switches; i++)
4135 if (switches[i].part1[0] == name[0]
4136 && ! strcmp (&switches[i].part1[1], &name[4]))
4138 switches[switchnum].valid = 1;
4139 switches[switchnum].live_cond = -1;
4145 /* We have XYYY, search for Xno-YYY. */
4146 for (i = switchnum + 1; i < n_switches; i++)
4147 if (switches[i].part1[0] == name[0]
4148 && switches[i].part1[1] == 'n'
4149 && switches[i].part1[2] == 'o'
4150 && switches[i].part1[3] == '-'
4151 && !strcmp (&switches[i].part1[4], &name[1]))
4153 switches[switchnum].valid = 1;
4154 switches[switchnum].live_cond = -1;
4161 /* Otherwise the switch is live. */
4162 switches[switchnum].live_cond = 1;
4166 /* Pass a switch to the current accumulating command
4167 in the same form that we received it.
4168 SWITCHNUM identifies the switch; it is an index into
4169 the vector of switches gcc received, which is `switches'.
4170 This cannot fail since it never finishes a command line.
4172 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4174 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4178 give_switch (switchnum, omit_first_word, include_blanks)
4180 int omit_first_word;
4183 if (!omit_first_word)
4185 do_spec_1 ("-", 0, NULL_PTR);
4186 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4189 if (switches[switchnum].args != 0)
4192 for (p = switches[switchnum].args; *p; p++)
4195 do_spec_1 (" ", 0, NULL_PTR);
4196 do_spec_1 (*p, 1, NULL_PTR);
4200 do_spec_1 (" ", 0, NULL_PTR);
4201 switches[switchnum].valid = 1;
4204 /* Search for a file named NAME trying various prefixes including the
4205 user's -B prefix and some standard ones.
4206 Return the absolute file name found. If nothing is found, return NAME. */
4214 /* Try multilib_dir if it is defined. */
4215 if (multilib_dir != NULL)
4219 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4220 strcpy (try, multilib_dir);
4221 strcat (try, dir_separator_str);
4224 newname = find_a_file (&startfile_prefixes, try, R_OK);
4226 /* If we don't find it in the multi library dir, then fall
4227 through and look for it in the normal places. */
4228 if (newname != NULL)
4232 newname = find_a_file (&startfile_prefixes, name, R_OK);
4233 return newname ? newname : name;
4236 /* Determine whether a directory exists. If LINKER, return 0 for
4237 certain fixed names not needed by the linker. If not LINKER, it is
4238 only important to return 0 if the host machine has a small ARG_MAX
4242 is_directory (path1, path2, linker)
4247 int len1 = strlen (path1);
4248 int len2 = strlen (path2);
4249 char *path = (char *) alloca (3 + len1 + len2);
4253 #ifndef SMALL_ARG_MAX
4258 /* Construct the path from the two parts. Ensure the string ends with "/.".
4259 The resulting path will be a directory even if the given path is a
4261 bcopy (path1, path, len1);
4262 bcopy (path2, path + len1, len2);
4263 cp = path + len1 + len2;
4264 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4265 *cp++ = DIR_SEPARATOR;
4269 /* Exclude directories that the linker is known to search. */
4272 && strcmp (path, concat (dir_separator_str, "lib",
4273 dir_separator_str, ".", NULL_PTR)) == 0)
4275 && strcmp (path, concat (dir_separator_str, "usr",
4276 dir_separator_str, "lib",
4277 dir_separator_str, ".", NULL_PTR)) == 0)))
4280 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4283 /* On fatal signals, delete all the temporary files. */
4286 fatal_error (signum)
4289 signal (signum, SIG_DFL);
4290 delete_failure_queue ();
4291 delete_temp_files ();
4292 /* Get the same signal again, this time not handled,
4293 so its normal effect occurs. */
4294 kill (getpid (), signum);
4305 int linker_was_run = 0;
4306 char *explicit_link_files;
4309 struct user_specs *uptr;
4311 p = argv[0] + strlen (argv[0]);
4312 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4315 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4316 signal (SIGINT, fatal_error);
4318 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4319 signal (SIGHUP, fatal_error);
4321 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4322 signal (SIGTERM, fatal_error);
4324 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4325 signal (SIGPIPE, fatal_error);
4329 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4331 obstack_init (&obstack);
4333 /* Build multilib_select, et. al from the separate lines that make up each
4334 multilib selection. */
4336 char **q = multilib_raw;
4339 obstack_init (&multilib_obstack);
4340 while ((p = *q++) != (char *) 0)
4341 obstack_grow (&multilib_obstack, p, strlen (p));
4343 obstack_1grow (&multilib_obstack, 0);
4344 multilib_select = obstack_finish (&multilib_obstack);
4346 q = multilib_matches_raw;
4347 while ((p = *q++) != (char *) 0)
4348 obstack_grow (&multilib_obstack, p, strlen (p));
4350 obstack_1grow (&multilib_obstack, 0);
4351 multilib_matches = obstack_finish (&multilib_obstack);
4355 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4359 obstack_1grow (&multilib_obstack, ' ');
4360 obstack_grow (&multilib_obstack,
4361 multilib_defaults_raw[i],
4362 strlen (multilib_defaults_raw[i]));
4366 obstack_1grow (&multilib_obstack, 0);
4367 multilib_defaults = obstack_finish (&multilib_obstack);
4370 /* Set up to remember the pathname of gcc and any options
4371 needed for collect. We use argv[0] instead of programname because
4372 we need the complete pathname. */
4373 obstack_init (&collect_obstack);
4374 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4375 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4376 putenv (obstack_finish (&collect_obstack));
4378 #ifdef INIT_ENVIRONMENT
4379 /* Set up any other necessary machine specific environment variables. */
4380 putenv (INIT_ENVIRONMENT);
4383 /* Choose directory for temp files. */
4385 temp_filename = choose_temp_base ();
4386 temp_filename_length = strlen (temp_filename);
4388 /* Make a table of what switches there are (switches, n_switches).
4389 Make a table of specified input files (infiles, n_infiles).
4390 Decode switches that are handled locally. */
4392 process_command (argc, argv);
4398 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4400 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4401 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4404 for (i = 0; i < n_switches; i++)
4409 obstack_grow (&collect_obstack, " ", 1);
4412 obstack_grow (&collect_obstack, "'-", 2);
4413 q = switches[i].part1;
4414 while ((p = (char *) index (q,'\'')))
4416 obstack_grow (&collect_obstack, q, p-q);
4417 obstack_grow (&collect_obstack, "'\\''", 4);
4420 obstack_grow (&collect_obstack, q, strlen (q));
4421 obstack_grow (&collect_obstack, "'", 1);
4423 for (args = switches[i].args; args && *args; args++)
4425 obstack_grow (&collect_obstack, " '", 2);
4427 while ((p = (char *) index (q,'\'')))
4429 obstack_grow (&collect_obstack, q, p-q);
4430 obstack_grow (&collect_obstack, "'\\''", 4);
4433 obstack_grow (&collect_obstack, q, strlen (q));
4434 obstack_grow (&collect_obstack, "'", 1);
4437 obstack_grow (&collect_obstack, "\0", 1);
4438 putenv (obstack_finish (&collect_obstack));
4441 /* Initialize the vector of specs to just the default.
4442 This means one element containing 0s, as a terminator. */
4444 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4445 bcopy ((char *) default_compilers, (char *) compilers,
4446 sizeof default_compilers);
4447 n_compilers = n_default_compilers;
4449 /* Read specs from a file if there is one. */
4451 machine_suffix = concat (spec_machine, dir_separator_str,
4452 spec_version, dir_separator_str, NULL_PTR);
4453 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4455 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4456 /* Read the specs file unless it is a default one. */
4457 if (specs_file != 0 && strcmp (specs_file, "specs"))
4458 read_specs (specs_file, TRUE);
4462 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4463 for any override of as, ld and libraries. */
4464 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4465 + strlen (just_machine_suffix)
4466 + sizeof ("specs"));
4468 strcpy (specs_file, standard_exec_prefix);
4469 strcat (specs_file, just_machine_suffix);
4470 strcat (specs_file, "specs");
4471 if (access (specs_file, R_OK) == 0)
4472 read_specs (specs_file, TRUE);
4474 /* Process any user specified specs in the order given on the command
4476 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4478 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4479 read_specs (filename ? filename : uptr->filename, FALSE);
4482 /* If not cross-compiling, look for startfiles in the standard places. */
4483 /* The fact that these are done here, after reading the specs file,
4484 means that it cannot be found in these directories.
4485 But that's okay. It should never be there anyway. */
4486 if (*cross_compile == '0')
4488 #ifdef MD_EXEC_PREFIX
4489 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4490 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4493 #ifdef MD_STARTFILE_PREFIX
4494 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4498 #ifdef MD_STARTFILE_PREFIX_1
4499 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4503 /* If standard_startfile_prefix is relative, base it on
4504 standard_exec_prefix. This lets us move the installed tree
4505 as a unit. If GCC_EXEC_PREFIX is defined, base
4506 standard_startfile_prefix on that as well. */
4507 if (*standard_startfile_prefix == '/'
4508 || *standard_startfile_prefix == DIR_SEPARATOR)
4509 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4513 if (gcc_exec_prefix)
4514 add_prefix (&startfile_prefixes,
4515 concat (gcc_exec_prefix, machine_suffix,
4516 standard_startfile_prefix, NULL_PTR),
4517 NULL_PTR, 0, 0, NULL_PTR);
4518 add_prefix (&startfile_prefixes,
4519 concat (standard_exec_prefix,
4521 standard_startfile_prefix, NULL_PTR),
4522 NULL_PTR, 0, 0, NULL_PTR);
4525 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4526 "BINUTILS", 0, 0, NULL_PTR);
4527 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4528 "BINUTILS", 0, 0, NULL_PTR);
4529 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4530 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
4535 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4536 add_prefix (&startfile_prefixes,
4537 concat (gcc_exec_prefix, machine_suffix,
4538 standard_startfile_prefix, NULL_PTR),
4539 "BINUTILS", 0, 0, NULL_PTR);
4542 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4543 if (gcc_exec_prefix)
4545 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4546 + strlen (spec_version)
4547 + strlen (spec_machine) + 3);
4548 strcpy (temp, gcc_exec_prefix);
4549 strcat (temp, spec_machine);
4550 strcat (temp, dir_separator_str);
4551 strcat (temp, spec_version);
4552 strcat (temp, dir_separator_str);
4553 gcc_exec_prefix = temp;
4556 /* Now we have the specs.
4557 Set the `valid' bits for switches that match anything in any spec. */
4559 validate_all_switches ();
4561 /* Now that we have the switches and the specs, set
4562 the subdirectory based on the options. */
4563 set_multilib_dir ();
4565 /* Warn about any switches that no pass was interested in. */
4567 for (i = 0; i < n_switches; i++)
4568 if (! switches[i].valid)
4569 error ("unrecognized option `-%s'", switches[i].part1);
4571 /* Obey some of the options. */
4573 if (print_search_dirs)
4575 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4576 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4577 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4581 if (print_file_name)
4583 printf ("%s\n", find_file (print_file_name));
4587 if (print_prog_name)
4589 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4590 printf ("%s\n", (newname ? newname : print_prog_name));
4594 if (print_multi_lib)
4596 print_multilib_info ();
4600 if (print_multi_directory)
4602 if (multilib_dir == NULL)
4605 printf ("%s\n", multilib_dir);
4613 /* compiler_version is truncated at the first space when initialized
4614 from version string, so truncate version_string at the first space
4615 before comparing. */
4616 for (n = 0; version_string[n]; n++)
4617 if (version_string[n] == ' ')
4620 if (! strncmp (version_string, compiler_version, n)
4621 && compiler_version[n] == 0)
4622 fprintf (stderr, "gcc version %s\n", version_string);
4624 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4625 version_string, compiler_version);
4632 fatal ("No input files");
4634 /* Make a place to record the compiler output file names
4635 that correspond to the input files. */
4637 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4638 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4640 /* Record which files were specified explicitly as link input. */
4642 explicit_link_files = xmalloc (n_infiles);
4643 bzero (explicit_link_files, n_infiles);
4645 for (i = 0; i < n_infiles; i++)
4647 register struct compiler *cp = 0;
4648 int this_file_error = 0;
4650 /* Tell do_spec what to substitute for %i. */
4652 input_filename = infiles[i].name;
4653 input_filename_length = strlen (input_filename);
4654 input_file_number = i;
4656 /* Use the same thing in %o, unless cp->spec says otherwise. */
4658 outfiles[i] = input_filename;
4660 /* Figure out which compiler from the file's suffix. */
4662 cp = lookup_compiler (infiles[i].name, input_filename_length,
4663 infiles[i].language);
4667 /* Ok, we found an applicable compiler. Run its spec. */
4668 /* First say how much of input_filename to substitute for %b */
4672 if (cp->spec[0][0] == '#')
4673 error ("%s: %s compiler not installed on this system",
4674 input_filename, &cp->spec[0][1]);
4676 input_basename = input_filename;
4677 for (p = input_filename; *p; p++)
4678 if (*p == '/' || *p == DIR_SEPARATOR)
4679 input_basename = p + 1;
4681 /* Find a suffix starting with the last period,
4682 and set basename_length to exclude that suffix. */
4683 basename_length = strlen (input_basename);
4684 p = input_basename + basename_length;
4685 while (p != input_basename && *p != '.') --p;
4686 if (*p == '.' && p != input_basename)
4688 basename_length = p - input_basename;
4689 input_suffix = p + 1;
4695 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4697 len += strlen (cp->spec[j]);
4699 p = (char *) xmalloc (len + 1);
4702 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4705 strcpy (p + len, cp->spec[j]);
4706 len += strlen (cp->spec[j]);
4709 value = do_spec (p);
4712 this_file_error = 1;
4715 /* If this file's name does not contain a recognized suffix,
4716 record it as explicit linker input. */
4719 explicit_link_files[i] = 1;
4721 /* Clear the delete-on-failure queue, deleting the files in it
4722 if this compilation failed. */
4724 if (this_file_error)
4726 delete_failure_queue ();
4729 /* If this compilation succeeded, don't delete those files later. */
4730 clear_failure_queue ();
4733 /* Run ld to link all the compiler output files. */
4735 if (error_count == 0)
4737 int tmp = execution_count;
4739 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4741 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4742 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4744 value = do_spec (link_command_spec);
4747 linker_was_run = (tmp != execution_count);
4750 /* Warn if a -B option was specified but the prefix was never used. */
4751 unused_prefix_warnings (&exec_prefixes);
4752 unused_prefix_warnings (&startfile_prefixes);
4754 /* If options said don't run linker,
4755 complain about input files to be given to the linker. */
4757 if (! linker_was_run && error_count == 0)
4758 for (i = 0; i < n_infiles; i++)
4759 if (explicit_link_files[i])
4760 error ("%s: linker input file unused since linking not done",
4763 /* Delete some or all of the temporary files we made. */
4766 delete_failure_queue ();
4767 delete_temp_files ();
4769 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4774 /* Find the proper compilation spec for the file name NAME,
4775 whose length is LENGTH. LANGUAGE is the specified language,
4776 or 0 if none specified. */
4778 static struct compiler *
4779 lookup_compiler (name, length, language)
4784 struct compiler *cp;
4786 /* Look for the language, if one is spec'd. */
4789 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4793 if (cp->suffix[0] == '@'
4794 && !strcmp (cp->suffix + 1, language))
4798 error ("language %s not recognized", language);
4801 /* Look for a suffix. */
4802 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4804 if (/* The suffix `-' matches only the file name `-'. */
4805 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4807 (strlen (cp->suffix) < length
4808 /* See if the suffix matches the end of NAME. */
4810 && (!strcmp (cp->suffix,
4811 name + length - strlen (cp->suffix))
4812 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4813 && !strcasecmp (cp->suffix,
4814 name + length - strlen (cp->suffix)))))
4816 && !strcmp (cp->suffix,
4817 name + length - strlen (cp->suffix))))
4820 if (cp->spec[0][0] == '@')
4822 struct compiler *new;
4823 /* An alias entry maps a suffix to a language.
4824 Search for the language; pass 0 for NAME and LENGTH
4825 to avoid infinite recursion if language not found.
4826 Construct the new compiler spec. */
4827 language = cp->spec[0] + 1;
4828 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4829 new->suffix = cp->suffix;
4830 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4831 (char *) new->spec, sizeof new->spec);
4834 /* A non-alias entry: return it. */
4846 register char *value = (char *) malloc (size);
4848 fatal ("virtual memory exhausted");
4853 xrealloc (ptr, size)
4857 register char *value = (char *) realloc (ptr, size);
4859 fatal ("virtual memory exhausted");
4863 /* This function is based on the one in libiberty. */
4866 concat VPROTO((char *first, ...))
4868 register int length;
4869 register char *newstr;
4877 /* First compute the size of the result and get sufficient memory. */
4879 VA_START (args, first);
4881 first = va_arg (args, char *);
4889 length += strlen (arg);
4890 arg = va_arg (args, char *);
4893 newstr = (char *) xmalloc (length + 1);
4896 /* Now copy the individual pieces to the result string. */
4898 VA_START (args, first);
4900 first = va_arg (args, char *);
4909 arg = va_arg (args, char *);
4918 save_string (s, len)
4922 register char *result = xmalloc (len + 1);
4924 bcopy (s, result, len);
4930 pfatal_with_name (name)
4933 fatal ("%s: %s", name, my_strerror (errno));
4937 perror_with_name (name)
4940 error ("%s: %s", name, my_strerror (errno));
4944 pfatal_pexecute (errmsg_fmt, errmsg_arg)
4950 /* Space for trailing '\0' is in %s. */
4951 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
4952 sprintf (msg, errmsg_fmt, errmsg_arg);
4956 fatal ("%s: %s", errmsg_fmt, my_strerror (errno));
4959 /* More 'friendly' abort that prints the line and file.
4960 config.h can #define abort fancy_abort if you like that sort of thing. */
4965 fatal ("Internal gcc abort.");
4970 /* Output an error message and exit */
4973 fatal VPROTO((char *format, ...))
4980 VA_START (ap, format);
4983 format = va_arg (ap, char *);
4986 fprintf (stderr, "%s: ", programname);
4987 vfprintf (stderr, format, ap);
4989 fprintf (stderr, "\n");
4990 delete_temp_files ();
4995 error VPROTO((char *format, ...))
5002 VA_START (ap, format);
5005 format = va_arg (ap, char *);
5008 fprintf (stderr, "%s: ", programname);
5009 vfprintf (stderr, format, ap);
5012 fprintf (stderr, "\n");
5015 #else /* not HAVE_VPRINTF */
5018 fatal (msg, arg1, arg2)
5019 char *msg, *arg1, *arg2;
5021 error (msg, arg1, arg2);
5022 delete_temp_files ();
5027 error (msg, arg1, arg2)
5028 char *msg, *arg1, *arg2;
5030 fprintf (stderr, "%s: ", programname);
5031 fprintf (stderr, msg, arg1, arg2);
5032 fprintf (stderr, "\n");
5035 #endif /* not HAVE_VPRINTF */
5039 validate_all_switches ()
5041 struct compiler *comp;
5044 struct spec_list *spec;
5046 for (comp = compilers; comp->spec[0]; comp++)
5049 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5053 if (c == '%' && *p == '{')
5054 /* We have a switch spec. */
5055 validate_switches (p + 1);
5059 /* look through the linked list of specs read from the specs file */
5060 for (spec = specs; spec ; spec = spec->next)
5062 p = *(spec->ptr_spec);
5064 if (c == '%' && *p == '{')
5065 /* We have a switch spec. */
5066 validate_switches (p + 1);
5069 p = link_command_spec;
5071 if (c == '%' && *p == '{')
5072 /* We have a switch spec. */
5073 validate_switches (p + 1);
5076 /* Look at the switch-name that comes after START
5077 and mark as valid all supplied switches that match it. */
5080 validate_switches (start)
5083 register char *p = start;
5098 while (*p != ':' && *p != '}') p++;
5102 else if (p[-1] == '*')
5104 /* Mark all matching switches as valid. */
5106 for (i = 0; i < n_switches; i++)
5107 if (!strncmp (switches[i].part1, filter, p - filter))
5108 switches[i].valid = 1;
5112 /* Mark an exact matching switch as valid. */
5113 for (i = 0; i < n_switches; i++)
5115 if (!strncmp (switches[i].part1, filter, p - filter)
5116 && switches[i].part1[p - filter] == 0)
5117 switches[i].valid = 1;
5122 /* Check whether a particular argument was used. The first time we
5123 canonicalize the switches to keep only the ones we care about. */
5137 static struct mswitchstr *mswitches;
5138 static int n_mswitches;
5143 struct mswitchstr *matches;
5147 /* Break multilib_matches into the component strings of string and replacement
5149 for (q = multilib_matches; *q != '\0'; q++)
5153 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5155 q = multilib_matches;
5166 matches[i].len = q - matches[i].str;
5168 matches[i].replace = ++q;
5169 while (*q != ';' && *q != '\0')
5175 matches[i].rep_len = q - matches[i].replace;
5183 /* Now build a list of the replacement string for switches that we care
5184 about. Make sure we allocate at least one entry. This prevents
5185 xmalloc from calling fatal, and prevents us from re-executing this
5188 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5189 * (n_switches ? n_switches : 1));
5190 for (i = 0; i < n_switches; i++)
5192 int xlen = strlen (switches[i].part1);
5193 for (j = 0; j < cnt; j++)
5194 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5196 mswitches[n_mswitches].str = matches[j].replace;
5197 mswitches[n_mswitches].len = matches[j].rep_len;
5198 mswitches[n_mswitches].replace = (char *)0;
5199 mswitches[n_mswitches].rep_len = 0;
5206 for (i = 0; i < n_mswitches; i++)
5207 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5214 default_arg (p, len)
5220 for (start = multilib_defaults; *start != '\0'; start = end+1)
5222 while (*start == ' ' || *start == '\t')
5228 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5231 if ((end - start) == len && strncmp (p, start, len) == 0)
5238 /* Work out the subdirectory to use based on the
5239 options. The format of multilib_select is a list of elements.
5240 Each element is a subdirectory name followed by a list of options
5241 followed by a semicolon. gcc will consider each line in turn. If
5242 none of the options beginning with an exclamation point are
5243 present, and all of the other options are present, that
5244 subdirectory will be used. */
5249 char *p = multilib_select;
5251 char *this_path, *this_arg;
5257 /* Ignore newlines. */
5264 /* Get the initial path. */
5272 this_path_len = p - this_path;
5274 /* Check the arguments. */
5289 while (*p != ' ' && *p != ';')
5296 if (*this_arg != '!')
5304 /* If this is a default argument, we can just ignore it.
5305 This is true even if this_arg begins with '!'. Beginning
5306 with '!' does not mean that this argument is necessarily
5307 inappropriate for this library: it merely means that
5308 there is a more specific library which uses this
5309 argument. If this argument is a default, we need not
5310 consider that more specific library. */
5311 if (! default_arg (this_arg, p - this_arg))
5313 ok = used_arg (this_arg, p - this_arg);
5324 if (this_path_len != 1
5325 || this_path[0] != '.')
5327 multilib_dir = xmalloc (this_path_len + 1);
5328 strncpy (multilib_dir, this_path, this_path_len);
5329 multilib_dir[this_path_len] = '\0';
5338 /* Print out the multiple library subdirectory selection
5339 information. This prints out a series of lines. Each line looks
5340 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5341 required. Only the desired options are printed out, the negative
5342 matches. The options are print without a leading dash. There are
5343 no spaces to make it easy to use the information in the shell.
5344 Each subdirectory is printed only once. This assumes the ordering
5345 generated by the genmultilib script. */
5348 print_multilib_info ()
5350 char *p = multilib_select;
5351 char *last_path = 0, *this_path;
5353 int last_path_len = 0;
5357 /* Ignore newlines. */
5364 /* Get the initial path. */
5373 /* If this is a duplicate, skip it. */
5374 skip = (last_path != 0 && p - this_path == last_path_len
5375 && ! strncmp (last_path, this_path, last_path_len));
5377 last_path = this_path;
5378 last_path_len = p - this_path;
5380 /* If this directory requires any default arguments, we can skip
5381 it. We will already have printed a directory identical to
5382 this one which does not require that default argument. */
5400 while (*q != ' ' && *q != ';')
5408 && default_arg (arg, q - arg))
5423 for (p1 = last_path; p1 < p; p1++)
5442 use_arg = *p != '!';
5447 while (*p != ' ' && *p != ';')
5462 /* If there are extra options, print them now */
5463 if (multilib_extra && *multilib_extra)
5465 int print_at = TRUE;
5468 for (q = multilib_extra; *q != '\0'; q++)