Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / contrib / gcc / gcc.c
CommitLineData
984263bc
MD
1/* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000 Free Software Foundation, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.
21
22This paragraph is here to try to keep Sun CC from dying.
23The number of chars here seems crucial!!!! */
24
25/* $FreeBSD: src/contrib/gcc/gcc.c,v 1.17.2.9 2002/06/20 23:12:28 obrien Exp $ */
1de703da 26/* $DragonFly: src/contrib/gcc/Attic/gcc.c,v 1.2 2003/06/17 04:24:01 dillon Exp $ */
984263bc
MD
27
28/* This program is the user interface to the C compiler and possibly to
29other compilers. It is used because compilation is a complicated procedure
30which involves running several programs and passing temporary files between
31them, forwarding the users switches to those programs selectively,
32and deleting the temporary files at the end.
33
34CC recognizes how to compile each input file by suffixes in the file names.
35Once it knows which kind of compilation to perform, the procedure for
36compilation is specified by a string called a "spec". */
37\f
38#include "config.h"
39#include "system.h"
40#include <signal.h>
41
42#include "obstack.h"
43#include "intl.h"
44#include "prefix.h"
45
46#ifdef VMS
47#define exit __posix_exit
48#endif
49
50/* By default there is no special suffix for executables. */
51#ifdef EXECUTABLE_SUFFIX
52#define HAVE_EXECUTABLE_SUFFIX
53#else
54#define EXECUTABLE_SUFFIX ""
55#endif
56
57/* By default, the suffix for object files is ".o". */
58#ifdef OBJECT_SUFFIX
59#define HAVE_OBJECT_SUFFIX
60#else
61#define OBJECT_SUFFIX ".o"
62#endif
63
64/* By default, colon separates directories in a path. */
65#ifndef PATH_SEPARATOR
66#define PATH_SEPARATOR ':'
67#endif
68
69#ifndef DIR_SEPARATOR
70#define DIR_SEPARATOR '/'
71#endif
72
73/* Define IS_DIR_SEPARATOR. */
74#ifndef DIR_SEPARATOR_2
75# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
76#else /* DIR_SEPARATOR_2 */
77# define IS_DIR_SEPARATOR(ch) \
78 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
79#endif /* DIR_SEPARATOR_2 */
80
81static char dir_separator_str[] = {DIR_SEPARATOR, 0};
82
83#define obstack_chunk_alloc xmalloc
84#define obstack_chunk_free free
85
86#ifndef GET_ENV_PATH_LIST
87#define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
88#endif
89
90#ifndef HAVE_KILL
91#define kill(p,s) raise(s)
92#endif
93
94/* If a stage of compilation returns an exit status >= 1,
95 compilation of that file ceases. */
96
97#define MIN_FATAL_STATUS 1
98
99/* Flag saying to print the directories gcc will search through looking for
100 programs, libraries, etc. */
101
102static int print_search_dirs;
103
104/* Flag saying to print the full filename of this file
105 as found through our usual search mechanism. */
106
107static const char *print_file_name = NULL;
108
109/* As print_file_name, but search for executable file. */
110
111static const char *print_prog_name = NULL;
112
113/* Flag saying to print the relative path we'd use to
114 find libgcc.a given the current compiler flags. */
115
116static int print_multi_directory;
117
118/* Flag saying to print the list of subdirectories and
119 compiler flags used to select them in a standard form. */
120
121static int print_multi_lib;
122
123/* Flag saying to print the command line options understood by gcc and its
124 sub-processes. */
125
126static int print_help_list;
127
128/* Flag indicating whether we should print the command and arguments */
129
130static int verbose_flag;
131
132/* Nonzero means write "temp" files in source directory
133 and use the source file's name in them, and don't delete them. */
134
135static int save_temps_flag;
136
137/* The compiler version. */
138
139static char *compiler_version;
140
141/* The target version specified with -V */
142
143static char *spec_version = DEFAULT_TARGET_VERSION;
144
145/* The target machine specified with -b. */
146
147static const char *spec_machine = DEFAULT_TARGET_MACHINE;
148
149/* Nonzero if cross-compiling.
150 When -b is used, the value comes from the `specs' file. */
151
152#ifdef CROSS_COMPILE
153static char *cross_compile = "1";
154#else
155static char *cross_compile = "0";
156#endif
157
158/* The number of errors that have occurred; the link phase will not be
159 run if this is non-zero. */
160static int error_count = 0;
161
162/* This is the obstack which we use to allocate many strings. */
163
164static struct obstack obstack;
165
166/* This is the obstack to build an environment variable to pass to
167 collect2 that describes all of the relevant switches of what to
168 pass the compiler in building the list of pointers to constructors
169 and destructors. */
170
171static struct obstack collect_obstack;
172
173extern char *version_string;
174
175/* Forward declaration for prototypes. */
176struct path_prefix;
177
178static void init_spec PROTO((void));
179static void read_specs PROTO((const char *, int));
180static void set_spec PROTO((const char *, const char *));
181static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
182static char *build_search_list PROTO((struct path_prefix *, const char *, int));
183static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
184static char *find_a_file PROTO((struct path_prefix *, const char *, int));
185static void add_prefix PROTO((struct path_prefix *, const char *,
186 const char *, int, int, int *));
187static char *skip_whitespace PROTO((char *));
188static void record_temp_file PROTO((const char *, int, int));
189static void delete_if_ordinary PROTO((const char *));
190static void delete_temp_files PROTO((void));
191static void delete_failure_queue PROTO((void));
192static void clear_failure_queue PROTO((void));
193static int check_live_switch PROTO((int, int));
194static const char *handle_braces PROTO((const char *));
195static char *save_string PROTO((const char *, int));
196extern int do_spec PROTO((const char *));
197static int do_spec_1 PROTO((const char *, int, const char *));
198static const char *find_file PROTO((const char *));
199static int is_directory PROTO((const char *, const char *, int));
200static void validate_switches PROTO((const char *));
201static void validate_all_switches PROTO((void));
202static void give_switch PROTO((int, int, int));
203static int used_arg PROTO((const char *, int));
204static int default_arg PROTO((const char *, int));
205static void set_multilib_dir PROTO((void));
206static void print_multilib_info PROTO((void));
207static void pfatal_with_name PROTO((const char *)) ATTRIBUTE_NORETURN;
208static void perror_with_name PROTO((const char *));
209static void pfatal_pexecute PROTO((const char *, const char *))
210 ATTRIBUTE_NORETURN;
211static void error PVPROTO((const char *, ...))
212 ATTRIBUTE_PRINTF_1;
213static void notice PVPROTO((const char *, ...))
214 ATTRIBUTE_PRINTF_1;
215static void display_help PROTO((void));
216static void add_preprocessor_option PROTO ((const char *, int));
217static void add_assembler_option PROTO ((const char *, int));
218static void add_linker_option PROTO ((const char *, int));
219static void process_command PROTO ((int, char **));
220static int execute PROTO ((void));
221static void unused_prefix_warnings PROTO ((struct path_prefix *));
222static void clear_args PROTO ((void));
223static void fatal_error PROTO ((int));
224
225void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN;
226
227/* Called before processing to change/add/remove arguments. */
228extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)),
229 int *, char ***, int *));
230
231/* Called before linking. Returns 0 on success and -1 on failure. */
232extern int lang_specific_pre_link ();
233
234/* Number of extra output files that lang_specific_pre_link may generate. */
235extern int lang_specific_extra_outfiles;
236\f
237/* Specs are strings containing lines, each of which (if not blank)
238is made up of a program name, and arguments separated by spaces.
239The program name must be exact and start from root, since no path
240is searched and it is unreliable to depend on the current working directory.
241Redirection of input or output is not supported; the subprograms must
242accept filenames saying what files to read and write.
243
244In addition, the specs can contain %-sequences to substitute variable text
245or for conditional text. Here is a table of all defined %-sequences.
246Note that spaces are not generated automatically around the results of
247expanding these sequences; therefore, you can concatenate them together
248or with constant text in a single argument.
249
250 %% substitute one % into the program name or argument.
251 %i substitute the name of the input file being processed.
252 %b substitute the basename of the input file being processed.
253 This is the substring up to (and not including) the last period
254 and not including the directory.
255 %gSUFFIX
256 substitute a file name that has suffix SUFFIX and is chosen
257 once per compilation, and mark the argument a la %d. To reduce
258 exposure to denial-of-service attacks, the file name is now
259 chosen in a way that is hard to predict even when previously
260 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
261 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
262 the regexp "[.A-Za-z]*" or the special string "%O", which is
263 treated exactly as if %O had been pre-processed. Previously, %g
264 was simply substituted with a file name chosen once per compilation,
265 without regard to any appended suffix (which was therefore treated
266 just like ordinary text), making such attacks more likely to succeed.
267 %uSUFFIX
268 like %g, but generates a new temporary file name even if %uSUFFIX
269 was already seen.
270 %USUFFIX
271 substitutes the last file name generated with %uSUFFIX, generating a
272 new one if there is no such last file name. In the absence of any
273 %uSUFFIX, this is just like %gSUFFIX, except they don't share
274 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
275 would involve the generation of two distinct file names, one
276 for each `%g.s' and another for each `%U.s'. Previously, %U was
277 simply substituted with a file name chosen for the previous %u,
278 without regard to any appended suffix.
279 %d marks the argument containing or following the %d as a
280 temporary file name, so that that file will be deleted if CC exits
281 successfully. Unlike %g, this contributes no text to the argument.
282 %w marks the argument containing or following the %w as the
283 "output file" of this compilation. This puts the argument
284 into the sequence of arguments that %o will substitute later.
285 %W{...}
286 like %{...} but mark last argument supplied within
287 as a file to be deleted on failure.
288 %o substitutes the names of all the output files, with spaces
289 automatically placed around them. You should write spaces
290 around the %o as well or the results are undefined.
291 %o is for use in the specs for running the linker.
292 Input files whose names have no recognized suffix are not compiled
293 at all, but they are included among the output files, so they will
294 be linked.
295 %O substitutes the suffix for object files. Note that this is
296 handled specially when it immediately follows %g, %u, or %U,
297 because of the need for those to form complete file names. The
298 handling is such that %O is treated exactly as if it had already
299 been substituted, except that %g, %u, and %U do not currently
300 support additional SUFFIX characters following %O as they would
301 following, for example, `.o'.
302 %p substitutes the standard macro predefinitions for the
303 current target machine. Use this when running cpp.
304 %P like %p, but puts `__' before and after the name of each macro.
305 (Except macros that already have __.)
306 This is for ANSI C.
307 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
308 %s current argument is the name of a library or startup file of some sort.
309 Search for that file in a standard list of directories
310 and substitute the full name found.
311 %eSTR Print STR as an error message. STR is terminated by a newline.
312 Use this when inconsistent options are detected.
313 %x{OPTION} Accumulate an option for %X.
314 %X Output the accumulated linker options specified by compilations.
315 %Y Output the accumulated assembler options specified by compilations.
316 %Z Output the accumulated preprocessor options specified by compilations.
317 %v1 Substitute the major version number of GCC.
318 (For version 2.5.n, this is 2.)
319 %v2 Substitute the minor version number of GCC.
320 (For version 2.5.n, this is 5.)
321 %a process ASM_SPEC as a spec.
322 This allows config.h to specify part of the spec for running as.
323 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
324 used here. This can be used to run a post-processor after the
325 assembler has done its job.
326 %D Dump out a -L option for each directory in startfile_prefixes.
327 If multilib_dir is set, extra entries are generated with it affixed.
328 %l process LINK_SPEC as a spec.
329 %L process LIB_SPEC as a spec.
330 %G process LIBGCC_SPEC as a spec.
331 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
332 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
333 %c process SIGNED_CHAR_SPEC as a spec.
334 %C process CPP_SPEC as a spec. A capital C is actually used here.
335 %1 process CC1_SPEC as a spec.
336 %2 process CC1PLUS_SPEC as a spec.
337 %| output "-" if the input for the current command is coming from a pipe.
338 %* substitute the variable part of a matched option. (See below.)
339 Note that each comma in the substituted string is replaced by
340 a single space.
341 %{S} substitutes the -S switch, if that switch was given to CC.
342 If that switch was not specified, this substitutes nothing.
343 Here S is a metasyntactic variable.
344 %{S*} substitutes all the switches specified to CC whose names start
345 with -S. This is used for -o, -D, -I, etc; switches that take
346 arguments. CC considers `-o foo' as being one switch whose
347 name starts with `o'. %{o*} would substitute this text,
348 including the space; thus, two arguments would be generated.
349 %{^S*} likewise, but don't put a blank between a switch and any args.
350 %{S*:X} substitutes X if one or more switches whose names start with -S are
351 specified to CC. Note that the tail part of the -S option
352 (i.e. the part matched by the `*') will be substituted for each
353 occurrence of %* within X.
354 %{S:X} substitutes X, but only if the -S switch was given to CC.
355 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
356 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
357 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
358 %{.S:X} substitutes X, but only if processing a file with suffix S.
359 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
360 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
361 combined with ! and . as above binding stronger than the OR.
362 %(Spec) processes a specification defined in a specs file as *Spec:
363 %[Spec] as above, but put __ around -D arguments
364
365The conditional text X in a %{S:X} or %{!S:X} construct may contain
366other nested % constructs or spaces, or even newlines. They are
367processed as usual, as described above.
368
369The -O, -f, -m, and -W switches are handled specifically in these
370constructs. If another value of -O or the negated form of a -f, -m, or
371-W switch is found later in the command line, the earlier switch
372value is ignored, except with {S*} where S is just one letter; this
373passes all matching options.
374
375The character | at the beginning of the predicate text is used to indicate
376that a command should be piped to the following command, but only if -pipe
377is specified.
378
379Note that it is built into CC which switches take arguments and which
380do not. You might think it would be useful to generalize this to
381allow each compiler's spec to say which switches take arguments. But
382this cannot be done in a consistent fashion. CC cannot even decide
383which input files have been specified without knowing which switches
384take arguments, and it must know which input files to compile in order
385to tell which compilers to run.
386
387CC also knows implicitly that arguments starting in `-l' are to be
388treated as compiler output files, and passed to the linker in their
389proper position among the other output files. */
390\f
391/* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
392
393/* config.h can define ASM_SPEC to provide extra args to the assembler
394 or extra switch-translations. */
395#ifndef ASM_SPEC
396#define ASM_SPEC ""
397#endif
398
399/* config.h can define ASM_FINAL_SPEC to run a post processor after
400 the assembler has run. */
401#ifndef ASM_FINAL_SPEC
402#define ASM_FINAL_SPEC ""
403#endif
404
405/* config.h can define CPP_SPEC to provide extra args to the C preprocessor
406 or extra switch-translations. */
407#ifndef CPP_SPEC
408#define CPP_SPEC ""
409#endif
410
411/* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
412 or extra switch-translations. */
413#ifndef CC1_SPEC
414#define CC1_SPEC ""
415#endif
416
417/* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
418 or extra switch-translations. */
419#ifndef CC1PLUS_SPEC
420#define CC1PLUS_SPEC ""
421#endif
422
423/* config.h can define LINK_SPEC to provide extra args to the linker
424 or extra switch-translations. */
425#ifndef LINK_SPEC
426#define LINK_SPEC ""
427#endif
428
429/* config.h can define LIB_SPEC to override the default libraries. */
430#ifndef LIB_SPEC
431#define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
432#endif
433
434/* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
435 included. */
436#ifndef LIBGCC_SPEC
437#if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
438/* Have gcc do the search for libgcc.a. */
439#define LIBGCC_SPEC "libgcc.a%s"
440#else
441#define LIBGCC_SPEC "-lgcc"
442#endif
443#endif
444
445/* config.h can define STARTFILE_SPEC to override the default crt0 files. */
446#ifndef STARTFILE_SPEC
447#define STARTFILE_SPEC \
448 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
449#endif
450
451/* config.h can define SWITCHES_NEED_SPACES to control which options
452 require spaces between the option and the argument. */
453#ifndef SWITCHES_NEED_SPACES
454#define SWITCHES_NEED_SPACES ""
455#endif
456
457/* config.h can define ENDFILE_SPEC to override the default crtn files. */
458#ifndef ENDFILE_SPEC
459#define ENDFILE_SPEC ""
460#endif
461
462/* This spec is used for telling cpp whether char is signed or not. */
463#ifndef SIGNED_CHAR_SPEC
464/* Use #if rather than ?:
465 because MIPS C compiler rejects like ?: in initializers. */
466#if DEFAULT_SIGNED_CHAR
467#define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
468#else
469#define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
470#endif
471#endif
472
473#ifndef LINKER_NAME
474#define LINKER_NAME "collect2"
475#endif
476
477static char *cpp_spec = CPP_SPEC;
478static char *cpp_predefines = CPP_PREDEFINES;
479static char *cc1_spec = CC1_SPEC;
480static char *cc1plus_spec = CC1PLUS_SPEC;
481static char *signed_char_spec = SIGNED_CHAR_SPEC;
482static char *asm_spec = ASM_SPEC;
483static char *asm_final_spec = ASM_FINAL_SPEC;
484static char *link_spec = LINK_SPEC;
485static char *lib_spec = LIB_SPEC;
486static char *libgcc_spec = LIBGCC_SPEC;
487static char *endfile_spec = ENDFILE_SPEC;
488static char *startfile_spec = STARTFILE_SPEC;
489static char *switches_need_spaces = SWITCHES_NEED_SPACES;
490static char *linker_name_spec = LINKER_NAME;
491
492/* Some compilers have limits on line lengths, and the multilib_select
493 and/or multilib_matches strings can be very long, so we build them at
494 run time. */
495static struct obstack multilib_obstack;
496static char *multilib_select;
497static char *multilib_matches;
498static char *multilib_defaults;
499#include "multilib.h"
500
501/* Check whether a particular argument is a default argument. */
502
503#ifndef MULTILIB_DEFAULTS
504#define MULTILIB_DEFAULTS { "" }
505#endif
506
507static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
508
509struct user_specs {
510 struct user_specs *next;
511 const char *filename;
512};
513
514static struct user_specs *user_specs_head, *user_specs_tail;
515
516/* This defines which switch letters take arguments. */
517
518#define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
519 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
520 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
521 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
522 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
523 || (CHAR) == 'B' || (CHAR) == 'b')
524
525#ifndef SWITCH_TAKES_ARG
526#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
527#endif
528
529/* This defines which multi-letter switches take arguments. */
530
531#define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
532 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
533 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
534 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
535 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
536 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
537 || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
538
539#ifndef WORD_SWITCH_TAKES_ARG
540#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
541#endif
542\f
543
544#ifdef HAVE_EXECUTABLE_SUFFIX
545/* This defines which switches stop a full compilation. */
546#define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
547 ((CHAR) == 'c' || (CHAR) == 'S')
548
549#ifndef SWITCH_CURTAILS_COMPILATION
550#define SWITCH_CURTAILS_COMPILATION(CHAR) \
551 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
552#endif
553#endif
554
555/* Record the mapping from file suffixes for compilation specs. */
556
557struct compiler
558{
559 const char *suffix; /* Use this compiler for input files
560 whose names end in this suffix. */
561
562 const char *spec[4]; /* To use this compiler, concatenate these
563 specs and pass to do_spec. */
564};
565
566/* Pointer to a vector of `struct compiler' that gives the spec for
567 compiling a file, based on its suffix.
568 A file that does not end in any of these suffixes will be passed
569 unchanged to the loader and nothing else will be done to it.
570
571 An entry containing two 0s is used to terminate the vector.
572
573 If multiple entries match a file, the last matching one is used. */
574
575static struct compiler *compilers;
576
577/* Number of entries in `compilers', not counting the null terminator. */
578
579static int n_compilers;
580
581/* The default list of file name suffixes and their compilation specs. */
582
583static struct compiler default_compilers[] =
584{
585 /* Add lists of suffixes of known languages here. If those languages
586 were not present when we built the driver, we will hit these copies
587 and be given a more meaningful error than "file not used since
588 linking is not done". */
589 {".m", {"#Objective-C"}},
590 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}},
591 {".c++", {"#C++"}}, {".C", {"#C++"}},
592 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
593 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
594 {".fpp", {"#Fortran"}},
595 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
596 /* Next come the entries for C. */
597 {".c", {"@c"}},
598 {"@c",
599 {
600#if USE_CPPLIB
601 "%{E|M|MM:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
602 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
603 %{C:%{!E:%eGNU C does not support -C without using -E}}\
604 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
605 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
606 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
607 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
608 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
609 %{ffast-math:-D__FAST_MATH__}\
610 %{traditional} %{ftraditional:-traditional}\
611 %{traditional-cpp:-traditional}\
612 %{fleading-underscore} %{fno-leading-underscore}\
613 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
614 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
615 %{!E:%{!M:%{!MM:cc1 %i %1 \
616 %{std*} %{nostdinc*} %{A*} %{I*} %I\
617 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
618 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
619 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
620 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
621 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
622 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
623 %{ffast-math:-D__FAST_MATH__}\
624 %{H} %C %{D*} %{U*} %{i*} %Z\
625 %{ftraditional:-traditional}\
626 %{traditional-cpp:-traditional}\
627 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
628 %{aux-info*} %{Qn:-fno-ident}\
629 %{--help:--help}\
630 %{g*} %{O*} %{W*} %{w} %{pedantic*}\
631 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
632 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
633 %{!S:as %a %Y\
634 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
635 %{!pipe:%g.s} %A\n }}}}"
636#else /* ! USE_CPPLIB */
637 "cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
638 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
639 %{C:%{!E:%eGNU C does not support -C without using -E}}\
640 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
641 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
642 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
643 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
644 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
645 %{ffast-math:-D__FAST_MATH__}\
646 %{traditional} %{ftraditional:-traditional}\
647 %{traditional-cpp:-traditional}\
648 %{fleading-underscore} %{fno-leading-underscore}\
649 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
650 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
651 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
652 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
653 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
654 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
655 %{aux-info*} %{Qn:-fno-ident}\
656 %{--help:--help} \
657 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
658 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
659 %{!S:as %a %Y\
660 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
661 %{!pipe:%g.s} %A\n }}}}"
662#endif /* ! USE_CPPLIB */
663 }},
664 {"-",
665 {"%{E:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\
666 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
667 %{C:%{!E:%eGNU C does not support -C without using -E}}\
668 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
669 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
670 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
671 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
672 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
673 %{ffast-math:-D__FAST_MATH__}\
674 %{traditional} %{ftraditional:-traditional}\
675 %{traditional-cpp:-traditional}\
676 %{fleading-underscore} %{fno-leading-underscore}\
677 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
678 %i %W{o*}}\
679 %{!E:%e-E required when input is from standard input}"}},
680 {".h", {"@c-header"}},
681 {"@c-header",
682 {"%{!E:%eCompilation of header file requested} \
683 cpp0 %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
684 %{C:%{!E:%eGNU C does not support -C without using -E}}\
685 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
686 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\
687 %{std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\
688 %{!undef:%{!std=*:%p}%{std=gnu*:%p} %P} %{trigraphs}\
689 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
690 %{ffast-math:-D__FAST_MATH__}\
691 %{traditional} %{ftraditional:-traditional}\
692 %{traditional-cpp:-traditional}\
693 %{fleading-underscore} %{fno-leading-underscore}\
694 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
695 %i %W{o*}"}},
696 {".i", {"@cpp-output"}},
697 {"@cpp-output",
698 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
699 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
700 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
701 %{aux-info*} %{Qn:-fno-ident}\
702 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
703 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
704 %{!S:as %a %Y\
705 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
706 %{!pipe:%g.s} %A\n }}}}"}},
707 {".s", {"@assembler"}},
708 {"@assembler",
709 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
710 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
711 %i %A\n }}}}"}},
712 {".S", {"@assembler-with-cpp"}},
713 {"@assembler-with-cpp",
714 {"cpp0 -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
715 %{C:%{!E:%eGNU C does not support -C without using -E}}\
716 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
717 -$ %{!undef:%p %P} -D__ASSEMBLER__ \
718 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
719 %{ffast-math:-D__FAST_MATH__}\
720 %{traditional} %{ftraditional:-traditional}\
721 %{traditional-cpp:-traditional}\
722 %{fleading-underscore} %{fno-leading-underscore}\
723 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
724 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
725 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
726 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
727 %{!pipe:%g.s} %A\n }}}}"}},
728#include "specs.h"
729 /* Mark end of table */
730 {0, {0}}
731};
732
733/* Number of elements in default_compilers, not counting the terminator. */
734
735static int n_default_compilers
736 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
737
738/* Here is the spec for running the linker, after compiling all files. */
739
740/* -u* was put back because both BSD and SysV seem to support it. */
741/* %{static:} simply prevents an error message if the target machine
742 doesn't handle -static. */
743/* We want %{T*} after %{L*} and %D so that it can be used to specify linker
744 scripts which exist in user specified directories, or in standard
745 directories. */
746#ifdef LINK_COMMAND_SPEC
747/* Provide option to override link_command_spec from machine specific
748 configuration files. */
749static const char *link_command_spec =
750 LINK_COMMAND_SPEC;
751#else
752#ifdef LINK_LIBGCC_SPECIAL
753/* Don't generate -L options. */
754static const char *link_command_spec = "\
755%{!fsyntax-only: \
756 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
757 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
758 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
759 %{static:} %{L*} %o\
760 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
761 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
762 %{T*}\
763 \n }}}}}}";
764#else
765/* Use -L. */
766static const char *link_command_spec = "\
767%{!fsyntax-only: \
768 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
769 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
770 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
771 %{static:} %{L*} %D %o\
772 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
773 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
774 %{T*}\
775 \n }}}}}}";
776#endif
777#endif
778
779/* A vector of options to give to the linker.
780 These options are accumulated by %x,
781 and substituted into the linker command with %X. */
782static int n_linker_options;
783static char **linker_options;
784
785/* A vector of options to give to the assembler.
786 These options are accumulated by -Wa,
787 and substituted into the assembler command with %Y. */
788static int n_assembler_options;
789static char **assembler_options;
790
791/* A vector of options to give to the preprocessor.
792 These options are accumulated by -Wp,
793 and substituted into the preprocessor command with %Z. */
794static int n_preprocessor_options;
795static char **preprocessor_options;
796\f
797/* Define how to map long options into short ones. */
798
799/* This structure describes one mapping. */
800struct option_map
801{
802 /* The long option's name. */
803 const char *name;
804 /* The equivalent short option. */
805 const char *equivalent;
806 /* Argument info. A string of flag chars; NULL equals no options.
807 a => argument required.
808 o => argument optional.
809 j => join argument to equivalent, making one word.
810 * => require other text after NAME as an argument. */
811 const char *arg_info;
812};
813
814/* This is the table of mappings. Mappings are tried sequentially
815 for each option encountered; the first one that matches, wins. */
816
817struct option_map option_map[] =
818 {
819 {"--all-warnings", "-Wall", 0},
820 {"--ansi", "-ansi", 0},
821 {"--assemble", "-S", 0},
822 {"--assert", "-A", "a"},
823 {"--classpath", "-fclasspath=", "aj"},
824 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
825 {"--comments", "-C", 0},
826 {"--compile", "-c", 0},
827 {"--debug", "-g", "oj"},
828 {"--define-macro", "-D", "aj"},
829 {"--dependencies", "-M", 0},
830 {"--dump", "-d", "a"},
831 {"--dumpbase", "-dumpbase", "a"},
832 {"--entry", "-e", 0},
833 {"--extra-warnings", "-W", 0},
834 {"--for-assembler", "-Wa", "a"},
835 {"--for-linker", "-Xlinker", "a"},
836 {"--force-link", "-u", "a"},
837 {"--imacros", "-imacros", "a"},
838 {"--include", "-include", "a"},
839 {"--include-barrier", "-I-", 0},
840 {"--include-directory", "-I", "aj"},
841 {"--include-directory-after", "-idirafter", "a"},
842 {"--include-prefix", "-iprefix", "a"},
843 {"--include-with-prefix", "-iwithprefix", "a"},
844 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
845 {"--include-with-prefix-after", "-iwithprefix", "a"},
846 {"--language", "-x", "a"},
847 {"--library-directory", "-L", "a"},
848 {"--machine", "-m", "aj"},
849 {"--machine-", "-m", "*j"},
850 {"--no-line-commands", "-P", 0},
851 {"--no-precompiled-includes", "-noprecomp", 0},
852 {"--no-standard-includes", "-nostdinc", 0},
853 {"--no-standard-libraries", "-nostdlib", 0},
854 {"--no-warnings", "-w", 0},
855 {"--optimize", "-O", "oj"},
856 {"--output", "-o", "a"},
857 {"--output-class-directory", "-foutput-class-dir=", "ja"},
858 {"--pedantic", "-pedantic", 0},
859 {"--pedantic-errors", "-pedantic-errors", 0},
860 {"--pipe", "-pipe", 0},
861 {"--prefix", "-B", "a"},
862 {"--preprocess", "-E", 0},
863 {"--print-search-dirs", "-print-search-dirs", 0},
864 {"--print-file-name", "-print-file-name=", "aj"},
865 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
866 {"--print-missing-file-dependencies", "-MG", 0},
867 {"--print-multi-lib", "-print-multi-lib", 0},
868 {"--print-multi-directory", "-print-multi-directory", 0},
869 {"--print-prog-name", "-print-prog-name=", "aj"},
870 {"--profile", "-p", 0},
871 {"--profile-blocks", "-a", 0},
872 {"--quiet", "-q", 0},
873 {"--save-temps", "-save-temps", 0},
874 {"--shared", "-shared", 0},
875 {"--silent", "-q", 0},
876 {"--specs", "-specs=", "aj"},
877 {"--static", "-static", 0},
878 {"--std", "-std=", "aj"},
879 {"--symbolic", "-symbolic", 0},
880 {"--target", "-b", "a"},
881 {"--trace-includes", "-H", 0},
882 {"--traditional", "-traditional", 0},
883 {"--traditional-cpp", "-traditional-cpp", 0},
884 {"--trigraphs", "-trigraphs", 0},
885 {"--undefine-macro", "-U", "aj"},
886 {"--use-version", "-V", "a"},
887 {"--user-dependencies", "-MM", 0},
888 {"--verbose", "-v", 0},
889 {"--version", "-dumpversion", 0},
890 {"--warn-", "-W", "*j"},
891 {"--write-dependencies", "-MD", 0},
892 {"--write-user-dependencies", "-MMD", 0},
893 {"--", "-f", "*j"}
894 };
895\f
896/* Translate the options described by *ARGCP and *ARGVP.
897 Make a new vector and store it back in *ARGVP,
898 and store its length in *ARGVC. */
899
900static void
901translate_options (argcp, argvp)
902 int *argcp;
903 const char ***argvp;
904{
905 int i;
906 int argc = *argcp;
907 const char **argv = *argvp;
908 const char **newv =
909 (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *));
910 int newindex = 0;
911
912 i = 0;
913 newv[newindex++] = argv[i++];
914
915 while (i < argc)
916 {
917 /* Translate -- options. */
918 if (argv[i][0] == '-' && argv[i][1] == '-')
919 {
920 size_t j;
921 /* Find a mapping that applies to this option. */
922 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
923 {
924 size_t optlen = strlen (option_map[j].name);
925 size_t arglen = strlen (argv[i]);
926 size_t complen = arglen > optlen ? optlen : arglen;
927 const char *arginfo = option_map[j].arg_info;
928
929 if (arginfo == 0)
930 arginfo = "";
931
932 if (!strncmp (argv[i], option_map[j].name, complen))
933 {
934 const char *arg = 0;
935
936 if (arglen < optlen)
937 {
938 size_t k;
939 for (k = j + 1;
940 k < sizeof (option_map) / sizeof (option_map[0]);
941 k++)
942 if (strlen (option_map[k].name) >= arglen
943 && !strncmp (argv[i], option_map[k].name, arglen))
944 {
945 error ("Ambiguous abbreviation %s", argv[i]);
946 break;
947 }
948
949 if (k != sizeof (option_map) / sizeof (option_map[0]))
950 break;
951 }
952
953 if (arglen > optlen)
954 {
955 /* If the option has an argument, accept that. */
956 if (argv[i][optlen] == '=')
957 arg = argv[i] + optlen + 1;
958
959 /* If this mapping requires extra text at end of name,
960 accept that as "argument". */
961 else if (index (arginfo, '*') != 0)
962 arg = argv[i] + optlen;
963
964 /* Otherwise, extra text at end means mismatch.
965 Try other mappings. */
966 else
967 continue;
968 }
969
970 else if (index (arginfo, '*') != 0)
971 {
972 error ("Incomplete `%s' option", option_map[j].name);
973 break;
974 }
975
976 /* Handle arguments. */
977 if (index (arginfo, 'a') != 0)
978 {
979 if (arg == 0)
980 {
981 if (i + 1 == argc)
982 {
983 error ("Missing argument to `%s' option",
984 option_map[j].name);
985 break;
986 }
987
988 arg = argv[++i];
989 }
990 }
991 else if (index (arginfo, '*') != 0)
992 ;
993 else if (index (arginfo, 'o') == 0)
994 {
995 if (arg != 0)
996 error ("Extraneous argument to `%s' option",
997 option_map[j].name);
998 arg = 0;
999 }
1000
1001 /* Store the translation as one argv elt or as two. */
1002 if (arg != 0 && index (arginfo, 'j') != 0)
1003 newv[newindex++] = concat (option_map[j].equivalent, arg,
1004 NULL_PTR);
1005 else if (arg != 0)
1006 {
1007 newv[newindex++] = option_map[j].equivalent;
1008 newv[newindex++] = arg;
1009 }
1010 else
1011 newv[newindex++] = option_map[j].equivalent;
1012
1013 break;
1014 }
1015 }
1016 i++;
1017 }
1018
1019 /* Handle old-fashioned options--just copy them through,
1020 with their arguments. */
1021 else if (argv[i][0] == '-')
1022 {
1023 const char *p = argv[i] + 1;
1024 int c = *p;
1025 int nskip = 1;
1026
1027 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1028 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1029 else if (WORD_SWITCH_TAKES_ARG (p))
1030 nskip += WORD_SWITCH_TAKES_ARG (p);
1031 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1032 && p[1] == 0)
1033 nskip += 1;
1034 else if (! strcmp (p, "Xlinker"))
1035 nskip += 1;
1036
1037 /* Watch out for an option at the end of the command line that
1038 is missing arguments, and avoid skipping past the end of the
1039 command line. */
1040 if (nskip + i > argc)
1041 nskip = argc - i;
1042
1043 while (nskip > 0)
1044 {
1045 newv[newindex++] = argv[i++];
1046 nskip--;
1047 }
1048 }
1049 else
1050 /* Ordinary operands, or +e options. */
1051 newv[newindex++] = argv[i++];
1052 }
1053
1054 newv[newindex] = 0;
1055
1056 *argvp = newv;
1057 *argcp = newindex;
1058}
1059\f
1060char *
1061xstrerror(e)
1062 int e;
1063{
1064#ifdef HAVE_STRERROR
1065
1066 return strerror(e);
1067
1068#else
1069
1070 if (!e)
1071 return "errno = 0";
1072
1073 if (e > 0 && e < sys_nerr)
1074 return sys_errlist[e];
1075
1076 return "errno = ?";
1077#endif
1078}
1079\f
1080static char *
1081skip_whitespace (p)
1082 char *p;
1083{
1084 while (1)
1085 {
1086 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1087 be considered whitespace. */
1088 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1089 return p + 1;
1090 else if (*p == '\n' || *p == ' ' || *p == '\t')
1091 p++;
1092 else if (*p == '#')
1093 {
1094 while (*p != '\n') p++;
1095 p++;
1096 }
1097 else
1098 break;
1099 }
1100
1101 return p;
1102}
1103\f
1104/* Structure to keep track of the specs that have been defined so far.
1105 These are accessed using %(specname) or %[specname] in a compiler
1106 or link spec. */
1107
1108struct spec_list
1109{
1110 /* The following 2 fields must be first */
1111 /* to allow EXTRA_SPECS to be initialized */
1112 char *name; /* name of the spec. */
1113 char *ptr; /* available ptr if no static pointer */
1114
1115 /* The following fields are not initialized */
1116 /* by EXTRA_SPECS */
1117 char **ptr_spec; /* pointer to the spec itself. */
1118 struct spec_list *next; /* Next spec in linked list. */
1119 int name_len; /* length of the name */
1120 int alloc_p; /* whether string was allocated */
1121};
1122
1123#define INIT_STATIC_SPEC(NAME,PTR) \
1124{ NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1125
1126/* List of statically defined specs */
1127static struct spec_list static_specs[] = {
1128 INIT_STATIC_SPEC ("asm", &asm_spec),
1129 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1130 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1131 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1132 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1133 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1134 INIT_STATIC_SPEC ("link", &link_spec),
1135 INIT_STATIC_SPEC ("lib", &lib_spec),
1136 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1137 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1138 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1139 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1140 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1141 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1142 INIT_STATIC_SPEC ("version", &compiler_version),
1143 INIT_STATIC_SPEC ("multilib", &multilib_select),
1144 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1145 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1146 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1147 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1148};
1149
1150#ifdef EXTRA_SPECS /* additional specs needed */
1151/* Structure to keep track of just the first two args of a spec_list.
1152 That is all that the EXTRA_SPECS macro gives us. */
1153struct spec_list_1
1154{
1155 char *name;
1156 char *ptr;
1157};
1158
1159static struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1160static struct spec_list * extra_specs = (struct spec_list *)0;
1161#endif
1162
1163/* List of dynamically allocates specs that have been defined so far. */
1164
1165static struct spec_list *specs = (struct spec_list *)0;
1166
1167\f
1168/* Initialize the specs lookup routines. */
1169
1170static void
1171init_spec ()
1172{
1173 struct spec_list *next = (struct spec_list *)0;
1174 struct spec_list *sl = (struct spec_list *)0;
1175 int i;
1176
1177 if (specs)
1178 return; /* already initialized */
1179
1180 if (verbose_flag)
1181 notice ("Using builtin specs.\n");
1182
1183#ifdef EXTRA_SPECS
1184 extra_specs = (struct spec_list *)
1185 xmalloc (sizeof(struct spec_list) *
1186 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
1187 bzero ((PTR) extra_specs, sizeof(struct spec_list) *
1188 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
1189
1190 for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--)
1191 {
1192 sl = &extra_specs[i];
1193 sl->name = extra_specs_1[i].name;
1194 sl->ptr = extra_specs_1[i].ptr;
1195 sl->next = next;
1196 sl->name_len = strlen (sl->name);
1197 sl->ptr_spec = &sl->ptr;
1198 next = sl;
1199 }
1200#endif
1201
1202 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1203 {
1204 sl = &static_specs[i];
1205 sl->next = next;
1206 next = sl;
1207 }
1208
1209 specs = sl;
1210}
1211
1212\f
1213/* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1214 removed; If the spec starts with a + then SPEC is added to the end of the
1215 current spec. */
1216
1217static void
1218set_spec (name, spec)
1219 const char *name;
1220 const char *spec;
1221{
1222 struct spec_list *sl;
1223 char *old_spec;
1224 int name_len = strlen (name);
1225 int i;
1226
1227 /* If this is the first call, initialize the statically allocated specs */
1228 if (!specs)
1229 {
1230 struct spec_list *next = (struct spec_list *)0;
1231 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1232 i >= 0; i--)
1233 {
1234 sl = &static_specs[i];
1235 sl->next = next;
1236 next = sl;
1237 }
1238 specs = sl;
1239 }
1240
1241 /* See if the spec already exists */
1242 for (sl = specs; sl; sl = sl->next)
1243 if (name_len == sl->name_len && !strcmp (sl->name, name))
1244 break;
1245
1246 if (!sl)
1247 {
1248 /* Not found - make it */
1249 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1250 sl->name = save_string (name, strlen (name));
1251 sl->name_len = name_len;
1252 sl->ptr_spec = &sl->ptr;
1253 sl->alloc_p = 0;
1254 *(sl->ptr_spec) = "";
1255 sl->next = specs;
1256 specs = sl;
1257 }
1258
1259 old_spec = *(sl->ptr_spec);
1260 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1261 ? concat (old_spec, spec + 1, NULL_PTR)
1262 : save_string (spec, strlen (spec)));
1263
1264#ifdef DEBUG_SPECS
1265 if (verbose_flag)
1266 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1267#endif
1268
1269 /* Free the old spec */
1270 if (old_spec && sl->alloc_p)
1271 free (old_spec);
1272
1273 sl->alloc_p = 1;
1274}
1275\f
1276/* Accumulate a command (program name and args), and run it. */
1277
1278/* Vector of pointers to arguments in the current line of specifications. */
1279
1280static char **argbuf;
1281
1282/* Number of elements allocated in argbuf. */
1283
1284static int argbuf_length;
1285
1286/* Number of elements in argbuf currently in use (containing args). */
1287
1288static int argbuf_index;
1289
1290/* We want this on by default all the time now. */
1291#define MKTEMP_EACH_FILE
1292
1293#ifdef MKTEMP_EACH_FILE
1294
1295extern char *make_temp_file PROTO((const char *));
1296
1297/* This is the list of suffixes and codes (%g/%u/%U) and the associated
1298 temp file. */
1299
1300static struct temp_name {
1301 const char *suffix; /* suffix associated with the code. */
1302 int length; /* strlen (suffix). */
1303 int unique; /* Indicates whether %g or %u/%U was used. */
1304 const char *filename; /* associated filename. */
1305 int filename_length; /* strlen (filename). */
1306 struct temp_name *next;
1307} *temp_names;
1308#endif
1309
1310
1311/* Number of commands executed so far. */
1312
1313static int execution_count;
1314
1315/* Number of commands that exited with a signal. */
1316
1317static int signal_count;
1318
1319/* Name with which this program was invoked. */
1320
1321static const char *programname;
1322\f
1323/* Structures to keep track of prefixes to try when looking for files. */
1324
1325struct prefix_list
1326{
1327 char *prefix; /* String to prepend to the path. */
1328 struct prefix_list *next; /* Next in linked list. */
1329 int require_machine_suffix; /* Don't use without machine_suffix. */
1330 /* 2 means try both machine_suffix and just_machine_suffix. */
1331 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1332};
1333
1334struct path_prefix
1335{
1336 struct prefix_list *plist; /* List of prefixes to try */
1337 int max_len; /* Max length of a prefix in PLIST */
1338 const char *name; /* Name of this list (used in config stuff) */
1339};
1340
1341/* List of prefixes to try when looking for executables. */
1342
1343static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1344
1345/* List of prefixes to try when looking for startup (crt0) files. */
1346
1347static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1348
1349/* List of prefixes to try when looking for include files. */
1350
1351static struct path_prefix include_prefixes = { 0, 0, "include" };
1352
1353/* Suffix to attach to directories searched for commands.
1354 This looks like `MACHINE/VERSION/'. */
1355
1356static const char *machine_suffix = 0;
1357
1358/* Suffix to attach to directories searched for commands.
1359 This is just `MACHINE/'. */
1360
1361static const char *just_machine_suffix = 0;
1362
1363/* Adjusted value of GCC_EXEC_PREFIX envvar. */
1364
1365static const char *gcc_exec_prefix;
1366
1367/* Default prefixes to attach to command names. */
1368
1369#ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1370#undef MD_EXEC_PREFIX
1371#undef MD_STARTFILE_PREFIX
1372#undef MD_STARTFILE_PREFIX_1
1373#endif
1374
1375#ifndef STANDARD_EXEC_PREFIX
1376#define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1377#endif /* !defined STANDARD_EXEC_PREFIX */
1378
1379static const char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1380static const char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1381#ifdef MD_EXEC_PREFIX
1382static const char *md_exec_prefix = MD_EXEC_PREFIX;
1383#endif
1384
1385#ifndef STANDARD_STARTFILE_PREFIX
1386#define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1387#endif /* !defined STANDARD_STARTFILE_PREFIX */
1388
1389#ifdef MD_STARTFILE_PREFIX
1390static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1391#endif
1392#ifdef MD_STARTFILE_PREFIX_1
1393static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1394#endif
1395static const char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1396static const char *standard_startfile_prefix_1 = "/lib/";
1397static const char *standard_startfile_prefix_2 = "/usr/lib/";
1398
1399#ifndef TOOLDIR_BASE_PREFIX
1400#define TOOLDIR_BASE_PREFIX "/usr/local/"
1401#endif
1402static const char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1403static const char *tooldir_prefix;
1404
1405/* Subdirectory to use for locating libraries. Set by
1406 set_multilib_dir based on the compilation options. */
1407
1408static const char *multilib_dir;
1409
1410/* Clear out the vector of arguments (after a command is executed). */
1411
1412static void
1413clear_args ()
1414{
1415 argbuf_index = 0;
1416}
1417
1418/* Add one argument to the vector at the end.
1419 This is done when a space is seen or at the end of the line.
1420 If DELETE_ALWAYS is nonzero, the arg is a filename
1421 and the file should be deleted eventually.
1422 If DELETE_FAILURE is nonzero, the arg is a filename
1423 and the file should be deleted if this compilation fails. */
1424
1425static void
1426store_arg (arg, delete_always, delete_failure)
1427 char *arg;
1428 int delete_always, delete_failure;
1429{
1430 if (argbuf_index + 1 == argbuf_length)
1431 argbuf
1432 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1433
1434 argbuf[argbuf_index++] = arg;
1435 argbuf[argbuf_index] = 0;
1436
1437 if (delete_always || delete_failure)
1438 record_temp_file (arg, delete_always, delete_failure);
1439}
1440\f
1441/* Read compilation specs from a file named FILENAME,
1442 replacing the default ones.
1443
1444 A suffix which starts with `*' is a definition for
1445 one of the machine-specific sub-specs. The "suffix" should be
1446 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1447 The corresponding spec is stored in asm_spec, etc.,
1448 rather than in the `compilers' vector.
1449
1450 Anything invalid in the file is a fatal error. */
1451
1452static void
1453read_specs (filename, main_p)
1454 const char *filename;
1455 int main_p;
1456{
1457 int desc;
1458 int readlen;
1459 struct stat statbuf;
1460 char *buffer;
1461 register char *p;
1462
1463 if (verbose_flag)
1464 notice ("Reading specs from %s\n", filename);
1465
1466 /* Open and stat the file. */
1467 desc = open (filename, O_RDONLY, 0);
1468 if (desc < 0)
1469 pfatal_with_name (filename);
1470 if (stat (filename, &statbuf) < 0)
1471 pfatal_with_name (filename);
1472
1473 /* Read contents of file into BUFFER. */
1474 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1475 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1476 if (readlen < 0)
1477 pfatal_with_name (filename);
1478 buffer[readlen] = 0;
1479 close (desc);
1480
1481 /* Scan BUFFER for specs, putting them in the vector. */
1482 p = buffer;
1483 while (1)
1484 {
1485 char *suffix;
1486 char *spec;
1487 char *in, *out, *p1, *p2, *p3;
1488
1489 /* Advance P in BUFFER to the next nonblank nocomment line. */
1490 p = skip_whitespace (p);
1491 if (*p == 0)
1492 break;
1493
1494 /* Is this a special command that starts with '%'? */
1495 /* Don't allow this for the main specs file, since it would
1496 encourage people to overwrite it. */
1497 if (*p == '%' && !main_p)
1498 {
1499 p1 = p;
1500 while (*p && *p != '\n')
1501 p++;
1502
1503 p++; /* Skip '\n' */
1504
1505 if (!strncmp (p1, "%include", sizeof ("%include")-1)
1506 && (p1[sizeof "%include" - 1] == ' '
1507 || p1[sizeof "%include" - 1] == '\t'))
1508 {
1509 char *new_filename;
1510
1511 p1 += sizeof ("%include");
1512 while (*p1 == ' ' || *p1 == '\t')
1513 p1++;
1514
1515 if (*p1++ != '<' || p[-2] != '>')
1516 fatal ("specs %%include syntax malformed after %ld characters",
1517 (long) (p1 - buffer + 1));
1518
1519 p[-2] = '\0';
1520 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1521 read_specs (new_filename ? new_filename : p1, FALSE);
1522 continue;
1523 }
1524 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1525 && (p1[sizeof "%include_noerr" - 1] == ' '
1526 || p1[sizeof "%include_noerr" - 1] == '\t'))
1527 {
1528 char *new_filename;
1529
1530 p1 += sizeof "%include_noerr";
1531 while (*p1 == ' ' || *p1 == '\t') p1++;
1532
1533 if (*p1++ != '<' || p[-2] != '>')
1534 fatal ("specs %%include syntax malformed after %ld characters",
1535 (long) (p1 - buffer + 1));
1536
1537 p[-2] = '\0';
1538 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1539 if (new_filename)
1540 read_specs (new_filename, FALSE);
1541 else if (verbose_flag)
1542 notice ("Could not find specs file %s\n", p1);
1543 continue;
1544 }
1545 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1546 && (p1[sizeof "%rename" - 1] == ' '
1547 || p1[sizeof "%rename" - 1] == '\t'))
1548 {
1549 int name_len;
1550 struct spec_list *sl;
1551
1552 /* Get original name */
1553 p1 += sizeof "%rename";
1554 while (*p1 == ' ' || *p1 == '\t')
1555 p1++;
1556
1557 if (! ISALPHA ((unsigned char)*p1))
1558 fatal ("specs %%rename syntax malformed after %ld characters",
1559 (long) (p1 - buffer));
1560
1561 p2 = p1;
1562 while (*p2 && !ISSPACE ((unsigned char)*p2))
1563 p2++;
1564
1565 if (*p2 != ' ' && *p2 != '\t')
1566 fatal ("specs %%rename syntax malformed after %ld characters",
1567 (long) (p2 - buffer));
1568
1569 name_len = p2 - p1;
1570 *p2++ = '\0';
1571 while (*p2 == ' ' || *p2 == '\t')
1572 p2++;
1573
1574 if (! ISALPHA ((unsigned char)*p2))
1575 fatal ("specs %%rename syntax malformed after %ld characters",
1576 (long) (p2 - buffer));
1577
1578 /* Get new spec name */
1579 p3 = p2;
1580 while (*p3 && !ISSPACE ((unsigned char)*p3))
1581 p3++;
1582
1583 if (p3 != p-1)
1584 fatal ("specs %%rename syntax malformed after %ld characters",
1585 (long) (p3 - buffer));
1586 *p3 = '\0';
1587
1588 for (sl = specs; sl; sl = sl->next)
1589 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1590 break;
1591
1592 if (!sl)
1593 fatal ("specs %s spec was not found to be renamed", p1);
1594
1595 if (strcmp (p1, p2) == 0)
1596 continue;
1597
1598 if (verbose_flag)
1599 {
1600 notice ("rename spec %s to %s\n", p1, p2);
1601#ifdef DEBUG_SPECS
1602 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1603#endif
1604 }
1605
1606 set_spec (p2, *(sl->ptr_spec));
1607 if (sl->alloc_p)
1608 free (*(sl->ptr_spec));
1609
1610 *(sl->ptr_spec) = "";
1611 sl->alloc_p = 0;
1612 continue;
1613 }
1614 else
1615 fatal ("specs unknown %% command after %ld characters",
1616 (long) (p1 - buffer));
1617 }
1618
1619 /* Find the colon that should end the suffix. */
1620 p1 = p;
1621 while (*p1 && *p1 != ':' && *p1 != '\n')
1622 p1++;
1623
1624 /* The colon shouldn't be missing. */
1625 if (*p1 != ':')
1626 fatal ("specs file malformed after %ld characters",
1627 (long) (p1 - buffer));
1628
1629 /* Skip back over trailing whitespace. */
1630 p2 = p1;
1631 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1632 p2--;
1633
1634 /* Copy the suffix to a string. */
1635 suffix = save_string (p, p2 - p);
1636 /* Find the next line. */
1637 p = skip_whitespace (p1 + 1);
1638 if (p[1] == 0)
1639 fatal ("specs file malformed after %ld characters",
1640 (long) (p - buffer));
1641
1642 p1 = p;
1643 /* Find next blank line or end of string. */
1644 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1645 p1++;
1646
1647 /* Specs end at the blank line and do not include the newline. */
1648 spec = save_string (p, p1 - p);
1649 p = p1;
1650
1651 /* Delete backslash-newline sequences from the spec. */
1652 in = spec;
1653 out = spec;
1654 while (*in != 0)
1655 {
1656 if (in[0] == '\\' && in[1] == '\n')
1657 in += 2;
1658 else if (in[0] == '#')
1659 while (*in && *in != '\n')
1660 in++;
1661
1662 else
1663 *out++ = *in++;
1664 }
1665 *out = 0;
1666
1667 if (suffix[0] == '*')
1668 {
1669 if (! strcmp (suffix, "*link_command"))
1670 link_command_spec = spec;
1671 else
1672 set_spec (suffix + 1, spec);
1673 }
1674 else
1675 {
1676 /* Add this pair to the vector. */
1677 compilers
1678 = ((struct compiler *)
1679 xrealloc (compilers,
1680 (n_compilers + 2) * sizeof (struct compiler)));
1681
1682 compilers[n_compilers].suffix = suffix;
1683 bzero ((char *) compilers[n_compilers].spec,
1684 sizeof compilers[n_compilers].spec);
1685 compilers[n_compilers].spec[0] = spec;
1686 n_compilers++;
1687 bzero ((char *) &compilers[n_compilers],
1688 sizeof compilers[n_compilers]);
1689 }
1690
1691 if (*suffix == 0)
1692 link_command_spec = spec;
1693 }
1694
1695 if (link_command_spec == 0)
1696 fatal ("spec file has no spec for linking");
1697}
1698\f
1699/* Record the names of temporary files we tell compilers to write,
1700 and delete them at the end of the run. */
1701
1702/* This is the common prefix we use to make temp file names.
1703 It is chosen once for each run of this program.
1704 It is substituted into a spec by %g.
1705 Thus, all temp file names contain this prefix.
1706 In practice, all temp file names start with this prefix.
1707
1708 This prefix comes from the envvar TMPDIR if it is defined;
1709 otherwise, from the P_tmpdir macro if that is defined;
1710 otherwise, in /usr/tmp or /tmp;
1711 or finally the current directory if all else fails. */
1712
1713static const char *temp_filename;
1714
1715/* Length of the prefix. */
1716
1717static int temp_filename_length;
1718
1719/* Define the list of temporary files to delete. */
1720
1721struct temp_file
1722{
1723 const char *name;
1724 struct temp_file *next;
1725};
1726
1727/* Queue of files to delete on success or failure of compilation. */
1728static struct temp_file *always_delete_queue;
1729/* Queue of files to delete on failure of compilation. */
1730static struct temp_file *failure_delete_queue;
1731
1732/* Record FILENAME as a file to be deleted automatically.
1733 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1734 otherwise delete it in any case.
1735 FAIL_DELETE nonzero means delete it if a compilation step fails;
1736 otherwise delete it in any case. */
1737
1738static void
1739record_temp_file (filename, always_delete, fail_delete)
1740 const char *filename;
1741 int always_delete;
1742 int fail_delete;
1743{
1744 register char *name;
1745 name = xmalloc (strlen (filename) + 1);
1746 strcpy (name, filename);
1747
1748 if (always_delete)
1749 {
1750 register struct temp_file *temp;
1751 for (temp = always_delete_queue; temp; temp = temp->next)
1752 if (! strcmp (name, temp->name))
1753 goto already1;
1754
1755 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1756 temp->next = always_delete_queue;
1757 temp->name = name;
1758 always_delete_queue = temp;
1759
1760 already1:;
1761 }
1762
1763 if (fail_delete)
1764 {
1765 register struct temp_file *temp;
1766 for (temp = failure_delete_queue; temp; temp = temp->next)
1767 if (! strcmp (name, temp->name))
1768 goto already2;
1769
1770 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1771 temp->next = failure_delete_queue;
1772 temp->name = name;
1773 failure_delete_queue = temp;
1774
1775 already2:;
1776 }
1777}
1778
1779/* Delete all the temporary files whose names we previously recorded. */
1780
1781static void
1782delete_if_ordinary (name)
1783 const char *name;
1784{
1785 struct stat st;
1786#ifdef DEBUG
1787 int i, c;
1788
1789 printf ("Delete %s? (y or n) ", name);
1790 fflush (stdout);
1791 i = getchar ();
1792 if (i != '\n')
1793 while ((c = getchar ()) != '\n' && c != EOF)
1794 ;
1795
1796 if (i == 'y' || i == 'Y')
1797#endif /* DEBUG */
1798 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1799 if (unlink (name) < 0)
1800 if (verbose_flag)
1801 perror_with_name (name);
1802}
1803
1804static void
1805delete_temp_files ()
1806{
1807 register struct temp_file *temp;
1808
1809 for (temp = always_delete_queue; temp; temp = temp->next)
1810 delete_if_ordinary (temp->name);
1811 always_delete_queue = 0;
1812}
1813
1814/* Delete all the files to be deleted on error. */
1815
1816static void
1817delete_failure_queue ()
1818{
1819 register struct temp_file *temp;
1820
1821 for (temp = failure_delete_queue; temp; temp = temp->next)
1822 delete_if_ordinary (temp->name);
1823}
1824
1825static void
1826clear_failure_queue ()
1827{
1828 failure_delete_queue = 0;
1829}
1830\f
1831/* Routine to add variables to the environment. We do this to pass
1832 the pathname of the gcc driver, and the directories search to the
1833 collect2 program, which is being run as ld. This way, we can be
1834 sure of executing the right compiler when collect2 wants to build
1835 constructors and destructors. Since the environment variables we
1836 use come from an obstack, we don't have to worry about allocating
1837 space for them. */
1838
1839#ifndef HAVE_PUTENV
1840
1841void
1842putenv (str)
1843 char *str;
1844{
1845#ifndef VMS /* nor about VMS */
1846
1847 extern char **environ;
1848 char **old_environ = environ;
1849 char **envp;
1850 int num_envs = 0;
1851 int name_len = 1;
1852 int str_len = strlen (str);
1853 char *p = str;
1854 int ch;
1855
1856 while ((ch = *p++) != '\0' && ch != '=')
1857 name_len++;
1858
1859 if (!ch)
1860 abort ();
1861
1862 /* Search for replacing an existing environment variable, and
1863 count the number of total environment variables. */
1864 for (envp = old_environ; *envp; envp++)
1865 {
1866 num_envs++;
1867 if (!strncmp (str, *envp, name_len))
1868 {
1869 *envp = str;
1870 return;
1871 }
1872 }
1873
1874 /* Add a new environment variable */
1875 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1876 *environ = str;
1877 memcpy ((char *) (environ + 1), (char *) old_environ,
1878 sizeof (char *) * (num_envs+1));
1879
1880#endif /* VMS */
1881}
1882
1883#endif /* HAVE_PUTENV */
1884
1885\f
1886/* Build a list of search directories from PATHS.
1887 PREFIX is a string to prepend to the list.
1888 If CHECK_DIR_P is non-zero we ensure the directory exists.
1889 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1890 It is also used by the --print-search-dirs flag. */
1891
1892static char *
1893build_search_list (paths, prefix, check_dir_p)
1894 struct path_prefix *paths;
1895 const char *prefix;
1896 int check_dir_p;
1897{
1898 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1899 int just_suffix_len
1900 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1901 int first_time = TRUE;
1902 struct prefix_list *pprefix;
1903
1904 obstack_grow (&collect_obstack, prefix, strlen (prefix));
1905
1906 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1907 {
1908 int len = strlen (pprefix->prefix);
1909
1910 if (machine_suffix
1911 && (! check_dir_p
1912 || is_directory (pprefix->prefix, machine_suffix, 0)))
1913 {
1914 if (!first_time)
1915 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1916
1917 first_time = FALSE;
1918 obstack_grow (&collect_obstack, pprefix->prefix, len);
1919 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1920 }
1921
1922 if (just_machine_suffix
1923 && pprefix->require_machine_suffix == 2
1924 && (! check_dir_p
1925 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1926 {
1927 if (! first_time)
1928 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1929
1930 first_time = FALSE;
1931 obstack_grow (&collect_obstack, pprefix->prefix, len);
1932 obstack_grow (&collect_obstack, just_machine_suffix,
1933 just_suffix_len);
1934 }
1935
1936 if (! pprefix->require_machine_suffix)
1937 {
1938 if (! first_time)
1939 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1940
1941 first_time = FALSE;
1942 obstack_grow (&collect_obstack, pprefix->prefix, len);
1943 }
1944 }
1945
1946 obstack_1grow (&collect_obstack, '\0');
1947 return obstack_finish (&collect_obstack);
1948}
1949
1950/* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1951 for collect. */
1952
1953static void
1954putenv_from_prefixes (paths, env_var)
1955 struct path_prefix *paths;
1956 const char *env_var;
1957{
1958 putenv (build_search_list (paths, env_var, 1));
1959}
1960\f
1961/* Search for NAME using the prefix list PREFIXES. MODE is passed to
1962 access to check permissions.
1963 Return 0 if not found, otherwise return its name, allocated with malloc. */
1964
1965static char *
1966find_a_file (pprefix, name, mode)
1967 struct path_prefix *pprefix;
1968 const char *name;
1969 int mode;
1970{
1971 char *temp;
1972 const char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1973 struct prefix_list *pl;
1974 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1975
1976#ifdef DEFAULT_ASSEMBLER
1977 if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
1978 name = DEFAULT_ASSEMBLER;
1979 len = strlen(name)+1;
1980 temp = xmalloc (len);
1981 strcpy (temp, name);
1982 return temp;
1983 }
1984#endif
1985
1986#ifdef DEFAULT_LINKER
1987 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
1988 name = DEFAULT_LINKER;
1989 len = strlen(name)+1;
1990 temp = xmalloc (len);
1991 strcpy (temp, name);
1992 return temp;
1993 }
1994#endif
1995
1996 if (machine_suffix)
1997 len += strlen (machine_suffix);
1998
1999 temp = xmalloc (len);
2000
2001 /* Determine the filename to execute (special case for absolute paths). */
2002
2003 if (IS_DIR_SEPARATOR (*name)
2004#ifdef HAVE_DOS_BASED_FILESYSTEM
2005 /* Check for disk name on MS-DOS-based systems. */
2006 || (name[0] && name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2007#endif
2008 )
2009 {
2010 if (access (name, mode) == 0)
2011 {
2012 strcpy (temp, name);
2013 return temp;
2014 }
2015 }
2016 else
2017 for (pl = pprefix->plist; pl; pl = pl->next)
2018 {
2019 if (machine_suffix)
2020 {
2021 /* Some systems have a suffix for executable files.
2022 So try appending that first. */
2023 if (file_suffix[0] != 0)
2024 {
2025 strcpy (temp, pl->prefix);
2026 strcat (temp, machine_suffix);
2027 strcat (temp, name);
2028 strcat (temp, file_suffix);
2029 if (access (temp, mode) == 0)
2030 {
2031 if (pl->used_flag_ptr != 0)
2032 *pl->used_flag_ptr = 1;
2033 return temp;
2034 }
2035 }
2036
2037 /* Now try just the name. */
2038 strcpy (temp, pl->prefix);
2039 strcat (temp, machine_suffix);
2040 strcat (temp, name);
2041 if (access (temp, mode) == 0)
2042 {
2043 if (pl->used_flag_ptr != 0)
2044 *pl->used_flag_ptr = 1;
2045 return temp;
2046 }
2047 }
2048
2049 /* Certain prefixes are tried with just the machine type,
2050 not the version. This is used for finding as, ld, etc. */
2051 if (just_machine_suffix && pl->require_machine_suffix == 2)
2052 {
2053 /* Some systems have a suffix for executable files.
2054 So try appending that first. */
2055 if (file_suffix[0] != 0)
2056 {
2057 strcpy (temp, pl->prefix);
2058 strcat (temp, just_machine_suffix);
2059 strcat (temp, name);
2060 strcat (temp, file_suffix);
2061 if (access (temp, mode) == 0)
2062 {
2063 if (pl->used_flag_ptr != 0)
2064 *pl->used_flag_ptr = 1;
2065 return temp;
2066 }
2067 }
2068
2069 strcpy (temp, pl->prefix);
2070 strcat (temp, just_machine_suffix);
2071 strcat (temp, name);
2072 if (access (temp, mode) == 0)
2073 {
2074 if (pl->used_flag_ptr != 0)
2075 *pl->used_flag_ptr = 1;
2076 return temp;
2077 }
2078 }
2079
2080 /* Certain prefixes can't be used without the machine suffix
2081 when the machine or version is explicitly specified. */
2082 if (! pl->require_machine_suffix)
2083 {
2084 /* Some systems have a suffix for executable files.
2085 So try appending that first. */
2086 if (file_suffix[0] != 0)
2087 {
2088 strcpy (temp, pl->prefix);
2089 strcat (temp, name);
2090 strcat (temp, file_suffix);
2091 if (access (temp, mode) == 0)
2092 {
2093 if (pl->used_flag_ptr != 0)
2094 *pl->used_flag_ptr = 1;
2095 return temp;
2096 }
2097 }
2098
2099 strcpy (temp, pl->prefix);
2100 strcat (temp, name);
2101 if (access (temp, mode) == 0)
2102 {
2103 if (pl->used_flag_ptr != 0)
2104 *pl->used_flag_ptr = 1;
2105 return temp;
2106 }
2107 }
2108 }
2109
2110 free (temp);
2111 return 0;
2112}
2113
2114/* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
2115 at the start of the list, otherwise it goes at the end.
2116
2117 If WARN is nonzero, we will warn if no file is found
2118 through this prefix. WARN should point to an int
2119 which will be set to 1 if this entry is used.
2120
2121 COMPONENT is the value to be passed to update_path.
2122
2123 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2124 the complete value of machine_suffix.
2125 2 means try both machine_suffix and just_machine_suffix. */
2126
2127static void
2128add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2129 struct path_prefix *pprefix;
2130 const char *prefix;
2131 const char *component;
2132 int first;
2133 int require_machine_suffix;
2134 int *warn;
2135{
2136 struct prefix_list *pl, **prev;
2137 int len;
2138
2139 if (! first && pprefix->plist)
2140 {
2141 for (pl = pprefix->plist; pl->next; pl = pl->next)
2142 ;
2143 prev = &pl->next;
2144 }
2145 else
2146 prev = &pprefix->plist;
2147
2148 /* Keep track of the longest prefix */
2149
2150 prefix = update_path (prefix, component);
2151 len = strlen (prefix);
2152 if (len > pprefix->max_len)
2153 pprefix->max_len = len;
2154
2155 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2156 pl->prefix = save_string (prefix, len);
2157 pl->require_machine_suffix = require_machine_suffix;
2158 pl->used_flag_ptr = warn;
2159 if (warn)
2160 *warn = 0;
2161
2162 if (*prev)
2163 pl->next = *prev;
2164 else
2165 pl->next = (struct prefix_list *) 0;
2166 *prev = pl;
2167}
2168
2169/* Print warnings for any prefixes in the list PPREFIX that were not used. */
2170
2171static void
2172unused_prefix_warnings (pprefix)
2173 struct path_prefix *pprefix;
2174{
2175 struct prefix_list *pl = pprefix->plist;
2176
2177 while (pl)
2178 {
2179 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2180 {
2181 if (pl->require_machine_suffix && machine_suffix)
2182 error ("file path prefix `%s%s' never used", pl->prefix,
2183 machine_suffix);
2184 else
2185 error ("file path prefix `%s' never used", pl->prefix);
2186
2187 /* Prevent duplicate warnings. */
2188 *pl->used_flag_ptr = 1;
2189 }
2190
2191 pl = pl->next;
2192 }
2193}
2194
2195\f
2196/* Execute the command specified by the arguments on the current line of spec.
2197 When using pipes, this includes several piped-together commands
2198 with `|' between them.
2199
2200 Return 0 if successful, -1 if failed. */
2201
2202static int
2203execute ()
2204{
2205 int i;
2206 int n_commands; /* # of command. */
2207 char *string;
2208 struct command
2209 {
2210 const char *prog; /* program name. */
2211 char **argv; /* vector of args. */
2212 int pid; /* pid of process for this command. */
2213 };
2214
2215 struct command *commands; /* each command buffer with above info. */
2216
2217 /* Count # of piped commands. */
2218 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2219 if (strcmp (argbuf[i], "|") == 0)
2220 n_commands++;
2221
2222 /* Get storage for each command. */
2223 commands
2224 = (struct command *) alloca (n_commands * sizeof (struct command));
2225
2226 /* Split argbuf into its separate piped processes,
2227 and record info about each one.
2228 Also search for the programs that are to be run. */
2229
2230 commands[0].prog = argbuf[0]; /* first command. */
2231 commands[0].argv = &argbuf[0];
2232 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2233
2234 if (string)
2235 commands[0].argv[0] = string;
2236
2237 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2238 if (strcmp (argbuf[i], "|") == 0)
2239 { /* each command. */
2240#if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2241 fatal ("-pipe not supported");
2242#endif
2243 argbuf[i] = 0; /* termination of command args. */
2244 commands[n_commands].prog = argbuf[i + 1];
2245 commands[n_commands].argv = &argbuf[i + 1];
2246 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2247 if (string)
2248 commands[n_commands].argv[0] = string;
2249 n_commands++;
2250 }
2251
2252 argbuf[argbuf_index] = 0;
2253
2254 /* If -v, print what we are about to do, and maybe query. */
2255
2256 if (verbose_flag)
2257 {
2258 /* For help listings, put a blank line between sub-processes. */
2259 if (print_help_list)
2260 fputc ('\n', stderr);
2261
2262 /* Print each piped command as a separate line. */
2263 for (i = 0; i < n_commands ; i++)
2264 {
2265 char **j;
2266
2267 for (j = commands[i].argv; *j; j++)
2268 fprintf (stderr, " %s", *j);
2269
2270 /* Print a pipe symbol after all but the last command. */
2271 if (i + 1 != n_commands)
2272 fprintf (stderr, " |");
2273 fprintf (stderr, "\n");
2274 }
2275 fflush (stderr);
2276#ifdef DEBUG
2277 notice ("\nGo ahead? (y or n) ");
2278 fflush (stderr);
2279 i = getchar ();
2280 if (i != '\n')
2281 while (getchar () != '\n')
2282 ;
2283
2284 if (i != 'y' && i != 'Y')
2285 return 0;
2286#endif /* DEBUG */
2287 }
2288
2289 /* Run each piped subprocess. */
2290
2291 for (i = 0; i < n_commands; i++)
2292 {
2293 char *errmsg_fmt, *errmsg_arg;
2294 char *string = commands[i].argv[0];
2295
2296 commands[i].pid = pexecute (string, commands[i].argv,
2297 programname, temp_filename,
2298 &errmsg_fmt, &errmsg_arg,
2299 ((i == 0 ? PEXECUTE_FIRST : 0)
2300 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2301 | (string == commands[i].prog
2302 ? PEXECUTE_SEARCH : 0)
2303 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2304
2305 if (commands[i].pid == -1)
2306 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2307
2308 if (string != commands[i].prog)
2309 free (string);
2310 }
2311
2312 execution_count++;
2313
2314 /* Wait for all the subprocesses to finish.
2315 We don't care what order they finish in;
2316 we know that N_COMMANDS waits will get them all.
2317 Ignore subprocesses that we don't know about,
2318 since they can be spawned by the process that exec'ed us. */
2319
2320 {
2321 int ret_code = 0;
2322
2323 for (i = 0; i < n_commands; )
2324 {
2325 int j;
2326 int status;
2327 int pid;
2328
2329 pid = pwait (commands[i].pid, &status, 0);
2330 if (pid < 0)
2331 abort ();
2332
2333 for (j = 0; j < n_commands; j++)
2334 if (commands[j].pid == pid)
2335 {
2336 i++;
2337 if (status != 0)
2338 {
2339 if (WIFSIGNALED (status))
2340 {
2341 fatal ("Internal compiler error: program %s got fatal signal %d",
2342 commands[j].prog, WTERMSIG (status));
2343 signal_count++;
2344 ret_code = -1;
2345 }
2346 else if (WIFEXITED (status)
2347 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2348 ret_code = -1;
2349 }
2350 break;
2351 }
2352 }
2353 return ret_code;
2354 }
2355}
2356\f
2357/* Find all the switches given to us
2358 and make a vector describing them.
2359 The elements of the vector are strings, one per switch given.
2360 If a switch uses following arguments, then the `part1' field
2361 is the switch itself and the `args' field
2362 is a null-terminated vector containing the following arguments.
2363 The `live_cond' field is 1 if the switch is true in a conditional spec,
2364 -1 if false (overridden by a later switch), and is initialized to zero.
2365 The `validated' field is nonzero if any spec has looked at this switch;
2366 if it remains zero at the end of the run, it must be meaningless. */
2367
2368struct switchstr
2369{
2370 const char *part1;
2371 char **args;
2372 int live_cond;
2373 int validated;
2374};
2375
2376static struct switchstr *switches;
2377
2378static int n_switches;
2379
2380struct infile
2381{
2382 const char *name;
2383 const char *language;
2384};
2385
2386/* Also a vector of input files specified. */
2387
2388static struct infile *infiles;
2389
2390static int n_infiles;
2391
2392/* This counts the number of libraries added by lang_specific_driver, so that
2393 we can tell if there were any user supplied any files or libraries. */
2394
2395static int added_libraries;
2396
2397/* And a vector of corresponding output files is made up later. */
2398
2399static const char **outfiles;
2400
2401/* Used to track if none of the -B paths are used. */
2402static int warn_B;
2403
2404/* Used to track if standard path isn't used and -b or -V is specified. */
2405static int warn_std;
2406
2407/* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2408static int *warn_std_ptr = 0;
2409
2410#if defined(FREEBSD_NATIVE)
2411#include <objformat.h>
2412
2413typedef enum { OBJFMT_UNKNOWN, OBJFMT_AOUT, OBJFMT_ELF } objf_t;
2414
2415static objf_t objformat = OBJFMT_UNKNOWN;
2416#endif /* FREEBSD_NATIVE */
2417\f
2418#if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2419
2420/* Convert NAME to a new name if it is the standard suffix. DO_EXE
2421 is true if we should look for an executable suffix as well. */
2422
2423static char *
2424convert_filename (name, do_exe)
2425 char *name;
2426 int do_exe;
2427{
2428 int i;
2429 int len;
2430
2431 if (name == NULL)
2432 return NULL;
2433
2434 len = strlen (name);
2435
2436#ifdef HAVE_OBJECT_SUFFIX
2437 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2438 if (len > 2
2439 && name[len - 2] == '.'
2440 && name[len - 1] == 'o')
2441 {
2442 obstack_grow (&obstack, name, len - 2);
2443 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2444 name = obstack_finish (&obstack);
2445 }
2446#endif
2447
2448#ifdef HAVE_EXECUTABLE_SUFFIX
2449 /* If there is no filetype, make it the executable suffix (which includes
2450 the "."). But don't get confused if we have just "-o". */
2451 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2452 return name;
2453
2454 for (i = len - 1; i >= 0; i--)
2455 if (IS_DIR_SEPARATOR (name[i]))
2456 break;
2457
2458 for (i++; i < len; i++)
2459 if (name[i] == '.')
2460 return name;
2461
2462 obstack_grow (&obstack, name, len);
2463 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2464 name = obstack_finish (&obstack);
2465#endif
2466
2467 return name;
2468}
2469#endif
2470\f
2471/* Display the command line switches accepted by gcc. */
2472static void
2473display_help ()
2474{
2475 printf ("Usage: %s [options] file...\n", programname);
2476 printf ("Options:\n");
2477
2478 printf (" --help Display this information\n");
2479 if (! verbose_flag)
2480 printf (" (Use '-v --help' to display command line options of sub-processes)\n");
2481 printf (" -dumpspecs Display all of the built in spec strings\n");
2482 printf (" -dumpversion Display the version of the compiler\n");
2483 printf (" -dumpmachine Display the compiler's target processor\n");
2484 printf (" -print-search-dirs Display the directories in the compiler's search path\n");
2485 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n");
2486 printf (" -print-file-name=<lib> Display the full path to library <lib>\n");
2487 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n");
2488 printf (" -print-multi-directory Display the root directory for versions of libgcc\n");
2489 printf (" -print-multi-lib Display the mapping between command line options and\n");
2490 printf (" multiple library search directories\n");
2491 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n");
2492 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n");
2493 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n");
2494 printf (" -Xlinker <arg> Pass <arg> on to the linker\n");
2495 printf (" -save-temps Do not delete intermediate files\n");
2496 printf (" -pipe Use pipes rather than intermediate files\n");
2497 printf (" -specs=<file> Override builtin specs with the contents of <file>\n");
2498 printf (" -std=<standard> Assume that the input sources are for <standard>\n");
2499 printf (" -B <directory> Add <directory> to the compiler's search paths\n");
2500 printf (" -b <machine> Run gcc for target <machine>, if installed\n");
2501 printf (" -V <version> Run gcc version number <version>, if installed\n");
2502 printf (" -v Display the programs invoked by the compiler\n");
2503 printf (" -E Preprocess only; do not compile, assemble or link\n");
2504 printf (" -S Compile only; do not assemble or link\n");
2505 printf (" -c Compile and assemble, but do not link\n");
2506 printf (" -o <file> Place the output into <file>\n");
2507 printf (" -x <language> Specify the language of the following input files\n");
2508 printf (" Permissable languages include: c c++ assembler none\n");
2509 printf (" 'none' means revert to the default behaviour of\n");
2510 printf (" guessing the language based on the file's extension\n");
2511
2512 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n");
2513 printf ("the various sub-processes invoked by %s. In order to pass other options\n",
2514 programname);
2515 printf ("on to these processes the -W<letter> options must be used.\n");
2516
2517 /* The rest of the options are displayed by invocations of the various
2518 sub-processes. */
2519}
2520
2521static void
2522add_preprocessor_option (option, len)
2523 const char * option;
2524 int len;
2525{
2526 n_preprocessor_options++;
2527
2528 if (! preprocessor_options)
2529 preprocessor_options
2530 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
2531 else
2532 preprocessor_options
2533 = (char **) xrealloc (preprocessor_options,
2534 n_preprocessor_options * sizeof (char *));
2535
2536 preprocessor_options [n_preprocessor_options - 1] =
2537 save_string (option, len);
2538}
2539
2540static void
2541add_assembler_option (option, len)
2542 const char * option;
2543 int len;
2544{
2545 n_assembler_options++;
2546
2547 if (! assembler_options)
2548 assembler_options
2549 = (char **) xmalloc (n_assembler_options * sizeof (char *));
2550 else
2551 assembler_options
2552 = (char **) xrealloc (assembler_options,
2553 n_assembler_options * sizeof (char *));
2554
2555 assembler_options [n_assembler_options - 1] = save_string (option, len);
2556}
2557
2558static void
2559add_linker_option (option, len)
2560 const char * option;
2561 int len;
2562{
2563 n_linker_options++;
2564
2565 if (! linker_options)
2566 linker_options
2567 = (char **) xmalloc (n_linker_options * sizeof (char *));
2568 else
2569 linker_options
2570 = (char **) xrealloc (linker_options,
2571 n_linker_options * sizeof (char *));
2572
2573 linker_options [n_linker_options - 1] = save_string (option, len);
2574}
2575\f
2576/* Create the vector `switches' and its contents.
2577 Store its length in `n_switches'. */
2578
2579static void
2580process_command (argc, argv)
2581 int argc;
2582 char **argv;
2583{
2584 register int i;
2585 const char *temp;
2586 char *temp1;
2587 char *spec_lang = 0;
2588 int last_language_n_infiles;
2589 int have_c = 0;
2590 int have_o = 0;
2591 int lang_n_infiles = 0;
2592
2593 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2594
2595 n_switches = 0;
2596 n_infiles = 0;
2597 added_libraries = 0;
2598
2599 /* Figure compiler version from version string. */
2600
2601 compiler_version = temp1 =
2602 save_string (version_string, strlen (version_string));
2603 for (; *temp1; ++temp1)
2604 {
2605 if (*temp1 == ' ')
2606 {
2607 *temp1 = '\0';
2608 break;
2609 }
2610 }
2611
2612 /* Set up the default search paths. */
2613
2614 if (gcc_exec_prefix)
2615 {
2616 int len = strlen (gcc_exec_prefix);
2617 if (len > (int) sizeof ("/lib/gcc-lib/")-1
2618 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
2619 {
2620 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2621 if (IS_DIR_SEPARATOR (*temp)
2622 && strncmp (temp+1, "lib", 3) == 0
2623 && IS_DIR_SEPARATOR (temp[4])
2624 && strncmp (temp+5, "gcc-lib", 7) == 0)
2625 len -= sizeof ("/lib/gcc-lib/") - 1;
2626 }
2627
2628 set_std_prefix (gcc_exec_prefix, len);
2629 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2630 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2631 }
2632
2633 /* COMPILER_PATH and LIBRARY_PATH have values
2634 that are lists of directory names with colons. */
2635
2636 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
2637 if (temp)
2638 {
2639 const char *startp, *endp;
2640 char *nstore = (char *) alloca (strlen (temp) + 3);
2641
2642 startp = endp = temp;
2643 while (1)
2644 {
2645 if (*endp == PATH_SEPARATOR || *endp == 0)
2646 {
2647 strncpy (nstore, startp, endp-startp);
2648 if (endp == startp)
2649 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2650 else if (!IS_DIR_SEPARATOR (endp[-1]))
2651 {
2652 nstore[endp-startp] = DIR_SEPARATOR;
2653 nstore[endp-startp+1] = 0;
2654 }
2655 else
2656 nstore[endp-startp] = 0;
2657 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2658 add_prefix (&include_prefixes,
2659 concat (nstore, "include", NULL_PTR),
2660 0, 0, 0, NULL_PTR);
2661 if (*endp == 0)
2662 break;
2663 endp = startp = endp + 1;
2664 }
2665 else
2666 endp++;
2667 }
2668 }
2669
2670 GET_ENV_PATH_LIST (temp, "LIBRARY_PATH");
2671 if (temp && *cross_compile == '0')
2672 {
2673 const char *startp, *endp;
2674 char *nstore = (char *) alloca (strlen (temp) + 3);
2675
2676 startp = endp = temp;
2677 while (1)
2678 {
2679 if (*endp == PATH_SEPARATOR || *endp == 0)
2680 {
2681 strncpy (nstore, startp, endp-startp);
2682 if (endp == startp)
2683 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2684 else if (!IS_DIR_SEPARATOR (endp[-1]))
2685 {
2686 nstore[endp-startp] = DIR_SEPARATOR;
2687 nstore[endp-startp+1] = 0;
2688 }
2689 else
2690 nstore[endp-startp] = 0;
2691 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2692 0, 0, NULL_PTR);
2693 if (*endp == 0)
2694 break;
2695 endp = startp = endp + 1;
2696 }
2697 else
2698 endp++;
2699 }
2700 }
2701
2702 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2703 GET_ENV_PATH_LIST (temp, "LPATH");
2704 if (temp && *cross_compile == '0')
2705 {
2706 const char *startp, *endp;
2707 char *nstore = (char *) alloca (strlen (temp) + 3);
2708
2709 startp = endp = temp;
2710 while (1)
2711 {
2712 if (*endp == PATH_SEPARATOR || *endp == 0)
2713 {
2714 strncpy (nstore, startp, endp-startp);
2715 if (endp == startp)
2716 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2717 else if (!IS_DIR_SEPARATOR (endp[-1]))
2718 {
2719 nstore[endp-startp] = DIR_SEPARATOR;
2720 nstore[endp-startp+1] = 0;
2721 }
2722 else
2723 nstore[endp-startp] = 0;
2724 add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2725 0, 0, NULL_PTR);
2726 if (*endp == 0)
2727 break;
2728 endp = startp = endp + 1;
2729 }
2730 else
2731 endp++;
2732 }
2733 }
2734
2735#if defined(FREEBSD_NATIVE)
2736 {
2737 char buf[64];
2738 if (getobjformat (buf, sizeof buf, &argc, argv))
2739 if (strcmp (buf, "aout") == 0)
2740 objformat = OBJFMT_AOUT;
2741 else if (strcmp (buf, "elf") == 0)
2742 objformat = OBJFMT_ELF;
2743 else
2744 fprintf(stderr, "Unrecognized object format: %s\n", buf);
2745 }
2746#endif /* FREEBSD_NATIVE */
2747
2748 /* Options specified as if they appeared on the command line. */
2749 temp = getenv ("GCC_OPTIONS");
2750 if ((temp) && (strlen (temp) > 0))
2751 {
2752 int len;
2753 int optc = 1;
2754 int new_argc;
2755 char **new_argv;
2756 char *envopts;
2757
2758 while (isspace (*temp))
2759 temp++;
2760 len = strlen (temp);
2761 envopts = (char *) xmalloc (len + 1);
2762 strcpy (envopts, temp);
2763
2764 for (i = 0; i < (len - 1); i++)
2765 if ((isspace (envopts[i])) && ! (isspace (envopts[i+1])))
2766 optc++;
2767
2768 new_argv = (char **) alloca ((optc + argc) * sizeof(char *));
2769
2770 for (i = 0, new_argc = 1; new_argc <= optc; new_argc++)
2771 {
2772 while (isspace (envopts[i]))
2773 i++;
2774 new_argv[new_argc] = envopts + i;
2775 while (!isspace (envopts[i]) && (envopts[i] != '\0'))
2776 i++;
2777 envopts[i++] = '\0';
2778 }
2779 for (i = 1; i < argc; i++)
2780 new_argv[new_argc++] = argv[i];
2781
2782 argv = new_argv;
2783 argc = new_argc;
2784 }
2785
2786 /* Convert new-style -- options to old-style. */
2787 translate_options (&argc, &argv);
2788
2789 /* Do language-specific adjustment/addition of flags. */
2790 lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2791
2792 /* Scan argv twice. Here, the first time, just count how many switches
2793 there will be in their vector, and how many input files in theirs.
2794 Here we also parse the switches that cc itself uses (e.g. -v). */
2795
2796 for (i = 1; i < argc; i++)
2797 {
2798 if (! strcmp (argv[i], "-dumpspecs"))
2799 {
2800 struct spec_list *sl;
2801 init_spec ();
2802 for (sl = specs; sl; sl = sl->next)
2803 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2804 if (link_command_spec)
2805 printf ("*link_command:\n%s\n\n", link_command_spec);
2806 exit (0);
2807 }
2808 else if (! strcmp (argv[i], "-dumpversion"))
2809 {
2810 printf ("%s\n", spec_version);
2811 exit (0);
2812 }
2813 else if (! strcmp (argv[i], "-dumpmachine"))
2814 {
2815 printf ("%s\n", spec_machine);
2816 exit (0);
2817 }
2818 else if (strcmp (argv[i], "-fhelp") == 0)
2819 {
2820 /* translate_options () has turned --help into -fhelp. */
2821 print_help_list = 1;
2822
2823 /* We will be passing a dummy file on to the sub-processes. */
2824 n_infiles++;
2825 n_switches++;
2826
2827 add_preprocessor_option ("--help", 6);
2828 add_assembler_option ("--help", 6);
2829 add_linker_option ("--help", 6);
2830 }
2831 else if (! strcmp (argv[i], "-print-search-dirs"))
2832 print_search_dirs = 1;
2833 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2834 print_file_name = "libgcc.a";
2835 else if (! strncmp (argv[i], "-print-file-name=", 17))
2836 print_file_name = argv[i] + 17;
2837 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2838 print_prog_name = argv[i] + 17;
2839 else if (! strcmp (argv[i], "-print-multi-lib"))
2840 print_multi_lib = 1;
2841 else if (! strcmp (argv[i], "-print-multi-directory"))
2842 print_multi_directory = 1;
2843 else if (! strncmp (argv[i], "-Wa,", 4))
2844 {
2845 int prev, j;
2846 /* Pass the rest of this option to the assembler. */
2847
2848 /* Split the argument at commas. */
2849 prev = 4;
2850 for (j = 4; argv[i][j]; j++)
2851 if (argv[i][j] == ',')
2852 {
2853 add_assembler_option (argv[i] + prev, j - prev);
2854 prev = j + 1;
2855 }
2856
2857 /* Record the part after the last comma. */
2858 add_assembler_option (argv[i] + prev, j - prev);
2859 }
2860 else if (! strncmp (argv[i], "-Wp,", 4))
2861 {
2862 int prev, j;
2863 /* Pass the rest of this option to the preprocessor. */
2864
2865 /* Split the argument at commas. */
2866 prev = 4;
2867 for (j = 4; argv[i][j]; j++)
2868 if (argv[i][j] == ',')
2869 {
2870 add_preprocessor_option (argv[i] + prev, j - prev);
2871 prev = j + 1;
2872 }
2873
2874 /* Record the part after the last comma. */
2875 add_preprocessor_option (argv[i] + prev, j - prev);
2876 }
2877 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2878 /* The +e options to the C++ front-end. */
2879 n_switches++;
2880 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2881 {
2882 int j;
2883 /* Split the argument at commas. */
2884 for (j = 3; argv[i][j]; j++)
2885 n_infiles += (argv[i][j] == ',');
2886 }
2887 else if (strcmp (argv[i], "-Xlinker") == 0)
2888 {
2889 if (i + 1 == argc)
2890 fatal ("argument to `-Xlinker' is missing");
2891
2892 n_infiles++;
2893 i++;
2894 }
2895 else if (strcmp (argv[i], "-l") == 0)
2896 {
2897 if (i + 1 == argc)
2898 fatal ("argument to `-l' is missing");
2899
2900 n_infiles++;
2901 i++;
2902 }
2903 else if (strncmp (argv[i], "-l", 2) == 0)
2904 n_infiles++;
2905 else if (strcmp (argv[i], "-save-temps") == 0)
2906 {
2907 save_temps_flag = 1;
2908 n_switches++;
2909 }
2910 else if (strcmp (argv[i], "-specs") == 0)
2911 {
2912 struct user_specs *user = (struct user_specs *)
2913 xmalloc (sizeof (struct user_specs));
2914 if (++i >= argc)
2915 fatal ("argument to `-specs' is missing");
2916
2917 user->next = (struct user_specs *)0;
2918 user->filename = argv[i];
2919 if (user_specs_tail)
2920 user_specs_tail->next = user;
2921 else
2922 user_specs_head = user;
2923 user_specs_tail = user;
2924 }
2925 else if (strncmp (argv[i], "-specs=", 7) == 0)
2926 {
2927 struct user_specs *user = (struct user_specs *)
2928 xmalloc (sizeof (struct user_specs));
2929 if (strlen (argv[i]) == 7)
2930 fatal ("argument to `-specs=' is missing");
2931
2932 user->next = (struct user_specs *)0;
2933 user->filename = argv[i]+7;
2934 if (user_specs_tail)
2935 user_specs_tail->next = user;
2936 else
2937 user_specs_head = user;
2938 user_specs_tail = user;
2939 }
2940 else if (argv[i][0] == '-' && argv[i][1] != 0)
2941 {
2942 register char *p = &argv[i][1];
2943 register int c = *p;
2944
2945 switch (c)
2946 {
2947 case 'b':
2948 n_switches++;
2949 if (p[1] == 0 && i + 1 == argc)
2950 fatal ("argument to `-b' is missing");
2951 if (p[1] == 0)
2952 spec_machine = argv[++i];
2953 else
2954 spec_machine = p + 1;
2955
2956 warn_std_ptr = &warn_std;
2957 break;
2958
2959 case 'B':
2960 {
2961 char *value;
2962 if (p[1] == 0 && i + 1 == argc)
2963 fatal ("argument to `-B' is missing");
2964 if (p[1] == 0)
2965 value = argv[++i];
2966 else
2967 value = p + 1;
2968 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2969 add_prefix (&startfile_prefixes, value, NULL_PTR,
2970 1, 0, &warn_B);
2971 add_prefix (&include_prefixes, concat (value, "include",
2972 NULL_PTR),
2973 NULL_PTR, 1, 0, NULL_PTR);
2974
2975 /* As a kludge, if the arg is "[foo/]stageN/", just add
2976 "[foo/]include" to the include prefix. */
2977 {
2978 int len = strlen (value);
2979 if ((len == 7
2980 || (len > 7
2981 && (IS_DIR_SEPARATOR (value[len - 8]))))
2982 && strncmp (value + len - 7, "stage", 5) == 0
2983 && ISDIGIT (value[len - 2])
2984 && (IS_DIR_SEPARATOR (value[len - 1])))
2985 {
2986 if (len == 7)
2987 add_prefix (&include_prefixes, "include", NULL_PTR,
2988 1, 0, NULL_PTR);
2989 else
2990 {
2991 char *string = xmalloc (len + 1);
2992 strncpy (string, value, len-7);
2993 strcpy (string+len-7, "include");
2994 add_prefix (&include_prefixes, string, NULL_PTR,
2995 1, 0, NULL_PTR);
2996 }
2997 }
2998 }
2999 n_switches++;
3000 }
3001 break;
3002
3003 case 'v': /* Print our subcommands and print versions. */
3004 n_switches++;
3005 /* If they do anything other than exactly `-v', don't set
3006 verbose_flag; rather, continue on to give the error. */
3007 if (p[1] != 0)
3008 break;
3009 verbose_flag++;
3010 break;
3011
3012 case 'V':
3013 n_switches++;
3014 if (p[1] == 0 && i + 1 == argc)
3015 fatal ("argument to `-V' is missing");
3016 if (p[1] == 0)
3017 spec_version = argv[++i];
3018 else
3019 spec_version = p + 1;
3020 compiler_version = spec_version;
3021 warn_std_ptr = &warn_std;
3022
3023 /* Validate the version number. Use the same checks
3024 done when inserting it into a spec.
3025
3026 The format of the version string is
3027 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3028 {
3029 const char *v = compiler_version;
3030
3031 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3032 while (! ISDIGIT (*v))
3033 v++;
3034
3035 if (v > compiler_version && v[-1] != '-')
3036 fatal ("invalid version number format");
3037
3038 /* Set V after the first period. */
3039 while (ISDIGIT (*v))
3040 v++;
3041
3042 if (*v != '.')
3043 fatal ("invalid version number format");
3044
3045 v++;
3046 while (ISDIGIT (*v))
3047 v++;
3048
3049 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
3050 fatal ("invalid version number format");
3051 }
3052 break;
3053
3054 case 'S':
3055 case 'c':
3056 if (p[1] == 0)
3057 {
3058 have_c = 1;
3059 n_switches++;
3060 break;
3061 }
3062 goto normal_switch;
3063
3064 case 'o':
3065 have_o = 1;
3066#if defined(HAVE_EXECUTABLE_SUFFIX)
3067 if (! have_c)
3068 {
3069 int skip;
3070
3071 /* Forward scan, just in case -S or -c is specified
3072 after -o. */
3073 int j = i + 1;
3074 if (p[1] == 0)
3075 ++j;
3076 while (j < argc)
3077 {
3078 if (argv[j][0] == '-')
3079 {
3080 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3081 && argv[j][2] == 0)
3082 {
3083 have_c = 1;
3084 break;
3085 }
3086 else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
3087 j += skip - (argv[j][2] != 0);
3088 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
3089 j += skip;
3090 }
3091 j++;
3092 }
3093 }
3094#endif
3095#if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
3096 if (p[1] == 0)
3097 argv[i+1] = convert_filename (argv[i+1], ! have_c);
3098 else
3099 argv[i] = convert_filename (argv[i], ! have_c);
3100#endif
3101 goto normal_switch;
3102
3103 default:
3104 normal_switch:
3105 n_switches++;
3106
3107 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3108 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3109 else if (WORD_SWITCH_TAKES_ARG (p))
3110 i += WORD_SWITCH_TAKES_ARG (p);
3111 }
3112 }
3113 else
3114 {
3115 n_infiles++;
3116 lang_n_infiles++;
3117 }
3118 }
3119
3120 if (have_c && have_o && lang_n_infiles > 1)
3121 fatal ("cannot specify -o with -c or -S and multiple compilations");
3122
3123 /* Set up the search paths before we go looking for config files. */
3124
3125 /* These come before the md prefixes so that we will find gcc's subcommands
3126 (such as cpp) rather than those of the host system. */
3127 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3128 as well as trying the machine and the version. */
3129#ifdef FREEBSD_NATIVE
3130 switch (objformat)
3131 {
3132 case OBJFMT_AOUT:
3133 n_switches++; /* add implied -maout */
3134 add_prefix (&exec_prefixes, PREFIX"/libexec/aout/", "BINUTILS",
3135 0, 0, NULL_PTR);
3136 break;
3137 case OBJFMT_ELF:
3138 add_prefix (&exec_prefixes, PREFIX"/libexec/elf/", "BINUTILS",
3139 0, 0, NULL_PTR);
3140 break;
3141 case OBJFMT_UNKNOWN:
3142 fatal ("object format unknown");
3143 }
3144#endif /* FREEBSD_NATIVE */
3145
3146#ifndef OS2
3147 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3148 0, 2, warn_std_ptr);
3149#ifndef FREEBSD_NATIVE
3150 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3151 0, 2, warn_std_ptr);
3152#endif /* not FREEBSD_NATIVE */
3153#endif
3154
3155#ifndef FREEBSD_NATIVE
3156 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3157 0, 1, warn_std_ptr);
3158 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3159 0, 1, warn_std_ptr);
3160#endif /* not FREEBSD_NATIVE */
3161
3162 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3163 dir_separator_str, NULL_PTR);
3164
3165 /* If tooldir is relative, base it on exec_prefixes. A relative
3166 tooldir lets us move the installed tree as a unit.
3167
3168 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3169 directories, so that we can search both the user specified directory
3170 and the standard place. */
3171
3172 if (!IS_DIR_SEPARATOR (*tooldir_prefix))
3173 {
3174 if (gcc_exec_prefix)
3175 {
3176 char *gcc_exec_tooldir_prefix
3177 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3178 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
3179
3180 add_prefix (&exec_prefixes,
3181 concat (gcc_exec_tooldir_prefix, "bin",
3182 dir_separator_str, NULL_PTR),
3183 NULL_PTR, 0, 0, NULL_PTR);
3184 add_prefix (&startfile_prefixes,
3185 concat (gcc_exec_tooldir_prefix, "lib",
3186 dir_separator_str, NULL_PTR),
3187 NULL_PTR, 0, 0, NULL_PTR);
3188 }
3189
3190 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3191 dir_separator_str, spec_version,
3192 dir_separator_str, tooldir_prefix, NULL_PTR);
3193 }
3194
3195#ifndef FREEBSD_NATIVE
3196 add_prefix (&exec_prefixes,
3197 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
3198 "BINUTILS", 0, 0, NULL_PTR);
3199 add_prefix (&startfile_prefixes,
3200 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
3201 "BINUTILS", 0, 0, NULL_PTR);
3202#endif /* not FREEBSD_NATIVE */
3203
3204 /* More prefixes are enabled in main, after we read the specs file
3205 and determine whether this is cross-compilation or not. */
3206
3207
3208 /* Then create the space for the vectors and scan again. */
3209
3210 switches = ((struct switchstr *)
3211 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3212 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3213 n_switches = 0;
3214 n_infiles = 0;
3215 last_language_n_infiles = -1;
3216
3217 /* This, time, copy the text of each switch and store a pointer
3218 to the copy in the vector of switches.
3219 Store all the infiles in their vector. */
3220
3221#if defined(FREEBSD_NATIVE)
3222 switch (objformat)
3223 {
3224 case OBJFMT_AOUT:
3225 switches[n_switches].part1 = "maout";
3226 switches[n_switches].args = 0;
3227 switches[n_switches].live_cond = 0;
3228 switches[n_switches].validated = 0;
3229 n_switches++;
3230 putenv("OBJFORMAT=aout");
3231 break;
3232 case OBJFMT_ELF:
3233 putenv("OBJFORMAT=elf");
3234 break;
3235 case OBJFMT_UNKNOWN:
3236 fatal ("object format unknown");
3237 }
3238#endif /* FREEBSD_NATIVE */
3239
3240 for (i = 1; i < argc; i++)
3241 {
3242 /* Just skip the switches that were handled by the preceding loop. */
3243 if (! strncmp (argv[i], "-Wa,", 4))
3244 ;
3245 else if (! strncmp (argv[i], "-Wp,", 4))
3246 ;
3247 else if (! strcmp (argv[i], "-print-search-dirs"))
3248 ;
3249 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3250 ;
3251 else if (! strncmp (argv[i], "-print-file-name=", 17))
3252 ;
3253 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3254 ;
3255 else if (! strcmp (argv[i], "-print-multi-lib"))
3256 ;
3257 else if (! strcmp (argv[i], "-print-multi-directory"))
3258 ;
3259 else if (strcmp (argv[i], "-fhelp") == 0)
3260 {
3261 if (verbose_flag)
3262 {
3263 /* Create a dummy input file, so that we can pass --help on to
3264 the various sub-processes. */
3265 infiles[n_infiles].language = "c";
3266 infiles[n_infiles++].name = "help-dummy";
3267
3268 /* Preserve the --help switch so that it can be caught by the
3269 cc1 spec string. */
3270 switches[n_switches].part1 = "--help";
3271 switches[n_switches].args = 0;
3272 switches[n_switches].live_cond = 0;
3273 switches[n_switches].validated = 0;
3274
3275 n_switches++;
3276 }
3277 }
3278 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3279 {
3280 /* Compensate for the +e options to the C++ front-end;
3281 they're there simply for cfront call-compatibility. We do
3282 some magic in default_compilers to pass them down properly.
3283 Note we deliberately start at the `+' here, to avoid passing
3284 -e0 or -e1 down into the linker. */
3285 switches[n_switches].part1 = &argv[i][0];
3286 switches[n_switches].args = 0;
3287 switches[n_switches].live_cond = 0;
3288 switches[n_switches].validated = 0;
3289 n_switches++;
3290 }
3291 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3292 {
3293 int prev, j;
3294 /* Split the argument at commas. */
3295 prev = 4;
3296 for (j = 4; argv[i][j]; j++)
3297 if (argv[i][j] == ',')
3298 {
3299 infiles[n_infiles].language = "*";
3300 infiles[n_infiles++].name
3301 = save_string (argv[i] + prev, j - prev);
3302 prev = j + 1;
3303 }
3304 /* Record the part after the last comma. */
3305 infiles[n_infiles].language = "*";
3306 infiles[n_infiles++].name = argv[i] + prev;
3307 }
3308 else if (strcmp (argv[i], "-Xlinker") == 0)
3309 {
3310 infiles[n_infiles].language = "*";
3311 infiles[n_infiles++].name = argv[++i];
3312 }
3313 else if (strcmp (argv[i], "-l") == 0)
3314 { /* POSIX allows separation of -l and the lib arg;
3315 canonicalize by concatenating -l with its arg */
3316 infiles[n_infiles].language = "*";
3317 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
3318 }
3319 else if (strncmp (argv[i], "-l", 2) == 0)
3320 {
3321 infiles[n_infiles].language = "*";
3322 infiles[n_infiles++].name = argv[i];
3323 }
3324 else if (strcmp (argv[i], "-specs") == 0)
3325 i++;
3326 else if (strncmp (argv[i], "-specs=", 7) == 0)
3327 ;
3328 /* -save-temps overrides -pipe, so that temp files are produced */
3329 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
3330 error ("Warning: -pipe ignored since -save-temps specified");
3331 else if (argv[i][0] == '-' && argv[i][1] != 0)
3332 {
3333 register char *p = &argv[i][1];
3334 register int c = *p;
3335
3336 if (c == 'x')
3337 {
3338 if (p[1] == 0 && i + 1 == argc)
3339 fatal ("argument to `-x' is missing");
3340 if (p[1] == 0)
3341 spec_lang = argv[++i];
3342 else
3343 spec_lang = p + 1;
3344 if (! strcmp (spec_lang, "none"))
3345 /* Suppress the warning if -xnone comes after the last input
3346 file, because alternate command interfaces like g++ might
3347 find it useful to place -xnone after each input file. */
3348 spec_lang = 0;
3349 else
3350 last_language_n_infiles = n_infiles;
3351 continue;
3352 }
3353 switches[n_switches].part1 = p;
3354 /* Deal with option arguments in separate argv elements. */
3355 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3356 || WORD_SWITCH_TAKES_ARG (p))
3357 {
3358 int j = 0;
3359 int n_args = WORD_SWITCH_TAKES_ARG (p);
3360
3361 if (n_args == 0)
3362 {
3363 /* Count only the option arguments in separate argv elements. */
3364 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3365 }
3366 if (i + n_args >= argc)
3367 fatal ("argument to `-%s' is missing", p);
3368 switches[n_switches].args
3369 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3370 while (j < n_args)
3371 switches[n_switches].args[j++] = argv[++i];
3372 /* Null-terminate the vector. */
3373 switches[n_switches].args[j] = 0;
3374 }
3375 else if (index (switches_need_spaces, c))
3376 {
3377 /* On some systems, ld cannot handle some options without
3378 a space. So split the option from its argument. */
3379 char *part1 = (char *) xmalloc (2);
3380 part1[0] = c;
3381 part1[1] = '\0';
3382
3383 switches[n_switches].part1 = part1;
3384 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3385 switches[n_switches].args[0] = xmalloc (strlen (p));
3386 strcpy (switches[n_switches].args[0], &p[1]);
3387 switches[n_switches].args[1] = 0;
3388 }
3389 else
3390 switches[n_switches].args = 0;
3391
3392 switches[n_switches].live_cond = 0;
3393 switches[n_switches].validated = 0;
3394 /* This is always valid, since gcc.c itself understands it. */
3395 if (!strcmp (p, "save-temps"))
3396 switches[n_switches].validated = 1;
3397 else
3398 {
3399 char ch = switches[n_switches].part1[0];
3400 if (ch == 'V' || ch == 'b' || ch == 'B')
3401 switches[n_switches].validated = 1;
3402 }
3403 n_switches++;
3404 }
3405 else
3406 {
3407#ifdef HAVE_OBJECT_SUFFIX
3408 argv[i] = convert_filename (argv[i], 0);
3409#endif
3410
3411 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3412 {
3413 perror_with_name (argv[i]);
3414 error_count++;
3415 }
3416 else
3417 {
3418 infiles[n_infiles].language = spec_lang;
3419 infiles[n_infiles++].name = argv[i];
3420 }
3421 }
3422 }
3423
3424 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3425 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3426
3427 switches[n_switches].part1 = 0;
3428 infiles[n_infiles].name = 0;
3429}
3430\f
3431/* Process a spec string, accumulating and running commands. */
3432
3433/* These variables describe the input file name.
3434 input_file_number is the index on outfiles of this file,
3435 so that the output file name can be stored for later use by %o.
3436 input_basename is the start of the part of the input file
3437 sans all directory names, and basename_length is the number
3438 of characters starting there excluding the suffix .c or whatever. */
3439
3440const char *input_filename;
3441static int input_file_number;
3442size_t input_filename_length;
3443static int basename_length;
3444static const char *input_basename;
3445static const char *input_suffix;
3446
3447/* These are variables used within do_spec and do_spec_1. */
3448
3449/* Nonzero if an arg has been started and not yet terminated
3450 (with space, tab or newline). */
3451static int arg_going;
3452
3453/* Nonzero means %d or %g has been seen; the next arg to be terminated
3454 is a temporary file name. */
3455static int delete_this_arg;
3456
3457/* Nonzero means %w has been seen; the next arg to be terminated
3458 is the output file name of this compilation. */
3459static int this_is_output_file;
3460
3461/* Nonzero means %s has been seen; the next arg to be terminated
3462 is the name of a library file and we should try the standard
3463 search dirs for it. */
3464static int this_is_library_file;
3465
3466/* Nonzero means that the input of this command is coming from a pipe. */
3467static int input_from_pipe;
3468
3469/* Process the spec SPEC and run the commands specified therein.
3470 Returns 0 if the spec is successfully processed; -1 if failed. */
3471
3472int
3473do_spec (spec)
3474 const char *spec;
3475{
3476 int value;
3477
3478 clear_args ();
3479 arg_going = 0;
3480 delete_this_arg = 0;
3481 this_is_output_file = 0;
3482 this_is_library_file = 0;
3483 input_from_pipe = 0;
3484
3485 value = do_spec_1 (spec, 0, NULL_PTR);
3486
3487 /* Force out any unfinished command.
3488 If -pipe, this forces out the last command if it ended in `|'. */
3489 if (value == 0)
3490 {
3491 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3492 argbuf_index--;
3493
3494 if (argbuf_index > 0)
3495 value = execute ();
3496 }
3497
3498 return value;
3499}
3500
3501/* Process the sub-spec SPEC as a portion of a larger spec.
3502 This is like processing a whole spec except that we do
3503 not initialize at the beginning and we do not supply a
3504 newline by default at the end.
3505 INSWITCH nonzero means don't process %-sequences in SPEC;
3506 in this case, % is treated as an ordinary character.
3507 This is used while substituting switches.
3508 INSWITCH nonzero also causes SPC not to terminate an argument.
3509
3510 Value is zero unless a line was finished
3511 and the command on that line reported an error. */
3512
3513static int
3514do_spec_1 (spec, inswitch, soft_matched_part)
3515 const char *spec;
3516 int inswitch;
3517 const char *soft_matched_part;
3518{
3519 register const char *p = spec;
3520 register int c;
3521 int i;
3522 const char *string;
3523 int value;
3524
3525 while ((c = *p++))
3526 /* If substituting a switch, treat all chars like letters.
3527 Otherwise, NL, SPC, TAB and % are special. */
3528 switch (inswitch ? 'a' : c)
3529 {
3530 case '\n':
3531 /* End of line: finish any pending argument,
3532 then run the pending command if one has been started. */
3533 if (arg_going)
3534 {
3535 obstack_1grow (&obstack, 0);
3536 string = obstack_finish (&obstack);
3537 if (this_is_library_file)
3538 string = find_file (string);
3539 store_arg (string, delete_this_arg, this_is_output_file);
3540 if (this_is_output_file)
3541 outfiles[input_file_number] = string;
3542 }
3543 arg_going = 0;
3544
3545 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3546 {
3547 for (i = 0; i < n_switches; i++)
3548 if (!strcmp (switches[i].part1, "pipe"))
3549 break;
3550
3551 /* A `|' before the newline means use a pipe here,
3552 but only if -pipe was specified.
3553 Otherwise, execute now and don't pass the `|' as an arg. */
3554 if (i < n_switches)
3555 {
3556 input_from_pipe = 1;
3557 switches[i].validated = 1;
3558 break;
3559 }
3560 else
3561 argbuf_index--;
3562 }
3563
3564 if (argbuf_index > 0)
3565 {
3566 value = execute ();
3567 if (value)
3568 return value;
3569 }
3570 /* Reinitialize for a new command, and for a new argument. */
3571 clear_args ();
3572 arg_going = 0;
3573 delete_this_arg = 0;
3574 this_is_output_file = 0;
3575 this_is_library_file = 0;
3576 input_from_pipe = 0;
3577 break;
3578
3579 case '|':
3580 /* End any pending argument. */
3581 if (arg_going)
3582 {
3583 obstack_1grow (&obstack, 0);
3584 string = obstack_finish (&obstack);
3585 if (this_is_library_file)
3586 string = find_file (string);
3587 store_arg (string, delete_this_arg, this_is_output_file);
3588 if (this_is_output_file)
3589 outfiles[input_file_number] = string;
3590 }
3591
3592 /* Use pipe */
3593 obstack_1grow (&obstack, c);
3594 arg_going = 1;
3595 break;
3596
3597 case '\t':
3598 case ' ':
3599 /* Space or tab ends an argument if one is pending. */
3600 if (arg_going)
3601 {
3602 obstack_1grow (&obstack, 0);
3603 string = obstack_finish (&obstack);
3604 if (this_is_library_file)
3605 string = find_file (string);
3606 store_arg (string, delete_this_arg, this_is_output_file);
3607 if (this_is_output_file)
3608 outfiles[input_file_number] = string;
3609 }
3610 /* Reinitialize for a new argument. */
3611 arg_going = 0;
3612 delete_this_arg = 0;
3613 this_is_output_file = 0;
3614 this_is_library_file = 0;
3615 break;
3616
3617 case '%':
3618 switch (c = *p++)
3619 {
3620 case 0:
3621 fatal ("Invalid specification! Bug in cc.");
3622
3623 case 'b':
3624 obstack_grow (&obstack, input_basename, basename_length);
3625 arg_going = 1;
3626 break;
3627
3628 case 'd':
3629 delete_this_arg = 2;
3630 break;
3631
3632 /* Dump out the directories specified with LIBRARY_PATH,
3633 followed by the absolute directories
3634 that we search for startfiles. */
3635 case 'D':
3636 {
3637 struct prefix_list *pl = startfile_prefixes.plist;
3638 size_t bufsize = 100;
3639 char *buffer = (char *) xmalloc (bufsize);
3640 int idx;
3641
3642 for (; pl; pl = pl->next)
3643 {
3644#ifdef RELATIVE_PREFIX_NOT_LINKDIR
3645 /* Used on systems which record the specified -L dirs
3646 and use them to search for dynamic linking. */
3647 /* Relative directories always come from -B,
3648 and it is better not to use them for searching
3649 at run time. In particular, stage1 loses */
3650 if (!IS_DIR_SEPARATOR (pl->prefix[0]))
3651 continue;
3652#endif
3653 /* Try subdirectory if there is one. */
3654 if (multilib_dir != NULL)
3655 {
3656 if (machine_suffix)
3657 {
3658 if (strlen (pl->prefix) + strlen (machine_suffix)
3659 >= bufsize)
3660 bufsize = (strlen (pl->prefix)
3661 + strlen (machine_suffix)) * 2 + 1;
3662 buffer = (char *) xrealloc (buffer, bufsize);
3663 strcpy (buffer, pl->prefix);
3664 strcat (buffer, machine_suffix);
3665 if (is_directory (buffer, multilib_dir, 1))
3666 {
3667 do_spec_1 ("-L", 0, NULL_PTR);
3668#ifdef SPACE_AFTER_L_OPTION
3669 do_spec_1 (" ", 0, NULL_PTR);
3670#endif
3671 do_spec_1 (buffer, 1, NULL_PTR);
3672 do_spec_1 (multilib_dir, 1, NULL_PTR);
3673 /* Make this a separate argument. */
3674 do_spec_1 (" ", 0, NULL_PTR);
3675 }
3676 }
3677 if (!pl->require_machine_suffix)
3678 {
3679 if (is_directory (pl->prefix, multilib_dir, 1))
3680 {
3681 do_spec_1 ("-L", 0, NULL_PTR);
3682#ifdef SPACE_AFTER_L_OPTION
3683 do_spec_1 (" ", 0, NULL_PTR);
3684#endif
3685 do_spec_1 (pl->prefix, 1, NULL_PTR);
3686 do_spec_1 (multilib_dir, 1, NULL_PTR);
3687 /* Make this a separate argument. */
3688 do_spec_1 (" ", 0, NULL_PTR);
3689 }
3690 }
3691 }
3692 if (machine_suffix)
3693 {
3694 if (is_directory (pl->prefix, machine_suffix, 1))
3695 {
3696 do_spec_1 ("-L", 0, NULL_PTR);
3697#ifdef SPACE_AFTER_L_OPTION
3698 do_spec_1 (" ", 0, NULL_PTR);
3699#endif
3700 do_spec_1 (pl->prefix, 1, NULL_PTR);
3701 /* Remove slash from machine_suffix. */
3702 if (strlen (machine_suffix) >= bufsize)
3703 bufsize = strlen (machine_suffix) * 2 + 1;
3704 buffer = (char *) xrealloc (buffer, bufsize);
3705 strcpy (buffer, machine_suffix);
3706 idx = strlen (buffer);
3707 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3708 buffer[idx - 1] = 0;
3709 do_spec_1 (buffer, 1, NULL_PTR);
3710 /* Make this a separate argument. */
3711 do_spec_1 (" ", 0, NULL_PTR);
3712 }
3713 }
3714 if (!pl->require_machine_suffix)
3715 {
3716 if (is_directory (pl->prefix, "", 1))
3717 {
3718 do_spec_1 ("-L", 0, NULL_PTR);
3719#ifdef SPACE_AFTER_L_OPTION
3720 do_spec_1 (" ", 0, NULL_PTR);
3721#endif
3722 /* Remove slash from pl->prefix. */
3723 if (strlen (pl->prefix) >= bufsize)
3724 bufsize = strlen (pl->prefix) * 2 + 1;
3725 buffer = (char *) xrealloc (buffer, bufsize);
3726 strcpy (buffer, pl->prefix);
3727 idx = strlen (buffer);
3728 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
3729 buffer[idx - 1] = 0;
3730 do_spec_1 (buffer, 1, NULL_PTR);
3731 /* Make this a separate argument. */
3732 do_spec_1 (" ", 0, NULL_PTR);
3733 }
3734 }
3735 }
3736 free (buffer);
3737 }
3738 break;
3739
3740 case 'e':
3741 /* %efoo means report an error with `foo' as error message
3742 and don't execute any more commands for this file. */
3743 {
3744 const char *q = p;
3745 char *buf;
3746 while (*p != 0 && *p != '\n') p++;
3747 buf = (char *) alloca (p - q + 1);
3748 strncpy (buf, q, p - q);
3749 buf[p - q] = 0;
3750 error (buf);
3751 return -1;
3752 }
3753 break;
3754
3755 case 'g':
3756 case 'u':
3757 case 'U':
3758 if (save_temps_flag)
3759 {
3760 obstack_grow (&obstack, input_basename, basename_length);
3761 delete_this_arg = 0;
3762 }
3763 else
3764 {
3765#ifdef MKTEMP_EACH_FILE
3766 /* ??? This has a problem: the total number of
3767 values mktemp can return is limited.
3768 That matters for the names of object files.
3769 In 2.4, do something about that. */
3770 struct temp_name *t;
3771 int suffix_length;
3772 const char *suffix = p;
3773
3774 if (p[0] == '%' && p[1] == 'O')
3775 {
3776 p += 2;
3777 /* We don't support extra suffix characters after %O. */
3778 if (*p == '.' || ISALPHA ((unsigned char)*p))
3779 abort ();
3780 suffix = OBJECT_SUFFIX;
3781 suffix_length = strlen (OBJECT_SUFFIX);
3782 }
3783 else
3784 {
3785 while (*p == '.' || ISALPHA ((unsigned char)*p))
3786 p++;
3787 suffix_length = p - suffix;
3788 }
3789
3790 /* See if we already have an association of %g/%u/%U and
3791 suffix. */
3792 for (t = temp_names; t; t = t->next)
3793 if (t->length == suffix_length
3794 && strncmp (t->suffix, suffix, suffix_length) == 0
3795 && t->unique == (c != 'g'))
3796 break;
3797
3798 /* Make a new association if needed. %u requires one. */
3799 if (t == 0 || c == 'u')
3800 {
3801 if (t == 0)
3802 {
3803 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3804 t->next = temp_names;
3805 temp_names = t;
3806 }
3807 t->length = suffix_length;
3808 t->suffix = save_string (suffix, suffix_length);
3809 t->unique = (c != 'g');
3810 temp_filename = make_temp_file (t->suffix);
3811 temp_filename_length = strlen (temp_filename);
3812 t->filename = temp_filename;
3813 t->filename_length = temp_filename_length;
3814 }
3815
3816 obstack_grow (&obstack, t->filename, t->filename_length);
3817 delete_this_arg = 1;
3818#else
3819 obstack_grow (&obstack, temp_filename, temp_filename_length);
3820 if (c == 'u' || c == 'U')
3821 {
3822 static int unique;
3823 char buff[9];
3824 if (c == 'u')
3825 unique++;
3826 sprintf (buff, "%d", unique);
3827 obstack_grow (&obstack, buff, strlen (buff));
3828 }
3829#endif
3830 delete_this_arg = 1;
3831 }
3832 arg_going = 1;
3833 break;
3834
3835 case 'i':
3836 obstack_grow (&obstack, input_filename, input_filename_length);
3837 arg_going = 1;
3838 break;
3839
3840 case 'I':
3841 {
3842 struct prefix_list *pl = include_prefixes.plist;
3843
3844 if (gcc_exec_prefix)
3845 {
3846 do_spec_1 ("-iprefix", 1, NULL_PTR);
3847 /* Make this a separate argument. */
3848 do_spec_1 (" ", 0, NULL_PTR);
3849 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3850 do_spec_1 (" ", 0, NULL_PTR);
3851 }
3852
3853 for (; pl; pl = pl->next)
3854 {
3855 do_spec_1 ("-isystem", 1, NULL_PTR);
3856 /* Make this a separate argument. */
3857 do_spec_1 (" ", 0, NULL_PTR);
3858 do_spec_1 (pl->prefix, 1, NULL_PTR);
3859 do_spec_1 (" ", 0, NULL_PTR);
3860 }
3861 }
3862 break;
3863
3864 case 'o':
3865 {
3866 int max = n_infiles;
3867 max += lang_specific_extra_outfiles;
3868
3869 for (i = 0; i < max; i++)
3870 if (outfiles[i])
3871 store_arg (outfiles[i], 0, 0);
3872 break;
3873 }
3874
3875 case 'O':
3876 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3877 arg_going = 1;
3878 break;
3879
3880 case 's':
3881 this_is_library_file = 1;
3882 break;
3883
3884 case 'w':
3885 this_is_output_file = 1;
3886 break;
3887
3888 case 'W':
3889 {
3890 int cur_index = argbuf_index;
3891 /* Handle the {...} following the %W. */
3892 if (*p != '{')
3893 abort ();
3894 p = handle_braces (p + 1);
3895 if (p == 0)
3896 return -1;
3897 /* If any args were output, mark the last one for deletion
3898 on failure. */
3899 if (argbuf_index != cur_index)
3900 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3901 break;
3902 }
3903
3904 /* %x{OPTION} records OPTION for %X to output. */
3905 case 'x':
3906 {
3907 const char *p1 = p;
3908 char *string;
3909
3910 /* Skip past the option value and make a copy. */
3911 if (*p != '{')
3912 abort ();
3913 while (*p++ != '}')
3914 ;
3915 string = save_string (p1 + 1, p - p1 - 2);
3916
3917 /* See if we already recorded this option. */
3918 for (i = 0; i < n_linker_options; i++)
3919 if (! strcmp (string, linker_options[i]))
3920 {
3921 free (string);
3922 return 0;
3923 }
3924
3925 /* This option is new; add it. */
3926 add_linker_option (string, strlen (string));
3927 }
3928 break;
3929
3930 /* Dump out the options accumulated previously using %x. */
3931 case 'X':
3932 for (i = 0; i < n_linker_options; i++)
3933 {
3934 do_spec_1 (linker_options[i], 1, NULL_PTR);
3935 /* Make each accumulated option a separate argument. */
3936 do_spec_1 (" ", 0, NULL_PTR);
3937 }
3938 break;
3939
3940 /* Dump out the options accumulated previously using -Wa,. */
3941 case 'Y':
3942 for (i = 0; i < n_assembler_options; i++)
3943 {
3944 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3945 /* Make each accumulated option a separate argument. */
3946 do_spec_1 (" ", 0, NULL_PTR);
3947 }
3948 break;
3949
3950 /* Dump out the options accumulated previously using -Wp,. */
3951 case 'Z':
3952 for (i = 0; i < n_preprocessor_options; i++)
3953 {
3954 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3955 /* Make each accumulated option a separate argument. */
3956 do_spec_1 (" ", 0, NULL_PTR);
3957 }
3958 break;
3959
3960 /* Here are digits and numbers that just process
3961 a certain constant string as a spec. */
3962
3963 case '1':
3964 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3965 if (value != 0)
3966 return value;
3967 break;
3968
3969 case '2':
3970 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3971 if (value != 0)
3972 return value;
3973 break;
3974
3975 case 'a':
3976 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3977 if (value != 0)
3978 return value;
3979 break;
3980
3981 case 'A':
3982 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3983 if (value != 0)
3984 return value;
3985 break;
3986
3987 case 'c':
3988 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3989 if (value != 0)
3990 return value;