]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gcc.c
*** empty log message ***
[thirdparty/gcc.git] / gcc / gcc.c
CommitLineData
ed1f651b
RS
1/* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
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
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20This paragraph is here to try to keep Sun CC from dying.
21The number of chars here seems crucial!!!! */
22
23/* This program is the user interface to the C compiler and possibly to
24other compilers. It is used because compilation is a complicated procedure
25which involves running several programs and passing temporary files between
26them, forwarding the users switches to those programs selectively,
27and deleting the temporary files at the end.
28
29CC recognizes how to compile each input file by suffixes in the file names.
30Once it knows which kind of compilation to perform, the procedure for
31compilation is specified by a string called a "spec". */
32\f
33#include <stdio.h>
34#include <sys/types.h>
35#include <ctype.h>
36#include <signal.h>
ed1f651b
RS
37#include <sys/stat.h>
38
39#include "config.h"
40#include "obstack.h"
41#include "gvarargs.h"
42
ed1f651b
RS
43#ifndef R_OK
44#define R_OK 4
45#define W_OK 2
46#define X_OK 1
47#endif
48
2378088a 49#ifdef USG
ed1f651b
RS
50#define vfork fork
51#endif /* USG */
52
53/* On MSDOS, write temp files in current dir
54 because there's no place else we can expect to use. */
55#if __MSDOS__
56#ifndef P_tmpdir
57#define P_tmpdir "./"
58#endif
59#endif
60
61/* Test if something is a normal file. */
62#ifndef S_ISREG
63#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
64#endif
65
66/* Test if something is a directory. */
67#ifndef S_ISDIR
68#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
69#endif
70
71/* By default there is no special suffix for executables. */
72#ifndef EXECUTABLE_SUFFIX
ed1f651b
RS
73#define EXECUTABLE_SUFFIX ""
74#endif
f6ec7e54
RS
75
76/* By default, colon separates directories in a path. */
77#ifndef PATH_SEPARATOR
78#define PATH_SEPARATOR ':'
ed1f651b
RS
79#endif
80
81#define obstack_chunk_alloc xmalloc
82#define obstack_chunk_free free
83
84extern void free ();
85extern char *getenv ();
86
87extern int errno, sys_nerr;
88extern char *sys_errlist[];
89
90extern int execv (), execvp ();
91
92/* If a stage of compilation returns an exit status >= 1,
93 compilation of that file ceases. */
94
95#define MIN_FATAL_STATUS 1
96
2dcb563f
RS
97/* Flag saying to print the full filename of libgcc.a
98 as found through our usual search mechanism. */
99
100static int print_libgcc_file_name;
101
ed1f651b
RS
102/* Flag indicating whether we should print the command and arguments */
103
104static int verbose_flag;
105
106/* Nonzero means write "temp" files in source directory
107 and use the source file's name in them, and don't delete them. */
108
109static int save_temps_flag;
110
111/* The compiler version specified with -V */
112
113static char *spec_version;
114
115/* The target machine specified with -b. */
116
117static char *spec_machine = DEFAULT_TARGET_MACHINE;
118
004fd4d5
RS
119/* Nonzero if cross-compiling.
120 When -b is used, the value comes from the `specs' file. */
121
122#ifdef CROSS_COMPILE
123static int cross_compile = 1;
124#else
125static int cross_compile = 0;
126#endif
127
ed1f651b
RS
128/* This is the obstack which we use to allocate many strings. */
129
130static struct obstack obstack;
131
b3865ca9 132/* This is the obstack to build an environment variable to pass to
6dc42e49 133 collect2 that describes all of the relevant switches of what to
b3865ca9
RS
134 pass the compiler in building the list of pointers to constructors
135 and destructors. */
136
137static struct obstack collect_obstack;
138
ed1f651b
RS
139extern char *version_string;
140
141static void set_spec ();
142static struct compiler *lookup_compiler ();
143static char *find_a_file ();
144static void add_prefix ();
145static char *skip_whitespace ();
146static void record_temp_file ();
147static char *handle_braces ();
148static char *save_string ();
149static char *concat ();
150static int do_spec ();
151static int do_spec_1 ();
152static char *find_file ();
153static int is_linker_dir ();
154static void validate_switches ();
155static void validate_all_switches ();
156static void give_switch ();
157static void pfatal_with_name ();
158static void perror_with_name ();
159static void perror_exec ();
160static void fatal ();
161static void error ();
162void fancy_abort ();
163char *xmalloc ();
164char *xrealloc ();
165\f
166/* Specs are strings containing lines, each of which (if not blank)
167is made up of a program name, and arguments separated by spaces.
168The program name must be exact and start from root, since no path
169is searched and it is unreliable to depend on the current working directory.
170Redirection of input or output is not supported; the subprograms must
171accept filenames saying what files to read and write.
172
173In addition, the specs can contain %-sequences to substitute variable text
174or for conditional text. Here is a table of all defined %-sequences.
175Note that spaces are not generated automatically around the results of
176expanding these sequences; therefore, you can concatenate them together
177or with constant text in a single argument.
178
179 %% substitute one % into the program name or argument.
180 %i substitute the name of the input file being processed.
181 %b substitute the basename of the input file being processed.
182 This is the substring up to (and not including) the last period
183 and not including the directory.
184 %g substitute the temporary-file-name-base. This is a string chosen
185 once per compilation. Different temporary file names are made by
186 concatenation of constant strings on the end, as in `%g.s'.
187 %g also has the same effect of %d.
188 %d marks the argument containing or following the %d as a
189 temporary file name, so that that file will be deleted if CC exits
190 successfully. Unlike %g, this contributes no text to the argument.
191 %w marks the argument containing or following the %w as the
192 "output file" of this compilation. This puts the argument
193 into the sequence of arguments that %o will substitute later.
194 %W{...}
195 like %{...} but mark last argument supplied within
196 as a file to be deleted on failure.
197 %o substitutes the names of all the output files, with spaces
198 automatically placed around them. You should write spaces
199 around the %o as well or the results are undefined.
200 %o is for use in the specs for running the linker.
201 Input files whose names have no recognized suffix are not compiled
202 at all, but they are included among the output files, so they will
203 be linked.
204 %p substitutes the standard macro predefinitions for the
205 current target machine. Use this when running cpp.
206 %P like %p, but puts `__' before and after the name of each macro.
207 (Except macros that already have __.)
208 This is for ANSI C.
209 %s current argument is the name of a library or startup file of some sort.
210 Search for that file in a standard list of directories
211 and substitute the full name found.
212 %eSTR Print STR as an error message. STR is terminated by a newline.
213 Use this when inconsistent options are detected.
214 %x{OPTION} Accumulate an option for %X.
215 %X Output the accumulated linker options specified by compilations.
216 %a process ASM_SPEC as a spec.
217 This allows config.h to specify part of the spec for running as.
218 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
219 used here. This can be used to run a post-processor after the
220 assembler has done it's job.
221 %D Dump out a -L option for each directory in library_prefix,
222 followed by a -L option for each directory in startfile_prefix.
223 %l process LINK_SPEC as a spec.
224 %L process LIB_SPEC as a spec.
225 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
226 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
227 %c process SIGNED_CHAR_SPEC as a spec.
228 %C process CPP_SPEC as a spec. A capital C is actually used here.
229 %1 process CC1_SPEC as a spec.
230 %2 process CC1PLUS_SPEC as a spec.
231 %* substitute the variable part of a matched option. (See below.)
232 Note that each comma in the substituted string is replaced by
233 a single space.
234 %{S} substitutes the -S switch, if that switch was given to CC.
235 If that switch was not specified, this substitutes nothing.
236 Here S is a metasyntactic variable.
237 %{S*} substitutes all the switches specified to CC whose names start
238 with -S. This is used for -o, -D, -I, etc; switches that take
239 arguments. CC considers `-o foo' as being one switch whose
240 name starts with `o'. %{o*} would substitute this text,
241 including the space; thus, two arguments would be generated.
242 %{S*:X} substitutes X if one or more switches whose names with -S are
243 specified to CC. Note that the tail part of the -S option
244 (i.e. the part matched by the `*') will be substituted for each
6dc42e49 245 occurrence of %* within X.
ed1f651b
RS
246 %{S:X} substitutes X, but only if the -S switch was given to CC.
247 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
248 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
249 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
250 %{.S:X} substitutes X, but only if processing a file with suffix S.
251 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
b3865ca9
RS
252 %(Spec) processes a specification defined in a specs file as *Spec:
253 %[Spec] as above, but put __ around -D arguments
ed1f651b
RS
254
255The conditional text X in a %{S:X} or %{!S:X} construct may contain
256other nested % constructs or spaces, or even newlines. They are
257processed as usual, as described above.
258
259The character | is used to indicate that a command should be piped to
260the following command, but only if -pipe is specified.
261
262Note that it is built into CC which switches take arguments and which
263do not. You might think it would be useful to generalize this to
264allow each compiler's spec to say which switches take arguments. But
265this cannot be done in a consistent fashion. CC cannot even decide
266which input files have been specified without knowing which switches
267take arguments, and it must know which input files to compile in order
268to tell which compilers to run.
269
270CC also knows implicitly that arguments starting in `-l' are to be
271treated as compiler output files, and passed to the linker in their
272proper position among the other output files. */
273\f
274/* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
275
276/* config.h can define ASM_SPEC to provide extra args to the assembler
277 or extra switch-translations. */
278#ifndef ASM_SPEC
279#define ASM_SPEC ""
280#endif
281
282/* config.h can define ASM_FINAL_SPEC to run a post processor after
283 the assembler has run. */
284#ifndef ASM_FINAL_SPEC
285#define ASM_FINAL_SPEC ""
286#endif
287
288/* config.h can define CPP_SPEC to provide extra args to the C preprocessor
289 or extra switch-translations. */
290#ifndef CPP_SPEC
291#define CPP_SPEC ""
292#endif
293
294/* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
295 or extra switch-translations. */
296#ifndef CC1_SPEC
297#define CC1_SPEC ""
298#endif
299
300/* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
301 or extra switch-translations. */
302#ifndef CC1PLUS_SPEC
303#define CC1PLUS_SPEC ""
304#endif
305
306/* config.h can define LINK_SPEC to provide extra args to the linker
307 or extra switch-translations. */
308#ifndef LINK_SPEC
309#define LINK_SPEC ""
310#endif
311
312/* config.h can define LIB_SPEC to override the default libraries. */
313#ifndef LIB_SPEC
314#define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
315#endif
316
317/* config.h can define STARTFILE_SPEC to override the default crt0 files. */
318#ifndef STARTFILE_SPEC
319#define STARTFILE_SPEC \
320 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
321#endif
322
323/* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
324 Make the string nonempty to require spaces there. */
325#ifndef SWITCHES_NEED_SPACES
326#define SWITCHES_NEED_SPACES ""
327#endif
328
329/* config.h can define ENDFILE_SPEC to override the default crtn files. */
330#ifndef ENDFILE_SPEC
331#define ENDFILE_SPEC ""
332#endif
333
334/* This spec is used for telling cpp whether char is signed or not. */
335#ifndef SIGNED_CHAR_SPEC
336#define SIGNED_CHAR_SPEC \
337 (DEFAULT_SIGNED_CHAR ? "%{funsigned-char:-D__CHAR_UNSIGNED__}" \
338 : "%{!fsigned-char:-D__CHAR_UNSIGNED__}")
339#endif
340
341static char *cpp_spec = CPP_SPEC;
342static char *cpp_predefines = CPP_PREDEFINES;
343static char *cc1_spec = CC1_SPEC;
344static char *cc1plus_spec = CC1PLUS_SPEC;
345static char *signed_char_spec = SIGNED_CHAR_SPEC;
346static char *asm_spec = ASM_SPEC;
347static char *asm_final_spec = ASM_FINAL_SPEC;
348static char *link_spec = LINK_SPEC;
349static char *lib_spec = LIB_SPEC;
350static char *endfile_spec = ENDFILE_SPEC;
351static char *startfile_spec = STARTFILE_SPEC;
352static char *switches_need_spaces = SWITCHES_NEED_SPACES;
353
354/* This defines which switch letters take arguments. */
355
356#ifndef SWITCH_TAKES_ARG
357#define SWITCH_TAKES_ARG(CHAR) \
358 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
359 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
360 || (CHAR) == 'I' || (CHAR) == 'm' \
361 || (CHAR) == 'L' || (CHAR) == 'A')
362#endif
363
364/* This defines which multi-letter switches take arguments. */
365
366#ifndef WORD_SWITCH_TAKES_ARG
367#define WORD_SWITCH_TAKES_ARG(STR) \
368 (!strcmp (STR, "Tdata") || !strcmp (STR, "include") \
b3865ca9 369 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info"))
ed1f651b
RS
370#endif
371\f
372/* Record the mapping from file suffixes for compilation specs. */
373
374struct compiler
375{
376 char *suffix; /* Use this compiler for input files
377 whose names end in this suffix. */
378 char *spec; /* To use this compiler, pass this spec
379 to do_spec. */
380};
381
382/* Pointer to a vector of `struct compiler' that gives the spec for
383 compiling a file, based on its suffix.
384 A file that does not end in any of these suffixes will be passed
385 unchanged to the loader and nothing else will be done to it.
386
387 An entry containing two 0s is used to terminate the vector.
388
389 If multiple entries match a file, the last matching one is used. */
390
391static struct compiler *compilers;
392
393/* Number of entries in `compilers', not counting the null terminator. */
394
395static int n_compilers;
396
397/* The default list of file name suffixes and their compilation specs. */
398
399static struct compiler default_compilers[] =
400{
401 {".c", "@c"},
402 {"@c",
2378088a 403 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
ed1f651b
RS
404 %{C:%{!E:%eGNU C does not support -C without using -E}}\
405 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
406 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
407 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
408 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
409 %{traditional-cpp:-traditional}\
410 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
004fd4d5
RS
411 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
412 %{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
ed1f651b
RS
413 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
414 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
415 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
b3865ca9 416 %{aux-info*}\
ed1f651b
RS
417 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
418 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
419 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
420 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
421 %{!pipe:%g.s} %A\n }}}}"},
422 {"-",
2378088a 423 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
ed1f651b
RS
424 %{C:%{!E:%eGNU C does not support -C without using -E}}\
425 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
426 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
427 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
428 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
429 %{traditional-cpp:-traditional}\
430 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
431 %i %W{o*}}\
432 %{!E:%e-E required when input is from standard input}"},
433 {".m", "@objective-c"},
434 {"@objective-c",
2378088a 435 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
ed1f651b
RS
436 %{C:%{!E:%eGNU C does not support -C without using -E}}\
437 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
438 -undef -D__OBJC__ -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
439 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
440 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
441 %{traditional-cpp:-traditional}\
442 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
004fd4d5
RS
443 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
444 %{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
ed1f651b
RS
445 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
446 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
447 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
448 -lang-objc %{gen-decls} \
b3865ca9 449 %{aux-info*}\
ed1f651b
RS
450 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
451 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
452 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
453 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
454 %{!pipe:%g.s} %A\n }}}}"},
455 {".h", "@c-header"},
456 {"@c-header",
457 "%{!E:%eCompilation of header file requested} \
2378088a 458 cpp %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
ed1f651b
RS
459 %{C:%{!E:%eGNU C does not support -C without using -E}}\
460 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
461 -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
462 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
463 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
464 %{traditional-cpp:-traditional}\
465 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
466 %i %W{o*}"},
467 {".cc", "@c++"},
468 {".cxx", "@c++"},
469 {".C", "@c++"},
470 {"@c++",
2378088a 471 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
ed1f651b
RS
472 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
473 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
474 -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus \
475 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
476 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
477 %{traditional-cpp:-traditional} %{trigraphs}\
478 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
004fd4d5
RS
479 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
480 %{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.i} %1 %2\
ed1f651b
RS
481 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
482 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
483 %{v:-version} %{pg:-p} %{p} %{f*}\
b3865ca9 484 %{aux-info*}\
ed1f651b
RS
485 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
486 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
487 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
488 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
489 %{!pipe:%g.s} %A\n }}}}"},
490 {".i", "@cpp-output"},
491 {"@cpp-output",
492 "cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
493 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
494 %{v:-version} %{pg:-p} %{p} %{f*}\
b3865ca9 495 %{aux-info*}\
ed1f651b
RS
496 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
497 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
498 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
499 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %{!pipe:%g.s} %A\n }"},
500 {".ii", "@c++-cpp-output"},
501 {"@c++-cpp-output",
502 "cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
503 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
504 %{v:-version} %{pg:-p} %{p} %{f*}\
b3865ca9 505 %{aux-info*}\
ed1f651b
RS
506 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
507 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
508 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
509 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
004fd4d5 510 %{!pipe:%g.s} %A\n }"},
ed1f651b
RS
511 {".s", "@assembler"},
512 {"@assembler",
513 "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
514 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %i %A\n }"},
515 {".S", "@assembler-with-cpp"},
516 {"@assembler-with-cpp",
2378088a 517 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
ed1f651b
RS
518 %{C:%{!E:%eGNU C does not support -C without using -E}}\
519 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \
520 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
521 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
522 %{traditional-cpp:-traditional}\
523 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C\
524 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n\
525 %{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
526 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
527 %{!pipe:%g.s} %A\n }}}}"},
528 /* Mark end of table */
529 {0, 0}
530};
531
532/* Number of elements in default_compilers, not counting the terminator. */
533
534static int n_default_compilers
535 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
536
537/* Here is the spec for running the linker, after compiling all files. */
538
004fd4d5
RS
539#ifdef LINK_LIBGCC_SPECIAL
540/* Have gcc do the search. */
2378088a 541/* -u* was put back because both BSD and SysV seem to support it. */
ed1f651b 542static char *link_command_spec = "\
59014d0a 543%{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
2378088a 544 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
ed1f651b
RS
545 %{!A:%{!nostdlib:%S}} \
546 %{L*} %D %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}";
004fd4d5
RS
547#else
548/* Use -l and have the linker do the search. */
549static char *link_command_spec = "\
59014d0a 550%{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
2378088a 551 %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
004fd4d5
RS
552 %{!A:%{!nostdlib:%S}} \
553 %{L*} %D %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}";
554#endif
ed1f651b
RS
555
556/* A vector of options to give to the linker.
6dc42e49 557 These options are accumulated by %x
ed1f651b
RS
558 and substituted into the linker command with %X. */
559static int n_linker_options;
560static char **linker_options;
561\f
562/* Read compilation specs from a file named FILENAME,
563 replacing the default ones.
564
565 A suffix which starts with `*' is a definition for
566 one of the machine-specific sub-specs. The "suffix" should be
567 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
568 The corresponding spec is stored in asm_spec, etc.,
569 rather than in the `compilers' vector.
570
571 Anything invalid in the file is a fatal error. */
572
573static void
574read_specs (filename)
575 char *filename;
576{
577 int desc;
578 struct stat statbuf;
579 char *buffer;
580 register char *p;
581
582 if (verbose_flag)
583 fprintf (stderr, "Reading specs from %s\n", filename);
584
585 /* Open and stat the file. */
586 desc = open (filename, 0, 0);
587 if (desc < 0)
588 pfatal_with_name (filename);
589 if (stat (filename, &statbuf) < 0)
590 pfatal_with_name (filename);
591
592 /* Read contents of file into BUFFER. */
593 buffer = xmalloc (statbuf.st_size + 1);
594 read (desc, buffer, statbuf.st_size);
595 buffer[statbuf.st_size] = 0;
596 close (desc);
597
598 /* Scan BUFFER for specs, putting them in the vector. */
599 p = buffer;
600 while (1)
601 {
602 char *suffix;
603 char *spec;
604 char *in, *out, *p1, *p2;
605
606 /* Advance P in BUFFER to the next nonblank nocomment line. */
607 p = skip_whitespace (p);
608 if (*p == 0)
609 break;
610
611 /* Find the colon that should end the suffix. */
612 p1 = p;
613 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
614 /* The colon shouldn't be missing. */
615 if (*p1 != ':')
616 fatal ("specs file malformed after %d characters", p1 - buffer);
617 /* Skip back over trailing whitespace. */
618 p2 = p1;
619 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
620 /* Copy the suffix to a string. */
621 suffix = save_string (p, p2 - p);
622 /* Find the next line. */
623 p = skip_whitespace (p1 + 1);
624 if (p[1] == 0)
625 fatal ("specs file malformed after %d characters", p - buffer);
626 p1 = p;
627 /* Find next blank line. */
628 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
629 /* Specs end at the blank line and do not include the newline. */
630 spec = save_string (p, p1 - p);
631 p = p1;
632
633 /* Delete backslash-newline sequences from the spec. */
634 in = spec;
635 out = spec;
636 while (*in != 0)
637 {
638 if (in[0] == '\\' && in[1] == '\n')
639 in += 2;
640 else if (in[0] == '#')
641 {
642 while (*in && *in != '\n') in++;
ed1f651b
RS
643 }
644 else
645 *out++ = *in++;
646 }
647 *out = 0;
648
649 if (suffix[0] == '*')
650 {
651 if (! strcmp (suffix, "*link_command"))
652 link_command_spec = spec;
653 else
654 set_spec (suffix + 1, spec);
655 }
656 else
657 {
658 /* Add this pair to the vector. */
659 compilers
660 = ((struct compiler *)
661 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
662 compilers[n_compilers].suffix = suffix;
663 compilers[n_compilers].spec = spec;
664 n_compilers++;
665 }
666
667 if (*suffix == 0)
668 link_command_spec = spec;
669 }
670
671 if (link_command_spec == 0)
672 fatal ("spec file has no spec for linking");
673}
674
675static char *
676skip_whitespace (p)
677 char *p;
678{
679 while (1)
680 {
681 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
682 be considered whitespace. */
683 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
684 return p + 1;
685 else if (*p == '\n' || *p == ' ' || *p == '\t')
686 p++;
687 else if (*p == '#')
688 {
689 while (*p != '\n') p++;
690 p++;
691 }
692 else
693 break;
694 }
695
696 return p;
697}
698\f
699/* Structure to keep track of the specs that have been defined so far. These
b3865ca9 700 are accessed using %(specname) or %[specname] in a compiler or link spec. */
ed1f651b
RS
701
702struct spec_list
703{
704 char *name; /* Name of the spec. */
705 char *spec; /* The spec itself. */
706 struct spec_list *next; /* Next spec in linked list. */
707};
708
709/* List of specs that have been defined so far. */
710
711static struct spec_list *specs = (struct spec_list *) 0;
712\f
713/* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
714 removed; If the spec starts with a + then SPEC is added to the end of the
715 current spec. */
716
717static void
718set_spec (name, spec)
719 char *name;
720 char *spec;
721{
722 struct spec_list *sl;
723 char *old_spec;
724
725 /* See if the spec already exists */
726 for (sl = specs; sl; sl = sl->next)
727 if (strcmp (sl->name, name) == 0)
728 break;
729
730 if (!sl)
731 {
732 /* Not found - make it */
733 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
734 sl->name = save_string (name, strlen (name));
735 sl->spec = save_string ("", 0);
736 sl->next = specs;
737 specs = sl;
738 }
739
740 old_spec = sl->spec;
741 if (name && spec[0] == '+' && isspace (spec[1]))
742 sl->spec = concat (name, spec + 1, "");
743 else
744 sl->spec = save_string (spec, strlen (spec));
745
746 if (! strcmp (name, "asm"))
747 asm_spec = sl->spec;
748 else if (! strcmp (name, "asm_final"))
749 asm_final_spec = sl->spec;
750 else if (! strcmp (name, "cc1"))
751 cc1_spec = sl->spec;
752 else if (! strcmp (name, "cc1plus"))
753 cc1plus_spec = sl->spec;
754 else if (! strcmp (name, "cpp"))
755 cpp_spec = sl->spec;
756 else if (! strcmp (name, "endfile"))
757 endfile_spec = sl->spec;
758 else if (! strcmp (name, "lib"))
759 lib_spec = sl->spec;
760 else if (! strcmp (name, "link"))
761 link_spec = sl->spec;
762 else if (! strcmp (name, "predefines"))
763 cpp_predefines = sl->spec;
764 else if (! strcmp (name, "signed_char"))
765 signed_char_spec = sl->spec;
766 else if (! strcmp (name, "startfile"))
767 startfile_spec = sl->spec;
768 else if (! strcmp (name, "switches_need_spaces"))
769 switches_need_spaces = sl->spec;
004fd4d5
RS
770 else if (! strcmp (name, "cross_compile"))
771 cross_compile = atoi (sl->spec);
ed1f651b
RS
772 /* Free the old spec */
773 if (old_spec)
774 free (old_spec);
775}
776\f
777/* Accumulate a command (program name and args), and run it. */
778
779/* Vector of pointers to arguments in the current line of specifications. */
780
781static char **argbuf;
782
783/* Number of elements allocated in argbuf. */
784
785static int argbuf_length;
786
787/* Number of elements in argbuf currently in use (containing args). */
788
789static int argbuf_index;
790
791/* Number of commands executed so far. */
792
793static int execution_count;
794
795/* Name with which this program was invoked. */
796
797static char *programname;
798\f
799/* Structures to keep track of prefixes to try when looking for files. */
800
801struct prefix_list
802{
803 char *prefix; /* String to prepend to the path. */
804 struct prefix_list *next; /* Next in linked list. */
805 int require_machine_suffix; /* Don't use without machine_suffix. */
806 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
807};
808
809struct path_prefix
810{
811 struct prefix_list *plist; /* List of prefixes to try */
812 int max_len; /* Max length of a prefix in PLIST */
813 char *name; /* Name of this list (used in config stuff) */
814};
815
816/* List of prefixes to try when looking for executables. */
817
818static struct path_prefix exec_prefix = { 0, 0, "exec" };
819
820/* List of prefixes to try when looking for startup (crt0) files. */
821
822static struct path_prefix startfile_prefix = { 0, 0, "startfile" };
823
824/* List of prefixes to try when looking for libraries. */
825
826static struct path_prefix library_prefix = { 0, 0, "libraryfile" };
827
828/* Suffix to attach to directories searched for commands. */
829
830static char *machine_suffix = 0;
831
ed1f651b
RS
832/* Default prefixes to attach to command names. */
833
834#ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
835#undef MD_EXEC_PREFIX
836#undef MD_STARTFILE_PREFIX
837#endif
838
839#ifndef STANDARD_EXEC_PREFIX
004fd4d5 840#define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
ed1f651b
RS
841#endif /* !defined STANDARD_EXEC_PREFIX */
842
843static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
844static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
845#ifdef MD_EXEC_PREFIX
846static char *md_exec_prefix = MD_EXEC_PREFIX;
847#endif
848
849#ifndef STANDARD_STARTFILE_PREFIX
850#define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
851#endif /* !defined STANDARD_STARTFILE_PREFIX */
852
853#ifdef MD_STARTFILE_PREFIX
854static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
855#endif
856static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
857static char *standard_startfile_prefix_1 = "/lib/";
858static char *standard_startfile_prefix_2 = "/usr/lib/";
859
860/* Clear out the vector of arguments (after a command is executed). */
861
862static void
863clear_args ()
864{
865 argbuf_index = 0;
866}
867
868/* Add one argument to the vector at the end.
869 This is done when a space is seen or at the end of the line.
870 If DELETE_ALWAYS is nonzero, the arg is a filename
871 and the file should be deleted eventually.
872 If DELETE_FAILURE is nonzero, the arg is a filename
873 and the file should be deleted if this compilation fails. */
874
875static void
876store_arg (arg, delete_always, delete_failure)
877 char *arg;
878 int delete_always, delete_failure;
879{
880 if (argbuf_index + 1 == argbuf_length)
881 {
882 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
883 }
884
885 argbuf[argbuf_index++] = arg;
886 argbuf[argbuf_index] = 0;
887
888 if (delete_always || delete_failure)
889 record_temp_file (arg, delete_always, delete_failure);
890}
891\f
892/* Record the names of temporary files we tell compilers to write,
893 and delete them at the end of the run. */
894
895/* This is the common prefix we use to make temp file names.
896 It is chosen once for each run of this program.
897 It is substituted into a spec by %g.
898 Thus, all temp file names contain this prefix.
899 In practice, all temp file names start with this prefix.
900
901 This prefix comes from the envvar TMPDIR if it is defined;
902 otherwise, from the P_tmpdir macro if that is defined;
903 otherwise, in /usr/tmp or /tmp. */
904
905static char *temp_filename;
906
907/* Length of the prefix. */
908
909static int temp_filename_length;
910
911/* Define the list of temporary files to delete. */
912
913struct temp_file
914{
915 char *name;
916 struct temp_file *next;
917};
918
919/* Queue of files to delete on success or failure of compilation. */
920static struct temp_file *always_delete_queue;
921/* Queue of files to delete on failure of compilation. */
922static struct temp_file *failure_delete_queue;
923
924/* Record FILENAME as a file to be deleted automatically.
925 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
926 otherwise delete it in any case.
927 FAIL_DELETE nonzero means delete it if a compilation step fails;
928 otherwise delete it in any case. */
929
930static void
931record_temp_file (filename, always_delete, fail_delete)
932 char *filename;
933 int always_delete;
934 int fail_delete;
935{
936 register char *name;
937 name = xmalloc (strlen (filename) + 1);
938 strcpy (name, filename);
939
940 if (always_delete)
941 {
942 register struct temp_file *temp;
943 for (temp = always_delete_queue; temp; temp = temp->next)
944 if (! strcmp (name, temp->name))
945 goto already1;
946 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
947 temp->next = always_delete_queue;
948 temp->name = name;
949 always_delete_queue = temp;
950 already1:;
951 }
952
953 if (fail_delete)
954 {
955 register struct temp_file *temp;
956 for (temp = failure_delete_queue; temp; temp = temp->next)
957 if (! strcmp (name, temp->name))
958 goto already2;
959 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
960 temp->next = failure_delete_queue;
961 temp->name = name;
962 failure_delete_queue = temp;
963 already2:;
964 }
965}
966
967/* Delete all the temporary files whose names we previously recorded. */
968
969static void
970delete_temp_files ()
971{
972 register struct temp_file *temp;
973
974 for (temp = always_delete_queue; temp; temp = temp->next)
975 {
976#ifdef DEBUG
977 int i;
978 printf ("Delete %s? (y or n) ", temp->name);
979 fflush (stdout);
980 i = getchar ();
981 if (i != '\n')
982 while (getchar () != '\n') ;
983 if (i == 'y' || i == 'Y')
984#endif /* DEBUG */
985 {
986 struct stat st;
987 if (stat (temp->name, &st) >= 0)
988 {
989 /* Delete only ordinary files. */
990 if (S_ISREG (st.st_mode))
991 if (unlink (temp->name) < 0)
992 if (verbose_flag)
993 perror_with_name (temp->name);
994 }
995 }
996 }
997
998 always_delete_queue = 0;
999}
1000
1001/* Delete all the files to be deleted on error. */
1002
1003static void
1004delete_failure_queue ()
1005{
1006 register struct temp_file *temp;
1007
1008 for (temp = failure_delete_queue; temp; temp = temp->next)
1009 {
1010#ifdef DEBUG
1011 int i;
1012 printf ("Delete %s? (y or n) ", temp->name);
1013 fflush (stdout);
1014 i = getchar ();
1015 if (i != '\n')
1016 while (getchar () != '\n') ;
1017 if (i == 'y' || i == 'Y')
1018#endif /* DEBUG */
1019 {
1020 if (unlink (temp->name) < 0)
1021 if (verbose_flag)
1022 perror_with_name (temp->name);
1023 }
1024 }
1025}
1026
1027static void
1028clear_failure_queue ()
1029{
1030 failure_delete_queue = 0;
1031}
1032
1033/* Compute a string to use as the base of all temporary file names.
1034 It is substituted for %g. */
1035
1036static void
1037choose_temp_base ()
1038{
1039 char *base = getenv ("TMPDIR");
1040 int len;
1041
1042 if (base == (char *)0)
1043 {
1044#ifdef P_tmpdir
1045 if (access (P_tmpdir, R_OK | W_OK) == 0)
1046 base = P_tmpdir;
1047#endif
1048 if (base == (char *)0)
1049 {
1050 if (access ("/usr/tmp", R_OK | W_OK) == 0)
1051 base = "/usr/tmp/";
1052 else
1053 base = "/tmp/";
1054 }
1055 }
1056
1057 len = strlen (base);
1058 temp_filename = xmalloc (len + sizeof("/ccXXXXXX"));
1059 strcpy (temp_filename, base);
1060 if (len > 0 && temp_filename[len-1] != '/')
1061 temp_filename[len++] = '/';
1062 strcpy (temp_filename + len, "ccXXXXXX");
1063
1064 mktemp (temp_filename);
1065 temp_filename_length = strlen (temp_filename);
1066}
b3865ca9
RS
1067\f
1068
1069/* Routine to add variables to the environment. We do this to pass
1070 the pathname of the gcc driver, and the directories search to the
1071 collect2 program, which is being run as ld. This way, we can be
1072 sure of executing the right compiler when collect2 wants to build
1073 constructors and destructors. Since the environment variables we
1074 use come from an obstack, we don't have to worry about allocating
1075 space for them. */
1076
1077#ifndef HAVE_PUTENV
1078
1079putenv (str)
1080 char *str;
1081{
b3865ca9
RS
1082#ifndef VMS /* nor about VMS */
1083
1084 extern char **environ;
1085 char **old_environ = environ;
1086 char **envp;
1087 int num_envs = 0;
1088 int name_len = 1;
1089 int str_len = strlen (str);
1090 char *p = str;
1091 int ch;
1092
1093 while ((ch = *p++) != '\0' && ch != '=')
1094 name_len++;
1095
1096 if (!ch)
1097 abort ();
1098
1099 /* Search for replacing an existing environment variable, and
1100 count the number of total environment variables. */
1101 for (envp = old_environ; *envp; envp++)
1102 {
1103 num_envs++;
1104 if (!strncmp (str, *envp, name_len))
1105 {
1106 *envp = str;
1107 return;
1108 }
1109 }
1110
1111 /* Add a new environment variable */
1112 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1113 *environ = str;
1114 bcopy (old_environ, environ+1, sizeof (char *) * (num_envs+1));
1115
1116#endif /* VMS */
b3865ca9
RS
1117}
1118
1119#endif /* HAVE_PUTENV */
1120
1121\f
1122/* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1123
1124static void
1125putenv_from_prefixes (paths, env_var)
1126 struct path_prefix *paths;
1127 char *env_var;
1128{
1129 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1130 int first_time = TRUE;
1131 struct prefix_list *pprefix;
1132
1133 obstack_grow (&collect_obstack, env_var, strlen (env_var));
1134
1135 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1136 {
1137 int len = strlen (pprefix->prefix);
1138
1139 if (machine_suffix)
1140 {
1141 if (!first_time)
1142 obstack_grow (&collect_obstack, ":", 1);
1143
1144 first_time = FALSE;
1145 obstack_grow (&collect_obstack, pprefix->prefix, len);
1146 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1147 }
1148
1149 if (!pprefix->require_machine_suffix)
1150 {
1151 if (!first_time)
1152 obstack_grow (&collect_obstack, ":", 1);
1153
1154 first_time = FALSE;
1155 obstack_grow (&collect_obstack, pprefix->prefix, len);
1156 }
1157 }
1158 obstack_grow (&collect_obstack, "\0", 1);
1159 putenv (obstack_finish (&collect_obstack));
1160}
1161
ed1f651b
RS
1162\f
1163/* Search for NAME using the prefix list PREFIXES. MODE is passed to
1164 access to check permissions.
1165 Return 0 if not found, otherwise return its name, allocated with malloc. */
1166
1167static char *
1168find_a_file (pprefix, name, mode)
1169 struct path_prefix *pprefix;
1170 char *name;
1171 int mode;
1172{
1173 char *temp;
004fd4d5 1174 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
ed1f651b
RS
1175 struct prefix_list *pl;
1176 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1177
1178 if (machine_suffix)
1179 len += strlen (machine_suffix);
1180
1181 temp = xmalloc (len);
1182
1183 /* Determine the filename to execute (special case for absolute paths). */
1184
1185 if (*name == '/')
1186 {
1187 if (access (name, mode))
1188 {
1189 strcpy (temp, name);
1190 return temp;
1191 }
1192 }
1193 else
1194 for (pl = pprefix->plist; pl; pl = pl->next)
1195 {
1196 if (machine_suffix)
1197 {
1198 strcpy (temp, pl->prefix);
1199 strcat (temp, machine_suffix);
1200 strcat (temp, name);
1201 if (access (temp, mode) == 0)
1202 {
1203 if (pl->used_flag_ptr != 0)
1204 *pl->used_flag_ptr = 1;
1205 return temp;
1206 }
1207 /* Some systems have a suffix for executable files.
1208 So try appending that. */
1209 if (file_suffix[0] != 0)
1210 {
1211 strcat (temp, file_suffix);
1212 if (access (temp, mode) == 0)
1213 {
1214 if (pl->used_flag_ptr != 0)
1215 *pl->used_flag_ptr = 1;
1216 return temp;
1217 }
1218 }
1219 }
1220 /* Certain prefixes can't be used without the machine suffix
1221 when the machine or version is explicitly specified. */
004fd4d5 1222 if (!pl->require_machine_suffix)
ed1f651b
RS
1223 {
1224 strcpy (temp, pl->prefix);
1225 strcat (temp, name);
1226 if (access (temp, mode) == 0)
1227 {
1228 if (pl->used_flag_ptr != 0)
1229 *pl->used_flag_ptr = 1;
1230 return temp;
1231 }
1232 /* Some systems have a suffix for executable files.
1233 So try appending that. */
1234 if (file_suffix[0] != 0)
1235 {
1236 strcat (temp, file_suffix);
1237 if (access (temp, mode) == 0)
1238 {
1239 if (pl->used_flag_ptr != 0)
1240 *pl->used_flag_ptr = 1;
1241 return temp;
1242 }
1243 }
1244 }
1245 }
1246
1247 free (temp);
1248 return 0;
1249}
1250
1251/* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1252 at the start of the list, otherwise it goes at the end.
1253
1254 If WARN is nonzero, we will warn if no file is found
1255 through this prefix. WARN should point to an int
1256 which will be set to 1 if this entry is used. */
1257
1258static void
1259add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1260 struct path_prefix *pprefix;
1261 char *prefix;
1262 int first;
1263 int require_machine_suffix;
1264 int *warn;
1265{
1266 struct prefix_list *pl, **prev;
1267 int len;
1268
1269 if (!first && pprefix->plist)
1270 {
1271 for (pl = pprefix->plist; pl->next; pl = pl->next)
1272 ;
1273 prev = &pl->next;
1274 }
1275 else
1276 prev = &pprefix->plist;
1277
1278 /* Keep track of the longest prefix */
1279
1280 len = strlen (prefix);
1281 if (len > pprefix->max_len)
1282 pprefix->max_len = len;
1283
1284 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1285 pl->prefix = save_string (prefix, len);
1286 pl->require_machine_suffix = require_machine_suffix;
1287 pl->used_flag_ptr = warn;
1288 if (warn)
1289 *warn = 0;
1290
1291 if (*prev)
1292 pl->next = *prev;
1293 else
1294 pl->next = (struct prefix_list *) 0;
1295 *prev = pl;
1296}
1297
1298/* Print warnings for any prefixes in the list PPREFIX that were not used. */
1299
1300static void
1301unused_prefix_warnings (pprefix)
1302 struct path_prefix *pprefix;
1303{
1304 struct prefix_list *pl = pprefix->plist;
1305
1306 while (pl)
1307 {
1308 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1309 {
1310 error ("file path prefix `%s' never used",
1311 pl->prefix);
1312 /* Prevent duplicate warnings. */
1313 *pl->used_flag_ptr = 1;
1314 }
1315 pl = pl->next;
1316 }
1317}
1318
1319/* Get rid of all prefixes built up so far in *PLISTP. */
1320
1321static void
1322free_path_prefix (pprefix)
1323 struct path_prefix *pprefix;
1324{
1325 struct prefix_list *pl = pprefix->plist;
1326 struct prefix_list *temp;
1327
1328 while (pl)
1329 {
1330 temp = pl;
1331 pl = pl->next;
1332 free (temp->prefix);
1333 free ((char *) temp);
1334 }
1335 pprefix->plist = (struct prefix_list *) 0;
1336}
1337\f
1338/* stdin file number. */
1339#define STDIN_FILE_NO 0
1340
1341/* stdout file number. */
1342#define STDOUT_FILE_NO 1
1343
1344/* value of `pipe': port index for reading. */
1345#define READ_PORT 0
1346
1347/* value of `pipe': port index for writing. */
1348#define WRITE_PORT 1
1349
1350/* Pipe waiting from last process, to be used as input for the next one.
1351 Value is STDIN_FILE_NO if no pipe is waiting
1352 (i.e. the next command is the first of a group). */
1353
1354static int last_pipe_input;
1355
1356/* Fork one piped subcommand. FUNC is the system call to use
1357 (either execv or execvp). ARGV is the arg vector to use.
1358 NOT_LAST is nonzero if this is not the last subcommand
1359 (i.e. its output should be piped to the next one.) */
1360
1361#ifdef __MSDOS__
1362
1363/* Declare these to avoid compilation error. They won't be called. */
1364int execv(const char *a, const char **b){}
1365int execvp(const char *a, const char **b){}
1366
1367static int
1368pexecute (func, program, argv, not_last)
1369 char *program;
1370 int (*func)();
1371 char *argv[];
1372 int not_last;
1373{
1374 char *scmd;
1375 FILE *argfile;
1376 int i;
1377
59014d0a
RS
1378 scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6);
1379 sprintf (scmd, "%s @%s.gp", program, temp_filename);
1380 argfile = fopen (scmd+strlen (program) + 2, "w");
ed1f651b 1381 if (argfile == 0)
59014d0a 1382 pfatal_with_name (scmd + strlen (program) + 2);
ed1f651b
RS
1383
1384 for (i=1; argv[i]; i++)
f6ec7e54
RS
1385 {
1386 char *cp;
1387 for (cp = argv[i]; *cp; cp++)
1388 {
1389 if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
1390 fputc ('\\', argfile);
1391 fputc (*cp, argfile);
1392 }
1393 fputc ('\n', argfile);
1394 }
59014d0a 1395 fclose (argfile);
ed1f651b 1396
59014d0a 1397 i = system (scmd);
ed1f651b 1398
59014d0a 1399 remove (scmd + strlen (program) + 2);
ed1f651b
RS
1400 return i << 8;
1401}
1402
1403#else /* not __MSDOS__ */
1404
1405static int
1406pexecute (func, program, argv, not_last)
1407 char *program;
1408 int (*func)();
1409 char *argv[];
1410 int not_last;
1411{
1412 int pid;
1413 int pdes[2];
1414 int input_desc = last_pipe_input;
1415 int output_desc = STDOUT_FILE_NO;
1416 int retries, sleep_interval;
1417
1418 /* If this isn't the last process, make a pipe for its output,
1419 and record it as waiting to be the input to the next process. */
1420
1421 if (not_last)
1422 {
1423 if (pipe (pdes) < 0)
1424 pfatal_with_name ("pipe");
1425 output_desc = pdes[WRITE_PORT];
1426 last_pipe_input = pdes[READ_PORT];
1427 }
1428 else
1429 last_pipe_input = STDIN_FILE_NO;
1430
1431 /* Fork a subprocess; wait and retry if it fails. */
1432 sleep_interval = 1;
1433 for (retries = 0; retries < 4; retries++)
1434 {
1435 pid = vfork ();
1436 if (pid >= 0)
1437 break;
1438 sleep (sleep_interval);
1439 sleep_interval *= 2;
1440 }
1441
1442 switch (pid)
1443 {
1444 case -1:
1445#ifdef vfork
1446 pfatal_with_name ("fork");
1447#else
1448 pfatal_with_name ("vfork");
1449#endif
1450 /* NOTREACHED */
1451 return 0;
1452
1453 case 0: /* child */
1454 /* Move the input and output pipes into place, if nec. */
1455 if (input_desc != STDIN_FILE_NO)
1456 {
1457 close (STDIN_FILE_NO);
1458 dup (input_desc);
1459 close (input_desc);
1460 }
1461 if (output_desc != STDOUT_FILE_NO)
1462 {
1463 close (STDOUT_FILE_NO);
1464 dup (output_desc);
1465 close (output_desc);
1466 }
1467
1468 /* Close the parent's descs that aren't wanted here. */
1469 if (last_pipe_input != STDIN_FILE_NO)
1470 close (last_pipe_input);
1471
1472 /* Exec the program. */
1473 (*func) (program, argv);
1474 perror_exec (program);
1475 exit (-1);
1476 /* NOTREACHED */
1477 return 0;
1478
1479 default:
1480 /* In the parent, after forking.
1481 Close the descriptors that we made for this child. */
1482 if (input_desc != STDIN_FILE_NO)
1483 close (input_desc);
1484 if (output_desc != STDOUT_FILE_NO)
1485 close (output_desc);
1486
1487 /* Return child's process number. */
1488 return pid;
1489 }
1490}
1491
1492#endif /* not __MSDOS__ */
1493\f
1494/* Execute the command specified by the arguments on the current line of spec.
1495 When using pipes, this includes several piped-together commands
1496 with `|' between them.
1497
1498 Return 0 if successful, -1 if failed. */
1499
1500static int
1501execute ()
1502{
1503 int i;
1504 int n_commands; /* # of command. */
1505 char *string;
1506 struct command
1507 {
1508 char *prog; /* program name. */
1509 char **argv; /* vector of args. */
1510 int pid; /* pid of process for this command. */
1511 };
1512
1513 struct command *commands; /* each command buffer with above info. */
1514
1515 /* Count # of piped commands. */
1516 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1517 if (strcmp (argbuf[i], "|") == 0)
1518 n_commands++;
1519
1520 /* Get storage for each command. */
1521 commands
1522 = (struct command *) alloca (n_commands * sizeof (struct command));
1523
1524 /* Split argbuf into its separate piped processes,
1525 and record info about each one.
1526 Also search for the programs that are to be run. */
1527
1528 commands[0].prog = argbuf[0]; /* first command. */
1529 commands[0].argv = &argbuf[0];
1530 string = find_a_file (&exec_prefix, commands[0].prog, X_OK);
1531 if (string)
1532 commands[0].argv[0] = string;
1533
1534 for (n_commands = 1, i = 0; i < argbuf_index; i++)
1535 if (strcmp (argbuf[i], "|") == 0)
1536 { /* each command. */
1537#ifdef __MSDOS__
1538 fatal ("-pipe not supported under MS-DOS");
1539#endif
1540 argbuf[i] = 0; /* termination of command args. */
1541 commands[n_commands].prog = argbuf[i + 1];
1542 commands[n_commands].argv = &argbuf[i + 1];
1543 string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK);
1544 if (string)
1545 commands[n_commands].argv[0] = string;
1546 n_commands++;
1547 }
1548
1549 argbuf[argbuf_index] = 0;
1550
1551 /* If -v, print what we are about to do, and maybe query. */
1552
b3865ca9 1553 if (verbose_flag)
ed1f651b
RS
1554 {
1555 /* Print each piped command as a separate line. */
1556 for (i = 0; i < n_commands ; i++)
1557 {
1558 char **j;
1559
1560 for (j = commands[i].argv; *j; j++)
1561 fprintf (stderr, " %s", *j);
1562
1563 /* Print a pipe symbol after all but the last command. */
1564 if (i + 1 != n_commands)
1565 fprintf (stderr, " |");
1566 fprintf (stderr, "\n");
1567 }
1568 fflush (stderr);
1569#ifdef DEBUG
1570 fprintf (stderr, "\nGo ahead? (y or n) ");
1571 fflush (stderr);
1572 i = getchar ();
1573 if (i != '\n')
1574 while (getchar () != '\n') ;
1575 if (i != 'y' && i != 'Y')
1576 return 0;
1577#endif /* DEBUG */
1578 }
1579
1580 /* Run each piped subprocess. */
1581
1582 last_pipe_input = STDIN_FILE_NO;
1583 for (i = 0; i < n_commands; i++)
1584 {
1585 char *string = commands[i].argv[0];
1586
1587 commands[i].pid = pexecute ((string != commands[i].prog ? execv : execvp),
1588 string, commands[i].argv,
1589 i + 1 < n_commands);
1590
1591 if (string != commands[i].prog)
1592 free (string);
1593 }
1594
1595 execution_count++;
1596
1597 /* Wait for all the subprocesses to finish.
1598 We don't care what order they finish in;
1599 we know that N_COMMANDS waits will get them all. */
1600
1601 {
1602 int ret_code = 0;
1603
1604 for (i = 0; i < n_commands; i++)
1605 {
1606 int status;
1607 int pid;
1608 char *prog;
1609
1610#ifdef __MSDOS__
1611 status = pid = commands[i].pid;
1612#else
1613 pid = wait (&status);
1614#endif
1615 if (pid < 0)
1616 abort ();
1617
1618 if (status != 0)
1619 {
1620 int j;
1621 for (j = 0; j < n_commands; j++)
1622 if (commands[j].pid == pid)
1623 prog = commands[j].prog;
1624
1625 if ((status & 0x7F) != 0)
1626 fatal ("Internal compiler error: program %s got fatal signal %d",
1627 prog, (status & 0x7F));
1628 if (((status & 0xFF00) >> 8) >= MIN_FATAL_STATUS)
1629 ret_code = -1;
1630 }
1631 }
1632 return ret_code;
1633 }
1634}
1635\f
1636/* Find all the switches given to us
1637 and make a vector describing them.
1638 The elements of the vector are strings, one per switch given.
1639 If a switch uses following arguments, then the `part1' field
1640 is the switch itself and the `args' field
1641 is a null-terminated vector containing the following arguments.
1642 The `valid' field is nonzero if any spec has looked at this switch;
1643 if it remains zero at the end of the run, it must be meaningless. */
1644
1645struct switchstr
1646{
1647 char *part1;
1648 char **args;
1649 int valid;
1650};
1651
1652static struct switchstr *switches;
1653
1654static int n_switches;
1655
1656struct infile
1657{
1658 char *name;
1659 char *language;
1660};
1661
1662/* Also a vector of input files specified. */
1663
1664static struct infile *infiles;
1665
1666static int n_infiles;
1667
1668/* And a vector of corresponding output files is made up later. */
1669
1670static char **outfiles;
1671
1672/* Create the vector `switches' and its contents.
1673 Store its length in `n_switches'. */
1674
1675static void
1676process_command (argc, argv)
1677 int argc;
1678 char **argv;
1679{
1680 register int i;
1681 char *temp;
1682 char *spec_lang = 0;
1683 int last_language_n_infiles;
1684
1685 n_switches = 0;
1686 n_infiles = 0;
1687 spec_version = version_string;
1688
1689 /* Set up the default search paths. */
1690
1691 temp = getenv ("GCC_EXEC_PREFIX");
1692 if (temp)
1693 {
1694 add_prefix (&exec_prefix, temp, 0, 0, 0);
1695 add_prefix (&startfile_prefix, temp, 0, 0, 0);
1696 }
1697
1698 /* COMPILER_PATH and LIBRARY_PATH have values
1699 that are lists of directory names with colons. */
1700
1701 temp = getenv ("COMPILER_PATH");
1702 if (temp)
1703 {
1704 char *startp, *endp;
1705 char *nstore = (char *) alloca (strlen (temp) + 3);
1706
1707 startp = endp = temp;
1708 while (1)
1709 {
f6ec7e54 1710 if (*endp == PATH_SEPARATOR || *endp == 0)
ed1f651b
RS
1711 {
1712 strncpy (nstore, startp, endp-startp);
1713 if (endp == startp)
1714 {
1715 strcpy (nstore, "./");
1716 }
1717 else if (endp[-1] != '/')
1718 {
1719 nstore[endp-startp] = '/';
1720 nstore[endp-startp+1] = 0;
1721 }
1722 else
1723 nstore[endp-startp] = 0;
1724 add_prefix (&exec_prefix, nstore, 0, 0, 0);
1725 if (*endp == 0)
1726 break;
1727 endp = startp = endp + 1;
1728 }
1729 else
1730 endp++;
1731 }
1732 }
1733
1734 temp = getenv ("LIBRARY_PATH");
1735 if (temp)
1736 {
1737 char *startp, *endp;
1738 char *nstore = (char *) alloca (strlen (temp) + 3);
1739
1740 startp = endp = temp;
1741 while (1)
1742 {
f6ec7e54 1743 if (*endp == PATH_SEPARATOR || *endp == 0)
ed1f651b
RS
1744 {
1745 strncpy (nstore, startp, endp-startp);
1746 if (endp == startp)
1747 {
1748 strcpy (nstore, "./");
1749 }
1750 else if (endp[-1] != '/')
1751 {
1752 nstore[endp-startp] = '/';
1753 nstore[endp-startp+1] = 0;
1754 }
1755 else
1756 nstore[endp-startp] = 0;
1757 add_prefix (&startfile_prefix, nstore, 0, 0, 0);
1758 /* Make separate list of dirs that came from LIBRARY_PATH. */
1759 add_prefix (&library_prefix, nstore, 0, 0, 0);
1760 if (*endp == 0)
1761 break;
1762 endp = startp = endp + 1;
1763 }
1764 else
1765 endp++;
1766 }
1767 }
1768
1769 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
1770 temp = getenv ("LPATH");
1771 if (temp)
1772 {
1773 char *startp, *endp;
1774 char *nstore = (char *) alloca (strlen (temp) + 3);
1775
1776 startp = endp = temp;
1777 while (1)
1778 {
f6ec7e54 1779 if (*endp == PATH_SEPARATOR || *endp == 0)
ed1f651b
RS
1780 {
1781 strncpy (nstore, startp, endp-startp);
1782 if (endp == startp)
1783 {
1784 strcpy (nstore, "./");
1785 }
1786 else if (endp[-1] != '/')
1787 {
1788 nstore[endp-startp] = '/';
1789 nstore[endp-startp+1] = 0;
1790 }
1791 else
1792 nstore[endp-startp] = 0;
1793 add_prefix (&startfile_prefix, nstore, 0, 0, 0);
1794 /* Make separate list of dirs that came from LIBRARY_PATH. */
1795 add_prefix (&library_prefix, nstore, 0, 0, 0);
1796 if (*endp == 0)
1797 break;
1798 endp = startp = endp + 1;
1799 }
1800 else
1801 endp++;
1802 }
1803 }
1804
1805 /* Scan argv twice. Here, the first time, just count how many switches
1806 there will be in their vector, and how many input files in theirs.
1807 Here we also parse the switches that cc itself uses (e.g. -v). */
1808
1809 for (i = 1; i < argc; i++)
1810 {
1811 if (! strcmp (argv[i], "-dumpspecs"))
1812 {
1813 printf ("*asm:\n%s\n\n", asm_spec);
1814 printf ("*asm_final:\n%s\n\n", asm_final_spec);
1815 printf ("*cpp:\n%s\n\n", cpp_spec);
1816 printf ("*cc1:\n%s\n\n", cc1_spec);
1817 printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
1818 printf ("*endfile:\n%s\n\n", endfile_spec);
1819 printf ("*link:\n%s\n\n", link_spec);
1820 printf ("*lib:\n%s\n\n", lib_spec);
1821 printf ("*startfile:\n%s\n\n", startfile_spec);
1822 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
1823 printf ("*signed_char:\n%s\n\n", signed_char_spec);
1824 printf ("*predefines:\n%s\n\n", cpp_predefines);
004fd4d5 1825 printf ("*cross_compile:\n%d\n\n", cross_compile);
ed1f651b
RS
1826
1827 exit (0);
1828 }
1829 else if (! strcmp (argv[i], "-dumpversion"))
1830 {
1831 printf ("%s\n", version_string);
1832 exit (0);
1833 }
2dcb563f
RS
1834 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
1835 {
1836 print_libgcc_file_name = 1;
1837 }
ed1f651b
RS
1838 else if (! strcmp (argv[i], "-Xlinker"))
1839 {
1840 /* Pass the argument of this option to the linker when we link. */
1841
1842 if (i + 1 == argc)
1843 fatal ("argument to `-Xlinker' is missing");
1844
1845 n_linker_options++;
1846 if (!linker_options)
1847 linker_options
1848 = (char **) xmalloc (n_linker_options * sizeof (char **));
1849 else
1850 linker_options
1851 = (char **) xrealloc (linker_options,
1852 n_linker_options * sizeof (char **));
1853
1854 linker_options[n_linker_options - 1] = argv[++i];
1855 }
1856 else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
1857 {
1858 register char *p = &argv[i][1];
1859 register int c = *p;
1860
1861 switch (c)
1862 {
1863 case 'b':
1864 if (p[1] == 0 && i + 1 == argc)
1865 fatal ("argument to `-b' is missing");
1866 if (p[1] == 0)
1867 spec_machine = argv[++i];
1868 else
1869 spec_machine = p + 1;
1870 break;
1871
1872 case 'B':
1873 {
1874 int *temp = (int *) xmalloc (sizeof (int));
1875 char *value;
1876 if (p[1] == 0 && i + 1 == argc)
1877 fatal ("argument to `-B' is missing");
1878 if (p[1] == 0)
1879 value = argv[++i];
1880 else
1881 value = p + 1;
1882 add_prefix (&exec_prefix, value, 1, 0, temp);
1883 add_prefix (&startfile_prefix, value, 1, 0, temp);
1884 }
1885 break;
1886
1887 case 'v': /* Print our subcommands and print versions. */
1888 verbose_flag++;
1889 n_switches++;
1890 break;
1891
1892 case 'V':
1893 if (p[1] == 0 && i + 1 == argc)
1894 fatal ("argument to `-V' is missing");
1895 if (p[1] == 0)
1896 spec_version = argv[++i];
1897 else
1898 spec_version = p + 1;
1899 break;
1900
1901 case 's':
1902 if (!strcmp (p, "save-temps"))
1903 {
1904 save_temps_flag = 1;
1905 break;
1906 }
1907 default:
1908 n_switches++;
1909
1910 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1911 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1912 else if (WORD_SWITCH_TAKES_ARG (p))
1913 i += WORD_SWITCH_TAKES_ARG (p);
1914 }
1915 }
1916 else
1917 n_infiles++;
1918 }
1919
1920 /* Set up the search paths before we go looking for config files. */
1921
1922 /* These come before the md prefixes so that we will find gcc's subcommands
1923 (such as cpp) rather than those of the host system. */
1924 add_prefix (&exec_prefix, standard_exec_prefix, 0, 1, 0);
1925 add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 1, 0);
1926
1927 add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, 0);
1928 add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, 0);
1929
004fd4d5
RS
1930 /* More prefixes are enabled in main, after we read the specs file
1931 and determine whether this is cross-compilation or not. */
ed1f651b 1932
ed1f651b
RS
1933
1934 /* Then create the space for the vectors and scan again. */
1935
1936 switches = ((struct switchstr *)
1937 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
1938 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
1939 n_switches = 0;
1940 n_infiles = 0;
1941 last_language_n_infiles = -1;
1942
1943 /* This, time, copy the text of each switch and store a pointer
1944 to the copy in the vector of switches.
1945 Store all the infiles in their vector. */
1946
1947 for (i = 1; i < argc; i++)
1948 {
1949 if (!strcmp (argv[i], "-Xlinker"))
1950 i++;
2dcb563f
RS
1951 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
1952 i++;
ed1f651b
RS
1953 else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
1954 {
1955 register char *p = &argv[i][1];
1956 register int c = *p;
1957
1958 if (c == 'B' || c == 'b' || c == 'V')
1959 {
1960 /* Skip a separate arg, if any. */
1961 if (p[1] == 0)
1962 i++;
1963 continue;
1964 }
1965 if (c == 'x')
1966 {
1967 if (p[1] == 0 && i + 1 == argc)
1968 fatal ("argument to `-x' is missing");
1969 if (p[1] == 0)
1970 spec_lang = argv[++i];
1971 else
1972 spec_lang = p + 1;
1973 if (! strcmp (spec_lang, "none"))
1974 /* Suppress the warning if -xnone comes after the last input file,
1975 because alternate command interfaces like g++ might find it
1976 useful to place -xnone after each input file. */
1977 spec_lang = 0;
1978 else
1979 last_language_n_infiles = n_infiles;
1980 continue;
1981 }
1982 switches[n_switches].part1 = p;
1983 /* Deal with option arguments in separate argv elements. */
1984 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
1985 || WORD_SWITCH_TAKES_ARG (p)) {
1986 int j = 0;
1987 int n_args = WORD_SWITCH_TAKES_ARG (p);
1988
1989 if (n_args == 0) {
1990 /* Count only the option arguments in separate argv elements. */
1991 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
1992 }
1993 switches[n_switches].args
1994 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
1995 while (j < n_args)
1996 switches[n_switches].args[j++] = argv[++i];
1997 /* Null-terminate the vector. */
1998 switches[n_switches].args[j] = 0;
1999 } else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L')) {
2000 /* On some systems, ld cannot handle -o or -L without space.
2001 So split the -o or -L from its argument. */
2002 switches[n_switches].part1 = (c == 'o' ? "o" : "L");
2003 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2004 switches[n_switches].args[0] = xmalloc (strlen (p));
2005 strcpy (switches[n_switches].args[0], &p[1]);
2006 switches[n_switches].args[1] = 0;
2007 } else
2008 switches[n_switches].args = 0;
2009 switches[n_switches].valid = 0;
2010 /* This is always valid, since gcc.c itself understands it. */
2011 if (!strcmp (p, "save-temps"))
2012 switches[n_switches].valid = 1;
2013 n_switches++;
2014 }
2015 else
2016 {
2017 infiles[n_infiles].language = spec_lang;
2018 infiles[n_infiles++].name = argv[i];
2019 }
2020 }
2021
2022 if (n_infiles == last_language_n_infiles)
2023 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2024
2025 switches[n_switches].part1 = 0;
2026 infiles[n_infiles].name = 0;
2027}
2028\f
2029/* Process a spec string, accumulating and running commands. */
2030
2031/* These variables describe the input file name.
2032 input_file_number is the index on outfiles of this file,
2033 so that the output file name can be stored for later use by %o.
2034 input_basename is the start of the part of the input file
2035 sans all directory names, and basename_length is the number
2036 of characters starting there excluding the suffix .c or whatever. */
2037
2038static char *input_filename;
2039static int input_file_number;
2040static int input_filename_length;
2041static int basename_length;
2042static char *input_basename;
2043static char *input_suffix;
2044
2045/* These are variables used within do_spec and do_spec_1. */
2046
2047/* Nonzero if an arg has been started and not yet terminated
2048 (with space, tab or newline). */
2049static int arg_going;
2050
2051/* Nonzero means %d or %g has been seen; the next arg to be terminated
2052 is a temporary file name. */
2053static int delete_this_arg;
2054
2055/* Nonzero means %w has been seen; the next arg to be terminated
2056 is the output file name of this compilation. */
2057static int this_is_output_file;
2058
2059/* Nonzero means %s has been seen; the next arg to be terminated
2060 is the name of a library file and we should try the standard
2061 search dirs for it. */
2062static int this_is_library_file;
2063
2064/* Process the spec SPEC and run the commands specified therein.
2065 Returns 0 if the spec is successfully processed; -1 if failed. */
2066
2067static int
2068do_spec (spec)
2069 char *spec;
2070{
2071 int value;
2072
2073 clear_args ();
2074 arg_going = 0;
2075 delete_this_arg = 0;
2076 this_is_output_file = 0;
2077 this_is_library_file = 0;
2078
2079 value = do_spec_1 (spec, 0, NULL);
2080
2081 /* Force out any unfinished command.
2082 If -pipe, this forces out the last command if it ended in `|'. */
2083 if (value == 0)
2084 {
2085 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2086 argbuf_index--;
2087
2088 if (argbuf_index > 0)
2089 value = execute ();
2090 }
2091
2092 return value;
2093}
2094
2095/* Process the sub-spec SPEC as a portion of a larger spec.
2096 This is like processing a whole spec except that we do
2097 not initialize at the beginning and we do not supply a
2098 newline by default at the end.
2099 INSWITCH nonzero means don't process %-sequences in SPEC;
2100 in this case, % is treated as an ordinary character.
2101 This is used while substituting switches.
2102 INSWITCH nonzero also causes SPC not to terminate an argument.
2103
2104 Value is zero unless a line was finished
2105 and the command on that line reported an error. */
2106
2107static int
2108do_spec_1 (spec, inswitch, soft_matched_part)
2109 char *spec;
2110 int inswitch;
2111 char *soft_matched_part;
2112{
2113 register char *p = spec;
2114 register int c;
2115 int i;
2116 char *string;
2117
2118 while (c = *p++)
2119 /* If substituting a switch, treat all chars like letters.
2120 Otherwise, NL, SPC, TAB and % are special. */
2121 switch (inswitch ? 'a' : c)
2122 {
2123 case '\n':
2124 /* End of line: finish any pending argument,
2125 then run the pending command if one has been started. */
2126 if (arg_going)
2127 {
2128 obstack_1grow (&obstack, 0);
2129 string = obstack_finish (&obstack);
2130 if (this_is_library_file)
2131 string = find_file (string);
2132 store_arg (string, delete_this_arg, this_is_output_file);
2133 if (this_is_output_file)
2134 outfiles[input_file_number] = string;
2135 }
2136 arg_going = 0;
2137
2138 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
2139 {
2140 int i;
2141 for (i = 0; i < n_switches; i++)
2142 if (!strcmp (switches[i].part1, "pipe"))
2143 break;
2144
2145 /* A `|' before the newline means use a pipe here,
2146 but only if -pipe was specified.
2147 Otherwise, execute now and don't pass the `|' as an arg. */
2148 if (i < n_switches)
2149 {
2150 switches[i].valid = 1;
2151 break;
2152 }
2153 else
2154 argbuf_index--;
2155 }
2156
2157 if (argbuf_index > 0)
2158 {
2159 int value = execute ();
2160 if (value)
2161 return value;
2162 }
2163 /* Reinitialize for a new command, and for a new argument. */
2164 clear_args ();
2165 arg_going = 0;
2166 delete_this_arg = 0;
2167 this_is_output_file = 0;
2168 this_is_library_file = 0;
2169 break;
2170
2171 case '|':
2172 /* End any pending argument. */
2173 if (arg_going)
2174 {
2175 obstack_1grow (&obstack, 0);
2176 string = obstack_finish (&obstack);
2177 if (this_is_library_file)
2178 string = find_file (string);
2179 store_arg (string, delete_this_arg, this_is_output_file);
2180 if (this_is_output_file)
2181 outfiles[input_file_number] = string;
2182 }
2183
2184 /* Use pipe */
2185 obstack_1grow (&obstack, c);
2186 arg_going = 1;
2187 break;
2188
2189 case '\t':
2190 case ' ':
2191 /* Space or tab ends an argument if one is pending. */
2192 if (arg_going)
2193 {
2194 obstack_1grow (&obstack, 0);
2195 string = obstack_finish (&obstack);
2196 if (this_is_library_file)
2197 string = find_file (string);
2198 store_arg (string, delete_this_arg, this_is_output_file);
2199 if (this_is_output_file)
2200 outfiles[input_file_number] = string;
2201 }
2202 /* Reinitialize for a new argument. */
2203 arg_going = 0;
2204 delete_this_arg = 0;
2205 this_is_output_file = 0;
2206 this_is_library_file = 0;
2207 break;
2208
2209 case '%':
2210 switch (c = *p++)
2211 {
2212 case 0:
2213 fatal ("Invalid specification! Bug in cc.");
2214
2215 case 'b':
2216 obstack_grow (&obstack, input_basename, basename_length);
2217 arg_going = 1;
2218 break;
2219
2220 case 'd':
2221 delete_this_arg = 2;
2222 break;
2223
2224 /* Dump out the directories specified with LIBRARY_PATH,
004fd4d5
RS
2225 followed by the absolute directories
2226 that we search for startfiles. */
ed1f651b
RS
2227 case 'D':
2228 for (i = 0; i < 2; i++)
2229 {
2230 struct prefix_list *pl
2231 = (i == 0 ? library_prefix.plist : startfile_prefix.plist);
59014d0a
RS
2232 int bufsize = 100;
2233 char *buffer = (char *) xmalloc (bufsize);
2234 int idx;
2235
ed1f651b
RS
2236 for (; pl; pl = pl->next)
2237 {
004fd4d5
RS
2238#ifdef RELATIVE_PREFIX_NOT_LINKDIR
2239 /* Used on systems which record the specified -L dirs
2240 and use them to search for dynamic linking. */
2241 /* Relative directories always come from -B,
2242 and it is better not to use them for searching
2243 at run time. In particular, stage1 loses */
2244 if (pl->prefix[0] != '/')
2245 continue;
2246#endif
ed1f651b
RS
2247 if (machine_suffix)
2248 {
2249 if (is_linker_dir (pl->prefix, machine_suffix))
2250 {
2251 do_spec_1 ("-L", 0, 0);
004fd4d5
RS
2252#ifdef SPACE_AFTER_L_OPTION
2253 do_spec_1 (" ", 0, 0);
2254#endif
ed1f651b 2255 do_spec_1 (pl->prefix, 1, 0);
59014d0a
RS
2256 /* Remove slash from machine_suffix. */
2257 if (strlen (machine_suffix) >= bufsize)
2258 bufsize = strlen (machine_suffix) * 2 + 1;
2259 buffer = (char *) xrealloc (buffer, bufsize);
2260 strcpy (buffer, machine_suffix);
2261 idx = strlen (buffer);
2262 if (buffer[idx - 1] == '/')
2263 buffer[idx - 1] = 0;
2264 do_spec_1 (buffer, 1, 0);
ed1f651b
RS
2265 /* Make this a separate argument. */
2266 do_spec_1 (" ", 0, 0);
2267 }
2268 }
004fd4d5 2269 if (!pl->require_machine_suffix)
ed1f651b
RS
2270 {
2271 if (is_linker_dir (pl->prefix, ""))
2272 {
2273 do_spec_1 ("-L", 0, 0);
004fd4d5
RS
2274#ifdef SPACE_AFTER_L_OPTION
2275 do_spec_1 (" ", 0, 0);
2276#endif
59014d0a
RS
2277 /* Remove slash from pl->prefix. */
2278 if (strlen (pl->prefix) >= bufsize)
2279 bufsize = strlen (pl->prefix) * 2 + 1;
2280 buffer = (char *) xrealloc (buffer, bufsize);
2281 strcpy (buffer, pl->prefix);
2282 idx = strlen (buffer);
2283 if (buffer[idx - 1] == '/')
2284 buffer[idx - 1] = 0;
2285 do_spec_1 (buffer, 1, 0);
ed1f651b
RS
2286 /* Make this a separate argument. */
2287 do_spec_1 (" ", 0, 0);
2288 }
2289 }
2290 }
59014d0a 2291 free (buffer);
ed1f651b
RS
2292 }
2293 break;
2294
2295 case 'e':
2296 /* {...:%efoo} means report an error with `foo' as error message
2297 and don't execute any more commands for this file. */
2298 {
2299 char *q = p;
2300 char *buf;
2301 while (*p != 0 && *p != '\n') p++;
2302 buf = (char *) alloca (p - q + 1);
2303 strncpy (buf, q, p - q);
2304 buf[p - q] = 0;
2305 error ("%s", buf);
2306 return -1;
2307 }
2308 break;
2309
2310 case 'g':
2311 if (save_temps_flag)
2312 obstack_grow (&obstack, input_basename, basename_length);
2313 else
2314 {
2315 obstack_grow (&obstack, temp_filename, temp_filename_length);
2316 delete_this_arg = 1;
2317 }
2318 arg_going = 1;
2319 break;
2320
2321 case 'i':
2322 obstack_grow (&obstack, input_filename, input_filename_length);
2323 arg_going = 1;
2324 break;
2325
2326 case 'o':
2327 {
2328 register int f;
2329 for (f = 0; f < n_infiles; f++)
2330 store_arg (outfiles[f], 0, 0);
2331 }
2332 break;
2333
2334 case 's':
2335 this_is_library_file = 1;
2336 break;
2337
2338 case 'w':
2339 this_is_output_file = 1;
2340 break;
2341
2342 case 'W':
2343 {
2344 int index = argbuf_index;
2345 /* Handle the {...} following the %W. */
2346 if (*p != '{')
2347 abort ();
2348 p = handle_braces (p + 1);
2349 if (p == 0)
2350 return -1;
2351 /* If any args were output, mark the last one for deletion
2352 on failure. */
2353 if (argbuf_index != index)
2354 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
2355 break;
2356 }
2357
2358 /* %x{OPTION} records OPTION for %X to output. */
2359 case 'x':
2360 {
2361 char *p1 = p;
2362 char *string;
2363
2364 /* Skip past the option value and make a copy. */
2365 if (*p != '{')
2366 abort ();
2367 while (*p++ != '}')
2368 ;
2369 string = save_string (p1 + 1, p - p1 - 2);
2370
2371 /* See if we already recorded this option. */
2372 for (i = 0; i < n_linker_options; i++)
2373 if (! strcmp (string, linker_options[i]))
2374 {
2375 free (string);
2376 return 0;
2377 }
2378
2379 /* This option is new; add it. */
2380 n_linker_options++;
2381 if (!linker_options)
2382 linker_options
2383 = (char **) xmalloc (n_linker_options * sizeof (char **));
2384 else
2385 linker_options
2386 = (char **) xrealloc (linker_options,
2387 n_linker_options * sizeof (char **));
2388
2389 linker_options[n_linker_options - 1] = string;
2390 }
2391 break;
2392
2393 /* Dump out the options accumulated previously using %x. */
2394 case 'X':
2395 for (i = 0; i < n_linker_options; i++)
2396 {
2397 do_spec_1 (linker_options[i], 1, NULL);
2398 /* Make each accumulated option a separate argument. */
2399 do_spec_1 (" ", 0, NULL);
2400 }
2401 break;
2402
2403 /* Here are digits and numbers that just process
2404 a certain constant string as a spec. */
2405
2406 case '1':
2407 do_spec_1 (cc1_spec, 0, NULL);
2408 break;
2409
2410 case '2':
2411 do_spec_1 (cc1plus_spec, 0, NULL);
2412 break;
2413
2414 case 'a':
2415 do_spec_1 (asm_spec, 0, NULL);
2416 break;
2417
2418 case 'A':
2419 do_spec_1 (asm_final_spec, 0, NULL);
2420 break;
2421
2422 case 'c':
2423 do_spec_1 (signed_char_spec, 0, NULL);
2424 break;
2425
2426 case 'C':
2427 do_spec_1 (cpp_spec, 0, NULL);
2428 break;
2429
2430 case 'E':
2431 do_spec_1 (endfile_spec, 0, NULL);
2432 break;
2433
2434 case 'l':
2435 do_spec_1 (link_spec, 0, NULL);
2436 break;
2437
2438 case 'L':
2439 do_spec_1 (lib_spec, 0, NULL);
2440 break;
2441
2442 case 'p':
2443 {
2444 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
2445 char *buf = x;
2446 char *y;
2447
2448 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
2449 y = cpp_predefines;
2450 while (*y != 0)
2451 {
2452 if (! strncmp (y, "-D", 2))
2453 /* Copy the whole option. */
2454 while (*y && *y != ' ' && *y != '\t')
2455 *x++ = *y++;
2456 else if (*y == ' ' || *y == '\t')
2457 /* Copy whitespace to the result. */
2458 *x++ = *y++;
2459 /* Don't copy other options. */
2460 else
2461 y++;
2462 }
2463
2464 *x = 0;
2465
2466 do_spec_1 (buf, 0, NULL);
2467 }
2468 break;
2469
2470 case 'P':
2471 {
2472 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
2473 char *buf = x;
2474 char *y;
2475
2476 /* Copy all of CPP_PREDEFINES into BUF,
2477 but put __ after every -D and at the end of each arg. */
2478 y = cpp_predefines;
2479 while (*y != 0)
2480 {
2481 if (! strncmp (y, "-D", 2))
2482 {
2483 int flag = 0;
2484
2485 *x++ = *y++;
2486 *x++ = *y++;
2487
2488 if (strncmp (y, "__", 2))
2489 {
2490 /* Stick __ at front of macro name. */
2491 *x++ = '_';
2492 *x++ = '_';
2493 /* Arrange to stick __ at the end as well. */
2494 flag = 1;
2495 }
2496
2497 /* Copy the macro name. */
2498 while (*y && *y != '=' && *y != ' ' && *y != '\t')
2499 *x++ = *y++;
2500
2501 if (flag)
2502 {
2503 *x++ = '_';
2504 *x++ = '_';
2505 }
2506
2507 /* Copy the value given, if any. */
2508 while (*y && *y != ' ' && *y != '\t')
2509 *x++ = *y++;
2510 }
2511 else if (*y == ' ' || *y == '\t')
2512 /* Copy whitespace to the result. */
2513 *x++ = *y++;
2514 /* Don't copy -A options */
2515 else
2516 y++;
2517 }
2518 *x++ = ' ';
2519
2520 /* Copy all of CPP_PREDEFINES into BUF,
2521 but put __ after every -D. */
2522 y = cpp_predefines;
2523 while (*y != 0)
2524 {
2525 if (! strncmp (y, "-D", 2))
2526 {
2527 *x++ = *y++;
2528 *x++ = *y++;
2529
2530 if (strncmp (y, "__", 2))
2531 {
2532 /* Stick __ at front of macro name. */
2533 *x++ = '_';
2534 *x++ = '_';
2535 }
2536
2537 /* Copy the macro name. */
2538 while (*y && *y != '=' && *y != ' ' && *y != '\t')
2539 *x++ = *y++;
2540
2541 /* Copy the value given, if any. */
2542 while (*y && *y != ' ' && *y != '\t')
2543 *x++ = *y++;
2544 }
2545 else if (*y == ' ' || *y == '\t')
2546 /* Copy whitespace to the result. */
2547 *x++ = *y++;
2548 /* Don't copy -A options */
2549 else
2550 y++;
2551 }
2552 *x++ = ' ';
2553
2554 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
2555 y = cpp_predefines;
2556 while (*y != 0)
2557 {
2558 if (! strncmp (y, "-A", 2))
2559 /* Copy the whole option. */
2560 while (*y && *y != ' ' && *y != '\t')
2561 *x++ = *y++;
2562 else if (*y == ' ' || *y == '\t')
2563 /* Copy whitespace to the result. */
2564 *x++ = *y++;
2565 /* Don't copy other options. */
2566 else
2567 y++;
2568 }
2569
2570 *x = 0;
2571
2572 do_spec_1 (buf, 0, NULL);
2573 }
2574 break;
2575
2576 case 'S':
2577 do_spec_1 (startfile_spec, 0, NULL);
2578 break;
2579
2580 /* Here we define characters other than letters and digits. */
2581
2582 case '{':
2583 p = handle_braces (p);
2584 if (p == 0)
2585 return -1;
2586 break;
2587
2588 case '%':
2589 obstack_1grow (&obstack, '%');
2590 break;
2591
2592 case '*':
2593 do_spec_1 (soft_matched_part, 1, NULL);
2594 do_spec_1 (" ", 0, NULL);
2595 break;
2596
2597 /* Process a string found as the value of a spec given by name.
2598 This feature allows individual machine descriptions
2599 to add and use their own specs.
2600 %[...] modifies -D options the way %P does;
2601 %(...) uses the spec unmodified. */
2602 case '(':
2603 case '[':
2604 {
2605 char *name = p;
2606 struct spec_list *sl;
2607 int len;
2608
2609 /* The string after the S/P is the name of a spec that is to be
2610 processed. */
2611 while (*p && *p != ')' && *p != ']')
2612 p++;
2613
2614 /* See if it's in the list */
2615 for (len = p - name, sl = specs; sl; sl = sl->next)
2616 if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
2617 {
2618 name = sl->spec;
2619 break;
2620 }
2621
2622 if (sl)
2623 {
2624 if (c == '(')
2625 do_spec_1 (name, 0, NULL);
2626 else
2627 {
2628 char *x = (char *) alloca (strlen (name) * 2 + 1);
2629 char *buf = x;
2630 char *y = name;
2631
2632 /* Copy all of NAME into BUF, but put __ after
2633 every -D and at the end of each arg, */
2634 while (1)
2635 {
2636 if (! strncmp (y, "-D", 2))
2637 {
2638 *x++ = '-';
2639 *x++ = 'D';
2640 *x++ = '_';
2641 *x++ = '_';
2642 y += 2;
2643 }
2644 else if (*y == ' ' || *y == 0)
2645 {
2646 *x++ = '_';
2647 *x++ = '_';
2648 if (*y == 0)
2649 break;
2650 else
2651 *x++ = *y++;
2652 }
2653 else
2654 *x++ = *y++;
2655 }
2656 *x = 0;
2657
2658 do_spec_1 (buf, 0, NULL);
2659 }
2660 }
b3865ca9
RS
2661
2662 /* Discard the closing paren or bracket. */
2663 if (*p)
2664 p++;
ed1f651b
RS
2665 }
2666 break;
2667
2668 default:
2669 abort ();
2670 }
2671 break;
2672
2673 case '\\':
2674 /* Backslash: treat next character as ordinary. */
2675 c = *p++;
2676
2677 /* fall through */
2678 default:
2679 /* Ordinary character: put it into the current argument. */
2680 obstack_1grow (&obstack, c);
2681 arg_going = 1;
2682 }
2683
2684 return 0; /* End of string */
2685}
2686
2687/* Return 0 if we call do_spec_1 and that returns -1. */
2688
2689static char *
2690handle_braces (p)
2691 register char *p;
2692{
2693 register char *q;
2694 char *filter;
2695 int pipe = 0;
2696 int negate = 0;
2697 int suffix = 0;
2698
2699 if (*p == '|')
2700 /* A `|' after the open-brace means,
2701 if the test fails, output a single minus sign rather than nothing.
2702 This is used in %{|!pipe:...}. */
2703 pipe = 1, ++p;
2704
2705 if (*p == '!')
2706 /* A `!' after the open-brace negates the condition:
2707 succeed if the specified switch is not present. */
2708 negate = 1, ++p;
2709
2710 if (*p == '.')
2711 /* A `.' after the open-brace means test against the current suffix. */
2712 {
2713 if (pipe)
2714 abort ();
2715
2716 suffix = 1;
2717 ++p;
2718 }
2719
2720 filter = p;
2721 while (*p != ':' && *p != '}') p++;
2722 if (*p != '}')
2723 {
2724 register int count = 1;
2725 q = p + 1;
2726 while (count > 0)
2727 {
2728 if (*q == '{')
2729 count++;
2730 else if (*q == '}')
2731 count--;
2732 else if (*q == 0)
2733 abort ();
2734 q++;
2735 }
2736 }
2737 else
2738 q = p + 1;
2739
2740 if (suffix)
2741 {
2742 int found = (input_suffix != 0
004fd4d5 2743 && strlen (input_suffix) == p - filter
ed1f651b
RS
2744 && strncmp (input_suffix, filter, p - filter) == 0);
2745
2746 if (p[0] == '}')
2747 abort ();
2748
2749 if (negate != found
2750 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL) < 0)
2751 return 0;
2752
2753 return q;
2754 }
2755 else if (p[-1] == '*' && p[0] == '}')
2756 {
2757 /* Substitute all matching switches as separate args. */
2758 register int i;
2759 --p;
2760 for (i = 0; i < n_switches; i++)
2761 if (!strncmp (switches[i].part1, filter, p - filter))
2762 give_switch (i, 0);
2763 }
2764 else
2765 {
2766 /* Test for presence of the specified switch. */
2767 register int i;
2768 int present = 0;
2769
2770 /* If name specified ends in *, as in {x*:...},
2771 check for %* and handle that case. */
2772 if (p[-1] == '*' && !negate)
2773 {
2774 int substitution;
2775 char *r = p;
2776
2777 /* First see whether we have %*. */
2778 substitution = 0;
b3865ca9 2779 while (r < q)
ed1f651b
RS
2780 {
2781 if (*r == '%' && r[1] == '*')
2782 substitution = 1;
2783 r++;
2784 }
2785 /* If we do, handle that case. */
2786 if (substitution)
2787 {
2788 /* Substitute all matching switches as separate args.
2789 But do this by substituting for %*
2790 in the text that follows the colon. */
2791
2792 unsigned hard_match_len = p - filter - 1;
2793 char *string = save_string (p + 1, q - p - 2);
2794
2795 for (i = 0; i < n_switches; i++)
2796 if (!strncmp (switches[i].part1, filter, hard_match_len))
2797 {
2798 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
2799 /* Pass any arguments this switch has. */
2800 give_switch (i, 1);
2801 }
2802
2803 return q;
2804 }
2805 }
2806
2807 /* If name specified ends in *, as in {x*:...},
2808 check for presence of any switch name starting with x. */
2809 if (p[-1] == '*')
2810 {
2811 for (i = 0; i < n_switches; i++)
2812 {
2813 unsigned hard_match_len = p - filter - 1;
2814
2815 if (!strncmp (switches[i].part1, filter, hard_match_len))
2816 {
2817 switches[i].valid = 1;
2818 present = 1;
2819 }
2820 }
2821 }
2822 /* Otherwise, check for presence of exact name specified. */
2823 else
2824 {
2825 for (i = 0; i < n_switches; i++)
2826 {
2827 if (!strncmp (switches[i].part1, filter, p - filter)
2828 && switches[i].part1[p - filter] == 0)
2829 {
2830 switches[i].valid = 1;
2831 present = 1;
2832 break;
2833 }
2834 }
2835 }
2836
2837 /* If it is as desired (present for %{s...}, absent for %{-s...})
2838 then substitute either the switch or the specified
2839 conditional text. */
2840 if (present != negate)
2841 {
2842 if (*p == '}')
2843 {
2844 give_switch (i, 0);
2845 }
2846 else
2847 {
2848 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL) < 0)
2849 return 0;
2850 }
2851 }
2852 else if (pipe)
2853 {
2854 /* Here if a %{|...} conditional fails: output a minus sign,
2855 which means "standard output" or "standard input". */
2856 do_spec_1 ("-", 0, NULL);
2857 }
2858 }
2859
2860 return q;
2861}
2862
2863/* Pass a switch to the current accumulating command
2864 in the same form that we received it.
2865 SWITCHNUM identifies the switch; it is an index into
2866 the vector of switches gcc received, which is `switches'.
2867 This cannot fail since it never finishes a command line.
2868
2869 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
2870
2871static void
2872give_switch (switchnum, omit_first_word)
2873 int switchnum;
2874 int omit_first_word;
2875{
2876 if (!omit_first_word)
2877 {
2878 do_spec_1 ("-", 0, NULL);
2879 do_spec_1 (switches[switchnum].part1, 1, NULL);
2880 }
2881 do_spec_1 (" ", 0, NULL);
2882 if (switches[switchnum].args != 0)
2883 {
2884 char **p;
2885 for (p = switches[switchnum].args; *p; p++)
2886 {
2887 do_spec_1 (*p, 1, NULL);
2888 do_spec_1 (" ", 0, NULL);
2889 }
2890 }
2891 switches[switchnum].valid = 1;
2892}
2893\f
2894/* Search for a file named NAME trying various prefixes including the
2895 user's -B prefix and some standard ones.
2896 Return the absolute file name found. If nothing is found, return NAME. */
2897
2898static char *
2899find_file (name)
2900 char *name;
2901{
2902 char *newname;
2903
2904 newname = find_a_file (&startfile_prefix, name, R_OK);
2905 return newname ? newname : name;
2906}
2907
2908/* Determine whether a -L option is relevant. Not required for certain
2909 fixed names and for directories that don't exist. */
2910
2911static int
2912is_linker_dir (path1, path2)
2913 char *path1;
2914 char *path2;
2915{
2916 int len1 = strlen (path1);
2917 int len2 = strlen (path2);
2918 char *path = (char *) alloca (3 + len1 + len2);
2919 char *cp;
2920 struct stat st;
2921
2922 /* Construct the path from the two parts. Ensure the string ends with "/.".
2923 The resulting path will be a directory even if the given path is a
2924 symbolic link. */
2925 bcopy (path1, path, len1);
2926 bcopy (path2, path + len1, len2);
2927 cp = path + len1 + len2;
2928 if (cp[-1] != '/')
2929 *cp++ = '/';
2930 *cp++ = '.';
2931 *cp = '\0';
2932
2933 /* Exclude directories that the linker is known to search. */
2934 if ((cp - path == 6 && strcmp (path, "/lib/.") == 0)
2935 || (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0))
2936 return 0;
2937
2938 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
2939}
ed1f651b
RS
2940\f
2941/* On fatal signals, delete all the temporary files. */
2942
2943static void
2944fatal_error (signum)
2945 int signum;
2946{
2947 signal (signum, SIG_DFL);
2948 delete_failure_queue ();
2949 delete_temp_files ();
2950 /* Get the same signal again, this time not handled,
2951 so its normal effect occurs. */
2952 kill (getpid (), signum);
2953}
2954
2955int
2956main (argc, argv)
2957 int argc;
2958 char **argv;
2959{
2960 register int i;
2961 int value;
2962 int error_count = 0;
2963 int linker_was_run = 0;
2964 char *explicit_link_files;
2965 char *specs_file;
2966
2967 programname = argv[0];
2968
2969 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
2970 signal (SIGINT, fatal_error);
2971 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
2972 signal (SIGHUP, fatal_error);
2973 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
2974 signal (SIGTERM, fatal_error);
2975#ifdef SIGPIPE
2976 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
2977 signal (SIGPIPE, fatal_error);
2978#endif
2979
2980 argbuf_length = 10;
2981 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
2982
2983 obstack_init (&obstack);
2984
b3865ca9
RS
2985 /* Set up to remember the pathname of gcc and any options
2986 needed for collect. */
2987 obstack_init (&collect_obstack);
2988 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
2989 obstack_grow (&collect_obstack, programname, strlen (programname)+1);
2990 putenv (obstack_finish (&collect_obstack));
2991
ed1f651b
RS
2992 /* Choose directory for temp files. */
2993
2994 choose_temp_base ();
2995
2996 /* Make a table of what switches there are (switches, n_switches).
2997 Make a table of specified input files (infiles, n_infiles).
2998 Decode switches that are handled locally. */
2999
3000 process_command (argc, argv);
3001
3002 /* Initialize the vector of specs to just the default.
3003 This means one element containing 0s, as a terminator. */
3004
3005 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
3006 bcopy (default_compilers, compilers, sizeof default_compilers);
3007 n_compilers = n_default_compilers;
3008
3009 /* Read specs from a file if there is one. */
3010
3011 machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", ""));
3012
3013 specs_file = find_a_file (&startfile_prefix, "specs", R_OK);
3014 /* Read the specs file unless it is a default one. */
3015 if (specs_file != 0 && strcmp (specs_file, "specs"))
3016 read_specs (specs_file);
3017
004fd4d5
RS
3018 /* If not cross-compiling, look for startfiles in the standard places. */
3019 /* The fact that these are done here, after reading the specs file,
3020 means that it cannot be found in these directories.
3021 But that's okay. It should never be there anyway. */
3022 if (!cross_compile)
3023 {
3024#ifdef MD_EXEC_PREFIX
3025 add_prefix (&exec_prefix, md_exec_prefix, 0, 0, 0);
3026 add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, 0);
3027#endif
3028
3029#ifdef MD_STARTFILE_PREFIX
3030 add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, 0);
3031#endif
3032
3033 add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0, 0);
3034 add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0, 0);
3035 add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0, 0);
3036#if 0 /* Can cause surprises, and one can use -B./ instead. */
3037 add_prefix (&startfile_prefix, "./", 0, 1, 0);
3038#endif
3039 }
3040
ed1f651b
RS
3041 /* Now we have the specs.
3042 Set the `valid' bits for switches that match anything in any spec. */
3043
3044 validate_all_switches ();
3045
3046 /* Warn about any switches that no pass was interested in. */
3047
3048 for (i = 0; i < n_switches; i++)
3049 if (! switches[i].valid)
3050 error ("unrecognized option `-%s'", switches[i].part1);
3051
2dcb563f
RS
3052 if (print_libgcc_file_name)
3053 {
3054 printf ("%s\n", find_file ("libgcc.a"));
3055 exit (0);
3056 }
3057
ed1f651b
RS
3058 /* Obey some of the options. */
3059
3060 if (verbose_flag)
3061 {
3062 fprintf (stderr, "gcc version %s\n", version_string);
3063 if (n_infiles == 0)
3064 exit (0);
3065 }
3066
3067 if (n_infiles == 0)
3068 fatal ("No input files specified.");
3069
3070 /* Make a place to record the compiler output file names
3071 that correspond to the input files. */
3072
3073 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
3074 bzero (outfiles, n_infiles * sizeof (char *));
3075
3076 /* Record which files were specified explicitly as link input. */
3077
3078 explicit_link_files = xmalloc (n_infiles);
3079 bzero (explicit_link_files, n_infiles);
3080
3081 for (i = 0; i < n_infiles; i++)
3082 {
3083 register struct compiler *cp = 0;
3084 int this_file_error = 0;
3085
3086 /* Tell do_spec what to substitute for %i. */
3087
3088 input_filename = infiles[i].name;
3089 input_filename_length = strlen (input_filename);
3090 input_file_number = i;
3091
3092 /* Use the same thing in %o, unless cp->spec says otherwise. */
3093
3094 outfiles[i] = input_filename;
3095
3096 /* Figure out which compiler from the file's suffix. */
3097
3098 cp = lookup_compiler (infiles[i].name, input_filename_length,
3099 infiles[i].language);
3100
3101 if (cp)
3102 {
3103 /* Ok, we found an applicable compiler. Run its spec. */
3104 /* First say how much of input_filename to substitute for %b */
3105 register char *p;
3106
3107 input_basename = input_filename;
3108 for (p = input_filename; *p; p++)
3109 if (*p == '/')
3110 input_basename = p + 1;
3111
3112 /* Find a suffix starting with the last period,
3113 and set basename_length to exclude that suffix. */
3114 basename_length = strlen (input_basename);
3115 p = input_basename + basename_length;
3116 while (p != input_basename && *p != '.') --p;
3117 if (*p == '.' && p != input_basename)
3118 {
3119 basename_length = p - input_basename;
3120 input_suffix = p + 1;
3121 }
3122 else
3123 input_suffix = "";
3124
3125 value = do_spec (cp->spec);
3126 if (value < 0)
3127 this_file_error = 1;
3128 }
3129
3130 /* If this file's name does not contain a recognized suffix,
3131 record it as explicit linker input. */
3132
3133 else
3134 explicit_link_files[i] = 1;
3135
3136 /* Clear the delete-on-failure queue, deleting the files in it
3137 if this compilation failed. */
3138
3139 if (this_file_error)
3140 {
3141 delete_failure_queue ();
3142 error_count++;
3143 }
3144 /* If this compilation succeeded, don't delete those files later. */
3145 clear_failure_queue ();
3146 }
3147
3148 /* Run ld to link all the compiler output files. */
3149
3150 if (error_count == 0)
3151 {
3152 int tmp = execution_count;
b3865ca9
RS
3153 int i;
3154 int first_time;
3155
3156 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
3157 for collect. */
3158 putenv_from_prefixes (&exec_prefix, "COMPILER_PATH=");
3159 putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH=");
3160
3161 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
3162 the compiler. */
3163 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
3164 sizeof ("COLLECT_GCC_OPTIONS=")-1);
3165
3166 first_time = TRUE;
3167 for (i = 0; i < n_switches; i++)
3168 {
3169 char **args;
3170 if (!first_time)
3171 obstack_grow (&collect_obstack, " ", 1);
3172
3173 first_time = FALSE;
3174 obstack_grow (&collect_obstack, "-", 1);
3175 obstack_grow (&collect_obstack, switches[i].part1,
3176 strlen (switches[i].part1));
3177
3178 for (args = switches[i].args; args && *args; args++)
3179 {
3180 obstack_grow (&collect_obstack, " ", 1);
3181 obstack_grow (&collect_obstack, *args, strlen (*args));
3182 }
3183 }
3184 obstack_grow (&collect_obstack, "\0", 1);
3185 putenv (obstack_finish (&collect_obstack));
3186
ed1f651b
RS
3187 value = do_spec (link_command_spec);
3188 if (value < 0)
3189 error_count = 1;
3190 linker_was_run = (tmp != execution_count);
3191 }
3192
3193 /* Warn if a -B option was specified but the prefix was never used. */
3194 unused_prefix_warnings (&exec_prefix);
3195 unused_prefix_warnings (&startfile_prefix);
3196
3197 /* If options said don't run linker,
3198 complain about input files to be given to the linker. */
3199
3200 if (! linker_was_run && error_count == 0)
3201 for (i = 0; i < n_infiles; i++)
3202 if (explicit_link_files[i])
3203 error ("%s: linker input file unused since linking not done",
3204 outfiles[i]);
3205
3206 /* Delete some or all of the temporary files we made. */
3207
3208 if (error_count)
3209 delete_failure_queue ();
3210 delete_temp_files ();
3211
3212 exit (error_count);
3213 /* NOTREACHED */
3214 return 0;
3215}
3216
3217/* Find the proper compilation spec for the file name NAME,
004fd4d5 3218 whose length is LENGTH. LANGUAGE is the specified language,
ed1f651b
RS
3219 or 0 if none specified. */
3220
3221static struct compiler *
3222lookup_compiler (name, length, language)
3223 char *name;
3224 int length;
3225 char *language;
3226{
3227 struct compiler *cp;
3228
3229 /* Look for the language, if one is spec'd. */
3230 if (language != 0)
3231 {
3232 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
3233 {
3234 if (language != 0)
3235 {
3236 if (cp->suffix[0] == '@'
3237 && !strcmp (cp->suffix + 1, language))
3238 return cp;
3239 }
3240 }
3241 error ("language %s not recognized", language);
3242 }
3243
3244 /* Look for a suffix. */
3245 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
3246 {
3247 if (strlen (cp->suffix) < length
3248 /* See if the suffix matches the end of NAME. */
3249 && !strcmp (cp->suffix,
3250 name + length - strlen (cp->suffix))
3251 /* The suffix `-' matches only the file name `-'. */
3252 && !(!strcmp (cp->suffix, "-") && length != 1))
3253 {
3254 if (cp->spec[0] == '@')
3255 {
3256 struct compiler *new;
3257 /* An alias entry maps a suffix to a language.
3258 Search for the language; pass 0 for NAME and LENGTH
3259 to avoid infinite recursion if language not found.
3260 Construct the new compiler spec. */
3261 language = cp->spec + 1;
3262 new = (struct compiler *) xmalloc (sizeof (struct compiler));
3263 new->suffix = cp->suffix;
3264 new->spec = lookup_compiler (0, 0, language)->spec;
3265 return new;
3266 }
3267 /* A non-alias entry: return it. */
3268 return cp;
3269 }
3270 }
3271
3272 return 0;
3273}
3274\f
3275char *
3276xmalloc (size)
3277 unsigned size;
3278{
3279 register char *value = (char *) malloc (size);
3280 if (value == 0)
3281 fatal ("virtual memory exhausted");
3282 return value;
3283}
3284
3285char *
3286xrealloc (ptr, size)
3287 char *ptr;
3288 unsigned size;
3289{
3290 register char *value = (char *) realloc (ptr, size);
3291 if (value == 0)
3292 fatal ("virtual memory exhausted");
3293 return value;
3294}
3295
3296/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
3297
3298static char *
3299concat (s1, s2, s3)
3300 char *s1, *s2, *s3;
3301{
3302 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
3303 char *result = xmalloc (len1 + len2 + len3 + 1);
3304
3305 strcpy (result, s1);
3306 strcpy (result + len1, s2);
3307 strcpy (result + len1 + len2, s3);
3308 *(result + len1 + len2 + len3) = 0;
3309
3310 return result;
3311}
3312
3313static char *
3314save_string (s, len)
3315 char *s;
3316 int len;
3317{
3318 register char *result = xmalloc (len + 1);
3319
3320 bcopy (s, result, len);
3321 result[len] = 0;
3322 return result;
3323}
3324
3325static void
3326pfatal_with_name (name)
3327 char *name;
3328{
3329 char *s;
3330
3331 if (errno < sys_nerr)
3332 s = concat ("%s: ", sys_errlist[errno], "");
3333 else
3334 s = "cannot open %s";
3335 fatal (s, name);
3336}
3337
3338static void
3339perror_with_name (name)
3340 char *name;
3341{
3342 char *s;
3343
3344 if (errno < sys_nerr)
3345 s = concat ("%s: ", sys_errlist[errno], "");
3346 else
3347 s = "cannot open %s";
3348 error (s, name);
3349}
3350
3351static void
3352perror_exec (name)
3353 char *name;
3354{
3355 char *s;
3356
3357 if (errno < sys_nerr)
3358 s = concat ("installation problem, cannot exec %s: ",
3359 sys_errlist[errno], "");
3360 else
3361 s = "installation problem, cannot exec %s";
3362 error (s, name);
3363}
3364
3365/* More 'friendly' abort that prints the line and file.
3366 config.h can #define abort fancy_abort if you like that sort of thing. */
3367
3368void
3369fancy_abort ()
3370{
3371 fatal ("Internal gcc abort.");
3372}
3373\f
3374#ifdef HAVE_VPRINTF
3375
3376/* Output an error message and exit */
3377
3378static void
3379fatal (va_alist)
3380 va_dcl
3381{
3382 va_list ap;
3383 char *format;
3384
3385 va_start (ap);
3386 format = va_arg (ap, char *);
3387 fprintf (stderr, "%s: ", programname);
3388 vfprintf (stderr, format, ap);
3389 va_end (ap);
3390 fprintf (stderr, "\n");
3391 delete_temp_files ();
3392 exit (1);
3393}
3394
3395static void
3396error (va_alist)
3397 va_dcl
3398{
3399 va_list ap;
3400 char *format;
3401
3402 va_start (ap);
3403 format = va_arg (ap, char *);
3404 fprintf (stderr, "%s: ", programname);
3405 vfprintf (stderr, format, ap);
3406 va_end (ap);
3407
3408 fprintf (stderr, "\n");
3409}
3410
3411#else /* not HAVE_VPRINTF */
3412
3413static void
3414fatal (msg, arg1, arg2)
3415 char *msg, *arg1, *arg2;
3416{
3417 error (msg, arg1, arg2);
3418 delete_temp_files ();
3419 exit (1);
3420}
3421
3422static void
3423error (msg, arg1, arg2)
3424 char *msg, *arg1, *arg2;
3425{
3426 fprintf (stderr, "%s: ", programname);
3427 fprintf (stderr, msg, arg1, arg2);
3428 fprintf (stderr, "\n");
3429}
3430
3431#endif /* not HAVE_VPRINTF */
3432
3433\f
3434static void
3435validate_all_switches ()
3436{
3437 struct compiler *comp;
3438 register char *p;
3439 register char c;
b3865ca9 3440 struct spec_list *spec;
ed1f651b
RS
3441
3442 for (comp = compilers; comp->spec; comp++)
3443 {
3444 p = comp->spec;
3445 while (c = *p++)
3446 if (c == '%' && *p == '{')
3447 /* We have a switch spec. */
3448 validate_switches (p + 1);
3449 }
3450
b3865ca9
RS
3451 /* look through the linked list of extra specs read from the specs file */
3452 for (spec = specs ; spec ; spec = spec->next)
3453 {
3454 p = spec->spec;
3455 while (c = *p++)
3456 if (c == '%' && *p == '{')
3457 /* We have a switch spec. */
3458 validate_switches (p + 1);
3459 }
3460
ed1f651b
RS
3461 p = link_command_spec;
3462 while (c = *p++)
3463 if (c == '%' && *p == '{')
3464 /* We have a switch spec. */
3465 validate_switches (p + 1);
3466
3467 /* Now notice switches mentioned in the machine-specific specs. */
3468
3469 p = asm_spec;
3470 while (c = *p++)
3471 if (c == '%' && *p == '{')
3472 /* We have a switch spec. */
3473 validate_switches (p + 1);
3474
3475 p = asm_final_spec;
3476 while (c = *p++)
3477 if (c == '%' && *p == '{')
3478 /* We have a switch spec. */
3479 validate_switches (p + 1);
3480
3481 p = cpp_spec;
3482 while (c = *p++)
3483 if (c == '%' && *p == '{')
3484 /* We have a switch spec. */
3485 validate_switches (p + 1);
3486
3487 p = signed_char_spec;
3488 while (c = *p++)
3489 if (c == '%' && *p == '{')
3490 /* We have a switch spec. */
3491 validate_switches (p + 1);
3492
3493 p = cc1_spec;
3494 while (c = *p++)
3495 if (c == '%' && *p == '{')
3496 /* We have a switch spec. */
3497 validate_switches (p + 1);
3498
3499 p = cc1plus_spec;
3500 while (c = *p++)
3501 if (c == '%' && *p == '{')
3502 /* We have a switch spec. */
3503 validate_switches (p + 1);
3504
3505 p = link_spec;
3506 while (c = *p++)
3507 if (c == '%' && *p == '{')
3508 /* We have a switch spec. */
3509 validate_switches (p + 1);
3510
3511 p = lib_spec;
3512 while (c = *p++)
3513 if (c == '%' && *p == '{')
3514 /* We have a switch spec. */
3515 validate_switches (p + 1);
3516
3517 p = startfile_spec;
3518 while (c = *p++)
3519 if (c == '%' && *p == '{')
3520 /* We have a switch spec. */
3521 validate_switches (p + 1);
3522}
3523
3524/* Look at the switch-name that comes after START
3525 and mark as valid all supplied switches that match it. */
3526
3527static void
3528validate_switches (start)
3529 char *start;
3530{
3531 register char *p = start;
3532 char *filter;
3533 register int i;
3534 int suffix = 0;
3535
3536 if (*p == '|')
3537 ++p;
3538
3539 if (*p == '!')
3540 ++p;
3541
3542 if (*p == '.')
3543 suffix = 1, ++p;
3544
3545 filter = p;
3546 while (*p != ':' && *p != '}') p++;
3547
3548 if (suffix)
3549 ;
3550 else if (p[-1] == '*')
3551 {
3552 /* Mark all matching switches as valid. */
3553 --p;
3554 for (i = 0; i < n_switches; i++)
3555 if (!strncmp (switches[i].part1, filter, p - filter))
3556 switches[i].valid = 1;
3557 }
3558 else
3559 {
3560 /* Mark an exact matching switch as valid. */
3561 for (i = 0; i < n_switches; i++)
3562 {
3563 if (!strncmp (switches[i].part1, filter, p - filter)
3564 && switches[i].part1[p - filter] == 0)
3565 switches[i].valid = 1;
3566 }
3567 }
3568}