1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 This paragraph is here to try to keep Sun CC from dying.
23 The number of chars here seems crucial!!!! */
25 /* This program is the user interface to the C compiler and possibly to
26 other compilers. It is used because compilation is a complicated procedure
27 which involves running several programs and passing temporary files between
28 them, forwarding the users switches to those programs selectively,
29 and deleting the temporary files at the end.
31 CC recognizes how to compile each input file by suffixes in the file names.
32 Once it knows which kind of compilation to perform, the procedure for
33 compilation is specified by a string called a "spec". */
35 /* A Short Introduction to Adding a Command-Line Option.
37 Before adding a command-line option, consider if it is really
38 necessary. Each additional command-line option adds complexity and
39 is difficult to remove in subsequent versions.
41 In the following, consider adding the command-line argument
44 1. Each command-line option is specified in the specs file. The
45 notation is described below in the comment entitled "The Specs
48 2. In this file, add an entry to "option_map" equating the long
49 `--' argument version and any shorter, single letter version. Read
50 the comments in the declaration of "struct option_map" for an
51 explanation. Do not omit the first `-'.
53 3. Look in the "specs" file to determine which program or option
54 list should be given the argument, e.g., "cc1_options". Add the
55 appropriate syntax for the shorter option version to the
56 corresponding "const char *" entry in this file. Omit the first
57 `-' from the option. For example, use `-bar', rather than `--bar'.
59 4. If the argument takes an argument, e.g., `--baz argument1',
60 modify either DEFAULT_SWITCH_TAKES_ARG or
61 DEFAULT_WORD_SWITCH_TAKES_ARG in this file. Omit the first `-'
64 5. Document the option in this file's display_help(). If the
65 option is passed to a subprogram, modify its corresponding
66 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
69 6. Compile and test. Make sure that your new specs file is being
70 read. For example, use a debugger to investigate the value of
71 "specs_file" in main(). */
76 #if ! defined( SIGCHLD ) && defined( SIGCLD )
77 # define SIGCHLD SIGCLD
85 #ifdef HAVE_SYS_RESOURCE_H
86 #include <sys/resource.h>
88 #if defined (HAVE_DECL_GETRUSAGE) && !HAVE_DECL_GETRUSAGE
89 extern int getrusage
PARAMS ((int, struct rusage
*));
92 /* By default there is no special suffix for target executables. */
93 /* FIXME: when autoconf is fixed, remove the host check - dj */
94 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
95 #define HAVE_TARGET_EXECUTABLE_SUFFIX
98 /* By default there is no special suffix for host executables. */
99 #ifdef HOST_EXECUTABLE_SUFFIX
100 #define HAVE_HOST_EXECUTABLE_SUFFIX
102 #define HOST_EXECUTABLE_SUFFIX ""
105 /* By default, the suffix for target object files is ".o". */
106 #ifdef TARGET_OBJECT_SUFFIX
107 #define HAVE_TARGET_OBJECT_SUFFIX
109 #define TARGET_OBJECT_SUFFIX ".o"
113 /* FIXME: the location independence code for VMS is hairier than this,
114 and hasn't been written. */
120 static const char dir_separator_str
[] = { DIR_SEPARATOR
, 0 };
122 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
123 #ifndef LIBRARY_PATH_ENV
124 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
128 #define kill(p,s) raise(s)
131 /* If a stage of compilation returns an exit status >= 1,
132 compilation of that file ceases. */
134 #define MIN_FATAL_STATUS 1
136 /* Flag set by cppspec.c to 1. */
139 /* Flag saying to pass the greatest exit code returned by a sub-process
140 to the calling program. */
141 static int pass_exit_codes
;
143 /* Definition of string containing the arguments given to configure. */
144 #include "configargs.h"
146 /* Flag saying to print the directories gcc will search through looking for
147 programs, libraries, etc. */
149 static int print_search_dirs
;
151 /* Flag saying to print the full filename of this file
152 as found through our usual search mechanism. */
154 static const char *print_file_name
= NULL
;
156 /* As print_file_name, but search for executable file. */
158 static const char *print_prog_name
= NULL
;
160 /* Flag saying to print the relative path we'd use to
161 find libgcc.a given the current compiler flags. */
163 static int print_multi_directory
;
165 /* Flag saying to print the relative path we'd use to
166 find OS libraries given the current compiler flags. */
168 static int print_multi_os_directory
;
170 /* Flag saying to print the list of subdirectories and
171 compiler flags used to select them in a standard form. */
173 static int print_multi_lib
;
175 /* Flag saying to print the command line options understood by gcc and its
178 static int print_help_list
;
180 /* Flag indicating whether we should print the command and arguments */
182 static int verbose_flag
;
184 /* Flag indicating whether we should ONLY print the command and
185 arguments (like verbose_flag) without executing the command.
186 Displayed arguments are quoted so that the generated command
187 line is suitable for execution. This is intended for use in
188 shell scripts to capture the driver-generated command line. */
189 static int verbose_only_flag
;
191 /* Flag indicating to print target specific command line options. */
193 static int target_help_flag
;
195 /* Flag indicating whether we should report subprocess execution times
196 (if this is supported by the system - see pexecute.c). */
198 static int report_times
;
200 /* Nonzero means write "temp" files in source directory
201 and use the source file's name in them, and don't delete them. */
203 static int save_temps_flag
;
205 /* The compiler version. */
207 static const char *compiler_version
;
209 /* The target version specified with -V */
211 static const char *const spec_version
= DEFAULT_TARGET_VERSION
;
213 /* The target machine specified with -b. */
215 static const char *spec_machine
= DEFAULT_TARGET_MACHINE
;
217 /* Nonzero if cross-compiling.
218 When -b is used, the value comes from the `specs' file. */
221 static const char *cross_compile
= "1";
223 static const char *cross_compile
= "0";
226 #ifdef MODIFY_TARGET_NAME
228 /* Information on how to alter the target name based on a command-line
229 switch. The only case we support now is simply appending or deleting a
230 string to or from the end of the first part of the configuration name. */
232 static const struct modify_target
234 const char *const sw
;
235 const enum add_del
{ADD
, DELETE
} add_del
;
236 const char *const str
;
238 modify_target
[] = MODIFY_TARGET_NAME
;
241 /* The number of errors that have occurred; the link phase will not be
242 run if this is nonzero. */
243 static int error_count
= 0;
245 /* Greatest exit code of sub-processes that has been encountered up to
247 static int greatest_status
= 1;
249 /* This is the obstack which we use to allocate many strings. */
251 static struct obstack obstack
;
253 /* This is the obstack to build an environment variable to pass to
254 collect2 that describes all of the relevant switches of what to
255 pass the compiler in building the list of pointers to constructors
258 static struct obstack collect_obstack
;
260 /* These structs are used to collect resource usage information for
262 #ifdef HAVE_GETRUSAGE
263 static struct rusage rus
, prus
;
266 /* Forward declaration for prototypes. */
269 static void init_spec
PARAMS ((void));
271 static char **split_directories
PARAMS ((const char *, int *));
272 static void free_split_directories
PARAMS ((char **));
273 static char *make_relative_prefix
PARAMS ((const char *, const char *, const char *));
275 static void store_arg
PARAMS ((const char *, int, int));
276 static char *load_specs
PARAMS ((const char *));
277 static void read_specs
PARAMS ((const char *, int));
278 static void set_spec
PARAMS ((const char *, const char *));
279 static struct compiler
*lookup_compiler
PARAMS ((const char *, size_t, const char *));
280 static char *build_search_list
PARAMS ((struct path_prefix
*, const char *, int));
281 static void putenv_from_prefixes
PARAMS ((struct path_prefix
*, const char *));
282 static int access_check
PARAMS ((const char *, int));
283 static char *find_a_file
PARAMS ((struct path_prefix
*, const char *,
285 static void add_prefix
PARAMS ((struct path_prefix
*, const char *,
286 const char *, int, int, int *, int));
287 static void translate_options
PARAMS ((int *, const char *const **));
288 static char *skip_whitespace
PARAMS ((char *));
289 static void delete_if_ordinary
PARAMS ((const char *));
290 static void delete_temp_files
PARAMS ((void));
291 static void delete_failure_queue
PARAMS ((void));
292 static void clear_failure_queue
PARAMS ((void));
293 static int check_live_switch
PARAMS ((int, int));
294 static const char *handle_braces
PARAMS ((const char *));
295 static char *save_string
PARAMS ((const char *, int));
296 static void set_collect_gcc_options
PARAMS ((void));
297 static int do_spec_1
PARAMS ((const char *, int, const char *));
298 static int do_spec_2
PARAMS ((const char *));
299 static void do_self_spec
PARAMS ((const char *));
300 static const char *find_file
PARAMS ((const char *));
301 static int is_directory
PARAMS ((const char *, const char *, int));
302 static void validate_switches
PARAMS ((const char *));
303 static void validate_all_switches
PARAMS ((void));
304 static void give_switch
PARAMS ((int, int, int));
305 static int used_arg
PARAMS ((const char *, int));
306 static int default_arg
PARAMS ((const char *, int));
307 static void set_multilib_dir
PARAMS ((void));
308 static void print_multilib_info
PARAMS ((void));
309 static void perror_with_name
PARAMS ((const char *));
310 static void pfatal_pexecute
PARAMS ((const char *, const char *))
312 static void notice
PARAMS ((const char *, ...))
314 static void display_help
PARAMS ((void));
315 static void add_preprocessor_option
PARAMS ((const char *, int));
316 static void add_assembler_option
PARAMS ((const char *, int));
317 static void add_linker_option
PARAMS ((const char *, int));
318 static void process_command
PARAMS ((int, const char *const *));
319 static int execute
PARAMS ((void));
320 static void clear_args
PARAMS ((void));
321 static void fatal_error
PARAMS ((int));
322 #ifdef ENABLE_SHARED_LIBGCC
323 static void init_gcc_specs
PARAMS ((struct obstack
*,
324 const char *, const char *,
327 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
328 static const char *convert_filename
PARAMS ((const char *, int, int));
331 /* The Specs Language
333 Specs are strings containing lines, each of which (if not blank)
334 is made up of a program name, and arguments separated by spaces.
335 The program name must be exact and start from root, since no path
336 is searched and it is unreliable to depend on the current working directory.
337 Redirection of input or output is not supported; the subprograms must
338 accept filenames saying what files to read and write.
340 In addition, the specs can contain %-sequences to substitute variable text
341 or for conditional text. Here is a table of all defined %-sequences.
342 Note that spaces are not generated automatically around the results of
343 expanding these sequences; therefore, you can concatenate them together
344 or with constant text in a single argument.
346 %% substitute one % into the program name or argument.
347 %i substitute the name of the input file being processed.
348 %b substitute the basename of the input file being processed.
349 This is the substring up to (and not including) the last period
350 and not including the directory.
351 %B same as %b, but include the file suffix (text after the last period).
353 substitute a file name that has suffix SUFFIX and is chosen
354 once per compilation, and mark the argument a la %d. To reduce
355 exposure to denial-of-service attacks, the file name is now
356 chosen in a way that is hard to predict even when previously
357 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
358 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
359 the regexp "[.A-Za-z]*%O"; "%O" is treated exactly as if it
360 had been pre-processed. Previously, %g was simply substituted
361 with a file name chosen once per compilation, without regard
362 to any appended suffix (which was therefore treated just like
363 ordinary text), making such attacks more likely to succeed.
365 like %g, but generates a new temporary file name even if %uSUFFIX
368 substitutes the last file name generated with %uSUFFIX, generating a
369 new one if there is no such last file name. In the absence of any
370 %uSUFFIX, this is just like %gSUFFIX, except they don't share
371 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
372 would involve the generation of two distinct file names, one
373 for each `%g.s' and another for each `%U.s'. Previously, %U was
374 simply substituted with a file name chosen for the previous %u,
375 without regard to any appended suffix.
377 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
378 writable, and if save-temps is off; otherwise, substitute the name
379 of a temporary file, just like %u. This temporary file is not
380 meant for communication between processes, but rather as a junk
383 substitutes .SUFFIX for the suffixes of a matched switch's args when
384 it is subsequently output with %*. SUFFIX is terminated by the next
386 %d marks the argument containing or following the %d as a
387 temporary file name, so that that file will be deleted if CC exits
388 successfully. Unlike %g, this contributes no text to the argument.
389 %w marks the argument containing or following the %w as the
390 "output file" of this compilation. This puts the argument
391 into the sequence of arguments that %o will substitute later.
393 like %{...} but mark last argument supplied within
394 as a file to be deleted on failure.
395 %o substitutes the names of all the output files, with spaces
396 automatically placed around them. You should write spaces
397 around the %o as well or the results are undefined.
398 %o is for use in the specs for running the linker.
399 Input files whose names have no recognized suffix are not compiled
400 at all, but they are included among the output files, so they will
402 %O substitutes the suffix for object files. Note that this is
403 handled specially when it immediately follows %g, %u, or %U
404 (with or without a suffix argument) because of the need for
405 those to form complete file names. The handling is such that
406 %O is treated exactly as if it had already been substituted,
407 except that %g, %u, and %U do not currently support additional
408 SUFFIX characters following %O as they would following, for
410 %p substitutes the standard macro predefinitions for the
411 current target machine. Use this when running cpp.
412 %P like %p, but puts `__' before and after the name of each macro.
413 (Except macros that already have __.)
415 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
416 %s current argument is the name of a library or startup file of some sort.
417 Search for that file in a standard list of directories
418 and substitute the full name found.
419 %eSTR Print STR as an error message. STR is terminated by a newline.
420 Use this when inconsistent options are detected.
421 %nSTR Print STR as an notice. STR is terminated by a newline.
422 %x{OPTION} Accumulate an option for %X.
423 %X Output the accumulated linker options specified by compilations.
424 %Y Output the accumulated assembler options specified by compilations.
425 %Z Output the accumulated preprocessor options specified by compilations.
426 %v1 Substitute the major version number of GCC.
427 (For version 2.5.3, this is 2.)
428 %v2 Substitute the minor version number of GCC.
429 (For version 2.5.3, this is 5.)
430 %v3 Substitute the patch level number of GCC.
431 (For version 2.5.3, this is 3.)
432 %a process ASM_SPEC as a spec.
433 This allows config.h to specify part of the spec for running as.
434 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
435 used here. This can be used to run a post-processor after the
436 assembler has done its job.
437 %D Dump out a -L option for each directory in startfile_prefixes.
438 If multilib_dir is set, extra entries are generated with it affixed.
439 %l process LINK_SPEC as a spec.
440 %L process LIB_SPEC as a spec.
441 %G process LIBGCC_SPEC as a spec.
442 %M output multilib_dir with directory separators replaced with "_";
443 if multilib_dir is not set or is ".", output "".
444 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
445 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
446 %C process CPP_SPEC as a spec.
447 %1 process CC1_SPEC as a spec.
448 %2 process CC1PLUS_SPEC as a spec.
449 %| output "-" if the input for the current command is coming from a pipe.
450 %* substitute the variable part of a matched option. (See below.)
451 Note that each comma in the substituted string is replaced by
453 %{S} substitutes the -S switch, if that switch was given to CC.
454 If that switch was not specified, this substitutes nothing.
455 Here S is a metasyntactic variable.
456 %{S*} substitutes all the switches specified to CC whose names start
457 with -S. This is used for -o, -I, etc; switches that take
458 arguments. CC considers `-o foo' as being one switch whose
459 name starts with `o'. %{o*} would substitute this text,
460 including the space; thus, two arguments would be generated.
461 %{^S*} likewise, but don't put a blank between a switch and any args.
462 %{S*&T*} likewise, but preserve order of S and T options (the order
463 of S and T in the spec is not significant). Can be any number
464 of ampersand-separated variables; for each the wild card is
465 optional. Useful for CPP as %{D*&U*&A*}.
466 %{S*:X} substitutes X if one or more switches whose names start with -S are
467 specified to CC. Note that the tail part of the -S option
468 (i.e. the part matched by the `*') will be substituted for each
469 occurrence of %* within X.
470 %{<S} remove all occurrences of -S from the command line.
471 Note - this option is position dependent. % commands in the
472 spec string before this option will see -S, % commands in the
473 spec string after this option will not.
474 %{S:X} substitutes X, but only if the -S switch was given to CC.
475 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
476 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
477 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
478 %{.S:X} substitutes X, but only if processing a file with suffix S.
479 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
480 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
481 combined with ! and . as above binding stronger than the OR.
482 %(Spec) processes a specification defined in a specs file as *Spec:
483 %[Spec] as above, but put __ around -D arguments
485 The conditional text X in a %{S:X} or %{!S:X} construct may contain
486 other nested % constructs or spaces, or even newlines. They are
487 processed as usual, as described above.
489 The -O, -f, -m, and -W switches are handled specifically in these
490 constructs. If another value of -O or the negated form of a -f, -m, or
491 -W switch is found later in the command line, the earlier switch
492 value is ignored, except with {S*} where S is just one letter; this
493 passes all matching options.
495 The character | at the beginning of the predicate text is used to indicate
496 that a command should be piped to the following command, but only if -pipe
499 Note that it is built into CC which switches take arguments and which
500 do not. You might think it would be useful to generalize this to
501 allow each compiler's spec to say which switches take arguments. But
502 this cannot be done in a consistent fashion. CC cannot even decide
503 which input files have been specified without knowing which switches
504 take arguments, and it must know which input files to compile in order
505 to tell which compilers to run.
507 CC also knows implicitly that arguments starting in `-l' are to be
508 treated as compiler output files, and passed to the linker in their
509 proper position among the other output files. */
511 /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
513 /* config.h can define ASM_SPEC to provide extra args to the assembler
514 or extra switch-translations. */
519 /* config.h can define ASM_FINAL_SPEC to run a post processor after
520 the assembler has run. */
521 #ifndef ASM_FINAL_SPEC
522 #define ASM_FINAL_SPEC ""
525 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
526 or extra switch-translations. */
531 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
532 or extra switch-translations. */
537 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
538 or extra switch-translations. */
540 #define CC1PLUS_SPEC ""
543 /* config.h can define LINK_SPEC to provide extra args to the linker
544 or extra switch-translations. */
549 /* config.h can define LIB_SPEC to override the default libraries. */
551 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
554 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
557 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
558 /* Have gcc do the search for libgcc.a. */
559 #define LIBGCC_SPEC "libgcc.a%s"
561 #define LIBGCC_SPEC "-lgcc"
565 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
566 #ifndef STARTFILE_SPEC
567 #define STARTFILE_SPEC \
568 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
571 /* config.h can define SWITCHES_NEED_SPACES to control which options
572 require spaces between the option and the argument. */
573 #ifndef SWITCHES_NEED_SPACES
574 #define SWITCHES_NEED_SPACES ""
577 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
579 #define ENDFILE_SPEC ""
583 #define LINKER_NAME "collect2"
586 /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
588 #ifndef ASM_DEBUG_SPEC
589 # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
590 && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
591 # define ASM_DEBUG_SPEC \
592 (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
593 ? "%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}" \
594 : "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}")
596 # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
597 # define ASM_DEBUG_SPEC "%{g*:--gstabs}"
599 # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
600 # define ASM_DEBUG_SPEC "%{g*:--gdwarf2}"
604 #ifndef ASM_DEBUG_SPEC
605 # define ASM_DEBUG_SPEC ""
608 /* Here is the spec for running the linker, after compiling all files. */
610 /* This is overridable by the target in case they need to specify the
611 -lgcc and -lc order specially, yet not require them to override all
612 of LINK_COMMAND_SPEC. */
613 #ifndef LINK_GCC_C_SEQUENCE_SPEC
614 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
617 /* -u* was put back because both BSD and SysV seem to support it. */
618 /* %{static:} simply prevents an error message if the target machine
619 doesn't handle -static. */
620 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
621 scripts which exist in user specified directories, or in standard
623 #ifndef LINK_COMMAND_SPEC
624 #define LINK_COMMAND_SPEC "\
625 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
626 %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
627 %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
628 %{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
629 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
632 #ifndef LINK_LIBGCC_SPEC
633 # ifdef LINK_LIBGCC_SPECIAL
634 /* Don't generate -L options for startfile prefix list. */
635 # define LINK_LIBGCC_SPEC ""
637 /* Do generate them. */
638 # define LINK_LIBGCC_SPEC "%D"
642 #ifndef STARTFILE_PREFIX_SPEC
643 # define STARTFILE_PREFIX_SPEC ""
646 static const char *asm_debug
;
647 static const char *cpp_spec
= CPP_SPEC
;
648 static const char *cpp_predefines
= CPP_PREDEFINES
;
649 static const char *cc1_spec
= CC1_SPEC
;
650 static const char *cc1plus_spec
= CC1PLUS_SPEC
;
651 static const char *link_gcc_c_sequence_spec
= LINK_GCC_C_SEQUENCE_SPEC
;
652 static const char *asm_spec
= ASM_SPEC
;
653 static const char *asm_final_spec
= ASM_FINAL_SPEC
;
654 static const char *link_spec
= LINK_SPEC
;
655 static const char *lib_spec
= LIB_SPEC
;
656 static const char *libgcc_spec
= LIBGCC_SPEC
;
657 static const char *endfile_spec
= ENDFILE_SPEC
;
658 static const char *startfile_spec
= STARTFILE_SPEC
;
659 static const char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
660 static const char *linker_name_spec
= LINKER_NAME
;
661 static const char *link_command_spec
= LINK_COMMAND_SPEC
;
662 static const char *link_libgcc_spec
= LINK_LIBGCC_SPEC
;
663 static const char *startfile_prefix_spec
= STARTFILE_PREFIX_SPEC
;
665 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
666 There should be no need to override these in target dependent files,
667 but we need to copy them to the specs file so that newer versions
668 of the GCC driver can correctly drive older tool chains with the
669 appropriate -B options. */
671 /* When cpplib handles traditional preprocessing, get rid of this, and
672 call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
673 that we default the front end language better. */
674 static const char *trad_capable_cpp
=
675 "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}";
677 /* We don't wrap .d files in %W{} since a missing .d file, and
678 therefore no dependency entry, confuses make into thinking a .o
679 file that happens to exist is up-to-date. */
680 static const char *cpp_unique_options
=
681 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
682 %{CC:%{!E:%eGNU C does not support -CC without using -E}}\
683 %{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*} %{P} %I\
684 %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
685 %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
686 %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
687 %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\
688 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
689 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
690 %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
693 /* This contains cpp options which are common with cc1_options and are passed
694 only when preprocessing only to avoid duplication. We pass the cc1 spec
695 options to the preprocessor so that it the cc1 spec may manipulate
696 options used to set target flags. Those special target flags settings may
697 in turn cause preprocessor symbols to be defined specially. */
698 static const char *cpp_options
=
699 "%(cpp_unique_options) %1 %{m*} %{std*} %{ansi} %{W*&pedantic*} %{w} %{f*}\
702 /* This contains cpp options which are not passed when the preprocessor
703 output will be used by another program. */
704 static const char *cpp_debug_options
= "%{d*}";
706 /* NB: This is shared amongst all front-ends. */
707 static const char *cc1_options
=
708 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
709 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
710 -auxbase%{c|S:%{o*:-strip %*}%{!o*: %b}}%{!c:%{!S: %b}}\
711 %{g*} %{O*} %{W*&pedantic*} %{w} %{std*} %{ansi}\
712 %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
713 %{Qn:-fno-ident} %{--help:--help}\
714 %{--target-help:--target-help}\
715 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
716 %{fsyntax-only:-o %j} %{-param*}";
718 static const char *asm_options
=
719 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
721 static const char *invoke_as
=
722 "%{!S:-o %{|!pipe:%g.s} |\n as %(asm_options) %{!pipe:%g.s} %A }";
724 /* Some compilers have limits on line lengths, and the multilib_select
725 and/or multilib_matches strings can be very long, so we build them at
727 static struct obstack multilib_obstack
;
728 static const char *multilib_select
;
729 static const char *multilib_matches
;
730 static const char *multilib_defaults
;
731 static const char *multilib_exclusions
;
732 #include "multilib.h"
734 /* Check whether a particular argument is a default argument. */
736 #ifndef MULTILIB_DEFAULTS
737 #define MULTILIB_DEFAULTS { "" }
740 static const char *const multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
742 #ifndef DRIVER_SELF_SPECS
743 #define DRIVER_SELF_SPECS ""
746 static const char *const driver_self_specs
[] = { DRIVER_SELF_SPECS
};
750 struct user_specs
*next
;
751 const char *filename
;
754 static struct user_specs
*user_specs_head
, *user_specs_tail
;
756 /* This defines which switch letters take arguments. */
758 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
759 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
760 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
761 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
762 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'B' || (CHAR) == 'b')
764 #ifndef SWITCH_TAKES_ARG
765 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
768 /* This defines which multi-letter switches take arguments. */
770 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
771 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
772 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
773 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
774 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
775 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
776 || !strcmp (STR, "isystem") || !strcmp (STR, "-param") \
777 || !strcmp (STR, "specs") \
778 || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
780 #ifndef WORD_SWITCH_TAKES_ARG
781 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
784 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
785 /* This defines which switches stop a full compilation. */
786 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
787 ((CHAR) == 'c' || (CHAR) == 'S')
789 #ifndef SWITCH_CURTAILS_COMPILATION
790 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
791 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
795 /* Record the mapping from file suffixes for compilation specs. */
799 const char *suffix
; /* Use this compiler for input files
800 whose names end in this suffix. */
802 const char *spec
; /* To use this compiler, run this spec. */
804 const char *cpp_spec
; /* If non-NULL, substitute this spec
805 for `%C', rather than the usual
809 /* Pointer to a vector of `struct compiler' that gives the spec for
810 compiling a file, based on its suffix.
811 A file that does not end in any of these suffixes will be passed
812 unchanged to the loader and nothing else will be done to it.
814 An entry containing two 0s is used to terminate the vector.
816 If multiple entries match a file, the last matching one is used. */
818 static struct compiler
*compilers
;
820 /* Number of entries in `compilers', not counting the null terminator. */
822 static int n_compilers
;
824 /* The default list of file name suffixes and their compilation specs. */
826 static const struct compiler default_compilers
[] =
828 /* Add lists of suffixes of known languages here. If those languages
829 were not present when we built the driver, we will hit these copies
830 and be given a more meaningful error than "file not used since
831 linking is not done". */
832 {".m", "#Objective-C", 0}, {".mi", "#Objective-C", 0},
833 {".cc", "#C++", 0}, {".cxx", "#C++", 0}, {".cpp", "#C++", 0},
834 {".cp", "#C++", 0}, {".c++", "#C++", 0}, {".C", "#C++", 0},
836 {".ads", "#Ada", 0}, {".adb", "#Ada", 0},
837 {".f", "#Fortran", 0}, {".for", "#Fortran", 0}, {".fpp", "#Fortran", 0},
838 {".F", "#Fortran", 0}, {".FOR", "#Fortran", 0}, {".FPP", "#Fortran", 0},
839 {".r", "#Ratfor", 0},
840 {".p", "#Pascal", 0}, {".pas", "#Pascal", 0},
841 {".java", "#Java", 0}, {".class", "#Java", 0},
842 {".zip", "#Java", 0}, {".jar", "#Java", 0},
843 /* Next come the entries for C. */
846 /* cc1 has an integrated ISO C preprocessor. We should invoke the
847 external preprocessor if -save-temps is given. */
848 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
850 %{traditional|ftraditional:\
851 %eGNU C no longer supports -traditional without -E}\
852 %{save-temps|traditional-cpp:%(trad_capable_cpp) \
853 %(cpp_options) %b.i \n\
854 cc1 -fpreprocessed %b.i %(cc1_options)}\
855 %{!save-temps:%{!traditional-cpp:\
856 cc1 %(cpp_unique_options) %(cc1_options)}}\
857 %{!fsyntax-only:%(invoke_as)}}}}", 0},
859 "%{!E:%e-E required when input is from standard input}\
860 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0},
861 {".h", "@c-header", 0},
863 "%{!E:%ecompilation of header file requested} \
864 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)",
866 {".i", "@cpp-output", 0},
868 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0},
869 {".s", "@assembler", 0},
871 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0},
872 {".S", "@assembler-with-cpp", 0},
873 {"@assembler-with-cpp",
874 "%(trad_capable_cpp) -lang-asm %(cpp_options)\
875 %{E|M|MM:%(cpp_debug_options)}\
876 %{!M:%{!MM:%{!E:%{!S:-o %{|!pipe:%g.s} |\n\
877 as %(asm_debug) %(asm_options) %{!pipe:%g.s} %A }}}}", 0},
879 /* Mark end of table */
883 /* Number of elements in default_compilers, not counting the terminator. */
885 static const int n_default_compilers
= ARRAY_SIZE (default_compilers
) - 1;
887 /* A vector of options to give to the linker.
888 These options are accumulated by %x,
889 and substituted into the linker command with %X. */
890 static int n_linker_options
;
891 static char **linker_options
;
893 /* A vector of options to give to the assembler.
894 These options are accumulated by -Wa,
895 and substituted into the assembler command with %Y. */
896 static int n_assembler_options
;
897 static char **assembler_options
;
899 /* A vector of options to give to the preprocessor.
900 These options are accumulated by -Wp,
901 and substituted into the preprocessor command with %Z. */
902 static int n_preprocessor_options
;
903 static char **preprocessor_options
;
905 /* Define how to map long options into short ones. */
907 /* This structure describes one mapping. */
910 /* The long option's name. */
911 const char *const name
;
912 /* The equivalent short option. */
913 const char *const equivalent
;
914 /* Argument info. A string of flag chars; NULL equals no options.
915 a => argument required.
916 o => argument optional.
917 j => join argument to equivalent, making one word.
918 * => require other text after NAME as an argument. */
919 const char *const arg_info
;
922 /* This is the table of mappings. Mappings are tried sequentially
923 for each option encountered; the first one that matches, wins. */
925 static const struct option_map option_map
[] =
927 {"--all-warnings", "-Wall", 0},
928 {"--ansi", "-ansi", 0},
929 {"--assemble", "-S", 0},
930 {"--assert", "-A", "a"},
931 {"--classpath", "-fclasspath=", "aj"},
932 {"--bootclasspath", "-fbootclasspath=", "aj"},
933 {"--CLASSPATH", "-fclasspath=", "aj"},
934 {"--comments", "-C", 0},
935 {"--comments-in-macros", "-CC", 0},
936 {"--compile", "-c", 0},
937 {"--debug", "-g", "oj"},
938 {"--define-macro", "-D", "aj"},
939 {"--dependencies", "-M", 0},
940 {"--dump", "-d", "a"},
941 {"--dumpbase", "-dumpbase", "a"},
942 {"--entry", "-e", 0},
943 {"--extra-warnings", "-W", 0},
944 {"--for-assembler", "-Wa", "a"},
945 {"--for-linker", "-Xlinker", "a"},
946 {"--force-link", "-u", "a"},
947 {"--imacros", "-imacros", "a"},
948 {"--include", "-include", "a"},
949 {"--include-barrier", "-I-", 0},
950 {"--include-directory", "-I", "aj"},
951 {"--include-directory-after", "-idirafter", "a"},
952 {"--include-prefix", "-iprefix", "a"},
953 {"--include-with-prefix", "-iwithprefix", "a"},
954 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
955 {"--include-with-prefix-after", "-iwithprefix", "a"},
956 {"--language", "-x", "a"},
957 {"--library-directory", "-L", "a"},
958 {"--machine", "-m", "aj"},
959 {"--machine-", "-m", "*j"},
960 {"--no-line-commands", "-P", 0},
961 {"--no-precompiled-includes", "-noprecomp", 0},
962 {"--no-standard-includes", "-nostdinc", 0},
963 {"--no-standard-libraries", "-nostdlib", 0},
964 {"--no-warnings", "-w", 0},
965 {"--optimize", "-O", "oj"},
966 {"--output", "-o", "a"},
967 {"--output-class-directory", "-foutput-class-dir=", "ja"},
968 {"--param", "--param", "a"},
969 {"--pedantic", "-pedantic", 0},
970 {"--pedantic-errors", "-pedantic-errors", 0},
971 {"--pipe", "-pipe", 0},
972 {"--prefix", "-B", "a"},
973 {"--preprocess", "-E", 0},
974 {"--print-search-dirs", "-print-search-dirs", 0},
975 {"--print-file-name", "-print-file-name=", "aj"},
976 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
977 {"--print-missing-file-dependencies", "-MG", 0},
978 {"--print-multi-lib", "-print-multi-lib", 0},
979 {"--print-multi-directory", "-print-multi-directory", 0},
980 {"--print-multi-os-directory", "-print-multi-os-directory", 0},
981 {"--print-prog-name", "-print-prog-name=", "aj"},
982 {"--profile", "-p", 0},
983 {"--profile-blocks", "-a", 0},
984 {"--quiet", "-q", 0},
985 {"--resource", "-fcompile-resource=", "aj"},
986 {"--save-temps", "-save-temps", 0},
987 {"--shared", "-shared", 0},
988 {"--silent", "-q", 0},
989 {"--specs", "-specs=", "aj"},
990 {"--static", "-static", 0},
991 {"--std", "-std=", "aj"},
992 {"--symbolic", "-symbolic", 0},
993 {"--target", "-b", "a"},
994 {"--time", "-time", 0},
995 {"--trace-includes", "-H", 0},
996 {"--traditional", "-traditional", 0},
997 {"--traditional-cpp", "-traditional-cpp", 0},
998 {"--trigraphs", "-trigraphs", 0},
999 {"--undefine-macro", "-U", "aj"},
1000 {"--use-version", "-V", "a"},
1001 {"--user-dependencies", "-MM", 0},
1002 {"--verbose", "-v", 0},
1003 {"--warn-", "-W", "*j"},
1004 {"--write-dependencies", "-MD", 0},
1005 {"--write-user-dependencies", "-MMD", 0},
1010 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1011 static const struct {
1012 const char *const option_found
;
1013 const char *const replacements
;
1014 } target_option_translations
[] =
1016 TARGET_OPTION_TRANSLATE_TABLE
,
1021 /* Translate the options described by *ARGCP and *ARGVP.
1022 Make a new vector and store it back in *ARGVP,
1023 and store its length in *ARGVC. */
1026 translate_options (argcp
, argvp
)
1028 const char *const **argvp
;
1032 const char *const *argv
= *argvp
;
1033 int newvsize
= (argc
+ 2) * 2 * sizeof (const char *);
1035 (const char **) xmalloc (newvsize
);
1039 newv
[newindex
++] = argv
[i
++];
1043 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1047 target_option_translations
[tott_idx
].option_found
;
1050 if (strcmp (target_option_translations
[tott_idx
].option_found
,
1057 for (sp
= target_option_translations
[tott_idx
].replacements
;
1064 newvsize
+= spaces
* sizeof (const char *);
1065 newv
= (const char **) xrealloc (newv
, newvsize
);
1067 sp
= target_option_translations
[tott_idx
].replacements
;
1076 newv
[newindex
++] = np
;
1077 while (*np
!= ' ' && *np
)
1088 if (target_option_translations
[tott_idx
].option_found
)
1092 /* Translate -- options. */
1093 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
1096 /* Find a mapping that applies to this option. */
1097 for (j
= 0; j
< ARRAY_SIZE (option_map
); j
++)
1099 size_t optlen
= strlen (option_map
[j
].name
);
1100 size_t arglen
= strlen (argv
[i
]);
1101 size_t complen
= arglen
> optlen
? optlen
: arglen
;
1102 const char *arginfo
= option_map
[j
].arg_info
;
1107 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
1109 const char *arg
= 0;
1111 if (arglen
< optlen
)
1114 for (k
= j
+ 1; k
< ARRAY_SIZE (option_map
); k
++)
1115 if (strlen (option_map
[k
].name
) >= arglen
1116 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
1118 error ("ambiguous abbreviation %s", argv
[i
]);
1122 if (k
!= ARRAY_SIZE (option_map
))
1126 if (arglen
> optlen
)
1128 /* If the option has an argument, accept that. */
1129 if (argv
[i
][optlen
] == '=')
1130 arg
= argv
[i
] + optlen
+ 1;
1132 /* If this mapping requires extra text at end of name,
1133 accept that as "argument". */
1134 else if (strchr (arginfo
, '*') != 0)
1135 arg
= argv
[i
] + optlen
;
1137 /* Otherwise, extra text at end means mismatch.
1138 Try other mappings. */
1143 else if (strchr (arginfo
, '*') != 0)
1145 error ("incomplete `%s' option", option_map
[j
].name
);
1149 /* Handle arguments. */
1150 if (strchr (arginfo
, 'a') != 0)
1156 error ("missing argument to `%s' option",
1157 option_map
[j
].name
);
1164 else if (strchr (arginfo
, '*') != 0)
1166 else if (strchr (arginfo
, 'o') == 0)
1169 error ("extraneous argument to `%s' option",
1170 option_map
[j
].name
);
1174 /* Store the translation as one argv elt or as two. */
1175 if (arg
!= 0 && strchr (arginfo
, 'j') != 0)
1176 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
1180 newv
[newindex
++] = option_map
[j
].equivalent
;
1181 newv
[newindex
++] = arg
;
1184 newv
[newindex
++] = option_map
[j
].equivalent
;
1192 /* Handle old-fashioned options--just copy them through,
1193 with their arguments. */
1194 else if (argv
[i
][0] == '-')
1196 const char *p
= argv
[i
] + 1;
1200 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1201 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1202 else if (WORD_SWITCH_TAKES_ARG (p
))
1203 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
1204 else if ((c
== 'B' || c
== 'b' || c
== 'x')
1207 else if (! strcmp (p
, "Xlinker"))
1210 /* Watch out for an option at the end of the command line that
1211 is missing arguments, and avoid skipping past the end of the
1213 if (nskip
+ i
> argc
)
1218 newv
[newindex
++] = argv
[i
++];
1223 /* Ordinary operands, or +e options. */
1224 newv
[newindex
++] = argv
[i
++];
1239 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1240 be considered whitespace. */
1241 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1243 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1257 /* Structures to keep track of prefixes to try when looking for files. */
1261 const char *prefix
; /* String to prepend to the path. */
1262 struct prefix_list
*next
; /* Next in linked list. */
1263 int require_machine_suffix
; /* Don't use without machine_suffix. */
1264 /* 2 means try both machine_suffix and just_machine_suffix. */
1265 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1266 int priority
; /* Sort key - priority within list. */
1267 int os_multilib
; /* 1 if OS multilib scheme should be used,
1268 0 for GCC multilib scheme. */
1273 struct prefix_list
*plist
; /* List of prefixes to try */
1274 int max_len
; /* Max length of a prefix in PLIST */
1275 const char *name
; /* Name of this list (used in config stuff) */
1278 /* List of prefixes to try when looking for executables. */
1280 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1282 /* List of prefixes to try when looking for startup (crt0) files. */
1284 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1286 /* List of prefixes to try when looking for include files. */
1288 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1290 /* Suffix to attach to directories searched for commands.
1291 This looks like `MACHINE/VERSION/'. */
1293 static const char *machine_suffix
= 0;
1295 /* Suffix to attach to directories searched for commands.
1296 This is just `MACHINE/'. */
1298 static const char *just_machine_suffix
= 0;
1300 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1302 static const char *gcc_exec_prefix
;
1304 /* Default prefixes to attach to command names. */
1306 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1307 #undef MD_EXEC_PREFIX
1308 #undef MD_STARTFILE_PREFIX
1309 #undef MD_STARTFILE_PREFIX_1
1312 /* If no prefixes defined, use the null string, which will disable them. */
1313 #ifndef MD_EXEC_PREFIX
1314 #define MD_EXEC_PREFIX ""
1316 #ifndef MD_STARTFILE_PREFIX
1317 #define MD_STARTFILE_PREFIX ""
1319 #ifndef MD_STARTFILE_PREFIX_1
1320 #define MD_STARTFILE_PREFIX_1 ""
1323 /* Supply defaults for the standard prefixes. */
1325 #ifndef STANDARD_EXEC_PREFIX
1326 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1328 #ifndef STANDARD_STARTFILE_PREFIX
1329 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1331 #ifndef TOOLDIR_BASE_PREFIX
1332 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1334 #ifndef STANDARD_BINDIR_PREFIX
1335 #define STANDARD_BINDIR_PREFIX "/usr/local/bin"
1338 static const char *const standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1339 static const char *const standard_exec_prefix_1
= "/usr/lib/gcc/";
1340 static const char *md_exec_prefix
= MD_EXEC_PREFIX
;
1342 static const char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1343 static const char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1344 static const char *const standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1345 static const char *const standard_startfile_prefix_1
= "/lib/";
1346 static const char *const standard_startfile_prefix_2
= "/usr/lib/";
1348 static const char *const tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1349 static const char *tooldir_prefix
;
1351 static const char *const standard_bindir_prefix
= STANDARD_BINDIR_PREFIX
;
1353 /* Subdirectory to use for locating libraries. Set by
1354 set_multilib_dir based on the compilation options. */
1356 static const char *multilib_dir
;
1358 /* Subdirectory to use for locating libraries in OS conventions. Set by
1359 set_multilib_dir based on the compilation options. */
1361 static const char *multilib_os_dir
;
1363 /* Structure to keep track of the specs that have been defined so far.
1364 These are accessed using %(specname) or %[specname] in a compiler
1369 /* The following 2 fields must be first */
1370 /* to allow EXTRA_SPECS to be initialized */
1371 const char *name
; /* name of the spec. */
1372 const char *ptr
; /* available ptr if no static pointer */
1374 /* The following fields are not initialized */
1375 /* by EXTRA_SPECS */
1376 const char **ptr_spec
; /* pointer to the spec itself. */
1377 struct spec_list
*next
; /* Next spec in linked list. */
1378 int name_len
; /* length of the name */
1379 int alloc_p
; /* whether string was allocated */
1382 #define INIT_STATIC_SPEC(NAME,PTR) \
1383 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1385 /* List of statically defined specs. */
1386 static struct spec_list static_specs
[] =
1388 INIT_STATIC_SPEC ("asm", &asm_spec
),
1389 INIT_STATIC_SPEC ("asm_debug", &asm_debug
),
1390 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1391 INIT_STATIC_SPEC ("asm_options", &asm_options
),
1392 INIT_STATIC_SPEC ("invoke_as", &invoke_as
),
1393 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1394 INIT_STATIC_SPEC ("cpp_options", &cpp_options
),
1395 INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options
),
1396 INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options
),
1397 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp
),
1398 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1399 INIT_STATIC_SPEC ("cc1_options", &cc1_options
),
1400 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1401 INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec
),
1402 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1403 INIT_STATIC_SPEC ("link", &link_spec
),
1404 INIT_STATIC_SPEC ("lib", &lib_spec
),
1405 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1406 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1407 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces
),
1408 INIT_STATIC_SPEC ("predefines", &cpp_predefines
),
1409 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1410 INIT_STATIC_SPEC ("version", &compiler_version
),
1411 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1412 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1413 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1414 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1415 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions
),
1416 INIT_STATIC_SPEC ("multilib_options", &multilib_options
),
1417 INIT_STATIC_SPEC ("linker", &linker_name_spec
),
1418 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec
),
1419 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix
),
1420 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix
),
1421 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1
),
1422 INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec
),
1425 #ifdef EXTRA_SPECS /* additional specs needed */
1426 /* Structure to keep track of just the first two args of a spec_list.
1427 That is all that the EXTRA_SPECS macro gives us. */
1430 const char *const name
;
1431 const char *const ptr
;
1434 static const struct spec_list_1 extra_specs_1
[] = { EXTRA_SPECS
};
1435 static struct spec_list
*extra_specs
= (struct spec_list
*) 0;
1438 /* List of dynamically allocates specs that have been defined so far. */
1440 static struct spec_list
*specs
= (struct spec_list
*) 0;
1442 /* Add appropriate libgcc specs to OBSTACK, taking into account
1443 various permutations of -shared-libgcc, -shared, and such. */
1445 #ifdef ENABLE_SHARED_LIBGCC
1447 init_gcc_specs (obstack
, shared_name
, static_name
, eh_name
)
1448 struct obstack
*obstack
;
1449 const char *shared_name
;
1450 const char *static_name
;
1451 const char *eh_name
;
1455 buf
= concat ("%{static|static-libgcc:", static_name
, " ", eh_name
,
1456 "}%{!static:%{!static-libgcc:",
1457 "%{!shared:%{!shared-libgcc:", static_name
, " ",
1458 eh_name
, "}%{shared-libgcc:", shared_name
, " ",
1459 static_name
, "}}%{shared:",
1461 "%{shared-libgcc:", shared_name
,
1462 "}%{!shared-libgcc:", static_name
, "}",
1468 obstack_grow (obstack
, buf
, strlen (buf
));
1471 #endif /* ENABLE_SHARED_LIBGCC */
1473 /* Initialize the specs lookup routines. */
1478 struct spec_list
*next
= (struct spec_list
*) 0;
1479 struct spec_list
*sl
= (struct spec_list
*) 0;
1483 return; /* Already initialized. */
1486 notice ("Using built-in specs.\n");
1489 extra_specs
= (struct spec_list
*)
1490 xcalloc (sizeof (struct spec_list
), ARRAY_SIZE (extra_specs_1
));
1492 for (i
= ARRAY_SIZE (extra_specs_1
) - 1; i
>= 0; i
--)
1494 sl
= &extra_specs
[i
];
1495 sl
->name
= extra_specs_1
[i
].name
;
1496 sl
->ptr
= extra_specs_1
[i
].ptr
;
1498 sl
->name_len
= strlen (sl
->name
);
1499 sl
->ptr_spec
= &sl
->ptr
;
1504 /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes
1505 on ?: in file-scope variable initializations. */
1506 asm_debug
= ASM_DEBUG_SPEC
;
1508 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1510 sl
= &static_specs
[i
];
1515 #ifdef ENABLE_SHARED_LIBGCC
1516 /* ??? If neither -shared-libgcc nor --static-libgcc was
1517 seen, then we should be making an educated guess. Some proposed
1518 heuristics for ELF include:
1520 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1521 program will be doing dynamic loading, which will likely
1522 need the shared libgcc.
1524 (2) If "-ldl", then it's also a fair bet that we're doing
1527 (3) For each ET_DYN we're linking against (either through -lfoo
1528 or /some/path/foo.so), check to see whether it or one of
1529 its dependencies depends on a shared libgcc.
1533 If the runtime is fixed to look for program headers instead
1534 of calling __register_frame_info at all, for each object,
1535 use the shared libgcc if any EH symbol referenced.
1537 If crtstuff is fixed to not invoke __register_frame_info
1538 automatically, for each object, use the shared libgcc if
1539 any non-empty unwind section found.
1541 Doing any of this probably requires invoking an external program to
1542 do the actual object file scanning. */
1544 const char *p
= libgcc_spec
;
1547 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1548 when given the proper command line arguments. */
1551 if (in_sep
&& *p
== '-' && strncmp (p
, "-lgcc", 5) == 0)
1553 init_gcc_specs (&obstack
,
1554 #ifdef NO_SHARED_LIBGCC_MULTILIB
1565 else if (in_sep
&& *p
== 'l' && strncmp (p
, "libgcc.a%s", 10) == 0)
1567 /* Ug. We don't know shared library extensions. Hope that
1568 systems that use this form don't do shared libraries. */
1569 init_gcc_specs (&obstack
,
1570 #ifdef NO_SHARED_LIBGCC_MULTILIB
1583 obstack_1grow (&obstack
, *p
);
1584 in_sep
= (*p
== ' ');
1589 obstack_1grow (&obstack
, '\0');
1590 libgcc_spec
= obstack_finish (&obstack
);
1593 #ifdef USE_AS_TRADITIONAL_FORMAT
1594 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1596 static const char tf
[] = "--traditional-format ";
1597 obstack_grow (&obstack
, tf
, sizeof(tf
) - 1);
1598 obstack_grow0 (&obstack
, asm_spec
, strlen (asm_spec
));
1599 asm_spec
= obstack_finish (&obstack
);
1603 /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1604 obstack_grow (&obstack
, LINK_EH_SPEC
, sizeof(LINK_EH_SPEC
) - 1);
1605 obstack_grow0 (&obstack
, link_spec
, strlen (link_spec
));
1606 link_spec
= obstack_finish (&obstack
);
1612 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1613 removed; If the spec starts with a + then SPEC is added to the end of the
1617 set_spec (name
, spec
)
1621 struct spec_list
*sl
;
1622 const char *old_spec
;
1623 int name_len
= strlen (name
);
1626 /* If this is the first call, initialize the statically allocated specs. */
1629 struct spec_list
*next
= (struct spec_list
*) 0;
1630 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1632 sl
= &static_specs
[i
];
1639 /* See if the spec already exists. */
1640 for (sl
= specs
; sl
; sl
= sl
->next
)
1641 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1646 /* Not found - make it. */
1647 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1648 sl
->name
= xstrdup (name
);
1649 sl
->name_len
= name_len
;
1650 sl
->ptr_spec
= &sl
->ptr
;
1652 *(sl
->ptr_spec
) = "";
1657 old_spec
= *(sl
->ptr_spec
);
1658 *(sl
->ptr_spec
) = ((spec
[0] == '+' && ISSPACE ((unsigned char)spec
[1]))
1659 ? concat (old_spec
, spec
+ 1, NULL
)
1664 notice ("Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1667 /* Free the old spec. */
1668 if (old_spec
&& sl
->alloc_p
)
1669 free ((PTR
) old_spec
);
1674 /* Accumulate a command (program name and args), and run it. */
1676 /* Vector of pointers to arguments in the current line of specifications. */
1678 static const char **argbuf
;
1680 /* Number of elements allocated in argbuf. */
1682 static int argbuf_length
;
1684 /* Number of elements in argbuf currently in use (containing args). */
1686 static int argbuf_index
;
1688 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1689 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1692 static struct temp_name
{
1693 const char *suffix
; /* suffix associated with the code. */
1694 int length
; /* strlen (suffix). */
1695 int unique
; /* Indicates whether %g or %u/%U was used. */
1696 const char *filename
; /* associated filename. */
1697 int filename_length
; /* strlen (filename). */
1698 struct temp_name
*next
;
1701 /* Number of commands executed so far. */
1703 static int execution_count
;
1705 /* Number of commands that exited with a signal. */
1707 static int signal_count
;
1709 /* Name with which this program was invoked. */
1711 static const char *programname
;
1713 /* Clear out the vector of arguments (after a command is executed). */
1721 /* Add one argument to the vector at the end.
1722 This is done when a space is seen or at the end of the line.
1723 If DELETE_ALWAYS is nonzero, the arg is a filename
1724 and the file should be deleted eventually.
1725 If DELETE_FAILURE is nonzero, the arg is a filename
1726 and the file should be deleted if this compilation fails. */
1729 store_arg (arg
, delete_always
, delete_failure
)
1731 int delete_always
, delete_failure
;
1733 if (argbuf_index
+ 1 == argbuf_length
)
1735 = (const char **) xrealloc (argbuf
,
1736 (argbuf_length
*= 2) * sizeof (const char *));
1738 argbuf
[argbuf_index
++] = arg
;
1739 argbuf
[argbuf_index
] = 0;
1741 if (delete_always
|| delete_failure
)
1742 record_temp_file (arg
, delete_always
, delete_failure
);
1745 /* Load specs from a file name named FILENAME, replacing occurrences of
1746 various different types of line-endings, \r\n, \n\r and just \r, with
1750 load_specs (filename
)
1751 const char *filename
;
1755 struct stat statbuf
;
1762 notice ("Reading specs from %s\n", filename
);
1764 /* Open and stat the file. */
1765 desc
= open (filename
, O_RDONLY
, 0);
1767 pfatal_with_name (filename
);
1768 if (stat (filename
, &statbuf
) < 0)
1769 pfatal_with_name (filename
);
1771 /* Read contents of file into BUFFER. */
1772 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1773 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1775 pfatal_with_name (filename
);
1776 buffer
[readlen
] = 0;
1779 specs
= xmalloc (readlen
+ 1);
1781 for (buffer_p
= buffer
; buffer_p
&& *buffer_p
; buffer_p
++)
1787 if (buffer_p
> buffer
&& *(buffer_p
- 1) == '\n') /* \n\r */
1789 else if (*(buffer_p
+ 1) == '\n') /* \r\n */
1803 /* Read compilation specs from a file named FILENAME,
1804 replacing the default ones.
1806 A suffix which starts with `*' is a definition for
1807 one of the machine-specific sub-specs. The "suffix" should be
1808 *asm, *cc1, *cpp, *link, *startfile, etc.
1809 The corresponding spec is stored in asm_spec, etc.,
1810 rather than in the `compilers' vector.
1812 Anything invalid in the file is a fatal error. */
1815 read_specs (filename
, main_p
)
1816 const char *filename
;
1822 buffer
= load_specs (filename
);
1824 /* Scan BUFFER for specs, putting them in the vector. */
1830 char *in
, *out
, *p1
, *p2
, *p3
;
1832 /* Advance P in BUFFER to the next nonblank nocomment line. */
1833 p
= skip_whitespace (p
);
1837 /* Is this a special command that starts with '%'? */
1838 /* Don't allow this for the main specs file, since it would
1839 encourage people to overwrite it. */
1840 if (*p
== '%' && !main_p
)
1843 while (*p
&& *p
!= '\n')
1849 if (!strncmp (p1
, "%include", sizeof ("%include") - 1)
1850 && (p1
[sizeof "%include" - 1] == ' '
1851 || p1
[sizeof "%include" - 1] == '\t'))
1855 p1
+= sizeof ("%include");
1856 while (*p1
== ' ' || *p1
== '\t')
1859 if (*p1
++ != '<' || p
[-2] != '>')
1860 fatal ("specs %%include syntax malformed after %ld characters",
1861 (long) (p1
- buffer
+ 1));
1864 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
, 0);
1865 read_specs (new_filename
? new_filename
: p1
, FALSE
);
1868 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
1869 && (p1
[sizeof "%include_noerr" - 1] == ' '
1870 || p1
[sizeof "%include_noerr" - 1] == '\t'))
1874 p1
+= sizeof "%include_noerr";
1875 while (*p1
== ' ' || *p1
== '\t')
1878 if (*p1
++ != '<' || p
[-2] != '>')
1879 fatal ("specs %%include syntax malformed after %ld characters",
1880 (long) (p1
- buffer
+ 1));
1883 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
, 0);
1885 read_specs (new_filename
, FALSE
);
1886 else if (verbose_flag
)
1887 notice ("could not find specs file %s\n", p1
);
1890 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
1891 && (p1
[sizeof "%rename" - 1] == ' '
1892 || p1
[sizeof "%rename" - 1] == '\t'))
1895 struct spec_list
*sl
;
1896 struct spec_list
*newsl
;
1898 /* Get original name. */
1899 p1
+= sizeof "%rename";
1900 while (*p1
== ' ' || *p1
== '\t')
1903 if (! ISALPHA ((unsigned char) *p1
))
1904 fatal ("specs %%rename syntax malformed after %ld characters",
1905 (long) (p1
- buffer
));
1908 while (*p2
&& !ISSPACE ((unsigned char) *p2
))
1911 if (*p2
!= ' ' && *p2
!= '\t')
1912 fatal ("specs %%rename syntax malformed after %ld characters",
1913 (long) (p2
- buffer
));
1917 while (*p2
== ' ' || *p2
== '\t')
1920 if (! ISALPHA ((unsigned char) *p2
))
1921 fatal ("specs %%rename syntax malformed after %ld characters",
1922 (long) (p2
- buffer
));
1924 /* Get new spec name. */
1926 while (*p3
&& !ISSPACE ((unsigned char) *p3
))
1930 fatal ("specs %%rename syntax malformed after %ld characters",
1931 (long) (p3
- buffer
));
1934 for (sl
= specs
; sl
; sl
= sl
->next
)
1935 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
1939 fatal ("specs %s spec was not found to be renamed", p1
);
1941 if (strcmp (p1
, p2
) == 0)
1944 for (newsl
= specs
; newsl
; newsl
= newsl
->next
)
1945 if (strcmp (newsl
->name
, p2
) == 0)
1946 fatal ("%s: attempt to rename spec '%s' to already defined spec '%s'",
1951 notice ("rename spec %s to %s\n", p1
, p2
);
1953 notice ("spec is '%s'\n\n", *(sl
->ptr_spec
));
1957 set_spec (p2
, *(sl
->ptr_spec
));
1959 free ((PTR
) *(sl
->ptr_spec
));
1961 *(sl
->ptr_spec
) = "";
1966 fatal ("specs unknown %% command after %ld characters",
1967 (long) (p1
- buffer
));
1970 /* Find the colon that should end the suffix. */
1972 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
1975 /* The colon shouldn't be missing. */
1977 fatal ("specs file malformed after %ld characters",
1978 (long) (p1
- buffer
));
1980 /* Skip back over trailing whitespace. */
1982 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
1985 /* Copy the suffix to a string. */
1986 suffix
= save_string (p
, p2
- p
);
1987 /* Find the next line. */
1988 p
= skip_whitespace (p1
+ 1);
1990 fatal ("specs file malformed after %ld characters",
1991 (long) (p
- buffer
));
1994 /* Find next blank line or end of string. */
1995 while (*p1
&& !(*p1
== '\n' && (p1
[1] == '\n' || p1
[1] == '\0')))
1998 /* Specs end at the blank line and do not include the newline. */
1999 spec
= save_string (p
, p1
- p
);
2002 /* Delete backslash-newline sequences from the spec. */
2007 if (in
[0] == '\\' && in
[1] == '\n')
2009 else if (in
[0] == '#')
2010 while (*in
&& *in
!= '\n')
2018 if (suffix
[0] == '*')
2020 if (! strcmp (suffix
, "*link_command"))
2021 link_command_spec
= spec
;
2023 set_spec (suffix
+ 1, spec
);
2027 /* Add this pair to the vector. */
2029 = ((struct compiler
*)
2030 xrealloc (compilers
,
2031 (n_compilers
+ 2) * sizeof (struct compiler
)));
2033 compilers
[n_compilers
].suffix
= suffix
;
2034 compilers
[n_compilers
].spec
= spec
;
2036 memset (&compilers
[n_compilers
], 0, sizeof compilers
[n_compilers
]);
2040 link_command_spec
= spec
;
2043 if (link_command_spec
== 0)
2044 fatal ("spec file has no spec for linking");
2047 /* Record the names of temporary files we tell compilers to write,
2048 and delete them at the end of the run. */
2050 /* This is the common prefix we use to make temp file names.
2051 It is chosen once for each run of this program.
2052 It is substituted into a spec by %g or %j.
2053 Thus, all temp file names contain this prefix.
2054 In practice, all temp file names start with this prefix.
2056 This prefix comes from the envvar TMPDIR if it is defined;
2057 otherwise, from the P_tmpdir macro if that is defined;
2058 otherwise, in /usr/tmp or /tmp;
2059 or finally the current directory if all else fails. */
2061 static const char *temp_filename
;
2063 /* Length of the prefix. */
2065 static int temp_filename_length
;
2067 /* Define the list of temporary files to delete. */
2072 struct temp_file
*next
;
2075 /* Queue of files to delete on success or failure of compilation. */
2076 static struct temp_file
*always_delete_queue
;
2077 /* Queue of files to delete on failure of compilation. */
2078 static struct temp_file
*failure_delete_queue
;
2080 /* Record FILENAME as a file to be deleted automatically.
2081 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2082 otherwise delete it in any case.
2083 FAIL_DELETE nonzero means delete it if a compilation step fails;
2084 otherwise delete it in any case. */
2087 record_temp_file (filename
, always_delete
, fail_delete
)
2088 const char *filename
;
2092 char *const name
= xstrdup (filename
);
2096 struct temp_file
*temp
;
2097 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2098 if (! strcmp (name
, temp
->name
))
2101 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
2102 temp
->next
= always_delete_queue
;
2104 always_delete_queue
= temp
;
2111 struct temp_file
*temp
;
2112 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2113 if (! strcmp (name
, temp
->name
))
2116 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
2117 temp
->next
= failure_delete_queue
;
2119 failure_delete_queue
= temp
;
2125 /* Delete all the temporary files whose names we previously recorded. */
2128 delete_if_ordinary (name
)
2135 printf ("Delete %s? (y or n) ", name
);
2139 while ((c
= getchar ()) != '\n' && c
!= EOF
)
2142 if (i
== 'y' || i
== 'Y')
2144 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
2145 if (unlink (name
) < 0)
2147 perror_with_name (name
);
2151 delete_temp_files ()
2153 struct temp_file
*temp
;
2155 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2156 delete_if_ordinary (temp
->name
);
2157 always_delete_queue
= 0;
2160 /* Delete all the files to be deleted on error. */
2163 delete_failure_queue ()
2165 struct temp_file
*temp
;
2167 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2168 delete_if_ordinary (temp
->name
);
2172 clear_failure_queue ()
2174 failure_delete_queue
= 0;
2177 /* Build a list of search directories from PATHS.
2178 PREFIX is a string to prepend to the list.
2179 If CHECK_DIR_P is nonzero we ensure the directory exists.
2180 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2181 It is also used by the --print-search-dirs flag. */
2184 build_search_list (paths
, prefix
, check_dir_p
)
2185 struct path_prefix
*paths
;
2189 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
2191 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
2192 int first_time
= TRUE
;
2193 struct prefix_list
*pprefix
;
2195 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
2196 obstack_1grow (&collect_obstack
, '=');
2198 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
2200 int len
= strlen (pprefix
->prefix
);
2204 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
2207 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2210 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2211 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
2214 if (just_machine_suffix
2215 && pprefix
->require_machine_suffix
== 2
2217 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
2220 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2223 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2224 obstack_grow (&collect_obstack
, just_machine_suffix
,
2228 if (! pprefix
->require_machine_suffix
)
2231 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2234 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2238 obstack_1grow (&collect_obstack
, '\0');
2239 return obstack_finish (&collect_obstack
);
2242 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2246 putenv_from_prefixes (paths
, env_var
)
2247 struct path_prefix
*paths
;
2248 const char *env_var
;
2250 putenv (build_search_list (paths
, env_var
, 1));
2255 /* FIXME: the location independence code for VMS is hairier than this,
2256 and hasn't been written. */
2258 /* Split a filename into component directories. */
2261 split_directories (name
, ptr_num_dirs
)
2270 /* Count the number of directories. Special case MSDOS disk names as part
2271 of the initial directory. */
2273 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2274 if (name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2279 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2281 while ((ch
= *p
++) != '\0')
2283 if (IS_DIR_SEPARATOR (ch
))
2286 while (IS_DIR_SEPARATOR (*p
))
2291 dirs
= (char **) xmalloc (sizeof (char *) * (num_dirs
+ 2));
2293 /* Now copy the directory parts. */
2296 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2297 if (name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2299 dirs
[num_dirs
++] = save_string (p
, 3);
2302 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2305 while ((ch
= *p
++) != '\0')
2307 if (IS_DIR_SEPARATOR (ch
))
2309 while (IS_DIR_SEPARATOR (*p
))
2312 dirs
[num_dirs
++] = save_string (q
, p
- q
);
2318 dirs
[num_dirs
++] = save_string (q
, p
- 1 - q
);
2320 dirs
[num_dirs
] = NULL
;
2322 *ptr_num_dirs
= num_dirs
;
2327 /* Release storage held by split directories. */
2330 free_split_directories (dirs
)
2335 while (dirs
[i
] != NULL
)
2338 free ((char *) dirs
);
2341 /* Given three strings PROGNAME, BIN_PREFIX, PREFIX, return a string that gets
2342 to PREFIX starting with the directory portion of PROGNAME and a relative
2343 pathname of the difference between BIN_PREFIX and PREFIX.
2345 For example, if BIN_PREFIX is /alpha/beta/gamma/gcc/delta, PREFIX is
2346 /alpha/beta/gamma/omega/, and PROGNAME is /red/green/blue/gcc, then this
2347 function will return /red/green/blue/../omega.
2349 If no relative prefix can be found, return NULL. */
2352 make_relative_prefix (progname
, bin_prefix
, prefix
)
2353 const char *progname
;
2354 const char *bin_prefix
;
2357 char **prog_dirs
, **bin_dirs
, **prefix_dirs
;
2358 int prog_num
, bin_num
, prefix_num
, std_loc_p
;
2361 prog_dirs
= split_directories (progname
, &prog_num
);
2362 bin_dirs
= split_directories (bin_prefix
, &bin_num
);
2364 /* If there is no full pathname, try to find the program by checking in each
2365 of the directories specified in the PATH environment variable. */
2370 GET_ENVIRONMENT (temp
, "PATH");
2373 char *startp
, *endp
, *nstore
;
2374 size_t prefixlen
= strlen (temp
) + 1;
2378 nstore
= (char *) alloca (prefixlen
+ strlen (progname
) + 1);
2380 startp
= endp
= temp
;
2383 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2388 nstore
[1] = DIR_SEPARATOR
;
2393 strncpy (nstore
, startp
, endp
- startp
);
2394 if (! IS_DIR_SEPARATOR (endp
[-1]))
2396 nstore
[endp
- startp
] = DIR_SEPARATOR
;
2397 nstore
[endp
- startp
+ 1] = 0;
2400 nstore
[endp
- startp
] = 0;
2402 strcat (nstore
, progname
);
2403 if (! access (nstore
, X_OK
)
2404 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
2405 || ! access (strcat (nstore
, HOST_EXECUTABLE_SUFFIX
), X_OK
)
2409 free_split_directories (prog_dirs
);
2411 prog_dirs
= split_directories (progname
, &prog_num
);
2417 endp
= startp
= endp
+ 1;
2425 /* Remove the program name from comparison of directory names. */
2428 /* Determine if the compiler is installed in the standard location, and if
2429 so, we don't need to specify relative directories. Also, if argv[0]
2430 doesn't contain any directory specifiers, there is not much we can do. */
2432 if (prog_num
== bin_num
)
2434 for (i
= 0; i
< bin_num
; i
++)
2436 if (strcmp (prog_dirs
[i
], bin_dirs
[i
]) != 0)
2440 if (prog_num
<= 0 || i
== bin_num
)
2443 free_split_directories (prog_dirs
);
2444 free_split_directories (bin_dirs
);
2445 prog_dirs
= bin_dirs
= (char **) 0;
2450 prefix_dirs
= split_directories (prefix
, &prefix_num
);
2452 /* Find how many directories are in common between bin_prefix & prefix. */
2453 n
= (prefix_num
< bin_num
) ? prefix_num
: bin_num
;
2454 for (common
= 0; common
< n
; common
++)
2456 if (strcmp (bin_dirs
[common
], prefix_dirs
[common
]) != 0)
2460 /* If there are no common directories, there can be no relative prefix. */
2463 free_split_directories (prog_dirs
);
2464 free_split_directories (bin_dirs
);
2465 free_split_directories (prefix_dirs
);
2469 /* Build up the pathnames in argv[0]. */
2470 for (i
= 0; i
< prog_num
; i
++)
2471 obstack_grow (&obstack
, prog_dirs
[i
], strlen (prog_dirs
[i
]));
2473 /* Now build up the ..'s. */
2474 for (i
= common
; i
< n
; i
++)
2476 obstack_grow (&obstack
, DIR_UP
, sizeof (DIR_UP
) - 1);
2477 obstack_1grow (&obstack
, DIR_SEPARATOR
);
2480 /* Put in directories to move over to prefix. */
2481 for (i
= common
; i
< prefix_num
; i
++)
2482 obstack_grow (&obstack
, prefix_dirs
[i
], strlen (prefix_dirs
[i
]));
2484 free_split_directories (prog_dirs
);
2485 free_split_directories (bin_dirs
);
2486 free_split_directories (prefix_dirs
);
2488 obstack_1grow (&obstack
, '\0');
2489 return obstack_finish (&obstack
);
2493 /* Check whether NAME can be accessed in MODE. This is like access,
2494 except that it never considers directories to be executable. */
2497 access_check (name
, mode
)
2505 if (stat (name
, &st
) < 0
2506 || S_ISDIR (st
.st_mode
))
2510 return access (name
, mode
);
2513 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2514 access to check permissions.
2515 Return 0 if not found, otherwise return its name, allocated with malloc. */
2518 find_a_file (pprefix
, name
, mode
, multilib
)
2519 struct path_prefix
*pprefix
;
2524 const char *const file_suffix
=
2525 ((mode
& X_OK
) != 0 ? HOST_EXECUTABLE_SUFFIX
: "");
2526 struct prefix_list
*pl
;
2527 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
2528 const char *multilib_name
, *multilib_os_name
;
2530 #ifdef DEFAULT_ASSEMBLER
2531 if (! strcmp (name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0)
2532 return xstrdup (DEFAULT_ASSEMBLER
);
2535 #ifdef DEFAULT_LINKER
2536 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0)
2537 return xstrdup (DEFAULT_LINKER
);
2541 len
+= strlen (machine_suffix
);
2543 multilib_name
= name
;
2544 multilib_os_name
= name
;
2545 if (multilib
&& multilib_os_dir
)
2547 int len1
= multilib_dir
? strlen (multilib_dir
) + 1 : 0;
2548 int len2
= strlen (multilib_os_dir
) + 1;
2550 len
+= len1
> len2
? len1
: len2
;
2552 multilib_name
= ACONCAT ((multilib_dir
, dir_separator_str
, name
,
2554 if (strcmp (multilib_os_dir
, ".") != 0)
2555 multilib_os_name
= ACONCAT ((multilib_os_dir
, dir_separator_str
, name
,
2559 temp
= xmalloc (len
);
2561 /* Determine the filename to execute (special case for absolute paths). */
2563 if (IS_ABSOLUTE_PATHNAME (name
))
2565 if (access (name
, mode
) == 0)
2567 strcpy (temp
, name
);
2572 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
2574 const char *this_name
2575 = pl
->os_multilib
? multilib_os_name
: multilib_name
;
2579 /* Some systems have a suffix for executable files.
2580 So try appending that first. */
2581 if (file_suffix
[0] != 0)
2583 strcpy (temp
, pl
->prefix
);
2584 strcat (temp
, machine_suffix
);
2585 strcat (temp
, multilib_name
);
2586 strcat (temp
, file_suffix
);
2587 if (access_check (temp
, mode
) == 0)
2589 if (pl
->used_flag_ptr
!= 0)
2590 *pl
->used_flag_ptr
= 1;
2595 /* Now try just the multilib_name. */
2596 strcpy (temp
, pl
->prefix
);
2597 strcat (temp
, machine_suffix
);
2598 strcat (temp
, multilib_name
);
2599 if (access_check (temp
, mode
) == 0)
2601 if (pl
->used_flag_ptr
!= 0)
2602 *pl
->used_flag_ptr
= 1;
2607 /* Certain prefixes are tried with just the machine type,
2608 not the version. This is used for finding as, ld, etc. */
2609 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
2611 /* Some systems have a suffix for executable files.
2612 So try appending that first. */
2613 if (file_suffix
[0] != 0)
2615 strcpy (temp
, pl
->prefix
);
2616 strcat (temp
, just_machine_suffix
);
2617 strcat (temp
, multilib_name
);
2618 strcat (temp
, file_suffix
);
2619 if (access_check (temp
, mode
) == 0)
2621 if (pl
->used_flag_ptr
!= 0)
2622 *pl
->used_flag_ptr
= 1;
2627 strcpy (temp
, pl
->prefix
);
2628 strcat (temp
, just_machine_suffix
);
2629 strcat (temp
, multilib_name
);
2630 if (access_check (temp
, mode
) == 0)
2632 if (pl
->used_flag_ptr
!= 0)
2633 *pl
->used_flag_ptr
= 1;
2638 /* Certain prefixes can't be used without the machine suffix
2639 when the machine or version is explicitly specified. */
2640 if (! pl
->require_machine_suffix
)
2642 /* Some systems have a suffix for executable files.
2643 So try appending that first. */
2644 if (file_suffix
[0] != 0)
2646 strcpy (temp
, pl
->prefix
);
2647 strcat (temp
, this_name
);
2648 strcat (temp
, file_suffix
);
2649 if (access_check (temp
, mode
) == 0)
2651 if (pl
->used_flag_ptr
!= 0)
2652 *pl
->used_flag_ptr
= 1;
2657 strcpy (temp
, pl
->prefix
);
2658 strcat (temp
, this_name
);
2659 if (access_check (temp
, mode
) == 0)
2661 if (pl
->used_flag_ptr
!= 0)
2662 *pl
->used_flag_ptr
= 1;
2672 /* Ranking of prefixes in the sort list. -B prefixes are put before
2675 enum path_prefix_priority
2677 PREFIX_PRIORITY_B_OPT
,
2678 PREFIX_PRIORITY_LAST
2681 /* Add an entry for PREFIX in PLIST. The PLIST is kept in assending
2682 order according to PRIORITY. Within each PRIORITY, new entries are
2685 If WARN is nonzero, we will warn if no file is found
2686 through this prefix. WARN should point to an int
2687 which will be set to 1 if this entry is used.
2689 COMPONENT is the value to be passed to update_path.
2691 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2692 the complete value of machine_suffix.
2693 2 means try both machine_suffix and just_machine_suffix. */
2696 add_prefix (pprefix
, prefix
, component
, priority
, require_machine_suffix
,
2698 struct path_prefix
*pprefix
;
2700 const char *component
;
2701 /* enum prefix_priority */ int priority
;
2702 int require_machine_suffix
;
2706 struct prefix_list
*pl
, **prev
;
2709 for (prev
= &pprefix
->plist
;
2710 (*prev
) != NULL
&& (*prev
)->priority
<= priority
;
2711 prev
= &(*prev
)->next
)
2714 /* Keep track of the longest prefix */
2716 prefix
= update_path (prefix
, component
);
2717 len
= strlen (prefix
);
2718 if (len
> pprefix
->max_len
)
2719 pprefix
->max_len
= len
;
2721 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2722 pl
->prefix
= prefix
;
2723 pl
->require_machine_suffix
= require_machine_suffix
;
2724 pl
->used_flag_ptr
= warn
;
2725 pl
->priority
= priority
;
2726 pl
->os_multilib
= os_multilib
;
2730 /* Insert after PREV */
2735 /* Execute the command specified by the arguments on the current line of spec.
2736 When using pipes, this includes several piped-together commands
2737 with `|' between them.
2739 Return 0 if successful, -1 if failed. */
2745 int n_commands
; /* # of command. */
2749 const char *prog
; /* program name. */
2750 const char **argv
; /* vector of args. */
2751 int pid
; /* pid of process for this command. */
2754 struct command
*commands
; /* each command buffer with above info. */
2756 /* Count # of piped commands. */
2757 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2758 if (strcmp (argbuf
[i
], "|") == 0)
2761 /* Get storage for each command. */
2762 commands
= (struct command
*) alloca (n_commands
* sizeof (struct command
));
2764 /* Split argbuf into its separate piped processes,
2765 and record info about each one.
2766 Also search for the programs that are to be run. */
2768 commands
[0].prog
= argbuf
[0]; /* first command. */
2769 commands
[0].argv
= &argbuf
[0];
2770 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
, 0);
2773 commands
[0].argv
[0] = string
;
2775 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2776 if (strcmp (argbuf
[i
], "|") == 0)
2777 { /* each command. */
2778 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2779 fatal ("-pipe not supported");
2781 argbuf
[i
] = 0; /* termination of command args. */
2782 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2783 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2784 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
,
2787 commands
[n_commands
].argv
[0] = string
;
2791 argbuf
[argbuf_index
] = 0;
2793 /* If -v, print what we are about to do, and maybe query. */
2797 /* For help listings, put a blank line between sub-processes. */
2798 if (print_help_list
)
2799 fputc ('\n', stderr
);
2801 /* Print each piped command as a separate line. */
2802 for (i
= 0; i
< n_commands
; i
++)
2804 const char *const *j
;
2806 if (verbose_only_flag
)
2808 for (j
= commands
[i
].argv
; *j
; j
++)
2811 fprintf (stderr
, " \"");
2812 for (p
= *j
; *p
; ++p
)
2814 if (*p
== '"' || *p
== '\\' || *p
== '$')
2815 fputc ('\\', stderr
);
2818 fputc ('"', stderr
);
2822 for (j
= commands
[i
].argv
; *j
; j
++)
2823 fprintf (stderr
, " %s", *j
);
2825 /* Print a pipe symbol after all but the last command. */
2826 if (i
+ 1 != n_commands
)
2827 fprintf (stderr
, " |");
2828 fprintf (stderr
, "\n");
2831 if (verbose_only_flag
!= 0)
2834 notice ("\nGo ahead? (y or n) ");
2838 while (getchar () != '\n')
2841 if (i
!= 'y' && i
!= 'Y')
2846 /* Run each piped subprocess. */
2848 for (i
= 0; i
< n_commands
; i
++)
2850 char *errmsg_fmt
, *errmsg_arg
;
2851 const char *string
= commands
[i
].argv
[0];
2853 /* For some bizarre reason, the second argument of execvp() is
2854 char *const *, not const char *const *. */
2855 commands
[i
].pid
= pexecute (string
, (char *const *) commands
[i
].argv
,
2856 programname
, temp_filename
,
2857 &errmsg_fmt
, &errmsg_arg
,
2858 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2859 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2860 | (string
== commands
[i
].prog
2861 ? PEXECUTE_SEARCH
: 0)
2862 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2864 if (commands
[i
].pid
== -1)
2865 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2867 if (string
!= commands
[i
].prog
)
2868 free ((PTR
) string
);
2873 /* Wait for all the subprocesses to finish.
2874 We don't care what order they finish in;
2875 we know that N_COMMANDS waits will get them all.
2876 Ignore subprocesses that we don't know about,
2877 since they can be spawned by the process that exec'ed us. */
2881 #ifdef HAVE_GETRUSAGE
2883 double ut
= 0.0, st
= 0.0;
2886 for (i
= 0; i
< n_commands
;)
2892 pid
= pwait (commands
[i
].pid
, &status
, 0);
2896 #ifdef HAVE_GETRUSAGE
2899 /* getrusage returns the total resource usage of all children
2900 up to now. Copy the previous values into prus, get the
2901 current statistics, then take the difference. */
2904 getrusage (RUSAGE_CHILDREN
, &rus
);
2905 d
.tv_sec
= rus
.ru_utime
.tv_sec
- prus
.ru_utime
.tv_sec
;
2906 d
.tv_usec
= rus
.ru_utime
.tv_usec
- prus
.ru_utime
.tv_usec
;
2907 ut
= (double) d
.tv_sec
+ (double) d
.tv_usec
/ 1.0e6
;
2909 d
.tv_sec
= rus
.ru_stime
.tv_sec
- prus
.ru_stime
.tv_sec
;
2910 d
.tv_usec
= rus
.ru_stime
.tv_usec
- prus
.ru_stime
.tv_usec
;
2911 st
= (double) d
.tv_sec
+ (double) d
.tv_usec
/ 1.0e6
;
2915 for (j
= 0; j
< n_commands
; j
++)
2916 if (commands
[j
].pid
== pid
)
2919 if (WIFSIGNALED (status
))
2922 /* SIGPIPE is a special case. It happens in -pipe mode
2923 when the compiler dies before the preprocessor is
2924 done, or the assembler dies before the compiler is
2925 done. There's generally been an error already, and
2926 this is just fallout. So don't generate another error
2927 unless we would otherwise have succeeded. */
2928 if (WTERMSIG (status
) == SIGPIPE
2929 && (signal_count
|| greatest_status
>= MIN_FATAL_STATUS
))
2934 Internal error: %s (program %s)\n\
2935 Please submit a full bug report.\n\
2936 See %s for instructions.",
2937 strsignal (WTERMSIG (status
)), commands
[j
].prog
,
2942 else if (WIFEXITED (status
)
2943 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2945 if (WEXITSTATUS (status
) > greatest_status
)
2946 greatest_status
= WEXITSTATUS (status
);
2949 #ifdef HAVE_GETRUSAGE
2950 if (report_times
&& ut
+ st
!= 0)
2951 notice ("# %s %.2f %.2f\n", commands
[j
].prog
, ut
, st
);
2960 /* Find all the switches given to us
2961 and make a vector describing them.
2962 The elements of the vector are strings, one per switch given.
2963 If a switch uses following arguments, then the `part1' field
2964 is the switch itself and the `args' field
2965 is a null-terminated vector containing the following arguments.
2966 The `live_cond' field is:
2968 1 if the switch is true in a conditional spec,
2969 -1 if false (overridden by a later switch)
2970 -2 if this switch should be ignored (used in %{<S})
2971 The `validated' field is nonzero if any spec has looked at this switch;
2972 if it remains zero at the end of the run, it must be meaningless. */
2975 #define SWITCH_FALSE -1
2976 #define SWITCH_IGNORE -2
2977 #define SWITCH_LIVE 1
2984 unsigned char validated
;
2985 unsigned char ordering
;
2988 static struct switchstr
*switches
;
2990 static int n_switches
;
2995 const char *language
;
2998 /* Also a vector of input files specified. */
3000 static struct infile
*infiles
;
3004 /* This counts the number of libraries added by lang_specific_driver, so that
3005 we can tell if there were any user supplied any files or libraries. */
3007 static int added_libraries
;
3009 /* And a vector of corresponding output files is made up later. */
3011 const char **outfiles
;
3013 /* Used to track if none of the -B paths are used. */
3016 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
3017 static int *warn_std_ptr
= 0;
3019 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3021 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3022 is true if we should look for an executable suffix. DO_OBJ
3023 is true if we should look for an object suffix. */
3026 convert_filename (name
, do_exe
, do_obj
)
3028 int do_exe ATTRIBUTE_UNUSED
;
3029 int do_obj ATTRIBUTE_UNUSED
;
3031 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3039 len
= strlen (name
);
3041 #ifdef HAVE_TARGET_OBJECT_SUFFIX
3042 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3043 if (do_obj
&& len
> 2
3044 && name
[len
- 2] == '.'
3045 && name
[len
- 1] == 'o')
3047 obstack_grow (&obstack
, name
, len
- 2);
3048 obstack_grow0 (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
3049 name
= obstack_finish (&obstack
);
3053 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3054 /* If there is no filetype, make it the executable suffix (which includes
3055 the "."). But don't get confused if we have just "-o". */
3056 if (! do_exe
|| TARGET_EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
3059 for (i
= len
- 1; i
>= 0; i
--)
3060 if (IS_DIR_SEPARATOR (name
[i
]))
3063 for (i
++; i
< len
; i
++)
3067 obstack_grow (&obstack
, name
, len
);
3068 obstack_grow0 (&obstack
, TARGET_EXECUTABLE_SUFFIX
,
3069 strlen (TARGET_EXECUTABLE_SUFFIX
));
3070 name
= obstack_finish (&obstack
);
3077 /* Display the command line switches accepted by gcc. */
3081 printf (_("Usage: %s [options] file...\n"), programname
);
3082 fputs (_("Options:\n"), stdout
);
3084 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout
);
3085 fputs (_(" --help Display this information\n"), stdout
);
3086 fputs (_(" --target-help Display target specific command line options\n"), stdout
);
3088 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout
);
3089 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout
);
3090 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout
);
3091 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout
);
3092 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout
);
3093 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout
);
3094 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout
);
3095 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout
);
3096 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout
);
3098 -print-multi-lib Display the mapping between command line options and\n\
3099 multiple library search directories\n"), stdout
);
3100 fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout
);
3101 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout
);
3102 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout
);
3103 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout
);
3104 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout
);
3105 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout
);
3106 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout
);
3107 fputs (_(" -time Time the execution of each subprocess\n"), stdout
);
3108 fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout
);
3109 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout
);
3110 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout
);
3111 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout
);
3112 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout
);
3113 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout
);
3114 fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout
);
3115 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout
);
3116 fputs (_(" -S Compile only; do not assemble or link\n"), stdout
);
3117 fputs (_(" -c Compile and assemble, but do not link\n"), stdout
);
3118 fputs (_(" -o <file> Place the output into <file>\n"), stdout
);
3120 -x <language> Specify the language of the following input files\n\
3121 Permissable languages include: c c++ assembler none\n\
3122 'none' means revert to the default behavior of\n\
3123 guessing the language based on the file's extension\n\
3127 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3128 passed on to the various sub-processes invoked by %s. In order to pass\n\
3129 other options on to these processes the -W<letter> options must be used.\n\
3132 /* The rest of the options are displayed by invocations of the various
3137 add_preprocessor_option (option
, len
)
3141 n_preprocessor_options
++;
3143 if (! preprocessor_options
)
3144 preprocessor_options
3145 = (char **) xmalloc (n_preprocessor_options
* sizeof (char *));
3147 preprocessor_options
3148 = (char **) xrealloc (preprocessor_options
,
3149 n_preprocessor_options
* sizeof (char *));
3151 preprocessor_options
[n_preprocessor_options
- 1] =
3152 save_string (option
, len
);
3156 add_assembler_option (option
, len
)
3160 n_assembler_options
++;
3162 if (! assembler_options
)
3164 = (char **) xmalloc (n_assembler_options
* sizeof (char *));
3167 = (char **) xrealloc (assembler_options
,
3168 n_assembler_options
* sizeof (char *));
3170 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
3174 add_linker_option (option
, len
)
3180 if (! linker_options
)
3182 = (char **) xmalloc (n_linker_options
* sizeof (char *));
3185 = (char **) xrealloc (linker_options
,
3186 n_linker_options
* sizeof (char *));
3188 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
3191 /* Create the vector `switches' and its contents.
3192 Store its length in `n_switches'. */
3195 process_command (argc
, argv
)
3197 const char *const *argv
;
3202 const char *spec_lang
= 0;
3203 int last_language_n_infiles
;
3206 int lang_n_infiles
= 0;
3207 #ifdef MODIFY_TARGET_NAME
3208 int is_modify_target_name
;
3212 GET_ENVIRONMENT (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
3216 added_libraries
= 0;
3218 /* Figure compiler version from version string. */
3220 compiler_version
= temp1
= xstrdup (version_string
);
3222 for (; *temp1
; ++temp1
)
3231 /* If there is a -V or -b option (or both), process it now, before
3232 trying to interpret the rest of the command line. */
3233 if (argc
> 1 && argv
[1][0] == '-'
3234 && (argv
[1][1] == 'V' || argv
[1][1] == 'b'))
3236 const char *new_version
= DEFAULT_TARGET_VERSION
;
3237 const char *new_machine
= DEFAULT_TARGET_MACHINE
;
3238 const char *progname
= argv
[0];
3243 while (argc
> 1 && argv
[1][0] == '-'
3244 && (argv
[1][1] == 'V' || argv
[1][1] == 'b'))
3246 char opt
= argv
[1][1];
3248 if (argv
[1][2] != '\0')
3261 fatal ("`-%c' option must have argument", opt
);
3268 for (baselen
= strlen (progname
); baselen
> 0; baselen
--)
3269 if (IS_DIR_SEPARATOR (progname
[baselen
-1]))
3271 new_argv0
= xmemdup (progname
, baselen
,
3272 baselen
+ concat_length (new_version
, new_machine
,
3273 "-gcc-", NULL
) + 1);
3274 strcpy (new_argv0
+ baselen
, new_machine
);
3275 strcat (new_argv0
, "-gcc-");
3276 strcat (new_argv0
, new_version
);
3278 new_argv
= xmemdup (argv
, (argc
+ 1) * sizeof (argv
[0]),
3279 (argc
+ 1) * sizeof (argv
[0]));
3280 new_argv
[0] = new_argv0
;
3282 execvp (new_argv0
, new_argv
);
3283 fatal ("couldn't run `%s': %s", new_argv0
, xstrerror (errno
));
3286 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3287 see if we can create it from the pathname specified in argv[0]. */
3290 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3291 if (!gcc_exec_prefix
)
3293 gcc_exec_prefix
= make_relative_prefix (argv
[0], standard_bindir_prefix
,
3294 standard_exec_prefix
);
3295 if (gcc_exec_prefix
)
3296 putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix
, NULL
));
3300 if (gcc_exec_prefix
)
3302 int len
= strlen (gcc_exec_prefix
);
3304 if (len
> (int) sizeof ("/lib/gcc-lib/") - 1
3305 && (IS_DIR_SEPARATOR (gcc_exec_prefix
[len
-1])))
3307 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc-lib/") + 1;
3308 if (IS_DIR_SEPARATOR (*temp
)
3309 && strncmp (temp
+ 1, "lib", 3) == 0
3310 && IS_DIR_SEPARATOR (temp
[4])
3311 && strncmp (temp
+ 5, "gcc-lib", 7) == 0)
3312 len
-= sizeof ("/lib/gcc-lib/") - 1;
3315 set_std_prefix (gcc_exec_prefix
, len
);
3316 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC",
3317 PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
3318 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC",
3319 PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
3322 /* COMPILER_PATH and LIBRARY_PATH have values
3323 that are lists of directory names with colons. */
3325 GET_ENVIRONMENT (temp
, "COMPILER_PATH");
3328 const char *startp
, *endp
;
3329 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3331 startp
= endp
= temp
;
3334 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3336 strncpy (nstore
, startp
, endp
- startp
);
3338 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3339 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3341 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3342 nstore
[endp
- startp
+ 1] = 0;
3345 nstore
[endp
- startp
] = 0;
3346 add_prefix (&exec_prefixes
, nstore
, 0,
3347 PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
3348 add_prefix (&include_prefixes
,
3349 concat (nstore
, "include", NULL
),
3350 0, PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
3353 endp
= startp
= endp
+ 1;
3360 GET_ENVIRONMENT (temp
, LIBRARY_PATH_ENV
);
3361 if (temp
&& *cross_compile
== '0')
3363 const char *startp
, *endp
;
3364 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3366 startp
= endp
= temp
;
3369 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3371 strncpy (nstore
, startp
, endp
- startp
);
3373 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3374 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3376 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3377 nstore
[endp
- startp
+ 1] = 0;
3380 nstore
[endp
- startp
] = 0;
3381 add_prefix (&startfile_prefixes
, nstore
, NULL
,
3382 PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
3385 endp
= startp
= endp
+ 1;
3392 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3393 GET_ENVIRONMENT (temp
, "LPATH");
3394 if (temp
&& *cross_compile
== '0')
3396 const char *startp
, *endp
;
3397 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3399 startp
= endp
= temp
;
3402 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3404 strncpy (nstore
, startp
, endp
- startp
);
3406 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3407 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3409 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3410 nstore
[endp
- startp
+ 1] = 0;
3413 nstore
[endp
- startp
] = 0;
3414 add_prefix (&startfile_prefixes
, nstore
, NULL
,
3415 PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
3418 endp
= startp
= endp
+ 1;
3425 /* Convert new-style -- options to old-style. */
3426 translate_options (&argc
, &argv
);
3428 /* Do language-specific adjustment/addition of flags. */
3429 lang_specific_driver (&argc
, &argv
, &added_libraries
);
3431 /* Scan argv twice. Here, the first time, just count how many switches
3432 there will be in their vector, and how many input files in theirs.
3433 Here we also parse the switches that cc itself uses (e.g. -v). */
3435 for (i
= 1; i
< argc
; i
++)
3437 if (! strcmp (argv
[i
], "-dumpspecs"))
3439 struct spec_list
*sl
;
3441 for (sl
= specs
; sl
; sl
= sl
->next
)
3442 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
3443 if (link_command_spec
)
3444 printf ("*link_command:\n%s\n\n", link_command_spec
);
3447 else if (! strcmp (argv
[i
], "-dumpversion"))
3449 printf ("%s\n", spec_version
);
3452 else if (! strcmp (argv
[i
], "-dumpmachine"))
3454 printf ("%s\n", spec_machine
);
3457 else if (strcmp (argv
[i
], "-fversion") == 0)
3459 /* translate_options () has turned --version into -fversion. */
3460 printf (_("%s (GCC) %s\n"), programname
, version_string
);
3461 fputs (_("Copyright (C) 2002 Free Software Foundation, Inc.\n"),
3463 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
3464 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
3468 else if (strcmp (argv
[i
], "-fhelp") == 0)
3470 /* translate_options () has turned --help into -fhelp. */
3471 print_help_list
= 1;
3473 /* We will be passing a dummy file on to the sub-processes. */
3477 /* CPP driver cannot obtain switch from cc1_options. */
3479 add_preprocessor_option ("--help", 6);
3480 add_assembler_option ("--help", 6);
3481 add_linker_option ("--help", 6);
3483 else if (strcmp (argv
[i
], "-ftarget-help") == 0)
3485 /* translate_options() has turned --target-help into -ftarget-help. */
3486 target_help_flag
= 1;
3488 /* We will be passing a dummy file on to the sub-processes. */
3492 /* CPP driver cannot obtain switch from cc1_options. */
3494 add_preprocessor_option ("--target-help", 13);
3495 add_assembler_option ("--target-help", 13);
3496 add_linker_option ("--target-help", 13);
3498 else if (! strcmp (argv
[i
], "-pass-exit-codes"))
3500 pass_exit_codes
= 1;
3503 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3504 print_search_dirs
= 1;
3505 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3506 print_file_name
= "libgcc.a";
3507 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3508 print_file_name
= argv
[i
] + 17;
3509 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3510 print_prog_name
= argv
[i
] + 17;
3511 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3512 print_multi_lib
= 1;
3513 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3514 print_multi_directory
= 1;
3515 else if (! strcmp (argv
[i
], "-print-multi-os-directory"))
3516 print_multi_os_directory
= 1;
3517 else if (! strncmp (argv
[i
], "-Wa,", 4))
3520 /* Pass the rest of this option to the assembler. */
3522 /* Split the argument at commas. */
3524 for (j
= 4; argv
[i
][j
]; j
++)
3525 if (argv
[i
][j
] == ',')
3527 add_assembler_option (argv
[i
] + prev
, j
- prev
);
3531 /* Record the part after the last comma. */
3532 add_assembler_option (argv
[i
] + prev
, j
- prev
);
3534 else if (! strncmp (argv
[i
], "-Wp,", 4))
3537 /* Pass the rest of this option to the preprocessor. */
3539 /* Split the argument at commas. */
3541 for (j
= 4; argv
[i
][j
]; j
++)
3542 if (argv
[i
][j
] == ',')
3544 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
3548 /* Record the part after the last comma. */
3549 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
3551 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3552 /* The +e options to the C++ front-end. */
3554 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3557 /* Split the argument at commas. */
3558 for (j
= 3; argv
[i
][j
]; j
++)
3559 n_infiles
+= (argv
[i
][j
] == ',');
3561 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3564 fatal ("argument to `-Xlinker' is missing");
3569 else if (strcmp (argv
[i
], "-l") == 0)
3572 fatal ("argument to `-l' is missing");
3577 else if (strncmp (argv
[i
], "-l", 2) == 0)
3579 else if (strcmp (argv
[i
], "-save-temps") == 0)
3581 save_temps_flag
= 1;
3584 else if (strcmp (argv
[i
], "-specs") == 0)
3586 struct user_specs
*user
= (struct user_specs
*)
3587 xmalloc (sizeof (struct user_specs
));
3589 fatal ("argument to `-specs' is missing");
3591 user
->next
= (struct user_specs
*) 0;
3592 user
->filename
= argv
[i
];
3593 if (user_specs_tail
)
3594 user_specs_tail
->next
= user
;
3596 user_specs_head
= user
;
3597 user_specs_tail
= user
;
3599 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3601 struct user_specs
*user
= (struct user_specs
*)
3602 xmalloc (sizeof (struct user_specs
));
3603 if (strlen (argv
[i
]) == 7)
3604 fatal ("argument to `-specs=' is missing");
3606 user
->next
= (struct user_specs
*) 0;
3607 user
->filename
= argv
[i
] + 7;
3608 if (user_specs_tail
)
3609 user_specs_tail
->next
= user
;
3611 user_specs_head
= user
;
3612 user_specs_tail
= user
;
3614 else if (strcmp (argv
[i
], "-time") == 0)
3616 else if (strcmp (argv
[i
], "-###") == 0)
3618 /* This is similar to -v except that there is no execution
3619 of the commands and the echoed arguments are quoted. It
3620 is intended for use in shell scripts to capture the
3621 driver-generated command line. */
3622 verbose_only_flag
++;
3625 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3627 const char *p
= &argv
[i
][1];
3634 fatal ("`-%c' must come at the start of the command line", c
);
3642 if (p
[1] == 0 && i
+ 1 == argc
)
3643 fatal ("argument to `-B' is missing");
3649 len
= strlen (value
);
3651 /* Catch the case where the user has forgotten to append a
3652 directory separator to the path. Note, they may be using
3653 -B to add an executable name prefix, eg "i386-elf-", in
3654 order to distinguish between multiple installations of
3655 GCC in the same directory. Hence we must check to see
3656 if appending a directory separator actually makes a
3657 valid directory name. */
3658 if (! IS_DIR_SEPARATOR (value
[len
- 1])
3659 && is_directory (value
, "", 0))
3661 char *tmp
= xmalloc (len
+ 2);
3662 strcpy (tmp
, value
);
3663 tmp
[len
] = DIR_SEPARATOR
;
3668 /* As a kludge, if the arg is "[foo/]stageN/", just
3669 add "[foo/]include" to the include prefix. */
3672 && (IS_DIR_SEPARATOR (value
[len
- 8]))))
3673 && strncmp (value
+ len
- 7, "stage", 5) == 0
3674 && ISDIGIT (value
[len
- 2])
3675 && (IS_DIR_SEPARATOR (value
[len
- 1])))
3678 add_prefix (&include_prefixes
, "include", NULL
,
3679 PREFIX_PRIORITY_B_OPT
, 0, NULL
, 0);
3682 char * string
= xmalloc (len
+ 1);
3684 strncpy (string
, value
, len
- 7);
3685 strcpy (string
+ len
- 7, "include");
3686 add_prefix (&include_prefixes
, string
, NULL
,
3687 PREFIX_PRIORITY_B_OPT
, 0, NULL
, 0);
3691 add_prefix (&exec_prefixes
, value
, NULL
,
3692 PREFIX_PRIORITY_B_OPT
, 0, &warn_B
, 0);
3693 add_prefix (&startfile_prefixes
, value
, NULL
,
3694 PREFIX_PRIORITY_B_OPT
, 0, &warn_B
, 0);
3695 add_prefix (&include_prefixes
, concat (value
, "include", NULL
),
3696 NULL
, PREFIX_PRIORITY_B_OPT
, 0, NULL
, 0);
3701 case 'v': /* Print our subcommands and print versions. */
3703 /* If they do anything other than exactly `-v', don't set
3704 verbose_flag; rather, continue on to give the error. */
3722 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3727 /* Forward scan, just in case -S or -c is specified
3734 if (argv
[j
][0] == '-')
3736 if (SWITCH_CURTAILS_COMPILATION (argv
[j
][1])
3742 else if ((skip
= SWITCH_TAKES_ARG (argv
[j
][1])))
3743 j
+= skip
- (argv
[j
][2] != 0);
3744 else if ((skip
= WORD_SWITCH_TAKES_ARG (argv
[j
] + 1)))
3751 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
3753 argv
[i
+ 1] = convert_filename (argv
[i
+ 1], ! have_c
, 0);
3755 argv
[i
] = convert_filename (argv
[i
], ! have_c
, 0);
3762 #ifdef MODIFY_TARGET_NAME
3763 is_modify_target_name
= 0;
3765 for (j
= 0; j
< ARRAY_SIZE (modify_target
); j
++)
3766 if (! strcmp (argv
[i
], modify_target
[j
].sw
))
3769 = (char *) xmalloc (strlen (modify_target
[j
].str
)
3770 + strlen (spec_machine
));
3773 int made_addition
= 0;
3775 is_modify_target_name
= 1;
3776 for (p
= spec_machine
, q
= new_name
; *p
!= 0; )
3778 if (modify_target
[j
].add_del
== DELETE
3779 && (! strncmp (q
, modify_target
[j
].str
,
3780 strlen (modify_target
[j
].str
))))
3781 p
+= strlen (modify_target
[j
].str
);
3782 else if (modify_target
[j
].add_del
== ADD
3783 && ! made_addition
&& *p
== '-')
3785 for (r
= modify_target
[j
].str
; *r
!= 0; )
3793 spec_machine
= new_name
;
3796 if (is_modify_target_name
)
3802 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3803 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3804 else if (WORD_SWITCH_TAKES_ARG (p
))
3805 i
+= WORD_SWITCH_TAKES_ARG (p
);
3815 if (have_c
&& have_o
&& lang_n_infiles
> 1)
3816 fatal ("cannot specify -o with -c or -S and multiple compilations");
3818 /* Set up the search paths before we go looking for config files. */
3820 /* These come before the md prefixes so that we will find gcc's subcommands
3821 (such as cpp) rather than those of the host system. */
3822 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3823 as well as trying the machine and the version. */
3825 add_prefix (&exec_prefixes
, standard_exec_prefix
, "GCC",
3826 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
, 0);
3827 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
3828 PREFIX_PRIORITY_LAST
, 2, warn_std_ptr
, 0);
3829 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3830 PREFIX_PRIORITY_LAST
, 2, warn_std_ptr
, 0);
3833 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
3834 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
, 0);
3835 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3836 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
, 0);
3838 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
3839 dir_separator_str
, NULL
);
3841 /* If tooldir is relative, base it on exec_prefixes. A relative
3842 tooldir lets us move the installed tree as a unit.
3844 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3845 directories, so that we can search both the user specified directory
3846 and the standard place. */
3848 if (!IS_ABSOLUTE_PATHNAME (tooldir_prefix
))
3850 if (gcc_exec_prefix
)
3852 char *gcc_exec_tooldir_prefix
3853 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
3854 spec_version
, dir_separator_str
, tooldir_prefix
, NULL
);
3856 add_prefix (&exec_prefixes
,
3857 concat (gcc_exec_tooldir_prefix
, "bin",
3858 dir_separator_str
, NULL
),
3859 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
3860 add_prefix (&startfile_prefixes
,
3861 concat (gcc_exec_tooldir_prefix
, "lib",
3862 dir_separator_str
, NULL
),
3863 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
3866 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
3867 dir_separator_str
, spec_version
,
3868 dir_separator_str
, tooldir_prefix
, NULL
);
3871 add_prefix (&exec_prefixes
,
3872 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL
),
3873 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
3874 add_prefix (&startfile_prefixes
,
3875 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL
),
3876 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
3878 /* More prefixes are enabled in main, after we read the specs file
3879 and determine whether this is cross-compilation or not. */
3881 /* Then create the space for the vectors and scan again. */
3883 switches
= ((struct switchstr
*)
3884 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
3885 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
3888 last_language_n_infiles
= -1;
3890 /* This, time, copy the text of each switch and store a pointer
3891 to the copy in the vector of switches.
3892 Store all the infiles in their vector. */
3894 for (i
= 1; i
< argc
; i
++)
3896 /* Just skip the switches that were handled by the preceding loop. */
3897 #ifdef MODIFY_TARGET_NAME
3898 is_modify_target_name
= 0;
3900 for (j
= 0; j
< ARRAY_SIZE (modify_target
); j
++)
3901 if (! strcmp (argv
[i
], modify_target
[j
].sw
))
3902 is_modify_target_name
= 1;
3904 if (is_modify_target_name
)
3908 if (! strncmp (argv
[i
], "-Wa,", 4))
3910 else if (! strncmp (argv
[i
], "-Wp,", 4))
3912 else if (! strcmp (argv
[i
], "-pass-exit-codes"))
3914 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3916 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3918 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3920 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3922 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3924 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3926 else if (! strcmp (argv
[i
], "-print-multi-os-directory"))
3928 else if (! strcmp (argv
[i
], "-ftarget-help"))
3930 else if (! strcmp (argv
[i
], "-fhelp"))
3932 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3934 /* Compensate for the +e options to the C++ front-end;
3935 they're there simply for cfront call-compatibility. We do
3936 some magic in default_compilers to pass them down properly.
3937 Note we deliberately start at the `+' here, to avoid passing
3938 -e0 or -e1 down into the linker. */
3939 switches
[n_switches
].part1
= &argv
[i
][0];
3940 switches
[n_switches
].args
= 0;
3941 switches
[n_switches
].live_cond
= SWITCH_OK
;
3942 switches
[n_switches
].validated
= 0;
3945 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3948 /* Split the argument at commas. */
3950 for (j
= 4; argv
[i
][j
]; j
++)
3951 if (argv
[i
][j
] == ',')
3953 infiles
[n_infiles
].language
= "*";
3954 infiles
[n_infiles
++].name
3955 = save_string (argv
[i
] + prev
, j
- prev
);
3958 /* Record the part after the last comma. */
3959 infiles
[n_infiles
].language
= "*";
3960 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
3962 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3964 infiles
[n_infiles
].language
= "*";
3965 infiles
[n_infiles
++].name
= argv
[++i
];
3967 else if (strcmp (argv
[i
], "-l") == 0)
3968 { /* POSIX allows separation of -l and the lib arg;
3969 canonicalize by concatenating -l with its arg */
3970 infiles
[n_infiles
].language
= "*";
3971 infiles
[n_infiles
++].name
= concat ("-l", argv
[++i
], NULL
);
3973 else if (strncmp (argv
[i
], "-l", 2) == 0)
3975 infiles
[n_infiles
].language
= "*";
3976 infiles
[n_infiles
++].name
= argv
[i
];
3978 else if (strcmp (argv
[i
], "-specs") == 0)
3980 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3982 else if (strcmp (argv
[i
], "-time") == 0)
3984 else if ((save_temps_flag
|| report_times
)
3985 && strcmp (argv
[i
], "-pipe") == 0)
3987 /* -save-temps overrides -pipe, so that temp files are produced */
3988 if (save_temps_flag
)
3989 error ("warning: -pipe ignored because -save-temps specified");
3990 /* -time overrides -pipe because we can't get correct stats when
3991 multiple children are running at once. */
3992 else if (report_times
)
3993 error ("warning: -pipe ignored because -time specified");
3995 else if (strcmp (argv
[i
], "-###") == 0)
3997 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3999 const char *p
= &argv
[i
][1];
4004 if (p
[1] == 0 && i
+ 1 == argc
)
4005 fatal ("argument to `-x' is missing");
4007 spec_lang
= argv
[++i
];
4010 if (! strcmp (spec_lang
, "none"))
4011 /* Suppress the warning if -xnone comes after the last input
4012 file, because alternate command interfaces like g++ might
4013 find it useful to place -xnone after each input file. */
4016 last_language_n_infiles
= n_infiles
;
4019 switches
[n_switches
].part1
= p
;
4020 /* Deal with option arguments in separate argv elements. */
4021 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
4022 || WORD_SWITCH_TAKES_ARG (p
))
4025 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
4029 /* Count only the option arguments in separate argv elements. */
4030 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
4032 if (i
+ n_args
>= argc
)
4033 fatal ("argument to `-%s' is missing", p
);
4034 switches
[n_switches
].args
4035 = (const char **) xmalloc ((n_args
+ 1) * sizeof(const char *));
4037 switches
[n_switches
].args
[j
++] = argv
[++i
];
4038 /* Null-terminate the vector. */
4039 switches
[n_switches
].args
[j
] = 0;
4041 else if (strchr (switches_need_spaces
, c
))
4043 /* On some systems, ld cannot handle some options without
4044 a space. So split the option from its argument. */
4045 char *part1
= (char *) xmalloc (2);
4049 switches
[n_switches
].part1
= part1
;
4050 switches
[n_switches
].args
4051 = (const char **) xmalloc (2 * sizeof (const char *));
4052 switches
[n_switches
].args
[0] = xstrdup (p
+1);
4053 switches
[n_switches
].args
[1] = 0;
4056 switches
[n_switches
].args
= 0;
4058 switches
[n_switches
].live_cond
= SWITCH_OK
;
4059 switches
[n_switches
].validated
= 0;
4060 switches
[n_switches
].ordering
= 0;
4061 /* These are always valid, since gcc.c itself understands it. */
4062 if (!strcmp (p
, "save-temps")
4063 || !strcmp (p
, "static-libgcc")
4064 || !strcmp (p
, "shared-libgcc"))
4065 switches
[n_switches
].validated
= 1;
4068 char ch
= switches
[n_switches
].part1
[0];
4070 switches
[n_switches
].validated
= 1;
4076 #ifdef HAVE_TARGET_OBJECT_SUFFIX
4077 argv
[i
] = convert_filename (argv
[i
], 0, access (argv
[i
], F_OK
));
4080 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], F_OK
) < 0)
4082 perror_with_name (argv
[i
]);
4087 infiles
[n_infiles
].language
= spec_lang
;
4088 infiles
[n_infiles
++].name
= argv
[i
];
4093 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
4094 error ("warning: `-x %s' after last input file has no effect", spec_lang
);
4096 /* Ensure we only invoke each subprocess once. */
4097 if (target_help_flag
|| print_help_list
)
4101 /* Create a dummy input file, so that we can pass --target-help on to
4102 the various sub-processes. */
4103 infiles
[0].language
= "c";
4104 infiles
[0].name
= "help-dummy";
4106 if (target_help_flag
)
4108 switches
[n_switches
].part1
= "--target-help";
4109 switches
[n_switches
].args
= 0;
4110 switches
[n_switches
].live_cond
= SWITCH_OK
;
4111 switches
[n_switches
].validated
= 0;
4116 if (print_help_list
)
4118 switches
[n_switches
].part1
= "--help";
4119 switches
[n_switches
].args
= 0;
4120 switches
[n_switches
].live_cond
= SWITCH_OK
;
4121 switches
[n_switches
].validated
= 0;
4127 switches
[n_switches
].part1
= 0;
4128 infiles
[n_infiles
].name
= 0;
4131 /* Store switches not filtered out by %{<S} in spec in COLLECT_GCC_OPTIONS
4132 and place that in the environment. */
4135 set_collect_gcc_options ()
4140 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4142 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4143 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
4146 for (i
= 0; (int) i
< n_switches
; i
++)
4148 const char *const *args
;
4151 obstack_grow (&collect_obstack
, " ", 1);
4155 /* Ignore elided switches. */
4156 if (switches
[i
].live_cond
== SWITCH_IGNORE
)
4159 obstack_grow (&collect_obstack
, "'-", 2);
4160 q
= switches
[i
].part1
;
4161 while ((p
= strchr (q
, '\'')))
4163 obstack_grow (&collect_obstack
, q
, p
- q
);
4164 obstack_grow (&collect_obstack
, "'\\''", 4);
4167 obstack_grow (&collect_obstack
, q
, strlen (q
));
4168 obstack_grow (&collect_obstack
, "'", 1);
4170 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4172 obstack_grow (&collect_obstack
, " '", 2);
4174 while ((p
= strchr (q
, '\'')))
4176 obstack_grow (&collect_obstack
, q
, p
- q
);
4177 obstack_grow (&collect_obstack
, "'\\''", 4);
4180 obstack_grow (&collect_obstack
, q
, strlen (q
));
4181 obstack_grow (&collect_obstack
, "'", 1);
4184 obstack_grow (&collect_obstack
, "\0", 1);
4185 putenv (obstack_finish (&collect_obstack
));
4188 /* Process a spec string, accumulating and running commands. */
4190 /* These variables describe the input file name.
4191 input_file_number is the index on outfiles of this file,
4192 so that the output file name can be stored for later use by %o.
4193 input_basename is the start of the part of the input file
4194 sans all directory names, and basename_length is the number
4195 of characters starting there excluding the suffix .c or whatever. */
4197 const char *input_filename
;
4198 static int input_file_number
;
4199 size_t input_filename_length
;
4200 static int basename_length
;
4201 static int suffixed_basename_length
;
4202 static const char *input_basename
;
4203 static const char *input_suffix
;
4204 static struct stat input_stat
;
4205 static int input_stat_set
;
4207 /* The compiler used to process the current input file. */
4208 static struct compiler
*input_file_compiler
;
4210 /* These are variables used within do_spec and do_spec_1. */
4212 /* Nonzero if an arg has been started and not yet terminated
4213 (with space, tab or newline). */
4214 static int arg_going
;
4216 /* Nonzero means %d or %g has been seen; the next arg to be terminated
4217 is a temporary file name. */
4218 static int delete_this_arg
;
4220 /* Nonzero means %w has been seen; the next arg to be terminated
4221 is the output file name of this compilation. */
4222 static int this_is_output_file
;
4224 /* Nonzero means %s has been seen; the next arg to be terminated
4225 is the name of a library file and we should try the standard
4226 search dirs for it. */
4227 static int this_is_library_file
;
4229 /* Nonzero means that the input of this command is coming from a pipe. */
4230 static int input_from_pipe
;
4232 /* Nonnull means substitute this for any suffix when outputting a switches
4234 static const char *suffix_subst
;
4236 /* Process the spec SPEC and run the commands specified therein.
4237 Returns 0 if the spec is successfully processed; -1 if failed. */
4245 value
= do_spec_2 (spec
);
4247 /* Force out any unfinished command.
4248 If -pipe, this forces out the last command if it ended in `|'. */
4251 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4254 set_collect_gcc_options ();
4256 if (argbuf_index
> 0)
4269 delete_this_arg
= 0;
4270 this_is_output_file
= 0;
4271 this_is_library_file
= 0;
4272 input_from_pipe
= 0;
4273 suffix_subst
= NULL
;
4275 return do_spec_1 (spec
, 0, NULL
);
4279 /* Process the given spec string and add any new options to the end
4280 of the switches/n_switches array. */
4287 do_spec_1 (" ", 0, NULL
);
4289 if (argbuf_index
> 0)
4294 n_switches
+= argbuf_index
;
4295 switches
= xrealloc (switches
,
4296 sizeof (struct switchstr
) * (n_switches
+ 1));
4298 switches
[n_switches
] = switches
[first
];
4299 for (i
= 0; i
< argbuf_index
; i
++)
4301 struct switchstr
*sw
;
4303 /* Each switch should start with '-'. */
4304 if (argbuf
[i
][0] != '-')
4307 sw
= &switches
[i
+ first
];
4308 sw
->part1
= &argbuf
[i
][1];
4310 sw
->live_cond
= SWITCH_OK
;
4317 /* Process the sub-spec SPEC as a portion of a larger spec.
4318 This is like processing a whole spec except that we do
4319 not initialize at the beginning and we do not supply a
4320 newline by default at the end.
4321 INSWITCH nonzero means don't process %-sequences in SPEC;
4322 in this case, % is treated as an ordinary character.
4323 This is used while substituting switches.
4324 INSWITCH nonzero also causes SPC not to terminate an argument.
4326 Value is zero unless a line was finished
4327 and the command on that line reported an error. */
4330 do_spec_1 (spec
, inswitch
, soft_matched_part
)
4333 const char *soft_matched_part
;
4335 const char *p
= spec
;
4342 /* If substituting a switch, treat all chars like letters.
4343 Otherwise, NL, SPC, TAB and % are special. */
4344 switch (inswitch
? 'a' : c
)
4347 /* End of line: finish any pending argument,
4348 then run the pending command if one has been started. */
4351 obstack_1grow (&obstack
, 0);
4352 string
= obstack_finish (&obstack
);
4353 if (this_is_library_file
)
4354 string
= find_file (string
);
4355 store_arg (string
, delete_this_arg
, this_is_output_file
);
4356 if (this_is_output_file
)
4357 outfiles
[input_file_number
] = string
;
4361 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4363 for (i
= 0; i
< n_switches
; i
++)
4364 if (!strcmp (switches
[i
].part1
, "pipe"))
4367 /* A `|' before the newline means use a pipe here,
4368 but only if -pipe was specified.
4369 Otherwise, execute now and don't pass the `|' as an arg. */
4372 input_from_pipe
= 1;
4373 switches
[i
].validated
= 1;
4380 set_collect_gcc_options ();
4382 if (argbuf_index
> 0)
4388 /* Reinitialize for a new command, and for a new argument. */
4391 delete_this_arg
= 0;
4392 this_is_output_file
= 0;
4393 this_is_library_file
= 0;
4394 input_from_pipe
= 0;
4398 /* End any pending argument. */
4401 obstack_1grow (&obstack
, 0);
4402 string
= obstack_finish (&obstack
);
4403 if (this_is_library_file
)
4404 string
= find_file (string
);
4405 store_arg (string
, delete_this_arg
, this_is_output_file
);
4406 if (this_is_output_file
)
4407 outfiles
[input_file_number
] = string
;
4411 obstack_1grow (&obstack
, c
);
4417 /* Space or tab ends an argument if one is pending. */
4420 obstack_1grow (&obstack
, 0);
4421 string
= obstack_finish (&obstack
);
4422 if (this_is_library_file
)
4423 string
= find_file (string
);
4424 store_arg (string
, delete_this_arg
, this_is_output_file
);
4425 if (this_is_output_file
)
4426 outfiles
[input_file_number
] = string
;
4428 /* Reinitialize for a new argument. */
4430 delete_this_arg
= 0;
4431 this_is_output_file
= 0;
4432 this_is_library_file
= 0;
4439 fatal ("invalid specification! Bug in cc");
4442 obstack_grow (&obstack
, input_basename
, basename_length
);
4447 obstack_grow (&obstack
, input_basename
, suffixed_basename_length
);
4452 delete_this_arg
= 2;
4455 /* Dump out the directories specified with LIBRARY_PATH,
4456 followed by the absolute directories
4457 that we search for startfiles. */
4460 struct prefix_list
*pl
= startfile_prefixes
.plist
;
4461 size_t bufsize
= 100;
4462 char *buffer
= (char *) xmalloc (bufsize
);
4465 for (; pl
; pl
= pl
->next
)
4467 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4468 /* Used on systems which record the specified -L dirs
4469 and use them to search for dynamic linking. */
4470 /* Relative directories always come from -B,
4471 and it is better not to use them for searching
4472 at run time. In particular, stage1 loses. */
4473 if (!IS_ABSOLUTE_PATHNAME (pl
->prefix
))
4476 /* Try subdirectory if there is one. */
4477 if (multilib_dir
!= NULL
4478 || (pl
->os_multilib
&& multilib_os_dir
!= NULL
))
4480 const char *multi_dir
;
4482 multi_dir
= pl
->os_multilib
? multilib_os_dir
4484 if (machine_suffix
&& multilib_dir
)
4486 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
4488 bufsize
= (strlen (pl
->prefix
)
4489 + strlen (machine_suffix
)) * 2 + 1;
4490 buffer
= (char *) xrealloc (buffer
, bufsize
);
4491 strcpy (buffer
, pl
->prefix
);
4492 strcat (buffer
, machine_suffix
);
4493 if (is_directory (buffer
, multilib_dir
, 1))
4495 do_spec_1 ("-L", 0, NULL
);
4496 #ifdef SPACE_AFTER_L_OPTION
4497 do_spec_1 (" ", 0, NULL
);
4499 do_spec_1 (buffer
, 1, NULL
);
4500 do_spec_1 (multilib_dir
, 1, NULL
);
4501 /* Make this a separate argument. */
4502 do_spec_1 (" ", 0, NULL
);
4505 if (!pl
->require_machine_suffix
)
4507 if (is_directory (pl
->prefix
, multi_dir
, 1))
4509 do_spec_1 ("-L", 0, NULL
);
4510 #ifdef SPACE_AFTER_L_OPTION
4511 do_spec_1 (" ", 0, NULL
);
4513 do_spec_1 (pl
->prefix
, 1, NULL
);
4514 do_spec_1 (multi_dir
, 1, NULL
);
4515 /* Make this a separate argument. */
4516 do_spec_1 (" ", 0, NULL
);
4522 if (is_directory (pl
->prefix
, machine_suffix
, 1))
4524 do_spec_1 ("-L", 0, NULL
);
4525 #ifdef SPACE_AFTER_L_OPTION
4526 do_spec_1 (" ", 0, NULL
);
4528 do_spec_1 (pl
->prefix
, 1, NULL
);
4529 /* Remove slash from machine_suffix. */
4530 if (strlen (machine_suffix
) >= bufsize
)
4531 bufsize
= strlen (machine_suffix
) * 2 + 1;
4532 buffer
= (char *) xrealloc (buffer
, bufsize
);
4533 strcpy (buffer
, machine_suffix
);
4534 idx
= strlen (buffer
);
4535 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
4536 buffer
[idx
- 1] = 0;
4537 do_spec_1 (buffer
, 1, NULL
);
4538 /* Make this a separate argument. */
4539 do_spec_1 (" ", 0, NULL
);
4542 if (!pl
->require_machine_suffix
)
4544 if (is_directory (pl
->prefix
, "", 1))
4546 do_spec_1 ("-L", 0, NULL
);
4547 #ifdef SPACE_AFTER_L_OPTION
4548 do_spec_1 (" ", 0, NULL
);
4550 /* Remove slash from pl->prefix. */
4551 if (strlen (pl
->prefix
) >= bufsize
)
4552 bufsize
= strlen (pl
->prefix
) * 2 + 1;
4553 buffer
= (char *) xrealloc (buffer
, bufsize
);
4554 strcpy (buffer
, pl
->prefix
);
4555 idx
= strlen (buffer
);
4556 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
4557 buffer
[idx
- 1] = 0;
4558 do_spec_1 (buffer
, 1, NULL
);
4559 /* Make this a separate argument. */
4560 do_spec_1 (" ", 0, NULL
);
4569 /* %efoo means report an error with `foo' as error message
4570 and don't execute any more commands for this file. */
4574 while (*p
!= 0 && *p
!= '\n')
4576 buf
= (char *) alloca (p
- q
+ 1);
4577 strncpy (buf
, q
, p
- q
);
4584 /* %nfoo means report an notice with `foo' on stderr. */
4588 while (*p
!= 0 && *p
!= '\n')
4590 buf
= (char *) alloca (p
- q
+ 1);
4591 strncpy (buf
, q
, p
- q
);
4593 notice ("%s\n", buf
);
4603 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is defined,
4604 and it is not a directory, and it is writable, use it.
4605 Otherwise, fall through and treat this like any other
4608 if ((!save_temps_flag
)
4609 && (stat (HOST_BIT_BUCKET
, &st
) == 0) && (!S_ISDIR (st
.st_mode
))
4610 && (access (HOST_BIT_BUCKET
, W_OK
) == 0))
4612 obstack_grow (&obstack
, HOST_BIT_BUCKET
,
4613 strlen (HOST_BIT_BUCKET
));
4614 delete_this_arg
= 0;
4623 struct temp_name
*t
;
4625 const char *suffix
= p
;
4626 char *saved_suffix
= NULL
;
4628 while (*p
== '.' || ISALPHA ((unsigned char) *p
))
4630 suffix_length
= p
- suffix
;
4631 if (p
[0] == '%' && p
[1] == 'O')
4634 /* We don't support extra suffix characters after %O. */
4635 if (*p
== '.' || ISALPHA ((unsigned char) *p
))
4637 if (suffix_length
== 0)
4638 suffix
= TARGET_OBJECT_SUFFIX
;
4642 = (char *) xmalloc (suffix_length
4643 + strlen (TARGET_OBJECT_SUFFIX
));
4644 strncpy (saved_suffix
, suffix
, suffix_length
);
4645 strcpy (saved_suffix
+ suffix_length
,
4646 TARGET_OBJECT_SUFFIX
);
4648 suffix_length
+= strlen (TARGET_OBJECT_SUFFIX
);
4651 /* If the input_filename has the same suffix specified
4652 for the %g, %u, or %U, and -save-temps is specified,
4653 we could end up using that file as an intermediate
4654 thus clobbering the user's source file (.e.g.,
4655 gcc -save-temps foo.s would clobber foo.s with the
4656 output of cpp0). So check for this condition and
4657 generate a temp file as the intermediate. */
4659 if (save_temps_flag
)
4661 temp_filename_length
= basename_length
+ suffix_length
;
4662 temp_filename
= alloca (temp_filename_length
+ 1);
4663 strncpy ((char *) temp_filename
, input_basename
, basename_length
);
4664 strncpy ((char *) temp_filename
+ basename_length
, suffix
,
4666 *((char *) temp_filename
+ temp_filename_length
) = '\0';
4667 if (strcmp (temp_filename
, input_filename
) != 0)
4669 struct stat st_temp
;
4671 /* Note, set_input() resets input_stat_set to 0. */
4672 if (input_stat_set
== 0)
4674 input_stat_set
= stat (input_filename
, &input_stat
);
4675 if (input_stat_set
>= 0)
4679 /* If we have the stat for the input_filename
4680 and we can do the stat for the temp_filename
4681 then the they could still refer to the same
4682 file if st_dev/st_ino's are the same. */
4684 if (input_stat_set
!= 1
4685 || stat (temp_filename
, &st_temp
) < 0
4686 || input_stat
.st_dev
!= st_temp
.st_dev
4687 || input_stat
.st_ino
!= st_temp
.st_ino
)
4689 temp_filename
= save_string (temp_filename
,
4690 temp_filename_length
+ 1);
4691 obstack_grow (&obstack
, temp_filename
,
4692 temp_filename_length
);
4699 /* See if we already have an association of %g/%u/%U and
4701 for (t
= temp_names
; t
; t
= t
->next
)
4702 if (t
->length
== suffix_length
4703 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
4704 && t
->unique
== (c
!= 'g'))
4707 /* Make a new association if needed. %u and %j
4709 if (t
== 0 || c
== 'u' || c
== 'j')
4713 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
4714 t
->next
= temp_names
;
4717 t
->length
= suffix_length
;
4720 t
->suffix
= saved_suffix
;
4721 saved_suffix
= NULL
;
4724 t
->suffix
= save_string (suffix
, suffix_length
);
4725 t
->unique
= (c
!= 'g');
4726 temp_filename
= make_temp_file (t
->suffix
);
4727 temp_filename_length
= strlen (temp_filename
);
4728 t
->filename
= temp_filename
;
4729 t
->filename_length
= temp_filename_length
;
4733 free (saved_suffix
);
4735 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
4736 delete_this_arg
= 1;
4742 obstack_grow (&obstack
, input_filename
, input_filename_length
);
4748 struct prefix_list
*pl
= include_prefixes
.plist
;
4750 if (gcc_exec_prefix
)
4752 do_spec_1 ("-iprefix", 1, NULL
);
4753 /* Make this a separate argument. */
4754 do_spec_1 (" ", 0, NULL
);
4755 do_spec_1 (gcc_exec_prefix
, 1, NULL
);
4756 do_spec_1 (" ", 0, NULL
);
4759 for (; pl
; pl
= pl
->next
)
4761 do_spec_1 ("-isystem", 1, NULL
);
4762 /* Make this a separate argument. */
4763 do_spec_1 (" ", 0, NULL
);
4764 do_spec_1 (pl
->prefix
, 1, NULL
);
4765 do_spec_1 (" ", 0, NULL
);
4772 int max
= n_infiles
;
4773 max
+= lang_specific_extra_outfiles
;
4775 for (i
= 0; i
< max
; i
++)
4777 store_arg (outfiles
[i
], 0, 0);
4782 obstack_grow (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
4787 this_is_library_file
= 1;
4791 this_is_output_file
= 1;
4796 int cur_index
= argbuf_index
;
4797 /* Handle the {...} following the %W. */
4800 p
= handle_braces (p
+ 1);
4803 /* If any args were output, mark the last one for deletion
4805 if (argbuf_index
!= cur_index
)
4806 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
4810 /* %x{OPTION} records OPTION for %X to output. */
4816 /* Skip past the option value and make a copy. */
4821 string
= save_string (p1
+ 1, p
- p1
- 2);
4823 /* See if we already recorded this option. */
4824 for (i
= 0; i
< n_linker_options
; i
++)
4825 if (! strcmp (string
, linker_options
[i
]))
4831 /* This option is new; add it. */
4832 add_linker_option (string
, strlen (string
));
4836 /* Dump out the options accumulated previously using %x. */
4838 for (i
= 0; i
< n_linker_options
; i
++)
4840 do_spec_1 (linker_options
[i
], 1, NULL
);
4841 /* Make each accumulated option a separate argument. */
4842 do_spec_1 (" ", 0, NULL
);
4846 /* Dump out the options accumulated previously using -Wa,. */
4848 for (i
= 0; i
< n_assembler_options
; i
++)
4850 do_spec_1 (assembler_options
[i
], 1, NULL
);
4851 /* Make each accumulated option a separate argument. */
4852 do_spec_1 (" ", 0, NULL
);
4856 /* Dump out the options accumulated previously using -Wp,. */
4858 for (i
= 0; i
< n_preprocessor_options
; i
++)
4860 do_spec_1 (preprocessor_options
[i
], 1, NULL
);
4861 /* Make each accumulated option a separate argument. */
4862 do_spec_1 (" ", 0, NULL
);
4866 /* Here are digits and numbers that just process
4867 a certain constant string as a spec. */
4870 value
= do_spec_1 (cc1_spec
, 0, NULL
);
4876 value
= do_spec_1 (cc1plus_spec
, 0, NULL
);
4882 value
= do_spec_1 (asm_spec
, 0, NULL
);
4888 value
= do_spec_1 (asm_final_spec
, 0, NULL
);
4895 const char *const spec
4896 = (input_file_compiler
->cpp_spec
4897 ? input_file_compiler
->cpp_spec
4899 value
= do_spec_1 (spec
, 0, NULL
);
4906 value
= do_spec_1 (endfile_spec
, 0, NULL
);
4912 value
= do_spec_1 (link_spec
, 0, NULL
);
4918 value
= do_spec_1 (lib_spec
, 0, NULL
);
4924 value
= do_spec_1 (libgcc_spec
, 0, NULL
);
4930 if (multilib_dir
&& strcmp (multilib_dir
, ".") != 0)
4936 len
= strlen (multilib_dir
);
4937 obstack_blank (&obstack
, len
+ 1);
4938 p
= obstack_next_free (&obstack
) - (len
+ 1);
4941 for (q
= multilib_dir
; *q
; ++q
, ++p
)
4942 *p
= (IS_DIR_SEPARATOR (*q
) ? '_' : *q
);
4948 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
4952 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4956 if (! strncmp (y
, "-D", 2))
4957 /* Copy the whole option. */
4958 while (*y
&& *y
!= ' ' && *y
!= '\t')
4960 else if (*y
== ' ' || *y
== '\t')
4961 /* Copy whitespace to the result. */
4963 /* Don't copy other options. */
4970 value
= do_spec_1 (buf
, 0, NULL
);
4978 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
4982 /* Copy all of CPP_PREDEFINES into BUF,
4983 but force them all into the reserved name space if they
4984 aren't already there. The reserved name space is all
4985 identifiers beginning with two underscores or with one
4986 underscore and a capital letter. We do the forcing by
4987 adding up to two underscores to the beginning and end
4988 of each symbol. e.g. mips, _mips, mips_, and _mips_ all
4993 if (! strncmp (y
, "-D", 2))
5002 && ! ISUPPER ((unsigned char) *(y
+ 1))))
5004 /* Stick __ at front of macro name. */
5008 /* Arrange to stick __ at the end as well. */
5012 /* Copy the macro name. */
5013 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
5026 /* Copy the value given, if any. */
5027 while (*y
&& *y
!= ' ' && *y
!= '\t')
5030 else if (*y
== ' ' || *y
== '\t')
5031 /* Copy whitespace to the result. */
5033 /* Don't copy -A options */
5039 /* Copy all of CPP_PREDEFINES into BUF,
5040 but put __ after every -D. */
5044 if (! strncmp (y
, "-D", 2))
5050 && ! ISUPPER ((unsigned char) *(y
+ 1))))
5052 /* Stick -D__ at front of macro name. */
5059 /* Copy the macro name. */
5060 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
5063 /* Copy the value given, if any. */
5064 while (*y
&& *y
!= ' ' && *y
!= '\t')
5069 /* Do not copy this macro - we have just done it before */
5070 while (*y
&& *y
!= ' ' && *y
!= '\t')
5074 else if (*y
== ' ' || *y
== '\t')
5075 /* Copy whitespace to the result. */
5077 /* Don't copy -A options. */
5083 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
5087 if (! strncmp (y
, "-A", 2))
5088 /* Copy the whole option. */
5089 while (*y
&& *y
!= ' ' && *y
!= '\t')
5091 else if (*y
== ' ' || *y
== '\t')
5092 /* Copy whitespace to the result. */
5094 /* Don't copy other options. */
5101 value
= do_spec_1 (buf
, 0, NULL
);
5108 value
= do_spec_1 (startfile_spec
, 0, NULL
);
5113 /* Here we define characters other than letters and digits. */
5116 p
= handle_braces (p
);
5122 obstack_1grow (&obstack
, '%');
5129 while (p
[len
] && p
[len
] != ' ' && p
[len
] != '%')
5131 suffix_subst
= save_string (p
- 1, len
+ 1);
5137 if (soft_matched_part
)
5139 do_spec_1 (soft_matched_part
, 1, NULL
);
5140 do_spec_1 (" ", 0, NULL
);
5143 /* Catch the case where a spec string contains something like
5144 '%{foo:%*}'. ie there is no * in the pattern on the left
5145 hand side of the :. */
5146 error ("spec failure: '%%*' has not been initialized by pattern match");
5149 /* Process a string found as the value of a spec given by name.
5150 This feature allows individual machine descriptions
5151 to add and use their own specs.
5152 %[...] modifies -D options the way %P does;
5153 %(...) uses the spec unmodified. */
5155 error ("warning: use of obsolete %%[ operator in specs");
5158 const char *name
= p
;
5159 struct spec_list
*sl
;
5162 /* The string after the S/P is the name of a spec that is to be
5164 while (*p
&& *p
!= ')' && *p
!= ']')
5167 /* See if it's in the list. */
5168 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
5169 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
5171 name
= *(sl
->ptr_spec
);
5173 notice ("Processing spec %c%s%c, which is '%s'\n",
5174 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
5183 value
= do_spec_1 (name
, 0, NULL
);
5189 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
5191 const char *y
= name
;
5194 /* Copy all of NAME into BUF, but put __ after
5195 every -D and at the end of each arg. */
5198 if (! strncmp (y
, "-D", 2))
5209 && (*y
== ' ' || *y
== '\t' || *y
== '='
5210 || *y
== '}' || *y
== 0))
5223 value
= do_spec_1 (buf
, 0, NULL
);
5229 /* Discard the closing paren or bracket. */
5237 int c1
= *p
++; /* Select first or second version number. */
5238 const char *v
= compiler_version
;
5240 static const char zeroc
= '0';
5242 /* The format of the version string is
5243 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
5245 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
5246 while (! ISDIGIT (*v
))
5248 if (v
> compiler_version
&& v
[-1] != '-')
5251 /* If desired, advance to second version number. */
5254 /* Set V after the first period. */
5255 while (ISDIGIT (*v
))
5262 /* If desired, advance to third version number.
5263 But don't complain if it's not present */
5266 /* Set V after the second period. */
5267 while (ISDIGIT (*v
))
5269 if ((*v
!= 0) && (*v
!= ' ') && (*v
!= '.') && (*v
!= '-'))
5275 /* Set Q at the next period or at the end. */
5277 while (ISDIGIT (*q
))
5279 if (*q
!= 0 && q
> v
&& *q
!= ' ' && *q
!= '.' && *q
!= '-')
5283 /* Put that part into the command. */
5284 obstack_grow (&obstack
, v
, q
- v
);
5286 /* Default to "0" */
5287 obstack_grow (&obstack
, &zeroc
, 1);
5293 if (input_from_pipe
)
5294 do_spec_1 ("-", 0, NULL
);
5298 error ("spec failure: unrecognized spec option '%c'", c
);
5304 /* Backslash: treat next character as ordinary. */
5309 /* Ordinary character: put it into the current argument. */
5310 obstack_1grow (&obstack
, c
);
5314 /* End of string. */
5318 /* Return 0 if we call do_spec_1 and that returns -1. */
5324 const char *filter
, *body
= NULL
, *endbody
= NULL
;
5326 int true_once
= 0; /* If, in %{a|b:d}, at least one of a,b was seen. */
5329 int include_blanks
= 1;
5330 int elide_switch
= 0;
5335 /* A '^' after the open-brace means to not give blanks before args. */
5342 /* A `|' after the open-brace means,
5343 if the test fails, output a single minus sign rather than nothing.
5344 This is used in %{|!pipe:...}. */
5351 /* A `<' after the open-brace means that the switch should be
5352 removed from the command-line. */
5358 negate
= suffix
= 0;
5361 /* A `!' after the open-brace negates the condition:
5362 succeed if the specified switch is not present. */
5366 /* A `.' after the open-brace means test against the current suffix. */
5375 if (elide_switch
&& (negate
|| pipe_p
|| suffix
))
5377 /* It doesn't make sense to mix elision with other flags. We
5378 could fatal() here, but the standard seems to be to abort. */
5384 while (*p
!= ':' && *p
!= '}' && *p
!= '|' && *p
!= '&')
5387 if (*p
== '|' && (pipe_p
|| ordered
))
5392 if (*p
!= '}' && *p
!= '&')
5408 fatal ("mismatched braces in specs");
5414 body
= p
, endbody
= p
+ 1;
5419 int found
= (input_suffix
!= 0
5420 && (long) strlen (input_suffix
) == (long) (p
- filter
)
5421 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
5427 && do_spec_1 (save_string (body
, endbody
-body
-1), 0, NULL
) < 0)
5430 else if (p
[-1] == '*' && (p
[0] == '}' || p
[0] == '&'))
5432 /* Substitute all matching switches as separate args. */
5435 for (i
= 0; i
< n_switches
; i
++)
5436 if (!strncmp (switches
[i
].part1
, filter
, p
- 1 - filter
)
5437 && check_live_switch (i
, p
- 1 - filter
))
5441 switches
[i
].live_cond
= SWITCH_IGNORE
;
5442 switches
[i
].validated
= 1;
5445 ordered
= 1, switches
[i
].ordering
= 1;
5450 /* Test for presence of the specified switch. */
5454 /* If name specified ends in *, as in {x*:...},
5455 check for %* and handle that case. */
5456 if (p
[-1] == '*' && !negate
)
5459 const char *r
= body
;
5461 /* First see whether we have %*. */
5465 if (*r
== '%' && r
[1] == '*')
5469 /* If we do, handle that case. */
5472 /* Substitute all matching switches as separate args.
5473 But do this by substituting for %*
5474 in the text that follows the colon. */
5476 unsigned hard_match_len
= p
- filter
- 1;
5477 char *string
= save_string (body
, endbody
- body
- 1);
5479 for (i
= 0; i
< n_switches
; i
++)
5480 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
5481 && check_live_switch (i
, -1))
5483 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
5484 /* Pass any arguments this switch has. */
5485 give_switch (i
, 1, 1);
5486 suffix_subst
= NULL
;
5489 /* We didn't match. Try again. */
5496 /* If name specified ends in *, as in {x*:...},
5497 check for presence of any switch name starting with x. */
5500 for (i
= 0; i
< n_switches
; i
++)
5502 unsigned hard_match_len
= p
- filter
- 1;
5504 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
5505 && check_live_switch (i
, hard_match_len
))
5512 /* Otherwise, check for presence of exact name specified. */
5515 for (i
= 0; i
< n_switches
; i
++)
5517 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5518 && switches
[i
].part1
[p
- filter
] == 0
5519 && check_live_switch (i
, -1))
5527 /* If it is as desired (present for %{s...}, absent for %{!s...})
5528 then substitute either the switch or the specified
5529 conditional text. */
5530 if (present
!= negate
)
5534 switches
[i
].live_cond
= SWITCH_IGNORE
;
5535 switches
[i
].validated
= 1;
5537 else if (ordered
|| *p
== '&')
5538 ordered
= 1, switches
[i
].ordering
= 1;
5540 give_switch (i
, 0, include_blanks
);
5542 /* Even if many alternatives are matched, only output once. */
5547 /* Here if a %{|...} conditional fails: output a minus sign,
5548 which means "standard output" or "standard input". */
5549 do_spec_1 ("-", 0, NULL
);
5554 /* We didn't match; try again. */
5561 goto next_ampersand
;
5567 /* Doing this set of switches later preserves their command-line
5568 ordering. This is needed for e.g. -U, -D and -A. */
5569 for (i
= 0; i
< n_switches
; i
++)
5570 if (switches
[i
].ordering
== 1)
5572 switches
[i
].ordering
= 0;
5573 give_switch (i
, 0, include_blanks
);
5576 /* Process the spec just once, regardless of match count. */
5579 if (do_spec_1 (save_string (body
, endbody
- body
- 1),
5587 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
5588 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
5589 spec, or -1 if either exact match or %* is used.
5591 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
5592 whose value does not begin with "no-" is obsoleted by the same value
5593 with the "no-", similarly for a switch with the "no-" prefix. */
5596 check_live_switch (switchnum
, prefix_length
)
5600 const char *name
= switches
[switchnum
].part1
;
5603 /* In the common case of {<at-most-one-letter>*}, a negating
5604 switch would always match, so ignore that case. We will just
5605 send the conflicting switches to the compiler phase. */
5606 if (prefix_length
>= 0 && prefix_length
<= 1)
5609 /* If we already processed this switch and determined if it was
5610 live or not, return our past determination. */
5611 if (switches
[switchnum
].live_cond
!= 0)
5612 return switches
[switchnum
].live_cond
> 0;
5614 /* Now search for duplicate in a manner that depends on the name. */
5618 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5619 if (switches
[i
].part1
[0] == 'O')
5621 switches
[switchnum
].validated
= 1;
5622 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5627 case 'W': case 'f': case 'm':
5628 if (! strncmp (name
+ 1, "no-", 3))
5630 /* We have Xno-YYY, search for XYYY. */
5631 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5632 if (switches
[i
].part1
[0] == name
[0]
5633 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
5635 switches
[switchnum
].validated
= 1;
5636 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5642 /* We have XYYY, search for Xno-YYY. */
5643 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5644 if (switches
[i
].part1
[0] == name
[0]
5645 && switches
[i
].part1
[1] == 'n'
5646 && switches
[i
].part1
[2] == 'o'
5647 && switches
[i
].part1
[3] == '-'
5648 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
5650 switches
[switchnum
].validated
= 1;
5651 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5658 /* Otherwise the switch is live. */
5659 switches
[switchnum
].live_cond
= SWITCH_LIVE
;
5663 /* Pass a switch to the current accumulating command
5664 in the same form that we received it.
5665 SWITCHNUM identifies the switch; it is an index into
5666 the vector of switches gcc received, which is `switches'.
5667 This cannot fail since it never finishes a command line.
5669 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
5671 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
5675 give_switch (switchnum
, omit_first_word
, include_blanks
)
5677 int omit_first_word
;
5680 if (switches
[switchnum
].live_cond
== SWITCH_IGNORE
)
5683 if (!omit_first_word
)
5685 do_spec_1 ("-", 0, NULL
);
5686 do_spec_1 (switches
[switchnum
].part1
, 1, NULL
);
5689 if (switches
[switchnum
].args
!= 0)
5692 for (p
= switches
[switchnum
].args
; *p
; p
++)
5694 const char *arg
= *p
;
5697 do_spec_1 (" ", 0, NULL
);
5700 unsigned length
= strlen (arg
);
5703 while (length
-- && !IS_DIR_SEPARATOR (arg
[length
]))
5704 if (arg
[length
] == '.')
5706 ((char *)arg
)[length
] = 0;
5710 do_spec_1 (arg
, 1, NULL
);
5712 ((char *)arg
)[length
] = '.';
5713 do_spec_1 (suffix_subst
, 1, NULL
);
5716 do_spec_1 (arg
, 1, NULL
);
5720 do_spec_1 (" ", 0, NULL
);
5721 switches
[switchnum
].validated
= 1;
5724 /* Search for a file named NAME trying various prefixes including the
5725 user's -B prefix and some standard ones.
5726 Return the absolute file name found. If nothing is found, return NAME. */
5734 /* Try multilib_dir if it is defined. */
5735 if (multilib_os_dir
!= NULL
)
5737 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
, 1);
5739 /* If we don't find it in the multi library dir, then fall
5740 through and look for it in the normal places. */
5741 if (newname
!= NULL
)
5745 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
, 0);
5746 return newname
? newname
: name
;
5749 /* Determine whether a directory exists. If LINKER, return 0 for
5750 certain fixed names not needed by the linker. If not LINKER, it is
5751 only important to return 0 if the host machine has a small ARG_MAX
5755 is_directory (path1
, path2
, linker
)
5760 int len1
= strlen (path1
);
5761 int len2
= strlen (path2
);
5762 char *path
= (char *) alloca (3 + len1
+ len2
);
5766 #ifndef SMALL_ARG_MAX
5771 /* Construct the path from the two parts. Ensure the string ends with "/.".
5772 The resulting path will be a directory even if the given path is a
5774 memcpy (path
, path1
, len1
);
5775 memcpy (path
+ len1
, path2
, len2
);
5776 cp
= path
+ len1
+ len2
;
5777 if (!IS_DIR_SEPARATOR (cp
[-1]))
5778 *cp
++ = DIR_SEPARATOR
;
5782 /* Exclude directories that the linker is known to search. */
5785 && strcmp (path
, concat (dir_separator_str
, "lib",
5786 dir_separator_str
, ".", NULL
)) == 0)
5788 && strcmp (path
, concat (dir_separator_str
, "usr",
5789 dir_separator_str
, "lib",
5790 dir_separator_str
, ".", NULL
)) == 0)))
5793 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
5796 /* Set up the various global variables to indicate that we're processing
5797 the input file named FILENAME. */
5800 set_input (filename
)
5801 const char *filename
;
5805 input_filename
= filename
;
5806 input_filename_length
= strlen (input_filename
);
5808 input_basename
= input_filename
;
5809 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5810 /* Skip drive name so 'x:foo' is handled properly. */
5811 if (input_basename
[1] == ':')
5812 input_basename
+= 2;
5814 for (p
= input_basename
; *p
; p
++)
5815 if (IS_DIR_SEPARATOR (*p
))
5816 input_basename
= p
+ 1;
5818 /* Find a suffix starting with the last period,
5819 and set basename_length to exclude that suffix. */
5820 basename_length
= strlen (input_basename
);
5821 suffixed_basename_length
= basename_length
;
5822 p
= input_basename
+ basename_length
;
5823 while (p
!= input_basename
&& *p
!= '.')
5825 if (*p
== '.' && p
!= input_basename
)
5827 basename_length
= p
- input_basename
;
5828 input_suffix
= p
+ 1;
5833 /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
5834 we will need to do a stat on the input_filename. The
5835 INPUT_STAT_SET signals that the stat is needed. */
5839 /* On fatal signals, delete all the temporary files. */
5842 fatal_error (signum
)
5845 signal (signum
, SIG_DFL
);
5846 delete_failure_queue ();
5847 delete_temp_files ();
5848 /* Get the same signal again, this time not handled,
5849 so its normal effect occurs. */
5850 kill (getpid (), signum
);
5853 extern int main
PARAMS ((int, const char *const *));
5858 const char *const *argv
;
5862 int linker_was_run
= 0;
5863 char *explicit_link_files
;
5866 struct user_specs
*uptr
;
5868 p
= argv
[0] + strlen (argv
[0]);
5869 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
5873 xmalloc_set_program_name (programname
);
5875 #ifdef GCC_DRIVER_HOST_INITIALIZATION
5876 /* Perform host dependent initialization when needed. */
5877 GCC_DRIVER_HOST_INITIALIZATION
;
5880 gcc_init_libintl ();
5882 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
5883 signal (SIGINT
, fatal_error
);
5885 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
5886 signal (SIGHUP
, fatal_error
);
5888 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
5889 signal (SIGTERM
, fatal_error
);
5891 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
5892 signal (SIGPIPE
, fatal_error
);
5895 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
5896 receive the signal. A different setting is inheritable */
5897 signal (SIGCHLD
, SIG_DFL
);
5901 argbuf
= (const char **) xmalloc (argbuf_length
* sizeof (const char *));
5903 obstack_init (&obstack
);
5905 /* Build multilib_select, et. al from the separate lines that make up each
5906 multilib selection. */
5908 const char *const *q
= multilib_raw
;
5911 obstack_init (&multilib_obstack
);
5912 while ((p
= *q
++) != (char *) 0)
5913 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5915 obstack_1grow (&multilib_obstack
, 0);
5916 multilib_select
= obstack_finish (&multilib_obstack
);
5918 q
= multilib_matches_raw
;
5919 while ((p
= *q
++) != (char *) 0)
5920 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5922 obstack_1grow (&multilib_obstack
, 0);
5923 multilib_matches
= obstack_finish (&multilib_obstack
);
5925 q
= multilib_exclusions_raw
;
5926 while ((p
= *q
++) != (char *) 0)
5927 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5929 obstack_1grow (&multilib_obstack
, 0);
5930 multilib_exclusions
= obstack_finish (&multilib_obstack
);
5933 for (i
= 0; i
< ARRAY_SIZE (multilib_defaults_raw
); i
++)
5936 obstack_1grow (&multilib_obstack
, ' ');
5937 obstack_grow (&multilib_obstack
,
5938 multilib_defaults_raw
[i
],
5939 strlen (multilib_defaults_raw
[i
]));
5943 obstack_1grow (&multilib_obstack
, 0);
5944 multilib_defaults
= obstack_finish (&multilib_obstack
);
5947 /* Set up to remember the pathname of gcc and any options
5948 needed for collect. We use argv[0] instead of programname because
5949 we need the complete pathname. */
5950 obstack_init (&collect_obstack
);
5951 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
5952 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0]) + 1);
5953 putenv (obstack_finish (&collect_obstack
));
5955 #ifdef INIT_ENVIRONMENT
5956 /* Set up any other necessary machine specific environment variables. */
5957 putenv (INIT_ENVIRONMENT
);
5960 /* Make a table of what switches there are (switches, n_switches).
5961 Make a table of specified input files (infiles, n_infiles).
5962 Decode switches that are handled locally. */
5964 process_command (argc
, argv
);
5966 /* Process DRIVER_SELF_SPECS, adding any new options to the end
5967 of the command line. */
5969 for (i
= 0; i
< ARRAY_SIZE (driver_self_specs
); i
++)
5970 do_self_spec (driver_self_specs
[i
]);
5972 /* Initialize the vector of specs to just the default.
5973 This means one element containing 0s, as a terminator. */
5975 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
5976 memcpy ((char *) compilers
, (char *) default_compilers
,
5977 sizeof default_compilers
);
5978 n_compilers
= n_default_compilers
;
5980 /* Read specs from a file if there is one. */
5982 machine_suffix
= concat (spec_machine
, dir_separator_str
,
5983 spec_version
, dir_separator_str
, NULL
);
5984 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL
);
5986 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
, 0);
5987 /* Read the specs file unless it is a default one. */
5988 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
5989 read_specs (specs_file
, TRUE
);
5993 /* We need to check standard_exec_prefix/just_machine_suffix/specs
5994 for any override of as, ld and libraries. */
5995 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
5996 + strlen (just_machine_suffix
)
5997 + sizeof ("specs"));
5999 strcpy (specs_file
, standard_exec_prefix
);
6000 strcat (specs_file
, just_machine_suffix
);
6001 strcat (specs_file
, "specs");
6002 if (access (specs_file
, R_OK
) == 0)
6003 read_specs (specs_file
, TRUE
);
6005 /* If not cross-compiling, look for startfiles in the standard places.
6006 Similarly, don't add the standard prefixes if startfile handling
6007 will be under control of startfile_prefix_spec. */
6008 if (*cross_compile
== '0' && *startfile_prefix_spec
== 0)
6010 if (*md_exec_prefix
)
6012 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC",
6013 PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
6014 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC",
6015 PREFIX_PRIORITY_LAST
, 0, NULL
, 0);
6018 if (*md_startfile_prefix
)
6019 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
6020 PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6022 if (*md_startfile_prefix_1
)
6023 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
6024 PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6026 /* If standard_startfile_prefix is relative, base it on
6027 standard_exec_prefix. This lets us move the installed tree
6028 as a unit. If GCC_EXEC_PREFIX is defined, base
6029 standard_startfile_prefix on that as well. */
6030 if (IS_ABSOLUTE_PATHNAME (standard_startfile_prefix
))
6031 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
6032 PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6035 if (gcc_exec_prefix
)
6036 add_prefix (&startfile_prefixes
,
6037 concat (gcc_exec_prefix
, machine_suffix
,
6038 standard_startfile_prefix
, NULL
),
6039 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6040 add_prefix (&startfile_prefixes
,
6041 concat (standard_exec_prefix
,
6043 standard_startfile_prefix
, NULL
),
6044 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6047 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
6048 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6049 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
6050 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6051 #if 0 /* Can cause surprises, and one can use -B./ instead. */
6052 add_prefix (&startfile_prefixes
, "./", NULL
,
6053 PREFIX_PRIORITY_LAST
, 1, NULL
, 0);
6058 if (!IS_ABSOLUTE_PATHNAME (standard_startfile_prefix
)
6060 add_prefix (&startfile_prefixes
,
6061 concat (gcc_exec_prefix
, machine_suffix
,
6062 standard_startfile_prefix
, NULL
),
6063 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6066 if (*startfile_prefix_spec
!= 0
6067 && do_spec_2 (startfile_prefix_spec
) == 0
6068 && do_spec_1 (" ", 0, NULL
) == 0)
6071 for (ndx
= 0; ndx
< argbuf_index
; ndx
++)
6072 add_prefix (&startfile_prefixes
, argbuf
[ndx
], "BINUTILS",
6073 PREFIX_PRIORITY_LAST
, 0, NULL
, 1);
6076 /* Process any user specified specs in the order given on the command
6078 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
6080 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
,
6082 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
6085 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
6086 if (gcc_exec_prefix
)
6087 gcc_exec_prefix
= concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
6088 spec_version
, dir_separator_str
, NULL
);
6090 /* Now we have the specs.
6091 Set the `valid' bits for switches that match anything in any spec. */
6093 validate_all_switches ();
6095 /* Now that we have the switches and the specs, set
6096 the subdirectory based on the options. */
6097 set_multilib_dir ();
6099 /* Warn about any switches that no pass was interested in. */
6101 for (i
= 0; (int) i
< n_switches
; i
++)
6102 if (! switches
[i
].validated
)
6103 error ("unrecognized option `-%s'", switches
[i
].part1
);
6105 /* Obey some of the options. */
6107 if (print_search_dirs
)
6109 printf (_("install: %s%s\n"), standard_exec_prefix
, machine_suffix
);
6110 printf (_("programs: %s\n"), build_search_list (&exec_prefixes
, "", 0));
6111 printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes
, "", 0));
6115 if (print_file_name
)
6117 printf ("%s\n", find_file (print_file_name
));
6121 if (print_prog_name
)
6123 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
, 0);
6124 printf ("%s\n", (newname
? newname
: print_prog_name
));
6128 if (print_multi_lib
)
6130 print_multilib_info ();
6134 if (print_multi_directory
)
6136 if (multilib_dir
== NULL
)
6139 printf ("%s\n", multilib_dir
);
6143 if (print_multi_os_directory
)
6145 if (multilib_os_dir
== NULL
)
6148 printf ("%s\n", multilib_os_dir
);
6152 if (target_help_flag
)
6154 /* Print if any target specific options. */
6156 /* We do not exit here. Instead we have created a fake input file
6157 called 'target-dummy' which needs to be compiled, and we pass this
6158 on to the various sub-processes, along with the --target-help
6162 if (print_help_list
)
6168 printf (_("\nFor bug reporting instructions, please see:\n"));
6169 printf ("%s.\n", bug_report_url
);
6174 /* We do not exit here. Instead we have created a fake input file
6175 called 'help-dummy' which needs to be compiled, and we pass this
6176 on the various sub-processes, along with the --help switch. */
6184 notice ("Configured with: %s\n", configuration_arguments
);
6186 #ifdef THREAD_MODEL_SPEC
6187 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
6188 but there's no point in doing all this processing just to get
6189 thread_model back. */
6190 obstack_init (&obstack
);
6191 do_spec_1 (THREAD_MODEL_SPEC
, 0, thread_model
);
6192 obstack_1grow (&obstack
, '\0');
6193 thrmod
= obstack_finish (&obstack
);
6195 thrmod
= thread_model
;
6198 notice ("Thread model: %s\n", thrmod
);
6200 /* compiler_version is truncated at the first space when initialized
6201 from version string, so truncate version_string at the first space
6202 before comparing. */
6203 for (n
= 0; version_string
[n
]; n
++)
6204 if (version_string
[n
] == ' ')
6207 if (! strncmp (version_string
, compiler_version
, n
)
6208 && compiler_version
[n
] == 0)
6209 notice ("gcc version %s\n", version_string
);
6211 notice ("gcc driver version %s executing gcc version %s\n",
6212 version_string
, compiler_version
);
6218 if (n_infiles
== added_libraries
)
6219 fatal ("no input files");
6221 /* Make a place to record the compiler output file names
6222 that correspond to the input files. */
6225 i
+= lang_specific_extra_outfiles
;
6226 outfiles
= (const char **) xcalloc (i
, sizeof (char *));
6228 /* Record which files were specified explicitly as link input. */
6230 explicit_link_files
= xcalloc (1, n_infiles
);
6232 for (i
= 0; (int) i
< n_infiles
; i
++)
6234 int this_file_error
= 0;
6236 /* Tell do_spec what to substitute for %i. */
6238 input_file_number
= i
;
6239 set_input (infiles
[i
].name
);
6241 /* Use the same thing in %o, unless cp->spec says otherwise. */
6243 outfiles
[i
] = input_filename
;
6245 /* Figure out which compiler from the file's suffix. */
6248 = lookup_compiler (infiles
[i
].name
, input_filename_length
,
6249 infiles
[i
].language
);
6251 if (input_file_compiler
)
6253 /* Ok, we found an applicable compiler. Run its spec. */
6255 if (input_file_compiler
->spec
[0] == '#')
6257 error ("%s: %s compiler not installed on this system",
6258 input_filename
, &input_file_compiler
->spec
[1]);
6259 this_file_error
= 1;
6263 value
= do_spec (input_file_compiler
->spec
);
6265 this_file_error
= 1;
6269 /* If this file's name does not contain a recognized suffix,
6270 record it as explicit linker input. */
6273 explicit_link_files
[i
] = 1;
6275 /* Clear the delete-on-failure queue, deleting the files in it
6276 if this compilation failed. */
6278 if (this_file_error
)
6280 delete_failure_queue ();
6283 /* If this compilation succeeded, don't delete those files later. */
6284 clear_failure_queue ();
6287 /* Reset the output file name to the first input file name, for use
6288 with %b in LINK_SPEC on a target that prefers not to emit a.out
6291 set_input (infiles
[0].name
);
6293 if (error_count
== 0)
6295 /* Make sure INPUT_FILE_NUMBER points to first available open
6297 input_file_number
= n_infiles
;
6298 if (lang_specific_pre_link ())
6302 /* Run ld to link all the compiler output files. */
6304 if (error_count
== 0)
6306 int tmp
= execution_count
;
6308 /* We'll use ld if we can't find collect2. */
6309 if (! strcmp (linker_name_spec
, "collect2"))
6311 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
, 0);
6313 linker_name_spec
= "ld";
6315 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
6317 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH");
6318 putenv_from_prefixes (&startfile_prefixes
, LIBRARY_PATH_ENV
);
6320 value
= do_spec (link_command_spec
);
6323 linker_was_run
= (tmp
!= execution_count
);
6326 /* If options said don't run linker,
6327 complain about input files to be given to the linker. */
6329 if (! linker_was_run
&& error_count
== 0)
6330 for (i
= 0; (int) i
< n_infiles
; i
++)
6331 if (explicit_link_files
[i
])
6332 error ("%s: linker input file unused because linking not done",
6335 /* Delete some or all of the temporary files we made. */
6338 delete_failure_queue ();
6339 delete_temp_files ();
6341 if (print_help_list
)
6343 printf (("\nFor bug reporting instructions, please see:\n"));
6344 printf ("%s\n", bug_report_url
);
6347 return (signal_count
!= 0 ? 2
6348 : error_count
> 0 ? (pass_exit_codes
? greatest_status
: 1)
6352 /* Find the proper compilation spec for the file name NAME,
6353 whose length is LENGTH. LANGUAGE is the specified language,
6354 or 0 if this file is to be passed to the linker. */
6356 static struct compiler
*
6357 lookup_compiler (name
, length
, language
)
6360 const char *language
;
6362 struct compiler
*cp
;
6364 /* If this was specified by the user to be a linker input, indicate that. */
6365 if (language
!= 0 && language
[0] == '*')
6368 /* Otherwise, look for the language, if one is spec'd. */
6371 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6372 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
6375 error ("language %s not recognized", language
);
6379 /* Look for a suffix. */
6380 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6382 if (/* The suffix `-' matches only the file name `-'. */
6383 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
6384 || (strlen (cp
->suffix
) < length
6385 /* See if the suffix matches the end of NAME. */
6386 && !strcmp (cp
->suffix
,
6387 name
+ length
- strlen (cp
->suffix
))
6392 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
6393 /* look again, but case-insensitively this time. */
6395 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6397 if (/* The suffix `-' matches only the file name `-'. */
6398 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
6399 || (strlen (cp
->suffix
) < length
6400 /* See if the suffix matches the end of NAME. */
6401 && ((!strcmp (cp
->suffix
,
6402 name
+ length
- strlen (cp
->suffix
))
6403 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
6404 && !strcasecmp (cp
->suffix
,
6405 name
+ length
- strlen (cp
->suffix
)))
6411 if (cp
>= compilers
)
6413 if (cp
->spec
[0] != '@')
6414 /* A non-alias entry: return it. */
6417 /* An alias entry maps a suffix to a language.
6418 Search for the language; pass 0 for NAME and LENGTH
6419 to avoid infinite recursion if language not found. */
6420 return lookup_compiler (NULL
, 0, cp
->spec
+ 1);
6426 save_string (s
, len
)
6430 char *result
= xmalloc (len
+ 1);
6432 memcpy (result
, s
, len
);
6438 pfatal_with_name (name
)
6441 perror_with_name (name
);
6442 delete_temp_files ();
6447 perror_with_name (name
)
6450 error ("%s: %s", name
, xstrerror (errno
));
6454 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
6455 const char *errmsg_fmt
;
6456 const char *errmsg_arg
;
6460 int save_errno
= errno
;
6462 /* Space for trailing '\0' is in %s. */
6463 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
6464 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
6470 pfatal_with_name (errmsg_fmt
);
6473 /* Output an error message and exit */
6478 fatal ("internal gcc abort");
6481 /* Output an error message and exit */
6484 fatal
VPARAMS ((const char *msgid
, ...))
6486 VA_OPEN (ap
, msgid
);
6487 VA_FIXEDARG (ap
, const char *, msgid
);
6489 fprintf (stderr
, "%s: ", programname
);
6490 vfprintf (stderr
, _(msgid
), ap
);
6492 fprintf (stderr
, "\n");
6493 delete_temp_files ();
6498 error
VPARAMS ((const char *msgid
, ...))
6500 VA_OPEN (ap
, msgid
);
6501 VA_FIXEDARG (ap
, const char *, msgid
);
6503 fprintf (stderr
, "%s: ", programname
);
6504 vfprintf (stderr
, _(msgid
), ap
);
6507 fprintf (stderr
, "\n");
6511 notice
VPARAMS ((const char *msgid
, ...))
6513 VA_OPEN (ap
, msgid
);
6514 VA_FIXEDARG (ap
, const char *, msgid
);
6516 vfprintf (stderr
, _(msgid
), ap
);
6521 validate_all_switches ()
6523 struct compiler
*comp
;
6526 struct spec_list
*spec
;
6528 for (comp
= compilers
; comp
->spec
; comp
++)
6532 if (c
== '%' && (*p
== '{' || (*p
== 'W' && *++p
== '{')))
6533 /* We have a switch spec. */
6534 validate_switches (p
+ 1);
6537 /* Look through the linked list of specs read from the specs file. */
6538 for (spec
= specs
; spec
; spec
= spec
->next
)
6540 p
= *(spec
->ptr_spec
);
6542 if (c
== '%' && (*p
== '{' || (*p
== 'W' && *++p
== '{')))
6543 /* We have a switch spec. */
6544 validate_switches (p
+ 1);
6547 p
= link_command_spec
;
6549 if (c
== '%' && (*p
== '{' || (*p
== 'W' && *++p
== '{')))
6550 /* We have a switch spec. */
6551 validate_switches (p
+ 1);
6554 /* Look at the switch-name that comes after START
6555 and mark as valid all supplied switches that match it. */
6558 validate_switches (start
)
6561 const char *p
= start
;
6578 while (*p
!= ':' && *p
!= '}' && *p
!= '|' && *p
!= '&')
6583 else if (p
[-1] == '*')
6585 /* Mark all matching switches as valid. */
6586 for (i
= 0; i
< n_switches
; i
++)
6587 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
- 1))
6588 switches
[i
].validated
= 1;
6592 /* Mark an exact matching switch as valid. */
6593 for (i
= 0; i
< n_switches
; i
++)
6595 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
6596 && switches
[i
].part1
[p
- filter
] == 0)
6597 switches
[i
].validated
= 1;
6601 if (*p
++ == '|' || p
[-1] == '&')
6611 static struct mdswitchstr
*mdswitches
;
6612 static int n_mdswitches
;
6614 /* Check whether a particular argument was used. The first time we
6615 canonicalize the switches to keep only the ones we care about. */
6625 const char *replace
;
6630 static struct mswitchstr
*mswitches
;
6631 static int n_mswitches
;
6636 struct mswitchstr
*matches
;
6640 /* Break multilib_matches into the component strings of string
6641 and replacement string. */
6642 for (q
= multilib_matches
; *q
!= '\0'; q
++)
6647 (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
6649 q
= multilib_matches
;
6659 matches
[i
].len
= q
- matches
[i
].str
;
6661 matches
[i
].replace
= ++q
;
6662 while (*q
!= ';' && *q
!= '\0')
6668 matches
[i
].rep_len
= q
- matches
[i
].replace
;
6674 /* Now build a list of the replacement string for switches that we care
6675 about. Make sure we allocate at least one entry. This prevents
6676 xmalloc from calling fatal, and prevents us from re-executing this
6679 = (struct mswitchstr
*)
6680 xmalloc (sizeof (struct mswitchstr
)
6681 * (n_mdswitches
+ (n_switches
? n_switches
: 1)));
6682 for (i
= 0; i
< n_switches
; i
++)
6684 int xlen
= strlen (switches
[i
].part1
);
6685 for (j
= 0; j
< cnt
; j
++)
6686 if (xlen
== matches
[j
].len
6687 && ! strncmp (switches
[i
].part1
, matches
[j
].str
, xlen
))
6689 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
6690 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
6691 mswitches
[n_mswitches
].replace
= (char *) 0;
6692 mswitches
[n_mswitches
].rep_len
= 0;
6698 /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
6699 on the command line nor any options mutually incompatible with
6701 for (i
= 0; i
< n_mdswitches
; i
++)
6705 for (q
= multilib_options
; *q
!= '\0'; q
++)
6711 while (strncmp (q
, mdswitches
[i
].str
, mdswitches
[i
].len
) != 0
6712 || strchr (" /", q
[mdswitches
[i
].len
]) == NULL
)
6714 while (*q
!= ' ' && *q
!= '/' && *q
!= '\0')
6721 if (*q
!= ' ' && *q
!= '\0')
6723 while (*r
!= ' ' && *r
!= '\0')
6726 while (*q
!= ' ' && *q
!= '/' && *q
!= '\0')
6729 if (used_arg (r
, q
- r
))
6734 mswitches
[n_mswitches
].str
= mdswitches
[i
].str
;
6735 mswitches
[n_mswitches
].len
= mdswitches
[i
].len
;
6736 mswitches
[n_mswitches
].replace
= (char *) 0;
6737 mswitches
[n_mswitches
].rep_len
= 0;
6750 for (i
= 0; i
< n_mswitches
; i
++)
6751 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
6758 default_arg (p
, len
)
6764 for (i
= 0; i
< n_mdswitches
; i
++)
6765 if (len
== mdswitches
[i
].len
&& ! strncmp (p
, mdswitches
[i
].str
, len
))
6771 /* Work out the subdirectory to use based on the options. The format of
6772 multilib_select is a list of elements. Each element is a subdirectory
6773 name followed by a list of options followed by a semicolon. The format
6774 of multilib_exclusions is the same, but without the preceding
6775 directory. First gcc will check the exclusions, if none of the options
6776 beginning with an exclamation point are present, and all of the other
6777 options are present, then we will ignore this completely. Passing
6778 that, gcc will consider each multilib_select in turn using the same
6779 rules for matching the options. If a match is found, that subdirectory
6786 unsigned int this_path_len
;
6787 const char *this_path
, *this_arg
;
6788 const char *start
, *end
;
6790 int ok
, ndfltok
, first
;
6793 start
= multilib_defaults
;
6794 while (*start
== ' ' || *start
== '\t')
6796 while (*start
!= '\0')
6799 while (*start
!= ' ' && *start
!= '\t' && *start
!= '\0')
6801 while (*start
== ' ' || *start
== '\t')
6810 = (struct mdswitchstr
*) xmalloc (sizeof (struct mdswitchstr
)
6812 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+ 1)
6814 while (*start
== ' ' || *start
== '\t')
6820 for (end
= start
+ 1;
6821 *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
6824 obstack_grow (&multilib_obstack
, start
, end
- start
);
6825 obstack_1grow (&multilib_obstack
, 0);
6826 mdswitches
[i
].str
= obstack_finish (&multilib_obstack
);
6827 mdswitches
[i
++].len
= end
- start
;
6834 p
= multilib_exclusions
;
6837 /* Ignore newlines. */
6844 /* Check the arguments. */
6858 while (*p
!= ' ' && *p
!= ';')
6865 if (*this_arg
!= '!')
6873 ok
= used_arg (this_arg
, p
- this_arg
);
6888 p
= multilib_select
;
6891 /* Ignore newlines. */
6898 /* Get the initial path. */
6906 this_path_len
= p
- this_path
;
6908 /* Check the arguments. */
6924 while (*p
!= ' ' && *p
!= ';')
6931 if (*this_arg
!= '!')
6939 /* If this is a default argument, we can just ignore it.
6940 This is true even if this_arg begins with '!'. Beginning
6941 with '!' does not mean that this argument is necessarily
6942 inappropriate for this library: it merely means that
6943 there is a more specific library which uses this
6944 argument. If this argument is a default, we need not
6945 consider that more specific library. */
6946 ok
= used_arg (this_arg
, p
- this_arg
);
6953 if (default_arg (this_arg
, p
- this_arg
))
6962 if (this_path_len
!= 1
6963 || this_path
[0] != '.')
6965 char *new_multilib_dir
= xmalloc (this_path_len
+ 1);
6968 strncpy (new_multilib_dir
, this_path
, this_path_len
);
6969 new_multilib_dir
[this_path_len
] = '\0';
6970 q
= strchr (new_multilib_dir
, ':');
6973 multilib_dir
= new_multilib_dir
;
6980 const char *q
= this_path
, *end
= this_path
+ this_path_len
;
6982 while (q
< end
&& *q
!= ':')
6986 char *new_multilib_os_dir
= xmalloc (end
- q
);
6987 memcpy (new_multilib_os_dir
, q
+ 1, end
- q
- 1);
6988 new_multilib_os_dir
[end
- q
- 1] = '\0';
6989 multilib_os_dir
= new_multilib_os_dir
;
6997 if (multilib_dir
== NULL
&& multilib_os_dir
!= NULL
6998 && strcmp (multilib_os_dir
, ".") == 0)
7000 free ((char *) multilib_os_dir
);
7001 multilib_os_dir
= NULL
;
7003 else if (multilib_dir
!= NULL
&& multilib_os_dir
== NULL
)
7004 multilib_os_dir
= multilib_dir
;
7007 /* Print out the multiple library subdirectory selection
7008 information. This prints out a series of lines. Each line looks
7009 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
7010 required. Only the desired options are printed out, the negative
7011 matches. The options are print without a leading dash. There are
7012 no spaces to make it easy to use the information in the shell.
7013 Each subdirectory is printed only once. This assumes the ordering
7014 generated by the genmultilib script. Also, we leave out ones that match
7018 print_multilib_info ()
7020 const char *p
= multilib_select
;
7021 const char *last_path
= 0, *this_path
;
7023 unsigned int last_path_len
= 0;
7028 /* Ignore newlines. */
7035 /* Get the initial path. */
7044 /* When --disable-multilib was used but target defines
7045 MULTILIB_OSDIRNAMES, entries starting with .: are there just
7046 to find multilib_os_dir, so skip them from output. */
7047 if (this_path
[0] == '.' && this_path
[1] == ':')
7050 /* Check for matches with the multilib_exclusions. We don't bother
7051 with the '!' in either list. If any of the exclusion rules match
7052 all of its options with the select rule, we skip it. */
7054 const char *e
= multilib_exclusions
;
7055 const char *this_arg
;
7060 /* Ignore newlines. */
7067 /* Check the arguments. */
7084 while (*e
!= ' ' && *e
!= ';')
7095 int len
= e
- this_arg
;
7102 while (*q
!= ' ' && *q
!= ';')
7109 if (! strncmp (arg
, this_arg
, (len
< q
- arg
) ? q
- arg
: len
) ||
7110 default_arg (this_arg
, e
- this_arg
))
7140 /* If this is a duplicate, skip it. */
7141 skip
= (last_path
!= 0 && (unsigned int) (p
- this_path
) == last_path_len
7142 && ! strncmp (last_path
, this_path
, last_path_len
));
7144 last_path
= this_path
;
7145 last_path_len
= p
- this_path
;
7148 /* If this directory requires any default arguments, we can skip
7149 it. We will already have printed a directory identical to
7150 this one which does not require that default argument. */
7168 while (*q
!= ' ' && *q
!= ';')
7176 && default_arg (arg
, q
- arg
))
7191 for (p1
= last_path
; p1
< p
&& *p1
!= ':'; p1
++)
7210 use_arg
= *p
!= '!';
7215 while (*p
!= ' ' && *p
!= ';')
7230 /* If there are extra options, print them now. */
7231 if (multilib_extra
&& *multilib_extra
)
7233 int print_at
= TRUE
;
7236 for (q
= multilib_extra
; *q
!= '\0'; q
++)