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, 2002 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!!!! */
27 /* This program is the user interface to the C compiler and possibly to
28 other compilers. It is used because compilation is a complicated procedure
29 which involves running several programs and passing temporary files between
30 them, forwarding the users switches to those programs selectively,
31 and deleting the temporary files at the end.
33 CC recognizes how to compile each input file by suffixes in the file names.
34 Once it knows which kind of compilation to perform, the procedure for
35 compilation is specified by a string called a "spec". */
37 /* A Short Introduction to Adding a Command-Line Option.
39 Before adding a command-line option, consider if it is really
40 necessary. Each additional command-line option adds complexity and
41 is difficult to remove in subsequent versions.
43 In the following, consider adding the command-line argument
46 1. Each command-line option is specified in the specs file. The
47 notation is described below in the comment entitled "The Specs
50 2. In this file, add an entry to "option_map" equating the long
51 `--' argument version and any shorter, single letter version. Read
52 the comments in the declaration of "struct option_map" for an
53 explanation. Do not omit the first `-'.
55 3. Look in the "specs" file to determine which program or option
56 list should be given the argument, e.g., "cc1_options". Add the
57 appropriate syntax for the shorter option version to the
58 corresponding "const char *" entry in this file. Omit the first
59 `-' from the option. For example, use `-bar', rather than `--bar'.
61 4. If the argument takes an argument, e.g., `--baz argument1',
62 modify either DEFAULT_SWITCH_TAKES_ARG or
63 DEFAULT_WORD_SWITCH_TAKES_ARG in this file. Omit the first `-'
66 5. Document the option in this file's display_help(). If the
67 option is passed to a subprogram, modify its corresponding
68 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
71 6. Compile and test. Make sure that your new specs file is being
72 read. For example, use a debugger to investigate the value of
73 "specs_file" in main(). */
78 #if ! defined( SIGCHLD ) && defined( SIGCLD )
79 # define SIGCHLD SIGCLD
87 #ifdef HAVE_SYS_RESOURCE_H
88 #include <sys/resource.h>
90 #if defined (HAVE_DECL_GETRUSAGE) && !HAVE_DECL_GETRUSAGE
91 extern int getrusage PARAMS ((int, struct rusage *));
94 /* By default there is no special suffix for target executables. */
95 /* FIXME: when autoconf is fixed, remove the host check - dj */
96 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
97 #define HAVE_TARGET_EXECUTABLE_SUFFIX
99 #undef 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 set by cppspec.c to 1. */
151 /* Flag saying to pass the greatest exit code returned by a sub-process
152 to the calling program. */
153 static int pass_exit_codes;
155 /* Definition of string containing the arguments given to configure. */
156 #include "configargs.h"
158 /* Flag saying to print the directories gcc will search through looking for
159 programs, libraries, etc. */
161 static int print_search_dirs;
163 /* Flag saying to print the full filename of this file
164 as found through our usual search mechanism. */
166 static const char *print_file_name = NULL;
168 /* As print_file_name, but search for executable file. */
170 static const char *print_prog_name = NULL;
172 /* Flag saying to print the relative path we'd use to
173 find libgcc.a given the current compiler flags. */
175 static int print_multi_directory;
177 /* Flag saying to print the list of subdirectories and
178 compiler flags used to select them in a standard form. */
180 static int print_multi_lib;
182 /* Flag saying to print the command line options understood by gcc and its
185 static int print_help_list;
187 /* Flag indicating whether we should print the command and arguments */
189 static int verbose_flag;
191 /* Flag indicating whether we should ONLY print the command and
192 arguments (like verbose_flag) without executing the command.
193 Displayed arguments are quoted so that the generated command
194 line is suitable for execution. This is intended for use in
195 shell scripts to capture the driver-generated command line. */
196 static int verbose_only_flag;
198 /* Flag indicating to print target specific command line options. */
200 static int target_help_flag;
202 /* Flag indicating whether we should report subprocess execution times
203 (if this is supported by the system - see pexecute.c). */
205 static int report_times;
207 /* Nonzero means write "temp" files in source directory
208 and use the source file's name in them, and don't delete them. */
210 static int save_temps_flag;
212 /* The compiler version. */
214 static const char *compiler_version;
216 /* The target version specified with -V */
218 static const char *spec_version = DEFAULT_TARGET_VERSION;
220 /* The target machine specified with -b. */
222 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
224 /* Nonzero if cross-compiling.
225 When -b is used, the value comes from the `specs' file. */
228 static const char *cross_compile = "1";
230 static const char *cross_compile = "0";
233 #ifdef MODIFY_TARGET_NAME
235 /* Information on how to alter the target name based on a command-line
236 switch. The only case we support now is simply appending or deleting a
237 string to or from the end of the first part of the configuration name. */
239 static const struct modify_target
241 const char *const sw;
242 const enum add_del {ADD, DELETE} add_del;
243 const char *const str;
245 modify_target[] = MODIFY_TARGET_NAME;
248 /* The number of errors that have occurred; the link phase will not be
249 run if this is non-zero. */
250 static int error_count = 0;
252 /* Greatest exit code of sub-processes that has been encountered up to
254 static int greatest_status = 1;
256 /* This is the obstack which we use to allocate many strings. */
258 static struct obstack obstack;
260 /* This is the obstack to build an environment variable to pass to
261 collect2 that describes all of the relevant switches of what to
262 pass the compiler in building the list of pointers to constructors
265 static struct obstack collect_obstack;
267 /* These structs are used to collect resource usage information for
269 #ifdef HAVE_GETRUSAGE
270 static struct rusage rus, prus;
273 /* Forward declaration for prototypes. */
276 static void init_spec PARAMS ((void));
278 static char **split_directories PARAMS ((const char *, int *));
279 static void free_split_directories PARAMS ((char **));
280 static char *make_relative_prefix PARAMS ((const char *, const char *, const char *));
282 static void store_arg PARAMS ((const char *, int, int));
283 static char *load_specs PARAMS ((const char *));
284 static void read_specs PARAMS ((const char *, int));
285 static void set_spec PARAMS ((const char *, const char *));
286 static struct compiler *lookup_compiler PARAMS ((const char *, size_t, const char *));
287 static char *build_search_list PARAMS ((struct path_prefix *, const char *, int));
288 static void putenv_from_prefixes PARAMS ((struct path_prefix *, const char *));
289 static int access_check PARAMS ((const char *, int));
290 static char *find_a_file PARAMS ((struct path_prefix *, const char *, int));
291 static void add_prefix PARAMS ((struct path_prefix *, const char *,
292 const char *, int, int, int *));
293 static void translate_options PARAMS ((int *, const char *const **));
294 static char *skip_whitespace PARAMS ((char *));
295 static void delete_if_ordinary PARAMS ((const char *));
296 static void delete_temp_files PARAMS ((void));
297 static void delete_failure_queue PARAMS ((void));
298 static void clear_failure_queue PARAMS ((void));
299 static int check_live_switch PARAMS ((int, int));
300 static const char *handle_braces PARAMS ((const char *));
301 static char *save_string PARAMS ((const char *, int));
302 static void set_collect_gcc_options PARAMS ((void));
303 static int do_spec_1 PARAMS ((const char *, int, const char *));
304 static const char *find_file PARAMS ((const char *));
305 static int is_directory PARAMS ((const char *, const char *, int));
306 static void validate_switches PARAMS ((const char *));
307 static void validate_all_switches PARAMS ((void));
308 static void give_switch PARAMS ((int, int, int));
309 static int used_arg PARAMS ((const char *, int));
310 static int default_arg PARAMS ((const char *, int));
311 static void set_multilib_dir PARAMS ((void));
312 static void print_multilib_info PARAMS ((void));
313 static void perror_with_name PARAMS ((const char *));
314 static void pfatal_pexecute PARAMS ((const char *, const char *))
316 static void notice PARAMS ((const char *, ...))
318 static void display_help PARAMS ((void));
319 static void add_preprocessor_option PARAMS ((const char *, int));
320 static void add_assembler_option PARAMS ((const char *, int));
321 static void add_linker_option PARAMS ((const char *, int));
322 static void process_command PARAMS ((int, const char *const *));
323 static int execute PARAMS ((void));
324 static void clear_args PARAMS ((void));
325 static void fatal_error PARAMS ((int));
326 #ifdef ENABLE_SHARED_LIBGCC
327 static void init_gcc_specs PARAMS ((struct obstack *,
328 const char *, const char *,
331 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
332 static const char *convert_filename PARAMS ((const char *, int, int));
335 /* The Specs Language
337 Specs are strings containing lines, each of which (if not blank)
338 is made up of a program name, and arguments separated by spaces.
339 The program name must be exact and start from root, since no path
340 is searched and it is unreliable to depend on the current working directory.
341 Redirection of input or output is not supported; the subprograms must
342 accept filenames saying what files to read and write.
344 In addition, the specs can contain %-sequences to substitute variable text
345 or for conditional text. Here is a table of all defined %-sequences.
346 Note that spaces are not generated automatically around the results of
347 expanding these sequences; therefore, you can concatenate them together
348 or with constant text in a single argument.
350 %% substitute one % into the program name or argument.
351 %i substitute the name of the input file being processed.
352 %b substitute the basename of the input file being processed.
353 This is the substring up to (and not including) the last period
354 and not including the directory.
355 %B same as %b, but include the file suffix (text after the last period).
357 substitute a file name that has suffix SUFFIX and is chosen
358 once per compilation, and mark the argument a la %d. To reduce
359 exposure to denial-of-service attacks, the file name is now
360 chosen in a way that is hard to predict even when previously
361 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
362 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
363 the regexp "[.A-Za-z]*%O"; "%O" is treated exactly as if it
364 had been pre-processed. Previously, %g was simply substituted
365 with a file name chosen once per compilation, without regard
366 to any appended suffix (which was therefore treated just like
367 ordinary text), making such attacks more likely to succeed.
369 like %g, but generates a new temporary file name even if %uSUFFIX
372 substitutes the last file name generated with %uSUFFIX, generating a
373 new one if there is no such last file name. In the absence of any
374 %uSUFFIX, this is just like %gSUFFIX, except they don't share
375 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
376 would involve the generation of two distinct file names, one
377 for each `%g.s' and another for each `%U.s'. Previously, %U was
378 simply substituted with a file name chosen for the previous %u,
379 without regard to any appended suffix.
381 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
382 writable, and if save-temps is off; otherwise, substitute the name
383 of a temporary file, just like %u. This temporary file is not
384 meant for communication between processes, but rather as a junk
387 substitutes .SUFFIX for the suffixes of a matched switch's args when
388 it is subsequently output with %*. SUFFIX is terminated by the next
390 %d marks the argument containing or following the %d as a
391 temporary file name, so that that file will be deleted if CC exits
392 successfully. Unlike %g, this contributes no text to the argument.
393 %w marks the argument containing or following the %w as the
394 "output file" of this compilation. This puts the argument
395 into the sequence of arguments that %o will substitute later.
397 like %{...} but mark last argument supplied within
398 as a file to be deleted on failure.
399 %o substitutes the names of all the output files, with spaces
400 automatically placed around them. You should write spaces
401 around the %o as well or the results are undefined.
402 %o is for use in the specs for running the linker.
403 Input files whose names have no recognized suffix are not compiled
404 at all, but they are included among the output files, so they will
406 %O substitutes the suffix for object files. Note that this is
407 handled specially when it immediately follows %g, %u, or %U
408 (with or without a suffix argument) because of the need for
409 those to form complete file names. The handling is such that
410 %O is treated exactly as if it had already been substituted,
411 except that %g, %u, and %U do not currently support additional
412 SUFFIX characters following %O as they would following, for
414 %p substitutes the standard macro predefinitions for the
415 current target machine. Use this when running cpp.
416 %P like %p, but puts `__' before and after the name of each macro.
417 (Except macros that already have __.)
419 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
420 %s current argument is the name of a library or startup file of some sort.
421 Search for that file in a standard list of directories
422 and substitute the full name found.
423 %eSTR Print STR as an error message. STR is terminated by a newline.
424 Use this when inconsistent options are detected.
425 %nSTR Print STR as an notice. STR is terminated by a newline.
426 %x{OPTION} Accumulate an option for %X.
427 %X Output the accumulated linker options specified by compilations.
428 %Y Output the accumulated assembler options specified by compilations.
429 %Z Output the accumulated preprocessor options specified by compilations.
430 %v1 Substitute the major version number of GCC.
431 (For version 2.5.3, this is 2.)
432 %v2 Substitute the minor version number of GCC.
433 (For version 2.5.3, this is 5.)
434 %v3 Substitute the patch level number of GCC.
435 (For version 2.5.3, this is 3.)
436 %a process ASM_SPEC as a spec.
437 This allows config.h to specify part of the spec for running as.
438 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
439 used here. This can be used to run a post-processor after the
440 assembler has done its job.
441 %D Dump out a -L option for each directory in startfile_prefixes.
442 If multilib_dir is set, extra entries are generated with it affixed.
443 %l process LINK_SPEC as a spec.
444 %L process LIB_SPEC as a spec.
445 %G process LIBGCC_SPEC as a spec.
446 %M output multilib_dir with directory separators replaced with "_";
447 if multilib_dir is not set or is ".", output "".
448 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
449 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
450 %c process SIGNED_CHAR_SPEC as a spec.
451 %C process CPP_SPEC as a spec.
452 %1 process CC1_SPEC as a spec.
453 %2 process CC1PLUS_SPEC as a spec.
454 %| output "-" if the input for the current command is coming from a pipe.
455 %* substitute the variable part of a matched option. (See below.)
456 Note that each comma in the substituted string is replaced by
458 %{S} substitutes the -S switch, if that switch was given to CC.
459 If that switch was not specified, this substitutes nothing.
460 Here S is a metasyntactic variable.
461 %{S*} substitutes all the switches specified to CC whose names start
462 with -S. This is used for -o, -I, etc; switches that take
463 arguments. CC considers `-o foo' as being one switch whose
464 name starts with `o'. %{o*} would substitute this text,
465 including the space; thus, two arguments would be generated.
466 %{^S*} likewise, but don't put a blank between a switch and any args.
467 %{S*&T*} likewise, but preserve order of S and T options (the order
468 of S and T in the spec is not significant). Can be any number
469 of ampersand-separated variables; for each the wild card is
470 optional. Useful for CPP as %{D*&U*&A*}.
471 %{S*:X} substitutes X if one or more switches whose names start with -S are
472 specified to CC. Note that the tail part of the -S option
473 (i.e. the part matched by the `*') will be substituted for each
474 occurrence of %* within X.
475 %{<S} remove all occurrences of -S from the command line.
476 Note - this option is position dependent. % commands in the
477 spec string before this option will see -S, % commands in the
478 spec string after this option will not.
479 %{S:X} substitutes X, but only if the -S switch was given to CC.
480 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
481 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
482 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
483 %{.S:X} substitutes X, but only if processing a file with suffix S.
484 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
485 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
486 combined with ! and . as above binding stronger than the OR.
487 %(Spec) processes a specification defined in a specs file as *Spec:
488 %[Spec] as above, but put __ around -D arguments
490 The conditional text X in a %{S:X} or %{!S:X} construct may contain
491 other nested % constructs or spaces, or even newlines. They are
492 processed as usual, as described above.
494 The -O, -f, -m, and -W switches are handled specifically in these
495 constructs. If another value of -O or the negated form of a -f, -m, or
496 -W switch is found later in the command line, the earlier switch
497 value is ignored, except with {S*} where S is just one letter; this
498 passes all matching options.
500 The character | at the beginning of the predicate text is used to indicate
501 that a command should be piped to the following command, but only if -pipe
504 Note that it is built into CC which switches take arguments and which
505 do not. You might think it would be useful to generalize this to
506 allow each compiler's spec to say which switches take arguments. But
507 this cannot be done in a consistent fashion. CC cannot even decide
508 which input files have been specified without knowing which switches
509 take arguments, and it must know which input files to compile in order
510 to tell which compilers to run.
512 CC also knows implicitly that arguments starting in `-l' are to be
513 treated as compiler output files, and passed to the linker in their
514 proper position among the other output files. */
516 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
518 /* config.h can define ASM_SPEC to provide extra args to the assembler
519 or extra switch-translations. */
524 /* config.h can define ASM_FINAL_SPEC to run a post processor after
525 the assembler has run. */
526 #ifndef ASM_FINAL_SPEC
527 #define ASM_FINAL_SPEC ""
530 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
531 or extra switch-translations. */
536 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
537 or extra switch-translations. */
542 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
543 or extra switch-translations. */
545 #define CC1PLUS_SPEC ""
548 /* config.h can define LINK_SPEC to provide extra args to the linker
549 or extra switch-translations. */
554 /* config.h can define LIB_SPEC to override the default libraries. */
556 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
559 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
562 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
563 /* Have gcc do the search for libgcc.a. */
564 #define LIBGCC_SPEC "libgcc.a%s"
566 #define LIBGCC_SPEC "-lgcc"
570 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
571 #ifndef STARTFILE_SPEC
572 #define STARTFILE_SPEC \
573 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
576 /* config.h can define SWITCHES_NEED_SPACES to control which options
577 require spaces between the option and the argument. */
578 #ifndef SWITCHES_NEED_SPACES
579 #define SWITCHES_NEED_SPACES ""
582 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
584 #define ENDFILE_SPEC ""
587 /* This spec is used for telling cpp whether char is signed or not. */
588 #ifndef SIGNED_CHAR_SPEC
589 /* Use #if rather than ?:
590 because MIPS C compiler rejects like ?: in initializers. */
591 #if DEFAULT_SIGNED_CHAR
592 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
594 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
599 #define LINKER_NAME "collect2"
602 /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
604 #ifndef ASM_DEBUG_SPEC
605 # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
606 && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
607 # define ASM_DEBUG_SPEC \
608 (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
609 ? "%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}" \
610 : "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}")
612 # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
613 # define ASM_DEBUG_SPEC "%{g*:--gstabs}"
615 # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
616 # define ASM_DEBUG_SPEC "%{g*:--gdwarf2}"
620 #ifndef ASM_DEBUG_SPEC
621 # define ASM_DEBUG_SPEC ""
624 /* Here is the spec for running the linker, after compiling all files. */
626 /* -u* was put back because both BSD and SysV seem to support it. */
627 /* %{static:} simply prevents an error message if the target machine
628 doesn't handle -static. */
629 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
630 scripts which exist in user specified directories, or in standard
632 #ifndef LINK_COMMAND_SPEC
633 #define LINK_COMMAND_SPEC "\
634 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
635 %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
636 %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
637 %{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
638 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
641 #ifndef LINK_LIBGCC_SPEC
642 # ifdef LINK_LIBGCC_SPECIAL
643 /* Don't generate -L options for startfile prefix list. */
644 # define LINK_LIBGCC_SPEC ""
646 /* Do generate them. */
647 # define LINK_LIBGCC_SPEC "%D"
651 static const char *asm_debug = ASM_DEBUG_SPEC;
652 static const char *cpp_spec = CPP_SPEC;
653 static const char *cpp_predefines = CPP_PREDEFINES;
654 static const char *cc1_spec = CC1_SPEC;
655 static const char *cc1plus_spec = CC1PLUS_SPEC;
656 static const char *signed_char_spec = SIGNED_CHAR_SPEC;
657 static const char *asm_spec = ASM_SPEC;
658 static const char *asm_final_spec = ASM_FINAL_SPEC;
659 static const char *link_spec = LINK_SPEC;
660 static const char *lib_spec = LIB_SPEC;
661 static const char *libgcc_spec = LIBGCC_SPEC;
662 static const char *endfile_spec = ENDFILE_SPEC;
663 static const char *startfile_spec = STARTFILE_SPEC;
664 static const char *switches_need_spaces = SWITCHES_NEED_SPACES;
665 static const char *linker_name_spec = LINKER_NAME;
666 static const char *link_command_spec = LINK_COMMAND_SPEC;
667 static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
669 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
670 There should be no need to override these in target dependent files,
671 but we need to copy them to the specs file so that newer versions
672 of the GCC driver can correctly drive older tool chains with the
673 appropriate -B options. */
675 static const char *trad_capable_cpp =
676 "%{traditional|ftraditional|traditional-cpp:trad}cpp0";
678 static const char *cpp_unique_options =
679 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
680 %{nostdinc*} %{C} %{v} %{I*} %{P} %{$} %I\
681 %{MD:-M -MF %W{!o: %b.d}%W{o*:%.d%*}}\
682 %{MMD:-MM -MF %W{!o: %b.d}%W{o*:%.d%*}}\
683 %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
684 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
685 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
686 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
687 %{fno-inline|O0|!O*:-D__NO_INLINE__} %{ffast-math:-D__FAST_MATH__}\
688 %{fshort-wchar:-U__WCHAR_TYPE__ -D__WCHAR_TYPE__=short\\ unsigned\\ int}\
689 %{ffreestanding:-D__STDC_HOSTED__=0} %{fno-hosted:-D__STDC_HOSTED__=0}\
690 %{!ffreestanding:%{!fno-hosted:-D__STDC_HOSTED__=1}} %{remap}\
691 %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
694 /* This contains cpp options which are common with cc1_options and are passed
695 only when preprocessing only to avoid duplication. */
696 static const char *cpp_options =
697 "%(cpp_unique_options) %{std*} %{d*} %{W*} %{w} %{pedantic*}\
698 %{fshow-column} %{fno-show-column}\
699 %{fleading-underscore} %{fno-leading-underscore}\
700 %{fno-operator-names} %{ftabstop=*}";
702 /* NB: This is shared amongst all front-ends. */
703 static const char *cc1_options =
704 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
705 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
706 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*} %{ansi}\
707 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
708 %{Qn:-fno-ident} %{--help:--help}\
709 %{--target-help:--target-help}\
710 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
711 %{fsyntax-only:-o %j} %{-param*}";
713 static const char *asm_options =
714 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
716 static const char *invoke_as =
717 "%{!S:-o %{|!pipe:%g.s} |\n as %(asm_options) %{!pipe:%g.s} %A }";
719 /* Some compilers have limits on line lengths, and the multilib_select
720 and/or multilib_matches strings can be very long, so we build them at
722 static struct obstack multilib_obstack;
723 static const char *multilib_select;
724 static const char *multilib_matches;
725 static const char *multilib_defaults;
726 static const char *multilib_exclusions;
727 #include "multilib.h"
729 /* Check whether a particular argument is a default argument. */
731 #ifndef MULTILIB_DEFAULTS
732 #define MULTILIB_DEFAULTS { "" }
735 static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
739 struct user_specs *next;
740 const char *filename;
743 static struct user_specs *user_specs_head, *user_specs_tail;
745 /* This defines which switch letters take arguments. */
747 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
748 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
749 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
750 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
751 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
752 || (CHAR) == 'B' || (CHAR) == 'b')
754 #ifndef SWITCH_TAKES_ARG
755 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
758 /* This defines which multi-letter switches take arguments. */
760 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
761 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
762 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
763 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
764 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
765 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
766 || !strcmp (STR, "isystem") || !strcmp (STR, "-param") \
767 || !strcmp (STR, "specs") \
768 || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
770 #ifndef WORD_SWITCH_TAKES_ARG
771 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
774 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
775 /* This defines which switches stop a full compilation. */
776 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
777 ((CHAR) == 'c' || (CHAR) == 'S')
779 #ifndef SWITCH_CURTAILS_COMPILATION
780 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
781 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
785 /* Record the mapping from file suffixes for compilation specs. */
789 const char *suffix; /* Use this compiler for input files
790 whose names end in this suffix. */
792 const char *spec; /* To use this compiler, run this spec. */
794 const char *cpp_spec; /* If non-NULL, substitute this spec
795 for `%C', rather than the usual
799 /* Pointer to a vector of `struct compiler' that gives the spec for
800 compiling a file, based on its suffix.
801 A file that does not end in any of these suffixes will be passed
802 unchanged to the loader and nothing else will be done to it.
804 An entry containing two 0s is used to terminate the vector.
806 If multiple entries match a file, the last matching one is used. */
808 static struct compiler *compilers;
810 /* Number of entries in `compilers', not counting the null terminator. */
812 static int n_compilers;
814 /* The default list of file name suffixes and their compilation specs. */
816 static const struct compiler default_compilers[] =
818 /* Add lists of suffixes of known languages here. If those languages
819 were not present when we built the driver, we will hit these copies
820 and be given a more meaningful error than "file not used since
821 linking is not done". */
822 {".m", "#Objective-C", 0}, {".mi", "#Objective-C", 0},
823 {".cc", "#C++", 0}, {".cxx", "#C++", 0}, {".cpp", "#C++", 0},
824 {".cp", "#C++", 0}, {".c++", "#C++", 0}, {".C", "#C++", 0},
826 {".ads", "#Ada", 0}, {".adb", "#Ada", 0},
827 {".f", "#Fortran", 0}, {".for", "#Fortran", 0}, {".fpp", "#Fortran", 0},
828 {".F", "#Fortran", 0}, {".FOR", "#Fortran", 0}, {".FPP", "#Fortran", 0},
829 {".r", "#Ratfor", 0},
830 {".p", "#Pascal", 0}, {".pas", "#Pascal", 0},
831 {".ch", "#Chill", 0}, {".chi", "#Chill", 0},
832 {".java", "#Java", 0}, {".class", "#Java", 0},
833 {".zip", "#Java", 0}, {".jar", "#Java", 0},
834 /* Next come the entries for C. */
837 /* cc1 has an integrated ISO C preprocessor. We should invoke the
838 external preprocessor if -save-temps or -traditional is given. */
839 "%{E|M|MM:%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)}\
841 %{save-temps:%(trad_capable_cpp) -lang-c %{ansi:-std=c89}\
842 %(cpp_options) %b.i \n\
843 cc1 -fpreprocessed %b.i %(cc1_options)}\
845 %{traditional|ftraditional|traditional-cpp:\
846 tradcpp0 -lang-c %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.i} |\n\
847 cc1 -fpreprocessed %{!pipe:%g.i} %(cc1_options)}\
848 %{!traditional:%{!ftraditional:%{!traditional-cpp:\
849 cc1 -lang-c %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}}}}\
850 %{!fsyntax-only:%(invoke_as)}}}}", 0},
852 "%{!E:%e-E required when input is from standard input}\
853 %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)", 0},
854 {".h", "@c-header", 0},
856 "%{!E:%ecompilation of header file requested} \
857 %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)", 0},
858 {".i", "@cpp-output", 0},
860 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0},
861 {".s", "@assembler", 0},
863 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0},
864 {".S", "@assembler-with-cpp", 0},
865 {"@assembler-with-cpp",
866 "%(trad_capable_cpp) -lang-asm %(cpp_options)\
867 %{!M:%{!MM:%{!E:%{!S:-o %{|!pipe:%g.s} |\n\
868 as %(asm_debug) %(asm_options) %{!pipe:%g.s} %A }}}}", 0},
870 /* Mark end of table */
874 /* Number of elements in default_compilers, not counting the terminator. */
876 static int n_default_compilers
877 = (sizeof default_compilers / sizeof (struct compiler)) - 1;
879 /* A vector of options to give to the linker.
880 These options are accumulated by %x,
881 and substituted into the linker command with %X. */
882 static int n_linker_options;
883 static char **linker_options;
885 /* A vector of options to give to the assembler.
886 These options are accumulated by -Wa,
887 and substituted into the assembler command with %Y. */
888 static int n_assembler_options;
889 static char **assembler_options;
891 /* A vector of options to give to the preprocessor.
892 These options are accumulated by -Wp,
893 and substituted into the preprocessor command with %Z. */
894 static int n_preprocessor_options;
895 static char **preprocessor_options;
897 /* Define how to map long options into short ones. */
899 /* This structure describes one mapping. */
902 /* The long option's name. */
903 const char *const name;
904 /* The equivalent short option. */
905 const char *const equivalent;
906 /* Argument info. A string of flag chars; NULL equals no options.
907 a => argument required.
908 o => argument optional.
909 j => join argument to equivalent, making one word.
910 * => require other text after NAME as an argument. */
911 const char *const arg_info;
914 /* This is the table of mappings. Mappings are tried sequentially
915 for each option encountered; the first one that matches, wins. */
917 static const struct option_map option_map[] =
919 {"--all-warnings", "-Wall", 0},
920 {"--ansi", "-ansi", 0},
921 {"--assemble", "-S", 0},
922 {"--assert", "-A", "a"},
923 {"--classpath", "-fclasspath=", "aj"},
924 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
925 {"--comments", "-C", 0},
926 {"--compile", "-c", 0},
927 {"--debug", "-g", "oj"},
928 {"--define-macro", "-D", "aj"},
929 {"--dependencies", "-M", 0},
930 {"--dump", "-d", "a"},
931 {"--dumpbase", "-dumpbase", "a"},
932 {"--entry", "-e", 0},
933 {"--extra-warnings", "-W", 0},
934 {"--for-assembler", "-Wa", "a"},
935 {"--for-linker", "-Xlinker", "a"},
936 {"--force-link", "-u", "a"},
937 {"--imacros", "-imacros", "a"},
938 {"--include", "-include", "a"},
939 {"--include-barrier", "-I-", 0},
940 {"--include-directory", "-I", "aj"},
941 {"--include-directory-after", "-idirafter", "a"},
942 {"--include-prefix", "-iprefix", "a"},
943 {"--include-with-prefix", "-iwithprefix", "a"},
944 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
945 {"--include-with-prefix-after", "-iwithprefix", "a"},
946 {"--language", "-x", "a"},
947 {"--library-directory", "-L", "a"},
948 {"--machine", "-m", "aj"},
949 {"--machine-", "-m", "*j"},
950 {"--no-line-commands", "-P", 0},
951 {"--no-precompiled-includes", "-noprecomp", 0},
952 {"--no-standard-includes", "-nostdinc", 0},
953 {"--no-standard-libraries", "-nostdlib", 0},
954 {"--no-warnings", "-w", 0},
955 {"--optimize", "-O", "oj"},
956 {"--output", "-o", "a"},
957 {"--output-class-directory", "-foutput-class-dir=", "ja"},
958 {"--param", "--param", "a"},
959 {"--pedantic", "-pedantic", 0},
960 {"--pedantic-errors", "-pedantic-errors", 0},
961 {"--pipe", "-pipe", 0},
962 {"--prefix", "-B", "a"},
963 {"--preprocess", "-E", 0},
964 {"--print-search-dirs", "-print-search-dirs", 0},
965 {"--print-file-name", "-print-file-name=", "aj"},
966 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
967 {"--print-missing-file-dependencies", "-MG", 0},
968 {"--print-multi-lib", "-print-multi-lib", 0},
969 {"--print-multi-directory", "-print-multi-directory", 0},
970 {"--print-prog-name", "-print-prog-name=", "aj"},
971 {"--profile", "-p", 0},
972 {"--profile-blocks", "-a", 0},
973 {"--quiet", "-q", 0},
974 {"--save-temps", "-save-temps", 0},
975 {"--shared", "-shared", 0},
976 {"--silent", "-q", 0},
977 {"--specs", "-specs=", "aj"},
978 {"--static", "-static", 0},
979 {"--std", "-std=", "aj"},
980 {"--symbolic", "-symbolic", 0},
981 {"--target", "-b", "a"},
982 {"--time", "-time", 0},
983 {"--trace-includes", "-H", 0},
984 {"--traditional", "-traditional", 0},
985 {"--traditional-cpp", "-traditional-cpp", 0},
986 {"--trigraphs", "-trigraphs", 0},
987 {"--undefine-macro", "-U", "aj"},
988 {"--use-version", "-V", "a"},
989 {"--user-dependencies", "-MM", 0},
990 {"--verbose", "-v", 0},
991 {"--warn-", "-W", "*j"},
992 {"--write-dependencies", "-MD", 0},
993 {"--write-user-dependencies", "-MMD", 0},
998 #ifdef TARGET_OPTION_TRANSLATE_TABLE
999 static const struct {
1000 const char *const option_found;
1001 const char *const replacements;
1002 } target_option_translations[] =
1004 TARGET_OPTION_TRANSLATE_TABLE,
1009 /* Translate the options described by *ARGCP and *ARGVP.
1010 Make a new vector and store it back in *ARGVP,
1011 and store its length in *ARGVC. */
1014 translate_options (argcp, argvp)
1016 const char *const **argvp;
1020 const char *const *argv = *argvp;
1021 int newvsize = (argc + 2) * 2 * sizeof (const char *);
1023 (const char **) xmalloc (newvsize);
1027 newv[newindex++] = argv[i++];
1031 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1035 target_option_translations[tott_idx].option_found;
1038 if (strcmp (target_option_translations[tott_idx].option_found,
1045 for (sp = target_option_translations[tott_idx].replacements;
1052 newvsize += spaces * sizeof (const char *);
1053 newv = (const char **) xrealloc (newv, newvsize);
1055 sp = target_option_translations[tott_idx].replacements;
1064 newv[newindex++] = np;
1065 while (*np != ' ' && *np)
1076 if (target_option_translations[tott_idx].option_found)
1080 /* Translate -- options. */
1081 if (argv[i][0] == '-' && argv[i][1] == '-')
1084 /* Find a mapping that applies to this option. */
1085 for (j = 0; j < ARRAY_SIZE (option_map); j++)
1087 size_t optlen = strlen (option_map[j].name);
1088 size_t arglen = strlen (argv[i]);
1089 size_t complen = arglen > optlen ? optlen : arglen;
1090 const char *arginfo = option_map[j].arg_info;
1095 if (!strncmp (argv[i], option_map[j].name, complen))
1097 const char *arg = 0;
1099 if (arglen < optlen)
1102 for (k = j + 1; k < ARRAY_SIZE (option_map); k++)
1103 if (strlen (option_map[k].name) >= arglen
1104 && !strncmp (argv[i], option_map[k].name, arglen))
1106 error ("ambiguous abbreviation %s", argv[i]);
1110 if (k != ARRAY_SIZE (option_map))
1114 if (arglen > optlen)
1116 /* If the option has an argument, accept that. */
1117 if (argv[i][optlen] == '=')
1118 arg = argv[i] + optlen + 1;
1120 /* If this mapping requires extra text at end of name,
1121 accept that as "argument". */
1122 else if (strchr (arginfo, '*') != 0)
1123 arg = argv[i] + optlen;
1125 /* Otherwise, extra text at end means mismatch.
1126 Try other mappings. */
1131 else if (strchr (arginfo, '*') != 0)
1133 error ("incomplete `%s' option", option_map[j].name);
1137 /* Handle arguments. */
1138 if (strchr (arginfo, 'a') != 0)
1144 error ("missing argument to `%s' option",
1145 option_map[j].name);
1152 else if (strchr (arginfo, '*') != 0)
1154 else if (strchr (arginfo, 'o') == 0)
1157 error ("extraneous argument to `%s' option",
1158 option_map[j].name);
1162 /* Store the translation as one argv elt or as two. */
1163 if (arg != 0 && strchr (arginfo, 'j') != 0)
1164 newv[newindex++] = concat (option_map[j].equivalent, arg,
1168 newv[newindex++] = option_map[j].equivalent;
1169 newv[newindex++] = arg;
1172 newv[newindex++] = option_map[j].equivalent;
1180 /* Handle old-fashioned options--just copy them through,
1181 with their arguments. */
1182 else if (argv[i][0] == '-')
1184 const char *p = argv[i] + 1;
1188 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1189 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1190 else if (WORD_SWITCH_TAKES_ARG (p))
1191 nskip += WORD_SWITCH_TAKES_ARG (p);
1192 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
1195 else if (! strcmp (p, "Xlinker"))
1198 /* Watch out for an option at the end of the command line that
1199 is missing arguments, and avoid skipping past the end of the
1201 if (nskip + i > argc)
1206 newv[newindex++] = argv[i++];
1211 /* Ordinary operands, or +e options. */
1212 newv[newindex++] = argv[i++];
1227 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1228 be considered whitespace. */
1229 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1231 else if (*p == '\n' || *p == ' ' || *p == '\t')
1245 /* Structures to keep track of prefixes to try when looking for files. */
1249 const char *prefix; /* String to prepend to the path. */
1250 struct prefix_list *next; /* Next in linked list. */
1251 int require_machine_suffix; /* Don't use without machine_suffix. */
1252 /* 2 means try both machine_suffix and just_machine_suffix. */
1253 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1254 int priority; /* Sort key - priority within list */
1259 struct prefix_list *plist; /* List of prefixes to try */
1260 int max_len; /* Max length of a prefix in PLIST */
1261 const char *name; /* Name of this list (used in config stuff) */
1264 /* List of prefixes to try when looking for executables. */
1266 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1268 /* List of prefixes to try when looking for startup (crt0) files. */
1270 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1272 /* List of prefixes to try when looking for include files. */
1274 static struct path_prefix include_prefixes = { 0, 0, "include" };
1276 /* Suffix to attach to directories searched for commands.
1277 This looks like `MACHINE/VERSION/'. */
1279 static const char *machine_suffix = 0;
1281 /* Suffix to attach to directories searched for commands.
1282 This is just `MACHINE/'. */
1284 static const char *just_machine_suffix = 0;
1286 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1288 static const char *gcc_exec_prefix;
1290 /* Default prefixes to attach to command names. */
1292 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1293 #undef MD_EXEC_PREFIX
1294 #undef MD_STARTFILE_PREFIX
1295 #undef MD_STARTFILE_PREFIX_1
1298 /* If no prefixes defined, use the null string, which will disable them. */
1299 #ifndef MD_EXEC_PREFIX
1300 #define MD_EXEC_PREFIX ""
1302 #ifndef MD_STARTFILE_PREFIX
1303 #define MD_STARTFILE_PREFIX ""
1305 #ifndef MD_STARTFILE_PREFIX_1
1306 #define MD_STARTFILE_PREFIX_1 ""
1309 /* Supply defaults for the standard prefixes. */
1311 #ifndef STANDARD_EXEC_PREFIX
1312 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1314 #ifndef STANDARD_STARTFILE_PREFIX
1315 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1317 #ifndef TOOLDIR_BASE_PREFIX
1318 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1320 #ifndef STANDARD_BINDIR_PREFIX
1321 #define STANDARD_BINDIR_PREFIX "/usr/local/bin"
1324 static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1325 static const char *const standard_exec_prefix_1 = "/usr/lib/gcc/";
1326 static const char *md_exec_prefix = MD_EXEC_PREFIX;
1328 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1329 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1330 static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1331 static const char *const standard_startfile_prefix_1 = "/lib/";
1332 static const char *const standard_startfile_prefix_2 = "/usr/lib/";
1334 static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1335 static const char *tooldir_prefix;
1337 static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1339 /* Subdirectory to use for locating libraries. Set by
1340 set_multilib_dir based on the compilation options. */
1342 static const char *multilib_dir;
1344 /* Structure to keep track of the specs that have been defined so far.
1345 These are accessed using %(specname) or %[specname] in a compiler
1350 /* The following 2 fields must be first */
1351 /* to allow EXTRA_SPECS to be initialized */
1352 const char *name; /* name of the spec. */
1353 const char *ptr; /* available ptr if no static pointer */
1355 /* The following fields are not initialized */
1356 /* by EXTRA_SPECS */
1357 const char **ptr_spec; /* pointer to the spec itself. */
1358 struct spec_list *next; /* Next spec in linked list. */
1359 int name_len; /* length of the name */
1360 int alloc_p; /* whether string was allocated */
1363 #define INIT_STATIC_SPEC(NAME,PTR) \
1364 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1366 /* List of statically defined specs. */
1367 static struct spec_list static_specs[] =
1369 INIT_STATIC_SPEC ("asm", &asm_spec),
1370 INIT_STATIC_SPEC ("asm_debug", &asm_debug),
1371 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1372 INIT_STATIC_SPEC ("asm_options", &asm_options),
1373 INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1374 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1375 INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1376 INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
1377 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1378 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1379 INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1380 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1381 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1382 INIT_STATIC_SPEC ("link", &link_spec),
1383 INIT_STATIC_SPEC ("lib", &lib_spec),
1384 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1385 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1386 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1387 INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
1388 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1389 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1390 INIT_STATIC_SPEC ("version", &compiler_version),
1391 INIT_STATIC_SPEC ("multilib", &multilib_select),
1392 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1393 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1394 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1395 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1396 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1397 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1398 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1399 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1400 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1403 #ifdef EXTRA_SPECS /* additional specs needed */
1404 /* Structure to keep track of just the first two args of a spec_list.
1405 That is all that the EXTRA_SPECS macro gives us. */
1408 const char *const name;
1409 const char *const ptr;
1412 static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1413 static struct spec_list *extra_specs = (struct spec_list *) 0;
1416 /* List of dynamically allocates specs that have been defined so far. */
1418 static struct spec_list *specs = (struct spec_list *) 0;
1420 /* Add appropriate libgcc specs to OBSTACK, taking into account
1421 various permutations of -shared-libgcc, -shared, and such. */
1423 #ifdef ENABLE_SHARED_LIBGCC
1425 init_gcc_specs (obstack, shared_name, static_name, eh_name)
1426 struct obstack *obstack;
1427 const char *shared_name;
1428 const char *static_name;
1429 const char *eh_name;
1434 /* If we see -shared-libgcc, then use the shared version. */
1435 sprintf (buffer, "%%{shared-libgcc:%s %s}", shared_name, static_name);
1436 obstack_grow (obstack, buffer, strlen (buffer));
1437 /* If we see -static-libgcc, then use the static version. */
1438 sprintf (buffer, "%%{static-libgcc:%s %s}", static_name, eh_name);
1439 obstack_grow (obstack, buffer, strlen (buffer));
1440 /* Otherwise, if we see -shared, then use the shared version
1441 if using EH registration routines or static version without
1442 exception handling routines otherwise. */
1443 p = "%{!shared-libgcc:%{!static-libgcc:%{shared:";
1444 obstack_grow (obstack, p, strlen (p));
1446 sprintf (buffer, "%s}}}", static_name);
1448 sprintf (buffer, "%s}}}", shared_name);
1450 obstack_grow (obstack, buffer, strlen (buffer));
1451 /* Otherwise, use the static version. */
1453 "%%{!shared-libgcc:%%{!static-libgcc:%%{!shared:%s %s}}}",
1454 static_name, eh_name);
1455 obstack_grow (obstack, buffer, strlen (buffer));
1457 #endif /* ENABLE_SHARED_LIBGCC */
1459 /* Initialize the specs lookup routines. */
1464 struct spec_list *next = (struct spec_list *) 0;
1465 struct spec_list *sl = (struct spec_list *) 0;
1469 return; /* Already initialized. */
1472 notice ("Using built-in specs.\n");
1475 extra_specs = (struct spec_list *)
1476 xcalloc (sizeof (struct spec_list), ARRAY_SIZE (extra_specs_1));
1478 for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1480 sl = &extra_specs[i];
1481 sl->name = extra_specs_1[i].name;
1482 sl->ptr = extra_specs_1[i].ptr;
1484 sl->name_len = strlen (sl->name);
1485 sl->ptr_spec = &sl->ptr;
1490 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1492 sl = &static_specs[i];
1497 #ifdef ENABLE_SHARED_LIBGCC
1498 /* ??? If neither -shared-libgcc nor --static-libgcc was
1499 seen, then we should be making an educated guess. Some proposed
1500 heuristics for ELF include:
1502 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1503 program will be doing dynamic loading, which will likely
1504 need the shared libgcc.
1506 (2) If "-ldl", then it's also a fair bet that we're doing
1509 (3) For each ET_DYN we're linking against (either through -lfoo
1510 or /some/path/foo.so), check to see whether it or one of
1511 its dependencies depends on a shared libgcc.
1515 If the runtime is fixed to look for program headers instead
1516 of calling __register_frame_info at all, for each object,
1517 use the shared libgcc if any EH symbol referenced.
1519 If crtstuff is fixed to not invoke __register_frame_info
1520 automatically, for each object, use the shared libgcc if
1521 any non-empty unwind section found.
1523 Doing any of this probably requires invoking an external program to
1524 do the actual object file scanning. */
1526 const char *p = libgcc_spec;
1529 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1530 when given the proper command line arguments. */
1533 if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
1535 init_gcc_specs (&obstack,
1536 #ifdef NO_SHARED_LIBGCC_MULTILIB
1547 else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0)
1549 /* Ug. We don't know shared library extensions. Hope that
1550 systems that use this form don't do shared libraries. */
1551 init_gcc_specs (&obstack,
1552 #ifdef NO_SHARED_LIBGCC_MULTILIB
1565 obstack_1grow (&obstack, *p);
1566 in_sep = (*p == ' ');
1571 obstack_1grow (&obstack, '\0');
1572 libgcc_spec = obstack_finish (&obstack);
1575 #ifdef USE_AS_TRADITIONAL_FORMAT
1576 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1578 static const char tf[] = "--traditional-format ";
1579 obstack_grow (&obstack, tf, sizeof(tf) - 1);
1580 obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1581 asm_spec = obstack_finish (&obstack);
1585 /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1586 obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1);
1587 obstack_grow0 (&obstack, link_spec, strlen (link_spec));
1588 link_spec = obstack_finish (&obstack);
1594 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1595 removed; If the spec starts with a + then SPEC is added to the end of the
1599 set_spec (name, spec)
1603 struct spec_list *sl;
1604 const char *old_spec;
1605 int name_len = strlen (name);
1608 /* If this is the first call, initialize the statically allocated specs. */
1611 struct spec_list *next = (struct spec_list *) 0;
1612 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1614 sl = &static_specs[i];
1621 /* See if the spec already exists. */
1622 for (sl = specs; sl; sl = sl->next)
1623 if (name_len == sl->name_len && !strcmp (sl->name, name))
1628 /* Not found - make it. */
1629 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1630 sl->name = xstrdup (name);
1631 sl->name_len = name_len;
1632 sl->ptr_spec = &sl->ptr;
1634 *(sl->ptr_spec) = "";
1639 old_spec = *(sl->ptr_spec);
1640 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1641 ? concat (old_spec, spec + 1, NULL)
1646 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1649 /* Free the old spec. */
1650 if (old_spec && sl->alloc_p)
1651 free ((PTR) old_spec);
1656 /* Accumulate a command (program name and args), and run it. */
1658 /* Vector of pointers to arguments in the current line of specifications. */
1660 static const char **argbuf;
1662 /* Number of elements allocated in argbuf. */
1664 static int argbuf_length;
1666 /* Number of elements in argbuf currently in use (containing args). */
1668 static int argbuf_index;
1670 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1671 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1674 static struct temp_name {
1675 const char *suffix; /* suffix associated with the code. */
1676 int length; /* strlen (suffix). */
1677 int unique; /* Indicates whether %g or %u/%U was used. */
1678 const char *filename; /* associated filename. */
1679 int filename_length; /* strlen (filename). */
1680 struct temp_name *next;
1683 /* Number of commands executed so far. */
1685 static int execution_count;
1687 /* Number of commands that exited with a signal. */
1689 static int signal_count;
1691 /* Name with which this program was invoked. */
1693 static const char *programname;
1695 /* Clear out the vector of arguments (after a command is executed). */
1703 /* Add one argument to the vector at the end.
1704 This is done when a space is seen or at the end of the line.
1705 If DELETE_ALWAYS is nonzero, the arg is a filename
1706 and the file should be deleted eventually.
1707 If DELETE_FAILURE is nonzero, the arg is a filename
1708 and the file should be deleted if this compilation fails. */
1711 store_arg (arg, delete_always, delete_failure)
1713 int delete_always, delete_failure;
1715 if (argbuf_index + 1 == argbuf_length)
1717 = (const char **) xrealloc (argbuf,
1718 (argbuf_length *= 2) * sizeof (const char *));
1720 argbuf[argbuf_index++] = arg;
1721 argbuf[argbuf_index] = 0;
1723 if (delete_always || delete_failure)
1724 record_temp_file (arg, delete_always, delete_failure);
1727 /* Load specs from a file name named FILENAME, replacing occurrences of
1728 various different types of line-endings, \r\n, \n\r and just \r, with
1732 load_specs (filename)
1733 const char *filename;
1737 struct stat statbuf;
1744 notice ("Reading specs from %s\n", filename);
1746 /* Open and stat the file. */
1747 desc = open (filename, O_RDONLY, 0);
1749 pfatal_with_name (filename);
1750 if (stat (filename, &statbuf) < 0)
1751 pfatal_with_name (filename);
1753 /* Read contents of file into BUFFER. */
1754 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1755 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1757 pfatal_with_name (filename);
1758 buffer[readlen] = 0;
1761 specs = xmalloc (readlen + 1);
1763 for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
1769 if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
1771 else if (*(buffer_p + 1) == '\n') /* \r\n */
1785 /* Read compilation specs from a file named FILENAME,
1786 replacing the default ones.
1788 A suffix which starts with `*' is a definition for
1789 one of the machine-specific sub-specs. The "suffix" should be
1790 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1791 The corresponding spec is stored in asm_spec, etc.,
1792 rather than in the `compilers' vector.
1794 Anything invalid in the file is a fatal error. */
1797 read_specs (filename, main_p)
1798 const char *filename;
1804 buffer = load_specs (filename);
1806 /* Scan BUFFER for specs, putting them in the vector. */
1812 char *in, *out, *p1, *p2, *p3;
1814 /* Advance P in BUFFER to the next nonblank nocomment line. */
1815 p = skip_whitespace (p);
1819 /* Is this a special command that starts with '%'? */
1820 /* Don't allow this for the main specs file, since it would
1821 encourage people to overwrite it. */
1822 if (*p == '%' && !main_p)
1825 while (*p && *p != '\n')
1831 if (!strncmp (p1, "%include", sizeof ("%include") - 1)
1832 && (p1[sizeof "%include" - 1] == ' '
1833 || p1[sizeof "%include" - 1] == '\t'))
1837 p1 += sizeof ("%include");
1838 while (*p1 == ' ' || *p1 == '\t')
1841 if (*p1++ != '<' || p[-2] != '>')
1842 fatal ("specs %%include syntax malformed after %ld characters",
1843 (long) (p1 - buffer + 1));
1846 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1847 read_specs (new_filename ? new_filename : p1, FALSE);
1850 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1851 && (p1[sizeof "%include_noerr" - 1] == ' '
1852 || p1[sizeof "%include_noerr" - 1] == '\t'))
1856 p1 += sizeof "%include_noerr";
1857 while (*p1 == ' ' || *p1 == '\t')
1860 if (*p1++ != '<' || p[-2] != '>')
1861 fatal ("specs %%include syntax malformed after %ld characters",
1862 (long) (p1 - buffer + 1));
1865 new_filename = find_a_file (&startfile_prefixes, p1, R_OK);
1867 read_specs (new_filename, FALSE);
1868 else if (verbose_flag)
1869 notice ("could not find specs file %s\n", p1);
1872 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1873 && (p1[sizeof "%rename" - 1] == ' '
1874 || p1[sizeof "%rename" - 1] == '\t'))
1877 struct spec_list *sl;
1879 /* Get original name */
1880 p1 += sizeof "%rename";
1881 while (*p1 == ' ' || *p1 == '\t')
1884 if (! ISALPHA ((unsigned char) *p1))
1885 fatal ("specs %%rename syntax malformed after %ld characters",
1886 (long) (p1 - buffer));
1889 while (*p2 && !ISSPACE ((unsigned char) *p2))
1892 if (*p2 != ' ' && *p2 != '\t')
1893 fatal ("specs %%rename syntax malformed after %ld characters",
1894 (long) (p2 - buffer));
1898 while (*p2 == ' ' || *p2 == '\t')
1901 if (! ISALPHA ((unsigned char) *p2))
1902 fatal ("specs %%rename syntax malformed after %ld characters",
1903 (long) (p2 - buffer));
1905 /* Get new spec name. */
1907 while (*p3 && !ISSPACE ((unsigned char) *p3))
1911 fatal ("specs %%rename syntax malformed after %ld characters",
1912 (long) (p3 - buffer));
1915 for (sl = specs; sl; sl = sl->next)
1916 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1920 fatal ("specs %s spec was not found to be renamed", p1);
1922 if (strcmp (p1, p2) == 0)
1927 notice ("rename spec %s to %s\n", p1, p2);
1929 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1933 set_spec (p2, *(sl->ptr_spec));
1935 free ((PTR) *(sl->ptr_spec));
1937 *(sl->ptr_spec) = "";
1942 fatal ("specs unknown %% command after %ld characters",
1943 (long) (p1 - buffer));
1946 /* Find the colon that should end the suffix. */
1948 while (*p1 && *p1 != ':' && *p1 != '\n')
1951 /* The colon shouldn't be missing. */
1953 fatal ("specs file malformed after %ld characters",
1954 (long) (p1 - buffer));
1956 /* Skip back over trailing whitespace. */
1958 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
1961 /* Copy the suffix to a string. */
1962 suffix = save_string (p, p2 - p);
1963 /* Find the next line. */
1964 p = skip_whitespace (p1 + 1);
1966 fatal ("specs file malformed after %ld characters",
1967 (long) (p - buffer));
1970 /* Find next blank line or end of string. */
1971 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
1974 /* Specs end at the blank line and do not include the newline. */
1975 spec = save_string (p, p1 - p);
1978 /* Delete backslash-newline sequences from the spec. */
1983 if (in[0] == '\\' && in[1] == '\n')
1985 else if (in[0] == '#')
1986 while (*in && *in != '\n')
1994 if (suffix[0] == '*')
1996 if (! strcmp (suffix, "*link_command"))
1997 link_command_spec = spec;
1999 set_spec (suffix + 1, spec);
2003 /* Add this pair to the vector. */
2005 = ((struct compiler *)
2006 xrealloc (compilers,
2007 (n_compilers + 2) * sizeof (struct compiler)));
2009 compilers[n_compilers].suffix = suffix;
2010 compilers[n_compilers].spec = spec;
2012 memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
2016 link_command_spec = spec;
2019 if (link_command_spec == 0)
2020 fatal ("spec file has no spec for linking");
2023 /* Record the names of temporary files we tell compilers to write,
2024 and delete them at the end of the run. */
2026 /* This is the common prefix we use to make temp file names.
2027 It is chosen once for each run of this program.
2028 It is substituted into a spec by %g or %j.
2029 Thus, all temp file names contain this prefix.
2030 In practice, all temp file names start with this prefix.
2032 This prefix comes from the envvar TMPDIR if it is defined;
2033 otherwise, from the P_tmpdir macro if that is defined;
2034 otherwise, in /usr/tmp or /tmp;
2035 or finally the current directory if all else fails. */
2037 static const char *temp_filename;
2039 /* Length of the prefix. */
2041 static int temp_filename_length;
2043 /* Define the list of temporary files to delete. */
2048 struct temp_file *next;
2051 /* Queue of files to delete on success or failure of compilation. */
2052 static struct temp_file *always_delete_queue;
2053 /* Queue of files to delete on failure of compilation. */
2054 static struct temp_file *failure_delete_queue;
2056 /* Record FILENAME as a file to be deleted automatically.
2057 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2058 otherwise delete it in any case.
2059 FAIL_DELETE nonzero means delete it if a compilation step fails;
2060 otherwise delete it in any case. */
2063 record_temp_file (filename, always_delete, fail_delete)
2064 const char *filename;
2068 char *const name = xstrdup (filename);
2072 struct temp_file *temp;
2073 for (temp = always_delete_queue; temp; temp = temp->next)
2074 if (! strcmp (name, temp->name))
2077 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
2078 temp->next = always_delete_queue;
2080 always_delete_queue = temp;
2087 struct temp_file *temp;
2088 for (temp = failure_delete_queue; temp; temp = temp->next)
2089 if (! strcmp (name, temp->name))
2092 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
2093 temp->next = failure_delete_queue;
2095 failure_delete_queue = temp;
2101 /* Delete all the temporary files whose names we previously recorded. */
2104 delete_if_ordinary (name)
2111 printf ("Delete %s? (y or n) ", name);
2115 while ((c = getchar ()) != '\n' && c != EOF)
2118 if (i == 'y' || i == 'Y')
2120 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
2121 if (unlink (name) < 0)
2123 perror_with_name (name);
2127 delete_temp_files ()
2129 struct temp_file *temp;
2131 for (temp = always_delete_queue; temp; temp = temp->next)
2132 delete_if_ordinary (temp->name);
2133 always_delete_queue = 0;
2136 /* Delete all the files to be deleted on error. */
2139 delete_failure_queue ()
2141 struct temp_file *temp;
2143 for (temp = failure_delete_queue; temp; temp = temp->next)
2144 delete_if_ordinary (temp->name);
2148 clear_failure_queue ()
2150 failure_delete_queue = 0;
2153 /* Build a list of search directories from PATHS.
2154 PREFIX is a string to prepend to the list.
2155 If CHECK_DIR_P is non-zero we ensure the directory exists.
2156 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2157 It is also used by the --print-search-dirs flag. */
2160 build_search_list (paths, prefix, check_dir_p)
2161 struct path_prefix *paths;
2165 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
2167 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
2168 int first_time = TRUE;
2169 struct prefix_list *pprefix;
2171 obstack_grow (&collect_obstack, prefix, strlen (prefix));
2172 obstack_1grow (&collect_obstack, '=');
2174 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
2176 int len = strlen (pprefix->prefix);
2180 || is_directory (pprefix->prefix, machine_suffix, 0)))
2183 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2186 obstack_grow (&collect_obstack, pprefix->prefix, len);
2187 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
2190 if (just_machine_suffix
2191 && pprefix->require_machine_suffix == 2
2193 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
2196 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2199 obstack_grow (&collect_obstack, pprefix->prefix, len);
2200 obstack_grow (&collect_obstack, just_machine_suffix,
2204 if (! pprefix->require_machine_suffix)
2207 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2210 obstack_grow (&collect_obstack, pprefix->prefix, len);
2214 obstack_1grow (&collect_obstack, '\0');
2215 return obstack_finish (&collect_obstack);
2218 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2222 putenv_from_prefixes (paths, env_var)
2223 struct path_prefix *paths;
2224 const char *env_var;
2226 putenv (build_search_list (paths, env_var, 1));
2231 /* FIXME: the location independence code for VMS is hairier than this,
2232 and hasn't been written. */
2234 /* Split a filename into component directories. */
2237 split_directories (name, ptr_num_dirs)
2246 /* Count the number of directories. Special case MSDOS disk names as part
2247 of the initial directory. */
2249 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2250 if (name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2255 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2257 while ((ch = *p++) != '\0')
2259 if (IS_DIR_SEPARATOR (ch))
2262 while (IS_DIR_SEPARATOR (*p))
2267 dirs = (char **) xmalloc (sizeof (char *) * (num_dirs + 2));
2269 /* Now copy the directory parts. */
2272 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2273 if (name[1] == ':' && IS_DIR_SEPARATOR (name[2]))
2275 dirs[num_dirs++] = save_string (p, 3);
2278 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2281 while ((ch = *p++) != '\0')
2283 if (IS_DIR_SEPARATOR (ch))
2285 while (IS_DIR_SEPARATOR (*p))
2288 dirs[num_dirs++] = save_string (q, p - q);
2294 dirs[num_dirs++] = save_string (q, p - 1 - q);
2296 dirs[num_dirs] = NULL;
2298 *ptr_num_dirs = num_dirs;
2303 /* Release storage held by split directories. */
2306 free_split_directories (dirs)
2311 while (dirs[i] != NULL)
2314 free ((char *) dirs);
2317 /* Given three strings PROGNAME, BIN_PREFIX, PREFIX, return a string that gets
2318 to PREFIX starting with the directory portion of PROGNAME and a relative
2319 pathname of the difference between BIN_PREFIX and PREFIX.
2321 For example, if BIN_PREFIX is /alpha/beta/gamma/gcc/delta, PREFIX is
2322 /alpha/beta/gamma/omega/, and PROGNAME is /red/green/blue/gcc, then this
2323 function will return /red/green/blue/../omega.
2325 If no relative prefix can be found, return NULL. */
2328 make_relative_prefix (progname, bin_prefix, prefix)
2329 const char *progname;
2330 const char *bin_prefix;
2333 char **prog_dirs, **bin_dirs, **prefix_dirs;
2334 int prog_num, bin_num, prefix_num, std_loc_p;
2337 prog_dirs = split_directories (progname, &prog_num);
2338 bin_dirs = split_directories (bin_prefix, &bin_num);
2340 /* If there is no full pathname, try to find the program by checking in each
2341 of the directories specified in the PATH environment variable. */
2346 GET_ENV_PATH_LIST (temp, "PATH");
2349 char *startp, *endp, *nstore;
2350 size_t prefixlen = strlen (temp) + 1;
2354 nstore = (char *) alloca (prefixlen + strlen (progname) + 1);
2356 startp = endp = temp;
2359 if (*endp == PATH_SEPARATOR || *endp == 0)
2364 nstore[1] = DIR_SEPARATOR;
2369 strncpy (nstore, startp, endp - startp);
2370 if (! IS_DIR_SEPARATOR (endp[-1]))
2372 nstore[endp - startp] = DIR_SEPARATOR;
2373 nstore[endp - startp + 1] = 0;
2376 nstore[endp - startp] = 0;
2378 strcat (nstore, progname);
2379 if (! access (nstore, X_OK)
2380 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
2381 || ! access (strcat (nstore, HOST_EXECUTABLE_SUFFIX), X_OK)
2385 free_split_directories (prog_dirs);
2387 prog_dirs = split_directories (progname, &prog_num);
2393 endp = startp = endp + 1;
2401 /* Remove the program name from comparison of directory names. */
2404 /* Determine if the compiler is installed in the standard location, and if
2405 so, we don't need to specify relative directories. Also, if argv[0]
2406 doesn't contain any directory specifiers, there is not much we can do. */
2408 if (prog_num == bin_num)
2410 for (i = 0; i < bin_num; i++)
2412 if (strcmp (prog_dirs[i], bin_dirs[i]) != 0)
2416 if (prog_num <= 0 || i == bin_num)
2419 free_split_directories (prog_dirs);
2420 free_split_directories (bin_dirs);
2421 prog_dirs = bin_dirs = (char **) 0;
2426 prefix_dirs = split_directories (prefix, &prefix_num);
2428 /* Find how many directories are in common between bin_prefix & prefix. */
2429 n = (prefix_num < bin_num) ? prefix_num : bin_num;
2430 for (common = 0; common < n; common++)
2432 if (strcmp (bin_dirs[common], prefix_dirs[common]) != 0)
2436 /* If there are no common directories, there can be no relative prefix. */
2439 free_split_directories (prog_dirs);
2440 free_split_directories (bin_dirs);
2441 free_split_directories (prefix_dirs);
2445 /* Build up the pathnames in argv[0]. */
2446 for (i = 0; i < prog_num; i++)
2447 obstack_grow (&obstack, prog_dirs[i], strlen (prog_dirs[i]));
2449 /* Now build up the ..'s. */
2450 for (i = common; i < n; i++)
2452 obstack_grow (&obstack, DIR_UP, sizeof (DIR_UP) - 1);
2453 obstack_1grow (&obstack, DIR_SEPARATOR);
2456 /* Put in directories to move over to prefix. */
2457 for (i = common; i < prefix_num; i++)
2458 obstack_grow (&obstack, prefix_dirs[i], strlen (prefix_dirs[i]));
2460 free_split_directories (prog_dirs);
2461 free_split_directories (bin_dirs);
2462 free_split_directories (prefix_dirs);
2464 obstack_1grow (&obstack, '\0');
2465 return obstack_finish (&obstack);
2469 /* Check whether NAME can be accessed in MODE. This is like access,
2470 except that it never considers directories to be executable. */
2473 access_check (name, mode)
2481 if (stat (name, &st) < 0
2482 || S_ISDIR (st.st_mode))
2486 return access (name, mode);
2489 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2490 access to check permissions.
2491 Return 0 if not found, otherwise return its name, allocated with malloc. */
2494 find_a_file (pprefix, name, mode)
2495 struct path_prefix *pprefix;
2500 const char *const file_suffix =
2501 ((mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "");
2502 struct prefix_list *pl;
2503 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
2505 #ifdef DEFAULT_ASSEMBLER
2506 if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
2507 return xstrdup (DEFAULT_ASSEMBLER);
2510 #ifdef DEFAULT_LINKER
2511 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
2512 return xstrdup (DEFAULT_LINKER);
2516 len += strlen (machine_suffix);
2518 temp = xmalloc (len);
2520 /* Determine the filename to execute (special case for absolute paths). */
2522 if (IS_ABSOLUTE_PATHNAME (name))
2524 if (access (name, mode) == 0)
2526 strcpy (temp, name);
2531 for (pl = pprefix->plist; pl; pl = pl->next)
2535 /* Some systems have a suffix for executable files.
2536 So try appending that first. */
2537 if (file_suffix[0] != 0)
2539 strcpy (temp, pl->prefix);
2540 strcat (temp, machine_suffix);
2541 strcat (temp, name);
2542 strcat (temp, file_suffix);
2543 if (access_check (temp, mode) == 0)
2545 if (pl->used_flag_ptr != 0)
2546 *pl->used_flag_ptr = 1;
2551 /* Now try just the name. */
2552 strcpy (temp, pl->prefix);
2553 strcat (temp, machine_suffix);
2554 strcat (temp, name);
2555 if (access_check (temp, mode) == 0)
2557 if (pl->used_flag_ptr != 0)
2558 *pl->used_flag_ptr = 1;
2563 /* Certain prefixes are tried with just the machine type,
2564 not the version. This is used for finding as, ld, etc. */
2565 if (just_machine_suffix && pl->require_machine_suffix == 2)
2567 /* Some systems have a suffix for executable files.
2568 So try appending that first. */
2569 if (file_suffix[0] != 0)
2571 strcpy (temp, pl->prefix);
2572 strcat (temp, just_machine_suffix);
2573 strcat (temp, name);
2574 strcat (temp, file_suffix);
2575 if (access_check (temp, mode) == 0)
2577 if (pl->used_flag_ptr != 0)
2578 *pl->used_flag_ptr = 1;
2583 strcpy (temp, pl->prefix);
2584 strcat (temp, just_machine_suffix);
2585 strcat (temp, name);
2586 if (access_check (temp, mode) == 0)
2588 if (pl->used_flag_ptr != 0)
2589 *pl->used_flag_ptr = 1;
2594 /* Certain prefixes can't be used without the machine suffix
2595 when the machine or version is explicitly specified. */
2596 if (! pl->require_machine_suffix)
2598 /* Some systems have a suffix for executable files.
2599 So try appending that first. */
2600 if (file_suffix[0] != 0)
2602 strcpy (temp, pl->prefix);
2603 strcat (temp, name);
2604 strcat (temp, file_suffix);
2605 if (access_check (temp, mode) == 0)
2607 if (pl->used_flag_ptr != 0)
2608 *pl->used_flag_ptr = 1;
2613 strcpy (temp, pl->prefix);
2614 strcat (temp, name);
2615 if (access_check (temp, mode) == 0)
2617 if (pl->used_flag_ptr != 0)
2618 *pl->used_flag_ptr = 1;
2628 /* Ranking of prefixes in the sort list. -B prefixes are put before
2631 enum path_prefix_priority
2633 PREFIX_PRIORITY_B_OPT,
2634 PREFIX_PRIORITY_LAST
2637 /* Add an entry for PREFIX in PLIST. The PLIST is kept in assending
2638 order according to PRIORITY. Within each PRIORITY, new entries are
2641 If WARN is nonzero, we will warn if no file is found
2642 through this prefix. WARN should point to an int
2643 which will be set to 1 if this entry is used.
2645 COMPONENT is the value to be passed to update_path.
2647 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2648 the complete value of machine_suffix.
2649 2 means try both machine_suffix and just_machine_suffix. */
2652 add_prefix (pprefix, prefix, component, priority, require_machine_suffix, warn)
2653 struct path_prefix *pprefix;
2655 const char *component;
2656 /* enum prefix_priority */ int priority;
2657 int require_machine_suffix;
2660 struct prefix_list *pl, **prev;
2663 for (prev = &pprefix->plist;
2664 (*prev) != NULL && (*prev)->priority <= priority;
2665 prev = &(*prev)->next)
2668 /* Keep track of the longest prefix */
2670 prefix = update_path (prefix, component);
2671 len = strlen (prefix);
2672 if (len > pprefix->max_len)
2673 pprefix->max_len = len;
2675 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2676 pl->prefix = prefix;
2677 pl->require_machine_suffix = require_machine_suffix;
2678 pl->used_flag_ptr = warn;
2679 pl->priority = priority;
2683 /* Insert after PREV */
2688 /* Execute the command specified by the arguments on the current line of spec.
2689 When using pipes, this includes several piped-together commands
2690 with `|' between them.
2692 Return 0 if successful, -1 if failed. */
2698 int n_commands; /* # of command. */
2702 const char *prog; /* program name. */
2703 const char **argv; /* vector of args. */
2704 int pid; /* pid of process for this command. */
2707 struct command *commands; /* each command buffer with above info. */
2709 /* Count # of piped commands. */
2710 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2711 if (strcmp (argbuf[i], "|") == 0)
2714 /* Get storage for each command. */
2715 commands = (struct command *) alloca (n_commands * sizeof (struct command));
2717 /* Split argbuf into its separate piped processes,
2718 and record info about each one.
2719 Also search for the programs that are to be run. */
2721 commands[0].prog = argbuf[0]; /* first command. */
2722 commands[0].argv = &argbuf[0];
2723 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
2726 commands[0].argv[0] = string;
2728 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2729 if (strcmp (argbuf[i], "|") == 0)
2730 { /* each command. */
2731 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2732 fatal ("-pipe not supported");
2734 argbuf[i] = 0; /* termination of command args. */
2735 commands[n_commands].prog = argbuf[i + 1];
2736 commands[n_commands].argv = &argbuf[i + 1];
2737 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
2739 commands[n_commands].argv[0] = string;
2743 argbuf[argbuf_index] = 0;
2745 /* If -v, print what we are about to do, and maybe query. */
2749 /* For help listings, put a blank line between sub-processes. */
2750 if (print_help_list)
2751 fputc ('\n', stderr);
2753 /* Print each piped command as a separate line. */
2754 for (i = 0; i < n_commands; i++)
2756 const char *const *j;
2758 if (verbose_only_flag)
2760 for (j = commands[i].argv; *j; j++)
2763 fprintf (stderr, " \"");
2764 for (p = *j; *p; ++p)
2766 if (*p == '"' || *p == '\\' || *p == '$')
2767 fputc ('\\', stderr);
2770 fputc ('"', stderr);
2774 for (j = commands[i].argv; *j; j++)
2775 fprintf (stderr, " %s", *j);
2777 /* Print a pipe symbol after all but the last command. */
2778 if (i + 1 != n_commands)
2779 fprintf (stderr, " |");
2780 fprintf (stderr, "\n");
2783 if (verbose_only_flag != 0)
2786 notice ("\nGo ahead? (y or n) ");
2790 while (getchar () != '\n')
2793 if (i != 'y' && i != 'Y')
2798 /* Run each piped subprocess. */
2800 for (i = 0; i < n_commands; i++)
2802 char *errmsg_fmt, *errmsg_arg;
2803 const char *string = commands[i].argv[0];
2805 /* For some bizarre reason, the second argument of execvp() is
2806 char *const *, not const char *const *. */
2807 commands[i].pid = pexecute (string, (char *const *) commands[i].argv,
2808 programname, temp_filename,
2809 &errmsg_fmt, &errmsg_arg,
2810 ((i == 0 ? PEXECUTE_FIRST : 0)
2811 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2812 | (string == commands[i].prog
2813 ? PEXECUTE_SEARCH : 0)
2814 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2816 if (commands[i].pid == -1)
2817 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2819 if (string != commands[i].prog)
2820 free ((PTR) string);
2825 /* Wait for all the subprocesses to finish.
2826 We don't care what order they finish in;
2827 we know that N_COMMANDS waits will get them all.
2828 Ignore subprocesses that we don't know about,
2829 since they can be spawned by the process that exec'ed us. */
2833 #ifdef HAVE_GETRUSAGE
2835 double ut = 0.0, st = 0.0;
2838 for (i = 0; i < n_commands;)
2844 pid = pwait (commands[i].pid, &status, 0);
2848 #ifdef HAVE_GETRUSAGE
2851 /* getrusage returns the total resource usage of all children
2852 up to now. Copy the previous values into prus, get the
2853 current statistics, then take the difference. */
2856 getrusage (RUSAGE_CHILDREN, &rus);
2857 d.tv_sec = rus.ru_utime.tv_sec - prus.ru_utime.tv_sec;
2858 d.tv_usec = rus.ru_utime.tv_usec - prus.ru_utime.tv_usec;
2859 ut = (double) d.tv_sec + (double) d.tv_usec / 1.0e6;
2861 d.tv_sec = rus.ru_stime.tv_sec - prus.ru_stime.tv_sec;
2862 d.tv_usec = rus.ru_stime.tv_usec - prus.ru_stime.tv_usec;
2863 st = (double) d.tv_sec + (double) d.tv_usec / 1.0e6;
2867 for (j = 0; j < n_commands; j++)
2868 if (commands[j].pid == pid)
2871 if (WIFSIGNALED (status))
2874 /* SIGPIPE is a special case. It happens in -pipe mode
2875 when the compiler dies before the preprocessor is
2876 done, or the assembler dies before the compiler is
2877 done. There's generally been an error already, and
2878 this is just fallout. So don't generate another error
2879 unless we would otherwise have succeeded. */
2880 if (WTERMSIG (status) == SIGPIPE
2881 && (signal_count || greatest_status >= MIN_FATAL_STATUS))
2886 Internal error: %s (program %s)\n\
2887 Please submit a full bug report.\n\
2888 See %s for instructions.",
2889 strsignal (WTERMSIG (status)), commands[j].prog,
2894 else if (WIFEXITED (status)
2895 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2897 if (WEXITSTATUS (status) > greatest_status)
2898 greatest_status = WEXITSTATUS (status);
2901 #ifdef HAVE_GETRUSAGE
2902 if (report_times && ut + st != 0)
2903 notice ("# %s %.2f %.2f\n", commands[j].prog, ut, st);
2912 /* Find all the switches given to us
2913 and make a vector describing them.
2914 The elements of the vector are strings, one per switch given.
2915 If a switch uses following arguments, then the `part1' field
2916 is the switch itself and the `args' field
2917 is a null-terminated vector containing the following arguments.
2918 The `live_cond' field is:
2920 1 if the switch is true in a conditional spec,
2921 -1 if false (overridden by a later switch)
2922 -2 if this switch should be ignored (used in %{<S})
2923 The `validated' field is nonzero if any spec has looked at this switch;
2924 if it remains zero at the end of the run, it must be meaningless. */
2927 #define SWITCH_FALSE -1
2928 #define SWITCH_IGNORE -2
2929 #define SWITCH_LIVE 1
2936 unsigned char validated;
2937 unsigned char ordering;
2940 static struct switchstr *switches;
2942 static int n_switches;
2947 const char *language;
2950 /* Also a vector of input files specified. */
2952 static struct infile *infiles;
2956 /* This counts the number of libraries added by lang_specific_driver, so that
2957 we can tell if there were any user supplied any files or libraries. */
2959 static int added_libraries;
2961 /* And a vector of corresponding output files is made up later. */
2963 const char **outfiles;
2965 /* Used to track if none of the -B paths are used. */
2968 /* Used to track if standard path isn't used and -b or -V is specified. */
2969 static int warn_std;
2971 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2972 static int *warn_std_ptr = 0;
2975 #if defined(FREEBSD_NATIVE)
2976 #include <objformat.h>
2978 typedef enum { OBJFMT_UNKNOWN, OBJFMT_AOUT, OBJFMT_ELF } objf_t;
2980 static objf_t objformat = OBJFMT_UNKNOWN;
2985 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2987 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2988 is true if we should look for an executable suffix. DO_OBJ
2989 is true if we should look for an object suffix. */
2992 convert_filename (name, do_exe, do_obj)
2994 int do_exe ATTRIBUTE_UNUSED;
2995 int do_obj ATTRIBUTE_UNUSED;
2997 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3005 len = strlen (name);
3007 #ifdef HAVE_TARGET_OBJECT_SUFFIX
3008 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3009 if (do_obj && len > 2
3010 && name[len - 2] == '.'
3011 && name[len - 1] == 'o')
3013 obstack_grow (&obstack, name, len - 2);
3014 obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
3015 name = obstack_finish (&obstack);
3019 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3020 /* If there is no filetype, make it the executable suffix (which includes
3021 the "."). But don't get confused if we have just "-o". */
3022 if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
3025 for (i = len - 1; i >= 0; i--)
3026 if (IS_DIR_SEPARATOR (name[i]))
3029 for (i++; i < len; i++)
3033 obstack_grow (&obstack, name, len);
3034 obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
3035 strlen (TARGET_EXECUTABLE_SUFFIX));
3036 name = obstack_finish (&obstack);
3043 /* Display the command line switches accepted by gcc. */
3047 printf (_("Usage: %s [options] file...\n"), programname);
3048 fputs (_("Options:\n"), stdout);
3050 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout);
3051 fputs (_(" --help Display this information\n"), stdout);
3052 fputs (_(" --target-help Display target specific command line options\n"), stdout);
3054 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout);
3055 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout);
3056 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout);
3057 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout);
3058 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout);
3059 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout);
3060 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout);
3061 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout);
3062 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout);
3064 -print-multi-lib Display the mapping between command line options and\n\
3065 multiple library search directories\n"), stdout);
3066 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout);
3067 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout);
3068 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout);
3069 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout);
3070 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout);
3071 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout);
3072 fputs (_(" -time Time the execution of each subprocess\n"), stdout);
3073 fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout);
3074 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout);
3075 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout);
3076 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout);
3077 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout);
3078 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout);
3079 fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout);
3080 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout);
3081 fputs (_(" -S Compile only; do not assemble or link\n"), stdout);
3082 fputs (_(" -c Compile and assemble, but do not link\n"), stdout);
3083 fputs (_(" -o <file> Place the output into <file>\n"), stdout);
3085 -x <language> Specify the language of the following input files\n\
3086 Permissable languages include: c c++ assembler none\n\
3087 'none' means revert to the default behavior of\n\
3088 guessing the language based on the file's extension\n\
3092 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3093 passed on to the various sub-processes invoked by %s. In order to pass\n\
3094 other options on to these processes the -W<letter> options must be used.\n\
3097 /* The rest of the options are displayed by invocations of the various
3102 add_preprocessor_option (option, len)
3106 n_preprocessor_options++;
3108 if (! preprocessor_options)
3109 preprocessor_options
3110 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
3112 preprocessor_options
3113 = (char **) xrealloc (preprocessor_options,
3114 n_preprocessor_options * sizeof (char *));
3116 preprocessor_options [n_preprocessor_options - 1] =
3117 save_string (option, len);
3121 add_assembler_option (option, len)
3125 n_assembler_options++;
3127 if (! assembler_options)
3129 = (char **) xmalloc (n_assembler_options * sizeof (char *));
3132 = (char **) xrealloc (assembler_options,
3133 n_assembler_options * sizeof (char *));
3135 assembler_options [n_assembler_options - 1] = save_string (option, len);
3139 add_linker_option (option, len)
3145 if (! linker_options)
3147 = (char **) xmalloc (n_linker_options * sizeof (char *));
3150 = (char **) xrealloc (linker_options,
3151 n_linker_options * sizeof (char *));
3153 linker_options [n_linker_options - 1] = save_string (option, len);
3156 /* Create the vector `switches' and its contents.
3157 Store its length in `n_switches'. */
3160 process_command (argc, argv)
3162 const char *const *argv;
3167 const char *spec_lang = 0;
3168 int last_language_n_infiles;
3171 int lang_n_infiles = 0;
3172 #ifdef MODIFY_TARGET_NAME
3173 int is_modify_target_name;
3177 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX");
3181 added_libraries = 0;
3183 /* Figure compiler version from version string. */
3185 compiler_version = temp1 = xstrdup (version_string);
3187 for (; *temp1; ++temp1)
3196 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3197 see if we can create it from the pathname specified in argv[0]. */
3200 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3201 if (!gcc_exec_prefix)
3203 gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix,
3204 standard_exec_prefix);
3205 if (gcc_exec_prefix)
3206 putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
3210 if (gcc_exec_prefix)
3212 int len = strlen (gcc_exec_prefix);
3214 if (len > (int) sizeof ("/lib/gcc-lib/") - 1
3215 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
3217 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
3218 if (IS_DIR_SEPARATOR (*temp)
3219 && strncmp (temp + 1, "lib", 3) == 0
3220 && IS_DIR_SEPARATOR (temp[4])
3221 && strncmp (temp + 5, "gcc-lib", 7) == 0)
3222 len -= sizeof ("/lib/gcc-lib/") - 1;
3225 set_std_prefix (gcc_exec_prefix, len);
3226 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC",
3227 PREFIX_PRIORITY_LAST, 0, NULL);
3228 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
3229 PREFIX_PRIORITY_LAST, 0, NULL);
3232 /* COMPILER_PATH and LIBRARY_PATH have values
3233 that are lists of directory names with colons. */
3235 GET_ENV_PATH_LIST (temp, "COMPILER_PATH");
3238 const char *startp, *endp;
3239 char *nstore = (char *) alloca (strlen (temp) + 3);
3241 startp = endp = temp;
3244 if (*endp == PATH_SEPARATOR || *endp == 0)
3246 strncpy (nstore, startp, endp - startp);
3248 strcpy (nstore, concat (".", dir_separator_str, NULL));
3249 else if (!IS_DIR_SEPARATOR (endp[-1]))
3251 nstore[endp - startp] = DIR_SEPARATOR;
3252 nstore[endp - startp + 1] = 0;
3255 nstore[endp - startp] = 0;
3256 add_prefix (&exec_prefixes, nstore, 0,
3257 PREFIX_PRIORITY_LAST, 0, NULL);
3258 add_prefix (&include_prefixes,
3259 concat (nstore, "include", NULL),
3260 0, PREFIX_PRIORITY_LAST, 0, NULL);
3263 endp = startp = endp + 1;
3270 GET_ENV_PATH_LIST (temp, LIBRARY_PATH_ENV);
3273 const char *startp, *endp;
3274 char *nstore = (char *) alloca (strlen (temp) + 3);
3276 startp = endp = temp;
3279 if (*endp == PATH_SEPARATOR || *endp == 0)
3281 strncpy (nstore, startp, endp - startp);
3283 strcpy (nstore, concat (".", dir_separator_str, NULL));
3284 else if (!IS_DIR_SEPARATOR (endp[-1]))
3286 nstore[endp - startp] = DIR_SEPARATOR;
3287 nstore[endp - startp + 1] = 0;
3290 nstore[endp - startp] = 0;
3291 add_prefix (&startfile_prefixes, nstore, NULL,
3292 PREFIX_PRIORITY_LAST, 0, NULL);
3295 endp = startp = endp + 1;
3302 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3303 GET_ENV_PATH_LIST (temp, "LPATH");
3304 if (temp && *cross_compile == '0')
3306 const char *startp, *endp;
3307 char *nstore = (char *) alloca (strlen (temp) + 3);
3309 startp = endp = temp;
3312 if (*endp == PATH_SEPARATOR || *endp == 0)
3314 strncpy (nstore, startp, endp - startp);
3316 strcpy (nstore, concat (".", dir_separator_str, NULL));
3317 else if (!IS_DIR_SEPARATOR (endp[-1]))
3319 nstore[endp - startp] = DIR_SEPARATOR;
3320 nstore[endp - startp + 1] = 0;
3323 nstore[endp - startp] = 0;
3324 add_prefix (&startfile_prefixes, nstore, NULL,
3325 PREFIX_PRIORITY_LAST, 0, NULL);
3328 endp = startp = endp + 1;
3335 #if defined(FREEBSD_NATIVE)
3338 if (getobjformat (buf, sizeof buf, &argc, argv))
3339 if (strcmp (buf, "aout") == 0)
3340 objformat = OBJFMT_AOUT;
3341 else if (strcmp (buf, "elf") == 0)
3342 objformat = OBJFMT_ELF;
3344 fprintf(stderr, "Unrecognized object format: %s\n", buf);
3348 /* Options specified as if they appeared on the command line. */
3349 temp = getenv ("GCC_OPTIONS");
3350 if ((temp) && (strlen (temp) > 0))
3358 while (isspace (*temp))
3360 len = strlen (temp);
3361 envopts = (char *) xmalloc (len + 1);
3362 strcpy (envopts, temp);
3364 for (i = 0; i < (len - 1); i++)
3365 if ((isspace (envopts[i])) && ! (isspace (envopts[i+1])))
3368 new_argv = (char **) alloca ((optc + argc) * sizeof(char *));
3370 for (i = 0, new_argc = 1; new_argc <= optc; new_argc++)
3372 while (isspace (envopts[i]))
3374 new_argv[new_argc] = envopts + i;
3375 while (!isspace (envopts[i]) && (envopts[i] != '\0'))
3377 envopts[i++] = '\0';
3379 for (i = 1; i < argc; i++)
3380 new_argv[new_argc++] = argv[i];
3386 /* Convert new-style -- options to old-style. */
3387 translate_options (&argc, &argv);
3389 /* Do language-specific adjustment/addition of flags. */
3390 lang_specific_driver (&argc, &argv, &added_libraries);
3392 /* Scan argv twice. Here, the first time, just count how many switches
3393 there will be in their vector, and how many input files in theirs.
3394 Also parse any switches that determine the configuration name, such as -b.
3395 Here we also parse the switches that cc itself uses (e.g. -v). */
3397 for (i = 1; i < argc; i++)
3399 if (! strcmp (argv[i], "-dumpspecs"))
3401 struct spec_list *sl;
3403 for (sl = specs; sl; sl = sl->next)
3404 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
3405 if (link_command_spec)
3406 printf ("*link_command:\n%s\n\n", link_command_spec);
3409 else if (! strcmp (argv[i], "-dumpversion"))
3411 printf ("%s\n", spec_version);
3414 else if (! strcmp (argv[i], "-dumpmachine"))
3416 printf ("%s\n", spec_machine);
3419 else if (strcmp (argv[i], "-fversion") == 0)
3421 /* translate_options () has turned --version into -fversion. */
3422 printf (_("%s (GCC) %s\n"), programname, version_string);
3423 fputs (_("Copyright (C) 2002 Free Software Foundation, Inc.\n"),
3425 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
3426 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
3430 else if (strcmp (argv[i], "-fhelp") == 0)
3432 /* translate_options () has turned --help into -fhelp. */
3433 print_help_list = 1;
3435 /* We will be passing a dummy file on to the sub-processes. */
3439 /* CPP driver cannot obtain switch from cc1_options. */
3441 add_preprocessor_option ("--help", 6);
3442 add_assembler_option ("--help", 6);
3443 add_linker_option ("--help", 6);
3445 else if (strcmp (argv[i], "-ftarget-help") == 0)
3447 /* translate_options() has turned --target-help into -ftarget-help. */
3448 target_help_flag = 1;
3450 /* We will be passing a dummy file on to the sub-processes. */
3454 /* CPP driver cannot obtain switch from cc1_options. */
3456 add_preprocessor_option ("--target-help", 13);
3457 add_assembler_option ("--target-help", 13);
3458 add_linker_option ("--target-help", 13);
3460 else if (! strcmp (argv[i], "-pass-exit-codes"))
3462 pass_exit_codes = 1;
3465 else if (! strcmp (argv[i], "-print-search-dirs"))
3466 print_search_dirs = 1;
3467 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3468 print_file_name = "libgcc.a";
3469 else if (! strncmp (argv[i], "-print-file-name=", 17))
3470 print_file_name = argv[i] + 17;
3471 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3472 print_prog_name = argv[i] + 17;
3473 else if (! strcmp (argv[i], "-print-multi-lib"))
3474 print_multi_lib = 1;
3475 else if (! strcmp (argv[i], "-print-multi-directory"))
3476 print_multi_directory = 1;
3477 else if (! strncmp (argv[i], "-Wa,", 4))
3480 /* Pass the rest of this option to the assembler. */
3482 /* Split the argument at commas. */
3484 for (j = 4; argv[i][j]; j++)
3485 if (argv[i][j] == ',')
3487 add_assembler_option (argv[i] + prev, j - prev);
3491 /* Record the part after the last comma. */
3492 add_assembler_option (argv[i] + prev, j - prev);
3494 else if (! strncmp (argv[i], "-Wp,", 4))
3497 /* Pass the rest of this option to the preprocessor. */
3499 /* Split the argument at commas. */
3501 for (j = 4; argv[i][j]; j++)
3502 if (argv[i][j] == ',')
3504 add_preprocessor_option (argv[i] + prev, j - prev);
3508 /* Record the part after the last comma. */
3509 add_preprocessor_option (argv[i] + prev, j - prev);
3511 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3512 /* The +e options to the C++ front-end. */
3514 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3517 /* Split the argument at commas. */
3518 for (j = 3; argv[i][j]; j++)
3519 n_infiles += (argv[i][j] == ',');
3521 else if (strcmp (argv[i], "-Xlinker") == 0)
3524 fatal ("argument to `-Xlinker' is missing");
3529 else if (strcmp (argv[i], "-l") == 0)
3532 fatal ("argument to `-l' is missing");
3537 else if (strncmp (argv[i], "-l", 2) == 0)
3539 else if (strcmp (argv[i], "-save-temps") == 0)
3541 save_temps_flag = 1;
3544 else if (strcmp (argv[i], "-specs") == 0)
3546 struct user_specs *user = (struct user_specs *)
3547 xmalloc (sizeof (struct user_specs));
3549 fatal ("argument to `-specs' is missing");
3551 user->next = (struct user_specs *) 0;
3552 user->filename = argv[i];
3553 if (user_specs_tail)
3554 user_specs_tail->next = user;
3556 user_specs_head = user;
3557 user_specs_tail = user;
3559 else if (strncmp (argv[i], "-specs=", 7) == 0)
3561 struct user_specs *user = (struct user_specs *)
3562 xmalloc (sizeof (struct user_specs));
3563 if (strlen (argv[i]) == 7)
3564 fatal ("argument to `-specs=' is missing");
3566 user->next = (struct user_specs *) 0;
3567 user->filename = argv[i] + 7;
3568 if (user_specs_tail)
3569 user_specs_tail->next = user;
3571 user_specs_head = user;
3572 user_specs_tail = user;
3574 else if (strcmp (argv[i], "-time") == 0)
3576 else if (strcmp (argv[i], "-###") == 0)
3578 /* This is similar to -v except that there is no execution
3579 of the commands and the echoed arguments are quoted. It
3580 is intended for use in shell scripts to capture the
3581 driver-generated command line. */
3582 verbose_only_flag++;
3585 else if (argv[i][0] == '-' && argv[i][1] != 0)
3587 const char *p = &argv[i][1];
3594 if (p[1] == 0 && i + 1 == argc)
3595 fatal ("argument to `-b' is missing");
3597 spec_machine = argv[++i];
3599 spec_machine = p + 1;
3601 warn_std_ptr = &warn_std;
3609 if (p[1] == 0 && i + 1 == argc)
3610 fatal ("argument to `-B' is missing");
3616 len = strlen (value);
3618 /* Catch the case where the user has forgotten to append a
3619 directory separator to the path. Note, they may be using
3620 -B to add an executable name prefix, eg "i386-elf-", in
3621 order to distinguish between multiple installations of
3622 GCC in the same directory. Hence we must check to see
3623 if appending a directory separator actually makes a
3624 valid directory name. */
3625 if (! IS_DIR_SEPARATOR (value [len - 1])
3626 && is_directory (value, "", 0))
3628 char *tmp = xmalloc (len + 2);
3629 strcpy (tmp, value);
3630 tmp[len] = DIR_SEPARATOR;
3635 /* As a kludge, if the arg is "[foo/]stageN/", just
3636 add "[foo/]include" to the include prefix. */
3639 && (IS_DIR_SEPARATOR (value[len - 8]))))
3640 && strncmp (value + len - 7, "stage", 5) == 0
3641 && ISDIGIT (value[len - 2])
3642 && (IS_DIR_SEPARATOR (value[len - 1])))
3645 add_prefix (&include_prefixes, "include", NULL,
3646 PREFIX_PRIORITY_B_OPT, 0, NULL);
3649 char * string = xmalloc (len + 1);
3651 strncpy (string, value, len - 7);
3652 strcpy (string + len - 7, "include");
3653 add_prefix (&include_prefixes, string, NULL,
3654 PREFIX_PRIORITY_B_OPT, 0, NULL);
3658 add_prefix (&exec_prefixes, value, NULL,
3659 PREFIX_PRIORITY_B_OPT, 0, &warn_B);
3660 add_prefix (&startfile_prefixes, value, NULL,
3661 PREFIX_PRIORITY_B_OPT, 0, &warn_B);
3662 add_prefix (&include_prefixes, concat (value, "include", NULL),
3663 NULL, PREFIX_PRIORITY_B_OPT, 0, NULL);
3668 case 'v': /* Print our subcommands and print versions. */
3670 /* If they do anything other than exactly `-v', don't set
3671 verbose_flag; rather, continue on to give the error. */
3679 if (p[1] == 0 && i + 1 == argc)
3680 fatal ("argument to `-V' is missing");
3682 spec_version = argv[++i];
3684 spec_version = p + 1;
3685 compiler_version = spec_version;
3686 warn_std_ptr = &warn_std;
3688 /* Validate the version number. Use the same checks
3689 done when inserting it into a spec.
3691 The format of the version string is
3692 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3694 const char *v = compiler_version;
3696 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3697 while (! ISDIGIT (*v))
3700 if (v > compiler_version && v[-1] != '-')
3701 fatal ("invalid version number format");
3703 /* Set V after the first period. */
3704 while (ISDIGIT (*v))
3708 fatal ("invalid version number format");
3711 while (ISDIGIT (*v))
3714 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-')
3715 fatal ("invalid version number format");
3731 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3736 /* Forward scan, just in case -S or -c is specified
3743 if (argv[j][0] == '-')
3745 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3751 else if ((skip = SWITCH_TAKES_ARG (argv[j][1])))
3752 j += skip - (argv[j][2] != 0);
3753 else if ((skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1)))
3760 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
3762 argv[i + 1] = convert_filename (argv[i + 1], ! have_c, 0);
3764 argv[i] = convert_filename (argv[i], ! have_c, 0);
3771 #ifdef MODIFY_TARGET_NAME
3772 is_modify_target_name = 0;
3775 j < sizeof modify_target / sizeof modify_target[0]; j++)
3776 if (! strcmp (argv[i], modify_target[j].sw))
3779 = (char *) xmalloc (strlen (modify_target[j].str)
3780 + strlen (spec_machine));
3783 int made_addition = 0;
3785 is_modify_target_name = 1;
3786 for (p = spec_machine, q = new_name; *p != 0; )
3788 if (modify_target[j].add_del == DELETE
3789 && (! strncmp (q, modify_target[j].str,
3790 strlen (modify_target[j].str))))
3791 p += strlen (modify_target[j].str);
3792 else if (modify_target[j].add_del == ADD
3793 && ! made_addition && *p == '-')
3795 for (r = modify_target[j].str; *r != 0; )
3803 spec_machine = new_name;
3806 if (is_modify_target_name)
3812 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
3813 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
3814 else if (WORD_SWITCH_TAKES_ARG (p))
3815 i += WORD_SWITCH_TAKES_ARG (p);
3825 if (have_c && have_o && lang_n_infiles > 1)
3826 fatal ("cannot specify -o with -c or -S and multiple compilations");
3828 /* Set up the search paths before we go looking for config files. */
3830 /* These come before the md prefixes so that we will find gcc's subcommands
3831 (such as cpp) rather than those of the host system. */
3832 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3833 as well as trying the machine and the version. */
3834 #ifdef FREEBSD_NATIVE
3838 n_switches++; /* add implied -maout */
3839 add_prefix (&exec_prefixes, PREFIX"/libexec/aout/", "BINUTILS",
3843 add_prefix (&exec_prefixes, PREFIX"/libexec/elf/", "BINUTILS",
3846 case OBJFMT_UNKNOWN:
3847 fatal ("object format unknown");
3849 #endif /* FREEBSD_NATIVE */
3851 add_prefix (&exec_prefixes, standard_exec_prefix, "GCC",
3852 PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
3853 #ifndef FREEBSD_NATIVE
3854 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
3855 PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
3856 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
3857 PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
3858 #endif /* not FREEBSD_NATIVE */
3861 #ifndef FREEBSD_NATIVE
3862 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
3863 PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
3864 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS",
3865 PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
3866 #endif /* not FREEBSD_NATIVE */
3868 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
3869 dir_separator_str, NULL);
3871 /* If tooldir is relative, base it on exec_prefixes. A relative
3872 tooldir lets us move the installed tree as a unit.
3874 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3875 directories, so that we can search both the user specified directory
3876 and the standard place. */
3878 if (!IS_ABSOLUTE_PATHNAME (tooldir_prefix))
3880 if (gcc_exec_prefix)
3882 char *gcc_exec_tooldir_prefix
3883 = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
3884 spec_version, dir_separator_str, tooldir_prefix, NULL);
3886 add_prefix (&exec_prefixes,
3887 concat (gcc_exec_tooldir_prefix, "bin",
3888 dir_separator_str, NULL),
3889 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
3890 add_prefix (&startfile_prefixes,
3891 concat (gcc_exec_tooldir_prefix, "lib",
3892 dir_separator_str, NULL),
3893 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
3896 tooldir_prefix = concat (standard_exec_prefix, spec_machine,
3897 dir_separator_str, spec_version,
3898 dir_separator_str, tooldir_prefix, NULL);
3901 #ifndef FREEBSD_NATIVE
3902 add_prefix (&exec_prefixes,
3903 concat (tooldir_prefix, "bin", dir_separator_str, NULL),
3904 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
3905 add_prefix (&startfile_prefixes,
3906 concat (tooldir_prefix, "lib", dir_separator_str, NULL),
3907 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
3908 #endif /* FREEBSD_NATIVE */
3910 /* More prefixes are enabled in main, after we read the specs file
3911 and determine whether this is cross-compilation or not. */
3913 /* Then create the space for the vectors and scan again. */
3915 switches = ((struct switchstr *)
3916 xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
3917 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
3920 last_language_n_infiles = -1;
3922 /* This, time, copy the text of each switch and store a pointer
3923 to the copy in the vector of switches.
3924 Store all the infiles in their vector. */
3926 #if defined(FREEBSD_NATIVE)
3930 switches[n_switches].part1 = "maout";
3931 switches[n_switches].args = 0;
3932 switches[n_switches].live_cond = 0;
3933 switches[n_switches].validated = 0;
3935 putenv("OBJFORMAT=aout");
3938 putenv("OBJFORMAT=elf");
3940 case OBJFMT_UNKNOWN:
3941 fatal ("object format unknown");
3945 for (i = 1; i < argc; i++)
3947 /* Just skip the switches that were handled by the preceding loop. */
3948 #ifdef MODIFY_TARGET_NAME
3949 is_modify_target_name = 0;
3951 for (j = 0; j < sizeof modify_target / sizeof modify_target[0]; j++)
3952 if (! strcmp (argv[i], modify_target[j].sw))
3953 is_modify_target_name = 1;
3955 if (is_modify_target_name)
3959 if (! strncmp (argv[i], "-Wa,", 4))
3961 else if (! strncmp (argv[i], "-Wp,", 4))
3963 else if (! strcmp (argv[i], "-pass-exit-codes"))
3965 else if (! strcmp (argv[i], "-print-search-dirs"))
3967 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3969 else if (! strncmp (argv[i], "-print-file-name=", 17))
3971 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3973 else if (! strcmp (argv[i], "-print-multi-lib"))
3975 else if (! strcmp (argv[i], "-print-multi-directory"))
3977 else if (! strcmp (argv[i], "-ftarget-help"))
3979 else if (! strcmp (argv[i], "-fhelp"))
3981 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3983 /* Compensate for the +e options to the C++ front-end;
3984 they're there simply for cfront call-compatibility. We do
3985 some magic in default_compilers to pass them down properly.
3986 Note we deliberately start at the `+' here, to avoid passing
3987 -e0 or -e1 down into the linker. */
3988 switches[n_switches].part1 = &argv[i][0];
3989 switches[n_switches].args = 0;
3990 switches[n_switches].live_cond = SWITCH_OK;
3991 switches[n_switches].validated = 0;
3994 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3997 /* Split the argument at commas. */
3999 for (j = 4; argv[i][j]; j++)
4000 if (argv[i][j] == ',')
4002 infiles[n_infiles].language = "*";
4003 infiles[n_infiles++].name
4004 = save_string (argv[i] + prev, j - prev);
4007 /* Record the part after the last comma. */
4008 infiles[n_infiles].language = "*";
4009 infiles[n_infiles++].name = argv[i] + prev;
4011 else if (strcmp (argv[i], "-Xlinker") == 0)
4013 infiles[n_infiles].language = "*";
4014 infiles[n_infiles++].name = argv[++i];
4016 else if (strcmp (argv[i], "-l") == 0)
4017 { /* POSIX allows separation of -l and the lib arg;
4018 canonicalize by concatenating -l with its arg */
4019 infiles[n_infiles].language = "*";
4020 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
4022 else if (strncmp (argv[i], "-l", 2) == 0)
4024 infiles[n_infiles].language = "*";
4025 infiles[n_infiles++].name = argv[i];
4027 else if (strcmp (argv[i], "-specs") == 0)
4029 else if (strncmp (argv[i], "-specs=", 7) == 0)
4031 else if (strcmp (argv[i], "-time") == 0)
4033 else if ((save_temps_flag || report_times)
4034 && strcmp (argv[i], "-pipe") == 0)
4036 /* -save-temps overrides -pipe, so that temp files are produced */
4037 if (save_temps_flag)
4038 error ("warning: -pipe ignored because -save-temps specified");
4039 /* -time overrides -pipe because we can't get correct stats when
4040 multiple children are running at once. */
4041 else if (report_times)
4042 error ("warning: -pipe ignored because -time specified");
4044 else if (strcmp (argv[i], "-###") == 0)
4046 else if (argv[i][0] == '-' && argv[i][1] != 0)
4048 const char *p = &argv[i][1];
4053 if (p[1] == 0 && i + 1 == argc)
4054 fatal ("argument to `-x' is missing");
4056 spec_lang = argv[++i];
4059 if (! strcmp (spec_lang, "none"))
4060 /* Suppress the warning if -xnone comes after the last input
4061 file, because alternate command interfaces like g++ might
4062 find it useful to place -xnone after each input file. */
4065 last_language_n_infiles = n_infiles;
4068 switches[n_switches].part1 = p;
4069 /* Deal with option arguments in separate argv elements. */
4070 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
4071 || WORD_SWITCH_TAKES_ARG (p))
4074 int n_args = WORD_SWITCH_TAKES_ARG (p);
4078 /* Count only the option arguments in separate argv elements. */
4079 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
4081 if (i + n_args >= argc)
4082 fatal ("argument to `-%s' is missing", p);
4083 switches[n_switches].args
4084 = (const char **) xmalloc ((n_args + 1) * sizeof(const char *));
4086 switches[n_switches].args[j++] = argv[++i];
4087 /* Null-terminate the vector. */
4088 switches[n_switches].args[j] = 0;
4090 else if (strchr (switches_need_spaces, c))
4092 /* On some systems, ld cannot handle some options without
4093 a space. So split the option from its argument. */
4094 char *part1 = (char *) xmalloc (2);
4098 switches[n_switches].part1 = part1;
4099 switches[n_switches].args
4100 = (const char **) xmalloc (2 * sizeof (const char *));
4101 switches[n_switches].args[0] = xstrdup (p+1);
4102 switches[n_switches].args[1] = 0;
4105 switches[n_switches].args = 0;
4107 switches[n_switches].live_cond = SWITCH_OK;
4108 switches[n_switches].validated = 0;
4109 switches[n_switches].ordering = 0;
4110 /* These are always valid, since gcc.c itself understands it. */
4111 if (!strcmp (p, "save-temps")
4112 || !strcmp (p, "static-libgcc")
4113 || !strcmp (p, "shared-libgcc"))
4114 switches[n_switches].validated = 1;
4117 char ch = switches[n_switches].part1[0];
4118 if (ch == 'V' || ch == 'b' || ch == 'B')
4119 switches[n_switches].validated = 1;
4125 #ifdef HAVE_TARGET_OBJECT_SUFFIX
4126 argv[i] = convert_filename (argv[i], 0, access (argv[i], F_OK));
4129 if (strcmp (argv[i], "-") != 0 && access (argv[i], F_OK) < 0)
4131 perror_with_name (argv[i]);
4136 infiles[n_infiles].language = spec_lang;
4137 infiles[n_infiles++].name = argv[i];
4142 if (n_infiles == last_language_n_infiles && spec_lang != 0)
4143 error ("warning: `-x %s' after last input file has no effect", spec_lang);
4145 /* Ensure we only invoke each subprocess once. */
4146 if (target_help_flag || print_help_list)
4150 /* Create a dummy input file, so that we can pass --target-help on to
4151 the various sub-processes. */
4152 infiles[0].language = "c";
4153 infiles[0].name = "help-dummy";
4155 if (target_help_flag)
4157 switches[n_switches].part1 = "--target-help";
4158 switches[n_switches].args = 0;
4159 switches[n_switches].live_cond = SWITCH_OK;
4160 switches[n_switches].validated = 0;
4165 if (print_help_list)
4167 switches[n_switches].part1 = "--help";
4168 switches[n_switches].args = 0;
4169 switches[n_switches].live_cond = SWITCH_OK;
4170 switches[n_switches].validated = 0;
4176 switches[n_switches].part1 = 0;
4177 infiles[n_infiles].name = 0;
4180 /* Store switches not filtered out by %{<S} in spec in COLLECT_GCC_OPTIONS
4181 and place that in the environment. */
4184 set_collect_gcc_options ()
4189 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4191 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4192 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
4195 for (i = 0; (int) i < n_switches; i++)
4197 const char *const *args;
4200 obstack_grow (&collect_obstack, " ", 1);
4204 /* Ignore elided switches. */
4205 if (switches[i].live_cond == SWITCH_IGNORE)
4208 obstack_grow (&collect_obstack, "'-", 2);
4209 q = switches[i].part1;
4210 while ((p = strchr (q, '\'')))
4212 obstack_grow (&collect_obstack, q, p - q);
4213 obstack_grow (&collect_obstack, "'\\''", 4);
4216 obstack_grow (&collect_obstack, q, strlen (q));
4217 obstack_grow (&collect_obstack, "'", 1);
4219 for (args = switches[i].args; args && *args; args++)
4221 obstack_grow (&collect_obstack, " '", 2);
4223 while ((p = strchr (q, '\'')))
4225 obstack_grow (&collect_obstack, q, p - q);
4226 obstack_grow (&collect_obstack, "'\\''", 4);
4229 obstack_grow (&collect_obstack, q, strlen (q));
4230 obstack_grow (&collect_obstack, "'", 1);
4233 obstack_grow (&collect_obstack, "\0", 1);
4234 putenv (obstack_finish (&collect_obstack));
4237 /* Process a spec string, accumulating and running commands. */
4239 /* These variables describe the input file name.
4240 input_file_number is the index on outfiles of this file,
4241 so that the output file name can be stored for later use by %o.
4242 input_basename is the start of the part of the input file
4243 sans all directory names, and basename_length is the number
4244 of characters starting there excluding the suffix .c or whatever. */
4246 const char *input_filename;
4247 static int input_file_number;
4248 size_t input_filename_length;
4249 static int basename_length;
4250 static int suffixed_basename_length;
4251 static const char *input_basename;
4252 static const char *input_suffix;
4253 static struct stat input_stat;
4254 static int input_stat_set;
4256 /* The compiler used to process the current input file. */
4257 static struct compiler *input_file_compiler;
4259 /* These are variables used within do_spec and do_spec_1. */
4261 /* Nonzero if an arg has been started and not yet terminated
4262 (with space, tab or newline). */
4263 static int arg_going;
4265 /* Nonzero means %d or %g has been seen; the next arg to be terminated
4266 is a temporary file name. */
4267 static int delete_this_arg;
4269 /* Nonzero means %w has been seen; the next arg to be terminated
4270 is the output file name of this compilation. */
4271 static int this_is_output_file;
4273 /* Nonzero means %s has been seen; the next arg to be terminated
4274 is the name of a library file and we should try the standard
4275 search dirs for it. */
4276 static int this_is_library_file;
4278 /* Nonzero means that the input of this command is coming from a pipe. */
4279 static int input_from_pipe;
4281 /* Nonnull means substitute this for any suffix when outputting a switches
4283 static const char *suffix_subst;
4285 /* Process the spec SPEC and run the commands specified therein.
4286 Returns 0 if the spec is successfully processed; -1 if failed. */
4296 delete_this_arg = 0;
4297 this_is_output_file = 0;
4298 this_is_library_file = 0;
4299 input_from_pipe = 0;
4300 suffix_subst = NULL;
4302 value = do_spec_1 (spec, 0, NULL);
4304 /* Force out any unfinished command.
4305 If -pipe, this forces out the last command if it ended in `|'. */
4308 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
4311 set_collect_gcc_options ();
4313 if (argbuf_index > 0)
4320 /* Process the sub-spec SPEC as a portion of a larger spec.
4321 This is like processing a whole spec except that we do
4322 not initialize at the beginning and we do not supply a
4323 newline by default at the end.
4324 INSWITCH nonzero means don't process %-sequences in SPEC;
4325 in this case, % is treated as an ordinary character.
4326 This is used while substituting switches.
4327 INSWITCH nonzero also causes SPC not to terminate an argument.
4329 Value is zero unless a line was finished
4330 and the command on that line reported an error. */
4333 do_spec_1 (spec, inswitch, soft_matched_part)
4336 const char *soft_matched_part;
4338 const char *p = spec;
4345 /* If substituting a switch, treat all chars like letters.
4346 Otherwise, NL, SPC, TAB and % are special. */
4347 switch (inswitch ? 'a' : c)
4350 /* End of line: finish any pending argument,
4351 then run the pending command if one has been started. */
4354 obstack_1grow (&obstack, 0);
4355 string = obstack_finish (&obstack);
4356 if (this_is_library_file)
4357 string = find_file (string);
4358 store_arg (string, delete_this_arg, this_is_output_file);
4359 if (this_is_output_file)
4360 outfiles[input_file_number] = string;
4364 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
4366 for (i = 0; i < n_switches; i++)
4367 if (!strcmp (switches[i].part1, "pipe"))
4370 /* A `|' before the newline means use a pipe here,
4371 but only if -pipe was specified.
4372 Otherwise, execute now and don't pass the `|' as an arg. */
4375 input_from_pipe = 1;
4376 switches[i].validated = 1;
4383 set_collect_gcc_options ();
4385 if (argbuf_index > 0)
4391 /* Reinitialize for a new command, and for a new argument. */
4394 delete_this_arg = 0;
4395 this_is_output_file = 0;
4396 this_is_library_file = 0;
4397 input_from_pipe = 0;
4401 /* End any pending argument. */
4404 obstack_1grow (&obstack, 0);
4405 string = obstack_finish (&obstack);
4406 if (this_is_library_file)
4407 string = find_file (string);
4408 store_arg (string, delete_this_arg, this_is_output_file);
4409 if (this_is_output_file)
4410 outfiles[input_file_number] = string;
4414 obstack_1grow (&obstack, c);
4420 /* Space or tab ends an argument if one is pending. */
4423 obstack_1grow (&obstack, 0);
4424 string = obstack_finish (&obstack);
4425 if (this_is_library_file)
4426 string = find_file (string);
4427 store_arg (string, delete_this_arg, this_is_output_file);
4428 if (this_is_output_file)
4429 outfiles[input_file_number] = string;
4431 /* Reinitialize for a new argument. */
4433 delete_this_arg = 0;
4434 this_is_output_file = 0;
4435 this_is_library_file = 0;
4442 fatal ("invalid specification! Bug in cc");
4445 obstack_grow (&obstack, input_basename, basename_length);
4450 obstack_grow (&obstack, input_basename, suffixed_basename_length);
4455 delete_this_arg = 2;
4458 /* Dump out the directories specified with LIBRARY_PATH,
4459 followed by the absolute directories
4460 that we search for startfiles. */
4463 struct prefix_list *pl = startfile_prefixes.plist;
4464 size_t bufsize = 100;
4465 char *buffer = (char *) xmalloc (bufsize);
4468 for (; pl; pl = pl->next)
4470 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4471 /* Used on systems which record the specified -L dirs
4472 and use them to search for dynamic linking. */
4473 /* Relative directories always come from -B,
4474 and it is better not to use them for searching
4475 at run time. In particular, stage1 loses. */
4476 if (!IS_ABSOLUTE_PATHNAME (pl->prefix))
4479 /* Try subdirectory if there is one. */
4480 if (multilib_dir != NULL)
4484 if (strlen (pl->prefix) + strlen (machine_suffix)
4486 bufsize = (strlen (pl->prefix)
4487 + strlen (machine_suffix)) * 2 + 1;
4488 buffer = (char *) xrealloc (buffer, bufsize);
4489 strcpy (buffer, pl->prefix);
4490 strcat (buffer, machine_suffix);
4491 if (is_directory (buffer, multilib_dir, 1))
4493 do_spec_1 ("-L", 0, NULL);
4494 #ifdef SPACE_AFTER_L_OPTION
4495 do_spec_1 (" ", 0, NULL);
4497 do_spec_1 (buffer, 1, NULL);
4498 do_spec_1 (multilib_dir, 1, NULL);
4499 /* Make this a separate argument. */
4500 do_spec_1 (" ", 0, NULL);
4503 if (!pl->require_machine_suffix)
4505 if (is_directory (pl->prefix, multilib_dir, 1))
4507 do_spec_1 ("-L", 0, NULL);
4508 #ifdef SPACE_AFTER_L_OPTION
4509 do_spec_1 (" ", 0, NULL);
4511 do_spec_1 (pl->prefix, 1, NULL);
4512 do_spec_1 (multilib_dir, 1, NULL);
4513 /* Make this a separate argument. */
4514 do_spec_1 (" ", 0, NULL);
4520 if (is_directory (pl->prefix, machine_suffix, 1))
4522 do_spec_1 ("-L", 0, NULL);
4523 #ifdef SPACE_AFTER_L_OPTION
4524 do_spec_1 (" ", 0, NULL);
4526 do_spec_1 (pl->prefix, 1, NULL);
4527 /* Remove slash from machine_suffix. */
4528 if (strlen (machine_suffix) >= bufsize)
4529 bufsize = strlen (machine_suffix) * 2 + 1;
4530 buffer = (char *) xrealloc (buffer, bufsize);
4531 strcpy (buffer, machine_suffix);
4532 idx = strlen (buffer);
4533 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
4534 buffer[idx - 1] = 0;
4535 do_spec_1 (buffer, 1, NULL);
4536 /* Make this a separate argument. */
4537 do_spec_1 (" ", 0, NULL);
4540 if (!pl->require_machine_suffix)
4542 if (is_directory (pl->prefix, "", 1))
4544 do_spec_1 ("-L", 0, NULL);
4545 #ifdef SPACE_AFTER_L_OPTION
4546 do_spec_1 (" ", 0, NULL);
4548 /* Remove slash from pl->prefix. */
4549 if (strlen (pl->prefix) >= bufsize)
4550 bufsize = strlen (pl->prefix) * 2 + 1;
4551 buffer = (char *) xrealloc (buffer, bufsize);
4552 strcpy (buffer, pl->prefix);
4553 idx = strlen (buffer);
4554 if (IS_DIR_SEPARATOR (buffer[idx - 1]))
4555 buffer[idx - 1] = 0;
4556 do_spec_1 (buffer, 1, NULL);
4557 /* Make this a separate argument. */
4558 do_spec_1 (" ", 0, NULL);
4567 /* %efoo means report an error with `foo' as error message
4568 and don't execute any more commands for this file. */
4572 while (*p != 0 && *p != '\n')
4574 buf = (char *) alloca (p - q + 1);
4575 strncpy (buf, q, p - q);
4582 /* %nfoo means report an notice with `foo' on stderr. */
4586 while (*p != 0 && *p != '\n')
4588 buf = (char *) alloca (p - q + 1);
4589 strncpy (buf, q, p - q);
4591 notice ("%s\n", buf);
4601 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is defined,
4602 and it is not a directory, and it is writable, use it.
4603 Otherwise, fall through and treat this like any other
4606 if ((!save_temps_flag)
4607 && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
4608 && (access (HOST_BIT_BUCKET, W_OK) == 0))
4610 obstack_grow (&obstack, HOST_BIT_BUCKET,
4611 strlen (HOST_BIT_BUCKET));
4612 delete_this_arg = 0;
4621 struct temp_name *t;
4623 const char *suffix = p;
4624 char *saved_suffix = NULL;
4626 while (*p == '.' || ISALPHA ((unsigned char) *p))
4628 suffix_length = p - suffix;
4629 if (p[0] == '%' && p[1] == 'O')
4632 /* We don't support extra suffix characters after %O. */
4633 if (*p == '.' || ISALPHA ((unsigned char) *p))
4635 if (suffix_length == 0)
4636 suffix = TARGET_OBJECT_SUFFIX;
4640 = (char *) xmalloc (suffix_length
4641 + strlen (TARGET_OBJECT_SUFFIX));
4642 strncpy (saved_suffix, suffix, suffix_length);
4643 strcpy (saved_suffix + suffix_length,
4644 TARGET_OBJECT_SUFFIX);
4646 suffix_length += strlen (TARGET_OBJECT_SUFFIX);
4649 /* If the input_filename has the same suffix specified
4650 for the %g, %u, or %U, and -save-temps is specified,
4651 we could end up using that file as an intermediate
4652 thus clobbering the user's source file (.e.g.,
4653 gcc -save-temps foo.s would clobber foo.s with the
4654 output of cpp0). So check for this condition and
4655 generate a temp file as the intermediate. */
4657 if (save_temps_flag)
4659 temp_filename_length = basename_length + suffix_length;
4660 temp_filename = alloca (temp_filename_length + 1);
4661 strncpy ((char *) temp_filename, input_basename, basename_length);
4662 strncpy ((char *) temp_filename + basename_length, suffix,
4664 *((char *) temp_filename + temp_filename_length) = '\0';
4665 if (strcmp (temp_filename, input_filename) != 0)
4667 struct stat st_temp;
4669 /* Note, set_input() resets input_stat_set to 0. */
4670 if (input_stat_set == 0)
4672 input_stat_set = stat (input_filename, &input_stat);
4673 if (input_stat_set >= 0)
4677 /* If we have the stat for the input_filename
4678 and we can do the stat for the temp_filename
4679 then the they could still refer to the same
4680 file if st_dev/st_ino's are the same. */
4682 if (input_stat_set != 1
4683 || stat (temp_filename, &st_temp) < 0
4684 || input_stat.st_dev != st_temp.st_dev
4685 || input_stat.st_ino != st_temp.st_ino)
4687 temp_filename = save_string (temp_filename,
4688 temp_filename_length + 1);
4689 obstack_grow (&obstack, temp_filename,
4690 temp_filename_length);
4697 /* See if we already have an association of %g/%u/%U and
4699 for (t = temp_names; t; t = t->next)
4700 if (t->length == suffix_length
4701 && strncmp (t->suffix, suffix, suffix_length) == 0
4702 && t->unique == (c != 'g'))
4705 /* Make a new association if needed. %u and %j
4707 if (t == 0 || c == 'u' || c == 'j')
4711 t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
4712 t->next = temp_names;
4715 t->length = suffix_length;
4718 t->suffix = saved_suffix;
4719 saved_suffix = NULL;
4722 t->suffix = save_string (suffix, suffix_length);
4723 t->unique = (c != 'g');
4724 temp_filename = make_temp_file (t->suffix);
4725 temp_filename_length = strlen (temp_filename);
4726 t->filename = temp_filename;
4727 t->filename_length = temp_filename_length;
4731 free (saved_suffix);
4733 obstack_grow (&obstack, t->filename, t->filename_length);
4734 delete_this_arg = 1;
4740 obstack_grow (&obstack, input_filename, input_filename_length);
4746 struct prefix_list *pl = include_prefixes.plist;
4748 if (gcc_exec_prefix)
4750 do_spec_1 ("-iprefix", 1, NULL);
4751 /* Make this a separate argument. */
4752 do_spec_1 (" ", 0, NULL);
4753 do_spec_1 (gcc_exec_prefix, 1, NULL);
4754 do_spec_1 (" ", 0, NULL);
4757 for (; pl; pl = pl->next)
4759 do_spec_1 ("-isystem", 1, NULL);
4760 /* Make this a separate argument. */
4761 do_spec_1 (" ", 0, NULL);
4762 do_spec_1 (pl->prefix, 1, NULL);
4763 do_spec_1 (" ", 0, NULL);
4770 int max = n_infiles;
4771 max += lang_specific_extra_outfiles;
4773 for (i = 0; i < max; i++)
4775 store_arg (outfiles[i], 0, 0);
4780 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
4785 this_is_library_file = 1;
4789 this_is_output_file = 1;
4794 int cur_index = argbuf_index;
4795 /* Handle the {...} following the %W. */
4798 p = handle_braces (p + 1);
4801 /* If any args were output, mark the last one for deletion
4803 if (argbuf_index != cur_index)
4804 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
4808 /* %x{OPTION} records OPTION for %X to output. */
4814 /* Skip past the option value and make a copy. */
4819 string = save_string (p1 + 1, p - p1 - 2);
4821 /* See if we already recorded this option. */
4822 for (i = 0; i < n_linker_options; i++)
4823 if (! strcmp (string, linker_options[i]))
4829 /* This option is new; add it. */
4830 add_linker_option (string, strlen (string));
4834 /* Dump out the options accumulated previously using %x. */
4836 for (i = 0; i < n_linker_options; i++)
4838 do_spec_1 (linker_options[i], 1, NULL);
4839 /* Make each accumulated option a separate argument. */
4840 do_spec_1 (" ", 0, NULL);
4844 /* Dump out the options accumulated previously using -Wa,. */
4846 for (i = 0; i < n_assembler_options; i++)
4848 do_spec_1 (assembler_options[i], 1, NULL);
4849 /* Make each accumulated option a separate argument. */
4850 do_spec_1 (" ", 0, NULL);
4854 /* Dump out the options accumulated previously using -Wp,. */
4856 for (i = 0; i < n_preprocessor_options; i++)
4858 do_spec_1 (preprocessor_options[i], 1, NULL);
4859 /* Make each accumulated option a separate argument. */
4860 do_spec_1 (" ", 0, NULL);
4864 /* Here are digits and numbers that just process
4865 a certain constant string as a spec. */
4868 value = do_spec_1 (cc1_spec, 0, NULL);
4874 value = do_spec_1 (cc1plus_spec, 0, NULL);
4880 value = do_spec_1 (asm_spec, 0, NULL);
4886 value = do_spec_1 (asm_final_spec, 0, NULL);
4892 value = do_spec_1 (signed_char_spec, 0, NULL);
4899 const char *const spec
4900 = (input_file_compiler->cpp_spec
4901 ? input_file_compiler->cpp_spec
4903 value = do_spec_1 (spec, 0, NULL);
4910 value = do_spec_1 (endfile_spec, 0, NULL);
4916 value = do_spec_1 (link_spec, 0, NULL);
4922 value = do_spec_1 (lib_spec, 0, NULL);
4928 value = do_spec_1 (libgcc_spec, 0, NULL);
4934 if (multilib_dir && strcmp (multilib_dir, ".") != 0)
4940 len = strlen (multilib_dir);
4941 obstack_blank (&obstack, len + 1);
4942 p = obstack_next_free (&obstack) - (len + 1);
4945 for (q = multilib_dir; *q ; ++q, ++p)
4946 *p = (IS_DIR_SEPARATOR (*q) ? '_' : *q);
4952 char *x = (char *) alloca (strlen (cpp_predefines) + 1);
4956 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4960 if (! strncmp (y, "-D", 2))
4961 /* Copy the whole option. */
4962 while (*y && *y != ' ' && *y != '\t')
4964 else if (*y == ' ' || *y == '\t')
4965 /* Copy whitespace to the result. */
4967 /* Don't copy other options. */
4974 value = do_spec_1 (buf, 0, NULL);
4982 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
4986 /* Copy all of CPP_PREDEFINES into BUF,
4987 but force them all into the reserved name space if they
4988 aren't already there. The reserved name space is all
4989 identifiers beginning with two underscores or with one
4990 underscore and a capital letter. We do the forcing by
4991 adding up to two underscores to the beginning and end
4992 of each symbol. e.g. mips, _mips, mips_, and _mips_ all
4997 if (! strncmp (y, "-D", 2))
5006 && ! ISUPPER ((unsigned char) *(y + 1))))
5008 /* Stick __ at front of macro name. */
5012 /* Arrange to stick __ at the end as well. */
5016 /* Copy the macro name. */
5017 while (*y && *y != '=' && *y != ' ' && *y != '\t')
5030 /* Copy the value given, if any. */
5031 while (*y && *y != ' ' && *y != '\t')
5034 else if (*y == ' ' || *y == '\t')
5035 /* Copy whitespace to the result. */
5037 /* Don't copy -A options */
5043 /* Copy all of CPP_PREDEFINES into BUF,
5044 but put __ after every -D. */
5048 if (! strncmp (y, "-D", 2))
5054 && ! ISUPPER ((unsigned char) *(y + 1))))
5056 /* Stick -D__ at front of macro name. */
5063 /* Copy the macro name. */
5064 while (*y && *y != '=' && *y != ' ' && *y != '\t')
5067 /* Copy the value given, if any. */
5068 while (*y && *y != ' ' && *y != '\t')
5073 /* Do not copy this macro - we have just done it before */
5074 while (*y && *y != ' ' && *y != '\t')
5078 else if (*y == ' ' || *y == '\t')
5079 /* Copy whitespace to the result. */
5081 /* Don't copy -A options. */
5087 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
5091 if (! strncmp (y, "-A", 2))
5092 /* Copy the whole option. */
5093 while (*y && *y != ' ' && *y != '\t')
5095 else if (*y == ' ' || *y == '\t')
5096 /* Copy whitespace to the result. */
5098 /* Don't copy other options. */
5105 value = do_spec_1 (buf, 0, NULL);
5112 value = do_spec_1 (startfile_spec, 0, NULL);
5117 /* Here we define characters other than letters and digits. */
5120 p = handle_braces (p);
5126 obstack_1grow (&obstack, '%');
5133 while (p[len] && p[len] != ' ' && p[len] != '%')
5135 suffix_subst = save_string (p - 1, len + 1);
5141 if (soft_matched_part)
5143 do_spec_1 (soft_matched_part, 1, NULL);
5144 do_spec_1 (" ", 0, NULL);
5147 /* Catch the case where a spec string contains something like
5148 '%{foo:%*}'. ie there is no * in the pattern on the left
5149 hand side of the :. */
5150 error ("spec failure: '%%*' has not been initialized by pattern match");
5153 /* Process a string found as the value of a spec given by name.
5154 This feature allows individual machine descriptions
5155 to add and use their own specs.
5156 %[...] modifies -D options the way %P does;
5157 %(...) uses the spec unmodified. */
5159 error ("warning: use of obsolete %%[ operator in specs");
5162 const char *name = p;
5163 struct spec_list *sl;
5166 /* The string after the S/P is the name of a spec that is to be
5168 while (*p && *p != ')' && *p != ']')
5171 /* See if it's in the list. */
5172 for (len = p - name, sl = specs; sl; sl = sl->next)
5173 if (sl->name_len == len && !strncmp (sl->name, name, len))
5175 name = *(sl->ptr_spec);
5177 notice ("Processing spec %c%s%c, which is '%s'\n",
5178 c, sl->name, (c == '(') ? ')' : ']', name);
5187 value = do_spec_1 (name, 0, NULL);
5193 char *x = (char *) alloca (strlen (name) * 2 + 1);
5195 const char *y = name;
5198 /* Copy all of NAME into BUF, but put __ after
5199 every -D and at the end of each arg. */
5202 if (! strncmp (y, "-D", 2))
5213 && (*y == ' ' || *y == '\t' || *y == '='
5214 || *y == '}' || *y == 0))
5227 value = do_spec_1 (buf, 0, NULL);
5233 /* Discard the closing paren or bracket. */
5241 int c1 = *p++; /* Select first or second version number. */
5242 const char *v = compiler_version;
5244 static const char zeroc = '0';
5246 /* The format of the version string is
5247 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
5249 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
5250 while (! ISDIGIT (*v))
5252 if (v > compiler_version && v[-1] != '-')
5255 /* If desired, advance to second version number. */
5258 /* Set V after the first period. */
5259 while (ISDIGIT (*v))
5266 /* If desired, advance to third version number.
5267 But don't complain if it's not present */
5270 /* Set V after the second period. */
5271 while (ISDIGIT (*v))
5273 if ((*v != 0) && (*v != ' ') && (*v != '.') && (*v != '-'))
5279 /* Set Q at the next period or at the end. */
5281 while (ISDIGIT (*q))
5283 if (*q != 0 && q > v && *q != ' ' && *q != '.' && *q != '-')
5287 /* Put that part into the command. */
5288 obstack_grow (&obstack, v, q - v);
5290 /* Default to "0" */
5291 obstack_grow (&obstack, &zeroc, 1);
5297 if (input_from_pipe)
5298 do_spec_1 ("-", 0, NULL);
5302 error ("spec failure: unrecognized spec option '%c'", c);
5308 /* Backslash: treat next character as ordinary. */
5313 /* Ordinary character: put it into the current argument. */
5314 obstack_1grow (&obstack, c);
5318 /* End of string. */
5322 /* Return 0 if we call do_spec_1 and that returns -1. */
5328 const char *filter, *body = NULL, *endbody = NULL;
5330 int true_once = 0; /* If, in %{a|b:d}, at least one of a,b was seen. */
5333 int include_blanks = 1;
5334 int elide_switch = 0;
5339 /* A '^' after the open-brace means to not give blanks before args. */
5346 /* A `|' after the open-brace means,
5347 if the test fails, output a single minus sign rather than nothing.
5348 This is used in %{|!pipe:...}. */
5355 /* A `<' after the open-brace means that the switch should be
5356 removed from the command-line. */
5362 negate = suffix = 0;
5365 /* A `!' after the open-brace negates the condition:
5366 succeed if the specified switch is not present. */
5370 /* A `.' after the open-brace means test against the current suffix. */
5379 if (elide_switch && (negate || pipe_p || suffix))
5381 /* It doesn't make sense to mix elision with other flags. We
5382 could fatal() here, but the standard seems to be to abort. */
5388 while (*p != ':' && *p != '}' && *p != '|' && *p != '&')
5391 if (*p == '|' && (pipe_p || ordered))
5396 if (*p != '}' && *p != '&')
5412 fatal ("mismatched braces in specs");
5418 body = p, endbody = p + 1;
5423 int found = (input_suffix != 0
5424 && (long) strlen (input_suffix) == (long) (p - filter)
5425 && strncmp (input_suffix, filter, p - filter) == 0);
5431 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL) < 0)
5434 else if (p[-1] == '*' && (p[0] == '}' || p[0] == '&'))
5436 /* Substitute all matching switches as separate args. */
5439 for (i = 0; i < n_switches; i++)
5440 if (!strncmp (switches[i].part1, filter, p - 1 - filter)
5441 && check_live_switch (i, p - 1 - filter))
5445 switches[i].live_cond = SWITCH_IGNORE;
5446 switches[i].validated = 1;
5449 ordered = 1, switches[i].ordering = 1;
5454 /* Test for presence of the specified switch. */
5458 /* If name specified ends in *, as in {x*:...},
5459 check for %* and handle that case. */
5460 if (p[-1] == '*' && !negate)
5463 const char *r = body;
5465 /* First see whether we have %*. */
5469 if (*r == '%' && r[1] == '*')
5473 /* If we do, handle that case. */
5476 /* Substitute all matching switches as separate args.
5477 But do this by substituting for %*
5478 in the text that follows the colon. */
5480 unsigned hard_match_len = p - filter - 1;
5481 char *string = save_string (body, endbody - body - 1);
5483 for (i = 0; i < n_switches; i++)
5484 if (!strncmp (switches[i].part1, filter, hard_match_len)
5485 && check_live_switch (i, -1))
5487 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
5488 /* Pass any arguments this switch has. */
5489 give_switch (i, 1, 1);
5490 suffix_subst = NULL;
5493 /* We didn't match. Try again. */
5500 /* If name specified ends in *, as in {x*:...},
5501 check for presence of any switch name starting with x. */
5504 for (i = 0; i < n_switches; i++)
5506 unsigned hard_match_len = p - filter - 1;
5508 if (!strncmp (switches[i].part1, filter, hard_match_len)
5509 && check_live_switch (i, hard_match_len))
5516 /* Otherwise, check for presence of exact name specified. */
5519 for (i = 0; i < n_switches; i++)
5521 if (!strncmp (switches[i].part1, filter, p - filter)
5522 && switches[i].part1[p - filter] == 0
5523 && check_live_switch (i, -1))
5531 /* If it is as desired (present for %{s...}, absent for %{!s...})
5532 then substitute either the switch or the specified
5533 conditional text. */
5534 if (present != negate)
5538 switches[i].live_cond = SWITCH_IGNORE;
5539 switches[i].validated = 1;
5541 else if (ordered || *p == '&')
5542 ordered = 1, switches[i].ordering = 1;
5544 give_switch (i, 0, include_blanks);
5546 /* Even if many alternatives are matched, only output once. */
5551 /* Here if a %{|...} conditional fails: output a minus sign,
5552 which means "standard output" or "standard input". */
5553 do_spec_1 ("-", 0, NULL);
5558 /* We didn't match; try again. */
5565 goto next_ampersand;
5571 /* Doing this set of switches later preserves their command-line
5572 ordering. This is needed for e.g. -U, -D and -A. */
5573 for (i = 0; i < n_switches; i++)
5574 if (switches[i].ordering == 1)
5576 switches[i].ordering = 0;
5577 give_switch (i, 0, include_blanks);
5580 /* Process the spec just once, regardless of match count. */
5583 if (do_spec_1 (save_string (body, endbody - body - 1),
5591 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
5592 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
5593 spec, or -1 if either exact match or %* is used.
5595 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
5596 whose value does not begin with "no-" is obsoleted by the same value
5597 with the "no-", similarly for a switch with the "no-" prefix. */
5600 check_live_switch (switchnum, prefix_length)
5604 const char *name = switches[switchnum].part1;
5607 /* In the common case of {<at-most-one-letter>*}, a negating
5608 switch would always match, so ignore that case. We will just
5609 send the conflicting switches to the compiler phase. */
5610 if (prefix_length >= 0 && prefix_length <= 1)
5613 /* If we already processed this switch and determined if it was
5614 live or not, return our past determination. */
5615 if (switches[switchnum].live_cond != 0)
5616 return switches[switchnum].live_cond > 0;
5618 /* Now search for duplicate in a manner that depends on the name. */
5622 for (i = switchnum + 1; i < n_switches; i++)
5623 if (switches[i].part1[0] == 'O')
5625 switches[switchnum].validated = 1;
5626 switches[switchnum].live_cond = SWITCH_FALSE;
5631 case 'W': case 'f': case 'm':
5632 if (! strncmp (name + 1, "no-", 3))
5634 /* We have Xno-YYY, search for XYYY. */
5635 for (i = switchnum + 1; i < n_switches; i++)
5636 if (switches[i].part1[0] == name[0]
5637 && ! strcmp (&switches[i].part1[1], &name[4]))
5639 switches[switchnum].validated = 1;
5640 switches[switchnum].live_cond = SWITCH_FALSE;
5646 /* We have XYYY, search for Xno-YYY. */
5647 for (i = switchnum + 1; i < n_switches; i++)
5648 if (switches[i].part1[0] == name[0]
5649 && switches[i].part1[1] == 'n'
5650 && switches[i].part1[2] == 'o'
5651 && switches[i].part1[3] == '-'
5652 && !strcmp (&switches[i].part1[4], &name[1]))
5654 switches[switchnum].validated = 1;
5655 switches[switchnum].live_cond = SWITCH_FALSE;
5662 /* Otherwise the switch is live. */
5663 switches[switchnum].live_cond = SWITCH_LIVE;
5667 /* Pass a switch to the current accumulating command
5668 in the same form that we received it.
5669 SWITCHNUM identifies the switch; it is an index into
5670 the vector of switches gcc received, which is `switches'.
5671 This cannot fail since it never finishes a command line.
5673 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
5675 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
5679 give_switch (switchnum, omit_first_word, include_blanks)
5681 int omit_first_word;
5684 if (switches[switchnum].live_cond == SWITCH_IGNORE)
5687 if (!omit_first_word)
5689 do_spec_1 ("-", 0, NULL);
5690 do_spec_1 (switches[switchnum].part1, 1, NULL);
5693 if (switches[switchnum].args != 0)
5696 for (p = switches[switchnum].args; *p; p++)
5698 const char *arg = *p;
5701 do_spec_1 (" ", 0, NULL);
5704 unsigned length = strlen (arg);
5707 while (length-- && !IS_DIR_SEPARATOR (arg[length]))
5708 if (arg[length] == '.')
5710 ((char *)arg)[length] = 0;
5714 do_spec_1 (arg, 1, NULL);
5716 ((char *)arg)[length] = '.';
5717 do_spec_1 (suffix_subst, 1, NULL);
5720 do_spec_1 (arg, 1, NULL);
5724 do_spec_1 (" ", 0, NULL);
5725 switches[switchnum].validated = 1;
5728 /* Search for a file named NAME trying various prefixes including the
5729 user's -B prefix and some standard ones.
5730 Return the absolute file name found. If nothing is found, return NAME. */
5738 /* Try multilib_dir if it is defined. */
5739 if (multilib_dir != NULL)
5741 const char *const try = ACONCAT ((multilib_dir, dir_separator_str, name, NULL));
5743 newname = find_a_file (&startfile_prefixes, try, R_OK);
5745 /* If we don't find it in the multi library dir, then fall
5746 through and look for it in the normal places. */
5747 if (newname != NULL)
5751 newname = find_a_file (&startfile_prefixes, name, R_OK);
5752 return newname ? newname : name;
5755 /* Determine whether a directory exists. If LINKER, return 0 for
5756 certain fixed names not needed by the linker. If not LINKER, it is
5757 only important to return 0 if the host machine has a small ARG_MAX
5761 is_directory (path1, path2, linker)
5766 int len1 = strlen (path1);
5767 int len2 = strlen (path2);
5768 char *path = (char *) alloca (3 + len1 + len2);
5772 #ifndef SMALL_ARG_MAX
5777 /* Construct the path from the two parts. Ensure the string ends with "/.".
5778 The resulting path will be a directory even if the given path is a
5780 memcpy (path, path1, len1);
5781 memcpy (path + len1, path2, len2);
5782 cp = path + len1 + len2;
5783 if (!IS_DIR_SEPARATOR (cp[-1]))
5784 *cp++ = DIR_SEPARATOR;
5788 #ifndef FREEBSD_NATIVE
5789 /* Exclude directories that the linker is known to search. */
5792 && strcmp (path, concat (dir_separator_str, "lib",
5793 dir_separator_str, ".", NULL)) == 0)
5795 && strcmp (path, concat (dir_separator_str, "usr",
5796 dir_separator_str, "lib",
5797 dir_separator_str, ".", NULL)) == 0)))
5799 #endif /* FREEBSD_NATIVE */
5801 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
5804 /* Set up the various global variables to indicate that we're processing
5805 the input file named FILENAME. */
5808 set_input (filename)
5809 const char *filename;
5813 input_filename = filename;
5814 input_filename_length = strlen (input_filename);
5816 input_basename = input_filename;
5817 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5818 /* Skip drive name so 'x:foo' is handled properly. */
5819 if (input_basename[1] == ':')
5820 input_basename += 2;
5822 for (p = input_basename; *p; p++)
5823 if (IS_DIR_SEPARATOR (*p))
5824 input_basename = p + 1;
5826 /* Find a suffix starting with the last period,
5827 and set basename_length to exclude that suffix. */
5828 basename_length = strlen (input_basename);
5829 suffixed_basename_length = basename_length;
5830 p = input_basename + basename_length;
5831 while (p != input_basename && *p != '.')
5833 if (*p == '.' && p != input_basename)
5835 basename_length = p - input_basename;
5836 input_suffix = p + 1;
5841 /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
5842 we will need to do a stat on the input_filename. The
5843 INPUT_STAT_SET signals that the stat is needed. */
5847 /* On fatal signals, delete all the temporary files. */
5850 fatal_error (signum)
5853 signal (signum, SIG_DFL);
5854 delete_failure_queue ();
5855 delete_temp_files ();
5856 /* Get the same signal again, this time not handled,
5857 so its normal effect occurs. */
5858 kill (getpid (), signum);
5861 extern int main PARAMS ((int, const char *const *));
5866 const char *const *argv;
5870 int linker_was_run = 0;
5871 char *explicit_link_files;
5874 struct user_specs *uptr;
5876 p = argv[0] + strlen (argv[0]);
5877 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
5881 xmalloc_set_program_name (programname);
5883 #ifdef GCC_DRIVER_HOST_INITIALIZATION
5884 /* Perform host dependent initialization when needed. */
5885 GCC_DRIVER_HOST_INITIALIZATION;
5888 gcc_init_libintl ();
5890 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
5891 signal (SIGINT, fatal_error);
5893 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
5894 signal (SIGHUP, fatal_error);
5896 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
5897 signal (SIGTERM, fatal_error);
5899 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
5900 signal (SIGPIPE, fatal_error);
5903 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
5904 receive the signal. A different setting is inheritable */
5905 signal (SIGCHLD, SIG_DFL);
5909 argbuf = (const char **) xmalloc (argbuf_length * sizeof (const char *));
5911 obstack_init (&obstack);
5913 /* Build multilib_select, et. al from the separate lines that make up each
5914 multilib selection. */
5916 const char *const *q = multilib_raw;
5919 obstack_init (&multilib_obstack);
5920 while ((p = *q++) != (char *) 0)
5921 obstack_grow (&multilib_obstack, p, strlen (p));
5923 obstack_1grow (&multilib_obstack, 0);
5924 multilib_select = obstack_finish (&multilib_obstack);
5926 q = multilib_matches_raw;
5927 while ((p = *q++) != (char *) 0)
5928 obstack_grow (&multilib_obstack, p, strlen (p));
5930 obstack_1grow (&multilib_obstack, 0);
5931 multilib_matches = obstack_finish (&multilib_obstack);
5933 q = multilib_exclusions_raw;
5934 while ((p = *q++) != (char *) 0)
5935 obstack_grow (&multilib_obstack, p, strlen (p));
5937 obstack_1grow (&multilib_obstack, 0);
5938 multilib_exclusions = obstack_finish (&multilib_obstack);
5941 for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
5944 obstack_1grow (&multilib_obstack, ' ');
5945 obstack_grow (&multilib_obstack,
5946 multilib_defaults_raw[i],
5947 strlen (multilib_defaults_raw[i]));
5951 obstack_1grow (&multilib_obstack, 0);
5952 multilib_defaults = obstack_finish (&multilib_obstack);
5955 /* Set up to remember the pathname of gcc and any options
5956 needed for collect. We use argv[0] instead of programname because
5957 we need the complete pathname. */
5958 obstack_init (&collect_obstack);
5959 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
5960 obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
5961 putenv (obstack_finish (&collect_obstack));
5963 #ifdef INIT_ENVIRONMENT
5964 /* Set up any other necessary machine specific environment variables. */
5965 putenv (INIT_ENVIRONMENT);
5968 /* Make a table of what switches there are (switches, n_switches).
5969 Make a table of specified input files (infiles, n_infiles).
5970 Decode switches that are handled locally. */
5972 process_command (argc, argv);
5974 /* Initialize the vector of specs to just the default.
5975 This means one element containing 0s, as a terminator. */
5977 compilers = (struct compiler *) xmalloc (sizeof default_compilers);
5978 memcpy ((char *) compilers, (char *) default_compilers,
5979 sizeof default_compilers);
5980 n_compilers = n_default_compilers;
5982 /* Read specs from a file if there is one. */
5984 #ifdef FREEBSD_NATIVE
5985 just_machine_suffix = "";
5986 #else /* FREEBSD_NATIVE */
5987 machine_suffix = concat (spec_machine, dir_separator_str,
5988 spec_version, dir_separator_str, NULL);
5989 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
5990 #endif /* FREEBSD_NATIVE */
5992 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
5993 /* Read the specs file unless it is a default one. */
5994 if (specs_file != 0 && strcmp (specs_file, "specs"))
5995 read_specs (specs_file, TRUE);
5999 /* We need to check standard_exec_prefix/just_machine_suffix/specs
6000 for any override of as, ld and libraries. */
6001 specs_file = (char *) alloca (strlen (standard_exec_prefix)
6002 + strlen (just_machine_suffix)
6003 + sizeof ("specs"));
6005 strcpy (specs_file, standard_exec_prefix);
6006 strcat (specs_file, just_machine_suffix);
6007 strcat (specs_file, "specs");
6008 if (access (specs_file, R_OK) == 0)
6009 read_specs (specs_file, TRUE);
6011 /* If not cross-compiling, look for startfiles in the standard places. */
6012 if (*cross_compile == '0')
6014 if (*md_exec_prefix)
6016 add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
6017 PREFIX_PRIORITY_LAST, 0, NULL);
6018 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC",
6019 PREFIX_PRIORITY_LAST, 0, NULL);
6022 if (*md_startfile_prefix)
6023 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
6024 PREFIX_PRIORITY_LAST, 0, NULL);
6026 if (*md_startfile_prefix_1)
6027 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
6028 PREFIX_PRIORITY_LAST, 0, NULL);
6030 /* If standard_startfile_prefix is relative, base it on
6031 standard_exec_prefix. This lets us move the installed tree
6032 as a unit. If GCC_EXEC_PREFIX is defined, base
6033 standard_startfile_prefix on that as well. */
6034 if (IS_ABSOLUTE_PATHNAME (standard_startfile_prefix))
6035 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS",
6036 PREFIX_PRIORITY_LAST, 0, NULL);
6039 if (gcc_exec_prefix)
6040 add_prefix (&startfile_prefixes,
6041 concat (gcc_exec_prefix, machine_suffix,
6042 standard_startfile_prefix, NULL),
6043 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
6044 add_prefix (&startfile_prefixes,
6045 concat (standard_exec_prefix,
6047 standard_startfile_prefix, NULL),
6048 NULL, PREFIX_PRIORITY_LAST, 0, NULL);
6051 #ifndef FREEBSD_NATIVE
6052 add_prefix (&startfile_prefixes, standard_startfile_prefix_1,
6053 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
6054 add_prefix (&startfile_prefixes, standard_startfile_prefix_2,
6055 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
6056 #endif /* not FREEBSD_NATIVE */
6057 #if 0 /* Can cause surprises, and one can use -B./ instead. */
6058 add_prefix (&startfile_prefixes, "./", NULL,
6059 PREFIX_PRIORITY_LAST, 1, NULL);
6064 if (!IS_ABSOLUTE_PATHNAME (standard_startfile_prefix)
6066 add_prefix (&startfile_prefixes,
6067 concat (gcc_exec_prefix, machine_suffix,
6068 standard_startfile_prefix, NULL),
6069 "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL);
6072 /* Process any user specified specs in the order given on the command
6074 for (uptr = user_specs_head; uptr; uptr = uptr->next)
6076 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK);
6077 read_specs (filename ? filename : uptr->filename, FALSE);
6080 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
6081 if (gcc_exec_prefix)
6082 gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
6083 spec_version, dir_separator_str, NULL);
6085 /* Now we have the specs.
6086 Set the `valid' bits for switches that match anything in any spec. */
6088 validate_all_switches ();
6090 /* Now that we have the switches and the specs, set
6091 the subdirectory based on the options. */
6092 set_multilib_dir ();
6094 /* Warn about any switches that no pass was interested in. */
6096 for (i = 0; (int) i < n_switches; i++)
6097 if (! switches[i].validated)
6098 error ("unrecognized option `-%s'", switches[i].part1);
6100 /* Obey some of the options. */
6102 if (print_search_dirs)
6104 printf (_("install: %s%s\n"), standard_exec_prefix, machine_suffix);
6105 printf (_("programs: %s\n"), build_search_list (&exec_prefixes, "", 0));
6106 printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes, "", 0));
6110 if (print_file_name)
6112 printf ("%s\n", find_file (print_file_name));
6116 if (print_prog_name)
6118 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
6119 printf ("%s\n", (newname ? newname : print_prog_name));
6123 if (print_multi_lib)
6125 print_multilib_info ();
6129 if (print_multi_directory)
6131 if (multilib_dir == NULL)
6134 printf ("%s\n", multilib_dir);
6138 if (target_help_flag)
6140 /* Print if any target specific options. */
6142 /* We do not exit here. Instead we have created a fake input file
6143 called 'target-dummy' which needs to be compiled, and we pass this
6144 on to the various sub-processes, along with the --target-help
6148 if (print_help_list)
6154 printf (_("\nFor bug reporting instructions, please see:\n"));
6155 printf ("%s.\n", GCCBUGURL);
6160 /* We do not exit here. Instead we have created a fake input file
6161 called 'help-dummy' which needs to be compiled, and we pass this
6162 on the various sub-processes, along with the --help switch. */
6170 notice ("Configured with: %s\n", configuration_arguments);
6172 #ifdef THREAD_MODEL_SPEC
6173 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
6174 but there's no point in doing all this processing just to get
6175 thread_model back. */
6176 obstack_init (&obstack);
6177 do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
6178 obstack_1grow (&obstack, '\0');
6179 thrmod = obstack_finish (&obstack);
6181 thrmod = thread_model;
6184 notice ("Thread model: %s\n", thrmod);
6186 /* compiler_version is truncated at the first space when initialized
6187 from version string, so truncate version_string at the first space
6188 before comparing. */
6189 for (n = 0; version_string[n]; n++)
6190 if (version_string[n] == ' ')
6193 if (! strncmp (version_string, compiler_version, n)
6194 && compiler_version[n] == 0)
6195 notice ("gcc version %s\n", version_string);
6197 notice ("gcc driver version %s executing gcc version %s\n",
6198 version_string, compiler_version);
6204 if (n_infiles == added_libraries)
6205 fatal ("No input files specified");
6207 /* Make a place to record the compiler output file names
6208 that correspond to the input files. */
6211 i += lang_specific_extra_outfiles;
6212 outfiles = (const char **) xcalloc (i, sizeof (char *));
6214 /* Record which files were specified explicitly as link input. */
6216 explicit_link_files = xcalloc (1, n_infiles);
6218 for (i = 0; (int) i < n_infiles; i++)
6220 int this_file_error = 0;
6222 /* Tell do_spec what to substitute for %i. */
6224 input_file_number = i;
6225 set_input (infiles[i].name);
6227 /* Use the same thing in %o, unless cp->spec says otherwise. */
6229 outfiles[i] = input_filename;
6231 /* Figure out which compiler from the file's suffix. */
6234 = lookup_compiler (infiles[i].name, input_filename_length,
6235 infiles[i].language);
6237 if (input_file_compiler)
6239 /* Ok, we found an applicable compiler. Run its spec. */
6241 if (input_file_compiler->spec[0] == '#')
6243 error ("%s: %s compiler not installed on this system",
6244 input_filename, &input_file_compiler->spec[1]);
6245 this_file_error = 1;
6249 value = do_spec (input_file_compiler->spec);
6251 this_file_error = 1;
6255 /* If this file's name does not contain a recognized suffix,
6256 record it as explicit linker input. */
6259 explicit_link_files[i] = 1;
6261 /* Clear the delete-on-failure queue, deleting the files in it
6262 if this compilation failed. */
6264 if (this_file_error)
6266 delete_failure_queue ();
6269 /* If this compilation succeeded, don't delete those files later. */
6270 clear_failure_queue ();
6273 /* Reset the output file name to the first input file name, for use
6274 with %b in LINK_SPEC on a target that prefers not to emit a.out
6277 set_input (infiles[0].name);
6279 if (error_count == 0)
6281 /* Make sure INPUT_FILE_NUMBER points to first available open
6283 input_file_number = n_infiles;
6284 if (lang_specific_pre_link ())
6288 /* Run ld to link all the compiler output files. */
6290 if (error_count == 0)
6292 int tmp = execution_count;
6294 /* We'll use ld if we can't find collect2. */
6295 if (! strcmp (linker_name_spec, "collect2"))
6297 char *s = find_a_file (&exec_prefixes, "collect2", X_OK);
6299 linker_name_spec = "ld";
6301 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
6303 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
6304 putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
6306 value = do_spec (link_command_spec);
6309 linker_was_run = (tmp != execution_count);
6312 /* If options said don't run linker,
6313 complain about input files to be given to the linker. */
6315 if (! linker_was_run && error_count == 0)
6316 for (i = 0; (int) i < n_infiles; i++)
6317 if (explicit_link_files[i])
6318 error ("%s: linker input file unused because linking not done",
6321 /* Delete some or all of the temporary files we made. */
6324 delete_failure_queue ();
6325 delete_temp_files ();
6327 if (print_help_list)
6329 printf (("\nFor bug reporting instructions, please see:\n"));
6330 printf ("%s\n", GCCBUGURL);
6333 return (signal_count != 0 ? 2
6334 : error_count > 0 ? (pass_exit_codes ? greatest_status : 1)
6338 /* Find the proper compilation spec for the file name NAME,
6339 whose length is LENGTH. LANGUAGE is the specified language,
6340 or 0 if this file is to be passed to the linker. */
6342 static struct compiler *
6343 lookup_compiler (name, length, language)
6346 const char *language;
6348 struct compiler *cp;
6350 /* If this was specified by the user to be a linker input, indicate that. */
6351 if (language != 0 && language[0] == '*')
6354 /* Otherwise, look for the language, if one is spec'd. */
6357 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
6358 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
6361 error ("language %s not recognized", language);
6365 /* Look for a suffix. */
6366 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
6368 if (/* The suffix `-' matches only the file name `-'. */
6369 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
6370 || (strlen (cp->suffix) < length
6371 /* See if the suffix matches the end of NAME. */
6372 && !strcmp (cp->suffix,
6373 name + length - strlen (cp->suffix))
6378 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
6379 /* look again, but case-insensitively this time. */
6381 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
6383 if (/* The suffix `-' matches only the file name `-'. */
6384 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
6385 || (strlen (cp->suffix) < length
6386 /* See if the suffix matches the end of NAME. */
6387 && ((!strcmp (cp->suffix,
6388 name + length - strlen (cp->suffix))
6389 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
6390 && !strcasecmp (cp->suffix,
6391 name + length - strlen (cp->suffix)))
6397 if (cp >= compilers)
6399 if (cp->spec[0] != '@')
6400 /* A non-alias entry: return it. */
6403 /* An alias entry maps a suffix to a language.
6404 Search for the language; pass 0 for NAME and LENGTH
6405 to avoid infinite recursion if language not found. */
6406 return lookup_compiler (NULL, 0, cp->spec + 1);
6412 save_string (s, len)
6416 char *result = xmalloc (len + 1);
6418 memcpy (result, s, len);
6424 pfatal_with_name (name)
6427 perror_with_name (name);
6428 delete_temp_files ();
6433 perror_with_name (name)
6436 error ("%s: %s", name, xstrerror (errno));
6440 pfatal_pexecute (errmsg_fmt, errmsg_arg)
6441 const char *errmsg_fmt;
6442 const char *errmsg_arg;
6446 int save_errno = errno;
6448 /* Space for trailing '\0' is in %s. */
6449 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg));
6450 sprintf (msg, errmsg_fmt, errmsg_arg);
6456 pfatal_with_name (errmsg_fmt);
6459 /* Output an error message and exit */
6464 fatal ("internal gcc abort");
6467 /* Output an error message and exit */
6470 fatal VPARAMS ((const char *msgid, ...))
6472 VA_OPEN (ap, msgid);
6473 VA_FIXEDARG (ap, const char *, msgid);
6475 fprintf (stderr, "%s: ", programname);
6476 vfprintf (stderr, _(msgid), ap);
6478 fprintf (stderr, "\n");
6479 delete_temp_files ();
6484 error VPARAMS ((const char *msgid, ...))
6486 VA_OPEN (ap, msgid);
6487 VA_FIXEDARG (ap, const char *, msgid);
6489 fprintf (stderr, "%s: ", programname);
6490 vfprintf (stderr, _(msgid), ap);
6493 fprintf (stderr, "\n");
6497 notice VPARAMS ((const char *msgid, ...))
6499 VA_OPEN (ap, msgid);
6500 VA_FIXEDARG (ap, const char *, msgid);
6502 vfprintf (stderr, _(msgid), ap);
6507 validate_all_switches ()
6509 struct compiler *comp;
6512 struct spec_list *spec;
6514 for (comp = compilers; comp->spec; comp++)
6518 if (c == '%' && *p == '{')
6519 /* We have a switch spec. */
6520 validate_switches (p + 1);
6523 /* Look through the linked list of specs read from the specs file. */
6524 for (spec = specs; spec; spec = spec->next)
6526 p = *(spec->ptr_spec);
6528 if (c == '%' && *p == '{')
6529 /* We have a switch spec. */
6530 validate_switches (p + 1);
6533 p = link_command_spec;
6535 if (c == '%' && *p == '{')
6536 /* We have a switch spec. */
6537 validate_switches (p + 1);
6540 /* Look at the switch-name that comes after START
6541 and mark as valid all supplied switches that match it. */
6544 validate_switches (start)
6547 const char *p = start;
6564 while (*p != ':' && *p != '}' && *p != '|' && *p != '&')
6569 else if (p[-1] == '*')
6571 /* Mark all matching switches as valid. */
6572 for (i = 0; i < n_switches; i++)
6573 if (!strncmp (switches[i].part1, filter, p - filter - 1))
6574 switches[i].validated = 1;
6578 /* Mark an exact matching switch as valid. */
6579 for (i = 0; i < n_switches; i++)
6581 if (!strncmp (switches[i].part1, filter, p - filter)
6582 && switches[i].part1[p - filter] == 0)
6583 switches[i].validated = 1;
6587 if (*p++ == '|' || p[-1] == '&')
6591 /* Check whether a particular argument was used. The first time we
6592 canonicalize the switches to keep only the ones we care about. */
6602 const char *replace;
6607 static struct mswitchstr *mswitches;
6608 static int n_mswitches;
6613 struct mswitchstr *matches;
6617 /* Break multilib_matches into the component strings of string
6618 and replacement string. */
6619 for (q = multilib_matches; *q != '\0'; q++)
6624 (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
6626 q = multilib_matches;
6636 matches[i].len = q - matches[i].str;
6638 matches[i].replace = ++q;
6639 while (*q != ';' && *q != '\0')
6645 matches[i].rep_len = q - matches[i].replace;
6651 /* Now build a list of the replacement string for switches that we care
6652 about. Make sure we allocate at least one entry. This prevents
6653 xmalloc from calling fatal, and prevents us from re-executing this
6656 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr))
6657 * (n_switches ? n_switches : 1));
6658 for (i = 0; i < n_switches; i++)
6660 int xlen = strlen (switches[i].part1);
6661 for (j = 0; j < cnt; j++)
6662 if (xlen == matches[j].len
6663 && ! strncmp (switches[i].part1, matches[j].str, xlen))
6665 mswitches[n_mswitches].str = matches[j].replace;
6666 mswitches[n_mswitches].len = matches[j].rep_len;
6667 mswitches[n_mswitches].replace = (char *) 0;
6668 mswitches[n_mswitches].rep_len = 0;
6675 for (i = 0; i < n_mswitches; i++)
6676 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
6683 default_arg (p, len)
6687 const char *start, *end;
6689 for (start = multilib_defaults; *start != '\0'; start = end + 1)
6691 while (*start == ' ' || *start == '\t')
6697 for (end = start + 1; *end != ' ' && *end != '\t' && *end != '\0'; end++)
6700 if ((end - start) == len && strncmp (p, start, len) == 0)
6710 /* Work out the subdirectory to use based on the options. The format of
6711 multilib_select is a list of elements. Each element is a subdirectory
6712 name followed by a list of options followed by a semicolon. The format
6713 of multilib_exclusions is the same, but without the preceding
6714 directory. First gcc will check the exclusions, if none of the options
6715 beginning with an exclamation point are present, and all of the other
6716 options are present, then we will ignore this completely. Passing
6717 that, gcc will consider each multilib_select in turn using the same
6718 rules for matching the options. If a match is found, that subdirectory
6725 unsigned int this_path_len;
6726 const char *this_path, *this_arg;
6730 p = multilib_exclusions;
6733 /* Ignore newlines. */
6740 /* Check the arguments. */
6754 while (*p != ' ' && *p != ';')
6761 if (*this_arg != '!')
6769 ok = used_arg (this_arg, p - this_arg);
6783 p = multilib_select;
6786 /* Ignore newlines. */
6793 /* Get the initial path. */
6801 this_path_len = p - this_path;
6803 /* Check the arguments. */
6818 while (*p != ' ' && *p != ';')
6825 if (*this_arg != '!')
6833 /* If this is a default argument, we can just ignore it.
6834 This is true even if this_arg begins with '!'. Beginning
6835 with '!' does not mean that this argument is necessarily
6836 inappropriate for this library: it merely means that
6837 there is a more specific library which uses this
6838 argument. If this argument is a default, we need not
6839 consider that more specific library. */
6840 if (! default_arg (this_arg, p - this_arg))
6842 ok = used_arg (this_arg, p - this_arg);
6853 if (this_path_len != 1
6854 || this_path[0] != '.')
6856 char *new_multilib_dir = xmalloc (this_path_len + 1);
6857 strncpy (new_multilib_dir, this_path, this_path_len);
6858 new_multilib_dir[this_path_len] = '\0';
6859 multilib_dir = new_multilib_dir;
6868 /* Print out the multiple library subdirectory selection
6869 information. This prints out a series of lines. Each line looks
6870 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
6871 required. Only the desired options are printed out, the negative
6872 matches. The options are print without a leading dash. There are
6873 no spaces to make it easy to use the information in the shell.
6874 Each subdirectory is printed only once. This assumes the ordering
6875 generated by the genmultilib script. Also, we leave out ones that match
6879 print_multilib_info ()
6881 const char *p = multilib_select;
6882 const char *last_path = 0, *this_path;
6884 unsigned int last_path_len = 0;
6889 /* Ignore newlines. */
6896 /* Get the initial path. */
6905 /* Check for matches with the multilib_exclusions. We don't bother
6906 with the '!' in either list. If any of the exclusion rules match
6907 all of its options with the select rule, we skip it. */
6909 const char *e = multilib_exclusions;
6910 const char *this_arg;
6915 /* Ignore newlines. */
6922 /* Check the arguments. */
6939 while (*e != ' ' && *e != ';')
6950 int len = e - this_arg;
6957 while (*q != ' ' && *q != ';')
6964 if (! strncmp (arg, this_arg, (len < q - arg) ? q - arg : len) ||
6965 default_arg (this_arg, e - this_arg))
6995 /* If this is a duplicate, skip it. */
6996 skip = (last_path != 0 && (unsigned int) (p - this_path) == last_path_len
6997 && ! strncmp (last_path, this_path, last_path_len));
6999 last_path = this_path;
7000 last_path_len = p - this_path;
7003 /* If this directory requires any default arguments, we can skip
7004 it. We will already have printed a directory identical to
7005 this one which does not require that default argument. */
7023 while (*q != ' ' && *q != ';')
7031 && default_arg (arg, q - arg))
7046 for (p1 = last_path; p1 < p; p1++)
7065 use_arg = *p != '!';
7070 while (*p != ' ' && *p != ';')
7085 /* If there are extra options, print them now. */
7086 if (multilib_extra && *multilib_extra)
7088 int print_at = TRUE;
7091 for (q = multilib_extra; *q != '\0'; q++)