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
97 #undef TARGET_EXECUTABLE_SUFFIX
98 #define TARGET_EXECUTABLE_SUFFIX ""
101 /* By default there is no special suffix for host executables. */
102 #ifdef HOST_EXECUTABLE_SUFFIX
103 #define HAVE_HOST_EXECUTABLE_SUFFIX
105 #define HOST_EXECUTABLE_SUFFIX ""
108 /* By default, the suffix for target object files is ".o". */
109 #ifdef TARGET_OBJECT_SUFFIX
110 #define HAVE_TARGET_OBJECT_SUFFIX
112 #define TARGET_OBJECT_SUFFIX ".o"
116 /* FIXME: the location independence code for VMS is hairier than this,
117 and hasn't been written. */
123 static const char dir_separator_str
[] = { DIR_SEPARATOR
, 0 };
125 #define obstack_chunk_alloc xmalloc
126 #define obstack_chunk_free free
128 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
129 #ifndef LIBRARY_PATH_ENV
130 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
134 #define kill(p,s) raise(s)
137 /* If a stage of compilation returns an exit status >= 1,
138 compilation of that file ceases. */
140 #define MIN_FATAL_STATUS 1
142 /* Flag set by cppspec.c to 1. */
145 /* Flag saying to pass the greatest exit code returned by a sub-process
146 to the calling program. */
147 static int pass_exit_codes
;
149 /* Definition of string containing the arguments given to configure. */
150 #include "configargs.h"
152 /* Flag saying to print the directories gcc will search through looking for
153 programs, libraries, etc. */
155 static int print_search_dirs
;
157 /* Flag saying to print the full filename of this file
158 as found through our usual search mechanism. */
160 static const char *print_file_name
= NULL
;
162 /* As print_file_name, but search for executable file. */
164 static const char *print_prog_name
= NULL
;
166 /* Flag saying to print the relative path we'd use to
167 find libgcc.a given the current compiler flags. */
169 static int print_multi_directory
;
171 /* Flag saying to print the list of subdirectories and
172 compiler flags used to select them in a standard form. */
174 static int print_multi_lib
;
176 /* Flag saying to print the command line options understood by gcc and its
179 static int print_help_list
;
181 /* Flag indicating whether we should print the command and arguments */
183 static int verbose_flag
;
185 /* Flag indicating whether we should ONLY print the command and
186 arguments (like verbose_flag) without executing the command.
187 Displayed arguments are quoted so that the generated command
188 line is suitable for execution. This is intended for use in
189 shell scripts to capture the driver-generated command line. */
190 static int verbose_only_flag
;
192 /* Flag indicating to print target specific command line options. */
194 static int target_help_flag
;
196 /* Flag indicating whether we should report subprocess execution times
197 (if this is supported by the system - see pexecute.c). */
199 static int report_times
;
201 /* Nonzero means write "temp" files in source directory
202 and use the source file's name in them, and don't delete them. */
204 static int save_temps_flag
;
206 /* The compiler version. */
208 static const char *compiler_version
;
210 /* The target version specified with -V */
212 static const char *const spec_version
= DEFAULT_TARGET_VERSION
;
214 /* The target machine specified with -b. */
216 static const char *spec_machine
= DEFAULT_TARGET_MACHINE
;
218 /* Nonzero if cross-compiling.
219 When -b is used, the value comes from the `specs' file. */
222 static const char *cross_compile
= "1";
224 static const char *cross_compile
= "0";
227 #ifdef MODIFY_TARGET_NAME
229 /* Information on how to alter the target name based on a command-line
230 switch. The only case we support now is simply appending or deleting a
231 string to or from the end of the first part of the configuration name. */
233 static const struct modify_target
235 const char *const sw
;
236 const enum add_del
{ADD
, DELETE
} add_del
;
237 const char *const str
;
239 modify_target
[] = MODIFY_TARGET_NAME
;
242 /* The number of errors that have occurred; the link phase will not be
243 run if this is non-zero. */
244 static int error_count
= 0;
246 /* Greatest exit code of sub-processes that has been encountered up to
248 static int greatest_status
= 1;
250 /* This is the obstack which we use to allocate many strings. */
252 static struct obstack obstack
;
254 /* This is the obstack to build an environment variable to pass to
255 collect2 that describes all of the relevant switches of what to
256 pass the compiler in building the list of pointers to constructors
259 static struct obstack collect_obstack
;
261 /* These structs are used to collect resource usage information for
263 #ifdef HAVE_GETRUSAGE
264 static struct rusage rus
, prus
;
267 /* Forward declaration for prototypes. */
270 static void init_spec
PARAMS ((void));
272 static char **split_directories
PARAMS ((const char *, int *));
273 static void free_split_directories
PARAMS ((char **));
274 static char *make_relative_prefix
PARAMS ((const char *, const char *, const char *));
276 static void store_arg
PARAMS ((const char *, int, int));
277 static char *load_specs
PARAMS ((const char *));
278 static void read_specs
PARAMS ((const char *, int));
279 static void set_spec
PARAMS ((const char *, const char *));
280 static struct compiler
*lookup_compiler
PARAMS ((const char *, size_t, const char *));
281 static char *build_search_list
PARAMS ((struct path_prefix
*, const char *, int));
282 static void putenv_from_prefixes
PARAMS ((struct path_prefix
*, const char *));
283 static int access_check
PARAMS ((const char *, int));
284 static char *find_a_file
PARAMS ((struct path_prefix
*, const char *, int));
285 static void add_prefix
PARAMS ((struct path_prefix
*, const char *,
286 const char *, 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 const char *find_file
PARAMS ((const char *));
300 static int is_directory
PARAMS ((const char *, const char *, int));
301 static void validate_switches
PARAMS ((const char *));
302 static void validate_all_switches
PARAMS ((void));
303 static void give_switch
PARAMS ((int, int, int));
304 static int used_arg
PARAMS ((const char *, int));
305 static int default_arg
PARAMS ((const char *, int));
306 static void set_multilib_dir
PARAMS ((void));
307 static void print_multilib_info
PARAMS ((void));
308 static void perror_with_name
PARAMS ((const char *));
309 static void pfatal_pexecute
PARAMS ((const char *, const char *))
311 static void notice
PARAMS ((const char *, ...))
313 static void display_help
PARAMS ((void));
314 static void add_preprocessor_option
PARAMS ((const char *, int));
315 static void add_assembler_option
PARAMS ((const char *, int));
316 static void add_linker_option
PARAMS ((const char *, int));
317 static void process_command
PARAMS ((int, const char *const *));
318 static int execute
PARAMS ((void));
319 static void clear_args
PARAMS ((void));
320 static void fatal_error
PARAMS ((int));
321 #ifdef ENABLE_SHARED_LIBGCC
322 static void init_gcc_specs
PARAMS ((struct obstack
*,
323 const char *, const char *,
326 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
327 static const char *convert_filename
PARAMS ((const char *, int, int));
330 /* The Specs Language
332 Specs are strings containing lines, each of which (if not blank)
333 is made up of a program name, and arguments separated by spaces.
334 The program name must be exact and start from root, since no path
335 is searched and it is unreliable to depend on the current working directory.
336 Redirection of input or output is not supported; the subprograms must
337 accept filenames saying what files to read and write.
339 In addition, the specs can contain %-sequences to substitute variable text
340 or for conditional text. Here is a table of all defined %-sequences.
341 Note that spaces are not generated automatically around the results of
342 expanding these sequences; therefore, you can concatenate them together
343 or with constant text in a single argument.
345 %% substitute one % into the program name or argument.
346 %i substitute the name of the input file being processed.
347 %b substitute the basename of the input file being processed.
348 This is the substring up to (and not including) the last period
349 and not including the directory.
350 %B same as %b, but include the file suffix (text after the last period).
352 substitute a file name that has suffix SUFFIX and is chosen
353 once per compilation, and mark the argument a la %d. To reduce
354 exposure to denial-of-service attacks, the file name is now
355 chosen in a way that is hard to predict even when previously
356 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
357 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
358 the regexp "[.A-Za-z]*%O"; "%O" is treated exactly as if it
359 had been pre-processed. Previously, %g was simply substituted
360 with a file name chosen once per compilation, without regard
361 to any appended suffix (which was therefore treated just like
362 ordinary text), making such attacks more likely to succeed.
364 like %g, but generates a new temporary file name even if %uSUFFIX
367 substitutes the last file name generated with %uSUFFIX, generating a
368 new one if there is no such last file name. In the absence of any
369 %uSUFFIX, this is just like %gSUFFIX, except they don't share
370 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
371 would involve the generation of two distinct file names, one
372 for each `%g.s' and another for each `%U.s'. Previously, %U was
373 simply substituted with a file name chosen for the previous %u,
374 without regard to any appended suffix.
376 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
377 writable, and if save-temps is off; otherwise, substitute the name
378 of a temporary file, just like %u. This temporary file is not
379 meant for communication between processes, but rather as a junk
382 substitutes .SUFFIX for the suffixes of a matched switch's args when
383 it is subsequently output with %*. SUFFIX is terminated by the next
385 %d marks the argument containing or following the %d as a
386 temporary file name, so that that file will be deleted if CC exits
387 successfully. Unlike %g, this contributes no text to the argument.
388 %w marks the argument containing or following the %w as the
389 "output file" of this compilation. This puts the argument
390 into the sequence of arguments that %o will substitute later.
392 like %{...} but mark last argument supplied within
393 as a file to be deleted on failure.
394 %o substitutes the names of all the output files, with spaces
395 automatically placed around them. You should write spaces
396 around the %o as well or the results are undefined.
397 %o is for use in the specs for running the linker.
398 Input files whose names have no recognized suffix are not compiled
399 at all, but they are included among the output files, so they will
401 %O substitutes the suffix for object files. Note that this is
402 handled specially when it immediately follows %g, %u, or %U
403 (with or without a suffix argument) because of the need for
404 those to form complete file names. The handling is such that
405 %O is treated exactly as if it had already been substituted,
406 except that %g, %u, and %U do not currently support additional
407 SUFFIX characters following %O as they would following, for
409 %p substitutes the standard macro predefinitions for the
410 current target machine. Use this when running cpp.
411 %P like %p, but puts `__' before and after the name of each macro.
412 (Except macros that already have __.)
414 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX.
415 %s current argument is the name of a library or startup file of some sort.
416 Search for that file in a standard list of directories
417 and substitute the full name found.
418 %eSTR Print STR as an error message. STR is terminated by a newline.
419 Use this when inconsistent options are detected.
420 %nSTR Print STR as an notice. STR is terminated by a newline.
421 %x{OPTION} Accumulate an option for %X.
422 %X Output the accumulated linker options specified by compilations.
423 %Y Output the accumulated assembler options specified by compilations.
424 %Z Output the accumulated preprocessor options specified by compilations.
425 %v1 Substitute the major version number of GCC.
426 (For version 2.5.3, this is 2.)
427 %v2 Substitute the minor version number of GCC.
428 (For version 2.5.3, this is 5.)
429 %v3 Substitute the patch level number of GCC.
430 (For version 2.5.3, this is 3.)
431 %a process ASM_SPEC as a spec.
432 This allows config.h to specify part of the spec for running as.
433 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
434 used here. This can be used to run a post-processor after the
435 assembler has done its job.
436 %D Dump out a -L option for each directory in startfile_prefixes.
437 If multilib_dir is set, extra entries are generated with it affixed.
438 %l process LINK_SPEC as a spec.
439 %L process LIB_SPEC as a spec.
440 %G process LIBGCC_SPEC as a spec.
441 %M output multilib_dir with directory separators replaced with "_";
442 if multilib_dir is not set or is ".", output "".
443 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
444 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
445 %C process CPP_SPEC as a spec.
446 %1 process CC1_SPEC as a spec.
447 %2 process CC1PLUS_SPEC as a spec.
448 %| output "-" if the input for the current command is coming from a pipe.
449 %* substitute the variable part of a matched option. (See below.)
450 Note that each comma in the substituted string is replaced by
452 %{S} substitutes the -S switch, if that switch was given to CC.
453 If that switch was not specified, this substitutes nothing.
454 Here S is a metasyntactic variable.
455 %{S*} substitutes all the switches specified to CC whose names start
456 with -S. This is used for -o, -I, etc; switches that take
457 arguments. CC considers `-o foo' as being one switch whose
458 name starts with `o'. %{o*} would substitute this text,
459 including the space; thus, two arguments would be generated.
460 %{^S*} likewise, but don't put a blank between a switch and any args.
461 %{S*&T*} likewise, but preserve order of S and T options (the order
462 of S and T in the spec is not significant). Can be any number
463 of ampersand-separated variables; for each the wild card is
464 optional. Useful for CPP as %{D*&U*&A*}.
465 %{S*:X} substitutes X if one or more switches whose names start with -S are
466 specified to CC. Note that the tail part of the -S option
467 (i.e. the part matched by the `*') will be substituted for each
468 occurrence of %* within X.
469 %{<S} remove all occurrences of -S from the command line.
470 Note - this option is position dependent. % commands in the
471 spec string before this option will see -S, % commands in the
472 spec string after this option will not.
473 %{S:X} substitutes X, but only if the -S switch was given to CC.
474 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
475 %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
476 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
477 %{.S:X} substitutes X, but only if processing a file with suffix S.
478 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
479 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be
480 combined with ! and . as above binding stronger than the OR.
481 %(Spec) processes a specification defined in a specs file as *Spec:
482 %[Spec] as above, but put __ around -D arguments
484 The conditional text X in a %{S:X} or %{!S:X} construct may contain
485 other nested % constructs or spaces, or even newlines. They are
486 processed as usual, as described above.
488 The -O, -f, -m, and -W switches are handled specifically in these
489 constructs. If another value of -O or the negated form of a -f, -m, or
490 -W switch is found later in the command line, the earlier switch
491 value is ignored, except with {S*} where S is just one letter; this
492 passes all matching options.
494 The character | at the beginning of the predicate text is used to indicate
495 that a command should be piped to the following command, but only if -pipe
498 Note that it is built into CC which switches take arguments and which
499 do not. You might think it would be useful to generalize this to
500 allow each compiler's spec to say which switches take arguments. But
501 this cannot be done in a consistent fashion. CC cannot even decide
502 which input files have been specified without knowing which switches
503 take arguments, and it must know which input files to compile in order
504 to tell which compilers to run.
506 CC also knows implicitly that arguments starting in `-l' are to be
507 treated as compiler output files, and passed to the linker in their
508 proper position among the other output files. */
510 /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
512 /* config.h can define ASM_SPEC to provide extra args to the assembler
513 or extra switch-translations. */
518 /* config.h can define ASM_FINAL_SPEC to run a post processor after
519 the assembler has run. */
520 #ifndef ASM_FINAL_SPEC
521 #define ASM_FINAL_SPEC ""
524 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
525 or extra switch-translations. */
530 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
531 or extra switch-translations. */
536 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
537 or extra switch-translations. */
539 #define CC1PLUS_SPEC ""
542 /* config.h can define LINK_SPEC to provide extra args to the linker
543 or extra switch-translations. */
548 /* config.h can define LIB_SPEC to override the default libraries. */
550 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
553 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
556 #if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1)
557 /* Have gcc do the search for libgcc.a. */
558 #define LIBGCC_SPEC "libgcc.a%s"
560 #define LIBGCC_SPEC "-lgcc"
564 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
565 #ifndef STARTFILE_SPEC
566 #define STARTFILE_SPEC \
567 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
570 /* config.h can define SWITCHES_NEED_SPACES to control which options
571 require spaces between the option and the argument. */
572 #ifndef SWITCHES_NEED_SPACES
573 #define SWITCHES_NEED_SPACES ""
576 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
578 #define ENDFILE_SPEC ""
582 #define LINKER_NAME "collect2"
585 /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
587 #ifndef ASM_DEBUG_SPEC
588 # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
589 && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
590 # define ASM_DEBUG_SPEC \
591 (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
592 ? "%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}" \
593 : "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}")
595 # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
596 # define ASM_DEBUG_SPEC "%{g*:--gstabs}"
598 # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
599 # define ASM_DEBUG_SPEC "%{g*:--gdwarf2}"
603 #ifndef ASM_DEBUG_SPEC
604 # define ASM_DEBUG_SPEC ""
607 /* Here is the spec for running the linker, after compiling all files. */
609 /* This is overridable by the target in case they need to specify the
610 -lgcc and -lc order specially, yet not require them to override all
611 of LINK_COMMAND_SPEC. */
612 #ifndef LINK_GCC_C_SEQUENCE_SPEC
613 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
616 /* -u* was put back because both BSD and SysV seem to support it. */
617 /* %{static:} simply prevents an error message if the target machine
618 doesn't handle -static. */
619 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
620 scripts which exist in user specified directories, or in standard
622 #ifndef LINK_COMMAND_SPEC
623 #define LINK_COMMAND_SPEC "\
624 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
625 %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
626 %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
627 %{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
628 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
631 #ifndef LINK_LIBGCC_SPEC
632 # ifdef LINK_LIBGCC_SPECIAL
633 /* Don't generate -L options for startfile prefix list. */
634 # define LINK_LIBGCC_SPEC ""
636 /* Do generate them. */
637 # define LINK_LIBGCC_SPEC "%D"
641 #ifndef STARTFILE_PREFIX_SPEC
642 # define STARTFILE_PREFIX_SPEC ""
645 static const char *asm_debug
;
646 static const char *cpp_spec
= CPP_SPEC
;
647 static const char *cpp_predefines
= CPP_PREDEFINES
;
648 static const char *cc1_spec
= CC1_SPEC
;
649 static const char *cc1plus_spec
= CC1PLUS_SPEC
;
650 static const char *link_gcc_c_sequence_spec
= LINK_GCC_C_SEQUENCE_SPEC
;
651 static const char *asm_spec
= ASM_SPEC
;
652 static const char *asm_final_spec
= ASM_FINAL_SPEC
;
653 static const char *link_spec
= LINK_SPEC
;
654 static const char *lib_spec
= LIB_SPEC
;
655 static const char *libgcc_spec
= LIBGCC_SPEC
;
656 static const char *endfile_spec
= ENDFILE_SPEC
;
657 static const char *startfile_spec
= STARTFILE_SPEC
;
658 static const char *switches_need_spaces
= SWITCHES_NEED_SPACES
;
659 static const char *linker_name_spec
= LINKER_NAME
;
660 static const char *link_command_spec
= LINK_COMMAND_SPEC
;
661 static const char *link_libgcc_spec
= LINK_LIBGCC_SPEC
;
662 static const char *startfile_prefix_spec
= STARTFILE_PREFIX_SPEC
;
664 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
665 There should be no need to override these in target dependent files,
666 but we need to copy them to the specs file so that newer versions
667 of the GCC driver can correctly drive older tool chains with the
668 appropriate -B options. */
670 /* When cpplib handles traditional preprocessing, get rid of this, and
671 call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
672 that we default the front end language better. */
673 static const char *trad_capable_cpp
=
674 "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}";
676 static const char *cpp_unique_options
=
677 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
678 %{CC:%{!E:%eGNU C does not support -CC without using -E}}\
679 %{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*} %{P} %{$} %I\
680 %{MD:-MD %W{!o: %b.d}%W{o*:%.d%*}}\
681 %{MMD:-MMD %W{!o: %b.d}%W{o*:%.d%*}}\
682 %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
683 %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\
684 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
685 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
686 %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
689 /* This contains cpp options which are common with cc1_options and are passed
690 only when preprocessing only to avoid duplication. We pass the cc1 spec
691 options to the preprocessor so that it the cc1 spec may manipulate
692 options used to set target flags. Those special target flags settings may
693 in turn cause preprocessor symbols to be defined specially. */
694 static const char *cpp_options
=
695 "%(cpp_unique_options) %1 %{std*} %{W*&pedantic*} %{w} %{m*} %{f*}\
698 /* This contains cpp options which are not passed when the preprocessor
699 output will be used by another program. */
700 static const char *cpp_debug_options
= "%{d*}";
702 /* NB: This is shared amongst all front-ends. */
703 static const char *cc1_options
=
704 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
705 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
706 %{g*} %{O*} %{W*&pedantic*} %{w} %{std*} %{ansi}\
707 %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
708 %{Qn:-fno-ident} %{--help:--help}\
709 %{--target-help:--target-help}\
710 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
711 %{fsyntax-only:-o %j} %{-param*}";
713 static const char *asm_options
=
714 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
716 static const char *invoke_as
=
717 "%{!S:-o %{|!pipe:%g.s} |\n as %(asm_options) %{!pipe:%g.s} %A }";
719 /* Some compilers have limits on line lengths, and the multilib_select
720 and/or multilib_matches strings can be very long, so we build them at
722 static struct obstack multilib_obstack
;
723 static const char *multilib_select
;
724 static const char *multilib_matches
;
725 static const char *multilib_defaults
;
726 static const char *multilib_exclusions
;
727 #include "multilib.h"
729 /* Check whether a particular argument is a default argument. */
731 #ifndef MULTILIB_DEFAULTS
732 #define MULTILIB_DEFAULTS { "" }
735 static const char *const multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
739 struct user_specs
*next
;
740 const char *filename
;
743 static struct user_specs
*user_specs_head
, *user_specs_tail
;
745 /* This defines which switch letters take arguments. */
747 #define DEFAULT_SWITCH_TAKES_ARG(CHAR) \
748 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
749 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
750 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \
751 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'B' || (CHAR) == 'b')
753 #ifndef SWITCH_TAKES_ARG
754 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
757 /* This defines which multi-letter switches take arguments. */
759 #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \
760 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \
761 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \
762 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
763 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
764 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
765 || !strcmp (STR, "isystem") || !strcmp (STR, "-param") \
766 || !strcmp (STR, "specs") \
767 || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
769 #ifndef WORD_SWITCH_TAKES_ARG
770 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
773 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
774 /* This defines which switches stop a full compilation. */
775 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
776 ((CHAR) == 'c' || (CHAR) == 'S')
778 #ifndef SWITCH_CURTAILS_COMPILATION
779 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
780 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
784 /* Record the mapping from file suffixes for compilation specs. */
788 const char *suffix
; /* Use this compiler for input files
789 whose names end in this suffix. */
791 const char *spec
; /* To use this compiler, run this spec. */
793 const char *cpp_spec
; /* If non-NULL, substitute this spec
794 for `%C', rather than the usual
798 /* Pointer to a vector of `struct compiler' that gives the spec for
799 compiling a file, based on its suffix.
800 A file that does not end in any of these suffixes will be passed
801 unchanged to the loader and nothing else will be done to it.
803 An entry containing two 0s is used to terminate the vector.
805 If multiple entries match a file, the last matching one is used. */
807 static struct compiler
*compilers
;
809 /* Number of entries in `compilers', not counting the null terminator. */
811 static int n_compilers
;
813 /* The default list of file name suffixes and their compilation specs. */
815 static const struct compiler default_compilers
[] =
817 /* Add lists of suffixes of known languages here. If those languages
818 were not present when we built the driver, we will hit these copies
819 and be given a more meaningful error than "file not used since
820 linking is not done". */
821 {".m", "#Objective-C", 0}, {".mi", "#Objective-C", 0},
822 {".cc", "#C++", 0}, {".cxx", "#C++", 0}, {".cpp", "#C++", 0},
823 {".cp", "#C++", 0}, {".c++", "#C++", 0}, {".C", "#C++", 0},
825 {".ads", "#Ada", 0}, {".adb", "#Ada", 0},
826 {".f", "#Fortran", 0}, {".for", "#Fortran", 0}, {".fpp", "#Fortran", 0},
827 {".F", "#Fortran", 0}, {".FOR", "#Fortran", 0}, {".FPP", "#Fortran", 0},
828 {".r", "#Ratfor", 0},
829 {".p", "#Pascal", 0}, {".pas", "#Pascal", 0},
830 {".java", "#Java", 0}, {".class", "#Java", 0},
831 {".zip", "#Java", 0}, {".jar", "#Java", 0},
832 /* Next come the entries for C. */
835 /* cc1 has an integrated ISO C preprocessor. We should invoke the
836 external preprocessor if -save-temps is given. */
837 "%{E|M|MM:%(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options)\
838 %(cpp_debug_options)}\
840 %{traditional|ftraditional:\
841 %eGNU C no longer supports -traditional without -E}\
842 %{save-temps|traditional-cpp:%(trad_capable_cpp) \
843 %{ansi:-std=c89} %(cpp_options) %b.i \n\
844 cc1 -fpreprocessed %b.i %(cc1_options)}\
845 %{!save-temps:%{!traditional-cpp:\
846 cc1 %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}}\
847 %{!fsyntax-only:%(invoke_as)}}}}", 0},
849 "%{!E:%e-E required when input is from standard input}\
850 %(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options)", 0},
851 {".h", "@c-header", 0},
853 "%{!E:%ecompilation of header file requested} \
854 %(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options) %(cpp_debug_options)",
856 {".i", "@cpp-output", 0},
858 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0},
859 {".s", "@assembler", 0},
861 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0},
862 {".S", "@assembler-with-cpp", 0},
863 {"@assembler-with-cpp",
864 "%(trad_capable_cpp) -lang-asm %(cpp_options)\
865 %{E|M|MM:%(cpp_debug_options)}\
866 %{!M:%{!MM:%{!E:%{!S:-o %{|!pipe:%g.s} |\n\
867 as %(asm_debug) %(asm_options) %{!pipe:%g.s} %A }}}}", 0},
869 /* Mark end of table */
873 /* Number of elements in default_compilers, not counting the terminator. */
875 static const int n_default_compilers
= ARRAY_SIZE (default_compilers
) - 1;
877 /* A vector of options to give to the linker.
878 These options are accumulated by %x,
879 and substituted into the linker command with %X. */
880 static int n_linker_options
;
881 static char **linker_options
;
883 /* A vector of options to give to the assembler.
884 These options are accumulated by -Wa,
885 and substituted into the assembler command with %Y. */
886 static int n_assembler_options
;
887 static char **assembler_options
;
889 /* A vector of options to give to the preprocessor.
890 These options are accumulated by -Wp,
891 and substituted into the preprocessor command with %Z. */
892 static int n_preprocessor_options
;
893 static char **preprocessor_options
;
895 /* Define how to map long options into short ones. */
897 /* This structure describes one mapping. */
900 /* The long option's name. */
901 const char *const name
;
902 /* The equivalent short option. */
903 const char *const equivalent
;
904 /* Argument info. A string of flag chars; NULL equals no options.
905 a => argument required.
906 o => argument optional.
907 j => join argument to equivalent, making one word.
908 * => require other text after NAME as an argument. */
909 const char *const arg_info
;
912 /* This is the table of mappings. Mappings are tried sequentially
913 for each option encountered; the first one that matches, wins. */
915 static const struct option_map option_map
[] =
917 {"--all-warnings", "-Wall", 0},
918 {"--ansi", "-ansi", 0},
919 {"--assemble", "-S", 0},
920 {"--assert", "-A", "a"},
921 {"--classpath", "-fclasspath=", "aj"},
922 {"--bootclasspath", "-fbootclasspath=", "aj"},
923 {"--CLASSPATH", "-fclasspath=", "aj"},
924 {"--comments", "-C", 0},
925 {"--comments-in-macros", "-CC", 0},
926 {"--compile", "-c", 0},
927 {"--debug", "-g", "oj"},
928 {"--define-macro", "-D", "aj"},
929 {"--dependencies", "-M", 0},
930 {"--dump", "-d", "a"},
931 {"--dumpbase", "-dumpbase", "a"},
932 {"--entry", "-e", 0},
933 {"--extra-warnings", "-W", 0},
934 {"--for-assembler", "-Wa", "a"},
935 {"--for-linker", "-Xlinker", "a"},
936 {"--force-link", "-u", "a"},
937 {"--imacros", "-imacros", "a"},
938 {"--include", "-include", "a"},
939 {"--include-barrier", "-I-", 0},
940 {"--include-directory", "-I", "aj"},
941 {"--include-directory-after", "-idirafter", "a"},
942 {"--include-prefix", "-iprefix", "a"},
943 {"--include-with-prefix", "-iwithprefix", "a"},
944 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
945 {"--include-with-prefix-after", "-iwithprefix", "a"},
946 {"--language", "-x", "a"},
947 {"--library-directory", "-L", "a"},
948 {"--machine", "-m", "aj"},
949 {"--machine-", "-m", "*j"},
950 {"--no-line-commands", "-P", 0},
951 {"--no-precompiled-includes", "-noprecomp", 0},
952 {"--no-standard-includes", "-nostdinc", 0},
953 {"--no-standard-libraries", "-nostdlib", 0},
954 {"--no-warnings", "-w", 0},
955 {"--optimize", "-O", "oj"},
956 {"--output", "-o", "a"},
957 {"--output-class-directory", "-foutput-class-dir=", "ja"},
958 {"--param", "--param", "a"},
959 {"--pedantic", "-pedantic", 0},
960 {"--pedantic-errors", "-pedantic-errors", 0},
961 {"--pipe", "-pipe", 0},
962 {"--prefix", "-B", "a"},
963 {"--preprocess", "-E", 0},
964 {"--print-search-dirs", "-print-search-dirs", 0},
965 {"--print-file-name", "-print-file-name=", "aj"},
966 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
967 {"--print-missing-file-dependencies", "-MG", 0},
968 {"--print-multi-lib", "-print-multi-lib", 0},
969 {"--print-multi-directory", "-print-multi-directory", 0},
970 {"--print-prog-name", "-print-prog-name=", "aj"},
971 {"--profile", "-p", 0},
972 {"--profile-blocks", "-a", 0},
973 {"--quiet", "-q", 0},
974 {"--resource", "-fcompile-resource=", "aj"},
975 {"--save-temps", "-save-temps", 0},
976 {"--shared", "-shared", 0},
977 {"--silent", "-q", 0},
978 {"--specs", "-specs=", "aj"},
979 {"--static", "-static", 0},
980 {"--std", "-std=", "aj"},
981 {"--symbolic", "-symbolic", 0},
982 {"--target", "-b", "a"},
983 {"--time", "-time", 0},
984 {"--trace-includes", "-H", 0},
985 {"--traditional", "-traditional", 0},
986 {"--traditional-cpp", "-traditional-cpp", 0},
987 {"--trigraphs", "-trigraphs", 0},
988 {"--undefine-macro", "-U", "aj"},
989 {"--use-version", "-V", "a"},
990 {"--user-dependencies", "-MM", 0},
991 {"--verbose", "-v", 0},
992 {"--warn-", "-W", "*j"},
993 {"--write-dependencies", "-MD", 0},
994 {"--write-user-dependencies", "-MMD", 0},
999 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1000 static const struct {
1001 const char *const option_found
;
1002 const char *const replacements
;
1003 } target_option_translations
[] =
1005 TARGET_OPTION_TRANSLATE_TABLE
,
1010 /* Translate the options described by *ARGCP and *ARGVP.
1011 Make a new vector and store it back in *ARGVP,
1012 and store its length in *ARGVC. */
1015 translate_options (argcp
, argvp
)
1017 const char *const **argvp
;
1021 const char *const *argv
= *argvp
;
1022 int newvsize
= (argc
+ 2) * 2 * sizeof (const char *);
1024 (const char **) xmalloc (newvsize
);
1028 newv
[newindex
++] = argv
[i
++];
1032 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1036 target_option_translations
[tott_idx
].option_found
;
1039 if (strcmp (target_option_translations
[tott_idx
].option_found
,
1046 for (sp
= target_option_translations
[tott_idx
].replacements
;
1053 newvsize
+= spaces
* sizeof (const char *);
1054 newv
= (const char **) xrealloc (newv
, newvsize
);
1056 sp
= target_option_translations
[tott_idx
].replacements
;
1065 newv
[newindex
++] = np
;
1066 while (*np
!= ' ' && *np
)
1077 if (target_option_translations
[tott_idx
].option_found
)
1081 /* Translate -- options. */
1082 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
1085 /* Find a mapping that applies to this option. */
1086 for (j
= 0; j
< ARRAY_SIZE (option_map
); j
++)
1088 size_t optlen
= strlen (option_map
[j
].name
);
1089 size_t arglen
= strlen (argv
[i
]);
1090 size_t complen
= arglen
> optlen
? optlen
: arglen
;
1091 const char *arginfo
= option_map
[j
].arg_info
;
1096 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
1098 const char *arg
= 0;
1100 if (arglen
< optlen
)
1103 for (k
= j
+ 1; k
< ARRAY_SIZE (option_map
); k
++)
1104 if (strlen (option_map
[k
].name
) >= arglen
1105 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
1107 error ("ambiguous abbreviation %s", argv
[i
]);
1111 if (k
!= ARRAY_SIZE (option_map
))
1115 if (arglen
> optlen
)
1117 /* If the option has an argument, accept that. */
1118 if (argv
[i
][optlen
] == '=')
1119 arg
= argv
[i
] + optlen
+ 1;
1121 /* If this mapping requires extra text at end of name,
1122 accept that as "argument". */
1123 else if (strchr (arginfo
, '*') != 0)
1124 arg
= argv
[i
] + optlen
;
1126 /* Otherwise, extra text at end means mismatch.
1127 Try other mappings. */
1132 else if (strchr (arginfo
, '*') != 0)
1134 error ("incomplete `%s' option", option_map
[j
].name
);
1138 /* Handle arguments. */
1139 if (strchr (arginfo
, 'a') != 0)
1145 error ("missing argument to `%s' option",
1146 option_map
[j
].name
);
1153 else if (strchr (arginfo
, '*') != 0)
1155 else if (strchr (arginfo
, 'o') == 0)
1158 error ("extraneous argument to `%s' option",
1159 option_map
[j
].name
);
1163 /* Store the translation as one argv elt or as two. */
1164 if (arg
!= 0 && strchr (arginfo
, 'j') != 0)
1165 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
1169 newv
[newindex
++] = option_map
[j
].equivalent
;
1170 newv
[newindex
++] = arg
;
1173 newv
[newindex
++] = option_map
[j
].equivalent
;
1181 /* Handle old-fashioned options--just copy them through,
1182 with their arguments. */
1183 else if (argv
[i
][0] == '-')
1185 const char *p
= argv
[i
] + 1;
1189 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1190 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1191 else if (WORD_SWITCH_TAKES_ARG (p
))
1192 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
1193 else if ((c
== 'B' || c
== 'b' || c
== 'x')
1196 else if (! strcmp (p
, "Xlinker"))
1199 /* Watch out for an option at the end of the command line that
1200 is missing arguments, and avoid skipping past the end of the
1202 if (nskip
+ i
> argc
)
1207 newv
[newindex
++] = argv
[i
++];
1212 /* Ordinary operands, or +e options. */
1213 newv
[newindex
++] = argv
[i
++];
1228 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1229 be considered whitespace. */
1230 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1232 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1246 /* Structures to keep track of prefixes to try when looking for files. */
1250 const char *prefix
; /* String to prepend to the path. */
1251 struct prefix_list
*next
; /* Next in linked list. */
1252 int require_machine_suffix
; /* Don't use without machine_suffix. */
1253 /* 2 means try both machine_suffix and just_machine_suffix. */
1254 int *used_flag_ptr
; /* 1 if a file was found with this prefix. */
1255 int priority
; /* Sort key - priority within list */
1260 struct prefix_list
*plist
; /* List of prefixes to try */
1261 int max_len
; /* Max length of a prefix in PLIST */
1262 const char *name
; /* Name of this list (used in config stuff) */
1265 /* List of prefixes to try when looking for executables. */
1267 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1269 /* List of prefixes to try when looking for startup (crt0) files. */
1271 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1273 /* List of prefixes to try when looking for include files. */
1275 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1277 /* Suffix to attach to directories searched for commands.
1278 This looks like `MACHINE/VERSION/'. */
1280 static const char *machine_suffix
= 0;
1282 /* Suffix to attach to directories searched for commands.
1283 This is just `MACHINE/'. */
1285 static const char *just_machine_suffix
= 0;
1287 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1289 static const char *gcc_exec_prefix
;
1291 /* Default prefixes to attach to command names. */
1293 #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */
1294 #undef MD_EXEC_PREFIX
1295 #undef MD_STARTFILE_PREFIX
1296 #undef MD_STARTFILE_PREFIX_1
1299 /* If no prefixes defined, use the null string, which will disable them. */
1300 #ifndef MD_EXEC_PREFIX
1301 #define MD_EXEC_PREFIX ""
1303 #ifndef MD_STARTFILE_PREFIX
1304 #define MD_STARTFILE_PREFIX ""
1306 #ifndef MD_STARTFILE_PREFIX_1
1307 #define MD_STARTFILE_PREFIX_1 ""
1310 /* Supply defaults for the standard prefixes. */
1312 #ifndef STANDARD_EXEC_PREFIX
1313 #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/"
1315 #ifndef STANDARD_STARTFILE_PREFIX
1316 #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/"
1318 #ifndef TOOLDIR_BASE_PREFIX
1319 #define TOOLDIR_BASE_PREFIX "/usr/local/"
1321 #ifndef STANDARD_BINDIR_PREFIX
1322 #define STANDARD_BINDIR_PREFIX "/usr/local/bin"
1325 static const char *const standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1326 static const char *const standard_exec_prefix_1
= "/usr/lib/gcc/";
1327 static const char *md_exec_prefix
= MD_EXEC_PREFIX
;
1329 static const char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1330 static const char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1331 static const char *const standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1332 static const char *const standard_startfile_prefix_1
= "/lib/";
1333 static const char *const standard_startfile_prefix_2
= "/usr/lib/";
1335 static const char *const tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1336 static const char *tooldir_prefix
;
1338 static const char *const standard_bindir_prefix
= STANDARD_BINDIR_PREFIX
;
1340 /* Subdirectory to use for locating libraries. Set by
1341 set_multilib_dir based on the compilation options. */
1343 static const char *multilib_dir
;
1345 /* Structure to keep track of the specs that have been defined so far.
1346 These are accessed using %(specname) or %[specname] in a compiler
1351 /* The following 2 fields must be first */
1352 /* to allow EXTRA_SPECS to be initialized */
1353 const char *name
; /* name of the spec. */
1354 const char *ptr
; /* available ptr if no static pointer */
1356 /* The following fields are not initialized */
1357 /* by EXTRA_SPECS */
1358 const char **ptr_spec
; /* pointer to the spec itself. */
1359 struct spec_list
*next
; /* Next spec in linked list. */
1360 int name_len
; /* length of the name */
1361 int alloc_p
; /* whether string was allocated */
1364 #define INIT_STATIC_SPEC(NAME,PTR) \
1365 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1367 /* List of statically defined specs. */
1368 static struct spec_list static_specs
[] =
1370 INIT_STATIC_SPEC ("asm", &asm_spec
),
1371 INIT_STATIC_SPEC ("asm_debug", &asm_debug
),
1372 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1373 INIT_STATIC_SPEC ("asm_options", &asm_options
),
1374 INIT_STATIC_SPEC ("invoke_as", &invoke_as
),
1375 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1376 INIT_STATIC_SPEC ("cpp_options", &cpp_options
),
1377 INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options
),
1378 INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options
),
1379 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp
),
1380 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1381 INIT_STATIC_SPEC ("cc1_options", &cc1_options
),
1382 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1383 INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec
),
1384 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1385 INIT_STATIC_SPEC ("link", &link_spec
),
1386 INIT_STATIC_SPEC ("lib", &lib_spec
),
1387 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1388 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1389 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces
),
1390 INIT_STATIC_SPEC ("predefines", &cpp_predefines
),
1391 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1392 INIT_STATIC_SPEC ("version", &compiler_version
),
1393 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1394 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1395 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1396 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1397 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions
),
1398 INIT_STATIC_SPEC ("linker", &linker_name_spec
),
1399 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec
),
1400 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix
),
1401 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix
),
1402 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1
),
1403 INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec
),
1406 #ifdef EXTRA_SPECS /* additional specs needed */
1407 /* Structure to keep track of just the first two args of a spec_list.
1408 That is all that the EXTRA_SPECS macro gives us. */
1411 const char *const name
;
1412 const char *const ptr
;
1415 static const struct spec_list_1 extra_specs_1
[] = { EXTRA_SPECS
};
1416 static struct spec_list
*extra_specs
= (struct spec_list
*) 0;
1419 /* List of dynamically allocates specs that have been defined so far. */
1421 static struct spec_list
*specs
= (struct spec_list
*) 0;
1423 /* Add appropriate libgcc specs to OBSTACK, taking into account
1424 various permutations of -shared-libgcc, -shared, and such. */
1426 #ifdef ENABLE_SHARED_LIBGCC
1428 init_gcc_specs (obstack
, shared_name
, static_name
, eh_name
)
1429 struct obstack
*obstack
;
1430 const char *shared_name
;
1431 const char *static_name
;
1432 const char *eh_name
;
1436 buf
= concat ("%{static|static-libgcc:", static_name
, " ", eh_name
,
1437 "}%{!static:%{!static-libgcc:",
1438 "%{!shared:%{!shared-libgcc:", static_name
, " ",
1439 eh_name
, "}%{shared-libgcc:", shared_name
, " ",
1440 static_name
, "}}%{shared:",
1442 "%{shared-libgcc:", shared_name
,
1443 "}%{!shared-libgcc:", static_name
, "}",
1449 obstack_grow (obstack
, buf
, strlen (buf
));
1452 #endif /* ENABLE_SHARED_LIBGCC */
1454 /* Initialize the specs lookup routines. */
1459 struct spec_list
*next
= (struct spec_list
*) 0;
1460 struct spec_list
*sl
= (struct spec_list
*) 0;
1464 return; /* Already initialized. */
1467 notice ("Using built-in specs.\n");
1470 extra_specs
= (struct spec_list
*)
1471 xcalloc (sizeof (struct spec_list
), ARRAY_SIZE (extra_specs_1
));
1473 for (i
= ARRAY_SIZE (extra_specs_1
) - 1; i
>= 0; i
--)
1475 sl
= &extra_specs
[i
];
1476 sl
->name
= extra_specs_1
[i
].name
;
1477 sl
->ptr
= extra_specs_1
[i
].ptr
;
1479 sl
->name_len
= strlen (sl
->name
);
1480 sl
->ptr_spec
= &sl
->ptr
;
1485 /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes
1486 on ?: in file-scope variable initializations. */
1487 asm_debug
= ASM_DEBUG_SPEC
;
1489 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1491 sl
= &static_specs
[i
];
1496 #ifdef ENABLE_SHARED_LIBGCC
1497 /* ??? If neither -shared-libgcc nor --static-libgcc was
1498 seen, then we should be making an educated guess. Some proposed
1499 heuristics for ELF include:
1501 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1502 program will be doing dynamic loading, which will likely
1503 need the shared libgcc.
1505 (2) If "-ldl", then it's also a fair bet that we're doing
1508 (3) For each ET_DYN we're linking against (either through -lfoo
1509 or /some/path/foo.so), check to see whether it or one of
1510 its dependencies depends on a shared libgcc.
1514 If the runtime is fixed to look for program headers instead
1515 of calling __register_frame_info at all, for each object,
1516 use the shared libgcc if any EH symbol referenced.
1518 If crtstuff is fixed to not invoke __register_frame_info
1519 automatically, for each object, use the shared libgcc if
1520 any non-empty unwind section found.
1522 Doing any of this probably requires invoking an external program to
1523 do the actual object file scanning. */
1525 const char *p
= libgcc_spec
;
1528 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1529 when given the proper command line arguments. */
1532 if (in_sep
&& *p
== '-' && strncmp (p
, "-lgcc", 5) == 0)
1534 init_gcc_specs (&obstack
,
1535 #ifdef NO_SHARED_LIBGCC_MULTILIB
1546 else if (in_sep
&& *p
== 'l' && strncmp (p
, "libgcc.a%s", 10) == 0)
1548 /* Ug. We don't know shared library extensions. Hope that
1549 systems that use this form don't do shared libraries. */
1550 init_gcc_specs (&obstack
,
1551 #ifdef NO_SHARED_LIBGCC_MULTILIB
1564 obstack_1grow (&obstack
, *p
);
1565 in_sep
= (*p
== ' ');
1570 obstack_1grow (&obstack
, '\0');
1571 libgcc_spec
= obstack_finish (&obstack
);
1574 #ifdef USE_AS_TRADITIONAL_FORMAT
1575 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1577 static const char tf
[] = "--traditional-format ";
1578 obstack_grow (&obstack
, tf
, sizeof(tf
) - 1);
1579 obstack_grow0 (&obstack
, asm_spec
, strlen (asm_spec
));
1580 asm_spec
= obstack_finish (&obstack
);
1584 /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1585 obstack_grow (&obstack
, LINK_EH_SPEC
, sizeof(LINK_EH_SPEC
) - 1);
1586 obstack_grow0 (&obstack
, link_spec
, strlen (link_spec
));
1587 link_spec
= obstack_finish (&obstack
);
1593 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1594 removed; If the spec starts with a + then SPEC is added to the end of the
1598 set_spec (name
, spec
)
1602 struct spec_list
*sl
;
1603 const char *old_spec
;
1604 int name_len
= strlen (name
);
1607 /* If this is the first call, initialize the statically allocated specs. */
1610 struct spec_list
*next
= (struct spec_list
*) 0;
1611 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1613 sl
= &static_specs
[i
];
1620 /* See if the spec already exists. */
1621 for (sl
= specs
; sl
; sl
= sl
->next
)
1622 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1627 /* Not found - make it. */
1628 sl
= (struct spec_list
*) xmalloc (sizeof (struct spec_list
));
1629 sl
->name
= xstrdup (name
);
1630 sl
->name_len
= name_len
;
1631 sl
->ptr_spec
= &sl
->ptr
;
1633 *(sl
->ptr_spec
) = "";
1638 old_spec
= *(sl
->ptr_spec
);
1639 *(sl
->ptr_spec
) = ((spec
[0] == '+' && ISSPACE ((unsigned char)spec
[1]))
1640 ? concat (old_spec
, spec
+ 1, NULL
)
1645 notice ("Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1648 /* Free the old spec. */
1649 if (old_spec
&& sl
->alloc_p
)
1650 free ((PTR
) old_spec
);
1655 /* Accumulate a command (program name and args), and run it. */
1657 /* Vector of pointers to arguments in the current line of specifications. */
1659 static const char **argbuf
;
1661 /* Number of elements allocated in argbuf. */
1663 static int argbuf_length
;
1665 /* Number of elements in argbuf currently in use (containing args). */
1667 static int argbuf_index
;
1669 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1670 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1673 static struct temp_name
{
1674 const char *suffix
; /* suffix associated with the code. */
1675 int length
; /* strlen (suffix). */
1676 int unique
; /* Indicates whether %g or %u/%U was used. */
1677 const char *filename
; /* associated filename. */
1678 int filename_length
; /* strlen (filename). */
1679 struct temp_name
*next
;
1682 /* Number of commands executed so far. */
1684 static int execution_count
;
1686 /* Number of commands that exited with a signal. */
1688 static int signal_count
;
1690 /* Name with which this program was invoked. */
1692 static const char *programname
;
1694 /* Clear out the vector of arguments (after a command is executed). */
1702 /* Add one argument to the vector at the end.
1703 This is done when a space is seen or at the end of the line.
1704 If DELETE_ALWAYS is nonzero, the arg is a filename
1705 and the file should be deleted eventually.
1706 If DELETE_FAILURE is nonzero, the arg is a filename
1707 and the file should be deleted if this compilation fails. */
1710 store_arg (arg
, delete_always
, delete_failure
)
1712 int delete_always
, delete_failure
;
1714 if (argbuf_index
+ 1 == argbuf_length
)
1716 = (const char **) xrealloc (argbuf
,
1717 (argbuf_length
*= 2) * sizeof (const char *));
1719 argbuf
[argbuf_index
++] = arg
;
1720 argbuf
[argbuf_index
] = 0;
1722 if (delete_always
|| delete_failure
)
1723 record_temp_file (arg
, delete_always
, delete_failure
);
1726 /* Load specs from a file name named FILENAME, replacing occurrences of
1727 various different types of line-endings, \r\n, \n\r and just \r, with
1731 load_specs (filename
)
1732 const char *filename
;
1736 struct stat statbuf
;
1743 notice ("Reading specs from %s\n", filename
);
1745 /* Open and stat the file. */
1746 desc
= open (filename
, O_RDONLY
, 0);
1748 pfatal_with_name (filename
);
1749 if (stat (filename
, &statbuf
) < 0)
1750 pfatal_with_name (filename
);
1752 /* Read contents of file into BUFFER. */
1753 buffer
= xmalloc ((unsigned) statbuf
.st_size
+ 1);
1754 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
1756 pfatal_with_name (filename
);
1757 buffer
[readlen
] = 0;
1760 specs
= xmalloc (readlen
+ 1);
1762 for (buffer_p
= buffer
; buffer_p
&& *buffer_p
; buffer_p
++)
1768 if (buffer_p
> buffer
&& *(buffer_p
- 1) == '\n') /* \n\r */
1770 else if (*(buffer_p
+ 1) == '\n') /* \r\n */
1784 /* Read compilation specs from a file named FILENAME,
1785 replacing the default ones.
1787 A suffix which starts with `*' is a definition for
1788 one of the machine-specific sub-specs. The "suffix" should be
1789 *asm, *cc1, *cpp, *link, *startfile, etc.
1790 The corresponding spec is stored in asm_spec, etc.,
1791 rather than in the `compilers' vector.
1793 Anything invalid in the file is a fatal error. */
1796 read_specs (filename
, main_p
)
1797 const char *filename
;
1803 buffer
= load_specs (filename
);
1805 /* Scan BUFFER for specs, putting them in the vector. */
1811 char *in
, *out
, *p1
, *p2
, *p3
;
1813 /* Advance P in BUFFER to the next nonblank nocomment line. */
1814 p
= skip_whitespace (p
);
1818 /* Is this a special command that starts with '%'? */
1819 /* Don't allow this for the main specs file, since it would
1820 encourage people to overwrite it. */
1821 if (*p
== '%' && !main_p
)
1824 while (*p
&& *p
!= '\n')
1830 if (!strncmp (p1
, "%include", sizeof ("%include") - 1)
1831 && (p1
[sizeof "%include" - 1] == ' '
1832 || p1
[sizeof "%include" - 1] == '\t'))
1836 p1
+= sizeof ("%include");
1837 while (*p1
== ' ' || *p1
== '\t')
1840 if (*p1
++ != '<' || p
[-2] != '>')
1841 fatal ("specs %%include syntax malformed after %ld characters",
1842 (long) (p1
- buffer
+ 1));
1845 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
);
1846 read_specs (new_filename
? new_filename
: p1
, FALSE
);
1849 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
1850 && (p1
[sizeof "%include_noerr" - 1] == ' '
1851 || p1
[sizeof "%include_noerr" - 1] == '\t'))
1855 p1
+= sizeof "%include_noerr";
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
);
1866 read_specs (new_filename
, FALSE
);
1867 else if (verbose_flag
)
1868 notice ("could not find specs file %s\n", p1
);
1871 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
1872 && (p1
[sizeof "%rename" - 1] == ' '
1873 || p1
[sizeof "%rename" - 1] == '\t'))
1876 struct spec_list
*sl
;
1877 struct spec_list
*newsl
;
1879 /* Get original name. */
1880 p1
+= sizeof "%rename";
1881 while (*p1
== ' ' || *p1
== '\t')
1884 if (! ISALPHA ((unsigned char) *p1
))
1885 fatal ("specs %%rename syntax malformed after %ld characters",
1886 (long) (p1
- buffer
));
1889 while (*p2
&& !ISSPACE ((unsigned char) *p2
))
1892 if (*p2
!= ' ' && *p2
!= '\t')
1893 fatal ("specs %%rename syntax malformed after %ld characters",
1894 (long) (p2
- buffer
));
1898 while (*p2
== ' ' || *p2
== '\t')
1901 if (! ISALPHA ((unsigned char) *p2
))
1902 fatal ("specs %%rename syntax malformed after %ld characters",
1903 (long) (p2
- buffer
));
1905 /* Get new spec name. */
1907 while (*p3
&& !ISSPACE ((unsigned char) *p3
))
1911 fatal ("specs %%rename syntax malformed after %ld characters",
1912 (long) (p3
- buffer
));
1915 for (sl
= specs
; sl
; sl
= sl
->next
)
1916 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
1920 fatal ("specs %s spec was not found to be renamed", p1
);
1922 if (strcmp (p1
, p2
) == 0)
1925 for (newsl
= specs
; newsl
; newsl
= newsl
->next
)
1926 if (strcmp (newsl
->name
, p2
) == 0)
1927 fatal ("%s: attempt to rename spec '%s' to already defined spec '%s'",
1932 notice ("rename spec %s to %s\n", p1
, p2
);
1934 notice ("spec is '%s'\n\n", *(sl
->ptr_spec
));
1938 set_spec (p2
, *(sl
->ptr_spec
));
1940 free ((PTR
) *(sl
->ptr_spec
));
1942 *(sl
->ptr_spec
) = "";
1947 fatal ("specs unknown %% command after %ld characters",
1948 (long) (p1
- buffer
));
1951 /* Find the colon that should end the suffix. */
1953 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
1956 /* The colon shouldn't be missing. */
1958 fatal ("specs file malformed after %ld characters",
1959 (long) (p1
- buffer
));
1961 /* Skip back over trailing whitespace. */
1963 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
1966 /* Copy the suffix to a string. */
1967 suffix
= save_string (p
, p2
- p
);
1968 /* Find the next line. */
1969 p
= skip_whitespace (p1
+ 1);
1971 fatal ("specs file malformed after %ld characters",
1972 (long) (p
- buffer
));
1975 /* Find next blank line or end of string. */
1976 while (*p1
&& !(*p1
== '\n' && (p1
[1] == '\n' || p1
[1] == '\0')))
1979 /* Specs end at the blank line and do not include the newline. */
1980 spec
= save_string (p
, p1
- p
);
1983 /* Delete backslash-newline sequences from the spec. */
1988 if (in
[0] == '\\' && in
[1] == '\n')
1990 else if (in
[0] == '#')
1991 while (*in
&& *in
!= '\n')
1999 if (suffix
[0] == '*')
2001 if (! strcmp (suffix
, "*link_command"))
2002 link_command_spec
= spec
;
2004 set_spec (suffix
+ 1, spec
);
2008 /* Add this pair to the vector. */
2010 = ((struct compiler
*)
2011 xrealloc (compilers
,
2012 (n_compilers
+ 2) * sizeof (struct compiler
)));
2014 compilers
[n_compilers
].suffix
= suffix
;
2015 compilers
[n_compilers
].spec
= spec
;
2017 memset (&compilers
[n_compilers
], 0, sizeof compilers
[n_compilers
]);
2021 link_command_spec
= spec
;
2024 if (link_command_spec
== 0)
2025 fatal ("spec file has no spec for linking");
2028 /* Record the names of temporary files we tell compilers to write,
2029 and delete them at the end of the run. */
2031 /* This is the common prefix we use to make temp file names.
2032 It is chosen once for each run of this program.
2033 It is substituted into a spec by %g or %j.
2034 Thus, all temp file names contain this prefix.
2035 In practice, all temp file names start with this prefix.
2037 This prefix comes from the envvar TMPDIR if it is defined;
2038 otherwise, from the P_tmpdir macro if that is defined;
2039 otherwise, in /usr/tmp or /tmp;
2040 or finally the current directory if all else fails. */
2042 static const char *temp_filename
;
2044 /* Length of the prefix. */
2046 static int temp_filename_length
;
2048 /* Define the list of temporary files to delete. */
2053 struct temp_file
*next
;
2056 /* Queue of files to delete on success or failure of compilation. */
2057 static struct temp_file
*always_delete_queue
;
2058 /* Queue of files to delete on failure of compilation. */
2059 static struct temp_file
*failure_delete_queue
;
2061 /* Record FILENAME as a file to be deleted automatically.
2062 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2063 otherwise delete it in any case.
2064 FAIL_DELETE nonzero means delete it if a compilation step fails;
2065 otherwise delete it in any case. */
2068 record_temp_file (filename
, always_delete
, fail_delete
)
2069 const char *filename
;
2073 char *const name
= xstrdup (filename
);
2077 struct temp_file
*temp
;
2078 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2079 if (! strcmp (name
, temp
->name
))
2082 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
2083 temp
->next
= always_delete_queue
;
2085 always_delete_queue
= temp
;
2092 struct temp_file
*temp
;
2093 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2094 if (! strcmp (name
, temp
->name
))
2097 temp
= (struct temp_file
*) xmalloc (sizeof (struct temp_file
));
2098 temp
->next
= failure_delete_queue
;
2100 failure_delete_queue
= temp
;
2106 /* Delete all the temporary files whose names we previously recorded. */
2109 delete_if_ordinary (name
)
2116 printf ("Delete %s? (y or n) ", name
);
2120 while ((c
= getchar ()) != '\n' && c
!= EOF
)
2123 if (i
== 'y' || i
== 'Y')
2125 if (stat (name
, &st
) >= 0 && S_ISREG (st
.st_mode
))
2126 if (unlink (name
) < 0)
2128 perror_with_name (name
);
2132 delete_temp_files ()
2134 struct temp_file
*temp
;
2136 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2137 delete_if_ordinary (temp
->name
);
2138 always_delete_queue
= 0;
2141 /* Delete all the files to be deleted on error. */
2144 delete_failure_queue ()
2146 struct temp_file
*temp
;
2148 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2149 delete_if_ordinary (temp
->name
);
2153 clear_failure_queue ()
2155 failure_delete_queue
= 0;
2158 /* Build a list of search directories from PATHS.
2159 PREFIX is a string to prepend to the list.
2160 If CHECK_DIR_P is non-zero we ensure the directory exists.
2161 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2162 It is also used by the --print-search-dirs flag. */
2165 build_search_list (paths
, prefix
, check_dir_p
)
2166 struct path_prefix
*paths
;
2170 int suffix_len
= (machine_suffix
) ? strlen (machine_suffix
) : 0;
2172 = (just_machine_suffix
) ? strlen (just_machine_suffix
) : 0;
2173 int first_time
= TRUE
;
2174 struct prefix_list
*pprefix
;
2176 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
2177 obstack_1grow (&collect_obstack
, '=');
2179 for (pprefix
= paths
->plist
; pprefix
!= 0; pprefix
= pprefix
->next
)
2181 int len
= strlen (pprefix
->prefix
);
2185 || is_directory (pprefix
->prefix
, machine_suffix
, 0)))
2188 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2191 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2192 obstack_grow (&collect_obstack
, machine_suffix
, suffix_len
);
2195 if (just_machine_suffix
2196 && pprefix
->require_machine_suffix
== 2
2198 || is_directory (pprefix
->prefix
, just_machine_suffix
, 0)))
2201 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2204 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2205 obstack_grow (&collect_obstack
, just_machine_suffix
,
2209 if (! pprefix
->require_machine_suffix
)
2212 obstack_1grow (&collect_obstack
, PATH_SEPARATOR
);
2215 obstack_grow (&collect_obstack
, pprefix
->prefix
, len
);
2219 obstack_1grow (&collect_obstack
, '\0');
2220 return obstack_finish (&collect_obstack
);
2223 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2227 putenv_from_prefixes (paths
, env_var
)
2228 struct path_prefix
*paths
;
2229 const char *env_var
;
2231 putenv (build_search_list (paths
, env_var
, 1));
2236 /* FIXME: the location independence code for VMS is hairier than this,
2237 and hasn't been written. */
2239 /* Split a filename into component directories. */
2242 split_directories (name
, ptr_num_dirs
)
2251 /* Count the number of directories. Special case MSDOS disk names as part
2252 of the initial directory. */
2254 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2255 if (name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2260 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2262 while ((ch
= *p
++) != '\0')
2264 if (IS_DIR_SEPARATOR (ch
))
2267 while (IS_DIR_SEPARATOR (*p
))
2272 dirs
= (char **) xmalloc (sizeof (char *) * (num_dirs
+ 2));
2274 /* Now copy the directory parts. */
2277 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2278 if (name
[1] == ':' && IS_DIR_SEPARATOR (name
[2]))
2280 dirs
[num_dirs
++] = save_string (p
, 3);
2283 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */
2286 while ((ch
= *p
++) != '\0')
2288 if (IS_DIR_SEPARATOR (ch
))
2290 while (IS_DIR_SEPARATOR (*p
))
2293 dirs
[num_dirs
++] = save_string (q
, p
- q
);
2299 dirs
[num_dirs
++] = save_string (q
, p
- 1 - q
);
2301 dirs
[num_dirs
] = NULL
;
2303 *ptr_num_dirs
= num_dirs
;
2308 /* Release storage held by split directories. */
2311 free_split_directories (dirs
)
2316 while (dirs
[i
] != NULL
)
2319 free ((char *) dirs
);
2322 /* Given three strings PROGNAME, BIN_PREFIX, PREFIX, return a string that gets
2323 to PREFIX starting with the directory portion of PROGNAME and a relative
2324 pathname of the difference between BIN_PREFIX and PREFIX.
2326 For example, if BIN_PREFIX is /alpha/beta/gamma/gcc/delta, PREFIX is
2327 /alpha/beta/gamma/omega/, and PROGNAME is /red/green/blue/gcc, then this
2328 function will return /red/green/blue/../omega.
2330 If no relative prefix can be found, return NULL. */
2333 make_relative_prefix (progname
, bin_prefix
, prefix
)
2334 const char *progname
;
2335 const char *bin_prefix
;
2338 char **prog_dirs
, **bin_dirs
, **prefix_dirs
;
2339 int prog_num
, bin_num
, prefix_num
, std_loc_p
;
2342 prog_dirs
= split_directories (progname
, &prog_num
);
2343 bin_dirs
= split_directories (bin_prefix
, &bin_num
);
2345 /* If there is no full pathname, try to find the program by checking in each
2346 of the directories specified in the PATH environment variable. */
2351 GET_ENVIRONMENT (temp
, "PATH");
2354 char *startp
, *endp
, *nstore
;
2355 size_t prefixlen
= strlen (temp
) + 1;
2359 nstore
= (char *) alloca (prefixlen
+ strlen (progname
) + 1);
2361 startp
= endp
= temp
;
2364 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
2369 nstore
[1] = DIR_SEPARATOR
;
2374 strncpy (nstore
, startp
, endp
- startp
);
2375 if (! IS_DIR_SEPARATOR (endp
[-1]))
2377 nstore
[endp
- startp
] = DIR_SEPARATOR
;
2378 nstore
[endp
- startp
+ 1] = 0;
2381 nstore
[endp
- startp
] = 0;
2383 strcat (nstore
, progname
);
2384 if (! access (nstore
, X_OK
)
2385 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
2386 || ! access (strcat (nstore
, HOST_EXECUTABLE_SUFFIX
), X_OK
)
2390 free_split_directories (prog_dirs
);
2392 prog_dirs
= split_directories (progname
, &prog_num
);
2398 endp
= startp
= endp
+ 1;
2406 /* Remove the program name from comparison of directory names. */
2409 /* Determine if the compiler is installed in the standard location, and if
2410 so, we don't need to specify relative directories. Also, if argv[0]
2411 doesn't contain any directory specifiers, there is not much we can do. */
2413 if (prog_num
== bin_num
)
2415 for (i
= 0; i
< bin_num
; i
++)
2417 if (strcmp (prog_dirs
[i
], bin_dirs
[i
]) != 0)
2421 if (prog_num
<= 0 || i
== bin_num
)
2424 free_split_directories (prog_dirs
);
2425 free_split_directories (bin_dirs
);
2426 prog_dirs
= bin_dirs
= (char **) 0;
2431 prefix_dirs
= split_directories (prefix
, &prefix_num
);
2433 /* Find how many directories are in common between bin_prefix & prefix. */
2434 n
= (prefix_num
< bin_num
) ? prefix_num
: bin_num
;
2435 for (common
= 0; common
< n
; common
++)
2437 if (strcmp (bin_dirs
[common
], prefix_dirs
[common
]) != 0)
2441 /* If there are no common directories, there can be no relative prefix. */
2444 free_split_directories (prog_dirs
);
2445 free_split_directories (bin_dirs
);
2446 free_split_directories (prefix_dirs
);
2450 /* Build up the pathnames in argv[0]. */
2451 for (i
= 0; i
< prog_num
; i
++)
2452 obstack_grow (&obstack
, prog_dirs
[i
], strlen (prog_dirs
[i
]));
2454 /* Now build up the ..'s. */
2455 for (i
= common
; i
< n
; i
++)
2457 obstack_grow (&obstack
, DIR_UP
, sizeof (DIR_UP
) - 1);
2458 obstack_1grow (&obstack
, DIR_SEPARATOR
);
2461 /* Put in directories to move over to prefix. */
2462 for (i
= common
; i
< prefix_num
; i
++)
2463 obstack_grow (&obstack
, prefix_dirs
[i
], strlen (prefix_dirs
[i
]));
2465 free_split_directories (prog_dirs
);
2466 free_split_directories (bin_dirs
);
2467 free_split_directories (prefix_dirs
);
2469 obstack_1grow (&obstack
, '\0');
2470 return obstack_finish (&obstack
);
2474 /* Check whether NAME can be accessed in MODE. This is like access,
2475 except that it never considers directories to be executable. */
2478 access_check (name
, mode
)
2486 if (stat (name
, &st
) < 0
2487 || S_ISDIR (st
.st_mode
))
2491 return access (name
, mode
);
2494 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2495 access to check permissions.
2496 Return 0 if not found, otherwise return its name, allocated with malloc. */
2499 find_a_file (pprefix
, name
, mode
)
2500 struct path_prefix
*pprefix
;
2505 const char *const file_suffix
=
2506 ((mode
& X_OK
) != 0 ? HOST_EXECUTABLE_SUFFIX
: "");
2507 struct prefix_list
*pl
;
2508 int len
= pprefix
->max_len
+ strlen (name
) + strlen (file_suffix
) + 1;
2510 #ifdef DEFAULT_ASSEMBLER
2511 if (! strcmp (name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0)
2512 return xstrdup (DEFAULT_ASSEMBLER
);
2515 #ifdef DEFAULT_LINKER
2516 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0)
2517 return xstrdup (DEFAULT_LINKER
);
2521 len
+= strlen (machine_suffix
);
2523 temp
= xmalloc (len
);
2525 /* Determine the filename to execute (special case for absolute paths). */
2527 if (IS_ABSOLUTE_PATHNAME (name
))
2529 if (access (name
, mode
) == 0)
2531 strcpy (temp
, name
);
2536 for (pl
= pprefix
->plist
; pl
; pl
= pl
->next
)
2540 /* Some systems have a suffix for executable files.
2541 So try appending that first. */
2542 if (file_suffix
[0] != 0)
2544 strcpy (temp
, pl
->prefix
);
2545 strcat (temp
, machine_suffix
);
2546 strcat (temp
, name
);
2547 strcat (temp
, file_suffix
);
2548 if (access_check (temp
, mode
) == 0)
2550 if (pl
->used_flag_ptr
!= 0)
2551 *pl
->used_flag_ptr
= 1;
2556 /* Now try just the name. */
2557 strcpy (temp
, pl
->prefix
);
2558 strcat (temp
, machine_suffix
);
2559 strcat (temp
, name
);
2560 if (access_check (temp
, mode
) == 0)
2562 if (pl
->used_flag_ptr
!= 0)
2563 *pl
->used_flag_ptr
= 1;
2568 /* Certain prefixes are tried with just the machine type,
2569 not the version. This is used for finding as, ld, etc. */
2570 if (just_machine_suffix
&& pl
->require_machine_suffix
== 2)
2572 /* Some systems have a suffix for executable files.
2573 So try appending that first. */
2574 if (file_suffix
[0] != 0)
2576 strcpy (temp
, pl
->prefix
);
2577 strcat (temp
, just_machine_suffix
);
2578 strcat (temp
, name
);
2579 strcat (temp
, file_suffix
);
2580 if (access_check (temp
, mode
) == 0)
2582 if (pl
->used_flag_ptr
!= 0)
2583 *pl
->used_flag_ptr
= 1;
2588 strcpy (temp
, pl
->prefix
);
2589 strcat (temp
, just_machine_suffix
);
2590 strcat (temp
, name
);
2591 if (access_check (temp
, mode
) == 0)
2593 if (pl
->used_flag_ptr
!= 0)
2594 *pl
->used_flag_ptr
= 1;
2599 /* Certain prefixes can't be used without the machine suffix
2600 when the machine or version is explicitly specified. */
2601 if (! pl
->require_machine_suffix
)
2603 /* Some systems have a suffix for executable files.
2604 So try appending that first. */
2605 if (file_suffix
[0] != 0)
2607 strcpy (temp
, pl
->prefix
);
2608 strcat (temp
, name
);
2609 strcat (temp
, file_suffix
);
2610 if (access_check (temp
, mode
) == 0)
2612 if (pl
->used_flag_ptr
!= 0)
2613 *pl
->used_flag_ptr
= 1;
2618 strcpy (temp
, pl
->prefix
);
2619 strcat (temp
, name
);
2620 if (access_check (temp
, mode
) == 0)
2622 if (pl
->used_flag_ptr
!= 0)
2623 *pl
->used_flag_ptr
= 1;
2633 /* Ranking of prefixes in the sort list. -B prefixes are put before
2636 enum path_prefix_priority
2638 PREFIX_PRIORITY_B_OPT
,
2639 PREFIX_PRIORITY_LAST
2642 /* Add an entry for PREFIX in PLIST. The PLIST is kept in assending
2643 order according to PRIORITY. Within each PRIORITY, new entries are
2646 If WARN is nonzero, we will warn if no file is found
2647 through this prefix. WARN should point to an int
2648 which will be set to 1 if this entry is used.
2650 COMPONENT is the value to be passed to update_path.
2652 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2653 the complete value of machine_suffix.
2654 2 means try both machine_suffix and just_machine_suffix. */
2657 add_prefix (pprefix
, prefix
, component
, priority
, require_machine_suffix
, warn
)
2658 struct path_prefix
*pprefix
;
2660 const char *component
;
2661 /* enum prefix_priority */ int priority
;
2662 int require_machine_suffix
;
2665 struct prefix_list
*pl
, **prev
;
2668 for (prev
= &pprefix
->plist
;
2669 (*prev
) != NULL
&& (*prev
)->priority
<= priority
;
2670 prev
= &(*prev
)->next
)
2673 /* Keep track of the longest prefix */
2675 prefix
= update_path (prefix
, component
);
2676 len
= strlen (prefix
);
2677 if (len
> pprefix
->max_len
)
2678 pprefix
->max_len
= len
;
2680 pl
= (struct prefix_list
*) xmalloc (sizeof (struct prefix_list
));
2681 pl
->prefix
= prefix
;
2682 pl
->require_machine_suffix
= require_machine_suffix
;
2683 pl
->used_flag_ptr
= warn
;
2684 pl
->priority
= priority
;
2688 /* Insert after PREV */
2693 /* Execute the command specified by the arguments on the current line of spec.
2694 When using pipes, this includes several piped-together commands
2695 with `|' between them.
2697 Return 0 if successful, -1 if failed. */
2703 int n_commands
; /* # of command. */
2707 const char *prog
; /* program name. */
2708 const char **argv
; /* vector of args. */
2709 int pid
; /* pid of process for this command. */
2712 struct command
*commands
; /* each command buffer with above info. */
2714 /* Count # of piped commands. */
2715 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2716 if (strcmp (argbuf
[i
], "|") == 0)
2719 /* Get storage for each command. */
2720 commands
= (struct command
*) alloca (n_commands
* sizeof (struct command
));
2722 /* Split argbuf into its separate piped processes,
2723 and record info about each one.
2724 Also search for the programs that are to be run. */
2726 commands
[0].prog
= argbuf
[0]; /* first command. */
2727 commands
[0].argv
= &argbuf
[0];
2728 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
);
2731 commands
[0].argv
[0] = string
;
2733 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2734 if (strcmp (argbuf
[i
], "|") == 0)
2735 { /* each command. */
2736 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2737 fatal ("-pipe not supported");
2739 argbuf
[i
] = 0; /* termination of command args. */
2740 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2741 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2742 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
, X_OK
);
2744 commands
[n_commands
].argv
[0] = string
;
2748 argbuf
[argbuf_index
] = 0;
2750 /* If -v, print what we are about to do, and maybe query. */
2754 /* For help listings, put a blank line between sub-processes. */
2755 if (print_help_list
)
2756 fputc ('\n', stderr
);
2758 /* Print each piped command as a separate line. */
2759 for (i
= 0; i
< n_commands
; i
++)
2761 const char *const *j
;
2763 if (verbose_only_flag
)
2765 for (j
= commands
[i
].argv
; *j
; j
++)
2768 fprintf (stderr
, " \"");
2769 for (p
= *j
; *p
; ++p
)
2771 if (*p
== '"' || *p
== '\\' || *p
== '$')
2772 fputc ('\\', stderr
);
2775 fputc ('"', stderr
);
2779 for (j
= commands
[i
].argv
; *j
; j
++)
2780 fprintf (stderr
, " %s", *j
);
2782 /* Print a pipe symbol after all but the last command. */
2783 if (i
+ 1 != n_commands
)
2784 fprintf (stderr
, " |");
2785 fprintf (stderr
, "\n");
2788 if (verbose_only_flag
!= 0)
2791 notice ("\nGo ahead? (y or n) ");
2795 while (getchar () != '\n')
2798 if (i
!= 'y' && i
!= 'Y')
2803 /* Run each piped subprocess. */
2805 for (i
= 0; i
< n_commands
; i
++)
2807 char *errmsg_fmt
, *errmsg_arg
;
2808 const char *string
= commands
[i
].argv
[0];
2810 /* For some bizarre reason, the second argument of execvp() is
2811 char *const *, not const char *const *. */
2812 commands
[i
].pid
= pexecute (string
, (char *const *) commands
[i
].argv
,
2813 programname
, temp_filename
,
2814 &errmsg_fmt
, &errmsg_arg
,
2815 ((i
== 0 ? PEXECUTE_FIRST
: 0)
2816 | (i
+ 1 == n_commands
? PEXECUTE_LAST
: 0)
2817 | (string
== commands
[i
].prog
2818 ? PEXECUTE_SEARCH
: 0)
2819 | (verbose_flag
? PEXECUTE_VERBOSE
: 0)));
2821 if (commands
[i
].pid
== -1)
2822 pfatal_pexecute (errmsg_fmt
, errmsg_arg
);
2824 if (string
!= commands
[i
].prog
)
2825 free ((PTR
) string
);
2830 /* Wait for all the subprocesses to finish.
2831 We don't care what order they finish in;
2832 we know that N_COMMANDS waits will get them all.
2833 Ignore subprocesses that we don't know about,
2834 since they can be spawned by the process that exec'ed us. */
2838 #ifdef HAVE_GETRUSAGE
2840 double ut
= 0.0, st
= 0.0;
2843 for (i
= 0; i
< n_commands
;)
2849 pid
= pwait (commands
[i
].pid
, &status
, 0);
2853 #ifdef HAVE_GETRUSAGE
2856 /* getrusage returns the total resource usage of all children
2857 up to now. Copy the previous values into prus, get the
2858 current statistics, then take the difference. */
2861 getrusage (RUSAGE_CHILDREN
, &rus
);
2862 d
.tv_sec
= rus
.ru_utime
.tv_sec
- prus
.ru_utime
.tv_sec
;
2863 d
.tv_usec
= rus
.ru_utime
.tv_usec
- prus
.ru_utime
.tv_usec
;
2864 ut
= (double) d
.tv_sec
+ (double) d
.tv_usec
/ 1.0e6
;
2866 d
.tv_sec
= rus
.ru_stime
.tv_sec
- prus
.ru_stime
.tv_sec
;
2867 d
.tv_usec
= rus
.ru_stime
.tv_usec
- prus
.ru_stime
.tv_usec
;
2868 st
= (double) d
.tv_sec
+ (double) d
.tv_usec
/ 1.0e6
;
2872 for (j
= 0; j
< n_commands
; j
++)
2873 if (commands
[j
].pid
== pid
)
2876 if (WIFSIGNALED (status
))
2879 /* SIGPIPE is a special case. It happens in -pipe mode
2880 when the compiler dies before the preprocessor is
2881 done, or the assembler dies before the compiler is
2882 done. There's generally been an error already, and
2883 this is just fallout. So don't generate another error
2884 unless we would otherwise have succeeded. */
2885 if (WTERMSIG (status
) == SIGPIPE
2886 && (signal_count
|| greatest_status
>= MIN_FATAL_STATUS
))
2891 Internal error: %s (program %s)\n\
2892 Please submit a full bug report.\n\
2893 See %s for instructions.",
2894 strsignal (WTERMSIG (status
)), commands
[j
].prog
,
2899 else if (WIFEXITED (status
)
2900 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
2902 if (WEXITSTATUS (status
) > greatest_status
)
2903 greatest_status
= WEXITSTATUS (status
);
2906 #ifdef HAVE_GETRUSAGE
2907 if (report_times
&& ut
+ st
!= 0)
2908 notice ("# %s %.2f %.2f\n", commands
[j
].prog
, ut
, st
);
2917 /* Find all the switches given to us
2918 and make a vector describing them.
2919 The elements of the vector are strings, one per switch given.
2920 If a switch uses following arguments, then the `part1' field
2921 is the switch itself and the `args' field
2922 is a null-terminated vector containing the following arguments.
2923 The `live_cond' field is:
2925 1 if the switch is true in a conditional spec,
2926 -1 if false (overridden by a later switch)
2927 -2 if this switch should be ignored (used in %{<S})
2928 The `validated' field is nonzero if any spec has looked at this switch;
2929 if it remains zero at the end of the run, it must be meaningless. */
2932 #define SWITCH_FALSE -1
2933 #define SWITCH_IGNORE -2
2934 #define SWITCH_LIVE 1
2941 unsigned char validated
;
2942 unsigned char ordering
;
2945 static struct switchstr
*switches
;
2947 static int n_switches
;
2952 const char *language
;
2955 /* Also a vector of input files specified. */
2957 static struct infile
*infiles
;
2961 /* This counts the number of libraries added by lang_specific_driver, so that
2962 we can tell if there were any user supplied any files or libraries. */
2964 static int added_libraries
;
2966 /* And a vector of corresponding output files is made up later. */
2968 const char **outfiles
;
2970 /* Used to track if none of the -B paths are used. */
2973 /* Gives value to pass as "warn" to add_prefix for standard prefixes. */
2974 static int *warn_std_ptr
= 0;
2976 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2978 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
2979 is true if we should look for an executable suffix. DO_OBJ
2980 is true if we should look for an object suffix. */
2983 convert_filename (name
, do_exe
, do_obj
)
2985 int do_exe ATTRIBUTE_UNUSED
;
2986 int do_obj ATTRIBUTE_UNUSED
;
2988 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
2996 len
= strlen (name
);
2998 #ifdef HAVE_TARGET_OBJECT_SUFFIX
2999 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3000 if (do_obj
&& len
> 2
3001 && name
[len
- 2] == '.'
3002 && name
[len
- 1] == 'o')
3004 obstack_grow (&obstack
, name
, len
- 2);
3005 obstack_grow0 (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
3006 name
= obstack_finish (&obstack
);
3010 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3011 /* If there is no filetype, make it the executable suffix (which includes
3012 the "."). But don't get confused if we have just "-o". */
3013 if (! do_exe
|| TARGET_EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
3016 for (i
= len
- 1; i
>= 0; i
--)
3017 if (IS_DIR_SEPARATOR (name
[i
]))
3020 for (i
++; i
< len
; i
++)
3024 obstack_grow (&obstack
, name
, len
);
3025 obstack_grow0 (&obstack
, TARGET_EXECUTABLE_SUFFIX
,
3026 strlen (TARGET_EXECUTABLE_SUFFIX
));
3027 name
= obstack_finish (&obstack
);
3034 /* Display the command line switches accepted by gcc. */
3038 printf (_("Usage: %s [options] file...\n"), programname
);
3039 fputs (_("Options:\n"), stdout
);
3041 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout
);
3042 fputs (_(" --help Display this information\n"), stdout
);
3043 fputs (_(" --target-help Display target specific command line options\n"), stdout
);
3045 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout
);
3046 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout
);
3047 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout
);
3048 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout
);
3049 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout
);
3050 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout
);
3051 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout
);
3052 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout
);
3053 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout
);
3055 -print-multi-lib Display the mapping between command line options and\n\
3056 multiple library search directories\n"), stdout
);
3057 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout
);
3058 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout
);
3059 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout
);
3060 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout
);
3061 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout
);
3062 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout
);
3063 fputs (_(" -time Time the execution of each subprocess\n"), stdout
);
3064 fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout
);
3065 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout
);
3066 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout
);
3067 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout
);
3068 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout
);
3069 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout
);
3070 fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout
);
3071 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout
);
3072 fputs (_(" -S Compile only; do not assemble or link\n"), stdout
);
3073 fputs (_(" -c Compile and assemble, but do not link\n"), stdout
);
3074 fputs (_(" -o <file> Place the output into <file>\n"), stdout
);
3076 -x <language> Specify the language of the following input files\n\
3077 Permissable languages include: c c++ assembler none\n\
3078 'none' means revert to the default behavior of\n\
3079 guessing the language based on the file's extension\n\
3083 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3084 passed on to the various sub-processes invoked by %s. In order to pass\n\
3085 other options on to these processes the -W<letter> options must be used.\n\
3088 /* The rest of the options are displayed by invocations of the various
3093 add_preprocessor_option (option
, len
)
3097 n_preprocessor_options
++;
3099 if (! preprocessor_options
)
3100 preprocessor_options
3101 = (char **) xmalloc (n_preprocessor_options
* sizeof (char *));
3103 preprocessor_options
3104 = (char **) xrealloc (preprocessor_options
,
3105 n_preprocessor_options
* sizeof (char *));
3107 preprocessor_options
[n_preprocessor_options
- 1] =
3108 save_string (option
, len
);
3112 add_assembler_option (option
, len
)
3116 n_assembler_options
++;
3118 if (! assembler_options
)
3120 = (char **) xmalloc (n_assembler_options
* sizeof (char *));
3123 = (char **) xrealloc (assembler_options
,
3124 n_assembler_options
* sizeof (char *));
3126 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
3130 add_linker_option (option
, len
)
3136 if (! linker_options
)
3138 = (char **) xmalloc (n_linker_options
* sizeof (char *));
3141 = (char **) xrealloc (linker_options
,
3142 n_linker_options
* sizeof (char *));
3144 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
3147 /* Create the vector `switches' and its contents.
3148 Store its length in `n_switches'. */
3151 process_command (argc
, argv
)
3153 const char *const *argv
;
3158 const char *spec_lang
= 0;
3159 int last_language_n_infiles
;
3162 int lang_n_infiles
= 0;
3163 #ifdef MODIFY_TARGET_NAME
3164 int is_modify_target_name
;
3168 GET_ENVIRONMENT (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
3172 added_libraries
= 0;
3174 /* Figure compiler version from version string. */
3176 compiler_version
= temp1
= xstrdup (version_string
);
3178 for (; *temp1
; ++temp1
)
3187 /* If there is a -V or -b option (or both), process it now, before
3188 trying to interpret the rest of the command line. */
3189 if (argc
> 1 && argv
[1][0] == '-'
3190 && (argv
[1][1] == 'V' || argv
[1][1] == 'b'))
3192 const char *new_version
= DEFAULT_TARGET_VERSION
;
3193 const char *new_machine
= DEFAULT_TARGET_MACHINE
;
3194 const char *progname
= argv
[0];
3199 while (argc
> 1 && argv
[1][0] == '-'
3200 && (argv
[1][1] == 'V' || argv
[1][1] == 'b'))
3202 char opt
= argv
[1][1];
3204 if (argv
[1][2] != '\0')
3217 fatal ("`-%c' option must have argument", opt
);
3224 for (baselen
= strlen (progname
); baselen
> 0; baselen
--)
3225 if (IS_DIR_SEPARATOR (progname
[baselen
-1]))
3227 new_argv0
= xmemdup (progname
, baselen
,
3228 baselen
+ concat_length (new_version
, new_machine
,
3229 "-gcc-", NULL
) + 1);
3230 strcpy (new_argv0
+ baselen
, new_machine
);
3231 strcat (new_argv0
, "-gcc-");
3232 strcat (new_argv0
, new_version
);
3234 new_argv
= xmemdup (argv
, (argc
+ 1) * sizeof (argv
[0]),
3235 (argc
+ 1) * sizeof (argv
[0]));
3236 new_argv
[0] = new_argv0
;
3238 execvp (new_argv0
, new_argv
);
3239 fatal ("couldn't run `%s': %s", new_argv0
, xstrerror (errno
));
3242 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3243 see if we can create it from the pathname specified in argv[0]. */
3246 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3247 if (!gcc_exec_prefix
)
3249 gcc_exec_prefix
= make_relative_prefix (argv
[0], standard_bindir_prefix
,
3250 standard_exec_prefix
);
3251 if (gcc_exec_prefix
)
3252 putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix
, NULL
));
3256 if (gcc_exec_prefix
)
3258 int len
= strlen (gcc_exec_prefix
);
3260 if (len
> (int) sizeof ("/lib/gcc-lib/") - 1
3261 && (IS_DIR_SEPARATOR (gcc_exec_prefix
[len
-1])))
3263 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc-lib/") + 1;
3264 if (IS_DIR_SEPARATOR (*temp
)
3265 && strncmp (temp
+ 1, "lib", 3) == 0
3266 && IS_DIR_SEPARATOR (temp
[4])
3267 && strncmp (temp
+ 5, "gcc-lib", 7) == 0)
3268 len
-= sizeof ("/lib/gcc-lib/") - 1;
3271 set_std_prefix (gcc_exec_prefix
, len
);
3272 add_prefix (&exec_prefixes
, gcc_exec_prefix
, "GCC",
3273 PREFIX_PRIORITY_LAST
, 0, NULL
);
3274 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC",
3275 PREFIX_PRIORITY_LAST
, 0, NULL
);
3278 /* COMPILER_PATH and LIBRARY_PATH have values
3279 that are lists of directory names with colons. */
3281 GET_ENVIRONMENT (temp
, "COMPILER_PATH");
3284 const char *startp
, *endp
;
3285 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3287 startp
= endp
= temp
;
3290 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3292 strncpy (nstore
, startp
, endp
- startp
);
3294 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3295 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3297 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3298 nstore
[endp
- startp
+ 1] = 0;
3301 nstore
[endp
- startp
] = 0;
3302 add_prefix (&exec_prefixes
, nstore
, 0,
3303 PREFIX_PRIORITY_LAST
, 0, NULL
);
3304 add_prefix (&include_prefixes
,
3305 concat (nstore
, "include", NULL
),
3306 0, PREFIX_PRIORITY_LAST
, 0, NULL
);
3309 endp
= startp
= endp
+ 1;
3316 GET_ENVIRONMENT (temp
, LIBRARY_PATH_ENV
);
3317 if (temp
&& *cross_compile
== '0')
3319 const char *startp
, *endp
;
3320 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3322 startp
= endp
= temp
;
3325 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3327 strncpy (nstore
, startp
, endp
- startp
);
3329 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3330 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3332 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3333 nstore
[endp
- startp
+ 1] = 0;
3336 nstore
[endp
- startp
] = 0;
3337 add_prefix (&startfile_prefixes
, nstore
, NULL
,
3338 PREFIX_PRIORITY_LAST
, 0, NULL
);
3341 endp
= startp
= endp
+ 1;
3348 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3349 GET_ENVIRONMENT (temp
, "LPATH");
3350 if (temp
&& *cross_compile
== '0')
3352 const char *startp
, *endp
;
3353 char *nstore
= (char *) alloca (strlen (temp
) + 3);
3355 startp
= endp
= temp
;
3358 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
3360 strncpy (nstore
, startp
, endp
- startp
);
3362 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
3363 else if (!IS_DIR_SEPARATOR (endp
[-1]))
3365 nstore
[endp
- startp
] = DIR_SEPARATOR
;
3366 nstore
[endp
- startp
+ 1] = 0;
3369 nstore
[endp
- startp
] = 0;
3370 add_prefix (&startfile_prefixes
, nstore
, NULL
,
3371 PREFIX_PRIORITY_LAST
, 0, NULL
);
3374 endp
= startp
= endp
+ 1;
3381 /* Convert new-style -- options to old-style. */
3382 translate_options (&argc
, &argv
);
3384 /* Do language-specific adjustment/addition of flags. */
3385 lang_specific_driver (&argc
, &argv
, &added_libraries
);
3387 /* Scan argv twice. Here, the first time, just count how many switches
3388 there will be in their vector, and how many input files in theirs.
3389 Here we also parse the switches that cc itself uses (e.g. -v). */
3391 for (i
= 1; i
< argc
; i
++)
3393 if (! strcmp (argv
[i
], "-dumpspecs"))
3395 struct spec_list
*sl
;
3397 for (sl
= specs
; sl
; sl
= sl
->next
)
3398 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
3399 if (link_command_spec
)
3400 printf ("*link_command:\n%s\n\n", link_command_spec
);
3403 else if (! strcmp (argv
[i
], "-dumpversion"))
3405 printf ("%s\n", spec_version
);
3408 else if (! strcmp (argv
[i
], "-dumpmachine"))
3410 printf ("%s\n", spec_machine
);
3413 else if (strcmp (argv
[i
], "-fversion") == 0)
3415 /* translate_options () has turned --version into -fversion. */
3416 printf (_("%s (GCC) %s\n"), programname
, version_string
);
3417 fputs (_("Copyright (C) 2002 Free Software Foundation, Inc.\n"),
3419 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
3420 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
3424 else if (strcmp (argv
[i
], "-fhelp") == 0)
3426 /* translate_options () has turned --help into -fhelp. */
3427 print_help_list
= 1;
3429 /* We will be passing a dummy file on to the sub-processes. */
3433 /* CPP driver cannot obtain switch from cc1_options. */
3435 add_preprocessor_option ("--help", 6);
3436 add_assembler_option ("--help", 6);
3437 add_linker_option ("--help", 6);
3439 else if (strcmp (argv
[i
], "-ftarget-help") == 0)
3441 /* translate_options() has turned --target-help into -ftarget-help. */
3442 target_help_flag
= 1;
3444 /* We will be passing a dummy file on to the sub-processes. */
3448 /* CPP driver cannot obtain switch from cc1_options. */
3450 add_preprocessor_option ("--target-help", 13);
3451 add_assembler_option ("--target-help", 13);
3452 add_linker_option ("--target-help", 13);
3454 else if (! strcmp (argv
[i
], "-pass-exit-codes"))
3456 pass_exit_codes
= 1;
3459 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3460 print_search_dirs
= 1;
3461 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3462 print_file_name
= "libgcc.a";
3463 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3464 print_file_name
= argv
[i
] + 17;
3465 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3466 print_prog_name
= argv
[i
] + 17;
3467 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3468 print_multi_lib
= 1;
3469 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3470 print_multi_directory
= 1;
3471 else if (! strncmp (argv
[i
], "-Wa,", 4))
3474 /* Pass the rest of this option to the assembler. */
3476 /* Split the argument at commas. */
3478 for (j
= 4; argv
[i
][j
]; j
++)
3479 if (argv
[i
][j
] == ',')
3481 add_assembler_option (argv
[i
] + prev
, j
- prev
);
3485 /* Record the part after the last comma. */
3486 add_assembler_option (argv
[i
] + prev
, j
- prev
);
3488 else if (! strncmp (argv
[i
], "-Wp,", 4))
3491 /* Pass the rest of this option to the preprocessor. */
3493 /* Split the argument at commas. */
3495 for (j
= 4; argv
[i
][j
]; j
++)
3496 if (argv
[i
][j
] == ',')
3498 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
3502 /* Record the part after the last comma. */
3503 add_preprocessor_option (argv
[i
] + prev
, j
- prev
);
3505 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3506 /* The +e options to the C++ front-end. */
3508 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3511 /* Split the argument at commas. */
3512 for (j
= 3; argv
[i
][j
]; j
++)
3513 n_infiles
+= (argv
[i
][j
] == ',');
3515 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3518 fatal ("argument to `-Xlinker' is missing");
3523 else if (strcmp (argv
[i
], "-l") == 0)
3526 fatal ("argument to `-l' is missing");
3531 else if (strncmp (argv
[i
], "-l", 2) == 0)
3533 else if (strcmp (argv
[i
], "-save-temps") == 0)
3535 save_temps_flag
= 1;
3538 else if (strcmp (argv
[i
], "-specs") == 0)
3540 struct user_specs
*user
= (struct user_specs
*)
3541 xmalloc (sizeof (struct user_specs
));
3543 fatal ("argument to `-specs' is missing");
3545 user
->next
= (struct user_specs
*) 0;
3546 user
->filename
= argv
[i
];
3547 if (user_specs_tail
)
3548 user_specs_tail
->next
= user
;
3550 user_specs_head
= user
;
3551 user_specs_tail
= user
;
3553 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3555 struct user_specs
*user
= (struct user_specs
*)
3556 xmalloc (sizeof (struct user_specs
));
3557 if (strlen (argv
[i
]) == 7)
3558 fatal ("argument to `-specs=' is missing");
3560 user
->next
= (struct user_specs
*) 0;
3561 user
->filename
= argv
[i
] + 7;
3562 if (user_specs_tail
)
3563 user_specs_tail
->next
= user
;
3565 user_specs_head
= user
;
3566 user_specs_tail
= user
;
3568 else if (strcmp (argv
[i
], "-time") == 0)
3570 else if (strcmp (argv
[i
], "-###") == 0)
3572 /* This is similar to -v except that there is no execution
3573 of the commands and the echoed arguments are quoted. It
3574 is intended for use in shell scripts to capture the
3575 driver-generated command line. */
3576 verbose_only_flag
++;
3579 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3581 const char *p
= &argv
[i
][1];
3588 fatal ("`-%c' must come at the start of the command line", c
);
3596 if (p
[1] == 0 && i
+ 1 == argc
)
3597 fatal ("argument to `-B' is missing");
3603 len
= strlen (value
);
3605 /* Catch the case where the user has forgotten to append a
3606 directory separator to the path. Note, they may be using
3607 -B to add an executable name prefix, eg "i386-elf-", in
3608 order to distinguish between multiple installations of
3609 GCC in the same directory. Hence we must check to see
3610 if appending a directory separator actually makes a
3611 valid directory name. */
3612 if (! IS_DIR_SEPARATOR (value
[len
- 1])
3613 && is_directory (value
, "", 0))
3615 char *tmp
= xmalloc (len
+ 2);
3616 strcpy (tmp
, value
);
3617 tmp
[len
] = DIR_SEPARATOR
;
3622 /* As a kludge, if the arg is "[foo/]stageN/", just
3623 add "[foo/]include" to the include prefix. */
3626 && (IS_DIR_SEPARATOR (value
[len
- 8]))))
3627 && strncmp (value
+ len
- 7, "stage", 5) == 0
3628 && ISDIGIT (value
[len
- 2])
3629 && (IS_DIR_SEPARATOR (value
[len
- 1])))
3632 add_prefix (&include_prefixes
, "include", NULL
,
3633 PREFIX_PRIORITY_B_OPT
, 0, NULL
);
3636 char * string
= xmalloc (len
+ 1);
3638 strncpy (string
, value
, len
- 7);
3639 strcpy (string
+ len
- 7, "include");
3640 add_prefix (&include_prefixes
, string
, NULL
,
3641 PREFIX_PRIORITY_B_OPT
, 0, NULL
);
3645 add_prefix (&exec_prefixes
, value
, NULL
,
3646 PREFIX_PRIORITY_B_OPT
, 0, &warn_B
);
3647 add_prefix (&startfile_prefixes
, value
, NULL
,
3648 PREFIX_PRIORITY_B_OPT
, 0, &warn_B
);
3649 add_prefix (&include_prefixes
, concat (value
, "include", NULL
),
3650 NULL
, PREFIX_PRIORITY_B_OPT
, 0, NULL
);
3655 case 'v': /* Print our subcommands and print versions. */
3657 /* If they do anything other than exactly `-v', don't set
3658 verbose_flag; rather, continue on to give the error. */
3676 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3681 /* Forward scan, just in case -S or -c is specified
3688 if (argv
[j
][0] == '-')
3690 if (SWITCH_CURTAILS_COMPILATION (argv
[j
][1])
3696 else if ((skip
= SWITCH_TAKES_ARG (argv
[j
][1])))
3697 j
+= skip
- (argv
[j
][2] != 0);
3698 else if ((skip
= WORD_SWITCH_TAKES_ARG (argv
[j
] + 1)))
3705 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
3707 argv
[i
+ 1] = convert_filename (argv
[i
+ 1], ! have_c
, 0);
3709 argv
[i
] = convert_filename (argv
[i
], ! have_c
, 0);
3716 #ifdef MODIFY_TARGET_NAME
3717 is_modify_target_name
= 0;
3719 for (j
= 0; j
< ARRAY_SIZE (modify_target
); j
++)
3720 if (! strcmp (argv
[i
], modify_target
[j
].sw
))
3723 = (char *) xmalloc (strlen (modify_target
[j
].str
)
3724 + strlen (spec_machine
));
3727 int made_addition
= 0;
3729 is_modify_target_name
= 1;
3730 for (p
= spec_machine
, q
= new_name
; *p
!= 0; )
3732 if (modify_target
[j
].add_del
== DELETE
3733 && (! strncmp (q
, modify_target
[j
].str
,
3734 strlen (modify_target
[j
].str
))))
3735 p
+= strlen (modify_target
[j
].str
);
3736 else if (modify_target
[j
].add_del
== ADD
3737 && ! made_addition
&& *p
== '-')
3739 for (r
= modify_target
[j
].str
; *r
!= 0; )
3747 spec_machine
= new_name
;
3750 if (is_modify_target_name
)
3756 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3757 i
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3758 else if (WORD_SWITCH_TAKES_ARG (p
))
3759 i
+= WORD_SWITCH_TAKES_ARG (p
);
3769 if (have_c
&& have_o
&& lang_n_infiles
> 1)
3770 fatal ("cannot specify -o with -c or -S and multiple compilations");
3772 /* Set up the search paths before we go looking for config files. */
3774 /* These come before the md prefixes so that we will find gcc's subcommands
3775 (such as cpp) rather than those of the host system. */
3776 /* Use 2 as fourth arg meaning try just the machine as a suffix,
3777 as well as trying the machine and the version. */
3779 add_prefix (&exec_prefixes
, standard_exec_prefix
, "GCC",
3780 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
);
3781 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
3782 PREFIX_PRIORITY_LAST
, 2, warn_std_ptr
);
3783 add_prefix (&exec_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3784 PREFIX_PRIORITY_LAST
, 2, warn_std_ptr
);
3787 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
3788 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
);
3789 add_prefix (&startfile_prefixes
, standard_exec_prefix_1
, "BINUTILS",
3790 PREFIX_PRIORITY_LAST
, 1, warn_std_ptr
);
3792 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
3793 dir_separator_str
, NULL
);
3795 /* If tooldir is relative, base it on exec_prefixes. A relative
3796 tooldir lets us move the installed tree as a unit.
3798 If GCC_EXEC_PREFIX is defined, then we want to add two relative
3799 directories, so that we can search both the user specified directory
3800 and the standard place. */
3802 if (!IS_ABSOLUTE_PATHNAME (tooldir_prefix
))
3804 if (gcc_exec_prefix
)
3806 char *gcc_exec_tooldir_prefix
3807 = concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
3808 spec_version
, dir_separator_str
, tooldir_prefix
, NULL
);
3810 add_prefix (&exec_prefixes
,
3811 concat (gcc_exec_tooldir_prefix
, "bin",
3812 dir_separator_str
, NULL
),
3813 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
3814 add_prefix (&startfile_prefixes
,
3815 concat (gcc_exec_tooldir_prefix
, "lib",
3816 dir_separator_str
, NULL
),
3817 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
3820 tooldir_prefix
= concat (standard_exec_prefix
, spec_machine
,
3821 dir_separator_str
, spec_version
,
3822 dir_separator_str
, tooldir_prefix
, NULL
);
3825 add_prefix (&exec_prefixes
,
3826 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL
),
3827 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
3828 add_prefix (&startfile_prefixes
,
3829 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL
),
3830 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
3832 /* More prefixes are enabled in main, after we read the specs file
3833 and determine whether this is cross-compilation or not. */
3835 /* Then create the space for the vectors and scan again. */
3837 switches
= ((struct switchstr
*)
3838 xmalloc ((n_switches
+ 1) * sizeof (struct switchstr
)));
3839 infiles
= (struct infile
*) xmalloc ((n_infiles
+ 1) * sizeof (struct infile
));
3842 last_language_n_infiles
= -1;
3844 /* This, time, copy the text of each switch and store a pointer
3845 to the copy in the vector of switches.
3846 Store all the infiles in their vector. */
3848 for (i
= 1; i
< argc
; i
++)
3850 /* Just skip the switches that were handled by the preceding loop. */
3851 #ifdef MODIFY_TARGET_NAME
3852 is_modify_target_name
= 0;
3854 for (j
= 0; j
< ARRAY_SIZE (modify_target
); j
++)
3855 if (! strcmp (argv
[i
], modify_target
[j
].sw
))
3856 is_modify_target_name
= 1;
3858 if (is_modify_target_name
)
3862 if (! strncmp (argv
[i
], "-Wa,", 4))
3864 else if (! strncmp (argv
[i
], "-Wp,", 4))
3866 else if (! strcmp (argv
[i
], "-pass-exit-codes"))
3868 else if (! strcmp (argv
[i
], "-print-search-dirs"))
3870 else if (! strcmp (argv
[i
], "-print-libgcc-file-name"))
3872 else if (! strncmp (argv
[i
], "-print-file-name=", 17))
3874 else if (! strncmp (argv
[i
], "-print-prog-name=", 17))
3876 else if (! strcmp (argv
[i
], "-print-multi-lib"))
3878 else if (! strcmp (argv
[i
], "-print-multi-directory"))
3880 else if (! strcmp (argv
[i
], "-ftarget-help"))
3882 else if (! strcmp (argv
[i
], "-fhelp"))
3884 else if (argv
[i
][0] == '+' && argv
[i
][1] == 'e')
3886 /* Compensate for the +e options to the C++ front-end;
3887 they're there simply for cfront call-compatibility. We do
3888 some magic in default_compilers to pass them down properly.
3889 Note we deliberately start at the `+' here, to avoid passing
3890 -e0 or -e1 down into the linker. */
3891 switches
[n_switches
].part1
= &argv
[i
][0];
3892 switches
[n_switches
].args
= 0;
3893 switches
[n_switches
].live_cond
= SWITCH_OK
;
3894 switches
[n_switches
].validated
= 0;
3897 else if (strncmp (argv
[i
], "-Wl,", 4) == 0)
3900 /* Split the argument at commas. */
3902 for (j
= 4; argv
[i
][j
]; j
++)
3903 if (argv
[i
][j
] == ',')
3905 infiles
[n_infiles
].language
= "*";
3906 infiles
[n_infiles
++].name
3907 = save_string (argv
[i
] + prev
, j
- prev
);
3910 /* Record the part after the last comma. */
3911 infiles
[n_infiles
].language
= "*";
3912 infiles
[n_infiles
++].name
= argv
[i
] + prev
;
3914 else if (strcmp (argv
[i
], "-Xlinker") == 0)
3916 infiles
[n_infiles
].language
= "*";
3917 infiles
[n_infiles
++].name
= argv
[++i
];
3919 else if (strcmp (argv
[i
], "-l") == 0)
3920 { /* POSIX allows separation of -l and the lib arg;
3921 canonicalize by concatenating -l with its arg */
3922 infiles
[n_infiles
].language
= "*";
3923 infiles
[n_infiles
++].name
= concat ("-l", argv
[++i
], NULL
);
3925 else if (strncmp (argv
[i
], "-l", 2) == 0)
3927 infiles
[n_infiles
].language
= "*";
3928 infiles
[n_infiles
++].name
= argv
[i
];
3930 else if (strcmp (argv
[i
], "-specs") == 0)
3932 else if (strncmp (argv
[i
], "-specs=", 7) == 0)
3934 else if (strcmp (argv
[i
], "-time") == 0)
3936 else if ((save_temps_flag
|| report_times
)
3937 && strcmp (argv
[i
], "-pipe") == 0)
3939 /* -save-temps overrides -pipe, so that temp files are produced */
3940 if (save_temps_flag
)
3941 error ("warning: -pipe ignored because -save-temps specified");
3942 /* -time overrides -pipe because we can't get correct stats when
3943 multiple children are running at once. */
3944 else if (report_times
)
3945 error ("warning: -pipe ignored because -time specified");
3947 else if (strcmp (argv
[i
], "-###") == 0)
3949 else if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
3951 const char *p
= &argv
[i
][1];
3956 if (p
[1] == 0 && i
+ 1 == argc
)
3957 fatal ("argument to `-x' is missing");
3959 spec_lang
= argv
[++i
];
3962 if (! strcmp (spec_lang
, "none"))
3963 /* Suppress the warning if -xnone comes after the last input
3964 file, because alternate command interfaces like g++ might
3965 find it useful to place -xnone after each input file. */
3968 last_language_n_infiles
= n_infiles
;
3971 switches
[n_switches
].part1
= p
;
3972 /* Deal with option arguments in separate argv elements. */
3973 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
3974 || WORD_SWITCH_TAKES_ARG (p
))
3977 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
3981 /* Count only the option arguments in separate argv elements. */
3982 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
3984 if (i
+ n_args
>= argc
)
3985 fatal ("argument to `-%s' is missing", p
);
3986 switches
[n_switches
].args
3987 = (const char **) xmalloc ((n_args
+ 1) * sizeof(const char *));
3989 switches
[n_switches
].args
[j
++] = argv
[++i
];
3990 /* Null-terminate the vector. */
3991 switches
[n_switches
].args
[j
] = 0;
3993 else if (strchr (switches_need_spaces
, c
))
3995 /* On some systems, ld cannot handle some options without
3996 a space. So split the option from its argument. */
3997 char *part1
= (char *) xmalloc (2);
4001 switches
[n_switches
].part1
= part1
;
4002 switches
[n_switches
].args
4003 = (const char **) xmalloc (2 * sizeof (const char *));
4004 switches
[n_switches
].args
[0] = xstrdup (p
+1);
4005 switches
[n_switches
].args
[1] = 0;
4008 switches
[n_switches
].args
= 0;
4010 switches
[n_switches
].live_cond
= SWITCH_OK
;
4011 switches
[n_switches
].validated
= 0;
4012 switches
[n_switches
].ordering
= 0;
4013 /* These are always valid, since gcc.c itself understands it. */
4014 if (!strcmp (p
, "save-temps")
4015 || !strcmp (p
, "static-libgcc")
4016 || !strcmp (p
, "shared-libgcc"))
4017 switches
[n_switches
].validated
= 1;
4020 char ch
= switches
[n_switches
].part1
[0];
4022 switches
[n_switches
].validated
= 1;
4028 #ifdef HAVE_TARGET_OBJECT_SUFFIX
4029 argv
[i
] = convert_filename (argv
[i
], 0, access (argv
[i
], F_OK
));
4032 if (strcmp (argv
[i
], "-") != 0 && access (argv
[i
], F_OK
) < 0)
4034 perror_with_name (argv
[i
]);
4039 infiles
[n_infiles
].language
= spec_lang
;
4040 infiles
[n_infiles
++].name
= argv
[i
];
4045 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
4046 error ("warning: `-x %s' after last input file has no effect", spec_lang
);
4048 /* Ensure we only invoke each subprocess once. */
4049 if (target_help_flag
|| print_help_list
)
4053 /* Create a dummy input file, so that we can pass --target-help on to
4054 the various sub-processes. */
4055 infiles
[0].language
= "c";
4056 infiles
[0].name
= "help-dummy";
4058 if (target_help_flag
)
4060 switches
[n_switches
].part1
= "--target-help";
4061 switches
[n_switches
].args
= 0;
4062 switches
[n_switches
].live_cond
= SWITCH_OK
;
4063 switches
[n_switches
].validated
= 0;
4068 if (print_help_list
)
4070 switches
[n_switches
].part1
= "--help";
4071 switches
[n_switches
].args
= 0;
4072 switches
[n_switches
].live_cond
= SWITCH_OK
;
4073 switches
[n_switches
].validated
= 0;
4079 switches
[n_switches
].part1
= 0;
4080 infiles
[n_infiles
].name
= 0;
4083 /* Store switches not filtered out by %{<S} in spec in COLLECT_GCC_OPTIONS
4084 and place that in the environment. */
4087 set_collect_gcc_options ()
4092 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4094 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4095 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
4098 for (i
= 0; (int) i
< n_switches
; i
++)
4100 const char *const *args
;
4103 obstack_grow (&collect_obstack
, " ", 1);
4107 /* Ignore elided switches. */
4108 if (switches
[i
].live_cond
== SWITCH_IGNORE
)
4111 obstack_grow (&collect_obstack
, "'-", 2);
4112 q
= switches
[i
].part1
;
4113 while ((p
= strchr (q
, '\'')))
4115 obstack_grow (&collect_obstack
, q
, p
- q
);
4116 obstack_grow (&collect_obstack
, "'\\''", 4);
4119 obstack_grow (&collect_obstack
, q
, strlen (q
));
4120 obstack_grow (&collect_obstack
, "'", 1);
4122 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4124 obstack_grow (&collect_obstack
, " '", 2);
4126 while ((p
= strchr (q
, '\'')))
4128 obstack_grow (&collect_obstack
, q
, p
- q
);
4129 obstack_grow (&collect_obstack
, "'\\''", 4);
4132 obstack_grow (&collect_obstack
, q
, strlen (q
));
4133 obstack_grow (&collect_obstack
, "'", 1);
4136 obstack_grow (&collect_obstack
, "\0", 1);
4137 putenv (obstack_finish (&collect_obstack
));
4140 /* Process a spec string, accumulating and running commands. */
4142 /* These variables describe the input file name.
4143 input_file_number is the index on outfiles of this file,
4144 so that the output file name can be stored for later use by %o.
4145 input_basename is the start of the part of the input file
4146 sans all directory names, and basename_length is the number
4147 of characters starting there excluding the suffix .c or whatever. */
4149 const char *input_filename
;
4150 static int input_file_number
;
4151 size_t input_filename_length
;
4152 static int basename_length
;
4153 static int suffixed_basename_length
;
4154 static const char *input_basename
;
4155 static const char *input_suffix
;
4156 static struct stat input_stat
;
4157 static int input_stat_set
;
4159 /* The compiler used to process the current input file. */
4160 static struct compiler
*input_file_compiler
;
4162 /* These are variables used within do_spec and do_spec_1. */
4164 /* Nonzero if an arg has been started and not yet terminated
4165 (with space, tab or newline). */
4166 static int arg_going
;
4168 /* Nonzero means %d or %g has been seen; the next arg to be terminated
4169 is a temporary file name. */
4170 static int delete_this_arg
;
4172 /* Nonzero means %w has been seen; the next arg to be terminated
4173 is the output file name of this compilation. */
4174 static int this_is_output_file
;
4176 /* Nonzero means %s has been seen; the next arg to be terminated
4177 is the name of a library file and we should try the standard
4178 search dirs for it. */
4179 static int this_is_library_file
;
4181 /* Nonzero means that the input of this command is coming from a pipe. */
4182 static int input_from_pipe
;
4184 /* Nonnull means substitute this for any suffix when outputting a switches
4186 static const char *suffix_subst
;
4188 /* Process the spec SPEC and run the commands specified therein.
4189 Returns 0 if the spec is successfully processed; -1 if failed. */
4197 value
= do_spec_2 (spec
);
4199 /* Force out any unfinished command.
4200 If -pipe, this forces out the last command if it ended in `|'. */
4203 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4206 set_collect_gcc_options ();
4208 if (argbuf_index
> 0)
4221 delete_this_arg
= 0;
4222 this_is_output_file
= 0;
4223 this_is_library_file
= 0;
4224 input_from_pipe
= 0;
4225 suffix_subst
= NULL
;
4227 return do_spec_1 (spec
, 0, NULL
);
4230 /* Process the sub-spec SPEC as a portion of a larger spec.
4231 This is like processing a whole spec except that we do
4232 not initialize at the beginning and we do not supply a
4233 newline by default at the end.
4234 INSWITCH nonzero means don't process %-sequences in SPEC;
4235 in this case, % is treated as an ordinary character.
4236 This is used while substituting switches.
4237 INSWITCH nonzero also causes SPC not to terminate an argument.
4239 Value is zero unless a line was finished
4240 and the command on that line reported an error. */
4243 do_spec_1 (spec
, inswitch
, soft_matched_part
)
4246 const char *soft_matched_part
;
4248 const char *p
= spec
;
4255 /* If substituting a switch, treat all chars like letters.
4256 Otherwise, NL, SPC, TAB and % are special. */
4257 switch (inswitch
? 'a' : c
)
4260 /* End of line: finish any pending argument,
4261 then run the pending command if one has been started. */
4264 obstack_1grow (&obstack
, 0);
4265 string
= obstack_finish (&obstack
);
4266 if (this_is_library_file
)
4267 string
= find_file (string
);
4268 store_arg (string
, delete_this_arg
, this_is_output_file
);
4269 if (this_is_output_file
)
4270 outfiles
[input_file_number
] = string
;
4274 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4276 for (i
= 0; i
< n_switches
; i
++)
4277 if (!strcmp (switches
[i
].part1
, "pipe"))
4280 /* A `|' before the newline means use a pipe here,
4281 but only if -pipe was specified.
4282 Otherwise, execute now and don't pass the `|' as an arg. */
4285 input_from_pipe
= 1;
4286 switches
[i
].validated
= 1;
4293 set_collect_gcc_options ();
4295 if (argbuf_index
> 0)
4301 /* Reinitialize for a new command, and for a new argument. */
4304 delete_this_arg
= 0;
4305 this_is_output_file
= 0;
4306 this_is_library_file
= 0;
4307 input_from_pipe
= 0;
4311 /* End any pending argument. */
4314 obstack_1grow (&obstack
, 0);
4315 string
= obstack_finish (&obstack
);
4316 if (this_is_library_file
)
4317 string
= find_file (string
);
4318 store_arg (string
, delete_this_arg
, this_is_output_file
);
4319 if (this_is_output_file
)
4320 outfiles
[input_file_number
] = string
;
4324 obstack_1grow (&obstack
, c
);
4330 /* Space or tab ends an argument if one is pending. */
4333 obstack_1grow (&obstack
, 0);
4334 string
= obstack_finish (&obstack
);
4335 if (this_is_library_file
)
4336 string
= find_file (string
);
4337 store_arg (string
, delete_this_arg
, this_is_output_file
);
4338 if (this_is_output_file
)
4339 outfiles
[input_file_number
] = string
;
4341 /* Reinitialize for a new argument. */
4343 delete_this_arg
= 0;
4344 this_is_output_file
= 0;
4345 this_is_library_file
= 0;
4352 fatal ("invalid specification! Bug in cc");
4355 obstack_grow (&obstack
, input_basename
, basename_length
);
4360 obstack_grow (&obstack
, input_basename
, suffixed_basename_length
);
4365 delete_this_arg
= 2;
4368 /* Dump out the directories specified with LIBRARY_PATH,
4369 followed by the absolute directories
4370 that we search for startfiles. */
4373 struct prefix_list
*pl
= startfile_prefixes
.plist
;
4374 size_t bufsize
= 100;
4375 char *buffer
= (char *) xmalloc (bufsize
);
4378 for (; pl
; pl
= pl
->next
)
4380 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4381 /* Used on systems which record the specified -L dirs
4382 and use them to search for dynamic linking. */
4383 /* Relative directories always come from -B,
4384 and it is better not to use them for searching
4385 at run time. In particular, stage1 loses. */
4386 if (!IS_ABSOLUTE_PATHNAME (pl
->prefix
))
4389 /* Try subdirectory if there is one. */
4390 if (multilib_dir
!= NULL
)
4394 if (strlen (pl
->prefix
) + strlen (machine_suffix
)
4396 bufsize
= (strlen (pl
->prefix
)
4397 + strlen (machine_suffix
)) * 2 + 1;
4398 buffer
= (char *) xrealloc (buffer
, bufsize
);
4399 strcpy (buffer
, pl
->prefix
);
4400 strcat (buffer
, machine_suffix
);
4401 if (is_directory (buffer
, multilib_dir
, 1))
4403 do_spec_1 ("-L", 0, NULL
);
4404 #ifdef SPACE_AFTER_L_OPTION
4405 do_spec_1 (" ", 0, NULL
);
4407 do_spec_1 (buffer
, 1, NULL
);
4408 do_spec_1 (multilib_dir
, 1, NULL
);
4409 /* Make this a separate argument. */
4410 do_spec_1 (" ", 0, NULL
);
4413 if (!pl
->require_machine_suffix
)
4415 if (is_directory (pl
->prefix
, multilib_dir
, 1))
4417 do_spec_1 ("-L", 0, NULL
);
4418 #ifdef SPACE_AFTER_L_OPTION
4419 do_spec_1 (" ", 0, NULL
);
4421 do_spec_1 (pl
->prefix
, 1, NULL
);
4422 do_spec_1 (multilib_dir
, 1, NULL
);
4423 /* Make this a separate argument. */
4424 do_spec_1 (" ", 0, NULL
);
4430 if (is_directory (pl
->prefix
, machine_suffix
, 1))
4432 do_spec_1 ("-L", 0, NULL
);
4433 #ifdef SPACE_AFTER_L_OPTION
4434 do_spec_1 (" ", 0, NULL
);
4436 do_spec_1 (pl
->prefix
, 1, NULL
);
4437 /* Remove slash from machine_suffix. */
4438 if (strlen (machine_suffix
) >= bufsize
)
4439 bufsize
= strlen (machine_suffix
) * 2 + 1;
4440 buffer
= (char *) xrealloc (buffer
, bufsize
);
4441 strcpy (buffer
, machine_suffix
);
4442 idx
= strlen (buffer
);
4443 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
4444 buffer
[idx
- 1] = 0;
4445 do_spec_1 (buffer
, 1, NULL
);
4446 /* Make this a separate argument. */
4447 do_spec_1 (" ", 0, NULL
);
4450 if (!pl
->require_machine_suffix
)
4452 if (is_directory (pl
->prefix
, "", 1))
4454 do_spec_1 ("-L", 0, NULL
);
4455 #ifdef SPACE_AFTER_L_OPTION
4456 do_spec_1 (" ", 0, NULL
);
4458 /* Remove slash from pl->prefix. */
4459 if (strlen (pl
->prefix
) >= bufsize
)
4460 bufsize
= strlen (pl
->prefix
) * 2 + 1;
4461 buffer
= (char *) xrealloc (buffer
, bufsize
);
4462 strcpy (buffer
, pl
->prefix
);
4463 idx
= strlen (buffer
);
4464 if (IS_DIR_SEPARATOR (buffer
[idx
- 1]))
4465 buffer
[idx
- 1] = 0;
4466 do_spec_1 (buffer
, 1, NULL
);
4467 /* Make this a separate argument. */
4468 do_spec_1 (" ", 0, NULL
);
4477 /* %efoo means report an error with `foo' as error message
4478 and don't execute any more commands for this file. */
4482 while (*p
!= 0 && *p
!= '\n')
4484 buf
= (char *) alloca (p
- q
+ 1);
4485 strncpy (buf
, q
, p
- q
);
4492 /* %nfoo means report an notice with `foo' on stderr. */
4496 while (*p
!= 0 && *p
!= '\n')
4498 buf
= (char *) alloca (p
- q
+ 1);
4499 strncpy (buf
, q
, p
- q
);
4501 notice ("%s\n", buf
);
4511 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is defined,
4512 and it is not a directory, and it is writable, use it.
4513 Otherwise, fall through and treat this like any other
4516 if ((!save_temps_flag
)
4517 && (stat (HOST_BIT_BUCKET
, &st
) == 0) && (!S_ISDIR (st
.st_mode
))
4518 && (access (HOST_BIT_BUCKET
, W_OK
) == 0))
4520 obstack_grow (&obstack
, HOST_BIT_BUCKET
,
4521 strlen (HOST_BIT_BUCKET
));
4522 delete_this_arg
= 0;
4531 struct temp_name
*t
;
4533 const char *suffix
= p
;
4534 char *saved_suffix
= NULL
;
4536 while (*p
== '.' || ISALPHA ((unsigned char) *p
))
4538 suffix_length
= p
- suffix
;
4539 if (p
[0] == '%' && p
[1] == 'O')
4542 /* We don't support extra suffix characters after %O. */
4543 if (*p
== '.' || ISALPHA ((unsigned char) *p
))
4545 if (suffix_length
== 0)
4546 suffix
= TARGET_OBJECT_SUFFIX
;
4550 = (char *) xmalloc (suffix_length
4551 + strlen (TARGET_OBJECT_SUFFIX
));
4552 strncpy (saved_suffix
, suffix
, suffix_length
);
4553 strcpy (saved_suffix
+ suffix_length
,
4554 TARGET_OBJECT_SUFFIX
);
4556 suffix_length
+= strlen (TARGET_OBJECT_SUFFIX
);
4559 /* If the input_filename has the same suffix specified
4560 for the %g, %u, or %U, and -save-temps is specified,
4561 we could end up using that file as an intermediate
4562 thus clobbering the user's source file (.e.g.,
4563 gcc -save-temps foo.s would clobber foo.s with the
4564 output of cpp0). So check for this condition and
4565 generate a temp file as the intermediate. */
4567 if (save_temps_flag
)
4569 temp_filename_length
= basename_length
+ suffix_length
;
4570 temp_filename
= alloca (temp_filename_length
+ 1);
4571 strncpy ((char *) temp_filename
, input_basename
, basename_length
);
4572 strncpy ((char *) temp_filename
+ basename_length
, suffix
,
4574 *((char *) temp_filename
+ temp_filename_length
) = '\0';
4575 if (strcmp (temp_filename
, input_filename
) != 0)
4577 struct stat st_temp
;
4579 /* Note, set_input() resets input_stat_set to 0. */
4580 if (input_stat_set
== 0)
4582 input_stat_set
= stat (input_filename
, &input_stat
);
4583 if (input_stat_set
>= 0)
4587 /* If we have the stat for the input_filename
4588 and we can do the stat for the temp_filename
4589 then the they could still refer to the same
4590 file if st_dev/st_ino's are the same. */
4592 if (input_stat_set
!= 1
4593 || stat (temp_filename
, &st_temp
) < 0
4594 || input_stat
.st_dev
!= st_temp
.st_dev
4595 || input_stat
.st_ino
!= st_temp
.st_ino
)
4597 temp_filename
= save_string (temp_filename
,
4598 temp_filename_length
+ 1);
4599 obstack_grow (&obstack
, temp_filename
,
4600 temp_filename_length
);
4607 /* See if we already have an association of %g/%u/%U and
4609 for (t
= temp_names
; t
; t
= t
->next
)
4610 if (t
->length
== suffix_length
4611 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
4612 && t
->unique
== (c
!= 'g'))
4615 /* Make a new association if needed. %u and %j
4617 if (t
== 0 || c
== 'u' || c
== 'j')
4621 t
= (struct temp_name
*) xmalloc (sizeof (struct temp_name
));
4622 t
->next
= temp_names
;
4625 t
->length
= suffix_length
;
4628 t
->suffix
= saved_suffix
;
4629 saved_suffix
= NULL
;
4632 t
->suffix
= save_string (suffix
, suffix_length
);
4633 t
->unique
= (c
!= 'g');
4634 temp_filename
= make_temp_file (t
->suffix
);
4635 temp_filename_length
= strlen (temp_filename
);
4636 t
->filename
= temp_filename
;
4637 t
->filename_length
= temp_filename_length
;
4641 free (saved_suffix
);
4643 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
4644 delete_this_arg
= 1;
4650 obstack_grow (&obstack
, input_filename
, input_filename_length
);
4656 struct prefix_list
*pl
= include_prefixes
.plist
;
4658 if (gcc_exec_prefix
)
4660 do_spec_1 ("-iprefix", 1, NULL
);
4661 /* Make this a separate argument. */
4662 do_spec_1 (" ", 0, NULL
);
4663 do_spec_1 (gcc_exec_prefix
, 1, NULL
);
4664 do_spec_1 (" ", 0, NULL
);
4667 for (; pl
; pl
= pl
->next
)
4669 do_spec_1 ("-isystem", 1, NULL
);
4670 /* Make this a separate argument. */
4671 do_spec_1 (" ", 0, NULL
);
4672 do_spec_1 (pl
->prefix
, 1, NULL
);
4673 do_spec_1 (" ", 0, NULL
);
4680 int max
= n_infiles
;
4681 max
+= lang_specific_extra_outfiles
;
4683 for (i
= 0; i
< max
; i
++)
4685 store_arg (outfiles
[i
], 0, 0);
4690 obstack_grow (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
4695 this_is_library_file
= 1;
4699 this_is_output_file
= 1;
4704 int cur_index
= argbuf_index
;
4705 /* Handle the {...} following the %W. */
4708 p
= handle_braces (p
+ 1);
4711 /* If any args were output, mark the last one for deletion
4713 if (argbuf_index
!= cur_index
)
4714 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
4718 /* %x{OPTION} records OPTION for %X to output. */
4724 /* Skip past the option value and make a copy. */
4729 string
= save_string (p1
+ 1, p
- p1
- 2);
4731 /* See if we already recorded this option. */
4732 for (i
= 0; i
< n_linker_options
; i
++)
4733 if (! strcmp (string
, linker_options
[i
]))
4739 /* This option is new; add it. */
4740 add_linker_option (string
, strlen (string
));
4744 /* Dump out the options accumulated previously using %x. */
4746 for (i
= 0; i
< n_linker_options
; i
++)
4748 do_spec_1 (linker_options
[i
], 1, NULL
);
4749 /* Make each accumulated option a separate argument. */
4750 do_spec_1 (" ", 0, NULL
);
4754 /* Dump out the options accumulated previously using -Wa,. */
4756 for (i
= 0; i
< n_assembler_options
; i
++)
4758 do_spec_1 (assembler_options
[i
], 1, NULL
);
4759 /* Make each accumulated option a separate argument. */
4760 do_spec_1 (" ", 0, NULL
);
4764 /* Dump out the options accumulated previously using -Wp,. */
4766 for (i
= 0; i
< n_preprocessor_options
; i
++)
4768 do_spec_1 (preprocessor_options
[i
], 1, NULL
);
4769 /* Make each accumulated option a separate argument. */
4770 do_spec_1 (" ", 0, NULL
);
4774 /* Here are digits and numbers that just process
4775 a certain constant string as a spec. */
4778 value
= do_spec_1 (cc1_spec
, 0, NULL
);
4784 value
= do_spec_1 (cc1plus_spec
, 0, NULL
);
4790 value
= do_spec_1 (asm_spec
, 0, NULL
);
4796 value
= do_spec_1 (asm_final_spec
, 0, NULL
);
4803 const char *const spec
4804 = (input_file_compiler
->cpp_spec
4805 ? input_file_compiler
->cpp_spec
4807 value
= do_spec_1 (spec
, 0, NULL
);
4814 value
= do_spec_1 (endfile_spec
, 0, NULL
);
4820 value
= do_spec_1 (link_spec
, 0, NULL
);
4826 value
= do_spec_1 (lib_spec
, 0, NULL
);
4832 value
= do_spec_1 (libgcc_spec
, 0, NULL
);
4838 if (multilib_dir
&& strcmp (multilib_dir
, ".") != 0)
4844 len
= strlen (multilib_dir
);
4845 obstack_blank (&obstack
, len
+ 1);
4846 p
= obstack_next_free (&obstack
) - (len
+ 1);
4849 for (q
= multilib_dir
; *q
; ++q
, ++p
)
4850 *p
= (IS_DIR_SEPARATOR (*q
) ? '_' : *q
);
4856 char *x
= (char *) alloca (strlen (cpp_predefines
) + 1);
4860 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */
4864 if (! strncmp (y
, "-D", 2))
4865 /* Copy the whole option. */
4866 while (*y
&& *y
!= ' ' && *y
!= '\t')
4868 else if (*y
== ' ' || *y
== '\t')
4869 /* Copy whitespace to the result. */
4871 /* Don't copy other options. */
4878 value
= do_spec_1 (buf
, 0, NULL
);
4886 char *x
= (char *) alloca (strlen (cpp_predefines
) * 4 + 1);
4890 /* Copy all of CPP_PREDEFINES into BUF,
4891 but force them all into the reserved name space if they
4892 aren't already there. The reserved name space is all
4893 identifiers beginning with two underscores or with one
4894 underscore and a capital letter. We do the forcing by
4895 adding up to two underscores to the beginning and end
4896 of each symbol. e.g. mips, _mips, mips_, and _mips_ all
4901 if (! strncmp (y
, "-D", 2))
4910 && ! ISUPPER ((unsigned char) *(y
+ 1))))
4912 /* Stick __ at front of macro name. */
4916 /* Arrange to stick __ at the end as well. */
4920 /* Copy the macro name. */
4921 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4934 /* Copy the value given, if any. */
4935 while (*y
&& *y
!= ' ' && *y
!= '\t')
4938 else if (*y
== ' ' || *y
== '\t')
4939 /* Copy whitespace to the result. */
4941 /* Don't copy -A options */
4947 /* Copy all of CPP_PREDEFINES into BUF,
4948 but put __ after every -D. */
4952 if (! strncmp (y
, "-D", 2))
4958 && ! ISUPPER ((unsigned char) *(y
+ 1))))
4960 /* Stick -D__ at front of macro name. */
4967 /* Copy the macro name. */
4968 while (*y
&& *y
!= '=' && *y
!= ' ' && *y
!= '\t')
4971 /* Copy the value given, if any. */
4972 while (*y
&& *y
!= ' ' && *y
!= '\t')
4977 /* Do not copy this macro - we have just done it before */
4978 while (*y
&& *y
!= ' ' && *y
!= '\t')
4982 else if (*y
== ' ' || *y
== '\t')
4983 /* Copy whitespace to the result. */
4985 /* Don't copy -A options. */
4991 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */
4995 if (! strncmp (y
, "-A", 2))
4996 /* Copy the whole option. */
4997 while (*y
&& *y
!= ' ' && *y
!= '\t')
4999 else if (*y
== ' ' || *y
== '\t')
5000 /* Copy whitespace to the result. */
5002 /* Don't copy other options. */
5009 value
= do_spec_1 (buf
, 0, NULL
);
5016 value
= do_spec_1 (startfile_spec
, 0, NULL
);
5021 /* Here we define characters other than letters and digits. */
5024 p
= handle_braces (p
);
5030 obstack_1grow (&obstack
, '%');
5037 while (p
[len
] && p
[len
] != ' ' && p
[len
] != '%')
5039 suffix_subst
= save_string (p
- 1, len
+ 1);
5045 if (soft_matched_part
)
5047 do_spec_1 (soft_matched_part
, 1, NULL
);
5048 do_spec_1 (" ", 0, NULL
);
5051 /* Catch the case where a spec string contains something like
5052 '%{foo:%*}'. ie there is no * in the pattern on the left
5053 hand side of the :. */
5054 error ("spec failure: '%%*' has not been initialized by pattern match");
5057 /* Process a string found as the value of a spec given by name.
5058 This feature allows individual machine descriptions
5059 to add and use their own specs.
5060 %[...] modifies -D options the way %P does;
5061 %(...) uses the spec unmodified. */
5063 error ("warning: use of obsolete %%[ operator in specs");
5066 const char *name
= p
;
5067 struct spec_list
*sl
;
5070 /* The string after the S/P is the name of a spec that is to be
5072 while (*p
&& *p
!= ')' && *p
!= ']')
5075 /* See if it's in the list. */
5076 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
5077 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
5079 name
= *(sl
->ptr_spec
);
5081 notice ("Processing spec %c%s%c, which is '%s'\n",
5082 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
5091 value
= do_spec_1 (name
, 0, NULL
);
5097 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
5099 const char *y
= name
;
5102 /* Copy all of NAME into BUF, but put __ after
5103 every -D and at the end of each arg. */
5106 if (! strncmp (y
, "-D", 2))
5117 && (*y
== ' ' || *y
== '\t' || *y
== '='
5118 || *y
== '}' || *y
== 0))
5131 value
= do_spec_1 (buf
, 0, NULL
);
5137 /* Discard the closing paren or bracket. */
5145 int c1
= *p
++; /* Select first or second version number. */
5146 const char *v
= compiler_version
;
5148 static const char zeroc
= '0';
5150 /* The format of the version string is
5151 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
5153 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */
5154 while (! ISDIGIT (*v
))
5156 if (v
> compiler_version
&& v
[-1] != '-')
5159 /* If desired, advance to second version number. */
5162 /* Set V after the first period. */
5163 while (ISDIGIT (*v
))
5170 /* If desired, advance to third version number.
5171 But don't complain if it's not present */
5174 /* Set V after the second period. */
5175 while (ISDIGIT (*v
))
5177 if ((*v
!= 0) && (*v
!= ' ') && (*v
!= '.') && (*v
!= '-'))
5183 /* Set Q at the next period or at the end. */
5185 while (ISDIGIT (*q
))
5187 if (*q
!= 0 && q
> v
&& *q
!= ' ' && *q
!= '.' && *q
!= '-')
5191 /* Put that part into the command. */
5192 obstack_grow (&obstack
, v
, q
- v
);
5194 /* Default to "0" */
5195 obstack_grow (&obstack
, &zeroc
, 1);
5201 if (input_from_pipe
)
5202 do_spec_1 ("-", 0, NULL
);
5206 error ("spec failure: unrecognized spec option '%c'", c
);
5212 /* Backslash: treat next character as ordinary. */
5217 /* Ordinary character: put it into the current argument. */
5218 obstack_1grow (&obstack
, c
);
5222 /* End of string. */
5226 /* Return 0 if we call do_spec_1 and that returns -1. */
5232 const char *filter
, *body
= NULL
, *endbody
= NULL
;
5234 int true_once
= 0; /* If, in %{a|b:d}, at least one of a,b was seen. */
5237 int include_blanks
= 1;
5238 int elide_switch
= 0;
5243 /* A '^' after the open-brace means to not give blanks before args. */
5250 /* A `|' after the open-brace means,
5251 if the test fails, output a single minus sign rather than nothing.
5252 This is used in %{|!pipe:...}. */
5259 /* A `<' after the open-brace means that the switch should be
5260 removed from the command-line. */
5266 negate
= suffix
= 0;
5269 /* A `!' after the open-brace negates the condition:
5270 succeed if the specified switch is not present. */
5274 /* A `.' after the open-brace means test against the current suffix. */
5283 if (elide_switch
&& (negate
|| pipe_p
|| suffix
))
5285 /* It doesn't make sense to mix elision with other flags. We
5286 could fatal() here, but the standard seems to be to abort. */
5292 while (*p
!= ':' && *p
!= '}' && *p
!= '|' && *p
!= '&')
5295 if (*p
== '|' && (pipe_p
|| ordered
))
5300 if (*p
!= '}' && *p
!= '&')
5316 fatal ("mismatched braces in specs");
5322 body
= p
, endbody
= p
+ 1;
5327 int found
= (input_suffix
!= 0
5328 && (long) strlen (input_suffix
) == (long) (p
- filter
)
5329 && strncmp (input_suffix
, filter
, p
- filter
) == 0);
5335 && do_spec_1 (save_string (body
, endbody
-body
-1), 0, NULL
) < 0)
5338 else if (p
[-1] == '*' && (p
[0] == '}' || p
[0] == '&'))
5340 /* Substitute all matching switches as separate args. */
5343 for (i
= 0; i
< n_switches
; i
++)
5344 if (!strncmp (switches
[i
].part1
, filter
, p
- 1 - filter
)
5345 && check_live_switch (i
, p
- 1 - filter
))
5349 switches
[i
].live_cond
= SWITCH_IGNORE
;
5350 switches
[i
].validated
= 1;
5353 ordered
= 1, switches
[i
].ordering
= 1;
5358 /* Test for presence of the specified switch. */
5362 /* If name specified ends in *, as in {x*:...},
5363 check for %* and handle that case. */
5364 if (p
[-1] == '*' && !negate
)
5367 const char *r
= body
;
5369 /* First see whether we have %*. */
5373 if (*r
== '%' && r
[1] == '*')
5377 /* If we do, handle that case. */
5380 /* Substitute all matching switches as separate args.
5381 But do this by substituting for %*
5382 in the text that follows the colon. */
5384 unsigned hard_match_len
= p
- filter
- 1;
5385 char *string
= save_string (body
, endbody
- body
- 1);
5387 for (i
= 0; i
< n_switches
; i
++)
5388 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
5389 && check_live_switch (i
, -1))
5391 do_spec_1 (string
, 0, &switches
[i
].part1
[hard_match_len
]);
5392 /* Pass any arguments this switch has. */
5393 give_switch (i
, 1, 1);
5394 suffix_subst
= NULL
;
5397 /* We didn't match. Try again. */
5404 /* If name specified ends in *, as in {x*:...},
5405 check for presence of any switch name starting with x. */
5408 for (i
= 0; i
< n_switches
; i
++)
5410 unsigned hard_match_len
= p
- filter
- 1;
5412 if (!strncmp (switches
[i
].part1
, filter
, hard_match_len
)
5413 && check_live_switch (i
, hard_match_len
))
5420 /* Otherwise, check for presence of exact name specified. */
5423 for (i
= 0; i
< n_switches
; i
++)
5425 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
5426 && switches
[i
].part1
[p
- filter
] == 0
5427 && check_live_switch (i
, -1))
5435 /* If it is as desired (present for %{s...}, absent for %{!s...})
5436 then substitute either the switch or the specified
5437 conditional text. */
5438 if (present
!= negate
)
5442 switches
[i
].live_cond
= SWITCH_IGNORE
;
5443 switches
[i
].validated
= 1;
5445 else if (ordered
|| *p
== '&')
5446 ordered
= 1, switches
[i
].ordering
= 1;
5448 give_switch (i
, 0, include_blanks
);
5450 /* Even if many alternatives are matched, only output once. */
5455 /* Here if a %{|...} conditional fails: output a minus sign,
5456 which means "standard output" or "standard input". */
5457 do_spec_1 ("-", 0, NULL
);
5462 /* We didn't match; try again. */
5469 goto next_ampersand
;
5475 /* Doing this set of switches later preserves their command-line
5476 ordering. This is needed for e.g. -U, -D and -A. */
5477 for (i
= 0; i
< n_switches
; i
++)
5478 if (switches
[i
].ordering
== 1)
5480 switches
[i
].ordering
= 0;
5481 give_switch (i
, 0, include_blanks
);
5484 /* Process the spec just once, regardless of match count. */
5487 if (do_spec_1 (save_string (body
, endbody
- body
- 1),
5495 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
5496 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
5497 spec, or -1 if either exact match or %* is used.
5499 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
5500 whose value does not begin with "no-" is obsoleted by the same value
5501 with the "no-", similarly for a switch with the "no-" prefix. */
5504 check_live_switch (switchnum
, prefix_length
)
5508 const char *name
= switches
[switchnum
].part1
;
5511 /* In the common case of {<at-most-one-letter>*}, a negating
5512 switch would always match, so ignore that case. We will just
5513 send the conflicting switches to the compiler phase. */
5514 if (prefix_length
>= 0 && prefix_length
<= 1)
5517 /* If we already processed this switch and determined if it was
5518 live or not, return our past determination. */
5519 if (switches
[switchnum
].live_cond
!= 0)
5520 return switches
[switchnum
].live_cond
> 0;
5522 /* Now search for duplicate in a manner that depends on the name. */
5526 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5527 if (switches
[i
].part1
[0] == 'O')
5529 switches
[switchnum
].validated
= 1;
5530 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5535 case 'W': case 'f': case 'm':
5536 if (! strncmp (name
+ 1, "no-", 3))
5538 /* We have Xno-YYY, search for XYYY. */
5539 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5540 if (switches
[i
].part1
[0] == name
[0]
5541 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
5543 switches
[switchnum
].validated
= 1;
5544 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5550 /* We have XYYY, search for Xno-YYY. */
5551 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
5552 if (switches
[i
].part1
[0] == name
[0]
5553 && switches
[i
].part1
[1] == 'n'
5554 && switches
[i
].part1
[2] == 'o'
5555 && switches
[i
].part1
[3] == '-'
5556 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
5558 switches
[switchnum
].validated
= 1;
5559 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
5566 /* Otherwise the switch is live. */
5567 switches
[switchnum
].live_cond
= SWITCH_LIVE
;
5571 /* Pass a switch to the current accumulating command
5572 in the same form that we received it.
5573 SWITCHNUM identifies the switch; it is an index into
5574 the vector of switches gcc received, which is `switches'.
5575 This cannot fail since it never finishes a command line.
5577 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.
5579 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument
5583 give_switch (switchnum
, omit_first_word
, include_blanks
)
5585 int omit_first_word
;
5588 if (switches
[switchnum
].live_cond
== SWITCH_IGNORE
)
5591 if (!omit_first_word
)
5593 do_spec_1 ("-", 0, NULL
);
5594 do_spec_1 (switches
[switchnum
].part1
, 1, NULL
);
5597 if (switches
[switchnum
].args
!= 0)
5600 for (p
= switches
[switchnum
].args
; *p
; p
++)
5602 const char *arg
= *p
;
5605 do_spec_1 (" ", 0, NULL
);
5608 unsigned length
= strlen (arg
);
5611 while (length
-- && !IS_DIR_SEPARATOR (arg
[length
]))
5612 if (arg
[length
] == '.')
5614 ((char *)arg
)[length
] = 0;
5618 do_spec_1 (arg
, 1, NULL
);
5620 ((char *)arg
)[length
] = '.';
5621 do_spec_1 (suffix_subst
, 1, NULL
);
5624 do_spec_1 (arg
, 1, NULL
);
5628 do_spec_1 (" ", 0, NULL
);
5629 switches
[switchnum
].validated
= 1;
5632 /* Search for a file named NAME trying various prefixes including the
5633 user's -B prefix and some standard ones.
5634 Return the absolute file name found. If nothing is found, return NAME. */
5642 /* Try multilib_dir if it is defined. */
5643 if (multilib_dir
!= NULL
)
5645 const char *const try = ACONCAT ((multilib_dir
, dir_separator_str
, name
, NULL
));
5647 newname
= find_a_file (&startfile_prefixes
, try, R_OK
);
5649 /* If we don't find it in the multi library dir, then fall
5650 through and look for it in the normal places. */
5651 if (newname
!= NULL
)
5655 newname
= find_a_file (&startfile_prefixes
, name
, R_OK
);
5656 return newname
? newname
: name
;
5659 /* Determine whether a directory exists. If LINKER, return 0 for
5660 certain fixed names not needed by the linker. If not LINKER, it is
5661 only important to return 0 if the host machine has a small ARG_MAX
5665 is_directory (path1
, path2
, linker
)
5670 int len1
= strlen (path1
);
5671 int len2
= strlen (path2
);
5672 char *path
= (char *) alloca (3 + len1
+ len2
);
5676 #ifndef SMALL_ARG_MAX
5681 /* Construct the path from the two parts. Ensure the string ends with "/.".
5682 The resulting path will be a directory even if the given path is a
5684 memcpy (path
, path1
, len1
);
5685 memcpy (path
+ len1
, path2
, len2
);
5686 cp
= path
+ len1
+ len2
;
5687 if (!IS_DIR_SEPARATOR (cp
[-1]))
5688 *cp
++ = DIR_SEPARATOR
;
5692 /* Exclude directories that the linker is known to search. */
5695 && strcmp (path
, concat (dir_separator_str
, "lib",
5696 dir_separator_str
, ".", NULL
)) == 0)
5698 && strcmp (path
, concat (dir_separator_str
, "usr",
5699 dir_separator_str
, "lib",
5700 dir_separator_str
, ".", NULL
)) == 0)))
5703 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
5706 /* Set up the various global variables to indicate that we're processing
5707 the input file named FILENAME. */
5710 set_input (filename
)
5711 const char *filename
;
5715 input_filename
= filename
;
5716 input_filename_length
= strlen (input_filename
);
5718 input_basename
= input_filename
;
5719 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5720 /* Skip drive name so 'x:foo' is handled properly. */
5721 if (input_basename
[1] == ':')
5722 input_basename
+= 2;
5724 for (p
= input_basename
; *p
; p
++)
5725 if (IS_DIR_SEPARATOR (*p
))
5726 input_basename
= p
+ 1;
5728 /* Find a suffix starting with the last period,
5729 and set basename_length to exclude that suffix. */
5730 basename_length
= strlen (input_basename
);
5731 suffixed_basename_length
= basename_length
;
5732 p
= input_basename
+ basename_length
;
5733 while (p
!= input_basename
&& *p
!= '.')
5735 if (*p
== '.' && p
!= input_basename
)
5737 basename_length
= p
- input_basename
;
5738 input_suffix
= p
+ 1;
5743 /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
5744 we will need to do a stat on the input_filename. The
5745 INPUT_STAT_SET signals that the stat is needed. */
5749 /* On fatal signals, delete all the temporary files. */
5752 fatal_error (signum
)
5755 signal (signum
, SIG_DFL
);
5756 delete_failure_queue ();
5757 delete_temp_files ();
5758 /* Get the same signal again, this time not handled,
5759 so its normal effect occurs. */
5760 kill (getpid (), signum
);
5763 extern int main
PARAMS ((int, const char *const *));
5768 const char *const *argv
;
5772 int linker_was_run
= 0;
5773 char *explicit_link_files
;
5776 struct user_specs
*uptr
;
5778 p
= argv
[0] + strlen (argv
[0]);
5779 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
5783 xmalloc_set_program_name (programname
);
5785 #ifdef GCC_DRIVER_HOST_INITIALIZATION
5786 /* Perform host dependent initialization when needed. */
5787 GCC_DRIVER_HOST_INITIALIZATION
;
5790 gcc_init_libintl ();
5792 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
5793 signal (SIGINT
, fatal_error
);
5795 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
5796 signal (SIGHUP
, fatal_error
);
5798 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
5799 signal (SIGTERM
, fatal_error
);
5801 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
5802 signal (SIGPIPE
, fatal_error
);
5805 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
5806 receive the signal. A different setting is inheritable */
5807 signal (SIGCHLD
, SIG_DFL
);
5811 argbuf
= (const char **) xmalloc (argbuf_length
* sizeof (const char *));
5813 obstack_init (&obstack
);
5815 /* Build multilib_select, et. al from the separate lines that make up each
5816 multilib selection. */
5818 const char *const *q
= multilib_raw
;
5821 obstack_init (&multilib_obstack
);
5822 while ((p
= *q
++) != (char *) 0)
5823 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5825 obstack_1grow (&multilib_obstack
, 0);
5826 multilib_select
= obstack_finish (&multilib_obstack
);
5828 q
= multilib_matches_raw
;
5829 while ((p
= *q
++) != (char *) 0)
5830 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5832 obstack_1grow (&multilib_obstack
, 0);
5833 multilib_matches
= obstack_finish (&multilib_obstack
);
5835 q
= multilib_exclusions_raw
;
5836 while ((p
= *q
++) != (char *) 0)
5837 obstack_grow (&multilib_obstack
, p
, strlen (p
));
5839 obstack_1grow (&multilib_obstack
, 0);
5840 multilib_exclusions
= obstack_finish (&multilib_obstack
);
5843 for (i
= 0; i
< ARRAY_SIZE (multilib_defaults_raw
); i
++)
5846 obstack_1grow (&multilib_obstack
, ' ');
5847 obstack_grow (&multilib_obstack
,
5848 multilib_defaults_raw
[i
],
5849 strlen (multilib_defaults_raw
[i
]));
5853 obstack_1grow (&multilib_obstack
, 0);
5854 multilib_defaults
= obstack_finish (&multilib_obstack
);
5857 /* Set up to remember the pathname of gcc and any options
5858 needed for collect. We use argv[0] instead of programname because
5859 we need the complete pathname. */
5860 obstack_init (&collect_obstack
);
5861 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
5862 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0]) + 1);
5863 putenv (obstack_finish (&collect_obstack
));
5865 #ifdef INIT_ENVIRONMENT
5866 /* Set up any other necessary machine specific environment variables. */
5867 putenv (INIT_ENVIRONMENT
);
5870 /* Make a table of what switches there are (switches, n_switches).
5871 Make a table of specified input files (infiles, n_infiles).
5872 Decode switches that are handled locally. */
5874 process_command (argc
, argv
);
5876 /* Initialize the vector of specs to just the default.
5877 This means one element containing 0s, as a terminator. */
5879 compilers
= (struct compiler
*) xmalloc (sizeof default_compilers
);
5880 memcpy ((char *) compilers
, (char *) default_compilers
,
5881 sizeof default_compilers
);
5882 n_compilers
= n_default_compilers
;
5884 /* Read specs from a file if there is one. */
5886 machine_suffix
= concat (spec_machine
, dir_separator_str
,
5887 spec_version
, dir_separator_str
, NULL
);
5888 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL
);
5890 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
);
5891 /* Read the specs file unless it is a default one. */
5892 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
5893 read_specs (specs_file
, TRUE
);
5897 /* We need to check standard_exec_prefix/just_machine_suffix/specs
5898 for any override of as, ld and libraries. */
5899 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
5900 + strlen (just_machine_suffix
)
5901 + sizeof ("specs"));
5903 strcpy (specs_file
, standard_exec_prefix
);
5904 strcat (specs_file
, just_machine_suffix
);
5905 strcat (specs_file
, "specs");
5906 if (access (specs_file
, R_OK
) == 0)
5907 read_specs (specs_file
, TRUE
);
5909 /* If not cross-compiling, look for startfiles in the standard places.
5910 Similarly, don't add the standard prefixes if startfile handling
5911 will be under control of startfile_prefix_spec. */
5912 if (*cross_compile
== '0' && *startfile_prefix_spec
== 0)
5914 if (*md_exec_prefix
)
5916 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC",
5917 PREFIX_PRIORITY_LAST
, 0, NULL
);
5918 add_prefix (&startfile_prefixes
, md_exec_prefix
, "GCC",
5919 PREFIX_PRIORITY_LAST
, 0, NULL
);
5922 if (*md_startfile_prefix
)
5923 add_prefix (&startfile_prefixes
, md_startfile_prefix
, "GCC",
5924 PREFIX_PRIORITY_LAST
, 0, NULL
);
5926 if (*md_startfile_prefix_1
)
5927 add_prefix (&startfile_prefixes
, md_startfile_prefix_1
, "GCC",
5928 PREFIX_PRIORITY_LAST
, 0, NULL
);
5930 /* If standard_startfile_prefix is relative, base it on
5931 standard_exec_prefix. This lets us move the installed tree
5932 as a unit. If GCC_EXEC_PREFIX is defined, base
5933 standard_startfile_prefix on that as well. */
5934 if (IS_ABSOLUTE_PATHNAME (standard_startfile_prefix
))
5935 add_prefix (&startfile_prefixes
, standard_startfile_prefix
, "BINUTILS",
5936 PREFIX_PRIORITY_LAST
, 0, NULL
);
5939 if (gcc_exec_prefix
)
5940 add_prefix (&startfile_prefixes
,
5941 concat (gcc_exec_prefix
, machine_suffix
,
5942 standard_startfile_prefix
, NULL
),
5943 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
5944 add_prefix (&startfile_prefixes
,
5945 concat (standard_exec_prefix
,
5947 standard_startfile_prefix
, NULL
),
5948 NULL
, PREFIX_PRIORITY_LAST
, 0, NULL
);
5951 add_prefix (&startfile_prefixes
, standard_startfile_prefix_1
,
5952 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
5953 add_prefix (&startfile_prefixes
, standard_startfile_prefix_2
,
5954 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
5955 #if 0 /* Can cause surprises, and one can use -B./ instead. */
5956 add_prefix (&startfile_prefixes
, "./", NULL
,
5957 PREFIX_PRIORITY_LAST
, 1, NULL
);
5962 if (!IS_ABSOLUTE_PATHNAME (standard_startfile_prefix
)
5964 add_prefix (&startfile_prefixes
,
5965 concat (gcc_exec_prefix
, machine_suffix
,
5966 standard_startfile_prefix
, NULL
),
5967 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, NULL
);
5970 if (*startfile_prefix_spec
!= 0
5971 && do_spec_2 (startfile_prefix_spec
) == 0
5972 && do_spec_1 (" ", 0, NULL
) == 0)
5975 for (ndx
= 0; ndx
< argbuf_index
; ndx
++)
5976 add_prefix (&startfile_prefixes
, argbuf
[ndx
], "BINUTILS",
5977 PREFIX_PRIORITY_LAST
, 0, NULL
);
5980 /* Process any user specified specs in the order given on the command
5982 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
5984 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
, R_OK
);
5985 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
5988 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
5989 if (gcc_exec_prefix
)
5990 gcc_exec_prefix
= concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
5991 spec_version
, dir_separator_str
, NULL
);
5993 /* Now we have the specs.
5994 Set the `valid' bits for switches that match anything in any spec. */
5996 validate_all_switches ();
5998 /* Now that we have the switches and the specs, set
5999 the subdirectory based on the options. */
6000 set_multilib_dir ();
6002 /* Warn about any switches that no pass was interested in. */
6004 for (i
= 0; (int) i
< n_switches
; i
++)
6005 if (! switches
[i
].validated
)
6006 error ("unrecognized option `-%s'", switches
[i
].part1
);
6008 /* Obey some of the options. */
6010 if (print_search_dirs
)
6012 printf (_("install: %s%s\n"), standard_exec_prefix
, machine_suffix
);
6013 printf (_("programs: %s\n"), build_search_list (&exec_prefixes
, "", 0));
6014 printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes
, "", 0));
6018 if (print_file_name
)
6020 printf ("%s\n", find_file (print_file_name
));
6024 if (print_prog_name
)
6026 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
);
6027 printf ("%s\n", (newname
? newname
: print_prog_name
));
6031 if (print_multi_lib
)
6033 print_multilib_info ();
6037 if (print_multi_directory
)
6039 if (multilib_dir
== NULL
)
6042 printf ("%s\n", multilib_dir
);
6046 if (target_help_flag
)
6048 /* Print if any target specific options. */
6050 /* We do not exit here. Instead we have created a fake input file
6051 called 'target-dummy' which needs to be compiled, and we pass this
6052 on to the various sub-processes, along with the --target-help
6056 if (print_help_list
)
6062 printf (_("\nFor bug reporting instructions, please see:\n"));
6063 printf ("%s.\n", GCCBUGURL
);
6068 /* We do not exit here. Instead we have created a fake input file
6069 called 'help-dummy' which needs to be compiled, and we pass this
6070 on the various sub-processes, along with the --help switch. */
6078 notice ("Configured with: %s\n", configuration_arguments
);
6080 #ifdef THREAD_MODEL_SPEC
6081 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
6082 but there's no point in doing all this processing just to get
6083 thread_model back. */
6084 obstack_init (&obstack
);
6085 do_spec_1 (THREAD_MODEL_SPEC
, 0, thread_model
);
6086 obstack_1grow (&obstack
, '\0');
6087 thrmod
= obstack_finish (&obstack
);
6089 thrmod
= thread_model
;
6092 notice ("Thread model: %s\n", thrmod
);
6094 /* compiler_version is truncated at the first space when initialized
6095 from version string, so truncate version_string at the first space
6096 before comparing. */
6097 for (n
= 0; version_string
[n
]; n
++)
6098 if (version_string
[n
] == ' ')
6101 if (! strncmp (version_string
, compiler_version
, n
)
6102 && compiler_version
[n
] == 0)
6103 notice ("gcc version %s\n", version_string
);
6105 notice ("gcc driver version %s executing gcc version %s\n",
6106 version_string
, compiler_version
);
6112 if (n_infiles
== added_libraries
)
6113 fatal ("no input files");
6115 /* Make a place to record the compiler output file names
6116 that correspond to the input files. */
6119 i
+= lang_specific_extra_outfiles
;
6120 outfiles
= (const char **) xcalloc (i
, sizeof (char *));
6122 /* Record which files were specified explicitly as link input. */
6124 explicit_link_files
= xcalloc (1, n_infiles
);
6126 for (i
= 0; (int) i
< n_infiles
; i
++)
6128 int this_file_error
= 0;
6130 /* Tell do_spec what to substitute for %i. */
6132 input_file_number
= i
;
6133 set_input (infiles
[i
].name
);
6135 /* Use the same thing in %o, unless cp->spec says otherwise. */
6137 outfiles
[i
] = input_filename
;
6139 /* Figure out which compiler from the file's suffix. */
6142 = lookup_compiler (infiles
[i
].name
, input_filename_length
,
6143 infiles
[i
].language
);
6145 if (input_file_compiler
)
6147 /* Ok, we found an applicable compiler. Run its spec. */
6149 if (input_file_compiler
->spec
[0] == '#')
6151 error ("%s: %s compiler not installed on this system",
6152 input_filename
, &input_file_compiler
->spec
[1]);
6153 this_file_error
= 1;
6157 value
= do_spec (input_file_compiler
->spec
);
6159 this_file_error
= 1;
6163 /* If this file's name does not contain a recognized suffix,
6164 record it as explicit linker input. */
6167 explicit_link_files
[i
] = 1;
6169 /* Clear the delete-on-failure queue, deleting the files in it
6170 if this compilation failed. */
6172 if (this_file_error
)
6174 delete_failure_queue ();
6177 /* If this compilation succeeded, don't delete those files later. */
6178 clear_failure_queue ();
6181 /* Reset the output file name to the first input file name, for use
6182 with %b in LINK_SPEC on a target that prefers not to emit a.out
6185 set_input (infiles
[0].name
);
6187 if (error_count
== 0)
6189 /* Make sure INPUT_FILE_NUMBER points to first available open
6191 input_file_number
= n_infiles
;
6192 if (lang_specific_pre_link ())
6196 /* Run ld to link all the compiler output files. */
6198 if (error_count
== 0)
6200 int tmp
= execution_count
;
6202 /* We'll use ld if we can't find collect2. */
6203 if (! strcmp (linker_name_spec
, "collect2"))
6205 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
);
6207 linker_name_spec
= "ld";
6209 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
6211 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH");
6212 putenv_from_prefixes (&startfile_prefixes
, LIBRARY_PATH_ENV
);
6214 value
= do_spec (link_command_spec
);
6217 linker_was_run
= (tmp
!= execution_count
);
6220 /* If options said don't run linker,
6221 complain about input files to be given to the linker. */
6223 if (! linker_was_run
&& error_count
== 0)
6224 for (i
= 0; (int) i
< n_infiles
; i
++)
6225 if (explicit_link_files
[i
])
6226 error ("%s: linker input file unused because linking not done",
6229 /* Delete some or all of the temporary files we made. */
6232 delete_failure_queue ();
6233 delete_temp_files ();
6235 if (print_help_list
)
6237 printf (("\nFor bug reporting instructions, please see:\n"));
6238 printf ("%s\n", GCCBUGURL
);
6241 return (signal_count
!= 0 ? 2
6242 : error_count
> 0 ? (pass_exit_codes
? greatest_status
: 1)
6246 /* Find the proper compilation spec for the file name NAME,
6247 whose length is LENGTH. LANGUAGE is the specified language,
6248 or 0 if this file is to be passed to the linker. */
6250 static struct compiler
*
6251 lookup_compiler (name
, length
, language
)
6254 const char *language
;
6256 struct compiler
*cp
;
6258 /* If this was specified by the user to be a linker input, indicate that. */
6259 if (language
!= 0 && language
[0] == '*')
6262 /* Otherwise, look for the language, if one is spec'd. */
6265 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6266 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
6269 error ("language %s not recognized", language
);
6273 /* Look for a suffix. */
6274 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6276 if (/* The suffix `-' matches only the file name `-'. */
6277 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
6278 || (strlen (cp
->suffix
) < length
6279 /* See if the suffix matches the end of NAME. */
6280 && !strcmp (cp
->suffix
,
6281 name
+ length
- strlen (cp
->suffix
))
6286 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
6287 /* look again, but case-insensitively this time. */
6289 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
6291 if (/* The suffix `-' matches only the file name `-'. */
6292 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
6293 || (strlen (cp
->suffix
) < length
6294 /* See if the suffix matches the end of NAME. */
6295 && ((!strcmp (cp
->suffix
,
6296 name
+ length
- strlen (cp
->suffix
))
6297 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
6298 && !strcasecmp (cp
->suffix
,
6299 name
+ length
- strlen (cp
->suffix
)))
6305 if (cp
>= compilers
)
6307 if (cp
->spec
[0] != '@')
6308 /* A non-alias entry: return it. */
6311 /* An alias entry maps a suffix to a language.
6312 Search for the language; pass 0 for NAME and LENGTH
6313 to avoid infinite recursion if language not found. */
6314 return lookup_compiler (NULL
, 0, cp
->spec
+ 1);
6320 save_string (s
, len
)
6324 char *result
= xmalloc (len
+ 1);
6326 memcpy (result
, s
, len
);
6332 pfatal_with_name (name
)
6335 perror_with_name (name
);
6336 delete_temp_files ();
6341 perror_with_name (name
)
6344 error ("%s: %s", name
, xstrerror (errno
));
6348 pfatal_pexecute (errmsg_fmt
, errmsg_arg
)
6349 const char *errmsg_fmt
;
6350 const char *errmsg_arg
;
6354 int save_errno
= errno
;
6356 /* Space for trailing '\0' is in %s. */
6357 char *msg
= xmalloc (strlen (errmsg_fmt
) + strlen (errmsg_arg
));
6358 sprintf (msg
, errmsg_fmt
, errmsg_arg
);
6364 pfatal_with_name (errmsg_fmt
);
6367 /* Output an error message and exit */
6372 fatal ("internal gcc abort");
6375 /* Output an error message and exit */
6378 fatal
VPARAMS ((const char *msgid
, ...))
6380 VA_OPEN (ap
, msgid
);
6381 VA_FIXEDARG (ap
, const char *, msgid
);
6383 fprintf (stderr
, "%s: ", programname
);
6384 vfprintf (stderr
, _(msgid
), ap
);
6386 fprintf (stderr
, "\n");
6387 delete_temp_files ();
6392 error
VPARAMS ((const char *msgid
, ...))
6394 VA_OPEN (ap
, msgid
);
6395 VA_FIXEDARG (ap
, const char *, msgid
);
6397 fprintf (stderr
, "%s: ", programname
);
6398 vfprintf (stderr
, _(msgid
), ap
);
6401 fprintf (stderr
, "\n");
6405 notice
VPARAMS ((const char *msgid
, ...))
6407 VA_OPEN (ap
, msgid
);
6408 VA_FIXEDARG (ap
, const char *, msgid
);
6410 vfprintf (stderr
, _(msgid
), ap
);
6415 validate_all_switches ()
6417 struct compiler
*comp
;
6420 struct spec_list
*spec
;
6422 for (comp
= compilers
; comp
->spec
; comp
++)
6426 if (c
== '%' && (*p
== '{' || (*p
== 'W' && *++p
== '{')))
6427 /* We have a switch spec. */
6428 validate_switches (p
+ 1);
6431 /* Look through the linked list of specs read from the specs file. */
6432 for (spec
= specs
; spec
; spec
= spec
->next
)
6434 p
= *(spec
->ptr_spec
);
6436 if (c
== '%' && (*p
== '{' || (*p
== 'W' && *++p
== '{')))
6437 /* We have a switch spec. */
6438 validate_switches (p
+ 1);
6441 p
= link_command_spec
;
6443 if (c
== '%' && (*p
== '{' || (*p
== 'W' && *++p
== '{')))
6444 /* We have a switch spec. */
6445 validate_switches (p
+ 1);
6448 /* Look at the switch-name that comes after START
6449 and mark as valid all supplied switches that match it. */
6452 validate_switches (start
)
6455 const char *p
= start
;
6472 while (*p
!= ':' && *p
!= '}' && *p
!= '|' && *p
!= '&')
6477 else if (p
[-1] == '*')
6479 /* Mark all matching switches as valid. */
6480 for (i
= 0; i
< n_switches
; i
++)
6481 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
- 1))
6482 switches
[i
].validated
= 1;
6486 /* Mark an exact matching switch as valid. */
6487 for (i
= 0; i
< n_switches
; i
++)
6489 if (!strncmp (switches
[i
].part1
, filter
, p
- filter
)
6490 && switches
[i
].part1
[p
- filter
] == 0)
6491 switches
[i
].validated
= 1;
6495 if (*p
++ == '|' || p
[-1] == '&')
6499 /* Check whether a particular argument was used. The first time we
6500 canonicalize the switches to keep only the ones we care about. */
6510 const char *replace
;
6515 static struct mswitchstr
*mswitches
;
6516 static int n_mswitches
;
6521 struct mswitchstr
*matches
;
6525 /* Break multilib_matches into the component strings of string
6526 and replacement string. */
6527 for (q
= multilib_matches
; *q
!= '\0'; q
++)
6532 (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
6534 q
= multilib_matches
;
6544 matches
[i
].len
= q
- matches
[i
].str
;
6546 matches
[i
].replace
= ++q
;
6547 while (*q
!= ';' && *q
!= '\0')
6553 matches
[i
].rep_len
= q
- matches
[i
].replace
;
6559 /* Now build a list of the replacement string for switches that we care
6560 about. Make sure we allocate at least one entry. This prevents
6561 xmalloc from calling fatal, and prevents us from re-executing this
6564 = (struct mswitchstr
*) xmalloc ((sizeof (struct mswitchstr
))
6565 * (n_switches
? n_switches
: 1));
6566 for (i
= 0; i
< n_switches
; i
++)
6568 int xlen
= strlen (switches
[i
].part1
);
6569 for (j
= 0; j
< cnt
; j
++)
6570 if (xlen
== matches
[j
].len
6571 && ! strncmp (switches
[i
].part1
, matches
[j
].str
, xlen
))
6573 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
6574 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
6575 mswitches
[n_mswitches
].replace
= (char *) 0;
6576 mswitches
[n_mswitches
].rep_len
= 0;
6583 for (i
= 0; i
< n_mswitches
; i
++)
6584 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
6591 default_arg (p
, len
)
6595 const char *start
, *end
;
6597 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+ 1)
6599 while (*start
== ' ' || *start
== '\t')
6605 for (end
= start
+ 1; *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
6608 if ((end
- start
) == len
&& strncmp (p
, start
, len
) == 0)
6618 /* Work out the subdirectory to use based on the options. The format of
6619 multilib_select is a list of elements. Each element is a subdirectory
6620 name followed by a list of options followed by a semicolon. The format
6621 of multilib_exclusions is the same, but without the preceding
6622 directory. First gcc will check the exclusions, if none of the options
6623 beginning with an exclamation point are present, and all of the other
6624 options are present, then we will ignore this completely. Passing
6625 that, gcc will consider each multilib_select in turn using the same
6626 rules for matching the options. If a match is found, that subdirectory
6633 unsigned int this_path_len
;
6634 const char *this_path
, *this_arg
;
6638 p
= multilib_exclusions
;
6641 /* Ignore newlines. */
6648 /* Check the arguments. */
6662 while (*p
!= ' ' && *p
!= ';')
6669 if (*this_arg
!= '!')
6677 ok
= used_arg (this_arg
, p
- this_arg
);
6691 p
= multilib_select
;
6694 /* Ignore newlines. */
6701 /* Get the initial path. */
6709 this_path_len
= p
- this_path
;
6711 /* Check the arguments. */
6726 while (*p
!= ' ' && *p
!= ';')
6733 if (*this_arg
!= '!')
6741 /* If this is a default argument, we can just ignore it.
6742 This is true even if this_arg begins with '!'. Beginning
6743 with '!' does not mean that this argument is necessarily
6744 inappropriate for this library: it merely means that
6745 there is a more specific library which uses this
6746 argument. If this argument is a default, we need not
6747 consider that more specific library. */
6748 if (! default_arg (this_arg
, p
- this_arg
))
6750 ok
= used_arg (this_arg
, p
- this_arg
);
6761 if (this_path_len
!= 1
6762 || this_path
[0] != '.')
6764 char *new_multilib_dir
= xmalloc (this_path_len
+ 1);
6765 strncpy (new_multilib_dir
, this_path
, this_path_len
);
6766 new_multilib_dir
[this_path_len
] = '\0';
6767 multilib_dir
= new_multilib_dir
;
6776 /* Print out the multiple library subdirectory selection
6777 information. This prints out a series of lines. Each line looks
6778 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
6779 required. Only the desired options are printed out, the negative
6780 matches. The options are print without a leading dash. There are
6781 no spaces to make it easy to use the information in the shell.
6782 Each subdirectory is printed only once. This assumes the ordering
6783 generated by the genmultilib script. Also, we leave out ones that match
6787 print_multilib_info ()
6789 const char *p
= multilib_select
;
6790 const char *last_path
= 0, *this_path
;
6792 unsigned int last_path_len
= 0;
6797 /* Ignore newlines. */
6804 /* Get the initial path. */
6813 /* Check for matches with the multilib_exclusions. We don't bother
6814 with the '!' in either list. If any of the exclusion rules match
6815 all of its options with the select rule, we skip it. */
6817 const char *e
= multilib_exclusions
;
6818 const char *this_arg
;
6823 /* Ignore newlines. */
6830 /* Check the arguments. */
6847 while (*e
!= ' ' && *e
!= ';')
6858 int len
= e
- this_arg
;
6865 while (*q
!= ' ' && *q
!= ';')
6872 if (! strncmp (arg
, this_arg
, (len
< q
- arg
) ? q
- arg
: len
) ||
6873 default_arg (this_arg
, e
- this_arg
))
6903 /* If this is a duplicate, skip it. */
6904 skip
= (last_path
!= 0 && (unsigned int) (p
- this_path
) == last_path_len
6905 && ! strncmp (last_path
, this_path
, last_path_len
));
6907 last_path
= this_path
;
6908 last_path_len
= p
- this_path
;
6911 /* If this directory requires any default arguments, we can skip
6912 it. We will already have printed a directory identical to
6913 this one which does not require that default argument. */
6931 while (*q
!= ' ' && *q
!= ';')
6939 && default_arg (arg
, q
- arg
))
6954 for (p1
= last_path
; p1
< p
; p1
++)
6973 use_arg
= *p
!= '!';
6978 while (*p
!= ' ' && *p
!= ';')
6993 /* If there are extra options, print them now. */
6994 if (multilib_extra
&& *multilib_extra
)
6996 int print_at
= TRUE
;
6999 for (q
= multilib_extra
; *q
!= '\0'; q
++)