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 int access_check
PROTO((const char *, int));
181 static char *find_a_file
PROTO((struct path_prefix
*, const char *, int));
182 static void add_prefix
PROTO((struct path_prefix
*, const char *,
183 const char *, int, int, int *));
184 static char *skip_whitespace
PROTO((char *));
185 static void record_temp_file
PROTO((const char *, int, int));
186 static void delete_if_ordinary
PROTO((const char *));
187 static void delete_temp_files
PROTO((void));
188 static void delete_failure_queue
PROTO((void));
189 static void clear_failure_queue
PROTO((void));
190 static int check_live_switch
PROTO((int, int));
191 static const char *handle_braces
PROTO((const char *));
192 static char *save_string
PROTO((const char *, int));
193 extern int do_spec
PROTO((const char *));
194 static int do_spec_1
PROTO((const char *, int, const char *));
195 static const char *find_file
PROTO((const char *));
196 static int is_directory
PROTO((const char *, const char *, int));
197 static void validate_switches
PROTO((const char *));
198 static void validate_all_switches
PROTO((void));
199 static void give_switch
PROTO((int, int, int));
200 static int used_arg
PROTO((const char *, int));
201 static int default_arg
PROTO((const char *, int));
202 static void set_multilib_dir
PROTO((void));
203 static void print_multilib_info
PROTO((void));
204 static void pfatal_with_name
PROTO((const char *)) ATTRIBUTE_NORETURN
;
205 static void perror_with_name
PROTO((const char *));
206 static void pfatal_pexecute
PROTO((const char *, const char *))
208 static void error
PVPROTO((const char *, ...))
210 static void notice
PVPROTO((const char *, ...))
212 static void display_help
PROTO((void));
213 static void add_preprocessor_option
PROTO ((const char *, int));
214 static void add_assembler_option
PROTO ((const char *, int));
215 static void add_linker_option
PROTO ((const char *, int));
216 static void process_command
PROTO ((int, char **));
217 static int execute
PROTO ((void));
218 static void unused_prefix_warnings
PROTO ((struct path_prefix
*));
219 static void clear_args
PROTO ((void));
220 static void fatal_error
PROTO ((int));
222 void fancy_abort
PROTO((void)) ATTRIBUTE_NORETURN
;
224 /* Called before processing to change/add/remove arguments. */
225 extern void lang_specific_driver
PROTO ((void (*) PVPROTO((const char *, ...)),
226 int *, char ***, int *));
228 /* Called before linking. Returns 0 on success and -1 on failure. */
229 extern int lang_specific_pre_link ();
231 /* Number of extra output files that lang_specific_pre_link may generate. */
232 extern int lang_specific_extra_outfiles
;
234 /* Specs are strings containing lines, each of which (if not blank)
235 is made up of a program name, and arguments separated by spaces.
236 The program name must be exact and start from root, since no path
237 is searched and it is unreliable to depend on the current working directory.
238 Redirection of input or output is not supported; the subprograms must
239 accept filenames saying what files to read and write.
241 In addition, the specs can contain %-sequences to substitute variable text
242 or for conditional text. Here is a table of all defined %-sequences.
243 Note that spaces are not generated automatically around the results of
244 expanding these sequences; therefore, you can concatenate them together
245 or with constant text in a single argument.
247 %% substitute one % into the program name or argument.
248 %i substitute the name of the input file being processed.
249 %b substitute the basename of the input file being processed.
250 This is the substring up to (and not including) the last period
251 and not including the directory.
253 substitute a file name that has suffix SUFFIX and is chosen
254 once per compilation, and mark the argument a la %d. To reduce
255 exposure to denial-of-service attacks, the file name is now
256 chosen in a way that is hard to predict even when previously
257 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
258 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
259 the regexp "[.A-Za-z]*" or the special string "%O", which is
260 treated exactly as if %O had been pre-processed. Previously, %g
261 was simply substituted with a file name chosen once per compilation,
262 without regard to any appended suffix (which was therefore treated
263 just like ordinary text), making such attacks more likely to succeed.
265 like %g, but generates a new temporary file name even if %uSUFFIX
268 substitutes the last file name generated with %uSUFFIX, generating a
269 new one if there is no such last file name. In the absence of any
270 %uSUFFIX, this is just like %gSUFFIX, except they don't share
271 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
272 would involve the generation of two distinct file names, one
273 for each `%g.s' and another for each `%U.s'. Previously, %U was
274 simply substituted with a file name chosen for the previous %u,
275 without regard to any appended suffix.
276 %d marks the argument containing or following the %d as a
277 temporary file name, so that that file will be deleted if CC exits
278 successfully. Unlike %g, this contributes no text to the argument.
279 %w marks the argument containing or following the %w as the
280 "output file" of this compilation. This puts the argument
281 into the sequence of arguments that %o will substitute later.
283 like %{...} but mark last argument supplied within
284 as a file to be deleted on failure.
285 %o substitutes the names of all the output files, with spaces
286 automatically placed around them. You should write spaces
287 around the %o as well or the results are undefined.
288 %o is for use in the specs for running the linker.
289 Input files whose names have no recognized suffix are not compiled
290 at all, but they are included among the output files, so they will
292 %O substitutes the suffix for object files. Note that this is
293 handled specially when it immediately follows %g, %u, or %U,
294 because of the need for those to form complete file names. The
295 handling is such that %O is treated exactly as if it had already
296 been substituted, except that %g, %u, and %U do not currently
297 support additional SUFFIX characters following %O as they would
298 following, for example, `.o'.
299 %p substitutes the standard macro predefinitions for the
300 current target machine. Use this when running cpp.
301 %P like %p, but puts `__' before and after the name of each macro.
302 (Except macros that already have __.)
304 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
305 %s current argument is the name of a library or startup file of some sort.
306 Search for that file in a standard list of directories
307 and substitute the full name found.
308 %eSTR Print STR as an error message. STR is terminated by a newline.
309 Use this when inconsistent options are detected.
310 %x{OPTION} Accumulate an option for %X.
311 %X Output the accumulated linker options specified by compilations.
312 %Y Output the accumulated assembler options specified by compilations.
313 %Z Output the accumulated preprocessor options specified by compilations.
314 %v1 Substitute the major version number of GCC.
315 (For version 2.5.n, this is 2.)
316 %v2 Substitute the minor version number of GCC.
317 (For version 2.5.n, this is 5.)
318 %a process ASM_SPEC as a spec.
319 This allows config.h to specify part of the spec for running as.
320 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
321 used here. This can be used to run a post-processor after the
322 assembler has done its job.
323 %D Dump out a -L option for each directory in startfile_prefixes.
324 If multilib_dir is set, extra entries are generated with it affixed.
325 %l process LINK_SPEC as a spec.
326 %L process LIB_SPEC as a spec.
327 %G process LIBGCC_SPEC as a spec.
328 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
329 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
330 %c process SIGNED_CHAR_SPEC as a spec.
331 %C process CPP_SPEC as a spec. A capital C is actually used here.
332 %1 process CC1_SPEC as a spec.
333 %2 process CC1PLUS_SPEC as a spec.
334 %| output "-" if the input for the current command is coming from a pipe.
335 %* substitute the variable part of a matched option. (See below.)
336 Note that each comma in the substituted string is replaced by
338 %{S} substitutes the -S switch, if that switch was given to CC.
339 If that switch was not specified, this substitutes nothing.
340 Here S is a metasyntactic variable.
341 %{S*} substitutes all the switches specified to CC whose names start
342 with -S. This is used for -o, -D, -I, etc; switches that take
343 arguments. CC considers `-o foo' as being one switch whose
344 name starts with `o'. %{o*} would substitute this text,
345 including the space; thus, two arguments would be generated.
346 %{^S*} likewise, but don't put a blank between a switch and any args.
347 %{S*:X} substitutes X if one or more switches whose names start with -S are
348 specified to CC. Note that the tail part of the -S option
349 (i.e. the part matched by the `*') will be substituted for each
350 occurrence of %* within X.
351 %{S:X} substitutes X, but only if the -S switch was given to CC.
352 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
353 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
354 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
355 %{.S:X} substitutes X, but only if processing a file with suffix S.
356 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
357 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
358 combined with ! and . as above binding stronger than the OR.
359 %(Spec) processes a specification defined in a specs file as *Spec:
360 %[Spec] as above, but put __ around -D arguments
362 The conditional text X in a %{S:X} or %{!S:X} construct may contain
363 other nested % constructs or spaces, or even newlines. They are
364 processed as usual, as described above.
366 The -O, -f, -m, and -W switches are handled specifically in these
367 constructs. If another value of -O or the negated form of a -f, -m, or
368 -W switch is found later in the command line, the earlier switch
369 value is ignored, except with {S*} where S is just one letter; this
370 passes all matching options.
372 The character | at the beginning of the predicate text is used to indicate
373 that a command should be piped to the following command, but only if -pipe
376 Note that it is built into CC which switches take arguments and which
377 do not. You might think it would be useful to generalize this to
378 allow each compiler's spec to say which switches take arguments. But
379 this cannot be done in a consistent fashion. CC cannot even decide
380 which input files have been specified without knowing which switches
381 take arguments, and it must know which input files to compile in order
382 to tell which compilers to run.
384 CC also knows implicitly that arguments starting in `-l' are to be
385 treated as compiler output files, and passed to the linker in their
386 proper position among the other output files. */
388 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
390 /* config.h can define ASM_SPEC to provide extra args to the assembler
391 or extra switch-translations. */
396 /* config.h can define ASM_FINAL_SPEC to run a post processor after
397 the assembler has run. */
398 #ifndef ASM_FINAL_SPEC
399 #define ASM_FINAL_SPEC ""
402 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
403 or extra switch-translations. */
408 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
409 or extra switch-translations. */
414 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
415 or extra switch-translations. */
417 #define CC1PLUS_SPEC ""
420 /* config.h can define LINK_SPEC to provide extra args to the linker
421 or extra switch-translations. */
426 /* config.h can define LIB_SPEC to override the default libraries. */
428 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
431 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
434 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
435 /* Have gcc do the search for libgcc.a. */
436 #define LIBGCC_SPEC "libgcc.a%s"
438 #define LIBGCC_SPEC "-lgcc"
442 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
443 #ifndef STARTFILE_SPEC
444 #define STARTFILE_SPEC \
445 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
448 /* config.h can define SWITCHES_NEED_SPACES to control which options
449 require spaces between the option and the argument. */
450 #ifndef SWITCHES_NEED_SPACES
451 #define SWITCHES_NEED_SPACES ""
454 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
456 #define ENDFILE_SPEC ""
459 /* This spec is used for telling cpp whether char is signed or not. */
460 #ifndef SIGNED_CHAR_SPEC
461 /* Use #if rather than ?:
462 because MIPS C compiler rejects like ?: in initializers. */
463 #if DEFAULT_SIGNED_CHAR
464 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
466 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
471 #define LINKER_NAME "collect2"
474 static char *cpp_spec
= CPP_SPEC
;
475 static char *cpp_predefines
= CPP_PREDEFINES
;
476 static char *cc1_spec
= CC1_SPEC
;
477 static char *cc1plus_spec
= CC1PLUS_SPEC
;
478 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
479 static char *asm_spec
= ASM_SPEC
;
480 static char *asm_final_spec
= ASM_FINAL_SPEC
;
481 static char *link_spec
= LINK_SPEC
;
482 static char *lib_spec
= LIB_SPEC
;
483 static char *libgcc_spec
= LIBGCC_SPEC
;
484 static char *endfile_spec
= ENDFILE_SPEC
;
485 static char *startfile_spec
= STARTFILE_SPEC
;
486 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
487 static char *linker_name_spec
= LINKER_NAME
;
489 /* Some compilers have limits on line lengths, and the multilib_select
490 and/or multilib_matches strings can be very long, so we build them at
492 static struct obstack multilib_obstack
;
493 static char *multilib_select
;
494 static char *multilib_matches
;
495 static char *multilib_defaults
;
496 #include "multilib.h"
498 /* Check whether a particular argument is a default argument. */
500 #ifndef MULTILIB_DEFAULTS
501 #define MULTILIB_DEFAULTS { "" }
504 static char *multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
507 struct user_specs
*next
;
508 const char *filename
;
511 static struct user_specs
*user_specs_head
, *user_specs_tail
;
513 /* This defines which switch letters take arguments. */
515 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
516 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
517 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
518 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
519 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
520 || (CHAR) == 'B' || (CHAR) == 'b')
522 #ifndef SWITCH_TAKES_ARG
523 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
526 /* This defines which multi-letter switches take arguments. */
528 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
529 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
530 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
531 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
532 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
533 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
534 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
536 #ifndef WORD_SWITCH_TAKES_ARG
537 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
541 #ifdef HAVE_EXECUTABLE_SUFFIX
542 /* This defines which switches stop a full compilation. */
543 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
544 ((CHAR) == 'c' || (CHAR) == 'S')
546 #ifndef SWITCH_CURTAILS_COMPILATION
547 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
548 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
552 /* Record the mapping from file suffixes for compilation specs. */
556 const char *suffix
; /* Use this compiler for input files
557 whose names end in this suffix. */
559 const char *spec
[4]; /* To use this compiler, concatenate these
560 specs and pass to do_spec. */
563 /* Pointer to a vector of `struct compiler' that gives the spec for
564 compiling a file, based on its suffix.
565 A file that does not end in any of these suffixes will be passed
566 unchanged to the loader and nothing else will be done to it.
568 An entry containing two 0s is used to terminate the vector.
570 If multiple entries match a file, the last matching one is used. */
572 static struct compiler
*compilers
;
574 /* Number of entries in `compilers', not counting the null terminator. */
576 static int n_compilers
;
578 /* The default list of file name suffixes and their compilation specs. */
580 static struct compiler default_compilers
[] =
582 /* Add lists of suffixes of known languages here. If those languages
583 were not present when we built the driver, we will hit these copies
584 and be given a more meaningful error than "file not used since
585 linking is not done". */
586 {".m", {"#Objective-C"}},
587 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}},
588 {".c++", {"#C++"}}, {".C", {"#C++"}},
589 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
590 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
591 {".fpp", {"#Fortran"}},
592 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
593 /* Next come the entries for C. */
598 "%{E|M|MM:cpp -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
599 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
600 %{C:%{!E:%eGNU C does not support -C without using -E}}\
601 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
602 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
603 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
604 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
605 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
606 %{ffast-math:-D__FAST_MATH__}\
607 %{traditional} %{ftraditional:-traditional}\
608 %{traditional-cpp:-traditional}\
609 %{fleading-underscore} %{fno-leading-underscore}\
610 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
611 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
612 %{!E:%{!M:%{!MM:cc1 %i %1 \
613 %{std*} %{nostdinc*} %{A*} %{I*} %I\
614 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
615 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
616 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
617 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
618 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
619 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
620 %{ffast-math:-D__FAST_MATH__}\
621 %{H} %C %{D*} %{U*} %{i*} %Z\
622 %{ftraditional:-traditional}\
623 %{traditional-cpp:-traditional}\
624 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
625 %{aux-info*} %{Qn:-fno-ident}\
627 %{g*} %{O*} %{W*} %{w} %{pedantic*}\
628 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
629 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
631 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
632 %{!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 %{!no-gcc:-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 }}}}"
659 #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 %{!no-gcc:-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 %{!no-gcc:-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} -fpreprocessed\
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 /* Check whether NAME can be accessed in MODE. This is like access,
1959 except that it never considers directories to be executable. */
1962 access_check (name
, mode
)
1970 if (stat (name
, &st
) < 0
1971 || S_ISDIR (st
.st_mode
))
1975 return access (name
, mode
);
1978 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1979 access to check permissions.
1980 Return 0 if not found, otherwise return its name, allocated with malloc. */
1983 find_a_file (pprefix
, name
, mode
)
1984 struct path_prefix
*pprefix
;
1989 const char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1990 struct prefix_list
*pl
;
1991 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1993 #ifdef DEFAULT_ASSEMBLER
1994 if (! strcmp(name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0) {
1995 name
= DEFAULT_ASSEMBLER
;
1996 len
= strlen(name
)+1;
1997 temp
= xmalloc (len
);
1998 strcpy (temp
, name
);
2003 #ifdef DEFAULT_LINKER
2004 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0) {
2005 name
= DEFAULT_LINKER
;
2006 len
= strlen(name
)+1;
2007 temp
= xmalloc (len
);
2008 strcpy (temp
, name
);
2014 len
+= strlen (machine_suffix
);
2016 temp
= xmalloc (len
);
2018 /* Determine the filename to execute (special case for absolute paths). */
2020 if (IS_DIR_SEPARATOR (*name
)
2021 #ifdef HAVE_DOS_BASED_FILESYSTEM
2022 /* Check for disk name on MS-DOS-based systems. */
2023 || (name
[0] && name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2027 if (access (name
, mode
) == 0)
2029 strcpy (temp
, name
);
2034 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
2038 /* Some systems have a suffix for executable files.
2039 So try appending that first. */
2040 if (file_suffix
[0] != 0)
2042 strcpy (temp
, pl
->prefix
);
2043 strcat (temp
, machine_suffix
);
2044 strcat (temp
, name
);
2045 strcat (temp
, file_suffix
);
2046 if (access_check (temp
, mode
) == 0)
2048 if (pl
->used_flag_ptr
!= 0)
2049 *pl
->used_flag_ptr
= 1;
2054 /* Now try just the name. */
2055 strcpy (temp
, pl
->prefix
);
2056 strcat (temp
, machine_suffix
);
2057 strcat (temp
, name
);
2058 if (access_check (temp
, mode
) == 0)
2060 if (pl
->used_flag_ptr
!= 0)
2061 *pl
->used_flag_ptr
= 1;
2066 /* Certain prefixes are tried with just the machine type,
2067 not the version. This is used for finding as, ld, etc. */
2068 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
2070 /* Some systems have a suffix for executable files.
2071 So try appending that first. */
2072 if (file_suffix
[0] != 0)
2074 strcpy (temp
, pl
->prefix
);
2075 strcat (temp
, just_machine_suffix
);
2076 strcat (temp
, name
);
2077 strcat (temp
, file_suffix
);
2078 if (access_check (temp
, mode
) == 0)
2080 if (pl
->used_flag_ptr
!= 0)
2081 *pl
->used_flag_ptr
= 1;
2086 strcpy (temp
, pl
->prefix
);
2087 strcat (temp
, just_machine_suffix
);
2088 strcat (temp
, name
);
2089 if (access_check (temp
, mode
) == 0)
2091 if (pl
->used_flag_ptr
!= 0)
2092 *pl
->used_flag_ptr
= 1;
2097 /* Certain prefixes can't be used without the machine suffix
2098 when the machine or version is explicitly specified. */
2099 if (! pl
->require_machine_suffix
)
2101 /* Some systems have a suffix for executable files.
2102 So try appending that first. */
2103 if (file_suffix
[0] != 0)
2105 strcpy (temp
, pl
->prefix
);
2106 strcat (temp
, name
);
2107 strcat (temp
, file_suffix
);
2108 if (access_check (temp
, mode
) == 0)
2110 if (pl
->used_flag_ptr
!= 0)
2111 *pl
->used_flag_ptr
= 1;
2116 strcpy (temp
, pl
->prefix
);
2117 strcat (temp
, name
);
2118 if (access_check (temp
, mode
) == 0)
2120 if (pl
->used_flag_ptr
!= 0)
2121 *pl
->used_flag_ptr
= 1;
2131 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2132 at the start of the list, otherwise it goes at the end.
2134 If WARN is nonzero, we will warn if no file is found
2135 through this prefix. WARN should point to an int
2136 which will be set to 1 if this entry is used.
2138 COMPONENT is the value to be passed to update_path.
2140 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2141 the complete value of machine_suffix.
2142 2 means try both machine_suffix and just_machine_suffix. */
2145 add_prefix (pprefix
, prefix
, component
, first
, require_machine_suffix
, warn
)
2146 struct path_prefix
*pprefix
;
2148 const char *component
;
2150 int require_machine_suffix
;
2153 struct prefix_list
*pl
, **prev
;
2156 if (! first
&& pprefix
->plist
)
2158 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
2163 prev
= &pprefix
->plist
;
2165 /* Keep track of the longest prefix */
2167 prefix
= update_path (prefix
, component
);
2168 len
= strlen (prefix
);
2169 if (len
> pprefix
->max_len
)
2170 pprefix
->max_len
= len
;
2172 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2173 pl
->prefix
= save_string (prefix
, len
);
2174 pl
->require_machine_suffix
= require_machine_suffix
;
2175 pl
->used_flag_ptr
= warn
;
2182 pl
->next
= (struct prefix_list
*) 0;
2186 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2189 unused_prefix_warnings (pprefix
)
2190 struct path_prefix
*pprefix
;
2192 struct prefix_list
*pl
= pprefix
->plist
;
2196 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
2198 if (pl
->require_machine_suffix
&& machine_suffix
)
2199 error ("file path prefix `%s%s' never used", pl
->prefix
,
2202 error ("file path prefix `%s' never used", pl
->prefix
);
2204 /* Prevent duplicate warnings. */
2205 *pl
->used_flag_ptr
= 1;
2213 /* Execute the command specified by the arguments on the current line of spec.
2214 When using pipes, this includes several piped-together commands
2215 with `|' between them.
2217 Return 0 if successful, -1 if failed. */
2223 int n_commands
; /* # of command. */
2227 const char *prog
; /* program name. */
2228 char **argv
; /* vector of args. */
2229 int pid
; /* pid of process for this command. */
2232 struct command
*commands
; /* each command buffer with above info. */
2234 /* Count # of piped commands. */
2235 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2236 if (strcmp (argbuf
[i
], "|") == 0)
2239 /* Get storage for each command. */
2241 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2243 /* Split argbuf into its separate piped processes,
2244 and record info about each one.
2245 Also search for the programs that are to be run. */
2247 commands
[0].prog
= argbuf
[0]; /* first command. */
2248 commands
[0].argv
= &argbuf
[0];
2249 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2252 commands
[0].argv
[0] = string
;
2254 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2255 if (strcmp (argbuf
[i
], "|") == 0)
2256 { /* each command. */
2257 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2258 fatal ("-pipe not supported");
2260 argbuf
[i
] = 0; /* termination of command args. */
2261 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2262 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2263 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2265 commands
[n_commands
].argv
[0] = string
;
2269 argbuf
[argbuf_index
] = 0;
2271 /* If -v, print what we are about to do, and maybe query. */
2275 /* For help listings, put a blank line between sub-processes. */
2276 if (print_help_list
)
2277 fputc ('\n', stderr
);
2279 /* Print each piped command as a separate line. */
2280 for (i
= 0; i
< n_commands
; i
++)
2284 for (j
= commands
[i
].argv
; *j
; j
++)
2285 fprintf (stderr
, " %s", *j
);
2287 /* Print a pipe symbol after all but the last command. */
2288 if (i
+ 1 != n_commands
)
2289 fprintf (stderr
, " |");
2290 fprintf (stderr
, "\n");
2294 notice ("\nGo ahead? (y or n) ");
2298 while (getchar () != '\n')
2301 if (i
!= 'y' && i
!= 'Y')
2306 /* Run each piped subprocess. */
2308 for (i
= 0; i
< n_commands
; i
++)
2310 char *errmsg_fmt
, *errmsg_arg
;
2311 char *string
= commands
[i
].argv
[0];
2313 commands
[i
].pid
= pexecute (string
, commands
[i
].argv
,
2314 programname
, temp_filename
,
2315 &errmsg_fmt
, &errmsg_arg
,
2316 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2317 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2318 | (string
== commands
[i
].prog
2319 ? PEXECUTE_SEARCH
: 0)
2320 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2322 if (commands
[i
].pid
== -1)
2323 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2325 if (string
!= commands
[i
].prog
)
2331 /* Wait for all the subprocesses to finish.
2332 We don't care what order they finish in;
2333 we know that N_COMMANDS waits will get them all.
2334 Ignore subprocesses that we don't know about,
2335 since they can be spawned by the process that exec'ed us. */
2340 for (i
= 0; i
< n_commands
; )
2346 pid
= pwait (commands
[i
].pid
, &status
, 0);
2350 for (j
= 0; j
< n_commands
; j
++)
2351 if (commands
[j
].pid
== pid
)
2356 if (WIFSIGNALED (status
))
2358 fatal ("Internal compiler error: program %s got fatal signal %d",
2359 commands
[j
].prog
, WTERMSIG (status
));
2363 else if (WIFEXITED (status
)
2364 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2374 /* Find all the switches given to us
2375 and make a vector describing them.
2376 The elements of the vector are strings, one per switch given.
2377 If a switch uses following arguments, then the `part1' field
2378 is the switch itself and the `args' field
2379 is a null-terminated vector containing the following arguments.
2380 The `live_cond' field is 1 if the switch is true in a conditional spec,
2381 -1 if false (overridden by a later switch), and is initialized to zero.
2382 The `validated' field is nonzero if any spec has looked at this switch;
2383 if it remains zero at the end of the run, it must be meaningless. */
2393 static struct switchstr
*switches
;
2395 static int n_switches
;
2400 const char *language
;
2403 /* Also a vector of input files specified. */
2405 static struct infile
*infiles
;
2407 static int n_infiles
;
2409 /* This counts the number of libraries added by lang_specific_driver, so that
2410 we can tell if there were any user supplied any files or libraries. */
2412 static int added_libraries
;
2414 /* And a vector of corresponding output files is made up later. */
2416 static const char **outfiles
;
2418 /* Used to track if none of the -B paths are used. */
2421 /* Used to track if standard path isn't used and -b or -V is specified. */
2422 static int warn_std
;
2424 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2425 static int *warn_std_ptr
= 0;
2428 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2430 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2431 is true if we should look for an executable suffix as well. */
2434 convert_filename (name
, do_exe
)
2444 len
= strlen (name
);
2446 #ifdef HAVE_OBJECT_SUFFIX
2447 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2449 && name
[len
- 2] == '.'
2450 && name
[len
- 1] == 'o')
2452 obstack_grow (&obstack
, name
, len
- 2);
2453 obstack_grow0 (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
2454 name
= obstack_finish (&obstack
);
2458 #ifdef HAVE_EXECUTABLE_SUFFIX
2459 /* If there is no filetype, make it the executable suffix (which includes
2460 the "."). But don't get confused if we have just "-o". */
2461 if (! do_exe
|| EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
2464 for (i
= len
- 1; i
>= 0; i
--)
2465 if (IS_DIR_SEPARATOR (name
[i
]))
2468 for (i
++; i
< len
; i
++)
2472 obstack_grow (&obstack
, name
, len
);
2473 obstack_grow0 (&obstack
, EXECUTABLE_SUFFIX
, strlen (EXECUTABLE_SUFFIX
));
2474 name
= obstack_finish (&obstack
);
2481 /* Display the command line switches accepted by gcc. */
2485 printf ("Usage: %s [options] file...\n", programname
);
2486 printf ("Options:\n");
2488 printf (" --help Display this information\n");
2490 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2491 printf (" -dumpspecs Display all of the built in spec strings\n");
2492 printf (" -dumpversion Display the version of the compiler\n");
2493 printf (" -dumpmachine Display the compiler's target processor\n");
2494 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2495 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2496 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2497 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2498 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2499 printf (" -print-multi-lib Display the mapping between command line options and\n");
2500 printf (" multiple library search directories\n");
2501 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2502 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2503 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2504 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2505 printf (" -save-temps Do not delete intermediate files\n");
2506 printf (" -pipe Use pipes rather than intermediate files\n");
2507 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2508 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2509 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2510 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2511 printf (" -V <version> Run gcc version number <version>, if installed\n");
2512 printf (" -v Display the programs invoked by the compiler\n");
2513 printf (" -E Preprocess only; do not compile, assemble or link\n");
2514 printf (" -S Compile only; do not assemble or link\n");
2515 printf (" -c Compile and assemble, but do not link\n");
2516 printf (" -o <file> Place the output into <file>\n");
2517 printf (" -x <language> Specify the language of the following input files\n");
2518 printf (" Permissable languages include: c c++ assembler none\n");
2519 printf (" 'none' means revert to the default behaviour of\n");
2520 printf (" guessing the language based on the file's extension\n");
2522 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2523 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2525 printf ("on to these processes the -W<letter> options must be used.\n");
2527 /* The rest of the options are displayed by invocations of the various
2532 add_preprocessor_option (option
, len
)
2533 const char * option
;
2536 n_preprocessor_options
++;
2538 if (! preprocessor_options
)
2539 preprocessor_options
2540 = (char **) xmalloc (n_preprocessor_options
* sizeof (char *));
2542 preprocessor_options
2543 = (char **) xrealloc (preprocessor_options
,
2544 n_preprocessor_options
* sizeof (char *));
2546 preprocessor_options
[n_preprocessor_options
- 1] =
2547 save_string (option
, len
);
2551 add_assembler_option (option
, len
)
2552 const char * option
;
2555 n_assembler_options
++;
2557 if (! assembler_options
)
2559 = (char **) xmalloc (n_assembler_options
* sizeof (char *));
2562 = (char **) xrealloc (assembler_options
,
2563 n_assembler_options
* sizeof (char *));
2565 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
2569 add_linker_option (option
, len
)
2570 const char * option
;
2575 if (! linker_options
)
2577 = (char **) xmalloc (n_linker_options
* sizeof (char *));
2580 = (char **) xrealloc (linker_options
,
2581 n_linker_options
* sizeof (char *));
2583 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
2586 /* Create the vector `switches' and its contents.
2587 Store its length in `n_switches'. */
2590 process_command (argc
, argv
)
2597 char *spec_lang
= 0;
2598 int last_language_n_infiles
;
2601 int lang_n_infiles
= 0;
2603 GET_ENV_PATH_LIST (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
2607 added_libraries
= 0;
2609 /* Figure compiler version from version string. */
2611 compiler_version
= temp1
=
2612 save_string (version_string
, strlen (version_string
));
2613 for (; *temp1
; ++temp1
)
2622 /* Set up the default search paths. */
2624 if (gcc_exec_prefix
)
2626 int len
= strlen (gcc_exec_prefix
);
2627 if (len
> (int) sizeof ("/lib/gcc-lib/")-1
2628 && (IS_DIR_SEPARATOR (gcc_exec_prefix
[len
-1])))
2630 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc-lib/") + 1;
2631 if (IS_DIR_SEPARATOR (*temp
)
2632 && strncmp (temp
+1, "lib", 3) == 0
2633 && IS_DIR_SEPARATOR (temp
[4])
2634 && strncmp (temp
+5, "gcc-lib", 7) == 0)
2635 len
-= sizeof ("/lib/gcc-lib/") - 1;
2638 set_std_prefix (gcc_exec_prefix
, len
);
2639 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2640 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2643 /* COMPILER_PATH and LIBRARY_PATH have values
2644 that are lists of directory names with colons. */
2646 GET_ENV_PATH_LIST (temp
, "COMPILER_PATH");
2649 const char *startp
, *endp
;
2650 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2652 startp
= endp
= temp
;
2655 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2657 strncpy (nstore
, startp
, endp
-startp
);
2659 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2660 else if (!IS_DIR_SEPARATOR (endp
[-1]))
2662 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2663 nstore
[endp
-startp
+1] = 0;
2666 nstore
[endp
-startp
] = 0;
2667 add_prefix (&exec_prefixes
, nstore
, 0, 0, 0, NULL_PTR
);
2668 add_prefix (&include_prefixes
,
2669 concat (nstore
, "include", NULL_PTR
),
2673 endp
= startp
= endp
+ 1;
2680 GET_ENV_PATH_LIST (temp
, "LIBRARY_PATH");
2681 if (temp
&& *cross_compile
== '0')
2683 const char *startp
, *endp
;
2684 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2686 startp
= endp
= temp
;
2689 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2691 strncpy (nstore
, startp
, endp
-startp
);
2693 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2694 else if (!IS_DIR_SEPARATOR (endp
[-1]))
2696 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2697 nstore
[endp
-startp
+1] = 0;
2700 nstore
[endp
-startp
] = 0;
2701 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2705 endp
= startp
= endp
+ 1;
2712 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2713 GET_ENV_PATH_LIST (temp
, "LPATH");
2714 if (temp
&& *cross_compile
== '0')
2716 const char *startp
, *endp
;
2717 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2719 startp
= endp
= temp
;
2722 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2724 strncpy (nstore
, startp
, endp
-startp
);
2726 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2727 else if (!IS_DIR_SEPARATOR (endp
[-1]))
2729 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2730 nstore
[endp
-startp
+1] = 0;
2733 nstore
[endp
-startp
] = 0;
2734 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2738 endp
= startp
= endp
+ 1;
2745 /* Convert new-style -- options to old-style. */
2746 translate_options (&argc
, &argv
);
2748 /* Do language-specific adjustment/addition of flags. */
2749 lang_specific_driver (fatal
, &argc
, &argv
, &added_libraries
);
2751 /* Scan argv twice. Here, the first time, just count how many switches
2752 there will be in their vector, and how many input files in theirs.
2753 Here we also parse the switches that cc itself uses (e.g. -v). */
2755 for (i
= 1; i
< argc
; i
++)
2757 if (! strcmp (argv
[i
], "-dumpspecs"))
2759 struct spec_list
*sl
;
2761 for (sl
= specs
; sl
; sl
= sl
->next
)
2762 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
2763 if (link_command_spec
)
2764 printf ("*link_command:\n%s\n\n", link_command_spec
);
2767 else if (! strcmp (argv
[i
], "-dumpversion"))
2769 printf ("%s\n", spec_version
);
2772 else if (! strcmp (argv
[i
], "-dumpmachine"))
2774 printf ("%s\n", spec_machine
);
2777 else if (strcmp (argv
[i
], "-fhelp") == 0)
2779 /* translate_options () has turned --help into -fhelp. */
2780 print_help_list
= 1;
2782 /* We will be passing a dummy file on to the sub-processes. */
2786 add_preprocessor_option ("--help", 6);
2787 add_assembler_option ("--help", 6);
2788 add_linker_option ("--help", 6);
2790 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2791 print_search_dirs
= 1;
2792 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2793 print_file_name
= "libgcc.a";
2794 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2795 print_file_name
= argv
[i
] + 17;
2796 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2797 print_prog_name
= argv
[i
] + 17;
2798 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2799 print_multi_lib
= 1;
2800 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2801 print_multi_directory
= 1;
2802 else if (! strncmp (argv
[i
], "-Wa,", 4))
2805 /* Pass the rest of this option to the assembler. */
2807 /* Split the argument at commas. */
2809 for (j
= 4; argv
[i
][j
]; j
++)
2810 if (argv
[i
][j
] == ',')
2812 add_assembler_option (argv
[i
] + prev
, j
- prev
);
2816 /* Record the part after the last comma. */
2817 add_assembler_option (argv
[i
] + prev
, j
- prev
);
2819 else if (! strncmp (argv
[i
], "-Wp,", 4))
2822 /* Pass the rest of this option to the preprocessor. */
2824 /* Split the argument at commas. */
2826 for (j
= 4; argv
[i
][j
]; j
++)
2827 if (argv
[i
][j
] == ',')
2829 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
2833 /* Record the part after the last comma. */
2834 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
2836 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2837 /* The +e options to the C++ front-end. */
2839 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2842 /* Split the argument at commas. */
2843 for (j
= 3; argv
[i
][j
]; j
++)
2844 n_infiles
+= (argv
[i
][j
] == ',');
2846 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2849 fatal ("argument to `-Xlinker' is missing");
2854 else if (strncmp (argv
[i
], "-l", 2) == 0)
2856 else if (strcmp (argv
[i
], "-save-temps") == 0)
2858 save_temps_flag
= 1;
2861 else if (strcmp (argv
[i
], "-specs") == 0)
2863 struct user_specs
*user
= (struct user_specs
*)
2864 xmalloc (sizeof (struct user_specs
));
2866 fatal ("argument to `-specs' is missing");
2868 user
->next
= (struct user_specs
*)0;
2869 user
->filename
= argv
[i
];
2870 if (user_specs_tail
)
2871 user_specs_tail
->next
= user
;
2873 user_specs_head
= user
;
2874 user_specs_tail
= user
;
2876 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
2878 struct user_specs
*user
= (struct user_specs
*)
2879 xmalloc (sizeof (struct user_specs
));
2880 if (strlen (argv
[i
]) == 7)
2881 fatal ("argument to `-specs=' is missing");
2883 user
->next
= (struct user_specs
*)0;
2884 user
->filename
= argv
[i
]+7;
2885 if (user_specs_tail
)
2886 user_specs_tail
->next
= user
;
2888 user_specs_head
= user
;
2889 user_specs_tail
= user
;
2891 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2893 register char *p
= &argv
[i
][1];
2894 register int c
= *p
;
2900 if (p
[1] == 0 && i
+ 1 == argc
)
2901 fatal ("argument to `-b' is missing");
2903 spec_machine
= argv
[++i
];
2905 spec_machine
= p
+ 1;
2907 warn_std_ptr
= &warn_std
;
2913 if (p
[1] == 0 && i
+ 1 == argc
)
2914 fatal ("argument to `-B' is missing");
2919 add_prefix (&exec_prefixes
, value
, NULL_PTR
, 1, 0, &warn_B
);
2920 add_prefix (&startfile_prefixes
, value
, NULL_PTR
,
2922 add_prefix (&include_prefixes
, concat (value
, "include",
2924 NULL_PTR
, 1, 0, NULL_PTR
);
2926 /* As a kludge, if the arg is "[foo/]stageN/", just add
2927 "[foo/]include" to the include prefix. */
2929 int len
= strlen (value
);
2932 && (IS_DIR_SEPARATOR (value
[len
- 8]))))
2933 && strncmp (value
+ len
- 7, "stage", 5) == 0
2934 && ISDIGIT (value
[len
- 2])
2935 && (IS_DIR_SEPARATOR (value
[len
- 1])))
2938 add_prefix (&include_prefixes
, "include", NULL_PTR
,
2942 char *string
= xmalloc (len
+ 1);
2943 strncpy (string
, value
, len
-7);
2944 strcpy (string
+len
-7, "include");
2945 add_prefix (&include_prefixes
, string
, NULL_PTR
,
2954 case 'v': /* Print our subcommands and print versions. */
2956 /* If they do anything other than exactly `-v', don't set
2957 verbose_flag; rather, continue on to give the error. */
2965 if (p
[1] == 0 && i
+ 1 == argc
)
2966 fatal ("argument to `-V' is missing");
2968 spec_version
= argv
[++i
];
2970 spec_version
= p
+ 1;
2971 compiler_version
= spec_version
;
2972 warn_std_ptr
= &warn_std
;
2974 /* Validate the version number. Use the same checks
2975 done when inserting it into a spec.
2977 The format of the version string is
2978 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2980 const char *v
= compiler_version
;
2982 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2983 while (! ISDIGIT (*v
))
2986 if (v
> compiler_version
&& v
[-1] != '-')
2987 fatal ("invalid version number format");
2989 /* Set V after the first period. */
2990 while (ISDIGIT (*v
))
2994 fatal ("invalid version number format");
2997 while (ISDIGIT (*v
))
3000 if (*v
!= 0 && *v
!= ' ' && *v
!= '.' && *v
!= '-')
3001 fatal ("invalid version number format");
3017 #if defined(HAVE_EXECUTABLE_SUFFIX)
3022 /* Forward scan, just in case -S or -c is specified
3029 if (argv
[j
][0] == '-')
3031 if (SWITCH_CURTAILS_COMPILATION (argv
[j
][1])
3037 else if (skip
= SWITCH_TAKES_ARG (argv
[j
][1]))
3038 j
+= skip
- (argv
[j
][2] != 0);
3039 else if (skip
= WORD_SWITCH_TAKES_ARG (argv
[j
] + 1))
3046 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3048 argv
[i
+1] = convert_filename (argv
[i
+1], ! have_c
);
3050 argv
[i
] = convert_filename (argv
[i
], ! have_c
);
3058 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3059 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3060 else if (WORD_SWITCH_TAKES_ARG (p
))
3061 i
+= WORD_SWITCH_TAKES_ARG (p
);
3071 if (have_c
&& have_o
&& lang_n_infiles
> 1)
3072 fatal ("cannot specify -o with -c or -S and multiple compilations");
3074 /* Set up the search paths before we go looking for config files. */
3076 /* These come before the md prefixes so that we will find gcc's subcommands
3077 (such as cpp) rather than those of the host system. */
3078 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3079 as well as trying the machine and the version. */
3081 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
3082 0, 2, warn_std_ptr
);
3083 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3084 0, 2, warn_std_ptr
);
3087 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
3088 0, 1, warn_std_ptr
);
3089 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3090 0, 1, warn_std_ptr
);
3092 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
3093 dir_separator_str
, NULL_PTR
);
3095 /* If tooldir is relative, base it on exec_prefixes. A relative
3096 tooldir lets us move the installed tree as a unit.
3098 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3099 directories, so that we can search both the user specified directory
3100 and the standard place. */
3102 if (!IS_DIR_SEPARATOR (*tooldir_prefix
))
3104 if (gcc_exec_prefix
)
3106 char *gcc_exec_tooldir_prefix
3107 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
3108 spec_version
, dir_separator_str
, tooldir_prefix
, NULL_PTR
);
3110 add_prefix (&exec_prefixes
,
3111 concat (gcc_exec_tooldir_prefix
, "bin",
3112 dir_separator_str
, NULL_PTR
),
3113 NULL_PTR
, 0, 0, NULL_PTR
);
3114 add_prefix (&startfile_prefixes
,
3115 concat (gcc_exec_tooldir_prefix
, "lib",
3116 dir_separator_str
, NULL_PTR
),
3117 NULL_PTR
, 0, 0, NULL_PTR
);
3120 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
3121 dir_separator_str
, spec_version
,
3122 dir_separator_str
, tooldir_prefix
, NULL_PTR
);
3125 add_prefix (&exec_prefixes
,
3126 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL_PTR
),
3127 "BINUTILS", 0, 0, NULL_PTR
);
3128 add_prefix (&startfile_prefixes
,
3129 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL_PTR
),
3130 "BINUTILS", 0, 0, NULL_PTR
);
3132 /* More prefixes are enabled in main, after we read the specs file
3133 and determine whether this is cross-compilation or not. */
3136 /* Then create the space for the vectors and scan again. */
3138 switches
= ((struct switchstr
*)
3139 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
3140 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
3143 last_language_n_infiles
= -1;
3145 /* This, time, copy the text of each switch and store a pointer
3146 to the copy in the vector of switches.
3147 Store all the infiles in their vector. */
3149 for (i
= 1; i
< argc
; i
++)
3151 /* Just skip the switches that were handled by the preceding loop. */
3152 if (! strncmp (argv
[i
], "-Wa,", 4))
3154 else if (! strncmp (argv
[i
], "-Wp,", 4))
3156 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3158 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3160 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3162 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3164 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3166 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3168 else if (strcmp (argv
[i
], "-fhelp") == 0)
3172 /* Create a dummy input file, so that we can pass --help on to
3173 the various sub-processes. */
3174 infiles
[n_infiles
].language
= "c";
3175 infiles
[n_infiles
++].name
= "help-dummy";
3177 /* Preserve the --help switch so that it can be caught by the
3179 switches
[n_switches
].part1
= "--help";
3180 switches
[n_switches
].args
= 0;
3181 switches
[n_switches
].live_cond
= 0;
3182 switches
[n_switches
].validated
= 0;
3187 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3189 /* Compensate for the +e options to the C++ front-end;
3190 they're there simply for cfront call-compatibility. We do
3191 some magic in default_compilers to pass them down properly.
3192 Note we deliberately start at the `+' here, to avoid passing
3193 -e0 or -e1 down into the linker. */
3194 switches
[n_switches
].part1
= &argv
[i
][0];
3195 switches
[n_switches
].args
= 0;
3196 switches
[n_switches
].live_cond
= 0;
3197 switches
[n_switches
].validated
= 0;
3200 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3203 /* Split the argument at commas. */
3205 for (j
= 4; argv
[i
][j
]; j
++)
3206 if (argv
[i
][j
] == ',')
3208 infiles
[n_infiles
].language
= "*";
3209 infiles
[n_infiles
++].name
3210 = save_string (argv
[i
] + prev
, j
- prev
);
3213 /* Record the part after the last comma. */
3214 infiles
[n_infiles
].language
= "*";
3215 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
3217 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3219 infiles
[n_infiles
].language
= "*";
3220 infiles
[n_infiles
++].name
= argv
[++i
];
3222 else if (strncmp (argv
[i
], "-l", 2) == 0)
3224 infiles
[n_infiles
].language
= "*";
3225 infiles
[n_infiles
++].name
= argv
[i
];
3227 else if (strcmp (argv
[i
], "-specs") == 0)
3229 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3231 /* -save-temps overrides -pipe, so that temp files are produced */
3232 else if (save_temps_flag
&& strcmp (argv
[i
], "-pipe") == 0)
3233 error ("Warning: -pipe ignored since -save-temps specified");
3234 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3236 register char *p
= &argv
[i
][1];
3237 register int c
= *p
;
3241 if (p
[1] == 0 && i
+ 1 == argc
)
3242 fatal ("argument to `-x' is missing");
3244 spec_lang
= argv
[++i
];
3247 if (! strcmp (spec_lang
, "none"))
3248 /* Suppress the warning if -xnone comes after the last input
3249 file, because alternate command interfaces like g++ might
3250 find it useful to place -xnone after each input file. */
3253 last_language_n_infiles
= n_infiles
;
3256 switches
[n_switches
].part1
= p
;
3257 /* Deal with option arguments in separate argv elements. */
3258 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3259 || WORD_SWITCH_TAKES_ARG (p
))
3262 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
3266 /* Count only the option arguments in separate argv elements. */
3267 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3269 if (i
+ n_args
>= argc
)
3270 fatal ("argument to `-%s' is missing", p
);
3271 switches
[n_switches
].args
3272 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
3274 switches
[n_switches
].args
[j
++] = argv
[++i
];
3275 /* Null-terminate the vector. */
3276 switches
[n_switches
].args
[j
] = 0;
3278 else if (index (switches_need_spaces
, c
))
3280 /* On some systems, ld cannot handle some options without
3281 a space. So split the option from its argument. */
3282 char *part1
= (char *) xmalloc (2);
3286 switches
[n_switches
].part1
= part1
;
3287 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
3288 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
3289 strcpy (switches
[n_switches
].args
[0], &p
[1]);
3290 switches
[n_switches
].args
[1] = 0;
3293 switches
[n_switches
].args
= 0;
3295 switches
[n_switches
].live_cond
= 0;
3296 switches
[n_switches
].validated
= 0;
3297 /* This is always valid, since gcc.c itself understands it. */
3298 if (!strcmp (p
, "save-temps"))
3299 switches
[n_switches
].validated
= 1;
3302 char ch
= switches
[n_switches
].part1
[0];
3303 if (ch
== 'V' || ch
== 'b' || ch
== 'B')
3304 switches
[n_switches
].validated
= 1;
3310 #ifdef HAVE_OBJECT_SUFFIX
3311 argv
[i
] = convert_filename (argv
[i
], 0);
3314 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], R_OK
) < 0)
3316 perror_with_name (argv
[i
]);
3321 infiles
[n_infiles
].language
= spec_lang
;
3322 infiles
[n_infiles
++].name
= argv
[i
];
3327 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
3328 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
3330 switches
[n_switches
].part1
= 0;
3331 infiles
[n_infiles
].name
= 0;
3334 /* Process a spec string, accumulating and running commands. */
3336 /* These variables describe the input file name.
3337 input_file_number is the index on outfiles of this file,
3338 so that the output file name can be stored for later use by %o.
3339 input_basename is the start of the part of the input file
3340 sans all directory names, and basename_length is the number
3341 of characters starting there excluding the suffix .c or whatever. */
3343 const char *input_filename
;
3344 static int input_file_number
;
3345 size_t input_filename_length
;
3346 static int basename_length
;
3347 static const char *input_basename
;
3348 static const char *input_suffix
;
3350 /* These are variables used within do_spec and do_spec_1. */
3352 /* Nonzero if an arg has been started and not yet terminated
3353 (with space, tab or newline). */
3354 static int arg_going
;
3356 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3357 is a temporary file name. */
3358 static int delete_this_arg
;
3360 /* Nonzero means %w has been seen; the next arg to be terminated
3361 is the output file name of this compilation. */
3362 static int this_is_output_file
;
3364 /* Nonzero means %s has been seen; the next arg to be terminated
3365 is the name of a library file and we should try the standard
3366 search dirs for it. */
3367 static int this_is_library_file
;
3369 /* Nonzero means that the input of this command is coming from a pipe. */
3370 static int input_from_pipe
;
3372 /* Process the spec SPEC and run the commands specified therein.
3373 Returns 0 if the spec is successfully processed; -1 if failed. */
3383 delete_this_arg
= 0;
3384 this_is_output_file
= 0;
3385 this_is_library_file
= 0;
3386 input_from_pipe
= 0;
3388 value
= do_spec_1 (spec
, 0, NULL_PTR
);
3390 /* Force out any unfinished command.
3391 If -pipe, this forces out the last command if it ended in `|'. */
3394 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3397 if (argbuf_index
> 0)
3404 /* Process the sub-spec SPEC as a portion of a larger spec.
3405 This is like processing a whole spec except that we do
3406 not initialize at the beginning and we do not supply a
3407 newline by default at the end.
3408 INSWITCH nonzero means don't process %-sequences in SPEC;
3409 in this case, % is treated as an ordinary character.
3410 This is used while substituting switches.
3411 INSWITCH nonzero also causes SPC not to terminate an argument.
3413 Value is zero unless a line was finished
3414 and the command on that line reported an error. */
3417 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3420 const char *soft_matched_part
;
3422 register const char *p
= spec
;
3429 /* If substituting a switch, treat all chars like letters.
3430 Otherwise, NL, SPC, TAB and % are special. */
3431 switch (inswitch
? 'a' : c
)
3434 /* End of line: finish any pending argument,
3435 then run the pending command if one has been started. */
3438 obstack_1grow (&obstack
, 0);
3439 string
= obstack_finish (&obstack
);
3440 if (this_is_library_file
)
3441 string
= find_file (string
);
3442 store_arg (string
, delete_this_arg
, this_is_output_file
);
3443 if (this_is_output_file
)
3444 outfiles
[input_file_number
] = string
;
3448 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3450 for (i
= 0; i
< n_switches
; i
++)
3451 if (!strcmp (switches
[i
].part1
, "pipe"))
3454 /* A `|' before the newline means use a pipe here,
3455 but only if -pipe was specified.
3456 Otherwise, execute now and don't pass the `|' as an arg. */
3459 input_from_pipe
= 1;
3460 switches
[i
].validated
= 1;
3467 if (argbuf_index
> 0)
3473 /* Reinitialize for a new command, and for a new argument. */
3476 delete_this_arg
= 0;
3477 this_is_output_file
= 0;
3478 this_is_library_file
= 0;
3479 input_from_pipe
= 0;
3483 /* End any pending argument. */
3486 obstack_1grow (&obstack
, 0);
3487 string
= obstack_finish (&obstack
);
3488 if (this_is_library_file
)
3489 string
= find_file (string
);
3490 store_arg (string
, delete_this_arg
, this_is_output_file
);
3491 if (this_is_output_file
)
3492 outfiles
[input_file_number
] = string
;
3496 obstack_1grow (&obstack
, c
);
3502 /* Space or tab ends an argument if one is pending. */
3505 obstack_1grow (&obstack
, 0);
3506 string
= obstack_finish (&obstack
);
3507 if (this_is_library_file
)
3508 string
= find_file (string
);
3509 store_arg (string
, delete_this_arg
, this_is_output_file
);
3510 if (this_is_output_file
)
3511 outfiles
[input_file_number
] = string
;
3513 /* Reinitialize for a new argument. */
3515 delete_this_arg
= 0;
3516 this_is_output_file
= 0;
3517 this_is_library_file
= 0;
3524 fatal ("Invalid specification! Bug in cc.");
3527 obstack_grow (&obstack
, input_basename
, basename_length
);
3532 delete_this_arg
= 2;
3535 /* Dump out the directories specified with LIBRARY_PATH,
3536 followed by the absolute directories
3537 that we search for startfiles. */
3540 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3541 size_t bufsize
= 100;
3542 char *buffer
= (char *) xmalloc (bufsize
);
3545 for (; pl
; pl
= pl
->next
)
3547 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3548 /* Used on systems which record the specified -L dirs
3549 and use them to search for dynamic linking. */
3550 /* Relative directories always come from -B,
3551 and it is better not to use them for searching
3552 at run time. In particular, stage1 loses */
3553 if (!IS_DIR_SEPARATOR (pl
->prefix
[0]))
3556 /* Try subdirectory if there is one. */
3557 if (multilib_dir
!= NULL
)
3561 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3563 bufsize
= (strlen (pl
->prefix
)
3564 + strlen (machine_suffix
)) * 2 + 1;
3565 buffer
= (char *) xrealloc (buffer
, bufsize
);
3566 strcpy (buffer
, pl
->prefix
);
3567 strcat (buffer
, machine_suffix
);
3568 if (is_directory (buffer
, multilib_dir
, 1))
3570 do_spec_1 ("-L", 0, NULL_PTR
);
3571 #ifdef SPACE_AFTER_L_OPTION
3572 do_spec_1 (" ", 0, NULL_PTR
);
3574 do_spec_1 (buffer
, 1, NULL_PTR
);
3575 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3576 /* Make this a separate argument. */
3577 do_spec_1 (" ", 0, NULL_PTR
);
3580 if (!pl
->require_machine_suffix
)
3582 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3584 do_spec_1 ("-L", 0, NULL_PTR
);
3585 #ifdef SPACE_AFTER_L_OPTION
3586 do_spec_1 (" ", 0, NULL_PTR
);
3588 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3589 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3590 /* Make this a separate argument. */
3591 do_spec_1 (" ", 0, NULL_PTR
);
3597 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3599 do_spec_1 ("-L", 0, NULL_PTR
);
3600 #ifdef SPACE_AFTER_L_OPTION
3601 do_spec_1 (" ", 0, NULL_PTR
);
3603 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3604 /* Remove slash from machine_suffix. */
3605 if (strlen (machine_suffix
) >= bufsize
)
3606 bufsize
= strlen (machine_suffix
) * 2 + 1;
3607 buffer
= (char *) xrealloc (buffer
, bufsize
);
3608 strcpy (buffer
, machine_suffix
);
3609 idx
= strlen (buffer
);
3610 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
3611 buffer
[idx
- 1] = 0;
3612 do_spec_1 (buffer
, 1, NULL_PTR
);
3613 /* Make this a separate argument. */
3614 do_spec_1 (" ", 0, NULL_PTR
);
3617 if (!pl
->require_machine_suffix
)
3619 if (is_directory (pl
->prefix
, "", 1))
3621 do_spec_1 ("-L", 0, NULL_PTR
);
3622 #ifdef SPACE_AFTER_L_OPTION
3623 do_spec_1 (" ", 0, NULL_PTR
);
3625 /* Remove slash from pl->prefix. */
3626 if (strlen (pl
->prefix
) >= bufsize
)
3627 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3628 buffer
= (char *) xrealloc (buffer
, bufsize
);
3629 strcpy (buffer
, pl
->prefix
);
3630 idx
= strlen (buffer
);
3631 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
3632 buffer
[idx
- 1] = 0;
3633 do_spec_1 (buffer
, 1, NULL_PTR
);
3634 /* Make this a separate argument. */
3635 do_spec_1 (" ", 0, NULL_PTR
);
3644 /* %efoo means report an error with `foo' as error message
3645 and don't execute any more commands for this file. */
3649 while (*p
!= 0 && *p
!= '\n') p
++;
3650 buf
= (char *) alloca (p
- q
+ 1);
3651 strncpy (buf
, q
, p
- q
);
3661 if (save_temps_flag
)
3663 obstack_grow (&obstack
, input_basename
, basename_length
);
3664 delete_this_arg
= 0;
3668 #ifdef MKTEMP_EACH_FILE
3669 /* ??? This has a problem: the total number of
3670 values mktemp can return is limited.
3671 That matters for the names of object files.
3672 In 2.4, do something about that. */
3673 struct temp_name
*t
;
3675 const char *suffix
= p
;
3677 if (p
[0] == '%' && p
[1] == 'O')
3680 /* We don't support extra suffix characters after %O. */
3681 if (*p
== '.' || ISALPHA ((unsigned char)*p
))
3683 suffix
= OBJECT_SUFFIX
;
3684 suffix_length
= strlen (OBJECT_SUFFIX
);
3688 while (*p
== '.' || ISALPHA ((unsigned char)*p
))
3690 suffix_length
= p
- suffix
;
3693 /* See if we already have an association of %g/%u/%U and
3695 for (t
= temp_names
; t
; t
= t
->next
)
3696 if (t
->length
== suffix_length
3697 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
3698 && t
->unique
== (c
!= 'g'))
3701 /* Make a new association if needed. %u requires one. */
3702 if (t
== 0 || c
== 'u')
3706 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3707 t
->next
= temp_names
;
3710 t
->length
= suffix_length
;
3711 t
->suffix
= save_string (suffix
, suffix_length
);
3712 t
->unique
= (c
!= 'g');
3713 temp_filename
= make_temp_file (t
->suffix
);
3714 temp_filename_length
= strlen (temp_filename
);
3715 t
->filename
= temp_filename
;
3716 t
->filename_length
= temp_filename_length
;
3719 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3720 delete_this_arg
= 1;
3722 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3723 if (c
== 'u' || c
== 'U')
3729 sprintf (buff
, "%d", unique
);
3730 obstack_grow (&obstack
, buff
, strlen (buff
));
3733 delete_this_arg
= 1;
3739 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3745 struct prefix_list
*pl
= include_prefixes
.plist
;
3747 if (gcc_exec_prefix
)
3749 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3750 /* Make this a separate argument. */
3751 do_spec_1 (" ", 0, NULL_PTR
);
3752 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3753 do_spec_1 (" ", 0, NULL_PTR
);
3756 for (; pl
; pl
= pl
->next
)
3758 do_spec_1 ("-isystem", 1, NULL_PTR
);
3759 /* Make this a separate argument. */
3760 do_spec_1 (" ", 0, NULL_PTR
);
3761 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3762 do_spec_1 (" ", 0, NULL_PTR
);
3769 int max
= n_infiles
;
3770 max
+= lang_specific_extra_outfiles
;
3772 for (i
= 0; i
< max
; i
++)
3774 store_arg (outfiles
[i
], 0, 0);
3779 obstack_grow (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
3784 this_is_library_file
= 1;
3788 this_is_output_file
= 1;
3793 int cur_index
= argbuf_index
;
3794 /* Handle the {...} following the %W. */
3797 p
= handle_braces (p
+ 1);
3800 /* If any args were output, mark the last one for deletion
3802 if (argbuf_index
!= cur_index
)
3803 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3807 /* %x{OPTION} records OPTION for %X to output. */
3813 /* Skip past the option value and make a copy. */
3818 string
= save_string (p1
+ 1, p
- p1
- 2);
3820 /* See if we already recorded this option. */
3821 for (i
= 0; i
< n_linker_options
; i
++)
3822 if (! strcmp (string
, linker_options
[i
]))
3828 /* This option is new; add it. */
3829 add_linker_option (string
, strlen (string
));
3833 /* Dump out the options accumulated previously using %x. */
3835 for (i
= 0; i
< n_linker_options
; i
++)
3837 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3838 /* Make each accumulated option a separate argument. */
3839 do_spec_1 (" ", 0, NULL_PTR
);
3843 /* Dump out the options accumulated previously using -Wa,. */
3845 for (i
= 0; i
< n_assembler_options
; i
++)
3847 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3848 /* Make each accumulated option a separate argument. */
3849 do_spec_1 (" ", 0, NULL_PTR
);
3853 /* Dump out the options accumulated previously using -Wp,. */
3855 for (i
= 0; i
< n_preprocessor_options
; i
++)
3857 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3858 /* Make each accumulated option a separate argument. */
3859 do_spec_1 (" ", 0, NULL_PTR
);
3863 /* Here are digits and numbers that just process
3864 a certain constant string as a spec. */
3867 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3873 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3879 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3885 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3891 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3897 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3903 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3909 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3915 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3921 value
= do_spec_1 (libgcc_spec
, 0, NULL_PTR
);
3928 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3932 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3936 if (! strncmp (y
, "-D", 2))
3937 /* Copy the whole option. */
3938 while (*y
&& *y
!= ' ' && *y
!= '\t')
3940 else if (*y
== ' ' || *y
== '\t')
3941 /* Copy whitespace to the result. */
3943 /* Don't copy other options. */
3950 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3958 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3962 /* Copy all of CPP_PREDEFINES into BUF,
3963 but put __ after every -D and at the end of each arg. */
3967 if (! strncmp (y
, "-D", 2))
3976 && ! ISUPPER ((unsigned char)*(y
+1))))
3978 /* Stick __ at front of macro name. */
3981 /* Arrange to stick __ at the end as well. */
3985 /* Copy the macro name. */
3986 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3995 /* Copy the value given, if any. */
3996 while (*y
&& *y
!= ' ' && *y
!= '\t')
3999 else if (*y
== ' ' || *y
== '\t')
4000 /* Copy whitespace to the result. */
4002 /* Don't copy -A options */
4008 /* Copy all of CPP_PREDEFINES into BUF,
4009 but put __ after every -D. */
4013 if (! strncmp (y
, "-D", 2))
4019 && ! ISUPPER ((unsigned char)*(y
+1))))
4021 /* Stick -D__ at front of macro name. */
4027 /* Copy the macro name. */
4028 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4031 /* Copy the value given, if any. */
4032 while (*y
&& *y
!= ' ' && *y
!= '\t')
4037 /* Do not copy this macro - we have just done it before */
4038 while (*y
&& *y
!= ' ' && *y
!= '\t')
4042 else if (*y
== ' ' || *y
== '\t')
4043 /* Copy whitespace to the result. */
4045 /* Don't copy -A options */
4051 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4055 if (! strncmp (y
, "-A", 2))
4056 /* Copy the whole option. */
4057 while (*y
&& *y
!= ' ' && *y
!= '\t')
4059 else if (*y
== ' ' || *y
== '\t')
4060 /* Copy whitespace to the result. */
4062 /* Don't copy other options. */
4069 value
= do_spec_1 (buf
, 0, NULL_PTR
);
4076 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
4081 /* Here we define characters other than letters and digits. */
4084 p
= handle_braces (p
);
4090 obstack_1grow (&obstack
, '%');
4094 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
4095 do_spec_1 (" ", 0, NULL_PTR
);
4098 /* Process a string found as the value of a spec given by name.
4099 This feature allows individual machine descriptions
4100 to add and use their own specs.
4101 %[...] modifies -D options the way %P does;
4102 %(...) uses the spec unmodified. */
4104 error ("Warning: use of obsolete %%[ operator in specs");
4107 const char *name
= p
;
4108 struct spec_list
*sl
;
4111 /* The string after the S/P is the name of a spec that is to be
4113 while (*p
&& *p
!= ')' && *p
!= ']')
4116 /* See if it's in the list */
4117 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
4118 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
4120 name
= *(sl
->ptr_spec
);
4122 notice ("Processing spec %c%s%c, which is '%s'\n",
4123 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
4132 value
= do_spec_1 (name
, 0, NULL_PTR
);
4138 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
4140 const char *y
= name
;
4143 /* Copy all of NAME into BUF, but put __ after
4144 every -D and at the end of each arg, */
4147 if (! strncmp (y
, "-D", 2))
4157 else if (flag
&& (*y
== ' ' || *y
== '\t' || *y
== '='
4158 || *y
== '}' || *y
== 0))
4171 value
= do_spec_1 (buf
, 0, NULL_PTR
);
4177 /* Discard the closing paren or bracket. */
4185 int c1
= *p
++; /* Select first or second version number. */
4186 char *v
= compiler_version
;
4189 /* The format of the version string is
4190 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4192 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4193 while (! ISDIGIT (*v
))
4195 if (v
> compiler_version
&& v
[-1] != '-')
4198 /* If desired, advance to second version number. */
4201 /* Set V after the first period. */
4202 while (ISDIGIT (*v
))
4209 /* Set Q at the next period or at the end. */
4211 while (ISDIGIT (*q
))
4213 if (*q
!= 0 && *q
!= ' ' && *q
!= '.' && *q
!= '-')
4216 /* Put that part into the command. */
4217 obstack_grow (&obstack
, v
, q
- v
);
4223 if (input_from_pipe
)
4224 do_spec_1 ("-", 0, NULL_PTR
);
4233 /* Backslash: treat next character as ordinary. */
4238 /* Ordinary character: put it into the current argument. */
4239 obstack_1grow (&obstack
, c
);
4243 return 0; /* End of string */
4246 /* Return 0 if we call do_spec_1 and that returns -1. */
4250 register const char *p
;
4252 const char *filter
, *body
= NULL
, *endbody
= NULL
;
4256 int include_blanks
= 1;
4259 /* A '^' after the open-brace means to not give blanks before args. */
4260 include_blanks
= 0, ++p
;
4263 /* A `|' after the open-brace means,
4264 if the test fails, output a single minus sign rather than nothing.
4265 This is used in %{|!pipe:...}. */
4269 negate
= suffix
= 0;
4272 /* A `!' after the open-brace negates the condition:
4273 succeed if the specified switch is not present. */
4277 /* A `.' after the open-brace means test against the current suffix. */
4287 while (*p
!= ':' && *p
!= '}' && *p
!= '|') p
++;
4289 if (*p
== '|' && pipe_p
)
4296 register int count
= 1;
4297 register const char *q
= p
;
4299 while (*q
++ != ':') continue;
4315 body
= p
, endbody
= p
+1;
4320 int found
= (input_suffix
!= 0
4321 && (long) strlen (input_suffix
) == (long)(p
- filter
)
4322 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
4328 && do_spec_1 (save_string (body
, endbody
-body
-1), 0, NULL_PTR
) < 0)
4331 else if (p
[-1] == '*' && p
[0] == '}')
4333 /* Substitute all matching switches as separate args. */
4336 for (i
= 0; i
< n_switches
; i
++)
4337 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4338 && check_live_switch (i
, p
- filter
))
4339 give_switch (i
, 0, include_blanks
);
4343 /* Test for presence of the specified switch. */
4347 /* If name specified ends in *, as in {x*:...},
4348 check for %* and handle that case. */
4349 if (p
[-1] == '*' && !negate
)
4352 const char *r
= body
;
4354 /* First see whether we have %*. */
4358 if (*r
== '%' && r
[1] == '*')
4362 /* If we do, handle that case. */
4365 /* Substitute all matching switches as separate args.
4366 But do this by substituting for %*
4367 in the text that follows the colon. */
4369 unsigned hard_match_len
= p
- filter
- 1;
4370 char *string
= save_string (body
, endbody
- body
- 1);
4372 for (i
= 0; i
< n_switches
; i
++)
4373 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4374 && check_live_switch (i
, -1))
4376 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
4377 /* Pass any arguments this switch has. */
4378 give_switch (i
, 1, 1);
4381 /* We didn't match. Try again. */
4388 /* If name specified ends in *, as in {x*:...},
4389 check for presence of any switch name starting with x. */
4392 for (i
= 0; i
< n_switches
; i
++)
4394 unsigned hard_match_len
= p
- filter
- 1;
4396 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4397 && check_live_switch (i
, hard_match_len
))
4403 /* Otherwise, check for presence of exact name specified. */
4406 for (i
= 0; i
< n_switches
; i
++)
4408 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4409 && switches
[i
].part1
[p
- filter
] == 0
4410 && check_live_switch (i
, -1))
4418 /* If it is as desired (present for %{s...}, absent for %{!s...})
4419 then substitute either the switch or the specified
4420 conditional text. */
4421 if (present
!= negate
)
4425 give_switch (i
, 0, include_blanks
);
4429 if (do_spec_1 (save_string (body
, endbody
- body
- 1),
4436 /* Here if a %{|...} conditional fails: output a minus sign,
4437 which means "standard output" or "standard input". */
4438 do_spec_1 ("-", 0, NULL_PTR
);
4443 /* We didn't match; try again. */
4450 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4451 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4452 spec, or -1 if either exact match or %* is used.
4454 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4455 whose value does not begin with "no-" is obsoleted by the same value
4456 with the "no-", similarly for a switch with the "no-" prefix. */
4459 check_live_switch (switchnum
, prefix_length
)
4463 const char *name
= switches
[switchnum
].part1
;
4466 /* In the common case of {<at-most-one-letter>*}, a negating
4467 switch would always match, so ignore that case. We will just
4468 send the conflicting switches to the compiler phase. */
4469 if (prefix_length
>= 0 && prefix_length
<= 1)
4472 /* If we already processed this switch and determined if it was
4473 live or not, return our past determination. */
4474 if (switches
[switchnum
].live_cond
!= 0)
4475 return switches
[switchnum
].live_cond
> 0;
4477 /* Now search for duplicate in a manner that depends on the name. */
4481 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4482 if (switches
[i
].part1
[0] == 'O')
4484 switches
[switchnum
].validated
= 1;
4485 switches
[switchnum
].live_cond
= -1;
4490 case 'W': case 'f': case 'm':
4491 if (! strncmp (name
+ 1, "no-", 3))
4493 /* We have Xno-YYY, search for XYYY. */
4494 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4495 if (switches
[i
].part1
[0] == name
[0]
4496 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4498 switches
[switchnum
].validated
= 1;
4499 switches
[switchnum
].live_cond
= -1;
4505 /* We have XYYY, search for Xno-YYY. */
4506 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4507 if (switches
[i
].part1
[0] == name
[0]
4508 && switches
[i
].part1
[1] == 'n'
4509 && switches
[i
].part1
[2] == 'o'
4510 && switches
[i
].part1
[3] == '-'
4511 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4513 switches
[switchnum
].validated
= 1;
4514 switches
[switchnum
].live_cond
= -1;
4521 /* Otherwise the switch is live. */
4522 switches
[switchnum
].live_cond
= 1;
4526 /* Pass a switch to the current accumulating command
4527 in the same form that we received it.
4528 SWITCHNUM identifies the switch; it is an index into
4529 the vector of switches gcc received, which is `switches'.
4530 This cannot fail since it never finishes a command line.
4532 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4534 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4538 give_switch (switchnum
, omit_first_word
, include_blanks
)
4540 int omit_first_word
;
4543 if (!omit_first_word
)
4545 do_spec_1 ("-", 0, NULL_PTR
);
4546 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4549 if (switches
[switchnum
].args
!= 0)
4552 for (p
= switches
[switchnum
].args
; *p
; p
++)
4555 do_spec_1 (" ", 0, NULL_PTR
);
4556 do_spec_1 (*p
, 1, NULL_PTR
);
4560 do_spec_1 (" ", 0, NULL_PTR
);
4561 switches
[switchnum
].validated
= 1;
4564 /* Search for a file named NAME trying various prefixes including the
4565 user's -B prefix and some standard ones.
4566 Return the absolute file name found. If nothing is found, return NAME. */
4574 /* Try multilib_dir if it is defined. */
4575 if (multilib_dir
!= NULL
)
4579 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4580 strcpy (try, multilib_dir
);
4581 strcat (try, dir_separator_str
);
4584 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4586 /* If we don't find it in the multi library dir, then fall
4587 through and look for it in the normal places. */
4588 if (newname
!= NULL
)
4592 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4593 return newname
? newname
: name
;
4596 /* Determine whether a directory exists. If LINKER, return 0 for
4597 certain fixed names not needed by the linker. If not LINKER, it is
4598 only important to return 0 if the host machine has a small ARG_MAX
4602 is_directory (path1
, path2
, linker
)
4607 int len1
= strlen (path1
);
4608 int len2
= strlen (path2
);
4609 char *path
= (char *) alloca (3 + len1
+ len2
);
4613 #ifndef SMALL_ARG_MAX
4618 /* Construct the path from the two parts. Ensure the string ends with "/.".
4619 The resulting path will be a directory even if the given path is a
4621 memcpy (path
, path1
, len1
);
4622 memcpy (path
+ len1
, path2
, len2
);
4623 cp
= path
+ len1
+ len2
;
4624 if (!IS_DIR_SEPARATOR (cp
[-1]))
4625 *cp
++ = DIR_SEPARATOR
;
4629 /* Exclude directories that the linker is known to search. */
4632 && strcmp (path
, concat (dir_separator_str
, "lib",
4633 dir_separator_str
, ".", NULL_PTR
)) == 0)
4635 && strcmp (path
, concat (dir_separator_str
, "usr",
4636 dir_separator_str
, "lib",
4637 dir_separator_str
, ".", NULL_PTR
)) == 0)))
4640 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4643 /* On fatal signals, delete all the temporary files. */
4646 fatal_error (signum
)
4649 signal (signum
, SIG_DFL
);
4650 delete_failure_queue ();
4651 delete_temp_files ();
4652 /* Get the same signal again, this time not handled,
4653 so its normal effect occurs. */
4654 kill (getpid (), signum
);
4665 int linker_was_run
= 0;
4666 char *explicit_link_files
;
4669 struct user_specs
*uptr
;
4671 p
= argv
[0] + strlen (argv
[0]);
4672 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
4676 #ifdef HAVE_LC_MESSAGES
4677 setlocale (LC_MESSAGES
, "");
4679 (void) bindtextdomain (PACKAGE
, localedir
);
4680 (void) textdomain (PACKAGE
);
4682 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4683 signal (SIGINT
, fatal_error
);
4685 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4686 signal (SIGHUP
, fatal_error
);
4688 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4689 signal (SIGTERM
, fatal_error
);
4691 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4692 signal (SIGPIPE
, fatal_error
);
4696 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4698 obstack_init (&obstack
);
4700 /* Build multilib_select, et. al from the separate lines that make up each
4701 multilib selection. */
4703 char **q
= multilib_raw
;
4706 obstack_init (&multilib_obstack
);
4707 while ((p
= *q
++) != (char *) 0)
4708 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4710 obstack_1grow (&multilib_obstack
, 0);
4711 multilib_select
= obstack_finish (&multilib_obstack
);
4713 q
= multilib_matches_raw
;
4714 while ((p
= *q
++) != (char *) 0)
4715 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4717 obstack_1grow (&multilib_obstack
, 0);
4718 multilib_matches
= obstack_finish (&multilib_obstack
);
4722 i
< sizeof (multilib_defaults_raw
) / sizeof (multilib_defaults_raw
[0]);
4726 obstack_1grow (&multilib_obstack
, ' ');
4727 obstack_grow (&multilib_obstack
,
4728 multilib_defaults_raw
[i
],
4729 strlen (multilib_defaults_raw
[i
]));
4733 obstack_1grow (&multilib_obstack
, 0);
4734 multilib_defaults
= obstack_finish (&multilib_obstack
);
4737 /* Set up to remember the pathname of gcc and any options
4738 needed for collect. We use argv[0] instead of programname because
4739 we need the complete pathname. */
4740 obstack_init (&collect_obstack
);
4741 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4742 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4743 putenv (obstack_finish (&collect_obstack
));
4745 #ifdef INIT_ENVIRONMENT
4746 /* Set up any other necessary machine specific environment variables. */
4747 putenv (INIT_ENVIRONMENT
);
4750 /* Choose directory for temp files. */
4752 #ifndef MKTEMP_EACH_FILE
4753 temp_filename
= choose_temp_base ();
4754 temp_filename_length
= strlen (temp_filename
);
4757 /* Make a table of what switches there are (switches, n_switches).
4758 Make a table of specified input files (infiles, n_infiles).
4759 Decode switches that are handled locally. */
4761 process_command (argc
, argv
);
4766 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4768 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4769 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4772 for (i
= 0; (int)i
< n_switches
; i
++)
4777 obstack_grow (&collect_obstack
, " ", 1);
4780 obstack_grow (&collect_obstack
, "'-", 2);
4781 q
= switches
[i
].part1
;
4782 while ((p
= index (q
,'\'')))
4784 obstack_grow (&collect_obstack
, q
, p
-q
);
4785 obstack_grow (&collect_obstack
, "'\\''", 4);
4788 obstack_grow (&collect_obstack
, q
, strlen (q
));
4789 obstack_grow (&collect_obstack
, "'", 1);
4791 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4793 obstack_grow (&collect_obstack
, " '", 2);
4795 while ((p
= index (q
,'\'')))
4797 obstack_grow (&collect_obstack
, q
, p
-q
);
4798 obstack_grow (&collect_obstack
, "'\\''", 4);
4801 obstack_grow (&collect_obstack
, q
, strlen (q
));
4802 obstack_grow (&collect_obstack
, "'", 1);
4805 obstack_grow (&collect_obstack
, "\0", 1);
4806 putenv (obstack_finish (&collect_obstack
));
4809 /* Initialize the vector of specs to just the default.
4810 This means one element containing 0s, as a terminator. */
4812 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4813 bcopy ((char *) default_compilers
, (char *) compilers
,
4814 sizeof default_compilers
);
4815 n_compilers
= n_default_compilers
;
4817 /* Read specs from a file if there is one. */
4819 machine_suffix
= concat (spec_machine
, dir_separator_str
,
4820 spec_version
, dir_separator_str
, NULL_PTR
);
4821 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL_PTR
);
4823 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4824 /* Read the specs file unless it is a default one. */
4825 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4826 read_specs (specs_file
, TRUE
);
4830 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4831 for any override of as, ld and libraries. */
4832 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
4833 + strlen (just_machine_suffix
)
4834 + sizeof ("specs"));
4836 strcpy (specs_file
, standard_exec_prefix
);
4837 strcat (specs_file
, just_machine_suffix
);
4838 strcat (specs_file
, "specs");
4839 if (access (specs_file
, R_OK
) == 0)
4840 read_specs (specs_file
, TRUE
);
4842 /* If not cross-compiling, look for startfiles in the standard places. */
4843 if (*cross_compile
== '0')
4845 #ifdef MD_EXEC_PREFIX
4846 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4847 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4850 #ifdef MD_STARTFILE_PREFIX
4851 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
4855 #ifdef MD_STARTFILE_PREFIX_1
4856 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
4860 /* If standard_startfile_prefix is relative, base it on
4861 standard_exec_prefix. This lets us move the installed tree
4862 as a unit. If GCC_EXEC_PREFIX is defined, base
4863 standard_startfile_prefix on that as well. */
4864 if (IS_DIR_SEPARATOR (*standard_startfile_prefix
)
4865 || *standard_startfile_prefix
== '$'
4866 #ifdef HAVE_DOS_BASED_FILESYSTEM
4867 /* Check for disk name on MS-DOS-based systems. */
4868 || (standard_startfile_prefix
[1] == ':'
4869 && (IS_DIR_SEPARATOR (standard_startfile_prefix
[2])))
4872 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
4876 if (gcc_exec_prefix
)
4877 add_prefix (&startfile_prefixes
,
4878 concat (gcc_exec_prefix
, machine_suffix
,
4879 standard_startfile_prefix
, NULL_PTR
),
4880 NULL_PTR
, 0, 0, NULL_PTR
);
4881 add_prefix (&startfile_prefixes
,
4882 concat (standard_exec_prefix
,
4884 standard_startfile_prefix
, NULL_PTR
),
4885 NULL_PTR
, 0, 0, NULL_PTR
);
4888 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
4889 "BINUTILS", 0, 0, NULL_PTR
);
4890 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
4891 "BINUTILS", 0, 0, NULL_PTR
);
4892 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4893 add_prefix (&startfile_prefixes
, "./", NULL_PTR
, 0, 1, NULL_PTR
);
4898 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix
) && gcc_exec_prefix
)
4899 add_prefix (&startfile_prefixes
,
4900 concat (gcc_exec_prefix
, machine_suffix
,
4901 standard_startfile_prefix
, NULL_PTR
),
4902 "BINUTILS", 0, 0, NULL_PTR
);
4905 /* Process any user specified specs in the order given on the command
4907 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
4909 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
, R_OK
);
4910 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
4913 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4914 if (gcc_exec_prefix
)
4916 char * temp
= (char *) xmalloc (strlen (gcc_exec_prefix
)
4917 + strlen (spec_version
)
4918 + strlen (spec_machine
) + 3);
4919 strcpy (temp
, gcc_exec_prefix
);
4920 strcat (temp
, spec_machine
);
4921 strcat (temp
, dir_separator_str
);
4922 strcat (temp
, spec_version
);
4923 strcat (temp
, dir_separator_str
);
4924 gcc_exec_prefix
= temp
;
4927 /* Now we have the specs.
4928 Set the `valid' bits for switches that match anything in any spec. */
4930 validate_all_switches ();
4932 /* Now that we have the switches and the specs, set
4933 the subdirectory based on the options. */
4934 set_multilib_dir ();
4936 /* Warn about any switches that no pass was interested in. */
4938 for (i
= 0; (int)i
< n_switches
; i
++)
4939 if (! switches
[i
].validated
)
4940 error ("unrecognized option `-%s'", switches
[i
].part1
);
4942 /* Obey some of the options. */
4944 if (print_search_dirs
)
4946 printf ("install: %s%s\n", standard_exec_prefix
, machine_suffix
);
4947 printf ("programs: %s\n", build_search_list (&exec_prefixes
, "", 0));
4948 printf ("libraries: %s\n", build_search_list (&startfile_prefixes
, "", 0));
4952 if (print_file_name
)
4954 printf ("%s\n", find_file (print_file_name
));
4958 if (print_prog_name
)
4960 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4961 printf ("%s\n", (newname
? newname
: print_prog_name
));
4965 if (print_multi_lib
)
4967 print_multilib_info ();
4971 if (print_multi_directory
)
4973 if (multilib_dir
== NULL
)
4976 printf ("%s\n", multilib_dir
);
4980 if (print_help_list
)
4986 printf ("\nFor bug reporting instructions, please see:\n");
4987 printf ("<URL:http://gcc.gnu.org/faq.html#bugreport>.\n");
4992 /* We do not exit here. Instead we have created a fake input file
4993 called 'help-dummy' which needs to be compiled, and we pass this
4994 on the the various sub-processes, along with the --help switch. */
5001 /* compiler_version is truncated at the first space when initialized
5002 from version string, so truncate version_string at the first space
5003 before comparing. */
5004 for (n
= 0; version_string
[n
]; n
++)
5005 if (version_string
[n
] == ' ')
5008 if (! strncmp (version_string
, compiler_version
, n
)
5009 && compiler_version
[n
] == 0)
5010 notice ("gcc version %s\n", version_string
);
5012 notice ("gcc driver version %s executing gcc version %s\n",
5013 version_string
, compiler_version
);
5019 if (n_infiles
== added_libraries
)
5020 fatal ("No input files");
5022 /* Make a place to record the compiler output file names
5023 that correspond to the input files. */
5026 i
+= lang_specific_extra_outfiles
;
5027 outfiles
= (const char **) xmalloc (i
* sizeof (char *));
5028 bzero ((char *) outfiles
, i
* sizeof (char *));
5030 /* Record which files were specified explicitly as link input. */
5032 explicit_link_files
= xmalloc (n_infiles
);
5033 bzero (explicit_link_files
, n_infiles
);
5035 for (i
= 0; (int)i
< n_infiles
; i
++)
5037 register struct compiler
*cp
= 0;
5038 int this_file_error
= 0;
5040 /* Tell do_spec what to substitute for %i. */
5042 input_filename
= infiles
[i
].name
;
5043 input_filename_length
= strlen (input_filename
);
5044 input_file_number
= i
;
5046 /* Use the same thing in %o, unless cp->spec says otherwise. */
5048 outfiles
[i
] = input_filename
;
5050 /* Figure out which compiler from the file's suffix. */
5052 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
5053 infiles
[i
].language
);
5057 /* Ok, we found an applicable compiler. Run its spec. */
5058 /* First say how much of input_filename to substitute for %b */
5059 register const char *p
;
5062 if (cp
->spec
[0][0] == '#')
5063 error ("%s: %s compiler not installed on this system",
5064 input_filename
, &cp
->spec
[0][1]);
5066 input_basename
= input_filename
;
5067 for (p
= input_filename
; *p
; p
++)
5068 if (IS_DIR_SEPARATOR (*p
))
5069 input_basename
= p
+ 1;
5071 /* Find a suffix starting with the last period,
5072 and set basename_length to exclude that suffix. */
5073 basename_length
= strlen (input_basename
);
5074 p
= input_basename
+ basename_length
;
5075 while (p
!= input_basename
&& *p
!= '.') --p
;
5076 if (*p
== '.' && p
!= input_basename
)
5078 basename_length
= p
- input_basename
;
5079 input_suffix
= p
+ 1;
5085 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
5087 len
+= strlen (cp
->spec
[j
]);
5090 char *p1
= (char *) xmalloc (len
+ 1);
5093 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
5096 strcpy (p1
+ len
, cp
->spec
[j
]);
5097 len
+= strlen (cp
->spec
[j
]);
5100 value
= do_spec (p1
);
5104 this_file_error
= 1;
5107 /* If this file's name does not contain a recognized suffix,
5108 record it as explicit linker input. */
5111 explicit_link_files
[i
] = 1;
5113 /* Clear the delete-on-failure queue, deleting the files in it
5114 if this compilation failed. */
5116 if (this_file_error
)
5118 delete_failure_queue ();
5121 /* If this compilation succeeded, don't delete those files later. */
5122 clear_failure_queue ();
5125 if (error_count
== 0)
5127 /* Make sure INPUT_FILE_NUMBER points to first available open
5129 input_file_number
= n_infiles
;
5130 if (lang_specific_pre_link ())
5134 /* Run ld to link all the compiler output files. */
5136 if (error_count
== 0)
5138 int tmp
= execution_count
;
5140 /* We'll use ld if we can't find collect2. */
5141 if (! strcmp (linker_name_spec
, "collect2"))
5143 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
);
5145 linker_name_spec
= "ld";
5147 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5149 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
5150 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
5152 value
= do_spec (link_command_spec
);
5155 linker_was_run
= (tmp
!= execution_count
);
5158 /* Warn if a -B option was specified but the prefix was never used. */
5159 unused_prefix_warnings (&exec_prefixes
);
5160 unused_prefix_warnings (&startfile_prefixes
);
5162 /* If options said don't run linker,
5163 complain about input files to be given to the linker. */
5165 if (! linker_was_run
&& error_count
== 0)
5166 for (i
= 0; (int)i
< n_infiles
; i
++)
5167 if (explicit_link_files
[i
])
5168 error ("%s: linker input file unused since linking not done",
5171 /* Delete some or all of the temporary files we made. */
5174 delete_failure_queue ();
5175 delete_temp_files ();
5177 if (print_help_list
)
5179 printf ("\nFor bug reporting instructions, please see:\n");
5180 printf ("<URL:http://gcc.gnu.org/faq.html#bugreport>\n");
5183 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
5188 /* Find the proper compilation spec for the file name NAME,
5189 whose length is LENGTH. LANGUAGE is the specified language,
5190 or 0 if this file is to be passed to the linker. */
5192 static struct compiler
*
5193 lookup_compiler (name
, length
, language
)
5196 const char *language
;
5198 struct compiler
*cp
;
5200 /* If this was specified by the user to be a linker input, indicate that. */
5201 if (language
!= 0 && language
[0] == '*')
5204 /* Otherwise, look for the language, if one is spec'd. */
5207 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
5208 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
5211 error ("language %s not recognized", language
);
5215 /* Look for a suffix. */
5216 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
5218 if (/* The suffix `-' matches only the file name `-'. */
5219 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
5220 || (strlen (cp
->suffix
) < length
5221 /* See if the suffix matches the end of NAME. */
5223 && ((!strcmp (cp
->suffix
,
5224 name
+ length
- strlen (cp
->suffix
))
5225 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5226 && !strcasecmp (cp
->suffix
,
5227 name
+ length
- strlen (cp
->suffix
)))
5229 && !strcmp (cp
->suffix
,
5230 name
+ length
- strlen (cp
->suffix
))
5234 if (cp
->spec
[0][0] == '@')
5236 struct compiler
*new;
5238 /* An alias entry maps a suffix to a language.
5239 Search for the language; pass 0 for NAME and LENGTH
5240 to avoid infinite recursion if language not found.
5241 Construct the new compiler spec. */
5242 language
= cp
->spec
[0] + 1;
5243 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
5244 new->suffix
= cp
->suffix
;
5245 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
5246 (char *) new->spec
, sizeof new->spec
);
5250 /* A non-alias entry: return it. */
5262 register PTR value
= (PTR
) malloc (size
);
5264 fatal ("virtual memory exhausted");
5269 xrealloc (old
, size
)
5275 ptr
= (PTR
) realloc (old
, size
);
5277 ptr
= (PTR
) malloc (size
);
5279 fatal ("virtual memory exhausted");
5284 save_string (s
, len
)
5288 register char *result
= xmalloc (len
+ 1);
5290 bcopy (s
, result
, len
);
5296 pfatal_with_name (name
)
5299 perror_with_name (name
);
5300 delete_temp_files ();
5305 perror_with_name (name
)
5308 error ("%s: %s", name
, xstrerror (errno
));
5312 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
5313 const char *errmsg_fmt
;
5314 const char *errmsg_arg
;
5318 int save_errno
= errno
;
5320 /* Space for trailing '\0' is in %s. */
5321 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
5322 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
5328 pfatal_with_name (errmsg_fmt
);
5331 /* More 'friendly' abort that prints the line and file.
5332 config.h can #define abort fancy_abort if you like that sort of thing. */
5337 fatal ("Internal gcc abort.");
5340 /* Output an error message and exit */
5343 fatal
VPROTO((const char *msgid
, ...))
5345 #ifndef ANSI_PROTOTYPES
5350 VA_START (ap
, msgid
);
5352 #ifndef ANSI_PROTOTYPES
5353 msgid
= va_arg (ap
, const char *);
5356 fprintf (stderr
, "%s: ", programname
);
5357 vfprintf (stderr
, _(msgid
), ap
);
5359 fprintf (stderr
, "\n");
5360 delete_temp_files ();
5365 error
VPROTO((const char *msgid
, ...))
5367 #ifndef ANSI_PROTOTYPES
5372 VA_START (ap
, msgid
);
5374 #ifndef ANSI_PROTOTYPES
5375 msgid
= va_arg (ap
, const char *);
5378 fprintf (stderr
, "%s: ", programname
);
5379 vfprintf (stderr
, _(msgid
), ap
);
5382 fprintf (stderr
, "\n");
5386 notice
VPROTO((const char *msgid
, ...))
5388 #ifndef ANSI_PROTOTYPES
5393 VA_START (ap
, msgid
);
5395 #ifndef ANSI_PROTOTYPES
5396 msgid
= va_arg (ap
, const char *);
5399 vfprintf (stderr
, _(msgid
), ap
);
5405 validate_all_switches ()
5407 struct compiler
*comp
;
5408 register const char *p
;
5410 struct spec_list
*spec
;
5412 for (comp
= compilers
; comp
->spec
[0]; comp
++)
5415 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
5419 if (c
== '%' && *p
== '{')
5420 /* We have a switch spec. */
5421 validate_switches (p
+ 1);
5425 /* look through the linked list of specs read from the specs file */
5426 for (spec
= specs
; spec
; spec
= spec
->next
)
5428 p
= *(spec
->ptr_spec
);
5430 if (c
== '%' && *p
== '{')
5431 /* We have a switch spec. */
5432 validate_switches (p
+ 1);
5435 p
= link_command_spec
;
5437 if (c
== '%' && *p
== '{')
5438 /* We have a switch spec. */
5439 validate_switches (p
+ 1);
5442 /* Look at the switch-name that comes after START
5443 and mark as valid all supplied switches that match it. */
5446 validate_switches (start
)
5449 register const char *p
= start
;
5464 while (*p
!= ':' && *p
!= '}') p
++;
5468 else if (p
[-1] == '*')
5470 /* Mark all matching switches as valid. */
5472 for (i
= 0; i
< n_switches
; i
++)
5473 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
5474 switches
[i
].validated
= 1;
5478 /* Mark an exact matching switch as valid. */
5479 for (i
= 0; i
< n_switches
; i
++)
5481 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5482 && switches
[i
].part1
[p
- filter
] == 0)
5483 switches
[i
].validated
= 1;
5488 /* Check whether a particular argument was used. The first time we
5489 canonicalize the switches to keep only the ones we care about. */
5503 static struct mswitchstr
*mswitches
;
5504 static int n_mswitches
;
5509 struct mswitchstr
*matches
;
5513 /* Break multilib_matches into the component strings of string and replacement
5515 for (q
= multilib_matches
; *q
!= '\0'; q
++)
5519 matches
= (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
5521 q
= multilib_matches
;
5532 matches
[i
].len
= q
- matches
[i
].str
;
5534 matches
[i
].replace
= ++q
;
5535 while (*q
!= ';' && *q
!= '\0')
5541 matches
[i
].rep_len
= q
- matches
[i
].replace
;
5549 /* Now build a list of the replacement string for switches that we care
5550 about. Make sure we allocate at least one entry. This prevents
5551 xmalloc from calling fatal, and prevents us from re-executing this
5554 = (struct mswitchstr
*) xmalloc ((sizeof (struct mswitchstr
))
5555 * (n_switches
? n_switches
: 1));
5556 for (i
= 0; i
< n_switches
; i
++)
5558 int xlen
= strlen (switches
[i
].part1
);
5559 for (j
= 0; j
< cnt
; j
++)
5560 if (xlen
== matches
[j
].len
&& ! strcmp (switches
[i
].part1
, matches
[j
].str
))
5562 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
5563 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
5564 mswitches
[n_mswitches
].replace
= (char *)0;
5565 mswitches
[n_mswitches
].rep_len
= 0;
5572 for (i
= 0; i
< n_mswitches
; i
++)
5573 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
5580 default_arg (p
, len
)
5586 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+1)
5588 while (*start
== ' ' || *start
== '\t')
5594 for (end
= start
+1; *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
5597 if ((end
- start
) == len
&& strncmp (p
, start
, len
) == 0)
5607 /* Work out the subdirectory to use based on the
5608 options. The format of multilib_select is a list of elements.
5609 Each element is a subdirectory name followed by a list of options
5610 followed by a semicolon. gcc will consider each line in turn. If
5611 none of the options beginning with an exclamation point are
5612 present, and all of the other options are present, that
5613 subdirectory will be used. */
5618 char *p
= multilib_select
;
5620 char *this_path
, *this_arg
;
5626 /* Ignore newlines. */
5633 /* Get the initial path. */
5641 this_path_len
= p
- this_path
;
5643 /* Check the arguments. */
5658 while (*p
!= ' ' && *p
!= ';')
5665 if (*this_arg
!= '!')
5673 /* If this is a default argument, we can just ignore it.
5674 This is true even if this_arg begins with '!'. Beginning
5675 with '!' does not mean that this argument is necessarily
5676 inappropriate for this library: it merely means that
5677 there is a more specific library which uses this
5678 argument. If this argument is a default, we need not
5679 consider that more specific library. */
5680 if (! default_arg (this_arg
, p
- this_arg
))
5682 ok
= used_arg (this_arg
, p
- this_arg
);
5693 if (this_path_len
!= 1
5694 || this_path
[0] != '.')
5696 char * new_multilib_dir
= xmalloc (this_path_len
+ 1);
5697 strncpy (new_multilib_dir
, this_path
, this_path_len
);
5698 new_multilib_dir
[this_path_len
] = '\0';
5699 multilib_dir
= new_multilib_dir
;
5708 /* Print out the multiple library subdirectory selection
5709 information. This prints out a series of lines. Each line looks
5710 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5711 required. Only the desired options are printed out, the negative
5712 matches. The options are print without a leading dash. There are
5713 no spaces to make it easy to use the information in the shell.
5714 Each subdirectory is printed only once. This assumes the ordering
5715 generated by the genmultilib script. */
5718 print_multilib_info ()
5720 char *p
= multilib_select
;
5721 char *last_path
= 0, *this_path
;
5723 int last_path_len
= 0;
5727 /* Ignore newlines. */
5734 /* Get the initial path. */
5743 /* If this is a duplicate, skip it. */
5744 skip
= (last_path
!= 0 && p
- this_path
== last_path_len
5745 && ! strncmp (last_path
, this_path
, last_path_len
));
5747 last_path
= this_path
;
5748 last_path_len
= p
- this_path
;
5750 /* If this directory requires any default arguments, we can skip
5751 it. We will already have printed a directory identical to
5752 this one which does not require that default argument. */
5770 while (*q
!= ' ' && *q
!= ';')
5778 && default_arg (arg
, q
- arg
))
5793 for (p1
= last_path
; p1
< p
; p1
++)
5812 use_arg
= *p
!= '!';
5817 while (*p
!= ' ' && *p
!= ';')
5832 /* If there are extra options, print them now */
5833 if (multilib_extra
&& *multilib_extra
)
5835 int print_at
= TRUE
;
5838 for (q
= multilib_extra
; *q
!= '\0'; q
++)