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.2 2003/06/17 04:24:01 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/";
1399 #ifndef TOOLDIR_BASE_PREFIX
1400 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1402 static const char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1403 static const char *tooldir_prefix;
1405 /* Subdirectory to use for locating libraries. Set by
1406 set_multilib_dir based on the compilation options. */
1408 static const char *multilib_dir;
1410 /* Clear out the vector of arguments (after a command is executed). */
1418 /* Add one argument to the vector at the end.
1419 This is done when a space is seen or at the end of the line.
1420 If DELETE_ALWAYS is nonzero, the arg is a filename
1421 and the file should be deleted eventually.
1422 If DELETE_FAILURE is nonzero, the arg is a filename
1423 and the file should be deleted if this compilation fails. */
1426 store_arg (arg, delete_always, delete_failure)
1428 int delete_always, delete_failure;
1430 if (argbuf_index + 1 == argbuf_length)
1432 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1434 argbuf[argbuf_index++] = arg;
1435 argbuf[argbuf_index] = 0;
1437 if (delete_always || delete_failure)
1438 record_temp_file (arg, delete_always, delete_failure);
1441 /* Read compilation specs from a file named FILENAME,
1442 replacing the default ones.
1444 A suffix which starts with `*' is a definition for
1445 one of the machine-specific sub-specs. The "suffix" should be
1446 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1447 The corresponding spec is stored in asm_spec, etc.,
1448 rather than in the `compilers' vector.
1450 Anything invalid in the file is a fatal error. */
1453 read_specs (filename, main_p)
1454 const char *filename;
1459 struct stat statbuf;
1464 notice ("Reading specs from %s\n", filename);
1466 /* Open and stat the file. */
1467 desc = open (filename, O_RDONLY, 0);
1469 pfatal_with_name (filename);
1470 if (stat (filename, &statbuf) < 0)
1471 pfatal_with_name (filename);
1473 /* Read contents of file into BUFFER. */
1474 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1475 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1477 pfatal_with_name (filename);
1478 buffer[readlen] = 0;
1481 /* Scan BUFFER for specs, putting them in the vector. */
1487 char *in, *out, *p1, *p2, *p3;
1489 /* Advance P in BUFFER to the next nonblank nocomment line. */
1490 p = skip_whitespace (p);
1494 /* Is this a special command that starts with '%'? */
1495 /* Don't allow this for the main specs file, since it would
1496 encourage people to overwrite it. */
1497 if (*p == '%' && !main_p)
1500 while (*p && *p != '\n')
1503 p++; /* Skip '\n' */
1505 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1506 && (p1[sizeof "%include" - 1] == ' '
1507 || p1[sizeof "%include" - 1] == '\t'))
1511 p1 += sizeof ("%include");
1512 while (*p1 == ' ' || *p1 == '\t')
1515 if (*p1++ != '<' || p[-2] != '>')
1516 fatal ("specs %%include syntax malformed after %ld characters",
1517 (long) (p1 - buffer + 1));
1520 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1521 read_specs (new_filename ? new_filename : p1, FALSE);
1524 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1525 && (p1[sizeof "%include_noerr" - 1] == ' '
1526 || p1[sizeof "%include_noerr" - 1] == '\t'))
1530 p1 += sizeof "%include_noerr";
1531 while (*p1 == ' ' || *p1 == '\t') p1++;
1533 if (*p1++ != '<' || p[-2] != '>')
1534 fatal ("specs %%include syntax malformed after %ld characters",
1535 (long) (p1 - buffer + 1));
1538 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1540 read_specs (new_filename, FALSE);
1541 else if (verbose_flag)
1542 notice ("Could not find specs file %s\n", p1);
1545 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1546 && (p1[sizeof "%rename" - 1] == ' '
1547 || p1[sizeof "%rename" - 1] == '\t'))
1550 struct spec_list *sl;
1552 /* Get original name */
1553 p1 += sizeof "%rename";
1554 while (*p1 == ' ' || *p1 == '\t')
1557 if (! ISALPHA ((unsigned char)*p1))
1558 fatal ("specs %%rename syntax malformed after %ld characters",
1559 (long) (p1 - buffer));
1562 while (*p2 && !ISSPACE ((unsigned char)*p2))
1565 if (*p2 != ' ' && *p2 != '\t')
1566 fatal ("specs %%rename syntax malformed after %ld characters",
1567 (long) (p2 - buffer));
1571 while (*p2 == ' ' || *p2 == '\t')
1574 if (! ISALPHA ((unsigned char)*p2))
1575 fatal ("specs %%rename syntax malformed after %ld characters",
1576 (long) (p2 - buffer));
1578 /* Get new spec name */
1580 while (*p3 && !ISSPACE ((unsigned char)*p3))
1584 fatal ("specs %%rename syntax malformed after %ld characters",
1585 (long) (p3 - buffer));
1588 for (sl = specs; sl; sl = sl->next)
1589 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1593 fatal ("specs %s spec was not found to be renamed", p1);
1595 if (strcmp (p1, p2) == 0)
1600 notice ("rename spec %s to %s\n", p1, p2);
1602 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1606 set_spec (p2, *(sl->ptr_spec));
1608 free (*(sl->ptr_spec));
1610 *(sl->ptr_spec) = "";
1615 fatal ("specs unknown %% command after %ld characters",
1616 (long) (p1 - buffer));
1619 /* Find the colon that should end the suffix. */
1621 while (*p1 && *p1 != ':' && *p1 != '\n')
1624 /* The colon shouldn't be missing. */
1626 fatal ("specs file malformed after %ld characters",
1627 (long) (p1 - buffer));
1629 /* Skip back over trailing whitespace. */
1631 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1634 /* Copy the suffix to a string. */
1635 suffix = save_string (p, p2 - p);
1636 /* Find the next line. */
1637 p = skip_whitespace (p1 + 1);
1639 fatal ("specs file malformed after %ld characters",
1640 (long) (p - buffer));
1643 /* Find next blank line or end of string. */
1644 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1647 /* Specs end at the blank line and do not include the newline. */
1648 spec = save_string (p, p1 - p);
1651 /* Delete backslash-newline sequences from the spec. */
1656 if (in[0] == '\\' && in[1] == '\n')
1658 else if (in[0] == '#')
1659 while (*in && *in != '\n')
1667 if (suffix[0] == '*')
1669 if (! strcmp (suffix, "*link_command"))
1670 link_command_spec = spec;
1672 set_spec (suffix + 1, spec);
1676 /* Add this pair to the vector. */
1678 = ((struct compiler *)
1679 xrealloc (compilers,
1680 (n_compilers + 2) * sizeof (struct compiler)));
1682 compilers[n_compilers].suffix = suffix;
1683 bzero ((char *) compilers[n_compilers].spec,
1684 sizeof compilers[n_compilers].spec);
1685 compilers[n_compilers].spec[0] = spec;
1687 bzero ((char *) &compilers[n_compilers],
1688 sizeof compilers[n_compilers]);
1692 link_command_spec = spec;
1695 if (link_command_spec == 0)
1696 fatal ("spec file has no spec for linking");
1699 /* Record the names of temporary files we tell compilers to write,
1700 and delete them at the end of the run. */
1702 /* This is the common prefix we use to make temp file names.
1703 It is chosen once for each run of this program.
1704 It is substituted into a spec by %g.
1705 Thus, all temp file names contain this prefix.
1706 In practice, all temp file names start with this prefix.
1708 This prefix comes from the envvar TMPDIR if it is defined;
1709 otherwise, from the P_tmpdir macro if that is defined;
1710 otherwise, in /usr/tmp or /tmp;
1711 or finally the current directory if all else fails. */
1713 static const char *temp_filename;
1715 /* Length of the prefix. */
1717 static int temp_filename_length;
1719 /* Define the list of temporary files to delete. */
1724 struct temp_file *next;
1727 /* Queue of files to delete on success or failure of compilation. */
1728 static struct temp_file *always_delete_queue;
1729 /* Queue of files to delete on failure of compilation. */
1730 static struct temp_file *failure_delete_queue;
1732 /* Record FILENAME as a file to be deleted automatically.
1733 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1734 otherwise delete it in any case.
1735 FAIL_DELETE nonzero means delete it if a compilation step fails;
1736 otherwise delete it in any case. */
1739 record_temp_file (filename, always_delete, fail_delete)
1740 const char *filename;
1744 register char *name;
1745 name = xmalloc (strlen (filename) + 1);
1746 strcpy (name, filename);
1750 register struct temp_file *temp;
1751 for (temp = always_delete_queue; temp; temp = temp->next)
1752 if (! strcmp (name, temp->name))
1755 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1756 temp->next = always_delete_queue;
1758 always_delete_queue = temp;
1765 register struct temp_file *temp;
1766 for (temp = failure_delete_queue; temp; temp = temp->next)
1767 if (! strcmp (name, temp->name))
1770 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1771 temp->next = failure_delete_queue;
1773 failure_delete_queue = temp;
1779 /* Delete all the temporary files whose names we previously recorded. */
1782 delete_if_ordinary (name)
1789 printf ("Delete %s? (y or n) ", name);
1793 while ((c = getchar ()) != '\n' && c != EOF)
1796 if (i == 'y' || i == 'Y')
1798 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1799 if (unlink (name) < 0)
1801 perror_with_name (name);
1805 delete_temp_files ()
1807 register struct temp_file *temp;
1809 for (temp = always_delete_queue; temp; temp = temp->next)
1810 delete_if_ordinary (temp->name);
1811 always_delete_queue = 0;
1814 /* Delete all the files to be deleted on error. */
1817 delete_failure_queue ()
1819 register struct temp_file *temp;
1821 for (temp = failure_delete_queue; temp; temp = temp->next)
1822 delete_if_ordinary (temp->name);
1826 clear_failure_queue ()
1828 failure_delete_queue = 0;
1831 /* Routine to add variables to the environment. We do this to pass
1832 the pathname of the gcc driver, and the directories search to the
1833 collect2 program, which is being run as ld. This way, we can be
1834 sure of executing the right compiler when collect2 wants to build
1835 constructors and destructors. Since the environment variables we
1836 use come from an obstack, we don't have to worry about allocating
1845 #ifndef VMS /* nor about VMS */
1847 extern char **environ;
1848 char **old_environ = environ;
1852 int str_len = strlen (str);
1856 while ((ch = *p++) != '\0' && ch != '=')
1862 /* Search for replacing an existing environment variable, and
1863 count the number of total environment variables. */
1864 for (envp = old_environ; *envp; envp++)
1867 if (!strncmp (str, *envp, name_len))
1874 /* Add a new environment variable */
1875 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1877 memcpy ((char *) (environ + 1), (char *) old_environ,
1878 sizeof (char *) * (num_envs+1));
1883 #endif /* HAVE_PUTENV */
1886 /* Build a list of search directories from PATHS.
1887 PREFIX is a string to prepend to the list.
1888 If CHECK_DIR_P is non-zero we ensure the directory exists.
1889 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1890 It is also used by the --print-search-dirs flag. */
1893 build_search_list (paths, prefix, check_dir_p)
1894 struct path_prefix *paths;
1898 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1900 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1901 int first_time = TRUE;
1902 struct prefix_list *pprefix;
1904 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1906 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1908 int len = strlen (pprefix->prefix);
1912 || is_directory (pprefix->prefix, machine_suffix, 0)))
1915 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1918 obstack_grow (&collect_obstack, pprefix->prefix, len);
1919 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1922 if (just_machine_suffix
1923 && pprefix->require_machine_suffix == 2
1925 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1928 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1931 obstack_grow (&collect_obstack, pprefix->prefix, len);
1932 obstack_grow (&collect_obstack, just_machine_suffix,
1936 if (! pprefix->require_machine_suffix)
1939 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1942 obstack_grow (&collect_obstack, pprefix->prefix, len);
1946 obstack_1grow (&collect_obstack, '\0');
1947 return obstack_finish (&collect_obstack);
1950 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1954 putenv_from_prefixes (paths, env_var)
1955 struct path_prefix *paths;
1956 const char *env_var;
1958 putenv (build_search_list (paths, env_var, 1));
1961 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1962 access to check permissions.
1963 Return 0 if not found, otherwise return its name, allocated with malloc. */
1966 find_a_file (pprefix, name, mode)
1967 struct path_prefix *pprefix;
1972 const char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1973 struct prefix_list *pl;
1974 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1976 #ifdef DEFAULT_ASSEMBLER
1977 if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
1978 name = DEFAULT_ASSEMBLER;
1979 len = strlen(name)+1;
1980 temp = xmalloc (len);
1981 strcpy (temp, name);
1986 #ifdef DEFAULT_LINKER
1987 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
1988 name = DEFAULT_LINKER;
1989 len = strlen(name)+1;
1990 temp = xmalloc (len);
1991 strcpy (temp, name);
1997 len += strlen (machine_suffix);
1999 temp = xmalloc (len);
2001 /* Determine the filename to execute (special case for absolute paths). */
2003 if (IS_DIR_SEPARATOR (*name)
2004 #ifdef HAVE_DOS_BASED_FILESYSTEM
2005 /* Check for disk name on MS-DOS-based systems. */
2006 || (name[0] && name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2010 if (access (name, mode) == 0)
2012 strcpy (temp, name);
2017 for (pl = pprefix->plist; pl; pl = pl->next)
2021 /* Some systems have a suffix for executable files.
2022 So try appending that first. */
2023 if (file_suffix[0] != 0)
2025 strcpy (temp, pl->prefix);
2026 strcat (temp, machine_suffix);
2027 strcat (temp, name);
2028 strcat (temp, file_suffix);
2029 if (access (temp, mode) == 0)
2031 if (pl->used_flag_ptr != 0)
2032 *pl->used_flag_ptr = 1;
2037 /* Now try just the name. */
2038 strcpy (temp, pl->prefix);
2039 strcat (temp, machine_suffix);
2040 strcat (temp, name);
2041 if (access (temp, mode) == 0)
2043 if (pl->used_flag_ptr != 0)
2044 *pl->used_flag_ptr = 1;
2049 /* Certain prefixes are tried with just the machine type,
2050 not the version. This is used for finding as, ld, etc. */
2051 if (just_machine_suffix && pl->require_machine_suffix == 2)
2053 /* Some systems have a suffix for executable files.
2054 So try appending that first. */
2055 if (file_suffix[0] != 0)
2057 strcpy (temp, pl->prefix);
2058 strcat (temp, just_machine_suffix);
2059 strcat (temp, name);
2060 strcat (temp, file_suffix);
2061 if (access (temp, mode) == 0)
2063 if (pl->used_flag_ptr != 0)
2064 *pl->used_flag_ptr = 1;
2069 strcpy (temp, pl->prefix);
2070 strcat (temp, just_machine_suffix);
2071 strcat (temp, name);
2072 if (access (temp, mode) == 0)
2074 if (pl->used_flag_ptr != 0)
2075 *pl->used_flag_ptr = 1;
2080 /* Certain prefixes can't be used without the machine suffix
2081 when the machine or version is explicitly specified. */
2082 if (! pl->require_machine_suffix)
2084 /* Some systems have a suffix for executable files.
2085 So try appending that first. */
2086 if (file_suffix[0] != 0)
2088 strcpy (temp, pl->prefix);
2089 strcat (temp, name);
2090 strcat (temp, file_suffix);
2091 if (access (temp, mode) == 0)
2093 if (pl->used_flag_ptr != 0)
2094 *pl->used_flag_ptr = 1;
2099 strcpy (temp, pl->prefix);
2100 strcat (temp, name);
2101 if (access (temp, mode) == 0)
2103 if (pl->used_flag_ptr != 0)
2104 *pl->used_flag_ptr = 1;
2114 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2115 at the start of the list, otherwise it goes at the end.
2117 If WARN is nonzero, we will warn if no file is found
2118 through this prefix. WARN should point to an int
2119 which will be set to 1 if this entry is used.
2121 COMPONENT is the value to be passed to update_path.
2123 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2124 the complete value of machine_suffix.
2125 2 means try both machine_suffix and just_machine_suffix. */
2128 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2129 struct path_prefix *pprefix;
2131 const char *component;
2133 int require_machine_suffix;
2136 struct prefix_list *pl, **prev;
2139 if (! first && pprefix->plist)
2141 for (pl = pprefix->plist; pl->next; pl = pl->next)
2146 prev = &pprefix->plist;
2148 /* Keep track of the longest prefix */
2150 prefix = update_path (prefix, component);
2151 len = strlen (prefix);
2152 if (len > pprefix->max_len)
2153 pprefix->max_len = len;
2155 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2156 pl->prefix = save_string (prefix, len);
2157 pl->require_machine_suffix = require_machine_suffix;
2158 pl->used_flag_ptr = warn;
2165 pl->next = (struct prefix_list *) 0;
2169 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2172 unused_prefix_warnings (pprefix)
2173 struct path_prefix *pprefix;
2175 struct prefix_list *pl = pprefix->plist;
2179 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2181 if (pl->require_machine_suffix && machine_suffix)
2182 error ("file path prefix `%s%s' never used", pl->prefix,
2185 error ("file path prefix `%s' never used", pl->prefix);
2187 /* Prevent duplicate warnings. */
2188 *pl->used_flag_ptr = 1;
2196 /* Execute the command specified by the arguments on the current line of spec.
2197 When using pipes, this includes several piped-together commands
2198 with `|' between them.
2200 Return 0 if successful, -1 if failed. */
2206 int n_commands; /* # of command. */
2210 const char *prog; /* program name. */
2211 char **argv; /* vector of args. */
2212 int pid; /* pid of process for this command. */
2215 struct command *commands; /* each command buffer with above info. */
2217 /* Count # of piped commands. */
2218 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2219 if (strcmp (argbuf[i], "|") == 0)
2222 /* Get storage for each command. */
2224 = (struct command *) alloca (n_commands * sizeof (struct command));
2226 /* Split argbuf into its separate piped processes,
2227 and record info about each one.
2228 Also search for the programs that are to be run. */
2230 commands[0].prog = argbuf[0]; /* first command. */
2231 commands[0].argv = &argbuf[0];
2232 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2235 commands[0].argv[0] = string;
2237 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2238 if (strcmp (argbuf[i], "|") == 0)
2239 { /* each command. */
2240 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2241 fatal ("-pipe not supported");
2243 argbuf[i] = 0; /* termination of command args. */
2244 commands[n_commands].prog = argbuf[i + 1];
2245 commands[n_commands].argv = &argbuf[i + 1];
2246 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2248 commands[n_commands].argv[0] = string;
2252 argbuf[argbuf_index] = 0;
2254 /* If -v, print what we are about to do, and maybe query. */
2258 /* For help listings, put a blank line between sub-processes. */
2259 if (print_help_list)
2260 fputc ('\n', stderr);
2262 /* Print each piped command as a separate line. */
2263 for (i = 0; i < n_commands ; i++)
2267 for (j = commands[i].argv; *j; j++)
2268 fprintf (stderr, " %s", *j);
2270 /* Print a pipe symbol after all but the last command. */
2271 if (i + 1 != n_commands)
2272 fprintf (stderr, " |");
2273 fprintf (stderr, "\n");
2277 notice ("\nGo ahead? (y or n) ");
2281 while (getchar () != '\n')
2284 if (i != 'y' && i != 'Y')
2289 /* Run each piped subprocess. */
2291 for (i = 0; i < n_commands; i++)
2293 char *errmsg_fmt, *errmsg_arg;
2294 char *string = commands[i].argv[0];
2296 commands[i].pid = pexecute (string, commands[i].argv,
2297 programname, temp_filename,
2298 &errmsg_fmt, &errmsg_arg,
2299 ((i == 0 ? PEXECUTE_FIRST : 0)
2300 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2301 | (string == commands[i].prog
2302 ? PEXECUTE_SEARCH : 0)
2303 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2305 if (commands[i].pid == -1)
2306 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2308 if (string != commands[i].prog)
2314 /* Wait for all the subprocesses to finish.
2315 We don't care what order they finish in;
2316 we know that N_COMMANDS waits will get them all.
2317 Ignore subprocesses that we don't know about,
2318 since they can be spawned by the process that exec'ed us. */
2323 for (i = 0; i < n_commands; )
2329 pid = pwait (commands[i].pid, &status, 0);
2333 for (j = 0; j < n_commands; j++)
2334 if (commands[j].pid == pid)
2339 if (WIFSIGNALED (status))
2341 fatal ("Internal compiler error: program %s got fatal signal %d",
2342 commands[j].prog, WTERMSIG (status));
2346 else if (WIFEXITED (status)
2347 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2357 /* Find all the switches given to us
2358 and make a vector describing them.
2359 The elements of the vector are strings, one per switch given.
2360 If a switch uses following arguments, then the `part1' field
2361 is the switch itself and the `args' field
2362 is a null-terminated vector containing the following arguments.
2363 The `live_cond' field is 1 if the switch is true in a conditional spec,
2364 -1 if false (overridden by a later switch), and is initialized to zero.
2365 The `validated' field is nonzero if any spec has looked at this switch;
2366 if it remains zero at the end of the run, it must be meaningless. */
2376 static struct switchstr *switches;
2378 static int n_switches;
2383 const char *language;
2386 /* Also a vector of input files specified. */
2388 static struct infile *infiles;
2390 static int n_infiles;
2392 /* This counts the number of libraries added by lang_specific_driver, so that
2393 we can tell if there were any user supplied any files or libraries. */
2395 static int added_libraries;
2397 /* And a vector of corresponding output files is made up later. */
2399 static const char **outfiles;
2401 /* Used to track if none of the -B paths are used. */
2404 /* Used to track if standard path isn't used and -b or -V is specified. */
2405 static int warn_std;
2407 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2408 static int *warn_std_ptr = 0;
2410 #if defined(FREEBSD_NATIVE)
2411 #include <objformat.h>
2413 typedef enum { OBJFMT_UNKNOWN, OBJFMT_AOUT, OBJFMT_ELF } objf_t;
2415 static objf_t objformat = OBJFMT_UNKNOWN;
2416 #endif /* FREEBSD_NATIVE */
2418 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2420 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2421 is true if we should look for an executable suffix as well. */
2424 convert_filename (name, do_exe)
2434 len = strlen (name);
2436 #ifdef HAVE_OBJECT_SUFFIX
2437 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2439 && name[len - 2] == '.'
2440 && name[len - 1] == 'o')
2442 obstack_grow (&obstack, name, len - 2);
2443 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2444 name = obstack_finish (&obstack);
2448 #ifdef HAVE_EXECUTABLE_SUFFIX
2449 /* If there is no filetype, make it the executable suffix (which includes
2450 the "."). But don't get confused if we have just "-o". */
2451 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2454 for (i = len - 1; i >= 0; i--)
2455 if (IS_DIR_SEPARATOR (name[i]))
2458 for (i++; i < len; i++)
2462 obstack_grow (&obstack, name, len);
2463 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2464 name = obstack_finish (&obstack);
2471 /* Display the command line switches accepted by gcc. */
2475 printf ("Usage: %s [options] file...\n", programname);
2476 printf ("Options:\n");
2478 printf (" --help Display this information\n");
2480 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2481 printf (" -dumpspecs Display all of the built in spec strings\n");
2482 printf (" -dumpversion Display the version of the compiler\n");
2483 printf (" -dumpmachine Display the compiler's target processor\n");
2484 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2485 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2486 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2487 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2488 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2489 printf (" -print-multi-lib Display the mapping between command line options and\n");
2490 printf (" multiple library search directories\n");
2491 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2492 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2493 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2494 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2495 printf (" -save-temps Do not delete intermediate files\n");
2496 printf (" -pipe Use pipes rather than intermediate files\n");
2497 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2498 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2499 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2500 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2501 printf (" -V <version> Run gcc version number <version>, if installed\n");
2502 printf (" -v Display the programs invoked by the compiler\n");
2503 printf (" -E Preprocess only; do not compile, assemble or link\n");
2504 printf (" -S Compile only; do not assemble or link\n");
2505 printf (" -c Compile and assemble, but do not link\n");
2506 printf (" -o <file> Place the output into <file>\n");
2507 printf (" -x <language> Specify the language of the following input files\n");
2508 printf (" Permissable languages include: c c++ assembler none\n");
2509 printf (" 'none' means revert to the default behaviour of\n");
2510 printf (" guessing the language based on the file's extension\n");
2512 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2513 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2515 printf ("on to these processes the -W<letter> options must be used.\n");
2517 /* The rest of the options are displayed by invocations of the various
2522 add_preprocessor_option (option, len)
2523 const char * option;
2526 n_preprocessor_options++;
2528 if (! preprocessor_options)
2529 preprocessor_options
2530 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
2532 preprocessor_options
2533 = (char **) xrealloc (preprocessor_options,
2534 n_preprocessor_options * sizeof (char *));
2536 preprocessor_options [n_preprocessor_options - 1] =
2537 save_string (option, len);
2541 add_assembler_option (option, len)
2542 const char * option;
2545 n_assembler_options++;
2547 if (! assembler_options)
2549 = (char **) xmalloc (n_assembler_options * sizeof (char *));
2552 = (char **) xrealloc (assembler_options,
2553 n_assembler_options * sizeof (char *));
2555 assembler_options [n_assembler_options - 1] = save_string (option, len);
2559 add_linker_option (option, len)
2560 const char * option;
2565 if (! linker_options)
2567 = (char **) xmalloc (n_linker_options * sizeof (char *));
2570 = (char **) xrealloc (linker_options,
2571 n_linker_options * sizeof (char *));
2573 linker_options [n_linker_options - 1] = save_string (option, len);
2576 /* Create the vector `switches' and its contents.
2577 Store its length in `n_switches'. */
2580 process_command (argc, argv)
2587 char *spec_lang = 0;
2588 int last_language_n_infiles;
2591 int lang_n_infiles = 0;
2593 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2597 added_libraries = 0;
2599 /* Figure compiler version from version string. */
2601 compiler_version = temp1 =
2602 save_string (version_string, strlen (version_string));
2603 for (; *temp1; ++temp1)
2612 /* Set up the default search paths. */
2614 if (gcc_exec_prefix)
2616 int len = strlen (gcc_exec_prefix);
2617 if (len > (int) sizeof ("/lib/gcc-lib/")-1
2618 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
2620 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2621 if (IS_DIR_SEPARATOR (*temp)
2622 && strncmp (temp+1, "lib", 3) == 0
2623 && IS_DIR_SEPARATOR (temp[4])
2624 && strncmp (temp+5, "gcc-lib", 7) == 0)
2625 len -= sizeof ("/lib/gcc-lib/") - 1;
2628 set_std_prefix (gcc_exec_prefix, len);
2629 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2630 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2633 /* COMPILER_PATH and LIBRARY_PATH have values
2634 that are lists of directory names with colons. */
2636 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
2639 const char *startp, *endp;
2640 char *nstore = (char *) alloca (strlen (temp) + 3);
2642 startp = endp = temp;
2645 if (*endp == PATH_SEPARATOR || *endp == 0)
2647 strncpy (nstore, startp, endp-startp);
2649 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2650 else if (!IS_DIR_SEPARATOR (endp[-1]))
2652 nstore[endp-startp] = DIR_SEPARATOR;
2653 nstore[endp-startp+1] = 0;
2656 nstore[endp-startp] = 0;
2657 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2658 add_prefix (&include_prefixes,
2659 concat (nstore, "include", NULL_PTR),
2663 endp = startp = endp + 1;
2670 GET_ENV_PATH_LIST (temp, "LIBRARY_PATH");
2671 if (temp && *cross_compile == '0')
2673 const char *startp, *endp;
2674 char *nstore = (char *) alloca (strlen (temp) + 3);
2676 startp = endp = temp;
2679 if (*endp == PATH_SEPARATOR || *endp == 0)
2681 strncpy (nstore, startp, endp-startp);
2683 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2684 else if (!IS_DIR_SEPARATOR (endp[-1]))
2686 nstore[endp-startp] = DIR_SEPARATOR;
2687 nstore[endp-startp+1] = 0;
2690 nstore[endp-startp] = 0;
2691 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2695 endp = startp = endp + 1;
2702 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2703 GET_ENV_PATH_LIST (temp, "LPATH");
2704 if (temp && *cross_compile == '0')
2706 const char *startp, *endp;
2707 char *nstore = (char *) alloca (strlen (temp) + 3);
2709 startp = endp = temp;
2712 if (*endp == PATH_SEPARATOR || *endp == 0)
2714 strncpy (nstore, startp, endp-startp);
2716 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2717 else if (!IS_DIR_SEPARATOR (endp[-1]))
2719 nstore[endp-startp] = DIR_SEPARATOR;
2720 nstore[endp-startp+1] = 0;
2723 nstore[endp-startp] = 0;
2724 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2728 endp = startp = endp + 1;
2735 #if defined(FREEBSD_NATIVE)
2738 if (getobjformat (buf, sizeof buf, &argc, argv))
2739 if (strcmp (buf, "aout") == 0)
2740 objformat = OBJFMT_AOUT;
2741 else if (strcmp (buf, "elf") == 0)
2742 objformat = OBJFMT_ELF;
2744 fprintf(stderr, "Unrecognized object format: %s\n", buf);
2746 #endif /* FREEBSD_NATIVE */
2748 /* Options specified as if they appeared on the command line. */
2749 temp = getenv ("GCC_OPTIONS");
2750 if ((temp) && (strlen (temp) > 0))
2758 while (isspace (*temp))
2760 len = strlen (temp);
2761 envopts = (char *) xmalloc (len + 1);
2762 strcpy (envopts, temp);
2764 for (i = 0; i < (len - 1); i++)
2765 if ((isspace (envopts[i])) && ! (isspace (envopts[i+1])))
2768 new_argv = (char **) alloca ((optc + argc) * sizeof(char *));
2770 for (i = 0, new_argc = 1; new_argc <= optc; new_argc++)
2772 while (isspace (envopts[i]))
2774 new_argv[new_argc] = envopts + i;
2775 while (!isspace (envopts[i]) && (envopts[i] != '\0'))
2777 envopts[i++] = '\0';
2779 for (i = 1; i < argc; i++)
2780 new_argv[new_argc++] = argv[i];
2786 /* Convert new-style -- options to old-style. */
2787 translate_options (&argc, &argv);
2789 /* Do language-specific adjustment/addition of flags. */
2790 lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2792 /* Scan argv twice. Here, the first time, just count how many switches
2793 there will be in their vector, and how many input files in theirs.
2794 Here we also parse the switches that cc itself uses (e.g. -v). */
2796 for (i = 1; i < argc; i++)
2798 if (! strcmp (argv[i], "-dumpspecs"))
2800 struct spec_list *sl;
2802 for (sl = specs; sl; sl = sl->next)
2803 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2804 if (link_command_spec)
2805 printf ("*link_command:\n%s\n\n", link_command_spec);
2808 else if (! strcmp (argv[i], "-dumpversion"))
2810 printf ("%s\n", spec_version);
2813 else if (! strcmp (argv[i], "-dumpmachine"))
2815 printf ("%s\n", spec_machine);
2818 else if (strcmp (argv[i], "-fhelp") == 0)
2820 /* translate_options () has turned --help into -fhelp. */
2821 print_help_list = 1;
2823 /* We will be passing a dummy file on to the sub-processes. */
2827 add_preprocessor_option ("--help", 6);
2828 add_assembler_option ("--help", 6);
2829 add_linker_option ("--help", 6);
2831 else if (! strcmp (argv[i], "-print-search-dirs"))
2832 print_search_dirs = 1;
2833 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2834 print_file_name = "libgcc.a";
2835 else if (! strncmp (argv[i], "-print-file-name=", 17))
2836 print_file_name = argv[i] + 17;
2837 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2838 print_prog_name = argv[i] + 17;
2839 else if (! strcmp (argv[i], "-print-multi-lib"))
2840 print_multi_lib = 1;
2841 else if (! strcmp (argv[i], "-print-multi-directory"))
2842 print_multi_directory = 1;
2843 else if (! strncmp (argv[i], "-Wa,", 4))
2846 /* Pass the rest of this option to the assembler. */
2848 /* Split the argument at commas. */
2850 for (j = 4; argv[i][j]; j++)
2851 if (argv[i][j] == ',')
2853 add_assembler_option (argv[i] + prev, j - prev);
2857 /* Record the part after the last comma. */
2858 add_assembler_option (argv[i] + prev, j - prev);
2860 else if (! strncmp (argv[i], "-Wp,", 4))
2863 /* Pass the rest of this option to the preprocessor. */
2865 /* Split the argument at commas. */
2867 for (j = 4; argv[i][j]; j++)
2868 if (argv[i][j] == ',')
2870 add_preprocessor_option (argv[i] + prev, j - prev);
2874 /* Record the part after the last comma. */
2875 add_preprocessor_option (argv[i] + prev, j - prev);
2877 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2878 /* The +e options to the C++ front-end. */
2880 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2883 /* Split the argument at commas. */
2884 for (j = 3; argv[i][j]; j++)
2885 n_infiles += (argv[i][j] == ',');
2887 else if (strcmp (argv[i], "-Xlinker") == 0)
2890 fatal ("argument to `-Xlinker' is missing");
2895 else if (strcmp (argv[i], "-l") == 0)
2898 fatal ("argument to `-l' is missing");
2903 else if (strncmp (argv[i], "-l", 2) == 0)
2905 else if (strcmp (argv[i], "-save-temps") == 0)
2907 save_temps_flag = 1;
2910 else if (strcmp (argv[i], "-specs") == 0)
2912 struct user_specs *user = (struct user_specs *)
2913 xmalloc (sizeof (struct user_specs));
2915 fatal ("argument to `-specs' is missing");
2917 user->next = (struct user_specs *)0;
2918 user->filename = argv[i];
2919 if (user_specs_tail)
2920 user_specs_tail->next = user;
2922 user_specs_head = user;
2923 user_specs_tail = user;
2925 else if (strncmp (argv[i], "-specs=", 7) == 0)
2927 struct user_specs *user = (struct user_specs *)
2928 xmalloc (sizeof (struct user_specs));
2929 if (strlen (argv[i]) == 7)
2930 fatal ("argument to `-specs=' is missing");
2932 user->next = (struct user_specs *)0;
2933 user->filename = argv[i]+7;
2934 if (user_specs_tail)
2935 user_specs_tail->next = user;
2937 user_specs_head = user;
2938 user_specs_tail = user;
2940 else if (argv[i][0] == '-' && argv[i][1] != 0)
2942 register char *p = &argv[i][1];
2943 register int c = *p;
2949 if (p[1] == 0 && i + 1 == argc)
2950 fatal ("argument to `-b' is missing");
2952 spec_machine = argv[++i];
2954 spec_machine = p + 1;
2956 warn_std_ptr = &warn_std;
2962 if (p[1] == 0 && i + 1 == argc)
2963 fatal ("argument to `-B' is missing");
2968 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2969 add_prefix (&startfile_prefixes, value, NULL_PTR,
2971 add_prefix (&include_prefixes, concat (value, "include",
2973 NULL_PTR, 1, 0, NULL_PTR);
2975 /* As a kludge, if the arg is "[foo/]stageN/", just add
2976 "[foo/]include" to the include prefix. */
2978 int len = strlen (value);
2981 && (IS_DIR_SEPARATOR (value[len - 8]))))
2982 && strncmp (value + len - 7, "stage", 5) == 0
2983 && ISDIGIT (value[len - 2])
2984 && (IS_DIR_SEPARATOR (value[len - 1])))
2987 add_prefix (&include_prefixes, "include", NULL_PTR,
2991 char *string = xmalloc (len + 1);
2992 strncpy (string, value, len-7);
2993 strcpy (string+len-7, "include");
2994 add_prefix (&include_prefixes, string, NULL_PTR,
3003 case 'v': /* Print our subcommands and print versions. */
3005 /* If they do anything other than exactly `-v', don't set
3006 verbose_flag; rather, continue on to give the error. */
3014 if (p[1] == 0 && i + 1 == argc)
3015 fatal ("argument to `-V' is missing");
3017 spec_version = argv[++i];
3019 spec_version = p + 1;
3020 compiler_version = spec_version;
3021 warn_std_ptr = &warn_std;
3023 /* Validate the version number. Use the same checks
3024 done when inserting it into a spec.
3026 The format of the version string is
3027 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3029 const char *v = compiler_version;
3031 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3032 while (! ISDIGIT (*v))
3035 if (v > compiler_version && v[-1] != '-')
3036 fatal ("invalid version number format");
3038 /* Set V after the first period. */
3039 while (ISDIGIT (*v))
3043 fatal ("invalid version number format");
3046 while (ISDIGIT (*v))
3049 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
3050 fatal ("invalid version number format");
3066 #if defined(HAVE_EXECUTABLE_SUFFIX)
3071 /* Forward scan, just in case -S or -c is specified
3078 if (argv[j][0] == '-')
3080 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3086 else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
3087 j += skip - (argv[j][2] != 0);
3088 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
3095 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3097 argv[i+1] = convert_filename (argv[i+1], ! have_c);
3099 argv[i] = convert_filename (argv[i], ! have_c);
3107 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3108 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3109 else if (WORD_SWITCH_TAKES_ARG (p))
3110 i += WORD_SWITCH_TAKES_ARG (p);
3120 if (have_c && have_o && lang_n_infiles > 1)
3121 fatal ("cannot specify -o with -c or -S and multiple compilations");
3123 /* Set up the search paths before we go looking for config files. */
3125 /* These come before the md prefixes so that we will find gcc's subcommands
3126 (such as cpp) rather than those of the host system. */
3127 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3128 as well as trying the machine and the version. */
3129 #ifdef FREEBSD_NATIVE
3133 n_switches++; /* add implied -maout */
3134 add_prefix (&exec_prefixes, PREFIX"/libexec/aout/", "BINUTILS",
3138 add_prefix (&exec_prefixes, PREFIX"/libexec/elf/", "BINUTILS",
3141 case OBJFMT_UNKNOWN:
3142 fatal ("object format unknown");
3144 #endif /* FREEBSD_NATIVE */
3147 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3148 0, 2, warn_std_ptr);
3149 #ifndef FREEBSD_NATIVE
3150 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3151 0, 2, warn_std_ptr);
3152 #endif /* not FREEBSD_NATIVE */
3155 #ifndef FREEBSD_NATIVE
3156 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3157 0, 1, warn_std_ptr);
3158 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3159 0, 1, warn_std_ptr);
3160 #endif /* not FREEBSD_NATIVE */
3162 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3163 dir_separator_str, NULL_PTR);
3165 /* If tooldir is relative, base it on exec_prefixes. A relative
3166 tooldir lets us move the installed tree as a unit.
3168 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3169 directories, so that we can search both the user specified directory
3170 and the standard place. */
3172 if (!IS_DIR_SEPARATOR (*tooldir_prefix))
3174 if (gcc_exec_prefix)
3176 char *gcc_exec_tooldir_prefix
3177 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3178 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
3180 add_prefix (&exec_prefixes,
3181 concat (gcc_exec_tooldir_prefix, "bin",
3182 dir_separator_str, NULL_PTR),
3183 NULL_PTR, 0, 0, NULL_PTR);
3184 add_prefix (&startfile_prefixes,
3185 concat (gcc_exec_tooldir_prefix, "lib",
3186 dir_separator_str, NULL_PTR),
3187 NULL_PTR, 0, 0, NULL_PTR);
3190 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3191 dir_separator_str, spec_version,
3192 dir_separator_str, tooldir_prefix, NULL_PTR);
3195 #ifndef FREEBSD_NATIVE
3196 add_prefix (&exec_prefixes,
3197 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
3198 "BINUTILS", 0, 0, NULL_PTR);
3199 add_prefix (&startfile_prefixes,
3200 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
3201 "BINUTILS", 0, 0, NULL_PTR);
3202 #endif /* not FREEBSD_NATIVE */
3204 /* More prefixes are enabled in main, after we read the specs file
3205 and determine whether this is cross-compilation or not. */
3208 /* Then create the space for the vectors and scan again. */
3210 switches = ((struct switchstr *)
3211 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3212 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3215 last_language_n_infiles = -1;
3217 /* This, time, copy the text of each switch and store a pointer
3218 to the copy in the vector of switches.
3219 Store all the infiles in their vector. */
3221 #if defined(FREEBSD_NATIVE)
3225 switches[n_switches].part1 = "maout";
3226 switches[n_switches].args = 0;
3227 switches[n_switches].live_cond = 0;
3228 switches[n_switches].validated = 0;
3230 putenv("OBJFORMAT=aout");
3233 putenv("OBJFORMAT=elf");
3235 case OBJFMT_UNKNOWN:
3236 fatal ("object format unknown");
3238 #endif /* FREEBSD_NATIVE */
3240 for (i = 1; i < argc; i++)
3242 /* Just skip the switches that were handled by the preceding loop. */
3243 if (! strncmp (argv[i], "-Wa,", 4))
3245 else if (! strncmp (argv[i], "-Wp,", 4))
3247 else if (! strcmp (argv[i], "-print-search-dirs"))
3249 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3251 else if (! strncmp (argv[i], "-print-file-name=", 17))
3253 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3255 else if (! strcmp (argv[i], "-print-multi-lib"))
3257 else if (! strcmp (argv[i], "-print-multi-directory"))
3259 else if (strcmp (argv[i], "-fhelp") == 0)
3263 /* Create a dummy input file, so that we can pass --help on to
3264 the various sub-processes. */
3265 infiles[n_infiles].language = "c";
3266 infiles[n_infiles++].name = "help-dummy";
3268 /* Preserve the --help switch so that it can be caught by the
3270 switches[n_switches].part1 = "--help";
3271 switches[n_switches].args = 0;
3272 switches[n_switches].live_cond = 0;
3273 switches[n_switches].validated = 0;
3278 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3280 /* Compensate for the +e options to the C++ front-end;
3281 they're there simply for cfront call-compatibility. We do
3282 some magic in default_compilers to pass them down properly.
3283 Note we deliberately start at the `+' here, to avoid passing
3284 -e0 or -e1 down into the linker. */
3285 switches[n_switches].part1 = &argv[i][0];
3286 switches[n_switches].args = 0;
3287 switches[n_switches].live_cond = 0;
3288 switches[n_switches].validated = 0;
3291 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3294 /* Split the argument at commas. */
3296 for (j = 4; argv[i][j]; j++)
3297 if (argv[i][j] == ',')
3299 infiles[n_infiles].language = "*";
3300 infiles[n_infiles++].name
3301 = save_string (argv[i] + prev, j - prev);
3304 /* Record the part after the last comma. */
3305 infiles[n_infiles].language = "*";
3306 infiles[n_infiles++].name = argv[i] + prev;
3308 else if (strcmp (argv[i], "-Xlinker") == 0)
3310 infiles[n_infiles].language = "*";
3311 infiles[n_infiles++].name = argv[++i];
3313 else if (strcmp (argv[i], "-l") == 0)
3314 { /* POSIX allows separation of -l and the lib arg;
3315 canonicalize by concatenating -l with its arg */
3316 infiles[n_infiles].language = "*";
3317 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
3319 else if (strncmp (argv[i], "-l", 2) == 0)
3321 infiles[n_infiles].language = "*";
3322 infiles[n_infiles++].name = argv[i];
3324 else if (strcmp (argv[i], "-specs") == 0)
3326 else if (strncmp (argv[i], "-specs=", 7) == 0)
3328 /* -save-temps overrides -pipe, so that temp files are produced */
3329 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
3330 error ("Warning: -pipe ignored since -save-temps specified");
3331 else if (argv[i][0] == '-' && argv[i][1] != 0)
3333 register char *p = &argv[i][1];
3334 register int c = *p;
3338 if (p[1] == 0 && i + 1 == argc)
3339 fatal ("argument to `-x' is missing");
3341 spec_lang = argv[++i];
3344 if (! strcmp (spec_lang, "none"))
3345 /* Suppress the warning if -xnone comes after the last input
3346 file, because alternate command interfaces like g++ might
3347 find it useful to place -xnone after each input file. */
3350 last_language_n_infiles = n_infiles;
3353 switches[n_switches].part1 = p;
3354 /* Deal with option arguments in separate argv elements. */
3355 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3356 || WORD_SWITCH_TAKES_ARG (p))
3359 int n_args = WORD_SWITCH_TAKES_ARG (p);
3363 /* Count only the option arguments in separate argv elements. */
3364 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3366 if (i + n_args >= argc)
3367 fatal ("argument to `-%s' is missing", p);
3368 switches[n_switches].args
3369 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3371 switches[n_switches].args[j++] = argv[++i];
3372 /* Null-terminate the vector. */
3373 switches[n_switches].args[j] = 0;
3375 else if (index (switches_need_spaces, c))
3377 /* On some systems, ld cannot handle some options without
3378 a space. So split the option from its argument. */
3379 char *part1 = (char *) xmalloc (2);
3383 switches[n_switches].part1 = part1;
3384 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3385 switches[n_switches].args[0] = xmalloc (strlen (p));
3386 strcpy (switches[n_switches].args[0], &p[1]);
3387 switches[n_switches].args[1] = 0;
3390 switches[n_switches].args = 0;
3392 switches[n_switches].live_cond = 0;
3393 switches[n_switches].validated = 0;
3394 /* This is always valid, since gcc.c itself understands it. */
3395 if (!strcmp (p, "save-temps"))
3396 switches[n_switches].validated = 1;
3399 char ch = switches[n_switches].part1[0];
3400 if (ch == 'V' || ch == 'b' || ch == 'B')
3401 switches[n_switches].validated = 1;
3407 #ifdef HAVE_OBJECT_SUFFIX
3408 argv[i] = convert_filename (argv[i], 0);
3411 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3413 perror_with_name (argv[i]);
3418 infiles[n_infiles].language = spec_lang;
3419 infiles[n_infiles++].name = argv[i];
3424 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3425 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3427 switches[n_switches].part1 = 0;
3428 infiles[n_infiles].name = 0;
3431 /* Process a spec string, accumulating and running commands. */
3433 /* These variables describe the input file name.
3434 input_file_number is the index on outfiles of this file,
3435 so that the output file name can be stored for later use by %o.
3436 input_basename is the start of the part of the input file
3437 sans all directory names, and basename_length is the number
3438 of characters starting there excluding the suffix .c or whatever. */
3440 const char *input_filename;
3441 static int input_file_number;
3442 size_t input_filename_length;
3443 static int basename_length;
3444 static const char *input_basename;
3445 static const char *input_suffix;
3447 /* These are variables used within do_spec and do_spec_1. */
3449 /* Nonzero if an arg has been started and not yet terminated
3450 (with space, tab or newline). */
3451 static int arg_going;
3453 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3454 is a temporary file name. */
3455 static int delete_this_arg;
3457 /* Nonzero means %w has been seen; the next arg to be terminated
3458 is the output file name of this compilation. */
3459 static int this_is_output_file;
3461 /* Nonzero means %s has been seen; the next arg to be terminated
3462 is the name of a library file and we should try the standard
3463 search dirs for it. */
3464 static int this_is_library_file;
3466 /* Nonzero means that the input of this command is coming from a pipe. */
3467 static int input_from_pipe;
3469 /* Process the spec SPEC and run the commands specified therein.
3470 Returns 0 if the spec is successfully processed; -1 if failed. */
3480 delete_this_arg = 0;
3481 this_is_output_file = 0;
3482 this_is_library_file = 0;
3483 input_from_pipe = 0;
3485 value = do_spec_1 (spec, 0, NULL_PTR);
3487 /* Force out any unfinished command.
3488 If -pipe, this forces out the last command if it ended in `|'. */
3491 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3494 if (argbuf_index > 0)
3501 /* Process the sub-spec SPEC as a portion of a larger spec.
3502 This is like processing a whole spec except that we do
3503 not initialize at the beginning and we do not supply a
3504 newline by default at the end.
3505 INSWITCH nonzero means don't process %-sequences in SPEC;
3506 in this case, % is treated as an ordinary character.
3507 This is used while substituting switches.
3508 INSWITCH nonzero also causes SPC not to terminate an argument.
3510 Value is zero unless a line was finished
3511 and the command on that line reported an error. */
3514 do_spec_1 (spec, inswitch, soft_matched_part)
3517 const char *soft_matched_part;
3519 register const char *p = spec;
3526 /* If substituting a switch, treat all chars like letters.
3527 Otherwise, NL, SPC, TAB and % are special. */
3528 switch (inswitch ? 'a' : c)
3531 /* End of line: finish any pending argument,
3532 then run the pending command if one has been started. */
3535 obstack_1grow (&obstack, 0);
3536 string = obstack_finish (&obstack);
3537 if (this_is_library_file)
3538 string = find_file (string);
3539 store_arg (string, delete_this_arg, this_is_output_file);
3540 if (this_is_output_file)
3541 outfiles[input_file_number] = string;
3545 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3547 for (i = 0; i < n_switches; i++)
3548 if (!strcmp (switches[i].part1, "pipe"))
3551 /* A `|' before the newline means use a pipe here,
3552 but only if -pipe was specified.
3553 Otherwise, execute now and don't pass the `|' as an arg. */
3556 input_from_pipe = 1;
3557 switches[i].validated = 1;
3564 if (argbuf_index > 0)
3570 /* Reinitialize for a new command, and for a new argument. */
3573 delete_this_arg = 0;
3574 this_is_output_file = 0;
3575 this_is_library_file = 0;
3576 input_from_pipe = 0;
3580 /* End any pending argument. */
3583 obstack_1grow (&obstack, 0);
3584 string = obstack_finish (&obstack);
3585 if (this_is_library_file)
3586 string = find_file (string);
3587 store_arg (string, delete_this_arg, this_is_output_file);
3588 if (this_is_output_file)
3589 outfiles[input_file_number] = string;
3593 obstack_1grow (&obstack, c);
3599 /* Space or tab ends an argument if one is pending. */
3602 obstack_1grow (&obstack, 0);
3603 string = obstack_finish (&obstack);
3604 if (this_is_library_file)
3605 string = find_file (string);
3606 store_arg (string, delete_this_arg, this_is_output_file);
3607 if (this_is_output_file)
3608 outfiles[input_file_number] = string;
3610 /* Reinitialize for a new argument. */
3612 delete_this_arg = 0;
3613 this_is_output_file = 0;
3614 this_is_library_file = 0;
3621 fatal ("Invalid specification! Bug in cc.");
3624 obstack_grow (&obstack, input_basename, basename_length);
3629 delete_this_arg = 2;
3632 /* Dump out the directories specified with LIBRARY_PATH,
3633 followed by the absolute directories
3634 that we search for startfiles. */
3637 struct prefix_list *pl = startfile_prefixes.plist;
3638 size_t bufsize = 100;
3639 char *buffer = (char *) xmalloc (bufsize);
3642 for (; pl; pl = pl->next)
3644 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3645 /* Used on systems which record the specified -L dirs
3646 and use them to search for dynamic linking. */
3647 /* Relative directories always come from -B,
3648 and it is better not to use them for searching
3649 at run time. In particular, stage1 loses */
3650 if (!IS_DIR_SEPARATOR (pl->prefix[0]))
3653 /* Try subdirectory if there is one. */
3654 if (multilib_dir != NULL)
3658 if (strlen (pl->prefix) + strlen (machine_suffix)
3660 bufsize = (strlen (pl->prefix)
3661 + strlen (machine_suffix)) * 2 + 1;
3662 buffer = (char *) xrealloc (buffer, bufsize);
3663 strcpy (buffer, pl->prefix);
3664 strcat (buffer, machine_suffix);
3665 if (is_directory (buffer, multilib_dir, 1))
3667 do_spec_1 ("-L", 0, NULL_PTR);
3668 #ifdef SPACE_AFTER_L_OPTION
3669 do_spec_1 (" ", 0, NULL_PTR);
3671 do_spec_1 (buffer, 1, NULL_PTR);
3672 do_spec_1 (multilib_dir, 1, NULL_PTR);
3673 /* Make this a separate argument. */
3674 do_spec_1 (" ", 0, NULL_PTR);
3677 if (!pl->require_machine_suffix)
3679 if (is_directory (pl->prefix, multilib_dir, 1))
3681 do_spec_1 ("-L", 0, NULL_PTR);
3682 #ifdef SPACE_AFTER_L_OPTION
3683 do_spec_1 (" ", 0, NULL_PTR);
3685 do_spec_1 (pl->prefix, 1, NULL_PTR);
3686 do_spec_1 (multilib_dir, 1, NULL_PTR);
3687 /* Make this a separate argument. */
3688 do_spec_1 (" ", 0, NULL_PTR);
3694 if (is_directory (pl->prefix, machine_suffix, 1))
3696 do_spec_1 ("-L", 0, NULL_PTR);
3697 #ifdef SPACE_AFTER_L_OPTION
3698 do_spec_1 (" ", 0, NULL_PTR);
3700 do_spec_1 (pl->prefix, 1, NULL_PTR);
3701 /* Remove slash from machine_suffix. */
3702 if (strlen (machine_suffix) >= bufsize)
3703 bufsize = strlen (machine_suffix) * 2 + 1;
3704 buffer = (char *) xrealloc (buffer, bufsize);
3705 strcpy (buffer, machine_suffix);
3706 idx = strlen (buffer);
3707 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3708 buffer[idx - 1] = 0;
3709 do_spec_1 (buffer, 1, NULL_PTR);
3710 /* Make this a separate argument. */
3711 do_spec_1 (" ", 0, NULL_PTR);
3714 if (!pl->require_machine_suffix)
3716 if (is_directory (pl->prefix, "", 1))
3718 do_spec_1 ("-L", 0, NULL_PTR);
3719 #ifdef SPACE_AFTER_L_OPTION
3720 do_spec_1 (" ", 0, NULL_PTR);
3722 /* Remove slash from pl->prefix. */
3723 if (strlen (pl->prefix) >= bufsize)
3724 bufsize = strlen (pl->prefix) * 2 + 1;
3725 buffer = (char *) xrealloc (buffer, bufsize);
3726 strcpy (buffer, pl->prefix);
3727 idx = strlen (buffer);
3728 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3729 buffer[idx - 1] = 0;
3730 do_spec_1 (buffer, 1, NULL_PTR);
3731 /* Make this a separate argument. */
3732 do_spec_1 (" ", 0, NULL_PTR);
3741 /* %efoo means report an error with `foo' as error message
3742 and don't execute any more commands for this file. */
3746 while (*p != 0 && *p != '\n') p++;
3747 buf = (char *) alloca (p - q + 1);
3748 strncpy (buf, q, p - q);
3758 if (save_temps_flag)
3760 obstack_grow (&obstack, input_basename, basename_length);
3761 delete_this_arg = 0;
3765 #ifdef MKTEMP_EACH_FILE
3766 /* ??? This has a problem: the total number of
3767 values mktemp can return is limited.
3768 That matters for the names of object files.
3769 In 2.4, do something about that. */
3770 struct temp_name *t;
3772 const char *suffix = p;
3774 if (p[0] == '%' && p[1] == 'O')
3777 /* We don't support extra suffix characters after %O. */
3778 if (*p == '.' || ISALPHA ((unsigned char)*p))
3780 suffix = OBJECT_SUFFIX;
3781 suffix_length = strlen (OBJECT_SUFFIX);
3785 while (*p == '.' || ISALPHA ((unsigned char)*p))
3787 suffix_length = p - suffix;
3790 /* See if we already have an association of %g/%u/%U and
3792 for (t = temp_names; t; t = t->next)
3793 if (t->length == suffix_length
3794 && strncmp (t->suffix, suffix, suffix_length) == 0
3795 && t->unique == (c != 'g'))
3798 /* Make a new association if needed. %u requires one. */
3799 if (t == 0 || c == 'u')
3803 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3804 t->next = temp_names;
3807 t->length = suffix_length;
3808 t->suffix = save_string (suffix, suffix_length);
3809 t->unique = (c != 'g');
3810 temp_filename = make_temp_file (t->suffix);
3811 temp_filename_length = strlen (temp_filename);
3812 t->filename = temp_filename;
3813 t->filename_length = temp_filename_length;
3816 obstack_grow (&obstack, t->filename, t->filename_length);
3817 delete_this_arg = 1;
3819 obstack_grow (&obstack, temp_filename, temp_filename_length);
3820 if (c == 'u' || c == 'U')
3826 sprintf (buff, "%d", unique);
3827 obstack_grow (&obstack, buff, strlen (buff));
3830 delete_this_arg = 1;
3836 obstack_grow (&obstack, input_filename, input_filename_length);
3842 struct prefix_list *pl = include_prefixes.plist;
3844 if (gcc_exec_prefix)
3846 do_spec_1 ("-iprefix", 1, NULL_PTR);
3847 /* Make this a separate argument. */
3848 do_spec_1 (" ", 0, NULL_PTR);
3849 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3850 do_spec_1 (" ", 0, NULL_PTR);
3853 for (; pl; pl = pl->next)
3855 do_spec_1 ("-isystem", 1, NULL_PTR);
3856 /* Make this a separate argument. */
3857 do_spec_1 (" ", 0, NULL_PTR);
3858 do_spec_1 (pl->prefix, 1, NULL_PTR);
3859 do_spec_1 (" ", 0, NULL_PTR);
3866 int max = n_infiles;
3867 max += lang_specific_extra_outfiles;
3869 for (i = 0; i < max; i++)
3871 store_arg (outfiles[i], 0, 0);
3876 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3881 this_is_library_file = 1;
3885 this_is_output_file = 1;
3890 int cur_index = argbuf_index;
3891 /* Handle the {...} following the %W. */
3894 p = handle_braces (p + 1);
3897 /* If any args were output, mark the last one for deletion
3899 if (argbuf_index != cur_index)
3900 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3904 /* %x{OPTION} records OPTION for %X to output. */
3910 /* Skip past the option value and make a copy. */
3915 string = save_string (p1 + 1, p - p1 - 2);
3917 /* See if we already recorded this option. */
3918 for (i = 0; i < n_linker_options; i++)
3919 if (! strcmp (string, linker_options[i]))
3925 /* This option is new; add it. */
3926 add_linker_option (string, strlen (string));
3930 /* Dump out the options accumulated previously using %x. */
3932 for (i = 0; i < n_linker_options; i++)
3934 do_spec_1 (linker_options[i], 1, NULL_PTR);
3935 /* Make each accumulated option a separate argument. */
3936 do_spec_1 (" ", 0, NULL_PTR);
3940 /* Dump out the options accumulated previously using -Wa,. */
3942 for (i = 0; i < n_assembler_options; i++)
3944 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3945 /* Make each accumulated option a separate argument. */
3946 do_spec_1 (" ", 0, NULL_PTR);
3950 /* Dump out the options accumulated previously using -Wp,. */
3952 for (i = 0; i < n_preprocessor_options; i++)
3954 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3955 /* Make each accumulated option a separate argument. */
3956 do_spec_1 (" ", 0, NULL_PTR);
3960 /* Here are digits and numbers that just process
3961 a certain constant string as a spec. */
3964 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3970 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3976 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3982 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3988 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3994 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
4000 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
4006 value = do_spec_1 (link_spec, 0, NULL_PTR);
4012 value = do_spec_1 (lib_spec, 0, NULL_PTR);
4018 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
4025 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
4029 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4033 if (! strncmp (y, "-D", 2))
4034 /* Copy the whole option. */
4035 while (*y && *y != ' ' && *y != '\t')
4037 else if (*y == ' ' || *y == '\t')
4038 /* Copy whitespace to the result. */
4040 /* Don't copy other options. */
4047 value = do_spec_1 (buf, 0, NULL_PTR);
4055 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
4059 /* Copy all of CPP_PREDEFINES into BUF,
4060 but put __ after every -D and at the end of each arg. */
4064 if (! strncmp (y, "-D", 2))
4073 && ! ISUPPER ((unsigned char)*(y+1))))
4075 /* Stick __ at front of macro name. */
4078 /* Arrange to stick __ at the end as well. */
4082 /* Copy the macro name. */
4083 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4092 /* Copy the value given, if any. */
4093 while (*y && *y != ' ' && *y != '\t')
4096 else if (*y == ' ' || *y == '\t')
4097 /* Copy whitespace to the result. */
4099 /* Don't copy -A options */
4105 /* Copy all of CPP_PREDEFINES into BUF,
4106 but put __ after every -D. */
4110 if (! strncmp (y, "-D", 2))
4116 && ! ISUPPER ((unsigned char)*(y+1))))
4118 /* Stick -D__ at front of macro name. */
4124 /* Copy the macro name. */
4125 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4128 /* Copy the value given, if any. */
4129 while (*y && *y != ' ' && *y != '\t')
4134 /* Do not copy this macro - we have just done it before */
4135 while (*y && *y != ' ' && *y != '\t')
4139 else if (*y == ' ' || *y == '\t')
4140 /* Copy whitespace to the result. */
4142 /* Don't copy -A options */
4148 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4152 if (! strncmp (y, "-A", 2))
4153 /* Copy the whole option. */
4154 while (*y && *y != ' ' && *y != '\t')
4156 else if (*y == ' ' || *y == '\t')
4157 /* Copy whitespace to the result. */
4159 /* Don't copy other options. */
4166 value = do_spec_1 (buf, 0, NULL_PTR);
4173 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
4178 /* Here we define characters other than letters and digits. */
4181 p = handle_braces (p);
4187 obstack_1grow (&obstack, '%');
4191 do_spec_1 (soft_matched_part, 1, NULL_PTR);
4192 do_spec_1 (" ", 0, NULL_PTR);
4195 /* Process a string found as the value of a spec given by name.
4196 This feature allows individual machine descriptions
4197 to add and use their own specs.
4198 %[...] modifies -D options the way %P does;
4199 %(...) uses the spec unmodified. */
4201 error ("Warning: use of obsolete %%[ operator in specs");
4204 const char *name = p;
4205 struct spec_list *sl;
4208 /* The string after the S/P is the name of a spec that is to be
4210 while (*p && *p != ')' && *p != ']')
4213 /* See if it's in the list */
4214 for (len = p - name, sl = specs; sl; sl = sl->next)
4215 if (sl->name_len == len && !strncmp (sl->name, name, len))
4217 name = *(sl->ptr_spec);
4219 notice ("Processing spec %c%s%c, which is '%s'\n",
4220 c, sl->name, (c == '(') ? ')' : ']', name);
4229 value = do_spec_1 (name, 0, NULL_PTR);
4235 char *x = (char *) alloca (strlen (name) * 2 + 1);
4237 const char *y = name;
4240 /* Copy all of NAME into BUF, but put __ after
4241 every -D and at the end of each arg, */
4244 if (! strncmp (y, "-D", 2))
4254 else if (flag && (*y == ' ' || *y == '\t' || *y == '='
4255 || *y == '}' || *y == 0))
4268 value = do_spec_1 (buf, 0, NULL_PTR);
4274 /* Discard the closing paren or bracket. */
4282 int c1 = *p++; /* Select first or second version number. */
4283 char *v = compiler_version;
4286 /* The format of the version string is
4287 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4289 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4290 while (! ISDIGIT (*v))
4292 if (v > compiler_version && v[-1] != '-')
4295 /* If desired, advance to second version number. */
4298 /* Set V after the first period. */
4299 while (ISDIGIT (*v))
4306 /* Set Q at the next period or at the end. */
4308 while (ISDIGIT (*q))
4310 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
4313 /* Put that part into the command. */
4314 obstack_grow (&obstack, v, q - v);
4320 if (input_from_pipe)
4321 do_spec_1 ("-", 0, NULL_PTR);
4330 /* Backslash: treat next character as ordinary. */
4335 /* Ordinary character: put it into the current argument. */
4336 obstack_1grow (&obstack, c);
4340 return 0; /* End of string */
4343 /* Return 0 if we call do_spec_1 and that returns -1. */
4347 register const char *p;
4349 const char *filter, *body = NULL, *endbody = NULL;
4353 int include_blanks = 1;
4356 /* A '^' after the open-brace means to not give blanks before args. */
4357 include_blanks = 0, ++p;
4360 /* A `|' after the open-brace means,
4361 if the test fails, output a single minus sign rather than nothing.
4362 This is used in %{|!pipe:...}. */
4366 negate = suffix = 0;
4369 /* A `!' after the open-brace negates the condition:
4370 succeed if the specified switch is not present. */
4374 /* A `.' after the open-brace means test against the current suffix. */
4384 while (*p != ':' && *p != '}' && *p != '|') p++;
4386 if (*p == '|' && pipe_p)
4393 register int count = 1;
4394 register const char *q = p;
4396 while (*q++ != ':') continue;
4412 body = p, endbody = p+1;
4417 int found = (input_suffix != 0
4418 && (long) strlen (input_suffix) == (long)(p - filter)
4419 && strncmp (input_suffix, filter, p - filter) == 0);
4425 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL_PTR) < 0)
4428 else if (p[-1] == '*' && p[0] == '}')
4430 /* Substitute all matching switches as separate args. */
4433 for (i = 0; i < n_switches; i++)
4434 if (!strncmp (switches[i].part1, filter, p - filter)
4435 && check_live_switch (i, p - filter))
4436 give_switch (i, 0, include_blanks);
4440 /* Test for presence of the specified switch. */
4444 /* If name specified ends in *, as in {x*:...},
4445 check for %* and handle that case. */
4446 if (p[-1] == '*' && !negate)
4449 const char *r = body;
4451 /* First see whether we have %*. */
4455 if (*r == '%' && r[1] == '*')
4459 /* If we do, handle that case. */
4462 /* Substitute all matching switches as separate args.
4463 But do this by substituting for %*
4464 in the text that follows the colon. */
4466 unsigned hard_match_len = p - filter - 1;
4467 char *string = save_string (body, endbody - body - 1);
4469 for (i = 0; i < n_switches; i++)
4470 if (!strncmp (switches[i].part1, filter, hard_match_len)
4471 && check_live_switch (i, -1))
4473 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4474 /* Pass any arguments this switch has. */
4475 give_switch (i, 1, 1);
4478 /* We didn't match. Try again. */
4485 /* If name specified ends in *, as in {x*:...},
4486 check for presence of any switch name starting with x. */
4489 for (i = 0; i < n_switches; i++)
4491 unsigned hard_match_len = p - filter - 1;
4493 if (!strncmp (switches[i].part1, filter, hard_match_len)
4494 && check_live_switch (i, hard_match_len))
4500 /* Otherwise, check for presence of exact name specified. */
4503 for (i = 0; i < n_switches; i++)
4505 if (!strncmp (switches[i].part1, filter, p - filter)
4506 && switches[i].part1[p - filter] == 0
4507 && check_live_switch (i, -1))
4515 /* If it is as desired (present for %{s...}, absent for %{!s...})
4516 then substitute either the switch or the specified
4517 conditional text. */
4518 if (present != negate)
4522 give_switch (i, 0, include_blanks);
4526 if (do_spec_1 (save_string (body, endbody - body - 1),
4533 /* Here if a %{|...} conditional fails: output a minus sign,
4534 which means "standard output" or "standard input". */
4535 do_spec_1 ("-", 0, NULL_PTR);
4540 /* We didn't match; try again. */
4547 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4548 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4549 spec, or -1 if either exact match or %* is used.
4551 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4552 whose value does not begin with "no-" is obsoleted by the same value
4553 with the "no-", similarly for a switch with the "no-" prefix. */
4556 check_live_switch (switchnum, prefix_length)
4560 const char *name = switches[switchnum].part1;
4563 /* In the common case of {<at-most-one-letter>*}, a negating
4564 switch would always match, so ignore that case. We will just
4565 send the conflicting switches to the compiler phase. */
4566 if (prefix_length >= 0 && prefix_length <= 1)
4569 /* If we already processed this switch and determined if it was
4570 live or not, return our past determination. */
4571 if (switches[switchnum].live_cond != 0)
4572 return switches[switchnum].live_cond > 0;
4574 /* Now search for duplicate in a manner that depends on the name. */
4578 for (i = switchnum + 1; i < n_switches; i++)
4579 if (switches[i].part1[0] == 'O')
4581 switches[switchnum].validated = 1;
4582 switches[switchnum].live_cond = -1;
4587 case 'W': case 'f': case 'm':
4588 if (! strncmp (name + 1, "no-", 3))
4590 /* We have Xno-YYY, search for XYYY. */
4591 for (i = switchnum + 1; i < n_switches; i++)
4592 if (switches[i].part1[0] == name[0]
4593 && ! strcmp (&switches[i].part1[1], &name[4]))
4595 switches[switchnum].validated = 1;
4596 switches[switchnum].live_cond = -1;
4602 /* We have XYYY, search for Xno-YYY. */
4603 for (i = switchnum + 1; i < n_switches; i++)
4604 if (switches[i].part1[0] == name[0]
4605 && switches[i].part1[1] == 'n'
4606 && switches[i].part1[2] == 'o'
4607 && switches[i].part1[3] == '-'
4608 && !strcmp (&switches[i].part1[4], &name[1]))
4610 switches[switchnum].validated = 1;
4611 switches[switchnum].live_cond = -1;
4618 /* Otherwise the switch is live. */
4619 switches[switchnum].live_cond = 1;
4623 /* Pass a switch to the current accumulating command
4624 in the same form that we received it.
4625 SWITCHNUM identifies the switch; it is an index into
4626 the vector of switches gcc received, which is `switches'.
4627 This cannot fail since it never finishes a command line.
4629 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4631 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4635 give_switch (switchnum, omit_first_word, include_blanks)
4637 int omit_first_word;
4640 if (!omit_first_word)
4642 do_spec_1 ("-", 0, NULL_PTR);
4643 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4646 if (switches[switchnum].args != 0)
4649 for (p = switches[switchnum].args; *p; p++)
4652 do_spec_1 (" ", 0, NULL_PTR);
4653 do_spec_1 (*p, 1, NULL_PTR);
4657 do_spec_1 (" ", 0, NULL_PTR);
4658 switches[switchnum].validated = 1;
4661 /* Search for a file named NAME trying various prefixes including the
4662 user's -B prefix and some standard ones.
4663 Return the absolute file name found. If nothing is found, return NAME. */
4671 /* Try multilib_dir if it is defined. */
4672 if (multilib_dir != NULL)
4676 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4677 strcpy (try, multilib_dir);
4678 strcat (try, dir_separator_str);
4681 newname = find_a_file (&startfile_prefixes, try, R_OK);
4683 /* If we don't find it in the multi library dir, then fall
4684 through and look for it in the normal places. */
4685 if (newname != NULL)
4689 newname = find_a_file (&startfile_prefixes, name, R_OK);
4690 return newname ? newname : name;
4693 /* Determine whether a directory exists. If LINKER, return 0 for
4694 certain fixed names not needed by the linker. If not LINKER, it is
4695 only important to return 0 if the host machine has a small ARG_MAX
4699 is_directory (path1, path2, linker)
4704 int len1 = strlen (path1);
4705 int len2 = strlen (path2);
4706 char *path = (char *) alloca (3 + len1 + len2);
4710 #ifndef SMALL_ARG_MAX
4715 /* Construct the path from the two parts. Ensure the string ends with "/.".
4716 The resulting path will be a directory even if the given path is a
4718 memcpy (path, path1, len1);
4719 memcpy (path + len1, path2, len2);
4720 cp = path + len1 + len2;
4721 if (!IS_DIR_SEPARATOR (cp[-1]))
4722 *cp++ = DIR_SEPARATOR;
4726 #ifndef FREEBSD_NATIVE
4727 /* Exclude directories that the linker is known to search. */
4730 && strcmp (path, concat (dir_separator_str, "lib",
4731 dir_separator_str, ".", NULL_PTR)) == 0)
4733 && strcmp (path, concat (dir_separator_str, "usr",
4734 dir_separator_str, "lib",
4735 dir_separator_str, ".", NULL_PTR)) == 0)))
4737 #endif /* not FREEBSD_NATIVE */
4739 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4742 /* On fatal signals, delete all the temporary files. */
4745 fatal_error (signum)
4748 signal (signum, SIG_DFL);
4749 delete_failure_queue ();
4750 delete_temp_files ();
4751 /* Get the same signal again, this time not handled,
4752 so its normal effect occurs. */
4753 kill (getpid (), signum);
4764 int linker_was_run = 0;
4765 char *explicit_link_files;
4768 struct user_specs *uptr;
4770 p = argv[0] + strlen (argv[0]);
4771 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
4775 #ifdef HAVE_LC_MESSAGES
4776 setlocale (LC_MESSAGES, "");
4778 (void) bindtextdomain (PACKAGE, localedir);
4779 (void) textdomain (PACKAGE);
4781 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4782 signal (SIGINT, fatal_error);
4784 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4785 signal (SIGHUP, fatal_error);
4787 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4788 signal (SIGTERM, fatal_error);
4790 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4791 signal (SIGPIPE, fatal_error);
4795 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4797 obstack_init (&obstack);
4799 /* Build multilib_select, et. al from the separate lines that make up each
4800 multilib selection. */
4802 char **q = multilib_raw;
4805 obstack_init (&multilib_obstack);
4806 while ((p = *q++) != (char *) 0)
4807 obstack_grow (&multilib_obstack, p, strlen (p));
4809 obstack_1grow (&multilib_obstack, 0);
4810 multilib_select = obstack_finish (&multilib_obstack);
4812 q = multilib_matches_raw;
4813 while ((p = *q++) != (char *) 0)
4814 obstack_grow (&multilib_obstack, p, strlen (p));
4816 obstack_1grow (&multilib_obstack, 0);
4817 multilib_matches = obstack_finish (&multilib_obstack);
4821 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4825 obstack_1grow (&multilib_obstack, ' ');
4826 obstack_grow (&multilib_obstack,
4827 multilib_defaults_raw[i],
4828 strlen (multilib_defaults_raw[i]));
4832 obstack_1grow (&multilib_obstack, 0);
4833 multilib_defaults = obstack_finish (&multilib_obstack);
4836 /* Set up to remember the pathname of gcc and any options
4837 needed for collect. We use argv[0] instead of programname because
4838 we need the complete pathname. */
4839 obstack_init (&collect_obstack);
4840 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4841 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4842 putenv (obstack_finish (&collect_obstack));
4844 #ifdef INIT_ENVIRONMENT
4845 /* Set up any other necessary machine specific environment variables. */
4846 putenv (INIT_ENVIRONMENT);
4849 /* Choose directory for temp files. */
4851 #ifndef MKTEMP_EACH_FILE
4852 temp_filename = choose_temp_base ();
4853 temp_filename_length = strlen (temp_filename);
4856 /* Make a table of what switches there are (switches, n_switches).
4857 Make a table of specified input files (infiles, n_infiles).
4858 Decode switches that are handled locally. */
4860 process_command (argc, argv);
4865 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4867 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4868 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4871 for (i = 0; (int)i < n_switches; i++)
4876 obstack_grow (&collect_obstack, " ", 1);
4879 obstack_grow (&collect_obstack, "'-", 2);
4880 q = switches[i].part1;
4881 while ((p = index (q,'\'')))
4883 obstack_grow (&collect_obstack, q, p-q);
4884 obstack_grow (&collect_obstack, "'\\''", 4);
4887 obstack_grow (&collect_obstack, q, strlen (q));
4888 obstack_grow (&collect_obstack, "'", 1);
4890 for (args = switches[i].args; args && *args; args++)
4892 obstack_grow (&collect_obstack, " '", 2);
4894 while ((p = index (q,'\'')))
4896 obstack_grow (&collect_obstack, q, p-q);
4897 obstack_grow (&collect_obstack, "'\\''", 4);
4900 obstack_grow (&collect_obstack, q, strlen (q));
4901 obstack_grow (&collect_obstack, "'", 1);
4904 obstack_grow (&collect_obstack, "\0", 1);
4905 putenv (obstack_finish (&collect_obstack));
4908 /* Initialize the vector of specs to just the default.
4909 This means one element containing 0s, as a terminator. */
4911 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4912 bcopy ((char *) default_compilers, (char *) compilers,
4913 sizeof default_compilers);
4914 n_compilers = n_default_compilers;
4916 /* Read specs from a file if there is one. */
4918 #ifdef FREEBSD_NATIVE
4919 just_machine_suffix = ""; /* I don't support specs, gives determinism */
4920 #else /* FREEBSD_NATIVE */
4921 machine_suffix = concat (spec_machine, dir_separator_str,
4922 spec_version, dir_separator_str, NULL_PTR);
4923 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4924 #endif /* FREEBSD_NATIVE */
4926 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4927 /* Read the specs file unless it is a default one. */
4928 if (specs_file != 0 && strcmp (specs_file, "specs"))
4929 read_specs (specs_file, TRUE);
4933 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4934 for any override of as, ld and libraries. */
4935 specs_file = (char *) alloca (strlen (standard_exec_prefix)
4936 + strlen (just_machine_suffix)
4937 + sizeof ("specs"));
4939 strcpy (specs_file, standard_exec_prefix);
4940 strcat (specs_file, just_machine_suffix);
4941 strcat (specs_file, "specs");
4942 if (access (specs_file, R_OK) == 0)
4943 read_specs (specs_file, TRUE);
4945 /* If not cross-compiling, look for startfiles in the standard places. */
4946 if (*cross_compile == '0')
4948 #ifdef MD_EXEC_PREFIX
4949 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4950 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4953 #ifdef MD_STARTFILE_PREFIX
4954 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4958 #ifdef MD_STARTFILE_PREFIX_1
4959 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4963 /* If standard_startfile_prefix is relative, base it on
4964 standard_exec_prefix. This lets us move the installed tree
4965 as a unit. If GCC_EXEC_PREFIX is defined, base
4966 standard_startfile_prefix on that as well. */
4967 if (IS_DIR_SEPARATOR (*standard_startfile_prefix)
4968 || *standard_startfile_prefix == '$'
4969 #ifdef HAVE_DOS_BASED_FILESYSTEM
4970 /* Check for disk name on MS-DOS-based systems. */
4971 || (standard_startfile_prefix[1] == ':'
4972 && (IS_DIR_SEPARATOR (standard_startfile_prefix[2])))
4975 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4979 if (gcc_exec_prefix)
4980 add_prefix (&startfile_prefixes,
4981 concat (gcc_exec_prefix, machine_suffix,
4982 standard_startfile_prefix, NULL_PTR),
4983 NULL_PTR, 0, 0, NULL_PTR);
4984 add_prefix (&startfile_prefixes,
4985 concat (standard_exec_prefix,
4987 standard_startfile_prefix, NULL_PTR),
4988 NULL_PTR, 0, 0, NULL_PTR);
4991 #ifndef FREEBSD_NATIVE
4992 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4993 "BINUTILS", 0, 0, NULL_PTR);
4994 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4995 "BINUTILS", 0, 0, NULL_PTR);
4996 #endif /* FREEBSD_NATIVE */
4997 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4998 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
5003 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix) && gcc_exec_prefix)
5004 add_prefix (&startfile_prefixes,
5005 concat (gcc_exec_prefix, machine_suffix,
5006 standard_startfile_prefix, NULL_PTR),
5007 "BINUTILS", 0, 0, NULL_PTR);
5008 #ifdef CROSS_STARTFILE_PREFIX
5009 add_prefix (&startfile_prefixes, CROSS_STARTFILE_PREFIX, "BINUTILS",
5014 /* Process any user specified specs in the order given on the command
5016 for (uptr = user_specs_head; uptr; uptr = uptr->next)
5018 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
5019 read_specs (filename ? filename : uptr->filename, FALSE);
5022 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
5023 if (gcc_exec_prefix)
5025 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
5026 + strlen (spec_version)
5027 + strlen (spec_machine) + 3);
5028 strcpy (temp, gcc_exec_prefix);
5029 strcat (temp, spec_machine);
5030 strcat (temp, dir_separator_str);
5031 strcat (temp, spec_version);
5032 strcat (temp, dir_separator_str);
5033 gcc_exec_prefix = temp;
5036 /* Now we have the specs.
5037 Set the `valid' bits for switches that match anything in any spec. */
5039 validate_all_switches ();
5041 /* Now that we have the switches and the specs, set
5042 the subdirectory based on the options. */
5043 set_multilib_dir ();
5045 /* Warn about any switches that no pass was interested in. */
5047 for (i = 0; (int)i < n_switches; i++)
5048 if (! switches[i].validated)
5049 error ("unrecognized option `-%s'", switches[i].part1);
5051 /* Obey some of the options. */
5053 if (print_search_dirs)
5055 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
5056 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
5057 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
5061 if (print_file_name)
5063 printf ("%s\n", find_file (print_file_name));
5067 if (print_prog_name)
5069 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
5070 printf ("%s\n", (newname ? newname : print_prog_name));
5074 if (print_multi_lib)
5076 print_multilib_info ();
5080 if (print_multi_directory)
5082 if (multilib_dir == NULL)
5085 printf ("%s\n", multilib_dir);
5089 if (print_help_list)
5095 printf ("\nFor bug reporting instructions, please see:\n");
5096 printf ("%s.\n", GCCBUGURL);
5101 /* We do not exit here. Instead we have created a fake input file
5102 called 'help-dummy' which needs to be compiled, and we pass this
5103 on the the various sub-processes, along with the --help switch. */
5110 /* compiler_version is truncated at the first space when initialized
5111 from version string, so truncate version_string at the first space
5112 before comparing. */
5113 for (n = 0; version_string[n]; n++)
5114 if (version_string[n] == ' ')
5117 if (! strncmp (version_string, compiler_version, n)
5118 && compiler_version[n] == 0)
5119 notice ("gcc version %s\n", version_string);
5121 notice ("gcc driver version %s executing gcc version %s\n",
5122 version_string, compiler_version);
5128 if (n_infiles == added_libraries)
5129 fatal ("No input files specified");
5131 /* Make a place to record the compiler output file names
5132 that correspond to the input files. */
5135 i += lang_specific_extra_outfiles;
5136 outfiles = (const char **) xmalloc (i * sizeof (char *));
5137 bzero ((char *) outfiles, i * sizeof (char *));
5139 /* Record which files were specified explicitly as link input. */
5141 explicit_link_files = xmalloc (n_infiles);
5142 bzero (explicit_link_files, n_infiles);
5144 for (i = 0; (int)i < n_infiles; i++)
5146 register struct compiler *cp = 0;
5147 int this_file_error = 0;
5149 /* Tell do_spec what to substitute for %i. */
5151 input_filename = infiles[i].name;
5152 input_filename_length = strlen (input_filename);
5153 input_file_number = i;
5155 /* Use the same thing in %o, unless cp->spec says otherwise. */
5157 outfiles[i] = input_filename;
5159 /* Figure out which compiler from the file's suffix. */
5161 cp = lookup_compiler (infiles[i].name, input_filename_length,
5162 infiles[i].language);
5166 /* Ok, we found an applicable compiler. Run its spec. */
5167 /* First say how much of input_filename to substitute for %b */
5168 register const char *p;
5171 if (cp->spec[0][0] == '#')
5173 error ("%s: %s compiler not installed on this system",
5174 input_filename, &cp->spec[0][1]);
5175 this_file_error = 1;
5179 input_basename = input_filename;
5180 for (p = input_filename; *p; p++)
5181 if (IS_DIR_SEPARATOR (*p))
5182 input_basename = p + 1;
5184 /* Find a suffix starting with the last period,
5185 and set basename_length to exclude that suffix. */
5186 basename_length = strlen (input_basename);
5187 p = input_basename + basename_length;
5188 while (p != input_basename && *p != '.') --p;
5189 if (*p == '.' && p != input_basename)
5191 basename_length = p - input_basename;
5192 input_suffix = p + 1;
5198 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5200 len += strlen (cp->spec[j]);
5203 char *p1 = (char *) xmalloc (len + 1);
5206 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
5209 strcpy (p1 + len, cp->spec[j]);
5210 len += strlen (cp->spec[j]);
5213 value = do_spec (p1);
5217 this_file_error = 1;
5221 /* If this file's name does not contain a recognized suffix,
5222 record it as explicit linker input. */
5225 explicit_link_files[i] = 1;
5227 /* Clear the delete-on-failure queue, deleting the files in it
5228 if this compilation failed. */
5230 if (this_file_error)
5232 delete_failure_queue ();
5235 /* If this compilation succeeded, don't delete those files later. */
5236 clear_failure_queue ();
5239 if (error_count == 0)
5241 /* Make sure INPUT_FILE_NUMBER points to first available open
5243 input_file_number = n_infiles;
5244 if (lang_specific_pre_link ())
5248 /* Run ld to link all the compiler output files. */
5250 if (error_count == 0)
5252 int tmp = execution_count;
5254 /* We'll use ld if we can't find collect2. */
5255 if (! strcmp (linker_name_spec, "collect2"))
5257 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
5259 linker_name_spec = "ld";
5261 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5263 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
5264 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
5266 value = do_spec (link_command_spec);
5269 linker_was_run = (tmp != execution_count);
5272 /* Warn if a -B option was specified but the prefix was never used. */
5273 unused_prefix_warnings (&exec_prefixes);
5274 unused_prefix_warnings (&startfile_prefixes);
5276 /* If options said don't run linker,
5277 complain about input files to be given to the linker. */
5279 if (! linker_was_run && error_count == 0)
5280 for (i = 0; (int)i < n_infiles; i++)
5281 if (explicit_link_files[i])
5282 error ("%s: linker input file unused since linking not done",
5285 /* Delete some or all of the temporary files we made. */
5288 delete_failure_queue ();
5289 delete_temp_files ();
5291 if (print_help_list)
5293 printf ("\nFor bug reporting instructions, please see:\n");
5294 printf ("%s\n", GCCBUGURL);
5297 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
5302 /* Find the proper compilation spec for the file name NAME,
5303 whose length is LENGTH. LANGUAGE is the specified language,
5304 or 0 if this file is to be passed to the linker. */
5306 static struct compiler *
5307 lookup_compiler (name, length, language)
5310 const char *language;
5312 struct compiler *cp;
5314 /* If this was specified by the user to be a linker input, indicate that. */
5315 if (language != 0 && language[0] == '*')
5318 /* Otherwise, look for the language, if one is spec'd. */
5321 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5322 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
5325 error ("language %s not recognized", language);
5329 /* Look for a suffix. */
5330 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
5332 if (/* The suffix `-' matches only the file name `-'. */
5333 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
5334 || (strlen (cp->suffix) < length
5335 /* See if the suffix matches the end of NAME. */
5337 && ((!strcmp (cp->suffix,
5338 name + length - strlen (cp->suffix))
5339 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5340 && !strcasecmp (cp->suffix,
5341 name + length - strlen (cp->suffix)))
5343 && !strcmp (cp->suffix,
5344 name + length - strlen (cp->suffix))
5348 if (cp->spec[0][0] == '@')
5350 struct compiler *new;
5352 /* An alias entry maps a suffix to a language.
5353 Search for the language; pass 0 for NAME and LENGTH
5354 to avoid infinite recursion if language not found.
5355 Construct the new compiler spec. */
5356 language = cp->spec[0] + 1;
5357 new = (struct compiler *) xmalloc (sizeof (struct compiler));
5358 new->suffix = cp->suffix;
5359 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
5360 (char *) new->spec, sizeof new->spec);
5364 /* A non-alias entry: return it. */
5376 register PTR value = (PTR) malloc (size);
5378 fatal ("virtual memory exhausted");
5383 xrealloc (old, size)
5389 ptr = (PTR) realloc (old, size);
5391 ptr = (PTR) malloc (size);
5393 fatal ("virtual memory exhausted");
5398 save_string (s, len)
5402 register char *result = xmalloc (len + 1);
5404 bcopy (s, result, len);
5410 pfatal_with_name (name)
5413 perror_with_name (name);
5414 delete_temp_files ();
5419 perror_with_name (name)
5422 error ("%s: %s", name, xstrerror (errno));
5426 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5427 const char *errmsg_fmt;
5428 const char *errmsg_arg;
5432 int save_errno = errno;
5434 /* Space for trailing '\0' is in %s. */
5435 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5436 sprintf (msg, errmsg_fmt, errmsg_arg);
5442 pfatal_with_name (errmsg_fmt);
5445 /* More 'friendly' abort that prints the line and file.
5446 config.h can #define abort fancy_abort if you like that sort of thing. */
5451 fatal ("Internal gcc abort.");
5454 /* Output an error message and exit */
5457 fatal VPROTO((const char *msgid, ...))
5459 #ifndef ANSI_PROTOTYPES
5464 VA_START (ap, msgid);
5466 #ifndef ANSI_PROTOTYPES
5467 msgid = va_arg (ap, const char *);
5470 fprintf (stderr, "%s: ", programname);
5471 vfprintf (stderr, _(msgid), ap);
5473 fprintf (stderr, "\n");
5474 delete_temp_files ();
5479 error VPROTO((const char *msgid, ...))
5481 #ifndef ANSI_PROTOTYPES
5486 VA_START (ap, msgid);
5488 #ifndef ANSI_PROTOTYPES
5489 msgid = va_arg (ap, const char *);
5492 fprintf (stderr, "%s: ", programname);
5493 vfprintf (stderr, _(msgid), ap);
5496 fprintf (stderr, "\n");
5500 notice VPROTO((const char *msgid, ...))
5502 #ifndef ANSI_PROTOTYPES
5507 VA_START (ap, msgid);
5509 #ifndef ANSI_PROTOTYPES
5510 msgid = va_arg (ap, const char *);
5513 vfprintf (stderr, _(msgid), ap);
5519 validate_all_switches ()
5521 struct compiler *comp;
5522 register const char *p;
5524 struct spec_list *spec;
5526 for (comp = compilers; comp->spec[0]; comp++)
5529 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5533 if (c == '%' && *p == '{')
5534 /* We have a switch spec. */
5535 validate_switches (p + 1);
5539 /* look through the linked list of specs read from the specs file */
5540 for (spec = specs; spec ; spec = spec->next)
5542 p = *(spec->ptr_spec);
5544 if (c == '%' && *p == '{')
5545 /* We have a switch spec. */
5546 validate_switches (p + 1);
5549 p = link_command_spec;
5551 if (c == '%' && *p == '{')
5552 /* We have a switch spec. */
5553 validate_switches (p + 1);
5556 /* Look at the switch-name that comes after START
5557 and mark as valid all supplied switches that match it. */
5560 validate_switches (start)
5563 register const char *p = start;
5578 while (*p != ':' && *p != '}') p++;
5582 else if (p[-1] == '*')
5584 /* Mark all matching switches as valid. */
5586 for (i = 0; i < n_switches; i++)
5587 if (!strncmp (switches[i].part1, filter, p - filter))
5588 switches[i].validated = 1;
5592 /* Mark an exact matching switch as valid. */
5593 for (i = 0; i < n_switches; i++)
5595 if (!strncmp (switches[i].part1, filter, p - filter)
5596 && switches[i].part1[p - filter] == 0)
5597 switches[i].validated = 1;
5602 /* Check whether a particular argument was used. The first time we
5603 canonicalize the switches to keep only the ones we care about. */
5617 static struct mswitchstr *mswitches;
5618 static int n_mswitches;
5623 struct mswitchstr *matches;
5627 /* Break multilib_matches into the component strings of string and replacement
5629 for (q = multilib_matches; *q != '\0'; q++)
5633 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5635 q = multilib_matches;
5646 matches[i].len = q - matches[i].str;
5648 matches[i].replace = ++q;
5649 while (*q != ';' && *q != '\0')
5655 matches[i].rep_len = q - matches[i].replace;
5663 /* Now build a list of the replacement string for switches that we care
5664 about. Make sure we allocate at least one entry. This prevents
5665 xmalloc from calling fatal, and prevents us from re-executing this
5668 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5669 * (n_switches ? n_switches : 1));
5670 for (i = 0; i < n_switches; i++)
5672 int xlen = strlen (switches[i].part1);
5673 for (j = 0; j < cnt; j++)
5674 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5676 mswitches[n_mswitches].str = matches[j].replace;
5677 mswitches[n_mswitches].len = matches[j].rep_len;
5678 mswitches[n_mswitches].replace = (char *)0;
5679 mswitches[n_mswitches].rep_len = 0;
5686 for (i = 0; i < n_mswitches; i++)
5687 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5694 default_arg (p, len)
5700 for (start = multilib_defaults; *start != '\0'; start = end+1)
5702 while (*start == ' ' || *start == '\t')
5708 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5711 if ((end - start) == len && strncmp (p, start, len) == 0)
5721 /* Work out the subdirectory to use based on the
5722 options. The format of multilib_select is a list of elements.
5723 Each element is a subdirectory name followed by a list of options
5724 followed by a semicolon. gcc will consider each line in turn. If
5725 none of the options beginning with an exclamation point are
5726 present, and all of the other options are present, that
5727 subdirectory will be used. */
5732 char *p = multilib_select;
5734 char *this_path, *this_arg;
5740 /* Ignore newlines. */
5747 /* Get the initial path. */
5755 this_path_len = p - this_path;
5757 /* Check the arguments. */
5772 while (*p != ' ' && *p != ';')
5779 if (*this_arg != '!')
5787 /* If this is a default argument, we can just ignore it.
5788 This is true even if this_arg begins with '!'. Beginning
5789 with '!' does not mean that this argument is necessarily
5790 inappropriate for this library: it merely means that
5791 there is a more specific library which uses this
5792 argument. If this argument is a default, we need not
5793 consider that more specific library. */
5794 if (! default_arg (this_arg, p - this_arg))
5796 ok = used_arg (this_arg, p - this_arg);
5807 if (this_path_len != 1
5808 || this_path[0] != '.')
5810 char * new_multilib_dir = xmalloc (this_path_len + 1);
5811 strncpy (new_multilib_dir, this_path, this_path_len);
5812 new_multilib_dir[this_path_len] = '\0';
5813 multilib_dir = new_multilib_dir;
5822 /* Print out the multiple library subdirectory selection
5823 information. This prints out a series of lines. Each line looks
5824 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5825 required. Only the desired options are printed out, the negative
5826 matches. The options are print without a leading dash. There are
5827 no spaces to make it easy to use the information in the shell.
5828 Each subdirectory is printed only once. This assumes the ordering
5829 generated by the genmultilib script. */
5832 print_multilib_info ()
5834 char *p = multilib_select;
5835 char *last_path = 0, *this_path;
5837 int last_path_len = 0;
5841 /* Ignore newlines. */
5848 /* Get the initial path. */
5857 /* If this is a duplicate, skip it. */
5858 skip = (last_path != 0 && p - this_path == last_path_len
5859 && ! strncmp (last_path, this_path, last_path_len));
5861 last_path = this_path;
5862 last_path_len = p - this_path;
5864 /* If this directory requires any default arguments, we can skip
5865 it. We will already have printed a directory identical to
5866 this one which does not require that default argument. */
5884 while (*q != ' ' && *q != ';')
5892 && default_arg (arg, q - arg))
5907 for (p1 = last_path; p1 < p; p1++)
5926 use_arg = *p != '!';
5931 while (*p != ' ' && *p != ';')
5946 /* If there are extra options, print them now */
5947 if (multilib_extra && *multilib_extra)
5949 int print_at = TRUE;
5952 for (q = multilib_extra; *q != '\0'; q++)