1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 This paragraph is here to try to keep Sun CC from dying.
22 The number of chars here seems crucial!!!! */
24 /* This program is the user interface to the C compiler and possibly to
25 other compilers. It is used because compilation is a complicated procedure
26 which involves running several programs and passing temporary files between
27 them, forwarding the users switches to those programs selectively,
28 and deleting the temporary files at the end.
30 CC recognizes how to compile each input file by suffixes in the file names.
31 Once it knows which kind of compilation to perform, the procedure for
32 compilation is specified by a string called a "spec". */
34 #include <sys/types.h>
41 #include <sys/file.h> /* May get R_OK, etc. on some systems. */
55 /* Include multi-lib information. */
65 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
68 #define WTERMSIG(S) ((S) & 0x7f)
71 #define WIFEXITED(S) (((S) & 0xff) == 0)
74 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
77 /* Add prototype support. */
79 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
80 #define PROTO(ARGS) ARGS
82 #define PROTO(ARGS) ()
88 #define PVPROTO(ARGS) ARGS
89 #define VPROTO(ARGS) ARGS
90 #define VA_START(va_list,var) va_start(va_list,var)
92 #define PVPROTO(ARGS) ()
93 #define VPROTO(ARGS) (va_alist) va_dcl
94 #define VA_START(va_list,var) va_start(va_list)
98 /* Define a generic NULL if one hasn't already been defined. */
104 /* Define O_RDONLY if the system hasn't defined it for us. */
110 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
111 #define GENERIC_PTR void *
113 #define GENERIC_PTR char *
118 #define NULL_PTR ((GENERIC_PTR)0)
125 /* On MSDOS, write temp files in current dir
126 because there's no place else we can expect to use. */
133 /* Test if something is a normal file. */
135 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
138 /* Test if something is a directory. */
140 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
143 /* By default there is no special suffix for executables. */
144 #ifndef EXECUTABLE_SUFFIX
145 #define EXECUTABLE_SUFFIX ""
148 /* By default, the suffix for object files is ".o". */
150 #define HAVE_OBJECT_SUFFIX
152 #define OBJECT_SUFFIX ".o"
155 /* By default, colon separates directories in a path. */
156 #ifndef PATH_SEPARATOR
157 #define PATH_SEPARATOR ':'
160 #ifndef DIR_SEPARATOR
161 #define DIR_SEPARATOR '/'
164 static char dir_separator_str
[] = {DIR_SEPARATOR
, 0};
166 #define obstack_chunk_alloc xmalloc
167 #define obstack_chunk_free free
170 extern char *getenv ();
177 #ifndef HAVE_STRERROR
179 extern const char *const sys_errlist
[];
181 extern char *sys_errlist
[];
184 extern char *strerror();
187 extern int execv (), execvp ();
189 /* If a stage of compilation returns an exit status >= 1,
190 compilation of that file ceases. */
192 #define MIN_FATAL_STATUS 1
194 /* Flag saying to print the directories gcc will search through looking for
195 programs, libraries, etc. */
197 static int print_search_dirs
;
199 /* Flag saying to print the full filename of this file
200 as found through our usual search mechanism. */
202 static char *print_file_name
= NULL
;
204 /* As print_file_name, but search for executable file. */
206 static char *print_prog_name
= NULL
;
208 /* Flag saying to print the relative path we'd use to
209 find libgcc.a given the current compiler flags. */
211 static int print_multi_directory
;
213 /* Flag saying to print the list of subdirectories and
214 compiler flags used to select them in a standard form. */
216 static int print_multi_lib
;
218 /* Flag indicating whether we should print the command and arguments */
220 static int verbose_flag
;
222 /* Nonzero means write "temp" files in source directory
223 and use the source file's name in them, and don't delete them. */
225 static int save_temps_flag
;
227 /* The compiler version. */
229 static char *compiler_version
;
231 /* The target version specified with -V */
233 static char *spec_version
= DEFAULT_TARGET_VERSION
;
235 /* The target machine specified with -b. */
237 static char *spec_machine
= DEFAULT_TARGET_MACHINE
;
239 /* Nonzero if cross-compiling.
240 When -b is used, the value comes from the `specs' file. */
243 static int cross_compile
= 1;
245 static int cross_compile
= 0;
248 /* The number of errors that have occurred; the link phase will not be
249 run if this is non-zero. */
250 static int error_count
= 0;
252 /* This is the obstack which we use to allocate many strings. */
254 static struct obstack obstack
;
256 /* This is the obstack to build an environment variable to pass to
257 collect2 that describes all of the relevant switches of what to
258 pass the compiler in building the list of pointers to constructors
261 static struct obstack collect_obstack
;
263 extern char *version_string
;
265 /* Forward declaration for prototypes. */
268 static void set_spec
PROTO((char *, char *));
269 static struct compiler
*lookup_compiler
PROTO((char *, int, char *));
270 static char *build_search_list
PROTO((struct path_prefix
*, char *, int));
271 static void putenv_from_prefixes
PROTO((struct path_prefix
*, char *));
272 static char *find_a_file
PROTO((struct path_prefix
*, char *, int));
273 static void add_prefix
PROTO((struct path_prefix
*, char *, int, int, int *));
274 static char *skip_whitespace
PROTO((char *));
275 static void record_temp_file
PROTO((char *, int, int));
276 static void delete_if_ordinary
PROTO((char *));
277 static void delete_temp_files
PROTO((void));
278 static void delete_failure_queue
PROTO((void));
279 static void clear_failure_queue
PROTO((void));
280 static char *choose_temp_base_try
PROTO((char *, char *));
281 static void choose_temp_base
PROTO((void));
282 static int check_live_switch
PROTO((int, int));
283 static char *handle_braces
PROTO((char *));
284 static char *save_string
PROTO((char *, int));
285 static char *concat
PROTO((char *, char *));
286 static char *concat3
PROTO((char *, char *, char *));
287 static char *concat4
PROTO((char *, char *, char *, char *));
288 static char *concat6
PROTO((char *, char *, char *, char *, char *, \
290 static int do_spec
PROTO((char *));
291 static int do_spec_1
PROTO((char *, int, char *));
292 static char *find_file
PROTO((char *));
293 static int is_directory
PROTO((char *, char *, int));
294 static void validate_switches
PROTO((char *));
295 static void validate_all_switches
PROTO((void));
296 static void give_switch
PROTO((int, int));
297 static int used_arg
PROTO((char *, int));
298 static void set_multilib_dir
PROTO((void));
299 static void print_multilib_info
PROTO((void));
300 static void pfatal_with_name
PROTO((char *));
301 static void perror_with_name
PROTO((char *));
302 static void perror_exec
PROTO((char *));
304 static void fatal
PVPROTO((char *, ...));
305 static void error
PVPROTO((char *, ...));
307 /* We must not provide any prototype here, even if ANSI C. */
308 static void fatal
PROTO(());
309 static void error
PROTO(());
316 /* Specs are strings containing lines, each of which (if not blank)
317 is made up of a program name, and arguments separated by spaces.
318 The program name must be exact and start from root, since no path
319 is searched and it is unreliable to depend on the current working directory.
320 Redirection of input or output is not supported; the subprograms must
321 accept filenames saying what files to read and write.
323 In addition, the specs can contain %-sequences to substitute variable text
324 or for conditional text. Here is a table of all defined %-sequences.
325 Note that spaces are not generated automatically around the results of
326 expanding these sequences; therefore, you can concatenate them together
327 or with constant text in a single argument.
329 %% substitute one % into the program name or argument.
330 %i substitute the name of the input file being processed.
331 %b substitute the basename of the input file being processed.
332 This is the substring up to (and not including) the last period
333 and not including the directory.
334 %g substitute the temporary-file-name-base. This is a string chosen
335 once per compilation. Different temporary file names are made by
336 concatenation of constant strings on the end, as in `%g.s'.
337 %g also has the same effect of %d.
338 %u like %g, but make the temporary file name unique.
339 %U returns the last file name generated with %u.
340 %d marks the argument containing or following the %d as a
341 temporary file name, so that that file will be deleted if CC exits
342 successfully. Unlike %g, this contributes no text to the argument.
343 %w marks the argument containing or following the %w as the
344 "output file" of this compilation. This puts the argument
345 into the sequence of arguments that %o will substitute later.
347 like %{...} but mark last argument supplied within
348 as a file to be deleted on failure.
349 %o substitutes the names of all the output files, with spaces
350 automatically placed around them. You should write spaces
351 around the %o as well or the results are undefined.
352 %o is for use in the specs for running the linker.
353 Input files whose names have no recognized suffix are not compiled
354 at all, but they are included among the output files, so they will
356 %O substitutes the suffix for object files.
357 %p substitutes the standard macro predefinitions for the
358 current target machine. Use this when running cpp.
359 %P like %p, but puts `__' before and after the name of each macro.
360 (Except macros that already have __.)
362 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
363 %s current argument is the name of a library or startup file of some sort.
364 Search for that file in a standard list of directories
365 and substitute the full name found.
366 %eSTR Print STR as an error message. STR is terminated by a newline.
367 Use this when inconsistent options are detected.
368 %x{OPTION} Accumulate an option for %X.
369 %X Output the accumulated linker options specified by compilations.
370 %Y Output the accumulated assembler options specified by compilations.
371 %Z Output the accumulated preprocessor options specified by compilations.
372 %v1 Substitute the major version number of GCC.
373 (For version 2.5.n, this is 2.)
374 %v2 Substitute the minor version number of GCC.
375 (For version 2.5.n, this is 5.)
376 %a process ASM_SPEC as a spec.
377 This allows config.h to specify part of the spec for running as.
378 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
379 used here. This can be used to run a post-processor after the
380 assembler has done it's job.
381 %D Dump out a -L option for each directory in startfile_prefixes.
382 If multilib_dir is set, extra entries are generated with it affixed.
383 %l process LINK_SPEC as a spec.
384 %L process LIB_SPEC as a spec.
385 %G process LIBGCC_SPEC as a spec.
386 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
387 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
388 %c process SIGNED_CHAR_SPEC as a spec.
389 %C process CPP_SPEC as a spec. A capital C is actually used here.
390 %1 process CC1_SPEC as a spec.
391 %2 process CC1PLUS_SPEC as a spec.
392 %| output "-" if the input for the current command is coming from a pipe.
393 %* substitute the variable part of a matched option. (See below.)
394 Note that each comma in the substituted string is replaced by
396 %{S} substitutes the -S switch, if that switch was given to CC.
397 If that switch was not specified, this substitutes nothing.
398 Here S is a metasyntactic variable.
399 %{S*} substitutes all the switches specified to CC whose names start
400 with -S. This is used for -o, -D, -I, etc; switches that take
401 arguments. CC considers `-o foo' as being one switch whose
402 name starts with `o'. %{o*} would substitute this text,
403 including the space; thus, two arguments would be generated.
404 %{S*:X} substitutes X if one or more switches whose names start with -S are
405 specified to CC. Note that the tail part of the -S option
406 (i.e. the part matched by the `*') will be substituted for each
407 occurrence of %* within X.
408 %{S:X} substitutes X, but only if the -S switch was given to CC.
409 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
410 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
411 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
412 %{.S:X} substitutes X, but only if processing a file with suffix S.
413 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
414 %(Spec) processes a specification defined in a specs file as *Spec:
415 %[Spec] as above, but put __ around -D arguments
417 The conditional text X in a %{S:X} or %{!S:X} construct may contain
418 other nested % constructs or spaces, or even newlines. They are
419 processed as usual, as described above.
421 The -O, -f, -m, and -W switches are handled specifically in these
422 constructs. If another value of -O or the negated form of a -f, -m, or
423 -W switch is found later in the command line, the earlier switch
424 value is ignored, except with {S*} where S is just one letter; this
425 passes all matching options.
427 The character | is used to indicate that a command should be piped to
428 the following command, but only if -pipe is specified.
430 Note that it is built into CC which switches take arguments and which
431 do not. You might think it would be useful to generalize this to
432 allow each compiler's spec to say which switches take arguments. But
433 this cannot be done in a consistent fashion. CC cannot even decide
434 which input files have been specified without knowing which switches
435 take arguments, and it must know which input files to compile in order
436 to tell which compilers to run.
438 CC also knows implicitly that arguments starting in `-l' are to be
439 treated as compiler output files, and passed to the linker in their
440 proper position among the other output files. */
442 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
444 /* config.h can define ASM_SPEC to provide extra args to the assembler
445 or extra switch-translations. */
450 /* config.h can define ASM_FINAL_SPEC to run a post processor after
451 the assembler has run. */
452 #ifndef ASM_FINAL_SPEC
453 #define ASM_FINAL_SPEC ""
456 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
457 or extra switch-translations. */
462 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
463 or extra switch-translations. */
468 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
469 or extra switch-translations. */
471 #define CC1PLUS_SPEC ""
474 /* config.h can define LINK_SPEC to provide extra args to the linker
475 or extra switch-translations. */
480 /* config.h can define LIB_SPEC to override the default libraries. */
482 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
485 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
488 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
489 /* Have gcc do the search for libgcc.a. */
490 #define LIBGCC_SPEC "%{!shared:libgcc.a%s}"
492 #define LIBGCC_SPEC "%{!shared:-lgcc}"
496 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
497 #ifndef STARTFILE_SPEC
498 #define STARTFILE_SPEC \
499 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
502 /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
503 Make the string nonempty to require spaces there. */
504 #ifndef SWITCHES_NEED_SPACES
505 #define SWITCHES_NEED_SPACES ""
508 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
510 #define ENDFILE_SPEC ""
513 /* This spec is used for telling cpp whether char is signed or not. */
514 #ifndef SIGNED_CHAR_SPEC
515 /* Use #if rather than ?:
516 because MIPS C compiler rejects like ?: in initializers. */
517 #if DEFAULT_SIGNED_CHAR
518 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
520 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
524 /* MULTILIB_SELECT comes from multilib.h. It gives a
525 string interpreted by set_multilib_dir to select a library
526 subdirectory based on the compiler options. */
527 #ifndef MULTILIB_SELECT
528 #define MULTILIB_SELECT ". ;"
531 static char *cpp_spec
= CPP_SPEC
;
532 static char *cpp_predefines
= CPP_PREDEFINES
;
533 static char *cc1_spec
= CC1_SPEC
;
534 static char *cc1plus_spec
= CC1PLUS_SPEC
;
535 static char *signed_char_spec
= SIGNED_CHAR_SPEC
;
536 static char *asm_spec
= ASM_SPEC
;
537 static char *asm_final_spec
= ASM_FINAL_SPEC
;
538 static char *link_spec
= LINK_SPEC
;
539 static char *lib_spec
= LIB_SPEC
;
540 static char *libgcc_spec
= LIBGCC_SPEC
;
541 static char *endfile_spec
= ENDFILE_SPEC
;
542 static char *startfile_spec
= STARTFILE_SPEC
;
543 static char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
544 static char *multilib_select
= MULTILIB_SELECT
;
546 /* This defines which switch letters take arguments. */
548 #ifndef SWITCH_TAKES_ARG
549 #define SWITCH_TAKES_ARG(CHAR) \
550 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
551 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
552 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
553 || (CHAR) == 'L' || (CHAR) == 'A')
556 /* This defines which multi-letter switches take arguments. */
558 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
559 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
560 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
561 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
562 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
563 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
564 || !strcmp (STR, "isystem"))
566 #ifndef WORD_SWITCH_TAKES_ARG
567 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
570 /* Record the mapping from file suffixes for compilation specs. */
574 char *suffix
; /* Use this compiler for input files
575 whose names end in this suffix. */
577 char *spec
[4]; /* To use this compiler, concatenate these
578 specs and pass to do_spec. */
581 /* Pointer to a vector of `struct compiler' that gives the spec for
582 compiling a file, based on its suffix.
583 A file that does not end in any of these suffixes will be passed
584 unchanged to the loader and nothing else will be done to it.
586 An entry containing two 0s is used to terminate the vector.
588 If multiple entries match a file, the last matching one is used. */
590 static struct compiler
*compilers
;
592 /* Number of entries in `compilers', not counting the null terminator. */
594 static int n_compilers
;
596 /* The default list of file name suffixes and their compilation specs. */
598 static struct compiler default_compilers
[] =
602 "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
603 %{C:%{!E:%eGNU C does not support -C without using -E}}\
604 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
605 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
606 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
607 %{!undef:%{!ansi:%p} %P} %{trigraphs} \
608 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
609 %{traditional-cpp:-traditional}\
610 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
611 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
612 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
613 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
614 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
615 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
617 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
618 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
620 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
621 %{!pipe:%g.s} %A\n }}}}"},
623 "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
624 %{C:%{!E:%eGNU C does not support -C without using -E}}\
625 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
626 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
627 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
628 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
629 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
630 %{traditional-cpp:-traditional}\
631 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
633 %{!E:%e-E required when input is from standard input}"},
634 {".m", "@objective-c"},
636 "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
637 %{C:%{!E:%eGNU C does not support -C without using -E}}\
638 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
639 -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
640 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
641 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
642 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
643 %{traditional-cpp:-traditional}\
644 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
645 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
646 "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
647 %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
648 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
649 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
650 -lang-objc %{gen-decls} \
652 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
653 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
655 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
656 %{!pipe:%g.s} %A\n }}}}"},
659 "%{!E:%eCompilation of header file requested} \
660 cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
661 %{C:%{!E:%eGNU C does not support -C without using -E}}\
662 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
663 -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
664 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
665 %{!undef:%{!ansi:%p} %P} %{trigraphs}\
666 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
667 %{traditional-cpp:-traditional}\
668 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
670 {".i", "@cpp-output"},
672 "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
673 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
674 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
676 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
677 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
679 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
680 %{!pipe:%g.s} %A\n }}}}"},
681 {".s", "@assembler"},
683 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
684 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
686 {".S", "@assembler-with-cpp"},
687 {"@assembler-with-cpp",
688 "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
689 %{C:%{!E:%eGNU C does not support -C without using -E}}\
690 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
691 -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
692 %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
693 %{traditional-cpp:-traditional}\
694 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
695 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
696 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\
697 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
698 %{!pipe:%g.s} %A\n }}}}"},
700 /* Mark end of table */
704 /* Number of elements in default_compilers, not counting the terminator. */
706 static int n_default_compilers
707 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
709 /* Here is the spec for running the linker, after compiling all files. */
711 /* -u* was put back because both BSD and SysV seem to support it. */
712 /* %{static:} simply prevents an error message if the target machine
713 doesn't handle -static. */
714 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
715 scripts which exist in user specified directories, or in standard
717 #ifdef LINK_LIBGCC_SPECIAL
718 /* Don't generate -L options. */
719 static char *link_command_spec
= "\
721 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
722 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
723 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
724 %{static:} %{L*} %{T*} %o\
725 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
726 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\n }}}}}}";
729 static char *link_command_spec
= "\
731 %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
732 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
733 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
734 %{static:} %{L*} %D %{T*} %o\
735 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
736 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\n }}}}}}";
739 /* A vector of options to give to the linker.
740 These options are accumulated by %x,
741 and substituted into the linker command with %X. */
742 static int n_linker_options
;
743 static char **linker_options
;
745 /* A vector of options to give to the assembler.
746 These options are accumulated by -Wa,
747 and substituted into the assembler command with %Y. */
748 static int n_assembler_options
;
749 static char **assembler_options
;
751 /* A vector of options to give to the preprocessor.
752 These options are accumulated by -Wp,
753 and substituted into the preprocessor command with %Z. */
754 static int n_preprocessor_options
;
755 static char **preprocessor_options
;
757 /* Define how to map long options into short ones. */
759 /* This structure describes one mapping. */
762 /* The long option's name. */
764 /* The equivalent short option. */
766 /* Argument info. A string of flag chars; NULL equals no options.
767 a => argument required.
768 o => argument optional.
769 j => join argument to equivalent, making one word.
770 * => require other text after NAME as an argument. */
774 /* This is the table of mappings. Mappings are tried sequentially
775 for each option encountered; the first one that matches, wins. */
777 struct option_map option_map
[] =
779 {"--all-warnings", "-Wall", 0},
780 {"--ansi", "-ansi", 0},
781 {"--assemble", "-S", 0},
782 {"--assert", "-A", "a"},
783 {"--comments", "-C", 0},
784 {"--compile", "-c", 0},
785 {"--debug", "-g", "oj"},
786 {"--define-macro", "-D", "a"},
787 {"--dependencies", "-M", 0},
788 {"--dump", "-d", "a"},
789 {"--dumpbase", "-dumpbase", "a"},
790 {"--entry", "-e", 0},
791 {"--extra-warnings", "-W", 0},
792 {"--for-assembler", "-Wa", "a"},
793 {"--for-linker", "-Xlinker", "a"},
794 {"--force-link", "-u", "a"},
795 {"--imacros", "-imacros", "a"},
796 {"--include", "-include", "a"},
797 {"--include-barrier", "-I-", 0},
798 {"--include-directory", "-I", "a"},
799 {"--include-directory-after", "-idirafter", "a"},
800 {"--include-prefix", "-iprefix", "a"},
801 {"--include-with-prefix", "-iwithprefix", "a"},
802 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
803 {"--include-with-prefix-after", "-iwithprefix", "a"},
804 {"--language", "-x", "a"},
805 {"--library-directory", "-L", "a"},
806 {"--machine", "-m", "aj"},
807 {"--machine-", "-m", "*j"},
808 {"--no-line-commands", "-P", 0},
809 {"--no-precompiled-includes", "-noprecomp", 0},
810 {"--no-standard-includes", "-nostdinc", 0},
811 {"--no-standard-libraries", "-nostdlib", 0},
812 {"--no-warnings", "-w", 0},
813 {"--optimize", "-O", "oj"},
814 {"--output", "-o", "a"},
815 {"--pedantic", "-pedantic", 0},
816 {"--pedantic-errors", "-pedantic-errors", 0},
817 {"--pipe", "-pipe", 0},
818 {"--prefix", "-B", "a"},
819 {"--preprocess", "-E", 0},
820 {"--print-search-dirs", "-print-search-dirs", 0},
821 {"--print-file-name", "-print-file-name=", "aj"},
822 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
823 {"--print-missing-file-dependencies", "-MG", 0},
824 {"--print-multi-lib", "-print-multi-lib", 0},
825 {"--print-multi-directory", "-print-multi-directory", 0},
826 {"--print-prog-name", "-print-prog-name=", "aj"},
827 {"--profile", "-p", 0},
828 {"--profile-blocks", "-a", 0},
829 {"--quiet", "-q", 0},
830 {"--save-temps", "-save-temps", 0},
831 {"--shared", "-shared", 0},
832 {"--silent", "-q", 0},
833 {"--static", "-static", 0},
834 {"--symbolic", "-symbolic", 0},
835 {"--target", "-b", "a"},
836 {"--trace-includes", "-H", 0},
837 {"--traditional", "-traditional", 0},
838 {"--traditional-cpp", "-traditional-cpp", 0},
839 {"--trigraphs", "-trigraphs", 0},
840 {"--undefine-macro", "-U", "a"},
841 {"--use-version", "-V", "a"},
842 {"--user-dependencies", "-MM", 0},
843 {"--verbose", "-v", 0},
844 {"--version", "-dumpversion", 0},
845 {"--warn-", "-W", "*j"},
846 {"--write-dependencies", "-MD", 0},
847 {"--write-user-dependencies", "-MMD", 0},
851 /* Translate the options described by *ARGCP and *ARGVP.
852 Make a new vector and store it back in *ARGVP,
853 and store its length in *ARGVC. */
856 translate_options (argcp
, argvp
)
862 char **argv
= *argvp
;
863 char **newv
= (char **) xmalloc ((argc
+ 2) * 2 * sizeof (char *));
867 newv
[newindex
++] = argv
[i
++];
871 /* Translate -- options. */
872 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
874 /* Find a mapping that applies to this option. */
875 for (j
= 0; j
< sizeof (option_map
) / sizeof (option_map
[0]); j
++)
877 int optlen
= strlen (option_map
[j
].name
);
878 int arglen
= strlen (argv
[i
]);
879 int complen
= arglen
> optlen
? optlen
: arglen
;
880 char *arginfo
= option_map
[j
].arg_info
;
885 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
892 k
< sizeof (option_map
) / sizeof (option_map
[0]);
894 if (strlen (option_map
[k
].name
) >= arglen
895 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
897 error ("Ambiguous abbreviation %s", argv
[i
]);
901 if (k
!= sizeof (option_map
) / sizeof (option_map
[0]))
907 /* If the option has an argument, accept that. */
908 if (argv
[i
][optlen
] == '=')
909 arg
= argv
[i
] + optlen
+ 1;
911 /* If this mapping requires extra text at end of name,
912 accept that as "argument". */
913 else if (index (arginfo
, '*') != 0)
914 arg
= argv
[i
] + optlen
;
916 /* Otherwise, extra text at end means mismatch.
917 Try other mappings. */
922 else if (index (arginfo
, '*') != 0)
924 error ("Incomplete `%s' option", option_map
[j
].name
);
928 /* Handle arguments. */
929 if (index (arginfo
, 'a') != 0)
935 error ("Missing argument to `%s' option",
943 else if (index (arginfo
, '*') != 0)
945 else if (index (arginfo
, 'o') == 0)
948 error ("Extraneous argument to `%s' option",
953 /* Store the translation as one argv elt or as two. */
954 if (arg
!= 0 && index (arginfo
, 'j') != 0)
955 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
);
958 newv
[newindex
++] = option_map
[j
].equivalent
;
959 newv
[newindex
++] = arg
;
962 newv
[newindex
++] = option_map
[j
].equivalent
;
970 /* Handle old-fashioned options--just copy them through,
971 with their arguments. */
972 else if (argv
[i
][0] == '-')
974 char *p
= argv
[i
] + 1;
978 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
979 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
980 else if (WORD_SWITCH_TAKES_ARG (p
))
981 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
982 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
985 else if (! strcmp (p
, "Xlinker"))
988 /* Watch out for an option at the end of the command line that
989 is missing arguments, and avoid skipping past the end of the
991 if (nskip
+ i
> argc
)
996 newv
[newindex
++] = argv
[i
++];
1001 /* Ordinary operands, or +e options. */
1002 newv
[newindex
++] = argv
[i
++];
1016 #ifdef HAVE_STRERROR
1021 static char buffer
[30];
1025 if (e
> 0 && e
< sys_nerr
)
1026 return sys_errlist
[e
];
1028 sprintf (buffer
, "Unknown error %d", e
);
1033 /* Read compilation specs from a file named FILENAME,
1034 replacing the default ones.
1036 A suffix which starts with `*' is a definition for
1037 one of the machine-specific sub-specs. The "suffix" should be
1038 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1039 The corresponding spec is stored in asm_spec, etc.,
1040 rather than in the `compilers' vector.
1042 Anything invalid in the file is a fatal error. */
1045 read_specs (filename
)
1050 struct stat statbuf
;
1055 fprintf (stderr
, "Reading specs from %s\n", filename
);
1057 /* Open and stat the file. */
1058 desc
= open (filename
, O_RDONLY
, 0);
1060 pfatal_with_name (filename
);
1061 if (stat (filename
, &statbuf
) < 0)
1062 pfatal_with_name (filename
);
1064 /* Read contents of file into BUFFER. */
1065 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1066 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1068 pfatal_with_name (filename
);
1069 buffer
[readlen
] = 0;
1072 /* Scan BUFFER for specs, putting them in the vector. */
1078 char *in
, *out
, *p1
, *p2
;
1080 /* Advance P in BUFFER to the next nonblank nocomment line. */
1081 p
= skip_whitespace (p
);
1085 /* Find the colon that should end the suffix. */
1087 while (*p1
&& *p1
!= ':' && *p1
!= '\n') p1
++;
1088 /* The colon shouldn't be missing. */
1090 fatal ("specs file malformed after %d characters", p1
- buffer
);
1091 /* Skip back over trailing whitespace. */
1093 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t')) p2
--;
1094 /* Copy the suffix to a string. */
1095 suffix
= save_string (p
, p2
- p
);
1096 /* Find the next line. */
1097 p
= skip_whitespace (p1
+ 1);
1099 fatal ("specs file malformed after %d characters", p
- buffer
);
1101 /* Find next blank line. */
1102 while (*p1
&& !(*p1
== '\n' && p1
[1] == '\n')) p1
++;
1103 /* Specs end at the blank line and do not include the newline. */
1104 spec
= save_string (p
, p1
- p
);
1107 /* Delete backslash-newline sequences from the spec. */
1112 if (in
[0] == '\\' && in
[1] == '\n')
1114 else if (in
[0] == '#')
1116 while (*in
&& *in
!= '\n') in
++;
1123 if (suffix
[0] == '*')
1125 if (! strcmp (suffix
, "*link_command"))
1126 link_command_spec
= spec
;
1128 set_spec (suffix
+ 1, spec
);
1132 /* Add this pair to the vector. */
1134 = ((struct compiler
*)
1135 xrealloc (compilers
, (n_compilers
+ 2) * sizeof (struct compiler
)));
1136 compilers
[n_compilers
].suffix
= suffix
;
1137 bzero ((char *) compilers
[n_compilers
].spec
,
1138 sizeof compilers
[n_compilers
].spec
);
1139 compilers
[n_compilers
].spec
[0] = spec
;
1141 bzero ((char *) &compilers
[n_compilers
],
1142 sizeof compilers
[n_compilers
]);
1146 link_command_spec
= spec
;
1149 if (link_command_spec
== 0)
1150 fatal ("spec file has no spec for linking");
1159 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1160 be considered whitespace. */
1161 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1163 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1167 while (*p
!= '\n') p
++;
1177 /* Structure to keep track of the specs that have been defined so far. These
1178 are accessed using %(specname) or %[specname] in a compiler or link spec. */
1182 char *name
; /* Name of the spec. */
1183 char *spec
; /* The spec itself. */
1184 struct spec_list
*next
; /* Next spec in linked list. */
1187 /* List of specs that have been defined so far. */
1189 static struct spec_list
*specs
= (struct spec_list
*) 0;
1191 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1192 removed; If the spec starts with a + then SPEC is added to the end of the
1196 set_spec (name
, spec
)
1200 struct spec_list
*sl
;
1203 /* See if the spec already exists */
1204 for (sl
= specs
; sl
; sl
= sl
->next
)
1205 if (strcmp (sl
->name
, name
) == 0)
1210 /* Not found - make it */
1211 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1212 sl
->name
= save_string (name
, strlen (name
));
1213 sl
->spec
= save_string ("", 0);
1218 old_spec
= sl
->spec
;
1219 if (name
&& spec
[0] == '+' && isspace (spec
[1]))
1220 sl
->spec
= concat (old_spec
, spec
+ 1);
1222 sl
->spec
= save_string (spec
, strlen (spec
));
1224 if (! strcmp (name
, "asm"))
1225 asm_spec
= sl
->spec
;
1226 else if (! strcmp (name
, "asm_final"))
1227 asm_final_spec
= sl
->spec
;
1228 else if (! strcmp (name
, "cc1"))
1229 cc1_spec
= sl
->spec
;
1230 else if (! strcmp (name
, "cc1plus"))
1231 cc1plus_spec
= sl
->spec
;
1232 else if (! strcmp (name
, "cpp"))
1233 cpp_spec
= sl
->spec
;
1234 else if (! strcmp (name
, "endfile"))
1235 endfile_spec
= sl
->spec
;
1236 else if (! strcmp (name
, "lib"))
1237 lib_spec
= sl
->spec
;
1238 else if (! strcmp (name
, "libgcc"))
1239 libgcc_spec
= sl
->spec
;
1240 else if (! strcmp (name
, "link"))
1241 link_spec
= sl
->spec
;
1242 else if (! strcmp (name
, "predefines"))
1243 cpp_predefines
= sl
->spec
;
1244 else if (! strcmp (name
, "signed_char"))
1245 signed_char_spec
= sl
->spec
;
1246 else if (! strcmp (name
, "startfile"))
1247 startfile_spec
= sl
->spec
;
1248 else if (! strcmp (name
, "switches_need_spaces"))
1249 switches_need_spaces
= sl
->spec
;
1250 else if (! strcmp (name
, "cross_compile"))
1251 cross_compile
= atoi (sl
->spec
);
1252 else if (! strcmp (name
, "multilib"))
1253 multilib_select
= sl
->spec
;
1254 /* Free the old spec */
1259 /* Accumulate a command (program name and args), and run it. */
1261 /* Vector of pointers to arguments in the current line of specifications. */
1263 static char **argbuf
;
1265 /* Number of elements allocated in argbuf. */
1267 static int argbuf_length
;
1269 /* Number of elements in argbuf currently in use (containing args). */
1271 static int argbuf_index
;
1273 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
1274 temp file. Used only if MKTEMP_EACH_FILE. */
1276 static struct temp_name
{
1277 char *suffix
; /* suffix associated with the code. */
1278 int length
; /* strlen (suffix). */
1279 int unique
; /* Indicates whether %g or %u/%U was used. */
1280 char *filename
; /* associated filename. */
1281 int filename_length
; /* strlen (filename). */
1282 struct temp_name
*next
;
1285 /* Number of commands executed so far. */
1287 static int execution_count
;
1289 /* Number of commands that exited with a signal. */
1291 static int signal_count
;
1293 /* Name with which this program was invoked. */
1295 static char *programname
;
1297 /* Structures to keep track of prefixes to try when looking for files. */
1301 char *prefix
; /* String to prepend to the path. */
1302 struct prefix_list
*next
; /* Next in linked list. */
1303 int require_machine_suffix
; /* Don't use without machine_suffix. */
1304 /* 2 means try both machine_suffix and just_machine_suffix. */
1305 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1310 struct prefix_list
*plist
; /* List of prefixes to try */
1311 int max_len
; /* Max length of a prefix in PLIST */
1312 char *name
; /* Name of this list (used in config stuff) */
1315 /* List of prefixes to try when looking for executables. */
1317 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1319 /* List of prefixes to try when looking for startup (crt0) files. */
1321 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1323 /* List of prefixes to try when looking for include files. */
1325 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1327 /* Suffix to attach to directories searched for commands.
1328 This looks like `MACHINE/VERSION/'. */
1330 static char *machine_suffix
= 0;
1332 /* Suffix to attach to directories searched for commands.
1333 This is just `MACHINE/'. */
1335 static char *just_machine_suffix
= 0;
1337 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1339 static char *gcc_exec_prefix
;
1341 /* Default prefixes to attach to command names. */
1343 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1344 #undef MD_EXEC_PREFIX
1345 #undef MD_STARTFILE_PREFIX
1346 #undef MD_STARTFILE_PREFIX_1
1349 #ifndef STANDARD_EXEC_PREFIX
1350 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1351 #endif /* !defined STANDARD_EXEC_PREFIX */
1353 static char *standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1354 static char *standard_exec_prefix_1
= "/usr/lib/gcc/";
1355 #ifdef MD_EXEC_PREFIX
1356 static char *md_exec_prefix
= MD_EXEC_PREFIX
;
1359 #ifndef STANDARD_STARTFILE_PREFIX
1360 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1361 #endif /* !defined STANDARD_STARTFILE_PREFIX */
1363 #ifdef MD_STARTFILE_PREFIX
1364 static char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1366 #ifdef MD_STARTFILE_PREFIX_1
1367 static char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1369 static char *standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1370 static char *standard_startfile_prefix_1
= "/lib/";
1371 static char *standard_startfile_prefix_2
= "/usr/lib/";
1373 #ifndef TOOLDIR_BASE_PREFIX
1374 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1376 static char *tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1377 static char *tooldir_prefix
;
1379 /* Subdirectory to use for locating libraries. Set by
1380 set_multilib_dir based on the compilation options. */
1382 static char *multilib_dir
;
1384 /* Clear out the vector of arguments (after a command is executed). */
1392 /* Add one argument to the vector at the end.
1393 This is done when a space is seen or at the end of the line.
1394 If DELETE_ALWAYS is nonzero, the arg is a filename
1395 and the file should be deleted eventually.
1396 If DELETE_FAILURE is nonzero, the arg is a filename
1397 and the file should be deleted if this compilation fails. */
1400 store_arg (arg
, delete_always
, delete_failure
)
1402 int delete_always
, delete_failure
;
1404 if (argbuf_index
+ 1 == argbuf_length
)
1406 argbuf
= (char **) xrealloc (argbuf
, (argbuf_length
*= 2) * sizeof (char *));
1409 argbuf
[argbuf_index
++] = arg
;
1410 argbuf
[argbuf_index
] = 0;
1412 if (delete_always
|| delete_failure
)
1413 record_temp_file (arg
, delete_always
, delete_failure
);
1416 /* Record the names of temporary files we tell compilers to write,
1417 and delete them at the end of the run. */
1419 /* This is the common prefix we use to make temp file names.
1420 It is chosen once for each run of this program.
1421 It is substituted into a spec by %g.
1422 Thus, all temp file names contain this prefix.
1423 In practice, all temp file names start with this prefix.
1425 This prefix comes from the envvar TMPDIR if it is defined;
1426 otherwise, from the P_tmpdir macro if that is defined;
1427 otherwise, in /usr/tmp or /tmp. */
1429 static char *temp_filename
;
1431 /* Length of the prefix. */
1433 static int temp_filename_length
;
1435 /* Define the list of temporary files to delete. */
1440 struct temp_file
*next
;
1443 /* Queue of files to delete on success or failure of compilation. */
1444 static struct temp_file
*always_delete_queue
;
1445 /* Queue of files to delete on failure of compilation. */
1446 static struct temp_file
*failure_delete_queue
;
1448 /* Record FILENAME as a file to be deleted automatically.
1449 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
1450 otherwise delete it in any case.
1451 FAIL_DELETE nonzero means delete it if a compilation step fails;
1452 otherwise delete it in any case. */
1455 record_temp_file (filename
, always_delete
, fail_delete
)
1460 register char *name
;
1461 name
= xmalloc (strlen (filename
) + 1);
1462 strcpy (name
, filename
);
1466 register struct temp_file
*temp
;
1467 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1468 if (! strcmp (name
, temp
->name
))
1470 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1471 temp
->next
= always_delete_queue
;
1473 always_delete_queue
= temp
;
1479 register struct temp_file
*temp
;
1480 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1481 if (! strcmp (name
, temp
->name
))
1483 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
1484 temp
->next
= failure_delete_queue
;
1486 failure_delete_queue
= temp
;
1491 /* Delete all the temporary files whose names we previously recorded. */
1494 delete_if_ordinary (name
)
1501 printf ("Delete %s? (y or n) ", name
);
1505 while ((c
= getchar ()) != '\n' && c
!= EOF
) ;
1506 if (i
== 'y' || i
== 'Y')
1508 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
1509 if (unlink (name
) < 0)
1511 perror_with_name (name
);
1515 delete_temp_files ()
1517 register struct temp_file
*temp
;
1519 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
1520 delete_if_ordinary (temp
->name
);
1521 always_delete_queue
= 0;
1524 /* Delete all the files to be deleted on error. */
1527 delete_failure_queue ()
1529 register struct temp_file
*temp
;
1531 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
1532 delete_if_ordinary (temp
->name
);
1536 clear_failure_queue ()
1538 failure_delete_queue
= 0;
1541 /* Compute a string to use as the base of all temporary file names.
1542 It is substituted for %g. */
1545 choose_temp_base_try (try, base
)
1552 else if (try == (char *)0)
1554 else if (access (try, R_OK
| W_OK
) != 0)
1567 base
= choose_temp_base_try (getenv ("TMPDIR"), base
);
1568 base
= choose_temp_base_try (getenv ("TMP"), base
);
1569 base
= choose_temp_base_try (getenv ("TEMP"), base
);
1572 base
= choose_temp_base_try (P_tmpdir
, base
);
1575 base
= choose_temp_base_try (concat4 (dir_separator_str
, "usr",
1576 dir_separator_str
, "tmp"),
1578 base
= choose_temp_base_try (concat (dir_separator_str
, "tmp"), base
);
1580 /* If all else fails, use the current directory! */
1581 if (base
== (char *)0) base
= concat(".", dir_separator_str
);
1583 len
= strlen (base
);
1584 temp_filename
= xmalloc (len
+ strlen (concat (dir_separator_str
,
1586 strcpy (temp_filename
, base
);
1587 if (len
> 0 && temp_filename
[len
-1] != '/'
1588 && temp_filename
[len
-1] != DIR_SEPARATOR
)
1589 temp_filename
[len
++] = DIR_SEPARATOR
;
1590 strcpy (temp_filename
+ len
, "ccXXXXXX");
1592 mktemp (temp_filename
);
1593 temp_filename_length
= strlen (temp_filename
);
1594 if (temp_filename_length
== 0)
1599 /* Routine to add variables to the environment. We do this to pass
1600 the pathname of the gcc driver, and the directories search to the
1601 collect2 program, which is being run as ld. This way, we can be
1602 sure of executing the right compiler when collect2 wants to build
1603 constructors and destructors. Since the environment variables we
1604 use come from an obstack, we don't have to worry about allocating
1613 #ifndef VMS /* nor about VMS */
1615 extern char **environ
;
1616 char **old_environ
= environ
;
1620 int str_len
= strlen (str
);
1624 while ((ch
= *p
++) != '\0' && ch
!= '=')
1630 /* Search for replacing an existing environment variable, and
1631 count the number of total environment variables. */
1632 for (envp
= old_environ
; *envp
; envp
++)
1635 if (!strncmp (str
, *envp
, name_len
))
1642 /* Add a new environment variable */
1643 environ
= (char **) xmalloc (sizeof (char *) * (num_envs
+2));
1645 bcopy ((char *) old_environ
, (char *) (environ
+ 1),
1646 sizeof (char *) * (num_envs
+1));
1651 #endif /* HAVE_PUTENV */
1654 /* Build a list of search directories from PATHS.
1655 PREFIX is a string to prepend to the list.
1656 If CHECK_DIR_P is non-zero we ensure the directory exists.
1657 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
1658 It is also used by the --print-search-dirs flag. */
1661 build_search_list (paths
, prefix
, check_dir_p
)
1662 struct path_prefix
*paths
;
1666 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
1668 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
1669 int first_time
= TRUE
;
1670 struct prefix_list
*pprefix
;
1672 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
1674 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
1676 int len
= strlen (pprefix
->prefix
);
1680 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
1683 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1686 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1687 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
1690 if (just_machine_suffix
1691 && pprefix
->require_machine_suffix
== 2
1693 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
1696 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1699 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1700 obstack_grow (&collect_obstack
, just_machine_suffix
,
1704 if (!pprefix
->require_machine_suffix
)
1707 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
1710 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
1713 obstack_1grow (&collect_obstack
, '\0');
1714 return obstack_finish (&collect_obstack
);
1717 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */
1720 putenv_from_prefixes (paths
, env_var
)
1721 struct path_prefix
*paths
;
1724 putenv (build_search_list (paths
, env_var
, 1));
1727 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
1728 access to check permissions.
1729 Return 0 if not found, otherwise return its name, allocated with malloc. */
1732 find_a_file (pprefix
, name
, mode
)
1733 struct path_prefix
*pprefix
;
1738 char *file_suffix
= ((mode
& X_OK
) != 0 ? EXECUTABLE_SUFFIX
: "");
1739 struct prefix_list
*pl
;
1740 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
1743 len
+= strlen (machine_suffix
);
1745 temp
= xmalloc (len
);
1747 /* Determine the filename to execute (special case for absolute paths). */
1749 if (*name
== '/' || *name
== DIR_SEPARATOR
)
1751 if (access (name
, mode
))
1753 strcpy (temp
, name
);
1758 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
1762 /* Some systems have a suffix for executable files.
1763 So try appending that first. */
1764 if (file_suffix
[0] != 0)
1766 strcpy (temp
, pl
->prefix
);
1767 strcat (temp
, machine_suffix
);
1768 strcat (temp
, name
);
1769 strcat (temp
, file_suffix
);
1770 if (access (temp
, mode
) == 0)
1772 if (pl
->used_flag_ptr
!= 0)
1773 *pl
->used_flag_ptr
= 1;
1778 /* Now try just the name. */
1779 strcpy (temp
, pl
->prefix
);
1780 strcat (temp
, machine_suffix
);
1781 strcat (temp
, name
);
1782 if (access (temp
, mode
) == 0)
1784 if (pl
->used_flag_ptr
!= 0)
1785 *pl
->used_flag_ptr
= 1;
1790 /* Certain prefixes are tried with just the machine type,
1791 not the version. This is used for finding as, ld, etc. */
1792 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
1794 /* Some systems have a suffix for executable files.
1795 So try appending that first. */
1796 if (file_suffix
[0] != 0)
1798 strcpy (temp
, pl
->prefix
);
1799 strcat (temp
, just_machine_suffix
);
1800 strcat (temp
, name
);
1801 strcat (temp
, file_suffix
);
1802 if (access (temp
, mode
) == 0)
1804 if (pl
->used_flag_ptr
!= 0)
1805 *pl
->used_flag_ptr
= 1;
1810 strcpy (temp
, pl
->prefix
);
1811 strcat (temp
, just_machine_suffix
);
1812 strcat (temp
, name
);
1813 if (access (temp
, mode
) == 0)
1815 if (pl
->used_flag_ptr
!= 0)
1816 *pl
->used_flag_ptr
= 1;
1821 /* Certain prefixes can't be used without the machine suffix
1822 when the machine or version is explicitly specified. */
1823 if (!pl
->require_machine_suffix
)
1825 /* Some systems have a suffix for executable files.
1826 So try appending that first. */
1827 if (file_suffix
[0] != 0)
1829 strcpy (temp
, pl
->prefix
);
1830 strcat (temp
, name
);
1831 strcat (temp
, file_suffix
);
1832 if (access (temp
, mode
) == 0)
1834 if (pl
->used_flag_ptr
!= 0)
1835 *pl
->used_flag_ptr
= 1;
1840 strcpy (temp
, pl
->prefix
);
1841 strcat (temp
, name
);
1842 if (access (temp
, mode
) == 0)
1844 if (pl
->used_flag_ptr
!= 0)
1845 *pl
->used_flag_ptr
= 1;
1855 /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes
1856 at the start of the list, otherwise it goes at the end.
1858 If WARN is nonzero, we will warn if no file is found
1859 through this prefix. WARN should point to an int
1860 which will be set to 1 if this entry is used.
1862 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
1863 the complete value of machine_suffix.
1864 2 means try both machine_suffix and just_machine_suffix. */
1867 add_prefix (pprefix
, prefix
, first
, require_machine_suffix
, warn
)
1868 struct path_prefix
*pprefix
;
1871 int require_machine_suffix
;
1874 struct prefix_list
*pl
, **prev
;
1877 if (!first
&& pprefix
->plist
)
1879 for (pl
= pprefix
->plist
; pl
->next
; pl
= pl
->next
)
1884 prev
= &pprefix
->plist
;
1886 /* Keep track of the longest prefix */
1888 len
= strlen (prefix
);
1889 if (len
> pprefix
->max_len
)
1890 pprefix
->max_len
= len
;
1892 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
1893 pl
->prefix
= save_string (prefix
, len
);
1894 pl
->require_machine_suffix
= require_machine_suffix
;
1895 pl
->used_flag_ptr
= warn
;
1902 pl
->next
= (struct prefix_list
*) 0;
1906 /* Print warnings for any prefixes in the list PPREFIX that were not used. */
1909 unused_prefix_warnings (pprefix
)
1910 struct path_prefix
*pprefix
;
1912 struct prefix_list
*pl
= pprefix
->plist
;
1916 if (pl
->used_flag_ptr
!= 0 && !*pl
->used_flag_ptr
)
1918 error ("file path prefix `%s' never used",
1920 /* Prevent duplicate warnings. */
1921 *pl
->used_flag_ptr
= 1;
1927 /* Get rid of all prefixes built up so far in *PLISTP. */
1930 free_path_prefix (pprefix
)
1931 struct path_prefix
*pprefix
;
1933 struct prefix_list
*pl
= pprefix
->plist
;
1934 struct prefix_list
*temp
;
1940 free (temp
->prefix
);
1941 free ((char *) temp
);
1943 pprefix
->plist
= (struct prefix_list
*) 0;
1946 /* stdin file number. */
1947 #define STDIN_FILE_NO 0
1949 /* stdout file number. */
1950 #define STDOUT_FILE_NO 1
1952 /* value of `pipe': port index for reading. */
1955 /* value of `pipe': port index for writing. */
1956 #define WRITE_PORT 1
1958 /* Pipe waiting from last process, to be used as input for the next one.
1959 Value is STDIN_FILE_NO if no pipe is waiting
1960 (i.e. the next command is the first of a group). */
1962 static int last_pipe_input
;
1964 /* Fork one piped subcommand. FUNC is the system call to use
1965 (either execv or execvp). ARGV is the arg vector to use.
1966 NOT_LAST is nonzero if this is not the last subcommand
1967 (i.e. its output should be piped to the next one.) */
1971 #include <process.h>
1973 pexecute (search_flag
, program
, argv
, not_last
)
1980 int i
= (search_flag
? spawnv
: spawnvp
) (1, program
, argv
);
1984 int i
, el
= search_flag
? 0 : 4;
1986 scmd
= (char *)malloc (strlen (program
) + strlen (temp_filename
) + 6 + el
);
1987 rf
= scmd
+ strlen(program
) + 2 + el
;
1988 sprintf (scmd
, "%s%s @%s.gp", program
,
1989 (search_flag
? "" : ".exe"), temp_filename
);
1990 argfile
= fopen (rf
, "w");
1992 pfatal_with_name (rf
);
1994 for (i
=1; argv
[i
]; i
++)
1997 for (cp
= argv
[i
]; *cp
; cp
++)
1999 if (*cp
== '"' || *cp
== '\'' || *cp
== '\\' || isspace (*cp
))
2000 fputc ('\\', argfile
);
2001 fputc (*cp
, argfile
);
2003 fputc ('\n', argfile
);
2014 perror_exec (program
);
2015 return MIN_FATAL_STATUS
<< 8;
2022 #if !defined(__MSDOS__) && !defined(OS2) && !defined(_WIN32)
2025 pexecute (search_flag
, program
, argv
, not_last
)
2031 int (*func
)() = (search_flag
? execv
: execvp
);
2034 int input_desc
= last_pipe_input
;
2035 int output_desc
= STDOUT_FILE_NO
;
2036 int retries
, sleep_interval
;
2038 /* If this isn't the last process, make a pipe for its output,
2039 and record it as waiting to be the input to the next process. */
2043 if (pipe (pdes
) < 0)
2044 pfatal_with_name ("pipe");
2045 output_desc
= pdes
[WRITE_PORT
];
2046 last_pipe_input
= pdes
[READ_PORT
];
2049 last_pipe_input
= STDIN_FILE_NO
;
2051 /* Fork a subprocess; wait and retry if it fails. */
2053 for (retries
= 0; retries
< 4; retries
++)
2058 sleep (sleep_interval
);
2059 sleep_interval
*= 2;
2066 pfatal_with_name ("fork");
2068 pfatal_with_name ("vfork");
2074 /* Move the input and output pipes into place, if nec. */
2075 if (input_desc
!= STDIN_FILE_NO
)
2077 close (STDIN_FILE_NO
);
2081 if (output_desc
!= STDOUT_FILE_NO
)
2083 close (STDOUT_FILE_NO
);
2085 close (output_desc
);
2088 /* Close the parent's descs that aren't wanted here. */
2089 if (last_pipe_input
!= STDIN_FILE_NO
)
2090 close (last_pipe_input
);
2092 /* Exec the program. */
2093 (*func
) (program
, argv
);
2094 perror_exec (program
);
2100 /* In the parent, after forking.
2101 Close the descriptors that we made for this child. */
2102 if (input_desc
!= STDIN_FILE_NO
)
2104 if (output_desc
!= STDOUT_FILE_NO
)
2105 close (output_desc
);
2107 /* Return child's process number. */
2112 #endif /* not __MSDOS__ and not OS2 and not _WIN32 */
2114 #if defined(OS2) || defined(_WIN32)
2118 /* This is a kludge to get around the Microsoft C spawn functions' propensity
2119 to remove the outermost set of double quotes from all arguments. */
2127 for (i
= 1; argvec
[i
] != 0; i
++)
2130 char *temp
, *newtemp
;
2133 len
= strlen (temp
);
2134 for (j
= 0; j
< len
; j
++)
2138 newtemp
= xmalloc (len
+ 2);
2139 strncpy (newtemp
, temp
, j
);
2141 strncpy (&newtemp
[j
+1], &temp
[j
], len
-j
);
2142 newtemp
[len
+1] = 0;
2152 return (const char* const*) argvec
;
2155 #define FIX_ARGV(a) fix_argv(a)
2159 #define FIX_ARGV(a) a
2164 pexecute (search_flag
, program
, argv
, not_last
)
2170 return (search_flag
? spawnv
: spawnvp
) (1, program
, FIX_ARGV (argv
));
2172 #endif /* OS2 or _WIN32 */
2175 /* Execute the command specified by the arguments on the current line of spec.
2176 When using pipes, this includes several piped-together commands
2177 with `|' between them.
2179 Return 0 if successful, -1 if failed. */
2185 int n_commands
; /* # of command. */
2189 char *prog
; /* program name. */
2190 char **argv
; /* vector of args. */
2191 int pid
; /* pid of process for this command. */
2194 struct command
*commands
; /* each command buffer with above info. */
2196 /* Count # of piped commands. */
2197 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2198 if (strcmp (argbuf
[i
], "|") == 0)
2201 /* Get storage for each command. */
2203 = (struct command
*) alloca (n_commands
* sizeof (struct command
));
2205 /* Split argbuf into its separate piped processes,
2206 and record info about each one.
2207 Also search for the programs that are to be run. */
2209 commands
[0].prog
= argbuf
[0]; /* first command. */
2210 commands
[0].argv
= &argbuf
[0];
2211 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2213 commands
[0].argv
[0] = string
;
2215 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2216 if (strcmp (argbuf
[i
], "|") == 0)
2217 { /* each command. */
2219 fatal ("-pipe not supported under MS-DOS");
2221 argbuf
[i
] = 0; /* termination of command args. */
2222 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2223 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2224 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2226 commands
[n_commands
].argv
[0] = string
;
2230 argbuf
[argbuf_index
] = 0;
2232 /* If -v, print what we are about to do, and maybe query. */
2236 /* Print each piped command as a separate line. */
2237 for (i
= 0; i
< n_commands
; i
++)
2241 for (j
= commands
[i
].argv
; *j
; j
++)
2242 fprintf (stderr
, " %s", *j
);
2244 /* Print a pipe symbol after all but the last command. */
2245 if (i
+ 1 != n_commands
)
2246 fprintf (stderr
, " |");
2247 fprintf (stderr
, "\n");
2251 fprintf (stderr
, "\nGo ahead? (y or n) ");
2255 while (getchar () != '\n') ;
2256 if (i
!= 'y' && i
!= 'Y')
2261 /* Run each piped subprocess. */
2263 last_pipe_input
= STDIN_FILE_NO
;
2264 for (i
= 0; i
< n_commands
; i
++)
2266 char *string
= commands
[i
].argv
[0];
2268 commands
[i
].pid
= pexecute (string
!= commands
[i
].prog
,
2269 string
, commands
[i
].argv
,
2270 i
+ 1 < n_commands
);
2272 if (string
!= commands
[i
].prog
)
2278 /* Wait for all the subprocesses to finish.
2279 We don't care what order they finish in;
2280 we know that N_COMMANDS waits will get them all.
2281 Ignore subprocesses that we don't know about,
2282 since they can be spawned by the process that exec'ed us. */
2287 for (i
= 0; i
< n_commands
; )
2294 status
= pid
= commands
[i
].pid
;
2297 pid
= cwait (&status
, commands
[i
].pid
, WAIT_CHILD
);
2299 pid
= wait (&status
);
2305 for (j
= 0; j
< n_commands
; j
++)
2306 if (commands
[j
].pid
== pid
)
2311 if (WIFSIGNALED (status
))
2313 fatal ("Internal compiler error: program %s got fatal signal %d",
2314 commands
[j
].prog
, WTERMSIG (status
));
2318 else if (WIFEXITED (status
)
2319 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2329 /* Find all the switches given to us
2330 and make a vector describing them.
2331 The elements of the vector are strings, one per switch given.
2332 If a switch uses following arguments, then the `part1' field
2333 is the switch itself and the `args' field
2334 is a null-terminated vector containing the following arguments.
2335 The `live_cond' field is 1 if the switch is true in a conditional spec,
2336 -1 if false (overridden by a later switch), and is initialized to zero.
2337 The `valid' field is nonzero if any spec has looked at this switch;
2338 if it remains zero at the end of the run, it must be meaningless. */
2348 static struct switchstr
*switches
;
2350 static int n_switches
;
2358 /* Also a vector of input files specified. */
2360 static struct infile
*infiles
;
2362 static int n_infiles
;
2364 /* And a vector of corresponding output files is made up later. */
2366 static char **outfiles
;
2368 /* Create the vector `switches' and its contents.
2369 Store its length in `n_switches'. */
2372 process_command (argc
, argv
)
2378 char *spec_lang
= 0;
2379 int last_language_n_infiles
;
2381 gcc_exec_prefix
= getenv ("GCC_EXEC_PREFIX");
2386 /* Figure compiler version from version string. */
2388 compiler_version
= save_string (version_string
, strlen (version_string
));
2389 for (temp
= compiler_version
; *temp
; ++temp
)
2398 /* Set up the default search paths. */
2400 if (gcc_exec_prefix
)
2402 add_prefix (&exec_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2403 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, 0, 0, NULL_PTR
);
2406 /* COMPILER_PATH and LIBRARY_PATH have values
2407 that are lists of directory names with colons. */
2409 temp
= getenv ("COMPILER_PATH");
2412 char *startp
, *endp
;
2413 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2415 startp
= endp
= temp
;
2418 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2420 strncpy (nstore
, startp
, endp
-startp
);
2422 strcpy (nstore
, concat (".", dir_separator_str
));
2423 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2425 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2426 nstore
[endp
-startp
+1] = 0;
2429 nstore
[endp
-startp
] = 0;
2430 add_prefix (&exec_prefixes
, nstore
, 0, 0, NULL_PTR
);
2433 endp
= startp
= endp
+ 1;
2440 temp
= getenv ("LIBRARY_PATH");
2441 if (temp
&& ! cross_compile
)
2443 char *startp
, *endp
;
2444 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2446 startp
= endp
= temp
;
2449 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2451 strncpy (nstore
, startp
, endp
-startp
);
2453 strcpy (nstore
, concat (".", dir_separator_str
));
2454 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2456 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2457 nstore
[endp
-startp
+1] = 0;
2460 nstore
[endp
-startp
] = 0;
2461 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2464 endp
= startp
= endp
+ 1;
2471 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
2472 temp
= getenv ("LPATH");
2473 if (temp
&& ! cross_compile
)
2475 char *startp
, *endp
;
2476 char *nstore
= (char *) alloca (strlen (temp
) + 3);
2478 startp
= endp
= temp
;
2481 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2483 strncpy (nstore
, startp
, endp
-startp
);
2485 strcpy (nstore
, concat (".", dir_separator_str
));
2486 else if (endp
[-1] != '/' && endp
[-1] != DIR_SEPARATOR
)
2488 nstore
[endp
-startp
] = DIR_SEPARATOR
;
2489 nstore
[endp
-startp
+1] = 0;
2492 nstore
[endp
-startp
] = 0;
2493 add_prefix (&startfile_prefixes
, nstore
, 0, 0, NULL_PTR
);
2496 endp
= startp
= endp
+ 1;
2503 /* Convert new-style -- options to old-style. */
2504 translate_options (&argc
, &argv
);
2506 /* Scan argv twice. Here, the first time, just count how many switches
2507 there will be in their vector, and how many input files in theirs.
2508 Here we also parse the switches that cc itself uses (e.g. -v). */
2510 for (i
= 1; i
< argc
; i
++)
2512 if (! strcmp (argv
[i
], "-dumpspecs"))
2514 printf ("*asm:\n%s\n\n", asm_spec
);
2515 printf ("*asm_final:\n%s\n\n", asm_final_spec
);
2516 printf ("*cpp:\n%s\n\n", cpp_spec
);
2517 printf ("*cc1:\n%s\n\n", cc1_spec
);
2518 printf ("*cc1plus:\n%s\n\n", cc1plus_spec
);
2519 printf ("*endfile:\n%s\n\n", endfile_spec
);
2520 printf ("*link:\n%s\n\n", link_spec
);
2521 printf ("*lib:\n%s\n\n", lib_spec
);
2522 printf ("*libgcc:\n%s\n\n", libgcc_spec
);
2523 printf ("*startfile:\n%s\n\n", startfile_spec
);
2524 printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces
);
2525 printf ("*signed_char:\n%s\n\n", signed_char_spec
);
2526 printf ("*predefines:\n%s\n\n", cpp_predefines
);
2527 printf ("*cross_compile:\n%d\n\n", cross_compile
);
2528 printf ("*multilib:\n%s\n\n", multilib_select
);
2532 else if (! strcmp (argv
[i
], "-dumpversion"))
2534 printf ("%s\n", version_string
);
2537 else if (! strcmp (argv
[i
], "-dumpmachine"))
2539 printf ("%s\n", spec_machine
);
2542 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2543 print_search_dirs
= 1;
2544 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2545 print_file_name
= "libgcc.a";
2546 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2547 print_file_name
= argv
[i
] + 17;
2548 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2549 print_prog_name
= argv
[i
] + 17;
2550 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2551 print_multi_lib
= 1;
2552 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2553 print_multi_directory
= 1;
2554 else if (! strncmp (argv
[i
], "-Wa,", 4))
2557 /* Pass the rest of this option to the assembler. */
2559 n_assembler_options
++;
2560 if (!assembler_options
)
2562 = (char **) xmalloc (n_assembler_options
* sizeof (char **));
2565 = (char **) xrealloc (assembler_options
,
2566 n_assembler_options
* sizeof (char **));
2568 /* Split the argument at commas. */
2570 for (j
= 4; argv
[i
][j
]; j
++)
2571 if (argv
[i
][j
] == ',')
2573 assembler_options
[n_assembler_options
- 1]
2574 = save_string (argv
[i
] + prev
, j
- prev
);
2575 n_assembler_options
++;
2577 = (char **) xrealloc (assembler_options
,
2578 n_assembler_options
* sizeof (char **));
2581 /* Record the part after the last comma. */
2582 assembler_options
[n_assembler_options
- 1] = argv
[i
] + prev
;
2584 else if (! strncmp (argv
[i
], "-Wp,", 4))
2587 /* Pass the rest of this option to the preprocessor. */
2589 n_preprocessor_options
++;
2590 if (!preprocessor_options
)
2591 preprocessor_options
2592 = (char **) xmalloc (n_preprocessor_options
* sizeof (char **));
2594 preprocessor_options
2595 = (char **) xrealloc (preprocessor_options
,
2596 n_preprocessor_options
* sizeof (char **));
2598 /* Split the argument at commas. */
2600 for (j
= 4; argv
[i
][j
]; j
++)
2601 if (argv
[i
][j
] == ',')
2603 preprocessor_options
[n_preprocessor_options
- 1]
2604 = save_string (argv
[i
] + prev
, j
- prev
);
2605 n_preprocessor_options
++;
2606 preprocessor_options
2607 = (char **) xrealloc (preprocessor_options
,
2608 n_preprocessor_options
* sizeof (char **));
2611 /* Record the part after the last comma. */
2612 preprocessor_options
[n_preprocessor_options
- 1] = argv
[i
] + prev
;
2614 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2615 /* The +e options to the C++ front-end. */
2617 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2620 /* Split the argument at commas. */
2621 for (j
= 3; argv
[i
][j
]; j
++)
2622 n_infiles
+= (argv
[i
][j
] == ',');
2624 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2627 fatal ("argument to `-Xlinker' is missing");
2632 else if (strncmp (argv
[i
], "-l", 2) == 0)
2634 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2636 register char *p
= &argv
[i
][1];
2637 register int c
= *p
;
2642 if (p
[1] == 0 && i
+ 1 == argc
)
2643 fatal ("argument to `-b' is missing");
2645 spec_machine
= argv
[++i
];
2647 spec_machine
= p
+ 1;
2652 int *temp
= (int *) xmalloc (sizeof (int));
2654 if (p
[1] == 0 && i
+ 1 == argc
)
2655 fatal ("argument to `-B' is missing");
2660 add_prefix (&exec_prefixes
, value
, 1, 0, temp
);
2661 add_prefix (&startfile_prefixes
, value
, 1, 0, temp
);
2662 add_prefix (&include_prefixes
, concat (value
, "include"),
2665 /* As a kludge, if the arg is "[foo/]stageN/", just add
2666 "[foo/]include" to the include prefix. */
2668 int len
= strlen (value
);
2671 && (value
[len
- 8] == '/'
2672 || value
[len
- 8] == DIR_SEPARATOR
)))
2673 && strncmp (value
+ len
- 7, "stage", 5) == 0
2674 && isdigit (value
[len
- 2])
2675 && (value
[len
- 1] == '/'
2676 || value
[len
- 1] == DIR_SEPARATOR
))
2679 add_prefix (&include_prefixes
, "include", 1, 0, 0);
2682 char *string
= xmalloc (len
+ 1);
2683 strncpy (string
, value
, len
-7);
2684 strcat (string
, "include");
2685 add_prefix (&include_prefixes
, string
, 1, 0, 0);
2692 case 'v': /* Print our subcommands and print versions. */
2694 /* If they do anything other than exactly `-v', don't set
2695 verbose_flag; rather, continue on to give the error. */
2702 if (p
[1] == 0 && i
+ 1 == argc
)
2703 fatal ("argument to `-V' is missing");
2705 spec_version
= argv
[++i
];
2707 spec_version
= p
+ 1;
2708 compiler_version
= spec_version
;
2712 if (!strcmp (p
, "save-temps"))
2714 save_temps_flag
= 1;
2721 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2722 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2723 else if (WORD_SWITCH_TAKES_ARG (p
))
2724 i
+= WORD_SWITCH_TAKES_ARG (p
);
2731 /* Set up the search paths before we go looking for config files. */
2733 /* These come before the md prefixes so that we will find gcc's subcommands
2734 (such as cpp) rather than those of the host system. */
2735 /* Use 2 as fourth arg meaning try just the machine as a suffix,
2736 as well as trying the machine and the version. */
2738 add_prefix (&exec_prefixes
, standard_exec_prefix
, 0, 2, NULL_PTR
);
2739 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, 0, 2, NULL_PTR
);
2742 add_prefix (&startfile_prefixes
, standard_exec_prefix
, 0, 1, NULL_PTR
);
2743 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, 0, 1, NULL_PTR
);
2745 tooldir_prefix
= concat3 (tooldir_base_prefix
, spec_machine
,
2748 /* If tooldir is relative, base it on exec_prefixes. A relative
2749 tooldir lets us move the installed tree as a unit.
2751 If GCC_EXEC_PREFIX is defined, then we want to add two relative
2752 directories, so that we can search both the user specified directory
2753 and the standard place. */
2755 if (*tooldir_prefix
!= '/' && *tooldir_prefix
!= DIR_SEPARATOR
)
2757 if (gcc_exec_prefix
)
2759 char *gcc_exec_tooldir_prefix
2760 = concat6 (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
2761 spec_version
, dir_separator_str
, tooldir_prefix
);
2763 add_prefix (&exec_prefixes
,
2764 concat3 (gcc_exec_tooldir_prefix
, "bin",
2767 add_prefix (&startfile_prefixes
,
2768 concat3 (gcc_exec_tooldir_prefix
, "lib",
2773 tooldir_prefix
= concat6 (standard_exec_prefix
, spec_machine
,
2774 dir_separator_str
, spec_version
,
2775 dir_separator_str
, tooldir_prefix
);
2778 add_prefix (&exec_prefixes
,
2779 concat3 (tooldir_prefix
, "bin", dir_separator_str
),
2781 add_prefix (&startfile_prefixes
,
2782 concat3 (tooldir_prefix
, "lib", dir_separator_str
),
2785 /* More prefixes are enabled in main, after we read the specs file
2786 and determine whether this is cross-compilation or not. */
2789 /* Then create the space for the vectors and scan again. */
2791 switches
= ((struct switchstr
*)
2792 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
2793 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
2796 last_language_n_infiles
= -1;
2798 /* This, time, copy the text of each switch and store a pointer
2799 to the copy in the vector of switches.
2800 Store all the infiles in their vector. */
2802 for (i
= 1; i
< argc
; i
++)
2804 /* Just skip the switches that were handled by the preceding loop. */
2805 if (! strncmp (argv
[i
], "-Wa,", 4))
2807 else if (! strncmp (argv
[i
], "-Wp,", 4))
2809 else if (! strcmp (argv
[i
], "-print-search-dirs"))
2811 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
2813 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
2815 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
2817 else if (! strcmp (argv
[i
], "-print-multi-lib"))
2819 else if (! strcmp (argv
[i
], "-print-multi-directory"))
2821 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
2823 /* Compensate for the +e options to the C++ front-end;
2824 they're there simply for cfront call-compatibility. We do
2825 some magic in default_compilers to pass them down properly.
2826 Note we deliberately start at the `+' here, to avoid passing
2827 -e0 or -e1 down into the linker. */
2828 switches
[n_switches
].part1
= &argv
[i
][0];
2829 switches
[n_switches
].args
= 0;
2830 switches
[n_switches
].live_cond
= 0;
2831 switches
[n_switches
].valid
= 0;
2834 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
2837 /* Split the argument at commas. */
2839 for (j
= 4; argv
[i
][j
]; j
++)
2840 if (argv
[i
][j
] == ',')
2842 infiles
[n_infiles
].language
= 0;
2843 infiles
[n_infiles
++].name
2844 = save_string (argv
[i
] + prev
, j
- prev
);
2847 /* Record the part after the last comma. */
2848 infiles
[n_infiles
].language
= 0;
2849 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
2851 else if (strcmp (argv
[i
], "-Xlinker") == 0)
2853 infiles
[n_infiles
].language
= 0;
2854 infiles
[n_infiles
++].name
= argv
[++i
];
2856 else if (strncmp (argv
[i
], "-l", 2) == 0)
2858 infiles
[n_infiles
].language
= 0;
2859 infiles
[n_infiles
++].name
= argv
[i
];
2861 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2863 register char *p
= &argv
[i
][1];
2864 register int c
= *p
;
2866 if (c
== 'B' || c
== 'b' || c
== 'V')
2868 /* Skip a separate arg, if any. */
2875 if (p
[1] == 0 && i
+ 1 == argc
)
2876 fatal ("argument to `-x' is missing");
2878 spec_lang
= argv
[++i
];
2881 if (! strcmp (spec_lang
, "none"))
2882 /* Suppress the warning if -xnone comes after the last input
2883 file, because alternate command interfaces like g++ might
2884 find it useful to place -xnone after each input file. */
2887 last_language_n_infiles
= n_infiles
;
2890 switches
[n_switches
].part1
= p
;
2891 /* Deal with option arguments in separate argv elements. */
2892 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
2893 || WORD_SWITCH_TAKES_ARG (p
))
2896 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
2900 /* Count only the option arguments in separate argv elements. */
2901 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
2903 if (i
+ n_args
>= argc
)
2904 fatal ("argument to `-%s' is missing", p
);
2905 switches
[n_switches
].args
2906 = (char **) xmalloc ((n_args
+ 1) * sizeof (char *));
2908 switches
[n_switches
].args
[j
++] = argv
[++i
];
2909 /* Null-terminate the vector. */
2910 switches
[n_switches
].args
[j
] = 0;
2912 else if (*switches_need_spaces
!= 0 && (c
== 'o' || c
== 'L'))
2914 /* On some systems, ld cannot handle -o or -L without space.
2915 So split the -o or -L from its argument. */
2916 switches
[n_switches
].part1
= (c
== 'o' ? "o" : "L");
2917 switches
[n_switches
].args
= (char **) xmalloc (2 * sizeof (char *));
2918 switches
[n_switches
].args
[0] = xmalloc (strlen (p
));
2919 strcpy (switches
[n_switches
].args
[0], &p
[1]);
2920 switches
[n_switches
].args
[1] = 0;
2923 switches
[n_switches
].args
= 0;
2925 switches
[n_switches
].live_cond
= 0;
2926 switches
[n_switches
].valid
= 0;
2927 /* This is always valid, since gcc.c itself understands it. */
2928 if (!strcmp (p
, "save-temps"))
2929 switches
[n_switches
].valid
= 1;
2934 #ifdef HAVE_OBJECT_SUFFIX
2935 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */
2936 if (strlen (argv
[i
]) > 2
2937 && argv
[i
][strlen (argv
[i
]) - 2] == '.'
2938 && argv
[i
][strlen (argv
[i
]) - 1] == 'o')
2942 for (j
= 0; j
< strlen (argv
[i
]) - 2; j
++)
2943 obstack_1grow (&obstack
, argv
[i
][j
]);
2945 obstack_grow (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
2946 obstack_1grow (&obstack
, 0);
2947 argv
[i
] = obstack_finish (&obstack
);
2951 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], R_OK
) < 0)
2953 perror_with_name (argv
[i
]);
2958 infiles
[n_infiles
].language
= spec_lang
;
2959 infiles
[n_infiles
++].name
= argv
[i
];
2964 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
2965 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
2967 switches
[n_switches
].part1
= 0;
2968 infiles
[n_infiles
].name
= 0;
2971 /* Process a spec string, accumulating and running commands. */
2973 /* These variables describe the input file name.
2974 input_file_number is the index on outfiles of this file,
2975 so that the output file name can be stored for later use by %o.
2976 input_basename is the start of the part of the input file
2977 sans all directory names, and basename_length is the number
2978 of characters starting there excluding the suffix .c or whatever. */
2980 static char *input_filename
;
2981 static int input_file_number
;
2982 static int input_filename_length
;
2983 static int basename_length
;
2984 static char *input_basename
;
2985 static char *input_suffix
;
2987 /* These are variables used within do_spec and do_spec_1. */
2989 /* Nonzero if an arg has been started and not yet terminated
2990 (with space, tab or newline). */
2991 static int arg_going
;
2993 /* Nonzero means %d or %g has been seen; the next arg to be terminated
2994 is a temporary file name. */
2995 static int delete_this_arg
;
2997 /* Nonzero means %w has been seen; the next arg to be terminated
2998 is the output file name of this compilation. */
2999 static int this_is_output_file
;
3001 /* Nonzero means %s has been seen; the next arg to be terminated
3002 is the name of a library file and we should try the standard
3003 search dirs for it. */
3004 static int this_is_library_file
;
3006 /* Nonzero means that the input of this command is coming from a pipe. */
3007 static int input_from_pipe
;
3009 /* Process the spec SPEC and run the commands specified therein.
3010 Returns 0 if the spec is successfully processed; -1 if failed. */
3020 delete_this_arg
= 0;
3021 this_is_output_file
= 0;
3022 this_is_library_file
= 0;
3023 input_from_pipe
= 0;
3025 value
= do_spec_1 (spec
, 0, NULL_PTR
);
3027 /* Force out any unfinished command.
3028 If -pipe, this forces out the last command if it ended in `|'. */
3031 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3034 if (argbuf_index
> 0)
3041 /* Process the sub-spec SPEC as a portion of a larger spec.
3042 This is like processing a whole spec except that we do
3043 not initialize at the beginning and we do not supply a
3044 newline by default at the end.
3045 INSWITCH nonzero means don't process %-sequences in SPEC;
3046 in this case, % is treated as an ordinary character.
3047 This is used while substituting switches.
3048 INSWITCH nonzero also causes SPC not to terminate an argument.
3050 Value is zero unless a line was finished
3051 and the command on that line reported an error. */
3054 do_spec_1 (spec
, inswitch
, soft_matched_part
)
3057 char *soft_matched_part
;
3059 register char *p
= spec
;
3066 /* If substituting a switch, treat all chars like letters.
3067 Otherwise, NL, SPC, TAB and % are special. */
3068 switch (inswitch
? 'a' : c
)
3071 /* End of line: finish any pending argument,
3072 then run the pending command if one has been started. */
3075 obstack_1grow (&obstack
, 0);
3076 string
= obstack_finish (&obstack
);
3077 if (this_is_library_file
)
3078 string
= find_file (string
);
3079 store_arg (string
, delete_this_arg
, this_is_output_file
);
3080 if (this_is_output_file
)
3081 outfiles
[input_file_number
] = string
;
3085 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
3087 for (i
= 0; i
< n_switches
; i
++)
3088 if (!strcmp (switches
[i
].part1
, "pipe"))
3091 /* A `|' before the newline means use a pipe here,
3092 but only if -pipe was specified.
3093 Otherwise, execute now and don't pass the `|' as an arg. */
3096 input_from_pipe
= 1;
3097 switches
[i
].valid
= 1;
3104 if (argbuf_index
> 0)
3110 /* Reinitialize for a new command, and for a new argument. */
3113 delete_this_arg
= 0;
3114 this_is_output_file
= 0;
3115 this_is_library_file
= 0;
3116 input_from_pipe
= 0;
3120 /* End any pending argument. */
3123 obstack_1grow (&obstack
, 0);
3124 string
= obstack_finish (&obstack
);
3125 if (this_is_library_file
)
3126 string
= find_file (string
);
3127 store_arg (string
, delete_this_arg
, this_is_output_file
);
3128 if (this_is_output_file
)
3129 outfiles
[input_file_number
] = string
;
3133 obstack_1grow (&obstack
, c
);
3139 /* Space or tab ends an argument if one is pending. */
3142 obstack_1grow (&obstack
, 0);
3143 string
= obstack_finish (&obstack
);
3144 if (this_is_library_file
)
3145 string
= find_file (string
);
3146 store_arg (string
, delete_this_arg
, this_is_output_file
);
3147 if (this_is_output_file
)
3148 outfiles
[input_file_number
] = string
;
3150 /* Reinitialize for a new argument. */
3152 delete_this_arg
= 0;
3153 this_is_output_file
= 0;
3154 this_is_library_file
= 0;
3161 fatal ("Invalid specification! Bug in cc.");
3164 obstack_grow (&obstack
, input_basename
, basename_length
);
3169 delete_this_arg
= 2;
3172 /* Dump out the directories specified with LIBRARY_PATH,
3173 followed by the absolute directories
3174 that we search for startfiles. */
3177 struct prefix_list
*pl
= startfile_prefixes
.plist
;
3179 char *buffer
= (char *) xmalloc (bufsize
);
3182 for (; pl
; pl
= pl
->next
)
3184 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
3185 /* Used on systems which record the specified -L dirs
3186 and use them to search for dynamic linking. */
3187 /* Relative directories always come from -B,
3188 and it is better not to use them for searching
3189 at run time. In particular, stage1 loses */
3190 if (pl
->prefix
[0] != '/' && pl
->prefix
[0] != DIR_SEPARATOR
)
3193 /* Try subdirectory if there is one. */
3194 if (multilib_dir
!= NULL
)
3198 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
3200 bufsize
= (strlen (pl
->prefix
)
3201 + strlen (machine_suffix
)) * 2 + 1;
3202 buffer
= (char *) xrealloc (buffer
, bufsize
);
3203 strcpy (buffer
, pl
->prefix
);
3204 strcat (buffer
, machine_suffix
);
3205 if (is_directory (buffer
, multilib_dir
, 1))
3207 do_spec_1 ("-L", 0, NULL_PTR
);
3208 #ifdef SPACE_AFTER_L_OPTION
3209 do_spec_1 (" ", 0, NULL_PTR
);
3211 do_spec_1 (buffer
, 1, NULL_PTR
);
3212 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3213 /* Make this a separate argument. */
3214 do_spec_1 (" ", 0, NULL_PTR
);
3217 if (!pl
->require_machine_suffix
)
3219 if (is_directory (pl
->prefix
, multilib_dir
, 1))
3221 do_spec_1 ("-L", 0, NULL_PTR
);
3222 #ifdef SPACE_AFTER_L_OPTION
3223 do_spec_1 (" ", 0, NULL_PTR
);
3225 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3226 do_spec_1 (multilib_dir
, 1, NULL_PTR
);
3227 /* Make this a separate argument. */
3228 do_spec_1 (" ", 0, NULL_PTR
);
3234 if (is_directory (pl
->prefix
, machine_suffix
, 1))
3236 do_spec_1 ("-L", 0, NULL_PTR
);
3237 #ifdef SPACE_AFTER_L_OPTION
3238 do_spec_1 (" ", 0, NULL_PTR
);
3240 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3241 /* Remove slash from machine_suffix. */
3242 if (strlen (machine_suffix
) >= bufsize
)
3243 bufsize
= strlen (machine_suffix
) * 2 + 1;
3244 buffer
= (char *) xrealloc (buffer
, bufsize
);
3245 strcpy (buffer
, machine_suffix
);
3246 idx
= strlen (buffer
);
3247 if (buffer
[idx
- 1] == '/'
3248 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3249 buffer
[idx
- 1] = 0;
3250 do_spec_1 (buffer
, 1, NULL_PTR
);
3251 /* Make this a separate argument. */
3252 do_spec_1 (" ", 0, NULL_PTR
);
3255 if (!pl
->require_machine_suffix
)
3257 if (is_directory (pl
->prefix
, "", 1))
3259 do_spec_1 ("-L", 0, NULL_PTR
);
3260 #ifdef SPACE_AFTER_L_OPTION
3261 do_spec_1 (" ", 0, NULL_PTR
);
3263 /* Remove slash from pl->prefix. */
3264 if (strlen (pl
->prefix
) >= bufsize
)
3265 bufsize
= strlen (pl
->prefix
) * 2 + 1;
3266 buffer
= (char *) xrealloc (buffer
, bufsize
);
3267 strcpy (buffer
, pl
->prefix
);
3268 idx
= strlen (buffer
);
3269 if (buffer
[idx
- 1] == '/'
3270 || buffer
[idx
- 1] == DIR_SEPARATOR
)
3271 buffer
[idx
- 1] = 0;
3272 do_spec_1 (buffer
, 1, NULL_PTR
);
3273 /* Make this a separate argument. */
3274 do_spec_1 (" ", 0, NULL_PTR
);
3283 /* {...:%efoo} means report an error with `foo' as error message
3284 and don't execute any more commands for this file. */
3288 while (*p
!= 0 && *p
!= '\n') p
++;
3289 buf
= (char *) alloca (p
- q
+ 1);
3290 strncpy (buf
, q
, p
- q
);
3300 if (save_temps_flag
)
3302 obstack_grow (&obstack
, input_basename
, basename_length
);
3303 delete_this_arg
= 0;
3307 #ifdef MKTEMP_EACH_FILE
3308 /* ??? This has a problem: the total number of
3309 values mktemp can return is limited.
3310 That matters for the names of object files.
3311 In 2.4, do something about that. */
3312 struct temp_name
*t
;
3314 while (*p
== '.' || isalpha (*p
)
3315 || (p
[0] == '%' && p
[1] == 'O'))
3318 /* See if we already have an association of %g/%u/%U and
3320 for (t
= temp_names
; t
; t
= t
->next
)
3321 if (t
->length
== p
- suffix
3322 && strncmp (t
->suffix
, suffix
, p
- suffix
) == 0
3323 && t
->unique
== (c
!= 'g'))
3326 /* Make a new association if needed. %u requires one. */
3327 if (t
== 0 || c
== 'u')
3331 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
3332 t
->next
= temp_names
;
3335 t
->length
= p
- suffix
;
3336 t
->suffix
= save_string (suffix
, p
- suffix
);
3337 t
->unique
= (c
!= 'g');
3338 choose_temp_base ();
3339 t
->filename
= temp_filename
;
3340 t
->filename_length
= temp_filename_length
;
3343 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
3344 delete_this_arg
= 1;
3346 obstack_grow (&obstack
, temp_filename
, temp_filename_length
);
3347 if (c
== 'u' || c
== 'U')
3353 sprintf (buff
, "%d", unique
);
3354 obstack_grow (&obstack
, buff
, strlen (buff
));
3357 delete_this_arg
= 1;
3363 obstack_grow (&obstack
, input_filename
, input_filename_length
);
3369 struct prefix_list
*pl
= include_prefixes
.plist
;
3371 if (gcc_exec_prefix
)
3373 do_spec_1 ("-iprefix", 1, NULL_PTR
);
3374 /* Make this a separate argument. */
3375 do_spec_1 (" ", 0, NULL_PTR
);
3376 do_spec_1 (gcc_exec_prefix
, 1, NULL_PTR
);
3377 do_spec_1 (" ", 0, NULL_PTR
);
3380 for (; pl
; pl
= pl
->next
)
3382 do_spec_1 ("-isystem", 1, NULL_PTR
);
3383 /* Make this a separate argument. */
3384 do_spec_1 (" ", 0, NULL_PTR
);
3385 do_spec_1 (pl
->prefix
, 1, NULL_PTR
);
3386 do_spec_1 (" ", 0, NULL_PTR
);
3392 for (i
= 0; i
< n_infiles
; i
++)
3393 store_arg (outfiles
[i
], 0, 0);
3397 obstack_grow (&obstack
, OBJECT_SUFFIX
, strlen (OBJECT_SUFFIX
));
3402 this_is_library_file
= 1;
3406 this_is_output_file
= 1;
3411 int index
= argbuf_index
;
3412 /* Handle the {...} following the %W. */
3415 p
= handle_braces (p
+ 1);
3418 /* If any args were output, mark the last one for deletion
3420 if (argbuf_index
!= index
)
3421 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
3425 /* %x{OPTION} records OPTION for %X to output. */
3431 /* Skip past the option value and make a copy. */
3436 string
= save_string (p1
+ 1, p
- p1
- 2);
3438 /* See if we already recorded this option. */
3439 for (i
= 0; i
< n_linker_options
; i
++)
3440 if (! strcmp (string
, linker_options
[i
]))
3446 /* This option is new; add it. */
3448 if (!linker_options
)
3450 = (char **) xmalloc (n_linker_options
* sizeof (char **));
3453 = (char **) xrealloc (linker_options
,
3454 n_linker_options
* sizeof (char **));
3456 linker_options
[n_linker_options
- 1] = string
;
3460 /* Dump out the options accumulated previously using %x. */
3462 for (i
= 0; i
< n_linker_options
; i
++)
3464 do_spec_1 (linker_options
[i
], 1, NULL_PTR
);
3465 /* Make each accumulated option a separate argument. */
3466 do_spec_1 (" ", 0, NULL_PTR
);
3470 /* Dump out the options accumulated previously using -Wa,. */
3472 for (i
= 0; i
< n_assembler_options
; i
++)
3474 do_spec_1 (assembler_options
[i
], 1, NULL_PTR
);
3475 /* Make each accumulated option a separate argument. */
3476 do_spec_1 (" ", 0, NULL_PTR
);
3480 /* Dump out the options accumulated previously using -Wp,. */
3482 for (i
= 0; i
< n_preprocessor_options
; i
++)
3484 do_spec_1 (preprocessor_options
[i
], 1, NULL_PTR
);
3485 /* Make each accumulated option a separate argument. */
3486 do_spec_1 (" ", 0, NULL_PTR
);
3490 /* Here are digits and numbers that just process
3491 a certain constant string as a spec. */
3494 value
= do_spec_1 (cc1_spec
, 0, NULL_PTR
);
3500 value
= do_spec_1 (cc1plus_spec
, 0, NULL_PTR
);
3506 value
= do_spec_1 (asm_spec
, 0, NULL_PTR
);
3512 value
= do_spec_1 (asm_final_spec
, 0, NULL_PTR
);
3518 value
= do_spec_1 (signed_char_spec
, 0, NULL_PTR
);
3524 value
= do_spec_1 (cpp_spec
, 0, NULL_PTR
);
3530 value
= do_spec_1 (endfile_spec
, 0, NULL_PTR
);
3536 value
= do_spec_1 (link_spec
, 0, NULL_PTR
);
3542 value
= do_spec_1 (lib_spec
, 0, NULL_PTR
);
3548 value
= do_spec_1 (libgcc_spec
, 0, NULL_PTR
);
3555 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
3559 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
3563 if (! strncmp (y
, "-D", 2))
3564 /* Copy the whole option. */
3565 while (*y
&& *y
!= ' ' && *y
!= '\t')
3567 else if (*y
== ' ' || *y
== '\t')
3568 /* Copy whitespace to the result. */
3570 /* Don't copy other options. */
3577 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3585 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
3589 /* Copy all of CPP_PREDEFINES into BUF,
3590 but put __ after every -D and at the end of each arg. */
3594 if (! strncmp (y
, "-D", 2))
3602 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3604 /* Stick __ at front of macro name. */
3607 /* Arrange to stick __ at the end as well. */
3611 /* Copy the macro name. */
3612 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3621 /* Copy the value given, if any. */
3622 while (*y
&& *y
!= ' ' && *y
!= '\t')
3625 else if (*y
== ' ' || *y
== '\t')
3626 /* Copy whitespace to the result. */
3628 /* Don't copy -A options */
3634 /* Copy all of CPP_PREDEFINES into BUF,
3635 but put __ after every -D. */
3639 if (! strncmp (y
, "-D", 2))
3644 || (*(y
+1) != '_' && ! isupper (*(y
+1))))
3646 /* Stick -D__ at front of macro name. */
3652 /* Copy the macro name. */
3653 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
3656 /* Copy the value given, if any. */
3657 while (*y
&& *y
!= ' ' && *y
!= '\t')
3662 /* Do not copy this macro - we have just done it before */
3663 while (*y
&& *y
!= ' ' && *y
!= '\t')
3667 else if (*y
== ' ' || *y
== '\t')
3668 /* Copy whitespace to the result. */
3670 /* Don't copy -A options */
3676 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
3680 if (! strncmp (y
, "-A", 2))
3681 /* Copy the whole option. */
3682 while (*y
&& *y
!= ' ' && *y
!= '\t')
3684 else if (*y
== ' ' || *y
== '\t')
3685 /* Copy whitespace to the result. */
3687 /* Don't copy other options. */
3694 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3701 value
= do_spec_1 (startfile_spec
, 0, NULL_PTR
);
3706 /* Here we define characters other than letters and digits. */
3709 p
= handle_braces (p
);
3715 obstack_1grow (&obstack
, '%');
3719 do_spec_1 (soft_matched_part
, 1, NULL_PTR
);
3720 do_spec_1 (" ", 0, NULL_PTR
);
3723 /* Process a string found as the value of a spec given by name.
3724 This feature allows individual machine descriptions
3725 to add and use their own specs.
3726 %[...] modifies -D options the way %P does;
3727 %(...) uses the spec unmodified. */
3732 struct spec_list
*sl
;
3735 /* The string after the S/P is the name of a spec that is to be
3737 while (*p
&& *p
!= ')' && *p
!= ']')
3740 /* See if it's in the list */
3741 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
3742 if (strncmp (sl
->name
, name
, len
) == 0 && !sl
->name
[len
])
3752 value
= do_spec_1 (name
, 0, NULL_PTR
);
3758 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
3762 /* Copy all of NAME into BUF, but put __ after
3763 every -D and at the end of each arg, */
3766 if (! strncmp (y
, "-D", 2))
3774 else if (*y
== ' ' || *y
== 0)
3788 value
= do_spec_1 (buf
, 0, NULL_PTR
);
3794 /* Discard the closing paren or bracket. */
3802 int c1
= *p
++; /* Select first or second version number. */
3803 char *v
= compiler_version
;
3805 /* If desired, advance to second version number. */
3808 /* Set P after the first period. */
3809 while (*v
!= 0 && *v
!= ' ' && *v
!= '.')
3814 /* Set Q at the next period or at the end. */
3816 while (*q
!= 0 && *q
!= ' ' && *q
!= '.')
3818 /* Empty string means zero. */
3824 /* Put that part into the command. */
3825 obstack_grow (&obstack
, v
, q
- v
);
3831 if (input_from_pipe
)
3832 do_spec_1 ("-", 0, NULL_PTR
);
3841 /* Backslash: treat next character as ordinary. */
3846 /* Ordinary character: put it into the current argument. */
3847 obstack_1grow (&obstack
, c
);
3851 return 0; /* End of string */
3854 /* Return 0 if we call do_spec_1 and that returns -1. */
3867 /* A `|' after the open-brace means,
3868 if the test fails, output a single minus sign rather than nothing.
3869 This is used in %{|!pipe:...}. */
3873 /* A `!' after the open-brace negates the condition:
3874 succeed if the specified switch is not present. */
3878 /* A `.' after the open-brace means test against the current suffix. */
3888 while (*p
!= ':' && *p
!= '}') p
++;
3891 register int count
= 1;
3909 int found
= (input_suffix
!= 0
3910 && strlen (input_suffix
) == p
- filter
3911 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
3917 && do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
3922 else if (p
[-1] == '*' && p
[0] == '}')
3924 /* Substitute all matching switches as separate args. */
3927 for (i
= 0; i
< n_switches
; i
++)
3928 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3929 && check_live_switch (i
, p
- filter
))
3934 /* Test for presence of the specified switch. */
3938 /* If name specified ends in *, as in {x*:...},
3939 check for %* and handle that case. */
3940 if (p
[-1] == '*' && !negate
)
3945 /* First see whether we have %*. */
3949 if (*r
== '%' && r
[1] == '*')
3953 /* If we do, handle that case. */
3956 /* Substitute all matching switches as separate args.
3957 But do this by substituting for %*
3958 in the text that follows the colon. */
3960 unsigned hard_match_len
= p
- filter
- 1;
3961 char *string
= save_string (p
+ 1, q
- p
- 2);
3963 for (i
= 0; i
< n_switches
; i
++)
3964 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3965 && check_live_switch (i
, -1))
3967 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
3968 /* Pass any arguments this switch has. */
3976 /* If name specified ends in *, as in {x*:...},
3977 check for presence of any switch name starting with x. */
3980 for (i
= 0; i
< n_switches
; i
++)
3982 unsigned hard_match_len
= p
- filter
- 1;
3984 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
3985 && check_live_switch (i
, hard_match_len
))
3991 /* Otherwise, check for presence of exact name specified. */
3994 for (i
= 0; i
< n_switches
; i
++)
3996 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
3997 && switches
[i
].part1
[p
- filter
] == 0
3998 && check_live_switch (i
, -1))
4006 /* If it is as desired (present for %{s...}, absent for %{-s...})
4007 then substitute either the switch or the specified
4008 conditional text. */
4009 if (present
!= negate
)
4017 if (do_spec_1 (save_string (p
+ 1, q
- p
- 2), 0, NULL_PTR
) < 0)
4023 /* Here if a %{|...} conditional fails: output a minus sign,
4024 which means "standard output" or "standard input". */
4025 do_spec_1 ("-", 0, NULL_PTR
);
4032 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
4033 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
4034 spec, or -1 if either exact match or %* is used.
4036 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
4037 whose value does not begin with "no-" is obsoleted by the same value
4038 with the "no-", similarly for a switch with the "no-" prefix. */
4041 check_live_switch (switchnum
, prefix_length
)
4045 char *name
= switches
[switchnum
].part1
;
4048 /* In the common case of {<at-most-one-letter>*}, a negating
4049 switch would always match, so ignore that case. We will just
4050 send the conflicting switches to the compiler phase. */
4051 if (prefix_length
>= 0 && prefix_length
<= 1)
4054 /* If we already processed this switch and determined if it was
4055 live or not, return our past determination. */
4056 if (switches
[switchnum
].live_cond
!= 0)
4057 return switches
[switchnum
].live_cond
> 0;
4059 /* Now search for duplicate in a manner that depends on the name. */
4063 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4064 if (switches
[i
].part1
[0] == 'O')
4066 switches
[switchnum
].valid
= 1;
4067 switches
[switchnum
].live_cond
= -1;
4072 case 'W': case 'f': case 'm':
4073 if (! strncmp (name
+ 1, "no-", 3))
4075 /* We have Xno-YYY, search for XYYY. */
4076 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4077 if (switches
[i
].part1
[0] == name
[0]
4078 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
4080 switches
[switchnum
].valid
= 1;
4081 switches
[switchnum
].live_cond
= -1;
4087 /* We have XYYY, search for Xno-YYY. */
4088 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
4089 if (switches
[i
].part1
[0] == name
[0]
4090 && switches
[i
].part1
[1] == 'n'
4091 && switches
[i
].part1
[2] == 'o'
4092 && switches
[i
].part1
[3] == '-'
4093 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
4095 switches
[switchnum
].valid
= 1;
4096 switches
[switchnum
].live_cond
= -1;
4103 /* Otherwise the switch is live. */
4104 switches
[switchnum
].live_cond
= 1;
4108 /* Pass a switch to the current accumulating command
4109 in the same form that we received it.
4110 SWITCHNUM identifies the switch; it is an index into
4111 the vector of switches gcc received, which is `switches'.
4112 This cannot fail since it never finishes a command line.
4114 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
4117 give_switch (switchnum
, omit_first_word
)
4119 int omit_first_word
;
4121 if (!omit_first_word
)
4123 do_spec_1 ("-", 0, NULL_PTR
);
4124 do_spec_1 (switches
[switchnum
].part1
, 1, NULL_PTR
);
4126 do_spec_1 (" ", 0, NULL_PTR
);
4127 if (switches
[switchnum
].args
!= 0)
4130 for (p
= switches
[switchnum
].args
; *p
; p
++)
4132 do_spec_1 (*p
, 1, NULL_PTR
);
4133 do_spec_1 (" ", 0, NULL_PTR
);
4136 switches
[switchnum
].valid
= 1;
4139 /* Search for a file named NAME trying various prefixes including the
4140 user's -B prefix and some standard ones.
4141 Return the absolute file name found. If nothing is found, return NAME. */
4149 /* Try multilib_dir if it is defined. */
4150 if (multilib_dir
!= NULL
)
4154 try = (char *) alloca (strlen (multilib_dir
) + strlen (name
) + 2);
4155 strcpy (try, multilib_dir
);
4156 strcat (try, dir_separator_str
);
4159 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
4161 /* If we don't find it in the multi library dir, then fall
4162 through and look for it in the normal places. */
4163 if (newname
!= NULL
)
4167 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
4168 return newname
? newname
: name
;
4171 /* Determine whether a directory exists. If LINKER, return 0 for
4172 certain fixed names not needed by the linker. If not LINKER, it is
4173 only important to return 0 if the host machine has a small ARG_MAX
4177 is_directory (path1
, path2
, linker
)
4182 int len1
= strlen (path1
);
4183 int len2
= strlen (path2
);
4184 char *path
= (char *) alloca (3 + len1
+ len2
);
4188 #ifndef SMALL_ARG_MAX
4193 /* Construct the path from the two parts. Ensure the string ends with "/.".
4194 The resulting path will be a directory even if the given path is a
4196 bcopy (path1
, path
, len1
);
4197 bcopy (path2
, path
+ len1
, len2
);
4198 cp
= path
+ len1
+ len2
;
4199 if (cp
[-1] != '/' && cp
[-1] != DIR_SEPARATOR
)
4200 *cp
++ = DIR_SEPARATOR
;
4204 /* Exclude directories that the linker is known to search. */
4207 && strcmp (path
, concat4 (dir_separator_str
, "lib",
4208 dir_separator_str
, ".")) == 0)
4210 && strcmp (path
, concat6 (dir_separator_str
, "usr",
4211 dir_separator_str
, "lib",
4212 dir_separator_str
, ".")) == 0)))
4215 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
4218 /* On fatal signals, delete all the temporary files. */
4221 fatal_error (signum
)
4224 signal (signum
, SIG_DFL
);
4225 delete_failure_queue ();
4226 delete_temp_files ();
4227 /* Get the same signal again, this time not handled,
4228 so its normal effect occurs. */
4229 kill (getpid (), signum
);
4240 int linker_was_run
= 0;
4241 char *explicit_link_files
;
4245 p
= argv
[0] + strlen (argv
[0]);
4246 while (p
!= argv
[0] && p
[-1] != '/' && p
[-1] != DIR_SEPARATOR
) --p
;
4249 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
4250 signal (SIGINT
, fatal_error
);
4252 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
4253 signal (SIGHUP
, fatal_error
);
4255 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
4256 signal (SIGTERM
, fatal_error
);
4258 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
4259 signal (SIGPIPE
, fatal_error
);
4263 argbuf
= (char **) xmalloc (argbuf_length
* sizeof (char *));
4265 obstack_init (&obstack
);
4267 /* Set up to remember the pathname of gcc and any options
4268 needed for collect. We use argv[0] instead of programname because
4269 we need the complete pathname. */
4270 obstack_init (&collect_obstack
);
4271 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
4272 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0])+1);
4273 putenv (obstack_finish (&collect_obstack
));
4275 #ifdef INIT_ENVIRONMENT
4276 /* Set up any other necessary machine specific environment variables. */
4277 putenv (INIT_ENVIRONMENT
);
4280 /* Choose directory for temp files. */
4282 choose_temp_base ();
4284 /* Make a table of what switches there are (switches, n_switches).
4285 Make a table of specified input files (infiles, n_infiles).
4286 Decode switches that are handled locally. */
4288 process_command (argc
, argv
);
4290 /* Initialize the vector of specs to just the default.
4291 This means one element containing 0s, as a terminator. */
4293 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
4294 bcopy ((char *) default_compilers
, (char *) compilers
,
4295 sizeof default_compilers
);
4296 n_compilers
= n_default_compilers
;
4298 /* Read specs from a file if there is one. */
4300 machine_suffix
= concat4 (spec_machine
, dir_separator_str
,
4301 spec_version
, dir_separator_str
);
4302 just_machine_suffix
= concat (spec_machine
, dir_separator_str
);
4304 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
4305 /* Read the specs file unless it is a default one. */
4306 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
4307 read_specs (specs_file
);
4309 /* If not cross-compiling, look for startfiles in the standard places. */
4310 /* The fact that these are done here, after reading the specs file,
4311 means that it cannot be found in these directories.
4312 But that's okay. It should never be there anyway. */
4315 #ifdef MD_EXEC_PREFIX
4316 add_prefix (&exec_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4317 add_prefix (&startfile_prefixes
, md_exec_prefix
, 0, 0, NULL_PTR
);
4320 #ifdef MD_STARTFILE_PREFIX
4321 add_prefix (&startfile_prefixes
, md_startfile_prefix
, 0, 0, NULL_PTR
);
4324 #ifdef MD_STARTFILE_PREFIX_1
4325 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, 0, 0, NULL_PTR
);
4328 /* If standard_startfile_prefix is relative, base it on
4329 standard_exec_prefix. This lets us move the installed tree
4330 as a unit. If GCC_EXEC_PREFIX is defined, base
4331 standard_startfile_prefix on that as well. */
4332 if (*standard_startfile_prefix
== '/'
4333 || *standard_startfile_prefix
== DIR_SEPARATOR
)
4334 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, 0, 0,
4338 if (gcc_exec_prefix
)
4339 add_prefix (&startfile_prefixes
,
4340 concat (gcc_exec_prefix
, standard_startfile_prefix
),
4342 add_prefix (&startfile_prefixes
,
4343 concat3 (standard_exec_prefix
,
4345 standard_startfile_prefix
),
4349 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
, 0, 0,
4351 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
, 0, 0,
4353 #if 0 /* Can cause surprises, and one can use -B./ instead. */
4354 add_prefix (&startfile_prefixes
, "./", 0, 1, NULL_PTR
);
4359 if (*standard_startfile_prefix
!= DIR_SEPARATOR
&& gcc_exec_prefix
)
4360 add_prefix (&startfile_prefixes
,
4361 concat (gcc_exec_prefix
, standard_startfile_prefix
),
4365 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
4366 if (gcc_exec_prefix
)
4368 char * temp
= (char *) xmalloc (strlen (gcc_exec_prefix
)
4369 + strlen (spec_version
)
4370 + strlen (spec_machine
) + 3);
4371 strcpy (temp
, gcc_exec_prefix
);
4372 strcat (temp
, spec_machine
);
4373 strcat (temp
, dir_separator_str
);
4374 strcat (temp
, spec_version
);
4375 strcat (temp
, dir_separator_str
);
4376 gcc_exec_prefix
= temp
;
4379 /* Now we have the specs.
4380 Set the `valid' bits for switches that match anything in any spec. */
4382 validate_all_switches ();
4384 /* Now that we have the switches and the specs, set
4385 the subdirectory based on the options. */
4386 set_multilib_dir ();
4388 /* Warn about any switches that no pass was interested in. */
4390 for (i
= 0; i
< n_switches
; i
++)
4391 if (! switches
[i
].valid
)
4392 error ("unrecognized option `-%s'", switches
[i
].part1
);
4394 /* Obey some of the options. */
4396 if (print_search_dirs
)
4398 printf ("install: %s%s\n", standard_exec_prefix
, machine_suffix
);
4399 printf ("programs: %s\n", build_search_list (&exec_prefixes
, "", 0));
4400 printf ("libraries: %s\n", build_search_list (&startfile_prefixes
, "", 0));
4404 if (print_file_name
)
4406 printf ("%s\n", find_file (print_file_name
));
4410 if (print_prog_name
)
4412 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
4413 printf ("%s\n", (newname
? newname
: print_prog_name
));
4417 if (print_multi_lib
)
4419 print_multilib_info ();
4423 if (print_multi_directory
)
4425 if (multilib_dir
== NULL
)
4428 printf ("%s\n", multilib_dir
);
4434 if (! strcmp (version_string
, compiler_version
))
4435 fprintf (stderr
, "gcc version %s\n", version_string
);
4437 fprintf (stderr
, "gcc driver version %s executing gcc version %s\n",
4438 version_string
, compiler_version
);
4445 fatal ("No input files");
4447 /* Make a place to record the compiler output file names
4448 that correspond to the input files. */
4450 outfiles
= (char **) xmalloc (n_infiles
* sizeof (char *));
4451 bzero ((char *) outfiles
, n_infiles
* sizeof (char *));
4453 /* Record which files were specified explicitly as link input. */
4455 explicit_link_files
= xmalloc (n_infiles
);
4456 bzero (explicit_link_files
, n_infiles
);
4458 for (i
= 0; i
< n_infiles
; i
++)
4460 register struct compiler
*cp
= 0;
4461 int this_file_error
= 0;
4463 /* Tell do_spec what to substitute for %i. */
4465 input_filename
= infiles
[i
].name
;
4466 input_filename_length
= strlen (input_filename
);
4467 input_file_number
= i
;
4469 /* Use the same thing in %o, unless cp->spec says otherwise. */
4471 outfiles
[i
] = input_filename
;
4473 /* Figure out which compiler from the file's suffix. */
4475 cp
= lookup_compiler (infiles
[i
].name
, input_filename_length
,
4476 infiles
[i
].language
);
4480 /* Ok, we found an applicable compiler. Run its spec. */
4481 /* First say how much of input_filename to substitute for %b */
4485 input_basename
= input_filename
;
4486 for (p
= input_filename
; *p
; p
++)
4487 if (*p
== '/' || *p
== DIR_SEPARATOR
)
4488 input_basename
= p
+ 1;
4490 /* Find a suffix starting with the last period,
4491 and set basename_length to exclude that suffix. */
4492 basename_length
= strlen (input_basename
);
4493 p
= input_basename
+ basename_length
;
4494 while (p
!= input_basename
&& *p
!= '.') --p
;
4495 if (*p
== '.' && p
!= input_basename
)
4497 basename_length
= p
- input_basename
;
4498 input_suffix
= p
+ 1;
4504 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4506 len
+= strlen (cp
->spec
[j
]);
4508 p
= (char *) xmalloc (len
+ 1);
4511 for (j
= 0; j
< sizeof cp
->spec
/ sizeof cp
->spec
[0]; j
++)
4514 strcpy (p
+ len
, cp
->spec
[j
]);
4515 len
+= strlen (cp
->spec
[j
]);
4518 value
= do_spec (p
);
4521 this_file_error
= 1;
4524 /* If this file's name does not contain a recognized suffix,
4525 record it as explicit linker input. */
4528 explicit_link_files
[i
] = 1;
4530 /* Clear the delete-on-failure queue, deleting the files in it
4531 if this compilation failed. */
4533 if (this_file_error
)
4535 delete_failure_queue ();
4538 /* If this compilation succeeded, don't delete those files later. */
4539 clear_failure_queue ();
4542 /* Run ld to link all the compiler output files. */
4544 if (error_count
== 0)
4546 int tmp
= execution_count
;
4550 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
4552 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH=");
4553 putenv_from_prefixes (&startfile_prefixes
, "LIBRARY_PATH=");
4555 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4557 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4558 sizeof ("COLLECT_GCC_OPTIONS=")-1);
4561 for (i
= 0; i
< n_switches
; i
++)
4565 obstack_grow (&collect_obstack
, " ", 1);
4568 obstack_grow (&collect_obstack
, "-", 1);
4569 obstack_grow (&collect_obstack
, switches
[i
].part1
,
4570 strlen (switches
[i
].part1
));
4572 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4574 obstack_grow (&collect_obstack
, " ", 1);
4575 obstack_grow (&collect_obstack
, *args
, strlen (*args
));
4578 obstack_grow (&collect_obstack
, "\0", 1);
4579 putenv (obstack_finish (&collect_obstack
));
4581 value
= do_spec (link_command_spec
);
4584 linker_was_run
= (tmp
!= execution_count
);
4587 /* Warn if a -B option was specified but the prefix was never used. */
4588 unused_prefix_warnings (&exec_prefixes
);
4589 unused_prefix_warnings (&startfile_prefixes
);
4591 /* If options said don't run linker,
4592 complain about input files to be given to the linker. */
4594 if (! linker_was_run
&& error_count
== 0)
4595 for (i
= 0; i
< n_infiles
; i
++)
4596 if (explicit_link_files
[i
])
4597 error ("%s: linker input file unused since linking not done",
4600 /* Delete some or all of the temporary files we made. */
4603 delete_failure_queue ();
4604 delete_temp_files ();
4606 exit (error_count
> 0 ? (signal_count
? 2 : 1) : 0);
4611 /* Find the proper compilation spec for the file name NAME,
4612 whose length is LENGTH. LANGUAGE is the specified language,
4613 or 0 if none specified. */
4615 static struct compiler
*
4616 lookup_compiler (name
, length
, language
)
4621 struct compiler
*cp
;
4623 /* Look for the language, if one is spec'd. */
4626 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4630 if (cp
->suffix
[0] == '@'
4631 && !strcmp (cp
->suffix
+ 1, language
))
4635 error ("language %s not recognized", language
);
4638 /* Look for a suffix. */
4639 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
4641 if (/* The suffix `-' matches only the file name `-'. */
4642 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
4644 (strlen (cp
->suffix
) < length
4645 /* See if the suffix matches the end of NAME. */
4647 && (!strcmp (cp
->suffix
,
4648 name
+ length
- strlen (cp
->suffix
))
4649 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
4650 && !strcasecmp (cp
->suffix
,
4651 name
+ length
- strlen (cp
->suffix
)))))
4653 && !strcmp (cp
->suffix
,
4654 name
+ length
- strlen (cp
->suffix
))))
4657 if (cp
->spec
[0][0] == '@')
4659 struct compiler
*new;
4660 /* An alias entry maps a suffix to a language.
4661 Search for the language; pass 0 for NAME and LENGTH
4662 to avoid infinite recursion if language not found.
4663 Construct the new compiler spec. */
4664 language
= cp
->spec
[0] + 1;
4665 new = (struct compiler
*) xmalloc (sizeof (struct compiler
));
4666 new->suffix
= cp
->suffix
;
4667 bcopy ((char *) lookup_compiler (NULL_PTR
, 0, language
)->spec
,
4668 (char *) new->spec
, sizeof new->spec
);
4671 /* A non-alias entry: return it. */
4683 register char *value
= (char *) malloc (size
);
4685 fatal ("virtual memory exhausted");
4690 xrealloc (ptr
, size
)
4694 register char *value
= (char *) realloc (ptr
, size
);
4696 fatal ("virtual memory exhausted");
4700 /* Return a newly-allocated string whose contents concatenate those of s1, s2 */
4706 int len1
= strlen (s1
);
4707 int len2
= strlen (s2
);
4708 char *result
= xmalloc (len1
+ len2
+ 1);
4710 strcpy (result
, s1
);
4711 strcpy (result
+ len1
, s2
);
4712 *(result
+ len1
+ len2
) = 0;
4718 concat3 (s1
, s2
, s3
)
4721 return concat (concat (s1
, s2
), s3
);
4725 concat4 (s1
, s2
, s3
, s4
)
4726 char *s1
, *s2
, *s3
, *s4
;
4728 return concat (concat (s1
, s2
), concat (s3
, s4
));
4732 concat6 (s1
, s2
, s3
, s4
, s5
, s6
)
4733 char *s1
, *s2
, *s3
, *s4
, *s5
, *s6
;
4735 return concat3 (concat (s1
, s2
), concat (s3
, s4
), concat (s5
, s6
));
4739 save_string (s
, len
)
4743 register char *result
= xmalloc (len
+ 1);
4745 bcopy (s
, result
, len
);
4751 pfatal_with_name (name
)
4756 if (errno
< sys_nerr
)
4757 s
= concat ("%s: ", my_strerror( errno
));
4759 s
= "cannot open %s";
4764 perror_with_name (name
)
4769 if (errno
< sys_nerr
)
4770 s
= concat ("%s: ", my_strerror( errno
));
4772 s
= "cannot open %s";
4782 if (errno
< sys_nerr
)
4783 s
= concat ("installation problem, cannot exec %s: ", my_strerror( errno
));
4785 s
= "installation problem, cannot exec %s";
4789 /* More 'friendly' abort that prints the line and file.
4790 config.h can #define abort fancy_abort if you like that sort of thing. */
4795 fatal ("Internal gcc abort.");
4800 /* Output an error message and exit */
4803 fatal
VPROTO((char *format
, ...))
4810 VA_START (ap
, format
);
4813 format
= va_arg (ap
, char*);
4816 fprintf (stderr
, "%s: ", programname
);
4817 vfprintf (stderr
, format
, ap
);
4819 fprintf (stderr
, "\n");
4820 delete_temp_files ();
4825 error
VPROTO((char *format
, ...))
4832 VA_START (ap
, format
);
4835 format
= va_arg (ap
, char*);
4838 fprintf (stderr
, "%s: ", programname
);
4839 vfprintf (stderr
, format
, ap
);
4842 fprintf (stderr
, "\n");
4845 #else /* not HAVE_VPRINTF */
4848 fatal (msg
, arg1
, arg2
)
4849 char *msg
, *arg1
, *arg2
;
4851 error (msg
, arg1
, arg2
);
4852 delete_temp_files ();
4857 error (msg
, arg1
, arg2
)
4858 char *msg
, *arg1
, *arg2
;
4860 fprintf (stderr
, "%s: ", programname
);
4861 fprintf (stderr
, msg
, arg1
, arg2
);
4862 fprintf (stderr
, "\n");
4865 #endif /* not HAVE_VPRINTF */
4869 validate_all_switches ()
4871 struct compiler
*comp
;
4874 struct spec_list
*spec
;
4876 for (comp
= compilers
; comp
->spec
[0]; comp
++)
4879 for (i
= 0; i
< sizeof comp
->spec
/ sizeof comp
->spec
[0] && comp
->spec
[i
]; i
++)
4883 if (c
== '%' && *p
== '{')
4884 /* We have a switch spec. */
4885 validate_switches (p
+ 1);
4889 /* look through the linked list of extra specs read from the specs file */
4890 for (spec
= specs
; spec
; spec
= spec
->next
)
4894 if (c
== '%' && *p
== '{')
4895 /* We have a switch spec. */
4896 validate_switches (p
+ 1);
4899 p
= link_command_spec
;
4901 if (c
== '%' && *p
== '{')
4902 /* We have a switch spec. */
4903 validate_switches (p
+ 1);
4905 /* Now notice switches mentioned in the machine-specific specs. */
4909 if (c
== '%' && *p
== '{')
4910 /* We have a switch spec. */
4911 validate_switches (p
+ 1);
4915 if (c
== '%' && *p
== '{')
4916 /* We have a switch spec. */
4917 validate_switches (p
+ 1);
4921 if (c
== '%' && *p
== '{')
4922 /* We have a switch spec. */
4923 validate_switches (p
+ 1);
4925 p
= signed_char_spec
;
4927 if (c
== '%' && *p
== '{')
4928 /* We have a switch spec. */
4929 validate_switches (p
+ 1);
4933 if (c
== '%' && *p
== '{')
4934 /* We have a switch spec. */
4935 validate_switches (p
+ 1);
4939 if (c
== '%' && *p
== '{')
4940 /* We have a switch spec. */
4941 validate_switches (p
+ 1);
4945 if (c
== '%' && *p
== '{')
4946 /* We have a switch spec. */
4947 validate_switches (p
+ 1);
4951 if (c
== '%' && *p
== '{')
4952 /* We have a switch spec. */
4953 validate_switches (p
+ 1);
4957 if (c
== '%' && *p
== '{')
4958 /* We have a switch spec. */
4959 validate_switches (p
+ 1);
4963 if (c
== '%' && *p
== '{')
4964 /* We have a switch spec. */
4965 validate_switches (p
+ 1);
4968 /* Look at the switch-name that comes after START
4969 and mark as valid all supplied switches that match it. */
4972 validate_switches (start
)
4975 register char *p
= start
;
4990 while (*p
!= ':' && *p
!= '}') p
++;
4994 else if (p
[-1] == '*')
4996 /* Mark all matching switches as valid. */
4998 for (i
= 0; i
< n_switches
; i
++)
4999 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
))
5000 switches
[i
].valid
= 1;
5004 /* Mark an exact matching switch as valid. */
5005 for (i
= 0; i
< n_switches
; i
++)
5007 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5008 && switches
[i
].part1
[p
- filter
] == 0)
5009 switches
[i
].valid
= 1;
5014 /* Check whether a particular argument was used. */
5023 for (i
= 0; i
< n_switches
; i
++)
5024 if (! strncmp (switches
[i
].part1
, p
, len
)
5025 && strlen (switches
[i
].part1
) == len
)
5030 /* Work out the subdirectory to use based on the
5031 options. The format of multilib_select is a list of elements.
5032 Each element is a subdirectory name followed by a list of options
5033 followed by a semicolon. gcc will consider each line in turn. If
5034 none of the options beginning with an exclamation point are
5035 present, and all of the other options are present, that
5036 subdirectory will be used. */
5041 char *p
= multilib_select
;
5043 char *this_path
, *this_arg
;
5048 /* Ignore newlines. */
5055 /* Get the initial path. */
5063 this_path_len
= p
- this_path
;
5065 /* Check the arguments. */
5080 while (*p
!= ' ' && *p
!= ';')
5087 if (*this_arg
== '!')
5088 failed
= used_arg (this_arg
+ 1, p
- (this_arg
+ 1));
5090 failed
= ! used_arg (this_arg
, p
- this_arg
);
5098 if (this_path_len
!= 1
5099 || this_path
[0] != '.')
5101 multilib_dir
= xmalloc (this_path_len
+ 1);
5102 strncpy (multilib_dir
, this_path
, this_path_len
);
5103 multilib_dir
[this_path_len
] = '\0';
5112 /* Print out the multiple library subdirectory selection
5113 information. This prints out a series of lines. Each line looks
5114 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
5115 required. Only the desired options are printed out, the negative
5116 matches. The options are print without a leading dash. There are
5117 no spaces to make it easy to use the information in the shell.
5118 Each subdirectory is printed only once. This assumes the ordering
5119 generated by the genmultilib script. */
5122 print_multilib_info ()
5124 char *p
= multilib_select
;
5125 char *last_path
= 0, *this_path
;
5127 int last_path_len
= 0;
5131 /* Ignore newlines. */
5138 /* Get the initial path. */
5147 /* If this is a duplicate, skip it. */
5148 skip
= (last_path
!= 0 && p
- this_path
== last_path_len
5149 && ! strncmp (last_path
, this_path
, last_path_len
));
5151 last_path
= this_path
;
5152 last_path_len
= p
- this_path
;
5158 for (p1
= last_path
; p1
< p
; p1
++)
5177 use_arg
= *p
!= '!';
5182 while (*p
!= ' ' && *p
!= ';')