1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 This paragraph is here to try to keep Sun CC from dying.
21 The number of chars here seems crucial!!!! */
23 /* This program is the user interface to the C compiler and possibly to
24 other compilers. It is used because compilation is a complicated procedure
25 which involves running several programs and passing temporary files between
26 them, forwarding the users switches to those programs selectively,
27 and deleting the temporary files at the end.
29 CC recognizes how to compile each input file by suffixes in the file names.
30 Once it knows which kind of compilation to perform, the procedure for
31 compilation is specified by a string called a "spec". */
33 #include <sys/types.h>
40 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
54 /* Include multi-lib information. */
64 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
67 #define WTERMSIG(S) ((S) & 0x7f)
70 #define WIFEXITED(S) (((S) & 0xff) == 0)
73 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
76 /* Add prototype support. */
78 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
79 #define PROTO(ARGS) ARGS
81 #define PROTO(ARGS) ()
87 #define PVPROTO(ARGS) ARGS
88 #define VPROTO(ARGS) ARGS
89 #define VA_START(va_list,var) va_start(va_list,var)
91 #define PVPROTO(ARGS) ()
92 #define VPROTO(ARGS) (va_alist) va_dcl
93 #define VA_START(va_list,var) va_start(va_list)
97 /* Define a generic NULL if one hasn't already been defined. */
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. */
2284 for (i
= 0; i
< n_commands
; i
++)
2288 char *prog
= "unknown";
2291 status
= pid
= commands
[i
].pid
;
2294 pid
= cwait (&status
, commands
[i
].pid
, WAIT_CHILD
);
2296 pid
= wait (&status
);
2305 for (j
= 0; j
< n_commands
; j
++)
2306 if (commands
[j
].pid
== pid
)
2307 prog
= commands
[j
].prog
;
2309 if (WIFSIGNALED (status
))
2311 fatal ("Internal compiler error: program %s got fatal signal %d",
2312 prog
, WTERMSIG (status
));
2316 else if (WIFEXITED (status
)
2317 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2325 /* Find all the switches given to us
2326 and make a vector describing them.
2327 The elements of the vector are strings, one per switch given.
2328 If a switch uses following arguments, then the `part1' field
2329 is the switch itself and the `args' field
2330 is a null-terminated vector containing the following arguments.
2331 The `live_cond' field is 1 if the switch is true in a conditional spec,
2332 -1 if false (overridden by a later switch), and is initialized to zero.
2333 The `valid' field is nonzero if any spec has looked at this switch;
2334 if it remains zero at the end of the run, it must be meaningless. */
2344 static struct switchstr
*switches
;
2346 static int n_switches
;
2354 /* Also a vector of input files specified. */
2356 static struct infile
*infiles
;
2358 static int n_infiles
;
2360 /* And a vector of corresponding output files is made up later. */
2362 static char **outfiles
;
2364 /* Create the vector `switches' and its contents.
2365 Store its length in `n_switches'. */
2368 process_command (argc
, argv
)
2374 char *spec_lang
= 0;
2375 int last_language_n_infiles
;
2377 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2382 /* Figure compiler version from version string. */
2384 compiler_version
= save_string (version_string
, strlen (version_string
));
2385 for (temp
= compiler_version
; *temp
; ++temp
)
2394 /* Set up the default search paths. */
2396 if (gcc_exec_prefix
)
2398 add_prefix (&exec_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2399 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2402 /* COMPILER_PATH and LIBRARY_PATH have values
2403 that are lists of directory names with colons. */
2405 temp
= getenv ("COMPILER_PATH");
2408 char *startp
, *endp
;
2409 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2411 startp
= endp
= temp
;
2414 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2416 strncpy (nstore
, startp
, endp
-startp
);
2418 strcpy (nstore
, concat (".", dir_separator_str
));
2419 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2421 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2422 nstore
[endp
-startp
+1] = 0;
2425 nstore
[endp
-startp
] = 0;
2426 add_prefix (&exec_prefixes
, nstore
, 0, 0, NULL_PTR
);
2429 endp
= startp
= endp
+ 1;
2436 temp
= getenv ("LIBRARY_PATH");
2437 if (temp
&& ! cross_compile
)
2439 char *startp
, *endp
;
2440 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2442 startp
= endp
= temp
;
2445 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2447 strncpy (nstore
, startp
, endp
-startp
);
2449 strcpy (nstore
, concat (".", dir_separator_str
));
2450 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2452 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2453 nstore
[endp
-startp
+1] = 0;
2456 nstore
[endp
-startp
] = 0;
2457 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2460 endp
= startp
= endp
+ 1;
2467 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2468 temp
= getenv ("LPATH");
2469 if (temp
&& ! cross_compile
)
2471 char *startp
, *endp
;
2472 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2474 startp
= endp
= temp
;
2477 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2479 strncpy (nstore
, startp
, endp
-startp
);
2481 strcpy (nstore
, concat (".", dir_separator_str
));
2482 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2484 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2485 nstore
[endp
-startp
+1] = 0;
2488 nstore
[endp
-startp
] = 0;
2489 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2492 endp
= startp
= endp
+ 1;
2499 /* Convert new-style -- options to old-style. */
2500 translate_options (&argc
, &argv
);
2502 /* Scan argv twice. Here, the first time, just count how many switches
2503 there will be in their vector, and how many input files in theirs.
2504 Here we also parse the switches that cc itself uses (e.g. -v). */
2506 for (i
= 1; i
< argc
; i
++)
2508 if (! strcmp (argv
[i
], "-dumpspecs"))
2510 printf ("*asm:\n%s\n\n", asm_spec
);
2511 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
2512 printf ("*cpp:\n%s\n\n", cpp_spec
);
2513 printf ("*cc1:\n%s\n\n", cc1_spec
);
2514 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
2515 printf ("*endfile:\n%s\n\n", endfile_spec
);
2516 printf ("*link:\n%s\n\n", link_spec
);
2517 printf ("*lib:\n%s\n\n", lib_spec
);
2518 printf ("*libgcc:\n%s\n\n", libgcc_spec
);
2519 printf ("*startfile:\n%s\n\n", startfile_spec
);
2520 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
2521 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
2522 printf ("*predefines:\n%s\n\n", cpp_predefines
);
2523 printf ("*cross_compile:\n%d\n\n", cross_compile
);
2524 printf ("*multilib:\n%s\n\n", multilib_select
);
2528 else if (! strcmp (argv
[i
], "-dumpversion"))
2530 printf ("%s\n", version_string
);
2533 else if (! strcmp (argv
[i
], "-dumpmachine"))
2535 printf ("%s\n", spec_machine
);
2538 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2539 print_file_name
= "libgcc.a";
2540 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2541 print_file_name
= argv
[i
] + 17;
2542 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2543 print_prog_name
= argv
[i
] + 17;
2544 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2545 print_multi_lib
= 1;
2546 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2547 print_multi_directory
= 1;
2548 else if (! strncmp (argv
[i
], "-Wa,", 4))
2551 /* Pass the rest of this option to the assembler. */
2553 n_assembler_options
++;
2554 if (!assembler_options
)
2556 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2559 = (char **) xrealloc (assembler_options
,
2560 n_assembler_options
* sizeof (char **));
2562 /* Split the argument at commas. */
2564 for (j
= 4; argv
[i
][j
]; j
++)
2565 if (argv
[i
][j
] == ',')
2567 assembler_options
[n_assembler_options
- 1]
2568 = save_string (argv
[i
] + prev
, j
- prev
);
2569 n_assembler_options
++;
2571 = (char **) xrealloc (assembler_options
,
2572 n_assembler_options
* sizeof (char **));
2575 /* Record the part after the last comma. */
2576 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2578 else if (! strncmp (argv
[i
], "-Wp,", 4))
2581 /* Pass the rest of this option to the preprocessor. */
2583 n_preprocessor_options
++;
2584 if (!preprocessor_options
)
2585 preprocessor_options
2586 = (char **) xmalloc (n_preprocessor_options
* sizeof (char **));
2588 preprocessor_options
2589 = (char **) xrealloc (preprocessor_options
,
2590 n_preprocessor_options
* sizeof (char **));
2592 /* Split the argument at commas. */
2594 for (j
= 4; argv
[i
][j
]; j
++)
2595 if (argv
[i
][j
] == ',')
2597 preprocessor_options
[n_preprocessor_options
- 1]
2598 = save_string (argv
[i
] + prev
, j
- prev
);
2599 n_preprocessor_options
++;
2600 preprocessor_options
2601 = (char **) xrealloc (preprocessor_options
,
2602 n_preprocessor_options
* sizeof (char **));
2605 /* Record the part after the last comma. */
2606 preprocessor_options
[n_preprocessor_options
- 1] = argv
[i
] + prev
;
2608 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2609 /* The +e options to the C++ front-end. */
2611 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2614 /* Split the argument at commas. */
2615 for (j
= 3; argv
[i
][j
]; j
++)
2616 n_infiles
+= (argv
[i
][j
] == ',');
2618 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2621 fatal ("argument to `-Xlinker' is missing");
2626 else if (strncmp (argv
[i
], "-l", 2) == 0)
2628 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2630 register char *p
= &argv
[i
][1];
2631 register int c
= *p
;
2636 if (p
[1] == 0 && i
+ 1 == argc
)
2637 fatal ("argument to `-b' is missing");
2639 spec_machine
= argv
[++i
];
2641 spec_machine
= p
+ 1;
2646 int *temp
= (int *) xmalloc (sizeof (int));
2648 if (p
[1] == 0 && i
+ 1 == argc
)
2649 fatal ("argument to `-B' is missing");
2654 add_prefix (&exec_prefixes
, value
, 1, 0, temp
);
2655 add_prefix (&startfile_prefixes
, value
, 1, 0, temp
);
2656 add_prefix (&include_prefixes
, concat (value
, "include"),
2659 /* As a kludge, if the arg is "[foo/]stageN/", just add
2660 "[foo/]include" to the include prefix. */
2662 int len
= strlen (value
);
2665 && (value
[len
- 8] == '/'
2666 || value
[len
- 8] == DIR_SEPARATOR
)))
2667 && strncmp (value
+ len
- 7, "stage", 5) == 0
2668 && isdigit (value
[len
- 2])
2669 && (value
[len
- 1] == '/'
2670 || value
[len
- 1] == DIR_SEPARATOR
))
2673 add_prefix (&include_prefixes
, "include", 1, 0, 0);
2676 char *string
= xmalloc (len
+ 1);
2677 strncpy (string
, value
, len
-7);
2678 strcat (string
, "include");
2679 add_prefix (&include_prefixes
, string
, 1, 0, 0);
2686 case 'v': /* Print our subcommands and print versions. */
2688 /* If they do anything other than exactly `-v', don't set
2689 verbose_flag; rather, continue on to give the error. */
2696 if (p
[1] == 0 && i
+ 1 == argc
)
2697 fatal ("argument to `-V' is missing");
2699 spec_version
= argv
[++i
];
2701 spec_version
= p
+ 1;
2702 compiler_version
= spec_version
;
2706 if (!strcmp (p
, "save-temps"))
2708 save_temps_flag
= 1;
2715 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2716 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2717 else if (WORD_SWITCH_TAKES_ARG (p
))
2718 i
+= WORD_SWITCH_TAKES_ARG (p
);
2725 /* Set up the search paths before we go looking for config files. */
2727 /* These come before the md prefixes so that we will find gcc's subcommands
2728 (such as cpp) rather than those of the host system. */
2729 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2730 as well as trying the machine and the version. */
2732 add_prefix (&exec_prefixes
, standard_exec_prefix
, 0, 2, NULL_PTR
);
2733 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, 0, 2, NULL_PTR
);
2736 add_prefix (&startfile_prefixes
, standard_exec_prefix
, 0, 1, NULL_PTR
);
2737 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, 0, 1, NULL_PTR
);
2739 tooldir_prefix
= concat3 (tooldir_base_prefix
, spec_machine
,
2742 /* If tooldir is relative, base it on exec_prefixes. A relative
2743 tooldir lets us move the installed tree as a unit.
2745 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2746 directories, so that we can search both the user specified directory
2747 and the standard place. */
2749 if (*tooldir_prefix
!= '/' && *tooldir_prefix
!= DIR_SEPARATOR
)
2751 if (gcc_exec_prefix
)
2753 char *gcc_exec_tooldir_prefix
2754 = concat6 (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
2755 spec_version
, dir_separator_str
, tooldir_prefix
);
2757 add_prefix (&exec_prefixes
,
2758 concat3 (gcc_exec_tooldir_prefix
, "bin",
2761 add_prefix (&startfile_prefixes
,
2762 concat3 (gcc_exec_tooldir_prefix
, "lib",
2767 tooldir_prefix
= concat6 (standard_exec_prefix
, spec_machine
,
2768 dir_separator_str
, spec_version
,
2769 dir_separator_str
, tooldir_prefix
);
2772 add_prefix (&exec_prefixes
,
2773 concat3 (tooldir_prefix
, "bin", dir_separator_str
),
2775 add_prefix (&startfile_prefixes
,
2776 concat3 (tooldir_prefix
, "lib", dir_separator_str
),
2779 /* More prefixes are enabled in main, after we read the specs file
2780 and determine whether this is cross-compilation or not. */
2783 /* Then create the space for the vectors and scan again. */
2785 switches
= ((struct switchstr
*)
2786 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2787 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2790 last_language_n_infiles
= -1;
2792 /* This, time, copy the text of each switch and store a pointer
2793 to the copy in the vector of switches.
2794 Store all the infiles in their vector. */
2796 for (i
= 1; i
< argc
; i
++)
2798 /* Just skip the switches that were handled by the preceding loop. */
2799 if (! strncmp (argv
[i
], "-Wa,", 4))
2801 else if (! strncmp (argv
[i
], "-Wp,", 4))
2803 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2805 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2807 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2809 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2811 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2813 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2815 /* Compensate for the +e options to the C++ front-end;
2816 they're there simply for cfront call-compatibility. We do
2817 some magic in default_compilers to pass them down properly.
2818 Note we deliberately start at the `+' here, to avoid passing
2819 -e0 or -e1 down into the linker. */
2820 switches
[n_switches
].part1
= &argv
[i
][0];
2821 switches
[n_switches
].args
= 0;
2822 switches
[n_switches
].live_cond
= 0;
2823 switches
[n_switches
].valid
= 0;
2826 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2829 /* Split the argument at commas. */
2831 for (j
= 4; argv
[i
][j
]; j
++)
2832 if (argv
[i
][j
] == ',')
2834 infiles
[n_infiles
].language
= spec_lang
;
2835 infiles
[n_infiles
++].name
2836 = save_string (argv
[i
] + prev
, j
- prev
);
2839 /* Record the part after the last comma. */
2840 infiles
[n_infiles
].language
= spec_lang
;
2841 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
2843 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2845 infiles
[n_infiles
].language
= spec_lang
;
2846 infiles
[n_infiles
++].name
= argv
[++i
];
2848 else if (strncmp (argv
[i
], "-l", 2) == 0)
2850 infiles
[n_infiles
].language
= spec_lang
;
2851 infiles
[n_infiles
++].name
= argv
[i
];
2853 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2855 register char *p
= &argv
[i
][1];
2856 register int c
= *p
;
2858 if (c
== 'B' || c
== 'b' || c
== 'V')
2860 /* Skip a separate arg, if any. */
2867 if (p
[1] == 0 && i
+ 1 == argc
)
2868 fatal ("argument to `-x' is missing");
2870 spec_lang
= argv
[++i
];
2873 if (! strcmp (spec_lang
, "none"))
2874 /* Suppress the warning if -xnone comes after the last input file,
2875 because alternate command interfaces like g++ might find it
2876 useful to place -xnone after each input file. */
2879 last_language_n_infiles
= n_infiles
;
2882 switches
[n_switches
].part1
= p
;
2883 /* Deal with option arguments in separate argv elements. */
2884 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2885 || WORD_SWITCH_TAKES_ARG (p
))
2888 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2892 /* Count only the option arguments in separate argv elements. */
2893 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2895 if (i
+ n_args
>= argc
)
2896 fatal ("argument to `-%s' is missing", p
);
2897 switches
[n_switches
].args
2898 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2900 switches
[n_switches
].args
[j
++] = argv
[++i
];
2901 /* Null-terminate the vector. */
2902 switches
[n_switches
].args
[j
] = 0;
2904 else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L'))
2906 /* On some systems, ld cannot handle -o or -L without space.
2907 So split the -o or -L from its argument. */
2908 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2909 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2910 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2911 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2912 switches
[n_switches
].args
[1] = 0;
2915 switches
[n_switches
].args
= 0;
2917 switches
[n_switches
].live_cond
= 0;
2918 switches
[n_switches
].valid
= 0;
2919 /* This is always valid, since gcc.c itself understands it. */
2920 if (!strcmp (p
, "save-temps"))
2921 switches
[n_switches
].valid
= 1;
2926 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], R_OK
) < 0)
2928 perror_with_name (argv
[i
]);
2933 infiles
[n_infiles
].language
= spec_lang
;
2934 infiles
[n_infiles
++].name
= argv
[i
];
2939 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
2940 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2942 switches
[n_switches
].part1
= 0;
2943 infiles
[n_infiles
].name
= 0;
2945 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2946 if (gcc_exec_prefix
)
2948 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2949 + strlen (spec_machine
) + 3);
2950 strcpy (temp
, gcc_exec_prefix
);
2951 strcat (temp
, spec_machine
);
2952 strcat (temp
, dir_separator_str
);
2953 strcat (temp
, spec_version
);
2954 strcat (temp
, dir_separator_str
);
2955 gcc_exec_prefix
= temp
;
2959 /* Process a spec string, accumulating and running commands. */
2961 /* These variables describe the input file name.
2962 input_file_number is the index on outfiles of this file,
2963 so that the output file name can be stored for later use by %o.
2964 input_basename is the start of the part of the input file
2965 sans all directory names, and basename_length is the number
2966 of characters starting there excluding the suffix .c or whatever. */
2968 static char *input_filename
;
2969 static int input_file_number
;
2970 static int input_filename_length
;
2971 static int basename_length
;
2972 static char *input_basename
;
2973 static char *input_suffix
;
2975 /* These are variables used within do_spec and do_spec_1. */
2977 /* Nonzero if an arg has been started and not yet terminated
2978 (with space, tab or newline). */
2979 static int arg_going
;
2981 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2982 is a temporary file name. */
2983 static int delete_this_arg
;
2985 /* Nonzero means %w has been seen; the next arg to be terminated
2986 is the output file name of this compilation. */
2987 static int this_is_output_file
;
2989 /* Nonzero means %s has been seen; the next arg to be terminated
2990 is the name of a library file and we should try the standard
2991 search dirs for it. */
2992 static int this_is_library_file
;
2994 /* Nonzero means that the input of this command is coming from a pipe. */
2995 static int input_from_pipe
;
2997 /* Process the spec SPEC and run the commands specified therein.
2998 Returns 0 if the spec is successfully processed; -1 if failed. */
3008 delete_this_arg
= 0;
3009 this_is_output_file
= 0;
3010 this_is_library_file
= 0;
3011 input_from_pipe
= 0;
3013 value
= do_spec_1 (spec
, 0, NULL_PTR
);
3015 /* Force out any unfinished command.
3016 If -pipe, this forces out the last command if it ended in `|'. */
3019 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3022 if (argbuf_index
> 0)
3029 /* Process the sub-spec SPEC as a portion of a larger spec.
3030 This is like processing a whole spec except that we do
3031 not initialize at the beginning and we do not supply a
3032 newline by default at the end.
3033 INSWITCH nonzero means don't process %-sequences in SPEC;
3034 in this case, % is treated as an ordinary character.
3035 This is used while substituting switches.
3036 INSWITCH nonzero also causes SPC not to terminate an argument.
3038 Value is zero unless a line was finished
3039 and the command on that line reported an error. */
3042 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3045 char *soft_matched_part
;
3047 register char *p
= spec
;
3054 /* If substituting a switch, treat all chars like letters.
3055 Otherwise, NL, SPC, TAB and % are special. */
3056 switch (inswitch
? 'a' : c
)
3059 /* End of line: finish any pending argument,
3060 then run the pending command if one has been started. */
3063 obstack_1grow (&obstack
, 0);
3064 string
= obstack_finish (&obstack
);
3065 if (this_is_library_file
)
3066 string
= find_file (string
);
3067 store_arg (string
, delete_this_arg
, this_is_output_file
);
3068 if (this_is_output_file
)
3069 outfiles
[input_file_number
] = string
;
3073 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3076 for (i
= 0; i
< n_switches
; i
++)
3077 if (!strcmp (switches
[i
].part1
, "pipe"))
3080 /* A `|' before the newline means use a pipe here,
3081 but only if -pipe was specified.
3082 Otherwise, execute now and don't pass the `|' as an arg. */
3085 input_from_pipe
= 1;
3086 switches
[i
].valid
= 1;
3093 if (argbuf_index
> 0)
3099 /* Reinitialize for a new command, and for a new argument. */
3102 delete_this_arg
= 0;
3103 this_is_output_file
= 0;
3104 this_is_library_file
= 0;
3105 input_from_pipe
= 0;
3109 /* End any pending argument. */
3112 obstack_1grow (&obstack
, 0);
3113 string
= obstack_finish (&obstack
);
3114 if (this_is_library_file
)
3115 string
= find_file (string
);
3116 store_arg (string
, delete_this_arg
, this_is_output_file
);
3117 if (this_is_output_file
)
3118 outfiles
[input_file_number
] = string
;
3122 obstack_1grow (&obstack
, c
);
3128 /* Space or tab ends an argument if one is pending. */
3131 obstack_1grow (&obstack
, 0);
3132 string
= obstack_finish (&obstack
);
3133 if (this_is_library_file
)
3134 string
= find_file (string
);
3135 store_arg (string
, delete_this_arg
, this_is_output_file
);
3136 if (this_is_output_file
)
3137 outfiles
[input_file_number
] = string
;
3139 /* Reinitialize for a new argument. */
3141 delete_this_arg
= 0;
3142 this_is_output_file
= 0;
3143 this_is_library_file
= 0;
3150 fatal ("Invalid specification! Bug in cc.");
3153 obstack_grow (&obstack
, input_basename
, basename_length
);
3158 delete_this_arg
= 2;
3161 /* Dump out the directories specified with LIBRARY_PATH,
3162 followed by the absolute directories
3163 that we search for startfiles. */
3166 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3168 char *buffer
= (char *) xmalloc (bufsize
);
3171 for (; pl
; pl
= pl
->next
)
3173 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3174 /* Used on systems which record the specified -L dirs
3175 and use them to search for dynamic linking. */
3176 /* Relative directories always come from -B,
3177 and it is better not to use them for searching
3178 at run time. In particular, stage1 loses */
3179 if (pl
->prefix
[0] != '/' && pl
->prefix
[0] != DIR_SEPARATOR
)
3182 /* Try subdirectory if there is one. */
3183 if (multilib_dir
!= NULL
)
3187 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3189 bufsize
= (strlen (pl
->prefix
)
3190 + strlen (machine_suffix
)) * 2 + 1;
3191 buffer
= (char *) xrealloc (buffer
, bufsize
);
3192 strcpy (buffer
, pl
->prefix
);
3193 strcat (buffer
, machine_suffix
);
3194 if (is_directory (buffer
, multilib_dir
, 1))
3196 do_spec_1 ("-L", 0, NULL_PTR
);
3197 #ifdef SPACE_AFTER_L_OPTION
3198 do_spec_1 (" ", 0, NULL_PTR
);
3200 do_spec_1 (buffer
, 1, NULL_PTR
);
3201 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3202 /* Make this a separate argument. */
3203 do_spec_1 (" ", 0, NULL_PTR
);
3206 if (!pl
->require_machine_suffix
)
3208 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3210 do_spec_1 ("-L", 0, NULL_PTR
);
3211 #ifdef SPACE_AFTER_L_OPTION
3212 do_spec_1 (" ", 0, NULL_PTR
);
3214 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3215 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3216 /* Make this a separate argument. */
3217 do_spec_1 (" ", 0, NULL_PTR
);
3223 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3225 do_spec_1 ("-L", 0, NULL_PTR
);
3226 #ifdef SPACE_AFTER_L_OPTION
3227 do_spec_1 (" ", 0, NULL_PTR
);
3229 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3230 /* Remove slash from machine_suffix. */
3231 if (strlen (machine_suffix
) >= bufsize
)
3232 bufsize
= strlen (machine_suffix
) * 2 + 1;
3233 buffer
= (char *) xrealloc (buffer
, bufsize
);
3234 strcpy (buffer
, machine_suffix
);
3235 idx
= strlen (buffer
);
3236 if (buffer
[idx
- 1] == '/'
3237 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3238 buffer
[idx
- 1] = 0;
3239 do_spec_1 (buffer
, 1, NULL_PTR
);
3240 /* Make this a separate argument. */
3241 do_spec_1 (" ", 0, NULL_PTR
);
3244 if (!pl
->require_machine_suffix
)
3246 if (is_directory (pl
->prefix
, "", 1))
3248 do_spec_1 ("-L", 0, NULL_PTR
);
3249 #ifdef SPACE_AFTER_L_OPTION
3250 do_spec_1 (" ", 0, NULL_PTR
);
3252 /* Remove slash from pl->prefix. */
3253 if (strlen (pl
->prefix
) >= bufsize
)
3254 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3255 buffer
= (char *) xrealloc (buffer
, bufsize
);
3256 strcpy (buffer
, pl
->prefix
);
3257 idx
= strlen (buffer
);
3258 if (buffer
[idx
- 1] == '/'
3259 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3260 buffer
[idx
- 1] = 0;
3261 do_spec_1 (buffer
, 1, NULL_PTR
);
3262 /* Make this a separate argument. */
3263 do_spec_1 (" ", 0, NULL_PTR
);
3272 /* {...:%efoo} means report an error with `foo' as error message
3273 and don't execute any more commands for this file. */
3277 while (*p
!= 0 && *p
!= '\n') p
++;
3278 buf
= (char *) alloca (p
- q
+ 1);
3279 strncpy (buf
, q
, p
- q
);
3289 if (save_temps_flag
)
3291 obstack_grow (&obstack
, input_basename
, basename_length
);
3292 delete_this_arg
= 0;
3296 #ifdef MKTEMP_EACH_FILE
3297 /* ??? This has a problem: the total number of
3298 values mktemp can return is limited.
3299 That matters for the names of object files.
3300 In 2.4, do something about that. */
3301 struct temp_name
*t
;
3303 while (*p
== '.' || isalpha (*p
))
3306 /* See if we already have an association of %g/%u/%U and
3308 for (t
= temp_names
; t
; t
= t
->next
)
3309 if (t
->length
== p
- suffix
3310 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3311 && t
->unique
== (c
!= 'g'))
3314 /* Make a new association if needed. %u requires one. */
3315 if (t
== 0 || c
== 'u')
3319 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3320 t
->next
= temp_names
;
3323 t
->length
= p
- suffix
;
3324 t
->suffix
= save_string (suffix
, p
- suffix
);
3325 t
->unique
= (c
!= 'g');
3326 choose_temp_base ();
3327 t
->filename
= temp_filename
;
3328 t
->filename_length
= temp_filename_length
;
3331 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3332 delete_this_arg
= 1;
3334 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3335 if (c
== 'u' || c
== 'U')
3341 sprintf (buff
, "%d", unique
);
3342 obstack_grow (&obstack
, buff
, strlen (buff
));
3345 delete_this_arg
= 1;
3351 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3357 struct prefix_list
*pl
= include_prefixes
.plist
;
3359 if (gcc_exec_prefix
)
3361 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3362 /* Make this a separate argument. */
3363 do_spec_1 (" ", 0, NULL_PTR
);
3364 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3365 do_spec_1 (" ", 0, NULL_PTR
);
3368 for (; pl
; pl
= pl
->next
)
3370 do_spec_1 ("-isystem", 1, NULL_PTR
);
3371 /* Make this a separate argument. */
3372 do_spec_1 (" ", 0, NULL_PTR
);
3373 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3374 do_spec_1 (" ", 0, NULL_PTR
);
3382 for (f
= 0; f
< n_infiles
; f
++)
3383 store_arg (outfiles
[f
], 0, 0);
3388 this_is_library_file
= 1;
3392 this_is_output_file
= 1;
3397 int index
= argbuf_index
;
3398 /* Handle the {...} following the %W. */
3401 p
= handle_braces (p
+ 1);
3404 /* If any args were output, mark the last one for deletion
3406 if (argbuf_index
!= index
)
3407 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3411 /* %x{OPTION} records OPTION for %X to output. */
3417 /* Skip past the option value and make a copy. */
3422 string
= save_string (p1
+ 1, p
- p1
- 2);
3424 /* See if we already recorded this option. */
3425 for (i
= 0; i
< n_linker_options
; i
++)
3426 if (! strcmp (string
, linker_options
[i
]))
3432 /* This option is new; add it. */
3434 if (!linker_options
)
3436 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3439 = (char **) xrealloc (linker_options
,
3440 n_linker_options
* sizeof (char **));
3442 linker_options
[n_linker_options
- 1] = string
;
3446 /* Dump out the options accumulated previously using %x. */
3448 for (i
= 0; i
< n_linker_options
; i
++)
3450 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3451 /* Make each accumulated option a separate argument. */
3452 do_spec_1 (" ", 0, NULL_PTR
);
3456 /* Dump out the options accumulated previously using -Wa,. */
3458 for (i
= 0; i
< n_assembler_options
; i
++)
3460 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3461 /* Make each accumulated option a separate argument. */
3462 do_spec_1 (" ", 0, NULL_PTR
);
3466 /* Dump out the options accumulated previously using -Wp,. */
3468 for (i
= 0; i
< n_preprocessor_options
; i
++)
3470 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3471 /* Make each accumulated option a separate argument. */
3472 do_spec_1 (" ", 0, NULL_PTR
);
3476 /* Here are digits and numbers that just process
3477 a certain constant string as a spec. */
3480 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3486 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3492 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3498 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3504 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3510 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3516 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3522 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3528 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3534 value
= do_spec_1 (libgcc_spec
, 0, NULL_PTR
);
3541 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3545 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3549 if (! strncmp (y
, "-D", 2))
3550 /* Copy the whole option. */
3551 while (*y
&& *y
!= ' ' && *y
!= '\t')
3553 else if (*y
== ' ' || *y
== '\t')
3554 /* Copy whitespace to the result. */
3556 /* Don't copy other options. */
3563 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3571 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3575 /* Copy all of CPP_PREDEFINES into BUF,
3576 but put __ after every -D and at the end of each arg. */
3580 if (! strncmp (y
, "-D", 2))
3588 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3590 /* Stick __ at front of macro name. */
3593 /* Arrange to stick __ at the end as well. */
3597 /* Copy the macro name. */
3598 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3607 /* Copy the value given, if any. */
3608 while (*y
&& *y
!= ' ' && *y
!= '\t')
3611 else if (*y
== ' ' || *y
== '\t')
3612 /* Copy whitespace to the result. */
3614 /* Don't copy -A options */
3620 /* Copy all of CPP_PREDEFINES into BUF,
3621 but put __ after every -D. */
3625 if (! strncmp (y
, "-D", 2))
3630 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3632 /* Stick -D__ at front of macro name. */
3638 /* Copy the macro name. */
3639 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3642 /* Copy the value given, if any. */
3643 while (*y
&& *y
!= ' ' && *y
!= '\t')
3648 /* Do not copy this macro - we have just done it before */
3649 while (*y
&& *y
!= ' ' && *y
!= '\t')
3653 else if (*y
== ' ' || *y
== '\t')
3654 /* Copy whitespace to the result. */
3656 /* Don't copy -A options */
3662 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3666 if (! strncmp (y
, "-A", 2))
3667 /* Copy the whole option. */
3668 while (*y
&& *y
!= ' ' && *y
!= '\t')
3670 else if (*y
== ' ' || *y
== '\t')
3671 /* Copy whitespace to the result. */
3673 /* Don't copy other options. */
3680 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3687 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3692 /* Here we define characters other than letters and digits. */
3695 p
= handle_braces (p
);
3701 obstack_1grow (&obstack
, '%');
3705 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3706 do_spec_1 (" ", 0, NULL_PTR
);
3709 /* Process a string found as the value of a spec given by name.
3710 This feature allows individual machine descriptions
3711 to add and use their own specs.
3712 %[...] modifies -D options the way %P does;
3713 %(...) uses the spec unmodified. */
3718 struct spec_list
*sl
;
3721 /* The string after the S/P is the name of a spec that is to be
3723 while (*p
&& *p
!= ')' && *p
!= ']')
3726 /* See if it's in the list */
3727 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3728 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
3738 value
= do_spec_1 (name
, 0, NULL_PTR
);
3744 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3748 /* Copy all of NAME into BUF, but put __ after
3749 every -D and at the end of each arg, */
3752 if (! strncmp (y
, "-D", 2))
3760 else if (*y
== ' ' || *y
== 0)
3774 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3780 /* Discard the closing paren or bracket. */
3788 int c1
= *p
++; /* Select first or second version number. */
3789 char *v
= compiler_version
;
3791 /* If desired, advance to second version number. */
3794 /* Set P after the first period. */
3795 while (*v
!= 0 && *v
!= ' ' && *v
!= '.')
3800 /* Set Q at the next period or at the end. */
3802 while (*q
!= 0 && *q
!= ' ' && *q
!= '.')
3804 /* Empty string means zero. */
3810 /* Put that part into the command. */
3811 obstack_grow (&obstack
, v
, q
- v
);
3817 if (input_from_pipe
)
3818 do_spec_1 ("-", 0, NULL_PTR
);
3827 /* Backslash: treat next character as ordinary. */
3832 /* Ordinary character: put it into the current argument. */
3833 obstack_1grow (&obstack
, c
);
3837 return 0; /* End of string */
3840 /* Return 0 if we call do_spec_1 and that returns -1. */
3853 /* A `|' after the open-brace means,
3854 if the test fails, output a single minus sign rather than nothing.
3855 This is used in %{|!pipe:...}. */
3859 /* A `!' after the open-brace negates the condition:
3860 succeed if the specified switch is not present. */
3864 /* A `.' after the open-brace means test against the current suffix. */
3874 while (*p
!= ':' && *p
!= '}') p
++;
3877 register int count
= 1;
3895 int found
= (input_suffix
!= 0
3896 && strlen (input_suffix
) == p
- filter
3897 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3903 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3908 else if (p
[-1] == '*' && p
[0] == '}')
3910 /* Substitute all matching switches as separate args. */
3913 for (i
= 0; i
< n_switches
; i
++)
3914 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3915 && check_live_switch (i
, p
- filter
))
3920 /* Test for presence of the specified switch. */
3924 /* If name specified ends in *, as in {x*:...},
3925 check for %* and handle that case. */
3926 if (p
[-1] == '*' && !negate
)
3931 /* First see whether we have %*. */
3935 if (*r
== '%' && r
[1] == '*')
3939 /* If we do, handle that case. */
3942 /* Substitute all matching switches as separate args.
3943 But do this by substituting for %*
3944 in the text that follows the colon. */
3946 unsigned hard_match_len
= p
- filter
- 1;
3947 char *string
= save_string (p
+ 1, q
- p
- 2);
3949 for (i
= 0; i
< n_switches
; i
++)
3950 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3951 && check_live_switch (i
, -1))
3953 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
3954 /* Pass any arguments this switch has. */
3962 /* If name specified ends in *, as in {x*:...},
3963 check for presence of any switch name starting with x. */
3966 for (i
= 0; i
< n_switches
; i
++)
3968 unsigned hard_match_len
= p
- filter
- 1;
3970 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3971 && check_live_switch (i
, hard_match_len
))
3977 /* Otherwise, check for presence of exact name specified. */
3980 for (i
= 0; i
< n_switches
; i
++)
3982 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3983 && switches
[i
].part1
[p
- filter
] == 0
3984 && check_live_switch (i
, -1))
3992 /* If it is as desired (present for %{s...}, absent for %{-s...})
3993 then substitute either the switch or the specified
3994 conditional text. */
3995 if (present
!= negate
)
4003 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
4009 /* Here if a %{|...} conditional fails: output a minus sign,
4010 which means "standard output" or "standard input". */
4011 do_spec_1 ("-", 0, NULL_PTR
);
4018 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4019 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4020 spec, or -1 if either exact match or %* is used.
4022 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4023 whose value does not begin with "no-" is obsoleted by the same value
4024 with the "no-", similarly for a switch with the "no-" prefix. */
4027 check_live_switch (switchnum
, prefix_length
)
4031 char *name
= switches
[switchnum
].part1
;
4034 /* In the common case of {<at-most-one-letter>*}, a negating
4035 switch would always match, so ignore that case. We will just
4036 send the conflicting switches to the compiler phase. */
4037 if (prefix_length
>= 0 && prefix_length
<= 1)
4040 /* If we already processed this switch and determined if it was
4041 live or not, return our past determination. */
4042 if (switches
[switchnum
].live_cond
!= 0)
4043 return switches
[switchnum
].live_cond
> 0;
4045 /* Now search for duplicate in a manner that depends on the name. */
4049 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4050 if (switches
[i
].part1
[0] == 'O')
4052 switches
[switchnum
].valid
= 1;
4053 switches
[switchnum
].live_cond
= -1;
4058 case 'W': case 'f': case 'm':
4059 if (! strncmp (name
+ 1, "no-", 3))
4061 /* We have Xno-YYY, search for XYYY. */
4062 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4063 if (switches
[i
].part1
[0] == name
[0]
4064 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4066 switches
[switchnum
].valid
= 1;
4067 switches
[switchnum
].live_cond
= -1;
4073 /* We have XYYY, search for Xno-YYY. */
4074 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4075 if (switches
[i
].part1
[0] == name
[0]
4076 && switches
[i
].part1
[1] == 'n'
4077 && switches
[i
].part1
[2] == 'o'
4078 && switches
[i
].part1
[3] == '-'
4079 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4081 switches
[switchnum
].valid
= 1;
4082 switches
[switchnum
].live_cond
= -1;
4089 /* Otherwise the switch is live. */
4090 switches
[switchnum
].live_cond
= 1;
4094 /* Pass a switch to the current accumulating command
4095 in the same form that we received it.
4096 SWITCHNUM identifies the switch; it is an index into
4097 the vector of switches gcc received, which is `switches'.
4098 This cannot fail since it never finishes a command line.
4100 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
4103 give_switch (switchnum
, omit_first_word
)
4105 int omit_first_word
;
4107 if (!omit_first_word
)
4109 do_spec_1 ("-", 0, NULL_PTR
);
4110 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4112 do_spec_1 (" ", 0, NULL_PTR
);
4113 if (switches
[switchnum
].args
!= 0)
4116 for (p
= switches
[switchnum
].args
; *p
; p
++)
4118 do_spec_1 (*p
, 1, NULL_PTR
);
4119 do_spec_1 (" ", 0, NULL_PTR
);
4122 switches
[switchnum
].valid
= 1;
4125 /* Search for a file named NAME trying various prefixes including the
4126 user's -B prefix and some standard ones.
4127 Return the absolute file name found. If nothing is found, return NAME. */
4135 /* Try multilib_dir if it is defined. */
4136 if (multilib_dir
!= NULL
)
4140 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4141 strcpy (try, multilib_dir
);
4142 strcat (try, dir_separator_str
);
4145 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4147 /* If we don't find it in the multi library dir, then fall
4148 through and look for it in the normal places. */
4149 if (newname
!= NULL
)
4153 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4154 return newname
? newname
: name
;
4157 /* Determine whether a directory exists. If LINKER, return 0 for
4158 certain fixed names not needed by the linker. If not LINKER, it is
4159 only important to return 0 if the host machine has a small ARG_MAX
4163 is_directory (path1
, path2
, linker
)
4168 int len1
= strlen (path1
);
4169 int len2
= strlen (path2
);
4170 char *path
= (char *) alloca (3 + len1
+ len2
);
4174 #ifndef SMALL_ARG_MAX
4179 /* Construct the path from the two parts. Ensure the string ends with "/.".
4180 The resulting path will be a directory even if the given path is a
4182 bcopy (path1
, path
, len1
);
4183 bcopy (path2
, path
+ len1
, len2
);
4184 cp
= path
+ len1
+ len2
;
4185 if (cp
[-1] != '/' && cp
[-1] != DIR_SEPARATOR
)
4186 *cp
++ = DIR_SEPARATOR
;
4190 /* Exclude directories that the linker is known to search. */
4193 && strcmp (path
, concat4 (dir_separator_str
, "lib",
4194 dir_separator_str
, ".")) == 0)
4196 && strcmp (path
, concat6 (dir_separator_str
, "usr",
4197 dir_separator_str
, "lib",
4198 dir_separator_str
, ".")) == 0)))
4201 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4204 /* On fatal signals, delete all the temporary files. */
4207 fatal_error (signum
)
4210 signal (signum
, SIG_DFL
);
4211 delete_failure_queue ();
4212 delete_temp_files ();
4213 /* Get the same signal again, this time not handled,
4214 so its normal effect occurs. */
4215 kill (getpid (), signum
);
4226 int linker_was_run
= 0;
4227 char *explicit_link_files
;
4231 p
= argv
[0] + strlen (argv
[0]);
4232 while (p
!= argv
[0] && p
[-1] != '/' && p
[-1] != DIR_SEPARATOR
) --p
;
4235 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4236 signal (SIGINT
, fatal_error
);
4238 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4239 signal (SIGHUP
, fatal_error
);
4241 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4242 signal (SIGTERM
, fatal_error
);
4244 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4245 signal (SIGPIPE
, fatal_error
);
4249 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4251 obstack_init (&obstack
);
4253 /* Set up to remember the pathname of gcc and any options
4254 needed for collect. We use argv[0] instead of programname because
4255 we need the complete pathname. */
4256 obstack_init (&collect_obstack
);
4257 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4258 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4259 putenv (obstack_finish (&collect_obstack
));
4261 /* Choose directory for temp files. */
4263 choose_temp_base ();
4265 /* Make a table of what switches there are (switches, n_switches).
4266 Make a table of specified input files (infiles, n_infiles).
4267 Decode switches that are handled locally. */
4269 process_command (argc
, argv
);
4271 /* Initialize the vector of specs to just the default.
4272 This means one element containing 0s, as a terminator. */
4274 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4275 bcopy ((char *) default_compilers
, (char *) compilers
,
4276 sizeof default_compilers
);
4277 n_compilers
= n_default_compilers
;
4279 /* Read specs from a file if there is one. */
4281 machine_suffix
= concat4 (spec_machine
, dir_separator_str
,
4282 spec_version
, dir_separator_str
);
4283 just_machine_suffix
= concat (spec_machine
, dir_separator_str
);
4285 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4286 /* Read the specs file unless it is a default one. */
4287 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4288 read_specs (specs_file
);
4290 /* If not cross-compiling, look for startfiles in the standard places. */
4291 /* The fact that these are done here, after reading the specs file,
4292 means that it cannot be found in these directories.
4293 But that's okay. It should never be there anyway. */
4296 #ifdef MD_EXEC_PREFIX
4297 add_prefix (&exec_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4298 add_prefix (&startfile_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4301 #ifdef MD_STARTFILE_PREFIX
4302 add_prefix (&startfile_prefixes
, md_startfile_prefix
, 0, 0, NULL_PTR
);
4305 #ifdef MD_STARTFILE_PREFIX_1
4306 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, 0, 0, NULL_PTR
);
4309 /* If standard_startfile_prefix is relative, base it on
4310 standard_exec_prefix. This lets us move the installed tree
4311 as a unit. If GCC_EXEC_PREFIX is defined, base
4312 standard_startfile_prefix on that as well. */
4313 if (*standard_startfile_prefix
== '/'
4314 || *standard_startfile_prefix
== DIR_SEPARATOR
)
4315 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, 0, 0,
4319 if (gcc_exec_prefix
)
4320 add_prefix (&startfile_prefixes
,
4321 concat (gcc_exec_prefix
, standard_startfile_prefix
),
4323 add_prefix (&startfile_prefixes
,
4324 concat3 (standard_exec_prefix
,
4326 standard_startfile_prefix
),
4330 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
, 0, 0,
4332 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
, 0, 0,
4334 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4335 add_prefix (&startfile_prefixes
, "./", 0, 1, NULL_PTR
);
4339 /* Now we have the specs.
4340 Set the `valid' bits for switches that match anything in any spec. */
4342 validate_all_switches ();
4344 /* Now that we have the switches and the specs, set
4345 the subdirectory based on the options. */
4346 set_multilib_dir ();
4348 /* Warn about any switches that no pass was interested in. */
4350 for (i
= 0; i
< n_switches
; i
++)
4351 if (! switches
[i
].valid
)
4352 error ("unrecognized option `-%s'", switches
[i
].part1
);
4354 /* Obey some of the options. */
4356 if (print_file_name
)
4358 printf ("%s\n", find_file (print_file_name
));
4362 if (print_prog_name
)
4364 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4365 printf ("%s\n", (newname
? newname
: print_prog_name
));
4369 if (print_multi_lib
)
4371 print_multilib_info ();
4375 if (print_multi_directory
)
4377 if (multilib_dir
== NULL
)
4380 printf ("%s\n", multilib_dir
);
4386 if (! strcmp (version_string
, compiler_version
))
4387 fprintf (stderr
, "gcc version %s\n", version_string
);
4389 fprintf (stderr
, "gcc driver version %s executing gcc version %s\n",
4390 version_string
, compiler_version
);
4397 fatal ("No input files");
4399 /* Make a place to record the compiler output file names
4400 that correspond to the input files. */
4402 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4403 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4405 /* Record which files were specified explicitly as link input. */
4407 explicit_link_files
= xmalloc (n_infiles
);
4408 bzero (explicit_link_files
, n_infiles
);
4410 for (i
= 0; i
< n_infiles
; i
++)
4412 register struct compiler
*cp
= 0;
4413 int this_file_error
= 0;
4415 /* Tell do_spec what to substitute for %i. */
4417 input_filename
= infiles
[i
].name
;
4418 input_filename_length
= strlen (input_filename
);
4419 input_file_number
= i
;
4421 /* Use the same thing in %o, unless cp->spec says otherwise. */
4423 outfiles
[i
] = input_filename
;
4425 /* Figure out which compiler from the file's suffix. */
4427 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4428 infiles
[i
].language
);
4432 /* Ok, we found an applicable compiler. Run its spec. */
4433 /* First say how much of input_filename to substitute for %b */
4437 input_basename
= input_filename
;
4438 for (p
= input_filename
; *p
; p
++)
4439 if (*p
== '/' || *p
== DIR_SEPARATOR
)
4440 input_basename
= p
+ 1;
4442 /* Find a suffix starting with the last period,
4443 and set basename_length to exclude that suffix. */
4444 basename_length
= strlen (input_basename
);
4445 p
= input_basename
+ basename_length
;
4446 while (p
!= input_basename
&& *p
!= '.') --p
;
4447 if (*p
== '.' && p
!= input_basename
)
4449 basename_length
= p
- input_basename
;
4450 input_suffix
= p
+ 1;
4456 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4458 len
+= strlen (cp
->spec
[j
]);
4460 p
= (char *) xmalloc (len
+ 1);
4463 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4466 strcpy (p
+ len
, cp
->spec
[j
]);
4467 len
+= strlen (cp
->spec
[j
]);
4470 value
= do_spec (p
);
4473 this_file_error
= 1;
4476 /* If this file's name does not contain a recognized suffix,
4477 record it as explicit linker input. */
4480 explicit_link_files
[i
] = 1;
4482 /* Clear the delete-on-failure queue, deleting the files in it
4483 if this compilation failed. */
4485 if (this_file_error
)
4487 delete_failure_queue ();
4490 /* If this compilation succeeded, don't delete those files later. */
4491 clear_failure_queue ();
4494 /* Run ld to link all the compiler output files. */
4496 if (error_count
== 0)
4498 int tmp
= execution_count
;
4502 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4504 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
4505 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
4507 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4509 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4510 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4513 for (i
= 0; i
< n_switches
; i
++)
4517 obstack_grow (&collect_obstack
, " ", 1);
4520 obstack_grow (&collect_obstack
, "-", 1);
4521 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4522 strlen (switches
[i
].part1
));
4524 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4526 obstack_grow (&collect_obstack
, " ", 1);
4527 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4530 obstack_grow (&collect_obstack
, "\0", 1);
4531 putenv (obstack_finish (&collect_obstack
));
4533 value
= do_spec (link_command_spec
);
4536 linker_was_run
= (tmp
!= execution_count
);
4539 /* Warn if a -B option was specified but the prefix was never used. */
4540 unused_prefix_warnings (&exec_prefixes
);
4541 unused_prefix_warnings (&startfile_prefixes
);
4543 /* If options said don't run linker,
4544 complain about input files to be given to the linker. */
4546 if (! linker_was_run
&& error_count
== 0)
4547 for (i
= 0; i
< n_infiles
; i
++)
4548 if (explicit_link_files
[i
])
4549 error ("%s: linker input file unused since linking not done",
4552 /* Delete some or all of the temporary files we made. */
4555 delete_failure_queue ();
4556 delete_temp_files ();
4558 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4563 /* Find the proper compilation spec for the file name NAME,
4564 whose length is LENGTH. LANGUAGE is the specified language,
4565 or 0 if none specified. */
4567 static struct compiler
*
4568 lookup_compiler (name
, length
, language
)
4573 struct compiler
*cp
;
4575 /* Look for the language, if one is spec'd. */
4578 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4582 if (cp
->suffix
[0] == '@'
4583 && !strcmp (cp
->suffix
+ 1, language
))
4587 error ("language %s not recognized", language
);
4590 /* Look for a suffix. */
4591 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4593 if (/* The suffix `-' matches only the file name `-'. */
4594 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4596 (strlen (cp
->suffix
) < length
4597 /* See if the suffix matches the end of NAME. */
4599 && (!strcmp (cp
->suffix
,
4600 name
+ length
- strlen (cp
->suffix
))
4601 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4602 && !strcasecmp (cp
->suffix
,
4603 name
+ length
- strlen (cp
->suffix
)))))
4605 && !strcmp (cp
->suffix
,
4606 name
+ length
- strlen (cp
->suffix
))))
4609 if (cp
->spec
[0][0] == '@')
4611 struct compiler
*new;
4612 /* An alias entry maps a suffix to a language.
4613 Search for the language; pass 0 for NAME and LENGTH
4614 to avoid infinite recursion if language not found.
4615 Construct the new compiler spec. */
4616 language
= cp
->spec
[0] + 1;
4617 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4618 new->suffix
= cp
->suffix
;
4619 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4620 (char *) new->spec
, sizeof new->spec
);
4623 /* A non-alias entry: return it. */
4635 register char *value
= (char *) malloc (size
);
4637 fatal ("virtual memory exhausted");
4642 xrealloc (ptr
, size
)
4646 register char *value
= (char *) realloc (ptr
, size
);
4648 fatal ("virtual memory exhausted");
4652 /* Return a newly-allocated string whose contents concatenate those of s1, s2 */
4658 int len1
= strlen (s1
);
4659 int len2
= strlen (s2
);
4660 char *result
= xmalloc (len1
+ len2
+ 1);
4662 strcpy (result
, s1
);
4663 strcpy (result
+ len1
, s2
);
4664 *(result
+ len1
+ len2
) = 0;
4670 concat3 (s1
, s2
, s3
)
4673 return concat (concat (s1
, s2
), s3
);
4677 concat4 (s1
, s2
, s3
, s4
)
4678 char *s1
, *s2
, *s3
, *s4
;
4680 return concat (concat (s1
, s2
), concat (s3
, s4
));
4684 concat6 (s1
, s2
, s3
, s4
, s5
, s6
)
4685 char *s1
, *s2
, *s3
, *s4
, *s5
, *s6
;
4687 return concat3 (concat (s1
, s2
), concat (s3
, s4
), concat (s5
, s6
));
4691 save_string (s
, len
)
4695 register char *result
= xmalloc (len
+ 1);
4697 bcopy (s
, result
, len
);
4703 pfatal_with_name (name
)
4708 if (errno
< sys_nerr
)
4709 s
= concat ("%s: ", sys_errlist
[errno
]);
4711 s
= "cannot open %s";
4716 perror_with_name (name
)
4721 if (errno
< sys_nerr
)
4722 s
= concat ("%s: ", sys_errlist
[errno
]);
4724 s
= "cannot open %s";
4734 if (errno
< sys_nerr
)
4735 s
= concat ("installation problem, cannot exec %s: ", sys_errlist
[errno
]);
4737 s
= "installation problem, cannot exec %s";
4741 /* More 'friendly' abort that prints the line and file.
4742 config.h can #define abort fancy_abort if you like that sort of thing. */
4747 fatal ("Internal gcc abort.");
4752 /* Output an error message and exit */
4755 fatal
VPROTO((char *format
, ...))
4762 VA_START (ap
, format
);
4765 format
= va_arg (ap
, char*);
4768 fprintf (stderr
, "%s: ", programname
);
4769 vfprintf (stderr
, format
, ap
);
4771 fprintf (stderr
, "\n");
4772 delete_temp_files ();
4777 error
VPROTO((char *format
, ...))
4784 VA_START (ap
, format
);
4787 format
= va_arg (ap
, char*);
4790 fprintf (stderr
, "%s: ", programname
);
4791 vfprintf (stderr
, format
, ap
);
4794 fprintf (stderr
, "\n");
4797 #else /* not HAVE_VPRINTF */
4800 fatal (msg
, arg1
, arg2
)
4801 char *msg
, *arg1
, *arg2
;
4803 error (msg
, arg1
, arg2
);
4804 delete_temp_files ();
4809 error (msg
, arg1
, arg2
)
4810 char *msg
, *arg1
, *arg2
;
4812 fprintf (stderr
, "%s: ", programname
);
4813 fprintf (stderr
, msg
, arg1
, arg2
);
4814 fprintf (stderr
, "\n");
4817 #endif /* not HAVE_VPRINTF */
4821 validate_all_switches ()
4823 struct compiler
*comp
;
4826 struct spec_list
*spec
;
4828 for (comp
= compilers
; comp
->spec
[0]; comp
++)
4831 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
4835 if (c
== '%' && *p
== '{')
4836 /* We have a switch spec. */
4837 validate_switches (p
+ 1);
4841 /* look through the linked list of extra specs read from the specs file */
4842 for (spec
= specs
; spec
; spec
= spec
->next
)
4846 if (c
== '%' && *p
== '{')
4847 /* We have a switch spec. */
4848 validate_switches (p
+ 1);
4851 p
= link_command_spec
;
4853 if (c
== '%' && *p
== '{')
4854 /* We have a switch spec. */
4855 validate_switches (p
+ 1);
4857 /* Now notice switches mentioned in the machine-specific specs. */
4861 if (c
== '%' && *p
== '{')
4862 /* We have a switch spec. */
4863 validate_switches (p
+ 1);
4867 if (c
== '%' && *p
== '{')
4868 /* We have a switch spec. */
4869 validate_switches (p
+ 1);
4873 if (c
== '%' && *p
== '{')
4874 /* We have a switch spec. */
4875 validate_switches (p
+ 1);
4877 p
= signed_char_spec
;
4879 if (c
== '%' && *p
== '{')
4880 /* We have a switch spec. */
4881 validate_switches (p
+ 1);
4885 if (c
== '%' && *p
== '{')
4886 /* We have a switch spec. */
4887 validate_switches (p
+ 1);
4891 if (c
== '%' && *p
== '{')
4892 /* We have a switch spec. */
4893 validate_switches (p
+ 1);
4897 if (c
== '%' && *p
== '{')
4898 /* We have a switch spec. */
4899 validate_switches (p
+ 1);
4903 if (c
== '%' && *p
== '{')
4904 /* We have a switch spec. */
4905 validate_switches (p
+ 1);
4909 if (c
== '%' && *p
== '{')
4910 /* We have a switch spec. */
4911 validate_switches (p
+ 1);
4915 if (c
== '%' && *p
== '{')
4916 /* We have a switch spec. */
4917 validate_switches (p
+ 1);
4920 /* Look at the switch-name that comes after START
4921 and mark as valid all supplied switches that match it. */
4924 validate_switches (start
)
4927 register char *p
= start
;
4942 while (*p
!= ':' && *p
!= '}') p
++;
4946 else if (p
[-1] == '*')
4948 /* Mark all matching switches as valid. */
4950 for (i
= 0; i
< n_switches
; i
++)
4951 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
4952 switches
[i
].valid
= 1;
4956 /* Mark an exact matching switch as valid. */
4957 for (i
= 0; i
< n_switches
; i
++)
4959 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4960 && switches
[i
].part1
[p
- filter
] == 0)
4961 switches
[i
].valid
= 1;
4966 /* Check whether a particular argument was used. */
4975 for (i
= 0; i
< n_switches
; i
++)
4976 if (! strncmp (switches
[i
].part1
, p
, len
)
4977 && strlen (switches
[i
].part1
) == len
)
4982 /* Work out the subdirectory to use based on the
4983 options. The format of multilib_select is a list of elements.
4984 Each element is a subdirectory name followed by a list of options
4985 followed by a semicolon. gcc will consider each line in turn. If
4986 none of the options beginning with an exclamation point are
4987 present, and all of the other options are present, that
4988 subdirectory will be used. */
4993 char *p
= multilib_select
;
4995 char *this_path
, *this_arg
;
5000 /* Ignore newlines. */
5007 /* Get the initial path. */
5015 this_path_len
= p
- this_path
;
5017 /* Check the arguments. */
5032 while (*p
!= ' ' && *p
!= ';')
5039 if (*this_arg
== '!')
5040 failed
= used_arg (this_arg
+ 1, p
- (this_arg
+ 1));
5042 failed
= ! used_arg (this_arg
, p
- this_arg
);
5050 if (this_path_len
!= 1
5051 || this_path
[0] != '.')
5053 multilib_dir
= xmalloc (this_path_len
+ 1);
5054 strncpy (multilib_dir
, this_path
, this_path_len
);
5055 multilib_dir
[this_path_len
] = '\0';
5064 /* Print out the multiple library subdirectory selection
5065 information. This prints out a series of lines. Each line looks
5066 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5067 required. Only the desired options are printed out, the negative
5068 matches. The options are print without a leading dash. There are
5069 no spaces to make it easy to use the information in the shell.
5070 Each subdirectory is printed only once. This assumes the ordering
5071 generated by the genmultilib script. */
5074 print_multilib_info ()
5076 char *p
= multilib_select
;
5077 char *last_path
, *this_path
;
5078 int last_path_len
, skip
, use_arg
;
5082 /* Ignore newlines. */
5089 /* Get the initial path. */
5098 /* If this is a duplicate, skip it. */
5099 skip
= (p
- this_path
== last_path_len
5100 && ! strncmp (last_path
, this_path
, last_path_len
));
5102 last_path
= this_path
;
5103 last_path_len
= p
- this_path
;
5109 for (p1
= last_path
; p1
< p
; p1
++)
5128 use_arg
= *p
!= '!';
5133 while (*p
!= ' ' && *p
!= ';')