1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 This paragraph is here to try to keep Sun CC from dying.
21 The number of chars here seems crucial!!!! */
23 /* This program is the user interface to the C compiler and possibly to
24 other compilers. It is used because compilation is a complicated procedure
25 which involves running several programs and passing temporary files between
26 them, forwarding the users switches to those programs selectively,
27 and deleting the temporary files at the end.
29 CC recognizes how to compile each input file by suffixes in the file names.
30 Once it knows which kind of compilation to perform, the procedure for
31 compilation is specified by a string called a "spec". */
33 #include <sys/types.h>
37 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
38 #include <sys/errno.h>
49 /* Include multi-lib information. */
58 /* Add prototype support. */
60 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
61 #define PROTO(ARGS) ARGS
63 #define PROTO(ARGS) ()
69 #define PVPROTO(ARGS) ARGS
70 #define VPROTO(ARGS) ARGS
71 #define VA_START(va_list,var) va_start(va_list,var)
73 #define PVPROTO(ARGS) ()
74 #define VPROTO(ARGS) (va_alist) va_dcl
75 #define VA_START(va_list,var) va_start(va_list)
79 /* Define a generic NULL if one hasn't already been defined. */
86 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
87 #define GENERIC_PTR void *
89 #define GENERIC_PTR char *
94 #define NULL_PTR ((GENERIC_PTR)0)
101 /* On MSDOS, write temp files in current dir
102 because there's no place else we can expect to use. */
109 /* Test if something is a normal file. */
111 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
114 /* Test if something is a directory. */
116 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
119 /* By default there is no special suffix for executables. */
120 #ifndef EXECUTABLE_SUFFIX
121 #define EXECUTABLE_SUFFIX ""
124 /* By default, colon separates directories in a path. */
125 #ifndef PATH_SEPARATOR
126 #define PATH_SEPARATOR ':'
129 #define obstack_chunk_alloc xmalloc
130 #define obstack_chunk_free free
133 extern char *getenv ();
135 extern int errno
, sys_nerr
;
136 #if defined(bsd4_4) || defined(__NetBSD__)
137 extern const char *const sys_errlist
[];
139 extern char *sys_errlist
[];
142 extern int execv (), execvp ();
144 /* If a stage of compilation returns an exit status >= 1,
145 compilation of that file ceases. */
147 #define MIN_FATAL_STATUS 1
149 /* Flag saying to print the full filename of this file
150 as found through our usual search mechanism. */
152 static char *print_file_name
= NULL
;
154 /* As print_file_name, but search for executable file. */
156 static char *print_prog_name
= NULL
;
158 /* Flag saying to print the relative path we'd use to
159 find libgcc.a given the current compiler flags. */
161 static int print_multi_directory
;
163 /* Flag saying to print the list of subdirectories and
164 compiler flags used to select them in a standard form. */
166 static int print_multi_lib
;
168 /* Flag indicating whether we should print the command and arguments */
170 static int verbose_flag
;
172 /* Nonzero means write "temp" files in source directory
173 and use the source file's name in them, and don't delete them. */
175 static int save_temps_flag
;
177 /* The compiler version. */
179 static char *compiler_version
;
181 /* The target version specified with -V */
183 static char *spec_version
= DEFAULT_TARGET_VERSION
;
185 /* The target machine specified with -b. */
187 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
189 /* Nonzero if cross-compiling.
190 When -b is used, the value comes from the `specs' file. */
193 static int cross_compile
= 1;
195 static int cross_compile
= 0;
198 /* The number of errors that have occurred; the link phase will not be
199 run if this is non-zero. */
200 static int error_count
= 0;
202 /* This is the obstack which we use to allocate many strings. */
204 static struct obstack obstack
;
206 /* This is the obstack to build an environment variable to pass to
207 collect2 that describes all of the relevant switches of what to
208 pass the compiler in building the list of pointers to constructors
211 static struct obstack collect_obstack
;
213 extern char *version_string
;
215 /* Forward declaration for prototypes. */
218 static void set_spec
PROTO((char *, char *));
219 static struct compiler
*lookup_compiler
PROTO((char *, int, char *));
220 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
221 static void add_prefix
PROTO((struct path_prefix
*, char *, int, int, int *));
222 static char *skip_whitespace
PROTO((char *));
223 static void record_temp_file
PROTO((char *, int, int));
224 static void delete_if_ordinary
PROTO((char *));
225 static void delete_temp_files
PROTO((void));
226 static void delete_failure_queue
PROTO((void));
227 static void clear_failure_queue
PROTO((void));
228 static char *choose_temp_base_try
PROTO((char *, char *));
229 static void choose_temp_base
PROTO((void));
230 static int check_live_switch
PROTO((int, int));
231 static char *handle_braces
PROTO((char *));
232 static char *save_string
PROTO((char *, int));
233 static char *concat
PROTO((char *, char *, char *));
234 static int do_spec
PROTO((char *));
235 static int do_spec_1
PROTO((char *, int, char *));
236 static char *find_file
PROTO((char *));
237 static int is_directory
PROTO((char *, char *, int));
238 static void validate_switches
PROTO((char *));
239 static void validate_all_switches
PROTO((void));
240 static void give_switch
PROTO((int, int));
241 static int used_arg
PROTO((char *, int));
242 static void set_multilib_dir
PROTO((void));
243 static void print_multilib_info
PROTO((void));
244 static void pfatal_with_name
PROTO((char *));
245 static void perror_with_name
PROTO((char *));
246 static void perror_exec
PROTO((char *));
248 static void fatal
PVPROTO((char *, ...));
249 static void error
PVPROTO((char *, ...));
251 /* We must not provide any prototype here, even if ANSI C. */
252 static void fatal
PROTO(());
253 static void error
PROTO(());
260 /* Specs are strings containing lines, each of which (if not blank)
261 is made up of a program name, and arguments separated by spaces.
262 The program name must be exact and start from root, since no path
263 is searched and it is unreliable to depend on the current working directory.
264 Redirection of input or output is not supported; the subprograms must
265 accept filenames saying what files to read and write.
267 In addition, the specs can contain %-sequences to substitute variable text
268 or for conditional text. Here is a table of all defined %-sequences.
269 Note that spaces are not generated automatically around the results of
270 expanding these sequences; therefore, you can concatenate them together
271 or with constant text in a single argument.
273 %% substitute one % into the program name or argument.
274 %i substitute the name of the input file being processed.
275 %b substitute the basename of the input file being processed.
276 This is the substring up to (and not including) the last period
277 and not including the directory.
278 %g substitute the temporary-file-name-base. This is a string chosen
279 once per compilation. Different temporary file names are made by
280 concatenation of constant strings on the end, as in `%g.s'.
281 %g also has the same effect of %d.
282 %u like %g, but make the temporary file name unique.
283 %U returns the last file name generated with %u.
284 %d marks the argument containing or following the %d as a
285 temporary file name, so that that file will be deleted if CC exits
286 successfully. Unlike %g, this contributes no text to the argument.
287 %w marks the argument containing or following the %w as the
288 "output file" of this compilation. This puts the argument
289 into the sequence of arguments that %o will substitute later.
291 like %{...} but mark last argument supplied within
292 as a file to be deleted on failure.
293 %o substitutes the names of all the output files, with spaces
294 automatically placed around them. You should write spaces
295 around the %o as well or the results are undefined.
296 %o is for use in the specs for running the linker.
297 Input files whose names have no recognized suffix are not compiled
298 at all, but they are included among the output files, so they will
300 %p substitutes the standard macro predefinitions for the
301 current target machine. Use this when running cpp.
302 %P like %p, but puts `__' before and after the name of each macro.
303 (Except macros that already have __.)
305 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
306 %s current argument is the name of a library or startup file of some sort.
307 Search for that file in a standard list of directories
308 and substitute the full name found.
309 %eSTR Print STR as an error message. STR is terminated by a newline.
310 Use this when inconsistent options are detected.
311 %x{OPTION} Accumulate an option for %X.
312 %X Output the accumulated linker options specified by compilations.
313 %Y Output the accumulated assembler options specified by compilations.
314 %v1 Substitute the major version number of GCC.
315 (For version 2.5.n, this is 2.)
316 %v2 Substitute the minor version number of GCC.
317 (For version 2.5.n, this is 5.)
318 %a process ASM_SPEC as a spec.
319 This allows config.h to specify part of the spec for running as.
320 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
321 used here. This can be used to run a post-processor after the
322 assembler has done it's job.
323 %D Dump out a -L option for each directory in startfile_prefix.
324 If multilib_dir is set, extra entries are generated with it affixed.
325 %l process LINK_SPEC as a spec.
326 %L process LIB_SPEC as a spec.
327 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
328 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
329 %c process SIGNED_CHAR_SPEC as a spec.
330 %C process CPP_SPEC as a spec. A capital C is actually used here.
331 %1 process CC1_SPEC as a spec.
332 %2 process CC1PLUS_SPEC as a spec.
333 %| output "-" if the input for the current command is coming from a pipe.
334 %* substitute the variable part of a matched option. (See below.)
335 Note that each comma in the substituted string is replaced by
337 %{S} substitutes the -S switch, if that switch was given to CC.
338 If that switch was not specified, this substitutes nothing.
339 Here S is a metasyntactic variable.
340 %{S*} substitutes all the switches specified to CC whose names start
341 with -S. This is used for -o, -D, -I, etc; switches that take
342 arguments. CC considers `-o foo' as being one switch whose
343 name starts with `o'. %{o*} would substitute this text,
344 including the space; thus, two arguments would be generated.
345 %{S*:X} substitutes X if one or more switches whose names start with -S are
346 specified to CC. Note that the tail part of the -S option
347 (i.e. the part matched by the `*') will be substituted for each
348 occurrence of %* within X.
349 %{S:X} substitutes X, but only if the -S switch was given to CC.
350 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
351 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
352 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
353 %{.S:X} substitutes X, but only if processing a file with suffix S.
354 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
355 %(Spec) processes a specification defined in a specs file as *Spec:
356 %[Spec] as above, but put __ around -D arguments
358 The conditional text X in a %{S:X} or %{!S:X} construct may contain
359 other nested % constructs or spaces, or even newlines. They are
360 processed as usual, as described above.
362 The -O, -f, -m, and -W switches are handled specifically in these
363 constructs. If another value of -O or the negated form of a -f, -m, or
364 -W switch is found later in the command line, the earlier switch
365 value is ignored, except with {S*} where S is just one letter; this
366 passes all matching options.
368 The character | is used to indicate that a command should be piped to
369 the following command, but only if -pipe is specified.
371 Note that it is built into CC which switches take arguments and which
372 do not. You might think it would be useful to generalize this to
373 allow each compiler's spec to say which switches take arguments. But
374 this cannot be done in a consistent fashion. CC cannot even decide
375 which input files have been specified without knowing which switches
376 take arguments, and it must know which input files to compile in order
377 to tell which compilers to run.
379 CC also knows implicitly that arguments starting in `-l' are to be
380 treated as compiler output files, and passed to the linker in their
381 proper position among the other output files. */
383 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
385 /* config.h can define ASM_SPEC to provide extra args to the assembler
386 or extra switch-translations. */
391 /* config.h can define ASM_FINAL_SPEC to run a post processor after
392 the assembler has run. */
393 #ifndef ASM_FINAL_SPEC
394 #define ASM_FINAL_SPEC ""
397 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
398 or extra switch-translations. */
403 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
404 or extra switch-translations. */
409 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
410 or extra switch-translations. */
412 #define CC1PLUS_SPEC ""
415 /* config.h can define LINK_SPEC to provide extra args to the linker
416 or extra switch-translations. */
421 /* config.h can define LIB_SPEC to override the default libraries. */
423 #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
426 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
427 #ifndef STARTFILE_SPEC
428 #define STARTFILE_SPEC \
429 "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
432 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
433 Make the string nonempty to require spaces there. */
434 #ifndef SWITCHES_NEED_SPACES
435 #define SWITCHES_NEED_SPACES ""
438 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
440 #define ENDFILE_SPEC ""
443 /* This spec is used for telling cpp whether char is signed or not. */
444 #ifndef SIGNED_CHAR_SPEC
445 /* Use #if rather than ?:
446 because MIPS C compiler rejects like ?: in initializers. */
447 #if DEFAULT_SIGNED_CHAR
448 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
450 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
454 /* MULTILIB_SELECT comes from multilib.h. It gives a
455 string interpreted by set_multilib_dir to select a library
456 subdirectory based on the compiler options. */
457 #ifndef MULTILIB_SELECT
458 #define MULTILIB_SELECT ". ;"
461 static char *cpp_spec
= CPP_SPEC
;
462 static char *cpp_predefines
= CPP_PREDEFINES
;
463 static char *cc1_spec
= CC1_SPEC
;
464 static char *cc1plus_spec
= CC1PLUS_SPEC
;
465 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
466 static char *asm_spec
= ASM_SPEC
;
467 static char *asm_final_spec
= ASM_FINAL_SPEC
;
468 static char *link_spec
= LINK_SPEC
;
469 static char *lib_spec
= LIB_SPEC
;
470 static char *endfile_spec
= ENDFILE_SPEC
;
471 static char *startfile_spec
= STARTFILE_SPEC
;
472 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
473 static char *multilib_select
= MULTILIB_SELECT
;
475 /* This defines which switch letters take arguments. */
477 #ifndef SWITCH_TAKES_ARG
478 #define SWITCH_TAKES_ARG(CHAR) \
479 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
480 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
481 || (CHAR) == 'I' || (CHAR) == 'm' \
482 || (CHAR) == 'L' || (CHAR) == 'A')
485 /* This defines which multi-letter switches take arguments. */
487 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
488 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
489 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
490 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
491 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
492 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
493 || !strcmp (STR, "isystem"))
495 #ifndef WORD_SWITCH_TAKES_ARG
496 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
499 /* Record the mapping from file suffixes for compilation specs. */
503 char *suffix
; /* Use this compiler for input files
504 whose names end in this suffix. */
506 char *spec
[4]; /* To use this compiler, concatenate these
507 specs and pass to do_spec. */
510 /* Pointer to a vector of `struct compiler' that gives the spec for
511 compiling a file, based on its suffix.
512 A file that does not end in any of these suffixes will be passed
513 unchanged to the loader and nothing else will be done to it.
515 An entry containing two 0s is used to terminate the vector.
517 If multiple entries match a file, the last matching one is used. */
519 static struct compiler
*compilers
;
521 /* Number of entries in `compilers', not counting the null terminator. */
523 static int n_compilers
;
525 /* The default list of file name suffixes and their compilation specs. */
527 static struct compiler default_compilers
[] =
531 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
532 %{C:%{!E:%eGNU C does not support -C without using -E}}\
533 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
534 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
535 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
536 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
537 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
538 %{traditional-cpp:-traditional}\
539 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
540 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
541 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
542 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
543 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
544 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
546 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
547 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
548 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
549 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
550 %{!pipe:%g.s} %A\n }}}}"},
552 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
553 %{C:%{!E:%eGNU C does not support -C without using -E}}\
554 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
555 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
556 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
557 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
558 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
559 %{traditional-cpp:-traditional}\
560 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
562 %{!E:%e-E required when input is from standard input}"},
563 {".m", "@objective-c"},
565 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
566 %{C:%{!E:%eGNU C does not support -C without using -E}}\
567 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
568 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
569 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
570 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
571 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
572 %{traditional-cpp:-traditional}\
573 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
574 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
575 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
576 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
577 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
578 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
579 -lang-objc %{gen-decls} \
581 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
582 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
583 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
584 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
585 %{!pipe:%g.s} %A\n }}}}"},
588 "%{!E:%eCompilation of header file requested} \
589 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
590 %{C:%{!E:%eGNU C does not support -C without using -E}}\
591 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
592 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
593 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
594 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
595 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
596 %{traditional-cpp:-traditional}\
597 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
604 "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
605 %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
606 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
607 -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
608 %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
609 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
610 %{traditional-cpp:-traditional} %{trigraphs}\
611 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
612 %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
613 "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\
614 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
615 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
616 %{traditional} %{v:-version} %{pg:-p} %{p}\
617 %{f*} %{+e*} %{aux-info*}\
618 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
619 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\
620 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
621 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
622 %{!pipe:%g.s} %A\n }}}}"},
623 {".i", "@cpp-output"},
625 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
626 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
627 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
629 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
630 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
631 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
632 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
633 %{!pipe:%g.s} %A\n }}}}"},
634 {".ii", "@c++-cpp-output"},
636 "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
637 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
638 %{traditional} %{v:-version} %{pg:-p} %{p}\
639 %{f*} %{+e*} %{aux-info*}\
640 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
641 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
642 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
643 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
644 %{!pipe:%g.s} %A\n }}}}"},
645 {".s", "@assembler"},
647 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
648 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
650 {".S", "@assembler-with-cpp"},
651 {"@assembler-with-cpp",
652 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
653 %{C:%{!E:%eGNU C does not support -C without using -E}}\
654 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
655 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
656 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
657 %{traditional-cpp:-traditional}\
658 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
659 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
660 "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
661 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
662 %{!pipe:%g.s} %A\n }}}}"},
667 "%{!M:%{!MM:%{!E:gnat1 %{k8:-gnatk8} %{w:-gnatws} %{!Q:-quiet}\
668 -dumpbase %b.ada %{g*} %{O*} %{p} %{pg:-p} %{f*}\
670 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
671 %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
672 %{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
673 %{c:%W{o*}%{!o*:-o %w%b.o}}\
674 %{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n}}}}}} "},
675 /* Mark end of table */
679 /* Number of elements in default_compilers, not counting the terminator. */
681 static int n_default_compilers
682 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
684 /* Here is the spec for running the linker, after compiling all files. */
686 /* -u* was put back because both BSD and SysV seem to support it. */
687 /* %{static:} simply prevents an error message if the target machine
688 doesn't handle -static. */
689 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
690 scripts which exist in user specified directories, or in standard
692 #ifdef LINK_LIBGCC_SPECIAL_1
693 /* Have gcc do the search for libgcc.a, but generate -L options as usual. */
694 static char *link_command_spec
= "\
696 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
697 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
698 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
699 %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
701 #ifdef LINK_LIBGCC_SPECIAL
702 /* Have gcc do the search for libgcc.a, and don't generate -L options. */
703 static char *link_command_spec
= "\
705 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
706 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
707 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
708 %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
710 /* Use -L and have the linker do the search for -lgcc. */
711 static char *link_command_spec
= "\
713 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
714 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
715 %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
716 %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}";
720 /* A vector of options to give to the linker.
721 These options are accumulated by -Xlinker and -Wl,
722 and substituted into the linker command with %X. */
723 static int n_linker_options
;
724 static char **linker_options
;
726 /* A vector of options to give to the assembler.
727 These options are accumulated by -Wa,
728 and substituted into the assembler command with %X. */
729 static int n_assembler_options
;
730 static char **assembler_options
;
732 /* Define how to map long options into short ones. */
734 /* This structure describes one mapping. */
737 /* The long option's name. */
739 /* The equivalent short option. */
741 /* Argument info. A string of flag chars; NULL equals no options.
742 a => argument required.
743 o => argument optional.
744 j => join argument to equivalent, making one word.
745 * => allow other text after NAME as an argument. */
749 /* This is the table of mappings. Mappings are tried sequentially
750 for each option encountered; the first one that matches, wins. */
752 struct option_map option_map
[] =
754 {"--profile-blocks", "-a", 0},
755 {"--target", "-b", "a"},
756 {"--compile", "-c", 0},
757 {"--dump", "-d", "a"},
758 {"--entry", "-e", 0},
759 {"--debug", "-g", "oj"},
760 {"--include", "-include", "a"},
761 {"--imacros", "-imacros", "a"},
762 {"--include-prefix", "-iprefix", "a"},
763 {"--include-directory-after", "-idirafter", "a"},
764 {"--include-with-prefix", "-iwithprefix", "a"},
765 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
766 {"--include-with-prefix-after", "-iwithprefix", "a"},
767 {"--machine-", "-m", "*j"},
768 {"--machine", "-m", "aj"},
769 {"--no-standard-includes", "-nostdinc", 0},
770 {"--no-standard-libraries", "-nostdlib", 0},
771 {"--no-precompiled-includes", "-noprecomp", 0},
772 {"--output", "-o", "a"},
773 {"--profile", "-p", 0},
774 {"--quiet", "-q", 0},
775 {"--silent", "-q", 0},
776 {"--force-link", "-u", "a"},
777 {"--verbose", "-v", 0},
778 {"--version", "-dumpversion", 0},
779 {"--no-warnings", "-w", 0},
780 {"--language", "-x", "a"},
782 {"--assert", "-A", "a"},
783 {"--prefix", "-B", "a"},
784 {"--comments", "-C", 0},
785 {"--define-macro", "-D", "a"},
786 {"--preprocess", "-E", 0},
787 {"--trace-includes", "-H", 0},
788 {"--include-directory", "-I", "a"},
789 {"--include-barrier", "-I-", 0},
790 {"--library-directory", "-L", "a"},
791 {"--dependencies", "-M", 0},
792 {"--user-dependencies", "-MM", 0},
793 {"--write-dependencies", "-MD", 0},
794 {"--write-user-dependencies", "-MMD", 0},
795 {"--print-missing-file-dependencies", "-MG", 0},
796 {"--optimize", "-O", "oj"},
797 {"--no-line-commands", "-P", 0},
798 {"--assemble", "-S", 0},
799 {"--undefine-macro", "-U", "a"},
800 {"--use-version", "-V", "a"},
801 {"--for-assembler", "-Wa", "a"},
802 {"--extra-warnings", "-W", 0},
803 {"--all-warnings", "-Wall", 0},
804 {"--warn-", "-W", "*j"},
805 {"--for-linker", "-Xlinker", "a"},
807 {"--ansi", "-ansi", 0},
808 {"--traditional", "-traditional", 0},
809 {"--traditional-cpp", "-traditional-cpp", 0},
810 {"--trigraphs", "-trigraphs", 0},
811 {"--pipe", "-pipe", 0},
812 {"--dumpbase", "-dumpbase", "a"},
813 {"--pedantic", "-pedantic", 0},
814 {"--pedantic-errors", "-pedantic-errors", 0},
815 {"--save-temps", "-save-temps", 0},
816 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
817 {"--print-file-name", "-print-file-name=", "aj"},
818 {"--print-prog-name", "-print-prog-name=", "aj"},
819 {"--print-multi-lib", "-print-multi-lib", 0},
820 {"--print-multi-directory", "-print-multi-directory", 0},
821 {"--static", "-static", 0},
822 {"--shared", "-shared", 0},
823 {"--symbolic", "-symbolic", 0},
827 /* Translate the options described by *ARGCP and *ARGVP.
828 Make a new vector and store it back in *ARGVP,
829 and store its length in *ARGVC. */
832 translate_options (argcp
, argvp
)
838 char **argv
= *argvp
;
839 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
843 newv
[newindex
++] = argv
[i
++];
847 /* Translate -- options. */
848 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
850 /* Find a mapping that applies to this option. */
851 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
853 int optlen
= strlen (option_map
[j
].name
);
854 int complen
= strlen (argv
[i
]);
855 char *arginfo
= option_map
[j
].arg_info
;
859 if (complen
> optlen
)
861 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
863 int extra
= strlen (argv
[i
]) > optlen
;
868 /* If the option has an argument, accept that. */
869 if (argv
[i
][optlen
] == '=')
870 arg
= argv
[i
] + optlen
+ 1;
871 /* If this mapping allows extra text at end of name,
872 accept that as "argument". */
873 else if (index (arginfo
, '*') != 0)
874 arg
= argv
[i
] + optlen
;
875 /* Otherwise, extra text at end means mismatch.
876 Try other mappings. */
880 else if (index (arginfo
, '*') != 0)
881 error ("Incomplete `%s' option", option_map
[j
].name
);
883 /* Handle arguments. */
884 if (index (arginfo
, 'o') != 0)
889 error ("Missing argument to `%s' option",
894 else if (index (arginfo
, '*') != 0)
896 else if (index (arginfo
, 'a') == 0)
899 error ("Extraneous argument to `%s' option",
904 /* Store the translation as one argv elt or as two. */
905 if (arg
!= 0 && index (arginfo
, 'j') != 0)
906 newv
[newindex
++] = concat (option_map
[j
].equivalent
,
910 newv
[newindex
++] = option_map
[j
].equivalent
;
911 newv
[newindex
++] = arg
;
914 newv
[newindex
++] = option_map
[j
].equivalent
;
921 /* Handle old-fashioned options--just copy them through,
922 with their arguments. */
923 else if (argv
[i
][0] == '-')
925 char *p
= argv
[i
] + 1;
929 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
930 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
931 else if (WORD_SWITCH_TAKES_ARG (p
))
932 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
933 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
936 else if (! strcmp (p
, "Xlinker"))
939 /* Watch out for an option at the end of the command line that
940 is missing arguments, and avoid skipping past the end of the
942 if (nskip
+ i
> argc
)
947 newv
[newindex
++] = argv
[i
++];
952 /* Ordinary operands, or +e options. */
953 newv
[newindex
++] = argv
[i
++];
962 /* Read compilation specs from a file named FILENAME,
963 replacing the default ones.
965 A suffix which starts with `*' is a definition for
966 one of the machine-specific sub-specs. The "suffix" should be
967 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
968 The corresponding spec is stored in asm_spec, etc.,
969 rather than in the `compilers' vector.
971 Anything invalid in the file is a fatal error. */
974 read_specs (filename
)
983 fprintf (stderr
, "Reading specs from %s\n", filename
);
985 /* Open and stat the file. */
986 desc
= open (filename
, 0, 0);
988 pfatal_with_name (filename
);
989 if (stat (filename
, &statbuf
) < 0)
990 pfatal_with_name (filename
);
992 /* Read contents of file into BUFFER. */
993 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
994 read (desc
, buffer
, (unsigned) statbuf
.st_size
);
995 buffer
[statbuf
.st_size
] = 0;
998 /* Scan BUFFER for specs, putting them in the vector. */
1004 char *in
, *out
, *p1
, *p2
;
1006 /* Advance P in BUFFER to the next nonblank nocomment line. */
1007 p
= skip_whitespace (p
);
1011 /* Find the colon that should end the suffix. */
1013 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
1014 /* The colon shouldn't be missing. */
1016 fatal ("specs file malformed after %d characters", p1
- buffer
);
1017 /* Skip back over trailing whitespace. */
1019 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
1020 /* Copy the suffix to a string. */
1021 suffix
= save_string (p
, p2
- p
);
1022 /* Find the next line. */
1023 p
= skip_whitespace (p1
+ 1);
1025 fatal ("specs file malformed after %d characters", p
- buffer
);
1027 /* Find next blank line. */
1028 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
1029 /* Specs end at the blank line and do not include the newline. */
1030 spec
= save_string (p
, p1
- p
);
1033 /* Delete backslash-newline sequences from the spec. */
1038 if (in
[0] == '\\' && in
[1] == '\n')
1040 else if (in
[0] == '#')
1042 while (*in
&& *in
!= '\n') in
++;
1049 if (suffix
[0] == '*')
1051 if (! strcmp (suffix
, "*link_command"))
1052 link_command_spec
= spec
;
1054 set_spec (suffix
+ 1, spec
);
1058 /* Add this pair to the vector. */
1060 = ((struct compiler
*)
1061 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
1062 compilers
[n_compilers
].suffix
= suffix
;
1063 bzero ((char *) compilers
[n_compilers
].spec
,
1064 sizeof compilers
[n_compilers
].spec
);
1065 compilers
[n_compilers
].spec
[0] = spec
;
1067 bzero ((char *) &compilers
[n_compilers
],
1068 sizeof compilers
[n_compilers
]);
1072 link_command_spec
= spec
;
1075 if (link_command_spec
== 0)
1076 fatal ("spec file has no spec for linking");
1085 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1086 be considered whitespace. */
1087 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1089 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1093 while (*p
!= '\n') p
++;
1103 /* Structure to keep track of the specs that have been defined so far. These
1104 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1108 char *name
; /* Name of the spec. */
1109 char *spec
; /* The spec itself. */
1110 struct spec_list
*next
; /* Next spec in linked list. */
1113 /* List of specs that have been defined so far. */
1115 static struct spec_list
*specs
= (struct spec_list
*) 0;
1117 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1118 removed; If the spec starts with a + then SPEC is added to the end of the
1122 set_spec (name
, spec
)
1126 struct spec_list
*sl
;
1129 /* See if the spec already exists */
1130 for (sl
= specs
; sl
; sl
= sl
->next
)
1131 if (strcmp (sl
->name
, name
) == 0)
1136 /* Not found - make it */
1137 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1138 sl
->name
= save_string (name
, strlen (name
));
1139 sl
->spec
= save_string ("", 0);
1144 old_spec
= sl
->spec
;
1145 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
1146 sl
->spec
= concat (old_spec
, spec
+ 1, "");
1148 sl
->spec
= save_string (spec
, strlen (spec
));
1150 if (! strcmp (name
, "asm"))
1151 asm_spec
= sl
->spec
;
1152 else if (! strcmp (name
, "asm_final"))
1153 asm_final_spec
= sl
->spec
;
1154 else if (! strcmp (name
, "cc1"))
1155 cc1_spec
= sl
->spec
;
1156 else if (! strcmp (name
, "cc1plus"))
1157 cc1plus_spec
= sl
->spec
;
1158 else if (! strcmp (name
, "cpp"))
1159 cpp_spec
= sl
->spec
;
1160 else if (! strcmp (name
, "endfile"))
1161 endfile_spec
= sl
->spec
;
1162 else if (! strcmp (name
, "lib"))
1163 lib_spec
= sl
->spec
;
1164 else if (! strcmp (name
, "link"))
1165 link_spec
= sl
->spec
;
1166 else if (! strcmp (name
, "predefines"))
1167 cpp_predefines
= sl
->spec
;
1168 else if (! strcmp (name
, "signed_char"))
1169 signed_char_spec
= sl
->spec
;
1170 else if (! strcmp (name
, "startfile"))
1171 startfile_spec
= sl
->spec
;
1172 else if (! strcmp (name
, "switches_need_spaces"))
1173 switches_need_spaces
= sl
->spec
;
1174 else if (! strcmp (name
, "cross_compile"))
1175 cross_compile
= atoi (sl
->spec
);
1176 else if (! strcmp (name
, "multilib"))
1177 multilib_select
= sl
->spec
;
1178 /* Free the old spec */
1183 /* Accumulate a command (program name and args), and run it. */
1185 /* Vector of pointers to arguments in the current line of specifications. */
1187 static char **argbuf
;
1189 /* Number of elements allocated in argbuf. */
1191 static int argbuf_length
;
1193 /* Number of elements in argbuf currently in use (containing args). */
1195 static int argbuf_index
;
1197 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1198 temp file. Used only if MKTEMP_EACH_FILE. */
1200 static struct temp_name
{
1201 char *suffix
; /* suffix associated with the code. */
1202 int length
; /* strlen (suffix). */
1203 int unique
; /* Indicates whether %g or %u/%U was used. */
1204 char *filename
; /* associated filename. */
1205 int filename_length
; /* strlen (filename). */
1206 struct temp_name
*next
;
1209 /* Number of commands executed so far. */
1211 static int execution_count
;
1213 /* Number of commands that exited with a signal. */
1215 static int signal_count
;
1217 /* Name with which this program was invoked. */
1219 static char *programname
;
1221 /* Structures to keep track of prefixes to try when looking for files. */
1225 char *prefix
; /* String to prepend to the path. */
1226 struct prefix_list
*next
; /* Next in linked list. */
1227 int require_machine_suffix
; /* Don't use without machine_suffix. */
1228 /* 2 means try both machine_suffix and just_machine_suffix. */
1229 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1234 struct prefix_list
*plist
; /* List of prefixes to try */
1235 int max_len
; /* Max length of a prefix in PLIST */
1236 char *name
; /* Name of this list (used in config stuff) */
1239 /* List of prefixes to try when looking for executables. */
1241 static struct path_prefix exec_prefix
= { 0, 0, "exec" };
1243 /* List of prefixes to try when looking for startup (crt0) files. */
1245 static struct path_prefix startfile_prefix
= { 0, 0, "startfile" };
1247 /* List of prefixes to try when looking for include files. */
1249 static struct path_prefix include_prefix
= { 0, 0, "include" };
1251 /* Suffix to attach to directories searched for commands.
1252 This looks like `MACHINE/VERSION/'. */
1254 static char *machine_suffix
= 0;
1256 /* Suffix to attach to directories searched for commands.
1257 This is just `MACHINE/'. */
1259 static char *just_machine_suffix
= 0;
1261 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1263 static char *gcc_exec_prefix
;
1265 /* Default prefixes to attach to command names. */
1267 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1268 #undef MD_EXEC_PREFIX
1269 #undef MD_STARTFILE_PREFIX
1270 #undef MD_STARTFILE_PREFIX_1
1273 #ifndef STANDARD_EXEC_PREFIX
1274 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1275 #endif /* !defined STANDARD_EXEC_PREFIX */
1277 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1278 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1279 #ifdef MD_EXEC_PREFIX
1280 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1283 #ifndef STANDARD_STARTFILE_PREFIX
1284 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1285 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1287 #ifdef MD_STARTFILE_PREFIX
1288 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1290 #ifdef MD_STARTFILE_PREFIX_1
1291 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1293 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1294 static char *standard_startfile_prefix_1
= "/lib/";
1295 static char *standard_startfile_prefix_2
= "/usr/lib/";
1297 #ifndef TOOLDIR_BASE_PREFIX
1298 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1300 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1301 static char *tooldir_prefix
;
1303 /* Subdirectory to use for locating libraries. Set by
1304 set_multilib_dir based on the compilation options. */
1306 static char *multilib_dir
;
1308 /* Clear out the vector of arguments (after a command is executed). */
1316 /* Add one argument to the vector at the end.
1317 This is done when a space is seen or at the end of the line.
1318 If DELETE_ALWAYS is nonzero, the arg is a filename
1319 and the file should be deleted eventually.
1320 If DELETE_FAILURE is nonzero, the arg is a filename
1321 and the file should be deleted if this compilation fails. */
1324 store_arg (arg
, delete_always
, delete_failure
)
1326 int delete_always
, delete_failure
;
1328 if (argbuf_index
+ 1 == argbuf_length
)
1330 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1333 argbuf
[argbuf_index
++] = arg
;
1334 argbuf
[argbuf_index
] = 0;
1336 if (delete_always
|| delete_failure
)
1337 record_temp_file (arg
, delete_always
, delete_failure
);
1340 /* Record the names of temporary files we tell compilers to write,
1341 and delete them at the end of the run. */
1343 /* This is the common prefix we use to make temp file names.
1344 It is chosen once for each run of this program.
1345 It is substituted into a spec by %g.
1346 Thus, all temp file names contain this prefix.
1347 In practice, all temp file names start with this prefix.
1349 This prefix comes from the envvar TMPDIR if it is defined;
1350 otherwise, from the P_tmpdir macro if that is defined;
1351 otherwise, in /usr/tmp or /tmp. */
1353 static char *temp_filename
;
1355 /* Length of the prefix. */
1357 static int temp_filename_length
;
1359 /* Define the list of temporary files to delete. */
1364 struct temp_file
*next
;
1367 /* Queue of files to delete on success or failure of compilation. */
1368 static struct temp_file
*always_delete_queue
;
1369 /* Queue of files to delete on failure of compilation. */
1370 static struct temp_file
*failure_delete_queue
;
1372 /* Record FILENAME as a file to be deleted automatically.
1373 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1374 otherwise delete it in any case.
1375 FAIL_DELETE nonzero means delete it if a compilation step fails;
1376 otherwise delete it in any case. */
1379 record_temp_file (filename
, always_delete
, fail_delete
)
1384 register char *name
;
1385 name
= xmalloc (strlen (filename
) + 1);
1386 strcpy (name
, filename
);
1390 register struct temp_file
*temp
;
1391 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1392 if (! strcmp (name
, temp
->name
))
1394 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1395 temp
->next
= always_delete_queue
;
1397 always_delete_queue
= temp
;
1403 register struct temp_file
*temp
;
1404 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1405 if (! strcmp (name
, temp
->name
))
1407 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1408 temp
->next
= failure_delete_queue
;
1410 failure_delete_queue
= temp
;
1415 /* Delete all the temporary files whose names we previously recorded. */
1418 delete_if_ordinary (name
)
1425 printf ("Delete %s? (y or n) ", name
);
1429 while ((c
= getchar ()) != '\n' && c
!= EOF
) ;
1430 if (i
== 'y' || i
== 'Y')
1432 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1433 if (unlink (name
) < 0)
1435 perror_with_name (name
);
1439 delete_temp_files ()
1441 register struct temp_file
*temp
;
1443 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1444 delete_if_ordinary (temp
->name
);
1445 always_delete_queue
= 0;
1448 /* Delete all the files to be deleted on error. */
1451 delete_failure_queue ()
1453 register struct temp_file
*temp
;
1455 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1456 delete_if_ordinary (temp
->name
);
1460 clear_failure_queue ()
1462 failure_delete_queue
= 0;
1465 /* Compute a string to use as the base of all temporary file names.
1466 It is substituted for %g. */
1469 choose_temp_base_try (try, base
)
1476 else if (try == (char *)0)
1478 else if (access (try, R_OK
| W_OK
) != 0)
1491 base
= choose_temp_base_try (getenv ("TMPDIR"), base
);
1492 base
= choose_temp_base_try (getenv ("TMP"), base
);
1493 base
= choose_temp_base_try (getenv ("TEMP"), base
);
1496 base
= choose_temp_base_try (P_tmpdir
, base
);
1499 base
= choose_temp_base_try ("/usr/tmp", base
);
1500 base
= choose_temp_base_try ("/tmp", base
);
1502 /* If all else fails, use the current directory! */
1503 if (base
== (char *)0)
1506 len
= strlen (base
);
1507 temp_filename
= xmalloc (len
+ sizeof("/ccXXXXXX") + 1);
1508 strcpy (temp_filename
, base
);
1509 if (len
> 0 && temp_filename
[len
-1] != '/')
1510 temp_filename
[len
++] = '/';
1511 strcpy (temp_filename
+ len
, "ccXXXXXX");
1513 mktemp (temp_filename
);
1514 temp_filename_length
= strlen (temp_filename
);
1515 if (temp_filename_length
== 0)
1520 /* Routine to add variables to the environment. We do this to pass
1521 the pathname of the gcc driver, and the directories search to the
1522 collect2 program, which is being run as ld. This way, we can be
1523 sure of executing the right compiler when collect2 wants to build
1524 constructors and destructors. Since the environment variables we
1525 use come from an obstack, we don't have to worry about allocating
1534 #ifndef VMS /* nor about VMS */
1536 extern char **environ
;
1537 char **old_environ
= environ
;
1541 int str_len
= strlen (str
);
1545 while ((ch
= *p
++) != '\0' && ch
!= '=')
1551 /* Search for replacing an existing environment variable, and
1552 count the number of total environment variables. */
1553 for (envp
= old_environ
; *envp
; envp
++)
1556 if (!strncmp (str
, *envp
, name_len
))
1563 /* Add a new environment variable */
1564 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1566 bcopy ((char *) old_environ
, (char *) (environ
+ 1),
1567 sizeof (char *) * (num_envs
+1));
1572 #endif /* HAVE_PUTENV */
1575 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1578 putenv_from_prefixes (paths
, env_var
)
1579 struct path_prefix
*paths
;
1582 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1584 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1585 int first_time
= TRUE
;
1586 struct prefix_list
*pprefix
;
1588 obstack_grow (&collect_obstack
, env_var
, strlen (env_var
));
1590 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1592 int len
= strlen (pprefix
->prefix
);
1595 && is_directory (pprefix
->prefix
, machine_suffix
, 0))
1598 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1601 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1602 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1605 if (just_machine_suffix
1606 && pprefix
->require_machine_suffix
== 2
1607 && is_directory (pprefix
->prefix
, just_machine_suffix
, 0))
1610 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1613 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1614 obstack_grow (&collect_obstack
, just_machine_suffix
,
1618 if (!pprefix
->require_machine_suffix
)
1621 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1624 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1627 obstack_1grow (&collect_obstack
, '\0');
1628 putenv (obstack_finish (&collect_obstack
));
1632 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1633 access to check permissions.
1634 Return 0 if not found, otherwise return its name, allocated with malloc. */
1637 find_a_file (pprefix
, name
, mode
)
1638 struct path_prefix
*pprefix
;
1643 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1644 struct prefix_list
*pl
;
1645 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1648 len
+= strlen (machine_suffix
);
1650 temp
= xmalloc (len
);
1652 /* Determine the filename to execute (special case for absolute paths). */
1656 if (access (name
, mode
))
1658 strcpy (temp
, name
);
1663 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1667 /* Some systems have a suffix for executable files.
1668 So try appending that first. */
1669 if (file_suffix
[0] != 0)
1671 strcpy (temp
, pl
->prefix
);
1672 strcat (temp
, machine_suffix
);
1673 strcat (temp
, name
);
1674 strcat (temp
, file_suffix
);
1675 if (access (temp
, mode
) == 0)
1677 if (pl
->used_flag_ptr
!= 0)
1678 *pl
->used_flag_ptr
= 1;
1683 /* Now try just the name. */
1684 strcpy (temp
, pl
->prefix
);
1685 strcat (temp
, machine_suffix
);
1686 strcat (temp
, name
);
1687 if (access (temp
, mode
) == 0)
1689 if (pl
->used_flag_ptr
!= 0)
1690 *pl
->used_flag_ptr
= 1;
1695 /* Certain prefixes are tried with just the machine type,
1696 not the version. This is used for finding as, ld, etc. */
1697 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
1699 /* Some systems have a suffix for executable files.
1700 So try appending that first. */
1701 if (file_suffix
[0] != 0)
1703 strcpy (temp
, pl
->prefix
);
1704 strcat (temp
, just_machine_suffix
);
1705 strcat (temp
, name
);
1706 strcat (temp
, file_suffix
);
1707 if (access (temp
, mode
) == 0)
1709 if (pl
->used_flag_ptr
!= 0)
1710 *pl
->used_flag_ptr
= 1;
1715 strcpy (temp
, pl
->prefix
);
1716 strcat (temp
, just_machine_suffix
);
1717 strcat (temp
, name
);
1718 if (access (temp
, mode
) == 0)
1720 if (pl
->used_flag_ptr
!= 0)
1721 *pl
->used_flag_ptr
= 1;
1726 /* Certain prefixes can't be used without the machine suffix
1727 when the machine or version is explicitly specified. */
1728 if (!pl
->require_machine_suffix
)
1730 /* Some systems have a suffix for executable files.
1731 So try appending that first. */
1732 if (file_suffix
[0] != 0)
1734 strcpy (temp
, pl
->prefix
);
1735 strcat (temp
, name
);
1736 strcat (temp
, file_suffix
);
1737 if (access (temp
, mode
) == 0)
1739 if (pl
->used_flag_ptr
!= 0)
1740 *pl
->used_flag_ptr
= 1;
1745 strcpy (temp
, pl
->prefix
);
1746 strcat (temp
, name
);
1747 if (access (temp
, mode
) == 0)
1749 if (pl
->used_flag_ptr
!= 0)
1750 *pl
->used_flag_ptr
= 1;
1760 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1761 at the start of the list, otherwise it goes at the end.
1763 If WARN is nonzero, we will warn if no file is found
1764 through this prefix. WARN should point to an int
1765 which will be set to 1 if this entry is used.
1767 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1768 the complete value of machine_suffix.
1769 2 means try both machine_suffix and just_machine_suffix. */
1772 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1773 struct path_prefix
*pprefix
;
1776 int require_machine_suffix
;
1779 struct prefix_list
*pl
, **prev
;
1782 if (!first
&& pprefix
->plist
)
1784 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1789 prev
= &pprefix
->plist
;
1791 /* Keep track of the longest prefix */
1793 len
= strlen (prefix
);
1794 if (len
> pprefix
->max_len
)
1795 pprefix
->max_len
= len
;
1797 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1798 pl
->prefix
= save_string (prefix
, len
);
1799 pl
->require_machine_suffix
= require_machine_suffix
;
1800 pl
->used_flag_ptr
= warn
;
1807 pl
->next
= (struct prefix_list
*) 0;
1811 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1814 unused_prefix_warnings (pprefix
)
1815 struct path_prefix
*pprefix
;
1817 struct prefix_list
*pl
= pprefix
->plist
;
1821 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1823 error ("file path prefix `%s' never used",
1825 /* Prevent duplicate warnings. */
1826 *pl
->used_flag_ptr
= 1;
1832 /* Get rid of all prefixes built up so far in *PLISTP. */
1835 free_path_prefix (pprefix
)
1836 struct path_prefix
*pprefix
;
1838 struct prefix_list
*pl
= pprefix
->plist
;
1839 struct prefix_list
*temp
;
1845 free (temp
->prefix
);
1846 free ((char *) temp
);
1848 pprefix
->plist
= (struct prefix_list
*) 0;
1851 /* stdin file number. */
1852 #define STDIN_FILE_NO 0
1854 /* stdout file number. */
1855 #define STDOUT_FILE_NO 1
1857 /* value of `pipe': port index for reading. */
1860 /* value of `pipe': port index for writing. */
1861 #define WRITE_PORT 1
1863 /* Pipe waiting from last process, to be used as input for the next one.
1864 Value is STDIN_FILE_NO if no pipe is waiting
1865 (i.e. the next command is the first of a group). */
1867 static int last_pipe_input
;
1869 /* Fork one piped subcommand. FUNC is the system call to use
1870 (either execv or execvp). ARGV is the arg vector to use.
1871 NOT_LAST is nonzero if this is not the last subcommand
1872 (i.e. its output should be piped to the next one.) */
1877 #include <process.h>
1879 pexecute (search_flag
, program
, argv
, not_last
)
1886 int i
= (search_flag
? spawnv
: spawnvp
) (1, program
, argv
);
1890 int i
, el
= search_flag
? 0 : 4;
1892 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6 + el
);
1893 rf
= scmd
+ strlen(program
) + 2 + el
;
1894 sprintf (scmd
, "%s%s @%s.gp", program
,
1895 (search_flag
? "" : ".exe"), temp_filename
);
1896 argfile
= fopen (rf
, "w");
1898 pfatal_with_name (rf
);
1900 for (i
=1; argv
[i
]; i
++)
1903 for (cp
= argv
[i
]; *cp
; cp
++)
1905 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
1906 fputc ('\\', argfile
);
1907 fputc (*cp
, argfile
);
1909 fputc ('\n', argfile
);
1920 perror_exec (program
);
1921 return MIN_FATAL_STATUS
<< 8;
1926 #else /* not __MSDOS__ */
1929 pexecute (search_flag
, program
, argv
, not_last
)
1935 int (*func
)() = (search_flag
? execv
: execvp
);
1938 int input_desc
= last_pipe_input
;
1939 int output_desc
= STDOUT_FILE_NO
;
1940 int retries
, sleep_interval
;
1942 /* If this isn't the last process, make a pipe for its output,
1943 and record it as waiting to be the input to the next process. */
1947 if (pipe (pdes
) < 0)
1948 pfatal_with_name ("pipe");
1949 output_desc
= pdes
[WRITE_PORT
];
1950 last_pipe_input
= pdes
[READ_PORT
];
1953 last_pipe_input
= STDIN_FILE_NO
;
1955 /* Fork a subprocess; wait and retry if it fails. */
1957 for (retries
= 0; retries
< 4; retries
++)
1962 sleep (sleep_interval
);
1963 sleep_interval
*= 2;
1970 pfatal_with_name ("fork");
1972 pfatal_with_name ("vfork");
1978 /* Move the input and output pipes into place, if nec. */
1979 if (input_desc
!= STDIN_FILE_NO
)
1981 close (STDIN_FILE_NO
);
1985 if (output_desc
!= STDOUT_FILE_NO
)
1987 close (STDOUT_FILE_NO
);
1989 close (output_desc
);
1992 /* Close the parent's descs that aren't wanted here. */
1993 if (last_pipe_input
!= STDIN_FILE_NO
)
1994 close (last_pipe_input
);
1996 /* Exec the program. */
1997 (*func
) (program
, argv
);
1998 perror_exec (program
);
2004 /* In the parent, after forking.
2005 Close the descriptors that we made for this child. */
2006 if (input_desc
!= STDIN_FILE_NO
)
2008 if (output_desc
!= STDOUT_FILE_NO
)
2009 close (output_desc
);
2011 /* Return child's process number. */
2016 #endif /* not __MSDOS__ */
2020 pexecute (search_flag
, program
, argv
, not_last
)
2026 return (search_flag
? spawnv
: spawnvp
) (1, program
, argv
);
2028 #endif /* not OS2 */
2030 /* Execute the command specified by the arguments on the current line of spec.
2031 When using pipes, this includes several piped-together commands
2032 with `|' between them.
2034 Return 0 if successful, -1 if failed. */
2040 int n_commands
; /* # of command. */
2044 char *prog
; /* program name. */
2045 char **argv
; /* vector of args. */
2046 int pid
; /* pid of process for this command. */
2049 struct command
*commands
; /* each command buffer with above info. */
2051 /* Count # of piped commands. */
2052 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2053 if (strcmp (argbuf
[i
], "|") == 0)
2056 /* Get storage for each command. */
2058 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2060 /* Split argbuf into its separate piped processes,
2061 and record info about each one.
2062 Also search for the programs that are to be run. */
2064 commands
[0].prog
= argbuf
[0]; /* first command. */
2065 commands
[0].argv
= &argbuf
[0];
2066 string
= find_a_file (&exec_prefix
, commands
[0].prog
, X_OK
);
2068 commands
[0].argv
[0] = string
;
2070 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2071 if (strcmp (argbuf
[i
], "|") == 0)
2072 { /* each command. */
2074 fatal ("-pipe not supported under MS-DOS");
2076 argbuf
[i
] = 0; /* termination of command args. */
2077 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2078 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2079 string
= find_a_file (&exec_prefix
, commands
[n_commands
].prog
, X_OK
);
2081 commands
[n_commands
].argv
[0] = string
;
2085 argbuf
[argbuf_index
] = 0;
2087 /* If -v, print what we are about to do, and maybe query. */
2091 /* Print each piped command as a separate line. */
2092 for (i
= 0; i
< n_commands
; i
++)
2096 for (j
= commands
[i
].argv
; *j
; j
++)
2097 fprintf (stderr
, " %s", *j
);
2099 /* Print a pipe symbol after all but the last command. */
2100 if (i
+ 1 != n_commands
)
2101 fprintf (stderr
, " |");
2102 fprintf (stderr
, "\n");
2106 fprintf (stderr
, "\nGo ahead? (y or n) ");
2110 while (getchar () != '\n') ;
2111 if (i
!= 'y' && i
!= 'Y')
2116 /* Run each piped subprocess. */
2118 last_pipe_input
= STDIN_FILE_NO
;
2119 for (i
= 0; i
< n_commands
; i
++)
2121 char *string
= commands
[i
].argv
[0];
2123 commands
[i
].pid
= pexecute (string
!= commands
[i
].prog
,
2124 string
, commands
[i
].argv
,
2125 i
+ 1 < n_commands
);
2127 if (string
!= commands
[i
].prog
)
2133 /* Wait for all the subprocesses to finish.
2134 We don't care what order they finish in;
2135 we know that N_COMMANDS waits will get them all. */
2140 for (i
= 0; i
< n_commands
; i
++)
2144 char *prog
= "unknown";
2147 status
= pid
= commands
[i
].pid
;
2149 pid
= wait (&status
);
2157 for (j
= 0; j
< n_commands
; j
++)
2158 if (commands
[j
].pid
== pid
)
2159 prog
= commands
[j
].prog
;
2161 if ((status
& 0x7F) != 0)
2163 fatal ("Internal compiler error: program %s got fatal signal %d",
2164 prog
, (status
& 0x7F));
2167 if (((status
& 0xFF00) >> 8) >= MIN_FATAL_STATUS
)
2175 /* Find all the switches given to us
2176 and make a vector describing them.
2177 The elements of the vector are strings, one per switch given.
2178 If a switch uses following arguments, then the `part1' field
2179 is the switch itself and the `args' field
2180 is a null-terminated vector containing the following arguments.
2181 The `live_cond' field is 1 if the switch is true in a conditional spec,
2182 -1 if false (overridden by a later switch), and is initialized to zero.
2183 The `valid' field is nonzero if any spec has looked at this switch;
2184 if it remains zero at the end of the run, it must be meaningless. */
2194 static struct switchstr
*switches
;
2196 static int n_switches
;
2204 /* Also a vector of input files specified. */
2206 static struct infile
*infiles
;
2208 static int n_infiles
;
2210 /* And a vector of corresponding output files is made up later. */
2212 static char **outfiles
;
2214 /* Create the vector `switches' and its contents.
2215 Store its length in `n_switches'. */
2218 process_command (argc
, argv
)
2224 char *spec_lang
= 0;
2225 int last_language_n_infiles
;
2227 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2232 /* Figure compiler version from version string. */
2234 compiler_version
= save_string (version_string
, strlen (version_string
));
2235 for (temp
= compiler_version
; *temp
; ++temp
)
2244 /* Set up the default search paths. */
2246 if (gcc_exec_prefix
)
2248 add_prefix (&exec_prefix
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2249 add_prefix (&startfile_prefix
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2252 /* COMPILER_PATH and LIBRARY_PATH have values
2253 that are lists of directory names with colons. */
2255 temp
= getenv ("COMPILER_PATH");
2258 char *startp
, *endp
;
2259 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2261 startp
= endp
= temp
;
2264 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2266 strncpy (nstore
, startp
, endp
-startp
);
2269 strcpy (nstore
, "./");
2271 else if (endp
[-1] != '/')
2273 nstore
[endp
-startp
] = '/';
2274 nstore
[endp
-startp
+1] = 0;
2277 nstore
[endp
-startp
] = 0;
2278 add_prefix (&exec_prefix
, nstore
, 0, 0, NULL_PTR
);
2281 endp
= startp
= endp
+ 1;
2288 temp
= getenv ("LIBRARY_PATH");
2291 char *startp
, *endp
;
2292 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2294 startp
= endp
= temp
;
2297 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2299 strncpy (nstore
, startp
, endp
-startp
);
2302 strcpy (nstore
, "./");
2304 else if (endp
[-1] != '/')
2306 nstore
[endp
-startp
] = '/';
2307 nstore
[endp
-startp
+1] = 0;
2310 nstore
[endp
-startp
] = 0;
2311 add_prefix (&startfile_prefix
, nstore
, 0, 0, NULL_PTR
);
2314 endp
= startp
= endp
+ 1;
2321 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2322 temp
= getenv ("LPATH");
2325 char *startp
, *endp
;
2326 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2328 startp
= endp
= temp
;
2331 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2333 strncpy (nstore
, startp
, endp
-startp
);
2336 strcpy (nstore
, "./");
2338 else if (endp
[-1] != '/')
2340 nstore
[endp
-startp
] = '/';
2341 nstore
[endp
-startp
+1] = 0;
2344 nstore
[endp
-startp
] = 0;
2345 add_prefix (&startfile_prefix
, nstore
, 0, 0, NULL_PTR
);
2348 endp
= startp
= endp
+ 1;
2355 /* Convert new-style -- options to old-style. */
2356 translate_options (&argc
, &argv
);
2358 /* Scan argv twice. Here, the first time, just count how many switches
2359 there will be in their vector, and how many input files in theirs.
2360 Here we also parse the switches that cc itself uses (e.g. -v). */
2362 for (i
= 1; i
< argc
; i
++)
2364 if (! strcmp (argv
[i
], "-dumpspecs"))
2366 printf ("*asm:\n%s\n\n", asm_spec
);
2367 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
2368 printf ("*cpp:\n%s\n\n", cpp_spec
);
2369 printf ("*cc1:\n%s\n\n", cc1_spec
);
2370 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
2371 printf ("*endfile:\n%s\n\n", endfile_spec
);
2372 printf ("*link:\n%s\n\n", link_spec
);
2373 printf ("*lib:\n%s\n\n", lib_spec
);
2374 printf ("*startfile:\n%s\n\n", startfile_spec
);
2375 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
2376 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
2377 printf ("*predefines:\n%s\n\n", cpp_predefines
);
2378 printf ("*cross_compile:\n%d\n\n", cross_compile
);
2379 printf ("*multilib:\n%s\n\n", multilib_select
);
2383 else if (! strcmp (argv
[i
], "-dumpversion"))
2385 printf ("%s\n", version_string
);
2388 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2389 print_file_name
= "libgcc.a";
2390 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2391 print_file_name
= argv
[i
] + 17;
2392 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2393 print_prog_name
= argv
[i
] + 17;
2394 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2395 print_multi_lib
= 1;
2396 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2397 print_multi_directory
= 1;
2398 else if (! strcmp (argv
[i
], "-Xlinker"))
2400 /* Pass the argument of this option to the linker when we link. */
2403 fatal ("argument to `-Xlinker' is missing");
2406 if (!linker_options
)
2408 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2411 = (char **) xrealloc (linker_options
,
2412 n_linker_options
* sizeof (char **));
2414 linker_options
[n_linker_options
- 1] = argv
[++i
];
2416 else if (! strncmp (argv
[i
], "-Wl,", 4))
2419 /* Pass the rest of this option to the linker when we link. */
2422 if (!linker_options
)
2424 = (char **) xmalloc (n_linker_options
* sizeof (char **));
2427 = (char **) xrealloc (linker_options
,
2428 n_linker_options
* sizeof (char **));
2430 /* Split the argument at commas. */
2432 for (j
= 4; argv
[i
][j
]; j
++)
2433 if (argv
[i
][j
] == ',')
2435 linker_options
[n_linker_options
- 1]
2436 = save_string (argv
[i
] + prev
, j
- prev
);
2439 = (char **) xrealloc (linker_options
,
2440 n_linker_options
* sizeof (char **));
2443 /* Record the part after the last comma. */
2444 linker_options
[n_linker_options
- 1] = argv
[i
] + prev
;
2446 else if (! strncmp (argv
[i
], "-Wa,", 4))
2449 /* Pass the rest of this option to the assembler. */
2451 n_assembler_options
++;
2452 if (!assembler_options
)
2454 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2457 = (char **) xrealloc (assembler_options
,
2458 n_assembler_options
* sizeof (char **));
2460 /* Split the argument at commas. */
2462 for (j
= 4; argv
[i
][j
]; j
++)
2463 if (argv
[i
][j
] == ',')
2465 assembler_options
[n_assembler_options
- 1]
2466 = save_string (argv
[i
] + prev
, j
- prev
);
2467 n_assembler_options
++;
2469 = (char **) xrealloc (assembler_options
,
2470 n_assembler_options
* sizeof (char **));
2473 /* Record the part after the last comma. */
2474 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2476 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2477 /* The +e options to the C++ front-end. */
2479 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2481 register char *p
= &argv
[i
][1];
2482 register int c
= *p
;
2487 if (p
[1] == 0 && i
+ 1 == argc
)
2488 fatal ("argument to `-b' is missing");
2490 spec_machine
= argv
[++i
];
2492 spec_machine
= p
+ 1;
2497 int *temp
= (int *) xmalloc (sizeof (int));
2499 if (p
[1] == 0 && i
+ 1 == argc
)
2500 fatal ("argument to `-B' is missing");
2505 add_prefix (&exec_prefix
, value
, 1, 0, temp
);
2506 add_prefix (&startfile_prefix
, value
, 1, 0, temp
);
2507 add_prefix (&include_prefix
, concat (value
, "include", ""),
2510 /* As a kludge, if the arg is "[foo/]stageN/", just add
2511 "[foo/]include" to the include prefix. */
2513 int len
= strlen (value
);
2514 if ((len
== 7 || (len
> 7 && value
[len
- 8] == '/'))
2515 && strncmp (value
+ len
- 7, "stage", 5) == 0
2516 && isdigit (value
[len
- 2])
2517 && value
[len
- 1] == '/')
2520 add_prefix (&include_prefix
, "include", 1, 0, 0);
2523 char *string
= xmalloc (len
+ 1);
2524 strncpy (string
, value
, len
-7);
2525 strcat (string
, "include");
2526 add_prefix (&include_prefix
, string
, 1, 0, 0);
2533 case 'v': /* Print our subcommands and print versions. */
2535 /* If they do anything other than exactly `-v', don't set
2536 verbose_flag; rather, continue on to give the error. */
2543 if (p
[1] == 0 && i
+ 1 == argc
)
2544 fatal ("argument to `-V' is missing");
2546 spec_version
= argv
[++i
];
2548 spec_version
= p
+ 1;
2549 compiler_version
= spec_version
;
2553 if (!strcmp (p
, "save-temps"))
2555 save_temps_flag
= 1;
2562 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2563 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2564 else if (WORD_SWITCH_TAKES_ARG (p
))
2565 i
+= WORD_SWITCH_TAKES_ARG (p
);
2572 /* Set up the search paths before we go looking for config files. */
2574 /* These come before the md prefixes so that we will find gcc's subcommands
2575 (such as cpp) rather than those of the host system. */
2576 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2577 as well as trying the machine and the version. */
2578 add_prefix (&exec_prefix
, standard_exec_prefix
, 0, 2, NULL_PTR
);
2579 add_prefix (&exec_prefix
, standard_exec_prefix_1
, 0, 2, NULL_PTR
);
2581 add_prefix (&startfile_prefix
, standard_exec_prefix
, 0, 1, NULL_PTR
);
2582 add_prefix (&startfile_prefix
, standard_exec_prefix_1
, 0, 1, NULL_PTR
);
2584 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
, "/");
2586 /* If tooldir is relative, base it on exec_prefix. A relative
2587 tooldir lets us move the installed tree as a unit.
2589 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2590 directories, so that we can search both the user specified directory
2591 and the standard place. */
2593 if (*tooldir_prefix
!= '/')
2595 if (gcc_exec_prefix
)
2597 char *gcc_exec_tooldir_prefix
2598 = concat (concat (gcc_exec_prefix
, spec_machine
, "/"),
2599 concat (spec_version
, "/", tooldir_prefix
),
2602 add_prefix (&exec_prefix
, concat (gcc_exec_tooldir_prefix
, "bin", "/"),
2604 add_prefix (&startfile_prefix
, concat (gcc_exec_tooldir_prefix
, "lib", "/"),
2608 tooldir_prefix
= concat (concat (standard_exec_prefix
, spec_machine
, "/"),
2609 concat (spec_version
, "/", tooldir_prefix
),
2613 add_prefix (&exec_prefix
, concat (tooldir_prefix
, "bin", "/"),
2615 add_prefix (&startfile_prefix
, concat (tooldir_prefix
, "lib", "/"),
2618 /* More prefixes are enabled in main, after we read the specs file
2619 and determine whether this is cross-compilation or not. */
2622 /* Then create the space for the vectors and scan again. */
2624 switches
= ((struct switchstr
*)
2625 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2626 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2629 last_language_n_infiles
= -1;
2631 /* This, time, copy the text of each switch and store a pointer
2632 to the copy in the vector of switches.
2633 Store all the infiles in their vector. */
2635 for (i
= 1; i
< argc
; i
++)
2637 /* Just skip the switches that were handled by the preceding loop. */
2638 if (!strcmp (argv
[i
], "-Xlinker"))
2640 else if (! strncmp (argv
[i
], "-Wl,", 4))
2642 else if (! strncmp (argv
[i
], "-Wa,", 4))
2644 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2646 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2648 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2650 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2652 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2654 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2656 /* Compensate for the +e options to the C++ front-end;
2657 they're there simply for cfront call-compatibility. We do
2658 some magic in default_compilers to pass them down properly.
2659 Note we deliberately start at the `+' here, to avoid passing
2660 -e0 or -e1 down into the linker. */
2661 switches
[n_switches
].part1
= &argv
[i
][0];
2662 switches
[n_switches
].args
= 0;
2663 switches
[n_switches
].live_cond
= 0;
2664 switches
[n_switches
].valid
= 0;
2667 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0 && argv
[i
][1] != 'l')
2669 register char *p
= &argv
[i
][1];
2670 register int c
= *p
;
2672 if (c
== 'B' || c
== 'b' || c
== 'V')
2674 /* Skip a separate arg, if any. */
2681 if (p
[1] == 0 && i
+ 1 == argc
)
2682 fatal ("argument to `-x' is missing");
2684 spec_lang
= argv
[++i
];
2687 if (! strcmp (spec_lang
, "none"))
2688 /* Suppress the warning if -xnone comes after the last input file,
2689 because alternate command interfaces like g++ might find it
2690 useful to place -xnone after each input file. */
2693 last_language_n_infiles
= n_infiles
;
2696 switches
[n_switches
].part1
= p
;
2697 /* Deal with option arguments in separate argv elements. */
2698 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2699 || WORD_SWITCH_TAKES_ARG (p
))
2702 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2706 /* Count only the option arguments in separate argv elements. */
2707 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2709 if (i
+ n_args
>= argc
)
2710 fatal ("argument to `-%s' is missing", p
);
2711 switches
[n_switches
].args
2712 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2714 switches
[n_switches
].args
[j
++] = argv
[++i
];
2715 /* Null-terminate the vector. */
2716 switches
[n_switches
].args
[j
] = 0;
2718 else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L'))
2720 /* On some systems, ld cannot handle -o or -L without space.
2721 So split the -o or -L from its argument. */
2722 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2723 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2724 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2725 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2726 switches
[n_switches
].args
[1] = 0;
2729 switches
[n_switches
].args
= 0;
2731 switches
[n_switches
].live_cond
= 0;
2732 switches
[n_switches
].valid
= 0;
2733 /* This is always valid, since gcc.c itself understands it. */
2734 if (!strcmp (p
, "save-temps"))
2735 switches
[n_switches
].valid
= 1;
2740 if ((argv
[i
][0] != '-' || argv
[i
][1] != 'l')
2741 && strcmp (argv
[i
], "-")
2742 && access (argv
[i
], R_OK
) < 0)
2744 perror_with_name (argv
[i
]);
2749 infiles
[n_infiles
].language
= spec_lang
;
2750 infiles
[n_infiles
++].name
= argv
[i
];
2755 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
2756 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2758 switches
[n_switches
].part1
= 0;
2759 infiles
[n_infiles
].name
= 0;
2761 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
2762 if (gcc_exec_prefix
)
2764 temp
= (char *) xmalloc (strlen (gcc_exec_prefix
) + strlen (spec_version
)
2765 + strlen (spec_machine
) + 3);
2766 strcpy (temp
, gcc_exec_prefix
);
2767 strcat (temp
, spec_machine
);
2769 strcat (temp
, spec_version
);
2771 gcc_exec_prefix
= temp
;
2775 /* Process a spec string, accumulating and running commands. */
2777 /* These variables describe the input file name.
2778 input_file_number is the index on outfiles of this file,
2779 so that the output file name can be stored for later use by %o.
2780 input_basename is the start of the part of the input file
2781 sans all directory names, and basename_length is the number
2782 of characters starting there excluding the suffix .c or whatever. */
2784 static char *input_filename
;
2785 static int input_file_number
;
2786 static int input_filename_length
;
2787 static int basename_length
;
2788 static char *input_basename
;
2789 static char *input_suffix
;
2791 /* These are variables used within do_spec and do_spec_1. */
2793 /* Nonzero if an arg has been started and not yet terminated
2794 (with space, tab or newline). */
2795 static int arg_going
;
2797 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2798 is a temporary file name. */
2799 static int delete_this_arg
;
2801 /* Nonzero means %w has been seen; the next arg to be terminated
2802 is the output file name of this compilation. */
2803 static int this_is_output_file
;
2805 /* Nonzero means %s has been seen; the next arg to be terminated
2806 is the name of a library file and we should try the standard
2807 search dirs for it. */
2808 static int this_is_library_file
;
2810 /* Nonzero means that the input of this command is coming from a pipe. */
2811 static int input_from_pipe
;
2813 /* Process the spec SPEC and run the commands specified therein.
2814 Returns 0 if the spec is successfully processed; -1 if failed. */
2824 delete_this_arg
= 0;
2825 this_is_output_file
= 0;
2826 this_is_library_file
= 0;
2827 input_from_pipe
= 0;
2829 value
= do_spec_1 (spec
, 0, NULL_PTR
);
2831 /* Force out any unfinished command.
2832 If -pipe, this forces out the last command if it ended in `|'. */
2835 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2838 if (argbuf_index
> 0)
2845 /* Process the sub-spec SPEC as a portion of a larger spec.
2846 This is like processing a whole spec except that we do
2847 not initialize at the beginning and we do not supply a
2848 newline by default at the end.
2849 INSWITCH nonzero means don't process %-sequences in SPEC;
2850 in this case, % is treated as an ordinary character.
2851 This is used while substituting switches.
2852 INSWITCH nonzero also causes SPC not to terminate an argument.
2854 Value is zero unless a line was finished
2855 and the command on that line reported an error. */
2858 do_spec_1 (spec
, inswitch
, soft_matched_part
)
2861 char *soft_matched_part
;
2863 register char *p
= spec
;
2870 /* If substituting a switch, treat all chars like letters.
2871 Otherwise, NL, SPC, TAB and % are special. */
2872 switch (inswitch
? 'a' : c
)
2875 /* End of line: finish any pending argument,
2876 then run the pending command if one has been started. */
2879 obstack_1grow (&obstack
, 0);
2880 string
= obstack_finish (&obstack
);
2881 if (this_is_library_file
)
2882 string
= find_file (string
);
2883 store_arg (string
, delete_this_arg
, this_is_output_file
);
2884 if (this_is_output_file
)
2885 outfiles
[input_file_number
] = string
;
2889 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
2892 for (i
= 0; i
< n_switches
; i
++)
2893 if (!strcmp (switches
[i
].part1
, "pipe"))
2896 /* A `|' before the newline means use a pipe here,
2897 but only if -pipe was specified.
2898 Otherwise, execute now and don't pass the `|' as an arg. */
2901 input_from_pipe
= 1;
2902 switches
[i
].valid
= 1;
2909 if (argbuf_index
> 0)
2915 /* Reinitialize for a new command, and for a new argument. */
2918 delete_this_arg
= 0;
2919 this_is_output_file
= 0;
2920 this_is_library_file
= 0;
2921 input_from_pipe
= 0;
2925 /* End any pending argument. */
2928 obstack_1grow (&obstack
, 0);
2929 string
= obstack_finish (&obstack
);
2930 if (this_is_library_file
)
2931 string
= find_file (string
);
2932 store_arg (string
, delete_this_arg
, this_is_output_file
);
2933 if (this_is_output_file
)
2934 outfiles
[input_file_number
] = string
;
2938 obstack_1grow (&obstack
, c
);
2944 /* Space or tab ends an argument if one is pending. */
2947 obstack_1grow (&obstack
, 0);
2948 string
= obstack_finish (&obstack
);
2949 if (this_is_library_file
)
2950 string
= find_file (string
);
2951 store_arg (string
, delete_this_arg
, this_is_output_file
);
2952 if (this_is_output_file
)
2953 outfiles
[input_file_number
] = string
;
2955 /* Reinitialize for a new argument. */
2957 delete_this_arg
= 0;
2958 this_is_output_file
= 0;
2959 this_is_library_file
= 0;
2966 fatal ("Invalid specification! Bug in cc.");
2969 obstack_grow (&obstack
, input_basename
, basename_length
);
2974 delete_this_arg
= 2;
2977 /* Dump out the directories specified with LIBRARY_PATH,
2978 followed by the absolute directories
2979 that we search for startfiles. */
2982 struct prefix_list
*pl
= startfile_prefix
.plist
;
2984 char *buffer
= (char *) xmalloc (bufsize
);
2987 for (; pl
; pl
= pl
->next
)
2989 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
2990 /* Used on systems which record the specified -L dirs
2991 and use them to search for dynamic linking. */
2992 /* Relative directories always come from -B,
2993 and it is better not to use them for searching
2994 at run time. In particular, stage1 loses */
2995 if (pl
->prefix
[0] != '/')
2998 /* Try subdirectory if there is one. */
2999 if (multilib_dir
!= NULL
)
3003 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3005 bufsize
= (strlen (pl
->prefix
)
3006 + strlen (machine_suffix
)) * 2 + 1;
3007 buffer
= (char *) xrealloc (buffer
, bufsize
);
3008 strcpy (buffer
, pl
->prefix
);
3009 strcat (buffer
, machine_suffix
);
3010 if (is_directory (buffer
, multilib_dir
, 1))
3012 do_spec_1 ("-L", 0, NULL_PTR
);
3013 #ifdef SPACE_AFTER_L_OPTION
3014 do_spec_1 (" ", 0, NULL_PTR
);
3016 do_spec_1 (buffer
, 1, NULL_PTR
);
3017 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3018 /* Make this a separate argument. */
3019 do_spec_1 (" ", 0, NULL_PTR
);
3022 if (!pl
->require_machine_suffix
)
3024 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3026 do_spec_1 ("-L", 0, NULL_PTR
);
3027 #ifdef SPACE_AFTER_L_OPTION
3028 do_spec_1 (" ", 0, NULL_PTR
);
3030 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3031 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3032 /* Make this a separate argument. */
3033 do_spec_1 (" ", 0, NULL_PTR
);
3039 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3041 do_spec_1 ("-L", 0, NULL_PTR
);
3042 #ifdef SPACE_AFTER_L_OPTION
3043 do_spec_1 (" ", 0, NULL_PTR
);
3045 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3046 /* Remove slash from machine_suffix. */
3047 if (strlen (machine_suffix
) >= bufsize
)
3048 bufsize
= strlen (machine_suffix
) * 2 + 1;
3049 buffer
= (char *) xrealloc (buffer
, bufsize
);
3050 strcpy (buffer
, machine_suffix
);
3051 idx
= strlen (buffer
);
3052 if (buffer
[idx
- 1] == '/')
3053 buffer
[idx
- 1] = 0;
3054 do_spec_1 (buffer
, 1, NULL_PTR
);
3055 /* Make this a separate argument. */
3056 do_spec_1 (" ", 0, NULL_PTR
);
3059 if (!pl
->require_machine_suffix
)
3061 if (is_directory (pl
->prefix
, "", 1))
3063 do_spec_1 ("-L", 0, NULL_PTR
);
3064 #ifdef SPACE_AFTER_L_OPTION
3065 do_spec_1 (" ", 0, NULL_PTR
);
3067 /* Remove slash from pl->prefix. */
3068 if (strlen (pl
->prefix
) >= bufsize
)
3069 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3070 buffer
= (char *) xrealloc (buffer
, bufsize
);
3071 strcpy (buffer
, pl
->prefix
);
3072 idx
= strlen (buffer
);
3073 if (buffer
[idx
- 1] == '/')
3074 buffer
[idx
- 1] = 0;
3075 do_spec_1 (buffer
, 1, NULL_PTR
);
3076 /* Make this a separate argument. */
3077 do_spec_1 (" ", 0, NULL_PTR
);
3086 /* {...:%efoo} means report an error with `foo' as error message
3087 and don't execute any more commands for this file. */
3091 while (*p
!= 0 && *p
!= '\n') p
++;
3092 buf
= (char *) alloca (p
- q
+ 1);
3093 strncpy (buf
, q
, p
- q
);
3103 if (save_temps_flag
)
3105 obstack_grow (&obstack
, input_basename
, basename_length
);
3106 delete_this_arg
= 0;
3110 #ifdef MKTEMP_EACH_FILE
3111 /* ??? This has a problem: the total number of
3112 values mktemp can return is limited.
3113 That matters for the names of object files.
3114 In 2.4, do something about that. */
3115 struct temp_name
*t
;
3117 while (*p
== '.' || isalpha (*p
))
3120 /* See if we already have an association of %g/%u/%U and
3122 for (t
= temp_names
; t
; t
= t
->next
)
3123 if (t
->length
== p
- suffix
3124 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3125 && t
->unique
== (c
!= 'g'))
3128 /* Make a new association if needed. %u requires one. */
3129 if (t
== 0 || c
== 'u')
3133 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3134 t
->next
= temp_names
;
3137 t
->length
= p
- suffix
;
3138 t
->suffix
= save_string (suffix
, p
- suffix
);
3139 t
->unique
= (c
!= 'g');
3140 choose_temp_base ();
3141 t
->filename
= temp_filename
;
3142 t
->filename_length
= temp_filename_length
;
3145 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3146 delete_this_arg
= 1;
3148 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3149 if (c
== 'u' || c
== 'U')
3155 sprintf (buff
, "%d", unique
);
3156 obstack_grow (&obstack
, buff
, strlen (buff
));
3159 delete_this_arg
= 1;
3165 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3171 struct prefix_list
*pl
= include_prefix
.plist
;
3173 if (gcc_exec_prefix
)
3175 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3176 /* Make this a separate argument. */
3177 do_spec_1 (" ", 0, NULL_PTR
);
3178 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3179 do_spec_1 (" ", 0, NULL_PTR
);
3182 for (; pl
; pl
= pl
->next
)
3184 do_spec_1 ("-isystem", 1, NULL_PTR
);
3185 /* Make this a separate argument. */
3186 do_spec_1 (" ", 0, NULL_PTR
);
3187 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3188 do_spec_1 (" ", 0, NULL_PTR
);
3196 for (f
= 0; f
< n_infiles
; f
++)
3197 store_arg (outfiles
[f
], 0, 0);
3202 this_is_library_file
= 1;
3206 this_is_output_file
= 1;
3211 int index
= argbuf_index
;
3212 /* Handle the {...} following the %W. */
3215 p
= handle_braces (p
+ 1);
3218 /* If any args were output, mark the last one for deletion
3220 if (argbuf_index
!= index
)
3221 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3225 /* %x{OPTION} records OPTION for %X to output. */
3231 /* Skip past the option value and make a copy. */
3236 string
= save_string (p1
+ 1, p
- p1
- 2);
3238 /* See if we already recorded this option. */
3239 for (i
= 0; i
< n_linker_options
; i
++)
3240 if (! strcmp (string
, linker_options
[i
]))
3246 /* This option is new; add it. */
3248 if (!linker_options
)
3250 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3253 = (char **) xrealloc (linker_options
,
3254 n_linker_options
* sizeof (char **));
3256 linker_options
[n_linker_options
- 1] = string
;
3260 /* Dump out the options accumulated previously using %x,
3261 -Xlinker and -Wl,. */
3263 for (i
= 0; i
< n_linker_options
; i
++)
3265 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3266 /* Make each accumulated option a separate argument. */
3267 do_spec_1 (" ", 0, NULL_PTR
);
3271 /* Dump out the options accumulated previously using -Wa,. */
3273 for (i
= 0; i
< n_assembler_options
; i
++)
3275 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3276 /* Make each accumulated option a separate argument. */
3277 do_spec_1 (" ", 0, NULL_PTR
);
3281 /* Here are digits and numbers that just process
3282 a certain constant string as a spec. */
3285 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3291 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3297 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3303 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3309 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3315 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3321 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3327 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3333 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3340 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3344 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3348 if (! strncmp (y
, "-D", 2))
3349 /* Copy the whole option. */
3350 while (*y
&& *y
!= ' ' && *y
!= '\t')
3352 else if (*y
== ' ' || *y
== '\t')
3353 /* Copy whitespace to the result. */
3355 /* Don't copy other options. */
3362 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3370 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3374 /* Copy all of CPP_PREDEFINES into BUF,
3375 but put __ after every -D and at the end of each arg. */
3379 if (! strncmp (y
, "-D", 2))
3387 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3389 /* Stick __ at front of macro name. */
3392 /* Arrange to stick __ at the end as well. */
3396 /* Copy the macro name. */
3397 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3406 /* Copy the value given, if any. */
3407 while (*y
&& *y
!= ' ' && *y
!= '\t')
3410 else if (*y
== ' ' || *y
== '\t')
3411 /* Copy whitespace to the result. */
3413 /* Don't copy -A options */
3419 /* Copy all of CPP_PREDEFINES into BUF,
3420 but put __ after every -D. */
3424 if (! strncmp (y
, "-D", 2))
3429 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3431 /* Stick -D__ at front of macro name. */
3437 /* Copy the macro name. */
3438 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3441 /* Copy the value given, if any. */
3442 while (*y
&& *y
!= ' ' && *y
!= '\t')
3447 /* Do not copy this macro - we have just done it before */
3448 while (*y
&& *y
!= ' ' && *y
!= '\t')
3452 else if (*y
== ' ' || *y
== '\t')
3453 /* Copy whitespace to the result. */
3455 /* Don't copy -A options */
3461 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3465 if (! strncmp (y
, "-A", 2))
3466 /* Copy the whole option. */
3467 while (*y
&& *y
!= ' ' && *y
!= '\t')
3469 else if (*y
== ' ' || *y
== '\t')
3470 /* Copy whitespace to the result. */
3472 /* Don't copy other options. */
3479 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3486 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3491 /* Here we define characters other than letters and digits. */
3494 p
= handle_braces (p
);
3500 obstack_1grow (&obstack
, '%');
3504 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3505 do_spec_1 (" ", 0, NULL_PTR
);
3508 /* Process a string found as the value of a spec given by name.
3509 This feature allows individual machine descriptions
3510 to add and use their own specs.
3511 %[...] modifies -D options the way %P does;
3512 %(...) uses the spec unmodified. */
3517 struct spec_list
*sl
;
3520 /* The string after the S/P is the name of a spec that is to be
3522 while (*p
&& *p
!= ')' && *p
!= ']')
3525 /* See if it's in the list */
3526 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3527 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
3537 value
= do_spec_1 (name
, 0, NULL_PTR
);
3543 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3547 /* Copy all of NAME into BUF, but put __ after
3548 every -D and at the end of each arg, */
3551 if (! strncmp (y
, "-D", 2))
3559 else if (*y
== ' ' || *y
== 0)
3573 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3579 /* Discard the closing paren or bracket. */
3587 int c1
= *p
++; /* Select first or second version number. */
3588 char *v
= compiler_version
;
3590 /* If desired, advance to second version number. */
3593 /* Set P after the first period. */
3594 while (*v
!= 0 && *v
!= ' ' && *v
!= '.')
3599 /* Set Q at the next period or at the end. */
3601 while (*q
!= 0 && *q
!= ' ' && *q
!= '.')
3603 /* Empty string means zero. */
3609 /* Put that part into the command. */
3610 obstack_grow (&obstack
, v
, q
- v
);
3616 if (input_from_pipe
)
3617 do_spec_1 ("-", 0, NULL_PTR
);
3626 /* Backslash: treat next character as ordinary. */
3631 /* Ordinary character: put it into the current argument. */
3632 obstack_1grow (&obstack
, c
);
3636 return 0; /* End of string */
3639 /* Return 0 if we call do_spec_1 and that returns -1. */
3652 /* A `|' after the open-brace means,
3653 if the test fails, output a single minus sign rather than nothing.
3654 This is used in %{|!pipe:...}. */
3658 /* A `!' after the open-brace negates the condition:
3659 succeed if the specified switch is not present. */
3663 /* A `.' after the open-brace means test against the current suffix. */
3673 while (*p
!= ':' && *p
!= '}') p
++;
3676 register int count
= 1;
3694 int found
= (input_suffix
!= 0
3695 && strlen (input_suffix
) == p
- filter
3696 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3702 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3707 else if (p
[-1] == '*' && p
[0] == '}')
3709 /* Substitute all matching switches as separate args. */
3712 for (i
= 0; i
< n_switches
; i
++)
3713 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3714 && check_live_switch (i
, p
- filter
))
3719 /* Test for presence of the specified switch. */
3723 /* If name specified ends in *, as in {x*:...},
3724 check for %* and handle that case. */
3725 if (p
[-1] == '*' && !negate
)
3730 /* First see whether we have %*. */
3734 if (*r
== '%' && r
[1] == '*')
3738 /* If we do, handle that case. */
3741 /* Substitute all matching switches as separate args.
3742 But do this by substituting for %*
3743 in the text that follows the colon. */
3745 unsigned hard_match_len
= p
- filter
- 1;
3746 char *string
= save_string (p
+ 1, q
- p
- 2);
3748 for (i
= 0; i
< n_switches
; i
++)
3749 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3750 && check_live_switch (i
, -1))
3752 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
3753 /* Pass any arguments this switch has. */
3761 /* If name specified ends in *, as in {x*:...},
3762 check for presence of any switch name starting with x. */
3765 for (i
= 0; i
< n_switches
; i
++)
3767 unsigned hard_match_len
= p
- filter
- 1;
3769 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3770 && check_live_switch (i
, hard_match_len
))
3776 /* Otherwise, check for presence of exact name specified. */
3779 for (i
= 0; i
< n_switches
; i
++)
3781 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3782 && switches
[i
].part1
[p
- filter
] == 0
3783 && check_live_switch (i
, -1))
3791 /* If it is as desired (present for %{s...}, absent for %{-s...})
3792 then substitute either the switch or the specified
3793 conditional text. */
3794 if (present
!= negate
)
3802 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3808 /* Here if a %{|...} conditional fails: output a minus sign,
3809 which means "standard output" or "standard input". */
3810 do_spec_1 ("-", 0, NULL_PTR
);
3817 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
3818 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
3819 spec, or -1 if either exact match or %* is used.
3821 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
3822 whose value does not begin with "no-" is obsoleted by the same value
3823 with the "no-", similarly for a switch with the "no-" prefix. */
3826 check_live_switch (switchnum
, prefix_length
)
3830 char *name
= switches
[switchnum
].part1
;
3833 /* In the common case of {<at-most-one-letter>*}, a negating
3834 switch would always match, so ignore that case. We will just
3835 send the conflicting switches to the compiler phase. */
3836 if (prefix_length
>= 0 && prefix_length
<= 1)
3839 /* If we already processed this switch and determined if it was
3840 live or not, return our past determination. */
3841 if (switches
[switchnum
].live_cond
!= 0)
3842 return switches
[switchnum
].live_cond
> 0;
3844 /* Now search for duplicate in a manner that depends on the name. */
3848 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
3849 if (switches
[i
].part1
[0] == 'O')
3851 switches
[switchnum
].valid
= 1;
3852 switches
[switchnum
].live_cond
= -1;
3857 case 'W': case 'f': case 'm':
3858 if (! strncmp (name
+ 1, "no-", 3))
3860 /* We have Xno-YYY, search for XYYY. */
3861 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
3862 if (switches
[i
].part1
[0] == name
[0]
3863 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
3865 switches
[switchnum
].valid
= 1;
3866 switches
[switchnum
].live_cond
= -1;
3872 /* We have XYYY, search for Xno-YYY. */
3873 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
3874 if (switches
[i
].part1
[0] == name
[0]
3875 && switches
[i
].part1
[1] == 'n'
3876 && switches
[i
].part1
[2] == 'o'
3877 && switches
[i
].part1
[3] == '-'
3878 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
3880 switches
[switchnum
].valid
= 1;
3881 switches
[switchnum
].live_cond
= -1;
3888 /* Otherwise the switch is live. */
3889 switches
[switchnum
].live_cond
= 1;
3893 /* Pass a switch to the current accumulating command
3894 in the same form that we received it.
3895 SWITCHNUM identifies the switch; it is an index into
3896 the vector of switches gcc received, which is `switches'.
3897 This cannot fail since it never finishes a command line.
3899 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
3902 give_switch (switchnum
, omit_first_word
)
3904 int omit_first_word
;
3906 if (!omit_first_word
)
3908 do_spec_1 ("-", 0, NULL_PTR
);
3909 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
3911 do_spec_1 (" ", 0, NULL_PTR
);
3912 if (switches
[switchnum
].args
!= 0)
3915 for (p
= switches
[switchnum
].args
; *p
; p
++)
3917 do_spec_1 (*p
, 1, NULL_PTR
);
3918 do_spec_1 (" ", 0, NULL_PTR
);
3921 switches
[switchnum
].valid
= 1;
3924 /* Search for a file named NAME trying various prefixes including the
3925 user's -B prefix and some standard ones.
3926 Return the absolute file name found. If nothing is found, return NAME. */
3934 /* Try multilib_dir if it is defined. */
3935 if (multilib_dir
!= NULL
)
3939 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
3940 strcpy (try, multilib_dir
);
3944 newname
= find_a_file (&startfile_prefix
, try, R_OK
);
3946 /* If we don't find it in the multi library dir, then fall
3947 through and look for it in the normal places. */
3948 if (newname
!= NULL
)
3952 newname
= find_a_file (&startfile_prefix
, name
, R_OK
);
3953 return newname
? newname
: name
;
3956 /* Determine whether a directory exists. If LINKER, return 0 for
3957 certain fixed names not needed by the linker. If not LINKER, it is
3958 only important to return 0 if the host machine has a small ARG_MAX
3962 is_directory (path1
, path2
, linker
)
3967 int len1
= strlen (path1
);
3968 int len2
= strlen (path2
);
3969 char *path
= (char *) alloca (3 + len1
+ len2
);
3973 #ifndef SMALL_ARG_MAX
3978 /* Construct the path from the two parts. Ensure the string ends with "/.".
3979 The resulting path will be a directory even if the given path is a
3981 bcopy (path1
, path
, len1
);
3982 bcopy (path2
, path
+ len1
, len2
);
3983 cp
= path
+ len1
+ len2
;
3989 /* Exclude directories that the linker is known to search. */
3991 && ((cp
- path
== 6 && strcmp (path
, "/lib/.") == 0)
3992 || (cp
- path
== 10 && strcmp (path
, "/usr/lib/.") == 0)))
3995 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
3998 /* On fatal signals, delete all the temporary files. */
4001 fatal_error (signum
)
4004 signal (signum
, SIG_DFL
);
4005 delete_failure_queue ();
4006 delete_temp_files ();
4007 /* Get the same signal again, this time not handled,
4008 so its normal effect occurs. */
4009 kill (getpid (), signum
);
4020 int linker_was_run
= 0;
4021 char *explicit_link_files
;
4025 p
= argv
[0] + strlen (argv
[0]);
4026 while (p
!= argv
[0] && p
[-1] != '/') --p
;
4029 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4030 signal (SIGINT
, fatal_error
);
4032 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4033 signal (SIGHUP
, fatal_error
);
4035 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4036 signal (SIGTERM
, fatal_error
);
4038 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4039 signal (SIGPIPE
, fatal_error
);
4043 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4045 obstack_init (&obstack
);
4047 /* Set up to remember the pathname of gcc and any options
4048 needed for collect. We use argv[0] instead of programname because
4049 we need the complete pathname. */
4050 obstack_init (&collect_obstack
);
4051 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4052 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4053 putenv (obstack_finish (&collect_obstack
));
4055 /* Choose directory for temp files. */
4057 choose_temp_base ();
4059 /* Make a table of what switches there are (switches, n_switches).
4060 Make a table of specified input files (infiles, n_infiles).
4061 Decode switches that are handled locally. */
4063 process_command (argc
, argv
);
4065 /* Initialize the vector of specs to just the default.
4066 This means one element containing 0s, as a terminator. */
4068 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4069 bcopy ((char *) default_compilers
, (char *) compilers
,
4070 sizeof default_compilers
);
4071 n_compilers
= n_default_compilers
;
4073 /* Read specs from a file if there is one. */
4075 machine_suffix
= concat (spec_machine
, "/", concat (spec_version
, "/", ""));
4076 just_machine_suffix
= concat (spec_machine
, "/", "");
4078 specs_file
= find_a_file (&startfile_prefix
, "specs", R_OK
);
4079 /* Read the specs file unless it is a default one. */
4080 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4081 read_specs (specs_file
);
4083 /* If not cross-compiling, look for startfiles in the standard places. */
4084 /* The fact that these are done here, after reading the specs file,
4085 means that it cannot be found in these directories.
4086 But that's okay. It should never be there anyway. */
4089 #ifdef MD_EXEC_PREFIX
4090 add_prefix (&exec_prefix
, md_exec_prefix
, 0, 0, NULL_PTR
);
4091 add_prefix (&startfile_prefix
, md_exec_prefix
, 0, 0, NULL_PTR
);
4094 #ifdef MD_STARTFILE_PREFIX
4095 add_prefix (&startfile_prefix
, md_startfile_prefix
, 0, 0, NULL_PTR
);
4098 #ifdef MD_STARTFILE_PREFIX_1
4099 add_prefix (&startfile_prefix
, md_startfile_prefix_1
, 0, 0, NULL_PTR
);
4102 /* If standard_startfile_prefix is relative, base it on
4103 standard_exec_prefix. This lets us move the installed tree
4104 as a unit. If GCC_EXEC_PREFIX is defined, base
4105 standard_startfile_prefix on that as well. */
4106 if (*standard_startfile_prefix
== '/')
4107 add_prefix (&startfile_prefix
, standard_startfile_prefix
, 0, 0,
4111 if (gcc_exec_prefix
)
4112 add_prefix (&startfile_prefix
,
4113 concat (gcc_exec_prefix
,
4114 standard_startfile_prefix
,
4117 add_prefix (&startfile_prefix
,
4118 concat (standard_exec_prefix
,
4120 standard_startfile_prefix
),
4124 add_prefix (&startfile_prefix
, standard_startfile_prefix_1
, 0, 0,
4126 add_prefix (&startfile_prefix
, standard_startfile_prefix_2
, 0, 0,
4128 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4129 add_prefix (&startfile_prefix
, "./", 0, 1, NULL_PTR
);
4133 /* Now we have the specs.
4134 Set the `valid' bits for switches that match anything in any spec. */
4136 validate_all_switches ();
4138 /* Now that we have the switches and the specs, set
4139 the subdirectory based on the options. */
4140 set_multilib_dir ();
4142 /* Warn about any switches that no pass was interested in. */
4144 for (i
= 0; i
< n_switches
; i
++)
4145 if (! switches
[i
].valid
)
4146 error ("unrecognized option `-%s'", switches
[i
].part1
);
4148 /* Obey some of the options. */
4150 if (print_file_name
)
4152 printf ("%s\n", find_file (print_file_name
));
4156 if (print_prog_name
)
4158 char *newname
= find_a_file (&exec_prefix
, print_prog_name
, X_OK
);
4159 printf ("%s\n", (newname
? newname
: print_prog_name
));
4163 if (print_multi_lib
)
4165 print_multilib_info ();
4169 if (print_multi_directory
)
4171 if (multilib_dir
== NULL
)
4174 printf ("%s\n", multilib_dir
);
4180 fprintf (stderr
, "gcc version %s\n", version_string
);
4186 fatal ("No input files");
4188 /* Make a place to record the compiler output file names
4189 that correspond to the input files. */
4191 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4192 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4194 /* Record which files were specified explicitly as link input. */
4196 explicit_link_files
= xmalloc (n_infiles
);
4197 bzero (explicit_link_files
, n_infiles
);
4199 for (i
= 0; i
< n_infiles
; i
++)
4201 register struct compiler
*cp
= 0;
4202 int this_file_error
= 0;
4204 /* Tell do_spec what to substitute for %i. */
4206 input_filename
= infiles
[i
].name
;
4207 input_filename_length
= strlen (input_filename
);
4208 input_file_number
= i
;
4210 /* Use the same thing in %o, unless cp->spec says otherwise. */
4212 outfiles
[i
] = input_filename
;
4214 /* Figure out which compiler from the file's suffix. */
4216 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4217 infiles
[i
].language
);
4221 /* Ok, we found an applicable compiler. Run its spec. */
4222 /* First say how much of input_filename to substitute for %b */
4226 input_basename
= input_filename
;
4227 for (p
= input_filename
; *p
; p
++)
4229 input_basename
= p
+ 1;
4231 /* Find a suffix starting with the last period,
4232 and set basename_length to exclude that suffix. */
4233 basename_length
= strlen (input_basename
);
4234 p
= input_basename
+ basename_length
;
4235 while (p
!= input_basename
&& *p
!= '.') --p
;
4236 if (*p
== '.' && p
!= input_basename
)
4238 basename_length
= p
- input_basename
;
4239 input_suffix
= p
+ 1;
4245 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4247 len
+= strlen (cp
->spec
[j
]);
4249 p
= (char *) xmalloc (len
+ 1);
4252 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4255 strcpy (p
+ len
, cp
->spec
[j
]);
4256 len
+= strlen (cp
->spec
[j
]);
4259 value
= do_spec (p
);
4262 this_file_error
= 1;
4265 /* If this file's name does not contain a recognized suffix,
4266 record it as explicit linker input. */
4269 explicit_link_files
[i
] = 1;
4271 /* Clear the delete-on-failure queue, deleting the files in it
4272 if this compilation failed. */
4274 if (this_file_error
)
4276 delete_failure_queue ();
4279 /* If this compilation succeeded, don't delete those files later. */
4280 clear_failure_queue ();
4283 /* Run ld to link all the compiler output files. */
4285 if (error_count
== 0)
4287 int tmp
= execution_count
;
4291 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4293 putenv_from_prefixes (&exec_prefix
, "COMPILER_PATH=");
4294 putenv_from_prefixes (&startfile_prefix
, "LIBRARY_PATH=");
4296 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4298 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4299 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4302 for (i
= 0; i
< n_switches
; i
++)
4306 obstack_grow (&collect_obstack
, " ", 1);
4309 obstack_grow (&collect_obstack
, "-", 1);
4310 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4311 strlen (switches
[i
].part1
));
4313 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4315 obstack_grow (&collect_obstack
, " ", 1);
4316 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4319 obstack_grow (&collect_obstack
, "\0", 1);
4320 putenv (obstack_finish (&collect_obstack
));
4322 value
= do_spec (link_command_spec
);
4325 linker_was_run
= (tmp
!= execution_count
);
4328 /* Warn if a -B option was specified but the prefix was never used. */
4329 unused_prefix_warnings (&exec_prefix
);
4330 unused_prefix_warnings (&startfile_prefix
);
4332 /* If options said don't run linker,
4333 complain about input files to be given to the linker. */
4335 if (! linker_was_run
&& error_count
== 0)
4336 for (i
= 0; i
< n_infiles
; i
++)
4337 if (explicit_link_files
[i
])
4338 error ("%s: linker input file unused since linking not done",
4341 /* Delete some or all of the temporary files we made. */
4344 delete_failure_queue ();
4345 delete_temp_files ();
4347 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4352 /* Find the proper compilation spec for the file name NAME,
4353 whose length is LENGTH. LANGUAGE is the specified language,
4354 or 0 if none specified. */
4356 static struct compiler
*
4357 lookup_compiler (name
, length
, language
)
4362 struct compiler
*cp
;
4364 /* Look for the language, if one is spec'd. */
4367 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4371 if (cp
->suffix
[0] == '@'
4372 && !strcmp (cp
->suffix
+ 1, language
))
4376 error ("language %s not recognized", language
);
4379 /* Look for a suffix. */
4380 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4382 if (/* The suffix `-' matches only the file name `-'. */
4383 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4385 (strlen (cp
->suffix
) < length
4386 /* See if the suffix matches the end of NAME. */
4387 && !strcmp (cp
->suffix
,
4388 name
+ length
- strlen (cp
->suffix
))))
4390 if (cp
->spec
[0][0] == '@')
4392 struct compiler
*new;
4393 /* An alias entry maps a suffix to a language.
4394 Search for the language; pass 0 for NAME and LENGTH
4395 to avoid infinite recursion if language not found.
4396 Construct the new compiler spec. */
4397 language
= cp
->spec
[0] + 1;
4398 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4399 new->suffix
= cp
->suffix
;
4400 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4401 (char *) new->spec
, sizeof new->spec
);
4404 /* A non-alias entry: return it. */
4416 register char *value
= (char *) malloc (size
);
4418 fatal ("virtual memory exhausted");
4423 xrealloc (ptr
, size
)
4427 register char *value
= (char *) realloc (ptr
, size
);
4429 fatal ("virtual memory exhausted");
4433 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
4439 int len1
= strlen (s1
), len2
= strlen (s2
), len3
= strlen (s3
);
4440 char *result
= xmalloc (len1
+ len2
+ len3
+ 1);
4442 strcpy (result
, s1
);
4443 strcpy (result
+ len1
, s2
);
4444 strcpy (result
+ len1
+ len2
, s3
);
4445 *(result
+ len1
+ len2
+ len3
) = 0;
4451 save_string (s
, len
)
4455 register char *result
= xmalloc (len
+ 1);
4457 bcopy (s
, result
, len
);
4463 pfatal_with_name (name
)
4468 if (errno
< sys_nerr
)
4469 s
= concat ("%s: ", sys_errlist
[errno
], "");
4471 s
= "cannot open %s";
4476 perror_with_name (name
)
4481 if (errno
< sys_nerr
)
4482 s
= concat ("%s: ", sys_errlist
[errno
], "");
4484 s
= "cannot open %s";
4494 if (errno
< sys_nerr
)
4495 s
= concat ("installation problem, cannot exec %s: ",
4496 sys_errlist
[errno
], "");
4498 s
= "installation problem, cannot exec %s";
4502 /* More 'friendly' abort that prints the line and file.
4503 config.h can #define abort fancy_abort if you like that sort of thing. */
4508 fatal ("Internal gcc abort.");
4513 /* Output an error message and exit */
4516 fatal
VPROTO((char *format
, ...))
4523 VA_START (ap
, format
);
4526 format
= va_arg (ap
, char*);
4529 fprintf (stderr
, "%s: ", programname
);
4530 vfprintf (stderr
, format
, ap
);
4532 fprintf (stderr
, "\n");
4533 delete_temp_files ();
4538 error
VPROTO((char *format
, ...))
4545 VA_START (ap
, format
);
4548 format
= va_arg (ap
, char*);
4551 fprintf (stderr
, "%s: ", programname
);
4552 vfprintf (stderr
, format
, ap
);
4555 fprintf (stderr
, "\n");
4558 #else /* not HAVE_VPRINTF */
4561 fatal (msg
, arg1
, arg2
)
4562 char *msg
, *arg1
, *arg2
;
4564 error (msg
, arg1
, arg2
);
4565 delete_temp_files ();
4570 error (msg
, arg1
, arg2
)
4571 char *msg
, *arg1
, *arg2
;
4573 fprintf (stderr
, "%s: ", programname
);
4574 fprintf (stderr
, msg
, arg1
, arg2
);
4575 fprintf (stderr
, "\n");
4578 #endif /* not HAVE_VPRINTF */
4582 validate_all_switches ()
4584 struct compiler
*comp
;
4587 struct spec_list
*spec
;
4589 for (comp
= compilers
; comp
->spec
[0]; comp
++)
4592 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
4596 if (c
== '%' && *p
== '{')
4597 /* We have a switch spec. */
4598 validate_switches (p
+ 1);
4602 /* look through the linked list of extra specs read from the specs file */
4603 for (spec
= specs
; spec
; spec
= spec
->next
)
4607 if (c
== '%' && *p
== '{')
4608 /* We have a switch spec. */
4609 validate_switches (p
+ 1);
4612 p
= link_command_spec
;
4614 if (c
== '%' && *p
== '{')
4615 /* We have a switch spec. */
4616 validate_switches (p
+ 1);
4618 /* Now notice switches mentioned in the machine-specific specs. */
4622 if (c
== '%' && *p
== '{')
4623 /* We have a switch spec. */
4624 validate_switches (p
+ 1);
4628 if (c
== '%' && *p
== '{')
4629 /* We have a switch spec. */
4630 validate_switches (p
+ 1);
4634 if (c
== '%' && *p
== '{')
4635 /* We have a switch spec. */
4636 validate_switches (p
+ 1);
4638 p
= signed_char_spec
;
4640 if (c
== '%' && *p
== '{')
4641 /* We have a switch spec. */
4642 validate_switches (p
+ 1);
4646 if (c
== '%' && *p
== '{')
4647 /* We have a switch spec. */
4648 validate_switches (p
+ 1);
4652 if (c
== '%' && *p
== '{')
4653 /* We have a switch spec. */
4654 validate_switches (p
+ 1);
4658 if (c
== '%' && *p
== '{')
4659 /* We have a switch spec. */
4660 validate_switches (p
+ 1);
4664 if (c
== '%' && *p
== '{')
4665 /* We have a switch spec. */
4666 validate_switches (p
+ 1);
4670 if (c
== '%' && *p
== '{')
4671 /* We have a switch spec. */
4672 validate_switches (p
+ 1);
4675 /* Look at the switch-name that comes after START
4676 and mark as valid all supplied switches that match it. */
4679 validate_switches (start
)
4682 register char *p
= start
;
4697 while (*p
!= ':' && *p
!= '}') p
++;
4701 else if (p
[-1] == '*')
4703 /* Mark all matching switches as valid. */
4705 for (i
= 0; i
< n_switches
; i
++)
4706 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
4707 switches
[i
].valid
= 1;
4711 /* Mark an exact matching switch as valid. */
4712 for (i
= 0; i
< n_switches
; i
++)
4714 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
4715 && switches
[i
].part1
[p
- filter
] == 0)
4716 switches
[i
].valid
= 1;
4721 /* Check whether a particular argument was used. */
4730 for (i
= 0; i
< n_switches
; i
++)
4731 if (! strncmp (switches
[i
].part1
, p
, len
)
4732 && strlen (switches
[i
].part1
) == len
)
4737 /* Work out the subdirectory to use based on the
4738 options. The format of multilib_select is a list of elements.
4739 Each element is a subdirectory name followed by a list of options
4740 followed by a semicolon. gcc will consider each line in turn. If
4741 none of the options beginning with an exclamation point are
4742 present, and all of the other options are present, that
4743 subdirectory will be used. */
4748 char *p
= multilib_select
;
4750 char *this_path
, *this_arg
;
4755 /* Ignore newlines. */
4762 /* Get the initial path. */
4770 this_path_len
= p
- this_path
;
4772 /* Check the arguments. */
4787 while (*p
!= ' ' && *p
!= ';')
4794 if (*this_arg
== '!')
4795 failed
= used_arg (this_arg
+ 1, p
- (this_arg
+ 1));
4797 failed
= ! used_arg (this_arg
, p
- this_arg
);
4805 if (this_path_len
!= 1
4806 || this_path
[0] != '.')
4808 multilib_dir
= xmalloc (this_path_len
+ 1);
4809 strncpy (multilib_dir
, this_path
, this_path_len
);
4810 multilib_dir
[this_path_len
] = '\0';
4819 /* Print out the multiple library subdirectory selection
4820 information. This prints out a series of lines. Each line looks
4821 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
4822 required. Only the desired options are printed out, the negative
4823 matches. The options are print without a leading dash. There are
4824 no spaces to make it easy to use the information in the shell.
4825 Each subdirectory is printed only once. This assumes the ordering
4826 generated by the genmultilib script. */
4829 print_multilib_info ()
4831 char *p
= multilib_select
;
4832 char *last_path
, *this_path
;
4833 int last_path_len
, skip
, use_arg
;
4837 /* Ignore newlines. */
4844 /* Get the initial path. */
4853 /* If this is a duplicate, skip it. */
4854 skip
= (p
- this_path
== last_path_len
4855 && ! strncmp (last_path
, this_path
, last_path_len
));
4857 last_path
= this_path
;
4858 last_path_len
= p
- this_path
;
4864 for (p1
= last_path
; p1
< p
; p1
++)
4883 use_arg
= *p
!= '!';
4888 while (*p
!= ' ' && *p
!= ';')