1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 This paragraph is here to try to keep Sun CC from dying.
23 The number of chars here seems crucial!!!! */
25 /* This program is the user interface to the C compiler and possibly to
26 other compilers. It is used because compilation is a complicated procedure
27 which involves running several programs and passing temporary files between
28 them, forwarding the users switches to those programs selectively,
29 and deleting the temporary files at the end.
31 CC recognizes how to compile each input file by suffixes in the file names.
32 Once it knows which kind of compilation to perform, the procedure for
33 compilation is specified by a string called a "spec". */
35 /* A Short Introduction to Adding a Command-Line Option.
37 Before adding a command-line option, consider if it is really
38 necessary. Each additional command-line option adds complexity and
39 is difficult to remove in subsequent versions.
41 In the following, consider adding the command-line argument
44 1. Each command-line option is specified in the specs file. The
45 notation is described below in the comment entitled "The Specs
48 2. In this file, add an entry to "option_map" equating the long
49 `--' argument version and any shorter, single letter version. Read
50 the comments in the declaration of "struct option_map" for an
51 explanation. Do not omit the first `-'.
53 3. Look in the "specs" file to determine which program or option
54 list should be given the argument, e.g., "cc1_options". Add the
55 appropriate syntax for the shorter option version to the
56 corresponding "const char *" entry in this file. Omit the first
57 `-' from the option. For example, use `-bar', rather than `--bar'.
59 4. If the argument takes an argument, e.g., `--baz argument1',
60 modify either DEFAULT_SWITCH_TAKES_ARG or
61 DEFAULT_WORD_SWITCH_TAKES_ARG in this file. Omit the first `-'
64 5. Document the option in this file's display_help(). If the
65 option is passed to a subprogram, modify its corresponding
66 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
69 6. Compile and test. Make sure that your new specs file is being
70 read. For example, use a debugger to investigate the value of
71 "specs_file" in main(). */
76 #if ! defined( SIGCHLD ) && defined( SIGCLD )
77 # define SIGCHLD SIGCLD
85 #define exit __posix_exit
88 #ifdef HAVE_SYS_RESOURCE_H
89 #include <sys/resource.h>
91 #if defined (HAVE_DECL_GETRUSAGE) && !HAVE_DECL_GETRUSAGE
92 extern int getrusage PARAMS ((int, struct rusage *));
95 /* By default there is no special suffix for target executables. */
96 /* FIXME: when autoconf is fixed, remove the host check - dj */
97 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
98 #define HAVE_TARGET_EXECUTABLE_SUFFIX
100 #define TARGET_EXECUTABLE_SUFFIX ""
103 /* By default there is no special suffix for host executables. */
104 #ifdef HOST_EXECUTABLE_SUFFIX
105 #define HAVE_HOST_EXECUTABLE_SUFFIX
107 #define HOST_EXECUTABLE_SUFFIX ""
110 /* By default, the suffix for target object files is ".o". */
111 #ifdef TARGET_OBJECT_SUFFIX
112 #define HAVE_TARGET_OBJECT_SUFFIX
114 #define TARGET_OBJECT_SUFFIX ".o"
118 /* FIXME: the location independence code for VMS is hairier than this,
119 and hasn't been written. */
125 static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
127 #define obstack_chunk_alloc xmalloc
128 #define obstack_chunk_free free
130 #ifndef GET_ENV_PATH_LIST
131 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
134 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
135 #ifndef LIBRARY_PATH_ENV
136 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
140 #define kill(p,s) raise(s)
143 /* If a stage of compilation returns an exit status >= 1,
144 compilation of that file ceases. */
146 #define MIN_FATAL_STATUS 1
148 /* Flag saying to pass the greatest exit code returned by a sub-process
149 to the calling program. */
150 static int pass_exit_codes;
152 /* Definition of string containing the arguments given to configure. */
153 #include "configargs.h"
155 /* Flag saying to print the directories gcc will search through looking for
156 programs, libraries, etc. */
158 static int print_search_dirs;
160 /* Flag saying to print the full filename of this file
161 as found through our usual search mechanism. */
163 static const char *print_file_name = NULL;
165 /* As print_file_name, but search for executable file. */
167 static const char *print_prog_name = NULL;
169 /* Flag saying to print the relative path we'd use to
170 find libgcc.a given the current compiler flags. */
172 static int print_multi_directory;
174 /* Flag saying to print the list of subdirectories and
175 compiler flags used to select them in a standard form. */
177 static int print_multi_lib;
179 /* Flag saying to print the command line options understood by gcc and its
182 static int print_help_list;
184 /* Flag indicating whether we should print the command and arguments */
186 static int verbose_flag;
188 /* Flag indicating to print target specific command line options. */
190 static int target_help_flag;
192 /* Flag indicating whether we should report subprocess execution times
193 (if this is supported by the system - see pexecute.c). */
195 static int report_times;
197 /* Nonzero means write "temp" files in source directory
198 and use the source file's name in them, and don't delete them. */
200 static int save_temps_flag;
202 /* The compiler version. */
204 static const char *compiler_version;
206 /* The target version specified with -V */
208 static const char *spec_version = DEFAULT_TARGET_VERSION;
210 /* The target machine specified with -b. */
212 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
214 /* Nonzero if cross-compiling.
215 When -b is used, the value comes from the `specs' file. */
218 static const char *cross_compile = "1";
220 static const char *cross_compile = "0";
223 #ifdef MODIFY_TARGET_NAME
225 /* Information on how to alter the target name based on a command-line
226 switch. The only case we support now is simply appending or deleting a
227 string to or from the end of the first part of the configuration name. */
229 const struct modify_target
231 const char *const sw;
232 const enum add_del {ADD, DELETE} add_del;
233 const char *const str;
235 modify_target[] = MODIFY_TARGET_NAME;
238 /* The number of errors that have occurred; the link phase will not be
239 run if this is non-zero. */
240 static int error_count = 0;
242 /* Greatest exit code of sub-processes that has been encountered up to
244 static int greatest_status = 1;
246 /* This is the obstack which we use to allocate many strings. */
248 static struct obstack obstack;
250 /* This is the obstack to build an environment variable to pass to
251 collect2 that describes all of the relevant switches of what to
252 pass the compiler in building the list of pointers to constructors
255 static struct obstack collect_obstack;
257 /* These structs are used to collect resource usage information for
259 #ifdef HAVE_GETRUSAGE
260 static struct rusage rus, prus;
263 /* Forward declaration for prototypes. */
266 static void init_spec PARAMS ((void));
268 static char **split_directories PARAMS ((const char *, int *));
269 static void free_split_directories PARAMS ((char **));
270 static char *make_relative_prefix PARAMS ((const char *, const char *, const char *));
272 static void store_arg PARAMS ((const char *, int, int));
273 static char *load_specs PARAMS ((const char *));
274 static void read_specs PARAMS ((const char *, int));
275 static void set_spec PARAMS ((const char *, const char *));
276 static struct compiler *lookup_compiler PARAMS ((const char *, size_t, const char *));
277 static char *build_search_list PARAMS ((struct path_prefix *, const char *, int));
278 static void putenv_from_prefixes PARAMS ((struct path_prefix *, const char *));
279 static int access_check PARAMS ((const char *, int));
280 static char *find_a_file PARAMS ((struct path_prefix *, const char *, int));
281 static void add_prefix PARAMS ((struct path_prefix *, const char *,
282 const char *, int, int, int *));
283 static void translate_options PARAMS ((int *, const char *const **));
284 static char *skip_whitespace PARAMS ((char *));
285 static void delete_if_ordinary PARAMS ((const char *));
286 static void delete_temp_files PARAMS ((void));
287 static void delete_failure_queue PARAMS ((void));
288 static void clear_failure_queue PARAMS ((void));
289 static int check_live_switch PARAMS ((int, int));
290 static const char *handle_braces PARAMS ((const char *));
291 static char *save_string PARAMS ((const char *, int));
292 static int do_spec_1 PARAMS ((const char *, int, const char *));
293 static const char *find_file PARAMS ((const char *));
294 static int is_directory PARAMS ((const char *, const char *, int));
295 static void validate_switches PARAMS ((const char *));
296 static void validate_all_switches PARAMS ((void));
297 static void give_switch PARAMS ((int, int, int));
298 static int used_arg PARAMS ((const char *, int));
299 static int default_arg PARAMS ((const char *, int));
300 static void set_multilib_dir PARAMS ((void));
301 static void print_multilib_info PARAMS ((void));
302 static void perror_with_name PARAMS ((const char *));
303 static void pfatal_pexecute PARAMS ((const char *, const char *))
305 static void notice PARAMS ((const char *, ...))
307 static void display_help PARAMS ((void));
308 static void add_preprocessor_option PARAMS ((const char *, int));
309 static void add_assembler_option PARAMS ((const char *, int));
310 static void add_linker_option PARAMS ((const char *, int));
311 static void process_command PARAMS ((int, const char *const *));
312 static int execute PARAMS ((void));
313 static void clear_args PARAMS ((void));
314 static void fatal_error PARAMS ((int));
315 static void set_input PARAMS ((const char *));
316 #ifdef ENABLE_SHARED_LIBGCC
317 static void init_gcc_specs PARAMS ((struct obstack *,
322 /* The Specs Language
324 Specs are strings containing lines, each of which (if not blank)
325 is made up of a program name, and arguments separated by spaces.
326 The program name must be exact and start from root, since no path
327 is searched and it is unreliable to depend on the current working directory.
328 Redirection of input or output is not supported; the subprograms must
329 accept filenames saying what files to read and write.
331 In addition, the specs can contain %-sequences to substitute variable text
332 or for conditional text. Here is a table of all defined %-sequences.
333 Note that spaces are not generated automatically around the results of
334 expanding these sequences; therefore, you can concatenate them together
335 or with constant text in a single argument.
337 %% substitute one % into the program name or argument.
338 %i substitute the name of the input file being processed.
339 %b substitute the basename of the input file being processed.
340 This is the substring up to (and not including) the last period
341 and not including the directory.
342 %B same as %b, but include the file suffix (text after the last period).
344 substitute a file name that has suffix SUFFIX and is chosen
345 once per compilation, and mark the argument a la %d. To reduce
346 exposure to denial-of-service attacks, the file name is now
347 chosen in a way that is hard to predict even when previously
348 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
349 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
350 the regexp "[.A-Za-z]*%O"; "%O" is treated exactly as if it
351 had been pre-processed. Previously, %g was simply substituted
352 with a file name chosen once per compilation, without regard
353 to any appended suffix (which was therefore treated just like
354 ordinary text), making such attacks more likely to succeed.
356 like %g, but generates a new temporary file name even if %uSUFFIX
359 substitutes the last file name generated with %uSUFFIX, generating a
360 new one if there is no such last file name. In the absence of any
361 %uSUFFIX, this is just like %gSUFFIX, except they don't share
362 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
363 would involve the generation of two distinct file names, one
364 for each `%g.s' and another for each `%U.s'. Previously, %U was
365 simply substituted with a file name chosen for the previous %u,
366 without regard to any appended suffix.
368 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
369 writable, and if save-temps is off; otherwise, substitute the name
370 of a temporary file, just like %u. This temporary file is not
371 meant for communication between processes, but rather as a junk
374 substitutes .SUFFIX for the suffixes of a matched switch's args when
375 it is subsequently output with %*. SUFFIX is terminated by the next
377 %d marks the argument containing or following the %d as a
378 temporary file name, so that that file will be deleted if CC exits
379 successfully. Unlike %g, this contributes no text to the argument.
380 %w marks the argument containing or following the %w as the
381 "output file" of this compilation. This puts the argument
382 into the sequence of arguments that %o will substitute later.
384 like %{...} but mark last argument supplied within
385 as a file to be deleted on failure.
386 %o substitutes the names of all the output files, with spaces
387 automatically placed around them. You should write spaces
388 around the %o as well or the results are undefined.
389 %o is for use in the specs for running the linker.
390 Input files whose names have no recognized suffix are not compiled
391 at all, but they are included among the output files, so they will
393 %O substitutes the suffix for object files. Note that this is
394 handled specially when it immediately follows %g, %u, or %U
395 (with or without a suffix argument) because of the need for
396 those to form complete file names. The handling is such that
397 %O is treated exactly as if it had already been substituted,
398 except that %g, %u, and %U do not currently support additional
399 SUFFIX characters following %O as they would following, for
401 %p substitutes the standard macro predefinitions for the
402 current target machine. Use this when running cpp.
403 %P like %p, but puts `__' before and after the name of each macro.
404 (Except macros that already have __.)
406 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
407 %s current argument is the name of a library or startup file of some sort.
408 Search for that file in a standard list of directories
409 and substitute the full name found.
410 %eSTR Print STR as an error message. STR is terminated by a newline.
411 Use this when inconsistent options are detected.
412 %nSTR Print STR as an notice. STR is terminated by a newline.
413 %x{OPTION} Accumulate an option for %X.
414 %X Output the accumulated linker options specified by compilations.
415 %Y Output the accumulated assembler options specified by compilations.
416 %Z Output the accumulated preprocessor options specified by compilations.
417 %v1 Substitute the major version number of GCC.
418 (For version 2.5.3, this is 2.)
419 %v2 Substitute the minor version number of GCC.
420 (For version 2.5.3, this is 5.)
421 %v3 Substitute the patch level number of GCC.
422 (For version 2.5.3, this is 3.)
423 %a process ASM_SPEC as a spec.
424 This allows config.h to specify part of the spec for running as.
425 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
426 used here. This can be used to run a post-processor after the
427 assembler has done its job.
428 %D Dump out a -L option for each directory in startfile_prefixes.
429 If multilib_dir is set, extra entries are generated with it affixed.
430 %l process LINK_SPEC as a spec.
431 %L process LIB_SPEC as a spec.
432 %G process LIBGCC_SPEC as a spec.
433 %M output multilib_dir with directory separators replaced with "_";
434 if multilib_dir is not set or is ".", output "".
435 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
436 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
437 %c process SIGNED_CHAR_SPEC as a spec.
438 %C process CPP_SPEC as a spec.
439 %1 process CC1_SPEC as a spec.
440 %2 process CC1PLUS_SPEC as a spec.
441 %| output "-" if the input for the current command is coming from a pipe.
442 %* substitute the variable part of a matched option. (See below.)
443 Note that each comma in the substituted string is replaced by
445 %{S} substitutes the -S switch, if that switch was given to CC.
446 If that switch was not specified, this substitutes nothing.
447 Here S is a metasyntactic variable.
448 %{S*} substitutes all the switches specified to CC whose names start
449 with -S. This is used for -o, -I, etc; switches that take
450 arguments. CC considers `-o foo' as being one switch whose
451 name starts with `o'. %{o*} would substitute this text,
452 including the space; thus, two arguments would be generated.
453 %{^S*} likewise, but don't put a blank between a switch and any args.
454 %{S*&T*} likewise, but preserve order of S and T options (the order
455 of S and T in the spec is not significant). Can be any number
456 of ampersand-separated variables; for each the wild card is
457 optional. Useful for CPP as %{D*&U*&A*}.
458 %{S*:X} substitutes X if one or more switches whose names start with -S are
459 specified to CC. Note that the tail part of the -S option
460 (i.e. the part matched by the `*') will be substituted for each
461 occurrence of %* within X.
462 %{<S} remove all occurrences of -S from the command line.
463 Note - this option is position dependent. % commands in the
464 spec string before this option will see -S, % commands in the
465 spec string after this option will not.
466 %{S:X} substitutes X, but only if the -S switch was given to CC.
467 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
468 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
469 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
470 %{.S:X} substitutes X, but only if processing a file with suffix S.
471 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
472 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
473 combined with ! and . as above binding stronger than the OR.
474 %(Spec) processes a specification defined in a specs file as *Spec:
475 %[Spec] as above, but put __ around -D arguments
477 The conditional text X in a %{S:X} or %{!S:X} construct may contain
478 other nested % constructs or spaces, or even newlines. They are
479 processed as usual, as described above.
481 The -O, -f, -m, and -W switches are handled specifically in these
482 constructs. If another value of -O or the negated form of a -f, -m, or
483 -W switch is found later in the command line, the earlier switch
484 value is ignored, except with {S*} where S is just one letter; this
485 passes all matching options.
487 The character | at the beginning of the predicate text is used to indicate
488 that a command should be piped to the following command, but only if -pipe
491 Note that it is built into CC which switches take arguments and which
492 do not. You might think it would be useful to generalize this to
493 allow each compiler's spec to say which switches take arguments. But
494 this cannot be done in a consistent fashion. CC cannot even decide
495 which input files have been specified without knowing which switches
496 take arguments, and it must know which input files to compile in order
497 to tell which compilers to run.
499 CC also knows implicitly that arguments starting in `-l' are to be
500 treated as compiler output files, and passed to the linker in their
501 proper position among the other output files. */
503 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
505 /* config.h can define ASM_SPEC to provide extra args to the assembler
506 or extra switch-translations. */
511 /* config.h can define ASM_FINAL_SPEC to run a post processor after
512 the assembler has run. */
513 #ifndef ASM_FINAL_SPEC
514 #define ASM_FINAL_SPEC ""
517 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
518 or extra switch-translations. */
523 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
524 or extra switch-translations. */
529 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
530 or extra switch-translations. */
532 #define CC1PLUS_SPEC ""
535 /* config.h can define LINK_SPEC to provide extra args to the linker
536 or extra switch-translations. */
541 /* config.h can define LIB_SPEC to override the default libraries. */
543 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
546 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
549 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
550 /* Have gcc do the search for libgcc.a. */
551 #define LIBGCC_SPEC "libgcc.a%s"
553 #define LIBGCC_SPEC "-lgcc"
557 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
558 #ifndef STARTFILE_SPEC
559 #define STARTFILE_SPEC \
560 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
563 /* config.h can define SWITCHES_NEED_SPACES to control which options
564 require spaces between the option and the argument. */
565 #ifndef SWITCHES_NEED_SPACES
566 #define SWITCHES_NEED_SPACES ""
569 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
571 #define ENDFILE_SPEC ""
574 /* This spec is used for telling cpp whether char is signed or not. */
575 #ifndef SIGNED_CHAR_SPEC
576 /* Use #if rather than ?:
577 because MIPS C compiler rejects like ?: in initializers. */
578 #if DEFAULT_SIGNED_CHAR
579 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
581 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
586 #define LINKER_NAME "collect2"
589 /* Here is the spec for running the linker, after compiling all files. */
591 /* -u* was put back because both BSD and SysV seem to support it. */
592 /* %{static:} simply prevents an error message if the target machine
593 doesn't handle -static. */
594 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
595 scripts which exist in user specified directories, or in standard
597 #ifndef LINK_COMMAND_SPEC
598 #define LINK_COMMAND_SPEC "\
599 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
600 %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
601 %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
602 %{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
603 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
606 #ifndef LINK_LIBGCC_SPEC
607 # ifdef LINK_LIBGCC_SPECIAL
608 /* Don't generate -L options for startfile prefix list. */
609 # define LINK_LIBGCC_SPEC ""
611 /* Do generate them. */
612 # define LINK_LIBGCC_SPEC "%D"
616 static const char *cpp_spec = CPP_SPEC;
617 static const char *cpp_predefines = CPP_PREDEFINES;
618 static const char *cc1_spec = CC1_SPEC;
619 static const char *cc1plus_spec = CC1PLUS_SPEC;
620 static const char *signed_char_spec = SIGNED_CHAR_SPEC;
621 static const char *asm_spec = ASM_SPEC;
622 static const char *asm_final_spec = ASM_FINAL_SPEC;
623 static const char *link_spec = LINK_SPEC;
624 static const char *lib_spec = LIB_SPEC;
625 static const char *libgcc_spec = LIBGCC_SPEC;
626 static const char *endfile_spec = ENDFILE_SPEC;
627 static const char *startfile_spec = STARTFILE_SPEC;
628 static const char *switches_need_spaces = SWITCHES_NEED_SPACES;
629 static const char *linker_name_spec = LINKER_NAME;
630 static const char *link_command_spec = LINK_COMMAND_SPEC;
631 static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
633 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
634 There should be no need to override these in target dependent files,
635 but we need to copy them to the specs file so that newer versions
636 of the GCC driver can correctly drive older tool chains with the
637 appropriate -B options. */
639 static const char *trad_capable_cpp =
640 "%{traditional|ftraditional|traditional-cpp:trad}cpp0";
642 static const char *cpp_options =
643 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
644 %{std*} %{nostdinc*}\
645 %{C} %{v} %{I*} %{P} %{$} %I\
646 %{MD:-M -MF %W{!o: %b.d}%W{o*:%.d%*}}\
647 %{MMD:-MM -MF %W{!o: %b.d}%W{o*:%.d%*}}\
648 %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
649 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
650 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
651 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
652 %{fno-inline|O0|!O*:-D__NO_INLINE__} %{ffast-math:-D__FAST_MATH__}\
653 %{fshort-wchar:-U__WCHAR_TYPE__ -D__WCHAR_TYPE__=short\\ unsigned\\ int}\
654 %{ffreestanding:-D__STDC_HOSTED__=0} %{fno-hosted:-D__STDC_HOSTED__=0}\
655 %{!ffreestanding:%{!fno-hosted:-D__STDC_HOSTED__=1}}\
656 %{fshow-column} %{fno-show-column}\
657 %{fleading-underscore} %{fno-leading-underscore}\
658 %{fno-operator-names} %{ftabstop=*} %{remap}\
659 %{g3:-dD} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*&U*&A*} %{i*} %Z %i\
662 /* NB: This is shared amongst all front-ends. */
663 static const char *cc1_options =
664 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
665 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
666 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*} %{ansi}\
667 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
668 %{Qn:-fno-ident} %{--help:--help}\
669 %{--target-help:--target-help}\
670 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
671 %{fsyntax-only:-o %j} %{-param*}";
673 static const char *asm_options =
674 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
676 static const char *invoke_as =
677 "%{!S:-o %{|!pipe:%g.s} |\n as %(asm_options) %{!pipe:%g.s} %A }";
679 /* Some compilers have limits on line lengths, and the multilib_select
680 and/or multilib_matches strings can be very long, so we build them at
682 static struct obstack multilib_obstack;
683 static const char *multilib_select;
684 static const char *multilib_matches;
685 static const char *multilib_defaults;
686 static const char *multilib_exclusions;
687 #include "multilib.h"
689 /* Check whether a particular argument is a default argument. */
691 #ifndef MULTILIB_DEFAULTS
692 #define MULTILIB_DEFAULTS { "" }
695 static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
699 struct user_specs *next;
700 const char *filename;
703 static struct user_specs *user_specs_head, *user_specs_tail;
705 /* This defines which switch letters take arguments. */
707 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
708 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
709 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
710 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
711 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
712 || (CHAR) == 'B' || (CHAR) == 'b')
714 #ifndef SWITCH_TAKES_ARG
715 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
718 /* This defines which multi-letter switches take arguments. */
720 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
721 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
722 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
723 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
724 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
725 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
726 || !strcmp (STR, "isystem") || !strcmp (STR, "-param") \
727 || !strcmp (STR, "specs") \
728 || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
730 #ifndef WORD_SWITCH_TAKES_ARG
731 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
734 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
735 /* This defines which switches stop a full compilation. */
736 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
737 ((CHAR) == 'c' || (CHAR) == 'S')
739 #ifndef SWITCH_CURTAILS_COMPILATION
740 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
741 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
745 /* Record the mapping from file suffixes for compilation specs. */
749 const char *suffix; /* Use this compiler for input files
750 whose names end in this suffix. */
752 const char *spec; /* To use this compiler, run this spec. */
754 const char *cpp_spec; /* If non-NULL, substitute this spec
755 for `%C', rather than the usual
759 /* Pointer to a vector of `struct compiler' that gives the spec for
760 compiling a file, based on its suffix.
761 A file that does not end in any of these suffixes will be passed
762 unchanged to the loader and nothing else will be done to it.
764 An entry containing two 0s is used to terminate the vector.
766 If multiple entries match a file, the last matching one is used. */
768 static struct compiler *compilers;
770 /* Number of entries in `compilers', not counting the null terminator. */
772 static int n_compilers;
774 /* The default list of file name suffixes and their compilation specs. */
776 static struct compiler default_compilers[] =
778 /* Add lists of suffixes of known languages here. If those languages
779 were not present when we built the driver, we will hit these copies
780 and be given a more meaningful error than "file not used since
781 linking is not done". */
782 {".m", "#Objective-C", 0}, {".mi", "#Objective-C", 0},
783 {".cc", "#C++", 0}, {".cxx", "#C++", 0}, {".cpp", "#C++", 0},
784 {".cp", "#C++", 0}, {".c++", "#C++", 0}, {".C", "#C++", 0},
786 {".ads", "#Ada", 0}, {".adb", "#Ada", 0},
787 {".f", "#Fortran", 0}, {".for", "#Fortran", 0}, {".fpp", "#Fortran", 0},
788 {".F", "#Fortran", 0}, {".FOR", "#Fortran", 0}, {".FPP", "#Fortran", 0},
789 {".r", "#Ratfor", 0},
790 {".p", "#Pascal", 0}, {".pas", "#Pascal", 0},
791 {".ch", "#Chill", 0}, {".chi", "#Chill", 0},
792 {".java", "#Java", 0}, {".class", "#Java", 0},
793 {".zip", "#Java", 0}, {".jar", "#Java", 0},
794 /* Next come the entries for C. */
797 /* cc1 has an integrated ISO C preprocessor. We should invoke the
798 external preprocessor if -save-temps or -traditional is given. */
799 "%{E|M|MM:%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)}\
801 %{save-temps:%(trad_capable_cpp) -lang-c %{ansi:-std=c89}\
802 %(cpp_options) %b.i \n\
803 cc1 -fpreprocessed %b.i %(cc1_options)}\
805 %{traditional|ftraditional|traditional-cpp:\
806 tradcpp0 -lang-c %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.i} |\n\
807 cc1 -fpreprocessed %{!pipe:%g.i} %(cc1_options)}\
808 %{!traditional:%{!ftraditional:%{!traditional-cpp:\
809 cc1 -lang-c %{ansi:-std=c89} %(cpp_options) %(cc1_options)}}}}\
810 %{!fsyntax-only:%(invoke_as)}}}}", 0},
812 "%{!E:%e-E required when input is from standard input}\
813 %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)", 0},
814 {".h", "@c-header", 0},
816 "%{!E:%eCompilation of header file requested} \
817 %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)", 0},
818 {".i", "@cpp-output", 0},
820 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0},
821 {".s", "@assembler", 0},
823 "%{!M:%{!MM:%{!E:%{!S:as %(asm_options) %i %A }}}}", 0},
824 {".S", "@assembler-with-cpp", 0},
825 {"@assembler-with-cpp",
826 "%(trad_capable_cpp) -lang-asm %(cpp_options)\
827 %{!M:%{!MM:%{!E:%(invoke_as)}}}", 0},
829 /* Mark end of table */
833 /* Number of elements in default_compilers, not counting the terminator. */
835 static int n_default_compilers
836 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
838 /* A vector of options to give to the linker.
839 These options are accumulated by %x,
840 and substituted into the linker command with %X. */
841 static int n_linker_options;
842 static char **linker_options;
844 /* A vector of options to give to the assembler.
845 These options are accumulated by -Wa,
846 and substituted into the assembler command with %Y. */
847 static int n_assembler_options;
848 static char **assembler_options;
850 /* A vector of options to give to the preprocessor.
851 These options are accumulated by -Wp,
852 and substituted into the preprocessor command with %Z. */
853 static int n_preprocessor_options;
854 static char **preprocessor_options;
856 /* Define how to map long options into short ones. */
858 /* This structure describes one mapping. */
861 /* The long option's name. */
862 const char *const name;
863 /* The equivalent short option. */
864 const char *const equivalent;
865 /* Argument info. A string of flag chars; NULL equals no options.
866 a => argument required.
867 o => argument optional.
868 j => join argument to equivalent, making one word.
869 * => require other text after NAME as an argument. */
870 const char *const arg_info;
873 /* This is the table of mappings. Mappings are tried sequentially
874 for each option encountered; the first one that matches, wins. */
876 static const struct option_map option_map[] =
878 {"--all-warnings", "-Wall", 0},
879 {"--ansi", "-ansi", 0},
880 {"--assemble", "-S", 0},
881 {"--assert", "-A", "a"},
882 {"--classpath", "-fclasspath=", "aj"},
883 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
884 {"--comments", "-C", 0},
885 {"--compile", "-c", 0},
886 {"--debug", "-g", "oj"},
887 {"--define-macro", "-D", "aj"},
888 {"--dependencies", "-M", 0},
889 {"--dump", "-d", "a"},
890 {"--dumpbase", "-dumpbase", "a"},
891 {"--entry", "-e", 0},
892 {"--extra-warnings", "-W", 0},
893 {"--for-assembler", "-Wa", "a"},
894 {"--for-linker", "-Xlinker", "a"},
895 {"--force-link", "-u", "a"},
896 {"--imacros", "-imacros", "a"},
897 {"--include", "-include", "a"},
898 {"--include-barrier", "-I-", 0},
899 {"--include-directory", "-I", "aj"},
900 {"--include-directory-after", "-idirafter", "a"},
901 {"--include-prefix", "-iprefix", "a"},
902 {"--include-with-prefix", "-iwithprefix", "a"},
903 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
904 {"--include-with-prefix-after", "-iwithprefix", "a"},
905 {"--language", "-x", "a"},
906 {"--library-directory", "-L", "a"},
907 {"--machine", "-m", "aj"},
908 {"--machine-", "-m", "*j"},
909 {"--no-line-commands", "-P", 0},
910 {"--no-precompiled-includes", "-noprecomp", 0},
911 {"--no-standard-includes", "-nostdinc", 0},
912 {"--no-standard-libraries", "-nostdlib", 0},
913 {"--no-warnings", "-w", 0},
914 {"--optimize", "-O", "oj"},
915 {"--output", "-o", "a"},
916 {"--output-class-directory", "-foutput-class-dir=", "ja"},
917 {"--param", "--param", "a"},
918 {"--pedantic", "-pedantic", 0},
919 {"--pedantic-errors", "-pedantic-errors", 0},
920 {"--pipe", "-pipe", 0},
921 {"--prefix", "-B", "a"},
922 {"--preprocess", "-E", 0},
923 {"--print-search-dirs", "-print-search-dirs", 0},
924 {"--print-file-name", "-print-file-name=", "aj"},
925 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
926 {"--print-missing-file-dependencies", "-MG", 0},
927 {"--print-multi-lib", "-print-multi-lib", 0},
928 {"--print-multi-directory", "-print-multi-directory", 0},
929 {"--print-prog-name", "-print-prog-name=", "aj"},
930 {"--profile", "-p", 0},
931 {"--profile-blocks", "-a", 0},
932 {"--quiet", "-q", 0},
933 {"--save-temps", "-save-temps", 0},
934 {"--shared", "-shared", 0},
935 {"--silent", "-q", 0},
936 {"--specs", "-specs=", "aj"},
937 {"--static", "-static", 0},
938 {"--std", "-std=", "aj"},
939 {"--symbolic", "-symbolic", 0},
940 {"--target", "-b", "a"},
941 {"--time", "-time", 0},
942 {"--trace-includes", "-H", 0},
943 {"--traditional", "-traditional", 0},
944 {"--traditional-cpp", "-traditional-cpp", 0},
945 {"--trigraphs", "-trigraphs", 0},
946 {"--undefine-macro", "-U", "aj"},
947 {"--use-version", "-V", "a"},
948 {"--user-dependencies", "-MM", 0},
949 {"--verbose", "-v", 0},
950 {"--version", "-dumpversion", 0},
951 {"--warn-", "-W", "*j"},
952 {"--write-dependencies", "-MD", 0},
953 {"--write-user-dependencies", "-MMD", 0},
958 #ifdef TARGET_OPTION_TRANSLATE_TABLE
959 static const struct {
960 const char *const option_found;
961 const char *const replacements;
962 } target_option_translations[] =
964 TARGET_OPTION_TRANSLATE_TABLE,
969 /* Translate the options described by *ARGCP and *ARGVP.
970 Make a new vector and store it back in *ARGVP,
971 and store its length in *ARGVC. */
974 translate_options (argcp, argvp)
976 const char *const **argvp;
980 const char *const *argv = *argvp;
981 int newvsize = (argc + 2) * 2 * sizeof (const char *);
983 (const char **) xmalloc (newvsize);
987 newv[newindex++] = argv[i++];
991 #ifdef TARGET_OPTION_TRANSLATE_TABLE
995 target_option_translations[tott_idx].option_found;
998 if (strcmp (target_option_translations[tott_idx].option_found,
1005 for (sp = target_option_translations[tott_idx].replacements;
1012 newvsize += spaces * sizeof (const char *);
1013 newv = (const char **) xrealloc (newv, newvsize);
1015 sp = target_option_translations[tott_idx].replacements;
1024 newv[newindex++] = np;
1025 while (*np != ' ' && *np)
1036 if (target_option_translations[tott_idx].option_found)
1040 /* Translate -- options. */
1041 if (argv[i][0] == '-' && argv[i][1] == '-')
1044 /* Find a mapping that applies to this option. */
1045 for (j = 0; j < ARRAY_SIZE (option_map); j++)
1047 size_t optlen = strlen (option_map[j].name);
1048 size_t arglen = strlen (argv[i]);
1049 size_t complen = arglen > optlen ? optlen : arglen;
1050 const char *arginfo = option_map[j].arg_info;
1055 if (!strncmp (argv[i], option_map[j].name, complen))
1057 const char *arg = 0;
1059 if (arglen < optlen)
1062 for (k = j + 1; k < ARRAY_SIZE (option_map); k++)
1063 if (strlen (option_map[k].name) >= arglen
1064 && !strncmp (argv[i], option_map[k].name, arglen))
1066 error ("Ambiguous abbreviation %s", argv[i]);
1070 if (k != ARRAY_SIZE (option_map))
1074 if (arglen > optlen)
1076 /* If the option has an argument, accept that. */
1077 if (argv[i][optlen] == '=')
1078 arg = argv[i] + optlen + 1;
1080 /* If this mapping requires extra text at end of name,
1081 accept that as "argument". */
1082 else if (strchr (arginfo, '*') != 0)
1083 arg = argv[i] + optlen;
1085 /* Otherwise, extra text at end means mismatch.
1086 Try other mappings. */
1091 else if (strchr (arginfo, '*') != 0)
1093 error ("Incomplete `%s' option", option_map[j].name);
1097 /* Handle arguments. */
1098 if (strchr (arginfo, 'a') != 0)
1104 error ("Missing argument to `%s' option",
1105 option_map[j].name);
1112 else if (strchr (arginfo, '*') != 0)
1114 else if (strchr (arginfo, 'o') == 0)
1117 error ("Extraneous argument to `%s' option",
1118 option_map[j].name);
1122 /* Store the translation as one argv elt or as two. */
1123 if (arg != 0 && strchr (arginfo, 'j') != 0)
1124 newv[newindex++] = concat (option_map[j].equivalent, arg,
1128 newv[newindex++] = option_map[j].equivalent;
1129 newv[newindex++] = arg;
1132 newv[newindex++] = option_map[j].equivalent;
1140 /* Handle old-fashioned options--just copy them through,
1141 with their arguments. */
1142 else if (argv[i][0] == '-')
1144 const char *p = argv[i] + 1;
1148 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1149 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1150 else if (WORD_SWITCH_TAKES_ARG (p))
1151 nskip += WORD_SWITCH_TAKES_ARG (p);
1152 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1155 else if (! strcmp (p, "Xlinker"))
1158 /* Watch out for an option at the end of the command line that
1159 is missing arguments, and avoid skipping past the end of the
1161 if (nskip + i > argc)
1166 newv[newindex++] = argv[i++];
1171 /* Ordinary operands, or +e options. */
1172 newv[newindex++] = argv[i++];
1187 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1188 be considered whitespace. */
1189 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1191 else if (*p == '\n' || *p == ' ' || *p == '\t')
1205 /* Structures to keep track of prefixes to try when looking for files. */
1209 const char *prefix; /* String to prepend to the path. */
1210 struct prefix_list *next; /* Next in linked list. */
1211 int require_machine_suffix; /* Don't use without machine_suffix. */
1212 /* 2 means try both machine_suffix and just_machine_suffix. */
1213 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1214 int priority; /* Sort key - priority within list */
1219 struct prefix_list *plist; /* List of prefixes to try */
1220 int max_len; /* Max length of a prefix in PLIST */
1221 const char *name; /* Name of this list (used in config stuff) */
1224 /* List of prefixes to try when looking for executables. */
1226 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1228 /* List of prefixes to try when looking for startup (crt0) files. */
1230 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1232 /* List of prefixes to try when looking for include files. */
1234 static struct path_prefix include_prefixes = { 0, 0, "include" };
1236 /* Suffix to attach to directories searched for commands.
1237 This looks like `MACHINE/VERSION/'. */
1239 static const char *machine_suffix = 0;
1241 /* Suffix to attach to directories searched for commands.
1242 This is just `MACHINE/'. */
1244 static const char *just_machine_suffix = 0;
1246 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1248 static const char *gcc_exec_prefix;
1250 /* Default prefixes to attach to command names. */
1252 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1253 #undef MD_EXEC_PREFIX
1254 #undef MD_STARTFILE_PREFIX
1255 #undef MD_STARTFILE_PREFIX_1
1258 /* If no prefixes defined, use the null string, which will disable them. */
1259 #ifndef MD_EXEC_PREFIX
1260 #define MD_EXEC_PREFIX ""
1262 #ifndef MD_STARTFILE_PREFIX
1263 #define MD_STARTFILE_PREFIX ""
1265 #ifndef MD_STARTFILE_PREFIX_1
1266 #define MD_STARTFILE_PREFIX_1 ""
1269 /* Supply defaults for the standard prefixes. */
1271 #ifndef STANDARD_EXEC_PREFIX
1272 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1274 #ifndef STANDARD_STARTFILE_PREFIX
1275 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1277 #ifndef TOOLDIR_BASE_PREFIX
1278 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1280 #ifndef STANDARD_BINDIR_PREFIX
1281 #define STANDARD_BINDIR_PREFIX "/usr/local/bin"
1284 static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1285 static const char *const standard_exec_prefix_1 = "/usr/lib/gcc/";
1286 static const char *md_exec_prefix = MD_EXEC_PREFIX;
1288 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1289 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1290 static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1291 static const char *const standard_startfile_prefix_1 = "/lib/";
1292 static const char *const standard_startfile_prefix_2 = "/usr/lib/";
1294 static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1295 static const char *tooldir_prefix;
1297 static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1299 /* Subdirectory to use for locating libraries. Set by
1300 set_multilib_dir based on the compilation options. */
1302 static const char *multilib_dir;
1304 /* Structure to keep track of the specs that have been defined so far.
1305 These are accessed using %(specname) or %[specname] in a compiler
1310 /* The following 2 fields must be first */
1311 /* to allow EXTRA_SPECS to be initialized */
1312 const char *name; /* name of the spec. */
1313 const char *ptr; /* available ptr if no static pointer */
1315 /* The following fields are not initialized */
1316 /* by EXTRA_SPECS */
1317 const char **ptr_spec; /* pointer to the spec itself. */
1318 struct spec_list *next; /* Next spec in linked list. */
1319 int name_len; /* length of the name */
1320 int alloc_p; /* whether string was allocated */
1323 #define INIT_STATIC_SPEC(NAME,PTR) \
1324 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1326 /* List of statically defined specs. */
1327 static struct spec_list static_specs[] =
1329 INIT_STATIC_SPEC ("asm", &asm_spec),
1330 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1331 INIT_STATIC_SPEC ("asm_options", &asm_options),
1332 INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1333 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1334 INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1335 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1336 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1337 INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1338 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1339 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1340 INIT_STATIC_SPEC ("link", &link_spec),
1341 INIT_STATIC_SPEC ("lib", &lib_spec),
1342 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1343 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1344 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1345 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1346 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1347 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1348 INIT_STATIC_SPEC ("version", &compiler_version),
1349 INIT_STATIC_SPEC ("multilib", &multilib_select),
1350 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1351 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1352 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1353 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1354 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1355 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1356 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1357 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1358 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1361 #ifdef EXTRA_SPECS /* additional specs needed */
1362 /* Structure to keep track of just the first two args of a spec_list.
1363 That is all that the EXTRA_SPECS macro gives us. */
1366 const char *const name;
1367 const char *const ptr;
1370 static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1371 static struct spec_list *extra_specs = (struct spec_list *) 0;
1374 /* List of dynamically allocates specs that have been defined so far. */
1376 static struct spec_list *specs = (struct spec_list *) 0;
1378 /* Add appropriate libgcc specs to OBSTACK, taking into account
1379 various permutations of -shared-libgcc, -shared, and such. */
1381 #ifdef ENABLE_SHARED_LIBGCC
1383 init_gcc_specs (obstack, shared_name, static_name)
1384 struct obstack *obstack;
1385 const char *shared_name;
1386 const char *static_name;
1390 /* If we see -shared-libgcc, then use the shared version. */
1391 sprintf (buffer, "%%{shared-libgcc:%s %s}", shared_name, static_name);
1392 obstack_grow (obstack, buffer, strlen (buffer));
1393 /* If we see -static-libgcc, then use the static version. */
1394 sprintf (buffer, "%%{static-libgcc:%s}", static_name);
1395 obstack_grow (obstack, buffer, strlen (buffer));
1396 /* Otherwise, if we see -shared, then use the shared version. */
1398 "%%{!shared-libgcc:%%{!static-libgcc:%%{shared:%s %s}}}",
1399 shared_name, static_name);
1400 obstack_grow (obstack, buffer, strlen (buffer));
1401 /* Otherwise, use the static version. */
1403 "%%{!shared-libgcc:%%{!static-libgcc:%%{!shared:%s}}}",
1405 obstack_grow (obstack, buffer, strlen (buffer));
1407 #endif /* ENABLE_SHARED_LIBGCC */
1409 /* Initialize the specs lookup routines. */
1414 struct spec_list *next = (struct spec_list *) 0;
1415 struct spec_list *sl = (struct spec_list *) 0;
1419 return; /* Already initialized. */
1422 notice ("Using builtin specs.\n");
1425 extra_specs = (struct spec_list *)
1426 xcalloc (sizeof (struct spec_list), ARRAY_SIZE (extra_specs_1));
1428 for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1430 sl = &extra_specs[i];
1431 sl->name = extra_specs_1[i].name;
1432 sl->ptr = extra_specs_1[i].ptr;
1434 sl->name_len = strlen (sl->name);
1435 sl->ptr_spec = &sl->ptr;
1440 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1442 sl = &static_specs[i];
1447 #ifdef ENABLE_SHARED_LIBGCC
1448 /* ??? If neither -shared-libgcc nor --static-libgcc was
1449 seen, then we should be making an educated guess. Some proposed
1450 heuristics for ELF include:
1452 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1453 program will be doing dynamic loading, which will likely
1454 need the shared libgcc.
1456 (2) If "-ldl", then it's also a fair bet that we're doing
1459 (3) For each ET_DYN we're linking against (either through -lfoo
1460 or /some/path/foo.so), check to see whether it or one of
1461 its dependencies depends on a shared libgcc.
1465 If the runtime is fixed to look for program headers instead
1466 of calling __register_frame_info at all, for each object,
1467 use the shared libgcc if any EH symbol referenced.
1469 If crtstuff is fixed to not invoke __register_frame_info
1470 automatically, for each object, use the shared libgcc if
1471 any non-empty unwind section found.
1473 Doing any of this probably requires invoking an external program to
1474 do the actual object file scanning. */
1476 const char *p = libgcc_spec;
1479 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1480 when given the proper command line arguments. */
1483 if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
1485 init_gcc_specs (&obstack,
1486 #ifdef NO_SHARED_LIBGCC_MULTILIB
1496 else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0)
1498 /* Ug. We don't know shared library extensions. Hope that
1499 systems that use this form don't do shared libraries. */
1500 init_gcc_specs (&obstack,
1501 #ifdef NO_SHARED_LIBGCC_MULTILIB
1513 obstack_1grow (&obstack, *p);
1514 in_sep = (*p == ' ');
1519 obstack_1grow (&obstack, '\0');
1520 libgcc_spec = obstack_finish (&obstack);
1523 #ifdef USE_AS_TRADITIONAL_FORMAT
1524 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1526 static const char tf[] = "--traditional-format ";
1527 obstack_grow (&obstack, tf, sizeof(tf) - 1);
1528 obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1529 asm_spec = obstack_finish (&obstack);
1536 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1537 removed; If the spec starts with a + then SPEC is added to the end of the
1541 set_spec (name, spec)
1545 struct spec_list *sl;
1546 const char *old_spec;
1547 int name_len = strlen (name);
1550 /* If this is the first call, initialize the statically allocated specs. */
1553 struct spec_list *next = (struct spec_list *) 0;
1554 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1556 sl = &static_specs[i];
1563 /* See if the spec already exists. */
1564 for (sl = specs; sl; sl = sl->next)
1565 if (name_len == sl->name_len && !strcmp (sl->name, name))
1570 /* Not found - make it. */
1571 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1572 sl->name = xstrdup (name);
1573 sl->name_len = name_len;
1574 sl->ptr_spec = &sl->ptr;
1576 *(sl->ptr_spec) = "";
1581 old_spec = *(sl->ptr_spec);
1582 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1583 ? concat (old_spec, spec + 1, NULL)
1588 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1591 /* Free the old spec. */
1592 if (old_spec && sl->alloc_p)
1593 free ((PTR) old_spec);
1598 /* Accumulate a command (program name and args), and run it. */
1600 /* Vector of pointers to arguments in the current line of specifications. */
1602 static const char **argbuf;
1604 /* Number of elements allocated in argbuf. */
1606 static int argbuf_length;
1608 /* Number of elements in argbuf currently in use (containing args). */
1610 static int argbuf_index;
1612 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1613 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1616 static struct temp_name {
1617 const char *suffix; /* suffix associated with the code. */
1618 int length; /* strlen (suffix). */
1619 int unique; /* Indicates whether %g or %u/%U was used. */
1620 const char *filename; /* associated filename. */
1621 int filename_length; /* strlen (filename). */
1622 struct temp_name *next;
1625 /* Number of commands executed so far. */
1627 static int execution_count;
1629 /* Number of commands that exited with a signal. */
1631 static int signal_count;
1633 /* Name with which this program was invoked. */
1635 static const char *programname;
1637 /* Clear out the vector of arguments (after a command is executed). */
1645 /* Add one argument to the vector at the end.
1646 This is done when a space is seen or at the end of the line.
1647 If DELETE_ALWAYS is nonzero, the arg is a filename
1648 and the file should be deleted eventually.
1649 If DELETE_FAILURE is nonzero, the arg is a filename
1650 and the file should be deleted if this compilation fails. */
1653 store_arg (arg, delete_always, delete_failure)
1655 int delete_always, delete_failure;
1657 if (argbuf_index + 1 == argbuf_length)
1659 = (const char **) xrealloc (argbuf,
1660 (argbuf_length *= 2) * sizeof (const char *));
1662 argbuf[argbuf_index++] = arg;
1663 argbuf[argbuf_index] = 0;
1665 if (delete_always || delete_failure)
1666 record_temp_file (arg, delete_always, delete_failure);
1669 /* Load specs from a file name named FILENAME, replacing occurrences of
1670 various different types of line-endings, \r\n, \n\r and just \r, with
1674 load_specs (filename)
1675 const char *filename;
1679 struct stat statbuf;
1686 notice ("Reading specs from %s\n", filename);
1688 /* Open and stat the file. */
1689 desc = open (filename, O_RDONLY, 0);
1691 pfatal_with_name (filename);
1692 if (stat (filename, &statbuf) < 0)
1693 pfatal_with_name (filename);
1695 /* Read contents of file into BUFFER. */
1696 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1697 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1699 pfatal_with_name (filename);
1700 buffer[readlen] = 0;
1703 specs = xmalloc (readlen + 1);
1705 for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
1711 if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
1713 else if (*(buffer_p + 1) == '\n') /* \r\n */
1727 /* Read compilation specs from a file named FILENAME,
1728 replacing the default ones.
1730 A suffix which starts with `*' is a definition for
1731 one of the machine-specific sub-specs. The "suffix" should be
1732 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1733 The corresponding spec is stored in asm_spec, etc.,
1734 rather than in the `compilers' vector.
1736 Anything invalid in the file is a fatal error. */
1739 read_specs (filename, main_p)
1740 const char *filename;
1746 buffer = load_specs (filename);
1748 /* Scan BUFFER for specs, putting them in the vector. */
1754 char *in, *out, *p1, *p2, *p3;
1756 /* Advance P in BUFFER to the next nonblank nocomment line. */
1757 p = skip_whitespace (p);
1761 /* Is this a special command that starts with '%'? */
1762 /* Don't allow this for the main specs file, since it would
1763 encourage people to overwrite it. */
1764 if (*p == '%' && !main_p)
1767 while (*p && *p != '\n')
1773 if (!strncmp (p1, "%include", sizeof ("%include") - 1)
1774 && (p1[sizeof "%include" - 1] == ' '
1775 || p1[sizeof "%include" - 1] == '\t'))
1779 p1 += sizeof ("%include");
1780 while (*p1 == ' ' || *p1 == '\t')
1783 if (*p1++ != '<' || p[-2] != '>')
1784 fatal ("specs %%include syntax malformed after %ld characters",
1785 (long) (p1 - buffer + 1));
1788 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1789 read_specs (new_filename ? new_filename : p1, FALSE);
1792 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1793 && (p1[sizeof "%include_noerr" - 1] == ' '
1794 || p1[sizeof "%include_noerr" - 1] == '\t'))
1798 p1 += sizeof "%include_noerr";
1799 while (*p1 == ' ' || *p1 == '\t')
1802 if (*p1++ != '<' || p[-2] != '>')
1803 fatal ("specs %%include syntax malformed after %ld characters",
1804 (long) (p1 - buffer + 1));
1807 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1809 read_specs (new_filename, FALSE);
1810 else if (verbose_flag)
1811 notice ("Could not find specs file %s\n", p1);
1814 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1815 && (p1[sizeof "%rename" - 1] == ' '
1816 || p1[sizeof "%rename" - 1] == '\t'))
1819 struct spec_list *sl;
1821 /* Get original name */
1822 p1 += sizeof "%rename";
1823 while (*p1 == ' ' || *p1 == '\t')
1826 if (! ISALPHA ((unsigned char) *p1))
1827 fatal ("specs %%rename syntax malformed after %ld characters",
1828 (long) (p1 - buffer));
1831 while (*p2 && !ISSPACE ((unsigned char) *p2))
1834 if (*p2 != ' ' && *p2 != '\t')
1835 fatal ("specs %%rename syntax malformed after %ld characters",
1836 (long) (p2 - buffer));
1840 while (*p2 == ' ' || *p2 == '\t')
1843 if (! ISALPHA ((unsigned char) *p2))
1844 fatal ("specs %%rename syntax malformed after %ld characters",
1845 (long) (p2 - buffer));
1847 /* Get new spec name. */
1849 while (*p3 && !ISSPACE ((unsigned char) *p3))
1853 fatal ("specs %%rename syntax malformed after %ld characters",
1854 (long) (p3 - buffer));
1857 for (sl = specs; sl; sl = sl->next)
1858 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1862 fatal ("specs %s spec was not found to be renamed", p1);
1864 if (strcmp (p1, p2) == 0)
1869 notice ("rename spec %s to %s\n", p1, p2);
1871 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1875 set_spec (p2, *(sl->ptr_spec));
1877 free ((PTR) *(sl->ptr_spec));
1879 *(sl->ptr_spec) = "";
1884 fatal ("specs unknown %% command after %ld characters",
1885 (long) (p1 - buffer));
1888 /* Find the colon that should end the suffix. */
1890 while (*p1 && *p1 != ':' && *p1 != '\n')
1893 /* The colon shouldn't be missing. */
1895 fatal ("specs file malformed after %ld characters",
1896 (long) (p1 - buffer));
1898 /* Skip back over trailing whitespace. */
1900 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1903 /* Copy the suffix to a string. */
1904 suffix = save_string (p, p2 - p);
1905 /* Find the next line. */
1906 p = skip_whitespace (p1 + 1);
1908 fatal ("specs file malformed after %ld characters",
1909 (long) (p - buffer));
1912 /* Find next blank line or end of string. */
1913 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1916 /* Specs end at the blank line and do not include the newline. */
1917 spec = save_string (p, p1 - p);
1920 /* Delete backslash-newline sequences from the spec. */
1925 if (in[0] == '\\' && in[1] == '\n')
1927 else if (in[0] == '#')
1928 while (*in && *in != '\n')
1936 if (suffix[0] == '*')
1938 if (! strcmp (suffix, "*link_command"))
1939 link_command_spec = spec;
1941 set_spec (suffix + 1, spec);
1945 /* Add this pair to the vector. */
1947 = ((struct compiler *)
1948 xrealloc (compilers,
1949 (n_compilers + 2) * sizeof (struct compiler)));
1951 compilers[n_compilers].suffix = suffix;
1952 compilers[n_compilers].spec = spec;
1954 memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
1958 link_command_spec = spec;
1961 if (link_command_spec == 0)
1962 fatal ("spec file has no spec for linking");
1965 /* Record the names of temporary files we tell compilers to write,
1966 and delete them at the end of the run. */
1968 /* This is the common prefix we use to make temp file names.
1969 It is chosen once for each run of this program.
1970 It is substituted into a spec by %g or %j.
1971 Thus, all temp file names contain this prefix.
1972 In practice, all temp file names start with this prefix.
1974 This prefix comes from the envvar TMPDIR if it is defined;
1975 otherwise, from the P_tmpdir macro if that is defined;
1976 otherwise, in /usr/tmp or /tmp;
1977 or finally the current directory if all else fails. */
1979 static const char *temp_filename;
1981 /* Length of the prefix. */
1983 static int temp_filename_length;
1985 /* Define the list of temporary files to delete. */
1990 struct temp_file *next;
1993 /* Queue of files to delete on success or failure of compilation. */
1994 static struct temp_file *always_delete_queue;
1995 /* Queue of files to delete on failure of compilation. */
1996 static struct temp_file *failure_delete_queue;
1998 /* Record FILENAME as a file to be deleted automatically.
1999 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2000 otherwise delete it in any case.
2001 FAIL_DELETE nonzero means delete it if a compilation step fails;
2002 otherwise delete it in any case. */
2005 record_temp_file (filename, always_delete, fail_delete)
2006 const char *filename;
2010 char *const name = xstrdup (filename);
2014 struct temp_file *temp;
2015 for (temp = always_delete_queue; temp; temp = temp->next)
2016 if (! strcmp (name, temp->name))
2019 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
2020 temp->next = always_delete_queue;
2022 always_delete_queue = temp;
2029 struct temp_file *temp;
2030 for (temp = failure_delete_queue; temp; temp = temp->next)
2031 if (! strcmp (name, temp->name))
2034 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
2035 temp->next = failure_delete_queue;
2037 failure_delete_queue = temp;
2043 /* Delete all the temporary files whose names we previously recorded. */
2046 delete_if_ordinary (name)
2053 printf ("Delete %s? (y or n) ", name);
2057 while ((c = getchar ()) != '\n' && c != EOF)
2060 if (i == 'y' || i == 'Y')
2062 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
2063 if (unlink (name) < 0)
2065 perror_with_name (name);
2069 delete_temp_files ()
2071 struct temp_file *temp;
2073 for (temp = always_delete_queue; temp; temp = temp->next)
2074 delete_if_ordinary (temp->name);
2075 always_delete_queue = 0;
2078 /* Delete all the files to be deleted on error. */
2081 delete_failure_queue ()
2083 struct temp_file *temp;
2085 for (temp = failure_delete_queue; temp; temp = temp->next)
2086 delete_if_ordinary (temp->name);
2090 clear_failure_queue ()
2092 failure_delete_queue = 0;
2095 /* Build a list of search directories from PATHS.
2096 PREFIX is a string to prepend to the list.
2097 If CHECK_DIR_P is non-zero we ensure the directory exists.
2098 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2099 It is also used by the --print-search-dirs flag. */
2102 build_search_list (paths, prefix, check_dir_p)
2103 struct path_prefix *paths;
2107 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
2109 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
2110 int first_time = TRUE;
2111 struct prefix_list *pprefix;
2113 obstack_grow (&collect_obstack, prefix, strlen (prefix));
2114 obstack_1grow (&collect_obstack, '=');
2116 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
2118 int len = strlen (pprefix->prefix);
2122 || is_directory (pprefix->prefix, machine_suffix, 0)))
2125 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2128 obstack_grow (&collect_obstack, pprefix->prefix, len);
2129 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
2132 if (just_machine_suffix
2133 && pprefix->require_machine_suffix == 2
2135 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
2138 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2141 obstack_grow (&collect_obstack, pprefix->prefix, len);
2142 obstack_grow (&collect_obstack, just_machine_suffix,
2146 if (! pprefix->require_machine_suffix)
2149 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2152 obstack_grow (&collect_obstack, pprefix->prefix, len);
2156 obstack_1grow (&collect_obstack, '\0');
2157 return obstack_finish (&collect_obstack);
2160 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2164 putenv_from_prefixes (paths, env_var)
2165 struct path_prefix *paths;
2166 const char *env_var;
2168 putenv (build_search_list (paths, env_var, 1));
2173 /* FIXME: the location independence code for VMS is hairier than this,
2174 and hasn't been written. */
2176 /* Split a filename into component directories. */
2179 split_directories (name, ptr_num_dirs)
2188 /* Count the number of directories. Special case MSDOS disk names as part
2189 of the initial directory. */
2191 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2192 if (name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2197 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2199 while ((ch = *p++) != '\0')
2201 if (IS_DIR_SEPARATOR (ch))
2204 while (IS_DIR_SEPARATOR (*p))
2209 dirs = (char **) xmalloc (sizeof (char *) * (num_dirs + 2));
2211 /* Now copy the directory parts. */
2214 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2215 if (name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2217 dirs[num_dirs++] = save_string (p, 3);
2220 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2223 while ((ch = *p++) != '\0')
2225 if (IS_DIR_SEPARATOR (ch))
2227 while (IS_DIR_SEPARATOR (*p))
2230 dirs[num_dirs++] = save_string (q, p - q);
2236 dirs[num_dirs++] = save_string (q, p - 1 - q);
2238 dirs[num_dirs] = NULL;
2240 *ptr_num_dirs = num_dirs;
2245 /* Release storage held by split directories. */
2248 free_split_directories (dirs)
2253 while (dirs[i] != NULL)
2256 free ((char *) dirs);
2259 /* Given three strings PROGNAME, BIN_PREFIX, PREFIX, return a string that gets
2260 to PREFIX starting with the directory portion of PROGNAME and a relative
2261 pathname of the difference between BIN_PREFIX and PREFIX.
2263 For example, if BIN_PREFIX is /alpha/beta/gamma/gcc/delta, PREFIX is
2264 /alpha/beta/gamma/omega/, and PROGNAME is /red/green/blue/gcc, then this
2265 function will return /red/green/blue/../omega.
2267 If no relative prefix can be found, return NULL. */
2270 make_relative_prefix (progname, bin_prefix, prefix)
2271 const char *progname;
2272 const char *bin_prefix;
2275 char **prog_dirs, **bin_dirs, **prefix_dirs;
2276 int prog_num, bin_num, prefix_num, std_loc_p;
2279 prog_dirs = split_directories (progname, &prog_num);
2280 bin_dirs = split_directories (bin_prefix, &bin_num);
2282 /* If there is no full pathname, try to find the program by checking in each
2283 of the directories specified in the PATH environment variable. */
2288 GET_ENV_PATH_LIST (temp, "PATH");
2291 char *startp, *endp, *nstore;
2292 size_t prefixlen = strlen (temp) + 1;
2296 nstore = (char *) alloca (prefixlen + strlen (progname) + 1);
2298 startp = endp = temp;
2301 if (*endp == PATH_SEPARATOR || *endp == 0)
2306 nstore[1] = DIR_SEPARATOR;
2311 strncpy (nstore, startp, endp - startp);
2312 if (! IS_DIR_SEPARATOR (endp[-1]))
2314 nstore[endp - startp] = DIR_SEPARATOR;
2315 nstore[endp - startp + 1] = 0;
2318 nstore[endp - startp] = 0;
2320 strcat (nstore, progname);
2321 if (! access (nstore, X_OK)
2322 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
2323 || ! access (strcat (nstore, HOST_EXECUTABLE_SUFFIX), X_OK)
2327 free_split_directories (prog_dirs);
2329 prog_dirs = split_directories (progname, &prog_num);
2335 endp = startp = endp + 1;
2343 /* Remove the program name from comparison of directory names. */
2346 /* Determine if the compiler is installed in the standard location, and if
2347 so, we don't need to specify relative directories. Also, if argv[0]
2348 doesn't contain any directory specifiers, there is not much we can do. */
2350 if (prog_num == bin_num)
2352 for (i = 0; i < bin_num; i++)
2354 if (strcmp (prog_dirs[i], bin_dirs[i]) != 0)
2358 if (prog_num <= 0 || i == bin_num)
2361 free_split_directories (prog_dirs);
2362 free_split_directories (bin_dirs);
2363 prog_dirs = bin_dirs = (char **) 0;
2368 prefix_dirs = split_directories (prefix, &prefix_num);
2370 /* Find how many directories are in common between bin_prefix & prefix. */
2371 n = (prefix_num < bin_num) ? prefix_num : bin_num;
2372 for (common = 0; common < n; common++)
2374 if (strcmp (bin_dirs[common], prefix_dirs[common]) != 0)
2378 /* If there are no common directories, there can be no relative prefix. */
2381 free_split_directories (prog_dirs);
2382 free_split_directories (bin_dirs);
2383 free_split_directories (prefix_dirs);
2387 /* Build up the pathnames in argv[0]. */
2388 for (i = 0; i < prog_num; i++)
2389 obstack_grow (&obstack, prog_dirs[i], strlen (prog_dirs[i]));
2391 /* Now build up the ..'s. */
2392 for (i = common; i < n; i++)
2394 obstack_grow (&obstack, DIR_UP, sizeof (DIR_UP) - 1);
2395 obstack_1grow (&obstack, DIR_SEPARATOR);
2398 /* Put in directories to move over to prefix. */
2399 for (i = common; i < prefix_num; i++)
2400 obstack_grow (&obstack, prefix_dirs[i], strlen (prefix_dirs[i]));
2402 free_split_directories (prog_dirs);
2403 free_split_directories (bin_dirs);
2404 free_split_directories (prefix_dirs);
2406 obstack_1grow (&obstack, '\0');
2407 return obstack_finish (&obstack);
2411 /* Check whether NAME can be accessed in MODE. This is like access,
2412 except that it never considers directories to be executable. */
2415 access_check (name, mode)
2423 if (stat (name, &st) < 0
2424 || S_ISDIR (st.st_mode))
2428 return access (name, mode);
2431 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2432 access to check permissions.
2433 Return 0 if not found, otherwise return its name, allocated with malloc. */
2436 find_a_file (pprefix, name, mode)
2437 struct path_prefix *pprefix;
2442 const char *const file_suffix =
2443 ((mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "");
2444 struct prefix_list *pl;
2445 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
2447 #ifdef DEFAULT_ASSEMBLER
2448 if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
2449 return xstrdup (DEFAULT_ASSEMBLER);
2452 #ifdef DEFAULT_LINKER
2453 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
2454 return xstrdup (DEFAULT_LINKER);
2458 len += strlen (machine_suffix);
2460 temp = xmalloc (len);
2462 /* Determine the filename to execute (special case for absolute paths). */
2464 if (IS_ABSOLUTE_PATHNAME (name))
2466 if (access (name, mode) == 0)
2468 strcpy (temp, name);
2473 for (pl = pprefix->plist; pl; pl = pl->next)
2477 /* Some systems have a suffix for executable files.
2478 So try appending that first. */
2479 if (file_suffix[0] != 0)
2481 strcpy (temp, pl->prefix);
2482 strcat (temp, machine_suffix);
2483 strcat (temp, name);
2484 strcat (temp, file_suffix);
2485 if (access_check (temp, mode) == 0)
2487 if (pl->used_flag_ptr != 0)
2488 *pl->used_flag_ptr = 1;
2493 /* Now try just the name. */
2494 strcpy (temp, pl->prefix);
2495 strcat (temp, machine_suffix);
2496 strcat (temp, name);
2497 if (access_check (temp, mode) == 0)
2499 if (pl->used_flag_ptr != 0)
2500 *pl->used_flag_ptr = 1;
2505 /* Certain prefixes are tried with just the machine type,
2506 not the version. This is used for finding as, ld, etc. */
2507 if (just_machine_suffix && pl->require_machine_suffix == 2)
2509 /* Some systems have a suffix for executable files.
2510 So try appending that first. */
2511 if (file_suffix[0] != 0)
2513 strcpy (temp, pl->prefix);
2514 strcat (temp, just_machine_suffix);
2515 strcat (temp, name);
2516 strcat (temp, file_suffix);
2517 if (access_check (temp, mode) == 0)
2519 if (pl->used_flag_ptr != 0)
2520 *pl->used_flag_ptr = 1;
2525 strcpy (temp, pl->prefix);
2526 strcat (temp, just_machine_suffix);
2527 strcat (temp, name);
2528 if (access_check (temp, mode) == 0)
2530 if (pl->used_flag_ptr != 0)
2531 *pl->used_flag_ptr = 1;
2536 /* Certain prefixes can't be used without the machine suffix
2537 when the machine or version is explicitly specified. */
2538 if (! pl->require_machine_suffix)
2540 /* Some systems have a suffix for executable files.
2541 So try appending that first. */
2542 if (file_suffix[0] != 0)
2544 strcpy (temp, pl->prefix);
2545 strcat (temp, name);
2546 strcat (temp, file_suffix);
2547 if (access_check (temp, mode) == 0)
2549 if (pl->used_flag_ptr != 0)
2550 *pl->used_flag_ptr = 1;
2555 strcpy (temp, pl->prefix);
2556 strcat (temp, name);
2557 if (access_check (temp, mode) == 0)
2559 if (pl->used_flag_ptr != 0)
2560 *pl->used_flag_ptr = 1;
2570 /* Ranking of prefixes in the sort list. -B prefixes are put before
2573 enum path_prefix_priority
2575 PREFIX_PRIORITY_B_OPT,
2576 PREFIX_PRIORITY_LAST
2579 /* Add an entry for PREFIX in PLIST. The PLIST is kept in assending
2580 order according to PRIORITY. Within each PRIORITY, new entries are
2583 If WARN is nonzero, we will warn if no file is found
2584 through this prefix. WARN should point to an int
2585 which will be set to 1 if this entry is used.
2587 COMPONENT is the value to be passed to update_path.
2589 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2590 the complete value of machine_suffix.
2591 2 means try both machine_suffix and just_machine_suffix. */
2594 add_prefix (pprefix, prefix, component, priority, require_machine_suffix, warn)
2595 struct path_prefix *pprefix;
2597 const char *component;
2598 /* enum prefix_priority */ int priority;
2599 int require_machine_suffix;
2602 struct prefix_list *pl, **prev;
2605 for (prev = &pprefix->plist;
2606 (*prev) != NULL && (*prev)->priority <= priority;
2607 prev = &(*prev)->next)
2610 /* Keep track of the longest prefix */
2612 prefix = update_path (prefix, component);
2613 len = strlen (prefix);
2614 if (len > pprefix->max_len)
2615 pprefix->max_len = len;
2617 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2618 pl->prefix = prefix;
2619 pl->require_machine_suffix = require_machine_suffix;
2620 pl->used_flag_ptr = warn;
2621 pl->priority = priority;
2625 /* Insert after PREV */
2630 /* Execute the command specified by the arguments on the current line of spec.
2631 When using pipes, this includes several piped-together commands
2632 with `|' between them.
2634 Return 0 if successful, -1 if failed. */
2640 int n_commands; /* # of command. */
2644 const char *prog; /* program name. */
2645 const char **argv; /* vector of args. */
2646 int pid; /* pid of process for this command. */
2649 struct command *commands; /* each command buffer with above info. */
2651 /* Count # of piped commands. */
2652 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2653 if (strcmp (argbuf[i], "|") == 0)
2656 /* Get storage for each command. */
2657 commands = (struct command *) alloca (n_commands * sizeof (struct command));
2659 /* Split argbuf into its separate piped processes,
2660 and record info about each one.
2661 Also search for the programs that are to be run. */
2663 commands[0].prog = argbuf[0]; /* first command. */
2664 commands[0].argv = &argbuf[0];
2665 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2668 commands[0].argv[0] = string;
2670 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2671 if (strcmp (argbuf[i], "|") == 0)
2672 { /* each command. */
2673 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2674 fatal ("-pipe not supported");
2676 argbuf[i] = 0; /* termination of command args. */
2677 commands[n_commands].prog = argbuf[i + 1];
2678 commands[n_commands].argv = &argbuf[i + 1];
2679 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2681 commands[n_commands].argv[0] = string;
2685 argbuf[argbuf_index] = 0;
2687 /* If -v, print what we are about to do, and maybe query. */
2691 /* For help listings, put a blank line between sub-processes. */
2692 if (print_help_list)
2693 fputc ('\n', stderr);
2695 /* Print each piped command as a separate line. */
2696 for (i = 0; i < n_commands; i++)
2698 const char *const *j;
2700 for (j = commands[i].argv; *j; j++)
2701 fprintf (stderr, " %s", *j);
2703 /* Print a pipe symbol after all but the last command. */
2704 if (i + 1 != n_commands)
2705 fprintf (stderr, " |");
2706 fprintf (stderr, "\n");
2710 notice ("\nGo ahead? (y or n) ");
2714 while (getchar () != '\n')
2717 if (i != 'y' && i != 'Y')
2722 /* Run each piped subprocess. */
2724 for (i = 0; i < n_commands; i++)
2726 char *errmsg_fmt, *errmsg_arg;
2727 const char *string = commands[i].argv[0];
2729 /* For some bizarre reason, the second argument of execvp() is
2730 char *const *, not const char *const *. */
2731 commands[i].pid = pexecute (string, (char *const *) commands[i].argv,
2732 programname, temp_filename,
2733 &errmsg_fmt, &errmsg_arg,
2734 ((i == 0 ? PEXECUTE_FIRST : 0)
2735 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2736 | (string == commands[i].prog
2737 ? PEXECUTE_SEARCH : 0)
2738 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2740 if (commands[i].pid == -1)
2741 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2743 if (string != commands[i].prog)
2744 free ((PTR) string);
2749 /* Wait for all the subprocesses to finish.
2750 We don't care what order they finish in;
2751 we know that N_COMMANDS waits will get them all.
2752 Ignore subprocesses that we don't know about,
2753 since they can be spawned by the process that exec'ed us. */
2757 #ifdef HAVE_GETRUSAGE
2759 double ut = 0.0, st = 0.0;
2762 for (i = 0; i < n_commands;)
2768 pid = pwait (commands[i].pid, &status, 0);
2772 #ifdef HAVE_GETRUSAGE
2775 /* getrusage returns the total resource usage of all children
2776 up to now. Copy the previous values into prus, get the
2777 current statistics, then take the difference. */
2780 getrusage (RUSAGE_CHILDREN, &rus);
2781 d.tv_sec = rus.ru_utime.tv_sec - prus.ru_utime.tv_sec;
2782 d.tv_usec = rus.ru_utime.tv_usec - prus.ru_utime.tv_usec;
2783 ut = (double) d.tv_sec + (double) d.tv_usec / 1.0e6;
2785 d.tv_sec = rus.ru_stime.tv_sec - prus.ru_stime.tv_sec;
2786 d.tv_usec = rus.ru_stime.tv_usec - prus.ru_stime.tv_usec;
2787 st = (double) d.tv_sec + (double) d.tv_usec / 1.0e6;
2791 for (j = 0; j < n_commands; j++)
2792 if (commands[j].pid == pid)
2795 if (WIFSIGNALED (status))
2798 /* SIGPIPE is a special case. It happens in -pipe mode
2799 when the compiler dies before the preprocessor is
2800 done, or the assembler dies before the compiler is
2801 done. There's generally been an error already, and
2802 this is just fallout. So don't generate another error
2803 unless we would otherwise have succeeded. */
2804 if (WTERMSIG (status) == SIGPIPE
2805 && (signal_count || greatest_status >= MIN_FATAL_STATUS))
2810 Internal error: %s (program %s)\n\
2811 Please submit a full bug report.\n\
2812 See %s for instructions.",
2813 strsignal (WTERMSIG (status)), commands[j].prog,
2818 else if (WIFEXITED (status)
2819 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2821 if (WEXITSTATUS (status) > greatest_status)
2822 greatest_status = WEXITSTATUS (status);
2825 #ifdef HAVE_GETRUSAGE
2826 if (report_times && ut + st != 0)
2827 notice ("# %s %.2f %.2f\n", commands[j].prog, ut, st);
2836 /* Find all the switches given to us
2837 and make a vector describing them.
2838 The elements of the vector are strings, one per switch given.
2839 If a switch uses following arguments, then the `part1' field
2840 is the switch itself and the `args' field
2841 is a null-terminated vector containing the following arguments.
2842 The `live_cond' field is:
2844 1 if the switch is true in a conditional spec,
2845 -1 if false (overridden by a later switch)
2846 -2 if this switch should be ignored (used in %{<S})
2847 The `validated' field is nonzero if any spec has looked at this switch;
2848 if it remains zero at the end of the run, it must be meaningless. */
2851 #define SWITCH_FALSE -1
2852 #define SWITCH_IGNORE -2
2853 #define SWITCH_LIVE 1
2860 unsigned char validated;
2861 unsigned char ordering;
2864 static struct switchstr *switches;
2866 static int n_switches;
2871 const char *language;
2874 /* Also a vector of input files specified. */
2876 static struct infile *infiles;
2880 /* This counts the number of libraries added by lang_specific_driver, so that
2881 we can tell if there were any user supplied any files or libraries. */
2883 static int added_libraries;
2885 /* And a vector of corresponding output files is made up later. */
2887 const char **outfiles;
2889 /* Used to track if none of the -B paths are used. */
2892 /* Used to track if standard path isn't used and -b or -V is specified. */
2893 static int warn_std;
2895 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2896 static int *warn_std_ptr = 0;
2898 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2900 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2901 is true if we should look for an executable suffix as well. */
2904 convert_filename (name, do_exe)
2914 len = strlen (name);
2916 #ifdef HAVE_TARGET_OBJECT_SUFFIX
2917 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
2919 && name[len - 2] == '.'
2920 && name[len - 1] == 'o')
2922 obstack_grow (&obstack, name, len - 2);
2923 obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
2924 name = obstack_finish (&obstack);
2928 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2929 /* If there is no filetype, make it the executable suffix (which includes
2930 the "."). But don't get confused if we have just "-o". */
2931 if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2934 for (i = len - 1; i >= 0; i--)
2935 if (IS_DIR_SEPARATOR (name[i]))
2938 for (i++; i < len; i++)
2942 obstack_grow (&obstack, name, len);
2943 obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
2944 strlen (TARGET_EXECUTABLE_SUFFIX));
2945 name = obstack_finish (&obstack);
2952 /* Display the command line switches accepted by gcc. */
2956 printf (_("Usage: %s [options] file...\n"), programname);
2957 fputs (_("Options:\n"), stdout);
2959 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout);
2960 fputs (_(" --help Display this information\n"), stdout);
2961 fputs (_(" --target-help Display target specific command line options\n"), stdout);
2963 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout);
2964 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout);
2965 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout);
2966 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout);
2967 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout);
2968 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout);
2969 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout);
2970 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout);
2971 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout);
2973 -print-multi-lib Display the mapping between command line options and\n\
2974 multiple library search directories\n"), stdout);
2975 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout);
2976 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout);
2977 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout);
2978 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout);
2979 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout);
2980 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout);
2981 fputs (_(" -time Time the execution of each subprocess\n"), stdout);
2982 fputs (_(" -specs=<file> Override builtin specs with the contents of <file>\n"), stdout);
2983 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout);
2984 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout);
2985 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout);
2986 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout);
2987 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout);
2988 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout);
2989 fputs (_(" -S Compile only; do not assemble or link\n"), stdout);
2990 fputs (_(" -c Compile and assemble, but do not link\n"), stdout);
2991 fputs (_(" -o <file> Place the output into <file>\n"), stdout);
2993 -x <language> Specify the language of the following input files\n\
2994 Permissable languages include: c c++ assembler none\n\
2995 'none' means revert to the default behaviour of\n\
2996 guessing the language based on the file's extension\n\
3000 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3001 passed on to the various sub-processes invoked by %s. In order to pass\n\
3002 other options on to these processes the -W<letter> options must be used.\n\
3005 /* The rest of the options are displayed by invocations of the various
3010 add_preprocessor_option (option, len)
3014 n_preprocessor_options++;
3016 if (! preprocessor_options)
3017 preprocessor_options
3018 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
3020 preprocessor_options
3021 = (char **) xrealloc (preprocessor_options,
3022 n_preprocessor_options * sizeof (char *));
3024 preprocessor_options [n_preprocessor_options - 1] =
3025 save_string (option, len);
3029 add_assembler_option (option, len)
3033 n_assembler_options++;
3035 if (! assembler_options)
3037 = (char **) xmalloc (n_assembler_options * sizeof (char *));
3040 = (char **) xrealloc (assembler_options,
3041 n_assembler_options * sizeof (char *));
3043 assembler_options [n_assembler_options - 1] = save_string (option, len);
3047 add_linker_option (option, len)
3053 if (! linker_options)
3055 = (char **) xmalloc (n_linker_options * sizeof (char *));
3058 = (char **) xrealloc (linker_options,
3059 n_linker_options * sizeof (char *));
3061 linker_options [n_linker_options - 1] = save_string (option, len);
3064 /* Create the vector `switches' and its contents.
3065 Store its length in `n_switches'. */
3068 process_command (argc, argv)
3070 const char *const *argv;
3075 const char *spec_lang = 0;
3076 int last_language_n_infiles;
3079 int lang_n_infiles = 0;
3080 #ifdef MODIFY_TARGET_NAME
3081 int is_modify_target_name;
3085 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
3089 added_libraries = 0;
3091 /* Figure compiler version from version string. */
3093 compiler_version = temp1 = xstrdup (version_string);
3095 for (; *temp1; ++temp1)
3104 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3105 see if we can create it from the pathname specified in argv[0]. */
3108 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3109 if (!gcc_exec_prefix)
3111 gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix,
3112 standard_exec_prefix);
3113 if (gcc_exec_prefix)
3114 putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
3118 if (gcc_exec_prefix)
3120 int len = strlen (gcc_exec_prefix);
3122 if (len > (int) sizeof ("/lib/gcc-lib/") - 1
3123 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
3125 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
3126 if (IS_DIR_SEPARATOR (*temp)
3127 && strncmp (temp + 1, "lib", 3) == 0
3128 && IS_DIR_SEPARATOR (temp[4])
3129 && strncmp (temp + 5, "gcc-lib", 7) == 0)
3130 len -= sizeof ("/lib/gcc-lib/") - 1;
3133 set_std_prefix (gcc_exec_prefix, len);
3134 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC",
3135 PREFIX_PRIORITY_LAST, 0, NULL);
3136 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
3137 PREFIX_PRIORITY_LAST, 0, NULL);
3140 /* COMPILER_PATH and LIBRARY_PATH have values
3141 that are lists of directory names with colons. */
3143 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
3146 const char *startp, *endp;
3147 char *nstore = (char *) alloca (strlen (temp) + 3);
3149 startp = endp = temp;
3152 if (*endp == PATH_SEPARATOR || *endp == 0)
3154 strncpy (nstore, startp, endp - startp);
3156 strcpy (nstore, concat (".", dir_separator_str, NULL));
3157 else if (!IS_DIR_SEPARATOR (endp[-1]))
3159 nstore[endp - startp] = DIR_SEPARATOR;
3160 nstore[endp - startp + 1] = 0;
3163 nstore[endp - startp] = 0;
3164 add_prefix (&exec_prefixes, nstore, 0,
3165 PREFIX_PRIORITY_LAST, 0, NULL);
3166 add_prefix (&include_prefixes,
3167 concat (nstore, "include", NULL),
3168 0, PREFIX_PRIORITY_LAST, 0, NULL);
3171 endp = startp = endp + 1;
3178 GET_ENV_PATH_LIST (temp, LIBRARY_PATH_ENV);
3179 if (temp && *cross_compile == '0')
3181 const char *startp, *endp;
3182 char *nstore = (char *) alloca (strlen (temp) + 3);
3184 startp = endp = temp;
3187 if (*endp == PATH_SEPARATOR || *endp == 0)
3189 strncpy (nstore, startp, endp - startp);
3191 strcpy (nstore, concat (".", dir_separator_str, NULL));
3192 else if (!IS_DIR_SEPARATOR (endp[-1]))
3194 nstore[endp - startp] = DIR_SEPARATOR;
3195 nstore[endp - startp + 1] = 0;
3198 nstore[endp - startp] = 0;
3199 add_prefix (&startfile_prefixes, nstore, NULL,
3200 PREFIX_PRIORITY_LAST, 0, NULL);
3203 endp = startp = endp + 1;
3210 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3211 GET_ENV_PATH_LIST (temp, "LPATH");
3212 if (temp && *cross_compile == '0')
3214 const char *startp, *endp;
3215 char *nstore = (char *) alloca (strlen (temp) + 3);
3217 startp = endp = temp;
3220 if (*endp == PATH_SEPARATOR || *endp == 0)
3222 strncpy (nstore, startp, endp - startp);
3224 strcpy (nstore, concat (".", dir_separator_str, NULL));
3225 else if (!IS_DIR_SEPARATOR (endp[-1]))
3227 nstore[endp - startp] = DIR_SEPARATOR;
3228 nstore[endp - startp + 1] = 0;
3231 nstore[endp - startp] = 0;
3232 add_prefix (&startfile_prefixes, nstore, NULL,
3233 PREFIX_PRIORITY_LAST, 0, NULL);
3236 endp = startp = endp + 1;
3243 /* Convert new-style -- options to old-style. */
3244 translate_options (&argc, &argv);
3246 /* Do language-specific adjustment/addition of flags. */
3247 lang_specific_driver (&argc, &argv, &added_libraries);
3249 /* Scan argv twice. Here, the first time, just count how many switches
3250 there will be in their vector, and how many input files in theirs.
3251 Also parse any switches that determine the configuration name, such as -b.
3252 Here we also parse the switches that cc itself uses (e.g. -v). */
3254 for (i = 1; i < argc; i++)
3256 if (! strcmp (argv[i], "-dumpspecs"))
3258 struct spec_list *sl;
3260 for (sl = specs; sl; sl = sl->next)
3261 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
3262 if (link_command_spec)
3263 printf ("*link_command:\n%s\n\n", link_command_spec);
3266 else if (! strcmp (argv[i], "-dumpversion"))
3268 printf ("%s\n", spec_version);
3271 else if (! strcmp (argv[i], "-dumpmachine"))
3273 printf ("%s\n", spec_machine);
3276 else if (strcmp (argv[i], "-fhelp") == 0)
3278 /* translate_options () has turned --help into -fhelp. */
3279 print_help_list = 1;
3281 /* We will be passing a dummy file on to the sub-processes. */
3285 add_preprocessor_option ("--help", 6);
3286 add_assembler_option ("--help", 6);
3287 add_linker_option ("--help", 6);
3289 else if (strcmp (argv[i], "-ftarget-help") == 0)
3291 /* translate_options() has turned --target-help into -ftarget-help. */
3292 target_help_flag = 1;
3294 /* We will be passing a dummy file on to the sub-processes. */
3298 add_preprocessor_option ("--target-help", 13);
3299 add_assembler_option ("--target-help", 13);
3300 add_linker_option ("--target-help", 13);
3302 else if (! strcmp (argv[i], "-pass-exit-codes"))
3304 pass_exit_codes = 1;
3307 else if (! strcmp (argv[i], "-print-search-dirs"))
3308 print_search_dirs = 1;
3309 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3310 print_file_name = "libgcc.a";
3311 else if (! strncmp (argv[i], "-print-file-name=", 17))
3312 print_file_name = argv[i] + 17;
3313 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3314 print_prog_name = argv[i] + 17;
3315 else if (! strcmp (argv[i], "-print-multi-lib"))
3316 print_multi_lib = 1;
3317 else if (! strcmp (argv[i], "-print-multi-directory"))
3318 print_multi_directory = 1;
3319 else if (! strncmp (argv[i], "-Wa,", 4))
3322 /* Pass the rest of this option to the assembler. */
3324 /* Split the argument at commas. */
3326 for (j = 4; argv[i][j]; j++)
3327 if (argv[i][j] == ',')
3329 add_assembler_option (argv[i] + prev, j - prev);
3333 /* Record the part after the last comma. */
3334 add_assembler_option (argv[i] + prev, j - prev);
3336 else if (! strncmp (argv[i], "-Wp,", 4))
3339 /* Pass the rest of this option to the preprocessor. */
3341 /* Split the argument at commas. */
3343 for (j = 4; argv[i][j]; j++)
3344 if (argv[i][j] == ',')
3346 add_preprocessor_option (argv[i] + prev, j - prev);
3350 /* Record the part after the last comma. */
3351 add_preprocessor_option (argv[i] + prev, j - prev);
3353 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3354 /* The +e options to the C++ front-end. */
3356 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3359 /* Split the argument at commas. */
3360 for (j = 3; argv[i][j]; j++)
3361 n_infiles += (argv[i][j] == ',');
3363 else if (strcmp (argv[i], "-Xlinker") == 0)
3366 fatal ("argument to `-Xlinker' is missing");
3371 else if (strcmp (argv[i], "-l") == 0)
3374 fatal ("argument to `-l' is missing");
3379 else if (strncmp (argv[i], "-l", 2) == 0)
3381 else if (strcmp (argv[i], "-save-temps") == 0)
3383 save_temps_flag = 1;
3386 else if (strcmp (argv[i], "-specs") == 0)
3388 struct user_specs *user = (struct user_specs *)
3389 xmalloc (sizeof (struct user_specs));
3391 fatal ("argument to `-specs' is missing");
3393 user->next = (struct user_specs *) 0;
3394 user->filename = argv[i];
3395 if (user_specs_tail)
3396 user_specs_tail->next = user;
3398 user_specs_head = user;
3399 user_specs_tail = user;
3401 else if (strncmp (argv[i], "-specs=", 7) == 0)
3403 struct user_specs *user = (struct user_specs *)
3404 xmalloc (sizeof (struct user_specs));
3405 if (strlen (argv[i]) == 7)
3406 fatal ("argument to `-specs=' is missing");
3408 user->next = (struct user_specs *) 0;
3409 user->filename = argv[i] + 7;
3410 if (user_specs_tail)
3411 user_specs_tail->next = user;
3413 user_specs_head = user;
3414 user_specs_tail = user;
3416 else if (strcmp (argv[i], "-time") == 0)
3418 else if (argv[i][0] == '-' && argv[i][1] != 0)
3420 const char *p = &argv[i][1];
3427 if (p[1] == 0 && i + 1 == argc)
3428 fatal ("argument to `-b' is missing");
3430 spec_machine = argv[++i];
3432 spec_machine = p + 1;
3434 warn_std_ptr = &warn_std;
3442 if (p[1] == 0 && i + 1 == argc)
3443 fatal ("argument to `-B' is missing");
3449 len = strlen (value);
3451 /* Catch the case where the user has forgotten to append a
3452 directory separator to the path. Note, they may be using
3453 -B to add an executable name prefix, eg "i386-elf-", in
3454 order to distinguish between multiple installations of
3455 GCC in the same directory. Hence we must check to see
3456 if appending a directory separator actually makes a
3457 valid directory name. */
3458 if (! IS_DIR_SEPARATOR (value [len - 1])
3459 && is_directory (value, "", 0))
3461 char *tmp = xmalloc (len + 2);
3462 strcpy (tmp, value);
3463 tmp[len] = DIR_SEPARATOR;
3468 /* As a kludge, if the arg is "[foo/]stageN/", just
3469 add "[foo/]include" to the include prefix. */
3472 && (IS_DIR_SEPARATOR (value[len - 8]))))
3473 && strncmp (value + len - 7, "stage", 5) == 0
3474 && ISDIGIT (value[len - 2])
3475 && (IS_DIR_SEPARATOR (value[len - 1])))
3478 add_prefix (&include_prefixes, "include", NULL,
3479 PREFIX_PRIORITY_B_OPT, 0, NULL);
3482 char * string = xmalloc (len + 1);
3484 strncpy (string, value, len - 7);
3485 strcpy (string + len - 7, "include");
3486 add_prefix (&include_prefixes, string, NULL,
3487 PREFIX_PRIORITY_B_OPT, 0, NULL);
3491 add_prefix (&exec_prefixes, value, NULL,
3492 PREFIX_PRIORITY_B_OPT, 0, &warn_B);
3493 add_prefix (&startfile_prefixes, value, NULL,
3494 PREFIX_PRIORITY_B_OPT, 0, &warn_B);
3495 add_prefix (&include_prefixes, concat (value, "include", NULL),
3496 NULL, PREFIX_PRIORITY_B_OPT, 0, NULL);
3501 case 'v': /* Print our subcommands and print versions. */
3503 /* If they do anything other than exactly `-v', don't set
3504 verbose_flag; rather, continue on to give the error. */
3512 if (p[1] == 0 && i + 1 == argc)
3513 fatal ("argument to `-V' is missing");
3515 spec_version = argv[++i];
3517 spec_version = p + 1;
3518 compiler_version = spec_version;
3519 warn_std_ptr = &warn_std;
3521 /* Validate the version number. Use the same checks
3522 done when inserting it into a spec.
3524 The format of the version string is
3525 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3527 const char *v = compiler_version;
3529 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3530 while (! ISDIGIT (*v))
3533 if (v > compiler_version && v[-1] != '-')
3534 fatal ("invalid version number format");
3536 /* Set V after the first period. */
3537 while (ISDIGIT (*v))
3541 fatal ("invalid version number format");
3544 while (ISDIGIT (*v))
3547 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
3548 fatal ("invalid version number format");
3564 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3569 /* Forward scan, just in case -S or -c is specified
3576 if (argv[j][0] == '-')
3578 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3584 else if ((skip = SWITCH_TAKES_ARG (argv[j][1])))
3585 j += skip - (argv[j][2] != 0);
3586 else if ((skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1)))
3593 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
3595 argv[i + 1] = convert_filename (argv[i + 1], ! have_c);
3597 argv[i] = convert_filename (argv[i], ! have_c);
3604 #ifdef MODIFY_TARGET_NAME
3605 is_modify_target_name = 0;
3608 j < sizeof modify_target / sizeof modify_target[0]; j++)
3609 if (! strcmp (argv[i], modify_target[j].sw))
3612 = (char *) xmalloc (strlen (modify_target[j].str)
3613 + strlen (spec_machine));
3616 int made_addition = 0;
3618 is_modify_target_name = 1;
3619 for (p = spec_machine, q = new_name; *p != 0; )
3621 if (modify_target[j].add_del == DELETE
3622 && (! strncmp (q, modify_target[j].str,
3623 strlen (modify_target[j].str))))
3624 p += strlen (modify_target[j].str);
3625 else if (modify_target[j].add_del == ADD
3626 && ! made_addition && *p == '-')
3628 for (r = modify_target[j].str; *r != 0; )
3636 spec_machine = new_name;
3639 if (is_modify_target_name)
3645 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3646 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3647 else if (WORD_SWITCH_TAKES_ARG (p))
3648 i += WORD_SWITCH_TAKES_ARG (p);
3658 if (have_c && have_o && lang_n_infiles > 1)
3659 fatal ("cannot specify -o with -c or -S and multiple compilations");
3661 /* Set up the search paths before we go looking for config files. */
3663 /* These come before the md prefixes so that we will find gcc's subcommands
3664 (such as cpp) rather than those of the host system. */
3665 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3666 as well as trying the machine and the version. */
3668 add_prefix (&exec_prefixes, standard_exec_prefix, "GCC",
3669 PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
3670 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3671 PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
3672 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3673 PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
3676 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3677 PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
3678 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3679 PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
3681 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3682 dir_separator_str, NULL);
3684 /* If tooldir is relative, base it on exec_prefixes. A relative
3685 tooldir lets us move the installed tree as a unit.
3687 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3688 directories, so that we can search both the user specified directory
3689 and the standard place. */
3691 if (!IS_ABSOLUTE_PATHNAME (tooldir_prefix))
3693 if (gcc_exec_prefix)
3695 char *gcc_exec_tooldir_prefix
3696 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3697 spec_version, dir_separator_str, tooldir_prefix, NULL);
3699 add_prefix (&exec_prefixes,
3700 concat (gcc_exec_tooldir_prefix, "bin",
3701 dir_separator_str, NULL),
3702 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
3703 add_prefix (&startfile_prefixes,
3704 concat (gcc_exec_tooldir_prefix, "lib",
3705 dir_separator_str, NULL),
3706 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
3709 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3710 dir_separator_str, spec_version,
3711 dir_separator_str, tooldir_prefix, NULL);
3714 add_prefix (&exec_prefixes,
3715 concat (tooldir_prefix, "bin", dir_separator_str, NULL),
3716 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
3717 add_prefix (&startfile_prefixes,
3718 concat (tooldir_prefix, "lib", dir_separator_str, NULL),
3719 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
3721 /* More prefixes are enabled in main, after we read the specs file
3722 and determine whether this is cross-compilation or not. */
3724 /* Then create the space for the vectors and scan again. */
3726 switches = ((struct switchstr *)
3727 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3728 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3731 last_language_n_infiles = -1;
3733 /* This, time, copy the text of each switch and store a pointer
3734 to the copy in the vector of switches.
3735 Store all the infiles in their vector. */
3737 for (i = 1; i < argc; i++)
3739 /* Just skip the switches that were handled by the preceding loop. */
3740 #ifdef MODIFY_TARGET_NAME
3741 is_modify_target_name = 0;
3743 for (j = 0; j < sizeof modify_target / sizeof modify_target[0]; j++)
3744 if (! strcmp (argv[i], modify_target[j].sw))
3745 is_modify_target_name = 1;
3747 if (is_modify_target_name)
3751 if (! strncmp (argv[i], "-Wa,", 4))
3753 else if (! strncmp (argv[i], "-Wp,", 4))
3755 else if (! strcmp (argv[i], "-pass-exit-codes"))
3757 else if (! strcmp (argv[i], "-print-search-dirs"))
3759 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3761 else if (! strncmp (argv[i], "-print-file-name=", 17))
3763 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3765 else if (! strcmp (argv[i], "-print-multi-lib"))
3767 else if (! strcmp (argv[i], "-print-multi-directory"))
3769 else if (strcmp (argv[i], "-ftarget-help") == 0)
3771 /* Create a dummy input file, so that we can pass --target-help on to
3772 the various sub-processes. */
3773 infiles[n_infiles].language = "c";
3774 infiles[n_infiles++].name = "target-dummy";
3776 /* Preserve the --target-help switch so that it can be caught by
3777 the cc1 spec string. */
3778 switches[n_switches].part1 = "--target-help";
3779 switches[n_switches].args = 0;
3780 switches[n_switches].live_cond = SWITCH_OK;
3781 switches[n_switches].validated = 0;
3785 else if (strcmp (argv[i], "-fhelp") == 0)
3789 /* Create a dummy input file, so that we can pass --help on to
3790 the various sub-processes. */
3791 infiles[n_infiles].language = "c";
3792 infiles[n_infiles++].name = "help-dummy";
3794 /* Preserve the --help switch so that it can be caught by the
3796 switches[n_switches].part1 = "--help";
3797 switches[n_switches].args = 0;
3798 switches[n_switches].live_cond = SWITCH_OK;
3799 switches[n_switches].validated = 0;
3804 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3806 /* Compensate for the +e options to the C++ front-end;
3807 they're there simply for cfront call-compatibility. We do
3808 some magic in default_compilers to pass them down properly.
3809 Note we deliberately start at the `+' here, to avoid passing
3810 -e0 or -e1 down into the linker. */
3811 switches[n_switches].part1 = &argv[i][0];
3812 switches[n_switches].args = 0;
3813 switches[n_switches].live_cond = SWITCH_OK;
3814 switches[n_switches].validated = 0;
3817 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3820 /* Split the argument at commas. */
3822 for (j = 4; argv[i][j]; j++)
3823 if (argv[i][j] == ',')
3825 infiles[n_infiles].language = "*";
3826 infiles[n_infiles++].name
3827 = save_string (argv[i] + prev, j - prev);
3830 /* Record the part after the last comma. */
3831 infiles[n_infiles].language = "*";
3832 infiles[n_infiles++].name = argv[i] + prev;
3834 else if (strcmp (argv[i], "-Xlinker") == 0)
3836 infiles[n_infiles].language = "*";
3837 infiles[n_infiles++].name = argv[++i];
3839 else if (strcmp (argv[i], "-l") == 0)
3840 { /* POSIX allows separation of -l and the lib arg;
3841 canonicalize by concatenating -l with its arg */
3842 infiles[n_infiles].language = "*";
3843 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
3845 else if (strncmp (argv[i], "-l", 2) == 0)
3847 infiles[n_infiles].language = "*";
3848 infiles[n_infiles++].name = argv[i];
3850 else if (strcmp (argv[i], "-specs") == 0)
3852 else if (strncmp (argv[i], "-specs=", 7) == 0)
3854 else if (strcmp (argv[i], "-time") == 0)
3856 else if ((save_temps_flag || report_times)
3857 && strcmp (argv[i], "-pipe") == 0)
3859 /* -save-temps overrides -pipe, so that temp files are produced */
3860 if (save_temps_flag)
3861 error ("Warning: -pipe ignored because -save-temps specified");
3862 /* -time overrides -pipe because we can't get correct stats when
3863 multiple children are running at once. */
3864 else if (report_times)
3865 error ("Warning: -pipe ignored because -time specified");
3867 else if (argv[i][0] == '-' && argv[i][1] != 0)
3869 const char *p = &argv[i][1];
3874 if (p[1] == 0 && i + 1 == argc)
3875 fatal ("argument to `-x' is missing");
3877 spec_lang = argv[++i];
3880 if (! strcmp (spec_lang, "none"))
3881 /* Suppress the warning if -xnone comes after the last input
3882 file, because alternate command interfaces like g++ might
3883 find it useful to place -xnone after each input file. */
3886 last_language_n_infiles = n_infiles;
3889 switches[n_switches].part1 = p;
3890 /* Deal with option arguments in separate argv elements. */
3891 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
3892 || WORD_SWITCH_TAKES_ARG (p))
3895 int n_args = WORD_SWITCH_TAKES_ARG (p);
3899 /* Count only the option arguments in separate argv elements. */
3900 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
3902 if (i + n_args >= argc)
3903 fatal ("argument to `-%s' is missing", p);
3904 switches[n_switches].args
3905 = (const char **) xmalloc ((n_args + 1) * sizeof(const char *));
3907 switches[n_switches].args[j++] = argv[++i];
3908 /* Null-terminate the vector. */
3909 switches[n_switches].args[j] = 0;
3911 else if (strchr (switches_need_spaces, c))
3913 /* On some systems, ld cannot handle some options without
3914 a space. So split the option from its argument. */
3915 char *part1 = (char *) xmalloc (2);
3919 switches[n_switches].part1 = part1;
3920 switches[n_switches].args
3921 = (const char **) xmalloc (2 * sizeof (const char *));
3922 switches[n_switches].args[0] = xstrdup (p+1);
3923 switches[n_switches].args[1] = 0;
3926 switches[n_switches].args = 0;
3928 switches[n_switches].live_cond = SWITCH_OK;
3929 switches[n_switches].validated = 0;
3930 switches[n_switches].ordering = 0;
3931 /* These are always valid, since gcc.c itself understands it. */
3932 if (!strcmp (p, "save-temps")
3933 || !strcmp (p, "static-libgcc")
3934 || !strcmp (p, "shared-libgcc"))
3935 switches[n_switches].validated = 1;
3938 char ch = switches[n_switches].part1[0];
3939 if (ch == 'V' || ch == 'b' || ch == 'B')
3940 switches[n_switches].validated = 1;
3946 #ifdef HAVE_TARGET_OBJECT_SUFFIX
3947 argv[i] = convert_filename (argv[i], 0);
3950 if (strcmp (argv[i], "-") != 0 && access (argv[i], F_OK) < 0)
3952 perror_with_name (argv[i]);
3957 infiles[n_infiles].language = spec_lang;
3958 infiles[n_infiles++].name = argv[i];
3963 if (n_infiles == last_language_n_infiles && spec_lang != 0)
3964 error ("Warning: `-x %s' after last input file has no effect", spec_lang);
3966 switches[n_switches].part1 = 0;
3967 infiles[n_infiles].name = 0;
3970 /* Process a spec string, accumulating and running commands. */
3972 /* These variables describe the input file name.
3973 input_file_number is the index on outfiles of this file,
3974 so that the output file name can be stored for later use by %o.
3975 input_basename is the start of the part of the input file
3976 sans all directory names, and basename_length is the number
3977 of characters starting there excluding the suffix .c or whatever. */
3979 const char *input_filename;
3980 static int input_file_number;
3981 size_t input_filename_length;
3982 static int basename_length;
3983 static int suffixed_basename_length;
3984 static const char *input_basename;
3985 static const char *input_suffix;
3987 /* The compiler used to process the current input file. */
3988 static struct compiler *input_file_compiler;
3990 /* These are variables used within do_spec and do_spec_1. */
3992 /* Nonzero if an arg has been started and not yet terminated
3993 (with space, tab or newline). */
3994 static int arg_going;
3996 /* Nonzero means %d or %g has been seen; the next arg to be terminated
3997 is a temporary file name. */
3998 static int delete_this_arg;
4000 /* Nonzero means %w has been seen; the next arg to be terminated
4001 is the output file name of this compilation. */
4002 static int this_is_output_file;
4004 /* Nonzero means %s has been seen; the next arg to be terminated
4005 is the name of a library file and we should try the standard
4006 search dirs for it. */
4007 static int this_is_library_file;
4009 /* Nonzero means that the input of this command is coming from a pipe. */
4010 static int input_from_pipe;
4012 /* Nonnull means substitute this for any suffix when outputting a switches
4014 static const char *suffix_subst;
4016 /* Process the spec SPEC and run the commands specified therein.
4017 Returns 0 if the spec is successfully processed; -1 if failed. */
4027 delete_this_arg = 0;
4028 this_is_output_file = 0;
4029 this_is_library_file = 0;
4030 input_from_pipe = 0;
4031 suffix_subst = NULL;
4033 value = do_spec_1 (spec, 0, NULL);
4035 /* Force out any unfinished command.
4036 If -pipe, this forces out the last command if it ended in `|'. */
4039 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
4042 if (argbuf_index > 0)
4049 /* Process the sub-spec SPEC as a portion of a larger spec.
4050 This is like processing a whole spec except that we do
4051 not initialize at the beginning and we do not supply a
4052 newline by default at the end.
4053 INSWITCH nonzero means don't process %-sequences in SPEC;
4054 in this case, % is treated as an ordinary character.
4055 This is used while substituting switches.
4056 INSWITCH nonzero also causes SPC not to terminate an argument.
4058 Value is zero unless a line was finished
4059 and the command on that line reported an error. */
4062 do_spec_1 (spec, inswitch, soft_matched_part)
4065 const char *soft_matched_part;
4067 const char *p = spec;
4074 /* If substituting a switch, treat all chars like letters.
4075 Otherwise, NL, SPC, TAB and % are special. */
4076 switch (inswitch ? 'a' : c)
4079 /* End of line: finish any pending argument,
4080 then run the pending command if one has been started. */
4083 obstack_1grow (&obstack, 0);
4084 string = obstack_finish (&obstack);
4085 if (this_is_library_file)
4086 string = find_file (string);
4087 store_arg (string, delete_this_arg, this_is_output_file);
4088 if (this_is_output_file)
4089 outfiles[input_file_number] = string;
4093 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
4095 for (i = 0; i < n_switches; i++)
4096 if (!strcmp (switches[i].part1, "pipe"))
4099 /* A `|' before the newline means use a pipe here,
4100 but only if -pipe was specified.
4101 Otherwise, execute now and don't pass the `|' as an arg. */
4104 input_from_pipe = 1;
4105 switches[i].validated = 1;
4112 if (argbuf_index > 0)
4118 /* Reinitialize for a new command, and for a new argument. */
4121 delete_this_arg = 0;
4122 this_is_output_file = 0;
4123 this_is_library_file = 0;
4124 input_from_pipe = 0;
4128 /* End any pending argument. */
4131 obstack_1grow (&obstack, 0);
4132 string = obstack_finish (&obstack);
4133 if (this_is_library_file)
4134 string = find_file (string);
4135 store_arg (string, delete_this_arg, this_is_output_file);
4136 if (this_is_output_file)
4137 outfiles[input_file_number] = string;
4141 obstack_1grow (&obstack, c);
4147 /* Space or tab ends an argument if one is pending. */
4150 obstack_1grow (&obstack, 0);
4151 string = obstack_finish (&obstack);
4152 if (this_is_library_file)
4153 string = find_file (string);
4154 store_arg (string, delete_this_arg, this_is_output_file);
4155 if (this_is_output_file)
4156 outfiles[input_file_number] = string;
4158 /* Reinitialize for a new argument. */
4160 delete_this_arg = 0;
4161 this_is_output_file = 0;
4162 this_is_library_file = 0;
4169 fatal ("Invalid specification! Bug in cc.");
4172 obstack_grow (&obstack, input_basename, basename_length);
4177 obstack_grow (&obstack, input_basename, suffixed_basename_length);
4182 delete_this_arg = 2;
4185 /* Dump out the directories specified with LIBRARY_PATH,
4186 followed by the absolute directories
4187 that we search for startfiles. */
4190 struct prefix_list *pl = startfile_prefixes.plist;
4191 size_t bufsize = 100;
4192 char *buffer = (char *) xmalloc (bufsize);
4195 for (; pl; pl = pl->next)
4197 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4198 /* Used on systems which record the specified -L dirs
4199 and use them to search for dynamic linking. */
4200 /* Relative directories always come from -B,
4201 and it is better not to use them for searching
4202 at run time. In particular, stage1 loses. */
4203 if (!IS_ABSOLUTE_PATHNAME (pl->prefix))
4206 /* Try subdirectory if there is one. */
4207 if (multilib_dir != NULL)
4211 if (strlen (pl->prefix) + strlen (machine_suffix)
4213 bufsize = (strlen (pl->prefix)
4214 + strlen (machine_suffix)) * 2 + 1;
4215 buffer = (char *) xrealloc (buffer, bufsize);
4216 strcpy (buffer, pl->prefix);
4217 strcat (buffer, machine_suffix);
4218 if (is_directory (buffer, multilib_dir, 1))
4220 do_spec_1 ("-L", 0, NULL);
4221 #ifdef SPACE_AFTER_L_OPTION
4222 do_spec_1 (" ", 0, NULL);
4224 do_spec_1 (buffer, 1, NULL);
4225 do_spec_1 (multilib_dir, 1, NULL);
4226 /* Make this a separate argument. */
4227 do_spec_1 (" ", 0, NULL);
4230 if (!pl->require_machine_suffix)
4232 if (is_directory (pl->prefix, multilib_dir, 1))
4234 do_spec_1 ("-L", 0, NULL);
4235 #ifdef SPACE_AFTER_L_OPTION
4236 do_spec_1 (" ", 0, NULL);
4238 do_spec_1 (pl->prefix, 1, NULL);
4239 do_spec_1 (multilib_dir, 1, NULL);
4240 /* Make this a separate argument. */
4241 do_spec_1 (" ", 0, NULL);
4247 if (is_directory (pl->prefix, machine_suffix, 1))
4249 do_spec_1 ("-L", 0, NULL);
4250 #ifdef SPACE_AFTER_L_OPTION
4251 do_spec_1 (" ", 0, NULL);
4253 do_spec_1 (pl->prefix, 1, NULL);
4254 /* Remove slash from machine_suffix. */
4255 if (strlen (machine_suffix) >= bufsize)
4256 bufsize = strlen (machine_suffix) * 2 + 1;
4257 buffer = (char *) xrealloc (buffer, bufsize);
4258 strcpy (buffer, machine_suffix);
4259 idx = strlen (buffer);
4260 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
4261 buffer[idx - 1] = 0;
4262 do_spec_1 (buffer, 1, NULL);
4263 /* Make this a separate argument. */
4264 do_spec_1 (" ", 0, NULL);
4267 if (!pl->require_machine_suffix)
4269 if (is_directory (pl->prefix, "", 1))
4271 do_spec_1 ("-L", 0, NULL);
4272 #ifdef SPACE_AFTER_L_OPTION
4273 do_spec_1 (" ", 0, NULL);
4275 /* Remove slash from pl->prefix. */
4276 if (strlen (pl->prefix) >= bufsize)
4277 bufsize = strlen (pl->prefix) * 2 + 1;
4278 buffer = (char *) xrealloc (buffer, bufsize);
4279 strcpy (buffer, pl->prefix);
4280 idx = strlen (buffer);
4281 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
4282 buffer[idx - 1] = 0;
4283 do_spec_1 (buffer, 1, NULL);
4284 /* Make this a separate argument. */
4285 do_spec_1 (" ", 0, NULL);
4294 /* %efoo means report an error with `foo' as error message
4295 and don't execute any more commands for this file. */
4299 while (*p != 0 && *p != '\n')
4301 buf = (char *) alloca (p - q + 1);
4302 strncpy (buf, q, p - q);
4309 /* %nfoo means report an notice with `foo' on stderr. */
4313 while (*p != 0 && *p != '\n')
4315 buf = (char *) alloca (p - q + 1);
4316 strncpy (buf, q, p - q);
4318 notice ("%s\n", buf);
4328 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is defined,
4329 and it is not a directory, and it is writable, use it.
4330 Otherwise, fall through and treat this like any other
4333 if ((!save_temps_flag)
4334 && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
4335 && (access (HOST_BIT_BUCKET, W_OK) == 0))
4337 obstack_grow (&obstack, HOST_BIT_BUCKET,
4338 strlen (HOST_BIT_BUCKET));
4339 delete_this_arg = 0;
4347 if (save_temps_flag)
4349 obstack_grow (&obstack, input_basename, basename_length);
4350 delete_this_arg = 0;
4354 struct temp_name *t;
4356 const char *suffix = p;
4357 char *saved_suffix = NULL;
4359 while (*p == '.' || ISALPHA ((unsigned char) *p))
4361 suffix_length = p - suffix;
4362 if (p[0] == '%' && p[1] == 'O')
4365 /* We don't support extra suffix characters after %O. */
4366 if (*p == '.' || ISALPHA ((unsigned char) *p))
4368 if (suffix_length == 0)
4369 suffix = TARGET_OBJECT_SUFFIX;
4373 = (char *) xmalloc (suffix_length
4374 + strlen (TARGET_OBJECT_SUFFIX));
4375 strncpy (saved_suffix, suffix, suffix_length);
4376 strcpy (saved_suffix + suffix_length,
4377 TARGET_OBJECT_SUFFIX);
4379 suffix_length += strlen (TARGET_OBJECT_SUFFIX);
4382 /* See if we already have an association of %g/%u/%U and
4384 for (t = temp_names; t; t = t->next)
4385 if (t->length == suffix_length
4386 && strncmp (t->suffix, suffix, suffix_length) == 0
4387 && t->unique == (c != 'g'))
4390 /* Make a new association if needed. %u and %j
4392 if (t == 0 || c == 'u' || c == 'j')
4396 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
4397 t->next = temp_names;
4400 t->length = suffix_length;
4403 t->suffix = saved_suffix;
4404 saved_suffix = NULL;
4407 t->suffix = save_string (suffix, suffix_length);
4408 t->unique = (c != 'g');
4409 temp_filename = make_temp_file (t->suffix);
4410 temp_filename_length = strlen (temp_filename);
4411 t->filename = temp_filename;
4412 t->filename_length = temp_filename_length;
4416 free (saved_suffix);
4418 obstack_grow (&obstack, t->filename, t->filename_length);
4419 delete_this_arg = 1;
4425 obstack_grow (&obstack, input_filename, input_filename_length);
4431 struct prefix_list *pl = include_prefixes.plist;
4433 if (gcc_exec_prefix)
4435 do_spec_1 ("-iprefix", 1, NULL);
4436 /* Make this a separate argument. */
4437 do_spec_1 (" ", 0, NULL);
4438 do_spec_1 (gcc_exec_prefix, 1, NULL);
4439 do_spec_1 (" ", 0, NULL);
4442 for (; pl; pl = pl->next)
4444 do_spec_1 ("-isystem", 1, NULL);
4445 /* Make this a separate argument. */
4446 do_spec_1 (" ", 0, NULL);
4447 do_spec_1 (pl->prefix, 1, NULL);
4448 do_spec_1 (" ", 0, NULL);
4455 int max = n_infiles;
4456 max += lang_specific_extra_outfiles;
4458 for (i = 0; i < max; i++)
4460 store_arg (outfiles[i], 0, 0);
4465 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
4470 this_is_library_file = 1;
4474 this_is_output_file = 1;
4479 int cur_index = argbuf_index;
4480 /* Handle the {...} following the %W. */
4483 p = handle_braces (p + 1);
4486 /* If any args were output, mark the last one for deletion
4488 if (argbuf_index != cur_index)
4489 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
4493 /* %x{OPTION} records OPTION for %X to output. */
4499 /* Skip past the option value and make a copy. */
4504 string = save_string (p1 + 1, p - p1 - 2);
4506 /* See if we already recorded this option. */
4507 for (i = 0; i < n_linker_options; i++)
4508 if (! strcmp (string, linker_options[i]))
4514 /* This option is new; add it. */
4515 add_linker_option (string, strlen (string));
4519 /* Dump out the options accumulated previously using %x. */
4521 for (i = 0; i < n_linker_options; i++)
4523 do_spec_1 (linker_options[i], 1, NULL);
4524 /* Make each accumulated option a separate argument. */
4525 do_spec_1 (" ", 0, NULL);
4529 /* Dump out the options accumulated previously using -Wa,. */
4531 for (i = 0; i < n_assembler_options; i++)
4533 do_spec_1 (assembler_options[i], 1, NULL);
4534 /* Make each accumulated option a separate argument. */
4535 do_spec_1 (" ", 0, NULL);
4539 /* Dump out the options accumulated previously using -Wp,. */
4541 for (i = 0; i < n_preprocessor_options; i++)
4543 do_spec_1 (preprocessor_options[i], 1, NULL);
4544 /* Make each accumulated option a separate argument. */
4545 do_spec_1 (" ", 0, NULL);
4549 /* Here are digits and numbers that just process
4550 a certain constant string as a spec. */
4553 value = do_spec_1 (cc1_spec, 0, NULL);
4559 value = do_spec_1 (cc1plus_spec, 0, NULL);
4565 value = do_spec_1 (asm_spec, 0, NULL);
4571 value = do_spec_1 (asm_final_spec, 0, NULL);
4577 value = do_spec_1 (signed_char_spec, 0, NULL);
4584 const char *const spec
4585 = (input_file_compiler->cpp_spec
4586 ? input_file_compiler->cpp_spec
4588 value = do_spec_1 (spec, 0, NULL);
4595 value = do_spec_1 (endfile_spec, 0, NULL);
4601 value = do_spec_1 (link_spec, 0, NULL);
4607 value = do_spec_1 (lib_spec, 0, NULL);
4613 value = do_spec_1 (libgcc_spec, 0, NULL);
4619 if (multilib_dir && strcmp (multilib_dir, ".") != 0)
4625 len = strlen (multilib_dir);
4626 obstack_blank (&obstack, len + 1);
4627 p = obstack_next_free (&obstack) - (len + 1);
4630 for (q = multilib_dir; *q ; ++q, ++p)
4631 *p = (IS_DIR_SEPARATOR (*q) ? '_' : *q);
4637 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
4641 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4645 if (! strncmp (y, "-D", 2))
4646 /* Copy the whole option. */
4647 while (*y && *y != ' ' && *y != '\t')
4649 else if (*y == ' ' || *y == '\t')
4650 /* Copy whitespace to the result. */
4652 /* Don't copy other options. */
4659 value = do_spec_1 (buf, 0, NULL);
4667 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
4671 /* Copy all of CPP_PREDEFINES into BUF,
4672 but force them all into the reserved name space if they
4673 aren't already there. The reserved name space is all
4674 identifiers beginning with two underscores or with one
4675 underscore and a capital letter. We do the forcing by
4676 adding up to two underscores to the beginning and end
4677 of each symbol. e.g. mips, _mips, mips_, and _mips_ all
4682 if (! strncmp (y, "-D", 2))
4691 && ! ISUPPER ((unsigned char) *(y + 1))))
4693 /* Stick __ at front of macro name. */
4697 /* Arrange to stick __ at the end as well. */
4701 /* Copy the macro name. */
4702 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4715 /* Copy the value given, if any. */
4716 while (*y && *y != ' ' && *y != '\t')
4719 else if (*y == ' ' || *y == '\t')
4720 /* Copy whitespace to the result. */
4722 /* Don't copy -A options */
4728 /* Copy all of CPP_PREDEFINES into BUF,
4729 but put __ after every -D. */
4733 if (! strncmp (y, "-D", 2))
4739 && ! ISUPPER ((unsigned char) *(y + 1))))
4741 /* Stick -D__ at front of macro name. */
4748 /* Copy the macro name. */
4749 while (*y && *y != '=' && *y != ' ' && *y != '\t')
4752 /* Copy the value given, if any. */
4753 while (*y && *y != ' ' && *y != '\t')
4758 /* Do not copy this macro - we have just done it before */
4759 while (*y && *y != ' ' && *y != '\t')
4763 else if (*y == ' ' || *y == '\t')
4764 /* Copy whitespace to the result. */
4766 /* Don't copy -A options. */
4772 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4776 if (! strncmp (y, "-A", 2))
4777 /* Copy the whole option. */
4778 while (*y && *y != ' ' && *y != '\t')
4780 else if (*y == ' ' || *y == '\t')
4781 /* Copy whitespace to the result. */
4783 /* Don't copy other options. */
4790 value = do_spec_1 (buf, 0, NULL);
4797 value = do_spec_1 (startfile_spec, 0, NULL);
4802 /* Here we define characters other than letters and digits. */
4805 p = handle_braces (p);
4811 obstack_1grow (&obstack, '%');
4818 while (p[len] && p[len] != ' ' && p[len] != '%')
4820 suffix_subst = save_string (p - 1, len + 1);
4826 if (soft_matched_part)
4828 do_spec_1 (soft_matched_part, 1, NULL);
4829 do_spec_1 (" ", 0, NULL);
4832 /* Catch the case where a spec string contains something like
4833 '%{foo:%*}'. ie there is no * in the pattern on the left
4834 hand side of the :. */
4835 error ("Spec failure: '%%*' has not been initialised by pattern match");
4838 /* Process a string found as the value of a spec given by name.
4839 This feature allows individual machine descriptions
4840 to add and use their own specs.
4841 %[...] modifies -D options the way %P does;
4842 %(...) uses the spec unmodified. */
4844 error ("Warning: use of obsolete %%[ operator in specs");
4847 const char *name = p;
4848 struct spec_list *sl;
4851 /* The string after the S/P is the name of a spec that is to be
4853 while (*p && *p != ')' && *p != ']')
4856 /* See if it's in the list. */
4857 for (len = p - name, sl = specs; sl; sl = sl->next)
4858 if (sl->name_len == len && !strncmp (sl->name, name, len))
4860 name = *(sl->ptr_spec);
4862 notice ("Processing spec %c%s%c, which is '%s'\n",
4863 c, sl->name, (c == '(') ? ')' : ']', name);
4872 value = do_spec_1 (name, 0, NULL);
4878 char *x = (char *) alloca (strlen (name) * 2 + 1);
4880 const char *y = name;
4883 /* Copy all of NAME into BUF, but put __ after
4884 every -D and at the end of each arg. */
4887 if (! strncmp (y, "-D", 2))
4898 && (*y == ' ' || *y == '\t' || *y == '='
4899 || *y == '}' || *y == 0))
4912 value = do_spec_1 (buf, 0, NULL);
4918 /* Discard the closing paren or bracket. */
4926 int c1 = *p++; /* Select first or second version number. */
4927 const char *v = compiler_version;
4929 static const char zeroc = '0';
4931 /* The format of the version string is
4932 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4934 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4935 while (! ISDIGIT (*v))
4937 if (v > compiler_version && v[-1] != '-')
4940 /* If desired, advance to second version number. */
4943 /* Set V after the first period. */
4944 while (ISDIGIT (*v))
4951 /* If desired, advance to third version number.
4952 But don't complain if it's not present */
4955 /* Set V after the second period. */
4956 while (ISDIGIT (*v))
4958 if ((*v != 0) && (*v != ' ') && (*v != '.') && (*v != '-'))
4964 /* Set Q at the next period or at the end. */
4966 while (ISDIGIT (*q))
4968 if (*q != 0 && q > v && *q != ' ' && *q != '.' && *q != '-')
4972 /* Put that part into the command. */
4973 obstack_grow (&obstack, v, q - v);
4975 /* Default to "0" */
4976 obstack_grow (&obstack, &zeroc, 1);
4982 if (input_from_pipe)
4983 do_spec_1 ("-", 0, NULL);
4987 error ("Spec failure: Unrecognised spec option '%c'", c);
4993 /* Backslash: treat next character as ordinary. */
4998 /* Ordinary character: put it into the current argument. */
4999 obstack_1grow (&obstack, c);
5003 /* End of string. */
5007 /* Return 0 if we call do_spec_1 and that returns -1. */
5013 const char *filter, *body = NULL, *endbody = NULL;
5015 int true_once = 0; /* If, in %{a|b:d}, at least one of a,b was seen. */
5018 int include_blanks = 1;
5019 int elide_switch = 0;
5024 /* A '^' after the open-brace means to not give blanks before args. */
5031 /* A `|' after the open-brace means,
5032 if the test fails, output a single minus sign rather than nothing.
5033 This is used in %{|!pipe:...}. */
5040 /* A `<' after the open-brace means that the switch should be
5041 removed from the command-line. */
5047 negate = suffix = 0;
5050 /* A `!' after the open-brace negates the condition:
5051 succeed if the specified switch is not present. */
5055 /* A `.' after the open-brace means test against the current suffix. */
5064 if (elide_switch && (negate || pipe_p || suffix))
5066 /* It doesn't make sense to mix elision with other flags. We
5067 could fatal() here, but the standard seems to be to abort. */
5073 while (*p != ':' && *p != '}' && *p != '|' && *p != '&')
5076 if (*p == '|' && (pipe_p || ordered))
5081 if (*p != '}' && *p != '&')
5097 fatal ("Mismatched braces in specs");
5103 body = p, endbody = p + 1;
5108 int found = (input_suffix != 0
5109 && (long) strlen (input_suffix) == (long) (p - filter)
5110 && strncmp (input_suffix, filter, p - filter) == 0);
5116 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL) < 0)
5119 else if (p[-1] == '*' && (p[0] == '}' || p[0] == '&'))
5121 /* Substitute all matching switches as separate args. */
5124 for (i = 0; i < n_switches; i++)
5125 if (!strncmp (switches[i].part1, filter, p - 1 - filter)
5126 && check_live_switch (i, p - 1 - filter))
5130 switches[i].live_cond = SWITCH_IGNORE;
5131 switches[i].validated = 1;
5134 ordered = 1, switches[i].ordering = 1;
5139 /* Test for presence of the specified switch. */
5143 /* If name specified ends in *, as in {x*:...},
5144 check for %* and handle that case. */
5145 if (p[-1] == '*' && !negate)
5148 const char *r = body;
5150 /* First see whether we have %*. */
5154 if (*r == '%' && r[1] == '*')
5158 /* If we do, handle that case. */
5161 /* Substitute all matching switches as separate args.
5162 But do this by substituting for %*
5163 in the text that follows the colon. */
5165 unsigned hard_match_len = p - filter - 1;
5166 char *string = save_string (body, endbody - body - 1);
5168 for (i = 0; i < n_switches; i++)
5169 if (!strncmp (switches[i].part1, filter, hard_match_len)
5170 && check_live_switch (i, -1))
5172 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
5173 /* Pass any arguments this switch has. */
5174 give_switch (i, 1, 1);
5175 suffix_subst = NULL;
5178 /* We didn't match. Try again. */
5185 /* If name specified ends in *, as in {x*:...},
5186 check for presence of any switch name starting with x. */
5189 for (i = 0; i < n_switches; i++)
5191 unsigned hard_match_len = p - filter - 1;
5193 if (!strncmp (switches[i].part1, filter, hard_match_len)
5194 && check_live_switch (i, hard_match_len))
5201 /* Otherwise, check for presence of exact name specified. */
5204 for (i = 0; i < n_switches; i++)
5206 if (!strncmp (switches[i].part1, filter, p - filter)
5207 && switches[i].part1[p - filter] == 0
5208 && check_live_switch (i, -1))
5216 /* If it is as desired (present for %{s...}, absent for %{!s...})
5217 then substitute either the switch or the specified
5218 conditional text. */
5219 if (present != negate)
5223 switches[i].live_cond = SWITCH_IGNORE;
5224 switches[i].validated = 1;
5226 else if (ordered || *p == '&')
5227 ordered = 1, switches[i].ordering = 1;
5229 give_switch (i, 0, include_blanks);
5231 /* Even if many alternatives are matched, only output once. */
5236 /* Here if a %{|...} conditional fails: output a minus sign,
5237 which means "standard output" or "standard input". */
5238 do_spec_1 ("-", 0, NULL);
5243 /* We didn't match; try again. */
5250 goto next_ampersand;
5256 /* Doing this set of switches later preserves their command-line
5257 ordering. This is needed for e.g. -U, -D and -A. */
5258 for (i = 0; i < n_switches; i++)
5259 if (switches[i].ordering == 1)
5261 switches[i].ordering = 0;
5262 give_switch (i, 0, include_blanks);
5265 /* Process the spec just once, regardless of match count. */
5268 if (do_spec_1 (save_string (body, endbody - body - 1),
5276 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
5277 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
5278 spec, or -1 if either exact match or %* is used.
5280 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
5281 whose value does not begin with "no-" is obsoleted by the same value
5282 with the "no-", similarly for a switch with the "no-" prefix. */
5285 check_live_switch (switchnum, prefix_length)
5289 const char *name = switches[switchnum].part1;
5292 /* In the common case of {<at-most-one-letter>*}, a negating
5293 switch would always match, so ignore that case. We will just
5294 send the conflicting switches to the compiler phase. */
5295 if (prefix_length >= 0 && prefix_length <= 1)
5298 /* If we already processed this switch and determined if it was
5299 live or not, return our past determination. */
5300 if (switches[switchnum].live_cond != 0)
5301 return switches[switchnum].live_cond > 0;
5303 /* Now search for duplicate in a manner that depends on the name. */
5307 for (i = switchnum + 1; i < n_switches; i++)
5308 if (switches[i].part1[0] == 'O')
5310 switches[switchnum].validated = 1;
5311 switches[switchnum].live_cond = SWITCH_FALSE;
5316 case 'W': case 'f': case 'm':
5317 if (! strncmp (name + 1, "no-", 3))
5319 /* We have Xno-YYY, search for XYYY. */
5320 for (i = switchnum + 1; i < n_switches; i++)
5321 if (switches[i].part1[0] == name[0]
5322 && ! strcmp (&switches[i].part1[1], &name[4]))
5324 switches[switchnum].validated = 1;
5325 switches[switchnum].live_cond = SWITCH_FALSE;
5331 /* We have XYYY, search for Xno-YYY. */
5332 for (i = switchnum + 1; i < n_switches; i++)
5333 if (switches[i].part1[0] == name[0]
5334 && switches[i].part1[1] == 'n'
5335 && switches[i].part1[2] == 'o'
5336 && switches[i].part1[3] == '-'
5337 && !strcmp (&switches[i].part1[4], &name[1]))
5339 switches[switchnum].validated = 1;
5340 switches[switchnum].live_cond = SWITCH_FALSE;
5347 /* Otherwise the switch is live. */
5348 switches[switchnum].live_cond = SWITCH_LIVE;
5352 /* Pass a switch to the current accumulating command
5353 in the same form that we received it.
5354 SWITCHNUM identifies the switch; it is an index into
5355 the vector of switches gcc received, which is `switches'.
5356 This cannot fail since it never finishes a command line.
5358 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
5360 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
5364 give_switch (switchnum, omit_first_word, include_blanks)
5366 int omit_first_word;
5369 if (switches[switchnum].live_cond == SWITCH_IGNORE)
5372 if (!omit_first_word)
5374 do_spec_1 ("-", 0, NULL);
5375 do_spec_1 (switches[switchnum].part1, 1, NULL);
5378 if (switches[switchnum].args != 0)
5381 for (p = switches[switchnum].args; *p; p++)
5383 const char *arg = *p;
5386 do_spec_1 (" ", 0, NULL);
5389 unsigned length = strlen (arg);
5392 while (length-- && !IS_DIR_SEPARATOR (arg[length]))
5393 if (arg[length] == '.')
5395 ((char *)arg)[length] = 0;
5399 do_spec_1 (arg, 1, NULL);
5401 ((char *)arg)[length] = '.';
5402 do_spec_1 (suffix_subst, 1, NULL);
5405 do_spec_1 (arg, 1, NULL);
5409 do_spec_1 (" ", 0, NULL);
5410 switches[switchnum].validated = 1;
5413 /* Search for a file named NAME trying various prefixes including the
5414 user's -B prefix and some standard ones.
5415 Return the absolute file name found. If nothing is found, return NAME. */
5423 /* Try multilib_dir if it is defined. */
5424 if (multilib_dir != NULL)
5426 const char *const try = ACONCAT ((multilib_dir, dir_separator_str, name, NULL));
5428 newname = find_a_file (&startfile_prefixes, try, R_OK);
5430 /* If we don't find it in the multi library dir, then fall
5431 through and look for it in the normal places. */
5432 if (newname != NULL)
5436 newname = find_a_file (&startfile_prefixes, name, R_OK);
5437 return newname ? newname : name;
5440 /* Determine whether a directory exists. If LINKER, return 0 for
5441 certain fixed names not needed by the linker. If not LINKER, it is
5442 only important to return 0 if the host machine has a small ARG_MAX
5446 is_directory (path1, path2, linker)
5451 int len1 = strlen (path1);
5452 int len2 = strlen (path2);
5453 char *path = (char *) alloca (3 + len1 + len2);
5457 #ifndef SMALL_ARG_MAX
5462 /* Construct the path from the two parts. Ensure the string ends with "/.".
5463 The resulting path will be a directory even if the given path is a
5465 memcpy (path, path1, len1);
5466 memcpy (path + len1, path2, len2);
5467 cp = path + len1 + len2;
5468 if (!IS_DIR_SEPARATOR (cp[-1]))
5469 *cp++ = DIR_SEPARATOR;
5473 /* Exclude directories that the linker is known to search. */
5476 && strcmp (path, concat (dir_separator_str, "lib",
5477 dir_separator_str, ".", NULL)) == 0)
5479 && strcmp (path, concat (dir_separator_str, "usr",
5480 dir_separator_str, "lib",
5481 dir_separator_str, ".", NULL)) == 0)))
5484 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
5487 /* Set up the various global variables to indicate that we're processing
5488 the input file named FILENAME. */
5491 set_input (filename)
5492 const char *filename;
5496 input_filename = filename;
5497 input_filename_length = strlen (input_filename);
5499 input_basename = input_filename;
5500 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5501 /* Skip drive name so 'x:foo' is handled properly. */
5502 if (input_basename[1] == ':')
5503 input_basename += 2;
5505 for (p = input_basename; *p; p++)
5506 if (IS_DIR_SEPARATOR (*p))
5507 input_basename = p + 1;
5509 /* Find a suffix starting with the last period,
5510 and set basename_length to exclude that suffix. */
5511 basename_length = strlen (input_basename);
5512 suffixed_basename_length = basename_length;
5513 p = input_basename + basename_length;
5514 while (p != input_basename && *p != '.')
5516 if (*p == '.' && p != input_basename)
5518 basename_length = p - input_basename;
5519 input_suffix = p + 1;
5525 /* On fatal signals, delete all the temporary files. */
5528 fatal_error (signum)
5531 signal (signum, SIG_DFL);
5532 delete_failure_queue ();
5533 delete_temp_files ();
5534 /* Get the same signal again, this time not handled,
5535 so its normal effect occurs. */
5536 kill (getpid (), signum);
5539 extern int main PARAMS ((int, const char *const *));
5544 const char *const *argv;
5548 int linker_was_run = 0;
5549 char *explicit_link_files;
5552 struct user_specs *uptr;
5554 p = argv[0] + strlen (argv[0]);
5555 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
5559 xmalloc_set_program_name (programname);
5561 #ifdef GCC_DRIVER_HOST_INITIALIZATION
5562 /* Perform host dependent initialization when needed. */
5563 GCC_DRIVER_HOST_INITIALIZATION;
5566 gcc_init_libintl ();
5568 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
5569 signal (SIGINT, fatal_error);
5571 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
5572 signal (SIGHUP, fatal_error);
5574 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
5575 signal (SIGTERM, fatal_error);
5577 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
5578 signal (SIGPIPE, fatal_error);
5581 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
5582 receive the signal. A different setting is inheritable */
5583 signal (SIGCHLD, SIG_DFL);
5587 argbuf = (const char **) xmalloc (argbuf_length * sizeof (const char *));
5589 obstack_init (&obstack);
5591 /* Build multilib_select, et. al from the separate lines that make up each
5592 multilib selection. */
5594 const char *const *q = multilib_raw;
5597 obstack_init (&multilib_obstack);
5598 while ((p = *q++) != (char *) 0)
5599 obstack_grow (&multilib_obstack, p, strlen (p));
5601 obstack_1grow (&multilib_obstack, 0);
5602 multilib_select = obstack_finish (&multilib_obstack);
5604 q = multilib_matches_raw;
5605 while ((p = *q++) != (char *) 0)
5606 obstack_grow (&multilib_obstack, p, strlen (p));
5608 obstack_1grow (&multilib_obstack, 0);
5609 multilib_matches = obstack_finish (&multilib_obstack);
5611 q = multilib_exclusions_raw;
5612 while ((p = *q++) != (char *) 0)
5613 obstack_grow (&multilib_obstack, p, strlen (p));
5615 obstack_1grow (&multilib_obstack, 0);
5616 multilib_exclusions = obstack_finish (&multilib_obstack);
5619 for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
5622 obstack_1grow (&multilib_obstack, ' ');
5623 obstack_grow (&multilib_obstack,
5624 multilib_defaults_raw[i],
5625 strlen (multilib_defaults_raw[i]));
5629 obstack_1grow (&multilib_obstack, 0);
5630 multilib_defaults = obstack_finish (&multilib_obstack);
5633 /* Set up to remember the pathname of gcc and any options
5634 needed for collect. We use argv[0] instead of programname because
5635 we need the complete pathname. */
5636 obstack_init (&collect_obstack);
5637 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
5638 obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
5639 putenv (obstack_finish (&collect_obstack));
5641 #ifdef INIT_ENVIRONMENT
5642 /* Set up any other necessary machine specific environment variables. */
5643 putenv (INIT_ENVIRONMENT);
5646 /* Make a table of what switches there are (switches, n_switches).
5647 Make a table of specified input files (infiles, n_infiles).
5648 Decode switches that are handled locally. */
5650 process_command (argc, argv);
5655 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
5657 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
5658 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
5661 for (i = 0; (int) i < n_switches; i++)
5663 const char *const *args;
5666 obstack_grow (&collect_obstack, " ", 1);
5669 obstack_grow (&collect_obstack, "'-", 2);
5670 q = switches[i].part1;
5671 while ((p = strchr (q, '\'')))
5673 obstack_grow (&collect_obstack, q, p - q);
5674 obstack_grow (&collect_obstack, "'\\''", 4);
5677 obstack_grow (&collect_obstack, q, strlen (q));
5678 obstack_grow (&collect_obstack, "'", 1);
5680 for (args = switches[i].args; args && *args; args++)
5682 obstack_grow (&collect_obstack, " '", 2);
5684 while ((p = strchr (q, '\'')))
5686 obstack_grow (&collect_obstack, q, p - q);
5687 obstack_grow (&collect_obstack, "'\\''", 4);
5690 obstack_grow (&collect_obstack, q, strlen (q));
5691 obstack_grow (&collect_obstack, "'", 1);
5694 obstack_grow (&collect_obstack, "\0", 1);
5695 putenv (obstack_finish (&collect_obstack));
5698 /* Initialize the vector of specs to just the default.
5699 This means one element containing 0s, as a terminator. */
5701 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
5702 memcpy ((char *) compilers, (char *) default_compilers,
5703 sizeof default_compilers);
5704 n_compilers = n_default_compilers;
5706 /* Read specs from a file if there is one. */
5708 machine_suffix = concat (spec_machine, dir_separator_str,
5709 spec_version, dir_separator_str, NULL);
5710 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
5712 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
5713 /* Read the specs file unless it is a default one. */
5714 if (specs_file != 0 && strcmp (specs_file, "specs"))
5715 read_specs (specs_file, TRUE);
5719 /* We need to check standard_exec_prefix/just_machine_suffix/specs
5720 for any override of as, ld and libraries. */
5721 specs_file = (char *) alloca (strlen (standard_exec_prefix)
5722 + strlen (just_machine_suffix)
5723 + sizeof ("specs"));
5725 strcpy (specs_file, standard_exec_prefix);
5726 strcat (specs_file, just_machine_suffix);
5727 strcat (specs_file, "specs");
5728 if (access (specs_file, R_OK) == 0)
5729 read_specs (specs_file, TRUE);
5731 /* If not cross-compiling, look for startfiles in the standard places. */
5732 if (*cross_compile == '0')
5734 if (*md_exec_prefix)
5736 add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
5737 PREFIX_PRIORITY_LAST, 0, NULL);
5738 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC",
5739 PREFIX_PRIORITY_LAST, 0, NULL);
5742 if (*md_startfile_prefix)
5743 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
5744 PREFIX_PRIORITY_LAST, 0, NULL);
5746 if (*md_startfile_prefix_1)
5747 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
5748 PREFIX_PRIORITY_LAST, 0, NULL);
5750 /* If standard_startfile_prefix is relative, base it on
5751 standard_exec_prefix. This lets us move the installed tree
5752 as a unit. If GCC_EXEC_PREFIX is defined, base
5753 standard_startfile_prefix on that as well. */
5754 if (IS_ABSOLUTE_PATHNAME (standard_startfile_prefix))
5755 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
5756 PREFIX_PRIORITY_LAST, 0, NULL);
5759 if (gcc_exec_prefix)
5760 add_prefix (&startfile_prefixes,
5761 concat (gcc_exec_prefix, machine_suffix,
5762 standard_startfile_prefix, NULL),
5763 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
5764 add_prefix (&startfile_prefixes,
5765 concat (standard_exec_prefix,
5767 standard_startfile_prefix, NULL),
5768 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
5771 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
5772 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
5773 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
5774 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
5775 #if 0 /* Can cause surprises, and one can use -B./ instead. */
5776 add_prefix (&startfile_prefixes, "./", NULL,
5777 PREFIX_PRIORITY_LAST, 1, NULL);
5782 if (!IS_ABSOLUTE_PATHNAME (standard_startfile_prefix)
5784 add_prefix (&startfile_prefixes,
5785 concat (gcc_exec_prefix, machine_suffix,
5786 standard_startfile_prefix, NULL),
5787 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
5790 /* Process any user specified specs in the order given on the command
5792 for (uptr = user_specs_head; uptr; uptr = uptr->next)
5794 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
5795 read_specs (filename ? filename : uptr->filename, FALSE);
5798 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
5799 if (gcc_exec_prefix)
5800 gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
5801 spec_version, dir_separator_str, NULL);
5803 /* Now we have the specs.
5804 Set the `valid' bits for switches that match anything in any spec. */
5806 validate_all_switches ();
5808 /* Now that we have the switches and the specs, set
5809 the subdirectory based on the options. */
5810 set_multilib_dir ();
5812 /* Warn about any switches that no pass was interested in. */
5814 for (i = 0; (int) i < n_switches; i++)
5815 if (! switches[i].validated)
5816 error ("unrecognized option `-%s'", switches[i].part1);
5818 /* Obey some of the options. */
5820 if (print_search_dirs)
5822 printf (_("install: %s%s\n"), standard_exec_prefix, machine_suffix);
5823 printf (_("programs: %s\n"), build_search_list (&exec_prefixes, "", 0));
5824 printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes, "", 0));
5828 if (print_file_name)
5830 printf ("%s\n", find_file (print_file_name));
5834 if (print_prog_name)
5836 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
5837 printf ("%s\n", (newname ? newname : print_prog_name));
5841 if (print_multi_lib)
5843 print_multilib_info ();
5847 if (print_multi_directory)
5849 if (multilib_dir == NULL)
5852 printf ("%s\n", multilib_dir);
5856 if (target_help_flag)
5858 /* Print if any target specific options.*/
5860 /* We do not exit here. Instead we have created a fake input file
5861 called 'target-dummy' which needs to be compiled, and we pass this
5862 on to the various sub-processes, along with the --target-help
5866 if (print_help_list)
5872 printf (_("\nFor bug reporting instructions, please see:\n"));
5873 printf ("%s.\n", GCCBUGURL);
5878 /* We do not exit here. Instead we have created a fake input file
5879 called 'help-dummy' which needs to be compiled, and we pass this
5880 on the various sub-processes, along with the --help switch. */
5888 notice ("Configured with: %s\n", configuration_arguments);
5890 #ifdef THREAD_MODEL_SPEC
5891 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
5892 but there's no point in doing all this processing just to get
5893 thread_model back. */
5894 obstack_init (&obstack);
5895 do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
5896 obstack_1grow (&obstack, '\0');
5897 thrmod = obstack_finish (&obstack);
5899 thrmod = thread_model;
5902 notice ("Thread model: %s\n", thrmod);
5904 /* compiler_version is truncated at the first space when initialized
5905 from version string, so truncate version_string at the first space
5906 before comparing. */
5907 for (n = 0; version_string[n]; n++)
5908 if (version_string[n] == ' ')
5911 if (! strncmp (version_string, compiler_version, n)
5912 && compiler_version[n] == 0)
5913 notice ("gcc version %s\n", version_string);
5915 notice ("gcc driver version %s executing gcc version %s\n",
5916 version_string, compiler_version);
5922 if (n_infiles == added_libraries)
5923 fatal ("No input files");
5925 /* Make a place to record the compiler output file names
5926 that correspond to the input files. */
5929 i += lang_specific_extra_outfiles;
5930 outfiles = (const char **) xcalloc (i, sizeof (char *));
5932 /* Record which files were specified explicitly as link input. */
5934 explicit_link_files = xcalloc (1, n_infiles);
5936 for (i = 0; (int) i < n_infiles; i++)
5938 int this_file_error = 0;
5940 /* Tell do_spec what to substitute for %i. */
5942 input_file_number = i;
5943 set_input (infiles[i].name);
5945 /* Use the same thing in %o, unless cp->spec says otherwise. */
5947 outfiles[i] = input_filename;
5949 /* Figure out which compiler from the file's suffix. */
5952 = lookup_compiler (infiles[i].name, input_filename_length,
5953 infiles[i].language);
5955 if (input_file_compiler)
5957 /* Ok, we found an applicable compiler. Run its spec. */
5959 if (input_file_compiler->spec[0] == '#')
5961 error ("%s: %s compiler not installed on this system",
5962 input_filename, &input_file_compiler->spec[1]);
5963 this_file_error = 1;
5967 value = do_spec (input_file_compiler->spec);
5969 this_file_error = 1;
5973 /* If this file's name does not contain a recognized suffix,
5974 record it as explicit linker input. */
5977 explicit_link_files[i] = 1;
5979 /* Clear the delete-on-failure queue, deleting the files in it
5980 if this compilation failed. */
5982 if (this_file_error)
5984 delete_failure_queue ();
5987 /* If this compilation succeeded, don't delete those files later. */
5988 clear_failure_queue ();
5991 /* Reset the output file name to the first input file name, for use
5992 with %b in LINK_SPEC on a target that prefers not to emit a.out
5995 set_input (infiles[0].name);
5997 if (error_count == 0)
5999 /* Make sure INPUT_FILE_NUMBER points to first available open
6001 input_file_number = n_infiles;
6002 if (lang_specific_pre_link ())
6006 /* Run ld to link all the compiler output files. */
6008 if (error_count == 0)
6010 int tmp = execution_count;
6012 /* We'll use ld if we can't find collect2. */
6013 if (! strcmp (linker_name_spec, "collect2"))
6015 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
6017 linker_name_spec = "ld";
6019 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
6021 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
6022 putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
6024 value = do_spec (link_command_spec);
6027 linker_was_run = (tmp != execution_count);
6030 /* If options said don't run linker,
6031 complain about input files to be given to the linker. */
6033 if (! linker_was_run && error_count == 0)
6034 for (i = 0; (int) i < n_infiles; i++)
6035 if (explicit_link_files[i])
6036 error ("%s: linker input file unused because linking not done",
6039 /* Delete some or all of the temporary files we made. */
6042 delete_failure_queue ();
6043 delete_temp_files ();
6045 if (print_help_list)
6047 printf (("\nFor bug reporting instructions, please see:\n"));
6048 printf ("%s\n", GCCBUGURL);
6051 return (signal_count != 0 ? 2
6052 : error_count > 0 ? (pass_exit_codes ? greatest_status : 1)
6056 /* Find the proper compilation spec for the file name NAME,
6057 whose length is LENGTH. LANGUAGE is the specified language,
6058 or 0 if this file is to be passed to the linker. */
6060 static struct compiler *
6061 lookup_compiler (name, length, language)
6064 const char *language;
6066 struct compiler *cp;
6068 /* If this was specified by the user to be a linker input, indicate that. */
6069 if (language != 0 && language[0] == '*')
6072 /* Otherwise, look for the language, if one is spec'd. */
6075 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
6076 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
6079 error ("language %s not recognized", language);
6083 /* Look for a suffix. */
6084 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
6086 if (/* The suffix `-' matches only the file name `-'. */
6087 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
6088 || (strlen (cp->suffix) < length
6089 /* See if the suffix matches the end of NAME. */
6090 && !strcmp (cp->suffix,
6091 name + length - strlen (cp->suffix))
6096 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
6097 /* look again, but case-insensitively this time. */
6099 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
6101 if (/* The suffix `-' matches only the file name `-'. */
6102 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
6103 || (strlen (cp->suffix) < length
6104 /* See if the suffix matches the end of NAME. */
6105 && ((!strcmp (cp->suffix,
6106 name + length - strlen (cp->suffix))
6107 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
6108 && !strcasecmp (cp->suffix,
6109 name + length - strlen (cp->suffix)))
6115 if (cp >= compilers)
6117 if (cp->spec[0] != '@')
6118 /* A non-alias entry: return it. */
6121 /* An alias entry maps a suffix to a language.
6122 Search for the language; pass 0 for NAME and LENGTH
6123 to avoid infinite recursion if language not found. */
6124 return lookup_compiler (NULL, 0, cp->spec + 1);
6130 save_string (s, len)
6134 char *result = xmalloc (len + 1);
6136 memcpy (result, s, len);
6142 pfatal_with_name (name)
6145 perror_with_name (name);
6146 delete_temp_files ();
6151 perror_with_name (name)
6154 error ("%s: %s", name, xstrerror (errno));
6158 pfatal_pexecute (errmsg_fmt, errmsg_arg)
6159 const char *errmsg_fmt;
6160 const char *errmsg_arg;
6164 int save_errno = errno;
6166 /* Space for trailing '\0' is in %s. */
6167 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
6168 sprintf (msg, errmsg_fmt, errmsg_arg);
6174 pfatal_with_name (errmsg_fmt);
6177 /* Output an error message and exit */
6182 fatal ("Internal gcc abort.");
6185 /* Output an error message and exit */
6188 fatal VPARAMS ((const char *msgid, ...))
6190 VA_OPEN (ap, msgid);
6191 VA_FIXEDARG (ap, const char *, msgid);
6193 fprintf (stderr, "%s: ", programname);
6194 vfprintf (stderr, _(msgid), ap);
6196 fprintf (stderr, "\n");
6197 delete_temp_files ();
6202 error VPARAMS ((const char *msgid, ...))
6204 VA_OPEN (ap, msgid);
6205 VA_FIXEDARG (ap, const char *, msgid);
6207 fprintf (stderr, "%s: ", programname);
6208 vfprintf (stderr, _(msgid), ap);
6211 fprintf (stderr, "\n");
6215 notice VPARAMS ((const char *msgid, ...))
6217 VA_OPEN (ap, msgid);
6218 VA_FIXEDARG (ap, const char *, msgid);
6220 vfprintf (stderr, _(msgid), ap);
6225 validate_all_switches ()
6227 struct compiler *comp;
6230 struct spec_list *spec;
6232 for (comp = compilers; comp->spec; comp++)
6236 if (c == '%' && *p == '{')
6237 /* We have a switch spec. */
6238 validate_switches (p + 1);
6241 /* Look through the linked list of specs read from the specs file. */
6242 for (spec = specs; spec; spec = spec->next)
6244 p = *(spec->ptr_spec);
6246 if (c == '%' && *p == '{')
6247 /* We have a switch spec. */
6248 validate_switches (p + 1);
6251 p = link_command_spec;
6253 if (c == '%' && *p == '{')
6254 /* We have a switch spec. */
6255 validate_switches (p + 1);
6258 /* Look at the switch-name that comes after START
6259 and mark as valid all supplied switches that match it. */
6262 validate_switches (start)
6265 const char *p = start;
6282 while (*p != ':' && *p != '}' && *p != '|' && *p != '&')
6287 else if (p[-1] == '*')
6289 /* Mark all matching switches as valid. */
6290 for (i = 0; i < n_switches; i++)
6291 if (!strncmp (switches[i].part1, filter, p - filter - 1))
6292 switches[i].validated = 1;
6296 /* Mark an exact matching switch as valid. */
6297 for (i = 0; i < n_switches; i++)
6299 if (!strncmp (switches[i].part1, filter, p - filter)
6300 && switches[i].part1[p - filter] == 0)
6301 switches[i].validated = 1;
6305 if (*p++ == '|' || p[-1] == '&')
6309 /* Check whether a particular argument was used. The first time we
6310 canonicalize the switches to keep only the ones we care about. */
6320 const char *replace;
6325 static struct mswitchstr *mswitches;
6326 static int n_mswitches;
6331 struct mswitchstr *matches;
6335 /* Break multilib_matches into the component strings of string
6336 and replacement string. */
6337 for (q = multilib_matches; *q != '\0'; q++)
6342 (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
6344 q = multilib_matches;
6354 matches[i].len = q - matches[i].str;
6356 matches[i].replace = ++q;
6357 while (*q != ';' && *q != '\0')
6363 matches[i].rep_len = q - matches[i].replace;
6369 /* Now build a list of the replacement string for switches that we care
6370 about. Make sure we allocate at least one entry. This prevents
6371 xmalloc from calling fatal, and prevents us from re-executing this
6374 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
6375 * (n_switches ? n_switches : 1));
6376 for (i = 0; i < n_switches; i++)
6378 int xlen = strlen (switches[i].part1);
6379 for (j = 0; j < cnt; j++)
6380 if (xlen == matches[j].len
6381 && ! strncmp (switches[i].part1, matches[j].str, xlen))
6383 mswitches[n_mswitches].str = matches[j].replace;
6384 mswitches[n_mswitches].len = matches[j].rep_len;
6385 mswitches[n_mswitches].replace = (char *) 0;
6386 mswitches[n_mswitches].rep_len = 0;
6393 for (i = 0; i < n_mswitches; i++)
6394 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
6401 default_arg (p, len)
6405 const char *start, *end;
6407 for (start = multilib_defaults; *start != '\0'; start = end + 1)
6409 while (*start == ' ' || *start == '\t')
6415 for (end = start + 1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
6418 if ((end - start) == len && strncmp (p, start, len) == 0)
6428 /* Work out the subdirectory to use based on the options. The format of
6429 multilib_select is a list of elements. Each element is a subdirectory
6430 name followed by a list of options followed by a semicolon. The format
6431 of multilib_exclusions is the same, but without the preceding
6432 directory. First gcc will check the exclusions, if none of the options
6433 beginning with an exclamation point are present, and all of the other
6434 options are present, then we will ignore this completely. Passing
6435 that, gcc will consider each multilib_select in turn using the same
6436 rules for matching the options. If a match is found, that subdirectory
6443 unsigned int this_path_len;
6444 const char *this_path, *this_arg;
6448 p = multilib_exclusions;
6451 /* Ignore newlines. */
6458 /* Check the arguments. */
6472 while (*p != ' ' && *p != ';')
6479 if (*this_arg != '!')
6487 ok = used_arg (this_arg, p - this_arg);
6501 p = multilib_select;
6504 /* Ignore newlines. */
6511 /* Get the initial path. */
6519 this_path_len = p - this_path;
6521 /* Check the arguments. */
6536 while (*p != ' ' && *p != ';')
6543 if (*this_arg != '!')
6551 /* If this is a default argument, we can just ignore it.
6552 This is true even if this_arg begins with '!'. Beginning
6553 with '!' does not mean that this argument is necessarily
6554 inappropriate for this library: it merely means that
6555 there is a more specific library which uses this
6556 argument. If this argument is a default, we need not
6557 consider that more specific library. */
6558 if (! default_arg (this_arg, p - this_arg))
6560 ok = used_arg (this_arg, p - this_arg);
6571 if (this_path_len != 1
6572 || this_path[0] != '.')
6574 char *new_multilib_dir = xmalloc (this_path_len + 1);
6575 strncpy (new_multilib_dir, this_path, this_path_len);
6576 new_multilib_dir[this_path_len] = '\0';
6577 multilib_dir = new_multilib_dir;
6586 /* Print out the multiple library subdirectory selection
6587 information. This prints out a series of lines. Each line looks
6588 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
6589 required. Only the desired options are printed out, the negative
6590 matches. The options are print without a leading dash. There are
6591 no spaces to make it easy to use the information in the shell.
6592 Each subdirectory is printed only once. This assumes the ordering
6593 generated by the genmultilib script. Also, we leave out ones that match
6597 print_multilib_info ()
6599 const char *p = multilib_select;
6600 const char *last_path = 0, *this_path;
6602 unsigned int last_path_len = 0;
6607 /* Ignore newlines. */
6614 /* Get the initial path. */
6623 /* Check for matches with the multilib_exclusions. We don't bother
6624 with the '!' in either list. If any of the exclusion rules match
6625 all of its options with the select rule, we skip it. */
6627 const char *e = multilib_exclusions;
6628 const char *this_arg;
6633 /* Ignore newlines. */
6640 /* Check the arguments. */
6657 while (*e != ' ' && *e != ';')
6668 int len = e - this_arg;
6675 while (*q != ' ' && *q != ';')
6682 if (! strncmp (arg, this_arg, (len < q - arg) ? q - arg : len) ||
6683 default_arg (this_arg, e - this_arg))
6713 /* If this is a duplicate, skip it. */
6714 skip = (last_path != 0 && (unsigned int) (p - this_path) == last_path_len
6715 && ! strncmp (last_path, this_path, last_path_len));
6717 last_path = this_path;
6718 last_path_len = p - this_path;
6721 /* If this directory requires any default arguments, we can skip
6722 it. We will already have printed a directory identical to
6723 this one which does not require that default argument. */
6741 while (*q != ' ' && *q != ';')
6749 && default_arg (arg, q - arg))
6764 for (p1 = last_path; p1 < p; p1++)
6783 use_arg = *p != '!';
6788 while (*p != ' ' && *p != ';')
6803 /* If there are extra options, print them now. */
6804 if (multilib_extra && *multilib_extra)
6806 int print_at = TRUE;
6809 for (q = multilib_extra; *q != '\0'; q++)