1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!! */
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers. It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec". */
45 #include "gansidecl.h"
49 /* ??? Need to find a GCC header to put these in. */
50 extern int pexecute PROTO ((const char *, char * const *, const char *,
51 const char *, char **, char **, int));
52 extern int pwait PROTO ((int, int *, int));
53 extern char *update_path PROTO((char *, char *));
54 extern void set_std_prefix PROTO((char *, int));
55 /* Flag arguments to pexecute. */
56 #define PEXECUTE_FIRST 1
57 #define PEXECUTE_LAST 2
58 #define PEXECUTE_SEARCH 4
59 #define PEXECUTE_VERBOSE 8
62 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
65 #define WTERMSIG(S) ((S) & 0x7f)
68 #define WIFEXITED(S) (((S) & 0xff) == 0)
71 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
75 #define exit __posix_exit
78 /* Define O_RDONLY if the system hasn't defined it for us. */
87 /* Test if something is a normal file. */
89 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
92 /* Test if something is a directory. */
94 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
97 /* By default there is no special suffix for executables. */
98 #ifdef EXECUTABLE_SUFFIX
99 #define HAVE_EXECUTABLE_SUFFIX
101 #define EXECUTABLE_SUFFIX ""
104 /* By default, the suffix for object files is ".o". */
106 #define HAVE_OBJECT_SUFFIX
108 #define OBJECT_SUFFIX ".o"
111 /* By default, colon separates directories in a path. */
112 #ifndef PATH_SEPARATOR
113 #define PATH_SEPARATOR ':'
116 #ifndef DIR_SEPARATOR
117 #define DIR_SEPARATOR '/'
120 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
122 #define obstack_chunk_alloc xmalloc
123 #define obstack_chunk_free free
125 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 *, size_t, 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 #ifdef LANG_SPECIFIC_DRIVER
264 extern void lang_specific_driver PROTO ((void (*) (), int *, char ***));
267 /* Specs are strings containing lines, each of which (if not blank)
268 is made up of a program name, and arguments separated by spaces.
269 The program name must be exact and start from root, since no path
270 is searched and it is unreliable to depend on the current working directory.
271 Redirection of input or output is not supported; the subprograms must
272 accept filenames saying what files to read and write.
274 In addition, the specs can contain %-sequences to substitute variable text
275 or for conditional text. Here is a table of all defined %-sequences.
276 Note that spaces are not generated automatically around the results of
277 expanding these sequences; therefore, you can concatenate them together
278 or with constant text in a single argument.
280 %% substitute one % into the program name or argument.
281 %i substitute the name of the input file being processed.
282 %b substitute the basename of the input file being processed.
283 This is the substring up to (and not including) the last period
284 and not including the directory.
285 %g substitute the temporary-file-name-base. This is a string chosen
286 once per compilation. Different temporary file names are made by
287 concatenation of constant strings on the end, as in `%g.s'.
288 %g also has the same effect of %d.
289 %u like %g, but make the temporary file name unique.
290 %U returns the last file name generated with %u.
291 %d marks the argument containing or following the %d as a
292 temporary file name, so that that file will be deleted if CC exits
293 successfully. Unlike %g, this contributes no text to the argument.
294 %w marks the argument containing or following the %w as the
295 "output file" of this compilation. This puts the argument
296 into the sequence of arguments that %o will substitute later.
298 like %{...} but mark last argument supplied within
299 as a file to be deleted on failure.
300 %o substitutes the names of all the output files, with spaces
301 automatically placed around them. You should write spaces
302 around the %o as well or the results are undefined.
303 %o is for use in the specs for running the linker.
304 Input files whose names have no recognized suffix are not compiled
305 at all, but they are included among the output files, so they will
307 %O substitutes the suffix for object files.
308 %p substitutes the standard macro predefinitions for the
309 current target machine. Use this when running cpp.
310 %P like %p, but puts `__' before and after the name of each macro.
311 (Except macros that already have __.)
313 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
314 %s current argument is the name of a library or startup file of some sort.
315 Search for that file in a standard list of directories
316 and substitute the full name found.
317 %eSTR Print STR as an error message. STR is terminated by a newline.
318 Use this when inconsistent options are detected.
319 %x{OPTION} Accumulate an option for %X.
320 %X Output the accumulated linker options specified by compilations.
321 %Y Output the accumulated assembler options specified by compilations.
322 %Z Output the accumulated preprocessor options specified by compilations.
323 %v1 Substitute the major version number of GCC.
324 (For version 2.5.n, this is 2.)
325 %v2 Substitute the minor version number of GCC.
326 (For version 2.5.n, this is 5.)
327 %a process ASM_SPEC as a spec.
328 This allows config.h to specify part of the spec for running as.
329 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
330 used here. This can be used to run a post-processor after the
331 assembler has done it's job.
332 %D Dump out a -L option for each directory in startfile_prefixes.
333 If multilib_dir is set, extra entries are generated with it affixed.
334 %l process LINK_SPEC as a spec.
335 %L process LIB_SPEC as a spec.
336 %G process LIBGCC_SPEC as a spec.
337 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
338 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
339 %c process SIGNED_CHAR_SPEC as a spec.
340 %C process CPP_SPEC as a spec. A capital C is actually used here.
341 %1 process CC1_SPEC as a spec.
342 %2 process CC1PLUS_SPEC as a spec.
343 %| output "-" if the input for the current command is coming from a pipe.
344 %* substitute the variable part of a matched option. (See below.)
345 Note that each comma in the substituted string is replaced by
347 %{S} substitutes the -S switch, if that switch was given to CC.
348 If that switch was not specified, this substitutes nothing.
349 Here S is a metasyntactic variable.
350 %{S*} substitutes all the switches specified to CC whose names start
351 with -S. This is used for -o, -D, -I, etc; switches that take
352 arguments. CC considers `-o foo' as being one switch whose
353 name starts with `o'. %{o*} would substitute this text,
354 including the space; thus, two arguments would be generated.
355 %{^S*} likewise, but don't put a blank between a switch and any args.
356 %{S*:X} substitutes X if one or more switches whose names start with -S are
357 specified to CC. Note that the tail part of the -S option
358 (i.e. the part matched by the `*') will be substituted for each
359 occurrence of %* within X.
360 %{S:X} substitutes X, but only if the -S switch was given to CC.
361 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
362 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
363 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
364 %{.S:X} substitutes X, but only if processing a file with suffix S.
365 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
366 %(Spec) processes a specification defined in a specs file as *Spec:
367 %[Spec] as above, but put __ around -D arguments
369 The conditional text X in a %{S:X} or %{!S:X} construct may contain
370 other nested % constructs or spaces, or even newlines. They are
371 processed as usual, as described above.
373 The -O, -f, -m, and -W switches are handled specifically in these
374 constructs. If another value of -O or the negated form of a -f, -m, or
375 -W switch is found later in the command line, the earlier switch
376 value is ignored, except with {S*} where S is just one letter; this
377 passes all matching options.
379 The character | is used to indicate that a command should be piped to
380 the following command, but only if -pipe is specified.
382 Note that it is built into CC which switches take arguments and which
383 do not. You might think it would be useful to generalize this to
384 allow each compiler's spec to say which switches take arguments. But
385 this cannot be done in a consistent fashion. CC cannot even decide
386 which input files have been specified without knowing which switches
387 take arguments, and it must know which input files to compile in order
388 to tell which compilers to run.
390 CC also knows implicitly that arguments starting in `-l' are to be
391 treated as compiler output files, and passed to the linker in their
392 proper position among the other output files. */
394 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
396 /* config.h can define ASM_SPEC to provide extra args to the assembler
397 or extra switch-translations. */
402 /* config.h can define ASM_FINAL_SPEC to run a post processor after
403 the assembler has run. */
404 #ifndef ASM_FINAL_SPEC
405 #define ASM_FINAL_SPEC ""
408 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
409 or extra switch-translations. */
414 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
415 or extra switch-translations. */
420 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
421 or extra switch-translations. */
423 #define CC1PLUS_SPEC ""
426 /* config.h can define LINK_SPEC to provide extra args to the linker
427 or extra switch-translations. */
432 /* config.h can define LIB_SPEC to override the default libraries. */
434 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
437 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
440 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
441 /* Have gcc do the search for libgcc.a. */
442 #define LIBGCC_SPEC "libgcc.a%s"
444 #define LIBGCC_SPEC "-lgcc"
448 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
449 #ifndef STARTFILE_SPEC
450 #define STARTFILE_SPEC \
451 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
454 /* config.h can define SWITCHES_NEED_SPACES to control which options
455 require spaces between the option and the argument. */
456 #ifndef SWITCHES_NEED_SPACES
457 #define SWITCHES_NEED_SPACES ""
460 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
462 #define ENDFILE_SPEC ""
465 /* This spec is used for telling cpp whether char is signed or not. */
466 #ifndef SIGNED_CHAR_SPEC
467 /* Use #if rather than ?:
468 because MIPS C compiler rejects like ?: in initializers. */
469 #if DEFAULT_SIGNED_CHAR
470 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
472 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
476 static char *cpp_spec = CPP_SPEC;
477 static char *cpp_predefines = CPP_PREDEFINES;
478 static char *cc1_spec = CC1_SPEC;
479 static char *cc1plus_spec = CC1PLUS_SPEC;
480 static char *signed_char_spec = SIGNED_CHAR_SPEC;
481 static char *asm_spec = ASM_SPEC;
482 static char *asm_final_spec = ASM_FINAL_SPEC;
483 static char *link_spec = LINK_SPEC;
484 static char *lib_spec = LIB_SPEC;
485 static char *libgcc_spec = LIBGCC_SPEC;
486 static char *endfile_spec = ENDFILE_SPEC;
487 static char *startfile_spec = STARTFILE_SPEC;
488 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
490 /* Some compilers have limits on line lengths, and the multilib_select
491 and/or multilib_matches strings can be very long, so we build them at
493 static struct obstack multilib_obstack;
494 static char *multilib_select;
495 static char *multilib_matches;
496 static char *multilib_defaults;
497 #include "multilib.h"
499 /* Check whether a particular argument is a default argument. */
501 #ifndef MULTILIB_DEFAULTS
502 #define MULTILIB_DEFAULTS { "" }
505 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
508 struct user_specs *next;
512 static struct user_specs *user_specs_head, *user_specs_tail;
514 /* This defines which switch letters take arguments. */
516 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
517 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
518 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
519 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
520 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
521 || (CHAR) == 'B' || (CHAR) == 'b')
523 #ifndef SWITCH_TAKES_ARG
524 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
527 /* This defines which multi-letter switches take arguments. */
529 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
530 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
531 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
532 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
533 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
534 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
535 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
537 #ifndef WORD_SWITCH_TAKES_ARG
538 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
541 /* Record the mapping from file suffixes for compilation specs. */
545 char *suffix; /* Use this compiler for input files
546 whose names end in this suffix. */
548 char *spec[4]; /* To use this compiler, concatenate these
549 specs and pass to do_spec. */
552 /* Pointer to a vector of `struct compiler' that gives the spec for
553 compiling a file, based on its suffix.
554 A file that does not end in any of these suffixes will be passed
555 unchanged to the loader and nothing else will be done to it.
557 An entry containing two 0s is used to terminate the vector.
559 If multiple entries match a file, the last matching one is used. */
561 static struct compiler *compilers;
563 /* Number of entries in `compilers', not counting the null terminator. */
565 static int n_compilers;
567 /* The default list of file name suffixes and their compilation specs. */
569 static struct compiler default_compilers[] =
571 /* Add lists of suffixes of known languages here. If those languages
572 were not present when we built the driver, we will hit these copies
573 and be given a more meaningful error than "file not used since
574 linking is not done". */
575 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}}, {".c++", {"#C++"}},
576 {".C", {"#C++"}}, {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
577 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
578 {".fpp", {"#Fortran"}},
579 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
580 /* Next come the entries for C. */
583 {"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
584 %{C:%{!E:%eGNU C does not support -C without using -E}}\
585 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
586 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
587 %{ansi:-trigraphs -D__STRICT_ANSI__}\
588 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
589 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
590 %{traditional} %{ftraditional:-traditional}\
591 %{traditional-cpp:-traditional}\
592 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
593 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
594 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
595 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
596 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
597 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
599 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
600 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
602 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
603 %{!pipe:%g.s} %A\n }}}}"}},
605 {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
606 %{C:%{!E:%eGNU C does not support -C without using -E}}\
607 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
608 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
609 %{ansi:-trigraphs -D__STRICT_ANSI__}\
610 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
611 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
612 %{traditional} %{ftraditional:-traditional}\
613 %{traditional-cpp:-traditional}\
614 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
616 %{!E:%e-E required when input is from standard input}"}},
617 {".m", {"@objective-c"}},
619 {"cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
620 %{C:%{!E:%eGNU C does not support -C without using -E}}\
621 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
622 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
623 %{ansi:-trigraphs -D__STRICT_ANSI__}\
624 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
625 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
626 %{traditional} %{ftraditional:-traditional}\
627 %{traditional-cpp:-traditional}\
628 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
629 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
630 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
631 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
632 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
633 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
634 -lang-objc %{gen-decls} \
636 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
637 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
639 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
640 %{!pipe:%g.s} %A\n }}}}"}},
641 {".h", {"@c-header"}},
643 {"%{!E:%eCompilation of header file requested} \
644 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
645 %{C:%{!E:%eGNU C does not support -C without using -E}}\
646 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
647 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
648 %{ansi:-trigraphs -D__STRICT_ANSI__}\
649 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
650 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
651 %{traditional} %{ftraditional:-traditional}\
652 %{traditional-cpp:-traditional}\
653 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
655 {".i", {"@cpp-output"}},
657 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
658 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
659 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
661 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
662 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
664 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
665 %{!pipe:%g.s} %A\n }}}}"}},
666 {".s", {"@assembler"}},
668 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
669 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
671 {".S", {"@assembler-with-cpp"}},
672 {"@assembler-with-cpp",
673 {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
674 %{C:%{!E:%eGNU C does not support -C without using -E}}\
675 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
676 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
677 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
678 %{traditional} %{ftraditional:-traditional}\
679 %{traditional-cpp:-traditional}\
680 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
681 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
682 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
683 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
684 %{!pipe:%g.s} %A\n }}}}"}},
686 /* Mark end of table */
690 /* Number of elements in default_compilers, not counting the terminator. */
692 static int n_default_compilers
693 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
695 /* Here is the spec for running the linker, after compiling all files. */
697 /* -u* was put back because both BSD and SysV seem to support it. */
698 /* %{static:} simply prevents an error message if the target machine
699 doesn't handle -static. */
700 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
701 scripts which exist in user specified directories, or in standard
703 #ifdef LINK_LIBGCC_SPECIAL
704 /* Don't generate -L options. */
705 static char *link_command_spec = "\
707 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
708 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
709 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
711 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
712 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
717 static char *link_command_spec = "\
719 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
720 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
721 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
722 %{static:} %{L*} %D %o\
723 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
724 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
729 /* A vector of options to give to the linker.
730 These options are accumulated by %x,
731 and substituted into the linker command with %X. */
732 static int n_linker_options;
733 static char **linker_options;
735 /* A vector of options to give to the assembler.
736 These options are accumulated by -Wa,
737 and substituted into the assembler command with %Y. */
738 static int n_assembler_options;
739 static char **assembler_options;
741 /* A vector of options to give to the preprocessor.
742 These options are accumulated by -Wp,
743 and substituted into the preprocessor command with %Z. */
744 static int n_preprocessor_options;
745 static char **preprocessor_options;
747 /* Define how to map long options into short ones. */
749 /* This structure describes one mapping. */
752 /* The long option's name. */
754 /* The equivalent short option. */
756 /* Argument info. A string of flag chars; NULL equals no options.
757 a => argument required.
758 o => argument optional.
759 j => join argument to equivalent, making one word.
760 * => require other text after NAME as an argument. */
764 /* This is the table of mappings. Mappings are tried sequentially
765 for each option encountered; the first one that matches, wins. */
767 struct option_map option_map[] =
769 {"--all-warnings", "-Wall", 0},
770 {"--ansi", "-ansi", 0},
771 {"--assemble", "-S", 0},
772 {"--assert", "-A", "a"},
773 {"--comments", "-C", 0},
774 {"--compile", "-c", 0},
775 {"--debug", "-g", "oj"},
776 {"--define-macro", "-D", "aj"},
777 {"--dependencies", "-M", 0},
778 {"--dump", "-d", "a"},
779 {"--dumpbase", "-dumpbase", "a"},
780 {"--entry", "-e", 0},
781 {"--extra-warnings", "-W", 0},
782 {"--for-assembler", "-Wa", "a"},
783 {"--for-linker", "-Xlinker", "a"},
784 {"--force-link", "-u", "a"},
785 {"--imacros", "-imacros", "a"},
786 {"--include", "-include", "a"},
787 {"--include-barrier", "-I-", 0},
788 {"--include-directory", "-I", "aj"},
789 {"--include-directory-after", "-idirafter", "a"},
790 {"--include-prefix", "-iprefix", "a"},
791 {"--include-with-prefix", "-iwithprefix", "a"},
792 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
793 {"--include-with-prefix-after", "-iwithprefix", "a"},
794 {"--language", "-x", "a"},
795 {"--library-directory", "-L", "a"},
796 {"--machine", "-m", "aj"},
797 {"--machine-", "-m", "*j"},
798 {"--no-line-commands", "-P", 0},
799 {"--no-precompiled-includes", "-noprecomp", 0},
800 {"--no-standard-includes", "-nostdinc", 0},
801 {"--no-standard-libraries", "-nostdlib", 0},
802 {"--no-warnings", "-w", 0},
803 {"--optimize", "-O", "oj"},
804 {"--output", "-o", "a"},
805 {"--pedantic", "-pedantic", 0},
806 {"--pedantic-errors", "-pedantic-errors", 0},
807 {"--pipe", "-pipe", 0},
808 {"--prefix", "-B", "a"},
809 {"--preprocess", "-E", 0},
810 {"--print-search-dirs", "-print-search-dirs", 0},
811 {"--print-file-name", "-print-file-name=", "aj"},
812 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
813 {"--print-missing-file-dependencies", "-MG", 0},
814 {"--print-multi-lib", "-print-multi-lib", 0},
815 {"--print-multi-directory", "-print-multi-directory", 0},
816 {"--print-prog-name", "-print-prog-name=", "aj"},
817 {"--profile", "-p", 0},
818 {"--profile-blocks", "-a", 0},
819 {"--quiet", "-q", 0},
820 {"--save-temps", "-save-temps", 0},
821 {"--shared", "-shared", 0},
822 {"--silent", "-q", 0},
823 {"--specs", "-specs=", "aj"},
824 {"--static", "-static", 0},
825 {"--symbolic", "-symbolic", 0},
826 {"--target", "-b", "a"},
827 {"--trace-includes", "-H", 0},
828 {"--traditional", "-traditional", 0},
829 {"--traditional-cpp", "-traditional-cpp", 0},
830 {"--trigraphs", "-trigraphs", 0},
831 {"--undefine-macro", "-U", "aj"},
832 {"--use-version", "-V", "a"},
833 {"--user-dependencies", "-MM", 0},
834 {"--verbose", "-v", 0},
835 {"--version", "-dumpversion", 0},
836 {"--warn-", "-W", "*j"},
837 {"--write-dependencies", "-MD", 0},
838 {"--write-user-dependencies", "-MMD", 0},
842 /* Translate the options described by *ARGCP and *ARGVP.
843 Make a new vector and store it back in *ARGVP,
844 and store its length in *ARGVC. */
847 translate_options (argcp, argvp)
853 char **argv = *argvp;
854 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
858 newv[newindex++] = argv[i++];
862 /* Translate -- options. */
863 if (argv[i][0] == '-' && argv[i][1] == '-')
865 /* Find a mapping that applies to this option. */
866 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
868 size_t optlen = strlen (option_map[j].name);
869 size_t arglen = strlen (argv[i]);
870 size_t complen = arglen > optlen ? optlen : arglen;
871 char *arginfo = option_map[j].arg_info;
876 if (!strncmp (argv[i], option_map[j].name, complen))
883 k < sizeof (option_map) / sizeof (option_map[0]);
885 if (strlen (option_map[k].name) >= arglen
886 && !strncmp (argv[i], option_map[k].name, arglen))
888 error ("Ambiguous abbreviation %s", argv[i]);
892 if (k != sizeof (option_map) / sizeof (option_map[0]))
898 /* If the option has an argument, accept that. */
899 if (argv[i][optlen] == '=')
900 arg = argv[i] + optlen + 1;
902 /* If this mapping requires extra text at end of name,
903 accept that as "argument". */
904 else if (index (arginfo, '*') != 0)
905 arg = argv[i] + optlen;
907 /* Otherwise, extra text at end means mismatch.
908 Try other mappings. */
913 else if (index (arginfo, '*') != 0)
915 error ("Incomplete `%s' option", option_map[j].name);
919 /* Handle arguments. */
920 if (index (arginfo, 'a') != 0)
926 error ("Missing argument to `%s' option",
934 else if (index (arginfo, '*') != 0)
936 else if (index (arginfo, 'o') == 0)
939 error ("Extraneous argument to `%s' option",
944 /* Store the translation as one argv elt or as two. */
945 if (arg != 0 && index (arginfo, 'j') != 0)
946 newv[newindex++] = concat (option_map[j].equivalent, arg,
950 newv[newindex++] = option_map[j].equivalent;
951 newv[newindex++] = arg;
954 newv[newindex++] = option_map[j].equivalent;
962 /* Handle old-fashioned options--just copy them through,
963 with their arguments. */
964 else if (argv[i][0] == '-')
966 char *p = argv[i] + 1;
970 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
971 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
972 else if (WORD_SWITCH_TAKES_ARG (p))
973 nskip += WORD_SWITCH_TAKES_ARG (p);
974 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
977 else if (! strcmp (p, "Xlinker"))
980 /* Watch out for an option at the end of the command line that
981 is missing arguments, and avoid skipping past the end of the
983 if (nskip + i > argc)
988 newv[newindex++] = argv[i++];
993 /* Ordinary operands, or +e options. */
994 newv[newindex++] = argv[i++];
1007 #ifdef HAVE_STRERROR
1013 static char buffer[30];
1015 return "cannot access";
1017 if (e > 0 && e < sys_nerr)
1018 return sys_errlist[e];
1020 sprintf (buffer, "Unknown error %d", e);
1031 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1032 be considered whitespace. */
1033 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1035 else if (*p == '\n' || *p == ' ' || *p == '\t')
1039 while (*p != '\n') p++;
1049 /* Structure to keep track of the specs that have been defined so far.
1050 These are accessed using %(specname) or %[specname] in a compiler
1055 /* The following 2 fields must be first */
1056 /* to allow EXTRA_SPECS to be initialized */
1057 char *name; /* name of the spec. */
1058 char *ptr; /* available ptr if no static pointer */
1060 /* The following fields are not initialized */
1061 /* by EXTRA_SPECS */
1062 char **ptr_spec; /* pointer to the spec itself. */
1063 struct spec_list *next; /* Next spec in linked list. */
1064 int name_len; /* length of the name */
1065 int alloc_p; /* whether string was allocated */
1068 #define INIT_STATIC_SPEC(NAME,PTR) \
1069 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1071 /* List of statically defined specs */
1072 static struct spec_list static_specs[] = {
1073 INIT_STATIC_SPEC ("asm", &asm_spec),
1074 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1075 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1076 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1077 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1078 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1079 INIT_STATIC_SPEC ("link", &link_spec),
1080 INIT_STATIC_SPEC ("lib", &lib_spec),
1081 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1082 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1083 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1084 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1085 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1086 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1087 INIT_STATIC_SPEC ("version", &compiler_version),
1088 INIT_STATIC_SPEC ("multilib", &multilib_select),
1089 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1090 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1091 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1094 #ifdef EXTRA_SPECS /* additional specs needed */
1095 static struct spec_list extra_specs[] = { EXTRA_SPECS };
1098 /* List of dynamically allocates specs that have been defined so far. */
1100 static struct spec_list *specs = (struct spec_list *)0;
1103 /* Initialize the specs lookup routines. */
1108 struct spec_list *next = (struct spec_list *)0;
1109 struct spec_list *sl = (struct spec_list *)0;
1113 return; /* already initialized */
1116 fprintf (stderr, "Using builtin specs.\n");
1119 for (i = (sizeof (extra_specs) / sizeof (extra_specs[0])) - 1; i >= 0; i--)
1121 sl = &extra_specs[i];
1123 sl->name_len = strlen (sl->name);
1124 sl->ptr_spec = &sl->ptr;
1129 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1131 sl = &static_specs[i];
1140 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1141 removed; If the spec starts with a + then SPEC is added to the end of the
1145 set_spec (name, spec)
1149 struct spec_list *sl;
1151 int name_len = strlen (name);
1154 /* If this is the first call, initialize the statically allocated specs */
1157 struct spec_list *next = (struct spec_list *)0;
1158 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1161 sl = &static_specs[i];
1168 /* See if the spec already exists */
1169 for (sl = specs; sl; sl = sl->next)
1170 if (name_len == sl->name_len && !strcmp (sl->name, name))
1175 /* Not found - make it */
1176 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1177 sl->name = save_string (name, strlen (name));
1178 sl->name_len = name_len;
1179 sl->ptr_spec = &sl->ptr;
1181 *(sl->ptr_spec) = "";
1186 old_spec = *(sl->ptr_spec);
1187 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE (spec[1]))
1188 ? concat (old_spec, spec + 1, NULL_PTR)
1189 : save_string (spec, strlen (spec)));
1193 fprintf (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1196 /* Free the old spec */
1197 if (old_spec && sl->alloc_p)
1203 /* Accumulate a command (program name and args), and run it. */
1205 /* Vector of pointers to arguments in the current line of specifications. */
1207 static char **argbuf;
1209 /* Number of elements allocated in argbuf. */
1211 static int argbuf_length;
1213 /* Number of elements in argbuf currently in use (containing args). */
1215 static int argbuf_index;
1217 #ifdef MKTEMP_EACH_FILE
1218 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1221 static struct temp_name {
1222 char *suffix; /* suffix associated with the code. */
1223 int length; /* strlen (suffix). */
1224 int unique; /* Indicates whether %g or %u/%U was used. */
1225 char *filename; /* associated filename. */
1226 int filename_length; /* strlen (filename). */
1227 struct temp_name *next;
1231 /* Number of commands executed so far. */
1233 static int execution_count;
1235 /* Number of commands that exited with a signal. */
1237 static int signal_count;
1239 /* Name with which this program was invoked. */
1241 static char *programname;
1243 /* Structures to keep track of prefixes to try when looking for files. */
1247 char *prefix; /* String to prepend to the path. */
1248 struct prefix_list *next; /* Next in linked list. */
1249 int require_machine_suffix; /* Don't use without machine_suffix. */
1250 /* 2 means try both machine_suffix and just_machine_suffix. */
1251 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1256 struct prefix_list *plist; /* List of prefixes to try */
1257 int max_len; /* Max length of a prefix in PLIST */
1258 char *name; /* Name of this list (used in config stuff) */
1261 /* List of prefixes to try when looking for executables. */
1263 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1265 /* List of prefixes to try when looking for startup (crt0) files. */
1267 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1269 /* List of prefixes to try when looking for include files. */
1271 static struct path_prefix include_prefixes = { 0, 0, "include" };
1273 /* Suffix to attach to directories searched for commands.
1274 This looks like `MACHINE/VERSION/'. */
1276 static char *machine_suffix = 0;
1278 /* Suffix to attach to directories searched for commands.
1279 This is just `MACHINE/'. */
1281 static char *just_machine_suffix = 0;
1283 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1285 static char *gcc_exec_prefix;
1287 /* Default prefixes to attach to command names. */
1289 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1290 #undef MD_EXEC_PREFIX
1291 #undef MD_STARTFILE_PREFIX
1292 #undef MD_STARTFILE_PREFIX_1
1295 #ifndef STANDARD_EXEC_PREFIX
1296 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1297 #endif /* !defined STANDARD_EXEC_PREFIX */
1299 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1300 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1301 #ifdef MD_EXEC_PREFIX
1302 static char *md_exec_prefix = MD_EXEC_PREFIX;
1305 #ifndef STANDARD_STARTFILE_PREFIX
1306 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1307 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1309 #ifdef MD_STARTFILE_PREFIX
1310 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1312 #ifdef MD_STARTFILE_PREFIX_1
1313 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1315 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1316 static char *standard_startfile_prefix_1 = "/lib/";
1317 static char *standard_startfile_prefix_2 = "/usr/lib/";
1319 #ifndef TOOLDIR_BASE_PREFIX
1320 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1322 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1323 static char *tooldir_prefix;
1325 /* Subdirectory to use for locating libraries. Set by
1326 set_multilib_dir based on the compilation options. */
1328 static char *multilib_dir;
1330 /* Clear out the vector of arguments (after a command is executed). */
1338 /* Add one argument to the vector at the end.
1339 This is done when a space is seen or at the end of the line.
1340 If DELETE_ALWAYS is nonzero, the arg is a filename
1341 and the file should be deleted eventually.
1342 If DELETE_FAILURE is nonzero, the arg is a filename
1343 and the file should be deleted if this compilation fails. */
1346 store_arg (arg, delete_always, delete_failure)
1348 int delete_always, delete_failure;
1350 if (argbuf_index + 1 == argbuf_length)
1352 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1354 argbuf[argbuf_index++] = arg;
1355 argbuf[argbuf_index] = 0;
1357 if (delete_always || delete_failure)
1358 record_temp_file (arg, delete_always, delete_failure);
1361 /* Read compilation specs from a file named FILENAME,
1362 replacing the default ones.
1364 A suffix which starts with `*' is a definition for
1365 one of the machine-specific sub-specs. The "suffix" should be
1366 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1367 The corresponding spec is stored in asm_spec, etc.,
1368 rather than in the `compilers' vector.
1370 Anything invalid in the file is a fatal error. */
1373 read_specs (filename, main_p)
1379 struct stat statbuf;
1384 fprintf (stderr, "Reading specs from %s\n", filename);
1386 /* Open and stat the file. */
1387 desc = open (filename, O_RDONLY, 0);
1389 pfatal_with_name (filename);
1390 if (stat (filename, &statbuf) < 0)
1391 pfatal_with_name (filename);
1393 /* Read contents of file into BUFFER. */
1394 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1395 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1397 pfatal_with_name (filename);
1398 buffer[readlen] = 0;
1401 /* Scan BUFFER for specs, putting them in the vector. */
1407 char *in, *out, *p1, *p2, *p3;
1409 /* Advance P in BUFFER to the next nonblank nocomment line. */
1410 p = skip_whitespace (p);
1414 /* Is this a special command that starts with '%'? */
1415 /* Don't allow this for the main specs file, since it would
1416 encourage people to overwrite it. */
1417 if (*p == '%' && !main_p)
1420 while (*p && *p != '\n')
1423 p++; /* Skip '\n' */
1425 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1426 && (p1[sizeof "%include" - 1] == ' '
1427 || p1[sizeof "%include" - 1] == '\t'))
1431 p1 += sizeof ("%include");
1432 while (*p1 == ' ' || *p1 == '\t')
1435 if (*p1++ != '<' || p[-2] != '>')
1436 fatal ("specs %%include syntax malformed after %d characters",
1440 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1441 read_specs (new_filename ? new_filename : p1, FALSE);
1444 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1445 && (p1[sizeof "%include_noerr" - 1] == ' '
1446 || p1[sizeof "%include_noerr" - 1] == '\t'))
1450 p1 += sizeof "%include_noerr";
1451 while (*p1 == ' ' || *p1 == '\t') p1++;
1453 if (*p1++ != '<' || p[-2] != '>')
1454 fatal ("specs %%include syntax malformed after %d characters",
1458 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1460 read_specs (new_filename, FALSE);
1461 else if (verbose_flag)
1462 fprintf (stderr, "Could not find specs file %s\n", p1);
1465 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1466 && (p1[sizeof "%rename" - 1] == ' '
1467 || p1[sizeof "%rename" - 1] == '\t'))
1470 struct spec_list *sl;
1472 /* Get original name */
1473 p1 += sizeof "%rename";
1474 while (*p1 == ' ' || *p1 == '\t')
1477 if (! ISALPHA (*p1))
1478 fatal ("specs %%rename syntax malformed after %d characters",
1482 while (*p2 && !ISSPACE (*p2))
1485 if (*p2 != ' ' && *p2 != '\t')
1486 fatal ("specs %%rename syntax malformed after %d characters",
1491 while (*p2 == ' ' || *p2 == '\t')
1494 if (! ISALPHA (*p2))
1495 fatal ("specs %%rename syntax malformed after %d characters",
1498 /* Get new spec name */
1500 while (*p3 && !ISSPACE (*p3))
1504 fatal ("specs %%rename syntax malformed after %d characters",
1508 for (sl = specs; sl; sl = sl->next)
1509 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1513 fatal ("specs %s spec was not found to be renamed", p1);
1515 if (strcmp (p1, p2) == 0)
1520 fprintf (stderr, "rename spec %s to %s\n", p1, p2);
1522 fprintf (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
1526 set_spec (p2, *(sl->ptr_spec));
1528 free (*(sl->ptr_spec));
1530 *(sl->ptr_spec) = "";
1535 fatal ("specs unknown %% command after %d characters",
1539 /* Find the colon that should end the suffix. */
1541 while (*p1 && *p1 != ':' && *p1 != '\n')
1544 /* The colon shouldn't be missing. */
1546 fatal ("specs file malformed after %d characters", p1 - buffer);
1548 /* Skip back over trailing whitespace. */
1550 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1553 /* Copy the suffix to a string. */
1554 suffix = save_string (p, p2 - p);
1555 /* Find the next line. */
1556 p = skip_whitespace (p1 + 1);
1558 fatal ("specs file malformed after %d characters", p - buffer);
1561 /* Find next blank line. */
1562 while (*p1 && !(*p1 == '\n' && p1[1] == '\n'))
1565 /* Specs end at the blank line and do not include the newline. */
1566 spec = save_string (p, p1 - p);
1569 /* Delete backslash-newline sequences from the spec. */
1574 if (in[0] == '\\' && in[1] == '\n')
1576 else if (in[0] == '#')
1577 while (*in && *in != '\n')
1585 if (suffix[0] == '*')
1587 if (! strcmp (suffix, "*link_command"))
1588 link_command_spec = spec;
1590 set_spec (suffix + 1, spec);
1594 /* Add this pair to the vector. */
1596 = ((struct compiler *)
1597 xrealloc (compilers,
1598 (n_compilers + 2) * sizeof (struct compiler)));
1600 compilers[n_compilers].suffix = suffix;
1601 bzero ((char *) compilers[n_compilers].spec,
1602 sizeof compilers[n_compilers].spec);
1603 compilers[n_compilers].spec[0] = spec;
1605 bzero ((char *) &compilers[n_compilers],
1606 sizeof compilers[n_compilers]);
1610 link_command_spec = spec;
1613 if (link_command_spec == 0)
1614 fatal ("spec file has no spec for linking");
1617 /* Record the names of temporary files we tell compilers to write,
1618 and delete them at the end of the run. */
1620 /* This is the common prefix we use to make temp file names.
1621 It is chosen once for each run of this program.
1622 It is substituted into a spec by %g.
1623 Thus, all temp file names contain this prefix.
1624 In practice, all temp file names start with this prefix.
1626 This prefix comes from the envvar TMPDIR if it is defined;
1627 otherwise, from the P_tmpdir macro if that is defined;
1628 otherwise, in /usr/tmp or /tmp;
1629 or finally the current directory if all else fails. */
1631 static char *temp_filename;
1633 /* Length of the prefix. */
1635 static int temp_filename_length;
1637 /* Define the list of temporary files to delete. */
1642 struct temp_file *next;
1645 /* Queue of files to delete on success or failure of compilation. */
1646 static struct temp_file *always_delete_queue;
1647 /* Queue of files to delete on failure of compilation. */
1648 static struct temp_file *failure_delete_queue;
1650 /* Record FILENAME as a file to be deleted automatically.
1651 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1652 otherwise delete it in any case.
1653 FAIL_DELETE nonzero means delete it if a compilation step fails;
1654 otherwise delete it in any case. */
1657 record_temp_file (filename, always_delete, fail_delete)
1662 register char *name;
1663 name = xmalloc (strlen (filename) + 1);
1664 strcpy (name, filename);
1668 register struct temp_file *temp;
1669 for (temp = always_delete_queue; temp; temp = temp->next)
1670 if (! strcmp (name, temp->name))
1673 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1674 temp->next = always_delete_queue;
1676 always_delete_queue = temp;
1683 register struct temp_file *temp;
1684 for (temp = failure_delete_queue; temp; temp = temp->next)
1685 if (! strcmp (name, temp->name))
1688 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1689 temp->next = failure_delete_queue;
1691 failure_delete_queue = temp;
1697 /* Delete all the temporary files whose names we previously recorded. */
1700 delete_if_ordinary (name)
1707 printf ("Delete %s? (y or n) ", name);
1711 while ((c = getchar ()) != '\n' && c != EOF)
1714 if (i == 'y' || i == 'Y')
1716 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1717 if (unlink (name) < 0)
1719 perror_with_name (name);
1723 delete_temp_files ()
1725 register struct temp_file *temp;
1727 for (temp = always_delete_queue; temp; temp = temp->next)
1728 delete_if_ordinary (temp->name);
1729 always_delete_queue = 0;
1732 /* Delete all the files to be deleted on error. */
1735 delete_failure_queue ()
1737 register struct temp_file *temp;
1739 for (temp = failure_delete_queue; temp; temp = temp->next)
1740 delete_if_ordinary (temp->name);
1744 clear_failure_queue ()
1746 failure_delete_queue = 0;
1749 /* Routine to add variables to the environment. We do this to pass
1750 the pathname of the gcc driver, and the directories search to the
1751 collect2 program, which is being run as ld. This way, we can be
1752 sure of executing the right compiler when collect2 wants to build
1753 constructors and destructors. Since the environment variables we
1754 use come from an obstack, we don't have to worry about allocating
1763 #ifndef VMS /* nor about VMS */
1765 extern char **environ;
1766 char **old_environ = environ;
1770 int str_len = strlen (str);
1774 while ((ch = *p++) != '\0' && ch != '=')
1780 /* Search for replacing an existing environment variable, and
1781 count the number of total environment variables. */
1782 for (envp = old_environ; *envp; envp++)
1785 if (!strncmp (str, *envp, name_len))
1792 /* Add a new environment variable */
1793 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1795 bcopy ((char *) old_environ, (char *) (environ + 1),
1796 sizeof (char *) * (num_envs+1));
1801 #endif /* HAVE_PUTENV */
1804 /* Build a list of search directories from PATHS.
1805 PREFIX is a string to prepend to the list.
1806 If CHECK_DIR_P is non-zero we ensure the directory exists.
1807 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1808 It is also used by the --print-search-dirs flag. */
1811 build_search_list (paths, prefix, check_dir_p)
1812 struct path_prefix *paths;
1816 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1818 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1819 int first_time = TRUE;
1820 struct prefix_list *pprefix;
1822 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1824 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1826 int len = strlen (pprefix->prefix);
1830 || is_directory (pprefix->prefix, machine_suffix, 0)))
1833 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1836 obstack_grow (&collect_obstack, pprefix->prefix, len);
1837 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1840 if (just_machine_suffix
1841 && pprefix->require_machine_suffix == 2
1843 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1846 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1849 obstack_grow (&collect_obstack, pprefix->prefix, len);
1850 obstack_grow (&collect_obstack, just_machine_suffix,
1854 if (! pprefix->require_machine_suffix)
1857 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1860 obstack_grow (&collect_obstack, pprefix->prefix, len);
1864 obstack_1grow (&collect_obstack, '\0');
1865 return obstack_finish (&collect_obstack);
1868 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1872 putenv_from_prefixes (paths, env_var)
1873 struct path_prefix *paths;
1876 putenv (build_search_list (paths, env_var, 1));
1879 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1880 access to check permissions.
1881 Return 0 if not found, otherwise return its name, allocated with malloc. */
1884 find_a_file (pprefix, name, mode)
1885 struct path_prefix *pprefix;
1890 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1891 struct prefix_list *pl;
1892 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1895 len += strlen (machine_suffix);
1897 temp = xmalloc (len);
1899 /* Determine the filename to execute (special case for absolute paths). */
1901 if (*name == '/' || *name == DIR_SEPARATOR
1902 /* Check for disk name on MS-DOS-based systems. */
1903 || (DIR_SEPARATOR == '\\' && name[1] == ':'
1904 && (name[2] == DIR_SEPARATOR || name[2] == '/')))
1906 if (access (name, mode))
1908 strcpy (temp, name);
1913 for (pl = pprefix->plist; pl; pl = pl->next)
1917 /* Some systems have a suffix for executable files.
1918 So try appending that first. */
1919 if (file_suffix[0] != 0)
1921 strcpy (temp, pl->prefix);
1922 strcat (temp, machine_suffix);
1923 strcat (temp, name);
1924 strcat (temp, file_suffix);
1925 if (access (temp, mode) == 0)
1927 if (pl->used_flag_ptr != 0)
1928 *pl->used_flag_ptr = 1;
1933 /* Now try just the name. */
1934 strcpy (temp, pl->prefix);
1935 strcat (temp, machine_suffix);
1936 strcat (temp, name);
1937 if (access (temp, mode) == 0)
1939 if (pl->used_flag_ptr != 0)
1940 *pl->used_flag_ptr = 1;
1945 /* Certain prefixes are tried with just the machine type,
1946 not the version. This is used for finding as, ld, etc. */
1947 if (just_machine_suffix && pl->require_machine_suffix == 2)
1949 /* Some systems have a suffix for executable files.
1950 So try appending that first. */
1951 if (file_suffix[0] != 0)
1953 strcpy (temp, pl->prefix);
1954 strcat (temp, just_machine_suffix);
1955 strcat (temp, name);
1956 strcat (temp, file_suffix);
1957 if (access (temp, mode) == 0)
1959 if (pl->used_flag_ptr != 0)
1960 *pl->used_flag_ptr = 1;
1965 strcpy (temp, pl->prefix);
1966 strcat (temp, just_machine_suffix);
1967 strcat (temp, name);
1968 if (access (temp, mode) == 0)
1970 if (pl->used_flag_ptr != 0)
1971 *pl->used_flag_ptr = 1;
1976 /* Certain prefixes can't be used without the machine suffix
1977 when the machine or version is explicitly specified. */
1978 if (! pl->require_machine_suffix)
1980 /* Some systems have a suffix for executable files.
1981 So try appending that first. */
1982 if (file_suffix[0] != 0)
1984 strcpy (temp, pl->prefix);
1985 strcat (temp, name);
1986 strcat (temp, file_suffix);
1987 if (access (temp, mode) == 0)
1989 if (pl->used_flag_ptr != 0)
1990 *pl->used_flag_ptr = 1;
1995 strcpy (temp, pl->prefix);
1996 strcat (temp, name);
1997 if (access (temp, mode) == 0)
1999 if (pl->used_flag_ptr != 0)
2000 *pl->used_flag_ptr = 1;
2010 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2011 at the start of the list, otherwise it goes at the end.
2013 If WARN is nonzero, we will warn if no file is found
2014 through this prefix. WARN should point to an int
2015 which will be set to 1 if this entry is used.
2017 COMPONENT is the value to be passed to update_path.
2019 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2020 the complete value of machine_suffix.
2021 2 means try both machine_suffix and just_machine_suffix. */
2024 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2025 struct path_prefix *pprefix;
2029 int require_machine_suffix;
2032 struct prefix_list *pl, **prev;
2035 if (! first && pprefix->plist)
2037 for (pl = pprefix->plist; pl->next; pl = pl->next)
2042 prev = &pprefix->plist;
2044 /* Keep track of the longest prefix */
2046 prefix = update_path (prefix, component);
2047 len = strlen (prefix);
2048 if (len > pprefix->max_len)
2049 pprefix->max_len = len;
2051 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2052 pl->prefix = save_string (prefix, len);
2053 pl->require_machine_suffix = require_machine_suffix;
2054 pl->used_flag_ptr = warn;
2061 pl->next = (struct prefix_list *) 0;
2065 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2068 unused_prefix_warnings (pprefix)
2069 struct path_prefix *pprefix;
2071 struct prefix_list *pl = pprefix->plist;
2075 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2077 if (pl->require_machine_suffix && machine_suffix)
2078 error ("file path prefix `%s%s' never used", pl->prefix,
2081 error ("file path prefix `%s' never used", pl->prefix);
2083 /* Prevent duplicate warnings. */
2084 *pl->used_flag_ptr = 1;
2092 /* Execute the command specified by the arguments on the current line of spec.
2093 When using pipes, this includes several piped-together commands
2094 with `|' between them.
2096 Return 0 if successful, -1 if failed. */
2102 int n_commands; /* # of command. */
2106 char *prog; /* program name. */
2107 char **argv; /* vector of args. */
2108 int pid; /* pid of process for this command. */
2111 struct command *commands; /* each command buffer with above info. */
2113 /* Count # of piped commands. */
2114 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2115 if (strcmp (argbuf[i], "|") == 0)
2118 /* Get storage for each command. */
2120 = (struct command *) alloca (n_commands * sizeof (struct command));
2122 /* Split argbuf into its separate piped processes,
2123 and record info about each one.
2124 Also search for the programs that are to be run. */
2126 commands[0].prog = argbuf[0]; /* first command. */
2127 commands[0].argv = &argbuf[0];
2128 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2130 commands[0].argv[0] = string;
2132 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2133 if (strcmp (argbuf[i], "|") == 0)
2134 { /* each command. */
2135 #if defined (__MSDOS__) || (defined (_WIN32) && defined (__CYGWIN32_)) || defined (OS2) || defined (VMS)
2136 fatal ("-pipe not supported");
2138 argbuf[i] = 0; /* termination of command args. */
2139 commands[n_commands].prog = argbuf[i + 1];
2140 commands[n_commands].argv = &argbuf[i + 1];
2141 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2143 commands[n_commands].argv[0] = string;
2147 argbuf[argbuf_index] = 0;
2149 /* If -v, print what we are about to do, and maybe query. */
2153 /* Print each piped command as a separate line. */
2154 for (i = 0; i < n_commands ; i++)
2158 for (j = commands[i].argv; *j; j++)
2159 fprintf (stderr, " %s", *j);
2161 /* Print a pipe symbol after all but the last command. */
2162 if (i + 1 != n_commands)
2163 fprintf (stderr, " |");
2164 fprintf (stderr, "\n");
2168 fprintf (stderr, "\nGo ahead? (y or n) ");
2172 while (getchar () != '\n')
2175 if (i != 'y' && i != 'Y')
2180 /* Run each piped subprocess. */
2182 for (i = 0; i < n_commands; i++)
2184 char *errmsg_fmt, *errmsg_arg;
2185 char *string = commands[i].argv[0];
2187 commands[i].pid = pexecute (string, commands[i].argv,
2188 programname, temp_filename,
2189 &errmsg_fmt, &errmsg_arg,
2190 ((i == 0 ? PEXECUTE_FIRST : 0)
2191 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2192 | (string == commands[i].prog
2193 ? PEXECUTE_SEARCH : 0)
2194 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2196 if (commands[i].pid == -1)
2197 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2199 if (string != commands[i].prog)
2205 /* Wait for all the subprocesses to finish.
2206 We don't care what order they finish in;
2207 we know that N_COMMANDS waits will get them all.
2208 Ignore subprocesses that we don't know about,
2209 since they can be spawned by the process that exec'ed us. */
2214 for (i = 0; i < n_commands; )
2220 pid = pwait (commands[i].pid, &status, 0);
2224 for (j = 0; j < n_commands; j++)
2225 if (commands[j].pid == pid)
2230 if (WIFSIGNALED (status))
2232 fatal ("Internal compiler error: program %s got fatal signal %d",
2233 commands[j].prog, WTERMSIG (status));
2237 else if (WIFEXITED (status)
2238 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2248 /* Find all the switches given to us
2249 and make a vector describing them.
2250 The elements of the vector are strings, one per switch given.
2251 If a switch uses following arguments, then the `part1' field
2252 is the switch itself and the `args' field
2253 is a null-terminated vector containing the following arguments.
2254 The `live_cond' field is 1 if the switch is true in a conditional spec,
2255 -1 if false (overridden by a later switch), and is initialized to zero.
2256 The `valid' field is nonzero if any spec has looked at this switch;
2257 if it remains zero at the end of the run, it must be meaningless. */
2267 static struct switchstr *switches;
2269 static int n_switches;
2277 /* Also a vector of input files specified. */
2279 static struct infile *infiles;
2281 static int n_infiles;
2283 /* And a vector of corresponding output files is made up later. */
2285 static char **outfiles;
2287 /* Used to track if none of the -B paths are used. */
2290 /* Used to track if standard path isn't used and -b or -V is specified. */
2291 static int warn_std;
2293 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2294 static int *warn_std_ptr = 0;
2297 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2299 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2300 is true if we should look for an executable suffix as well. */
2303 convert_filename (name, do_exe)
2308 int len = strlen (name);
2310 #ifdef HAVE_OBJECT_SUFFIX
2311 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2313 && name[len - 2] == '.'
2314 && name[len - 1] == 'o')
2316 obstack_grow (&obstack, name, len - 2);
2317 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2318 name = obstack_finish (&obstack);
2322 #ifdef HAVE_EXECUTABLE_SUFFIX
2323 /* If there is no filetype, make it the executable suffix (which includes
2324 the "."). But don't get confused if we have just "-o". */
2325 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2328 for (i = len - 1; i >= 0; i--)
2329 if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2332 for (i++; i < len; i++)
2336 obstack_grow (&obstack, name, len);
2337 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2338 name = obstack_finish (&obstack);
2345 /* Create the vector `switches' and its contents.
2346 Store its length in `n_switches'. */
2349 process_command (argc, argv)
2355 char *spec_lang = 0;
2356 int last_language_n_infiles;
2359 int lang_n_infiles = 0;
2361 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
2366 /* Figure compiler version from version string. */
2368 compiler_version = save_string (version_string, strlen (version_string));
2369 for (temp = compiler_version; *temp; ++temp)
2378 /* Set up the default search paths. */
2380 if (gcc_exec_prefix)
2382 int len = strlen (gcc_exec_prefix);
2383 if (len > sizeof ("/lib/gcc-lib/")-1
2384 && (gcc_exec_prefix[len-1] == '/'
2385 || gcc_exec_prefix[len-1] == DIR_SEPARATOR))
2387 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2388 if ((*temp == '/' || *temp == DIR_SEPARATOR)
2389 && strncmp (temp+1, "lib", 3) == 0
2390 && (temp[4] == '/' || temp[4] == DIR_SEPARATOR)
2391 && strncmp (temp+5, "gcc-lib", 7) == 0)
2392 len -= sizeof ("/lib/gcc-lib/") - 1;
2395 set_std_prefix (gcc_exec_prefix, len);
2396 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2397 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2400 /* COMPILER_PATH and LIBRARY_PATH have values
2401 that are lists of directory names with colons. */
2403 temp = getenv ("COMPILER_PATH");
2406 char *startp, *endp;
2407 char *nstore = (char *) alloca (strlen (temp) + 3);
2409 startp = endp = temp;
2412 if (*endp == PATH_SEPARATOR || *endp == 0)
2414 strncpy (nstore, startp, endp-startp);
2416 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2417 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2419 nstore[endp-startp] = DIR_SEPARATOR;
2420 nstore[endp-startp+1] = 0;
2423 nstore[endp-startp] = 0;
2424 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2425 add_prefix (&include_prefixes,
2426 concat (nstore, "include", NULL_PTR),
2430 endp = startp = endp + 1;
2437 temp = getenv ("LIBRARY_PATH");
2438 if (temp && *cross_compile == '0')
2440 char *startp, *endp;
2441 char *nstore = (char *) alloca (strlen (temp) + 3);
2443 startp = endp = temp;
2446 if (*endp == PATH_SEPARATOR || *endp == 0)
2448 strncpy (nstore, startp, endp-startp);
2450 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2451 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2453 nstore[endp-startp] = DIR_SEPARATOR;
2454 nstore[endp-startp+1] = 0;
2457 nstore[endp-startp] = 0;
2458 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2462 endp = startp = endp + 1;
2469 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2470 temp = getenv ("LPATH");
2471 if (temp && *cross_compile == '0')
2473 char *startp, *endp;
2474 char *nstore = (char *) alloca (strlen (temp) + 3);
2476 startp = endp = temp;
2479 if (*endp == PATH_SEPARATOR || *endp == 0)
2481 strncpy (nstore, startp, endp-startp);
2483 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2484 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2486 nstore[endp-startp] = DIR_SEPARATOR;
2487 nstore[endp-startp+1] = 0;
2490 nstore[endp-startp] = 0;
2491 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2495 endp = startp = endp + 1;
2502 /* Convert new-style -- options to old-style. */
2503 translate_options (&argc, &argv);
2505 #ifdef LANG_SPECIFIC_DRIVER
2506 /* Do language-specific adjustment/addition of flags. */
2507 lang_specific_driver (fatal, &argc, &argv);
2510 /* Scan argv twice. Here, the first time, just count how many switches
2511 there will be in their vector, and how many input files in theirs.
2512 Here we also parse the switches that cc itself uses (e.g. -v). */
2514 for (i = 1; i < argc; i++)
2516 if (! strcmp (argv[i], "-dumpspecs"))
2518 struct spec_list *sl;
2520 for (sl = specs; sl; sl = sl->next)
2521 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2524 else if (! strcmp (argv[i], "-dumpversion"))
2526 printf ("%s\n", version_string);
2529 else if (! strcmp (argv[i], "-dumpmachine"))
2531 printf ("%s\n", spec_machine);
2534 else if (! strcmp (argv[i], "-print-search-dirs"))
2535 print_search_dirs = 1;
2536 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2537 print_file_name = "libgcc.a";
2538 else if (! strncmp (argv[i], "-print-file-name=", 17))
2539 print_file_name = argv[i] + 17;
2540 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2541 print_prog_name = argv[i] + 17;
2542 else if (! strcmp (argv[i], "-print-multi-lib"))
2543 print_multi_lib = 1;
2544 else if (! strcmp (argv[i], "-print-multi-directory"))
2545 print_multi_directory = 1;
2546 else if (! strncmp (argv[i], "-Wa,", 4))
2549 /* Pass the rest of this option to the assembler. */
2551 n_assembler_options++;
2552 if (!assembler_options)
2554 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2557 = (char **) xrealloc (assembler_options,
2558 n_assembler_options * sizeof (char **));
2560 /* Split the argument at commas. */
2562 for (j = 4; argv[i][j]; j++)
2563 if (argv[i][j] == ',')
2565 assembler_options[n_assembler_options - 1]
2566 = save_string (argv[i] + prev, j - prev);
2567 n_assembler_options++;
2569 = (char **) xrealloc (assembler_options,
2570 n_assembler_options * sizeof (char **));
2573 /* Record the part after the last comma. */
2574 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2576 else if (! strncmp (argv[i], "-Wp,", 4))
2579 /* Pass the rest of this option to the preprocessor. */
2581 n_preprocessor_options++;
2582 if (!preprocessor_options)
2583 preprocessor_options
2584 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2586 preprocessor_options
2587 = (char **) xrealloc (preprocessor_options,
2588 n_preprocessor_options * sizeof (char **));
2590 /* Split the argument at commas. */
2592 for (j = 4; argv[i][j]; j++)
2593 if (argv[i][j] == ',')
2595 preprocessor_options[n_preprocessor_options - 1]
2596 = save_string (argv[i] + prev, j - prev);
2597 n_preprocessor_options++;
2598 preprocessor_options
2599 = (char **) xrealloc (preprocessor_options,
2600 n_preprocessor_options * sizeof (char **));
2603 /* Record the part after the last comma. */
2604 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2606 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2607 /* The +e options to the C++ front-end. */
2609 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2612 /* Split the argument at commas. */
2613 for (j = 3; argv[i][j]; j++)
2614 n_infiles += (argv[i][j] == ',');
2616 else if (strcmp (argv[i], "-Xlinker") == 0)
2619 fatal ("argument to `-Xlinker' is missing");
2624 else if (strncmp (argv[i], "-l", 2) == 0)
2626 else if (strcmp (argv[i], "-save-temps") == 0)
2628 save_temps_flag = 1;
2631 else if (strcmp (argv[i], "-specs") == 0)
2633 struct user_specs *user = (struct user_specs *)
2634 xmalloc (sizeof (struct user_specs));
2636 fatal ("argument to `-specs' is missing");
2638 user->next = (struct user_specs *)0;
2639 user->filename = argv[i];
2640 if (user_specs_tail)
2641 user_specs_tail->next = user;
2643 user_specs_head = user;
2644 user_specs_tail = user;
2646 else if (strncmp (argv[i], "-specs=", 7) == 0)
2648 struct user_specs *user = (struct user_specs *)
2649 xmalloc (sizeof (struct user_specs));
2650 if (strlen (argv[i]) == 7)
2651 fatal ("argument to `-specs=' is missing");
2653 user->next = (struct user_specs *)0;
2654 user->filename = argv[i]+7;
2655 if (user_specs_tail)
2656 user_specs_tail->next = user;
2658 user_specs_head = user;
2659 user_specs_tail = user;
2661 else if (argv[i][0] == '-' && argv[i][1] != 0)
2663 register char *p = &argv[i][1];
2664 register int c = *p;
2670 if (p[1] == 0 && i + 1 == argc)
2671 fatal ("argument to `-b' is missing");
2673 spec_machine = argv[++i];
2675 spec_machine = p + 1;
2677 warn_std_ptr = &warn_std;
2683 if (p[1] == 0 && i + 1 == argc)
2684 fatal ("argument to `-B' is missing");
2689 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2690 add_prefix (&startfile_prefixes, value, NULL_PTR,
2692 add_prefix (&include_prefixes, concat (value, "include",
2694 NULL_PTR, 1, 0, NULL_PTR);
2696 /* As a kludge, if the arg is "[foo/]stageN/", just add
2697 "[foo/]include" to the include prefix. */
2699 int len = strlen (value);
2702 && (value[len - 8] == '/'
2703 || value[len - 8] == DIR_SEPARATOR)))
2704 && strncmp (value + len - 7, "stage", 5) == 0
2705 && ISDIGIT (value[len - 2])
2706 && (value[len - 1] == '/'
2707 || value[len - 1] == DIR_SEPARATOR))
2710 add_prefix (&include_prefixes, "include", NULL_PTR,
2714 char *string = xmalloc (len + 1);
2715 strncpy (string, value, len-7);
2716 strcpy (string+len-7, "include");
2717 add_prefix (&include_prefixes, string, NULL_PTR,
2726 case 'v': /* Print our subcommands and print versions. */
2728 /* If they do anything other than exactly `-v', don't set
2729 verbose_flag; rather, continue on to give the error. */
2737 if (p[1] == 0 && i + 1 == argc)
2738 fatal ("argument to `-V' is missing");
2740 spec_version = argv[++i];
2742 spec_version = p + 1;
2743 compiler_version = spec_version;
2744 warn_std_ptr = &warn_std;
2758 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2759 argv[i] = convert_filename (argv[i], 1);
2761 argv[i+1] = convert_filename (argv[i+1], 1);
2769 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2770 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2771 else if (WORD_SWITCH_TAKES_ARG (p))
2772 i += WORD_SWITCH_TAKES_ARG (p);
2782 if (have_c && have_o && lang_n_infiles > 1)
2783 fatal ("cannot specify -o with -c and multiple compilations");
2785 /* Set up the search paths before we go looking for config files. */
2787 /* These come before the md prefixes so that we will find gcc's subcommands
2788 (such as cpp) rather than those of the host system. */
2789 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2790 as well as trying the machine and the version. */
2792 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
2793 0, 2, warn_std_ptr);
2794 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
2795 0, 2, warn_std_ptr);
2798 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
2799 0, 1, warn_std_ptr);
2800 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
2801 0, 1, warn_std_ptr);
2803 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
2804 dir_separator_str, NULL_PTR);
2806 /* If tooldir is relative, base it on exec_prefixes. A relative
2807 tooldir lets us move the installed tree as a unit.
2809 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2810 directories, so that we can search both the user specified directory
2811 and the standard place. */
2813 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2815 if (gcc_exec_prefix)
2817 char *gcc_exec_tooldir_prefix
2818 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2819 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2821 add_prefix (&exec_prefixes,
2822 concat (gcc_exec_tooldir_prefix, "bin",
2823 dir_separator_str, NULL_PTR),
2824 NULL_PTR, 0, 0, NULL_PTR);
2825 add_prefix (&startfile_prefixes,
2826 concat (gcc_exec_tooldir_prefix, "lib",
2827 dir_separator_str, NULL_PTR),
2828 NULL_PTR, 0, 0, NULL_PTR);
2831 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2832 dir_separator_str, spec_version,
2833 dir_separator_str, tooldir_prefix, NULL_PTR);
2836 add_prefix (&exec_prefixes,
2837 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2838 "BINUTILS", 0, 0, NULL_PTR);
2839 add_prefix (&startfile_prefixes,
2840 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2841 "BINUTILS", 0, 0, NULL_PTR);
2843 /* More prefixes are enabled in main, after we read the specs file
2844 and determine whether this is cross-compilation or not. */
2847 /* Then create the space for the vectors and scan again. */
2849 switches = ((struct switchstr *)
2850 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2851 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2854 last_language_n_infiles = -1;
2856 /* This, time, copy the text of each switch and store a pointer
2857 to the copy in the vector of switches.
2858 Store all the infiles in their vector. */
2860 for (i = 1; i < argc; i++)
2862 /* Just skip the switches that were handled by the preceding loop. */
2863 if (! strncmp (argv[i], "-Wa,", 4))
2865 else if (! strncmp (argv[i], "-Wp,", 4))
2867 else if (! strcmp (argv[i], "-print-search-dirs"))
2869 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2871 else if (! strncmp (argv[i], "-print-file-name=", 17))
2873 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2875 else if (! strcmp (argv[i], "-print-multi-lib"))
2877 else if (! strcmp (argv[i], "-print-multi-directory"))
2879 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2881 /* Compensate for the +e options to the C++ front-end;
2882 they're there simply for cfront call-compatibility. We do
2883 some magic in default_compilers to pass them down properly.
2884 Note we deliberately start at the `+' here, to avoid passing
2885 -e0 or -e1 down into the linker. */
2886 switches[n_switches].part1 = &argv[i][0];
2887 switches[n_switches].args = 0;
2888 switches[n_switches].live_cond = 0;
2889 switches[n_switches].valid = 0;
2892 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2895 /* Split the argument at commas. */
2897 for (j = 4; argv[i][j]; j++)
2898 if (argv[i][j] == ',')
2900 infiles[n_infiles].language = 0;
2901 infiles[n_infiles++].name
2902 = save_string (argv[i] + prev, j - prev);
2905 /* Record the part after the last comma. */
2906 infiles[n_infiles].language = 0;
2907 infiles[n_infiles++].name = argv[i] + prev;
2909 else if (strcmp (argv[i], "-Xlinker") == 0)
2911 infiles[n_infiles].language = 0;
2912 infiles[n_infiles++].name = argv[++i];
2914 else if (strncmp (argv[i], "-l", 2) == 0)
2916 infiles[n_infiles].language = 0;
2917 infiles[n_infiles++].name = argv[i];
2919 else if (strcmp (argv[i], "-specs") == 0)
2921 else if (strncmp (argv[i], "-specs=", 7) == 0)
2923 /* -save-temps overrides -pipe, so that temp files are produced */
2924 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
2925 error ("Warning: -pipe ignored since -save-temps specified");
2926 else if (argv[i][0] == '-' && argv[i][1] != 0)
2928 register char *p = &argv[i][1];
2929 register int c = *p;
2933 if (p[1] == 0 && i + 1 == argc)
2934 fatal ("argument to `-x' is missing");
2936 spec_lang = argv[++i];
2939 if (! strcmp (spec_lang, "none"))
2940 /* Suppress the warning if -xnone comes after the last input
2941 file, because alternate command interfaces like g++ might
2942 find it useful to place -xnone after each input file. */
2945 last_language_n_infiles = n_infiles;
2948 switches[n_switches].part1 = p;
2949 /* Deal with option arguments in separate argv elements. */
2950 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2951 || WORD_SWITCH_TAKES_ARG (p))
2954 int n_args = WORD_SWITCH_TAKES_ARG (p);
2958 /* Count only the option arguments in separate argv elements. */
2959 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2961 if (i + n_args >= argc)
2962 fatal ("argument to `-%s' is missing", p);
2963 switches[n_switches].args
2964 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2966 switches[n_switches].args[j++] = argv[++i];
2967 /* Null-terminate the vector. */
2968 switches[n_switches].args[j] = 0;
2970 else if (index (switches_need_spaces, c))
2972 /* On some systems, ld cannot handle some options without
2973 a space. So split the option from its argument. */
2974 char *part1 = (char *) xmalloc (2);
2978 switches[n_switches].part1 = part1;
2979 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2980 switches[n_switches].args[0] = xmalloc (strlen (p));
2981 strcpy (switches[n_switches].args[0], &p[1]);
2982 switches[n_switches].args[1] = 0;
2985 switches[n_switches].args = 0;
2987 switches[n_switches].live_cond = 0;
2988 switches[n_switches].valid = 0;
2989 /* This is always valid, since gcc.c itself understands it. */
2990 if (!strcmp (p, "save-temps"))
2991 switches[n_switches].valid = 1;
2994 char ch = switches[n_switches].part1[0];
2995 if (ch == 'V' || ch == 'b' || ch == 'B')
2996 switches[n_switches].valid = 1;
3002 #ifdef HAVE_OBJECT_SUFFIX
3003 argv[i] = convert_filename (argv[i], 0);
3006 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3008 perror_with_name (argv[i]);
3013 infiles[n_infiles].language = spec_lang;
3014 infiles[n_infiles++].name = argv[i];
3019 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3020 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3022 switches[n_switches].part1 = 0;
3023 infiles[n_infiles].name = 0;
3026 /* Process a spec string, accumulating and running commands. */
3028 /* These variables describe the input file name.
3029 input_file_number is the index on outfiles of this file,
3030 so that the output file name can be stored for later use by %o.
3031 input_basename is the start of the part of the input file
3032 sans all directory names, and basename_length is the number
3033 of characters starting there excluding the suffix .c or whatever. */
3035 static char *input_filename;
3036 static int input_file_number;
3037 static size_t input_filename_length;
3038 static int basename_length;
3039 static char *input_basename;
3040 static char *input_suffix;
3042 /* These are variables used within do_spec and do_spec_1. */
3044 /* Nonzero if an arg has been started and not yet terminated
3045 (with space, tab or newline). */
3046 static int arg_going;
3048 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3049 is a temporary file name. */
3050 static int delete_this_arg;
3052 /* Nonzero means %w has been seen; the next arg to be terminated
3053 is the output file name of this compilation. */
3054 static int this_is_output_file;
3056 /* Nonzero means %s has been seen; the next arg to be terminated
3057 is the name of a library file and we should try the standard
3058 search dirs for it. */
3059 static int this_is_library_file;
3061 /* Nonzero means that the input of this command is coming from a pipe. */
3062 static int input_from_pipe;
3064 /* Process the spec SPEC and run the commands specified therein.
3065 Returns 0 if the spec is successfully processed; -1 if failed. */
3075 delete_this_arg = 0;
3076 this_is_output_file = 0;
3077 this_is_library_file = 0;
3078 input_from_pipe = 0;
3080 value = do_spec_1 (spec, 0, NULL_PTR);
3082 /* Force out any unfinished command.
3083 If -pipe, this forces out the last command if it ended in `|'. */
3086 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3089 if (argbuf_index > 0)
3096 /* Process the sub-spec SPEC as a portion of a larger spec.
3097 This is like processing a whole spec except that we do
3098 not initialize at the beginning and we do not supply a
3099 newline by default at the end.
3100 INSWITCH nonzero means don't process %-sequences in SPEC;
3101 in this case, % is treated as an ordinary character.
3102 This is used while substituting switches.
3103 INSWITCH nonzero also causes SPC not to terminate an argument.
3105 Value is zero unless a line was finished
3106 and the command on that line reported an error. */
3109 do_spec_1 (spec, inswitch, soft_matched_part)
3112 char *soft_matched_part;
3114 register char *p = spec;
3121 /* If substituting a switch, treat all chars like letters.
3122 Otherwise, NL, SPC, TAB and % are special. */
3123 switch (inswitch ? 'a' : c)
3126 /* End of line: finish any pending argument,
3127 then run the pending command if one has been started. */
3130 obstack_1grow (&obstack, 0);
3131 string = obstack_finish (&obstack);
3132 if (this_is_library_file)
3133 string = find_file (string);
3134 store_arg (string, delete_this_arg, this_is_output_file);
3135 if (this_is_output_file)
3136 outfiles[input_file_number] = string;
3140 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3142 for (i = 0; i < n_switches; i++)
3143 if (!strcmp (switches[i].part1, "pipe"))
3146 /* A `|' before the newline means use a pipe here,
3147 but only if -pipe was specified.
3148 Otherwise, execute now and don't pass the `|' as an arg. */
3151 input_from_pipe = 1;
3152 switches[i].valid = 1;
3159 if (argbuf_index > 0)
3165 /* Reinitialize for a new command, and for a new argument. */
3168 delete_this_arg = 0;
3169 this_is_output_file = 0;
3170 this_is_library_file = 0;
3171 input_from_pipe = 0;
3175 /* End any pending argument. */
3178 obstack_1grow (&obstack, 0);
3179 string = obstack_finish (&obstack);
3180 if (this_is_library_file)
3181 string = find_file (string);
3182 store_arg (string, delete_this_arg, this_is_output_file);
3183 if (this_is_output_file)
3184 outfiles[input_file_number] = string;
3188 obstack_1grow (&obstack, c);
3194 /* Space or tab ends an argument if one is pending. */
3197 obstack_1grow (&obstack, 0);
3198 string = obstack_finish (&obstack);
3199 if (this_is_library_file)
3200 string = find_file (string);
3201 store_arg (string, delete_this_arg, this_is_output_file);
3202 if (this_is_output_file)
3203 outfiles[input_file_number] = string;
3205 /* Reinitialize for a new argument. */
3207 delete_this_arg = 0;
3208 this_is_output_file = 0;
3209 this_is_library_file = 0;
3216 fatal ("Invalid specification! Bug in cc.");
3219 obstack_grow (&obstack, input_basename, basename_length);
3224 delete_this_arg = 2;
3227 /* Dump out the directories specified with LIBRARY_PATH,
3228 followed by the absolute directories
3229 that we search for startfiles. */
3232 struct prefix_list *pl = startfile_prefixes.plist;
3233 size_t bufsize = 100;
3234 char *buffer = (char *) xmalloc (bufsize);
3237 for (; pl; pl = pl->next)
3239 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3240 /* Used on systems which record the specified -L dirs
3241 and use them to search for dynamic linking. */
3242 /* Relative directories always come from -B,
3243 and it is better not to use them for searching
3244 at run time. In particular, stage1 loses */
3245 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3248 /* Try subdirectory if there is one. */
3249 if (multilib_dir != NULL)
3253 if (strlen (pl->prefix) + strlen (machine_suffix)
3255 bufsize = (strlen (pl->prefix)
3256 + strlen (machine_suffix)) * 2 + 1;
3257 buffer = (char *) xrealloc (buffer, bufsize);
3258 strcpy (buffer, pl->prefix);
3259 strcat (buffer, machine_suffix);
3260 if (is_directory (buffer, multilib_dir, 1))
3262 do_spec_1 ("-L", 0, NULL_PTR);
3263 #ifdef SPACE_AFTER_L_OPTION
3264 do_spec_1 (" ", 0, NULL_PTR);
3266 do_spec_1 (buffer, 1, NULL_PTR);
3267 do_spec_1 (multilib_dir, 1, NULL_PTR);
3268 /* Make this a separate argument. */
3269 do_spec_1 (" ", 0, NULL_PTR);
3272 if (!pl->require_machine_suffix)
3274 if (is_directory (pl->prefix, multilib_dir, 1))
3276 do_spec_1 ("-L", 0, NULL_PTR);
3277 #ifdef SPACE_AFTER_L_OPTION
3278 do_spec_1 (" ", 0, NULL_PTR);
3280 do_spec_1 (pl->prefix, 1, NULL_PTR);
3281 do_spec_1 (multilib_dir, 1, NULL_PTR);
3282 /* Make this a separate argument. */
3283 do_spec_1 (" ", 0, NULL_PTR);
3289 if (is_directory (pl->prefix, machine_suffix, 1))
3291 do_spec_1 ("-L", 0, NULL_PTR);
3292 #ifdef SPACE_AFTER_L_OPTION
3293 do_spec_1 (" ", 0, NULL_PTR);
3295 do_spec_1 (pl->prefix, 1, NULL_PTR);
3296 /* Remove slash from machine_suffix. */
3297 if (strlen (machine_suffix) >= bufsize)
3298 bufsize = strlen (machine_suffix) * 2 + 1;
3299 buffer = (char *) xrealloc (buffer, bufsize);
3300 strcpy (buffer, machine_suffix);
3301 idx = strlen (buffer);
3302 if (buffer[idx - 1] == '/'
3303 || buffer[idx - 1] == DIR_SEPARATOR)
3304 buffer[idx - 1] = 0;
3305 do_spec_1 (buffer, 1, NULL_PTR);
3306 /* Make this a separate argument. */
3307 do_spec_1 (" ", 0, NULL_PTR);
3310 if (!pl->require_machine_suffix)
3312 if (is_directory (pl->prefix, "", 1))
3314 do_spec_1 ("-L", 0, NULL_PTR);
3315 #ifdef SPACE_AFTER_L_OPTION
3316 do_spec_1 (" ", 0, NULL_PTR);
3318 /* Remove slash from pl->prefix. */
3319 if (strlen (pl->prefix) >= bufsize)
3320 bufsize = strlen (pl->prefix) * 2 + 1;
3321 buffer = (char *) xrealloc (buffer, bufsize);
3322 strcpy (buffer, pl->prefix);
3323 idx = strlen (buffer);
3324 if (buffer[idx - 1] == '/'
3325 || buffer[idx - 1] == DIR_SEPARATOR)
3326 buffer[idx - 1] = 0;
3327 do_spec_1 (buffer, 1, NULL_PTR);
3328 /* Make this a separate argument. */
3329 do_spec_1 (" ", 0, NULL_PTR);
3338 /* {...:%efoo} means report an error with `foo' as error message
3339 and don't execute any more commands for this file. */
3343 while (*p != 0 && *p != '\n') p++;
3344 buf = (char *) alloca (p - q + 1);
3345 strncpy (buf, q, p - q);
3355 if (save_temps_flag)
3357 obstack_grow (&obstack, input_basename, basename_length);
3358 delete_this_arg = 0;
3362 #ifdef MKTEMP_EACH_FILE
3363 /* ??? This has a problem: the total number of
3364 values mktemp can return is limited.
3365 That matters for the names of object files.
3366 In 2.4, do something about that. */
3367 struct temp_name *t;
3369 while (*p == '.' || ISALPHA (*p)
3370 || (p[0] == '%' && p[1] == 'O'))
3373 /* See if we already have an association of %g/%u/%U and
3375 for (t = temp_names; t; t = t->next)
3376 if (t->length == p - suffix
3377 && strncmp (t->suffix, suffix, p - suffix) == 0
3378 && t->unique == (c != 'g'))
3381 /* Make a new association if needed. %u requires one. */
3382 if (t == 0 || c == 'u')
3386 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3387 t->next = temp_names;
3390 t->length = p - suffix;
3391 t->suffix = save_string (suffix, p - suffix);
3392 t->unique = (c != 'g');
3393 temp_filename = choose_temp_base ();
3394 temp_filename_length = strlen (temp_filename);
3395 t->filename = temp_filename;
3396 t->filename_length = temp_filename_length;
3399 obstack_grow (&obstack, t->filename, t->filename_length);
3400 delete_this_arg = 1;
3402 obstack_grow (&obstack, temp_filename, temp_filename_length);
3403 if (c == 'u' || c == 'U')
3409 sprintf (buff, "%d", unique);
3410 obstack_grow (&obstack, buff, strlen (buff));
3413 delete_this_arg = 1;
3419 obstack_grow (&obstack, input_filename, input_filename_length);
3425 struct prefix_list *pl = include_prefixes.plist;
3427 if (gcc_exec_prefix)
3429 do_spec_1 ("-iprefix", 1, NULL_PTR);
3430 /* Make this a separate argument. */
3431 do_spec_1 (" ", 0, NULL_PTR);
3432 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3433 do_spec_1 (" ", 0, NULL_PTR);
3436 for (; pl; pl = pl->next)
3438 do_spec_1 ("-isystem", 1, NULL_PTR);
3439 /* Make this a separate argument. */
3440 do_spec_1 (" ", 0, NULL_PTR);
3441 do_spec_1 (pl->prefix, 1, NULL_PTR);
3442 do_spec_1 (" ", 0, NULL_PTR);
3448 for (i = 0; i < n_infiles; i++)
3449 store_arg (outfiles[i], 0, 0);
3453 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3458 this_is_library_file = 1;
3462 this_is_output_file = 1;
3467 int cur_index = argbuf_index;
3468 /* Handle the {...} following the %W. */
3471 p = handle_braces (p + 1);
3474 /* If any args were output, mark the last one for deletion
3476 if (argbuf_index != cur_index)
3477 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3481 /* %x{OPTION} records OPTION for %X to output. */
3487 /* Skip past the option value and make a copy. */
3492 string = save_string (p1 + 1, p - p1 - 2);
3494 /* See if we already recorded this option. */
3495 for (i = 0; i < n_linker_options; i++)
3496 if (! strcmp (string, linker_options[i]))
3502 /* This option is new; add it. */
3504 if (!linker_options)
3506 = (char **) xmalloc (n_linker_options * sizeof (char **));
3509 = (char **) xrealloc (linker_options,
3510 n_linker_options * sizeof (char **));
3512 linker_options[n_linker_options - 1] = string;
3516 /* Dump out the options accumulated previously using %x. */
3518 for (i = 0; i < n_linker_options; i++)
3520 do_spec_1 (linker_options[i], 1, NULL_PTR);
3521 /* Make each accumulated option a separate argument. */
3522 do_spec_1 (" ", 0, NULL_PTR);
3526 /* Dump out the options accumulated previously using -Wa,. */
3528 for (i = 0; i < n_assembler_options; i++)
3530 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3531 /* Make each accumulated option a separate argument. */
3532 do_spec_1 (" ", 0, NULL_PTR);
3536 /* Dump out the options accumulated previously using -Wp,. */
3538 for (i = 0; i < n_preprocessor_options; i++)
3540 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3541 /* Make each accumulated option a separate argument. */
3542 do_spec_1 (" ", 0, NULL_PTR);
3546 /* Here are digits and numbers that just process
3547 a certain constant string as a spec. */
3550 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3556 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3562 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3568 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3574 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3580 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3586 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3592 value = do_spec_1 (link_spec, 0, NULL_PTR);
3598 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3604 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3611 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3615 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3619 if (! strncmp (y, "-D", 2))
3620 /* Copy the whole option. */
3621 while (*y && *y != ' ' && *y != '\t')
3623 else if (*y == ' ' || *y == '\t')
3624 /* Copy whitespace to the result. */
3626 /* Don't copy other options. */
3633 value = do_spec_1 (buf, 0, NULL_PTR);
3641 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3645 /* Copy all of CPP_PREDEFINES into BUF,
3646 but put __ after every -D and at the end of each arg. */
3650 if (! strncmp (y, "-D", 2))
3658 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3660 /* Stick __ at front of macro name. */
3663 /* Arrange to stick __ at the end as well. */
3667 /* Copy the macro name. */
3668 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3677 /* Copy the value given, if any. */
3678 while (*y && *y != ' ' && *y != '\t')
3681 else if (*y == ' ' || *y == '\t')
3682 /* Copy whitespace to the result. */
3684 /* Don't copy -A options */
3690 /* Copy all of CPP_PREDEFINES into BUF,
3691 but put __ after every -D. */
3695 if (! strncmp (y, "-D", 2))
3700 || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3702 /* Stick -D__ at front of macro name. */
3708 /* Copy the macro name. */
3709 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3712 /* Copy the value given, if any. */
3713 while (*y && *y != ' ' && *y != '\t')
3718 /* Do not copy this macro - we have just done it before */
3719 while (*y && *y != ' ' && *y != '\t')
3723 else if (*y == ' ' || *y == '\t')
3724 /* Copy whitespace to the result. */
3726 /* Don't copy -A options */
3732 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3736 if (! strncmp (y, "-A", 2))
3737 /* Copy the whole option. */
3738 while (*y && *y != ' ' && *y != '\t')
3740 else if (*y == ' ' || *y == '\t')
3741 /* Copy whitespace to the result. */
3743 /* Don't copy other options. */
3750 value = do_spec_1 (buf, 0, NULL_PTR);
3757 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3762 /* Here we define characters other than letters and digits. */
3765 p = handle_braces (p);
3771 obstack_1grow (&obstack, '%');
3775 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3776 do_spec_1 (" ", 0, NULL_PTR);
3779 /* Process a string found as the value of a spec given by name.
3780 This feature allows individual machine descriptions
3781 to add and use their own specs.
3782 %[...] modifies -D options the way %P does;
3783 %(...) uses the spec unmodified. */
3788 struct spec_list *sl;
3791 /* The string after the S/P is the name of a spec that is to be
3793 while (*p && *p != ')' && *p != ']')
3796 /* See if it's in the list */
3797 for (len = p - name, sl = specs; sl; sl = sl->next)
3798 if (sl->name_len == len && !strncmp (sl->name, name, len))
3800 name = *(sl->ptr_spec);
3802 fprintf (stderr, "Processing spec %c%s%c, which is '%s'\n",
3803 c, sl->name, (c == '(') ? ')' : ']', name);
3812 value = do_spec_1 (name, 0, NULL_PTR);
3818 char *x = (char *) alloca (strlen (name) * 2 + 1);
3822 /* Copy all of NAME into BUF, but put __ after
3823 every -D and at the end of each arg, */
3828 if (! strncmp (y, "-D", 2))
3838 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
3839 || *y == '}' || *y == 0))
3852 value = do_spec_1 (buf, 0, NULL_PTR);
3858 /* Discard the closing paren or bracket. */
3866 int c1 = *p++; /* Select first or second version number. */
3867 char *v = compiler_version;
3870 /* The format of the version string is
3871 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3873 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3874 while (! ISDIGIT (*v))
3876 if (v > compiler_version && v[-1] != '-')
3879 /* If desired, advance to second version number. */
3882 /* Set V after the first period. */
3883 while (ISDIGIT (*v))
3890 /* Set Q at the next period or at the end. */
3892 while (ISDIGIT (*q))
3894 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3897 /* Put that part into the command. */
3898 obstack_grow (&obstack, v, q - v);
3904 if (input_from_pipe)
3905 do_spec_1 ("-", 0, NULL_PTR);
3914 /* Backslash: treat next character as ordinary. */
3919 /* Ordinary character: put it into the current argument. */
3920 obstack_1grow (&obstack, c);
3924 return 0; /* End of string */
3927 /* Return 0 if we call do_spec_1 and that returns -1. */
3938 int include_blanks = 1;
3941 /* A '^' after the open-brace means to not give blanks before args. */
3942 include_blanks = 0, ++p;
3945 /* A `|' after the open-brace means,
3946 if the test fails, output a single minus sign rather than nothing.
3947 This is used in %{|!pipe:...}. */
3951 /* A `!' after the open-brace negates the condition:
3952 succeed if the specified switch is not present. */
3956 /* A `.' after the open-brace means test against the current suffix. */
3966 while (*p != ':' && *p != '}') p++;
3969 register int count = 1;
3987 int found = (input_suffix != 0
3988 && strlen (input_suffix) == p - filter
3989 && strncmp (input_suffix, filter, p - filter) == 0);
3995 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4000 else if (p[-1] == '*' && p[0] == '}')
4002 /* Substitute all matching switches as separate args. */
4005 for (i = 0; i < n_switches; i++)
4006 if (!strncmp (switches[i].part1, filter, p - filter)
4007 && check_live_switch (i, p - filter))
4008 give_switch (i, 0, include_blanks);
4012 /* Test for presence of the specified switch. */
4016 /* If name specified ends in *, as in {x*:...},
4017 check for %* and handle that case. */
4018 if (p[-1] == '*' && !negate)
4023 /* First see whether we have %*. */
4027 if (*r == '%' && r[1] == '*')
4031 /* If we do, handle that case. */
4034 /* Substitute all matching switches as separate args.
4035 But do this by substituting for %*
4036 in the text that follows the colon. */
4038 unsigned hard_match_len = p - filter - 1;
4039 char *string = save_string (p + 1, q - p - 2);
4041 for (i = 0; i < n_switches; i++)
4042 if (!strncmp (switches[i].part1, filter, hard_match_len)
4043 && check_live_switch (i, -1))
4045 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4046 /* Pass any arguments this switch has. */
4047 give_switch (i, 1, 1);
4054 /* If name specified ends in *, as in {x*:...},
4055 check for presence of any switch name starting with x. */
4058 for (i = 0; i < n_switches; i++)
4060 unsigned hard_match_len = p - filter - 1;
4062 if (!strncmp (switches[i].part1, filter, hard_match_len)
4063 && check_live_switch (i, hard_match_len))
4069 /* Otherwise, check for presence of exact name specified. */
4072 for (i = 0; i < n_switches; i++)
4074 if (!strncmp (switches[i].part1, filter, p - filter)
4075 && switches[i].part1[p - filter] == 0
4076 && check_live_switch (i, -1))
4084 /* If it is as desired (present for %{s...}, absent for %{-s...})
4085 then substitute either the switch or the specified
4086 conditional text. */
4087 if (present != negate)
4091 give_switch (i, 0, include_blanks);
4095 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4101 /* Here if a %{|...} conditional fails: output a minus sign,
4102 which means "standard output" or "standard input". */
4103 do_spec_1 ("-", 0, NULL_PTR);
4110 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4111 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4112 spec, or -1 if either exact match or %* is used.
4114 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4115 whose value does not begin with "no-" is obsoleted by the same value
4116 with the "no-", similarly for a switch with the "no-" prefix. */
4119 check_live_switch (switchnum, prefix_length)
4123 char *name = switches[switchnum].part1;
4126 /* In the common case of {<at-most-one-letter>*}, a negating
4127 switch would always match, so ignore that case. We will just
4128 send the conflicting switches to the compiler phase. */
4129 if (prefix_length >= 0 && prefix_length <= 1)
4132 /* If we already processed this switch and determined if it was
4133 live or not, return our past determination. */
4134 if (switches[switchnum].live_cond != 0)
4135 return switches[switchnum].live_cond > 0;
4137 /* Now search for duplicate in a manner that depends on the name. */
4141 for (i = switchnum + 1; i < n_switches; i++)
4142 if (switches[i].part1[0] == 'O')
4144 switches[switchnum].valid = 1;
4145 switches[switchnum].live_cond = -1;
4150 case 'W': case 'f': case 'm':
4151 if (! strncmp (name + 1, "no-", 3))
4153 /* We have Xno-YYY, search for XYYY. */
4154 for (i = switchnum + 1; i < n_switches; i++)
4155 if (switches[i].part1[0] == name[0]
4156 && ! strcmp (&switches[i].part1[1], &name[4]))
4158 switches[switchnum].valid = 1;
4159 switches[switchnum].live_cond = -1;
4165 /* We have XYYY, search for Xno-YYY. */
4166 for (i = switchnum + 1; i < n_switches; i++)
4167 if (switches[i].part1[0] == name[0]
4168 && switches[i].part1[1] == 'n'
4169 && switches[i].part1[2] == 'o'
4170 && switches[i].part1[3] == '-'
4171 && !strcmp (&switches[i].part1[4], &name[1]))
4173 switches[switchnum].valid = 1;
4174 switches[switchnum].live_cond = -1;
4181 /* Otherwise the switch is live. */
4182 switches[switchnum].live_cond = 1;
4186 /* Pass a switch to the current accumulating command
4187 in the same form that we received it.
4188 SWITCHNUM identifies the switch; it is an index into
4189 the vector of switches gcc received, which is `switches'.
4190 This cannot fail since it never finishes a command line.
4192 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4194 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4198 give_switch (switchnum, omit_first_word, include_blanks)
4200 int omit_first_word;
4203 if (!omit_first_word)
4205 do_spec_1 ("-", 0, NULL_PTR);
4206 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4209 if (switches[switchnum].args != 0)
4212 for (p = switches[switchnum].args; *p; p++)
4215 do_spec_1 (" ", 0, NULL_PTR);
4216 do_spec_1 (*p, 1, NULL_PTR);
4220 do_spec_1 (" ", 0, NULL_PTR);
4221 switches[switchnum].valid = 1;
4224 /* Search for a file named NAME trying various prefixes including the
4225 user's -B prefix and some standard ones.
4226 Return the absolute file name found. If nothing is found, return NAME. */
4234 /* Try multilib_dir if it is defined. */
4235 if (multilib_dir != NULL)
4239 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4240 strcpy (try, multilib_dir);
4241 strcat (try, dir_separator_str);
4244 newname = find_a_file (&startfile_prefixes, try, R_OK);
4246 /* If we don't find it in the multi library dir, then fall
4247 through and look for it in the normal places. */
4248 if (newname != NULL)
4252 newname = find_a_file (&startfile_prefixes, name, R_OK);
4253 return newname ? newname : name;
4256 /* Determine whether a directory exists. If LINKER, return 0 for
4257 certain fixed names not needed by the linker. If not LINKER, it is
4258 only important to return 0 if the host machine has a small ARG_MAX
4262 is_directory (path1, path2, linker)
4267 int len1 = strlen (path1);
4268 int len2 = strlen (path2);
4269 char *path = (char *) alloca (3 + len1 + len2);
4273 #ifndef SMALL_ARG_MAX
4278 /* Construct the path from the two parts. Ensure the string ends with "/.".
4279 The resulting path will be a directory even if the given path is a
4281 bcopy (path1, path, len1);
4282 bcopy (path2, path + len1, len2);
4283 cp = path + len1 + len2;
4284 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4285 *cp++ = DIR_SEPARATOR;
4289 /* Exclude directories that the linker is known to search. */
4292 && strcmp (path, concat (dir_separator_str, "lib",
4293 dir_separator_str, ".", NULL_PTR)) == 0)
4295 && strcmp (path, concat (dir_separator_str, "usr",
4296 dir_separator_str, "lib",
4297 dir_separator_str, ".", NULL_PTR)) == 0)))
4300 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4303 /* On fatal signals, delete all the temporary files. */
4306 fatal_error (signum)
4309 signal (signum, SIG_DFL);
4310 delete_failure_queue ();
4311 delete_temp_files ();
4312 /* Get the same signal again, this time not handled,
4313 so its normal effect occurs. */
4314 kill (getpid (), signum);
4325 int linker_was_run = 0;
4326 char *explicit_link_files;
4329 struct user_specs *uptr;
4331 p = argv[0] + strlen (argv[0]);
4332 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4335 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4336 signal (SIGINT, fatal_error);
4338 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4339 signal (SIGHUP, fatal_error);
4341 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4342 signal (SIGTERM, fatal_error);
4344 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4345 signal (SIGPIPE, fatal_error);
4349 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4351 obstack_init (&obstack);
4353 /* Build multilib_select, et. al from the separate lines that make up each
4354 multilib selection. */
4356 char **q = multilib_raw;
4359 obstack_init (&multilib_obstack);
4360 while ((p = *q++) != (char *) 0)
4361 obstack_grow (&multilib_obstack, p, strlen (p));
4363 obstack_1grow (&multilib_obstack, 0);
4364 multilib_select = obstack_finish (&multilib_obstack);
4366 q = multilib_matches_raw;
4367 while ((p = *q++) != (char *) 0)
4368 obstack_grow (&multilib_obstack, p, strlen (p));
4370 obstack_1grow (&multilib_obstack, 0);
4371 multilib_matches = obstack_finish (&multilib_obstack);
4375 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4379 obstack_1grow (&multilib_obstack, ' ');
4380 obstack_grow (&multilib_obstack,
4381 multilib_defaults_raw[i],
4382 strlen (multilib_defaults_raw[i]));
4386 obstack_1grow (&multilib_obstack, 0);
4387 multilib_defaults = obstack_finish (&multilib_obstack);
4390 /* Set up to remember the pathname of gcc and any options
4391 needed for collect. We use argv[0] instead of programname because
4392 we need the complete pathname. */
4393 obstack_init (&collect_obstack);
4394 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4395 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4396 putenv (obstack_finish (&collect_obstack));
4398 #ifdef INIT_ENVIRONMENT
4399 /* Set up any other necessary machine specific environment variables. */
4400 putenv (INIT_ENVIRONMENT);
4403 /* Choose directory for temp files. */
4405 temp_filename = choose_temp_base ();
4406 temp_filename_length = strlen (temp_filename);
4408 /* Make a table of what switches there are (switches, n_switches).
4409 Make a table of specified input files (infiles, n_infiles).
4410 Decode switches that are handled locally. */
4412 process_command (argc, argv);
4417 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4419 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4420 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4423 for (i = 0; i < n_switches; i++)
4428 obstack_grow (&collect_obstack, " ", 1);
4431 obstack_grow (&collect_obstack, "'-", 2);
4432 q = switches[i].part1;
4433 while ((p = index (q,'\'')))
4435 obstack_grow (&collect_obstack, q, p-q);
4436 obstack_grow (&collect_obstack, "'\\''", 4);
4439 obstack_grow (&collect_obstack, q, strlen (q));
4440 obstack_grow (&collect_obstack, "'", 1);
4442 for (args = switches[i].args; args && *args; args++)
4444 obstack_grow (&collect_obstack, " '", 2);
4446 while ((p = index (q,'\'')))
4448 obstack_grow (&collect_obstack, q, p-q);
4449 obstack_grow (&collect_obstack, "'\\''", 4);
4452 obstack_grow (&collect_obstack, q, strlen (q));
4453 obstack_grow (&collect_obstack, "'", 1);
4456 obstack_grow (&collect_obstack, "\0", 1);
4457 putenv (obstack_finish (&collect_obstack));
4460 /* Initialize the vector of specs to just the default.
4461 This means one element containing 0s, as a terminator. */
4463 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4464 bcopy ((char *) default_compilers, (char *) compilers,
4465 sizeof default_compilers);
4466 n_compilers = n_default_compilers;
4468 /* Read specs from a file if there is one. */
4470 machine_suffix = concat (spec_machine, dir_separator_str,
4471 spec_version, dir_separator_str, NULL_PTR);
4472 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4474 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4475 /* Read the specs file unless it is a default one. */
4476 if (specs_file != 0 && strcmp (specs_file, "specs"))
4477 read_specs (specs_file, TRUE);
4481 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4482 for any override of as, ld and libraries. */
4483 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4484 + strlen (just_machine_suffix)
4485 + sizeof ("specs"));
4487 strcpy (specs_file, standard_exec_prefix);
4488 strcat (specs_file, just_machine_suffix);
4489 strcat (specs_file, "specs");
4490 if (access (specs_file, R_OK) == 0)
4491 read_specs (specs_file, TRUE);
4493 /* Process any user specified specs in the order given on the command
4495 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4497 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4498 read_specs (filename ? filename : uptr->filename, FALSE);
4501 /* If not cross-compiling, look for startfiles in the standard places. */
4502 /* The fact that these are done here, after reading the specs file,
4503 means that it cannot be found in these directories.
4504 But that's okay. It should never be there anyway. */
4505 if (*cross_compile == '0')
4507 #ifdef MD_EXEC_PREFIX
4508 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4509 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4512 #ifdef MD_STARTFILE_PREFIX
4513 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4517 #ifdef MD_STARTFILE_PREFIX_1
4518 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4522 /* If standard_startfile_prefix is relative, base it on
4523 standard_exec_prefix. This lets us move the installed tree
4524 as a unit. If GCC_EXEC_PREFIX is defined, base
4525 standard_startfile_prefix on that as well. */
4526 if (*standard_startfile_prefix == '/'
4527 || *standard_startfile_prefix == DIR_SEPARATOR)
4528 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4532 if (gcc_exec_prefix)
4533 add_prefix (&startfile_prefixes,
4534 concat (gcc_exec_prefix, machine_suffix,
4535 standard_startfile_prefix, NULL_PTR),
4536 NULL_PTR, 0, 0, NULL_PTR);
4537 add_prefix (&startfile_prefixes,
4538 concat (standard_exec_prefix,
4540 standard_startfile_prefix, NULL_PTR),
4541 NULL_PTR, 0, 0, NULL_PTR);
4544 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4545 "BINUTILS", 0, 0, NULL_PTR);
4546 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4547 "BINUTILS", 0, 0, NULL_PTR);
4548 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4549 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
4554 if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4555 add_prefix (&startfile_prefixes,
4556 concat (gcc_exec_prefix, machine_suffix,
4557 standard_startfile_prefix, NULL_PTR),
4558 "BINUTILS", 0, 0, NULL_PTR);
4561 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4562 if (gcc_exec_prefix)
4564 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4565 + strlen (spec_version)
4566 + strlen (spec_machine) + 3);
4567 strcpy (temp, gcc_exec_prefix);
4568 strcat (temp, spec_machine);
4569 strcat (temp, dir_separator_str);
4570 strcat (temp, spec_version);
4571 strcat (temp, dir_separator_str);
4572 gcc_exec_prefix = temp;
4575 /* Now we have the specs.
4576 Set the `valid' bits for switches that match anything in any spec. */
4578 validate_all_switches ();
4580 /* Now that we have the switches and the specs, set
4581 the subdirectory based on the options. */
4582 set_multilib_dir ();
4584 /* Warn about any switches that no pass was interested in. */
4586 for (i = 0; i < n_switches; i++)
4587 if (! switches[i].valid)
4588 error ("unrecognized option `-%s'", switches[i].part1);
4590 /* Obey some of the options. */
4592 if (print_search_dirs)
4594 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4595 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4596 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4600 if (print_file_name)
4602 printf ("%s\n", find_file (print_file_name));
4606 if (print_prog_name)
4608 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4609 printf ("%s\n", (newname ? newname : print_prog_name));
4613 if (print_multi_lib)
4615 print_multilib_info ();
4619 if (print_multi_directory)
4621 if (multilib_dir == NULL)
4624 printf ("%s\n", multilib_dir);
4632 /* compiler_version is truncated at the first space when initialized
4633 from version string, so truncate version_string at the first space
4634 before comparing. */
4635 for (n = 0; version_string[n]; n++)
4636 if (version_string[n] == ' ')
4639 if (! strncmp (version_string, compiler_version, n)
4640 && compiler_version[n] == 0)
4641 fprintf (stderr, "gcc version %s\n", version_string);
4643 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4644 version_string, compiler_version);
4651 fatal ("No input files");
4653 /* Make a place to record the compiler output file names
4654 that correspond to the input files. */
4656 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4657 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4659 /* Record which files were specified explicitly as link input. */
4661 explicit_link_files = xmalloc (n_infiles);
4662 bzero (explicit_link_files, n_infiles);
4664 for (i = 0; i < n_infiles; i++)
4666 register struct compiler *cp = 0;
4667 int this_file_error = 0;
4669 /* Tell do_spec what to substitute for %i. */
4671 input_filename = infiles[i].name;
4672 input_filename_length = strlen (input_filename);
4673 input_file_number = i;
4675 /* Use the same thing in %o, unless cp->spec says otherwise. */
4677 outfiles[i] = input_filename;
4679 /* Figure out which compiler from the file's suffix. */
4681 cp = lookup_compiler (infiles[i].name, input_filename_length,
4682 infiles[i].language);
4686 /* Ok, we found an applicable compiler. Run its spec. */
4687 /* First say how much of input_filename to substitute for %b */
4691 if (cp->spec[0][0] == '#')
4692 error ("%s: %s compiler not installed on this system",
4693 input_filename, &cp->spec[0][1]);
4695 input_basename = input_filename;
4696 for (p = input_filename; *p; p++)
4697 if (*p == '/' || *p == DIR_SEPARATOR)
4698 input_basename = p + 1;
4700 /* Find a suffix starting with the last period,
4701 and set basename_length to exclude that suffix. */
4702 basename_length = strlen (input_basename);
4703 p = input_basename + basename_length;
4704 while (p != input_basename && *p != '.') --p;
4705 if (*p == '.' && p != input_basename)
4707 basename_length = p - input_basename;
4708 input_suffix = p + 1;
4714 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4716 len += strlen (cp->spec[j]);
4718 p = (char *) xmalloc (len + 1);
4721 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4724 strcpy (p + len, cp->spec[j]);
4725 len += strlen (cp->spec[j]);
4728 value = do_spec (p);
4731 this_file_error = 1;
4734 /* If this file's name does not contain a recognized suffix,
4735 record it as explicit linker input. */
4738 explicit_link_files[i] = 1;
4740 /* Clear the delete-on-failure queue, deleting the files in it
4741 if this compilation failed. */
4743 if (this_file_error)
4745 delete_failure_queue ();
4748 /* If this compilation succeeded, don't delete those files later. */
4749 clear_failure_queue ();
4752 /* Run ld to link all the compiler output files. */
4754 if (error_count == 0)
4756 int tmp = execution_count;
4758 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4760 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4761 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4763 value = do_spec (link_command_spec);
4766 linker_was_run = (tmp != execution_count);
4769 /* Warn if a -B option was specified but the prefix was never used. */
4770 unused_prefix_warnings (&exec_prefixes);
4771 unused_prefix_warnings (&startfile_prefixes);
4773 /* If options said don't run linker,
4774 complain about input files to be given to the linker. */
4776 if (! linker_was_run && error_count == 0)
4777 for (i = 0; i < n_infiles; i++)
4778 if (explicit_link_files[i])
4779 error ("%s: linker input file unused since linking not done",
4782 /* Delete some or all of the temporary files we made. */
4785 delete_failure_queue ();
4786 delete_temp_files ();
4788 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4793 /* Find the proper compilation spec for the file name NAME,
4794 whose length is LENGTH. LANGUAGE is the specified language,
4795 or 0 if none specified. */
4797 static struct compiler *
4798 lookup_compiler (name, length, language)
4803 struct compiler *cp;
4805 /* Look for the language, if one is spec'd. */
4808 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4812 if (cp->suffix[0] == '@'
4813 && !strcmp (cp->suffix + 1, language))
4817 error ("language %s not recognized", language);
4820 /* Look for a suffix. */
4821 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4823 if (/* The suffix `-' matches only the file name `-'. */
4824 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4826 (strlen (cp->suffix) < length
4827 /* See if the suffix matches the end of NAME. */
4829 && (!strcmp (cp->suffix,
4830 name + length - strlen (cp->suffix))
4831 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4832 && !strcasecmp (cp->suffix,
4833 name + length - strlen (cp->suffix)))))
4835 && !strcmp (cp->suffix,
4836 name + length - strlen (cp->suffix))))
4839 if (cp->spec[0][0] == '@')
4841 struct compiler *new;
4842 /* An alias entry maps a suffix to a language.
4843 Search for the language; pass 0 for NAME and LENGTH
4844 to avoid infinite recursion if language not found.
4845 Construct the new compiler spec. */
4846 language = cp->spec[0] + 1;
4847 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4848 new->suffix = cp->suffix;
4849 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4850 (char *) new->spec, sizeof new->spec);
4853 /* A non-alias entry: return it. */
4865 register char *value = (char *) malloc (size);
4867 fatal ("virtual memory exhausted");
4872 xrealloc (ptr, size)
4876 register char *value = (char *) realloc (ptr, size);
4878 fatal ("virtual memory exhausted");
4882 /* This function is based on the one in libiberty. */
4885 concat VPROTO((char *first, ...))
4887 register int length;
4888 register char *newstr;
4896 /* First compute the size of the result and get sufficient memory. */
4898 VA_START (args, first);
4900 first = va_arg (args, char *);
4908 length += strlen (arg);
4909 arg = va_arg (args, char *);
4912 newstr = (char *) xmalloc (length + 1);
4915 /* Now copy the individual pieces to the result string. */
4917 VA_START (args, first);
4919 first = va_arg (args, char *);
4928 arg = va_arg (args, char *);
4937 save_string (s, len)
4941 register char *result = xmalloc (len + 1);
4943 bcopy (s, result, len);
4949 pfatal_with_name (name)
4952 fatal ("%s: %s", name, my_strerror (errno));
4956 perror_with_name (name)
4959 error ("%s: %s", name, my_strerror (errno));
4963 pfatal_pexecute (errmsg_fmt, errmsg_arg)
4969 /* Space for trailing '\0' is in %s. */
4970 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
4971 sprintf (msg, errmsg_fmt, errmsg_arg);
4975 fatal ("%s: %s", errmsg_fmt, my_strerror (errno));
4978 /* More 'friendly' abort that prints the line and file.
4979 config.h can #define abort fancy_abort if you like that sort of thing. */
4984 fatal ("Internal gcc abort.");
4989 /* Output an error message and exit */
4992 fatal VPROTO((char *format, ...))
4999 VA_START (ap, format);
5002 format = va_arg (ap, char *);
5005 fprintf (stderr, "%s: ", programname);
5006 vfprintf (stderr, format, ap);
5008 fprintf (stderr, "\n");
5009 delete_temp_files ();
5014 error VPROTO((char *format, ...))
5021 VA_START (ap, format);
5024 format = va_arg (ap, char *);
5027 fprintf (stderr, "%s: ", programname);
5028 vfprintf (stderr, format, ap);
5031 fprintf (stderr, "\n");
5034 #else /* not HAVE_VPRINTF */
5037 fatal (msg, arg1, arg2)
5038 char *msg, *arg1, *arg2;
5040 error (msg, arg1, arg2);
5041 delete_temp_files ();
5046 error (msg, arg1, arg2)
5047 char *msg, *arg1, *arg2;
5049 fprintf (stderr, "%s: ", programname);
5050 fprintf (stderr, msg, arg1, arg2);
5051 fprintf (stderr, "\n");
5054 #endif /* not HAVE_VPRINTF */
5058 validate_all_switches ()
5060 struct compiler *comp;
5063 struct spec_list *spec;
5065 for (comp = compilers; comp->spec[0]; comp++)
5068 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5072 if (c == '%' && *p == '{')
5073 /* We have a switch spec. */
5074 validate_switches (p + 1);
5078 /* look through the linked list of specs read from the specs file */
5079 for (spec = specs; spec ; spec = spec->next)
5081 p = *(spec->ptr_spec);
5083 if (c == '%' && *p == '{')
5084 /* We have a switch spec. */
5085 validate_switches (p + 1);
5088 p = link_command_spec;
5090 if (c == '%' && *p == '{')
5091 /* We have a switch spec. */
5092 validate_switches (p + 1);
5095 /* Look at the switch-name that comes after START
5096 and mark as valid all supplied switches that match it. */
5099 validate_switches (start)
5102 register char *p = start;
5117 while (*p != ':' && *p != '}') p++;
5121 else if (p[-1] == '*')
5123 /* Mark all matching switches as valid. */
5125 for (i = 0; i < n_switches; i++)
5126 if (!strncmp (switches[i].part1, filter, p - filter))
5127 switches[i].valid = 1;
5131 /* Mark an exact matching switch as valid. */
5132 for (i = 0; i < n_switches; i++)
5134 if (!strncmp (switches[i].part1, filter, p - filter)
5135 && switches[i].part1[p - filter] == 0)
5136 switches[i].valid = 1;
5141 /* Check whether a particular argument was used. The first time we
5142 canonicalize the switches to keep only the ones we care about. */
5156 static struct mswitchstr *mswitches;
5157 static int n_mswitches;
5162 struct mswitchstr *matches;
5166 /* Break multilib_matches into the component strings of string and replacement
5168 for (q = multilib_matches; *q != '\0'; q++)
5172 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5174 q = multilib_matches;
5185 matches[i].len = q - matches[i].str;
5187 matches[i].replace = ++q;
5188 while (*q != ';' && *q != '\0')
5194 matches[i].rep_len = q - matches[i].replace;
5202 /* Now build a list of the replacement string for switches that we care
5203 about. Make sure we allocate at least one entry. This prevents
5204 xmalloc from calling fatal, and prevents us from re-executing this
5207 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5208 * (n_switches ? n_switches : 1));
5209 for (i = 0; i < n_switches; i++)
5211 int xlen = strlen (switches[i].part1);
5212 for (j = 0; j < cnt; j++)
5213 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5215 mswitches[n_mswitches].str = matches[j].replace;
5216 mswitches[n_mswitches].len = matches[j].rep_len;
5217 mswitches[n_mswitches].replace = (char *)0;
5218 mswitches[n_mswitches].rep_len = 0;
5225 for (i = 0; i < n_mswitches; i++)
5226 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5233 default_arg (p, len)
5239 for (start = multilib_defaults; *start != '\0'; start = end+1)
5241 while (*start == ' ' || *start == '\t')
5247 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5250 if ((end - start) == len && strncmp (p, start, len) == 0)
5260 /* Work out the subdirectory to use based on the
5261 options. The format of multilib_select is a list of elements.
5262 Each element is a subdirectory name followed by a list of options
5263 followed by a semicolon. gcc will consider each line in turn. If
5264 none of the options beginning with an exclamation point are
5265 present, and all of the other options are present, that
5266 subdirectory will be used. */
5271 char *p = multilib_select;
5273 char *this_path, *this_arg;
5279 /* Ignore newlines. */
5286 /* Get the initial path. */
5294 this_path_len = p - this_path;
5296 /* Check the arguments. */
5311 while (*p != ' ' && *p != ';')
5318 if (*this_arg != '!')
5326 /* If this is a default argument, we can just ignore it.
5327 This is true even if this_arg begins with '!'. Beginning
5328 with '!' does not mean that this argument is necessarily
5329 inappropriate for this library: it merely means that
5330 there is a more specific library which uses this
5331 argument. If this argument is a default, we need not
5332 consider that more specific library. */
5333 if (! default_arg (this_arg, p - this_arg))
5335 ok = used_arg (this_arg, p - this_arg);
5346 if (this_path_len != 1
5347 || this_path[0] != '.')
5349 multilib_dir = xmalloc (this_path_len + 1);
5350 strncpy (multilib_dir, this_path, this_path_len);
5351 multilib_dir[this_path_len] = '\0';
5360 /* Print out the multiple library subdirectory selection
5361 information. This prints out a series of lines. Each line looks
5362 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5363 required. Only the desired options are printed out, the negative
5364 matches. The options are print without a leading dash. There are
5365 no spaces to make it easy to use the information in the shell.
5366 Each subdirectory is printed only once. This assumes the ordering
5367 generated by the genmultilib script. */
5370 print_multilib_info ()
5372 char *p = multilib_select;
5373 char *last_path = 0, *this_path;
5375 int last_path_len = 0;
5379 /* Ignore newlines. */
5386 /* Get the initial path. */
5395 /* If this is a duplicate, skip it. */
5396 skip = (last_path != 0 && p - this_path == last_path_len
5397 && ! strncmp (last_path, this_path, last_path_len));
5399 last_path = this_path;
5400 last_path_len = p - this_path;
5402 /* If this directory requires any default arguments, we can skip
5403 it. We will already have printed a directory identical to
5404 this one which does not require that default argument. */
5422 while (*q != ' ' && *q != ';')
5430 && default_arg (arg, q - arg))
5445 for (p1 = last_path; p1 < p; p1++)
5464 use_arg = *p != '!';
5469 while (*p != ' ' && *p != ';')
5484 /* If there are extra options, print them now */
5485 if (multilib_extra && *multilib_extra)
5487 int print_at = TRUE;
5490 for (q = multilib_extra; *q != '\0'; q++)