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