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!!!! */
25 /* This program is the user interface to the C compiler and possibly to
26 other compilers. It is used because compilation is a complicated procedure
27 which involves running several programs and passing temporary files between
28 them, forwarding the users switches to those programs selectively,
29 and deleting the temporary files at the end.
31 CC recognizes how to compile each input file by suffixes in the file names.
32 Once it knows which kind of compilation to perform, the procedure for
33 compilation is specified by a string called a "spec". */
35 /* A Short Introduction to Adding a Command-Line Option.
37 Before adding a command-line option, consider if it is really
38 necessary. Each additional command-line option adds complexity and
39 is difficult to remove in subsequent versions.
41 In the following, consider adding the command-line argument
44 1. Each command-line option is specified in the specs file. The
45 notation is described below in the comment entitled "The Specs
48 2. In this file, add an entry to "option_map" equating the long
49 `--' argument version and any shorter, single letter version. Read
50 the comments in the declaration of "struct option_map" for an
51 explanation. Do not omit the first `-'.
53 3. Look in the "specs" file to determine which program or option
54 list should be given the argument, e.g., "cc1_options". Add the
55 appropriate syntax for the shorter option version to the
56 corresponding "const char *" entry in this file. Omit the first
57 `-' from the option. For example, use `-bar', rather than `--bar'.
59 4. If the argument takes an argument, e.g., `--baz argument1',
60 modify either DEFAULT_SWITCH_TAKES_ARG or
61 DEFAULT_WORD_SWITCH_TAKES_ARG in this file. Omit the first `-'
64 5. Document the option in this file's display_help(). If the
65 option is passed to a subprogram, modify its corresponding
66 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
69 6. Compile and test. Make sure that your new specs file is being
70 read. For example, use a debugger to investigate the value of
71 "specs_file" in main(). */
76 #if ! defined( SIGCHLD ) && defined( SIGCLD )
77 # define SIGCHLD SIGCLD
85 #ifdef HAVE_SYS_RESOURCE_H
86 #include <sys/resource.h>
88 #if defined (HAVE_DECL_GETRUSAGE) && !HAVE_DECL_GETRUSAGE
89 extern int getrusage PARAMS ((int, struct rusage *));
92 /* By default there is no special suffix for target executables. */
93 /* FIXME: when autoconf is fixed, remove the host check - dj */
94 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
95 #define HAVE_TARGET_EXECUTABLE_SUFFIX
98 /* By default there is no special suffix for host executables. */
99 #ifdef HOST_EXECUTABLE_SUFFIX
100 #define HAVE_HOST_EXECUTABLE_SUFFIX
102 #define HOST_EXECUTABLE_SUFFIX ""
105 /* By default, the suffix for target object files is ".o". */
106 #ifdef TARGET_OBJECT_SUFFIX
107 #define HAVE_TARGET_OBJECT_SUFFIX
109 #define TARGET_OBJECT_SUFFIX ".o"
113 /* FIXME: the location independence code for VMS is hairier than this,
114 and hasn't been written. */
120 static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
122 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
123 #ifndef LIBRARY_PATH_ENV
124 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
128 #define kill(p,s) raise(s)
131 /* If a stage of compilation returns an exit status >= 1,
132 compilation of that file ceases. */
134 #define MIN_FATAL_STATUS 1
136 /* Flag set by cppspec.c to 1. */
139 /* Flag saying to pass the greatest exit code returned by a sub-process
140 to the calling program. */
141 static int pass_exit_codes;
143 /* Definition of string containing the arguments given to configure. */
144 #include "configargs.h"
146 /* Flag saying to print the directories gcc will search through looking for
147 programs, libraries, etc. */
149 static int print_search_dirs;
151 /* Flag saying to print the full filename of this file
152 as found through our usual search mechanism. */
154 static const char *print_file_name = NULL;
156 /* As print_file_name, but search for executable file. */
158 static const char *print_prog_name = NULL;
160 /* Flag saying to print the relative path we'd use to
161 find libgcc.a given the current compiler flags. */
163 static int print_multi_directory;
165 /* Flag saying to print the relative path we'd use to
166 find OS libraries given the current compiler flags. */
168 static int print_multi_os_directory;
170 /* Flag saying to print the list of subdirectories and
171 compiler flags used to select them in a standard form. */
173 static int print_multi_lib;
175 /* Flag saying to print the command line options understood by gcc and its
178 static int print_help_list;
180 /* Flag indicating whether we should print the command and arguments */
182 static int verbose_flag;
184 /* Flag indicating whether we should ONLY print the command and
185 arguments (like verbose_flag) without executing the command.
186 Displayed arguments are quoted so that the generated command
187 line is suitable for execution. This is intended for use in
188 shell scripts to capture the driver-generated command line. */
189 static int verbose_only_flag;
191 /* Flag indicating to print target specific command line options. */
193 static int target_help_flag;
195 /* Flag indicating whether we should report subprocess execution times
196 (if this is supported by the system - see pexecute.c). */
198 static int report_times;
200 /* Nonzero means write "temp" files in source directory
201 and use the source file's name in them, and don't delete them. */
203 static int save_temps_flag;
205 /* The compiler version. */
207 static const char *compiler_version;
209 /* The target version specified with -V */
211 static const char *const spec_version = DEFAULT_TARGET_VERSION;
213 /* The target machine specified with -b. */
215 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
217 /* Nonzero if cross-compiling.
218 When -b is used, the value comes from the `specs' file. */
221 static const char *cross_compile = "1";
223 static const char *cross_compile = "0";
226 #ifdef MODIFY_TARGET_NAME
228 /* Information on how to alter the target name based on a command-line
229 switch. The only case we support now is simply appending or deleting a
230 string to or from the end of the first part of the configuration name. */
232 static const struct modify_target
234 const char *const sw;
235 const enum add_del {ADD, DELETE} add_del;
236 const char *const str;
238 modify_target[] = MODIFY_TARGET_NAME;
241 /* The number of errors that have occurred; the link phase will not be
242 run if this is nonzero. */
243 static int error_count = 0;
245 /* Greatest exit code of sub-processes that has been encountered up to
247 static int greatest_status = 1;
249 /* This is the obstack which we use to allocate many strings. */
251 static struct obstack obstack;
253 /* This is the obstack to build an environment variable to pass to
254 collect2 that describes all of the relevant switches of what to
255 pass the compiler in building the list of pointers to constructors
258 static struct obstack collect_obstack;
260 /* These structs are used to collect resource usage information for
262 #ifdef HAVE_GETRUSAGE
263 static struct rusage rus, prus;
266 /* Forward declaration for prototypes. */
269 static void init_spec PARAMS ((void));
270 static void store_arg PARAMS ((const char *, int, int));
271 static char *load_specs PARAMS ((const char *));
272 static void read_specs PARAMS ((const char *, int));
273 static void set_spec PARAMS ((const char *, const char *));
274 static struct compiler *lookup_compiler PARAMS ((const char *, size_t, const char *));
275 static char *build_search_list PARAMS ((struct path_prefix *, const char *, int));
276 static void putenv_from_prefixes PARAMS ((struct path_prefix *, const char *));
277 static int access_check PARAMS ((const char *, int));
278 static char *find_a_file PARAMS ((struct path_prefix *, const char *,
280 static void add_prefix PARAMS ((struct path_prefix *, const char *,
281 const char *, int, int, int *, int));
282 static void translate_options PARAMS ((int *, const char *const **));
283 static char *skip_whitespace PARAMS ((char *));
284 static void delete_if_ordinary PARAMS ((const char *));
285 static void delete_temp_files PARAMS ((void));
286 static void delete_failure_queue PARAMS ((void));
287 static void clear_failure_queue PARAMS ((void));
288 static int check_live_switch PARAMS ((int, int));
289 static const char *handle_braces PARAMS ((const char *));
290 static const struct spec_function *lookup_spec_function PARAMS ((const char *));
291 static const char *eval_spec_function PARAMS ((const char *, const char *));
292 static const char *handle_spec_function PARAMS ((const char *));
293 static char *save_string PARAMS ((const char *, int));
294 static void set_collect_gcc_options PARAMS ((void));
295 static int do_spec_1 PARAMS ((const char *, int, const char *));
296 static int do_spec_2 PARAMS ((const char *));
297 static void do_self_spec PARAMS ((const char *));
298 static const char *find_file PARAMS ((const char *));
299 static int is_directory PARAMS ((const char *, const char *, int));
300 static void validate_switches PARAMS ((const char *));
301 static void validate_all_switches PARAMS ((void));
302 static void give_switch PARAMS ((int, int, int));
303 static int used_arg PARAMS ((const char *, int));
304 static int default_arg PARAMS ((const char *, int));
305 static void set_multilib_dir PARAMS ((void));
306 static void print_multilib_info PARAMS ((void));
307 static void perror_with_name PARAMS ((const char *));
308 static void pfatal_pexecute PARAMS ((const char *, const char *))
310 static void notice PARAMS ((const char *, ...))
312 static void display_help PARAMS ((void));
313 static void add_preprocessor_option PARAMS ((const char *, int));
314 static void add_assembler_option PARAMS ((const char *, int));
315 static void add_linker_option PARAMS ((const char *, int));
316 static void process_command PARAMS ((int, const char *const *));
317 static int execute PARAMS ((void));
318 static void alloc_args PARAMS ((void));
319 static void clear_args PARAMS ((void));
320 static void fatal_error PARAMS ((int));
321 #ifdef ENABLE_SHARED_LIBGCC
322 static void init_gcc_specs PARAMS ((struct obstack *,
323 const char *, const char *,
326 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
327 static const char *convert_filename PARAMS ((const char *, int, int));
330 static const char *if_exists_spec_function PARAMS ((int, const char **));
332 /* The Specs Language
334 Specs are strings containing lines, each of which (if not blank)
335 is made up of a program name, and arguments separated by spaces.
336 The program name must be exact and start from root, since no path
337 is searched and it is unreliable to depend on the current working directory.
338 Redirection of input or output is not supported; the subprograms must
339 accept filenames saying what files to read and write.
341 In addition, the specs can contain %-sequences to substitute variable text
342 or for conditional text. Here is a table of all defined %-sequences.
343 Note that spaces are not generated automatically around the results of
344 expanding these sequences; therefore, you can concatenate them together
345 or with constant text in a single argument.
347 %% substitute one % into the program name or argument.
348 %i substitute the name of the input file being processed.
349 %b substitute the basename of the input file being processed.
350 This is the substring up to (and not including) the last period
351 and not including the directory.
352 %B same as %b, but include the file suffix (text after the last period).
354 substitute a file name that has suffix SUFFIX and is chosen
355 once per compilation, and mark the argument a la %d. To reduce
356 exposure to denial-of-service attacks, the file name is now
357 chosen in a way that is hard to predict even when previously
358 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
359 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
360 the regexp "[.A-Za-z]*%O"; "%O" is treated exactly as if it
361 had been pre-processed. Previously, %g was simply substituted
362 with a file name chosen once per compilation, without regard
363 to any appended suffix (which was therefore treated just like
364 ordinary text), making such attacks more likely to succeed.
366 like %g, but generates a new temporary file name even if %uSUFFIX
369 substitutes the last file name generated with %uSUFFIX, generating a
370 new one if there is no such last file name. In the absence of any
371 %uSUFFIX, this is just like %gSUFFIX, except they don't share
372 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
373 would involve the generation of two distinct file names, one
374 for each `%g.s' and another for each `%U.s'. Previously, %U was
375 simply substituted with a file name chosen for the previous %u,
376 without regard to any appended suffix.
378 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
379 writable, and if save-temps is off; otherwise, substitute the name
380 of a temporary file, just like %u. This temporary file is not
381 meant for communication between processes, but rather as a junk
384 substitutes .SUFFIX for the suffixes of a matched switch's args when
385 it is subsequently output with %*. SUFFIX is terminated by the next
387 %d marks the argument containing or following the %d as a
388 temporary file name, so that that file will be deleted if CC exits
389 successfully. Unlike %g, this contributes no text to the argument.
390 %w marks the argument containing or following the %w as the
391 "output file" of this compilation. This puts the argument
392 into the sequence of arguments that %o will substitute later.
394 like %{...} but mark last argument supplied within
395 as a file to be deleted on failure.
396 %o substitutes the names of all the output files, with spaces
397 automatically placed around them. You should write spaces
398 around the %o as well or the results are undefined.
399 %o is for use in the specs for running the linker.
400 Input files whose names have no recognized suffix are not compiled
401 at all, but they are included among the output files, so they will
403 %O substitutes the suffix for object files. Note that this is
404 handled specially when it immediately follows %g, %u, or %U
405 (with or without a suffix argument) because of the need for
406 those to form complete file names. The handling is such that
407 %O is treated exactly as if it had already been substituted,
408 except that %g, %u, and %U do not currently support additional
409 SUFFIX characters following %O as they would following, for
411 %p substitutes the standard macro predefinitions for the
412 current target machine. Use this when running cpp.
413 %P like %p, but puts `__' before and after the name of each macro.
414 (Except macros that already have __.)
416 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
417 %s current argument is the name of a library or startup file of some sort.
418 Search for that file in a standard list of directories
419 and substitute the full name found.
420 %eSTR Print STR as an error message. STR is terminated by a newline.
421 Use this when inconsistent options are detected.
422 %nSTR Print STR as an notice. STR is terminated by a newline.
423 %x{OPTION} Accumulate an option for %X.
424 %X Output the accumulated linker options specified by compilations.
425 %Y Output the accumulated assembler options specified by compilations.
426 %Z Output the accumulated preprocessor options specified by compilations.
427 %v1 Substitute the major version number of GCC.
428 (For version 2.5.3, this is 2.)
429 %v2 Substitute the minor version number of GCC.
430 (For version 2.5.3, this is 5.)
431 %v3 Substitute the patch level number of GCC.
432 (For version 2.5.3, this is 3.)
433 %a process ASM_SPEC as a spec.
434 This allows config.h to specify part of the spec for running as.
435 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
436 used here. This can be used to run a post-processor after the
437 assembler has done its job.
438 %D Dump out a -L option for each directory in startfile_prefixes.
439 If multilib_dir is set, extra entries are generated with it affixed.
440 %l process LINK_SPEC as a spec.
441 %L process LIB_SPEC as a spec.
442 %G process LIBGCC_SPEC as a spec.
443 %M output multilib_dir with directory separators replaced with "_";
444 if multilib_dir is not set or is ".", output "".
445 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
446 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
447 %C process CPP_SPEC as a spec.
448 %1 process CC1_SPEC as a spec.
449 %2 process CC1PLUS_SPEC as a spec.
450 %| output "-" if the input for the current command is coming from a pipe.
451 %* substitute the variable part of a matched option. (See below.)
452 Note that each comma in the substituted string is replaced by
455 Call the named function FUNCTION, passing it ARGS. ARGS is
456 first processed as a nested spec string, then split into an
457 argument vector in the usual fashion. The function returns
458 a string which is processed as if it had appeared literally
459 as part of the current spec.
460 %{S} substitutes the -S switch, if that switch was given to CC.
461 If that switch was not specified, this substitutes nothing.
462 Here S is a metasyntactic variable.
463 %{S*} substitutes all the switches specified to CC whose names start
464 with -S. This is used for -o, -I, etc; switches that take
465 arguments. CC considers `-o foo' as being one switch whose
466 name starts with `o'. %{o*} would substitute this text,
467 including the space; thus, two arguments would be generated.
468 %{^S*} likewise, but don't put a blank between a switch and any args.
469 %{S*&T*} likewise, but preserve order of S and T options (the order
470 of S and T in the spec is not significant). Can be any number
471 of ampersand-separated variables; for each the wild card is
472 optional. Useful for CPP as %{D*&U*&A*}.
473 %{S*:X} substitutes X if one or more switches whose names start with -S are
474 specified to CC. Note that the tail part of the -S option
475 (i.e. the part matched by the `*') will be substituted for each
476 occurrence of %* within X.
477 %{<S} remove all occurrences of -S from the command line.
478 Note - this option is position dependent. % commands in the
479 spec string before this option will see -S, % commands in the
480 spec string after this option will not.
481 %{S:X} substitutes X, but only if the -S switch was given to CC.
482 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
483 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
484 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
485 %{.S:X} substitutes X, but only if processing a file with suffix S.
486 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
487 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
488 combined with ! and . as above binding stronger than the OR.
489 %(Spec) processes a specification defined in a specs file as *Spec:
490 %[Spec] as above, but put __ around -D arguments
492 The conditional text X in a %{S:X} or %{!S:X} construct may contain
493 other nested % constructs or spaces, or even newlines. They are
494 processed as usual, as described above.
496 The -O, -f, -m, and -W switches are handled specifically in these
497 constructs. If another value of -O or the negated form of a -f, -m, or
498 -W switch is found later in the command line, the earlier switch
499 value is ignored, except with {S*} where S is just one letter; this
500 passes all matching options.
502 The character | at the beginning of the predicate text is used to indicate
503 that a command should be piped to the following command, but only if -pipe
506 Note that it is built into CC which switches take arguments and which
507 do not. You might think it would be useful to generalize this to
508 allow each compiler's spec to say which switches take arguments. But
509 this cannot be done in a consistent fashion. CC cannot even decide
510 which input files have been specified without knowing which switches
511 take arguments, and it must know which input files to compile in order
512 to tell which compilers to run.
514 CC also knows implicitly that arguments starting in `-l' are to be
515 treated as compiler output files, and passed to the linker in their
516 proper position among the other output files. */
518 /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
520 /* config.h can define ASM_SPEC to provide extra args to the assembler
521 or extra switch-translations. */
526 /* config.h can define ASM_FINAL_SPEC to run a post processor after
527 the assembler has run. */
528 #ifndef ASM_FINAL_SPEC
529 #define ASM_FINAL_SPEC ""
532 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
533 or extra switch-translations. */
538 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
539 or extra switch-translations. */
544 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
545 or extra switch-translations. */
547 #define CC1PLUS_SPEC ""
550 /* config.h can define LINK_SPEC to provide extra args to the linker
551 or extra switch-translations. */
556 /* config.h can define LIB_SPEC to override the default libraries. */
558 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
561 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
564 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
565 /* Have gcc do the search for libgcc.a. */
566 #define LIBGCC_SPEC "libgcc.a%s"
568 #define LIBGCC_SPEC "-lgcc"
572 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
573 #ifndef STARTFILE_SPEC
574 #define STARTFILE_SPEC \
575 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
578 /* config.h can define SWITCHES_NEED_SPACES to control which options
579 require spaces between the option and the argument. */
580 #ifndef SWITCHES_NEED_SPACES
581 #define SWITCHES_NEED_SPACES ""
584 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
586 #define ENDFILE_SPEC ""
590 #define LINKER_NAME "collect2"
593 /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
595 #ifndef ASM_DEBUG_SPEC
596 # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
597 && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
598 # define ASM_DEBUG_SPEC \
599 (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
600 ? "%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}" \
601 : "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}")
603 # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
604 # define ASM_DEBUG_SPEC "%{g*:--gstabs}"
606 # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
607 # define ASM_DEBUG_SPEC "%{g*:--gdwarf2}"
611 #ifndef ASM_DEBUG_SPEC
612 # define ASM_DEBUG_SPEC ""
615 /* Here is the spec for running the linker, after compiling all files. */
617 /* This is overridable by the target in case they need to specify the
618 -lgcc and -lc order specially, yet not require them to override all
619 of LINK_COMMAND_SPEC. */
620 #ifndef LINK_GCC_C_SEQUENCE_SPEC
621 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
624 /* -u* was put back because both BSD and SysV seem to support it. */
625 /* %{static:} simply prevents an error message if the target machine
626 doesn't handle -static. */
627 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
628 scripts which exist in user specified directories, or in standard
630 #ifndef LINK_COMMAND_SPEC
631 #define LINK_COMMAND_SPEC "\
632 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
633 %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
634 %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
635 %{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
636 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
639 #ifndef LINK_LIBGCC_SPEC
640 # ifdef LINK_LIBGCC_SPECIAL
641 /* Don't generate -L options for startfile prefix list. */
642 # define LINK_LIBGCC_SPEC ""
644 /* Do generate them. */
645 # define LINK_LIBGCC_SPEC "%D"
649 #ifndef STARTFILE_PREFIX_SPEC
650 # define STARTFILE_PREFIX_SPEC ""
653 static const char *asm_debug;
654 static const char *cpp_spec = CPP_SPEC;
655 static const char *cpp_predefines = CPP_PREDEFINES;
656 static const char *cc1_spec = CC1_SPEC;
657 static const char *cc1plus_spec = CC1PLUS_SPEC;
658 static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;
659 static const char *asm_spec = ASM_SPEC;
660 static const char *asm_final_spec = ASM_FINAL_SPEC;
661 static const char *link_spec = LINK_SPEC;
662 static const char *lib_spec = LIB_SPEC;
663 static const char *libgcc_spec = LIBGCC_SPEC;
664 static const char *endfile_spec = ENDFILE_SPEC;
665 static const char *startfile_spec = STARTFILE_SPEC;
666 static const char *switches_need_spaces = SWITCHES_NEED_SPACES;
667 static const char *linker_name_spec = LINKER_NAME;
668 static const char *link_command_spec = LINK_COMMAND_SPEC;
669 static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
670 static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
672 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
673 There should be no need to override these in target dependent files,
674 but we need to copy them to the specs file so that newer versions
675 of the GCC driver can correctly drive older tool chains with the
676 appropriate -B options. */
678 /* When cpplib handles traditional preprocessing, get rid of this, and
679 call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
680 that we default the front end language better. */
681 static const char *trad_capable_cpp =
682 "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}";
684 /* We don't wrap .d files in %W{} since a missing .d file, and
685 therefore no dependency entry, confuses make into thinking a .o
686 file that happens to exist is up-to-date. */
687 static const char *cpp_unique_options =
688 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
689 %{CC:%{!E:%eGNU C does not support -CC without using -E}}\
690 %{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*} %{P} %I\
691 %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
692 %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
693 %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
694 %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\
695 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
696 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
697 %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
700 /* This contains cpp options which are common with cc1_options and are passed
701 only when preprocessing only to avoid duplication. We pass the cc1 spec
702 options to the preprocessor so that it the cc1 spec may manipulate
703 options used to set target flags. Those special target flags settings may
704 in turn cause preprocessor symbols to be defined specially. */
705 static const char *cpp_options =
706 "%(cpp_unique_options) %1 %{m*} %{std*} %{ansi} %{W*&pedantic*} %{w} %{f*}\
709 /* This contains cpp options which are not passed when the preprocessor
710 output will be used by another program. */
711 static const char *cpp_debug_options = "%{d*}";
713 /* NB: This is shared amongst all front-ends. */
714 static const char *cc1_options =
715 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
716 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
717 -auxbase%{c|S:%{o*:-strip %*}%{!o*: %b}}%{!c:%{!S: %b}}\
718 %{g*} %{O*} %{W*&pedantic*} %{w} %{std*} %{ansi}\
719 %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
720 %{Qn:-fno-ident} %{--help:--help}\
721 %{--target-help:--target-help}\
722 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
723 %{fsyntax-only:-o %j} %{-param*}";
725 static const char *asm_options =
726 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
728 static const char *invoke_as =
729 "%{!S:-o %{|!pipe:%g.s} |\n as %(asm_options) %{!pipe:%g.s} %A }";
731 /* Some compilers have limits on line lengths, and the multilib_select
732 and/or multilib_matches strings can be very long, so we build them at
734 static struct obstack multilib_obstack;
735 static const char *multilib_select;
736 static const char *multilib_matches;
737 static const char *multilib_defaults;
738 static const char *multilib_exclusions;
739 #include "multilib.h"
741 /* Check whether a particular argument is a default argument. */
743 #ifndef MULTILIB_DEFAULTS
744 #define MULTILIB_DEFAULTS { "" }
747 static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
749 #ifndef DRIVER_SELF_SPECS
750 #define DRIVER_SELF_SPECS ""
753 static const char *const driver_self_specs[] = { DRIVER_SELF_SPECS };
757 struct user_specs *next;
758 const char *filename;
761 static struct user_specs *user_specs_head, *user_specs_tail;
763 /* This defines which switch letters take arguments. */
765 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
766 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
767 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
768 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
769 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'B' || (CHAR) == 'b')
771 #ifndef SWITCH_TAKES_ARG
772 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
775 /* This defines which multi-letter switches take arguments. */
777 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
778 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
779 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
780 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
781 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
782 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
783 || !strcmp (STR, "isystem") || !strcmp (STR, "-param") \
784 || !strcmp (STR, "specs") \
785 || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
787 #ifndef WORD_SWITCH_TAKES_ARG
788 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
791 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
792 /* This defines which switches stop a full compilation. */
793 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
794 ((CHAR) == 'c' || (CHAR) == 'S')
796 #ifndef SWITCH_CURTAILS_COMPILATION
797 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
798 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
802 /* Record the mapping from file suffixes for compilation specs. */
806 const char *suffix; /* Use this compiler for input files
807 whose names end in this suffix. */
809 const char *spec; /* To use this compiler, run this spec. */
811 const char *cpp_spec; /* If non-NULL, substitute this spec
812 for `%C', rather than the usual
816 /* Pointer to a vector of `struct compiler' that gives the spec for
817 compiling a file, based on its suffix.
818 A file that does not end in any of these suffixes will be passed
819 unchanged to the loader and nothing else will be done to it.
821 An entry containing two 0s is used to terminate the vector.
823 If multiple entries match a file, the last matching one is used. */
825 static struct compiler *compilers;
827 /* Number of entries in `compilers', not counting the null terminator. */
829 static int n_compilers;
831 /* The default list of file name suffixes and their compilation specs. */
833 static const struct compiler default_compilers[] =
835 /* Add lists of suffixes of known languages here. If those languages
836 were not present when we built the driver, we will hit these copies
837 and be given a more meaningful error than "file not used since
838 linking is not done". */
839 {".m", "#Objective-C", 0}, {".mi", "#Objective-C", 0},
840 {".cc", "#C++", 0}, {".cxx", "#C++", 0}, {".cpp", "#C++", 0},
841 {".cp", "#C++", 0}, {".c++", "#C++", 0}, {".C", "#C++", 0},
843 {".ads", "#Ada", 0}, {".adb", "#Ada", 0},
844 {".f", "#Fortran", 0}, {".for", "#Fortran", 0}, {".fpp", "#Fortran", 0},
845 {".F", "#Fortran", 0}, {".FOR", "#Fortran", 0}, {".FPP", "#Fortran", 0},
846 {".r", "#Ratfor", 0},
847 {".p", "#Pascal", 0}, {".pas", "#Pascal", 0},
848 {".java", "#Java", 0}, {".class", "#Java", 0},
849 {".zip", "#Java", 0}, {".jar", "#Java", 0},
850 /* Next come the entries for C. */
853 /* cc1 has an integrated ISO C preprocessor. We should invoke the
854 external preprocessor if -save-temps is given. */
855 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
857 %{traditional|ftraditional:\
858 %eGNU C no longer supports -traditional without -E}\
859 %{save-temps|traditional-cpp:%(trad_capable_cpp) \
860 %(cpp_options) %b.i \n\
861 cc1 -fpreprocessed %b.i %(cc1_options)}\
862 %{!save-temps:%{!traditional-cpp:\
863 cc1 %(cpp_unique_options) %(cc1_options)}}\
864 %{!fsyntax-only:%(invoke_as)}}}}", 0},
866 "%{!E:%e-E required when input is from standard input}\
867 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0},
868 {".h", "@c-header", 0},
870 "%{!E:%ecompilation of header file requested} \
871 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)",
873 {".i", "@cpp-output", 0},
875 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0},
876 {".s", "@assembler", 0},
878 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0},
879 {".S", "@assembler-with-cpp", 0},
880 {"@assembler-with-cpp",
881 "%(trad_capable_cpp) -lang-asm %(cpp_options)\
882 %{E|M|MM:%(cpp_debug_options)}\
883 %{!M:%{!MM:%{!E:%{!S:-o %{|!pipe:%g.s} |\n\
884 as %(asm_debug) %(asm_options) %{!pipe:%g.s} %A }}}}", 0},
886 /* Mark end of table */
890 /* Number of elements in default_compilers, not counting the terminator. */
892 static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
894 /* A vector of options to give to the linker.
895 These options are accumulated by %x,
896 and substituted into the linker command with %X. */
897 static int n_linker_options;
898 static char **linker_options;
900 /* A vector of options to give to the assembler.
901 These options are accumulated by -Wa,
902 and substituted into the assembler command with %Y. */
903 static int n_assembler_options;
904 static char **assembler_options;
906 /* A vector of options to give to the preprocessor.
907 These options are accumulated by -Wp,
908 and substituted into the preprocessor command with %Z. */
909 static int n_preprocessor_options;
910 static char **preprocessor_options;
912 /* Define how to map long options into short ones. */
914 /* This structure describes one mapping. */
917 /* The long option's name. */
918 const char *const name;
919 /* The equivalent short option. */
920 const char *const equivalent;
921 /* Argument info. A string of flag chars; NULL equals no options.
922 a => argument required.
923 o => argument optional.
924 j => join argument to equivalent, making one word.
925 * => require other text after NAME as an argument. */
926 const char *const arg_info;
929 /* This is the table of mappings. Mappings are tried sequentially
930 for each option encountered; the first one that matches, wins. */
932 static const struct option_map option_map[] =
934 {"--all-warnings", "-Wall", 0},
935 {"--ansi", "-ansi", 0},
936 {"--assemble", "-S", 0},
937 {"--assert", "-A", "a"},
938 {"--classpath", "-fclasspath=", "aj"},
939 {"--bootclasspath", "-fbootclasspath=", "aj"},
940 {"--CLASSPATH", "-fclasspath=", "aj"},
941 {"--comments", "-C", 0},
942 {"--comments-in-macros", "-CC", 0},
943 {"--compile", "-c", 0},
944 {"--debug", "-g", "oj"},
945 {"--define-macro", "-D", "aj"},
946 {"--dependencies", "-M", 0},
947 {"--dump", "-d", "a"},
948 {"--dumpbase", "-dumpbase", "a"},
949 {"--entry", "-e", 0},
950 {"--extra-warnings", "-W", 0},
951 {"--for-assembler", "-Wa", "a"},
952 {"--for-linker", "-Xlinker", "a"},
953 {"--force-link", "-u", "a"},
954 {"--imacros", "-imacros", "a"},
955 {"--include", "-include", "a"},
956 {"--include-barrier", "-I-", 0},
957 {"--include-directory", "-I", "aj"},
958 {"--include-directory-after", "-idirafter", "a"},
959 {"--include-prefix", "-iprefix", "a"},
960 {"--include-with-prefix", "-iwithprefix", "a"},
961 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
962 {"--include-with-prefix-after", "-iwithprefix", "a"},
963 {"--language", "-x", "a"},
964 {"--library-directory", "-L", "a"},
965 {"--machine", "-m", "aj"},
966 {"--machine-", "-m", "*j"},
967 {"--no-line-commands", "-P", 0},
968 {"--no-precompiled-includes", "-noprecomp", 0},
969 {"--no-standard-includes", "-nostdinc", 0},
970 {"--no-standard-libraries", "-nostdlib", 0},
971 {"--no-warnings", "-w", 0},
972 {"--optimize", "-O", "oj"},
973 {"--output", "-o", "a"},
974 {"--output-class-directory", "-foutput-class-dir=", "ja"},
975 {"--param", "--param", "a"},
976 {"--pedantic", "-pedantic", 0},
977 {"--pedantic-errors", "-pedantic-errors", 0},
978 {"--pipe", "-pipe", 0},
979 {"--prefix", "-B", "a"},
980 {"--preprocess", "-E", 0},
981 {"--print-search-dirs", "-print-search-dirs", 0},
982 {"--print-file-name", "-print-file-name=", "aj"},
983 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
984 {"--print-missing-file-dependencies", "-MG", 0},
985 {"--print-multi-lib", "-print-multi-lib", 0},
986 {"--print-multi-directory", "-print-multi-directory", 0},
987 {"--print-multi-os-directory", "-print-multi-os-directory", 0},
988 {"--print-prog-name", "-print-prog-name=", "aj"},
989 {"--profile", "-p", 0},
990 {"--profile-blocks", "-a", 0},
991 {"--quiet", "-q", 0},
992 {"--resource", "-fcompile-resource=", "aj"},
993 {"--save-temps", "-save-temps", 0},
994 {"--shared", "-shared", 0},
995 {"--silent", "-q", 0},
996 {"--specs", "-specs=", "aj"},
997 {"--static", "-static", 0},
998 {"--std", "-std=", "aj"},
999 {"--symbolic", "-symbolic", 0},
1000 {"--target", "-b", "a"},
1001 {"--time", "-time", 0},
1002 {"--trace-includes", "-H", 0},
1003 {"--traditional", "-traditional", 0},
1004 {"--traditional-cpp", "-traditional-cpp", 0},
1005 {"--trigraphs", "-trigraphs", 0},
1006 {"--undefine-macro", "-U", "aj"},
1007 {"--use-version", "-V", "a"},
1008 {"--user-dependencies", "-MM", 0},
1009 {"--verbose", "-v", 0},
1010 {"--warn-", "-W", "*j"},
1011 {"--write-dependencies", "-MD", 0},
1012 {"--write-user-dependencies", "-MMD", 0},
1017 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1018 static const struct {
1019 const char *const option_found;
1020 const char *const replacements;
1021 } target_option_translations[] =
1023 TARGET_OPTION_TRANSLATE_TABLE,
1028 /* Translate the options described by *ARGCP and *ARGVP.
1029 Make a new vector and store it back in *ARGVP,
1030 and store its length in *ARGVC. */
1033 translate_options (argcp, argvp)
1035 const char *const **argvp;
1039 const char *const *argv = *argvp;
1040 int newvsize = (argc + 2) * 2 * sizeof (const char *);
1042 (const char **) xmalloc (newvsize);
1046 newv[newindex++] = argv[i++];
1050 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1054 target_option_translations[tott_idx].option_found;
1057 if (strcmp (target_option_translations[tott_idx].option_found,
1064 for (sp = target_option_translations[tott_idx].replacements;
1071 newvsize += spaces * sizeof (const char *);
1072 newv = (const char **) xrealloc (newv, newvsize);
1074 sp = target_option_translations[tott_idx].replacements;
1083 newv[newindex++] = np;
1084 while (*np != ' ' && *np)
1095 if (target_option_translations[tott_idx].option_found)
1099 /* Translate -- options. */
1100 if (argv[i][0] == '-' && argv[i][1] == '-')
1103 /* Find a mapping that applies to this option. */
1104 for (j = 0; j < ARRAY_SIZE (option_map); j++)
1106 size_t optlen = strlen (option_map[j].name);
1107 size_t arglen = strlen (argv[i]);
1108 size_t complen = arglen > optlen ? optlen : arglen;
1109 const char *arginfo = option_map[j].arg_info;
1114 if (!strncmp (argv[i], option_map[j].name, complen))
1116 const char *arg = 0;
1118 if (arglen < optlen)
1121 for (k = j + 1; k < ARRAY_SIZE (option_map); k++)
1122 if (strlen (option_map[k].name) >= arglen
1123 && !strncmp (argv[i], option_map[k].name, arglen))
1125 error ("ambiguous abbreviation %s", argv[i]);
1129 if (k != ARRAY_SIZE (option_map))
1133 if (arglen > optlen)
1135 /* If the option has an argument, accept that. */
1136 if (argv[i][optlen] == '=')
1137 arg = argv[i] + optlen + 1;
1139 /* If this mapping requires extra text at end of name,
1140 accept that as "argument". */
1141 else if (strchr (arginfo, '*') != 0)
1142 arg = argv[i] + optlen;
1144 /* Otherwise, extra text at end means mismatch.
1145 Try other mappings. */
1150 else if (strchr (arginfo, '*') != 0)
1152 error ("incomplete `%s' option", option_map[j].name);
1156 /* Handle arguments. */
1157 if (strchr (arginfo, 'a') != 0)
1163 error ("missing argument to `%s' option",
1164 option_map[j].name);
1171 else if (strchr (arginfo, '*') != 0)
1173 else if (strchr (arginfo, 'o') == 0)
1176 error ("extraneous argument to `%s' option",
1177 option_map[j].name);
1181 /* Store the translation as one argv elt or as two. */
1182 if (arg != 0 && strchr (arginfo, 'j') != 0)
1183 newv[newindex++] = concat (option_map[j].equivalent, arg,
1187 newv[newindex++] = option_map[j].equivalent;
1188 newv[newindex++] = arg;
1191 newv[newindex++] = option_map[j].equivalent;
1199 /* Handle old-fashioned options--just copy them through,
1200 with their arguments. */
1201 else if (argv[i][0] == '-')
1203 const char *p = argv[i] + 1;
1207 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1208 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1209 else if (WORD_SWITCH_TAKES_ARG (p))
1210 nskip += WORD_SWITCH_TAKES_ARG (p);
1211 else if ((c == 'B' || c == 'b' || c == 'x')
1214 else if (! strcmp (p, "Xlinker"))
1217 /* Watch out for an option at the end of the command line that
1218 is missing arguments, and avoid skipping past the end of the
1220 if (nskip + i > argc)
1225 newv[newindex++] = argv[i++];
1230 /* Ordinary operands, or +e options. */
1231 newv[newindex++] = argv[i++];
1246 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1247 be considered whitespace. */
1248 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1250 else if (*p == '\n' || *p == ' ' || *p == '\t')
1264 /* Structures to keep track of prefixes to try when looking for files. */
1268 const char *prefix; /* String to prepend to the path. */
1269 struct prefix_list *next; /* Next in linked list. */
1270 int require_machine_suffix; /* Don't use without machine_suffix. */
1271 /* 2 means try both machine_suffix and just_machine_suffix. */
1272 int *used_flag_ptr; /* 1 if a file was found with this prefix. */
1273 int priority; /* Sort key - priority within list. */
1274 int os_multilib; /* 1 if OS multilib scheme should be used,
1275 0 for GCC multilib scheme. */
1280 struct prefix_list *plist; /* List of prefixes to try */
1281 int max_len; /* Max length of a prefix in PLIST */
1282 const char *name; /* Name of this list (used in config stuff) */
1285 /* List of prefixes to try when looking for executables. */
1287 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1289 /* List of prefixes to try when looking for startup (crt0) files. */
1291 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1293 /* List of prefixes to try when looking for include files. */
1295 static struct path_prefix include_prefixes = { 0, 0, "include" };
1297 /* Suffix to attach to directories searched for commands.
1298 This looks like `MACHINE/VERSION/'. */
1300 static const char *machine_suffix = 0;
1302 /* Suffix to attach to directories searched for commands.
1303 This is just `MACHINE/'. */
1305 static const char *just_machine_suffix = 0;
1307 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1309 static const char *gcc_exec_prefix;
1311 /* Default prefixes to attach to command names. */
1313 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1314 #undef MD_EXEC_PREFIX
1315 #undef MD_STARTFILE_PREFIX
1316 #undef MD_STARTFILE_PREFIX_1
1319 /* If no prefixes defined, use the null string, which will disable them. */
1320 #ifndef MD_EXEC_PREFIX
1321 #define MD_EXEC_PREFIX ""
1323 #ifndef MD_STARTFILE_PREFIX
1324 #define MD_STARTFILE_PREFIX ""
1326 #ifndef MD_STARTFILE_PREFIX_1
1327 #define MD_STARTFILE_PREFIX_1 ""
1330 /* Supply defaults for the standard prefixes. */
1332 #ifndef STANDARD_EXEC_PREFIX
1333 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1335 #ifndef STANDARD_STARTFILE_PREFIX
1336 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1338 #ifndef TOOLDIR_BASE_PREFIX
1339 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1341 #ifndef STANDARD_BINDIR_PREFIX
1342 #define STANDARD_BINDIR_PREFIX "/usr/local/bin"
1345 static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1346 static const char *const standard_exec_prefix_1 = "/usr/lib/gcc/";
1347 static const char *md_exec_prefix = MD_EXEC_PREFIX;
1349 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1350 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1351 static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1352 static const char *const standard_startfile_prefix_1 = "/lib/";
1353 static const char *const standard_startfile_prefix_2 = "/usr/lib/";
1355 static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1356 static const char *tooldir_prefix;
1358 static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1360 /* Subdirectory to use for locating libraries. Set by
1361 set_multilib_dir based on the compilation options. */
1363 static const char *multilib_dir;
1365 /* Subdirectory to use for locating libraries in OS conventions. Set by
1366 set_multilib_dir based on the compilation options. */
1368 static const char *multilib_os_dir;
1370 /* Structure to keep track of the specs that have been defined so far.
1371 These are accessed using %(specname) or %[specname] in a compiler
1376 /* The following 2 fields must be first */
1377 /* to allow EXTRA_SPECS to be initialized */
1378 const char *name; /* name of the spec. */
1379 const char *ptr; /* available ptr if no static pointer */
1381 /* The following fields are not initialized */
1382 /* by EXTRA_SPECS */
1383 const char **ptr_spec; /* pointer to the spec itself. */
1384 struct spec_list *next; /* Next spec in linked list. */
1385 int name_len; /* length of the name */
1386 int alloc_p; /* whether string was allocated */
1389 #define INIT_STATIC_SPEC(NAME,PTR) \
1390 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1392 /* List of statically defined specs. */
1393 static struct spec_list static_specs[] =
1395 INIT_STATIC_SPEC ("asm", &asm_spec),
1396 INIT_STATIC_SPEC ("asm_debug", &asm_debug),
1397 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1398 INIT_STATIC_SPEC ("asm_options", &asm_options),
1399 INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1400 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1401 INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1402 INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options),
1403 INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
1404 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1405 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1406 INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1407 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1408 INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec),
1409 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1410 INIT_STATIC_SPEC ("link", &link_spec),
1411 INIT_STATIC_SPEC ("lib", &lib_spec),
1412 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1413 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1414 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1415 INIT_STATIC_SPEC ("predefines", &cpp_predefines),
1416 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1417 INIT_STATIC_SPEC ("version", &compiler_version),
1418 INIT_STATIC_SPEC ("multilib", &multilib_select),
1419 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1420 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1421 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1422 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1423 INIT_STATIC_SPEC ("multilib_options", &multilib_options),
1424 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1425 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1426 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1427 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1428 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1429 INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
1432 #ifdef EXTRA_SPECS /* additional specs needed */
1433 /* Structure to keep track of just the first two args of a spec_list.
1434 That is all that the EXTRA_SPECS macro gives us. */
1437 const char *const name;
1438 const char *const ptr;
1441 static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1442 static struct spec_list *extra_specs = (struct spec_list *) 0;
1445 /* List of dynamically allocates specs that have been defined so far. */
1447 static struct spec_list *specs = (struct spec_list *) 0;
1449 /* List of static spec functions. */
1451 static const struct spec_function static_spec_functions[] =
1453 { "if-exists", if_exists_spec_function },
1457 static int processing_spec_function;
1459 /* Add appropriate libgcc specs to OBSTACK, taking into account
1460 various permutations of -shared-libgcc, -shared, and such. */
1462 #ifdef ENABLE_SHARED_LIBGCC
1464 init_gcc_specs (obstack, shared_name, static_name, eh_name)
1465 struct obstack *obstack;
1466 const char *shared_name;
1467 const char *static_name;
1468 const char *eh_name;
1472 buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name,
1473 "}%{!static:%{!static-libgcc:",
1474 "%{!shared:%{!shared-libgcc:", static_name, " ",
1475 eh_name, "}%{shared-libgcc:", shared_name, " ",
1476 static_name, "}}%{shared:",
1478 "%{shared-libgcc:", shared_name,
1479 "}%{!shared-libgcc:", static_name, "}",
1485 obstack_grow (obstack, buf, strlen (buf));
1488 #endif /* ENABLE_SHARED_LIBGCC */
1490 /* Initialize the specs lookup routines. */
1495 struct spec_list *next = (struct spec_list *) 0;
1496 struct spec_list *sl = (struct spec_list *) 0;
1500 return; /* Already initialized. */
1503 notice ("Using built-in specs.\n");
1506 extra_specs = (struct spec_list *)
1507 xcalloc (sizeof (struct spec_list), ARRAY_SIZE (extra_specs_1));
1509 for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1511 sl = &extra_specs[i];
1512 sl->name = extra_specs_1[i].name;
1513 sl->ptr = extra_specs_1[i].ptr;
1515 sl->name_len = strlen (sl->name);
1516 sl->ptr_spec = &sl->ptr;
1521 /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes
1522 on ?: in file-scope variable initializations. */
1523 asm_debug = ASM_DEBUG_SPEC;
1525 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1527 sl = &static_specs[i];
1532 #ifdef ENABLE_SHARED_LIBGCC
1533 /* ??? If neither -shared-libgcc nor --static-libgcc was
1534 seen, then we should be making an educated guess. Some proposed
1535 heuristics for ELF include:
1537 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1538 program will be doing dynamic loading, which will likely
1539 need the shared libgcc.
1541 (2) If "-ldl", then it's also a fair bet that we're doing
1544 (3) For each ET_DYN we're linking against (either through -lfoo
1545 or /some/path/foo.so), check to see whether it or one of
1546 its dependencies depends on a shared libgcc.
1550 If the runtime is fixed to look for program headers instead
1551 of calling __register_frame_info at all, for each object,
1552 use the shared libgcc if any EH symbol referenced.
1554 If crtstuff is fixed to not invoke __register_frame_info
1555 automatically, for each object, use the shared libgcc if
1556 any non-empty unwind section found.
1558 Doing any of this probably requires invoking an external program to
1559 do the actual object file scanning. */
1561 const char *p = libgcc_spec;
1564 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1565 when given the proper command line arguments. */
1568 if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
1570 init_gcc_specs (&obstack,
1571 #ifdef NO_SHARED_LIBGCC_MULTILIB
1582 else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0)
1584 /* Ug. We don't know shared library extensions. Hope that
1585 systems that use this form don't do shared libraries. */
1586 init_gcc_specs (&obstack,
1587 #ifdef NO_SHARED_LIBGCC_MULTILIB
1600 obstack_1grow (&obstack, *p);
1601 in_sep = (*p == ' ');
1606 obstack_1grow (&obstack, '\0');
1607 libgcc_spec = obstack_finish (&obstack);
1610 #ifdef USE_AS_TRADITIONAL_FORMAT
1611 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1613 static const char tf[] = "--traditional-format ";
1614 obstack_grow (&obstack, tf, sizeof(tf) - 1);
1615 obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1616 asm_spec = obstack_finish (&obstack);
1620 /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1621 obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1);
1622 obstack_grow0 (&obstack, link_spec, strlen (link_spec));
1623 link_spec = obstack_finish (&obstack);
1629 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1630 removed; If the spec starts with a + then SPEC is added to the end of the
1634 set_spec (name, spec)
1638 struct spec_list *sl;
1639 const char *old_spec;
1640 int name_len = strlen (name);
1643 /* If this is the first call, initialize the statically allocated specs. */
1646 struct spec_list *next = (struct spec_list *) 0;
1647 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1649 sl = &static_specs[i];
1656 /* See if the spec already exists. */
1657 for (sl = specs; sl; sl = sl->next)
1658 if (name_len == sl->name_len && !strcmp (sl->name, name))
1663 /* Not found - make it. */
1664 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
1665 sl->name = xstrdup (name);
1666 sl->name_len = name_len;
1667 sl->ptr_spec = &sl->ptr;
1669 *(sl->ptr_spec) = "";
1674 old_spec = *(sl->ptr_spec);
1675 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1676 ? concat (old_spec, spec + 1, NULL)
1681 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1684 /* Free the old spec. */
1685 if (old_spec && sl->alloc_p)
1686 free ((PTR) old_spec);
1691 /* Accumulate a command (program name and args), and run it. */
1693 /* Vector of pointers to arguments in the current line of specifications. */
1695 static const char **argbuf;
1697 /* Number of elements allocated in argbuf. */
1699 static int argbuf_length;
1701 /* Number of elements in argbuf currently in use (containing args). */
1703 static int argbuf_index;
1705 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1706 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1709 static struct temp_name {
1710 const char *suffix; /* suffix associated with the code. */
1711 int length; /* strlen (suffix). */
1712 int unique; /* Indicates whether %g or %u/%U was used. */
1713 const char *filename; /* associated filename. */
1714 int filename_length; /* strlen (filename). */
1715 struct temp_name *next;
1718 /* Number of commands executed so far. */
1720 static int execution_count;
1722 /* Number of commands that exited with a signal. */
1724 static int signal_count;
1726 /* Name with which this program was invoked. */
1728 static const char *programname;
1730 /* Allocate the argument vector. */
1736 argbuf = (const char **) xmalloc (argbuf_length * sizeof (const char *));
1739 /* Clear out the vector of arguments (after a command is executed). */
1747 /* Add one argument to the vector at the end.
1748 This is done when a space is seen or at the end of the line.
1749 If DELETE_ALWAYS is nonzero, the arg is a filename
1750 and the file should be deleted eventually.
1751 If DELETE_FAILURE is nonzero, the arg is a filename
1752 and the file should be deleted if this compilation fails. */
1755 store_arg (arg, delete_always, delete_failure)
1757 int delete_always, delete_failure;
1759 if (argbuf_index + 1 == argbuf_length)
1761 = (const char **) xrealloc (argbuf,
1762 (argbuf_length *= 2) * sizeof (const char *));
1764 argbuf[argbuf_index++] = arg;
1765 argbuf[argbuf_index] = 0;
1767 if (delete_always || delete_failure)
1768 record_temp_file (arg, delete_always, delete_failure);
1771 /* Load specs from a file name named FILENAME, replacing occurrences of
1772 various different types of line-endings, \r\n, \n\r and just \r, with
1776 load_specs (filename)
1777 const char *filename;
1781 struct stat statbuf;
1788 notice ("Reading specs from %s\n", filename);
1790 /* Open and stat the file. */
1791 desc = open (filename, O_RDONLY, 0);
1793 pfatal_with_name (filename);
1794 if (stat (filename, &statbuf) < 0)
1795 pfatal_with_name (filename);
1797 /* Read contents of file into BUFFER. */
1798 buffer = xmalloc ((unsigned) statbuf.st_size + 1);
1799 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
1801 pfatal_with_name (filename);
1802 buffer[readlen] = 0;
1805 specs = xmalloc (readlen + 1);
1807 for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
1813 if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
1815 else if (*(buffer_p + 1) == '\n') /* \r\n */
1829 /* Read compilation specs from a file named FILENAME,
1830 replacing the default ones.
1832 A suffix which starts with `*' is a definition for
1833 one of the machine-specific sub-specs. The "suffix" should be
1834 *asm, *cc1, *cpp, *link, *startfile, etc.
1835 The corresponding spec is stored in asm_spec, etc.,
1836 rather than in the `compilers' vector.
1838 Anything invalid in the file is a fatal error. */
1841 read_specs (filename, main_p)
1842 const char *filename;
1848 buffer = load_specs (filename);
1850 /* Scan BUFFER for specs, putting them in the vector. */
1856 char *in, *out, *p1, *p2, *p3;
1858 /* Advance P in BUFFER to the next nonblank nocomment line. */
1859 p = skip_whitespace (p);
1863 /* Is this a special command that starts with '%'? */
1864 /* Don't allow this for the main specs file, since it would
1865 encourage people to overwrite it. */
1866 if (*p == '%' && !main_p)
1869 while (*p && *p != '\n')
1875 if (!strncmp (p1, "%include", sizeof ("%include") - 1)
1876 && (p1[sizeof "%include" - 1] == ' '
1877 || p1[sizeof "%include" - 1] == '\t'))
1881 p1 += sizeof ("%include");
1882 while (*p1 == ' ' || *p1 == '\t')
1885 if (*p1++ != '<' || p[-2] != '>')
1886 fatal ("specs %%include syntax malformed after %ld characters",
1887 (long) (p1 - buffer + 1));
1890 new_filename = find_a_file (&startfile_prefixes, p1, R_OK, 0);
1891 read_specs (new_filename ? new_filename : p1, FALSE);
1894 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
1895 && (p1[sizeof "%include_noerr" - 1] == ' '
1896 || p1[sizeof "%include_noerr" - 1] == '\t'))
1900 p1 += sizeof "%include_noerr";
1901 while (*p1 == ' ' || *p1 == '\t')
1904 if (*p1++ != '<' || p[-2] != '>')
1905 fatal ("specs %%include syntax malformed after %ld characters",
1906 (long) (p1 - buffer + 1));
1909 new_filename = find_a_file (&startfile_prefixes, p1, R_OK, 0);
1911 read_specs (new_filename, FALSE);
1912 else if (verbose_flag)
1913 notice ("could not find specs file %s\n", p1);
1916 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
1917 && (p1[sizeof "%rename" - 1] == ' '
1918 || p1[sizeof "%rename" - 1] == '\t'))
1921 struct spec_list *sl;
1922 struct spec_list *newsl;
1924 /* Get original name. */
1925 p1 += sizeof "%rename";
1926 while (*p1 == ' ' || *p1 == '\t')
1929 if (! ISALPHA ((unsigned char) *p1))
1930 fatal ("specs %%rename syntax malformed after %ld characters",
1931 (long) (p1 - buffer));
1934 while (*p2 && !ISSPACE ((unsigned char) *p2))
1937 if (*p2 != ' ' && *p2 != '\t')
1938 fatal ("specs %%rename syntax malformed after %ld characters",
1939 (long) (p2 - buffer));
1943 while (*p2 == ' ' || *p2 == '\t')
1946 if (! ISALPHA ((unsigned char) *p2))
1947 fatal ("specs %%rename syntax malformed after %ld characters",
1948 (long) (p2 - buffer));
1950 /* Get new spec name. */
1952 while (*p3 && !ISSPACE ((unsigned char) *p3))
1956 fatal ("specs %%rename syntax malformed after %ld characters",
1957 (long) (p3 - buffer));
1960 for (sl = specs; sl; sl = sl->next)
1961 if (name_len == sl->name_len && !strcmp (sl->name, p1))
1965 fatal ("specs %s spec was not found to be renamed", p1);
1967 if (strcmp (p1, p2) == 0)
1970 for (newsl = specs; newsl; newsl = newsl->next)
1971 if (strcmp (newsl->name, p2) == 0)
1972 fatal ("%s: attempt to rename spec '%s' to already defined spec '%s'",
1977 notice ("rename spec %s to %s\n", p1, p2);
1979 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
1983 set_spec (p2, *(sl->ptr_spec));
1985 free ((PTR) *(sl->ptr_spec));
1987 *(sl->ptr_spec) = "";
1992 fatal ("specs unknown %% command after %ld characters",
1993 (long) (p1 - buffer));
1996 /* Find the colon that should end the suffix. */
1998 while (*p1 && *p1 != ':' && *p1 != '\n')
2001 /* The colon shouldn't be missing. */
2003 fatal ("specs file malformed after %ld characters",
2004 (long) (p1 - buffer));
2006 /* Skip back over trailing whitespace. */
2008 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
2011 /* Copy the suffix to a string. */
2012 suffix = save_string (p, p2 - p);
2013 /* Find the next line. */
2014 p = skip_whitespace (p1 + 1);
2016 fatal ("specs file malformed after %ld characters",
2017 (long) (p - buffer));
2020 /* Find next blank line or end of string. */
2021 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
2024 /* Specs end at the blank line and do not include the newline. */
2025 spec = save_string (p, p1 - p);
2028 /* Delete backslash-newline sequences from the spec. */
2033 if (in[0] == '\\' && in[1] == '\n')
2035 else if (in[0] == '#')
2036 while (*in && *in != '\n')
2044 if (suffix[0] == '*')
2046 if (! strcmp (suffix, "*link_command"))
2047 link_command_spec = spec;
2049 set_spec (suffix + 1, spec);
2053 /* Add this pair to the vector. */
2055 = ((struct compiler *)
2056 xrealloc (compilers,
2057 (n_compilers + 2) * sizeof (struct compiler)));
2059 compilers[n_compilers].suffix = suffix;
2060 compilers[n_compilers].spec = spec;
2062 memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
2066 link_command_spec = spec;
2069 if (link_command_spec == 0)
2070 fatal ("spec file has no spec for linking");
2073 /* Record the names of temporary files we tell compilers to write,
2074 and delete them at the end of the run. */
2076 /* This is the common prefix we use to make temp file names.
2077 It is chosen once for each run of this program.
2078 It is substituted into a spec by %g or %j.
2079 Thus, all temp file names contain this prefix.
2080 In practice, all temp file names start with this prefix.
2082 This prefix comes from the envvar TMPDIR if it is defined;
2083 otherwise, from the P_tmpdir macro if that is defined;
2084 otherwise, in /usr/tmp or /tmp;
2085 or finally the current directory if all else fails. */
2087 static const char *temp_filename;
2089 /* Length of the prefix. */
2091 static int temp_filename_length;
2093 /* Define the list of temporary files to delete. */
2098 struct temp_file *next;
2101 /* Queue of files to delete on success or failure of compilation. */
2102 static struct temp_file *always_delete_queue;
2103 /* Queue of files to delete on failure of compilation. */
2104 static struct temp_file *failure_delete_queue;
2106 /* Record FILENAME as a file to be deleted automatically.
2107 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2108 otherwise delete it in any case.
2109 FAIL_DELETE nonzero means delete it if a compilation step fails;
2110 otherwise delete it in any case. */
2113 record_temp_file (filename, always_delete, fail_delete)
2114 const char *filename;
2118 char *const name = xstrdup (filename);
2122 struct temp_file *temp;
2123 for (temp = always_delete_queue; temp; temp = temp->next)
2124 if (! strcmp (name, temp->name))
2127 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
2128 temp->next = always_delete_queue;
2130 always_delete_queue = temp;
2137 struct temp_file *temp;
2138 for (temp = failure_delete_queue; temp; temp = temp->next)
2139 if (! strcmp (name, temp->name))
2142 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
2143 temp->next = failure_delete_queue;
2145 failure_delete_queue = temp;
2151 /* Delete all the temporary files whose names we previously recorded. */
2154 delete_if_ordinary (name)
2161 printf ("Delete %s? (y or n) ", name);
2165 while ((c = getchar ()) != '\n' && c != EOF)
2168 if (i == 'y' || i == 'Y')
2170 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
2171 if (unlink (name) < 0)
2173 perror_with_name (name);
2177 delete_temp_files ()
2179 struct temp_file *temp;
2181 for (temp = always_delete_queue; temp; temp = temp->next)
2182 delete_if_ordinary (temp->name);
2183 always_delete_queue = 0;
2186 /* Delete all the files to be deleted on error. */
2189 delete_failure_queue ()
2191 struct temp_file *temp;
2193 for (temp = failure_delete_queue; temp; temp = temp->next)
2194 delete_if_ordinary (temp->name);
2198 clear_failure_queue ()
2200 failure_delete_queue = 0;
2203 /* Build a list of search directories from PATHS.
2204 PREFIX is a string to prepend to the list.
2205 If CHECK_DIR_P is nonzero we ensure the directory exists.
2206 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2207 It is also used by the --print-search-dirs flag. */
2210 build_search_list (paths, prefix, check_dir_p)
2211 struct path_prefix *paths;
2215 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
2217 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
2218 int first_time = TRUE;
2219 struct prefix_list *pprefix;
2221 obstack_grow (&collect_obstack, prefix, strlen (prefix));
2222 obstack_1grow (&collect_obstack, '=');
2224 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
2226 int len = strlen (pprefix->prefix);
2230 || is_directory (pprefix->prefix, machine_suffix, 0)))
2233 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2236 obstack_grow (&collect_obstack, pprefix->prefix, len);
2237 obstack_grow (&collect_obstack, machine_suffix, suffix_len);
2240 if (just_machine_suffix
2241 && pprefix->require_machine_suffix == 2
2243 || is_directory (pprefix->prefix, just_machine_suffix, 0)))
2246 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2249 obstack_grow (&collect_obstack, pprefix->prefix, len);
2250 obstack_grow (&collect_obstack, just_machine_suffix,
2254 if (! pprefix->require_machine_suffix)
2257 obstack_1grow (&collect_obstack, PATH_SEPARATOR);
2260 obstack_grow (&collect_obstack, pprefix->prefix, len);
2264 obstack_1grow (&collect_obstack, '\0');
2265 return obstack_finish (&collect_obstack);
2268 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2272 putenv_from_prefixes (paths, env_var)
2273 struct path_prefix *paths;
2274 const char *env_var;
2276 putenv (build_search_list (paths, env_var, 1));
2279 /* Check whether NAME can be accessed in MODE. This is like access,
2280 except that it never considers directories to be executable. */
2283 access_check (name, mode)
2291 if (stat (name, &st) < 0
2292 || S_ISDIR (st.st_mode))
2296 return access (name, mode);
2299 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2300 access to check permissions.
2301 Return 0 if not found, otherwise return its name, allocated with malloc. */
2304 find_a_file (pprefix, name, mode, multilib)
2305 struct path_prefix *pprefix;
2310 const char *const file_suffix =
2311 ((mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "");
2312 struct prefix_list *pl;
2313 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
2314 const char *multilib_name, *multilib_os_name;
2316 #ifdef DEFAULT_ASSEMBLER
2317 if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
2318 return xstrdup (DEFAULT_ASSEMBLER);
2321 #ifdef DEFAULT_LINKER
2322 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
2323 return xstrdup (DEFAULT_LINKER);
2327 len += strlen (machine_suffix);
2329 multilib_name = name;
2330 multilib_os_name = name;
2331 if (multilib && multilib_os_dir)
2333 int len1 = multilib_dir ? strlen (multilib_dir) + 1 : 0;
2334 int len2 = strlen (multilib_os_dir) + 1;
2336 len += len1 > len2 ? len1 : len2;
2338 multilib_name = ACONCAT ((multilib_dir, dir_separator_str, name,
2340 if (strcmp (multilib_os_dir, ".") != 0)
2341 multilib_os_name = ACONCAT ((multilib_os_dir, dir_separator_str, name,
2345 temp = xmalloc (len);
2347 /* Determine the filename to execute (special case for absolute paths). */
2349 if (IS_ABSOLUTE_PATHNAME (name))
2351 if (access (name, mode) == 0)
2353 strcpy (temp, name);
2358 for (pl = pprefix->plist; pl; pl = pl->next)
2360 const char *this_name
2361 = pl->os_multilib ? multilib_os_name : multilib_name;
2365 /* Some systems have a suffix for executable files.
2366 So try appending that first. */
2367 if (file_suffix[0] != 0)
2369 strcpy (temp, pl->prefix);
2370 strcat (temp, machine_suffix);
2371 strcat (temp, multilib_name);
2372 strcat (temp, file_suffix);
2373 if (access_check (temp, mode) == 0)
2375 if (pl->used_flag_ptr != 0)
2376 *pl->used_flag_ptr = 1;
2381 /* Now try just the multilib_name. */
2382 strcpy (temp, pl->prefix);
2383 strcat (temp, machine_suffix);
2384 strcat (temp, multilib_name);
2385 if (access_check (temp, mode) == 0)
2387 if (pl->used_flag_ptr != 0)
2388 *pl->used_flag_ptr = 1;
2393 /* Certain prefixes are tried with just the machine type,
2394 not the version. This is used for finding as, ld, etc. */
2395 if (just_machine_suffix && pl->require_machine_suffix == 2)
2397 /* Some systems have a suffix for executable files.
2398 So try appending that first. */
2399 if (file_suffix[0] != 0)
2401 strcpy (temp, pl->prefix);
2402 strcat (temp, just_machine_suffix);
2403 strcat (temp, multilib_name);
2404 strcat (temp, file_suffix);
2405 if (access_check (temp, mode) == 0)
2407 if (pl->used_flag_ptr != 0)
2408 *pl->used_flag_ptr = 1;
2413 strcpy (temp, pl->prefix);
2414 strcat (temp, just_machine_suffix);
2415 strcat (temp, multilib_name);
2416 if (access_check (temp, mode) == 0)
2418 if (pl->used_flag_ptr != 0)
2419 *pl->used_flag_ptr = 1;
2424 /* Certain prefixes can't be used without the machine suffix
2425 when the machine or version is explicitly specified. */
2426 if (! pl->require_machine_suffix)
2428 /* Some systems have a suffix for executable files.
2429 So try appending that first. */
2430 if (file_suffix[0] != 0)
2432 strcpy (temp, pl->prefix);
2433 strcat (temp, this_name);
2434 strcat (temp, file_suffix);
2435 if (access_check (temp, mode) == 0)
2437 if (pl->used_flag_ptr != 0)
2438 *pl->used_flag_ptr = 1;
2443 strcpy (temp, pl->prefix);
2444 strcat (temp, this_name);
2445 if (access_check (temp, mode) == 0)
2447 if (pl->used_flag_ptr != 0)
2448 *pl->used_flag_ptr = 1;
2458 /* Ranking of prefixes in the sort list. -B prefixes are put before
2461 enum path_prefix_priority
2463 PREFIX_PRIORITY_B_OPT,
2464 PREFIX_PRIORITY_LAST
2467 /* Add an entry for PREFIX in PLIST. The PLIST is kept in assending
2468 order according to PRIORITY. Within each PRIORITY, new entries are
2471 If WARN is nonzero, we will warn if no file is found
2472 through this prefix. WARN should point to an int
2473 which will be set to 1 if this entry is used.
2475 COMPONENT is the value to be passed to update_path.
2477 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2478 the complete value of machine_suffix.
2479 2 means try both machine_suffix and just_machine_suffix. */
2482 add_prefix (pprefix, prefix, component, priority, require_machine_suffix,
2484 struct path_prefix *pprefix;
2486 const char *component;
2487 /* enum prefix_priority */ int priority;
2488 int require_machine_suffix;
2492 struct prefix_list *pl, **prev;
2495 for (prev = &pprefix->plist;
2496 (*prev) != NULL && (*prev)->priority <= priority;
2497 prev = &(*prev)->next)
2500 /* Keep track of the longest prefix */
2502 prefix = update_path (prefix, component);
2503 len = strlen (prefix);
2504 if (len > pprefix->max_len)
2505 pprefix->max_len = len;
2507 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
2508 pl->prefix = prefix;
2509 pl->require_machine_suffix = require_machine_suffix;
2510 pl->used_flag_ptr = warn;
2511 pl->priority = priority;
2512 pl->os_multilib = os_multilib;
2516 /* Insert after PREV */
2521 /* Execute the command specified by the arguments on the current line of spec.
2522 When using pipes, this includes several piped-together commands
2523 with `|' between them.
2525 Return 0 if successful, -1 if failed. */
2531 int n_commands; /* # of command. */
2535 const char *prog; /* program name. */
2536 const char **argv; /* vector of args. */
2537 int pid; /* pid of process for this command. */
2540 struct command *commands; /* each command buffer with above info. */
2542 if (processing_spec_function)
2545 /* Count # of piped commands. */
2546 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2547 if (strcmp (argbuf[i], "|") == 0)
2550 /* Get storage for each command. */
2551 commands = (struct command *) alloca (n_commands * sizeof (struct command));
2553 /* Split argbuf into its separate piped processes,
2554 and record info about each one.
2555 Also search for the programs that are to be run. */
2557 commands[0].prog = argbuf[0]; /* first command. */
2558 commands[0].argv = &argbuf[0];
2559 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, 0);
2562 commands[0].argv[0] = string;
2564 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2565 if (strcmp (argbuf[i], "|") == 0)
2566 { /* each command. */
2567 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2568 fatal ("-pipe not supported");
2570 argbuf[i] = 0; /* termination of command args. */
2571 commands[n_commands].prog = argbuf[i + 1];
2572 commands[n_commands].argv = &argbuf[i + 1];
2573 string = find_a_file (&exec_prefixes, commands[n_commands].prog,
2576 commands[n_commands].argv[0] = string;
2580 argbuf[argbuf_index] = 0;
2582 /* If -v, print what we are about to do, and maybe query. */
2586 /* For help listings, put a blank line between sub-processes. */
2587 if (print_help_list)
2588 fputc ('\n', stderr);
2590 /* Print each piped command as a separate line. */
2591 for (i = 0; i < n_commands; i++)
2593 const char *const *j;
2595 if (verbose_only_flag)
2597 for (j = commands[i].argv; *j; j++)
2600 fprintf (stderr, " \"");
2601 for (p = *j; *p; ++p)
2603 if (*p == '"' || *p == '\\' || *p == '$')
2604 fputc ('\\', stderr);
2607 fputc ('"', stderr);
2611 for (j = commands[i].argv; *j; j++)
2612 fprintf (stderr, " %s", *j);
2614 /* Print a pipe symbol after all but the last command. */
2615 if (i + 1 != n_commands)
2616 fprintf (stderr, " |");
2617 fprintf (stderr, "\n");
2620 if (verbose_only_flag != 0)
2623 notice ("\nGo ahead? (y or n) ");
2627 while (getchar () != '\n')
2630 if (i != 'y' && i != 'Y')
2635 #ifdef ENABLE_VALGRIND_CHECKING
2636 /* Run the each command through valgrind. To simplifiy prepending the
2637 path to valgrind and the option "-q" (for quiet operation unless
2638 something triggers), we allocate a separate argv array. */
2640 for (i = 0; i < n_commands; i++)
2646 for (argc = 0; commands[i].argv[argc] != NULL; argc++)
2649 argv = alloca ((argc + 3) * sizeof (char *));
2651 argv[0] = VALGRIND_PATH;
2653 for (j = 2; j < argc + 2; j++)
2654 argv[j] = commands[i].argv[j - 2];
2657 commands[i].argv = argv;
2658 commands[i].prog = argv[0];
2662 /* Run each piped subprocess. */
2664 for (i = 0; i < n_commands; i++)
2666 char *errmsg_fmt, *errmsg_arg;
2667 const char *string = commands[i].argv[0];
2669 /* For some bizarre reason, the second argument of execvp() is
2670 char *const *, not const char *const *. */
2671 commands[i].pid = pexecute (string, (char *const *) commands[i].argv,
2672 programname, temp_filename,
2673 &errmsg_fmt, &errmsg_arg,
2674 ((i == 0 ? PEXECUTE_FIRST : 0)
2675 | (i + 1 == n_commands ? PEXECUTE_LAST : 0)
2676 | (string == commands[i].prog
2677 ? PEXECUTE_SEARCH : 0)
2678 | (verbose_flag ? PEXECUTE_VERBOSE : 0)));
2680 if (commands[i].pid == -1)
2681 pfatal_pexecute (errmsg_fmt, errmsg_arg);
2683 if (string != commands[i].prog)
2684 free ((PTR) string);
2689 /* Wait for all the subprocesses to finish.
2690 We don't care what order they finish in;
2691 we know that N_COMMANDS waits will get them all.
2692 Ignore subprocesses that we don't know about,
2693 since they can be spawned by the process that exec'ed us. */
2697 #ifdef HAVE_GETRUSAGE
2699 double ut = 0.0, st = 0.0;
2702 for (i = 0; i < n_commands;)
2708 pid = pwait (commands[i].pid, &status, 0);
2712 #ifdef HAVE_GETRUSAGE
2715 /* getrusage returns the total resource usage of all children
2716 up to now. Copy the previous values into prus, get the
2717 current statistics, then take the difference. */
2720 getrusage (RUSAGE_CHILDREN, &rus);
2721 d.tv_sec = rus.ru_utime.tv_sec - prus.ru_utime.tv_sec;
2722 d.tv_usec = rus.ru_utime.tv_usec - prus.ru_utime.tv_usec;
2723 ut = (double) d.tv_sec + (double) d.tv_usec / 1.0e6;
2725 d.tv_sec = rus.ru_stime.tv_sec - prus.ru_stime.tv_sec;
2726 d.tv_usec = rus.ru_stime.tv_usec - prus.ru_stime.tv_usec;
2727 st = (double) d.tv_sec + (double) d.tv_usec / 1.0e6;
2731 for (j = 0; j < n_commands; j++)
2732 if (commands[j].pid == pid)
2735 if (WIFSIGNALED (status))
2738 /* SIGPIPE is a special case. It happens in -pipe mode
2739 when the compiler dies before the preprocessor is
2740 done, or the assembler dies before the compiler is
2741 done. There's generally been an error already, and
2742 this is just fallout. So don't generate another error
2743 unless we would otherwise have succeeded. */
2744 if (WTERMSIG (status) == SIGPIPE
2745 && (signal_count || greatest_status >= MIN_FATAL_STATUS))
2750 Internal error: %s (program %s)\n\
2751 Please submit a full bug report.\n\
2752 See %s for instructions.",
2753 strsignal (WTERMSIG (status)), commands[j].prog,
2758 else if (WIFEXITED (status)
2759 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
2761 if (WEXITSTATUS (status) > greatest_status)
2762 greatest_status = WEXITSTATUS (status);
2765 #ifdef HAVE_GETRUSAGE
2766 if (report_times && ut + st != 0)
2767 notice ("# %s %.2f %.2f\n", commands[j].prog, ut, st);
2776 /* Find all the switches given to us
2777 and make a vector describing them.
2778 The elements of the vector are strings, one per switch given.
2779 If a switch uses following arguments, then the `part1' field
2780 is the switch itself and the `args' field
2781 is a null-terminated vector containing the following arguments.
2782 The `live_cond' field is:
2784 1 if the switch is true in a conditional spec,
2785 -1 if false (overridden by a later switch)
2786 -2 if this switch should be ignored (used in %{<S})
2787 The `validated' field is nonzero if any spec has looked at this switch;
2788 if it remains zero at the end of the run, it must be meaningless. */
2791 #define SWITCH_FALSE -1
2792 #define SWITCH_IGNORE -2
2793 #define SWITCH_LIVE 1
2800 unsigned char validated;
2801 unsigned char ordering;
2804 static struct switchstr *switches;
2806 static int n_switches;
2811 const char *language;
2814 /* Also a vector of input files specified. */
2816 static struct infile *infiles;
2820 /* This counts the number of libraries added by lang_specific_driver, so that
2821 we can tell if there were any user supplied any files or libraries. */
2823 static int added_libraries;
2825 /* And a vector of corresponding output files is made up later. */
2827 const char **outfiles;
2829 /* Used to track if none of the -B paths are used. */
2832 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2833 static int *warn_std_ptr = 0;
2835 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2837 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2838 is true if we should look for an executable suffix. DO_OBJ
2839 is true if we should look for an object suffix. */
2842 convert_filename (name, do_exe, do_obj)
2844 int do_exe ATTRIBUTE_UNUSED;
2845 int do_obj ATTRIBUTE_UNUSED;
2847 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2855 len = strlen (name);
2857 #ifdef HAVE_TARGET_OBJECT_SUFFIX
2858 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
2859 if (do_obj && len > 2
2860 && name[len - 2] == '.'
2861 && name[len - 1] == 'o')
2863 obstack_grow (&obstack, name, len - 2);
2864 obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
2865 name = obstack_finish (&obstack);
2869 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2870 /* If there is no filetype, make it the executable suffix (which includes
2871 the "."). But don't get confused if we have just "-o". */
2872 if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
2875 for (i = len - 1; i >= 0; i--)
2876 if (IS_DIR_SEPARATOR (name[i]))
2879 for (i++; i < len; i++)
2883 obstack_grow (&obstack, name, len);
2884 obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
2885 strlen (TARGET_EXECUTABLE_SUFFIX));
2886 name = obstack_finish (&obstack);
2893 /* Display the command line switches accepted by gcc. */
2897 printf (_("Usage: %s [options] file...\n"), programname);
2898 fputs (_("Options:\n"), stdout);
2900 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout);
2901 fputs (_(" --help Display this information\n"), stdout);
2902 fputs (_(" --target-help Display target specific command line options\n"), stdout);
2904 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout);
2905 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout);
2906 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout);
2907 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout);
2908 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout);
2909 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout);
2910 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout);
2911 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout);
2912 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout);
2914 -print-multi-lib Display the mapping between command line options and\n\
2915 multiple library search directories\n"), stdout);
2916 fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout);
2917 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout);
2918 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout);
2919 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout);
2920 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout);
2921 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout);
2922 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout);
2923 fputs (_(" -time Time the execution of each subprocess\n"), stdout);
2924 fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout);
2925 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout);
2926 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout);
2927 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout);
2928 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout);
2929 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout);
2930 fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout);
2931 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout);
2932 fputs (_(" -S Compile only; do not assemble or link\n"), stdout);
2933 fputs (_(" -c Compile and assemble, but do not link\n"), stdout);
2934 fputs (_(" -o <file> Place the output into <file>\n"), stdout);
2936 -x <language> Specify the language of the following input files\n\
2937 Permissable languages include: c c++ assembler none\n\
2938 'none' means revert to the default behavior of\n\
2939 guessing the language based on the file's extension\n\
2943 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
2944 passed on to the various sub-processes invoked by %s. In order to pass\n\
2945 other options on to these processes the -W<letter> options must be used.\n\
2948 /* The rest of the options are displayed by invocations of the various
2953 add_preprocessor_option (option, len)
2957 n_preprocessor_options++;
2959 if (! preprocessor_options)
2960 preprocessor_options
2961 = (char **) xmalloc (n_preprocessor_options * sizeof (char *));
2963 preprocessor_options
2964 = (char **) xrealloc (preprocessor_options,
2965 n_preprocessor_options * sizeof (char *));
2967 preprocessor_options [n_preprocessor_options - 1] =
2968 save_string (option, len);
2972 add_assembler_option (option, len)
2976 n_assembler_options++;
2978 if (! assembler_options)
2980 = (char **) xmalloc (n_assembler_options * sizeof (char *));
2983 = (char **) xrealloc (assembler_options,
2984 n_assembler_options * sizeof (char *));
2986 assembler_options [n_assembler_options - 1] = save_string (option, len);
2990 add_linker_option (option, len)
2996 if (! linker_options)
2998 = (char **) xmalloc (n_linker_options * sizeof (char *));
3001 = (char **) xrealloc (linker_options,
3002 n_linker_options * sizeof (char *));
3004 linker_options [n_linker_options - 1] = save_string (option, len);
3007 /* Create the vector `switches' and its contents.
3008 Store its length in `n_switches'. */
3011 process_command (argc, argv)
3013 const char *const *argv;
3018 const char *spec_lang = 0;
3019 int last_language_n_infiles;
3022 int lang_n_infiles = 0;
3023 #ifdef MODIFY_TARGET_NAME
3024 int is_modify_target_name;
3028 GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
3032 added_libraries = 0;
3034 /* Figure compiler version from version string. */
3036 compiler_version = temp1 = xstrdup (version_string);
3038 for (; *temp1; ++temp1)
3047 /* If there is a -V or -b option (or both), process it now, before
3048 trying to interpret the rest of the command line. */
3049 if (argc > 1 && argv[1][0] == '-'
3050 && (argv[1][1] == 'V' || argv[1][1] == 'b'))
3052 const char *new_version = DEFAULT_TARGET_VERSION;
3053 const char *new_machine = DEFAULT_TARGET_MACHINE;
3054 const char *progname = argv[0];
3059 while (argc > 1 && argv[1][0] == '-'
3060 && (argv[1][1] == 'V' || argv[1][1] == 'b'))
3062 char opt = argv[1][1];
3064 if (argv[1][2] != '\0')
3077 fatal ("`-%c' option must have argument", opt);
3084 for (baselen = strlen (progname); baselen > 0; baselen--)
3085 if (IS_DIR_SEPARATOR (progname[baselen-1]))
3087 new_argv0 = xmemdup (progname, baselen,
3088 baselen + concat_length (new_version, new_machine,
3089 "-gcc-", NULL) + 1);
3090 strcpy (new_argv0 + baselen, new_machine);
3091 strcat (new_argv0, "-gcc-");
3092 strcat (new_argv0, new_version);
3094 new_argv = xmemdup (argv, (argc + 1) * sizeof (argv[0]),
3095 (argc + 1) * sizeof (argv[0]));
3096 new_argv[0] = new_argv0;
3098 execvp (new_argv0, new_argv);
3099 fatal ("couldn't run `%s': %s", new_argv0, xstrerror (errno));
3102 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3103 see if we can create it from the pathname specified in argv[0]. */
3106 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3107 if (!gcc_exec_prefix)
3109 gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix,
3110 standard_exec_prefix);
3111 if (gcc_exec_prefix)
3112 putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
3116 if (gcc_exec_prefix)
3118 int len = strlen (gcc_exec_prefix);
3120 if (len > (int) sizeof ("/lib/gcc-lib/") - 1
3121 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
3123 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1;
3124 if (IS_DIR_SEPARATOR (*temp)
3125 && strncmp (temp + 1, "lib", 3) == 0
3126 && IS_DIR_SEPARATOR (temp[4])
3127 && strncmp (temp + 5, "gcc-lib", 7) == 0)
3128 len -= sizeof ("/lib/gcc-lib/") - 1;
3131 set_std_prefix (gcc_exec_prefix, len);
3132 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC",
3133 PREFIX_PRIORITY_LAST, 0, NULL, 0);
3134 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
3135 PREFIX_PRIORITY_LAST, 0, NULL, 0);
3138 /* COMPILER_PATH and LIBRARY_PATH have values
3139 that are lists of directory names with colons. */
3141 GET_ENVIRONMENT (temp, "COMPILER_PATH");
3144 const char *startp, *endp;
3145 char *nstore = (char *) alloca (strlen (temp) + 3);
3147 startp = endp = temp;
3150 if (*endp == PATH_SEPARATOR || *endp == 0)
3152 strncpy (nstore, startp, endp - startp);
3154 strcpy (nstore, concat (".", dir_separator_str, NULL));
3155 else if (!IS_DIR_SEPARATOR (endp[-1]))
3157 nstore[endp - startp] = DIR_SEPARATOR;
3158 nstore[endp - startp + 1] = 0;
3161 nstore[endp - startp] = 0;
3162 add_prefix (&exec_prefixes, nstore, 0,
3163 PREFIX_PRIORITY_LAST, 0, NULL, 0);
3164 add_prefix (&include_prefixes,
3165 concat (nstore, "include", NULL),
3166 0, PREFIX_PRIORITY_LAST, 0, NULL, 0);
3169 endp = startp = endp + 1;
3176 GET_ENVIRONMENT (temp, LIBRARY_PATH_ENV);
3177 if (temp && *cross_compile == '0')
3179 const char *startp, *endp;
3180 char *nstore = (char *) alloca (strlen (temp) + 3);
3182 startp = endp = temp;
3185 if (*endp == PATH_SEPARATOR || *endp == 0)
3187 strncpy (nstore, startp, endp - startp);
3189 strcpy (nstore, concat (".", dir_separator_str, NULL));
3190 else if (!IS_DIR_SEPARATOR (endp[-1]))
3192 nstore[endp - startp] = DIR_SEPARATOR;
3193 nstore[endp - startp + 1] = 0;
3196 nstore[endp - startp] = 0;
3197 add_prefix (&startfile_prefixes, nstore, NULL,
3198 PREFIX_PRIORITY_LAST, 0, NULL, 1);
3201 endp = startp = endp + 1;
3208 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3209 GET_ENVIRONMENT (temp, "LPATH");
3210 if (temp && *cross_compile == '0')
3212 const char *startp, *endp;
3213 char *nstore = (char *) alloca (strlen (temp) + 3);
3215 startp = endp = temp;
3218 if (*endp == PATH_SEPARATOR || *endp == 0)
3220 strncpy (nstore, startp, endp - startp);
3222 strcpy (nstore, concat (".", dir_separator_str, NULL));
3223 else if (!IS_DIR_SEPARATOR (endp[-1]))
3225 nstore[endp - startp] = DIR_SEPARATOR;
3226 nstore[endp - startp + 1] = 0;
3229 nstore[endp - startp] = 0;
3230 add_prefix (&startfile_prefixes, nstore, NULL,
3231 PREFIX_PRIORITY_LAST, 0, NULL, 1);
3234 endp = startp = endp + 1;
3241 /* Convert new-style -- options to old-style. */
3242 translate_options (&argc, &argv);
3244 /* Do language-specific adjustment/addition of flags. */
3245 lang_specific_driver (&argc, &argv, &added_libraries);
3247 /* Scan argv twice. Here, the first time, just count how many switches
3248 there will be in their vector, and how many input files in theirs.
3249 Here we also parse the switches that cc itself uses (e.g. -v). */
3251 for (i = 1; i < argc; i++)
3253 if (! strcmp (argv[i], "-dumpspecs"))
3255 struct spec_list *sl;
3257 for (sl = specs; sl; sl = sl->next)
3258 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
3259 if (link_command_spec)
3260 printf ("*link_command:\n%s\n\n", link_command_spec);
3263 else if (! strcmp (argv[i], "-dumpversion"))
3265 printf ("%s\n", spec_version);
3268 else if (! strcmp (argv[i], "-dumpmachine"))
3270 printf ("%s\n", spec_machine);
3273 else if (strcmp (argv[i], "-fversion") == 0)
3275 /* translate_options () has turned --version into -fversion. */
3276 printf (_("%s (GCC) %s\n"), programname, version_string);
3277 fputs (_("Copyright (C) 2002 Free Software Foundation, Inc.\n"),
3279 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
3280 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
3284 else if (strcmp (argv[i], "-fhelp") == 0)
3286 /* translate_options () has turned --help into -fhelp. */
3287 print_help_list = 1;
3289 /* We will be passing a dummy file on to the sub-processes. */
3293 /* CPP driver cannot obtain switch from cc1_options. */
3295 add_preprocessor_option ("--help", 6);
3296 add_assembler_option ("--help", 6);
3297 add_linker_option ("--help", 6);
3299 else if (strcmp (argv[i], "-ftarget-help") == 0)
3301 /* translate_options() has turned --target-help into -ftarget-help. */
3302 target_help_flag = 1;
3304 /* We will be passing a dummy file on to the sub-processes. */
3308 /* CPP driver cannot obtain switch from cc1_options. */
3310 add_preprocessor_option ("--target-help", 13);
3311 add_assembler_option ("--target-help", 13);
3312 add_linker_option ("--target-help", 13);
3314 else if (! strcmp (argv[i], "-pass-exit-codes"))
3316 pass_exit_codes = 1;
3319 else if (! strcmp (argv[i], "-print-search-dirs"))
3320 print_search_dirs = 1;
3321 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3322 print_file_name = "libgcc.a";
3323 else if (! strncmp (argv[i], "-print-file-name=", 17))
3324 print_file_name = argv[i] + 17;
3325 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3326 print_prog_name = argv[i] + 17;
3327 else if (! strcmp (argv[i], "-print-multi-lib"))
3328 print_multi_lib = 1;
3329 else if (! strcmp (argv[i], "-print-multi-directory"))
3330 print_multi_directory = 1;
3331 else if (! strcmp (argv[i], "-print-multi-os-directory"))
3332 print_multi_os_directory = 1;
3333 else if (! strncmp (argv[i], "-Wa,", 4))
3336 /* Pass the rest of this option to the assembler. */
3338 /* Split the argument at commas. */
3340 for (j = 4; argv[i][j]; j++)
3341 if (argv[i][j] == ',')
3343 add_assembler_option (argv[i] + prev, j - prev);
3347 /* Record the part after the last comma. */
3348 add_assembler_option (argv[i] + prev, j - prev);
3350 else if (! strncmp (argv[i], "-Wp,", 4))
3353 /* Pass the rest of this option to the preprocessor. */
3355 /* Split the argument at commas. */
3357 for (j = 4; argv[i][j]; j++)
3358 if (argv[i][j] == ',')
3360 add_preprocessor_option (argv[i] + prev, j - prev);
3364 /* Record the part after the last comma. */
3365 add_preprocessor_option (argv[i] + prev, j - prev);
3367 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3368 /* The +e options to the C++ front-end. */
3370 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3373 /* Split the argument at commas. */
3374 for (j = 3; argv[i][j]; j++)
3375 n_infiles += (argv[i][j] == ',');
3377 else if (strcmp (argv[i], "-Xlinker") == 0)
3380 fatal ("argument to `-Xlinker' is missing");
3385 else if (strcmp (argv[i], "-l") == 0)
3388 fatal ("argument to `-l' is missing");
3393 else if (strncmp (argv[i], "-l", 2) == 0)
3395 else if (strcmp (argv[i], "-save-temps") == 0)
3397 save_temps_flag = 1;
3400 else if (strcmp (argv[i], "-specs") == 0)
3402 struct user_specs *user = (struct user_specs *)
3403 xmalloc (sizeof (struct user_specs));
3405 fatal ("argument to `-specs' is missing");
3407 user->next = (struct user_specs *) 0;
3408 user->filename = argv[i];
3409 if (user_specs_tail)
3410 user_specs_tail->next = user;
3412 user_specs_head = user;
3413 user_specs_tail = user;
3415 else if (strncmp (argv[i], "-specs=", 7) == 0)
3417 struct user_specs *user = (struct user_specs *)
3418 xmalloc (sizeof (struct user_specs));
3419 if (strlen (argv[i]) == 7)
3420 fatal ("argument to `-specs=' is missing");
3422 user->next = (struct user_specs *) 0;
3423 user->filename = argv[i] + 7;
3424 if (user_specs_tail)
3425 user_specs_tail->next = user;
3427 user_specs_head = user;
3428 user_specs_tail = user;
3430 else if (strcmp (argv[i], "-time") == 0)
3432 else if (strcmp (argv[i], "-###") == 0)
3434 /* This is similar to -v except that there is no execution
3435 of the commands and the echoed arguments are quoted. It
3436 is intended for use in shell scripts to capture the
3437 driver-generated command line. */
3438 verbose_only_flag++;
3441 else if (argv[i][0] == '-' && argv[i][1] != 0)
3443 const char *p = &argv[i][1];
3450 fatal ("`-%c' must come at the start of the command line", c);
3458 if (p[1] == 0 && i + 1 == argc)
3459 fatal ("argument to `-B' is missing");
3465 len = strlen (value);
3467 /* Catch the case where the user has forgotten to append a
3468 directory separator to the path. Note, they may be using
3469 -B to add an executable name prefix, eg "i386-elf-", in
3470 order to distinguish between multiple installations of
3471 GCC in the same directory. Hence we must check to see
3472 if appending a directory separator actually makes a
3473 valid directory name. */
3474 if (! IS_DIR_SEPARATOR (value [len - 1])
3475 && is_directory (value, "", 0))
3477 char *tmp = xmalloc (len + 2);
3478 strcpy (tmp, value);
3479 tmp[len] = DIR_SEPARATOR;
3484 /* As a kludge, if the arg is "[foo/]stageN/", just
3485 add "[foo/]include" to the include prefix. */
3488 && (IS_DIR_SEPARATOR (value[len - 8]))))
3489 && strncmp (value + len - 7, "stage", 5) == 0
3490 && ISDIGIT (value[len - 2])
3491 && (IS_DIR_SEPARATOR (value[len - 1])))
3494 add_prefix (&include_prefixes, "include", NULL,
3495 PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
3498 char * string = xmalloc (len + 1);
3500 strncpy (string, value, len - 7);
3501 strcpy (string + len - 7, "include");
3502 add_prefix (&include_prefixes, string, NULL,
3503 PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
3507 add_prefix (&exec_prefixes, value, NULL,
3508 PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
3509 add_prefix (&startfile_prefixes, value, NULL,
3510 PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
3511 add_prefix (&include_prefixes, concat (value, "include", NULL),
3512 NULL, PREFIX_PRIORITY_B_OPT, 0, NULL, 0);