1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 This paragraph is here to try to keep Sun CC from dying.
23 The number of chars here seems crucial!!!! */
25 /* $FreeBSD: src/contrib/gcc/gcc.c,v 1.17.2.9 2002/06/20 23:12:28 obrien Exp $ */
27 /* This program is the user interface to the C compiler and possibly to
28 other compilers. It is used because compilation is a complicated procedure
29 which involves running several programs and passing temporary files between
30 them, forwarding the users switches to those programs selectively,
31 and deleting the temporary files at the end.
33 CC recognizes how to compile each input file by suffixes in the file names.
34 Once it knows which kind of compilation to perform, the procedure for
35 compilation is specified by a string called a "spec". */
46 #define exit __posix_exit
49 /* By default there is no special suffix for executables. */
50 #ifdef EXECUTABLE_SUFFIX
51 #define HAVE_EXECUTABLE_SUFFIX
53 #define EXECUTABLE_SUFFIX ""
56 /* By default, the suffix for object files is ".o". */
58 #define HAVE_OBJECT_SUFFIX
60 #define OBJECT_SUFFIX ".o"
63 /* By default, colon separates directories in a path. */
64 #ifndef PATH_SEPARATOR
65 #define PATH_SEPARATOR ':'
69 #define DIR_SEPARATOR '/'
72 /* Define IS_DIR_SEPARATOR. */
73 #ifndef DIR_SEPARATOR_2
74 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
75 #else /* DIR_SEPARATOR_2 */
76 # define IS_DIR_SEPARATOR(ch) \
77 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
78 #endif /* DIR_SEPARATOR_2 */
80 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
82 #define obstack_chunk_alloc xmalloc
83 #define obstack_chunk_free free
85 #ifndef GET_ENV_PATH_LIST
86 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
90 #define kill(p,s) raise(s)
93 /* If a stage of compilation returns an exit status >= 1,
94 compilation of that file ceases. */
96 #define MIN_FATAL_STATUS 1
98 /* Flag saying to print the directories gcc will search through looking for
99 programs, libraries, etc. */
101 static int print_search_dirs;
103 /* Flag saying to print the full filename of this file
104 as found through our usual search mechanism. */
106 static const char *print_file_name = NULL;
108 /* As print_file_name, but search for executable file. */
110 static const char *print_prog_name = NULL;
112 /* Flag saying to print the relative path we'd use to
113 find libgcc.a given the current compiler flags. */
115 static int print_multi_directory;
117 /* Flag saying to print the list of subdirectories and
118 compiler flags used to select them in a standard form. */
120 static int print_multi_lib;
122 /* Flag saying to print the command line options understood by gcc and its
125 static int print_help_list;
127 /* Flag indicating whether we should print the command and arguments */
129 static int verbose_flag;
131 /* Nonzero means write "temp" files in source directory
132 and use the source file's name in them, and don't delete them. */
134 static int save_temps_flag;
136 /* The compiler version. */
138 static char *compiler_version;
140 /* The target version specified with -V */
142 static char *spec_version = DEFAULT_TARGET_VERSION;
144 /* The target machine specified with -b. */
146 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
148 /* Nonzero if cross-compiling.
149 When -b is used, the value comes from the `specs' file. */
152 static char *cross_compile = "1";
154 static char *cross_compile = "0";
157 /* The number of errors that have occurred; the link phase will not be
158 run if this is non-zero. */
159 static int error_count = 0;
161 /* This is the obstack which we use to allocate many strings. */
163 static struct obstack obstack;
165 /* This is the obstack to build an environment variable to pass to
166 collect2 that describes all of the relevant switches of what to
167 pass the compiler in building the list of pointers to constructors
170 static struct obstack collect_obstack;
172 extern char *version_string;
174 /* Forward declaration for prototypes. */
177 static void init_spec PROTO((void));
178 static void read_specs PROTO((const char *, int));
179 static void set_spec PROTO((const char *, const char *));
180 static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
181 static char *build_search_list PROTO((struct path_prefix *, const char *, int));
182 static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
183 static char *find_a_file PROTO((struct path_prefix *, const char *, int));
184 static void add_prefix PROTO((struct path_prefix *, const char *,
185 const char *, int, int, int *));
186 static char *skip_whitespace PROTO((char *));
187 static void record_temp_file PROTO((const char *, int, int));
188 static void delete_if_ordinary PROTO((const char *));
189 static void delete_temp_files PROTO((void));
190 static void delete_failure_queue PROTO((void));
191 static void clear_failure_queue PROTO((void));
192 static int check_live_switch PROTO((int, int));
193 static const char *handle_braces PROTO((const char *));
194 static char *save_string PROTO((const char *, int));
195 extern int do_spec PROTO((const char *));
196 static int do_spec_1 PROTO((const char *, int, const char *));
197 static const char *find_file PROTO((const char *));
198 static int is_directory PROTO((const char *, const char *, int));
199 static void validate_switches PROTO((const char *));
200 static void validate_all_switches PROTO((void));
201 static void give_switch PROTO((int, int, int));
202 static int used_arg PROTO((const char *, int));
203 static int default_arg PROTO((const char *, int));
204 static void set_multilib_dir PROTO((void));
205 static void print_multilib_info PROTO((void));
206 static void pfatal_with_name PROTO((const char *)) ATTRIBUTE_NORETURN;
207 static void perror_with_name PROTO((const char *));
208 static void pfatal_pexecute PROTO((const char *, const char *))
210 static void error PVPROTO((const char *, ...))
212 static void notice PVPROTO((const char *, ...))
214 static void display_help PROTO((void));
215 static void add_preprocessor_option PROTO ((const char *, int));
216 static void add_assembler_option PROTO ((const char *, int));
217 static void add_linker_option PROTO ((const char *, int));
218 static void process_command PROTO ((int, char **));
219 static int execute PROTO ((void));
220 static void unused_prefix_warnings PROTO ((struct path_prefix *));
221 static void clear_args PROTO ((void));
222 static void fatal_error PROTO ((int));
224 void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN;
226 /* Called before processing to change/add/remove arguments. */
227 extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)),
228 int *, char ***, int *));
230 /* Called before linking. Returns 0 on success and -1 on failure. */
231 extern int lang_specific_pre_link ();
233 /* Number of extra output files that lang_specific_pre_link may generate. */
234 extern int lang_specific_extra_outfiles;
236 /* Specs are strings containing lines, each of which (if not blank)
237 is made up of a program name, and arguments separated by spaces.
238 The program name must be exact and start from root, since no path
239 is searched and it is unreliable to depend on the current working directory.
240 Redirection of input or output is not supported; the subprograms must
241 accept filenames saying what files to read and write.
243 In addition, the specs can contain %-sequences to substitute variable text
244 or for conditional text. Here is a table of all defined %-sequences.
245 Note that spaces are not generated automatically around the results of
246 expanding these sequences; therefore, you can concatenate them together
247 or with constant text in a single argument.
249 %% substitute one % into the program name or argument.
250 %i substitute the name of the input file being processed.
251 %b substitute the basename of the input file being processed.
252 This is the substring up to (and not including) the last period
253 and not including the directory.
255 substitute a file name that has suffix SUFFIX and is chosen
256 once per compilation, and mark the argument a la %d. To reduce
257 exposure to denial-of-service attacks, the file name is now
258 chosen in a way that is hard to predict even when previously
259 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
260 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
261 the regexp "[.A-Za-z]*" or the special string "%O", which is
262 treated exactly as if %O had been pre-processed. Previously, %g
263 was simply substituted with a file name chosen once per compilation,
264 without regard to any appended suffix (which was therefore treated
265 just like ordinary text), making such attacks more likely to succeed.
267 like %g, but generates a new temporary file name even if %uSUFFIX
270 substitutes the last file name generated with %uSUFFIX, generating a
271 new one if there is no such last file name. In the absence of any
272 %uSUFFIX, this is just like %gSUFFIX, except they don't share
273 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
274 would involve the generation of two distinct file names, one
275 for each `%g.s' and another for each `%U.s'. Previously, %U was
276 simply substituted with a file name chosen for the previous %u,
277 without regard to any appended suffix.
278 %d marks the argument containing or following the %d as a
279 temporary file name, so that that file will be deleted if CC exits
280 successfully. Unlike %g, this contributes no text to the argument.
281 %w marks the argument containing or following the %w as the
282 "output file" of this compilation. This puts the argument
283 into the sequence of arguments that %o will substitute later.
285 like %{...} but mark last argument supplied within
286 as a file to be deleted on failure.
287 %o substitutes the names of all the output files, with spaces
288 automatically placed around them. You should write spaces
289 around the %o as well or the results are undefined.
290 %o is for use in the specs for running the linker.
291 Input files whose names have no recognized suffix are not compiled
292 at all, but they are included among the output files, so they will
294 %O substitutes the suffix for object files. Note that this is
295 handled specially when it immediately follows %g, %u, or %U,
296 because of the need for those to form complete file names. The
297 handling is such that %O is treated exactly as if it had already
298 been substituted, except that %g, %u, and %U do not currently
299 support additional SUFFIX characters following %O as they would
300 following, for example, `.o'.
301 %p substitutes the standard macro predefinitions for the
302 current target machine. Use this when running cpp.
303 %P like %p, but puts `__' before and after the name of each macro.
304 (Except macros that already have __.)
306 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
307 %s current argument is the name of a library or startup file of some sort.
308 Search for that file in a standard list of directories
309 and substitute the full name found.
310 %eSTR Print STR as an error message. STR is terminated by a newline.
311 Use this when inconsistent options are detected.
312 %x{OPTION} Accumulate an option for %X.
313 %X Output the accumulated linker options specified by compilations.
314 %Y Output the accumulated assembler options specified by compilations.
315 %Z Output the accumulated preprocessor options specified by compilations.
316 %v1 Substitute the major version number of GCC.
317 (For version 2.5.n, this is 2.)
318 %v2 Substitute the minor version number of GCC.
319 (For version 2.5.n, this is 5.)
320 %a process ASM_SPEC as a spec.
321 This allows config.h to specify part of the spec for running as.
322 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
323 used here. This can be used to run a post-processor after the
324 assembler has done its job.
325 %D Dump out a -L option for each directory in startfile_prefixes.
326 If multilib_dir is set, extra entries are generated with it affixed.
327 %l process LINK_SPEC as a spec.
328 %L process LIB_SPEC as a spec.
329 %G process LIBGCC_SPEC as a spec.
330 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
331 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
332 %c process SIGNED_CHAR_SPEC as a spec.
333 %C process CPP_SPEC as a spec. A capital C is actually used here.
334 %1 process CC1_SPEC as a spec.
335 %2 process CC1PLUS_SPEC as a spec.
336 %| output "-" if the input for the current command is coming from a pipe.
337 %* substitute the variable part of a matched option. (See below.)
338 Note that each comma in the substituted string is replaced by
340 %{S} substitutes the -S switch, if that switch was given to CC.
341 If that switch was not specified, this substitutes nothing.
342 Here S is a metasyntactic variable.
343 %{S*} substitutes all the switches specified to CC whose names start
344 with -S. This is used for -o, -D, -I, etc; switches that take
345 arguments. CC considers `-o foo' as being one switch whose
346 name starts with `o'. %{o*} would substitute this text,
347 including the space; thus, two arguments would be generated.
348 %{^S*} likewise, but don't put a blank between a switch and any args.
349 %{S*:X} substitutes X if one or more switches whose names start with -S are
350 specified to CC. Note that the tail part of the -S option
351 (i.e. the part matched by the `*') will be substituted for each
352 occurrence of %* within X.
353 %{S:X} substitutes X, but only if the -S switch was given to CC.
354 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
355 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
356 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
357 %{.S:X} substitutes X, but only if processing a file with suffix S.
358 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
359 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
360 combined with ! and . as above binding stronger than the OR.
361 %(Spec) processes a specification defined in a specs file as *Spec:
362 %[Spec] as above, but put __ around -D arguments
364 The conditional text X in a %{S:X} or %{!S:X} construct may contain
365 other nested % constructs or spaces, or even newlines. They are
366 processed as usual, as described above.
368 The -O, -f, -m, and -W switches are handled specifically in these
369 constructs. If another value of -O or the negated form of a -f, -m, or
370 -W switch is found later in the command line, the earlier switch
371 value is ignored, except with {S*} where S is just one letter; this
372 passes all matching options.
374 The character | at the beginning of the predicate text is used to indicate
375 that a command should be piped to the following command, but only if -pipe
378 Note that it is built into CC which switches take arguments and which
379 do not. You might think it would be useful to generalize this to
380 allow each compiler's spec to say which switches take arguments. But
381 this cannot be done in a consistent fashion. CC cannot even decide
382 which input files have been specified without knowing which switches
383 take arguments, and it must know which input files to compile in order
384 to tell which compilers to run.
386 CC also knows implicitly that arguments starting in `-l' are to be
387 treated as compiler output files, and passed to the linker in their
388 proper position among the other output files. */
390 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
392 /* config.h can define ASM_SPEC to provide extra args to the assembler
393 or extra switch-translations. */
398 /* config.h can define ASM_FINAL_SPEC to run a post processor after
399 the assembler has run. */
400 #ifndef ASM_FINAL_SPEC
401 #define ASM_FINAL_SPEC ""
404 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
405 or extra switch-translations. */
410 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
411 or extra switch-translations. */
416 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
417 or extra switch-translations. */
419 #define CC1PLUS_SPEC ""
422 /* config.h can define LINK_SPEC to provide extra args to the linker
423 or extra switch-translations. */
428 /* config.h can define LIB_SPEC to override the default libraries. */
430 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
433 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
436 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
437 /* Have gcc do the search for libgcc.a. */
438 #define LIBGCC_SPEC "libgcc.a%s"
440 #define LIBGCC_SPEC "-lgcc"
444 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
445 #ifndef STARTFILE_SPEC
446 #define STARTFILE_SPEC \
447 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
450 /* config.h can define SWITCHES_NEED_SPACES to control which options
451 require spaces between the option and the argument. */
452 #ifndef SWITCHES_NEED_SPACES
453 #define SWITCHES_NEED_SPACES ""
456 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
458 #define ENDFILE_SPEC ""
461 /* This spec is used for telling cpp whether char is signed or not. */
462 #ifndef SIGNED_CHAR_SPEC
463 /* Use #if rather than ?:
464 because MIPS C compiler rejects like ?: in initializers. */
465 #if DEFAULT_SIGNED_CHAR
466 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
468 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
473 #define LINKER_NAME "collect2"
476 static char *cpp_spec = CPP_SPEC;
477 static char *cpp_predefines = CPP_PREDEFINES;
478 static char *cc1_spec = CC1_SPEC;
479 static char *cc1plus_spec = CC1PLUS_SPEC;
480 static char *signed_char_spec = SIGNED_CHAR_SPEC;
481 static char *asm_spec = ASM_SPEC;
482 static char *asm_final_spec = ASM_FINAL_SPEC;
483 static char *link_spec = LINK_SPEC;
484 static char *lib_spec = LIB_SPEC;
485 static char *libgcc_spec = LIBGCC_SPEC;
486 static char *endfile_spec = ENDFILE_SPEC;
487 static char *startfile_spec = STARTFILE_SPEC;
488 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
489 static char *linker_name_spec = LINKER_NAME;
491 /* Some compilers have limits on line lengths, and the multilib_select
492 and/or multilib_matches strings can be very long, so we build them at
494 static struct obstack multilib_obstack;
495 static char *multilib_select;
496 static char *multilib_matches;
497 static char *multilib_defaults;
498 #include "multilib.h"
500 /* Check whether a particular argument is a default argument. */
502 #ifndef MULTILIB_DEFAULTS
503 #define MULTILIB_DEFAULTS { "" }
506 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
509 struct user_specs *next;
510 const char *filename;
513 static struct user_specs *user_specs_head, *user_specs_tail;
515 /* This defines which switch letters take arguments. */
517 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
518 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
519 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
520 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
521 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
522 || (CHAR) == 'B' || (CHAR) == 'b')
524 #ifndef SWITCH_TAKES_ARG
525 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
528 /* This defines which multi-letter switches take arguments. */
530 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
531 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
532 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
533 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
534 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
535 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
536 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
538 #ifndef WORD_SWITCH_TAKES_ARG
539 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
543 #ifdef HAVE_EXECUTABLE_SUFFIX
544 /* This defines which switches stop a full compilation. */
545 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
546 ((CHAR) == 'c' || (CHAR) == 'S')
548 #ifndef SWITCH_CURTAILS_COMPILATION
549 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
550 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
554 /* Record the mapping from file suffixes for compilation specs. */
558 const char *suffix; /* Use this compiler for input files
559 whose names end in this suffix. */
561 const char *spec[4]; /* To use this compiler, concatenate these
562 specs and pass to do_spec. */
565 /* Pointer to a vector of `struct compiler' that gives the spec for
566 compiling a file, based on its suffix.
567 A file that does not end in any of these suffixes will be passed
568 unchanged to the loader and nothing else will be done to it.
570 An entry containing two 0s is used to terminate the vector.
572 If multiple entries match a file, the last matching one is used. */
574 static struct compiler *compilers;
576 /* Number of entries in `compilers', not counting the null terminator. */
578 static int n_compilers;
580 /* The default list of file name suffixes and their compilation specs. */
582 static struct compiler default_compilers[] =
584 /* Add lists of suffixes of known languages here. If those languages
585 were not present when we built the driver, we will hit these copies
586 and be given a more meaningful error than "file not used since
587 linking is not done". */
588 {".m", {"#Objective-C"}},
589 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}},
590 {".c++", {"#C++"}}, {".C", {"#C++"}},
591 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
592 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
593 {".fpp", {"#Fortran"}},
594 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
595 /* Next come the entries for C. */
600 "%{E|M|MM:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
601 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
602 %{C:%{!E:%eGNU C does not support -C without using -E}}\
603 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
604 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
605 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
606 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
607 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
608 %{ffast-math:-D__FAST_MATH__}\
609 %{traditional} %{ftraditional:-traditional}\
610 %{traditional-cpp:-traditional}\
611 %{fleading-underscore} %{fno-leading-underscore}\
612 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
613 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
614 %{!E:%{!M:%{!MM:cc1 %i %1 \
615 %{std*} %{nostdinc*} %{A*} %{I*} %I\
616 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
617 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
618 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
619 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
620 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
621 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
622 %{ffast-math:-D__FAST_MATH__}\
623 %{H} %C %{D*} %{U*} %{i*} %Z\
624 %{ftraditional:-traditional}\
625 %{traditional-cpp:-traditional}\
626 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
627 %{aux-info*} %{Qn:-fno-ident}\
629 %{g*} %{O*} %{W*} %{w} %{pedantic*}\
630 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
631 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
633 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
634 %{!pipe:%g.s} %A\n }}}}"
635 #else /* ! USE_CPPLIB */
636 "cpp0 -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 %{!no-gcc:-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 }}}}"
661 #endif /* ! USE_CPPLIB */
664 {"%{E:cpp0 -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 %{!no-gcc:-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 cpp0 %{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 %{!no-gcc:-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 {"cpp0 -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;
2409 #if defined(FREEBSD_NATIVE)
2410 #include <objformat.h>
2412 typedef enum { OBJFMT_UNKNOWN, OBJFMT_AOUT, OBJFMT_ELF } objf_t;
2414 static objf_t objformat = OBJFMT_UNKNOWN;
2415 #endif /* FREEBSD_NATIVE */
2417 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2419 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2420 is true if we should look for an executable suffix as well. */
2423 convert_filename (name, do_exe)
2433 len = strlen (name);
2435 #ifdef HAVE_OBJECT_SUFFIX
2436 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2438 && name[len - 2] == '.'
2439 && name[len - 1] == 'o')
2441 obstack_grow (&obstack, name, len - 2);
2442 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2443 name = obstack_finish (&obstack);
2447 #ifdef HAVE_EXECUTABLE_SUFFIX
2448 /* If there is no filetype, make it the executable suffix (which includes
2449 the "."). But don't get confused if we have just "-o". */
2450 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2453 for (i = len - 1; i >= 0; i--)
2454 if (IS_DIR_SEPARATOR (name[i]))
2457 for (i++; i < len; i++)
2461 obstack_grow (&obstack, name, len);
2462 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2463 name = obstack_finish (&obstack);
2470 /* Display the command line switches accepted by gcc. */
2474 printf ("Usage: %s [options] file...\n", programname);
2475 printf ("Options:\n");
2477 printf (" --help Display this information\n");
2479 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2480 printf (" -dumpspecs Display all of the built in spec strings\n");
2481 printf (" -dumpversion Display the version of the compiler\n");
2482 printf (" -dumpmachine Display the compiler's target processor\n");
2483 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2484 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2485 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2486 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2487 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2488 printf (" -print-multi-lib Display the mapping between command line options and\n");
2489 printf (" multiple library search directories\n");
2490 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2491 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2492 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2493 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2494 printf (" -save-temps Do not delete intermediate files\n");
2495 printf (" -pipe Use pipes rather than intermediate files\n");
2496 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2497 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2498 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2499 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2500 printf (" -V <version> Run gcc version number <version>, if installed\n");
2501 printf (" -v Display the programs invoked by the compiler\n");
2502 printf (" -E Preprocess only; do not compile, assemble or link\n");
2503 printf (" -S Compile only; do not assemble or link\n");
2504 printf (" -c Compile and assemble, but do not link\n");
2505 printf (" -o <file> Place the output into <file>\n");
2506 printf (" -x <language> Specify the language of the following input files\n");
2507 printf (" Permissable languages include: c c++ assembler none\n");
2508 printf (" 'none' means revert to the default behaviour of\n");
2509 printf (" guessing the language based on the file's extension\n");
2511 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2512 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2514 printf ("on to these processes the -W<letter> options must be used.\n");
2516 /* The rest of the options are displayed by invocations of the various
2521 add_preprocessor_option (option, len)
2522 const char * option;
2525 n_preprocessor_options++;
2527 if (! preprocessor_options)
2528 preprocessor_options
2529 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
2531 preprocessor_options
2532 = (char **) xrealloc (preprocessor_options,
2533 n_preprocessor_options * sizeof (char *));
2535 preprocessor_options [n_preprocessor_options - 1] =
2536 save_string (option, len);
2540 add_assembler_option (option, len)
2541 const char * option;
2544 n_assembler_options++;
2546 if (! assembler_options)
2548 = (char **) xmalloc (n_assembler_options * sizeof (char *));
2551 = (char **) xrealloc (assembler_options,
2552 n_assembler_options * sizeof (char *));
2554 assembler_options [n_assembler_options - 1] = save_string (option, len);
2558 add_linker_option (option, len)
2559 const char * option;
2564 if (! linker_options)
2566 = (char **) xmalloc (n_linker_options * sizeof (char *));
2569 = (char **) xrealloc (linker_options,
2570 n_linker_options * sizeof (char *));
2572 linker_options [n_linker_options - 1] = save_string (option, len);
2575 /* Create the vector `switches' and its contents.
2576 Store its length in `n_switches'. */
2579 process_command (argc, argv)
2586 char *spec_lang = 0;
2587 int last_language_n_infiles;
2590 int lang_n_infiles = 0;
2592 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2596 added_libraries = 0;
2598 /* Figure compiler version from version string. */
2600 compiler_version = temp1 =
2601 save_string (version_string, strlen (version_string));
2602 for (; *temp1; ++temp1)
2611 /* Set up the default search paths. */
2613 if (gcc_exec_prefix)
2615 int len = strlen (gcc_exec_prefix);
2616 if (len > (int) sizeof ("/lib/gcc-lib/")-1
2617 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
2619 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2620 if (IS_DIR_SEPARATOR (*temp)
2621 && strncmp (temp+1, "lib", 3) == 0
2622 && IS_DIR_SEPARATOR (temp[4])
2623 && strncmp (temp+5, "gcc-lib", 7) == 0)
2624 len -= sizeof ("/lib/gcc-lib/") - 1;
2627 set_std_prefix (gcc_exec_prefix, len);
2628 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2629 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2632 /* COMPILER_PATH and LIBRARY_PATH have values
2633 that are lists of directory names with colons. */
2635 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
2638 const char *startp, *endp;
2639 char *nstore = (char *) alloca (strlen (temp) + 3);
2641 startp = endp = temp;
2644 if (*endp == PATH_SEPARATOR || *endp == 0)
2646 strncpy (nstore, startp, endp-startp);
2648 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2649 else if (!IS_DIR_SEPARATOR (endp[-1]))
2651 nstore[endp-startp] = DIR_SEPARATOR;
2652 nstore[endp-startp+1] = 0;
2655 nstore[endp-startp] = 0;
2656 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2657 add_prefix (&include_prefixes,
2658 concat (nstore, "include", NULL_PTR),
2662 endp = startp = endp + 1;
2669 GET_ENV_PATH_LIST (temp, "LIBRARY_PATH");
2670 if (temp && *cross_compile == '0')
2672 const char *startp, *endp;
2673 char *nstore = (char *) alloca (strlen (temp) + 3);
2675 startp = endp = temp;
2678 if (*endp == PATH_SEPARATOR || *endp == 0)
2680 strncpy (nstore, startp, endp-startp);
2682 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2683 else if (!IS_DIR_SEPARATOR (endp[-1]))
2685 nstore[endp-startp] = DIR_SEPARATOR;
2686 nstore[endp-startp+1] = 0;
2689 nstore[endp-startp] = 0;
2690 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2694 endp = startp = endp + 1;
2701 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2702 GET_ENV_PATH_LIST (temp, "LPATH");
2703 if (temp && *cross_compile == '0')
2705 const char *startp, *endp;
2706 char *nstore = (char *) alloca (strlen (temp) + 3);
2708 startp = endp = temp;
2711 if (*endp == PATH_SEPARATOR || *endp == 0)
2713 strncpy (nstore, startp, endp-startp);
2715 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2716 else if (!IS_DIR_SEPARATOR (endp[-1]))
2718 nstore[endp-startp] = DIR_SEPARATOR;
2719 nstore[endp-startp+1] = 0;
2722 nstore[endp-startp] = 0;
2723 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2727 endp = startp = endp + 1;
2734 #if defined(FREEBSD_NATIVE)
2737 if (getobjformat (buf, sizeof buf, &argc, argv))
2738 if (strcmp (buf, "aout") == 0)
2739 objformat = OBJFMT_AOUT;
2740 else if (strcmp (buf, "elf") == 0)
2741 objformat = OBJFMT_ELF;
2743 fprintf(stderr, "Unrecognized object format: %s\n", buf);
2745 #endif /* FREEBSD_NATIVE */
2747 /* Options specified as if they appeared on the command line. */
2748 temp = getenv ("GCC_OPTIONS");
2749 if ((temp) && (strlen (temp) > 0))
2757 while (isspace (*temp))
2759 len = strlen (temp);
2760 envopts = (char *) xmalloc (len + 1);
2761 strcpy (envopts, temp);
2763 for (i = 0; i < (len - 1); i++)
2764 if ((isspace (envopts[i])) && ! (isspace (envopts[i+1])))
2767 new_argv = (char **) alloca ((optc + argc) * sizeof(char *));
2769 for (i = 0, new_argc = 1; new_argc <= optc; new_argc++)
2771 while (isspace (envopts[i]))
2773 new_argv[new_argc] = envopts + i;
2774 while (!isspace (envopts[i]) && (envopts[i] != '\0'))
2776 envopts[i++] = '\0';
2778 for (i = 1; i < argc; i++)
2779 new_argv[new_argc++] = argv[i];
2785 /* Convert new-style -- options to old-style. */
2786 translate_options (&argc, &argv);
2788 /* Do language-specific adjustment/addition of flags. */
2789 lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2791 /* Scan argv twice. Here, the first time, just count how many switches
2792 there will be in their vector, and how many input files in theirs.
2793 Here we also parse the switches that cc itself uses (e.g. -v). */
2795 for (i = 1; i < argc; i++)
2797 if (! strcmp (argv[i], "-dumpspecs"))
2799 struct spec_list *sl;
2801 for (sl = specs; sl; sl = sl->next)
2802 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2803 if (link_command_spec)
2804 printf ("*link_command:\n%s\n\n", link_command_spec);
2807 else if (! strcmp (argv[i], "-dumpversion"))
2809 printf ("%s\n", spec_version);
2812 else if (! strcmp (argv[i], "-dumpmachine"))
2814 printf ("%s\n", spec_machine);
2817 else if (strcmp (argv[i], "-fhelp") == 0)
2819 /* translate_options () has turned --help into -fhelp. */
2820 print_help_list = 1;
2822 /* We will be passing a dummy file on to the sub-processes. */
2826 add_preprocessor_option ("--help", 6);
2827 add_assembler_option ("--help", 6);
2828 add_linker_option ("--help", 6);
2830 else if (! strcmp (argv[i], "-print-search-dirs"))
2831 print_search_dirs = 1;
2832 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2833 print_file_name = "libgcc.a";
2834 else if (! strncmp (argv[i], "-print-file-name=", 17))
2835 print_file_name = argv[i] + 17;
2836 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2837 print_prog_name = argv[i] + 17;
2838 else if (! strcmp (argv[i], "-print-multi-lib"))
2839 print_multi_lib = 1;
2840 else if (! strcmp (argv[i], "-print-multi-directory"))
2841 print_multi_directory = 1;
2842 else if (! strncmp (argv[i], "-Wa,", 4))
2845 /* Pass the rest of this option to the assembler. */
2847 /* Split the argument at commas. */
2849 for (j = 4; argv[i][j]; j++)
2850 if (argv[i][j] == ',')
2852 add_assembler_option (argv[i] + prev, j - prev);
2856 /* Record the part after the last comma. */
2857 add_assembler_option (argv[i] + prev, j - prev);
2859 else if (! strncmp (argv[i], "-Wp,", 4))
2862 /* Pass the rest of this option to the preprocessor. */
2864 /* Split the argument at commas. */
2866 for (j = 4; argv[i][j]; j++)
2867 if (argv[i][j] == ',')
2869 add_preprocessor_option (argv[i] + prev, j - prev);
2873 /* Record the part after the last comma. */
2874 add_preprocessor_option (argv[i] + prev, j - prev);
2876 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2877 /* The +e options to the C++ front-end. */
2879 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2882 /* Split the argument at commas. */
2883 for (j = 3; argv[i][j]; j++)
2884 n_infiles += (argv[i][j] == ',');
2886 else if (strcmp (argv[i], "-Xlinker") == 0)
2889 fatal ("argument to `-Xlinker' is missing");
2894 else if (strcmp (argv[i], "-l") == 0)
2897 fatal ("argument to `-l' is missing");
2902 else if (strncmp (argv[i], "-l", 2) == 0)
2904 else if (strcmp (argv[i], "-save-temps") == 0)
2906 save_temps_flag = 1;
2909 else if (strcmp (argv[i], "-specs") == 0)
2911 struct user_specs *user = (struct user_specs *)
2912 xmalloc (sizeof (struct user_specs));
2914 fatal ("argument to `-specs' is missing");
2916 user->next = (struct user_specs *)0;
2917 user->filename = argv[i];
2918 if (user_specs_tail)
2919 user_specs_tail->next = user;
2921 user_specs_head = user;
2922 user_specs_tail = user;
2924 else if (strncmp (argv[i], "-specs=", 7) == 0)
2926 struct user_specs *user = (struct user_specs *)
2927 xmalloc (sizeof (struct user_specs));
2928 if (strlen (argv[i]) == 7)
2929 fatal ("argument to `-specs=' is missing");
2931 user->next = (struct user_specs *)0;
2932 user->filename = argv[i]+7;
2933 if (user_specs_tail)
2934 user_specs_tail->next = user;
2936 user_specs_head = user;
2937 user_specs_tail = user;
2939 else if (argv[i][0] == '-' && argv[i][1] != 0)
2941 register char *p = &argv[i][1];
2942 register int c = *p;
2948 if (p[1] == 0 && i + 1 == argc)
2949 fatal ("argument to `-b' is missing");
2951 spec_machine = argv[++i];
2953 spec_machine = p + 1;
2955 warn_std_ptr = &warn_std;
2961 if (p[1] == 0 && i + 1 == argc)
2962 fatal ("argument to `-B' is missing");
2967 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2968 add_prefix (&startfile_prefixes, value, NULL_PTR,
2970 add_prefix (&include_prefixes, concat (value, "include",
2972 NULL_PTR, 1, 0, NULL_PTR);
2974 /* As a kludge, if the arg is "[foo/]stageN/", just add
2975 "[foo/]include" to the include prefix. */
2977 int len = strlen (value);
2980 && (IS_DIR_SEPARATOR (value[len - 8]))))
2981 && strncmp (value + len - 7, "stage", 5) == 0
2982 && ISDIGIT (value[len - 2])
2983 && (IS_DIR_SEPARATOR (value[len - 1])))
2986 add_prefix (&include_prefixes, "include", NULL_PTR,
2990 char *string = xmalloc (len + 1);
2991 strncpy (string, value, len-7);
2992 strcpy (string+len-7, "include");
2993 add_prefix (&include_prefixes, string, NULL_PTR,
3002 case 'v': /* Print our subcommands and print versions. */
3004 /* If they do anything other than exactly `-v', don't set
3005 verbose_flag; rather, continue on to give the error. */
3013 if (p[1] == 0 && i + 1 == argc)
3014 fatal ("argument to `-V' is missing");
3016 spec_version = argv[++i];
3018 spec_version = p + 1;
3019 compiler_version = spec_version;
3020 warn_std_ptr = &warn_std;
3022 /* Validate the version number. Use the same checks
3023 done when inserting it into a spec.
3025 The format of the version string is
3026 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3028 const char *v = compiler_version;
3030 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3031 while (! ISDIGIT (*v))
3034 if (v > compiler_version && v[-1] != '-')
3035 fatal ("invalid version number format");
3037 /* Set V after the first period. */
3038 while (ISDIGIT (*v))
3042 fatal ("invalid version number format");
3045 while (ISDIGIT (*v))
3048 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
3049 fatal ("invalid version number format");
3065 #if defined(HAVE_EXECUTABLE_SUFFIX)
3070 /* Forward scan, just in case -S or -c is specified
3077 if (argv[j][0] == '-')
3079 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3085 else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
3086 j += skip - (argv[j][2] != 0);
3087 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
3094 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3096 argv[i+1] = convert_filename (argv[i+1], ! have_c);
3098 argv[i] = convert_filename (argv[i], ! have_c);
3106 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3107 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3108 else if (WORD_SWITCH_TAKES_ARG (p))
3109 i += WORD_SWITCH_TAKES_ARG (p);
3119 if (have_c && have_o && lang_n_infiles > 1)
3120 fatal ("cannot specify -o with -c or -S and multiple compilations");
3122 /* Set up the search paths before we go looking for config files. */
3124 /* These come before the md prefixes so that we will find gcc's subcommands
3125 (such as cpp) rather than those of the host system. */
3126 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3127 as well as trying the machine and the version. */
3128 #ifdef FREEBSD_NATIVE
3132 n_switches++; /* add implied -maout */
3133 add_prefix (&exec_prefixes, PREFIX"/libexec/aout/", "BINUTILS",
3137 add_prefix (&exec_prefixes, PREFIX"/libexec/elf/", "BINUTILS",
3140 case OBJFMT_UNKNOWN:
3141 fatal ("object format unknown");
3143 #endif /* FREEBSD_NATIVE */
3146 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3147 0, 2, warn_std_ptr);
3148 #ifndef FREEBSD_NATIVE
3149 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3150 0, 2, warn_std_ptr);
3151 #endif /* not FREEBSD_NATIVE */
3154 #ifndef FREEBSD_NATIVE
3155 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3156 0, 1, warn_std_ptr);
3157 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3158 0, 1, warn_std_ptr);
3159 #endif /* not FREEBSD_NATIVE */
3161 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3162 dir_separator_str, NULL_PTR);
3164 /* If tooldir is relative, base it on exec_prefixes. A relative
3165 tooldir lets us move the installed tree as a unit.
3167 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3168 directories, so that we can search both the user specified directory
3169 and the standard place. */
3171 if (!IS_DIR_SEPARATOR (*tooldir_prefix))
3173 if (gcc_exec_prefix)
3175 char *gcc_exec_tooldir_prefix
3176 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3177 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
3179 add_prefix (&exec_prefixes,
3180 concat (gcc_exec_tooldir_prefix, "bin",
3181 dir_separator_str, NULL_PTR),
3182 NULL_PTR, 0, 0, NULL_PTR);
3183 add_prefix (&startfile_prefixes,
3184 concat (gcc_exec_tooldir_prefix, "lib",
3185 dir_separator_str, NULL_PTR),
3186 NULL_PTR, 0, 0, NULL_PTR);
3189 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3190 dir_separator_str, spec_version,
3191 dir_separator_str, tooldir_prefix, NULL_PTR);
3194 #ifndef FREEBSD_NATIVE
3195 add_prefix (&exec_prefixes,
3196 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
3197 "BINUTILS", 0, 0, NULL_PTR);
3198 add_prefix (&startfile_prefixes,
3199 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
3200 "BINUTILS", 0, 0, NULL_PTR);
3201 #endif /* not FREEBSD_NATIVE */
3203 /* More prefixes are enabled in main, after we read the specs file
3204 and determine whether this is cross-compilation or not. */
3207 /* Then create the space for the vectors and scan again. */
3209 switches = ((struct switchstr *)
3210 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3211 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3214 last_language_n_infiles = -1;
3216 /* This, time, copy the text of each switch and store a pointer
3217 to the copy in the vector of switches.
3218 Store all the infiles in their vector. */
3220 #if defined(FREEBSD_NATIVE)
3224 switches[n_switches].part1 = "maout";
3225 switches[n_switches].args = 0;
3226 switches[n_switches].live_cond = 0;
3227 switches[n_switches].validated = 0;
3229 putenv("OBJFORMAT=aout");
3232 putenv("OBJFORMAT=elf");
3234 case OBJFMT_UNKNOWN:
3235 fatal ("object format unknown");
3237 #endif /* FREEBSD_NATIVE */
3239 for (i = 1; i < argc; i++)
3241 /* Just skip the switches that were handled by the preceding loop. */
3242 if (! strncmp (argv[i], "-Wa,", 4))
3244 else if (! strncmp (argv[i], "-Wp,", 4))
3246 else if (! strcmp (argv[i], "-print-search-dirs"))
3248 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3250 else if (! strncmp (argv[i], "-print-file-name=", 17))
3252 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3254 else if (! strcmp (argv[i], "-print-multi-lib"))
3256 else if (! strcmp (argv[i], "-print-multi-directory"))
3258 else if (strcmp (argv[i], "-fhelp") == 0)
3262 /* Create a dummy input file, so that we can pass --help on to
3263 the various sub-processes. */
3264 infiles[n_infiles].language = "c";
3265 infiles[n_infiles++].name = "help-dummy";
3267 /* Preserve the --help switch so that it can be caught by the
3269 switches[n_switches].part1 = "--help";
3270 switches[n_switches].args = 0;
3271 switches[n_switches].live_cond = 0;
3272 switches[n_switches].validated = 0;
3277 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3279 /* Compensate for the +e options to the C++ front-end;
3280 they're there simply for cfront call-compatibility. We do
3281 some magic in default_compilers to pass them down properly.
3282 Note we deliberately start at the `+' here, to avoid passing
3283 -e0 or -e1 down into the linker. */
3284 switches[n_switches].part1 = &argv[i][0];
3285 switches[n_switches].args = 0;
3286 switches[n_switches].live_cond = 0;
3287 switches[n_switches].validated = 0;
3290 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3293 /* Split the argument at commas. */
3295 for (j = 4; argv[i][j]; j++)
3296 if (argv[i][j] == ',')
3298 infiles[n_infiles].language = "*";
3299 infiles[n_infiles++].name
3300 = save_string (argv[i] + prev, j - prev);
3303 /* Record the part after the last comma. */
3304 infiles[n_infiles].language = "*";
3305 infiles[n_infiles++].name = argv[i] + prev;
3307 else if (strcmp (argv[i], "-Xlinker") == 0)
3309 infiles[n_infiles].language = "*";
3310 infiles[n_infiles++].name = argv[++i];
3312 else if (strcmp (argv[i], "-l") == 0)
3313 { /* POSIX allows separation of -l and the lib arg;
3314 canonicalize by concatenating -l with its arg */
3315 infiles[n_infiles].language = "*";
3316 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
3318 else if (strncmp (argv[i], "-l", 2) == 0)
3320 infiles[n_infiles].language = "*";
3321 infiles[n_infiles++].name = argv[i];
3323 else if (strcmp (argv[i], "-specs") == 0)
3325 else if (strncmp (argv[i], "-specs=", 7) == 0)
3327 /* -save-temps overrides -pipe, so that temp files are produced */
3328 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
3329 error ("Warning: -pipe ignored since -save-temps specified");
3330 else if (argv[i][0] == '-' && argv[i][1] != 0)
3332 register char *p = &argv[i][1];
3333 register int c = *p;
3337 if (p[1] == 0 && i + 1 == argc)
3338 fatal ("argument to `-x' is missing");
3340 spec_lang = argv[++i];
3343 if (! strcmp (spec_lang, "none"))
3344 /* Suppress the warning if -xnone comes after the last input
3345 file, because alternate command interfaces like g++ might
3346 find it useful to place -xnone after each input file. */
3349 last_language_n_infiles = n_infiles;
3352 switches[n_switches].part1 = p;
3353 /* Deal with option arguments in separate argv elements. */
3354 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3355 || WORD_SWITCH_TAKES_ARG (p))
3358 int n_args = WORD_SWITCH_TAKES_ARG (p);
3362 /* Count only the option arguments in separate argv elements. */
3363 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3365 if (i + n_args >= argc)
3366 fatal ("argument to `-%s' is missing", p);
3367 switches[n_switches].args
3368 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3370 switches[n_switches].args[j++] = argv[++i];
3371 /* Null-terminate the vector. */
3372 switches[n_switches].args[j] = 0;
3374 else if (index (switches_need_spaces, c))
3376 /* On some systems, ld cannot handle some options without
3377 a space. So split the option from its argument. */
3378 char *part1 = (char *) xmalloc (2);
3382 switches[n_switches].part1 = part1;
3383 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3384 switches[n_switches].args[0] = xmalloc (strlen (p));
3385 strcpy (switches[n_switches].args[0], &p[1]);
3386 switches[n_switches].args[1] = 0;
3389 switches[n_switches].args = 0;
3391 switches[n_switches].live_cond = 0;
3392 switches[n_switches].validated = 0;
3393 /* This is always valid, since gcc.c itself understands it. */
3394 if (!strcmp (p, "save-temps"))
3395 switches[n_switches].validated = 1;
3398 char ch = switches[n_switches].part1[0];
3399 if (ch == 'V' || ch == 'b' || ch == 'B')
3400 switches[n_switches].validated = 1;
3406 #ifdef HAVE_OBJECT_SUFFIX
3407 argv[i] = convert_filename (argv[i], 0);
3410 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3412 perror_with_name (argv[i]);
3417 infiles[n_infiles].language = spec_lang;
3418 infiles[n_infiles++].name = argv[i];
3423 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3424 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3426 switches[n_switches].part1 = 0;
3427 infiles[n_infiles].name = 0;
3430 /* Process a spec string, accumulating and running commands. */
3432 /* These variables describe the input file name.
3433 input_file_number is the index on outfiles of this file,
3434 so that the output file name can be stored for later use by %o.
3435 input_basename is the start of the part of the input file
3436 sans all directory names, and basename_length is the number
3437 of characters starting there excluding the suffix .c or whatever. */
3439 const char *input_filename;
3440 static int input_file_number;
3441 size_t input_filename_length;
3442 static int basename_length;
3443 static const char *input_basename;
3444 static const char *input_suffix;
3446 /* These are variables used within do_spec and do_spec_1. */
3448 /* Nonzero if an arg has been started and not yet terminated
3449 (with space, tab or newline). */
3450 static int arg_going;
3452 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3453 is a temporary file name. */
3454 static int delete_this_arg;
3456 /* Nonzero means %w has been seen; the next arg to be terminated
3457 is the output file name of this compilation. */
3458 static int this_is_output_file;
3460 /* Nonzero means %s has been seen; the next arg to be terminated
3461 is the name of a library file and we should try the standard
3462 search dirs for it. */
3463 static int this_is_library_file;
3465 /* Nonzero means that the input of this command is coming from a pipe. */
3466 static int input_from_pipe;
3468 /* Process the spec SPEC and run the commands specified therein.
3469 Returns 0 if the spec is successfully processed; -1 if failed. */
3479 delete_this_arg = 0;
3480 this_is_output_file = 0;
3481 this_is_library_file = 0;
3482 input_from_pipe = 0;
3484 value = do_spec_1 (spec, 0, NULL_PTR);
3486 /* Force out any unfinished command.
3487 If -pipe, this forces out the last command if it ended in `|'. */
3490 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3493 if (argbuf_index > 0)
3500 /* Process the sub-spec SPEC as a portion of a larger spec.
3501 This is like processing a whole spec except that we do
3502 not initialize at the beginning and we do not supply a
3503 newline by default at the end.
3504 INSWITCH nonzero means don't process %-sequences in SPEC;
3505 in this case, % is treated as an ordinary character.
3506 This is used while substituting switches.
3507 INSWITCH nonzero also causes SPC not to terminate an argument.
3509 Value is zero unless a line was finished
3510 and the command on that line reported an error. */
3513 do_spec_1 (spec, inswitch, soft_matched_part)
3516 const char *soft_matched_part;
3518 register const char *p = spec;
3525 /* If substituting a switch, treat all chars like letters.
3526 Otherwise, NL, SPC, TAB and % are special. */
3527 switch (inswitch ? 'a' : c)
3530 /* End of line: finish any pending argument,
3531 then run the pending command if one has been started. */
3534 obstack_1grow (&obstack, 0);
3535 string = obstack_finish (&obstack);
3536 if (this_is_library_file)
3537 string = find_file (string);
3538 store_arg (string, delete_this_arg, this_is_output_file);
3539 if (this_is_output_file)
3540 outfiles[input_file_number] = string;
3544 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3546 for (i = 0; i < n_switches; i++)
3547 if (!strcmp (switches[i].part1, "pipe"))
3550 /* A `|' before the newline means use a pipe here,
3551 but only if -pipe was specified.
3552 Otherwise, execute now and don't pass the `|' as an arg. */
3555 input_from_pipe = 1;
3556 switches[i].validated = 1;
3563 if (argbuf_index > 0)
3569 /* Reinitialize for a new command, and for a new argument. */
3572 delete_this_arg = 0;
3573 this_is_output_file = 0;
3574 this_is_library_file = 0;
3575 input_from_pipe = 0;
3579 /* End any pending argument. */
3582 obstack_1grow (&obstack, 0);
3583 string = obstack_finish (&obstack);
3584 if (this_is_library_file)
3585 string = find_file (string);
3586 store_arg (string, delete_this_arg, this_is_output_file);
3587 if (this_is_output_file)
3588 outfiles[input_file_number] = string;
3592 obstack_1grow (&obstack, c);
3598 /* Space or tab ends an argument if one is pending. */
3601 obstack_1grow (&obstack, 0);
3602 string = obstack_finish (&obstack);
3603 if (this_is_library_file)
3604 string = find_file (string);
3605 store_arg (string, delete_this_arg, this_is_output_file);
3606 if (this_is_output_file)
3607 outfiles[input_file_number] = string;
3609 /* Reinitialize for a new argument. */
3611 delete_this_arg = 0;
3612 this_is_output_file = 0;
3613 this_is_library_file = 0;
3620 fatal ("Invalid specification! Bug in cc.");
3623 obstack_grow (&obstack, input_basename, basename_length);
3628 delete_this_arg = 2;
3631 /* Dump out the directories specified with LIBRARY_PATH,
3632 followed by the absolute directories
3633 that we search for startfiles. */
3636 struct prefix_list *pl = startfile_prefixes.plist;
3637 size_t bufsize = 100;
3638 char *buffer = (char *) xmalloc (bufsize);
3641 for (; pl; pl = pl->next)
3643 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3644 /* Used on systems which record the specified -L dirs
3645 and use them to search for dynamic linking. */
3646 /* Relative directories always come from -B,
3647 and it is better not to use them for searching
3648 at run time. In particular, stage1 loses */
3649 if (!IS_DIR_SEPARATOR (pl->prefix[0]))
3652 /* Try subdirectory if there is one. */
3653 if (multilib_dir != NULL)
3657 if (strlen (pl->prefix) + strlen (machine_suffix)
3659 bufsize = (strlen (pl->prefix)
3660 + strlen (machine_suffix)) * 2 + 1;
3661 buffer = (char *) xrealloc (buffer, bufsize);
3662 strcpy (buffer, pl->prefix);
3663 strcat (buffer, machine_suffix);
3664 if (is_directory (buffer, multilib_dir, 1))
3666 do_spec_1 ("-L", 0, NULL_PTR);
3667 #ifdef SPACE_AFTER_L_OPTION
3668 do_spec_1 (" ", 0, NULL_PTR);
3670 do_spec_1 (buffer, 1, NULL_PTR);
3671 do_spec_1 (multilib_dir, 1, NULL_PTR);
3672 /* Make this a separate argument. */
3673 do_spec_1 (" ", 0, NULL_PTR);
3676 if (!pl->require_machine_suffix)
3678 if (is_directory (pl->prefix, multilib_dir, 1))
3680 do_spec_1 ("-L", 0, NULL_PTR);
3681 #ifdef SPACE_AFTER_L_OPTION
3682 do_spec_1 (" ", 0, NULL_PTR);
3684 do_spec_1 (pl->prefix, 1, NULL_PTR);
3685 do_spec_1 (multilib_dir, 1, NULL_PTR);
3686 /* Make this a separate argument. */
3687 do_spec_1 (" ", 0, NULL_PTR);
3693 if (is_directory (pl->prefix, machine_suffix, 1))
3695 do_spec_1 ("-L", 0, NULL_PTR);
3696 #ifdef SPACE_AFTER_L_OPTION
3697 do_spec_1 (" ", 0, NULL_PTR);
3699 do_spec_1 (pl->prefix, 1, NULL_PTR);
3700 /* Remove slash from machine_suffix. */
3701 if (strlen (machine_suffix) >= bufsize)
3702 bufsize = strlen (machine_suffix) * 2 + 1;
3703 buffer = (char *) xrealloc (buffer, bufsize);
3704 strcpy (buffer, machine_suffix);
3705 idx = strlen (buffer);
3706 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3707 buffer[idx - 1] = 0;
3708 do_spec_1 (buffer, 1, NULL_PTR);
3709 /* Make this a separate argument. */
3710 do_spec_1 (" ", 0, NULL_PTR);
3713 if (!pl->require_machine_suffix)
3715 if (is_directory (pl->prefix, "", 1))
3717 do_spec_1 ("-L", 0, NULL_PTR);
3718 #ifdef SPACE_AFTER_L_OPTION
3719 do_spec_1 (" ", 0, NULL_PTR);
3721 /* Remove slash from pl->prefix. */
3722 if (strlen (pl->prefix) >= bufsize)
3723 bufsize = strlen (pl->prefix) * 2 + 1;
3724 buffer = (char *) xrealloc (buffer, bufsize);
3725 strcpy (buffer, pl->prefix);
3726 idx = strlen (buffer);
3727 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3728 buffer[idx - 1] = 0;
3729 do_spec_1 (buffer, 1, NULL_PTR);
3730 /* Make this a separate argument. */
3731 do_spec_1 (" ", 0, NULL_PTR);
3740 /* %efoo means report an error with `foo' as error message
3741 and don't execute any more commands for this file. */
3745 while (*p != 0 && *p != '\n') p++;
3746 buf = (char *) alloca (p - q + 1);
3747 strncpy (buf, q, p - q);
3757 if (save_temps_flag)
3759 obstack_grow (&obstack, input_basename, basename_length);
3760 delete_this_arg = 0;
3764 #ifdef MKTEMP_EACH_FILE
3765 /* ??? This has a problem: the total number of
3766 values mktemp can return is limited.
3767 That matters for the names of object files.
3768 In 2.4, do something about that. */
3769 struct temp_name *t;
3771 const char *suffix = p;
3773 if (p[0] == '%' && p[1] == 'O')
3776 /* We don't support extra suffix characters after %O. */
3777 if (*p == '.' || ISALPHA ((unsigned char)*p))
3779 suffix = OBJECT_SUFFIX;
3780 suffix_length = strlen (OBJECT_SUFFIX);
3784 while (*p == '.' || ISALPHA ((unsigned char)*p))
3786 suffix_length = p - suffix;
3789 /* See if we already have an association of %g/%u/%U and
3791 for (t = temp_names; t; t = t->next)
3792 if (t->length == suffix_length
3793 && strncmp (t->suffix, suffix, suffix_length) == 0
3794 && t->unique == (c != 'g'))
3797 /* Make a new association if needed. %u requires one. */
3798 if (t == 0 || c == 'u')
3802 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3803 t->next = temp_names;
3806 t->length = suffix_length;
3807 t->suffix = save_string (suffix, suffix_length);
3808 t->unique = (c != 'g');
3809 temp_filename = make_temp_file (t->suffix);
3810 temp_filename_length = strlen (temp_filename);
3811 t->filename = temp_filename;
3812 t->filename_length = temp_filename_length;
3815 obstack_grow (&obstack, t->filename, t->filename_length);
3816 delete_this_arg = 1;
3818 obstack_grow (&obstack, temp_filename, temp_filename_length);
3819 if (c == 'u' || c == 'U')
3825 sprintf (buff, "%d", unique);
3826 obstack_grow (&obstack, buff, strlen (buff));
3829 delete_this_arg = 1;
3835 obstack_grow (&obstack, input_filename, input_filename_length);
3841 struct prefix_list *pl = include_prefixes.plist;
3843 if (gcc_exec_prefix)
3845 do_spec_1 ("-iprefix", 1, NULL_PTR);
3846 /* Make this a separate argument. */
3847 do_spec_1 (" ", 0, NULL_PTR);
3848 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3849 do_spec_1 (" ", 0, NULL_PTR);
3852 for (; pl; pl = pl->next)
3854 do_spec_1 ("-isystem", 1, NULL_PTR);
3855 /* Make this a separate argument. */
3856 do_spec_1 (" ", 0, NULL_PTR);
3857 do_spec_1 (pl->prefix, 1, NULL_PTR);
3858 do_spec_1 (" ", 0, NULL_PTR);
3865 int max = n_infiles;
3866 max += lang_specific_extra_outfiles;
3868 for (i = 0; i < max; i++)
3870 store_arg (outfiles[i], 0, 0);
3875 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3880 this_is_library_file = 1;
3884 this_is_output_file = 1;
3889 int cur_index = argbuf_index;
3890 /* Handle the {...} following the %W. */
3893 p = handle_braces (p + 1);
3896 /* If any args were output, mark the last one for deletion
3898 if (argbuf_index != cur_index)
3899 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3903 /* %x{OPTION} records OPTION for %X to output. */
3909 /* Skip past the option value and make a copy. */
3914 string = save_string (p1 + 1, p - p1 - 2);
3916 /* See if we already recorded this option. */
3917 for (i = 0; i < n_linker_options; i++)
3918 if (! strcmp (string, linker_options[i]))
3924 /* This option is new; add it. */
3925 add_linker_option (string, strlen (string));
3929 /* Dump out the options accumulated previously using %x. */
3931 for (i = 0; i < n_linker_options; i++)
3933 do_spec_1 (linker_options[i], 1, NULL_PTR);
3934 /* Make each accumulated option a separate argument. */
3935 do_spec_1 (" ", 0, NULL_PTR);
3939 /* Dump out the options accumulated previously using -Wa,. */
3941 for (i = 0; i < n_assembler_options; i++)
3943 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3944 /* Make each accumulated option a separate argument. */
3945 do_spec_1 (" ", 0, NULL_PTR);
3949 /* Dump out the options accumulated previously using -Wp,. */
3951 for (i = 0; i < n_preprocessor_options; i++)
3953 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3954 /* Make each accumulated option a separate argument. */
3955 do_spec_1 (" ", 0, NULL_PTR);
3959 /* Here are digits and numbers that just process
3960 a certain constant string as a spec. */
3963 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3969 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3975 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3981 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3987 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3993 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3999 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
4005 value = do_spec_1 (link_spec, 0, NULL_PTR);
4011 value = do_spec_1 (lib_spec, 0, NULL_PTR);
4017 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
4024 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
4028 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4032 if (! strncmp (y, "-D", 2))
4033 /* Copy the whole option. */
4034 while (*y && *y != ' ' && *y != '\t')
4036 else if (*y == ' ' || *y == '\t')
4037 /* Copy whitespace to the result. */
4039 /* Don't copy other options. */
4046 value = do_spec_1 (buf, 0, NULL_PTR);
4054 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
4058 /* Copy all of CPP_PREDEFINES into BUF,
4059 but put __ after every -D and at the end of each arg. */
4063 if (! strncmp (y, "-D", 2))
4072 && ! ISUPPER ((unsigned char)*(y+1))))
4074 /* Stick __ at front of macro name. */
4077 /* Arrange to stick __ at the end as well. */
4081 /* Copy the macro name. */
4082 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4091 /* Copy the value given, if any. */
4092 while (*y && *y != ' ' && *y != '\t')
4095 else if (*y == ' ' || *y == '\t')
4096 /* Copy whitespace to the result. */
4098 /* Don't copy -A options */
4104 /* Copy all of CPP_PREDEFINES into BUF,
4105 but put __ after every -D. */
4109 if (! strncmp (y, "-D", 2))
4115 && ! ISUPPER ((unsigned char)*(y+1))))
4117 /* Stick -D__ at front of macro name. */
4123 /* Copy the macro name. */
4124 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4127 /* Copy the value given, if any. */
4128 while (*y && *y != ' ' && *y != '\t')
4133 /* Do not copy this macro - we have just done it before */
4134 while (*y && *y != ' ' && *y != '\t')
4138 else if (*y == ' ' || *y == '\t')
4139 /* Copy whitespace to the result. */
4141 /* Don't copy -A options */
4147 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4151 if (! strncmp (y, "-A", 2))
4152 /* Copy the whole option. */
4153 while (*y && *y != ' ' && *y != '\t')
4155 else if (*y == ' ' || *y == '\t')
4156 /* Copy whitespace to the result. */
4158 /* Don't copy other options. */
4165 value = do_spec_1 (buf, 0, NULL_PTR);
4172 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
4177 /* Here we define characters other than letters and digits. */
4180 p = handle_braces (p);
4186 obstack_1grow (&obstack, '%');
4190 do_spec_1 (soft_matched_part, 1, NULL_PTR);
4191 do_spec_1 (" ", 0, NULL_PTR);
4194 /* Process a string found as the value of a spec given by name.
4195 This feature allows individual machine descriptions
4196 to add and use their own specs.
4197 %[...] modifies -D options the way %P does;
4198 %(...) uses the spec unmodified. */
4200 error ("Warning: use of obsolete %%[ operator in specs");
4203 const char *name = p;
4204 struct spec_list *sl;
4207 /* The string after the S/P is the name of a spec that is to be
4209 while (*p && *p != ')' && *p != ']')
4212 /* See if it's in the list */
4213 for (len = p - name, sl = specs; sl; sl = sl->next)
4214 if (sl->name_len == len && !strncmp (sl->name, name, len))
4216 name = *(sl->ptr_spec);
4218 notice ("Processing spec %c%s%c, which is '%s'\n",
4219 c, sl->name, (c == '(') ? ')' : ']', name);
4228 value = do_spec_1 (name, 0, NULL_PTR);
4234 char *x = (char *) alloca (strlen (name) * 2 + 1);
4236 const char *y = name;
4239 /* Copy all of NAME into BUF, but put __ after
4240 every -D and at the end of each arg, */
4243 if (! strncmp (y, "-D", 2))
4253 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
4254 || *y == '}' || *y == 0))
4267 value = do_spec_1 (buf, 0, NULL_PTR);
4273 /* Discard the closing paren or bracket. */
4281 int c1 = *p++; /* Select first or second version number. */
4282 char *v = compiler_version;
4285 /* The format of the version string is
4286 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4288 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4289 while (! ISDIGIT (*v))
4291 if (v > compiler_version && v[-1] != '-')
4294 /* If desired, advance to second version number. */
4297 /* Set V after the first period. */
4298 while (ISDIGIT (*v))
4305 /* Set Q at the next period or at the end. */
4307 while (ISDIGIT (*q))
4309 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
4312 /* Put that part into the command. */
4313 obstack_grow (&obstack, v, q - v);
4319 if (input_from_pipe)
4320 do_spec_1 ("-", 0, NULL_PTR);
4329 /* Backslash: treat next character as ordinary. */
4334 /* Ordinary character: put it into the current argument. */
4335 obstack_1grow (&obstack, c);
4339 return 0; /* End of string */
4342 /* Return 0 if we call do_spec_1 and that returns -1. */
4346 register const char *p;
4348 const char *filter, *body = NULL, *endbody = NULL;
4352 int include_blanks = 1;
4355 /* A '^' after the open-brace means to not give blanks before args. */
4356 include_blanks = 0, ++p;
4359 /* A `|' after the open-brace means,
4360 if the test fails, output a single minus sign rather than nothing.
4361 This is used in %{|!pipe:...}. */
4365 negate = suffix = 0;
4368 /* A `!' after the open-brace negates the condition:
4369 succeed if the specified switch is not present. */
4373 /* A `.' after the open-brace means test against the current suffix. */
4383 while (*p != ':' && *p != '}' && *p != '|') p++;
4385 if (*p == '|' && pipe_p)
4392 register int count = 1;
4393 register const char *q = p;
4395 while (*q++ != ':') continue;
4411 body = p, endbody = p+1;
4416 int found = (input_suffix != 0
4417 && (long) strlen (input_suffix) == (long)(p - filter)
4418 && strncmp (input_suffix, filter, p - filter) == 0);
4424 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL_PTR) < 0)
4427 else if (p[-1] == '*' && p[0] == '}')
4429 /* Substitute all matching switches as separate args. */
4432 for (i = 0; i < n_switches; i++)
4433 if (!strncmp (switches[i].part1, filter, p - filter)
4434 && check_live_switch (i, p - filter))
4435 give_switch (i, 0, include_blanks);
4439 /* Test for presence of the specified switch. */
4443 /* If name specified ends in *, as in {x*:...},
4444 check for %* and handle that case. */
4445 if (p[-1] == '*' && !negate)
4448 const char *r = body;
4450 /* First see whether we have %*. */
4454 if (*r == '%' && r[1] == '*')
4458 /* If we do, handle that case. */
4461 /* Substitute all matching switches as separate args.
4462 But do this by substituting for %*
4463 in the text that follows the colon. */
4465 unsigned hard_match_len = p - filter - 1;
4466 char *string = save_string (body, endbody - body - 1);
4468 for (i = 0; i < n_switches; i++)
4469 if (!strncmp (switches[i].part1, filter, hard_match_len)
4470 && check_live_switch (i, -1))
4472 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4473 /* Pass any arguments this switch has. */
4474 give_switch (i, 1, 1);
4477 /* We didn't match. Try again. */
4484 /* If name specified ends in *, as in {x*:...},
4485 check for presence of any switch name starting with x. */
4488 for (i = 0; i < n_switches; i++)
4490 unsigned hard_match_len = p - filter - 1;
4492 if (!strncmp (switches[i].part1, filter, hard_match_len)
4493 && check_live_switch (i, hard_match_len))
4499 /* Otherwise, check for presence of exact name specified. */
4502 for (i = 0; i < n_switches; i++)
4504 if (!strncmp (switches[i].part1, filter, p - filter)
4505 && switches[i].part1[p - filter] == 0
4506 && check_live_switch (i, -1))
4514 /* If it is as desired (present for %{s...}, absent for %{!s...})
4515 then substitute either the switch or the specified
4516 conditional text. */
4517 if (present != negate)
4521 give_switch (i, 0, include_blanks);
4525 if (do_spec_1 (save_string (body, endbody - body - 1),
4532 /* Here if a %{|...} conditional fails: output a minus sign,
4533 which means "standard output" or "standard input". */
4534 do_spec_1 ("-", 0, NULL_PTR);
4539 /* We didn't match; try again. */
4546 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4547 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4548 spec, or -1 if either exact match or %* is used.
4550 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4551 whose value does not begin with "no-" is obsoleted by the same value
4552 with the "no-", similarly for a switch with the "no-" prefix. */
4555 check_live_switch (switchnum, prefix_length)
4559 const char *name = switches[switchnum].part1;
4562 /* In the common case of {<at-most-one-letter>*}, a negating
4563 switch would always match, so ignore that case. We will just
4564 send the conflicting switches to the compiler phase. */
4565 if (prefix_length >= 0 && prefix_length <= 1)
4568 /* If we already processed this switch and determined if it was
4569 live or not, return our past determination. */
4570 if (switches[switchnum].live_cond != 0)
4571 return switches[switchnum].live_cond > 0;
4573 /* Now search for duplicate in a manner that depends on the name. */
4577 for (i = switchnum + 1; i < n_switches; i++)
4578 if (switches[i].part1[0] == 'O')
4580 switches[switchnum].validated = 1;
4581 switches[switchnum].live_cond = -1;
4586 case 'W': case 'f': case 'm':
4587 if (! strncmp (name + 1, "no-", 3))
4589 /* We have Xno-YYY, search for XYYY. */
4590 for (i = switchnum + 1; i < n_switches; i++)
4591 if (switches[i].part1[0] == name[0]
4592 && ! strcmp (&switches[i].part1[1], &name[4]))
4594 switches[switchnum].validated = 1;
4595 switches[switchnum].live_cond = -1;
4601 /* We have XYYY, search for Xno-YYY. */
4602 for (i = switchnum + 1; i < n_switches; i++)
4603 if (switches[i].part1[0] == name[0]
4604 && switches[i].part1[1] == 'n'
4605 && switches[i].part1[2] == 'o'
4606 && switches[i].part1[3] == '-'
4607 && !strcmp (&switches[i].part1[4], &name[1]))
4609 switches[switchnum].validated = 1;
4610 switches[switchnum].live_cond = -1;
4617 /* Otherwise the switch is live. */
4618 switches[switchnum].live_cond = 1;
4622 /* Pass a switch to the current accumulating command
4623 in the same form that we received it.
4624 SWITCHNUM identifies the switch; it is an index into
4625 the vector of switches gcc received, which is `switches'.
4626 This cannot fail since it never finishes a command line.
4628 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4630 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4634 give_switch (switchnum, omit_first_word, include_blanks)
4636 int omit_first_word;
4639 if (!omit_first_word)
4641 do_spec_1 ("-", 0, NULL_PTR);
4642 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4645 if (switches[switchnum].args != 0)
4648 for (p = switches[switchnum].args; *p; p++)
4651 do_spec_1 (" ", 0, NULL_PTR);
4652 do_spec_1 (*p, 1, NULL_PTR);
4656 do_spec_1 (" ", 0, NULL_PTR);
4657 switches[switchnum].validated = 1;
4660 /* Search for a file named NAME trying various prefixes including the
4661 user's -B prefix and some standard ones.
4662 Return the absolute file name found. If nothing is found, return NAME. */
4670 /* Try multilib_dir if it is defined. */
4671 if (multilib_dir != NULL)
4675 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4676 strcpy (try, multilib_dir);
4677 strcat (try, dir_separator_str);
4680 newname = find_a_file (&startfile_prefixes, try, R_OK);
4682 /* If we don't find it in the multi library dir, then fall
4683 through and look for it in the normal places. */
4684 if (newname != NULL)
4688 newname = find_a_file (&startfile_prefixes, name, R_OK);
4689 return newname ? newname : name;
4692 /* Determine whether a directory exists. If LINKER, return 0 for
4693 certain fixed names not needed by the linker. If not LINKER, it is
4694 only important to return 0 if the host machine has a small ARG_MAX
4698 is_directory (path1, path2, linker)
4703 int len1 = strlen (path1);
4704 int len2 = strlen (path2);
4705 char *path = (char *) alloca (3 + len1 + len2);
4709 #ifndef SMALL_ARG_MAX
4714 /* Construct the path from the two parts. Ensure the string ends with "/.".
4715 The resulting path will be a directory even if the given path is a
4717 memcpy (path, path1, len1);
4718 memcpy (path + len1, path2, len2);
4719 cp = path + len1 + len2;
4720 if (!IS_DIR_SEPARATOR (cp[-1]))
4721 *cp++ = DIR_SEPARATOR;
4725 #ifndef FREEBSD_NATIVE
4726 /* Exclude directories that the linker is known to search. */
4729 && strcmp (path, concat (dir_separator_str, "lib",
4730 dir_separator_str, ".", NULL_PTR)) == 0)
4732 && strcmp (path, concat (dir_separator_str, "usr",
4733 dir_separator_str, "lib",
4734 dir_separator_str, ".", NULL_PTR)) == 0)))
4736 #endif /* not FREEBSD_NATIVE */
4738 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4741 /* On fatal signals, delete all the temporary files. */
4744 fatal_error (signum)
4747 signal (signum, SIG_DFL);
4748 delete_failure_queue ();
4749 delete_temp_files ();
4750 /* Get the same signal again, this time not handled,
4751 so its normal effect occurs. */
4752 kill (getpid (), signum);
4763 int linker_was_run = 0;
4764 char *explicit_link_files;
4767 struct user_specs *uptr;
4769 p = argv[0] + strlen (argv[0]);
4770 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
4774 #ifdef HAVE_LC_MESSAGES
4775 setlocale (LC_MESSAGES, "");
4777 (void) bindtextdomain (PACKAGE, localedir);
4778 (void) textdomain (PACKAGE);
4780 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4781 signal (SIGINT, fatal_error);
4783 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4784 signal (SIGHUP, fatal_error);
4786 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4787 signal (SIGTERM, fatal_error);
4789 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4790 signal (SIGPIPE, fatal_error);
4794 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4796 obstack_init (&obstack);
4798 /* Build multilib_select, et. al from the separate lines that make up each
4799 multilib selection. */
4801 char **q = multilib_raw;
4804 obstack_init (&multilib_obstack);
4805 while ((p = *q++) != (char *) 0)
4806 obstack_grow (&multilib_obstack, p, strlen (p));
4808 obstack_1grow (&multilib_obstack, 0);
4809 multilib_select = obstack_finish (&multilib_obstack);
4811 q = multilib_matches_raw;
4812 while ((p = *q++) != (char *) 0)
4813 obstack_grow (&multilib_obstack, p, strlen (p));
4815 obstack_1grow (&multilib_obstack, 0);
4816 multilib_matches = obstack_finish (&multilib_obstack);
4820 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4824 obstack_1grow (&multilib_obstack, ' ');
4825 obstack_grow (&multilib_obstack,
4826 multilib_defaults_raw[i],
4827 strlen (multilib_defaults_raw[i]));
4831 obstack_1grow (&multilib_obstack, 0);
4832 multilib_defaults = obstack_finish (&multilib_obstack);
4835 /* Set up to remember the pathname of gcc and any options
4836 needed for collect. We use argv[0] instead of programname because
4837 we need the complete pathname. */
4838 obstack_init (&collect_obstack);
4839 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4840 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4841 putenv (obstack_finish (&collect_obstack));
4843 #ifdef INIT_ENVIRONMENT
4844 /* Set up any other necessary machine specific environment variables. */
4845 putenv (INIT_ENVIRONMENT);
4848 /* Choose directory for temp files. */
4850 #ifndef MKTEMP_EACH_FILE
4851 temp_filename = choose_temp_base ();
4852 temp_filename_length = strlen (temp_filename);
4855 /* Make a table of what switches there are (switches, n_switches).
4856 Make a table of specified input files (infiles, n_infiles).
4857 Decode switches that are handled locally. */
4859 process_command (argc, argv);
4864 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4866 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4867 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4870 for (i = 0; (int)i < n_switches; i++)
4875 obstack_grow (&collect_obstack, " ", 1);
4878 obstack_grow (&collect_obstack, "'-", 2);
4879 q = switches[i].part1;
4880 while ((p = index (q,'\'')))
4882 obstack_grow (&collect_obstack, q, p-q);
4883 obstack_grow (&collect_obstack, "'\\''", 4);
4886 obstack_grow (&collect_obstack, q, strlen (q));
4887 obstack_grow (&collect_obstack, "'", 1);
4889 for (args = switches[i].args; args && *args; args++)
4891 obstack_grow (&collect_obstack, " '", 2);
4893 while ((p = index (q,'\'')))
4895 obstack_grow (&collect_obstack, q, p-q);
4896 obstack_grow (&collect_obstack, "'\\''", 4);
4899 obstack_grow (&collect_obstack, q, strlen (q));
4900 obstack_grow (&collect_obstack, "'", 1);
4903 obstack_grow (&collect_obstack, "\0", 1);
4904 putenv (obstack_finish (&collect_obstack));
4907 /* Initialize the vector of specs to just the default.
4908 This means one element containing 0s, as a terminator. */
4910 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4911 bcopy ((char *) default_compilers, (char *) compilers,
4912 sizeof default_compilers);
4913 n_compilers = n_default_compilers;
4915 /* Read specs from a file if there is one. */
4917 #ifdef FREEBSD_NATIVE
4918 just_machine_suffix = ""; /* I don't support specs, gives determinism */
4919 #else /* FREEBSD_NATIVE */
4920 machine_suffix = concat (spec_machine, dir_separator_str,
4921 spec_version, dir_separator_str, NULL_PTR);
4922 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4923 #endif /* FREEBSD_NATIVE */
4925 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4926 /* Read the specs file unless it is a default one. */
4927 if (specs_file != 0 && strcmp (specs_file, "specs"))
4928 read_specs (specs_file, TRUE);
4932 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4933 for any override of as, ld and libraries. */
4934 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4935 + strlen (just_machine_suffix)
4936 + sizeof ("specs"));
4938 strcpy (specs_file, standard_exec_prefix);
4939 strcat (specs_file, just_machine_suffix);
4940 strcat (specs_file, "specs");
4941 if (access (specs_file, R_OK) == 0)
4942 read_specs (specs_file, TRUE);
4944 /* If not cross-compiling, look for startfiles in the standard places. */
4945 if (*cross_compile == '0')
4947 #ifdef MD_EXEC_PREFIX
4948 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4949 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4952 #ifdef MD_STARTFILE_PREFIX
4953 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4957 #ifdef MD_STARTFILE_PREFIX_1
4958 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4962 /* If standard_startfile_prefix is relative, base it on
4963 standard_exec_prefix. This lets us move the installed tree
4964 as a unit. If GCC_EXEC_PREFIX is defined, base
4965 standard_startfile_prefix on that as well. */
4966 if (IS_DIR_SEPARATOR (*standard_startfile_prefix)
4967 || *standard_startfile_prefix == '$'
4968 #ifdef HAVE_DOS_BASED_FILESYSTEM
4969 /* Check for disk name on MS-DOS-based systems. */
4970 || (standard_startfile_prefix[1] == ':'
4971 && (IS_DIR_SEPARATOR (standard_startfile_prefix[2])))
4974 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4978 if (gcc_exec_prefix)
4979 add_prefix (&startfile_prefixes,
4980 concat (gcc_exec_prefix, machine_suffix,
4981 standard_startfile_prefix, NULL_PTR),
4982 NULL_PTR, 0, 0, NULL_PTR);
4983 add_prefix (&startfile_prefixes,
4984 concat (standard_exec_prefix,
4986 standard_startfile_prefix, NULL_PTR),
4987 NULL_PTR, 0, 0, NULL_PTR);
4990 #ifndef FREEBSD_NATIVE
4991 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4992 "BINUTILS", 0, 0, NULL_PTR);
4993 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4994 "BINUTILS", 0, 0, NULL_PTR);
4995 #endif /* FREEBSD_NATIVE */
4996 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4997 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
5002 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix) && gcc_exec_prefix)
5003 add_prefix (&startfile_prefixes,
5004 concat (gcc_exec_prefix, machine_suffix,
5005 standard_startfile_prefix, NULL_PTR),
5006 "BINUTILS", 0, 0, NULL_PTR);
5007 #ifdef CROSS_STARTFILE_PREFIX
5008 add_prefix (&startfile_prefixes, CROSS_STARTFILE_PREFIX, "BINUTILS",
5013 /* Process any user specified specs in the order given on the command
5015 for (uptr = user_specs_head; uptr; uptr = uptr->next)
5017 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
5018 read_specs (filename ? filename : uptr->filename, FALSE);
5021 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
5022 if (gcc_exec_prefix)
5024 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
5025 + strlen (spec_version)
5026 + strlen (spec_machine) + 3);
5027 strcpy (temp, gcc_exec_prefix);
5028 strcat (temp, spec_machine);
5029 strcat (temp, dir_separator_str);
5030 strcat (temp, spec_version);
5031 strcat (temp, dir_separator_str);
5032 gcc_exec_prefix = temp;
5035 /* Now we have the specs.
5036 Set the `valid' bits for switches that match anything in any spec. */
5038 validate_all_switches ();
5040 /* Now that we have the switches and the specs, set
5041 the subdirectory based on the options. */
5042 set_multilib_dir ();
5044 /* Warn about any switches that no pass was interested in. */
5046 for (i = 0; (int)i < n_switches; i++)
5047 if (! switches[i].validated)
5048 error ("unrecognized option `-%s'", switches[i].part1);
5050 /* Obey some of the options. */
5052 if (print_search_dirs)
5054 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
5055 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
5056 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
5060 if (print_file_name)
5062 printf ("%s\n", find_file (print_file_name));
5066 if (print_prog_name)
5068 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
5069 printf ("%s\n", (newname ? newname : print_prog_name));
5073 if (print_multi_lib)
5075 print_multilib_info ();
5079 if (print_multi_directory)
5081 if (multilib_dir == NULL)
5084 printf ("%s\n", multilib_dir);
5088 if (print_help_list)
5094 printf ("\nFor bug reporting instructions, please see:\n");
5095 printf ("%s.\n", GCCBUGURL);
5100 /* We do not exit here. Instead we have created a fake input file
5101 called 'help-dummy' which needs to be compiled, and we pass this
5102 on the the various sub-processes, along with the --help switch. */
5109 /* compiler_version is truncated at the first space when initialized
5110 from version string, so truncate version_string at the first space
5111 before comparing. */
5112 for (n = 0; version_string[n]; n++)
5113 if (version_string[n] == ' ')
5116 if (! strncmp (version_string, compiler_version, n)
5117 && compiler_version[n] == 0)
5118 notice ("gcc version %s\n", version_string);
5120 notice ("gcc driver version %s executing gcc version %s\n",
5121 version_string, compiler_version);
5127 if (n_infiles == added_libraries)
5128 fatal ("No input files specified");
5130 /* Make a place to record the compiler output file names
5131 that correspond to the input files. */
5134 i += lang_specific_extra_outfiles;
5135 outfiles = (const char **) xmalloc (i * sizeof (char *));
5136 bzero ((char *) outfiles, i * sizeof (char *));
5138 /* Record which files were specified explicitly as link input. */
5140 explicit_link_files = xmalloc (n_infiles);
5141 bzero (explicit_link_files, n_infiles);
5143 for (i = 0; (int)i < n_infiles; i++)
5145 register struct compiler *cp = 0;
5146 int this_file_error = 0;
5148 /* Tell do_spec what to substitute for %i. */
5150 input_filename = infiles[i].name;
5151 input_filename_length = strlen (input_filename);
5152 input_file_number = i;
5154 /* Use the same thing in %o, unless cp->spec says otherwise. */
5156 outfiles[i] = input_filename;
5158 /* Figure out which compiler from the file's suffix. */
5160 cp = lookup_compiler (infiles[i].name, input_filename_length,
5161 infiles[i].language);
5165 /* Ok, we found an applicable compiler. Run its spec. */
5166 /* First say how much of input_filename to substitute for %b */
5167 register const char *p;
5170 if (cp->spec[0][0] == '#')
5172 error ("%s: %s compiler not installed on this system",
5173 input_filename, &cp->spec[0][1]);
5174 this_file_error = 1;
5178 input_basename = input_filename;
5179 for (p = input_filename; *p; p++)
5180 if (IS_DIR_SEPARATOR (*p))
5181 input_basename = p + 1;
5183 /* Find a suffix starting with the last period,
5184 and set basename_length to exclude that suffix. */
5185 basename_length = strlen (input_basename);
5186 p = input_basename + basename_length;
5187 while (p != input_basename && *p != '.') --p;
5188 if (*p == '.' && p != input_basename)
5190 basename_length = p - input_basename;
5191 input_suffix = p + 1;
5197 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5199 len += strlen (cp->spec[j]);
5202 char *p1 = (char *) xmalloc (len + 1);
5205 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5208 strcpy (p1 + len, cp->spec[j]);
5209 len += strlen (cp->spec[j]);
5212 value = do_spec (p1);
5216 this_file_error = 1;
5220 /* If this file's name does not contain a recognized suffix,
5221 record it as explicit linker input. */
5224 explicit_link_files[i] = 1;
5226 /* Clear the delete-on-failure queue, deleting the files in it
5227 if this compilation failed. */
5229 if (this_file_error)
5231 delete_failure_queue ();
5234 /* If this compilation succeeded, don't delete those files later. */
5235 clear_failure_queue ();
5238 if (error_count == 0)
5240 /* Make sure INPUT_FILE_NUMBER points to first available open
5242 input_file_number = n_infiles;
5243 if (lang_specific_pre_link ())
5247 /* Run ld to link all the compiler output files. */
5249 if (error_count == 0)
5251 int tmp = execution_count;
5253 /* We'll use ld if we can't find collect2. */
5254 if (! strcmp (linker_name_spec, "collect2"))
5256 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
5258 linker_name_spec = "ld";
5260 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5262 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
5263 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
5265 value = do_spec (link_command_spec);
5268 linker_was_run = (tmp != execution_count);
5271 /* Warn if a -B option was specified but the prefix was never used. */
5272 unused_prefix_warnings (&exec_prefixes);
5273 unused_prefix_warnings (&startfile_prefixes);
5275 /* If options said don't run linker,
5276 complain about input files to be given to the linker. */
5278 if (! linker_was_run && error_count == 0)
5279 for (i = 0; (int)i < n_infiles; i++)
5280 if (explicit_link_files[i])
5281 error ("%s: linker input file unused since linking not done",
5284 /* Delete some or all of the temporary files we made. */
5287 delete_failure_queue ();
5288 delete_temp_files ();
5290 if (print_help_list)
5292 printf ("\nFor bug reporting instructions, please see:\n");
5293 printf ("%s\n", GCCBUGURL);
5296 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
5301 /* Find the proper compilation spec for the file name NAME,
5302 whose length is LENGTH. LANGUAGE is the specified language,
5303 or 0 if this file is to be passed to the linker. */
5305 static struct compiler *
5306 lookup_compiler (name, length, language)
5309 const char *language;
5311 struct compiler *cp;
5313 /* If this was specified by the user to be a linker input, indicate that. */
5314 if (language != 0 && language[0] == '*')
5317 /* Otherwise, look for the language, if one is spec'd. */
5320 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5321 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
5324 error ("language %s not recognized", language);
5328 /* Look for a suffix. */
5329 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5331 if (/* The suffix `-' matches only the file name `-'. */
5332 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
5333 || (strlen (cp->suffix) < length
5334 /* See if the suffix matches the end of NAME. */
5336 && ((!strcmp (cp->suffix,
5337 name + length - strlen (cp->suffix))
5338 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5339 && !strcasecmp (cp->suffix,
5340 name + length - strlen (cp->suffix)))
5342 && !strcmp (cp->suffix,
5343 name + length - strlen (cp->suffix))
5347 if (cp->spec[0][0] == '@')
5349 struct compiler *new;
5351 /* An alias entry maps a suffix to a language.
5352 Search for the language; pass 0 for NAME and LENGTH
5353 to avoid infinite recursion if language not found.
5354 Construct the new compiler spec. */
5355 language = cp->spec[0] + 1;
5356 new = (struct compiler *) xmalloc (sizeof (struct compiler));
5357 new->suffix = cp->suffix;
5358 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
5359 (char *) new->spec, sizeof new->spec);
5363 /* A non-alias entry: return it. */
5375 register PTR value = (PTR) malloc (size);
5377 fatal ("virtual memory exhausted");
5382 xrealloc (old, size)
5388 ptr = (PTR) realloc (old, size);
5390 ptr = (PTR) malloc (size);
5392 fatal ("virtual memory exhausted");
5397 save_string (s, len)
5401 register char *result = xmalloc (len + 1);
5403 bcopy (s, result, len);
5409 pfatal_with_name (name)
5412 perror_with_name (name);
5413 delete_temp_files ();
5418 perror_with_name (name)
5421 error ("%s: %s", name, xstrerror (errno));
5425 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5426 const char *errmsg_fmt;
5427 const char *errmsg_arg;
5431 int save_errno = errno;
5433 /* Space for trailing '\0' is in %s. */
5434 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5435 sprintf (msg, errmsg_fmt, errmsg_arg);
5441 pfatal_with_name (errmsg_fmt);
5444 /* More 'friendly' abort that prints the line and file.
5445 config.h can #define abort fancy_abort if you like that sort of thing. */
5450 fatal ("Internal gcc abort.");
5453 /* Output an error message and exit */
5456 fatal VPROTO((const char *msgid, ...))
5458 #ifndef ANSI_PROTOTYPES
5463 VA_START (ap, msgid);
5465 #ifndef ANSI_PROTOTYPES
5466 msgid = va_arg (ap, const char *);
5469 fprintf (stderr, "%s: ", programname);
5470 vfprintf (stderr, _(msgid), ap);
5472 fprintf (stderr, "\n");
5473 delete_temp_files ();
5478 error VPROTO((const char *msgid, ...))
5480 #ifndef ANSI_PROTOTYPES
5485 VA_START (ap, msgid);
5487 #ifndef ANSI_PROTOTYPES
5488 msgid = va_arg (ap, const char *);
5491 fprintf (stderr, "%s: ", programname);
5492 vfprintf (stderr, _(msgid), ap);
5495 fprintf (stderr, "\n");
5499 notice VPROTO((const char *msgid, ...))
5501 #ifndef ANSI_PROTOTYPES
5506 VA_START (ap, msgid);
5508 #ifndef ANSI_PROTOTYPES
5509 msgid = va_arg (ap, const char *);
5512 vfprintf (stderr, _(msgid), ap);
5518 validate_all_switches ()
5520 struct compiler *comp;
5521 register const char *p;
5523 struct spec_list *spec;
5525 for (comp = compilers; comp->spec[0]; comp++)
5528 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5532 if (c == '%' && *p == '{')
5533 /* We have a switch spec. */
5534 validate_switches (p + 1);
5538 /* look through the linked list of specs read from the specs file */
5539 for (spec = specs; spec ; spec = spec->next)
5541 p = *(spec->ptr_spec);
5543 if (c == '%' && *p == '{')
5544 /* We have a switch spec. */
5545 validate_switches (p + 1);
5548 p = link_command_spec;
5550 if (c == '%' && *p == '{')
5551 /* We have a switch spec. */
5552 validate_switches (p + 1);
5555 /* Look at the switch-name that comes after START
5556 and mark as valid all supplied switches that match it. */
5559 validate_switches (start)
5562 register const char *p = start;
5577 while (*p != ':' && *p != '}') p++;
5581 else if (p[-1] == '*')
5583 /* Mark all matching switches as valid. */
5585 for (i = 0; i < n_switches; i++)
5586 if (!strncmp (switches[i].part1, filter, p - filter))
5587 switches[i].validated = 1;
5591 /* Mark an exact matching switch as valid. */
5592 for (i = 0; i < n_switches; i++)
5594 if (!strncmp (switches[i].part1, filter, p - filter)
5595 && switches[i].part1[p - filter] == 0)
5596 switches[i].validated = 1;
5601 /* Check whether a particular argument was used. The first time we
5602 canonicalize the switches to keep only the ones we care about. */
5616 static struct mswitchstr *mswitches;
5617 static int n_mswitches;
5622 struct mswitchstr *matches;
5626 /* Break multilib_matches into the component strings of string and replacement
5628 for (q = multilib_matches; *q != '\0'; q++)
5632 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5634 q = multilib_matches;
5645 matches[i].len = q - matches[i].str;
5647 matches[i].replace = ++q;
5648 while (*q != ';' && *q != '\0')
5654 matches[i].rep_len = q - matches[i].replace;
5662 /* Now build a list of the replacement string for switches that we care
5663 about. Make sure we allocate at least one entry. This prevents
5664 xmalloc from calling fatal, and prevents us from re-executing this
5667 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5668 * (n_switches ? n_switches : 1));
5669 for (i = 0; i < n_switches; i++)
5671 int xlen = strlen (switches[i].part1);
5672 for (j = 0; j < cnt; j++)
5673 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5675 mswitches[n_mswitches].str = matches[j].replace;
5676 mswitches[n_mswitches].len = matches[j].rep_len;
5677 mswitches[n_mswitches].replace = (char *)0;
5678 mswitches[n_mswitches].rep_len = 0;
5685 for (i = 0; i < n_mswitches; i++)
5686 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5693 default_arg (p, len)
5699 for (start = multilib_defaults; *start != '\0'; start = end+1)
5701 while (*start == ' ' || *start == '\t')
5707 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5710 if ((end - start) == len && strncmp (p, start, len) == 0)
5720 /* Work out the subdirectory to use based on the
5721 options. The format of multilib_select is a list of elements.
5722 Each element is a subdirectory name followed by a list of options
5723 followed by a semicolon. gcc will consider each line in turn. If
5724 none of the options beginning with an exclamation point are
5725 present, and all of the other options are present, that
5726 subdirectory will be used. */
5731 char *p = multilib_select;
5733 char *this_path, *this_arg;
5739 /* Ignore newlines. */
5746 /* Get the initial path. */
5754 this_path_len = p - this_path;
5756 /* Check the arguments. */
5771 while (*p != ' ' && *p != ';')
5778 if (*this_arg != '!')
5786 /* If this is a default argument, we can just ignore it.
5787 This is true even if this_arg begins with '!'. Beginning
5788 with '!' does not mean that this argument is necessarily
5789 inappropriate for this library: it merely means that
5790 there is a more specific library which uses this
5791 argument. If this argument is a default, we need not
5792 consider that more specific library. */
5793 if (! default_arg (this_arg, p - this_arg))
5795 ok = used_arg (this_arg, p - this_arg);
5806 if (this_path_len != 1
5807 || this_path[0] != '.')
5809 char * new_multilib_dir = xmalloc (this_path_len + 1);
5810 strncpy (new_multilib_dir, this_path, this_path_len);
5811 new_multilib_dir[this_path_len] = '\0';
5812 multilib_dir = new_multilib_dir;
5821 /* Print out the multiple library subdirectory selection
5822 information. This prints out a series of lines. Each line looks
5823 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5824 required. Only the desired options are printed out, the negative
5825 matches. The options are print without a leading dash. There are
5826 no spaces to make it easy to use the information in the shell.
5827 Each subdirectory is printed only once. This assumes the ordering
5828 generated by the genmultilib script. */
5831 print_multilib_info ()
5833 char *p = multilib_select;
5834 char *last_path = 0, *this_path;
5836 int last_path_len = 0;
5840 /* Ignore newlines. */
5847 /* Get the initial path. */
5856 /* If this is a duplicate, skip it. */
5857 skip = (last_path != 0 && p - this_path == last_path_len
5858 && ! strncmp (last_path, this_path, last_path_len));
5860 last_path = this_path;
5861 last_path_len = p - this_path;
5863 /* If this directory requires any default arguments, we can skip
5864 it. We will already have printed a directory identical to
5865 this one which does not require that default argument. */
5883 while (*q != ' ' && *q != ';')
5891 && default_arg (arg, q - arg))
5906 for (p1 = last_path; p1 < p; p1++)
5925 use_arg = *p != '!';
5930 while (*p != ' ' && *p != ';')
5945 /* If there are extra options, print them now */
5946 if (multilib_extra && *multilib_extra)
5948 int print_at = TRUE;
5951 for (q = multilib_extra; *q != '\0'; q++)