1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-98, 1999 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". */
43 #define exit __posix_exit
46 /* By default there is no special suffix for executables. */
47 #ifdef EXECUTABLE_SUFFIX
48 #define HAVE_EXECUTABLE_SUFFIX
50 #define EXECUTABLE_SUFFIX ""
53 /* By default, the suffix for object files is ".o". */
55 #define HAVE_OBJECT_SUFFIX
57 #define OBJECT_SUFFIX ".o"
60 /* By default, colon separates directories in a path. */
61 #ifndef PATH_SEPARATOR
62 #define PATH_SEPARATOR ':'
66 #define DIR_SEPARATOR '/'
69 /* Define IS_DIR_SEPARATOR. */
70 #ifndef DIR_SEPARATOR_2
71 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
72 #else /* DIR_SEPARATOR_2 */
73 # define IS_DIR_SEPARATOR(ch) \
74 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
75 #endif /* DIR_SEPARATOR_2 */
77 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
79 #define obstack_chunk_alloc xmalloc
80 #define obstack_chunk_free free
82 #ifndef GET_ENV_PATH_LIST
83 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
87 #define kill(p,s) raise(s)
90 /* If a stage of compilation returns an exit status >= 1,
91 compilation of that file ceases. */
93 #define MIN_FATAL_STATUS 1
95 /* Flag saying to print the directories gcc will search through looking for
96 programs, libraries, etc. */
98 static int print_search_dirs;
100 /* Flag saying to print the full filename of this file
101 as found through our usual search mechanism. */
103 static const char *print_file_name = NULL;
105 /* As print_file_name, but search for executable file. */
107 static const char *print_prog_name = NULL;
109 /* Flag saying to print the relative path we'd use to
110 find libgcc.a given the current compiler flags. */
112 static int print_multi_directory;
114 /* Flag saying to print the list of subdirectories and
115 compiler flags used to select them in a standard form. */
117 static int print_multi_lib;
119 /* Flag saying to print the command line options understood by gcc and its
122 static int print_help_list;
124 /* Flag indicating whether we should print the command and arguments */
126 static int verbose_flag;
128 /* Nonzero means write "temp" files in source directory
129 and use the source file's name in them, and don't delete them. */
131 static int save_temps_flag;
133 /* The compiler version. */
135 static char *compiler_version;
137 /* The target version specified with -V */
139 static char *spec_version = DEFAULT_TARGET_VERSION;
141 /* The target machine specified with -b. */
143 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
145 /* Nonzero if cross-compiling.
146 When -b is used, the value comes from the `specs' file. */
149 static char *cross_compile = "1";
151 static char *cross_compile = "0";
154 /* The number of errors that have occurred; the link phase will not be
155 run if this is non-zero. */
156 static int error_count = 0;
158 /* This is the obstack which we use to allocate many strings. */
160 static struct obstack obstack;
162 /* This is the obstack to build an environment variable to pass to
163 collect2 that describes all of the relevant switches of what to
164 pass the compiler in building the list of pointers to constructors
167 static struct obstack collect_obstack;
169 extern char *version_string;
171 /* Forward declaration for prototypes. */
174 static void init_spec PROTO((void));
175 static void read_specs PROTO((const char *, int));
176 static void set_spec PROTO((const char *, const char *));
177 static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
178 static char *build_search_list PROTO((struct path_prefix *, const char *, int));
179 static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
180 static char *find_a_file PROTO((struct path_prefix *, const char *, int));
181 static void add_prefix PROTO((struct path_prefix *, const char *,
182 const char *, int, int, int *));
183 static char *skip_whitespace PROTO((char *));
184 static void record_temp_file PROTO((const char *, int, int));
185 static void delete_if_ordinary PROTO((const char *));
186 static void delete_temp_files PROTO((void));
187 static void delete_failure_queue PROTO((void));
188 static void clear_failure_queue PROTO((void));
189 static int check_live_switch PROTO((int, int));
190 static const char *handle_braces PROTO((const char *));
191 static char *save_string PROTO((const char *, int));
192 extern int do_spec PROTO((const char *));
193 static int do_spec_1 PROTO((const char *, int, const char *));
194 static const char *find_file PROTO((const char *));
195 static int is_directory PROTO((const char *, const char *, int));
196 static void validate_switches PROTO((const char *));
197 static void validate_all_switches PROTO((void));
198 static void give_switch PROTO((int, int, int));
199 static int used_arg PROTO((const char *, int));
200 static int default_arg PROTO((const char *, int));
201 static void set_multilib_dir PROTO((void));
202 static void print_multilib_info PROTO((void));
203 static void pfatal_with_name PROTO((const char *)) ATTRIBUTE_NORETURN;
204 static void perror_with_name PROTO((const char *));
205 static void pfatal_pexecute PROTO((const char *, const char *))
207 static void fatal PVPROTO((const char *, ...))
208 ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
209 static void error PVPROTO((const char *, ...))
211 static void notice PVPROTO((const char *, ...))
213 static void display_help PROTO((void));
214 static void add_preprocessor_option PROTO ((const char *, int));
215 static void add_assembler_option PROTO ((const char *, int));
216 static void add_linker_option PROTO ((const char *, int));
217 static void process_command PROTO ((int, char **));
218 static int execute PROTO ((void));
219 static void unused_prefix_warnings PROTO ((struct path_prefix *));
220 static void clear_args PROTO ((void));
221 static void fatal_error PROTO ((int));
223 void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN;
225 /* Called before processing to change/add/remove arguments. */
226 extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)),
227 int *, char ***, int *));
229 /* Called before linking. Returns 0 on success and -1 on failure. */
230 extern int lang_specific_pre_link ();
232 /* Number of extra output files that lang_specific_pre_link may generate. */
233 extern int lang_specific_extra_outfiles;
235 /* Specs are strings containing lines, each of which (if not blank)
236 is made up of a program name, and arguments separated by spaces.
237 The program name must be exact and start from root, since no path
238 is searched and it is unreliable to depend on the current working directory.
239 Redirection of input or output is not supported; the subprograms must
240 accept filenames saying what files to read and write.
242 In addition, the specs can contain %-sequences to substitute variable text
243 or for conditional text. Here is a table of all defined %-sequences.
244 Note that spaces are not generated automatically around the results of
245 expanding these sequences; therefore, you can concatenate them together
246 or with constant text in a single argument.
248 %% substitute one % into the program name or argument.
249 %i substitute the name of the input file being processed.
250 %b substitute the basename of the input file being processed.
251 This is the substring up to (and not including) the last period
252 and not including the directory.
254 substitute a file name that has suffix SUFFIX and is chosen
255 once per compilation, and mark the argument a la %d. To reduce
256 exposure to denial-of-service attacks, the file name is now
257 chosen in a way that is hard to predict even when previously
258 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
259 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
260 the regexp "[.A-Za-z]*" or the special string "%O", which is
261 treated exactly as if %O had been pre-processed. Previously, %g
262 was simply substituted with a file name chosen once per compilation,
263 without regard to any appended suffix (which was therefore treated
264 just like ordinary text), making such attacks more likely to succeed.
266 like %g, but generates a new temporary file name even if %uSUFFIX
269 substitutes the last file name generated with %uSUFFIX, generating a
270 new one if there is no such last file name. In the absence of any
271 %uSUFFIX, this is just like %gSUFFIX, except they don't share
272 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
273 would involve the generation of two distinct file names, one
274 for each `%g.s' and another for each `%U.s'. Previously, %U was
275 simply substituted with a file name chosen for the previous %u,
276 without regard to any appended suffix.
277 %d marks the argument containing or following the %d as a
278 temporary file name, so that that file will be deleted if CC exits
279 successfully. Unlike %g, this contributes no text to the argument.
280 %w marks the argument containing or following the %w as the
281 "output file" of this compilation. This puts the argument
282 into the sequence of arguments that %o will substitute later.
284 like %{...} but mark last argument supplied within
285 as a file to be deleted on failure.
286 %o substitutes the names of all the output files, with spaces
287 automatically placed around them. You should write spaces
288 around the %o as well or the results are undefined.
289 %o is for use in the specs for running the linker.
290 Input files whose names have no recognized suffix are not compiled
291 at all, but they are included among the output files, so they will
293 %O substitutes the suffix for object files. Note that this is
294 handled specially when it immediately follows %g, %u, or %U,
295 because of the need for those to form complete file names. The
296 handling is such that %O is treated exactly as if it had already
297 been substituted, except that %g, %u, and %U do not currently
298 support additional SUFFIX characters following %O as they would
299 following, for example, `.o'.
300 %p substitutes the standard macro predefinitions for the
301 current target machine. Use this when running cpp.
302 %P like %p, but puts `__' before and after the name of each macro.
303 (Except macros that already have __.)
305 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
306 %s current argument is the name of a library or startup file of some sort.
307 Search for that file in a standard list of directories
308 and substitute the full name found.
309 %eSTR Print STR as an error message. STR is terminated by a newline.
310 Use this when inconsistent options are detected.
311 %x{OPTION} Accumulate an option for %X.
312 %X Output the accumulated linker options specified by compilations.
313 %Y Output the accumulated assembler options specified by compilations.
314 %Z Output the accumulated preprocessor options specified by compilations.
315 %v1 Substitute the major version number of GCC.
316 (For version 2.5.n, this is 2.)
317 %v2 Substitute the minor version number of GCC.
318 (For version 2.5.n, this is 5.)
319 %a process ASM_SPEC as a spec.
320 This allows config.h to specify part of the spec for running as.
321 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
322 used here. This can be used to run a post-processor after the
323 assembler has done its job.
324 %D Dump out a -L option for each directory in startfile_prefixes.
325 If multilib_dir is set, extra entries are generated with it affixed.
326 %l process LINK_SPEC as a spec.
327 %L process LIB_SPEC as a spec.
328 %G process LIBGCC_SPEC as a spec.
329 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
330 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
331 %c process SIGNED_CHAR_SPEC as a spec.
332 %C process CPP_SPEC as a spec. A capital C is actually used here.
333 %1 process CC1_SPEC as a spec.
334 %2 process CC1PLUS_SPEC as a spec.
335 %| output "-" if the input for the current command is coming from a pipe.
336 %* substitute the variable part of a matched option. (See below.)
337 Note that each comma in the substituted string is replaced by
339 %{S} substitutes the -S switch, if that switch was given to CC.
340 If that switch was not specified, this substitutes nothing.
341 Here S is a metasyntactic variable.
342 %{S*} substitutes all the switches specified to CC whose names start
343 with -S. This is used for -o, -D, -I, etc; switches that take
344 arguments. CC considers `-o foo' as being one switch whose
345 name starts with `o'. %{o*} would substitute this text,
346 including the space; thus, two arguments would be generated.
347 %{^S*} likewise, but don't put a blank between a switch and any args.
348 %{S*:X} substitutes X if one or more switches whose names start with -S are
349 specified to CC. Note that the tail part of the -S option
350 (i.e. the part matched by the `*') will be substituted for each
351 occurrence of %* within X.
352 %{S:X} substitutes X, but only if the -S switch was given to CC.
353 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
354 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
355 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
356 %{.S:X} substitutes X, but only if processing a file with suffix S.
357 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
358 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
359 combined with ! and . as above binding stronger than the OR.
360 %(Spec) processes a specification defined in a specs file as *Spec:
361 %[Spec] as above, but put __ around -D arguments
363 The conditional text X in a %{S:X} or %{!S:X} construct may contain
364 other nested % constructs or spaces, or even newlines. They are
365 processed as usual, as described above.
367 The -O, -f, -m, and -W switches are handled specifically in these
368 constructs. If another value of -O or the negated form of a -f, -m, or
369 -W switch is found later in the command line, the earlier switch
370 value is ignored, except with {S*} where S is just one letter; this
371 passes all matching options.
373 The character | at the beginning of the predicate text is used to indicate
374 that a command should be piped to the following command, but only if -pipe
377 Note that it is built into CC which switches take arguments and which
378 do not. You might think it would be useful to generalize this to
379 allow each compiler's spec to say which switches take arguments. But
380 this cannot be done in a consistent fashion. CC cannot even decide
381 which input files have been specified without knowing which switches
382 take arguments, and it must know which input files to compile in order
383 to tell which compilers to run.
385 CC also knows implicitly that arguments starting in `-l' are to be
386 treated as compiler output files, and passed to the linker in their
387 proper position among the other output files. */
389 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
391 /* config.h can define ASM_SPEC to provide extra args to the assembler
392 or extra switch-translations. */
397 /* config.h can define ASM_FINAL_SPEC to run a post processor after
398 the assembler has run. */
399 #ifndef ASM_FINAL_SPEC
400 #define ASM_FINAL_SPEC ""
403 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
404 or extra switch-translations. */
409 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
410 or extra switch-translations. */
415 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
416 or extra switch-translations. */
418 #define CC1PLUS_SPEC ""
421 /* config.h can define LINK_SPEC to provide extra args to the linker
422 or extra switch-translations. */
427 /* config.h can define LIB_SPEC to override the default libraries. */
429 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
432 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
435 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
436 /* Have gcc do the search for libgcc.a. */
437 #define LIBGCC_SPEC "libgcc.a%s"
439 #define LIBGCC_SPEC "-lgcc"
443 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
444 #ifndef STARTFILE_SPEC
445 #define STARTFILE_SPEC \
446 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
449 /* config.h can define SWITCHES_NEED_SPACES to control which options
450 require spaces between the option and the argument. */
451 #ifndef SWITCHES_NEED_SPACES
452 #define SWITCHES_NEED_SPACES ""
455 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
457 #define ENDFILE_SPEC ""
460 /* This spec is used for telling cpp whether char is signed or not. */
461 #ifndef SIGNED_CHAR_SPEC
462 /* Use #if rather than ?:
463 because MIPS C compiler rejects like ?: in initializers. */
464 #if DEFAULT_SIGNED_CHAR
465 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
467 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
472 #define LINKER_NAME "collect2"
475 static char *cpp_spec = CPP_SPEC;
476 static char *cpp_predefines = CPP_PREDEFINES;
477 static char *cc1_spec = CC1_SPEC;
478 static char *cc1plus_spec = CC1PLUS_SPEC;
479 static char *signed_char_spec = SIGNED_CHAR_SPEC;
480 static char *asm_spec = ASM_SPEC;
481 static char *asm_final_spec = ASM_FINAL_SPEC;
482 static char *link_spec = LINK_SPEC;
483 static char *lib_spec = LIB_SPEC;
484 static char *libgcc_spec = LIBGCC_SPEC;
485 static char *endfile_spec = ENDFILE_SPEC;
486 static char *startfile_spec = STARTFILE_SPEC;
487 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
488 static char *linker_name_spec = LINKER_NAME;
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;
509 const char *filename;
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)
542 #ifdef HAVE_EXECUTABLE_SUFFIX
543 /* This defines which switches stop a full compilation. */
544 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
545 ((CHAR) == 'c' || (CHAR) == 'S')
547 #ifndef SWITCH_CURTAILS_COMPILATION
548 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
549 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
553 /* Record the mapping from file suffixes for compilation specs. */
557 const char *suffix; /* Use this compiler for input files
558 whose names end in this suffix. */
560 const char *spec[4]; /* To use this compiler, concatenate these
561 specs and pass to do_spec. */
564 /* Pointer to a vector of `struct compiler' that gives the spec for
565 compiling a file, based on its suffix.
566 A file that does not end in any of these suffixes will be passed
567 unchanged to the loader and nothing else will be done to it.
569 An entry containing two 0s is used to terminate the vector.
571 If multiple entries match a file, the last matching one is used. */
573 static struct compiler *compilers;
575 /* Number of entries in `compilers', not counting the null terminator. */
577 static int n_compilers;
579 /* The default list of file name suffixes and their compilation specs. */
581 static struct compiler default_compilers[] =
583 /* Add lists of suffixes of known languages here. If those languages
584 were not present when we built the driver, we will hit these copies
585 and be given a more meaningful error than "file not used since
586 linking is not done". */
587 {".m", {"#Objective-C"}},
588 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}},
589 {".c++", {"#C++"}}, {".C", {"#C++"}},
590 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
591 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
592 {".fpp", {"#Fortran"}},
593 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
594 /* Next come the entries for C. */
599 "%{E|M|MM:cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
600 %{C} %{v} %{A*} %{I*} %{P} %I\
601 %{C:%{!E:%eGNU C does not support -C without using -E}}\
602 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
603 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
604 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
605 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
606 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
607 %{ffast-math:-D__FAST_MATH__}\
608 %{traditional} %{ftraditional:-traditional}\
609 %{traditional-cpp:-traditional}\
610 %{fleading-underscore} %{fno-leading-underscore}\
611 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
612 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
613 %{!E:%{!M:%{!MM:cc1 %i %1 \
614 %{std*} %{nostdinc*} %{A*} %{I*} %I\
615 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
616 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
617 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
618 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
619 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
620 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
621 %{ffast-math:-D__FAST_MATH__}\
622 %{H} %C %{D*} %{U*} %{i*} %Z\
623 %{ftraditional:-traditional}\
624 %{traditional-cpp:-traditional}\
625 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
626 %{aux-info*} %{Qn:-fno-ident}\
628 %{g*} %{O*} %{W*} %{w} %{pedantic*}\
629 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
630 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
632 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
633 %{!pipe:%g.s} %A\n }}}}"
635 #else /* ! USE_CPPLIB */
636 "cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
637 %{C} %{v} %{A*} %{I*} %{P} %I\
638 %{C:%{!E:%eGNU C does not support -C without using -E}}\
639 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
640 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
641 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
642 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
643 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
644 %{ffast-math:-D__FAST_MATH__}\
645 %{traditional} %{ftraditional:-traditional}\
646 %{traditional-cpp:-traditional}\
647 %{fleading-underscore} %{fno-leading-underscore}\
648 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
649 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
650 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
651 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
652 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
653 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
654 %{aux-info*} %{Qn:-fno-ident}\
656 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
657 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
659 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
660 %{!pipe:%g.s} %A\n }}}}"
662 #endif /* ! USE_CPPLIB */
664 {"%{E:cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
665 %{C} %{v} %{A*} %{I*} %{P} %I\
666 %{C:%{!E:%eGNU C does not support -C without using -E}}\
667 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
668 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
669 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
670 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
671 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
672 %{ffast-math:-D__FAST_MATH__}\
673 %{traditional} %{ftraditional:-traditional}\
674 %{traditional-cpp:-traditional}\
675 %{fleading-underscore} %{fno-leading-underscore}\
676 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
678 %{!E:%e-E required when input is from standard input}"}},
679 {".h", {"@c-header"}},
681 {"%{!E:%eCompilation of header file requested} \
682 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
683 %{C:%{!E:%eGNU C does not support -C without using -E}}\
684 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
685 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
686 %{std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
687 %{!undef:%{!std=*:%p}%{std=gnu*:%p} %P} %{trigraphs}\
688 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
689 %{ffast-math:-D__FAST_MATH__}\
690 %{traditional} %{ftraditional:-traditional}\
691 %{traditional-cpp:-traditional}\
692 %{fleading-underscore} %{fno-leading-underscore}\
693 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
695 {".i", {"@cpp-output"}},
697 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
698 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
699 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
700 %{aux-info*} %{Qn:-fno-ident}\
701 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
702 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
704 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
705 %{!pipe:%g.s} %A\n }}}}"}},
706 {".s", {"@assembler"}},
708 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
709 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
711 {".S", {"@assembler-with-cpp"}},
712 {"@assembler-with-cpp",
713 {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
714 %{C:%{!E:%eGNU C does not support -C without using -E}}\
715 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
716 -$ %{!undef:%p %P} -D__ASSEMBLER__ \
717 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
718 %{ffast-math:-D__FAST_MATH__}\
719 %{traditional} %{ftraditional:-traditional}\
720 %{traditional-cpp:-traditional}\
721 %{fleading-underscore} %{fno-leading-underscore}\
722 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
723 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
724 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
725 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
726 %{!pipe:%g.s} %A\n }}}}"}},
728 /* Mark end of table */
732 /* Number of elements in default_compilers, not counting the terminator. */
734 static int n_default_compilers
735 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
737 /* Here is the spec for running the linker, after compiling all files. */
739 /* -u* was put back because both BSD and SysV seem to support it. */
740 /* %{static:} simply prevents an error message if the target machine
741 doesn't handle -static. */
742 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
743 scripts which exist in user specified directories, or in standard
745 #ifdef LINK_COMMAND_SPEC
746 /* Provide option to override link_command_spec from machine specific
747 configuration files. */
748 static const char *link_command_spec =
751 #ifdef LINK_LIBGCC_SPECIAL
752 /* Don't generate -L options. */
753 static const char *link_command_spec = "\
755 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
756 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
757 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
759 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
760 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
765 static const char *link_command_spec = "\
767 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
768 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
769 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
770 %{static:} %{L*} %D %o\
771 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
772 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
778 /* A vector of options to give to the linker.
779 These options are accumulated by %x,
780 and substituted into the linker command with %X. */
781 static int n_linker_options;
782 static char **linker_options;
784 /* A vector of options to give to the assembler.
785 These options are accumulated by -Wa,
786 and substituted into the assembler command with %Y. */
787 static int n_assembler_options;
788 static char **assembler_options;
790 /* A vector of options to give to the preprocessor.
791 These options are accumulated by -Wp,
792 and substituted into the preprocessor command with %Z. */
793 static int n_preprocessor_options;
794 static char **preprocessor_options;
796 /* Define how to map long options into short ones. */
798 /* This structure describes one mapping. */
801 /* The long option's name. */
803 /* The equivalent short option. */
804 const char *equivalent;
805 /* Argument info. A string of flag chars; NULL equals no options.
806 a => argument required.
807 o => argument optional.
808 j => join argument to equivalent, making one word.
809 * => require other text after NAME as an argument. */
810 const char *arg_info;
813 /* This is the table of mappings. Mappings are tried sequentially
814 for each option encountered; the first one that matches, wins. */
816 struct option_map option_map[] =
818 {"--all-warnings", "-Wall", 0},
819 {"--ansi", "-ansi", 0},
820 {"--assemble", "-S", 0},
821 {"--assert", "-A", "a"},
822 {"--classpath", "-fclasspath=", "aj"},
823 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
824 {"--comments", "-C", 0},
825 {"--compile", "-c", 0},
826 {"--debug", "-g", "oj"},
827 {"--define-macro", "-D", "aj"},
828 {"--dependencies", "-M", 0},
829 {"--dump", "-d", "a"},
830 {"--dumpbase", "-dumpbase", "a"},
831 {"--entry", "-e", 0},
832 {"--extra-warnings", "-W", 0},
833 {"--for-assembler", "-Wa", "a"},
834 {"--for-linker", "-Xlinker", "a"},
835 {"--force-link", "-u", "a"},
836 {"--imacros", "-imacros", "a"},
837 {"--include", "-include", "a"},
838 {"--include-barrier", "-I-", 0},
839 {"--include-directory", "-I", "aj"},
840 {"--include-directory-after", "-idirafter", "a"},
841 {"--include-prefix", "-iprefix", "a"},
842 {"--include-with-prefix", "-iwithprefix", "a"},
843 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
844 {"--include-with-prefix-after", "-iwithprefix", "a"},
845 {"--language", "-x", "a"},
846 {"--library-directory", "-L", "a"},
847 {"--machine", "-m", "aj"},
848 {"--machine-", "-m", "*j"},
849 {"--no-line-commands", "-P", 0},
850 {"--no-precompiled-includes", "-noprecomp", 0},
851 {"--no-standard-includes", "-nostdinc", 0},
852 {"--no-standard-libraries", "-nostdlib", 0},
853 {"--no-warnings", "-w", 0},
854 {"--optimize", "-O", "oj"},
855 {"--output", "-o", "a"},
856 {"--output-class-directory", "-foutput-class-dir=", "ja"},
857 {"--pedantic", "-pedantic", 0},
858 {"--pedantic-errors", "-pedantic-errors", 0},
859 {"--pipe", "-pipe", 0},
860 {"--prefix", "-B", "a"},
861 {"--preprocess", "-E", 0},
862 {"--print-search-dirs", "-print-search-dirs", 0},
863 {"--print-file-name", "-print-file-name=", "aj"},
864 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
865 {"--print-missing-file-dependencies", "-MG", 0},
866 {"--print-multi-lib", "-print-multi-lib", 0},
867 {"--print-multi-directory", "-print-multi-directory", 0},
868 {"--print-prog-name", "-print-prog-name=", "aj"},
869 {"--profile", "-p", 0},
870 {"--profile-blocks", "-a", 0},
871 {"--quiet", "-q", 0},
872 {"--save-temps", "-save-temps", 0},
873 {"--shared", "-shared", 0},
874 {"--silent", "-q", 0},
875 {"--specs", "-specs=", "aj"},
876 {"--static", "-static", 0},
877 {"--std", "-std=", "aj"},
878 {"--symbolic", "-symbolic", 0},
879 {"--target", "-b", "a"},
880 {"--trace-includes", "-H", 0},
881 {"--traditional", "-traditional", 0},
882 {"--traditional-cpp", "-traditional-cpp", 0},
883 {"--trigraphs", "-trigraphs", 0},
884 {"--undefine-macro", "-U", "aj"},
885 {"--use-version", "-V", "a"},
886 {"--user-dependencies", "-MM", 0},
887 {"--verbose", "-v", 0},
888 {"--version", "-dumpversion", 0},
889 {"--warn-", "-W", "*j"},
890 {"--write-dependencies", "-MD", 0},
891 {"--write-user-dependencies", "-MMD", 0},
895 /* Translate the options described by *ARGCP and *ARGVP.
896 Make a new vector and store it back in *ARGVP,
897 and store its length in *ARGVC. */
900 translate_options (argcp, argvp)
906 const char **argv = *argvp;
908 (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *));
912 newv[newindex++] = argv[i++];
916 /* Translate -- options. */
917 if (argv[i][0] == '-' && argv[i][1] == '-')
920 /* Find a mapping that applies to this option. */
921 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
923 size_t optlen = strlen (option_map[j].name);
924 size_t arglen = strlen (argv[i]);
925 size_t complen = arglen > optlen ? optlen : arglen;
926 const char *arginfo = option_map[j].arg_info;
931 if (!strncmp (argv[i], option_map[j].name, complen))
939 k < sizeof (option_map) / sizeof (option_map[0]);
941 if (strlen (option_map[k].name) >= arglen
942 && !strncmp (argv[i], option_map[k].name, arglen))
944 error ("Ambiguous abbreviation %s", argv[i]);
948 if (k != sizeof (option_map) / sizeof (option_map[0]))
954 /* If the option has an argument, accept that. */
955 if (argv[i][optlen] == '=')
956 arg = argv[i] + optlen + 1;
958 /* If this mapping requires extra text at end of name,
959 accept that as "argument". */
960 else if (index (arginfo, '*') != 0)
961 arg = argv[i] + optlen;
963 /* Otherwise, extra text at end means mismatch.
964 Try other mappings. */
969 else if (index (arginfo, '*') != 0)
971 error ("Incomplete `%s' option", option_map[j].name);
975 /* Handle arguments. */
976 if (index (arginfo, 'a') != 0)
982 error ("Missing argument to `%s' option",
990 else if (index (arginfo, '*') != 0)
992 else if (index (arginfo, 'o') == 0)
995 error ("Extraneous argument to `%s' option",
1000 /* Store the translation as one argv elt or as two. */
1001 if (arg != 0 && index (arginfo, 'j') != 0)
1002 newv[newindex++] = concat (option_map[j].equivalent, arg,
1006 newv[newindex++] = option_map[j].equivalent;
1007 newv[newindex++] = arg;
1010 newv[newindex++] = option_map[j].equivalent;
1018 /* Handle old-fashioned options--just copy them through,
1019 with their arguments. */
1020 else if (argv[i][0] == '-')
1022 const char *p = argv[i] + 1;
1026 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1027 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1028 else if (WORD_SWITCH_TAKES_ARG (p))
1029 nskip += WORD_SWITCH_TAKES_ARG (p);
1030 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1033 else if (! strcmp (p, "Xlinker"))
1036 /* Watch out for an option at the end of the command line that
1037 is missing arguments, and avoid skipping past the end of the
1039 if (nskip + i > argc)
1044 newv[newindex++] = argv[i++];
1049 /* Ordinary operands, or +e options. */
1050 newv[newindex++] = argv[i++];
1063 #ifdef HAVE_STRERROR
1072 if (e > 0 && e < sys_nerr)
1073 return sys_errlist[e];
1085 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1086 be considered whitespace. */
1087 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1089 else if (*p == '\n' || *p == ' ' || *p == '\t')
1093 while (*p != '\n') p++;
1103 /* Structure to keep track of the specs that have been defined so far.
1104 These are accessed using %(specname) or %[specname] in a compiler
1109 /* The following 2 fields must be first */
1110 /* to allow EXTRA_SPECS to be initialized */
1111 char *name; /* name of the spec. */
1112 char *ptr; /* available ptr if no static pointer */
1114 /* The following fields are not initialized */
1115 /* by EXTRA_SPECS */
1116 char **ptr_spec; /* pointer to the spec itself. */
1117 struct spec_list *next; /* Next spec in linked list. */
1118 int name_len; /* length of the name */
1119 int alloc_p; /* whether string was allocated */
1122 #define INIT_STATIC_SPEC(NAME,PTR) \
1123 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1125 /* List of statically defined specs */
1126 static struct spec_list static_specs[] = {
1127 INIT_STATIC_SPEC ("asm", &asm_spec),
1128 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1129 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1130 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1131 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1132 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1133 INIT_STATIC_SPEC ("link", &link_spec),
1134 INIT_STATIC_SPEC ("lib", &lib_spec),
1135 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1136 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1137 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1138 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1139 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1140 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1141 INIT_STATIC_SPEC ("version", &compiler_version),
1142 INIT_STATIC_SPEC ("multilib", &multilib_select),
1143 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1144 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1145 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1146 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1149 #ifdef EXTRA_SPECS /* additional specs needed */
1150 /* Structure to keep track of just the first two args of a spec_list.
1151 That is all that the EXTRA_SPECS macro gives us. */
1158 static struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1159 static struct spec_list * extra_specs = (struct spec_list *)0;
1162 /* List of dynamically allocates specs that have been defined so far. */
1164 static struct spec_list *specs = (struct spec_list *)0;
1167 /* Initialize the specs lookup routines. */
1172 struct spec_list *next = (struct spec_list *)0;
1173 struct spec_list *sl = (struct spec_list *)0;
1177 return; /* already initialized */
1180 notice ("Using builtin specs.\n");
1183 extra_specs = (struct spec_list *)
1184 xmalloc (sizeof(struct spec_list) *
1185 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
1186 bzero ((PTR) extra_specs, sizeof(struct spec_list) *
1187 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
1189 for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--)
1191 sl = &extra_specs[i];
1192 sl->name = extra_specs_1[i].name;
1193 sl->ptr = extra_specs_1[i].ptr;
1195 sl->name_len = strlen (sl->name);
1196 sl->ptr_spec = &sl->ptr;
1201 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1203 sl = &static_specs[i];
1212 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1213 removed; If the spec starts with a + then SPEC is added to the end of the
1217 set_spec (name, spec)
1221 struct spec_list *sl;
1223 int name_len = strlen (name);
1226 /* If this is the first call, initialize the statically allocated specs */
1229 struct spec_list *next = (struct spec_list *)0;
1230 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1233 sl = &static_specs[i];
1240 /* See if the spec already exists */
1241 for (sl = specs; sl; sl = sl->next)
1242 if (name_len == sl->name_len && !strcmp (sl->name, name))
1247 /* Not found - make it */
1248 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1249 sl->name = save_string (name, strlen (name));
1250 sl->name_len = name_len;
1251 sl->ptr_spec = &sl->ptr;
1253 *(sl->ptr_spec) = "";
1258 old_spec = *(sl->ptr_spec);
1259 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1260 ? concat (old_spec, spec + 1, NULL_PTR)
1261 : save_string (spec, strlen (spec)));
1265 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1268 /* Free the old spec */
1269 if (old_spec && sl->alloc_p)
1275 /* Accumulate a command (program name and args), and run it. */
1277 /* Vector of pointers to arguments in the current line of specifications. */
1279 static char **argbuf;
1281 /* Number of elements allocated in argbuf. */
1283 static int argbuf_length;
1285 /* Number of elements in argbuf currently in use (containing args). */
1287 static int argbuf_index;
1289 /* We want this on by default all the time now. */
1290 #define MKTEMP_EACH_FILE
1292 #ifdef MKTEMP_EACH_FILE
1294 extern char *make_temp_file PROTO((const char *));
1296 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1299 static struct temp_name {
1300 const char *suffix; /* suffix associated with the code. */
1301 int length; /* strlen (suffix). */
1302 int unique; /* Indicates whether %g or %u/%U was used. */
1303 const char *filename; /* associated filename. */
1304 int filename_length; /* strlen (filename). */
1305 struct temp_name *next;
1310 /* Number of commands executed so far. */
1312 static int execution_count;
1314 /* Number of commands that exited with a signal. */
1316 static int signal_count;
1318 /* Name with which this program was invoked. */
1320 static const char *programname;
1322 /* Structures to keep track of prefixes to try when looking for files. */
1326 char *prefix; /* String to prepend to the path. */
1327 struct prefix_list *next; /* Next in linked list. */
1328 int require_machine_suffix; /* Don't use without machine_suffix. */
1329 /* 2 means try both machine_suffix and just_machine_suffix. */
1330 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1335 struct prefix_list *plist; /* List of prefixes to try */
1336 int max_len; /* Max length of a prefix in PLIST */
1337 const char *name; /* Name of this list (used in config stuff) */
1340 /* List of prefixes to try when looking for executables. */
1342 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1344 /* List of prefixes to try when looking for startup (crt0) files. */
1346 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1348 /* List of prefixes to try when looking for include files. */
1350 static struct path_prefix include_prefixes = { 0, 0, "include" };
1352 /* Suffix to attach to directories searched for commands.
1353 This looks like `MACHINE/VERSION/'. */
1355 static const char *machine_suffix = 0;
1357 /* Suffix to attach to directories searched for commands.
1358 This is just `MACHINE/'. */
1360 static const char *just_machine_suffix = 0;
1362 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1364 static const char *gcc_exec_prefix;
1366 /* Default prefixes to attach to command names. */
1368 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1369 #undef MD_EXEC_PREFIX
1370 #undef MD_STARTFILE_PREFIX
1371 #undef MD_STARTFILE_PREFIX_1
1374 #ifndef STANDARD_EXEC_PREFIX
1375 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1376 #endif /* !defined STANDARD_EXEC_PREFIX */
1378 static const char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1379 static const char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1380 #ifdef MD_EXEC_PREFIX
1381 static const char *md_exec_prefix = MD_EXEC_PREFIX;
1384 #ifndef STANDARD_STARTFILE_PREFIX
1385 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1386 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1388 #ifdef MD_STARTFILE_PREFIX
1389 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1391 #ifdef MD_STARTFILE_PREFIX_1
1392 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1394 static const char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1395 static const char *standard_startfile_prefix_1 = "/lib/";
1396 static const char *standard_startfile_prefix_2 = "/usr/lib/";
1398 #ifndef TOOLDIR_BASE_PREFIX
1399 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1401 static const char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1402 static const char *tooldir_prefix;
1404 /* Subdirectory to use for locating libraries. Set by
1405 set_multilib_dir based on the compilation options. */
1407 static const char *multilib_dir;
1409 /* Clear out the vector of arguments (after a command is executed). */
1417 /* Add one argument to the vector at the end.
1418 This is done when a space is seen or at the end of the line.
1419 If DELETE_ALWAYS is nonzero, the arg is a filename
1420 and the file should be deleted eventually.
1421 If DELETE_FAILURE is nonzero, the arg is a filename
1422 and the file should be deleted if this compilation fails. */
1425 store_arg (arg, delete_always, delete_failure)
1427 int delete_always, delete_failure;
1429 if (argbuf_index + 1 == argbuf_length)
1431 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1433 argbuf[argbuf_index++] = arg;
1434 argbuf[argbuf_index] = 0;
1436 if (delete_always || delete_failure)
1437 record_temp_file (arg, delete_always, delete_failure);
1440 /* Read compilation specs from a file named FILENAME,
1441 replacing the default ones.
1443 A suffix which starts with `*' is a definition for
1444 one of the machine-specific sub-specs. The "suffix" should be
1445 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1446 The corresponding spec is stored in asm_spec, etc.,
1447 rather than in the `compilers' vector.
1449 Anything invalid in the file is a fatal error. */
1452 read_specs (filename, main_p)
1453 const char *filename;
1458 struct stat statbuf;
1463 notice ("Reading specs from %s\n", filename);
1465 /* Open and stat the file. */
1466 desc = open (filename, O_RDONLY, 0);
1468 pfatal_with_name (filename);
1469 if (stat (filename, &statbuf) < 0)
1470 pfatal_with_name (filename);
1472 /* Read contents of file into BUFFER. */
1473 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1474 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1476 pfatal_with_name (filename);
1477 buffer[readlen] = 0;
1480 /* Scan BUFFER for specs, putting them in the vector. */
1486 char *in, *out, *p1, *p2, *p3;
1488 /* Advance P in BUFFER to the next nonblank nocomment line. */
1489 p = skip_whitespace (p);
1493 /* Is this a special command that starts with '%'? */
1494 /* Don't allow this for the main specs file, since it would
1495 encourage people to overwrite it. */
1496 if (*p == '%' && !main_p)
1499 while (*p && *p != '\n')
1502 p++; /* Skip '\n' */
1504 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1505 && (p1[sizeof "%include" - 1] == ' '
1506 || p1[sizeof "%include" - 1] == '\t'))
1510 p1 += sizeof ("%include");
1511 while (*p1 == ' ' || *p1 == '\t')
1514 if (*p1++ != '<' || p[-2] != '>')
1515 fatal ("specs %%include syntax malformed after %ld characters",
1516 (long) (p1 - buffer + 1));
1519 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1520 read_specs (new_filename ? new_filename : p1, FALSE);
1523 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1524 && (p1[sizeof "%include_noerr" - 1] == ' '
1525 || p1[sizeof "%include_noerr" - 1] == '\t'))
1529 p1 += sizeof "%include_noerr";
1530 while (*p1 == ' ' || *p1 == '\t') p1++;
1532 if (*p1++ != '<' || p[-2] != '>')
1533 fatal ("specs %%include syntax malformed after %ld characters",
1534 (long) (p1 - buffer + 1));
1537 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1539 read_specs (new_filename, FALSE);
1540 else if (verbose_flag)
1541 notice ("Could not find specs file %s\n", p1);
1544 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1545 && (p1[sizeof "%rename" - 1] == ' '
1546 || p1[sizeof "%rename" - 1] == '\t'))
1549 struct spec_list *sl;
1551 /* Get original name */
1552 p1 += sizeof "%rename";
1553 while (*p1 == ' ' || *p1 == '\t')
1556 if (! ISALPHA ((unsigned char)*p1))
1557 fatal ("specs %%rename syntax malformed after %ld characters",
1558 (long) (p1 - buffer));
1561 while (*p2 && !ISSPACE ((unsigned char)*p2))
1564 if (*p2 != ' ' && *p2 != '\t')
1565 fatal ("specs %%rename syntax malformed after %ld characters",
1566 (long) (p2 - buffer));
1570 while (*p2 == ' ' || *p2 == '\t')
1573 if (! ISALPHA ((unsigned char)*p2))
1574 fatal ("specs %%rename syntax malformed after %ld characters",
1575 (long) (p2 - buffer));
1577 /* Get new spec name */
1579 while (*p3 && !ISSPACE ((unsigned char)*p3))
1583 fatal ("specs %%rename syntax malformed after %ld characters",
1584 (long) (p3 - buffer));
1587 for (sl = specs; sl; sl = sl->next)
1588 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1592 fatal ("specs %s spec was not found to be renamed", p1);
1594 if (strcmp (p1, p2) == 0)
1599 notice ("rename spec %s to %s\n", p1, p2);
1601 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1605 set_spec (p2, *(sl->ptr_spec));
1607 free (*(sl->ptr_spec));
1609 *(sl->ptr_spec) = "";
1614 fatal ("specs unknown %% command after %ld characters",
1615 (long) (p1 - buffer));
1618 /* Find the colon that should end the suffix. */
1620 while (*p1 && *p1 != ':' && *p1 != '\n')
1623 /* The colon shouldn't be missing. */
1625 fatal ("specs file malformed after %ld characters",
1626 (long) (p1 - buffer));
1628 /* Skip back over trailing whitespace. */
1630 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1633 /* Copy the suffix to a string. */
1634 suffix = save_string (p, p2 - p);
1635 /* Find the next line. */
1636 p = skip_whitespace (p1 + 1);
1638 fatal ("specs file malformed after %ld characters",
1639 (long) (p - buffer));
1642 /* Find next blank line or end of string. */
1643 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1646 /* Specs end at the blank line and do not include the newline. */
1647 spec = save_string (p, p1 - p);
1650 /* Delete backslash-newline sequences from the spec. */
1655 if (in[0] == '\\' && in[1] == '\n')
1657 else if (in[0] == '#')
1658 while (*in && *in != '\n')
1666 if (suffix[0] == '*')
1668 if (! strcmp (suffix, "*link_command"))
1669 link_command_spec = spec;
1671 set_spec (suffix + 1, spec);
1675 /* Add this pair to the vector. */
1677 = ((struct compiler *)
1678 xrealloc (compilers,
1679 (n_compilers + 2) * sizeof (struct compiler)));
1681 compilers[n_compilers].suffix = suffix;
1682 bzero ((char *) compilers[n_compilers].spec,
1683 sizeof compilers[n_compilers].spec);
1684 compilers[n_compilers].spec[0] = spec;
1686 bzero ((char *) &compilers[n_compilers],
1687 sizeof compilers[n_compilers]);
1691 link_command_spec = spec;
1694 if (link_command_spec == 0)
1695 fatal ("spec file has no spec for linking");
1698 /* Record the names of temporary files we tell compilers to write,
1699 and delete them at the end of the run. */
1701 /* This is the common prefix we use to make temp file names.
1702 It is chosen once for each run of this program.
1703 It is substituted into a spec by %g.
1704 Thus, all temp file names contain this prefix.
1705 In practice, all temp file names start with this prefix.
1707 This prefix comes from the envvar TMPDIR if it is defined;
1708 otherwise, from the P_tmpdir macro if that is defined;
1709 otherwise, in /usr/tmp or /tmp;
1710 or finally the current directory if all else fails. */
1712 static const char *temp_filename;
1714 /* Length of the prefix. */
1716 static int temp_filename_length;
1718 /* Define the list of temporary files to delete. */
1723 struct temp_file *next;
1726 /* Queue of files to delete on success or failure of compilation. */
1727 static struct temp_file *always_delete_queue;
1728 /* Queue of files to delete on failure of compilation. */
1729 static struct temp_file *failure_delete_queue;
1731 /* Record FILENAME as a file to be deleted automatically.
1732 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1733 otherwise delete it in any case.
1734 FAIL_DELETE nonzero means delete it if a compilation step fails;
1735 otherwise delete it in any case. */
1738 record_temp_file (filename, always_delete, fail_delete)
1739 const char *filename;
1743 register char *name;
1744 name = xmalloc (strlen (filename) + 1);
1745 strcpy (name, filename);
1749 register struct temp_file *temp;
1750 for (temp = always_delete_queue; temp; temp = temp->next)
1751 if (! strcmp (name, temp->name))
1754 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1755 temp->next = always_delete_queue;
1757 always_delete_queue = temp;
1764 register struct temp_file *temp;
1765 for (temp = failure_delete_queue; temp; temp = temp->next)
1766 if (! strcmp (name, temp->name))
1769 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1770 temp->next = failure_delete_queue;
1772 failure_delete_queue = temp;
1778 /* Delete all the temporary files whose names we previously recorded. */
1781 delete_if_ordinary (name)
1788 printf ("Delete %s? (y or n) ", name);
1792 while ((c = getchar ()) != '\n' && c != EOF)
1795 if (i == 'y' || i == 'Y')
1797 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1798 if (unlink (name) < 0)
1800 perror_with_name (name);
1804 delete_temp_files ()
1806 register struct temp_file *temp;
1808 for (temp = always_delete_queue; temp; temp = temp->next)
1809 delete_if_ordinary (temp->name);
1810 always_delete_queue = 0;
1813 /* Delete all the files to be deleted on error. */
1816 delete_failure_queue ()
1818 register struct temp_file *temp;
1820 for (temp = failure_delete_queue; temp; temp = temp->next)
1821 delete_if_ordinary (temp->name);
1825 clear_failure_queue ()
1827 failure_delete_queue = 0;
1830 /* Routine to add variables to the environment. We do this to pass
1831 the pathname of the gcc driver, and the directories search to the
1832 collect2 program, which is being run as ld. This way, we can be
1833 sure of executing the right compiler when collect2 wants to build
1834 constructors and destructors. Since the environment variables we
1835 use come from an obstack, we don't have to worry about allocating
1844 #ifndef VMS /* nor about VMS */
1846 extern char **environ;
1847 char **old_environ = environ;
1851 int str_len = strlen (str);
1855 while ((ch = *p++) != '\0' && ch != '=')
1861 /* Search for replacing an existing environment variable, and
1862 count the number of total environment variables. */
1863 for (envp = old_environ; *envp; envp++)
1866 if (!strncmp (str, *envp, name_len))
1873 /* Add a new environment variable */
1874 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1876 memcpy ((char *) (environ + 1), (char *) old_environ,
1877 sizeof (char *) * (num_envs+1));
1882 #endif /* HAVE_PUTENV */
1885 /* Build a list of search directories from PATHS.
1886 PREFIX is a string to prepend to the list.
1887 If CHECK_DIR_P is non-zero we ensure the directory exists.
1888 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1889 It is also used by the --print-search-dirs flag. */
1892 build_search_list (paths, prefix, check_dir_p)
1893 struct path_prefix *paths;
1897 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1899 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1900 int first_time = TRUE;
1901 struct prefix_list *pprefix;
1903 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1905 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1907 int len = strlen (pprefix->prefix);
1911 || is_directory (pprefix->prefix, machine_suffix, 0)))
1914 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1917 obstack_grow (&collect_obstack, pprefix->prefix, len);
1918 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1921 if (just_machine_suffix
1922 && pprefix->require_machine_suffix == 2
1924 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1927 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1930 obstack_grow (&collect_obstack, pprefix->prefix, len);
1931 obstack_grow (&collect_obstack, just_machine_suffix,
1935 if (! pprefix->require_machine_suffix)
1938 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1941 obstack_grow (&collect_obstack, pprefix->prefix, len);
1945 obstack_1grow (&collect_obstack, '\0');
1946 return obstack_finish (&collect_obstack);
1949 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1953 putenv_from_prefixes (paths, env_var)
1954 struct path_prefix *paths;
1955 const char *env_var;
1957 putenv (build_search_list (paths, env_var, 1));
1960 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1961 access to check permissions.
1962 Return 0 if not found, otherwise return its name, allocated with malloc. */
1965 find_a_file (pprefix, name, mode)
1966 struct path_prefix *pprefix;
1971 const char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1972 struct prefix_list *pl;
1973 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1975 #ifdef DEFAULT_ASSEMBLER
1976 if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
1977 name = DEFAULT_ASSEMBLER;
1978 len = strlen(name)+1;
1979 temp = xmalloc (len);
1980 strcpy (temp, name);
1985 #ifdef DEFAULT_LINKER
1986 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
1987 name = DEFAULT_LINKER;
1988 len = strlen(name)+1;
1989 temp = xmalloc (len);
1990 strcpy (temp, name);
1996 len += strlen (machine_suffix);
1998 temp = xmalloc (len);
2000 /* Determine the filename to execute (special case for absolute paths). */
2002 if (IS_DIR_SEPARATOR (*name)
2003 #ifdef HAVE_DOS_BASED_FILESYSTEM
2004 /* Check for disk name on MS-DOS-based systems. */
2005 || (name[0] && name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2009 if (access (name, mode) == 0)
2011 strcpy (temp, name);
2016 for (pl = pprefix->plist; pl; pl = pl->next)
2020 /* Some systems have a suffix for executable files.
2021 So try appending that first. */
2022 if (file_suffix[0] != 0)
2024 strcpy (temp, pl->prefix);
2025 strcat (temp, machine_suffix);
2026 strcat (temp, name);
2027 strcat (temp, file_suffix);
2028 if (access (temp, mode) == 0)
2030 if (pl->used_flag_ptr != 0)
2031 *pl->used_flag_ptr = 1;
2036 /* Now try just the name. */
2037 strcpy (temp, pl->prefix);
2038 strcat (temp, machine_suffix);
2039 strcat (temp, name);
2040 if (access (temp, mode) == 0)
2042 if (pl->used_flag_ptr != 0)
2043 *pl->used_flag_ptr = 1;
2048 /* Certain prefixes are tried with just the machine type,
2049 not the version. This is used for finding as, ld, etc. */
2050 if (just_machine_suffix && pl->require_machine_suffix == 2)
2052 /* Some systems have a suffix for executable files.
2053 So try appending that first. */
2054 if (file_suffix[0] != 0)
2056 strcpy (temp, pl->prefix);
2057 strcat (temp, just_machine_suffix);
2058 strcat (temp, name);
2059 strcat (temp, file_suffix);
2060 if (access (temp, mode) == 0)
2062 if (pl->used_flag_ptr != 0)
2063 *pl->used_flag_ptr = 1;
2068 strcpy (temp, pl->prefix);
2069 strcat (temp, just_machine_suffix);
2070 strcat (temp, name);
2071 if (access (temp, mode) == 0)
2073 if (pl->used_flag_ptr != 0)
2074 *pl->used_flag_ptr = 1;
2079 /* Certain prefixes can't be used without the machine suffix
2080 when the machine or version is explicitly specified. */
2081 if (! pl->require_machine_suffix)
2083 /* Some systems have a suffix for executable files.
2084 So try appending that first. */
2085 if (file_suffix[0] != 0)
2087 strcpy (temp, pl->prefix);
2088 strcat (temp, name);
2089 strcat (temp, file_suffix);
2090 if (access (temp, mode) == 0)
2092 if (pl->used_flag_ptr != 0)
2093 *pl->used_flag_ptr = 1;
2098 strcpy (temp, pl->prefix);
2099 strcat (temp, name);
2100 if (access (temp, mode) == 0)
2102 if (pl->used_flag_ptr != 0)
2103 *pl->used_flag_ptr = 1;
2113 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2114 at the start of the list, otherwise it goes at the end.
2116 If WARN is nonzero, we will warn if no file is found
2117 through this prefix. WARN should point to an int
2118 which will be set to 1 if this entry is used.
2120 COMPONENT is the value to be passed to update_path.
2122 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2123 the complete value of machine_suffix.
2124 2 means try both machine_suffix and just_machine_suffix. */
2127 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2128 struct path_prefix *pprefix;
2130 const char *component;
2132 int require_machine_suffix;
2135 struct prefix_list *pl, **prev;
2138 if (! first && pprefix->plist)
2140 for (pl = pprefix->plist; pl->next; pl = pl->next)
2145 prev = &pprefix->plist;
2147 /* Keep track of the longest prefix */
2149 prefix = update_path (prefix, component);
2150 len = strlen (prefix);
2151 if (len > pprefix->max_len)
2152 pprefix->max_len = len;
2154 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2155 pl->prefix = save_string (prefix, len);
2156 pl->require_machine_suffix = require_machine_suffix;
2157 pl->used_flag_ptr = warn;
2164 pl->next = (struct prefix_list *) 0;
2168 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2171 unused_prefix_warnings (pprefix)
2172 struct path_prefix *pprefix;
2174 struct prefix_list *pl = pprefix->plist;
2178 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2180 if (pl->require_machine_suffix && machine_suffix)
2181 error ("file path prefix `%s%s' never used", pl->prefix,
2184 error ("file path prefix `%s' never used", pl->prefix);
2186 /* Prevent duplicate warnings. */
2187 *pl->used_flag_ptr = 1;
2195 /* Execute the command specified by the arguments on the current line of spec.
2196 When using pipes, this includes several piped-together commands
2197 with `|' between them.
2199 Return 0 if successful, -1 if failed. */
2205 int n_commands; /* # of command. */
2209 const char *prog; /* program name. */
2210 char **argv; /* vector of args. */
2211 int pid; /* pid of process for this command. */
2214 struct command *commands; /* each command buffer with above info. */
2216 /* Count # of piped commands. */
2217 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2218 if (strcmp (argbuf[i], "|") == 0)
2221 /* Get storage for each command. */
2223 = (struct command *) alloca (n_commands * sizeof (struct command));
2225 /* Split argbuf into its separate piped processes,
2226 and record info about each one.
2227 Also search for the programs that are to be run. */
2229 commands[0].prog = argbuf[0]; /* first command. */
2230 commands[0].argv = &argbuf[0];
2231 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2234 commands[0].argv[0] = string;
2236 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2237 if (strcmp (argbuf[i], "|") == 0)
2238 { /* each command. */
2239 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2240 fatal ("-pipe not supported");
2242 argbuf[i] = 0; /* termination of command args. */
2243 commands[n_commands].prog = argbuf[i + 1];
2244 commands[n_commands].argv = &argbuf[i + 1];
2245 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2247 commands[n_commands].argv[0] = string;
2251 argbuf[argbuf_index] = 0;
2253 /* If -v, print what we are about to do, and maybe query. */
2257 /* For help listings, put a blank line between sub-processes. */
2258 if (print_help_list)
2259 fputc ('\n', stderr);
2261 /* Print each piped command as a separate line. */
2262 for (i = 0; i < n_commands ; i++)
2266 for (j = commands[i].argv; *j; j++)
2267 fprintf (stderr, " %s", *j);
2269 /* Print a pipe symbol after all but the last command. */
2270 if (i + 1 != n_commands)
2271 fprintf (stderr, " |");
2272 fprintf (stderr, "\n");
2276 notice ("\nGo ahead? (y or n) ");
2280 while (getchar () != '\n')
2283 if (i != 'y' && i != 'Y')
2288 /* Run each piped subprocess. */
2290 for (i = 0; i < n_commands; i++)
2292 char *errmsg_fmt, *errmsg_arg;
2293 char *string = commands[i].argv[0];
2295 commands[i].pid = pexecute (string, commands[i].argv,
2296 programname, temp_filename,
2297 &errmsg_fmt, &errmsg_arg,
2298 ((i == 0 ? PEXECUTE_FIRST : 0)
2299 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2300 | (string == commands[i].prog
2301 ? PEXECUTE_SEARCH : 0)
2302 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2304 if (commands[i].pid == -1)
2305 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2307 if (string != commands[i].prog)
2313 /* Wait for all the subprocesses to finish.
2314 We don't care what order they finish in;
2315 we know that N_COMMANDS waits will get them all.
2316 Ignore subprocesses that we don't know about,
2317 since they can be spawned by the process that exec'ed us. */
2322 for (i = 0; i < n_commands; )
2328 pid = pwait (commands[i].pid, &status, 0);
2332 for (j = 0; j < n_commands; j++)
2333 if (commands[j].pid == pid)
2338 if (WIFSIGNALED (status))
2340 fatal ("Internal compiler error: program %s got fatal signal %d",
2341 commands[j].prog, WTERMSIG (status));
2345 else if (WIFEXITED (status)
2346 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2356 /* Find all the switches given to us
2357 and make a vector describing them.
2358 The elements of the vector are strings, one per switch given.
2359 If a switch uses following arguments, then the `part1' field
2360 is the switch itself and the `args' field
2361 is a null-terminated vector containing the following arguments.
2362 The `live_cond' field is 1 if the switch is true in a conditional spec,
2363 -1 if false (overridden by a later switch), and is initialized to zero.
2364 The `validated' field is nonzero if any spec has looked at this switch;
2365 if it remains zero at the end of the run, it must be meaningless. */
2375 static struct switchstr *switches;
2377 static int n_switches;
2382 const char *language;
2385 /* Also a vector of input files specified. */
2387 static struct infile *infiles;
2389 static int n_infiles;
2391 /* This counts the number of libraries added by lang_specific_driver, so that
2392 we can tell if there were any user supplied any files or libraries. */
2394 static int added_libraries;
2396 /* And a vector of corresponding output files is made up later. */
2398 static const char **outfiles;
2400 /* Used to track if none of the -B paths are used. */
2403 /* Used to track if standard path isn't used and -b or -V is specified. */
2404 static int warn_std;
2406 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2407 static int *warn_std_ptr = 0;
2410 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2412 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2413 is true if we should look for an executable suffix as well. */
2416 convert_filename (name, do_exe)
2426 len = strlen (name);
2428 #ifdef HAVE_OBJECT_SUFFIX
2429 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2431 && name[len - 2] == '.'
2432 && name[len - 1] == 'o')
2434 obstack_grow (&obstack, name, len - 2);
2435 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2436 name = obstack_finish (&obstack);
2440 #ifdef HAVE_EXECUTABLE_SUFFIX
2441 /* If there is no filetype, make it the executable suffix (which includes
2442 the "."). But don't get confused if we have just "-o". */
2443 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2446 for (i = len - 1; i >= 0; i--)
2447 if (IS_DIR_SEPARATOR (name[i]))
2450 for (i++; i < len; i++)
2454 obstack_grow (&obstack, name, len);
2455 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2456 name = obstack_finish (&obstack);
2463 /* Display the command line switches accepted by gcc. */
2467 printf ("Usage: %s [options] file...\n", programname);
2468 printf ("Options:\n");
2470 printf (" --help Display this information\n");
2472 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2473 printf (" -dumpspecs Display all of the built in spec strings\n");
2474 printf (" -dumpversion Display the version of the compiler\n");
2475 printf (" -dumpmachine Display the compiler's target processor\n");
2476 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2477 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2478 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2479 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2480 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2481 printf (" -print-multi-lib Display the mapping between command line options and\n");
2482 printf (" multiple library search directories\n");
2483 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2484 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2485 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2486 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2487 printf (" -save-temps Do not delete intermediate files\n");
2488 printf (" -pipe Use pipes rather than intermediate files\n");
2489 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2490 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2491 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2492 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2493 printf (" -V <version> Run gcc version number <version>, if installed\n");
2494 printf (" -v Display the programs invoked by the compiler\n");
2495 printf (" -E Preprocess only; do not compile, assemble or link\n");
2496 printf (" -S Compile only; do not assemble or link\n");
2497 printf (" -c Compile and assemble, but do not link\n");
2498 printf (" -o <file> Place the output into <file>\n");
2499 printf (" -x <language> Specify the language of the following input files\n");
2500 printf (" Permissable languages include: c c++ assembler none\n");
2501 printf (" 'none' means revert to the default behaviour of\n");
2502 printf (" guessing the language based on the file's extension\n");
2504 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2505 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2507 printf ("on to these processes the -W<letter> options must be used.\n");
2509 /* The rest of the options are displayed by invocations of the various
2514 add_preprocessor_option (option, len)
2515 const char * option;
2518 n_preprocessor_options++;
2520 if (! preprocessor_options)
2521 preprocessor_options
2522 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
2524 preprocessor_options
2525 = (char **) xrealloc (preprocessor_options,
2526 n_preprocessor_options * sizeof (char *));
2528 preprocessor_options [n_preprocessor_options - 1] =
2529 save_string (option, len);
2533 add_assembler_option (option, len)
2534 const char * option;
2537 n_assembler_options++;
2539 if (! assembler_options)
2541 = (char **) xmalloc (n_assembler_options * sizeof (char *));
2544 = (char **) xrealloc (assembler_options,
2545 n_assembler_options * sizeof (char *));
2547 assembler_options [n_assembler_options - 1] = save_string (option, len);
2551 add_linker_option (option, len)
2552 const char * option;
2557 if (! linker_options)
2559 = (char **) xmalloc (n_linker_options * sizeof (char *));
2562 = (char **) xrealloc (linker_options,
2563 n_linker_options * sizeof (char *));
2565 linker_options [n_linker_options - 1] = save_string (option, len);
2568 /* Create the vector `switches' and its contents.
2569 Store its length in `n_switches'. */
2572 process_command (argc, argv)
2579 char *spec_lang = 0;
2580 int last_language_n_infiles;
2583 int lang_n_infiles = 0;
2585 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2589 added_libraries = 0;
2591 /* Figure compiler version from version string. */
2593 compiler_version = temp1 =
2594 save_string (version_string, strlen (version_string));
2595 for (; *temp1; ++temp1)
2604 /* Set up the default search paths. */
2606 if (gcc_exec_prefix)
2608 int len = strlen (gcc_exec_prefix);
2609 if (len > (int) sizeof ("/lib/gcc-lib/")-1
2610 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
2612 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2613 if (IS_DIR_SEPARATOR (*temp)
2614 && strncmp (temp+1, "lib", 3) == 0
2615 && IS_DIR_SEPARATOR (temp[4])
2616 && strncmp (temp+5, "gcc-lib", 7) == 0)
2617 len -= sizeof ("/lib/gcc-lib/") - 1;
2620 set_std_prefix (gcc_exec_prefix, len);
2621 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2622 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2625 /* COMPILER_PATH and LIBRARY_PATH have values
2626 that are lists of directory names with colons. */
2628 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
2631 const char *startp, *endp;
2632 char *nstore = (char *) alloca (strlen (temp) + 3);
2634 startp = endp = temp;
2637 if (*endp == PATH_SEPARATOR || *endp == 0)
2639 strncpy (nstore, startp, endp-startp);
2641 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2642 else if (!IS_DIR_SEPARATOR (endp[-1]))
2644 nstore[endp-startp] = DIR_SEPARATOR;
2645 nstore[endp-startp+1] = 0;
2648 nstore[endp-startp] = 0;
2649 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2650 add_prefix (&include_prefixes,
2651 concat (nstore, "include", NULL_PTR),
2655 endp = startp = endp + 1;
2662 GET_ENV_PATH_LIST (temp, "LIBRARY_PATH");
2663 if (temp && *cross_compile == '0')
2665 const char *startp, *endp;
2666 char *nstore = (char *) alloca (strlen (temp) + 3);
2668 startp = endp = temp;
2671 if (*endp == PATH_SEPARATOR || *endp == 0)
2673 strncpy (nstore, startp, endp-startp);
2675 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2676 else if (!IS_DIR_SEPARATOR (endp[-1]))
2678 nstore[endp-startp] = DIR_SEPARATOR;
2679 nstore[endp-startp+1] = 0;
2682 nstore[endp-startp] = 0;
2683 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2687 endp = startp = endp + 1;
2694 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2695 GET_ENV_PATH_LIST (temp, "LPATH");
2696 if (temp && *cross_compile == '0')
2698 const char *startp, *endp;
2699 char *nstore = (char *) alloca (strlen (temp) + 3);
2701 startp = endp = temp;
2704 if (*endp == PATH_SEPARATOR || *endp == 0)
2706 strncpy (nstore, startp, endp-startp);
2708 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2709 else if (!IS_DIR_SEPARATOR (endp[-1]))
2711 nstore[endp-startp] = DIR_SEPARATOR;
2712 nstore[endp-startp+1] = 0;
2715 nstore[endp-startp] = 0;
2716 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2720 endp = startp = endp + 1;
2727 /* Convert new-style -- options to old-style. */
2728 translate_options (&argc, &argv);
2730 /* Do language-specific adjustment/addition of flags. */
2731 lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2733 /* Scan argv twice. Here, the first time, just count how many switches
2734 there will be in their vector, and how many input files in theirs.
2735 Here we also parse the switches that cc itself uses (e.g. -v). */
2737 for (i = 1; i < argc; i++)
2739 if (! strcmp (argv[i], "-dumpspecs"))
2741 struct spec_list *sl;
2743 for (sl = specs; sl; sl = sl->next)
2744 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2745 if (link_command_spec)
2746 printf ("*link_command:\n%s\n\n", link_command_spec);
2749 else if (! strcmp (argv[i], "-dumpversion"))
2751 printf ("%s\n", spec_version);
2754 else if (! strcmp (argv[i], "-dumpmachine"))
2756 printf ("%s\n", spec_machine);
2759 else if (strcmp (argv[i], "-fhelp") == 0)
2761 /* translate_options () has turned --help into -fhelp. */
2762 print_help_list = 1;
2764 /* We will be passing a dummy file on to the sub-processes. */
2768 add_preprocessor_option ("--help", 6);
2769 add_assembler_option ("--help", 6);
2770 add_linker_option ("--help", 6);
2772 else if (! strcmp (argv[i], "-print-search-dirs"))
2773 print_search_dirs = 1;
2774 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2775 print_file_name = "libgcc.a";
2776 else if (! strncmp (argv[i], "-print-file-name=", 17))
2777 print_file_name = argv[i] + 17;
2778 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2779 print_prog_name = argv[i] + 17;
2780 else if (! strcmp (argv[i], "-print-multi-lib"))
2781 print_multi_lib = 1;
2782 else if (! strcmp (argv[i], "-print-multi-directory"))
2783 print_multi_directory = 1;
2784 else if (! strncmp (argv[i], "-Wa,", 4))
2787 /* Pass the rest of this option to the assembler. */
2789 /* Split the argument at commas. */
2791 for (j = 4; argv[i][j]; j++)
2792 if (argv[i][j] == ',')
2794 add_assembler_option (argv[i] + prev, j - prev);
2798 /* Record the part after the last comma. */
2799 add_assembler_option (argv[i] + prev, j - prev);
2801 else if (! strncmp (argv[i], "-Wp,", 4))
2804 /* Pass the rest of this option to the preprocessor. */
2806 /* Split the argument at commas. */
2808 for (j = 4; argv[i][j]; j++)
2809 if (argv[i][j] == ',')
2811 add_preprocessor_option (argv[i] + prev, j - prev);
2815 /* Record the part after the last comma. */
2816 add_preprocessor_option (argv[i] + prev, j - prev);
2818 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2819 /* The +e options to the C++ front-end. */
2821 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2824 /* Split the argument at commas. */
2825 for (j = 3; argv[i][j]; j++)
2826 n_infiles += (argv[i][j] == ',');
2828 else if (strcmp (argv[i], "-Xlinker") == 0)
2831 fatal ("argument to `-Xlinker' is missing");
2836 else if (strncmp (argv[i], "-l", 2) == 0)
2838 else if (strcmp (argv[i], "-save-temps") == 0)
2840 save_temps_flag = 1;
2843 else if (strcmp (argv[i], "-specs") == 0)
2845 struct user_specs *user = (struct user_specs *)
2846 xmalloc (sizeof (struct user_specs));
2848 fatal ("argument to `-specs' is missing");
2850 user->next = (struct user_specs *)0;
2851 user->filename = argv[i];
2852 if (user_specs_tail)
2853 user_specs_tail->next = user;
2855 user_specs_head = user;
2856 user_specs_tail = user;
2858 else if (strncmp (argv[i], "-specs=", 7) == 0)
2860 struct user_specs *user = (struct user_specs *)
2861 xmalloc (sizeof (struct user_specs));
2862 if (strlen (argv[i]) == 7)
2863 fatal ("argument to `-specs=' is missing");
2865 user->next = (struct user_specs *)0;
2866 user->filename = argv[i]+7;
2867 if (user_specs_tail)
2868 user_specs_tail->next = user;
2870 user_specs_head = user;
2871 user_specs_tail = user;
2873 else if (argv[i][0] == '-' && argv[i][1] != 0)
2875 register char *p = &argv[i][1];
2876 register int c = *p;
2882 if (p[1] == 0 && i + 1 == argc)
2883 fatal ("argument to `-b' is missing");
2885 spec_machine = argv[++i];
2887 spec_machine = p + 1;
2889 warn_std_ptr = &warn_std;
2895 if (p[1] == 0 && i + 1 == argc)
2896 fatal ("argument to `-B' is missing");
2901 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2902 add_prefix (&startfile_prefixes, value, NULL_PTR,
2904 add_prefix (&include_prefixes, concat (value, "include",
2906 NULL_PTR, 1, 0, NULL_PTR);
2908 /* As a kludge, if the arg is "[foo/]stageN/", just add
2909 "[foo/]include" to the include prefix. */
2911 int len = strlen (value);
2914 && (IS_DIR_SEPARATOR (value[len - 8]))))
2915 && strncmp (value + len - 7, "stage", 5) == 0
2916 && ISDIGIT (value[len - 2])
2917 && (IS_DIR_SEPARATOR (value[len - 1])))
2920 add_prefix (&include_prefixes, "include", NULL_PTR,
2924 char *string = xmalloc (len + 1);
2925 strncpy (string, value, len-7);
2926 strcpy (string+len-7, "include");
2927 add_prefix (&include_prefixes, string, NULL_PTR,
2936 case 'v': /* Print our subcommands and print versions. */
2938 /* If they do anything other than exactly `-v', don't set
2939 verbose_flag; rather, continue on to give the error. */
2947 if (p[1] == 0 && i + 1 == argc)
2948 fatal ("argument to `-V' is missing");
2950 spec_version = argv[++i];
2952 spec_version = p + 1;
2953 compiler_version = spec_version;
2954 warn_std_ptr = &warn_std;
2956 /* Validate the version number. Use the same checks
2957 done when inserting it into a spec.
2959 The format of the version string is
2960 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2962 const char *v = compiler_version;
2964 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2965 while (! ISDIGIT (*v))
2968 if (v > compiler_version && v[-1] != '-')
2969 fatal ("invalid version number format");
2971 /* Set V after the first period. */
2972 while (ISDIGIT (*v))
2976 fatal ("invalid version number format");
2979 while (ISDIGIT (*v))
2982 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
2983 fatal ("invalid version number format");
2999 #if defined(HAVE_EXECUTABLE_SUFFIX)
3004 /* Forward scan, just in case -S or -c is specified
3011 if (argv[j][0] == '-')
3013 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3019 else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
3020 j += skip - (argv[j][2] != 0);
3021 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
3028 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3030 argv[i+1] = convert_filename (argv[i+1], ! have_c);
3032 argv[i] = convert_filename (argv[i], ! have_c);
3040 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3041 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3042 else if (WORD_SWITCH_TAKES_ARG (p))
3043 i += WORD_SWITCH_TAKES_ARG (p);
3053 if (have_c && have_o && lang_n_infiles > 1)
3054 fatal ("cannot specify -o with -c or -S and multiple compilations");
3056 /* Set up the search paths before we go looking for config files. */
3058 /* These come before the md prefixes so that we will find gcc's subcommands
3059 (such as cpp) rather than those of the host system. */
3060 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3061 as well as trying the machine and the version. */
3063 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3064 0, 2, warn_std_ptr);
3065 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3066 0, 2, warn_std_ptr);
3069 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3070 0, 1, warn_std_ptr);
3071 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3072 0, 1, warn_std_ptr);
3074 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3075 dir_separator_str, NULL_PTR);
3077 /* If tooldir is relative, base it on exec_prefixes. A relative
3078 tooldir lets us move the installed tree as a unit.
3080 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3081 directories, so that we can search both the user specified directory
3082 and the standard place. */
3084 if (!IS_DIR_SEPARATOR (*tooldir_prefix))
3086 if (gcc_exec_prefix)
3088 char *gcc_exec_tooldir_prefix
3089 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3090 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
3092 add_prefix (&exec_prefixes,
3093 concat (gcc_exec_tooldir_prefix, "bin",
3094 dir_separator_str, NULL_PTR),
3095 NULL_PTR, 0, 0, NULL_PTR);
3096 add_prefix (&startfile_prefixes,
3097 concat (gcc_exec_tooldir_prefix, "lib",
3098 dir_separator_str, NULL_PTR),
3099 NULL_PTR, 0, 0, NULL_PTR);
3102 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3103 dir_separator_str, spec_version,
3104 dir_separator_str, tooldir_prefix, NULL_PTR);
3107 add_prefix (&exec_prefixes,
3108 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
3109 "BINUTILS", 0, 0, NULL_PTR);
3110 add_prefix (&startfile_prefixes,
3111 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
3112 "BINUTILS", 0, 0, NULL_PTR);
3114 /* More prefixes are enabled in main, after we read the specs file
3115 and determine whether this is cross-compilation or not. */
3118 /* Then create the space for the vectors and scan again. */
3120 switches = ((struct switchstr *)
3121 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3122 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3125 last_language_n_infiles = -1;
3127 /* This, time, copy the text of each switch and store a pointer
3128 to the copy in the vector of switches.
3129 Store all the infiles in their vector. */
3131 for (i = 1; i < argc; i++)
3133 /* Just skip the switches that were handled by the preceding loop. */
3134 if (! strncmp (argv[i], "-Wa,", 4))
3136 else if (! strncmp (argv[i], "-Wp,", 4))
3138 else if (! strcmp (argv[i], "-print-search-dirs"))
3140 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3142 else if (! strncmp (argv[i], "-print-file-name=", 17))
3144 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3146 else if (! strcmp (argv[i], "-print-multi-lib"))
3148 else if (! strcmp (argv[i], "-print-multi-directory"))
3150 else if (strcmp (argv[i], "-fhelp") == 0)
3154 /* Create a dummy input file, so that we can pass --help on to
3155 the various sub-processes. */
3156 infiles[n_infiles].language = "c";
3157 infiles[n_infiles++].name = "help-dummy";
3159 /* Preserve the --help switch so that it can be caught by the
3161 switches[n_switches].part1 = "--help";
3162 switches[n_switches].args = 0;
3163 switches[n_switches].live_cond = 0;
3164 switches[n_switches].validated = 0;
3169 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3171 /* Compensate for the +e options to the C++ front-end;
3172 they're there simply for cfront call-compatibility. We do
3173 some magic in default_compilers to pass them down properly.
3174 Note we deliberately start at the `+' here, to avoid passing
3175 -e0 or -e1 down into the linker. */
3176 switches[n_switches].part1 = &argv[i][0];
3177 switches[n_switches].args = 0;
3178 switches[n_switches].live_cond = 0;
3179 switches[n_switches].validated = 0;
3182 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3185 /* Split the argument at commas. */
3187 for (j = 4; argv[i][j]; j++)
3188 if (argv[i][j] == ',')
3190 infiles[n_infiles].language = "*";
3191 infiles[n_infiles++].name
3192 = save_string (argv[i] + prev, j - prev);
3195 /* Record the part after the last comma. */
3196 infiles[n_infiles].language = "*";
3197 infiles[n_infiles++].name = argv[i] + prev;
3199 else if (strcmp (argv[i], "-Xlinker") == 0)
3201 infiles[n_infiles].language = "*";
3202 infiles[n_infiles++].name = argv[++i];
3204 else if (strncmp (argv[i], "-l", 2) == 0)
3206 infiles[n_infiles].language = "*";
3207 infiles[n_infiles++].name = argv[i];
3209 else if (strcmp (argv[i], "-specs") == 0)
3211 else if (strncmp (argv[i], "-specs=", 7) == 0)
3213 /* -save-temps overrides -pipe, so that temp files are produced */
3214 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
3215 error ("Warning: -pipe ignored since -save-temps specified");
3216 else if (argv[i][0] == '-' && argv[i][1] != 0)
3218 register char *p = &argv[i][1];
3219 register int c = *p;
3223 if (p[1] == 0 && i + 1 == argc)
3224 fatal ("argument to `-x' is missing");
3226 spec_lang = argv[++i];
3229 if (! strcmp (spec_lang, "none"))
3230 /* Suppress the warning if -xnone comes after the last input
3231 file, because alternate command interfaces like g++ might
3232 find it useful to place -xnone after each input file. */
3235 last_language_n_infiles = n_infiles;
3238 switches[n_switches].part1 = p;
3239 /* Deal with option arguments in separate argv elements. */
3240 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3241 || WORD_SWITCH_TAKES_ARG (p))
3244 int n_args = WORD_SWITCH_TAKES_ARG (p);
3248 /* Count only the option arguments in separate argv elements. */
3249 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3251 if (i + n_args >= argc)
3252 fatal ("argument to `-%s' is missing", p);
3253 switches[n_switches].args
3254 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3256 switches[n_switches].args[j++] = argv[++i];
3257 /* Null-terminate the vector. */
3258 switches[n_switches].args[j] = 0;
3260 else if (index (switches_need_spaces, c))
3262 /* On some systems, ld cannot handle some options without
3263 a space. So split the option from its argument. */
3264 char *part1 = (char *) xmalloc (2);
3268 switches[n_switches].part1 = part1;
3269 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3270 switches[n_switches].args[0] = xmalloc (strlen (p));
3271 strcpy (switches[n_switches].args[0], &p[1]);
3272 switches[n_switches].args[1] = 0;
3275 switches[n_switches].args = 0;
3277 switches[n_switches].live_cond = 0;
3278 switches[n_switches].validated = 0;
3279 /* This is always valid, since gcc.c itself understands it. */
3280 if (!strcmp (p, "save-temps"))
3281 switches[n_switches].validated = 1;
3284 char ch = switches[n_switches].part1[0];
3285 if (ch == 'V' || ch == 'b' || ch == 'B')
3286 switches[n_switches].validated = 1;
3292 #ifdef HAVE_OBJECT_SUFFIX
3293 argv[i] = convert_filename (argv[i], 0);
3296 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3298 perror_with_name (argv[i]);
3303 infiles[n_infiles].language = spec_lang;
3304 infiles[n_infiles++].name = argv[i];
3309 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3310 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3312 switches[n_switches].part1 = 0;
3313 infiles[n_infiles].name = 0;
3316 /* Process a spec string, accumulating and running commands. */
3318 /* These variables describe the input file name.
3319 input_file_number is the index on outfiles of this file,
3320 so that the output file name can be stored for later use by %o.
3321 input_basename is the start of the part of the input file
3322 sans all directory names, and basename_length is the number
3323 of characters starting there excluding the suffix .c or whatever. */
3325 const char *input_filename;
3326 static int input_file_number;
3327 size_t input_filename_length;
3328 static int basename_length;
3329 static const char *input_basename;
3330 static const char *input_suffix;
3332 /* These are variables used within do_spec and do_spec_1. */
3334 /* Nonzero if an arg has been started and not yet terminated
3335 (with space, tab or newline). */
3336 static int arg_going;
3338 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3339 is a temporary file name. */
3340 static int delete_this_arg;
3342 /* Nonzero means %w has been seen; the next arg to be terminated
3343 is the output file name of this compilation. */
3344 static int this_is_output_file;
3346 /* Nonzero means %s has been seen; the next arg to be terminated
3347 is the name of a library file and we should try the standard
3348 search dirs for it. */
3349 static int this_is_library_file;
3351 /* Nonzero means that the input of this command is coming from a pipe. */
3352 static int input_from_pipe;
3354 /* Process the spec SPEC and run the commands specified therein.
3355 Returns 0 if the spec is successfully processed; -1 if failed. */
3365 delete_this_arg = 0;
3366 this_is_output_file = 0;
3367 this_is_library_file = 0;
3368 input_from_pipe = 0;
3370 value = do_spec_1 (spec, 0, NULL_PTR);
3372 /* Force out any unfinished command.
3373 If -pipe, this forces out the last command if it ended in `|'. */
3376 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3379 if (argbuf_index > 0)
3386 /* Process the sub-spec SPEC as a portion of a larger spec.
3387 This is like processing a whole spec except that we do
3388 not initialize at the beginning and we do not supply a
3389 newline by default at the end.
3390 INSWITCH nonzero means don't process %-sequences in SPEC;
3391 in this case, % is treated as an ordinary character.
3392 This is used while substituting switches.
3393 INSWITCH nonzero also causes SPC not to terminate an argument.
3395 Value is zero unless a line was finished
3396 and the command on that line reported an error. */
3399 do_spec_1 (spec, inswitch, soft_matched_part)
3402 const char *soft_matched_part;
3404 register const char *p = spec;
3411 /* If substituting a switch, treat all chars like letters.
3412 Otherwise, NL, SPC, TAB and % are special. */
3413 switch (inswitch ? 'a' : c)
3416 /* End of line: finish any pending argument,
3417 then run the pending command if one has been started. */
3420 obstack_1grow (&obstack, 0);
3421 string = obstack_finish (&obstack);
3422 if (this_is_library_file)
3423 string = find_file (string);
3424 store_arg (string, delete_this_arg, this_is_output_file);
3425 if (this_is_output_file)
3426 outfiles[input_file_number] = string;
3430 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3432 for (i = 0; i < n_switches; i++)
3433 if (!strcmp (switches[i].part1, "pipe"))
3436 /* A `|' before the newline means use a pipe here,
3437 but only if -pipe was specified.
3438 Otherwise, execute now and don't pass the `|' as an arg. */
3441 input_from_pipe = 1;
3442 switches[i].validated = 1;
3449 if (argbuf_index > 0)
3455 /* Reinitialize for a new command, and for a new argument. */
3458 delete_this_arg = 0;
3459 this_is_output_file = 0;
3460 this_is_library_file = 0;
3461 input_from_pipe = 0;
3465 /* End any pending argument. */
3468 obstack_1grow (&obstack, 0);
3469 string = obstack_finish (&obstack);
3470 if (this_is_library_file)
3471 string = find_file (string);
3472 store_arg (string, delete_this_arg, this_is_output_file);
3473 if (this_is_output_file)
3474 outfiles[input_file_number] = string;
3478 obstack_1grow (&obstack, c);
3484 /* Space or tab ends an argument if one is pending. */
3487 obstack_1grow (&obstack, 0);
3488 string = obstack_finish (&obstack);
3489 if (this_is_library_file)
3490 string = find_file (string);
3491 store_arg (string, delete_this_arg, this_is_output_file);
3492 if (this_is_output_file)
3493 outfiles[input_file_number] = string;
3495 /* Reinitialize for a new argument. */
3497 delete_this_arg = 0;
3498 this_is_output_file = 0;
3499 this_is_library_file = 0;
3506 fatal ("Invalid specification! Bug in cc.");
3509 obstack_grow (&obstack, input_basename, basename_length);
3514 delete_this_arg = 2;
3517 /* Dump out the directories specified with LIBRARY_PATH,
3518 followed by the absolute directories
3519 that we search for startfiles. */
3522 struct prefix_list *pl = startfile_prefixes.plist;
3523 size_t bufsize = 100;
3524 char *buffer = (char *) xmalloc (bufsize);
3527 for (; pl; pl = pl->next)
3529 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3530 /* Used on systems which record the specified -L dirs
3531 and use them to search for dynamic linking. */
3532 /* Relative directories always come from -B,
3533 and it is better not to use them for searching
3534 at run time. In particular, stage1 loses */
3535 if (!IS_DIR_SEPARATOR (pl->prefix[0]))
3538 /* Try subdirectory if there is one. */
3539 if (multilib_dir != NULL)
3543 if (strlen (pl->prefix) + strlen (machine_suffix)
3545 bufsize = (strlen (pl->prefix)
3546 + strlen (machine_suffix)) * 2 + 1;
3547 buffer = (char *) xrealloc (buffer, bufsize);
3548 strcpy (buffer, pl->prefix);
3549 strcat (buffer, machine_suffix);
3550 if (is_directory (buffer, multilib_dir, 1))
3552 do_spec_1 ("-L", 0, NULL_PTR);
3553 #ifdef SPACE_AFTER_L_OPTION
3554 do_spec_1 (" ", 0, NULL_PTR);
3556 do_spec_1 (buffer, 1, NULL_PTR);
3557 do_spec_1 (multilib_dir, 1, NULL_PTR);
3558 /* Make this a separate argument. */
3559 do_spec_1 (" ", 0, NULL_PTR);
3562 if (!pl->require_machine_suffix)
3564 if (is_directory (pl->prefix, multilib_dir, 1))
3566 do_spec_1 ("-L", 0, NULL_PTR);
3567 #ifdef SPACE_AFTER_L_OPTION
3568 do_spec_1 (" ", 0, NULL_PTR);
3570 do_spec_1 (pl->prefix, 1, NULL_PTR);
3571 do_spec_1 (multilib_dir, 1, NULL_PTR);
3572 /* Make this a separate argument. */
3573 do_spec_1 (" ", 0, NULL_PTR);
3579 if (is_directory (pl->prefix, machine_suffix, 1))
3581 do_spec_1 ("-L", 0, NULL_PTR);
3582 #ifdef SPACE_AFTER_L_OPTION
3583 do_spec_1 (" ", 0, NULL_PTR);
3585 do_spec_1 (pl->prefix, 1, NULL_PTR);
3586 /* Remove slash from machine_suffix. */
3587 if (strlen (machine_suffix) >= bufsize)
3588 bufsize = strlen (machine_suffix) * 2 + 1;
3589 buffer = (char *) xrealloc (buffer, bufsize);
3590 strcpy (buffer, machine_suffix);
3591 idx = strlen (buffer);
3592 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3593 buffer[idx - 1] = 0;
3594 do_spec_1 (buffer, 1, NULL_PTR);
3595 /* Make this a separate argument. */
3596 do_spec_1 (" ", 0, NULL_PTR);
3599 if (!pl->require_machine_suffix)
3601 if (is_directory (pl->prefix, "", 1))
3603 do_spec_1 ("-L", 0, NULL_PTR);
3604 #ifdef SPACE_AFTER_L_OPTION
3605 do_spec_1 (" ", 0, NULL_PTR);
3607 /* Remove slash from pl->prefix. */
3608 if (strlen (pl->prefix) >= bufsize)
3609 bufsize = strlen (pl->prefix) * 2 + 1;
3610 buffer = (char *) xrealloc (buffer, bufsize);
3611 strcpy (buffer, pl->prefix);
3612 idx = strlen (buffer);
3613 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3614 buffer[idx - 1] = 0;
3615 do_spec_1 (buffer, 1, NULL_PTR);
3616 /* Make this a separate argument. */
3617 do_spec_1 (" ", 0, NULL_PTR);
3626 /* %efoo means report an error with `foo' as error message
3627 and don't execute any more commands for this file. */
3631 while (*p != 0 && *p != '\n') p++;
3632 buf = (char *) alloca (p - q + 1);
3633 strncpy (buf, q, p - q);
3643 if (save_temps_flag)
3645 obstack_grow (&obstack, input_basename, basename_length);
3646 delete_this_arg = 0;
3650 #ifdef MKTEMP_EACH_FILE
3651 /* ??? This has a problem: the total number of
3652 values mktemp can return is limited.
3653 That matters for the names of object files.
3654 In 2.4, do something about that. */
3655 struct temp_name *t;
3657 const char *suffix = p;
3659 if (p[0] == '%' && p[1] == 'O')
3662 /* We don't support extra suffix characters after %O. */
3663 if (*p == '.' || ISALPHA ((unsigned char)*p))
3665 suffix = OBJECT_SUFFIX;
3666 suffix_length = strlen (OBJECT_SUFFIX);
3670 while (*p == '.' || ISALPHA ((unsigned char)*p))
3672 suffix_length = p - suffix;
3675 /* See if we already have an association of %g/%u/%U and
3677 for (t = temp_names; t; t = t->next)
3678 if (t->length == suffix_length
3679 && strncmp (t->suffix, suffix, suffix_length) == 0
3680 && t->unique == (c != 'g'))
3683 /* Make a new association if needed. %u requires one. */
3684 if (t == 0 || c == 'u')
3688 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3689 t->next = temp_names;
3692 t->length = suffix_length;
3693 t->suffix = save_string (suffix, suffix_length);
3694 t->unique = (c != 'g');
3695 temp_filename = make_temp_file (t->suffix);
3696 temp_filename_length = strlen (temp_filename);
3697 t->filename = temp_filename;
3698 t->filename_length = temp_filename_length;
3701 obstack_grow (&obstack, t->filename, t->filename_length);
3702 delete_this_arg = 1;
3704 obstack_grow (&obstack, temp_filename, temp_filename_length);
3705 if (c == 'u' || c == 'U')
3711 sprintf (buff, "%d", unique);
3712 obstack_grow (&obstack, buff, strlen (buff));
3715 delete_this_arg = 1;
3721 obstack_grow (&obstack, input_filename, input_filename_length);
3727 struct prefix_list *pl = include_prefixes.plist;
3729 if (gcc_exec_prefix)
3731 do_spec_1 ("-iprefix", 1, NULL_PTR);
3732 /* Make this a separate argument. */
3733 do_spec_1 (" ", 0, NULL_PTR);
3734 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3735 do_spec_1 (" ", 0, NULL_PTR);
3738 for (; pl; pl = pl->next)
3740 do_spec_1 ("-isystem", 1, NULL_PTR);
3741 /* Make this a separate argument. */
3742 do_spec_1 (" ", 0, NULL_PTR);
3743 do_spec_1 (pl->prefix, 1, NULL_PTR);
3744 do_spec_1 (" ", 0, NULL_PTR);
3751 int max = n_infiles;
3752 max += lang_specific_extra_outfiles;
3754 for (i = 0; i < max; i++)
3756 store_arg (outfiles[i], 0, 0);
3761 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3766 this_is_library_file = 1;
3770 this_is_output_file = 1;
3775 int cur_index = argbuf_index;
3776 /* Handle the {...} following the %W. */
3779 p = handle_braces (p + 1);
3782 /* If any args were output, mark the last one for deletion
3784 if (argbuf_index != cur_index)
3785 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3789 /* %x{OPTION} records OPTION for %X to output. */
3795 /* Skip past the option value and make a copy. */
3800 string = save_string (p1 + 1, p - p1 - 2);
3802 /* See if we already recorded this option. */
3803 for (i = 0; i < n_linker_options; i++)
3804 if (! strcmp (string, linker_options[i]))
3810 /* This option is new; add it. */
3811 add_linker_option (string, strlen (string));
3815 /* Dump out the options accumulated previously using %x. */
3817 for (i = 0; i < n_linker_options; i++)
3819 do_spec_1 (linker_options[i], 1, NULL_PTR);
3820 /* Make each accumulated option a separate argument. */
3821 do_spec_1 (" ", 0, NULL_PTR);
3825 /* Dump out the options accumulated previously using -Wa,. */
3827 for (i = 0; i < n_assembler_options; i++)
3829 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3830 /* Make each accumulated option a separate argument. */
3831 do_spec_1 (" ", 0, NULL_PTR);
3835 /* Dump out the options accumulated previously using -Wp,. */
3837 for (i = 0; i < n_preprocessor_options; i++)
3839 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3840 /* Make each accumulated option a separate argument. */
3841 do_spec_1 (" ", 0, NULL_PTR);
3845 /* Here are digits and numbers that just process
3846 a certain constant string as a spec. */
3849 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3855 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3861 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3867 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3873 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3879 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3885 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3891 value = do_spec_1 (link_spec, 0, NULL_PTR);
3897 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3903 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3910 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3914 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3918 if (! strncmp (y, "-D", 2))
3919 /* Copy the whole option. */
3920 while (*y && *y != ' ' && *y != '\t')
3922 else if (*y == ' ' || *y == '\t')
3923 /* Copy whitespace to the result. */
3925 /* Don't copy other options. */
3932 value = do_spec_1 (buf, 0, NULL_PTR);
3940 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3944 /* Copy all of CPP_PREDEFINES into BUF,
3945 but put __ after every -D and at the end of each arg. */
3949 if (! strncmp (y, "-D", 2))
3958 && ! ISUPPER ((unsigned char)*(y+1))))
3960 /* Stick __ at front of macro name. */
3963 /* Arrange to stick __ at the end as well. */
3967 /* Copy the macro name. */
3968 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3977 /* Copy the value given, if any. */
3978 while (*y && *y != ' ' && *y != '\t')
3981 else if (*y == ' ' || *y == '\t')
3982 /* Copy whitespace to the result. */
3984 /* Don't copy -A options */
3990 /* Copy all of CPP_PREDEFINES into BUF,
3991 but put __ after every -D. */
3995 if (! strncmp (y, "-D", 2))
4001 && ! ISUPPER ((unsigned char)*(y+1))))
4003 /* Stick -D__ at front of macro name. */
4009 /* Copy the macro name. */
4010 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4013 /* Copy the value given, if any. */
4014 while (*y && *y != ' ' && *y != '\t')
4019 /* Do not copy this macro - we have just done it before */
4020 while (*y && *y != ' ' && *y != '\t')
4024 else if (*y == ' ' || *y == '\t')
4025 /* Copy whitespace to the result. */
4027 /* Don't copy -A options */
4033 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4037 if (! strncmp (y, "-A", 2))
4038 /* Copy the whole option. */
4039 while (*y && *y != ' ' && *y != '\t')
4041 else if (*y == ' ' || *y == '\t')
4042 /* Copy whitespace to the result. */
4044 /* Don't copy other options. */
4051 value = do_spec_1 (buf, 0, NULL_PTR);
4058 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
4063 /* Here we define characters other than letters and digits. */
4066 p = handle_braces (p);
4072 obstack_1grow (&obstack, '%');
4076 do_spec_1 (soft_matched_part, 1, NULL_PTR);
4077 do_spec_1 (" ", 0, NULL_PTR);
4080 /* Process a string found as the value of a spec given by name.
4081 This feature allows individual machine descriptions
4082 to add and use their own specs.
4083 %[...] modifies -D options the way %P does;
4084 %(...) uses the spec unmodified. */
4086 error ("Warning: use of obsolete %%[ operator in specs");
4089 const char *name = p;
4090 struct spec_list *sl;
4093 /* The string after the S/P is the name of a spec that is to be
4095 while (*p && *p != ')' && *p != ']')
4098 /* See if it's in the list */
4099 for (len = p - name, sl = specs; sl; sl = sl->next)
4100 if (sl->name_len == len && !strncmp (sl->name, name, len))
4102 name = *(sl->ptr_spec);
4104 notice ("Processing spec %c%s%c, which is '%s'\n",
4105 c, sl->name, (c == '(') ? ')' : ']', name);
4114 value = do_spec_1 (name, 0, NULL_PTR);
4120 char *x = (char *) alloca (strlen (name) * 2 + 1);
4122 const char *y = name;
4125 /* Copy all of NAME into BUF, but put __ after
4126 every -D and at the end of each arg, */
4129 if (! strncmp (y, "-D", 2))
4139 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
4140 || *y == '}' || *y == 0))
4153 value = do_spec_1 (buf, 0, NULL_PTR);
4159 /* Discard the closing paren or bracket. */
4167 int c1 = *p++; /* Select first or second version number. */
4168 char *v = compiler_version;
4171 /* The format of the version string is
4172 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4174 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4175 while (! ISDIGIT (*v))
4177 if (v > compiler_version && v[-1] != '-')
4180 /* If desired, advance to second version number. */
4183 /* Set V after the first period. */
4184 while (ISDIGIT (*v))
4191 /* Set Q at the next period or at the end. */
4193 while (ISDIGIT (*q))
4195 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
4198 /* Put that part into the command. */
4199 obstack_grow (&obstack, v, q - v);
4205 if (input_from_pipe)
4206 do_spec_1 ("-", 0, NULL_PTR);
4215 /* Backslash: treat next character as ordinary. */
4220 /* Ordinary character: put it into the current argument. */
4221 obstack_1grow (&obstack, c);
4225 return 0; /* End of string */
4228 /* Return 0 if we call do_spec_1 and that returns -1. */
4232 register const char *p;
4234 const char *filter, *body = NULL, *endbody = NULL;
4238 int include_blanks = 1;
4241 /* A '^' after the open-brace means to not give blanks before args. */
4242 include_blanks = 0, ++p;
4245 /* A `|' after the open-brace means,
4246 if the test fails, output a single minus sign rather than nothing.
4247 This is used in %{|!pipe:...}. */
4251 negate = suffix = 0;
4254 /* A `!' after the open-brace negates the condition:
4255 succeed if the specified switch is not present. */
4259 /* A `.' after the open-brace means test against the current suffix. */
4269 while (*p != ':' && *p != '}' && *p != '|') p++;
4271 if (*p == '|' && pipe_p)
4278 register int count = 1;
4279 register const char *q = p;
4281 while (*q++ != ':') continue;
4297 body = p, endbody = p+1;
4302 int found = (input_suffix != 0
4303 && (long) strlen (input_suffix) == (long)(p - filter)
4304 && strncmp (input_suffix, filter, p - filter) == 0);
4310 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL_PTR) < 0)
4313 else if (p[-1] == '*' && p[0] == '}')
4315 /* Substitute all matching switches as separate args. */
4318 for (i = 0; i < n_switches; i++)
4319 if (!strncmp (switches[i].part1, filter, p - filter)
4320 && check_live_switch (i, p - filter))
4321 give_switch (i, 0, include_blanks);
4325 /* Test for presence of the specified switch. */
4329 /* If name specified ends in *, as in {x*:...},
4330 check for %* and handle that case. */
4331 if (p[-1] == '*' && !negate)
4334 const char *r = body;
4336 /* First see whether we have %*. */
4340 if (*r == '%' && r[1] == '*')
4344 /* If we do, handle that case. */
4347 /* Substitute all matching switches as separate args.
4348 But do this by substituting for %*
4349 in the text that follows the colon. */
4351 unsigned hard_match_len = p - filter - 1;
4352 char *string = save_string (body, endbody - body - 1);
4354 for (i = 0; i < n_switches; i++)
4355 if (!strncmp (switches[i].part1, filter, hard_match_len)
4356 && check_live_switch (i, -1))
4358 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4359 /* Pass any arguments this switch has. */
4360 give_switch (i, 1, 1);
4363 /* We didn't match. Try again. */
4370 /* If name specified ends in *, as in {x*:...},
4371 check for presence of any switch name starting with x. */
4374 for (i = 0; i < n_switches; i++)
4376 unsigned hard_match_len = p - filter - 1;
4378 if (!strncmp (switches[i].part1, filter, hard_match_len)
4379 && check_live_switch (i, hard_match_len))
4385 /* Otherwise, check for presence of exact name specified. */
4388 for (i = 0; i < n_switches; i++)
4390 if (!strncmp (switches[i].part1, filter, p - filter)
4391 && switches[i].part1[p - filter] == 0
4392 && check_live_switch (i, -1))
4400 /* If it is as desired (present for %{s...}, absent for %{!s...})
4401 then substitute either the switch or the specified
4402 conditional text. */
4403 if (present != negate)
4407 give_switch (i, 0, include_blanks);
4411 if (do_spec_1 (save_string (body, endbody - body - 1),
4418 /* Here if a %{|...} conditional fails: output a minus sign,
4419 which means "standard output" or "standard input". */
4420 do_spec_1 ("-", 0, NULL_PTR);
4425 /* We didn't match; try again. */
4432 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4433 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4434 spec, or -1 if either exact match or %* is used.
4436 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4437 whose value does not begin with "no-" is obsoleted by the same value
4438 with the "no-", similarly for a switch with the "no-" prefix. */
4441 check_live_switch (switchnum, prefix_length)
4445 const char *name = switches[switchnum].part1;
4448 /* In the common case of {<at-most-one-letter>*}, a negating
4449 switch would always match, so ignore that case. We will just
4450 send the conflicting switches to the compiler phase. */
4451 if (prefix_length >= 0 && prefix_length <= 1)
4454 /* If we already processed this switch and determined if it was
4455 live or not, return our past determination. */
4456 if (switches[switchnum].live_cond != 0)
4457 return switches[switchnum].live_cond > 0;
4459 /* Now search for duplicate in a manner that depends on the name. */
4463 for (i = switchnum + 1; i < n_switches; i++)
4464 if (switches[i].part1[0] == 'O')
4466 switches[switchnum].validated = 1;
4467 switches[switchnum].live_cond = -1;
4472 case 'W': case 'f': case 'm':
4473 if (! strncmp (name + 1, "no-", 3))
4475 /* We have Xno-YYY, search for XYYY. */
4476 for (i = switchnum + 1; i < n_switches; i++)
4477 if (switches[i].part1[0] == name[0]
4478 && ! strcmp (&switches[i].part1[1], &name[4]))
4480 switches[switchnum].validated = 1;
4481 switches[switchnum].live_cond = -1;
4487 /* We have XYYY, search for Xno-YYY. */
4488 for (i = switchnum + 1; i < n_switches; i++)
4489 if (switches[i].part1[0] == name[0]
4490 && switches[i].part1[1] == 'n'
4491 && switches[i].part1[2] == 'o'
4492 && switches[i].part1[3] == '-'
4493 && !strcmp (&switches[i].part1[4], &name[1]))
4495 switches[switchnum].validated = 1;
4496 switches[switchnum].live_cond = -1;
4503 /* Otherwise the switch is live. */
4504 switches[switchnum].live_cond = 1;
4508 /* Pass a switch to the current accumulating command
4509 in the same form that we received it.
4510 SWITCHNUM identifies the switch; it is an index into
4511 the vector of switches gcc received, which is `switches'.
4512 This cannot fail since it never finishes a command line.
4514 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4516 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4520 give_switch (switchnum, omit_first_word, include_blanks)
4522 int omit_first_word;
4525 if (!omit_first_word)
4527 do_spec_1 ("-", 0, NULL_PTR);
4528 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4531 if (switches[switchnum].args != 0)
4534 for (p = switches[switchnum].args; *p; p++)
4537 do_spec_1 (" ", 0, NULL_PTR);
4538 do_spec_1 (*p, 1, NULL_PTR);
4542 do_spec_1 (" ", 0, NULL_PTR);
4543 switches[switchnum].validated = 1;
4546 /* Search for a file named NAME trying various prefixes including the
4547 user's -B prefix and some standard ones.
4548 Return the absolute file name found. If nothing is found, return NAME. */
4556 /* Try multilib_dir if it is defined. */
4557 if (multilib_dir != NULL)
4561 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4562 strcpy (try, multilib_dir);
4563 strcat (try, dir_separator_str);
4566 newname = find_a_file (&startfile_prefixes, try, R_OK);
4568 /* If we don't find it in the multi library dir, then fall
4569 through and look for it in the normal places. */
4570 if (newname != NULL)
4574 newname = find_a_file (&startfile_prefixes, name, R_OK);
4575 return newname ? newname : name;
4578 /* Determine whether a directory exists. If LINKER, return 0 for
4579 certain fixed names not needed by the linker. If not LINKER, it is
4580 only important to return 0 if the host machine has a small ARG_MAX
4584 is_directory (path1, path2, linker)
4589 int len1 = strlen (path1);
4590 int len2 = strlen (path2);
4591 char *path = (char *) alloca (3 + len1 + len2);
4595 #ifndef SMALL_ARG_MAX
4600 /* Construct the path from the two parts. Ensure the string ends with "/.".
4601 The resulting path will be a directory even if the given path is a
4603 memcpy (path, path1, len1);
4604 memcpy (path + len1, path2, len2);
4605 cp = path + len1 + len2;
4606 if (!IS_DIR_SEPARATOR (cp[-1]))
4607 *cp++ = DIR_SEPARATOR;
4611 /* Exclude directories that the linker is known to search. */
4614 && strcmp (path, concat (dir_separator_str, "lib",
4615 dir_separator_str, ".", NULL_PTR)) == 0)
4617 && strcmp (path, concat (dir_separator_str, "usr",
4618 dir_separator_str, "lib",
4619 dir_separator_str, ".", NULL_PTR)) == 0)))
4622 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4625 /* On fatal signals, delete all the temporary files. */
4628 fatal_error (signum)
4631 signal (signum, SIG_DFL);
4632 delete_failure_queue ();
4633 delete_temp_files ();
4634 /* Get the same signal again, this time not handled,
4635 so its normal effect occurs. */
4636 kill (getpid (), signum);
4647 int linker_was_run = 0;
4648 char *explicit_link_files;
4651 struct user_specs *uptr;
4653 p = argv[0] + strlen (argv[0]);
4654 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
4658 #ifdef HAVE_LC_MESSAGES
4659 setlocale (LC_MESSAGES, "");
4661 (void) bindtextdomain (PACKAGE, localedir);
4662 (void) textdomain (PACKAGE);
4664 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4665 signal (SIGINT, fatal_error);
4667 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4668 signal (SIGHUP, fatal_error);
4670 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4671 signal (SIGTERM, fatal_error);
4673 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4674 signal (SIGPIPE, fatal_error);
4678 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4680 obstack_init (&obstack);
4682 /* Build multilib_select, et. al from the separate lines that make up each
4683 multilib selection. */
4685 char **q = multilib_raw;
4688 obstack_init (&multilib_obstack);
4689 while ((p = *q++) != (char *) 0)
4690 obstack_grow (&multilib_obstack, p, strlen (p));
4692 obstack_1grow (&multilib_obstack, 0);
4693 multilib_select = obstack_finish (&multilib_obstack);
4695 q = multilib_matches_raw;
4696 while ((p = *q++) != (char *) 0)
4697 obstack_grow (&multilib_obstack, p, strlen (p));
4699 obstack_1grow (&multilib_obstack, 0);
4700 multilib_matches = obstack_finish (&multilib_obstack);
4704 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4708 obstack_1grow (&multilib_obstack, ' ');
4709 obstack_grow (&multilib_obstack,
4710 multilib_defaults_raw[i],
4711 strlen (multilib_defaults_raw[i]));
4715 obstack_1grow (&multilib_obstack, 0);
4716 multilib_defaults = obstack_finish (&multilib_obstack);
4719 /* Set up to remember the pathname of gcc and any options
4720 needed for collect. We use argv[0] instead of programname because
4721 we need the complete pathname. */
4722 obstack_init (&collect_obstack);
4723 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4724 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4725 putenv (obstack_finish (&collect_obstack));
4727 #ifdef INIT_ENVIRONMENT
4728 /* Set up any other necessary machine specific environment variables. */
4729 putenv (INIT_ENVIRONMENT);
4732 /* Choose directory for temp files. */
4734 #ifndef MKTEMP_EACH_FILE
4735 temp_filename = choose_temp_base ();
4736 temp_filename_length = strlen (temp_filename);
4739 /* Make a table of what switches there are (switches, n_switches).
4740 Make a table of specified input files (infiles, n_infiles).
4741 Decode switches that are handled locally. */
4743 process_command (argc, argv);
4748 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4750 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4751 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4754 for (i = 0; (int)i < n_switches; i++)
4759 obstack_grow (&collect_obstack, " ", 1);
4762 obstack_grow (&collect_obstack, "'-", 2);
4763 q = switches[i].part1;
4764 while ((p = index (q,'\'')))
4766 obstack_grow (&collect_obstack, q, p-q);
4767 obstack_grow (&collect_obstack, "'\\''", 4);
4770 obstack_grow (&collect_obstack, q, strlen (q));
4771 obstack_grow (&collect_obstack, "'", 1);
4773 for (args = switches[i].args; args && *args; args++)
4775 obstack_grow (&collect_obstack, " '", 2);
4777 while ((p = index (q,'\'')))
4779 obstack_grow (&collect_obstack, q, p-q);
4780 obstack_grow (&collect_obstack, "'\\''", 4);
4783 obstack_grow (&collect_obstack, q, strlen (q));
4784 obstack_grow (&collect_obstack, "'", 1);
4787 obstack_grow (&collect_obstack, "\0", 1);
4788 putenv (obstack_finish (&collect_obstack));
4791 /* Initialize the vector of specs to just the default.
4792 This means one element containing 0s, as a terminator. */
4794 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4795 bcopy ((char *) default_compilers, (char *) compilers,
4796 sizeof default_compilers);
4797 n_compilers = n_default_compilers;
4799 /* Read specs from a file if there is one. */
4801 machine_suffix = concat (spec_machine, dir_separator_str,
4802 spec_version, dir_separator_str, NULL_PTR);
4803 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4805 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4806 /* Read the specs file unless it is a default one. */
4807 if (specs_file != 0 && strcmp (specs_file, "specs"))
4808 read_specs (specs_file, TRUE);
4812 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4813 for any override of as, ld and libraries. */
4814 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4815 + strlen (just_machine_suffix)
4816 + sizeof ("specs"));
4818 strcpy (specs_file, standard_exec_prefix);
4819 strcat (specs_file, just_machine_suffix);
4820 strcat (specs_file, "specs");
4821 if (access (specs_file, R_OK) == 0)
4822 read_specs (specs_file, TRUE);
4824 /* Process any user specified specs in the order given on the command
4826 for (uptr = user_specs_head; uptr; uptr = uptr->next)
4828 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4829 read_specs (filename ? filename : uptr->filename, FALSE);
4832 /* If not cross-compiling, look for startfiles in the standard places. */
4833 /* The fact that these are done here, after reading the specs file,
4834 means that it cannot be found in these directories.
4835 But that's okay. It should never be there anyway. */
4836 if (*cross_compile == '0')
4838 #ifdef MD_EXEC_PREFIX
4839 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4840 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4843 #ifdef MD_STARTFILE_PREFIX
4844 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4848 #ifdef MD_STARTFILE_PREFIX_1
4849 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4853 /* If standard_startfile_prefix is relative, base it on
4854 standard_exec_prefix. This lets us move the installed tree
4855 as a unit. If GCC_EXEC_PREFIX is defined, base
4856 standard_startfile_prefix on that as well. */
4857 if (IS_DIR_SEPARATOR (*standard_startfile_prefix)
4858 || *standard_startfile_prefix == '$'
4859 #ifdef HAVE_DOS_BASED_FILESYSTEM
4860 /* Check for disk name on MS-DOS-based systems. */
4861 || (standard_startfile_prefix[1] == ':'
4862 && (IS_DIR_SEPARATOR (standard_startfile_prefix[2])))
4865 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4869 if (gcc_exec_prefix)
4870 add_prefix (&startfile_prefixes,
4871 concat (gcc_exec_prefix, machine_suffix,
4872 standard_startfile_prefix, NULL_PTR),
4873 NULL_PTR, 0, 0, NULL_PTR);
4874 add_prefix (&startfile_prefixes,
4875 concat (standard_exec_prefix,
4877 standard_startfile_prefix, NULL_PTR),
4878 NULL_PTR, 0, 0, NULL_PTR);
4881 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4882 "BINUTILS", 0, 0, NULL_PTR);
4883 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4884 "BINUTILS", 0, 0, NULL_PTR);
4885 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4886 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
4891 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix) && gcc_exec_prefix)
4892 add_prefix (&startfile_prefixes,
4893 concat (gcc_exec_prefix, machine_suffix,
4894 standard_startfile_prefix, NULL_PTR),
4895 "BINUTILS", 0, 0, NULL_PTR);
4898 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4899 if (gcc_exec_prefix)
4901 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4902 + strlen (spec_version)
4903 + strlen (spec_machine) + 3);
4904 strcpy (temp, gcc_exec_prefix);
4905 strcat (temp, spec_machine);
4906 strcat (temp, dir_separator_str);
4907 strcat (temp, spec_version);
4908 strcat (temp, dir_separator_str);
4909 gcc_exec_prefix = temp;
4912 /* Now we have the specs.
4913 Set the `valid' bits for switches that match anything in any spec. */
4915 validate_all_switches ();
4917 /* Now that we have the switches and the specs, set
4918 the subdirectory based on the options. */
4919 set_multilib_dir ();
4921 /* Warn about any switches that no pass was interested in. */
4923 for (i = 0; (int)i < n_switches; i++)
4924 if (! switches[i].validated)
4925 error ("unrecognized option `-%s'", switches[i].part1);
4927 /* Obey some of the options. */
4929 if (print_search_dirs)
4931 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4932 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4933 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4937 if (print_file_name)
4939 printf ("%s\n", find_file (print_file_name));
4943 if (print_prog_name)
4945 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4946 printf ("%s\n", (newname ? newname : print_prog_name));
4950 if (print_multi_lib)
4952 print_multilib_info ();
4956 if (print_multi_directory)
4958 if (multilib_dir == NULL)
4961 printf ("%s\n", multilib_dir);
4965 if (print_help_list)
4971 printf ("\nReport bugs to egcs-bugs@egcs.cygnus.com.\n");
4972 printf ("Please see the file BUGS (included with the sources) first.\n");
4977 /* We do not exit here. Instead we have created a fake input file
4978 called 'help-dummy' which needs to be compiled, and we pass this
4979 on the the various sub-processes, along with the --help switch. */
4986 /* compiler_version is truncated at the first space when initialized
4987 from version string, so truncate version_string at the first space
4988 before comparing. */
4989 for (n = 0; version_string[n]; n++)
4990 if (version_string[n] == ' ')
4993 if (! strncmp (version_string, compiler_version, n)
4994 && compiler_version[n] == 0)
4995 notice ("gcc version %s\n", version_string);
4997 notice ("gcc driver version %s executing gcc version %s\n",
4998 version_string, compiler_version);
5004 if (n_infiles == added_libraries)
5005 fatal ("No input files");
5007 /* Make a place to record the compiler output file names
5008 that correspond to the input files. */
5011 i += lang_specific_extra_outfiles;
5012 outfiles = (const char **) xmalloc (i * sizeof (char *));
5013 bzero ((char *) outfiles, i * sizeof (char *));
5015 /* Record which files were specified explicitly as link input. */
5017 explicit_link_files = xmalloc (n_infiles);
5018 bzero (explicit_link_files, n_infiles);
5020 for (i = 0; (int)i < n_infiles; i++)
5022 register struct compiler *cp = 0;
5023 int this_file_error = 0;
5025 /* Tell do_spec what to substitute for %i. */
5027 input_filename = infiles[i].name;
5028 input_filename_length = strlen (input_filename);
5029 input_file_number = i;
5031 /* Use the same thing in %o, unless cp->spec says otherwise. */
5033 outfiles[i] = input_filename;
5035 /* Figure out which compiler from the file's suffix. */
5037 cp = lookup_compiler (infiles[i].name, input_filename_length,
5038 infiles[i].language);
5042 /* Ok, we found an applicable compiler. Run its spec. */
5043 /* First say how much of input_filename to substitute for %b */
5044 register const char *p;
5047 if (cp->spec[0][0] == '#')
5048 error ("%s: %s compiler not installed on this system",
5049 input_filename, &cp->spec[0][1]);
5051 input_basename = input_filename;
5052 for (p = input_filename; *p; p++)
5053 if (IS_DIR_SEPARATOR (*p))
5054 input_basename = p + 1;
5056 /* Find a suffix starting with the last period,
5057 and set basename_length to exclude that suffix. */
5058 basename_length = strlen (input_basename);
5059 p = input_basename + basename_length;
5060 while (p != input_basename && *p != '.') --p;
5061 if (*p == '.' && p != input_basename)
5063 basename_length = p - input_basename;
5064 input_suffix = p + 1;
5070 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5072 len += strlen (cp->spec[j]);
5075 char *p1 = (char *) xmalloc (len + 1);
5078 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5081 strcpy (p1 + len, cp->spec[j]);
5082 len += strlen (cp->spec[j]);
5085 value = do_spec (p1);
5089 this_file_error = 1;
5092 /* If this file's name does not contain a recognized suffix,
5093 record it as explicit linker input. */
5096 explicit_link_files[i] = 1;
5098 /* Clear the delete-on-failure queue, deleting the files in it
5099 if this compilation failed. */
5101 if (this_file_error)
5103 delete_failure_queue ();
5106 /* If this compilation succeeded, don't delete those files later. */
5107 clear_failure_queue ();
5110 if (error_count == 0)
5112 /* Make sure INPUT_FILE_NUMBER points to first available open
5114 input_file_number = n_infiles;
5115 if (lang_specific_pre_link ())
5119 /* Run ld to link all the compiler output files. */
5121 if (error_count == 0)
5123 int tmp = execution_count;
5125 /* We'll use ld if we can't find collect2. */
5126 if (! strcmp (linker_name_spec, "collect2"))
5128 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
5130 linker_name_spec = "ld";
5132 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5134 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
5135 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
5137 value = do_spec (link_command_spec);
5140 linker_was_run = (tmp != execution_count);
5143 /* Warn if a -B option was specified but the prefix was never used. */
5144 unused_prefix_warnings (&exec_prefixes);
5145 unused_prefix_warnings (&startfile_prefixes);
5147 /* If options said don't run linker,
5148 complain about input files to be given to the linker. */
5150 if (! linker_was_run && error_count == 0)
5151 for (i = 0; (int)i < n_infiles; i++)
5152 if (explicit_link_files[i])
5153 error ("%s: linker input file unused since linking not done",
5156 /* Delete some or all of the temporary files we made. */
5159 delete_failure_queue ();
5160 delete_temp_files ();
5162 if (print_help_list)
5164 printf ("\nReport bugs to egcs-bugs@egcs.cygnus.com.\n");
5165 printf ("Please see the file BUGS (included with the sources) first.\n");
5168 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
5173 /* Find the proper compilation spec for the file name NAME,
5174 whose length is LENGTH. LANGUAGE is the specified language,
5175 or 0 if this file is to be passed to the linker. */
5177 static struct compiler *
5178 lookup_compiler (name, length, language)
5181 const char *language;
5183 struct compiler *cp;
5185 /* If this was specified by the user to be a linker input, indicate that. */
5186 if (language != 0 && language[0] == '*')
5189 /* Otherwise, look for the language, if one is spec'd. */
5192 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5193 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
5196 error ("language %s not recognized", language);
5200 /* Look for a suffix. */
5201 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5203 if (/* The suffix `-' matches only the file name `-'. */
5204 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
5205 || (strlen (cp->suffix) < length
5206 /* See if the suffix matches the end of NAME. */
5208 && ((!strcmp (cp->suffix,
5209 name + length - strlen (cp->suffix))
5210 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5211 && !strcasecmp (cp->suffix,
5212 name + length - strlen (cp->suffix)))
5214 && !strcmp (cp->suffix,
5215 name + length - strlen (cp->suffix))
5219 if (cp->spec[0][0] == '@')
5221 struct compiler *new;
5223 /* An alias entry maps a suffix to a language.
5224 Search for the language; pass 0 for NAME and LENGTH
5225 to avoid infinite recursion if language not found.
5226 Construct the new compiler spec. */
5227 language = cp->spec[0] + 1;
5228 new = (struct compiler *) xmalloc (sizeof (struct compiler));
5229 new->suffix = cp->suffix;
5230 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
5231 (char *) new->spec, sizeof new->spec);
5235 /* A non-alias entry: return it. */
5247 register PTR value = (PTR) malloc (size);
5249 fatal ("virtual memory exhausted");
5254 xrealloc (old, size)
5260 ptr = (PTR) realloc (old, size);
5262 ptr = (PTR) malloc (size);
5264 fatal ("virtual memory exhausted");
5269 save_string (s, len)
5273 register char *result = xmalloc (len + 1);
5275 bcopy (s, result, len);
5281 pfatal_with_name (name)
5284 perror_with_name (name);
5285 delete_temp_files ();
5290 perror_with_name (name)
5293 error ("%s: %s", name, xstrerror (errno));
5297 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5298 const char *errmsg_fmt;
5299 const char *errmsg_arg;
5303 int save_errno = errno;
5305 /* Space for trailing '\0' is in %s. */
5306 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5307 sprintf (msg, errmsg_fmt, errmsg_arg);
5313 pfatal_with_name (errmsg_fmt);
5316 /* More 'friendly' abort that prints the line and file.
5317 config.h can #define abort fancy_abort if you like that sort of thing. */
5322 fatal ("Internal gcc abort.");
5325 /* Output an error message and exit */
5328 fatal VPROTO((const char *msgid, ...))
5330 #ifndef ANSI_PROTOTYPES
5335 VA_START (ap, msgid);
5337 #ifndef ANSI_PROTOTYPES
5338 msgid = va_arg (ap, const char *);
5341 fprintf (stderr, "%s: ", programname);
5342 vfprintf (stderr, _(msgid), ap);
5344 fprintf (stderr, "\n");
5345 delete_temp_files ();
5350 error VPROTO((const char *msgid, ...))
5352 #ifndef ANSI_PROTOTYPES
5357 VA_START (ap, msgid);
5359 #ifndef ANSI_PROTOTYPES
5360 msgid = va_arg (ap, const char *);
5363 fprintf (stderr, "%s: ", programname);
5364 vfprintf (stderr, _(msgid), ap);
5367 fprintf (stderr, "\n");
5371 notice VPROTO((const char *msgid, ...))
5373 #ifndef ANSI_PROTOTYPES
5378 VA_START (ap, msgid);
5380 #ifndef ANSI_PROTOTYPES
5381 msgid = va_arg (ap, const char *);
5384 vfprintf (stderr, _(msgid), ap);
5390 validate_all_switches ()
5392 struct compiler *comp;
5393 register const char *p;
5395 struct spec_list *spec;
5397 for (comp = compilers; comp->spec[0]; comp++)
5400 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5404 if (c == '%' && *p == '{')
5405 /* We have a switch spec. */
5406 validate_switches (p + 1);
5410 /* look through the linked list of specs read from the specs file */
5411 for (spec = specs; spec ; spec = spec->next)
5413 p = *(spec->ptr_spec);
5415 if (c == '%' && *p == '{')
5416 /* We have a switch spec. */
5417 validate_switches (p + 1);
5420 p = link_command_spec;
5422 if (c == '%' && *p == '{')
5423 /* We have a switch spec. */
5424 validate_switches (p + 1);
5427 /* Look at the switch-name that comes after START
5428 and mark as valid all supplied switches that match it. */
5431 validate_switches (start)
5434 register const char *p = start;
5449 while (*p != ':' && *p != '}') p++;
5453 else if (p[-1] == '*')
5455 /* Mark all matching switches as valid. */
5457 for (i = 0; i < n_switches; i++)
5458 if (!strncmp (switches[i].part1, filter, p - filter))
5459 switches[i].validated = 1;
5463 /* Mark an exact matching switch as valid. */
5464 for (i = 0; i < n_switches; i++)
5466 if (!strncmp (switches[i].part1, filter, p - filter)
5467 && switches[i].part1[p - filter] == 0)
5468 switches[i].validated = 1;
5473 /* Check whether a particular argument was used. The first time we
5474 canonicalize the switches to keep only the ones we care about. */
5488 static struct mswitchstr *mswitches;
5489 static int n_mswitches;
5494 struct mswitchstr *matches;
5498 /* Break multilib_matches into the component strings of string and replacement
5500 for (q = multilib_matches; *q != '\0'; q++)
5504 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5506 q = multilib_matches;
5517 matches[i].len = q - matches[i].str;
5519 matches[i].replace = ++q;
5520 while (*q != ';' && *q != '\0')
5526 matches[i].rep_len = q - matches[i].replace;
5534 /* Now build a list of the replacement string for switches that we care
5535 about. Make sure we allocate at least one entry. This prevents
5536 xmalloc from calling fatal, and prevents us from re-executing this
5539 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5540 * (n_switches ? n_switches : 1));
5541 for (i = 0; i < n_switches; i++)
5543 int xlen = strlen (switches[i].part1);
5544 for (j = 0; j < cnt; j++)
5545 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5547 mswitches[n_mswitches].str = matches[j].replace;
5548 mswitches[n_mswitches].len = matches[j].rep_len;
5549 mswitches[n_mswitches].replace = (char *)0;
5550 mswitches[n_mswitches].rep_len = 0;
5557 for (i = 0; i < n_mswitches; i++)
5558 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5565 default_arg (p, len)
5571 for (start = multilib_defaults; *start != '\0'; start = end+1)
5573 while (*start == ' ' || *start == '\t')
5579 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5582 if ((end - start) == len && strncmp (p, start, len) == 0)
5592 /* Work out the subdirectory to use based on the
5593 options. The format of multilib_select is a list of elements.
5594 Each element is a subdirectory name followed by a list of options
5595 followed by a semicolon. gcc will consider each line in turn. If
5596 none of the options beginning with an exclamation point are
5597 present, and all of the other options are present, that
5598 subdirectory will be used. */
5603 char *p = multilib_select;
5605 char *this_path, *this_arg;
5611 /* Ignore newlines. */
5618 /* Get the initial path. */
5626 this_path_len = p - this_path;
5628 /* Check the arguments. */
5643 while (*p != ' ' && *p != ';')
5650 if (*this_arg != '!')
5658 /* If this is a default argument, we can just ignore it.
5659 This is true even if this_arg begins with '!'. Beginning
5660 with '!' does not mean that this argument is necessarily
5661 inappropriate for this library: it merely means that
5662 there is a more specific library which uses this
5663 argument. If this argument is a default, we need not
5664 consider that more specific library. */
5665 if (! default_arg (this_arg, p - this_arg))
5667 ok = used_arg (this_arg, p - this_arg);
5678 if (this_path_len != 1
5679 || this_path[0] != '.')
5681 char * new_multilib_dir = xmalloc (this_path_len + 1);
5682 strncpy (new_multilib_dir, this_path, this_path_len);
5683 new_multilib_dir[this_path_len] = '\0';
5684 multilib_dir = new_multilib_dir;
5693 /* Print out the multiple library subdirectory selection
5694 information. This prints out a series of lines. Each line looks
5695 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5696 required. Only the desired options are printed out, the negative
5697 matches. The options are print without a leading dash. There are
5698 no spaces to make it easy to use the information in the shell.
5699 Each subdirectory is printed only once. This assumes the ordering
5700 generated by the genmultilib script. */
5703 print_multilib_info ()
5705 char *p = multilib_select;
5706 char *last_path = 0, *this_path;
5708 int last_path_len = 0;
5712 /* Ignore newlines. */
5719 /* Get the initial path. */
5728 /* If this is a duplicate, skip it. */
5729 skip = (last_path != 0 && p - this_path == last_path_len
5730 && ! strncmp (last_path, this_path, last_path_len));
5732 last_path = this_path;
5733 last_path_len = p - this_path;
5735 /* If this directory requires any default arguments, we can skip
5736 it. We will already have printed a directory identical to
5737 this one which does not require that default argument. */
5755 while (*q != ' ' && *q != ';')
5763 && default_arg (arg, q - arg))
5778 for (p1 = last_path; p1 < p; p1++)
5797 use_arg = *p != '!';
5802 while (*p != ' ' && *p != ';')
5817 /* If there are extra options, print them now */
5818 if (multilib_extra && *multilib_extra)
5820 int print_at = TRUE;
5823 for (q = multilib_extra; *q != '\0'; q++)