1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92-97, 1998 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". */
42 /* ??? Need to find a GCC header to put these in. */
43 extern int pexecute
PROTO ((const char *, char * const *, const char *,
44 const char *, char **, char **, int));
45 extern int pwait
PROTO ((int, int *, int));
46 extern char *update_path
PROTO((char *, char *));
47 extern void set_std_prefix
PROTO((char *, int));
48 /* Flag arguments to pexecute. */
49 #define PEXECUTE_FIRST 1
50 #define PEXECUTE_LAST 2
51 #define PEXECUTE_SEARCH 4
52 #define PEXECUTE_VERBOSE 8
55 #define exit __posix_exit
58 /* By default there is no special suffix for executables. */
59 #ifdef EXECUTABLE_SUFFIX
60 #define HAVE_EXECUTABLE_SUFFIX
62 #define EXECUTABLE_SUFFIX ""
65 /* By default, the suffix for object files is ".o". */
67 #define HAVE_OBJECT_SUFFIX
69 #define OBJECT_SUFFIX ".o"
72 /* By default, colon separates directories in a path. */
73 #ifndef PATH_SEPARATOR
74 #define PATH_SEPARATOR ':'
78 #define DIR_SEPARATOR '/'
81 static char dir_separator_str
[] = {DIR_SEPARATOR
, 0};
83 #define obstack_chunk_alloc xmalloc
84 #define obstack_chunk_free free
86 #ifndef GET_ENV_PATH_LIST
87 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
90 extern char *my_strerror
PROTO((int));
93 #define kill(p,s) raise(s)
96 /* If a stage of compilation returns an exit status >= 1,
97 compilation of that file ceases. */
99 #define MIN_FATAL_STATUS 1
101 /* Flag saying to print the directories gcc will search through looking for
102 programs, libraries, etc. */
104 static int print_search_dirs
;
106 /* Flag saying to print the full filename of this file
107 as found through our usual search mechanism. */
109 static char *print_file_name
= NULL
;
111 /* As print_file_name, but search for executable file. */
113 static char *print_prog_name
= NULL
;
115 /* Flag saying to print the relative path we'd use to
116 find libgcc.a given the current compiler flags. */
118 static int print_multi_directory
;
120 /* Flag saying to print the list of subdirectories and
121 compiler flags used to select them in a standard form. */
123 static int print_multi_lib
;
125 /* Flag saying to print the command line options understood by gcc and its
128 static int print_help_list
;
130 /* Flag indicating whether we should print the command and arguments */
132 static int verbose_flag
;
134 /* Nonzero means write "temp" files in source directory
135 and use the source file's name in them, and don't delete them. */
137 static int save_temps_flag
;
139 /* The compiler version. */
141 static char *compiler_version
;
143 /* The target version specified with -V */
145 static char *spec_version
= DEFAULT_TARGET_VERSION
;
147 /* The target machine specified with -b. */
149 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
151 /* Nonzero if cross-compiling.
152 When -b is used, the value comes from the `specs' file. */
155 static char *cross_compile
= "1";
157 static char *cross_compile
= "0";
160 /* The number of errors that have occurred; the link phase will not be
161 run if this is non-zero. */
162 static int error_count
= 0;
164 /* This is the obstack which we use to allocate many strings. */
166 static struct obstack obstack
;
168 /* This is the obstack to build an environment variable to pass to
169 collect2 that describes all of the relevant switches of what to
170 pass the compiler in building the list of pointers to constructors
173 static struct obstack collect_obstack
;
175 extern char *version_string
;
177 /* Forward declaration for prototypes. */
180 static void init_spec
PROTO((void));
181 static void read_specs
PROTO((char *, int));
182 static void set_spec
PROTO((char *, char *));
183 static struct compiler
*lookup_compiler
PROTO((char *, size_t, char *));
184 static char *build_search_list
PROTO((struct path_prefix
*, char *, int));
185 static void putenv_from_prefixes
PROTO((struct path_prefix
*, char *));
186 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
187 static void add_prefix
PROTO((struct path_prefix
*, char *, char *,
189 static char *skip_whitespace
PROTO((char *));
190 static void record_temp_file
PROTO((char *, int, int));
191 static void delete_if_ordinary
PROTO((char *));
192 static void delete_temp_files
PROTO((void));
193 static void delete_failure_queue
PROTO((void));
194 static void clear_failure_queue
PROTO((void));
195 static int check_live_switch
PROTO((int, int));
196 static char *handle_braces
PROTO((char *));
197 static char *save_string
PROTO((char *, int));
198 static char *concat
PVPROTO((char *, ...));
199 extern int do_spec
PROTO((char *));
200 static int do_spec_1
PROTO((char *, int, char *));
201 static char *find_file
PROTO((char *));
202 static int is_directory
PROTO((char *, char *, int));
203 static void validate_switches
PROTO((char *));
204 static void validate_all_switches
PROTO((void));
205 static void give_switch
PROTO((int, int, int));
206 static int used_arg
PROTO((char *, int));
207 static int default_arg
PROTO((char *, int));
208 static void set_multilib_dir
PROTO((void));
209 static void print_multilib_info
PROTO((void));
210 static void pfatal_with_name
PROTO((char *)) ATTRIBUTE_NORETURN
;
211 static void perror_with_name
PROTO((char *));
212 static void pfatal_pexecute
PROTO((char *, char *)) ATTRIBUTE_NORETURN
;
213 static void fatal
PVPROTO((char *, ...)) ATTRIBUTE_NORETURN
;
214 static void error
PVPROTO((char *, ...));
215 static void display_help
PROTO((void));
217 void fancy_abort
PROTO((void)) ATTRIBUTE_NORETURN
;
221 #ifdef LANG_SPECIFIC_DRIVER
222 /* Called before processing to change/add/remove arguments. */
223 extern void lang_specific_driver
PROTO ((void (*) PVPROTO((char *, ...)), int *, char ***, int *));
225 /* Called before linking. Returns 0 on success and -1 on failure. */
226 extern int lang_specific_pre_link ();
228 /* Number of extra output files that lang_specific_pre_link may generate. */
229 extern int lang_specific_extra_outfiles
;
232 /* Specs are strings containing lines, each of which (if not blank)
233 is made up of a program name, and arguments separated by spaces.
234 The program name must be exact and start from root, since no path
235 is searched and it is unreliable to depend on the current working directory.
236 Redirection of input or output is not supported; the subprograms must
237 accept filenames saying what files to read and write.
239 In addition, the specs can contain %-sequences to substitute variable text
240 or for conditional text. Here is a table of all defined %-sequences.
241 Note that spaces are not generated automatically around the results of
242 expanding these sequences; therefore, you can concatenate them together
243 or with constant text in a single argument.
245 %% substitute one % into the program name or argument.
246 %i substitute the name of the input file being processed.
247 %b substitute the basename of the input file being processed.
248 This is the substring up to (and not including) the last period
249 and not including the directory.
251 substitute a file name that has suffix SUFFIX and is chosen
252 once per compilation, and mark the argument a la %d. To reduce
253 exposure to denial-of-service attacks, the file name is now
254 chosen in a way that is hard to predict even when previously
255 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
256 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
257 the regexp "[.A-Za-z]*" or the special string "%O", which is
258 treated exactly as if %O had been pre-processed. Previously, %g
259 was simply substituted with a file name chosen once per compilation,
260 without regard to any appended suffix (which was therefore treated
261 just like ordinary text), making such attacks more likely to succeed.
263 like %g, but generates a new temporary file name even if %uSUFFIX
266 substitutes the last file name generated with %uSUFFIX, generating a
267 new one if there is no such last file name. In the absence of any
268 %uSUFFIX, this is just like %gSUFFIX, except they don't share
269 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
270 would involve the generation of two distinct file names, one
271 for each `%g.s' and another for each `%U.s'. Previously, %U was
272 simply substituted with a file name chosen for the previous %u,
273 without regard to any appended suffix.
274 %d marks the argument containing or following the %d as a
275 temporary file name, so that that file will be deleted if CC exits
276 successfully. Unlike %g, this contributes no text to the argument.
277 %w marks the argument containing or following the %w as the
278 "output file" of this compilation. This puts the argument
279 into the sequence of arguments that %o will substitute later.
281 like %{...} but mark last argument supplied within
282 as a file to be deleted on failure.
283 %o substitutes the names of all the output files, with spaces
284 automatically placed around them. You should write spaces
285 around the %o as well or the results are undefined.
286 %o is for use in the specs for running the linker.
287 Input files whose names have no recognized suffix are not compiled
288 at all, but they are included among the output files, so they will
290 %O substitutes the suffix for object files. Note that this is
291 handled specially when it immediately follows %g, %u, or %U,
292 because of the need for those to form complete file names. The
293 handling is such that %O is treated exactly as if it had already
294 been substituted, except that %g, %u, and %U do not currently
295 support additional SUFFIX characters following %O as they would
296 following, for example, `.o'.
297 %p substitutes the standard macro predefinitions for the
298 current target machine. Use this when running cpp.
299 %P like %p, but puts `__' before and after the name of each macro.
300 (Except macros that already have __.)
302 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
303 %s current argument is the name of a library or startup file of some sort.
304 Search for that file in a standard list of directories
305 and substitute the full name found.
306 %eSTR Print STR as an error message. STR is terminated by a newline.
307 Use this when inconsistent options are detected.
308 %x{OPTION} Accumulate an option for %X.
309 %X Output the accumulated linker options specified by compilations.
310 %Y Output the accumulated assembler options specified by compilations.
311 %Z Output the accumulated preprocessor options specified by compilations.
312 %v1 Substitute the major version number of GCC.
313 (For version 2.5.n, this is 2.)
314 %v2 Substitute the minor version number of GCC.
315 (For version 2.5.n, this is 5.)
316 %a process ASM_SPEC as a spec.
317 This allows config.h to specify part of the spec for running as.
318 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
319 used here. This can be used to run a post-processor after the
320 assembler has done its job.
321 %D Dump out a -L option for each directory in startfile_prefixes.
322 If multilib_dir is set, extra entries are generated with it affixed.
323 %l process LINK_SPEC as a spec.
324 %L process LIB_SPEC as a spec.
325 %G process LIBGCC_SPEC as a spec.
326 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
327 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
328 %c process SIGNED_CHAR_SPEC as a spec.
329 %C process CPP_SPEC as a spec. A capital C is actually used here.
330 %1 process CC1_SPEC as a spec.
331 %2 process CC1PLUS_SPEC as a spec.
332 %| output "-" if the input for the current command is coming from a pipe.
333 %* substitute the variable part of a matched option. (See below.)
334 Note that each comma in the substituted string is replaced by
336 %{S} substitutes the -S switch, if that switch was given to CC.
337 If that switch was not specified, this substitutes nothing.
338 Here S is a metasyntactic variable.
339 %{S*} substitutes all the switches specified to CC whose names start
340 with -S. This is used for -o, -D, -I, etc; switches that take
341 arguments. CC considers `-o foo' as being one switch whose
342 name starts with `o'. %{o*} would substitute this text,
343 including the space; thus, two arguments would be generated.
344 %{^S*} likewise, but don't put a blank between a switch and any args.
345 %{S*:X} substitutes X if one or more switches whose names start with -S are
346 specified to CC. Note that the tail part of the -S option
347 (i.e. the part matched by the `*') will be substituted for each
348 occurrence of %* within X.
349 %{S:X} substitutes X, but only if the -S switch was given to CC.
350 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
351 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
352 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
353 %{.S:X} substitutes X, but only if processing a file with suffix S.
354 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
355 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
356 combined with ! and . as above binding stronger than the OR.
357 %(Spec) processes a specification defined in a specs file as *Spec:
358 %[Spec] as above, but put __ around -D arguments
360 The conditional text X in a %{S:X} or %{!S:X} construct may contain
361 other nested % constructs or spaces, or even newlines. They are
362 processed as usual, as described above.
364 The -O, -f, -m, and -W switches are handled specifically in these
365 constructs. If another value of -O or the negated form of a -f, -m, or
366 -W switch is found later in the command line, the earlier switch
367 value is ignored, except with {S*} where S is just one letter; this
368 passes all matching options.
370 The character | at the beginning of the predicate text is used to indicate
371 that a command should be piped to the following command, but only if -pipe
374 Note that it is built into CC which switches take arguments and which
375 do not. You might think it would be useful to generalize this to
376 allow each compiler's spec to say which switches take arguments. But
377 this cannot be done in a consistent fashion. CC cannot even decide
378 which input files have been specified without knowing which switches
379 take arguments, and it must know which input files to compile in order
380 to tell which compilers to run.
382 CC also knows implicitly that arguments starting in `-l' are to be
383 treated as compiler output files, and passed to the linker in their
384 proper position among the other output files. */
386 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
388 /* config.h can define ASM_SPEC to provide extra args to the assembler
389 or extra switch-translations. */
394 /* config.h can define ASM_FINAL_SPEC to run a post processor after
395 the assembler has run. */
396 #ifndef ASM_FINAL_SPEC
397 #define ASM_FINAL_SPEC ""
400 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
401 or extra switch-translations. */
406 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
407 or extra switch-translations. */
412 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
413 or extra switch-translations. */
415 #define CC1PLUS_SPEC ""
418 /* config.h can define LINK_SPEC to provide extra args to the linker
419 or extra switch-translations. */
424 /* config.h can define LIB_SPEC to override the default libraries. */
426 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
429 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
432 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
433 /* Have gcc do the search for libgcc.a. */
434 #define LIBGCC_SPEC "libgcc.a%s"
436 #define LIBGCC_SPEC "-lgcc"
440 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
441 #ifndef STARTFILE_SPEC
442 #define STARTFILE_SPEC \
443 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
446 /* config.h can define SWITCHES_NEED_SPACES to control which options
447 require spaces between the option and the argument. */
448 #ifndef SWITCHES_NEED_SPACES
449 #define SWITCHES_NEED_SPACES ""
452 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
454 #define ENDFILE_SPEC ""
457 /* This spec is used for telling cpp whether char is signed or not. */
458 #ifndef SIGNED_CHAR_SPEC
459 /* Use #if rather than ?:
460 because MIPS C compiler rejects like ?: in initializers. */
461 #if DEFAULT_SIGNED_CHAR
462 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
464 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
469 #define LINKER_NAME "collect2"
472 static char *cpp_spec
= CPP_SPEC
;
473 static char *cpp_predefines
= CPP_PREDEFINES
;
474 static char *cc1_spec
= CC1_SPEC
;
475 static char *cc1plus_spec
= CC1PLUS_SPEC
;
476 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
477 static char *asm_spec
= ASM_SPEC
;
478 static char *asm_final_spec
= ASM_FINAL_SPEC
;
479 static char *link_spec
= LINK_SPEC
;
480 static char *lib_spec
= LIB_SPEC
;
481 static char *libgcc_spec
= LIBGCC_SPEC
;
482 static char *endfile_spec
= ENDFILE_SPEC
;
483 static char *startfile_spec
= STARTFILE_SPEC
;
484 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
485 static char *linker_name_spec
= LINKER_NAME
;
487 /* Some compilers have limits on line lengths, and the multilib_select
488 and/or multilib_matches strings can be very long, so we build them at
490 static struct obstack multilib_obstack
;
491 static char *multilib_select
;
492 static char *multilib_matches
;
493 static char *multilib_defaults
;
494 #include "multilib.h"
496 /* Check whether a particular argument is a default argument. */
498 #ifndef MULTILIB_DEFAULTS
499 #define MULTILIB_DEFAULTS { "" }
502 static char *multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
505 struct user_specs
*next
;
509 static struct user_specs
*user_specs_head
, *user_specs_tail
;
511 /* This defines which switch letters take arguments. */
513 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
514 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
515 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
516 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
517 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
518 || (CHAR) == 'B' || (CHAR) == 'b')
520 #ifndef SWITCH_TAKES_ARG
521 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
524 /* This defines which multi-letter switches take arguments. */
526 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
527 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
528 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
529 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
530 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
531 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
532 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
534 #ifndef WORD_SWITCH_TAKES_ARG
535 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
539 #ifdef HAVE_EXECUTABLE_SUFFIX
540 /* This defines which switches stop a full compilation. */
541 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
542 ((CHAR) == 'c' || (CHAR) == 'S')
544 #ifndef SWITCH_CURTAILS_COMPILATION
545 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
546 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
550 /* Record the mapping from file suffixes for compilation specs. */
554 char *suffix
; /* Use this compiler for input files
555 whose names end in this suffix. */
557 char *spec
[4]; /* To use this compiler, concatenate these
558 specs and pass to do_spec. */
561 /* Pointer to a vector of `struct compiler' that gives the spec for
562 compiling a file, based on its suffix.
563 A file that does not end in any of these suffixes will be passed
564 unchanged to the loader and nothing else will be done to it.
566 An entry containing two 0s is used to terminate the vector.
568 If multiple entries match a file, the last matching one is used. */
570 static struct compiler
*compilers
;
572 /* Number of entries in `compilers', not counting the null terminator. */
574 static int n_compilers
;
576 /* The default list of file name suffixes and their compilation specs. */
578 static struct compiler default_compilers
[] =
580 /* Add lists of suffixes of known languages here. If those languages
581 were not present when we built the driver, we will hit these copies
582 and be given a more meaningful error than "file not used since
583 linking is not done". */
584 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}}, {".c++", {"#C++"}},
585 {".C", {"#C++"}}, {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
586 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
587 {".fpp", {"#Fortran"}},
588 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
589 /* Next come the entries for C. */
594 "%{E|M|MM:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
595 %{C:%{!E:%eGNU C does not support -C without using -E}}\
596 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
597 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
598 %{ansi:-trigraphs -D__STRICT_ANSI__}\
599 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
600 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
601 %{traditional} %{ftraditional:-traditional}\
602 %{traditional-cpp:-traditional}\
603 %{fleading-underscore} %{fno-leading-underscore}\
604 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
605 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
606 %{!E:%{!M:%{!MM:cc1 %i %1 \
607 -lang-c%{ansi:89} %{nostdinc*} %{A*} %{I*} %I\
608 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
609 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
610 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
611 %{ansi:-trigraphs -D__STRICT_ANSI__}\
612 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
613 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
614 %{H} %C %{D*} %{U*} %{i*} %Z\
615 %{ftraditional:-traditional}\
616 %{traditional-cpp:-traditional}\
617 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
620 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
621 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
622 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
624 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
625 %{!pipe:%g.s} %A\n }}}}"
627 #else /* ! USE_CPPLIB */
628 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
629 %{C:%{!E:%eGNU C does not support -C without using -E}}\
630 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
631 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
632 %{ansi:-trigraphs -D__STRICT_ANSI__}\
633 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
634 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
635 %{traditional} %{ftraditional:-traditional}\
636 %{traditional-cpp:-traditional}\
637 %{fleading-underscore} %{fno-leading-underscore}\
638 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
639 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
640 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
641 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
642 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
643 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
646 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
647 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
649 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
650 %{!pipe:%g.s} %A\n }}}}"
652 #endif /* ! USE_CPPLIB */
654 {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
655 %{C:%{!E:%eGNU C does not support -C without using -E}}\
656 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
657 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
658 %{ansi:-trigraphs -D__STRICT_ANSI__}\
659 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
660 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
661 %{traditional} %{ftraditional:-traditional}\
662 %{traditional-cpp:-traditional}\
663 %{fleading-underscore} %{fno-leading-underscore}\
664 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
666 %{!E:%e-E required when input is from standard input}"}},
667 {".m", {"@objective-c"}},
669 {"cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
670 %{C:%{!E:%eGNU C does not support -C without using -E}}\
671 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
672 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
673 %{ansi:-trigraphs -D__STRICT_ANSI__}\
674 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
675 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
676 %{traditional} %{ftraditional:-traditional}\
677 %{traditional-cpp:-traditional}\
678 %{fleading-underscore} %{fno-leading-underscore}\
679 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
680 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
681 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
682 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
683 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
684 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
685 -lang-objc %{gen-decls} \
687 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
688 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
690 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
691 %{!pipe:%g.s} %A\n }}}}"}},
692 {".h", {"@c-header"}},
694 {"%{!E:%eCompilation of header file requested} \
695 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
696 %{C:%{!E:%eGNU C does not support -C without using -E}}\
697 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
698 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
699 %{ansi:-trigraphs -D__STRICT_ANSI__}\
700 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
701 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
702 %{traditional} %{ftraditional:-traditional}\
703 %{traditional-cpp:-traditional}\
704 %{fleading-underscore} %{fno-leading-underscore}\
705 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
707 {".i", {"@cpp-output"}},
709 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
710 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
711 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
713 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
714 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
716 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
717 %{!pipe:%g.s} %A\n }}}}"}},
718 {".s", {"@assembler"}},
720 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
721 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
723 {".S", {"@assembler-with-cpp"}},
724 {"@assembler-with-cpp",
725 {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
726 %{C:%{!E:%eGNU C does not support -C without using -E}}\
727 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
728 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
729 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
730 %{traditional} %{ftraditional:-traditional}\
731 %{traditional-cpp:-traditional}\
732 %{fleading-underscore} %{fno-leading-underscore}\
733 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
734 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
735 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
736 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
737 %{!pipe:%g.s} %A\n }}}}"}},
739 /* Mark end of table */
743 /* Number of elements in default_compilers, not counting the terminator. */
745 static int n_default_compilers
746 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
748 /* Here is the spec for running the linker, after compiling all files. */
750 /* -u* was put back because both BSD and SysV seem to support it. */
751 /* %{static:} simply prevents an error message if the target machine
752 doesn't handle -static. */
753 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
754 scripts which exist in user specified directories, or in standard
756 #ifdef LINK_COMMAND_SPEC
757 /* Provide option to override link_command_spec from machine specific
758 configuration files. */
759 static char *link_command_spec
=
762 #ifdef LINK_LIBGCC_SPECIAL
763 /* Don't generate -L options. */
764 static char *link_command_spec
= "\
766 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
767 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
768 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
770 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
771 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
776 static char *link_command_spec
= "\
778 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
779 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
780 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
781 %{static:} %{L*} %D %o\
782 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
783 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
789 /* A vector of options to give to the linker.
790 These options are accumulated by %x,
791 and substituted into the linker command with %X. */
792 static int n_linker_options
;
793 static char **linker_options
;
795 /* A vector of options to give to the assembler.
796 These options are accumulated by -Wa,
797 and substituted into the assembler command with %Y. */
798 static int n_assembler_options
;
799 static char **assembler_options
;
801 /* A vector of options to give to the preprocessor.
802 These options are accumulated by -Wp,
803 and substituted into the preprocessor command with %Z. */
804 static int n_preprocessor_options
;
805 static char **preprocessor_options
;
807 /* Define how to map long options into short ones. */
809 /* This structure describes one mapping. */
812 /* The long option's name. */
814 /* The equivalent short option. */
816 /* Argument info. A string of flag chars; NULL equals no options.
817 a => argument required.
818 o => argument optional.
819 j => join argument to equivalent, making one word.
820 * => require other text after NAME as an argument. */
824 /* This is the table of mappings. Mappings are tried sequentially
825 for each option encountered; the first one that matches, wins. */
827 struct option_map option_map
[] =
829 {"--all-warnings", "-Wall", 0},
830 {"--ansi", "-ansi", 0},
831 {"--assemble", "-S", 0},
832 {"--assert", "-A", "a"},
833 {"--classpath", "-fclasspath=", "aj"},
834 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
835 {"--comments", "-C", 0},
836 {"--compile", "-c", 0},
837 {"--debug", "-g", "oj"},
838 {"--define-macro", "-D", "aj"},
839 {"--dependencies", "-M", 0},
840 {"--dump", "-d", "a"},
841 {"--dumpbase", "-dumpbase", "a"},
842 {"--entry", "-e", 0},
843 {"--extra-warnings", "-W", 0},
844 {"--for-assembler", "-Wa", "a"},
845 {"--for-linker", "-Xlinker", "a"},
846 {"--force-link", "-u", "a"},
847 {"--imacros", "-imacros", "a"},
848 {"--include", "-include", "a"},
849 {"--include-barrier", "-I-", 0},
850 {"--include-directory", "-I", "aj"},
851 {"--include-directory-after", "-idirafter", "a"},
852 {"--include-prefix", "-iprefix", "a"},
853 {"--include-with-prefix", "-iwithprefix", "a"},
854 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
855 {"--include-with-prefix-after", "-iwithprefix", "a"},
856 {"--language", "-x", "a"},
857 {"--library-directory", "-L", "a"},
858 {"--machine", "-m", "aj"},
859 {"--machine-", "-m", "*j"},
860 {"--no-line-commands", "-P", 0},
861 {"--no-precompiled-includes", "-noprecomp", 0},
862 {"--no-standard-includes", "-nostdinc", 0},
863 {"--no-standard-libraries", "-nostdlib", 0},
864 {"--no-warnings", "-w", 0},
865 {"--optimize", "-O", "oj"},
866 {"--output", "-o", "a"},
867 {"--pedantic", "-pedantic", 0},
868 {"--pedantic-errors", "-pedantic-errors", 0},
869 {"--pipe", "-pipe", 0},
870 {"--prefix", "-B", "a"},
871 {"--preprocess", "-E", 0},
872 {"--print-search-dirs", "-print-search-dirs", 0},
873 {"--print-file-name", "-print-file-name=", "aj"},
874 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
875 {"--print-missing-file-dependencies", "-MG", 0},
876 {"--print-multi-lib", "-print-multi-lib", 0},
877 {"--print-multi-directory", "-print-multi-directory", 0},
878 {"--print-prog-name", "-print-prog-name=", "aj"},
879 {"--profile", "-p", 0},
880 {"--profile-blocks", "-a", 0},
881 {"--quiet", "-q", 0},
882 {"--save-temps", "-save-temps", 0},
883 {"--shared", "-shared", 0},
884 {"--silent", "-q", 0},
885 {"--specs", "-specs=", "aj"},
886 {"--static", "-static", 0},
887 {"--symbolic", "-symbolic", 0},
888 {"--target", "-b", "a"},
889 {"--trace-includes", "-H", 0},
890 {"--traditional", "-traditional", 0},
891 {"--traditional-cpp", "-traditional-cpp", 0},
892 {"--trigraphs", "-trigraphs", 0},
893 {"--undefine-macro", "-U", "aj"},
894 {"--use-version", "-V", "a"},
895 {"--user-dependencies", "-MM", 0},
896 {"--verbose", "-v", 0},
897 {"--version", "-dumpversion", 0},
898 {"--warn-", "-W", "*j"},
899 {"--write-dependencies", "-MD", 0},
900 {"--write-user-dependencies", "-MMD", 0},
904 /* Translate the options described by *ARGCP and *ARGVP.
905 Make a new vector and store it back in *ARGVP,
906 and store its length in *ARGVC. */
909 translate_options (argcp
, argvp
)
915 char **argv
= *argvp
;
916 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
920 newv
[newindex
++] = argv
[i
++];
924 /* Translate -- options. */
925 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
928 /* Find a mapping that applies to this option. */
929 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
931 size_t optlen
= strlen (option_map
[j
].name
);
932 size_t arglen
= strlen (argv
[i
]);
933 size_t complen
= arglen
> optlen
? optlen
: arglen
;
934 char *arginfo
= option_map
[j
].arg_info
;
939 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
947 k
< sizeof (option_map
) / sizeof (option_map
[0]);
949 if (strlen (option_map
[k
].name
) >= arglen
950 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
952 error ("Ambiguous abbreviation %s", argv
[i
]);
956 if (k
!= sizeof (option_map
) / sizeof (option_map
[0]))
962 /* If the option has an argument, accept that. */
963 if (argv
[i
][optlen
] == '=')
964 arg
= argv
[i
] + optlen
+ 1;
966 /* If this mapping requires extra text at end of name,
967 accept that as "argument". */
968 else if (index (arginfo
, '*') != 0)
969 arg
= argv
[i
] + optlen
;
971 /* Otherwise, extra text at end means mismatch.
972 Try other mappings. */
977 else if (index (arginfo
, '*') != 0)
979 error ("Incomplete `%s' option", option_map
[j
].name
);
983 /* Handle arguments. */
984 if (index (arginfo
, 'a') != 0)
990 error ("Missing argument to `%s' option",
998 else if (index (arginfo
, '*') != 0)
1000 else if (index (arginfo
, 'o') == 0)
1003 error ("Extraneous argument to `%s' option",
1004 option_map
[j
].name
);
1008 /* Store the translation as one argv elt or as two. */
1009 if (arg
!= 0 && index (arginfo
, 'j') != 0)
1010 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
1014 newv
[newindex
++] = option_map
[j
].equivalent
;
1015 newv
[newindex
++] = arg
;
1018 newv
[newindex
++] = option_map
[j
].equivalent
;
1026 /* Handle old-fashioned options--just copy them through,
1027 with their arguments. */
1028 else if (argv
[i
][0] == '-')
1030 char *p
= argv
[i
] + 1;
1034 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1035 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1036 else if (WORD_SWITCH_TAKES_ARG (p
))
1037 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
1038 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
1041 else if (! strcmp (p
, "Xlinker"))
1044 /* Watch out for an option at the end of the command line that
1045 is missing arguments, and avoid skipping past the end of the
1047 if (nskip
+ i
> argc
)
1052 newv
[newindex
++] = argv
[i
++];
1057 /* Ordinary operands, or +e options. */
1058 newv
[newindex
++] = argv
[i
++];
1071 #ifdef HAVE_STRERROR
1077 static char buffer
[30];
1079 return "cannot access";
1081 if (e
> 0 && e
< sys_nerr
)
1082 return sys_errlist
[e
];
1084 sprintf (buffer
, "Unknown error %d", e
);
1095 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1096 be considered whitespace. */
1097 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1099 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1103 while (*p
!= '\n') p
++;
1113 /* Structure to keep track of the specs that have been defined so far.
1114 These are accessed using %(specname) or %[specname] in a compiler
1119 /* The following 2 fields must be first */
1120 /* to allow EXTRA_SPECS to be initialized */
1121 char *name
; /* name of the spec. */
1122 char *ptr
; /* available ptr if no static pointer */
1124 /* The following fields are not initialized */
1125 /* by EXTRA_SPECS */
1126 char **ptr_spec
; /* pointer to the spec itself. */
1127 struct spec_list
*next
; /* Next spec in linked list. */
1128 int name_len
; /* length of the name */
1129 int alloc_p
; /* whether string was allocated */
1132 #define INIT_STATIC_SPEC(NAME,PTR) \
1133 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1135 /* List of statically defined specs */
1136 static struct spec_list static_specs
[] = {
1137 INIT_STATIC_SPEC ("asm", &asm_spec
),
1138 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1139 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1140 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1141 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1142 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1143 INIT_STATIC_SPEC ("link", &link_spec
),
1144 INIT_STATIC_SPEC ("lib", &lib_spec
),
1145 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1146 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1147 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces
),
1148 INIT_STATIC_SPEC ("signed_char", &signed_char_spec
),
1149 INIT_STATIC_SPEC ("predefines", &cpp_predefines
),
1150 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1151 INIT_STATIC_SPEC ("version", &compiler_version
),
1152 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1153 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1154 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1155 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1156 INIT_STATIC_SPEC ("linker", &linker_name_spec
),
1159 #ifdef EXTRA_SPECS /* additional specs needed */
1160 /* Structure to keep track of just the first two args of a spec_list.
1161 That is all that the EXTRA_SPECS macro gives us. */
1168 static struct spec_list_1 extra_specs_1
[] = { EXTRA_SPECS
};
1169 static struct spec_list
* extra_specs
= (struct spec_list
*)0;
1172 /* List of dynamically allocates specs that have been defined so far. */
1174 static struct spec_list
*specs
= (struct spec_list
*)0;
1177 /* Initialize the specs lookup routines. */
1182 struct spec_list
*next
= (struct spec_list
*)0;
1183 struct spec_list
*sl
= (struct spec_list
*)0;
1187 return; /* already initialized */
1190 fprintf (stderr
, "Using builtin specs.\n");
1193 extra_specs
= (struct spec_list
*)
1194 xmalloc (sizeof(struct spec_list
) *
1195 (sizeof(extra_specs_1
)/sizeof(extra_specs_1
[0])));
1196 bzero ((PTR
) extra_specs
, sizeof(struct spec_list
) *
1197 (sizeof(extra_specs_1
)/sizeof(extra_specs_1
[0])));
1199 for (i
= (sizeof(extra_specs_1
) / sizeof(extra_specs_1
[0])) - 1; i
>= 0; i
--)
1201 sl
= &extra_specs
[i
];
1202 sl
->name
= extra_specs_1
[i
].name
;
1203 sl
->ptr
= extra_specs_1
[i
].ptr
;
1205 sl
->name_len
= strlen (sl
->name
);
1206 sl
->ptr_spec
= &sl
->ptr
;
1211 for (i
= (sizeof (static_specs
) / sizeof (static_specs
[0])) - 1; i
>= 0; i
--)
1213 sl
= &static_specs
[i
];
1222 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1223 removed; If the spec starts with a + then SPEC is added to the end of the
1227 set_spec (name
, spec
)
1231 struct spec_list
*sl
;
1233 int name_len
= strlen (name
);
1236 /* If this is the first call, initialize the statically allocated specs */
1239 struct spec_list
*next
= (struct spec_list
*)0;
1240 for (i
= (sizeof (static_specs
) / sizeof (static_specs
[0])) - 1;
1243 sl
= &static_specs
[i
];
1250 /* See if the spec already exists */
1251 for (sl
= specs
; sl
; sl
= sl
->next
)
1252 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1257 /* Not found - make it */
1258 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1259 sl
->name
= save_string (name
, strlen (name
));
1260 sl
->name_len
= name_len
;
1261 sl
->ptr_spec
= &sl
->ptr
;
1263 *(sl
->ptr_spec
) = "";
1268 old_spec
= *(sl
->ptr_spec
);
1269 *(sl
->ptr_spec
) = ((spec
[0] == '+' && ISSPACE ((unsigned char)spec
[1]))
1270 ? concat (old_spec
, spec
+ 1, NULL_PTR
)
1271 : save_string (spec
, strlen (spec
)));
1275 fprintf (stderr
, "Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1278 /* Free the old spec */
1279 if (old_spec
&& sl
->alloc_p
)
1285 /* Accumulate a command (program name and args), and run it. */
1287 /* Vector of pointers to arguments in the current line of specifications. */
1289 static char **argbuf
;
1291 /* Number of elements allocated in argbuf. */
1293 static int argbuf_length
;
1295 /* Number of elements in argbuf currently in use (containing args). */
1297 static int argbuf_index
;
1299 /* We want this on by default all the time now. */
1300 #define MKTEMP_EACH_FILE
1302 #ifdef MKTEMP_EACH_FILE
1304 extern char *make_temp_file
PROTO((char *));
1306 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1309 static struct temp_name
{
1310 char *suffix
; /* suffix associated with the code. */
1311 int length
; /* strlen (suffix). */
1312 int unique
; /* Indicates whether %g or %u/%U was used. */
1313 char *filename
; /* associated filename. */
1314 int filename_length
; /* strlen (filename). */
1315 struct temp_name
*next
;
1318 extern char *choose_temp_base
PROTO((void));
1322 /* Number of commands executed so far. */
1324 static int execution_count
;
1326 /* Number of commands that exited with a signal. */
1328 static int signal_count
;
1330 /* Name with which this program was invoked. */
1332 static char *programname
;
1334 /* Structures to keep track of prefixes to try when looking for files. */
1338 char *prefix
; /* String to prepend to the path. */
1339 struct prefix_list
*next
; /* Next in linked list. */
1340 int require_machine_suffix
; /* Don't use without machine_suffix. */
1341 /* 2 means try both machine_suffix and just_machine_suffix. */
1342 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1347 struct prefix_list
*plist
; /* List of prefixes to try */
1348 int max_len
; /* Max length of a prefix in PLIST */
1349 char *name
; /* Name of this list (used in config stuff) */
1352 /* List of prefixes to try when looking for executables. */
1354 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1356 /* List of prefixes to try when looking for startup (crt0) files. */
1358 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1360 /* List of prefixes to try when looking for include files. */
1362 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1364 /* Suffix to attach to directories searched for commands.
1365 This looks like `MACHINE/VERSION/'. */
1367 static char *machine_suffix
= 0;
1369 /* Suffix to attach to directories searched for commands.
1370 This is just `MACHINE/'. */
1372 static char *just_machine_suffix
= 0;
1374 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1376 static char *gcc_exec_prefix
;
1378 /* Default prefixes to attach to command names. */
1380 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1381 #undef MD_EXEC_PREFIX
1382 #undef MD_STARTFILE_PREFIX
1383 #undef MD_STARTFILE_PREFIX_1
1386 #ifndef STANDARD_EXEC_PREFIX
1387 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1388 #endif /* !defined STANDARD_EXEC_PREFIX */
1390 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1391 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1392 #ifdef MD_EXEC_PREFIX
1393 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1396 #ifndef STANDARD_STARTFILE_PREFIX
1397 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1398 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1400 #ifdef MD_STARTFILE_PREFIX
1401 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1403 #ifdef MD_STARTFILE_PREFIX_1
1404 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1406 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1407 static char *standard_startfile_prefix_1
= "/lib/";
1408 static char *standard_startfile_prefix_2
= "/usr/lib/";
1410 #ifndef TOOLDIR_BASE_PREFIX
1411 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1413 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1414 static char *tooldir_prefix
;
1416 /* Subdirectory to use for locating libraries. Set by
1417 set_multilib_dir based on the compilation options. */
1419 static char *multilib_dir
;
1421 /* Clear out the vector of arguments (after a command is executed). */
1429 /* Add one argument to the vector at the end.
1430 This is done when a space is seen or at the end of the line.
1431 If DELETE_ALWAYS is nonzero, the arg is a filename
1432 and the file should be deleted eventually.
1433 If DELETE_FAILURE is nonzero, the arg is a filename
1434 and the file should be deleted if this compilation fails. */
1437 store_arg (arg
, delete_always
, delete_failure
)
1439 int delete_always
, delete_failure
;
1441 if (argbuf_index
+ 1 == argbuf_length
)
1443 = (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1445 argbuf
[argbuf_index
++] = arg
;
1446 argbuf
[argbuf_index
] = 0;
1448 if (delete_always
|| delete_failure
)
1449 record_temp_file (arg
, delete_always
, delete_failure
);
1452 /* Read compilation specs from a file named FILENAME,
1453 replacing the default ones.
1455 A suffix which starts with `*' is a definition for
1456 one of the machine-specific sub-specs. The "suffix" should be
1457 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1458 The corresponding spec is stored in asm_spec, etc.,
1459 rather than in the `compilers' vector.
1461 Anything invalid in the file is a fatal error. */
1464 read_specs (filename
, main_p
)
1470 struct stat statbuf
;
1475 fprintf (stderr
, "Reading specs from %s\n", filename
);
1477 /* Open and stat the file. */
1478 desc
= open (filename
, O_RDONLY
, 0);
1480 pfatal_with_name (filename
);
1481 if (stat (filename
, &statbuf
) < 0)
1482 pfatal_with_name (filename
);
1484 /* Read contents of file into BUFFER. */
1485 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1486 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1488 pfatal_with_name (filename
);
1489 buffer
[readlen
] = 0;
1492 /* Scan BUFFER for specs, putting them in the vector. */
1498 char *in
, *out
, *p1
, *p2
, *p3
;
1500 /* Advance P in BUFFER to the next nonblank nocomment line. */
1501 p
= skip_whitespace (p
);
1505 /* Is this a special command that starts with '%'? */
1506 /* Don't allow this for the main specs file, since it would
1507 encourage people to overwrite it. */
1508 if (*p
== '%' && !main_p
)
1511 while (*p
&& *p
!= '\n')
1514 p
++; /* Skip '\n' */
1516 if (!strncmp (p1
, "%include", sizeof ("%include")-1)
1517 && (p1
[sizeof "%include" - 1] == ' '
1518 || p1
[sizeof "%include" - 1] == '\t'))
1522 p1
+= sizeof ("%include");
1523 while (*p1
== ' ' || *p1
== '\t')
1526 if (*p1
++ != '<' || p
[-2] != '>')
1527 fatal ("specs %%include syntax malformed after %d characters",
1531 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1532 read_specs (new_filename
? new_filename
: p1
, FALSE
);
1535 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
1536 && (p1
[sizeof "%include_noerr" - 1] == ' '
1537 || p1
[sizeof "%include_noerr" - 1] == '\t'))
1541 p1
+= sizeof "%include_noerr";
1542 while (*p1
== ' ' || *p1
== '\t') p1
++;
1544 if (*p1
++ != '<' || p
[-2] != '>')
1545 fatal ("specs %%include syntax malformed after %d characters",
1549 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1551 read_specs (new_filename
, FALSE
);
1552 else if (verbose_flag
)
1553 fprintf (stderr
, "Could not find specs file %s\n", p1
);
1556 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
1557 && (p1
[sizeof "%rename" - 1] == ' '
1558 || p1
[sizeof "%rename" - 1] == '\t'))
1561 struct spec_list
*sl
;
1563 /* Get original name */
1564 p1
+= sizeof "%rename";
1565 while (*p1
== ' ' || *p1
== '\t')
1568 if (! ISALPHA ((unsigned char)*p1
))
1569 fatal ("specs %%rename syntax malformed after %d characters",
1573 while (*p2
&& !ISSPACE ((unsigned char)*p2
))
1576 if (*p2
!= ' ' && *p2
!= '\t')
1577 fatal ("specs %%rename syntax malformed after %d characters",
1582 while (*p2
== ' ' || *p2
== '\t')
1585 if (! ISALPHA ((unsigned char)*p2
))
1586 fatal ("specs %%rename syntax malformed after %d characters",
1589 /* Get new spec name */
1591 while (*p3
&& !ISSPACE ((unsigned char)*p3
))
1595 fatal ("specs %%rename syntax malformed after %d characters",
1599 for (sl
= specs
; sl
; sl
= sl
->next
)
1600 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
1604 fatal ("specs %s spec was not found to be renamed", p1
);
1606 if (strcmp (p1
, p2
) == 0)
1611 fprintf (stderr
, "rename spec %s to %s\n", p1
, p2
);
1613 fprintf (stderr
, "spec is '%s'\n\n", *(sl
->ptr_spec
));
1617 set_spec (p2
, *(sl
->ptr_spec
));
1619 free (*(sl
->ptr_spec
));
1621 *(sl
->ptr_spec
) = "";
1626 fatal ("specs unknown %% command after %d characters",
1630 /* Find the colon that should end the suffix. */
1632 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
1635 /* The colon shouldn't be missing. */
1637 fatal ("specs file malformed after %d characters", p1
- buffer
);
1639 /* Skip back over trailing whitespace. */
1641 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
1644 /* Copy the suffix to a string. */
1645 suffix
= save_string (p
, p2
- p
);
1646 /* Find the next line. */
1647 p
= skip_whitespace (p1
+ 1);
1649 fatal ("specs file malformed after %d characters", p
- buffer
);
1652 /* Find next blank line or end of string. */
1653 while (*p1
&& !(*p1
== '\n' && (p1
[1] == '\n' || p1
[1] == '\0')))
1656 /* Specs end at the blank line and do not include the newline. */
1657 spec
= save_string (p
, p1
- p
);
1660 /* Delete backslash-newline sequences from the spec. */
1665 if (in
[0] == '\\' && in
[1] == '\n')
1667 else if (in
[0] == '#')
1668 while (*in
&& *in
!= '\n')
1676 if (suffix
[0] == '*')
1678 if (! strcmp (suffix
, "*link_command"))
1679 link_command_spec
= spec
;
1681 set_spec (suffix
+ 1, spec
);
1685 /* Add this pair to the vector. */
1687 = ((struct compiler
*)
1688 xrealloc (compilers
,
1689 (n_compilers
+ 2) * sizeof (struct compiler
)));
1691 compilers
[n_compilers
].suffix
= suffix
;
1692 bzero ((char *) compilers
[n_compilers
].spec
,
1693 sizeof compilers
[n_compilers
].spec
);
1694 compilers
[n_compilers
].spec
[0] = spec
;
1696 bzero ((char *) &compilers
[n_compilers
],
1697 sizeof compilers
[n_compilers
]);
1701 link_command_spec
= spec
;
1704 if (link_command_spec
== 0)
1705 fatal ("spec file has no spec for linking");
1708 /* Record the names of temporary files we tell compilers to write,
1709 and delete them at the end of the run. */
1711 /* This is the common prefix we use to make temp file names.
1712 It is chosen once for each run of this program.
1713 It is substituted into a spec by %g.
1714 Thus, all temp file names contain this prefix.
1715 In practice, all temp file names start with this prefix.
1717 This prefix comes from the envvar TMPDIR if it is defined;
1718 otherwise, from the P_tmpdir macro if that is defined;
1719 otherwise, in /usr/tmp or /tmp;
1720 or finally the current directory if all else fails. */
1722 static char *temp_filename
;
1724 /* Length of the prefix. */
1726 static int temp_filename_length
;
1728 /* Define the list of temporary files to delete. */
1733 struct temp_file
*next
;
1736 /* Queue of files to delete on success or failure of compilation. */
1737 static struct temp_file
*always_delete_queue
;
1738 /* Queue of files to delete on failure of compilation. */
1739 static struct temp_file
*failure_delete_queue
;
1741 /* Record FILENAME as a file to be deleted automatically.
1742 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1743 otherwise delete it in any case.
1744 FAIL_DELETE nonzero means delete it if a compilation step fails;
1745 otherwise delete it in any case. */
1748 record_temp_file (filename
, always_delete
, fail_delete
)
1753 register char *name
;
1754 name
= xmalloc (strlen (filename
) + 1);
1755 strcpy (name
, filename
);
1759 register struct temp_file
*temp
;
1760 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1761 if (! strcmp (name
, temp
->name
))
1764 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1765 temp
->next
= always_delete_queue
;
1767 always_delete_queue
= temp
;
1774 register struct temp_file
*temp
;
1775 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1776 if (! strcmp (name
, temp
->name
))
1779 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1780 temp
->next
= failure_delete_queue
;
1782 failure_delete_queue
= temp
;
1788 /* Delete all the temporary files whose names we previously recorded. */
1791 delete_if_ordinary (name
)
1798 printf ("Delete %s? (y or n) ", name
);
1802 while ((c
= getchar ()) != '\n' && c
!= EOF
)
1805 if (i
== 'y' || i
== 'Y')
1807 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1808 if (unlink (name
) < 0)
1810 perror_with_name (name
);
1814 delete_temp_files ()
1816 register struct temp_file
*temp
;
1818 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1819 delete_if_ordinary (temp
->name
);
1820 always_delete_queue
= 0;
1823 /* Delete all the files to be deleted on error. */
1826 delete_failure_queue ()
1828 register struct temp_file
*temp
;
1830 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1831 delete_if_ordinary (temp
->name
);
1835 clear_failure_queue ()
1837 failure_delete_queue
= 0;
1840 /* Routine to add variables to the environment. We do this to pass
1841 the pathname of the gcc driver, and the directories search to the
1842 collect2 program, which is being run as ld. This way, we can be
1843 sure of executing the right compiler when collect2 wants to build
1844 constructors and destructors. Since the environment variables we
1845 use come from an obstack, we don't have to worry about allocating
1854 #ifndef VMS /* nor about VMS */
1856 extern char **environ
;
1857 char **old_environ
= environ
;
1861 int str_len
= strlen (str
);
1865 while ((ch
= *p
++) != '\0' && ch
!= '=')
1871 /* Search for replacing an existing environment variable, and
1872 count the number of total environment variables. */
1873 for (envp
= old_environ
; *envp
; envp
++)
1876 if (!strncmp (str
, *envp
, name_len
))
1883 /* Add a new environment variable */
1884 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1886 memcpy ((char *) (environ
+ 1), (char *) old_environ
,
1887 sizeof (char *) * (num_envs
+1));
1892 #endif /* HAVE_PUTENV */
1895 /* Build a list of search directories from PATHS.
1896 PREFIX is a string to prepend to the list.
1897 If CHECK_DIR_P is non-zero we ensure the directory exists.
1898 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1899 It is also used by the --print-search-dirs flag. */
1902 build_search_list (paths
, prefix
, check_dir_p
)
1903 struct path_prefix
*paths
;
1907 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1909 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1910 int first_time
= TRUE
;
1911 struct prefix_list
*pprefix
;
1913 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
1915 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1917 int len
= strlen (pprefix
->prefix
);
1921 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
1924 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1927 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1928 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1931 if (just_machine_suffix
1932 && pprefix
->require_machine_suffix
== 2
1934 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
1937 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1940 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1941 obstack_grow (&collect_obstack
, just_machine_suffix
,
1945 if (! pprefix
->require_machine_suffix
)
1948 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1951 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1955 obstack_1grow (&collect_obstack
, '\0');
1956 return obstack_finish (&collect_obstack
);
1959 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1963 putenv_from_prefixes (paths
, env_var
)
1964 struct path_prefix
*paths
;
1967 putenv (build_search_list (paths
, env_var
, 1));
1970 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1971 access to check permissions.
1972 Return 0 if not found, otherwise return its name, allocated with malloc. */
1975 find_a_file (pprefix
, name
, mode
)
1976 struct path_prefix
*pprefix
;
1981 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1982 struct prefix_list
*pl
;
1983 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1985 #ifdef DEFAULT_ASSEMBLER
1986 if (! strcmp(name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0) {
1987 name
= DEFAULT_ASSEMBLER
;
1988 len
= strlen(name
)+1;
1989 temp
= xmalloc (len
);
1990 strcpy (temp
, name
);
1995 #ifdef DEFAULT_LINKER
1996 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0) {
1997 name
= DEFAULT_LINKER
;
1998 len
= strlen(name
)+1;
1999 temp
= xmalloc (len
);
2000 strcpy (temp
, name
);
2006 len
+= strlen (machine_suffix
);
2008 temp
= xmalloc (len
);
2010 /* Determine the filename to execute (special case for absolute paths). */
2012 if (*name
== '/' || *name
== DIR_SEPARATOR
2013 /* Check for disk name on MS-DOS-based systems. */
2014 || (DIR_SEPARATOR
== '\\' && name
[1] == ':'
2015 && (name
[2] == DIR_SEPARATOR
|| name
[2] == '/')))
2017 if (access (name
, mode
) == 0)
2019 strcpy (temp
, name
);
2024 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
2028 /* Some systems have a suffix for executable files.
2029 So try appending that first. */
2030 if (file_suffix
[0] != 0)
2032 strcpy (temp
, pl
->prefix
);
2033 strcat (temp
, machine_suffix
);
2034 strcat (temp
, name
);
2035 strcat (temp
, file_suffix
);
2036 if (access (temp
, mode
) == 0)
2038 if (pl
->used_flag_ptr
!= 0)
2039 *pl
->used_flag_ptr
= 1;
2044 /* Now try just the name. */
2045 strcpy (temp
, pl
->prefix
);
2046 strcat (temp
, machine_suffix
);
2047 strcat (temp
, name
);
2048 if (access (temp
, mode
) == 0)
2050 if (pl
->used_flag_ptr
!= 0)
2051 *pl
->used_flag_ptr
= 1;
2056 /* Certain prefixes are tried with just the machine type,
2057 not the version. This is used for finding as, ld, etc. */
2058 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
2060 /* Some systems have a suffix for executable files.
2061 So try appending that first. */
2062 if (file_suffix
[0] != 0)
2064 strcpy (temp
, pl
->prefix
);
2065 strcat (temp
, just_machine_suffix
);
2066 strcat (temp
, name
);
2067 strcat (temp
, file_suffix
);
2068 if (access (temp
, mode
) == 0)
2070 if (pl
->used_flag_ptr
!= 0)
2071 *pl
->used_flag_ptr
= 1;
2076 strcpy (temp
, pl
->prefix
);
2077 strcat (temp
, just_machine_suffix
);
2078 strcat (temp
, name
);
2079 if (access (temp
, mode
) == 0)
2081 if (pl
->used_flag_ptr
!= 0)
2082 *pl
->used_flag_ptr
= 1;
2087 /* Certain prefixes can't be used without the machine suffix
2088 when the machine or version is explicitly specified. */
2089 if (! pl
->require_machine_suffix
)
2091 /* Some systems have a suffix for executable files.
2092 So try appending that first. */
2093 if (file_suffix
[0] != 0)
2095 strcpy (temp
, pl
->prefix
);
2096 strcat (temp
, name
);
2097 strcat (temp
, file_suffix
);
2098 if (access (temp
, mode
) == 0)
2100 if (pl
->used_flag_ptr
!= 0)
2101 *pl
->used_flag_ptr
= 1;
2106 strcpy (temp
, pl
->prefix
);
2107 strcat (temp
, name
);
2108 if (access (temp
, mode
) == 0)
2110 if (pl
->used_flag_ptr
!= 0)
2111 *pl
->used_flag_ptr
= 1;
2121 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2122 at the start of the list, otherwise it goes at the end.
2124 If WARN is nonzero, we will warn if no file is found
2125 through this prefix. WARN should point to an int
2126 which will be set to 1 if this entry is used.
2128 COMPONENT is the value to be passed to update_path.
2130 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2131 the complete value of machine_suffix.
2132 2 means try both machine_suffix and just_machine_suffix. */
2135 add_prefix (pprefix
, prefix
, component
, first
, require_machine_suffix
, warn
)
2136 struct path_prefix
*pprefix
;
2140 int require_machine_suffix
;
2143 struct prefix_list
*pl
, **prev
;
2146 if (! first
&& pprefix
->plist
)
2148 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
2153 prev
= &pprefix
->plist
;
2155 /* Keep track of the longest prefix */
2157 prefix
= update_path (prefix
, component
);
2158 len
= strlen (prefix
);
2159 if (len
> pprefix
->max_len
)
2160 pprefix
->max_len
= len
;
2162 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2163 pl
->prefix
= save_string (prefix
, len
);
2164 pl
->require_machine_suffix
= require_machine_suffix
;
2165 pl
->used_flag_ptr
= warn
;
2172 pl
->next
= (struct prefix_list
*) 0;
2176 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2179 unused_prefix_warnings (pprefix
)
2180 struct path_prefix
*pprefix
;
2182 struct prefix_list
*pl
= pprefix
->plist
;
2186 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
2188 if (pl
->require_machine_suffix
&& machine_suffix
)
2189 error ("file path prefix `%s%s' never used", pl
->prefix
,
2192 error ("file path prefix `%s' never used", pl
->prefix
);
2194 /* Prevent duplicate warnings. */
2195 *pl
->used_flag_ptr
= 1;
2203 /* Execute the command specified by the arguments on the current line of spec.
2204 When using pipes, this includes several piped-together commands
2205 with `|' between them.
2207 Return 0 if successful, -1 if failed. */
2213 int n_commands
; /* # of command. */
2217 char *prog
; /* program name. */
2218 char **argv
; /* vector of args. */
2219 int pid
; /* pid of process for this command. */
2222 struct command
*commands
; /* each command buffer with above info. */
2224 /* Count # of piped commands. */
2225 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2226 if (strcmp (argbuf
[i
], "|") == 0)
2229 /* Get storage for each command. */
2231 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2233 /* Split argbuf into its separate piped processes,
2234 and record info about each one.
2235 Also search for the programs that are to be run. */
2237 commands
[0].prog
= argbuf
[0]; /* first command. */
2238 commands
[0].argv
= &argbuf
[0];
2239 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2242 commands
[0].argv
[0] = string
;
2244 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2245 if (strcmp (argbuf
[i
], "|") == 0)
2246 { /* each command. */
2247 #if defined (__MSDOS__) || (defined (_WIN32) && defined (__CYGWIN__)) || defined (OS2) || defined (VMS)
2248 fatal ("-pipe not supported");
2250 argbuf
[i
] = 0; /* termination of command args. */
2251 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2252 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2253 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2255 commands
[n_commands
].argv
[0] = string
;
2259 argbuf
[argbuf_index
] = 0;
2261 /* If -v, print what we are about to do, and maybe query. */
2265 /* For help listings, put a blank line between sub-processes. */
2266 if (print_help_list
)
2267 fputc ('\n', stderr
);
2269 /* Print each piped command as a separate line. */
2270 for (i
= 0; i
< n_commands
; i
++)
2274 for (j
= commands
[i
].argv
; *j
; j
++)
2275 fprintf (stderr
, " %s", *j
);
2277 /* Print a pipe symbol after all but the last command. */
2278 if (i
+ 1 != n_commands
)
2279 fprintf (stderr
, " |");
2280 fprintf (stderr
, "\n");
2284 fprintf (stderr
, "\nGo ahead? (y or n) ");
2288 while (getchar () != '\n')
2291 if (i
!= 'y' && i
!= 'Y')
2296 /* Run each piped subprocess. */
2298 for (i
= 0; i
< n_commands
; i
++)
2300 char *errmsg_fmt
, *errmsg_arg
;
2301 char *string
= commands
[i
].argv
[0];
2303 commands
[i
].pid
= pexecute (string
, commands
[i
].argv
,
2304 programname
, temp_filename
,
2305 &errmsg_fmt
, &errmsg_arg
,
2306 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2307 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2308 | (string
== commands
[i
].prog
2309 ? PEXECUTE_SEARCH
: 0)
2310 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2312 if (commands
[i
].pid
== -1)
2313 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2315 if (string
!= commands
[i
].prog
)
2321 /* Wait for all the subprocesses to finish.
2322 We don't care what order they finish in;
2323 we know that N_COMMANDS waits will get them all.
2324 Ignore subprocesses that we don't know about,
2325 since they can be spawned by the process that exec'ed us. */
2330 for (i
= 0; i
< n_commands
; )
2336 pid
= pwait (commands
[i
].pid
, &status
, 0);
2340 for (j
= 0; j
< n_commands
; j
++)
2341 if (commands
[j
].pid
== pid
)
2346 if (WIFSIGNALED (status
))
2348 fatal ("Internal compiler error: program %s got fatal signal %d",
2349 commands
[j
].prog
, WTERMSIG (status
));
2353 else if (WIFEXITED (status
)
2354 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2364 /* Find all the switches given to us
2365 and make a vector describing them.
2366 The elements of the vector are strings, one per switch given.
2367 If a switch uses following arguments, then the `part1' field
2368 is the switch itself and the `args' field
2369 is a null-terminated vector containing the following arguments.
2370 The `live_cond' field is 1 if the switch is true in a conditional spec,
2371 -1 if false (overridden by a later switch), and is initialized to zero.
2372 The `valid' field is nonzero if any spec has looked at this switch;
2373 if it remains zero at the end of the run, it must be meaningless. */
2383 static struct switchstr
*switches
;
2385 static int n_switches
;
2393 /* Also a vector of input files specified. */
2395 static struct infile
*infiles
;
2397 static int n_infiles
;
2399 /* This counts the number of libraries added by LANG_SPECIFIC_DRIVER, so that
2400 we can tell if there were any user supplied any files or libraries. */
2402 static int added_libraries
;
2404 /* And a vector of corresponding output files is made up later. */
2406 static char **outfiles
;
2408 /* Used to track if none of the -B paths are used. */
2411 /* Used to track if standard path isn't used and -b or -V is specified. */
2412 static int warn_std
;
2414 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2415 static int *warn_std_ptr
= 0;
2418 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2420 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2421 is true if we should look for an executable suffix as well. */
2424 convert_filename (name
, do_exe
)
2429 int len
= strlen (name
);
2431 #ifdef HAVE_OBJECT_SUFFIX
2432 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2434 && name
[len
- 2] == '.'
2435 && name
[len
- 1] == 'o')
2437 obstack_grow (&obstack
, name
, len
- 2);
2438 obstack_grow0 (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
2439 name
= obstack_finish (&obstack
);
2443 #ifdef HAVE_EXECUTABLE_SUFFIX
2444 /* If there is no filetype, make it the executable suffix (which includes
2445 the "."). But don't get confused if we have just "-o". */
2446 if (! do_exe
|| EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
2449 for (i
= len
- 1; i
>= 0; i
--)
2450 if (name
[i
] == '/' || name
[i
] == DIR_SEPARATOR
)
2453 for (i
++; i
< len
; i
++)
2457 obstack_grow (&obstack
, name
, len
);
2458 obstack_grow0 (&obstack
, EXECUTABLE_SUFFIX
, strlen (EXECUTABLE_SUFFIX
));
2459 name
= obstack_finish (&obstack
);
2466 /* Display the command line switches accepted by gcc. */
2470 printf ("Usage: %s [options] file...\n", programname
);
2471 printf ("Options:\n");
2473 printf (" --help Display this information\n");
2475 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2476 printf (" -dumpspecs Display all of the built in spec strings\n");
2477 printf (" -dumpversion Display the version of the compiler\n");
2478 printf (" -dumpmachine Display the compiler's target processor\n");
2479 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2480 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2481 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2482 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2483 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2484 printf (" -print-multi-lib Display the mapping between command line options and\n");
2485 printf (" multiple library search directories\n");
2486 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2487 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2488 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2489 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2490 printf (" -save-temps Do not delete intermediate files\n");
2491 printf (" -pipe Use pipes rather than intermediate files\n");
2492 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2493 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2494 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2495 printf (" -V <version> Run gcc version number <version>, if installed\n");
2496 printf (" -v Display the programs invoked by the compiler\n");
2497 printf (" -E Preprocess only; do not compile, assemble or link\n");
2498 printf (" -S Compile only; do not assemble or link\n");
2499 printf (" -c Compile and assemble, but do not link\n");
2500 printf (" -o <file> Place the output into <file>\n");
2501 printf (" -x <language> Specify the language of the following input files\n");
2502 printf (" Permissable languages include: c c++ assembler none\n");
2503 printf (" 'none' means revert to the default behaviour of\n");
2504 printf (" guessing the language based on the file's extension\n");
2506 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2507 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2509 printf ("on to these processes the -W<letter> options must be used.\n");
2511 /* The rest of the options are displayed by invocations of the various
2516 add_preprocessor_option (option
, len
)
2520 n_preprocessor_options
++;
2522 if (! preprocessor_options
)
2523 preprocessor_options
2524 = (char **) xmalloc (n_preprocessor_options
* sizeof (char *));
2526 preprocessor_options
2527 = (char **) xrealloc (preprocessor_options
,
2528 n_preprocessor_options
* sizeof (char *));
2530 preprocessor_options
[n_preprocessor_options
- 1] = save_string (option
, len
);
2534 add_assembler_option (option
, len
)
2538 n_assembler_options
++;
2540 if (! assembler_options
)
2542 = (char **) xmalloc (n_assembler_options
* sizeof (char *));
2545 = (char **) xrealloc (assembler_options
,
2546 n_assembler_options
* sizeof (char *));
2548 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
2552 add_linker_option (option
, len
)
2558 if (! linker_options
)
2560 = (char **) xmalloc (n_linker_options
* sizeof (char *));
2563 = (char **) xrealloc (linker_options
,
2564 n_linker_options
* sizeof (char *));
2566 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
2569 /* Create the vector `switches' and its contents.
2570 Store its length in `n_switches'. */
2573 process_command (argc
, argv
)
2579 char *spec_lang
= 0;
2580 int last_language_n_infiles
;
2583 int lang_n_infiles
= 0;
2585 GET_ENV_PATH_LIST (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
2589 added_libraries
= 0;
2591 /* Figure compiler version from version string. */
2593 compiler_version
= save_string (version_string
, strlen (version_string
));
2594 for (temp
= compiler_version
; *temp
; ++temp
)
2603 /* Set up the default search paths. */
2605 if (gcc_exec_prefix
)
2607 int len
= strlen (gcc_exec_prefix
);
2608 if (len
> (int) sizeof ("/lib/gcc-lib/")-1
2609 && (gcc_exec_prefix
[len
-1] == '/'
2610 || gcc_exec_prefix
[len
-1] == DIR_SEPARATOR
))
2612 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc-lib/") + 1;
2613 if ((*temp
== '/' || *temp
== DIR_SEPARATOR
)
2614 && strncmp (temp
+1, "lib", 3) == 0
2615 && (temp
[4] == '/' || temp
[4] == DIR_SEPARATOR
)
2616 && strncmp (temp
+5, "gcc-lib", 7) == 0)
2617 len
-= sizeof ("/lib/gcc-lib/") - 1;
2620 set_std_prefix (gcc_exec_prefix
, len
);
2621 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2622 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2625 /* COMPILER_PATH and LIBRARY_PATH have values
2626 that are lists of directory names with colons. */
2628 GET_ENV_PATH_LIST (temp
, "COMPILER_PATH");
2631 char *startp
, *endp
;
2632 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2634 startp
= endp
= temp
;
2637 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2639 strncpy (nstore
, startp
, endp
-startp
);
2641 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2642 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2644 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2645 nstore
[endp
-startp
+1] = 0;
2648 nstore
[endp
-startp
] = 0;
2649 add_prefix (&exec_prefixes
, nstore
, 0, 0, 0, NULL_PTR
);
2650 add_prefix (&include_prefixes
,
2651 concat (nstore
, "include", NULL_PTR
),
2655 endp
= startp
= endp
+ 1;
2662 GET_ENV_PATH_LIST (temp
, "LIBRARY_PATH");
2663 if (temp
&& *cross_compile
== '0')
2665 char *startp
, *endp
;
2666 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2668 startp
= endp
= temp
;
2671 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2673 strncpy (nstore
, startp
, endp
-startp
);
2675 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2676 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2678 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2679 nstore
[endp
-startp
+1] = 0;
2682 nstore
[endp
-startp
] = 0;
2683 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2687 endp
= startp
= endp
+ 1;
2694 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2695 GET_ENV_PATH_LIST (temp
, "LPATH");
2696 if (temp
&& *cross_compile
== '0')
2698 char *startp
, *endp
;
2699 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2701 startp
= endp
= temp
;
2704 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2706 strncpy (nstore
, startp
, endp
-startp
);
2708 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2709 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2711 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2712 nstore
[endp
-startp
+1] = 0;
2715 nstore
[endp
-startp
] = 0;
2716 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2720 endp
= startp
= endp
+ 1;
2727 /* Convert new-style -- options to old-style. */
2728 translate_options (&argc
, &argv
);
2730 #ifdef LANG_SPECIFIC_DRIVER
2731 /* Do language-specific adjustment/addition of flags. */
2732 lang_specific_driver (fatal
, &argc
, &argv
, &added_libraries
);
2735 /* Scan argv twice. Here, the first time, just count how many switches
2736 there will be in their vector, and how many input files in theirs.
2737 Here we also parse the switches that cc itself uses (e.g. -v). */
2739 for (i
= 1; i
< argc
; i
++)
2741 if (! strcmp (argv
[i
], "-dumpspecs"))
2743 struct spec_list
*sl
;
2745 for (sl
= specs
; sl
; sl
= sl
->next
)
2746 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
2749 else if (! strcmp (argv
[i
], "-dumpversion"))
2751 printf ("%s\n", spec_version
);
2754 else if (! strcmp (argv
[i
], "-dumpmachine"))
2756 printf ("%s\n", spec_machine
);
2759 else if (strcmp (argv
[i
], "-fhelp") == 0)
2761 /* translate_options () has turned --help into -fhelp. */
2762 print_help_list
= 1;
2764 /* We will be passing a dummy file on to the sub-processes. */
2768 add_preprocessor_option ("--help", 6);
2769 add_assembler_option ("--help", 6);
2770 add_linker_option ("--help", 6);
2772 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2773 print_search_dirs
= 1;
2774 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2775 print_file_name
= "libgcc.a";
2776 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2777 print_file_name
= argv
[i
] + 17;
2778 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2779 print_prog_name
= argv
[i
] + 17;
2780 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2781 print_multi_lib
= 1;
2782 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2783 print_multi_directory
= 1;
2784 else if (! strncmp (argv
[i
], "-Wa,", 4))
2787 /* Pass the rest of this option to the assembler. */
2789 /* Split the argument at commas. */
2791 for (j
= 4; argv
[i
][j
]; j
++)
2792 if (argv
[i
][j
] == ',')
2794 add_assembler_option (argv
[i
] + prev
, j
- prev
);
2798 /* Record the part after the last comma. */
2799 add_assembler_option (argv
[i
] + prev
, j
- prev
);
2801 else if (! strncmp (argv
[i
], "-Wp,", 4))
2804 /* Pass the rest of this option to the preprocessor. */
2806 /* Split the argument at commas. */
2808 for (j
= 4; argv
[i
][j
]; j
++)
2809 if (argv
[i
][j
] == ',')
2811 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
2815 /* Record the part after the last comma. */
2816 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
2818 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2819 /* The +e options to the C++ front-end. */
2821 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2824 /* Split the argument at commas. */
2825 for (j
= 3; argv
[i
][j
]; j
++)
2826 n_infiles
+= (argv
[i
][j
] == ',');
2828 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2831 fatal ("argument to `-Xlinker' is missing");
2836 else if (strncmp (argv
[i
], "-l", 2) == 0)
2838 else if (strcmp (argv
[i
], "-save-temps") == 0)
2840 save_temps_flag
= 1;
2843 else if (strcmp (argv
[i
], "-specs") == 0)
2845 struct user_specs
*user
= (struct user_specs
*)
2846 xmalloc (sizeof (struct user_specs
));
2848 fatal ("argument to `-specs' is missing");
2850 user
->next
= (struct user_specs
*)0;
2851 user
->filename
= argv
[i
];
2852 if (user_specs_tail
)
2853 user_specs_tail
->next
= user
;
2855 user_specs_head
= user
;
2856 user_specs_tail
= user
;
2858 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
2860 struct user_specs
*user
= (struct user_specs
*)
2861 xmalloc (sizeof (struct user_specs
));
2862 if (strlen (argv
[i
]) == 7)
2863 fatal ("argument to `-specs=' is missing");
2865 user
->next
= (struct user_specs
*)0;
2866 user
->filename
= argv
[i
]+7;
2867 if (user_specs_tail
)
2868 user_specs_tail
->next
= user
;
2870 user_specs_head
= user
;
2871 user_specs_tail
= user
;
2873 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2875 register char *p
= &argv
[i
][1];
2876 register int c
= *p
;
2882 if (p
[1] == 0 && i
+ 1 == argc
)
2883 fatal ("argument to `-b' is missing");
2885 spec_machine
= argv
[++i
];
2887 spec_machine
= p
+ 1;
2889 warn_std_ptr
= &warn_std
;
2895 if (p
[1] == 0 && i
+ 1 == argc
)
2896 fatal ("argument to `-B' is missing");
2901 add_prefix (&exec_prefixes
, value
, NULL_PTR
, 1, 0, &warn_B
);
2902 add_prefix (&startfile_prefixes
, value
, NULL_PTR
,
2904 add_prefix (&include_prefixes
, concat (value
, "include",
2906 NULL_PTR
, 1, 0, NULL_PTR
);
2908 /* As a kludge, if the arg is "[foo/]stageN/", just add
2909 "[foo/]include" to the include prefix. */
2911 int len
= strlen (value
);
2914 && (value
[len
- 8] == '/'
2915 || value
[len
- 8] == DIR_SEPARATOR
)))
2916 && strncmp (value
+ len
- 7, "stage", 5) == 0
2917 && ISDIGIT (value
[len
- 2])
2918 && (value
[len
- 1] == '/'
2919 || value
[len
- 1] == DIR_SEPARATOR
))
2922 add_prefix (&include_prefixes
, "include", NULL_PTR
,
2926 char *string
= xmalloc (len
+ 1);
2927 strncpy (string
, value
, len
-7);
2928 strcpy (string
+len
-7, "include");
2929 add_prefix (&include_prefixes
, string
, NULL_PTR
,
2938 case 'v': /* Print our subcommands and print versions. */
2940 /* If they do anything other than exactly `-v', don't set
2941 verbose_flag; rather, continue on to give the error. */
2949 if (p
[1] == 0 && i
+ 1 == argc
)
2950 fatal ("argument to `-V' is missing");
2952 spec_version
= argv
[++i
];
2954 spec_version
= p
+ 1;
2955 compiler_version
= spec_version
;
2956 warn_std_ptr
= &warn_std
;
2958 /* Validate the version number. Use the same checks
2959 done when inserting it into a spec.
2961 The format of the version string is
2962 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2964 char *v
= compiler_version
;
2966 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2967 while (! ISDIGIT (*v
))
2970 if (v
> compiler_version
&& v
[-1] != '-')
2971 fatal ("invalid version number format");
2973 /* Set V after the first period. */
2974 while (ISDIGIT (*v
))
2978 fatal ("invalid version number format");
2981 while (ISDIGIT (*v
))
2984 if (*v
!= 0 && *v
!= ' ' && *v
!= '.' && *v
!= '-')
2985 fatal ("invalid version number format");
3001 #if defined(HAVE_EXECUTABLE_SUFFIX)
3006 /* Forward scan, just in case -S or -c is specified
3013 if (argv
[j
][0] == '-')
3015 if (SWITCH_CURTAILS_COMPILATION (argv
[j
][1])
3021 else if (skip
= SWITCH_TAKES_ARG (argv
[j
][1]))
3022 j
+= skip
- (argv
[j
][2] != 0);
3023 else if (skip
= WORD_SWITCH_TAKES_ARG (argv
[j
] + 1))
3030 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3032 argv
[i
+1] = convert_filename (argv
[i
+1], ! have_c
);
3034 argv
[i
] = convert_filename (argv
[i
], ! have_c
);
3042 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3043 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3044 else if (WORD_SWITCH_TAKES_ARG (p
))
3045 i
+= WORD_SWITCH_TAKES_ARG (p
);
3055 if (have_c
&& have_o
&& lang_n_infiles
> 1)
3056 fatal ("cannot specify -o with -c or -S and multiple compilations");
3058 /* Set up the search paths before we go looking for config files. */
3060 /* These come before the md prefixes so that we will find gcc's subcommands
3061 (such as cpp) rather than those of the host system. */
3062 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3063 as well as trying the machine and the version. */
3065 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
3066 0, 2, warn_std_ptr
);
3067 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3068 0, 2, warn_std_ptr
);
3071 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
3072 0, 1, warn_std_ptr
);
3073 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3074 0, 1, warn_std_ptr
);
3076 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
3077 dir_separator_str
, NULL_PTR
);
3079 /* If tooldir is relative, base it on exec_prefixes. A relative
3080 tooldir lets us move the installed tree as a unit.
3082 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3083 directories, so that we can search both the user specified directory
3084 and the standard place. */
3086 if (*tooldir_prefix
!= '/' && *tooldir_prefix
!= DIR_SEPARATOR
)
3088 if (gcc_exec_prefix
)
3090 char *gcc_exec_tooldir_prefix
3091 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
3092 spec_version
, dir_separator_str
, tooldir_prefix
, NULL_PTR
);
3094 add_prefix (&exec_prefixes
,
3095 concat (gcc_exec_tooldir_prefix
, "bin",
3096 dir_separator_str
, NULL_PTR
),
3097 NULL_PTR
, 0, 0, NULL_PTR
);
3098 add_prefix (&startfile_prefixes
,
3099 concat (gcc_exec_tooldir_prefix
, "lib",
3100 dir_separator_str
, NULL_PTR
),
3101 NULL_PTR
, 0, 0, NULL_PTR
);
3104 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
3105 dir_separator_str
, spec_version
,
3106 dir_separator_str
, tooldir_prefix
, NULL_PTR
);
3109 add_prefix (&exec_prefixes
,
3110 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL_PTR
),
3111 "BINUTILS", 0, 0, NULL_PTR
);
3112 add_prefix (&startfile_prefixes
,
3113 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL_PTR
),
3114 "BINUTILS", 0, 0, NULL_PTR
);
3116 /* More prefixes are enabled in main, after we read the specs file
3117 and determine whether this is cross-compilation or not. */
3120 /* Then create the space for the vectors and scan again. */
3122 switches
= ((struct switchstr
*)
3123 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
3124 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
3127 last_language_n_infiles
= -1;
3129 /* This, time, copy the text of each switch and store a pointer
3130 to the copy in the vector of switches.
3131 Store all the infiles in their vector. */
3133 for (i
= 1; i
< argc
; i
++)
3135 /* Just skip the switches that were handled by the preceding loop. */
3136 if (! strncmp (argv
[i
], "-Wa,", 4))
3138 else if (! strncmp (argv
[i
], "-Wp,", 4))
3140 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3142 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3144 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3146 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3148 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3150 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3152 else if (strcmp (argv
[i
], "-fhelp") == 0)
3156 /* Create a dummy input file, so that we can pass --help on to
3157 the various sub-processes. */
3158 infiles
[n_infiles
].language
= "c";
3159 infiles
[n_infiles
++].name
= "help-dummy";
3161 /* Preserve the --help switch so that it can be caught by the
3163 switches
[n_switches
].part1
= "--help";
3164 switches
[n_switches
].args
= 0;
3165 switches
[n_switches
].live_cond
= 0;
3166 switches
[n_switches
].valid
= 0;
3171 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3173 /* Compensate for the +e options to the C++ front-end;
3174 they're there simply for cfront call-compatibility. We do
3175 some magic in default_compilers to pass them down properly.
3176 Note we deliberately start at the `+' here, to avoid passing
3177 -e0 or -e1 down into the linker. */
3178 switches
[n_switches
].part1
= &argv
[i
][0];
3179 switches
[n_switches
].args
= 0;
3180 switches
[n_switches
].live_cond
= 0;
3181 switches
[n_switches
].valid
= 0;
3184 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3187 /* Split the argument at commas. */
3189 for (j
= 4; argv
[i
][j
]; j
++)
3190 if (argv
[i
][j
] == ',')
3192 infiles
[n_infiles
].language
= "*";
3193 infiles
[n_infiles
++].name
3194 = save_string (argv
[i
] + prev
, j
- prev
);
3197 /* Record the part after the last comma. */
3198 infiles
[n_infiles
].language
= "*";
3199 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
3201 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3203 infiles
[n_infiles
].language
= "*";
3204 infiles
[n_infiles
++].name
= argv
[++i
];
3206 else if (strncmp (argv
[i
], "-l", 2) == 0)
3208 infiles
[n_infiles
].language
= "*";
3209 infiles
[n_infiles
++].name
= argv
[i
];
3211 else if (strcmp (argv
[i
], "-specs") == 0)
3213 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3215 /* -save-temps overrides -pipe, so that temp files are produced */
3216 else if (save_temps_flag
&& strcmp (argv
[i
], "-pipe") == 0)
3217 error ("Warning: -pipe ignored since -save-temps specified");
3218 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3220 register char *p
= &argv
[i
][1];
3221 register int c
= *p
;
3225 if (p
[1] == 0 && i
+ 1 == argc
)
3226 fatal ("argument to `-x' is missing");
3228 spec_lang
= argv
[++i
];
3231 if (! strcmp (spec_lang
, "none"))
3232 /* Suppress the warning if -xnone comes after the last input
3233 file, because alternate command interfaces like g++ might
3234 find it useful to place -xnone after each input file. */
3237 last_language_n_infiles
= n_infiles
;
3240 switches
[n_switches
].part1
= p
;
3241 /* Deal with option arguments in separate argv elements. */
3242 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3243 || WORD_SWITCH_TAKES_ARG (p
))
3246 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
3250 /* Count only the option arguments in separate argv elements. */
3251 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3253 if (i
+ n_args
>= argc
)
3254 fatal ("argument to `-%s' is missing", p
);
3255 switches
[n_switches
].args
3256 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
3258 switches
[n_switches
].args
[j
++] = argv
[++i
];
3259 /* Null-terminate the vector. */
3260 switches
[n_switches
].args
[j
] = 0;
3262 else if (index (switches_need_spaces
, c
))
3264 /* On some systems, ld cannot handle some options without
3265 a space. So split the option from its argument. */
3266 char *part1
= (char *) xmalloc (2);
3270 switches
[n_switches
].part1
= part1
;
3271 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
3272 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
3273 strcpy (switches
[n_switches
].args
[0], &p
[1]);
3274 switches
[n_switches
].args
[1] = 0;
3277 switches
[n_switches
].args
= 0;
3279 switches
[n_switches
].live_cond
= 0;
3280 switches
[n_switches
].valid
= 0;
3281 /* This is always valid, since gcc.c itself understands it. */
3282 if (!strcmp (p
, "save-temps"))
3283 switches
[n_switches
].valid
= 1;
3286 char ch
= switches
[n_switches
].part1
[0];
3287 if (ch
== 'V' || ch
== 'b' || ch
== 'B')
3288 switches
[n_switches
].valid
= 1;
3294 #ifdef HAVE_OBJECT_SUFFIX
3295 argv
[i
] = convert_filename (argv
[i
], 0);
3298 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], R_OK
) < 0)
3300 perror_with_name (argv
[i
]);
3305 infiles
[n_infiles
].language
= spec_lang
;
3306 infiles
[n_infiles
++].name
= argv
[i
];
3311 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
3312 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
3314 switches
[n_switches
].part1
= 0;
3315 infiles
[n_infiles
].name
= 0;
3318 /* Process a spec string, accumulating and running commands. */
3320 /* These variables describe the input file name.
3321 input_file_number is the index on outfiles of this file,
3322 so that the output file name can be stored for later use by %o.
3323 input_basename is the start of the part of the input file
3324 sans all directory names, and basename_length is the number
3325 of characters starting there excluding the suffix .c or whatever. */
3327 char *input_filename
;
3328 static int input_file_number
;
3329 size_t input_filename_length
;
3330 static int basename_length
;
3331 static char *input_basename
;
3332 static char *input_suffix
;
3334 /* These are variables used within do_spec and do_spec_1. */
3336 /* Nonzero if an arg has been started and not yet terminated
3337 (with space, tab or newline). */
3338 static int arg_going
;
3340 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3341 is a temporary file name. */
3342 static int delete_this_arg
;
3344 /* Nonzero means %w has been seen; the next arg to be terminated
3345 is the output file name of this compilation. */
3346 static int this_is_output_file
;
3348 /* Nonzero means %s has been seen; the next arg to be terminated
3349 is the name of a library file and we should try the standard
3350 search dirs for it. */
3351 static int this_is_library_file
;
3353 /* Nonzero means that the input of this command is coming from a pipe. */
3354 static int input_from_pipe
;
3356 /* Process the spec SPEC and run the commands specified therein.
3357 Returns 0 if the spec is successfully processed; -1 if failed. */
3367 delete_this_arg
= 0;
3368 this_is_output_file
= 0;
3369 this_is_library_file
= 0;
3370 input_from_pipe
= 0;
3372 value
= do_spec_1 (spec
, 0, NULL_PTR
);
3374 /* Force out any unfinished command.
3375 If -pipe, this forces out the last command if it ended in `|'. */
3378 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3381 if (argbuf_index
> 0)
3388 /* Process the sub-spec SPEC as a portion of a larger spec.
3389 This is like processing a whole spec except that we do
3390 not initialize at the beginning and we do not supply a
3391 newline by default at the end.
3392 INSWITCH nonzero means don't process %-sequences in SPEC;
3393 in this case, % is treated as an ordinary character.
3394 This is used while substituting switches.
3395 INSWITCH nonzero also causes SPC not to terminate an argument.
3397 Value is zero unless a line was finished
3398 and the command on that line reported an error. */
3401 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3404 char *soft_matched_part
;
3406 register char *p
= spec
;
3413 /* If substituting a switch, treat all chars like letters.
3414 Otherwise, NL, SPC, TAB and % are special. */
3415 switch (inswitch
? 'a' : c
)
3418 /* End of line: finish any pending argument,
3419 then run the pending command if one has been started. */
3422 obstack_1grow (&obstack
, 0);
3423 string
= obstack_finish (&obstack
);
3424 if (this_is_library_file
)
3425 string
= find_file (string
);
3426 store_arg (string
, delete_this_arg
, this_is_output_file
);
3427 if (this_is_output_file
)
3428 outfiles
[input_file_number
] = string
;
3432 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3434 for (i
= 0; i
< n_switches
; i
++)
3435 if (!strcmp (switches
[i
].part1
, "pipe"))
3438 /* A `|' before the newline means use a pipe here,
3439 but only if -pipe was specified.
3440 Otherwise, execute now and don't pass the `|' as an arg. */
3443 input_from_pipe
= 1;
3444 switches
[i
].valid
= 1;
3451 if (argbuf_index
> 0)
3457 /* Reinitialize for a new command, and for a new argument. */
3460 delete_this_arg
= 0;
3461 this_is_output_file
= 0;
3462 this_is_library_file
= 0;
3463 input_from_pipe
= 0;
3467 /* End any pending argument. */
3470 obstack_1grow (&obstack
, 0);
3471 string
= obstack_finish (&obstack
);
3472 if (this_is_library_file
)
3473 string
= find_file (string
);
3474 store_arg (string
, delete_this_arg
, this_is_output_file
);
3475 if (this_is_output_file
)
3476 outfiles
[input_file_number
] = string
;
3480 obstack_1grow (&obstack
, c
);
3486 /* Space or tab ends an argument if one is pending. */
3489 obstack_1grow (&obstack
, 0);
3490 string
= obstack_finish (&obstack
);
3491 if (this_is_library_file
)
3492 string
= find_file (string
);
3493 store_arg (string
, delete_this_arg
, this_is_output_file
);
3494 if (this_is_output_file
)
3495 outfiles
[input_file_number
] = string
;
3497 /* Reinitialize for a new argument. */
3499 delete_this_arg
= 0;
3500 this_is_output_file
= 0;
3501 this_is_library_file
= 0;
3508 fatal ("Invalid specification! Bug in cc.");
3511 obstack_grow (&obstack
, input_basename
, basename_length
);
3516 delete_this_arg
= 2;
3519 /* Dump out the directories specified with LIBRARY_PATH,
3520 followed by the absolute directories
3521 that we search for startfiles. */
3524 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3525 size_t bufsize
= 100;
3526 char *buffer
= (char *) xmalloc (bufsize
);
3529 for (; pl
; pl
= pl
->next
)
3531 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3532 /* Used on systems which record the specified -L dirs
3533 and use them to search for dynamic linking. */
3534 /* Relative directories always come from -B,
3535 and it is better not to use them for searching
3536 at run time. In particular, stage1 loses */
3537 if (pl
->prefix
[0] != '/' && pl
->prefix
[0] != DIR_SEPARATOR
)
3540 /* Try subdirectory if there is one. */
3541 if (multilib_dir
!= NULL
)
3545 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3547 bufsize
= (strlen (pl
->prefix
)
3548 + strlen (machine_suffix
)) * 2 + 1;
3549 buffer
= (char *) xrealloc (buffer
, bufsize
);
3550 strcpy (buffer
, pl
->prefix
);
3551 strcat (buffer
, machine_suffix
);
3552 if (is_directory (buffer
, multilib_dir
, 1))
3554 do_spec_1 ("-L", 0, NULL_PTR
);
3555 #ifdef SPACE_AFTER_L_OPTION
3556 do_spec_1 (" ", 0, NULL_PTR
);
3558 do_spec_1 (buffer
, 1, NULL_PTR
);
3559 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3560 /* Make this a separate argument. */
3561 do_spec_1 (" ", 0, NULL_PTR
);
3564 if (!pl
->require_machine_suffix
)
3566 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3568 do_spec_1 ("-L", 0, NULL_PTR
);
3569 #ifdef SPACE_AFTER_L_OPTION
3570 do_spec_1 (" ", 0, NULL_PTR
);
3572 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3573 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3574 /* Make this a separate argument. */
3575 do_spec_1 (" ", 0, NULL_PTR
);
3581 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3583 do_spec_1 ("-L", 0, NULL_PTR
);
3584 #ifdef SPACE_AFTER_L_OPTION
3585 do_spec_1 (" ", 0, NULL_PTR
);
3587 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3588 /* Remove slash from machine_suffix. */
3589 if (strlen (machine_suffix
) >= bufsize
)
3590 bufsize
= strlen (machine_suffix
) * 2 + 1;
3591 buffer
= (char *) xrealloc (buffer
, bufsize
);
3592 strcpy (buffer
, machine_suffix
);
3593 idx
= strlen (buffer
);
3594 if (buffer
[idx
- 1] == '/'
3595 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3596 buffer
[idx
- 1] = 0;
3597 do_spec_1 (buffer
, 1, NULL_PTR
);
3598 /* Make this a separate argument. */
3599 do_spec_1 (" ", 0, NULL_PTR
);
3602 if (!pl
->require_machine_suffix
)
3604 if (is_directory (pl
->prefix
, "", 1))
3606 do_spec_1 ("-L", 0, NULL_PTR
);
3607 #ifdef SPACE_AFTER_L_OPTION
3608 do_spec_1 (" ", 0, NULL_PTR
);
3610 /* Remove slash from pl->prefix. */
3611 if (strlen (pl
->prefix
) >= bufsize
)
3612 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3613 buffer
= (char *) xrealloc (buffer
, bufsize
);
3614 strcpy (buffer
, pl
->prefix
);
3615 idx
= strlen (buffer
);
3616 if (buffer
[idx
- 1] == '/'
3617 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3618 buffer
[idx
- 1] = 0;
3619 do_spec_1 (buffer
, 1, NULL_PTR
);
3620 /* Make this a separate argument. */
3621 do_spec_1 (" ", 0, NULL_PTR
);
3630 /* {...:%efoo} means report an error with `foo' as error message
3631 and don't execute any more commands for this file. */
3635 while (*p
!= 0 && *p
!= '\n') p
++;
3636 buf
= (char *) alloca (p
- q
+ 1);
3637 strncpy (buf
, q
, p
- q
);
3647 if (save_temps_flag
)
3649 obstack_grow (&obstack
, input_basename
, basename_length
);
3650 delete_this_arg
= 0;
3654 #ifdef MKTEMP_EACH_FILE
3655 /* ??? This has a problem: the total number of
3656 values mktemp can return is limited.
3657 That matters for the names of object files.
3658 In 2.4, do something about that. */
3659 struct temp_name
*t
;
3663 if (p
[0] == '%' && p
[1] == 'O')
3665 /* We don't support extra suffix characters after %O. */
3666 if (*p
== '.' || ISALPHA ((unsigned char)*p
))
3668 suffix
= OBJECT_SUFFIX
;
3669 suffix_length
= strlen (OBJECT_SUFFIX
);
3674 while (*p
== '.' || ISALPHA ((unsigned char)*p
))
3676 suffix_length
= p
- suffix
;
3679 /* See if we already have an association of %g/%u/%U and
3681 for (t
= temp_names
; t
; t
= t
->next
)
3682 if (t
->length
== suffix_length
3683 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
3684 && t
->unique
== (c
!= 'g'))
3687 /* Make a new association if needed. %u requires one. */
3688 if (t
== 0 || c
== 'u')
3692 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3693 t
->next
= temp_names
;
3696 t
->length
= suffix_length
;
3697 t
->suffix
= save_string (suffix
, suffix_length
);
3698 t
->unique
= (c
!= 'g');
3699 temp_filename
= make_temp_file (t
->suffix
);
3700 temp_filename_length
= strlen (temp_filename
);
3701 t
->filename
= temp_filename
;
3702 t
->filename_length
= temp_filename_length
;
3705 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3706 delete_this_arg
= 1;
3708 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3709 if (c
== 'u' || c
== 'U')
3715 sprintf (buff
, "%d", unique
);
3716 obstack_grow (&obstack
, buff
, strlen (buff
));
3719 delete_this_arg
= 1;
3725 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3731 struct prefix_list
*pl
= include_prefixes
.plist
;
3733 if (gcc_exec_prefix
)
3735 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3736 /* Make this a separate argument. */
3737 do_spec_1 (" ", 0, NULL_PTR
);
3738 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3739 do_spec_1 (" ", 0, NULL_PTR
);
3742 for (; pl
; pl
= pl
->next
)
3744 do_spec_1 ("-isystem", 1, NULL_PTR
);
3745 /* Make this a separate argument. */
3746 do_spec_1 (" ", 0, NULL_PTR
);
3747 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3748 do_spec_1 (" ", 0, NULL_PTR
);
3755 int max
= n_infiles
;
3756 #ifdef LANG_SPECIFIC_DRIVER
3757 max
+= lang_specific_extra_outfiles
;
3759 for (i
= 0; i
< max
; i
++)
3761 store_arg (outfiles
[i
], 0, 0);
3766 obstack_grow (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
3771 this_is_library_file
= 1;
3775 this_is_output_file
= 1;
3780 int cur_index
= argbuf_index
;
3781 /* Handle the {...} following the %W. */
3784 p
= handle_braces (p
+ 1);
3787 /* If any args were output, mark the last one for deletion
3789 if (argbuf_index
!= cur_index
)
3790 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3794 /* %x{OPTION} records OPTION for %X to output. */
3800 /* Skip past the option value and make a copy. */
3805 string
= save_string (p1
+ 1, p
- p1
- 2);
3807 /* See if we already recorded this option. */
3808 for (i
= 0; i
< n_linker_options
; i
++)
3809 if (! strcmp (string
, linker_options
[i
]))
3815 /* This option is new; add it. */
3816 add_linker_option (string
, strlen (string
));
3820 /* Dump out the options accumulated previously using %x. */
3822 for (i
= 0; i
< n_linker_options
; i
++)
3824 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3825 /* Make each accumulated option a separate argument. */
3826 do_spec_1 (" ", 0, NULL_PTR
);
3830 /* Dump out the options accumulated previously using -Wa,. */
3832 for (i
= 0; i
< n_assembler_options
; i
++)
3834 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3835 /* Make each accumulated option a separate argument. */
3836 do_spec_1 (" ", 0, NULL_PTR
);
3840 /* Dump out the options accumulated previously using -Wp,. */
3842 for (i
= 0; i
< n_preprocessor_options
; i
++)
3844 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3845 /* Make each accumulated option a separate argument. */
3846 do_spec_1 (" ", 0, NULL_PTR
);
3850 /* Here are digits and numbers that just process
3851 a certain constant string as a spec. */
3854 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3860 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3866 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3872 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3878 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3884 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3890 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3896 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3902 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3908 value
= do_spec_1 (libgcc_spec
, 0, NULL_PTR
);
3915 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3919 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3923 if (! strncmp (y
, "-D", 2))
3924 /* Copy the whole option. */
3925 while (*y
&& *y
!= ' ' && *y
!= '\t')
3927 else if (*y
== ' ' || *y
== '\t')
3928 /* Copy whitespace to the result. */
3930 /* Don't copy other options. */
3937 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3945 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3949 /* Copy all of CPP_PREDEFINES into BUF,
3950 but put __ after every -D and at the end of each arg. */
3954 if (! strncmp (y
, "-D", 2))
3963 && ! ISUPPER ((unsigned char)*(y
+1))))
3965 /* Stick __ at front of macro name. */
3968 /* Arrange to stick __ at the end as well. */
3972 /* Copy the macro name. */
3973 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3982 /* Copy the value given, if any. */
3983 while (*y
&& *y
!= ' ' && *y
!= '\t')
3986 else if (*y
== ' ' || *y
== '\t')
3987 /* Copy whitespace to the result. */
3989 /* Don't copy -A options */
3995 /* Copy all of CPP_PREDEFINES into BUF,
3996 but put __ after every -D. */
4000 if (! strncmp (y
, "-D", 2))
4006 && ! ISUPPER ((unsigned char)*(y
+1))))
4008 /* Stick -D__ at front of macro name. */
4014 /* Copy the macro name. */
4015 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4018 /* Copy the value given, if any. */
4019 while (*y
&& *y
!= ' ' && *y
!= '\t')
4024 /* Do not copy this macro - we have just done it before */
4025 while (*y
&& *y
!= ' ' && *y
!= '\t')
4029 else if (*y
== ' ' || *y
== '\t')
4030 /* Copy whitespace to the result. */
4032 /* Don't copy -A options */
4038 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4042 if (! strncmp (y
, "-A", 2))
4043 /* Copy the whole option. */
4044 while (*y
&& *y
!= ' ' && *y
!= '\t')
4046 else if (*y
== ' ' || *y
== '\t')
4047 /* Copy whitespace to the result. */
4049 /* Don't copy other options. */
4056 value
= do_spec_1 (buf
, 0, NULL_PTR
);
4063 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
4068 /* Here we define characters other than letters and digits. */
4071 p
= handle_braces (p
);
4077 obstack_1grow (&obstack
, '%');
4081 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
4082 do_spec_1 (" ", 0, NULL_PTR
);
4085 /* Process a string found as the value of a spec given by name.
4086 This feature allows individual machine descriptions
4087 to add and use their own specs.
4088 %[...] modifies -D options the way %P does;
4089 %(...) uses the spec unmodified. */
4091 error ("Warning: use of obsolete %%[ operator in specs");
4095 struct spec_list
*sl
;
4098 /* The string after the S/P is the name of a spec that is to be
4100 while (*p
&& *p
!= ')' && *p
!= ']')
4103 /* See if it's in the list */
4104 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
4105 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
4107 name
= *(sl
->ptr_spec
);
4109 fprintf (stderr
, "Processing spec %c%s%c, which is '%s'\n",
4110 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
4119 value
= do_spec_1 (name
, 0, NULL_PTR
);
4125 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
4130 /* Copy all of NAME into BUF, but put __ after
4131 every -D and at the end of each arg, */
4134 if (! strncmp (y
, "-D", 2))
4144 else if (flag
&& (*y
== ' ' || *y
== '\t' || *y
== '='
4145 || *y
== '}' || *y
== 0))
4158 value
= do_spec_1 (buf
, 0, NULL_PTR
);
4164 /* Discard the closing paren or bracket. */
4172 int c1
= *p
++; /* Select first or second version number. */
4173 char *v
= compiler_version
;
4176 /* The format of the version string is
4177 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4179 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4180 while (! ISDIGIT (*v
))
4182 if (v
> compiler_version
&& v
[-1] != '-')
4185 /* If desired, advance to second version number. */
4188 /* Set V after the first period. */
4189 while (ISDIGIT (*v
))
4196 /* Set Q at the next period or at the end. */
4198 while (ISDIGIT (*q
))
4200 if (*q
!= 0 && *q
!= ' ' && *q
!= '.' && *q
!= '-')
4203 /* Put that part into the command. */
4204 obstack_grow (&obstack
, v
, q
- v
);
4210 if (input_from_pipe
)
4211 do_spec_1 ("-", 0, NULL_PTR
);
4220 /* Backslash: treat next character as ordinary. */
4225 /* Ordinary character: put it into the current argument. */
4226 obstack_1grow (&obstack
, c
);
4230 return 0; /* End of string */
4233 /* Return 0 if we call do_spec_1 and that returns -1. */
4239 char *filter
, *body
= NULL
, *endbody
;
4243 int include_blanks
= 1;
4246 /* A '^' after the open-brace means to not give blanks before args. */
4247 include_blanks
= 0, ++p
;
4250 /* A `|' after the open-brace means,
4251 if the test fails, output a single minus sign rather than nothing.
4252 This is used in %{|!pipe:...}. */
4256 negate
= suffix
= 0;
4259 /* A `!' after the open-brace negates the condition:
4260 succeed if the specified switch is not present. */
4264 /* A `.' after the open-brace means test against the current suffix. */
4274 while (*p
!= ':' && *p
!= '}' && *p
!= '|') p
++;
4276 if (*p
== '|' && pipe_p
)
4283 register int count
= 1;
4284 register char *q
= p
;
4286 while (*q
++ != ':') continue;
4302 body
= p
, endbody
= p
+1;
4307 int found
= (input_suffix
!= 0
4308 && (long) strlen (input_suffix
) == (long)(p
- filter
)
4309 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
4315 && do_spec_1 (save_string (body
, endbody
-body
-1), 0, NULL_PTR
) < 0)
4318 else if (p
[-1] == '*' && p
[0] == '}')
4320 /* Substitute all matching switches as separate args. */
4323 for (i
= 0; i
< n_switches
; i
++)
4324 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4325 && check_live_switch (i
, p
- filter
))
4326 give_switch (i
, 0, include_blanks
);
4330 /* Test for presence of the specified switch. */
4334 /* If name specified ends in *, as in {x*:...},
4335 check for %* and handle that case. */
4336 if (p
[-1] == '*' && !negate
)
4341 /* First see whether we have %*. */
4345 if (*r
== '%' && r
[1] == '*')
4349 /* If we do, handle that case. */
4352 /* Substitute all matching switches as separate args.
4353 But do this by substituting for %*
4354 in the text that follows the colon. */
4356 unsigned hard_match_len
= p
- filter
- 1;
4357 char *string
= save_string (body
, endbody
- body
- 1);
4359 for (i
= 0; i
< n_switches
; i
++)
4360 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4361 && check_live_switch (i
, -1))
4363 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
4364 /* Pass any arguments this switch has. */
4365 give_switch (i
, 1, 1);
4368 /* We didn't match. Try again. */
4375 /* If name specified ends in *, as in {x*:...},
4376 check for presence of any switch name starting with x. */
4379 for (i
= 0; i
< n_switches
; i
++)
4381 unsigned hard_match_len
= p
- filter
- 1;
4383 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4384 && check_live_switch (i
, hard_match_len
))
4390 /* Otherwise, check for presence of exact name specified. */
4393 for (i
= 0; i
< n_switches
; i
++)
4395 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4396 && switches
[i
].part1
[p
- filter
] == 0
4397 && check_live_switch (i
, -1))
4405 /* If it is as desired (present for %{s...}, absent for %{!s...})
4406 then substitute either the switch or the specified
4407 conditional text. */
4408 if (present
!= negate
)
4412 give_switch (i
, 0, include_blanks
);
4416 if (do_spec_1 (save_string (body
, endbody
- body
- 1),
4423 /* Here if a %{|...} conditional fails: output a minus sign,
4424 which means "standard output" or "standard input". */
4425 do_spec_1 ("-", 0, NULL_PTR
);
4430 /* We didn't match; try again. */
4437 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4438 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4439 spec, or -1 if either exact match or %* is used.
4441 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4442 whose value does not begin with "no-" is obsoleted by the same value
4443 with the "no-", similarly for a switch with the "no-" prefix. */
4446 check_live_switch (switchnum
, prefix_length
)
4450 char *name
= switches
[switchnum
].part1
;
4453 /* In the common case of {<at-most-one-letter>*}, a negating
4454 switch would always match, so ignore that case. We will just
4455 send the conflicting switches to the compiler phase. */
4456 if (prefix_length
>= 0 && prefix_length
<= 1)
4459 /* If we already processed this switch and determined if it was
4460 live or not, return our past determination. */
4461 if (switches
[switchnum
].live_cond
!= 0)
4462 return switches
[switchnum
].live_cond
> 0;
4464 /* Now search for duplicate in a manner that depends on the name. */
4468 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4469 if (switches
[i
].part1
[0] == 'O')
4471 switches
[switchnum
].valid
= 1;
4472 switches
[switchnum
].live_cond
= -1;
4477 case 'W': case 'f': case 'm':
4478 if (! strncmp (name
+ 1, "no-", 3))
4480 /* We have Xno-YYY, search for XYYY. */
4481 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4482 if (switches
[i
].part1
[0] == name
[0]
4483 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4485 switches
[switchnum
].valid
= 1;
4486 switches
[switchnum
].live_cond
= -1;
4492 /* We have XYYY, search for Xno-YYY. */
4493 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4494 if (switches
[i
].part1
[0] == name
[0]
4495 && switches
[i
].part1
[1] == 'n'
4496 && switches
[i
].part1
[2] == 'o'
4497 && switches
[i
].part1
[3] == '-'
4498 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4500 switches
[switchnum
].valid
= 1;
4501 switches
[switchnum
].live_cond
= -1;
4508 /* Otherwise the switch is live. */
4509 switches
[switchnum
].live_cond
= 1;
4513 /* Pass a switch to the current accumulating command
4514 in the same form that we received it.
4515 SWITCHNUM identifies the switch; it is an index into
4516 the vector of switches gcc received, which is `switches'.
4517 This cannot fail since it never finishes a command line.
4519 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4521 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4525 give_switch (switchnum
, omit_first_word
, include_blanks
)
4527 int omit_first_word
;
4530 if (!omit_first_word
)
4532 do_spec_1 ("-", 0, NULL_PTR
);
4533 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4536 if (switches
[switchnum
].args
!= 0)
4539 for (p
= switches
[switchnum
].args
; *p
; p
++)
4542 do_spec_1 (" ", 0, NULL_PTR
);
4543 do_spec_1 (*p
, 1, NULL_PTR
);
4547 do_spec_1 (" ", 0, NULL_PTR
);
4548 switches
[switchnum
].valid
= 1;
4551 /* Search for a file named NAME trying various prefixes including the
4552 user's -B prefix and some standard ones.
4553 Return the absolute file name found. If nothing is found, return NAME. */
4561 /* Try multilib_dir if it is defined. */
4562 if (multilib_dir
!= NULL
)
4566 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4567 strcpy (try, multilib_dir
);
4568 strcat (try, dir_separator_str
);
4571 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4573 /* If we don't find it in the multi library dir, then fall
4574 through and look for it in the normal places. */
4575 if (newname
!= NULL
)
4579 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4580 return newname
? newname
: name
;
4583 /* Determine whether a directory exists. If LINKER, return 0 for
4584 certain fixed names not needed by the linker. If not LINKER, it is
4585 only important to return 0 if the host machine has a small ARG_MAX
4589 is_directory (path1
, path2
, linker
)
4594 int len1
= strlen (path1
);
4595 int len2
= strlen (path2
);
4596 char *path
= (char *) alloca (3 + len1
+ len2
);
4600 #ifndef SMALL_ARG_MAX
4605 /* Construct the path from the two parts. Ensure the string ends with "/.".
4606 The resulting path will be a directory even if the given path is a
4608 memcpy (path
, path1
, len1
);
4609 memcpy (path
+ len1
, path2
, len2
);
4610 cp
= path
+ len1
+ len2
;
4611 if (cp
[-1] != '/' && cp
[-1] != DIR_SEPARATOR
)
4612 *cp
++ = DIR_SEPARATOR
;
4616 /* Exclude directories that the linker is known to search. */
4619 && strcmp (path
, concat (dir_separator_str
, "lib",
4620 dir_separator_str
, ".", NULL_PTR
)) == 0)
4622 && strcmp (path
, concat (dir_separator_str
, "usr",
4623 dir_separator_str
, "lib",
4624 dir_separator_str
, ".", NULL_PTR
)) == 0)))
4627 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4630 /* On fatal signals, delete all the temporary files. */
4633 fatal_error (signum
)
4636 signal (signum
, SIG_DFL
);
4637 delete_failure_queue ();
4638 delete_temp_files ();
4639 /* Get the same signal again, this time not handled,
4640 so its normal effect occurs. */
4641 kill (getpid (), signum
);
4652 int linker_was_run
= 0;
4653 char *explicit_link_files
;
4656 struct user_specs
*uptr
;
4658 p
= argv
[0] + strlen (argv
[0]);
4659 while (p
!= argv
[0] && p
[-1] != '/' && p
[-1] != DIR_SEPARATOR
) --p
;
4662 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4663 signal (SIGINT
, fatal_error
);
4665 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4666 signal (SIGHUP
, fatal_error
);
4668 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4669 signal (SIGTERM
, fatal_error
);
4671 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4672 signal (SIGPIPE
, fatal_error
);
4676 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4678 obstack_init (&obstack
);
4680 /* Build multilib_select, et. al from the separate lines that make up each
4681 multilib selection. */
4683 char **q
= multilib_raw
;
4686 obstack_init (&multilib_obstack
);
4687 while ((p
= *q
++) != (char *) 0)
4688 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4690 obstack_1grow (&multilib_obstack
, 0);
4691 multilib_select
= obstack_finish (&multilib_obstack
);
4693 q
= multilib_matches_raw
;
4694 while ((p
= *q
++) != (char *) 0)
4695 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4697 obstack_1grow (&multilib_obstack
, 0);
4698 multilib_matches
= obstack_finish (&multilib_obstack
);
4702 i
< sizeof (multilib_defaults_raw
) / sizeof (multilib_defaults_raw
[0]);
4706 obstack_1grow (&multilib_obstack
, ' ');
4707 obstack_grow (&multilib_obstack
,
4708 multilib_defaults_raw
[i
],
4709 strlen (multilib_defaults_raw
[i
]));
4713 obstack_1grow (&multilib_obstack
, 0);
4714 multilib_defaults
= obstack_finish (&multilib_obstack
);
4717 /* Set up to remember the pathname of gcc and any options
4718 needed for collect. We use argv[0] instead of programname because
4719 we need the complete pathname. */
4720 obstack_init (&collect_obstack
);
4721 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4722 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4723 putenv (obstack_finish (&collect_obstack
));
4725 #ifdef INIT_ENVIRONMENT
4726 /* Set up any other necessary machine specific environment variables. */
4727 putenv (INIT_ENVIRONMENT
);
4730 /* Choose directory for temp files. */
4732 #ifndef MKTEMP_EACH_FILE
4733 temp_filename
= choose_temp_base ();
4734 temp_filename_length
= strlen (temp_filename
);
4737 /* Make a table of what switches there are (switches, n_switches).
4738 Make a table of specified input files (infiles, n_infiles).
4739 Decode switches that are handled locally. */
4741 process_command (argc
, argv
);
4746 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4748 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4749 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4752 for (i
= 0; (int)i
< n_switches
; i
++)
4757 obstack_grow (&collect_obstack
, " ", 1);
4760 obstack_grow (&collect_obstack
, "'-", 2);
4761 q
= switches
[i
].part1
;
4762 while ((p
= index (q
,'\'')))
4764 obstack_grow (&collect_obstack
, q
, p
-q
);
4765 obstack_grow (&collect_obstack
, "'\\''", 4);
4768 obstack_grow (&collect_obstack
, q
, strlen (q
));
4769 obstack_grow (&collect_obstack
, "'", 1);
4771 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4773 obstack_grow (&collect_obstack
, " '", 2);
4775 while ((p
= index (q
,'\'')))
4777 obstack_grow (&collect_obstack
, q
, p
-q
);
4778 obstack_grow (&collect_obstack
, "'\\''", 4);
4781 obstack_grow (&collect_obstack
, q
, strlen (q
));
4782 obstack_grow (&collect_obstack
, "'", 1);
4785 obstack_grow (&collect_obstack
, "\0", 1);
4786 putenv (obstack_finish (&collect_obstack
));
4789 /* Initialize the vector of specs to just the default.
4790 This means one element containing 0s, as a terminator. */
4792 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4793 bcopy ((char *) default_compilers
, (char *) compilers
,
4794 sizeof default_compilers
);
4795 n_compilers
= n_default_compilers
;
4797 /* Read specs from a file if there is one. */
4799 machine_suffix
= concat (spec_machine
, dir_separator_str
,
4800 spec_version
, dir_separator_str
, NULL_PTR
);
4801 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL_PTR
);
4803 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4804 /* Read the specs file unless it is a default one. */
4805 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4806 read_specs (specs_file
, TRUE
);
4810 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4811 for any override of as, ld and libraries. */
4812 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
4813 + strlen (just_machine_suffix
)
4814 + sizeof ("specs"));
4816 strcpy (specs_file
, standard_exec_prefix
);
4817 strcat (specs_file
, just_machine_suffix
);
4818 strcat (specs_file
, "specs");
4819 if (access (specs_file
, R_OK
) == 0)
4820 read_specs (specs_file
, TRUE
);
4822 /* Process any user specified specs in the order given on the command
4824 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
4826 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
, R_OK
);
4827 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
4830 /* If not cross-compiling, look for startfiles in the standard places. */
4831 /* The fact that these are done here, after reading the specs file,
4832 means that it cannot be found in these directories.
4833 But that's okay. It should never be there anyway. */
4834 if (*cross_compile
== '0')
4836 #ifdef MD_EXEC_PREFIX
4837 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4838 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4841 #ifdef MD_STARTFILE_PREFIX
4842 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
4846 #ifdef MD_STARTFILE_PREFIX_1
4847 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
4851 /* If standard_startfile_prefix is relative, base it on
4852 standard_exec_prefix. This lets us move the installed tree
4853 as a unit. If GCC_EXEC_PREFIX is defined, base
4854 standard_startfile_prefix on that as well. */
4855 if (*standard_startfile_prefix
== '/'
4856 || *standard_startfile_prefix
== DIR_SEPARATOR
4857 || *standard_startfile_prefix
== '$'
4859 /* Check for disk name on MS-DOS-based systems. */
4860 || (standard_startfile_prefix
[1] == ':'
4861 && (standard_startfile_prefix
[2] == DIR_SEPARATOR
4862 || standard_startfile_prefix
[2] == '/'))
4865 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
4869 if (gcc_exec_prefix
)
4870 add_prefix (&startfile_prefixes
,
4871 concat (gcc_exec_prefix
, machine_suffix
,
4872 standard_startfile_prefix
, NULL_PTR
),
4873 NULL_PTR
, 0, 0, NULL_PTR
);
4874 add_prefix (&startfile_prefixes
,
4875 concat (standard_exec_prefix
,
4877 standard_startfile_prefix
, NULL_PTR
),
4878 NULL_PTR
, 0, 0, NULL_PTR
);
4881 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
4882 "BINUTILS", 0, 0, NULL_PTR
);
4883 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
4884 "BINUTILS", 0, 0, NULL_PTR
);
4885 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4886 add_prefix (&startfile_prefixes
, "./", NULL_PTR
, 0, 1, NULL_PTR
);
4891 if (*standard_startfile_prefix
!= DIR_SEPARATOR
&& gcc_exec_prefix
)
4892 add_prefix (&startfile_prefixes
,
4893 concat (gcc_exec_prefix
, machine_suffix
,
4894 standard_startfile_prefix
, NULL_PTR
),
4895 "BINUTILS", 0, 0, NULL_PTR
);
4898 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4899 if (gcc_exec_prefix
)
4901 char * temp
= (char *) xmalloc (strlen (gcc_exec_prefix
)
4902 + strlen (spec_version
)
4903 + strlen (spec_machine
) + 3);
4904 strcpy (temp
, gcc_exec_prefix
);
4905 strcat (temp
, spec_machine
);
4906 strcat (temp
, dir_separator_str
);
4907 strcat (temp
, spec_version
);
4908 strcat (temp
, dir_separator_str
);
4909 gcc_exec_prefix
= temp
;
4912 /* Now we have the specs.
4913 Set the `valid' bits for switches that match anything in any spec. */
4915 validate_all_switches ();
4917 /* Now that we have the switches and the specs, set
4918 the subdirectory based on the options. */
4919 set_multilib_dir ();
4921 /* Warn about any switches that no pass was interested in. */
4923 for (i
= 0; (int)i
< n_switches
; i
++)
4924 if (! switches
[i
].valid
)
4925 error ("unrecognized option `-%s'", switches
[i
].part1
);
4927 /* Obey some of the options. */
4929 if (print_search_dirs
)
4931 printf ("install: %s%s\n", standard_exec_prefix
, machine_suffix
);
4932 printf ("programs: %s\n", build_search_list (&exec_prefixes
, "", 0));
4933 printf ("libraries: %s\n", build_search_list (&startfile_prefixes
, "", 0));
4937 if (print_file_name
)
4939 printf ("%s\n", find_file (print_file_name
));
4943 if (print_prog_name
)
4945 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4946 printf ("%s\n", (newname
? newname
: print_prog_name
));
4950 if (print_multi_lib
)
4952 print_multilib_info ();
4956 if (print_multi_directory
)
4958 if (multilib_dir
== NULL
)
4961 printf ("%s\n", multilib_dir
);
4965 if (print_help_list
)
4971 printf ("\nReport bugs to egcs-bugs@cygnus.com.\n");
4972 printf ("Please see the file BUGS (included with the sources) first.\n");
4977 /* We do not exit here. Instead we have created a fake input file
4978 called 'help-dummy' which needs to be compiled, and we pass this
4979 on the the various sub-processes, along with the --help switch. */
4986 /* compiler_version is truncated at the first space when initialized
4987 from version string, so truncate version_string at the first space
4988 before comparing. */
4989 for (n
= 0; version_string
[n
]; n
++)
4990 if (version_string
[n
] == ' ')
4993 if (! strncmp (version_string
, compiler_version
, n
)
4994 && compiler_version
[n
] == 0)
4995 fprintf (stderr
, "gcc version %s\n", version_string
);
4997 fprintf (stderr
, "gcc driver version %s executing gcc version %s\n",
4998 version_string
, compiler_version
);
5004 if (n_infiles
== added_libraries
)
5005 fatal ("No input files");
5007 /* Make a place to record the compiler output file names
5008 that correspond to the input files. */
5011 #ifdef LANG_SPECIFIC_DRIVER
5012 i
+= lang_specific_extra_outfiles
;
5014 outfiles
= (char **) xmalloc (i
* sizeof (char *));
5015 bzero ((char *) outfiles
, i
* sizeof (char *));
5017 /* Record which files were specified explicitly as link input. */
5019 explicit_link_files
= xmalloc (n_infiles
);
5020 bzero (explicit_link_files
, n_infiles
);
5022 for (i
= 0; (int)i
< n_infiles
; i
++)
5024 register struct compiler
*cp
= 0;
5025 int this_file_error
= 0;
5027 /* Tell do_spec what to substitute for %i. */
5029 input_filename
= infiles
[i
].name
;
5030 input_filename_length
= strlen (input_filename
);
5031 input_file_number
= i
;
5033 /* Use the same thing in %o, unless cp->spec says otherwise. */
5035 outfiles
[i
] = input_filename
;
5037 /* Figure out which compiler from the file's suffix. */
5039 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
5040 infiles
[i
].language
);
5044 /* Ok, we found an applicable compiler. Run its spec. */
5045 /* First say how much of input_filename to substitute for %b */
5049 if (cp
->spec
[0][0] == '#')
5050 error ("%s: %s compiler not installed on this system",
5051 input_filename
, &cp
->spec
[0][1]);
5053 input_basename
= input_filename
;
5054 for (p
= input_filename
; *p
; p
++)
5055 if (*p
== '/' || *p
== DIR_SEPARATOR
)
5056 input_basename
= p
+ 1;
5058 /* Find a suffix starting with the last period,
5059 and set basename_length to exclude that suffix. */
5060 basename_length
= strlen (input_basename
);
5061 p
= input_basename
+ basename_length
;
5062 while (p
!= input_basename
&& *p
!= '.') --p
;
5063 if (*p
== '.' && p
!= input_basename
)
5065 basename_length
= p
- input_basename
;
5066 input_suffix
= p
+ 1;
5072 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
5074 len
+= strlen (cp
->spec
[j
]);
5076 p
= (char *) xmalloc (len
+ 1);
5079 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
5082 strcpy (p
+ len
, cp
->spec
[j
]);
5083 len
+= strlen (cp
->spec
[j
]);
5086 value
= do_spec (p
);
5089 this_file_error
= 1;
5092 /* If this file's name does not contain a recognized suffix,
5093 record it as explicit linker input. */
5096 explicit_link_files
[i
] = 1;
5098 /* Clear the delete-on-failure queue, deleting the files in it
5099 if this compilation failed. */
5101 if (this_file_error
)
5103 delete_failure_queue ();
5106 /* If this compilation succeeded, don't delete those files later. */
5107 clear_failure_queue ();
5110 #ifdef LANG_SPECIFIC_DRIVER
5111 if (error_count
== 0)
5113 /* Make sure INPUT_FILE_NUMBER points to first available open
5115 input_file_number
= n_infiles
;
5116 if (lang_specific_pre_link ())
5121 /* Run ld to link all the compiler output files. */
5123 if (error_count
== 0)
5125 int tmp
= execution_count
;
5127 /* We'll use ld if we can't find collect2. */
5128 if (! strcmp (linker_name_spec
, "collect2"))
5130 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
);
5132 linker_name_spec
= "ld";
5134 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
5136 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
5137 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
5139 value
= do_spec (link_command_spec
);
5142 linker_was_run
= (tmp
!= execution_count
);
5145 /* Warn if a -B option was specified but the prefix was never used. */
5146 unused_prefix_warnings (&exec_prefixes
);
5147 unused_prefix_warnings (&startfile_prefixes
);
5149 /* If options said don't run linker,
5150 complain about input files to be given to the linker. */
5152 if (! linker_was_run
&& error_count
== 0)
5153 for (i
= 0; (int)i
< n_infiles
; i
++)
5154 if (explicit_link_files
[i
])
5155 error ("%s: linker input file unused since linking not done",
5158 /* Delete some or all of the temporary files we made. */
5161 delete_failure_queue ();
5162 delete_temp_files ();
5164 if (print_help_list
)
5166 printf ("\nReport bugs to egcs-bugs@cygnus.com.\n");
5167 printf ("Please see the file BUGS (included with the sources) first.\n");
5170 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
5175 /* Find the proper compilation spec for the file name NAME,
5176 whose length is LENGTH. LANGUAGE is the specified language,
5177 or 0 if this file is to be passed to the linker. */
5179 static struct compiler
*
5180 lookup_compiler (name
, length
, language
)
5185 struct compiler
*cp
;
5187 /* If this was specified by the user to be a linker input, indicate that. */
5188 if (language
!= 0 && language
[0] == '*')
5191 /* Otherwise, look for the language, if one is spec'd. */
5194 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
5195 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
5198 error ("language %s not recognized", language
);
5202 /* Look for a suffix. */
5203 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
5205 if (/* The suffix `-' matches only the file name `-'. */
5206 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
5207 || (strlen (cp
->suffix
) < length
5208 /* See if the suffix matches the end of NAME. */
5210 && ((!strcmp (cp
->suffix
,
5211 name
+ length
- strlen (cp
->suffix
))
5212 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
5213 && !strcasecmp (cp
->suffix
,
5214 name
+ length
- strlen (cp
->suffix
)))
5216 && !strcmp (cp
->suffix
,
5217 name
+ length
- strlen (cp
->suffix
))
5221 if (cp
->spec
[0][0] == '@')
5223 struct compiler
*new;
5225 /* An alias entry maps a suffix to a language.
5226 Search for the language; pass 0 for NAME and LENGTH
5227 to avoid infinite recursion if language not found.
5228 Construct the new compiler spec. */
5229 language
= cp
->spec
[0] + 1;
5230 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
5231 new->suffix
= cp
->suffix
;
5232 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
5233 (char *) new->spec
, sizeof new->spec
);
5237 /* A non-alias entry: return it. */
5249 register char *value
= (char *) malloc (size
);
5251 fatal ("virtual memory exhausted");
5256 xrealloc (ptr
, size
)
5260 register char *value
= (char *) realloc (ptr
, size
);
5262 fatal ("virtual memory exhausted");
5266 /* This function is based on the one in libiberty. */
5269 concat
VPROTO((char *first
, ...))
5271 register int length
;
5272 register char *newstr
;
5276 #ifndef ANSI_PROTOTYPES
5280 /* First compute the size of the result and get sufficient memory. */
5282 VA_START (args
, first
);
5283 #ifndef ANSI_PROTOTYPES
5284 first
= va_arg (args
, char *);
5292 length
+= strlen (arg
);
5293 arg
= va_arg (args
, char *);
5296 newstr
= (char *) xmalloc (length
+ 1);
5299 /* Now copy the individual pieces to the result string. */
5301 VA_START (args
, first
);
5302 #ifndef ANSI_PROTOTYPES
5303 first
= va_arg (args
, char *);
5312 arg
= va_arg (args
, char *);
5321 save_string (s
, len
)
5325 register char *result
= xmalloc (len
+ 1);
5327 bcopy (s
, result
, len
);
5333 pfatal_with_name (name
)
5336 fatal ("%s: %s", name
, my_strerror (errno
));
5340 perror_with_name (name
)
5343 error ("%s: %s", name
, my_strerror (errno
));
5347 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
5351 int save_errno
= errno
;
5355 /* Space for trailing '\0' is in %s. */
5356 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
5357 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
5361 fatal ("%s: %s", errmsg_fmt
, my_strerror (save_errno
));
5364 /* More 'friendly' abort that prints the line and file.
5365 config.h can #define abort fancy_abort if you like that sort of thing. */
5370 fatal ("Internal gcc abort.");
5373 /* Output an error message and exit */
5376 fatal
VPROTO((char *format
, ...))
5378 #ifndef ANSI_PROTOTYPES
5383 VA_START (ap
, format
);
5385 #ifndef ANSI_PROTOTYPES
5386 format
= va_arg (ap
, char *);
5389 fprintf (stderr
, "%s: ", programname
);
5390 vfprintf (stderr
, format
, ap
);
5392 fprintf (stderr
, "\n");
5393 delete_temp_files ();
5398 error
VPROTO((char *format
, ...))
5400 #ifndef ANSI_PROTOTYPES
5405 VA_START (ap
, format
);
5407 #ifndef ANSI_PROTOTYPES
5408 format
= va_arg (ap
, char *);
5411 fprintf (stderr
, "%s: ", programname
);
5412 vfprintf (stderr
, format
, ap
);
5415 fprintf (stderr
, "\n");
5419 validate_all_switches ()
5421 struct compiler
*comp
;
5424 struct spec_list
*spec
;
5426 for (comp
= compilers
; comp
->spec
[0]; comp
++)
5429 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
5433 if (c
== '%' && *p
== '{')
5434 /* We have a switch spec. */
5435 validate_switches (p
+ 1);
5439 /* look through the linked list of specs read from the specs file */
5440 for (spec
= specs
; spec
; spec
= spec
->next
)
5442 p
= *(spec
->ptr_spec
);
5444 if (c
== '%' && *p
== '{')
5445 /* We have a switch spec. */
5446 validate_switches (p
+ 1);
5449 p
= link_command_spec
;
5451 if (c
== '%' && *p
== '{')
5452 /* We have a switch spec. */
5453 validate_switches (p
+ 1);
5456 /* Look at the switch-name that comes after START
5457 and mark as valid all supplied switches that match it. */
5460 validate_switches (start
)
5463 register char *p
= start
;
5478 while (*p
!= ':' && *p
!= '}') p
++;
5482 else if (p
[-1] == '*')
5484 /* Mark all matching switches as valid. */
5486 for (i
= 0; i
< n_switches
; i
++)
5487 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
5488 switches
[i
].valid
= 1;
5492 /* Mark an exact matching switch as valid. */
5493 for (i
= 0; i
< n_switches
; i
++)
5495 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5496 && switches
[i
].part1
[p
- filter
] == 0)
5497 switches
[i
].valid
= 1;
5502 /* Check whether a particular argument was used. The first time we
5503 canonicalize the switches to keep only the ones we care about. */
5517 static struct mswitchstr
*mswitches
;
5518 static int n_mswitches
;
5523 struct mswitchstr
*matches
;
5527 /* Break multilib_matches into the component strings of string and replacement
5529 for (q
= multilib_matches
; *q
!= '\0'; q
++)
5533 matches
= (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
5535 q
= multilib_matches
;
5546 matches
[i
].len
= q
- matches
[i
].str
;
5548 matches
[i
].replace
= ++q
;
5549 while (*q
!= ';' && *q
!= '\0')
5555 matches
[i
].rep_len
= q
- matches
[i
].replace
;
5563 /* Now build a list of the replacement string for switches that we care
5564 about. Make sure we allocate at least one entry. This prevents
5565 xmalloc from calling fatal, and prevents us from re-executing this
5568 = (struct mswitchstr
*) xmalloc ((sizeof (struct mswitchstr
))
5569 * (n_switches
? n_switches
: 1));
5570 for (i
= 0; i
< n_switches
; i
++)
5572 int xlen
= strlen (switches
[i
].part1
);
5573 for (j
= 0; j
< cnt
; j
++)
5574 if (xlen
== matches
[j
].len
&& ! strcmp (switches
[i
].part1
, matches
[j
].str
))
5576 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
5577 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
5578 mswitches
[n_mswitches
].replace
= (char *)0;
5579 mswitches
[n_mswitches
].rep_len
= 0;
5586 for (i
= 0; i
< n_mswitches
; i
++)
5587 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
5594 default_arg (p
, len
)
5600 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+1)
5602 while (*start
== ' ' || *start
== '\t')
5608 for (end
= start
+1; *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
5611 if ((end
- start
) == len
&& strncmp (p
, start
, len
) == 0)
5621 /* Work out the subdirectory to use based on the
5622 options. The format of multilib_select is a list of elements.
5623 Each element is a subdirectory name followed by a list of options
5624 followed by a semicolon. gcc will consider each line in turn. If
5625 none of the options beginning with an exclamation point are
5626 present, and all of the other options are present, that
5627 subdirectory will be used. */
5632 char *p
= multilib_select
;
5634 char *this_path
, *this_arg
;
5640 /* Ignore newlines. */
5647 /* Get the initial path. */
5655 this_path_len
= p
- this_path
;
5657 /* Check the arguments. */
5672 while (*p
!= ' ' && *p
!= ';')
5679 if (*this_arg
!= '!')
5687 /* If this is a default argument, we can just ignore it.
5688 This is true even if this_arg begins with '!'. Beginning
5689 with '!' does not mean that this argument is necessarily
5690 inappropriate for this library: it merely means that
5691 there is a more specific library which uses this
5692 argument. If this argument is a default, we need not
5693 consider that more specific library. */
5694 if (! default_arg (this_arg
, p
- this_arg
))
5696 ok
= used_arg (this_arg
, p
- this_arg
);
5707 if (this_path_len
!= 1
5708 || this_path
[0] != '.')
5710 multilib_dir
= xmalloc (this_path_len
+ 1);
5711 strncpy (multilib_dir
, this_path
, this_path_len
);
5712 multilib_dir
[this_path_len
] = '\0';
5721 /* Print out the multiple library subdirectory selection
5722 information. This prints out a series of lines. Each line looks
5723 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5724 required. Only the desired options are printed out, the negative
5725 matches. The options are print without a leading dash. There are
5726 no spaces to make it easy to use the information in the shell.
5727 Each subdirectory is printed only once. This assumes the ordering
5728 generated by the genmultilib script. */
5731 print_multilib_info ()
5733 char *p
= multilib_select
;
5734 char *last_path
= 0, *this_path
;
5736 int last_path_len
= 0;
5740 /* Ignore newlines. */
5747 /* Get the initial path. */
5756 /* If this is a duplicate, skip it. */
5757 skip
= (last_path
!= 0 && p
- this_path
== last_path_len
5758 && ! strncmp (last_path
, this_path
, last_path_len
));
5760 last_path
= this_path
;
5761 last_path_len
= p
- this_path
;
5763 /* If this directory requires any default arguments, we can skip
5764 it. We will already have printed a directory identical to
5765 this one which does not require that default argument. */
5783 while (*q
!= ' ' && *q
!= ';')
5791 && default_arg (arg
, q
- arg
))
5806 for (p1
= last_path
; p1
< p
; p1
++)
5825 use_arg
= *p
!= '!';
5830 while (*p
!= ' ' && *p
!= ';')
5845 /* If there are extra options, print them now */
5846 if (multilib_extra
&& *multilib_extra
)
5848 int print_at
= TRUE
;
5851 for (q
= multilib_extra
; *q
!= '\0'; q
++)