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 $ */
26 /* $DragonFly: src/contrib/gcc/Attic/gcc.c,v 1.5 2004/01/29 01:39:44 dillon Exp $ */
28 /* This program is the user interface to the C compiler and possibly to
29 other compilers. It is used because compilation is a complicated procedure
30 which involves running several programs and passing temporary files between
31 them, forwarding the users switches to those programs selectively,
32 and deleting the temporary files at the end.
34 CC recognizes how to compile each input file by suffixes in the file names.
35 Once it knows which kind of compilation to perform, the procedure for
36 compilation is specified by a string called a "spec". */
47 #define exit __posix_exit
50 /* By default there is no special suffix for executables. */
51 #ifdef EXECUTABLE_SUFFIX
52 #define HAVE_EXECUTABLE_SUFFIX
54 #define EXECUTABLE_SUFFIX ""
57 /* By default, the suffix for object files is ".o". */
59 #define HAVE_OBJECT_SUFFIX
61 #define OBJECT_SUFFIX ".o"
64 /* By default, colon separates directories in a path. */
65 #ifndef PATH_SEPARATOR
66 #define PATH_SEPARATOR ':'
70 #define DIR_SEPARATOR '/'
73 /* Define IS_DIR_SEPARATOR. */
74 #ifndef DIR_SEPARATOR_2
75 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
76 #else /* DIR_SEPARATOR_2 */
77 # define IS_DIR_SEPARATOR(ch) \
78 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
79 #endif /* DIR_SEPARATOR_2 */
81 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
83 #define obstack_chunk_alloc xmalloc
84 #define obstack_chunk_free free
86 #ifndef GET_ENV_PATH_LIST
87 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
91 #define kill(p,s) raise(s)
94 /* If a stage of compilation returns an exit status >= 1,
95 compilation of that file ceases. */
97 #define MIN_FATAL_STATUS 1
99 /* Flag saying to print the directories gcc will search through looking for
100 programs, libraries, etc. */
102 static int print_search_dirs;
104 /* Flag saying to print the full filename of this file
105 as found through our usual search mechanism. */
107 static const char *print_file_name = NULL;
109 /* As print_file_name, but search for executable file. */
111 static const char *print_prog_name = NULL;
113 /* Flag saying to print the relative path we'd use to
114 find libgcc.a given the current compiler flags. */
116 static int print_multi_directory;
118 /* Flag saying to print the list of subdirectories and
119 compiler flags used to select them in a standard form. */
121 static int print_multi_lib;
123 /* Flag saying to print the command line options understood by gcc and its
126 static int print_help_list;
128 /* Flag indicating whether we should print the command and arguments */
130 static int verbose_flag;
132 /* Nonzero means write "temp" files in source directory
133 and use the source file's name in them, and don't delete them. */
135 static int save_temps_flag;
137 /* The compiler version. */
139 static char *compiler_version;
141 /* The target version specified with -V */
143 static char *spec_version = DEFAULT_TARGET_VERSION;
145 /* The target machine specified with -b. */
147 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
149 /* Nonzero if cross-compiling.
150 When -b is used, the value comes from the `specs' file. */
153 static char *cross_compile = "1";
155 static char *cross_compile = "0";
158 /* The number of errors that have occurred; the link phase will not be
159 run if this is non-zero. */
160 static int error_count = 0;
162 /* This is the obstack which we use to allocate many strings. */
164 static struct obstack obstack;
166 /* This is the obstack to build an environment variable to pass to
167 collect2 that describes all of the relevant switches of what to
168 pass the compiler in building the list of pointers to constructors
171 static struct obstack collect_obstack;
173 extern char *version_string;
175 /* Forward declaration for prototypes. */
178 static void init_spec PROTO((void));
179 static void read_specs PROTO((const char *, int));
180 static void set_spec PROTO((const char *, const char *));
181 static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
182 static char *build_search_list PROTO((struct path_prefix *, const char *, int));
183 static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
184 static char *find_a_file PROTO((struct path_prefix *, const char *, int));
185 static void add_prefix PROTO((struct path_prefix *, const char *,
186 const char *, int, int, int *));
187 static char *skip_whitespace PROTO((char *));
188 static void record_temp_file PROTO((const char *, int, int));
189 static void delete_if_ordinary PROTO((const char *));
190 static void delete_temp_files PROTO((void));
191 static void delete_failure_queue PROTO((void));
192 static void clear_failure_queue PROTO((void));
193 static int check_live_switch PROTO((int, int));
194 static const char *handle_braces PROTO((const char *));
195 static char *save_string PROTO((const char *, int));
196 extern int do_spec PROTO((const char *));
197 static int do_spec_1 PROTO((const char *, int, const char *));
198 static const char *find_file PROTO((const char *));
199 static int is_directory PROTO((const char *, const char *, int));
200 static void validate_switches PROTO((const char *));
201 static void validate_all_switches PROTO((void));
202 static void give_switch PROTO((int, int, int));
203 static int used_arg PROTO((const char *, int));
204 static int default_arg PROTO((const char *, int));
205 static void set_multilib_dir PROTO((void));
206 static void print_multilib_info PROTO((void));
207 static void pfatal_with_name PROTO((const char *)) ATTRIBUTE_NORETURN;
208 static void perror_with_name PROTO((const char *));
209 static void pfatal_pexecute PROTO((const char *, const char *))
211 static void error PVPROTO((const char *, ...))
213 static void notice PVPROTO((const char *, ...))
215 static void display_help PROTO((void));
216 static void add_preprocessor_option PROTO ((const char *, int));
217 static void add_assembler_option PROTO ((const char *, int));
218 static void add_linker_option PROTO ((const char *, int));
219 static void process_command PROTO ((int, char **));
220 static int execute PROTO ((void));
221 static void unused_prefix_warnings PROTO ((struct path_prefix *));
222 static void clear_args PROTO ((void));
223 static void fatal_error PROTO ((int));
225 void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN;
227 /* Called before processing to change/add/remove arguments. */
228 extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)),
229 int *, char ***, int *));
231 /* Called before linking. Returns 0 on success and -1 on failure. */
232 extern int lang_specific_pre_link ();
234 /* Number of extra output files that lang_specific_pre_link may generate. */
235 extern int lang_specific_extra_outfiles;
237 /* Specs are strings containing lines, each of which (if not blank)
238 is made up of a program name, and arguments separated by spaces.
239 The program name must be exact and start from root, since no path
240 is searched and it is unreliable to depend on the current working directory.
241 Redirection of input or output is not supported; the subprograms must
242 accept filenames saying what files to read and write.
244 In addition, the specs can contain %-sequences to substitute variable text
245 or for conditional text. Here is a table of all defined %-sequences.
246 Note that spaces are not generated automatically around the results of
247 expanding these sequences; therefore, you can concatenate them together
248 or with constant text in a single argument.
250 %% substitute one % into the program name or argument.
251 %i substitute the name of the input file being processed.
252 %b substitute the basename of the input file being processed.
253 This is the substring up to (and not including) the last period
254 and not including the directory.
256 substitute a file name that has suffix SUFFIX and is chosen
257 once per compilation, and mark the argument a la %d. To reduce
258 exposure to denial-of-service attacks, the file name is now
259 chosen in a way that is hard to predict even when previously
260 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
261 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
262 the regexp "[.A-Za-z]*" or the special string "%O", which is
263 treated exactly as if %O had been pre-processed. Previously, %g
264 was simply substituted with a file name chosen once per compilation,
265 without regard to any appended suffix (which was therefore treated
266 just like ordinary text), making such attacks more likely to succeed.
268 like %g, but generates a new temporary file name even if %uSUFFIX
271 substitutes the last file name generated with %uSUFFIX, generating a
272 new one if there is no such last file name. In the absence of any
273 %uSUFFIX, this is just like %gSUFFIX, except they don't share
274 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
275 would involve the generation of two distinct file names, one
276 for each `%g.s' and another for each `%U.s'. Previously, %U was
277 simply substituted with a file name chosen for the previous %u,
278 without regard to any appended suffix.
279 %d marks the argument containing or following the %d as a
280 temporary file name, so that that file will be deleted if CC exits
281 successfully. Unlike %g, this contributes no text to the argument.
282 %w marks the argument containing or following the %w as the
283 "output file" of this compilation. This puts the argument
284 into the sequence of arguments that %o will substitute later.
286 like %{...} but mark last argument supplied within
287 as a file to be deleted on failure.
288 %o substitutes the names of all the output files, with spaces
289 automatically placed around them. You should write spaces
290 around the %o as well or the results are undefined.
291 %o is for use in the specs for running the linker.
292 Input files whose names have no recognized suffix are not compiled
293 at all, but they are included among the output files, so they will
295 %O substitutes the suffix for object files. Note that this is
296 handled specially when it immediately follows %g, %u, or %U,
297 because of the need for those to form complete file names. The
298 handling is such that %O is treated exactly as if it had already
299 been substituted, except that %g, %u, and %U do not currently
300 support additional SUFFIX characters following %O as they would
301 following, for example, `.o'.
302 %p substitutes the standard macro predefinitions for the
303 current target machine. Use this when running cpp.
304 %P like %p, but puts `__' before and after the name of each macro.
305 (Except macros that already have __.)
307 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
308 %s current argument is the name of a library or startup file of some sort.
309 Search for that file in a standard list of directories
310 and substitute the full name found.
311 %eSTR Print STR as an error message. STR is terminated by a newline.
312 Use this when inconsistent options are detected.
313 %x{OPTION} Accumulate an option for %X.
314 %X Output the accumulated linker options specified by compilations.
315 %Y Output the accumulated assembler options specified by compilations.
316 %Z Output the accumulated preprocessor options specified by compilations.
317 %v1 Substitute the major version number of GCC.
318 (For version 2.5.n, this is 2.)
319 %v2 Substitute the minor version number of GCC.
320 (For version 2.5.n, this is 5.)
321 %a process ASM_SPEC as a spec.
322 This allows config.h to specify part of the spec for running as.
323 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
324 used here. This can be used to run a post-processor after the
325 assembler has done its job.
326 %D Dump out a -L option for each directory in startfile_prefixes.
327 If multilib_dir is set, extra entries are generated with it affixed.
328 %l process LINK_SPEC as a spec.
329 %L process LIB_SPEC as a spec.
330 %G process LIBGCC_SPEC as a spec.
331 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
332 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
333 %c process SIGNED_CHAR_SPEC as a spec.
334 %C process CPP_SPEC as a spec. A capital C is actually used here.
335 %1 process CC1_SPEC as a spec.
336 %2 process CC1PLUS_SPEC as a spec.
337 %| output "-" if the input for the current command is coming from a pipe.
338 %* substitute the variable part of a matched option. (See below.)
339 Note that each comma in the substituted string is replaced by
341 %{S} substitutes the -S switch, if that switch was given to CC.
342 If that switch was not specified, this substitutes nothing.
343 Here S is a metasyntactic variable.
344 %{S*} substitutes all the switches specified to CC whose names start
345 with -S. This is used for -o, -D, -I, etc; switches that take
346 arguments. CC considers `-o foo' as being one switch whose
347 name starts with `o'. %{o*} would substitute this text,
348 including the space; thus, two arguments would be generated.
349 %{^S*} likewise, but don't put a blank between a switch and any args.
350 %{S*:X} substitutes X if one or more switches whose names start with -S are
351 specified to CC. Note that the tail part of the -S option
352 (i.e. the part matched by the `*') will be substituted for each
353 occurrence of %* within X.
354 %{S:X} substitutes X, but only if the -S switch was given to CC.
355 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
356 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
357 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
358 %{.S:X} substitutes X, but only if processing a file with suffix S.
359 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
360 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
361 combined with ! and . as above binding stronger than the OR.
362 %(Spec) processes a specification defined in a specs file as *Spec:
363 %[Spec] as above, but put __ around -D arguments
365 The conditional text X in a %{S:X} or %{!S:X} construct may contain
366 other nested % constructs or spaces, or even newlines. They are
367 processed as usual, as described above.
369 The -O, -f, -m, and -W switches are handled specifically in these
370 constructs. If another value of -O or the negated form of a -f, -m, or
371 -W switch is found later in the command line, the earlier switch
372 value is ignored, except with {S*} where S is just one letter; this
373 passes all matching options.
375 The character | at the beginning of the predicate text is used to indicate
376 that a command should be piped to the following command, but only if -pipe
379 Note that it is built into CC which switches take arguments and which
380 do not. You might think it would be useful to generalize this to
381 allow each compiler's spec to say which switches take arguments. But
382 this cannot be done in a consistent fashion. CC cannot even decide
383 which input files have been specified without knowing which switches
384 take arguments, and it must know which input files to compile in order
385 to tell which compilers to run.
387 CC also knows implicitly that arguments starting in `-l' are to be
388 treated as compiler output files, and passed to the linker in their
389 proper position among the other output files. */
391 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
393 /* config.h can define ASM_SPEC to provide extra args to the assembler
394 or extra switch-translations. */
399 /* config.h can define ASM_FINAL_SPEC to run a post processor after
400 the assembler has run. */
401 #ifndef ASM_FINAL_SPEC
402 #define ASM_FINAL_SPEC ""
405 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
406 or extra switch-translations. */
411 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
412 or extra switch-translations. */
417 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
418 or extra switch-translations. */
420 #define CC1PLUS_SPEC ""
423 /* config.h can define LINK_SPEC to provide extra args to the linker
424 or extra switch-translations. */
429 /* config.h can define LIB_SPEC to override the default libraries. */
431 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
434 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
437 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
438 /* Have gcc do the search for libgcc.a. */
439 #define LIBGCC_SPEC "libgcc.a%s"
441 #define LIBGCC_SPEC "-lgcc"
445 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
446 #ifndef STARTFILE_SPEC
447 #define STARTFILE_SPEC \
448 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
451 /* config.h can define SWITCHES_NEED_SPACES to control which options
452 require spaces between the option and the argument. */
453 #ifndef SWITCHES_NEED_SPACES
454 #define SWITCHES_NEED_SPACES ""
457 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
459 #define ENDFILE_SPEC ""
462 /* This spec is used for telling cpp whether char is signed or not. */
463 #ifndef SIGNED_CHAR_SPEC
464 /* Use #if rather than ?:
465 because MIPS C compiler rejects like ?: in initializers. */
466 #if DEFAULT_SIGNED_CHAR
467 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
469 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
474 #define LINKER_NAME "collect2"
477 static char *cpp_spec = CPP_SPEC;
478 static char *cpp_predefines = CPP_PREDEFINES;
479 static char *cc1_spec = CC1_SPEC;
480 static char *cc1plus_spec = CC1PLUS_SPEC;
481 static char *signed_char_spec = SIGNED_CHAR_SPEC;
482 static char *asm_spec = ASM_SPEC;
483 static char *asm_final_spec = ASM_FINAL_SPEC;
484 static char *link_spec = LINK_SPEC;
485 static char *lib_spec = LIB_SPEC;
486 static char *libgcc_spec = LIBGCC_SPEC;
487 static char *endfile_spec = ENDFILE_SPEC;
488 static char *startfile_spec = STARTFILE_SPEC;
489 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
490 static char *linker_name_spec = LINKER_NAME;
492 /* Some compilers have limits on line lengths, and the multilib_select
493 and/or multilib_matches strings can be very long, so we build them at
495 static struct obstack multilib_obstack;
496 static char *multilib_select;
497 static char *multilib_matches;
498 static char *multilib_defaults;
499 #include "multilib.h"
501 /* Check whether a particular argument is a default argument. */
503 #ifndef MULTILIB_DEFAULTS
504 #define MULTILIB_DEFAULTS { "" }
507 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
510 struct user_specs *next;
511 const char *filename;
514 static struct user_specs *user_specs_head, *user_specs_tail;
516 /* This defines which switch letters take arguments. */
518 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
519 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
520 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
521 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
522 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
523 || (CHAR) == 'B' || (CHAR) == 'b')
525 #ifndef SWITCH_TAKES_ARG
526 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
529 /* This defines which multi-letter switches take arguments. */
531 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
532 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
533 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
534 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
535 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
536 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
537 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
539 #ifndef WORD_SWITCH_TAKES_ARG
540 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
544 #ifdef HAVE_EXECUTABLE_SUFFIX
545 /* This defines which switches stop a full compilation. */
546 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
547 ((CHAR) == 'c' || (CHAR) == 'S')
549 #ifndef SWITCH_CURTAILS_COMPILATION
550 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
551 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
555 /* Record the mapping from file suffixes for compilation specs. */
559 const char *suffix; /* Use this compiler for input files
560 whose names end in this suffix. */
562 const char *spec[4]; /* To use this compiler, concatenate these
563 specs and pass to do_spec. */
566 /* Pointer to a vector of `struct compiler' that gives the spec for
567 compiling a file, based on its suffix.
568 A file that does not end in any of these suffixes will be passed
569 unchanged to the loader and nothing else will be done to it.
571 An entry containing two 0s is used to terminate the vector.
573 If multiple entries match a file, the last matching one is used. */
575 static struct compiler *compilers;
577 /* Number of entries in `compilers', not counting the null terminator. */
579 static int n_compilers;
581 /* The default list of file name suffixes and their compilation specs. */
583 static struct compiler default_compilers[] =
585 /* Add lists of suffixes of known languages here. If those languages
586 were not present when we built the driver, we will hit these copies
587 and be given a more meaningful error than "file not used since
588 linking is not done". */
589 {".m", {"#Objective-C"}},
590 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}},
591 {".c++", {"#C++"}}, {".C", {"#C++"}},
592 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
593 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
594 {".fpp", {"#Fortran"}},
595 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
596 /* Next come the entries for C. */
601 "%{E|M|MM:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
602 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
603 %{C:%{!E:%eGNU C does not support -C without using -E}}\
604 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
605 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
606 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
607 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
608 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
609 %{ffast-math:-D__FAST_MATH__}\
610 %{traditional} %{ftraditional:-traditional}\
611 %{traditional-cpp:-traditional}\
612 %{fleading-underscore} %{fno-leading-underscore}\
613 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
614 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
615 %{!E:%{!M:%{!MM:cc1 %i %1 \
616 %{std*} %{nostdinc*} %{A*} %{I*} %I\
617 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
618 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
619 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
620 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
621 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
622 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
623 %{ffast-math:-D__FAST_MATH__}\
624 %{H} %C %{D*} %{U*} %{i*} %Z\
625 %{ftraditional:-traditional}\
626 %{traditional-cpp:-traditional}\
627 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
628 %{aux-info*} %{Qn:-fno-ident}\
630 %{g*} %{O*} %{W*} %{w} %{pedantic*}\
631 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
632 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
634 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
635 %{!pipe:%g.s} %A\n }}}}"
636 #else /* ! USE_CPPLIB */
637 "cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
638 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
639 %{C:%{!E:%eGNU C does not support -C without using -E}}\
640 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
641 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
642 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
643 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
644 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
645 %{ffast-math:-D__FAST_MATH__}\
646 %{traditional} %{ftraditional:-traditional}\
647 %{traditional-cpp:-traditional}\
648 %{fleading-underscore} %{fno-leading-underscore}\
649 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
650 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
651 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
652 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
653 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
654 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
655 %{aux-info*} %{Qn:-fno-ident}\
657 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
658 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
660 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
661 %{!pipe:%g.s} %A\n }}}}"
662 #endif /* ! USE_CPPLIB */
665 {"%{E:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
666 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
667 %{C:%{!E:%eGNU C does not support -C without using -E}}\
668 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
669 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
670 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
671 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
672 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
673 %{ffast-math:-D__FAST_MATH__}\
674 %{traditional} %{ftraditional:-traditional}\
675 %{traditional-cpp:-traditional}\
676 %{fleading-underscore} %{fno-leading-underscore}\
677 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
679 %{!E:%e-E required when input is from standard input}"}},
680 {".h", {"@c-header"}},
682 {"%{!E:%eCompilation of header file requested} \
683 cpp0 %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
684 %{C:%{!E:%eGNU C does not support -C without using -E}}\
685 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
686 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
687 %{std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
688 %{!undef:%{!std=*:%p}%{std=gnu*:%p} %P} %{trigraphs}\
689 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
690 %{ffast-math:-D__FAST_MATH__}\
691 %{traditional} %{ftraditional:-traditional}\
692 %{traditional-cpp:-traditional}\
693 %{fleading-underscore} %{fno-leading-underscore}\
694 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
696 {".i", {"@cpp-output"}},
698 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
699 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
700 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
701 %{aux-info*} %{Qn:-fno-ident}\
702 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
703 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
705 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
706 %{!pipe:%g.s} %A\n }}}}"}},
707 {".s", {"@assembler"}},
709 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
710 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
712 {".S", {"@assembler-with-cpp"}},
713 {"@assembler-with-cpp",
714 {"cpp0 -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
715 %{C:%{!E:%eGNU C does not support -C without using -E}}\
716 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
717 -$ %{!undef:%p %P} -D__ASSEMBLER__ \
718 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
719 %{ffast-math:-D__FAST_MATH__}\
720 %{traditional} %{ftraditional:-traditional}\
721 %{traditional-cpp:-traditional}\
722 %{fleading-underscore} %{fno-leading-underscore}\
723 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
724 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
725 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
726 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
727 %{!pipe:%g.s} %A\n }}}}"}},
729 /* Mark end of table */
733 /* Number of elements in default_compilers, not counting the terminator. */
735 static int n_default_compilers
736 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
738 /* Here is the spec for running the linker, after compiling all files. */
740 /* -u* was put back because both BSD and SysV seem to support it. */
741 /* %{static:} simply prevents an error message if the target machine
742 doesn't handle -static. */
743 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
744 scripts which exist in user specified directories, or in standard
746 #ifdef LINK_COMMAND_SPEC
747 /* Provide option to override link_command_spec from machine specific
748 configuration files. */
749 static const char *link_command_spec =
752 #ifdef LINK_LIBGCC_SPECIAL
753 /* Don't generate -L options. */
754 static const char *link_command_spec = "\
756 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
757 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
758 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
760 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
761 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
766 static const char *link_command_spec = "\
768 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
769 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
770 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
771 %{static:} %{L*} %D %o\
772 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
773 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
779 /* A vector of options to give to the linker.
780 These options are accumulated by %x,
781 and substituted into the linker command with %X. */
782 static int n_linker_options;
783 static char **linker_options;
785 /* A vector of options to give to the assembler.
786 These options are accumulated by -Wa,
787 and substituted into the assembler command with %Y. */
788 static int n_assembler_options;
789 static char **assembler_options;
791 /* A vector of options to give to the preprocessor.
792 These options are accumulated by -Wp,
793 and substituted into the preprocessor command with %Z. */
794 static int n_preprocessor_options;
795 static char **preprocessor_options;
797 /* Define how to map long options into short ones. */
799 /* This structure describes one mapping. */
802 /* The long option's name. */
804 /* The equivalent short option. */
805 const char *equivalent;
806 /* Argument info. A string of flag chars; NULL equals no options.
807 a => argument required.
808 o => argument optional.
809 j => join argument to equivalent, making one word.
810 * => require other text after NAME as an argument. */
811 const char *arg_info;
814 /* This is the table of mappings. Mappings are tried sequentially
815 for each option encountered; the first one that matches, wins. */
817 struct option_map option_map[] =
819 {"--all-warnings", "-Wall", 0},
820 {"--ansi", "-ansi", 0},
821 {"--assemble", "-S", 0},
822 {"--assert", "-A", "a"},
823 {"--classpath", "-fclasspath=", "aj"},
824 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
825 {"--comments", "-C", 0},
826 {"--compile", "-c", 0},
827 {"--debug", "-g", "oj"},
828 {"--define-macro", "-D", "aj"},
829 {"--dependencies", "-M", 0},
830 {"--dump", "-d", "a"},
831 {"--dumpbase", "-dumpbase", "a"},
832 {"--entry", "-e", 0},
833 {"--extra-warnings", "-W", 0},
834 {"--for-assembler", "-Wa", "a"},
835 {"--for-linker", "-Xlinker", "a"},
836 {"--force-link", "-u", "a"},
837 {"--imacros", "-imacros", "a"},
838 {"--include", "-include", "a"},
839 {"--include-barrier", "-I-", 0},
840 {"--include-directory", "-I", "aj"},
841 {"--include-directory-after", "-idirafter", "a"},
842 {"--include-prefix", "-iprefix", "a"},
843 {"--include-with-prefix", "-iwithprefix", "a"},
844 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
845 {"--include-with-prefix-after", "-iwithprefix", "a"},
846 {"--language", "-x", "a"},
847 {"--library-directory", "-L", "a"},
848 {"--machine", "-m", "aj"},
849 {"--machine-", "-m", "*j"},
850 {"--no-line-commands", "-P", 0},
851 {"--no-precompiled-includes", "-noprecomp", 0},
852 {"--no-standard-includes", "-nostdinc", 0},
853 {"--no-standard-libraries", "-nostdlib", 0},
854 {"--no-warnings", "-w", 0},
855 {"--optimize", "-O", "oj"},
856 {"--output", "-o", "a"},
857 {"--output-class-directory", "-foutput-class-dir=", "ja"},
858 {"--pedantic", "-pedantic", 0},
859 {"--pedantic-errors", "-pedantic-errors", 0},
860 {"--pipe", "-pipe", 0},
861 {"--prefix", "-B", "a"},
862 {"--preprocess", "-E", 0},
863 {"--print-search-dirs", "-print-search-dirs", 0},
864 {"--print-file-name", "-print-file-name=", "aj"},
865 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
866 {"--print-missing-file-dependencies", "-MG", 0},
867 {"--print-multi-lib", "-print-multi-lib", 0},
868 {"--print-multi-directory", "-print-multi-directory", 0},
869 {"--print-prog-name", "-print-prog-name=", "aj"},
870 {"--profile", "-p", 0},
871 {"--profile-blocks", "-a", 0},
872 {"--quiet", "-q", 0},
873 {"--save-temps", "-save-temps", 0},
874 {"--shared", "-shared", 0},
875 {"--silent", "-q", 0},
876 {"--specs", "-specs=", "aj"},
877 {"--static", "-static", 0},
878 {"--std", "-std=", "aj"},
879 {"--symbolic", "-symbolic", 0},
880 {"--target", "-b", "a"},
881 {"--trace-includes", "-H", 0},
882 {"--traditional", "-traditional", 0},
883 {"--traditional-cpp", "-traditional-cpp", 0},
884 {"--trigraphs", "-trigraphs", 0},
885 {"--undefine-macro", "-U", "aj"},
886 {"--use-version", "-V", "a"},
887 {"--user-dependencies", "-MM", 0},
888 {"--verbose", "-v", 0},
889 {"--version", "-dumpversion", 0},
890 {"--warn-", "-W", "*j"},
891 {"--write-dependencies", "-MD", 0},
892 {"--write-user-dependencies", "-MMD", 0},
896 /* Translate the options described by *ARGCP and *ARGVP.
897 Make a new vector and store it back in *ARGVP,
898 and store its length in *ARGVC. */
901 translate_options (argcp, argvp)
907 const char **argv = *argvp;
909 (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *));
913 newv[newindex++] = argv[i++];
917 /* Translate -- options. */
918 if (argv[i][0] == '-' && argv[i][1] == '-')
921 /* Find a mapping that applies to this option. */
922 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
924 size_t optlen = strlen (option_map[j].name);
925 size_t arglen = strlen (argv[i]);
926 size_t complen = arglen > optlen ? optlen : arglen;
927 const char *arginfo = option_map[j].arg_info;
932 if (!strncmp (argv[i], option_map[j].name, complen))
940 k < sizeof (option_map) / sizeof (option_map[0]);
942 if (strlen (option_map[k].name) >= arglen
943 && !strncmp (argv[i], option_map[k].name, arglen))
945 error ("Ambiguous abbreviation %s", argv[i]);
949 if (k != sizeof (option_map) / sizeof (option_map[0]))
955 /* If the option has an argument, accept that. */
956 if (argv[i][optlen] == '=')
957 arg = argv[i] + optlen + 1;
959 /* If this mapping requires extra text at end of name,
960 accept that as "argument". */
961 else if (index (arginfo, '*') != 0)
962 arg = argv[i] + optlen;
964 /* Otherwise, extra text at end means mismatch.
965 Try other mappings. */
970 else if (index (arginfo, '*') != 0)
972 error ("Incomplete `%s' option", option_map[j].name);
976 /* Handle arguments. */
977 if (index (arginfo, 'a') != 0)
983 error ("Missing argument to `%s' option",
991 else if (index (arginfo, '*') != 0)
993 else if (index (arginfo, 'o') == 0)
996 error ("Extraneous argument to `%s' option",
1001 /* Store the translation as one argv elt or as two. */
1002 if (arg != 0 && index (arginfo, 'j') != 0)
1003 newv[newindex++] = concat (option_map[j].equivalent, arg,
1007 newv[newindex++] = option_map[j].equivalent;
1008 newv[newindex++] = arg;
1011 newv[newindex++] = option_map[j].equivalent;
1019 /* Handle old-fashioned options--just copy them through,
1020 with their arguments. */
1021 else if (argv[i][0] == '-')
1023 const char *p = argv[i] + 1;
1027 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1028 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1029 else if (WORD_SWITCH_TAKES_ARG (p))
1030 nskip += WORD_SWITCH_TAKES_ARG (p);
1031 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1034 else if (! strcmp (p, "Xlinker"))
1037 /* Watch out for an option at the end of the command line that
1038 is missing arguments, and avoid skipping past the end of the
1040 if (nskip + i > argc)
1045 newv[newindex++] = argv[i++];
1050 /* Ordinary operands, or +e options. */
1051 newv[newindex++] = argv[i++];
1064 #ifdef HAVE_STRERROR
1073 if (e > 0 && e < sys_nerr)
1074 return sys_errlist[e];
1086 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1087 be considered whitespace. */
1088 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1090 else if (*p == '\n' || *p == ' ' || *p == '\t')
1094 while (*p != '\n') p++;
1104 /* Structure to keep track of the specs that have been defined so far.
1105 These are accessed using %(specname) or %[specname] in a compiler
1110 /* The following 2 fields must be first */
1111 /* to allow EXTRA_SPECS to be initialized */
1112 char *name; /* name of the spec. */
1113 char *ptr; /* available ptr if no static pointer */
1115 /* The following fields are not initialized */
1116 /* by EXTRA_SPECS */
1117 char **ptr_spec; /* pointer to the spec itself. */
1118 struct spec_list *next; /* Next spec in linked list. */
1119 int name_len; /* length of the name */
1120 int alloc_p; /* whether string was allocated */
1123 #define INIT_STATIC_SPEC(NAME,PTR) \
1124 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1126 /* List of statically defined specs */
1127 static struct spec_list static_specs[] = {
1128 INIT_STATIC_SPEC ("asm", &asm_spec),
1129 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1130 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1131 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1132 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1133 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1134 INIT_STATIC_SPEC ("link", &link_spec),
1135 INIT_STATIC_SPEC ("lib", &lib_spec),
1136 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1137 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1138 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1139 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1140 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1141 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1142 INIT_STATIC_SPEC ("version", &compiler_version),
1143 INIT_STATIC_SPEC ("multilib", &multilib_select),
1144 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1145 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1146 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1147 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1150 #ifdef EXTRA_SPECS /* additional specs needed */
1151 /* Structure to keep track of just the first two args of a spec_list.
1152 That is all that the EXTRA_SPECS macro gives us. */
1159 static struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1160 static struct spec_list * extra_specs = (struct spec_list *)0;
1163 /* List of dynamically allocates specs that have been defined so far. */
1165 static struct spec_list *specs = (struct spec_list *)0;
1168 /* Initialize the specs lookup routines. */
1173 struct spec_list *next = (struct spec_list *)0;
1174 struct spec_list *sl = (struct spec_list *)0;
1178 return; /* already initialized */
1181 notice ("Using builtin specs.\n");
1184 extra_specs = (struct spec_list *)
1185 xmalloc (sizeof(struct spec_list) *
1186 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
1187 bzero ((PTR) extra_specs, sizeof(struct spec_list) *
1188 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
1190 for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--)
1192 sl = &extra_specs[i];
1193 sl->name = extra_specs_1[i].name;
1194 sl->ptr = extra_specs_1[i].ptr;
1196 sl->name_len = strlen (sl->name);
1197 sl->ptr_spec = &sl->ptr;
1202 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1204 sl = &static_specs[i];
1213 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1214 removed; If the spec starts with a + then SPEC is added to the end of the
1218 set_spec (name, spec)
1222 struct spec_list *sl;
1224 int name_len = strlen (name);
1227 /* If this is the first call, initialize the statically allocated specs */
1230 struct spec_list *next = (struct spec_list *)0;
1231 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1234 sl = &static_specs[i];
1241 /* See if the spec already exists */
1242 for (sl = specs; sl; sl = sl->next)
1243 if (name_len == sl->name_len && !strcmp (sl->name, name))
1248 /* Not found - make it */
1249 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1250 sl->name = save_string (name, strlen (name));
1251 sl->name_len = name_len;
1252 sl->ptr_spec = &sl->ptr;
1254 *(sl->ptr_spec) = "";
1259 old_spec = *(sl->ptr_spec);
1260 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1261 ? concat (old_spec, spec + 1, NULL_PTR)
1262 : save_string (spec, strlen (spec)));
1266 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1269 /* Free the old spec */
1270 if (old_spec && sl->alloc_p)
1276 /* Accumulate a command (program name and args), and run it. */
1278 /* Vector of pointers to arguments in the current line of specifications. */
1280 static char **argbuf;
1282 /* Number of elements allocated in argbuf. */
1284 static int argbuf_length;
1286 /* Number of elements in argbuf currently in use (containing args). */
1288 static int argbuf_index;
1290 /* We want this on by default all the time now. */
1291 #define MKTEMP_EACH_FILE
1293 #ifdef MKTEMP_EACH_FILE
1295 extern char *make_temp_file PROTO((const char *));
1297 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1300 static struct temp_name {
1301 const char *suffix; /* suffix associated with the code. */
1302 int length; /* strlen (suffix). */
1303 int unique; /* Indicates whether %g or %u/%U was used. */
1304 const char *filename; /* associated filename. */
1305 int filename_length; /* strlen (filename). */
1306 struct temp_name *next;
1311 /* Number of commands executed so far. */
1313 static int execution_count;
1315 /* Number of commands that exited with a signal. */
1317 static int signal_count;
1319 /* Name with which this program was invoked. */
1321 static const char *programname;
1323 /* Structures to keep track of prefixes to try when looking for files. */
1327 char *prefix; /* String to prepend to the path. */
1328 struct prefix_list *next; /* Next in linked list. */
1329 int require_machine_suffix; /* Don't use without machine_suffix. */
1330 /* 2 means try both machine_suffix and just_machine_suffix. */
1331 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1336 struct prefix_list *plist; /* List of prefixes to try */
1337 int max_len; /* Max length of a prefix in PLIST */
1338 const char *name; /* Name of this list (used in config stuff) */
1341 /* List of prefixes to try when looking for executables. */
1343 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1345 /* List of prefixes to try when looking for startup (crt0) files. */
1347 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1349 /* List of prefixes to try when looking for include files. */
1351 static struct path_prefix include_prefixes = { 0, 0, "include" };
1353 /* Suffix to attach to directories searched for commands.
1354 This looks like `MACHINE/VERSION/'. */
1356 static const char *machine_suffix = 0;
1358 /* Suffix to attach to directories searched for commands.
1359 This is just `MACHINE/'. */
1361 static const char *just_machine_suffix = 0;
1363 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1365 static const char *gcc_exec_prefix;
1367 /* Default prefixes to attach to command names. */
1369 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1370 #undef MD_EXEC_PREFIX
1371 #undef MD_STARTFILE_PREFIX
1372 #undef MD_STARTFILE_PREFIX_1
1375 #ifndef STANDARD_EXEC_PREFIX
1376 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1377 #endif /* !defined STANDARD_EXEC_PREFIX */
1379 static const char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1380 static const char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1381 #ifdef MD_EXEC_PREFIX
1382 static const char *md_exec_prefix = MD_EXEC_PREFIX;
1385 #ifndef STANDARD_STARTFILE_PREFIX
1386 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1387 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1389 #ifdef MD_STARTFILE_PREFIX
1390 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1392 #ifdef MD_STARTFILE_PREFIX_1
1393 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1395 static const char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1396 static const char *standard_startfile_prefix_1 = "/lib/";
1397 static const char *standard_startfile_prefix_2 = "/usr/lib/";
1400 #error CCVER not defined
1403 #error BINUTILS not defined
1406 #ifndef TOOLDIR_BASE_PREFIX
1407 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1409 static const char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1410 static const char *tooldir_prefix;
1412 /* Subdirectory to use for locating libraries. Set by
1413 set_multilib_dir based on the compilation options. */
1415 static const char *multilib_dir;
1417 /* Clear out the vector of arguments (after a command is executed). */
1425 /* Add one argument to the vector at the end.
1426 This is done when a space is seen or at the end of the line.
1427 If DELETE_ALWAYS is nonzero, the arg is a filename
1428 and the file should be deleted eventually.
1429 If DELETE_FAILURE is nonzero, the arg is a filename
1430 and the file should be deleted if this compilation fails. */
1433 store_arg (arg, delete_always, delete_failure)
1435 int delete_always, delete_failure;
1437 if (argbuf_index + 1 == argbuf_length)
1439 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1441 argbuf[argbuf_index++] = arg;
1442 argbuf[argbuf_index] = 0;
1444 if (delete_always || delete_failure)
1445 record_temp_file (arg, delete_always, delete_failure);
1448 /* Read compilation specs from a file named FILENAME,
1449 replacing the default ones.
1451 A suffix which starts with `*' is a definition for
1452 one of the machine-specific sub-specs. The "suffix" should be
1453 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1454 The corresponding spec is stored in asm_spec, etc.,
1455 rather than in the `compilers' vector.
1457 Anything invalid in the file is a fatal error. */
1460 read_specs (filename, main_p)
1461 const char *filename;
1466 struct stat statbuf;
1471 notice ("Reading specs from %s\n", filename);
1473 /* Open and stat the file. */
1474 desc = open (filename, O_RDONLY, 0);
1476 pfatal_with_name (filename);
1477 if (stat (filename, &statbuf) < 0)
1478 pfatal_with_name (filename);
1480 /* Read contents of file into BUFFER. */
1481 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1482 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1484 pfatal_with_name (filename);
1485 buffer[readlen] = 0;
1488 /* Scan BUFFER for specs, putting them in the vector. */
1494 char *in, *out, *p1, *p2, *p3;
1496 /* Advance P in BUFFER to the next nonblank nocomment line. */
1497 p = skip_whitespace (p);
1501 /* Is this a special command that starts with '%'? */
1502 /* Don't allow this for the main specs file, since it would
1503 encourage people to overwrite it. */
1504 if (*p == '%' && !main_p)
1507 while (*p && *p != '\n')
1510 p++; /* Skip '\n' */
1512 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1513 && (p1[sizeof "%include" - 1] == ' '
1514 || p1[sizeof "%include" - 1] == '\t'))
1518 p1 += sizeof ("%include");
1519 while (*p1 == ' ' || *p1 == '\t')
1522 if (*p1++ != '<' || p[-2] != '>')
1523 fatal ("specs %%include syntax malformed after %ld characters",
1524 (long) (p1 - buffer + 1));
1527 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1528 read_specs (new_filename ? new_filename : p1, FALSE);
1531 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1532 && (p1[sizeof "%include_noerr" - 1] == ' '
1533 || p1[sizeof "%include_noerr" - 1] == '\t'))
1537 p1 += sizeof "%include_noerr";
1538 while (*p1 == ' ' || *p1 == '\t') p1++;
1540 if (*p1++ != '<' || p[-2] != '>')
1541 fatal ("specs %%include syntax malformed after %ld characters",
1542 (long) (p1 - buffer + 1));
1545 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1547 read_specs (new_filename, FALSE);
1548 else if (verbose_flag)
1549 notice ("Could not find specs file %s\n", p1);
1552 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1553 && (p1[sizeof "%rename" - 1] == ' '
1554 || p1[sizeof "%rename" - 1] == '\t'))
1557 struct spec_list *sl;
1559 /* Get original name */
1560 p1 += sizeof "%rename";
1561 while (*p1 == ' ' || *p1 == '\t')
1564 if (! ISALPHA ((unsigned char)*p1))
1565 fatal ("specs %%rename syntax malformed after %ld characters",
1566 (long) (p1 - buffer));
1569 while (*p2 && !ISSPACE ((unsigned char)*p2))
1572 if (*p2 != ' ' && *p2 != '\t')
1573 fatal ("specs %%rename syntax malformed after %ld characters",
1574 (long) (p2 - buffer));
1578 while (*p2 == ' ' || *p2 == '\t')
1581 if (! ISALPHA ((unsigned char)*p2))
1582 fatal ("specs %%rename syntax malformed after %ld characters",
1583 (long) (p2 - buffer));
1585 /* Get new spec name */
1587 while (*p3 && !ISSPACE ((unsigned char)*p3))
1591 fatal ("specs %%rename syntax malformed after %ld characters",
1592 (long) (p3 - buffer));
1595 for (sl = specs; sl; sl = sl->next)
1596 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1600 fatal ("specs %s spec was not found to be renamed", p1);
1602 if (strcmp (p1, p2) == 0)
1607 notice ("rename spec %s to %s\n", p1, p2);
1609 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1613 set_spec (p2, *(sl->ptr_spec));
1615 free (*(sl->ptr_spec));
1617 *(sl->ptr_spec) = "";
1622 fatal ("specs unknown %% command after %ld characters",
1623 (long) (p1 - buffer));
1626 /* Find the colon that should end the suffix. */
1628 while (*p1 && *p1 != ':' && *p1 != '\n')
1631 /* The colon shouldn't be missing. */
1633 fatal ("specs file malformed after %ld characters",
1634 (long) (p1 - buffer));
1636 /* Skip back over trailing whitespace. */
1638 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1641 /* Copy the suffix to a string. */
1642 suffix = save_string (p, p2 - p);
1643 /* Find the next line. */
1644 p = skip_whitespace (p1 + 1);
1646 fatal ("specs file malformed after %ld characters",
1647 (long) (p - buffer));
1650 /* Find next blank line or end of string. */
1651 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1654 /* Specs end at the blank line and do not include the newline. */
1655 spec = save_string (p, p1 - p);
1658 /* Delete backslash-newline sequences from the spec. */
1663 if (in[0] == '\\' && in[1] == '\n')
1665 else if (in[0] == '#')
1666 while (*in && *in != '\n')
1674 if (suffix[0] == '*')
1676 if (! strcmp (suffix, "*link_command"))
1677 link_command_spec = spec;
1679 set_spec (suffix + 1, spec);
1683 /* Add this pair to the vector. */
1685 = ((struct compiler *)
1686 xrealloc (compilers,
1687 (n_compilers + 2) * sizeof (struct compiler)));
1689 compilers[n_compilers].suffix = suffix;
1690 bzero ((char *) compilers[n_compilers].spec,
1691 sizeof compilers[n_compilers].spec);
1692 compilers[n_compilers].spec[0] = spec;
1694 bzero ((char *) &compilers[n_compilers],
1695 sizeof compilers[n_compilers]);
1699 link_command_spec = spec;
1702 if (link_command_spec == 0)
1703 fatal ("spec file has no spec for linking");
1706 /* Record the names of temporary files we tell compilers to write,
1707 and delete them at the end of the run. */
1709 /* This is the common prefix we use to make temp file names.
1710 It is chosen once for each run of this program.
1711 It is substituted into a spec by %g.
1712 Thus, all temp file names contain this prefix.
1713 In practice, all temp file names start with this prefix.
1715 This prefix comes from the envvar TMPDIR if it is defined;
1716 otherwise, from the P_tmpdir macro if that is defined;
1717 otherwise, in /usr/tmp or /tmp;
1718 or finally the current directory if all else fails. */
1720 static const char *temp_filename;
1722 /* Length of the prefix. */
1724 static int temp_filename_length;
1726 /* Define the list of temporary files to delete. */
1731 struct temp_file *next;
1734 /* Queue of files to delete on success or failure of compilation. */
1735 static struct temp_file *always_delete_queue;
1736 /* Queue of files to delete on failure of compilation. */
1737 static struct temp_file *failure_delete_queue;
1739 /* Record FILENAME as a file to be deleted automatically.
1740 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1741 otherwise delete it in any case.
1742 FAIL_DELETE nonzero means delete it if a compilation step fails;
1743 otherwise delete it in any case. */
1746 record_temp_file (filename, always_delete, fail_delete)
1747 const char *filename;
1751 register char *name;
1752 name = xmalloc (strlen (filename) + 1);
1753 strcpy (name, filename);
1757 register struct temp_file *temp;
1758 for (temp = always_delete_queue; temp; temp = temp->next)
1759 if (! strcmp (name, temp->name))
1762 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1763 temp->next = always_delete_queue;
1765 always_delete_queue = temp;
1772 register struct temp_file *temp;
1773 for (temp = failure_delete_queue; temp; temp = temp->next)
1774 if (! strcmp (name, temp->name))
1777 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1778 temp->next = failure_delete_queue;
1780 failure_delete_queue = temp;
1786 /* Delete all the temporary files whose names we previously recorded. */
1789 delete_if_ordinary (name)
1796 printf ("Delete %s? (y or n) ", name);
1800 while ((c = getchar ()) != '\n' && c != EOF)
1803 if (i == 'y' || i == 'Y')
1805 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1806 if (unlink (name) < 0)
1808 perror_with_name (name);
1812 delete_temp_files ()
1814 register struct temp_file *temp;
1816 for (temp = always_delete_queue; temp; temp = temp->next)
1817 delete_if_ordinary (temp->name);
1818 always_delete_queue = 0;
1821 /* Delete all the files to be deleted on error. */
1824 delete_failure_queue ()
1826 register struct temp_file *temp;
1828 for (temp = failure_delete_queue; temp; temp = temp->next)
1829 delete_if_ordinary (temp->name);
1833 clear_failure_queue ()
1835 failure_delete_queue = 0;
1838 /* Routine to add variables to the environment. We do this to pass
1839 the pathname of the gcc driver, and the directories search to the
1840 collect2 program, which is being run as ld. This way, we can be
1841 sure of executing the right compiler when collect2 wants to build
1842 constructors and destructors. Since the environment variables we
1843 use come from an obstack, we don't have to worry about allocating
1852 #ifndef VMS /* nor about VMS */
1854 extern char **environ;
1855 char **old_environ = environ;
1859 int str_len = strlen (str);
1863 while ((ch = *p++) != '\0' && ch != '=')
1869 /* Search for replacing an existing environment variable, and
1870 count the number of total environment variables. */
1871 for (envp = old_environ; *envp; envp++)
1874 if (!strncmp (str, *envp, name_len))
1881 /* Add a new environment variable */
1882 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1884 memcpy ((char *) (environ + 1), (char *) old_environ,
1885 sizeof (char *) * (num_envs+1));
1890 #endif /* HAVE_PUTENV */
1893 /* Build a list of search directories from PATHS.
1894 PREFIX is a string to prepend to the list.
1895 If CHECK_DIR_P is non-zero we ensure the directory exists.
1896 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1897 It is also used by the --print-search-dirs flag. */
1900 build_search_list (paths, prefix, check_dir_p)
1901 struct path_prefix *paths;
1905 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1907 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1908 int first_time = TRUE;
1909 struct prefix_list *pprefix;
1911 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1913 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1915 int len = strlen (pprefix->prefix);
1919 || is_directory (pprefix->prefix, machine_suffix, 0)))
1922 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1925 obstack_grow (&collect_obstack, pprefix->prefix, len);
1926 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1929 if (just_machine_suffix
1930 && pprefix->require_machine_suffix == 2
1932 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1935 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1938 obstack_grow (&collect_obstack, pprefix->prefix, len);
1939 obstack_grow (&collect_obstack, just_machine_suffix,
1943 if (! pprefix->require_machine_suffix)
1946 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1949 obstack_grow (&collect_obstack, pprefix->prefix, len);
1953 obstack_1grow (&collect_obstack, '\0');
1954 return obstack_finish (&collect_obstack);
1957 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1961 putenv_from_prefixes (paths, env_var)
1962 struct path_prefix *paths;
1963 const char *env_var;
1965 putenv (build_search_list (paths, env_var, 1));
1968 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1969 access to check permissions.
1970 Return 0 if not found, otherwise return its name, allocated with malloc. */
1973 find_a_file (pprefix, name, mode)
1974 struct path_prefix *pprefix;
1979 const char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1980 struct prefix_list *pl;
1981 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1983 #ifdef DEFAULT_ASSEMBLER
1984 if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
1985 name = DEFAULT_ASSEMBLER;
1986 len = strlen(name)+1;
1987 temp = xmalloc (len);
1988 strcpy (temp, name);
1993 #ifdef DEFAULT_LINKER
1994 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
1995 name = DEFAULT_LINKER;
1996 len = strlen(name)+1;
1997 temp = xmalloc (len);
1998 strcpy (temp, name);
2004 len += strlen (machine_suffix);
2006 temp = xmalloc (len);
2008 /* Determine the filename to execute (special case for absolute paths). */
2010 if (IS_DIR_SEPARATOR (*name)
2011 #ifdef HAVE_DOS_BASED_FILESYSTEM
2012 /* Check for disk name on MS-DOS-based systems. */
2013 || (name[0] && name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2017 if (access (name, mode) == 0)
2019 strcpy (temp, name);
2024 for (pl = pprefix->plist; pl; pl = pl->next)
2028 /* Some systems have a suffix for executable files.
2029 So try appending that first. */
2030 if (file_suffix[0] != 0)
2032 strcpy (temp, pl->prefix);
2033 strcat (temp, machine_suffix);
2034 strcat (temp, name);
2035 strcat (temp, file_suffix);
2036 if (access (temp, mode) == 0)
2038 if (pl->used_flag_ptr != 0)
2039 *pl->used_flag_ptr = 1;
2044 /* Now try just the name. */
2045 strcpy (temp, pl->prefix);
2046 strcat (temp, machine_suffix);
2047 strcat (temp, name);
2048 if (access (temp, mode) == 0)
2050 if (pl->used_flag_ptr != 0)
2051 *pl->used_flag_ptr = 1;
2056 /* Certain prefixes are tried with just the machine type,
2057 not the version. This is used for finding as, ld, etc. */
2058 if (just_machine_suffix && pl->require_machine_suffix == 2)
2060 /* Some systems have a suffix for executable files.
2061 So try appending that first. */
2062 if (file_suffix[0] != 0)
2064 strcpy (temp, pl->prefix);
2065 strcat (temp, just_machine_suffix);
2066 strcat (temp, name);
2067 strcat (temp, file_suffix);
2068 if (access (temp, mode) == 0)
2070 if (pl->used_flag_ptr != 0)
2071 *pl->used_flag_ptr = 1;
2076 strcpy (temp, pl->prefix);
2077 strcat (temp, just_machine_suffix);
2078 strcat (temp, name);
2079 if (access (temp, mode) == 0)
2081 if (pl->used_flag_ptr != 0)
2082 *pl->used_flag_ptr = 1;
2087 /* Certain prefixes can't be used without the machine suffix
2088 when the machine or version is explicitly specified. */
2089 if (! pl->require_machine_suffix)
2091 /* Some systems have a suffix for executable files.
2092 So try appending that first. */
2093 if (file_suffix[0] != 0)
2095 strcpy (temp, pl->prefix);
2096 strcat (temp, name);
2097 strcat (temp, file_suffix);
2098 if (access (temp, mode) == 0)
2100 if (pl->used_flag_ptr != 0)
2101 *pl->used_flag_ptr = 1;
2106 strcpy (temp, pl->prefix);
2107 strcat (temp, name);
2108 if (access (temp, mode) == 0)
2110 if (pl->used_flag_ptr != 0)
2111 *pl->used_flag_ptr = 1;
2121 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2122 at the start of the list, otherwise it goes at the end.
2124 If WARN is nonzero, we will warn if no file is found
2125 through this prefix. WARN should point to an int
2126 which will be set to 1 if this entry is used.
2128 COMPONENT is the value to be passed to update_path.
2130 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2131 the complete value of machine_suffix.
2132 2 means try both machine_suffix and just_machine_suffix. */
2135 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2136 struct path_prefix *pprefix;
2138 const char *component;
2140 int require_machine_suffix;
2143 struct prefix_list *pl, **prev;
2146 if (! first && pprefix->plist)
2148 for (pl = pprefix->plist; pl->next; pl = pl->next)
2153 prev = &pprefix->plist;
2155 /* Keep track of the longest prefix */
2157 prefix = update_path (prefix, component);
2158 len = strlen (prefix);
2159 if (len > pprefix->max_len)
2160 pprefix->max_len = len;
2162 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2163 pl->prefix = save_string (prefix, len);
2164 pl->require_machine_suffix = require_machine_suffix;
2165 pl->used_flag_ptr = warn;
2172 pl->next = (struct prefix_list *) 0;
2176 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2179 unused_prefix_warnings (pprefix)
2180 struct path_prefix *pprefix;
2182 struct prefix_list *pl = pprefix->plist;
2186 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2188 if (pl->require_machine_suffix && machine_suffix)
2189 error ("file path prefix `%s%s' never used", pl->prefix,
2192 error ("file path prefix `%s' never used", pl->prefix);
2194 /* Prevent duplicate warnings. */
2195 *pl->used_flag_ptr = 1;
2203 /* Execute the command specified by the arguments on the current line of spec.
2204 When using pipes, this includes several piped-together commands
2205 with `|' between them.
2207 Return 0 if successful, -1 if failed. */
2213 int n_commands; /* # of command. */
2217 const char *prog; /* program name. */
2218 char **argv; /* vector of args. */
2219 int pid; /* pid of process for this command. */
2222 struct command *commands; /* each command buffer with above info. */
2224 /* Count # of piped commands. */
2225 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2226 if (strcmp (argbuf[i], "|") == 0)
2229 /* Get storage for each command. */
2231 = (struct command *) alloca (n_commands * sizeof (struct command));
2233 /* Split argbuf into its separate piped processes,
2234 and record info about each one.
2235 Also search for the programs that are to be run. */
2237 commands[0].prog = argbuf[0]; /* first command. */
2238 commands[0].argv = &argbuf[0];
2239 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2242 commands[0].argv[0] = string;
2244 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2245 if (strcmp (argbuf[i], "|") == 0)
2246 { /* each command. */
2247 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2248 fatal ("-pipe not supported");
2250 argbuf[i] = 0; /* termination of command args. */
2251 commands[n_commands].prog = argbuf[i + 1];
2252 commands[n_commands].argv = &argbuf[i + 1];
2253 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2255 commands[n_commands].argv[0] = string;
2259 argbuf[argbuf_index] = 0;
2261 /* If -v, print what we are about to do, and maybe query. */
2265 /* For help listings, put a blank line between sub-processes. */
2266 if (print_help_list)
2267 fputc ('\n', stderr);
2269 /* Print each piped command as a separate line. */
2270 for (i = 0; i < n_commands ; i++)
2274 for (j = commands[i].argv; *j; j++)
2275 fprintf (stderr, " %s", *j);
2277 /* Print a pipe symbol after all but the last command. */
2278 if (i + 1 != n_commands)
2279 fprintf (stderr, " |");
2280 fprintf (stderr, "\n");
2284 notice ("\nGo ahead? (y or n) ");
2288 while (getchar () != '\n')
2291 if (i != 'y' && i != 'Y')
2296 /* Run each piped subprocess. */
2298 for (i = 0; i < n_commands; i++)
2300 char *errmsg_fmt, *errmsg_arg;
2301 char *string = commands[i].argv[0];
2303 commands[i].pid = pexecute (string, commands[i].argv,
2304 programname, temp_filename,
2305 &errmsg_fmt, &errmsg_arg,
2306 ((i == 0 ? PEXECUTE_FIRST : 0)
2307 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2308 | (string == commands[i].prog
2309 ? PEXECUTE_SEARCH : 0)
2310 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2312 if (commands[i].pid == -1)
2313 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2315 if (string != commands[i].prog)
2321 /* Wait for all the subprocesses to finish.
2322 We don't care what order they finish in;
2323 we know that N_COMMANDS waits will get them all.
2324 Ignore subprocesses that we don't know about,
2325 since they can be spawned by the process that exec'ed us. */
2330 for (i = 0; i < n_commands; )
2336 pid = pwait (commands[i].pid, &status, 0);
2340 for (j = 0; j < n_commands; j++)
2341 if (commands[j].pid == pid)
2346 if (WIFSIGNALED (status))
2348 fatal ("Internal compiler error: program %s got fatal signal %d",
2349 commands[j].prog, WTERMSIG (status));
2353 else if (WIFEXITED (status)
2354 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2364 /* Find all the switches given to us
2365 and make a vector describing them.
2366 The elements of the vector are strings, one per switch given.
2367 If a switch uses following arguments, then the `part1' field
2368 is the switch itself and the `args' field
2369 is a null-terminated vector containing the following arguments.
2370 The `live_cond' field is 1 if the switch is true in a conditional spec,
2371 -1 if false (overridden by a later switch), and is initialized to zero.
2372 The `validated' field is nonzero if any spec has looked at this switch;
2373 if it remains zero at the end of the run, it must be meaningless. */
2383 static struct switchstr *switches;
2385 static int n_switches;
2390 const char *language;
2393 /* Also a vector of input files specified. */
2395 static struct infile *infiles;
2397 static int n_infiles;
2399 /* This counts the number of libraries added by lang_specific_driver, so that
2400 we can tell if there were any user supplied any files or libraries. */
2402 static int added_libraries;
2404 /* And a vector of corresponding output files is made up later. */
2406 static const char **outfiles;
2408 /* Used to track if none of the -B paths are used. */
2411 /* Used to track if standard path isn't used and -b or -V is specified. */
2412 static int warn_std;
2414 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2415 static int *warn_std_ptr = 0;
2417 #if defined(FREEBSD_NATIVE)
2418 #include <objformat.h>
2420 typedef enum { OBJFMT_UNKNOWN, OBJFMT_AOUT, OBJFMT_ELF } objf_t;
2422 static objf_t objformat = OBJFMT_UNKNOWN;
2423 #endif /* FREEBSD_NATIVE */
2425 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2427 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2428 is true if we should look for an executable suffix as well. */
2431 convert_filename (name, do_exe)
2441 len = strlen (name);
2443 #ifdef HAVE_OBJECT_SUFFIX
2444 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2446 && name[len - 2] == '.'
2447 && name[len - 1] == 'o')
2449 obstack_grow (&obstack, name, len - 2);
2450 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2451 name = obstack_finish (&obstack);
2455 #ifdef HAVE_EXECUTABLE_SUFFIX
2456 /* If there is no filetype, make it the executable suffix (which includes
2457 the "."). But don't get confused if we have just "-o". */
2458 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2461 for (i = len - 1; i >= 0; i--)
2462 if (IS_DIR_SEPARATOR (name[i]))
2465 for (i++; i < len; i++)
2469 obstack_grow (&obstack, name, len);
2470 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2471 name = obstack_finish (&obstack);
2478 /* Display the command line switches accepted by gcc. */
2482 printf ("Usage: %s [options] file...\n", programname);
2483 printf ("Options:\n");
2485 printf (" --help Display this information\n");
2487 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2488 printf (" -dumpspecs Display all of the built in spec strings\n");
2489 printf (" -dumpversion Display the version of the compiler\n");
2490 printf (" -dumpmachine Display the compiler's target processor\n");
2491 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2492 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2493 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2494 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2495 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2496 printf (" -print-multi-lib Display the mapping between command line options and\n");
2497 printf (" multiple library search directories\n");
2498 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2499 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2500 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2501 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2502 printf (" -save-temps Do not delete intermediate files\n");
2503 printf (" -pipe Use pipes rather than intermediate files\n");
2504 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2505 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2506 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2507 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2508 printf (" -V <version> Run gcc version number <version>, if installed\n");
2509 printf (" -v Display the programs invoked by the compiler\n");
2510 printf (" -E Preprocess only; do not compile, assemble or link\n");
2511 printf (" -S Compile only; do not assemble or link\n");
2512 printf (" -c Compile and assemble, but do not link\n");
2513 printf (" -o <file> Place the output into <file>\n");
2514 printf (" -x <language> Specify the language of the following input files\n");
2515 printf (" Permissable languages include: c c++ assembler none\n");
2516 printf (" 'none' means revert to the default behaviour of\n");
2517 printf (" guessing the language based on the file's extension\n");
2519 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2520 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2522 printf ("on to these processes the -W<letter> options must be used.\n");
2524 /* The rest of the options are displayed by invocations of the various
2529 add_preprocessor_option (option, len)
2530 const char * option;
2533 n_preprocessor_options++;
2535 if (! preprocessor_options)
2536 preprocessor_options
2537 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
2539 preprocessor_options
2540 = (char **) xrealloc (preprocessor_options,
2541 n_preprocessor_options * sizeof (char *));
2543 preprocessor_options [n_preprocessor_options - 1] =
2544 save_string (option, len);
2548 add_assembler_option (option, len)
2549 const char * option;
2552 n_assembler_options++;
2554 if (! assembler_options)
2556 = (char **) xmalloc (n_assembler_options * sizeof (char *));
2559 = (char **) xrealloc (assembler_options,
2560 n_assembler_options * sizeof (char *));
2562 assembler_options [n_assembler_options - 1] = save_string (option, len);
2566 add_linker_option (option, len)
2567 const char * option;
2572 if (! linker_options)
2574 = (char **) xmalloc (n_linker_options * sizeof (char *));
2577 = (char **) xrealloc (linker_options,
2578 n_linker_options * sizeof (char *));
2580 linker_options [n_linker_options - 1] = save_string (option, len);
2583 /* Create the vector `switches' and its contents.
2584 Store its length in `n_switches'. */
2587 process_command (argc, argv)
2594 char *spec_lang = 0;
2595 int last_language_n_infiles;
2598 int lang_n_infiles = 0;
2600 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2604 added_libraries = 0;
2606 /* Figure compiler version from version string. */
2608 compiler_version = temp1 =
2609 save_string (version_string, strlen (version_string));
2610 for (; *temp1; ++temp1)
2619 /* Set up the default search paths. */
2621 if (gcc_exec_prefix)
2623 int len = strlen (gcc_exec_prefix);
2624 if (len > (int) sizeof ("/lib/gcc-lib/")-1
2625 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
2627 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2628 if (IS_DIR_SEPARATOR (*temp)
2629 && strncmp (temp+1, "lib", 3) == 0
2630 && IS_DIR_SEPARATOR (temp[4])
2631 && strncmp (temp+5, "gcc-lib", 7) == 0)
2632 len -= sizeof ("/lib/gcc-lib/") - 1;
2635 set_std_prefix (gcc_exec_prefix, len);
2636 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2637 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2640 /* COMPILER_PATH and LIBRARY_PATH have values
2641 that are lists of directory names with colons. */
2643 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
2646 const char *startp, *endp;
2647 char *nstore = (char *) alloca (strlen (temp) + 3);
2649 startp = endp = temp;
2652 if (*endp == PATH_SEPARATOR || *endp == 0)
2654 strncpy (nstore, startp, endp-startp);
2656 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2657 else if (!IS_DIR_SEPARATOR (endp[-1]))
2659 nstore[endp-startp] = DIR_SEPARATOR;
2660 nstore[endp-startp+1] = 0;
2663 nstore[endp-startp] = 0;
2664 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2665 add_prefix (&include_prefixes,
2666 concat (nstore, "include", NULL_PTR),
2670 endp = startp = endp + 1;
2677 GET_ENV_PATH_LIST (temp, "LIBRARY_PATH");
2678 if (temp && *cross_compile == '0')
2680 const char *startp, *endp;
2681 char *nstore = (char *) alloca (strlen (temp) + 3);
2683 startp = endp = temp;
2686 if (*endp == PATH_SEPARATOR || *endp == 0)
2688 strncpy (nstore, startp, endp-startp);
2690 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2691 else if (!IS_DIR_SEPARATOR (endp[-1]))
2693 nstore[endp-startp] = DIR_SEPARATOR;
2694 nstore[endp-startp+1] = 0;
2697 nstore[endp-startp] = 0;
2698 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2702 endp = startp = endp + 1;
2709 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2710 GET_ENV_PATH_LIST (temp, "LPATH");
2711 if (temp && *cross_compile == '0')
2713 const char *startp, *endp;
2714 char *nstore = (char *) alloca (strlen (temp) + 3);
2716 startp = endp = temp;
2719 if (*endp == PATH_SEPARATOR || *endp == 0)
2721 strncpy (nstore, startp, endp-startp);
2723 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2724 else if (!IS_DIR_SEPARATOR (endp[-1]))
2726 nstore[endp-startp] = DIR_SEPARATOR;
2727 nstore[endp-startp+1] = 0;
2730 nstore[endp-startp] = 0;
2731 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2735 endp = startp = endp + 1;
2742 #if defined(FREEBSD_NATIVE)
2745 if (getobjformat (buf, sizeof buf, &argc, argv))
2746 if (strcmp (buf, "aout") == 0)
2747 objformat = OBJFMT_AOUT;
2748 else if (strcmp (buf, "elf") == 0)
2749 objformat = OBJFMT_ELF;
2751 fprintf(stderr, "Unrecognized object format: %s\n", buf);
2753 #endif /* FREEBSD_NATIVE */
2755 /* Options specified as if they appeared on the command line. */
2756 temp = getenv ("GCC_OPTIONS");
2757 if ((temp) && (strlen (temp) > 0))
2765 while (isspace (*temp))
2767 len = strlen (temp);
2768 envopts = (char *) xmalloc (len + 1);
2769 strcpy (envopts, temp);
2771 for (i = 0; i < (len - 1); i++)
2772 if ((isspace (envopts[i])) && ! (isspace (envopts[i+1])))
2775 new_argv = (char **) alloca ((optc + argc) * sizeof(char *));
2777 for (i = 0, new_argc = 1; new_argc <= optc; new_argc++)
2779 while (isspace (envopts[i]))
2781 new_argv[new_argc] = envopts + i;
2782 while (!isspace (envopts[i]) && (envopts[i] != '\0'))
2784 envopts[i++] = '\0';
2786 for (i = 1; i < argc; i++)
2787 new_argv[new_argc++] = argv[i];
2793 /* Convert new-style -- options to old-style. */
2794 translate_options (&argc, &argv);
2796 /* Do language-specific adjustment/addition of flags. */
2797 lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2799 /* Scan argv twice. Here, the first time, just count how many switches
2800 there will be in their vector, and how many input files in theirs.
2801 Here we also parse the switches that cc itself uses (e.g. -v). */
2803 for (i = 1; i < argc; i++)
2805 if (! strcmp (argv[i], "-dumpspecs"))
2807 struct spec_list *sl;
2809 for (sl = specs; sl; sl = sl->next)
2810 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2811 if (link_command_spec)
2812 printf ("*link_command:\n%s\n\n", link_command_spec);
2815 else if (! strcmp (argv[i], "-dumpversion"))
2817 printf ("%s\n", spec_version);
2820 else if (! strcmp (argv[i], "-dumpmachine"))
2822 printf ("%s\n", spec_machine);
2825 else if (strcmp (argv[i], "-fhelp") == 0)
2827 /* translate_options () has turned --help into -fhelp. */
2828 print_help_list = 1;
2830 /* We will be passing a dummy file on to the sub-processes. */
2834 add_preprocessor_option ("--help", 6);
2835 add_assembler_option ("--help", 6);
2836 add_linker_option ("--help", 6);
2838 else if (! strcmp (argv[i], "-print-search-dirs"))
2839 print_search_dirs = 1;
2840 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2841 print_file_name = "libgcc.a";
2842 else if (! strncmp (argv[i], "-print-file-name=", 17))
2843 print_file_name = argv[i] + 17;
2844 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2845 print_prog_name = argv[i] + 17;
2846 else if (! strcmp (argv[i], "-print-multi-lib"))
2847 print_multi_lib = 1;
2848 else if (! strcmp (argv[i], "-print-multi-directory"))
2849 print_multi_directory = 1;
2850 else if (! strncmp (argv[i], "-Wa,", 4))
2853 /* Pass the rest of this option to the assembler. */
2855 /* Split the argument at commas. */
2857 for (j = 4; argv[i][j]; j++)
2858 if (argv[i][j] == ',')
2860 add_assembler_option (argv[i] + prev, j - prev);
2864 /* Record the part after the last comma. */
2865 add_assembler_option (argv[i] + prev, j - prev);
2867 else if (! strncmp (argv[i], "-Wp,", 4))
2870 /* Pass the rest of this option to the preprocessor. */
2872 /* Split the argument at commas. */
2874 for (j = 4; argv[i][j]; j++)
2875 if (argv[i][j] == ',')
2877 add_preprocessor_option (argv[i] + prev, j - prev);
2881 /* Record the part after the last comma. */
2882 add_preprocessor_option (argv[i] + prev, j - prev);
2884 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2885 /* The +e options to the C++ front-end. */
2887 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2890 /* Split the argument at commas. */
2891 for (j = 3; argv[i][j]; j++)
2892 n_infiles += (argv[i][j] == ',');
2894 else if (strcmp (argv[i], "-Xlinker") == 0)
2897 fatal ("argument to `-Xlinker' is missing");
2902 else if (strcmp (argv[i], "-l") == 0)
2905 fatal ("argument to `-l' is missing");
2910 else if (strncmp (argv[i], "-l", 2) == 0)
2912 else if (strcmp (argv[i], "-save-temps") == 0)
2914 save_temps_flag = 1;
2917 else if (strcmp (argv[i], "-specs") == 0)
2919 struct user_specs *user = (struct user_specs *)
2920 xmalloc (sizeof (struct user_specs));
2922 fatal ("argument to `-specs' is missing");
2924 user->next = (struct user_specs *)0;
2925 user->filename = argv[i];
2926 if (user_specs_tail)
2927 user_specs_tail->next = user;
2929 user_specs_head = user;
2930 user_specs_tail = user;
2932 else if (strncmp (argv[i], "-specs=", 7) == 0)
2934 struct user_specs *user = (struct user_specs *)
2935 xmalloc (sizeof (struct user_specs));
2936 if (strlen (argv[i]) == 7)
2937 fatal ("argument to `-specs=' is missing");
2939 user->next = (struct user_specs *)0;
2940 user->filename = argv[i]+7;
2941 if (user_specs_tail)
2942 user_specs_tail->next = user;
2944 user_specs_head = user;
2945 user_specs_tail = user;
2947 else if (argv[i][0] == '-' && argv[i][1] != 0)
2949 register char *p = &argv[i][1];
2950 register int c = *p;
2956 if (p[1] == 0 && i + 1 == argc)
2957 fatal ("argument to `-b' is missing");
2959 spec_machine = argv[++i];
2961 spec_machine = p + 1;
2963 warn_std_ptr = &warn_std;
2969 if (p[1] == 0 && i + 1 == argc)
2970 fatal ("argument to `-B' is missing");
2975 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2976 add_prefix (&startfile_prefixes, value, NULL_PTR,
2978 add_prefix (&include_prefixes, concat (value, "include",
2980 NULL_PTR, 1, 0, NULL_PTR);
2982 /* As a kludge, if the arg is "[foo/]stageN/", just add
2983 "[foo/]include" to the include prefix. */
2985 int len = strlen (value);
2988 && (IS_DIR_SEPARATOR (value[len - 8]))))
2989 && strncmp (value + len - 7, "stage", 5) == 0
2990 && ISDIGIT (value[len - 2])
2991 && (IS_DIR_SEPARATOR (value[len - 1])))
2994 add_prefix (&include_prefixes, "include", NULL_PTR,
2998 char *string = xmalloc (len + 1);
2999 strncpy (string, value, len-7);
3000 strcpy (string+len-7, "include");
3001 add_prefix (&include_prefixes, string, NULL_PTR,
3010 case 'v': /* Print our subcommands and print versions. */
3012 /* If they do anything other than exactly `-v', don't set
3013 verbose_flag; rather, continue on to give the error. */
3021 if (p[1] == 0 && i + 1 == argc)
3022 fatal ("argument to `-V' is missing");
3024 spec_version = argv[++i];
3026 spec_version = p + 1;
3027 compiler_version = spec_version;
3028 warn_std_ptr = &warn_std;
3030 /* Validate the version number. Use the same checks
3031 done when inserting it into a spec.
3033 The format of the version string is
3034 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3036 const char *v = compiler_version;
3038 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3039 while (! ISDIGIT (*v))
3042 if (v > compiler_version && v[-1] != '-')
3043 fatal ("invalid version number format");
3045 /* Set V after the first period. */
3046 while (ISDIGIT (*v))
3050 fatal ("invalid version number format");
3053 while (ISDIGIT (*v))
3056 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
3057 fatal ("invalid version number format");
3073 #if defined(HAVE_EXECUTABLE_SUFFIX)
3078 /* Forward scan, just in case -S or -c is specified
3085 if (argv[j][0] == '-')
3087 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3093 else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
3094 j += skip - (argv[j][2] != 0);
3095 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
3102 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3104 argv[i+1] = convert_filename (argv[i+1], ! have_c);
3106 argv[i] = convert_filename (argv[i], ! have_c);
3114 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3115 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3116 else if (WORD_SWITCH_TAKES_ARG (p))
3117 i += WORD_SWITCH_TAKES_ARG (p);
3127 if (have_c && have_o && lang_n_infiles > 1)
3128 fatal ("cannot specify -o with -c or -S and multiple compilations");
3130 /* Set up the search paths before we go looking for config files. */
3132 /* These come before the md prefixes so that we will find gcc's subcommands
3133 (such as cpp) rather than those of the host system. */
3134 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3135 as well as trying the machine and the version. */
3136 #ifdef FREEBSD_NATIVE
3137 add_prefix (&exec_prefixes, PREFIX"/libexec/" BINUTILS "/", "BINUTILS",
3142 n_switches++; /* add implied -maout */
3143 add_prefix (&exec_prefixes, PREFIX"/libexec/" BINUTILS "/aout/", "BINUTILS",
3147 add_prefix (&exec_prefixes, PREFIX"/libexec/" BINUTILS "/elf/", "BINUTILS",
3150 case OBJFMT_UNKNOWN:
3151 fatal ("object format unknown");
3153 #endif /* FREEBSD_NATIVE */
3156 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3157 0, 2, warn_std_ptr);
3158 #ifndef FREEBSD_NATIVE
3159 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3160 0, 2, warn_std_ptr);
3161 #endif /* not FREEBSD_NATIVE */
3164 #ifndef FREEBSD_NATIVE
3165 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3166 0, 1, warn_std_ptr);
3167 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3168 0, 1, warn_std_ptr);
3169 #endif /* not FREEBSD_NATIVE */
3171 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3172 dir_separator_str, NULL_PTR);
3174 /* If tooldir is relative, base it on exec_prefixes. A relative
3175 tooldir lets us move the installed tree as a unit.
3177 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3178 directories, so that we can search both the user specified directory
3179 and the standard place. */
3181 if (!IS_DIR_SEPARATOR (*tooldir_prefix))
3183 if (gcc_exec_prefix)
3185 char *gcc_exec_tooldir_prefix
3186 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3187 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
3189 add_prefix (&exec_prefixes,
3190 concat (gcc_exec_tooldir_prefix, "bin",
3191 dir_separator_str, NULL_PTR),
3192 NULL_PTR, 0, 0, NULL_PTR);
3193 add_prefix (&startfile_prefixes,
3194 concat (gcc_exec_tooldir_prefix, "lib",
3195 dir_separator_str, NULL_PTR),
3196 NULL_PTR, 0, 0, NULL_PTR);
3199 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3200 dir_separator_str, spec_version,
3201 dir_separator_str, tooldir_prefix, NULL_PTR);
3204 #ifndef FREEBSD_NATIVE
3205 add_prefix (&exec_prefixes,
3206 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
3207 "BINUTILS", 0, 0, NULL_PTR);
3208 add_prefix (&startfile_prefixes,
3209 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
3210 "BINUTILS", 0, 0, NULL_PTR);
3211 #endif /* not FREEBSD_NATIVE */
3213 /* More prefixes are enabled in main, after we read the specs file
3214 and determine whether this is cross-compilation or not. */
3217 /* Then create the space for the vectors and scan again. */
3219 switches = ((struct switchstr *)
3220 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3221 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3224 last_language_n_infiles = -1;
3226 /* This, time, copy the text of each switch and store a pointer
3227 to the copy in the vector of switches.
3228 Store all the infiles in their vector. */
3230 #if defined(FREEBSD_NATIVE)
3234 switches[n_switches].part1 = "maout";
3235 switches[n_switches].args = 0;
3236 switches[n_switches].live_cond = 0;
3237 switches[n_switches].validated = 0;
3239 putenv("OBJFORMAT=aout");
3242 putenv("OBJFORMAT=elf");
3244 case OBJFMT_UNKNOWN:
3245 fatal ("object format unknown");
3247 #endif /* FREEBSD_NATIVE */
3249 for (i = 1; i < argc; i++)
3251 /* Just skip the switches that were handled by the preceding loop. */
3252 if (! strncmp (argv[i], "-Wa,", 4))
3254 else if (! strncmp (argv[i], "-Wp,", 4))
3256 else if (! strcmp (argv[i], "-print-search-dirs"))
3258 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3260 else if (! strncmp (argv[i], "-print-file-name=", 17))
3262 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3264 else if (! strcmp (argv[i], "-print-multi-lib"))
3266 else if (! strcmp (argv[i], "-print-multi-directory"))
3268 else if (strcmp (argv[i], "-fhelp") == 0)
3272 /* Create a dummy input file, so that we can pass --help on to
3273 the various sub-processes. */
3274 infiles[n_infiles].language = "c";
3275 infiles[n_infiles++].name = "help-dummy";
3277 /* Preserve the --help switch so that it can be caught by the
3279 switches[n_switches].part1 = "--help";
3280 switches[n_switches].args = 0;
3281 switches[n_switches].live_cond = 0;
3282 switches[n_switches].validated = 0;
3287 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3289 /* Compensate for the +e options to the C++ front-end;
3290 they're there simply for cfront call-compatibility. We do
3291 some magic in default_compilers to pass them down properly.
3292 Note we deliberately start at the `+' here, to avoid passing
3293 -e0 or -e1 down into the linker. */
3294 switches[n_switches].part1 = &argv[i][0];
3295 switches[n_switches].args = 0;
3296 switches[n_switches].live_cond = 0;
3297 switches[n_switches].validated = 0;
3300 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3303 /* Split the argument at commas. */
3305 for (j = 4; argv[i][j]; j++)
3306 if (argv[i][j] == ',')
3308 infiles[n_infiles].language = "*";
3309 infiles[n_infiles++].name
3310 = save_string (argv[i] + prev, j - prev);
3313 /* Record the part after the last comma. */
3314 infiles[n_infiles].language = "*";
3315 infiles[n_infiles++].name = argv[i] + prev;
3317 else if (strcmp (argv[i], "-Xlinker") == 0)
3319 infiles[n_infiles].language = "*";
3320 infiles[n_infiles++].name = argv[++i];
3322 else if (strcmp (argv[i], "-l") == 0)
3323 { /* POSIX allows separation of -l and the lib arg;
3324 canonicalize by concatenating -l with its arg */
3325 infiles[n_infiles].language = "*";
3326 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
3328 else if (strncmp (argv[i], "-l", 2) == 0)
3330 infiles[n_infiles].language = "*";
3331 infiles[n_infiles++].name = argv[i];
3333 else if (strcmp (argv[i], "-specs") == 0)
3335 else if (strncmp (argv[i], "-specs=", 7) == 0)
3337 /* -save-temps overrides -pipe, so that temp files are produced */
3338 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
3339 error ("Warning: -pipe ignored since -save-temps specified");
3340 else if (argv[i][0] == '-' && argv[i][1] != 0)
3342 register char *p = &argv[i][1];
3343 register int c = *p;
3347 if (p[1] == 0 && i + 1 == argc)
3348 fatal ("argument to `-x' is missing");
3350 spec_lang = argv[++i];
3353 if (! strcmp (spec_lang, "none"))
3354 /* Suppress the warning if -xnone comes after the last input
3355 file, because alternate command interfaces like g++ might
3356 find it useful to place -xnone after each input file. */
3359 last_language_n_infiles = n_infiles;
3362 switches[n_switches].part1 = p;
3363 /* Deal with option arguments in separate argv elements. */
3364 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3365 || WORD_SWITCH_TAKES_ARG (p))
3368 int n_args = WORD_SWITCH_TAKES_ARG (p);
3372 /* Count only the option arguments in separate argv elements. */
3373 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3375 if (i + n_args >= argc)
3376 fatal ("argument to `-%s' is missing", p);
3377 switches[n_switches].args
3378 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3380 switches[n_switches].args[j++] = argv[++i];
3381 /* Null-terminate the vector. */
3382 switches[n_switches].args[j] = 0;
3384 else if (index (switches_need_spaces, c))
3386 /* On some systems, ld cannot handle some options without
3387 a space. So split the option from its argument. */
3388 char *part1 = (char *) xmalloc (2);
3392 switches[n_switches].part1 = part1;
3393 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3394 switches[n_switches].args[0] = xmalloc (strlen (p));
3395 strcpy (switches[n_switches].args[0], &p[1]);
3396 switches[n_switches].args[1] = 0;
3399 switches[n_switches].args = 0;
3401 switches[n_switches].live_cond = 0;
3402 switches[n_switches].validated = 0;
3403 /* This is always valid, since gcc.c itself understands it. */
3404 if (!strcmp (p, "save-temps"))
3405 switches[n_switches].validated = 1;
3408 char ch = switches[n_switches].part1[0];
3409 if (ch == 'V' || ch == 'b' || ch == 'B')
3410 switches[n_switches].validated = 1;
3416 #ifdef HAVE_OBJECT_SUFFIX
3417 argv[i] = convert_filename (argv[i], 0);
3420 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3422 perror_with_name (argv[i]);
3427 infiles[n_infiles].language = spec_lang;
3428 infiles[n_infiles++].name = argv[i];
3433 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3434 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3436 switches[n_switches].part1 = 0;
3437 infiles[n_infiles].name = 0;
3440 /* Process a spec string, accumulating and running commands. */
3442 /* These variables describe the input file name.
3443 input_file_number is the index on outfiles of this file,
3444 so that the output file name can be stored for later use by %o.
3445 input_basename is the start of the part of the input file
3446 sans all directory names, and basename_length is the number
3447 of characters starting there excluding the suffix .c or whatever. */
3449 const char *input_filename;
3450 static int input_file_number;
3451 size_t input_filename_length;
3452 static int basename_length;
3453 static const char *input_basename;
3454 static const char *input_suffix;
3456 /* These are variables used within do_spec and do_spec_1. */
3458 /* Nonzero if an arg has been started and not yet terminated
3459 (with space, tab or newline). */
3460 static int arg_going;
3462 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3463 is a temporary file name. */
3464 static int delete_this_arg;
3466 /* Nonzero means %w has been seen; the next arg to be terminated
3467 is the output file name of this compilation. */
3468 static int this_is_output_file;
3470 /* Nonzero means %s has been seen; the next arg to be terminated
3471 is the name of a library file and we should try the standard
3472 search dirs for it. */
3473 static int this_is_library_file;
3475 /* Nonzero means that the input of this command is coming from a pipe. */
3476 static int input_from_pipe;
3478 /* Process the spec SPEC and run the commands specified therein.
3479 Returns 0 if the spec is successfully processed; -1 if failed. */
3489 delete_this_arg = 0;
3490 this_is_output_file = 0;
3491 this_is_library_file = 0;
3492 input_from_pipe = 0;
3494 value = do_spec_1 (spec, 0, NULL_PTR);
3496 /* Force out any unfinished command.
3497 If -pipe, this forces out the last command if it ended in `|'. */
3500 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3503 if (argbuf_index > 0)
3510 /* Process the sub-spec SPEC as a portion of a larger spec.
3511 This is like processing a whole spec except that we do
3512 not initialize at the beginning and we do not supply a
3513 newline by default at the end.
3514 INSWITCH nonzero means don't process %-sequences in SPEC;
3515 in this case, % is treated as an ordinary character.
3516 This is used while substituting switches.
3517 INSWITCH nonzero also causes SPC not to terminate an argument.
3519 Value is zero unless a line was finished
3520 and the command on that line reported an error. */
3523 do_spec_1 (spec, inswitch, soft_matched_part)
3526 const char *soft_matched_part;
3528 register const char *p = spec;
3535 /* If substituting a switch, treat all chars like letters.
3536 Otherwise, NL, SPC, TAB and % are special. */
3537 switch (inswitch ? 'a' : c)
3540 /* End of line: finish any pending argument,
3541 then run the pending command if one has been started. */
3544 obstack_1grow (&obstack, 0);
3545 string = obstack_finish (&obstack);
3546 if (this_is_library_file)
3547 string = find_file (string);
3548 store_arg (string, delete_this_arg, this_is_output_file);
3549 if (this_is_output_file)
3550 outfiles[input_file_number] = string;
3554 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3556 for (i = 0; i < n_switches; i++)
3557 if (!strcmp (switches[i].part1, "pipe"))
3560 /* A `|' before the newline means use a pipe here,
3561 but only if -pipe was specified.
3562 Otherwise, execute now and don't pass the `|' as an arg. */
3565 input_from_pipe = 1;
3566 switches[i].validated = 1;
3573 if (argbuf_index > 0)
3579 /* Reinitialize for a new command, and for a new argument. */
3582 delete_this_arg = 0;
3583 this_is_output_file = 0;
3584 this_is_library_file = 0;
3585 input_from_pipe = 0;
3589 /* End any pending argument. */
3592 obstack_1grow (&obstack, 0);
3593 string = obstack_finish (&obstack);
3594 if (this_is_library_file)
3595 string = find_file (string);
3596 store_arg (string, delete_this_arg, this_is_output_file);
3597 if (this_is_output_file)
3598 outfiles[input_file_number] = string;
3602 obstack_1grow (&obstack, c);
3608 /* Space or tab ends an argument if one is pending. */
3611 obstack_1grow (&obstack, 0);
3612 string = obstack_finish (&obstack);
3613 if (this_is_library_file)
3614 string = find_file (string);
3615 store_arg (string, delete_this_arg, this_is_output_file);
3616 if (this_is_output_file)
3617 outfiles[input_file_number] = string;
3619 /* Reinitialize for a new argument. */
3621 delete_this_arg = 0;
3622 this_is_output_file = 0;
3623 this_is_library_file = 0;
3630 fatal ("Invalid specification! Bug in cc.");
3633 obstack_grow (&obstack, input_basename, basename_length);
3638 delete_this_arg = 2;
3641 /* Dump out the directories specified with LIBRARY_PATH,
3642 followed by the absolute directories
3643 that we search for startfiles. */
3646 struct prefix_list *pl = startfile_prefixes.plist;
3647 size_t bufsize = 100;
3648 char *buffer = (char *) xmalloc (bufsize);
3651 for (; pl; pl = pl->next)
3653 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3654 /* Used on systems which record the specified -L dirs
3655 and use them to search for dynamic linking. */
3656 /* Relative directories always come from -B,
3657 and it is better not to use them for searching
3658 at run time. In particular, stage1 loses */
3659 if (!IS_DIR_SEPARATOR (pl->prefix[0]))
3662 /* Try subdirectory if there is one. */
3663 if (multilib_dir != NULL)
3667 if (strlen (pl->prefix) + strlen (machine_suffix)
3669 bufsize = (strlen (pl->prefix)
3670 + strlen (machine_suffix)) * 2 + 1;
3671 buffer = (char *) xrealloc (buffer, bufsize);
3672 strcpy (buffer, pl->prefix);
3673 strcat (buffer, machine_suffix);
3674 if (is_directory (buffer, multilib_dir, 1))
3676 do_spec_1 ("-L", 0, NULL_PTR);
3677 #ifdef SPACE_AFTER_L_OPTION
3678 do_spec_1 (" ", 0, NULL_PTR);
3680 do_spec_1 (buffer, 1, NULL_PTR);
3681 do_spec_1 (multilib_dir, 1, NULL_PTR);
3682 /* Make this a separate argument. */
3683 do_spec_1 (" ", 0, NULL_PTR);
3686 if (!pl->require_machine_suffix)
3688 if (is_directory (pl->prefix, multilib_dir, 1))
3690 do_spec_1 ("-L", 0, NULL_PTR);
3691 #ifdef SPACE_AFTER_L_OPTION
3692 do_spec_1 (" ", 0, NULL_PTR);
3694 do_spec_1 (pl->prefix, 1, NULL_PTR);
3695 do_spec_1 (multilib_dir, 1, NULL_PTR);
3696 /* Make this a separate argument. */
3697 do_spec_1 (" ", 0, NULL_PTR);
3703 if (is_directory (pl->prefix, machine_suffix, 1))
3705 do_spec_1 ("-L", 0, NULL_PTR);
3706 #ifdef SPACE_AFTER_L_OPTION
3707 do_spec_1 (" ", 0, NULL_PTR);
3709 do_spec_1 (pl->prefix, 1, NULL_PTR);
3710 /* Remove slash from machine_suffix. */
3711 if (strlen (machine_suffix) >= bufsize)
3712 bufsize = strlen (machine_suffix) * 2 + 1;
3713 buffer = (char *) xrealloc (buffer, bufsize);
3714 strcpy (buffer, machine_suffix);
3715 idx = strlen (buffer);
3716 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3717 buffer[idx - 1] = 0;
3718 do_spec_1 (buffer, 1, NULL_PTR);
3719 /* Make this a separate argument. */
3720 do_spec_1 (" ", 0, NULL_PTR);
3723 if (!pl->require_machine_suffix)
3725 if (is_directory (pl->prefix, "", 1))
3727 do_spec_1 ("-L", 0, NULL_PTR);
3728 #ifdef SPACE_AFTER_L_OPTION
3729 do_spec_1 (" ", 0, NULL_PTR);
3731 /* Remove slash from pl->prefix. */
3732 if (strlen (pl->prefix) >= bufsize)
3733 bufsize = strlen (pl->prefix) * 2 + 1;
3734 buffer = (char *) xrealloc (buffer, bufsize);
3735 strcpy (buffer, pl->prefix);
3736 idx = strlen (buffer);
3737 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3738 buffer[idx - 1] = 0;
3739 do_spec_1 (buffer, 1, NULL_PTR);
3740 /* Make this a separate argument. */
3741 do_spec_1 (" ", 0, NULL_PTR);
3750 /* %efoo means report an error with `foo' as error message
3751 and don't execute any more commands for this file. */
3755 while (*p != 0 && *p != '\n') p++;
3756 buf = (char *) alloca (p - q + 1);
3757 strncpy (buf, q, p - q);
3767 if (save_temps_flag)
3769 obstack_grow (&obstack, input_basename, basename_length);
3770 delete_this_arg = 0;
3774 #ifdef MKTEMP_EACH_FILE
3775 /* ??? This has a problem: the total number of
3776 values mktemp can return is limited.
3777 That matters for the names of object files.
3778 In 2.4, do something about that. */
3779 struct temp_name *t;
3781 const char *suffix = p;
3783 if (p[0] == '%' && p[1] == 'O')
3786 /* We don't support extra suffix characters after %O. */
3787 if (*p == '.' || ISALPHA ((unsigned char)*p))
3789 suffix = OBJECT_SUFFIX;
3790 suffix_length = strlen (OBJECT_SUFFIX);
3794 while (*p == '.' || ISALPHA ((unsigned char)*p))
3796 suffix_length = p - suffix;
3799 /* See if we already have an association of %g/%u/%U and
3801 for (t = temp_names; t; t = t->next)
3802 if (t->length == suffix_length
3803 && strncmp (t->suffix, suffix, suffix_length) == 0
3804 && t->unique == (c != 'g'))
3807 /* Make a new association if needed. %u requires one. */
3808 if (t == 0 || c == 'u')
3812 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3813 t->next = temp_names;
3816 t->length = suffix_length;
3817 t->suffix = save_string (suffix, suffix_length);
3818 t->unique = (c != 'g');
3819 temp_filename = make_temp_file (t->suffix);
3820 temp_filename_length = strlen (temp_filename);
3821 t->filename = temp_filename;
3822 t->filename_length = temp_filename_length;
3825 obstack_grow (&obstack, t->filename, t->filename_length);
3826 delete_this_arg = 1;
3828 obstack_grow (&obstack, temp_filename, temp_filename_length);
3829 if (c == 'u' || c == 'U')
3835 sprintf (buff, "%d", unique);
3836 obstack_grow (&obstack, buff, strlen (buff));
3839 delete_this_arg = 1;
3845 obstack_grow (&obstack, input_filename, input_filename_length);
3851 struct prefix_list *pl = include_prefixes.plist;
3853 if (gcc_exec_prefix)
3855 do_spec_1 ("-iprefix", 1, NULL_PTR);
3856 /* Make this a separate argument. */
3857 do_spec_1 (" ", 0, NULL_PTR);
3858 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3859 do_spec_1 (" ", 0, NULL_PTR);
3862 for (; pl; pl = pl->next)
3864 do_spec_1 ("-isystem", 1, NULL_PTR);
3865 /* Make this a separate argument. */
3866 do_spec_1 (" ", 0, NULL_PTR);
3867 do_spec_1 (pl->prefix, 1, NULL_PTR);
3868 do_spec_1 (" ", 0, NULL_PTR);
3875 int max = n_infiles;
3876 max += lang_specific_extra_outfiles;
3878 for (i = 0; i < max; i++)
3880 store_arg (outfiles[i], 0, 0);
3885 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3890 this_is_library_file = 1;
3894 this_is_output_file = 1;
3899 int cur_index = argbuf_index;
3900 /* Handle the {...} following the %W. */
3903 p = handle_braces (p + 1);
3906 /* If any args were output, mark the last one for deletion
3908 if (argbuf_index != cur_index)
3909 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3913 /* %x{OPTION} records OPTION for %X to output. */
3919 /* Skip past the option value and make a copy. */
3924 string = save_string (p1 + 1, p - p1 - 2);
3926 /* See if we already recorded this option. */
3927 for (i = 0; i < n_linker_options; i++)
3928 if (! strcmp (string, linker_options[i]))
3934 /* This option is new; add it. */
3935 add_linker_option (string, strlen (string));
3939 /* Dump out the options accumulated previously using %x. */
3941 for (i = 0; i < n_linker_options; i++)
3943 do_spec_1 (linker_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 -Wa,. */
3951 for (i = 0; i < n_assembler_options; i++)
3953 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3954 /* Make each accumulated option a separate argument. */
3955 do_spec_1 (" ", 0, NULL_PTR);
3959 /* Dump out the options accumulated previously using -Wp,. */
3961 for (i = 0; i < n_preprocessor_options; i++)
3963 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3964 /* Make each accumulated option a separate argument. */
3965 do_spec_1 (" ", 0, NULL_PTR);
3969 /* Here are digits and numbers that just process
3970 a certain constant string as a spec. */
3973 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3979 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3985 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3991 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3997 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
4003 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
4009 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
4015 value = do_spec_1 (link_spec, 0, NULL_PTR);
4021 value = do_spec_1 (lib_spec, 0, NULL_PTR);
4027 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
4034 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
4038 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4042 if (! strncmp (y, "-D", 2))
4043 /* Copy the whole option. */
4044 while (*y && *y != ' ' && *y != '\t')
4046 else if (*y == ' ' || *y == '\t')
4047 /* Copy whitespace to the result. */
4049 /* Don't copy other options. */
4056 value = do_spec_1 (buf, 0, NULL_PTR);
4064 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
4068 /* Copy all of CPP_PREDEFINES into BUF,
4069 but put __ after every -D and at the end of each arg. */
4073 if (! strncmp (y, "-D", 2))
4082 && ! ISUPPER ((unsigned char)*(y+1))))
4084 /* Stick __ at front of macro name. */
4087 /* Arrange to stick __ at the end as well. */
4091 /* Copy the macro name. */
4092 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4101 /* Copy the value given, if any. */
4102 while (*y && *y != ' ' && *y != '\t')
4105 else if (*y == ' ' || *y == '\t')
4106 /* Copy whitespace to the result. */
4108 /* Don't copy -A options */
4114 /* Copy all of CPP_PREDEFINES into BUF,
4115 but put __ after every -D. */
4119 if (! strncmp (y, "-D", 2))
4125 && ! ISUPPER ((unsigned char)*(y+1))))
4127 /* Stick -D__ at front of macro name. */
4133 /* Copy the macro name. */
4134 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4137 /* Copy the value given, if any. */
4138 while (*y && *y != ' ' && *y != '\t')
4143 /* Do not copy this macro - we have just done it before */
4144 while (*y && *y != ' ' && *y != '\t')
4148 else if (*y == ' ' || *y == '\t')
4149 /* Copy whitespace to the result. */
4151 /* Don't copy -A options */
4157 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4161 if (! strncmp (y, "-A", 2))
4162 /* Copy the whole option. */
4163 while (*y && *y != ' ' && *y != '\t')
4165 else if (*y == ' ' || *y == '\t')
4166 /* Copy whitespace to the result. */
4168 /* Don't copy other options. */
4175 value = do_spec_1 (buf, 0, NULL_PTR);
4182 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
4187 /* Here we define characters other than letters and digits. */
4190 p = handle_braces (p);
4196 obstack_1grow (&obstack, '%');
4200 do_spec_1 (soft_matched_part, 1, NULL_PTR);
4201 do_spec_1 (" ", 0, NULL_PTR);
4204 /* Process a string found as the value of a spec given by name.
4205 This feature allows individual machine descriptions
4206 to add and use their own specs.
4207 %[...] modifies -D options the way %P does;
4208 %(...) uses the spec unmodified. */
4210 error ("Warning: use of obsolete %%[ operator in specs");
4213 const char *name = p;
4214 struct spec_list *sl;
4217 /* The string after the S/P is the name of a spec that is to be
4219 while (*p && *p != ')' && *p != ']')
4222 /* See if it's in the list */
4223 for (len = p - name, sl = specs; sl; sl = sl->next)
4224 if (sl->name_len == len && !strncmp (sl->name, name, len))
4226 name = *(sl->ptr_spec);
4228 notice ("Processing spec %c%s%c, which is '%s'\n",
4229 c, sl->name, (c == '(') ? ')' : ']', name);
4238 value = do_spec_1 (name, 0, NULL_PTR);
4244 char *x = (char *) alloca (strlen (name) * 2 + 1);
4246 const char *y = name;
4249 /* Copy all of NAME into BUF, but put __ after
4250 every -D and at the end of each arg, */
4253 if (! strncmp (y, "-D", 2))
4263 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
4264 || *y == '}' || *y == 0))
4277 value = do_spec_1 (buf, 0, NULL_PTR);
4283 /* Discard the closing paren or bracket. */
4291 int c1 = *p++; /* Select first or second version number. */
4292 char *v = compiler_version;
4295 /* The format of the version string is
4296 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4298 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4299 while (! ISDIGIT (*v))
4301 if (v > compiler_version && v[-1] != '-')
4304 /* If desired, advance to second version number. */
4307 /* Set V after the first period. */
4308 while (ISDIGIT (*v))
4315 /* Set Q at the next period or at the end. */
4317 while (ISDIGIT (*q))
4319 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
4322 /* Put that part into the command. */
4323 obstack_grow (&obstack, v, q - v);
4329 if (input_from_pipe)
4330 do_spec_1 ("-", 0, NULL_PTR);
4339 /* Backslash: treat next character as ordinary. */
4344 /* Ordinary character: put it into the current argument. */
4345 obstack_1grow (&obstack, c);
4349 return 0; /* End of string */
4352 /* Return 0 if we call do_spec_1 and that returns -1. */
4356 register const char *p;
4358 const char *filter, *body = NULL, *endbody = NULL;
4362 int include_blanks = 1;
4365 /* A '^' after the open-brace means to not give blanks before args. */
4366 include_blanks = 0, ++p;
4369 /* A `|' after the open-brace means,
4370 if the test fails, output a single minus sign rather than nothing.
4371 This is used in %{|!pipe:...}. */
4375 negate = suffix = 0;
4378 /* A `!' after the open-brace negates the condition:
4379 succeed if the specified switch is not present. */
4383 /* A `.' after the open-brace means test against the current suffix. */
4393 while (*p != ':' && *p != '}' && *p != '|') p++;
4395 if (*p == '|' && pipe_p)
4402 register int count = 1;
4403 register const char *q = p;
4405 while (*q++ != ':') continue;
4421 body = p, endbody = p+1;
4426 int found = (input_suffix != 0
4427 && (long) strlen (input_suffix) == (long)(p - filter)
4428 && strncmp (input_suffix, filter, p - filter) == 0);
4434 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL_PTR) < 0)
4437 else if (p[-1] == '*' && p[0] == '}')
4439 /* Substitute all matching switches as separate args. */
4442 for (i = 0; i < n_switches; i++)
4443 if (!strncmp (switches[i].part1, filter, p - filter)
4444 && check_live_switch (i, p - filter))
4445 give_switch (i, 0, include_blanks);
4449 /* Test for presence of the specified switch. */
4453 /* If name specified ends in *, as in {x*:...},
4454 check for %* and handle that case. */
4455 if (p[-1] == '*' && !negate)
4458 const char *r = body;
4460 /* First see whether we have %*. */
4464 if (*r == '%' && r[1] == '*')
4468 /* If we do, handle that case. */
4471 /* Substitute all matching switches as separate args.
4472 But do this by substituting for %*
4473 in the text that follows the colon. */
4475 unsigned hard_match_len = p - filter - 1;
4476 char *string = save_string (body, endbody - body - 1);
4478 for (i = 0; i < n_switches; i++)
4479 if (!strncmp (switches[i].part1, filter, hard_match_len)
4480 && check_live_switch (i, -1))
4482 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4483 /* Pass any arguments this switch has. */
4484 give_switch (i, 1, 1);
4487 /* We didn't match. Try again. */
4494 /* If name specified ends in *, as in {x*:...},
4495 check for presence of any switch name starting with x. */
4498 for (i = 0; i < n_switches; i++)
4500 unsigned hard_match_len = p - filter - 1;
4502 if (!strncmp (switches[i].part1, filter, hard_match_len)
4503 && check_live_switch (i, hard_match_len))
4509 /* Otherwise, check for presence of exact name specified. */
4512 for (i = 0; i < n_switches; i++)
4514 if (!strncmp (switches[i].part1, filter, p - filter)
4515 && switches[i].part1[p - filter] == 0
4516 && check_live_switch (i, -1))
4524 /* If it is as desired (present for %{s...}, absent for %{!s...})
4525 then substitute either the switch or the specified
4526 conditional text. */
4527 if (present != negate)
4531 give_switch (i, 0, include_blanks);
4535 if (do_spec_1 (save_string (body, endbody - body - 1),
4542 /* Here if a %{|...} conditional fails: output a minus sign,
4543 which means "standard output" or "standard input". */
4544 do_spec_1 ("-", 0, NULL_PTR);
4549 /* We didn't match; try again. */
4556 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4557 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4558 spec, or -1 if either exact match or %* is used.
4560 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4561 whose value does not begin with "no-" is obsoleted by the same value
4562 with the "no-", similarly for a switch with the "no-" prefix. */
4565 check_live_switch (switchnum, prefix_length)
4569 const char *name = switches[switchnum].part1;
4572 /* In the common case of {<at-most-one-letter>*}, a negating
4573 switch would always match, so ignore that case. We will just
4574 send the conflicting switches to the compiler phase. */
4575 if (prefix_length >= 0 && prefix_length <= 1)
4578 /* If we already processed this switch and determined if it was
4579 live or not, return our past determination. */
4580 if (switches[switchnum].live_cond != 0)
4581 return switches[switchnum].live_cond > 0;
4583 /* Now search for duplicate in a manner that depends on the name. */
4587 for (i = switchnum + 1; i < n_switches; i++)
4588 if (switches[i].part1[0] == 'O')
4590 switches[switchnum].validated = 1;
4591 switches[switchnum].live_cond = -1;
4596 case 'W': case 'f': case 'm':
4597 if (! strncmp (name + 1, "no-", 3))
4599 /* We have Xno-YYY, search for XYYY. */
4600 for (i = switchnum + 1; i < n_switches; i++)
4601 if (switches[i].part1[0] == name[0]
4602 && ! strcmp (&switches[i].part1[1], &name[4]))
4604 switches[switchnum].validated = 1;
4605 switches[switchnum].live_cond = -1;
4611 /* We have XYYY, search for Xno-YYY. */
4612 for (i = switchnum + 1; i < n_switches; i++)
4613 if (switches[i].part1[0] == name[0]
4614 && switches[i].part1[1] == 'n'
4615 && switches[i].part1[2] == 'o'
4616 && switches[i].part1[3] == '-'
4617 && !strcmp (&switches[i].part1[4], &name[1]))
4619 switches[switchnum].validated = 1;
4620 switches[switchnum].live_cond = -1;
4627 /* Otherwise the switch is live. */
4628 switches[switchnum].live_cond = 1;
4632 /* Pass a switch to the current accumulating command
4633 in the same form that we received it.
4634 SWITCHNUM identifies the switch; it is an index into
4635 the vector of switches gcc received, which is `switches'.
4636 This cannot fail since it never finishes a command line.
4638 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4640 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4644 give_switch (switchnum, omit_first_word, include_blanks)
4646 int omit_first_word;
4649 if (!omit_first_word)
4651 do_spec_1 ("-", 0, NULL_PTR);
4652 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4655 if (switches[switchnum].args != 0)
4658 for (p = switches[switchnum].args; *p; p++)
4661 do_spec_1 (" ", 0, NULL_PTR);
4662 do_spec_1 (*p, 1, NULL_PTR);
4666 do_spec_1 (" ", 0, NULL_PTR);
4667 switches[switchnum].validated = 1;
4670 /* Search for a file named NAME trying various prefixes including the
4671 user's -B prefix and some standard ones.
4672 Return the absolute file name found. If nothing is found, return NAME. */
4680 /* Try multilib_dir if it is defined. */
4681 if (multilib_dir != NULL)
4685 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4686 strcpy (try, multilib_dir);
4687 strcat (try, dir_separator_str);
4690 newname = find_a_file (&startfile_prefixes, try, R_OK);
4692 /* If we don't find it in the multi library dir, then fall
4693 through and look for it in the normal places. */
4694 if (newname != NULL)
4698 newname = find_a_file (&startfile_prefixes, name, R_OK);
4699 return newname ? newname : name;
4702 /* Determine whether a directory exists. If LINKER, return 0 for
4703 certain fixed names not needed by the linker. If not LINKER, it is
4704 only important to return 0 if the host machine has a small ARG_MAX
4708 is_directory (path1, path2, linker)
4713 int len1 = strlen (path1);
4714 int len2 = strlen (path2);
4715 char *path = (char *) alloca (3 + len1 + len2);
4719 #ifndef SMALL_ARG_MAX
4724 /* Construct the path from the two parts. Ensure the string ends with "/.".
4725 The resulting path will be a directory even if the given path is a
4727 memcpy (path, path1, len1);
4728 memcpy (path + len1, path2, len2);
4729 cp = path + len1 + len2;
4730 if (!IS_DIR_SEPARATOR (cp[-1]))
4731 *cp++ = DIR_SEPARATOR;
4735 #ifndef FREEBSD_NATIVE
4736 /* Exclude directories that the linker is known to search. */
4739 && strcmp (path, concat (dir_separator_str, "lib",
4740 dir_separator_str, ".", NULL_PTR)) == 0)
4742 && strcmp (path, concat (dir_separator_str, "usr",
4743 dir_separator_str, "lib",
4744 dir_separator_str, ".", NULL_PTR)) == 0)))
4746 #endif /* not FREEBSD_NATIVE */
4748 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4751 /* On fatal signals, delete all the temporary files. */
4754 fatal_error (signum)
4757 signal (signum, SIG_DFL);
4758 delete_failure_queue ();
4759 delete_temp_files ();
4760 /* Get the same signal again, this time not handled,
4761 so its normal effect occurs. */
4762 kill (getpid (), signum);
4773 int linker_was_run = 0;
4774 char *explicit_link_files;
4777 struct user_specs *uptr;
4779 p = argv[0] + strlen (argv[0]);
4780 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
4784 #ifdef HAVE_LC_MESSAGES
4785 setlocale (LC_MESSAGES, "");
4787 (void) bindtextdomain (PACKAGE, localedir);
4788 (void) textdomain (PACKAGE);
4790 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4791 signal (SIGINT, fatal_error);
4793 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4794 signal (SIGHUP, fatal_error);
4796 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4797 signal (SIGTERM, fatal_error);
4799 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4800 signal (SIGPIPE, fatal_error);
4804 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4806 obstack_init (&obstack);
4808 /* Build multilib_select, et. al from the separate lines that make up each
4809 multilib selection. */
4811 char **q = multilib_raw;
4814 obstack_init (&multilib_obstack);
4815 while ((p = *q++) != (char *) 0)
4816 obstack_grow (&multilib_obstack, p, strlen (p));
4818 obstack_1grow (&multilib_obstack, 0);
4819 multilib_select = obstack_finish (&multilib_obstack);
4821 q = multilib_matches_raw;
4822 while ((p = *q++) != (char *) 0)
4823 obstack_grow (&multilib_obstack, p, strlen (p));
4825 obstack_1grow (&multilib_obstack, 0);
4826 multilib_matches = obstack_finish (&multilib_obstack);
4830 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4834 obstack_1grow (&multilib_obstack, ' ');
4835 obstack_grow (&multilib_obstack,
4836 multilib_defaults_raw[i],
4837 strlen (multilib_defaults_raw[i]));
4841 obstack_1grow (&multilib_obstack, 0);
4842 multilib_defaults = obstack_finish (&multilib_obstack);
4845 /* Set up to remember the pathname of gcc and any options
4846 needed for collect. We use argv[0] instead of programname because
4847 we need the complete pathname. */
4848 obstack_init (&collect_obstack);
4849 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4850 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4851 putenv (obstack_finish (&collect_obstack));
4853 #ifdef INIT_ENVIRONMENT
4854 /* Set up any other necessary machine specific environment variables. */
4855 putenv (INIT_ENVIRONMENT);
4858 /* Choose directory for temp files. */
4860 #ifndef MKTEMP_EACH_FILE
4861 temp_filename = choose_temp_base ();
4862 temp_filename_length = strlen (temp_filename);
4865 /* Make a table of what switches there are (switches, n_switches).
4866 Make a table of specified input files (infiles, n_infiles).
4867 Decode switches that are handled locally. */
4869 process_command (argc, argv);
4874 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4876 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4877 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4880 for (i = 0; (int)i < n_switches; i++)
4885 obstack_grow (&collect_obstack, " ", 1);
4888 obstack_grow (&collect_obstack, "'-", 2);
4889 q = switches[i].part1;
4890 while ((p = index (q,'\'')))
4892 obstack_grow (&collect_obstack, q, p-q);
4893 obstack_grow (&collect_obstack, "'\\''", 4);
4896 obstack_grow (&collect_obstack, q, strlen (q));
4897 obstack_grow (&collect_obstack, "'", 1);
4899 for (args = switches[i].args; args && *args; args++)
4901 obstack_grow (&collect_obstack, " '", 2);
4903 while ((p = index (q,'\'')))
4905 obstack_grow (&collect_obstack, q, p-q);
4906 obstack_grow (&collect_obstack, "'\\''", 4);
4909 obstack_grow (&collect_obstack, q, strlen (q));
4910 obstack_grow (&collect_obstack, "'", 1);
4913 obstack_grow (&collect_obstack, "\0", 1);
4914 putenv (obstack_finish (&collect_obstack));
4917 /* Initialize the vector of specs to just the default.
4918 This means one element containing 0s, as a terminator. */
4920 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4921 bcopy ((char *) default_compilers, (char *) compilers,
4922 sizeof default_compilers);
4923 n_compilers = n_default_compilers;
4925 /* Read specs from a file if there is one. */
4927 #ifdef FREEBSD_NATIVE
4928 just_machine_suffix = ""; /* I don't support specs, gives determinism */
4929 #else /* FREEBSD_NATIVE */
4930 machine_suffix = concat (spec_machine, dir_separator_str,
4931 spec_version, dir_separator_str, NULL_PTR);
4932 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4933 #endif /* FREEBSD_NATIVE */
4935 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4936 /* Read the specs file unless it is a default one. */
4937 if (specs_file != 0 && strcmp (specs_file, "specs"))
4938 read_specs (specs_file, TRUE);
4942 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4943 for any override of as, ld and libraries. */
4944 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4945 + strlen (just_machine_suffix)
4946 + sizeof ("specs"));
4948 strcpy (specs_file, standard_exec_prefix);
4949 strcat (specs_file, just_machine_suffix);
4950 strcat (specs_file, "specs");
4951 if (access (specs_file, R_OK) == 0)
4952 read_specs (specs_file, TRUE);
4954 /* If not cross-compiling, look for startfiles in the standard places. */
4955 if (*cross_compile == '0')
4957 #ifdef MD_EXEC_PREFIX
4958 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4959 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4962 #ifdef MD_STARTFILE_PREFIX
4963 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4967 #ifdef MD_STARTFILE_PREFIX_1
4968 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4972 /* If standard_startfile_prefix is relative, base it on
4973 standard_exec_prefix. This lets us move the installed tree
4974 as a unit. If GCC_EXEC_PREFIX is defined, base
4975 standard_startfile_prefix on that as well. */
4976 if (IS_DIR_SEPARATOR (*standard_startfile_prefix)
4977 || *standard_startfile_prefix == '$'
4978 #ifdef HAVE_DOS_BASED_FILESYSTEM
4979 /* Check for disk name on MS-DOS-based systems. */
4980 || (standard_startfile_prefix[1] == ':'
4981 && (IS_DIR_SEPARATOR (standard_startfile_prefix[2])))
4984 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4988 if (gcc_exec_prefix)
4989 add_prefix (&startfile_prefixes,
4990 concat (gcc_exec_prefix, machine_suffix,
4991 standard_startfile_prefix, NULL_PTR),
4992 NULL_PTR, 0, 0, NULL_PTR);
4993 add_prefix (&startfile_prefixes,
4994 concat (standard_exec_prefix,
4996 standard_startfile_prefix, NULL_PTR),
4997 NULL_PTR, 0, 0, NULL_PTR);
5000 #ifndef FREEBSD_NATIVE
5001 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
5002 "BINUTILS", 0, 0, NULL_PTR);
5003 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
5004 "BINUTILS", 0, 0, NULL_PTR);
5005 #endif /* FREEBSD_NATIVE */
5006 #if 0 /* Can cause surprises, and one can use -B./ instead. */
5007 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
5012 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix) && gcc_exec_prefix)
5013 add_prefix (&startfile_prefixes,
5014 concat (gcc_exec_prefix, machine_suffix,
5015 standard_startfile_prefix, NULL_PTR),
5016 "BINUTILS", 0, 0, NULL_PTR);
5017 #ifdef CROSS_STARTFILE_PREFIX
5018 add_prefix (&startfile_prefixes, CROSS_STARTFILE_PREFIX, "BINUTILS",
5023 /* Process any user specified specs in the order given on the command
5025 for (uptr = user_specs_head; uptr; uptr = uptr->next)
5027 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
5028 read_specs (filename ? filename : uptr->filename, FALSE);
5031 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
5032 if (gcc_exec_prefix)
5034 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
5035 + strlen (spec_version)
5036 + strlen (spec_machine) + 3);
5037 strcpy (temp, gcc_exec_prefix);
5038 strcat (temp, spec_machine);
5039 strcat (temp, dir_separator_str);
5040 strcat (temp, spec_version);
5041 strcat (temp, dir_separator_str);
5042 gcc_exec_prefix = temp;
5045 /* Now we have the specs.
5046 Set the `valid' bits for switches that match anything in any spec. */
5048 validate_all_switches ();
5050 /* Now that we have the switches and the specs, set
5051 the subdirectory based on the options. */
5052 set_multilib_dir ();
5054 /* Warn about any switches that no pass was interested in. */
5056 for (i = 0; (int)i < n_switches; i++)
5057 if (! switches[i].validated)
5058 error ("unrecognized option `-%s'", switches[i].part1);
5060 /* Obey some of the options. */
5062 if (print_search_dirs)
5064 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
5065 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
5066 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
5070 if (print_file_name)
5072 printf ("%s\n", find_file (print_file_name));
5076 if (print_prog_name)
5078 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
5079 printf ("%s\n", (newname ? newname : print_prog_name));
5083 if (print_multi_lib)
5085 print_multilib_info ();
5089 if (print_multi_directory)
5091 if (multilib_dir == NULL)
5094 printf ("%s\n", multilib_dir);
5098 if (print_help_list)
5104 printf ("\nFor bug reporting instructions, please see:\n");
5105 printf ("%s.\n", GCCBUGURL);
5110 /* We do not exit here. Instead we have created a fake input file
5111 called 'help-dummy' which needs to be compiled, and we pass this
5112 on the the various sub-processes, along with the --help switch. */
5119 /* compiler_version is truncated at the first space when initialized
5120 from version string, so truncate version_string at the first space
5121 before comparing. */
5122 for (n = 0; version_string[n]; n++)
5123 if (version_string[n] == ' ')
5126 if (! strncmp (version_string, compiler_version, n)
5127 && compiler_version[n] == 0)
5128 notice ("gcc version %s\n", version_string);
5130 notice ("gcc driver version %s executing gcc version %s\n",
5131 version_string, compiler_version);
5137 if (n_infiles == added_libraries)
5138 fatal ("No input files specified");
5140 /* Make a place to record the compiler output file names
5141 that correspond to the input files. */
5144 i += lang_specific_extra_outfiles;
5145 outfiles = (const char **) xmalloc (i * sizeof (char *));
5146 bzero ((char *) outfiles, i * sizeof (char *));
5148 /* Record which files were specified explicitly as link input. */
5150 explicit_link_files = xmalloc (n_infiles);
5151 bzero (explicit_link_files, n_infiles);
5153 for (i = 0; (int)i < n_infiles; i++)
5155 register struct compiler *cp = 0;
5156 int this_file_error = 0;
5158 /* Tell do_spec what to substitute for %i. */
5160 input_filename = infiles[i].name;
5161 input_filename_length = strlen (input_filename);
5162 input_file_number = i;
5164 /* Use the same thing in %o, unless cp->spec says otherwise. */
5166 outfiles[i] = input_filename;
5168 /* Figure out which compiler from the file's suffix. */
5170 cp = lookup_compiler (infiles[i].name, input_filename_length,
5171 infiles[i].language);
5175 /* Ok, we found an applicable compiler. Run its spec. */
5176 /* First say how much of input_filename to substitute for %b */
5177 register const char *p;
5180 if (cp->spec[0][0] == '#')
5182 error ("%s: %s compiler not installed on this system",
5183 input_filename, &cp->spec[0][1]);
5184 this_file_error = 1;
5188 input_basename = input_filename;
5189 for (p = input_filename; *p; p++)
5190 if (IS_DIR_SEPARATOR (*p))
5191 input_basename = p + 1;
5193 /* Find a suffix starting with the last period,
5194 and set basename_length to exclude that suffix. */
5195 basename_length = strlen (input_basename);
5196 p = input_basename + basename_length;
5197 while (p != input_basename && *p != '.') --p;
5198 if (*p == '.' && p != input_basename)
5200 basename_length = p - input_basename;
5201 input_suffix = p + 1;
5207 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5209 len += strlen (cp->spec[j]);
5212 char *p1 = (char *) xmalloc (len + 1);
5215 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5218 strcpy (p1 + len, cp->spec[j]);
5219 len += strlen (cp->spec[j]);
5222 value = do_spec (p1);
5226 this_file_error = 1;
5230 /* If this file's name does not contain a recognized suffix,
5231 record it as explicit linker input. */
5234 explicit_link_files[i] = 1;
5236 /* Clear the delete-on-failure queue, deleting the files in it
5237 if this compilation failed. */
5239 if (this_file_error)
5241 delete_failure_queue ();
5244 /* If this compilation succeeded, don't delete those files later. */
5245 clear_failure_queue ();
5248 if (error_count == 0)
5250 /* Make sure INPUT_FILE_NUMBER points to first available open
5252 input_file_number = n_infiles;
5253 if (lang_specific_pre_link ())
5257 /* Run ld to link all the compiler output files. */
5259 if (error_count == 0)
5261 int tmp = execution_count;
5263 /* We'll use ld if we can't find collect2. */
5264 if (! strcmp (linker_name_spec, "collect2"))
5266 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
5268 linker_name_spec = "ld";
5270 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5272 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
5273 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
5275 value = do_spec (link_command_spec);
5278 linker_was_run = (tmp != execution_count);
5281 /* Warn if a -B option was specified but the prefix was never used. */
5282 unused_prefix_warnings (&exec_prefixes);
5283 unused_prefix_warnings (&startfile_prefixes);
5285 /* If options said don't run linker,
5286 complain about input files to be given to the linker. */
5288 if (! linker_was_run && error_count == 0)
5289 for (i = 0; (int)i < n_infiles; i++)
5290 if (explicit_link_files[i])
5291 error ("%s: linker input file unused since linking not done",
5294 /* Delete some or all of the temporary files we made. */
5297 delete_failure_queue ();
5298 delete_temp_files ();
5300 if (print_help_list)
5302 printf ("\nFor bug reporting instructions, please see:\n");
5303 printf ("%s\n", GCCBUGURL);
5306 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
5311 /* Find the proper compilation spec for the file name NAME,
5312 whose length is LENGTH. LANGUAGE is the specified language,
5313 or 0 if this file is to be passed to the linker. */
5315 static struct compiler *
5316 lookup_compiler (name, length, language)
5319 const char *language;
5321 struct compiler *cp;
5323 /* If this was specified by the user to be a linker input, indicate that. */
5324 if (language != 0 && language[0] == '*')
5327 /* Otherwise, look for the language, if one is spec'd. */
5330 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5331 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
5334 error ("language %s not recognized", language);
5338 /* Look for a suffix. */
5339 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5341 if (/* The suffix `-' matches only the file name `-'. */
5342 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
5343 || (strlen (cp->suffix) < length
5344 /* See if the suffix matches the end of NAME. */
5346 && ((!strcmp (cp->suffix,
5347 name + length - strlen (cp->suffix))
5348 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5349 && !strcasecmp (cp->suffix,
5350 name + length - strlen (cp->suffix)))
5352 && !strcmp (cp->suffix,
5353 name + length - strlen (cp->suffix))
5357 if (cp->spec[0][0] == '@')
5359 struct compiler *new;
5361 /* An alias entry maps a suffix to a language.
5362 Search for the language; pass 0 for NAME and LENGTH
5363 to avoid infinite recursion if language not found.
5364 Construct the new compiler spec. */
5365 language = cp->spec[0] + 1;
5366 new = (struct compiler *) xmalloc (sizeof (struct compiler));
5367 new->suffix = cp->suffix;
5368 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
5369 (char *) new->spec, sizeof new->spec);
5373 /* A non-alias entry: return it. */
5385 register PTR value = (PTR) malloc (size);
5387 fatal ("virtual memory exhausted");
5392 xrealloc (old, size)
5398 ptr = (PTR) realloc (old, size);
5400 ptr = (PTR) malloc (size);
5402 fatal ("virtual memory exhausted");
5407 save_string (s, len)
5411 register char *result = xmalloc (len + 1);
5413 bcopy (s, result, len);
5419 pfatal_with_name (name)
5422 perror_with_name (name);
5423 delete_temp_files ();
5428 perror_with_name (name)
5431 error ("%s: %s", name, xstrerror (errno));
5435 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5436 const char *errmsg_fmt;
5437 const char *errmsg_arg;
5441 int save_errno = errno;
5443 /* Space for trailing '\0' is in %s. */
5444 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5445 sprintf (msg, errmsg_fmt, errmsg_arg);
5451 pfatal_with_name (errmsg_fmt);
5454 /* More 'friendly' abort that prints the line and file.
5455 config.h can #define abort fancy_abort if you like that sort of thing. */
5460 fatal ("Internal gcc abort.");
5463 /* Output an error message and exit */
5466 fatal VPROTO((const char *msgid, ...))
5468 #ifndef ANSI_PROTOTYPES
5473 VA_START (ap, msgid);
5475 #ifndef ANSI_PROTOTYPES
5476 msgid = va_arg (ap, const char *);
5479 fprintf (stderr, "%s: ", programname);
5480 vfprintf (stderr, _(msgid), ap);
5482 fprintf (stderr, "\n");
5483 delete_temp_files ();
5488 error VPROTO((const char *msgid, ...))
5490 #ifndef ANSI_PROTOTYPES
5495 VA_START (ap, msgid);
5497 #ifndef ANSI_PROTOTYPES
5498 msgid = va_arg (ap, const char *);
5501 fprintf (stderr, "%s: ", programname);
5502 vfprintf (stderr, _(msgid), ap);
5505 fprintf (stderr, "\n");
5509 notice VPROTO((const char *msgid, ...))
5511 #ifndef ANSI_PROTOTYPES
5516 VA_START (ap, msgid);
5518 #ifndef ANSI_PROTOTYPES
5519 msgid = va_arg (ap, const char *);
5522 vfprintf (stderr, _(msgid), ap);
5528 validate_all_switches ()
5530 struct compiler *comp;
5531 register const char *p;
5533 struct spec_list *spec;
5535 for (comp = compilers; comp->spec[0]; comp++)
5538 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5542 if (c == '%' && *p == '{')
5543 /* We have a switch spec. */
5544 validate_switches (p + 1);
5548 /* look through the linked list of specs read from the specs file */
5549 for (spec = specs; spec ; spec = spec->next)
5551 p = *(spec->ptr_spec);
5553 if (c == '%' && *p == '{')
5554 /* We have a switch spec. */
5555 validate_switches (p + 1);
5558 p = link_command_spec;
5560 if (c == '%' && *p == '{')
5561 /* We have a switch spec. */
5562 validate_switches (p + 1);
5565 /* Look at the switch-name that comes after START
5566 and mark as valid all supplied switches that match it. */
5569 validate_switches (start)
5572 register const char *p = start;
5587 while (*p != ':' && *p != '}') p++;
5591 else if (p[-1] == '*')
5593 /* Mark all matching switches as valid. */
5595 for (i = 0; i < n_switches; i++)
5596 if (!strncmp (switches[i].part1, filter, p - filter))
5597 switches[i].validated = 1;
5601 /* Mark an exact matching switch as valid. */
5602 for (i = 0; i < n_switches; i++)
5604 if (!strncmp (switches[i].part1, filter, p - filter)
5605 && switches[i].part1[p - filter] == 0)
5606 switches[i].validated = 1;
5611 /* Check whether a particular argument was used. The first time we
5612 canonicalize the switches to keep only the ones we care about. */
5626 static struct mswitchstr *mswitches;
5627 static int n_mswitches;
5632 struct mswitchstr *matches;
5636 /* Break multilib_matches into the component strings of string and replacement
5638 for (q = multilib_matches; *q != '\0'; q++)
5642 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5644 q = multilib_matches;
5655 matches[i].len = q - matches[i].str;
5657 matches[i].replace = ++q;
5658 while (*q != ';' && *q != '\0')
5664 matches[i].rep_len = q - matches[i].replace;
5672 /* Now build a list of the replacement string for switches that we care
5673 about. Make sure we allocate at least one entry. This prevents
5674 xmalloc from calling fatal, and prevents us from re-executing this
5677 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5678 * (n_switches ? n_switches : 1));
5679 for (i = 0; i < n_switches; i++)
5681 int xlen = strlen (switches[i].part1);
5682 for (j = 0; j < cnt; j++)
5683 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5685 mswitches[n_mswitches].str = matches[j].replace;
5686 mswitches[n_mswitches].len = matches[j].rep_len;
5687 mswitches[n_mswitches].replace = (char *)0;
5688 mswitches[n_mswitches].rep_len = 0;
5695 for (i = 0; i < n_mswitches; i++)
5696 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5703 default_arg (p, len)
5709 for (start = multilib_defaults; *start != '\0'; start = end+1)
5711 while (*start == ' ' || *start == '\t')
5717 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5720 if ((end - start) == len && strncmp (p, start, len) == 0)
5730 /* Work out the subdirectory to use based on the
5731 options. The format of multilib_select is a list of elements.
5732 Each element is a subdirectory name followed by a list of options
5733 followed by a semicolon. gcc will consider each line in turn. If
5734 none of the options beginning with an exclamation point are
5735 present, and all of the other options are present, that
5736 subdirectory will be used. */
5741 char *p = multilib_select;
5743 char *this_path, *this_arg;
5749 /* Ignore newlines. */
5756 /* Get the initial path. */
5764 this_path_len = p - this_path;
5766 /* Check the arguments. */
5781 while (*p != ' ' && *p != ';')
5788 if (*this_arg != '!')
5796 /* If this is a default argument, we can just ignore it.
5797 This is true even if this_arg begins with '!'. Beginning
5798 with '!' does not mean that this argument is necessarily
5799 inappropriate for this library: it merely means that
5800 there is a more specific library which uses this
5801 argument. If this argument is a default, we need not
5802 consider that more specific library. */
5803 if (! default_arg (this_arg, p - this_arg))
5805 ok = used_arg (this_arg, p - this_arg);
5816 if (this_path_len != 1
5817 || this_path[0] != '.')
5819 char * new_multilib_dir = xmalloc (this_path_len + 1);
5820 strncpy (new_multilib_dir, this_path, this_path_len);
5821 new_multilib_dir[this_path_len] = '\0';
5822 multilib_dir = new_multilib_dir;
5831 /* Print out the multiple library subdirectory selection
5832 information. This prints out a series of lines. Each line looks
5833 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5834 required. Only the desired options are printed out, the negative
5835 matches. The options are print without a leading dash. There are
5836 no spaces to make it easy to use the information in the shell.
5837 Each subdirectory is printed only once. This assumes the ordering
5838 generated by the genmultilib script. */
5841 print_multilib_info ()
5843 char *p = multilib_select;
5844 char *last_path = 0, *this_path;
5846 int last_path_len = 0;
5850 /* Ignore newlines. */
5857 /* Get the initial path. */
5866 /* If this is a duplicate, skip it. */
5867 skip = (last_path != 0 && p - this_path == last_path_len
5868 && ! strncmp (last_path, this_path, last_path_len));
5870 last_path = this_path;
5871 last_path_len = p - this_path;
5873 /* If this directory requires any default arguments, we can skip
5874 it. We will already have printed a directory identical to
5875 this one which does not require that default argument. */
5893 while (*q != ' ' && *q != ';')
5901 && default_arg (arg, q - arg))
5916 for (p1 = last_path; p1 < p; p1++)
5935 use_arg = *p != '!';
5940 while (*p != ' ' && *p != ';')
5955 /* If there are extra options, print them now */
5956 if (multilib_extra && *multilib_extra)
5958 int print_at = TRUE;
5961 for (q = multilib_extra; *q != '\0'; q++)