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>
40 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
54 /* Include multi-lib information. */
64 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
67 #define WTERMSIG(S) ((S) & 0x7f)
70 #define WIFEXITED(S) (((S) & 0xff) == 0)
73 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
76 /* Add prototype support. */
78 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
79 #define PROTO(ARGS) ARGS
81 #define PROTO(ARGS) ()
87 #define PVPROTO(ARGS) ARGS
88 #define VPROTO(ARGS) ARGS
89 #define VA_START(va_list,var) va_start(va_list,var)
91 #define PVPROTO(ARGS) ()
92 #define VPROTO(ARGS) (va_alist) va_dcl
93 #define VA_START(va_list,var) va_start(va_list)
97 /* Define a generic NULL if one hasn't already been defined. */
104 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
105 #define GENERIC_PTR void *
107 #define GENERIC_PTR char *
112 #define NULL_PTR ((GENERIC_PTR)0)
119 /* On MSDOS, write temp files in current dir
120 because there's no place else we can expect to use. */
127 /* Test if something is a normal file. */
129 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
132 /* Test if something is a directory. */
134 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
137 /* By default there is no special suffix for executables. */
138 #ifndef EXECUTABLE_SUFFIX
139 #define EXECUTABLE_SUFFIX ""
142 /* By default, colon separates directories in a path. */
143 #ifndef PATH_SEPARATOR
144 #define PATH_SEPARATOR ':'
147 #ifndef DIR_SEPARATOR
148 #define DIR_SEPARATOR '/'
151 static char dir_separator_str
[] = {DIR_SEPARATOR
, 0};
153 #define obstack_chunk_alloc xmalloc
154 #define obstack_chunk_free free
157 extern char *getenv ();
164 #if defined(bsd4_4) || defined(__NetBSD__)
165 extern const char *const sys_errlist
[];
167 extern char *sys_errlist
[];
170 extern int execv (), execvp ();
172 /* If a stage of compilation returns an exit status >= 1,
173 compilation of that file ceases. */
175 #define MIN_FATAL_STATUS 1
177 /* Flag saying to print the full filename of this file
178 as found through our usual search mechanism. */
180 static char *print_file_name
= NULL
;
182 /* As print_file_name, but search for executable file. */
184 static char *print_prog_name
= NULL
;
186 /* Flag saying to print the relative path we'd use to
187 find libgcc.a given the current compiler flags. */
189 static int print_multi_directory
;
191 /* Flag saying to print the list of subdirectories and
192 compiler flags used to select them in a standard form. */
194 static int print_multi_lib
;
196 /* Flag indicating whether we should print the command and arguments */
198 static int verbose_flag
;
200 /* Nonzero means write "temp" files in source directory
201 and use the source file's name in them, and don't delete them. */
203 static int save_temps_flag
;
205 /* The compiler version. */
207 static char *compiler_version
;
209 /* The target version specified with -V */
211 static char *spec_version
= DEFAULT_TARGET_VERSION
;
213 /* The target machine specified with -b. */
215 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
217 /* Nonzero if cross-compiling.
218 When -b is used, the value comes from the `specs' file. */
221 static int cross_compile
= 1;
223 static int cross_compile
= 0;
226 /* The number of errors that have occurred; the link phase will not be
227 run if this is non-zero. */
228 static int error_count
= 0;
230 /* This is the obstack which we use to allocate many strings. */
232 static struct obstack obstack
;
234 /* This is the obstack to build an environment variable to pass to
235 collect2 that describes all of the relevant switches of what to
236 pass the compiler in building the list of pointers to constructors
239 static struct obstack collect_obstack
;
241 extern char *version_string
;
243 /* Forward declaration for prototypes. */
246 static void set_spec
PROTO((char *, char *));
247 static struct compiler
*lookup_compiler
PROTO((char *, int, char *));
248 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
249 static void add_prefix
PROTO((struct path_prefix
*, char *, int, int, int *));
250 static char *skip_whitespace
PROTO((char *));
251 static void record_temp_file
PROTO((char *, int, int));
252 static void delete_if_ordinary
PROTO((char *));
253 static void delete_temp_files
PROTO((void));
254 static void delete_failure_queue
PROTO((void));
255 static void clear_failure_queue
PROTO((void));
256 static char *choose_temp_base_try
PROTO((char *, char *));
257 static void choose_temp_base
PROTO((void));
258 static int check_live_switch
PROTO((int, int));
259 static char *handle_braces
PROTO((char *));
260 static char *save_string
PROTO((char *, int));
261 static char *concat
PROTO((char *, char *));
262 static char *concat3
PROTO((char *, char *, char *));
263 static char *concat4
PROTO((char *, char *, char *, char *));
264 static char *concat6
PROTO((char *, char *, char *, char *, char *, \
266 static int do_spec
PROTO((char *));
267 static int do_spec_1
PROTO((char *, int, char *));
268 static char *find_file
PROTO((char *));
269 static int is_directory
PROTO((char *, char *, int));
270 static void validate_switches
PROTO((char *));
271 static void validate_all_switches
PROTO((void));
272 static void give_switch
PROTO((int, int));
273 static int used_arg
PROTO((char *, int));
274 static void set_multilib_dir
PROTO((void));
275 static void print_multilib_info
PROTO((void));
276 static void pfatal_with_name
PROTO((char *));
277 static void perror_with_name
PROTO((char *));
278 static void perror_exec
PROTO((char *));
280 static void fatal
PVPROTO((char *, ...));
281 static void error
PVPROTO((char *, ...));
283 /* We must not provide any prototype here, even if ANSI C. */
284 static void fatal
PROTO(());
285 static void error
PROTO(());
292 /* Specs are strings containing lines, each of which (if not blank)
293 is made up of a program name, and arguments separated by spaces.
294 The program name must be exact and start from root, since no path
295 is searched and it is unreliable to depend on the current working directory.
296 Redirection of input or output is not supported; the subprograms must
297 accept filenames saying what files to read and write.
299 In addition, the specs can contain %-sequences to substitute variable text
300 or for conditional text. Here is a table of all defined %-sequences.
301 Note that spaces are not generated automatically around the results of
302 expanding these sequences; therefore, you can concatenate them together
303 or with constant text in a single argument.
305 %% substitute one % into the program name or argument.
306 %i substitute the name of the input file being processed.
307 %b substitute the basename of the input file being processed.
308 This is the substring up to (and not including) the last period
309 and not including the directory.
310 %g substitute the temporary-file-name-base. This is a string chosen
311 once per compilation. Different temporary file names are made by
312 concatenation of constant strings on the end, as in `%g.s'.
313 %g also has the same effect of %d.
314 %u like %g, but make the temporary file name unique.
315 %U returns the last file name generated with %u.
316 %d marks the argument containing or following the %d as a
317 temporary file name, so that that file will be deleted if CC exits
318 successfully. Unlike %g, this contributes no text to the argument.
319 %w marks the argument containing or following the %w as the
320 "output file" of this compilation. This puts the argument
321 into the sequence of arguments that %o will substitute later.
323 like %{...} but mark last argument supplied within
324 as a file to be deleted on failure.
325 %o substitutes the names of all the output files, with spaces
326 automatically placed around them. You should write spaces
327 around the %o as well or the results are undefined.
328 %o is for use in the specs for running the linker.
329 Input files whose names have no recognized suffix are not compiled
330 at all, but they are included among the output files, so they will
332 %p substitutes the standard macro predefinitions for the
333 current target machine. Use this when running cpp.
334 %P like %p, but puts `__' before and after the name of each macro.
335 (Except macros that already have __.)
337 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
338 %s current argument is the name of a library or startup file of some sort.
339 Search for that file in a standard list of directories
340 and substitute the full name found.
341 %eSTR Print STR as an error message. STR is terminated by a newline.
342 Use this when inconsistent options are detected.
343 %x{OPTION} Accumulate an option for %X.
344 %X Output the accumulated linker options specified by compilations.
345 %Y Output the accumulated assembler options specified by compilations.
346 %Z Output the accumulated preprocessor options specified by compilations.
347 %v1 Substitute the major version number of GCC.
348 (For version 2.5.n, this is 2.)
349 %v2 Substitute the minor version number of GCC.
350 (For version 2.5.n, this is 5.)
351 %a process ASM_SPEC as a spec.
352 This allows config.h to specify part of the spec for running as.
353 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
354 used here. This can be used to run a post-processor after the
355 assembler has done it's job.
356 %D Dump out a -L option for each directory in startfile_prefixes.
357 If multilib_dir is set, extra entries are generated with it affixed.
358 %l process LINK_SPEC as a spec.
359 %L process LIB_SPEC as a spec.
360 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
361 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
362 %c process SIGNED_CHAR_SPEC as a spec.
363 %C process CPP_SPEC as a spec. A capital C is actually used here.
364 %1 process CC1_SPEC as a spec.
365 %2 process CC1PLUS_SPEC as a spec.
366 %| output "-" if the input for the current command is coming from a pipe.
367 %* substitute the variable part of a matched option. (See below.)
368 Note that each comma in the substituted string is replaced by
370 %{S} substitutes the -S switch, if that switch was given to CC.
371 If that switch was not specified, this substitutes nothing.
372 Here S is a metasyntactic variable.
373 %{S*} substitutes all the switches specified to CC whose names start
374 with -S. This is used for -o, -D, -I, etc; switches that take
375 arguments. CC considers `-o foo' as being one switch whose
376 name starts with `o'. %{o*} would substitute this text,
377 including the space; thus, two arguments would be generated.
378 %{S*:X} substitutes X if one or more switches whose names start with -S are
379 specified to CC. Note that the tail part of the -S option
380 (i.e. the part matched by the `*') will be substituted for each
381 occurrence of %* within X.
382 %{S:X} substitutes X, but only if the -S switch was given to CC.
383 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
384 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
385 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
386 %{.S:X} substitutes X, but only if processing a file with suffix S.
387 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
388 %(Spec) processes a specification defined in a specs file as *Spec:
389 %[Spec] as above, but put __ around -D arguments
391 The conditional text X in a %{S:X} or %{!S:X} construct may contain
392 other nested % constructs or spaces, or even newlines. They are
393 processed as usual, as described above.
395 The -O, -f, -m, and -W switches are handled specifically in these
396 constructs. If another value of -O or the negated form of a -f, -m, or
397 -W switch is found later in the command line, the earlier switch
398 value is ignored, except with {S*} where S is just one letter; this
399 passes all matching options.
401 The character | is used to indicate that a command should be piped to
402 the following command, but only if -pipe is specified.
404 Note that it is built into CC which switches take arguments and which
405 do not. You might think it would be useful to generalize this to
406 allow each compiler's spec to say which switches take arguments. But
407 this cannot be done in a consistent fashion. CC cannot even decide
408 which input files have been specified without knowing which switches
409 take arguments, and it must know which input files to compile in order
410 to tell which compilers to run.
412 CC also knows implicitly that arguments starting in `-l' are to be
413 treated as compiler output files, and passed to the linker in their
414 proper position among the other output files. */
416 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
418 /* config.h can define ASM_SPEC to provide extra args to the assembler
419 or extra switch-translations. */
424 /* config.h can define ASM_FINAL_SPEC to run a post processor after
425 the assembler has run. */
426 #ifndef ASM_FINAL_SPEC
427 #define ASM_FINAL_SPEC ""
430 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
431 or extra switch-translations. */
436 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
437 or extra switch-translations. */
442 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
443 or extra switch-translations. */
445 #define CC1PLUS_SPEC ""
448 /* config.h can define LINK_SPEC to provide extra args to the linker
449 or extra switch-translations. */
454 /* config.h can define LIB_SPEC to override the default libraries. */
456 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
459 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
460 #ifndef STARTFILE_SPEC
461 #define STARTFILE_SPEC \
462 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
465 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
466 Make the string nonempty to require spaces there. */
467 #ifndef SWITCHES_NEED_SPACES
468 #define SWITCHES_NEED_SPACES ""
471 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
473 #define ENDFILE_SPEC ""
476 /* This spec is used for telling cpp whether char is signed or not. */
477 #ifndef SIGNED_CHAR_SPEC
478 /* Use #if rather than ?:
479 because MIPS C compiler rejects like ?: in initializers. */
480 #if DEFAULT_SIGNED_CHAR
481 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
483 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
487 /* MULTILIB_SELECT comes from multilib.h. It gives a
488 string interpreted by set_multilib_dir to select a library
489 subdirectory based on the compiler options. */
490 #ifndef MULTILIB_SELECT
491 #define MULTILIB_SELECT ". ;"
494 static char *cpp_spec
= CPP_SPEC
;
495 static char *cpp_predefines
= CPP_PREDEFINES
;
496 static char *cc1_spec
= CC1_SPEC
;
497 static char *cc1plus_spec
= CC1PLUS_SPEC
;
498 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
499 static char *asm_spec
= ASM_SPEC
;
500 static char *asm_final_spec
= ASM_FINAL_SPEC
;
501 static char *link_spec
= LINK_SPEC
;
502 static char *lib_spec
= LIB_SPEC
;
503 static char *endfile_spec
= ENDFILE_SPEC
;
504 static char *startfile_spec
= STARTFILE_SPEC
;
505 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
506 static char *multilib_select
= MULTILIB_SELECT
;
508 /* This defines which switch letters take arguments. */
510 #ifndef SWITCH_TAKES_ARG
511 #define SWITCH_TAKES_ARG(CHAR) \
512 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
513 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
514 || (CHAR) == 'I' || (CHAR) == 'm' \
515 || (CHAR) == 'L' || (CHAR) == 'A')
518 /* This defines which multi-letter switches take arguments. */
520 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
521 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
522 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
523 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
524 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
525 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
526 || !strcmp (STR, "isystem"))
528 #ifndef WORD_SWITCH_TAKES_ARG
529 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
532 /* Record the mapping from file suffixes for compilation specs. */
536 char *suffix
; /* Use this compiler for input files
537 whose names end in this suffix. */
539 char *spec
[4]; /* To use this compiler, concatenate these
540 specs and pass to do_spec. */
543 /* Pointer to a vector of `struct compiler' that gives the spec for
544 compiling a file, based on its suffix.
545 A file that does not end in any of these suffixes will be passed
546 unchanged to the loader and nothing else will be done to it.
548 An entry containing two 0s is used to terminate the vector.
550 If multiple entries match a file, the last matching one is used. */
552 static struct compiler
*compilers
;
554 /* Number of entries in `compilers', not counting the null terminator. */
556 static int n_compilers
;
558 /* The default list of file name suffixes and their compilation specs. */
560 static struct compiler default_compilers
[] =
564 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
565 %{C:%{!E:%eGNU C does not support -C without using -E}}\
566 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
567 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
568 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
569 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
570 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
571 %{traditional-cpp:-traditional}\
572 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
573 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
574 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
575 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
576 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
577 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
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 }}}}"},
585 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
586 %{C:%{!E:%eGNU C does not support -C without using -E}}\
587 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
588 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
589 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
590 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
591 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
592 %{traditional-cpp:-traditional}\
593 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
595 %{!E:%e-E required when input is from standard input}"},
596 {".m", "@objective-c"},
598 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
599 %{C:%{!E:%eGNU C does not support -C without using -E}}\
600 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
601 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
602 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
603 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
604 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
605 %{traditional-cpp:-traditional}\
606 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
607 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
608 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
609 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
610 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
611 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
612 -lang-objc %{gen-decls} \
614 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
615 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
616 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
617 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
618 %{!pipe:%g.s} %A\n }}}}"},
621 "%{!E:%eCompilation of header file requested} \
622 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
623 %{C:%{!E:%eGNU C does not support -C without using -E}}\
624 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
625 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
626 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
627 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
628 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
629 %{traditional-cpp:-traditional}\
630 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
637 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
638 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
639 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
640 -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
641 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
642 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
643 %{traditional-cpp:-traditional} %{trigraphs}\
644 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
645 %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
646 "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\
647 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
648 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
649 %{traditional} %{v:-version} %{pg:-p} %{p}\
650 %{f*} %{+e*} %{aux-info*}\
651 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
652 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\
653 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
654 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
655 %{!pipe:%g.s} %A\n }}}}"},
656 {".i", "@cpp-output"},
658 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
659 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
660 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
662 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
663 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
664 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
665 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
666 %{!pipe:%g.s} %A\n }}}}"},
667 {".ii", "@c++-cpp-output"},
669 "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
670 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
671 %{traditional} %{v:-version} %{pg:-p} %{p}\
672 %{f*} %{+e*} %{aux-info*}\
673 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
674 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
675 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
676 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
677 %{!pipe:%g.s} %A\n }}}}"},
678 {".s", "@assembler"},
680 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
681 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
683 {".S", "@assembler-with-cpp"},
684 {"@assembler-with-cpp",
685 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
686 %{C:%{!E:%eGNU C does not support -C without using -E}}\
687 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
688 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
689 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
690 %{traditional-cpp:-traditional}\
691 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
692 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
693 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
694 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
695 %{!pipe:%g.s} %A\n }}}}"},
700 "%{!M:%{!MM:%{!E:gnat1 %{k8:-gnatk8} %{w:-gnatws} %{!Q:-quiet}\
701 -dumpbase %b.ada %{g*} %{O*} %{p} %{pg:-p} %{f*}\
703 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
704 %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
705 %{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
706 %{c:%W{o*}%{!o*:-o %w%b.o}}\
707 %{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n}}}}}} "},
708 /* Mark end of table */
712 /* Number of elements in default_compilers, not counting the terminator. */
714 static int n_default_compilers
715 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
717 /* Here is the spec for running the linker, after compiling all files. */
719 /* -u* was put back because both BSD and SysV seem to support it. */
720 /* %{static:} simply prevents an error message if the target machine
721 doesn't handle -static. */
722 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
723 scripts which exist in user specified directories, or in standard
725 #ifdef LINK_LIBGCC_SPECIAL_1
726 /* Have gcc do the search for libgcc.a, but generate -L options as usual. */
727 static char *link_command_spec
= "\
729 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
730 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
731 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
732 %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
734 #ifdef LINK_LIBGCC_SPECIAL
735 /* Have gcc do the search for libgcc.a, and don't generate -L options. */
736 static char *link_command_spec
= "\
738 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
739 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
740 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
741 %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
743 /* Use -L and have the linker do the search for -lgcc. */
744 static char *link_command_spec
= "\
746 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
747 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
748 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
749 %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}";
753 /* A vector of options to give to the linker.
754 These options are accumulated by -Xlinker and -Wl,
755 and substituted into the linker command with %X. */
756 static int n_linker_options
;
757 static char **linker_options
;
759 /* A vector of options to give to the assembler.
760 These options are accumulated by -Wa,
761 and substituted into the assembler command with %Y. */
762 static int n_assembler_options
;
763 static char **assembler_options
;
765 /* A vector of options to give to the preprocessor.
766 These options are accumulated by -Wp,
767 and substituted into the preprocessor command with %Z. */
768 static int n_preprocessor_options
;
769 static char **preprocessor_options
;
771 /* Define how to map long options into short ones. */
773 /* This structure describes one mapping. */
776 /* The long option's name. */
778 /* The equivalent short option. */
780 /* Argument info. A string of flag chars; NULL equals no options.
781 a => argument required.
782 o => argument optional.
783 j => join argument to equivalent, making one word.
784 * => require other text after NAME as an argument. */
788 /* This is the table of mappings. Mappings are tried sequentially
789 for each option encountered; the first one that matches, wins. */
791 struct option_map option_map
[] =
793 {"--all-warnings", "-Wall", 0},
794 {"--ansi", "-ansi", 0},
795 {"--assemble", "-S", 0},
796 {"--assert", "-A", "a"},
797 {"--comments", "-C", 0},
798 {"--compile", "-c", 0},
799 {"--debug", "-g", "oj"},
800 {"--define-macro", "-D", "a"},
801 {"--dependencies", "-M", 0},
802 {"--dump", "-d", "a"},
803 {"--dumpbase", "-dumpbase", "a"},
804 {"--entry", "-e", 0},
805 {"--extra-warnings", "-W", 0},
806 {"--for-assembler", "-Wa", "a"},
807 {"--for-linker", "-Xlinker", "a"},
808 {"--force-link", "-u", "a"},
809 {"--imacros", "-imacros", "a"},
810 {"--include", "-include", "a"},
811 {"--include-barrier", "-I-", 0},
812 {"--include-directory", "-I", "a"},
813 {"--include-directory-after", "-idirafter", "a"},
814 {"--include-prefix", "-iprefix", "a"},
815 {"--include-with-prefix", "-iwithprefix", "a"},
816 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
817 {"--include-with-prefix-after", "-iwithprefix", "a"},
818 {"--language", "-x", "a"},
819 {"--library-directory", "-L", "a"},
820 {"--machine", "-m", "aj"},
821 {"--machine-", "-m", "*j"},
822 {"--no-line-commands", "-P", 0},
823 {"--no-precompiled-includes", "-noprecomp", 0},
824 {"--no-standard-includes", "-nostdinc", 0},
825 {"--no-standard-libraries", "-nostdlib", 0},
826 {"--no-warnings", "-w", 0},
827 {"--optimize", "-O", "oj"},
828 {"--output", "-o", "a"},
829 {"--pedantic", "-pedantic", 0},
830 {"--pedantic-errors", "-pedantic-errors", 0},
831 {"--pipe", "-pipe", 0},
832 {"--prefix", "-B", "a"},
833 {"--preprocess", "-E", 0},
834 {"--print-file-name", "-print-file-name=", "aj"},
835 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
836 {"--print-missing-file-dependencies", "-MG", 0},
837 {"--print-multi-lib", "-print-multi-lib", 0},
838 {"--print-multi-directory", "-print-multi-directory", 0},
839 {"--print-prog-name", "-print-prog-name=", "aj"},
840 {"--profile", "-p", 0},
841 {"--profile-blocks", "-a", 0},
842 {"--quiet", "-q", 0},
843 {"--save-temps", "-save-temps", 0},
844 {"--shared", "-shared", 0},
845 {"--silent", "-q", 0},
846 {"--static", "-static", 0},
847 {"--symbolic", "-symbolic", 0},
848 {"--target", "-b", "a"},
849 {"--trace-includes", "-H", 0},
850 {"--traditional", "-traditional", 0},
851 {"--traditional-cpp", "-traditional-cpp", 0},
852 {"--trigraphs", "-trigraphs", 0},
853 {"--undefine-macro", "-U", "a"},
854 {"--use-version", "-V", "a"},
855 {"--user-dependencies", "-MM", 0},
856 {"--verbose", "-v", 0},
857 {"--version", "-dumpversion", 0},
858 {"--warn-", "-W", "*j"},
859 {"--write-dependencies", "-MD", 0},
860 {"--write-user-dependencies", "-MMD", 0},
864 /* Translate the options described by *ARGCP and *ARGVP.
865 Make a new vector and store it back in *ARGVP,
866 and store its length in *ARGVC. */
869 translate_options (argcp
, argvp
)
875 char **argv
= *argvp
;
876 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
880 newv
[newindex
++] = argv
[i
++];
884 /* Translate -- options. */
885 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
887 /* Find a mapping that applies to this option. */
888 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
890 int optlen
= strlen (option_map
[j
].name
);
891 int arglen
= strlen (argv
[i
]);
892 int complen
= arglen
> optlen
? optlen
: arglen
;
893 char *arginfo
= option_map
[j
].arg_info
;
898 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
905 k
< sizeof (option_map
) / sizeof (option_map
[0]);
907 if (strlen (option_map
[k
].name
) >= arglen
908 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
910 error ("Ambiguous abbreviation %s", argv
[i
]);
914 if (k
!= sizeof (option_map
) / sizeof (option_map
[0]))
920 /* If the option has an argument, accept that. */
921 if (argv
[i
][optlen
] == '=')
922 arg
= argv
[i
] + optlen
+ 1;
924 /* If this mapping requires extra text at end of name,
925 accept that as "argument". */
926 else if (index (arginfo
, '*') != 0)
927 arg
= argv
[i
] + optlen
;
929 /* Otherwise, extra text at end means mismatch.
930 Try other mappings. */
935 else if (index (arginfo
, '*') != 0)
937 error ("Incomplete `%s' option", option_map
[j
].name
);
941 /* Handle arguments. */
942 if (index (arginfo
, 'a') != 0)
948 error ("Missing argument to `%s' option",
956 else if (index (arginfo
, '*') != 0)
958 else if (index (arginfo
, 'o') == 0)
961 error ("Extraneous argument to `%s' option",
966 /* Store the translation as one argv elt or as two. */
967 if (arg
!= 0 && index (arginfo
, 'j') != 0)
968 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
);
971 newv
[newindex
++] = option_map
[j
].equivalent
;
972 newv
[newindex
++] = arg
;
975 newv
[newindex
++] = option_map
[j
].equivalent
;
983 /* Handle old-fashioned options--just copy them through,
984 with their arguments. */
985 else if (argv
[i
][0] == '-')
987 char *p
= argv
[i
] + 1;
991 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
992 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
993 else if (WORD_SWITCH_TAKES_ARG (p
))
994 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
995 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
998 else if (! strcmp (p
, "Xlinker"))
1001 /* Watch out for an option at the end of the command line that
1002 is missing arguments, and avoid skipping past the end of the
1004 if (nskip
+ i
> argc
)
1009 newv
[newindex
++] = argv
[i
++];
1014 /* Ordinary operands, or +e options. */
1015 newv
[newindex
++] = argv
[i
++];
1024 /* Read compilation specs from a file named FILENAME,
1025 replacing the default ones.
1027 A suffix which starts with `*' is a definition for
1028 one of the machine-specific sub-specs. The "suffix" should be
1029 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1030 The corresponding spec is stored in asm_spec, etc.,
1031 rather than in the `compilers' vector.
1033 Anything invalid in the file is a fatal error. */
1036 read_specs (filename
)
1040 struct stat statbuf
;
1045 fprintf (stderr
, "Reading specs from %s\n", filename
);
1047 /* Open and stat the file. */
1048 desc
= open (filename
, 0, 0);
1050 pfatal_with_name (filename
);
1051 if (stat (filename
, &statbuf
) < 0)
1052 pfatal_with_name (filename
);
1054 /* Read contents of file into BUFFER. */
1055 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1056 read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1057 buffer
[statbuf
.st_size
] = 0;
1060 /* Scan BUFFER for specs, putting them in the vector. */
1066 char *in
, *out
, *p1
, *p2
;
1068 /* Advance P in BUFFER to the next nonblank nocomment line. */
1069 p
= skip_whitespace (p
);
1073 /* Find the colon that should end the suffix. */
1075 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
1076 /* The colon shouldn't be missing. */
1078 fatal ("specs file malformed after %d characters", p1
- buffer
);
1079 /* Skip back over trailing whitespace. */
1081 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
1082 /* Copy the suffix to a string. */
1083 suffix
= save_string (p
, p2
- p
);
1084 /* Find the next line. */
1085 p
= skip_whitespace (p1
+ 1);
1087 fatal ("specs file malformed after %d characters", p
- buffer
);
1089 /* Find next blank line. */
1090 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
1091 /* Specs end at the blank line and do not include the newline. */
1092 spec
= save_string (p
, p1
- p
);
1095 /* Delete backslash-newline sequences from the spec. */
1100 if (in
[0] == '\\' && in
[1] == '\n')
1102 else if (in
[0] == '#')
1104 while (*in
&& *in
!= '\n') in
++;
1111 if (suffix
[0] == '*')
1113 if (! strcmp (suffix
, "*link_command"))
1114 link_command_spec
= spec
;
1116 set_spec (suffix
+ 1, spec
);
1120 /* Add this pair to the vector. */
1122 = ((struct compiler
*)
1123 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
1124 compilers
[n_compilers
].suffix
= suffix
;
1125 bzero ((char *) compilers
[n_compilers
].spec
,
1126 sizeof compilers
[n_compilers
].spec
);
1127 compilers
[n_compilers
].spec
[0] = spec
;
1129 bzero ((char *) &compilers
[n_compilers
],
1130 sizeof compilers
[n_compilers
]);
1134 link_command_spec
= spec
;
1137 if (link_command_spec
== 0)
1138 fatal ("spec file has no spec for linking");
1147 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1148 be considered whitespace. */
1149 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1151 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1155 while (*p
!= '\n') p
++;
1165 /* Structure to keep track of the specs that have been defined so far. These
1166 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1170 char *name
; /* Name of the spec. */
1171 char *spec
; /* The spec itself. */
1172 struct spec_list
*next
; /* Next spec in linked list. */
1175 /* List of specs that have been defined so far. */
1177 static struct spec_list
*specs
= (struct spec_list
*) 0;
1179 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1180 removed; If the spec starts with a + then SPEC is added to the end of the
1184 set_spec (name
, spec
)
1188 struct spec_list
*sl
;
1191 /* See if the spec already exists */
1192 for (sl
= specs
; sl
; sl
= sl
->next
)
1193 if (strcmp (sl
->name
, name
) == 0)
1198 /* Not found - make it */
1199 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1200 sl
->name
= save_string (name
, strlen (name
));
1201 sl
->spec
= save_string ("", 0);
1206 old_spec
= sl
->spec
;
1207 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
1208 sl
->spec
= concat (old_spec
, spec
+ 1);
1210 sl
->spec
= save_string (spec
, strlen (spec
));
1212 if (! strcmp (name
, "asm"))
1213 asm_spec
= sl
->spec
;
1214 else if (! strcmp (name
, "asm_final"))
1215 asm_final_spec
= sl
->spec
;
1216 else if (! strcmp (name
, "cc1"))
1217 cc1_spec
= sl
->spec
;
1218 else if (! strcmp (name
, "cc1plus"))
1219 cc1plus_spec
= sl
->spec
;
1220 else if (! strcmp (name
, "cpp"))
1221 cpp_spec
= sl
->spec
;
1222 else if (! strcmp (name
, "endfile"))
1223 endfile_spec
= sl
->spec
;
1224 else if (! strcmp (name
, "lib"))
1225 lib_spec
= sl
->spec
;
1226 else if (! strcmp (name
, "link"))
1227 link_spec
= sl
->spec
;
1228 else if (! strcmp (name
, "predefines"))
1229 cpp_predefines
= sl
->spec
;
1230 else if (! strcmp (name
, "signed_char"))
1231 signed_char_spec
= sl
->spec
;
1232 else if (! strcmp (name
, "startfile"))
1233 startfile_spec
= sl
->spec
;
1234 else if (! strcmp (name
, "switches_need_spaces"))
1235 switches_need_spaces
= sl
->spec
;
1236 else if (! strcmp (name
, "cross_compile"))
1237 cross_compile
= atoi (sl
->spec
);
1238 else if (! strcmp (name
, "multilib"))
1239 multilib_select
= sl
->spec
;
1240 /* Free the old spec */
1245 /* Accumulate a command (program name and args), and run it. */
1247 /* Vector of pointers to arguments in the current line of specifications. */
1249 static char **argbuf
;
1251 /* Number of elements allocated in argbuf. */
1253 static int argbuf_length
;
1255 /* Number of elements in argbuf currently in use (containing args). */
1257 static int argbuf_index
;
1259 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1260 temp file. Used only if MKTEMP_EACH_FILE. */
1262 static struct temp_name
{
1263 char *suffix
; /* suffix associated with the code. */
1264 int length
; /* strlen (suffix). */
1265 int unique
; /* Indicates whether %g or %u/%U was used. */
1266 char *filename
; /* associated filename. */
1267 int filename_length
; /* strlen (filename). */
1268 struct temp_name
*next
;
1271 /* Number of commands executed so far. */
1273 static int execution_count
;
1275 /* Number of commands that exited with a signal. */
1277 static int signal_count
;
1279 /* Name with which this program was invoked. */
1281 static char *programname
;
1283 /* Structures to keep track of prefixes to try when looking for files. */
1287 char *prefix
; /* String to prepend to the path. */
1288 struct prefix_list
*next
; /* Next in linked list. */
1289 int require_machine_suffix
; /* Don't use without machine_suffix. */
1290 /* 2 means try both machine_suffix and just_machine_suffix. */
1291 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1296 struct prefix_list
*plist
; /* List of prefixes to try */
1297 int max_len
; /* Max length of a prefix in PLIST */
1298 char *name
; /* Name of this list (used in config stuff) */
1301 /* List of prefixes to try when looking for executables. */
1303 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1305 /* List of prefixes to try when looking for startup (crt0) files. */
1307 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1309 /* List of prefixes to try when looking for include files. */
1311 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1313 /* Suffix to attach to directories searched for commands.
1314 This looks like `MACHINE/VERSION/'. */
1316 static char *machine_suffix
= 0;
1318 /* Suffix to attach to directories searched for commands.
1319 This is just `MACHINE/'. */
1321 static char *just_machine_suffix
= 0;
1323 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1325 static char *gcc_exec_prefix
;
1327 /* Default prefixes to attach to command names. */
1329 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1330 #undef MD_EXEC_PREFIX
1331 #undef MD_STARTFILE_PREFIX
1332 #undef MD_STARTFILE_PREFIX_1
1335 #ifndef STANDARD_EXEC_PREFIX
1336 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1337 #endif /* !defined STANDARD_EXEC_PREFIX */
1339 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1340 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1341 #ifdef MD_EXEC_PREFIX
1342 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1345 #ifndef STANDARD_STARTFILE_PREFIX
1346 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1347 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1349 #ifdef MD_STARTFILE_PREFIX
1350 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1352 #ifdef MD_STARTFILE_PREFIX_1
1353 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1355 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1356 static char *standard_startfile_prefix_1
= "/lib/";
1357 static char *standard_startfile_prefix_2
= "/usr/lib/";
1359 #ifndef TOOLDIR_BASE_PREFIX
1360 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1362 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1363 static char *tooldir_prefix
;
1365 /* Subdirectory to use for locating libraries. Set by
1366 set_multilib_dir based on the compilation options. */
1368 static char *multilib_dir
;
1370 /* Clear out the vector of arguments (after a command is executed). */
1378 /* Add one argument to the vector at the end.
1379 This is done when a space is seen or at the end of the line.
1380 If DELETE_ALWAYS is nonzero, the arg is a filename
1381 and the file should be deleted eventually.
1382 If DELETE_FAILURE is nonzero, the arg is a filename
1383 and the file should be deleted if this compilation fails. */
1386 store_arg (arg
, delete_always
, delete_failure
)
1388 int delete_always
, delete_failure
;
1390 if (argbuf_index
+ 1 == argbuf_length
)
1392 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1395 argbuf
[argbuf_index
++] = arg
;
1396 argbuf
[argbuf_index
] = 0;
1398 if (delete_always
|| delete_failure
)
1399 record_temp_file (arg
, delete_always
, delete_failure
);
1402 /* Record the names of temporary files we tell compilers to write,
1403 and delete them at the end of the run. */
1405 /* This is the common prefix we use to make temp file names.
1406 It is chosen once for each run of this program.
1407 It is substituted into a spec by %g.
1408 Thus, all temp file names contain this prefix.
1409 In practice, all temp file names start with this prefix.
1411 This prefix comes from the envvar TMPDIR if it is defined;
1412 otherwise, from the P_tmpdir macro if that is defined;
1413 otherwise, in /usr/tmp or /tmp. */
1415 static char *temp_filename
;
1417 /* Length of the prefix. */
1419 static int temp_filename_length
;
1421 /* Define the list of temporary files to delete. */
1426 struct temp_file
*next
;
1429 /* Queue of files to delete on success or failure of compilation. */
1430 static struct temp_file
*always_delete_queue
;
1431 /* Queue of files to delete on failure of compilation. */
1432 static struct temp_file
*failure_delete_queue
;
1434 /* Record FILENAME as a file to be deleted automatically.
1435 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1436 otherwise delete it in any case.
1437 FAIL_DELETE nonzero means delete it if a compilation step fails;
1438 otherwise delete it in any case. */
1441 record_temp_file (filename
, always_delete
, fail_delete
)
1446 register char *name
;
1447 name
= xmalloc (strlen (filename
) + 1);
1448 strcpy (name
, filename
);
1452 register struct temp_file
*temp
;
1453 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1454 if (! strcmp (name
, temp
->name
))
1456 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1457 temp
->next
= always_delete_queue
;
1459 always_delete_queue
= temp
;
1465 register struct temp_file
*temp
;
1466 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1467 if (! strcmp (name
, temp
->name
))
1469 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1470 temp
->next
= failure_delete_queue
;
1472 failure_delete_queue
= temp
;
1477 /* Delete all the temporary files whose names we previously recorded. */
1480 delete_if_ordinary (name
)
1487 printf ("Delete %s? (y or n) ", name
);
1491 while ((c
= getchar ()) != '\n' && c
!= EOF
) ;
1492 if (i
== 'y' || i
== 'Y')
1494 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1495 if (unlink (name
) < 0)
1497 perror_with_name (name
);
1501 delete_temp_files ()
1503 register struct temp_file
*temp
;
1505 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1506 delete_if_ordinary (temp
->name
);
1507 always_delete_queue
= 0;
1510 /* Delete all the files to be deleted on error. */
1513 delete_failure_queue ()
1515 register struct temp_file
*temp
;
1517 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1518 delete_if_ordinary (temp
->name
);
1522 clear_failure_queue ()
1524 failure_delete_queue
= 0;
1527 /* Compute a string to use as the base of all temporary file names.
1528 It is substituted for %g. */
1531 choose_temp_base_try (try, base
)
1538 else if (try == (char *)0)
1540 else if (access (try, R_OK
| W_OK
) != 0)
1553 base
= choose_temp_base_try (getenv ("TMPDIR"), base
);
1554 base
= choose_temp_base_try (getenv ("TMP"), base
);
1555 base
= choose_temp_base_try (getenv ("TEMP"), base
);
1558 base
= choose_temp_base_try (P_tmpdir
, base
);
1561 base
= choose_temp_base_try (concat4 (dir_separator_str
, "usr",
1562 dir_separator_str
, "tmp"),
1564 base
= choose_temp_base_try (concat (dir_separator_str
, "tmp"), base
);
1566 /* If all else fails, use the current directory! */
1567 if (base
== (char *)0) base
= concat(".", dir_separator_str
);
1569 len
= strlen (base
);
1570 temp_filename
= xmalloc (len
+ strlen (concat (dir_separator_str
,
1572 strcpy (temp_filename
, base
);
1573 if (len
> 0 && temp_filename
[len
-1] != '/'
1574 && temp_filename
[len
-1] != DIR_SEPARATOR
)
1575 temp_filename
[len
++] = DIR_SEPARATOR
;
1576 strcpy (temp_filename
+ len
, "ccXXXXXX");
1578 mktemp (temp_filename
);
1579 temp_filename_length
= strlen (temp_filename
);
1580 if (temp_filename_length
== 0)
1585 /* Routine to add variables to the environment. We do this to pass
1586 the pathname of the gcc driver, and the directories search to the
1587 collect2 program, which is being run as ld. This way, we can be
1588 sure of executing the right compiler when collect2 wants to build
1589 constructors and destructors. Since the environment variables we
1590 use come from an obstack, we don't have to worry about allocating
1599 #ifndef VMS /* nor about VMS */
1601 extern char **environ
;
1602 char **old_environ
= environ
;
1606 int str_len
= strlen (str
);
1610 while ((ch
= *p
++) != '\0' && ch
!= '=')
1616 /* Search for replacing an existing environment variable, and
1617 count the number of total environment variables. */
1618 for (envp
= old_environ
; *envp
; envp
++)
1621 if (!strncmp (str
, *envp
, name_len
))
1628 /* Add a new environment variable */
1629 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1631 bcopy ((char *) old_environ
, (char *) (environ
+ 1),
1632 sizeof (char *) * (num_envs
+1));
1637 #endif /* HAVE_PUTENV */
1640 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1643 putenv_from_prefixes (paths
, env_var
)
1644 struct path_prefix
*paths
;
1647 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1649 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1650 int first_time
= TRUE
;
1651 struct prefix_list
*pprefix
;
1653 obstack_grow (&collect_obstack
, env_var
, strlen (env_var
));
1655 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1657 int len
= strlen (pprefix
->prefix
);
1660 && is_directory (pprefix
->prefix
, machine_suffix
, 0))
1663 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1666 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1667 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1670 if (just_machine_suffix
1671 && pprefix
->require_machine_suffix
== 2
1672 && is_directory (pprefix
->prefix
, just_machine_suffix
, 0))
1675 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1678 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1679 obstack_grow (&collect_obstack
, just_machine_suffix
,
1683 if (!pprefix
->require_machine_suffix
)
1686 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1689 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1692 obstack_1grow (&collect_obstack
, '\0');
1693 putenv (obstack_finish (&collect_obstack
));
1697 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1698 access to check permissions.
1699 Return 0 if not found, otherwise return its name, allocated with malloc. */
1702 find_a_file (pprefix
, name
, mode
)
1703 struct path_prefix
*pprefix
;
1708 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1709 struct prefix_list
*pl
;
1710 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1713 len
+= strlen (machine_suffix
);
1715 temp
= xmalloc (len
);
1717 /* Determine the filename to execute (special case for absolute paths). */
1719 if (*name
== '/' || *name
== DIR_SEPARATOR
)
1721 if (access (name
, mode
))
1723 strcpy (temp
, name
);
1728 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1732 /* Some systems have a suffix for executable files.
1733 So try appending that first. */
1734 if (file_suffix
[0] != 0)
1736 strcpy (temp
, pl
->prefix
);
1737 strcat (temp
, machine_suffix
);
1738 strcat (temp
, name
);
1739 strcat (temp
, file_suffix
);
1740 if (access (temp
, mode
) == 0)
1742 if (pl
->used_flag_ptr
!= 0)
1743 *pl
->used_flag_ptr
= 1;
1748 /* Now try just the name. */
1749 strcpy (temp
, pl
->prefix
);
1750 strcat (temp
, machine_suffix
);
1751 strcat (temp
, name
);
1752 if (access (temp
, mode
) == 0)
1754 if (pl
->used_flag_ptr
!= 0)
1755 *pl
->used_flag_ptr
= 1;
1760 /* Certain prefixes are tried with just the machine type,
1761 not the version. This is used for finding as, ld, etc. */
1762 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
1764 /* Some systems have a suffix for executable files.
1765 So try appending that first. */
1766 if (file_suffix
[0] != 0)
1768 strcpy (temp
, pl
->prefix
);
1769 strcat (temp
, just_machine_suffix
);
1770 strcat (temp
, name
);
1771 strcat (temp
, file_suffix
);
1772 if (access (temp
, mode
) == 0)
1774 if (pl
->used_flag_ptr
!= 0)
1775 *pl
->used_flag_ptr
= 1;
1780 strcpy (temp
, pl
->prefix
);
1781 strcat (temp
, just_machine_suffix
);
1782 strcat (temp
, name
);
1783 if (access (temp
, mode
) == 0)
1785 if (pl
->used_flag_ptr
!= 0)
1786 *pl
->used_flag_ptr
= 1;
1791 /* Certain prefixes can't be used without the machine suffix
1792 when the machine or version is explicitly specified. */
1793 if (!pl
->require_machine_suffix
)
1795 /* Some systems have a suffix for executable files.
1796 So try appending that first. */
1797 if (file_suffix
[0] != 0)
1799 strcpy (temp
, pl
->prefix
);
1800 strcat (temp
, name
);
1801 strcat (temp
, file_suffix
);
1802 if (access (temp
, mode
) == 0)
1804 if (pl
->used_flag_ptr
!= 0)
1805 *pl
->used_flag_ptr
= 1;
1810 strcpy (temp
, pl
->prefix
);
1811 strcat (temp
, name
);
1812 if (access (temp
, mode
) == 0)
1814 if (pl
->used_flag_ptr
!= 0)
1815 *pl
->used_flag_ptr
= 1;
1825 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1826 at the start of the list, otherwise it goes at the end.
1828 If WARN is nonzero, we will warn if no file is found
1829 through this prefix. WARN should point to an int
1830 which will be set to 1 if this entry is used.
1832 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1833 the complete value of machine_suffix.
1834 2 means try both machine_suffix and just_machine_suffix. */
1837 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1838 struct path_prefix
*pprefix
;
1841 int require_machine_suffix
;
1844 struct prefix_list
*pl
, **prev
;
1847 if (!first
&& pprefix
->plist
)
1849 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1854 prev
= &pprefix
->plist
;
1856 /* Keep track of the longest prefix */
1858 len
= strlen (prefix
);
1859 if (len
> pprefix
->max_len
)
1860 pprefix
->max_len
= len
;
1862 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1863 pl
->prefix
= save_string (prefix
, len
);
1864 pl
->require_machine_suffix
= require_machine_suffix
;
1865 pl
->used_flag_ptr
= warn
;
1872 pl
->next
= (struct prefix_list
*) 0;
1876 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1879 unused_prefix_warnings (pprefix
)
1880 struct path_prefix
*pprefix
;
1882 struct prefix_list
*pl
= pprefix
->plist
;
1886 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1888 error ("file path prefix `%s' never used",
1890 /* Prevent duplicate warnings. */
1891 *pl
->used_flag_ptr
= 1;
1897 /* Get rid of all prefixes built up so far in *PLISTP. */
1900 free_path_prefix (pprefix
)
1901 struct path_prefix
*pprefix
;
1903 struct prefix_list
*pl
= pprefix
->plist
;
1904 struct prefix_list
*temp
;
1910 free (temp
->prefix
);
1911 free ((char *) temp
);
1913 pprefix
->plist
= (struct prefix_list
*) 0;
1916 /* stdin file number. */
1917 #define STDIN_FILE_NO 0
1919 /* stdout file number. */
1920 #define STDOUT_FILE_NO 1
1922 /* value of `pipe': port index for reading. */
1925 /* value of `pipe': port index for writing. */
1926 #define WRITE_PORT 1
1928 /* Pipe waiting from last process, to be used as input for the next one.
1929 Value is STDIN_FILE_NO if no pipe is waiting
1930 (i.e. the next command is the first of a group). */
1932 static int last_pipe_input
;
1934 /* Fork one piped subcommand. FUNC is the system call to use
1935 (either execv or execvp). ARGV is the arg vector to use.
1936 NOT_LAST is nonzero if this is not the last subcommand
1937 (i.e. its output should be piped to the next one.) */
1941 #include <process.h>
1943 pexecute (search_flag
, program
, argv
, not_last
)
1950 int i
= (search_flag
? spawnv
: spawnvp
) (1, program
, argv
);
1954 int i
, el
= search_flag
? 0 : 4;
1956 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6 + el
);
1957 rf
= scmd
+ strlen(program
) + 2 + el
;
1958 sprintf (scmd
, "%s%s @%s.gp", program
,
1959 (search_flag
? "" : ".exe"), temp_filename
);
1960 argfile
= fopen (rf
, "w");
1962 pfatal_with_name (rf
);
1964 for (i
=1; argv
[i
]; i
++)
1967 for (cp
= argv
[i
]; *cp
; cp
++)
1969 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
1970 fputc ('\\', argfile
);
1971 fputc (*cp
, argfile
);
1973 fputc ('\n', argfile
);
1984 perror_exec (program
);
1985 return MIN_FATAL_STATUS
<< 8;
1992 #if !defined(__MSDOS__) && !defined(OS2) && !defined(WINNT)
1995 pexecute (search_flag
, program
, argv
, not_last
)
2001 int (*func
)() = (search_flag
? execv
: execvp
);
2004 int input_desc
= last_pipe_input
;
2005 int output_desc
= STDOUT_FILE_NO
;
2006 int retries
, sleep_interval
;
2008 /* If this isn't the last process, make a pipe for its output,
2009 and record it as waiting to be the input to the next process. */
2013 if (pipe (pdes
) < 0)
2014 pfatal_with_name ("pipe");
2015 output_desc
= pdes
[WRITE_PORT
];
2016 last_pipe_input
= pdes
[READ_PORT
];
2019 last_pipe_input
= STDIN_FILE_NO
;
2021 /* Fork a subprocess; wait and retry if it fails. */
2023 for (retries
= 0; retries
< 4; retries
++)
2028 sleep (sleep_interval
);
2029 sleep_interval
*= 2;
2036 pfatal_with_name ("fork");
2038 pfatal_with_name ("vfork");
2044 /* Move the input and output pipes into place, if nec. */
2045 if (input_desc
!= STDIN_FILE_NO
)
2047 close (STDIN_FILE_NO
);
2051 if (output_desc
!= STDOUT_FILE_NO
)
2053 close (STDOUT_FILE_NO
);
2055 close (output_desc
);
2058 /* Close the parent's descs that aren't wanted here. */
2059 if (last_pipe_input
!= STDIN_FILE_NO
)
2060 close (last_pipe_input
);
2062 /* Exec the program. */
2063 (*func
) (program
, argv
);
2064 perror_exec (program
);
2070 /* In the parent, after forking.
2071 Close the descriptors that we made for this child. */
2072 if (input_desc
!= STDIN_FILE_NO
)
2074 if (output_desc
!= STDOUT_FILE_NO
)
2075 close (output_desc
);
2077 /* Return child's process number. */
2082 #endif /* not __MSDOS__ and not OS2 */
2084 #if defined(OS2) || defined(WINNT)
2094 for (i
= 1; argvec
[i
] != 0; i
++)
2097 char *temp
, *newtemp
;
2100 len
= strlen (temp
);
2101 for (j
= 0; j
< len
; j
++)
2105 newtemp
= xmalloc (len
+ 2);
2106 strncpy (newtemp
, temp
, j
);
2108 strncpy (&newtemp
[j
+1], &temp
[j
], len
-j
);
2109 newtemp
[len
+1] = 0;
2123 #define FIX_ARGV(a) fix_argv(a)
2127 #define FIX_ARGV(a) a
2129 #endif /* OS2 or WINNT */
2132 pexecute (search_flag
, program
, argv
, not_last
)
2138 return (search_flag
? spawnv
: spawnvp
) (1, program
, FIX_ARGV (argv
));
2140 #endif /* OS2 or WINNT */
2143 /* Execute the command specified by the arguments on the current line of spec.
2144 When using pipes, this includes several piped-together commands
2145 with `|' between them.
2147 Return 0 if successful, -1 if failed. */
2153 int n_commands
; /* # of command. */
2157 char *prog
; /* program name. */
2158 char **argv
; /* vector of args. */
2159 int pid
; /* pid of process for this command. */
2162 struct command
*commands
; /* each command buffer with above info. */
2164 /* Count # of piped commands. */
2165 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2166 if (strcmp (argbuf
[i
], "|") == 0)
2169 /* Get storage for each command. */
2171 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2173 /* Split argbuf into its separate piped processes,
2174 and record info about each one.
2175 Also search for the programs that are to be run. */
2177 commands
[0].prog
= argbuf
[0]; /* first command. */
2178 commands
[0].argv
= &argbuf
[0];
2179 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2181 commands
[0].argv
[0] = string
;
2183 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2184 if (strcmp (argbuf
[i
], "|") == 0)
2185 { /* each command. */
2187 fatal ("-pipe not supported under MS-DOS");
2189 argbuf
[i
] = 0; /* termination of command args. */
2190 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2191 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2192 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2194 commands
[n_commands
].argv
[0] = string
;
2198 argbuf
[argbuf_index
] = 0;
2200 /* If -v, print what we are about to do, and maybe query. */
2204 /* Print each piped command as a separate line. */
2205 for (i
= 0; i
< n_commands
; i
++)
2209 for (j
= commands
[i
].argv
; *j
; j
++)
2210 fprintf (stderr
, " %s", *j
);
2212 /* Print a pipe symbol after all but the last command. */
2213 if (i
+ 1 != n_commands
)
2214 fprintf (stderr
, " |");
2215 fprintf (stderr
, "\n");
2219 fprintf (stderr
, "\nGo ahead? (y or n) ");
2223 while (getchar () != '\n') ;
2224 if (i
!= 'y' && i
!= 'Y')
2229 /* Run each piped subprocess. */
2231 last_pipe_input
= STDIN_FILE_NO
;
2232 for (i
= 0; i
< n_commands
; i
++)
2234 char *string
= commands
[i
].argv
[0];
2236 commands
[i
].pid
= pexecute (string
!= commands
[i
].prog
,
2237 string
, commands
[i
].argv
,
2238 i
+ 1 < n_commands
);
2240 if (string
!= commands
[i
].prog
)
2246 /* Wait for all the subprocesses to finish.
2247 We don't care what order they finish in;
2248 we know that N_COMMANDS waits will get them all. */
2253 for (i
= 0; i
< n_commands
; i
++)
2257 char *prog
= "unknown";
2260 status
= pid
= commands
[i
].pid
;
2263 pid
= cwait (&status
, commands
[i
].pid
, WAIT_CHILD
);
2265 pid
= wait (&status
);
2274 for (j
= 0; j
< n_commands
; j
++)
2275 if (commands
[j
].pid
== pid
)
2276 prog
= commands
[j
].prog
;
2278 if (WIFSIGNALED (status
))
2280 fatal ("Internal compiler error: program %s got fatal signal %d",
2281 prog
, WTERMSIG (status
));
2285 else if (WIFEXITED (status
)
2286 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2294 /* Find all the switches given to us
2295 and make a vector describing them.
2296 The elements of the vector are strings, one per switch given.
2297 If a switch uses following arguments, then the `part1' field
2298 is the switch itself and the `args' field
2299 is a null-terminated vector containing the following arguments.
2300 The `live_cond' field is 1 if the switch is true in a conditional spec,
2301 -1 if false (overridden by a later switch), and is initialized to zero.
2302 The `valid' field is nonzero if any spec has looked at this switch;
2303 if it remains zero at the end of the run, it must be meaningless. */
2313 static struct switchstr
*switches
;
2315 static int n_switches
;
2323 /* Also a vector of input files specified. */
2325 static struct infile
*infiles
;
2327 static int n_infiles
;
2329 /* And a vector of corresponding output files is made up later. */
2331 static char **outfiles
;
2333 /* Create the vector `switches' and its contents.
2334 Store its length in `n_switches'. */
2337 process_command (argc
, argv
)
2343 char *spec_lang
= 0;
2344 int last_language_n_infiles
;
2346 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2351 /* Figure compiler version from version string. */
2353 compiler_version
= save_string (version_string
, strlen (version_string
));
2354 for (temp
= compiler_version
; *temp
; ++temp
)
2363 /* Set up the default search paths. */
2365 if (gcc_exec_prefix
)
2367 add_prefix (&exec_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2368 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2371 /* COMPILER_PATH and LIBRARY_PATH have values
2372 that are lists of directory names with colons. */
2374 temp
= getenv ("COMPILER_PATH");
2377 char *startp
, *endp
;
2378 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2380 startp
= endp
= temp
;
2383 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2385 strncpy (nstore
, startp
, endp
-startp
);
2387 strcpy (nstore
, concat (".", dir_separator_str
));
2388 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2390 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2391 nstore
[endp
-startp
+1] = 0;
2394 nstore
[endp
-startp
] = 0;
2395 add_prefix (&exec_prefixes
, nstore
, 0, 0, NULL_PTR
);
2398 endp
= startp
= endp
+ 1;
2405 temp
= getenv ("LIBRARY_PATH");
2408 char *startp
, *endp
;
2409 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2411 startp
= endp
= temp
;
2414 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2416 strncpy (nstore
, startp
, endp
-startp
);
2418 strcpy (nstore
, concat (".", dir_separator_str
));
2419 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2421 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2422 nstore
[endp
-startp
+1] = 0;
2425 nstore
[endp
-startp
] = 0;
2426 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2429 endp
= startp
= endp
+ 1;
2436 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2437 temp
= getenv ("LPATH");
2440 char *startp
, *endp
;
2441 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2443 startp
= endp
= temp
;
2446 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2448 strncpy (nstore
, startp
, endp
-startp
);
2450 strcpy (nstore
, concat (".", dir_separator_str
));
2451 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2453 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2454 nstore
[endp
-startp
+1] = 0;
2457 nstore
[endp
-startp
] = 0;
2458 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2461 endp
= startp
= endp
+ 1;
2468 /* Convert new-style -- options to old-style. */
2469 translate_options (&argc
, &argv
);
2471 /* Scan argv twice. Here, the first time, just count how many switches
2472 there will be in their vector, and how many input files in theirs.
2473 Here we also parse the switches that cc itself uses (e.g. -v). */
2475 for (i
= 1; i
< argc
; i
++)
2477 if (! strcmp (argv
[i
], "-dumpspecs"))
2479 printf ("*asm:\n%s\n\n", asm_spec
);
2480 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
2481 printf ("*cpp:\n%s\n\n", cpp_spec
);
2482 printf ("*cc1:\n%s\n\n", cc1_spec
);
2483 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
2484 printf ("*endfile:\n%s\n\n", endfile_spec
);
2485 printf ("*link:\n%s\n\n", link_spec
);
2486 printf ("*lib:\n%s\n\n", lib_spec
);
2487 printf ("*startfile:\n%s\n\n", startfile_spec
);
2488 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
2489 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
2490 printf ("*predefines:\n%s\n\n", cpp_predefines
);
2491 printf ("*cross_compile:\n%d\n\n", cross_compile
);
2492 printf ("*multilib:\n%s\n\n", multilib_select
);
2496 else if (! strcmp (argv
[i
], "-dumpversion"))
2498 printf ("%s\n", version_string
);
2501 else if (! strcmp (argv
[i
], "-dumpmachine"))
2503 printf ("%s\n", spec_machine
);
2506 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2507 print_file_name
= "libgcc.a";
2508 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2509 print_file_name
= argv
[i
] + 17;
2510 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2511 print_prog_name
= argv
[i
] + 17;
2512 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2513 print_multi_lib
= 1;
2514 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2515 print_multi_directory
= 1;
2516 else if (! strcmp (argv
[i
], "-Xlinker"))
2518 /* Pass the argument of this option to the linker when we link. */
2521 fatal ("argument to `-Xlinker' is missing");
2524 if (!linker_options
)
2526 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2529 = (char **) xrealloc (linker_options
,
2530 n_linker_options
* sizeof (char **));
2532 linker_options
[n_linker_options
- 1] = argv
[++i
];
2534 else if (! strncmp (argv
[i
], "-Wl,", 4))
2537 /* Pass the rest of this option to the linker when we link. */
2540 if (!linker_options
)
2542 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2545 = (char **) xrealloc (linker_options
,
2546 n_linker_options
* sizeof (char **));
2548 /* Split the argument at commas. */
2550 for (j
= 4; argv
[i
][j
]; j
++)
2551 if (argv
[i
][j
] == ',')
2553 linker_options
[n_linker_options
- 1]
2554 = save_string (argv
[i
] + prev
, j
- prev
);
2557 = (char **) xrealloc (linker_options
,
2558 n_linker_options
* sizeof (char **));
2561 /* Record the part after the last comma. */
2562 linker_options
[n_linker_options
- 1] = argv
[i
] + prev
;
2564 else if (! strncmp (argv
[i
], "-Wa,", 4))
2567 /* Pass the rest of this option to the assembler. */
2569 n_assembler_options
++;
2570 if (!assembler_options
)
2572 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2575 = (char **) xrealloc (assembler_options
,
2576 n_assembler_options
* sizeof (char **));
2578 /* Split the argument at commas. */
2580 for (j
= 4; argv
[i
][j
]; j
++)
2581 if (argv
[i
][j
] == ',')
2583 assembler_options
[n_assembler_options
- 1]
2584 = save_string (argv
[i
] + prev
, j
- prev
);
2585 n_assembler_options
++;
2587 = (char **) xrealloc (assembler_options
,
2588 n_assembler_options
* sizeof (char **));
2591 /* Record the part after the last comma. */
2592 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2594 else if (! strncmp (argv
[i
], "-Wp,", 4))
2597 /* Pass the rest of this option to the preprocessor. */
2599 n_preprocessor_options
++;
2600 if (!preprocessor_options
)
2601 preprocessor_options
2602 = (char **) xmalloc (n_preprocessor_options
* sizeof (char **));
2604 preprocessor_options
2605 = (char **) xrealloc (preprocessor_options
,
2606 n_preprocessor_options
* sizeof (char **));
2608 /* Split the argument at commas. */
2610 for (j
= 4; argv
[i
][j
]; j
++)
2611 if (argv
[i
][j
] == ',')
2613 preprocessor_options
[n_preprocessor_options
- 1]
2614 = save_string (argv
[i
] + prev
, j
- prev
);
2615 n_preprocessor_options
++;
2616 preprocessor_options
2617 = (char **) xrealloc (preprocessor_options
,
2618 n_preprocessor_options
* sizeof (char **));
2621 /* Record the part after the last comma. */
2622 preprocessor_options
[n_preprocessor_options
- 1] = argv
[i
] + prev
;
2624 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2625 /* The +e options to the C++ front-end. */
2627 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2629 register char *p
= &argv
[i
][1];
2630 register int c
= *p
;
2635 if (p
[1] == 0 && i
+ 1 == argc
)
2636 fatal ("argument to `-b' is missing");
2638 spec_machine
= argv
[++i
];
2640 spec_machine
= p
+ 1;
2645 int *temp
= (int *) xmalloc (sizeof (int));
2647 if (p
[1] == 0 && i
+ 1 == argc
)
2648 fatal ("argument to `-B' is missing");
2653 add_prefix (&exec_prefixes
, value
, 1, 0, temp
);
2654 add_prefix (&startfile_prefixes
, value
, 1, 0, temp
);
2655 add_prefix (&include_prefixes
, concat (value
, "include"),
2658 /* As a kludge, if the arg is "[foo/]stageN/", just add
2659 "[foo/]include" to the include prefix. */
2661 int len
= strlen (value
);
2664 && (value
[len
- 8] == '/'
2665 || value
[len
- 8] == DIR_SEPARATOR
)))
2666 && strncmp (value
+ len
- 7, "stage", 5) == 0
2667 && isdigit (value
[len
- 2])
2668 && (value
[len
- 1] == '/'
2669 || value
[len
- 1] == DIR_SEPARATOR
))
2672 add_prefix (&include_prefixes
, "include", 1, 0, 0);
2675 char *string
= xmalloc (len
+ 1);
2676 strncpy (string
, value
, len
-7);
2677 strcat (string
, "include");
2678 add_prefix (&include_prefixes
, string
, 1, 0, 0);
2685 case 'v': /* Print our subcommands and print versions. */
2687 /* If they do anything other than exactly `-v', don't set
2688 verbose_flag; rather, continue on to give the error. */
2695 if (p
[1] == 0 && i
+ 1 == argc
)
2696 fatal ("argument to `-V' is missing");
2698 spec_version
= argv
[++i
];
2700 spec_version
= p
+ 1;
2701 compiler_version
= spec_version
;
2705 if (!strcmp (p
, "save-temps"))
2707 save_temps_flag
= 1;
2714 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2715 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2716 else if (WORD_SWITCH_TAKES_ARG (p
))
2717 i
+= WORD_SWITCH_TAKES_ARG (p
);
2724 /* Set up the search paths before we go looking for config files. */
2726 /* These come before the md prefixes so that we will find gcc's subcommands
2727 (such as cpp) rather than those of the host system. */
2728 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2729 as well as trying the machine and the version. */
2731 add_prefix (&exec_prefixes
, standard_exec_prefix
, 0, 2, NULL_PTR
);
2732 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, 0, 2, NULL_PTR
);
2735 add_prefix (&startfile_prefixes
, standard_exec_prefix
, 0, 1, NULL_PTR
);
2736 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, 0, 1, NULL_PTR
);
2738 tooldir_prefix
= concat3 (tooldir_base_prefix
, spec_machine
,
2741 /* If tooldir is relative, base it on exec_prefixes. A relative
2742 tooldir lets us move the installed tree as a unit.
2744 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2745 directories, so that we can search both the user specified directory
2746 and the standard place. */
2748 if (*tooldir_prefix
!= '/' && *tooldir_prefix
!= DIR_SEPARATOR
)
2750 if (gcc_exec_prefix
)
2752 char *gcc_exec_tooldir_prefix
2753 = concat6 (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
2754 spec_version
, dir_separator_str
, tooldir_prefix
);
2756 add_prefix (&exec_prefixes
,
2757 concat3 (gcc_exec_tooldir_prefix
, "bin",
2760 add_prefix (&startfile_prefixes
,
2761 concat3 (gcc_exec_tooldir_prefix
, "lib",
2766 tooldir_prefix
= concat6 (standard_exec_prefix
, spec_machine
,
2767 dir_separator_str
, spec_version
,
2768 dir_separator_str
, tooldir_prefix
);
2771 add_prefix (&exec_prefixes
,
2772 concat3 (tooldir_prefix
, "bin", dir_separator_str
),
2774 add_prefix (&startfile_prefixes
,
2775 concat3 (tooldir_prefix
, "lib", dir_separator_str
),
2778 /* More prefixes are enabled in main, after we read the specs file
2779 and determine whether this is cross-compilation or not. */
2782 /* Then create the space for the vectors and scan again. */
2784 switches
= ((struct switchstr
*)
2785 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2786 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2789 last_language_n_infiles
= -1;
2791 /* This, time, copy the text of each switch and store a pointer
2792 to the copy in the vector of switches.
2793 Store all the infiles in their vector. */
2795 for (i
= 1; i
< argc
; i
++)
2797 /* Just skip the switches that were handled by the preceding loop. */
2798 if (!strcmp (argv
[i
], "-Xlinker"))
2800 else if (! strncmp (argv
[i
], "-Wl,", 4))
2802 else if (! strncmp (argv
[i
], "-Wa,", 4))
2804 else if (! strncmp (argv
[i
], "-Wp,", 4))
2806 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2808 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2810 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2812 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2814 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2816 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2818 /* Compensate for the +e options to the C++ front-end;
2819 they're there simply for cfront call-compatibility. We do
2820 some magic in default_compilers to pass them down properly.
2821 Note we deliberately start at the `+' here, to avoid passing
2822 -e0 or -e1 down into the linker. */
2823 switches
[n_switches
].part1
= &argv
[i
][0];
2824 switches
[n_switches
].args
= 0;
2825 switches
[n_switches
].live_cond
= 0;
2826 switches
[n_switches
].valid
= 0;
2829 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2831 register char *p
= &argv
[i
][1];
2832 register int c
= *p
;
2834 if (c
== 'B' || c
== 'b' || c
== 'V')
2836 /* Skip a separate arg, if any. */
2843 if (p
[1] == 0 && i
+ 1 == argc
)
2844 fatal ("argument to `-x' is missing");
2846 spec_lang
= argv
[++i
];
2849 if (! strcmp (spec_lang
, "none"))
2850 /* Suppress the warning if -xnone comes after the last input file,
2851 because alternate command interfaces like g++ might find it
2852 useful to place -xnone after each input file. */
2855 last_language_n_infiles
= n_infiles
;
2858 switches
[n_switches
].part1
= p
;
2859 /* Deal with option arguments in separate argv elements. */
2860 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2861 || WORD_SWITCH_TAKES_ARG (p
))
2864 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2868 /* Count only the option arguments in separate argv elements. */
2869 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2871 if (i
+ n_args
>= argc
)
2872 fatal ("argument to `-%s' is missing", p
);
2873 switches
[n_switches
].args
2874 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2876 switches
[n_switches
].args
[j
++] = argv
[++i
];
2877 /* Null-terminate the vector. */
2878 switches
[n_switches
].args
[j
] = 0;
2880 else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L'))
2882 /* On some systems, ld cannot handle -o or -L without space.
2883 So split the -o or -L from its argument. */
2884 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2885 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2886 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2887 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2888 switches
[n_switches
].args
[1] = 0;
2891 switches
[n_switches
].args
= 0;
2893 switches
[n_switches
].live_cond
= 0;
2894 switches
[n_switches
].valid
= 0;
2895 /* This is always valid, since gcc.c itself understands it. */
2896 if (!strcmp (p
, "save-temps"))
2897 switches
[n_switches
].valid
= 1;
2902 if ((argv
[i
][0] != '-' || argv
[i
][1] != 'l')
2903 && strcmp (argv
[i
], "-")
2904 && access (argv
[i
], R_OK
) < 0)
2906 perror_with_name (argv
[i
]);
2911 infiles
[n_infiles
].language
= spec_lang
;
2912 infiles
[n_infiles
++].name
= argv
[i
];
2917 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
2918 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2920 switches
[n_switches
].part1
= 0;
2921 infiles
[n_infiles
].name
= 0;
2923 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2924 if (gcc_exec_prefix
)
2926 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2927 + strlen (spec_machine
) + 3);
2928 strcpy (temp
, gcc_exec_prefix
);
2929 strcat (temp
, spec_machine
);
2930 strcat (temp
, dir_separator_str
);
2931 strcat (temp
, spec_version
);
2932 strcat (temp
, dir_separator_str
);
2933 gcc_exec_prefix
= temp
;
2937 /* Process a spec string, accumulating and running commands. */
2939 /* These variables describe the input file name.
2940 input_file_number is the index on outfiles of this file,
2941 so that the output file name can be stored for later use by %o.
2942 input_basename is the start of the part of the input file
2943 sans all directory names, and basename_length is the number
2944 of characters starting there excluding the suffix .c or whatever. */
2946 static char *input_filename
;
2947 static int input_file_number
;
2948 static int input_filename_length
;
2949 static int basename_length
;
2950 static char *input_basename
;
2951 static char *input_suffix
;
2953 /* These are variables used within do_spec and do_spec_1. */
2955 /* Nonzero if an arg has been started and not yet terminated
2956 (with space, tab or newline). */
2957 static int arg_going
;
2959 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2960 is a temporary file name. */
2961 static int delete_this_arg
;
2963 /* Nonzero means %w has been seen; the next arg to be terminated
2964 is the output file name of this compilation. */
2965 static int this_is_output_file
;
2967 /* Nonzero means %s has been seen; the next arg to be terminated
2968 is the name of a library file and we should try the standard
2969 search dirs for it. */
2970 static int this_is_library_file
;
2972 /* Nonzero means that the input of this command is coming from a pipe. */
2973 static int input_from_pipe
;
2975 /* Process the spec SPEC and run the commands specified therein.
2976 Returns 0 if the spec is successfully processed; -1 if failed. */
2986 delete_this_arg
= 0;
2987 this_is_output_file
= 0;
2988 this_is_library_file
= 0;
2989 input_from_pipe
= 0;
2991 value
= do_spec_1 (spec
, 0, NULL_PTR
);
2993 /* Force out any unfinished command.
2994 If -pipe, this forces out the last command if it ended in `|'. */
2997 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3000 if (argbuf_index
> 0)
3007 /* Process the sub-spec SPEC as a portion of a larger spec.
3008 This is like processing a whole spec except that we do
3009 not initialize at the beginning and we do not supply a
3010 newline by default at the end.
3011 INSWITCH nonzero means don't process %-sequences in SPEC;
3012 in this case, % is treated as an ordinary character.
3013 This is used while substituting switches.
3014 INSWITCH nonzero also causes SPC not to terminate an argument.
3016 Value is zero unless a line was finished
3017 and the command on that line reported an error. */
3020 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3023 char *soft_matched_part
;
3025 register char *p
= spec
;
3032 /* If substituting a switch, treat all chars like letters.
3033 Otherwise, NL, SPC, TAB and % are special. */
3034 switch (inswitch
? 'a' : c
)
3037 /* End of line: finish any pending argument,
3038 then run the pending command if one has been started. */
3041 obstack_1grow (&obstack
, 0);
3042 string
= obstack_finish (&obstack
);
3043 if (this_is_library_file
)
3044 string
= find_file (string
);
3045 store_arg (string
, delete_this_arg
, this_is_output_file
);
3046 if (this_is_output_file
)
3047 outfiles
[input_file_number
] = string
;
3051 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3054 for (i
= 0; i
< n_switches
; i
++)
3055 if (!strcmp (switches
[i
].part1
, "pipe"))
3058 /* A `|' before the newline means use a pipe here,
3059 but only if -pipe was specified.
3060 Otherwise, execute now and don't pass the `|' as an arg. */
3063 input_from_pipe
= 1;
3064 switches
[i
].valid
= 1;
3071 if (argbuf_index
> 0)
3077 /* Reinitialize for a new command, and for a new argument. */
3080 delete_this_arg
= 0;
3081 this_is_output_file
= 0;
3082 this_is_library_file
= 0;
3083 input_from_pipe
= 0;
3087 /* End any pending argument. */
3090 obstack_1grow (&obstack
, 0);
3091 string
= obstack_finish (&obstack
);
3092 if (this_is_library_file
)
3093 string
= find_file (string
);
3094 store_arg (string
, delete_this_arg
, this_is_output_file
);
3095 if (this_is_output_file
)
3096 outfiles
[input_file_number
] = string
;
3100 obstack_1grow (&obstack
, c
);
3106 /* Space or tab ends an argument if one is pending. */
3109 obstack_1grow (&obstack
, 0);
3110 string
= obstack_finish (&obstack
);
3111 if (this_is_library_file
)
3112 string
= find_file (string
);
3113 store_arg (string
, delete_this_arg
, this_is_output_file
);
3114 if (this_is_output_file
)
3115 outfiles
[input_file_number
] = string
;
3117 /* Reinitialize for a new argument. */
3119 delete_this_arg
= 0;
3120 this_is_output_file
= 0;
3121 this_is_library_file
= 0;
3128 fatal ("Invalid specification! Bug in cc.");
3131 obstack_grow (&obstack
, input_basename
, basename_length
);
3136 delete_this_arg
= 2;
3139 /* Dump out the directories specified with LIBRARY_PATH,
3140 followed by the absolute directories
3141 that we search for startfiles. */
3144 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3146 char *buffer
= (char *) xmalloc (bufsize
);
3149 for (; pl
; pl
= pl
->next
)
3151 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3152 /* Used on systems which record the specified -L dirs
3153 and use them to search for dynamic linking. */
3154 /* Relative directories always come from -B,
3155 and it is better not to use them for searching
3156 at run time. In particular, stage1 loses */
3157 if (pl
->prefix
[0] != '/' && pl
->prefix
[0] != DIR_SEPARATOR
)
3160 /* Try subdirectory if there is one. */
3161 if (multilib_dir
!= NULL
)
3165 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3167 bufsize
= (strlen (pl
->prefix
)
3168 + strlen (machine_suffix
)) * 2 + 1;
3169 buffer
= (char *) xrealloc (buffer
, bufsize
);
3170 strcpy (buffer
, pl
->prefix
);
3171 strcat (buffer
, machine_suffix
);
3172 if (is_directory (buffer
, multilib_dir
, 1))
3174 do_spec_1 ("-L", 0, NULL_PTR
);
3175 #ifdef SPACE_AFTER_L_OPTION
3176 do_spec_1 (" ", 0, NULL_PTR
);
3178 do_spec_1 (buffer
, 1, NULL_PTR
);
3179 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3180 /* Make this a separate argument. */
3181 do_spec_1 (" ", 0, NULL_PTR
);
3184 if (!pl
->require_machine_suffix
)
3186 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3188 do_spec_1 ("-L", 0, NULL_PTR
);
3189 #ifdef SPACE_AFTER_L_OPTION
3190 do_spec_1 (" ", 0, NULL_PTR
);
3192 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3193 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3194 /* Make this a separate argument. */
3195 do_spec_1 (" ", 0, NULL_PTR
);
3201 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3203 do_spec_1 ("-L", 0, NULL_PTR
);
3204 #ifdef SPACE_AFTER_L_OPTION
3205 do_spec_1 (" ", 0, NULL_PTR
);
3207 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3208 /* Remove slash from machine_suffix. */
3209 if (strlen (machine_suffix
) >= bufsize
)
3210 bufsize
= strlen (machine_suffix
) * 2 + 1;
3211 buffer
= (char *) xrealloc (buffer
, bufsize
);
3212 strcpy (buffer
, machine_suffix
);
3213 idx
= strlen (buffer
);
3214 if (buffer
[idx
- 1] == '/'
3215 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3216 buffer
[idx
- 1] = 0;
3217 do_spec_1 (buffer
, 1, NULL_PTR
);
3218 /* Make this a separate argument. */
3219 do_spec_1 (" ", 0, NULL_PTR
);
3222 if (!pl
->require_machine_suffix
)
3224 if (is_directory (pl
->prefix
, "", 1))
3226 do_spec_1 ("-L", 0, NULL_PTR
);
3227 #ifdef SPACE_AFTER_L_OPTION
3228 do_spec_1 (" ", 0, NULL_PTR
);
3230 /* Remove slash from pl->prefix. */
3231 if (strlen (pl
->prefix
) >= bufsize
)
3232 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3233 buffer
= (char *) xrealloc (buffer
, bufsize
);
3234 strcpy (buffer
, pl
->prefix
);
3235 idx
= strlen (buffer
);
3236 if (buffer
[idx
- 1] == '/'
3237 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3238 buffer
[idx
- 1] = 0;
3239 do_spec_1 (buffer
, 1, NULL_PTR
);
3240 /* Make this a separate argument. */
3241 do_spec_1 (" ", 0, NULL_PTR
);
3250 /* {...:%efoo} means report an error with `foo' as error message
3251 and don't execute any more commands for this file. */
3255 while (*p
!= 0 && *p
!= '\n') p
++;
3256 buf
= (char *) alloca (p
- q
+ 1);
3257 strncpy (buf
, q
, p
- q
);
3267 if (save_temps_flag
)
3269 obstack_grow (&obstack
, input_basename
, basename_length
);
3270 delete_this_arg
= 0;
3274 #ifdef MKTEMP_EACH_FILE
3275 /* ??? This has a problem: the total number of
3276 values mktemp can return is limited.
3277 That matters for the names of object files.
3278 In 2.4, do something about that. */
3279 struct temp_name
*t
;
3281 while (*p
== '.' || isalpha (*p
))
3284 /* See if we already have an association of %g/%u/%U and
3286 for (t
= temp_names
; t
; t
= t
->next
)
3287 if (t
->length
== p
- suffix
3288 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3289 && t
->unique
== (c
!= 'g'))
3292 /* Make a new association if needed. %u requires one. */
3293 if (t
== 0 || c
== 'u')
3297 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3298 t
->next
= temp_names
;
3301 t
->length
= p
- suffix
;
3302 t
->suffix
= save_string (suffix
, p
- suffix
);
3303 t
->unique
= (c
!= 'g');
3304 choose_temp_base ();
3305 t
->filename
= temp_filename
;
3306 t
->filename_length
= temp_filename_length
;
3309 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3310 delete_this_arg
= 1;
3312 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3313 if (c
== 'u' || c
== 'U')
3319 sprintf (buff
, "%d", unique
);
3320 obstack_grow (&obstack
, buff
, strlen (buff
));
3323 delete_this_arg
= 1;
3329 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3335 struct prefix_list
*pl
= include_prefixes
.plist
;
3337 if (gcc_exec_prefix
)
3339 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3340 /* Make this a separate argument. */
3341 do_spec_1 (" ", 0, NULL_PTR
);
3342 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3343 do_spec_1 (" ", 0, NULL_PTR
);
3346 for (; pl
; pl
= pl
->next
)
3348 do_spec_1 ("-isystem", 1, NULL_PTR
);
3349 /* Make this a separate argument. */
3350 do_spec_1 (" ", 0, NULL_PTR
);
3351 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3352 do_spec_1 (" ", 0, NULL_PTR
);
3360 for (f
= 0; f
< n_infiles
; f
++)
3361 store_arg (outfiles
[f
], 0, 0);
3366 this_is_library_file
= 1;
3370 this_is_output_file
= 1;
3375 int index
= argbuf_index
;
3376 /* Handle the {...} following the %W. */
3379 p
= handle_braces (p
+ 1);
3382 /* If any args were output, mark the last one for deletion
3384 if (argbuf_index
!= index
)
3385 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3389 /* %x{OPTION} records OPTION for %X to output. */
3395 /* Skip past the option value and make a copy. */
3400 string
= save_string (p1
+ 1, p
- p1
- 2);
3402 /* See if we already recorded this option. */
3403 for (i
= 0; i
< n_linker_options
; i
++)
3404 if (! strcmp (string
, linker_options
[i
]))
3410 /* This option is new; add it. */
3412 if (!linker_options
)
3414 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3417 = (char **) xrealloc (linker_options
,
3418 n_linker_options
* sizeof (char **));
3420 linker_options
[n_linker_options
- 1] = string
;
3424 /* Dump out the options accumulated previously using %x,
3425 -Xlinker and -Wl,. */
3427 for (i
= 0; i
< n_linker_options
; i
++)
3429 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3430 /* Make each accumulated option a separate argument. */
3431 do_spec_1 (" ", 0, NULL_PTR
);
3435 /* Dump out the options accumulated previously using -Wa,. */
3437 for (i
= 0; i
< n_assembler_options
; i
++)
3439 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3440 /* Make each accumulated option a separate argument. */
3441 do_spec_1 (" ", 0, NULL_PTR
);
3445 /* Dump out the options accumulated previously using -Wp,. */
3447 for (i
= 0; i
< n_preprocessor_options
; i
++)
3449 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3450 /* Make each accumulated option a separate argument. */
3451 do_spec_1 (" ", 0, NULL_PTR
);
3455 /* Here are digits and numbers that just process
3456 a certain constant string as a spec. */
3459 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3465 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3471 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3477 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3483 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3489 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3495 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3501 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3507 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3514 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3518 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3522 if (! strncmp (y
, "-D", 2))
3523 /* Copy the whole option. */
3524 while (*y
&& *y
!= ' ' && *y
!= '\t')
3526 else if (*y
== ' ' || *y
== '\t')
3527 /* Copy whitespace to the result. */
3529 /* Don't copy other options. */
3536 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3544 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3548 /* Copy all of CPP_PREDEFINES into BUF,
3549 but put __ after every -D and at the end of each arg. */
3553 if (! strncmp (y
, "-D", 2))
3561 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3563 /* Stick __ at front of macro name. */
3566 /* Arrange to stick __ at the end as well. */
3570 /* Copy the macro name. */
3571 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3580 /* Copy the value given, if any. */
3581 while (*y
&& *y
!= ' ' && *y
!= '\t')
3584 else if (*y
== ' ' || *y
== '\t')
3585 /* Copy whitespace to the result. */
3587 /* Don't copy -A options */
3593 /* Copy all of CPP_PREDEFINES into BUF,
3594 but put __ after every -D. */
3598 if (! strncmp (y
, "-D", 2))
3603 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3605 /* Stick -D__ at front of macro name. */
3611 /* Copy the macro name. */
3612 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3615 /* Copy the value given, if any. */
3616 while (*y
&& *y
!= ' ' && *y
!= '\t')
3621 /* Do not copy this macro - we have just done it before */
3622 while (*y
&& *y
!= ' ' && *y
!= '\t')
3626 else if (*y
== ' ' || *y
== '\t')
3627 /* Copy whitespace to the result. */
3629 /* Don't copy -A options */
3635 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3639 if (! strncmp (y
, "-A", 2))
3640 /* Copy the whole option. */
3641 while (*y
&& *y
!= ' ' && *y
!= '\t')
3643 else if (*y
== ' ' || *y
== '\t')
3644 /* Copy whitespace to the result. */
3646 /* Don't copy other options. */
3653 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3660 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3665 /* Here we define characters other than letters and digits. */
3668 p
= handle_braces (p
);
3674 obstack_1grow (&obstack
, '%');
3678 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3679 do_spec_1 (" ", 0, NULL_PTR
);
3682 /* Process a string found as the value of a spec given by name.
3683 This feature allows individual machine descriptions
3684 to add and use their own specs.
3685 %[...] modifies -D options the way %P does;
3686 %(...) uses the spec unmodified. */
3691 struct spec_list
*sl
;
3694 /* The string after the S/P is the name of a spec that is to be
3696 while (*p
&& *p
!= ')' && *p
!= ']')
3699 /* See if it's in the list */
3700 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3701 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
3711 value
= do_spec_1 (name
, 0, NULL_PTR
);
3717 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3721 /* Copy all of NAME into BUF, but put __ after
3722 every -D and at the end of each arg, */
3725 if (! strncmp (y
, "-D", 2))
3733 else if (*y
== ' ' || *y
== 0)
3747 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3753 /* Discard the closing paren or bracket. */
3761 int c1
= *p
++; /* Select first or second version number. */
3762 char *v
= compiler_version
;
3764 /* If desired, advance to second version number. */
3767 /* Set P after the first period. */
3768 while (*v
!= 0 && *v
!= ' ' && *v
!= '.')
3773 /* Set Q at the next period or at the end. */
3775 while (*q
!= 0 && *q
!= ' ' && *q
!= '.')
3777 /* Empty string means zero. */
3783 /* Put that part into the command. */
3784 obstack_grow (&obstack
, v
, q
- v
);
3790 if (input_from_pipe
)
3791 do_spec_1 ("-", 0, NULL_PTR
);
3800 /* Backslash: treat next character as ordinary. */
3805 /* Ordinary character: put it into the current argument. */
3806 obstack_1grow (&obstack
, c
);
3810 return 0; /* End of string */
3813 /* Return 0 if we call do_spec_1 and that returns -1. */
3826 /* A `|' after the open-brace means,
3827 if the test fails, output a single minus sign rather than nothing.
3828 This is used in %{|!pipe:...}. */
3832 /* A `!' after the open-brace negates the condition:
3833 succeed if the specified switch is not present. */
3837 /* A `.' after the open-brace means test against the current suffix. */
3847 while (*p
!= ':' && *p
!= '}') p
++;
3850 register int count
= 1;
3868 int found
= (input_suffix
!= 0
3869 && strlen (input_suffix
) == p
- filter
3870 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3876 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3881 else if (p
[-1] == '*' && p
[0] == '}')
3883 /* Substitute all matching switches as separate args. */
3886 for (i
= 0; i
< n_switches
; i
++)
3887 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3888 && check_live_switch (i
, p
- filter
))
3893 /* Test for presence of the specified switch. */
3897 /* If name specified ends in *, as in {x*:...},
3898 check for %* and handle that case. */
3899 if (p
[-1] == '*' && !negate
)
3904 /* First see whether we have %*. */
3908 if (*r
== '%' && r
[1] == '*')
3912 /* If we do, handle that case. */
3915 /* Substitute all matching switches as separate args.
3916 But do this by substituting for %*
3917 in the text that follows the colon. */
3919 unsigned hard_match_len
= p
- filter
- 1;
3920 char *string
= save_string (p
+ 1, q
- p
- 2);
3922 for (i
= 0; i
< n_switches
; i
++)
3923 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3924 && check_live_switch (i
, -1))
3926 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
3927 /* Pass any arguments this switch has. */
3935 /* If name specified ends in *, as in {x*:...},
3936 check for presence of any switch name starting with x. */
3939 for (i
= 0; i
< n_switches
; i
++)
3941 unsigned hard_match_len
= p
- filter
- 1;
3943 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3944 && check_live_switch (i
, hard_match_len
))
3950 /* Otherwise, check for presence of exact name specified. */
3953 for (i
= 0; i
< n_switches
; i
++)
3955 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3956 && switches
[i
].part1
[p
- filter
] == 0
3957 && check_live_switch (i
, -1))
3965 /* If it is as desired (present for %{s...}, absent for %{-s...})
3966 then substitute either the switch or the specified
3967 conditional text. */
3968 if (present
!= negate
)
3976 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3982 /* Here if a %{|...} conditional fails: output a minus sign,
3983 which means "standard output" or "standard input". */
3984 do_spec_1 ("-", 0, NULL_PTR
);
3991 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3992 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3993 spec, or -1 if either exact match or %* is used.
3995 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3996 whose value does not begin with "no-" is obsoleted by the same value
3997 with the "no-", similarly for a switch with the "no-" prefix. */
4000 check_live_switch (switchnum
, prefix_length
)
4004 char *name
= switches
[switchnum
].part1
;
4007 /* In the common case of {<at-most-one-letter>*}, a negating
4008 switch would always match, so ignore that case. We will just
4009 send the conflicting switches to the compiler phase. */
4010 if (prefix_length
>= 0 && prefix_length
<= 1)
4013 /* If we already processed this switch and determined if it was
4014 live or not, return our past determination. */
4015 if (switches
[switchnum
].live_cond
!= 0)
4016 return switches
[switchnum
].live_cond
> 0;
4018 /* Now search for duplicate in a manner that depends on the name. */
4022 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4023 if (switches
[i
].part1
[0] == 'O')
4025 switches
[switchnum
].valid
= 1;
4026 switches
[switchnum
].live_cond
= -1;
4031 case 'W': case 'f': case 'm':
4032 if (! strncmp (name
+ 1, "no-", 3))
4034 /* We have Xno-YYY, search for XYYY. */
4035 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4036 if (switches
[i
].part1
[0] == name
[0]
4037 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4039 switches
[switchnum
].valid
= 1;
4040 switches
[switchnum
].live_cond
= -1;
4046 /* We have XYYY, search for Xno-YYY. */
4047 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4048 if (switches
[i
].part1
[0] == name
[0]
4049 && switches
[i
].part1
[1] == 'n'
4050 && switches
[i
].part1
[2] == 'o'
4051 && switches
[i
].part1
[3] == '-'
4052 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4054 switches
[switchnum
].valid
= 1;
4055 switches
[switchnum
].live_cond
= -1;
4062 /* Otherwise the switch is live. */
4063 switches
[switchnum
].live_cond
= 1;
4067 /* Pass a switch to the current accumulating command
4068 in the same form that we received it.
4069 SWITCHNUM identifies the switch; it is an index into
4070 the vector of switches gcc received, which is `switches'.
4071 This cannot fail since it never finishes a command line.
4073 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
4076 give_switch (switchnum
, omit_first_word
)
4078 int omit_first_word
;
4080 if (!omit_first_word
)
4082 do_spec_1 ("-", 0, NULL_PTR
);
4083 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4085 do_spec_1 (" ", 0, NULL_PTR
);
4086 if (switches
[switchnum
].args
!= 0)
4089 for (p
= switches
[switchnum
].args
; *p
; p
++)
4091 do_spec_1 (*p
, 1, NULL_PTR
);
4092 do_spec_1 (" ", 0, NULL_PTR
);
4095 switches
[switchnum
].valid
= 1;
4098 /* Search for a file named NAME trying various prefixes including the
4099 user's -B prefix and some standard ones.
4100 Return the absolute file name found. If nothing is found, return NAME. */
4108 /* Try multilib_dir if it is defined. */
4109 if (multilib_dir
!= NULL
)
4113 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4114 strcpy (try, multilib_dir
);
4115 strcat (try, dir_separator_str
);
4118 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4120 /* If we don't find it in the multi library dir, then fall
4121 through and look for it in the normal places. */
4122 if (newname
!= NULL
)
4126 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4127 return newname
? newname
: name
;
4130 /* Determine whether a directory exists. If LINKER, return 0 for
4131 certain fixed names not needed by the linker. If not LINKER, it is
4132 only important to return 0 if the host machine has a small ARG_MAX
4136 is_directory (path1
, path2
, linker
)
4141 int len1
= strlen (path1
);
4142 int len2
= strlen (path2
);
4143 char *path
= (char *) alloca (3 + len1
+ len2
);
4147 #ifndef SMALL_ARG_MAX
4152 /* Construct the path from the two parts. Ensure the string ends with "/.".
4153 The resulting path will be a directory even if the given path is a
4155 bcopy (path1
, path
, len1
);
4156 bcopy (path2
, path
+ len1
, len2
);
4157 cp
= path
+ len1
+ len2
;
4158 if (cp
[-1] != '/' && cp
[-1] != DIR_SEPARATOR
)
4159 *cp
++ = DIR_SEPARATOR
;
4163 /* Exclude directories that the linker is known to search. */
4166 && strcmp (path
, concat4 (dir_separator_str
, "lib",
4167 dir_separator_str
, ".")) == 0)
4169 && strcmp (path
, concat6 (dir_separator_str
, "usr",
4170 dir_separator_str
, "lib",
4171 dir_separator_str
, ".")) == 0)))
4174 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4177 /* On fatal signals, delete all the temporary files. */
4180 fatal_error (signum
)
4183 signal (signum
, SIG_DFL
);
4184 delete_failure_queue ();
4185 delete_temp_files ();
4186 /* Get the same signal again, this time not handled,
4187 so its normal effect occurs. */
4188 kill (getpid (), signum
);
4199 int linker_was_run
= 0;
4200 char *explicit_link_files
;
4204 p
= argv
[0] + strlen (argv
[0]);
4205 while (p
!= argv
[0] && p
[-1] != '/' && p
[-1] != DIR_SEPARATOR
) --p
;
4208 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4209 signal (SIGINT
, fatal_error
);
4211 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4212 signal (SIGHUP
, fatal_error
);
4214 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4215 signal (SIGTERM
, fatal_error
);
4217 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4218 signal (SIGPIPE
, fatal_error
);
4222 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4224 obstack_init (&obstack
);
4226 /* Set up to remember the pathname of gcc and any options
4227 needed for collect. We use argv[0] instead of programname because
4228 we need the complete pathname. */
4229 obstack_init (&collect_obstack
);
4230 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4231 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4232 putenv (obstack_finish (&collect_obstack
));
4234 /* Choose directory for temp files. */
4236 choose_temp_base ();
4238 /* Make a table of what switches there are (switches, n_switches).
4239 Make a table of specified input files (infiles, n_infiles).
4240 Decode switches that are handled locally. */
4242 process_command (argc
, argv
);
4244 /* Initialize the vector of specs to just the default.
4245 This means one element containing 0s, as a terminator. */
4247 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4248 bcopy ((char *) default_compilers
, (char *) compilers
,
4249 sizeof default_compilers
);
4250 n_compilers
= n_default_compilers
;
4252 /* Read specs from a file if there is one. */
4254 machine_suffix
= concat4 (spec_machine
, dir_separator_str
,
4255 spec_version
, dir_separator_str
);
4256 just_machine_suffix
= concat (spec_machine
, dir_separator_str
);
4258 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4259 /* Read the specs file unless it is a default one. */
4260 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4261 read_specs (specs_file
);
4263 /* If not cross-compiling, look for startfiles in the standard places. */
4264 /* The fact that these are done here, after reading the specs file,
4265 means that it cannot be found in these directories.
4266 But that's okay. It should never be there anyway. */
4269 #ifdef MD_EXEC_PREFIX
4270 add_prefix (&exec_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4271 add_prefix (&startfile_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4274 #ifdef MD_STARTFILE_PREFIX
4275 add_prefix (&startfile_prefixes
, md_startfile_prefix
, 0, 0, NULL_PTR
);
4278 #ifdef MD_STARTFILE_PREFIX_1
4279 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, 0, 0, NULL_PTR
);
4282 /* If standard_startfile_prefix is relative, base it on
4283 standard_exec_prefix. This lets us move the installed tree
4284 as a unit. If GCC_EXEC_PREFIX is defined, base
4285 standard_startfile_prefix on that as well. */
4286 if (*standard_startfile_prefix
== '/'
4287 || *standard_startfile_prefix
== DIR_SEPARATOR
)
4288 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, 0, 0,
4292 if (gcc_exec_prefix
)
4293 add_prefix (&startfile_prefixes
,
4294 concat (gcc_exec_prefix
, standard_startfile_prefix
),
4296 add_prefix (&startfile_prefixes
,
4297 concat3 (standard_exec_prefix
,
4299 standard_startfile_prefix
),
4303 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
, 0, 0,
4305 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
, 0, 0,
4307 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4308 add_prefix (&startfile_prefixes
, "./", 0, 1, NULL_PTR
);
4312 /* Now we have the specs.
4313 Set the `valid' bits for switches that match anything in any spec. */
4315 validate_all_switches ();
4317 /* Now that we have the switches and the specs, set
4318 the subdirectory based on the options. */
4319 set_multilib_dir ();
4321 /* Warn about any switches that no pass was interested in. */
4323 for (i
= 0; i
< n_switches
; i
++)
4324 if (! switches
[i
].valid
)
4325 error ("unrecognized option `-%s'", switches
[i
].part1
);
4327 /* Obey some of the options. */
4329 if (print_file_name
)
4331 printf ("%s\n", find_file (print_file_name
));
4335 if (print_prog_name
)
4337 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4338 printf ("%s\n", (newname
? newname
: print_prog_name
));
4342 if (print_multi_lib
)
4344 print_multilib_info ();
4348 if (print_multi_directory
)
4350 if (multilib_dir
== NULL
)
4353 printf ("%s\n", multilib_dir
);
4359 fprintf (stderr
, "gcc version %s\n", version_string
);
4365 fatal ("No input files");
4367 /* Make a place to record the compiler output file names
4368 that correspond to the input files. */
4370 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4371 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4373 /* Record which files were specified explicitly as link input. */
4375 explicit_link_files
= xmalloc (n_infiles
);
4376 bzero (explicit_link_files
, n_infiles
);
4378 for (i
= 0; i
< n_infiles
; i
++)
4380 register struct compiler
*cp
= 0;
4381 int this_file_error
= 0;
4383 /* Tell do_spec what to substitute for %i. */
4385 input_filename
= infiles
[i
].name
;
4386 input_filename_length
= strlen (input_filename
);
4387 input_file_number
= i
;
4389 /* Use the same thing in %o, unless cp->spec says otherwise. */
4391 outfiles
[i
] = input_filename
;
4393 /* Figure out which compiler from the file's suffix. */
4395 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4396 infiles
[i
].language
);
4400 /* Ok, we found an applicable compiler. Run its spec. */
4401 /* First say how much of input_filename to substitute for %b */
4405 input_basename
= input_filename
;
4406 for (p
= input_filename
; *p
; p
++)
4407 if (*p
== '/' || *p
== DIR_SEPARATOR
)
4408 input_basename
= p
+ 1;
4410 /* Find a suffix starting with the last period,
4411 and set basename_length to exclude that suffix. */
4412 basename_length
= strlen (input_basename
);
4413 p
= input_basename
+ basename_length
;
4414 while (p
!= input_basename
&& *p
!= '.') --p
;
4415 if (*p
== '.' && p
!= input_basename
)
4417 basename_length
= p
- input_basename
;
4418 input_suffix
= p
+ 1;
4424 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4426 len
+= strlen (cp
->spec
[j
]);
4428 p
= (char *) xmalloc (len
+ 1);
4431 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4434 strcpy (p
+ len
, cp
->spec
[j
]);
4435 len
+= strlen (cp
->spec
[j
]);
4438 value
= do_spec (p
);
4441 this_file_error
= 1;
4444 /* If this file's name does not contain a recognized suffix,
4445 record it as explicit linker input. */
4448 explicit_link_files
[i
] = 1;
4450 /* Clear the delete-on-failure queue, deleting the files in it
4451 if this compilation failed. */
4453 if (this_file_error
)
4455 delete_failure_queue ();
4458 /* If this compilation succeeded, don't delete those files later. */
4459 clear_failure_queue ();
4462 /* Run ld to link all the compiler output files. */
4464 if (error_count
== 0)
4466 int tmp
= execution_count
;
4470 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4472 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
4473 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
4475 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4477 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4478 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4481 for (i
= 0; i
< n_switches
; i
++)
4485 obstack_grow (&collect_obstack
, " ", 1);
4488 obstack_grow (&collect_obstack
, "-", 1);
4489 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4490 strlen (switches
[i
].part1
));
4492 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4494 obstack_grow (&collect_obstack
, " ", 1);
4495 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4498 obstack_grow (&collect_obstack
, "\0", 1);
4499 putenv (obstack_finish (&collect_obstack
));
4501 value
= do_spec (link_command_spec
);
4504 linker_was_run
= (tmp
!= execution_count
);
4507 /* Warn if a -B option was specified but the prefix was never used. */
4508 unused_prefix_warnings (&exec_prefixes
);
4509 unused_prefix_warnings (&startfile_prefixes
);
4511 /* If options said don't run linker,
4512 complain about input files to be given to the linker. */
4514 if (! linker_was_run
&& error_count
== 0)
4515 for (i
= 0; i
< n_infiles
; i
++)
4516 if (explicit_link_files
[i
])
4517 error ("%s: linker input file unused since linking not done",
4520 /* Delete some or all of the temporary files we made. */
4523 delete_failure_queue ();
4524 delete_temp_files ();
4526 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4531 /* Find the proper compilation spec for the file name NAME,
4532 whose length is LENGTH. LANGUAGE is the specified language,
4533 or 0 if none specified. */
4535 static struct compiler
*
4536 lookup_compiler (name
, length
, language
)
4541 struct compiler
*cp
;
4543 /* Look for the language, if one is spec'd. */
4546 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4550 if (cp
->suffix
[0] == '@'
4551 && !strcmp (cp
->suffix
+ 1, language
))
4555 error ("language %s not recognized", language
);
4558 /* Look for a suffix. */
4559 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4561 if (/* The suffix `-' matches only the file name `-'. */
4562 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4564 (strlen (cp
->suffix
) < length
4565 /* See if the suffix matches the end of NAME. */
4567 && (!strcmp (cp
->suffix
,
4568 name
+ length
- strlen (cp
->suffix
))
4569 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4570 && !strcasecmp (cp
->suffix
,
4571 name
+ length
- strlen (cp
->suffix
)))))
4573 && !strcmp (cp
->suffix
,
4574 name
+ length
- strlen (cp
->suffix
))))
4577 if (cp
->spec
[0][0] == '@')
4579 struct compiler
*new;
4580 /* An alias entry maps a suffix to a language.
4581 Search for the language; pass 0 for NAME and LENGTH
4582 to avoid infinite recursion if language not found.
4583 Construct the new compiler spec. */
4584 language
= cp
->spec
[0] + 1;
4585 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4586 new->suffix
= cp
->suffix
;
4587 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4588 (char *) new->spec
, sizeof new->spec
);
4591 /* A non-alias entry: return it. */
4603 register char *value
= (char *) malloc (size
);
4605 fatal ("virtual memory exhausted");
4610 xrealloc (ptr
, size
)
4614 register char *value
= (char *) realloc (ptr
, size
);
4616 fatal ("virtual memory exhausted");
4620 /* Return a newly-allocated string whose contents concatenate those of s1, s2 */
4626 int len1
= strlen (s1
);
4627 int len2
= strlen (s2
);
4628 char *result
= xmalloc (len1
+ len2
+ 1);
4630 strcpy (result
, s1
);
4631 strcpy (result
+ len1
, s2
);
4632 *(result
+ len1
+ len2
) = 0;
4638 concat3 (s1
, s2
, s3
)
4641 return concat (concat (s1
, s2
), s3
);
4645 concat4 (s1
, s2
, s3
, s4
)
4646 char *s1
, *s2
, *s3
, *s4
;
4648 return concat (concat (s1
, s2
), concat (s3
, s4
));
4652 concat6 (s1
, s2
, s3
, s4
, s5
, s6
)
4653 char *s1
, *s2
, *s3
, *s4
, *s5
, *s6
;
4655 return concat3 (concat (s1
, s2
), concat (s3
, s4
), concat (s5
, s6
));
4659 save_string (s
, len
)
4663 register char *result
= xmalloc (len
+ 1);
4665 bcopy (s
, result
, len
);
4671 pfatal_with_name (name
)
4676 if (errno
< sys_nerr
)
4677 s
= concat ("%s: ", sys_errlist
[errno
]);
4679 s
= "cannot open %s";
4684 perror_with_name (name
)
4689 if (errno
< sys_nerr
)
4690 s
= concat ("%s: ", sys_errlist
[errno
]);
4692 s
= "cannot open %s";
4702 if (errno
< sys_nerr
)
4703 s
= concat ("installation problem, cannot exec %s: ", sys_errlist
[errno
]);
4705 s
= "installation problem, cannot exec %s";
4709 /* More 'friendly' abort that prints the line and file.
4710 config.h can #define abort fancy_abort if you like that sort of thing. */
4715 fatal ("Internal gcc abort.");
4720 /* Output an error message and exit */
4723 fatal
VPROTO((char *format
, ...))
4730 VA_START (ap
, format
);
4733 format
= va_arg (ap
, char*);
4736 fprintf (stderr
, "%s: ", programname
);
4737 vfprintf (stderr
, format
, ap
);
4739 fprintf (stderr
, "\n");
4740 delete_temp_files ();
4745 error
VPROTO((char *format
, ...))
4752 VA_START (ap
, format
);
4755 format
= va_arg (ap
, char*);
4758 fprintf (stderr
, "%s: ", programname
);
4759 vfprintf (stderr
, format
, ap
);
4762 fprintf (stderr
, "\n");
4765 #else /* not HAVE_VPRINTF */
4768 fatal (msg
, arg1
, arg2
)
4769 char *msg
, *arg1
, *arg2
;
4771 error (msg
, arg1
, arg2
);
4772 delete_temp_files ();
4777 error (msg
, arg1
, arg2
)
4778 char *msg
, *arg1
, *arg2
;
4780 fprintf (stderr
, "%s: ", programname
);
4781 fprintf (stderr
, msg
, arg1
, arg2
);
4782 fprintf (stderr
, "\n");
4785 #endif /* not HAVE_VPRINTF */
4789 validate_all_switches ()
4791 struct compiler
*comp
;
4794 struct spec_list
*spec
;
4796 for (comp
= compilers
; comp
->spec
[0]; comp
++)
4799 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
4803 if (c
== '%' && *p
== '{')
4804 /* We have a switch spec. */
4805 validate_switches (p
+ 1);
4809 /* look through the linked list of extra specs read from the specs file */
4810 for (spec
= specs
; spec
; spec
= spec
->next
)
4814 if (c
== '%' && *p
== '{')
4815 /* We have a switch spec. */
4816 validate_switches (p
+ 1);
4819 p
= link_command_spec
;
4821 if (c
== '%' && *p
== '{')
4822 /* We have a switch spec. */
4823 validate_switches (p
+ 1);
4825 /* Now notice switches mentioned in the machine-specific specs. */
4829 if (c
== '%' && *p
== '{')
4830 /* We have a switch spec. */
4831 validate_switches (p
+ 1);
4835 if (c
== '%' && *p
== '{')
4836 /* We have a switch spec. */
4837 validate_switches (p
+ 1);
4841 if (c
== '%' && *p
== '{')
4842 /* We have a switch spec. */
4843 validate_switches (p
+ 1);
4845 p
= signed_char_spec
;
4847 if (c
== '%' && *p
== '{')
4848 /* We have a switch spec. */
4849 validate_switches (p
+ 1);
4853 if (c
== '%' && *p
== '{')
4854 /* We have a switch spec. */
4855 validate_switches (p
+ 1);
4859 if (c
== '%' && *p
== '{')
4860 /* We have a switch spec. */
4861 validate_switches (p
+ 1);
4865 if (c
== '%' && *p
== '{')
4866 /* We have a switch spec. */
4867 validate_switches (p
+ 1);
4871 if (c
== '%' && *p
== '{')
4872 /* We have a switch spec. */
4873 validate_switches (p
+ 1);
4877 if (c
== '%' && *p
== '{')
4878 /* We have a switch spec. */
4879 validate_switches (p
+ 1);
4882 /* Look at the switch-name that comes after START
4883 and mark as valid all supplied switches that match it. */
4886 validate_switches (start
)
4889 register char *p
= start
;
4904 while (*p
!= ':' && *p
!= '}') p
++;
4908 else if (p
[-1] == '*')
4910 /* Mark all matching switches as valid. */
4912 for (i
= 0; i
< n_switches
; i
++)
4913 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
4914 switches
[i
].valid
= 1;
4918 /* Mark an exact matching switch as valid. */
4919 for (i
= 0; i
< n_switches
; i
++)
4921 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4922 && switches
[i
].part1
[p
- filter
] == 0)
4923 switches
[i
].valid
= 1;
4928 /* Check whether a particular argument was used. */
4937 for (i
= 0; i
< n_switches
; i
++)
4938 if (! strncmp (switches
[i
].part1
, p
, len
)
4939 && strlen (switches
[i
].part1
) == len
)
4944 /* Work out the subdirectory to use based on the
4945 options. The format of multilib_select is a list of elements.
4946 Each element is a subdirectory name followed by a list of options
4947 followed by a semicolon. gcc will consider each line in turn. If
4948 none of the options beginning with an exclamation point are
4949 present, and all of the other options are present, that
4950 subdirectory will be used. */
4955 char *p
= multilib_select
;
4957 char *this_path
, *this_arg
;
4962 /* Ignore newlines. */
4969 /* Get the initial path. */
4977 this_path_len
= p
- this_path
;
4979 /* Check the arguments. */
4994 while (*p
!= ' ' && *p
!= ';')
5001 if (*this_arg
== '!')
5002 failed
= used_arg (this_arg
+ 1, p
- (this_arg
+ 1));
5004 failed
= ! used_arg (this_arg
, p
- this_arg
);
5012 if (this_path_len
!= 1
5013 || this_path
[0] != '.')
5015 multilib_dir
= xmalloc (this_path_len
+ 1);
5016 strncpy (multilib_dir
, this_path
, this_path_len
);
5017 multilib_dir
[this_path_len
] = '\0';
5026 /* Print out the multiple library subdirectory selection
5027 information. This prints out a series of lines. Each line looks
5028 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5029 required. Only the desired options are printed out, the negative
5030 matches. The options are print without a leading dash. There are
5031 no spaces to make it easy to use the information in the shell.
5032 Each subdirectory is printed only once. This assumes the ordering
5033 generated by the genmultilib script. */
5036 print_multilib_info ()
5038 char *p
= multilib_select
;
5039 char *last_path
, *this_path
;
5040 int last_path_len
, skip
, use_arg
;
5044 /* Ignore newlines. */
5051 /* Get the initial path. */
5060 /* If this is a duplicate, skip it. */
5061 skip
= (p
- this_path
== last_path_len
5062 && ! strncmp (last_path
, this_path
, last_path_len
));
5064 last_path
= this_path
;
5065 last_path_len
= p
- this_path
;
5071 for (p1
= last_path
; p1
< p
; p1
++)
5090 use_arg
= *p
!= '!';
5095 while (*p
!= ' ' && *p
!= ';')