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". */
39 #include "gansidecl.h"
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 /* Flag arguments to pexecute. */
48 #define PEXECUTE_FIRST 1
49 #define PEXECUTE_LAST 2
50 #define PEXECUTE_SEARCH 4
51 #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 extern char *choose_temp_base
PROTO((void));
89 #define kill(p,s) raise(s)
92 /* If a stage of compilation returns an exit status >= 1,
93 compilation of that file ceases. */
95 #define MIN_FATAL_STATUS 1
97 /* Flag saying to print the directories gcc will search through looking for
98 programs, libraries, etc. */
100 static int print_search_dirs
;
102 /* Flag saying to print the full filename of this file
103 as found through our usual search mechanism. */
105 static char *print_file_name
= NULL
;
107 /* As print_file_name, but search for executable file. */
109 static char *print_prog_name
= NULL
;
111 /* Flag saying to print the relative path we'd use to
112 find libgcc.a given the current compiler flags. */
114 static int print_multi_directory
;
116 /* Flag saying to print the list of subdirectories and
117 compiler flags used to select them in a standard form. */
119 static int print_multi_lib
;
121 /* Flag indicating whether we should print the command and arguments */
123 static int verbose_flag
;
125 /* Nonzero means write "temp" files in source directory
126 and use the source file's name in them, and don't delete them. */
128 static int save_temps_flag
;
130 /* The compiler version. */
132 static char *compiler_version
;
134 /* The target version specified with -V */
136 static char *spec_version
= DEFAULT_TARGET_VERSION
;
138 /* The target machine specified with -b. */
140 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
142 /* Nonzero if cross-compiling.
143 When -b is used, the value comes from the `specs' file. */
146 static char *cross_compile
= "1";
148 static char *cross_compile
= "0";
151 /* The number of errors that have occurred; the link phase will not be
152 run if this is non-zero. */
153 static int error_count
= 0;
155 /* This is the obstack which we use to allocate many strings. */
157 static struct obstack obstack
;
159 /* This is the obstack to build an environment variable to pass to
160 collect2 that describes all of the relevant switches of what to
161 pass the compiler in building the list of pointers to constructors
164 static struct obstack collect_obstack
;
166 extern char *version_string
;
168 /* Forward declaration for prototypes. */
171 static void init_spec
PROTO((void));
172 static void read_specs
PROTO((char *, int));
173 static void set_spec
PROTO((char *, char *));
174 static struct compiler
*lookup_compiler
PROTO((char *, int, char *));
175 static char *build_search_list
PROTO((struct path_prefix
*, char *, int));
176 static void putenv_from_prefixes
PROTO((struct path_prefix
*, char *));
177 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
178 static void add_prefix
PROTO((struct path_prefix
*, char *, char *,
180 static char *skip_whitespace
PROTO((char *));
181 static void record_temp_file
PROTO((char *, int, int));
182 static void delete_if_ordinary
PROTO((char *));
183 static void delete_temp_files
PROTO((void));
184 static void delete_failure_queue
PROTO((void));
185 static void clear_failure_queue
PROTO((void));
186 static int check_live_switch
PROTO((int, int));
187 static char *handle_braces
PROTO((char *));
188 static char *save_string
PROTO((char *, int));
189 static char *concat
PVPROTO((char *, ...));
190 static int do_spec
PROTO((char *));
191 static int do_spec_1
PROTO((char *, int, char *));
192 static char *find_file
PROTO((char *));
193 static int is_directory
PROTO((char *, char *, int));
194 static void validate_switches
PROTO((char *));
195 static void validate_all_switches
PROTO((void));
196 static void give_switch
PROTO((int, int, int));
197 static int used_arg
PROTO((char *, int));
198 static int default_arg
PROTO((char *, int));
199 static void set_multilib_dir
PROTO((void));
200 static void print_multilib_info
PROTO((void));
201 static void pfatal_with_name
PROTO((char *));
202 static void perror_with_name
PROTO((char *));
203 static void pfatal_pexecute
PROTO((char *, char *));
204 static void snapshot_warning
PROTO((void));
206 static void fatal
PVPROTO((char *, ...));
207 static void error
PVPROTO((char *, ...));
208 static void notice
PVPROTO((char *, ...));
210 /* We must not provide any prototype here, even if ANSI C. */
211 static void fatal
PROTO(());
212 static void error
PROTO(());
213 static void notice
PROTO(());
220 /* Specs are strings containing lines, each of which (if not blank)
221 is made up of a program name, and arguments separated by spaces.
222 The program name must be exact and start from root, since no path
223 is searched and it is unreliable to depend on the current working directory.
224 Redirection of input or output is not supported; the subprograms must
225 accept filenames saying what files to read and write.
227 In addition, the specs can contain %-sequences to substitute variable text
228 or for conditional text. Here is a table of all defined %-sequences.
229 Note that spaces are not generated automatically around the results of
230 expanding these sequences; therefore, you can concatenate them together
231 or with constant text in a single argument.
233 %% substitute one % into the program name or argument.
234 %i substitute the name of the input file being processed.
235 %b substitute the basename of the input file being processed.
236 This is the substring up to (and not including) the last period
237 and not including the directory.
238 %g substitute the temporary-file-name-base. This is a string chosen
239 once per compilation. Different temporary file names are made by
240 concatenation of constant strings on the end, as in `%g.s'.
241 %g also has the same effect of %d.
242 %u like %g, but make the temporary file name unique.
243 %U returns the last file name generated with %u.
244 %d marks the argument containing or following the %d as a
245 temporary file name, so that that file will be deleted if CC exits
246 successfully. Unlike %g, this contributes no text to the argument.
247 %w marks the argument containing or following the %w as the
248 "output file" of this compilation. This puts the argument
249 into the sequence of arguments that %o will substitute later.
251 like %{...} but mark last argument supplied within
252 as a file to be deleted on failure.
253 %o substitutes the names of all the output files, with spaces
254 automatically placed around them. You should write spaces
255 around the %o as well or the results are undefined.
256 %o is for use in the specs for running the linker.
257 Input files whose names have no recognized suffix are not compiled
258 at all, but they are included among the output files, so they will
260 %O substitutes the suffix for object files.
261 %p substitutes the standard macro predefinitions for the
262 current target machine. Use this when running cpp.
263 %P like %p, but puts `__' before and after the name of each macro.
264 (Except macros that already have __.)
266 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
267 %s current argument is the name of a library or startup file of some sort.
268 Search for that file in a standard list of directories
269 and substitute the full name found.
270 %eSTR Print STR as an error message. STR is terminated by a newline.
271 Use this when inconsistent options are detected.
272 %x{OPTION} Accumulate an option for %X.
273 %X Output the accumulated linker options specified by compilations.
274 %Y Output the accumulated assembler options specified by compilations.
275 %Z Output the accumulated preprocessor options specified by compilations.
276 %v1 Substitute the major version number of GCC.
277 (For version 2.5.n, this is 2.)
278 %v2 Substitute the minor version number of GCC.
279 (For version 2.5.n, this is 5.)
280 %a process ASM_SPEC as a spec.
281 This allows config.h to specify part of the spec for running as.
282 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
283 used here. This can be used to run a post-processor after the
284 assembler has done its job.
285 %D Dump out a -L option for each directory in startfile_prefixes.
286 If multilib_dir is set, extra entries are generated with it affixed.
287 %l process LINK_SPEC as a spec.
288 %L process LIB_SPEC as a spec.
289 %G process LIBGCC_SPEC as a spec.
290 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
291 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
292 %c process SIGNED_CHAR_SPEC as a spec.
293 %C process CPP_SPEC as a spec. A capital C is actually used here.
294 %1 process CC1_SPEC as a spec.
295 %2 process CC1PLUS_SPEC as a spec.
296 %| output "-" if the input for the current command is coming from a pipe.
297 %* substitute the variable part of a matched option. (See below.)
298 Note that each comma in the substituted string is replaced by
300 %{S} substitutes the -S switch, if that switch was given to CC.
301 If that switch was not specified, this substitutes nothing.
302 Here S is a metasyntactic variable.
303 %{S*} substitutes all the switches specified to CC whose names start
304 with -S. This is used for -o, -D, -I, etc; switches that take
305 arguments. CC considers `-o foo' as being one switch whose
306 name starts with `o'. %{o*} would substitute this text,
307 including the space; thus, two arguments would be generated.
308 %{^S*} likewise, but don't put a blank between a switch and any args.
309 %{S*:X} substitutes X if one or more switches whose names start with -S are
310 specified to CC. Note that the tail part of the -S option
311 (i.e. the part matched by the `*') will be substituted for each
312 occurrence of %* within X.
313 %{S:X} substitutes X, but only if the -S switch was given to CC.
314 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
315 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
316 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
317 %{.S:X} substitutes X, but only if processing a file with suffix S.
318 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
319 %(Spec) processes a specification defined in a specs file as *Spec:
320 %[Spec] as above, but put __ around -D arguments
322 The conditional text X in a %{S:X} or %{!S:X} construct may contain
323 other nested % constructs or spaces, or even newlines. They are
324 processed as usual, as described above.
326 The -O, -f, -m, and -W switches are handled specifically in these
327 constructs. If another value of -O or the negated form of a -f, -m, or
328 -W switch is found later in the command line, the earlier switch
329 value is ignored, except with {S*} where S is just one letter; this
330 passes all matching options.
332 The character | is used to indicate that a command should be piped to
333 the following command, but only if -pipe is specified.
335 Note that it is built into CC which switches take arguments and which
336 do not. You might think it would be useful to generalize this to
337 allow each compiler's spec to say which switches take arguments. But
338 this cannot be done in a consistent fashion. CC cannot even decide
339 which input files have been specified without knowing which switches
340 take arguments, and it must know which input files to compile in order
341 to tell which compilers to run.
343 CC also knows implicitly that arguments starting in `-l' are to be
344 treated as compiler output files, and passed to the linker in their
345 proper position among the other output files. */
347 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
349 /* config.h can define ASM_SPEC to provide extra args to the assembler
350 or extra switch-translations. */
355 /* config.h can define ASM_FINAL_SPEC to run a post processor after
356 the assembler has run. */
357 #ifndef ASM_FINAL_SPEC
358 #define ASM_FINAL_SPEC ""
361 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
362 or extra switch-translations. */
367 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
368 or extra switch-translations. */
373 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
374 or extra switch-translations. */
376 #define CC1PLUS_SPEC ""
379 /* config.h can define LINK_SPEC to provide extra args to the linker
380 or extra switch-translations. */
385 /* config.h can define LIB_SPEC to override the default libraries. */
387 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
390 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
393 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
394 /* Have gcc do the search for libgcc.a. */
395 #define LIBGCC_SPEC "libgcc.a%s"
397 #define LIBGCC_SPEC "-lgcc"
401 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
402 #ifndef STARTFILE_SPEC
403 #define STARTFILE_SPEC \
404 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
407 /* config.h can define SWITCHES_NEED_SPACES to control which options
408 require spaces between the option and the argument. */
409 #ifndef SWITCHES_NEED_SPACES
410 #define SWITCHES_NEED_SPACES ""
413 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
415 #define ENDFILE_SPEC ""
418 /* This spec is used for telling cpp whether char is signed or not. */
419 #ifndef SIGNED_CHAR_SPEC
420 /* Use #if rather than ?:
421 because MIPS C compiler rejects like ?: in initializers. */
422 #if DEFAULT_SIGNED_CHAR
423 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
425 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
429 static char *cpp_spec
= CPP_SPEC
;
430 static char *cpp_predefines
= CPP_PREDEFINES
;
431 static char *cc1_spec
= CC1_SPEC
;
432 static char *cc1plus_spec
= CC1PLUS_SPEC
;
433 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
434 static char *asm_spec
= ASM_SPEC
;
435 static char *asm_final_spec
= ASM_FINAL_SPEC
;
436 static char *link_spec
= LINK_SPEC
;
437 static char *lib_spec
= LIB_SPEC
;
438 static char *libgcc_spec
= LIBGCC_SPEC
;
439 static char *endfile_spec
= ENDFILE_SPEC
;
440 static char *startfile_spec
= STARTFILE_SPEC
;
441 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
443 /* Some compilers have limits on line lengths, and the multilib_select
444 and/or multilib_matches strings can be very long, so we build them at
446 static struct obstack multilib_obstack
;
447 static char *multilib_select
;
448 static char *multilib_matches
;
449 static char *multilib_defaults
;
450 #include "multilib.h"
452 /* Check whether a particular argument is a default argument. */
454 #ifndef MULTILIB_DEFAULTS
455 #define MULTILIB_DEFAULTS { "" }
458 static char *multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
461 struct user_specs
*next
;
465 static struct user_specs
*user_specs_head
, *user_specs_tail
;
467 /* This defines which switch letters take arguments. */
469 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
470 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
471 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
472 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
473 || (CHAR) == 'L' || (CHAR) == 'A')
475 #ifndef SWITCH_TAKES_ARG
476 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
479 /* This defines which multi-letter switches take arguments. */
481 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
482 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
483 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
484 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
485 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
486 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
487 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
489 #ifndef WORD_SWITCH_TAKES_ARG
490 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
493 /* Record the mapping from file suffixes for compilation specs. */
497 char *suffix
; /* Use this compiler for input files
498 whose names end in this suffix. */
500 char *spec
[4]; /* To use this compiler, concatenate these
501 specs and pass to do_spec. */
504 /* Pointer to a vector of `struct compiler' that gives the spec for
505 compiling a file, based on its suffix.
506 A file that does not end in any of these suffixes will be passed
507 unchanged to the loader and nothing else will be done to it.
509 An entry containing two 0s is used to terminate the vector.
511 If multiple entries match a file, the last matching one is used. */
513 static struct compiler
*compilers
;
515 /* Number of entries in `compilers', not counting the null terminator. */
517 static int n_compilers
;
519 /* The default list of file name suffixes and their compilation specs. */
521 static struct compiler default_compilers
[] =
523 /* Add lists of suffixes of known languages here. If those languages
524 were not present when we built the driver, we will hit these copies
525 and be given a more meaningful error than "file not used since
526 linking is not done". */
527 {".cc", "#C++"}, {".cxx", "#C++"}, {".cpp", "#C++"}, {".c++", "#C++"},
529 {".ads", "#Ada"}, {".adb", "#Ada"},
530 {".f", "#Fortran"}, {".for", "#Fortran"}, {".F", "#Fortran"},
531 {".fpp", "#Fortran"},
532 {".p", "#Pascal"}, {".pas", "#Pascal"},
533 /* Next come the entries for C. */
536 "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
537 %{C:%{!E:%eGNU C does not support -C without using -E}}\
538 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
539 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
540 %{ansi:-trigraphs -D__STRICT_ANSI__}\
541 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
542 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
543 %{traditional-cpp:-traditional}\
544 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
545 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
546 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
547 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
548 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
549 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
551 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
552 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
554 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
555 %{!pipe:%g.s} %A\n }}}}"},
557 "%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
558 %{C:%{!E:%eGNU C does not support -C without using -E}}\
559 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
560 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
561 %{ansi:-trigraphs -D__STRICT_ANSI__}\
562 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
563 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
564 %{traditional-cpp:-traditional}\
565 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
567 %{!E:%e-E required when input is from standard input}"},
568 {".m", "@objective-c"},
570 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
571 %{C:%{!E:%eGNU C does not support -C without using -E}}\
572 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
573 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
574 %{ansi:-trigraphs -D__STRICT_ANSI__}\
575 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
576 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
577 %{traditional-cpp:-traditional}\
578 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
579 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
580 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
581 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
582 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
583 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
584 -lang-objc %{gen-decls} \
586 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
587 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
589 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
590 %{!pipe:%g.s} %A\n }}}}"},
593 "%{!E:%eCompilation of header file requested} \
594 cpp %{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 %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
601 %{traditional-cpp:-traditional}\
602 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
604 {".i", "@cpp-output"},
606 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
607 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
608 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
610 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
611 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
613 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
614 %{!pipe:%g.s} %A\n }}}}"},
615 {".s", "@assembler"},
617 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
618 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
620 {".S", "@assembler-with-cpp"},
621 {"@assembler-with-cpp",
622 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
623 %{C:%{!E:%eGNU C does not support -C without using -E}}\
624 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
625 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
626 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
627 %{traditional-cpp:-traditional}\
628 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
629 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
630 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
631 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
632 %{!pipe:%g.s} %A\n }}}}"},
634 /* Mark end of table */
638 /* Number of elements in default_compilers, not counting the terminator. */
640 static int n_default_compilers
641 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
643 /* Here is the spec for running the linker, after compiling all files. */
645 /* -u* was put back because both BSD and SysV seem to support it. */
646 /* %{static:} simply prevents an error message if the target machine
647 doesn't handle -static. */
648 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
649 scripts which exist in user specified directories, or in standard
651 #ifdef LINK_COMMAND_SPEC
652 /* Provide option to override link_command_spec from machine specific
653 configuration files. */
654 static char *link_command_spec
=
657 #ifdef LINK_LIBGCC_SPECIAL
658 /* Don't generate -L options. */
659 static char *link_command_spec
= "\
661 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
662 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
663 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
665 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
666 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
671 static char *link_command_spec
= "\
673 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
674 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
675 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
676 %{static:} %{L*} %D %o\
677 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
678 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
684 /* A vector of options to give to the linker.
685 These options are accumulated by %x,
686 and substituted into the linker command with %X. */
687 static int n_linker_options
;
688 static char **linker_options
;
690 /* A vector of options to give to the assembler.
691 These options are accumulated by -Wa,
692 and substituted into the assembler command with %Y. */
693 static int n_assembler_options
;
694 static char **assembler_options
;
696 /* A vector of options to give to the preprocessor.
697 These options are accumulated by -Wp,
698 and substituted into the preprocessor command with %Z. */
699 static int n_preprocessor_options
;
700 static char **preprocessor_options
;
702 /* Define how to map long options into short ones. */
704 /* This structure describes one mapping. */
707 /* The long option's name. */
709 /* The equivalent short option. */
711 /* Argument info. A string of flag chars; NULL equals no options.
712 a => argument required.
713 o => argument optional.
714 j => join argument to equivalent, making one word.
715 * => require other text after NAME as an argument. */
719 /* This is the table of mappings. Mappings are tried sequentially
720 for each option encountered; the first one that matches, wins. */
722 struct option_map option_map
[] =
724 {"--all-warnings", "-Wall", 0},
725 {"--ansi", "-ansi", 0},
726 {"--assemble", "-S", 0},
727 {"--assert", "-A", "a"},
728 {"--comments", "-C", 0},
729 {"--compile", "-c", 0},
730 {"--debug", "-g", "oj"},
731 {"--define-macro", "-D", "aj"},
732 {"--dependencies", "-M", 0},
733 {"--dump", "-d", "a"},
734 {"--dumpbase", "-dumpbase", "a"},
735 {"--entry", "-e", 0},
736 {"--extra-warnings", "-W", 0},
737 {"--for-assembler", "-Wa", "a"},
738 {"--for-linker", "-Xlinker", "a"},
739 {"--force-link", "-u", "a"},
740 {"--imacros", "-imacros", "a"},
741 {"--include", "-include", "a"},
742 {"--include-barrier", "-I-", 0},
743 {"--include-directory", "-I", "aj"},
744 {"--include-directory-after", "-idirafter", "a"},
745 {"--include-prefix", "-iprefix", "a"},
746 {"--include-with-prefix", "-iwithprefix", "a"},
747 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
748 {"--include-with-prefix-after", "-iwithprefix", "a"},
749 {"--language", "-x", "a"},
750 {"--library-directory", "-L", "a"},
751 {"--machine", "-m", "aj"},
752 {"--machine-", "-m", "*j"},
753 {"--no-line-commands", "-P", 0},
754 {"--no-precompiled-includes", "-noprecomp", 0},
755 {"--no-standard-includes", "-nostdinc", 0},
756 {"--no-standard-libraries", "-nostdlib", 0},
757 {"--no-warnings", "-w", 0},
758 {"--optimize", "-O", "oj"},
759 {"--output", "-o", "a"},
760 {"--pedantic", "-pedantic", 0},
761 {"--pedantic-errors", "-pedantic-errors", 0},
762 {"--pipe", "-pipe", 0},
763 {"--prefix", "-B", "a"},
764 {"--preprocess", "-E", 0},
765 {"--print-search-dirs", "-print-search-dirs", 0},
766 {"--print-file-name", "-print-file-name=", "aj"},
767 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
768 {"--print-missing-file-dependencies", "-MG", 0},
769 {"--print-multi-lib", "-print-multi-lib", 0},
770 {"--print-multi-directory", "-print-multi-directory", 0},
771 {"--print-prog-name", "-print-prog-name=", "aj"},
772 {"--profile", "-p", 0},
773 {"--profile-blocks", "-a", 0},
774 {"--quiet", "-q", 0},
775 {"--save-temps", "-save-temps", 0},
776 {"--shared", "-shared", 0},
777 {"--silent", "-q", 0},
778 {"--specs", "-specs=", "aj"},
779 {"--static", "-static", 0},
780 {"--symbolic", "-symbolic", 0},
781 {"--target", "-b", "a"},
782 {"--trace-includes", "-H", 0},
783 {"--traditional", "-traditional", 0},
784 {"--traditional-cpp", "-traditional-cpp", 0},
785 {"--trigraphs", "-trigraphs", 0},
786 {"--undefine-macro", "-U", "aj"},
787 {"--use-version", "-V", "a"},
788 {"--user-dependencies", "-MM", 0},
789 {"--verbose", "-v", 0},
790 {"--version", "-dumpversion", 0},
791 {"--warn-", "-W", "*j"},
792 {"--write-dependencies", "-MD", 0},
793 {"--write-user-dependencies", "-MMD", 0},
797 /* Translate the options described by *ARGCP and *ARGVP.
798 Make a new vector and store it back in *ARGVP,
799 and store its length in *ARGVC. */
802 translate_options (argcp
, argvp
)
808 char **argv
= *argvp
;
809 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
813 newv
[newindex
++] = argv
[i
++];
817 /* Translate -- options. */
818 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
820 /* Find a mapping that applies to this option. */
821 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
823 int optlen
= strlen (option_map
[j
].name
);
824 int arglen
= strlen (argv
[i
]);
825 int complen
= arglen
> optlen
? optlen
: arglen
;
826 char *arginfo
= option_map
[j
].arg_info
;
831 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
838 k
< sizeof (option_map
) / sizeof (option_map
[0]);
840 if (strlen (option_map
[k
].name
) >= arglen
841 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
843 error ("Ambiguous abbreviation %s", argv
[i
]);
847 if (k
!= sizeof (option_map
) / sizeof (option_map
[0]))
853 /* If the option has an argument, accept that. */
854 if (argv
[i
][optlen
] == '=')
855 arg
= argv
[i
] + optlen
+ 1;
857 /* If this mapping requires extra text at end of name,
858 accept that as "argument". */
859 else if (index (arginfo
, '*') != 0)
860 arg
= argv
[i
] + optlen
;
862 /* Otherwise, extra text at end means mismatch.
863 Try other mappings. */
868 else if (index (arginfo
, '*') != 0)
870 error ("Incomplete `%s' option", option_map
[j
].name
);
874 /* Handle arguments. */
875 if (index (arginfo
, 'a') != 0)
881 error ("Missing argument to `%s' option",
889 else if (index (arginfo
, '*') != 0)
891 else if (index (arginfo
, 'o') == 0)
894 error ("Extraneous argument to `%s' option",
899 /* Store the translation as one argv elt or as two. */
900 if (arg
!= 0 && index (arginfo
, 'j') != 0)
901 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
905 newv
[newindex
++] = option_map
[j
].equivalent
;
906 newv
[newindex
++] = arg
;
909 newv
[newindex
++] = option_map
[j
].equivalent
;
917 /* Handle old-fashioned options--just copy them through,
918 with their arguments. */
919 else if (argv
[i
][0] == '-')
921 char *p
= argv
[i
] + 1;
925 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
926 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
927 else if (WORD_SWITCH_TAKES_ARG (p
))
928 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
929 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
932 else if (! strcmp (p
, "Xlinker"))
935 /* Watch out for an option at the end of the command line that
936 is missing arguments, and avoid skipping past the end of the
938 if (nskip
+ i
> argc
)
943 newv
[newindex
++] = argv
[i
++];
948 /* Ordinary operands, or +e options. */
949 newv
[newindex
++] = argv
[i
++];
971 if (e
> 0 && e
< sys_nerr
)
972 return sys_errlist
[e
];
984 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
985 be considered whitespace. */
986 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
988 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
992 while (*p
!= '\n') p
++;
1002 /* Structure to keep track of the specs that have been defined so far.
1003 These are accessed using %(specname) or %[specname] in a compiler
1008 /* The following 2 fields must be first */
1009 /* to allow EXTRA_SPECS to be initialized */
1010 char *name
; /* name of the spec. */
1011 char *ptr
; /* available ptr if no static pointer */
1013 /* The following fields are not initialized */
1014 /* by EXTRA_SPECS */
1015 char **ptr_spec
; /* pointer to the spec itself. */
1016 struct spec_list
*next
; /* Next spec in linked list. */
1017 int name_len
; /* length of the name */
1018 int alloc_p
; /* whether string was allocated */
1021 #define INIT_STATIC_SPEC(NAME,PTR) \
1022 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1024 /* List of statically defined specs */
1025 static struct spec_list static_specs
[] = {
1026 INIT_STATIC_SPEC ("asm", &asm_spec
),
1027 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1028 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1029 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1030 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1031 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1032 INIT_STATIC_SPEC ("link", &link_spec
),
1033 INIT_STATIC_SPEC ("lib", &lib_spec
),
1034 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1035 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1036 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces
),
1037 INIT_STATIC_SPEC ("signed_char", &signed_char_spec
),
1038 INIT_STATIC_SPEC ("predefines", &cpp_predefines
),
1039 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1040 INIT_STATIC_SPEC ("version", &compiler_version
),
1041 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1042 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1043 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1044 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1047 #ifdef EXTRA_SPECS /* additional specs needed */
1048 static struct spec_list extra_specs
[] = { EXTRA_SPECS
};
1051 /* List of dynamically allocates specs that have been defined so far. */
1053 static struct spec_list
*specs
= (struct spec_list
*)0;
1056 /* Initialize the specs lookup routines. */
1061 struct spec_list
*next
= (struct spec_list
*)0;
1062 struct spec_list
*sl
= (struct spec_list
*)0;
1066 return; /* already initialized */
1069 notice ("Using builtin specs.\n");
1072 for (i
= (sizeof (extra_specs
) / sizeof (extra_specs
[0])) - 1; i
>= 0; i
--)
1074 sl
= &extra_specs
[i
];
1076 sl
->name_len
= strlen (sl
->name
);
1077 sl
->ptr_spec
= &sl
->ptr
;
1082 for (i
= (sizeof (static_specs
) / sizeof (static_specs
[0])) - 1; i
>= 0; i
--)
1084 sl
= &static_specs
[i
];
1093 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1094 removed; If the spec starts with a + then SPEC is added to the end of the
1098 set_spec (name
, spec
)
1102 struct spec_list
*sl
;
1104 int name_len
= strlen (name
);
1107 /* If this is the first call, initialize the statically allocated specs */
1110 struct spec_list
*next
= (struct spec_list
*)0;
1111 for (i
= (sizeof (static_specs
) / sizeof (static_specs
[0])) - 1;
1114 sl
= &static_specs
[i
];
1121 /* See if the spec already exists */
1122 for (sl
= specs
; sl
; sl
= sl
->next
)
1123 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1128 /* Not found - make it */
1129 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1130 sl
->name
= save_string (name
, strlen (name
));
1131 sl
->name_len
= name_len
;
1132 sl
->ptr_spec
= &sl
->ptr
;
1134 *(sl
->ptr_spec
) = "";
1139 old_spec
= *(sl
->ptr_spec
);
1140 *(sl
->ptr_spec
) = ((spec
[0] == '+' && isspace (spec
[1]))
1141 ? concat (old_spec
, spec
+ 1, NULL_PTR
)
1142 : save_string (spec
, strlen (spec
)));
1146 notice ("Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1149 /* Free the old spec */
1150 if (old_spec
&& sl
->alloc_p
)
1156 /* Accumulate a command (program name and args), and run it. */
1158 /* Vector of pointers to arguments in the current line of specifications. */
1160 static char **argbuf
;
1162 /* Number of elements allocated in argbuf. */
1164 static int argbuf_length
;
1166 /* Number of elements in argbuf currently in use (containing args). */
1168 static int argbuf_index
;
1170 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1171 temp file. Used only if MKTEMP_EACH_FILE. */
1173 static struct temp_name
{
1174 char *suffix
; /* suffix associated with the code. */
1175 int length
; /* strlen (suffix). */
1176 int unique
; /* Indicates whether %g or %u/%U was used. */
1177 char *filename
; /* associated filename. */
1178 int filename_length
; /* strlen (filename). */
1179 struct temp_name
*next
;
1182 /* Number of commands executed so far. */
1184 static int execution_count
;
1186 /* Number of commands that exited with a signal. */
1188 static int signal_count
;
1190 /* Name with which this program was invoked. */
1192 static char *programname
;
1194 /* Structures to keep track of prefixes to try when looking for files. */
1198 char *prefix
; /* String to prepend to the path. */
1199 struct prefix_list
*next
; /* Next in linked list. */
1200 int require_machine_suffix
; /* Don't use without machine_suffix. */
1201 /* 2 means try both machine_suffix and just_machine_suffix. */
1202 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1207 struct prefix_list
*plist
; /* List of prefixes to try */
1208 int max_len
; /* Max length of a prefix in PLIST */
1209 char *name
; /* Name of this list (used in config stuff) */
1212 /* List of prefixes to try when looking for executables. */
1214 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1216 /* List of prefixes to try when looking for startup (crt0) files. */
1218 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1220 /* List of prefixes to try when looking for include files. */
1222 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1224 /* Suffix to attach to directories searched for commands.
1225 This looks like `MACHINE/VERSION/'. */
1227 static char *machine_suffix
= 0;
1229 /* Suffix to attach to directories searched for commands.
1230 This is just `MACHINE/'. */
1232 static char *just_machine_suffix
= 0;
1234 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1236 static char *gcc_exec_prefix
;
1238 /* Default prefixes to attach to command names. */
1240 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1241 #undef MD_EXEC_PREFIX
1242 #undef MD_STARTFILE_PREFIX
1243 #undef MD_STARTFILE_PREFIX_1
1246 #ifndef STANDARD_EXEC_PREFIX
1247 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1248 #endif /* !defined STANDARD_EXEC_PREFIX */
1250 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1251 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1252 #ifdef MD_EXEC_PREFIX
1253 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1256 #ifndef STANDARD_STARTFILE_PREFIX
1257 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1258 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1260 #ifdef MD_STARTFILE_PREFIX
1261 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1263 #ifdef MD_STARTFILE_PREFIX_1
1264 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1266 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1267 static char *standard_startfile_prefix_1
= "/lib/";
1268 static char *standard_startfile_prefix_2
= "/usr/lib/";
1270 #ifndef TOOLDIR_BASE_PREFIX
1271 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1273 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1274 static char *tooldir_prefix
;
1276 /* Subdirectory to use for locating libraries. Set by
1277 set_multilib_dir based on the compilation options. */
1279 static char *multilib_dir
;
1281 /* Clear out the vector of arguments (after a command is executed). */
1289 /* Add one argument to the vector at the end.
1290 This is done when a space is seen or at the end of the line.
1291 If DELETE_ALWAYS is nonzero, the arg is a filename
1292 and the file should be deleted eventually.
1293 If DELETE_FAILURE is nonzero, the arg is a filename
1294 and the file should be deleted if this compilation fails. */
1297 store_arg (arg
, delete_always
, delete_failure
)
1299 int delete_always
, delete_failure
;
1301 if (argbuf_index
+ 1 == argbuf_length
)
1303 = (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1305 argbuf
[argbuf_index
++] = arg
;
1306 argbuf
[argbuf_index
] = 0;
1308 if (delete_always
|| delete_failure
)
1309 record_temp_file (arg
, delete_always
, delete_failure
);
1312 /* Read compilation specs from a file named FILENAME,
1313 replacing the default ones.
1315 A suffix which starts with `*' is a definition for
1316 one of the machine-specific sub-specs. The "suffix" should be
1317 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1318 The corresponding spec is stored in asm_spec, etc.,
1319 rather than in the `compilers' vector.
1321 Anything invalid in the file is a fatal error. */
1324 read_specs (filename
, main_p
)
1330 struct stat statbuf
;
1335 notice ("Reading specs from %s\n", filename
);
1337 /* Open and stat the file. */
1338 desc
= open (filename
, O_RDONLY
, 0);
1340 pfatal_with_name (filename
);
1341 if (stat (filename
, &statbuf
) < 0)
1342 pfatal_with_name (filename
);
1344 /* Read contents of file into BUFFER. */
1345 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1346 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1348 pfatal_with_name (filename
);
1349 buffer
[readlen
] = 0;
1352 /* Scan BUFFER for specs, putting them in the vector. */
1358 char *in
, *out
, *p1
, *p2
, *p3
;
1360 /* Advance P in BUFFER to the next nonblank nocomment line. */
1361 p
= skip_whitespace (p
);
1365 /* Is this a special command that starts with '%'? */
1366 /* Don't allow this for the main specs file, since it would
1367 encourage people to overwrite it. */
1368 if (*p
== '%' && !main_p
)
1371 while (*p
&& *p
!= '\n')
1374 p
++; /* Skip '\n' */
1376 if (!strncmp (p1
, "%include", sizeof ("%include")-1)
1377 && (p1
[sizeof "%include" - 1] == ' '
1378 || p1
[sizeof "%include" - 1] == '\t'))
1382 p1
+= sizeof ("%include");
1383 while (*p1
== ' ' || *p1
== '\t')
1386 if (*p1
++ != '<' || p
[-2] != '>')
1387 fatal ("specs %%include syntax malformed after %d characters",
1391 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1392 read_specs (new_filename
? new_filename
: p1
, FALSE
);
1395 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
1396 && (p1
[sizeof "%include_noerr" - 1] == ' '
1397 || p1
[sizeof "%include_noerr" - 1] == '\t'))
1401 p1
+= sizeof "%include_noerr";
1402 while (*p1
== ' ' || *p1
== '\t') p1
++;
1404 if (*p1
++ != '<' || p
[-2] != '>')
1405 fatal ("specs %%include syntax malformed after %d characters",
1409 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1411 read_specs (new_filename
, FALSE
);
1412 else if (verbose_flag
)
1413 notice ("Could not find specs file %s\n", p1
);
1416 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
1417 && (p1
[sizeof "%rename" - 1] == ' '
1418 || p1
[sizeof "%rename" - 1] == '\t'))
1421 struct spec_list
*sl
;
1423 /* Get original name */
1424 p1
+= sizeof "%rename";
1425 while (*p1
== ' ' || *p1
== '\t')
1428 if (! isalpha (*p1
))
1429 fatal ("specs %%rename syntax malformed after %d characters",
1433 while (*p2
&& !isspace (*p2
))
1436 if (*p2
!= ' ' && *p2
!= '\t')
1437 fatal ("specs %%rename syntax malformed after %d characters",
1442 while (*p2
== ' ' || *p2
== '\t')
1445 if (! isalpha (*p2
))
1446 fatal ("specs %%rename syntax malformed after %d characters",
1449 /* Get new spec name */
1451 while (*p3
&& !isspace (*p3
))
1455 fatal ("specs %%rename syntax malformed after %d characters",
1459 for (sl
= specs
; sl
; sl
= sl
->next
)
1460 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
1464 fatal ("specs %s spec was not found to be renamed", p1
);
1466 if (strcmp (p1
, p2
) == 0)
1471 notice ("rename spec %s to %s\n", p1
, p2
);
1473 notice ("spec is '%s'\n\n", *(sl
->ptr_spec
));
1477 set_spec (p2
, *(sl
->ptr_spec
));
1479 free (*(sl
->ptr_spec
));
1481 *(sl
->ptr_spec
) = "";
1486 fatal ("specs unknown %% command after %d characters",
1490 /* Find the colon that should end the suffix. */
1492 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
1495 /* The colon shouldn't be missing. */
1497 fatal ("specs file malformed after %d characters", p1
- buffer
);
1499 /* Skip back over trailing whitespace. */
1501 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
1504 /* Copy the suffix to a string. */
1505 suffix
= save_string (p
, p2
- p
);
1506 /* Find the next line. */
1507 p
= skip_whitespace (p1
+ 1);
1509 fatal ("specs file malformed after %d characters", p
- buffer
);
1512 /* Find next blank line. */
1513 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n'))
1516 /* Specs end at the blank line and do not include the newline. */
1517 spec
= save_string (p
, p1
- p
);
1520 /* Delete backslash-newline sequences from the spec. */
1525 if (in
[0] == '\\' && in
[1] == '\n')
1527 else if (in
[0] == '#')
1528 while (*in
&& *in
!= '\n')
1536 if (suffix
[0] == '*')
1538 if (! strcmp (suffix
, "*link_command"))
1539 link_command_spec
= spec
;
1541 set_spec (suffix
+ 1, spec
);
1545 /* Add this pair to the vector. */
1547 = ((struct compiler
*)
1548 xrealloc (compilers
,
1549 (n_compilers
+ 2) * sizeof (struct compiler
)));
1551 compilers
[n_compilers
].suffix
= suffix
;
1552 bzero ((char *) compilers
[n_compilers
].spec
,
1553 sizeof compilers
[n_compilers
].spec
);
1554 compilers
[n_compilers
].spec
[0] = spec
;
1556 bzero ((char *) &compilers
[n_compilers
],
1557 sizeof compilers
[n_compilers
]);
1561 link_command_spec
= spec
;
1564 if (link_command_spec
== 0)
1565 fatal ("spec file has no spec for linking");
1568 /* Record the names of temporary files we tell compilers to write,
1569 and delete them at the end of the run. */
1571 /* This is the common prefix we use to make temp file names.
1572 It is chosen once for each run of this program.
1573 It is substituted into a spec by %g.
1574 Thus, all temp file names contain this prefix.
1575 In practice, all temp file names start with this prefix.
1577 This prefix comes from the envvar TMPDIR if it is defined;
1578 otherwise, from the P_tmpdir macro if that is defined;
1579 otherwise, in /usr/tmp or /tmp;
1580 or finally the current directory if all else fails. */
1582 static char *temp_filename
;
1584 /* Length of the prefix. */
1586 static int temp_filename_length
;
1588 /* Define the list of temporary files to delete. */
1593 struct temp_file
*next
;
1596 /* Queue of files to delete on success or failure of compilation. */
1597 static struct temp_file
*always_delete_queue
;
1598 /* Queue of files to delete on failure of compilation. */
1599 static struct temp_file
*failure_delete_queue
;
1601 /* Record FILENAME as a file to be deleted automatically.
1602 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1603 otherwise delete it in any case.
1604 FAIL_DELETE nonzero means delete it if a compilation step fails;
1605 otherwise delete it in any case. */
1608 record_temp_file (filename
, always_delete
, fail_delete
)
1613 register char *name
;
1614 name
= xmalloc (strlen (filename
) + 1);
1615 strcpy (name
, filename
);
1619 register struct temp_file
*temp
;
1620 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1621 if (! strcmp (name
, temp
->name
))
1624 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1625 temp
->next
= always_delete_queue
;
1627 always_delete_queue
= temp
;
1634 register struct temp_file
*temp
;
1635 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1636 if (! strcmp (name
, temp
->name
))
1639 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1640 temp
->next
= failure_delete_queue
;
1642 failure_delete_queue
= temp
;
1648 /* Delete all the temporary files whose names we previously recorded. */
1651 delete_if_ordinary (name
)
1658 printf ("Delete %s? (y or n) ", name
);
1662 while ((c
= getchar ()) != '\n' && c
!= EOF
)
1665 if (i
== 'y' || i
== 'Y')
1667 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1668 if (unlink (name
) < 0)
1670 perror_with_name (name
);
1674 delete_temp_files ()
1676 register struct temp_file
*temp
;
1678 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1679 delete_if_ordinary (temp
->name
);
1680 always_delete_queue
= 0;
1683 /* Delete all the files to be deleted on error. */
1686 delete_failure_queue ()
1688 register struct temp_file
*temp
;
1690 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1691 delete_if_ordinary (temp
->name
);
1695 clear_failure_queue ()
1697 failure_delete_queue
= 0;
1700 /* Routine to add variables to the environment. We do this to pass
1701 the pathname of the gcc driver, and the directories search to the
1702 collect2 program, which is being run as ld. This way, we can be
1703 sure of executing the right compiler when collect2 wants to build
1704 constructors and destructors. Since the environment variables we
1705 use come from an obstack, we don't have to worry about allocating
1714 #ifndef VMS /* nor about VMS */
1716 extern char **environ
;
1717 char **old_environ
= environ
;
1721 int str_len
= strlen (str
);
1725 while ((ch
= *p
++) != '\0' && ch
!= '=')
1731 /* Search for replacing an existing environment variable, and
1732 count the number of total environment variables. */
1733 for (envp
= old_environ
; *envp
; envp
++)
1736 if (!strncmp (str
, *envp
, name_len
))
1743 /* Add a new environment variable */
1744 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1746 bcopy ((char *) old_environ
, (char *) (environ
+ 1),
1747 sizeof (char *) * (num_envs
+1));
1752 #endif /* HAVE_PUTENV */
1755 /* Build a list of search directories from PATHS.
1756 PREFIX is a string to prepend to the list.
1757 If CHECK_DIR_P is non-zero we ensure the directory exists.
1758 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1759 It is also used by the --print-search-dirs flag. */
1762 build_search_list (paths
, prefix
, check_dir_p
)
1763 struct path_prefix
*paths
;
1767 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1769 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1770 int first_time
= TRUE
;
1771 struct prefix_list
*pprefix
;
1773 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
1775 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1777 int len
= strlen (pprefix
->prefix
);
1781 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
1784 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1787 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1788 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1791 if (just_machine_suffix
1792 && pprefix
->require_machine_suffix
== 2
1794 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
1797 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1800 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1801 obstack_grow (&collect_obstack
, just_machine_suffix
,
1805 if (! pprefix
->require_machine_suffix
)
1808 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1811 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1815 obstack_1grow (&collect_obstack
, '\0');
1816 return obstack_finish (&collect_obstack
);
1819 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1823 putenv_from_prefixes (paths
, env_var
)
1824 struct path_prefix
*paths
;
1827 putenv (build_search_list (paths
, env_var
, 1));
1830 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1831 access to check permissions.
1832 Return 0 if not found, otherwise return its name, allocated with malloc. */
1835 find_a_file (pprefix
, name
, mode
)
1836 struct path_prefix
*pprefix
;
1841 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1842 struct prefix_list
*pl
;
1843 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1846 len
+= strlen (machine_suffix
);
1848 temp
= xmalloc (len
);
1850 /* Determine the filename to execute (special case for absolute paths). */
1852 if (*name
== '/' || *name
== DIR_SEPARATOR
1853 /* Check for disk name on MS-DOS-based systems. */
1854 || (DIR_SEPARATOR
== '\\' && name
[1] == ':'
1855 && (name
[2] == DIR_SEPARATOR
|| name
[2] == '/')))
1857 if (access (name
, mode
))
1859 strcpy (temp
, name
);
1864 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1868 /* Some systems have a suffix for executable files.
1869 So try appending that first. */
1870 if (file_suffix
[0] != 0)
1872 strcpy (temp
, pl
->prefix
);
1873 strcat (temp
, machine_suffix
);
1874 strcat (temp
, name
);
1875 strcat (temp
, file_suffix
);
1876 if (access (temp
, mode
) == 0)
1878 if (pl
->used_flag_ptr
!= 0)
1879 *pl
->used_flag_ptr
= 1;
1884 /* Now try just the name. */
1885 strcpy (temp
, pl
->prefix
);
1886 strcat (temp
, machine_suffix
);
1887 strcat (temp
, name
);
1888 if (access (temp
, mode
) == 0)
1890 if (pl
->used_flag_ptr
!= 0)
1891 *pl
->used_flag_ptr
= 1;
1896 /* Certain prefixes are tried with just the machine type,
1897 not the version. This is used for finding as, ld, etc. */
1898 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
1900 /* Some systems have a suffix for executable files.
1901 So try appending that first. */
1902 if (file_suffix
[0] != 0)
1904 strcpy (temp
, pl
->prefix
);
1905 strcat (temp
, just_machine_suffix
);
1906 strcat (temp
, name
);
1907 strcat (temp
, file_suffix
);
1908 if (access (temp
, mode
) == 0)
1910 if (pl
->used_flag_ptr
!= 0)
1911 *pl
->used_flag_ptr
= 1;
1916 strcpy (temp
, pl
->prefix
);
1917 strcat (temp
, just_machine_suffix
);
1918 strcat (temp
, name
);
1919 if (access (temp
, mode
) == 0)
1921 if (pl
->used_flag_ptr
!= 0)
1922 *pl
->used_flag_ptr
= 1;
1927 /* Certain prefixes can't be used without the machine suffix
1928 when the machine or version is explicitly specified. */
1929 if (! pl
->require_machine_suffix
)
1931 /* Some systems have a suffix for executable files.
1932 So try appending that first. */
1933 if (file_suffix
[0] != 0)
1935 strcpy (temp
, pl
->prefix
);
1936 strcat (temp
, name
);
1937 strcat (temp
, file_suffix
);
1938 if (access (temp
, mode
) == 0)
1940 if (pl
->used_flag_ptr
!= 0)
1941 *pl
->used_flag_ptr
= 1;
1946 strcpy (temp
, pl
->prefix
);
1947 strcat (temp
, name
);
1948 if (access (temp
, mode
) == 0)
1950 if (pl
->used_flag_ptr
!= 0)
1951 *pl
->used_flag_ptr
= 1;
1961 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1962 at the start of the list, otherwise it goes at the end.
1964 If WARN is nonzero, we will warn if no file is found
1965 through this prefix. WARN should point to an int
1966 which will be set to 1 if this entry is used.
1968 COMPONENT is the value to be passed to update_path.
1970 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1971 the complete value of machine_suffix.
1972 2 means try both machine_suffix and just_machine_suffix. */
1975 add_prefix (pprefix
, prefix
, component
, first
, require_machine_suffix
, warn
)
1976 struct path_prefix
*pprefix
;
1980 int require_machine_suffix
;
1983 struct prefix_list
*pl
, **prev
;
1986 if (! first
&& pprefix
->plist
)
1988 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1993 prev
= &pprefix
->plist
;
1995 /* Keep track of the longest prefix */
1997 prefix
= update_path (prefix
, component
);
1998 len
= strlen (prefix
);
1999 if (len
> pprefix
->max_len
)
2000 pprefix
->max_len
= len
;
2002 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2003 pl
->prefix
= save_string (prefix
, len
);
2004 pl
->require_machine_suffix
= require_machine_suffix
;
2005 pl
->used_flag_ptr
= warn
;
2012 pl
->next
= (struct prefix_list
*) 0;
2016 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
2019 unused_prefix_warnings (pprefix
)
2020 struct path_prefix
*pprefix
;
2022 struct prefix_list
*pl
= pprefix
->plist
;
2026 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
2028 if (pl
->require_machine_suffix
&& machine_suffix
)
2029 error ("file path prefix `%s%s' never used", pl
->prefix
,
2032 error ("file path prefix `%s' never used", pl
->prefix
);
2034 /* Prevent duplicate warnings. */
2035 *pl
->used_flag_ptr
= 1;
2042 /* Get rid of all prefixes built up so far in *PLISTP. */
2045 free_path_prefix (pprefix
)
2046 struct path_prefix
*pprefix
;
2048 struct prefix_list
*pl
= pprefix
->plist
;
2049 struct prefix_list
*temp
;
2055 free (temp
->prefix
);
2056 free ((char *) temp
);
2059 pprefix
->plist
= (struct prefix_list
*) 0;
2062 /* Execute the command specified by the arguments on the current line of spec.
2063 When using pipes, this includes several piped-together commands
2064 with `|' between them.
2066 Return 0 if successful, -1 if failed. */
2072 int n_commands
; /* # of command. */
2076 char *prog
; /* program name. */
2077 char **argv
; /* vector of args. */
2078 int pid
; /* pid of process for this command. */
2081 struct command
*commands
; /* each command buffer with above info. */
2083 /* Count # of piped commands. */
2084 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2085 if (strcmp (argbuf
[i
], "|") == 0)
2088 /* Get storage for each command. */
2090 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2092 /* Split argbuf into its separate piped processes,
2093 and record info about each one.
2094 Also search for the programs that are to be run. */
2096 commands
[0].prog
= argbuf
[0]; /* first command. */
2097 commands
[0].argv
= &argbuf
[0];
2098 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2100 commands
[0].argv
[0] = string
;
2102 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2103 if (strcmp (argbuf
[i
], "|") == 0)
2104 { /* each command. */
2105 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) || defined (OS2) || defined (VMS)
2106 fatal ("-pipe not supported");
2108 argbuf
[i
] = 0; /* termination of command args. */
2109 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2110 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2111 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2113 commands
[n_commands
].argv
[0] = string
;
2117 argbuf
[argbuf_index
] = 0;
2119 /* If -v, print what we are about to do, and maybe query. */
2123 /* Print each piped command as a separate line. */
2124 for (i
= 0; i
< n_commands
; i
++)
2128 for (j
= commands
[i
].argv
; *j
; j
++)
2129 fprintf (stderr
, " %s", *j
);
2131 /* Print a pipe symbol after all but the last command. */
2132 if (i
+ 1 != n_commands
)
2133 fprintf (stderr
, " |");
2134 fprintf (stderr
, "\n");
2138 notice ("\nGo ahead? (y or n) ");
2142 while (getchar () != '\n')
2145 if (i
!= 'y' && i
!= 'Y')
2150 /* Run each piped subprocess. */
2152 for (i
= 0; i
< n_commands
; i
++)
2154 char *errmsg_fmt
, *errmsg_arg
;
2155 char *string
= commands
[i
].argv
[0];
2157 commands
[i
].pid
= pexecute (string
, commands
[i
].argv
,
2158 programname
, temp_filename
,
2159 &errmsg_fmt
, &errmsg_arg
,
2160 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2161 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2162 | (string
== commands
[i
].prog
2163 ? PEXECUTE_SEARCH
: 0)
2164 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2166 if (commands
[i
].pid
== -1)
2167 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2169 if (string
!= commands
[i
].prog
)
2175 /* Wait for all the subprocesses to finish.
2176 We don't care what order they finish in;
2177 we know that N_COMMANDS waits will get them all.
2178 Ignore subprocesses that we don't know about,
2179 since they can be spawned by the process that exec'ed us. */
2184 for (i
= 0; i
< n_commands
; )
2190 pid
= pwait (commands
[i
].pid
, &status
, 0);
2194 for (j
= 0; j
< n_commands
; j
++)
2195 if (commands
[j
].pid
== pid
)
2200 if (WIFSIGNALED (status
))
2202 fatal ("Internal compiler error: program %s got fatal signal %d",
2203 commands
[j
].prog
, WTERMSIG (status
));
2207 else if (WIFEXITED (status
)
2208 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2218 /* Find all the switches given to us
2219 and make a vector describing them.
2220 The elements of the vector are strings, one per switch given.
2221 If a switch uses following arguments, then the `part1' field
2222 is the switch itself and the `args' field
2223 is a null-terminated vector containing the following arguments.
2224 The `live_cond' field is 1 if the switch is true in a conditional spec,
2225 -1 if false (overridden by a later switch), and is initialized to zero.
2226 The `validated' field is nonzero if any spec has looked at this switch;
2227 if it remains zero at the end of the run, it must be meaningless. */
2237 static struct switchstr
*switches
;
2239 static int n_switches
;
2247 /* Also a vector of input files specified. */
2249 static struct infile
*infiles
;
2251 static int n_infiles
;
2253 /* And a vector of corresponding output files is made up later. */
2255 static char **outfiles
;
2257 /* Used to track if none of the -B paths are used. */
2260 /* Used to track if standard path isn't used and -b or -V is specified. */
2261 static int warn_std
;
2263 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2264 static int *warn_std_ptr
= 0;
2267 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2269 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2270 is true if we should look for an executable suffix as well. */
2273 convert_filename (name
, do_exe
)
2278 int len
= strlen (name
);
2280 #ifdef HAVE_OBJECT_SUFFIX
2281 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2283 && name
[len
- 2] == '.'
2284 && name
[len
- 1] == 'o')
2286 obstack_grow (&obstack
, name
, len
- 2);
2287 obstack_grow0 (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
2288 name
= obstack_finish (&obstack
);
2292 #ifdef HAVE_EXECUTABLE_SUFFIX
2293 /* If there is no filetype, make it the executable suffix (which includes
2294 the "."). But don't get confused if we have just "-o". */
2295 if (! do_exe
|| EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
2298 for (i
= len
- 1; i
>= 0; i
--)
2299 if (name
[i
] == '/' || name
[i
] == DIR_SEPARATOR
)
2302 for (i
++; i
< len
; i
++)
2306 obstack_grow (&obstack
, name
, len
);
2307 obstack_grow0 (&obstack
, EXECUTABLE_SUFFIX
, strlen (EXECUTABLE_SUFFIX
));
2308 name
= obstack_finish (&obstack
);
2315 /* Create the vector `switches' and its contents.
2316 Store its length in `n_switches'. */
2319 process_command (argc
, argv
)
2325 char *spec_lang
= 0;
2326 int last_language_n_infiles
;
2329 int lang_n_infiles
= 0;
2331 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2336 /* Figure compiler version from version string. */
2338 compiler_version
= save_string (version_string
, strlen (version_string
));
2339 for (temp
= compiler_version
; *temp
; ++temp
)
2348 /* Set up the default search paths. */
2350 if (gcc_exec_prefix
)
2352 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2353 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
2356 /* COMPILER_PATH and LIBRARY_PATH have values
2357 that are lists of directory names with colons. */
2359 temp
= getenv ("COMPILER_PATH");
2362 char *startp
, *endp
;
2363 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2365 startp
= endp
= temp
;
2368 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2370 strncpy (nstore
, startp
, endp
-startp
);
2372 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2373 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2375 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2376 nstore
[endp
-startp
+1] = 0;
2379 nstore
[endp
-startp
] = 0;
2380 add_prefix (&exec_prefixes
, nstore
, 0, 0, 0, NULL_PTR
);
2383 endp
= startp
= endp
+ 1;
2390 temp
= getenv ("LIBRARY_PATH");
2391 if (temp
&& *cross_compile
== '0')
2393 char *startp
, *endp
;
2394 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2396 startp
= endp
= temp
;
2399 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2401 strncpy (nstore
, startp
, endp
-startp
);
2403 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2404 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2406 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2407 nstore
[endp
-startp
+1] = 0;
2410 nstore
[endp
-startp
] = 0;
2411 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2415 endp
= startp
= endp
+ 1;
2422 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2423 temp
= getenv ("LPATH");
2424 if (temp
&& *cross_compile
== '0')
2426 char *startp
, *endp
;
2427 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2429 startp
= endp
= temp
;
2432 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2434 strncpy (nstore
, startp
, endp
-startp
);
2436 strcpy (nstore
, concat (".", dir_separator_str
, NULL_PTR
));
2437 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2439 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2440 nstore
[endp
-startp
+1] = 0;
2443 nstore
[endp
-startp
] = 0;
2444 add_prefix (&startfile_prefixes
, nstore
, NULL_PTR
,
2448 endp
= startp
= endp
+ 1;
2455 /* Convert new-style -- options to old-style. */
2456 translate_options (&argc
, &argv
);
2458 #ifdef LANG_SPECIFIC_DRIVER
2459 /* Do language-specific adjustment/addition of flags. */
2460 lang_specific_driver (fatal
, &argc
, &argv
);
2463 /* Scan argv twice. Here, the first time, just count how many switches
2464 there will be in their vector, and how many input files in theirs.
2465 Here we also parse the switches that cc itself uses (e.g. -v). */
2467 for (i
= 1; i
< argc
; i
++)
2469 if (! strcmp (argv
[i
], "-dumpspecs"))
2471 struct spec_list
*sl
;
2473 for (sl
= specs
; sl
; sl
= sl
->next
)
2474 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
2477 else if (! strcmp (argv
[i
], "-dumpversion"))
2479 printf ("%s\n", spec_version
);
2482 else if (! strcmp (argv
[i
], "-dumpmachine"))
2484 printf ("%s\n", spec_machine
);
2487 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2488 print_search_dirs
= 1;
2489 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2490 print_file_name
= "libgcc.a";
2491 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2492 print_file_name
= argv
[i
] + 17;
2493 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2494 print_prog_name
= argv
[i
] + 17;
2495 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2496 print_multi_lib
= 1;
2497 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2498 print_multi_directory
= 1;
2499 else if (! strncmp (argv
[i
], "-Wa,", 4))
2502 /* Pass the rest of this option to the assembler. */
2504 n_assembler_options
++;
2505 if (!assembler_options
)
2507 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2510 = (char **) xrealloc (assembler_options
,
2511 n_assembler_options
* sizeof (char **));
2513 /* Split the argument at commas. */
2515 for (j
= 4; argv
[i
][j
]; j
++)
2516 if (argv
[i
][j
] == ',')
2518 assembler_options
[n_assembler_options
- 1]
2519 = save_string (argv
[i
] + prev
, j
- prev
);
2520 n_assembler_options
++;
2522 = (char **) xrealloc (assembler_options
,
2523 n_assembler_options
* sizeof (char **));
2526 /* Record the part after the last comma. */
2527 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2529 else if (! strncmp (argv
[i
], "-Wp,", 4))
2532 /* Pass the rest of this option to the preprocessor. */
2534 n_preprocessor_options
++;
2535 if (!preprocessor_options
)
2536 preprocessor_options
2537 = (char **) xmalloc (n_preprocessor_options
* sizeof (char **));
2539 preprocessor_options
2540 = (char **) xrealloc (preprocessor_options
,
2541 n_preprocessor_options
* sizeof (char **));
2543 /* Split the argument at commas. */
2545 for (j
= 4; argv
[i
][j
]; j
++)
2546 if (argv
[i
][j
] == ',')
2548 preprocessor_options
[n_preprocessor_options
- 1]
2549 = save_string (argv
[i
] + prev
, j
- prev
);
2550 n_preprocessor_options
++;
2551 preprocessor_options
2552 = (char **) xrealloc (preprocessor_options
,
2553 n_preprocessor_options
* sizeof (char **));
2556 /* Record the part after the last comma. */
2557 preprocessor_options
[n_preprocessor_options
- 1] = argv
[i
] + prev
;
2559 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2560 /* The +e options to the C++ front-end. */
2562 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2565 /* Split the argument at commas. */
2566 for (j
= 3; argv
[i
][j
]; j
++)
2567 n_infiles
+= (argv
[i
][j
] == ',');
2569 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2572 fatal ("argument to `-Xlinker' is missing");
2577 else if (strncmp (argv
[i
], "-l", 2) == 0)
2579 else if (strcmp (argv
[i
], "-save-temps") == 0)
2581 save_temps_flag
= 1;
2584 else if (strcmp (argv
[i
], "-specs") == 0)
2586 struct user_specs
*user
= (struct user_specs
*)
2587 xmalloc (sizeof (struct user_specs
));
2589 fatal ("argument to `-specs' is missing");
2591 user
->next
= (struct user_specs
*)0;
2592 user
->filename
= argv
[i
];
2593 if (user_specs_tail
)
2594 user_specs_tail
->next
= user
;
2596 user_specs_head
= user
;
2597 user_specs_tail
= user
;
2599 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
2601 struct user_specs
*user
= (struct user_specs
*)
2602 xmalloc (sizeof (struct user_specs
));
2603 if (strlen (argv
[i
]) == 7)
2604 fatal ("argument to `-specs=' is missing");
2606 user
->next
= (struct user_specs
*)0;
2607 user
->filename
= argv
[i
]+7;
2608 if (user_specs_tail
)
2609 user_specs_tail
->next
= user
;
2611 user_specs_head
= user
;
2612 user_specs_tail
= user
;
2614 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2616 register char *p
= &argv
[i
][1];
2617 register int c
= *p
;
2622 if (p
[1] == 0 && i
+ 1 == argc
)
2623 fatal ("argument to `-b' is missing");
2625 spec_machine
= argv
[++i
];
2627 spec_machine
= p
+ 1;
2629 warn_std_ptr
= &warn_std
;
2634 int *temp
= (int *) xmalloc (sizeof (int));
2636 if (p
[1] == 0 && i
+ 1 == argc
)
2637 fatal ("argument to `-B' is missing");
2642 add_prefix (&exec_prefixes
, value
, NULL_PTR
, 1, 0, &warn_B
);
2643 add_prefix (&startfile_prefixes
, value
, NULL_PTR
,
2645 add_prefix (&include_prefixes
, concat (value
, "include",
2647 NULL_PTR
, 1, 0, NULL_PTR
);
2649 /* As a kludge, if the arg is "[foo/]stageN/", just add
2650 "[foo/]include" to the include prefix. */
2652 int len
= strlen (value
);
2655 && (value
[len
- 8] == '/'
2656 || value
[len
- 8] == DIR_SEPARATOR
)))
2657 && strncmp (value
+ len
- 7, "stage", 5) == 0
2658 && isdigit (value
[len
- 2])
2659 && (value
[len
- 1] == '/'
2660 || value
[len
- 1] == DIR_SEPARATOR
))
2663 add_prefix (&include_prefixes
, "include", NULL_PTR
,
2667 char *string
= xmalloc (len
+ 1);
2668 strncpy (string
, value
, len
-7);
2669 strcpy (string
+len
-7, "include");
2670 add_prefix (&include_prefixes
, string
, NULL_PTR
,
2678 case 'v': /* Print our subcommands and print versions. */
2680 /* If they do anything other than exactly `-v', don't set
2681 verbose_flag; rather, continue on to give the error. */
2688 if (p
[1] == 0 && i
+ 1 == argc
)
2689 fatal ("argument to `-V' is missing");
2691 spec_version
= argv
[++i
];
2693 spec_version
= p
+ 1;
2694 compiler_version
= spec_version
;
2695 warn_std_ptr
= &warn_std
;
2697 /* Validate the version number. Use the same checks
2698 done when inserting it into a spec.
2700 The format of the version string is
2701 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
2703 char *v
= compiler_version
;
2705 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
2706 while (! isdigit (*v
))
2709 if (v
> compiler_version
&& v
[-1] != '-')
2710 fatal ("invalid version number format");
2712 /* Set V after the first period. */
2713 while (isdigit (*v
))
2717 fatal ("invalid version number format");
2720 while (isdigit (*v
))
2723 if (*v
!= 0 && *v
!= ' ' && *v
!= '.' && *v
!= '-')
2724 fatal ("invalid version number format");
2739 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2740 argv
[i
] = convert_filename (argv
[i
], 1);
2742 argv
[i
+1] = convert_filename (argv
[i
+1], 1);
2750 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2751 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2752 else if (WORD_SWITCH_TAKES_ARG (p
))
2753 i
+= WORD_SWITCH_TAKES_ARG (p
);
2763 if (have_c
&& have_o
&& lang_n_infiles
> 1)
2764 fatal ("cannot specify -o with -c and multiple compilations");
2766 /* Set up the search paths before we go looking for config files. */
2768 /* These come before the md prefixes so that we will find gcc's subcommands
2769 (such as cpp) rather than those of the host system. */
2770 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2771 as well as trying the machine and the version. */
2773 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
2774 0, 2, warn_std_ptr
);
2775 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
2776 0, 2, warn_std_ptr
);
2779 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
2780 0, 1, warn_std_ptr
);
2781 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
2782 0, 1, warn_std_ptr
);
2784 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
2785 dir_separator_str
, NULL_PTR
);
2787 /* If tooldir is relative, base it on exec_prefixes. A relative
2788 tooldir lets us move the installed tree as a unit.
2790 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2791 directories, so that we can search both the user specified directory
2792 and the standard place. */
2794 if (*tooldir_prefix
!= '/' && *tooldir_prefix
!= DIR_SEPARATOR
)
2796 if (gcc_exec_prefix
)
2798 char *gcc_exec_tooldir_prefix
2799 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
2800 spec_version
, dir_separator_str
, tooldir_prefix
, NULL_PTR
);
2802 add_prefix (&exec_prefixes
,
2803 concat (gcc_exec_tooldir_prefix
, "bin",
2804 dir_separator_str
, NULL_PTR
),
2805 NULL_PTR
, 0, 0, NULL_PTR
);
2806 add_prefix (&startfile_prefixes
,
2807 concat (gcc_exec_tooldir_prefix
, "lib",
2808 dir_separator_str
, NULL_PTR
),
2809 NULL_PTR
, 0, 0, NULL_PTR
);
2812 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
2813 dir_separator_str
, spec_version
,
2814 dir_separator_str
, tooldir_prefix
, NULL_PTR
);
2817 add_prefix (&exec_prefixes
,
2818 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL_PTR
),
2819 "BINUTILS", 0, 0, NULL_PTR
);
2820 add_prefix (&startfile_prefixes
,
2821 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL_PTR
),
2822 "BINUTILS", 0, 0, NULL_PTR
);
2824 /* More prefixes are enabled in main, after we read the specs file
2825 and determine whether this is cross-compilation or not. */
2828 /* Then create the space for the vectors and scan again. */
2830 switches
= ((struct switchstr
*)
2831 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2832 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2835 last_language_n_infiles
= -1;
2837 /* This, time, copy the text of each switch and store a pointer
2838 to the copy in the vector of switches.
2839 Store all the infiles in their vector. */
2841 for (i
= 1; i
< argc
; i
++)
2843 /* Just skip the switches that were handled by the preceding loop. */
2844 if (! strncmp (argv
[i
], "-Wa,", 4))
2846 else if (! strncmp (argv
[i
], "-Wp,", 4))
2848 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2850 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2852 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2854 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2856 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2858 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2860 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2862 /* Compensate for the +e options to the C++ front-end;
2863 they're there simply for cfront call-compatibility. We do
2864 some magic in default_compilers to pass them down properly.
2865 Note we deliberately start at the `+' here, to avoid passing
2866 -e0 or -e1 down into the linker. */
2867 switches
[n_switches
].part1
= &argv
[i
][0];
2868 switches
[n_switches
].args
= 0;
2869 switches
[n_switches
].live_cond
= 0;
2870 switches
[n_switches
].validated
= 0;
2873 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2876 /* Split the argument at commas. */
2878 for (j
= 4; argv
[i
][j
]; j
++)
2879 if (argv
[i
][j
] == ',')
2881 infiles
[n_infiles
].language
= "*";
2882 infiles
[n_infiles
++].name
2883 = save_string (argv
[i
] + prev
, j
- prev
);
2886 /* Record the part after the last comma. */
2887 infiles
[n_infiles
].language
= "*";
2888 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
2890 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2892 infiles
[n_infiles
].language
= "*";
2893 infiles
[n_infiles
++].name
= argv
[++i
];
2895 else if (strncmp (argv
[i
], "-l", 2) == 0)
2897 infiles
[n_infiles
].language
= "*";
2898 infiles
[n_infiles
++].name
= argv
[i
];
2900 else if (strcmp (argv
[i
], "-specs") == 0)
2902 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
2904 /* -save-temps overrides -pipe, so that temp files are produced */
2905 else if (save_temps_flag
&& strcmp (argv
[i
], "-pipe") == 0)
2906 error ("Warning: -pipe ignored since -save-temps specified");
2907 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2909 register char *p
= &argv
[i
][1];
2910 register int c
= *p
;
2912 if (c
== 'B' || c
== 'b' || c
== 'V')
2914 /* Skip a separate arg, if any. */
2921 if (p
[1] == 0 && i
+ 1 == argc
)
2922 fatal ("argument to `-x' is missing");
2924 spec_lang
= argv
[++i
];
2927 if (! strcmp (spec_lang
, "none"))
2928 /* Suppress the warning if -xnone comes after the last input
2929 file, because alternate command interfaces like g++ might
2930 find it useful to place -xnone after each input file. */
2933 last_language_n_infiles
= n_infiles
;
2936 switches
[n_switches
].part1
= p
;
2937 /* Deal with option arguments in separate argv elements. */
2938 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2939 || WORD_SWITCH_TAKES_ARG (p
))
2942 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2946 /* Count only the option arguments in separate argv elements. */
2947 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2949 if (i
+ n_args
>= argc
)
2950 fatal ("argument to `-%s' is missing", p
);
2951 switches
[n_switches
].args
2952 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2954 switches
[n_switches
].args
[j
++] = argv
[++i
];
2955 /* Null-terminate the vector. */
2956 switches
[n_switches
].args
[j
] = 0;
2958 else if (index (switches_need_spaces
, c
))
2960 /* On some systems, ld cannot handle some options without
2961 a space. So split the option from its argument. */
2962 char *part1
= (char *) xmalloc (2);
2966 switches
[n_switches
].part1
= part1
;
2967 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2968 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2969 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2970 switches
[n_switches
].args
[1] = 0;
2973 switches
[n_switches
].args
= 0;
2975 switches
[n_switches
].live_cond
= 0;
2976 switches
[n_switches
].validated
= 0;
2977 /* This is always valid, since gcc.c itself understands it. */
2978 if (!strcmp (p
, "save-temps"))
2979 switches
[n_switches
].validated
= 1;
2984 #ifdef HAVE_OBJECT_SUFFIX
2985 argv
[i
] = convert_filename (argv
[i
], 0);
2988 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], R_OK
) < 0)
2990 perror_with_name (argv
[i
]);
2995 infiles
[n_infiles
].language
= spec_lang
;
2996 infiles
[n_infiles
++].name
= argv
[i
];
3001 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
3002 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
3004 switches
[n_switches
].part1
= 0;
3005 infiles
[n_infiles
].name
= 0;
3008 /* Process a spec string, accumulating and running commands. */
3010 /* These variables describe the input file name.
3011 input_file_number is the index on outfiles of this file,
3012 so that the output file name can be stored for later use by %o.
3013 input_basename is the start of the part of the input file
3014 sans all directory names, and basename_length is the number
3015 of characters starting there excluding the suffix .c or whatever. */
3017 static char *input_filename
;
3018 static int input_file_number
;
3019 static int input_filename_length
;
3020 static int basename_length
;
3021 static char *input_basename
;
3022 static char *input_suffix
;
3024 /* These are variables used within do_spec and do_spec_1. */
3026 /* Nonzero if an arg has been started and not yet terminated
3027 (with space, tab or newline). */
3028 static int arg_going
;
3030 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3031 is a temporary file name. */
3032 static int delete_this_arg
;
3034 /* Nonzero means %w has been seen; the next arg to be terminated
3035 is the output file name of this compilation. */
3036 static int this_is_output_file
;
3038 /* Nonzero means %s has been seen; the next arg to be terminated
3039 is the name of a library file and we should try the standard
3040 search dirs for it. */
3041 static int this_is_library_file
;
3043 /* Nonzero means that the input of this command is coming from a pipe. */
3044 static int input_from_pipe
;
3046 /* Process the spec SPEC and run the commands specified therein.
3047 Returns 0 if the spec is successfully processed; -1 if failed. */
3057 delete_this_arg
= 0;
3058 this_is_output_file
= 0;
3059 this_is_library_file
= 0;
3060 input_from_pipe
= 0;
3062 value
= do_spec_1 (spec
, 0, NULL_PTR
);
3064 /* Force out any unfinished command.
3065 If -pipe, this forces out the last command if it ended in `|'. */
3068 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3071 if (argbuf_index
> 0)
3078 /* Process the sub-spec SPEC as a portion of a larger spec.
3079 This is like processing a whole spec except that we do
3080 not initialize at the beginning and we do not supply a
3081 newline by default at the end.
3082 INSWITCH nonzero means don't process %-sequences in SPEC;
3083 in this case, % is treated as an ordinary character.
3084 This is used while substituting switches.
3085 INSWITCH nonzero also causes SPC not to terminate an argument.
3087 Value is zero unless a line was finished
3088 and the command on that line reported an error. */
3091 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3094 char *soft_matched_part
;
3096 register char *p
= spec
;
3103 /* If substituting a switch, treat all chars like letters.
3104 Otherwise, NL, SPC, TAB and % are special. */
3105 switch (inswitch
? 'a' : c
)
3108 /* End of line: finish any pending argument,
3109 then run the pending command if one has been started. */
3112 obstack_1grow (&obstack
, 0);
3113 string
= obstack_finish (&obstack
);
3114 if (this_is_library_file
)
3115 string
= find_file (string
);
3116 store_arg (string
, delete_this_arg
, this_is_output_file
);
3117 if (this_is_output_file
)
3118 outfiles
[input_file_number
] = string
;
3122 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3124 for (i
= 0; i
< n_switches
; i
++)
3125 if (!strcmp (switches
[i
].part1
, "pipe"))
3128 /* A `|' before the newline means use a pipe here,
3129 but only if -pipe was specified.
3130 Otherwise, execute now and don't pass the `|' as an arg. */
3133 input_from_pipe
= 1;
3134 switches
[i
].validated
= 1;
3141 if (argbuf_index
> 0)
3147 /* Reinitialize for a new command, and for a new argument. */
3150 delete_this_arg
= 0;
3151 this_is_output_file
= 0;
3152 this_is_library_file
= 0;
3153 input_from_pipe
= 0;
3157 /* End any pending argument. */
3160 obstack_1grow (&obstack
, 0);
3161 string
= obstack_finish (&obstack
);
3162 if (this_is_library_file
)
3163 string
= find_file (string
);
3164 store_arg (string
, delete_this_arg
, this_is_output_file
);
3165 if (this_is_output_file
)
3166 outfiles
[input_file_number
] = string
;
3170 obstack_1grow (&obstack
, c
);
3176 /* Space or tab ends an argument if one is pending. */
3179 obstack_1grow (&obstack
, 0);
3180 string
= obstack_finish (&obstack
);
3181 if (this_is_library_file
)
3182 string
= find_file (string
);
3183 store_arg (string
, delete_this_arg
, this_is_output_file
);
3184 if (this_is_output_file
)
3185 outfiles
[input_file_number
] = string
;
3187 /* Reinitialize for a new argument. */
3189 delete_this_arg
= 0;
3190 this_is_output_file
= 0;
3191 this_is_library_file
= 0;
3198 fatal ("Invalid specification! Bug in cc.");
3201 obstack_grow (&obstack
, input_basename
, basename_length
);
3206 delete_this_arg
= 2;
3209 /* Dump out the directories specified with LIBRARY_PATH,
3210 followed by the absolute directories
3211 that we search for startfiles. */
3214 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3216 char *buffer
= (char *) xmalloc (bufsize
);
3219 for (; pl
; pl
= pl
->next
)
3221 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3222 /* Used on systems which record the specified -L dirs
3223 and use them to search for dynamic linking. */
3224 /* Relative directories always come from -B,
3225 and it is better not to use them for searching
3226 at run time. In particular, stage1 loses */
3227 if (pl
->prefix
[0] != '/' && pl
->prefix
[0] != DIR_SEPARATOR
)
3230 /* Try subdirectory if there is one. */
3231 if (multilib_dir
!= NULL
)
3235 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3237 bufsize
= (strlen (pl
->prefix
)
3238 + strlen (machine_suffix
)) * 2 + 1;
3239 buffer
= (char *) xrealloc (buffer
, bufsize
);
3240 strcpy (buffer
, pl
->prefix
);
3241 strcat (buffer
, machine_suffix
);
3242 if (is_directory (buffer
, multilib_dir
, 1))
3244 do_spec_1 ("-L", 0, NULL_PTR
);
3245 #ifdef SPACE_AFTER_L_OPTION
3246 do_spec_1 (" ", 0, NULL_PTR
);
3248 do_spec_1 (buffer
, 1, NULL_PTR
);
3249 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3250 /* Make this a separate argument. */
3251 do_spec_1 (" ", 0, NULL_PTR
);
3254 if (!pl
->require_machine_suffix
)
3256 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3258 do_spec_1 ("-L", 0, NULL_PTR
);
3259 #ifdef SPACE_AFTER_L_OPTION
3260 do_spec_1 (" ", 0, NULL_PTR
);
3262 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3263 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3264 /* Make this a separate argument. */
3265 do_spec_1 (" ", 0, NULL_PTR
);
3271 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3273 do_spec_1 ("-L", 0, NULL_PTR
);
3274 #ifdef SPACE_AFTER_L_OPTION
3275 do_spec_1 (" ", 0, NULL_PTR
);
3277 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3278 /* Remove slash from machine_suffix. */
3279 if (strlen (machine_suffix
) >= bufsize
)
3280 bufsize
= strlen (machine_suffix
) * 2 + 1;
3281 buffer
= (char *) xrealloc (buffer
, bufsize
);
3282 strcpy (buffer
, machine_suffix
);
3283 idx
= strlen (buffer
);
3284 if (buffer
[idx
- 1] == '/'
3285 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3286 buffer
[idx
- 1] = 0;
3287 do_spec_1 (buffer
, 1, NULL_PTR
);
3288 /* Make this a separate argument. */
3289 do_spec_1 (" ", 0, NULL_PTR
);
3292 if (!pl
->require_machine_suffix
)
3294 if (is_directory (pl
->prefix
, "", 1))
3296 do_spec_1 ("-L", 0, NULL_PTR
);
3297 #ifdef SPACE_AFTER_L_OPTION
3298 do_spec_1 (" ", 0, NULL_PTR
);
3300 /* Remove slash from pl->prefix. */
3301 if (strlen (pl
->prefix
) >= bufsize
)
3302 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3303 buffer
= (char *) xrealloc (buffer
, bufsize
);
3304 strcpy (buffer
, pl
->prefix
);
3305 idx
= strlen (buffer
);
3306 if (buffer
[idx
- 1] == '/'
3307 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3308 buffer
[idx
- 1] = 0;
3309 do_spec_1 (buffer
, 1, NULL_PTR
);
3310 /* Make this a separate argument. */
3311 do_spec_1 (" ", 0, NULL_PTR
);
3320 /* %efoo means report an error with `foo' as error message
3321 and don't execute any more commands for this file. */
3325 while (*p
!= 0 && *p
!= '\n') p
++;
3326 buf
= (char *) alloca (p
- q
+ 1);
3327 strncpy (buf
, q
, p
- q
);
3337 if (save_temps_flag
)
3339 obstack_grow (&obstack
, input_basename
, basename_length
);
3340 delete_this_arg
= 0;
3344 #ifdef MKTEMP_EACH_FILE
3345 /* ??? This has a problem: the total number of
3346 values mktemp can return is limited.
3347 That matters for the names of object files.
3348 In 2.4, do something about that. */
3349 struct temp_name
*t
;
3351 while (*p
== '.' || isalpha (*p
)
3352 || (p
[0] == '%' && p
[1] == 'O'))
3355 /* See if we already have an association of %g/%u/%U and
3357 for (t
= temp_names
; t
; t
= t
->next
)
3358 if (t
->length
== p
- suffix
3359 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3360 && t
->unique
== (c
!= 'g'))
3363 /* Make a new association if needed. %u requires one. */
3364 if (t
== 0 || c
== 'u')
3368 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3369 t
->next
= temp_names
;
3372 t
->length
= p
- suffix
;
3373 t
->suffix
= save_string (suffix
, p
- suffix
);
3374 t
->unique
= (c
!= 'g');
3375 temp_filename
= choose_temp_base ();
3376 temp_filename_length
= strlen (temp_filename
);
3377 t
->filename
= temp_filename
;
3378 t
->filename_length
= temp_filename_length
;
3381 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3382 delete_this_arg
= 1;
3384 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3385 if (c
== 'u' || c
== 'U')
3391 sprintf (buff
, "%d", unique
);
3392 obstack_grow (&obstack
, buff
, strlen (buff
));
3395 delete_this_arg
= 1;
3401 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3407 struct prefix_list
*pl
= include_prefixes
.plist
;
3409 if (gcc_exec_prefix
)
3411 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3412 /* Make this a separate argument. */
3413 do_spec_1 (" ", 0, NULL_PTR
);
3414 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3415 do_spec_1 (" ", 0, NULL_PTR
);
3418 for (; pl
; pl
= pl
->next
)
3420 do_spec_1 ("-isystem", 1, NULL_PTR
);
3421 /* Make this a separate argument. */
3422 do_spec_1 (" ", 0, NULL_PTR
);
3423 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3424 do_spec_1 (" ", 0, NULL_PTR
);
3430 for (i
= 0; i
< n_infiles
; i
++)
3431 store_arg (outfiles
[i
], 0, 0);
3435 obstack_grow (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
3440 this_is_library_file
= 1;
3444 this_is_output_file
= 1;
3449 int cur_index
= argbuf_index
;
3450 /* Handle the {...} following the %W. */
3453 p
= handle_braces (p
+ 1);
3456 /* If any args were output, mark the last one for deletion
3458 if (argbuf_index
!= cur_index
)
3459 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3463 /* %x{OPTION} records OPTION for %X to output. */
3469 /* Skip past the option value and make a copy. */
3474 string
= save_string (p1
+ 1, p
- p1
- 2);
3476 /* See if we already recorded this option. */
3477 for (i
= 0; i
< n_linker_options
; i
++)
3478 if (! strcmp (string
, linker_options
[i
]))
3484 /* This option is new; add it. */
3486 if (!linker_options
)
3488 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3491 = (char **) xrealloc (linker_options
,
3492 n_linker_options
* sizeof (char **));
3494 linker_options
[n_linker_options
- 1] = string
;
3498 /* Dump out the options accumulated previously using %x. */
3500 for (i
= 0; i
< n_linker_options
; i
++)
3502 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3503 /* Make each accumulated option a separate argument. */
3504 do_spec_1 (" ", 0, NULL_PTR
);
3508 /* Dump out the options accumulated previously using -Wa,. */
3510 for (i
= 0; i
< n_assembler_options
; i
++)
3512 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3513 /* Make each accumulated option a separate argument. */
3514 do_spec_1 (" ", 0, NULL_PTR
);
3518 /* Dump out the options accumulated previously using -Wp,. */
3520 for (i
= 0; i
< n_preprocessor_options
; i
++)
3522 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3523 /* Make each accumulated option a separate argument. */
3524 do_spec_1 (" ", 0, NULL_PTR
);
3528 /* Here are digits and numbers that just process
3529 a certain constant string as a spec. */
3532 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3538 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3544 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3550 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3556 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3562 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3568 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3574 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3580 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3586 value
= do_spec_1 (libgcc_spec
, 0, NULL_PTR
);
3593 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3597 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3601 if (! strncmp (y
, "-D", 2))
3602 /* Copy the whole option. */
3603 while (*y
&& *y
!= ' ' && *y
!= '\t')
3605 else if (*y
== ' ' || *y
== '\t')
3606 /* Copy whitespace to the result. */
3608 /* Don't copy other options. */
3615 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3623 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3627 /* Copy all of CPP_PREDEFINES into BUF,
3628 but put __ after every -D and at the end of each arg. */
3632 if (! strncmp (y
, "-D", 2))
3640 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3642 /* Stick __ at front of macro name. */
3645 /* Arrange to stick __ at the end as well. */
3649 /* Copy the macro name. */
3650 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3659 /* Copy the value given, if any. */
3660 while (*y
&& *y
!= ' ' && *y
!= '\t')
3663 else if (*y
== ' ' || *y
== '\t')
3664 /* Copy whitespace to the result. */
3666 /* Don't copy -A options */
3672 /* Copy all of CPP_PREDEFINES into BUF,
3673 but put __ after every -D. */
3677 if (! strncmp (y
, "-D", 2))
3682 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3684 /* Stick -D__ at front of macro name. */
3690 /* Copy the macro name. */
3691 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3694 /* Copy the value given, if any. */
3695 while (*y
&& *y
!= ' ' && *y
!= '\t')
3700 /* Do not copy this macro - we have just done it before */
3701 while (*y
&& *y
!= ' ' && *y
!= '\t')
3705 else if (*y
== ' ' || *y
== '\t')
3706 /* Copy whitespace to the result. */
3708 /* Don't copy -A options */
3714 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3718 if (! strncmp (y
, "-A", 2))
3719 /* Copy the whole option. */
3720 while (*y
&& *y
!= ' ' && *y
!= '\t')
3722 else if (*y
== ' ' || *y
== '\t')
3723 /* Copy whitespace to the result. */
3725 /* Don't copy other options. */
3732 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3739 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3744 /* Here we define characters other than letters and digits. */
3747 p
= handle_braces (p
);
3753 obstack_1grow (&obstack
, '%');
3757 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3758 do_spec_1 (" ", 0, NULL_PTR
);
3761 /* Process a string found as the value of a spec given by name.
3762 This feature allows individual machine descriptions
3763 to add and use their own specs.
3764 %[...] modifies -D options the way %P does;
3765 %(...) uses the spec unmodified. */
3770 struct spec_list
*sl
;
3773 /* The string after the S/P is the name of a spec that is to be
3775 while (*p
&& *p
!= ')' && *p
!= ']')
3778 /* See if it's in the list */
3779 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3780 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
3782 name
= *(sl
->ptr_spec
);
3784 notice ("Processing spec %c%s%c, which is '%s'\n",
3785 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
3794 value
= do_spec_1 (name
, 0, NULL_PTR
);
3800 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3804 /* Copy all of NAME into BUF, but put __ after
3805 every -D and at the end of each arg, */
3810 if (! strncmp (y
, "-D", 2))
3820 else if (flag
&& (*y
== ' ' || *y
== '\t' || *y
== '='
3821 || *y
== '}' || *y
== 0))
3834 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3840 /* Discard the closing paren or bracket. */
3848 int c1
= *p
++; /* Select first or second version number. */
3849 char *v
= compiler_version
;
3852 /* The format of the version string is
3853 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3855 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3856 while (! isdigit (*v
))
3858 if (v
> compiler_version
&& v
[-1] != '-')
3861 /* If desired, advance to second version number. */
3864 /* Set V after the first period. */
3865 while (isdigit (*v
))
3872 /* Set Q at the next period or at the end. */
3874 while (isdigit (*q
))
3876 if (*q
!= 0 && *q
!= ' ' && *q
!= '.' && *q
!= '-')
3879 /* Put that part into the command. */
3880 obstack_grow (&obstack
, v
, q
- v
);
3886 if (input_from_pipe
)
3887 do_spec_1 ("-", 0, NULL_PTR
);
3896 /* Backslash: treat next character as ordinary. */
3901 /* Ordinary character: put it into the current argument. */
3902 obstack_1grow (&obstack
, c
);
3906 return 0; /* End of string */
3909 /* Return 0 if we call do_spec_1 and that returns -1. */
3920 int include_blanks
= 1;
3923 /* A '^' after the open-brace means to not give blanks before args. */
3924 include_blanks
= 0, ++p
;
3927 /* A `|' after the open-brace means,
3928 if the test fails, output a single minus sign rather than nothing.
3929 This is used in %{|!pipe:...}. */
3933 /* A `!' after the open-brace negates the condition:
3934 succeed if the specified switch is not present. */
3938 /* A `.' after the open-brace means test against the current suffix. */
3948 while (*p
!= ':' && *p
!= '}') p
++;
3951 register int count
= 1;
3969 int found
= (input_suffix
!= 0
3970 && strlen (input_suffix
) == p
- filter
3971 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3977 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3982 else if (p
[-1] == '*' && p
[0] == '}')
3984 /* Substitute all matching switches as separate args. */
3987 for (i
= 0; i
< n_switches
; i
++)
3988 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3989 && check_live_switch (i
, p
- filter
))
3990 give_switch (i
, 0, include_blanks
);
3994 /* Test for presence of the specified switch. */
3998 /* If name specified ends in *, as in {x*:...},
3999 check for %* and handle that case. */
4000 if (p
[-1] == '*' && !negate
)
4005 /* First see whether we have %*. */
4009 if (*r
== '%' && r
[1] == '*')
4013 /* If we do, handle that case. */
4016 /* Substitute all matching switches as separate args.
4017 But do this by substituting for %*
4018 in the text that follows the colon. */
4020 unsigned hard_match_len
= p
- filter
- 1;
4021 char *string
= save_string (p
+ 1, q
- p
- 2);
4023 for (i
= 0; i
< n_switches
; i
++)
4024 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4025 && check_live_switch (i
, -1))
4027 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
4028 /* Pass any arguments this switch has. */
4029 give_switch (i
, 1, 1);
4036 /* If name specified ends in *, as in {x*:...},
4037 check for presence of any switch name starting with x. */
4040 for (i
= 0; i
< n_switches
; i
++)
4042 unsigned hard_match_len
= p
- filter
- 1;
4044 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
4045 && check_live_switch (i
, hard_match_len
))
4051 /* Otherwise, check for presence of exact name specified. */
4054 for (i
= 0; i
< n_switches
; i
++)
4056 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4057 && switches
[i
].part1
[p
- filter
] == 0
4058 && check_live_switch (i
, -1))
4066 /* If it is as desired (present for %{s...}, absent for %{-s...})
4067 then substitute either the switch or the specified
4068 conditional text. */
4069 if (present
!= negate
)
4073 give_switch (i
, 0, include_blanks
);
4077 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
4083 /* Here if a %{|...} conditional fails: output a minus sign,
4084 which means "standard output" or "standard input". */
4085 do_spec_1 ("-", 0, NULL_PTR
);
4092 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4093 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4094 spec, or -1 if either exact match or %* is used.
4096 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4097 whose value does not begin with "no-" is obsoleted by the same value
4098 with the "no-", similarly for a switch with the "no-" prefix. */
4101 check_live_switch (switchnum
, prefix_length
)
4105 char *name
= switches
[switchnum
].part1
;
4108 /* In the common case of {<at-most-one-letter>*}, a negating
4109 switch would always match, so ignore that case. We will just
4110 send the conflicting switches to the compiler phase. */
4111 if (prefix_length
>= 0 && prefix_length
<= 1)
4114 /* If we already processed this switch and determined if it was
4115 live or not, return our past determination. */
4116 if (switches
[switchnum
].live_cond
!= 0)
4117 return switches
[switchnum
].live_cond
> 0;
4119 /* Now search for duplicate in a manner that depends on the name. */
4123 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4124 if (switches
[i
].part1
[0] == 'O')
4126 switches
[switchnum
].validated
= 1;
4127 switches
[switchnum
].live_cond
= -1;
4132 case 'W': case 'f': case 'm':
4133 if (! strncmp (name
+ 1, "no-", 3))
4135 /* We have Xno-YYY, search for XYYY. */
4136 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4137 if (switches
[i
].part1
[0] == name
[0]
4138 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4140 switches
[switchnum
].validated
= 1;
4141 switches
[switchnum
].live_cond
= -1;
4147 /* We have XYYY, search for Xno-YYY. */
4148 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4149 if (switches
[i
].part1
[0] == name
[0]
4150 && switches
[i
].part1
[1] == 'n'
4151 && switches
[i
].part1
[2] == 'o'
4152 && switches
[i
].part1
[3] == '-'
4153 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4155 switches
[switchnum
].validated
= 1;
4156 switches
[switchnum
].live_cond
= -1;
4163 /* Otherwise the switch is live. */
4164 switches
[switchnum
].live_cond
= 1;
4168 /* Pass a switch to the current accumulating command
4169 in the same form that we received it.
4170 SWITCHNUM identifies the switch; it is an index into
4171 the vector of switches gcc received, which is `switches'.
4172 This cannot fail since it never finishes a command line.
4174 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4176 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4180 give_switch (switchnum
, omit_first_word
, include_blanks
)
4182 int omit_first_word
;
4185 if (!omit_first_word
)
4187 do_spec_1 ("-", 0, NULL_PTR
);
4188 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4191 if (switches
[switchnum
].args
!= 0)
4194 for (p
= switches
[switchnum
].args
; *p
; p
++)
4197 do_spec_1 (" ", 0, NULL_PTR
);
4198 do_spec_1 (*p
, 1, NULL_PTR
);
4202 do_spec_1 (" ", 0, NULL_PTR
);
4203 switches
[switchnum
].validated
= 1;
4206 /* Search for a file named NAME trying various prefixes including the
4207 user's -B prefix and some standard ones.
4208 Return the absolute file name found. If nothing is found, return NAME. */
4216 /* Try multilib_dir if it is defined. */
4217 if (multilib_dir
!= NULL
)
4221 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4222 strcpy (try, multilib_dir
);
4223 strcat (try, dir_separator_str
);
4226 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4228 /* If we don't find it in the multi library dir, then fall
4229 through and look for it in the normal places. */
4230 if (newname
!= NULL
)
4234 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4235 return newname
? newname
: name
;
4238 /* Determine whether a directory exists. If LINKER, return 0 for
4239 certain fixed names not needed by the linker. If not LINKER, it is
4240 only important to return 0 if the host machine has a small ARG_MAX
4244 is_directory (path1
, path2
, linker
)
4249 int len1
= strlen (path1
);
4250 int len2
= strlen (path2
);
4251 char *path
= (char *) alloca (3 + len1
+ len2
);
4255 #ifndef SMALL_ARG_MAX
4260 /* Construct the path from the two parts. Ensure the string ends with "/.".
4261 The resulting path will be a directory even if the given path is a
4263 bcopy (path1
, path
, len1
);
4264 bcopy (path2
, path
+ len1
, len2
);
4265 cp
= path
+ len1
+ len2
;
4266 if (cp
[-1] != '/' && cp
[-1] != DIR_SEPARATOR
)
4267 *cp
++ = DIR_SEPARATOR
;
4271 /* Exclude directories that the linker is known to search. */
4274 && strcmp (path
, concat (dir_separator_str
, "lib",
4275 dir_separator_str
, ".", NULL_PTR
)) == 0)
4277 && strcmp (path
, concat (dir_separator_str
, "usr",
4278 dir_separator_str
, "lib",
4279 dir_separator_str
, ".", NULL_PTR
)) == 0)))
4282 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4285 /* On fatal signals, delete all the temporary files. */
4288 fatal_error (signum
)
4291 signal (signum
, SIG_DFL
);
4292 delete_failure_queue ();
4293 delete_temp_files ();
4294 /* Get the same signal again, this time not handled,
4295 so its normal effect occurs. */
4296 kill (getpid (), signum
);
4307 int linker_was_run
= 0;
4308 char *explicit_link_files
;
4311 struct user_specs
*uptr
;
4313 p
= argv
[0] + strlen (argv
[0]);
4314 while (p
!= argv
[0] && p
[-1] != '/' && p
[-1] != DIR_SEPARATOR
) --p
;
4317 setlocale (LC_MESSAGES
, "");
4318 bindtextdomain (PACKAGE
, localedir
);
4319 textdomain (PACKAGE
);
4321 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4322 signal (SIGINT
, fatal_error
);
4324 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4325 signal (SIGHUP
, fatal_error
);
4327 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4328 signal (SIGTERM
, fatal_error
);
4330 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4331 signal (SIGPIPE
, fatal_error
);
4334 /* If this is a test release of GCC, issue a warning. */
4335 if (version_string
[0] == 't' && version_string
[1] == 'e')
4336 snapshot_warning ();
4339 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4341 obstack_init (&obstack
);
4343 /* Build multilib_select, et. al from the separate lines that make up each
4344 multilib selection. */
4346 char **q
= multilib_raw
;
4349 obstack_init (&multilib_obstack
);
4350 while ((p
= *q
++) != (char *) 0)
4351 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4353 obstack_1grow (&multilib_obstack
, 0);
4354 multilib_select
= obstack_finish (&multilib_obstack
);
4356 q
= multilib_matches_raw
;
4357 while ((p
= *q
++) != (char *) 0)
4358 obstack_grow (&multilib_obstack
, p
, strlen (p
));
4360 obstack_1grow (&multilib_obstack
, 0);
4361 multilib_matches
= obstack_finish (&multilib_obstack
);
4365 i
< sizeof (multilib_defaults_raw
) / sizeof (multilib_defaults_raw
[0]);
4369 obstack_1grow (&multilib_obstack
, ' ');
4370 obstack_grow (&multilib_obstack
,
4371 multilib_defaults_raw
[i
],
4372 strlen (multilib_defaults_raw
[i
]));
4376 obstack_1grow (&multilib_obstack
, 0);
4377 multilib_defaults
= obstack_finish (&multilib_obstack
);
4380 /* Set up to remember the pathname of gcc and any options
4381 needed for collect. We use argv[0] instead of programname because
4382 we need the complete pathname. */
4383 obstack_init (&collect_obstack
);
4384 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4385 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4386 putenv (obstack_finish (&collect_obstack
));
4388 #ifdef INIT_ENVIRONMENT
4389 /* Set up any other necessary machine specific environment variables. */
4390 putenv (INIT_ENVIRONMENT
);
4393 /* Choose directory for temp files. */
4395 temp_filename
= choose_temp_base ();
4396 temp_filename_length
= strlen (temp_filename
);
4398 /* Make a table of what switches there are (switches, n_switches).
4399 Make a table of specified input files (infiles, n_infiles).
4400 Decode switches that are handled locally. */
4402 process_command (argc
, argv
);
4404 /* Initialize the vector of specs to just the default.
4405 This means one element containing 0s, as a terminator. */
4407 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4408 bcopy ((char *) default_compilers
, (char *) compilers
,
4409 sizeof default_compilers
);
4410 n_compilers
= n_default_compilers
;
4412 /* Read specs from a file if there is one. */
4414 machine_suffix
= concat (spec_machine
, dir_separator_str
,
4415 spec_version
, dir_separator_str
, NULL_PTR
);
4416 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL_PTR
);
4418 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4419 /* Read the specs file unless it is a default one. */
4420 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4421 read_specs (specs_file
, TRUE
);
4425 /* We need to check standard_exec_prefix/just_machine_suffix/specs
4426 for any override of as, ld and libraries. */
4427 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
4428 + strlen (just_machine_suffix
)
4429 + sizeof ("specs"));
4431 strcpy (specs_file
, standard_exec_prefix
);
4432 strcat (specs_file
, just_machine_suffix
);
4433 strcat (specs_file
, "specs");
4434 if (access (specs_file
, R_OK
) == 0)
4435 read_specs (specs_file
, TRUE
);
4437 /* Process any user specified specs in the order given on the command
4439 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
4441 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
, R_OK
);
4442 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
4445 /* If not cross-compiling, look for startfiles in the standard places. */
4446 /* The fact that these are done here, after reading the specs file,
4447 means that it cannot be found in these directories.
4448 But that's okay. It should never be there anyway. */
4449 if (*cross_compile
== '0')
4451 #ifdef MD_EXEC_PREFIX
4452 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4453 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC", 0, 0, NULL_PTR
);
4456 #ifdef MD_STARTFILE_PREFIX
4457 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
4461 #ifdef MD_STARTFILE_PREFIX_1
4462 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
4466 /* If standard_startfile_prefix is relative, base it on
4467 standard_exec_prefix. This lets us move the installed tree
4468 as a unit. If GCC_EXEC_PREFIX is defined, base
4469 standard_startfile_prefix on that as well. */
4470 if (*standard_startfile_prefix
== '/'
4471 || *standard_startfile_prefix
== DIR_SEPARATOR
4472 || *standard_startfile_prefix
== '$'
4474 /* Check for disk name on MS-DOS-based systems. */
4475 || (standard_startfile_prefix
[1] == ':'
4476 && (standard_startfile_prefix
[2] == DIR_SEPARATOR
4477 || standard_startfile_prefix
[2] == '/'))
4480 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
4484 if (gcc_exec_prefix
)
4485 add_prefix (&startfile_prefixes
,
4486 concat (gcc_exec_prefix
, machine_suffix
,
4487 standard_startfile_prefix
, NULL_PTR
),
4488 NULL_PTR
, 0, 0, NULL_PTR
);
4489 add_prefix (&startfile_prefixes
,
4490 concat (standard_exec_prefix
,
4492 standard_startfile_prefix
, NULL_PTR
),
4493 NULL_PTR
, 0, 0, NULL_PTR
);
4496 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
4497 "BINUTILS", 0, 0, NULL_PTR
);
4498 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
4499 "BINUTILS", 0, 0, NULL_PTR
);
4500 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4501 add_prefix (&startfile_prefixes
, "./", NULL_PTR
, 0, 1, NULL_PTR
);
4506 if (*standard_startfile_prefix
!= DIR_SEPARATOR
&& gcc_exec_prefix
)
4507 add_prefix (&startfile_prefixes
,
4508 concat (gcc_exec_prefix
, machine_suffix
,
4509 standard_startfile_prefix
, NULL_PTR
),
4510 "BINUTILS", 0, 0, NULL_PTR
);
4513 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4514 if (gcc_exec_prefix
)
4516 char * temp
= (char *) xmalloc (strlen (gcc_exec_prefix
)
4517 + strlen (spec_version
)
4518 + strlen (spec_machine
) + 3);
4519 strcpy (temp
, gcc_exec_prefix
);
4520 strcat (temp
, spec_machine
);
4521 strcat (temp
, dir_separator_str
);
4522 strcat (temp
, spec_version
);
4523 strcat (temp
, dir_separator_str
);
4524 gcc_exec_prefix
= temp
;
4527 /* Now we have the specs.
4528 Set the `valid' bits for switches that match anything in any spec. */
4530 validate_all_switches ();
4532 /* Now that we have the switches and the specs, set
4533 the subdirectory based on the options. */
4534 set_multilib_dir ();
4536 /* Warn about any switches that no pass was interested in. */
4538 for (i
= 0; i
< n_switches
; i
++)
4539 if (! switches
[i
].validated
)
4540 error ("unrecognized option `-%s'", switches
[i
].part1
);
4542 /* Obey some of the options. */
4544 if (print_search_dirs
)
4546 printf ("install: %s%s\n", standard_exec_prefix
, machine_suffix
);
4547 printf ("programs: %s\n", build_search_list (&exec_prefixes
, "", 0));
4548 printf ("libraries: %s\n", build_search_list (&startfile_prefixes
, "", 0));
4552 if (print_file_name
)
4554 printf ("%s\n", find_file (print_file_name
));
4558 if (print_prog_name
)
4560 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4561 printf ("%s\n", (newname
? newname
: print_prog_name
));
4565 if (print_multi_lib
)
4567 print_multilib_info ();
4571 if (print_multi_directory
)
4573 if (multilib_dir
== NULL
)
4576 printf ("%s\n", multilib_dir
);
4584 /* compiler_version is truncated at the first space when initialized
4585 from version string, so truncate version_string at the first space
4586 before comparing. */
4587 for (n
= 0; version_string
[n
]; n
++)
4588 if (version_string
[n
] == ' ')
4591 if (! strncmp (version_string
, compiler_version
, n
)
4592 && compiler_version
[n
] == 0)
4593 notice ("gcc version %s\n", version_string
);
4595 notice ("gcc driver version %s executing gcc version %s\n",
4596 version_string
, compiler_version
);
4603 fatal ("No input files");
4605 /* Make a place to record the compiler output file names
4606 that correspond to the input files. */
4608 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4609 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4611 /* Record which files were specified explicitly as link input. */
4613 explicit_link_files
= xmalloc (n_infiles
);
4614 bzero (explicit_link_files
, n_infiles
);
4616 for (i
= 0; i
< n_infiles
; i
++)
4618 register struct compiler
*cp
= 0;
4619 int this_file_error
= 0;
4621 /* Tell do_spec what to substitute for %i. */
4623 input_filename
= infiles
[i
].name
;
4624 input_filename_length
= strlen (input_filename
);
4625 input_file_number
= i
;
4627 /* Use the same thing in %o, unless cp->spec says otherwise. */
4629 outfiles
[i
] = input_filename
;
4631 /* Figure out which compiler from the file's suffix. */
4633 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4634 infiles
[i
].language
);
4638 /* Ok, we found an applicable compiler. Run its spec. */
4639 /* First say how much of input_filename to substitute for %b */
4643 if (cp
->spec
[0][0] == '#')
4644 error ("%s: %s compiler not installed on this system",
4645 input_filename
, &cp
->spec
[0][1]);
4647 input_basename
= input_filename
;
4648 for (p
= input_filename
; *p
; p
++)
4649 if (*p
== '/' || *p
== DIR_SEPARATOR
)
4650 input_basename
= p
+ 1;
4652 /* Find a suffix starting with the last period,
4653 and set basename_length to exclude that suffix. */
4654 basename_length
= strlen (input_basename
);
4655 p
= input_basename
+ basename_length
;
4656 while (p
!= input_basename
&& *p
!= '.') --p
;
4657 if (*p
== '.' && p
!= input_basename
)
4659 basename_length
= p
- input_basename
;
4660 input_suffix
= p
+ 1;
4666 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4668 len
+= strlen (cp
->spec
[j
]);
4670 p
= (char *) xmalloc (len
+ 1);
4673 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4676 strcpy (p
+ len
, cp
->spec
[j
]);
4677 len
+= strlen (cp
->spec
[j
]);
4680 value
= do_spec (p
);
4683 this_file_error
= 1;
4686 /* If this file's name does not contain a recognized suffix,
4687 record it as explicit linker input. */
4690 explicit_link_files
[i
] = 1;
4692 /* Clear the delete-on-failure queue, deleting the files in it
4693 if this compilation failed. */
4695 if (this_file_error
)
4697 delete_failure_queue ();
4700 /* If this compilation succeeded, don't delete those files later. */
4701 clear_failure_queue ();
4704 /* Run ld to link all the compiler output files. */
4706 if (error_count
== 0)
4708 int tmp
= execution_count
;
4712 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4714 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
4715 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
4717 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4719 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4720 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4723 for (i
= 0; i
< n_switches
; i
++)
4727 obstack_grow (&collect_obstack
, " ", 1);
4730 obstack_grow (&collect_obstack
, "-", 1);
4731 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4732 strlen (switches
[i
].part1
));
4734 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4736 obstack_grow (&collect_obstack
, " ", 1);
4737 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4740 obstack_grow (&collect_obstack
, "\0", 1);
4741 putenv (obstack_finish (&collect_obstack
));
4743 value
= do_spec (link_command_spec
);
4746 linker_was_run
= (tmp
!= execution_count
);
4749 /* Warn if a -B option was specified but the prefix was never used. */
4750 unused_prefix_warnings (&exec_prefixes
);
4751 unused_prefix_warnings (&startfile_prefixes
);
4753 /* If options said don't run linker,
4754 complain about input files to be given to the linker. */
4756 if (! linker_was_run
&& error_count
== 0)
4757 for (i
= 0; i
< n_infiles
; i
++)
4758 if (explicit_link_files
[i
])
4759 error ("%s: linker input file unused since linking not done",
4762 /* Delete some or all of the temporary files we made. */
4765 delete_failure_queue ();
4766 delete_temp_files ();
4768 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4773 /* Find the proper compilation spec for the file name NAME,
4774 whose length is LENGTH. LANGUAGE is the specified language,
4775 or 0 if this file is to be passed to the linker. */
4777 static struct compiler
*
4778 lookup_compiler (name
, length
, language
)
4783 struct compiler
*cp
;
4785 /* If this was specified by the user to be a linker input, indicate that. */
4786 if (language
!= 0 && language
[0] == '*')
4789 /* Otherwise, look for the language, if one is spec'd. */
4792 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4793 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
4796 error ("language %s not recognized", language
);
4800 /* Look for a suffix. */
4801 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4803 if (/* The suffix `-' matches only the file name `-'. */
4804 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4805 || (strlen (cp
->suffix
) < length
4806 /* See if the suffix matches the end of NAME. */
4808 && ((!strcmp (cp
->suffix
,
4809 name
+ length
- strlen (cp
->suffix
))
4810 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
4811 && !strcasecmp (cp
->suffix
,
4812 name
+ length
- strlen (cp
->suffix
)))
4814 && !strcmp (cp
->suffix
,
4815 name
+ length
- strlen (cp
->suffix
))
4819 if (cp
->spec
[0][0] == '@')
4821 struct compiler
*new;
4823 /* An alias entry maps a suffix to a language.
4824 Search for the language; pass 0 for NAME and LENGTH
4825 to avoid infinite recursion if language not found.
4826 Construct the new compiler spec. */
4827 language
= cp
->spec
[0] + 1;
4828 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4829 new->suffix
= cp
->suffix
;
4830 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4831 (char *) new->spec
, sizeof new->spec
);
4835 /* A non-alias entry: return it. */
4847 register char *value
= (char *) malloc (size
);
4849 fatal ("virtual memory exhausted");
4854 xrealloc (ptr
, size
)
4858 register char *value
= (char *) realloc (ptr
, size
);
4860 fatal ("virtual memory exhausted");
4864 /* This function is based on the one in libiberty. */
4867 concat
VPROTO((char *first
, ...))
4869 register int length
;
4870 register char *newstr
;
4874 #ifndef ANSI_PROTOTYPES
4878 /* First compute the size of the result and get sufficient memory. */
4880 VA_START (args
, first
);
4881 #ifndef ANSI_PROTOTYPES
4882 first
= va_arg (args
, char *);
4890 length
+= strlen (arg
);
4891 arg
= va_arg (args
, char *);
4894 newstr
= (char *) xmalloc (length
+ 1);
4897 /* Now copy the individual pieces to the result string. */
4899 VA_START (args
, first
);
4900 #ifndef ANSI_PROTOTYPES
4901 first
= va_arg (args
, char *);
4910 arg
= va_arg (args
, char *);
4919 save_string (s
, len
)
4923 register char *result
= xmalloc (len
+ 1);
4925 bcopy (s
, result
, len
);
4931 pfatal_with_name (name
)
4934 perror_with_name (name
);
4935 delete_temp_files ();
4940 perror_with_name (name
)
4943 fprintf (stderr
, "%s: %s: %s\n", programname
, name
, my_strerror (errno
));
4947 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
4953 int save_errno
= errno
;
4955 /* Space for trailing '\0' is in %s. */
4956 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
4957 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
4963 pfatal_with_name (errmsg_fmt
);
4966 /* More 'friendly' abort that prints the line and file.
4967 config.h can #define abort fancy_abort if you like that sort of thing. */
4972 fatal ("Internal gcc abort.");
4977 /* Output an error message and exit */
4980 fatal
VPROTO((char *msgid
, ...))
4982 #ifndef ANSI_PROTOTYPES
4987 VA_START (ap
, msgid
);
4989 #ifndef ANSI_PROTOTYPES
4990 msgid
= va_arg (ap
, char *);
4993 fprintf (stderr
, "%s: ", programname
);
4994 vfprintf (stderr
, _(msgid
), ap
);
4996 fprintf (stderr
, "\n");
4997 delete_temp_files ();
5002 error
VPROTO((char *msgid
, ...))
5004 #ifndef ANSI_PROTOTYPES
5009 VA_START (ap
, msgid
);
5011 #ifndef ANSI_PROTOTYPES
5012 msgid
= va_arg (ap
, char *);
5015 fprintf (stderr
, "%s: ", programname
);
5016 vfprintf (stderr
, _(msgid
), ap
);
5019 fprintf (stderr
, "\n");
5023 notice
VPROTO((char *msgid
, ...))
5025 #ifndef ANSI_PROTOTYPES
5030 VA_START (ap
, msgid
);
5032 #ifndef ANSI_PROTOTYPES
5033 msgid
= va_arg (ap
, char *);
5036 vfprintf (stderr
, _(msgid
), ap
);
5040 #else /* not HAVE_VPRINTF */
5043 fatal (msgid
, arg1
, arg2
)
5044 char *msgid
, *arg1
, *arg2
;
5046 error (msgid
, arg1
, arg2
);
5047 delete_temp_files ();
5052 error (msgid
, arg1
, arg2
)
5053 char *msgid
, *arg1
, *arg2
;
5055 fprintf (stderr
, "%s: ", programname
);
5056 fprintf (stderr
, _(msgid
), arg1
, arg2
);
5057 fprintf (stderr
, "\n");
5061 notice (msgid
, arg1
, arg2
)
5062 char *msgid
, *arg1
, *arg2
;
5064 fprintf (stderr
, _(msgid
), arg1
, arg2
);
5067 #endif /* not HAVE_VPRINTF */
5071 validate_all_switches ()
5073 struct compiler
*comp
;
5076 struct spec_list
*spec
;
5078 for (comp
= compilers
; comp
->spec
[0]; comp
++)
5081 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
5085 if (c
== '%' && *p
== '{')
5086 /* We have a switch spec. */
5087 validate_switches (p
+ 1);
5091 /* look through the linked list of specs read from the specs file */
5092 for (spec
= specs
; spec
; spec
= spec
->next
)
5094 p
= *(spec
->ptr_spec
);
5096 if (c
== '%' && *p
== '{')
5097 /* We have a switch spec. */
5098 validate_switches (p
+ 1);
5101 p
= link_command_spec
;
5103 if (c
== '%' && *p
== '{')
5104 /* We have a switch spec. */
5105 validate_switches (p
+ 1);
5108 /* Look at the switch-name that comes after START
5109 and mark as valid all supplied switches that match it. */
5112 validate_switches (start
)
5115 register char *p
= start
;
5130 while (*p
!= ':' && *p
!= '}') p
++;
5134 else if (p
[-1] == '*')
5136 /* Mark all matching switches as valid. */
5138 for (i
= 0; i
< n_switches
; i
++)
5139 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
5140 switches
[i
].validated
= 1;
5144 /* Mark an exact matching switch as valid. */
5145 for (i
= 0; i
< n_switches
; i
++)
5147 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5148 && switches
[i
].part1
[p
- filter
] == 0)
5149 switches
[i
].validated
= 1;
5154 /* Check whether a particular argument was used. The first time we
5155 canonicalize the switches to keep only the ones we care about. */
5169 static struct mswitchstr
*mswitches
;
5170 static int n_mswitches
;
5175 struct mswitchstr
*matches
;
5179 /* Break multilib_matches into the component strings of string and replacement
5181 for (q
= multilib_matches
; *q
!= '\0'; q
++)
5185 matches
= (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
5187 q
= multilib_matches
;
5198 matches
[i
].len
= q
- matches
[i
].str
;
5200 matches
[i
].replace
= ++q
;
5201 while (*q
!= ';' && *q
!= '\0')
5207 matches
[i
].rep_len
= q
- matches
[i
].replace
;
5215 /* Now build a list of the replacement string for switches that we care
5216 about. Make sure we allocate at least one entry. This prevents
5217 xmalloc from calling fatal, and prevents us from re-executing this
5220 = (struct mswitchstr
*) xmalloc ((sizeof (struct mswitchstr
))
5221 * (n_switches
? n_switches
: 1));
5222 for (i
= 0; i
< n_switches
; i
++)
5224 int xlen
= strlen (switches
[i
].part1
);
5225 for (j
= 0; j
< cnt
; j
++)
5226 if (xlen
== matches
[j
].len
&& ! strcmp (switches
[i
].part1
, matches
[j
].str
))
5228 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
5229 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
5230 mswitches
[n_mswitches
].replace
= (char *)0;
5231 mswitches
[n_mswitches
].rep_len
= 0;
5238 for (i
= 0; i
< n_mswitches
; i
++)
5239 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
5246 default_arg (p
, len
)
5253 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+1)
5255 while (*start
== ' ' || *start
== '\t')
5261 for (end
= start
+1; *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
5264 if ((end
- start
) == len
&& strncmp (p
, start
, len
) == 0)
5274 /* Work out the subdirectory to use based on the
5275 options. The format of multilib_select is a list of elements.
5276 Each element is a subdirectory name followed by a list of options
5277 followed by a semicolon. gcc will consider each line in turn. If
5278 none of the options beginning with an exclamation point are
5279 present, and all of the other options are present, that
5280 subdirectory will be used. */
5285 char *p
= multilib_select
;
5287 char *this_path
, *this_arg
;
5293 /* Ignore newlines. */
5300 /* Get the initial path. */
5308 this_path_len
= p
- this_path
;
5310 /* Check the arguments. */
5325 while (*p
!= ' ' && *p
!= ';')
5332 if (*this_arg
!= '!')
5340 /* If this is a default argument, we can just ignore it.
5341 This is true even if this_arg begins with '!'. Beginning
5342 with '!' does not mean that this argument is necessarily
5343 inappropriate for this library: it merely means that
5344 there is a more specific library which uses this
5345 argument. If this argument is a default, we need not
5346 consider that more specific library. */
5347 if (! default_arg (this_arg
, p
- this_arg
))
5349 ok
= used_arg (this_arg
, p
- this_arg
);
5360 if (this_path_len
!= 1
5361 || this_path
[0] != '.')
5363 multilib_dir
= xmalloc (this_path_len
+ 1);
5364 strncpy (multilib_dir
, this_path
, this_path_len
);
5365 multilib_dir
[this_path_len
] = '\0';
5374 /* Print out the multiple library subdirectory selection
5375 information. This prints out a series of lines. Each line looks
5376 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5377 required. Only the desired options are printed out, the negative
5378 matches. The options are print without a leading dash. There are
5379 no spaces to make it easy to use the information in the shell.
5380 Each subdirectory is printed only once. This assumes the ordering
5381 generated by the genmultilib script. */
5384 print_multilib_info ()
5386 char *p
= multilib_select
;
5387 char *last_path
= 0, *this_path
;
5389 int last_path_len
= 0;
5393 /* Ignore newlines. */
5400 /* Get the initial path. */
5409 /* If this is a duplicate, skip it. */
5410 skip
= (last_path
!= 0 && p
- this_path
== last_path_len
5411 && ! strncmp (last_path
, this_path
, last_path_len
));
5413 last_path
= this_path
;
5414 last_path_len
= p
- this_path
;
5416 /* If this directory requires any default arguments, we can skip
5417 it. We will already have printed a directory identical to
5418 this one which does not require that default argument. */
5436 while (*q
!= ' ' && *q
!= ';')
5444 && default_arg (arg
, q
- arg
))
5459 for (p1
= last_path
; p1
< p
; p1
++)
5478 use_arg
= *p
!= '!';
5483 while (*p
!= ' ' && *p
!= ';')
5498 /* If there are extra options, print them now */
5499 if (multilib_extra
&& *multilib_extra
)
5501 int print_at
= TRUE
;
5504 for (q
= multilib_extra
; *q
!= '\0'; q
++)
5524 /* If a snapshot, warn the user that this version of gcc is for testing and
5525 developing only. If we can find a home directory, we can restrict the
5526 warning to once per day. Otherwise always issue it. */
5528 #define TIMESTAMP_FILE ".gcc-test-time"
5529 #define ONE_DAY (24*60*60)
5537 /* Every function here but `time' is called elsewhere in this file,
5538 but we only can be sure we have it for Unix and the Windows systems,
5539 so conditionalize this on those.
5541 ??? This should use autoconf at some point. */
5543 #if defined(unix) || defined(__CYGWIN32__) || defined(_MINGW32__)
5545 home
= getenv ("HOME");
5549 = (char *) alloca (strlen (home
) + 1 + sizeof (TIMESTAMP_FILE
));
5550 struct stat statbuf
;
5551 time_t now
= time (NULL
);
5554 sprintf (file_name
, "%s/%s", home
, TIMESTAMP_FILE
);
5555 s
= stat (file_name
, &statbuf
);
5557 && (statbuf
.st_mtime
+ ONE_DAY
> now
))
5561 FILE *f
= fopen (file_name
, "w");
5574 notice ("*** This is a development snapshot of GCC.\n\
5575 *** It is not a reliable release, and the GCC developers\n\
5576 *** warn you not to use it for anything except to test it.\n");