OSDN Git Service

* config/linux.h (ASM_COMMENT_START): Remove from here,
[pf3gnuchains/gcc-fork.git] / gcc / gcc.c
1 /* Compiler driver program that can handle many languages.
2    Copyright (C) 1987, 89, 92-97, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!!  */
23
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers.  It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
29
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec".  */
33 \f
34 #include "config.h"
35
36 #ifdef __STDC__
37 #include <stdarg.h>
38 #else
39 #include <varargs.h>
40 #endif
41 #include "system.h"
42 #include <signal.h>
43 #include <sys/stat.h>
44
45 #include "gansidecl.h"
46 #include "obstack.h"
47
48
49 /* ??? Need to find a GCC header to put these in.  */
50 extern int pexecute PROTO ((const char *, char * const *, const char *,
51                             const char *, char **, char **, int));
52 extern int pwait PROTO ((int, int *, int));
53 extern char *update_path PROTO((char *, char *));
54 extern void set_std_prefix PROTO((char *, int));
55 /* Flag arguments to pexecute.  */
56 #define PEXECUTE_FIRST   1
57 #define PEXECUTE_LAST    2
58 #define PEXECUTE_SEARCH  4
59 #define PEXECUTE_VERBOSE 8
60
61 #ifndef WIFSIGNALED
62 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
63 #endif
64 #ifndef WTERMSIG
65 #define WTERMSIG(S) ((S) & 0x7f)
66 #endif
67 #ifndef WIFEXITED
68 #define WIFEXITED(S) (((S) & 0xff) == 0)
69 #endif
70 #ifndef WEXITSTATUS
71 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
72 #endif
73
74 #ifdef VMS
75 #define exit __posix_exit
76 #endif
77
78 #ifdef USG
79 #define vfork fork
80 #endif /* USG */
81
82 /* Test if something is a normal file.  */
83 #ifndef S_ISREG
84 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
85 #endif
86
87 /* Test if something is a directory.  */
88 #ifndef S_ISDIR
89 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
90 #endif
91
92 /* By default there is no special suffix for executables.  */
93 #ifdef EXECUTABLE_SUFFIX
94 #define HAVE_EXECUTABLE_SUFFIX
95 #else
96 #define EXECUTABLE_SUFFIX ""
97 #endif
98
99 /* By default, the suffix for object files is ".o".  */
100 #ifdef OBJECT_SUFFIX
101 #define HAVE_OBJECT_SUFFIX
102 #else
103 #define OBJECT_SUFFIX ".o"
104 #endif
105
106 /* By default, colon separates directories in a path.  */
107 #ifndef PATH_SEPARATOR
108 #define PATH_SEPARATOR ':'
109 #endif
110
111 #ifndef DIR_SEPARATOR
112 #define DIR_SEPARATOR '/'
113 #endif
114
115 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
116
117 #define obstack_chunk_alloc xmalloc
118 #define obstack_chunk_free free
119
120 #ifndef GET_ENVIRONMENT
121 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
122 #endif
123
124 extern char *choose_temp_base PROTO((void));
125
126 #ifndef HAVE_STRERROR
127 extern int sys_nerr;
128 extern char *sys_errlist[];
129 #else
130 extern char *strerror();
131 #endif
132
133 #ifndef HAVE_KILL
134 #define kill(p,s) raise(s)
135 #endif
136
137 /* If a stage of compilation returns an exit status >= 1,
138    compilation of that file ceases.  */
139
140 #define MIN_FATAL_STATUS 1
141
142 /* Flag saying to print the directories gcc will search through looking for
143    programs, libraries, etc.  */
144
145 static int print_search_dirs;
146
147 /* Flag saying to print the full filename of this file
148    as found through our usual search mechanism.  */
149
150 static char *print_file_name = NULL;
151
152 /* As print_file_name, but search for executable file.  */
153
154 static char *print_prog_name = NULL;
155
156 /* Flag saying to print the relative path we'd use to
157    find libgcc.a given the current compiler flags.  */
158
159 static int print_multi_directory;
160
161 /* Flag saying to print the list of subdirectories and
162    compiler flags used to select them in a standard form.  */
163
164 static int print_multi_lib;
165
166 /* Flag indicating whether we should print the command and arguments */
167
168 static int verbose_flag;
169
170 /* Nonzero means write "temp" files in source directory
171    and use the source file's name in them, and don't delete them.  */
172
173 static int save_temps_flag;
174
175 /* The compiler version.  */
176
177 static char *compiler_version;
178
179 /* The target version specified with -V */
180
181 static char *spec_version = DEFAULT_TARGET_VERSION;
182
183 /* The target machine specified with -b.  */
184
185 static char *spec_machine = DEFAULT_TARGET_MACHINE;
186
187 /* Nonzero if cross-compiling.
188    When -b is used, the value comes from the `specs' file.  */
189
190 #ifdef CROSS_COMPILE
191 static char *cross_compile = "1";
192 #else
193 static char *cross_compile = "0";
194 #endif
195
196 /* The number of errors that have occurred; the link phase will not be
197    run if this is non-zero.  */
198 static int error_count = 0;
199
200 /* This is the obstack which we use to allocate many strings.  */
201
202 static struct obstack obstack;
203
204 /* This is the obstack to build an environment variable to pass to
205    collect2 that describes all of the relevant switches of what to
206    pass the compiler in building the list of pointers to constructors
207    and destructors.  */
208
209 static struct obstack collect_obstack;
210
211 extern char *version_string;
212
213 /* Forward declaration for prototypes.  */
214 struct path_prefix;
215
216 static void init_spec           PROTO((void));
217 static void read_specs          PROTO((char *, int));
218 static void set_spec            PROTO((char *, char *));
219 static struct compiler *lookup_compiler PROTO((char *, size_t, char *));
220 static char *build_search_list  PROTO((struct path_prefix *, char *, int));
221 static void putenv_from_prefixes PROTO((struct path_prefix *, char *));
222 static char *find_a_file        PROTO((struct path_prefix *, char *, int));
223 static void add_prefix          PROTO((struct path_prefix *, char *, char *,
224                                        int, int, int *));
225 static char *skip_whitespace    PROTO((char *));
226 static void record_temp_file    PROTO((char *, int, int));
227 static void delete_if_ordinary  PROTO((char *));
228 static void delete_temp_files   PROTO((void));
229 static void delete_failure_queue PROTO((void));
230 static void clear_failure_queue PROTO((void));
231 static int check_live_switch    PROTO((int, int));
232 static char *handle_braces      PROTO((char *));
233 static char *save_string        PROTO((char *, int));
234 static char *concat             PVPROTO((char *, ...));
235 static int do_spec              PROTO((char *));
236 static int do_spec_1            PROTO((char *, int, char *));
237 static char *find_file          PROTO((char *));
238 static int is_directory         PROTO((char *, char *, int));
239 static void validate_switches   PROTO((char *));
240 static void validate_all_switches PROTO((void));
241 static void give_switch         PROTO((int, int, int));
242 static int used_arg             PROTO((char *, int));
243 static int default_arg          PROTO((char *, int));
244 static void set_multilib_dir    PROTO((void));
245 static void print_multilib_info PROTO((void));
246 static void pfatal_with_name    PROTO((char *));
247 static void perror_with_name    PROTO((char *));
248 static void pfatal_pexecute     PROTO((char *, char *));
249 #ifdef HAVE_VPRINTF
250 static void fatal               PVPROTO((char *, ...));
251 static void error               PVPROTO((char *, ...));
252 #else
253 /* We must not provide any prototype here, even if ANSI C.  */
254 static void fatal               PROTO(());
255 static void error               PROTO(());
256 #endif
257
258 void fancy_abort ();
259 char *xmalloc ();
260 char *xrealloc ();
261
262 #ifdef LANG_SPECIFIC_DRIVER
263 #ifdef HAVE_VPRINTF
264 extern void lang_specific_driver PROTO ((void (*) (char *, ...), int *, char ***, int *));
265 #else
266 extern void lang_specific_driver PROTO ((void (*) (), int *, char ***, int *));
267 #endif
268 #endif
269 \f
270 /* Specs are strings containing lines, each of which (if not blank)
271 is made up of a program name, and arguments separated by spaces.
272 The program name must be exact and start from root, since no path
273 is searched and it is unreliable to depend on the current working directory.
274 Redirection of input or output is not supported; the subprograms must
275 accept filenames saying what files to read and write.
276
277 In addition, the specs can contain %-sequences to substitute variable text
278 or for conditional text.  Here is a table of all defined %-sequences.
279 Note that spaces are not generated automatically around the results of
280 expanding these sequences; therefore, you can concatenate them together
281 or with constant text in a single argument.
282
283  %%     substitute one % into the program name or argument.
284  %i     substitute the name of the input file being processed.
285  %b     substitute the basename of the input file being processed.
286         This is the substring up to (and not including) the last period
287         and not including the directory.
288  %g     substitute the temporary-file-name-base.  This is a string chosen
289         once per compilation.  Different temporary file names are made by
290         concatenation of constant strings on the end, as in `%g.s'.
291         %g also has the same effect of %d.
292  %u     like %g, but make the temporary file name unique.
293  %U     returns the last file name generated with %u.
294  %d     marks the argument containing or following the %d as a
295         temporary file name, so that that file will be deleted if CC exits
296         successfully.  Unlike %g, this contributes no text to the argument.
297  %w     marks the argument containing or following the %w as the
298         "output file" of this compilation.  This puts the argument
299         into the sequence of arguments that %o will substitute later.
300  %W{...}
301         like %{...} but mark last argument supplied within
302         as a file to be deleted on failure.
303  %o     substitutes the names of all the output files, with spaces
304         automatically placed around them.  You should write spaces
305         around the %o as well or the results are undefined.
306         %o is for use in the specs for running the linker.
307         Input files whose names have no recognized suffix are not compiled
308         at all, but they are included among the output files, so they will
309         be linked.
310  %O     substitutes the suffix for object files.
311  %p     substitutes the standard macro predefinitions for the
312         current target machine.  Use this when running cpp.
313  %P     like %p, but puts `__' before and after the name of each macro.
314         (Except macros that already have __.)
315         This is for ANSI C.
316  %I     Substitute a -iprefix option made from GCC_EXEC_PREFIX.
317  %s     current argument is the name of a library or startup file of some sort.
318         Search for that file in a standard list of directories
319         and substitute the full name found.
320  %eSTR  Print STR as an error message.  STR is terminated by a newline.
321         Use this when inconsistent options are detected.
322  %x{OPTION}     Accumulate an option for %X.
323  %X     Output the accumulated linker options specified by compilations.
324  %Y     Output the accumulated assembler options specified by compilations.
325  %Z     Output the accumulated preprocessor options specified by compilations.
326  %v1    Substitute the major version number of GCC.
327         (For version 2.5.n, this is 2.)
328  %v2    Substitute the minor version number of GCC.
329         (For version 2.5.n, this is 5.)
330  %a     process ASM_SPEC as a spec.
331         This allows config.h to specify part of the spec for running as.
332  %A     process ASM_FINAL_SPEC as a spec.  A capital A is actually
333         used here.  This can be used to run a post-processor after the
334         assembler has done it's job.
335  %D     Dump out a -L option for each directory in startfile_prefixes.
336         If multilib_dir is set, extra entries are generated with it affixed.
337  %l     process LINK_SPEC as a spec.
338  %L     process LIB_SPEC as a spec.
339  %G     process LIBGCC_SPEC as a spec.
340  %S     process STARTFILE_SPEC as a spec.  A capital S is actually used here.
341  %E     process ENDFILE_SPEC as a spec.  A capital E is actually used here.
342  %c     process SIGNED_CHAR_SPEC as a spec.
343  %C     process CPP_SPEC as a spec.  A capital C is actually used here.
344  %1     process CC1_SPEC as a spec.
345  %2     process CC1PLUS_SPEC as a spec.
346  %|     output "-" if the input for the current command is coming from a pipe.
347  %*     substitute the variable part of a matched option.  (See below.)
348         Note that each comma in the substituted string is replaced by
349         a single space.
350  %{S}   substitutes the -S switch, if that switch was given to CC.
351         If that switch was not specified, this substitutes nothing.
352         Here S is a metasyntactic variable.
353  %{S*}  substitutes all the switches specified to CC whose names start
354         with -S.  This is used for -o, -D, -I, etc; switches that take
355         arguments.  CC considers `-o foo' as being one switch whose
356         name starts with `o'.  %{o*} would substitute this text,
357         including the space; thus, two arguments would be generated.
358  %{^S*} likewise, but don't put a blank between a switch and any args.
359  %{S*:X} substitutes X if one or more switches whose names start with -S are
360         specified to CC.  Note that the tail part of the -S option
361         (i.e. the part matched by the `*') will be substituted for each
362         occurrence of %* within X.
363  %{S:X} substitutes X, but only if the -S switch was given to CC.
364  %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
365  %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
366  %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
367  %{.S:X} substitutes X, but only if processing a file with suffix S.
368  %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
369  %(Spec) processes a specification defined in a specs file as *Spec:
370  %[Spec] as above, but put __ around -D arguments
371
372 The conditional text X in a %{S:X} or %{!S:X} construct may contain
373 other nested % constructs or spaces, or even newlines.  They are
374 processed as usual, as described above.
375
376 The -O, -f, -m, and -W switches are handled specifically in these
377 constructs.  If another value of -O or the negated form of a -f, -m, or
378 -W switch is found later in the command line, the earlier switch
379 value is ignored, except with {S*} where S is just one letter; this
380 passes all matching options.
381
382 The character | is used to indicate that a command should be piped to
383 the following command, but only if -pipe is specified.
384
385 Note that it is built into CC which switches take arguments and which
386 do not.  You might think it would be useful to generalize this to
387 allow each compiler's spec to say which switches take arguments.  But
388 this cannot be done in a consistent fashion.  CC cannot even decide
389 which input files have been specified without knowing which switches
390 take arguments, and it must know which input files to compile in order
391 to tell which compilers to run.
392
393 CC also knows implicitly that arguments starting in `-l' are to be
394 treated as compiler output files, and passed to the linker in their
395 proper position among the other output files.  */
396 \f
397 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1.  */
398
399 /* config.h can define ASM_SPEC to provide extra args to the assembler
400    or extra switch-translations.  */
401 #ifndef ASM_SPEC
402 #define ASM_SPEC ""
403 #endif
404
405 /* config.h can define ASM_FINAL_SPEC to run a post processor after
406    the assembler has run.  */
407 #ifndef ASM_FINAL_SPEC
408 #define ASM_FINAL_SPEC ""
409 #endif
410
411 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
412    or extra switch-translations.  */
413 #ifndef CPP_SPEC
414 #define CPP_SPEC ""
415 #endif
416
417 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
418    or extra switch-translations.  */
419 #ifndef CC1_SPEC
420 #define CC1_SPEC ""
421 #endif
422
423 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
424    or extra switch-translations.  */
425 #ifndef CC1PLUS_SPEC
426 #define CC1PLUS_SPEC ""
427 #endif
428
429 /* config.h can define LINK_SPEC to provide extra args to the linker
430    or extra switch-translations.  */
431 #ifndef LINK_SPEC
432 #define LINK_SPEC ""
433 #endif
434
435 /* config.h can define LIB_SPEC to override the default libraries.  */
436 #ifndef LIB_SPEC
437 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
438 #endif
439
440 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
441    included.  */
442 #ifndef LIBGCC_SPEC
443 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
444 /* Have gcc do the search for libgcc.a.  */
445 #define LIBGCC_SPEC "libgcc.a%s"
446 #else
447 #define LIBGCC_SPEC "-lgcc"
448 #endif
449 #endif
450
451 /* config.h can define STARTFILE_SPEC to override the default crt0 files.  */
452 #ifndef STARTFILE_SPEC
453 #define STARTFILE_SPEC  \
454   "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
455 #endif
456
457 /* config.h can define SWITCHES_NEED_SPACES to control which options
458    require spaces between the option and the argument.  */
459 #ifndef SWITCHES_NEED_SPACES
460 #define SWITCHES_NEED_SPACES ""
461 #endif
462
463 /* config.h can define ENDFILE_SPEC to override the default crtn files.  */
464 #ifndef ENDFILE_SPEC
465 #define ENDFILE_SPEC ""
466 #endif
467
468 /* This spec is used for telling cpp whether char is signed or not.  */
469 #ifndef SIGNED_CHAR_SPEC
470 /* Use #if rather than ?:
471    because MIPS C compiler rejects like ?: in initializers.  */
472 #if DEFAULT_SIGNED_CHAR
473 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
474 #else
475 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
476 #endif
477 #endif
478
479 #ifndef LINKER_NAME
480 #define LINKER_NAME "collect2"
481 #endif
482
483 static char *cpp_spec = CPP_SPEC;
484 static char *cpp_predefines = CPP_PREDEFINES;
485 static char *cc1_spec = CC1_SPEC;
486 static char *cc1plus_spec = CC1PLUS_SPEC;
487 static char *signed_char_spec = SIGNED_CHAR_SPEC;
488 static char *asm_spec = ASM_SPEC;
489 static char *asm_final_spec = ASM_FINAL_SPEC;
490 static char *link_spec = LINK_SPEC;
491 static char *lib_spec = LIB_SPEC;
492 static char *libgcc_spec = LIBGCC_SPEC;
493 static char *endfile_spec = ENDFILE_SPEC;
494 static char *startfile_spec = STARTFILE_SPEC;
495 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
496 static char *linker_name_spec = LINKER_NAME;
497
498 /* Some compilers have limits on line lengths, and the multilib_select
499    and/or multilib_matches strings can be very long, so we build them at
500    run time.  */
501 static struct obstack multilib_obstack;
502 static char *multilib_select;
503 static char *multilib_matches;
504 static char *multilib_defaults;
505 #include "multilib.h"
506
507 /* Check whether a particular argument is a default argument.  */
508
509 #ifndef MULTILIB_DEFAULTS
510 #define MULTILIB_DEFAULTS { "" }
511 #endif
512
513 static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
514
515 struct user_specs {
516   struct user_specs *next;
517   char *filename;
518 };
519
520 static struct user_specs *user_specs_head, *user_specs_tail;
521
522 /* This defines which switch letters take arguments.  */
523
524 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
525   ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
526    || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
527    || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
528    || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
529    || (CHAR) == 'B' || (CHAR) == 'b')
530
531 #ifndef SWITCH_TAKES_ARG
532 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
533 #endif
534
535 /* This defines which multi-letter switches take arguments.  */
536
537 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR)              \
538  (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext")      \
539   || !strcmp (STR, "Tbss") || !strcmp (STR, "include")  \
540   || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
541   || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
542   || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
543   || !strcmp (STR, "isystem") || !strcmp (STR, "specs"))
544
545 #ifndef WORD_SWITCH_TAKES_ARG
546 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
547 #endif
548 \f
549 /* Record the mapping from file suffixes for compilation specs.  */
550
551 struct compiler
552 {
553   char *suffix;                 /* Use this compiler for input files
554                                    whose names end in this suffix.  */
555
556   char *spec[4];                /* To use this compiler, concatenate these
557                                    specs and pass to do_spec.  */
558 };
559
560 /* Pointer to a vector of `struct compiler' that gives the spec for
561    compiling a file, based on its suffix.
562    A file that does not end in any of these suffixes will be passed
563    unchanged to the loader and nothing else will be done to it.
564
565    An entry containing two 0s is used to terminate the vector.
566
567    If multiple entries match a file, the last matching one is used.  */
568
569 static struct compiler *compilers;
570
571 /* Number of entries in `compilers', not counting the null terminator.  */
572
573 static int n_compilers;
574
575 /* The default list of file name suffixes and their compilation specs.  */
576
577 static struct compiler default_compilers[] =
578 {
579   /* Add lists of suffixes of known languages here.  If those languages
580      were not present when we built the driver, we will hit these copies
581      and be given a more meaningful error than "file not used since
582      linking is not done".  */
583   {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}}, {".c++", {"#C++"}},
584   {".C", {"#C++"}}, {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}},
585   {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}},
586   {".fpp", {"#Fortran"}},
587   {".p", {"#Pascal"}}, {".pas", {"#Pascal"}},
588   /* Next come the entries for C.  */
589   {".c", {"@c"}},
590   {"@c",
591    {"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
592         %{C:%{!E:%eGNU C does not support -C without using -E}}\
593         %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
594         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
595         %{ansi:-trigraphs -D__STRICT_ANSI__}\
596         %{!undef:%{!ansi:%p} %P} %{trigraphs} \
597         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
598         %{traditional} %{ftraditional:-traditional}\
599         %{traditional-cpp:-traditional}\
600         %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
601         %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
602     "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
603                    %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
604                    %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
605                    %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
606                    %{aux-info*}\
607                    %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
608                    %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
609               %{!S:as %a %Y\
610                       %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
611                       %{!pipe:%g.s} %A\n }}}}"}},
612   {"-",
613    {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
614         %{C:%{!E:%eGNU C does not support -C without using -E}}\
615         %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
616         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
617         %{ansi:-trigraphs -D__STRICT_ANSI__}\
618         %{!undef:%{!ansi:%p} %P} %{trigraphs}\
619         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
620         %{traditional} %{ftraditional:-traditional}\
621         %{traditional-cpp:-traditional}\
622         %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
623         %i %W{o*}}\
624     %{!E:%e-E required when input is from standard input}"}},
625   {".m", {"@objective-c"}},
626   {"@objective-c",
627    {"cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
628         %{C:%{!E:%eGNU C does not support -C without using -E}}\
629         %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
630         -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
631          %{ansi:-trigraphs -D__STRICT_ANSI__}\
632         %{!undef:%{!ansi:%p} %P} %{trigraphs}\
633         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
634         %{traditional} %{ftraditional:-traditional}\
635         %{traditional-cpp:-traditional}\
636         %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
637         %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
638     "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
639                    %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a*}\
640                    %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
641                    %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
642                    -lang-objc %{gen-decls} \
643                    %{aux-info*}\
644                    %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
645                    %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
646               %{!S:as %a %Y\
647                       %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
648                       %{!pipe:%g.s} %A\n }}}}"}},
649   {".h", {"@c-header"}},
650   {"@c-header",
651    {"%{!E:%eCompilation of header file requested} \
652     cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
653         %{C:%{!E:%eGNU C does not support -C without using -E}}\
654          %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
655         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
656          %{ansi:-trigraphs -D__STRICT_ANSI__}\
657         %{!undef:%{!ansi:%p} %P} %{trigraphs}\
658         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
659         %{traditional} %{ftraditional:-traditional}\
660         %{traditional-cpp:-traditional}\
661         %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
662         %i %W{o*}"}},
663   {".i", {"@cpp-output"}},
664   {"@cpp-output",
665    {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
666                         %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
667                         %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
668                         %{aux-info*}\
669                         %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
670                         %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
671                      %{!S:as %a %Y\
672                              %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
673                              %{!pipe:%g.s} %A\n }}}}"}},
674   {".s", {"@assembler"}},
675   {"@assembler",
676    {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\
677                             %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
678                             %i %A\n }}}}"}},
679   {".S", {"@assembler-with-cpp"}},
680   {"@assembler-with-cpp",
681    {"cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
682         %{C:%{!E:%eGNU C does not support -C without using -E}}\
683         %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
684         -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
685         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
686         %{traditional} %{ftraditional:-traditional}\
687         %{traditional-cpp:-traditional}\
688         %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
689         %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
690     "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
691                     %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
692                     %{!pipe:%g.s} %A\n }}}}"}},
693 #include "specs.h"
694   /* Mark end of table */
695   {0, {0}}
696 };
697
698 /* Number of elements in default_compilers, not counting the terminator.  */
699
700 static int n_default_compilers
701   = (sizeof default_compilers / sizeof (struct compiler)) - 1;
702
703 /* Here is the spec for running the linker, after compiling all files.  */
704
705 /* -u* was put back because both BSD and SysV seem to support it.  */
706 /* %{static:} simply prevents an error message if the target machine
707    doesn't handle -static.  */
708 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
709    scripts which exist in user specified directories, or in standard
710    directories.  */
711 #ifdef LINK_LIBGCC_SPECIAL
712 /* Don't generate -L options.  */
713 static char *link_command_spec = "\
714 %{!fsyntax-only: \
715  %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
716                         %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
717                         %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
718                         %{static:} %{L*} %o\
719                         %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
720                         %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
721                         %{T*}\
722                         \n }}}}}}";
723 #else
724 /* Use -L.  */
725 static char *link_command_spec = "\
726 %{!fsyntax-only: \
727  %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
728                         %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
729                         %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
730                         %{static:} %{L*} %D %o\
731                         %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
732                         %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\
733                         %{T*}\
734                         \n }}}}}}";
735 #endif
736
737 /* A vector of options to give to the linker.
738    These options are accumulated by %x,
739    and substituted into the linker command with %X.  */
740 static int n_linker_options;
741 static char **linker_options;
742
743 /* A vector of options to give to the assembler.
744    These options are accumulated by -Wa,
745    and substituted into the assembler command with %Y.  */
746 static int n_assembler_options;
747 static char **assembler_options;
748
749 /* A vector of options to give to the preprocessor.
750    These options are accumulated by -Wp,
751    and substituted into the preprocessor command with %Z.  */
752 static int n_preprocessor_options;
753 static char **preprocessor_options;
754 \f
755 /* Define how to map long options into short ones.  */
756
757 /* This structure describes one mapping.  */
758 struct option_map
759 {
760   /* The long option's name.  */
761   char *name;
762   /* The equivalent short option.  */
763   char *equivalent;
764   /* Argument info.  A string of flag chars; NULL equals no options.
765      a => argument required.
766      o => argument optional.
767      j => join argument to equivalent, making one word.
768      * => require other text after NAME as an argument.  */
769   char *arg_info;
770 };
771
772 /* This is the table of mappings.  Mappings are tried sequentially
773    for each option encountered; the first one that matches, wins.  */
774
775 struct option_map option_map[] =
776  {
777    {"--all-warnings", "-Wall", 0},
778    {"--ansi", "-ansi", 0},
779    {"--assemble", "-S", 0},
780    {"--assert", "-A", "a"},
781    {"--comments", "-C", 0},
782    {"--compile", "-c", 0},
783    {"--debug", "-g", "oj"},
784    {"--define-macro", "-D", "aj"},
785    {"--dependencies", "-M", 0},
786    {"--dump", "-d", "a"},
787    {"--dumpbase", "-dumpbase", "a"},
788    {"--entry", "-e", 0},
789    {"--extra-warnings", "-W", 0},
790    {"--for-assembler", "-Wa", "a"},
791    {"--for-linker", "-Xlinker", "a"},
792    {"--force-link", "-u", "a"},
793    {"--imacros", "-imacros", "a"},
794    {"--include", "-include", "a"},
795    {"--include-barrier", "-I-", 0},
796    {"--include-directory", "-I", "aj"},
797    {"--include-directory-after", "-idirafter", "a"},
798    {"--include-prefix", "-iprefix", "a"},
799    {"--include-with-prefix", "-iwithprefix", "a"},
800    {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
801    {"--include-with-prefix-after", "-iwithprefix", "a"},
802    {"--language", "-x", "a"},
803    {"--library-directory", "-L", "a"},
804    {"--machine", "-m", "aj"},
805    {"--machine-", "-m", "*j"},
806    {"--no-line-commands", "-P", 0},
807    {"--no-precompiled-includes", "-noprecomp", 0},
808    {"--no-standard-includes", "-nostdinc", 0},
809    {"--no-standard-libraries", "-nostdlib", 0},
810    {"--no-warnings", "-w", 0},
811    {"--optimize", "-O", "oj"},
812    {"--output", "-o", "a"},
813    {"--pedantic", "-pedantic", 0},
814    {"--pedantic-errors", "-pedantic-errors", 0},
815    {"--pipe", "-pipe", 0},
816    {"--prefix", "-B", "a"},
817    {"--preprocess", "-E", 0},
818    {"--print-search-dirs", "-print-search-dirs", 0},
819    {"--print-file-name", "-print-file-name=", "aj"},
820    {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
821    {"--print-missing-file-dependencies", "-MG", 0},
822    {"--print-multi-lib", "-print-multi-lib", 0},
823    {"--print-multi-directory", "-print-multi-directory", 0},
824    {"--print-prog-name", "-print-prog-name=", "aj"},
825    {"--profile", "-p", 0},
826    {"--profile-blocks", "-a", 0},
827    {"--quiet", "-q", 0},
828    {"--save-temps", "-save-temps", 0},
829    {"--shared", "-shared", 0},
830    {"--silent", "-q", 0},
831    {"--specs", "-specs=", "aj"},
832    {"--static", "-static", 0},
833    {"--symbolic", "-symbolic", 0},
834    {"--target", "-b", "a"},
835    {"--trace-includes", "-H", 0},
836    {"--traditional", "-traditional", 0},
837    {"--traditional-cpp", "-traditional-cpp", 0},
838    {"--trigraphs", "-trigraphs", 0},
839    {"--undefine-macro", "-U", "aj"},
840    {"--use-version", "-V", "a"},
841    {"--user-dependencies", "-MM", 0},
842    {"--verbose", "-v", 0},
843    {"--version", "-dumpversion", 0},
844    {"--warn-", "-W", "*j"},
845    {"--write-dependencies", "-MD", 0},
846    {"--write-user-dependencies", "-MMD", 0},
847    {"--", "-f", "*j"}
848  };
849 \f
850 /* Translate the options described by *ARGCP and *ARGVP.
851    Make a new vector and store it back in *ARGVP,
852    and store its length in *ARGVC.  */
853
854 static void
855 translate_options (argcp, argvp)
856      int *argcp;
857      char ***argvp;
858 {
859   int i, j, k;
860   int argc = *argcp;
861   char **argv = *argvp;
862   char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
863   int newindex = 0;
864
865   i = 0;
866   newv[newindex++] = argv[i++];
867
868   while (i < argc)
869     {
870       /* Translate -- options.  */
871       if (argv[i][0] == '-' && argv[i][1] == '-')
872         {
873           /* Find a mapping that applies to this option.  */
874           for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
875             {
876               size_t optlen = strlen (option_map[j].name);
877               size_t arglen = strlen (argv[i]);
878               size_t complen = arglen > optlen ? optlen : arglen;
879               char *arginfo = option_map[j].arg_info;
880
881               if (arginfo == 0)
882                 arginfo = "";
883
884               if (!strncmp (argv[i], option_map[j].name, complen))
885                 {
886                   char *arg = 0;
887
888                   if (arglen < optlen)
889                     {
890                       for (k = j + 1;
891                            k < sizeof (option_map) / sizeof (option_map[0]);
892                            k++)
893                         if (strlen (option_map[k].name) >= arglen
894                             && !strncmp (argv[i], option_map[k].name, arglen))
895                           {
896                             error ("Ambiguous abbreviation %s", argv[i]);
897                             break;
898                           }
899
900                       if (k != sizeof (option_map) / sizeof (option_map[0]))
901                         break;
902                     }
903
904                   if (arglen > optlen)
905                     {
906                       /* If the option has an argument, accept that.  */
907                       if (argv[i][optlen] == '=')
908                         arg = argv[i] + optlen + 1;
909
910                       /* If this mapping requires extra text at end of name,
911                          accept that as "argument".  */
912                       else if (index (arginfo, '*') != 0)
913                         arg = argv[i] + optlen;
914
915                       /* Otherwise, extra text at end means mismatch.
916                          Try other mappings.  */
917                       else
918                         continue;
919                     }
920
921                   else if (index (arginfo, '*') != 0)
922                     {
923                       error ("Incomplete `%s' option", option_map[j].name);
924                       break;
925                     }
926
927                   /* Handle arguments.  */
928                   if (index (arginfo, 'a') != 0)
929                     {
930                       if (arg == 0)
931                         {
932                           if (i + 1 == argc)
933                             {
934                               error ("Missing argument to `%s' option",
935                                      option_map[j].name);
936                               break;
937                             }
938
939                           arg = argv[++i];
940                         }
941                     }
942                   else if (index (arginfo, '*') != 0)
943                     ;
944                   else if (index (arginfo, 'o') == 0)
945                     {
946                       if (arg != 0)
947                         error ("Extraneous argument to `%s' option",
948                                option_map[j].name);
949                       arg = 0;
950                     }
951
952                   /* Store the translation as one argv elt or as two.  */
953                   if (arg != 0 && index (arginfo, 'j') != 0)
954                     newv[newindex++] = concat (option_map[j].equivalent, arg,
955                                                NULL_PTR);
956                   else if (arg != 0)
957                     {
958                       newv[newindex++] = option_map[j].equivalent;
959                       newv[newindex++] = arg;
960                     }
961                   else
962                     newv[newindex++] = option_map[j].equivalent;
963
964                   break;
965                 }
966             }
967           i++;
968         }
969
970       /* Handle old-fashioned options--just copy them through,
971          with their arguments.  */
972       else if (argv[i][0] == '-')
973         {
974           char *p = argv[i] + 1;
975           int c = *p;
976           int nskip = 1;
977
978           if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
979             nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
980           else if (WORD_SWITCH_TAKES_ARG (p))
981             nskip += WORD_SWITCH_TAKES_ARG (p);
982           else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
983                    && p[1] == 0)
984             nskip += 1;
985           else if (! strcmp (p, "Xlinker"))
986             nskip += 1;
987
988           /* Watch out for an option at the end of the command line that
989              is missing arguments, and avoid skipping past the end of the
990              command line.  */
991           if (nskip + i > argc)
992             nskip = argc - i;
993
994           while (nskip > 0)
995             {
996               newv[newindex++] = argv[i++];
997               nskip--;
998             }
999         }
1000       else
1001         /* Ordinary operands, or +e options.  */
1002         newv[newindex++] = argv[i++];
1003     }
1004
1005   newv[newindex] = 0;
1006
1007   *argvp = newv;
1008   *argcp = newindex;
1009 }
1010 \f
1011 char *
1012 my_strerror(e)
1013      int e;
1014 {
1015 #ifdef HAVE_STRERROR
1016
1017   return strerror(e);
1018
1019 #else
1020
1021   static char buffer[30];
1022   if (!e)
1023     return "cannot access";
1024
1025   if (e > 0 && e < sys_nerr)
1026     return sys_errlist[e];
1027
1028   sprintf (buffer, "Unknown error %d", e);
1029   return buffer;
1030 #endif
1031 }
1032 \f
1033 static char *
1034 skip_whitespace (p)
1035      char *p;
1036 {
1037   while (1)
1038     {
1039       /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1040          be considered whitespace.  */
1041       if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1042         return p + 1;
1043       else if (*p == '\n' || *p == ' ' || *p == '\t')
1044         p++;
1045       else if (*p == '#')
1046         {
1047           while (*p != '\n') p++;
1048           p++;
1049         }
1050       else
1051         break;
1052     }
1053
1054   return p;
1055 }
1056 \f
1057 /* Structure to keep track of the specs that have been defined so far.
1058    These are accessed using %(specname) or %[specname] in a compiler
1059    or link spec.  */
1060
1061 struct spec_list
1062 {
1063                                 /* The following 2 fields must be first */
1064                                 /* to allow EXTRA_SPECS to be initialized */
1065   char *name;                   /* name of the spec.  */
1066   char *ptr;                    /* available ptr if no static pointer */
1067
1068                                 /* The following fields are not initialized */
1069                                 /* by EXTRA_SPECS */
1070   char **ptr_spec;              /* pointer to the spec itself.  */
1071   struct spec_list *next;       /* Next spec in linked list.  */
1072   int name_len;                 /* length of the name */
1073   int alloc_p;                  /* whether string was allocated */
1074 };
1075
1076 #define INIT_STATIC_SPEC(NAME,PTR) \
1077 { NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 }
1078
1079 /* List of statically defined specs */
1080 static struct spec_list static_specs[] = {
1081   INIT_STATIC_SPEC ("asm",                      &asm_spec),
1082   INIT_STATIC_SPEC ("asm_final",                &asm_final_spec),
1083   INIT_STATIC_SPEC ("cpp",                      &cpp_spec),
1084   INIT_STATIC_SPEC ("cc1",                      &cc1_spec),
1085   INIT_STATIC_SPEC ("cc1plus",                  &cc1plus_spec),
1086   INIT_STATIC_SPEC ("endfile",                  &endfile_spec),
1087   INIT_STATIC_SPEC ("link",                     &link_spec),
1088   INIT_STATIC_SPEC ("lib",                      &lib_spec),
1089   INIT_STATIC_SPEC ("libgcc",                   &libgcc_spec),
1090   INIT_STATIC_SPEC ("startfile",                &startfile_spec),
1091   INIT_STATIC_SPEC ("switches_need_spaces",     &switches_need_spaces),
1092   INIT_STATIC_SPEC ("signed_char",              &signed_char_spec),
1093   INIT_STATIC_SPEC ("predefines",               &cpp_predefines),
1094   INIT_STATIC_SPEC ("cross_compile",            &cross_compile),
1095   INIT_STATIC_SPEC ("version",                  &compiler_version),
1096   INIT_STATIC_SPEC ("multilib",                 &multilib_select),
1097   INIT_STATIC_SPEC ("multilib_defaults",        &multilib_defaults),
1098   INIT_STATIC_SPEC ("multilib_extra",           &multilib_extra),
1099   INIT_STATIC_SPEC ("multilib_matches",         &multilib_matches),
1100   INIT_STATIC_SPEC ("linker",                   &linker_name_spec),
1101 };
1102
1103 #ifdef EXTRA_SPECS              /* additional specs needed */
1104 static struct spec_list extra_specs[] = { EXTRA_SPECS };
1105 #endif
1106
1107 /* List of dynamically allocates specs that have been defined so far.  */
1108
1109 static struct spec_list *specs = (struct spec_list *)0;
1110
1111 \f
1112 /* Initialize the specs lookup routines.  */
1113
1114 static void
1115 init_spec ()
1116 {
1117   struct spec_list *next = (struct spec_list *)0;
1118   struct spec_list *sl   = (struct spec_list *)0;
1119   int i;
1120
1121   if (specs)
1122     return;                     /* already initialized */
1123
1124   if (verbose_flag)
1125     fprintf (stderr, "Using builtin specs.\n");
1126
1127 #ifdef EXTRA_SPECS
1128   for (i = (sizeof (extra_specs) / sizeof (extra_specs[0])) - 1; i >= 0; i--)
1129     {
1130       sl = &extra_specs[i];
1131       sl->next = next;
1132       sl->name_len = strlen (sl->name);
1133       sl->ptr_spec = &sl->ptr;
1134       next = sl;
1135     }
1136 #endif
1137
1138   for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--)
1139     {
1140       sl = &static_specs[i];
1141       sl->next = next;
1142       next = sl;
1143     }
1144
1145   specs = sl;
1146 }
1147
1148 \f
1149 /* Change the value of spec NAME to SPEC.  If SPEC is empty, then the spec is
1150    removed; If the spec starts with a + then SPEC is added to the end of the
1151    current spec.  */
1152
1153 static void
1154 set_spec (name, spec)
1155      char *name;
1156      char *spec;
1157 {
1158   struct spec_list *sl;
1159   char *old_spec;
1160   int name_len = strlen (name);
1161   int i;
1162
1163   /* If this is the first call, initialize the statically allocated specs */
1164   if (!specs)
1165     {
1166       struct spec_list *next = (struct spec_list *)0;
1167       for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1;
1168            i >= 0; i--)
1169         {
1170           sl = &static_specs[i];
1171           sl->next = next;
1172           next = sl;
1173         }
1174       specs = sl;
1175     }
1176
1177   /* See if the spec already exists */
1178   for (sl = specs; sl; sl = sl->next)
1179     if (name_len == sl->name_len && !strcmp (sl->name, name))
1180       break;
1181
1182   if (!sl)
1183     {
1184       /* Not found - make it */
1185       sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1186       sl->name = save_string (name, strlen (name));
1187       sl->name_len = name_len;
1188       sl->ptr_spec = &sl->ptr;
1189       sl->alloc_p = 0;
1190       *(sl->ptr_spec) = "";
1191       sl->next = specs;
1192       specs = sl;
1193     }
1194
1195   old_spec = *(sl->ptr_spec);
1196   *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE (spec[1]))
1197                      ? concat (old_spec, spec + 1, NULL_PTR)
1198                      : save_string (spec, strlen (spec)));
1199
1200 #ifdef DEBUG_SPECS
1201   if (verbose_flag)
1202     fprintf (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1203 #endif
1204
1205   /* Free the old spec */
1206   if (old_spec && sl->alloc_p)
1207     free (old_spec);
1208
1209   sl->alloc_p = 1;
1210 }
1211 \f
1212 /* Accumulate a command (program name and args), and run it.  */
1213
1214 /* Vector of pointers to arguments in the current line of specifications.  */
1215
1216 static char **argbuf;
1217
1218 /* Number of elements allocated in argbuf.  */
1219
1220 static int argbuf_length;
1221
1222 /* Number of elements in argbuf currently in use (containing args).  */
1223
1224 static int argbuf_index;
1225
1226 #ifdef MKTEMP_EACH_FILE
1227 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1228    temp file.  */
1229
1230 static struct temp_name {
1231   char *suffix;         /* suffix associated with the code.  */
1232   int length;           /* strlen (suffix).  */
1233   int unique;           /* Indicates whether %g or %u/%U was used.  */
1234   char *filename;       /* associated filename.  */
1235   int filename_length;  /* strlen (filename).  */
1236   struct temp_name *next;
1237 } *temp_names;
1238 #endif
1239
1240 /* Number of commands executed so far.  */
1241
1242 static int execution_count;
1243
1244 /* Number of commands that exited with a signal.  */
1245
1246 static int signal_count;
1247
1248 /* Name with which this program was invoked.  */
1249
1250 static char *programname;
1251 \f
1252 /* Structures to keep track of prefixes to try when looking for files.  */
1253
1254 struct prefix_list
1255 {
1256   char *prefix;               /* String to prepend to the path.  */
1257   struct prefix_list *next;   /* Next in linked list.  */
1258   int require_machine_suffix; /* Don't use without machine_suffix.  */
1259   /* 2 means try both machine_suffix and just_machine_suffix.  */
1260   int *used_flag_ptr;         /* 1 if a file was found with this prefix.  */
1261 };
1262
1263 struct path_prefix
1264 {
1265   struct prefix_list *plist;  /* List of prefixes to try */
1266   int max_len;                /* Max length of a prefix in PLIST */
1267   char *name;                 /* Name of this list (used in config stuff) */
1268 };
1269
1270 /* List of prefixes to try when looking for executables.  */
1271
1272 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1273
1274 /* List of prefixes to try when looking for startup (crt0) files.  */
1275
1276 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1277
1278 /* List of prefixes to try when looking for include files.  */
1279
1280 static struct path_prefix include_prefixes = { 0, 0, "include" };
1281
1282 /* Suffix to attach to directories searched for commands.
1283    This looks like `MACHINE/VERSION/'.  */
1284
1285 static char *machine_suffix = 0;
1286
1287 /* Suffix to attach to directories searched for commands.
1288    This is just `MACHINE/'.  */
1289
1290 static char *just_machine_suffix = 0;
1291
1292 /* Adjusted value of GCC_EXEC_PREFIX envvar.  */
1293
1294 static char *gcc_exec_prefix;
1295
1296 /* Default prefixes to attach to command names.  */
1297
1298 #ifdef CROSS_COMPILE  /* Don't use these prefixes for a cross compiler.  */
1299 #undef MD_EXEC_PREFIX
1300 #undef MD_STARTFILE_PREFIX
1301 #undef MD_STARTFILE_PREFIX_1
1302 #endif
1303
1304 #ifndef STANDARD_EXEC_PREFIX
1305 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1306 #endif /* !defined STANDARD_EXEC_PREFIX */
1307
1308 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1309 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1310 #ifdef MD_EXEC_PREFIX
1311 static char *md_exec_prefix = MD_EXEC_PREFIX;
1312 #endif
1313
1314 #ifndef STANDARD_STARTFILE_PREFIX
1315 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1316 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1317
1318 #ifdef MD_STARTFILE_PREFIX
1319 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1320 #endif
1321 #ifdef MD_STARTFILE_PREFIX_1
1322 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1323 #endif
1324 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1325 static char *standard_startfile_prefix_1 = "/lib/";
1326 static char *standard_startfile_prefix_2 = "/usr/lib/";
1327
1328 #ifndef TOOLDIR_BASE_PREFIX
1329 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1330 #endif
1331 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1332 static char *tooldir_prefix;
1333
1334 /* Subdirectory to use for locating libraries.  Set by
1335    set_multilib_dir based on the compilation options.  */
1336
1337 static char *multilib_dir;
1338
1339 /* Clear out the vector of arguments (after a command is executed).  */
1340
1341 static void
1342 clear_args ()
1343 {
1344   argbuf_index = 0;
1345 }
1346
1347 /* Add one argument to the vector at the end.
1348    This is done when a space is seen or at the end of the line.
1349    If DELETE_ALWAYS is nonzero, the arg is a filename
1350     and the file should be deleted eventually.
1351    If DELETE_FAILURE is nonzero, the arg is a filename
1352     and the file should be deleted if this compilation fails.  */
1353
1354 static void
1355 store_arg (arg, delete_always, delete_failure)
1356      char *arg;
1357      int delete_always, delete_failure;
1358 {
1359   if (argbuf_index + 1 == argbuf_length)
1360     argbuf
1361       = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1362
1363   argbuf[argbuf_index++] = arg;
1364   argbuf[argbuf_index] = 0;
1365
1366   if (delete_always || delete_failure)
1367     record_temp_file (arg, delete_always, delete_failure);
1368 }
1369 \f
1370 /* Read compilation specs from a file named FILENAME,
1371    replacing the default ones.
1372
1373    A suffix which starts with `*' is a definition for
1374    one of the machine-specific sub-specs.  The "suffix" should be
1375    *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1376    The corresponding spec is stored in asm_spec, etc.,
1377    rather than in the `compilers' vector.
1378
1379    Anything invalid in the file is a fatal error.  */
1380
1381 static void
1382 read_specs (filename, main_p)
1383      char *filename;
1384      int main_p;
1385 {
1386   int desc;
1387   int readlen;
1388   struct stat statbuf;
1389   char *buffer;
1390   register char *p;
1391
1392   if (verbose_flag)
1393     fprintf (stderr, "Reading specs from %s\n", filename);
1394
1395   /* Open and stat the file.  */
1396   desc = open (filename, O_RDONLY, 0);
1397   if (desc < 0)
1398     pfatal_with_name (filename);
1399   if (stat (filename, &statbuf) < 0)
1400     pfatal_with_name (filename);
1401
1402   /* Read contents of file into BUFFER.  */
1403   buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1404   readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1405   if (readlen < 0)
1406     pfatal_with_name (filename);
1407   buffer[readlen] = 0;
1408   close (desc);
1409
1410   /* Scan BUFFER for specs, putting them in the vector.  */
1411   p = buffer;
1412   while (1)
1413     {
1414       char *suffix;
1415       char *spec;
1416       char *in, *out, *p1, *p2, *p3;
1417
1418       /* Advance P in BUFFER to the next nonblank nocomment line.  */
1419       p = skip_whitespace (p);
1420       if (*p == 0)
1421         break;
1422
1423       /* Is this a special command that starts with '%'? */
1424       /* Don't allow this for the main specs file, since it would
1425          encourage people to overwrite it.  */
1426       if (*p == '%' && !main_p)
1427         {
1428           p1 = p;
1429           while (*p && *p != '\n')
1430             p++;
1431
1432           p++;                  /* Skip '\n' */
1433
1434           if (!strncmp (p1, "%include", sizeof ("%include")-1)
1435               && (p1[sizeof "%include" - 1] == ' '
1436                   || p1[sizeof "%include" - 1] == '\t'))
1437             {
1438               char *new_filename;
1439
1440               p1 += sizeof ("%include");
1441               while (*p1 == ' ' || *p1 == '\t')
1442                 p1++;
1443
1444               if (*p1++ != '<' || p[-2] != '>')
1445                 fatal ("specs %%include syntax malformed after %d characters",
1446                        p1 - buffer + 1);
1447
1448               p[-2] = '\0';
1449               new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1450               read_specs (new_filename ? new_filename : p1, FALSE);
1451               continue;
1452             }
1453           else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1454                    && (p1[sizeof "%include_noerr" - 1] == ' '
1455                        || p1[sizeof "%include_noerr" - 1] == '\t'))
1456             {
1457               char *new_filename;
1458
1459               p1 += sizeof "%include_noerr";
1460               while (*p1 == ' ' || *p1 == '\t') p1++;
1461
1462               if (*p1++ != '<' || p[-2] != '>')
1463                 fatal ("specs %%include syntax malformed after %d characters",
1464                        p1 - buffer + 1);
1465
1466               p[-2] = '\0';
1467               new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1468               if (new_filename)
1469                 read_specs (new_filename, FALSE);
1470               else if (verbose_flag)
1471                 fprintf (stderr, "Could not find specs file %s\n", p1);
1472               continue;
1473             }
1474           else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1475                    && (p1[sizeof "%rename" - 1] == ' '
1476                        || p1[sizeof "%rename" - 1] == '\t'))
1477             {
1478               int name_len;
1479               struct spec_list *sl;
1480
1481               /* Get original name */
1482               p1 += sizeof "%rename";
1483               while (*p1 == ' ' || *p1 == '\t')
1484                 p1++;
1485
1486               if (! ISALPHA (*p1))
1487                 fatal ("specs %%rename syntax malformed after %d characters",
1488                        p1 - buffer);
1489
1490               p2 = p1;
1491               while (*p2 && !ISSPACE (*p2))
1492                 p2++;
1493
1494               if (*p2 != ' ' && *p2 != '\t')
1495                 fatal ("specs %%rename syntax malformed after %d characters",
1496                        p2 - buffer);
1497
1498               name_len = p2 - p1;
1499               *p2++ = '\0';
1500               while (*p2 == ' ' || *p2 == '\t')
1501                 p2++;
1502
1503               if (! ISALPHA (*p2))
1504                 fatal ("specs %%rename syntax malformed after %d characters",
1505                        p2 - buffer);
1506
1507               /* Get new spec name */
1508               p3 = p2;
1509               while (*p3 && !ISSPACE (*p3))
1510                 p3++;
1511
1512               if (p3 != p-1)
1513                 fatal ("specs %%rename syntax malformed after %d characters",
1514                        p3 - buffer);
1515               *p3 = '\0';
1516
1517               for (sl = specs; sl; sl = sl->next)
1518                 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1519                   break;
1520
1521               if (!sl)
1522                 fatal ("specs %s spec was not found to be renamed", p1);
1523
1524               if (strcmp (p1, p2) == 0)
1525                 continue;
1526
1527               if (verbose_flag)
1528                 {
1529                   fprintf (stderr, "rename spec %s to %s\n", p1, p2);
1530 #ifdef DEBUG_SPECS
1531                   fprintf (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
1532 #endif
1533                 }
1534
1535               set_spec (p2, *(sl->ptr_spec));
1536               if (sl->alloc_p)
1537                 free (*(sl->ptr_spec));
1538
1539               *(sl->ptr_spec) = "";
1540               sl->alloc_p = 0;
1541               continue;
1542             }
1543           else
1544             fatal ("specs unknown %% command after %d characters",
1545                    p1 - buffer);
1546         }
1547
1548       /* Find the colon that should end the suffix.  */
1549       p1 = p;
1550       while (*p1 && *p1 != ':' && *p1 != '\n')
1551         p1++;
1552
1553       /* The colon shouldn't be missing.  */
1554       if (*p1 != ':')
1555         fatal ("specs file malformed after %d characters", p1 - buffer);
1556
1557       /* Skip back over trailing whitespace.  */
1558       p2 = p1;
1559       while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1560         p2--;
1561
1562       /* Copy the suffix to a string.  */
1563       suffix = save_string (p, p2 - p);
1564       /* Find the next line.  */
1565       p = skip_whitespace (p1 + 1);
1566       if (p[1] == 0)
1567         fatal ("specs file malformed after %d characters", p - buffer);
1568
1569       p1 = p;
1570       /* Find next blank line.  */
1571       while (*p1 && !(*p1 == '\n' && p1[1] == '\n'))
1572         p1++;
1573
1574       /* Specs end at the blank line and do not include the newline.  */
1575       spec = save_string (p, p1 - p);
1576       p = p1;
1577
1578       /* Delete backslash-newline sequences from the spec.  */
1579       in = spec;
1580       out = spec;
1581       while (*in != 0)
1582         {
1583           if (in[0] == '\\' && in[1] == '\n')
1584             in += 2;
1585           else if (in[0] == '#')
1586             while (*in && *in != '\n')
1587               in++;
1588
1589           else
1590             *out++ = *in++;
1591         }
1592       *out = 0;
1593
1594       if (suffix[0] == '*')
1595         {
1596           if (! strcmp (suffix, "*link_command"))
1597             link_command_spec = spec;
1598           else
1599             set_spec (suffix + 1, spec);
1600         }
1601       else
1602         {
1603           /* Add this pair to the vector.  */
1604           compilers
1605             = ((struct compiler *)
1606                xrealloc (compilers,
1607                          (n_compilers + 2) * sizeof (struct compiler)));
1608
1609           compilers[n_compilers].suffix = suffix;
1610           bzero ((char *) compilers[n_compilers].spec,
1611                  sizeof compilers[n_compilers].spec);
1612           compilers[n_compilers].spec[0] = spec;
1613           n_compilers++;
1614           bzero ((char *) &compilers[n_compilers],
1615                  sizeof compilers[n_compilers]);
1616         }
1617
1618       if (*suffix == 0)
1619         link_command_spec = spec;
1620     }
1621
1622   if (link_command_spec == 0)
1623     fatal ("spec file has no spec for linking");
1624 }
1625 \f
1626 /* Record the names of temporary files we tell compilers to write,
1627    and delete them at the end of the run.  */
1628
1629 /* This is the common prefix we use to make temp file names.
1630    It is chosen once for each run of this program.
1631    It is substituted into a spec by %g.
1632    Thus, all temp file names contain this prefix.
1633    In practice, all temp file names start with this prefix.
1634
1635    This prefix comes from the envvar TMPDIR if it is defined;
1636    otherwise, from the P_tmpdir macro if that is defined;
1637    otherwise, in /usr/tmp or /tmp;
1638    or finally the current directory if all else fails.  */
1639
1640 static char *temp_filename;
1641
1642 /* Length of the prefix.  */
1643
1644 static int temp_filename_length;
1645
1646 /* Define the list of temporary files to delete.  */
1647
1648 struct temp_file
1649 {
1650   char *name;
1651   struct temp_file *next;
1652 };
1653
1654 /* Queue of files to delete on success or failure of compilation.  */
1655 static struct temp_file *always_delete_queue;
1656 /* Queue of files to delete on failure of compilation.  */
1657 static struct temp_file *failure_delete_queue;
1658
1659 /* Record FILENAME as a file to be deleted automatically.
1660    ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1661    otherwise delete it in any case.
1662    FAIL_DELETE nonzero means delete it if a compilation step fails;
1663    otherwise delete it in any case.  */
1664
1665 static void
1666 record_temp_file (filename, always_delete, fail_delete)
1667      char *filename;
1668      int always_delete;
1669      int fail_delete;
1670 {
1671   register char *name;
1672   name = xmalloc (strlen (filename) + 1);
1673   strcpy (name, filename);
1674
1675   if (always_delete)
1676     {
1677       register struct temp_file *temp;
1678       for (temp = always_delete_queue; temp; temp = temp->next)
1679         if (! strcmp (name, temp->name))
1680           goto already1;
1681
1682       temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1683       temp->next = always_delete_queue;
1684       temp->name = name;
1685       always_delete_queue = temp;
1686
1687     already1:;
1688     }
1689
1690   if (fail_delete)
1691     {
1692       register struct temp_file *temp;
1693       for (temp = failure_delete_queue; temp; temp = temp->next)
1694         if (! strcmp (name, temp->name))
1695           goto already2;
1696
1697       temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1698       temp->next = failure_delete_queue;
1699       temp->name = name;
1700       failure_delete_queue = temp;
1701
1702     already2:;
1703     }
1704 }
1705
1706 /* Delete all the temporary files whose names we previously recorded.  */
1707
1708 static void
1709 delete_if_ordinary (name)
1710      char *name;
1711 {
1712   struct stat st;
1713 #ifdef DEBUG
1714   int i, c;
1715
1716   printf ("Delete %s? (y or n) ", name);
1717   fflush (stdout);
1718   i = getchar ();
1719   if (i != '\n')
1720     while ((c = getchar ()) != '\n' && c != EOF)
1721       ;
1722
1723   if (i == 'y' || i == 'Y')
1724 #endif /* DEBUG */
1725     if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1726       if (unlink (name) < 0)
1727         if (verbose_flag)
1728           perror_with_name (name);
1729 }
1730
1731 static void
1732 delete_temp_files ()
1733 {
1734   register struct temp_file *temp;
1735
1736   for (temp = always_delete_queue; temp; temp = temp->next)
1737     delete_if_ordinary (temp->name);
1738   always_delete_queue = 0;
1739 }
1740
1741 /* Delete all the files to be deleted on error.  */
1742
1743 static void
1744 delete_failure_queue ()
1745 {
1746   register struct temp_file *temp;
1747
1748   for (temp = failure_delete_queue; temp; temp = temp->next)
1749     delete_if_ordinary (temp->name);
1750 }
1751
1752 static void
1753 clear_failure_queue ()
1754 {
1755   failure_delete_queue = 0;
1756 }
1757 \f
1758 /* Routine to add variables to the environment.  We do this to pass
1759    the pathname of the gcc driver, and the directories search to the
1760    collect2 program, which is being run as ld.  This way, we can be
1761    sure of executing the right compiler when collect2 wants to build
1762    constructors and destructors.  Since the environment variables we
1763    use come from an obstack, we don't have to worry about allocating
1764    space for them.  */
1765
1766 #ifndef HAVE_PUTENV
1767
1768 void
1769 putenv (str)
1770      char *str;
1771 {
1772 #ifndef VMS                     /* nor about VMS */
1773
1774   extern char **environ;
1775   char **old_environ = environ;
1776   char **envp;
1777   int num_envs = 0;
1778   int name_len = 1;
1779   int str_len = strlen (str);
1780   char *p = str;
1781   int ch;
1782
1783   while ((ch = *p++) != '\0' && ch != '=')
1784     name_len++;
1785
1786   if (!ch)
1787     abort ();
1788
1789   /* Search for replacing an existing environment variable, and
1790      count the number of total environment variables.  */
1791   for (envp = old_environ; *envp; envp++)
1792     {
1793       num_envs++;
1794       if (!strncmp (str, *envp, name_len))
1795         {
1796           *envp = str;
1797           return;
1798         }
1799     }
1800
1801   /* Add a new environment variable */
1802   environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1803   *environ = str;
1804   bcopy ((char *) old_environ, (char *) (environ + 1),
1805          sizeof (char *) * (num_envs+1));
1806
1807 #endif  /* VMS */
1808 }
1809
1810 #endif  /* HAVE_PUTENV */
1811
1812 \f
1813 /* Build a list of search directories from PATHS.
1814    PREFIX is a string to prepend to the list.
1815    If CHECK_DIR_P is non-zero we ensure the directory exists.
1816    This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1817    It is also used by the --print-search-dirs flag.  */
1818
1819 static char *
1820 build_search_list (paths, prefix, check_dir_p)
1821      struct path_prefix *paths;
1822      char *prefix;
1823      int check_dir_p;
1824 {
1825   int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1826   int just_suffix_len
1827     = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1828   int first_time = TRUE;
1829   struct prefix_list *pprefix;
1830
1831   obstack_grow (&collect_obstack, prefix, strlen (prefix));
1832
1833   for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1834     {
1835       int len = strlen (pprefix->prefix);
1836
1837       if (machine_suffix
1838           && (! check_dir_p
1839               || is_directory (pprefix->prefix, machine_suffix, 0)))
1840         {
1841           if (!first_time)
1842             obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1843             
1844           first_time = FALSE;
1845           obstack_grow (&collect_obstack, pprefix->prefix, len);
1846           obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1847         }
1848
1849       if (just_machine_suffix
1850           && pprefix->require_machine_suffix == 2
1851           && (! check_dir_p
1852               || is_directory (pprefix->prefix, just_machine_suffix, 0)))
1853         {
1854           if (! first_time)
1855             obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1856             
1857           first_time = FALSE;
1858           obstack_grow (&collect_obstack, pprefix->prefix, len);
1859           obstack_grow (&collect_obstack, just_machine_suffix,
1860                         just_suffix_len);
1861         }
1862
1863       if (! pprefix->require_machine_suffix)
1864         {
1865           if (! first_time)
1866             obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1867
1868           first_time = FALSE;
1869           obstack_grow (&collect_obstack, pprefix->prefix, len);
1870         }
1871     }
1872
1873   obstack_1grow (&collect_obstack, '\0');
1874   return obstack_finish (&collect_obstack);
1875 }
1876
1877 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
1878    for collect.  */
1879
1880 static void
1881 putenv_from_prefixes (paths, env_var)
1882      struct path_prefix *paths;
1883      char *env_var;
1884 {
1885   putenv (build_search_list (paths, env_var, 1));
1886 }
1887 \f
1888 /* Search for NAME using the prefix list PREFIXES.  MODE is passed to
1889    access to check permissions.
1890    Return 0 if not found, otherwise return its name, allocated with malloc.  */
1891
1892 static char *
1893 find_a_file (pprefix, name, mode)
1894      struct path_prefix *pprefix;
1895      char *name;
1896      int mode;
1897 {
1898   char *temp;
1899   char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1900   struct prefix_list *pl;
1901   int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1902
1903   if (machine_suffix)
1904     len += strlen (machine_suffix);
1905
1906   temp = xmalloc (len);
1907
1908   /* Determine the filename to execute (special case for absolute paths).  */
1909
1910   if (*name == '/' || *name == DIR_SEPARATOR
1911       /* Check for disk name on MS-DOS-based systems.  */
1912       || (DIR_SEPARATOR == '\\' && name[1] == ':'
1913           && (name[2] == DIR_SEPARATOR || name[2] == '/')))
1914     {
1915       if (access (name, mode))
1916         {
1917           strcpy (temp, name);
1918           return temp;
1919         }
1920     }
1921   else
1922     for (pl = pprefix->plist; pl; pl = pl->next)
1923       {
1924         if (machine_suffix)
1925           {
1926             /* Some systems have a suffix for executable files.
1927                So try appending that first.  */
1928             if (file_suffix[0] != 0)
1929               {
1930                 strcpy (temp, pl->prefix);
1931                 strcat (temp, machine_suffix);
1932                 strcat (temp, name);
1933                 strcat (temp, file_suffix);
1934                 if (access (temp, mode) == 0)
1935                   {
1936                     if (pl->used_flag_ptr != 0)
1937                       *pl->used_flag_ptr = 1;
1938                     return temp;
1939                   }
1940               }
1941
1942             /* Now try just the name.  */
1943             strcpy (temp, pl->prefix);
1944             strcat (temp, machine_suffix);
1945             strcat (temp, name);
1946             if (access (temp, mode) == 0)
1947               {
1948                 if (pl->used_flag_ptr != 0)
1949                   *pl->used_flag_ptr = 1;
1950                 return temp;
1951               }
1952           }
1953
1954         /* Certain prefixes are tried with just the machine type,
1955            not the version.  This is used for finding as, ld, etc.  */
1956         if (just_machine_suffix && pl->require_machine_suffix == 2)
1957           {
1958             /* Some systems have a suffix for executable files.
1959                So try appending that first.  */
1960             if (file_suffix[0] != 0)
1961               {
1962                 strcpy (temp, pl->prefix);
1963                 strcat (temp, just_machine_suffix);
1964                 strcat (temp, name);
1965                 strcat (temp, file_suffix);
1966                 if (access (temp, mode) == 0)
1967                   {
1968                     if (pl->used_flag_ptr != 0)
1969                       *pl->used_flag_ptr = 1;
1970                     return temp;
1971                   }
1972               }
1973
1974             strcpy (temp, pl->prefix);
1975             strcat (temp, just_machine_suffix);
1976             strcat (temp, name);
1977             if (access (temp, mode) == 0)
1978               {
1979                 if (pl->used_flag_ptr != 0)
1980                   *pl->used_flag_ptr = 1;
1981                 return temp;
1982               }
1983           }
1984
1985         /* Certain prefixes can't be used without the machine suffix
1986            when the machine or version is explicitly specified.  */
1987         if (! pl->require_machine_suffix)
1988           {
1989             /* Some systems have a suffix for executable files.
1990                So try appending that first.  */
1991             if (file_suffix[0] != 0)
1992               {
1993                 strcpy (temp, pl->prefix);
1994                 strcat (temp, name);
1995                 strcat (temp, file_suffix);
1996                 if (access (temp, mode) == 0)
1997                   {
1998                     if (pl->used_flag_ptr != 0)
1999                       *pl->used_flag_ptr = 1;
2000                     return temp;
2001                   }
2002               }
2003
2004             strcpy (temp, pl->prefix);
2005             strcat (temp, name);
2006             if (access (temp, mode) == 0)
2007               {
2008                 if (pl->used_flag_ptr != 0)
2009                   *pl->used_flag_ptr = 1;
2010                 return temp;
2011               }
2012           }
2013       }
2014
2015   free (temp);
2016   return 0;
2017 }
2018
2019 /* Add an entry for PREFIX in PLIST.  If FIRST is set, it goes
2020    at the start of the list, otherwise it goes at the end.
2021
2022    If WARN is nonzero, we will warn if no file is found
2023    through this prefix.  WARN should point to an int
2024    which will be set to 1 if this entry is used.
2025
2026    COMPONENT is the value to be passed to update_path.
2027
2028    REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2029    the complete value of machine_suffix.
2030    2 means try both machine_suffix and just_machine_suffix.  */
2031
2032 static void
2033 add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn)
2034      struct path_prefix *pprefix;
2035      char *prefix;
2036      char *component;
2037      int first;
2038      int require_machine_suffix;
2039      int *warn;
2040 {
2041   struct prefix_list *pl, **prev;
2042   int len;
2043
2044   if (! first && pprefix->plist)
2045     {
2046       for (pl = pprefix->plist; pl->next; pl = pl->next)
2047         ;
2048       prev = &pl->next;
2049     }
2050   else
2051     prev = &pprefix->plist;
2052
2053   /* Keep track of the longest prefix */
2054
2055   prefix = update_path (prefix, component);
2056   len = strlen (prefix);
2057   if (len > pprefix->max_len)
2058     pprefix->max_len = len;
2059
2060   pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2061   pl->prefix = save_string (prefix, len);
2062   pl->require_machine_suffix = require_machine_suffix;
2063   pl->used_flag_ptr = warn;
2064   if (warn)
2065     *warn = 0;
2066
2067   if (*prev)
2068     pl->next = *prev;
2069   else
2070     pl->next = (struct prefix_list *) 0;
2071   *prev = pl;
2072 }
2073
2074 /* Print warnings for any prefixes in the list PPREFIX that were not used.  */
2075
2076 static void
2077 unused_prefix_warnings (pprefix)
2078      struct path_prefix *pprefix;
2079 {
2080   struct prefix_list *pl = pprefix->plist;
2081
2082   while (pl)
2083     {
2084       if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
2085         {
2086           if (pl->require_machine_suffix && machine_suffix)
2087             error ("file path prefix `%s%s' never used", pl->prefix,
2088                    machine_suffix);
2089           else
2090             error ("file path prefix `%s' never used", pl->prefix);
2091
2092           /* Prevent duplicate warnings.  */
2093           *pl->used_flag_ptr = 1;
2094         }
2095
2096       pl = pl->next;
2097     }
2098 }
2099
2100 \f
2101 /* Execute the command specified by the arguments on the current line of spec.
2102    When using pipes, this includes several piped-together commands
2103    with `|' between them.
2104
2105    Return 0 if successful, -1 if failed.  */
2106
2107 static int
2108 execute ()
2109 {
2110   int i;
2111   int n_commands;               /* # of command.  */
2112   char *string;
2113   struct command
2114     {
2115       char *prog;               /* program name.  */
2116       char **argv;              /* vector of args.  */
2117       int pid;                  /* pid of process for this command.  */
2118     };
2119
2120   struct command *commands;     /* each command buffer with above info.  */
2121
2122   /* Count # of piped commands.  */
2123   for (n_commands = 1, i = 0; i < argbuf_index; i++)
2124     if (strcmp (argbuf[i], "|") == 0)
2125       n_commands++;
2126
2127   /* Get storage for each command.  */
2128   commands
2129     = (struct command *) alloca (n_commands * sizeof (struct command));
2130
2131   /* Split argbuf into its separate piped processes,
2132      and record info about each one.
2133      Also search for the programs that are to be run.  */
2134
2135   commands[0].prog = argbuf[0]; /* first command.  */
2136   commands[0].argv = &argbuf[0];
2137   string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2138
2139   if (string)
2140     commands[0].argv[0] = string;
2141
2142   for (n_commands = 1, i = 0; i < argbuf_index; i++)
2143     if (strcmp (argbuf[i], "|") == 0)
2144       {                         /* each command.  */
2145 #if defined (__MSDOS__) || (defined (_WIN32) && defined (__CYGWIN32_)) || defined (OS2) || defined (VMS)
2146         fatal ("-pipe not supported");
2147 #endif
2148         argbuf[i] = 0;  /* termination of command args.  */
2149         commands[n_commands].prog = argbuf[i + 1];
2150         commands[n_commands].argv = &argbuf[i + 1];
2151         string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2152         if (string)
2153           commands[n_commands].argv[0] = string;
2154         n_commands++;
2155       }
2156
2157   argbuf[argbuf_index] = 0;
2158
2159   /* If -v, print what we are about to do, and maybe query.  */
2160
2161   if (verbose_flag)
2162     {
2163       /* Print each piped command as a separate line.  */
2164       for (i = 0; i < n_commands ; i++)
2165         {
2166           char **j;
2167
2168           for (j = commands[i].argv; *j; j++)
2169             fprintf (stderr, " %s", *j);
2170
2171           /* Print a pipe symbol after all but the last command.  */
2172           if (i + 1 != n_commands)
2173             fprintf (stderr, " |");
2174           fprintf (stderr, "\n");
2175         }
2176       fflush (stderr);
2177 #ifdef DEBUG
2178       fprintf (stderr, "\nGo ahead? (y or n) ");
2179       fflush (stderr);
2180       i = getchar ();
2181       if (i != '\n')
2182         while (getchar () != '\n')
2183           ;
2184
2185       if (i != 'y' && i != 'Y')
2186         return 0;
2187 #endif /* DEBUG */
2188     }
2189
2190   /* Run each piped subprocess.  */
2191
2192   for (i = 0; i < n_commands; i++)
2193     {
2194       char *errmsg_fmt, *errmsg_arg;
2195       char *string = commands[i].argv[0];
2196
2197       commands[i].pid = pexecute (string, commands[i].argv,
2198                                   programname, temp_filename,
2199                                   &errmsg_fmt, &errmsg_arg,
2200                                   ((i == 0 ? PEXECUTE_FIRST : 0)
2201                                    | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2202                                    | (string == commands[i].prog
2203                                       ? PEXECUTE_SEARCH : 0)
2204                                    | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2205
2206       if (commands[i].pid == -1)
2207         pfatal_pexecute (errmsg_fmt, errmsg_arg);
2208
2209       if (string != commands[i].prog)
2210         free (string);
2211     }
2212
2213   execution_count++;
2214
2215   /* Wait for all the subprocesses to finish.
2216      We don't care what order they finish in;
2217      we know that N_COMMANDS waits will get them all.
2218      Ignore subprocesses that we don't know about,
2219      since they can be spawned by the process that exec'ed us.  */
2220
2221   {
2222     int ret_code = 0;
2223
2224     for (i = 0; i < n_commands; )
2225       {
2226         int j;
2227         int status;
2228         int pid;
2229
2230         pid = pwait (commands[i].pid, &status, 0);
2231         if (pid < 0)
2232           abort ();
2233
2234         for (j = 0; j < n_commands; j++)
2235           if (commands[j].pid == pid)
2236             {
2237               i++;
2238               if (status != 0)
2239                 {
2240                   if (WIFSIGNALED (status))
2241                     {
2242                       fatal ("Internal compiler error: program %s got fatal signal %d",
2243                              commands[j].prog, WTERMSIG (status));
2244                       signal_count++;
2245                       ret_code = -1;
2246                     }
2247                   else if (WIFEXITED (status)
2248                            && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2249                     ret_code = -1;
2250                 }
2251               break;
2252             }
2253       }
2254     return ret_code;
2255   }
2256 }
2257 \f
2258 /* Find all the switches given to us
2259    and make a vector describing them.
2260    The elements of the vector are strings, one per switch given.
2261    If a switch uses following arguments, then the `part1' field
2262    is the switch itself and the `args' field
2263    is a null-terminated vector containing the following arguments.
2264    The `live_cond' field is 1 if the switch is true in a conditional spec,
2265    -1 if false (overridden by a later switch), and is initialized to zero.
2266    The `valid' field is nonzero if any spec has looked at this switch;
2267    if it remains zero at the end of the run, it must be meaningless.  */
2268
2269 struct switchstr
2270 {
2271   char *part1;
2272   char **args;
2273   int live_cond;
2274   int valid;
2275 };
2276
2277 static struct switchstr *switches;
2278
2279 static int n_switches;
2280
2281 struct infile
2282 {
2283   char *name;
2284   char *language;
2285 };
2286
2287 /* Also a vector of input files specified.  */
2288
2289 static struct infile *infiles;
2290
2291 static int n_infiles;
2292
2293 /* This counts the number of libraries added by LANG_SPECIFIC_DRIVER, so that
2294    we can tell if there were any user supplied any files or libraries.  */
2295
2296 static int added_libraries;
2297
2298 /* And a vector of corresponding output files is made up later.  */
2299
2300 static char **outfiles;
2301
2302 /* Used to track if none of the -B paths are used.  */
2303 static int warn_B;
2304
2305 /* Used to track if standard path isn't used and -b or -V is specified.  */
2306 static int warn_std;
2307
2308 /* Gives value to pass as "warn" to add_prefix for standard prefixes.  */
2309 static int *warn_std_ptr = 0;
2310
2311 \f
2312 #if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX)
2313
2314 /* Convert NAME to a new name if it is the standard suffix.  DO_EXE
2315    is true if we should look for an executable suffix as well.  */
2316
2317 static char *
2318 convert_filename (name, do_exe)
2319      char *name;
2320      int do_exe;
2321 {
2322   int i;
2323   int len = strlen (name);
2324
2325 #ifdef HAVE_OBJECT_SUFFIX
2326   /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj".  */
2327   if (len > 2
2328       && name[len - 2] == '.'
2329       && name[len - 1] == 'o')
2330     {
2331       obstack_grow (&obstack, name, len - 2);
2332       obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
2333       name = obstack_finish (&obstack);
2334     }
2335 #endif
2336
2337 #ifdef HAVE_EXECUTABLE_SUFFIX
2338   /* If there is no filetype, make it the executable suffix (which includes
2339      the ".").  But don't get confused if we have just "-o".  */
2340   if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2341     return name;
2342
2343   for (i = len - 1; i >= 0; i--)
2344     if (name[i] == '/' || name[i] == DIR_SEPARATOR)
2345       break;
2346
2347   for (i++; i < len; i++)
2348     if (name[i] == '.')
2349       return name;
2350
2351   obstack_grow (&obstack, name, len);
2352   obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX));
2353   name = obstack_finish (&obstack);
2354 #endif
2355
2356   return name;
2357 }
2358 #endif
2359 \f
2360 /* Create the vector `switches' and its contents.
2361    Store its length in `n_switches'.  */
2362
2363 static void
2364 process_command (argc, argv)
2365      int argc;
2366      char **argv;
2367 {
2368   register int i;
2369   char *temp;
2370   char *spec_lang = 0;
2371   int last_language_n_infiles;
2372   int have_c = 0;
2373   int have_o = 0;
2374   int lang_n_infiles = 0;
2375
2376   GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
2377
2378   n_switches = 0;
2379   n_infiles = 0;
2380   added_libraries = 0;
2381
2382   /* Figure compiler version from version string.  */
2383
2384   compiler_version = save_string (version_string, strlen (version_string));
2385   for (temp = compiler_version; *temp; ++temp)
2386     {
2387       if (*temp == ' ')
2388         {
2389           *temp = '\0';
2390           break;
2391         }
2392     }
2393
2394   /* Set up the default search paths.  */
2395
2396   if (gcc_exec_prefix)
2397     {
2398       int len = strlen (gcc_exec_prefix);
2399       if (len > sizeof ("/lib/gcc-lib/")-1
2400           && (gcc_exec_prefix[len-1] == '/'
2401               || gcc_exec_prefix[len-1] == DIR_SEPARATOR))
2402         {
2403           temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
2404           if ((*temp == '/' || *temp == DIR_SEPARATOR)
2405               && strncmp (temp+1, "lib", 3) == 0
2406               && (temp[4] == '/' || temp[4] == DIR_SEPARATOR)
2407               && strncmp (temp+5, "gcc-lib", 7) == 0)
2408             len -= sizeof ("/lib/gcc-lib/") - 1;
2409         }
2410
2411       set_std_prefix (gcc_exec_prefix, len);
2412       add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2413       add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR);
2414     }
2415
2416   /* COMPILER_PATH and LIBRARY_PATH have values
2417      that are lists of directory names with colons.  */
2418
2419   GET_ENVIRONMENT (temp, "COMPILER_PATH");
2420   if (temp)
2421     {
2422       char *startp, *endp;
2423       char *nstore = (char *) alloca (strlen (temp) + 3);
2424
2425       startp = endp = temp;
2426       while (1)
2427         {
2428           if (*endp == PATH_SEPARATOR || *endp == 0)
2429             {
2430               strncpy (nstore, startp, endp-startp);
2431               if (endp == startp)
2432                 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2433               else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2434                 {
2435                   nstore[endp-startp] = DIR_SEPARATOR;
2436                   nstore[endp-startp+1] = 0;
2437                 }
2438               else
2439                 nstore[endp-startp] = 0;
2440               add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR);
2441               add_prefix (&include_prefixes,
2442                           concat (nstore, "include", NULL_PTR),
2443                           0, 0, 0, NULL_PTR);
2444               if (*endp == 0)
2445                 break;
2446               endp = startp = endp + 1;
2447             }
2448           else
2449             endp++;
2450         }
2451     }
2452
2453   GET_ENVIRONMENT (temp, "LIBRARY_PATH");
2454   if (temp && *cross_compile == '0')
2455     {
2456       char *startp, *endp;
2457       char *nstore = (char *) alloca (strlen (temp) + 3);
2458
2459       startp = endp = temp;
2460       while (1)
2461         {
2462           if (*endp == PATH_SEPARATOR || *endp == 0)
2463             {
2464               strncpy (nstore, startp, endp-startp);
2465               if (endp == startp)
2466                 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2467               else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2468                 {
2469                   nstore[endp-startp] = DIR_SEPARATOR;
2470                   nstore[endp-startp+1] = 0;
2471                 }
2472               else
2473                 nstore[endp-startp] = 0;
2474               add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2475                           0, 0, NULL_PTR);
2476               if (*endp == 0)
2477                 break;
2478               endp = startp = endp + 1;
2479             }
2480           else
2481             endp++;
2482         }
2483     }
2484
2485   /* Use LPATH like LIBRARY_PATH (for the CMU build program).  */
2486   GET_ENVIRONMENT (temp, "LPATH");
2487   if (temp && *cross_compile == '0')
2488     {
2489       char *startp, *endp;
2490       char *nstore = (char *) alloca (strlen (temp) + 3);
2491
2492       startp = endp = temp;
2493       while (1)
2494         {
2495           if (*endp == PATH_SEPARATOR || *endp == 0)
2496             {
2497               strncpy (nstore, startp, endp-startp);
2498               if (endp == startp)
2499                 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR));
2500               else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2501                 {
2502                   nstore[endp-startp] = DIR_SEPARATOR;
2503                   nstore[endp-startp+1] = 0;
2504                 }
2505               else
2506                 nstore[endp-startp] = 0;
2507               add_prefix (&startfile_prefixes, nstore, NULL_PTR,
2508                           0, 0, NULL_PTR);
2509               if (*endp == 0)
2510                 break;
2511               endp = startp = endp + 1;
2512             }
2513           else
2514             endp++;
2515         }
2516     }
2517
2518   /* Convert new-style -- options to old-style.  */
2519   translate_options (&argc, &argv);
2520
2521 #ifdef LANG_SPECIFIC_DRIVER
2522   /* Do language-specific adjustment/addition of flags.  */
2523   lang_specific_driver (fatal, &argc, &argv, &added_libraries);
2524 #endif
2525
2526   /* Scan argv twice.  Here, the first time, just count how many switches
2527      there will be in their vector, and how many input files in theirs.
2528      Here we also parse the switches that cc itself uses (e.g. -v).  */
2529
2530   for (i = 1; i < argc; i++)
2531     {
2532       if (! strcmp (argv[i], "-dumpspecs"))
2533         {
2534           struct spec_list *sl;
2535           init_spec ();
2536           for (sl = specs; sl; sl = sl->next)
2537             printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
2538           exit (0);
2539         }
2540       else if (! strcmp (argv[i], "-dumpversion"))
2541         {
2542           printf ("%s\n", spec_version);
2543           exit (0);
2544         }
2545       else if (! strcmp (argv[i], "-dumpmachine"))
2546         {
2547           printf ("%s\n", spec_machine);
2548           exit  (0);
2549         }
2550       else if (! strcmp (argv[i], "-print-search-dirs"))
2551         print_search_dirs = 1;
2552       else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2553         print_file_name = "libgcc.a";
2554       else if (! strncmp (argv[i], "-print-file-name=", 17))
2555         print_file_name = argv[i] + 17;
2556       else if (! strncmp (argv[i], "-print-prog-name=", 17))
2557         print_prog_name = argv[i] + 17;
2558       else if (! strcmp (argv[i], "-print-multi-lib"))
2559         print_multi_lib = 1;
2560       else if (! strcmp (argv[i], "-print-multi-directory"))
2561         print_multi_directory = 1;
2562       else if (! strncmp (argv[i], "-Wa,", 4))
2563         {
2564           int prev, j;
2565           /* Pass the rest of this option to the assembler.  */
2566
2567           n_assembler_options++;
2568           if (!assembler_options)
2569             assembler_options
2570               = (char **) xmalloc (n_assembler_options * sizeof (char **));
2571           else
2572             assembler_options
2573               = (char **) xrealloc (assembler_options,
2574                                     n_assembler_options * sizeof (char **));
2575
2576           /* Split the argument at commas.  */
2577           prev = 4;
2578           for (j = 4; argv[i][j]; j++)
2579             if (argv[i][j] == ',')
2580               {
2581                 assembler_options[n_assembler_options - 1]
2582                   = save_string (argv[i] + prev, j - prev);
2583                 n_assembler_options++;
2584                 assembler_options
2585                   = (char **) xrealloc (assembler_options,
2586                                         n_assembler_options * sizeof (char **));
2587                 prev = j + 1;
2588               }
2589           /* Record the part after the last comma.  */
2590           assembler_options[n_assembler_options - 1] = argv[i] + prev;
2591         }
2592       else if (! strncmp (argv[i], "-Wp,", 4))
2593         {
2594           int prev, j;
2595           /* Pass the rest of this option to the preprocessor.  */
2596
2597           n_preprocessor_options++;
2598           if (!preprocessor_options)
2599             preprocessor_options
2600               = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2601           else
2602             preprocessor_options
2603               = (char **) xrealloc (preprocessor_options,
2604                                     n_preprocessor_options * sizeof (char **));
2605
2606           /* Split the argument at commas.  */
2607           prev = 4;
2608           for (j = 4; argv[i][j]; j++)
2609             if (argv[i][j] == ',')
2610               {
2611                 preprocessor_options[n_preprocessor_options - 1]
2612                   = save_string (argv[i] + prev, j - prev);
2613                 n_preprocessor_options++;
2614                 preprocessor_options
2615                   = (char **) xrealloc (preprocessor_options,
2616                                         n_preprocessor_options * sizeof (char **));
2617                 prev = j + 1;
2618               }
2619           /* Record the part after the last comma.  */
2620           preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2621         }
2622       else if (argv[i][0] == '+' && argv[i][1] == 'e')
2623         /* The +e options to the C++ front-end.  */
2624         n_switches++;
2625       else if (strncmp (argv[i], "-Wl,", 4) == 0)
2626         {
2627           int j;
2628           /* Split the argument at commas.  */
2629           for (j = 3; argv[i][j]; j++)
2630             n_infiles += (argv[i][j] == ',');
2631         }
2632       else if (strcmp (argv[i], "-Xlinker") == 0)
2633         {
2634           if (i + 1 == argc)
2635             fatal ("argument to `-Xlinker' is missing");
2636
2637           n_infiles++;
2638           i++;
2639         }
2640       else if (strncmp (argv[i], "-l", 2) == 0)
2641         n_infiles++;
2642       else if (strcmp (argv[i], "-save-temps") == 0)
2643         {
2644           save_temps_flag = 1;
2645           n_switches++;
2646         }
2647       else if (strcmp (argv[i], "-specs") == 0)
2648         {
2649           struct user_specs *user = (struct user_specs *)
2650             xmalloc (sizeof (struct user_specs));
2651           if (++i >= argc)
2652             fatal ("argument to `-specs' is missing");
2653
2654           user->next = (struct user_specs *)0;
2655           user->filename = argv[i];
2656           if (user_specs_tail)
2657             user_specs_tail->next = user;
2658           else
2659             user_specs_head = user;
2660           user_specs_tail = user;
2661         }
2662       else if (strncmp (argv[i], "-specs=", 7) == 0)
2663         {
2664           struct user_specs *user = (struct user_specs *)
2665             xmalloc (sizeof (struct user_specs));
2666           if (strlen (argv[i]) == 7)
2667             fatal ("argument to `-specs=' is missing");
2668
2669           user->next = (struct user_specs *)0;
2670           user->filename = argv[i]+7;
2671           if (user_specs_tail)
2672             user_specs_tail->next = user;
2673           else
2674             user_specs_head = user;
2675           user_specs_tail = user;
2676         }
2677       else if (argv[i][0] == '-' && argv[i][1] != 0)
2678         {
2679           register char *p = &argv[i][1];
2680           register int c = *p;
2681
2682           switch (c)
2683             {
2684             case 'b':
2685               n_switches++;
2686               if (p[1] == 0 && i + 1 == argc)
2687                 fatal ("argument to `-b' is missing");
2688               if (p[1] == 0)
2689                 spec_machine = argv[++i];
2690               else
2691                 spec_machine = p + 1;
2692
2693               warn_std_ptr = &warn_std;
2694               break;
2695
2696             case 'B':
2697               {
2698                 char *value;
2699                 if (p[1] == 0 && i + 1 == argc)
2700                   fatal ("argument to `-B' is missing");
2701                 if (p[1] == 0)
2702                   value = argv[++i];
2703                 else
2704                   value = p + 1;
2705                 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
2706                 add_prefix (&startfile_prefixes, value, NULL_PTR,
2707                             1, 0, &warn_B);
2708                 add_prefix (&include_prefixes, concat (value, "include",
2709                                                        NULL_PTR),
2710                             NULL_PTR, 1, 0, NULL_PTR);
2711
2712                 /* As a kludge, if the arg is "[foo/]stageN/", just add
2713                    "[foo/]include" to the include prefix.  */
2714                 {
2715                   int len = strlen (value);
2716                   if ((len == 7
2717                        || (len > 7
2718                            && (value[len - 8] == '/'
2719                                || value[len - 8] == DIR_SEPARATOR)))
2720                       && strncmp (value + len - 7, "stage", 5) == 0
2721                       && ISDIGIT (value[len - 2])
2722                       && (value[len - 1] == '/'
2723                           || value[len - 1] == DIR_SEPARATOR))
2724                     {
2725                       if (len == 7)
2726                         add_prefix (&include_prefixes, "include", NULL_PTR,
2727                                     1, 0, NULL_PTR);
2728                       else
2729                         {
2730                           char *string = xmalloc (len + 1);
2731                           strncpy (string, value, len-7);
2732                           strcpy (string+len-7, "include");
2733                           add_prefix (&include_prefixes, string, NULL_PTR,
2734                                       1, 0, NULL_PTR);
2735                         }
2736                     }
2737                 }
2738                 n_switches++;
2739               }
2740               break;
2741
2742             case 'v':   /* Print our subcommands and print versions.  */
2743               n_switches++;
2744               /* If they do anything other than exactly `-v', don't set
2745                  verbose_flag; rather, continue on to give the error.  */
2746               if (p[1] != 0)
2747                 break;
2748               verbose_flag++;
2749               break;
2750
2751             case 'V':
2752               n_switches++;
2753               if (p[1] == 0 && i + 1 == argc)
2754                 fatal ("argument to `-V' is missing");
2755               if (p[1] == 0)
2756                 spec_version = argv[++i];
2757               else
2758                 spec_version = p + 1;
2759               compiler_version = spec_version;
2760               warn_std_ptr = &warn_std;
2761
2762               /* Validate the version number.  Use the same checks
2763                  done when inserting it into a spec.
2764
2765                  The format of the version string is
2766                  ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?  */
2767               {
2768                 char *v = compiler_version;
2769
2770                 /* Ignore leading non-digits.  i.e. "foo-" in "foo-2.7.2".  */
2771                 while (! ISDIGIT (*v))
2772                   v++;
2773
2774                 if (v > compiler_version && v[-1] != '-')
2775                   fatal ("invalid version number format");
2776
2777                 /* Set V after the first period.  */
2778                 while (ISDIGIT (*v))
2779                   v++;
2780
2781                 if (*v != '.')
2782                   fatal ("invalid version number format");
2783
2784                 v++;
2785                 while (ISDIGIT (*v))
2786                   v++;
2787
2788                 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
2789                   fatal ("invalid version number format");
2790               }
2791               break;
2792
2793             case 'c':
2794               if (p[1] == 0)
2795                 {
2796                   have_c = 1;
2797                   n_switches++;
2798                   break;
2799                 }
2800               goto normal_switch;
2801
2802             case 'o':
2803               have_o = 1;
2804 #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
2805               argv[i] = convert_filename (argv[i], 1);
2806               if (p[1] == 0)
2807                 argv[i+1] = convert_filename (argv[i+1], 1);
2808 #endif
2809               goto normal_switch;
2810
2811             default:
2812             normal_switch:
2813               n_switches++;
2814
2815               if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2816                 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2817               else if (WORD_SWITCH_TAKES_ARG (p))
2818                 i += WORD_SWITCH_TAKES_ARG (p);
2819             }
2820         }
2821       else
2822         {
2823           n_infiles++;
2824           lang_n_infiles++;
2825         }
2826     }
2827
2828   if (have_c && have_o && lang_n_infiles > 1)
2829     fatal ("cannot specify -o with -c or -S and multiple compilations");
2830
2831   /* Set up the search paths before we go looking for config files.  */
2832
2833   /* These come before the md prefixes so that we will find gcc's subcommands
2834      (such as cpp) rather than those of the host system.  */
2835   /* Use 2 as fourth arg meaning try just the machine as a suffix,
2836      as well as trying the machine and the version.  */
2837 #ifndef OS2
2838   add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
2839               0, 2, warn_std_ptr);
2840   add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
2841               0, 2, warn_std_ptr);
2842 #endif
2843
2844   add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
2845               0, 1, warn_std_ptr);
2846   add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
2847               0, 1, warn_std_ptr);
2848
2849   tooldir_prefix = concat (tooldir_base_prefix, spec_machine, 
2850                            dir_separator_str, NULL_PTR);
2851
2852   /* If tooldir is relative, base it on exec_prefixes.  A relative
2853      tooldir lets us move the installed tree as a unit.
2854
2855      If GCC_EXEC_PREFIX is defined, then we want to add two relative
2856      directories, so that we can search both the user specified directory
2857      and the standard place.  */
2858
2859   if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2860     {
2861       if (gcc_exec_prefix)
2862         {
2863           char *gcc_exec_tooldir_prefix
2864             = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
2865                       spec_version, dir_separator_str, tooldir_prefix, NULL_PTR);
2866
2867           add_prefix (&exec_prefixes,
2868                       concat (gcc_exec_tooldir_prefix, "bin", 
2869                               dir_separator_str, NULL_PTR),
2870                       NULL_PTR, 0, 0, NULL_PTR);
2871           add_prefix (&startfile_prefixes,
2872                       concat (gcc_exec_tooldir_prefix, "lib", 
2873                               dir_separator_str, NULL_PTR),
2874                       NULL_PTR, 0, 0, NULL_PTR);
2875         }
2876
2877       tooldir_prefix = concat (standard_exec_prefix, spec_machine,
2878                                dir_separator_str, spec_version, 
2879                                dir_separator_str, tooldir_prefix, NULL_PTR);
2880     }
2881
2882   add_prefix (&exec_prefixes, 
2883               concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR),
2884               "BINUTILS", 0, 0, NULL_PTR);
2885   add_prefix (&startfile_prefixes,
2886               concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR),
2887               "BINUTILS", 0, 0, NULL_PTR);
2888
2889   /* More prefixes are enabled in main, after we read the specs file
2890      and determine whether this is cross-compilation or not.  */
2891
2892
2893   /* Then create the space for the vectors and scan again.  */
2894
2895   switches = ((struct switchstr *)
2896               xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2897   infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2898   n_switches = 0;
2899   n_infiles = 0;
2900   last_language_n_infiles = -1;
2901
2902   /* This, time, copy the text of each switch and store a pointer
2903      to the copy in the vector of switches.
2904      Store all the infiles in their vector.  */
2905
2906   for (i = 1; i < argc; i++)
2907     {
2908       /* Just skip the switches that were handled by the preceding loop.  */
2909       if (! strncmp (argv[i], "-Wa,", 4))
2910         ;
2911       else if (! strncmp (argv[i], "-Wp,", 4))
2912         ;
2913       else if (! strcmp (argv[i], "-print-search-dirs"))
2914         ;
2915       else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2916         ;
2917       else if (! strncmp (argv[i], "-print-file-name=", 17))
2918         ;
2919       else if (! strncmp (argv[i], "-print-prog-name=", 17))
2920         ;
2921       else if (! strcmp (argv[i], "-print-multi-lib"))
2922         ;
2923       else if (! strcmp (argv[i], "-print-multi-directory"))
2924         ;
2925       else if (argv[i][0] == '+' && argv[i][1] == 'e')
2926         {
2927           /* Compensate for the +e options to the C++ front-end;
2928              they're there simply for cfront call-compatibility.  We do
2929              some magic in default_compilers to pass them down properly.
2930              Note we deliberately start at the `+' here, to avoid passing
2931              -e0 or -e1 down into the linker.  */
2932           switches[n_switches].part1 = &argv[i][0];
2933           switches[n_switches].args = 0;
2934           switches[n_switches].live_cond = 0;
2935           switches[n_switches].valid = 0;
2936           n_switches++;
2937         }
2938       else if (strncmp (argv[i], "-Wl,", 4) == 0)
2939         {
2940           int prev, j;
2941           /* Split the argument at commas.  */
2942           prev = 4;
2943           for (j = 4; argv[i][j]; j++)
2944             if (argv[i][j] == ',')
2945               {
2946                 infiles[n_infiles].language = "*";
2947                 infiles[n_infiles++].name
2948                   = save_string (argv[i] + prev, j - prev);
2949                 prev = j + 1;
2950               }
2951           /* Record the part after the last comma.  */
2952           infiles[n_infiles].language = "*";
2953           infiles[n_infiles++].name = argv[i] + prev;
2954         }
2955       else if (strcmp (argv[i], "-Xlinker") == 0)
2956         {
2957           infiles[n_infiles].language = "*";
2958           infiles[n_infiles++].name = argv[++i];
2959         }
2960       else if (strncmp (argv[i], "-l", 2) == 0)
2961         {
2962           infiles[n_infiles].language = "*";
2963           infiles[n_infiles++].name = argv[i];
2964         }
2965       else if (strcmp (argv[i], "-specs") == 0)
2966         i++;
2967       else if (strncmp (argv[i], "-specs=", 7) == 0)
2968         ;
2969       /* -save-temps overrides -pipe, so that temp files are produced */
2970       else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0)
2971         error ("Warning: -pipe ignored since -save-temps specified");
2972       else if (argv[i][0] == '-' && argv[i][1] != 0)
2973         {
2974           register char *p = &argv[i][1];
2975           register int c = *p;
2976
2977           if (c == 'x')
2978             {
2979               if (p[1] == 0 && i + 1 == argc)
2980                 fatal ("argument to `-x' is missing");
2981               if (p[1] == 0)
2982                 spec_lang = argv[++i];
2983               else
2984                 spec_lang = p + 1;
2985               if (! strcmp (spec_lang, "none"))
2986                 /* Suppress the warning if -xnone comes after the last input
2987                    file, because alternate command interfaces like g++ might
2988                    find it useful to place -xnone after each input file.  */
2989                 spec_lang = 0;
2990               else
2991                 last_language_n_infiles = n_infiles;
2992               continue;
2993             }
2994           switches[n_switches].part1 = p;
2995           /* Deal with option arguments in separate argv elements.  */
2996           if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2997               || WORD_SWITCH_TAKES_ARG (p))
2998             {
2999               int j = 0;
3000               int n_args = WORD_SWITCH_TAKES_ARG (p);
3001
3002               if (n_args == 0)
3003                 {
3004                   /* Count only the option arguments in separate argv elements.  */
3005                   n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3006                 }
3007               if (i + n_args >= argc)
3008                 fatal ("argument to `-%s' is missing", p);
3009               switches[n_switches].args
3010                 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
3011               while (j < n_args)
3012                 switches[n_switches].args[j++] = argv[++i];
3013               /* Null-terminate the vector.  */
3014               switches[n_switches].args[j] = 0;
3015             }
3016           else if (index (switches_need_spaces, c))
3017             {
3018               /* On some systems, ld cannot handle some options without
3019                  a space.  So split the option from its argument.  */
3020               char *part1 = (char *) xmalloc (2);
3021               part1[0] = c;
3022               part1[1] = '\0';
3023               
3024               switches[n_switches].part1 = part1;
3025               switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
3026               switches[n_switches].args[0] = xmalloc (strlen (p));
3027               strcpy (switches[n_switches].args[0], &p[1]);
3028               switches[n_switches].args[1] = 0;
3029             }
3030           else
3031             switches[n_switches].args = 0;
3032
3033           switches[n_switches].live_cond = 0;
3034           switches[n_switches].valid = 0;
3035           /* This is always valid, since gcc.c itself understands it.  */
3036           if (!strcmp (p, "save-temps"))
3037             switches[n_switches].valid = 1;
3038           else
3039             {
3040               char ch = switches[n_switches].part1[0];
3041               if (ch == 'V' || ch == 'b' || ch == 'B')
3042                 switches[n_switches].valid = 1;
3043             }
3044           n_switches++;
3045         }
3046       else
3047         {
3048 #ifdef HAVE_OBJECT_SUFFIX
3049           argv[i] = convert_filename (argv[i], 0);
3050 #endif
3051
3052           if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
3053             {
3054               perror_with_name (argv[i]);
3055               error_count++;
3056             }
3057           else
3058             {
3059               infiles[n_infiles].language = spec_lang;
3060               infiles[n_infiles++].name = argv[i];
3061             }
3062         }
3063     }
3064
3065   if (n_infiles == last_language_n_infiles && spec_lang != 0)
3066     error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3067
3068   switches[n_switches].part1 = 0;
3069   infiles[n_infiles].name = 0;
3070 }
3071 \f
3072 /* Process a spec string, accumulating and running commands.  */
3073
3074 /* These variables describe the input file name.
3075    input_file_number is the index on outfiles of this file,
3076    so that the output file name can be stored for later use by %o.
3077    input_basename is the start of the part of the input file
3078    sans all directory names, and basename_length is the number
3079    of characters starting there excluding the suffix .c or whatever.  */
3080
3081 static char *input_filename;
3082 static int input_file_number;
3083 static size_t input_filename_length;
3084 static int basename_length;
3085 static char *input_basename;
3086 static char *input_suffix;
3087
3088 /* These are variables used within do_spec and do_spec_1.  */
3089
3090 /* Nonzero if an arg has been started and not yet terminated
3091    (with space, tab or newline).  */
3092 static int arg_going;
3093
3094 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3095    is a temporary file name.  */
3096 static int delete_this_arg;
3097
3098 /* Nonzero means %w has been seen; the next arg to be terminated
3099    is the output file name of this compilation.  */
3100 static int this_is_output_file;
3101
3102 /* Nonzero means %s has been seen; the next arg to be terminated
3103    is the name of a library file and we should try the standard
3104    search dirs for it.  */
3105 static int this_is_library_file;
3106
3107 /* Nonzero means that the input of this command is coming from a pipe.  */
3108 static int input_from_pipe;
3109
3110 /* Process the spec SPEC and run the commands specified therein.
3111    Returns 0 if the spec is successfully processed; -1 if failed.  */
3112
3113 static int
3114 do_spec (spec)
3115      char *spec;
3116 {
3117   int value;
3118
3119   clear_args ();
3120   arg_going = 0;
3121   delete_this_arg = 0;
3122   this_is_output_file = 0;
3123   this_is_library_file = 0;
3124   input_from_pipe = 0;
3125
3126   value = do_spec_1 (spec, 0, NULL_PTR);
3127
3128   /* Force out any unfinished command.
3129      If -pipe, this forces out the last command if it ended in `|'.  */
3130   if (value == 0)
3131     {
3132       if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3133         argbuf_index--;
3134
3135       if (argbuf_index > 0)
3136         value = execute ();
3137     }
3138
3139   return value;
3140 }
3141
3142 /* Process the sub-spec SPEC as a portion of a larger spec.
3143    This is like processing a whole spec except that we do
3144    not initialize at the beginning and we do not supply a
3145    newline by default at the end.
3146    INSWITCH nonzero means don't process %-sequences in SPEC;
3147    in this case, % is treated as an ordinary character.
3148    This is used while substituting switches.
3149    INSWITCH nonzero also causes SPC not to terminate an argument.
3150
3151    Value is zero unless a line was finished
3152    and the command on that line reported an error.  */
3153
3154 static int
3155 do_spec_1 (spec, inswitch, soft_matched_part)
3156      char *spec;
3157      int inswitch;
3158      char *soft_matched_part;
3159 {
3160   register char *p = spec;
3161   register int c;
3162   int i;
3163   char *string;
3164   int value;
3165
3166   while ((c = *p++))
3167     /* If substituting a switch, treat all chars like letters.
3168        Otherwise, NL, SPC, TAB and % are special.  */
3169     switch (inswitch ? 'a' : c)
3170       {
3171       case '\n':
3172         /* End of line: finish any pending argument,
3173            then run the pending command if one has been started.  */
3174         if (arg_going)
3175           {
3176             obstack_1grow (&obstack, 0);
3177             string = obstack_finish (&obstack);
3178             if (this_is_library_file)
3179               string = find_file (string);
3180             store_arg (string, delete_this_arg, this_is_output_file);
3181             if (this_is_output_file)
3182               outfiles[input_file_number] = string;
3183           }
3184         arg_going = 0;
3185
3186         if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3187           {
3188             for (i = 0; i < n_switches; i++)
3189               if (!strcmp (switches[i].part1, "pipe"))
3190                 break;
3191
3192             /* A `|' before the newline means use a pipe here,
3193                but only if -pipe was specified.
3194                Otherwise, execute now and don't pass the `|' as an arg.  */
3195             if (i < n_switches)
3196               {
3197                 input_from_pipe = 1;
3198                 switches[i].valid = 1;
3199                 break;
3200               }
3201             else
3202               argbuf_index--;
3203           }
3204
3205         if (argbuf_index > 0)
3206           {
3207             value = execute ();
3208             if (value)
3209               return value;
3210           }
3211         /* Reinitialize for a new command, and for a new argument.  */
3212         clear_args ();
3213         arg_going = 0;
3214         delete_this_arg = 0;
3215         this_is_output_file = 0;
3216         this_is_library_file = 0;
3217         input_from_pipe = 0;
3218         break;
3219
3220       case '|':
3221         /* End any pending argument.  */
3222         if (arg_going)
3223           {
3224             obstack_1grow (&obstack, 0);
3225             string = obstack_finish (&obstack);
3226             if (this_is_library_file)
3227               string = find_file (string);
3228             store_arg (string, delete_this_arg, this_is_output_file);
3229             if (this_is_output_file)
3230               outfiles[input_file_number] = string;
3231           }
3232
3233         /* Use pipe */
3234         obstack_1grow (&obstack, c);
3235         arg_going = 1;
3236         break;
3237
3238       case '\t':
3239       case ' ':
3240         /* Space or tab ends an argument if one is pending.  */
3241         if (arg_going)
3242           {
3243             obstack_1grow (&obstack, 0);
3244             string = obstack_finish (&obstack);
3245             if (this_is_library_file)
3246               string = find_file (string);
3247             store_arg (string, delete_this_arg, this_is_output_file);
3248             if (this_is_output_file)
3249               outfiles[input_file_number] = string;
3250           }
3251         /* Reinitialize for a new argument.  */
3252         arg_going = 0;
3253         delete_this_arg = 0;
3254         this_is_output_file = 0;
3255         this_is_library_file = 0;
3256         break;
3257
3258       case '%':
3259         switch (c = *p++)
3260           {
3261           case 0:
3262             fatal ("Invalid specification!  Bug in cc.");
3263
3264           case 'b':
3265             obstack_grow (&obstack, input_basename, basename_length);
3266             arg_going = 1;
3267             break;
3268
3269           case 'd':
3270             delete_this_arg = 2;
3271             break;
3272
3273           /* Dump out the directories specified with LIBRARY_PATH,
3274              followed by the absolute directories
3275              that we search for startfiles.  */
3276           case 'D':
3277             {
3278               struct prefix_list *pl = startfile_prefixes.plist;
3279               size_t bufsize = 100;
3280               char *buffer = (char *) xmalloc (bufsize);
3281               int idx;
3282
3283               for (; pl; pl = pl->next)
3284                 {
3285 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3286                   /* Used on systems which record the specified -L dirs
3287                      and use them to search for dynamic linking.  */
3288                   /* Relative directories always come from -B,
3289                      and it is better not to use them for searching
3290                      at run time.  In particular, stage1 loses  */
3291                   if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3292                     continue;
3293 #endif
3294                   /* Try subdirectory if there is one.  */
3295                   if (multilib_dir != NULL)
3296                     {
3297                       if (machine_suffix)
3298                         {
3299                           if (strlen (pl->prefix) + strlen (machine_suffix)
3300                               >= bufsize)
3301                             bufsize = (strlen (pl->prefix)
3302                                        + strlen (machine_suffix)) * 2 + 1;
3303                           buffer = (char *) xrealloc (buffer, bufsize);
3304                           strcpy (buffer, pl->prefix);
3305                           strcat (buffer, machine_suffix);
3306                           if (is_directory (buffer, multilib_dir, 1))
3307                             {
3308                               do_spec_1 ("-L", 0, NULL_PTR);
3309 #ifdef SPACE_AFTER_L_OPTION
3310                               do_spec_1 (" ", 0, NULL_PTR);
3311 #endif
3312                               do_spec_1 (buffer, 1, NULL_PTR);
3313                               do_spec_1 (multilib_dir, 1, NULL_PTR);
3314                               /* Make this a separate argument.  */
3315                               do_spec_1 (" ", 0, NULL_PTR);
3316                             }
3317                         }
3318                       if (!pl->require_machine_suffix)
3319                         {
3320                           if (is_directory (pl->prefix, multilib_dir, 1))
3321                             {
3322                               do_spec_1 ("-L", 0, NULL_PTR);
3323 #ifdef SPACE_AFTER_L_OPTION
3324                               do_spec_1 (" ", 0, NULL_PTR);
3325 #endif
3326                               do_spec_1 (pl->prefix, 1, NULL_PTR);
3327                               do_spec_1 (multilib_dir, 1, NULL_PTR);
3328                               /* Make this a separate argument.  */
3329                               do_spec_1 (" ", 0, NULL_PTR);
3330                             }
3331                         }
3332                     }
3333                   if (machine_suffix)
3334                     {
3335                       if (is_directory (pl->prefix, machine_suffix, 1))
3336                         {
3337                           do_spec_1 ("-L", 0, NULL_PTR);
3338 #ifdef SPACE_AFTER_L_OPTION
3339                           do_spec_1 (" ", 0, NULL_PTR);
3340 #endif
3341                           do_spec_1 (pl->prefix, 1, NULL_PTR);
3342                           /* Remove slash from machine_suffix.  */
3343                           if (strlen (machine_suffix) >= bufsize)
3344                             bufsize = strlen (machine_suffix) * 2 + 1;
3345                           buffer = (char *) xrealloc (buffer, bufsize);
3346                           strcpy (buffer, machine_suffix);
3347                           idx = strlen (buffer);
3348                           if (buffer[idx - 1] == '/'
3349                               || buffer[idx - 1] == DIR_SEPARATOR)
3350                             buffer[idx - 1] = 0;
3351                           do_spec_1 (buffer, 1, NULL_PTR);
3352                           /* Make this a separate argument.  */
3353                           do_spec_1 (" ", 0, NULL_PTR);
3354                         }
3355                     }
3356                   if (!pl->require_machine_suffix)
3357                     {
3358                       if (is_directory (pl->prefix, "", 1))
3359                         {
3360                           do_spec_1 ("-L", 0, NULL_PTR);
3361 #ifdef SPACE_AFTER_L_OPTION
3362                           do_spec_1 (" ", 0, NULL_PTR);
3363 #endif
3364                           /* Remove slash from pl->prefix.  */
3365                           if (strlen (pl->prefix) >= bufsize)
3366                             bufsize = strlen (pl->prefix) * 2 + 1;
3367                           buffer = (char *) xrealloc (buffer, bufsize);
3368                           strcpy (buffer, pl->prefix);
3369                           idx = strlen (buffer);
3370                           if (buffer[idx - 1] == '/'
3371                               || buffer[idx - 1] == DIR_SEPARATOR)
3372                             buffer[idx - 1] = 0;
3373                           do_spec_1 (buffer, 1, NULL_PTR);
3374                           /* Make this a separate argument.  */
3375                           do_spec_1 (" ", 0, NULL_PTR);
3376                         }
3377                     }
3378                 }
3379               free (buffer);
3380             }
3381             break;
3382
3383           case 'e':
3384             /* {...:%efoo} means report an error with `foo' as error message
3385                and don't execute any more commands for this file.  */
3386             {
3387               char *q = p;
3388               char *buf;
3389               while (*p != 0 && *p != '\n') p++;
3390               buf = (char *) alloca (p - q + 1);
3391               strncpy (buf, q, p - q);
3392               buf[p - q] = 0;
3393               error ("%s", buf);
3394               return -1;
3395             }
3396             break;
3397
3398           case 'g':
3399           case 'u':
3400           case 'U':
3401             if (save_temps_flag)
3402               {
3403                 obstack_grow (&obstack, input_basename, basename_length);
3404                 delete_this_arg = 0;
3405               }
3406             else
3407               {
3408 #ifdef MKTEMP_EACH_FILE
3409                 /* ??? This has a problem: the total number of
3410                    values mktemp can return is limited.
3411                    That matters for the names of object files.
3412                    In 2.4, do something about that.  */
3413                 struct temp_name *t;
3414                 char *suffix = p;
3415                 while (*p == '.' || ISALPHA (*p)
3416                        || (p[0] == '%' && p[1] == 'O'))
3417                   p++;
3418
3419                 /* See if we already have an association of %g/%u/%U and
3420                    suffix.  */
3421                 for (t = temp_names; t; t = t->next)
3422                   if (t->length == p - suffix
3423                       && strncmp (t->suffix, suffix, p - suffix) == 0
3424                       && t->unique == (c != 'g'))
3425                     break;
3426
3427                 /* Make a new association if needed.  %u requires one.  */
3428                 if (t == 0 || c == 'u')
3429                   {
3430                     if (t == 0)
3431                       {
3432                         t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3433                         t->next = temp_names;
3434                         temp_names = t;
3435                       }
3436                     t->length = p - suffix;
3437                     t->suffix = save_string (suffix, p - suffix);
3438                     t->unique = (c != 'g');
3439                     temp_filename = choose_temp_base ();
3440                     temp_filename_length = strlen (temp_filename);
3441                     t->filename = temp_filename;
3442                     t->filename_length = temp_filename_length;
3443                   }
3444
3445                 obstack_grow (&obstack, t->filename, t->filename_length);
3446                 delete_this_arg = 1;
3447 #else
3448                 obstack_grow (&obstack, temp_filename, temp_filename_length);
3449                 if (c == 'u' || c == 'U')
3450                   {
3451                     static int unique;
3452                     char buff[9];
3453                     if (c == 'u')
3454                       unique++;
3455                     sprintf (buff, "%d", unique);
3456                     obstack_grow (&obstack, buff, strlen (buff));
3457                   }
3458 #endif
3459                 delete_this_arg = 1;
3460               }
3461             arg_going = 1;
3462             break;
3463
3464           case 'i':
3465             obstack_grow (&obstack, input_filename, input_filename_length);
3466             arg_going = 1;
3467             break;
3468
3469           case 'I':
3470             {
3471               struct prefix_list *pl = include_prefixes.plist;
3472
3473               if (gcc_exec_prefix)
3474                 {
3475                   do_spec_1 ("-iprefix", 1, NULL_PTR);
3476                   /* Make this a separate argument.  */
3477                   do_spec_1 (" ", 0, NULL_PTR);
3478                   do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3479                   do_spec_1 (" ", 0, NULL_PTR);
3480                 }
3481
3482               for (; pl; pl = pl->next)
3483                 {
3484                   do_spec_1 ("-isystem", 1, NULL_PTR);
3485                   /* Make this a separate argument.  */
3486                   do_spec_1 (" ", 0, NULL_PTR);
3487                   do_spec_1 (pl->prefix, 1, NULL_PTR);
3488                   do_spec_1 (" ", 0, NULL_PTR);
3489                 }
3490             }
3491             break;
3492
3493           case 'o':
3494             for (i = 0; i < n_infiles; i++)
3495               store_arg (outfiles[i], 0, 0);
3496             break;
3497
3498           case 'O':
3499             obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX));
3500             arg_going = 1;
3501             break;
3502
3503           case 's':
3504             this_is_library_file = 1;
3505             break;
3506
3507           case 'w':
3508             this_is_output_file = 1;
3509             break;
3510
3511           case 'W':
3512             {
3513               int cur_index = argbuf_index;
3514               /* Handle the {...} following the %W.  */
3515               if (*p != '{')
3516                 abort ();
3517               p = handle_braces (p + 1);
3518               if (p == 0)
3519                 return -1;
3520               /* If any args were output, mark the last one for deletion
3521                  on failure.  */
3522               if (argbuf_index != cur_index)
3523                 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3524               break;
3525             }
3526
3527           /* %x{OPTION} records OPTION for %X to output.  */
3528           case 'x':
3529             {
3530               char *p1 = p;
3531               char *string;
3532
3533               /* Skip past the option value and make a copy.  */
3534               if (*p != '{')
3535                 abort ();
3536               while (*p++ != '}')
3537                 ;
3538               string = save_string (p1 + 1, p - p1 - 2);
3539
3540               /* See if we already recorded this option.  */
3541               for (i = 0; i < n_linker_options; i++)
3542                 if (! strcmp (string, linker_options[i]))
3543                   {
3544                     free (string);
3545                     return 0;
3546                   }
3547
3548               /* This option is new; add it.  */
3549               n_linker_options++;
3550               if (!linker_options)
3551                 linker_options
3552                   = (char **) xmalloc (n_linker_options * sizeof (char **));
3553               else
3554                 linker_options
3555                   = (char **) xrealloc (linker_options,
3556                                         n_linker_options * sizeof (char **));
3557
3558               linker_options[n_linker_options - 1] = string;
3559             }
3560             break;
3561
3562           /* Dump out the options accumulated previously using %x.  */
3563           case 'X':
3564             for (i = 0; i < n_linker_options; i++)
3565               {
3566                 do_spec_1 (linker_options[i], 1, NULL_PTR);
3567                 /* Make each accumulated option a separate argument.  */
3568                 do_spec_1 (" ", 0, NULL_PTR);
3569               }
3570             break;
3571
3572           /* Dump out the options accumulated previously using -Wa,.  */
3573           case 'Y':
3574             for (i = 0; i < n_assembler_options; i++)
3575               {
3576                 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3577                 /* Make each accumulated option a separate argument.  */
3578                 do_spec_1 (" ", 0, NULL_PTR);
3579               }
3580             break;
3581
3582           /* Dump out the options accumulated previously using -Wp,.  */
3583           case 'Z':
3584             for (i = 0; i < n_preprocessor_options; i++)
3585               {
3586                 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3587                 /* Make each accumulated option a separate argument.  */
3588                 do_spec_1 (" ", 0, NULL_PTR);
3589               }
3590             break;
3591
3592             /* Here are digits and numbers that just process
3593                a certain constant string as a spec.  */
3594
3595           case '1':
3596             value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3597             if (value != 0)
3598               return value;
3599             break;
3600
3601           case '2':
3602             value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3603             if (value != 0)
3604               return value;
3605             break;
3606
3607           case 'a':
3608             value = do_spec_1 (asm_spec, 0, NULL_PTR);
3609             if (value != 0)
3610               return value;
3611             break;
3612
3613           case 'A':
3614             value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3615             if (value != 0)
3616               return value;
3617             break;
3618
3619           case 'c':
3620             value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3621             if (value != 0)
3622               return value;
3623             break;
3624
3625           case 'C':
3626             value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3627             if (value != 0)
3628               return value;
3629             break;
3630
3631           case 'E':
3632             value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3633             if (value != 0)
3634               return value;
3635             break;
3636
3637           case 'l':
3638             value = do_spec_1 (link_spec, 0, NULL_PTR);
3639             if (value != 0)
3640               return value;
3641             break;
3642
3643           case 'L':
3644             value = do_spec_1 (lib_spec, 0, NULL_PTR);
3645             if (value != 0)
3646               return value;
3647             break;
3648
3649           case 'G':
3650             value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3651             if (value != 0)
3652               return value;
3653             break;
3654
3655           case 'p':
3656             {
3657               char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3658               char *buf = x;
3659               char *y;
3660
3661               /* Copy all of the -D options in CPP_PREDEFINES into BUF.  */
3662               y = cpp_predefines;
3663               while (*y != 0)
3664                 {
3665                   if (! strncmp (y, "-D", 2))
3666                     /* Copy the whole option.  */
3667                     while (*y && *y != ' ' && *y != '\t')
3668                       *x++ = *y++;
3669                   else if (*y == ' ' || *y == '\t')
3670                     /* Copy whitespace to the result.  */
3671                     *x++ = *y++;
3672                   /* Don't copy other options.  */
3673                   else
3674                     y++;
3675                 }
3676
3677               *x = 0;
3678
3679               value = do_spec_1 (buf, 0, NULL_PTR);
3680               if (value != 0)
3681                 return value;
3682             }
3683             break;
3684
3685           case 'P':
3686             {
3687               char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3688               char *buf = x;
3689               char *y;
3690
3691               /* Copy all of CPP_PREDEFINES into BUF,
3692                  but put __ after every -D and at the end of each arg.  */
3693               y = cpp_predefines;
3694               while (*y != 0)
3695                 {
3696                   if (! strncmp (y, "-D", 2))
3697                     {
3698                       int flag = 0;
3699
3700                       *x++ = *y++;
3701                       *x++ = *y++;
3702
3703                       if (*y != '_'
3704                           || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3705                         {
3706                           /* Stick __ at front of macro name.  */
3707                           *x++ = '_';
3708                           *x++ = '_';
3709                           /* Arrange to stick __ at the end as well.  */
3710                           flag = 1;
3711                         }
3712
3713                       /* Copy the macro name.  */
3714                       while (*y && *y != '=' && *y != ' ' && *y != '\t')
3715                         *x++ = *y++;
3716
3717                       if (flag)
3718                         {
3719                           *x++ = '_';
3720                           *x++ = '_';
3721                         }
3722
3723                       /* Copy the value given, if any.  */
3724                       while (*y && *y != ' ' && *y != '\t')
3725                         *x++ = *y++;
3726                     }
3727                   else if (*y == ' ' || *y == '\t')
3728                     /* Copy whitespace to the result.  */
3729                     *x++ = *y++;
3730                   /* Don't copy -A options  */
3731                   else
3732                     y++;
3733                 }
3734               *x++ = ' ';
3735
3736               /* Copy all of CPP_PREDEFINES into BUF,
3737                  but put __ after every -D.  */
3738               y = cpp_predefines;
3739               while (*y != 0)
3740                 {
3741                   if (! strncmp (y, "-D", 2))
3742                     {
3743                       y += 2;
3744
3745                       if (*y != '_'
3746                           || (*(y+1) != '_' && ! ISUPPER (*(y+1))))
3747                         {
3748                           /* Stick -D__ at front of macro name.  */
3749                           *x++ = '-';
3750                           *x++ = 'D';
3751                           *x++ = '_';
3752                           *x++ = '_';
3753
3754                           /* Copy the macro name.  */
3755                           while (*y && *y != '=' && *y != ' ' && *y != '\t')
3756                             *x++ = *y++;
3757
3758                           /* Copy the value given, if any.  */
3759                           while (*y && *y != ' ' && *y != '\t')
3760                             *x++ = *y++;
3761                         }
3762                       else
3763                         {
3764                           /* Do not copy this macro - we have just done it before */
3765                           while (*y && *y != ' ' && *y != '\t')
3766                             y++;
3767                         }
3768                     }
3769                   else if (*y == ' ' || *y == '\t')
3770                     /* Copy whitespace to the result.  */
3771                     *x++ = *y++;
3772                   /* Don't copy -A options  */
3773                   else
3774                     y++;
3775                 }
3776               *x++ = ' ';
3777
3778               /* Copy all of the -A options in CPP_PREDEFINES into BUF.  */
3779               y = cpp_predefines;
3780               while (*y != 0)
3781                 {
3782                   if (! strncmp (y, "-A", 2))
3783                     /* Copy the whole option.  */
3784                     while (*y && *y != ' ' && *y != '\t')
3785                       *x++ = *y++;
3786                   else if (*y == ' ' || *y == '\t')
3787                     /* Copy whitespace to the result.  */
3788                     *x++ = *y++;
3789                   /* Don't copy other options.  */
3790                   else
3791                     y++;
3792                 }
3793
3794               *x = 0;
3795
3796               value = do_spec_1 (buf, 0, NULL_PTR);
3797               if (value != 0)
3798                 return value;
3799             }
3800             break;
3801
3802           case 'S':
3803             value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3804             if (value != 0)
3805               return value;
3806             break;
3807
3808             /* Here we define characters other than letters and digits.  */
3809
3810           case '{':
3811             p = handle_braces (p);
3812             if (p == 0)
3813               return -1;
3814             break;
3815
3816           case '%':
3817             obstack_1grow (&obstack, '%');
3818             break;
3819
3820           case '*':
3821             do_spec_1 (soft_matched_part, 1, NULL_PTR);
3822             do_spec_1 (" ", 0, NULL_PTR);
3823             break;
3824
3825             /* Process a string found as the value of a spec given by name.
3826                This feature allows individual machine descriptions
3827                to add and use their own specs.
3828                %[...] modifies -D options the way %P does;
3829                %(...) uses the spec unmodified.  */
3830           case '(':
3831           case '[':
3832             {
3833               char *name = p;
3834               struct spec_list *sl;
3835               int len;
3836
3837               /* The string after the S/P is the name of a spec that is to be
3838                  processed.  */
3839               while (*p && *p != ')' && *p != ']')
3840                 p++;
3841
3842               /* See if it's in the list */
3843               for (len = p - name, sl = specs; sl; sl = sl->next)
3844                 if (sl->name_len == len && !strncmp (sl->name, name, len))
3845                   {
3846                     name = *(sl->ptr_spec);
3847 #ifdef DEBUG_SPECS
3848                     fprintf (stderr, "Processing spec %c%s%c, which is '%s'\n",
3849                              c, sl->name, (c == '(') ? ')' : ']', name);
3850 #endif
3851                     break;
3852                   }
3853
3854               if (sl)
3855                 {
3856                   if (c == '(')
3857                     {
3858                       value = do_spec_1 (name, 0, NULL_PTR);
3859                       if (value != 0)
3860                         return value;
3861                     }
3862                   else
3863                     {
3864                       char *x = (char *) alloca (strlen (name) * 2 + 1);
3865                       char *buf = x;
3866                       char *y = name;
3867                       int flag = 0;
3868
3869                       /* Copy all of NAME into BUF, but put __ after
3870                          every -D and at the end of each arg,  */
3871                       while (1)
3872                         {
3873                           if (! strncmp (y, "-D", 2))
3874                             {
3875                               *x++ = '-';
3876                               *x++ = 'D';
3877                               *x++ = '_';
3878                               *x++ = '_';
3879                               y += 2;
3880                               flag = 1;
3881                               continue;
3882                             }
3883                           else if (flag && (*y == ' ' || *y == '\t' || *y == '='
3884                                             || *y == '}' || *y == 0))
3885                             {
3886                               *x++ = '_';
3887                               *x++ = '_';
3888                               flag = 0;
3889                             }
3890                           if (*y == 0)
3891                             break;
3892                           else
3893                             *x++ = *y++;
3894                         }
3895                       *x = 0;
3896
3897                       value = do_spec_1 (buf, 0, NULL_PTR);
3898                       if (value != 0)
3899                         return value;
3900                     }
3901                 }
3902
3903               /* Discard the closing paren or bracket.  */
3904               if (*p)
3905                 p++;
3906             }
3907             break;
3908
3909           case 'v':
3910             {
3911               int c1 = *p++;  /* Select first or second version number.  */
3912               char *v = compiler_version;
3913               char *q;
3914
3915               /* The format of the version string is
3916                  ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?  */
3917
3918               /* Ignore leading non-digits.  i.e. "foo-" in "foo-2.7.2".  */
3919               while (! ISDIGIT (*v))
3920                 v++;
3921               if (v > compiler_version && v[-1] != '-')
3922                 abort ();
3923
3924               /* If desired, advance to second version number.  */
3925               if (c1 == '2')
3926                 {
3927                   /* Set V after the first period.  */
3928                   while (ISDIGIT (*v))
3929                     v++;
3930                   if (*v != '.')
3931                     abort ();
3932                   v++;
3933                 }
3934
3935               /* Set Q at the next period or at the end.  */
3936               q = v;
3937               while (ISDIGIT (*q))
3938                 q++;
3939               if (*q != 0 && *q != ' ' && *q != '.' && *q != '-')
3940                 abort ();
3941
3942               /* Put that part into the command.  */
3943               obstack_grow (&obstack, v, q - v);
3944               arg_going = 1;
3945             }
3946             break;
3947
3948           case '|':
3949             if (input_from_pipe)
3950               do_spec_1 ("-", 0, NULL_PTR);
3951             break;
3952
3953           default:
3954             abort ();
3955           }
3956         break;
3957
3958       case '\\':
3959         /* Backslash: treat next character as ordinary.  */
3960         c = *p++;
3961
3962         /* fall through */
3963       default:
3964         /* Ordinary character: put it into the current argument.  */
3965         obstack_1grow (&obstack, c);
3966         arg_going = 1;
3967       }
3968
3969   return 0;             /* End of string */
3970 }
3971
3972 /* Return 0 if we call do_spec_1 and that returns -1.  */
3973
3974 static char *
3975 handle_braces (p)
3976      register char *p;
3977 {
3978   register char *q;
3979   char *filter;
3980   int pipe_p = 0;
3981   int negate = 0;
3982   int suffix = 0;
3983   int include_blanks = 1;
3984
3985   if (*p == '^')
3986     /* A '^' after the open-brace means to not give blanks before args.  */
3987     include_blanks = 0, ++p;
3988
3989   if (*p == '|')
3990     /* A `|' after the open-brace means,
3991        if the test fails, output a single minus sign rather than nothing.
3992        This is used in %{|!pipe:...}.  */
3993     pipe_p = 1, ++p;
3994
3995   if (*p == '!')
3996     /* A `!' after the open-brace negates the condition:
3997        succeed if the specified switch is not present.  */
3998     negate = 1, ++p;
3999
4000   if (*p == '.')
4001     /* A `.' after the open-brace means test against the current suffix.  */
4002     {
4003       if (pipe_p)
4004         abort ();
4005
4006       suffix = 1;
4007       ++p;
4008     }
4009
4010   filter = p;
4011   while (*p != ':' && *p != '}') p++;
4012   if (*p != '}')
4013     {
4014       register int count = 1;
4015       q = p + 1;
4016       while (count > 0)
4017         {
4018           if (*q == '{')
4019             count++;
4020           else if (*q == '}')
4021             count--;
4022           else if (*q == 0)
4023             abort ();
4024           q++;
4025         }
4026     }
4027   else
4028     q = p + 1;
4029
4030   if (suffix)
4031     {
4032       int found = (input_suffix != 0
4033                    && strlen (input_suffix) == p - filter
4034                    && strncmp (input_suffix, filter, p - filter) == 0);
4035
4036       if (p[0] == '}')
4037         abort ();
4038
4039       if (negate != found
4040           && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4041         return 0;
4042
4043       return q;
4044     }
4045   else if (p[-1] == '*' && p[0] == '}')
4046     {
4047       /* Substitute all matching switches as separate args.  */
4048       register int i;
4049       --p;
4050       for (i = 0; i < n_switches; i++)
4051         if (!strncmp (switches[i].part1, filter, p - filter)
4052             && check_live_switch (i, p - filter))
4053           give_switch (i, 0, include_blanks);
4054     }
4055   else
4056     {
4057       /* Test for presence of the specified switch.  */
4058       register int i;
4059       int present = 0;
4060
4061       /* If name specified ends in *, as in {x*:...},
4062          check for %* and handle that case.  */
4063       if (p[-1] == '*' && !negate)
4064         {
4065           int substitution;
4066           char *r = p;
4067
4068           /* First see whether we have %*.  */
4069           substitution = 0;
4070           while (r < q)
4071             {
4072               if (*r == '%' && r[1] == '*')
4073                 substitution = 1;
4074               r++;
4075             }
4076           /* If we do, handle that case.  */
4077           if (substitution)
4078             {
4079               /* Substitute all matching switches as separate args.
4080                  But do this by substituting for %*
4081                  in the text that follows the colon.  */
4082
4083               unsigned hard_match_len = p - filter - 1;
4084               char *string = save_string (p + 1, q - p - 2);
4085
4086               for (i = 0; i < n_switches; i++)
4087                 if (!strncmp (switches[i].part1, filter, hard_match_len)
4088                     && check_live_switch (i, -1))
4089                   {
4090                     do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
4091                     /* Pass any arguments this switch has.  */
4092                     give_switch (i, 1, 1);
4093                   }
4094
4095               return q;
4096             }
4097         }
4098
4099       /* If name specified ends in *, as in {x*:...},
4100          check for presence of any switch name starting with x.  */
4101       if (p[-1] == '*')
4102         {
4103           for (i = 0; i < n_switches; i++)
4104             {
4105               unsigned hard_match_len = p - filter - 1;
4106
4107               if (!strncmp (switches[i].part1, filter, hard_match_len)
4108                   && check_live_switch (i, hard_match_len))
4109                 {
4110                   present = 1;
4111                 }
4112             }
4113         }
4114       /* Otherwise, check for presence of exact name specified.  */
4115       else
4116         {
4117           for (i = 0; i < n_switches; i++)
4118             {
4119               if (!strncmp (switches[i].part1, filter, p - filter)
4120                   && switches[i].part1[p - filter] == 0
4121                   && check_live_switch (i, -1))
4122                 {
4123                   present = 1;
4124                   break;
4125                 }
4126             }
4127         }
4128
4129       /* If it is as desired (present for %{s...}, absent for %{-s...})
4130          then substitute either the switch or the specified
4131          conditional text.  */
4132       if (present != negate)
4133         {
4134           if (*p == '}')
4135             {
4136               give_switch (i, 0, include_blanks);
4137             }
4138           else
4139             {
4140               if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4141                 return 0;
4142             }
4143         }
4144       else if (pipe_p)
4145         {
4146           /* Here if a %{|...} conditional fails: output a minus sign,
4147              which means "standard output" or "standard input".  */
4148           do_spec_1 ("-", 0, NULL_PTR);
4149         }
4150     }
4151
4152   return q;
4153 }
4154 \f
4155 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4156    on the command line.  PREFIX_LENGTH is the length of XXX in an {XXX*}
4157    spec, or -1 if either exact match or %* is used.
4158
4159    A -O switch is obsoleted by a later -O switch.  A -f, -m, or -W switch
4160    whose value does not begin with "no-" is obsoleted by the same value
4161    with the "no-", similarly for a switch with the "no-" prefix.  */
4162
4163 static int
4164 check_live_switch (switchnum, prefix_length)
4165      int switchnum;
4166      int prefix_length;
4167 {
4168   char *name = switches[switchnum].part1;
4169   int i;
4170
4171   /* In the common case of {<at-most-one-letter>*}, a negating
4172      switch would always match, so ignore that case.  We will just
4173      send the conflicting switches to the compiler phase.  */
4174   if (prefix_length >= 0 && prefix_length <= 1)
4175     return 1;
4176
4177   /* If we already processed this switch and determined if it was
4178      live or not, return our past determination.  */
4179   if (switches[switchnum].live_cond != 0)
4180     return switches[switchnum].live_cond > 0;
4181
4182   /* Now search for duplicate in a manner that depends on the name.  */
4183   switch (*name)
4184     {
4185     case 'O':
4186         for (i = switchnum + 1; i < n_switches; i++)
4187           if (switches[i].part1[0] == 'O')
4188             {
4189               switches[switchnum].valid = 1;
4190               switches[switchnum].live_cond = -1;
4191               return 0;
4192             }
4193       break;
4194
4195     case 'W':  case 'f':  case 'm':
4196       if (! strncmp (name + 1, "no-", 3))
4197         {
4198           /* We have Xno-YYY, search for XYYY.  */
4199           for (i = switchnum + 1; i < n_switches; i++)
4200             if (switches[i].part1[0] == name[0]
4201                 && ! strcmp (&switches[i].part1[1], &name[4]))
4202             {
4203               switches[switchnum].valid = 1;
4204               switches[switchnum].live_cond = -1;
4205               return 0;
4206             }
4207         }
4208       else
4209         {
4210           /* We have XYYY, search for Xno-YYY.  */
4211           for (i = switchnum + 1; i < n_switches; i++)
4212             if (switches[i].part1[0] == name[0]
4213                 && switches[i].part1[1] == 'n'
4214                 && switches[i].part1[2] == 'o'
4215                 && switches[i].part1[3] == '-'
4216                 && !strcmp (&switches[i].part1[4], &name[1]))
4217             {
4218               switches[switchnum].valid = 1;
4219               switches[switchnum].live_cond = -1;
4220               return 0;
4221             }
4222         }
4223       break;
4224     }
4225
4226   /* Otherwise the switch is live.  */
4227   switches[switchnum].live_cond = 1;
4228   return 1;
4229 }
4230 \f
4231 /* Pass a switch to the current accumulating command
4232    in the same form that we received it.
4233    SWITCHNUM identifies the switch; it is an index into
4234    the vector of switches gcc received, which is `switches'.
4235    This cannot fail since it never finishes a command line.
4236
4237    If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
4238
4239    If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
4240    of the switch.  */
4241
4242 static void
4243 give_switch (switchnum, omit_first_word, include_blanks)
4244      int switchnum;
4245      int omit_first_word;
4246      int include_blanks;
4247 {
4248   if (!omit_first_word)
4249     {
4250       do_spec_1 ("-", 0, NULL_PTR);
4251       do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4252     }
4253
4254   if (switches[switchnum].args != 0)
4255     {
4256       char **p;
4257       for (p = switches[switchnum].args; *p; p++)
4258         {
4259           if (include_blanks)
4260             do_spec_1 (" ", 0, NULL_PTR);
4261           do_spec_1 (*p, 1, NULL_PTR);
4262         }
4263     }
4264
4265   do_spec_1 (" ", 0, NULL_PTR);
4266   switches[switchnum].valid = 1;
4267 }
4268 \f
4269 /* Search for a file named NAME trying various prefixes including the
4270    user's -B prefix and some standard ones.
4271    Return the absolute file name found.  If nothing is found, return NAME.  */
4272
4273 static char *
4274 find_file (name)
4275      char *name;
4276 {
4277   char *newname;
4278
4279   /* Try multilib_dir if it is defined.  */
4280   if (multilib_dir != NULL)
4281     {
4282       char *try;
4283
4284       try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4285       strcpy (try, multilib_dir);
4286       strcat (try, dir_separator_str);
4287       strcat (try, name);
4288
4289       newname = find_a_file (&startfile_prefixes, try, R_OK);
4290
4291       /* If we don't find it in the multi library dir, then fall
4292          through and look for it in the normal places.  */
4293       if (newname != NULL)
4294         return newname;
4295     }
4296
4297   newname = find_a_file (&startfile_prefixes, name, R_OK);
4298   return newname ? newname : name;
4299 }
4300
4301 /* Determine whether a directory exists.  If LINKER, return 0 for
4302    certain fixed names not needed by the linker.  If not LINKER, it is
4303    only important to return 0 if the host machine has a small ARG_MAX
4304    limit.  */
4305
4306 static int
4307 is_directory (path1, path2, linker)
4308      char *path1;
4309      char *path2;
4310      int linker;
4311 {
4312   int len1 = strlen (path1);
4313   int len2 = strlen (path2);
4314   char *path = (char *) alloca (3 + len1 + len2);
4315   char *cp;
4316   struct stat st;
4317
4318 #ifndef SMALL_ARG_MAX
4319   if (! linker)
4320     return 1;
4321 #endif
4322
4323   /* Construct the path from the two parts.  Ensure the string ends with "/.".
4324      The resulting path will be a directory even if the given path is a
4325      symbolic link.  */
4326   bcopy (path1, path, len1);
4327   bcopy (path2, path + len1, len2);
4328   cp = path + len1 + len2;
4329   if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4330     *cp++ = DIR_SEPARATOR;
4331   *cp++ = '.';
4332   *cp = '\0';
4333
4334   /* Exclude directories that the linker is known to search.  */
4335   if (linker
4336       && ((cp - path == 6
4337            && strcmp (path, concat (dir_separator_str, "lib", 
4338                                     dir_separator_str, ".", NULL_PTR)) == 0)
4339           || (cp - path == 10
4340               && strcmp (path, concat (dir_separator_str, "usr", 
4341                                        dir_separator_str, "lib", 
4342                                        dir_separator_str, ".", NULL_PTR)) == 0)))
4343     return 0;
4344
4345   return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4346 }
4347 \f
4348 /* On fatal signals, delete all the temporary files.  */
4349
4350 static void
4351 fatal_error (signum)
4352      int signum;
4353 {
4354   signal (signum, SIG_DFL);
4355   delete_failure_queue ();
4356   delete_temp_files ();
4357   /* Get the same signal again, this time not handled,
4358      so its normal effect occurs.  */
4359   kill (getpid (), signum);
4360 }
4361
4362 int
4363 main (argc, argv)
4364      int argc;
4365      char **argv;
4366 {
4367   register size_t i;
4368   size_t j;
4369   int value;
4370   int linker_was_run = 0;
4371   char *explicit_link_files;
4372   char *specs_file;
4373   char *p;
4374   struct user_specs *uptr;
4375
4376   p = argv[0] + strlen (argv[0]);
4377   while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4378   programname = p;
4379
4380   if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4381     signal (SIGINT, fatal_error);
4382 #ifdef SIGHUP
4383   if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4384     signal (SIGHUP, fatal_error);
4385 #endif
4386   if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4387     signal (SIGTERM, fatal_error);
4388 #ifdef SIGPIPE
4389   if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4390     signal (SIGPIPE, fatal_error);
4391 #endif
4392
4393   argbuf_length = 10;
4394   argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4395
4396   obstack_init (&obstack);
4397
4398   /* Build multilib_select, et. al from the separate lines that make up each
4399      multilib selection.  */
4400   {
4401     char **q = multilib_raw;
4402     int need_space;
4403
4404     obstack_init (&multilib_obstack);
4405     while ((p = *q++) != (char *) 0)
4406       obstack_grow (&multilib_obstack, p, strlen (p));
4407
4408     obstack_1grow (&multilib_obstack, 0);
4409     multilib_select = obstack_finish (&multilib_obstack);
4410
4411     q = multilib_matches_raw;
4412     while ((p = *q++) != (char *) 0)
4413       obstack_grow (&multilib_obstack, p, strlen (p));
4414
4415     obstack_1grow (&multilib_obstack, 0);
4416     multilib_matches = obstack_finish (&multilib_obstack);
4417
4418     need_space = FALSE;
4419     for (i = 0;
4420          i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]);
4421          i++)
4422       {
4423         if (need_space)
4424           obstack_1grow (&multilib_obstack, ' ');
4425         obstack_grow (&multilib_obstack,
4426                       multilib_defaults_raw[i],
4427                       strlen (multilib_defaults_raw[i]));
4428         need_space = TRUE;
4429       }
4430
4431     obstack_1grow (&multilib_obstack, 0);
4432     multilib_defaults = obstack_finish (&multilib_obstack);
4433   }
4434
4435   /* Set up to remember the pathname of gcc and any options
4436      needed for collect.  We use argv[0] instead of programname because
4437      we need the complete pathname.  */
4438   obstack_init (&collect_obstack);
4439   obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4440   obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4441   putenv (obstack_finish (&collect_obstack));
4442
4443 #ifdef INIT_ENVIRONMENT
4444   /* Set up any other necessary machine specific environment variables.  */
4445   putenv (INIT_ENVIRONMENT);
4446 #endif
4447
4448   /* Choose directory for temp files.  */
4449
4450   temp_filename = choose_temp_base ();
4451   temp_filename_length = strlen (temp_filename);
4452
4453   /* Make a table of what switches there are (switches, n_switches).
4454      Make a table of specified input files (infiles, n_infiles).
4455      Decode switches that are handled locally.  */
4456
4457   process_command (argc, argv);
4458
4459   {
4460     int first_time;
4461
4462     /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4463        the compiler.  */
4464     obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4465                   sizeof ("COLLECT_GCC_OPTIONS=")-1);
4466
4467     first_time = TRUE;
4468     for (i = 0; i < n_switches; i++)
4469       {
4470         char **args;
4471         char *p, *q;
4472         if (!first_time)
4473           obstack_grow (&collect_obstack, " ", 1);
4474
4475         first_time = FALSE;
4476         obstack_grow (&collect_obstack, "'-", 2);
4477         q = switches[i].part1;
4478         while ((p = index (q,'\'')))
4479           {
4480             obstack_grow (&collect_obstack, q, p-q);
4481             obstack_grow (&collect_obstack, "'\\''", 4);
4482             q = ++p;
4483           }
4484         obstack_grow (&collect_obstack, q, strlen (q));
4485         obstack_grow (&collect_obstack, "'", 1);
4486
4487         for (args = switches[i].args; args && *args; args++)
4488           {
4489             obstack_grow (&collect_obstack, " '", 2);
4490             q = *args;
4491             while ((p = index (q,'\'')))
4492               {
4493                 obstack_grow (&collect_obstack, q, p-q);
4494                 obstack_grow (&collect_obstack, "'\\''", 4);
4495                 q = ++p;
4496               }
4497             obstack_grow (&collect_obstack, q, strlen (q));
4498             obstack_grow (&collect_obstack, "'", 1);
4499           }
4500       }
4501     obstack_grow (&collect_obstack, "\0", 1);
4502     putenv (obstack_finish (&collect_obstack));
4503   }
4504
4505   /* Initialize the vector of specs to just the default.
4506      This means one element containing 0s, as a terminator.  */
4507
4508   compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4509   bcopy ((char *) default_compilers, (char *) compilers,
4510          sizeof default_compilers);
4511   n_compilers = n_default_compilers;
4512
4513   /* Read specs from a file if there is one.  */
4514
4515   machine_suffix = concat (spec_machine, dir_separator_str,
4516                            spec_version, dir_separator_str, NULL_PTR);
4517   just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR);
4518
4519   specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4520   /* Read the specs file unless it is a default one.  */
4521   if (specs_file != 0 && strcmp (specs_file, "specs"))
4522     read_specs (specs_file, TRUE);
4523   else
4524     init_spec ();
4525
4526   /* We need to check standard_exec_prefix/just_machine_suffix/specs
4527      for any override of as, ld and libraries. */
4528   specs_file = (char *) alloca (strlen (standard_exec_prefix)
4529                                 + strlen (just_machine_suffix)
4530                                 + sizeof ("specs"));
4531
4532   strcpy (specs_file, standard_exec_prefix);
4533   strcat (specs_file, just_machine_suffix);
4534   strcat (specs_file, "specs");
4535   if (access (specs_file, R_OK) == 0)
4536     read_specs (specs_file, TRUE);
4537  
4538   /* Process any user specified specs in the order given on the command
4539      line.  */
4540   for (uptr = user_specs_head; uptr; uptr = uptr->next)
4541     {
4542       char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
4543       read_specs (filename ? filename : uptr->filename, FALSE);
4544     }
4545
4546   /* If not cross-compiling, look for startfiles in the standard places.  */
4547   /* The fact that these are done here, after reading the specs file,
4548      means that it cannot be found in these directories.
4549      But that's okay.  It should never be there anyway.  */
4550   if (*cross_compile == '0')
4551     {
4552 #ifdef MD_EXEC_PREFIX
4553       add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4554       add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
4555 #endif
4556
4557 #ifdef MD_STARTFILE_PREFIX
4558       add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
4559                   0, 0, NULL_PTR);
4560 #endif
4561
4562 #ifdef MD_STARTFILE_PREFIX_1
4563       add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
4564                   0, 0, NULL_PTR);
4565 #endif
4566
4567       /* If standard_startfile_prefix is relative, base it on
4568          standard_exec_prefix.  This lets us move the installed tree
4569          as a unit.  If GCC_EXEC_PREFIX is defined, base
4570          standard_startfile_prefix on that as well.  */
4571       if (*standard_startfile_prefix == '/'
4572           || *standard_startfile_prefix == DIR_SEPARATOR
4573           || *standard_startfile_prefix == '$'
4574 #ifdef __MSDOS__
4575           /* Check for disk name on MS-DOS-based systems.  */
4576           || (standard_startfile_prefix[1] == ':'
4577               && (standard_startfile_prefix[2] == DIR_SEPARATOR
4578                   || standard_startfile_prefix[2] == '/'))
4579 #endif
4580           )
4581         add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
4582                     0, 0, NULL_PTR);
4583       else
4584         {
4585           if (gcc_exec_prefix)
4586             add_prefix (&startfile_prefixes,
4587                         concat (gcc_exec_prefix, machine_suffix,
4588                                 standard_startfile_prefix, NULL_PTR),
4589                         NULL_PTR, 0, 0, NULL_PTR);
4590           add_prefix (&startfile_prefixes,
4591                       concat (standard_exec_prefix,
4592                               machine_suffix,
4593                               standard_startfile_prefix, NULL_PTR),
4594                       NULL_PTR, 0, 0, NULL_PTR);
4595         }                      
4596
4597       add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
4598                   "BINUTILS", 0, 0, NULL_PTR);
4599       add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
4600                   "BINUTILS", 0, 0, NULL_PTR);
4601 #if 0 /* Can cause surprises, and one can use -B./ instead.  */
4602       add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR);
4603 #endif
4604     }
4605   else
4606     {
4607       if (*standard_startfile_prefix != DIR_SEPARATOR && gcc_exec_prefix)
4608         add_prefix (&startfile_prefixes,
4609                     concat (gcc_exec_prefix, machine_suffix,
4610                             standard_startfile_prefix, NULL_PTR),
4611                     "BINUTILS", 0, 0, NULL_PTR);
4612     }
4613
4614   /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake.  */
4615   if (gcc_exec_prefix)
4616     {
4617       char * temp = (char *) xmalloc (strlen (gcc_exec_prefix)
4618                                       + strlen (spec_version)
4619                                       + strlen (spec_machine) + 3);
4620       strcpy (temp, gcc_exec_prefix);
4621       strcat (temp, spec_machine);
4622       strcat (temp, dir_separator_str);
4623       strcat (temp, spec_version);
4624       strcat (temp, dir_separator_str);
4625       gcc_exec_prefix = temp;
4626     }
4627
4628   /* Now we have the specs.
4629      Set the `valid' bits for switches that match anything in any spec.  */
4630
4631   validate_all_switches ();
4632
4633   /* Now that we have the switches and the specs, set
4634      the subdirectory based on the options.  */
4635   set_multilib_dir ();
4636
4637   /* Warn about any switches that no pass was interested in.  */
4638
4639   for (i = 0; i < n_switches; i++)
4640     if (! switches[i].valid)
4641       error ("unrecognized option `-%s'", switches[i].part1);
4642
4643   /* Obey some of the options.  */
4644
4645   if (print_search_dirs)
4646     {
4647       printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
4648       printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
4649       printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
4650       exit (0);
4651     }
4652
4653   if (print_file_name)
4654     {
4655       printf ("%s\n", find_file (print_file_name));
4656       exit (0);
4657     }
4658
4659   if (print_prog_name)
4660     {
4661       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4662       printf ("%s\n", (newname ? newname : print_prog_name));
4663       exit (0);
4664     }
4665
4666   if (print_multi_lib)
4667     {
4668       print_multilib_info ();
4669       exit (0);
4670     }
4671
4672   if (print_multi_directory)
4673     {
4674       if (multilib_dir == NULL)
4675         printf (".\n");
4676       else
4677         printf ("%s\n", multilib_dir);
4678       exit (0);
4679     }
4680
4681   if (verbose_flag)
4682     {
4683       int n;
4684
4685       /* compiler_version is truncated at the first space when initialized
4686          from version string, so truncate version_string at the first space
4687          before comparing.  */
4688       for (n = 0; version_string[n]; n++)
4689         if (version_string[n] == ' ')
4690           break;
4691
4692       if (! strncmp (version_string, compiler_version, n)
4693           && compiler_version[n] == 0)
4694         fprintf (stderr, "gcc version %s\n", version_string);
4695       else
4696         fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4697                  version_string, compiler_version);
4698
4699       if (n_infiles == 0)
4700         exit (0);
4701     }
4702
4703   if (n_infiles == added_libraries)
4704     fatal ("No input files");
4705
4706   /* Make a place to record the compiler output file names
4707      that correspond to the input files.  */
4708
4709   outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4710   bzero ((char *) outfiles, n_infiles * sizeof (char *));
4711
4712   /* Record which files were specified explicitly as link input.  */
4713
4714   explicit_link_files = xmalloc (n_infiles);
4715   bzero (explicit_link_files, n_infiles);
4716
4717   for (i = 0; i < n_infiles; i++)
4718     {
4719       register struct compiler *cp = 0;
4720       int this_file_error = 0;
4721
4722       /* Tell do_spec what to substitute for %i.  */
4723
4724       input_filename = infiles[i].name;
4725       input_filename_length = strlen (input_filename);
4726       input_file_number = i;
4727
4728       /* Use the same thing in %o, unless cp->spec says otherwise.  */
4729
4730       outfiles[i] = input_filename;
4731
4732       /* Figure out which compiler from the file's suffix.  */
4733
4734       cp = lookup_compiler (infiles[i].name, input_filename_length,
4735                             infiles[i].language);
4736
4737       if (cp)
4738         {
4739           /* Ok, we found an applicable compiler.  Run its spec.  */
4740           /* First say how much of input_filename to substitute for %b  */
4741           register char *p;
4742           int len;
4743
4744           if (cp->spec[0][0] == '#')
4745             error ("%s: %s compiler not installed on this system",
4746                    input_filename, &cp->spec[0][1]);
4747
4748           input_basename = input_filename;
4749           for (p = input_filename; *p; p++)
4750             if (*p == '/' || *p == DIR_SEPARATOR)
4751               input_basename = p + 1;
4752
4753           /* Find a suffix starting with the last period,
4754              and set basename_length to exclude that suffix.  */
4755           basename_length = strlen (input_basename);
4756           p = input_basename + basename_length;
4757           while (p != input_basename && *p != '.') --p;
4758           if (*p == '.' && p != input_basename)
4759             {
4760               basename_length = p - input_basename;
4761               input_suffix = p + 1;
4762             }
4763           else
4764             input_suffix = "";
4765
4766           len = 0;
4767           for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4768             if (cp->spec[j])
4769               len += strlen (cp->spec[j]);
4770
4771           p = (char *) xmalloc (len + 1);
4772
4773           len = 0;
4774           for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4775             if (cp->spec[j])
4776               {
4777                 strcpy (p + len, cp->spec[j]);
4778                 len += strlen (cp->spec[j]);
4779               }
4780
4781           value = do_spec (p);
4782           free (p);
4783           if (value < 0)
4784             this_file_error = 1;
4785         }
4786
4787       /* If this file's name does not contain a recognized suffix,
4788          record it as explicit linker input.  */
4789
4790       else
4791         explicit_link_files[i] = 1;
4792
4793       /* Clear the delete-on-failure queue, deleting the files in it
4794          if this compilation failed.  */
4795
4796       if (this_file_error)
4797         {
4798           delete_failure_queue ();
4799           error_count++;
4800         }
4801       /* If this compilation succeeded, don't delete those files later.  */
4802       clear_failure_queue ();
4803     }
4804
4805   /* Run ld to link all the compiler output files.  */
4806
4807   if (error_count == 0)
4808     {
4809       int tmp = execution_count;
4810
4811       /* We'll use ld if we can't find collect2. */
4812       if (! strcmp (linker_name_spec, "collect2"))
4813         {
4814           char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
4815           if (s == NULL)
4816             linker_name_spec = "ld";
4817         }
4818       /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4819          for collect.  */
4820       putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4821       putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4822
4823       value = do_spec (link_command_spec);
4824       if (value < 0)
4825         error_count = 1;
4826       linker_was_run = (tmp != execution_count);
4827     }
4828
4829   /* Warn if a -B option was specified but the prefix was never used.  */
4830   unused_prefix_warnings (&exec_prefixes);
4831   unused_prefix_warnings (&startfile_prefixes);
4832
4833   /* If options said don't run linker,
4834      complain about input files to be given to the linker.  */
4835
4836   if (! linker_was_run && error_count == 0)
4837     for (i = 0; i < n_infiles; i++)
4838       if (explicit_link_files[i])
4839         error ("%s: linker input file unused since linking not done",
4840                outfiles[i]);
4841
4842   /* Delete some or all of the temporary files we made.  */
4843
4844   if (error_count)
4845     delete_failure_queue ();
4846   delete_temp_files ();
4847
4848   exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4849   /* NOTREACHED */
4850   return 0;
4851 }
4852
4853 /* Find the proper compilation spec for the file name NAME,
4854    whose length is LENGTH.  LANGUAGE is the specified language,
4855    or 0 if this file is to be passed to the linker.  */
4856
4857 static struct compiler *
4858 lookup_compiler (name, length, language)
4859      char *name;
4860      size_t length;
4861      char *language;
4862 {
4863   struct compiler *cp;
4864
4865   /* If this was specified by the user to be a linker input, indicate that. */
4866   if (language != 0 && language[0] == '*')
4867     return 0;
4868
4869   /* Otherwise, look for the language, if one is spec'd.  */
4870   if (language != 0)
4871     {
4872       for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4873         if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
4874           return cp;
4875
4876       error ("language %s not recognized", language);
4877       return 0;
4878     }
4879
4880   /* Look for a suffix.  */
4881   for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4882     {
4883       if (/* The suffix `-' matches only the file name `-'.  */
4884           (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4885           || (strlen (cp->suffix) < length
4886               /* See if the suffix matches the end of NAME.  */
4887 #ifdef OS2
4888               && ((!strcmp (cp->suffix,
4889                            name + length - strlen (cp->suffix))
4890                    || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
4891                   && !strcasecmp (cp->suffix,
4892                                   name + length - strlen (cp->suffix)))
4893 #else
4894               && !strcmp (cp->suffix,
4895                           name + length - strlen (cp->suffix))
4896 #endif
4897          ))
4898         {
4899           if (cp->spec[0][0] == '@')
4900             {
4901               struct compiler *new;
4902
4903               /* An alias entry maps a suffix to a language.
4904                  Search for the language; pass 0 for NAME and LENGTH
4905                  to avoid infinite recursion if language not found.
4906                  Construct the new compiler spec.  */
4907               language = cp->spec[0] + 1;
4908               new = (struct compiler *) xmalloc (sizeof (struct compiler));
4909               new->suffix = cp->suffix;
4910               bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4911                      (char *) new->spec, sizeof new->spec);
4912               return new;
4913             }
4914
4915           /* A non-alias entry: return it.  */
4916           return cp;
4917         }
4918     }
4919
4920   return 0;
4921 }
4922 \f
4923 char *
4924 xmalloc (size)
4925      unsigned size;
4926 {
4927   register char *value = (char *) malloc (size);
4928   if (value == 0)
4929     fatal ("virtual memory exhausted");
4930   return value;
4931 }
4932
4933 char *
4934 xrealloc (ptr, size)
4935      char *ptr;
4936      unsigned size;
4937 {
4938   register char *value = (char *) realloc (ptr, size);
4939   if (value == 0)
4940     fatal ("virtual memory exhausted");
4941   return value;
4942 }
4943
4944 /* This function is based on the one in libiberty.  */
4945
4946 static char *
4947 concat VPROTO((char *first, ...))
4948 {
4949   register int length;
4950   register char *newstr;
4951   register char *end;
4952   register char *arg;
4953   va_list args;
4954 #ifndef __STDC__
4955   char *first;
4956 #endif
4957
4958   /* First compute the size of the result and get sufficient memory.  */
4959
4960   VA_START (args, first);
4961 #ifndef __STDC__
4962   first = va_arg (args, char *);
4963 #endif
4964
4965   arg = first;
4966   length = 0;
4967
4968   while (arg != 0)
4969     {
4970       length += strlen (arg);
4971       arg = va_arg (args, char *);
4972     }
4973
4974   newstr = (char *) xmalloc (length + 1);
4975   va_end (args);
4976
4977   /* Now copy the individual pieces to the result string.  */
4978
4979   VA_START (args, first);
4980 #ifndef __STDC__
4981   first = va_arg (args, char *);
4982 #endif
4983
4984   end = newstr;
4985   arg = first;
4986   while (arg != 0)
4987     {
4988       while (*arg)
4989         *end++ = *arg++;
4990       arg = va_arg (args, char *);
4991     }
4992   *end = '\000';
4993   va_end (args);
4994
4995   return (newstr);
4996 }
4997
4998 static char *
4999 save_string (s, len)
5000      char *s;
5001      int len;
5002 {
5003   register char *result = xmalloc (len + 1);
5004
5005   bcopy (s, result, len);
5006   result[len] = 0;
5007   return result;
5008 }
5009
5010 static void
5011 pfatal_with_name (name)
5012      char *name;
5013 {
5014   fatal ("%s: %s", name, my_strerror (errno));
5015 }
5016
5017 static void
5018 perror_with_name (name)
5019      char *name;
5020 {
5021   error ("%s: %s", name, my_strerror (errno));
5022 }
5023
5024 static void
5025 pfatal_pexecute (errmsg_fmt, errmsg_arg)
5026      char *errmsg_fmt;
5027      char *errmsg_arg;
5028 {
5029   int save_errno = errno;
5030
5031   if (errmsg_arg)
5032     {
5033       /* Space for trailing '\0' is in %s.  */
5034       char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
5035       sprintf (msg, errmsg_fmt, errmsg_arg);
5036       errmsg_fmt = msg;
5037     }
5038
5039   fatal ("%s: %s", errmsg_fmt, my_strerror (save_errno));
5040 }
5041
5042 /* More 'friendly' abort that prints the line and file.
5043    config.h can #define abort fancy_abort if you like that sort of thing.  */
5044
5045 void
5046 fancy_abort ()
5047 {
5048   fatal ("Internal gcc abort.");
5049 }
5050 \f
5051 #ifdef HAVE_VPRINTF
5052
5053 /* Output an error message and exit */
5054
5055 static void
5056 fatal VPROTO((char *format, ...))
5057 {
5058 #ifndef __STDC__
5059   char *format;
5060 #endif
5061   va_list ap;
5062
5063   VA_START (ap, format);
5064
5065 #ifndef __STDC__
5066   format = va_arg (ap, char *);
5067 #endif
5068
5069   fprintf (stderr, "%s: ", programname);
5070   vfprintf (stderr, format, ap);
5071   va_end (ap);
5072   fprintf (stderr, "\n");
5073   delete_temp_files ();
5074   exit (1);
5075 }
5076
5077 static void
5078 error VPROTO((char *format, ...))
5079 {
5080 #ifndef __STDC__
5081   char *format;
5082 #endif
5083   va_list ap;
5084
5085   VA_START (ap, format);
5086
5087 #ifndef __STDC__
5088   format = va_arg (ap, char *);
5089 #endif
5090
5091   fprintf (stderr, "%s: ", programname);
5092   vfprintf (stderr, format, ap);
5093   va_end (ap);
5094
5095   fprintf (stderr, "\n");
5096 }
5097
5098 #else /* not HAVE_VPRINTF */
5099
5100 static void
5101 fatal (msg, arg1, arg2)
5102      char *msg, *arg1, *arg2;
5103 {
5104   error (msg, arg1, arg2);
5105   delete_temp_files ();
5106   exit (1);
5107 }
5108
5109 static void
5110 error (msg, arg1, arg2)
5111      char *msg, *arg1, *arg2;
5112 {
5113   fprintf (stderr, "%s: ", programname);
5114   fprintf (stderr, msg, arg1, arg2);
5115   fprintf (stderr, "\n");
5116 }
5117
5118 #endif /* not HAVE_VPRINTF */
5119
5120 \f
5121 static void
5122 validate_all_switches ()
5123 {
5124   struct compiler *comp;
5125   register char *p;
5126   register char c;
5127   struct spec_list *spec;
5128
5129   for (comp = compilers; comp->spec[0]; comp++)
5130     {
5131       size_t i;
5132       for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
5133         {
5134           p = comp->spec[i];
5135           while ((c = *p++))
5136             if (c == '%' && *p == '{')
5137               /* We have a switch spec.  */
5138               validate_switches (p + 1);
5139         }
5140     }
5141
5142   /* look through the linked list of specs read from the specs file */
5143   for (spec = specs; spec ; spec = spec->next)
5144     {
5145       p = *(spec->ptr_spec);
5146       while ((c = *p++))
5147         if (c == '%' && *p == '{')
5148           /* We have a switch spec.  */
5149           validate_switches (p + 1);
5150     }
5151
5152   p = link_command_spec;
5153   while ((c = *p++))
5154     if (c == '%' && *p == '{')
5155       /* We have a switch spec.  */
5156       validate_switches (p + 1);
5157 }
5158
5159 /* Look at the switch-name that comes after START
5160    and mark as valid all supplied switches that match it.  */
5161
5162 static void
5163 validate_switches (start)
5164      char *start;
5165 {
5166   register char *p = start;
5167   char *filter;
5168   register int i;
5169   int suffix = 0;
5170
5171   if (*p == '|')
5172     ++p;
5173
5174   if (*p == '!')
5175     ++p;
5176
5177   if (*p == '.')
5178     suffix = 1, ++p;
5179
5180   filter = p;
5181   while (*p != ':' && *p != '}') p++;
5182
5183   if (suffix)
5184     ;
5185   else if (p[-1] == '*')
5186     {
5187       /* Mark all matching switches as valid.  */
5188       --p;
5189       for (i = 0; i < n_switches; i++)
5190         if (!strncmp (switches[i].part1, filter, p - filter))
5191           switches[i].valid = 1;
5192     }
5193   else
5194     {
5195       /* Mark an exact matching switch as valid.  */
5196       for (i = 0; i < n_switches; i++)
5197         {
5198           if (!strncmp (switches[i].part1, filter, p - filter)
5199               && switches[i].part1[p - filter] == 0)
5200             switches[i].valid = 1;
5201         }
5202     }
5203 }
5204 \f
5205 /* Check whether a particular argument was used.  The first time we
5206    canonicalize the switches to keep only the ones we care about.  */
5207
5208 static int
5209 used_arg (p, len)
5210      char *p;
5211      int len;
5212 {
5213   struct mswitchstr {
5214     char *str;
5215     char *replace;
5216     int len;
5217     int rep_len;
5218   };
5219
5220   static struct mswitchstr *mswitches;
5221   static int n_mswitches;
5222   int i, j;
5223
5224   if (!mswitches)
5225     {
5226       struct mswitchstr *matches;
5227       char *q;
5228       int cnt = 0;
5229
5230       /* Break multilib_matches into the component strings of string and replacement
5231          string */
5232       for (q = multilib_matches; *q != '\0'; q++)
5233         if (*q == ';')
5234           cnt++;
5235
5236       matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
5237       i = 0;
5238       q = multilib_matches;
5239       while (*q != '\0')
5240         {
5241           matches[i].str = q;
5242           while (*q != ' ')
5243             {
5244               if (*q == '\0')
5245                 abort ();
5246               q++;
5247             }
5248           *q = '\0';
5249           matches[i].len = q - matches[i].str;
5250
5251           matches[i].replace = ++q;
5252           while (*q != ';' && *q != '\0')
5253             {
5254               if (*q == ' ')
5255                 abort ();
5256               q++;
5257             }
5258           matches[i].rep_len = q - matches[i].replace;
5259           i++;
5260           if (*q == ';')
5261             *q++ = '\0';
5262           else
5263             break;
5264         }
5265
5266       /* Now build a list of the replacement string for switches that we care
5267          about.  Make sure we allocate at least one entry.  This prevents
5268          xmalloc from calling fatal, and prevents us from re-executing this
5269          block of code.  */
5270       mswitches
5271         = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
5272                                          * (n_switches ? n_switches : 1));
5273       for (i = 0; i < n_switches; i++)
5274         {
5275           int xlen = strlen (switches[i].part1);
5276           for (j = 0; j < cnt; j++)
5277             if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str))
5278               {
5279                 mswitches[n_mswitches].str = matches[j].replace;
5280                 mswitches[n_mswitches].len = matches[j].rep_len;
5281                 mswitches[n_mswitches].replace = (char *)0;
5282                 mswitches[n_mswitches].rep_len = 0;
5283                 n_mswitches++;
5284                 break;
5285               }
5286         }
5287     }
5288
5289   for (i = 0; i < n_mswitches; i++)
5290     if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
5291       return 1;
5292
5293   return 0;
5294 }
5295
5296 static int
5297 default_arg (p, len)
5298      char *p;
5299      int len;
5300 {
5301   char *start, *end;
5302
5303   for (start = multilib_defaults; *start != '\0'; start = end+1)
5304     {
5305       while (*start == ' ' || *start == '\t')
5306         start++;
5307
5308       if (*start == '\0')
5309         break;
5310
5311       for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
5312         ;
5313
5314       if ((end - start) == len && strncmp (p, start, len) == 0)
5315         return 1;
5316
5317       if (*end == '\0')
5318         break;
5319     }
5320
5321   return 0;
5322 }
5323
5324 /* Work out the subdirectory to use based on the
5325    options.  The format of multilib_select is a list of elements.
5326    Each element is a subdirectory name followed by a list of options
5327    followed by a semicolon.  gcc will consider each line in turn.  If
5328    none of the options beginning with an exclamation point are
5329    present, and all of the other options are present, that
5330    subdirectory will be used.  */
5331
5332 static void
5333 set_multilib_dir ()
5334 {
5335   char *p = multilib_select;
5336   int this_path_len;
5337   char *this_path, *this_arg;
5338   int not_arg;
5339   int ok;
5340
5341   while (*p != '\0')
5342     {
5343       /* Ignore newlines.  */
5344       if (*p == '\n')
5345         {
5346           ++p;
5347           continue;
5348         }
5349
5350       /* Get the initial path.  */
5351       this_path = p;
5352       while (*p != ' ')
5353         {
5354           if (*p == '\0')
5355             abort ();
5356           ++p;
5357         }
5358       this_path_len = p - this_path;
5359
5360       /* Check the arguments.  */
5361       ok = 1;
5362       ++p;
5363       while (*p != ';')
5364         {
5365           if (*p == '\0')
5366             abort ();
5367
5368           if (! ok)
5369             {
5370               ++p;
5371               continue;
5372             }
5373
5374           this_arg = p;
5375           while (*p != ' ' && *p != ';')
5376             {
5377               if (*p == '\0')
5378                 abort ();
5379               ++p;
5380             }
5381
5382           if (*this_arg != '!')
5383             not_arg = 0;
5384           else
5385             {
5386               not_arg = 1;
5387               ++this_arg;
5388             }
5389
5390           /* If this is a default argument, we can just ignore it.
5391              This is true even if this_arg begins with '!'.  Beginning
5392              with '!' does not mean that this argument is necessarily
5393              inappropriate for this library: it merely means that
5394              there is a more specific library which uses this
5395              argument.  If this argument is a default, we need not
5396              consider that more specific library.  */
5397           if (! default_arg (this_arg, p - this_arg))
5398             {
5399               ok = used_arg (this_arg, p - this_arg);
5400               if (not_arg)
5401                 ok = ! ok;
5402             }
5403
5404           if (*p == ' ')
5405             ++p;
5406         }
5407
5408       if (ok)
5409         {
5410           if (this_path_len != 1
5411               || this_path[0] != '.')
5412             {
5413               multilib_dir = xmalloc (this_path_len + 1);
5414               strncpy (multilib_dir, this_path, this_path_len);
5415               multilib_dir[this_path_len] = '\0';
5416             }
5417           break;
5418         }
5419
5420       ++p;
5421     }      
5422 }
5423
5424 /* Print out the multiple library subdirectory selection
5425    information.  This prints out a series of lines.  Each line looks
5426    like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5427    required.  Only the desired options are printed out, the negative
5428    matches.  The options are print without a leading dash.  There are
5429    no spaces to make it easy to use the information in the shell.
5430    Each subdirectory is printed only once.  This assumes the ordering
5431    generated by the genmultilib script.  */
5432
5433 static void
5434 print_multilib_info ()
5435 {
5436   char *p = multilib_select;
5437   char *last_path = 0, *this_path;
5438   int skip;
5439   int last_path_len = 0;
5440
5441   while (*p != '\0')
5442     {
5443       /* Ignore newlines.  */
5444       if (*p == '\n')
5445         {
5446           ++p;
5447           continue;
5448         }
5449
5450       /* Get the initial path.  */
5451       this_path = p;
5452       while (*p != ' ')
5453         {
5454           if (*p == '\0')
5455             abort ();
5456           ++p;
5457         }
5458
5459       /* If this is a duplicate, skip it.  */
5460       skip = (last_path != 0 && p - this_path == last_path_len
5461               && ! strncmp (last_path, this_path, last_path_len));
5462
5463       last_path = this_path;
5464       last_path_len = p - this_path;
5465
5466       /* If this directory requires any default arguments, we can skip
5467          it.  We will already have printed a directory identical to
5468          this one which does not require that default argument.  */
5469       if (! skip)
5470         {
5471           char *q;
5472
5473           q = p + 1;
5474           while (*q != ';')
5475             {
5476               char *arg;
5477
5478               if (*q == '\0')
5479                 abort ();
5480
5481               if (*q == '!')
5482                 arg = NULL;
5483               else
5484                 arg = q;
5485
5486               while (*q != ' ' && *q != ';')
5487                 {
5488                   if (*q == '\0')
5489                     abort ();
5490                   ++q;
5491                 }
5492
5493               if (arg != NULL
5494                   && default_arg (arg, q - arg))
5495                 {
5496                   skip = 1;
5497                   break;
5498                 }
5499
5500               if (*q == ' ')
5501                 ++q;
5502             }
5503         }
5504
5505       if (! skip)
5506         {
5507           char *p1;
5508
5509           for (p1 = last_path; p1 < p; p1++)
5510             putchar (*p1);
5511           putchar (';');
5512         }
5513
5514       ++p;
5515       while (*p != ';')
5516         {
5517           int use_arg;
5518
5519           if (*p == '\0')
5520             abort ();
5521
5522           if (skip)
5523             {
5524               ++p;
5525               continue;
5526             }
5527
5528           use_arg = *p != '!';
5529
5530           if (use_arg)
5531             putchar ('@');
5532
5533           while (*p != ' ' && *p != ';')
5534             {
5535               if (*p == '\0')
5536                 abort ();
5537               if (use_arg)
5538                 putchar (*p);
5539               ++p;
5540             }
5541
5542           if (*p == ' ')
5543             ++p;
5544         }
5545
5546       if (! skip)
5547         {
5548           /* If there are extra options, print them now */
5549           if (multilib_extra && *multilib_extra)
5550             {
5551               int print_at = TRUE;
5552               char *q;
5553
5554               for (q = multilib_extra; *q != '\0'; q++)
5555                 {
5556                   if (*q == ' ')
5557                     print_at = TRUE;
5558                   else
5559                     {
5560                       if (print_at)
5561                         putchar ('@');
5562                       putchar (*q);
5563                       print_at = FALSE;
5564                     }
5565                 }
5566             }
5567           putchar ('\n');
5568         }
5569
5570       ++p;
5571     }
5572 }