1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 This paragraph is here to try to keep Sun CC from dying.
23 The number of chars here seems crucial!!!! */
25 /* This program is the user interface to the C compiler and possibly to
26 other compilers. It is used because compilation is a complicated procedure
27 which involves running several programs and passing temporary files between
28 them, forwarding the users switches to those programs selectively,
29 and deleting the temporary files at the end.
31 CC recognizes how to compile each input file by suffixes in the file names.
32 Once it knows which kind of compilation to perform, the procedure for
33 compilation is specified by a string called a "spec". */
35 /* A Short Introduction to Adding a Command-Line Option.
37 Before adding a command-line option, consider if it is really
38 necessary. Each additional command-line option adds complexity and
39 is difficult to remove in subsequent versions.
41 In the following, consider adding the command-line argument
44 1. Each command-line option is specified in the specs file. The
45 notation is described below in the comment entitled "The Specs
48 2. In this file, add an entry to "option_map" equating the long
49 `--' argument version and any shorter, single letter version. Read
50 the comments in the declaration of "struct option_map" for an
51 explanation. Do not omit the first `-'.
53 3. Look in the "specs" file to determine which program or option
54 list should be given the argument, e.g., "cc1_options". Add the
55 appropriate syntax for the shorter option version to the
56 corresponding "const char *" entry in this file. Omit the first
57 `-' from the option. For example, use `-bar', rather than `--bar'.
59 4. If the argument takes an argument, e.g., `--baz argument1',
60 modify either DEFAULT_SWITCH_TAKES_ARG or
61 DEFAULT_WORD_SWITCH_TAKES_ARG in this file. Omit the first `-'
64 5. Document the option in this file's display_help(). If the
65 option is passed to a subprogram, modify its corresponding
66 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
69 6. Compile and test. Make sure that your new specs file is being
70 read. For example, use a debugger to investigate the value of
71 "specs_file" in main(). */
76 #if ! defined( SIGCHLD ) && defined( SIGCLD )
77 # define SIGCHLD SIGCLD
85 #define exit __posix_exit
88 #ifdef HAVE_SYS_RESOURCE_H
89 #include <sys/resource.h>
91 #if defined (HAVE_DECL_GETRUSAGE) && !HAVE_DECL_GETRUSAGE
92 extern int getrusage
PARAMS ((int, struct rusage
*));
95 /* By default there is no special suffix for target executables. */
96 /* FIXME: when autoconf is fixed, remove the host check - dj */
97 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
98 #define HAVE_TARGET_EXECUTABLE_SUFFIX
100 #undef TARGET_EXECUTABLE_SUFFIX
101 #define TARGET_EXECUTABLE_SUFFIX ""
104 /* By default there is no special suffix for host executables. */
105 #ifdef HOST_EXECUTABLE_SUFFIX
106 #define HAVE_HOST_EXECUTABLE_SUFFIX
108 #define HOST_EXECUTABLE_SUFFIX ""
111 /* By default, the suffix for target object files is ".o". */
112 #ifdef TARGET_OBJECT_SUFFIX
113 #define HAVE_TARGET_OBJECT_SUFFIX
115 #define TARGET_OBJECT_SUFFIX ".o"
119 /* FIXME: the location independence code for VMS is hairier than this,
120 and hasn't been written. */
126 static const char dir_separator_str
[] = { DIR_SEPARATOR
, 0 };
128 #define obstack_chunk_alloc xmalloc
129 #define obstack_chunk_free free
131 #ifndef GET_ENV_PATH_LIST
132 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
135 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
136 #ifndef LIBRARY_PATH_ENV
137 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
141 #define kill(p,s) raise(s)
144 /* If a stage of compilation returns an exit status >= 1,
145 compilation of that file ceases. */
147 #define MIN_FATAL_STATUS 1
149 /* Flag saying to pass the greatest exit code returned by a sub-process
150 to the calling program. */
151 static int pass_exit_codes
;
153 /* Definition of string containing the arguments given to configure. */
154 #include "configargs.h"
156 /* Flag saying to print the directories gcc will search through looking for
157 programs, libraries, etc. */
159 static int print_search_dirs
;
161 /* Flag saying to print the full filename of this file
162 as found through our usual search mechanism. */
164 static const char *print_file_name
= NULL
;
166 /* As print_file_name, but search for executable file. */
168 static const char *print_prog_name
= NULL
;
170 /* Flag saying to print the relative path we'd use to
171 find libgcc.a given the current compiler flags. */
173 static int print_multi_directory
;
175 /* Flag saying to print the list of subdirectories and
176 compiler flags used to select them in a standard form. */
178 static int print_multi_lib
;
180 /* Flag saying to print the command line options understood by gcc and its
183 static int print_help_list
;
185 /* Flag indicating whether we should print the command and arguments */
187 static int verbose_flag
;
189 /* Flag indicating to print target specific command line options. */
191 static int target_help_flag
;
193 /* Flag indicating whether we should report subprocess execution times
194 (if this is supported by the system - see pexecute.c). */
196 static int report_times
;
198 /* Nonzero means write "temp" files in source directory
199 and use the source file's name in them, and don't delete them. */
201 static int save_temps_flag
;
203 /* The compiler version. */
205 static const char *compiler_version
;
207 /* The target version specified with -V */
209 static const char *spec_version
= DEFAULT_TARGET_VERSION
;
211 /* The target machine specified with -b. */
213 static const char *spec_machine
= DEFAULT_TARGET_MACHINE
;
215 /* Nonzero if cross-compiling.
216 When -b is used, the value comes from the `specs' file. */
219 static const char *cross_compile
= "1";
221 static const char *cross_compile
= "0";
224 #ifdef MODIFY_TARGET_NAME
226 /* Information on how to alter the target name based on a command-line
227 switch. The only case we support now is simply appending or deleting a
228 string to or from the end of the first part of the configuration name. */
230 const struct modify_target
232 const char *const sw
;
233 const enum add_del
{ADD
, DELETE
} add_del
;
234 const char *const str
;
236 modify_target
[] = MODIFY_TARGET_NAME
;
239 /* The number of errors that have occurred; the link phase will not be
240 run if this is non-zero. */
241 static int error_count
= 0;
243 /* Greatest exit code of sub-processes that has been encountered up to
245 static int greatest_status
= 1;
247 /* This is the obstack which we use to allocate many strings. */
249 static struct obstack obstack
;
251 /* This is the obstack to build an environment variable to pass to
252 collect2 that describes all of the relevant switches of what to
253 pass the compiler in building the list of pointers to constructors
256 static struct obstack collect_obstack
;
258 /* These structs are used to collect resource usage information for
260 #ifdef HAVE_GETRUSAGE
261 static struct rusage rus
, prus
;
264 /* Forward declaration for prototypes. */
267 static void init_spec
PARAMS ((void));
269 static char **split_directories
PARAMS ((const char *, int *));
270 static void free_split_directories
PARAMS ((char **));
271 static char *make_relative_prefix
PARAMS ((const char *, const char *, const char *));
273 static void store_arg
PARAMS ((const char *, int, int));
274 static char *load_specs
PARAMS ((const char *));
275 static void read_specs
PARAMS ((const char *, int));
276 static void set_spec
PARAMS ((const char *, const char *));
277 static struct compiler
*lookup_compiler
PARAMS ((const char *, size_t, const char *));
278 static char *build_search_list
PARAMS ((struct path_prefix
*, const char *, int));
279 static void putenv_from_prefixes
PARAMS ((struct path_prefix
*, const char *));
280 static int access_check
PARAMS ((const char *, int));
281 static char *find_a_file
PARAMS ((struct path_prefix
*, const char *, int));
282 static void add_prefix
PARAMS ((struct path_prefix
*, const char *,
283 const char *, int, int, int *));
284 static void translate_options
PARAMS ((int *, const char *const **));
285 static char *skip_whitespace
PARAMS ((char *));
286 static void delete_if_ordinary
PARAMS ((const char *));
287 static void delete_temp_files
PARAMS ((void));
288 static void delete_failure_queue
PARAMS ((void));
289 static void clear_failure_queue
PARAMS ((void));
290 static int check_live_switch
PARAMS ((int, int));
291 static const char *handle_braces
PARAMS ((const char *));
292 static char *save_string
PARAMS ((const char *, int));
293 static int do_spec_1
PARAMS ((const char *, int, const char *));
294 static const char *find_file
PARAMS ((const char *));
295 static int is_directory
PARAMS ((const char *, const char *, int));
296 static void validate_switches
PARAMS ((const char *));
297 static void validate_all_switches
PARAMS ((void));
298 static void give_switch
PARAMS ((int, int, int));
299 static int used_arg
PARAMS ((const char *, int));
300 static int default_arg
PARAMS ((const char *, int));
301 static void set_multilib_dir
PARAMS ((void));
302 static void print_multilib_info
PARAMS ((void));
303 static void perror_with_name
PARAMS ((const char *));
304 static void pfatal_pexecute
PARAMS ((const char *, const char *))
306 static void notice
PARAMS ((const char *, ...))
308 static void display_help
PARAMS ((void));
309 static void add_preprocessor_option
PARAMS ((const char *, int));
310 static void add_assembler_option
PARAMS ((const char *, int));
311 static void add_linker_option
PARAMS ((const char *, int));
312 static void process_command
PARAMS ((int, const char *const *));
313 static int execute
PARAMS ((void));
314 static void clear_args
PARAMS ((void));
315 static void fatal_error
PARAMS ((int));
316 static void set_input
PARAMS ((const char *));
317 #ifdef ENABLE_SHARED_LIBGCC
318 static void init_gcc_specs
PARAMS ((struct obstack
*,
322 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
323 static const char *convert_filename
PARAMS ((const char *, int));
326 /* The Specs Language
328 Specs are strings containing lines, each of which (if not blank)
329 is made up of a program name, and arguments separated by spaces.
330 The program name must be exact and start from root, since no path
331 is searched and it is unreliable to depend on the current working directory.
332 Redirection of input or output is not supported; the subprograms must
333 accept filenames saying what files to read and write.
335 In addition, the specs can contain %-sequences to substitute variable text
336 or for conditional text. Here is a table of all defined %-sequences.
337 Note that spaces are not generated automatically around the results of
338 expanding these sequences; therefore, you can concatenate them together
339 or with constant text in a single argument.
341 %% substitute one % into the program name or argument.
342 %i substitute the name of the input file being processed.
343 %b substitute the basename of the input file being processed.
344 This is the substring up to (and not including) the last period
345 and not including the directory.
346 %B same as %b, but include the file suffix (text after the last period).
348 substitute a file name that has suffix SUFFIX and is chosen
349 once per compilation, and mark the argument a la %d. To reduce
350 exposure to denial-of-service attacks, the file name is now
351 chosen in a way that is hard to predict even when previously
352 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
353 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
354 the regexp "[.A-Za-z]*%O"; "%O" is treated exactly as if it
355 had been pre-processed. Previously, %g was simply substituted
356 with a file name chosen once per compilation, without regard
357 to any appended suffix (which was therefore treated just like
358 ordinary text), making such attacks more likely to succeed.
360 like %g, but generates a new temporary file name even if %uSUFFIX
363 substitutes the last file name generated with %uSUFFIX, generating a
364 new one if there is no such last file name. In the absence of any
365 %uSUFFIX, this is just like %gSUFFIX, except they don't share
366 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
367 would involve the generation of two distinct file names, one
368 for each `%g.s' and another for each `%U.s'. Previously, %U was
369 simply substituted with a file name chosen for the previous %u,
370 without regard to any appended suffix.
372 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
373 writable, and if save-temps is off; otherwise, substitute the name
374 of a temporary file, just like %u. This temporary file is not
375 meant for communication between processes, but rather as a junk
378 substitutes .SUFFIX for the suffixes of a matched switch's args when
379 it is subsequently output with %*. SUFFIX is terminated by the next
381 %d marks the argument containing or following the %d as a
382 temporary file name, so that that file will be deleted if CC exits
383 successfully. Unlike %g, this contributes no text to the argument.
384 %w marks the argument containing or following the %w as the
385 "output file" of this compilation. This puts the argument
386 into the sequence of arguments that %o will substitute later.
388 like %{...} but mark last argument supplied within
389 as a file to be deleted on failure.
390 %o substitutes the names of all the output files, with spaces
391 automatically placed around them. You should write spaces
392 around the %o as well or the results are undefined.
393 %o is for use in the specs for running the linker.
394 Input files whose names have no recognized suffix are not compiled
395 at all, but they are included among the output files, so they will
397 %O substitutes the suffix for object files. Note that this is
398 handled specially when it immediately follows %g, %u, or %U
399 (with or without a suffix argument) because of the need for
400 those to form complete file names. The handling is such that
401 %O is treated exactly as if it had already been substituted,
402 except that %g, %u, and %U do not currently support additional
403 SUFFIX characters following %O as they would following, for
405 %p substitutes the standard macro predefinitions for the
406 current target machine. Use this when running cpp.
407 %P like %p, but puts `__' before and after the name of each macro.
408 (Except macros that already have __.)
410 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
411 %s current argument is the name of a library or startup file of some sort.
412 Search for that file in a standard list of directories
413 and substitute the full name found.
414 %eSTR Print STR as an error message. STR is terminated by a newline.
415 Use this when inconsistent options are detected.
416 %nSTR Print STR as an notice. STR is terminated by a newline.
417 %x{OPTION} Accumulate an option for %X.
418 %X Output the accumulated linker options specified by compilations.
419 %Y Output the accumulated assembler options specified by compilations.
420 %Z Output the accumulated preprocessor options specified by compilations.
421 %v1 Substitute the major version number of GCC.
422 (For version 2.5.3, this is 2.)
423 %v2 Substitute the minor version number of GCC.
424 (For version 2.5.3, this is 5.)
425 %v3 Substitute the patch level number of GCC.
426 (For version 2.5.3, this is 3.)
427 %a process ASM_SPEC as a spec.
428 This allows config.h to specify part of the spec for running as.
429 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
430 used here. This can be used to run a post-processor after the
431 assembler has done its job.
432 %D Dump out a -L option for each directory in startfile_prefixes.
433 If multilib_dir is set, extra entries are generated with it affixed.
434 %l process LINK_SPEC as a spec.
435 %L process LIB_SPEC as a spec.
436 %G process LIBGCC_SPEC as a spec.
437 %M output multilib_dir with directory separators replaced with "_";
438 if multilib_dir is not set or is ".", output "".
439 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
440 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
441 %c process SIGNED_CHAR_SPEC as a spec.
442 %C process CPP_SPEC as a spec.
443 %1 process CC1_SPEC as a spec.
444 %2 process CC1PLUS_SPEC as a spec.
445 %| output "-" if the input for the current command is coming from a pipe.
446 %* substitute the variable part of a matched option. (See below.)
447 Note that each comma in the substituted string is replaced by
449 %{S} substitutes the -S switch, if that switch was given to CC.
450 If that switch was not specified, this substitutes nothing.
451 Here S is a metasyntactic variable.
452 %{S*} substitutes all the switches specified to CC whose names start
453 with -S. This is used for -o, -I, etc; switches that take
454 arguments. CC considers `-o foo' as being one switch whose
455 name starts with `o'. %{o*} would substitute this text,
456 including the space; thus, two arguments would be generated.
457 %{^S*} likewise, but don't put a blank between a switch and any args.
458 %{S*&T*} likewise, but preserve order of S and T options (the order
459 of S and T in the spec is not significant). Can be any number
460 of ampersand-separated variables; for each the wild card is
461 optional. Useful for CPP as %{D*&U*&A*}.
462 %{S*:X} substitutes X if one or more switches whose names start with -S are
463 specified to CC. Note that the tail part of the -S option
464 (i.e. the part matched by the `*') will be substituted for each
465 occurrence of %* within X.
466 %{<S} remove all occurrences of -S from the command line.
467 Note - this option is position dependent. % commands in the
468 spec string before this option will see -S, % commands in the
469 spec string after this option will not.
470 %{S:X} substitutes X, but only if the -S switch was given to CC.
471 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
472 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
473 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
474 %{.S:X} substitutes X, but only if processing a file with suffix S.
475 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
476 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
477 combined with ! and . as above binding stronger than the OR.
478 %(Spec) processes a specification defined in a specs file as *Spec:
479 %[Spec] as above, but put __ around -D arguments
481 The conditional text X in a %{S:X} or %{!S:X} construct may contain
482 other nested % constructs or spaces, or even newlines. They are
483 processed as usual, as described above.
485 The -O, -f, -m, and -W switches are handled specifically in these
486 constructs. If another value of -O or the negated form of a -f, -m, or
487 -W switch is found later in the command line, the earlier switch
488 value is ignored, except with {S*} where S is just one letter; this
489 passes all matching options.
491 The character | at the beginning of the predicate text is used to indicate
492 that a command should be piped to the following command, but only if -pipe
495 Note that it is built into CC which switches take arguments and which
496 do not. You might think it would be useful to generalize this to
497 allow each compiler's spec to say which switches take arguments. But
498 this cannot be done in a consistent fashion. CC cannot even decide
499 which input files have been specified without knowing which switches
500 take arguments, and it must know which input files to compile in order
501 to tell which compilers to run.
503 CC also knows implicitly that arguments starting in `-l' are to be
504 treated as compiler output files, and passed to the linker in their
505 proper position among the other output files. */
507 /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
509 /* config.h can define ASM_SPEC to provide extra args to the assembler
510 or extra switch-translations. */
515 /* config.h can define ASM_FINAL_SPEC to run a post processor after
516 the assembler has run. */
517 #ifndef ASM_FINAL_SPEC
518 #define ASM_FINAL_SPEC ""
521 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
522 or extra switch-translations. */
527 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
528 or extra switch-translations. */
533 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
534 or extra switch-translations. */
536 #define CC1PLUS_SPEC ""
539 /* config.h can define LINK_SPEC to provide extra args to the linker
540 or extra switch-translations. */
545 /* config.h can define LIB_SPEC to override the default libraries. */
547 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
550 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
553 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
554 /* Have gcc do the search for libgcc.a. */
555 #define LIBGCC_SPEC "libgcc.a%s"
557 #define LIBGCC_SPEC "-lgcc"
561 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
562 #ifndef STARTFILE_SPEC
563 #define STARTFILE_SPEC \
564 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
567 /* config.h can define SWITCHES_NEED_SPACES to control which options
568 require spaces between the option and the argument. */
569 #ifndef SWITCHES_NEED_SPACES
570 #define SWITCHES_NEED_SPACES ""
573 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
575 #define ENDFILE_SPEC ""
578 /* This spec is used for telling cpp whether char is signed or not. */
579 #ifndef SIGNED_CHAR_SPEC
580 /* Use #if rather than ?:
581 because MIPS C compiler rejects like ?: in initializers. */
582 #if DEFAULT_SIGNED_CHAR
583 #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
585 #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
590 #define LINKER_NAME "collect2"
593 /* Here is the spec for running the linker, after compiling all files. */
595 /* -u* was put back because both BSD and SysV seem to support it. */
596 /* %{static:} simply prevents an error message if the target machine
597 doesn't handle -static. */
598 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
599 scripts which exist in user specified directories, or in standard
601 #ifndef LINK_COMMAND_SPEC
602 #define LINK_COMMAND_SPEC "\
603 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
604 %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
605 %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
606 %{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\
607 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
610 #ifndef LINK_LIBGCC_SPEC
611 # ifdef LINK_LIBGCC_SPECIAL
612 /* Don't generate -L options for startfile prefix list. */
613 # define LINK_LIBGCC_SPEC ""
615 /* Do generate them. */
616 # define LINK_LIBGCC_SPEC "%D"
620 static const char *cpp_spec
= CPP_SPEC
;
621 static const char *cpp_predefines
= CPP_PREDEFINES
;
622 static const char *cc1_spec
= CC1_SPEC
;
623 static const char *cc1plus_spec
= CC1PLUS_SPEC
;
624 static const char *signed_char_spec
= SIGNED_CHAR_SPEC
;
625 static const char *asm_spec
= ASM_SPEC
;
626 static const char *asm_final_spec
= ASM_FINAL_SPEC
;
627 static const char *link_spec
= LINK_SPEC
;
628 static const char *lib_spec
= LIB_SPEC
;
629 static const char *libgcc_spec
= LIBGCC_SPEC
;
630 static const char *endfile_spec
= ENDFILE_SPEC
;
631 static const char *startfile_spec
= STARTFILE_SPEC
;
632 static const char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
633 static const char *linker_name_spec
= LINKER_NAME
;
634 static const char *link_command_spec
= LINK_COMMAND_SPEC
;
635 static const char *link_libgcc_spec
= LINK_LIBGCC_SPEC
;
637 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
638 There should be no need to override these in target dependent files,
639 but we need to copy them to the specs file so that newer versions
640 of the GCC driver can correctly drive older tool chains with the
641 appropriate -B options. */
643 static const char *trad_capable_cpp
=
644 "%{traditional|ftraditional|traditional-cpp:trad}cpp0";
646 static const char *cpp_options
=
647 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
648 %{std*} %{nostdinc*}\
649 %{C} %{v} %{I*} %{P} %{$} %I\
650 %{MD:-M -MF %W{!o: %b.d}%W{o*:%.d%*}}\
651 %{MMD:-MM -MF %W{!o: %b.d}%W{o*:%.d%*}}\
652 %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
653 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
654 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
655 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
656 %{fno-inline|O0|!O*:-D__NO_INLINE__} %{ffast-math:-D__FAST_MATH__}\
657 %{fshort-wchar:-U__WCHAR_TYPE__ -D__WCHAR_TYPE__=short\\ unsigned\\ int}\
658 %{ffreestanding:-D__STDC_HOSTED__=0} %{fno-hosted:-D__STDC_HOSTED__=0}\
659 %{!ffreestanding:%{!fno-hosted:-D__STDC_HOSTED__=1}}\
660 %{fshow-column} %{fno-show-column}\
661 %{fleading-underscore} %{fno-leading-underscore}\
662 %{fno-operator-names} %{ftabstop=*} %{remap}\
663 %{g3:-dD} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*&U*&A*} %{i*} %Z %i\
666 /* NB: This is shared amongst all front-ends. */
667 static const char *cc1_options
=
668 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
669 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
670 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*} %{ansi}\
671 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
672 %{Qn:-fno-ident} %{--help:--help}\
673 %{--target-help:--target-help}\
674 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
675 %{fsyntax-only:-o %j} %{-param*}";
677 static const char *asm_options
=
678 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
680 static const char *invoke_as
=
681 "%{!S:-o %{|!pipe:%g.s} |\n as %(asm_options) %{!pipe:%g.s} %A }";
683 /* Some compilers have limits on line lengths, and the multilib_select
684 and/or multilib_matches strings can be very long, so we build them at
686 static struct obstack multilib_obstack
;
687 static const char *multilib_select
;
688 static const char *multilib_matches
;
689 static const char *multilib_defaults
;
690 static const char *multilib_exclusions
;
691 #include "multilib.h"
693 /* Check whether a particular argument is a default argument. */
695 #ifndef MULTILIB_DEFAULTS
696 #define MULTILIB_DEFAULTS { "" }
699 static const char *const multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
703 struct user_specs
*next
;
704 const char *filename
;
707 static struct user_specs
*user_specs_head
, *user_specs_tail
;
709 /* This defines which switch letters take arguments. */
711 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
712 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
713 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
714 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
715 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \
716 || (CHAR) == 'B' || (CHAR) == 'b')
718 #ifndef SWITCH_TAKES_ARG
719 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
722 /* This defines which multi-letter switches take arguments. */
724 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
725 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
726 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
727 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
728 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
729 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
730 || !strcmp (STR, "isystem") || !strcmp (STR, "-param") \
731 || !strcmp (STR, "specs") \
732 || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
734 #ifndef WORD_SWITCH_TAKES_ARG
735 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
738 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
739 /* This defines which switches stop a full compilation. */
740 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
741 ((CHAR) == 'c' || (CHAR) == 'S')
743 #ifndef SWITCH_CURTAILS_COMPILATION
744 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
745 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
749 /* Record the mapping from file suffixes for compilation specs. */
753 const char *suffix
; /* Use this compiler for input files
754 whose names end in this suffix. */
756 const char *spec
; /* To use this compiler, run this spec. */
758 const char *cpp_spec
; /* If non-NULL, substitute this spec
759 for `%C', rather than the usual
763 /* Pointer to a vector of `struct compiler' that gives the spec for
764 compiling a file, based on its suffix.
765 A file that does not end in any of these suffixes will be passed
766 unchanged to the loader and nothing else will be done to it.
768 An entry containing two 0s is used to terminate the vector.
770 If multiple entries match a file, the last matching one is used. */
772 static struct compiler
*compilers
;
774 /* Number of entries in `compilers', not counting the null terminator. */
776 static int n_compilers
;
778 /* The default list of file name suffixes and their compilation specs. */
780 static struct compiler default_compilers
[] =
782 /* Add lists of suffixes of known languages here. If those languages
783 were not present when we built the driver, we will hit these copies
784 and be given a more meaningful error than "file not used since
785 linking is not done". */
786 {".m", "#Objective-C", 0}, {".mi", "#Objective-C", 0},
787 {".cc", "#C++", 0}, {".cxx", "#C++", 0}, {".cpp", "#C++", 0},
788 {".cp", "#C++", 0}, {".c++", "#C++", 0}, {".C", "#C++", 0},
790 {".ads", "#Ada", 0}, {".adb", "#Ada", 0},
791 {".f", "#Fortran", 0}, {".for", "#Fortran", 0}, {".fpp", "#Fortran", 0},
792 {".F", "#Fortran", 0}, {".FOR", "#Fortran", 0}, {".FPP", "#Fortran", 0},
793 {".r", "#Ratfor", 0},
794 {".p", "#Pascal", 0}, {".pas", "#Pascal", 0},
795 {".ch", "#Chill", 0}, {".chi", "#Chill", 0},
796 {".java", "#Java", 0}, {".class", "#Java", 0},
797 {".zip", "#Java", 0}, {".jar", "#Java", 0},
798 /* Next come the entries for C. */
801 /* cc1 has an integrated ISO C preprocessor. We should invoke the
802 external preprocessor if -save-temps or -traditional is given. */
803 "%{E|M|MM:%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)}\
805 %{save-temps:%(trad_capable_cpp) -lang-c %{ansi:-std=c89}\
806 %(cpp_options) %b.i \n\
807 cc1 -fpreprocessed %b.i %(cc1_options)}\
809 %{traditional|ftraditional|traditional-cpp:\
810 tradcpp0 -lang-c %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.i} |\n\
811 cc1 -fpreprocessed %{!pipe:%g.i} %(cc1_options)}\
812 %{!traditional:%{!ftraditional:%{!traditional-cpp:\
813 cc1 -lang-c %{ansi:-std=c89} %(cpp_options) %(cc1_options)}}}}\
814 %{!fsyntax-only:%(invoke_as)}}}}", 0},
816 "%{!E:%e-E required when input is from standard input}\
817 %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)", 0},
818 {".h", "@c-header", 0},
820 "%{!E:%eCompilation of header file requested} \
821 %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)", 0},
822 {".i", "@cpp-output", 0},
824 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0},
825 {".s", "@assembler", 0},
827 "%{!M:%{!MM:%{!E:%{!S:as %(asm_options) %i %A }}}}", 0},
828 {".S", "@assembler-with-cpp", 0},
829 {"@assembler-with-cpp",
830 "%(trad_capable_cpp) -lang-asm %(cpp_options)\
831 %{!M:%{!MM:%{!E:%(invoke_as)}}}", 0},
833 /* Mark end of table */
837 /* Number of elements in default_compilers, not counting the terminator. */
839 static int n_default_compilers
840 = (sizeof default_compilers
/ sizeof (struct compiler
)) - 1;
842 /* A vector of options to give to the linker.
843 These options are accumulated by %x,
844 and substituted into the linker command with %X. */
845 static int n_linker_options
;
846 static char **linker_options
;
848 /* A vector of options to give to the assembler.
849 These options are accumulated by -Wa,
850 and substituted into the assembler command with %Y. */
851 static int n_assembler_options
;
852 static char **assembler_options
;
854 /* A vector of options to give to the preprocessor.
855 These options are accumulated by -Wp,
856 and substituted into the preprocessor command with %Z. */
857 static int n_preprocessor_options
;
858 static char **preprocessor_options
;
860 /* Define how to map long options into short ones. */
862 /* This structure describes one mapping. */
865 /* The long option's name. */
866 const char *const name
;
867 /* The equivalent short option. */
868 const char *const equivalent
;
869 /* Argument info. A string of flag chars; NULL equals no options.
870 a => argument required.
871 o => argument optional.
872 j => join argument to equivalent, making one word.
873 * => require other text after NAME as an argument. */
874 const char *const arg_info
;
877 /* This is the table of mappings. Mappings are tried sequentially
878 for each option encountered; the first one that matches, wins. */
880 static const struct option_map option_map
[] =
882 {"--all-warnings", "-Wall", 0},
883 {"--ansi", "-ansi", 0},
884 {"--assemble", "-S", 0},
885 {"--assert", "-A", "a"},
886 {"--classpath", "-fclasspath=", "aj"},
887 {"--CLASSPATH", "-fCLASSPATH=", "aj"},
888 {"--comments", "-C", 0},
889 {"--compile", "-c", 0},
890 {"--debug", "-g", "oj"},
891 {"--define-macro", "-D", "aj"},
892 {"--dependencies", "-M", 0},
893 {"--dump", "-d", "a"},
894 {"--dumpbase", "-dumpbase", "a"},
895 {"--entry", "-e", 0},
896 {"--extra-warnings", "-W", 0},
897 {"--for-assembler", "-Wa", "a"},
898 {"--for-linker", "-Xlinker", "a"},
899 {"--force-link", "-u", "a"},
900 {"--imacros", "-imacros", "a"},
901 {"--include", "-include", "a"},
902 {"--include-barrier", "-I-", 0},
903 {"--include-directory", "-I", "aj"},
904 {"--include-directory-after", "-idirafter", "a"},
905 {"--include-prefix", "-iprefix", "a"},
906 {"--include-with-prefix", "-iwithprefix", "a"},
907 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
908 {"--include-with-prefix-after", "-iwithprefix", "a"},
909 {"--language", "-x", "a"},
910 {"--library-directory", "-L", "a"},
911 {"--machine", "-m", "aj"},
912 {"--machine-", "-m", "*j"},
913 {"--no-line-commands", "-P", 0},
914 {"--no-precompiled-includes", "-noprecomp", 0},
915 {"--no-standard-includes", "-nostdinc", 0},
916 {"--no-standard-libraries", "-nostdlib", 0},
917 {"--no-warnings", "-w", 0},
918 {"--optimize", "-O", "oj"},
919 {"--output", "-o", "a"},
920 {"--output-class-directory", "-foutput-class-dir=", "ja"},
921 {"--param", "--param", "a"},
922 {"--pedantic", "-pedantic", 0},
923 {"--pedantic-errors", "-pedantic-errors", 0},
924 {"--pipe", "-pipe", 0},
925 {"--prefix", "-B", "a"},
926 {"--preprocess", "-E", 0},
927 {"--print-search-dirs", "-print-search-dirs", 0},
928 {"--print-file-name", "-print-file-name=", "aj"},
929 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
930 {"--print-missing-file-dependencies", "-MG", 0},
931 {"--print-multi-lib", "-print-multi-lib", 0},
932 {"--print-multi-directory", "-print-multi-directory", 0},
933 {"--print-prog-name", "-print-prog-name=", "aj"},
934 {"--profile", "-p", 0},
935 {"--profile-blocks", "-a", 0},
936 {"--quiet", "-q", 0},
937 {"--save-temps", "-save-temps", 0},
938 {"--shared", "-shared", 0},
939 {"--silent", "-q", 0},
940 {"--specs", "-specs=", "aj"},
941 {"--static", "-static", 0},
942 {"--std", "-std=", "aj"},
943 {"--symbolic", "-symbolic", 0},
944 {"--target", "-b", "a"},
945 {"--time", "-time", 0},
946 {"--trace-includes", "-H", 0},
947 {"--traditional", "-traditional", 0},
948 {"--traditional-cpp", "-traditional-cpp", 0},
949 {"--trigraphs", "-trigraphs", 0},
950 {"--undefine-macro", "-U", "aj"},
951 {"--use-version", "-V", "a"},
952 {"--user-dependencies", "-MM", 0},
953 {"--verbose", "-v", 0},
954 {"--version", "-dumpversion", 0},
955 {"--warn-", "-W", "*j"},
956 {"--write-dependencies", "-MD", 0},
957 {"--write-user-dependencies", "-MMD", 0},
962 #ifdef TARGET_OPTION_TRANSLATE_TABLE
963 static const struct {
964 const char *const option_found
;
965 const char *const replacements
;
966 } target_option_translations
[] =
968 TARGET_OPTION_TRANSLATE_TABLE
,
973 /* Translate the options described by *ARGCP and *ARGVP.
974 Make a new vector and store it back in *ARGVP,
975 and store its length in *ARGVC. */
978 translate_options (argcp
, argvp
)
980 const char *const **argvp
;
984 const char *const *argv
= *argvp
;
985 int newvsize
= (argc
+ 2) * 2 * sizeof (const char *);
987 (const char **) xmalloc (newvsize
);
991 newv
[newindex
++] = argv
[i
++];
995 #ifdef TARGET_OPTION_TRANSLATE_TABLE
999 target_option_translations
[tott_idx
].option_found
;
1002 if (strcmp (target_option_translations
[tott_idx
].option_found
,
1009 for (sp
= target_option_translations
[tott_idx
].replacements
;
1016 newvsize
+= spaces
* sizeof (const char *);
1017 newv
= (const char **) xrealloc (newv
, newvsize
);
1019 sp
= target_option_translations
[tott_idx
].replacements
;
1028 newv
[newindex
++] = np
;
1029 while (*np
!= ' ' && *np
)
1040 if (target_option_translations
[tott_idx
].option_found
)
1044 /* Translate -- options. */
1045 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
1048 /* Find a mapping that applies to this option. */
1049 for (j
= 0; j
< ARRAY_SIZE (option_map
); j
++)
1051 size_t optlen
= strlen (option_map
[j
].name
);
1052 size_t arglen
= strlen (argv
[i
]);
1053 size_t complen
= arglen
> optlen
? optlen
: arglen
;
1054 const char *arginfo
= option_map
[j
].arg_info
;
1059 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
1061 const char *arg
= 0;
1063 if (arglen
< optlen
)
1066 for (k
= j
+ 1; k
< ARRAY_SIZE (option_map
); k
++)
1067 if (strlen (option_map
[k
].name
) >= arglen
1068 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
1070 error ("Ambiguous abbreviation %s", argv
[i
]);
1074 if (k
!= ARRAY_SIZE (option_map
))
1078 if (arglen
> optlen
)
1080 /* If the option has an argument, accept that. */
1081 if (argv
[i
][optlen
] == '=')
1082 arg
= argv
[i
] + optlen
+ 1;
1084 /* If this mapping requires extra text at end of name,
1085 accept that as "argument". */
1086 else if (strchr (arginfo
, '*') != 0)
1087 arg
= argv
[i
] + optlen
;
1089 /* Otherwise, extra text at end means mismatch.
1090 Try other mappings. */
1095 else if (strchr (arginfo
, '*') != 0)
1097 error ("Incomplete `%s' option", option_map
[j
].name
);
1101 /* Handle arguments. */
1102 if (strchr (arginfo
, 'a') != 0)
1108 error ("Missing argument to `%s' option",
1109 option_map
[j
].name
);
1116 else if (strchr (arginfo
, '*') != 0)
1118 else if (strchr (arginfo
, 'o') == 0)
1121 error ("Extraneous argument to `%s' option",
1122 option_map
[j
].name
);
1126 /* Store the translation as one argv elt or as two. */
1127 if (arg
!= 0 && strchr (arginfo
, 'j') != 0)
1128 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
1132 newv
[newindex
++] = option_map
[j
].equivalent
;
1133 newv
[newindex
++] = arg
;
1136 newv
[newindex
++] = option_map
[j
].equivalent
;
1144 /* Handle old-fashioned options--just copy them through,
1145 with their arguments. */
1146 else if (argv
[i
][0] == '-')
1148 const char *p
= argv
[i
] + 1;
1152 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1153 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1154 else if (WORD_SWITCH_TAKES_ARG (p
))
1155 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
1156 else if ((c
== 'B' || c
== 'b' || c
== 'V' || c
== 'x')
1159 else if (! strcmp (p
, "Xlinker"))
1162 /* Watch out for an option at the end of the command line that
1163 is missing arguments, and avoid skipping past the end of the
1165 if (nskip
+ i
> argc
)
1170 newv
[newindex
++] = argv
[i
++];
1175 /* Ordinary operands, or +e options. */
1176 newv
[newindex
++] = argv
[i
++];
1191 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1192 be considered whitespace. */
1193 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1195 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1209 /* Structures to keep track of prefixes to try when looking for files. */
1213 const char *prefix
; /* String to prepend to the path. */
1214 struct prefix_list
*next
; /* Next in linked list. */
1215 int require_machine_suffix
; /* Don't use without machine_suffix. */
1216 /* 2 means try both machine_suffix and just_machine_suffix. */
1217 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1218 int priority
; /* Sort key - priority within list */
1223 struct prefix_list
*plist
; /* List of prefixes to try */
1224 int max_len
; /* Max length of a prefix in PLIST */
1225 const char *name
; /* Name of this list (used in config stuff) */
1228 /* List of prefixes to try when looking for executables. */
1230 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1232 /* List of prefixes to try when looking for startup (crt0) files. */
1234 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1236 /* List of prefixes to try when looking for include files. */
1238 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1240 /* Suffix to attach to directories searched for commands.
1241 This looks like `MACHINE/VERSION/'. */
1243 static const char *machine_suffix
= 0;
1245 /* Suffix to attach to directories searched for commands.
1246 This is just `MACHINE/'. */
1248 static const char *just_machine_suffix
= 0;
1250 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1252 static const char *gcc_exec_prefix
;
1254 /* Default prefixes to attach to command names. */
1256 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1257 #undef MD_EXEC_PREFIX
1258 #undef MD_STARTFILE_PREFIX
1259 #undef MD_STARTFILE_PREFIX_1
1262 /* If no prefixes defined, use the null string, which will disable them. */
1263 #ifndef MD_EXEC_PREFIX
1264 #define MD_EXEC_PREFIX ""
1266 #ifndef MD_STARTFILE_PREFIX
1267 #define MD_STARTFILE_PREFIX ""
1269 #ifndef MD_STARTFILE_PREFIX_1
1270 #define MD_STARTFILE_PREFIX_1 ""
1273 /* Supply defaults for the standard prefixes. */
1275 #ifndef STANDARD_EXEC_PREFIX
1276 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1278 #ifndef STANDARD_STARTFILE_PREFIX
1279 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1281 #ifndef TOOLDIR_BASE_PREFIX
1282 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1284 #ifndef STANDARD_BINDIR_PREFIX
1285 #define STANDARD_BINDIR_PREFIX "/usr/local/bin"
1288 static const char *const standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1289 static const char *const standard_exec_prefix_1
= "/usr/lib/gcc/";
1290 static const char *md_exec_prefix
= MD_EXEC_PREFIX
;
1292 static const char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1293 static const char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1294 static const char *const standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1295 static const char *const standard_startfile_prefix_1
= "/lib/";
1296 static const char *const standard_startfile_prefix_2
= "/usr/lib/";
1298 static const char *const tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1299 static const char *tooldir_prefix
;
1301 static const char *const standard_bindir_prefix
= STANDARD_BINDIR_PREFIX
;
1303 /* Subdirectory to use for locating libraries. Set by
1304 set_multilib_dir based on the compilation options. */
1306 static const char *multilib_dir
;
1308 /* Structure to keep track of the specs that have been defined so far.
1309 These are accessed using %(specname) or %[specname] in a compiler
1314 /* The following 2 fields must be first */
1315 /* to allow EXTRA_SPECS to be initialized */
1316 const char *name
; /* name of the spec. */
1317 const char *ptr
; /* available ptr if no static pointer */
1319 /* The following fields are not initialized */
1320 /* by EXTRA_SPECS */
1321 const char **ptr_spec
; /* pointer to the spec itself. */
1322 struct spec_list
*next
; /* Next spec in linked list. */
1323 int name_len
; /* length of the name */
1324 int alloc_p
; /* whether string was allocated */
1327 #define INIT_STATIC_SPEC(NAME,PTR) \
1328 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1330 /* List of statically defined specs. */
1331 static struct spec_list static_specs
[] =
1333 INIT_STATIC_SPEC ("asm", &asm_spec
),
1334 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1335 INIT_STATIC_SPEC ("asm_options", &asm_options
),
1336 INIT_STATIC_SPEC ("invoke_as", &invoke_as
),
1337 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1338 INIT_STATIC_SPEC ("cpp_options", &cpp_options
),
1339 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp
),
1340 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1341 INIT_STATIC_SPEC ("cc1_options", &cc1_options
),
1342 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1343 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1344 INIT_STATIC_SPEC ("link", &link_spec
),
1345 INIT_STATIC_SPEC ("lib", &lib_spec
),
1346 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1347 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1348 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces
),
1349 INIT_STATIC_SPEC ("signed_char", &signed_char_spec
),
1350 INIT_STATIC_SPEC ("predefines", &cpp_predefines
),
1351 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1352 INIT_STATIC_SPEC ("version", &compiler_version
),
1353 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1354 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1355 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1356 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1357 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions
),
1358 INIT_STATIC_SPEC ("linker", &linker_name_spec
),
1359 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec
),
1360 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix
),
1361 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix
),
1362 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1
),
1365 #ifdef EXTRA_SPECS /* additional specs needed */
1366 /* Structure to keep track of just the first two args of a spec_list.
1367 That is all that the EXTRA_SPECS macro gives us. */
1370 const char *const name
;
1371 const char *const ptr
;
1374 static const struct spec_list_1 extra_specs_1
[] = { EXTRA_SPECS
};
1375 static struct spec_list
*extra_specs
= (struct spec_list
*) 0;
1378 /* List of dynamically allocates specs that have been defined so far. */
1380 static struct spec_list
*specs
= (struct spec_list
*) 0;
1382 /* Add appropriate libgcc specs to OBSTACK, taking into account
1383 various permutations of -shared-libgcc, -shared, and such. */
1385 #ifdef ENABLE_SHARED_LIBGCC
1387 init_gcc_specs (obstack
, shared_name
, static_name
)
1388 struct obstack
*obstack
;
1389 const char *shared_name
;
1390 const char *static_name
;
1394 /* If we see -shared-libgcc, then use the shared version. */
1395 sprintf (buffer
, "%%{shared-libgcc:%s %s}", shared_name
, static_name
);
1396 obstack_grow (obstack
, buffer
, strlen (buffer
));
1397 /* If we see -static-libgcc, then use the static version. */
1398 sprintf (buffer
, "%%{static-libgcc:%s}", static_name
);
1399 obstack_grow (obstack
, buffer
, strlen (buffer
));
1400 /* Otherwise, if we see -shared, then use the shared version. */
1402 "%%{!shared-libgcc:%%{!static-libgcc:%%{shared:%s %s}}}",
1403 shared_name
, static_name
);
1404 obstack_grow (obstack
, buffer
, strlen (buffer
));
1405 /* Otherwise, use the static version. */
1407 "%%{!shared-libgcc:%%{!static-libgcc:%%{!shared:%s}}}",
1409 obstack_grow (obstack
, buffer
, strlen (buffer
));
1411 #endif /* ENABLE_SHARED_LIBGCC */
1413 /* Initialize the specs lookup routines. */
1418 struct spec_list
*next
= (struct spec_list
*) 0;
1419 struct spec_list
*sl
= (struct spec_list
*) 0;
1423 return; /* Already initialized. */
1426 notice ("Using builtin specs.\n");
1429 extra_specs
= (struct spec_list
*)
1430 xcalloc (sizeof (struct spec_list
), ARRAY_SIZE (extra_specs_1
));
1432 for (i
= ARRAY_SIZE (extra_specs_1
) - 1; i
>= 0; i
--)
1434 sl
= &extra_specs
[i
];
1435 sl
->name
= extra_specs_1
[i
].name
;
1436 sl
->ptr
= extra_specs_1
[i
].ptr
;
1438 sl
->name_len
= strlen (sl
->name
);
1439 sl
->ptr_spec
= &sl
->ptr
;
1444 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1446 sl
= &static_specs
[i
];
1451 #ifdef ENABLE_SHARED_LIBGCC
1452 /* ??? If neither -shared-libgcc nor --static-libgcc was
1453 seen, then we should be making an educated guess. Some proposed
1454 heuristics for ELF include:
1456 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1457 program will be doing dynamic loading, which will likely
1458 need the shared libgcc.
1460 (2) If "-ldl", then it's also a fair bet that we're doing
1463 (3) For each ET_DYN we're linking against (either through -lfoo
1464 or /some/path/foo.so), check to see whether it or one of
1465 its dependencies depends on a shared libgcc.
1469 If the runtime is fixed to look for program headers instead
1470 of calling __register_frame_info at all, for each object,
1471 use the shared libgcc if any EH symbol referenced.
1473 If crtstuff is fixed to not invoke __register_frame_info
1474 automatically, for each object, use the shared libgcc if
1475 any non-empty unwind section found.
1477 Doing any of this probably requires invoking an external program to
1478 do the actual object file scanning. */
1480 const char *p
= libgcc_spec
;
1483 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1484 when given the proper command line arguments. */
1487 if (in_sep
&& *p
== '-' && strncmp (p
, "-lgcc", 5) == 0)
1489 init_gcc_specs (&obstack
,
1490 #ifdef NO_SHARED_LIBGCC_MULTILIB
1500 else if (in_sep
&& *p
== 'l' && strncmp (p
, "libgcc.a%s", 10) == 0)
1502 /* Ug. We don't know shared library extensions. Hope that
1503 systems that use this form don't do shared libraries. */
1504 init_gcc_specs (&obstack
,
1505 #ifdef NO_SHARED_LIBGCC_MULTILIB
1517 obstack_1grow (&obstack
, *p
);
1518 in_sep
= (*p
== ' ');
1523 obstack_1grow (&obstack
, '\0');
1524 libgcc_spec
= obstack_finish (&obstack
);
1527 #ifdef USE_AS_TRADITIONAL_FORMAT
1528 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1530 static const char tf
[] = "--traditional-format ";
1531 obstack_grow (&obstack
, tf
, sizeof(tf
) - 1);
1532 obstack_grow0 (&obstack
, asm_spec
, strlen (asm_spec
));
1533 asm_spec
= obstack_finish (&obstack
);
1540 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1541 removed; If the spec starts with a + then SPEC is added to the end of the
1545 set_spec (name
, spec
)
1549 struct spec_list
*sl
;
1550 const char *old_spec
;
1551 int name_len
= strlen (name
);
1554 /* If this is the first call, initialize the statically allocated specs. */
1557 struct spec_list
*next
= (struct spec_list
*) 0;
1558 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1560 sl
= &static_specs
[i
];
1567 /* See if the spec already exists. */
1568 for (sl
= specs
; sl
; sl
= sl
->next
)
1569 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1574 /* Not found - make it. */
1575 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1576 sl
->name
= xstrdup (name
);
1577 sl
->name_len
= name_len
;
1578 sl
->ptr_spec
= &sl
->ptr
;
1580 *(sl
->ptr_spec
) = "";
1585 old_spec
= *(sl
->ptr_spec
);
1586 *(sl
->ptr_spec
) = ((spec
[0] == '+' && ISSPACE ((unsigned char)spec
[1]))
1587 ? concat (old_spec
, spec
+ 1, NULL
)
1592 notice ("Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1595 /* Free the old spec. */
1596 if (old_spec
&& sl
->alloc_p
)
1597 free ((PTR
) old_spec
);
1602 /* Accumulate a command (program name and args), and run it. */
1604 /* Vector of pointers to arguments in the current line of specifications. */
1606 static const char **argbuf
;
1608 /* Number of elements allocated in argbuf. */
1610 static int argbuf_length
;
1612 /* Number of elements in argbuf currently in use (containing args). */
1614 static int argbuf_index
;
1616 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1617 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1620 static struct temp_name
{
1621 const char *suffix
; /* suffix associated with the code. */
1622 int length
; /* strlen (suffix). */
1623 int unique
; /* Indicates whether %g or %u/%U was used. */
1624 const char *filename
; /* associated filename. */
1625 int filename_length
; /* strlen (filename). */
1626 struct temp_name
*next
;
1629 /* Number of commands executed so far. */
1631 static int execution_count
;
1633 /* Number of commands that exited with a signal. */
1635 static int signal_count
;
1637 /* Name with which this program was invoked. */
1639 static const char *programname
;
1641 /* Clear out the vector of arguments (after a command is executed). */
1649 /* Add one argument to the vector at the end.
1650 This is done when a space is seen or at the end of the line.
1651 If DELETE_ALWAYS is nonzero, the arg is a filename
1652 and the file should be deleted eventually.
1653 If DELETE_FAILURE is nonzero, the arg is a filename
1654 and the file should be deleted if this compilation fails. */
1657 store_arg (arg
, delete_always
, delete_failure
)
1659 int delete_always
, delete_failure
;
1661 if (argbuf_index
+ 1 == argbuf_length
)
1663 = (const char **) xrealloc (argbuf
,
1664 (argbuf_length
*= 2) * sizeof (const char *));
1666 argbuf
[argbuf_index
++] = arg
;
1667 argbuf
[argbuf_index
] = 0;
1669 if (delete_always
|| delete_failure
)
1670 record_temp_file (arg
, delete_always
, delete_failure
);
1673 /* Load specs from a file name named FILENAME, replacing occurrences of
1674 various different types of line-endings, \r\n, \n\r and just \r, with
1678 load_specs (filename
)
1679 const char *filename
;
1683 struct stat statbuf
;
1690 notice ("Reading specs from %s\n", filename
);
1692 /* Open and stat the file. */
1693 desc
= open (filename
, O_RDONLY
, 0);
1695 pfatal_with_name (filename
);
1696 if (stat (filename
, &statbuf
) < 0)
1697 pfatal_with_name (filename
);
1699 /* Read contents of file into BUFFER. */
1700 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1701 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1703 pfatal_with_name (filename
);
1704 buffer
[readlen
] = 0;
1707 specs
= xmalloc (readlen
+ 1);
1709 for (buffer_p
= buffer
; buffer_p
&& *buffer_p
; buffer_p
++)
1715 if (buffer_p
> buffer
&& *(buffer_p
- 1) == '\n') /* \n\r */
1717 else if (*(buffer_p
+ 1) == '\n') /* \r\n */
1731 /* Read compilation specs from a file named FILENAME,
1732 replacing the default ones.
1734 A suffix which starts with `*' is a definition for
1735 one of the machine-specific sub-specs. The "suffix" should be
1736 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
1737 The corresponding spec is stored in asm_spec, etc.,
1738 rather than in the `compilers' vector.
1740 Anything invalid in the file is a fatal error. */
1743 read_specs (filename
, main_p
)
1744 const char *filename
;
1750 buffer
= load_specs (filename
);
1752 /* Scan BUFFER for specs, putting them in the vector. */
1758 char *in
, *out
, *p1
, *p2
, *p3
;
1760 /* Advance P in BUFFER to the next nonblank nocomment line. */
1761 p
= skip_whitespace (p
);
1765 /* Is this a special command that starts with '%'? */
1766 /* Don't allow this for the main specs file, since it would
1767 encourage people to overwrite it. */
1768 if (*p
== '%' && !main_p
)
1771 while (*p
&& *p
!= '\n')
1777 if (!strncmp (p1
, "%include", sizeof ("%include") - 1)
1778 && (p1
[sizeof "%include" - 1] == ' '
1779 || p1
[sizeof "%include" - 1] == '\t'))
1783 p1
+= sizeof ("%include");
1784 while (*p1
== ' ' || *p1
== '\t')
1787 if (*p1
++ != '<' || p
[-2] != '>')
1788 fatal ("specs %%include syntax malformed after %ld characters",
1789 (long) (p1
- buffer
+ 1));
1792 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1793 read_specs (new_filename
? new_filename
: p1
, FALSE
);
1796 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
1797 && (p1
[sizeof "%include_noerr" - 1] == ' '
1798 || p1
[sizeof "%include_noerr" - 1] == '\t'))
1802 p1
+= sizeof "%include_noerr";
1803 while (*p1
== ' ' || *p1
== '\t')
1806 if (*p1
++ != '<' || p
[-2] != '>')
1807 fatal ("specs %%include syntax malformed after %ld characters",
1808 (long) (p1
- buffer
+ 1));
1811 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1813 read_specs (new_filename
, FALSE
);
1814 else if (verbose_flag
)
1815 notice ("Could not find specs file %s\n", p1
);
1818 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
1819 && (p1
[sizeof "%rename" - 1] == ' '
1820 || p1
[sizeof "%rename" - 1] == '\t'))
1823 struct spec_list
*sl
;
1825 /* Get original name */
1826 p1
+= sizeof "%rename";
1827 while (*p1
== ' ' || *p1
== '\t')
1830 if (! ISALPHA ((unsigned char) *p1
))
1831 fatal ("specs %%rename syntax malformed after %ld characters",
1832 (long) (p1
- buffer
));
1835 while (*p2
&& !ISSPACE ((unsigned char) *p2
))
1838 if (*p2
!= ' ' && *p2
!= '\t')
1839 fatal ("specs %%rename syntax malformed after %ld characters",
1840 (long) (p2
- buffer
));
1844 while (*p2
== ' ' || *p2
== '\t')
1847 if (! ISALPHA ((unsigned char) *p2
))
1848 fatal ("specs %%rename syntax malformed after %ld characters",
1849 (long) (p2
- buffer
));
1851 /* Get new spec name. */
1853 while (*p3
&& !ISSPACE ((unsigned char) *p3
))
1857 fatal ("specs %%rename syntax malformed after %ld characters",
1858 (long) (p3
- buffer
));
1861 for (sl
= specs
; sl
; sl
= sl
->next
)
1862 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
1866 fatal ("specs %s spec was not found to be renamed", p1
);
1868 if (strcmp (p1
, p2
) == 0)
1873 notice ("rename spec %s to %s\n", p1
, p2
);
1875 notice ("spec is '%s'\n\n", *(sl
->ptr_spec
));
1879 set_spec (p2
, *(sl
->ptr_spec
));
1881 free ((PTR
) *(sl
->ptr_spec
));
1883 *(sl
->ptr_spec
) = "";
1888 fatal ("specs unknown %% command after %ld characters",
1889 (long) (p1
- buffer
));
1892 /* Find the colon that should end the suffix. */
1894 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
1897 /* The colon shouldn't be missing. */
1899 fatal ("specs file malformed after %ld characters",
1900 (long) (p1
- buffer
));
1902 /* Skip back over trailing whitespace. */
1904 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
1907 /* Copy the suffix to a string. */
1908 suffix
= save_string (p
, p2
- p
);
1909 /* Find the next line. */
1910 p
= skip_whitespace (p1
+ 1);
1912 fatal ("specs file malformed after %ld characters",
1913 (long) (p
- buffer
));
1916 /* Find next blank line or end of string. */
1917 while (*p1
&& !(*p1
== '\n' && (p1
[1] == '\n' || p1
[1] == '\0')))
1920 /* Specs end at the blank line and do not include the newline. */
1921 spec
= save_string (p
, p1
- p
);
1924 /* Delete backslash-newline sequences from the spec. */
1929 if (in
[0] == '\\' && in
[1] == '\n')
1931 else if (in
[0] == '#')
1932 while (*in
&& *in
!= '\n')
1940 if (suffix
[0] == '*')
1942 if (! strcmp (suffix
, "*link_command"))
1943 link_command_spec
= spec
;
1945 set_spec (suffix
+ 1, spec
);
1949 /* Add this pair to the vector. */
1951 = ((struct compiler
*)
1952 xrealloc (compilers
,
1953 (n_compilers
+ 2) * sizeof (struct compiler
)));
1955 compilers
[n_compilers
].suffix
= suffix
;
1956 compilers
[n_compilers
].spec
= spec
;
1958 memset (&compilers
[n_compilers
], 0, sizeof compilers
[n_compilers
]);
1962 link_command_spec
= spec
;
1965 if (link_command_spec
== 0)
1966 fatal ("spec file has no spec for linking");
1969 /* Record the names of temporary files we tell compilers to write,
1970 and delete them at the end of the run. */
1972 /* This is the common prefix we use to make temp file names.
1973 It is chosen once for each run of this program.
1974 It is substituted into a spec by %g or %j.
1975 Thus, all temp file names contain this prefix.
1976 In practice, all temp file names start with this prefix.
1978 This prefix comes from the envvar TMPDIR if it is defined;
1979 otherwise, from the P_tmpdir macro if that is defined;
1980 otherwise, in /usr/tmp or /tmp;
1981 or finally the current directory if all else fails. */
1983 static const char *temp_filename
;
1985 /* Length of the prefix. */
1987 static int temp_filename_length
;
1989 /* Define the list of temporary files to delete. */
1994 struct temp_file
*next
;
1997 /* Queue of files to delete on success or failure of compilation. */
1998 static struct temp_file
*always_delete_queue
;
1999 /* Queue of files to delete on failure of compilation. */
2000 static struct temp_file
*failure_delete_queue
;
2002 /* Record FILENAME as a file to be deleted automatically.
2003 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2004 otherwise delete it in any case.
2005 FAIL_DELETE nonzero means delete it if a compilation step fails;
2006 otherwise delete it in any case. */
2009 record_temp_file (filename
, always_delete
, fail_delete
)
2010 const char *filename
;
2014 char *const name
= xstrdup (filename
);
2018 struct temp_file
*temp
;
2019 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2020 if (! strcmp (name
, temp
->name
))
2023 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
2024 temp
->next
= always_delete_queue
;
2026 always_delete_queue
= temp
;
2033 struct temp_file
*temp
;
2034 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2035 if (! strcmp (name
, temp
->name
))
2038 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
2039 temp
->next
= failure_delete_queue
;
2041 failure_delete_queue
= temp
;
2047 /* Delete all the temporary files whose names we previously recorded. */
2050 delete_if_ordinary (name
)
2057 printf ("Delete %s? (y or n) ", name
);
2061 while ((c
= getchar ()) != '\n' && c
!= EOF
)
2064 if (i
== 'y' || i
== 'Y')
2066 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
2067 if (unlink (name
) < 0)
2069 perror_with_name (name
);
2073 delete_temp_files ()
2075 struct temp_file
*temp
;
2077 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2078 delete_if_ordinary (temp
->name
);
2079 always_delete_queue
= 0;
2082 /* Delete all the files to be deleted on error. */
2085 delete_failure_queue ()
2087 struct temp_file
*temp
;
2089 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2090 delete_if_ordinary (temp
->name
);
2094 clear_failure_queue ()
2096 failure_delete_queue
= 0;
2099 /* Build a list of search directories from PATHS.
2100 PREFIX is a string to prepend to the list.
2101 If CHECK_DIR_P is non-zero we ensure the directory exists.
2102 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2103 It is also used by the --print-search-dirs flag. */
2106 build_search_list (paths
, prefix
, check_dir_p
)
2107 struct path_prefix
*paths
;
2111 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
2113 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
2114 int first_time
= TRUE
;
2115 struct prefix_list
*pprefix
;
2117 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
2118 obstack_1grow (&collect_obstack
, '=');
2120 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
2122 int len
= strlen (pprefix
->prefix
);
2126 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
2129 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2132 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2133 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
2136 if (just_machine_suffix
2137 && pprefix
->require_machine_suffix
== 2
2139 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
2142 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2145 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2146 obstack_grow (&collect_obstack
, just_machine_suffix
,
2150 if (! pprefix
->require_machine_suffix
)
2153 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2156 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2160 obstack_1grow (&collect_obstack
, '\0');
2161 return obstack_finish (&collect_obstack
);
2164 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2168 putenv_from_prefixes (paths
, env_var
)
2169 struct path_prefix
*paths
;
2170 const char *env_var
;
2172 putenv (build_search_list (paths
, env_var
, 1));
2177 /* FIXME: the location independence code for VMS is hairier than this,
2178 and hasn't been written. */
2180 /* Split a filename into component directories. */
2183 split_directories (name
, ptr_num_dirs
)
2192 /* Count the number of directories. Special case MSDOS disk names as part
2193 of the initial directory. */
2195 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2196 if (name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2201 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2203 while ((ch
= *p
++) != '\0')
2205 if (IS_DIR_SEPARATOR (ch
))
2208 while (IS_DIR_SEPARATOR (*p
))
2213 dirs
= (char **) xmalloc (sizeof (char *) * (num_dirs
+ 2));
2215 /* Now copy the directory parts. */
2218 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2219 if (name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2221 dirs
[num_dirs
++] = save_string (p
, 3);
2224 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2227 while ((ch
= *p
++) != '\0')
2229 if (IS_DIR_SEPARATOR (ch
))
2231 while (IS_DIR_SEPARATOR (*p
))
2234 dirs
[num_dirs
++] = save_string (q
, p
- q
);
2240 dirs
[num_dirs
++] = save_string (q
, p
- 1 - q
);
2242 dirs
[num_dirs
] = NULL
;
2244 *ptr_num_dirs
= num_dirs
;
2249 /* Release storage held by split directories. */
2252 free_split_directories (dirs
)
2257 while (dirs
[i
] != NULL
)
2260 free ((char *) dirs
);
2263 /* Given three strings PROGNAME, BIN_PREFIX, PREFIX, return a string that gets
2264 to PREFIX starting with the directory portion of PROGNAME and a relative
2265 pathname of the difference between BIN_PREFIX and PREFIX.
2267 For example, if BIN_PREFIX is /alpha/beta/gamma/gcc/delta, PREFIX is
2268 /alpha/beta/gamma/omega/, and PROGNAME is /red/green/blue/gcc, then this
2269 function will return /red/green/blue/../omega.
2271 If no relative prefix can be found, return NULL. */
2274 make_relative_prefix (progname
, bin_prefix
, prefix
)
2275 const char *progname
;
2276 const char *bin_prefix
;
2279 char **prog_dirs
, **bin_dirs
, **prefix_dirs
;
2280 int prog_num
, bin_num
, prefix_num
, std_loc_p
;
2283 prog_dirs
= split_directories (progname
, &prog_num
);
2284 bin_dirs
= split_directories (bin_prefix
, &bin_num
);
2286 /* If there is no full pathname, try to find the program by checking in each
2287 of the directories specified in the PATH environment variable. */
2292 GET_ENV_PATH_LIST (temp
, "PATH");
2295 char *startp
, *endp
, *nstore
;
2296 size_t prefixlen
= strlen (temp
) + 1;
2300 nstore
= (char *) alloca (prefixlen
+ strlen (progname
) + 1);
2302 startp
= endp
= temp
;
2305 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2310 nstore
[1] = DIR_SEPARATOR
;
2315 strncpy (nstore
, startp
, endp
- startp
);
2316 if (! IS_DIR_SEPARATOR (endp
[-1]))
2318 nstore
[endp
- startp
] = DIR_SEPARATOR
;
2319 nstore
[endp
- startp
+ 1] = 0;
2322 nstore
[endp
- startp
] = 0;
2324 strcat (nstore
, progname
);
2325 if (! access (nstore
, X_OK
)
2326 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
2327 || ! access (strcat (nstore
, HOST_EXECUTABLE_SUFFIX
), X_OK
)
2331 free_split_directories (prog_dirs
);
2333 prog_dirs
= split_directories (progname
, &prog_num
);
2339 endp
= startp
= endp
+ 1;
2347 /* Remove the program name from comparison of directory names. */
2350 /* Determine if the compiler is installed in the standard location, and if
2351 so, we don't need to specify relative directories. Also, if argv[0]
2352 doesn't contain any directory specifiers, there is not much we can do. */
2354 if (prog_num
== bin_num
)
2356 for (i
= 0; i
< bin_num
; i
++)
2358 if (strcmp (prog_dirs
[i
], bin_dirs
[i
]) != 0)
2362 if (prog_num
<= 0 || i
== bin_num
)
2365 free_split_directories (prog_dirs
);
2366 free_split_directories (bin_dirs
);
2367 prog_dirs
= bin_dirs
= (char **) 0;
2372 prefix_dirs
= split_directories (prefix
, &prefix_num
);
2374 /* Find how many directories are in common between bin_prefix & prefix. */
2375 n
= (prefix_num
< bin_num
) ? prefix_num
: bin_num
;
2376 for (common
= 0; common
< n
; common
++)
2378 if (strcmp (bin_dirs
[common
], prefix_dirs
[common
]) != 0)
2382 /* If there are no common directories, there can be no relative prefix. */
2385 free_split_directories (prog_dirs
);
2386 free_split_directories (bin_dirs
);
2387 free_split_directories (prefix_dirs
);
2391 /* Build up the pathnames in argv[0]. */
2392 for (i
= 0; i
< prog_num
; i
++)
2393 obstack_grow (&obstack
, prog_dirs
[i
], strlen (prog_dirs
[i
]));
2395 /* Now build up the ..'s. */
2396 for (i
= common
; i
< n
; i
++)
2398 obstack_grow (&obstack
, DIR_UP
, sizeof (DIR_UP
) - 1);
2399 obstack_1grow (&obstack
, DIR_SEPARATOR
);
2402 /* Put in directories to move over to prefix. */
2403 for (i
= common
; i
< prefix_num
; i
++)
2404 obstack_grow (&obstack
, prefix_dirs
[i
], strlen (prefix_dirs
[i
]));
2406 free_split_directories (prog_dirs
);
2407 free_split_directories (bin_dirs
);
2408 free_split_directories (prefix_dirs
);
2410 obstack_1grow (&obstack
, '\0');
2411 return obstack_finish (&obstack
);
2415 /* Check whether NAME can be accessed in MODE. This is like access,
2416 except that it never considers directories to be executable. */
2419 access_check (name
, mode
)
2427 if (stat (name
, &st
) < 0
2428 || S_ISDIR (st
.st_mode
))
2432 return access (name
, mode
);
2435 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2436 access to check permissions.
2437 Return 0 if not found, otherwise return its name, allocated with malloc. */
2440 find_a_file (pprefix
, name
, mode
)
2441 struct path_prefix
*pprefix
;
2446 const char *const file_suffix
=
2447 ((mode
& X_OK
) != 0 ? HOST_EXECUTABLE_SUFFIX
: "");
2448 struct prefix_list
*pl
;
2449 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
2451 #ifdef DEFAULT_ASSEMBLER
2452 if (! strcmp (name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0)
2453 return xstrdup (DEFAULT_ASSEMBLER
);
2456 #ifdef DEFAULT_LINKER
2457 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0)
2458 return xstrdup (DEFAULT_LINKER
);
2462 len
+= strlen (machine_suffix
);
2464 temp
= xmalloc (len
);
2466 /* Determine the filename to execute (special case for absolute paths). */
2468 if (IS_ABSOLUTE_PATHNAME (name
))
2470 if (access (name
, mode
) == 0)
2472 strcpy (temp
, name
);
2477 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
2481 /* Some systems have a suffix for executable files.
2482 So try appending that first. */
2483 if (file_suffix
[0] != 0)
2485 strcpy (temp
, pl
->prefix
);
2486 strcat (temp
, machine_suffix
);
2487 strcat (temp
, name
);
2488 strcat (temp
, file_suffix
);
2489 if (access_check (temp
, mode
) == 0)
2491 if (pl
->used_flag_ptr
!= 0)
2492 *pl
->used_flag_ptr
= 1;
2497 /* Now try just the name. */
2498 strcpy (temp
, pl
->prefix
);
2499 strcat (temp
, machine_suffix
);
2500 strcat (temp
, name
);
2501 if (access_check (temp
, mode
) == 0)
2503 if (pl
->used_flag_ptr
!= 0)
2504 *pl
->used_flag_ptr
= 1;
2509 /* Certain prefixes are tried with just the machine type,
2510 not the version. This is used for finding as, ld, etc. */
2511 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
2513 /* Some systems have a suffix for executable files.
2514 So try appending that first. */
2515 if (file_suffix
[0] != 0)
2517 strcpy (temp
, pl
->prefix
);
2518 strcat (temp
, just_machine_suffix
);
2519 strcat (temp
, name
);
2520 strcat (temp
, file_suffix
);
2521 if (access_check (temp
, mode
) == 0)
2523 if (pl
->used_flag_ptr
!= 0)
2524 *pl
->used_flag_ptr
= 1;
2529 strcpy (temp
, pl
->prefix
);
2530 strcat (temp
, just_machine_suffix
);
2531 strcat (temp
, name
);
2532 if (access_check (temp
, mode
) == 0)
2534 if (pl
->used_flag_ptr
!= 0)
2535 *pl
->used_flag_ptr
= 1;
2540 /* Certain prefixes can't be used without the machine suffix
2541 when the machine or version is explicitly specified. */
2542 if (! pl
->require_machine_suffix
)
2544 /* Some systems have a suffix for executable files.
2545 So try appending that first. */
2546 if (file_suffix
[0] != 0)
2548 strcpy (temp
, pl
->prefix
);
2549 strcat (temp
, name
);
2550 strcat (temp
, file_suffix
);
2551 if (access_check (temp
, mode
) == 0)
2553 if (pl
->used_flag_ptr
!= 0)
2554 *pl
->used_flag_ptr
= 1;
2559 strcpy (temp
, pl
->prefix
);
2560 strcat (temp
, name
);
2561 if (access_check (temp
, mode
) == 0)
2563 if (pl
->used_flag_ptr
!= 0)
2564 *pl
->used_flag_ptr
= 1;
2574 /* Ranking of prefixes in the sort list. -B prefixes are put before
2577 enum path_prefix_priority
2579 PREFIX_PRIORITY_B_OPT
,
2580 PREFIX_PRIORITY_LAST
2583 /* Add an entry for PREFIX in PLIST. The PLIST is kept in assending
2584 order according to PRIORITY. Within each PRIORITY, new entries are
2587 If WARN is nonzero, we will warn if no file is found
2588 through this prefix. WARN should point to an int
2589 which will be set to 1 if this entry is used.
2591 COMPONENT is the value to be passed to update_path.
2593 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2594 the complete value of machine_suffix.
2595 2 means try both machine_suffix and just_machine_suffix. */
2598 add_prefix (pprefix
, prefix
, component
, priority
, require_machine_suffix
, warn
)
2599 struct path_prefix
*pprefix
;
2601 const char *component
;
2602 /* enum prefix_priority */ int priority
;
2603 int require_machine_suffix
;
2606 struct prefix_list
*pl
, **prev
;
2609 for (prev
= &pprefix
->plist
;
2610 (*prev
) != NULL
&& (*prev
)->priority
<= priority
;
2611 prev
= &(*prev
)->next
)
2614 /* Keep track of the longest prefix */
2616 prefix
= update_path (prefix
, component
);
2617 len
= strlen (prefix
);
2618 if (len
> pprefix
->max_len
)
2619 pprefix
->max_len
= len
;
2621 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2622 pl
->prefix
= prefix
;
2623 pl
->require_machine_suffix
= require_machine_suffix
;
2624 pl
->used_flag_ptr
= warn
;
2625 pl
->priority
= priority
;
2629 /* Insert after PREV */
2634 /* Execute the command specified by the arguments on the current line of spec.
2635 When using pipes, this includes several piped-together commands
2636 with `|' between them.
2638 Return 0 if successful, -1 if failed. */
2644 int n_commands
; /* # of command. */
2648 const char *prog
; /* program name. */
2649 const char **argv
; /* vector of args. */
2650 int pid
; /* pid of process for this command. */
2653 struct command
*commands
; /* each command buffer with above info. */
2655 /* Count # of piped commands. */
2656 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2657 if (strcmp (argbuf
[i
], "|") == 0)
2660 /* Get storage for each command. */
2661 commands
= (struct command
*) alloca (n_commands
* sizeof (struct command
));
2663 /* Split argbuf into its separate piped processes,
2664 and record info about each one.
2665 Also search for the programs that are to be run. */
2667 commands
[0].prog
= argbuf
[0]; /* first command. */
2668 commands
[0].argv
= &argbuf
[0];
2669 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2672 commands
[0].argv
[0] = string
;
2674 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2675 if (strcmp (argbuf
[i
], "|") == 0)
2676 { /* each command. */
2677 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2678 fatal ("-pipe not supported");
2680 argbuf
[i
] = 0; /* termination of command args. */
2681 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2682 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2683 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2685 commands
[n_commands
].argv
[0] = string
;
2689 argbuf
[argbuf_index
] = 0;
2691 /* If -v, print what we are about to do, and maybe query. */
2695 /* For help listings, put a blank line between sub-processes. */
2696 if (print_help_list
)
2697 fputc ('\n', stderr
);
2699 /* Print each piped command as a separate line. */
2700 for (i
= 0; i
< n_commands
; i
++)
2702 const char *const *j
;
2704 for (j
= commands
[i
].argv
; *j
; j
++)
2705 fprintf (stderr
, " %s", *j
);
2707 /* Print a pipe symbol after all but the last command. */
2708 if (i
+ 1 != n_commands
)
2709 fprintf (stderr
, " |");
2710 fprintf (stderr
, "\n");
2714 notice ("\nGo ahead? (y or n) ");
2718 while (getchar () != '\n')
2721 if (i
!= 'y' && i
!= 'Y')
2726 /* Run each piped subprocess. */
2728 for (i
= 0; i
< n_commands
; i
++)
2730 char *errmsg_fmt
, *errmsg_arg
;
2731 const char *string
= commands
[i
].argv
[0];
2733 /* For some bizarre reason, the second argument of execvp() is
2734 char *const *, not const char *const *. */
2735 commands
[i
].pid
= pexecute (string
, (char *const *) commands
[i
].argv
,
2736 programname
, temp_filename
,
2737 &errmsg_fmt
, &errmsg_arg
,
2738 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2739 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2740 | (string
== commands
[i
].prog
2741 ? PEXECUTE_SEARCH
: 0)
2742 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2744 if (commands
[i
].pid
== -1)
2745 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2747 if (string
!= commands
[i
].prog
)
2748 free ((PTR
) string
);
2753 /* Wait for all the subprocesses to finish.
2754 We don't care what order they finish in;
2755 we know that N_COMMANDS waits will get them all.
2756 Ignore subprocesses that we don't know about,
2757 since they can be spawned by the process that exec'ed us. */
2761 #ifdef HAVE_GETRUSAGE
2763 double ut
= 0.0, st
= 0.0;
2766 for (i
= 0; i
< n_commands
;)
2772 pid
= pwait (commands
[i
].pid
, &status
, 0);
2776 #ifdef HAVE_GETRUSAGE
2779 /* getrusage returns the total resource usage of all children
2780 up to now. Copy the previous values into prus, get the
2781 current statistics, then take the difference. */
2784 getrusage (RUSAGE_CHILDREN
, &rus
);
2785 d
.tv_sec
= rus
.ru_utime
.tv_sec
- prus
.ru_utime
.tv_sec
;
2786 d
.tv_usec
= rus
.ru_utime
.tv_usec
- prus
.ru_utime
.tv_usec
;
2787 ut
= (double) d
.tv_sec
+ (double) d
.tv_usec
/ 1.0e6
;
2789 d
.tv_sec
= rus
.ru_stime
.tv_sec
- prus
.ru_stime
.tv_sec
;
2790 d
.tv_usec
= rus
.ru_stime
.tv_usec
- prus
.ru_stime
.tv_usec
;
2791 st
= (double) d
.tv_sec
+ (double) d
.tv_usec
/ 1.0e6
;
2795 for (j
= 0; j
< n_commands
; j
++)
2796 if (commands
[j
].pid
== pid
)
2799 if (WIFSIGNALED (status
))
2802 /* SIGPIPE is a special case. It happens in -pipe mode
2803 when the compiler dies before the preprocessor is
2804 done, or the assembler dies before the compiler is
2805 done. There's generally been an error already, and
2806 this is just fallout. So don't generate another error
2807 unless we would otherwise have succeeded. */
2808 if (WTERMSIG (status
) == SIGPIPE
2809 && (signal_count
|| greatest_status
>= MIN_FATAL_STATUS
))
2814 Internal error: %s (program %s)\n\
2815 Please submit a full bug report.\n\
2816 See %s for instructions.",
2817 strsignal (WTERMSIG (status
)), commands
[j
].prog
,
2822 else if (WIFEXITED (status
)
2823 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2825 if (WEXITSTATUS (status
) > greatest_status
)
2826 greatest_status
= WEXITSTATUS (status
);
2829 #ifdef HAVE_GETRUSAGE
2830 if (report_times
&& ut
+ st
!= 0)
2831 notice ("# %s %.2f %.2f\n", commands
[j
].prog
, ut
, st
);
2840 /* Find all the switches given to us
2841 and make a vector describing them.
2842 The elements of the vector are strings, one per switch given.
2843 If a switch uses following arguments, then the `part1' field
2844 is the switch itself and the `args' field
2845 is a null-terminated vector containing the following arguments.
2846 The `live_cond' field is:
2848 1 if the switch is true in a conditional spec,
2849 -1 if false (overridden by a later switch)
2850 -2 if this switch should be ignored (used in %{<S})
2851 The `validated' field is nonzero if any spec has looked at this switch;
2852 if it remains zero at the end of the run, it must be meaningless. */
2855 #define SWITCH_FALSE -1
2856 #define SWITCH_IGNORE -2
2857 #define SWITCH_LIVE 1
2864 unsigned char validated
;
2865 unsigned char ordering
;
2868 static struct switchstr
*switches
;
2870 static int n_switches
;
2875 const char *language
;
2878 /* Also a vector of input files specified. */
2880 static struct infile
*infiles
;
2884 /* This counts the number of libraries added by lang_specific_driver, so that
2885 we can tell if there were any user supplied any files or libraries. */
2887 static int added_libraries
;
2889 /* And a vector of corresponding output files is made up later. */
2891 const char **outfiles
;
2893 /* Used to track if none of the -B paths are used. */
2896 /* Used to track if standard path isn't used and -b or -V is specified. */
2897 static int warn_std
;
2899 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2900 static int *warn_std_ptr
= 0;
2902 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2904 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2905 is true if we should look for an executable suffix as well. */
2908 convert_filename (name
, do_exe
)
2910 int do_exe ATTRIBUTE_UNUSED
;
2912 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2920 len
= strlen (name
);
2922 #ifdef HAVE_TARGET_OBJECT_SUFFIX
2923 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
2925 && name
[len
- 2] == '.'
2926 && name
[len
- 1] == 'o')
2928 obstack_grow (&obstack
, name
, len
- 2);
2929 obstack_grow0 (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
2930 name
= obstack_finish (&obstack
);
2934 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2935 /* If there is no filetype, make it the executable suffix (which includes
2936 the "."). But don't get confused if we have just "-o". */
2937 if (! do_exe
|| TARGET_EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
2940 for (i
= len
- 1; i
>= 0; i
--)
2941 if (IS_DIR_SEPARATOR (name
[i
]))
2944 for (i
++; i
< len
; i
++)
2948 obstack_grow (&obstack
, name
, len
);
2949 obstack_grow0 (&obstack
, TARGET_EXECUTABLE_SUFFIX
,
2950 strlen (TARGET_EXECUTABLE_SUFFIX
));
2951 name
= obstack_finish (&obstack
);
2958 /* Display the command line switches accepted by gcc. */
2962 printf (_("Usage: %s [options] file...\n"), programname
);
2963 fputs (_("Options:\n"), stdout
);
2965 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout
);
2966 fputs (_(" --help Display this information\n"), stdout
);
2967 fputs (_(" --target-help Display target specific command line options\n"), stdout
);
2969 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout
);
2970 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout
);
2971 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout
);
2972 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout
);
2973 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout
);
2974 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout
);
2975 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout
);
2976 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout
);
2977 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout
);
2979 -print-multi-lib Display the mapping between command line options and\n\
2980 multiple library search directories\n"), stdout
);
2981 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout
);
2982 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout
);
2983 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout
);
2984 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout
);
2985 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout
);
2986 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout
);
2987 fputs (_(" -time Time the execution of each subprocess\n"), stdout
);
2988 fputs (_(" -specs=<file> Override builtin specs with the contents of <file>\n"), stdout
);
2989 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout
);
2990 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout
);
2991 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout
);
2992 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout
);
2993 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout
);
2994 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout
);
2995 fputs (_(" -S Compile only; do not assemble or link\n"), stdout
);
2996 fputs (_(" -c Compile and assemble, but do not link\n"), stdout
);
2997 fputs (_(" -o <file> Place the output into <file>\n"), stdout
);
2999 -x <language> Specify the language of the following input files\n\
3000 Permissable languages include: c c++ assembler none\n\
3001 'none' means revert to the default behaviour of\n\
3002 guessing the language based on the file's extension\n\
3006 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3007 passed on to the various sub-processes invoked by %s. In order to pass\n\
3008 other options on to these processes the -W<letter> options must be used.\n\
3011 /* The rest of the options are displayed by invocations of the various
3016 add_preprocessor_option (option
, len
)
3020 n_preprocessor_options
++;
3022 if (! preprocessor_options
)
3023 preprocessor_options
3024 = (char **) xmalloc (n_preprocessor_options
* sizeof (char *));
3026 preprocessor_options
3027 = (char **) xrealloc (preprocessor_options
,
3028 n_preprocessor_options
* sizeof (char *));
3030 preprocessor_options
[n_preprocessor_options
- 1] =
3031 save_string (option
, len
);
3035 add_assembler_option (option
, len
)
3039 n_assembler_options
++;
3041 if (! assembler_options
)
3043 = (char **) xmalloc (n_assembler_options
* sizeof (char *));
3046 = (char **) xrealloc (assembler_options
,
3047 n_assembler_options
* sizeof (char *));
3049 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
3053 add_linker_option (option
, len
)
3059 if (! linker_options
)
3061 = (char **) xmalloc (n_linker_options
* sizeof (char *));
3064 = (char **) xrealloc (linker_options
,
3065 n_linker_options
* sizeof (char *));
3067 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
3070 /* Create the vector `switches' and its contents.
3071 Store its length in `n_switches'. */
3074 process_command (argc
, argv
)
3076 const char *const *argv
;
3081 const char *spec_lang
= 0;
3082 int last_language_n_infiles
;
3085 int lang_n_infiles
= 0;
3086 #ifdef MODIFY_TARGET_NAME
3087 int is_modify_target_name
;
3091 GET_ENV_PATH_LIST (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
3095 added_libraries
= 0;
3097 /* Figure compiler version from version string. */
3099 compiler_version
= temp1
= xstrdup (version_string
);
3101 for (; *temp1
; ++temp1
)
3110 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3111 see if we can create it from the pathname specified in argv[0]. */
3114 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3115 if (!gcc_exec_prefix
)
3117 gcc_exec_prefix
= make_relative_prefix (argv
[0], standard_bindir_prefix
,
3118 standard_exec_prefix
);
3119 if (gcc_exec_prefix
)
3120 putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix
, NULL
));
3124 if (gcc_exec_prefix
)
3126 int len
= strlen (gcc_exec_prefix
);
3128 if (len
> (int) sizeof ("/lib/gcc-lib/") - 1
3129 && (IS_DIR_SEPARATOR (gcc_exec_prefix
[len
-1])))
3131 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc-lib/") + 1;
3132 if (IS_DIR_SEPARATOR (*temp
)
3133 && strncmp (temp
+ 1, "lib", 3) == 0
3134 && IS_DIR_SEPARATOR (temp
[4])
3135 && strncmp (temp
+ 5, "gcc-lib", 7) == 0)
3136 len
-= sizeof ("/lib/gcc-lib/") - 1;
3139 set_std_prefix (gcc_exec_prefix
, len
);
3140 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC",
3141 PREFIX_PRIORITY_LAST
, 0, NULL
);
3142 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC",
3143 PREFIX_PRIORITY_LAST
, 0, NULL
);
3146 /* COMPILER_PATH and LIBRARY_PATH have values
3147 that are lists of directory names with colons. */
3149 GET_ENV_PATH_LIST (temp
, "COMPILER_PATH");
3152 const char *startp
, *endp
;
3153 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3155 startp
= endp
= temp
;
3158 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3160 strncpy (nstore
, startp
, endp
- startp
);
3162 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3163 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3165 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3166 nstore
[endp
- startp
+ 1] = 0;
3169 nstore
[endp
- startp
] = 0;
3170 add_prefix (&exec_prefixes
, nstore
, 0,
3171 PREFIX_PRIORITY_LAST
, 0, NULL
);
3172 add_prefix (&include_prefixes
,
3173 concat (nstore
, "include", NULL
),
3174 0, PREFIX_PRIORITY_LAST
, 0, NULL
);
3177 endp
= startp
= endp
+ 1;
3184 GET_ENV_PATH_LIST (temp
, LIBRARY_PATH_ENV
);
3185 if (temp
&& *cross_compile
== '0')
3187 const char *startp
, *endp
;
3188 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3190 startp
= endp
= temp
;
3193 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3195 strncpy (nstore
, startp
, endp
- startp
);
3197 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3198 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3200 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3201 nstore
[endp
- startp
+ 1] = 0;
3204 nstore
[endp
- startp
] = 0;
3205 add_prefix (&startfile_prefixes
, nstore
, NULL
,
3206 PREFIX_PRIORITY_LAST
, 0, NULL
);
3209 endp
= startp
= endp
+ 1;
3216 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3217 GET_ENV_PATH_LIST (temp
, "LPATH");
3218 if (temp
&& *cross_compile
== '0')
3220 const char *startp
, *endp
;
3221 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3223 startp
= endp
= temp
;
3226 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3228 strncpy (nstore
, startp
, endp
- startp
);
3230 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3231 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3233 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3234 nstore
[endp
- startp
+ 1] = 0;
3237 nstore
[endp
- startp
] = 0;
3238 add_prefix (&startfile_prefixes
, nstore
, NULL
,
3239 PREFIX_PRIORITY_LAST
, 0, NULL
);
3242 endp
= startp
= endp
+ 1;
3249 /* Convert new-style -- options to old-style. */
3250 translate_options (&argc
, &argv
);
3252 /* Do language-specific adjustment/addition of flags. */
3253 lang_specific_driver (&argc
, &argv
, &added_libraries
);
3255 /* Scan argv twice. Here, the first time, just count how many switches
3256 there will be in their vector, and how many input files in theirs.
3257 Also parse any switches that determine the configuration name, such as -b.
3258 Here we also parse the switches that cc itself uses (e.g. -v). */
3260 for (i
= 1; i
< argc
; i
++)
3262 if (! strcmp (argv
[i
], "-dumpspecs"))
3264 struct spec_list
*sl
;
3266 for (sl
= specs
; sl
; sl
= sl
->next
)
3267 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
3268 if (link_command_spec
)
3269 printf ("*link_command:\n%s\n\n", link_command_spec
);
3272 else if (! strcmp (argv
[i
], "-dumpversion"))
3274 printf ("%s\n", spec_version
);
3277 else if (! strcmp (argv
[i
], "-dumpmachine"))
3279 printf ("%s\n", spec_machine
);
3282 else if (strcmp (argv
[i
], "-fhelp") == 0)
3284 /* translate_options () has turned --help into -fhelp. */
3285 print_help_list
= 1;
3287 /* We will be passing a dummy file on to the sub-processes. */
3291 add_preprocessor_option ("--help", 6);
3292 add_assembler_option ("--help", 6);
3293 add_linker_option ("--help", 6);
3295 else if (strcmp (argv
[i
], "-ftarget-help") == 0)
3297 /* translate_options() has turned --target-help into -ftarget-help. */
3298 target_help_flag
= 1;
3300 /* We will be passing a dummy file on to the sub-processes. */
3304 add_preprocessor_option ("--target-help", 13);
3305 add_assembler_option ("--target-help", 13);
3306 add_linker_option ("--target-help", 13);
3308 else if (! strcmp (argv
[i
], "-pass-exit-codes"))
3310 pass_exit_codes
= 1;
3313 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3314 print_search_dirs
= 1;
3315 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3316 print_file_name
= "libgcc.a";
3317 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3318 print_file_name
= argv
[i
] + 17;
3319 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3320 print_prog_name
= argv
[i
] + 17;
3321 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3322 print_multi_lib
= 1;
3323 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3324 print_multi_directory
= 1;
3325 else if (! strncmp (argv
[i
], "-Wa,", 4))
3328 /* Pass the rest of this option to the assembler. */
3330 /* Split the argument at commas. */
3332 for (j
= 4; argv
[i
][j
]; j
++)
3333 if (argv
[i
][j
] == ',')
3335 add_assembler_option (argv
[i
] + prev
, j
- prev
);
3339 /* Record the part after the last comma. */
3340 add_assembler_option (argv
[i
] + prev
, j
- prev
);
3342 else if (! strncmp (argv
[i
], "-Wp,", 4))
3345 /* Pass the rest of this option to the preprocessor. */
3347 /* Split the argument at commas. */
3349 for (j
= 4; argv
[i
][j
]; j
++)
3350 if (argv
[i
][j
] == ',')
3352 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
3356 /* Record the part after the last comma. */
3357 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
3359 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3360 /* The +e options to the C++ front-end. */
3362 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3365 /* Split the argument at commas. */
3366 for (j
= 3; argv
[i
][j
]; j
++)
3367 n_infiles
+= (argv
[i
][j
] == ',');
3369 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3372 fatal ("argument to `-Xlinker' is missing");
3377 else if (strcmp (argv
[i
], "-l") == 0)
3380 fatal ("argument to `-l' is missing");
3385 else if (strncmp (argv
[i
], "-l", 2) == 0)
3387 else if (strcmp (argv
[i
], "-save-temps") == 0)
3389 save_temps_flag
= 1;
3392 else if (strcmp (argv
[i
], "-specs") == 0)
3394 struct user_specs
*user
= (struct user_specs
*)
3395 xmalloc (sizeof (struct user_specs
));
3397 fatal ("argument to `-specs' is missing");
3399 user
->next
= (struct user_specs
*) 0;
3400 user
->filename
= argv
[i
];
3401 if (user_specs_tail
)
3402 user_specs_tail
->next
= user
;
3404 user_specs_head
= user
;
3405 user_specs_tail
= user
;
3407 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3409 struct user_specs
*user
= (struct user_specs
*)
3410 xmalloc (sizeof (struct user_specs
));
3411 if (strlen (argv
[i
]) == 7)
3412 fatal ("argument to `-specs=' is missing");
3414 user
->next
= (struct user_specs
*) 0;
3415 user
->filename
= argv
[i
] + 7;
3416 if (user_specs_tail
)
3417 user_specs_tail
->next
= user
;
3419 user_specs_head
= user
;
3420 user_specs_tail
= user
;
3422 else if (strcmp (argv
[i
], "-time") == 0)
3424 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3426 const char *p
= &argv
[i
][1];
3433 if (p
[1] == 0 && i
+ 1 == argc
)
3434 fatal ("argument to `-b' is missing");
3436 spec_machine
= argv
[++i
];
3438 spec_machine
= p
+ 1;
3440 warn_std_ptr
= &warn_std
;
3448 if (p
[1] == 0 && i
+ 1 == argc
)
3449 fatal ("argument to `-B' is missing");
3455 len
= strlen (value
);
3457 /* Catch the case where the user has forgotten to append a
3458 directory separator to the path. Note, they may be using
3459 -B to add an executable name prefix, eg "i386-elf-", in
3460 order to distinguish between multiple installations of
3461 GCC in the same directory. Hence we must check to see
3462 if appending a directory separator actually makes a
3463 valid directory name. */
3464 if (! IS_DIR_SEPARATOR (value
[len
- 1])
3465 && is_directory (value
, "", 0))
3467 char *tmp
= xmalloc (len
+ 2);
3468 strcpy (tmp
, value
);
3469 tmp
[len
] = DIR_SEPARATOR
;
3474 /* As a kludge, if the arg is "[foo/]stageN/", just
3475 add "[foo/]include" to the include prefix. */
3478 && (IS_DIR_SEPARATOR (value
[len
- 8]))))
3479 && strncmp (value
+ len
- 7, "stage", 5) == 0
3480 && ISDIGIT (value
[len
- 2])
3481 && (IS_DIR_SEPARATOR (value
[len
- 1])))
3484 add_prefix (&include_prefixes
, "include", NULL
,
3485 PREFIX_PRIORITY_B_OPT
, 0, NULL
);
3488 char * string
= xmalloc (len
+ 1);
3490 strncpy (string
, value
, len
- 7);
3491 strcpy (string
+ len
- 7, "include");
3492 add_prefix (&include_prefixes
, string
, NULL
,
3493 PREFIX_PRIORITY_B_OPT
, 0, NULL
);
3497 add_prefix (&exec_prefixes
, value
, NULL
,
3498 PREFIX_PRIORITY_B_OPT
, 0, &warn_B
);
3499 add_prefix (&startfile_prefixes
, value
, NULL
,
3500 PREFIX_PRIORITY_B_OPT
, 0, &warn_B
);
3501 add_prefix (&include_prefixes
, concat (value
, "include", NULL
),
3502 NULL
, PREFIX_PRIORITY_B_OPT
, 0, NULL
);
3507 case 'v': /* Print our subcommands and print versions. */
3509 /* If they do anything other than exactly `-v', don't set
3510 verbose_flag; rather, continue on to give the error. */
3518 if (p
[1] == 0 && i
+ 1 == argc
)
3519 fatal ("argument to `-V' is missing");
3521 spec_version
= argv
[++i
];
3523 spec_version
= p
+ 1;
3524 compiler_version
= spec_version
;
3525 warn_std_ptr
= &warn_std
;
3527 /* Validate the version number. Use the same checks
3528 done when inserting it into a spec.
3530 The format of the version string is
3531 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
3533 const char *v
= compiler_version
;
3535 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
3536 while (! ISDIGIT (*v
))
3539 if (v
> compiler_version
&& v
[-1] != '-')
3540 fatal ("invalid version number format");
3542 /* Set V after the first period. */
3543 while (ISDIGIT (*v
))
3547 fatal ("invalid version number format");
3550 while (ISDIGIT (*v
))
3553 if (*v
!= 0 && *v
!= ' ' && *v
!= '.' && *v
!= '-')
3554 fatal ("invalid version number format");
3570 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3575 /* Forward scan, just in case -S or -c is specified
3582 if (argv
[j
][0] == '-')
3584 if (SWITCH_CURTAILS_COMPILATION (argv
[j
][1])
3590 else if ((skip
= SWITCH_TAKES_ARG (argv
[j
][1])))
3591 j
+= skip
- (argv
[j
][2] != 0);
3592 else if ((skip
= WORD_SWITCH_TAKES_ARG (argv
[j
] + 1)))
3599 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
3601 argv
[i
+ 1] = convert_filename (argv
[i
+ 1], ! have_c
);
3603 argv
[i
] = convert_filename (argv
[i
], ! have_c
);
3610 #ifdef MODIFY_TARGET_NAME
3611 is_modify_target_name
= 0;
3614 j
< sizeof modify_target
/ sizeof modify_target
[0]; j
++)
3615 if (! strcmp (argv
[i
], modify_target
[j
].sw
))
3618 = (char *) xmalloc (strlen (modify_target
[j
].str
)
3619 + strlen (spec_machine
));
3622 int made_addition
= 0;
3624 is_modify_target_name
= 1;
3625 for (p
= spec_machine
, q
= new_name
; *p
!= 0; )
3627 if (modify_target
[j
].add_del
== DELETE
3628 && (! strncmp (q
, modify_target
[j
].str
,
3629 strlen (modify_target
[j
].str
))))
3630 p
+= strlen (modify_target
[j
].str
);
3631 else if (modify_target
[j
].add_del
== ADD
3632 && ! made_addition
&& *p
== '-')
3634 for (r
= modify_target
[j
].str
; *r
!= 0; )
3642 spec_machine
= new_name
;
3645 if (is_modify_target_name
)
3651 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3652 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3653 else if (WORD_SWITCH_TAKES_ARG (p
))
3654 i
+= WORD_SWITCH_TAKES_ARG (p
);
3664 if (have_c
&& have_o
&& lang_n_infiles
> 1)
3665 fatal ("cannot specify -o with -c or -S and multiple compilations");
3667 /* Set up the search paths before we go looking for config files. */
3669 /* These come before the md prefixes so that we will find gcc's subcommands
3670 (such as cpp) rather than those of the host system. */
3671 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3672 as well as trying the machine and the version. */
3674 add_prefix (&exec_prefixes
, standard_exec_prefix
, "GCC",
3675 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
);
3676 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
3677 PREFIX_PRIORITY_LAST
, 2, warn_std_ptr
);
3678 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3679 PREFIX_PRIORITY_LAST
, 2, warn_std_ptr
);
3682 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
3683 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
);
3684 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3685 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
);
3687 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
3688 dir_separator_str
, NULL
);
3690 /* If tooldir is relative, base it on exec_prefixes. A relative
3691 tooldir lets us move the installed tree as a unit.
3693 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3694 directories, so that we can search both the user specified directory
3695 and the standard place. */
3697 if (!IS_ABSOLUTE_PATHNAME (tooldir_prefix
))
3699 if (gcc_exec_prefix
)
3701 char *gcc_exec_tooldir_prefix
3702 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
3703 spec_version
, dir_separator_str
, tooldir_prefix
, NULL
);
3705 add_prefix (&exec_prefixes
,
3706 concat (gcc_exec_tooldir_prefix
, "bin",
3707 dir_separator_str
, NULL
),
3708 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
3709 add_prefix (&startfile_prefixes
,
3710 concat (gcc_exec_tooldir_prefix
, "lib",
3711 dir_separator_str
, NULL
),
3712 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
3715 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
3716 dir_separator_str
, spec_version
,
3717 dir_separator_str
, tooldir_prefix
, NULL
);
3720 add_prefix (&exec_prefixes
,
3721 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL
),
3722 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
3723 add_prefix (&startfile_prefixes
,
3724 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL
),
3725 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
3727 /* More prefixes are enabled in main, after we read the specs file
3728 and determine whether this is cross-compilation or not. */
3730 /* Then create the space for the vectors and scan again. */
3732 switches
= ((struct switchstr
*)
3733 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
3734 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
3737 last_language_n_infiles
= -1;
3739 /* This, time, copy the text of each switch and store a pointer
3740 to the copy in the vector of switches.
3741 Store all the infiles in their vector. */
3743 for (i
= 1; i
< argc
; i
++)
3745 /* Just skip the switches that were handled by the preceding loop. */
3746 #ifdef MODIFY_TARGET_NAME
3747 is_modify_target_name
= 0;
3749 for (j
= 0; j
< sizeof modify_target
/ sizeof modify_target
[0]; j
++)
3750 if (! strcmp (argv
[i
], modify_target
[j
].sw
))
3751 is_modify_target_name
= 1;
3753 if (is_modify_target_name
)
3757 if (! strncmp (argv
[i
], "-Wa,", 4))
3759 else if (! strncmp (argv
[i
], "-Wp,", 4))
3761 else if (! strcmp (argv
[i
], "-pass-exit-codes"))
3763 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3765 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3767 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3769 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3771 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3773 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3775 else if (strcmp (argv
[i
], "-ftarget-help") == 0)
3777 /* Create a dummy input file, so that we can pass --target-help on to
3778 the various sub-processes. */
3779 infiles
[n_infiles
].language
= "c";
3780 infiles
[n_infiles
++].name
= "target-dummy";
3782 /* Preserve the --target-help switch so that it can be caught by
3783 the cc1 spec string. */
3784 switches
[n_switches
].part1
= "--target-help";
3785 switches
[n_switches
].args
= 0;
3786 switches
[n_switches
].live_cond
= SWITCH_OK
;
3787 switches
[n_switches
].validated
= 0;
3791 else if (strcmp (argv
[i
], "-fhelp") == 0)
3795 /* Create a dummy input file, so that we can pass --help on to
3796 the various sub-processes. */
3797 infiles
[n_infiles
].language
= "c";
3798 infiles
[n_infiles
++].name
= "help-dummy";
3800 /* Preserve the --help switch so that it can be caught by the
3802 switches
[n_switches
].part1
= "--help";
3803 switches
[n_switches
].args
= 0;
3804 switches
[n_switches
].live_cond
= SWITCH_OK
;
3805 switches
[n_switches
].validated
= 0;
3810 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3812 /* Compensate for the +e options to the C++ front-end;
3813 they're there simply for cfront call-compatibility. We do
3814 some magic in default_compilers to pass them down properly.
3815 Note we deliberately start at the `+' here, to avoid passing
3816 -e0 or -e1 down into the linker. */
3817 switches
[n_switches
].part1
= &argv
[i
][0];
3818 switches
[n_switches
].args
= 0;
3819 switches
[n_switches
].live_cond
= SWITCH_OK
;
3820 switches
[n_switches
].validated
= 0;
3823 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3826 /* Split the argument at commas. */
3828 for (j
= 4; argv
[i
][j
]; j
++)
3829 if (argv
[i
][j
] == ',')
3831 infiles
[n_infiles
].language
= "*";
3832 infiles
[n_infiles
++].name
3833 = save_string (argv
[i
] + prev
, j
- prev
);
3836 /* Record the part after the last comma. */
3837 infiles
[n_infiles
].language
= "*";
3838 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
3840 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3842 infiles
[n_infiles
].language
= "*";
3843 infiles
[n_infiles
++].name
= argv
[++i
];
3845 else if (strcmp (argv
[i
], "-l") == 0)
3846 { /* POSIX allows separation of -l and the lib arg;
3847 canonicalize by concatenating -l with its arg */
3848 infiles
[n_infiles
].language
= "*";
3849 infiles
[n_infiles
++].name
= concat ("-l", argv
[++i
], NULL
);
3851 else if (strncmp (argv
[i
], "-l", 2) == 0)
3853 infiles
[n_infiles
].language
= "*";
3854 infiles
[n_infiles
++].name
= argv
[i
];
3856 else if (strcmp (argv
[i
], "-specs") == 0)
3858 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3860 else if (strcmp (argv
[i
], "-time") == 0)
3862 else if ((save_temps_flag
|| report_times
)
3863 && strcmp (argv
[i
], "-pipe") == 0)
3865 /* -save-temps overrides -pipe, so that temp files are produced */
3866 if (save_temps_flag
)
3867 error ("Warning: -pipe ignored because -save-temps specified");
3868 /* -time overrides -pipe because we can't get correct stats when
3869 multiple children are running at once. */
3870 else if (report_times
)
3871 error ("Warning: -pipe ignored because -time specified");
3873 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3875 const char *p
= &argv
[i
][1];
3880 if (p
[1] == 0 && i
+ 1 == argc
)
3881 fatal ("argument to `-x' is missing");
3883 spec_lang
= argv
[++i
];
3886 if (! strcmp (spec_lang
, "none"))
3887 /* Suppress the warning if -xnone comes after the last input
3888 file, because alternate command interfaces like g++ might
3889 find it useful to place -xnone after each input file. */
3892 last_language_n_infiles
= n_infiles
;
3895 switches
[n_switches
].part1
= p
;
3896 /* Deal with option arguments in separate argv elements. */
3897 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3898 || WORD_SWITCH_TAKES_ARG (p
))
3901 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
3905 /* Count only the option arguments in separate argv elements. */
3906 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3908 if (i
+ n_args
>= argc
)
3909 fatal ("argument to `-%s' is missing", p
);
3910 switches
[n_switches
].args
3911 = (const char **) xmalloc ((n_args
+ 1) * sizeof(const char *));
3913 switches
[n_switches
].args
[j
++] = argv
[++i
];
3914 /* Null-terminate the vector. */
3915 switches
[n_switches
].args
[j
] = 0;
3917 else if (strchr (switches_need_spaces
, c
))
3919 /* On some systems, ld cannot handle some options without
3920 a space. So split the option from its argument. */
3921 char *part1
= (char *) xmalloc (2);
3925 switches
[n_switches
].part1
= part1
;
3926 switches
[n_switches
].args
3927 = (const char **) xmalloc (2 * sizeof (const char *));
3928 switches
[n_switches
].args
[0] = xstrdup (p
+1);
3929 switches
[n_switches
].args
[1] = 0;
3932 switches
[n_switches
].args
= 0;
3934 switches
[n_switches
].live_cond
= SWITCH_OK
;
3935 switches
[n_switches
].validated
= 0;
3936 switches
[n_switches
].ordering
= 0;
3937 /* These are always valid, since gcc.c itself understands it. */
3938 if (!strcmp (p
, "save-temps")
3939 || !strcmp (p
, "static-libgcc")
3940 || !strcmp (p
, "shared-libgcc"))
3941 switches
[n_switches
].validated
= 1;
3944 char ch
= switches
[n_switches
].part1
[0];
3945 if (ch
== 'V' || ch
== 'b' || ch
== 'B')
3946 switches
[n_switches
].validated
= 1;
3952 #ifdef HAVE_TARGET_OBJECT_SUFFIX
3953 argv
[i
] = convert_filename (argv
[i
], 0);
3956 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], F_OK
) < 0)
3958 perror_with_name (argv
[i
]);
3963 infiles
[n_infiles
].language
= spec_lang
;
3964 infiles
[n_infiles
++].name
= argv
[i
];
3969 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
3970 error ("Warning: `-x %s' after last input file has no effect", spec_lang
);
3972 switches
[n_switches
].part1
= 0;
3973 infiles
[n_infiles
].name
= 0;
3976 /* Process a spec string, accumulating and running commands. */
3978 /* These variables describe the input file name.
3979 input_file_number is the index on outfiles of this file,
3980 so that the output file name can be stored for later use by %o.
3981 input_basename is the start of the part of the input file
3982 sans all directory names, and basename_length is the number
3983 of characters starting there excluding the suffix .c or whatever. */
3985 const char *input_filename
;
3986 static int input_file_number
;
3987 size_t input_filename_length
;
3988 static int basename_length
;
3989 static int suffixed_basename_length
;
3990 static const char *input_basename
;
3991 static const char *input_suffix
;
3993 /* The compiler used to process the current input file. */
3994 static struct compiler
*input_file_compiler
;
3996 /* These are variables used within do_spec and do_spec_1. */
3998 /* Nonzero if an arg has been started and not yet terminated
3999 (with space, tab or newline). */
4000 static int arg_going
;
4002 /* Nonzero means %d or %g has been seen; the next arg to be terminated
4003 is a temporary file name. */
4004 static int delete_this_arg
;
4006 /* Nonzero means %w has been seen; the next arg to be terminated
4007 is the output file name of this compilation. */
4008 static int this_is_output_file
;
4010 /* Nonzero means %s has been seen; the next arg to be terminated
4011 is the name of a library file and we should try the standard
4012 search dirs for it. */
4013 static int this_is_library_file
;
4015 /* Nonzero means that the input of this command is coming from a pipe. */
4016 static int input_from_pipe
;
4018 /* Nonnull means substitute this for any suffix when outputting a switches
4020 static const char *suffix_subst
;
4022 /* Process the spec SPEC and run the commands specified therein.
4023 Returns 0 if the spec is successfully processed; -1 if failed. */
4033 delete_this_arg
= 0;
4034 this_is_output_file
= 0;
4035 this_is_library_file
= 0;
4036 input_from_pipe
= 0;
4037 suffix_subst
= NULL
;
4039 value
= do_spec_1 (spec
, 0, NULL
);
4041 /* Force out any unfinished command.
4042 If -pipe, this forces out the last command if it ended in `|'. */
4045 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4048 if (argbuf_index
> 0)
4055 /* Process the sub-spec SPEC as a portion of a larger spec.
4056 This is like processing a whole spec except that we do
4057 not initialize at the beginning and we do not supply a
4058 newline by default at the end.
4059 INSWITCH nonzero means don't process %-sequences in SPEC;
4060 in this case, % is treated as an ordinary character.
4061 This is used while substituting switches.
4062 INSWITCH nonzero also causes SPC not to terminate an argument.
4064 Value is zero unless a line was finished
4065 and the command on that line reported an error. */
4068 do_spec_1 (spec
, inswitch
, soft_matched_part
)
4071 const char *soft_matched_part
;
4073 const char *p
= spec
;
4080 /* If substituting a switch, treat all chars like letters.
4081 Otherwise, NL, SPC, TAB and % are special. */
4082 switch (inswitch
? 'a' : c
)
4085 /* End of line: finish any pending argument,
4086 then run the pending command if one has been started. */
4089 obstack_1grow (&obstack
, 0);
4090 string
= obstack_finish (&obstack
);
4091 if (this_is_library_file
)
4092 string
= find_file (string
);
4093 store_arg (string
, delete_this_arg
, this_is_output_file
);
4094 if (this_is_output_file
)
4095 outfiles
[input_file_number
] = string
;
4099 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4101 for (i
= 0; i
< n_switches
; i
++)
4102 if (!strcmp (switches
[i
].part1
, "pipe"))
4105 /* A `|' before the newline means use a pipe here,
4106 but only if -pipe was specified.
4107 Otherwise, execute now and don't pass the `|' as an arg. */
4110 input_from_pipe
= 1;
4111 switches
[i
].validated
= 1;
4118 if (argbuf_index
> 0)
4124 /* Reinitialize for a new command, and for a new argument. */
4127 delete_this_arg
= 0;
4128 this_is_output_file
= 0;
4129 this_is_library_file
= 0;
4130 input_from_pipe
= 0;
4134 /* End any pending argument. */
4137 obstack_1grow (&obstack
, 0);
4138 string
= obstack_finish (&obstack
);
4139 if (this_is_library_file
)
4140 string
= find_file (string
);
4141 store_arg (string
, delete_this_arg
, this_is_output_file
);
4142 if (this_is_output_file
)
4143 outfiles
[input_file_number
] = string
;
4147 obstack_1grow (&obstack
, c
);
4153 /* Space or tab ends an argument if one is pending. */
4156 obstack_1grow (&obstack
, 0);
4157 string
= obstack_finish (&obstack
);
4158 if (this_is_library_file
)
4159 string
= find_file (string
);
4160 store_arg (string
, delete_this_arg
, this_is_output_file
);
4161 if (this_is_output_file
)
4162 outfiles
[input_file_number
] = string
;
4164 /* Reinitialize for a new argument. */
4166 delete_this_arg
= 0;
4167 this_is_output_file
= 0;
4168 this_is_library_file
= 0;
4175 fatal ("Invalid specification! Bug in cc.");
4178 obstack_grow (&obstack
, input_basename
, basename_length
);
4183 obstack_grow (&obstack
, input_basename
, suffixed_basename_length
);
4188 delete_this_arg
= 2;
4191 /* Dump out the directories specified with LIBRARY_PATH,
4192 followed by the absolute directories
4193 that we search for startfiles. */
4196 struct prefix_list
*pl
= startfile_prefixes
.plist
;
4197 size_t bufsize
= 100;
4198 char *buffer
= (char *) xmalloc (bufsize
);
4201 for (; pl
; pl
= pl
->next
)
4203 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4204 /* Used on systems which record the specified -L dirs
4205 and use them to search for dynamic linking. */
4206 /* Relative directories always come from -B,
4207 and it is better not to use them for searching
4208 at run time. In particular, stage1 loses. */
4209 if (!IS_ABSOLUTE_PATHNAME (pl
->prefix
))
4212 /* Try subdirectory if there is one. */
4213 if (multilib_dir
!= NULL
)
4217 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
4219 bufsize
= (strlen (pl
->prefix
)
4220 + strlen (machine_suffix
)) * 2 + 1;
4221 buffer
= (char *) xrealloc (buffer
, bufsize
);
4222 strcpy (buffer
, pl
->prefix
);
4223 strcat (buffer
, machine_suffix
);
4224 if (is_directory (buffer
, multilib_dir
, 1))
4226 do_spec_1 ("-L", 0, NULL
);
4227 #ifdef SPACE_AFTER_L_OPTION
4228 do_spec_1 (" ", 0, NULL
);
4230 do_spec_1 (buffer
, 1, NULL
);
4231 do_spec_1 (multilib_dir
, 1, NULL
);
4232 /* Make this a separate argument. */
4233 do_spec_1 (" ", 0, NULL
);
4236 if (!pl
->require_machine_suffix
)
4238 if (is_directory (pl
->prefix
, multilib_dir
, 1))
4240 do_spec_1 ("-L", 0, NULL
);
4241 #ifdef SPACE_AFTER_L_OPTION
4242 do_spec_1 (" ", 0, NULL
);
4244 do_spec_1 (pl
->prefix
, 1, NULL
);
4245 do_spec_1 (multilib_dir
, 1, NULL
);
4246 /* Make this a separate argument. */
4247 do_spec_1 (" ", 0, NULL
);
4253 if (is_directory (pl
->prefix
, machine_suffix
, 1))
4255 do_spec_1 ("-L", 0, NULL
);
4256 #ifdef SPACE_AFTER_L_OPTION
4257 do_spec_1 (" ", 0, NULL
);
4259 do_spec_1 (pl
->prefix
, 1, NULL
);
4260 /* Remove slash from machine_suffix. */
4261 if (strlen (machine_suffix
) >= bufsize
)
4262 bufsize
= strlen (machine_suffix
) * 2 + 1;
4263 buffer
= (char *) xrealloc (buffer
, bufsize
);
4264 strcpy (buffer
, machine_suffix
);
4265 idx
= strlen (buffer
);
4266 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
4267 buffer
[idx
- 1] = 0;
4268 do_spec_1 (buffer
, 1, NULL
);
4269 /* Make this a separate argument. */
4270 do_spec_1 (" ", 0, NULL
);
4273 if (!pl
->require_machine_suffix
)
4275 if (is_directory (pl
->prefix
, "", 1))
4277 do_spec_1 ("-L", 0, NULL
);
4278 #ifdef SPACE_AFTER_L_OPTION
4279 do_spec_1 (" ", 0, NULL
);
4281 /* Remove slash from pl->prefix. */
4282 if (strlen (pl
->prefix
) >= bufsize
)
4283 bufsize
= strlen (pl
->prefix
) * 2 + 1;
4284 buffer
= (char *) xrealloc (buffer
, bufsize
);
4285 strcpy (buffer
, pl
->prefix
);
4286 idx
= strlen (buffer
);
4287 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
4288 buffer
[idx
- 1] = 0;
4289 do_spec_1 (buffer
, 1, NULL
);
4290 /* Make this a separate argument. */
4291 do_spec_1 (" ", 0, NULL
);
4300 /* %efoo means report an error with `foo' as error message
4301 and don't execute any more commands for this file. */
4305 while (*p
!= 0 && *p
!= '\n')
4307 buf
= (char *) alloca (p
- q
+ 1);
4308 strncpy (buf
, q
, p
- q
);
4315 /* %nfoo means report an notice with `foo' on stderr. */
4319 while (*p
!= 0 && *p
!= '\n')
4321 buf
= (char *) alloca (p
- q
+ 1);
4322 strncpy (buf
, q
, p
- q
);
4324 notice ("%s\n", buf
);
4334 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is defined,
4335 and it is not a directory, and it is writable, use it.
4336 Otherwise, fall through and treat this like any other
4339 if ((!save_temps_flag
)
4340 && (stat (HOST_BIT_BUCKET
, &st
) == 0) && (!S_ISDIR (st
.st_mode
))
4341 && (access (HOST_BIT_BUCKET
, W_OK
) == 0))
4343 obstack_grow (&obstack
, HOST_BIT_BUCKET
,
4344 strlen (HOST_BIT_BUCKET
));
4345 delete_this_arg
= 0;
4353 if (save_temps_flag
)
4355 obstack_grow (&obstack
, input_basename
, basename_length
);
4356 delete_this_arg
= 0;
4360 struct temp_name
*t
;
4362 const char *suffix
= p
;
4363 char *saved_suffix
= NULL
;
4365 while (*p
== '.' || ISALPHA ((unsigned char) *p
))
4367 suffix_length
= p
- suffix
;
4368 if (p
[0] == '%' && p
[1] == 'O')
4371 /* We don't support extra suffix characters after %O. */
4372 if (*p
== '.' || ISALPHA ((unsigned char) *p
))
4374 if (suffix_length
== 0)
4375 suffix
= TARGET_OBJECT_SUFFIX
;
4379 = (char *) xmalloc (suffix_length
4380 + strlen (TARGET_OBJECT_SUFFIX
));
4381 strncpy (saved_suffix
, suffix
, suffix_length
);
4382 strcpy (saved_suffix
+ suffix_length
,
4383 TARGET_OBJECT_SUFFIX
);
4385 suffix_length
+= strlen (TARGET_OBJECT_SUFFIX
);
4388 /* See if we already have an association of %g/%u/%U and
4390 for (t
= temp_names
; t
; t
= t
->next
)
4391 if (t
->length
== suffix_length
4392 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
4393 && t
->unique
== (c
!= 'g'))
4396 /* Make a new association if needed. %u and %j
4398 if (t
== 0 || c
== 'u' || c
== 'j')
4402 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
4403 t
->next
= temp_names
;
4406 t
->length
= suffix_length
;
4409 t
->suffix
= saved_suffix
;
4410 saved_suffix
= NULL
;
4413 t
->suffix
= save_string (suffix
, suffix_length
);
4414 t
->unique
= (c
!= 'g');
4415 temp_filename
= make_temp_file (t
->suffix
);
4416 temp_filename_length
= strlen (temp_filename
);
4417 t
->filename
= temp_filename
;
4418 t
->filename_length
= temp_filename_length
;
4422 free (saved_suffix
);
4424 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
4425 delete_this_arg
= 1;
4431 obstack_grow (&obstack
, input_filename
, input_filename_length
);
4437 struct prefix_list
*pl
= include_prefixes
.plist
;
4439 if (gcc_exec_prefix
)
4441 do_spec_1 ("-iprefix", 1, NULL
);
4442 /* Make this a separate argument. */
4443 do_spec_1 (" ", 0, NULL
);
4444 do_spec_1 (gcc_exec_prefix
, 1, NULL
);
4445 do_spec_1 (" ", 0, NULL
);
4448 for (; pl
; pl
= pl
->next
)
4450 do_spec_1 ("-isystem", 1, NULL
);
4451 /* Make this a separate argument. */
4452 do_spec_1 (" ", 0, NULL
);
4453 do_spec_1 (pl
->prefix
, 1, NULL
);
4454 do_spec_1 (" ", 0, NULL
);
4461 int max
= n_infiles
;
4462 max
+= lang_specific_extra_outfiles
;
4464 for (i
= 0; i
< max
; i
++)
4466 store_arg (outfiles
[i
], 0, 0);
4471 obstack_grow (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
4476 this_is_library_file
= 1;
4480 this_is_output_file
= 1;
4485 int cur_index
= argbuf_index
;
4486 /* Handle the {...} following the %W. */
4489 p
= handle_braces (p
+ 1);
4492 /* If any args were output, mark the last one for deletion
4494 if (argbuf_index
!= cur_index
)
4495 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
4499 /* %x{OPTION} records OPTION for %X to output. */
4505 /* Skip past the option value and make a copy. */
4510 string
= save_string (p1
+ 1, p
- p1
- 2);
4512 /* See if we already recorded this option. */
4513 for (i
= 0; i
< n_linker_options
; i
++)
4514 if (! strcmp (string
, linker_options
[i
]))
4520 /* This option is new; add it. */
4521 add_linker_option (string
, strlen (string
));
4525 /* Dump out the options accumulated previously using %x. */
4527 for (i
= 0; i
< n_linker_options
; i
++)
4529 do_spec_1 (linker_options
[i
], 1, NULL
);
4530 /* Make each accumulated option a separate argument. */
4531 do_spec_1 (" ", 0, NULL
);
4535 /* Dump out the options accumulated previously using -Wa,. */
4537 for (i
= 0; i
< n_assembler_options
; i
++)
4539 do_spec_1 (assembler_options
[i
], 1, NULL
);
4540 /* Make each accumulated option a separate argument. */
4541 do_spec_1 (" ", 0, NULL
);
4545 /* Dump out the options accumulated previously using -Wp,. */
4547 for (i
= 0; i
< n_preprocessor_options
; i
++)
4549 do_spec_1 (preprocessor_options
[i
], 1, NULL
);
4550 /* Make each accumulated option a separate argument. */
4551 do_spec_1 (" ", 0, NULL
);
4555 /* Here are digits and numbers that just process
4556 a certain constant string as a spec. */
4559 value
= do_spec_1 (cc1_spec
, 0, NULL
);
4565 value
= do_spec_1 (cc1plus_spec
, 0, NULL
);
4571 value
= do_spec_1 (asm_spec
, 0, NULL
);
4577 value
= do_spec_1 (asm_final_spec
, 0, NULL
);
4583 value
= do_spec_1 (signed_char_spec
, 0, NULL
);
4590 const char *const spec
4591 = (input_file_compiler
->cpp_spec
4592 ? input_file_compiler
->cpp_spec
4594 value
= do_spec_1 (spec
, 0, NULL
);
4601 value
= do_spec_1 (endfile_spec
, 0, NULL
);
4607 value
= do_spec_1 (link_spec
, 0, NULL
);
4613 value
= do_spec_1 (lib_spec
, 0, NULL
);
4619 value
= do_spec_1 (libgcc_spec
, 0, NULL
);
4625 if (multilib_dir
&& strcmp (multilib_dir
, ".") != 0)
4631 len
= strlen (multilib_dir
);
4632 obstack_blank (&obstack
, len
+ 1);
4633 p
= obstack_next_free (&obstack
) - (len
+ 1);
4636 for (q
= multilib_dir
; *q
; ++q
, ++p
)
4637 *p
= (IS_DIR_SEPARATOR (*q
) ? '_' : *q
);
4643 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
4647 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4651 if (! strncmp (y
, "-D", 2))
4652 /* Copy the whole option. */
4653 while (*y
&& *y
!= ' ' && *y
!= '\t')
4655 else if (*y
== ' ' || *y
== '\t')
4656 /* Copy whitespace to the result. */
4658 /* Don't copy other options. */
4665 value
= do_spec_1 (buf
, 0, NULL
);
4673 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
4677 /* Copy all of CPP_PREDEFINES into BUF,
4678 but force them all into the reserved name space if they
4679 aren't already there. The reserved name space is all
4680 identifiers beginning with two underscores or with one
4681 underscore and a capital letter. We do the forcing by
4682 adding up to two underscores to the beginning and end
4683 of each symbol. e.g. mips, _mips, mips_, and _mips_ all
4688 if (! strncmp (y
, "-D", 2))
4697 && ! ISUPPER ((unsigned char) *(y
+ 1))))
4699 /* Stick __ at front of macro name. */
4703 /* Arrange to stick __ at the end as well. */
4707 /* Copy the macro name. */
4708 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4721 /* Copy the value given, if any. */
4722 while (*y
&& *y
!= ' ' && *y
!= '\t')
4725 else if (*y
== ' ' || *y
== '\t')
4726 /* Copy whitespace to the result. */
4728 /* Don't copy -A options */
4734 /* Copy all of CPP_PREDEFINES into BUF,
4735 but put __ after every -D. */
4739 if (! strncmp (y
, "-D", 2))
4745 && ! ISUPPER ((unsigned char) *(y
+ 1))))
4747 /* Stick -D__ at front of macro name. */
4754 /* Copy the macro name. */
4755 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4758 /* Copy the value given, if any. */
4759 while (*y
&& *y
!= ' ' && *y
!= '\t')
4764 /* Do not copy this macro - we have just done it before */
4765 while (*y
&& *y
!= ' ' && *y
!= '\t')
4769 else if (*y
== ' ' || *y
== '\t')
4770 /* Copy whitespace to the result. */
4772 /* Don't copy -A options. */
4778 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4782 if (! strncmp (y
, "-A", 2))
4783 /* Copy the whole option. */
4784 while (*y
&& *y
!= ' ' && *y
!= '\t')
4786 else if (*y
== ' ' || *y
== '\t')
4787 /* Copy whitespace to the result. */
4789 /* Don't copy other options. */
4796 value
= do_spec_1 (buf
, 0, NULL
);
4803 value
= do_spec_1 (startfile_spec
, 0, NULL
);
4808 /* Here we define characters other than letters and digits. */
4811 p
= handle_braces (p
);
4817 obstack_1grow (&obstack
, '%');
4824 while (p
[len
] && p
[len
] != ' ' && p
[len
] != '%')
4826 suffix_subst
= save_string (p
- 1, len
+ 1);
4832 if (soft_matched_part
)
4834 do_spec_1 (soft_matched_part
, 1, NULL
);
4835 do_spec_1 (" ", 0, NULL
);
4838 /* Catch the case where a spec string contains something like
4839 '%{foo:%*}'. ie there is no * in the pattern on the left
4840 hand side of the :. */
4841 error ("Spec failure: '%%*' has not been initialised by pattern match");
4844 /* Process a string found as the value of a spec given by name.
4845 This feature allows individual machine descriptions
4846 to add and use their own specs.
4847 %[...] modifies -D options the way %P does;
4848 %(...) uses the spec unmodified. */
4850 error ("Warning: use of obsolete %%[ operator in specs");
4853 const char *name
= p
;
4854 struct spec_list
*sl
;
4857 /* The string after the S/P is the name of a spec that is to be
4859 while (*p
&& *p
!= ')' && *p
!= ']')
4862 /* See if it's in the list. */
4863 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
4864 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
4866 name
= *(sl
->ptr_spec
);
4868 notice ("Processing spec %c%s%c, which is '%s'\n",
4869 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
4878 value
= do_spec_1 (name
, 0, NULL
);
4884 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
4886 const char *y
= name
;
4889 /* Copy all of NAME into BUF, but put __ after
4890 every -D and at the end of each arg. */
4893 if (! strncmp (y
, "-D", 2))
4904 && (*y
== ' ' || *y
== '\t' || *y
== '='
4905 || *y
== '}' || *y
== 0))
4918 value
= do_spec_1 (buf
, 0, NULL
);
4924 /* Discard the closing paren or bracket. */
4932 int c1
= *p
++; /* Select first or second version number. */
4933 const char *v
= compiler_version
;
4935 static const char zeroc
= '0';
4937 /* The format of the version string is
4938 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
4940 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
4941 while (! ISDIGIT (*v
))
4943 if (v
> compiler_version
&& v
[-1] != '-')
4946 /* If desired, advance to second version number. */
4949 /* Set V after the first period. */
4950 while (ISDIGIT (*v
))
4957 /* If desired, advance to third version number.
4958 But don't complain if it's not present */
4961 /* Set V after the second period. */
4962 while (ISDIGIT (*v
))
4964 if ((*v
!= 0) && (*v
!= ' ') && (*v
!= '.') && (*v
!= '-'))
4970 /* Set Q at the next period or at the end. */
4972 while (ISDIGIT (*q
))
4974 if (*q
!= 0 && q
> v
&& *q
!= ' ' && *q
!= '.' && *q
!= '-')
4978 /* Put that part into the command. */
4979 obstack_grow (&obstack
, v
, q
- v
);
4981 /* Default to "0" */
4982 obstack_grow (&obstack
, &zeroc
, 1);
4988 if (input_from_pipe
)
4989 do_spec_1 ("-", 0, NULL
);
4993 error ("Spec failure: Unrecognised spec option '%c'", c
);
4999 /* Backslash: treat next character as ordinary. */
5004 /* Ordinary character: put it into the current argument. */
5005 obstack_1grow (&obstack
, c
);
5009 /* End of string. */
5013 /* Return 0 if we call do_spec_1 and that returns -1. */
5019 const char *filter
, *body
= NULL
, *endbody
= NULL
;
5021 int true_once
= 0; /* If, in %{a|b:d}, at least one of a,b was seen. */
5024 int include_blanks
= 1;
5025 int elide_switch
= 0;
5030 /* A '^' after the open-brace means to not give blanks before args. */
5037 /* A `|' after the open-brace means,
5038 if the test fails, output a single minus sign rather than nothing.
5039 This is used in %{|!pipe:...}. */
5046 /* A `<' after the open-brace means that the switch should be
5047 removed from the command-line. */
5053 negate
= suffix
= 0;
5056 /* A `!' after the open-brace negates the condition:
5057 succeed if the specified switch is not present. */
5061 /* A `.' after the open-brace means test against the current suffix. */
5070 if (elide_switch
&& (negate
|| pipe_p
|| suffix
))
5072 /* It doesn't make sense to mix elision with other flags. We
5073 could fatal() here, but the standard seems to be to abort. */
5079 while (*p
!= ':' && *p
!= '}' && *p
!= '|' && *p
!= '&')
5082 if (*p
== '|' && (pipe_p
|| ordered
))
5087 if (*p
!= '}' && *p
!= '&')
5103 fatal ("Mismatched braces in specs");
5109 body
= p
, endbody
= p
+ 1;
5114 int found
= (input_suffix
!= 0
5115 && (long) strlen (input_suffix
) == (long) (p
- filter
)
5116 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
5122 && do_spec_1 (save_string (body
, endbody
-body
-1), 0, NULL
) < 0)
5125 else if (p
[-1] == '*' && (p
[0] == '}' || p
[0] == '&'))
5127 /* Substitute all matching switches as separate args. */
5130 for (i
= 0; i
< n_switches
; i
++)
5131 if (!strncmp (switches
[i
].part1
, filter
, p
- 1 - filter
)
5132 && check_live_switch (i
, p
- 1 - filter
))
5136 switches
[i
].live_cond
= SWITCH_IGNORE
;
5137 switches
[i
].validated
= 1;
5140 ordered
= 1, switches
[i
].ordering
= 1;
5145 /* Test for presence of the specified switch. */
5149 /* If name specified ends in *, as in {x*:...},
5150 check for %* and handle that case. */
5151 if (p
[-1] == '*' && !negate
)
5154 const char *r
= body
;
5156 /* First see whether we have %*. */
5160 if (*r
== '%' && r
[1] == '*')
5164 /* If we do, handle that case. */
5167 /* Substitute all matching switches as separate args.
5168 But do this by substituting for %*
5169 in the text that follows the colon. */
5171 unsigned hard_match_len
= p
- filter
- 1;
5172 char *string
= save_string (body
, endbody
- body
- 1);
5174 for (i
= 0; i
< n_switches
; i
++)
5175 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
5176 && check_live_switch (i
, -1))
5178 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
5179 /* Pass any arguments this switch has. */
5180 give_switch (i
, 1, 1);
5181 suffix_subst
= NULL
;
5184 /* We didn't match. Try again. */
5191 /* If name specified ends in *, as in {x*:...},
5192 check for presence of any switch name starting with x. */
5195 for (i
= 0; i
< n_switches
; i
++)
5197 unsigned hard_match_len
= p
- filter
- 1;
5199 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
5200 && check_live_switch (i
, hard_match_len
))
5207 /* Otherwise, check for presence of exact name specified. */
5210 for (i
= 0; i
< n_switches
; i
++)
5212 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5213 && switches
[i
].part1
[p
- filter
] == 0
5214 && check_live_switch (i
, -1))
5222 /* If it is as desired (present for %{s...}, absent for %{!s...})
5223 then substitute either the switch or the specified
5224 conditional text. */
5225 if (present
!= negate
)
5229 switches
[i
].live_cond
= SWITCH_IGNORE
;
5230 switches
[i
].validated
= 1;
5232 else if (ordered
|| *p
== '&')
5233 ordered
= 1, switches
[i
].ordering
= 1;
5235 give_switch (i
, 0, include_blanks
);
5237 /* Even if many alternatives are matched, only output once. */
5242 /* Here if a %{|...} conditional fails: output a minus sign,
5243 which means "standard output" or "standard input". */
5244 do_spec_1 ("-", 0, NULL
);
5249 /* We didn't match; try again. */
5256 goto next_ampersand
;
5262 /* Doing this set of switches later preserves their command-line
5263 ordering. This is needed for e.g. -U, -D and -A. */
5264 for (i
= 0; i
< n_switches
; i
++)
5265 if (switches
[i
].ordering
== 1)
5267 switches
[i
].ordering
= 0;
5268 give_switch (i
, 0, include_blanks
);
5271 /* Process the spec just once, regardless of match count. */
5274 if (do_spec_1 (save_string (body
, endbody
- body
- 1),
5282 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
5283 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
5284 spec, or -1 if either exact match or %* is used.
5286 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
5287 whose value does not begin with "no-" is obsoleted by the same value
5288 with the "no-", similarly for a switch with the "no-" prefix. */
5291 check_live_switch (switchnum
, prefix_length
)
5295 const char *name
= switches
[switchnum
].part1
;
5298 /* In the common case of {<at-most-one-letter>*}, a negating
5299 switch would always match, so ignore that case. We will just
5300 send the conflicting switches to the compiler phase. */
5301 if (prefix_length
>= 0 && prefix_length
<= 1)
5304 /* If we already processed this switch and determined if it was
5305 live or not, return our past determination. */
5306 if (switches
[switchnum
].live_cond
!= 0)
5307 return switches
[switchnum
].live_cond
> 0;
5309 /* Now search for duplicate in a manner that depends on the name. */
5313 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5314 if (switches
[i
].part1
[0] == 'O')
5316 switches
[switchnum
].validated
= 1;
5317 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5322 case 'W': case 'f': case 'm':
5323 if (! strncmp (name
+ 1, "no-", 3))
5325 /* We have Xno-YYY, search for XYYY. */
5326 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5327 if (switches
[i
].part1
[0] == name
[0]
5328 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
5330 switches
[switchnum
].validated
= 1;
5331 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5337 /* We have XYYY, search for Xno-YYY. */
5338 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5339 if (switches
[i
].part1
[0] == name
[0]
5340 && switches
[i
].part1
[1] == 'n'
5341 && switches
[i
].part1
[2] == 'o'
5342 && switches
[i
].part1
[3] == '-'
5343 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
5345 switches
[switchnum
].validated
= 1;
5346 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5353 /* Otherwise the switch is live. */
5354 switches
[switchnum
].live_cond
= SWITCH_LIVE
;
5358 /* Pass a switch to the current accumulating command
5359 in the same form that we received it.
5360 SWITCHNUM identifies the switch; it is an index into
5361 the vector of switches gcc received, which is `switches'.
5362 This cannot fail since it never finishes a command line.
5364 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
5366 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
5370 give_switch (switchnum
, omit_first_word
, include_blanks
)
5372 int omit_first_word
;
5375 if (switches
[switchnum
].live_cond
== SWITCH_IGNORE
)
5378 if (!omit_first_word
)
5380 do_spec_1 ("-", 0, NULL
);
5381 do_spec_1 (switches
[switchnum
].part1
, 1, NULL
);
5384 if (switches
[switchnum
].args
!= 0)
5387 for (p
= switches
[switchnum
].args
; *p
; p
++)
5389 const char *arg
= *p
;
5392 do_spec_1 (" ", 0, NULL
);
5395 unsigned length
= strlen (arg
);
5398 while (length
-- && !IS_DIR_SEPARATOR (arg
[length
]))
5399 if (arg
[length
] == '.')
5401 ((char *)arg
)[length
] = 0;
5405 do_spec_1 (arg
, 1, NULL
);
5407 ((char *)arg
)[length
] = '.';
5408 do_spec_1 (suffix_subst
, 1, NULL
);
5411 do_spec_1 (arg
, 1, NULL
);
5415 do_spec_1 (" ", 0, NULL
);
5416 switches
[switchnum
].validated
= 1;
5419 /* Search for a file named NAME trying various prefixes including the
5420 user's -B prefix and some standard ones.
5421 Return the absolute file name found. If nothing is found, return NAME. */
5429 /* Try multilib_dir if it is defined. */
5430 if (multilib_dir
!= NULL
)
5432 const char *const try = ACONCAT ((multilib_dir
, dir_separator_str
, name
, NULL
));
5434 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
5436 /* If we don't find it in the multi library dir, then fall
5437 through and look for it in the normal places. */
5438 if (newname
!= NULL
)
5442 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
5443 return newname
? newname
: name
;
5446 /* Determine whether a directory exists. If LINKER, return 0 for
5447 certain fixed names not needed by the linker. If not LINKER, it is
5448 only important to return 0 if the host machine has a small ARG_MAX
5452 is_directory (path1
, path2
, linker
)
5457 int len1
= strlen (path1
);
5458 int len2
= strlen (path2
);
5459 char *path
= (char *) alloca (3 + len1
+ len2
);
5463 #ifndef SMALL_ARG_MAX
5468 /* Construct the path from the two parts. Ensure the string ends with "/.".
5469 The resulting path will be a directory even if the given path is a
5471 memcpy (path
, path1
, len1
);
5472 memcpy (path
+ len1
, path2
, len2
);
5473 cp
= path
+ len1
+ len2
;
5474 if (!IS_DIR_SEPARATOR (cp
[-1]))
5475 *cp
++ = DIR_SEPARATOR
;
5479 /* Exclude directories that the linker is known to search. */
5482 && strcmp (path
, concat (dir_separator_str
, "lib",
5483 dir_separator_str
, ".", NULL
)) == 0)
5485 && strcmp (path
, concat (dir_separator_str
, "usr",
5486 dir_separator_str
, "lib",
5487 dir_separator_str
, ".", NULL
)) == 0)))
5490 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
5493 /* Set up the various global variables to indicate that we're processing
5494 the input file named FILENAME. */
5497 set_input (filename
)
5498 const char *filename
;
5502 input_filename
= filename
;
5503 input_filename_length
= strlen (input_filename
);
5505 input_basename
= input_filename
;
5506 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5507 /* Skip drive name so 'x:foo' is handled properly. */
5508 if (input_basename
[1] == ':')
5509 input_basename
+= 2;
5511 for (p
= input_basename
; *p
; p
++)
5512 if (IS_DIR_SEPARATOR (*p
))
5513 input_basename
= p
+ 1;
5515 /* Find a suffix starting with the last period,
5516 and set basename_length to exclude that suffix. */
5517 basename_length
= strlen (input_basename
);
5518 suffixed_basename_length
= basename_length
;
5519 p
= input_basename
+ basename_length
;
5520 while (p
!= input_basename
&& *p
!= '.')
5522 if (*p
== '.' && p
!= input_basename
)
5524 basename_length
= p
- input_basename
;
5525 input_suffix
= p
+ 1;
5531 /* On fatal signals, delete all the temporary files. */
5534 fatal_error (signum
)
5537 signal (signum
, SIG_DFL
);
5538 delete_failure_queue ();
5539 delete_temp_files ();
5540 /* Get the same signal again, this time not handled,
5541 so its normal effect occurs. */
5542 kill (getpid (), signum
);
5545 extern int main
PARAMS ((int, const char *const *));
5550 const char *const *argv
;
5554 int linker_was_run
= 0;
5555 char *explicit_link_files
;
5558 struct user_specs
*uptr
;
5560 p
= argv
[0] + strlen (argv
[0]);
5561 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
5565 xmalloc_set_program_name (programname
);
5567 #ifdef GCC_DRIVER_HOST_INITIALIZATION
5568 /* Perform host dependent initialization when needed. */
5569 GCC_DRIVER_HOST_INITIALIZATION
;
5572 gcc_init_libintl ();
5574 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
5575 signal (SIGINT
, fatal_error
);
5577 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
5578 signal (SIGHUP
, fatal_error
);
5580 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
5581 signal (SIGTERM
, fatal_error
);
5583 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
5584 signal (SIGPIPE
, fatal_error
);
5587 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
5588 receive the signal. A different setting is inheritable */
5589 signal (SIGCHLD
, SIG_DFL
);
5593 argbuf
= (const char **) xmalloc (argbuf_length
* sizeof (const char *));
5595 obstack_init (&obstack
);
5597 /* Build multilib_select, et. al from the separate lines that make up each
5598 multilib selection. */
5600 const char *const *q
= multilib_raw
;
5603 obstack_init (&multilib_obstack
);
5604 while ((p
= *q
++) != (char *) 0)
5605 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5607 obstack_1grow (&multilib_obstack
, 0);
5608 multilib_select
= obstack_finish (&multilib_obstack
);
5610 q
= multilib_matches_raw
;
5611 while ((p
= *q
++) != (char *) 0)
5612 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5614 obstack_1grow (&multilib_obstack
, 0);
5615 multilib_matches
= obstack_finish (&multilib_obstack
);
5617 q
= multilib_exclusions_raw
;
5618 while ((p
= *q
++) != (char *) 0)
5619 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5621 obstack_1grow (&multilib_obstack
, 0);
5622 multilib_exclusions
= obstack_finish (&multilib_obstack
);
5625 for (i
= 0; i
< ARRAY_SIZE (multilib_defaults_raw
); i
++)
5628 obstack_1grow (&multilib_obstack
, ' ');
5629 obstack_grow (&multilib_obstack
,
5630 multilib_defaults_raw
[i
],
5631 strlen (multilib_defaults_raw
[i
]));
5635 obstack_1grow (&multilib_obstack
, 0);
5636 multilib_defaults
= obstack_finish (&multilib_obstack
);
5639 /* Set up to remember the pathname of gcc and any options
5640 needed for collect. We use argv[0] instead of programname because
5641 we need the complete pathname. */
5642 obstack_init (&collect_obstack
);
5643 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
5644 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0]) + 1);
5645 putenv (obstack_finish (&collect_obstack
));
5647 #ifdef INIT_ENVIRONMENT
5648 /* Set up any other necessary machine specific environment variables. */
5649 putenv (INIT_ENVIRONMENT
);
5652 /* Make a table of what switches there are (switches, n_switches).
5653 Make a table of specified input files (infiles, n_infiles).
5654 Decode switches that are handled locally. */
5656 process_command (argc
, argv
);
5661 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
5663 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
5664 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
5667 for (i
= 0; (int) i
< n_switches
; i
++)
5669 const char *const *args
;
5672 obstack_grow (&collect_obstack
, " ", 1);
5675 obstack_grow (&collect_obstack
, "'-", 2);
5676 q
= switches
[i
].part1
;
5677 while ((p
= strchr (q
, '\'')))
5679 obstack_grow (&collect_obstack
, q
, p
- q
);
5680 obstack_grow (&collect_obstack
, "'\\''", 4);
5683 obstack_grow (&collect_obstack
, q
, strlen (q
));
5684 obstack_grow (&collect_obstack
, "'", 1);
5686 for (args
= switches
[i
].args
; args
&& *args
; args
++)
5688 obstack_grow (&collect_obstack
, " '", 2);
5690 while ((p
= strchr (q
, '\'')))
5692 obstack_grow (&collect_obstack
, q
, p
- q
);
5693 obstack_grow (&collect_obstack
, "'\\''", 4);
5696 obstack_grow (&collect_obstack
, q
, strlen (q
));
5697 obstack_grow (&collect_obstack
, "'", 1);
5700 obstack_grow (&collect_obstack
, "\0", 1);
5701 putenv (obstack_finish (&collect_obstack
));
5704 /* Initialize the vector of specs to just the default.
5705 This means one element containing 0s, as a terminator. */
5707 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
5708 memcpy ((char *) compilers
, (char *) default_compilers
,
5709 sizeof default_compilers
);
5710 n_compilers
= n_default_compilers
;
5712 /* Read specs from a file if there is one. */
5714 machine_suffix
= concat (spec_machine
, dir_separator_str
,
5715 spec_version
, dir_separator_str
, NULL
);
5716 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL
);
5718 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
5719 /* Read the specs file unless it is a default one. */
5720 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
5721 read_specs (specs_file
, TRUE
);
5725 /* We need to check standard_exec_prefix/just_machine_suffix/specs
5726 for any override of as, ld and libraries. */
5727 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
5728 + strlen (just_machine_suffix
)
5729 + sizeof ("specs"));
5731 strcpy (specs_file
, standard_exec_prefix
);
5732 strcat (specs_file
, just_machine_suffix
);
5733 strcat (specs_file
, "specs");
5734 if (access (specs_file
, R_OK
) == 0)
5735 read_specs (specs_file
, TRUE
);
5737 /* If not cross-compiling, look for startfiles in the standard places. */
5738 if (*cross_compile
== '0')
5740 if (*md_exec_prefix
)
5742 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC",
5743 PREFIX_PRIORITY_LAST
, 0, NULL
);
5744 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC",
5745 PREFIX_PRIORITY_LAST
, 0, NULL
);
5748 if (*md_startfile_prefix
)
5749 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
5750 PREFIX_PRIORITY_LAST
, 0, NULL
);
5752 if (*md_startfile_prefix_1
)
5753 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
5754 PREFIX_PRIORITY_LAST
, 0, NULL
);
5756 /* If standard_startfile_prefix is relative, base it on
5757 standard_exec_prefix. This lets us move the installed tree
5758 as a unit. If GCC_EXEC_PREFIX is defined, base
5759 standard_startfile_prefix on that as well. */
5760 if (IS_ABSOLUTE_PATHNAME (standard_startfile_prefix
))
5761 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
5762 PREFIX_PRIORITY_LAST
, 0, NULL
);
5765 if (gcc_exec_prefix
)
5766 add_prefix (&startfile_prefixes
,
5767 concat (gcc_exec_prefix
, machine_suffix
,
5768 standard_startfile_prefix
, NULL
),
5769 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
5770 add_prefix (&startfile_prefixes
,
5771 concat (standard_exec_prefix
,
5773 standard_startfile_prefix
, NULL
),
5774 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
5777 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
5778 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
5779 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
5780 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
5781 #if 0 /* Can cause surprises, and one can use -B./ instead. */
5782 add_prefix (&startfile_prefixes
, "./", NULL
,
5783 PREFIX_PRIORITY_LAST
, 1, NULL
);
5788 if (!IS_ABSOLUTE_PATHNAME (standard_startfile_prefix
)
5790 add_prefix (&startfile_prefixes
,
5791 concat (gcc_exec_prefix
, machine_suffix
,
5792 standard_startfile_prefix
, NULL
),
5793 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
5796 /* Process any user specified specs in the order given on the command
5798 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
5800 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
, R_OK
);
5801 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
5804 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
5805 if (gcc_exec_prefix
)
5806 gcc_exec_prefix
= concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
5807 spec_version
, dir_separator_str
, NULL
);
5809 /* Now we have the specs.
5810 Set the `valid' bits for switches that match anything in any spec. */
5812 validate_all_switches ();
5814 /* Now that we have the switches and the specs, set
5815 the subdirectory based on the options. */
5816 set_multilib_dir ();
5818 /* Warn about any switches that no pass was interested in. */
5820 for (i
= 0; (int) i
< n_switches
; i
++)
5821 if (! switches
[i
].validated
)
5822 error ("unrecognized option `-%s'", switches
[i
].part1
);
5824 /* Obey some of the options. */
5826 if (print_search_dirs
)
5828 printf (_("install: %s%s\n"), standard_exec_prefix
, machine_suffix
);
5829 printf (_("programs: %s\n"), build_search_list (&exec_prefixes
, "", 0));
5830 printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes
, "", 0));
5834 if (print_file_name
)
5836 printf ("%s\n", find_file (print_file_name
));
5840 if (print_prog_name
)
5842 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
5843 printf ("%s\n", (newname
? newname
: print_prog_name
));
5847 if (print_multi_lib
)
5849 print_multilib_info ();
5853 if (print_multi_directory
)
5855 if (multilib_dir
== NULL
)
5858 printf ("%s\n", multilib_dir
);
5862 if (target_help_flag
)
5864 /* Print if any target specific options.*/
5866 /* We do not exit here. Instead we have created a fake input file
5867 called 'target-dummy' which needs to be compiled, and we pass this
5868 on to the various sub-processes, along with the --target-help
5872 if (print_help_list
)
5878 printf (_("\nFor bug reporting instructions, please see:\n"));
5879 printf ("%s.\n", GCCBUGURL
);
5884 /* We do not exit here. Instead we have created a fake input file
5885 called 'help-dummy' which needs to be compiled, and we pass this
5886 on the various sub-processes, along with the --help switch. */
5894 notice ("Configured with: %s\n", configuration_arguments
);
5896 #ifdef THREAD_MODEL_SPEC
5897 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
5898 but there's no point in doing all this processing just to get
5899 thread_model back. */
5900 obstack_init (&obstack
);
5901 do_spec_1 (THREAD_MODEL_SPEC
, 0, thread_model
);
5902 obstack_1grow (&obstack
, '\0');
5903 thrmod
= obstack_finish (&obstack
);
5905 thrmod
= thread_model
;
5908 notice ("Thread model: %s\n", thrmod
);
5910 /* compiler_version is truncated at the first space when initialized
5911 from version string, so truncate version_string at the first space
5912 before comparing. */
5913 for (n
= 0; version_string
[n
]; n
++)
5914 if (version_string
[n
] == ' ')
5917 if (! strncmp (version_string
, compiler_version
, n
)
5918 && compiler_version
[n
] == 0)
5919 notice ("gcc version %s\n", version_string
);
5921 notice ("gcc driver version %s executing gcc version %s\n",
5922 version_string
, compiler_version
);
5928 if (n_infiles
== added_libraries
)
5929 fatal ("No input files");
5931 /* Make a place to record the compiler output file names
5932 that correspond to the input files. */
5935 i
+= lang_specific_extra_outfiles
;
5936 outfiles
= (const char **) xcalloc (i
, sizeof (char *));
5938 /* Record which files were specified explicitly as link input. */
5940 explicit_link_files
= xcalloc (1, n_infiles
);
5942 for (i
= 0; (int) i
< n_infiles
; i
++)
5944 int this_file_error
= 0;
5946 /* Tell do_spec what to substitute for %i. */
5948 input_file_number
= i
;
5949 set_input (infiles
[i
].name
);
5951 /* Use the same thing in %o, unless cp->spec says otherwise. */
5953 outfiles
[i
] = input_filename
;
5955 /* Figure out which compiler from the file's suffix. */
5958 = lookup_compiler (infiles
[i
].name
, input_filename_length
,
5959 infiles
[i
].language
);
5961 if (input_file_compiler
)
5963 /* Ok, we found an applicable compiler. Run its spec. */
5965 if (input_file_compiler
->spec
[0] == '#')
5967 error ("%s: %s compiler not installed on this system",
5968 input_filename
, &input_file_compiler
->spec
[1]);
5969 this_file_error
= 1;
5973 value
= do_spec (input_file_compiler
->spec
);
5975 this_file_error
= 1;
5979 /* If this file's name does not contain a recognized suffix,
5980 record it as explicit linker input. */
5983 explicit_link_files
[i
] = 1;
5985 /* Clear the delete-on-failure queue, deleting the files in it
5986 if this compilation failed. */
5988 if (this_file_error
)
5990 delete_failure_queue ();
5993 /* If this compilation succeeded, don't delete those files later. */
5994 clear_failure_queue ();
5997 /* Reset the output file name to the first input file name, for use
5998 with %b in LINK_SPEC on a target that prefers not to emit a.out
6001 set_input (infiles
[0].name
);
6003 if (error_count
== 0)
6005 /* Make sure INPUT_FILE_NUMBER points to first available open
6007 input_file_number
= n_infiles
;
6008 if (lang_specific_pre_link ())
6012 /* Run ld to link all the compiler output files. */
6014 if (error_count
== 0)
6016 int tmp
= execution_count
;
6018 /* We'll use ld if we can't find collect2. */
6019 if (! strcmp (linker_name_spec
, "collect2"))
6021 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
);
6023 linker_name_spec
= "ld";
6025 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
6027 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH");
6028 putenv_from_prefixes (&startfile_prefixes
, LIBRARY_PATH_ENV
);
6030 value
= do_spec (link_command_spec
);
6033 linker_was_run
= (tmp
!= execution_count
);
6036 /* If options said don't run linker,
6037 complain about input files to be given to the linker. */
6039 if (! linker_was_run
&& error_count
== 0)
6040 for (i
= 0; (int) i
< n_infiles
; i
++)
6041 if (explicit_link_files
[i
])
6042 error ("%s: linker input file unused because linking not done",
6045 /* Delete some or all of the temporary files we made. */
6048 delete_failure_queue ();
6049 delete_temp_files ();
6051 if (print_help_list
)
6053 printf (("\nFor bug reporting instructions, please see:\n"));
6054 printf ("%s\n", GCCBUGURL
);
6057 return (signal_count
!= 0 ? 2
6058 : error_count
> 0 ? (pass_exit_codes
? greatest_status
: 1)
6062 /* Find the proper compilation spec for the file name NAME,
6063 whose length is LENGTH. LANGUAGE is the specified language,
6064 or 0 if this file is to be passed to the linker. */
6066 static struct compiler
*
6067 lookup_compiler (name
, length
, language
)
6070 const char *language
;
6072 struct compiler
*cp
;
6074 /* If this was specified by the user to be a linker input, indicate that. */
6075 if (language
!= 0 && language
[0] == '*')
6078 /* Otherwise, look for the language, if one is spec'd. */
6081 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6082 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
6085 error ("language %s not recognized", language
);
6089 /* Look for a suffix. */
6090 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6092 if (/* The suffix `-' matches only the file name `-'. */
6093 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
6094 || (strlen (cp
->suffix
) < length
6095 /* See if the suffix matches the end of NAME. */
6096 && !strcmp (cp
->suffix
,
6097 name
+ length
- strlen (cp
->suffix
))
6102 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
6103 /* look again, but case-insensitively this time. */
6105 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6107 if (/* The suffix `-' matches only the file name `-'. */
6108 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
6109 || (strlen (cp
->suffix
) < length
6110 /* See if the suffix matches the end of NAME. */
6111 && ((!strcmp (cp
->suffix
,
6112 name
+ length
- strlen (cp
->suffix
))
6113 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
6114 && !strcasecmp (cp
->suffix
,
6115 name
+ length
- strlen (cp
->suffix
)))
6121 if (cp
>= compilers
)
6123 if (cp
->spec
[0] != '@')
6124 /* A non-alias entry: return it. */
6127 /* An alias entry maps a suffix to a language.
6128 Search for the language; pass 0 for NAME and LENGTH
6129 to avoid infinite recursion if language not found. */
6130 return lookup_compiler (NULL
, 0, cp
->spec
+ 1);
6136 save_string (s
, len
)
6140 char *result
= xmalloc (len
+ 1);
6142 memcpy (result
, s
, len
);
6148 pfatal_with_name (name
)
6151 perror_with_name (name
);
6152 delete_temp_files ();
6157 perror_with_name (name
)
6160 error ("%s: %s", name
, xstrerror (errno
));
6164 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
6165 const char *errmsg_fmt
;
6166 const char *errmsg_arg
;
6170 int save_errno
= errno
;
6172 /* Space for trailing '\0' is in %s. */
6173 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
6174 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
6180 pfatal_with_name (errmsg_fmt
);
6183 /* Output an error message and exit */
6188 fatal ("Internal gcc abort.");
6191 /* Output an error message and exit */
6194 fatal
VPARAMS ((const char *msgid
, ...))
6196 VA_OPEN (ap
, msgid
);
6197 VA_FIXEDARG (ap
, const char *, msgid
);
6199 fprintf (stderr
, "%s: ", programname
);
6200 vfprintf (stderr
, _(msgid
), ap
);
6202 fprintf (stderr
, "\n");
6203 delete_temp_files ();
6208 error
VPARAMS ((const char *msgid
, ...))
6210 VA_OPEN (ap
, msgid
);
6211 VA_FIXEDARG (ap
, const char *, msgid
);
6213 fprintf (stderr
, "%s: ", programname
);
6214 vfprintf (stderr
, _(msgid
), ap
);
6217 fprintf (stderr
, "\n");
6221 notice
VPARAMS ((const char *msgid
, ...))
6223 VA_OPEN (ap
, msgid
);
6224 VA_FIXEDARG (ap
, const char *, msgid
);
6226 vfprintf (stderr
, _(msgid
), ap
);
6231 validate_all_switches ()
6233 struct compiler
*comp
;
6236 struct spec_list
*spec
;
6238 for (comp
= compilers
; comp
->spec
; comp
++)
6242 if (c
== '%' && *p
== '{')
6243 /* We have a switch spec. */
6244 validate_switches (p
+ 1);
6247 /* Look through the linked list of specs read from the specs file. */
6248 for (spec
= specs
; spec
; spec
= spec
->next
)
6250 p
= *(spec
->ptr_spec
);
6252 if (c
== '%' && *p
== '{')
6253 /* We have a switch spec. */
6254 validate_switches (p
+ 1);
6257 p
= link_command_spec
;
6259 if (c
== '%' && *p
== '{')
6260 /* We have a switch spec. */
6261 validate_switches (p
+ 1);
6264 /* Look at the switch-name that comes after START
6265 and mark as valid all supplied switches that match it. */
6268 validate_switches (start
)
6271 const char *p
= start
;
6288 while (*p
!= ':' && *p
!= '}' && *p
!= '|' && *p
!= '&')
6293 else if (p
[-1] == '*')
6295 /* Mark all matching switches as valid. */
6296 for (i
= 0; i
< n_switches
; i
++)
6297 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
- 1))
6298 switches
[i
].validated
= 1;
6302 /* Mark an exact matching switch as valid. */
6303 for (i
= 0; i
< n_switches
; i
++)
6305 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
6306 && switches
[i
].part1
[p
- filter
] == 0)
6307 switches
[i
].validated
= 1;
6311 if (*p
++ == '|' || p
[-1] == '&')
6315 /* Check whether a particular argument was used. The first time we
6316 canonicalize the switches to keep only the ones we care about. */
6326 const char *replace
;
6331 static struct mswitchstr
*mswitches
;
6332 static int n_mswitches
;
6337 struct mswitchstr
*matches
;
6341 /* Break multilib_matches into the component strings of string
6342 and replacement string. */
6343 for (q
= multilib_matches
; *q
!= '\0'; q
++)
6348 (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
6350 q
= multilib_matches
;
6360 matches
[i
].len
= q
- matches
[i
].str
;
6362 matches
[i
].replace
= ++q
;
6363 while (*q
!= ';' && *q
!= '\0')
6369 matches
[i
].rep_len
= q
- matches
[i
].replace
;
6375 /* Now build a list of the replacement string for switches that we care
6376 about. Make sure we allocate at least one entry. This prevents
6377 xmalloc from calling fatal, and prevents us from re-executing this
6380 = (struct mswitchstr
*) xmalloc ((sizeof (struct mswitchstr
))
6381 * (n_switches
? n_switches
: 1));
6382 for (i
= 0; i
< n_switches
; i
++)
6384 int xlen
= strlen (switches
[i
].part1
);
6385 for (j
= 0; j
< cnt
; j
++)
6386 if (xlen
== matches
[j
].len
6387 && ! strncmp (switches
[i
].part1
, matches
[j
].str
, xlen
))
6389 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
6390 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
6391 mswitches
[n_mswitches
].replace
= (char *) 0;
6392 mswitches
[n_mswitches
].rep_len
= 0;
6399 for (i
= 0; i
< n_mswitches
; i
++)
6400 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
6407 default_arg (p
, len
)
6411 const char *start
, *end
;
6413 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+ 1)
6415 while (*start
== ' ' || *start
== '\t')
6421 for (end
= start
+ 1; *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
6424 if ((end
- start
) == len
&& strncmp (p
, start
, len
) == 0)
6434 /* Work out the subdirectory to use based on the options. The format of
6435 multilib_select is a list of elements. Each element is a subdirectory
6436 name followed by a list of options followed by a semicolon. The format
6437 of multilib_exclusions is the same, but without the preceding
6438 directory. First gcc will check the exclusions, if none of the options
6439 beginning with an exclamation point are present, and all of the other
6440 options are present, then we will ignore this completely. Passing
6441 that, gcc will consider each multilib_select in turn using the same
6442 rules for matching the options. If a match is found, that subdirectory
6449 unsigned int this_path_len
;
6450 const char *this_path
, *this_arg
;
6454 p
= multilib_exclusions
;
6457 /* Ignore newlines. */
6464 /* Check the arguments. */
6478 while (*p
!= ' ' && *p
!= ';')
6485 if (*this_arg
!= '!')
6493 ok
= used_arg (this_arg
, p
- this_arg
);
6507 p
= multilib_select
;
6510 /* Ignore newlines. */
6517 /* Get the initial path. */
6525 this_path_len
= p
- this_path
;
6527 /* Check the arguments. */
6542 while (*p
!= ' ' && *p
!= ';')
6549 if (*this_arg
!= '!')
6557 /* If this is a default argument, we can just ignore it.
6558 This is true even if this_arg begins with '!'. Beginning
6559 with '!' does not mean that this argument is necessarily
6560 inappropriate for this library: it merely means that
6561 there is a more specific library which uses this
6562 argument. If this argument is a default, we need not
6563 consider that more specific library. */
6564 if (! default_arg (this_arg
, p
- this_arg
))
6566 ok
= used_arg (this_arg
, p
- this_arg
);
6577 if (this_path_len
!= 1
6578 || this_path
[0] != '.')
6580 char *new_multilib_dir
= xmalloc (this_path_len
+ 1);
6581 strncpy (new_multilib_dir
, this_path
, this_path_len
);
6582 new_multilib_dir
[this_path_len
] = '\0';
6583 multilib_dir
= new_multilib_dir
;
6592 /* Print out the multiple library subdirectory selection
6593 information. This prints out a series of lines. Each line looks
6594 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
6595 required. Only the desired options are printed out, the negative
6596 matches. The options are print without a leading dash. There are
6597 no spaces to make it easy to use the information in the shell.
6598 Each subdirectory is printed only once. This assumes the ordering
6599 generated by the genmultilib script. Also, we leave out ones that match
6603 print_multilib_info ()
6605 const char *p
= multilib_select
;
6606 const char *last_path
= 0, *this_path
;
6608 unsigned int last_path_len
= 0;
6613 /* Ignore newlines. */
6620 /* Get the initial path. */
6629 /* Check for matches with the multilib_exclusions. We don't bother
6630 with the '!' in either list. If any of the exclusion rules match
6631 all of its options with the select rule, we skip it. */
6633 const char *e
= multilib_exclusions
;
6634 const char *this_arg
;
6639 /* Ignore newlines. */
6646 /* Check the arguments. */
6663 while (*e
!= ' ' && *e
!= ';')
6674 int len
= e
- this_arg
;
6681 while (*q
!= ' ' && *q
!= ';')
6688 if (! strncmp (arg
, this_arg
, (len
< q
- arg
) ? q
- arg
: len
) ||
6689 default_arg (this_arg
, e
- this_arg
))
6719 /* If this is a duplicate, skip it. */
6720 skip
= (last_path
!= 0 && (unsigned int) (p
- this_path
) == last_path_len
6721 && ! strncmp (last_path
, this_path
, last_path_len
));
6723 last_path
= this_path
;
6724 last_path_len
= p
- this_path
;
6727 /* If this directory requires any default arguments, we can skip
6728 it. We will already have printed a directory identical to
6729 this one which does not require that default argument. */
6747 while (*q
!= ' ' && *q
!= ';')
6755 && default_arg (arg
, q
- arg
))
6770 for (p1
= last_path
; p1
< p
; p1
++)
6789 use_arg
= *p
!= '!';
6794 while (*p
!= ' ' && *p
!= ';')
6809 /* If there are extra options, print them now. */
6810 if (multilib_extra
&& *multilib_extra
)
6812 int print_at
= TRUE
;
6815 for (q
= multilib_extra
; *q
!= '\0'; q
++)