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