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. */
63 /* Add prototype support. */
65 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
66 #define PROTO(ARGS) ARGS
68 #define PROTO(ARGS) ()
74 #define PVPROTO(ARGS) ARGS
75 #define VPROTO(ARGS) ARGS
76 #define VA_START(va_list,var) va_start(va_list,var)
78 #define PVPROTO(ARGS) ()
79 #define VPROTO(ARGS) (va_alist) va_dcl
80 #define VA_START(va_list,var) va_start(va_list)
84 /* Define a generic NULL if one hasn't already been defined. */
91 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
92 #define GENERIC_PTR void *
94 #define GENERIC_PTR char *
99 #define NULL_PTR ((GENERIC_PTR)0)
106 /* On MSDOS, write temp files in current dir
107 because there's no place else we can expect to use. */
114 /* Test if something is a normal file. */
116 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
119 /* Test if something is a directory. */
121 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
124 /* By default there is no special suffix for executables. */
125 #ifndef EXECUTABLE_SUFFIX
126 #define EXECUTABLE_SUFFIX ""
129 /* By default, colon separates directories in a path. */
130 #ifndef PATH_SEPARATOR
131 #define PATH_SEPARATOR ':'
134 #ifndef DIR_SEPARATOR
135 #define DIR_SEPARATOR '/'
138 static char dir_separator_str
[] = {DIR_SEPARATOR
, 0};
140 #define obstack_chunk_alloc xmalloc
141 #define obstack_chunk_free free
144 extern char *getenv ();
151 #if defined(bsd4_4) || defined(__NetBSD__)
152 extern const char *const sys_errlist
[];
154 extern char *sys_errlist
[];
157 extern int execv (), execvp ();
159 /* If a stage of compilation returns an exit status >= 1,
160 compilation of that file ceases. */
162 #define MIN_FATAL_STATUS 1
164 /* Flag saying to print the full filename of this file
165 as found through our usual search mechanism. */
167 static char *print_file_name
= NULL
;
169 /* As print_file_name, but search for executable file. */
171 static char *print_prog_name
= NULL
;
173 /* Flag saying to print the relative path we'd use to
174 find libgcc.a given the current compiler flags. */
176 static int print_multi_directory
;
178 /* Flag saying to print the list of subdirectories and
179 compiler flags used to select them in a standard form. */
181 static int print_multi_lib
;
183 /* Flag indicating whether we should print the command and arguments */
185 static int verbose_flag
;
187 /* Nonzero means write "temp" files in source directory
188 and use the source file's name in them, and don't delete them. */
190 static int save_temps_flag
;
192 /* The compiler version. */
194 static char *compiler_version
;
196 /* The target version specified with -V */
198 static char *spec_version
= DEFAULT_TARGET_VERSION
;
200 /* The target machine specified with -b. */
202 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
204 /* Nonzero if cross-compiling.
205 When -b is used, the value comes from the `specs' file. */
208 static int cross_compile
= 1;
210 static int cross_compile
= 0;
213 /* The number of errors that have occurred; the link phase will not be
214 run if this is non-zero. */
215 static int error_count
= 0;
217 /* This is the obstack which we use to allocate many strings. */
219 static struct obstack obstack
;
221 /* This is the obstack to build an environment variable to pass to
222 collect2 that describes all of the relevant switches of what to
223 pass the compiler in building the list of pointers to constructors
226 static struct obstack collect_obstack
;
228 extern char *version_string
;
230 /* Forward declaration for prototypes. */
233 static void set_spec
PROTO((char *, char *));
234 static struct compiler
*lookup_compiler
PROTO((char *, int, char *));
235 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
236 static void add_prefix
PROTO((struct path_prefix
*, char *, int, int, int *));
237 static char *skip_whitespace
PROTO((char *));
238 static void record_temp_file
PROTO((char *, int, int));
239 static void delete_if_ordinary
PROTO((char *));
240 static void delete_temp_files
PROTO((void));
241 static void delete_failure_queue
PROTO((void));
242 static void clear_failure_queue
PROTO((void));
243 static char *choose_temp_base_try
PROTO((char *, char *));
244 static void choose_temp_base
PROTO((void));
245 static int check_live_switch
PROTO((int, int));
246 static char *handle_braces
PROTO((char *));
247 static char *save_string
PROTO((char *, int));
248 static char *concat
PROTO((char *, char *));
249 static char *concat3
PROTO((char *, char *, char *));
250 static char *concat4
PROTO((char *, char *, char *, char *));
251 static char *concat6
PROTO((char *, char *, char *, char *, char *, \
253 static int do_spec
PROTO((char *));
254 static int do_spec_1
PROTO((char *, int, char *));
255 static char *find_file
PROTO((char *));
256 static int is_directory
PROTO((char *, char *, int));
257 static void validate_switches
PROTO((char *));
258 static void validate_all_switches
PROTO((void));
259 static void give_switch
PROTO((int, int));
260 static int used_arg
PROTO((char *, int));
261 static void set_multilib_dir
PROTO((void));
262 static void print_multilib_info
PROTO((void));
263 static void pfatal_with_name
PROTO((char *));
264 static void perror_with_name
PROTO((char *));
265 static void perror_exec
PROTO((char *));
267 static void fatal
PVPROTO((char *, ...));
268 static void error
PVPROTO((char *, ...));
270 /* We must not provide any prototype here, even if ANSI C. */
271 static void fatal
PROTO(());
272 static void error
PROTO(());
279 /* Specs are strings containing lines, each of which (if not blank)
280 is made up of a program name, and arguments separated by spaces.
281 The program name must be exact and start from root, since no path
282 is searched and it is unreliable to depend on the current working directory.
283 Redirection of input or output is not supported; the subprograms must
284 accept filenames saying what files to read and write.
286 In addition, the specs can contain %-sequences to substitute variable text
287 or for conditional text. Here is a table of all defined %-sequences.
288 Note that spaces are not generated automatically around the results of
289 expanding these sequences; therefore, you can concatenate them together
290 or with constant text in a single argument.
292 %% substitute one % into the program name or argument.
293 %i substitute the name of the input file being processed.
294 %b substitute the basename of the input file being processed.
295 This is the substring up to (and not including) the last period
296 and not including the directory.
297 %g substitute the temporary-file-name-base. This is a string chosen
298 once per compilation. Different temporary file names are made by
299 concatenation of constant strings on the end, as in `%g.s'.
300 %g also has the same effect of %d.
301 %u like %g, but make the temporary file name unique.
302 %U returns the last file name generated with %u.
303 %d marks the argument containing or following the %d as a
304 temporary file name, so that that file will be deleted if CC exits
305 successfully. Unlike %g, this contributes no text to the argument.
306 %w marks the argument containing or following the %w as the
307 "output file" of this compilation. This puts the argument
308 into the sequence of arguments that %o will substitute later.
310 like %{...} but mark last argument supplied within
311 as a file to be deleted on failure.
312 %o substitutes the names of all the output files, with spaces
313 automatically placed around them. You should write spaces
314 around the %o as well or the results are undefined.
315 %o is for use in the specs for running the linker.
316 Input files whose names have no recognized suffix are not compiled
317 at all, but they are included among the output files, so they will
319 %p substitutes the standard macro predefinitions for the
320 current target machine. Use this when running cpp.
321 %P like %p, but puts `__' before and after the name of each macro.
322 (Except macros that already have __.)
324 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
325 %s current argument is the name of a library or startup file of some sort.
326 Search for that file in a standard list of directories
327 and substitute the full name found.
328 %eSTR Print STR as an error message. STR is terminated by a newline.
329 Use this when inconsistent options are detected.
330 %x{OPTION} Accumulate an option for %X.
331 %X Output the accumulated linker options specified by compilations.
332 %Y Output the accumulated assembler options specified by compilations.
333 %Z Output the accumulated preprocessor options specified by compilations.
334 %v1 Substitute the major version number of GCC.
335 (For version 2.5.n, this is 2.)
336 %v2 Substitute the minor version number of GCC.
337 (For version 2.5.n, this is 5.)
338 %a process ASM_SPEC as a spec.
339 This allows config.h to specify part of the spec for running as.
340 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
341 used here. This can be used to run a post-processor after the
342 assembler has done it's job.
343 %D Dump out a -L option for each directory in startfile_prefixes.
344 If multilib_dir is set, extra entries are generated with it affixed.
345 %l process LINK_SPEC as a spec.
346 %L process LIB_SPEC as a spec.
347 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
348 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
349 %c process SIGNED_CHAR_SPEC as a spec.
350 %C process CPP_SPEC as a spec. A capital C is actually used here.
351 %1 process CC1_SPEC as a spec.
352 %2 process CC1PLUS_SPEC as a spec.
353 %| output "-" if the input for the current command is coming from a pipe.
354 %* substitute the variable part of a matched option. (See below.)
355 Note that each comma in the substituted string is replaced by
357 %{S} substitutes the -S switch, if that switch was given to CC.
358 If that switch was not specified, this substitutes nothing.
359 Here S is a metasyntactic variable.
360 %{S*} substitutes all the switches specified to CC whose names start
361 with -S. This is used for -o, -D, -I, etc; switches that take
362 arguments. CC considers `-o foo' as being one switch whose
363 name starts with `o'. %{o*} would substitute this text,
364 including the space; thus, two arguments would be generated.
365 %{S*:X} substitutes X if one or more switches whose names start with -S are
366 specified to CC. Note that the tail part of the -S option
367 (i.e. the part matched by the `*') will be substituted for each
368 occurrence of %* within X.
369 %{S:X} substitutes X, but only if the -S switch was given to CC.
370 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
371 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
372 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
373 %{.S:X} substitutes X, but only if processing a file with suffix S.
374 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
375 %(Spec) processes a specification defined in a specs file as *Spec:
376 %[Spec] as above, but put __ around -D arguments
378 The conditional text X in a %{S:X} or %{!S:X} construct may contain
379 other nested % constructs or spaces, or even newlines. They are
380 processed as usual, as described above.
382 The -O, -f, -m, and -W switches are handled specifically in these
383 constructs. If another value of -O or the negated form of a -f, -m, or
384 -W switch is found later in the command line, the earlier switch
385 value is ignored, except with {S*} where S is just one letter; this
386 passes all matching options.
388 The character | is used to indicate that a command should be piped to
389 the following command, but only if -pipe is specified.
391 Note that it is built into CC which switches take arguments and which
392 do not. You might think it would be useful to generalize this to
393 allow each compiler's spec to say which switches take arguments. But
394 this cannot be done in a consistent fashion. CC cannot even decide
395 which input files have been specified without knowing which switches
396 take arguments, and it must know which input files to compile in order
397 to tell which compilers to run.
399 CC also knows implicitly that arguments starting in `-l' are to be
400 treated as compiler output files, and passed to the linker in their
401 proper position among the other output files. */
403 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
405 /* config.h can define ASM_SPEC to provide extra args to the assembler
406 or extra switch-translations. */
411 /* config.h can define ASM_FINAL_SPEC to run a post processor after
412 the assembler has run. */
413 #ifndef ASM_FINAL_SPEC
414 #define ASM_FINAL_SPEC ""
417 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
418 or extra switch-translations. */
423 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
424 or extra switch-translations. */
429 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
430 or extra switch-translations. */
432 #define CC1PLUS_SPEC ""
435 /* config.h can define LINK_SPEC to provide extra args to the linker
436 or extra switch-translations. */
441 /* config.h can define LIB_SPEC to override the default libraries. */
443 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
446 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
447 #ifndef STARTFILE_SPEC
448 #define STARTFILE_SPEC \
449 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
452 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
453 Make the string nonempty to require spaces there. */
454 #ifndef SWITCHES_NEED_SPACES
455 #define SWITCHES_NEED_SPACES ""
458 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
460 #define ENDFILE_SPEC ""
463 /* This spec is used for telling cpp whether char is signed or not. */
464 #ifndef SIGNED_CHAR_SPEC
465 /* Use #if rather than ?:
466 because MIPS C compiler rejects like ?: in initializers. */
467 #if DEFAULT_SIGNED_CHAR
468 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
470 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
474 /* MULTILIB_SELECT comes from multilib.h. It gives a
475 string interpreted by set_multilib_dir to select a library
476 subdirectory based on the compiler options. */
477 #ifndef MULTILIB_SELECT
478 #define MULTILIB_SELECT ". ;"
481 static char *cpp_spec
= CPP_SPEC
;
482 static char *cpp_predefines
= CPP_PREDEFINES
;
483 static char *cc1_spec
= CC1_SPEC
;
484 static char *cc1plus_spec
= CC1PLUS_SPEC
;
485 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
486 static char *asm_spec
= ASM_SPEC
;
487 static char *asm_final_spec
= ASM_FINAL_SPEC
;
488 static char *link_spec
= LINK_SPEC
;
489 static char *lib_spec
= LIB_SPEC
;
490 static char *endfile_spec
= ENDFILE_SPEC
;
491 static char *startfile_spec
= STARTFILE_SPEC
;
492 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
493 static char *multilib_select
= MULTILIB_SELECT
;
495 /* This defines which switch letters take arguments. */
497 #ifndef SWITCH_TAKES_ARG
498 #define SWITCH_TAKES_ARG(CHAR) \
499 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
500 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
501 || (CHAR) == 'I' || (CHAR) == 'm' \
502 || (CHAR) == 'L' || (CHAR) == 'A')
505 /* This defines which multi-letter switches take arguments. */
507 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
508 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
509 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
510 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
511 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
512 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
513 || !strcmp (STR, "isystem"))
515 #ifndef WORD_SWITCH_TAKES_ARG
516 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
519 /* Record the mapping from file suffixes for compilation specs. */
523 char *suffix
; /* Use this compiler for input files
524 whose names end in this suffix. */
526 char *spec
[4]; /* To use this compiler, concatenate these
527 specs and pass to do_spec. */
530 /* Pointer to a vector of `struct compiler' that gives the spec for
531 compiling a file, based on its suffix.
532 A file that does not end in any of these suffixes will be passed
533 unchanged to the loader and nothing else will be done to it.
535 An entry containing two 0s is used to terminate the vector.
537 If multiple entries match a file, the last matching one is used. */
539 static struct compiler
*compilers
;
541 /* Number of entries in `compilers', not counting the null terminator. */
543 static int n_compilers
;
545 /* The default list of file name suffixes and their compilation specs. */
547 static struct compiler default_compilers
[] =
551 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
552 %{C:%{!E:%eGNU C does not support -C without using -E}}\
553 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
554 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
555 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
556 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
557 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
558 %{traditional-cpp:-traditional}\
559 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
560 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
561 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
562 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
563 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
564 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
566 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
567 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
568 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
569 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
570 %{!pipe:%g.s} %A\n }}}}"},
572 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
573 %{C:%{!E:%eGNU C does not support -C without using -E}}\
574 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
575 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
576 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
577 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
578 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
579 %{traditional-cpp:-traditional}\
580 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
582 %{!E:%e-E required when input is from standard input}"},
583 {".m", "@objective-c"},
585 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
586 %{C:%{!E:%eGNU C does not support -C without using -E}}\
587 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
588 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
589 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
590 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
591 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
592 %{traditional-cpp:-traditional}\
593 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
594 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
595 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
596 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
597 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
598 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
599 -lang-objc %{gen-decls} \
601 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
602 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
603 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
604 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
605 %{!pipe:%g.s} %A\n }}}}"},
608 "%{!E:%eCompilation of header file requested} \
609 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
610 %{C:%{!E:%eGNU C does not support -C without using -E}}\
611 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
612 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
613 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
614 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
615 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
616 %{traditional-cpp:-traditional}\
617 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
624 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
625 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
626 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
627 -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
628 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
629 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
630 %{traditional-cpp:-traditional} %{trigraphs}\
631 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
632 %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
633 "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\
634 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
635 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
636 %{traditional} %{v:-version} %{pg:-p} %{p}\
637 %{f*} %{+e*} %{aux-info*}\
638 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
639 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\
640 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
641 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
642 %{!pipe:%g.s} %A\n }}}}"},
643 {".i", "@cpp-output"},
645 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
646 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
647 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
649 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
650 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
651 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
652 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
653 %{!pipe:%g.s} %A\n }}}}"},
654 {".ii", "@c++-cpp-output"},
656 "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
657 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
658 %{traditional} %{v:-version} %{pg:-p} %{p}\
659 %{f*} %{+e*} %{aux-info*}\
660 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
661 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
662 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
663 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
664 %{!pipe:%g.s} %A\n }}}}"},
665 {".s", "@assembler"},
667 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
668 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
670 {".S", "@assembler-with-cpp"},
671 {"@assembler-with-cpp",
672 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
673 %{C:%{!E:%eGNU C does not support -C without using -E}}\
674 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
675 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
676 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
677 %{traditional-cpp:-traditional}\
678 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
679 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
680 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
681 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
682 %{!pipe:%g.s} %A\n }}}}"},
687 "%{!M:%{!MM:%{!E:gnat1 %{k8:-gnatk8} %{w:-gnatws} %{!Q:-quiet}\
688 -dumpbase %b.ada %{g*} %{O*} %{p} %{pg:-p} %{f*}\
690 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
691 %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
692 %{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
693 %{c:%W{o*}%{!o*:-o %w%b.o}}\
694 %{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n}}}}}} "},
695 /* Mark end of table */
699 /* Number of elements in default_compilers, not counting the terminator. */
701 static int n_default_compilers
702 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
704 /* Here is the spec for running the linker, after compiling all files. */
706 /* -u* was put back because both BSD and SysV seem to support it. */
707 /* %{static:} simply prevents an error message if the target machine
708 doesn't handle -static. */
709 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
710 scripts which exist in user specified directories, or in standard
712 #ifdef LINK_LIBGCC_SPECIAL_1
713 /* Have gcc do the search for libgcc.a, but generate -L options as usual. */
714 static char *link_command_spec
= "\
716 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
717 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
718 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
719 %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
721 #ifdef LINK_LIBGCC_SPECIAL
722 /* Have gcc do the search for libgcc.a, and don't generate -L options. */
723 static char *link_command_spec
= "\
725 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
726 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
727 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
728 %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
730 /* Use -L and have the linker do the search for -lgcc. */
731 static char *link_command_spec
= "\
733 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
734 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
735 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
736 %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}";
740 /* A vector of options to give to the linker.
741 These options are accumulated by -Xlinker and -Wl,
742 and substituted into the linker command with %X. */
743 static int n_linker_options
;
744 static char **linker_options
;
746 /* A vector of options to give to the assembler.
747 These options are accumulated by -Wa,
748 and substituted into the assembler command with %Y. */
749 static int n_assembler_options
;
750 static char **assembler_options
;
752 /* A vector of options to give to the preprocessor.
753 These options are accumulated by -Wp,
754 and substituted into the preprocessor command with %Z. */
755 static int n_preprocessor_options
;
756 static char **preprocessor_options
;
758 /* Define how to map long options into short ones. */
760 /* This structure describes one mapping. */
763 /* The long option's name. */
765 /* The equivalent short option. */
767 /* Argument info. A string of flag chars; NULL equals no options.
768 a => argument required.
769 o => argument optional.
770 j => join argument to equivalent, making one word.
771 * => require other text after NAME as an argument. */
775 /* This is the table of mappings. Mappings are tried sequentially
776 for each option encountered; the first one that matches, wins. */
778 struct option_map option_map
[] =
780 {"--all-warnings", "-Wall", 0},
781 {"--ansi", "-ansi", 0},
782 {"--assemble", "-S", 0},
783 {"--assert", "-A", "a"},
784 {"--comments", "-C", 0},
785 {"--compile", "-c", 0},
786 {"--debug", "-g", "oj"},
787 {"--define-macro", "-D", "a"},
788 {"--dependencies", "-M", 0},
789 {"--dump", "-d", "a"},
790 {"--dumpbase", "-dumpbase", "a"},
791 {"--entry", "-e", 0},
792 {"--extra-warnings", "-W", 0},
793 {"--for-assembler", "-Wa", "a"},
794 {"--for-linker", "-Xlinker", "a"},
795 {"--force-link", "-u", "a"},
796 {"--imacros", "-imacros", "a"},
797 {"--include", "-include", "a"},
798 {"--include-barrier", "-I-", 0},
799 {"--include-directory", "-I", "a"},
800 {"--include-directory-after", "-idirafter", "a"},
801 {"--include-prefix", "-iprefix", "a"},
802 {"--include-with-prefix", "-iwithprefix", "a"},
803 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
804 {"--include-with-prefix-after", "-iwithprefix", "a"},
805 {"--language", "-x", "a"},
806 {"--library-directory", "-L", "a"},
807 {"--machine", "-m", "aj"},
808 {"--machine-", "-m", "*j"},
809 {"--no-line-commands", "-P", 0},
810 {"--no-precompiled-includes", "-noprecomp", 0},
811 {"--no-standard-includes", "-nostdinc", 0},
812 {"--no-standard-libraries", "-nostdlib", 0},
813 {"--no-warnings", "-w", 0},
814 {"--optimize", "-O", "oj"},
815 {"--output", "-o", "a"},
816 {"--pedantic", "-pedantic", 0},
817 {"--pedantic-errors", "-pedantic-errors", 0},
818 {"--pipe", "-pipe", 0},
819 {"--prefix", "-B", "a"},
820 {"--preprocess", "-E", 0},
821 {"--print-file-name", "-print-file-name=", "aj"},
822 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
823 {"--print-missing-file-dependencies", "-MG", 0},
824 {"--print-multi-lib", "-print-multi-lib", 0},
825 {"--print-multi-directory", "-print-multi-directory", 0},
826 {"--print-prog-name", "-print-prog-name=", "aj"},
827 {"--profile", "-p", 0},
828 {"--profile-blocks", "-a", 0},
829 {"--quiet", "-q", 0},
830 {"--save-temps", "-save-temps", 0},
831 {"--shared", "-shared", 0},
832 {"--silent", "-q", 0},
833 {"--static", "-static", 0},
834 {"--symbolic", "-symbolic", 0},
835 {"--target", "-b", "a"},
836 {"--trace-includes", "-H", 0},
837 {"--traditional", "-traditional", 0},
838 {"--traditional-cpp", "-traditional-cpp", 0},
839 {"--trigraphs", "-trigraphs", 0},
840 {"--undefine-macro", "-U", "a"},
841 {"--use-version", "-V", "a"},
842 {"--user-dependencies", "-MM", 0},
843 {"--verbose", "-v", 0},
844 {"--version", "-dumpversion", 0},
845 {"--warn-", "-W", "*j"},
846 {"--write-dependencies", "-MD", 0},
847 {"--write-user-dependencies", "-MMD", 0},
851 /* Translate the options described by *ARGCP and *ARGVP.
852 Make a new vector and store it back in *ARGVP,
853 and store its length in *ARGVC. */
856 translate_options (argcp
, argvp
)
862 char **argv
= *argvp
;
863 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
867 newv
[newindex
++] = argv
[i
++];
871 /* Translate -- options. */
872 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
874 /* Find a mapping that applies to this option. */
875 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
877 int optlen
= strlen (option_map
[j
].name
);
878 int arglen
= strlen (argv
[i
]);
879 int complen
= arglen
> optlen
? optlen
: arglen
;
880 char *arginfo
= option_map
[j
].arg_info
;
885 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
892 k
< sizeof (option_map
) / sizeof (option_map
[0]);
894 if (strlen (option_map
[k
].name
) >= arglen
895 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
897 error ("Ambiguous abbreviation %s", argv
[i
]);
901 if (k
!= sizeof (option_map
) / sizeof (option_map
[0]))
907 /* If the option has an argument, accept that. */
908 if (argv
[i
][optlen
] == '=')
909 arg
= argv
[i
] + optlen
+ 1;
911 /* If this mapping requires extra text at end of name,
912 accept that as "argument". */
913 else if (index (arginfo
, '*') != 0)
914 arg
= argv
[i
] + optlen
;
916 /* Otherwise, extra text at end means mismatch.
917 Try other mappings. */
922 else if (index (arginfo
, '*') != 0)
924 error ("Incomplete `%s' option", option_map
[j
].name
);
928 /* Handle arguments. */
929 if (index (arginfo
, 'a') != 0)
935 error ("Missing argument to `%s' option",
943 else if (index (arginfo
, '*') != 0)
945 else if (index (arginfo
, 'o') == 0)
948 error ("Extraneous argument to `%s' option",
953 /* Store the translation as one argv elt or as two. */
954 if (arg
!= 0 && index (arginfo
, 'j') != 0)
955 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
);
958 newv
[newindex
++] = option_map
[j
].equivalent
;
959 newv
[newindex
++] = arg
;
962 newv
[newindex
++] = option_map
[j
].equivalent
;
970 /* Handle old-fashioned options--just copy them through,
971 with their arguments. */
972 else if (argv
[i
][0] == '-')
974 char *p
= argv
[i
] + 1;
978 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
979 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
980 else if (WORD_SWITCH_TAKES_ARG (p
))
981 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
982 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
985 else if (! strcmp (p
, "Xlinker"))
988 /* Watch out for an option at the end of the command line that
989 is missing arguments, and avoid skipping past the end of the
991 if (nskip
+ i
> argc
)
996 newv
[newindex
++] = argv
[i
++];
1001 /* Ordinary operands, or +e options. */
1002 newv
[newindex
++] = argv
[i
++];
1011 /* Read compilation specs from a file named FILENAME,
1012 replacing the default ones.
1014 A suffix which starts with `*' is a definition for
1015 one of the machine-specific sub-specs. The "suffix" should be
1016 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1017 The corresponding spec is stored in asm_spec, etc.,
1018 rather than in the `compilers' vector.
1020 Anything invalid in the file is a fatal error. */
1023 read_specs (filename
)
1027 struct stat statbuf
;
1032 fprintf (stderr
, "Reading specs from %s\n", filename
);
1034 /* Open and stat the file. */
1035 desc
= open (filename
, 0, 0);
1037 pfatal_with_name (filename
);
1038 if (stat (filename
, &statbuf
) < 0)
1039 pfatal_with_name (filename
);
1041 /* Read contents of file into BUFFER. */
1042 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1043 read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1044 buffer
[statbuf
.st_size
] = 0;
1047 /* Scan BUFFER for specs, putting them in the vector. */
1053 char *in
, *out
, *p1
, *p2
;
1055 /* Advance P in BUFFER to the next nonblank nocomment line. */
1056 p
= skip_whitespace (p
);
1060 /* Find the colon that should end the suffix. */
1062 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
1063 /* The colon shouldn't be missing. */
1065 fatal ("specs file malformed after %d characters", p1
- buffer
);
1066 /* Skip back over trailing whitespace. */
1068 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
1069 /* Copy the suffix to a string. */
1070 suffix
= save_string (p
, p2
- p
);
1071 /* Find the next line. */
1072 p
= skip_whitespace (p1
+ 1);
1074 fatal ("specs file malformed after %d characters", p
- buffer
);
1076 /* Find next blank line. */
1077 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
1078 /* Specs end at the blank line and do not include the newline. */
1079 spec
= save_string (p
, p1
- p
);
1082 /* Delete backslash-newline sequences from the spec. */
1087 if (in
[0] == '\\' && in
[1] == '\n')
1089 else if (in
[0] == '#')
1091 while (*in
&& *in
!= '\n') in
++;
1098 if (suffix
[0] == '*')
1100 if (! strcmp (suffix
, "*link_command"))
1101 link_command_spec
= spec
;
1103 set_spec (suffix
+ 1, spec
);
1107 /* Add this pair to the vector. */
1109 = ((struct compiler
*)
1110 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
1111 compilers
[n_compilers
].suffix
= suffix
;
1112 bzero ((char *) compilers
[n_compilers
].spec
,
1113 sizeof compilers
[n_compilers
].spec
);
1114 compilers
[n_compilers
].spec
[0] = spec
;
1116 bzero ((char *) &compilers
[n_compilers
],
1117 sizeof compilers
[n_compilers
]);
1121 link_command_spec
= spec
;
1124 if (link_command_spec
== 0)
1125 fatal ("spec file has no spec for linking");
1134 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1135 be considered whitespace. */
1136 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1138 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1142 while (*p
!= '\n') p
++;
1152 /* Structure to keep track of the specs that have been defined so far. These
1153 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1157 char *name
; /* Name of the spec. */
1158 char *spec
; /* The spec itself. */
1159 struct spec_list
*next
; /* Next spec in linked list. */
1162 /* List of specs that have been defined so far. */
1164 static struct spec_list
*specs
= (struct spec_list
*) 0;
1166 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1167 removed; If the spec starts with a + then SPEC is added to the end of the
1171 set_spec (name
, spec
)
1175 struct spec_list
*sl
;
1178 /* See if the spec already exists */
1179 for (sl
= specs
; sl
; sl
= sl
->next
)
1180 if (strcmp (sl
->name
, name
) == 0)
1185 /* Not found - make it */
1186 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1187 sl
->name
= save_string (name
, strlen (name
));
1188 sl
->spec
= save_string ("", 0);
1193 old_spec
= sl
->spec
;
1194 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
1195 sl
->spec
= concat (old_spec
, spec
+ 1);
1197 sl
->spec
= save_string (spec
, strlen (spec
));
1199 if (! strcmp (name
, "asm"))
1200 asm_spec
= sl
->spec
;
1201 else if (! strcmp (name
, "asm_final"))
1202 asm_final_spec
= sl
->spec
;
1203 else if (! strcmp (name
, "cc1"))
1204 cc1_spec
= sl
->spec
;
1205 else if (! strcmp (name
, "cc1plus"))
1206 cc1plus_spec
= sl
->spec
;
1207 else if (! strcmp (name
, "cpp"))
1208 cpp_spec
= sl
->spec
;
1209 else if (! strcmp (name
, "endfile"))
1210 endfile_spec
= sl
->spec
;
1211 else if (! strcmp (name
, "lib"))
1212 lib_spec
= sl
->spec
;
1213 else if (! strcmp (name
, "link"))
1214 link_spec
= sl
->spec
;
1215 else if (! strcmp (name
, "predefines"))
1216 cpp_predefines
= sl
->spec
;
1217 else if (! strcmp (name
, "signed_char"))
1218 signed_char_spec
= sl
->spec
;
1219 else if (! strcmp (name
, "startfile"))
1220 startfile_spec
= sl
->spec
;
1221 else if (! strcmp (name
, "switches_need_spaces"))
1222 switches_need_spaces
= sl
->spec
;
1223 else if (! strcmp (name
, "cross_compile"))
1224 cross_compile
= atoi (sl
->spec
);
1225 else if (! strcmp (name
, "multilib"))
1226 multilib_select
= sl
->spec
;
1227 /* Free the old spec */
1232 /* Accumulate a command (program name and args), and run it. */
1234 /* Vector of pointers to arguments in the current line of specifications. */
1236 static char **argbuf
;
1238 /* Number of elements allocated in argbuf. */
1240 static int argbuf_length
;
1242 /* Number of elements in argbuf currently in use (containing args). */
1244 static int argbuf_index
;
1246 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1247 temp file. Used only if MKTEMP_EACH_FILE. */
1249 static struct temp_name
{
1250 char *suffix
; /* suffix associated with the code. */
1251 int length
; /* strlen (suffix). */
1252 int unique
; /* Indicates whether %g or %u/%U was used. */
1253 char *filename
; /* associated filename. */
1254 int filename_length
; /* strlen (filename). */
1255 struct temp_name
*next
;
1258 /* Number of commands executed so far. */
1260 static int execution_count
;
1262 /* Number of commands that exited with a signal. */
1264 static int signal_count
;
1266 /* Name with which this program was invoked. */
1268 static char *programname
;
1270 /* Structures to keep track of prefixes to try when looking for files. */
1274 char *prefix
; /* String to prepend to the path. */
1275 struct prefix_list
*next
; /* Next in linked list. */
1276 int require_machine_suffix
; /* Don't use without machine_suffix. */
1277 /* 2 means try both machine_suffix and just_machine_suffix. */
1278 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1283 struct prefix_list
*plist
; /* List of prefixes to try */
1284 int max_len
; /* Max length of a prefix in PLIST */
1285 char *name
; /* Name of this list (used in config stuff) */
1288 /* List of prefixes to try when looking for executables. */
1290 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1292 /* List of prefixes to try when looking for startup (crt0) files. */
1294 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1296 /* List of prefixes to try when looking for include files. */
1298 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1300 /* Suffix to attach to directories searched for commands.
1301 This looks like `MACHINE/VERSION/'. */
1303 static char *machine_suffix
= 0;
1305 /* Suffix to attach to directories searched for commands.
1306 This is just `MACHINE/'. */
1308 static char *just_machine_suffix
= 0;
1310 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1312 static char *gcc_exec_prefix
;
1314 /* Default prefixes to attach to command names. */
1316 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1317 #undef MD_EXEC_PREFIX
1318 #undef MD_STARTFILE_PREFIX
1319 #undef MD_STARTFILE_PREFIX_1
1322 #ifndef STANDARD_EXEC_PREFIX
1323 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1324 #endif /* !defined STANDARD_EXEC_PREFIX */
1326 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1327 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1328 #ifdef MD_EXEC_PREFIX
1329 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1332 #ifndef STANDARD_STARTFILE_PREFIX
1333 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1334 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1336 #ifdef MD_STARTFILE_PREFIX
1337 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1339 #ifdef MD_STARTFILE_PREFIX_1
1340 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1342 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1343 static char *standard_startfile_prefix_1
= "/lib/";
1344 static char *standard_startfile_prefix_2
= "/usr/lib/";
1346 #ifndef TOOLDIR_BASE_PREFIX
1347 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1349 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1350 static char *tooldir_prefix
;
1352 /* Subdirectory to use for locating libraries. Set by
1353 set_multilib_dir based on the compilation options. */
1355 static char *multilib_dir
;
1357 /* Clear out the vector of arguments (after a command is executed). */
1365 /* Add one argument to the vector at the end.
1366 This is done when a space is seen or at the end of the line.
1367 If DELETE_ALWAYS is nonzero, the arg is a filename
1368 and the file should be deleted eventually.
1369 If DELETE_FAILURE is nonzero, the arg is a filename
1370 and the file should be deleted if this compilation fails. */
1373 store_arg (arg
, delete_always
, delete_failure
)
1375 int delete_always
, delete_failure
;
1377 if (argbuf_index
+ 1 == argbuf_length
)
1379 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1382 argbuf
[argbuf_index
++] = arg
;
1383 argbuf
[argbuf_index
] = 0;
1385 if (delete_always
|| delete_failure
)
1386 record_temp_file (arg
, delete_always
, delete_failure
);
1389 /* Record the names of temporary files we tell compilers to write,
1390 and delete them at the end of the run. */
1392 /* This is the common prefix we use to make temp file names.
1393 It is chosen once for each run of this program.
1394 It is substituted into a spec by %g.
1395 Thus, all temp file names contain this prefix.
1396 In practice, all temp file names start with this prefix.
1398 This prefix comes from the envvar TMPDIR if it is defined;
1399 otherwise, from the P_tmpdir macro if that is defined;
1400 otherwise, in /usr/tmp or /tmp. */
1402 static char *temp_filename
;
1404 /* Length of the prefix. */
1406 static int temp_filename_length
;
1408 /* Define the list of temporary files to delete. */
1413 struct temp_file
*next
;
1416 /* Queue of files to delete on success or failure of compilation. */
1417 static struct temp_file
*always_delete_queue
;
1418 /* Queue of files to delete on failure of compilation. */
1419 static struct temp_file
*failure_delete_queue
;
1421 /* Record FILENAME as a file to be deleted automatically.
1422 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1423 otherwise delete it in any case.
1424 FAIL_DELETE nonzero means delete it if a compilation step fails;
1425 otherwise delete it in any case. */
1428 record_temp_file (filename
, always_delete
, fail_delete
)
1433 register char *name
;
1434 name
= xmalloc (strlen (filename
) + 1);
1435 strcpy (name
, filename
);
1439 register struct temp_file
*temp
;
1440 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1441 if (! strcmp (name
, temp
->name
))
1443 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1444 temp
->next
= always_delete_queue
;
1446 always_delete_queue
= temp
;
1452 register struct temp_file
*temp
;
1453 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1454 if (! strcmp (name
, temp
->name
))
1456 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1457 temp
->next
= failure_delete_queue
;
1459 failure_delete_queue
= temp
;
1464 /* Delete all the temporary files whose names we previously recorded. */
1467 delete_if_ordinary (name
)
1474 printf ("Delete %s? (y or n) ", name
);
1478 while ((c
= getchar ()) != '\n' && c
!= EOF
) ;
1479 if (i
== 'y' || i
== 'Y')
1481 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1482 if (unlink (name
) < 0)
1484 perror_with_name (name
);
1488 delete_temp_files ()
1490 register struct temp_file
*temp
;
1492 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1493 delete_if_ordinary (temp
->name
);
1494 always_delete_queue
= 0;
1497 /* Delete all the files to be deleted on error. */
1500 delete_failure_queue ()
1502 register struct temp_file
*temp
;
1504 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1505 delete_if_ordinary (temp
->name
);
1509 clear_failure_queue ()
1511 failure_delete_queue
= 0;
1514 /* Compute a string to use as the base of all temporary file names.
1515 It is substituted for %g. */
1518 choose_temp_base_try (try, base
)
1525 else if (try == (char *)0)
1527 else if (access (try, R_OK
| W_OK
) != 0)
1540 base
= choose_temp_base_try (getenv ("TMPDIR"), base
);
1541 base
= choose_temp_base_try (getenv ("TMP"), base
);
1542 base
= choose_temp_base_try (getenv ("TEMP"), base
);
1545 base
= choose_temp_base_try (P_tmpdir
, base
);
1548 base
= choose_temp_base_try (concat4 (dir_separator_str
, "usr",
1549 dir_separator_str
, "tmp"),
1551 base
= choose_temp_base_try (concat (dir_separator_str
, "tmp"), base
);
1553 /* If all else fails, use the current directory! */
1554 if (base
== (char *)0) base
= concat(".", dir_separator_str
);
1556 len
= strlen (base
);
1557 temp_filename
= xmalloc (len
+ strlen (concat (dir_separator_str
,
1559 strcpy (temp_filename
, base
);
1560 if (len
> 0 && temp_filename
[len
-1] != '/'
1561 && temp_filename
[len
-1] != DIR_SEPARATOR
)
1562 temp_filename
[len
++] = DIR_SEPARATOR
;
1563 strcpy (temp_filename
+ len
, "ccXXXXXX");
1565 mktemp (temp_filename
);
1566 temp_filename_length
= strlen (temp_filename
);
1567 if (temp_filename_length
== 0)
1572 /* Routine to add variables to the environment. We do this to pass
1573 the pathname of the gcc driver, and the directories search to the
1574 collect2 program, which is being run as ld. This way, we can be
1575 sure of executing the right compiler when collect2 wants to build
1576 constructors and destructors. Since the environment variables we
1577 use come from an obstack, we don't have to worry about allocating
1586 #ifndef VMS /* nor about VMS */
1588 extern char **environ
;
1589 char **old_environ
= environ
;
1593 int str_len
= strlen (str
);
1597 while ((ch
= *p
++) != '\0' && ch
!= '=')
1603 /* Search for replacing an existing environment variable, and
1604 count the number of total environment variables. */
1605 for (envp
= old_environ
; *envp
; envp
++)
1608 if (!strncmp (str
, *envp
, name_len
))
1615 /* Add a new environment variable */
1616 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1618 bcopy ((char *) old_environ
, (char *) (environ
+ 1),
1619 sizeof (char *) * (num_envs
+1));
1624 #endif /* HAVE_PUTENV */
1627 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1630 putenv_from_prefixes (paths
, env_var
)
1631 struct path_prefix
*paths
;
1634 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1636 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1637 int first_time
= TRUE
;
1638 struct prefix_list
*pprefix
;
1640 obstack_grow (&collect_obstack
, env_var
, strlen (env_var
));
1642 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1644 int len
= strlen (pprefix
->prefix
);
1647 && is_directory (pprefix
->prefix
, machine_suffix
, 0))
1650 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1653 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1654 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1657 if (just_machine_suffix
1658 && pprefix
->require_machine_suffix
== 2
1659 && is_directory (pprefix
->prefix
, just_machine_suffix
, 0))
1662 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1665 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1666 obstack_grow (&collect_obstack
, just_machine_suffix
,
1670 if (!pprefix
->require_machine_suffix
)
1673 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1676 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1679 obstack_1grow (&collect_obstack
, '\0');
1680 putenv (obstack_finish (&collect_obstack
));
1684 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1685 access to check permissions.
1686 Return 0 if not found, otherwise return its name, allocated with malloc. */
1689 find_a_file (pprefix
, name
, mode
)
1690 struct path_prefix
*pprefix
;
1695 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1696 struct prefix_list
*pl
;
1697 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1700 len
+= strlen (machine_suffix
);
1702 temp
= xmalloc (len
);
1704 /* Determine the filename to execute (special case for absolute paths). */
1706 if (*name
== '/' || *name
== DIR_SEPARATOR
)
1708 if (access (name
, mode
))
1710 strcpy (temp
, name
);
1715 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1719 /* Some systems have a suffix for executable files.
1720 So try appending that first. */
1721 if (file_suffix
[0] != 0)
1723 strcpy (temp
, pl
->prefix
);
1724 strcat (temp
, machine_suffix
);
1725 strcat (temp
, name
);
1726 strcat (temp
, file_suffix
);
1727 if (access (temp
, mode
) == 0)
1729 if (pl
->used_flag_ptr
!= 0)
1730 *pl
->used_flag_ptr
= 1;
1735 /* Now try just the name. */
1736 strcpy (temp
, pl
->prefix
);
1737 strcat (temp
, machine_suffix
);
1738 strcat (temp
, name
);
1739 if (access (temp
, mode
) == 0)
1741 if (pl
->used_flag_ptr
!= 0)
1742 *pl
->used_flag_ptr
= 1;
1747 /* Certain prefixes are tried with just the machine type,
1748 not the version. This is used for finding as, ld, etc. */
1749 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
1751 /* Some systems have a suffix for executable files.
1752 So try appending that first. */
1753 if (file_suffix
[0] != 0)
1755 strcpy (temp
, pl
->prefix
);
1756 strcat (temp
, just_machine_suffix
);
1757 strcat (temp
, name
);
1758 strcat (temp
, file_suffix
);
1759 if (access (temp
, mode
) == 0)
1761 if (pl
->used_flag_ptr
!= 0)
1762 *pl
->used_flag_ptr
= 1;
1767 strcpy (temp
, pl
->prefix
);
1768 strcat (temp
, just_machine_suffix
);
1769 strcat (temp
, name
);
1770 if (access (temp
, mode
) == 0)
1772 if (pl
->used_flag_ptr
!= 0)
1773 *pl
->used_flag_ptr
= 1;
1778 /* Certain prefixes can't be used without the machine suffix
1779 when the machine or version is explicitly specified. */
1780 if (!pl
->require_machine_suffix
)
1782 /* Some systems have a suffix for executable files.
1783 So try appending that first. */
1784 if (file_suffix
[0] != 0)
1786 strcpy (temp
, pl
->prefix
);
1787 strcat (temp
, name
);
1788 strcat (temp
, file_suffix
);
1789 if (access (temp
, mode
) == 0)
1791 if (pl
->used_flag_ptr
!= 0)
1792 *pl
->used_flag_ptr
= 1;
1797 strcpy (temp
, pl
->prefix
);
1798 strcat (temp
, name
);
1799 if (access (temp
, mode
) == 0)
1801 if (pl
->used_flag_ptr
!= 0)
1802 *pl
->used_flag_ptr
= 1;
1812 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1813 at the start of the list, otherwise it goes at the end.
1815 If WARN is nonzero, we will warn if no file is found
1816 through this prefix. WARN should point to an int
1817 which will be set to 1 if this entry is used.
1819 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1820 the complete value of machine_suffix.
1821 2 means try both machine_suffix and just_machine_suffix. */
1824 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1825 struct path_prefix
*pprefix
;
1828 int require_machine_suffix
;
1831 struct prefix_list
*pl
, **prev
;
1834 if (!first
&& pprefix
->plist
)
1836 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1841 prev
= &pprefix
->plist
;
1843 /* Keep track of the longest prefix */
1845 len
= strlen (prefix
);
1846 if (len
> pprefix
->max_len
)
1847 pprefix
->max_len
= len
;
1849 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1850 pl
->prefix
= save_string (prefix
, len
);
1851 pl
->require_machine_suffix
= require_machine_suffix
;
1852 pl
->used_flag_ptr
= warn
;
1859 pl
->next
= (struct prefix_list
*) 0;
1863 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1866 unused_prefix_warnings (pprefix
)
1867 struct path_prefix
*pprefix
;
1869 struct prefix_list
*pl
= pprefix
->plist
;
1873 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1875 error ("file path prefix `%s' never used",
1877 /* Prevent duplicate warnings. */
1878 *pl
->used_flag_ptr
= 1;
1884 /* Get rid of all prefixes built up so far in *PLISTP. */
1887 free_path_prefix (pprefix
)
1888 struct path_prefix
*pprefix
;
1890 struct prefix_list
*pl
= pprefix
->plist
;
1891 struct prefix_list
*temp
;
1897 free (temp
->prefix
);
1898 free ((char *) temp
);
1900 pprefix
->plist
= (struct prefix_list
*) 0;
1903 /* stdin file number. */
1904 #define STDIN_FILE_NO 0
1906 /* stdout file number. */
1907 #define STDOUT_FILE_NO 1
1909 /* value of `pipe': port index for reading. */
1912 /* value of `pipe': port index for writing. */
1913 #define WRITE_PORT 1
1915 /* Pipe waiting from last process, to be used as input for the next one.
1916 Value is STDIN_FILE_NO if no pipe is waiting
1917 (i.e. the next command is the first of a group). */
1919 static int last_pipe_input
;
1921 /* Fork one piped subcommand. FUNC is the system call to use
1922 (either execv or execvp). ARGV is the arg vector to use.
1923 NOT_LAST is nonzero if this is not the last subcommand
1924 (i.e. its output should be piped to the next one.) */
1928 #include <process.h>
1930 pexecute (search_flag
, program
, argv
, not_last
)
1937 int i
= (search_flag
? spawnv
: spawnvp
) (1, program
, argv
);
1941 int i
, el
= search_flag
? 0 : 4;
1943 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6 + el
);
1944 rf
= scmd
+ strlen(program
) + 2 + el
;
1945 sprintf (scmd
, "%s%s @%s.gp", program
,
1946 (search_flag
? "" : ".exe"), temp_filename
);
1947 argfile
= fopen (rf
, "w");
1949 pfatal_with_name (rf
);
1951 for (i
=1; argv
[i
]; i
++)
1954 for (cp
= argv
[i
]; *cp
; cp
++)
1956 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
1957 fputc ('\\', argfile
);
1958 fputc (*cp
, argfile
);
1960 fputc ('\n', argfile
);
1971 perror_exec (program
);
1972 return MIN_FATAL_STATUS
<< 8;
1979 #if !defined(__MSDOS__) && !defined(OS2) && !defined(WINNT)
1982 pexecute (search_flag
, program
, argv
, not_last
)
1988 int (*func
)() = (search_flag
? execv
: execvp
);
1991 int input_desc
= last_pipe_input
;
1992 int output_desc
= STDOUT_FILE_NO
;
1993 int retries
, sleep_interval
;
1995 /* If this isn't the last process, make a pipe for its output,
1996 and record it as waiting to be the input to the next process. */
2000 if (pipe (pdes
) < 0)
2001 pfatal_with_name ("pipe");
2002 output_desc
= pdes
[WRITE_PORT
];
2003 last_pipe_input
= pdes
[READ_PORT
];
2006 last_pipe_input
= STDIN_FILE_NO
;
2008 /* Fork a subprocess; wait and retry if it fails. */
2010 for (retries
= 0; retries
< 4; retries
++)
2015 sleep (sleep_interval
);
2016 sleep_interval
*= 2;
2023 pfatal_with_name ("fork");
2025 pfatal_with_name ("vfork");
2031 /* Move the input and output pipes into place, if nec. */
2032 if (input_desc
!= STDIN_FILE_NO
)
2034 close (STDIN_FILE_NO
);
2038 if (output_desc
!= STDOUT_FILE_NO
)
2040 close (STDOUT_FILE_NO
);
2042 close (output_desc
);
2045 /* Close the parent's descs that aren't wanted here. */
2046 if (last_pipe_input
!= STDIN_FILE_NO
)
2047 close (last_pipe_input
);
2049 /* Exec the program. */
2050 (*func
) (program
, argv
);
2051 perror_exec (program
);
2057 /* In the parent, after forking.
2058 Close the descriptors that we made for this child. */
2059 if (input_desc
!= STDIN_FILE_NO
)
2061 if (output_desc
!= STDOUT_FILE_NO
)
2062 close (output_desc
);
2064 /* Return child's process number. */
2069 #endif /* not __MSDOS__ and not OS2 */
2071 #if defined(OS2) || defined(WINNT)
2081 for (i
= 1; argvec
[i
] != 0; i
++)
2084 char *temp
, *newtemp
;
2087 len
= strlen (temp
);
2088 for (j
= 0; j
< len
; j
++)
2092 newtemp
= xmalloc (len
+ 2);
2093 strncpy (newtemp
, temp
, j
);
2095 strncpy (&newtemp
[j
+1], &temp
[j
], len
-j
);
2096 newtemp
[len
+1] = 0;
2110 #define FIX_ARGV(a) fix_argv(a)
2114 #define FIX_ARGV(a) a
2116 #endif /* OS2 or WINNT */
2119 pexecute (search_flag
, program
, argv
, not_last
)
2125 return (search_flag
? spawnv
: spawnvp
) (1, program
, FIX_ARGV (argv
));
2127 #endif /* OS2 or WINNT */
2130 /* Execute the command specified by the arguments on the current line of spec.
2131 When using pipes, this includes several piped-together commands
2132 with `|' between them.
2134 Return 0 if successful, -1 if failed. */
2140 int n_commands
; /* # of command. */
2144 char *prog
; /* program name. */
2145 char **argv
; /* vector of args. */
2146 int pid
; /* pid of process for this command. */
2149 struct command
*commands
; /* each command buffer with above info. */
2151 /* Count # of piped commands. */
2152 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2153 if (strcmp (argbuf
[i
], "|") == 0)
2156 /* Get storage for each command. */
2158 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2160 /* Split argbuf into its separate piped processes,
2161 and record info about each one.
2162 Also search for the programs that are to be run. */
2164 commands
[0].prog
= argbuf
[0]; /* first command. */
2165 commands
[0].argv
= &argbuf
[0];
2166 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2168 commands
[0].argv
[0] = string
;
2170 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2171 if (strcmp (argbuf
[i
], "|") == 0)
2172 { /* each command. */
2174 fatal ("-pipe not supported under MS-DOS");
2176 argbuf
[i
] = 0; /* termination of command args. */
2177 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2178 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2179 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2181 commands
[n_commands
].argv
[0] = string
;
2185 argbuf
[argbuf_index
] = 0;
2187 /* If -v, print what we are about to do, and maybe query. */
2191 /* Print each piped command as a separate line. */
2192 for (i
= 0; i
< n_commands
; i
++)
2196 for (j
= commands
[i
].argv
; *j
; j
++)
2197 fprintf (stderr
, " %s", *j
);
2199 /* Print a pipe symbol after all but the last command. */
2200 if (i
+ 1 != n_commands
)
2201 fprintf (stderr
, " |");
2202 fprintf (stderr
, "\n");
2206 fprintf (stderr
, "\nGo ahead? (y or n) ");
2210 while (getchar () != '\n') ;
2211 if (i
!= 'y' && i
!= 'Y')
2216 /* Run each piped subprocess. */
2218 last_pipe_input
= STDIN_FILE_NO
;
2219 for (i
= 0; i
< n_commands
; i
++)
2221 char *string
= commands
[i
].argv
[0];
2223 commands
[i
].pid
= pexecute (string
!= commands
[i
].prog
,
2224 string
, commands
[i
].argv
,
2225 i
+ 1 < n_commands
);
2227 if (string
!= commands
[i
].prog
)
2233 /* Wait for all the subprocesses to finish.
2234 We don't care what order they finish in;
2235 we know that N_COMMANDS waits will get them all. */
2240 for (i
= 0; i
< n_commands
; i
++)
2244 char *prog
= "unknown";
2247 status
= pid
= commands
[i
].pid
;
2250 pid
= cwait (&status
, commands
[i
].pid
, WAIT_CHILD
);
2252 pid
= wait (&status
);
2261 for (j
= 0; j
< n_commands
; j
++)
2262 if (commands
[j
].pid
== pid
)
2263 prog
= commands
[j
].prog
;
2265 if ((status
& 0x7F) != 0)
2267 fatal ("Internal compiler error: program %s got fatal signal %d",
2268 prog
, (status
& 0x7F));
2271 if (((status
& 0xFF00) >> 8) >= MIN_FATAL_STATUS
)
2279 /* Find all the switches given to us
2280 and make a vector describing them.
2281 The elements of the vector are strings, one per switch given.
2282 If a switch uses following arguments, then the `part1' field
2283 is the switch itself and the `args' field
2284 is a null-terminated vector containing the following arguments.
2285 The `live_cond' field is 1 if the switch is true in a conditional spec,
2286 -1 if false (overridden by a later switch), and is initialized to zero.
2287 The `valid' field is nonzero if any spec has looked at this switch;
2288 if it remains zero at the end of the run, it must be meaningless. */
2298 static struct switchstr
*switches
;
2300 static int n_switches
;
2308 /* Also a vector of input files specified. */
2310 static struct infile
*infiles
;
2312 static int n_infiles
;
2314 /* And a vector of corresponding output files is made up later. */
2316 static char **outfiles
;
2318 /* Create the vector `switches' and its contents.
2319 Store its length in `n_switches'. */
2322 process_command (argc
, argv
)
2328 char *spec_lang
= 0;
2329 int last_language_n_infiles
;
2331 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2336 /* Figure compiler version from version string. */
2338 compiler_version
= save_string (version_string
, strlen (version_string
));
2339 for (temp
= compiler_version
; *temp
; ++temp
)
2348 /* Set up the default search paths. */
2350 if (gcc_exec_prefix
)
2352 add_prefix (&exec_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2353 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2356 /* COMPILER_PATH and LIBRARY_PATH have values
2357 that are lists of directory names with colons. */
2359 temp
= getenv ("COMPILER_PATH");
2362 char *startp
, *endp
;
2363 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2365 startp
= endp
= temp
;
2368 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2370 strncpy (nstore
, startp
, endp
-startp
);
2372 strcpy (nstore
, concat (".", dir_separator_str
));
2373 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2375 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2376 nstore
[endp
-startp
+1] = 0;
2379 nstore
[endp
-startp
] = 0;
2380 add_prefix (&exec_prefixes
, nstore
, 0, 0, NULL_PTR
);
2383 endp
= startp
= endp
+ 1;
2390 temp
= getenv ("LIBRARY_PATH");
2393 char *startp
, *endp
;
2394 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2396 startp
= endp
= temp
;
2399 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2401 strncpy (nstore
, startp
, endp
-startp
);
2403 strcpy (nstore
, concat (".", dir_separator_str
));
2404 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2406 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2407 nstore
[endp
-startp
+1] = 0;
2410 nstore
[endp
-startp
] = 0;
2411 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2414 endp
= startp
= endp
+ 1;
2421 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2422 temp
= getenv ("LPATH");
2425 char *startp
, *endp
;
2426 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2428 startp
= endp
= temp
;
2431 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2433 strncpy (nstore
, startp
, endp
-startp
);
2435 strcpy (nstore
, concat (".", dir_separator_str
));
2436 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2438 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2439 nstore
[endp
-startp
+1] = 0;
2442 nstore
[endp
-startp
] = 0;
2443 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2446 endp
= startp
= endp
+ 1;
2453 /* Convert new-style -- options to old-style. */
2454 translate_options (&argc
, &argv
);
2456 /* Scan argv twice. Here, the first time, just count how many switches
2457 there will be in their vector, and how many input files in theirs.
2458 Here we also parse the switches that cc itself uses (e.g. -v). */
2460 for (i
= 1; i
< argc
; i
++)
2462 if (! strcmp (argv
[i
], "-dumpspecs"))
2464 printf ("*asm:\n%s\n\n", asm_spec
);
2465 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
2466 printf ("*cpp:\n%s\n\n", cpp_spec
);
2467 printf ("*cc1:\n%s\n\n", cc1_spec
);
2468 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
2469 printf ("*endfile:\n%s\n\n", endfile_spec
);
2470 printf ("*link:\n%s\n\n", link_spec
);
2471 printf ("*lib:\n%s\n\n", lib_spec
);
2472 printf ("*startfile:\n%s\n\n", startfile_spec
);
2473 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
2474 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
2475 printf ("*predefines:\n%s\n\n", cpp_predefines
);
2476 printf ("*cross_compile:\n%d\n\n", cross_compile
);
2477 printf ("*multilib:\n%s\n\n", multilib_select
);
2481 else if (! strcmp (argv
[i
], "-dumpversion"))
2483 printf ("%s\n", version_string
);
2486 else if (! strcmp (argv
[i
], "-dumpmachine"))
2488 printf ("%s\n", spec_machine
);
2491 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2492 print_file_name
= "libgcc.a";
2493 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2494 print_file_name
= argv
[i
] + 17;
2495 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2496 print_prog_name
= argv
[i
] + 17;
2497 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2498 print_multi_lib
= 1;
2499 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2500 print_multi_directory
= 1;
2501 else if (! strcmp (argv
[i
], "-Xlinker"))
2503 /* Pass the argument of this option to the linker when we link. */
2506 fatal ("argument to `-Xlinker' is missing");
2509 if (!linker_options
)
2511 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2514 = (char **) xrealloc (linker_options
,
2515 n_linker_options
* sizeof (char **));
2517 linker_options
[n_linker_options
- 1] = argv
[++i
];
2519 else if (! strncmp (argv
[i
], "-Wl,", 4))
2522 /* Pass the rest of this option to the linker when we link. */
2525 if (!linker_options
)
2527 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2530 = (char **) xrealloc (linker_options
,
2531 n_linker_options
* sizeof (char **));
2533 /* Split the argument at commas. */
2535 for (j
= 4; argv
[i
][j
]; j
++)
2536 if (argv
[i
][j
] == ',')
2538 linker_options
[n_linker_options
- 1]
2539 = save_string (argv
[i
] + prev
, j
- prev
);
2542 = (char **) xrealloc (linker_options
,
2543 n_linker_options
* sizeof (char **));
2546 /* Record the part after the last comma. */
2547 linker_options
[n_linker_options
- 1] = argv
[i
] + prev
;
2549 else if (! strncmp (argv
[i
], "-Wa,", 4))
2552 /* Pass the rest of this option to the assembler. */
2554 n_assembler_options
++;
2555 if (!assembler_options
)
2557 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2560 = (char **) xrealloc (assembler_options
,
2561 n_assembler_options
* sizeof (char **));
2563 /* Split the argument at commas. */
2565 for (j
= 4; argv
[i
][j
]; j
++)
2566 if (argv
[i
][j
] == ',')
2568 assembler_options
[n_assembler_options
- 1]
2569 = save_string (argv
[i
] + prev
, j
- prev
);
2570 n_assembler_options
++;
2572 = (char **) xrealloc (assembler_options
,
2573 n_assembler_options
* sizeof (char **));
2576 /* Record the part after the last comma. */
2577 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2579 else if (! strncmp (argv
[i
], "-Wp,", 4))
2582 /* Pass the rest of this option to the preprocessor. */
2584 n_preprocessor_options
++;
2585 if (!preprocessor_options
)
2586 preprocessor_options
2587 = (char **) xmalloc (n_preprocessor_options
* sizeof (char **));
2589 preprocessor_options
2590 = (char **) xrealloc (preprocessor_options
,
2591 n_preprocessor_options
* sizeof (char **));
2593 /* Split the argument at commas. */
2595 for (j
= 4; argv
[i
][j
]; j
++)
2596 if (argv
[i
][j
] == ',')
2598 preprocessor_options
[n_preprocessor_options
- 1]
2599 = save_string (argv
[i
] + prev
, j
- prev
);
2600 n_preprocessor_options
++;
2601 preprocessor_options
2602 = (char **) xrealloc (preprocessor_options
,
2603 n_preprocessor_options
* sizeof (char **));
2606 /* Record the part after the last comma. */
2607 preprocessor_options
[n_preprocessor_options
- 1] = argv
[i
] + prev
;
2609 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2610 /* The +e options to the C++ front-end. */
2612 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2614 register char *p
= &argv
[i
][1];
2615 register int c
= *p
;
2620 if (p
[1] == 0 && i
+ 1 == argc
)
2621 fatal ("argument to `-b' is missing");
2623 spec_machine
= argv
[++i
];
2625 spec_machine
= p
+ 1;
2630 int *temp
= (int *) xmalloc (sizeof (int));
2632 if (p
[1] == 0 && i
+ 1 == argc
)
2633 fatal ("argument to `-B' is missing");
2638 add_prefix (&exec_prefixes
, value
, 1, 0, temp
);
2639 add_prefix (&startfile_prefixes
, value
, 1, 0, temp
);
2640 add_prefix (&include_prefixes
, concat (value
, "include"),
2643 /* As a kludge, if the arg is "[foo/]stageN/", just add
2644 "[foo/]include" to the include prefix. */
2646 int len
= strlen (value
);
2649 && (value
[len
- 8] == '/'
2650 || value
[len
- 8] == DIR_SEPARATOR
)))
2651 && strncmp (value
+ len
- 7, "stage", 5) == 0
2652 && isdigit (value
[len
- 2])
2653 && (value
[len
- 1] == '/'
2654 || value
[len
- 1] == DIR_SEPARATOR
))
2657 add_prefix (&include_prefixes
, "include", 1, 0, 0);
2660 char *string
= xmalloc (len
+ 1);
2661 strncpy (string
, value
, len
-7);
2662 strcat (string
, "include");
2663 add_prefix (&include_prefixes
, string
, 1, 0, 0);
2670 case 'v': /* Print our subcommands and print versions. */
2672 /* If they do anything other than exactly `-v', don't set
2673 verbose_flag; rather, continue on to give the error. */
2680 if (p
[1] == 0 && i
+ 1 == argc
)
2681 fatal ("argument to `-V' is missing");
2683 spec_version
= argv
[++i
];
2685 spec_version
= p
+ 1;
2686 compiler_version
= spec_version
;
2690 if (!strcmp (p
, "save-temps"))
2692 save_temps_flag
= 1;
2699 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2700 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2701 else if (WORD_SWITCH_TAKES_ARG (p
))
2702 i
+= WORD_SWITCH_TAKES_ARG (p
);
2709 /* Set up the search paths before we go looking for config files. */
2711 /* These come before the md prefixes so that we will find gcc's subcommands
2712 (such as cpp) rather than those of the host system. */
2713 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2714 as well as trying the machine and the version. */
2716 add_prefix (&exec_prefixes
, standard_exec_prefix
, 0, 2, NULL_PTR
);
2717 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, 0, 2, NULL_PTR
);
2720 add_prefix (&startfile_prefixes
, standard_exec_prefix
, 0, 1, NULL_PTR
);
2721 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, 0, 1, NULL_PTR
);
2723 tooldir_prefix
= concat3 (tooldir_base_prefix
, spec_machine
,
2726 /* If tooldir is relative, base it on exec_prefixes. A relative
2727 tooldir lets us move the installed tree as a unit.
2729 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2730 directories, so that we can search both the user specified directory
2731 and the standard place. */
2733 if (*tooldir_prefix
!= '/' && *tooldir_prefix
!= DIR_SEPARATOR
)
2735 if (gcc_exec_prefix
)
2737 char *gcc_exec_tooldir_prefix
2738 = concat6 (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
2739 spec_version
, dir_separator_str
, tooldir_prefix
);
2741 add_prefix (&exec_prefixes
,
2742 concat3 (gcc_exec_tooldir_prefix
, "bin",
2745 add_prefix (&startfile_prefixes
,
2746 concat3 (gcc_exec_tooldir_prefix
, "lib",
2751 tooldir_prefix
= concat6 (standard_exec_prefix
, spec_machine
,
2752 dir_separator_str
, spec_version
,
2753 dir_separator_str
, tooldir_prefix
);
2756 add_prefix (&exec_prefixes
,
2757 concat3 (tooldir_prefix
, "bin", dir_separator_str
),
2759 add_prefix (&startfile_prefixes
,
2760 concat3 (tooldir_prefix
, "lib", dir_separator_str
),
2763 /* More prefixes are enabled in main, after we read the specs file
2764 and determine whether this is cross-compilation or not. */
2767 /* Then create the space for the vectors and scan again. */
2769 switches
= ((struct switchstr
*)
2770 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2771 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2774 last_language_n_infiles
= -1;
2776 /* This, time, copy the text of each switch and store a pointer
2777 to the copy in the vector of switches.
2778 Store all the infiles in their vector. */
2780 for (i
= 1; i
< argc
; i
++)
2782 /* Just skip the switches that were handled by the preceding loop. */
2783 if (!strcmp (argv
[i
], "-Xlinker"))
2785 else if (! strncmp (argv
[i
], "-Wl,", 4))
2787 else if (! strncmp (argv
[i
], "-Wa,", 4))
2789 else if (! strncmp (argv
[i
], "-Wp,", 4))
2791 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2793 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2795 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2797 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2799 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2801 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2803 /* Compensate for the +e options to the C++ front-end;
2804 they're there simply for cfront call-compatibility. We do
2805 some magic in default_compilers to pass them down properly.
2806 Note we deliberately start at the `+' here, to avoid passing
2807 -e0 or -e1 down into the linker. */
2808 switches
[n_switches
].part1
= &argv
[i
][0];
2809 switches
[n_switches
].args
= 0;
2810 switches
[n_switches
].live_cond
= 0;
2811 switches
[n_switches
].valid
= 0;
2814 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2816 register char *p
= &argv
[i
][1];
2817 register int c
= *p
;
2819 if (c
== 'B' || c
== 'b' || c
== 'V')
2821 /* Skip a separate arg, if any. */
2828 if (p
[1] == 0 && i
+ 1 == argc
)
2829 fatal ("argument to `-x' is missing");
2831 spec_lang
= argv
[++i
];
2834 if (! strcmp (spec_lang
, "none"))
2835 /* Suppress the warning if -xnone comes after the last input file,
2836 because alternate command interfaces like g++ might find it
2837 useful to place -xnone after each input file. */
2840 last_language_n_infiles
= n_infiles
;
2843 switches
[n_switches
].part1
= p
;
2844 /* Deal with option arguments in separate argv elements. */
2845 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2846 || WORD_SWITCH_TAKES_ARG (p
))
2849 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2853 /* Count only the option arguments in separate argv elements. */
2854 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2856 if (i
+ n_args
>= argc
)
2857 fatal ("argument to `-%s' is missing", p
);
2858 switches
[n_switches
].args
2859 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2861 switches
[n_switches
].args
[j
++] = argv
[++i
];
2862 /* Null-terminate the vector. */
2863 switches
[n_switches
].args
[j
] = 0;
2865 else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L'))
2867 /* On some systems, ld cannot handle -o or -L without space.
2868 So split the -o or -L from its argument. */
2869 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2870 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2871 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2872 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2873 switches
[n_switches
].args
[1] = 0;
2876 switches
[n_switches
].args
= 0;
2878 switches
[n_switches
].live_cond
= 0;
2879 switches
[n_switches
].valid
= 0;
2880 /* This is always valid, since gcc.c itself understands it. */
2881 if (!strcmp (p
, "save-temps"))
2882 switches
[n_switches
].valid
= 1;
2887 if ((argv
[i
][0] != '-' || argv
[i
][1] != 'l')
2888 && strcmp (argv
[i
], "-")
2889 && access (argv
[i
], R_OK
) < 0)
2891 perror_with_name (argv
[i
]);
2896 infiles
[n_infiles
].language
= spec_lang
;
2897 infiles
[n_infiles
++].name
= argv
[i
];
2902 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
2903 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2905 switches
[n_switches
].part1
= 0;
2906 infiles
[n_infiles
].name
= 0;
2908 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2909 if (gcc_exec_prefix
)
2911 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2912 + strlen (spec_machine
) + 3);
2913 strcpy (temp
, gcc_exec_prefix
);
2914 strcat (temp
, spec_machine
);
2915 strcat (temp
, dir_separator_str
);
2916 strcat (temp
, spec_version
);
2917 strcat (temp
, dir_separator_str
);
2918 gcc_exec_prefix
= temp
;
2922 /* Process a spec string, accumulating and running commands. */
2924 /* These variables describe the input file name.
2925 input_file_number is the index on outfiles of this file,
2926 so that the output file name can be stored for later use by %o.
2927 input_basename is the start of the part of the input file
2928 sans all directory names, and basename_length is the number
2929 of characters starting there excluding the suffix .c or whatever. */
2931 static char *input_filename
;
2932 static int input_file_number
;
2933 static int input_filename_length
;
2934 static int basename_length
;
2935 static char *input_basename
;
2936 static char *input_suffix
;
2938 /* These are variables used within do_spec and do_spec_1. */
2940 /* Nonzero if an arg has been started and not yet terminated
2941 (with space, tab or newline). */
2942 static int arg_going
;
2944 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2945 is a temporary file name. */
2946 static int delete_this_arg
;
2948 /* Nonzero means %w has been seen; the next arg to be terminated
2949 is the output file name of this compilation. */
2950 static int this_is_output_file
;
2952 /* Nonzero means %s has been seen; the next arg to be terminated
2953 is the name of a library file and we should try the standard
2954 search dirs for it. */
2955 static int this_is_library_file
;
2957 /* Nonzero means that the input of this command is coming from a pipe. */
2958 static int input_from_pipe
;
2960 /* Process the spec SPEC and run the commands specified therein.
2961 Returns 0 if the spec is successfully processed; -1 if failed. */
2971 delete_this_arg
= 0;
2972 this_is_output_file
= 0;
2973 this_is_library_file
= 0;
2974 input_from_pipe
= 0;
2976 value
= do_spec_1 (spec
, 0, NULL_PTR
);
2978 /* Force out any unfinished command.
2979 If -pipe, this forces out the last command if it ended in `|'. */
2982 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2985 if (argbuf_index
> 0)
2992 /* Process the sub-spec SPEC as a portion of a larger spec.
2993 This is like processing a whole spec except that we do
2994 not initialize at the beginning and we do not supply a
2995 newline by default at the end.
2996 INSWITCH nonzero means don't process %-sequences in SPEC;
2997 in this case, % is treated as an ordinary character.
2998 This is used while substituting switches.
2999 INSWITCH nonzero also causes SPC not to terminate an argument.
3001 Value is zero unless a line was finished
3002 and the command on that line reported an error. */
3005 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3008 char *soft_matched_part
;
3010 register char *p
= spec
;
3017 /* If substituting a switch, treat all chars like letters.
3018 Otherwise, NL, SPC, TAB and % are special. */
3019 switch (inswitch
? 'a' : c
)
3022 /* End of line: finish any pending argument,
3023 then run the pending command if one has been started. */
3026 obstack_1grow (&obstack
, 0);
3027 string
= obstack_finish (&obstack
);
3028 if (this_is_library_file
)
3029 string
= find_file (string
);
3030 store_arg (string
, delete_this_arg
, this_is_output_file
);
3031 if (this_is_output_file
)
3032 outfiles
[input_file_number
] = string
;
3036 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3039 for (i
= 0; i
< n_switches
; i
++)
3040 if (!strcmp (switches
[i
].part1
, "pipe"))
3043 /* A `|' before the newline means use a pipe here,
3044 but only if -pipe was specified.
3045 Otherwise, execute now and don't pass the `|' as an arg. */
3048 input_from_pipe
= 1;
3049 switches
[i
].valid
= 1;
3056 if (argbuf_index
> 0)
3062 /* Reinitialize for a new command, and for a new argument. */
3065 delete_this_arg
= 0;
3066 this_is_output_file
= 0;
3067 this_is_library_file
= 0;
3068 input_from_pipe
= 0;
3072 /* End any pending argument. */
3075 obstack_1grow (&obstack
, 0);
3076 string
= obstack_finish (&obstack
);
3077 if (this_is_library_file
)
3078 string
= find_file (string
);
3079 store_arg (string
, delete_this_arg
, this_is_output_file
);
3080 if (this_is_output_file
)
3081 outfiles
[input_file_number
] = string
;
3085 obstack_1grow (&obstack
, c
);
3091 /* Space or tab ends an argument if one is pending. */
3094 obstack_1grow (&obstack
, 0);
3095 string
= obstack_finish (&obstack
);
3096 if (this_is_library_file
)
3097 string
= find_file (string
);
3098 store_arg (string
, delete_this_arg
, this_is_output_file
);
3099 if (this_is_output_file
)
3100 outfiles
[input_file_number
] = string
;
3102 /* Reinitialize for a new argument. */
3104 delete_this_arg
= 0;
3105 this_is_output_file
= 0;
3106 this_is_library_file
= 0;
3113 fatal ("Invalid specification! Bug in cc.");
3116 obstack_grow (&obstack
, input_basename
, basename_length
);
3121 delete_this_arg
= 2;
3124 /* Dump out the directories specified with LIBRARY_PATH,
3125 followed by the absolute directories
3126 that we search for startfiles. */
3129 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3131 char *buffer
= (char *) xmalloc (bufsize
);
3134 for (; pl
; pl
= pl
->next
)
3136 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3137 /* Used on systems which record the specified -L dirs
3138 and use them to search for dynamic linking. */
3139 /* Relative directories always come from -B,
3140 and it is better not to use them for searching
3141 at run time. In particular, stage1 loses */
3142 if (pl
->prefix
[0] != '/' && pl
->prefix
[0] != DIR_SEPARATOR
)
3145 /* Try subdirectory if there is one. */
3146 if (multilib_dir
!= NULL
)
3150 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3152 bufsize
= (strlen (pl
->prefix
)
3153 + strlen (machine_suffix
)) * 2 + 1;
3154 buffer
= (char *) xrealloc (buffer
, bufsize
);
3155 strcpy (buffer
, pl
->prefix
);
3156 strcat (buffer
, machine_suffix
);
3157 if (is_directory (buffer
, multilib_dir
, 1))
3159 do_spec_1 ("-L", 0, NULL_PTR
);
3160 #ifdef SPACE_AFTER_L_OPTION
3161 do_spec_1 (" ", 0, NULL_PTR
);
3163 do_spec_1 (buffer
, 1, NULL_PTR
);
3164 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3165 /* Make this a separate argument. */
3166 do_spec_1 (" ", 0, NULL_PTR
);
3169 if (!pl
->require_machine_suffix
)
3171 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3173 do_spec_1 ("-L", 0, NULL_PTR
);
3174 #ifdef SPACE_AFTER_L_OPTION
3175 do_spec_1 (" ", 0, NULL_PTR
);
3177 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3178 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3179 /* Make this a separate argument. */
3180 do_spec_1 (" ", 0, NULL_PTR
);
3186 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3188 do_spec_1 ("-L", 0, NULL_PTR
);
3189 #ifdef SPACE_AFTER_L_OPTION
3190 do_spec_1 (" ", 0, NULL_PTR
);
3192 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3193 /* Remove slash from machine_suffix. */
3194 if (strlen (machine_suffix
) >= bufsize
)
3195 bufsize
= strlen (machine_suffix
) * 2 + 1;
3196 buffer
= (char *) xrealloc (buffer
, bufsize
);
3197 strcpy (buffer
, machine_suffix
);
3198 idx
= strlen (buffer
);
3199 if (buffer
[idx
- 1] == '/'
3200 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3201 buffer
[idx
- 1] = 0;
3202 do_spec_1 (buffer
, 1, NULL_PTR
);
3203 /* Make this a separate argument. */
3204 do_spec_1 (" ", 0, NULL_PTR
);
3207 if (!pl
->require_machine_suffix
)
3209 if (is_directory (pl
->prefix
, "", 1))
3211 do_spec_1 ("-L", 0, NULL_PTR
);
3212 #ifdef SPACE_AFTER_L_OPTION
3213 do_spec_1 (" ", 0, NULL_PTR
);
3215 /* Remove slash from pl->prefix. */
3216 if (strlen (pl
->prefix
) >= bufsize
)
3217 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3218 buffer
= (char *) xrealloc (buffer
, bufsize
);
3219 strcpy (buffer
, pl
->prefix
);
3220 idx
= strlen (buffer
);
3221 if (buffer
[idx
- 1] == '/'
3222 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3223 buffer
[idx
- 1] = 0;
3224 do_spec_1 (buffer
, 1, NULL_PTR
);
3225 /* Make this a separate argument. */
3226 do_spec_1 (" ", 0, NULL_PTR
);
3235 /* {...:%efoo} means report an error with `foo' as error message
3236 and don't execute any more commands for this file. */
3240 while (*p
!= 0 && *p
!= '\n') p
++;
3241 buf
= (char *) alloca (p
- q
+ 1);
3242 strncpy (buf
, q
, p
- q
);
3252 if (save_temps_flag
)
3254 obstack_grow (&obstack
, input_basename
, basename_length
);
3255 delete_this_arg
= 0;
3259 #ifdef MKTEMP_EACH_FILE
3260 /* ??? This has a problem: the total number of
3261 values mktemp can return is limited.
3262 That matters for the names of object files.
3263 In 2.4, do something about that. */
3264 struct temp_name
*t
;
3266 while (*p
== '.' || isalpha (*p
))
3269 /* See if we already have an association of %g/%u/%U and
3271 for (t
= temp_names
; t
; t
= t
->next
)
3272 if (t
->length
== p
- suffix
3273 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3274 && t
->unique
== (c
!= 'g'))
3277 /* Make a new association if needed. %u requires one. */
3278 if (t
== 0 || c
== 'u')
3282 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3283 t
->next
= temp_names
;
3286 t
->length
= p
- suffix
;
3287 t
->suffix
= save_string (suffix
, p
- suffix
);
3288 t
->unique
= (c
!= 'g');
3289 choose_temp_base ();
3290 t
->filename
= temp_filename
;
3291 t
->filename_length
= temp_filename_length
;
3294 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3295 delete_this_arg
= 1;
3297 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3298 if (c
== 'u' || c
== 'U')
3304 sprintf (buff
, "%d", unique
);
3305 obstack_grow (&obstack
, buff
, strlen (buff
));
3308 delete_this_arg
= 1;
3314 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3320 struct prefix_list
*pl
= include_prefixes
.plist
;
3322 if (gcc_exec_prefix
)
3324 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3325 /* Make this a separate argument. */
3326 do_spec_1 (" ", 0, NULL_PTR
);
3327 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3328 do_spec_1 (" ", 0, NULL_PTR
);
3331 for (; pl
; pl
= pl
->next
)
3333 do_spec_1 ("-isystem", 1, NULL_PTR
);
3334 /* Make this a separate argument. */
3335 do_spec_1 (" ", 0, NULL_PTR
);
3336 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3337 do_spec_1 (" ", 0, NULL_PTR
);
3345 for (f
= 0; f
< n_infiles
; f
++)
3346 store_arg (outfiles
[f
], 0, 0);
3351 this_is_library_file
= 1;
3355 this_is_output_file
= 1;
3360 int index
= argbuf_index
;
3361 /* Handle the {...} following the %W. */
3364 p
= handle_braces (p
+ 1);
3367 /* If any args were output, mark the last one for deletion
3369 if (argbuf_index
!= index
)
3370 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3374 /* %x{OPTION} records OPTION for %X to output. */
3380 /* Skip past the option value and make a copy. */
3385 string
= save_string (p1
+ 1, p
- p1
- 2);
3387 /* See if we already recorded this option. */
3388 for (i
= 0; i
< n_linker_options
; i
++)
3389 if (! strcmp (string
, linker_options
[i
]))
3395 /* This option is new; add it. */
3397 if (!linker_options
)
3399 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3402 = (char **) xrealloc (linker_options
,
3403 n_linker_options
* sizeof (char **));
3405 linker_options
[n_linker_options
- 1] = string
;
3409 /* Dump out the options accumulated previously using %x,
3410 -Xlinker and -Wl,. */
3412 for (i
= 0; i
< n_linker_options
; i
++)
3414 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3415 /* Make each accumulated option a separate argument. */
3416 do_spec_1 (" ", 0, NULL_PTR
);
3420 /* Dump out the options accumulated previously using -Wa,. */
3422 for (i
= 0; i
< n_assembler_options
; i
++)
3424 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3425 /* Make each accumulated option a separate argument. */
3426 do_spec_1 (" ", 0, NULL_PTR
);
3430 /* Dump out the options accumulated previously using -Wp,. */
3432 for (i
= 0; i
< n_preprocessor_options
; i
++)
3434 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3435 /* Make each accumulated option a separate argument. */
3436 do_spec_1 (" ", 0, NULL_PTR
);
3440 /* Here are digits and numbers that just process
3441 a certain constant string as a spec. */
3444 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3450 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3456 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3462 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3468 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3474 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3480 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3486 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3492 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3499 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3503 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3507 if (! strncmp (y
, "-D", 2))
3508 /* Copy the whole option. */
3509 while (*y
&& *y
!= ' ' && *y
!= '\t')
3511 else if (*y
== ' ' || *y
== '\t')
3512 /* Copy whitespace to the result. */
3514 /* Don't copy other options. */
3521 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3529 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3533 /* Copy all of CPP_PREDEFINES into BUF,
3534 but put __ after every -D and at the end of each arg. */
3538 if (! strncmp (y
, "-D", 2))
3546 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3548 /* Stick __ at front of macro name. */
3551 /* Arrange to stick __ at the end as well. */
3555 /* Copy the macro name. */
3556 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3565 /* Copy the value given, if any. */
3566 while (*y
&& *y
!= ' ' && *y
!= '\t')
3569 else if (*y
== ' ' || *y
== '\t')
3570 /* Copy whitespace to the result. */
3572 /* Don't copy -A options */
3578 /* Copy all of CPP_PREDEFINES into BUF,
3579 but put __ after every -D. */
3583 if (! strncmp (y
, "-D", 2))
3588 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3590 /* Stick -D__ at front of macro name. */
3596 /* Copy the macro name. */
3597 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3600 /* Copy the value given, if any. */
3601 while (*y
&& *y
!= ' ' && *y
!= '\t')
3606 /* Do not copy this macro - we have just done it before */
3607 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 the -A options in CPP_PREDEFINES into BUF. */
3624 if (! strncmp (y
, "-A", 2))
3625 /* Copy the whole option. */
3626 while (*y
&& *y
!= ' ' && *y
!= '\t')
3628 else if (*y
== ' ' || *y
== '\t')
3629 /* Copy whitespace to the result. */
3631 /* Don't copy other options. */
3638 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3645 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3650 /* Here we define characters other than letters and digits. */
3653 p
= handle_braces (p
);
3659 obstack_1grow (&obstack
, '%');
3663 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3664 do_spec_1 (" ", 0, NULL_PTR
);
3667 /* Process a string found as the value of a spec given by name.
3668 This feature allows individual machine descriptions
3669 to add and use their own specs.
3670 %[...] modifies -D options the way %P does;
3671 %(...) uses the spec unmodified. */
3676 struct spec_list
*sl
;
3679 /* The string after the S/P is the name of a spec that is to be
3681 while (*p
&& *p
!= ')' && *p
!= ']')
3684 /* See if it's in the list */
3685 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3686 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
3696 value
= do_spec_1 (name
, 0, NULL_PTR
);
3702 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3706 /* Copy all of NAME into BUF, but put __ after
3707 every -D and at the end of each arg, */
3710 if (! strncmp (y
, "-D", 2))
3718 else if (*y
== ' ' || *y
== 0)
3732 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3738 /* Discard the closing paren or bracket. */
3746 int c1
= *p
++; /* Select first or second version number. */
3747 char *v
= compiler_version
;
3749 /* If desired, advance to second version number. */
3752 /* Set P after the first period. */
3753 while (*v
!= 0 && *v
!= ' ' && *v
!= '.')
3758 /* Set Q at the next period or at the end. */
3760 while (*q
!= 0 && *q
!= ' ' && *q
!= '.')
3762 /* Empty string means zero. */
3768 /* Put that part into the command. */
3769 obstack_grow (&obstack
, v
, q
- v
);
3775 if (input_from_pipe
)
3776 do_spec_1 ("-", 0, NULL_PTR
);
3785 /* Backslash: treat next character as ordinary. */
3790 /* Ordinary character: put it into the current argument. */
3791 obstack_1grow (&obstack
, c
);
3795 return 0; /* End of string */
3798 /* Return 0 if we call do_spec_1 and that returns -1. */
3811 /* A `|' after the open-brace means,
3812 if the test fails, output a single minus sign rather than nothing.
3813 This is used in %{|!pipe:...}. */
3817 /* A `!' after the open-brace negates the condition:
3818 succeed if the specified switch is not present. */
3822 /* A `.' after the open-brace means test against the current suffix. */
3832 while (*p
!= ':' && *p
!= '}') p
++;
3835 register int count
= 1;
3853 int found
= (input_suffix
!= 0
3854 && strlen (input_suffix
) == p
- filter
3855 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3861 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3866 else if (p
[-1] == '*' && p
[0] == '}')
3868 /* Substitute all matching switches as separate args. */
3871 for (i
= 0; i
< n_switches
; i
++)
3872 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3873 && check_live_switch (i
, p
- filter
))
3878 /* Test for presence of the specified switch. */
3882 /* If name specified ends in *, as in {x*:...},
3883 check for %* and handle that case. */
3884 if (p
[-1] == '*' && !negate
)
3889 /* First see whether we have %*. */
3893 if (*r
== '%' && r
[1] == '*')
3897 /* If we do, handle that case. */
3900 /* Substitute all matching switches as separate args.
3901 But do this by substituting for %*
3902 in the text that follows the colon. */
3904 unsigned hard_match_len
= p
- filter
- 1;
3905 char *string
= save_string (p
+ 1, q
- p
- 2);
3907 for (i
= 0; i
< n_switches
; i
++)
3908 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3909 && check_live_switch (i
, -1))
3911 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
3912 /* Pass any arguments this switch has. */
3920 /* If name specified ends in *, as in {x*:...},
3921 check for presence of any switch name starting with x. */
3924 for (i
= 0; i
< n_switches
; i
++)
3926 unsigned hard_match_len
= p
- filter
- 1;
3928 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3929 && check_live_switch (i
, hard_match_len
))
3935 /* Otherwise, check for presence of exact name specified. */
3938 for (i
= 0; i
< n_switches
; i
++)
3940 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3941 && switches
[i
].part1
[p
- filter
] == 0
3942 && check_live_switch (i
, -1))
3950 /* If it is as desired (present for %{s...}, absent for %{-s...})
3951 then substitute either the switch or the specified
3952 conditional text. */
3953 if (present
!= negate
)
3961 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3967 /* Here if a %{|...} conditional fails: output a minus sign,
3968 which means "standard output" or "standard input". */
3969 do_spec_1 ("-", 0, NULL_PTR
);
3976 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3977 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3978 spec, or -1 if either exact match or %* is used.
3980 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3981 whose value does not begin with "no-" is obsoleted by the same value
3982 with the "no-", similarly for a switch with the "no-" prefix. */
3985 check_live_switch (switchnum
, prefix_length
)
3989 char *name
= switches
[switchnum
].part1
;
3992 /* In the common case of {<at-most-one-letter>*}, a negating
3993 switch would always match, so ignore that case. We will just
3994 send the conflicting switches to the compiler phase. */
3995 if (prefix_length
>= 0 && prefix_length
<= 1)
3998 /* If we already processed this switch and determined if it was
3999 live or not, return our past determination. */
4000 if (switches
[switchnum
].live_cond
!= 0)
4001 return switches
[switchnum
].live_cond
> 0;
4003 /* Now search for duplicate in a manner that depends on the name. */
4007 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4008 if (switches
[i
].part1
[0] == 'O')
4010 switches
[switchnum
].valid
= 1;
4011 switches
[switchnum
].live_cond
= -1;
4016 case 'W': case 'f': case 'm':
4017 if (! strncmp (name
+ 1, "no-", 3))
4019 /* We have Xno-YYY, search for XYYY. */
4020 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4021 if (switches
[i
].part1
[0] == name
[0]
4022 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4024 switches
[switchnum
].valid
= 1;
4025 switches
[switchnum
].live_cond
= -1;
4031 /* We have XYYY, search for Xno-YYY. */
4032 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4033 if (switches
[i
].part1
[0] == name
[0]
4034 && switches
[i
].part1
[1] == 'n'
4035 && switches
[i
].part1
[2] == 'o'
4036 && switches
[i
].part1
[3] == '-'
4037 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4039 switches
[switchnum
].valid
= 1;
4040 switches
[switchnum
].live_cond
= -1;
4047 /* Otherwise the switch is live. */
4048 switches
[switchnum
].live_cond
= 1;
4052 /* Pass a switch to the current accumulating command
4053 in the same form that we received it.
4054 SWITCHNUM identifies the switch; it is an index into
4055 the vector of switches gcc received, which is `switches'.
4056 This cannot fail since it never finishes a command line.
4058 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
4061 give_switch (switchnum
, omit_first_word
)
4063 int omit_first_word
;
4065 if (!omit_first_word
)
4067 do_spec_1 ("-", 0, NULL_PTR
);
4068 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4070 do_spec_1 (" ", 0, NULL_PTR
);
4071 if (switches
[switchnum
].args
!= 0)
4074 for (p
= switches
[switchnum
].args
; *p
; p
++)
4076 do_spec_1 (*p
, 1, NULL_PTR
);
4077 do_spec_1 (" ", 0, NULL_PTR
);
4080 switches
[switchnum
].valid
= 1;
4083 /* Search for a file named NAME trying various prefixes including the
4084 user's -B prefix and some standard ones.
4085 Return the absolute file name found. If nothing is found, return NAME. */
4093 /* Try multilib_dir if it is defined. */
4094 if (multilib_dir
!= NULL
)
4098 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4099 strcpy (try, multilib_dir
);
4100 strcat (try, dir_separator_str
);
4103 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4105 /* If we don't find it in the multi library dir, then fall
4106 through and look for it in the normal places. */
4107 if (newname
!= NULL
)
4111 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4112 return newname
? newname
: name
;
4115 /* Determine whether a directory exists. If LINKER, return 0 for
4116 certain fixed names not needed by the linker. If not LINKER, it is
4117 only important to return 0 if the host machine has a small ARG_MAX
4121 is_directory (path1
, path2
, linker
)
4126 int len1
= strlen (path1
);
4127 int len2
= strlen (path2
);
4128 char *path
= (char *) alloca (3 + len1
+ len2
);
4132 #ifndef SMALL_ARG_MAX
4137 /* Construct the path from the two parts. Ensure the string ends with "/.".
4138 The resulting path will be a directory even if the given path is a
4140 bcopy (path1
, path
, len1
);
4141 bcopy (path2
, path
+ len1
, len2
);
4142 cp
= path
+ len1
+ len2
;
4143 if (cp
[-1] != '/' && cp
[-1] != DIR_SEPARATOR
)
4144 *cp
++ = DIR_SEPARATOR
;
4148 /* Exclude directories that the linker is known to search. */
4151 && strcmp (path
, concat4 (dir_separator_str
, "lib",
4152 dir_separator_str
, ".")) == 0)
4154 && strcmp (path
, concat6 (dir_separator_str
, "usr",
4155 dir_separator_str
, "lib",
4156 dir_separator_str
, ".")) == 0)))
4159 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4162 /* On fatal signals, delete all the temporary files. */
4165 fatal_error (signum
)
4168 signal (signum
, SIG_DFL
);
4169 delete_failure_queue ();
4170 delete_temp_files ();
4171 /* Get the same signal again, this time not handled,
4172 so its normal effect occurs. */
4173 kill (getpid (), signum
);
4184 int linker_was_run
= 0;
4185 char *explicit_link_files
;
4189 p
= argv
[0] + strlen (argv
[0]);
4190 while (p
!= argv
[0] && p
[-1] != '/' && p
[-1] != DIR_SEPARATOR
) --p
;
4193 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4194 signal (SIGINT
, fatal_error
);
4196 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4197 signal (SIGHUP
, fatal_error
);
4199 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4200 signal (SIGTERM
, fatal_error
);
4202 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4203 signal (SIGPIPE
, fatal_error
);
4207 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4209 obstack_init (&obstack
);
4211 /* Set up to remember the pathname of gcc and any options
4212 needed for collect. We use argv[0] instead of programname because
4213 we need the complete pathname. */
4214 obstack_init (&collect_obstack
);
4215 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4216 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4217 putenv (obstack_finish (&collect_obstack
));
4219 /* Choose directory for temp files. */
4221 choose_temp_base ();
4223 /* Make a table of what switches there are (switches, n_switches).
4224 Make a table of specified input files (infiles, n_infiles).
4225 Decode switches that are handled locally. */
4227 process_command (argc
, argv
);
4229 /* Initialize the vector of specs to just the default.
4230 This means one element containing 0s, as a terminator. */
4232 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4233 bcopy ((char *) default_compilers
, (char *) compilers
,
4234 sizeof default_compilers
);
4235 n_compilers
= n_default_compilers
;
4237 /* Read specs from a file if there is one. */
4239 machine_suffix
= concat4 (spec_machine
, dir_separator_str
,
4240 spec_version
, dir_separator_str
);
4241 just_machine_suffix
= concat (spec_machine
, dir_separator_str
);
4243 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4244 /* Read the specs file unless it is a default one. */
4245 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4246 read_specs (specs_file
);
4248 /* If not cross-compiling, look for startfiles in the standard places. */
4249 /* The fact that these are done here, after reading the specs file,
4250 means that it cannot be found in these directories.
4251 But that's okay. It should never be there anyway. */
4254 #ifdef MD_EXEC_PREFIX
4255 add_prefix (&exec_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4256 add_prefix (&startfile_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4259 #ifdef MD_STARTFILE_PREFIX
4260 add_prefix (&startfile_prefixes
, md_startfile_prefix
, 0, 0, NULL_PTR
);
4263 #ifdef MD_STARTFILE_PREFIX_1
4264 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, 0, 0, NULL_PTR
);
4267 /* If standard_startfile_prefix is relative, base it on
4268 standard_exec_prefix. This lets us move the installed tree
4269 as a unit. If GCC_EXEC_PREFIX is defined, base
4270 standard_startfile_prefix on that as well. */
4271 if (*standard_startfile_prefix
== '/'
4272 || *standard_startfile_prefix
== DIR_SEPARATOR
)
4273 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, 0, 0,
4277 if (gcc_exec_prefix
)
4278 add_prefix (&startfile_prefixes
,
4279 concat (gcc_exec_prefix
, standard_startfile_prefix
),
4281 add_prefix (&startfile_prefixes
,
4282 concat3 (standard_exec_prefix
,
4284 standard_startfile_prefix
),
4288 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
, 0, 0,
4290 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
, 0, 0,
4292 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4293 add_prefix (&startfile_prefixes
, "./", 0, 1, NULL_PTR
);
4297 /* Now we have the specs.
4298 Set the `valid' bits for switches that match anything in any spec. */
4300 validate_all_switches ();
4302 /* Now that we have the switches and the specs, set
4303 the subdirectory based on the options. */
4304 set_multilib_dir ();
4306 /* Warn about any switches that no pass was interested in. */
4308 for (i
= 0; i
< n_switches
; i
++)
4309 if (! switches
[i
].valid
)
4310 error ("unrecognized option `-%s'", switches
[i
].part1
);
4312 /* Obey some of the options. */
4314 if (print_file_name
)
4316 printf ("%s\n", find_file (print_file_name
));
4320 if (print_prog_name
)
4322 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4323 printf ("%s\n", (newname
? newname
: print_prog_name
));
4327 if (print_multi_lib
)
4329 print_multilib_info ();
4333 if (print_multi_directory
)
4335 if (multilib_dir
== NULL
)
4338 printf ("%s\n", multilib_dir
);
4344 fprintf (stderr
, "gcc version %s\n", version_string
);
4350 fatal ("No input files");
4352 /* Make a place to record the compiler output file names
4353 that correspond to the input files. */
4355 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4356 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4358 /* Record which files were specified explicitly as link input. */
4360 explicit_link_files
= xmalloc (n_infiles
);
4361 bzero (explicit_link_files
, n_infiles
);
4363 for (i
= 0; i
< n_infiles
; i
++)
4365 register struct compiler
*cp
= 0;
4366 int this_file_error
= 0;
4368 /* Tell do_spec what to substitute for %i. */
4370 input_filename
= infiles
[i
].name
;
4371 input_filename_length
= strlen (input_filename
);
4372 input_file_number
= i
;
4374 /* Use the same thing in %o, unless cp->spec says otherwise. */
4376 outfiles
[i
] = input_filename
;
4378 /* Figure out which compiler from the file's suffix. */
4380 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4381 infiles
[i
].language
);
4385 /* Ok, we found an applicable compiler. Run its spec. */
4386 /* First say how much of input_filename to substitute for %b */
4390 input_basename
= input_filename
;
4391 for (p
= input_filename
; *p
; p
++)
4392 if (*p
== '/' || *p
== DIR_SEPARATOR
)
4393 input_basename
= p
+ 1;
4395 /* Find a suffix starting with the last period,
4396 and set basename_length to exclude that suffix. */
4397 basename_length
= strlen (input_basename
);
4398 p
= input_basename
+ basename_length
;
4399 while (p
!= input_basename
&& *p
!= '.') --p
;
4400 if (*p
== '.' && p
!= input_basename
)
4402 basename_length
= p
- input_basename
;
4403 input_suffix
= p
+ 1;
4409 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4411 len
+= strlen (cp
->spec
[j
]);
4413 p
= (char *) xmalloc (len
+ 1);
4416 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4419 strcpy (p
+ len
, cp
->spec
[j
]);
4420 len
+= strlen (cp
->spec
[j
]);
4423 value
= do_spec (p
);
4426 this_file_error
= 1;
4429 /* If this file's name does not contain a recognized suffix,
4430 record it as explicit linker input. */
4433 explicit_link_files
[i
] = 1;
4435 /* Clear the delete-on-failure queue, deleting the files in it
4436 if this compilation failed. */
4438 if (this_file_error
)
4440 delete_failure_queue ();
4443 /* If this compilation succeeded, don't delete those files later. */
4444 clear_failure_queue ();
4447 /* Run ld to link all the compiler output files. */
4449 if (error_count
== 0)
4451 int tmp
= execution_count
;
4455 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4457 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
4458 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
4460 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4462 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4463 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4466 for (i
= 0; i
< n_switches
; i
++)
4470 obstack_grow (&collect_obstack
, " ", 1);
4473 obstack_grow (&collect_obstack
, "-", 1);
4474 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4475 strlen (switches
[i
].part1
));
4477 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4479 obstack_grow (&collect_obstack
, " ", 1);
4480 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4483 obstack_grow (&collect_obstack
, "\0", 1);
4484 putenv (obstack_finish (&collect_obstack
));
4486 value
= do_spec (link_command_spec
);
4489 linker_was_run
= (tmp
!= execution_count
);
4492 /* Warn if a -B option was specified but the prefix was never used. */
4493 unused_prefix_warnings (&exec_prefixes
);
4494 unused_prefix_warnings (&startfile_prefixes
);
4496 /* If options said don't run linker,
4497 complain about input files to be given to the linker. */
4499 if (! linker_was_run
&& error_count
== 0)
4500 for (i
= 0; i
< n_infiles
; i
++)
4501 if (explicit_link_files
[i
])
4502 error ("%s: linker input file unused since linking not done",
4505 /* Delete some or all of the temporary files we made. */
4508 delete_failure_queue ();
4509 delete_temp_files ();
4511 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4516 /* Find the proper compilation spec for the file name NAME,
4517 whose length is LENGTH. LANGUAGE is the specified language,
4518 or 0 if none specified. */
4520 static struct compiler
*
4521 lookup_compiler (name
, length
, language
)
4526 struct compiler
*cp
;
4528 /* Look for the language, if one is spec'd. */
4531 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4535 if (cp
->suffix
[0] == '@'
4536 && !strcmp (cp
->suffix
+ 1, language
))
4540 error ("language %s not recognized", language
);
4543 /* Look for a suffix. */
4544 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4546 if (/* The suffix `-' matches only the file name `-'. */
4547 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4549 (strlen (cp
->suffix
) < length
4550 /* See if the suffix matches the end of NAME. */
4552 && (!strcmp (cp
->suffix
,
4553 name
+ length
- strlen (cp
->suffix
))
4554 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4555 && !strcasecmp (cp
->suffix
,
4556 name
+ length
- strlen (cp
->suffix
)))))
4558 && !strcmp (cp
->suffix
,
4559 name
+ length
- strlen (cp
->suffix
))))
4562 if (cp
->spec
[0][0] == '@')
4564 struct compiler
*new;
4565 /* An alias entry maps a suffix to a language.
4566 Search for the language; pass 0 for NAME and LENGTH
4567 to avoid infinite recursion if language not found.
4568 Construct the new compiler spec. */
4569 language
= cp
->spec
[0] + 1;
4570 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4571 new->suffix
= cp
->suffix
;
4572 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4573 (char *) new->spec
, sizeof new->spec
);
4576 /* A non-alias entry: return it. */
4588 register char *value
= (char *) malloc (size
);
4590 fatal ("virtual memory exhausted");
4595 xrealloc (ptr
, size
)
4599 register char *value
= (char *) realloc (ptr
, size
);
4601 fatal ("virtual memory exhausted");
4605 /* Return a newly-allocated string whose contents concatenate those of s1, s2 */
4611 int len1
= strlen (s1
);
4612 int len2
= strlen (s2
);
4613 char *result
= xmalloc (len1
+ len2
+ 1);
4615 strcpy (result
, s1
);
4616 strcpy (result
+ len1
, s2
);
4617 *(result
+ len1
+ len2
) = 0;
4623 concat3 (s1
, s2
, s3
)
4626 return concat (concat (s1
, s2
), s3
);
4630 concat4 (s1
, s2
, s3
, s4
)
4631 char *s1
, *s2
, *s3
, *s4
;
4633 return concat (concat (s1
, s2
), concat (s3
, s4
));
4637 concat6 (s1
, s2
, s3
, s4
, s5
, s6
)
4638 char *s1
, *s2
, *s3
, *s4
, *s5
, *s6
;
4640 return concat3 (concat (s1
, s2
), concat (s3
, s4
), concat (s5
, s6
));
4644 save_string (s
, len
)
4648 register char *result
= xmalloc (len
+ 1);
4650 bcopy (s
, result
, len
);
4656 pfatal_with_name (name
)
4661 if (errno
< sys_nerr
)
4662 s
= concat ("%s: ", sys_errlist
[errno
]);
4664 s
= "cannot open %s";
4669 perror_with_name (name
)
4674 if (errno
< sys_nerr
)
4675 s
= concat ("%s: ", sys_errlist
[errno
]);
4677 s
= "cannot open %s";
4687 if (errno
< sys_nerr
)
4688 s
= concat ("installation problem, cannot exec %s: ", sys_errlist
[errno
]);
4690 s
= "installation problem, cannot exec %s";
4694 /* More 'friendly' abort that prints the line and file.
4695 config.h can #define abort fancy_abort if you like that sort of thing. */
4700 fatal ("Internal gcc abort.");
4705 /* Output an error message and exit */
4708 fatal
VPROTO((char *format
, ...))
4715 VA_START (ap
, format
);
4718 format
= va_arg (ap
, char*);
4721 fprintf (stderr
, "%s: ", programname
);
4722 vfprintf (stderr
, format
, ap
);
4724 fprintf (stderr
, "\n");
4725 delete_temp_files ();
4730 error
VPROTO((char *format
, ...))
4737 VA_START (ap
, format
);
4740 format
= va_arg (ap
, char*);
4743 fprintf (stderr
, "%s: ", programname
);
4744 vfprintf (stderr
, format
, ap
);
4747 fprintf (stderr
, "\n");
4750 #else /* not HAVE_VPRINTF */
4753 fatal (msg
, arg1
, arg2
)
4754 char *msg
, *arg1
, *arg2
;
4756 error (msg
, arg1
, arg2
);
4757 delete_temp_files ();
4762 error (msg
, arg1
, arg2
)
4763 char *msg
, *arg1
, *arg2
;
4765 fprintf (stderr
, "%s: ", programname
);
4766 fprintf (stderr
, msg
, arg1
, arg2
);
4767 fprintf (stderr
, "\n");
4770 #endif /* not HAVE_VPRINTF */
4774 validate_all_switches ()
4776 struct compiler
*comp
;
4779 struct spec_list
*spec
;
4781 for (comp
= compilers
; comp
->spec
[0]; comp
++)
4784 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
4788 if (c
== '%' && *p
== '{')
4789 /* We have a switch spec. */
4790 validate_switches (p
+ 1);
4794 /* look through the linked list of extra specs read from the specs file */
4795 for (spec
= specs
; spec
; spec
= spec
->next
)
4799 if (c
== '%' && *p
== '{')
4800 /* We have a switch spec. */
4801 validate_switches (p
+ 1);
4804 p
= link_command_spec
;
4806 if (c
== '%' && *p
== '{')
4807 /* We have a switch spec. */
4808 validate_switches (p
+ 1);
4810 /* Now notice switches mentioned in the machine-specific specs. */
4814 if (c
== '%' && *p
== '{')
4815 /* We have a switch spec. */
4816 validate_switches (p
+ 1);
4820 if (c
== '%' && *p
== '{')
4821 /* We have a switch spec. */
4822 validate_switches (p
+ 1);
4826 if (c
== '%' && *p
== '{')
4827 /* We have a switch spec. */
4828 validate_switches (p
+ 1);
4830 p
= signed_char_spec
;
4832 if (c
== '%' && *p
== '{')
4833 /* We have a switch spec. */
4834 validate_switches (p
+ 1);
4838 if (c
== '%' && *p
== '{')
4839 /* We have a switch spec. */
4840 validate_switches (p
+ 1);
4844 if (c
== '%' && *p
== '{')
4845 /* We have a switch spec. */
4846 validate_switches (p
+ 1);
4850 if (c
== '%' && *p
== '{')
4851 /* We have a switch spec. */
4852 validate_switches (p
+ 1);
4856 if (c
== '%' && *p
== '{')
4857 /* We have a switch spec. */
4858 validate_switches (p
+ 1);
4862 if (c
== '%' && *p
== '{')
4863 /* We have a switch spec. */
4864 validate_switches (p
+ 1);
4867 /* Look at the switch-name that comes after START
4868 and mark as valid all supplied switches that match it. */
4871 validate_switches (start
)
4874 register char *p
= start
;
4889 while (*p
!= ':' && *p
!= '}') p
++;
4893 else if (p
[-1] == '*')
4895 /* Mark all matching switches as valid. */
4897 for (i
= 0; i
< n_switches
; i
++)
4898 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
4899 switches
[i
].valid
= 1;
4903 /* Mark an exact matching switch as valid. */
4904 for (i
= 0; i
< n_switches
; i
++)
4906 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4907 && switches
[i
].part1
[p
- filter
] == 0)
4908 switches
[i
].valid
= 1;
4913 /* Check whether a particular argument was used. */
4922 for (i
= 0; i
< n_switches
; i
++)
4923 if (! strncmp (switches
[i
].part1
, p
, len
)
4924 && strlen (switches
[i
].part1
) == len
)
4929 /* Work out the subdirectory to use based on the
4930 options. The format of multilib_select is a list of elements.
4931 Each element is a subdirectory name followed by a list of options
4932 followed by a semicolon. gcc will consider each line in turn. If
4933 none of the options beginning with an exclamation point are
4934 present, and all of the other options are present, that
4935 subdirectory will be used. */
4940 char *p
= multilib_select
;
4942 char *this_path
, *this_arg
;
4947 /* Ignore newlines. */
4954 /* Get the initial path. */
4962 this_path_len
= p
- this_path
;
4964 /* Check the arguments. */
4979 while (*p
!= ' ' && *p
!= ';')
4986 if (*this_arg
== '!')
4987 failed
= used_arg (this_arg
+ 1, p
- (this_arg
+ 1));
4989 failed
= ! used_arg (this_arg
, p
- this_arg
);
4997 if (this_path_len
!= 1
4998 || this_path
[0] != '.')
5000 multilib_dir
= xmalloc (this_path_len
+ 1);
5001 strncpy (multilib_dir
, this_path
, this_path_len
);
5002 multilib_dir
[this_path_len
] = '\0';
5011 /* Print out the multiple library subdirectory selection
5012 information. This prints out a series of lines. Each line looks
5013 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5014 required. Only the desired options are printed out, the negative
5015 matches. The options are print without a leading dash. There are
5016 no spaces to make it easy to use the information in the shell.
5017 Each subdirectory is printed only once. This assumes the ordering
5018 generated by the genmultilib script. */
5021 print_multilib_info ()
5023 char *p
= multilib_select
;
5024 char *last_path
, *this_path
;
5025 int last_path_len
, skip
, use_arg
;
5029 /* Ignore newlines. */
5036 /* Get the initial path. */
5045 /* If this is a duplicate, skip it. */
5046 skip
= (p
- this_path
== last_path_len
5047 && ! strncmp (last_path
, this_path
, last_path_len
));
5049 last_path
= this_path
;
5050 last_path_len
= p
- this_path
;
5056 for (p1
= last_path
; p1
< p
; p1
++)
5075 use_arg
= *p
!= '!';
5080 while (*p
!= ' ' && *p
!= ';')