1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 This paragraph is here to try to keep Sun CC from dying.
21 The number of chars here seems crucial!!!! */
23 /* This program is the user interface to the C compiler and possibly to
24 other compilers. It is used because compilation is a complicated procedure
25 which involves running several programs and passing temporary files between
26 them, forwarding the users switches to those programs selectively,
27 and deleting the temporary files at the end.
29 CC recognizes how to compile each input file by suffixes in the file names.
30 Once it knows which kind of compilation to perform, the procedure for
31 compilation is specified by a string called a "spec". */
33 #include <sys/types.h>
37 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
48 /* Include multi-lib information. */
57 /* Add prototype support. */
59 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
60 #define PROTO(ARGS) ARGS
62 #define PROTO(ARGS) ()
68 #define PVPROTO(ARGS) ARGS
69 #define VPROTO(ARGS) ARGS
70 #define VA_START(va_list,var) va_start(va_list,var)
72 #define PVPROTO(ARGS) ()
73 #define VPROTO(ARGS) (va_alist) va_dcl
74 #define VA_START(va_list,var) va_start(va_list)
78 /* Define a generic NULL if one hasn't already been defined. */
85 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
86 #define GENERIC_PTR void *
88 #define GENERIC_PTR char *
93 #define NULL_PTR ((GENERIC_PTR)0)
100 /* On MSDOS, write temp files in current dir
101 because there's no place else we can expect to use. */
108 /* Test if something is a normal file. */
110 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
113 /* Test if something is a directory. */
115 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
118 /* By default there is no special suffix for executables. */
119 #ifndef EXECUTABLE_SUFFIX
120 #define EXECUTABLE_SUFFIX ""
123 /* By default, colon separates directories in a path. */
124 #ifndef PATH_SEPARATOR
125 #define PATH_SEPARATOR ':'
128 #define obstack_chunk_alloc xmalloc
129 #define obstack_chunk_free free
132 extern char *getenv ();
134 extern int errno
, sys_nerr
;
136 extern const char *const sys_errlist
[];
138 extern char *sys_errlist
[];
141 extern int execv (), execvp ();
143 /* If a stage of compilation returns an exit status >= 1,
144 compilation of that file ceases. */
146 #define MIN_FATAL_STATUS 1
148 /* Flag saying to print the full filename of this file
149 as found through our usual search mechanism. */
151 static char *print_file_name
= NULL
;
153 /* As print_file_name, but search for executable file. */
155 static char *print_prog_name
= NULL
;
157 /* Flag saying to print the relative path we'd use to
158 find libgcc.a given the current compiler flags. */
160 static int print_multi_directory
;
162 /* Flag saying to print the list of subdirectories and
163 compiler flags used to select them in a standard form. */
165 static int print_multi_lib
;
167 /* Flag indicating whether we should print the command and arguments */
169 static int verbose_flag
;
171 /* Nonzero means write "temp" files in source directory
172 and use the source file's name in them, and don't delete them. */
174 static int save_temps_flag
;
176 /* The compiler version. */
178 static char *compiler_version
;
180 /* The target version specified with -V */
182 static char *spec_version
= DEFAULT_TARGET_VERSION
;
184 /* The target machine specified with -b. */
186 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
188 /* Nonzero if cross-compiling.
189 When -b is used, the value comes from the `specs' file. */
192 static int cross_compile
= 1;
194 static int cross_compile
= 0;
197 /* The number of errors that have occurred; the link phase will not be
198 run if this is non-zero. */
199 static int error_count
= 0;
201 /* This is the obstack which we use to allocate many strings. */
203 static struct obstack obstack
;
205 /* This is the obstack to build an environment variable to pass to
206 collect2 that describes all of the relevant switches of what to
207 pass the compiler in building the list of pointers to constructors
210 static struct obstack collect_obstack
;
212 extern char *version_string
;
214 /* Forward declaration for prototypes. */
217 static void set_spec
PROTO((char *, char *));
218 static struct compiler
*lookup_compiler
PROTO((char *, int, char *));
219 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
220 static void add_prefix
PROTO((struct path_prefix
*, char *, int, int, int *));
221 static char *skip_whitespace
PROTO((char *));
222 static void record_temp_file
PROTO((char *, int, int));
223 static void delete_if_ordinary
PROTO((char *));
224 static void delete_temp_files
PROTO((void));
225 static void delete_failure_queue
PROTO((void));
226 static void clear_failure_queue
PROTO((void));
227 static char *choose_temp_base_try
PROTO((char *, char *));
228 static void choose_temp_base
PROTO((void));
229 static int check_live_switch
PROTO((int, int));
230 static char *handle_braces
PROTO((char *));
231 static char *save_string
PROTO((char *, int));
232 static char *concat
PROTO((char *, char *, char *));
233 static int do_spec
PROTO((char *));
234 static int do_spec_1
PROTO((char *, int, char *));
235 static char *find_file
PROTO((char *));
236 static int is_directory
PROTO((char *, char *, int));
237 static void validate_switches
PROTO((char *));
238 static void validate_all_switches
PROTO((void));
239 static void give_switch
PROTO((int, int));
240 static int used_arg
PROTO((char *, int));
241 static void set_multilib_dir
PROTO((void));
242 static void print_multilib_info
PROTO((void));
243 static void pfatal_with_name
PROTO((char *));
244 static void perror_with_name
PROTO((char *));
245 static void perror_exec
PROTO((char *));
247 static void fatal
PVPROTO((char *, ...));
248 static void error
PVPROTO((char *, ...));
250 /* We must not provide any prototype here, even if ANSI C. */
251 static void fatal
PROTO(());
252 static void error
PROTO(());
259 /* Specs are strings containing lines, each of which (if not blank)
260 is made up of a program name, and arguments separated by spaces.
261 The program name must be exact and start from root, since no path
262 is searched and it is unreliable to depend on the current working directory.
263 Redirection of input or output is not supported; the subprograms must
264 accept filenames saying what files to read and write.
266 In addition, the specs can contain %-sequences to substitute variable text
267 or for conditional text. Here is a table of all defined %-sequences.
268 Note that spaces are not generated automatically around the results of
269 expanding these sequences; therefore, you can concatenate them together
270 or with constant text in a single argument.
272 %% substitute one % into the program name or argument.
273 %i substitute the name of the input file being processed.
274 %b substitute the basename of the input file being processed.
275 This is the substring up to (and not including) the last period
276 and not including the directory.
277 %g substitute the temporary-file-name-base. This is a string chosen
278 once per compilation. Different temporary file names are made by
279 concatenation of constant strings on the end, as in `%g.s'.
280 %g also has the same effect of %d.
281 %u like %g, but make the temporary file name unique.
282 %U returns the last file name generated with %u.
283 %d marks the argument containing or following the %d as a
284 temporary file name, so that that file will be deleted if CC exits
285 successfully. Unlike %g, this contributes no text to the argument.
286 %w marks the argument containing or following the %w as the
287 "output file" of this compilation. This puts the argument
288 into the sequence of arguments that %o will substitute later.
290 like %{...} but mark last argument supplied within
291 as a file to be deleted on failure.
292 %o substitutes the names of all the output files, with spaces
293 automatically placed around them. You should write spaces
294 around the %o as well or the results are undefined.
295 %o is for use in the specs for running the linker.
296 Input files whose names have no recognized suffix are not compiled
297 at all, but they are included among the output files, so they will
299 %p substitutes the standard macro predefinitions for the
300 current target machine. Use this when running cpp.
301 %P like %p, but puts `__' before and after the name of each macro.
302 (Except macros that already have __.)
304 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
305 %s current argument is the name of a library or startup file of some sort.
306 Search for that file in a standard list of directories
307 and substitute the full name found.
308 %eSTR Print STR as an error message. STR is terminated by a newline.
309 Use this when inconsistent options are detected.
310 %x{OPTION} Accumulate an option for %X.
311 %X Output the accumulated linker options specified by compilations.
312 %Y Output the accumulated assembler options specified by compilations.
313 %v1 Substitute the major version number of GCC.
314 (For version 2.5.n, this is 2.)
315 %v2 Substitute the minor version number of GCC.
316 (For version 2.5.n, this is 5.)
317 %a process ASM_SPEC as a spec.
318 This allows config.h to specify part of the spec for running as.
319 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
320 used here. This can be used to run a post-processor after the
321 assembler has done it's job.
322 %D Dump out a -L option for each directory in startfile_prefix.
323 If multilib_dir is set, extra entries are generated with it affixed.
324 %l process LINK_SPEC as a spec.
325 %L process LIB_SPEC as a spec.
326 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
327 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
328 %c process SIGNED_CHAR_SPEC as a spec.
329 %C process CPP_SPEC as a spec. A capital C is actually used here.
330 %1 process CC1_SPEC as a spec.
331 %2 process CC1PLUS_SPEC as a spec.
332 %| output "-" if the input for the current command is coming from a pipe.
333 %* substitute the variable part of a matched option. (See below.)
334 Note that each comma in the substituted string is replaced by
336 %{S} substitutes the -S switch, if that switch was given to CC.
337 If that switch was not specified, this substitutes nothing.
338 Here S is a metasyntactic variable.
339 %{S*} substitutes all the switches specified to CC whose names start
340 with -S. This is used for -o, -D, -I, etc; switches that take
341 arguments. CC considers `-o foo' as being one switch whose
342 name starts with `o'. %{o*} would substitute this text,
343 including the space; thus, two arguments would be generated.
344 %{S*:X} substitutes X if one or more switches whose names start with -S are
345 specified to CC. Note that the tail part of the -S option
346 (i.e. the part matched by the `*') will be substituted for each
347 occurrence of %* within X.
348 %{S:X} substitutes X, but only if the -S switch was given to CC.
349 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
350 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
351 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
352 %{.S:X} substitutes X, but only if processing a file with suffix S.
353 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
354 %(Spec) processes a specification defined in a specs file as *Spec:
355 %[Spec] as above, but put __ around -D arguments
357 The conditional text X in a %{S:X} or %{!S:X} construct may contain
358 other nested % constructs or spaces, or even newlines. They are
359 processed as usual, as described above.
361 The -O, -f, -m, and -W switches are handled specifically in these
362 constructs. If another value of -O or the negated form of a -f, -m, or
363 -W switch is found later in the command line, the earlier switch
364 value is ignored, except with {S*} where S is just one letter; this
365 passes all matching options.
367 The character | is used to indicate that a command should be piped to
368 the following command, but only if -pipe is specified.
370 Note that it is built into CC which switches take arguments and which
371 do not. You might think it would be useful to generalize this to
372 allow each compiler's spec to say which switches take arguments. But
373 this cannot be done in a consistent fashion. CC cannot even decide
374 which input files have been specified without knowing which switches
375 take arguments, and it must know which input files to compile in order
376 to tell which compilers to run.
378 CC also knows implicitly that arguments starting in `-l' are to be
379 treated as compiler output files, and passed to the linker in their
380 proper position among the other output files. */
382 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
384 /* config.h can define ASM_SPEC to provide extra args to the assembler
385 or extra switch-translations. */
390 /* config.h can define ASM_FINAL_SPEC to run a post processor after
391 the assembler has run. */
392 #ifndef ASM_FINAL_SPEC
393 #define ASM_FINAL_SPEC ""
396 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
397 or extra switch-translations. */
402 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
403 or extra switch-translations. */
408 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
409 or extra switch-translations. */
411 #define CC1PLUS_SPEC ""
414 /* config.h can define LINK_SPEC to provide extra args to the linker
415 or extra switch-translations. */
420 /* config.h can define LIB_SPEC to override the default libraries. */
422 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
425 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
426 #ifndef STARTFILE_SPEC
427 #define STARTFILE_SPEC \
428 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
431 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
432 Make the string nonempty to require spaces there. */
433 #ifndef SWITCHES_NEED_SPACES
434 #define SWITCHES_NEED_SPACES ""
437 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
439 #define ENDFILE_SPEC ""
442 /* This spec is used for telling cpp whether char is signed or not. */
443 #ifndef SIGNED_CHAR_SPEC
444 /* Use #if rather than ?:
445 because MIPS C compiler rejects like ?: in initializers. */
446 #if DEFAULT_SIGNED_CHAR
447 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
449 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
453 /* MULTILIB_SELECT comes from multilib.h. It gives a
454 string interpreted by set_multilib_dir to select a library
455 subdirectory based on the compiler options. */
456 #ifndef MULTILIB_SELECT
457 #define MULTILIB_SELECT ". ;"
460 static char *cpp_spec
= CPP_SPEC
;
461 static char *cpp_predefines
= CPP_PREDEFINES
;
462 static char *cc1_spec
= CC1_SPEC
;
463 static char *cc1plus_spec
= CC1PLUS_SPEC
;
464 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
465 static char *asm_spec
= ASM_SPEC
;
466 static char *asm_final_spec
= ASM_FINAL_SPEC
;
467 static char *link_spec
= LINK_SPEC
;
468 static char *lib_spec
= LIB_SPEC
;
469 static char *endfile_spec
= ENDFILE_SPEC
;
470 static char *startfile_spec
= STARTFILE_SPEC
;
471 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
472 static char *multilib_select
= MULTILIB_SELECT
;
474 /* This defines which switch letters take arguments. */
476 #ifndef SWITCH_TAKES_ARG
477 #define SWITCH_TAKES_ARG(CHAR) \
478 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
479 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
480 || (CHAR) == 'I' || (CHAR) == 'm' \
481 || (CHAR) == 'L' || (CHAR) == 'A')
484 /* This defines which multi-letter switches take arguments. */
486 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
487 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
488 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
489 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
490 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
491 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore"))
493 #ifndef WORD_SWITCH_TAKES_ARG
494 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
497 /* Record the mapping from file suffixes for compilation specs. */
501 char *suffix
; /* Use this compiler for input files
502 whose names end in this suffix. */
504 char *spec
[4]; /* To use this compiler, concatenate these
505 specs and pass to do_spec. */
508 /* Pointer to a vector of `struct compiler' that gives the spec for
509 compiling a file, based on its suffix.
510 A file that does not end in any of these suffixes will be passed
511 unchanged to the loader and nothing else will be done to it.
513 An entry containing two 0s is used to terminate the vector.
515 If multiple entries match a file, the last matching one is used. */
517 static struct compiler
*compilers
;
519 /* Number of entries in `compilers', not counting the null terminator. */
521 static int n_compilers
;
523 /* The default list of file name suffixes and their compilation specs. */
525 static struct compiler default_compilers
[] =
529 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
530 %{C:%{!E:%eGNU C does not support -C without using -E}}\
531 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
532 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
533 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
534 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
535 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
536 %{traditional-cpp:-traditional}\
537 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
538 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
539 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
540 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
541 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
542 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
544 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
545 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
546 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
547 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
548 %{!pipe:%g.s} %A\n }}}}"},
550 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
551 %{C:%{!E:%eGNU C does not support -C without using -E}}\
552 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
553 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
554 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
555 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
556 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
557 %{traditional-cpp:-traditional}\
558 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
560 %{!E:%e-E required when input is from standard input}"},
561 {".m", "@objective-c"},
563 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
564 %{C:%{!E:%eGNU C does not support -C without using -E}}\
565 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
566 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
567 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
568 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
569 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
570 %{traditional-cpp:-traditional}\
571 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
572 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
573 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
574 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
575 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
576 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
577 -lang-objc %{gen-decls} \
579 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
580 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
581 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
582 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
583 %{!pipe:%g.s} %A\n }}}}"},
586 "%{!E:%eCompilation of header file requested} \
587 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
588 %{C:%{!E:%eGNU C does not support -C without using -E}}\
589 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
590 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
591 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
592 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
593 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
594 %{traditional-cpp:-traditional}\
595 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
602 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
603 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
604 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
605 -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
606 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
607 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
608 %{traditional-cpp:-traditional} %{trigraphs}\
609 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
610 %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
611 "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\
612 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
613 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
614 %{traditional} %{v:-version} %{pg:-p} %{p}\
615 %{f*} %{+e*} %{aux-info*}\
616 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
617 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\
618 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
619 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
620 %{!pipe:%g.s} %A\n }}}}"},
621 {".i", "@cpp-output"},
623 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
624 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
625 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
627 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
628 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
629 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
630 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
631 %{!pipe:%g.s} %A\n }}}}"},
632 {".ii", "@c++-cpp-output"},
634 "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
635 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
636 %{traditional} %{v:-version} %{pg:-p} %{p}\
637 %{f*} %{+e*} %{aux-info*}\
638 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
639 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
640 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
641 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
642 %{!pipe:%g.s} %A\n }}}}"},
643 {".s", "@assembler"},
645 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
646 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
648 {".S", "@assembler-with-cpp"},
649 {"@assembler-with-cpp",
650 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
651 %{C:%{!E:%eGNU C does not support -C without using -E}}\
652 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
653 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
654 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
655 %{traditional-cpp:-traditional}\
656 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
657 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
658 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
659 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
660 %{!pipe:%g.s} %A\n }}}}"},
665 "%{!M:%{!MM:%{!E:gnat1 %{k8:-gnatk8} %{w:-gnatws} %{!Q:-quiet}\
666 -dumpbase %b.ada %{g*} %{O*} %{p} %{pg:-p} %{f*}\
668 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
669 %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
670 %{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
671 %{c:%W{o*}%{!o*:-o %w%b.o}}\
672 %{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n}}}}}} "},
673 /* Mark end of table */
677 /* Number of elements in default_compilers, not counting the terminator. */
679 static int n_default_compilers
680 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
682 /* Here is the spec for running the linker, after compiling all files. */
684 /* -u* was put back because both BSD and SysV seem to support it. */
685 /* %{static:} simply prevents an error message if the target machine
686 doesn't handle -static. */
687 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
688 scripts which exist in user specified directories, or in standard
690 #ifdef LINK_LIBGCC_SPECIAL_1
691 /* Have gcc do the search for libgcc.a, but generate -L options as usual. */
692 static char *link_command_spec
= "\
694 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
695 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
696 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
697 %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
699 #ifdef LINK_LIBGCC_SPECIAL
700 /* Have gcc do the search for libgcc.a, and don't generate -L options. */
701 static char *link_command_spec
= "\
703 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
704 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
705 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
706 %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
708 /* Use -L and have the linker do the search for -lgcc. */
709 static char *link_command_spec
= "\
711 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
712 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
713 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
714 %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}";
718 /* A vector of options to give to the linker.
719 These options are accumulated by -Xlinker and -Wl,
720 and substituted into the linker command with %X. */
721 static int n_linker_options
;
722 static char **linker_options
;
724 /* A vector of options to give to the assembler.
725 These options are accumulated by -Wa,
726 and substituted into the assembler command with %X. */
727 static int n_assembler_options
;
728 static char **assembler_options
;
730 /* Define how to map long options into short ones. */
732 /* This structure describes one mapping. */
735 /* The long option's name. */
737 /* The equivalent short option. */
739 /* Argument info. A string of flag chars; NULL equals no options.
740 a => argument required.
741 o => argument optional.
742 j => join argument to equivalent, making one word.
743 * => allow other text after NAME as an argument. */
747 /* This is the table of mappings. Mappings are tried sequentially
748 for each option encountered; the first one that matches, wins. */
750 struct option_map option_map
[] =
752 {"--profile-blocks", "-a", 0},
753 {"--target", "-b", "a"},
754 {"--compile", "-c", 0},
755 {"--dump", "-d", "a"},
756 {"--entry", "-e", 0},
757 {"--debug", "-g", "oj"},
758 {"--include", "-include", "a"},
759 {"--imacros", "-imacros", "a"},
760 {"--include-prefix", "-iprefix", "a"},
761 {"--include-directory-after", "-idirafter", "a"},
762 {"--include-with-prefix", "-iwithprefix", "a"},
763 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
764 {"--include-with-prefix-after", "-iwithprefix", "a"},
765 {"--machine-", "-m", "*j"},
766 {"--machine", "-m", "aj"},
767 {"--no-standard-includes", "-nostdinc", 0},
768 {"--no-standard-libraries", "-nostdlib", 0},
769 {"--no-precompiled-includes", "-noprecomp", 0},
770 {"--output", "-o", "a"},
771 {"--profile", "-p", 0},
772 {"--quiet", "-q", 0},
773 {"--silent", "-q", 0},
774 {"--force-link", "-u", "a"},
775 {"--verbose", "-v", 0},
776 {"--version", "-dumpversion", 0},
777 {"--no-warnings", "-w", 0},
778 {"--language", "-x", "a"},
780 {"--assert", "-A", "a"},
781 {"--prefix", "-B", "a"},
782 {"--comments", "-C", 0},
783 {"--define-macro", "-D", "a"},
784 {"--preprocess", "-E", 0},
785 {"--trace-includes", "-H", 0},
786 {"--include-directory", "-I", "a"},
787 {"--include-barrier", "-I-", 0},
788 {"--library-directory", "-L", "a"},
789 {"--dependencies", "-M", 0},
790 {"--user-dependencies", "-MM", 0},
791 {"--write-dependencies", "-MD", 0},
792 {"--write-user-dependencies", "-MMD", 0},
793 {"--print-missing-file-dependencies", "-MG", 0},
794 {"--optimize", "-O", "oj"},
795 {"--no-line-commands", "-P", 0},
796 {"--assemble", "-S", 0},
797 {"--undefine-macro", "-U", "a"},
798 {"--use-version", "-V", "a"},
799 {"--for-assembler", "-Wa", "a"},
800 {"--extra-warnings", "-W", 0},
801 {"--all-warnings", "-Wall", 0},
802 {"--warn-", "-W", "*j"},
803 {"--for-linker", "-Xlinker", "a"},
805 {"--ansi", "-ansi", 0},
806 {"--traditional", "-traditional", 0},
807 {"--traditional-cpp", "-traditional-cpp", 0},
808 {"--trigraphs", "-trigraphs", 0},
809 {"--pipe", "-pipe", 0},
810 {"--dumpbase", "-dumpbase", "a"},
811 {"--pedantic", "-pedantic", 0},
812 {"--pedantic-errors", "-pedantic-errors", 0},
813 {"--save-temps", "-save-temps", 0},
814 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
815 {"--print-file-name", "-print-file-name=", "aj"},
816 {"--print-prog-name", "-print-prog-name=", "aj"},
817 {"--print-multi-lib", "-print-multi-lib", 0},
818 {"--print-multi-directory", "-print-multi-directory", 0},
819 {"--static", "-static", 0},
820 {"--shared", "-shared", 0},
821 {"--symbolic", "-symbolic", 0},
825 /* Translate the options described by *ARGCP and *ARGVP.
826 Make a new vector and store it back in *ARGVP,
827 and store its length in *ARGVC. */
830 translate_options (argcp
, argvp
)
836 char **argv
= *argvp
;
837 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
841 newv
[newindex
++] = argv
[i
++];
845 /* Translate -- options. */
846 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
848 /* Find a mapping that applies to this option. */
849 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
851 int optlen
= strlen (option_map
[j
].name
);
852 int complen
= strlen (argv
[i
]);
853 char *arginfo
= option_map
[j
].arg_info
;
857 if (complen
> optlen
)
859 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
861 int extra
= strlen (argv
[i
]) > optlen
;
866 /* If the option has an argument, accept that. */
867 if (argv
[i
][optlen
] == '=')
868 arg
= argv
[i
] + optlen
+ 1;
869 /* If this mapping allows extra text at end of name,
870 accept that as "argument". */
871 else if (index (arginfo
, '*') != 0)
872 arg
= argv
[i
] + optlen
;
873 /* Otherwise, extra text at end means mismatch.
874 Try other mappings. */
878 else if (index (arginfo
, '*') != 0)
879 error ("Incomplete `%s' option", option_map
[j
].name
);
881 /* Handle arguments. */
882 if (index (arginfo
, 'o') != 0)
887 error ("Missing argument to `%s' option",
892 else if (index (arginfo
, '*') != 0)
894 else if (index (arginfo
, 'a') == 0)
897 error ("Extraneous argument to `%s' option",
902 /* Store the translation as one argv elt or as two. */
903 if (arg
!= 0 && index (arginfo
, 'j') != 0)
904 newv
[newindex
++] = concat (option_map
[j
].equivalent
,
908 newv
[newindex
++] = option_map
[j
].equivalent
;
909 newv
[newindex
++] = arg
;
912 newv
[newindex
++] = option_map
[j
].equivalent
;
919 /* Handle old-fashioned options--just copy them through,
920 with their arguments. */
921 else if (argv
[i
][0] == '-')
923 char *p
= argv
[i
] + 1;
927 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
928 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
929 else if (WORD_SWITCH_TAKES_ARG (p
))
930 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
931 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
934 else if (! strcmp (p
, "Xlinker"))
937 /* Watch out for an option at the end of the command line that
938 is missing arguments, and avoid skipping past the end of the
940 if (nskip
+ i
> argc
)
945 newv
[newindex
++] = argv
[i
++];
950 /* Ordinary operands, or +e options. */
951 newv
[newindex
++] = argv
[i
++];
960 /* Read compilation specs from a file named FILENAME,
961 replacing the default ones.
963 A suffix which starts with `*' is a definition for
964 one of the machine-specific sub-specs. The "suffix" should be
965 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
966 The corresponding spec is stored in asm_spec, etc.,
967 rather than in the `compilers' vector.
969 Anything invalid in the file is a fatal error. */
972 read_specs (filename
)
981 fprintf (stderr
, "Reading specs from %s\n", filename
);
983 /* Open and stat the file. */
984 desc
= open (filename
, 0, 0);
986 pfatal_with_name (filename
);
987 if (stat (filename
, &statbuf
) < 0)
988 pfatal_with_name (filename
);
990 /* Read contents of file into BUFFER. */
991 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
992 read (desc
, buffer
, (unsigned) statbuf
.st_size
);
993 buffer
[statbuf
.st_size
] = 0;
996 /* Scan BUFFER for specs, putting them in the vector. */
1002 char *in
, *out
, *p1
, *p2
;
1004 /* Advance P in BUFFER to the next nonblank nocomment line. */
1005 p
= skip_whitespace (p
);
1009 /* Find the colon that should end the suffix. */
1011 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
1012 /* The colon shouldn't be missing. */
1014 fatal ("specs file malformed after %d characters", p1
- buffer
);
1015 /* Skip back over trailing whitespace. */
1017 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
1018 /* Copy the suffix to a string. */
1019 suffix
= save_string (p
, p2
- p
);
1020 /* Find the next line. */
1021 p
= skip_whitespace (p1
+ 1);
1023 fatal ("specs file malformed after %d characters", p
- buffer
);
1025 /* Find next blank line. */
1026 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
1027 /* Specs end at the blank line and do not include the newline. */
1028 spec
= save_string (p
, p1
- p
);
1031 /* Delete backslash-newline sequences from the spec. */
1036 if (in
[0] == '\\' && in
[1] == '\n')
1038 else if (in
[0] == '#')
1040 while (*in
&& *in
!= '\n') in
++;
1047 if (suffix
[0] == '*')
1049 if (! strcmp (suffix
, "*link_command"))
1050 link_command_spec
= spec
;
1052 set_spec (suffix
+ 1, spec
);
1056 /* Add this pair to the vector. */
1058 = ((struct compiler
*)
1059 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
1060 compilers
[n_compilers
].suffix
= suffix
;
1061 bzero ((char *) compilers
[n_compilers
].spec
,
1062 sizeof compilers
[n_compilers
].spec
);
1063 compilers
[n_compilers
].spec
[0] = spec
;
1065 bzero ((char *) &compilers
[n_compilers
],
1066 sizeof compilers
[n_compilers
]);
1070 link_command_spec
= spec
;
1073 if (link_command_spec
== 0)
1074 fatal ("spec file has no spec for linking");
1083 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1084 be considered whitespace. */
1085 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1087 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1091 while (*p
!= '\n') p
++;
1101 /* Structure to keep track of the specs that have been defined so far. These
1102 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1106 char *name
; /* Name of the spec. */
1107 char *spec
; /* The spec itself. */
1108 struct spec_list
*next
; /* Next spec in linked list. */
1111 /* List of specs that have been defined so far. */
1113 static struct spec_list
*specs
= (struct spec_list
*) 0;
1115 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1116 removed; If the spec starts with a + then SPEC is added to the end of the
1120 set_spec (name
, spec
)
1124 struct spec_list
*sl
;
1127 /* See if the spec already exists */
1128 for (sl
= specs
; sl
; sl
= sl
->next
)
1129 if (strcmp (sl
->name
, name
) == 0)
1134 /* Not found - make it */
1135 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1136 sl
->name
= save_string (name
, strlen (name
));
1137 sl
->spec
= save_string ("", 0);
1142 old_spec
= sl
->spec
;
1143 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
1144 sl
->spec
= concat (old_spec
, spec
+ 1, "");
1146 sl
->spec
= save_string (spec
, strlen (spec
));
1148 if (! strcmp (name
, "asm"))
1149 asm_spec
= sl
->spec
;
1150 else if (! strcmp (name
, "asm_final"))
1151 asm_final_spec
= sl
->spec
;
1152 else if (! strcmp (name
, "cc1"))
1153 cc1_spec
= sl
->spec
;
1154 else if (! strcmp (name
, "cc1plus"))
1155 cc1plus_spec
= sl
->spec
;
1156 else if (! strcmp (name
, "cpp"))
1157 cpp_spec
= sl
->spec
;
1158 else if (! strcmp (name
, "endfile"))
1159 endfile_spec
= sl
->spec
;
1160 else if (! strcmp (name
, "lib"))
1161 lib_spec
= sl
->spec
;
1162 else if (! strcmp (name
, "link"))
1163 link_spec
= sl
->spec
;
1164 else if (! strcmp (name
, "predefines"))
1165 cpp_predefines
= sl
->spec
;
1166 else if (! strcmp (name
, "signed_char"))
1167 signed_char_spec
= sl
->spec
;
1168 else if (! strcmp (name
, "startfile"))
1169 startfile_spec
= sl
->spec
;
1170 else if (! strcmp (name
, "switches_need_spaces"))
1171 switches_need_spaces
= sl
->spec
;
1172 else if (! strcmp (name
, "cross_compile"))
1173 cross_compile
= atoi (sl
->spec
);
1174 else if (! strcmp (name
, "multilib"))
1175 multilib_select
= sl
->spec
;
1176 /* Free the old spec */
1181 /* Accumulate a command (program name and args), and run it. */
1183 /* Vector of pointers to arguments in the current line of specifications. */
1185 static char **argbuf
;
1187 /* Number of elements allocated in argbuf. */
1189 static int argbuf_length
;
1191 /* Number of elements in argbuf currently in use (containing args). */
1193 static int argbuf_index
;
1195 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1196 temp file. Used only if MKTEMP_EACH_FILE. */
1198 static struct temp_name
{
1199 char *suffix
; /* suffix associated with the code. */
1200 int length
; /* strlen (suffix). */
1201 int unique
; /* Indicates whether %g or %u/%U was used. */
1202 char *filename
; /* associated filename. */
1203 int filename_length
; /* strlen (filename). */
1204 struct temp_name
*next
;
1207 /* Number of commands executed so far. */
1209 static int execution_count
;
1211 /* Number of commands that exited with a signal. */
1213 static int signal_count
;
1215 /* Name with which this program was invoked. */
1217 static char *programname
;
1219 /* Structures to keep track of prefixes to try when looking for files. */
1223 char *prefix
; /* String to prepend to the path. */
1224 struct prefix_list
*next
; /* Next in linked list. */
1225 int require_machine_suffix
; /* Don't use without machine_suffix. */
1226 /* 2 means try both machine_suffix and just_machine_suffix. */
1227 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1232 struct prefix_list
*plist
; /* List of prefixes to try */
1233 int max_len
; /* Max length of a prefix in PLIST */
1234 char *name
; /* Name of this list (used in config stuff) */
1237 /* List of prefixes to try when looking for executables. */
1239 static struct path_prefix exec_prefix
= { 0, 0, "exec" };
1241 /* List of prefixes to try when looking for startup (crt0) files. */
1243 static struct path_prefix startfile_prefix
= { 0, 0, "startfile" };
1245 /* List of prefixes to try when looking for include files. */
1247 static struct path_prefix include_prefix
= { 0, 0, "include" };
1249 /* Suffix to attach to directories searched for commands.
1250 This looks like `MACHINE/VERSION/'. */
1252 static char *machine_suffix
= 0;
1254 /* Suffix to attach to directories searched for commands.
1255 This is just `MACHINE/'. */
1257 static char *just_machine_suffix
= 0;
1259 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1261 static char *gcc_exec_prefix
;
1263 /* Default prefixes to attach to command names. */
1265 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1266 #undef MD_EXEC_PREFIX
1267 #undef MD_STARTFILE_PREFIX
1268 #undef MD_STARTFILE_PREFIX_1
1271 #ifndef STANDARD_EXEC_PREFIX
1272 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1273 #endif /* !defined STANDARD_EXEC_PREFIX */
1275 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1276 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1277 #ifdef MD_EXEC_PREFIX
1278 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1281 #ifndef STANDARD_STARTFILE_PREFIX
1282 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1283 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1285 #ifdef MD_STARTFILE_PREFIX
1286 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1288 #ifdef MD_STARTFILE_PREFIX_1
1289 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1291 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1292 static char *standard_startfile_prefix_1
= "/lib/";
1293 static char *standard_startfile_prefix_2
= "/usr/lib/";
1295 #ifndef TOOLDIR_BASE_PREFIX
1296 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1298 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1299 static char *tooldir_prefix
;
1301 /* Subdirectory to use for locating libraries. Set by
1302 set_multilib_dir based on the compilation options. */
1304 static char *multilib_dir
;
1306 /* Clear out the vector of arguments (after a command is executed). */
1314 /* Add one argument to the vector at the end.
1315 This is done when a space is seen or at the end of the line.
1316 If DELETE_ALWAYS is nonzero, the arg is a filename
1317 and the file should be deleted eventually.
1318 If DELETE_FAILURE is nonzero, the arg is a filename
1319 and the file should be deleted if this compilation fails. */
1322 store_arg (arg
, delete_always
, delete_failure
)
1324 int delete_always
, delete_failure
;
1326 if (argbuf_index
+ 1 == argbuf_length
)
1328 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1331 argbuf
[argbuf_index
++] = arg
;
1332 argbuf
[argbuf_index
] = 0;
1334 if (delete_always
|| delete_failure
)
1335 record_temp_file (arg
, delete_always
, delete_failure
);
1338 /* Record the names of temporary files we tell compilers to write,
1339 and delete them at the end of the run. */
1341 /* This is the common prefix we use to make temp file names.
1342 It is chosen once for each run of this program.
1343 It is substituted into a spec by %g.
1344 Thus, all temp file names contain this prefix.
1345 In practice, all temp file names start with this prefix.
1347 This prefix comes from the envvar TMPDIR if it is defined;
1348 otherwise, from the P_tmpdir macro if that is defined;
1349 otherwise, in /usr/tmp or /tmp. */
1351 static char *temp_filename
;
1353 /* Length of the prefix. */
1355 static int temp_filename_length
;
1357 /* Define the list of temporary files to delete. */
1362 struct temp_file
*next
;
1365 /* Queue of files to delete on success or failure of compilation. */
1366 static struct temp_file
*always_delete_queue
;
1367 /* Queue of files to delete on failure of compilation. */
1368 static struct temp_file
*failure_delete_queue
;
1370 /* Record FILENAME as a file to be deleted automatically.
1371 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1372 otherwise delete it in any case.
1373 FAIL_DELETE nonzero means delete it if a compilation step fails;
1374 otherwise delete it in any case. */
1377 record_temp_file (filename
, always_delete
, fail_delete
)
1382 register char *name
;
1383 name
= xmalloc (strlen (filename
) + 1);
1384 strcpy (name
, filename
);
1388 register struct temp_file
*temp
;
1389 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1390 if (! strcmp (name
, temp
->name
))
1392 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1393 temp
->next
= always_delete_queue
;
1395 always_delete_queue
= temp
;
1401 register struct temp_file
*temp
;
1402 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1403 if (! strcmp (name
, temp
->name
))
1405 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1406 temp
->next
= failure_delete_queue
;
1408 failure_delete_queue
= temp
;
1413 /* Delete all the temporary files whose names we previously recorded. */
1416 delete_if_ordinary (name
)
1423 printf ("Delete %s? (y or n) ", name
);
1427 while ((c
= getchar ()) != '\n' && c
!= EOF
) ;
1428 if (i
== 'y' || i
== 'Y')
1430 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1431 if (unlink (name
) < 0)
1433 perror_with_name (name
);
1437 delete_temp_files ()
1439 register struct temp_file
*temp
;
1441 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1442 delete_if_ordinary (temp
->name
);
1443 always_delete_queue
= 0;
1446 /* Delete all the files to be deleted on error. */
1449 delete_failure_queue ()
1451 register struct temp_file
*temp
;
1453 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1454 delete_if_ordinary (temp
->name
);
1458 clear_failure_queue ()
1460 failure_delete_queue
= 0;
1463 /* Compute a string to use as the base of all temporary file names.
1464 It is substituted for %g. */
1467 choose_temp_base_try (try, base
)
1474 else if (try == (char *)0)
1476 else if (access (try, R_OK
| W_OK
) != 0)
1489 base
= choose_temp_base_try (getenv ("TMPDIR"), base
);
1490 base
= choose_temp_base_try (getenv ("TMP"), base
);
1491 base
= choose_temp_base_try (getenv ("TEMP"), base
);
1494 base
= choose_temp_base_try (P_tmpdir
, base
);
1497 base
= choose_temp_base_try ("/usr/tmp", base
);
1498 base
= choose_temp_base_try ("/tmp", base
);
1500 /* If all else fails, use the current directory! */
1501 if (base
== (char *)0)
1504 len
= strlen (base
);
1505 temp_filename
= xmalloc (len
+ sizeof("/ccXXXXXX") + 1);
1506 strcpy (temp_filename
, base
);
1507 if (len
> 0 && temp_filename
[len
-1] != '/')
1508 temp_filename
[len
++] = '/';
1509 strcpy (temp_filename
+ len
, "ccXXXXXX");
1511 mktemp (temp_filename
);
1512 temp_filename_length
= strlen (temp_filename
);
1513 if (temp_filename_length
== 0)
1518 /* Routine to add variables to the environment. We do this to pass
1519 the pathname of the gcc driver, and the directories search to the
1520 collect2 program, which is being run as ld. This way, we can be
1521 sure of executing the right compiler when collect2 wants to build
1522 constructors and destructors. Since the environment variables we
1523 use come from an obstack, we don't have to worry about allocating
1532 #ifndef VMS /* nor about VMS */
1534 extern char **environ
;
1535 char **old_environ
= environ
;
1539 int str_len
= strlen (str
);
1543 while ((ch
= *p
++) != '\0' && ch
!= '=')
1549 /* Search for replacing an existing environment variable, and
1550 count the number of total environment variables. */
1551 for (envp
= old_environ
; *envp
; envp
++)
1554 if (!strncmp (str
, *envp
, name_len
))
1561 /* Add a new environment variable */
1562 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1564 bcopy ((char *) old_environ
, (char *) (environ
+ 1),
1565 sizeof (char *) * (num_envs
+1));
1570 #endif /* HAVE_PUTENV */
1573 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1576 putenv_from_prefixes (paths
, env_var
)
1577 struct path_prefix
*paths
;
1580 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1582 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1583 int first_time
= TRUE
;
1584 struct prefix_list
*pprefix
;
1586 obstack_grow (&collect_obstack
, env_var
, strlen (env_var
));
1588 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1590 int len
= strlen (pprefix
->prefix
);
1593 && is_directory (pprefix
->prefix
, machine_suffix
, 0))
1596 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1599 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1600 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1603 if (just_machine_suffix
1604 && pprefix
->require_machine_suffix
== 2
1605 && is_directory (pprefix
->prefix
, just_machine_suffix
, 0))
1608 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1611 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1612 obstack_grow (&collect_obstack
, just_machine_suffix
,
1616 if (!pprefix
->require_machine_suffix
)
1619 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1622 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1625 obstack_1grow (&collect_obstack
, '\0');
1626 putenv (obstack_finish (&collect_obstack
));
1630 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1631 access to check permissions.
1632 Return 0 if not found, otherwise return its name, allocated with malloc. */
1635 find_a_file (pprefix
, name
, mode
)
1636 struct path_prefix
*pprefix
;
1641 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1642 struct prefix_list
*pl
;
1643 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1646 len
+= strlen (machine_suffix
);
1648 temp
= xmalloc (len
);
1650 /* Determine the filename to execute (special case for absolute paths). */
1654 if (access (name
, mode
))
1656 strcpy (temp
, name
);
1661 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1665 /* Some systems have a suffix for executable files.
1666 So try appending that first. */
1667 if (file_suffix
[0] != 0)
1669 strcpy (temp
, pl
->prefix
);
1670 strcat (temp
, machine_suffix
);
1671 strcat (temp
, name
);
1672 strcat (temp
, file_suffix
);
1673 if (access (temp
, mode
) == 0)
1675 if (pl
->used_flag_ptr
!= 0)
1676 *pl
->used_flag_ptr
= 1;
1681 /* Now try just the name. */
1682 strcpy (temp
, pl
->prefix
);
1683 strcat (temp
, machine_suffix
);
1684 strcat (temp
, name
);
1685 if (access (temp
, mode
) == 0)
1687 if (pl
->used_flag_ptr
!= 0)
1688 *pl
->used_flag_ptr
= 1;
1693 /* Certain prefixes are tried with just the machine type,
1694 not the version. This is used for finding as, ld, etc. */
1695 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
1697 /* Some systems have a suffix for executable files.
1698 So try appending that first. */
1699 if (file_suffix
[0] != 0)
1701 strcpy (temp
, pl
->prefix
);
1702 strcat (temp
, just_machine_suffix
);
1703 strcat (temp
, name
);
1704 strcat (temp
, file_suffix
);
1705 if (access (temp
, mode
) == 0)
1707 if (pl
->used_flag_ptr
!= 0)
1708 *pl
->used_flag_ptr
= 1;
1713 strcpy (temp
, pl
->prefix
);
1714 strcat (temp
, just_machine_suffix
);
1715 strcat (temp
, name
);
1716 if (access (temp
, mode
) == 0)
1718 if (pl
->used_flag_ptr
!= 0)
1719 *pl
->used_flag_ptr
= 1;
1724 /* Certain prefixes can't be used without the machine suffix
1725 when the machine or version is explicitly specified. */
1726 if (!pl
->require_machine_suffix
)
1728 /* Some systems have a suffix for executable files.
1729 So try appending that first. */
1730 if (file_suffix
[0] != 0)
1732 strcpy (temp
, pl
->prefix
);
1733 strcat (temp
, name
);
1734 strcat (temp
, file_suffix
);
1735 if (access (temp
, mode
) == 0)
1737 if (pl
->used_flag_ptr
!= 0)
1738 *pl
->used_flag_ptr
= 1;
1743 strcpy (temp
, pl
->prefix
);
1744 strcat (temp
, name
);
1745 if (access (temp
, mode
) == 0)
1747 if (pl
->used_flag_ptr
!= 0)
1748 *pl
->used_flag_ptr
= 1;
1758 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1759 at the start of the list, otherwise it goes at the end.
1761 If WARN is nonzero, we will warn if no file is found
1762 through this prefix. WARN should point to an int
1763 which will be set to 1 if this entry is used.
1765 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1766 the complete value of machine_suffix.
1767 2 means try both machine_suffix and just_machine_suffix. */
1770 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1771 struct path_prefix
*pprefix
;
1774 int require_machine_suffix
;
1777 struct prefix_list
*pl
, **prev
;
1780 if (!first
&& pprefix
->plist
)
1782 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1787 prev
= &pprefix
->plist
;
1789 /* Keep track of the longest prefix */
1791 len
= strlen (prefix
);
1792 if (len
> pprefix
->max_len
)
1793 pprefix
->max_len
= len
;
1795 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1796 pl
->prefix
= save_string (prefix
, len
);
1797 pl
->require_machine_suffix
= require_machine_suffix
;
1798 pl
->used_flag_ptr
= warn
;
1805 pl
->next
= (struct prefix_list
*) 0;
1809 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1812 unused_prefix_warnings (pprefix
)
1813 struct path_prefix
*pprefix
;
1815 struct prefix_list
*pl
= pprefix
->plist
;
1819 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1821 error ("file path prefix `%s' never used",
1823 /* Prevent duplicate warnings. */
1824 *pl
->used_flag_ptr
= 1;
1830 /* Get rid of all prefixes built up so far in *PLISTP. */
1833 free_path_prefix (pprefix
)
1834 struct path_prefix
*pprefix
;
1836 struct prefix_list
*pl
= pprefix
->plist
;
1837 struct prefix_list
*temp
;
1843 free (temp
->prefix
);
1844 free ((char *) temp
);
1846 pprefix
->plist
= (struct prefix_list
*) 0;
1849 /* stdin file number. */
1850 #define STDIN_FILE_NO 0
1852 /* stdout file number. */
1853 #define STDOUT_FILE_NO 1
1855 /* value of `pipe': port index for reading. */
1858 /* value of `pipe': port index for writing. */
1859 #define WRITE_PORT 1
1861 /* Pipe waiting from last process, to be used as input for the next one.
1862 Value is STDIN_FILE_NO if no pipe is waiting
1863 (i.e. the next command is the first of a group). */
1865 static int last_pipe_input
;
1867 /* Fork one piped subcommand. FUNC is the system call to use
1868 (either execv or execvp). ARGV is the arg vector to use.
1869 NOT_LAST is nonzero if this is not the last subcommand
1870 (i.e. its output should be piped to the next one.) */
1875 /* Declare these to avoid compilation error. They won't be called. */
1876 int execv(const char *a
, const char **b
){}
1877 int execvp(const char *a
, const char **b
){}
1880 pexecute (search_flag
, program
, argv
, not_last
)
1888 int i
, el
= search_flag
? 0 : 4;
1890 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6 + el
);
1891 rf
= scmd
+ strlen(program
) + 2 + el
;
1892 sprintf (scmd
, "%s%s @%s.gp", program
,
1893 (search_flag
? "" : ".exe"), temp_filename
);
1894 argfile
= fopen (rf
, "w");
1896 pfatal_with_name (rf
);
1898 for (i
=1; argv
[i
]; i
++)
1901 for (cp
= argv
[i
]; *cp
; cp
++)
1903 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
1904 fputc ('\\', argfile
);
1905 fputc (*cp
, argfile
);
1907 fputc ('\n', argfile
);
1917 perror_exec (program
);
1918 return MIN_FATAL_STATUS
<< 8;
1924 #else /* not __MSDOS__ */
1927 pexecute (search_flag
, program
, argv
, not_last
)
1933 int (*func
)() = (search_flag
? execv
: execvp
);
1936 int input_desc
= last_pipe_input
;
1937 int output_desc
= STDOUT_FILE_NO
;
1938 int retries
, sleep_interval
;
1940 /* If this isn't the last process, make a pipe for its output,
1941 and record it as waiting to be the input to the next process. */
1945 if (pipe (pdes
) < 0)
1946 pfatal_with_name ("pipe");
1947 output_desc
= pdes
[WRITE_PORT
];
1948 last_pipe_input
= pdes
[READ_PORT
];
1951 last_pipe_input
= STDIN_FILE_NO
;
1953 /* Fork a subprocess; wait and retry if it fails. */
1955 for (retries
= 0; retries
< 4; retries
++)
1960 sleep (sleep_interval
);
1961 sleep_interval
*= 2;
1968 pfatal_with_name ("fork");
1970 pfatal_with_name ("vfork");
1976 /* Move the input and output pipes into place, if nec. */
1977 if (input_desc
!= STDIN_FILE_NO
)
1979 close (STDIN_FILE_NO
);
1983 if (output_desc
!= STDOUT_FILE_NO
)
1985 close (STDOUT_FILE_NO
);
1987 close (output_desc
);
1990 /* Close the parent's descs that aren't wanted here. */
1991 if (last_pipe_input
!= STDIN_FILE_NO
)
1992 close (last_pipe_input
);
1994 /* Exec the program. */
1995 (*func
) (program
, argv
);
1996 perror_exec (program
);
2002 /* In the parent, after forking.
2003 Close the descriptors that we made for this child. */
2004 if (input_desc
!= STDIN_FILE_NO
)
2006 if (output_desc
!= STDOUT_FILE_NO
)
2007 close (output_desc
);
2009 /* Return child's process number. */
2014 #endif /* not __MSDOS__ */
2018 pexecute (search_flag
, program
, argv
, not_last
)
2024 return (search_flag
? spawnv
: spawnvp
) (1, program
, argv
);
2026 #endif /* not OS2 */
2028 /* Execute the command specified by the arguments on the current line of spec.
2029 When using pipes, this includes several piped-together commands
2030 with `|' between them.
2032 Return 0 if successful, -1 if failed. */
2038 int n_commands
; /* # of command. */
2042 char *prog
; /* program name. */
2043 char **argv
; /* vector of args. */
2044 int pid
; /* pid of process for this command. */
2047 struct command
*commands
; /* each command buffer with above info. */
2049 /* Count # of piped commands. */
2050 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2051 if (strcmp (argbuf
[i
], "|") == 0)
2054 /* Get storage for each command. */
2056 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2058 /* Split argbuf into its separate piped processes,
2059 and record info about each one.
2060 Also search for the programs that are to be run. */
2062 commands
[0].prog
= argbuf
[0]; /* first command. */
2063 commands
[0].argv
= &argbuf
[0];
2064 string
= find_a_file (&exec_prefix
, commands
[0].prog
, X_OK
);
2066 commands
[0].argv
[0] = string
;
2068 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2069 if (strcmp (argbuf
[i
], "|") == 0)
2070 { /* each command. */
2072 fatal ("-pipe not supported under MS-DOS");
2074 argbuf
[i
] = 0; /* termination of command args. */
2075 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2076 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2077 string
= find_a_file (&exec_prefix
, commands
[n_commands
].prog
, X_OK
);
2079 commands
[n_commands
].argv
[0] = string
;
2083 argbuf
[argbuf_index
] = 0;
2085 /* If -v, print what we are about to do, and maybe query. */
2089 /* Print each piped command as a separate line. */
2090 for (i
= 0; i
< n_commands
; i
++)
2094 for (j
= commands
[i
].argv
; *j
; j
++)
2095 fprintf (stderr
, " %s", *j
);
2097 /* Print a pipe symbol after all but the last command. */
2098 if (i
+ 1 != n_commands
)
2099 fprintf (stderr
, " |");
2100 fprintf (stderr
, "\n");
2104 fprintf (stderr
, "\nGo ahead? (y or n) ");
2108 while (getchar () != '\n') ;
2109 if (i
!= 'y' && i
!= 'Y')
2114 /* Run each piped subprocess. */
2116 last_pipe_input
= STDIN_FILE_NO
;
2117 for (i
= 0; i
< n_commands
; i
++)
2119 char *string
= commands
[i
].argv
[0];
2121 commands
[i
].pid
= pexecute (string
!= commands
[i
].prog
,
2122 string
, commands
[i
].argv
,
2123 i
+ 1 < n_commands
);
2125 if (string
!= commands
[i
].prog
)
2131 /* Wait for all the subprocesses to finish.
2132 We don't care what order they finish in;
2133 we know that N_COMMANDS waits will get them all. */
2138 for (i
= 0; i
< n_commands
; i
++)
2142 char *prog
= "unknown";
2145 status
= pid
= commands
[i
].pid
;
2147 pid
= wait (&status
);
2155 for (j
= 0; j
< n_commands
; j
++)
2156 if (commands
[j
].pid
== pid
)
2157 prog
= commands
[j
].prog
;
2159 if ((status
& 0x7F) != 0)
2161 fatal ("Internal compiler error: program %s got fatal signal %d",
2162 prog
, (status
& 0x7F));
2165 if (((status
& 0xFF00) >> 8) >= MIN_FATAL_STATUS
)
2173 /* Find all the switches given to us
2174 and make a vector describing them.
2175 The elements of the vector are strings, one per switch given.
2176 If a switch uses following arguments, then the `part1' field
2177 is the switch itself and the `args' field
2178 is a null-terminated vector containing the following arguments.
2179 The `live_cond' field is 1 if the switch is true in a conditional spec,
2180 -1 if false (overridden by a later switch), and is initialized to zero.
2181 The `valid' field is nonzero if any spec has looked at this switch;
2182 if it remains zero at the end of the run, it must be meaningless. */
2192 static struct switchstr
*switches
;
2194 static int n_switches
;
2202 /* Also a vector of input files specified. */
2204 static struct infile
*infiles
;
2206 static int n_infiles
;
2208 /* And a vector of corresponding output files is made up later. */
2210 static char **outfiles
;
2212 /* Create the vector `switches' and its contents.
2213 Store its length in `n_switches'. */
2216 process_command (argc
, argv
)
2222 char *spec_lang
= 0;
2223 int last_language_n_infiles
;
2225 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2230 /* Figure compiler version from version string. */
2232 compiler_version
= save_string (version_string
, strlen (version_string
));
2233 for (temp
= compiler_version
; *temp
; ++temp
)
2242 /* Set up the default search paths. */
2244 if (gcc_exec_prefix
)
2246 add_prefix (&exec_prefix
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2247 add_prefix (&startfile_prefix
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2250 /* COMPILER_PATH and LIBRARY_PATH have values
2251 that are lists of directory names with colons. */
2253 temp
= getenv ("COMPILER_PATH");
2256 char *startp
, *endp
;
2257 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2259 startp
= endp
= temp
;
2262 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2264 strncpy (nstore
, startp
, endp
-startp
);
2267 strcpy (nstore
, "./");
2269 else if (endp
[-1] != '/')
2271 nstore
[endp
-startp
] = '/';
2272 nstore
[endp
-startp
+1] = 0;
2275 nstore
[endp
-startp
] = 0;
2276 add_prefix (&exec_prefix
, nstore
, 0, 0, NULL_PTR
);
2279 endp
= startp
= endp
+ 1;
2286 temp
= getenv ("LIBRARY_PATH");
2289 char *startp
, *endp
;
2290 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2292 startp
= endp
= temp
;
2295 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2297 strncpy (nstore
, startp
, endp
-startp
);
2300 strcpy (nstore
, "./");
2302 else if (endp
[-1] != '/')
2304 nstore
[endp
-startp
] = '/';
2305 nstore
[endp
-startp
+1] = 0;
2308 nstore
[endp
-startp
] = 0;
2309 add_prefix (&startfile_prefix
, nstore
, 0, 0, NULL_PTR
);
2312 endp
= startp
= endp
+ 1;
2319 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2320 temp
= getenv ("LPATH");
2323 char *startp
, *endp
;
2324 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2326 startp
= endp
= temp
;
2329 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2331 strncpy (nstore
, startp
, endp
-startp
);
2334 strcpy (nstore
, "./");
2336 else if (endp
[-1] != '/')
2338 nstore
[endp
-startp
] = '/';
2339 nstore
[endp
-startp
+1] = 0;
2342 nstore
[endp
-startp
] = 0;
2343 add_prefix (&startfile_prefix
, nstore
, 0, 0, NULL_PTR
);
2346 endp
= startp
= endp
+ 1;
2353 /* Convert new-style -- options to old-style. */
2354 translate_options (&argc
, &argv
);
2356 /* Scan argv twice. Here, the first time, just count how many switches
2357 there will be in their vector, and how many input files in theirs.
2358 Here we also parse the switches that cc itself uses (e.g. -v). */
2360 for (i
= 1; i
< argc
; i
++)
2362 if (! strcmp (argv
[i
], "-dumpspecs"))
2364 printf ("*asm:\n%s\n\n", asm_spec
);
2365 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
2366 printf ("*cpp:\n%s\n\n", cpp_spec
);
2367 printf ("*cc1:\n%s\n\n", cc1_spec
);
2368 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
2369 printf ("*endfile:\n%s\n\n", endfile_spec
);
2370 printf ("*link:\n%s\n\n", link_spec
);
2371 printf ("*lib:\n%s\n\n", lib_spec
);
2372 printf ("*startfile:\n%s\n\n", startfile_spec
);
2373 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
2374 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
2375 printf ("*predefines:\n%s\n\n", cpp_predefines
);
2376 printf ("*cross_compile:\n%d\n\n", cross_compile
);
2377 printf ("*multilib:\n%s\n\n", multilib_select
);
2381 else if (! strcmp (argv
[i
], "-dumpversion"))
2383 printf ("%s\n", version_string
);
2386 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2387 print_file_name
= "libgcc.a";
2388 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2389 print_file_name
= argv
[i
] + 17;
2390 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2391 print_prog_name
= argv
[i
] + 17;
2392 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2393 print_multi_lib
= 1;
2394 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2395 print_multi_directory
= 1;
2396 else if (! strcmp (argv
[i
], "-Xlinker"))
2398 /* Pass the argument of this option to the linker when we link. */
2401 fatal ("argument to `-Xlinker' is missing");
2404 if (!linker_options
)
2406 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2409 = (char **) xrealloc (linker_options
,
2410 n_linker_options
* sizeof (char **));
2412 linker_options
[n_linker_options
- 1] = argv
[++i
];
2414 else if (! strncmp (argv
[i
], "-Wl,", 4))
2417 /* Pass the rest of this option to the linker when we link. */
2420 if (!linker_options
)
2422 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2425 = (char **) xrealloc (linker_options
,
2426 n_linker_options
* sizeof (char **));
2428 /* Split the argument at commas. */
2430 for (j
= 4; argv
[i
][j
]; j
++)
2431 if (argv
[i
][j
] == ',')
2433 linker_options
[n_linker_options
- 1]
2434 = save_string (argv
[i
] + prev
, j
- prev
);
2437 = (char **) xrealloc (linker_options
,
2438 n_linker_options
* sizeof (char **));
2441 /* Record the part after the last comma. */
2442 linker_options
[n_linker_options
- 1] = argv
[i
] + prev
;
2444 else if (! strncmp (argv
[i
], "-Wa,", 4))
2447 /* Pass the rest of this option to the assembler. */
2449 n_assembler_options
++;
2450 if (!assembler_options
)
2452 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2455 = (char **) xrealloc (assembler_options
,
2456 n_assembler_options
* sizeof (char **));
2458 /* Split the argument at commas. */
2460 for (j
= 4; argv
[i
][j
]; j
++)
2461 if (argv
[i
][j
] == ',')
2463 assembler_options
[n_assembler_options
- 1]
2464 = save_string (argv
[i
] + prev
, j
- prev
);
2465 n_assembler_options
++;
2467 = (char **) xrealloc (assembler_options
,
2468 n_assembler_options
* sizeof (char **));
2471 /* Record the part after the last comma. */
2472 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2474 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2475 /* The +e options to the C++ front-end. */
2477 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2479 register char *p
= &argv
[i
][1];
2480 register int c
= *p
;
2485 if (p
[1] == 0 && i
+ 1 == argc
)
2486 fatal ("argument to `-b' is missing");
2488 spec_machine
= argv
[++i
];
2490 spec_machine
= p
+ 1;
2495 int *temp
= (int *) xmalloc (sizeof (int));
2497 if (p
[1] == 0 && i
+ 1 == argc
)
2498 fatal ("argument to `-B' is missing");
2503 add_prefix (&exec_prefix
, value
, 1, 0, temp
);
2504 add_prefix (&startfile_prefix
, value
, 1, 0, temp
);
2505 add_prefix (&include_prefix
, concat (value
, "include", ""),
2508 /* As a kludge, if the arg is "[foo/]stageN/", just add
2509 "[foo/]stageN/../include" to the include prefix. */
2511 int len
= strlen (value
);
2512 if ((len
== 7 || (len
> 7 && value
[len
- 8] == '/'))
2513 && strncmp (value
+ len
- 7, "stage", 5) == 0
2514 && isdigit (value
[len
- 2])
2515 && value
[len
- 1] == '/')
2516 add_prefix (&include_prefix
,
2517 concat (value
, "../include", ""), 1, 0, 0);
2522 case 'v': /* Print our subcommands and print versions. */
2524 /* If they do anything other than exactly `-v', don't set
2525 verbose_flag; rather, continue on to give the error. */
2532 if (p
[1] == 0 && i
+ 1 == argc
)
2533 fatal ("argument to `-V' is missing");
2535 spec_version
= argv
[++i
];
2537 spec_version
= p
+ 1;
2538 compiler_version
= spec_version
;
2542 if (!strcmp (p
, "save-temps"))
2544 save_temps_flag
= 1;
2551 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2552 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2553 else if (WORD_SWITCH_TAKES_ARG (p
))
2554 i
+= WORD_SWITCH_TAKES_ARG (p
);
2561 /* Set up the search paths before we go looking for config files. */
2563 /* These come before the md prefixes so that we will find gcc's subcommands
2564 (such as cpp) rather than those of the host system. */
2565 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2566 as well as trying the machine and the version. */
2567 add_prefix (&exec_prefix
, standard_exec_prefix
, 0, 2, NULL_PTR
);
2568 add_prefix (&exec_prefix
, standard_exec_prefix_1
, 0, 2, NULL_PTR
);
2570 add_prefix (&startfile_prefix
, standard_exec_prefix
, 0, 1, NULL_PTR
);
2571 add_prefix (&startfile_prefix
, standard_exec_prefix_1
, 0, 1, NULL_PTR
);
2573 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
, "/");
2575 /* If tooldir is relative, base it on exec_prefix. A relative
2576 tooldir lets us move the installed tree as a unit.
2578 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2579 directories, so that we can search both the user specified directory
2580 and the standard place. */
2582 if (*tooldir_prefix
!= '/')
2584 if (gcc_exec_prefix
)
2586 char *gcc_exec_tooldir_prefix
2587 = concat (concat (gcc_exec_prefix
, spec_machine
, "/"),
2588 concat (spec_version
, "/", tooldir_prefix
),
2591 add_prefix (&exec_prefix
, concat (gcc_exec_tooldir_prefix
, "bin", "/"),
2593 add_prefix (&startfile_prefix
, concat (gcc_exec_tooldir_prefix
, "lib", "/"),
2597 tooldir_prefix
= concat (concat (standard_exec_prefix
, spec_machine
, "/"),
2598 concat (spec_version
, "/", tooldir_prefix
),
2602 add_prefix (&exec_prefix
, concat (tooldir_prefix
, "bin", "/"),
2604 add_prefix (&startfile_prefix
, concat (tooldir_prefix
, "lib", "/"),
2607 /* More prefixes are enabled in main, after we read the specs file
2608 and determine whether this is cross-compilation or not. */
2611 /* Then create the space for the vectors and scan again. */
2613 switches
= ((struct switchstr
*)
2614 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2615 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2618 last_language_n_infiles
= -1;
2620 /* This, time, copy the text of each switch and store a pointer
2621 to the copy in the vector of switches.
2622 Store all the infiles in their vector. */
2624 for (i
= 1; i
< argc
; i
++)
2626 /* Just skip the switches that were handled by the preceding loop. */
2627 if (!strcmp (argv
[i
], "-Xlinker"))
2629 else if (! strncmp (argv
[i
], "-Wl,", 4))
2631 else if (! strncmp (argv
[i
], "-Wa,", 4))
2633 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2635 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2637 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2639 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2641 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2643 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2645 /* Compensate for the +e options to the C++ front-end;
2646 they're there simply for cfront call-compatibility. We do
2647 some magic in default_compilers to pass them down properly.
2648 Note we deliberately start at the `+' here, to avoid passing
2649 -e0 or -e1 down into the linker. */
2650 switches
[n_switches
].part1
= &argv
[i
][0];
2651 switches
[n_switches
].args
= 0;
2652 switches
[n_switches
].live_cond
= 0;
2653 switches
[n_switches
].valid
= 0;
2656 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2658 register char *p
= &argv
[i
][1];
2659 register int c
= *p
;
2661 if (c
== 'B' || c
== 'b' || c
== 'V')
2663 /* Skip a separate arg, if any. */
2670 if (p
[1] == 0 && i
+ 1 == argc
)
2671 fatal ("argument to `-x' is missing");
2673 spec_lang
= argv
[++i
];
2676 if (! strcmp (spec_lang
, "none"))
2677 /* Suppress the warning if -xnone comes after the last input file,
2678 because alternate command interfaces like g++ might find it
2679 useful to place -xnone after each input file. */
2682 last_language_n_infiles
= n_infiles
;
2685 switches
[n_switches
].part1
= p
;
2686 /* Deal with option arguments in separate argv elements. */
2687 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2688 || WORD_SWITCH_TAKES_ARG (p
))
2691 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2695 /* Count only the option arguments in separate argv elements. */
2696 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2698 if (i
+ n_args
>= argc
)
2699 fatal ("argument to `-%s' is missing", p
);
2700 switches
[n_switches
].args
2701 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2703 switches
[n_switches
].args
[j
++] = argv
[++i
];
2704 /* Null-terminate the vector. */
2705 switches
[n_switches
].args
[j
] = 0;
2707 else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L'))
2709 /* On some systems, ld cannot handle -o or -L without space.
2710 So split the -o or -L from its argument. */
2711 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2712 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2713 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2714 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2715 switches
[n_switches
].args
[1] = 0;
2718 switches
[n_switches
].args
= 0;
2720 switches
[n_switches
].live_cond
= 0;
2721 switches
[n_switches
].valid
= 0;
2722 /* This is always valid, since gcc.c itself understands it. */
2723 if (!strcmp (p
, "save-temps"))
2724 switches
[n_switches
].valid
= 1;
2729 if ((argv
[i
][0] != '-' || argv
[i
][1] != 'l')
2730 && strcmp (argv
[i
], "-")
2731 && access (argv
[i
], R_OK
) < 0)
2733 perror_with_name (argv
[i
]);
2738 infiles
[n_infiles
].language
= spec_lang
;
2739 infiles
[n_infiles
++].name
= argv
[i
];
2744 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
2745 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2747 switches
[n_switches
].part1
= 0;
2748 infiles
[n_infiles
].name
= 0;
2750 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2751 if (gcc_exec_prefix
)
2753 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2754 + strlen (spec_machine
) + 3);
2755 strcpy (temp
, gcc_exec_prefix
);
2756 strcat (temp
, spec_machine
);
2758 strcat (temp
, spec_version
);
2760 gcc_exec_prefix
= temp
;
2764 /* Process a spec string, accumulating and running commands. */
2766 /* These variables describe the input file name.
2767 input_file_number is the index on outfiles of this file,
2768 so that the output file name can be stored for later use by %o.
2769 input_basename is the start of the part of the input file
2770 sans all directory names, and basename_length is the number
2771 of characters starting there excluding the suffix .c or whatever. */
2773 static char *input_filename
;
2774 static int input_file_number
;
2775 static int input_filename_length
;
2776 static int basename_length
;
2777 static char *input_basename
;
2778 static char *input_suffix
;
2780 /* These are variables used within do_spec and do_spec_1. */
2782 /* Nonzero if an arg has been started and not yet terminated
2783 (with space, tab or newline). */
2784 static int arg_going
;
2786 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2787 is a temporary file name. */
2788 static int delete_this_arg
;
2790 /* Nonzero means %w has been seen; the next arg to be terminated
2791 is the output file name of this compilation. */
2792 static int this_is_output_file
;
2794 /* Nonzero means %s has been seen; the next arg to be terminated
2795 is the name of a library file and we should try the standard
2796 search dirs for it. */
2797 static int this_is_library_file
;
2799 /* Nonzero means that the input of this command is coming from a pipe. */
2800 static int input_from_pipe
;
2802 /* Process the spec SPEC and run the commands specified therein.
2803 Returns 0 if the spec is successfully processed; -1 if failed. */
2813 delete_this_arg
= 0;
2814 this_is_output_file
= 0;
2815 this_is_library_file
= 0;
2816 input_from_pipe
= 0;
2818 value
= do_spec_1 (spec
, 0, NULL_PTR
);
2820 /* Force out any unfinished command.
2821 If -pipe, this forces out the last command if it ended in `|'. */
2824 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2827 if (argbuf_index
> 0)
2834 /* Process the sub-spec SPEC as a portion of a larger spec.
2835 This is like processing a whole spec except that we do
2836 not initialize at the beginning and we do not supply a
2837 newline by default at the end.
2838 INSWITCH nonzero means don't process %-sequences in SPEC;
2839 in this case, % is treated as an ordinary character.
2840 This is used while substituting switches.
2841 INSWITCH nonzero also causes SPC not to terminate an argument.
2843 Value is zero unless a line was finished
2844 and the command on that line reported an error. */
2847 do_spec_1 (spec
, inswitch
, soft_matched_part
)
2850 char *soft_matched_part
;
2852 register char *p
= spec
;
2859 /* If substituting a switch, treat all chars like letters.
2860 Otherwise, NL, SPC, TAB and % are special. */
2861 switch (inswitch
? 'a' : c
)
2864 /* End of line: finish any pending argument,
2865 then run the pending command if one has been started. */
2868 obstack_1grow (&obstack
, 0);
2869 string
= obstack_finish (&obstack
);
2870 if (this_is_library_file
)
2871 string
= find_file (string
);
2872 store_arg (string
, delete_this_arg
, this_is_output_file
);
2873 if (this_is_output_file
)
2874 outfiles
[input_file_number
] = string
;
2878 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2881 for (i
= 0; i
< n_switches
; i
++)
2882 if (!strcmp (switches
[i
].part1
, "pipe"))
2885 /* A `|' before the newline means use a pipe here,
2886 but only if -pipe was specified.
2887 Otherwise, execute now and don't pass the `|' as an arg. */
2890 input_from_pipe
= 1;
2891 switches
[i
].valid
= 1;
2898 if (argbuf_index
> 0)
2904 /* Reinitialize for a new command, and for a new argument. */
2907 delete_this_arg
= 0;
2908 this_is_output_file
= 0;
2909 this_is_library_file
= 0;
2910 input_from_pipe
= 0;
2914 /* End any pending argument. */
2917 obstack_1grow (&obstack
, 0);
2918 string
= obstack_finish (&obstack
);
2919 if (this_is_library_file
)
2920 string
= find_file (string
);
2921 store_arg (string
, delete_this_arg
, this_is_output_file
);
2922 if (this_is_output_file
)
2923 outfiles
[input_file_number
] = string
;
2927 obstack_1grow (&obstack
, c
);
2933 /* Space or tab ends an argument if one is pending. */
2936 obstack_1grow (&obstack
, 0);
2937 string
= obstack_finish (&obstack
);
2938 if (this_is_library_file
)
2939 string
= find_file (string
);
2940 store_arg (string
, delete_this_arg
, this_is_output_file
);
2941 if (this_is_output_file
)
2942 outfiles
[input_file_number
] = string
;
2944 /* Reinitialize for a new argument. */
2946 delete_this_arg
= 0;
2947 this_is_output_file
= 0;
2948 this_is_library_file
= 0;
2955 fatal ("Invalid specification! Bug in cc.");
2958 obstack_grow (&obstack
, input_basename
, basename_length
);
2963 delete_this_arg
= 2;
2966 /* Dump out the directories specified with LIBRARY_PATH,
2967 followed by the absolute directories
2968 that we search for startfiles. */
2971 struct prefix_list
*pl
= startfile_prefix
.plist
;
2973 char *buffer
= (char *) xmalloc (bufsize
);
2976 for (; pl
; pl
= pl
->next
)
2978 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2979 /* Used on systems which record the specified -L dirs
2980 and use them to search for dynamic linking. */
2981 /* Relative directories always come from -B,
2982 and it is better not to use them for searching
2983 at run time. In particular, stage1 loses */
2984 if (pl
->prefix
[0] != '/')
2987 /* Try subdirectory if there is one. */
2988 if (multilib_dir
!= NULL
)
2992 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
2994 bufsize
= (strlen (pl
->prefix
)
2995 + strlen (machine_suffix
)) * 2 + 1;
2996 buffer
= (char *) xrealloc (buffer
, bufsize
);
2997 strcpy (buffer
, pl
->prefix
);
2998 strcat (buffer
, machine_suffix
);
2999 if (is_directory (buffer
, multilib_dir
, 1))
3001 do_spec_1 ("-L", 0, NULL_PTR
);
3002 #ifdef SPACE_AFTER_L_OPTION
3003 do_spec_1 (" ", 0, NULL_PTR
);
3005 do_spec_1 (buffer
, 1, NULL_PTR
);
3006 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3007 /* Make this a separate argument. */
3008 do_spec_1 (" ", 0, NULL_PTR
);
3011 if (!pl
->require_machine_suffix
)
3013 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3015 do_spec_1 ("-L", 0, NULL_PTR
);
3016 #ifdef SPACE_AFTER_L_OPTION
3017 do_spec_1 (" ", 0, NULL_PTR
);
3019 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3020 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3021 /* Make this a separate argument. */
3022 do_spec_1 (" ", 0, NULL_PTR
);
3028 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3030 do_spec_1 ("-L", 0, NULL_PTR
);
3031 #ifdef SPACE_AFTER_L_OPTION
3032 do_spec_1 (" ", 0, NULL_PTR
);
3034 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3035 /* Remove slash from machine_suffix. */
3036 if (strlen (machine_suffix
) >= bufsize
)
3037 bufsize
= strlen (machine_suffix
) * 2 + 1;
3038 buffer
= (char *) xrealloc (buffer
, bufsize
);
3039 strcpy (buffer
, machine_suffix
);
3040 idx
= strlen (buffer
);
3041 if (buffer
[idx
- 1] == '/')
3042 buffer
[idx
- 1] = 0;
3043 do_spec_1 (buffer
, 1, NULL_PTR
);
3044 /* Make this a separate argument. */
3045 do_spec_1 (" ", 0, NULL_PTR
);
3048 if (!pl
->require_machine_suffix
)
3050 if (is_directory (pl
->prefix
, "", 1))
3052 do_spec_1 ("-L", 0, NULL_PTR
);
3053 #ifdef SPACE_AFTER_L_OPTION
3054 do_spec_1 (" ", 0, NULL_PTR
);
3056 /* Remove slash from pl->prefix. */
3057 if (strlen (pl
->prefix
) >= bufsize
)
3058 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3059 buffer
= (char *) xrealloc (buffer
, bufsize
);
3060 strcpy (buffer
, pl
->prefix
);
3061 idx
= strlen (buffer
);
3062 if (buffer
[idx
- 1] == '/')
3063 buffer
[idx
- 1] = 0;
3064 do_spec_1 (buffer
, 1, NULL_PTR
);
3065 /* Make this a separate argument. */
3066 do_spec_1 (" ", 0, NULL_PTR
);
3075 /* {...:%efoo} means report an error with `foo' as error message
3076 and don't execute any more commands for this file. */
3080 while (*p
!= 0 && *p
!= '\n') p
++;
3081 buf
= (char *) alloca (p
- q
+ 1);
3082 strncpy (buf
, q
, p
- q
);
3092 if (save_temps_flag
)
3094 obstack_grow (&obstack
, input_basename
, basename_length
);
3095 delete_this_arg
= 0;
3099 #ifdef MKTEMP_EACH_FILE
3100 /* ??? This has a problem: the total number of
3101 values mktemp can return is limited.
3102 That matters for the names of object files.
3103 In 2.4, do something about that. */
3104 struct temp_name
*t
;
3106 while (*p
== '.' || isalpha (*p
))
3109 /* See if we already have an association of %g/%u/%U and
3111 for (t
= temp_names
; t
; t
= t
->next
)
3112 if (t
->length
== p
- suffix
3113 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3114 && t
->unique
== (c
!= 'g'))
3117 /* Make a new association if needed. %u requires one. */
3118 if (t
== 0 || c
== 'u')
3122 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3123 t
->next
= temp_names
;
3126 t
->length
= p
- suffix
;
3127 t
->suffix
= save_string (suffix
, p
- suffix
);
3128 t
->unique
= (c
!= 'g');
3129 choose_temp_base ();
3130 t
->filename
= temp_filename
;
3131 t
->filename_length
= temp_filename_length
;
3134 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3135 delete_this_arg
= 1;
3137 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3138 if (c
== 'u' || c
== 'U')
3144 sprintf (buff
, "%d", unique
);
3145 obstack_grow (&obstack
, buff
, strlen (buff
));
3148 delete_this_arg
= 1;
3154 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3160 struct prefix_list
*pl
= include_prefix
.plist
;
3162 if (gcc_exec_prefix
)
3164 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3165 /* Make this a separate argument. */
3166 do_spec_1 (" ", 0, NULL_PTR
);
3167 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3168 do_spec_1 (" ", 0, NULL_PTR
);
3171 for (; pl
; pl
= pl
->next
)
3173 do_spec_1 ("-isystem", 1, NULL_PTR
);
3174 /* Make this a separate argument. */
3175 do_spec_1 (" ", 0, NULL_PTR
);
3176 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3177 do_spec_1 (" ", 0, NULL_PTR
);
3185 for (f
= 0; f
< n_infiles
; f
++)
3186 store_arg (outfiles
[f
], 0, 0);
3191 this_is_library_file
= 1;
3195 this_is_output_file
= 1;
3200 int index
= argbuf_index
;
3201 /* Handle the {...} following the %W. */
3204 p
= handle_braces (p
+ 1);
3207 /* If any args were output, mark the last one for deletion
3209 if (argbuf_index
!= index
)
3210 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3214 /* %x{OPTION} records OPTION for %X to output. */
3220 /* Skip past the option value and make a copy. */
3225 string
= save_string (p1
+ 1, p
- p1
- 2);
3227 /* See if we already recorded this option. */
3228 for (i
= 0; i
< n_linker_options
; i
++)
3229 if (! strcmp (string
, linker_options
[i
]))
3235 /* This option is new; add it. */
3237 if (!linker_options
)
3239 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3242 = (char **) xrealloc (linker_options
,
3243 n_linker_options
* sizeof (char **));
3245 linker_options
[n_linker_options
- 1] = string
;
3249 /* Dump out the options accumulated previously using %x,
3250 -Xlinker and -Wl,. */
3252 for (i
= 0; i
< n_linker_options
; i
++)
3254 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3255 /* Make each accumulated option a separate argument. */
3256 do_spec_1 (" ", 0, NULL_PTR
);
3260 /* Dump out the options accumulated previously using -Wa,. */
3262 for (i
= 0; i
< n_assembler_options
; i
++)
3264 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3265 /* Make each accumulated option a separate argument. */
3266 do_spec_1 (" ", 0, NULL_PTR
);
3270 /* Here are digits and numbers that just process
3271 a certain constant string as a spec. */
3274 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3280 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3286 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3292 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3298 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3304 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3310 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3316 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3322 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3329 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3333 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3337 if (! strncmp (y
, "-D", 2))
3338 /* Copy the whole option. */
3339 while (*y
&& *y
!= ' ' && *y
!= '\t')
3341 else if (*y
== ' ' || *y
== '\t')
3342 /* Copy whitespace to the result. */
3344 /* Don't copy other options. */
3351 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3359 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3363 /* Copy all of CPP_PREDEFINES into BUF,
3364 but put __ after every -D and at the end of each arg. */
3368 if (! strncmp (y
, "-D", 2))
3375 if (strncmp (y
, "__", 2))
3377 /* Stick __ at front of macro name. */
3380 /* Arrange to stick __ at the end as well. */
3384 /* Copy the macro name. */
3385 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3394 /* Copy the value given, if any. */
3395 while (*y
&& *y
!= ' ' && *y
!= '\t')
3398 else if (*y
== ' ' || *y
== '\t')
3399 /* Copy whitespace to the result. */
3401 /* Don't copy -A options */
3407 /* Copy all of CPP_PREDEFINES into BUF,
3408 but put __ after every -D. */
3412 if (! strncmp (y
, "-D", 2))
3416 if (strncmp (y
, "__", 2))
3418 /* Stick -D__ at front of macro name. */
3424 /* Copy the macro name. */
3425 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3428 /* Copy the value given, if any. */
3429 while (*y
&& *y
!= ' ' && *y
!= '\t')
3434 /* Do not copy this macro - we have just done it before */
3435 while (*y
&& *y
!= ' ' && *y
!= '\t')
3439 else if (*y
== ' ' || *y
== '\t')
3440 /* Copy whitespace to the result. */
3442 /* Don't copy -A options */
3448 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3452 if (! strncmp (y
, "-A", 2))
3453 /* Copy the whole option. */
3454 while (*y
&& *y
!= ' ' && *y
!= '\t')
3456 else if (*y
== ' ' || *y
== '\t')
3457 /* Copy whitespace to the result. */
3459 /* Don't copy other options. */
3466 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3473 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3478 /* Here we define characters other than letters and digits. */
3481 p
= handle_braces (p
);
3487 obstack_1grow (&obstack
, '%');
3491 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3492 do_spec_1 (" ", 0, NULL_PTR
);
3495 /* Process a string found as the value of a spec given by name.
3496 This feature allows individual machine descriptions
3497 to add and use their own specs.
3498 %[...] modifies -D options the way %P does;
3499 %(...) uses the spec unmodified. */
3504 struct spec_list
*sl
;
3507 /* The string after the S/P is the name of a spec that is to be
3509 while (*p
&& *p
!= ')' && *p
!= ']')
3512 /* See if it's in the list */
3513 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3514 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
3524 value
= do_spec_1 (name
, 0, NULL_PTR
);
3530 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3534 /* Copy all of NAME into BUF, but put __ after
3535 every -D and at the end of each arg, */
3538 if (! strncmp (y
, "-D", 2))
3546 else if (*y
== ' ' || *y
== 0)
3560 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3566 /* Discard the closing paren or bracket. */
3574 int c1
= *p
++; /* Select first or second version number. */
3575 char *v
= compiler_version
;
3577 /* If desired, advance to second version number. */
3580 /* Set P after the first period. */
3581 while (*v
!= 0 && *v
!= ' ' && *v
!= '.')
3586 /* Set Q at the next period or at the end. */
3588 while (*q
!= 0 && *q
!= ' ' && *q
!= '.')
3590 /* Empty string means zero. */
3596 /* Put that part into the command. */
3597 obstack_grow (&obstack
, v
, q
- v
);
3603 if (input_from_pipe
)
3604 do_spec_1 ("-", 0, NULL_PTR
);
3613 /* Backslash: treat next character as ordinary. */
3618 /* Ordinary character: put it into the current argument. */
3619 obstack_1grow (&obstack
, c
);
3623 return 0; /* End of string */
3626 /* Return 0 if we call do_spec_1 and that returns -1. */
3639 /* A `|' after the open-brace means,
3640 if the test fails, output a single minus sign rather than nothing.
3641 This is used in %{|!pipe:...}. */
3645 /* A `!' after the open-brace negates the condition:
3646 succeed if the specified switch is not present. */
3650 /* A `.' after the open-brace means test against the current suffix. */
3660 while (*p
!= ':' && *p
!= '}') p
++;
3663 register int count
= 1;
3681 int found
= (input_suffix
!= 0
3682 && strlen (input_suffix
) == p
- filter
3683 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3689 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3694 else if (p
[-1] == '*' && p
[0] == '}')
3696 /* Substitute all matching switches as separate args. */
3699 for (i
= 0; i
< n_switches
; i
++)
3700 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3701 && check_live_switch (i
, p
- filter
))
3706 /* Test for presence of the specified switch. */
3710 /* If name specified ends in *, as in {x*:...},
3711 check for %* and handle that case. */
3712 if (p
[-1] == '*' && !negate
)
3717 /* First see whether we have %*. */
3721 if (*r
== '%' && r
[1] == '*')
3725 /* If we do, handle that case. */
3728 /* Substitute all matching switches as separate args.
3729 But do this by substituting for %*
3730 in the text that follows the colon. */
3732 unsigned hard_match_len
= p
- filter
- 1;
3733 char *string
= save_string (p
+ 1, q
- p
- 2);
3735 for (i
= 0; i
< n_switches
; i
++)
3736 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3737 && check_live_switch (i
, -1))
3739 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
3740 /* Pass any arguments this switch has. */
3748 /* If name specified ends in *, as in {x*:...},
3749 check for presence of any switch name starting with x. */
3752 for (i
= 0; i
< n_switches
; i
++)
3754 unsigned hard_match_len
= p
- filter
- 1;
3756 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3757 && check_live_switch (i
, hard_match_len
))
3763 /* Otherwise, check for presence of exact name specified. */
3766 for (i
= 0; i
< n_switches
; i
++)
3768 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3769 && switches
[i
].part1
[p
- filter
] == 0
3770 && check_live_switch (i
, -1))
3778 /* If it is as desired (present for %{s...}, absent for %{-s...})
3779 then substitute either the switch or the specified
3780 conditional text. */
3781 if (present
!= negate
)
3789 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3795 /* Here if a %{|...} conditional fails: output a minus sign,
3796 which means "standard output" or "standard input". */
3797 do_spec_1 ("-", 0, NULL_PTR
);
3804 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3805 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3806 spec, or -1 if either exact match or %* is used.
3808 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3809 whose value does not begin with "no-" is obsoleted by the same value
3810 with the "no-", similarly for a switch with the "no-" prefix. */
3813 check_live_switch (switchnum
, prefix_length
)
3817 char *name
= switches
[switchnum
].part1
;
3820 /* In the common case of {<at-most-one-letter>*}, a negating
3821 switch would always match, so ignore that case. We will just
3822 send the conflicting switches to the compiler phase. */
3823 if (prefix_length
>= 0 && prefix_length
<= 1)
3826 /* If we already processed this switch and determined if it was
3827 live or not, return our past determination. */
3828 if (switches
[switchnum
].live_cond
!= 0)
3829 return switches
[switchnum
].live_cond
> 0;
3831 /* Now search for duplicate in a manner that depends on the name. */
3835 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
3836 if (switches
[i
].part1
[0] == 'O')
3838 switches
[switchnum
].valid
= 1;
3839 switches
[switchnum
].live_cond
= -1;
3844 case 'W': case 'f': case 'm':
3845 if (! strncmp (name
+ 1, "no-", 3))
3847 /* We have Xno-YYY, search for XYYY. */
3848 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
3849 if (switches
[i
].part1
[0] == name
[0]
3850 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
3852 switches
[switchnum
].valid
= 1;
3853 switches
[switchnum
].live_cond
= -1;
3859 /* We have XYYY, search for Xno-YYY. */
3860 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
3861 if (switches
[i
].part1
[0] == name
[0]
3862 && switches
[i
].part1
[1] == 'n'
3863 && switches
[i
].part1
[2] == 'o'
3864 && switches
[i
].part1
[3] == '-'
3865 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
3867 switches
[switchnum
].valid
= 1;
3868 switches
[switchnum
].live_cond
= -1;
3875 /* Otherwise the switch is live. */
3876 switches
[switchnum
].live_cond
= 1;
3880 /* Pass a switch to the current accumulating command
3881 in the same form that we received it.
3882 SWITCHNUM identifies the switch; it is an index into
3883 the vector of switches gcc received, which is `switches'.
3884 This cannot fail since it never finishes a command line.
3886 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
3889 give_switch (switchnum
, omit_first_word
)
3891 int omit_first_word
;
3893 if (!omit_first_word
)
3895 do_spec_1 ("-", 0, NULL_PTR
);
3896 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
3898 do_spec_1 (" ", 0, NULL_PTR
);
3899 if (switches
[switchnum
].args
!= 0)
3902 for (p
= switches
[switchnum
].args
; *p
; p
++)
3904 do_spec_1 (*p
, 1, NULL_PTR
);
3905 do_spec_1 (" ", 0, NULL_PTR
);
3908 switches
[switchnum
].valid
= 1;
3911 /* Search for a file named NAME trying various prefixes including the
3912 user's -B prefix and some standard ones.
3913 Return the absolute file name found. If nothing is found, return NAME. */
3921 /* Try multilib_dir if it is defined. */
3922 if (multilib_dir
!= NULL
)
3926 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
3927 strcpy (try, multilib_dir
);
3931 newname
= find_a_file (&startfile_prefix
, try, R_OK
);
3933 /* If we don't find it in the multi library dir, then fall
3934 through and look for it in the normal places. */
3935 if (newname
!= NULL
)
3939 newname
= find_a_file (&startfile_prefix
, name
, R_OK
);
3940 return newname
? newname
: name
;
3943 /* Determine whether a directory exists. If LINKER, return 0 for
3944 certain fixed names not needed by the linker. If not LINKER, it is
3945 only important to return 0 if the host machine has a small ARG_MAX
3949 is_directory (path1
, path2
, linker
)
3954 int len1
= strlen (path1
);
3955 int len2
= strlen (path2
);
3956 char *path
= (char *) alloca (3 + len1
+ len2
);
3960 #ifndef SMALL_ARG_MAX
3965 /* Construct the path from the two parts. Ensure the string ends with "/.".
3966 The resulting path will be a directory even if the given path is a
3968 bcopy (path1
, path
, len1
);
3969 bcopy (path2
, path
+ len1
, len2
);
3970 cp
= path
+ len1
+ len2
;
3976 /* Exclude directories that the linker is known to search. */
3978 && ((cp
- path
== 6 && strcmp (path
, "/lib/.") == 0)
3979 || (cp
- path
== 10 && strcmp (path
, "/usr/lib/.") == 0)))
3982 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
3985 /* On fatal signals, delete all the temporary files. */
3988 fatal_error (signum
)
3991 signal (signum
, SIG_DFL
);
3992 delete_failure_queue ();
3993 delete_temp_files ();
3994 /* Get the same signal again, this time not handled,
3995 so its normal effect occurs. */
3996 kill (getpid (), signum
);
4007 int linker_was_run
= 0;
4008 char *explicit_link_files
;
4012 p
= argv
[0] + strlen (argv
[0]);
4013 while (p
!= argv
[0] && p
[-1] != '/') --p
;
4016 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4017 signal (SIGINT
, fatal_error
);
4019 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4020 signal (SIGHUP
, fatal_error
);
4022 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4023 signal (SIGTERM
, fatal_error
);
4025 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4026 signal (SIGPIPE
, fatal_error
);
4030 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4032 obstack_init (&obstack
);
4034 /* Set up to remember the pathname of gcc and any options
4035 needed for collect. We use argv[0] instead of programname because
4036 we need the complete pathname. */
4037 obstack_init (&collect_obstack
);
4038 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4039 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4040 putenv (obstack_finish (&collect_obstack
));
4042 /* Choose directory for temp files. */
4044 choose_temp_base ();
4046 /* Make a table of what switches there are (switches, n_switches).
4047 Make a table of specified input files (infiles, n_infiles).
4048 Decode switches that are handled locally. */
4050 process_command (argc
, argv
);
4052 /* Initialize the vector of specs to just the default.
4053 This means one element containing 0s, as a terminator. */
4055 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4056 bcopy ((char *) default_compilers
, (char *) compilers
,
4057 sizeof default_compilers
);
4058 n_compilers
= n_default_compilers
;
4060 /* Read specs from a file if there is one. */
4062 machine_suffix
= concat (spec_machine
, "/", concat (spec_version
, "/", ""));
4063 just_machine_suffix
= concat (spec_machine
, "/", "");
4065 specs_file
= find_a_file (&startfile_prefix
, "specs", R_OK
);
4066 /* Read the specs file unless it is a default one. */
4067 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4068 read_specs (specs_file
);
4070 /* If not cross-compiling, look for startfiles in the standard places. */
4071 /* The fact that these are done here, after reading the specs file,
4072 means that it cannot be found in these directories.
4073 But that's okay. It should never be there anyway. */
4076 #ifdef MD_EXEC_PREFIX
4077 add_prefix (&exec_prefix
, md_exec_prefix
, 0, 0, NULL_PTR
);
4078 add_prefix (&startfile_prefix
, md_exec_prefix
, 0, 0, NULL_PTR
);
4081 #ifdef MD_STARTFILE_PREFIX
4082 add_prefix (&startfile_prefix
, md_startfile_prefix
, 0, 0, NULL_PTR
);
4085 #ifdef MD_STARTFILE_PREFIX_1
4086 add_prefix (&startfile_prefix
, md_startfile_prefix_1
, 0, 0, NULL_PTR
);
4089 /* If standard_startfile_prefix is relative, base it on
4090 standard_exec_prefix. This lets us move the installed tree
4091 as a unit. If GCC_EXEC_PREFIX is defined, base
4092 standard_startfile_prefix on that as well. */
4093 if (*standard_startfile_prefix
== '/')
4094 add_prefix (&startfile_prefix
, standard_startfile_prefix
, 0, 0,
4098 if (gcc_exec_prefix
)
4099 add_prefix (&startfile_prefix
,
4100 concat (gcc_exec_prefix
,
4101 standard_startfile_prefix
,
4104 add_prefix (&startfile_prefix
,
4105 concat (standard_exec_prefix
,
4107 standard_startfile_prefix
),
4111 add_prefix (&startfile_prefix
, standard_startfile_prefix_1
, 0, 0,
4113 add_prefix (&startfile_prefix
, standard_startfile_prefix_2
, 0, 0,
4115 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4116 add_prefix (&startfile_prefix
, "./", 0, 1, NULL_PTR
);
4120 /* Now we have the specs.
4121 Set the `valid' bits for switches that match anything in any spec. */
4123 validate_all_switches ();
4125 /* Now that we have the switches and the specs, set
4126 the subdirectory based on the options. */
4127 set_multilib_dir ();
4129 /* Warn about any switches that no pass was interested in. */
4131 for (i
= 0; i
< n_switches
; i
++)
4132 if (! switches
[i
].valid
)
4133 error ("unrecognized option `-%s'", switches
[i
].part1
);
4135 /* Obey some of the options. */
4137 if (print_file_name
)
4139 printf ("%s\n", find_file (print_file_name
));
4143 if (print_prog_name
)
4145 char *newname
= find_a_file (&exec_prefix
, print_prog_name
, X_OK
);
4146 printf ("%s\n", (newname
? newname
: print_prog_name
));
4150 if (print_multi_lib
)
4152 print_multilib_info ();
4156 if (print_multi_directory
)
4158 if (multilib_dir
== NULL
)
4161 printf ("%s\n", multilib_dir
);
4167 fprintf (stderr
, "gcc version %s\n", version_string
);
4173 fatal ("No input files");
4175 /* Make a place to record the compiler output file names
4176 that correspond to the input files. */
4178 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4179 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4181 /* Record which files were specified explicitly as link input. */
4183 explicit_link_files
= xmalloc (n_infiles
);
4184 bzero (explicit_link_files
, n_infiles
);
4186 for (i
= 0; i
< n_infiles
; i
++)
4188 register struct compiler
*cp
= 0;
4189 int this_file_error
= 0;
4191 /* Tell do_spec what to substitute for %i. */
4193 input_filename
= infiles
[i
].name
;
4194 input_filename_length
= strlen (input_filename
);
4195 input_file_number
= i
;
4197 /* Use the same thing in %o, unless cp->spec says otherwise. */
4199 outfiles
[i
] = input_filename
;
4201 /* Figure out which compiler from the file's suffix. */
4203 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4204 infiles
[i
].language
);
4208 /* Ok, we found an applicable compiler. Run its spec. */
4209 /* First say how much of input_filename to substitute for %b */
4213 input_basename
= input_filename
;
4214 for (p
= input_filename
; *p
; p
++)
4216 input_basename
= p
+ 1;
4218 /* Find a suffix starting with the last period,
4219 and set basename_length to exclude that suffix. */
4220 basename_length
= strlen (input_basename
);
4221 p
= input_basename
+ basename_length
;
4222 while (p
!= input_basename
&& *p
!= '.') --p
;
4223 if (*p
== '.' && p
!= input_basename
)
4225 basename_length
= p
- input_basename
;
4226 input_suffix
= p
+ 1;
4232 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4234 len
+= strlen (cp
->spec
[j
]);
4236 p
= (char *) xmalloc (len
+ 1);
4239 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4242 strcpy (p
+ len
, cp
->spec
[j
]);
4243 len
+= strlen (cp
->spec
[j
]);
4246 value
= do_spec (p
);
4249 this_file_error
= 1;
4252 /* If this file's name does not contain a recognized suffix,
4253 record it as explicit linker input. */
4256 explicit_link_files
[i
] = 1;
4258 /* Clear the delete-on-failure queue, deleting the files in it
4259 if this compilation failed. */
4261 if (this_file_error
)
4263 delete_failure_queue ();
4266 /* If this compilation succeeded, don't delete those files later. */
4267 clear_failure_queue ();
4270 /* Run ld to link all the compiler output files. */
4272 if (error_count
== 0)
4274 int tmp
= execution_count
;
4278 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4280 putenv_from_prefixes (&exec_prefix
, "COMPILER_PATH=");
4281 putenv_from_prefixes (&startfile_prefix
, "LIBRARY_PATH=");
4283 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4285 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4286 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4289 for (i
= 0; i
< n_switches
; i
++)
4293 obstack_grow (&collect_obstack
, " ", 1);
4296 obstack_grow (&collect_obstack
, "-", 1);
4297 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4298 strlen (switches
[i
].part1
));
4300 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4302 obstack_grow (&collect_obstack
, " ", 1);
4303 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4306 obstack_grow (&collect_obstack
, "\0", 1);
4307 putenv (obstack_finish (&collect_obstack
));
4309 value
= do_spec (link_command_spec
);
4312 linker_was_run
= (tmp
!= execution_count
);
4315 /* Warn if a -B option was specified but the prefix was never used. */
4316 unused_prefix_warnings (&exec_prefix
);
4317 unused_prefix_warnings (&startfile_prefix
);
4319 /* If options said don't run linker,
4320 complain about input files to be given to the linker. */
4322 if (! linker_was_run
&& error_count
== 0)
4323 for (i
= 0; i
< n_infiles
; i
++)
4324 if (explicit_link_files
[i
])
4325 error ("%s: linker input file unused since linking not done",
4328 /* Delete some or all of the temporary files we made. */
4331 delete_failure_queue ();
4332 delete_temp_files ();
4334 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4339 /* Find the proper compilation spec for the file name NAME,
4340 whose length is LENGTH. LANGUAGE is the specified language,
4341 or 0 if none specified. */
4343 static struct compiler
*
4344 lookup_compiler (name
, length
, language
)
4349 struct compiler
*cp
;
4351 /* Look for the language, if one is spec'd. */
4354 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4358 if (cp
->suffix
[0] == '@'
4359 && !strcmp (cp
->suffix
+ 1, language
))
4363 error ("language %s not recognized", language
);
4366 /* Look for a suffix. */
4367 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4369 if (/* The suffix `-' matches only the file name `-'. */
4370 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4372 (strlen (cp
->suffix
) < length
4373 /* See if the suffix matches the end of NAME. */
4374 && !strcmp (cp
->suffix
,
4375 name
+ length
- strlen (cp
->suffix
))))
4377 if (cp
->spec
[0][0] == '@')
4379 struct compiler
*new;
4380 /* An alias entry maps a suffix to a language.
4381 Search for the language; pass 0 for NAME and LENGTH
4382 to avoid infinite recursion if language not found.
4383 Construct the new compiler spec. */
4384 language
= cp
->spec
[0] + 1;
4385 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4386 new->suffix
= cp
->suffix
;
4387 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4388 (char *) new->spec
, sizeof new->spec
);
4391 /* A non-alias entry: return it. */
4403 register char *value
= (char *) malloc (size
);
4405 fatal ("virtual memory exhausted");
4410 xrealloc (ptr
, size
)
4414 register char *value
= (char *) realloc (ptr
, size
);
4416 fatal ("virtual memory exhausted");
4420 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
4426 int len1
= strlen (s1
), len2
= strlen (s2
), len3
= strlen (s3
);
4427 char *result
= xmalloc (len1
+ len2
+ len3
+ 1);
4429 strcpy (result
, s1
);
4430 strcpy (result
+ len1
, s2
);
4431 strcpy (result
+ len1
+ len2
, s3
);
4432 *(result
+ len1
+ len2
+ len3
) = 0;
4438 save_string (s
, len
)
4442 register char *result
= xmalloc (len
+ 1);
4444 bcopy (s
, result
, len
);
4450 pfatal_with_name (name
)
4455 if (errno
< sys_nerr
)
4456 s
= concat ("%s: ", sys_errlist
[errno
], "");
4458 s
= "cannot open %s";
4463 perror_with_name (name
)
4468 if (errno
< sys_nerr
)
4469 s
= concat ("%s: ", sys_errlist
[errno
], "");
4471 s
= "cannot open %s";
4481 if (errno
< sys_nerr
)
4482 s
= concat ("installation problem, cannot exec %s: ",
4483 sys_errlist
[errno
], "");
4485 s
= "installation problem, cannot exec %s";
4489 /* More 'friendly' abort that prints the line and file.
4490 config.h can #define abort fancy_abort if you like that sort of thing. */
4495 fatal ("Internal gcc abort.");
4500 /* Output an error message and exit */
4503 fatal
VPROTO((char *format
, ...))
4510 VA_START (ap
, format
);
4513 format
= va_arg (ap
, char*);
4516 fprintf (stderr
, "%s: ", programname
);
4517 vfprintf (stderr
, format
, ap
);
4519 fprintf (stderr
, "\n");
4520 delete_temp_files ();
4525 error
VPROTO((char *format
, ...))
4532 VA_START (ap
, format
);
4535 format
= va_arg (ap
, char*);
4538 fprintf (stderr
, "%s: ", programname
);
4539 vfprintf (stderr
, format
, ap
);
4542 fprintf (stderr
, "\n");
4545 #else /* not HAVE_VPRINTF */
4548 fatal (msg
, arg1
, arg2
)
4549 char *msg
, *arg1
, *arg2
;
4551 error (msg
, arg1
, arg2
);
4552 delete_temp_files ();
4557 error (msg
, arg1
, arg2
)
4558 char *msg
, *arg1
, *arg2
;
4560 fprintf (stderr
, "%s: ", programname
);
4561 fprintf (stderr
, msg
, arg1
, arg2
);
4562 fprintf (stderr
, "\n");
4565 #endif /* not HAVE_VPRINTF */
4569 validate_all_switches ()
4571 struct compiler
*comp
;
4574 struct spec_list
*spec
;
4576 for (comp
= compilers
; comp
->spec
[0]; comp
++)
4579 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
4583 if (c
== '%' && *p
== '{')
4584 /* We have a switch spec. */
4585 validate_switches (p
+ 1);
4589 /* look through the linked list of extra specs read from the specs file */
4590 for (spec
= specs
; spec
; spec
= spec
->next
)
4594 if (c
== '%' && *p
== '{')
4595 /* We have a switch spec. */
4596 validate_switches (p
+ 1);
4599 p
= link_command_spec
;
4601 if (c
== '%' && *p
== '{')
4602 /* We have a switch spec. */
4603 validate_switches (p
+ 1);
4605 /* Now notice switches mentioned in the machine-specific specs. */
4609 if (c
== '%' && *p
== '{')
4610 /* We have a switch spec. */
4611 validate_switches (p
+ 1);
4615 if (c
== '%' && *p
== '{')
4616 /* We have a switch spec. */
4617 validate_switches (p
+ 1);
4621 if (c
== '%' && *p
== '{')
4622 /* We have a switch spec. */
4623 validate_switches (p
+ 1);
4625 p
= signed_char_spec
;
4627 if (c
== '%' && *p
== '{')
4628 /* We have a switch spec. */
4629 validate_switches (p
+ 1);
4633 if (c
== '%' && *p
== '{')
4634 /* We have a switch spec. */
4635 validate_switches (p
+ 1);
4639 if (c
== '%' && *p
== '{')
4640 /* We have a switch spec. */
4641 validate_switches (p
+ 1);
4645 if (c
== '%' && *p
== '{')
4646 /* We have a switch spec. */
4647 validate_switches (p
+ 1);
4651 if (c
== '%' && *p
== '{')
4652 /* We have a switch spec. */
4653 validate_switches (p
+ 1);
4657 if (c
== '%' && *p
== '{')
4658 /* We have a switch spec. */
4659 validate_switches (p
+ 1);
4662 /* Look at the switch-name that comes after START
4663 and mark as valid all supplied switches that match it. */
4666 validate_switches (start
)
4669 register char *p
= start
;
4684 while (*p
!= ':' && *p
!= '}') p
++;
4688 else if (p
[-1] == '*')
4690 /* Mark all matching switches as valid. */
4692 for (i
= 0; i
< n_switches
; i
++)
4693 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
4694 switches
[i
].valid
= 1;
4698 /* Mark an exact matching switch as valid. */
4699 for (i
= 0; i
< n_switches
; i
++)
4701 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4702 && switches
[i
].part1
[p
- filter
] == 0)
4703 switches
[i
].valid
= 1;
4708 /* Check whether a particular argument was used. */
4717 for (i
= 0; i
< n_switches
; i
++)
4718 if (! strncmp (switches
[i
].part1
, p
, len
)
4719 && strlen (switches
[i
].part1
) == len
)
4724 /* Work out the subdirectory to use based on the
4725 options. The format of multilib_select is a list of elements.
4726 Each element is a subdirectory name followed by a list of options
4727 followed by a semicolon. gcc will consider each line in turn. If
4728 none of the options beginning with an exclamation point are
4729 present, and all of the other options are present, that
4730 subdirectory will be used. */
4735 char *p
= multilib_select
;
4737 char *this_path
, *this_arg
;
4742 /* Ignore newlines. */
4749 /* Get the initial path. */
4757 this_path_len
= p
- this_path
;
4759 /* Check the arguments. */
4774 while (*p
!= ' ' && *p
!= ';')
4781 if (*this_arg
== '!')
4782 failed
= used_arg (this_arg
+ 1, p
- (this_arg
+ 1));
4784 failed
= ! used_arg (this_arg
, p
- this_arg
);
4792 if (this_path_len
!= 1
4793 || this_path
[0] != '.')
4795 multilib_dir
= xmalloc (this_path_len
+ 1);
4796 strncpy (multilib_dir
, this_path
, this_path_len
);
4797 multilib_dir
[this_path_len
] = '\0';
4806 /* Print out the multiple library subdirectory selection
4807 information. This prints out a series of lines. Each line looks
4808 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
4809 required. Only the desired options are printed out, the negative
4810 matches. The options are print without a leading dash. There are
4811 no spaces to make it easy to use the information in the shell.
4812 Each subdirectory is printed only once. This assumes the ordering
4813 generated by the genmultilib script. */
4816 print_multilib_info ()
4818 char *p
= multilib_select
;
4819 char *last_path
, *this_path
;
4820 int last_path_len
, skip
, use_arg
;
4824 /* Ignore newlines. */
4831 /* Get the initial path. */
4840 /* If this is a duplicate, skip it. */
4841 skip
= (p
- this_path
== last_path_len
4842 && ! strncmp (last_path
, this_path
, last_path_len
));
4844 last_path
= this_path
;
4845 last_path_len
= p
- this_path
;
4851 for (p1
= last_path
; p1
< p
; p1
++)
4870 use_arg
= *p
!= '!';
4875 while (*p
!= ' ' && *p
!= ';')