1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!! */
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers. It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec". */
43 #define exit __posix_exit
46 /* By default there is no special suffix for executables. */
47 #ifdef EXECUTABLE_SUFFIX
48 #define HAVE_EXECUTABLE_SUFFIX
50 #define EXECUTABLE_SUFFIX ""
53 /* By default, the suffix for object files is ".o". */
55 #define HAVE_OBJECT_SUFFIX
57 #define OBJECT_SUFFIX ".o"
60 /* By default, colon separates directories in a path. */
61 #ifndef PATH_SEPARATOR
62 #define PATH_SEPARATOR ':'
66 #define DIR_SEPARATOR '/'
69 /* Define IS_DIR_SEPARATOR. */
70 #ifndef DIR_SEPARATOR_2
71 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
72 #else /* DIR_SEPARATOR_2 */
73 # define IS_DIR_SEPARATOR(ch) \
74 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
75 #endif /* DIR_SEPARATOR_2 */
77 static char dir_separator_str
[] = {DIR_SEPARATOR
, 0};
79 #define obstack_chunk_alloc xmalloc
80 #define obstack_chunk_free free
82 #ifndef GET_ENV_PATH_LIST
83 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
87 #define kill(p,s) raise(s)
90 /* If a stage of compilation returns an exit status >= 1,
91 compilation of that file ceases. */
93 #define MIN_FATAL_STATUS 1
95 /* Flag saying to print the directories gcc will search through looking for
96 programs, libraries, etc. */
98 static int print_search_dirs
;
100 /* Flag saying to print the full filename of this file
101 as found through our usual search mechanism. */
103 static const char *print_file_name
= NULL
;
105 /* As print_file_name, but search for executable file. */
107 static const char *print_prog_name
= NULL
;
109 /* Flag saying to print the relative path we'd use to
110 find libgcc.a given the current compiler flags. */
112 static int print_multi_directory
;
114 /* Flag saying to print the list of subdirectories and
115 compiler flags used to select them in a standard form. */
117 static int print_multi_lib
;
119 /* Flag saying to print the command line options understood by gcc and its
122 static int print_help_list
;
124 /* Flag indicating whether we should print the command and arguments */
126 static int verbose_flag
;
128 /* Nonzero means write "temp" files in source directory
129 and use the source file's name in them, and don't delete them. */
131 static int save_temps_flag
;
133 /* The compiler version. */
135 static char *compiler_version
;
137 /* The target version specified with -V */
139 static char *spec_version
= DEFAULT_TARGET_VERSION
;
141 /* The target machine specified with -b. */
143 static const char *spec_machine
= DEFAULT_TARGET_MACHINE
;
145 /* Nonzero if cross-compiling.
146 When -b is used, the value comes from the `specs' file. */
149 static char *cross_compile
= "1";
151 static char *cross_compile
= "0";
154 /* The number of errors that have occurred; the link phase will not be
155 run if this is non-zero. */
156 static int error_count
= 0;
158 /* This is the obstack which we use to allocate many strings. */
160 static struct obstack obstack
;
162 /* This is the obstack to build an environment variable to pass to
163 collect2 that describes all of the relevant switches of what to
164 pass the compiler in building the list of pointers to constructors
167 static struct obstack collect_obstack
;
169 extern char *version_string
;
171 /* Forward declaration for prototypes. */
174 static void init_spec
PROTO((void));
175 static void read_specs
PROTO((const char *, int));
176 static void set_spec
PROTO((const char *, const char *));
177 static struct compiler
*lookup_compiler
PROTO((const char *, size_t, const char *));
178 static char *build_search_list
PROTO((struct path_prefix
*, const char *, int));
179 static void putenv_from_prefixes
PROTO((struct path_prefix
*, const char *));
180 static char *find_a_file
PROTO((struct path_prefix
*, const char *, int));
181 static void add_prefix
PROTO((struct path_prefix
*, const char *,
182 const char *, int, int, int *));
183 static char *skip_whitespace
PROTO((char *));
184 static void record_temp_file
PROTO((const char *, int, int));
185 static void delete_if_ordinary
PROTO((const char *));
186 static void delete_temp_files
PROTO((void));
187 static void delete_failure_queue
PROTO((void));
188 static void clear_failure_queue
PROTO((void));
189 static int check_live_switch
PROTO((int, int));
190 static const char *handle_braces
PROTO((const char *));
191 static char *save_string
PROTO((const char *, int));
192 extern int do_spec
PROTO((const char *));
193 static int do_spec_1
PROTO((const char *, int, const char *));
194 static const char *find_file
PROTO((const char *));
195 static int is_directory
PROTO((const char *, const char *, int));
196 static void validate_switches
PROTO((const char *));
197 static void validate_all_switches
PROTO((void));
198 static void give_switch
PROTO((int, int, int));
199 static int used_arg
PROTO((const char *, int));
200 static int default_arg
PROTO((const char *, int));
201 static void set_multilib_dir
PROTO((void));
202 static void print_multilib_info
PROTO((void));
203 static void pfatal_with_name
PROTO((const char *)) ATTRIBUTE_NORETURN
;
204 static void perror_with_name
PROTO((const char *));
205 static void pfatal_pexecute
PROTO((const char *, const char *))
207 static void error
PVPROTO((const char *, ...))
209 static void notice
PVPROTO((const char *, ...))
211 static void display_help
PROTO((void));
212 static void add_preprocessor_option
PROTO ((const char *, int));
213 static void add_assembler_option
PROTO ((const char *, int));
214 static void add_linker_option
PROTO ((const char *, int));
215 static void process_command
PROTO ((int, char **));
216 static int execute
PROTO ((void));
217 static void unused_prefix_warnings
PROTO ((struct path_prefix
*));
218 static void clear_args
PROTO ((void));
219 static void fatal_error
PROTO ((int));
221 void fancy_abort
PROTO((void)) ATTRIBUTE_NORETURN
;
223 /* Called before processing to change/add/remove arguments. */
224 extern void lang_specific_driver
PROTO ((void (*) PVPROTO((const char *, ...)),
225 int *, char ***, int *));
227 /* Called before linking. Returns 0 on success and -1 on failure. */
228 extern int lang_specific_pre_link ();
230 /* Number of extra output files that lang_specific_pre_link may generate. */
231 extern int lang_specific_extra_outfiles
;
233 /* Specs are strings containing lines, each of which (if not blank)
234 is made up of a program name, and arguments separated by spaces.
235 The program name must be exact and start from root, since no path
236 is searched and it is unreliable to depend on the current working directory.
237 Redirection of input or output is not supported; the subprograms must
238 accept filenames saying what files to read and write.
240 In addition, the specs can contain %-sequences to substitute variable text
241 or for conditional text. Here is a table of all defined %-sequences.
242 Note that spaces are not generated automatically around the results of
243 expanding these sequences; therefore, you can concatenate them together
244 or with constant text in a single argument.
246 %% substitute one % into the program name or argument.
247 %i substitute the name of the input file being processed.
248 %b substitute the basename of the input file being processed.
249 This is the substring up to (and not including) the last period
250 and not including the directory.
252 substitute a file name that has suffix SUFFIX and is chosen
253 once per compilation, and mark the argument a la %d. To reduce
254 exposure to denial-of-service attacks, the file name is now
255 chosen in a way that is hard to predict even when previously
256 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
257 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
258 the regexp "[.A-Za-z]*" or the special string "%O", which is
259 treated exactly as if %O had been pre-processed. Previously, %g
260 was simply substituted with a file name chosen once per compilation,
261 without regard to any appended suffix (which was therefore treated
262 just like ordinary text), making such attacks more likely to succeed.
264 like %g, but generates a new temporary file name even if %uSUFFIX
267 substitutes the last file name generated with %uSUFFIX, generating a
268 new one if there is no such last file name. In the absence of any
269 %uSUFFIX, this is just like %gSUFFIX, except they don't share
270 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
271 would involve the generation of two distinct file names, one
272 for each `%g.s' and another for each `%U.s'. Previously, %U was
273 simply substituted with a file name chosen for the previous %u,
274 without regard to any appended suffix.
275 %d marks the argument containing or following the %d as a
276 temporary file name, so that that file will be deleted if CC exits
277 successfully. Unlike %g, this contributes no text to the argument.
278 %w marks the argument containing or following the %w as the
279 "output file" of this compilation. This puts the argument
280 into the sequence of arguments that %o will substitute later.
282 like %{...} but mark last argument supplied within
283 as a file to be deleted on failure.
284 %o substitutes the names of all the output files, with spaces
285 automatically placed around them. You should write spaces
286 around the %o as well or the results are undefined.
287 %o is for use in the specs for running the linker.
288 Input files whose names have no recognized suffix are not compiled
289 at all, but they are included among the output files, so they will
291 %O substitutes the suffix for object files. Note that this is
292 handled specially when it immediately follows %g, %u, or %U,
293 because of the need for those to form complete file names. The
294 handling is such that %O is treated exactly as if it had already
295 been substituted, except that %g, %u, and %U do not currently
296 support additional SUFFIX characters following %O as they would
297 following, for example, `.o'.
298 %p substitutes the standard macro predefinitions for the
299 current target machine. Use this when running cpp.
300 %P like %p, but puts `__' before and after the name of each macro.
301 (Except macros that already have __.)
303 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
304 %s current argument is the name of a library or startup file of some sort.
305 Search for that file in a standard list of directories
306 and substitute the full name found.
307 %eSTR Print STR as an error message. STR is terminated by a newline.
308 Use this when inconsistent options are detected.
309 %x{OPTION} Accumulate an option for %X.
310 %X Output the accumulated linker options specified by compilations.
311 %Y Output the accumulated assembler options specified by compilations.
312 %Z Output the accumulated preprocessor options specified by compilations.
313 %v1 Substitute the major version number of GCC.
314 (For version 2.5.n, this is 2.)
315 %v2 Substitute the minor version number of GCC.
316 (For version 2.5.n, this is 5.)
317 %a process ASM_SPEC as a spec.
318 This allows config.h to specify part of the spec for running as.
319 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
320 used here. This can be used to run a post-processor after the
321 assembler has done its job.
322 %D Dump out a -L option for each directory in startfile_prefixes.
323 If multilib_dir is set, extra entries are generated with it affixed.
324 %l process LINK_SPEC as a spec.
325 %L process LIB_SPEC as a spec.
326 %G process LIBGCC_SPEC as a spec.
327 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
328 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
329 %c process SIGNED_CHAR_SPEC as a spec.
330 %C process CPP_SPEC as a spec. A capital C is actually used here.
331 %1 process CC1_SPEC as a spec.
332 %2 process CC1PLUS_SPEC as a spec.
333 %| output "-" if the input for the current command is coming from a pipe.
334 %* substitute the variable part of a matched option. (See below.)
335 Note that each comma in the substituted string is replaced by
337 %{S} substitutes the -S switch, if that switch was given to CC.
338 If that switch was not specified, this substitutes nothing.
339 Here S is a metasyntactic variable.
340 %{S*} substitutes all the switches specified to CC whose names start
341 with -S. This is used for -o, -D, -I, etc; switches that take
342 arguments. CC considers `-o foo' as being one switch whose
343 name starts with `o'. %{o*} would substitute this text,
344 including the space; thus, two arguments would be generated.
345 %{^S*} likewise, but don't put a blank between a switch and any args.
346 %{S*:X} substitutes X if one or more switches whose names start with -S are
347 specified to CC. Note that the tail part of the -S option
348 (i.e. the part matched by the `*') will be substituted for each
349 occurrence of %* within X.
350 %{S:X} substitutes X, but only if the -S switch was given to CC.
351 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
352 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
353 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
354 %{.S:X} substitutes X, but only if processing a file with suffix S.
355 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
356 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
357 combined with ! and . as above binding stronger than the OR.
358 %(Spec) processes a specification defined in a specs file as *Spec:
359 %[Spec] as above, but put __ around -D arguments
361 The conditional text X in a %{S:X} or %{!S:X} construct may contain
362 other nested % constructs or spaces, or even newlines. They are
363 processed as usual, as described above.
365 The -O, -f, -m, and -W switches are handled specifically in these
366 constructs. If another value of -O or the negated form of a -f, -m, or
367 -W switch is found later in the command line, the earlier switch
368 value is ignored, except with {S*} where S is just one letter; this
369 passes all matching options.
371 The character | at the beginning of the predicate text is used to indicate
372 that a command should be piped to the following command, but only if -pipe
375 Note that it is built into CC which switches take arguments and which
376 do not. You might think it would be useful to generalize this to
377 allow each compiler's spec to say which switches take arguments. But
378 this cannot be done in a consistent fashion. CC cannot even decide
379 which input files have been specified without knowing which switches
380 take arguments, and it must know which input files to compile in order
381 to tell which compilers to run.
383 CC also knows implicitly that arguments starting in `-l' are to be
384 treated as compiler output files, and passed to the linker in their
385 proper position among the other output files. */
387 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
389 /* config.h can define ASM_SPEC to provide extra args to the assembler
390 or extra switch-translations. */
395 /* config.h can define ASM_FINAL_SPEC to run a post processor after
396 the assembler has run. */
397 #ifndef ASM_FINAL_SPEC
398 #define ASM_FINAL_SPEC ""
401 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
402 or extra switch-translations. */
407 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
408 or extra switch-translations. */
413 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
414 or extra switch-translations. */
416 #define CC1PLUS_SPEC ""
419 /* config.h can define LINK_SPEC to provide extra args to the linker
420 or extra switch-translations. */
425 /* config.h can define LIB_SPEC to override the default libraries. */
427 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
430 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
433 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
434 /* Have gcc do the search for libgcc.a. */
435 #define LIBGCC_SPEC "libgcc.a%s"
437 #define LIBGCC_SPEC "-lgcc"
441 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
442 #ifndef STARTFILE_SPEC
443 #define STARTFILE_SPEC \
444 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
447 /* config.h can define SWITCHES_NEED_SPACES to control which options
448 require spaces between the option and the argument. */
449 #ifndef SWITCHES_NEED_SPACES
450 #define SWITCHES_NEED_SPACES ""
453 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
455 #define ENDFILE_SPEC ""
458 /* This spec is used for telling cpp whether char is signed or not. */
459 #ifndef SIGNED_CHAR_SPEC
460 /* Use #if rather than ?:
461 because MIPS C compiler rejects like ?: in initializers. */
462 #if DEFAULT_SIGNED_CHAR
463 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
465 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
470 #define LINKER_NAME "collect2"
473 static char *cpp_spec
= CPP_SPEC
;
474 static char *cpp_predefines
= CPP_PREDEFINES
;
475 static char *cc1_spec
= CC1_SPEC
;
476 static char *cc1plus_spec
= CC1PLUS_SPEC
;
477 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
478 static char *asm_spec
= ASM_SPEC
;
479 static char *asm_final_spec
= ASM_FINAL_SPEC
;
480 static char *link_spec
= LINK_SPEC
;
481 static char *lib_spec
= LIB_SPEC
;
482 static char *libgcc_spec
= LIBGCC_SPEC
;
483 static char *endfile_spec
= ENDFILE_SPEC
;
484 static char *startfile_spec
= STARTFILE_SPEC
;
485 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
486 static char *linker_name_spec
= LINKER_NAME
;
488 /* Some compilers have limits on line lengths, and the multilib_select
489 and/or multilib_matches strings can be very long, so we build them at
491 static struct obstack multilib_obstack
;
492 static char *multilib_select
;
493 static char *multilib_matches
;
494 static char *multilib_defaults
;
495 #include "multilib.h"
497 /* Check whether a particular argument is a default argument. */
499 #ifndef MULTILIB_DEFAULTS
500 #define MULTILIB_DEFAULTS { "" }
503 static char *multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
506 struct user_specs
*next
;
507 const char *filename
;
510 static struct user_specs
*user_specs_head
, *user_specs_tail
;
512 /* This defines which switch letters take arguments. */
514 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
515 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
516 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
517 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
518 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
519 || (CHAR) == 'B' || (CHAR) == 'b')
521 #ifndef SWITCH_TAKES_ARG
522 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
525 /* This defines which multi-letter switches take arguments. */
527 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
528 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
529 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
530 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
531 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
532 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
533 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
535 #ifndef WORD_SWITCH_TAKES_ARG
536 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
540 #ifdef HAVE_EXECUTABLE_SUFFIX
541 /* This defines which switches stop a full compilation. */
542 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
543 ((CHAR) == 'c' || (CHAR) == 'S')
545 #ifndef SWITCH_CURTAILS_COMPILATION
546 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
547 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
551 /* Record the mapping from file suffixes for compilation specs. */
555 const char *suffix
; /* Use this compiler for input files
556 whose names end in this suffix. */
558 const char *spec
[4]; /* To use this compiler, concatenate these
559 specs and pass to do_spec. */
562 /* Pointer to a vector of `struct compiler' that gives the spec for
563 compiling a file, based on its suffix.
564 A file that does not end in any of these suffixes will be passed
565 unchanged to the loader and nothing else will be done to it.
567 An entry containing two 0s is used to terminate the vector.
569 If multiple entries match a file, the last matching one is used. */
571 static struct compiler
*compilers
;
573 /* Number of entries in `compilers', not counting the null terminator. */
575 static int n_compilers
;
577 /* The default list of file name suffixes and their compilation specs. */
579 static struct compiler default_compilers
[] =
581 /* Add lists of suffixes of known languages here. If those languages
582 were not present when we built the driver, we will hit these copies
583 and be given a more meaningful error than "file not used since
584 linking is not done". */
585 {".m", {"#Objective-C"}},
586 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}},
587 {".c++", {"#C++"}}, {".C", {"#C++"}},
588 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
589 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
590 {".fpp", {"#Fortran"}},
591 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
592 /* Next come the entries for C. */
597 "%{E|M|MM:cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
598 %{C} %{v} %{A*} %{I*} %{P} %I\
599 %{C:%{!E:%eGNU C does not support -C without using -E}}\
600 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
601 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
602 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
603 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
604 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
605 %{ffast-math:-D__FAST_MATH__}\
606 %{traditional} %{ftraditional:-traditional}\
607 %{traditional-cpp:-traditional}\
608 %{fleading-underscore} %{fno-leading-underscore}\
609 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
610 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
611 %{!E:%{!M:%{!MM:cc1 %i %1 \
612 %{std*} %{nostdinc*} %{A*} %{I*} %I\
613 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
614 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
615 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
616 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
617 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
618 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
619 %{ffast-math:-D__FAST_MATH__}\
620 %{H} %C %{D*} %{U*} %{i*} %Z\
621 %{ftraditional:-traditional}\
622 %{traditional-cpp:-traditional}\
623 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
624 %{aux-info*} %{Qn:-fno-ident}\
626 %{g*} %{O*} %{W*} %{w} %{pedantic*}\
627 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
628 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
630 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
631 %{!pipe:%g.s} %A\n }}}}"
633 #else /* ! USE_CPPLIB */
634 "cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
635 %{C} %{v} %{A*} %{I*} %{P} %I\
636 %{C:%{!E:%eGNU C does not support -C without using -E}}\
637 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
638 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
639 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
640 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
641 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
642 %{ffast-math:-D__FAST_MATH__}\
643 %{traditional} %{ftraditional:-traditional}\
644 %{traditional-cpp:-traditional}\
645 %{fleading-underscore} %{fno-leading-underscore}\
646 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
647 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
648 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
649 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
650 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
651 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
652 %{aux-info*} %{Qn:-fno-ident}\
654 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
655 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
657 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
658 %{!pipe:%g.s} %A\n }}}}"
660 #endif /* ! USE_CPPLIB */
662 {"%{E:cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
663 %{C} %{v} %{A*} %{I*} %{P} %I\
664 %{C:%{!E:%eGNU C does not support -C without using -E}}\
665 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
666 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
667 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
668 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
669 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
670 %{ffast-math:-D__FAST_MATH__}\
671 %{traditional} %{ftraditional:-traditional}\
672 %{traditional-cpp:-traditional}\
673 %{fleading-underscore} %{fno-leading-underscore}\
674 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
676 %{!E:%e-E required when input is from standard input}"}},
677 {".h", {"@c-header"}},
679 {"%{!E:%eCompilation of header file requested} \
680 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
681 %{C:%{!E:%eGNU C does not support -C without using -E}}\
682 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
683 -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
684 %{std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
685 %{!undef:%{!std=*:%p}%{std=gnu*:%p} %P} %{trigraphs}\
686 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
687 %{ffast-math:-D__FAST_MATH__}\
688 %{traditional} %{ftraditional:-traditional}\
689 %{traditional-cpp:-traditional}\
690 %{fleading-underscore} %{fno-leading-underscore}\
691 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
693 {".i", {"@cpp-output"}},
695 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
696 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
697 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
698 %{aux-info*} %{Qn:-fno-ident}\
699 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
700 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
702 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
703 %{!pipe:%g.s} %A\n }}}}"}},
704 {".s", {"@assembler"}},
706 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
707 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
709 {".S", {"@assembler-with-cpp"}},
710 {"@assembler-with-cpp",
711 {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
712 %{C:%{!E:%eGNU C does not support -C without using -E}}\
713 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
714 -$ %{!undef:%p %P} -D__ASSEMBLER__ \
715 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
716 %{ffast-math:-D__FAST_MATH__}\
717 %{traditional} %{ftraditional:-traditional}\
718 %{traditional-cpp:-traditional}\
719 %{fleading-underscore} %{fno-leading-underscore}\
720 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
721 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
722 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
723 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
724 %{!pipe:%g.s} %A\n }}}}"}},
726 /* Mark end of table */
730 /* Number of elements in default_compilers, not counting the terminator. */
732 static int n_default_compilers
733 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
735 /* Here is the spec for running the linker, after compiling all files. */
737 /* -u* was put back because both BSD and SysV seem to support it. */
738 /* %{static:} simply prevents an error message if the target machine
739 doesn't handle -static. */
740 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
741 scripts which exist in user specified directories, or in standard
743 #ifdef LINK_COMMAND_SPEC
744 /* Provide option to override link_command_spec from machine specific
745 configuration files. */
746 static const char *link_command_spec
=
749 #ifdef LINK_LIBGCC_SPECIAL
750 /* Don't generate -L options. */
751 static const char *link_command_spec
= "\
753 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
754 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
755 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
757 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
758 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
763 static const char *link_command_spec
= "\
765 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
766 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
767 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
768 %{static:} %{L*} %D %o\
769 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
770 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
776 /* A vector of options to give to the linker.
777 These options are accumulated by %x,
778 and substituted into the linker command with %X. */
779 static int n_linker_options
;
780 static char **linker_options
;
782 /* A vector of options to give to the assembler.
783 These options are accumulated by -Wa,
784 and substituted into the assembler command with %Y. */
785 static int n_assembler_options
;
786 static char **assembler_options
;
788 /* A vector of options to give to the preprocessor.
789 These options are accumulated by -Wp,
790 and substituted into the preprocessor command with %Z. */
791 static int n_preprocessor_options
;
792 static char **preprocessor_options
;
794 /* Define how to map long options into short ones. */
796 /* This structure describes one mapping. */
799 /* The long option's name. */
801 /* The equivalent short option. */
802 const char *equivalent
;
803 /* Argument info. A string of flag chars; NULL equals no options.
804 a => argument required.
805 o => argument optional.
806 j => join argument to equivalent, making one word.
807 * => require other text after NAME as an argument. */
808 const char *arg_info
;
811 /* This is the table of mappings. Mappings are tried sequentially
812 for each option encountered; the first one that matches, wins. */
814 struct option_map option_map
[] =
816 {"--all-warnings", "-Wall", 0},
817 {"--ansi", "-ansi", 0},
818 {"--assemble", "-S", 0},
819 {"--assert", "-A", "a"},
820 {"--classpath", "-fclasspath=", "aj"},
821 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
822 {"--comments", "-C", 0},
823 {"--compile", "-c", 0},
824 {"--debug", "-g", "oj"},
825 {"--define-macro", "-D", "aj"},
826 {"--dependencies", "-M", 0},
827 {"--dump", "-d", "a"},
828 {"--dumpbase", "-dumpbase", "a"},
829 {"--entry", "-e", 0},
830 {"--extra-warnings", "-W", 0},
831 {"--for-assembler", "-Wa", "a"},
832 {"--for-linker", "-Xlinker", "a"},
833 {"--force-link", "-u", "a"},
834 {"--imacros", "-imacros", "a"},
835 {"--include", "-include", "a"},
836 {"--include-barrier", "-I-", 0},
837 {"--include-directory", "-I", "aj"},
838 {"--include-directory-after", "-idirafter", "a"},
839 {"--include-prefix", "-iprefix", "a"},
840 {"--include-with-prefix", "-iwithprefix", "a"},
841 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
842 {"--include-with-prefix-after", "-iwithprefix", "a"},
843 {"--language", "-x", "a"},
844 {"--library-directory", "-L", "a"},
845 {"--machine", "-m", "aj"},
846 {"--machine-", "-m", "*j"},
847 {"--no-line-commands", "-P", 0},
848 {"--no-precompiled-includes", "-noprecomp", 0},
849 {"--no-standard-includes", "-nostdinc", 0},
850 {"--no-standard-libraries", "-nostdlib", 0},
851 {"--no-warnings", "-w", 0},
852 {"--optimize", "-O", "oj"},
853 {"--output", "-o", "a"},
854 {"--output-class-directory", "-foutput-class-dir=", "ja"},
855 {"--pedantic", "-pedantic", 0},
856 {"--pedantic-errors", "-pedantic-errors", 0},
857 {"--pipe", "-pipe", 0},
858 {"--prefix", "-B", "a"},
859 {"--preprocess", "-E", 0},
860 {"--print-search-dirs", "-print-search-dirs", 0},
861 {"--print-file-name", "-print-file-name=", "aj"},
862 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
863 {"--print-missing-file-dependencies", "-MG", 0},
864 {"--print-multi-lib", "-print-multi-lib", 0},
865 {"--print-multi-directory", "-print-multi-directory", 0},
866 {"--print-prog-name", "-print-prog-name=", "aj"},
867 {"--profile", "-p", 0},
868 {"--profile-blocks", "-a", 0},
869 {"--quiet", "-q", 0},
870 {"--save-temps", "-save-temps", 0},
871 {"--shared", "-shared", 0},
872 {"--silent", "-q", 0},
873 {"--specs", "-specs=", "aj"},
874 {"--static", "-static", 0},
875 {"--std", "-std=", "aj"},
876 {"--symbolic", "-symbolic", 0},
877 {"--target", "-b", "a"},
878 {"--trace-includes", "-H", 0},
879 {"--traditional", "-traditional", 0},
880 {"--traditional-cpp", "-traditional-cpp", 0},
881 {"--trigraphs", "-trigraphs", 0},
882 {"--undefine-macro", "-U", "aj"},
883 {"--use-version", "-V", "a"},
884 {"--user-dependencies", "-MM", 0},
885 {"--verbose", "-v", 0},
886 {"--version", "-dumpversion", 0},
887 {"--warn-", "-W", "*j"},
888 {"--write-dependencies", "-MD", 0},
889 {"--write-user-dependencies", "-MMD", 0},
893 /* Translate the options described by *ARGCP and *ARGVP.
894 Make a new vector and store it back in *ARGVP,
895 and store its length in *ARGVC. */
898 translate_options (argcp
, argvp
)
904 const char **argv
= *argvp
;
906 (const char **) xmalloc ((argc
+ 2) * 2 * sizeof (const char *));
910 newv
[newindex
++] = argv
[i
++];
914 /* Translate -- options. */
915 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
918 /* Find a mapping that applies to this option. */
919 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
921 size_t optlen
= strlen (option_map
[j
].name
);
922 size_t arglen
= strlen (argv
[i
]);
923 size_t complen
= arglen
> optlen
? optlen
: arglen
;
924 const char *arginfo
= option_map
[j
].arg_info
;
929 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
937 k
< sizeof (option_map
) / sizeof (option_map
[0]);
939 if (strlen (option_map
[k
].name
) >= arglen
940 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
942 error ("Ambiguous abbreviation %s", argv
[i
]);
946 if (k
!= sizeof (option_map
) / sizeof (option_map
[0]))
952 /* If the option has an argument, accept that. */
953 if (argv
[i
][optlen
] == '=')
954 arg
= argv
[i
] + optlen
+ 1;
956 /* If this mapping requires extra text at end of name,
957 accept that as "argument". */
958 else if (index (arginfo
, '*') != 0)
959 arg
= argv
[i
] + optlen
;
961 /* Otherwise, extra text at end means mismatch.
962 Try other mappings. */
967 else if (index (arginfo
, '*') != 0)
969 error ("Incomplete `%s' option", option_map
[j
].name
);
973 /* Handle arguments. */
974 if (index (arginfo
, 'a') != 0)
980 error ("Missing argument to `%s' option",
988 else if (index (arginfo
, '*') != 0)
990 else if (index (arginfo
, 'o') == 0)
993 error ("Extraneous argument to `%s' option",
998 /* Store the translation as one argv elt or as two. */
999 if (arg
!= 0 && index (arginfo
, 'j') != 0)
1000 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
1004 newv
[newindex
++] = option_map
[j
].equivalent
;
1005 newv
[newindex
++] = arg
;
1008 newv
[newindex
++] = option_map
[j
].equivalent
;
1016 /* Handle old-fashioned options--just copy them through,
1017 with their arguments. */
1018 else if (argv
[i
][0] == '-')
1020 const char *p
= argv
[i
] + 1;
1024 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1025 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1026 else if (WORD_SWITCH_TAKES_ARG (p
))
1027 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
1028 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
1031 else if (! strcmp (p
, "Xlinker"))
1034 /* Watch out for an option at the end of the command line that
1035 is missing arguments, and avoid skipping past the end of the
1037 if (nskip
+ i
> argc
)
1042 newv
[newindex
++] = argv
[i
++];
1047 /* Ordinary operands, or +e options. */
1048 newv
[newindex
++] = argv
[i
++];
1061 #ifdef HAVE_STRERROR
1070 if (e
> 0 && e
< sys_nerr
)
1071 return sys_errlist
[e
];
1083 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1084 be considered whitespace. */
1085 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1087 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1091 while (*p
!= '\n') p
++;
1101 /* Structure to keep track of the specs that have been defined so far.
1102 These are accessed using %(specname) or %[specname] in a compiler
1107 /* The following 2 fields must be first */
1108 /* to allow EXTRA_SPECS to be initialized */
1109 char *name
; /* name of the spec. */
1110 char *ptr
; /* available ptr if no static pointer */
1112 /* The following fields are not initialized */
1113 /* by EXTRA_SPECS */
1114 char **ptr_spec
; /* pointer to the spec itself. */
1115 struct spec_list
*next
; /* Next spec in linked list. */
1116 int name_len
; /* length of the name */
1117 int alloc_p
; /* whether string was allocated */
1120 #define INIT_STATIC_SPEC(NAME,PTR) \
1121 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1123 /* List of statically defined specs */
1124 static struct spec_list static_specs
[] = {
1125 INIT_STATIC_SPEC ("asm", &asm_spec
),
1126 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1127 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1128 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1129 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1130 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1131 INIT_STATIC_SPEC ("link", &link_spec
),
1132 INIT_STATIC_SPEC ("lib", &lib_spec
),
1133 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1134 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1135 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces
),
1136 INIT_STATIC_SPEC ("signed_char", &signed_char_spec
),
1137 INIT_STATIC_SPEC ("predefines", &cpp_predefines
),
1138 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1139 INIT_STATIC_SPEC ("version", &compiler_version
),
1140 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1141 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1142 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1143 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1144 INIT_STATIC_SPEC ("linker", &linker_name_spec
),
1147 #ifdef EXTRA_SPECS /* additional specs needed */
1148 /* Structure to keep track of just the first two args of a spec_list.
1149 That is all that the EXTRA_SPECS macro gives us. */
1156 static struct spec_list_1 extra_specs_1
[] = { EXTRA_SPECS
};
1157 static struct spec_list
* extra_specs
= (struct spec_list
*)0;
1160 /* List of dynamically allocates specs that have been defined so far. */
1162 static struct spec_list
*specs
= (struct spec_list
*)0;
1165 /* Initialize the specs lookup routines. */
1170 struct spec_list
*next
= (struct spec_list
*)0;
1171 struct spec_list
*sl
= (struct spec_list
*)0;
1175 return; /* already initialized */
1178 notice ("Using builtin specs.\n");
1181 extra_specs
= (struct spec_list
*)
1182 xmalloc (sizeof(struct spec_list
) *
1183 (sizeof(extra_specs_1
)/sizeof(extra_specs_1
[0])));
1184 bzero ((PTR
) extra_specs
, sizeof(struct spec_list
) *
1185 (sizeof(extra_specs_1
)/sizeof(extra_specs_1
[0])));
1187 for (i
= (sizeof(extra_specs_1
) / sizeof(extra_specs_1
[0])) - 1; i
>= 0; i
--)
1189 sl
= &extra_specs
[i
];
1190 sl
->name
= extra_specs_1
[i
].name
;
1191 sl
->ptr
= extra_specs_1
[i
].ptr
;
1193 sl
->name_len
= strlen (sl
->name
);
1194 sl
->ptr_spec
= &sl
->ptr
;
1199 for (i
= (sizeof (static_specs
) / sizeof (static_specs
[0])) - 1; i
>= 0; i
--)
1201 sl
= &static_specs
[i
];
1210 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1211 removed; If the spec starts with a + then SPEC is added to the end of the
1215 set_spec (name
, spec
)
1219 struct spec_list
*sl
;
1221 int name_len
= strlen (name
);
1224 /* If this is the first call, initialize the statically allocated specs */
1227 struct spec_list
*next
= (struct spec_list
*)0;
1228 for (i
= (sizeof (static_specs
) / sizeof (static_specs
[0])) - 1;
1231 sl
= &static_specs
[i
];
1238 /* See if the spec already exists */
1239 for (sl
= specs
; sl
; sl
= sl
->next
)
1240 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1245 /* Not found - make it */
1246 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1247 sl
->name
= save_string (name
, strlen (name
));
1248 sl
->name_len
= name_len
;
1249 sl
->ptr_spec
= &sl
->ptr
;
1251 *(sl
->ptr_spec
) = "";
1256 old_spec
= *(sl
->ptr_spec
);
1257 *(sl
->ptr_spec
) = ((spec
[0] == '+' && ISSPACE ((unsigned char)spec
[1]))
1258 ? concat (old_spec
, spec
+ 1, NULL_PTR
)
1259 : save_string (spec
, strlen (spec
)));
1263 notice ("Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1266 /* Free the old spec */
1267 if (old_spec
&& sl
->alloc_p
)
1273 /* Accumulate a command (program name and args), and run it. */
1275 /* Vector of pointers to arguments in the current line of specifications. */
1277 static char **argbuf
;
1279 /* Number of elements allocated in argbuf. */
1281 static int argbuf_length
;
1283 /* Number of elements in argbuf currently in use (containing args). */
1285 static int argbuf_index
;
1287 /* We want this on by default all the time now. */
1288 #define MKTEMP_EACH_FILE
1290 #ifdef MKTEMP_EACH_FILE
1292 extern char *make_temp_file
PROTO((const char *));
1294 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1297 static struct temp_name
{
1298 const char *suffix
; /* suffix associated with the code. */
1299 int length
; /* strlen (suffix). */
1300 int unique
; /* Indicates whether %g or %u/%U was used. */
1301 const char *filename
; /* associated filename. */
1302 int filename_length
; /* strlen (filename). */
1303 struct temp_name
*next
;
1308 /* Number of commands executed so far. */
1310 static int execution_count
;
1312 /* Number of commands that exited with a signal. */
1314 static int signal_count
;
1316 /* Name with which this program was invoked. */
1318 static const char *programname
;
1320 /* Structures to keep track of prefixes to try when looking for files. */
1324 char *prefix
; /* String to prepend to the path. */
1325 struct prefix_list
*next
; /* Next in linked list. */
1326 int require_machine_suffix
; /* Don't use without machine_suffix. */
1327 /* 2 means try both machine_suffix and just_machine_suffix. */
1328 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1333 struct prefix_list
*plist
; /* List of prefixes to try */
1334 int max_len
; /* Max length of a prefix in PLIST */
1335 const char *name
; /* Name of this list (used in config stuff) */
1338 /* List of prefixes to try when looking for executables. */
1340 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1342 /* List of prefixes to try when looking for startup (crt0) files. */
1344 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1346 /* List of prefixes to try when looking for include files. */
1348 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1350 /* Suffix to attach to directories searched for commands.
1351 This looks like `MACHINE/VERSION/'. */
1353 static const char *machine_suffix
= 0;
1355 /* Suffix to attach to directories searched for commands.
1356 This is just `MACHINE/'. */
1358 static const char *just_machine_suffix
= 0;
1360 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1362 static const char *gcc_exec_prefix
;
1364 /* Default prefixes to attach to command names. */
1366 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1367 #undef MD_EXEC_PREFIX
1368 #undef MD_STARTFILE_PREFIX
1369 #undef MD_STARTFILE_PREFIX_1
1372 #ifndef STANDARD_EXEC_PREFIX
1373 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1374 #endif /* !defined STANDARD_EXEC_PREFIX */
1376 static const char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1377 static const char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1378 #ifdef MD_EXEC_PREFIX
1379 static const char *md_exec_prefix
= MD_EXEC_PREFIX
;
1382 #ifndef STANDARD_STARTFILE_PREFIX
1383 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1384 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1386 #ifdef MD_STARTFILE_PREFIX
1387 static const char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1389 #ifdef MD_STARTFILE_PREFIX_1
1390 static const char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1392 static const char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1393 static const char *standard_startfile_prefix_1
= "/lib/";
1394 static const char *standard_startfile_prefix_2
= "/usr/lib/";
1396 #ifndef TOOLDIR_BASE_PREFIX
1397 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1399 static const char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1400 static const char *tooldir_prefix
;
1402 /* Subdirectory to use for locating libraries. Set by
1403 set_multilib_dir based on the compilation options. */
1405 static const char *multilib_dir
;
1407 /* Clear out the vector of arguments (after a command is executed). */
1415 /* Add one argument to the vector at the end.
1416 This is done when a space is seen or at the end of the line.
1417 If DELETE_ALWAYS is nonzero, the arg is a filename
1418 and the file should be deleted eventually.
1419 If DELETE_FAILURE is nonzero, the arg is a filename
1420 and the file should be deleted if this compilation fails. */
1423 store_arg (arg
, delete_always
, delete_failure
)
1425 int delete_always
, delete_failure
;
1427 if (argbuf_index
+ 1 == argbuf_length
)
1429 = (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1431 argbuf
[argbuf_index
++] = arg
;
1432 argbuf
[argbuf_index
] = 0;
1434 if (delete_always
|| delete_failure
)
1435 record_temp_file (arg
, delete_always
, delete_failure
);
1438 /* Read compilation specs from a file named FILENAME,
1439 replacing the default ones.
1441 A suffix which starts with `*' is a definition for
1442 one of the machine-specific sub-specs. The "suffix" should be
1443 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1444 The corresponding spec is stored in asm_spec, etc.,
1445 rather than in the `compilers' vector.
1447 Anything invalid in the file is a fatal error. */
1450 read_specs (filename
, main_p
)
1451 const char *filename
;
1456 struct stat statbuf
;
1461 notice ("Reading specs from %s\n", filename
);
1463 /* Open and stat the file. */
1464 desc
= open (filename
, O_RDONLY
, 0);
1466 pfatal_with_name (filename
);
1467 if (stat (filename
, &statbuf
) < 0)
1468 pfatal_with_name (filename
);
1470 /* Read contents of file into BUFFER. */
1471 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1472 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1474 pfatal_with_name (filename
);
1475 buffer
[readlen
] = 0;
1478 /* Scan BUFFER for specs, putting them in the vector. */
1484 char *in
, *out
, *p1
, *p2
, *p3
;
1486 /* Advance P in BUFFER to the next nonblank nocomment line. */
1487 p
= skip_whitespace (p
);
1491 /* Is this a special command that starts with '%'? */
1492 /* Don't allow this for the main specs file, since it would
1493 encourage people to overwrite it. */
1494 if (*p
== '%' && !main_p
)
1497 while (*p
&& *p
!= '\n')
1500 p
++; /* Skip '\n' */
1502 if (!strncmp (p1
, "%include", sizeof ("%include")-1)
1503 && (p1
[sizeof "%include" - 1] == ' '
1504 || p1
[sizeof "%include" - 1] == '\t'))
1508 p1
+= sizeof ("%include");
1509 while (*p1
== ' ' || *p1
== '\t')
1512 if (*p1
++ != '<' || p
[-2] != '>')
1513 fatal ("specs %%include syntax malformed after %ld characters",
1514 (long) (p1
- buffer
+ 1));
1517 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1518 read_specs (new_filename
? new_filename
: p1
, FALSE
);
1521 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
1522 && (p1
[sizeof "%include_noerr" - 1] == ' '
1523 || p1
[sizeof "%include_noerr" - 1] == '\t'))
1527 p1
+= sizeof "%include_noerr";
1528 while (*p1
== ' ' || *p1
== '\t') p1
++;
1530 if (*p1
++ != '<' || p
[-2] != '>')
1531 fatal ("specs %%include syntax malformed after %ld characters",
1532 (long) (p1
- buffer
+ 1));
1535 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1537 read_specs (new_filename
, FALSE
);
1538 else if (verbose_flag
)
1539 notice ("Could not find specs file %s\n", p1
);
1542 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
1543 && (p1
[sizeof "%rename" - 1] == ' '
1544 || p1
[sizeof "%rename" - 1] == '\t'))
1547 struct spec_list
*sl
;
1549 /* Get original name */
1550 p1
+= sizeof "%rename";
1551 while (*p1
== ' ' || *p1
== '\t')
1554 if (! ISALPHA ((unsigned char)*p1
))
1555 fatal ("specs %%rename syntax malformed after %ld characters",
1556 (long) (p1
- buffer
));
1559 while (*p2
&& !ISSPACE ((unsigned char)*p2
))
1562 if (*p2
!= ' ' && *p2
!= '\t')
1563 fatal ("specs %%rename syntax malformed after %ld characters",
1564 (long) (p2
- buffer
));
1568 while (*p2
== ' ' || *p2
== '\t')
1571 if (! ISALPHA ((unsigned char)*p2
))
1572 fatal ("specs %%rename syntax malformed after %ld characters",
1573 (long) (p2
- buffer
));
1575 /* Get new spec name */
1577 while (*p3
&& !ISSPACE ((unsigned char)*p3
))
1581 fatal ("specs %%rename syntax malformed after %ld characters",
1582 (long) (p3
- buffer
));
1585 for (sl
= specs
; sl
; sl
= sl
->next
)
1586 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
1590 fatal ("specs %s spec was not found to be renamed", p1
);
1592 if (strcmp (p1
, p2
) == 0)
1597 notice ("rename spec %s to %s\n", p1
, p2
);
1599 notice ("spec is '%s'\n\n", *(sl
->ptr_spec
));
1603 set_spec (p2
, *(sl
->ptr_spec
));
1605 free (*(sl
->ptr_spec
));
1607 *(sl
->ptr_spec
) = "";
1612 fatal ("specs unknown %% command after %ld characters",
1613 (long) (p1
- buffer
));
1616 /* Find the colon that should end the suffix. */
1618 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
1621 /* The colon shouldn't be missing. */
1623 fatal ("specs file malformed after %ld characters",
1624 (long) (p1
- buffer
));
1626 /* Skip back over trailing whitespace. */
1628 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
1631 /* Copy the suffix to a string. */
1632 suffix
= save_string (p
, p2
- p
);
1633 /* Find the next line. */
1634 p
= skip_whitespace (p1
+ 1);
1636 fatal ("specs file malformed after %ld characters",
1637 (long) (p
- buffer
));
1640 /* Find next blank line or end of string. */
1641 while (*p1
&& !(*p1
== '\n' && (p1
[1] == '\n' || p1
[1] == '\0')))
1644 /* Specs end at the blank line and do not include the newline. */
1645 spec
= save_string (p
, p1
- p
);
1648 /* Delete backslash-newline sequences from the spec. */
1653 if (in
[0] == '\\' && in
[1] == '\n')
1655 else if (in
[0] == '#')
1656 while (*in
&& *in
!= '\n')
1664 if (suffix
[0] == '*')
1666 if (! strcmp (suffix
, "*link_command"))
1667 link_command_spec
= spec
;
1669 set_spec (suffix
+ 1, spec
);
1673 /* Add this pair to the vector. */
1675 = ((struct compiler
*)
1676 xrealloc (compilers
,
1677 (n_compilers
+ 2) * sizeof (struct compiler
)));
1679 compilers
[n_compilers
].suffix
= suffix
;
1680 bzero ((char *) compilers
[n_compilers
].spec
,
1681 sizeof compilers
[n_compilers
].spec
);
1682 compilers
[n_compilers
].spec
[0] = spec
;
1684 bzero ((char *) &compilers
[n_compilers
],
1685 sizeof compilers
[n_compilers
]);
1689 link_command_spec
= spec
;
1692 if (link_command_spec
== 0)
1693 fatal ("spec file has no spec for linking");
1696 /* Record the names of temporary files we tell compilers to write,
1697 and delete them at the end of the run. */
1699 /* This is the common prefix we use to make temp file names.
1700 It is chosen once for each run of this program.
1701 It is substituted into a spec by %g.
1702 Thus, all temp file names contain this prefix.
1703 In practice, all temp file names start with this prefix.
1705 This prefix comes from the envvar TMPDIR if it is defined;
1706 otherwise, from the P_tmpdir macro if that is defined;
1707 otherwise, in /usr/tmp or /tmp;
1708 or finally the current directory if all else fails. */
1710 static const char *temp_filename
;
1712 /* Length of the prefix. */
1714 static int temp_filename_length
;
1716 /* Define the list of temporary files to delete. */
1721 struct temp_file
*next
;
1724 /* Queue of files to delete on success or failure of compilation. */
1725 static struct temp_file
*always_delete_queue
;
1726 /* Queue of files to delete on failure of compilation. */
1727 static struct temp_file
*failure_delete_queue
;
1729 /* Record FILENAME as a file to be deleted automatically.
1730 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1731 otherwise delete it in any case.
1732 FAIL_DELETE nonzero means delete it if a compilation step fails;
1733 otherwise delete it in any case. */
1736 record_temp_file (filename
, always_delete
, fail_delete
)
1737 const char *filename
;
1741 register char *name
;
1742 name
= xmalloc (strlen (filename
) + 1);
1743 strcpy (name
, filename
);
1747 register struct temp_file
*temp
;
1748 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1749 if (! strcmp (name
, temp
->name
))
1752 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1753 temp
->next
= always_delete_queue
;
1755 always_delete_queue
= temp
;
1762 register struct temp_file
*temp
;
1763 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1764 if (! strcmp (name
, temp
->name
))
1767 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1768 temp
->next
= failure_delete_queue
;
1770 failure_delete_queue
= temp
;
1776 /* Delete all the temporary files whose names we previously recorded. */
1779 delete_if_ordinary (name
)
1786 printf ("Delete %s? (y or n) ", name
);
1790 while ((c
= getchar ()) != '\n' && c
!= EOF
)
1793 if (i
== 'y' || i
== 'Y')
1795 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1796 if (unlink (name
) < 0)
1798 perror_with_name (name
);
1802 delete_temp_files ()
1804 register struct temp_file
*temp
;
1806 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1807 delete_if_ordinary (temp
->name
);
1808 always_delete_queue
= 0;
1811 /* Delete all the files to be deleted on error. */
1814 delete_failure_queue ()
1816 register struct temp_file
*temp
;
1818 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1819 delete_if_ordinary (temp
->name
);
1823 clear_failure_queue ()
1825 failure_delete_queue
= 0;
1828 /* Routine to add variables to the environment. We do this to pass
1829 the pathname of the gcc driver, and the directories search to the
1830 collect2 program, which is being run as ld. This way, we can be
1831 sure of executing the right compiler when collect2 wants to build
1832 constructors and destructors. Since the environment variables we
1833 use come from an obstack, we don't have to worry about allocating
1842 #ifndef VMS /* nor about VMS */
1844 extern char **environ
;
1845 char **old_environ
= environ
;
1849 int str_len
= strlen (str
);
1853 while ((ch
= *p
++) != '\0' && ch
!= '=')
1859 /* Search for replacing an existing environment variable, and
1860 count the number of total environment variables. */
1861 for (envp
= old_environ
; *envp
; envp
++)
1864 if (!strncmp (str
, *envp
, name_len
))
1871 /* Add a new environment variable */
1872 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1874 memcpy ((char *) (environ
+ 1), (char *) old_environ
,
1875 sizeof (char *) * (num_envs
+1));
1880 #endif /* HAVE_PUTENV */
1883 /* Build a list of search directories from PATHS.
1884 PREFIX is a string to prepend to the list.
1885 If CHECK_DIR_P is non-zero we ensure the directory exists.
1886 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1887 It is also used by the --print-search-dirs flag. */
1890 build_search_list (paths
, prefix
, check_dir_p
)
1891 struct path_prefix
*paths
;
1895 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1897 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1898 int first_time
= TRUE
;
1899 struct prefix_list
*pprefix
;
1901 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
1903 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1905 int len
= strlen (pprefix
->prefix
);
1909 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
1912 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1915 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1916 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1919 if (just_machine_suffix
1920 && pprefix
->require_machine_suffix
== 2
1922 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
1925 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1928 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1929 obstack_grow (&collect_obstack
, just_machine_suffix
,
1933 if (! pprefix
->require_machine_suffix
)
1936 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1939 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1943 obstack_1grow (&collect_obstack
, '\0');
1944 return obstack_finish (&collect_obstack
);
1947 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1951 putenv_from_prefixes (paths
, env_var
)
1952 struct path_prefix
*paths
;
1953 const char *env_var
;
1955 putenv (build_search_list (paths
, env_var
, 1));
1958 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1959 access to check permissions.
1960 Return 0 if not found, otherwise return its name, allocated with malloc. */
1963 find_a_file (pprefix
, name
, mode
)
1964 struct path_prefix
*pprefix
;
1969 const char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1970 struct prefix_list
*pl
;
1971 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1973 #ifdef DEFAULT_ASSEMBLER
1974 if (! strcmp(name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0) {
1975 name
= DEFAULT_ASSEMBLER
;
1976 len
= strlen(name
)+1;
1977 temp
= xmalloc (len
);
1978 strcpy (temp
, name
);
1983 #ifdef DEFAULT_LINKER
1984 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0) {
1985 name
= DEFAULT_LINKER
;
1986 len
= strlen(name
)+1;
1987 temp
= xmalloc (len
);
1988 strcpy (temp
, name
);
1994 len
+= strlen (machine_suffix
);
1996 temp
= xmalloc (len
);
1998 /* Determine the filename to execute (special case for absolute paths). */
2000 if (IS_DIR_SEPARATOR (*name
)
2001 #ifdef HAVE_DOS_BASED_FILESYSTEM
2002 /* Check for disk name on MS-DOS-based systems. */
2003 || (name
[0] && name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2007 if (access (name
, mode
) == 0)
2009 strcpy (temp
, name
);
2014 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
2018 /* Some systems have a suffix for executable files.
2019 So try appending that first. */
2020 if (file_suffix
[0] != 0)
2022 strcpy (temp
, pl
->prefix
);
2023 strcat (temp
, machine_suffix
);
2024 strcat (temp
, name
);
2025 strcat (temp
, file_suffix
);
2026 if (access (temp
, mode
) == 0)
2028 if (pl
->used_flag_ptr
!= 0)
2029 *pl
->used_flag_ptr
= 1;
2034 /* Now try just the name. */
2035 strcpy (temp
, pl
->prefix
);
2036 strcat (temp
, machine_suffix
);
2037 strcat (temp
, name
);
2038 if (access (temp
, mode
) == 0)
2040 if (pl
->used_flag_ptr
!= 0)
2041 *pl
->used_flag_ptr
= 1;
2046 /* Certain prefixes are tried with just the machine type,
2047 not the version. This is used for finding as, ld, etc. */
2048 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
2050 /* Some systems have a suffix for executable files.
2051 So try appending that first. */
2052 if (file_suffix
[0] != 0)
2054 strcpy (temp
, pl
->prefix
);
2055 strcat (temp
, just_machine_suffix
);
2056 strcat (temp
, name
);
2057 strcat (temp
, file_suffix
);
2058 if (access (temp
, mode
) == 0)
2060 if (pl
->used_flag_ptr
!= 0)
2061 *pl
->used_flag_ptr
= 1;
2066 strcpy (temp
, pl
->prefix
);
2067 strcat (temp
, just_machine_suffix
);
2068 strcat (temp
, name
);
2069 if (access (temp
, mode
) == 0)
2071 if (pl
->used_flag_ptr
!= 0)
2072 *pl
->used_flag_ptr
= 1;
2077 /* Certain prefixes can't be used without the machine suffix
2078 when the machine or version is explicitly specified. */
2079 if (! pl
->require_machine_suffix
)
2081 /* Some systems have a suffix for executable files.
2082 So try appending that first. */
2083 if (file_suffix
[0] != 0)
2085 strcpy (temp
, pl
->prefix
);
2086 strcat (temp
, name
);
2087 strcat (temp
, file_suffix
);
2088 if (access (temp
, mode
) == 0)
2090 if (pl
->used_flag_ptr
!= 0)
2091 *pl
->used_flag_ptr
= 1;
2096 strcpy (temp
, pl
->prefix
);
2097 strcat (temp
, name
);
2098 if (access (temp
, mode
) == 0)
2100 if (pl
->used_flag_ptr
!= 0)
2101 *pl
->used_flag_ptr
= 1;
2111 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2112 at the start of the list, otherwise it goes at the end.
2114 If WARN is nonzero, we will warn if no file is found
2115 through this prefix. WARN should point to an int
2116 which will be set to 1 if this entry is used.
2118 COMPONENT is the value to be passed to update_path.
2120 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2121 the complete value of machine_suffix.
2122 2 means try both machine_suffix and just_machine_suffix. */
2125 add_prefix (pprefix
, prefix
, component
, first
, require_machine_suffix
, warn
)
2126 struct path_prefix
*pprefix
;
2128 const char *component
;
2130 int require_machine_suffix
;
2133 struct prefix_list
*pl
, **prev
;
2136 if (! first
&& pprefix
->plist
)
2138 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
2143 prev
= &pprefix
->plist
;
2145 /* Keep track of the longest prefix */
2147 prefix
= update_path (prefix
, component
);
2148 len
= strlen (prefix
);
2149 if (len
> pprefix
->max_len
)
2150 pprefix
->max_len
= len
;
2152 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2153 pl
->prefix
= save_string (prefix
, len
);
2154 pl
->require_machine_suffix
= require_machine_suffix
;
2155 pl
->used_flag_ptr
= warn
;
2162 pl
->next
= (struct prefix_list
*) 0;
2166 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2169 unused_prefix_warnings (pprefix
)
2170 struct path_prefix
*pprefix
;
2172 struct prefix_list
*pl
= pprefix
->plist
;
2176 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
2178 if (pl
->require_machine_suffix
&& machine_suffix
)
2179 error ("file path prefix `%s%s' never used", pl
->prefix
,
2182 error ("file path prefix `%s' never used", pl
->prefix
);
2184 /* Prevent duplicate warnings. */
2185 *pl
->used_flag_ptr
= 1;
2193 /* Execute the command specified by the arguments on the current line of spec.
2194 When using pipes, this includes several piped-together commands
2195 with `|' between them.
2197 Return 0 if successful, -1 if failed. */
2203 int n_commands
; /* # of command. */
2207 const char *prog
; /* program name. */
2208 char **argv
; /* vector of args. */
2209 int pid
; /* pid of process for this command. */
2212 struct command
*commands
; /* each command buffer with above info. */
2214 /* Count # of piped commands. */
2215 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2216 if (strcmp (argbuf
[i
], "|") == 0)
2219 /* Get storage for each command. */
2221 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2223 /* Split argbuf into its separate piped processes,
2224 and record info about each one.
2225 Also search for the programs that are to be run. */
2227 commands
[0].prog
= argbuf
[0]; /* first command. */
2228 commands
[0].argv
= &argbuf
[0];
2229 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2232 commands
[0].argv
[0] = string
;
2234 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2235 if (strcmp (argbuf
[i
], "|") == 0)
2236 { /* each command. */
2237 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2238 fatal ("-pipe not supported");
2240 argbuf
[i
] = 0; /* termination of command args. */
2241 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2242 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2243 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2245 commands
[n_commands
].argv
[0] = string
;
2249 argbuf
[argbuf_index
] = 0;
2251 /* If -v, print what we are about to do, and maybe query. */
2255 /* For help listings, put a blank line between sub-processes. */
2256 if (print_help_list
)
2257 fputc ('\n', stderr
);
2259 /* Print each piped command as a separate line. */
2260 for (i
= 0; i
< n_commands
; i
++)
2264 for (j
= commands
[i
].argv
; *j
; j
++)
2265 fprintf (stderr
, " %s", *j
);
2267 /* Print a pipe symbol after all but the last command. */
2268 if (i
+ 1 != n_commands
)
2269 fprintf (stderr
, " |");
2270 fprintf (stderr
, "\n");
2274 notice ("\nGo ahead? (y or n) ");
2278 while (getchar () != '\n')
2281 if (i
!= 'y' && i
!= 'Y')
2286 /* Run each piped subprocess. */
2288 for (i
= 0; i
< n_commands
; i
++)
2290 char *errmsg_fmt
, *errmsg_arg
;
2291 char *string
= commands
[i
].argv
[0];
2293 commands
[i
].pid
= pexecute (string
, commands
[i
].argv
,
2294 programname
, temp_filename
,
2295 &errmsg_fmt
, &errmsg_arg
,
2296 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2297 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2298 | (string
== commands
[i
].prog
2299 ? PEXECUTE_SEARCH
: 0)
2300 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2302 if (commands
[i
].pid
== -1)
2303 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2305 if (string
!= commands
[i
].prog
)
2311 /* Wait for all the subprocesses to finish.
2312 We don't care what order they finish in;
2313 we know that N_COMMANDS waits will get them all.
2314 Ignore subprocesses that we don't know about,
2315 since they can be spawned by the process that exec'ed us. */
2320 for (i
= 0; i
< n_commands
; )
2326 pid
= pwait (commands
[i
].pid
, &status
, 0);
2330 for (j
= 0; j
< n_commands
; j
++)
2331 if (commands
[j
].pid
== pid
)
2336 if (WIFSIGNALED (status
))
2338 fatal ("Internal compiler error: program %s got fatal signal %d",
2339 commands
[j
].prog
, WTERMSIG (status
));
2343 else if (WIFEXITED (status
)
2344 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2354 /* Find all the switches given to us
2355 and make a vector describing them.
2356 The elements of the vector are strings, one per switch given.
2357 If a switch uses following arguments, then the `part1' field
2358 is the switch itself and the `args' field
2359 is a null-terminated vector containing the following arguments.
2360 The `live_cond' field is 1 if the switch is true in a conditional spec,
2361 -1 if false (overridden by a later switch), and is initialized to zero.
2362 The `validated' field is nonzero if any spec has looked at this switch;
2363 if it remains zero at the end of the run, it must be meaningless. */
2373 static struct switchstr
*switches
;
2375 static int n_switches
;
2380 const char *language
;
2383 /* Also a vector of input files specified. */
2385 static struct infile
*infiles
;
2387 static int n_infiles
;
2389 /* This counts the number of libraries added by lang_specific_driver, so that
2390 we can tell if there were any user supplied any files or libraries. */
2392 static int added_libraries
;
2394 /* And a vector of corresponding output files is made up later. */
2396 static const char **outfiles
;
2398 /* Used to track if none of the -B paths are used. */
2401 /* Used to track if standard path isn't used and -b or -V is specified. */
2402 static int warn_std
;
2404 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2405 static int *warn_std_ptr
= 0;
2408 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2410 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2411 is true if we should look for an executable suffix as well. */
2414 convert_filename (name
, do_exe
)
2424 len
= strlen (name
);
2426 #ifdef HAVE_OBJECT_SUFFIX
2427 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2429 && name
[len
- 2] == '.'
2430 && name
[len
- 1] == 'o')
2432 obstack_grow (&obstack
, name
, len
- 2);
2433 obstack_grow0 (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
2434 name
= obstack_finish (&obstack
);
2438 #ifdef HAVE_EXECUTABLE_SUFFIX
2439 /* If there is no filetype, make it the executable suffix (which includes
2440 the "."). But don't get confused if we have just "-o". */
2441 if (! do_exe
|| EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
2444 for (i
= len
- 1; i
>= 0; i
--)
2445 if (IS_DIR_SEPARATOR (name
[i
]))
2448 for (i
++; i
< len
; i
++)
2452 obstack_grow (&obstack
, name
, len
);
2453 obstack_grow0 (&obstack
, EXECUTABLE_SUFFIX
, strlen (EXECUTABLE_SUFFIX
));
2454 name
= obstack_finish (&obstack
);
2461 /* Display the command line switches accepted by gcc. */
2465 printf ("Usage: %s [options] file...\n", programname
);
2466 printf ("Options:\n");
2468 printf (" --help Display this information\n");
2470 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2471 printf (" -dumpspecs Display all of the built in spec strings\n");
2472 printf (" -dumpversion Display the version of the compiler\n");
2473 printf (" -dumpmachine Display the compiler's target processor\n");
2474 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2475 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2476 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2477 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2478 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2479 printf (" -print-multi-lib Display the mapping between command line options and\n");
2480 printf (" multiple library search directories\n");
2481 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2482 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2483 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2484 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2485 printf (" -save-temps Do not delete intermediate files\n");
2486 printf (" -pipe Use pipes rather than intermediate files\n");
2487 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2488 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2489 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2490 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2491 printf (" -V <version> Run gcc version number <version>, if installed\n");
2492 printf (" -v Display the programs invoked by the compiler\n");
2493 printf (" -E Preprocess only; do not compile, assemble or link\n");
2494 printf (" -S Compile only; do not assemble or link\n");
2495 printf (" -c Compile and assemble, but do not link\n");
2496 printf (" -o <file> Place the output into <file>\n");
2497 printf (" -x <language> Specify the language of the following input files\n");
2498 printf (" Permissable languages include: c c++ assembler none\n");
2499 printf (" 'none' means revert to the default behaviour of\n");
2500 printf (" guessing the language based on the file's extension\n");
2502 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2503 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2505 printf ("on to these processes the -W<letter> options must be used.\n");
2507 /* The rest of the options are displayed by invocations of the various
2512 add_preprocessor_option (option
, len
)
2513 const char * option
;
2516 n_preprocessor_options
++;
2518 if (! preprocessor_options
)
2519 preprocessor_options
2520 = (char **) xmalloc (n_preprocessor_options
* sizeof (char *));
2522 preprocessor_options
2523 = (char **) xrealloc (preprocessor_options
,
2524 n_preprocessor_options
* sizeof (char *));
2526 preprocessor_options
[n_preprocessor_options
- 1] =
2527 save_string (option
, len
);
2531 add_assembler_option (option
, len
)
2532 const char * option
;
2535 n_assembler_options
++;
2537 if (! assembler_options
)
2539 = (char **) xmalloc (n_assembler_options
* sizeof (char *));
2542 = (char **) xrealloc (assembler_options
,
2543 n_assembler_options
* sizeof (char *));
2545 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
2549 add_linker_option (option
, len
)
2550 const char * option
;
2555 if (! linker_options
)
2557 = (char **) xmalloc (n_linker_options
* sizeof (char *));
2560 = (char **) xrealloc (linker_options
,
2561 n_linker_options
* sizeof (char *));
2563 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
2566 /* Create the vector `switches' and its contents.
2567 Store its length in `n_switches'. */
2570 process_command (argc
, argv
)
2577 char *spec_lang
= 0;
2578 int last_language_n_infiles
;
2581 int lang_n_infiles
= 0;
2583 GET_ENV_PATH_LIST (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
2587 added_libraries
= 0;
2589 /* Figure compiler version from version string. */
2591 compiler_version
= temp1
=
2592 save_string (version_string
, strlen (version_string
));
2593 for (; *temp1
; ++temp1
)
2602 /* Set up the default search paths. */
2604 if (gcc_exec_prefix
)
2606 int len
= strlen (gcc_exec_prefix
);
2607 if (len
> (int) sizeof ("/lib/gcc-lib/")-1
2608 && (IS_DIR_SEPARATOR (gcc_exec_prefix
[len
-1])))
2610 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc-lib/") + 1;
2611 if (IS_DIR_SEPARATOR (*temp
)
2612 && strncmp (temp
+1, "lib", 3) == 0
2613 && IS_DIR_SEPARATOR (temp
[4])
2614 && strncmp (temp
+5, "gcc-lib", 7) == 0)
2615 len
-= sizeof ("/lib/gcc-lib/") - 1;
2618 set_std_prefix (gcc_exec_prefix
, len
);
2619 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2620 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2623 /* COMPILER_PATH and LIBRARY_PATH have values
2624 that are lists of directory names with colons. */
2626 GET_ENV_PATH_LIST (temp
, "COMPILER_PATH");
2629 const char *startp
, *endp
;
2630 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2632 startp
= endp
= temp
;
2635 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2637 strncpy (nstore
, startp
, endp
-startp
);
2639 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2640 else if (!IS_DIR_SEPARATOR (endp
[-1]))
2642 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2643 nstore
[endp
-startp
+1] = 0;
2646 nstore
[endp
-startp
] = 0;
2647 add_prefix (&exec_prefixes
, nstore
, 0, 0, 0, NULL_PTR
);
2648 add_prefix (&include_prefixes
,
2649 concat (nstore
, "include", NULL_PTR
),
2653 endp
= startp
= endp
+ 1;
2660 GET_ENV_PATH_LIST (temp
, "LIBRARY_PATH");
2661 if (temp
&& *cross_compile
== '0')
2663 const char *startp
, *endp
;
2664 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2666 startp
= endp
= temp
;
2669 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2671 strncpy (nstore
, startp
, endp
-startp
);
2673 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2674 else if (!IS_DIR_SEPARATOR (endp
[-1]))
2676 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2677 nstore
[endp
-startp
+1] = 0;
2680 nstore
[endp
-startp
] = 0;
2681 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2685 endp
= startp
= endp
+ 1;
2692 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2693 GET_ENV_PATH_LIST (temp
, "LPATH");
2694 if (temp
&& *cross_compile
== '0')
2696 const char *startp
, *endp
;
2697 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2699 startp
= endp
= temp
;
2702 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2704 strncpy (nstore
, startp
, endp
-startp
);
2706 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2707 else if (!IS_DIR_SEPARATOR (endp
[-1]))
2709 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2710 nstore
[endp
-startp
+1] = 0;
2713 nstore
[endp
-startp
] = 0;
2714 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2718 endp
= startp
= endp
+ 1;
2725 /* Convert new-style -- options to old-style. */
2726 translate_options (&argc
, &argv
);
2728 /* Do language-specific adjustment/addition of flags. */
2729 lang_specific_driver (fatal
, &argc
, &argv
, &added_libraries
);
2731 /* Scan argv twice. Here, the first time, just count how many switches
2732 there will be in their vector, and how many input files in theirs.
2733 Here we also parse the switches that cc itself uses (e.g. -v). */
2735 for (i
= 1; i
< argc
; i
++)
2737 if (! strcmp (argv
[i
], "-dumpspecs"))
2739 struct spec_list
*sl
;
2741 for (sl
= specs
; sl
; sl
= sl
->next
)
2742 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
2743 if (link_command_spec
)
2744 printf ("*link_command:\n%s\n\n", link_command_spec
);
2747 else if (! strcmp (argv
[i
], "-dumpversion"))
2749 printf ("%s\n", spec_version
);
2752 else if (! strcmp (argv
[i
], "-dumpmachine"))
2754 printf ("%s\n", spec_machine
);
2757 else if (strcmp (argv
[i
], "-fhelp") == 0)
2759 /* translate_options () has turned --help into -fhelp. */
2760 print_help_list
= 1;
2762 /* We will be passing a dummy file on to the sub-processes. */
2766 add_preprocessor_option ("--help", 6);
2767 add_assembler_option ("--help", 6);
2768 add_linker_option ("--help", 6);
2770 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2771 print_search_dirs
= 1;
2772 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2773 print_file_name
= "libgcc.a";
2774 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2775 print_file_name
= argv
[i
] + 17;
2776 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2777 print_prog_name
= argv
[i
] + 17;
2778 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2779 print_multi_lib
= 1;
2780 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2781 print_multi_directory
= 1;
2782 else if (! strncmp (argv
[i
], "-Wa,", 4))
2785 /* Pass the rest of this option to the assembler. */
2787 /* Split the argument at commas. */
2789 for (j
= 4; argv
[i
][j
]; j
++)
2790 if (argv
[i
][j
] == ',')
2792 add_assembler_option (argv
[i
] + prev
, j
- prev
);
2796 /* Record the part after the last comma. */
2797 add_assembler_option (argv
[i
] + prev
, j
- prev
);
2799 else if (! strncmp (argv
[i
], "-Wp,", 4))
2802 /* Pass the rest of this option to the preprocessor. */
2804 /* Split the argument at commas. */
2806 for (j
= 4; argv
[i
][j
]; j
++)
2807 if (argv
[i
][j
] == ',')
2809 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
2813 /* Record the part after the last comma. */
2814 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
2816 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2817 /* The +e options to the C++ front-end. */
2819 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2822 /* Split the argument at commas. */
2823 for (j
= 3; argv
[i
][j
]; j
++)
2824 n_infiles
+= (argv
[i
][j
] == ',');
2826 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2829 fatal ("argument to `-Xlinker' is missing");
2834 else if (strncmp (argv
[i
], "-l", 2) == 0)
2836 else if (strcmp (argv
[i
], "-save-temps") == 0)
2838 save_temps_flag
= 1;
2841 else if (strcmp (argv
[i
], "-specs") == 0)
2843 struct user_specs
*user
= (struct user_specs
*)
2844 xmalloc (sizeof (struct user_specs
));
2846 fatal ("argument to `-specs' is missing");
2848 user
->next
= (struct user_specs
*)0;
2849 user
->filename
= argv
[i
];
2850 if (user_specs_tail
)
2851 user_specs_tail
->next
= user
;
2853 user_specs_head
= user
;
2854 user_specs_tail
= user
;
2856 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
2858 struct user_specs
*user
= (struct user_specs
*)
2859 xmalloc (sizeof (struct user_specs
));
2860 if (strlen (argv
[i
]) == 7)
2861 fatal ("argument to `-specs=' is missing");
2863 user
->next
= (struct user_specs
*)0;
2864 user
->filename
= argv
[i
]+7;
2865 if (user_specs_tail
)
2866 user_specs_tail
->next
= user
;
2868 user_specs_head
= user
;
2869 user_specs_tail
= user
;
2871 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2873 register char *p
= &argv
[i
][1];
2874 register int c
= *p
;
2880 if (p
[1] == 0 && i
+ 1 == argc
)
2881 fatal ("argument to `-b' is missing");
2883 spec_machine
= argv
[++i
];
2885 spec_machine
= p
+ 1;
2887 warn_std_ptr
= &warn_std
;
2893 if (p
[1] == 0 && i
+ 1 == argc
)
2894 fatal ("argument to `-B' is missing");
2899 add_prefix (&exec_prefixes
, value
, NULL_PTR
, 1, 0, &warn_B
);
2900 add_prefix (&startfile_prefixes
, value
, NULL_PTR
,
2902 add_prefix (&include_prefixes
, concat (value
, "include",
2904 NULL_PTR
, 1, 0, NULL_PTR
);
2906 /* As a kludge, if the arg is "[foo/]stageN/", just add
2907 "[foo/]include" to the include prefix. */
2909 int len
= strlen (value
);
2912 && (IS_DIR_SEPARATOR (value
[len
- 8]))))
2913 && strncmp (value
+ len
- 7, "stage", 5) == 0
2914 && ISDIGIT (value
[len
- 2])
2915 && (IS_DIR_SEPARATOR (value
[len
- 1])))
2918 add_prefix (&include_prefixes
, "include", NULL_PTR
,
2922 char *string
= xmalloc (len
+ 1);
2923 strncpy (string
, value
, len
-7);
2924 strcpy (string
+len
-7, "include");
2925 add_prefix (&include_prefixes
, string
, NULL_PTR
,
2934 case 'v': /* Print our subcommands and print versions. */
2936 /* If they do anything other than exactly `-v', don't set
2937 verbose_flag; rather, continue on to give the error. */
2945 if (p
[1] == 0 && i
+ 1 == argc
)
2946 fatal ("argument to `-V' is missing");
2948 spec_version
= argv
[++i
];
2950 spec_version
= p
+ 1;
2951 compiler_version
= spec_version
;
2952 warn_std_ptr
= &warn_std
;
2954 /* Validate the version number. Use the same checks
2955 done when inserting it into a spec.
2957 The format of the version string is
2958 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2960 const char *v
= compiler_version
;
2962 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2963 while (! ISDIGIT (*v
))
2966 if (v
> compiler_version
&& v
[-1] != '-')
2967 fatal ("invalid version number format");
2969 /* Set V after the first period. */
2970 while (ISDIGIT (*v
))
2974 fatal ("invalid version number format");
2977 while (ISDIGIT (*v
))
2980 if (*v
!= 0 && *v
!= ' ' && *v
!= '.' && *v
!= '-')
2981 fatal ("invalid version number format");
2997 #if defined(HAVE_EXECUTABLE_SUFFIX)
3002 /* Forward scan, just in case -S or -c is specified
3009 if (argv
[j
][0] == '-')
3011 if (SWITCH_CURTAILS_COMPILATION (argv
[j
][1])
3017 else if (skip
= SWITCH_TAKES_ARG (argv
[j
][1]))
3018 j
+= skip
- (argv
[j
][2] != 0);
3019 else if (skip
= WORD_SWITCH_TAKES_ARG (argv
[j
] + 1))
3026 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3028 argv
[i
+1] = convert_filename (argv
[i
+1], ! have_c
);
3030 argv
[i
] = convert_filename (argv
[i
], ! have_c
);
3038 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3039 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3040 else if (WORD_SWITCH_TAKES_ARG (p
))
3041 i
+= WORD_SWITCH_TAKES_ARG (p
);
3051 if (have_c
&& have_o
&& lang_n_infiles
> 1)
3052 fatal ("cannot specify -o with -c or -S and multiple compilations");
3054 /* Set up the search paths before we go looking for config files. */
3056 /* These come before the md prefixes so that we will find gcc's subcommands
3057 (such as cpp) rather than those of the host system. */
3058 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3059 as well as trying the machine and the version. */
3061 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
3062 0, 2, warn_std_ptr
);
3063 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3064 0, 2, warn_std_ptr
);
3067 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
3068 0, 1, warn_std_ptr
);
3069 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3070 0, 1, warn_std_ptr
);
3072 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
3073 dir_separator_str
, NULL_PTR
);
3075 /* If tooldir is relative, base it on exec_prefixes. A relative
3076 tooldir lets us move the installed tree as a unit.
3078 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3079 directories, so that we can search both the user specified directory
3080 and the standard place. */
3082 if (!IS_DIR_SEPARATOR (*tooldir_prefix
))
3084 if (gcc_exec_prefix
)
3086 char *gcc_exec_tooldir_prefix
3087 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
3088 spec_version
, dir_separator_str
, tooldir_prefix
, NULL_PTR
);
3090 add_prefix (&exec_prefixes
,
3091 concat (gcc_exec_tooldir_prefix
, "bin",
3092 dir_separator_str
, NULL_PTR
),
3093 NULL_PTR
, 0, 0, NULL_PTR
);
3094 add_prefix (&startfile_prefixes
,
3095 concat (gcc_exec_tooldir_prefix
, "lib",
3096 dir_separator_str
, NULL_PTR
),
3097 NULL_PTR
, 0, 0, NULL_PTR
);
3100 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
3101 dir_separator_str
, spec_version
,
3102 dir_separator_str
, tooldir_prefix
, NULL_PTR
);
3105 add_prefix (&exec_prefixes
,
3106 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL_PTR
),
3107 "BINUTILS", 0, 0, NULL_PTR
);
3108 add_prefix (&startfile_prefixes
,
3109 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL_PTR
),
3110 "BINUTILS", 0, 0, NULL_PTR
);
3112 /* More prefixes are enabled in main, after we read the specs file
3113 and determine whether this is cross-compilation or not. */
3116 /* Then create the space for the vectors and scan again. */
3118 switches
= ((struct switchstr
*)
3119 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
3120 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
3123 last_language_n_infiles
= -1;
3125 /* This, time, copy the text of each switch and store a pointer
3126 to the copy in the vector of switches.
3127 Store all the infiles in their vector. */
3129 for (i
= 1; i
< argc
; i
++)
3131 /* Just skip the switches that were handled by the preceding loop. */
3132 if (! strncmp (argv
[i
], "-Wa,", 4))
3134 else if (! strncmp (argv
[i
], "-Wp,", 4))
3136 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3138 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3140 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3142 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3144 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3146 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3148 else if (strcmp (argv
[i
], "-fhelp") == 0)
3152 /* Create a dummy input file, so that we can pass --help on to
3153 the various sub-processes. */
3154 infiles
[n_infiles
].language
= "c";
3155 infiles
[n_infiles
++].name
= "help-dummy";
3157 /* Preserve the --help switch so that it can be caught by the
3159 switches
[n_switches
].part1
= "--help";
3160 switches
[n_switches
].args
= 0;
3161 switches
[n_switches
].live_cond
= 0;
3162 switches
[n_switches
].validated
= 0;
3167 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3169 /* Compensate for the +e options to the C++ front-end;
3170 they're there simply for cfront call-compatibility. We do
3171 some magic in default_compilers to pass them down properly.
3172 Note we deliberately start at the `+' here, to avoid passing
3173 -e0 or -e1 down into the linker. */
3174 switches
[n_switches
].part1
= &argv
[i
][0];
3175 switches
[n_switches
].args
= 0;
3176 switches
[n_switches
].live_cond
= 0;
3177 switches
[n_switches
].validated
= 0;
3180 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3183 /* Split the argument at commas. */
3185 for (j
= 4; argv
[i
][j
]; j
++)
3186 if (argv
[i
][j
] == ',')
3188 infiles
[n_infiles
].language
= "*";
3189 infiles
[n_infiles
++].name
3190 = save_string (argv
[i
] + prev
, j
- prev
);
3193 /* Record the part after the last comma. */
3194 infiles
[n_infiles
].language
= "*";
3195 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
3197 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3199 infiles
[n_infiles
].language
= "*";
3200 infiles
[n_infiles
++].name
= argv
[++i
];
3202 else if (strncmp (argv
[i
], "-l", 2) == 0)
3204 infiles
[n_infiles
].language
= "*";
3205 infiles
[n_infiles
++].name
= argv
[i
];
3207 else if (strcmp (argv
[i
], "-specs") == 0)
3209 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3211 /* -save-temps overrides -pipe, so that temp files are produced */
3212 else if (save_temps_flag
&& strcmp (argv
[i
], "-pipe") == 0)
3213 error ("Warning: -pipe ignored since -save-temps specified");
3214 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3216 register char *p
= &argv
[i
][1];
3217 register int c
= *p
;
3221 if (p
[1] == 0 && i
+ 1 == argc
)
3222 fatal ("argument to `-x' is missing");
3224 spec_lang
= argv
[++i
];
3227 if (! strcmp (spec_lang
, "none"))
3228 /* Suppress the warning if -xnone comes after the last input
3229 file, because alternate command interfaces like g++ might
3230 find it useful to place -xnone after each input file. */
3233 last_language_n_infiles
= n_infiles
;
3236 switches
[n_switches
].part1
= p
;
3237 /* Deal with option arguments in separate argv elements. */
3238 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3239 || WORD_SWITCH_TAKES_ARG (p
))
3242 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
3246 /* Count only the option arguments in separate argv elements. */
3247 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3249 if (i
+ n_args
>= argc
)
3250 fatal ("argument to `-%s' is missing", p
);
3251 switches
[n_switches
].args
3252 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
3254 switches
[n_switches
].args
[j
++] = argv
[++i
];
3255 /* Null-terminate the vector. */
3256 switches
[n_switches
].args
[j
] = 0;
3258 else if (index (switches_need_spaces
, c
))
3260 /* On some systems, ld cannot handle some options without
3261 a space. So split the option from its argument. */
3262 char *part1
= (char *) xmalloc (2);
3266 switches
[n_switches
].part1
= part1
;
3267 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
3268 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
3269 strcpy (switches
[n_switches
].args
[0], &p
[1]);
3270 switches
[n_switches
].args
[1] = 0;
3273 switches
[n_switches
].args
= 0;
3275 switches
[n_switches
].live_cond
= 0;
3276 switches
[n_switches
].validated
= 0;
3277 /* This is always valid, since gcc.c itself understands it. */
3278 if (!strcmp (p
, "save-temps"))
3279 switches
[n_switches
].validated
= 1;
3282 char ch
= switches
[n_switches
].part1
[0];
3283 if (ch
== 'V' || ch
== 'b' || ch
== 'B')
3284 switches
[n_switches
].validated
= 1;
3290 #ifdef HAVE_OBJECT_SUFFIX
3291 argv
[i
] = convert_filename (argv
[i
], 0);
3294 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], R_OK
) < 0)
3296 perror_with_name (argv
[i
]);
3301 infiles
[n_infiles
].language
= spec_lang
;
3302 infiles
[n_infiles
++].name
= argv
[i
];
3307 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
3308 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
3310 switches
[n_switches
].part1
= 0;
3311 infiles
[n_infiles
].name
= 0;
3314 /* Process a spec string, accumulating and running commands. */
3316 /* These variables describe the input file name.
3317 input_file_number is the index on outfiles of this file,
3318 so that the output file name can be stored for later use by %o.
3319 input_basename is the start of the part of the input file
3320 sans all directory names, and basename_length is the number
3321 of characters starting there excluding the suffix .c or whatever. */
3323 const char *input_filename
;
3324 static int input_file_number
;
3325 size_t input_filename_length
;
3326 static int basename_length
;
3327 static const char *input_basename
;
3328 static const char *input_suffix
;
3330 /* These are variables used within do_spec and do_spec_1. */
3332 /* Nonzero if an arg has been started and not yet terminated
3333 (with space, tab or newline). */
3334 static int arg_going
;
3336 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3337 is a temporary file name. */
3338 static int delete_this_arg
;
3340 /* Nonzero means %w has been seen; the next arg to be terminated
3341 is the output file name of this compilation. */
3342 static int this_is_output_file
;
3344 /* Nonzero means %s has been seen; the next arg to be terminated
3345 is the name of a library file and we should try the standard
3346 search dirs for it. */
3347 static int this_is_library_file
;
3349 /* Nonzero means that the input of this command is coming from a pipe. */
3350 static int input_from_pipe
;
3352 /* Process the spec SPEC and run the commands specified therein.
3353 Returns 0 if the spec is successfully processed; -1 if failed. */
3363 delete_this_arg
= 0;
3364 this_is_output_file
= 0;
3365 this_is_library_file
= 0;
3366 input_from_pipe
= 0;
3368 value
= do_spec_1 (spec
, 0, NULL_PTR
);
3370 /* Force out any unfinished command.
3371 If -pipe, this forces out the last command if it ended in `|'. */
3374 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3377 if (argbuf_index
> 0)
3384 /* Process the sub-spec SPEC as a portion of a larger spec.
3385 This is like processing a whole spec except that we do
3386 not initialize at the beginning and we do not supply a
3387 newline by default at the end.
3388 INSWITCH nonzero means don't process %-sequences in SPEC;
3389 in this case, % is treated as an ordinary character.
3390 This is used while substituting switches.
3391 INSWITCH nonzero also causes SPC not to terminate an argument.
3393 Value is zero unless a line was finished
3394 and the command on that line reported an error. */
3397 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3400 const char *soft_matched_part
;
3402 register const char *p
= spec
;
3409 /* If substituting a switch, treat all chars like letters.
3410 Otherwise, NL, SPC, TAB and % are special. */
3411 switch (inswitch
? 'a' : c
)
3414 /* End of line: finish any pending argument,
3415 then run the pending command if one has been started. */
3418 obstack_1grow (&obstack
, 0);
3419 string
= obstack_finish (&obstack
);
3420 if (this_is_library_file
)
3421 string
= find_file (string
);
3422 store_arg (string
, delete_this_arg
, this_is_output_file
);
3423 if (this_is_output_file
)
3424 outfiles
[input_file_number
] = string
;
3428 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3430 for (i
= 0; i
< n_switches
; i
++)
3431 if (!strcmp (switches
[i
].part1
, "pipe"))
3434 /* A `|' before the newline means use a pipe here,
3435 but only if -pipe was specified.
3436 Otherwise, execute now and don't pass the `|' as an arg. */
3439 input_from_pipe
= 1;
3440 switches
[i
].validated
= 1;
3447 if (argbuf_index
> 0)
3453 /* Reinitialize for a new command, and for a new argument. */
3456 delete_this_arg
= 0;
3457 this_is_output_file
= 0;
3458 this_is_library_file
= 0;
3459 input_from_pipe
= 0;
3463 /* End any pending argument. */
3466 obstack_1grow (&obstack
, 0);
3467 string
= obstack_finish (&obstack
);
3468 if (this_is_library_file
)
3469 string
= find_file (string
);
3470 store_arg (string
, delete_this_arg
, this_is_output_file
);
3471 if (this_is_output_file
)
3472 outfiles
[input_file_number
] = string
;
3476 obstack_1grow (&obstack
, c
);
3482 /* Space or tab ends an argument if one is pending. */
3485 obstack_1grow (&obstack
, 0);
3486 string
= obstack_finish (&obstack
);
3487 if (this_is_library_file
)
3488 string
= find_file (string
);
3489 store_arg (string
, delete_this_arg
, this_is_output_file
);
3490 if (this_is_output_file
)
3491 outfiles
[input_file_number
] = string
;
3493 /* Reinitialize for a new argument. */
3495 delete_this_arg
= 0;
3496 this_is_output_file
= 0;
3497 this_is_library_file
= 0;
3504 fatal ("Invalid specification! Bug in cc.");
3507 obstack_grow (&obstack
, input_basename
, basename_length
);
3512 delete_this_arg
= 2;
3515 /* Dump out the directories specified with LIBRARY_PATH,
3516 followed by the absolute directories
3517 that we search for startfiles. */
3520 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3521 size_t bufsize
= 100;
3522 char *buffer
= (char *) xmalloc (bufsize
);
3525 for (; pl
; pl
= pl
->next
)
3527 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3528 /* Used on systems which record the specified -L dirs
3529 and use them to search for dynamic linking. */
3530 /* Relative directories always come from -B,
3531 and it is better not to use them for searching
3532 at run time. In particular, stage1 loses */
3533 if (!IS_DIR_SEPARATOR (pl
->prefix
[0]))
3536 /* Try subdirectory if there is one. */
3537 if (multilib_dir
!= NULL
)
3541 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3543 bufsize
= (strlen (pl
->prefix
)
3544 + strlen (machine_suffix
)) * 2 + 1;
3545 buffer
= (char *) xrealloc (buffer
, bufsize
);
3546 strcpy (buffer
, pl
->prefix
);
3547 strcat (buffer
, machine_suffix
);
3548 if (is_directory (buffer
, multilib_dir
, 1))
3550 do_spec_1 ("-L", 0, NULL_PTR
);
3551 #ifdef SPACE_AFTER_L_OPTION
3552 do_spec_1 (" ", 0, NULL_PTR
);
3554 do_spec_1 (buffer
, 1, NULL_PTR
);
3555 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3556 /* Make this a separate argument. */
3557 do_spec_1 (" ", 0, NULL_PTR
);
3560 if (!pl
->require_machine_suffix
)
3562 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3564 do_spec_1 ("-L", 0, NULL_PTR
);
3565 #ifdef SPACE_AFTER_L_OPTION
3566 do_spec_1 (" ", 0, NULL_PTR
);
3568 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3569 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3570 /* Make this a separate argument. */
3571 do_spec_1 (" ", 0, NULL_PTR
);
3577 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3579 do_spec_1 ("-L", 0, NULL_PTR
);
3580 #ifdef SPACE_AFTER_L_OPTION
3581 do_spec_1 (" ", 0, NULL_PTR
);
3583 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3584 /* Remove slash from machine_suffix. */
3585 if (strlen (machine_suffix
) >= bufsize
)
3586 bufsize
= strlen (machine_suffix
) * 2 + 1;
3587 buffer
= (char *) xrealloc (buffer
, bufsize
);
3588 strcpy (buffer
, machine_suffix
);
3589 idx
= strlen (buffer
);
3590 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
3591 buffer
[idx
- 1] = 0;
3592 do_spec_1 (buffer
, 1, NULL_PTR
);
3593 /* Make this a separate argument. */
3594 do_spec_1 (" ", 0, NULL_PTR
);
3597 if (!pl
->require_machine_suffix
)
3599 if (is_directory (pl
->prefix
, "", 1))
3601 do_spec_1 ("-L", 0, NULL_PTR
);
3602 #ifdef SPACE_AFTER_L_OPTION
3603 do_spec_1 (" ", 0, NULL_PTR
);
3605 /* Remove slash from pl->prefix. */
3606 if (strlen (pl
->prefix
) >= bufsize
)
3607 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3608 buffer
= (char *) xrealloc (buffer
, bufsize
);
3609 strcpy (buffer
, pl
->prefix
);
3610 idx
= strlen (buffer
);
3611 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
3612 buffer
[idx
- 1] = 0;
3613 do_spec_1 (buffer
, 1, NULL_PTR
);
3614 /* Make this a separate argument. */
3615 do_spec_1 (" ", 0, NULL_PTR
);
3624 /* %efoo means report an error with `foo' as error message
3625 and don't execute any more commands for this file. */
3629 while (*p
!= 0 && *p
!= '\n') p
++;
3630 buf
= (char *) alloca (p
- q
+ 1);
3631 strncpy (buf
, q
, p
- q
);
3641 if (save_temps_flag
)
3643 obstack_grow (&obstack
, input_basename
, basename_length
);
3644 delete_this_arg
= 0;
3648 #ifdef MKTEMP_EACH_FILE
3649 /* ??? This has a problem: the total number of
3650 values mktemp can return is limited.
3651 That matters for the names of object files.
3652 In 2.4, do something about that. */
3653 struct temp_name
*t
;
3655 const char *suffix
= p
;
3657 if (p
[0] == '%' && p
[1] == 'O')
3660 /* We don't support extra suffix characters after %O. */
3661 if (*p
== '.' || ISALPHA ((unsigned char)*p
))
3663 suffix
= OBJECT_SUFFIX
;
3664 suffix_length
= strlen (OBJECT_SUFFIX
);
3668 while (*p
== '.' || ISALPHA ((unsigned char)*p
))
3670 suffix_length
= p
- suffix
;
3673 /* See if we already have an association of %g/%u/%U and
3675 for (t
= temp_names
; t
; t
= t
->next
)
3676 if (t
->length
== suffix_length
3677 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
3678 && t
->unique
== (c
!= 'g'))
3681 /* Make a new association if needed. %u requires one. */
3682 if (t
== 0 || c
== 'u')
3686 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3687 t
->next
= temp_names
;
3690 t
->length
= suffix_length
;
3691 t
->suffix
= save_string (suffix
, suffix_length
);
3692 t
->unique
= (c
!= 'g');
3693 temp_filename
= make_temp_file (t
->suffix
);
3694 temp_filename_length
= strlen (temp_filename
);
3695 t
->filename
= temp_filename
;
3696 t
->filename_length
= temp_filename_length
;
3699 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3700 delete_this_arg
= 1;
3702 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3703 if (c
== 'u' || c
== 'U')
3709 sprintf (buff
, "%d", unique
);
3710 obstack_grow (&obstack
, buff
, strlen (buff
));
3713 delete_this_arg
= 1;
3719 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3725 struct prefix_list
*pl
= include_prefixes
.plist
;
3727 if (gcc_exec_prefix
)
3729 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3730 /* Make this a separate argument. */
3731 do_spec_1 (" ", 0, NULL_PTR
);
3732 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3733 do_spec_1 (" ", 0, NULL_PTR
);
3736 for (; pl
; pl
= pl
->next
)
3738 do_spec_1 ("-isystem", 1, NULL_PTR
);
3739 /* Make this a separate argument. */
3740 do_spec_1 (" ", 0, NULL_PTR
);
3741 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3742 do_spec_1 (" ", 0, NULL_PTR
);
3749 int max
= n_infiles
;
3750 max
+= lang_specific_extra_outfiles
;
3752 for (i
= 0; i
< max
; i
++)
3754 store_arg (outfiles
[i
], 0, 0);
3759 obstack_grow (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
3764 this_is_library_file
= 1;
3768 this_is_output_file
= 1;
3773 int cur_index
= argbuf_index
;
3774 /* Handle the {...} following the %W. */
3777 p
= handle_braces (p
+ 1);
3780 /* If any args were output, mark the last one for deletion
3782 if (argbuf_index
!= cur_index
)
3783 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3787 /* %x{OPTION} records OPTION for %X to output. */
3793 /* Skip past the option value and make a copy. */
3798 string
= save_string (p1
+ 1, p
- p1
- 2);
3800 /* See if we already recorded this option. */
3801 for (i
= 0; i
< n_linker_options
; i
++)
3802 if (! strcmp (string
, linker_options
[i
]))
3808 /* This option is new; add it. */
3809 add_linker_option (string
, strlen (string
));
3813 /* Dump out the options accumulated previously using %x. */
3815 for (i
= 0; i
< n_linker_options
; i
++)
3817 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3818 /* Make each accumulated option a separate argument. */
3819 do_spec_1 (" ", 0, NULL_PTR
);
3823 /* Dump out the options accumulated previously using -Wa,. */
3825 for (i
= 0; i
< n_assembler_options
; i
++)
3827 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3828 /* Make each accumulated option a separate argument. */
3829 do_spec_1 (" ", 0, NULL_PTR
);
3833 /* Dump out the options accumulated previously using -Wp,. */
3835 for (i
= 0; i
< n_preprocessor_options
; i
++)
3837 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3838 /* Make each accumulated option a separate argument. */
3839 do_spec_1 (" ", 0, NULL_PTR
);
3843 /* Here are digits and numbers that just process
3844 a certain constant string as a spec. */
3847 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3853 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3859 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3865 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3871 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3877 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3883 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3889 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3895 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3901 value
= do_spec_1 (libgcc_spec
, 0, NULL_PTR
);
3908 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3912 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3916 if (! strncmp (y
, "-D", 2))
3917 /* Copy the whole option. */
3918 while (*y
&& *y
!= ' ' && *y
!= '\t')
3920 else if (*y
== ' ' || *y
== '\t')
3921 /* Copy whitespace to the result. */
3923 /* Don't copy other options. */
3930 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3938 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3942 /* Copy all of CPP_PREDEFINES into BUF,
3943 but put __ after every -D and at the end of each arg. */
3947 if (! strncmp (y
, "-D", 2))
3956 && ! ISUPPER ((unsigned char)*(y
+1))))
3958 /* Stick __ at front of macro name. */
3961 /* Arrange to stick __ at the end as well. */
3965 /* Copy the macro name. */
3966 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3975 /* Copy the value given, if any. */
3976 while (*y
&& *y
!= ' ' && *y
!= '\t')
3979 else if (*y
== ' ' || *y
== '\t')
3980 /* Copy whitespace to the result. */
3982 /* Don't copy -A options */
3988 /* Copy all of CPP_PREDEFINES into BUF,
3989 but put __ after every -D. */
3993 if (! strncmp (y
, "-D", 2))
3999 && ! ISUPPER ((unsigned char)*(y
+1))))
4001 /* Stick -D__ at front of macro name. */
4007 /* Copy the macro name. */
4008 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4011 /* Copy the value given, if any. */
4012 while (*y
&& *y
!= ' ' && *y
!= '\t')
4017 /* Do not copy this macro - we have just done it before */
4018 while (*y
&& *y
!= ' ' && *y
!= '\t')
4022 else if (*y
== ' ' || *y
== '\t')
4023 /* Copy whitespace to the result. */
4025 /* Don't copy -A options */
4031 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4035 if (! strncmp (y
, "-A", 2))
4036 /* Copy the whole option. */
4037 while (*y
&& *y
!= ' ' && *y
!= '\t')
4039 else if (*y
== ' ' || *y
== '\t')
4040 /* Copy whitespace to the result. */
4042 /* Don't copy other options. */
4049 value
= do_spec_1 (buf
, 0, NULL_PTR
);
4056 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
4061 /* Here we define characters other than letters and digits. */
4064 p
= handle_braces (p
);
4070 obstack_1grow (&obstack
, '%');
4074 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
4075 do_spec_1 (" ", 0, NULL_PTR
);
4078 /* Process a string found as the value of a spec given by name.
4079 This feature allows individual machine descriptions
4080 to add and use their own specs.
4081 %[...] modifies -D options the way %P does;
4082 %(...) uses the spec unmodified. */
4084 error ("Warning: use of obsolete %%[ operator in specs");
4087 const char *name
= p
;
4088 struct spec_list
*sl
;
4091 /* The string after the S/P is the name of a spec that is to be
4093 while (*p
&& *p
!= ')' && *p
!= ']')
4096 /* See if it's in the list */
4097 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
4098 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
4100 name
= *(sl
->ptr_spec
);
4102 notice ("Processing spec %c%s%c, which is '%s'\n",
4103 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
4112 value
= do_spec_1 (name
, 0, NULL_PTR
);
4118 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
4120 const char *y
= name
;
4123 /* Copy all of NAME into BUF, but put __ after
4124 every -D and at the end of each arg, */
4127 if (! strncmp (y
, "-D", 2))
4137 else if (flag
&& (*y
== ' ' || *y
== '\t' || *y
== '='
4138 || *y
== '}' || *y
== 0))
4151 value
= do_spec_1 (buf
, 0, NULL_PTR
);
4157 /* Discard the closing paren or bracket. */
4165 int c1
= *p
++; /* Select first or second version number. */
4166 char *v
= compiler_version
;
4169 /* The format of the version string is
4170 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4172 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4173 while (! ISDIGIT (*v
))
4175 if (v
> compiler_version
&& v
[-1] != '-')
4178 /* If desired, advance to second version number. */
4181 /* Set V after the first period. */
4182 while (ISDIGIT (*v
))
4189 /* Set Q at the next period or at the end. */
4191 while (ISDIGIT (*q
))
4193 if (*q
!= 0 && *q
!= ' ' && *q
!= '.' && *q
!= '-')
4196 /* Put that part into the command. */
4197 obstack_grow (&obstack
, v
, q
- v
);
4203 if (input_from_pipe
)
4204 do_spec_1 ("-", 0, NULL_PTR
);
4213 /* Backslash: treat next character as ordinary. */
4218 /* Ordinary character: put it into the current argument. */
4219 obstack_1grow (&obstack
, c
);
4223 return 0; /* End of string */
4226 /* Return 0 if we call do_spec_1 and that returns -1. */
4230 register const char *p
;
4232 const char *filter
, *body
= NULL
, *endbody
= NULL
;
4236 int include_blanks
= 1;
4239 /* A '^' after the open-brace means to not give blanks before args. */
4240 include_blanks
= 0, ++p
;
4243 /* A `|' after the open-brace means,
4244 if the test fails, output a single minus sign rather than nothing.
4245 This is used in %{|!pipe:...}. */
4249 negate
= suffix
= 0;
4252 /* A `!' after the open-brace negates the condition:
4253 succeed if the specified switch is not present. */
4257 /* A `.' after the open-brace means test against the current suffix. */
4267 while (*p
!= ':' && *p
!= '}' && *p
!= '|') p
++;
4269 if (*p
== '|' && pipe_p
)
4276 register int count
= 1;
4277 register const char *q
= p
;
4279 while (*q
++ != ':') continue;
4295 body
= p
, endbody
= p
+1;
4300 int found
= (input_suffix
!= 0
4301 && (long) strlen (input_suffix
) == (long)(p
- filter
)
4302 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
4308 && do_spec_1 (save_string (body
, endbody
-body
-1), 0, NULL_PTR
) < 0)
4311 else if (p
[-1] == '*' && p
[0] == '}')
4313 /* Substitute all matching switches as separate args. */
4316 for (i
= 0; i
< n_switches
; i
++)
4317 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4318 && check_live_switch (i
, p
- filter
))
4319 give_switch (i
, 0, include_blanks
);
4323 /* Test for presence of the specified switch. */
4327 /* If name specified ends in *, as in {x*:...},
4328 check for %* and handle that case. */
4329 if (p
[-1] == '*' && !negate
)
4332 const char *r
= body
;
4334 /* First see whether we have %*. */
4338 if (*r
== '%' && r
[1] == '*')
4342 /* If we do, handle that case. */
4345 /* Substitute all matching switches as separate args.
4346 But do this by substituting for %*
4347 in the text that follows the colon. */
4349 unsigned hard_match_len
= p
- filter
- 1;
4350 char *string
= save_string (body
, endbody
- body
- 1);
4352 for (i
= 0; i
< n_switches
; i
++)
4353 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4354 && check_live_switch (i
, -1))
4356 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
4357 /* Pass any arguments this switch has. */
4358 give_switch (i
, 1, 1);
4361 /* We didn't match. Try again. */
4368 /* If name specified ends in *, as in {x*:...},
4369 check for presence of any switch name starting with x. */
4372 for (i
= 0; i
< n_switches
; i
++)
4374 unsigned hard_match_len
= p
- filter
- 1;
4376 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4377 && check_live_switch (i
, hard_match_len
))
4383 /* Otherwise, check for presence of exact name specified. */
4386 for (i
= 0; i
< n_switches
; i
++)
4388 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4389 && switches
[i
].part1
[p
- filter
] == 0
4390 && check_live_switch (i
, -1))
4398 /* If it is as desired (present for %{s...}, absent for %{!s...})
4399 then substitute either the switch or the specified
4400 conditional text. */
4401 if (present
!= negate
)
4405 give_switch (i
, 0, include_blanks
);
4409 if (do_spec_1 (save_string (body
, endbody
- body
- 1),
4416 /* Here if a %{|...} conditional fails: output a minus sign,
4417 which means "standard output" or "standard input". */
4418 do_spec_1 ("-", 0, NULL_PTR
);
4423 /* We didn't match; try again. */
4430 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4431 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4432 spec, or -1 if either exact match or %* is used.
4434 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4435 whose value does not begin with "no-" is obsoleted by the same value
4436 with the "no-", similarly for a switch with the "no-" prefix. */
4439 check_live_switch (switchnum
, prefix_length
)
4443 const char *name
= switches
[switchnum
].part1
;
4446 /* In the common case of {<at-most-one-letter>*}, a negating
4447 switch would always match, so ignore that case. We will just
4448 send the conflicting switches to the compiler phase. */
4449 if (prefix_length
>= 0 && prefix_length
<= 1)
4452 /* If we already processed this switch and determined if it was
4453 live or not, return our past determination. */
4454 if (switches
[switchnum
].live_cond
!= 0)
4455 return switches
[switchnum
].live_cond
> 0;
4457 /* Now search for duplicate in a manner that depends on the name. */
4461 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4462 if (switches
[i
].part1
[0] == 'O')
4464 switches
[switchnum
].validated
= 1;
4465 switches
[switchnum
].live_cond
= -1;
4470 case 'W': case 'f': case 'm':
4471 if (! strncmp (name
+ 1, "no-", 3))
4473 /* We have Xno-YYY, search for XYYY. */
4474 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4475 if (switches
[i
].part1
[0] == name
[0]
4476 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4478 switches
[switchnum
].validated
= 1;
4479 switches
[switchnum
].live_cond
= -1;
4485 /* We have XYYY, search for Xno-YYY. */
4486 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4487 if (switches
[i
].part1
[0] == name
[0]
4488 && switches
[i
].part1
[1] == 'n'
4489 && switches
[i
].part1
[2] == 'o'
4490 && switches
[i
].part1
[3] == '-'
4491 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4493 switches
[switchnum
].validated
= 1;
4494 switches
[switchnum
].live_cond
= -1;
4501 /* Otherwise the switch is live. */
4502 switches
[switchnum
].live_cond
= 1;
4506 /* Pass a switch to the current accumulating command
4507 in the same form that we received it.
4508 SWITCHNUM identifies the switch; it is an index into
4509 the vector of switches gcc received, which is `switches'.
4510 This cannot fail since it never finishes a command line.
4512 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4514 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4518 give_switch (switchnum
, omit_first_word
, include_blanks
)
4520 int omit_first_word
;
4523 if (!omit_first_word
)
4525 do_spec_1 ("-", 0, NULL_PTR
);
4526 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4529 if (switches
[switchnum
].args
!= 0)
4532 for (p
= switches
[switchnum
].args
; *p
; p
++)
4535 do_spec_1 (" ", 0, NULL_PTR
);
4536 do_spec_1 (*p
, 1, NULL_PTR
);
4540 do_spec_1 (" ", 0, NULL_PTR
);
4541 switches
[switchnum
].validated
= 1;
4544 /* Search for a file named NAME trying various prefixes including the
4545 user's -B prefix and some standard ones.
4546 Return the absolute file name found. If nothing is found, return NAME. */
4554 /* Try multilib_dir if it is defined. */
4555 if (multilib_dir
!= NULL
)
4559 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4560 strcpy (try, multilib_dir
);
4561 strcat (try, dir_separator_str
);
4564 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4566 /* If we don't find it in the multi library dir, then fall
4567 through and look for it in the normal places. */
4568 if (newname
!= NULL
)
4572 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4573 return newname
? newname
: name
;
4576 /* Determine whether a directory exists. If LINKER, return 0 for
4577 certain fixed names not needed by the linker. If not LINKER, it is
4578 only important to return 0 if the host machine has a small ARG_MAX
4582 is_directory (path1
, path2
, linker
)
4587 int len1
= strlen (path1
);
4588 int len2
= strlen (path2
);
4589 char *path
= (char *) alloca (3 + len1
+ len2
);
4593 #ifndef SMALL_ARG_MAX
4598 /* Construct the path from the two parts. Ensure the string ends with "/.".
4599 The resulting path will be a directory even if the given path is a
4601 memcpy (path
, path1
, len1
);
4602 memcpy (path
+ len1
, path2
, len2
);
4603 cp
= path
+ len1
+ len2
;
4604 if (!IS_DIR_SEPARATOR (cp
[-1]))
4605 *cp
++ = DIR_SEPARATOR
;
4609 /* Exclude directories that the linker is known to search. */
4612 && strcmp (path
, concat (dir_separator_str
, "lib",
4613 dir_separator_str
, ".", NULL_PTR
)) == 0)
4615 && strcmp (path
, concat (dir_separator_str
, "usr",
4616 dir_separator_str
, "lib",
4617 dir_separator_str
, ".", NULL_PTR
)) == 0)))
4620 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4623 /* On fatal signals, delete all the temporary files. */
4626 fatal_error (signum
)
4629 signal (signum
, SIG_DFL
);
4630 delete_failure_queue ();
4631 delete_temp_files ();
4632 /* Get the same signal again, this time not handled,
4633 so its normal effect occurs. */
4634 kill (getpid (), signum
);
4645 int linker_was_run
= 0;
4646 char *explicit_link_files
;
4649 struct user_specs
*uptr
;
4651 p
= argv
[0] + strlen (argv
[0]);
4652 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
4656 #ifdef HAVE_LC_MESSAGES
4657 setlocale (LC_MESSAGES
, "");
4659 (void) bindtextdomain (PACKAGE
, localedir
);
4660 (void) textdomain (PACKAGE
);
4662 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4663 signal (SIGINT
, fatal_error
);
4665 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4666 signal (SIGHUP
, fatal_error
);
4668 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4669 signal (SIGTERM
, fatal_error
);
4671 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4672 signal (SIGPIPE
, fatal_error
);
4676 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4678 obstack_init (&obstack
);
4680 /* Build multilib_select, et. al from the separate lines that make up each
4681 multilib selection. */
4683 char **q
= multilib_raw
;
4686 obstack_init (&multilib_obstack
);
4687 while ((p
= *q
++) != (char *) 0)
4688 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4690 obstack_1grow (&multilib_obstack
, 0);
4691 multilib_select
= obstack_finish (&multilib_obstack
);
4693 q
= multilib_matches_raw
;
4694 while ((p
= *q
++) != (char *) 0)
4695 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4697 obstack_1grow (&multilib_obstack
, 0);
4698 multilib_matches
= obstack_finish (&multilib_obstack
);
4702 i
< sizeof (multilib_defaults_raw
) / sizeof (multilib_defaults_raw
[0]);
4706 obstack_1grow (&multilib_obstack
, ' ');
4707 obstack_grow (&multilib_obstack
,
4708 multilib_defaults_raw
[i
],
4709 strlen (multilib_defaults_raw
[i
]));
4713 obstack_1grow (&multilib_obstack
, 0);
4714 multilib_defaults
= obstack_finish (&multilib_obstack
);
4717 /* Set up to remember the pathname of gcc and any options
4718 needed for collect. We use argv[0] instead of programname because
4719 we need the complete pathname. */
4720 obstack_init (&collect_obstack
);
4721 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4722 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4723 putenv (obstack_finish (&collect_obstack
));
4725 #ifdef INIT_ENVIRONMENT
4726 /* Set up any other necessary machine specific environment variables. */
4727 putenv (INIT_ENVIRONMENT
);
4730 /* Choose directory for temp files. */
4732 #ifndef MKTEMP_EACH_FILE
4733 temp_filename
= choose_temp_base ();
4734 temp_filename_length
= strlen (temp_filename
);
4737 /* Make a table of what switches there are (switches, n_switches).
4738 Make a table of specified input files (infiles, n_infiles).
4739 Decode switches that are handled locally. */
4741 process_command (argc
, argv
);
4746 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4748 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4749 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4752 for (i
= 0; (int)i
< n_switches
; i
++)
4757 obstack_grow (&collect_obstack
, " ", 1);
4760 obstack_grow (&collect_obstack
, "'-", 2);
4761 q
= switches
[i
].part1
;
4762 while ((p
= index (q
,'\'')))
4764 obstack_grow (&collect_obstack
, q
, p
-q
);
4765 obstack_grow (&collect_obstack
, "'\\''", 4);
4768 obstack_grow (&collect_obstack
, q
, strlen (q
));
4769 obstack_grow (&collect_obstack
, "'", 1);
4771 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4773 obstack_grow (&collect_obstack
, " '", 2);
4775 while ((p
= index (q
,'\'')))
4777 obstack_grow (&collect_obstack
, q
, p
-q
);
4778 obstack_grow (&collect_obstack
, "'\\''", 4);
4781 obstack_grow (&collect_obstack
, q
, strlen (q
));
4782 obstack_grow (&collect_obstack
, "'", 1);
4785 obstack_grow (&collect_obstack
, "\0", 1);
4786 putenv (obstack_finish (&collect_obstack
));
4789 /* Initialize the vector of specs to just the default.
4790 This means one element containing 0s, as a terminator. */
4792 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4793 bcopy ((char *) default_compilers
, (char *) compilers
,
4794 sizeof default_compilers
);
4795 n_compilers
= n_default_compilers
;
4797 /* Read specs from a file if there is one. */
4799 machine_suffix
= concat (spec_machine
, dir_separator_str
,
4800 spec_version
, dir_separator_str
, NULL_PTR
);
4801 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL_PTR
);
4803 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4804 /* Read the specs file unless it is a default one. */
4805 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4806 read_specs (specs_file
, TRUE
);
4810 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4811 for any override of as, ld and libraries. */
4812 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
4813 + strlen (just_machine_suffix
)
4814 + sizeof ("specs"));
4816 strcpy (specs_file
, standard_exec_prefix
);
4817 strcat (specs_file
, just_machine_suffix
);
4818 strcat (specs_file
, "specs");
4819 if (access (specs_file
, R_OK
) == 0)
4820 read_specs (specs_file
, TRUE
);
4822 /* Process any user specified specs in the order given on the command
4824 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
4826 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
, R_OK
);
4827 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
4830 /* If not cross-compiling, look for startfiles in the standard places. */
4831 /* The fact that these are done here, after reading the specs file,
4832 means that it cannot be found in these directories.
4833 But that's okay. It should never be there anyway. */
4834 if (*cross_compile
== '0')
4836 #ifdef MD_EXEC_PREFIX
4837 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4838 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4841 #ifdef MD_STARTFILE_PREFIX
4842 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
4846 #ifdef MD_STARTFILE_PREFIX_1
4847 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
4851 /* If standard_startfile_prefix is relative, base it on
4852 standard_exec_prefix. This lets us move the installed tree
4853 as a unit. If GCC_EXEC_PREFIX is defined, base
4854 standard_startfile_prefix on that as well. */
4855 if (IS_DIR_SEPARATOR (*standard_startfile_prefix
)
4856 || *standard_startfile_prefix
== '$'
4857 #ifdef HAVE_DOS_BASED_FILESYSTEM
4858 /* Check for disk name on MS-DOS-based systems. */
4859 || (standard_startfile_prefix
[1] == ':'
4860 && (IS_DIR_SEPARATOR (standard_startfile_prefix
[2])))
4863 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
4867 if (gcc_exec_prefix
)
4868 add_prefix (&startfile_prefixes
,
4869 concat (gcc_exec_prefix
, machine_suffix
,
4870 standard_startfile_prefix
, NULL_PTR
),
4871 NULL_PTR
, 0, 0, NULL_PTR
);
4872 add_prefix (&startfile_prefixes
,
4873 concat (standard_exec_prefix
,
4875 standard_startfile_prefix
, NULL_PTR
),
4876 NULL_PTR
, 0, 0, NULL_PTR
);
4879 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
4880 "BINUTILS", 0, 0, NULL_PTR
);
4881 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
4882 "BINUTILS", 0, 0, NULL_PTR
);
4883 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4884 add_prefix (&startfile_prefixes
, "./", NULL_PTR
, 0, 1, NULL_PTR
);
4889 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix
) && gcc_exec_prefix
)
4890 add_prefix (&startfile_prefixes
,
4891 concat (gcc_exec_prefix
, machine_suffix
,
4892 standard_startfile_prefix
, NULL_PTR
),
4893 "BINUTILS", 0, 0, NULL_PTR
);
4896 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4897 if (gcc_exec_prefix
)
4899 char * temp
= (char *) xmalloc (strlen (gcc_exec_prefix
)
4900 + strlen (spec_version
)
4901 + strlen (spec_machine
) + 3);
4902 strcpy (temp
, gcc_exec_prefix
);
4903 strcat (temp
, spec_machine
);
4904 strcat (temp
, dir_separator_str
);
4905 strcat (temp
, spec_version
);
4906 strcat (temp
, dir_separator_str
);
4907 gcc_exec_prefix
= temp
;
4910 /* Now we have the specs.
4911 Set the `valid' bits for switches that match anything in any spec. */
4913 validate_all_switches ();
4915 /* Now that we have the switches and the specs, set
4916 the subdirectory based on the options. */
4917 set_multilib_dir ();
4919 /* Warn about any switches that no pass was interested in. */
4921 for (i
= 0; (int)i
< n_switches
; i
++)
4922 if (! switches
[i
].validated
)
4923 error ("unrecognized option `-%s'", switches
[i
].part1
);
4925 /* Obey some of the options. */
4927 if (print_search_dirs
)
4929 printf ("install: %s%s\n", standard_exec_prefix
, machine_suffix
);
4930 printf ("programs: %s\n", build_search_list (&exec_prefixes
, "", 0));
4931 printf ("libraries: %s\n", build_search_list (&startfile_prefixes
, "", 0));
4935 if (print_file_name
)
4937 printf ("%s\n", find_file (print_file_name
));
4941 if (print_prog_name
)
4943 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4944 printf ("%s\n", (newname
? newname
: print_prog_name
));
4948 if (print_multi_lib
)
4950 print_multilib_info ();
4954 if (print_multi_directory
)
4956 if (multilib_dir
== NULL
)
4959 printf ("%s\n", multilib_dir
);
4963 if (print_help_list
)
4969 printf ("\nReport bugs to egcs-bugs@egcs.cygnus.com.\n");
4970 printf ("Please see the file BUGS (included with the sources) first.\n");
4975 /* We do not exit here. Instead we have created a fake input file
4976 called 'help-dummy' which needs to be compiled, and we pass this
4977 on the the various sub-processes, along with the --help switch. */
4984 /* compiler_version is truncated at the first space when initialized
4985 from version string, so truncate version_string at the first space
4986 before comparing. */
4987 for (n
= 0; version_string
[n
]; n
++)
4988 if (version_string
[n
] == ' ')
4991 if (! strncmp (version_string
, compiler_version
, n
)
4992 && compiler_version
[n
] == 0)
4993 notice ("gcc version %s\n", version_string
);
4995 notice ("gcc driver version %s executing gcc version %s\n",
4996 version_string
, compiler_version
);
5002 if (n_infiles
== added_libraries
)
5003 fatal ("No input files");
5005 /* Make a place to record the compiler output file names
5006 that correspond to the input files. */
5009 i
+= lang_specific_extra_outfiles
;
5010 outfiles
= (const char **) xmalloc (i
* sizeof (char *));
5011 bzero ((char *) outfiles
, i
* sizeof (char *));
5013 /* Record which files were specified explicitly as link input. */
5015 explicit_link_files
= xmalloc (n_infiles
);
5016 bzero (explicit_link_files
, n_infiles
);
5018 for (i
= 0; (int)i
< n_infiles
; i
++)
5020 register struct compiler
*cp
= 0;
5021 int this_file_error
= 0;
5023 /* Tell do_spec what to substitute for %i. */
5025 input_filename
= infiles
[i
].name
;
5026 input_filename_length
= strlen (input_filename
);
5027 input_file_number
= i
;
5029 /* Use the same thing in %o, unless cp->spec says otherwise. */
5031 outfiles
[i
] = input_filename
;
5033 /* Figure out which compiler from the file's suffix. */
5035 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
5036 infiles
[i
].language
);
5040 /* Ok, we found an applicable compiler. Run its spec. */
5041 /* First say how much of input_filename to substitute for %b */
5042 register const char *p
;
5045 if (cp
->spec
[0][0] == '#')
5046 error ("%s: %s compiler not installed on this system",
5047 input_filename
, &cp
->spec
[0][1]);
5049 input_basename
= input_filename
;
5050 for (p
= input_filename
; *p
; p
++)
5051 if (IS_DIR_SEPARATOR (*p
))
5052 input_basename
= p
+ 1;
5054 /* Find a suffix starting with the last period,
5055 and set basename_length to exclude that suffix. */
5056 basename_length
= strlen (input_basename
);
5057 p
= input_basename
+ basename_length
;
5058 while (p
!= input_basename
&& *p
!= '.') --p
;
5059 if (*p
== '.' && p
!= input_basename
)
5061 basename_length
= p
- input_basename
;
5062 input_suffix
= p
+ 1;
5068 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
5070 len
+= strlen (cp
->spec
[j
]);
5073 char *p1
= (char *) xmalloc (len
+ 1);
5076 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
5079 strcpy (p1
+ len
, cp
->spec
[j
]);
5080 len
+= strlen (cp
->spec
[j
]);
5083 value
= do_spec (p1
);
5087 this_file_error
= 1;
5090 /* If this file's name does not contain a recognized suffix,
5091 record it as explicit linker input. */
5094 explicit_link_files
[i
] = 1;
5096 /* Clear the delete-on-failure queue, deleting the files in it
5097 if this compilation failed. */
5099 if (this_file_error
)
5101 delete_failure_queue ();
5104 /* If this compilation succeeded, don't delete those files later. */
5105 clear_failure_queue ();
5108 if (error_count
== 0)
5110 /* Make sure INPUT_FILE_NUMBER points to first available open
5112 input_file_number
= n_infiles
;
5113 if (lang_specific_pre_link ())
5117 /* Run ld to link all the compiler output files. */
5119 if (error_count
== 0)
5121 int tmp
= execution_count
;
5123 /* We'll use ld if we can't find collect2. */
5124 if (! strcmp (linker_name_spec
, "collect2"))
5126 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
);
5128 linker_name_spec
= "ld";
5130 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5132 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
5133 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
5135 value
= do_spec (link_command_spec
);
5138 linker_was_run
= (tmp
!= execution_count
);
5141 /* Warn if a -B option was specified but the prefix was never used. */
5142 unused_prefix_warnings (&exec_prefixes
);
5143 unused_prefix_warnings (&startfile_prefixes
);
5145 /* If options said don't run linker,
5146 complain about input files to be given to the linker. */
5148 if (! linker_was_run
&& error_count
== 0)
5149 for (i
= 0; (int)i
< n_infiles
; i
++)
5150 if (explicit_link_files
[i
])
5151 error ("%s: linker input file unused since linking not done",
5154 /* Delete some or all of the temporary files we made. */
5157 delete_failure_queue ();
5158 delete_temp_files ();
5160 if (print_help_list
)
5162 printf ("\nReport bugs to egcs-bugs@egcs.cygnus.com.\n");
5163 printf ("Please see the file BUGS (included with the sources) first.\n");
5166 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
5171 /* Find the proper compilation spec for the file name NAME,
5172 whose length is LENGTH. LANGUAGE is the specified language,
5173 or 0 if this file is to be passed to the linker. */
5175 static struct compiler
*
5176 lookup_compiler (name
, length
, language
)
5179 const char *language
;
5181 struct compiler
*cp
;
5183 /* If this was specified by the user to be a linker input, indicate that. */
5184 if (language
!= 0 && language
[0] == '*')
5187 /* Otherwise, look for the language, if one is spec'd. */
5190 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
5191 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
5194 error ("language %s not recognized", language
);
5198 /* Look for a suffix. */
5199 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
5201 if (/* The suffix `-' matches only the file name `-'. */
5202 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
5203 || (strlen (cp
->suffix
) < length
5204 /* See if the suffix matches the end of NAME. */
5206 && ((!strcmp (cp
->suffix
,
5207 name
+ length
- strlen (cp
->suffix
))
5208 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5209 && !strcasecmp (cp
->suffix
,
5210 name
+ length
- strlen (cp
->suffix
)))
5212 && !strcmp (cp
->suffix
,
5213 name
+ length
- strlen (cp
->suffix
))
5217 if (cp
->spec
[0][0] == '@')
5219 struct compiler
*new;
5221 /* An alias entry maps a suffix to a language.
5222 Search for the language; pass 0 for NAME and LENGTH
5223 to avoid infinite recursion if language not found.
5224 Construct the new compiler spec. */
5225 language
= cp
->spec
[0] + 1;
5226 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
5227 new->suffix
= cp
->suffix
;
5228 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
5229 (char *) new->spec
, sizeof new->spec
);
5233 /* A non-alias entry: return it. */
5245 register PTR value
= (PTR
) malloc (size
);
5247 fatal ("virtual memory exhausted");
5252 xrealloc (old
, size
)
5258 ptr
= (PTR
) realloc (old
, size
);
5260 ptr
= (PTR
) malloc (size
);
5262 fatal ("virtual memory exhausted");
5267 save_string (s
, len
)
5271 register char *result
= xmalloc (len
+ 1);
5273 bcopy (s
, result
, len
);
5279 pfatal_with_name (name
)
5282 perror_with_name (name
);
5283 delete_temp_files ();
5288 perror_with_name (name
)
5291 error ("%s: %s", name
, xstrerror (errno
));
5295 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
5296 const char *errmsg_fmt
;
5297 const char *errmsg_arg
;
5301 int save_errno
= errno
;
5303 /* Space for trailing '\0' is in %s. */
5304 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
5305 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
5311 pfatal_with_name (errmsg_fmt
);
5314 /* More 'friendly' abort that prints the line and file.
5315 config.h can #define abort fancy_abort if you like that sort of thing. */
5320 fatal ("Internal gcc abort.");
5323 /* Output an error message and exit */
5326 fatal
VPROTO((const char *msgid
, ...))
5328 #ifndef ANSI_PROTOTYPES
5333 VA_START (ap
, msgid
);
5335 #ifndef ANSI_PROTOTYPES
5336 msgid
= va_arg (ap
, const char *);
5339 fprintf (stderr
, "%s: ", programname
);
5340 vfprintf (stderr
, _(msgid
), ap
);
5342 fprintf (stderr
, "\n");
5343 delete_temp_files ();
5348 error
VPROTO((const char *msgid
, ...))
5350 #ifndef ANSI_PROTOTYPES
5355 VA_START (ap
, msgid
);
5357 #ifndef ANSI_PROTOTYPES
5358 msgid
= va_arg (ap
, const char *);
5361 fprintf (stderr
, "%s: ", programname
);
5362 vfprintf (stderr
, _(msgid
), ap
);
5365 fprintf (stderr
, "\n");
5369 notice
VPROTO((const char *msgid
, ...))
5371 #ifndef ANSI_PROTOTYPES
5376 VA_START (ap
, msgid
);
5378 #ifndef ANSI_PROTOTYPES
5379 msgid
= va_arg (ap
, const char *);
5382 vfprintf (stderr
, _(msgid
), ap
);
5388 validate_all_switches ()
5390 struct compiler
*comp
;
5391 register const char *p
;
5393 struct spec_list
*spec
;
5395 for (comp
= compilers
; comp
->spec
[0]; comp
++)
5398 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
5402 if (c
== '%' && *p
== '{')
5403 /* We have a switch spec. */
5404 validate_switches (p
+ 1);
5408 /* look through the linked list of specs read from the specs file */
5409 for (spec
= specs
; spec
; spec
= spec
->next
)
5411 p
= *(spec
->ptr_spec
);
5413 if (c
== '%' && *p
== '{')
5414 /* We have a switch spec. */
5415 validate_switches (p
+ 1);
5418 p
= link_command_spec
;
5420 if (c
== '%' && *p
== '{')
5421 /* We have a switch spec. */
5422 validate_switches (p
+ 1);
5425 /* Look at the switch-name that comes after START
5426 and mark as valid all supplied switches that match it. */
5429 validate_switches (start
)
5432 register const char *p
= start
;
5447 while (*p
!= ':' && *p
!= '}') p
++;
5451 else if (p
[-1] == '*')
5453 /* Mark all matching switches as valid. */
5455 for (i
= 0; i
< n_switches
; i
++)
5456 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
5457 switches
[i
].validated
= 1;
5461 /* Mark an exact matching switch as valid. */
5462 for (i
= 0; i
< n_switches
; i
++)
5464 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5465 && switches
[i
].part1
[p
- filter
] == 0)
5466 switches
[i
].validated
= 1;
5471 /* Check whether a particular argument was used. The first time we
5472 canonicalize the switches to keep only the ones we care about. */
5486 static struct mswitchstr
*mswitches
;
5487 static int n_mswitches
;
5492 struct mswitchstr
*matches
;
5496 /* Break multilib_matches into the component strings of string and replacement
5498 for (q
= multilib_matches
; *q
!= '\0'; q
++)
5502 matches
= (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
5504 q
= multilib_matches
;
5515 matches
[i
].len
= q
- matches
[i
].str
;
5517 matches
[i
].replace
= ++q
;
5518 while (*q
!= ';' && *q
!= '\0')
5524 matches
[i
].rep_len
= q
- matches
[i
].replace
;
5532 /* Now build a list of the replacement string for switches that we care
5533 about. Make sure we allocate at least one entry. This prevents
5534 xmalloc from calling fatal, and prevents us from re-executing this
5537 = (struct mswitchstr
*) xmalloc ((sizeof (struct mswitchstr
))
5538 * (n_switches
? n_switches
: 1));
5539 for (i
= 0; i
< n_switches
; i
++)
5541 int xlen
= strlen (switches
[i
].part1
);
5542 for (j
= 0; j
< cnt
; j
++)
5543 if (xlen
== matches
[j
].len
&& ! strcmp (switches
[i
].part1
, matches
[j
].str
))
5545 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
5546 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
5547 mswitches
[n_mswitches
].replace
= (char *)0;
5548 mswitches
[n_mswitches
].rep_len
= 0;
5555 for (i
= 0; i
< n_mswitches
; i
++)
5556 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
5563 default_arg (p
, len
)
5569 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+1)
5571 while (*start
== ' ' || *start
== '\t')
5577 for (end
= start
+1; *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
5580 if ((end
- start
) == len
&& strncmp (p
, start
, len
) == 0)
5590 /* Work out the subdirectory to use based on the
5591 options. The format of multilib_select is a list of elements.
5592 Each element is a subdirectory name followed by a list of options
5593 followed by a semicolon. gcc will consider each line in turn. If
5594 none of the options beginning with an exclamation point are
5595 present, and all of the other options are present, that
5596 subdirectory will be used. */
5601 char *p
= multilib_select
;
5603 char *this_path
, *this_arg
;
5609 /* Ignore newlines. */
5616 /* Get the initial path. */
5624 this_path_len
= p
- this_path
;
5626 /* Check the arguments. */
5641 while (*p
!= ' ' && *p
!= ';')
5648 if (*this_arg
!= '!')
5656 /* If this is a default argument, we can just ignore it.
5657 This is true even if this_arg begins with '!'. Beginning
5658 with '!' does not mean that this argument is necessarily
5659 inappropriate for this library: it merely means that
5660 there is a more specific library which uses this
5661 argument. If this argument is a default, we need not
5662 consider that more specific library. */
5663 if (! default_arg (this_arg
, p
- this_arg
))
5665 ok
= used_arg (this_arg
, p
- this_arg
);
5676 if (this_path_len
!= 1
5677 || this_path
[0] != '.')
5679 char * new_multilib_dir
= xmalloc (this_path_len
+ 1);
5680 strncpy (new_multilib_dir
, this_path
, this_path_len
);
5681 new_multilib_dir
[this_path_len
] = '\0';
5682 multilib_dir
= new_multilib_dir
;
5691 /* Print out the multiple library subdirectory selection
5692 information. This prints out a series of lines. Each line looks
5693 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5694 required. Only the desired options are printed out, the negative
5695 matches. The options are print without a leading dash. There are
5696 no spaces to make it easy to use the information in the shell.
5697 Each subdirectory is printed only once. This assumes the ordering
5698 generated by the genmultilib script. */
5701 print_multilib_info ()
5703 char *p
= multilib_select
;
5704 char *last_path
= 0, *this_path
;
5706 int last_path_len
= 0;
5710 /* Ignore newlines. */
5717 /* Get the initial path. */
5726 /* If this is a duplicate, skip it. */
5727 skip
= (last_path
!= 0 && p
- this_path
== last_path_len
5728 && ! strncmp (last_path
, this_path
, last_path_len
));
5730 last_path
= this_path
;
5731 last_path_len
= p
- this_path
;
5733 /* If this directory requires any default arguments, we can skip
5734 it. We will already have printed a directory identical to
5735 this one which does not require that default argument. */
5753 while (*q
!= ' ' && *q
!= ';')
5761 && default_arg (arg
, q
- arg
))
5776 for (p1
= last_path
; p1
< p
; p1
++)
5795 use_arg
= *p
!= '!';
5800 while (*p
!= ' ' && *p
!= ';')
5815 /* If there are extra options, print them now */
5816 if (multilib_extra
&& *multilib_extra
)
5818 int print_at
= TRUE
;
5821 for (q
= multilib_extra
; *q
!= '\0'; q
++)