1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92, 93, 94, 1995 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. */
103 /* Define O_RDONLY if the system hasn't defined it for us. */
109 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
110 #define GENERIC_PTR void *
112 #define GENERIC_PTR char *
117 #define NULL_PTR ((GENERIC_PTR)0)
124 /* On MSDOS, write temp files in current dir
125 because there's no place else we can expect to use. */
132 /* Test if something is a normal file. */
134 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
137 /* Test if something is a directory. */
139 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
142 /* By default there is no special suffix for executables. */
143 #ifndef EXECUTABLE_SUFFIX
144 #define EXECUTABLE_SUFFIX ""
147 /* By default, colon separates directories in a path. */
148 #ifndef PATH_SEPARATOR
149 #define PATH_SEPARATOR ':'
152 #ifndef DIR_SEPARATOR
153 #define DIR_SEPARATOR '/'
156 static char dir_separator_str[] = {DIR_SEPARATOR, 0};
158 #define obstack_chunk_alloc xmalloc
159 #define obstack_chunk_free free
162 extern char *getenv ();
169 #if defined(bsd4_4) || defined(__NetBSD__)
170 extern const char *const sys_errlist[];
172 extern char *sys_errlist[];
175 extern int execv (), execvp ();
177 /* If a stage of compilation returns an exit status >= 1,
178 compilation of that file ceases. */
180 #define MIN_FATAL_STATUS 1
182 /* Flag saying to print the full filename of this file
183 as found through our usual search mechanism. */
185 static char *print_file_name = NULL;
187 /* As print_file_name, but search for executable file. */
189 static char *print_prog_name = NULL;
191 /* Flag saying to print the relative path we'd use to
192 find libgcc.a given the current compiler flags. */
194 static int print_multi_directory;
196 /* Flag saying to print the list of subdirectories and
197 compiler flags used to select them in a standard form. */
199 static int print_multi_lib;
201 /* Flag indicating whether we should print the command and arguments */
203 static int verbose_flag;
205 /* Nonzero means write "temp" files in source directory
206 and use the source file's name in them, and don't delete them. */
208 static int save_temps_flag;
210 /* The compiler version. */
212 static char *compiler_version;
214 /* The target version specified with -V */
216 static char *spec_version = DEFAULT_TARGET_VERSION;
218 /* The target machine specified with -b. */
220 static char *spec_machine = DEFAULT_TARGET_MACHINE;
222 /* Nonzero if cross-compiling.
223 When -b is used, the value comes from the `specs' file. */
226 static int cross_compile = 1;
228 static int cross_compile = 0;
231 /* The number of errors that have occurred; the link phase will not be
232 run if this is non-zero. */
233 static int error_count = 0;
235 /* This is the obstack which we use to allocate many strings. */
237 static struct obstack obstack;
239 /* This is the obstack to build an environment variable to pass to
240 collect2 that describes all of the relevant switches of what to
241 pass the compiler in building the list of pointers to constructors
244 static struct obstack collect_obstack;
246 extern char *version_string;
248 /* Forward declaration for prototypes. */
251 static void set_spec PROTO((char *, char *));
252 static struct compiler *lookup_compiler PROTO((char *, int, char *));
253 static char *find_a_file PROTO((struct path_prefix *, char *, int));
254 static void add_prefix PROTO((struct path_prefix *, char *, int, int, int *));
255 static char *skip_whitespace PROTO((char *));
256 static void record_temp_file PROTO((char *, int, int));
257 static void delete_if_ordinary PROTO((char *));
258 static void delete_temp_files PROTO((void));
259 static void delete_failure_queue PROTO((void));
260 static void clear_failure_queue PROTO((void));
261 static char *choose_temp_base_try PROTO((char *, char *));
262 static void choose_temp_base PROTO((void));
263 static int check_live_switch PROTO((int, int));
264 static char *handle_braces PROTO((char *));
265 static char *save_string PROTO((char *, int));
266 static char *concat PROTO((char *, char *));
267 static char *concat3 PROTO((char *, char *, char *));
268 static char *concat4 PROTO((char *, char *, char *, char *));
269 static char *concat6 PROTO((char *, char *, char *, char *, char *, \
271 static int do_spec PROTO((char *));
272 static int do_spec_1 PROTO((char *, int, char *));
273 static char *find_file PROTO((char *));
274 static int is_directory PROTO((char *, char *, int));
275 static void validate_switches PROTO((char *));
276 static void validate_all_switches PROTO((void));
277 static void give_switch PROTO((int, int));
278 static int used_arg PROTO((char *, int));
279 static void set_multilib_dir PROTO((void));
280 static void print_multilib_info PROTO((void));
281 static void pfatal_with_name PROTO((char *));
282 static void perror_with_name PROTO((char *));
283 static void perror_exec PROTO((char *));
285 static void fatal PVPROTO((char *, ...));
286 static void error PVPROTO((char *, ...));
288 /* We must not provide any prototype here, even if ANSI C. */
289 static void fatal PROTO(());
290 static void error PROTO(());
297 /* Specs are strings containing lines, each of which (if not blank)
298 is made up of a program name, and arguments separated by spaces.
299 The program name must be exact and start from root, since no path
300 is searched and it is unreliable to depend on the current working directory.
301 Redirection of input or output is not supported; the subprograms must
302 accept filenames saying what files to read and write.
304 In addition, the specs can contain %-sequences to substitute variable text
305 or for conditional text. Here is a table of all defined %-sequences.
306 Note that spaces are not generated automatically around the results of
307 expanding these sequences; therefore, you can concatenate them together
308 or with constant text in a single argument.
310 %% substitute one % into the program name or argument.
311 %i substitute the name of the input file being processed.
312 %b substitute the basename of the input file being processed.
313 This is the substring up to (and not including) the last period
314 and not including the directory.
315 %g substitute the temporary-file-name-base. This is a string chosen
316 once per compilation. Different temporary file names are made by
317 concatenation of constant strings on the end, as in `%g.s'.
318 %g also has the same effect of %d.
319 %u like %g, but make the temporary file name unique.
320 %U returns the last file name generated with %u.
321 %d marks the argument containing or following the %d as a
322 temporary file name, so that that file will be deleted if CC exits
323 successfully. Unlike %g, this contributes no text to the argument.
324 %w marks the argument containing or following the %w as the
325 "output file" of this compilation. This puts the argument
326 into the sequence of arguments that %o will substitute later.
328 like %{...} but mark last argument supplied within
329 as a file to be deleted on failure.
330 %o substitutes the names of all the output files, with spaces
331 automatically placed around them. You should write spaces
332 around the %o as well or the results are undefined.
333 %o is for use in the specs for running the linker.
334 Input files whose names have no recognized suffix are not compiled
335 at all, but they are included among the output files, so they will
337 %p substitutes the standard macro predefinitions for the
338 current target machine. Use this when running cpp.
339 %P like %p, but puts `__' before and after the name of each macro.
340 (Except macros that already have __.)
342 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
343 %s current argument is the name of a library or startup file of some sort.
344 Search for that file in a standard list of directories
345 and substitute the full name found.
346 %eSTR Print STR as an error message. STR is terminated by a newline.
347 Use this when inconsistent options are detected.
348 %x{OPTION} Accumulate an option for %X.
349 %X Output the accumulated linker options specified by compilations.
350 %Y Output the accumulated assembler options specified by compilations.
351 %Z Output the accumulated preprocessor options specified by compilations.
352 %v1 Substitute the major version number of GCC.
353 (For version 2.5.n, this is 2.)
354 %v2 Substitute the minor version number of GCC.
355 (For version 2.5.n, this is 5.)
356 %a process ASM_SPEC as a spec.
357 This allows config.h to specify part of the spec for running as.
358 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
359 used here. This can be used to run a post-processor after the
360 assembler has done it's job.
361 %D Dump out a -L option for each directory in startfile_prefixes.
362 If multilib_dir is set, extra entries are generated with it affixed.
363 %l process LINK_SPEC as a spec.
364 %L process LIB_SPEC as a spec.
365 %G process LIBGCC_SPEC as a spec.
366 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
367 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
368 %c process SIGNED_CHAR_SPEC as a spec.
369 %C process CPP_SPEC as a spec. A capital C is actually used here.
370 %1 process CC1_SPEC as a spec.
371 %2 process CC1PLUS_SPEC as a spec.
372 %| output "-" if the input for the current command is coming from a pipe.
373 %* substitute the variable part of a matched option. (See below.)
374 Note that each comma in the substituted string is replaced by
376 %{S} substitutes the -S switch, if that switch was given to CC.
377 If that switch was not specified, this substitutes nothing.
378 Here S is a metasyntactic variable.
379 %{S*} substitutes all the switches specified to CC whose names start
380 with -S. This is used for -o, -D, -I, etc; switches that take
381 arguments. CC considers `-o foo' as being one switch whose
382 name starts with `o'. %{o*} would substitute this text,
383 including the space; thus, two arguments would be generated.
384 %{S*:X} substitutes X if one or more switches whose names start with -S are
385 specified to CC. Note that the tail part of the -S option
386 (i.e. the part matched by the `*') will be substituted for each
387 occurrence of %* within X.
388 %{S:X} substitutes X, but only if the -S switch was given to CC.
389 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
390 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
391 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
392 %{.S:X} substitutes X, but only if processing a file with suffix S.
393 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
394 %(Spec) processes a specification defined in a specs file as *Spec:
395 %[Spec] as above, but put __ around -D arguments
397 The conditional text X in a %{S:X} or %{!S:X} construct may contain
398 other nested % constructs or spaces, or even newlines. They are
399 processed as usual, as described above.
401 The -O, -f, -m, and -W switches are handled specifically in these
402 constructs. If another value of -O or the negated form of a -f, -m, or
403 -W switch is found later in the command line, the earlier switch
404 value is ignored, except with {S*} where S is just one letter; this
405 passes all matching options.
407 The character | is used to indicate that a command should be piped to
408 the following command, but only if -pipe is specified.
410 Note that it is built into CC which switches take arguments and which
411 do not. You might think it would be useful to generalize this to
412 allow each compiler's spec to say which switches take arguments. But
413 this cannot be done in a consistent fashion. CC cannot even decide
414 which input files have been specified without knowing which switches
415 take arguments, and it must know which input files to compile in order
416 to tell which compilers to run.
418 CC also knows implicitly that arguments starting in `-l' are to be
419 treated as compiler output files, and passed to the linker in their
420 proper position among the other output files. */
422 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
424 /* config.h can define ASM_SPEC to provide extra args to the assembler
425 or extra switch-translations. */
430 /* config.h can define ASM_FINAL_SPEC to run a post processor after
431 the assembler has run. */
432 #ifndef ASM_FINAL_SPEC
433 #define ASM_FINAL_SPEC ""
436 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
437 or extra switch-translations. */
442 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
443 or extra switch-translations. */
448 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
449 or extra switch-translations. */
451 #define CC1PLUS_SPEC ""
454 /* config.h can define LINK_SPEC to provide extra args to the linker
455 or extra switch-translations. */
460 /* config.h can define LIB_SPEC to override the default libraries. */
462 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
465 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
468 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
469 /* Have gcc do the search for libgcc.a. */
470 #define LIBGCC_SPEC "%{!shared:libgcc.a%s}"
472 #define LIBGCC_SPEC "%{!shared:-lgcc}"
476 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
477 #ifndef STARTFILE_SPEC
478 #define STARTFILE_SPEC \
479 "%{!shared:%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}}"
482 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
483 Make the string nonempty to require spaces there. */
484 #ifndef SWITCHES_NEED_SPACES
485 #define SWITCHES_NEED_SPACES ""
488 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
490 #define ENDFILE_SPEC ""
493 /* This spec is used for telling cpp whether char is signed or not. */
494 #ifndef SIGNED_CHAR_SPEC
495 /* Use #if rather than ?:
496 because MIPS C compiler rejects like ?: in initializers. */
497 #if DEFAULT_SIGNED_CHAR
498 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
500 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
504 /* MULTILIB_SELECT comes from multilib.h. It gives a
505 string interpreted by set_multilib_dir to select a library
506 subdirectory based on the compiler options. */
507 #ifndef MULTILIB_SELECT
508 #define MULTILIB_SELECT ". ;"
511 static char *cpp_spec = CPP_SPEC;
512 static char *cpp_predefines = CPP_PREDEFINES;
513 static char *cc1_spec = CC1_SPEC;
514 static char *cc1plus_spec = CC1PLUS_SPEC;
515 static char *signed_char_spec = SIGNED_CHAR_SPEC;
516 static char *asm_spec = ASM_SPEC;
517 static char *asm_final_spec = ASM_FINAL_SPEC;
518 static char *link_spec = LINK_SPEC;
519 static char *lib_spec = LIB_SPEC;
520 static char *libgcc_spec = LIBGCC_SPEC;
521 static char *endfile_spec = ENDFILE_SPEC;
522 static char *startfile_spec = STARTFILE_SPEC;
523 static char *switches_need_spaces = SWITCHES_NEED_SPACES;
524 static char *multilib_select = MULTILIB_SELECT;
526 /* This defines which switch letters take arguments. */
528 #ifndef SWITCH_TAKES_ARG
529 #define SWITCH_TAKES_ARG(CHAR) \
530 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
531 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
532 || (CHAR) == 'I' || (CHAR) == 'm' \
533 || (CHAR) == 'L' || (CHAR) == 'A')
536 /* This defines which multi-letter switches take arguments. */
538 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
539 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
540 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
541 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
542 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
543 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
544 || !strcmp (STR, "isystem"))
546 #ifndef WORD_SWITCH_TAKES_ARG
547 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
550 /* Record the mapping from file suffixes for compilation specs. */
554 char *suffix; /* Use this compiler for input files
555 whose names end in this suffix. */
557 char *spec[4]; /* To use this compiler, concatenate these
558 specs and pass to do_spec. */
561 /* Pointer to a vector of `struct compiler' that gives the spec for
562 compiling a file, based on its suffix.
563 A file that does not end in any of these suffixes will be passed
564 unchanged to the loader and nothing else will be done to it.
566 An entry containing two 0s is used to terminate the vector.
568 If multiple entries match a file, the last matching one is used. */
570 static struct compiler *compilers;
572 /* Number of entries in `compilers', not counting the null terminator. */
574 static int n_compilers;
576 /* The default list of file name suffixes and their compilation specs. */
578 static struct compiler default_compilers[] =
582 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
583 %{C:%{!E:%eGNU C does not support -C without using -E}}\
584 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
585 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
586 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
587 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
588 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
589 %{traditional-cpp:-traditional}\
590 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
591 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
592 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
593 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
594 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
595 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
597 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
598 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
599 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
600 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
601 %{!pipe:%g.s} %A\n }}}}"},
603 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
604 %{C:%{!E:%eGNU C does not support -C without using -E}}\
605 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
606 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
607 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
608 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
609 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
610 %{traditional-cpp:-traditional}\
611 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
613 %{!E:%e-E required when input is from standard input}"},
614 {".m", "@objective-c"},
616 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
617 %{C:%{!E:%eGNU C does not support -C without using -E}}\
618 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
619 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
620 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
621 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
622 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
623 %{traditional-cpp:-traditional}\
624 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
625 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
626 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
627 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
628 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
629 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
630 -lang-objc %{gen-decls} \
632 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
633 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
634 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
635 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
636 %{!pipe:%g.s} %A\n }}}}"},
639 "%{!E:%eCompilation of header file requested} \
640 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
641 %{C:%{!E:%eGNU C does not support -C without using -E}}\
642 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
643 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
644 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
645 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
646 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
647 %{traditional-cpp:-traditional}\
648 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
653 "cpp -lang-chill %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
654 %{C:%{!E:%eGNU CHILL does not support -C without using -E}}\
655 -undef -D__GNUCHILL__=%v1 -D__GNUC_MINOR__=%v2\
656 %c %{O*:-D__OPTIMIZE__} %{traditional} %{ftraditional:-traditional}\
657 %{traditional-cpp:-traditional} %{!undef:%{!ansi:%p} %P} %{trigraphs}\
658 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
659 %i %{!E:%g.i}%{E:%W{o*}} \n",
660 "%{!E:cc1chill %g.i %1 \
661 %{!Q:-quiet} -dumpbase %b.ch %{d*} %{m*} %{a}\
662 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{itu} \
663 %{v:-version} %{pg:-p} %{p} %{f*} %{I*} \
665 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
666 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
667 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y %{keep-local-as-symbols:-L} \
668 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
669 %{!pipe:%g.s} %A\n }}"},
676 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
677 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
678 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
679 -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
680 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
681 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
682 %{traditional-cpp:-traditional} %{trigraphs}\
683 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
684 %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
685 "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\
686 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
687 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
688 %{traditional} %{v:-version} %{pg:-p} %{p}\
689 %{f*} %{+e*} %{aux-info*}\
690 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
691 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\
692 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
693 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
694 %{!pipe:%g.s} %A\n }}}}"},
695 {".i", "@cpp-output"},
697 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
698 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
699 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
701 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
702 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
703 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
704 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
705 %{!pipe:%g.s} %A\n }}}}"},
706 {".ii", "@c++-cpp-output"},
708 "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
709 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
710 %{traditional} %{v:-version} %{pg:-p} %{p}\
711 %{f*} %{+e*} %{aux-info*}\
712 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
713 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
714 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
715 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
716 %{!pipe:%g.s} %A\n }}}}"},
717 {".s", "@assembler"},
719 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
720 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
722 {".S", "@assembler-with-cpp"},
723 {"@assembler-with-cpp",
724 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
725 %{C:%{!E:%eGNU C does not support -C without using -E}}\
726 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
727 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
728 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
729 %{traditional-cpp:-traditional}\
730 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
731 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
732 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
733 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
734 %{!pipe:%g.s} %A\n }}}}"},
739 "%{!M:%{!MM:%{!E:gnat1 %{k8:-gnatk8} %{w:-gnatws} %{!Q:-quiet}\
740 -dumpbase %b.ada %{g*} %{O*} %{p} %{pg:-p} %{f*}\
742 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
743 %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
744 %{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
745 %{c:%W{o*}%{!o*:-o %w%b.o}}\
746 %{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n}}}}}} "},
747 /* Mark end of table */
751 /* Number of elements in default_compilers, not counting the terminator. */
753 static int n_default_compilers
754 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
756 /* Here is the spec for running the linker, after compiling all files. */
758 /* -u* was put back because both BSD and SysV seem to support it. */
759 /* %{static:} simply prevents an error message if the target machine
760 doesn't handle -static. */
761 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
762 scripts which exist in user specified directories, or in standard
764 #ifdef LINK_LIBGCC_SPECIAL
765 /* Don't generate -L options. */
766 static char *link_command_spec = "\
768 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
769 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
770 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
771 %{L*} %{T*} %o %{!nostdlib:%G %L %G %{!A:%E}}\n }}}}}}";
774 static char *link_command_spec = "\
776 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
777 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
778 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
779 %{L*} %D %{T*} %o %{!nostdlib:%G %L %G %{!A:%E}}\n }}}}}}";
782 /* A vector of options to give to the linker.
783 These options are accumulated by %x,
784 and substituted into the linker command with %X. */
785 static int n_linker_options;
786 static char **linker_options;
788 /* A vector of options to give to the assembler.
789 These options are accumulated by -Wa,
790 and substituted into the assembler command with %Y. */
791 static int n_assembler_options;
792 static char **assembler_options;
794 /* A vector of options to give to the preprocessor.
795 These options are accumulated by -Wp,
796 and substituted into the preprocessor command with %Z. */
797 static int n_preprocessor_options;
798 static char **preprocessor_options;
800 /* Define how to map long options into short ones. */
802 /* This structure describes one mapping. */
805 /* The long option's name. */
807 /* The equivalent short option. */
809 /* Argument info. A string of flag chars; NULL equals no options.
810 a => argument required.
811 o => argument optional.
812 j => join argument to equivalent, making one word.
813 * => require other text after NAME as an argument. */
817 /* This is the table of mappings. Mappings are tried sequentially
818 for each option encountered; the first one that matches, wins. */
820 struct option_map option_map[] =
822 {"--all-warnings", "-Wall", 0},
823 {"--ansi", "-ansi", 0},
824 {"--assemble", "-S", 0},
825 {"--assert", "-A", "a"},
826 {"--comments", "-C", 0},
827 {"--compile", "-c", 0},
828 {"--debug", "-g", "oj"},
829 {"--define-macro", "-D", "a"},
830 {"--dependencies", "-M", 0},
831 {"--dump", "-d", "a"},
832 {"--dumpbase", "-dumpbase", "a"},
833 {"--entry", "-e", 0},
834 {"--extra-warnings", "-W", 0},
835 {"--for-assembler", "-Wa", "a"},
836 {"--for-linker", "-Xlinker", "a"},
837 {"--force-link", "-u", "a"},
838 {"--imacros", "-imacros", "a"},
839 {"--include", "-include", "a"},
840 {"--include-barrier", "-I-", 0},
841 {"--include-directory", "-I", "a"},
842 {"--include-directory-after", "-idirafter", "a"},
843 {"--include-prefix", "-iprefix", "a"},
844 {"--include-with-prefix", "-iwithprefix", "a"},
845 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
846 {"--include-with-prefix-after", "-iwithprefix", "a"},
847 {"--language", "-x", "a"},
848 {"--library-directory", "-L", "a"},
849 {"--machine", "-m", "aj"},
850 {"--machine-", "-m", "*j"},
851 {"--no-line-commands", "-P", 0},
852 {"--no-precompiled-includes", "-noprecomp", 0},
853 {"--no-standard-includes", "-nostdinc", 0},
854 {"--no-standard-libraries", "-nostdlib", 0},
855 {"--no-warnings", "-w", 0},
856 {"--optimize", "-O", "oj"},
857 {"--output", "-o", "a"},
858 {"--pedantic", "-pedantic", 0},
859 {"--pedantic-errors", "-pedantic-errors", 0},
860 {"--pipe", "-pipe", 0},
861 {"--prefix", "-B", "a"},
862 {"--preprocess", "-E", 0},
863 {"--print-file-name", "-print-file-name=", "aj"},
864 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
865 {"--print-missing-file-dependencies", "-MG", 0},
866 {"--print-multi-lib", "-print-multi-lib", 0},
867 {"--print-multi-directory", "-print-multi-directory", 0},
868 {"--print-prog-name", "-print-prog-name=", "aj"},
869 {"--profile", "-p", 0},
870 {"--profile-blocks", "-a", 0},
871 {"--quiet", "-q", 0},
872 {"--save-temps", "-save-temps", 0},
873 {"--shared", "-shared", 0},
874 {"--silent", "-q", 0},
875 {"--static", "-static", 0},
876 {"--symbolic", "-symbolic", 0},
877 {"--target", "-b", "a"},
878 {"--trace-includes", "-H", 0},
879 {"--traditional", "-traditional", 0},
880 {"--traditional-cpp", "-traditional-cpp", 0},
881 {"--trigraphs", "-trigraphs", 0},
882 {"--undefine-macro", "-U", "a"},
883 {"--use-version", "-V", "a"},
884 {"--user-dependencies", "-MM", 0},
885 {"--verbose", "-v", 0},
886 {"--version", "-dumpversion", 0},
887 {"--warn-", "-W", "*j"},
888 {"--write-dependencies", "-MD", 0},
889 {"--write-user-dependencies", "-MMD", 0},
893 /* Translate the options described by *ARGCP and *ARGVP.
894 Make a new vector and store it back in *ARGVP,
895 and store its length in *ARGVC. */
898 translate_options (argcp, argvp)
904 char **argv = *argvp;
905 char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
909 newv[newindex++] = argv[i++];
913 /* Translate -- options. */
914 if (argv[i][0] == '-' && argv[i][1] == '-')
916 /* Find a mapping that applies to this option. */
917 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
919 int optlen = strlen (option_map[j].name);
920 int arglen = strlen (argv[i]);
921 int complen = arglen > optlen ? optlen : arglen;
922 char *arginfo = option_map[j].arg_info;
927 if (!strncmp (argv[i], option_map[j].name, complen))
934 k < sizeof (option_map) / sizeof (option_map[0]);
936 if (strlen (option_map[k].name) >= arglen
937 && !strncmp (argv[i], option_map[k].name, arglen))
939 error ("Ambiguous abbreviation %s", argv[i]);
943 if (k != sizeof (option_map) / sizeof (option_map[0]))
949 /* If the option has an argument, accept that. */
950 if (argv[i][optlen] == '=')
951 arg = argv[i] + optlen + 1;
953 /* If this mapping requires extra text at end of name,
954 accept that as "argument". */
955 else if (index (arginfo, '*') != 0)
956 arg = argv[i] + optlen;
958 /* Otherwise, extra text at end means mismatch.
959 Try other mappings. */
964 else if (index (arginfo, '*') != 0)
966 error ("Incomplete `%s' option", option_map[j].name);
970 /* Handle arguments. */
971 if (index (arginfo, 'a') != 0)
977 error ("Missing argument to `%s' option",
985 else if (index (arginfo, '*') != 0)
987 else if (index (arginfo, 'o') == 0)
990 error ("Extraneous argument to `%s' option",
995 /* Store the translation as one argv elt or as two. */
996 if (arg != 0 && index (arginfo, 'j') != 0)
997 newv[newindex++] = concat (option_map[j].equivalent, arg);
1000 newv[newindex++] = option_map[j].equivalent;
1001 newv[newindex++] = arg;
1004 newv[newindex++] = option_map[j].equivalent;
1012 /* Handle old-fashioned options--just copy them through,
1013 with their arguments. */
1014 else if (argv[i][0] == '-')
1016 char *p = argv[i] + 1;
1020 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1021 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1022 else if (WORD_SWITCH_TAKES_ARG (p))
1023 nskip += WORD_SWITCH_TAKES_ARG (p);
1024 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1027 else if (! strcmp (p, "Xlinker"))
1030 /* Watch out for an option at the end of the command line that
1031 is missing arguments, and avoid skipping past the end of the
1033 if (nskip + i > argc)
1038 newv[newindex++] = argv[i++];
1043 /* Ordinary operands, or +e options. */
1044 newv[newindex++] = argv[i++];
1053 /* Read compilation specs from a file named FILENAME,
1054 replacing the default ones.
1056 A suffix which starts with `*' is a definition for
1057 one of the machine-specific sub-specs. The "suffix" should be
1058 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1059 The corresponding spec is stored in asm_spec, etc.,
1060 rather than in the `compilers' vector.
1062 Anything invalid in the file is a fatal error. */
1065 read_specs (filename)
1069 struct stat statbuf;
1074 fprintf (stderr, "Reading specs from %s\n", filename);
1076 /* Open and stat the file. */
1077 desc = open (filename, O_RDONLY, 0);
1079 pfatal_with_name (filename);
1080 if (stat (filename, &statbuf) < 0)
1081 pfatal_with_name (filename);
1083 /* Read contents of file into BUFFER. */
1084 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1085 read (desc, buffer, (unsigned) statbuf.st_size);
1086 buffer[statbuf.st_size] = 0;
1089 /* Scan BUFFER for specs, putting them in the vector. */
1095 char *in, *out, *p1, *p2;
1097 /* Advance P in BUFFER to the next nonblank nocomment line. */
1098 p = skip_whitespace (p);
1102 /* Find the colon that should end the suffix. */
1104 while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
1105 /* The colon shouldn't be missing. */
1107 fatal ("specs file malformed after %d characters", p1 - buffer);
1108 /* Skip back over trailing whitespace. */
1110 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
1111 /* Copy the suffix to a string. */
1112 suffix = save_string (p, p2 - p);
1113 /* Find the next line. */
1114 p = skip_whitespace (p1 + 1);
1116 fatal ("specs file malformed after %d characters", p - buffer);
1118 /* Find next blank line. */
1119 while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
1120 /* Specs end at the blank line and do not include the newline. */
1121 spec = save_string (p, p1 - p);
1124 /* Delete backslash-newline sequences from the spec. */
1129 if (in[0] == '\\' && in[1] == '\n')
1131 else if (in[0] == '#')
1133 while (*in && *in != '\n') in++;
1140 if (suffix[0] == '*')
1142 if (! strcmp (suffix, "*link_command"))
1143 link_command_spec = spec;
1145 set_spec (suffix + 1, spec);
1149 /* Add this pair to the vector. */
1151 = ((struct compiler *)
1152 xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
1153 compilers[n_compilers].suffix = suffix;
1154 bzero ((char *) compilers[n_compilers].spec,
1155 sizeof compilers[n_compilers].spec);
1156 compilers[n_compilers].spec[0] = spec;
1158 bzero ((char *) &compilers[n_compilers],
1159 sizeof compilers[n_compilers]);
1163 link_command_spec = spec;
1166 if (link_command_spec == 0)
1167 fatal ("spec file has no spec for linking");
1176 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1177 be considered whitespace. */
1178 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1180 else if (*p == '\n' || *p == ' ' || *p == '\t')
1184 while (*p != '\n') p++;
1194 /* Structure to keep track of the specs that have been defined so far. These
1195 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1199 char *name; /* Name of the spec. */
1200 char *spec; /* The spec itself. */
1201 struct spec_list *next; /* Next spec in linked list. */
1204 /* List of specs that have been defined so far. */
1206 static struct spec_list *specs = (struct spec_list *) 0;
1208 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1209 removed; If the spec starts with a + then SPEC is added to the end of the
1213 set_spec (name, spec)
1217 struct spec_list *sl;
1220 /* See if the spec already exists */
1221 for (sl = specs; sl; sl = sl->next)
1222 if (strcmp (sl->name, name) == 0)
1227 /* Not found - make it */
1228 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1229 sl->name = save_string (name, strlen (name));
1230 sl->spec = save_string ("", 0);
1235 old_spec = sl->spec;
1236 if (name && spec[0] == '+' && isspace (spec[1]))
1237 sl->spec = concat (old_spec, spec + 1);
1239 sl->spec = save_string (spec, strlen (spec));
1241 if (! strcmp (name, "asm"))
1242 asm_spec = sl->spec;
1243 else if (! strcmp (name, "asm_final"))
1244 asm_final_spec = sl->spec;
1245 else if (! strcmp (name, "cc1"))
1246 cc1_spec = sl->spec;
1247 else if (! strcmp (name, "cc1plus"))
1248 cc1plus_spec = sl->spec;
1249 else if (! strcmp (name, "cpp"))
1250 cpp_spec = sl->spec;
1251 else if (! strcmp (name, "endfile"))
1252 endfile_spec = sl->spec;
1253 else if (! strcmp (name, "lib"))
1254 lib_spec = sl->spec;
1255 else if (! strcmp (name, "libgcc"))
1256 libgcc_spec = sl->spec;
1257 else if (! strcmp (name, "link"))
1258 link_spec = sl->spec;
1259 else if (! strcmp (name, "predefines"))
1260 cpp_predefines = sl->spec;
1261 else if (! strcmp (name, "signed_char"))
1262 signed_char_spec = sl->spec;
1263 else if (! strcmp (name, "startfile"))
1264 startfile_spec = sl->spec;
1265 else if (! strcmp (name, "switches_need_spaces"))
1266 switches_need_spaces = sl->spec;
1267 else if (! strcmp (name, "cross_compile"))
1268 cross_compile = atoi (sl->spec);
1269 else if (! strcmp (name, "multilib"))
1270 multilib_select = sl->spec;
1271 /* Free the old spec */
1276 /* Accumulate a command (program name and args), and run it. */
1278 /* Vector of pointers to arguments in the current line of specifications. */
1280 static char **argbuf;
1282 /* Number of elements allocated in argbuf. */
1284 static int argbuf_length;
1286 /* Number of elements in argbuf currently in use (containing args). */
1288 static int argbuf_index;
1290 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1291 temp file. Used only if MKTEMP_EACH_FILE. */
1293 static struct temp_name {
1294 char *suffix; /* suffix associated with the code. */
1295 int length; /* strlen (suffix). */
1296 int unique; /* Indicates whether %g or %u/%U was used. */
1297 char *filename; /* associated filename. */
1298 int filename_length; /* strlen (filename). */
1299 struct temp_name *next;
1302 /* Number of commands executed so far. */
1304 static int execution_count;
1306 /* Number of commands that exited with a signal. */
1308 static int signal_count;
1310 /* Name with which this program was invoked. */
1312 static char *programname;
1314 /* Structures to keep track of prefixes to try when looking for files. */
1318 char *prefix; /* String to prepend to the path. */
1319 struct prefix_list *next; /* Next in linked list. */
1320 int require_machine_suffix; /* Don't use without machine_suffix. */
1321 /* 2 means try both machine_suffix and just_machine_suffix. */
1322 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1327 struct prefix_list *plist; /* List of prefixes to try */
1328 int max_len; /* Max length of a prefix in PLIST */
1329 char *name; /* Name of this list (used in config stuff) */
1332 /* List of prefixes to try when looking for executables. */
1334 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1336 /* List of prefixes to try when looking for startup (crt0) files. */
1338 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1340 /* List of prefixes to try when looking for include files. */
1342 static struct path_prefix include_prefixes = { 0, 0, "include" };
1344 /* Suffix to attach to directories searched for commands.
1345 This looks like `MACHINE/VERSION/'. */
1347 static char *machine_suffix = 0;
1349 /* Suffix to attach to directories searched for commands.
1350 This is just `MACHINE/'. */
1352 static char *just_machine_suffix = 0;
1354 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1356 static char *gcc_exec_prefix;
1358 /* Default prefixes to attach to command names. */
1360 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1361 #undef MD_EXEC_PREFIX
1362 #undef MD_STARTFILE_PREFIX
1363 #undef MD_STARTFILE_PREFIX_1
1366 #ifndef STANDARD_EXEC_PREFIX
1367 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1368 #endif /* !defined STANDARD_EXEC_PREFIX */
1370 static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
1371 static char *standard_exec_prefix_1 = "/usr/lib/gcc/";
1372 #ifdef MD_EXEC_PREFIX
1373 static char *md_exec_prefix = MD_EXEC_PREFIX;
1376 #ifndef STANDARD_STARTFILE_PREFIX
1377 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1378 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1380 #ifdef MD_STARTFILE_PREFIX
1381 static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1383 #ifdef MD_STARTFILE_PREFIX_1
1384 static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1386 static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1387 static char *standard_startfile_prefix_1 = "/lib/";
1388 static char *standard_startfile_prefix_2 = "/usr/lib/";
1390 #ifndef TOOLDIR_BASE_PREFIX
1391 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1393 static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1394 static char *tooldir_prefix;
1396 /* Subdirectory to use for locating libraries. Set by
1397 set_multilib_dir based on the compilation options. */
1399 static char *multilib_dir;
1401 /* Clear out the vector of arguments (after a command is executed). */
1409 /* Add one argument to the vector at the end.
1410 This is done when a space is seen or at the end of the line.
1411 If DELETE_ALWAYS is nonzero, the arg is a filename
1412 and the file should be deleted eventually.
1413 If DELETE_FAILURE is nonzero, the arg is a filename
1414 and the file should be deleted if this compilation fails. */
1417 store_arg (arg, delete_always, delete_failure)
1419 int delete_always, delete_failure;
1421 if (argbuf_index + 1 == argbuf_length)
1423 argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
1426 argbuf[argbuf_index++] = arg;
1427 argbuf[argbuf_index] = 0;
1429 if (delete_always || delete_failure)
1430 record_temp_file (arg, delete_always, delete_failure);
1433 /* Record the names of temporary files we tell compilers to write,
1434 and delete them at the end of the run. */
1436 /* This is the common prefix we use to make temp file names.
1437 It is chosen once for each run of this program.
1438 It is substituted into a spec by %g.
1439 Thus, all temp file names contain this prefix.
1440 In practice, all temp file names start with this prefix.
1442 This prefix comes from the envvar TMPDIR if it is defined;
1443 otherwise, from the P_tmpdir macro if that is defined;
1444 otherwise, in /usr/tmp or /tmp. */
1446 static char *temp_filename;
1448 /* Length of the prefix. */
1450 static int temp_filename_length;
1452 /* Define the list of temporary files to delete. */
1457 struct temp_file *next;
1460 /* Queue of files to delete on success or failure of compilation. */
1461 static struct temp_file *always_delete_queue;
1462 /* Queue of files to delete on failure of compilation. */
1463 static struct temp_file *failure_delete_queue;
1465 /* Record FILENAME as a file to be deleted automatically.
1466 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1467 otherwise delete it in any case.
1468 FAIL_DELETE nonzero means delete it if a compilation step fails;
1469 otherwise delete it in any case. */
1472 record_temp_file (filename, always_delete, fail_delete)
1477 register char *name;
1478 name = xmalloc (strlen (filename) + 1);
1479 strcpy (name, filename);
1483 register struct temp_file *temp;
1484 for (temp = always_delete_queue; temp; temp = temp->next)
1485 if (! strcmp (name, temp->name))
1487 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1488 temp->next = always_delete_queue;
1490 always_delete_queue = temp;
1496 register struct temp_file *temp;
1497 for (temp = failure_delete_queue; temp; temp = temp->next)
1498 if (! strcmp (name, temp->name))
1500 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
1501 temp->next = failure_delete_queue;
1503 failure_delete_queue = temp;
1508 /* Delete all the temporary files whose names we previously recorded. */
1511 delete_if_ordinary (name)
1518 printf ("Delete %s? (y or n) ", name);
1522 while ((c = getchar ()) != '\n' && c != EOF) ;
1523 if (i == 'y' || i == 'Y')
1525 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
1526 if (unlink (name) < 0)
1528 perror_with_name (name);
1532 delete_temp_files ()
1534 register struct temp_file *temp;
1536 for (temp = always_delete_queue; temp; temp = temp->next)
1537 delete_if_ordinary (temp->name);
1538 always_delete_queue = 0;
1541 /* Delete all the files to be deleted on error. */
1544 delete_failure_queue ()
1546 register struct temp_file *temp;
1548 for (temp = failure_delete_queue; temp; temp = temp->next)
1549 delete_if_ordinary (temp->name);
1553 clear_failure_queue ()
1555 failure_delete_queue = 0;
1558 /* Compute a string to use as the base of all temporary file names.
1559 It is substituted for %g. */
1562 choose_temp_base_try (try, base)
1569 else if (try == (char *)0)
1571 else if (access (try, R_OK | W_OK) != 0)
1584 base = choose_temp_base_try (getenv ("TMPDIR"), base);
1585 base = choose_temp_base_try (getenv ("TMP"), base);
1586 base = choose_temp_base_try (getenv ("TEMP"), base);
1589 base = choose_temp_base_try (P_tmpdir, base);
1592 base = choose_temp_base_try (concat4 (dir_separator_str, "usr",
1593 dir_separator_str, "tmp"),
1595 base = choose_temp_base_try (concat (dir_separator_str, "tmp"), base);
1597 /* If all else fails, use the current directory! */
1598 if (base == (char *)0) base = concat(".", dir_separator_str);
1600 len = strlen (base);
1601 temp_filename = xmalloc (len + strlen (concat (dir_separator_str,
1603 strcpy (temp_filename, base);
1604 if (len > 0 && temp_filename[len-1] != '/'
1605 && temp_filename[len-1] != DIR_SEPARATOR)
1606 temp_filename[len++] = DIR_SEPARATOR;
1607 strcpy (temp_filename + len, "ccXXXXXX");
1609 mktemp (temp_filename);
1610 temp_filename_length = strlen (temp_filename);
1611 if (temp_filename_length == 0)
1616 /* Routine to add variables to the environment. We do this to pass
1617 the pathname of the gcc driver, and the directories search to the
1618 collect2 program, which is being run as ld. This way, we can be
1619 sure of executing the right compiler when collect2 wants to build
1620 constructors and destructors. Since the environment variables we
1621 use come from an obstack, we don't have to worry about allocating
1630 #ifndef VMS /* nor about VMS */
1632 extern char **environ;
1633 char **old_environ = environ;
1637 int str_len = strlen (str);
1641 while ((ch = *p++) != '\0' && ch != '=')
1647 /* Search for replacing an existing environment variable, and
1648 count the number of total environment variables. */
1649 for (envp = old_environ; *envp; envp++)
1652 if (!strncmp (str, *envp, name_len))
1659 /* Add a new environment variable */
1660 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
1662 bcopy ((char *) old_environ, (char *) (environ + 1),
1663 sizeof (char *) * (num_envs+1));
1668 #endif /* HAVE_PUTENV */
1671 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1674 putenv_from_prefixes (paths, env_var)
1675 struct path_prefix *paths;
1678 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
1680 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
1681 int first_time = TRUE;
1682 struct prefix_list *pprefix;
1684 obstack_grow (&collect_obstack, env_var, strlen (env_var));
1686 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
1688 int len = strlen (pprefix->prefix);
1691 && is_directory (pprefix->prefix, machine_suffix, 0))
1694 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1697 obstack_grow (&collect_obstack, pprefix->prefix, len);
1698 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
1701 if (just_machine_suffix
1702 && pprefix->require_machine_suffix == 2
1703 && is_directory (pprefix->prefix, just_machine_suffix, 0))
1706 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1709 obstack_grow (&collect_obstack, pprefix->prefix, len);
1710 obstack_grow (&collect_obstack, just_machine_suffix,
1714 if (!pprefix->require_machine_suffix)
1717 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
1720 obstack_grow (&collect_obstack, pprefix->prefix, len);
1723 obstack_1grow (&collect_obstack, '\0');
1724 putenv (obstack_finish (&collect_obstack));
1728 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1729 access to check permissions.
1730 Return 0 if not found, otherwise return its name, allocated with malloc. */
1733 find_a_file (pprefix, name, mode)
1734 struct path_prefix *pprefix;
1739 char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
1740 struct prefix_list *pl;
1741 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
1744 len += strlen (machine_suffix);
1746 temp = xmalloc (len);
1748 /* Determine the filename to execute (special case for absolute paths). */
1750 if (*name == '/' || *name == DIR_SEPARATOR)
1752 if (access (name, mode))
1754 strcpy (temp, name);
1759 for (pl = pprefix->plist; pl; pl = pl->next)
1763 /* Some systems have a suffix for executable files.
1764 So try appending that first. */
1765 if (file_suffix[0] != 0)
1767 strcpy (temp, pl->prefix);
1768 strcat (temp, machine_suffix);
1769 strcat (temp, name);
1770 strcat (temp, file_suffix);
1771 if (access (temp, mode) == 0)
1773 if (pl->used_flag_ptr != 0)
1774 *pl->used_flag_ptr = 1;
1779 /* Now try just the name. */
1780 strcpy (temp, pl->prefix);
1781 strcat (temp, 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 are tried with just the machine type,
1792 not the version. This is used for finding as, ld, etc. */
1793 if (just_machine_suffix && pl->require_machine_suffix == 2)
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, just_machine_suffix);
1801 strcat (temp, name);
1802 strcat (temp, file_suffix);
1803 if (access (temp, mode) == 0)
1805 if (pl->used_flag_ptr != 0)
1806 *pl->used_flag_ptr = 1;
1811 strcpy (temp, pl->prefix);
1812 strcat (temp, just_machine_suffix);
1813 strcat (temp, name);
1814 if (access (temp, mode) == 0)
1816 if (pl->used_flag_ptr != 0)
1817 *pl->used_flag_ptr = 1;
1822 /* Certain prefixes can't be used without the machine suffix
1823 when the machine or version is explicitly specified. */
1824 if (!pl->require_machine_suffix)
1826 /* Some systems have a suffix for executable files.
1827 So try appending that first. */
1828 if (file_suffix[0] != 0)
1830 strcpy (temp, pl->prefix);
1831 strcat (temp, name);
1832 strcat (temp, file_suffix);
1833 if (access (temp, mode) == 0)
1835 if (pl->used_flag_ptr != 0)
1836 *pl->used_flag_ptr = 1;
1841 strcpy (temp, pl->prefix);
1842 strcat (temp, name);
1843 if (access (temp, mode) == 0)
1845 if (pl->used_flag_ptr != 0)
1846 *pl->used_flag_ptr = 1;
1856 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1857 at the start of the list, otherwise it goes at the end.
1859 If WARN is nonzero, we will warn if no file is found
1860 through this prefix. WARN should point to an int
1861 which will be set to 1 if this entry is used.
1863 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1864 the complete value of machine_suffix.
1865 2 means try both machine_suffix and just_machine_suffix. */
1868 add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
1869 struct path_prefix *pprefix;
1872 int require_machine_suffix;
1875 struct prefix_list *pl, **prev;
1878 if (!first && pprefix->plist)
1880 for (pl = pprefix->plist; pl->next; pl = pl->next)
1885 prev = &pprefix->plist;
1887 /* Keep track of the longest prefix */
1889 len = strlen (prefix);
1890 if (len > pprefix->max_len)
1891 pprefix->max_len = len;
1893 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
1894 pl->prefix = save_string (prefix, len);
1895 pl->require_machine_suffix = require_machine_suffix;
1896 pl->used_flag_ptr = warn;
1903 pl->next = (struct prefix_list *) 0;
1907 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1910 unused_prefix_warnings (pprefix)
1911 struct path_prefix *pprefix;
1913 struct prefix_list *pl = pprefix->plist;
1917 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
1919 error ("file path prefix `%s' never used",
1921 /* Prevent duplicate warnings. */
1922 *pl->used_flag_ptr = 1;
1928 /* Get rid of all prefixes built up so far in *PLISTP. */
1931 free_path_prefix (pprefix)
1932 struct path_prefix *pprefix;
1934 struct prefix_list *pl = pprefix->plist;
1935 struct prefix_list *temp;
1941 free (temp->prefix);
1942 free ((char *) temp);
1944 pprefix->plist = (struct prefix_list *) 0;
1947 /* stdin file number. */
1948 #define STDIN_FILE_NO 0
1950 /* stdout file number. */
1951 #define STDOUT_FILE_NO 1
1953 /* value of `pipe': port index for reading. */
1956 /* value of `pipe': port index for writing. */
1957 #define WRITE_PORT 1
1959 /* Pipe waiting from last process, to be used as input for the next one.
1960 Value is STDIN_FILE_NO if no pipe is waiting
1961 (i.e. the next command is the first of a group). */
1963 static int last_pipe_input;
1965 /* Fork one piped subcommand. FUNC is the system call to use
1966 (either execv or execvp). ARGV is the arg vector to use.
1967 NOT_LAST is nonzero if this is not the last subcommand
1968 (i.e. its output should be piped to the next one.) */
1972 #include <process.h>
1974 pexecute (search_flag, program, argv, not_last)
1981 int i = (search_flag ? spawnv : spawnvp) (1, program, argv);
1985 int i, el = search_flag ? 0 : 4;
1987 scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6 + el);
1988 rf = scmd + strlen(program) + 2 + el;
1989 sprintf (scmd, "%s%s @%s.gp", program,
1990 (search_flag ? "" : ".exe"), temp_filename);
1991 argfile = fopen (rf, "w");
1993 pfatal_with_name (rf);
1995 for (i=1; argv[i]; i++)
1998 for (cp = argv[i]; *cp; cp++)
2000 if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
2001 fputc ('\\', argfile);
2002 fputc (*cp, argfile);
2004 fputc ('\n', argfile);
2015 perror_exec (program);
2016 return MIN_FATAL_STATUS << 8;
2023 #if !defined(__MSDOS__) && !defined(OS2) && !defined(WINNT)
2026 pexecute (search_flag, program, argv, not_last)
2032 int (*func)() = (search_flag ? execv : execvp);
2035 int input_desc = last_pipe_input;
2036 int output_desc = STDOUT_FILE_NO;
2037 int retries, sleep_interval;
2039 /* If this isn't the last process, make a pipe for its output,
2040 and record it as waiting to be the input to the next process. */
2044 if (pipe (pdes) < 0)
2045 pfatal_with_name ("pipe");
2046 output_desc = pdes[WRITE_PORT];
2047 last_pipe_input = pdes[READ_PORT];
2050 last_pipe_input = STDIN_FILE_NO;
2052 /* Fork a subprocess; wait and retry if it fails. */
2054 for (retries = 0; retries < 4; retries++)
2059 sleep (sleep_interval);
2060 sleep_interval *= 2;
2067 pfatal_with_name ("fork");
2069 pfatal_with_name ("vfork");
2075 /* Move the input and output pipes into place, if nec. */
2076 if (input_desc != STDIN_FILE_NO)
2078 close (STDIN_FILE_NO);
2082 if (output_desc != STDOUT_FILE_NO)
2084 close (STDOUT_FILE_NO);
2086 close (output_desc);
2089 /* Close the parent's descs that aren't wanted here. */
2090 if (last_pipe_input != STDIN_FILE_NO)
2091 close (last_pipe_input);
2093 /* Exec the program. */
2094 (*func) (program, argv);
2095 perror_exec (program);
2101 /* In the parent, after forking.
2102 Close the descriptors that we made for this child. */
2103 if (input_desc != STDIN_FILE_NO)
2105 if (output_desc != STDOUT_FILE_NO)
2106 close (output_desc);
2108 /* Return child's process number. */
2113 #endif /* not __MSDOS__ and not OS2 */
2115 #if defined(OS2) || defined(WINNT)
2125 for (i = 1; argvec[i] != 0; i++)
2128 char *temp, *newtemp;
2131 len = strlen (temp);
2132 for (j = 0; j < len; j++)
2136 newtemp = xmalloc (len + 2);
2137 strncpy (newtemp, temp, j);
2139 strncpy (&newtemp [j+1], &temp [j], len-j);
2140 newtemp [len+1] = 0;
2154 #define FIX_ARGV(a) fix_argv(a)
2158 #define FIX_ARGV(a) a
2160 #endif /* OS2 or WINNT */
2163 pexecute (search_flag, program, argv, not_last)
2169 return (search_flag ? spawnv : spawnvp) (1, program, FIX_ARGV (argv));
2171 #endif /* OS2 or WINNT */
2174 /* Execute the command specified by the arguments on the current line of spec.
2175 When using pipes, this includes several piped-together commands
2176 with `|' between them.
2178 Return 0 if successful, -1 if failed. */
2184 int n_commands; /* # of command. */
2188 char *prog; /* program name. */
2189 char **argv; /* vector of args. */
2190 int pid; /* pid of process for this command. */
2193 struct command *commands; /* each command buffer with above info. */
2195 /* Count # of piped commands. */
2196 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2197 if (strcmp (argbuf[i], "|") == 0)
2200 /* Get storage for each command. */
2202 = (struct command *) alloca (n_commands * sizeof (struct command));
2204 /* Split argbuf into its separate piped processes,
2205 and record info about each one.
2206 Also search for the programs that are to be run. */
2208 commands[0].prog = argbuf[0]; /* first command. */
2209 commands[0].argv = &argbuf[0];
2210 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2212 commands[0].argv[0] = string;
2214 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2215 if (strcmp (argbuf[i], "|") == 0)
2216 { /* each command. */
2218 fatal ("-pipe not supported under MS-DOS");
2220 argbuf[i] = 0; /* termination of command args. */
2221 commands[n_commands].prog = argbuf[i + 1];
2222 commands[n_commands].argv = &argbuf[i + 1];
2223 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2225 commands[n_commands].argv[0] = string;
2229 argbuf[argbuf_index] = 0;
2231 /* If -v, print what we are about to do, and maybe query. */
2235 /* Print each piped command as a separate line. */
2236 for (i = 0; i < n_commands ; i++)
2240 for (j = commands[i].argv; *j; j++)
2241 fprintf (stderr, " %s", *j);
2243 /* Print a pipe symbol after all but the last command. */
2244 if (i + 1 != n_commands)
2245 fprintf (stderr, " |");
2246 fprintf (stderr, "\n");
2250 fprintf (stderr, "\nGo ahead? (y or n) ");
2254 while (getchar () != '\n') ;
2255 if (i != 'y' && i != 'Y')
2260 /* Run each piped subprocess. */
2262 last_pipe_input = STDIN_FILE_NO;
2263 for (i = 0; i < n_commands; i++)
2265 char *string = commands[i].argv[0];
2267 commands[i].pid = pexecute (string != commands[i].prog,
2268 string, commands[i].argv,
2269 i + 1 < n_commands);
2271 if (string != commands[i].prog)
2277 /* Wait for all the subprocesses to finish.
2278 We don't care what order they finish in;
2279 we know that N_COMMANDS waits will get them all.
2280 Ignore subprocesses that we don't know about,
2281 since they can be spawned by the process that exec'ed us. */
2286 for (i = 0; i < n_commands; )
2293 status = pid = commands[i].pid;
2296 pid = cwait (&status, commands[i].pid, WAIT_CHILD);
2298 pid = wait (&status);
2304 for (j = 0; j < n_commands; j++)
2305 if (commands[j].pid == pid)
2310 if (WIFSIGNALED (status))
2312 fatal ("Internal compiler error: program %s got fatal signal %d",
2313 commands[j].prog, WTERMSIG (status));
2317 else if (WIFEXITED (status)
2318 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2328 /* Find all the switches given to us
2329 and make a vector describing them.
2330 The elements of the vector are strings, one per switch given.
2331 If a switch uses following arguments, then the `part1' field
2332 is the switch itself and the `args' field
2333 is a null-terminated vector containing the following arguments.
2334 The `live_cond' field is 1 if the switch is true in a conditional spec,
2335 -1 if false (overridden by a later switch), and is initialized to zero.
2336 The `valid' field is nonzero if any spec has looked at this switch;
2337 if it remains zero at the end of the run, it must be meaningless. */
2347 static struct switchstr *switches;
2349 static int n_switches;
2357 /* Also a vector of input files specified. */
2359 static struct infile *infiles;
2361 static int n_infiles;
2363 /* And a vector of corresponding output files is made up later. */
2365 static char **outfiles;
2367 /* Create the vector `switches' and its contents.
2368 Store its length in `n_switches'. */
2371 process_command (argc, argv)
2377 char *spec_lang = 0;
2378 int last_language_n_infiles;
2380 gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
2385 /* Figure compiler version from version string. */
2387 compiler_version = save_string (version_string, strlen (version_string));
2388 for (temp = compiler_version; *temp; ++temp)
2397 /* Set up the default search paths. */
2399 if (gcc_exec_prefix)
2401 add_prefix (&exec_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2402 add_prefix (&startfile_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
2405 /* COMPILER_PATH and LIBRARY_PATH have values
2406 that are lists of directory names with colons. */
2408 temp = getenv ("COMPILER_PATH");
2411 char *startp, *endp;
2412 char *nstore = (char *) alloca (strlen (temp) + 3);
2414 startp = endp = temp;
2417 if (*endp == PATH_SEPARATOR || *endp == 0)
2419 strncpy (nstore, startp, endp-startp);
2421 strcpy (nstore, concat (".", dir_separator_str));
2422 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2424 nstore[endp-startp] = DIR_SEPARATOR;
2425 nstore[endp-startp+1] = 0;
2428 nstore[endp-startp] = 0;
2429 add_prefix (&exec_prefixes, nstore, 0, 0, NULL_PTR);
2432 endp = startp = endp + 1;
2439 temp = getenv ("LIBRARY_PATH");
2440 if (temp && ! cross_compile)
2442 char *startp, *endp;
2443 char *nstore = (char *) alloca (strlen (temp) + 3);
2445 startp = endp = temp;
2448 if (*endp == PATH_SEPARATOR || *endp == 0)
2450 strncpy (nstore, startp, endp-startp);
2452 strcpy (nstore, concat (".", dir_separator_str));
2453 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2455 nstore[endp-startp] = DIR_SEPARATOR;
2456 nstore[endp-startp+1] = 0;
2459 nstore[endp-startp] = 0;
2460 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2463 endp = startp = endp + 1;
2470 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2471 temp = getenv ("LPATH");
2472 if (temp && ! cross_compile)
2474 char *startp, *endp;
2475 char *nstore = (char *) alloca (strlen (temp) + 3);
2477 startp = endp = temp;
2480 if (*endp == PATH_SEPARATOR || *endp == 0)
2482 strncpy (nstore, startp, endp-startp);
2484 strcpy (nstore, concat (".", dir_separator_str));
2485 else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
2487 nstore[endp-startp] = DIR_SEPARATOR;
2488 nstore[endp-startp+1] = 0;
2491 nstore[endp-startp] = 0;
2492 add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
2495 endp = startp = endp + 1;
2502 /* Convert new-style -- options to old-style. */
2503 translate_options (&argc, &argv);
2505 /* Scan argv twice. Here, the first time, just count how many switches
2506 there will be in their vector, and how many input files in theirs.
2507 Here we also parse the switches that cc itself uses (e.g. -v). */
2509 for (i = 1; i < argc; i++)
2511 if (! strcmp (argv[i], "-dumpspecs"))
2513 printf ("*asm:\n%s\n\n", asm_spec);
2514 printf ("*asm_final:\n%s\n\n", asm_final_spec);
2515 printf ("*cpp:\n%s\n\n", cpp_spec);
2516 printf ("*cc1:\n%s\n\n", cc1_spec);
2517 printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
2518 printf ("*endfile:\n%s\n\n", endfile_spec);
2519 printf ("*link:\n%s\n\n", link_spec);
2520 printf ("*lib:\n%s\n\n", lib_spec);
2521 printf ("*libgcc:\n%s\n\n", libgcc_spec);
2522 printf ("*startfile:\n%s\n\n", startfile_spec);
2523 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
2524 printf ("*signed_char:\n%s\n\n", signed_char_spec);
2525 printf ("*predefines:\n%s\n\n", cpp_predefines);
2526 printf ("*cross_compile:\n%d\n\n", cross_compile);
2527 printf ("*multilib:\n%s\n\n", multilib_select);
2531 else if (! strcmp (argv[i], "-dumpversion"))
2533 printf ("%s\n", version_string);
2536 else if (! strcmp (argv[i], "-dumpmachine"))
2538 printf ("%s\n", spec_machine);
2541 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
2542 print_file_name = "libgcc.a";
2543 else if (! strncmp (argv[i], "-print-file-name=", 17))
2544 print_file_name = argv[i] + 17;
2545 else if (! strncmp (argv[i], "-print-prog-name=", 17))
2546 print_prog_name = argv[i] + 17;
2547 else if (! strcmp (argv[i], "-print-multi-lib"))
2548 print_multi_lib = 1;
2549 else if (! strcmp (argv[i], "-print-multi-directory"))
2550 print_multi_directory = 1;
2551 else if (! strncmp (argv[i], "-Wa,", 4))
2554 /* Pass the rest of this option to the assembler. */
2556 n_assembler_options++;
2557 if (!assembler_options)
2559 = (char **) xmalloc (n_assembler_options * sizeof (char **));
2562 = (char **) xrealloc (assembler_options,
2563 n_assembler_options * sizeof (char **));
2565 /* Split the argument at commas. */
2567 for (j = 4; argv[i][j]; j++)
2568 if (argv[i][j] == ',')
2570 assembler_options[n_assembler_options - 1]
2571 = save_string (argv[i] + prev, j - prev);
2572 n_assembler_options++;
2574 = (char **) xrealloc (assembler_options,
2575 n_assembler_options * sizeof (char **));
2578 /* Record the part after the last comma. */
2579 assembler_options[n_assembler_options - 1] = argv[i] + prev;
2581 else if (! strncmp (argv[i], "-Wp,", 4))
2584 /* Pass the rest of this option to the preprocessor. */
2586 n_preprocessor_options++;
2587 if (!preprocessor_options)
2588 preprocessor_options
2589 = (char **) xmalloc (n_preprocessor_options * sizeof (char **));
2591 preprocessor_options
2592 = (char **) xrealloc (preprocessor_options,
2593 n_preprocessor_options * sizeof (char **));
2595 /* Split the argument at commas. */
2597 for (j = 4; argv[i][j]; j++)
2598 if (argv[i][j] == ',')
2600 preprocessor_options[n_preprocessor_options - 1]
2601 = save_string (argv[i] + prev, j - prev);
2602 n_preprocessor_options++;
2603 preprocessor_options
2604 = (char **) xrealloc (preprocessor_options,
2605 n_preprocessor_options * sizeof (char **));
2608 /* Record the part after the last comma. */
2609 preprocessor_options[n_preprocessor_options - 1] = argv[i] + prev;
2611 else if (argv[i][0] == '+' && argv[i][1] == 'e')
2612 /* The +e options to the C++ front-end. */
2614 else if (strncmp (argv[i], "-Wl,", 4) == 0)
2617 /* Split the argument at commas. */
2618 for (j = 3; argv[i][j]; j++)
2619 n_infiles += (argv[i][j] == ',');
2621 else if (strcmp (argv[i], "-Xlinker") == 0)
2624 fatal ("argument to `-Xlinker' is missing");
2629 else if (strncmp (argv[i], "-l", 2) == 0)
2631 else if (argv[i][0] == '-' && argv[i][1] != 0)
2633 register char *p = &argv[i][1];
2634 register int c = *p;
2639 if (p[1] == 0 && i + 1 == argc)
2640 fatal ("argument to `-b' is missing");
2642 spec_machine = argv[++i];
2644 spec_machine = p + 1;
2649 int *temp = (int *) xmalloc (sizeof (int));
2651 if (p[1] == 0 && i + 1 == argc)
2652 fatal ("argument to `-B' is missing");
2657 add_prefix (&exec_prefixes, value, 1, 0, temp);
2658 add_prefix (&startfile_prefixes, value, 1, 0, temp);
2659 add_prefix (&include_prefixes, concat (value, "include"),
2662 /* As a kludge, if the arg is "[foo/]stageN/", just add
2663 "[foo/]include" to the include prefix. */
2665 int len = strlen (value);
2668 && (value[len - 8] == '/'
2669 || value[len - 8] == DIR_SEPARATOR)))
2670 && strncmp (value + len - 7, "stage", 5) == 0
2671 && isdigit (value[len - 2])
2672 && (value[len - 1] == '/'
2673 || value[len - 1] == DIR_SEPARATOR))
2676 add_prefix (&include_prefixes, "include", 1, 0, 0);
2679 char *string = xmalloc (len + 1);
2680 strncpy (string, value, len-7);
2681 strcat (string, "include");
2682 add_prefix (&include_prefixes, string, 1, 0, 0);
2689 case 'v': /* Print our subcommands and print versions. */
2691 /* If they do anything other than exactly `-v', don't set
2692 verbose_flag; rather, continue on to give the error. */
2699 if (p[1] == 0 && i + 1 == argc)
2700 fatal ("argument to `-V' is missing");
2702 spec_version = argv[++i];
2704 spec_version = p + 1;
2705 compiler_version = spec_version;
2709 if (!strcmp (p, "save-temps"))
2711 save_temps_flag = 1;
2718 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
2719 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
2720 else if (WORD_SWITCH_TAKES_ARG (p))
2721 i += WORD_SWITCH_TAKES_ARG (p);
2728 /* Set up the search paths before we go looking for config files. */
2730 /* These come before the md prefixes so that we will find gcc's subcommands
2731 (such as cpp) rather than those of the host system. */
2732 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2733 as well as trying the machine and the version. */
2735 add_prefix (&exec_prefixes, standard_exec_prefix, 0, 2, NULL_PTR);
2736 add_prefix (&exec_prefixes, standard_exec_prefix_1, 0, 2, NULL_PTR);
2739 add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, NULL_PTR);
2740 add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, NULL_PTR);
2742 tooldir_prefix = concat3 (tooldir_base_prefix, spec_machine,
2745 /* If tooldir is relative, base it on exec_prefixes. A relative
2746 tooldir lets us move the installed tree as a unit.
2748 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2749 directories, so that we can search both the user specified directory
2750 and the standard place. */
2752 if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
2754 if (gcc_exec_prefix)
2756 char *gcc_exec_tooldir_prefix
2757 = concat6 (gcc_exec_prefix, spec_machine, dir_separator_str,
2758 spec_version, dir_separator_str, tooldir_prefix);
2760 add_prefix (&exec_prefixes,
2761 concat3 (gcc_exec_tooldir_prefix, "bin",
2764 add_prefix (&startfile_prefixes,
2765 concat3 (gcc_exec_tooldir_prefix, "lib",
2770 tooldir_prefix = concat6 (standard_exec_prefix, spec_machine,
2771 dir_separator_str, spec_version,
2772 dir_separator_str, tooldir_prefix);
2775 add_prefix (&exec_prefixes,
2776 concat3 (tooldir_prefix, "bin", dir_separator_str),
2778 add_prefix (&startfile_prefixes,
2779 concat3 (tooldir_prefix, "lib", dir_separator_str),
2782 /* More prefixes are enabled in main, after we read the specs file
2783 and determine whether this is cross-compilation or not. */
2786 /* Then create the space for the vectors and scan again. */
2788 switches = ((struct switchstr *)
2789 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
2790 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
2793 last_language_n_infiles = -1;
2795 /* This, time, copy the text of each switch and store a pointer
2796 to the copy in the vector of switches.
2797 Store all the infiles in their vector. */
2799 for (i = 1; i < argc; i++)
2801 /* Just skip the switches that were handled by the preceding loop. */
2802 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 (strncmp (argv[i], "-Wl,", 4) == 0)
2832 /* Split the argument at commas. */
2834 for (j = 4; argv[i][j]; j++)
2835 if (argv[i][j] == ',')
2837 infiles[n_infiles].language = spec_lang;
2838 infiles[n_infiles++].name
2839 = save_string (argv[i] + prev, j - prev);
2842 /* Record the part after the last comma. */
2843 infiles[n_infiles].language = spec_lang;
2844 infiles[n_infiles++].name = argv[i] + prev;
2846 else if (strcmp (argv[i], "-Xlinker") == 0)
2848 infiles[n_infiles].language = spec_lang;
2849 infiles[n_infiles++].name = argv[++i];
2851 else if (strncmp (argv[i], "-l", 2) == 0)
2853 infiles[n_infiles].language = spec_lang;
2854 infiles[n_infiles++].name = argv[i];
2856 else if (argv[i][0] == '-' && argv[i][1] != 0)
2858 register char *p = &argv[i][1];
2859 register int c = *p;
2861 if (c == 'B' || c == 'b' || c == 'V')
2863 /* Skip a separate arg, if any. */
2870 if (p[1] == 0 && i + 1 == argc)
2871 fatal ("argument to `-x' is missing");
2873 spec_lang = argv[++i];
2876 if (! strcmp (spec_lang, "none"))
2877 /* Suppress the warning if -xnone comes after the last input file,
2878 because alternate command interfaces like g++ might find it
2879 useful to place -xnone after each input file. */
2882 last_language_n_infiles = n_infiles;
2885 switches[n_switches].part1 = p;
2886 /* Deal with option arguments in separate argv elements. */
2887 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
2888 || WORD_SWITCH_TAKES_ARG (p))
2891 int n_args = WORD_SWITCH_TAKES_ARG (p);
2895 /* Count only the option arguments in separate argv elements. */
2896 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
2898 if (i + n_args >= argc)
2899 fatal ("argument to `-%s' is missing", p);
2900 switches[n_switches].args
2901 = (char **) xmalloc ((n_args + 1) * sizeof (char *));
2903 switches[n_switches].args[j++] = argv[++i];
2904 /* Null-terminate the vector. */
2905 switches[n_switches].args[j] = 0;
2907 else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L'))
2909 /* On some systems, ld cannot handle -o or -L without space.
2910 So split the -o or -L from its argument. */
2911 switches[n_switches].part1 = (c == 'o' ? "o" : "L");
2912 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
2913 switches[n_switches].args[0] = xmalloc (strlen (p));
2914 strcpy (switches[n_switches].args[0], &p[1]);
2915 switches[n_switches].args[1] = 0;
2918 switches[n_switches].args = 0;
2920 switches[n_switches].live_cond = 0;
2921 switches[n_switches].valid = 0;
2922 /* This is always valid, since gcc.c itself understands it. */
2923 if (!strcmp (p, "save-temps"))
2924 switches[n_switches].valid = 1;
2929 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
2931 perror_with_name (argv[i]);
2936 infiles[n_infiles].language = spec_lang;
2937 infiles[n_infiles++].name = argv[i];
2942 if (n_infiles == last_language_n_infiles && spec_lang != 0)
2943 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
2945 switches[n_switches].part1 = 0;
2946 infiles[n_infiles].name = 0;
2948 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2949 if (gcc_exec_prefix)
2951 temp = (char *) xmalloc (strlen (gcc_exec_prefix) + strlen (spec_version)
2952 + strlen (spec_machine) + 3);
2953 strcpy (temp, gcc_exec_prefix);
2954 strcat (temp, spec_machine);
2955 strcat (temp, dir_separator_str);
2956 strcat (temp, spec_version);
2957 strcat (temp, dir_separator_str);
2958 gcc_exec_prefix = temp;
2962 /* Process a spec string, accumulating and running commands. */
2964 /* These variables describe the input file name.
2965 input_file_number is the index on outfiles of this file,
2966 so that the output file name can be stored for later use by %o.
2967 input_basename is the start of the part of the input file
2968 sans all directory names, and basename_length is the number
2969 of characters starting there excluding the suffix .c or whatever. */
2971 static char *input_filename;
2972 static int input_file_number;
2973 static int input_filename_length;
2974 static int basename_length;
2975 static char *input_basename;
2976 static char *input_suffix;
2978 /* These are variables used within do_spec and do_spec_1. */
2980 /* Nonzero if an arg has been started and not yet terminated
2981 (with space, tab or newline). */
2982 static int arg_going;
2984 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2985 is a temporary file name. */
2986 static int delete_this_arg;
2988 /* Nonzero means %w has been seen; the next arg to be terminated
2989 is the output file name of this compilation. */
2990 static int this_is_output_file;
2992 /* Nonzero means %s has been seen; the next arg to be terminated
2993 is the name of a library file and we should try the standard
2994 search dirs for it. */
2995 static int this_is_library_file;
2997 /* Nonzero means that the input of this command is coming from a pipe. */
2998 static int input_from_pipe;
3000 /* Process the spec SPEC and run the commands specified therein.
3001 Returns 0 if the spec is successfully processed; -1 if failed. */
3011 delete_this_arg = 0;
3012 this_is_output_file = 0;
3013 this_is_library_file = 0;
3014 input_from_pipe = 0;
3016 value = do_spec_1 (spec, 0, NULL_PTR);
3018 /* Force out any unfinished command.
3019 If -pipe, this forces out the last command if it ended in `|'. */
3022 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3025 if (argbuf_index > 0)
3032 /* Process the sub-spec SPEC as a portion of a larger spec.
3033 This is like processing a whole spec except that we do
3034 not initialize at the beginning and we do not supply a
3035 newline by default at the end.
3036 INSWITCH nonzero means don't process %-sequences in SPEC;
3037 in this case, % is treated as an ordinary character.
3038 This is used while substituting switches.
3039 INSWITCH nonzero also causes SPC not to terminate an argument.
3041 Value is zero unless a line was finished
3042 and the command on that line reported an error. */
3045 do_spec_1 (spec, inswitch, soft_matched_part)
3048 char *soft_matched_part;
3050 register char *p = spec;
3057 /* If substituting a switch, treat all chars like letters.
3058 Otherwise, NL, SPC, TAB and % are special. */
3059 switch (inswitch ? 'a' : c)
3062 /* End of line: finish any pending argument,
3063 then run the pending command if one has been started. */
3066 obstack_1grow (&obstack, 0);
3067 string = obstack_finish (&obstack);
3068 if (this_is_library_file)
3069 string = find_file (string);
3070 store_arg (string, delete_this_arg, this_is_output_file);
3071 if (this_is_output_file)
3072 outfiles[input_file_number] = string;
3076 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
3079 for (i = 0; i < n_switches; i++)
3080 if (!strcmp (switches[i].part1, "pipe"))
3083 /* A `|' before the newline means use a pipe here,
3084 but only if -pipe was specified.
3085 Otherwise, execute now and don't pass the `|' as an arg. */
3088 input_from_pipe = 1;
3089 switches[i].valid = 1;
3096 if (argbuf_index > 0)
3102 /* Reinitialize for a new command, and for a new argument. */
3105 delete_this_arg = 0;
3106 this_is_output_file = 0;
3107 this_is_library_file = 0;
3108 input_from_pipe = 0;
3112 /* End any pending argument. */
3115 obstack_1grow (&obstack, 0);
3116 string = obstack_finish (&obstack);
3117 if (this_is_library_file)
3118 string = find_file (string);
3119 store_arg (string, delete_this_arg, this_is_output_file);
3120 if (this_is_output_file)
3121 outfiles[input_file_number] = string;
3125 obstack_1grow (&obstack, c);
3131 /* Space or tab ends an argument if one is pending. */
3134 obstack_1grow (&obstack, 0);
3135 string = obstack_finish (&obstack);
3136 if (this_is_library_file)
3137 string = find_file (string);
3138 store_arg (string, delete_this_arg, this_is_output_file);
3139 if (this_is_output_file)
3140 outfiles[input_file_number] = string;
3142 /* Reinitialize for a new argument. */
3144 delete_this_arg = 0;
3145 this_is_output_file = 0;
3146 this_is_library_file = 0;
3153 fatal ("Invalid specification! Bug in cc.");
3156 obstack_grow (&obstack, input_basename, basename_length);
3161 delete_this_arg = 2;
3164 /* Dump out the directories specified with LIBRARY_PATH,
3165 followed by the absolute directories
3166 that we search for startfiles. */
3169 struct prefix_list *pl = startfile_prefixes.plist;
3171 char *buffer = (char *) xmalloc (bufsize);
3174 for (; pl; pl = pl->next)
3176 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3177 /* Used on systems which record the specified -L dirs
3178 and use them to search for dynamic linking. */
3179 /* Relative directories always come from -B,
3180 and it is better not to use them for searching
3181 at run time. In particular, stage1 loses */
3182 if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
3185 /* Try subdirectory if there is one. */
3186 if (multilib_dir != NULL)
3190 if (strlen (pl->prefix) + strlen (machine_suffix)
3192 bufsize = (strlen (pl->prefix)
3193 + strlen (machine_suffix)) * 2 + 1;
3194 buffer = (char *) xrealloc (buffer, bufsize);
3195 strcpy (buffer, pl->prefix);
3196 strcat (buffer, machine_suffix);
3197 if (is_directory (buffer, multilib_dir, 1))
3199 do_spec_1 ("-L", 0, NULL_PTR);
3200 #ifdef SPACE_AFTER_L_OPTION
3201 do_spec_1 (" ", 0, NULL_PTR);
3203 do_spec_1 (buffer, 1, NULL_PTR);
3204 do_spec_1 (multilib_dir, 1, NULL_PTR);
3205 /* Make this a separate argument. */
3206 do_spec_1 (" ", 0, NULL_PTR);
3209 if (!pl->require_machine_suffix)
3211 if (is_directory (pl->prefix, multilib_dir, 1))
3213 do_spec_1 ("-L", 0, NULL_PTR);
3214 #ifdef SPACE_AFTER_L_OPTION
3215 do_spec_1 (" ", 0, NULL_PTR);
3217 do_spec_1 (pl->prefix, 1, NULL_PTR);
3218 do_spec_1 (multilib_dir, 1, NULL_PTR);
3219 /* Make this a separate argument. */
3220 do_spec_1 (" ", 0, NULL_PTR);
3226 if (is_directory (pl->prefix, machine_suffix, 1))
3228 do_spec_1 ("-L", 0, NULL_PTR);
3229 #ifdef SPACE_AFTER_L_OPTION
3230 do_spec_1 (" ", 0, NULL_PTR);
3232 do_spec_1 (pl->prefix, 1, NULL_PTR);
3233 /* Remove slash from machine_suffix. */
3234 if (strlen (machine_suffix) >= bufsize)
3235 bufsize = strlen (machine_suffix) * 2 + 1;
3236 buffer = (char *) xrealloc (buffer, bufsize);
3237 strcpy (buffer, machine_suffix);
3238 idx = strlen (buffer);
3239 if (buffer[idx - 1] == '/'
3240 || buffer[idx - 1] == DIR_SEPARATOR)
3241 buffer[idx - 1] = 0;
3242 do_spec_1 (buffer, 1, NULL_PTR);
3243 /* Make this a separate argument. */
3244 do_spec_1 (" ", 0, NULL_PTR);
3247 if (!pl->require_machine_suffix)
3249 if (is_directory (pl->prefix, "", 1))
3251 do_spec_1 ("-L", 0, NULL_PTR);
3252 #ifdef SPACE_AFTER_L_OPTION
3253 do_spec_1 (" ", 0, NULL_PTR);
3255 /* Remove slash from pl->prefix. */
3256 if (strlen (pl->prefix) >= bufsize)
3257 bufsize = strlen (pl->prefix) * 2 + 1;
3258 buffer = (char *) xrealloc (buffer, bufsize);
3259 strcpy (buffer, pl->prefix);
3260 idx = strlen (buffer);
3261 if (buffer[idx - 1] == '/'
3262 || buffer[idx - 1] == DIR_SEPARATOR)
3263 buffer[idx - 1] = 0;
3264 do_spec_1 (buffer, 1, NULL_PTR);
3265 /* Make this a separate argument. */
3266 do_spec_1 (" ", 0, NULL_PTR);
3275 /* {...:%efoo} means report an error with `foo' as error message
3276 and don't execute any more commands for this file. */
3280 while (*p != 0 && *p != '\n') p++;
3281 buf = (char *) alloca (p - q + 1);
3282 strncpy (buf, q, p - q);
3292 if (save_temps_flag)
3294 obstack_grow (&obstack, input_basename, basename_length);
3295 delete_this_arg = 0;
3299 #ifdef MKTEMP_EACH_FILE
3300 /* ??? This has a problem: the total number of
3301 values mktemp can return is limited.
3302 That matters for the names of object files.
3303 In 2.4, do something about that. */
3304 struct temp_name *t;
3306 while (*p == '.' || isalpha (*p))
3309 /* See if we already have an association of %g/%u/%U and
3311 for (t = temp_names; t; t = t->next)
3312 if (t->length == p - suffix
3313 && strncmp (t->suffix, suffix, p - suffix) == 0
3314 && t->unique == (c != 'g'))
3317 /* Make a new association if needed. %u requires one. */
3318 if (t == 0 || c == 'u')
3322 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
3323 t->next = temp_names;
3326 t->length = p - suffix;
3327 t->suffix = save_string (suffix, p - suffix);
3328 t->unique = (c != 'g');
3329 choose_temp_base ();
3330 t->filename = temp_filename;
3331 t->filename_length = temp_filename_length;
3334 obstack_grow (&obstack, t->filename, t->filename_length);
3335 delete_this_arg = 1;
3337 obstack_grow (&obstack, temp_filename, temp_filename_length);
3338 if (c == 'u' || c == 'U')
3344 sprintf (buff, "%d", unique);
3345 obstack_grow (&obstack, buff, strlen (buff));
3348 delete_this_arg = 1;
3354 obstack_grow (&obstack, input_filename, input_filename_length);
3360 struct prefix_list *pl = include_prefixes.plist;
3362 if (gcc_exec_prefix)
3364 do_spec_1 ("-iprefix", 1, NULL_PTR);
3365 /* Make this a separate argument. */
3366 do_spec_1 (" ", 0, NULL_PTR);
3367 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
3368 do_spec_1 (" ", 0, NULL_PTR);
3371 for (; pl; pl = pl->next)
3373 do_spec_1 ("-isystem", 1, NULL_PTR);
3374 /* Make this a separate argument. */
3375 do_spec_1 (" ", 0, NULL_PTR);
3376 do_spec_1 (pl->prefix, 1, NULL_PTR);
3377 do_spec_1 (" ", 0, NULL_PTR);
3385 for (f = 0; f < n_infiles; f++)
3386 store_arg (outfiles[f], 0, 0);
3391 this_is_library_file = 1;
3395 this_is_output_file = 1;
3400 int index = argbuf_index;
3401 /* Handle the {...} following the %W. */
3404 p = handle_braces (p + 1);
3407 /* If any args were output, mark the last one for deletion
3409 if (argbuf_index != index)
3410 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
3414 /* %x{OPTION} records OPTION for %X to output. */
3420 /* Skip past the option value and make a copy. */
3425 string = save_string (p1 + 1, p - p1 - 2);
3427 /* See if we already recorded this option. */
3428 for (i = 0; i < n_linker_options; i++)
3429 if (! strcmp (string, linker_options[i]))
3435 /* This option is new; add it. */
3437 if (!linker_options)
3439 = (char **) xmalloc (n_linker_options * sizeof (char **));
3442 = (char **) xrealloc (linker_options,
3443 n_linker_options * sizeof (char **));
3445 linker_options[n_linker_options - 1] = string;
3449 /* Dump out the options accumulated previously using %x. */
3451 for (i = 0; i < n_linker_options; i++)
3453 do_spec_1 (linker_options[i], 1, NULL_PTR);
3454 /* Make each accumulated option a separate argument. */
3455 do_spec_1 (" ", 0, NULL_PTR);
3459 /* Dump out the options accumulated previously using -Wa,. */
3461 for (i = 0; i < n_assembler_options; i++)
3463 do_spec_1 (assembler_options[i], 1, NULL_PTR);
3464 /* Make each accumulated option a separate argument. */
3465 do_spec_1 (" ", 0, NULL_PTR);
3469 /* Dump out the options accumulated previously using -Wp,. */
3471 for (i = 0; i < n_preprocessor_options; i++)
3473 do_spec_1 (preprocessor_options[i], 1, NULL_PTR);
3474 /* Make each accumulated option a separate argument. */
3475 do_spec_1 (" ", 0, NULL_PTR);
3479 /* Here are digits and numbers that just process
3480 a certain constant string as a spec. */
3483 value = do_spec_1 (cc1_spec, 0, NULL_PTR);
3489 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
3495 value = do_spec_1 (asm_spec, 0, NULL_PTR);
3501 value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
3507 value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
3513 value = do_spec_1 (cpp_spec, 0, NULL_PTR);
3519 value = do_spec_1 (endfile_spec, 0, NULL_PTR);
3525 value = do_spec_1 (link_spec, 0, NULL_PTR);
3531 value = do_spec_1 (lib_spec, 0, NULL_PTR);
3537 value = do_spec_1 (libgcc_spec, 0, NULL_PTR);
3544 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
3548 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3552 if (! strncmp (y, "-D", 2))
3553 /* Copy the whole option. */
3554 while (*y && *y != ' ' && *y != '\t')
3556 else if (*y == ' ' || *y == '\t')
3557 /* Copy whitespace to the result. */
3559 /* Don't copy other options. */
3566 value = do_spec_1 (buf, 0, NULL_PTR);
3574 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
3578 /* Copy all of CPP_PREDEFINES into BUF,
3579 but put __ after every -D and at the end of each arg. */
3583 if (! strncmp (y, "-D", 2))
3591 || (*(y+1) != '_' && ! isupper (*(y+1))))
3593 /* Stick __ at front of macro name. */
3596 /* Arrange to stick __ at the end as well. */
3600 /* Copy the macro name. */
3601 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3610 /* Copy the value given, if any. */
3611 while (*y && *y != ' ' && *y != '\t')
3614 else if (*y == ' ' || *y == '\t')
3615 /* Copy whitespace to the result. */
3617 /* Don't copy -A options */
3623 /* Copy all of CPP_PREDEFINES into BUF,
3624 but put __ after every -D. */
3628 if (! strncmp (y, "-D", 2))
3633 || (*(y+1) != '_' && ! isupper (*(y+1))))
3635 /* Stick -D__ at front of macro name. */
3641 /* Copy the macro name. */
3642 while (*y && *y != '=' && *y != ' ' && *y != '\t')
3645 /* Copy the value given, if any. */
3646 while (*y && *y != ' ' && *y != '\t')
3651 /* Do not copy this macro - we have just done it before */
3652 while (*y && *y != ' ' && *y != '\t')
3656 else if (*y == ' ' || *y == '\t')
3657 /* Copy whitespace to the result. */
3659 /* Don't copy -A options */
3665 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3669 if (! strncmp (y, "-A", 2))
3670 /* Copy the whole option. */
3671 while (*y && *y != ' ' && *y != '\t')
3673 else if (*y == ' ' || *y == '\t')
3674 /* Copy whitespace to the result. */
3676 /* Don't copy other options. */
3683 value = do_spec_1 (buf, 0, NULL_PTR);
3690 value = do_spec_1 (startfile_spec, 0, NULL_PTR);
3695 /* Here we define characters other than letters and digits. */
3698 p = handle_braces (p);
3704 obstack_1grow (&obstack, '%');
3708 do_spec_1 (soft_matched_part, 1, NULL_PTR);
3709 do_spec_1 (" ", 0, NULL_PTR);
3712 /* Process a string found as the value of a spec given by name.
3713 This feature allows individual machine descriptions
3714 to add and use their own specs.
3715 %[...] modifies -D options the way %P does;
3716 %(...) uses the spec unmodified. */
3721 struct spec_list *sl;
3724 /* The string after the S/P is the name of a spec that is to be
3726 while (*p && *p != ')' && *p != ']')
3729 /* See if it's in the list */
3730 for (len = p - name, sl = specs; sl; sl = sl->next)
3731 if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
3741 value = do_spec_1 (name, 0, NULL_PTR);
3747 char *x = (char *) alloca (strlen (name) * 2 + 1);
3751 /* Copy all of NAME into BUF, but put __ after
3752 every -D and at the end of each arg, */
3755 if (! strncmp (y, "-D", 2))
3763 else if (*y == ' ' || *y == 0)
3777 value = do_spec_1 (buf, 0, NULL_PTR);
3783 /* Discard the closing paren or bracket. */
3791 int c1 = *p++; /* Select first or second version number. */
3792 char *v = compiler_version;
3794 /* If desired, advance to second version number. */
3797 /* Set P after the first period. */
3798 while (*v != 0 && *v != ' ' && *v != '.')
3803 /* Set Q at the next period or at the end. */
3805 while (*q != 0 && *q != ' ' && *q != '.')
3807 /* Empty string means zero. */
3813 /* Put that part into the command. */
3814 obstack_grow (&obstack, v, q - v);
3820 if (input_from_pipe)
3821 do_spec_1 ("-", 0, NULL_PTR);
3830 /* Backslash: treat next character as ordinary. */
3835 /* Ordinary character: put it into the current argument. */
3836 obstack_1grow (&obstack, c);
3840 return 0; /* End of string */
3843 /* Return 0 if we call do_spec_1 and that returns -1. */
3856 /* A `|' after the open-brace means,
3857 if the test fails, output a single minus sign rather than nothing.
3858 This is used in %{|!pipe:...}. */
3862 /* A `!' after the open-brace negates the condition:
3863 succeed if the specified switch is not present. */
3867 /* A `.' after the open-brace means test against the current suffix. */
3877 while (*p != ':' && *p != '}') p++;
3880 register int count = 1;
3898 int found = (input_suffix != 0
3899 && strlen (input_suffix) == p - filter
3900 && strncmp (input_suffix, filter, p - filter) == 0);
3906 && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
3911 else if (p[-1] == '*' && p[0] == '}')
3913 /* Substitute all matching switches as separate args. */
3916 for (i = 0; i < n_switches; i++)
3917 if (!strncmp (switches[i].part1, filter, p - filter)
3918 && check_live_switch (i, p - filter))
3923 /* Test for presence of the specified switch. */
3927 /* If name specified ends in *, as in {x*:...},
3928 check for %* and handle that case. */
3929 if (p[-1] == '*' && !negate)
3934 /* First see whether we have %*. */
3938 if (*r == '%' && r[1] == '*')
3942 /* If we do, handle that case. */
3945 /* Substitute all matching switches as separate args.
3946 But do this by substituting for %*
3947 in the text that follows the colon. */
3949 unsigned hard_match_len = p - filter - 1;
3950 char *string = save_string (p + 1, q - p - 2);
3952 for (i = 0; i < n_switches; i++)
3953 if (!strncmp (switches[i].part1, filter, hard_match_len)
3954 && check_live_switch (i, -1))
3956 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
3957 /* Pass any arguments this switch has. */
3965 /* If name specified ends in *, as in {x*:...},
3966 check for presence of any switch name starting with x. */
3969 for (i = 0; i < n_switches; i++)
3971 unsigned hard_match_len = p - filter - 1;
3973 if (!strncmp (switches[i].part1, filter, hard_match_len)
3974 && check_live_switch (i, hard_match_len))
3980 /* Otherwise, check for presence of exact name specified. */
3983 for (i = 0; i < n_switches; i++)
3985 if (!strncmp (switches[i].part1, filter, p - filter)
3986 && switches[i].part1[p - filter] == 0
3987 && check_live_switch (i, -1))
3995 /* If it is as desired (present for %{s...}, absent for %{-s...})
3996 then substitute either the switch or the specified
3997 conditional text. */
3998 if (present != negate)
4006 if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
4012 /* Here if a %{|...} conditional fails: output a minus sign,
4013 which means "standard output" or "standard input". */
4014 do_spec_1 ("-", 0, NULL_PTR);
4021 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4022 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4023 spec, or -1 if either exact match or %* is used.
4025 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4026 whose value does not begin with "no-" is obsoleted by the same value
4027 with the "no-", similarly for a switch with the "no-" prefix. */
4030 check_live_switch (switchnum, prefix_length)
4034 char *name = switches[switchnum].part1;
4037 /* In the common case of {<at-most-one-letter>*}, a negating
4038 switch would always match, so ignore that case. We will just
4039 send the conflicting switches to the compiler phase. */
4040 if (prefix_length >= 0 && prefix_length <= 1)
4043 /* If we already processed this switch and determined if it was
4044 live or not, return our past determination. */
4045 if (switches[switchnum].live_cond != 0)
4046 return switches[switchnum].live_cond > 0;
4048 /* Now search for duplicate in a manner that depends on the name. */
4052 for (i = switchnum + 1; i < n_switches; i++)
4053 if (switches[i].part1[0] == 'O')
4055 switches[switchnum].valid = 1;
4056 switches[switchnum].live_cond = -1;
4061 case 'W': case 'f': case 'm':
4062 if (! strncmp (name + 1, "no-", 3))
4064 /* We have Xno-YYY, search for XYYY. */
4065 for (i = switchnum + 1; i < n_switches; i++)
4066 if (switches[i].part1[0] == name[0]
4067 && ! strcmp (&switches[i].part1[1], &name[4]))
4069 switches[switchnum].valid = 1;
4070 switches[switchnum].live_cond = -1;
4076 /* We have XYYY, search for Xno-YYY. */
4077 for (i = switchnum + 1; i < n_switches; i++)
4078 if (switches[i].part1[0] == name[0]
4079 && switches[i].part1[1] == 'n'
4080 && switches[i].part1[2] == 'o'
4081 && switches[i].part1[3] == '-'
4082 && !strcmp (&switches[i].part1[4], &name[1]))
4084 switches[switchnum].valid = 1;
4085 switches[switchnum].live_cond = -1;
4092 /* Otherwise the switch is live. */
4093 switches[switchnum].live_cond = 1;
4097 /* Pass a switch to the current accumulating command
4098 in the same form that we received it.
4099 SWITCHNUM identifies the switch; it is an index into
4100 the vector of switches gcc received, which is `switches'.
4101 This cannot fail since it never finishes a command line.
4103 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
4106 give_switch (switchnum, omit_first_word)
4108 int omit_first_word;
4110 if (!omit_first_word)
4112 do_spec_1 ("-", 0, NULL_PTR);
4113 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
4115 do_spec_1 (" ", 0, NULL_PTR);
4116 if (switches[switchnum].args != 0)
4119 for (p = switches[switchnum].args; *p; p++)
4121 do_spec_1 (*p, 1, NULL_PTR);
4122 do_spec_1 (" ", 0, NULL_PTR);
4125 switches[switchnum].valid = 1;
4128 /* Search for a file named NAME trying various prefixes including the
4129 user's -B prefix and some standard ones.
4130 Return the absolute file name found. If nothing is found, return NAME. */
4138 /* Try multilib_dir if it is defined. */
4139 if (multilib_dir != NULL)
4143 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
4144 strcpy (try, multilib_dir);
4145 strcat (try, dir_separator_str);
4148 newname = find_a_file (&startfile_prefixes, try, R_OK);
4150 /* If we don't find it in the multi library dir, then fall
4151 through and look for it in the normal places. */
4152 if (newname != NULL)
4156 newname = find_a_file (&startfile_prefixes, name, R_OK);
4157 return newname ? newname : name;
4160 /* Determine whether a directory exists. If LINKER, return 0 for
4161 certain fixed names not needed by the linker. If not LINKER, it is
4162 only important to return 0 if the host machine has a small ARG_MAX
4166 is_directory (path1, path2, linker)
4171 int len1 = strlen (path1);
4172 int len2 = strlen (path2);
4173 char *path = (char *) alloca (3 + len1 + len2);
4177 #ifndef SMALL_ARG_MAX
4182 /* Construct the path from the two parts. Ensure the string ends with "/.".
4183 The resulting path will be a directory even if the given path is a
4185 bcopy (path1, path, len1);
4186 bcopy (path2, path + len1, len2);
4187 cp = path + len1 + len2;
4188 if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
4189 *cp++ = DIR_SEPARATOR;
4193 /* Exclude directories that the linker is known to search. */
4196 && strcmp (path, concat4 (dir_separator_str, "lib",
4197 dir_separator_str, ".")) == 0)
4199 && strcmp (path, concat6 (dir_separator_str, "usr",
4200 dir_separator_str, "lib",
4201 dir_separator_str, ".")) == 0)))
4204 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
4207 /* On fatal signals, delete all the temporary files. */
4210 fatal_error (signum)
4213 signal (signum, SIG_DFL);
4214 delete_failure_queue ();
4215 delete_temp_files ();
4216 /* Get the same signal again, this time not handled,
4217 so its normal effect occurs. */
4218 kill (getpid (), signum);
4229 int linker_was_run = 0;
4230 char *explicit_link_files;
4234 p = argv[0] + strlen (argv[0]);
4235 while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
4238 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
4239 signal (SIGINT, fatal_error);
4241 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
4242 signal (SIGHUP, fatal_error);
4244 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
4245 signal (SIGTERM, fatal_error);
4247 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
4248 signal (SIGPIPE, fatal_error);
4252 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
4254 obstack_init (&obstack);
4256 /* Set up to remember the pathname of gcc and any options
4257 needed for collect. We use argv[0] instead of programname because
4258 we need the complete pathname. */
4259 obstack_init (&collect_obstack);
4260 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4261 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
4262 putenv (obstack_finish (&collect_obstack));
4264 /* Choose directory for temp files. */
4266 choose_temp_base ();
4268 /* Make a table of what switches there are (switches, n_switches).
4269 Make a table of specified input files (infiles, n_infiles).
4270 Decode switches that are handled locally. */
4272 process_command (argc, argv);
4274 /* Initialize the vector of specs to just the default.
4275 This means one element containing 0s, as a terminator. */
4277 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
4278 bcopy ((char *) default_compilers, (char *) compilers,
4279 sizeof default_compilers);
4280 n_compilers = n_default_compilers;
4282 /* Read specs from a file if there is one. */
4284 machine_suffix = concat4 (spec_machine, dir_separator_str,
4285 spec_version, dir_separator_str);
4286 just_machine_suffix = concat (spec_machine, dir_separator_str);
4288 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
4289 /* Read the specs file unless it is a default one. */
4290 if (specs_file != 0 && strcmp (specs_file, "specs"))
4291 read_specs (specs_file);
4293 /* If not cross-compiling, look for startfiles in the standard places. */
4294 /* The fact that these are done here, after reading the specs file,
4295 means that it cannot be found in these directories.
4296 But that's okay. It should never be there anyway. */
4299 #ifdef MD_EXEC_PREFIX
4300 add_prefix (&exec_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4301 add_prefix (&startfile_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
4304 #ifdef MD_STARTFILE_PREFIX
4305 add_prefix (&startfile_prefixes, md_startfile_prefix, 0, 0, NULL_PTR);
4308 #ifdef MD_STARTFILE_PREFIX_1
4309 add_prefix (&startfile_prefixes, md_startfile_prefix_1, 0, 0, NULL_PTR);
4312 /* If standard_startfile_prefix is relative, base it on
4313 standard_exec_prefix. This lets us move the installed tree
4314 as a unit. If GCC_EXEC_PREFIX is defined, base
4315 standard_startfile_prefix on that as well. */
4316 if (*standard_startfile_prefix == '/'
4317 || *standard_startfile_prefix == DIR_SEPARATOR)
4318 add_prefix (&startfile_prefixes, standard_startfile_prefix, 0, 0,
4322 if (gcc_exec_prefix)
4323 add_prefix (&startfile_prefixes,
4324 concat (gcc_exec_prefix, standard_startfile_prefix),
4326 add_prefix (&startfile_prefixes,
4327 concat3 (standard_exec_prefix,
4329 standard_startfile_prefix),
4333 add_prefix (&startfile_prefixes, standard_startfile_prefix_1, 0, 0,
4335 add_prefix (&startfile_prefixes, standard_startfile_prefix_2, 0, 0,
4337 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4338 add_prefix (&startfile_prefixes, "./", 0, 1, NULL_PTR);
4342 /* Now we have the specs.
4343 Set the `valid' bits for switches that match anything in any spec. */
4345 validate_all_switches ();
4347 /* Now that we have the switches and the specs, set
4348 the subdirectory based on the options. */
4349 set_multilib_dir ();
4351 /* Warn about any switches that no pass was interested in. */
4353 for (i = 0; i < n_switches; i++)
4354 if (! switches[i].valid)
4355 error ("unrecognized option `-%s'", switches[i].part1);
4357 /* Obey some of the options. */
4359 if (print_file_name)
4361 printf ("%s\n", find_file (print_file_name));
4365 if (print_prog_name)
4367 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
4368 printf ("%s\n", (newname ? newname : print_prog_name));
4372 if (print_multi_lib)
4374 print_multilib_info ();
4378 if (print_multi_directory)
4380 if (multilib_dir == NULL)
4383 printf ("%s\n", multilib_dir);
4389 if (! strcmp (version_string, compiler_version))
4390 fprintf (stderr, "gcc version %s\n", version_string);
4392 fprintf (stderr, "gcc driver version %s executing gcc version %s\n",
4393 version_string, compiler_version);
4400 fatal ("No input files");
4402 /* Make a place to record the compiler output file names
4403 that correspond to the input files. */
4405 outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
4406 bzero ((char *) outfiles, n_infiles * sizeof (char *));
4408 /* Record which files were specified explicitly as link input. */
4410 explicit_link_files = xmalloc (n_infiles);
4411 bzero (explicit_link_files, n_infiles);
4413 for (i = 0; i < n_infiles; i++)
4415 register struct compiler *cp = 0;
4416 int this_file_error = 0;
4418 /* Tell do_spec what to substitute for %i. */
4420 input_filename = infiles[i].name;
4421 input_filename_length = strlen (input_filename);
4422 input_file_number = i;
4424 /* Use the same thing in %o, unless cp->spec says otherwise. */
4426 outfiles[i] = input_filename;
4428 /* Figure out which compiler from the file's suffix. */
4430 cp = lookup_compiler (infiles[i].name, input_filename_length,
4431 infiles[i].language);
4435 /* Ok, we found an applicable compiler. Run its spec. */
4436 /* First say how much of input_filename to substitute for %b */
4440 input_basename = input_filename;
4441 for (p = input_filename; *p; p++)
4442 if (*p == '/' || *p == DIR_SEPARATOR)
4443 input_basename = p + 1;
4445 /* Find a suffix starting with the last period,
4446 and set basename_length to exclude that suffix. */
4447 basename_length = strlen (input_basename);
4448 p = input_basename + basename_length;
4449 while (p != input_basename && *p != '.') --p;
4450 if (*p == '.' && p != input_basename)
4452 basename_length = p - input_basename;
4453 input_suffix = p + 1;
4459 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4461 len += strlen (cp->spec[j]);
4463 p = (char *) xmalloc (len + 1);
4466 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
4469 strcpy (p + len, cp->spec[j]);
4470 len += strlen (cp->spec[j]);
4473 value = do_spec (p);
4476 this_file_error = 1;
4479 /* If this file's name does not contain a recognized suffix,
4480 record it as explicit linker input. */
4483 explicit_link_files[i] = 1;
4485 /* Clear the delete-on-failure queue, deleting the files in it
4486 if this compilation failed. */
4488 if (this_file_error)
4490 delete_failure_queue ();
4493 /* If this compilation succeeded, don't delete those files later. */
4494 clear_failure_queue ();
4497 /* Run ld to link all the compiler output files. */
4499 if (error_count == 0)
4501 int tmp = execution_count;
4505 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4507 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
4508 putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
4510 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4512 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4513 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4516 for (i = 0; i < n_switches; i++)
4520 obstack_grow (&collect_obstack, " ", 1);
4523 obstack_grow (&collect_obstack, "-", 1);
4524 obstack_grow (&collect_obstack, switches[i].part1,
4525 strlen (switches[i].part1));
4527 for (args = switches[i].args; args && *args; args++)
4529 obstack_grow (&collect_obstack, " ", 1);
4530 obstack_grow (&collect_obstack, *args, strlen (*args));
4533 obstack_grow (&collect_obstack, "\0", 1);
4534 putenv (obstack_finish (&collect_obstack));
4536 value = do_spec (link_command_spec);
4539 linker_was_run = (tmp != execution_count);
4542 /* Warn if a -B option was specified but the prefix was never used. */
4543 unused_prefix_warnings (&exec_prefixes);
4544 unused_prefix_warnings (&startfile_prefixes);
4546 /* If options said don't run linker,
4547 complain about input files to be given to the linker. */
4549 if (! linker_was_run && error_count == 0)
4550 for (i = 0; i < n_infiles; i++)
4551 if (explicit_link_files[i])
4552 error ("%s: linker input file unused since linking not done",
4555 /* Delete some or all of the temporary files we made. */
4558 delete_failure_queue ();
4559 delete_temp_files ();
4561 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
4566 /* Find the proper compilation spec for the file name NAME,
4567 whose length is LENGTH. LANGUAGE is the specified language,
4568 or 0 if none specified. */
4570 static struct compiler *
4571 lookup_compiler (name, length, language)
4576 struct compiler *cp;
4578 /* Look for the language, if one is spec'd. */
4581 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4585 if (cp->suffix[0] == '@'
4586 && !strcmp (cp->suffix + 1, language))
4590 error ("language %s not recognized", language);
4593 /* Look for a suffix. */
4594 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
4596 if (/* The suffix `-' matches only the file name `-'. */
4597 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
4599 (strlen (cp->suffix) < length
4600 /* See if the suffix matches the end of NAME. */
4602 && (!strcmp (cp->suffix,
4603 name + length - strlen (cp->suffix))
4604 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4605 && !strcasecmp (cp->suffix,
4606 name + length - strlen (cp->suffix)))))
4608 && !strcmp (cp->suffix,
4609 name + length - strlen (cp->suffix))))
4612 if (cp->spec[0][0] == '@')
4614 struct compiler *new;
4615 /* An alias entry maps a suffix to a language.
4616 Search for the language; pass 0 for NAME and LENGTH
4617 to avoid infinite recursion if language not found.
4618 Construct the new compiler spec. */
4619 language = cp->spec[0] + 1;
4620 new = (struct compiler *) xmalloc (sizeof (struct compiler));
4621 new->suffix = cp->suffix;
4622 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
4623 (char *) new->spec, sizeof new->spec);
4626 /* A non-alias entry: return it. */
4638 register char *value = (char *) malloc (size);
4640 fatal ("virtual memory exhausted");
4645 xrealloc (ptr, size)
4649 register char *value = (char *) realloc (ptr, size);
4651 fatal ("virtual memory exhausted");
4655 /* Return a newly-allocated string whose contents concatenate those of s1, s2 */
4661 int len1 = strlen (s1);
4662 int len2 = strlen (s2);
4663 char *result = xmalloc (len1 + len2 + 1);
4665 strcpy (result, s1);
4666 strcpy (result + len1, s2);
4667 *(result + len1 + len2) = 0;
4673 concat3 (s1, s2, s3)
4676 return concat (concat (s1, s2), s3);
4680 concat4 (s1, s2, s3, s4)
4681 char *s1, *s2, *s3, *s4;
4683 return concat (concat (s1, s2), concat (s3, s4));
4687 concat6 (s1, s2, s3, s4, s5, s6)
4688 char *s1, *s2, *s3, *s4, *s5, *s6;
4690 return concat3 (concat (s1, s2), concat (s3, s4), concat (s5, s6));
4694 save_string (s, len)
4698 register char *result = xmalloc (len + 1);
4700 bcopy (s, result, len);
4706 pfatal_with_name (name)
4711 if (errno < sys_nerr)
4712 s = concat ("%s: ", sys_errlist[errno]);
4714 s = "cannot open %s";
4719 perror_with_name (name)
4724 if (errno < sys_nerr)
4725 s = concat ("%s: ", sys_errlist[errno]);
4727 s = "cannot open %s";
4737 if (errno < sys_nerr)
4738 s = concat ("installation problem, cannot exec %s: ", sys_errlist[errno]);
4740 s = "installation problem, cannot exec %s";
4744 /* More 'friendly' abort that prints the line and file.
4745 config.h can #define abort fancy_abort if you like that sort of thing. */
4750 fatal ("Internal gcc abort.");
4755 /* Output an error message and exit */
4758 fatal VPROTO((char *format, ...))
4765 VA_START (ap, format);
4768 format = va_arg (ap, char*);
4771 fprintf (stderr, "%s: ", programname);
4772 vfprintf (stderr, format, ap);
4774 fprintf (stderr, "\n");
4775 delete_temp_files ();
4780 error VPROTO((char *format, ...))
4787 VA_START (ap, format);
4790 format = va_arg (ap, char*);
4793 fprintf (stderr, "%s: ", programname);
4794 vfprintf (stderr, format, ap);
4797 fprintf (stderr, "\n");
4800 #else /* not HAVE_VPRINTF */
4803 fatal (msg, arg1, arg2)
4804 char *msg, *arg1, *arg2;
4806 error (msg, arg1, arg2);
4807 delete_temp_files ();
4812 error (msg, arg1, arg2)
4813 char *msg, *arg1, *arg2;
4815 fprintf (stderr, "%s: ", programname);
4816 fprintf (stderr, msg, arg1, arg2);
4817 fprintf (stderr, "\n");
4820 #endif /* not HAVE_VPRINTF */
4824 validate_all_switches ()
4826 struct compiler *comp;
4829 struct spec_list *spec;
4831 for (comp = compilers; comp->spec[0]; comp++)
4834 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
4838 if (c == '%' && *p == '{')
4839 /* We have a switch spec. */
4840 validate_switches (p + 1);
4844 /* look through the linked list of extra specs read from the specs file */
4845 for (spec = specs; spec ; spec = spec->next)
4849 if (c == '%' && *p == '{')
4850 /* We have a switch spec. */
4851 validate_switches (p + 1);
4854 p = link_command_spec;
4856 if (c == '%' && *p == '{')
4857 /* We have a switch spec. */
4858 validate_switches (p + 1);
4860 /* Now notice switches mentioned in the machine-specific specs. */
4864 if (c == '%' && *p == '{')
4865 /* We have a switch spec. */
4866 validate_switches (p + 1);
4870 if (c == '%' && *p == '{')
4871 /* We have a switch spec. */
4872 validate_switches (p + 1);
4876 if (c == '%' && *p == '{')
4877 /* We have a switch spec. */
4878 validate_switches (p + 1);
4880 p = signed_char_spec;
4882 if (c == '%' && *p == '{')
4883 /* We have a switch spec. */
4884 validate_switches (p + 1);
4888 if (c == '%' && *p == '{')
4889 /* We have a switch spec. */
4890 validate_switches (p + 1);
4894 if (c == '%' && *p == '{')
4895 /* We have a switch spec. */
4896 validate_switches (p + 1);
4900 if (c == '%' && *p == '{')
4901 /* We have a switch spec. */
4902 validate_switches (p + 1);
4906 if (c == '%' && *p == '{')
4907 /* We have a switch spec. */
4908 validate_switches (p + 1);
4912 if (c == '%' && *p == '{')
4913 /* We have a switch spec. */
4914 validate_switches (p + 1);
4918 if (c == '%' && *p == '{')
4919 /* We have a switch spec. */
4920 validate_switches (p + 1);
4923 /* Look at the switch-name that comes after START
4924 and mark as valid all supplied switches that match it. */
4927 validate_switches (start)
4930 register char *p = start;
4945 while (*p != ':' && *p != '}') p++;
4949 else if (p[-1] == '*')
4951 /* Mark all matching switches as valid. */
4953 for (i = 0; i < n_switches; i++)
4954 if (!strncmp (switches[i].part1, filter, p - filter))
4955 switches[i].valid = 1;
4959 /* Mark an exact matching switch as valid. */
4960 for (i = 0; i < n_switches; i++)
4962 if (!strncmp (switches[i].part1, filter, p - filter)
4963 && switches[i].part1[p - filter] == 0)
4964 switches[i].valid = 1;
4969 /* Check whether a particular argument was used. */
4978 for (i = 0; i < n_switches; i++)
4979 if (! strncmp (switches[i].part1, p, len)
4980 && strlen (switches[i].part1) == len)
4985 /* Work out the subdirectory to use based on the
4986 options. The format of multilib_select is a list of elements.
4987 Each element is a subdirectory name followed by a list of options
4988 followed by a semicolon. gcc will consider each line in turn. If
4989 none of the options beginning with an exclamation point are
4990 present, and all of the other options are present, that
4991 subdirectory will be used. */
4996 char *p = multilib_select;
4998 char *this_path, *this_arg;
5003 /* Ignore newlines. */
5010 /* Get the initial path. */
5018 this_path_len = p - this_path;
5020 /* Check the arguments. */
5035 while (*p != ' ' && *p != ';')
5042 if (*this_arg == '!')
5043 failed = used_arg (this_arg + 1, p - (this_arg + 1));
5045 failed = ! used_arg (this_arg, p - this_arg);
5053 if (this_path_len != 1
5054 || this_path[0] != '.')
5056 multilib_dir = xmalloc (this_path_len + 1);
5057 strncpy (multilib_dir, this_path, this_path_len);
5058 multilib_dir[this_path_len] = '\0';
5067 /* Print out the multiple library subdirectory selection
5068 information. This prints out a series of lines. Each line looks
5069 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5070 required. Only the desired options are printed out, the negative
5071 matches. The options are print without a leading dash. There are
5072 no spaces to make it easy to use the information in the shell.
5073 Each subdirectory is printed only once. This assumes the ordering
5074 generated by the genmultilib script. */
5077 print_multilib_info ()
5079 char *p = multilib_select;
5080 char *last_path, *this_path;
5082 int last_path_len = 0;
5086 /* Ignore newlines. */
5093 /* Get the initial path. */
5102 /* If this is a duplicate, skip it. */
5103 skip = (p - this_path == last_path_len
5104 && ! strncmp (last_path, this_path, last_path_len));
5106 last_path = this_path;
5107 last_path_len = p - this_path;
5113 for (p1 = last_path; p1 < p; p1++)
5132 use_arg = *p != '!';
5137 while (*p != ' ' && *p != ';')