1/* Compiler driver program that can handle many languages. 2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 3 2000 Free Software Foundation, Inc. 4 5This file is part of GNU CC. 6 7GNU CC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GNU CC is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GNU CC; see the file COPYING. If not, write to 19the Free Software Foundation, 59 Temple Place - Suite 330, 20Boston, MA 02111-1307, USA. 21 22This paragraph is here to try to keep Sun CC from dying. 23The number of chars here seems crucial!!!! */ 24 25/* This program is the user interface to the C compiler and possibly to 26other compilers. It is used because compilation is a complicated procedure 27which involves running several programs and passing temporary files between 28them, forwarding the users switches to those programs selectively, 29and deleting the temporary files at the end. 30 31CC recognizes how to compile each input file by suffixes in the file names. 32Once it knows which kind of compilation to perform, the procedure for 33compilation is specified by a string called a "spec". */ 34 35#include "config.h" 36#include "system.h" 37#include <signal.h> 38 39#include "obstack.h" 40#include "intl.h" 41#include "prefix.h" 42 43#ifdef VMS 44#define exit __posix_exit 45#endif 46 47/* By default there is no special suffix for executables. */ 48#ifdef EXECUTABLE_SUFFIX 49#define HAVE_EXECUTABLE_SUFFIX 50#else 51#define EXECUTABLE_SUFFIX "" 52#endif 53 54/* By default, the suffix for object files is ".o". */ 55#ifdef OBJECT_SUFFIX 56#define HAVE_OBJECT_SUFFIX 57#else 58#define OBJECT_SUFFIX ".o" 59#endif 60 61/* By default, colon separates directories in a path. */ 62#ifndef PATH_SEPARATOR 63#define PATH_SEPARATOR ':' 64#endif 65 66#ifndef DIR_SEPARATOR 67#define DIR_SEPARATOR '/' 68#endif 69 70/* Define IS_DIR_SEPARATOR. */ 71#ifndef DIR_SEPARATOR_2 72# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) 73#else /* DIR_SEPARATOR_2 */ 74# define IS_DIR_SEPARATOR(ch) \ 75 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) 76#endif /* DIR_SEPARATOR_2 */ 77 78static char dir_separator_str[] = {DIR_SEPARATOR, 0}; 79 80#define obstack_chunk_alloc xmalloc 81#define obstack_chunk_free free 82 83#ifndef GET_ENV_PATH_LIST 84#define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0) 85#endif 86 87/* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */ 88#ifndef LIBRARY_PATH_ENV 89#define LIBRARY_PATH_ENV "LIBRARY_PATH" 90#endif 91 92#ifndef HAVE_KILL 93#define kill(p,s) raise(s) 94#endif 95 96#if defined(__BEOS__) || defined(__HAIKU__) 97#include <OS.h> 98/* the thread priority used for all gcc-tools */ 99static int priority = B_LOW_PRIORITY; 100#endif 101 102/* If a stage of compilation returns an exit status >= 1, 103 compilation of that file ceases. */ 104 105#define MIN_FATAL_STATUS 1 106 107/* Flag saying to print the directories gcc will search through looking for 108 programs, libraries, etc. */ 109 110static int print_search_dirs; 111 112/* Flag saying to print the full filename of this file 113 as found through our usual search mechanism. */ 114 115static const char *print_file_name = NULL; 116 117/* As print_file_name, but search for executable file. */ 118 119static const char *print_prog_name = NULL; 120 121/* Flag saying to print the relative path we'd use to 122 find libgcc.a given the current compiler flags. */ 123 124static int print_multi_directory; 125 126/* Flag saying to print the list of subdirectories and 127 compiler flags used to select them in a standard form. */ 128 129static int print_multi_lib; 130 131/* Flag saying to print the command line options understood by gcc and its 132 sub-processes. */ 133 134static int print_help_list; 135 136/* Flag indicating whether we should print the command and arguments */ 137 138static int verbose_flag; 139 140/* Nonzero means write "temp" files in source directory 141 and use the source file's name in them, and don't delete them. */ 142 143static int save_temps_flag; 144 145/* The compiler version. */ 146 147static char *compiler_version; 148 149/* The target version specified with -V */ 150 151static char *spec_version = DEFAULT_TARGET_VERSION; 152 153/* The target machine specified with -b. */ 154 155static const char *spec_machine = DEFAULT_TARGET_MACHINE; 156 157/* Nonzero if cross-compiling. 158 When -b is used, the value comes from the `specs' file. */ 159 160#ifdef CROSS_COMPILE 161static char *cross_compile = "1"; 162#else 163static char *cross_compile = "0"; 164#endif 165 166/* The number of errors that have occurred; the link phase will not be 167 run if this is non-zero. */ 168static int error_count = 0; 169 170/* This is the obstack which we use to allocate many strings. */ 171 172static struct obstack obstack; 173 174/* This is the obstack to build an environment variable to pass to 175 collect2 that describes all of the relevant switches of what to 176 pass the compiler in building the list of pointers to constructors 177 and destructors. */ 178 179static struct obstack collect_obstack; 180 181extern char *version_string; 182 183/* Forward declaration for prototypes. */ 184struct path_prefix; 185 186static void init_spec PROTO((void)); 187static void read_specs PROTO((const char *, int)); 188static void set_spec PROTO((const char *, const char *)); 189static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *)); 190static char *build_search_list PROTO((struct path_prefix *, const char *, int)); 191static void putenv_from_prefixes PROTO((struct path_prefix *, const char *)); 192static char *find_a_file PROTO((struct path_prefix *, const char *, int)); 193static void add_prefix PROTO((struct path_prefix *, const char *, 194 const char *, int, int, int *)); 195static char *skip_whitespace PROTO((char *)); 196static void record_temp_file PROTO((const char *, int, int)); 197static void delete_if_ordinary PROTO((const char *)); 198static void delete_temp_files PROTO((void)); 199static void delete_failure_queue PROTO((void)); 200static void clear_failure_queue PROTO((void)); 201static int check_live_switch PROTO((int, int)); 202static const char *handle_braces PROTO((const char *)); 203static char *save_string PROTO((const char *, int)); 204extern int do_spec PROTO((const char *)); 205static int do_spec_1 PROTO((const char *, int, const char *)); 206static const char *find_file PROTO((const char *)); 207static int is_directory PROTO((const char *, const char *, int)); 208static void validate_switches PROTO((const char *)); 209static void validate_all_switches PROTO((void)); 210static void give_switch PROTO((int, int, int)); 211static int used_arg PROTO((const char *, int)); 212static int default_arg PROTO((const char *, int)); 213static void set_multilib_dir PROTO((void)); 214static void print_multilib_info PROTO((void)); 215static void pfatal_with_name PROTO((const char *)) ATTRIBUTE_NORETURN; 216static void perror_with_name PROTO((const char *)); 217static void pfatal_pexecute PROTO((const char *, const char *)) 218 ATTRIBUTE_NORETURN; 219static void error PVPROTO((const char *, ...)) 220 ATTRIBUTE_PRINTF_1; 221static void notice PVPROTO((const char *, ...)) 222 ATTRIBUTE_PRINTF_1; 223static void display_help PROTO((void)); 224static void add_preprocessor_option PROTO ((const char *, int)); 225static void add_assembler_option PROTO ((const char *, int)); 226static void add_linker_option PROTO ((const char *, int)); 227static void process_command PROTO ((int, char **)); 228static int execute PROTO ((void)); 229static void unused_prefix_warnings PROTO ((struct path_prefix *)); 230static void clear_args PROTO ((void)); 231static void fatal_error PROTO ((int)); 232 233void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN; 234 235/* Called before processing to change/add/remove arguments. */ 236extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)), 237 int *, char ***, int *)); 238 239/* Called before linking. Returns 0 on success and -1 on failure. */ 240extern int lang_specific_pre_link (); 241 242/* Number of extra output files that lang_specific_pre_link may generate. */ 243extern int lang_specific_extra_outfiles; 244 245/* Specs are strings containing lines, each of which (if not blank) 246is made up of a program name, and arguments separated by spaces. 247The program name must be exact and start from root, since no path 248is searched and it is unreliable to depend on the current working directory. 249Redirection of input or output is not supported; the subprograms must 250accept filenames saying what files to read and write. 251 252In addition, the specs can contain %-sequences to substitute variable text 253or for conditional text. Here is a table of all defined %-sequences. 254Note that spaces are not generated automatically around the results of 255expanding these sequences; therefore, you can concatenate them together 256or with constant text in a single argument. 257 258 %% substitute one % into the program name or argument. 259 %i substitute the name of the input file being processed. 260 %b substitute the basename of the input file being processed. 261 This is the substring up to (and not including) the last period 262 and not including the directory. 263 %gSUFFIX 264 substitute a file name that has suffix SUFFIX and is chosen 265 once per compilation, and mark the argument a la %d. To reduce 266 exposure to denial-of-service attacks, the file name is now 267 chosen in a way that is hard to predict even when previously 268 chosen file names are known. For example, `%g.s ... %g.o ... %g.s' 269 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches 270 the regexp "[.A-Za-z]*" or the special string "%O", which is 271 treated exactly as if %O had been pre-processed. Previously, %g 272 was simply substituted with a file name chosen once per compilation, 273 without regard to any appended suffix (which was therefore treated 274 just like ordinary text), making such attacks more likely to succeed. 275 %uSUFFIX 276 like %g, but generates a new temporary file name even if %uSUFFIX 277 was already seen. 278 %USUFFIX 279 substitutes the last file name generated with %uSUFFIX, generating a 280 new one if there is no such last file name. In the absence of any 281 %uSUFFIX, this is just like %gSUFFIX, except they don't share 282 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' 283 would involve the generation of two distinct file names, one 284 for each `%g.s' and another for each `%U.s'. Previously, %U was 285 simply substituted with a file name chosen for the previous %u, 286 without regard to any appended suffix. 287 %d marks the argument containing or following the %d as a 288 temporary file name, so that that file will be deleted if CC exits 289 successfully. Unlike %g, this contributes no text to the argument. 290 %w marks the argument containing or following the %w as the 291 "output file" of this compilation. This puts the argument 292 into the sequence of arguments that %o will substitute later. 293 %W{...} 294 like %{...} but mark last argument supplied within 295 as a file to be deleted on failure. 296 %o substitutes the names of all the output files, with spaces 297 automatically placed around them. You should write spaces 298 around the %o as well or the results are undefined. 299 %o is for use in the specs for running the linker. 300 Input files whose names have no recognized suffix are not compiled 301 at all, but they are included among the output files, so they will 302 be linked. 303 %O substitutes the suffix for object files. Note that this is 304 handled specially when it immediately follows %g, %u, or %U, 305 because of the need for those to form complete file names. The 306 handling is such that %O is treated exactly as if it had already 307 been substituted, except that %g, %u, and %U do not currently 308 support additional SUFFIX characters following %O as they would 309 following, for example, `.o'. 310 %p substitutes the standard macro predefinitions for the 311 current target machine. Use this when running cpp. 312 %P like %p, but puts `__' before and after the name of each macro. 313 (Except macros that already have __.) 314 This is for ANSI C. 315 %I Substitute a -iprefix option made from GCC_EXEC_PREFIX. 316 %s current argument is the name of a library or startup file of some sort. 317 Search for that file in a standard list of directories 318 and substitute the full name found. 319 %eSTR Print STR as an error message. STR is terminated by a newline. 320 Use this when inconsistent options are detected. 321 %x{OPTION} Accumulate an option for %X. 322 %X Output the accumulated linker options specified by compilations. 323 %Y Output the accumulated assembler options specified by compilations. 324 %Z Output the accumulated preprocessor options specified by compilations. 325 %v1 Substitute the major version number of GCC. 326 (For version 2.5.n, this is 2.) 327 %v2 Substitute the minor version number of GCC. 328 (For version 2.5.n, this is 5.) 329 %a process ASM_SPEC as a spec. 330 This allows config.h to specify part of the spec for running as. 331 %A process ASM_FINAL_SPEC as a spec. A capital A is actually 332 used here. This can be used to run a post-processor after the 333 assembler has done its job. 334 %D Dump out a -L option for each directory in startfile_prefixes. 335 If multilib_dir is set, extra entries are generated with it affixed. 336 %l process LINK_SPEC as a spec. 337 %L process LIB_SPEC as a spec. 338 %G process LIBGCC_SPEC as a spec. 339 %S process STARTFILE_SPEC as a spec. A capital S is actually used here. 340 %E process ENDFILE_SPEC as a spec. A capital E is actually used here. 341 %c process SIGNED_CHAR_SPEC as a spec. 342 %C process CPP_SPEC as a spec. A capital C is actually used here. 343 %1 process CC1_SPEC as a spec. 344 %2 process CC1PLUS_SPEC as a spec. 345 %| output "-" if the input for the current command is coming from a pipe. 346 %* substitute the variable part of a matched option. (See below.) 347 Note that each comma in the substituted string is replaced by 348 a single space. 349 %{S} substitutes the -S switch, if that switch was given to CC. 350 If that switch was not specified, this substitutes nothing. 351 Here S is a metasyntactic variable. 352 %{S*} substitutes all the switches specified to CC whose names start 353 with -S. This is used for -o, -D, -I, etc; switches that take 354 arguments. CC considers `-o foo' as being one switch whose 355 name starts with `o'. %{o*} would substitute this text, 356 including the space; thus, two arguments would be generated. 357 %{^S*} likewise, but don't put a blank between a switch and any args. 358 %{S*:X} substitutes X if one or more switches whose names start with -S are 359 specified to CC. Note that the tail part of the -S option 360 (i.e. the part matched by the `*') will be substituted for each 361 occurrence of %* within X. 362 %{S:X} substitutes X, but only if the -S switch was given to CC. 363 %{!S:X} substitutes X, but only if the -S switch was NOT given to CC. 364 %{|S:X} like %{S:X}, but if no S switch, substitute `-'. 365 %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'. 366 %{.S:X} substitutes X, but only if processing a file with suffix S. 367 %{!.S:X} substitutes X, but only if NOT processing a file with suffix S. 368 %{S|P:X} substitutes X if either -S or -P was given to CC. This may be 369 combined with ! and . as above binding stronger than the OR. 370 %(Spec) processes a specification defined in a specs file as *Spec: 371 %[Spec] as above, but put __ around -D arguments 372 373The conditional text X in a %{S:X} or %{!S:X} construct may contain 374other nested % constructs or spaces, or even newlines. They are 375processed as usual, as described above. 376 377The -O, -f, -m, and -W switches are handled specifically in these 378constructs. If another value of -O or the negated form of a -f, -m, or 379-W switch is found later in the command line, the earlier switch 380value is ignored, except with {S*} where S is just one letter; this 381passes all matching options. 382 383The character | at the beginning of the predicate text is used to indicate 384that a command should be piped to the following command, but only if -pipe 385is specified. 386 387Note that it is built into CC which switches take arguments and which 388do not. You might think it would be useful to generalize this to 389allow each compiler's spec to say which switches take arguments. But 390this cannot be done in a consistent fashion. CC cannot even decide 391which input files have been specified without knowing which switches 392take arguments, and it must know which input files to compile in order 393to tell which compilers to run. 394 395CC also knows implicitly that arguments starting in `-l' are to be 396treated as compiler output files, and passed to the linker in their 397proper position among the other output files. */ 398 399/* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */ 400 401/* config.h can define ASM_SPEC to provide extra args to the assembler 402 or extra switch-translations. */ 403#ifndef ASM_SPEC 404#define ASM_SPEC "" 405#endif 406 407/* config.h can define ASM_FINAL_SPEC to run a post processor after 408 the assembler has run. */ 409#ifndef ASM_FINAL_SPEC 410#define ASM_FINAL_SPEC "" 411#endif 412 413/* config.h can define CPP_SPEC to provide extra args to the C preprocessor 414 or extra switch-translations. */ 415#ifndef CPP_SPEC 416#define CPP_SPEC "" 417#endif 418 419/* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus 420 or extra switch-translations. */ 421#ifndef CC1_SPEC 422#define CC1_SPEC "" 423#endif 424 425/* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus 426 or extra switch-translations. */ 427#ifndef CC1PLUS_SPEC 428#define CC1PLUS_SPEC "" 429#endif 430 431/* config.h can define LINK_SPEC to provide extra args to the linker 432 or extra switch-translations. */ 433#ifndef LINK_SPEC 434#define LINK_SPEC "" 435#endif 436 437/* config.h can define LIB_SPEC to override the default libraries. */ 438#ifndef LIB_SPEC 439#define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" 440#endif 441 442/* config.h can define LIBGCC_SPEC to override how and when libgcc.a is 443 included. */ 444#ifndef LIBGCC_SPEC 445#if defined(LINK_LIBGCC_SPECIAL) || defined(LINK_LIBGCC_SPECIAL_1) 446/* Have gcc do the search for libgcc.a. */ 447#define LIBGCC_SPEC "libgcc.a%s" 448#else 449#define LIBGCC_SPEC "-lgcc" 450#endif 451#endif 452 453/* config.h can define STARTFILE_SPEC to override the default crt0 files. */ 454#ifndef STARTFILE_SPEC 455#define STARTFILE_SPEC \ 456 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" 457#endif 458 459/* config.h can define SWITCHES_NEED_SPACES to control which options 460 require spaces between the option and the argument. */ 461#ifndef SWITCHES_NEED_SPACES 462#define SWITCHES_NEED_SPACES "" 463#endif 464 465/* config.h can define ENDFILE_SPEC to override the default crtn files. */ 466#ifndef ENDFILE_SPEC 467#define ENDFILE_SPEC "" 468#endif 469 470/* This spec is used for telling cpp whether char is signed or not. */ 471#ifndef SIGNED_CHAR_SPEC 472/* Use #if rather than ?: 473 because MIPS C compiler rejects like ?: in initializers. */ 474#if DEFAULT_SIGNED_CHAR 475#define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}" 476#else 477#define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}" 478#endif 479#endif 480 481#ifndef LINKER_NAME 482#define LINKER_NAME "collect2" 483#endif 484 485static char *cpp_spec = CPP_SPEC; 486static char *cpp_predefines = CPP_PREDEFINES; 487static char *cc1_spec = CC1_SPEC; 488static char *cc1plus_spec = CC1PLUS_SPEC; 489static char *signed_char_spec = SIGNED_CHAR_SPEC; 490static char *asm_spec = ASM_SPEC; 491static char *asm_final_spec = ASM_FINAL_SPEC; 492static char *link_spec = LINK_SPEC; 493static char *lib_spec = LIB_SPEC; 494static char *libgcc_spec = LIBGCC_SPEC; 495static char *endfile_spec = ENDFILE_SPEC; 496static char *startfile_spec = STARTFILE_SPEC; 497static char *switches_need_spaces = SWITCHES_NEED_SPACES; 498static char *linker_name_spec = LINKER_NAME; 499 500/* Some compilers have limits on line lengths, and the multilib_select 501 and/or multilib_matches strings can be very long, so we build them at 502 run time. */ 503static struct obstack multilib_obstack; 504static char *multilib_select; 505static char *multilib_matches; 506static char *multilib_defaults; 507#include "multilib.h" 508 509/* Check whether a particular argument is a default argument. */ 510 511#ifndef MULTILIB_DEFAULTS 512#define MULTILIB_DEFAULTS { "" } 513#endif 514 515static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS; 516 517struct user_specs { 518 struct user_specs *next; 519 const char *filename; 520}; 521 522static struct user_specs *user_specs_head, *user_specs_tail; 523 524/* This defines which switch letters take arguments. */ 525 526#define DEFAULT_SWITCH_TAKES_ARG(CHAR) \ 527 ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \ 528 || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \ 529 || (CHAR) == 'I' || (CHAR) == 'm' || (CHAR) == 'x' \ 530 || (CHAR) == 'L' || (CHAR) == 'A' || (CHAR) == 'V' \ 531 || (CHAR) == 'B' || (CHAR) == 'b') 532 533#ifndef SWITCH_TAKES_ARG 534#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR) 535#endif 536 537/* This defines which multi-letter switches take arguments. */ 538 539#define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \ 540 (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \ 541 || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \ 542 || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \ 543 || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \ 544 || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \ 545 || !strcmp (STR, "isystem") || !strcmp (STR, "specs")) 546 547#ifndef WORD_SWITCH_TAKES_ARG 548#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR) 549#endif 550 551 552#ifdef HAVE_EXECUTABLE_SUFFIX 553/* This defines which switches stop a full compilation. */ 554#define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \ 555 ((CHAR) == 'c' || (CHAR) == 'S') 556 557#ifndef SWITCH_CURTAILS_COMPILATION 558#define SWITCH_CURTAILS_COMPILATION(CHAR) \ 559 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) 560#endif 561#endif 562 563/* Record the mapping from file suffixes for compilation specs. */ 564 565struct compiler 566{ 567 const char *suffix; /* Use this compiler for input files 568 whose names end in this suffix. */ 569 570 const char *spec[4]; /* To use this compiler, concatenate these 571 specs and pass to do_spec. */ 572}; 573 574/* Pointer to a vector of `struct compiler' that gives the spec for 575 compiling a file, based on its suffix. 576 A file that does not end in any of these suffixes will be passed 577 unchanged to the loader and nothing else will be done to it. 578 579 An entry containing two 0s is used to terminate the vector. 580 581 If multiple entries match a file, the last matching one is used. */ 582 583static struct compiler *compilers; 584 585/* Number of entries in `compilers', not counting the null terminator. */ 586 587static int n_compilers; 588 589/* The default list of file name suffixes and their compilation specs. */ 590 591static struct compiler default_compilers[] = 592{ 593 /* Add lists of suffixes of known languages here. If those languages 594 were not present when we built the driver, we will hit these copies 595 and be given a more meaningful error than "file not used since 596 linking is not done". */ 597 {".m", {"#Objective-C"}}, 598 {".cc", {"#C++"}}, {".cxx", {"#C++"}}, {".cpp", {"#C++"}}, 599 {".c++", {"#C++"}}, {".C", {"#C++"}}, 600 {".ads", {"#Ada"}}, {".adb", {"#Ada"}}, {".ada", {"#Ada"}}, 601 {".f", {"#Fortran"}}, {".for", {"#Fortran"}}, {".F", {"#Fortran"}}, 602 {".fpp", {"#Fortran"}}, 603 {".p", {"#Pascal"}}, {".pas", {"#Pascal"}}, 604 /* Next come the entries for C. */ 605 {".c", {"@c"}}, 606 {"@c", 607 { 608#if USE_CPPLIB 609 "%{E|M|MM:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\ 610 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\ 611 %{C:%{!E:%eGNU C does not support -C without using -E}}\ 612 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ 613 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\ 614 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\ 615 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\ 616 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ 617 %{ffast-math:-D__FAST_MATH__}\ 618 %{traditional} %{ftraditional:-traditional}\ 619 %{traditional-cpp:-traditional}\ 620 %{fleading-underscore} %{fno-leading-underscore}\ 621 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ 622 %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\ 623 %{!E:%{!M:%{!MM:cc1 %i %1 \ 624 %{std*} %{nostdinc*} %{A*} %{I*} %I\ 625 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\ 626 %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ 627 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\ 628 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\ 629 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\ 630 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ 631 %{ffast-math:-D__FAST_MATH__}\ 632 %{H} %C %{D*} %{U*} %{i*} %Z\ 633 %{ftraditional:-traditional}\ 634 %{traditional-cpp:-traditional}\ 635 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\ 636 %{aux-info*} %{Qn:-fno-ident}\ 637 %{--help:--help}\ 638 %{g*} %{O*} %{W*} %{w} %{pedantic*}\ 639 %{priority*}\ 640 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 641 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 642 %{!S:as %a %Y\ 643 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ 644 %{!pipe:%g.s} %A\n }}}}" 645#else /* ! USE_CPPLIB */ 646 "cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\ 647 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\ 648 %{C:%{!E:%eGNU C does not support -C without using -E}}\ 649 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ 650 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\ 651 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\ 652 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\ 653 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ 654 %{ffast-math:-D__FAST_MATH__}\ 655 %{traditional} %{ftraditional:-traditional}\ 656 %{traditional-cpp:-traditional}\ 657 %{fleading-underscore} %{fno-leading-underscore}\ 658 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ 659 %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", 660 "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \ 661 %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\ 662 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\ 663 %{priority*}\ 664 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\ 665 %{aux-info*} %{Qn:-fno-ident}\ 666 %{--help:--help} \ 667 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 668 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 669 %{!S:as %a %Y\ 670 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ 671 %{!pipe:%g.s} %A\n }}}}" 672#endif /* ! USE_CPPLIB */ 673 }}, 674 {"-", 675 {"%{E:cpp0 -lang-c %{ansi:-std=c89} %{std*} %{nostdinc*}\ 676 %{C} %{v} %{A*} %{I*} %{P} %{$} %I\ 677 %{C:%{!E:%eGNU C does not support -C without using -E}}\ 678 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ 679 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\ 680 %{ansi|std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\ 681 %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\ 682 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ 683 %{ffast-math:-D__FAST_MATH__}\ 684 %{traditional} %{ftraditional:-traditional}\ 685 %{traditional-cpp:-traditional}\ 686 %{fleading-underscore} %{fno-leading-underscore}\ 687 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ 688 %i %W{o*}}\ 689 %{!E:%e-E required when input is from standard input}"}}, 690 {".h", {"@c-header"}}, 691 {"@c-header", 692 {"%{!E:%eCompilation of header file requested} \ 693 cpp0 %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %{$} %I\ 694 %{C:%{!E:%eGNU C does not support -C without using -E}}\ 695 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ 696 %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2}\ 697 %{std=*:%{!std=gnu*:-trigraphs -D__STRICT_ANSI__}}\ 698 %{!undef:%{!std=*:%p}%{std=gnu*:%p} %P} %{trigraphs}\ 699 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ 700 %{ffast-math:-D__FAST_MATH__}\ 701 %{traditional} %{ftraditional:-traditional}\ 702 %{traditional-cpp:-traditional}\ 703 %{fleading-underscore} %{fno-leading-underscore}\ 704 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ 705 %i %W{o*}"}}, 706 {".i", {"@cpp-output"}}, 707 {"@cpp-output", 708 {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\ 709 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\ 710 %{priority*}\ 711 %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\ 712 %{aux-info*} %{Qn:-fno-ident}\ 713 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 714 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 715 %{!S:as %a %Y\ 716 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ 717 %{!pipe:%g.s} %A\n }}}}"}}, 718 {".s", {"@assembler"}}, 719 {"@assembler", 720 {"%{!M:%{!MM:%{!E:%{!S:as %a %Y\ 721 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ 722 %i %A\n }}}}"}}, 723 {".S", {"@assembler-with-cpp"}}, 724 {"@assembler-with-cpp", 725 {"cpp0 -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %{$} %I\ 726 %{C:%{!E:%eGNU C does not support -C without using -E}}\ 727 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\ 728 -$ %{!undef:%p %P} -D__ASSEMBLER__ \ 729 %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ 730 %{ffast-math:-D__FAST_MATH__}\ 731 %{traditional} %{ftraditional:-traditional}\ 732 %{traditional-cpp:-traditional}\ 733 %{fleading-underscore} %{fno-leading-underscore}\ 734 %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ 735 %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", 736 "%{!M:%{!MM:%{!E:%{!S:as %a %Y\ 737 %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ 738 %{!pipe:%g.s} %A\n }}}}"}}, 739#include "specs.h" 740 /* Mark end of table */ 741 {0, {0}} 742}; 743 744/* Number of elements in default_compilers, not counting the terminator. */ 745 746static int n_default_compilers 747 = (sizeof default_compilers / sizeof (struct compiler)) - 1; 748 749/* Here is the spec for running the linker, after compiling all files. */ 750 751/* -u* was put back because both BSD and SysV seem to support it. */ 752/* %{static:} simply prevents an error message if the target machine 753 doesn't handle -static. */ 754/* We want %{T*} after %{L*} and %D so that it can be used to specify linker 755 scripts which exist in user specified directories, or in standard 756 directories. */ 757#ifdef LINK_COMMAND_SPEC 758/* Provide option to override link_command_spec from machine specific 759 configuration files. */ 760static const char *link_command_spec = 761 LINK_COMMAND_SPEC; 762#else 763#ifdef LINK_LIBGCC_SPECIAL 764/* Don't generate -L options. */ 765static const char *link_command_spec = "\ 766%{!fsyntax-only: \ 767 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \ 768 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\ 769 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ 770 %{static:} %{L*} %o\ 771 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\ 772 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\ 773 %{T*}\ 774 \n }}}}}}"; 775#else 776/* Use -L. */ 777static const char *link_command_spec = "\ 778%{!fsyntax-only: \ 779 %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \ 780 %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\ 781 %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ 782 %{static:} %{L*} %D %o\ 783 %{!nostdlib:%{!nodefaultlibs:%G %L %G}}\ 784 %{!A:%{!nostdlib:%{!nostartfiles:%E}}}\ 785 %{T*}\ 786 \n }}}}}}"; 787#endif 788#endif 789 790/* A vector of options to give to the linker. 791 These options are accumulated by %x, 792 and substituted into the linker command with %X. */ 793static int n_linker_options; 794static char **linker_options; 795 796/* A vector of options to give to the assembler. 797 These options are accumulated by -Wa, 798 and substituted into the assembler command with %Y. */ 799static int n_assembler_options; 800static char **assembler_options; 801 802/* A vector of options to give to the preprocessor. 803 These options are accumulated by -Wp, 804 and substituted into the preprocessor command with %Z. */ 805static int n_preprocessor_options; 806static char **preprocessor_options; 807 808/* Define how to map long options into short ones. */ 809 810/* This structure describes one mapping. */ 811struct option_map 812{ 813 /* The long option's name. */ 814 const char *name; 815 /* The equivalent short option. */ 816 const char *equivalent; 817 /* Argument info. A string of flag chars; NULL equals no options. 818 a => argument required. 819 o => argument optional. 820 j => join argument to equivalent, making one word. 821 * => require other text after NAME as an argument. */ 822 const char *arg_info; 823}; 824 825/* This is the table of mappings. Mappings are tried sequentially 826 for each option encountered; the first one that matches, wins. */ 827 828struct option_map option_map[] = 829 { 830 {"--all-warnings", "-Wall", 0}, 831 {"--ansi", "-ansi", 0}, 832 {"--assemble", "-S", 0}, 833 {"--assert", "-A", "a"}, 834 {"--classpath", "-fclasspath=", "aj"}, 835 {"--CLASSPATH", "-fCLASSPATH=", "aj"}, 836 {"--comments", "-C", 0}, 837 {"--compile", "-c", 0}, 838 {"--debug", "-g", "oj"}, 839 {"--define-macro", "-D", "aj"}, 840 {"--dependencies", "-M", 0}, 841 {"--dump", "-d", "a"}, 842 {"--dumpbase", "-dumpbase", "a"}, 843 {"--entry", "-e", 0}, 844 {"--extra-warnings", "-W", 0}, 845 {"--for-assembler", "-Wa", "a"}, 846 {"--for-linker", "-Xlinker", "a"}, 847 {"--force-link", "-u", "a"}, 848 {"--imacros", "-imacros", "a"}, 849 {"--include", "-include", "a"}, 850 {"--include-barrier", "-I-", 0}, 851 {"--include-directory", "-I", "aj"}, 852 {"--include-directory-after", "-idirafter", "a"}, 853 {"--include-prefix", "-iprefix", "a"}, 854 {"--include-with-prefix", "-iwithprefix", "a"}, 855 {"--include-with-prefix-before", "-iwithprefixbefore", "a"}, 856 {"--include-with-prefix-after", "-iwithprefix", "a"}, 857 {"--language", "-x", "a"}, 858 {"--library-directory", "-L", "a"}, 859 {"--machine", "-m", "aj"}, 860 {"--machine-", "-m", "*j"}, 861#ifndef __HAIKU__ 862 {"--no-beos-fixes", "-no-beos-fixes", 0}, 863#endif 864 {"--no-line-commands", "-P", 0}, 865 {"--no-precompiled-includes", "-noprecomp", 0}, 866 {"--no-standard-includes", "-nostdinc", 0}, 867 {"--no-standard-libraries", "-nostdlib", 0}, 868 {"--no-warnings", "-w", 0}, 869 {"--optimize", "-O", "oj"}, 870 {"--output", "-o", "a"}, 871 {"--output-class-directory", "-foutput-class-dir=", "ja"}, 872 {"--pedantic", "-pedantic", 0}, 873 {"--pedantic-errors", "-pedantic-errors", 0}, 874 {"--pipe", "-pipe", 0}, 875 {"--prefix", "-B", "a"}, 876 {"--preprocess", "-E", 0}, 877 {"--priority", "-priority", 0}, 878 {"--print-search-dirs", "-print-search-dirs", 0}, 879 {"--print-file-name", "-print-file-name=", "aj"}, 880 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0}, 881 {"--print-missing-file-dependencies", "-MG", 0}, 882 {"--print-multi-lib", "-print-multi-lib", 0}, 883 {"--print-multi-directory", "-print-multi-directory", 0}, 884 {"--print-prog-name", "-print-prog-name=", "aj"}, 885 {"--profile", "-p", 0}, 886 {"--profile-blocks", "-a", 0}, 887 {"--quiet", "-q", 0}, 888 {"--save-temps", "-save-temps", 0}, 889 {"--shared", "-shared", 0}, 890 {"--silent", "-q", 0}, 891 {"--specs", "-specs=", "aj"}, 892 {"--static", "-static", 0}, 893 {"--std", "-std=", "aj"}, 894 {"--symbolic", "-symbolic", 0}, 895 {"--target", "-b", "a"}, 896 {"--trace-includes", "-H", 0}, 897 {"--traditional", "-traditional", 0}, 898 {"--traditional-cpp", "-traditional-cpp", 0}, 899 {"--trigraphs", "-trigraphs", 0}, 900 {"--undefine-macro", "-U", "aj"}, 901 {"--use-version", "-V", "a"}, 902 {"--user-dependencies", "-MM", 0}, 903 {"--verbose", "-v", 0}, 904 {"--version", "-dumpversion", 0}, 905 {"--warn-", "-W", "*j"}, 906 {"--write-dependencies", "-MD", 0}, 907 {"--write-user-dependencies", "-MMD", 0}, 908 {"--", "-f", "*j"} 909 }; 910 911/* Translate the options described by *ARGCP and *ARGVP. 912 Make a new vector and store it back in *ARGVP, 913 and store its length in *ARGVC. */ 914 915static void 916translate_options (argcp, argvp) 917 int *argcp; 918 const char ***argvp; 919{ 920 int i; 921 int argc = *argcp; 922 const char **argv = *argvp; 923 const char **newv = 924 (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *)); 925 int newindex = 0; 926 927 i = 0; 928 newv[newindex++] = argv[i++]; 929 930 while (i < argc) 931 { 932 /* Translate -- options. */ 933 if (argv[i][0] == '-' && argv[i][1] == '-') 934 { 935 size_t j; 936 /* Find a mapping that applies to this option. */ 937 for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++) 938 { 939 size_t optlen = strlen (option_map[j].name); 940 size_t arglen = strlen (argv[i]); 941 size_t complen = arglen > optlen ? optlen : arglen; 942 const char *arginfo = option_map[j].arg_info; 943 944 if (arginfo == 0) 945 arginfo = ""; 946 947 if (!strncmp (argv[i], option_map[j].name, complen)) 948 { 949 const char *arg = 0; 950 951 if (arglen < optlen) 952 { 953 size_t k; 954 for (k = j + 1; 955 k < sizeof (option_map) / sizeof (option_map[0]); 956 k++) 957 if (strlen (option_map[k].name) >= arglen 958 && !strncmp (argv[i], option_map[k].name, arglen)) 959 { 960 error ("Ambiguous abbreviation %s", argv[i]); 961 break; 962 } 963 964 if (k != sizeof (option_map) / sizeof (option_map[0])) 965 break; 966 } 967 968 if (arglen > optlen) 969 { 970 /* If the option has an argument, accept that. */ 971 if (argv[i][optlen] == '=') 972 arg = argv[i] + optlen + 1; 973 974 /* If this mapping requires extra text at end of name, 975 accept that as "argument". */ 976 else if (index (arginfo, '*') != 0) 977 arg = argv[i] + optlen; 978 979 /* Otherwise, extra text at end means mismatch. 980 Try other mappings. */ 981 else 982 continue; 983 } 984 985 else if (index (arginfo, '*') != 0) 986 { 987 error ("Incomplete `%s' option", option_map[j].name); 988 break; 989 } 990 991 /* Handle arguments. */ 992 if (index (arginfo, 'a') != 0) 993 { 994 if (arg == 0) 995 { 996 if (i + 1 == argc) 997 { 998 error ("Missing argument to `%s' option", 999 option_map[j].name); 1000 break; 1001 } 1002 1003 arg = argv[++i]; 1004 } 1005 } 1006 else if (index (arginfo, '*') != 0) 1007 ; 1008 else if (index (arginfo, 'o') == 0) 1009 { 1010 if (arg != 0) 1011 error ("Extraneous argument to `%s' option", 1012 option_map[j].name); 1013 arg = 0; 1014 } 1015 1016 /* Store the translation as one argv elt or as two. */ 1017 if (arg != 0 && index (arginfo, 'j') != 0) 1018 newv[newindex++] = concat (option_map[j].equivalent, arg, 1019 NULL_PTR); 1020 else if (arg != 0) 1021 { 1022 newv[newindex++] = option_map[j].equivalent; 1023 newv[newindex++] = arg; 1024 } 1025 else 1026 newv[newindex++] = option_map[j].equivalent; 1027 1028 break; 1029 } 1030 } 1031 i++; 1032 } 1033 1034 /* Handle old-fashioned options--just copy them through, 1035 with their arguments. */ 1036 else if (argv[i][0] == '-') 1037 { 1038 const char *p = argv[i] + 1; 1039 int c = *p; 1040 int nskip = 1; 1041 1042 if (SWITCH_TAKES_ARG (c) > (p[1] != 0)) 1043 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0); 1044 else if (WORD_SWITCH_TAKES_ARG (p)) 1045 nskip += WORD_SWITCH_TAKES_ARG (p); 1046 else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x') 1047 && p[1] == 0) 1048 nskip += 1; 1049 else if (! strcmp (p, "Xlinker")) 1050 nskip += 1; 1051 1052 /* Watch out for an option at the end of the command line that 1053 is missing arguments, and avoid skipping past the end of the 1054 command line. */ 1055 if (nskip + i > argc) 1056 nskip = argc - i; 1057 1058 while (nskip > 0) 1059 { 1060 newv[newindex++] = argv[i++]; 1061 nskip--; 1062 } 1063 } 1064 else 1065 /* Ordinary operands, or +e options. */ 1066 newv[newindex++] = argv[i++]; 1067 } 1068 1069 newv[newindex] = 0; 1070 1071 *argvp = newv; 1072 *argcp = newindex; 1073} 1074 1075char * 1076xstrerror(e) 1077 int e; 1078{ 1079#ifdef HAVE_STRERROR 1080 1081 return strerror(e); 1082 1083#else 1084 1085 if (!e) 1086 return "errno = 0"; 1087 1088 if (e > 0 && e < sys_nerr) 1089 return sys_errlist[e]; 1090 1091 return "errno = ?"; 1092#endif 1093} 1094 1095static char * 1096skip_whitespace (p) 1097 char *p; 1098{ 1099 while (1) 1100 { 1101 /* A fully-blank line is a delimiter in the SPEC file and shouldn't 1102 be considered whitespace. */ 1103 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') 1104 return p + 1; 1105 else if (*p == '\n' || *p == ' ' || *p == '\t') 1106 p++; 1107 else if (*p == '#') 1108 { 1109 while (*p != '\n') p++; 1110 p++; 1111 } 1112 else 1113 break; 1114 } 1115 1116 return p; 1117} 1118 1119/* Structure to keep track of the specs that have been defined so far. 1120 These are accessed using %(specname) or %[specname] in a compiler 1121 or link spec. */ 1122 1123struct spec_list 1124{ 1125 /* The following 2 fields must be first */ 1126 /* to allow EXTRA_SPECS to be initialized */ 1127 char *name; /* name of the spec. */ 1128 char *ptr; /* available ptr if no static pointer */ 1129 1130 /* The following fields are not initialized */ 1131 /* by EXTRA_SPECS */ 1132 char **ptr_spec; /* pointer to the spec itself. */ 1133 struct spec_list *next; /* Next spec in linked list. */ 1134 int name_len; /* length of the name */ 1135 int alloc_p; /* whether string was allocated */ 1136}; 1137 1138#define INIT_STATIC_SPEC(NAME,PTR) \ 1139{ NAME, NULL_PTR, PTR, (struct spec_list *)0, sizeof (NAME)-1, 0 } 1140 1141/* List of statically defined specs */ 1142static struct spec_list static_specs[] = { 1143 INIT_STATIC_SPEC ("asm", &asm_spec), 1144 INIT_STATIC_SPEC ("asm_final", &asm_final_spec), 1145 INIT_STATIC_SPEC ("cpp", &cpp_spec), 1146 INIT_STATIC_SPEC ("cc1", &cc1_spec), 1147 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec), 1148 INIT_STATIC_SPEC ("endfile", &endfile_spec), 1149 INIT_STATIC_SPEC ("link", &link_spec), 1150 INIT_STATIC_SPEC ("lib", &lib_spec), 1151 INIT_STATIC_SPEC ("libgcc", &libgcc_spec), 1152 INIT_STATIC_SPEC ("startfile", &startfile_spec), 1153 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces), 1154 INIT_STATIC_SPEC ("signed_char", &signed_char_spec), 1155 INIT_STATIC_SPEC ("predefines", &cpp_predefines), 1156 INIT_STATIC_SPEC ("cross_compile", &cross_compile), 1157 INIT_STATIC_SPEC ("version", &compiler_version), 1158 INIT_STATIC_SPEC ("multilib", &multilib_select), 1159 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults), 1160 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra), 1161 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches), 1162 INIT_STATIC_SPEC ("linker", &linker_name_spec), 1163}; 1164 1165#ifdef EXTRA_SPECS /* additional specs needed */ 1166/* Structure to keep track of just the first two args of a spec_list. 1167 That is all that the EXTRA_SPECS macro gives us. */ 1168struct spec_list_1 1169{ 1170 char *name; 1171 char *ptr; 1172}; 1173 1174static struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS }; 1175static struct spec_list * extra_specs = (struct spec_list *)0; 1176#endif 1177 1178/* List of dynamically allocates specs that have been defined so far. */ 1179 1180static struct spec_list *specs = (struct spec_list *)0; 1181 1182 1183/* Initialize the specs lookup routines. */ 1184 1185static void 1186init_spec () 1187{ 1188 struct spec_list *next = (struct spec_list *)0; 1189 struct spec_list *sl = (struct spec_list *)0; 1190 int i; 1191 1192 if (specs) 1193 return; /* already initialized */ 1194 1195 if (verbose_flag) 1196 notice ("Using builtin specs.\n"); 1197 1198#ifdef EXTRA_SPECS 1199 extra_specs = (struct spec_list *) 1200 xmalloc (sizeof(struct spec_list) * 1201 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0]))); 1202 bzero ((PTR) extra_specs, sizeof(struct spec_list) * 1203 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0]))); 1204 1205 for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--) 1206 { 1207 sl = &extra_specs[i]; 1208 sl->name = extra_specs_1[i].name; 1209 sl->ptr = extra_specs_1[i].ptr; 1210 sl->next = next; 1211 sl->name_len = strlen (sl->name); 1212 sl->ptr_spec = &sl->ptr; 1213 next = sl; 1214 } 1215#endif 1216 1217 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; i >= 0; i--) 1218 { 1219 sl = &static_specs[i]; 1220 sl->next = next; 1221 next = sl; 1222 } 1223 1224 specs = sl; 1225} 1226 1227 1228/* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is 1229 removed; If the spec starts with a + then SPEC is added to the end of the 1230 current spec. */ 1231 1232static void 1233set_spec (name, spec) 1234 const char *name; 1235 const char *spec; 1236{ 1237 struct spec_list *sl; 1238 char *old_spec; 1239 int name_len = strlen (name); 1240 int i; 1241 1242 /* If this is the first call, initialize the statically allocated specs */ 1243 if (!specs) 1244 { 1245 struct spec_list *next = (struct spec_list *)0; 1246 for (i = (sizeof (static_specs) / sizeof (static_specs[0])) - 1; 1247 i >= 0; i--) 1248 { 1249 sl = &static_specs[i]; 1250 sl->next = next; 1251 next = sl; 1252 } 1253 specs = sl; 1254 } 1255 1256 /* See if the spec already exists */ 1257 for (sl = specs; sl; sl = sl->next) 1258 if (name_len == sl->name_len && !strcmp (sl->name, name)) 1259 break; 1260 1261 if (!sl) 1262 { 1263 /* Not found - make it */ 1264 sl = (struct spec_list *) xmalloc (sizeof (struct spec_list)); 1265 sl->name = save_string (name, strlen (name)); 1266 sl->name_len = name_len; 1267 sl->ptr_spec = &sl->ptr; 1268 sl->alloc_p = 0; 1269 *(sl->ptr_spec) = ""; 1270 sl->next = specs; 1271 specs = sl; 1272 } 1273 1274 old_spec = *(sl->ptr_spec); 1275 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1])) 1276 ? concat (old_spec, spec + 1, NULL_PTR) 1277 : save_string (spec, strlen (spec))); 1278 1279#ifdef DEBUG_SPECS 1280 if (verbose_flag) 1281 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec)); 1282#endif 1283 1284 /* Free the old spec */ 1285 if (old_spec && sl->alloc_p) 1286 free (old_spec); 1287 1288 sl->alloc_p = 1; 1289} 1290 1291/* Accumulate a command (program name and args), and run it. */ 1292 1293/* Vector of pointers to arguments in the current line of specifications. */ 1294 1295static char **argbuf; 1296 1297/* Number of elements allocated in argbuf. */ 1298 1299static int argbuf_length; 1300 1301/* Number of elements in argbuf currently in use (containing args). */ 1302 1303static int argbuf_index; 1304 1305/* We want this on by default all the time now. */ 1306#define MKTEMP_EACH_FILE 1307 1308#ifdef MKTEMP_EACH_FILE 1309 1310extern char *make_temp_file PROTO((const char *)); 1311 1312/* This is the list of suffixes and codes (%g/%u/%U) and the associated 1313 temp file. */ 1314 1315static struct temp_name { 1316 const char *suffix; /* suffix associated with the code. */ 1317 int length; /* strlen (suffix). */ 1318 int unique; /* Indicates whether %g or %u/%U was used. */ 1319 const char *filename; /* associated filename. */ 1320 int filename_length; /* strlen (filename). */ 1321 struct temp_name *next; 1322} *temp_names; 1323#endif 1324 1325 1326/* Number of commands executed so far. */ 1327 1328static int execution_count; 1329 1330/* Number of commands that exited with a signal. */ 1331 1332static int signal_count; 1333 1334/* Name with which this program was invoked. */ 1335 1336static const char *programname; 1337 1338/* Structures to keep track of prefixes to try when looking for files. */ 1339 1340struct prefix_list 1341{ 1342 char *prefix; /* String to prepend to the path. */ 1343 struct prefix_list *next; /* Next in linked list. */ 1344 int require_machine_suffix; /* Don't use without machine_suffix. */ 1345 /* 2 means try both machine_suffix and just_machine_suffix. */ 1346 int *used_flag_ptr; /* 1 if a file was found with this prefix. */ 1347}; 1348 1349struct path_prefix 1350{ 1351 struct prefix_list *plist; /* List of prefixes to try */ 1352 int max_len; /* Max length of a prefix in PLIST */ 1353 const char *name; /* Name of this list (used in config stuff) */ 1354}; 1355 1356/* List of prefixes to try when looking for executables. */ 1357 1358static struct path_prefix exec_prefixes = { 0, 0, "exec" }; 1359 1360/* List of prefixes to try when looking for startup (crt0) files. */ 1361 1362static struct path_prefix startfile_prefixes = { 0, 0, "startfile" }; 1363 1364/* List of prefixes to try when looking for include files. */ 1365 1366static struct path_prefix include_prefixes = { 0, 0, "include" }; 1367 1368/* Suffix to attach to directories searched for commands. 1369 This looks like `MACHINE/VERSION/'. */ 1370 1371static const char *machine_suffix = 0; 1372 1373/* Suffix to attach to directories searched for commands. 1374 This is just `MACHINE/'. */ 1375 1376static const char *just_machine_suffix = 0; 1377 1378/* Adjusted value of GCC_EXEC_PREFIX envvar. */ 1379 1380static const char *gcc_exec_prefix; 1381 1382/* Default prefixes to attach to command names. */ 1383 1384#ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */ 1385#undef MD_EXEC_PREFIX 1386#undef MD_STARTFILE_PREFIX 1387#undef MD_STARTFILE_PREFIX_1 1388#endif 1389 1390#ifndef STANDARD_EXEC_PREFIX 1391#define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/" 1392#endif /* !defined STANDARD_EXEC_PREFIX */ 1393 1394static const char *standard_exec_prefix = STANDARD_EXEC_PREFIX; 1395#if !defined(__BEOS__) && !defined(__HAIKU__) 1396static const char *standard_exec_prefix_1 = "/usr/lib/gcc/"; 1397#endif 1398#ifdef MD_EXEC_PREFIX 1399static const char *md_exec_prefix = MD_EXEC_PREFIX; 1400#endif 1401 1402#ifndef STANDARD_STARTFILE_PREFIX 1403#define STANDARD_STARTFILE_PREFIX "/usr/local/lib/" 1404#endif /* !defined STANDARD_STARTFILE_PREFIX */ 1405 1406#ifdef MD_STARTFILE_PREFIX 1407static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; 1408#endif 1409#ifdef MD_STARTFILE_PREFIX_1 1410static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; 1411#endif 1412 1413static const char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; 1414 1415#if defined(__HAIKU__) 1416#ifdef HYBRID_SECONDARY 1417static const char *standard_startfile_prefix_1 = 1418 "/boot/common/develop/lib/" HYBRID_SECONDARY "/"; 1419static const char *standard_startfile_prefix_2 = 1420 "/boot/system/develop/lib/" HYBRID_SECONDARY "/"; 1421#else 1422static const char *standard_startfile_prefix_1 = "/boot/common/develop/lib/"; 1423static const char *standard_startfile_prefix_2 = "/boot/system/develop/lib/"; 1424#endif 1425#else 1426static const char *standard_startfile_prefix_1 = "/lib/"; 1427static const char *standard_startfile_prefix_2 = "/usr/lib/"; 1428#endif 1429 1430#ifndef TOOLDIR_BASE_PREFIX 1431#define TOOLDIR_BASE_PREFIX "/usr/local/" 1432#endif 1433static const char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX; 1434static const char *tooldir_prefix; 1435 1436/* Subdirectory to use for locating libraries. Set by 1437 set_multilib_dir based on the compilation options. */ 1438 1439static const char *multilib_dir; 1440 1441/* Clear out the vector of arguments (after a command is executed). */ 1442 1443static void 1444clear_args () 1445{ 1446 argbuf_index = 0; 1447} 1448 1449/* Add one argument to the vector at the end. 1450 This is done when a space is seen or at the end of the line. 1451 If DELETE_ALWAYS is nonzero, the arg is a filename 1452 and the file should be deleted eventually. 1453 If DELETE_FAILURE is nonzero, the arg is a filename 1454 and the file should be deleted if this compilation fails. */ 1455 1456static void 1457store_arg (arg, delete_always, delete_failure) 1458 char *arg; 1459 int delete_always, delete_failure; 1460{ 1461 if (argbuf_index + 1 == argbuf_length) 1462 argbuf 1463 = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *)); 1464 1465 argbuf[argbuf_index++] = arg; 1466 argbuf[argbuf_index] = 0; 1467 1468 if (delete_always || delete_failure) 1469 record_temp_file (arg, delete_always, delete_failure); 1470} 1471 1472/* Read compilation specs from a file named FILENAME, 1473 replacing the default ones. 1474 1475 A suffix which starts with `*' is a definition for 1476 one of the machine-specific sub-specs. The "suffix" should be 1477 *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc. 1478 The corresponding spec is stored in asm_spec, etc., 1479 rather than in the `compilers' vector. 1480 1481 Anything invalid in the file is a fatal error. */ 1482 1483static void 1484read_specs (filename, main_p) 1485 const char *filename; 1486 int main_p; 1487{ 1488 int desc; 1489 int readlen; 1490 struct stat statbuf; 1491 char *buffer; 1492 register char *p; 1493 1494 if (verbose_flag) 1495 notice ("Reading specs from %s\n", filename); 1496 1497 /* Open and stat the file. */ 1498 desc = open (filename, O_RDONLY, 0); 1499 if (desc < 0) 1500 pfatal_with_name (filename); 1501 if (stat (filename, &statbuf) < 0) 1502 pfatal_with_name (filename); 1503 1504 /* Read contents of file into BUFFER. */ 1505 buffer = xmalloc ((unsigned) statbuf.st_size + 1); 1506 readlen = read (desc, buffer, (unsigned) statbuf.st_size); 1507 if (readlen < 0) 1508 pfatal_with_name (filename); 1509 buffer[readlen] = 0; 1510 close (desc); 1511 1512 /* Scan BUFFER for specs, putting them in the vector. */ 1513 p = buffer; 1514 while (1) 1515 { 1516 char *suffix; 1517 char *spec; 1518 char *in, *out, *p1, *p2, *p3; 1519 1520 /* Advance P in BUFFER to the next nonblank nocomment line. */ 1521 p = skip_whitespace (p); 1522 if (*p == 0) 1523 break; 1524 1525 /* Is this a special command that starts with '%'? */ 1526 /* Don't allow this for the main specs file, since it would 1527 encourage people to overwrite it. */ 1528 if (*p == '%' && !main_p) 1529 { 1530 p1 = p; 1531 while (*p && *p != '\n') 1532 p++; 1533 1534 p++; /* Skip '\n' */ 1535 1536 if (!strncmp (p1, "%include", sizeof ("%include")-1) 1537 && (p1[sizeof "%include" - 1] == ' ' 1538 || p1[sizeof "%include" - 1] == '\t')) 1539 { 1540 char *new_filename; 1541 1542 p1 += sizeof ("%include"); 1543 while (*p1 == ' ' || *p1 == '\t') 1544 p1++; 1545 1546 if (*p1++ != '<' || p[-2] != '>') 1547 fatal ("specs %%include syntax malformed after %ld characters", 1548 (long) (p1 - buffer + 1)); 1549 1550 p[-2] = '\0'; 1551 new_filename = find_a_file (&startfile_prefixes, p1, R_OK); 1552 read_specs (new_filename ? new_filename : p1, FALSE); 1553 continue; 1554 } 1555 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1) 1556 && (p1[sizeof "%include_noerr" - 1] == ' ' 1557 || p1[sizeof "%include_noerr" - 1] == '\t')) 1558 { 1559 char *new_filename; 1560 1561 p1 += sizeof "%include_noerr"; 1562 while (*p1 == ' ' || *p1 == '\t') p1++; 1563 1564 if (*p1++ != '<' || p[-2] != '>') 1565 fatal ("specs %%include syntax malformed after %ld characters", 1566 (long) (p1 - buffer + 1)); 1567 1568 p[-2] = '\0'; 1569 new_filename = find_a_file (&startfile_prefixes, p1, R_OK); 1570 if (new_filename) 1571 read_specs (new_filename, FALSE); 1572 else if (verbose_flag) 1573 notice ("Could not find specs file %s\n", p1); 1574 continue; 1575 } 1576 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1) 1577 && (p1[sizeof "%rename" - 1] == ' ' 1578 || p1[sizeof "%rename" - 1] == '\t')) 1579 { 1580 int name_len; 1581 struct spec_list *sl; 1582 1583 /* Get original name */ 1584 p1 += sizeof "%rename"; 1585 while (*p1 == ' ' || *p1 == '\t') 1586 p1++; 1587 1588 if (! ISALPHA ((unsigned char)*p1)) 1589 fatal ("specs %%rename syntax malformed after %ld characters", 1590 (long) (p1 - buffer)); 1591 1592 p2 = p1; 1593 while (*p2 && !ISSPACE ((unsigned char)*p2)) 1594 p2++; 1595 1596 if (*p2 != ' ' && *p2 != '\t') 1597 fatal ("specs %%rename syntax malformed after %ld characters", 1598 (long) (p2 - buffer)); 1599 1600 name_len = p2 - p1; 1601 *p2++ = '\0'; 1602 while (*p2 == ' ' || *p2 == '\t') 1603 p2++; 1604 1605 if (! ISALPHA ((unsigned char)*p2)) 1606 fatal ("specs %%rename syntax malformed after %ld characters", 1607 (long) (p2 - buffer)); 1608 1609 /* Get new spec name */ 1610 p3 = p2; 1611 while (*p3 && !ISSPACE ((unsigned char)*p3)) 1612 p3++; 1613 1614 if (p3 != p-1) 1615 fatal ("specs %%rename syntax malformed after %ld characters", 1616 (long) (p3 - buffer)); 1617 *p3 = '\0'; 1618 1619 for (sl = specs; sl; sl = sl->next) 1620 if (name_len == sl->name_len && !strcmp (sl->name, p1)) 1621 break; 1622 1623 if (!sl) 1624 fatal ("specs %s spec was not found to be renamed", p1); 1625 1626 if (strcmp (p1, p2) == 0) 1627 continue; 1628 1629 if (verbose_flag) 1630 { 1631 notice ("rename spec %s to %s\n", p1, p2); 1632#ifdef DEBUG_SPECS 1633 notice ("spec is '%s'\n\n", *(sl->ptr_spec)); 1634#endif 1635 } 1636 1637 set_spec (p2, *(sl->ptr_spec)); 1638 if (sl->alloc_p) 1639 free (*(sl->ptr_spec)); 1640 1641 *(sl->ptr_spec) = ""; 1642 sl->alloc_p = 0; 1643 continue; 1644 } 1645 else 1646 fatal ("specs unknown %% command after %ld characters", 1647 (long) (p1 - buffer)); 1648 } 1649 1650 /* Find the colon that should end the suffix. */ 1651 p1 = p; 1652 while (*p1 && *p1 != ':' && *p1 != '\n') 1653 p1++; 1654 1655 /* The colon shouldn't be missing. */ 1656 if (*p1 != ':') 1657 fatal ("specs file malformed after %ld characters", 1658 (long) (p1 - buffer)); 1659 1660 /* Skip back over trailing whitespace. */ 1661 p2 = p1; 1662 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) 1663 p2--; 1664 1665 /* Copy the suffix to a string. */ 1666 suffix = save_string (p, p2 - p); 1667 /* Find the next line. */ 1668 p = skip_whitespace (p1 + 1); 1669 if (p[1] == 0) 1670 fatal ("specs file malformed after %ld characters", 1671 (long) (p - buffer)); 1672 1673 p1 = p; 1674 /* Find next blank line or end of string. */ 1675 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0'))) 1676 p1++; 1677 1678 /* Specs end at the blank line and do not include the newline. */ 1679 spec = save_string (p, p1 - p); 1680 p = p1; 1681 1682 /* Delete backslash-newline sequences from the spec. */ 1683 in = spec; 1684 out = spec; 1685 while (*in != 0) 1686 { 1687 if (in[0] == '\\' && in[1] == '\n') 1688 in += 2; 1689 else if (in[0] == '#') 1690 while (*in && *in != '\n') 1691 in++; 1692 1693 else 1694 *out++ = *in++; 1695 } 1696 *out = 0; 1697 1698 if (suffix[0] == '*') 1699 { 1700 if (! strcmp (suffix, "*link_command")) 1701 link_command_spec = spec; 1702 else 1703 set_spec (suffix + 1, spec); 1704 } 1705 else 1706 { 1707 /* Add this pair to the vector. */ 1708 compilers 1709 = ((struct compiler *) 1710 xrealloc (compilers, 1711 (n_compilers + 2) * sizeof (struct compiler))); 1712 1713 compilers[n_compilers].suffix = suffix; 1714 bzero ((char *) compilers[n_compilers].spec, 1715 sizeof compilers[n_compilers].spec); 1716 compilers[n_compilers].spec[0] = spec; 1717 n_compilers++; 1718 bzero ((char *) &compilers[n_compilers], 1719 sizeof compilers[n_compilers]); 1720 } 1721 1722 if (*suffix == 0) 1723 link_command_spec = spec; 1724 } 1725 1726 if (link_command_spec == 0) 1727 fatal ("spec file has no spec for linking"); 1728} 1729 1730/* Record the names of temporary files we tell compilers to write, 1731 and delete them at the end of the run. */ 1732 1733/* This is the common prefix we use to make temp file names. 1734 It is chosen once for each run of this program. 1735 It is substituted into a spec by %g. 1736 Thus, all temp file names contain this prefix. 1737 In practice, all temp file names start with this prefix. 1738 1739 This prefix comes from the envvar TMPDIR if it is defined; 1740 otherwise, from the P_tmpdir macro if that is defined; 1741 otherwise, in /usr/tmp or /tmp; 1742 or finally the current directory if all else fails. */ 1743 1744static const char *temp_filename; 1745 1746/* Length of the prefix. */ 1747 1748static int temp_filename_length; 1749 1750/* Define the list of temporary files to delete. */ 1751 1752struct temp_file 1753{ 1754 const char *name; 1755 struct temp_file *next; 1756}; 1757 1758/* Queue of files to delete on success or failure of compilation. */ 1759static struct temp_file *always_delete_queue; 1760/* Queue of files to delete on failure of compilation. */ 1761static struct temp_file *failure_delete_queue; 1762 1763/* Record FILENAME as a file to be deleted automatically. 1764 ALWAYS_DELETE nonzero means delete it if all compilation succeeds; 1765 otherwise delete it in any case. 1766 FAIL_DELETE nonzero means delete it if a compilation step fails; 1767 otherwise delete it in any case. */ 1768 1769static void 1770record_temp_file (filename, always_delete, fail_delete) 1771 const char *filename; 1772 int always_delete; 1773 int fail_delete; 1774{ 1775 register char *name; 1776 name = xmalloc (strlen (filename) + 1); 1777 strcpy (name, filename); 1778 1779 if (always_delete) 1780 { 1781 register struct temp_file *temp; 1782 for (temp = always_delete_queue; temp; temp = temp->next) 1783 if (! strcmp (name, temp->name)) 1784 goto already1; 1785 1786 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file)); 1787 temp->next = always_delete_queue; 1788 temp->name = name; 1789 always_delete_queue = temp; 1790 1791 already1:; 1792 } 1793 1794 if (fail_delete) 1795 { 1796 register struct temp_file *temp; 1797 for (temp = failure_delete_queue; temp; temp = temp->next) 1798 if (! strcmp (name, temp->name)) 1799 goto already2; 1800 1801 temp = (struct temp_file *) xmalloc (sizeof (struct temp_file)); 1802 temp->next = failure_delete_queue; 1803 temp->name = name; 1804 failure_delete_queue = temp; 1805 1806 already2:; 1807 } 1808} 1809 1810/* Delete all the temporary files whose names we previously recorded. */ 1811 1812static void 1813delete_if_ordinary (name) 1814 const char *name; 1815{ 1816 struct stat st; 1817#ifdef DEBUG 1818 int i, c; 1819 1820 printf ("Delete %s? (y or n) ", name); 1821 fflush (stdout); 1822 i = getchar (); 1823 if (i != '\n') 1824 while ((c = getchar ()) != '\n' && c != EOF) 1825 ; 1826 1827 if (i == 'y' || i == 'Y') 1828#endif /* DEBUG */ 1829 if (stat (name, &st) >= 0 && S_ISREG (st.st_mode)) 1830 if (unlink (name) < 0) 1831 if (verbose_flag) 1832 perror_with_name (name); 1833} 1834 1835static void 1836delete_temp_files () 1837{ 1838 register struct temp_file *temp; 1839 1840 for (temp = always_delete_queue; temp; temp = temp->next) 1841 delete_if_ordinary (temp->name); 1842 always_delete_queue = 0; 1843} 1844 1845/* Delete all the files to be deleted on error. */ 1846 1847static void 1848delete_failure_queue () 1849{ 1850 register struct temp_file *temp; 1851 1852 for (temp = failure_delete_queue; temp; temp = temp->next) 1853 delete_if_ordinary (temp->name); 1854} 1855 1856static void 1857clear_failure_queue () 1858{ 1859 failure_delete_queue = 0; 1860} 1861 1862/* Routine to add variables to the environment. We do this to pass 1863 the pathname of the gcc driver, and the directories search to the 1864 collect2 program, which is being run as ld. This way, we can be 1865 sure of executing the right compiler when collect2 wants to build 1866 constructors and destructors. Since the environment variables we 1867 use come from an obstack, we don't have to worry about allocating 1868 space for them. */ 1869 1870#ifndef HAVE_PUTENV 1871 1872void 1873putenv (str) 1874 char *str; 1875{ 1876#ifndef VMS /* nor about VMS */ 1877 1878 extern char **environ; 1879 char **old_environ = environ; 1880 char **envp; 1881 int num_envs = 0; 1882 int name_len = 1; 1883 int str_len = strlen (str); 1884 char *p = str; 1885 int ch; 1886 1887 while ((ch = *p++) != '\0' && ch != '=') 1888 name_len++; 1889 1890 if (!ch) 1891 abort (); 1892 1893 /* Search for replacing an existing environment variable, and 1894 count the number of total environment variables. */ 1895 for (envp = old_environ; *envp; envp++) 1896 { 1897 num_envs++; 1898 if (!strncmp (str, *envp, name_len)) 1899 { 1900 *envp = str; 1901 return; 1902 } 1903 } 1904 1905 /* Add a new environment variable */ 1906 environ = (char **) xmalloc (sizeof (char *) * (num_envs+2)); 1907 *environ = str; 1908 memcpy ((char *) (environ + 1), (char *) old_environ, 1909 sizeof (char *) * (num_envs+1)); 1910 1911#endif /* VMS */ 1912} 1913 1914#endif /* HAVE_PUTENV */ 1915 1916 1917/* Build a list of search directories from PATHS. 1918 PREFIX is a string to prepend to the list. 1919 If CHECK_DIR_P is non-zero we ensure the directory exists. 1920 This is used mostly by putenv_from_prefixes so we use `collect_obstack'. 1921 It is also used by the --print-search-dirs flag. */ 1922 1923static char * 1924build_search_list (paths, prefix, check_dir_p) 1925 struct path_prefix *paths; 1926 const char *prefix; 1927 int check_dir_p; 1928{ 1929 int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0; 1930 int just_suffix_len 1931 = (just_machine_suffix) ? strlen (just_machine_suffix) : 0; 1932 int first_time = TRUE; 1933 struct prefix_list *pprefix; 1934 1935 obstack_grow (&collect_obstack, prefix, strlen (prefix)); 1936 1937 for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next) 1938 { 1939 int len = strlen (pprefix->prefix); 1940 1941 if (machine_suffix 1942 && (! check_dir_p 1943 || is_directory (pprefix->prefix, machine_suffix, 0))) 1944 { 1945 if (!first_time) 1946 obstack_1grow (&collect_obstack, PATH_SEPARATOR); 1947 1948 first_time = FALSE; 1949 obstack_grow (&collect_obstack, pprefix->prefix, len); 1950 obstack_grow (&collect_obstack, machine_suffix, suffix_len); 1951 } 1952 1953 if (just_machine_suffix 1954 && pprefix->require_machine_suffix == 2 1955 && (! check_dir_p 1956 || is_directory (pprefix->prefix, just_machine_suffix, 0))) 1957 { 1958 if (! first_time) 1959 obstack_1grow (&collect_obstack, PATH_SEPARATOR); 1960 1961 first_time = FALSE; 1962 obstack_grow (&collect_obstack, pprefix->prefix, len); 1963 obstack_grow (&collect_obstack, just_machine_suffix, 1964 just_suffix_len); 1965 } 1966 1967 if (! pprefix->require_machine_suffix) 1968 { 1969 if (! first_time) 1970 obstack_1grow (&collect_obstack, PATH_SEPARATOR); 1971 1972 first_time = FALSE; 1973 obstack_grow (&collect_obstack, pprefix->prefix, len); 1974 } 1975 } 1976 1977 obstack_1grow (&collect_obstack, '\0'); 1978 return obstack_finish (&collect_obstack); 1979} 1980 1981/* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables 1982 for collect. */ 1983 1984static void 1985putenv_from_prefixes (paths, env_var) 1986 struct path_prefix *paths; 1987 const char *env_var; 1988{ 1989 putenv (build_search_list (paths, env_var, 1)); 1990} 1991 1992/* Search for NAME using the prefix list PREFIXES. MODE is passed to 1993 access to check permissions. 1994 Return 0 if not found, otherwise return its name, allocated with malloc. */ 1995 1996static char * 1997find_a_file (pprefix, name, mode) 1998 struct path_prefix *pprefix; 1999 const char *name; 2000 int mode; 2001{ 2002 char *temp; 2003 const char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : ""); 2004 struct prefix_list *pl; 2005 int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1; 2006 2007#ifdef DEFAULT_ASSEMBLER 2008 if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) { 2009 name = DEFAULT_ASSEMBLER; 2010 len = strlen(name)+1; 2011 temp = xmalloc (len); 2012 strcpy (temp, name); 2013 return temp; 2014 } 2015#endif 2016 2017#ifdef DEFAULT_LINKER 2018 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) { 2019 name = DEFAULT_LINKER; 2020 len = strlen(name)+1; 2021 temp = xmalloc (len); 2022 strcpy (temp, name); 2023 return temp; 2024 } 2025#endif 2026 2027 if (machine_suffix) 2028 len += strlen (machine_suffix); 2029 2030 temp = xmalloc (len); 2031 2032 /* Determine the filename to execute (special case for absolute paths). */ 2033 2034 if (IS_DIR_SEPARATOR (*name) 2035#ifdef HAVE_DOS_BASED_FILESYSTEM 2036 /* Check for disk name on MS-DOS-based systems. */ 2037 || (name[0] && name[1] == ':' && IS_DIR_SEPARATOR (name[2])) 2038#endif 2039 ) 2040 { 2041 if (access (name, mode) == 0) 2042 { 2043 strcpy (temp, name); 2044 return temp; 2045 } 2046 } 2047 else 2048 for (pl = pprefix->plist; pl; pl = pl->next) 2049 { 2050 if (machine_suffix) 2051 { 2052 /* Some systems have a suffix for executable files. 2053 So try appending that first. */ 2054 if (file_suffix[0] != 0) 2055 { 2056 strcpy (temp, pl->prefix); 2057 strcat (temp, machine_suffix); 2058 strcat (temp, name); 2059 strcat (temp, file_suffix); 2060 if (access (temp, mode) == 0) 2061 { 2062 if (pl->used_flag_ptr != 0) 2063 *pl->used_flag_ptr = 1; 2064 return temp; 2065 } 2066 } 2067 2068 /* Now try just the name. */ 2069 strcpy (temp, pl->prefix); 2070 strcat (temp, machine_suffix); 2071 strcat (temp, name); 2072 if (access (temp, mode) == 0) 2073 { 2074 if (pl->used_flag_ptr != 0) 2075 *pl->used_flag_ptr = 1; 2076 return temp; 2077 } 2078 } 2079 2080 /* Certain prefixes are tried with just the machine type, 2081 not the version. This is used for finding as, ld, etc. */ 2082 if (just_machine_suffix && pl->require_machine_suffix == 2) 2083 { 2084 /* Some systems have a suffix for executable files. 2085 So try appending that first. */ 2086 if (file_suffix[0] != 0) 2087 { 2088 strcpy (temp, pl->prefix); 2089 strcat (temp, just_machine_suffix); 2090 strcat (temp, name); 2091 strcat (temp, file_suffix); 2092 if (access (temp, mode) == 0) 2093 { 2094 if (pl->used_flag_ptr != 0) 2095 *pl->used_flag_ptr = 1; 2096 return temp; 2097 } 2098 } 2099 2100 strcpy (temp, pl->prefix); 2101 strcat (temp, just_machine_suffix); 2102 strcat (temp, name); 2103 if (access (temp, mode) == 0) 2104 { 2105 if (pl->used_flag_ptr != 0) 2106 *pl->used_flag_ptr = 1; 2107 return temp; 2108 } 2109 } 2110 2111 /* Certain prefixes can't be used without the machine suffix 2112 when the machine or version is explicitly specified. */ 2113 if (! pl->require_machine_suffix) 2114 { 2115 /* Some systems have a suffix for executable files. 2116 So try appending that first. */ 2117 if (file_suffix[0] != 0) 2118 { 2119 strcpy (temp, pl->prefix); 2120 strcat (temp, name); 2121 strcat (temp, file_suffix); 2122 if (access (temp, mode) == 0) 2123 { 2124 if (pl->used_flag_ptr != 0) 2125 *pl->used_flag_ptr = 1; 2126 return temp; 2127 } 2128 } 2129 2130 strcpy (temp, pl->prefix); 2131 strcat (temp, name); 2132 if (access (temp, mode) == 0) 2133 { 2134 if (pl->used_flag_ptr != 0) 2135 *pl->used_flag_ptr = 1; 2136 return temp; 2137 } 2138 } 2139 } 2140 2141 free (temp); 2142 return 0; 2143} 2144 2145/* Add an entry for PREFIX in PLIST. If FIRST is set, it goes 2146 at the start of the list, otherwise it goes at the end. 2147 2148 If WARN is nonzero, we will warn if no file is found 2149 through this prefix. WARN should point to an int 2150 which will be set to 1 if this entry is used. 2151 2152 COMPONENT is the value to be passed to update_path. 2153 2154 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without 2155 the complete value of machine_suffix. 2156 2 means try both machine_suffix and just_machine_suffix. */ 2157 2158static void 2159add_prefix (pprefix, prefix, component, first, require_machine_suffix, warn) 2160 struct path_prefix *pprefix; 2161 const char *prefix; 2162 const char *component; 2163 int first; 2164 int require_machine_suffix; 2165 int *warn; 2166{ 2167 struct prefix_list *pl, **prev; 2168 int len; 2169 2170 if (! first && pprefix->plist) 2171 { 2172 for (pl = pprefix->plist; pl->next; pl = pl->next) 2173 ; 2174 prev = &pl->next; 2175 } 2176 else 2177 prev = &pprefix->plist; 2178 2179 /* Keep track of the longest prefix */ 2180 2181 prefix = update_path (prefix, component); 2182 len = strlen (prefix); 2183 if (len > pprefix->max_len) 2184 pprefix->max_len = len; 2185 2186 pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list)); 2187 pl->prefix = save_string (prefix, len); 2188 pl->require_machine_suffix = require_machine_suffix; 2189 pl->used_flag_ptr = warn; 2190 if (warn) 2191 *warn = 0; 2192 2193 if (*prev) 2194 pl->next = *prev; 2195 else 2196 pl->next = (struct prefix_list *) 0; 2197 *prev = pl; 2198} 2199 2200/* Print warnings for any prefixes in the list PPREFIX that were not used. */ 2201 2202static void 2203unused_prefix_warnings (pprefix) 2204 struct path_prefix *pprefix; 2205{ 2206 struct prefix_list *pl = pprefix->plist; 2207 2208 while (pl) 2209 { 2210 if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr) 2211 { 2212 if (pl->require_machine_suffix && machine_suffix) 2213 error ("file path prefix `%s%s' never used", pl->prefix, 2214 machine_suffix); 2215 else 2216 error ("file path prefix `%s' never used", pl->prefix); 2217 2218 /* Prevent duplicate warnings. */ 2219 *pl->used_flag_ptr = 1; 2220 } 2221 2222 pl = pl->next; 2223 } 2224} 2225 2226 2227/* Execute the command specified by the arguments on the current line of spec. 2228 When using pipes, this includes several piped-together commands 2229 with `|' between them. 2230 2231 Return 0 if successful, -1 if failed. */ 2232 2233static int 2234execute () 2235{ 2236 int i; 2237 int n_commands; /* # of command. */ 2238 char *string; 2239 struct command 2240 { 2241 const char *prog; /* program name. */ 2242 char **argv; /* vector of args. */ 2243 int pid; /* pid of process for this command. */ 2244 }; 2245 2246 struct command *commands; /* each command buffer with above info. */ 2247 2248 /* Count # of piped commands. */ 2249 for (n_commands = 1, i = 0; i < argbuf_index; i++) 2250 if (strcmp (argbuf[i], "|") == 0) 2251 n_commands++; 2252 2253 /* Get storage for each command. */ 2254 commands 2255 = (struct command *) alloca (n_commands * sizeof (struct command)); 2256 2257 /* Split argbuf into its separate piped processes, 2258 and record info about each one. 2259 Also search for the programs that are to be run. */ 2260 2261 commands[0].prog = argbuf[0]; /* first command. */ 2262 commands[0].argv = &argbuf[0]; 2263 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK); 2264 2265 if (string) 2266 commands[0].argv[0] = string; 2267 2268 for (n_commands = 1, i = 0; i < argbuf_index; i++) 2269 if (strcmp (argbuf[i], "|") == 0) 2270 { /* each command. */ 2271#if defined (__MSDOS__) || defined (OS2) || defined (VMS) 2272 fatal ("-pipe not supported"); 2273#endif 2274 argbuf[i] = 0; /* termination of command args. */ 2275 commands[n_commands].prog = argbuf[i + 1]; 2276 commands[n_commands].argv = &argbuf[i + 1]; 2277 string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK); 2278 if (string) 2279 commands[n_commands].argv[0] = string; 2280 n_commands++; 2281 } 2282 2283 argbuf[argbuf_index] = 0; 2284 2285 /* If -v, print what we are about to do, and maybe query. */ 2286 2287 if (verbose_flag) 2288 { 2289 /* For help listings, put a blank line between sub-processes. */ 2290 if (print_help_list) 2291 fputc ('\n', stderr); 2292 2293 /* Print each piped command as a separate line. */ 2294 for (i = 0; i < n_commands ; i++) 2295 { 2296 char **j; 2297 2298 for (j = commands[i].argv; *j; j++) 2299 fprintf (stderr, " %s", *j); 2300 2301 /* Print a pipe symbol after all but the last command. */ 2302 if (i + 1 != n_commands) 2303 fprintf (stderr, " |"); 2304 fprintf (stderr, "\n"); 2305 } 2306 fflush (stderr); 2307#ifdef DEBUG 2308 notice ("\nGo ahead? (y or n) "); 2309 fflush (stderr); 2310 i = getchar (); 2311 if (i != '\n') 2312 while (getchar () != '\n') 2313 ; 2314 2315 if (i != 'y' && i != 'Y') 2316 return 0; 2317#endif /* DEBUG */ 2318 } 2319 2320 /* Run each piped subprocess. */ 2321 2322 for (i = 0; i < n_commands; i++) 2323 { 2324 char *errmsg_fmt, *errmsg_arg; 2325 char *string = commands[i].argv[0]; 2326 2327 commands[i].pid = pexecute (string, commands[i].argv, 2328 programname, temp_filename, 2329 &errmsg_fmt, &errmsg_arg, 2330 ((i == 0 ? PEXECUTE_FIRST : 0) 2331 | (i + 1 == n_commands ? PEXECUTE_LAST : 0) 2332 | (string == commands[i].prog 2333 ? PEXECUTE_SEARCH : 0) 2334 | (verbose_flag ? PEXECUTE_VERBOSE : 0))); 2335 2336 if (commands[i].pid == -1) 2337 pfatal_pexecute (errmsg_fmt, errmsg_arg); 2338 2339 if (string != commands[i].prog) 2340 free (string); 2341 } 2342 2343 execution_count++; 2344 2345 /* Wait for all the subprocesses to finish. 2346 We don't care what order they finish in; 2347 we know that N_COMMANDS waits will get them all. 2348 Ignore subprocesses that we don't know about, 2349 since they can be spawned by the process that exec'ed us. */ 2350 2351 { 2352 int ret_code = 0; 2353 2354 for (i = 0; i < n_commands; ) 2355 { 2356 int j; 2357 int status; 2358 int pid; 2359 2360 pid = pwait (commands[i].pid, &status, 0); 2361 if (pid < 0) 2362 abort (); 2363 2364 for (j = 0; j < n_commands; j++) 2365 if (commands[j].pid == pid) 2366 { 2367 i++; 2368 if (status != 0) 2369 { 2370 if (WIFSIGNALED (status)) 2371 { 2372 fatal ("Internal compiler error: program %s got fatal signal %d", 2373 commands[j].prog, WTERMSIG (status)); 2374 signal_count++; 2375 ret_code = -1; 2376 } 2377 else if (WIFEXITED (status) 2378 && WEXITSTATUS (status) >= MIN_FATAL_STATUS) 2379 ret_code = -1; 2380 } 2381 break; 2382 } 2383 } 2384 return ret_code; 2385 } 2386} 2387 2388/* Find all the switches given to us 2389 and make a vector describing them. 2390 The elements of the vector are strings, one per switch given. 2391 If a switch uses following arguments, then the `part1' field 2392 is the switch itself and the `args' field 2393 is a null-terminated vector containing the following arguments. 2394 The `live_cond' field is 1 if the switch is true in a conditional spec, 2395 -1 if false (overridden by a later switch), and is initialized to zero. 2396 The `validated' field is nonzero if any spec has looked at this switch; 2397 if it remains zero at the end of the run, it must be meaningless. */ 2398 2399struct switchstr 2400{ 2401 const char *part1; 2402 char **args; 2403 int live_cond; 2404 int validated; 2405}; 2406 2407static struct switchstr *switches; 2408 2409static int n_switches; 2410 2411struct infile 2412{ 2413 const char *name; 2414 const char *language; 2415}; 2416 2417/* Also a vector of input files specified. */ 2418 2419static struct infile *infiles; 2420 2421static int n_infiles; 2422 2423/* This counts the number of libraries added by lang_specific_driver, so that 2424 we can tell if there were any user supplied any files or libraries. */ 2425 2426static int added_libraries; 2427 2428/* And a vector of corresponding output files is made up later. */ 2429 2430static const char **outfiles; 2431 2432/* Used to track if none of the -B paths are used. */ 2433static int warn_B; 2434 2435/* Used to track if standard path isn't used and -b or -V is specified. */ 2436static int warn_std; 2437 2438/* Gives value to pass as "warn" to add_prefix for standard prefixes. */ 2439static int *warn_std_ptr = 0; 2440 2441 2442#if defined(HAVE_OBJECT_SUFFIX) || defined(HAVE_EXECUTABLE_SUFFIX) 2443 2444/* Convert NAME to a new name if it is the standard suffix. DO_EXE 2445 is true if we should look for an executable suffix as well. */ 2446 2447static char * 2448convert_filename (name, do_exe) 2449 char *name; 2450 int do_exe; 2451{ 2452 int i; 2453 int len; 2454 2455 if (name == NULL) 2456 return NULL; 2457 2458 len = strlen (name); 2459 2460#ifdef HAVE_OBJECT_SUFFIX 2461 /* Convert x.o to x.obj if OBJECT_SUFFIX is ".obj". */ 2462 if (len > 2 2463 && name[len - 2] == '.' 2464 && name[len - 1] == 'o') 2465 { 2466 obstack_grow (&obstack, name, len - 2); 2467 obstack_grow0 (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX)); 2468 name = obstack_finish (&obstack); 2469 } 2470#endif 2471 2472#ifdef HAVE_EXECUTABLE_SUFFIX 2473 /* If there is no filetype, make it the executable suffix (which includes 2474 the "."). But don't get confused if we have just "-o". */ 2475 if (! do_exe || EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-')) 2476 return name; 2477 2478 for (i = len - 1; i >= 0; i--) 2479 if (IS_DIR_SEPARATOR (name[i])) 2480 break; 2481 2482 for (i++; i < len; i++) 2483 if (name[i] == '.') 2484 return name; 2485 2486 obstack_grow (&obstack, name, len); 2487 obstack_grow0 (&obstack, EXECUTABLE_SUFFIX, strlen (EXECUTABLE_SUFFIX)); 2488 name = obstack_finish (&obstack); 2489#endif 2490 2491 return name; 2492} 2493#endif 2494 2495/* Display the command line switches accepted by gcc. */ 2496static void 2497display_help () 2498{ 2499 printf ("Usage: %s [options] file...\n", programname); 2500 printf ("Options:\n"); 2501 2502 printf (" --help Display this information\n"); 2503 if (! verbose_flag) 2504 printf (" (Use '-v --help' to display command line options of sub-processes)\n"); 2505 printf (" -dumpspecs Display all of the built in spec strings\n"); 2506 printf (" -dumpversion Display the version of the compiler\n"); 2507 printf (" -dumpmachine Display the compiler's target processor\n"); 2508 printf (" -print-search-dirs Display the directories in the compiler's search path\n"); 2509 printf (" -print-libgcc-file-name Display the name of the compiler's companion library\n"); 2510 printf (" -print-file-name=<lib> Display the full path to library <lib>\n"); 2511 printf (" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"); 2512 printf (" -print-multi-directory Display the root directory for versions of libgcc\n"); 2513 printf (" -print-multi-lib Display the mapping between command line options and\n"); 2514 printf (" multiple library search directories\n"); 2515 printf (" -Wa,<options> Pass comma-separated <options> on to the assembler\n"); 2516 printf (" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"); 2517 printf (" -Wl,<options> Pass comma-separated <options> on to the linker\n"); 2518 printf (" -Xlinker <arg> Pass <arg> on to the linker\n"); 2519 printf (" -save-temps Do not delete intermediate files\n"); 2520 printf (" -pipe Use pipes rather than intermediate files\n"); 2521 printf (" -specs=<file> Override builtin specs with the contents of <file>\n"); 2522 printf (" -std=<standard> Assume that the input sources are for <standard>\n"); 2523 printf (" -B <directory> Add <directory> to the compiler's search paths\n"); 2524 printf (" -b <machine> Run gcc for target <machine>, if installed\n"); 2525 printf (" -V <version> Run gcc version number <version>, if installed\n"); 2526 printf (" -v Display the programs invoked by the compiler\n"); 2527 printf (" -E Preprocess only; do not compile, assemble or link\n"); 2528 printf (" -S Compile only; do not assemble or link\n"); 2529 printf (" -c Compile and assemble, but do not link\n"); 2530 printf (" -o <file> Place the output into <file>\n"); 2531 printf (" -x <language> Specify the language of the following input files\n"); 2532 printf (" Permissable languages include: c c++ assembler none\n"); 2533 printf (" 'none' means revert to the default behaviour of\n"); 2534 printf (" guessing the language based on the file's extension\n"); 2535 printf (" -priority=<prio> Specify thread-priority to use (1-10, default is 5)\n"); 2536#ifndef __HAIKU__ 2537 printf (" -no-beos-fixes Disable any BeOS-R5 compatibility fixes\n"); 2538#endif 2539 2540 printf ("\nOptions starting with -g, -f, -m, -O or -W are automatically passed on to\n"); 2541 printf ("the various sub-processes invoked by %s. In order to pass other options\n", 2542 programname); 2543 printf ("on to these processes the -W<letter> options must be used.\n"); 2544 2545 /* The rest of the options are displayed by invocations of the various 2546 sub-processes. */ 2547} 2548 2549static void 2550add_preprocessor_option (option, len) 2551 const char * option; 2552 int len; 2553{ 2554 n_preprocessor_options++; 2555 2556 if (! preprocessor_options) 2557 preprocessor_options 2558 = (char **) xmalloc (n_preprocessor_options * sizeof (char *)); 2559 else 2560 preprocessor_options 2561 = (char **) xrealloc (preprocessor_options, 2562 n_preprocessor_options * sizeof (char *)); 2563 2564 preprocessor_options [n_preprocessor_options - 1] = 2565 save_string (option, len); 2566} 2567 2568static void 2569add_assembler_option (option, len) 2570 const char * option; 2571 int len; 2572{ 2573 n_assembler_options++; 2574 2575 if (! assembler_options) 2576 assembler_options 2577 = (char **) xmalloc (n_assembler_options * sizeof (char *)); 2578 else 2579 assembler_options 2580 = (char **) xrealloc (assembler_options, 2581 n_assembler_options * sizeof (char *)); 2582 2583 assembler_options [n_assembler_options - 1] = save_string (option, len); 2584} 2585 2586static void 2587add_linker_option (option, len) 2588 const char * option; 2589 int len; 2590{ 2591 n_linker_options++; 2592 2593 if (! linker_options) 2594 linker_options 2595 = (char **) xmalloc (n_linker_options * sizeof (char *)); 2596 else 2597 linker_options 2598 = (char **) xrealloc (linker_options, 2599 n_linker_options * sizeof (char *)); 2600 2601 linker_options [n_linker_options - 1] = save_string (option, len); 2602} 2603 2604/* Create the vector `switches' and its contents. 2605 Store its length in `n_switches'. */ 2606 2607static void 2608process_command (argc, argv) 2609 int argc; 2610 char **argv; 2611{ 2612 register int i; 2613 const char *temp; 2614 char *temp1; 2615 char *spec_lang = 0; 2616 int last_language_n_infiles; 2617 int have_c = 0; 2618 int have_o = 0; 2619 int lang_n_infiles = 0; 2620 2621 GET_ENV_PATH_LIST (gcc_exec_prefix, "GCC_EXEC_PREFIX"); 2622 2623 n_switches = 0; 2624 n_infiles = 0; 2625 added_libraries = 0; 2626 2627 /* Figure compiler version from version string. */ 2628 2629 compiler_version = temp1 = 2630 save_string (version_string, strlen (version_string)); 2631 for (; *temp1; ++temp1) 2632 { 2633 if (*temp1 == ' ') 2634 { 2635 *temp1 = '\0'; 2636 break; 2637 } 2638 } 2639 2640 /* Set up the default search paths. */ 2641 2642 if (gcc_exec_prefix) 2643 { 2644 int len = strlen (gcc_exec_prefix); 2645 if (len > (int) sizeof ("/lib/gcc-lib/")-1 2646 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1]))) 2647 { 2648 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc-lib/") + 1; 2649 if (IS_DIR_SEPARATOR (*temp) 2650 && strncmp (temp+1, "lib", 3) == 0 2651 && IS_DIR_SEPARATOR (temp[4]) 2652 && strncmp (temp+5, "gcc-lib", 7) == 0) 2653 len -= sizeof ("/lib/gcc-lib/") - 1; 2654 } 2655 2656 set_std_prefix (gcc_exec_prefix, len); 2657 add_prefix (&exec_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR); 2658 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", 0, 0, NULL_PTR); 2659 } 2660 2661 /* COMPILER_PATH and LIBRARY_PATH have values 2662 that are lists of directory names with colons. */ 2663 2664 GET_ENV_PATH_LIST (temp, "COMPILER_PATH"); 2665 if (temp) 2666 { 2667 const char *startp, *endp; 2668 char *nstore = (char *) alloca (strlen (temp) + 3); 2669 2670 startp = endp = temp; 2671 while (1) 2672 { 2673 if (*endp == PATH_SEPARATOR || *endp == 0) 2674 { 2675 strncpy (nstore, startp, endp-startp); 2676 if (endp == startp) 2677 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR)); 2678 else if (!IS_DIR_SEPARATOR (endp[-1])) 2679 { 2680 nstore[endp-startp] = DIR_SEPARATOR; 2681 nstore[endp-startp+1] = 0; 2682 } 2683 else 2684 nstore[endp-startp] = 0; 2685 add_prefix (&exec_prefixes, nstore, 0, 0, 0, NULL_PTR); 2686 add_prefix (&include_prefixes, 2687 concat (nstore, "include", NULL_PTR), 2688 0, 0, 0, NULL_PTR); 2689 if (*endp == 0) 2690 break; 2691 endp = startp = endp + 1; 2692 } 2693 else 2694 endp++; 2695 } 2696 } 2697 2698 GET_ENV_PATH_LIST (temp, LIBRARY_PATH_ENV); 2699 if (temp && *cross_compile == '0') 2700 { 2701 const char *startp, *endp; 2702 char *nstore = (char *) alloca (strlen (temp) + 3); 2703 2704 startp = endp = temp; 2705 while (1) 2706 { 2707 if (*endp == PATH_SEPARATOR || *endp == 0) 2708 { 2709 strncpy (nstore, startp, endp-startp); 2710 if (endp == startp) 2711 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR)); 2712 else if (!IS_DIR_SEPARATOR (endp[-1])) 2713 { 2714 nstore[endp-startp] = DIR_SEPARATOR; 2715 nstore[endp-startp+1] = 0; 2716 } 2717 else 2718 nstore[endp-startp] = 0; 2719 add_prefix (&startfile_prefixes, nstore, NULL_PTR, 2720 0, 0, NULL_PTR); 2721 if (*endp == 0) 2722 break; 2723 endp = startp = endp + 1; 2724 } 2725 else 2726 endp++; 2727 } 2728 } 2729 2730 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ 2731 GET_ENV_PATH_LIST (temp, "LPATH"); 2732 if (temp && *cross_compile == '0') 2733 { 2734 const char *startp, *endp; 2735 char *nstore = (char *) alloca (strlen (temp) + 3); 2736 2737 startp = endp = temp; 2738 while (1) 2739 { 2740 if (*endp == PATH_SEPARATOR || *endp == 0) 2741 { 2742 strncpy (nstore, startp, endp-startp); 2743 if (endp == startp) 2744 strcpy (nstore, concat (".", dir_separator_str, NULL_PTR)); 2745 else if (!IS_DIR_SEPARATOR (endp[-1])) 2746 { 2747 nstore[endp-startp] = DIR_SEPARATOR; 2748 nstore[endp-startp+1] = 0; 2749 } 2750 else 2751 nstore[endp-startp] = 0; 2752 add_prefix (&startfile_prefixes, nstore, NULL_PTR, 2753 0, 0, NULL_PTR); 2754 if (*endp == 0) 2755 break; 2756 endp = startp = endp + 1; 2757 } 2758 else 2759 endp++; 2760 } 2761 } 2762 2763 /* Convert new-style -- options to old-style. */ 2764 translate_options (&argc, &argv); 2765 2766 /* Do language-specific adjustment/addition of flags. */ 2767 lang_specific_driver (fatal, &argc, &argv, &added_libraries); 2768 2769 /* Scan argv twice. Here, the first time, just count how many switches 2770 there will be in their vector, and how many input files in theirs. 2771 Here we also parse the switches that cc itself uses (e.g. -v). */ 2772 2773 for (i = 1; i < argc; i++) 2774 { 2775 if (! strcmp (argv[i], "-dumpspecs")) 2776 { 2777 struct spec_list *sl; 2778 init_spec (); 2779 for (sl = specs; sl; sl = sl->next) 2780 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec)); 2781 if (link_command_spec) 2782 printf ("*link_command:\n%s\n\n", link_command_spec); 2783 exit (0); 2784 } 2785 else if (! strcmp (argv[i], "-dumpversion")) 2786 { 2787 printf ("%s\n", spec_version); 2788 exit (0); 2789 } 2790 else if (! strcmp (argv[i], "-dumpmachine")) 2791 { 2792 printf ("%s\n", spec_machine); 2793 exit (0); 2794 } 2795 else if (strcmp (argv[i], "-fhelp") == 0) 2796 { 2797 /* translate_options () has turned --help into -fhelp. */ 2798 print_help_list = 1; 2799 2800 /* We will be passing a dummy file on to the sub-processes. */ 2801 n_infiles++; 2802 n_switches++; 2803 2804 add_preprocessor_option ("--help", 6); 2805 add_assembler_option ("--help", 6); 2806 add_linker_option ("--help", 6); 2807 } 2808#if defined(__BEOS__) || defined(__HAIKU__) 2809 else if (!strncmp (argv[i], "-priority=", 10)) 2810 { 2811 priority = atol (argv[i] + 10); 2812 add_preprocessor_option (argv[i], strlen(argv[i])); 2813 add_assembler_option (argv[i], strlen(argv[i])); 2814 add_linker_option (argv[i], strlen(argv[i])); 2815 n_switches++; 2816 } 2817#ifndef __HAIKU__ 2818 else if (!strcmp (argv[i], "-no-beos-fixes")) 2819 { 2820 n_switches++; 2821 } 2822#endif /* !__HAIKU__ */ 2823#endif 2824 else if (! strcmp (argv[i], "-print-search-dirs")) 2825 print_search_dirs = 1; 2826 else if (! strcmp (argv[i], "-print-libgcc-file-name")) 2827 print_file_name = "libgcc.a"; 2828 else if (! strncmp (argv[i], "-print-file-name=", 17)) 2829 print_file_name = argv[i] + 17; 2830 else if (! strncmp (argv[i], "-print-prog-name=", 17)) 2831 print_prog_name = argv[i] + 17; 2832 else if (! strcmp (argv[i], "-print-multi-lib")) 2833 print_multi_lib = 1; 2834 else if (! strcmp (argv[i], "-print-multi-directory")) 2835 print_multi_directory = 1; 2836 else if (! strncmp (argv[i], "-Wa,", 4)) 2837 { 2838 int prev, j; 2839 /* Pass the rest of this option to the assembler. */ 2840 2841 /* Split the argument at commas. */ 2842 prev = 4; 2843 for (j = 4; argv[i][j]; j++) 2844 if (argv[i][j] == ',') 2845 { 2846 add_assembler_option (argv[i] + prev, j - prev); 2847 prev = j + 1; 2848 } 2849 2850 /* Record the part after the last comma. */ 2851 add_assembler_option (argv[i] + prev, j - prev); 2852 } 2853 else if (! strncmp (argv[i], "-Wp,", 4)) 2854 { 2855 int prev, j; 2856 /* Pass the rest of this option to the preprocessor. */ 2857 2858 /* Split the argument at commas. */ 2859 prev = 4; 2860 for (j = 4; argv[i][j]; j++) 2861 if (argv[i][j] == ',') 2862 { 2863 add_preprocessor_option (argv[i] + prev, j - prev); 2864 prev = j + 1; 2865 } 2866 2867 /* Record the part after the last comma. */ 2868 add_preprocessor_option (argv[i] + prev, j - prev); 2869 } 2870 else if (argv[i][0] == '+' && argv[i][1] == 'e') 2871 /* The +e options to the C++ front-end. */ 2872 n_switches++; 2873 else if (strncmp (argv[i], "-Wl,", 4) == 0) 2874 { 2875 int j; 2876 /* Split the argument at commas. */ 2877 for (j = 3; argv[i][j]; j++) 2878 n_infiles += (argv[i][j] == ','); 2879 } 2880 else if (strcmp (argv[i], "-Xlinker") == 0) 2881 { 2882 if (i + 1 == argc) 2883 fatal ("argument to `-Xlinker' is missing"); 2884 2885 n_infiles++; 2886 i++; 2887 } 2888 else if (strncmp (argv[i], "-l", 2) == 0) 2889 n_infiles++; 2890 else if (strcmp (argv[i], "-save-temps") == 0) 2891 { 2892 save_temps_flag = 1; 2893 n_switches++; 2894 } 2895 else if (strcmp (argv[i], "-specs") == 0) 2896 { 2897 struct user_specs *user = (struct user_specs *) 2898 xmalloc (sizeof (struct user_specs)); 2899 if (++i >= argc) 2900 fatal ("argument to `-specs' is missing"); 2901 2902 user->next = (struct user_specs *)0; 2903 user->filename = argv[i]; 2904 if (user_specs_tail) 2905 user_specs_tail->next = user; 2906 else 2907 user_specs_head = user; 2908 user_specs_tail = user; 2909 } 2910 else if (strncmp (argv[i], "-specs=", 7) == 0) 2911 { 2912 struct user_specs *user = (struct user_specs *) 2913 xmalloc (sizeof (struct user_specs)); 2914 if (strlen (argv[i]) == 7) 2915 fatal ("argument to `-specs=' is missing"); 2916 2917 user->next = (struct user_specs *)0; 2918 user->filename = argv[i]+7; 2919 if (user_specs_tail) 2920 user_specs_tail->next = user; 2921 else 2922 user_specs_head = user; 2923 user_specs_tail = user; 2924 } 2925 else if (argv[i][0] == '-' && argv[i][1] != 0) 2926 { 2927 register char *p = &argv[i][1]; 2928 register int c = *p; 2929 2930 switch (c) 2931 { 2932 case 'b': 2933 n_switches++; 2934 if (p[1] == 0 && i + 1 == argc) 2935 fatal ("argument to `-b' is missing"); 2936 if (p[1] == 0) 2937 spec_machine = argv[++i]; 2938 else 2939 spec_machine = p + 1; 2940 2941 warn_std_ptr = &warn_std; 2942 break; 2943 2944 case 'B': 2945 { 2946 char *value; 2947 if (p[1] == 0 && i + 1 == argc) 2948 fatal ("argument to `-B' is missing"); 2949 if (p[1] == 0) 2950 value = argv[++i]; 2951 else 2952 value = p + 1; 2953 add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B); 2954 add_prefix (&startfile_prefixes, value, NULL_PTR, 2955 1, 0, &warn_B); 2956 add_prefix (&include_prefixes, concat (value, "include", 2957 NULL_PTR), 2958 NULL_PTR, 1, 0, NULL_PTR); 2959 2960 /* As a kludge, if the arg is "[foo/]stageN/", just add 2961 "[foo/]include" to the include prefix. */ 2962 { 2963 int len = strlen (value); 2964 if ((len == 7 2965 || (len > 7 2966 && (IS_DIR_SEPARATOR (value[len - 8])))) 2967 && strncmp (value + len - 7, "stage", 5) == 0 2968 && ISDIGIT (value[len - 2]) 2969 && (IS_DIR_SEPARATOR (value[len - 1]))) 2970 { 2971 if (len == 7) 2972 add_prefix (&include_prefixes, "include", NULL_PTR, 2973 1, 0, NULL_PTR); 2974 else 2975 { 2976 char *string = xmalloc (len + 1); 2977 strncpy (string, value, len-7); 2978 strcpy (string+len-7, "include"); 2979 add_prefix (&include_prefixes, string, NULL_PTR, 2980 1, 0, NULL_PTR); 2981 } 2982 } 2983 } 2984 n_switches++; 2985 } 2986 break; 2987 2988 case 'v': /* Print our subcommands and print versions. */ 2989 n_switches++; 2990 /* If they do anything other than exactly `-v', don't set 2991 verbose_flag; rather, continue on to give the error. */ 2992 if (p[1] != 0) 2993 break; 2994 verbose_flag++; 2995 break; 2996 2997 case 'V': 2998 n_switches++; 2999 if (p[1] == 0 && i + 1 == argc) 3000 fatal ("argument to `-V' is missing"); 3001 if (p[1] == 0) 3002 spec_version = argv[++i]; 3003 else 3004 spec_version = p + 1; 3005 compiler_version = spec_version; 3006 warn_std_ptr = &warn_std; 3007 3008 /* Validate the version number. Use the same checks 3009 done when inserting it into a spec. 3010 3011 The format of the version string is 3012 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */ 3013 { 3014 const char *v = compiler_version; 3015 3016 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */ 3017 while (! ISDIGIT (*v)) 3018 v++; 3019 3020 if (v > compiler_version && v[-1] != '-') 3021 fatal ("invalid version number format"); 3022 3023 /* Set V after the first period. */ 3024 while (ISDIGIT (*v)) 3025 v++; 3026 3027 if (*v != '.') 3028 fatal ("invalid version number format"); 3029 3030 v++; 3031 while (ISDIGIT (*v)) 3032 v++; 3033 3034 if (*v != 0 && *v != ' ' && *v != '.' && *v != '-') 3035 fatal ("invalid version number format"); 3036 } 3037 break; 3038 3039 case 'S': 3040 case 'c': 3041 if (p[1] == 0) 3042 { 3043 have_c = 1; 3044 n_switches++; 3045 break; 3046 } 3047 goto normal_switch; 3048 3049 case 'o': 3050 have_o = 1; 3051#if defined(HAVE_EXECUTABLE_SUFFIX) 3052 if (! have_c) 3053 { 3054 int skip; 3055 3056 /* Forward scan, just in case -S or -c is specified 3057 after -o. */ 3058 int j = i + 1; 3059 if (p[1] == 0) 3060 ++j; 3061 while (j < argc) 3062 { 3063 if (argv[j][0] == '-') 3064 { 3065 if (SWITCH_CURTAILS_COMPILATION (argv[j][1]) 3066 && argv[j][2] == 0) 3067 { 3068 have_c = 1; 3069 break; 3070 } 3071 else if (skip = SWITCH_TAKES_ARG (argv[j][1])) 3072 j += skip - (argv[j][2] != 0); 3073 else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1)) 3074 j += skip; 3075 } 3076 j++; 3077 } 3078 } 3079#endif 3080#if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX) 3081 if (p[1] == 0) 3082 argv[i+1] = convert_filename (argv[i+1], ! have_c); 3083 else 3084 argv[i] = convert_filename (argv[i], ! have_c); 3085#endif 3086 goto normal_switch; 3087 3088 default: 3089 normal_switch: 3090 n_switches++; 3091 3092 if (SWITCH_TAKES_ARG (c) > (p[1] != 0)) 3093 i += SWITCH_TAKES_ARG (c) - (p[1] != 0); 3094 else if (WORD_SWITCH_TAKES_ARG (p)) 3095 i += WORD_SWITCH_TAKES_ARG (p); 3096 } 3097 } 3098 else 3099 { 3100 n_infiles++; 3101 lang_n_infiles++; 3102 } 3103 } 3104 3105 if (have_c && have_o && lang_n_infiles > 1) 3106 fatal ("cannot specify -o with -c or -S and multiple compilations"); 3107 3108#if defined(__BEOS__) || defined(__HAIKU__) 3109 set_thread_priority (find_thread(NULL), priority); 3110 { 3111 char priobuf[20]; 3112 sprintf (priobuf, "-priority=%d", priority); 3113 if (verbose_flag) 3114 notice ("using priority %d\n", priority); 3115 } 3116#endif 3117 3118 /* Set up the search paths before we go looking for config files. */ 3119 3120 /* These come before the md prefixes so that we will find gcc's subcommands 3121 (such as cpp) rather than those of the host system. */ 3122 /* Use 2 as fourth arg meaning try just the machine as a suffix, 3123 as well as trying the machine and the version. */ 3124#ifndef OS2 3125 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS", 3126 0, 2, warn_std_ptr); 3127#if !defined(__BEOS__) && !defined(__HAIKU__) 3128 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS", 3129 0, 2, warn_std_ptr); 3130#endif 3131#endif 3132 3133 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS", 3134 0, 1, warn_std_ptr); 3135#if !defined(__BEOS__) && !defined(__HAIKU__) 3136 add_prefix (&startfile_prefixes, standard_exec_prefix_1, "BINUTILS", 3137 0, 1, warn_std_ptr); 3138#endif 3139 3140 tooldir_prefix = concat (tooldir_base_prefix, spec_machine, 3141 dir_separator_str, NULL_PTR); 3142 3143 /* If tooldir is relative, base it on exec_prefixes. A relative 3144 tooldir lets us move the installed tree as a unit. 3145 3146 If GCC_EXEC_PREFIX is defined, then we want to add two relative 3147 directories, so that we can search both the user specified directory 3148 and the standard place. */ 3149 3150 if (!IS_DIR_SEPARATOR (*tooldir_prefix)) 3151 { 3152 if (gcc_exec_prefix) 3153 { 3154 char *gcc_exec_tooldir_prefix 3155 = concat (gcc_exec_prefix, spec_machine, dir_separator_str, 3156 spec_version, dir_separator_str, tooldir_prefix, NULL_PTR); 3157 3158 add_prefix (&exec_prefixes, 3159 concat (gcc_exec_tooldir_prefix, "bin", 3160 dir_separator_str, NULL_PTR), 3161 NULL_PTR, 0, 0, NULL_PTR); 3162 add_prefix (&startfile_prefixes, 3163 concat (gcc_exec_tooldir_prefix, "lib", 3164 dir_separator_str, NULL_PTR), 3165 NULL_PTR, 0, 0, NULL_PTR); 3166 } 3167 3168 tooldir_prefix = concat (standard_exec_prefix, spec_machine, 3169 dir_separator_str, spec_version, 3170 dir_separator_str, tooldir_prefix, NULL_PTR); 3171 } 3172 3173 add_prefix (&exec_prefixes, 3174 concat (tooldir_prefix, "bin", dir_separator_str, NULL_PTR), 3175 "BINUTILS", 0, 0, NULL_PTR); 3176 add_prefix (&startfile_prefixes, 3177 concat (tooldir_prefix, "lib", dir_separator_str, NULL_PTR), 3178 "BINUTILS", 0, 0, NULL_PTR); 3179 3180 /* More prefixes are enabled in main, after we read the specs file 3181 and determine whether this is cross-compilation or not. */ 3182 3183 3184 /* Then create the space for the vectors and scan again. */ 3185 3186 switches = ((struct switchstr *) 3187 xmalloc ((n_switches + 1) * sizeof (struct switchstr))); 3188 infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile)); 3189 n_switches = 0; 3190 n_infiles = 0; 3191 last_language_n_infiles = -1; 3192 3193 /* This, time, copy the text of each switch and store a pointer 3194 to the copy in the vector of switches. 3195 Store all the infiles in their vector. */ 3196 3197 for (i = 1; i < argc; i++) 3198 { 3199 /* Just skip the switches that were handled by the preceding loop. */ 3200 if (! strncmp (argv[i], "-Wa,", 4)) 3201 ; 3202 else if (! strncmp (argv[i], "-Wp,", 4)) 3203 ; 3204 else if (! strcmp (argv[i], "-print-search-dirs")) 3205 ; 3206 else if (! strcmp (argv[i], "-print-libgcc-file-name")) 3207 ; 3208 else if (! strncmp (argv[i], "-print-file-name=", 17)) 3209 ; 3210 else if (! strncmp (argv[i], "-print-prog-name=", 17)) 3211 ; 3212 else if (! strcmp (argv[i], "-print-multi-lib")) 3213 ; 3214 else if (! strcmp (argv[i], "-print-multi-directory")) 3215 ; 3216#ifndef __HAIKU__ 3217 else if (! strcmp (argv[i], "-no-beos-fixes")) 3218 { 3219 /* Preserve the switch so that it can be caught by the 3220 cc1 spec string. */ 3221 switches[n_switches].part1 = argv[i]+1; 3222 switches[n_switches].args = 0; 3223 switches[n_switches].live_cond = 0; 3224 switches[n_switches].validated = 0; 3225 n_switches++; 3226 } 3227#endif /* !__HAIKU__ */ 3228 else if (! strncmp (argv[i], "-priority=", 10)) 3229 { 3230 /* Preserve the switch so that it can be caught by the 3231 cc1 spec string. */ 3232 switches[n_switches].part1 = argv[i]+1; 3233 switches[n_switches].args = 0; 3234 switches[n_switches].live_cond = 0; 3235 switches[n_switches].validated = 0; 3236 n_switches++; 3237 } 3238 else if (strcmp (argv[i], "-fhelp") == 0) 3239 { 3240 if (verbose_flag) 3241 { 3242 /* Create a dummy input file, so that we can pass --help on to 3243 the various sub-processes. */ 3244 infiles[n_infiles].language = "c"; 3245 infiles[n_infiles++].name = "help-dummy"; 3246 3247 /* Preserve the --help switch so that it can be caught by the 3248 cc1 spec string. */ 3249 switches[n_switches].part1 = "--help"; 3250 switches[n_switches].args = 0; 3251 switches[n_switches].live_cond = 0; 3252 switches[n_switches].validated = 0; 3253 3254 n_switches++; 3255 } 3256 } 3257 else if (argv[i][0] == '+' && argv[i][1] == 'e') 3258 { 3259 /* Compensate for the +e options to the C++ front-end; 3260 they're there simply for cfront call-compatibility. We do 3261 some magic in default_compilers to pass them down properly. 3262 Note we deliberately start at the `+' here, to avoid passing 3263 -e0 or -e1 down into the linker. */ 3264 switches[n_switches].part1 = &argv[i][0]; 3265 switches[n_switches].args = 0; 3266 switches[n_switches].live_cond = 0; 3267 switches[n_switches].validated = 0; 3268 n_switches++; 3269 } 3270 else if (strncmp (argv[i], "-Wl,", 4) == 0) 3271 { 3272 int prev, j; 3273 /* Split the argument at commas. */ 3274 prev = 4; 3275 for (j = 4; argv[i][j]; j++) 3276 if (argv[i][j] == ',') 3277 { 3278 infiles[n_infiles].language = "*"; 3279 infiles[n_infiles++].name 3280 = save_string (argv[i] + prev, j - prev); 3281 prev = j + 1; 3282 } 3283 /* Record the part after the last comma. */ 3284 infiles[n_infiles].language = "*"; 3285 infiles[n_infiles++].name = argv[i] + prev; 3286 } 3287 else if (strcmp (argv[i], "-Xlinker") == 0) 3288 { 3289 infiles[n_infiles].language = "*"; 3290 infiles[n_infiles++].name = argv[++i]; 3291 } 3292 else if (strncmp (argv[i], "-l", 2) == 0) 3293 { 3294 infiles[n_infiles].language = "*"; 3295 infiles[n_infiles++].name = argv[i]; 3296 } 3297 else if (strcmp (argv[i], "-specs") == 0) 3298 i++; 3299 else if (strncmp (argv[i], "-specs=", 7) == 0) 3300 ; 3301 /* -save-temps overrides -pipe, so that temp files are produced */ 3302 else if (save_temps_flag && strcmp (argv[i], "-pipe") == 0) 3303 error ("Warning: -pipe ignored since -save-temps specified"); 3304 else if (argv[i][0] == '-' && argv[i][1] != 0) 3305 { 3306 register char *p = &argv[i][1]; 3307 register int c = *p; 3308 3309 if (c == 'x') 3310 { 3311 if (p[1] == 0 && i + 1 == argc) 3312 fatal ("argument to `-x' is missing"); 3313 if (p[1] == 0) 3314 spec_lang = argv[++i]; 3315 else 3316 spec_lang = p + 1; 3317 if (! strcmp (spec_lang, "none")) 3318 /* Suppress the warning if -xnone comes after the last input 3319 file, because alternate command interfaces like g++ might 3320 find it useful to place -xnone after each input file. */ 3321 spec_lang = 0; 3322 else 3323 last_language_n_infiles = n_infiles; 3324 continue; 3325 } 3326 switches[n_switches].part1 = p; 3327 /* Deal with option arguments in separate argv elements. */ 3328 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0)) 3329 || WORD_SWITCH_TAKES_ARG (p)) 3330 { 3331 int j = 0; 3332 int n_args = WORD_SWITCH_TAKES_ARG (p); 3333 3334 if (n_args == 0) 3335 { 3336 /* Count only the option arguments in separate argv elements. */ 3337 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0); 3338 } 3339 if (i + n_args >= argc) 3340 fatal ("argument to `-%s' is missing", p); 3341 switches[n_switches].args 3342 = (char **) xmalloc ((n_args + 1) * sizeof (char *)); 3343 while (j < n_args) 3344 switches[n_switches].args[j++] = argv[++i]; 3345 /* Null-terminate the vector. */ 3346 switches[n_switches].args[j] = 0; 3347 } 3348 else if (index (switches_need_spaces, c)) 3349 { 3350 /* On some systems, ld cannot handle some options without 3351 a space. So split the option from its argument. */ 3352 char *part1 = (char *) xmalloc (2); 3353 part1[0] = c; 3354 part1[1] = '\0'; 3355 3356 switches[n_switches].part1 = part1; 3357 switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *)); 3358 switches[n_switches].args[0] = xmalloc (strlen (p)); 3359 strcpy (switches[n_switches].args[0], &p[1]); 3360 switches[n_switches].args[1] = 0; 3361 } 3362 else 3363 switches[n_switches].args = 0; 3364 3365 switches[n_switches].live_cond = 0; 3366 switches[n_switches].validated = 0; 3367 /* This is always valid, since gcc.c itself understands it. */ 3368 if (!strcmp (p, "save-temps")) 3369 switches[n_switches].validated = 1; 3370 else 3371 { 3372 char ch = switches[n_switches].part1[0]; 3373 if (ch == 'V' || ch == 'b' || ch == 'B') 3374 switches[n_switches].validated = 1; 3375 } 3376 n_switches++; 3377 } 3378 else 3379 { 3380#ifdef HAVE_OBJECT_SUFFIX 3381 argv[i] = convert_filename (argv[i], 0); 3382#endif 3383 3384 if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0) 3385 { 3386 perror_with_name (argv[i]); 3387 error_count++; 3388 } 3389 else 3390 { 3391 infiles[n_infiles].language = spec_lang; 3392 infiles[n_infiles++].name = argv[i]; 3393 } 3394 } 3395 } 3396 3397 if (n_infiles == last_language_n_infiles && spec_lang != 0) 3398 error ("Warning: `-x %s' after last input file has no effect", spec_lang); 3399 3400 switches[n_switches].part1 = 0; 3401 infiles[n_infiles].name = 0; 3402} 3403 3404/* Process a spec string, accumulating and running commands. */ 3405 3406/* These variables describe the input file name. 3407 input_file_number is the index on outfiles of this file, 3408 so that the output file name can be stored for later use by %o. 3409 input_basename is the start of the part of the input file 3410 sans all directory names, and basename_length is the number 3411 of characters starting there excluding the suffix .c or whatever. */ 3412 3413const char *input_filename; 3414static int input_file_number; 3415size_t input_filename_length; 3416static int basename_length; 3417static const char *input_basename; 3418static const char *input_suffix; 3419 3420/* These are variables used within do_spec and do_spec_1. */ 3421 3422/* Nonzero if an arg has been started and not yet terminated 3423 (with space, tab or newline). */ 3424static int arg_going; 3425 3426/* Nonzero means %d or %g has been seen; the next arg to be terminated 3427 is a temporary file name. */ 3428static int delete_this_arg; 3429 3430/* Nonzero means %w has been seen; the next arg to be terminated 3431 is the output file name of this compilation. */ 3432static int this_is_output_file; 3433 3434/* Nonzero means %s has been seen; the next arg to be terminated 3435 is the name of a library file and we should try the standard 3436 search dirs for it. */ 3437static int this_is_library_file; 3438 3439/* Nonzero means that the input of this command is coming from a pipe. */ 3440static int input_from_pipe; 3441 3442/* Process the spec SPEC and run the commands specified therein. 3443 Returns 0 if the spec is successfully processed; -1 if failed. */ 3444 3445int 3446do_spec (spec) 3447 const char *spec; 3448{ 3449 int value; 3450 3451 clear_args (); 3452 arg_going = 0; 3453 delete_this_arg = 0; 3454 this_is_output_file = 0; 3455 this_is_library_file = 0; 3456 input_from_pipe = 0; 3457 3458 value = do_spec_1 (spec, 0, NULL_PTR); 3459 3460 /* Force out any unfinished command. 3461 If -pipe, this forces out the last command if it ended in `|'. */ 3462 if (value == 0) 3463 { 3464 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) 3465 argbuf_index--; 3466 3467 if (argbuf_index > 0) 3468 value = execute (); 3469 } 3470 3471 return value; 3472} 3473 3474/* Process the sub-spec SPEC as a portion of a larger spec. 3475 This is like processing a whole spec except that we do 3476 not initialize at the beginning and we do not supply a 3477 newline by default at the end. 3478 INSWITCH nonzero means don't process %-sequences in SPEC; 3479 in this case, % is treated as an ordinary character. 3480 This is used while substituting switches. 3481 INSWITCH nonzero also causes SPC not to terminate an argument. 3482 3483 Value is zero unless a line was finished 3484 and the command on that line reported an error. */ 3485 3486static int 3487do_spec_1 (spec, inswitch, soft_matched_part) 3488 const char *spec; 3489 int inswitch; 3490 const char *soft_matched_part; 3491{ 3492 register const char *p = spec; 3493 register int c; 3494 int i; 3495 const char *string; 3496 int value; 3497 3498 while ((c = *p++)) 3499 /* If substituting a switch, treat all chars like letters. 3500 Otherwise, NL, SPC, TAB and % are special. */ 3501 switch (inswitch ? 'a' : c) 3502 { 3503 case '\n': 3504 /* End of line: finish any pending argument, 3505 then run the pending command if one has been started. */ 3506 if (arg_going) 3507 { 3508 obstack_1grow (&obstack, 0); 3509 string = obstack_finish (&obstack); 3510 if (this_is_library_file) 3511 string = find_file (string); 3512 store_arg (string, delete_this_arg, this_is_output_file); 3513 if (this_is_output_file) 3514 outfiles[input_file_number] = string; 3515 } 3516 arg_going = 0; 3517 3518 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) 3519 { 3520 for (i = 0; i < n_switches; i++) 3521 if (!strcmp (switches[i].part1, "pipe")) 3522 break; 3523 3524 /* A `|' before the newline means use a pipe here, 3525 but only if -pipe was specified. 3526 Otherwise, execute now and don't pass the `|' as an arg. */ 3527 if (i < n_switches) 3528 { 3529 input_from_pipe = 1; 3530 switches[i].validated = 1; 3531 break; 3532 } 3533 else 3534 argbuf_index--; 3535 } 3536 3537 if (argbuf_index > 0) 3538 { 3539 value = execute (); 3540 if (value) 3541 return value; 3542 } 3543 /* Reinitialize for a new command, and for a new argument. */ 3544 clear_args (); 3545 arg_going = 0; 3546 delete_this_arg = 0; 3547 this_is_output_file = 0; 3548 this_is_library_file = 0; 3549 input_from_pipe = 0; 3550 break; 3551 3552 case '|': 3553 /* End any pending argument. */ 3554 if (arg_going) 3555 { 3556 obstack_1grow (&obstack, 0); 3557 string = obstack_finish (&obstack); 3558 if (this_is_library_file) 3559 string = find_file (string); 3560 store_arg (string, delete_this_arg, this_is_output_file); 3561 if (this_is_output_file) 3562 outfiles[input_file_number] = string; 3563 } 3564 3565 /* Use pipe */ 3566 obstack_1grow (&obstack, c); 3567 arg_going = 1; 3568 break; 3569 3570 case '\t': 3571 case ' ': 3572 /* Space or tab ends an argument if one is pending. */ 3573 if (arg_going) 3574 { 3575 obstack_1grow (&obstack, 0); 3576 string = obstack_finish (&obstack); 3577 if (this_is_library_file) 3578 string = find_file (string); 3579 store_arg (string, delete_this_arg, this_is_output_file); 3580 if (this_is_output_file) 3581 outfiles[input_file_number] = string; 3582 } 3583 /* Reinitialize for a new argument. */ 3584 arg_going = 0; 3585 delete_this_arg = 0; 3586 this_is_output_file = 0; 3587 this_is_library_file = 0; 3588 break; 3589 3590 case '%': 3591 switch (c = *p++) 3592 { 3593 case 0: 3594 fatal ("Invalid specification! Bug in cc."); 3595 3596 case 'b': 3597 obstack_grow (&obstack, input_basename, basename_length); 3598 arg_going = 1; 3599 break; 3600 3601 case 'd': 3602 delete_this_arg = 2; 3603 break; 3604 3605 /* Dump out the directories specified with LIBRARY_PATH, 3606 followed by the absolute directories 3607 that we search for startfiles. */ 3608 case 'D': 3609 { 3610 struct prefix_list *pl = startfile_prefixes.plist; 3611 size_t bufsize = 100; 3612 char *buffer = (char *) xmalloc (bufsize); 3613 int idx; 3614 3615 for (; pl; pl = pl->next) 3616 { 3617#ifdef RELATIVE_PREFIX_NOT_LINKDIR 3618 /* Used on systems which record the specified -L dirs 3619 and use them to search for dynamic linking. */ 3620 /* Relative directories always come from -B, 3621 and it is better not to use them for searching 3622 at run time. In particular, stage1 loses */ 3623 if (!IS_DIR_SEPARATOR (pl->prefix[0])) 3624 continue; 3625#endif 3626 /* Try subdirectory if there is one. */ 3627 if (multilib_dir != NULL) 3628 { 3629 if (machine_suffix) 3630 { 3631 if (strlen (pl->prefix) + strlen (machine_suffix) 3632 >= bufsize) 3633 bufsize = (strlen (pl->prefix) 3634 + strlen (machine_suffix)) * 2 + 1; 3635 buffer = (char *) xrealloc (buffer, bufsize); 3636 strcpy (buffer, pl->prefix); 3637 strcat (buffer, machine_suffix); 3638 if (is_directory (buffer, multilib_dir, 1)) 3639 { 3640 do_spec_1 ("-L", 0, NULL_PTR); 3641#ifdef SPACE_AFTER_L_OPTION 3642 do_spec_1 (" ", 0, NULL_PTR); 3643#endif 3644 do_spec_1 (buffer, 1, NULL_PTR); 3645 do_spec_1 (multilib_dir, 1, NULL_PTR); 3646 /* Make this a separate argument. */ 3647 do_spec_1 (" ", 0, NULL_PTR); 3648 } 3649 } 3650 if (!pl->require_machine_suffix) 3651 { 3652 if (is_directory (pl->prefix, multilib_dir, 1)) 3653 { 3654 do_spec_1 ("-L", 0, NULL_PTR); 3655#ifdef SPACE_AFTER_L_OPTION 3656 do_spec_1 (" ", 0, NULL_PTR); 3657#endif 3658 do_spec_1 (pl->prefix, 1, NULL_PTR); 3659 do_spec_1 (multilib_dir, 1, NULL_PTR); 3660 /* Make this a separate argument. */ 3661 do_spec_1 (" ", 0, NULL_PTR); 3662 } 3663 } 3664 } 3665 if (machine_suffix) 3666 { 3667 if (is_directory (pl->prefix, machine_suffix, 1)) 3668 { 3669 do_spec_1 ("-L", 0, NULL_PTR); 3670#ifdef SPACE_AFTER_L_OPTION 3671 do_spec_1 (" ", 0, NULL_PTR); 3672#endif 3673 do_spec_1 (pl->prefix, 1, NULL_PTR); 3674 /* Remove slash from machine_suffix. */ 3675 if (strlen (machine_suffix) >= bufsize) 3676 bufsize = strlen (machine_suffix) * 2 + 1; 3677 buffer = (char *) xrealloc (buffer, bufsize); 3678 strcpy (buffer, machine_suffix); 3679 idx = strlen (buffer); 3680 if (IS_DIR_SEPARATOR (buffer[idx - 1])) 3681 buffer[idx - 1] = 0; 3682 do_spec_1 (buffer, 1, NULL_PTR); 3683 /* Make this a separate argument. */ 3684 do_spec_1 (" ", 0, NULL_PTR); 3685 } 3686 } 3687 if (!pl->require_machine_suffix) 3688 { 3689 if (is_directory (pl->prefix, "", 1)) 3690 { 3691 do_spec_1 ("-L", 0, NULL_PTR); 3692#ifdef SPACE_AFTER_L_OPTION 3693 do_spec_1 (" ", 0, NULL_PTR); 3694#endif 3695 /* Remove slash from pl->prefix. */ 3696 if (strlen (pl->prefix) >= bufsize) 3697 bufsize = strlen (pl->prefix) * 2 + 1; 3698 buffer = (char *) xrealloc (buffer, bufsize); 3699 strcpy (buffer, pl->prefix); 3700 idx = strlen (buffer); 3701 if (IS_DIR_SEPARATOR (buffer[idx - 1])) 3702 buffer[idx - 1] = 0; 3703 do_spec_1 (buffer, 1, NULL_PTR); 3704 /* Make this a separate argument. */ 3705 do_spec_1 (" ", 0, NULL_PTR); 3706 } 3707 } 3708 } 3709 free (buffer); 3710 } 3711 break; 3712 3713 case 'e': 3714 /* %efoo means report an error with `foo' as error message 3715 and don't execute any more commands for this file. */ 3716 { 3717 const char *q = p; 3718 char *buf; 3719 while (*p != 0 && *p != '\n') p++; 3720 buf = (char *) alloca (p - q + 1); 3721 strncpy (buf, q, p - q); 3722 buf[p - q] = 0; 3723 error (buf); 3724 return -1; 3725 } 3726 break; 3727 3728 case 'g': 3729 case 'u': 3730 case 'U': 3731 if (save_temps_flag) 3732 { 3733 obstack_grow (&obstack, input_basename, basename_length); 3734 delete_this_arg = 0; 3735 } 3736 else 3737 { 3738#ifdef MKTEMP_EACH_FILE 3739 /* ??? This has a problem: the total number of 3740 values mktemp can return is limited. 3741 That matters for the names of object files. 3742 In 2.4, do something about that. */ 3743 struct temp_name *t; 3744 int suffix_length; 3745 const char *suffix = p; 3746 3747 if (p[0] == '%' && p[1] == 'O') 3748 { 3749 p += 2; 3750 /* We don't support extra suffix characters after %O. */ 3751 if (*p == '.' || ISALPHA ((unsigned char)*p)) 3752 abort (); 3753 suffix = OBJECT_SUFFIX; 3754 suffix_length = strlen (OBJECT_SUFFIX); 3755 } 3756 else 3757 { 3758 while (*p == '.' || ISALPHA ((unsigned char)*p)) 3759 p++; 3760 suffix_length = p - suffix; 3761 } 3762 3763 /* See if we already have an association of %g/%u/%U and 3764 suffix. */ 3765 for (t = temp_names; t; t = t->next) 3766 if (t->length == suffix_length 3767 && strncmp (t->suffix, suffix, suffix_length) == 0 3768 && t->unique == (c != 'g')) 3769 break; 3770 3771 /* Make a new association if needed. %u requires one. */ 3772 if (t == 0 || c == 'u') 3773 { 3774 if (t == 0) 3775 { 3776 t = (struct temp_name *) xmalloc (sizeof (struct temp_name)); 3777 t->next = temp_names; 3778 temp_names = t; 3779 } 3780 t->length = suffix_length; 3781 t->suffix = save_string (suffix, suffix_length); 3782 t->unique = (c != 'g'); 3783 temp_filename = make_temp_file (t->suffix); 3784 temp_filename_length = strlen (temp_filename); 3785 t->filename = temp_filename; 3786 t->filename_length = temp_filename_length; 3787 } 3788 3789 obstack_grow (&obstack, t->filename, t->filename_length); 3790 delete_this_arg = 1; 3791#else 3792 obstack_grow (&obstack, temp_filename, temp_filename_length); 3793 if (c == 'u' || c == 'U') 3794 { 3795 static int unique; 3796 char buff[9]; 3797 if (c == 'u') 3798 unique++; 3799 sprintf (buff, "%d", unique); 3800 obstack_grow (&obstack, buff, strlen (buff)); 3801 } 3802#endif 3803 delete_this_arg = 1; 3804 } 3805 arg_going = 1; 3806 break; 3807 3808 case 'i': 3809 obstack_grow (&obstack, input_filename, input_filename_length); 3810 arg_going = 1; 3811 break; 3812 3813 case 'I': 3814 { 3815 struct prefix_list *pl = include_prefixes.plist; 3816 3817 if (gcc_exec_prefix) 3818 { 3819 do_spec_1 ("-iprefix", 1, NULL_PTR); 3820 /* Make this a separate argument. */ 3821 do_spec_1 (" ", 0, NULL_PTR); 3822 do_spec_1 (gcc_exec_prefix, 1, NULL_PTR); 3823 do_spec_1 (" ", 0, NULL_PTR); 3824 } 3825 3826 for (; pl; pl = pl->next) 3827 { 3828 do_spec_1 ("-isystem", 1, NULL_PTR); 3829 /* Make this a separate argument. */ 3830 do_spec_1 (" ", 0, NULL_PTR); 3831 do_spec_1 (pl->prefix, 1, NULL_PTR); 3832 do_spec_1 (" ", 0, NULL_PTR); 3833 } 3834 } 3835 break; 3836 3837 case 'o': 3838 { 3839 int max = n_infiles; 3840 max += lang_specific_extra_outfiles; 3841 3842 for (i = 0; i < max; i++) 3843 if (outfiles[i]) 3844 store_arg (outfiles[i], 0, 0); 3845 break; 3846 } 3847 3848 case 'O': 3849 obstack_grow (&obstack, OBJECT_SUFFIX, strlen (OBJECT_SUFFIX)); 3850 arg_going = 1; 3851 break; 3852 3853 case 's': 3854 this_is_library_file = 1; 3855 break; 3856 3857 case 'w': 3858 this_is_output_file = 1; 3859 break; 3860 3861 case 'W': 3862 { 3863 int cur_index = argbuf_index; 3864 /* Handle the {...} following the %W. */ 3865 if (*p != '{') 3866 abort (); 3867 p = handle_braces (p + 1); 3868 if (p == 0) 3869 return -1; 3870 /* If any args were output, mark the last one for deletion 3871 on failure. */ 3872 if (argbuf_index != cur_index) 3873 record_temp_file (argbuf[argbuf_index - 1], 0, 1); 3874 break; 3875 } 3876 3877 /* %x{OPTION} records OPTION for %X to output. */ 3878 case 'x': 3879 { 3880 const char *p1 = p; 3881 char *string; 3882 3883 /* Skip past the option value and make a copy. */ 3884 if (*p != '{') 3885 abort (); 3886 while (*p++ != '}') 3887 ; 3888 string = save_string (p1 + 1, p - p1 - 2); 3889 3890 /* See if we already recorded this option. */ 3891 for (i = 0; i < n_linker_options; i++) 3892 if (! strcmp (string, linker_options[i])) 3893 { 3894 free (string); 3895 return 0; 3896 } 3897 3898 /* This option is new; add it. */ 3899 add_linker_option (string, strlen (string)); 3900 } 3901 break; 3902 3903 /* Dump out the options accumulated previously using %x. */ 3904 case 'X': 3905 for (i = 0; i < n_linker_options; i++) 3906 { 3907 do_spec_1 (linker_options[i], 1, NULL_PTR); 3908 /* Make each accumulated option a separate argument. */ 3909 do_spec_1 (" ", 0, NULL_PTR); 3910 } 3911 break; 3912 3913 /* Dump out the options accumulated previously using -Wa,. */ 3914 case 'Y': 3915 for (i = 0; i < n_assembler_options; i++) 3916 { 3917 do_spec_1 (assembler_options[i], 1, NULL_PTR); 3918 /* Make each accumulated option a separate argument. */ 3919 do_spec_1 (" ", 0, NULL_PTR); 3920 } 3921 break; 3922 3923 /* Dump out the options accumulated previously using -Wp,. */ 3924 case 'Z': 3925 for (i = 0; i < n_preprocessor_options; i++) 3926 { 3927 do_spec_1 (preprocessor_options[i], 1, NULL_PTR); 3928 /* Make each accumulated option a separate argument. */ 3929 do_spec_1 (" ", 0, NULL_PTR); 3930 } 3931 break; 3932 3933 /* Here are digits and numbers that just process 3934 a certain constant string as a spec. */ 3935 3936 case '1': 3937 value = do_spec_1 (cc1_spec, 0, NULL_PTR); 3938 if (value != 0) 3939 return value; 3940 break; 3941 3942 case '2': 3943 value = do_spec_1 (cc1plus_spec, 0, NULL_PTR); 3944 if (value != 0) 3945 return value; 3946 break; 3947 3948 case 'a': 3949 value = do_spec_1 (asm_spec, 0, NULL_PTR); 3950 if (value != 0) 3951 return value; 3952 break; 3953 3954 case 'A': 3955 value = do_spec_1 (asm_final_spec, 0, NULL_PTR); 3956 if (value != 0) 3957 return value; 3958 break; 3959 3960 case 'c': 3961 value = do_spec_1 (signed_char_spec, 0, NULL_PTR); 3962 if (value != 0) 3963 return value; 3964 break; 3965 3966 case 'C': 3967 value = do_spec_1 (cpp_spec, 0, NULL_PTR); 3968 if (value != 0) 3969 return value; 3970 break; 3971 3972 case 'E': 3973 value = do_spec_1 (endfile_spec, 0, NULL_PTR); 3974 if (value != 0) 3975 return value; 3976 break; 3977 3978 case 'l': 3979 value = do_spec_1 (link_spec, 0, NULL_PTR); 3980 if (value != 0) 3981 return value; 3982 break; 3983 3984 case 'L': 3985 value = do_spec_1 (lib_spec, 0, NULL_PTR); 3986 if (value != 0) 3987 return value; 3988 break; 3989 3990 case 'G': 3991 value = do_spec_1 (libgcc_spec, 0, NULL_PTR); 3992 if (value != 0) 3993 return value; 3994 break; 3995 3996 case 'p': 3997 { 3998 char *x = (char *) alloca (strlen (cpp_predefines) + 1); 3999 char *buf = x; 4000 char *y; 4001 4002 /* Copy all of the -D options in CPP_PREDEFINES into BUF. */ 4003 y = cpp_predefines; 4004 while (*y != 0) 4005 { 4006 if (! strncmp (y, "-D", 2)) 4007 /* Copy the whole option. */ 4008 while (*y && *y != ' ' && *y != '\t') 4009 *x++ = *y++; 4010 else if (*y == ' ' || *y == '\t') 4011 /* Copy whitespace to the result. */ 4012 *x++ = *y++; 4013 /* Don't copy other options. */ 4014 else 4015 y++; 4016 } 4017 4018 *x = 0; 4019 4020 value = do_spec_1 (buf, 0, NULL_PTR); 4021 if (value != 0) 4022 return value; 4023 } 4024 break; 4025 4026 case 'P': 4027 { 4028 char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1); 4029 char *buf = x; 4030 char *y; 4031 4032 /* Copy all of CPP_PREDEFINES into BUF, 4033 but put __ after every -D and at the end of each arg. */ 4034 y = cpp_predefines; 4035 while (*y != 0) 4036 { 4037 if (! strncmp (y, "-D", 2)) 4038 { 4039 int flag = 0; 4040 4041 *x++ = *y++; 4042 *x++ = *y++; 4043 4044 if (*y != '_' 4045 || (*(y+1) != '_' 4046 && ! ISUPPER ((unsigned char)*(y+1)))) 4047 { 4048 /* Stick __ at front of macro name. */ 4049 *x++ = '_'; 4050 *x++ = '_'; 4051 /* Arrange to stick __ at the end as well. */ 4052 flag = 1; 4053 } 4054 4055 /* Copy the macro name. */ 4056 while (*y && *y != '=' && *y != ' ' && *y != '\t') 4057 *x++ = *y++; 4058 4059 if (flag) 4060 { 4061 *x++ = '_'; 4062 *x++ = '_'; 4063 } 4064 4065 /* Copy the value given, if any. */ 4066 while (*y && *y != ' ' && *y != '\t') 4067 *x++ = *y++; 4068 } 4069 else if (*y == ' ' || *y == '\t') 4070 /* Copy whitespace to the result. */ 4071 *x++ = *y++; 4072 /* Don't copy -A options */ 4073 else 4074 y++; 4075 } 4076 *x++ = ' '; 4077 4078 /* Copy all of CPP_PREDEFINES into BUF, 4079 but put __ after every -D. */ 4080 y = cpp_predefines; 4081 while (*y != 0) 4082 { 4083 if (! strncmp (y, "-D", 2)) 4084 { 4085 y += 2; 4086 4087 if (*y != '_' 4088 || (*(y+1) != '_' 4089 && ! ISUPPER ((unsigned char)*(y+1)))) 4090 { 4091 /* Stick -D__ at front of macro name. */ 4092 *x++ = '-'; 4093 *x++ = 'D'; 4094 *x++ = '_'; 4095 *x++ = '_'; 4096 4097 /* Copy the macro name. */ 4098 while (*y && *y != '=' && *y != ' ' && *y != '\t') 4099 *x++ = *y++; 4100 4101 /* Copy the value given, if any. */ 4102 while (*y && *y != ' ' && *y != '\t') 4103 *x++ = *y++; 4104 } 4105 else 4106 { 4107 /* Do not copy this macro - we have just done it before */ 4108 while (*y && *y != ' ' && *y != '\t') 4109 y++; 4110 } 4111 } 4112 else if (*y == ' ' || *y == '\t') 4113 /* Copy whitespace to the result. */ 4114 *x++ = *y++; 4115 /* Don't copy -A options */ 4116 else 4117 y++; 4118 } 4119 *x++ = ' '; 4120 4121 /* Copy all of the -A options in CPP_PREDEFINES into BUF. */ 4122 y = cpp_predefines; 4123 while (*y != 0) 4124 { 4125 if (! strncmp (y, "-A", 2)) 4126 /* Copy the whole option. */ 4127 while (*y && *y != ' ' && *y != '\t') 4128 *x++ = *y++; 4129 else if (*y == ' ' || *y == '\t') 4130 /* Copy whitespace to the result. */ 4131 *x++ = *y++; 4132 /* Don't copy other options. */ 4133 else 4134 y++; 4135 } 4136 4137 *x = 0; 4138 4139 value = do_spec_1 (buf, 0, NULL_PTR); 4140 if (value != 0) 4141 return value; 4142 } 4143 break; 4144 4145 case 'S': 4146 value = do_spec_1 (startfile_spec, 0, NULL_PTR); 4147 if (value != 0) 4148 return value; 4149 break; 4150 4151 /* Here we define characters other than letters and digits. */ 4152 4153 case '{': 4154 p = handle_braces (p); 4155 if (p == 0) 4156 return -1; 4157 break; 4158 4159 case '%': 4160 obstack_1grow (&obstack, '%'); 4161 break; 4162 4163 case '*': 4164 do_spec_1 (soft_matched_part, 1, NULL_PTR); 4165 do_spec_1 (" ", 0, NULL_PTR); 4166 break; 4167 4168 /* Process a string found as the value of a spec given by name. 4169 This feature allows individual machine descriptions 4170 to add and use their own specs. 4171 %[...] modifies -D options the way %P does; 4172 %(...) uses the spec unmodified. */ 4173 case '[': 4174 error ("Warning: use of obsolete %%[ operator in specs"); 4175 case '(': 4176 { 4177 const char *name = p; 4178 struct spec_list *sl; 4179 int len; 4180 4181 /* The string after the S/P is the name of a spec that is to be 4182 processed. */ 4183 while (*p && *p != ')' && *p != ']') 4184 p++; 4185 4186 /* See if it's in the list */ 4187 for (len = p - name, sl = specs; sl; sl = sl->next) 4188 if (sl->name_len == len && !strncmp (sl->name, name, len)) 4189 { 4190 name = *(sl->ptr_spec); 4191#ifdef DEBUG_SPECS 4192 notice ("Processing spec %c%s%c, which is '%s'\n", 4193 c, sl->name, (c == '(') ? ')' : ']', name); 4194#endif 4195 break; 4196 } 4197 4198 if (sl) 4199 { 4200 if (c == '(') 4201 { 4202 value = do_spec_1 (name, 0, NULL_PTR); 4203 if (value != 0) 4204 return value; 4205 } 4206 else 4207 { 4208 char *x = (char *) alloca (strlen (name) * 2 + 1); 4209 char *buf = x; 4210 const char *y = name; 4211 int flag = 0; 4212 4213 /* Copy all of NAME into BUF, but put __ after 4214 every -D and at the end of each arg, */ 4215 while (1) 4216 { 4217 if (! strncmp (y, "-D", 2)) 4218 { 4219 *x++ = '-'; 4220 *x++ = 'D'; 4221 *x++ = '_'; 4222 *x++ = '_'; 4223 y += 2; 4224 flag = 1; 4225 continue; 4226 } 4227 else if (flag && (*y == ' ' || *y == '\t' || *y == '=' 4228 || *y == '}' || *y == 0)) 4229 { 4230 *x++ = '_'; 4231 *x++ = '_'; 4232 flag = 0; 4233 } 4234 if (*y == 0) 4235 break; 4236 else 4237 *x++ = *y++; 4238 } 4239 *x = 0; 4240 4241 value = do_spec_1 (buf, 0, NULL_PTR); 4242 if (value != 0) 4243 return value; 4244 } 4245 } 4246 4247 /* Discard the closing paren or bracket. */ 4248 if (*p) 4249 p++; 4250 } 4251 break; 4252 4253 case 'v': 4254 { 4255 int c1 = *p++; /* Select first or second version number. */ 4256 char *v = compiler_version; 4257 char *q; 4258 4259 /* The format of the version string is 4260 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */ 4261 4262 /* Ignore leading non-digits. i.e. "foo-" in "foo-2.7.2". */ 4263 while (! ISDIGIT (*v)) 4264 v++; 4265 if (v > compiler_version && v[-1] != '-') 4266 abort (); 4267 4268 /* If desired, advance to second version number. */ 4269 if (c1 == '2') 4270 { 4271 /* Set V after the first period. */ 4272 while (ISDIGIT (*v)) 4273 v++; 4274 if (*v != '.') 4275 abort (); 4276 v++; 4277 } 4278 4279 /* Set Q at the next period or at the end. */ 4280 q = v; 4281 while (ISDIGIT (*q)) 4282 q++; 4283 if (*q != 0 && *q != ' ' && *q != '.' && *q != '-') 4284 abort (); 4285 4286 /* Put that part into the command. */ 4287 obstack_grow (&obstack, v, q - v); 4288 arg_going = 1; 4289 } 4290 break; 4291 4292 case '|': 4293 if (input_from_pipe) 4294 do_spec_1 ("-", 0, NULL_PTR); 4295 break; 4296 4297 default: 4298 abort (); 4299 } 4300 break; 4301 4302 case '\\': 4303 /* Backslash: treat next character as ordinary. */ 4304 c = *p++; 4305 4306 /* fall through */ 4307 default: 4308 /* Ordinary character: put it into the current argument. */ 4309 obstack_1grow (&obstack, c); 4310 arg_going = 1; 4311 } 4312 4313 return 0; /* End of string */ 4314} 4315 4316/* Return 0 if we call do_spec_1 and that returns -1. */ 4317 4318static const char * 4319handle_braces (p) 4320 register const char *p; 4321{ 4322 const char *filter, *body = NULL, *endbody = NULL; 4323 int pipe_p = 0; 4324 int negate; 4325 int suffix; 4326 int include_blanks = 1; 4327 4328 if (*p == '^') 4329 /* A '^' after the open-brace means to not give blanks before args. */ 4330 include_blanks = 0, ++p; 4331 4332 if (*p == '|') 4333 /* A `|' after the open-brace means, 4334 if the test fails, output a single minus sign rather than nothing. 4335 This is used in %{|!pipe:...}. */ 4336 pipe_p = 1, ++p; 4337 4338next_member: 4339 negate = suffix = 0; 4340 4341 if (*p == '!') 4342 /* A `!' after the open-brace negates the condition: 4343 succeed if the specified switch is not present. */ 4344 negate = 1, ++p; 4345 4346 if (*p == '.') 4347 /* A `.' after the open-brace means test against the current suffix. */ 4348 { 4349 if (pipe_p) 4350 abort (); 4351 4352 suffix = 1; 4353 ++p; 4354 } 4355 4356 filter = p; 4357 while (*p != ':' && *p != '}' && *p != '|') p++; 4358 4359 if (*p == '|' && pipe_p) 4360 abort (); 4361 4362 if (!body) 4363 { 4364 if (*p != '}') 4365 { 4366 register int count = 1; 4367 register const char *q = p; 4368 4369 while (*q++ != ':') continue; 4370 body = q; 4371 4372 while (count > 0) 4373 { 4374 if (*q == '{') 4375 count++; 4376 else if (*q == '}') 4377 count--; 4378 else if (*q == 0) 4379 abort (); 4380 q++; 4381 } 4382 endbody = q; 4383 } 4384 else 4385 body = p, endbody = p+1; 4386 } 4387 4388 if (suffix) 4389 { 4390 int found = (input_suffix != 0 4391 && (long) strlen (input_suffix) == (long)(p - filter) 4392 && strncmp (input_suffix, filter, p - filter) == 0); 4393 4394 if (body[0] == '}') 4395 abort (); 4396 4397 if (negate != found 4398 && do_spec_1 (save_string (body, endbody-body-1), 0, NULL_PTR) < 0) 4399 return 0; 4400 } 4401 else if (p[-1] == '*' && p[0] == '}') 4402 { 4403 /* Substitute all matching switches as separate args. */ 4404 register int i; 4405 --p; 4406 for (i = 0; i < n_switches; i++) 4407 if (!strncmp (switches[i].part1, filter, p - filter) 4408 && check_live_switch (i, p - filter)) 4409 give_switch (i, 0, include_blanks); 4410 } 4411 else 4412 { 4413 /* Test for presence of the specified switch. */ 4414 register int i; 4415 int present = 0; 4416 4417 /* If name specified ends in *, as in {x*:...}, 4418 check for %* and handle that case. */ 4419 if (p[-1] == '*' && !negate) 4420 { 4421 int substitution; 4422 const char *r = body; 4423 4424 /* First see whether we have %*. */ 4425 substitution = 0; 4426 while (r < endbody) 4427 { 4428 if (*r == '%' && r[1] == '*') 4429 substitution = 1; 4430 r++; 4431 } 4432 /* If we do, handle that case. */ 4433 if (substitution) 4434 { 4435 /* Substitute all matching switches as separate args. 4436 But do this by substituting for %* 4437 in the text that follows the colon. */ 4438 4439 unsigned hard_match_len = p - filter - 1; 4440 char *string = save_string (body, endbody - body - 1); 4441 4442 for (i = 0; i < n_switches; i++) 4443 if (!strncmp (switches[i].part1, filter, hard_match_len) 4444 && check_live_switch (i, -1)) 4445 { 4446 do_spec_1 (string, 0, &switches[i].part1[hard_match_len]); 4447 /* Pass any arguments this switch has. */ 4448 give_switch (i, 1, 1); 4449 } 4450 4451 /* We didn't match. Try again. */ 4452 if (*p++ == '|') 4453 goto next_member; 4454 return endbody; 4455 } 4456 } 4457 4458 /* If name specified ends in *, as in {x*:...}, 4459 check for presence of any switch name starting with x. */ 4460 if (p[-1] == '*') 4461 { 4462 for (i = 0; i < n_switches; i++) 4463 { 4464 unsigned hard_match_len = p - filter - 1; 4465 4466 if (!strncmp (switches[i].part1, filter, hard_match_len) 4467 && check_live_switch (i, hard_match_len)) 4468 { 4469 present = 1; 4470 } 4471 } 4472 } 4473 /* Otherwise, check for presence of exact name specified. */ 4474 else 4475 { 4476 for (i = 0; i < n_switches; i++) 4477 { 4478 if (!strncmp (switches[i].part1, filter, p - filter) 4479 && switches[i].part1[p - filter] == 0 4480 && check_live_switch (i, -1)) 4481 { 4482 present = 1; 4483 break; 4484 } 4485 } 4486 } 4487 4488 /* If it is as desired (present for %{s...}, absent for %{!s...}) 4489 then substitute either the switch or the specified 4490 conditional text. */ 4491 if (present != negate) 4492 { 4493 if (*p == '}') 4494 { 4495 give_switch (i, 0, include_blanks); 4496 } 4497 else 4498 { 4499 if (do_spec_1 (save_string (body, endbody - body - 1), 4500 0, NULL_PTR) < 0) 4501 return 0; 4502 } 4503 } 4504 else if (pipe_p) 4505 { 4506 /* Here if a %{|...} conditional fails: output a minus sign, 4507 which means "standard output" or "standard input". */ 4508 do_spec_1 ("-", 0, NULL_PTR); 4509 return endbody; 4510 } 4511 } 4512 4513 /* We didn't match; try again. */ 4514 if (*p++ == '|') 4515 goto next_member; 4516 4517 return endbody; 4518} 4519 4520/* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch 4521 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*} 4522 spec, or -1 if either exact match or %* is used. 4523 4524 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch 4525 whose value does not begin with "no-" is obsoleted by the same value 4526 with the "no-", similarly for a switch with the "no-" prefix. */ 4527 4528static int 4529check_live_switch (switchnum, prefix_length) 4530 int switchnum; 4531 int prefix_length; 4532{ 4533 const char *name = switches[switchnum].part1; 4534 int i; 4535 4536 /* In the common case of {<at-most-one-letter>*}, a negating 4537 switch would always match, so ignore that case. We will just 4538 send the conflicting switches to the compiler phase. */ 4539 if (prefix_length >= 0 && prefix_length <= 1) 4540 return 1; 4541 4542 /* If we already processed this switch and determined if it was 4543 live or not, return our past determination. */ 4544 if (switches[switchnum].live_cond != 0) 4545 return switches[switchnum].live_cond > 0; 4546 4547 /* Now search for duplicate in a manner that depends on the name. */ 4548 switch (*name) 4549 { 4550 case 'O': 4551 for (i = switchnum + 1; i < n_switches; i++) 4552 if (switches[i].part1[0] == 'O') 4553 { 4554 switches[switchnum].validated = 1; 4555 switches[switchnum].live_cond = -1; 4556 return 0; 4557 } 4558 break; 4559 4560 case 'W': case 'f': case 'm': 4561 if (! strncmp (name + 1, "no-", 3)) 4562 { 4563 /* We have Xno-YYY, search for XYYY. */ 4564 for (i = switchnum + 1; i < n_switches; i++) 4565 if (switches[i].part1[0] == name[0] 4566 && ! strcmp (&switches[i].part1[1], &name[4])) 4567 { 4568 switches[switchnum].validated = 1; 4569 switches[switchnum].live_cond = -1; 4570 return 0; 4571 } 4572 } 4573 else 4574 { 4575 /* We have XYYY, search for Xno-YYY. */ 4576 for (i = switchnum + 1; i < n_switches; i++) 4577 if (switches[i].part1[0] == name[0] 4578 && switches[i].part1[1] == 'n' 4579 && switches[i].part1[2] == 'o' 4580 && switches[i].part1[3] == '-' 4581 && !strcmp (&switches[i].part1[4], &name[1])) 4582 { 4583 switches[switchnum].validated = 1; 4584 switches[switchnum].live_cond = -1; 4585 return 0; 4586 } 4587 } 4588 break; 4589 } 4590 4591 /* Otherwise the switch is live. */ 4592 switches[switchnum].live_cond = 1; 4593 return 1; 4594} 4595 4596/* Pass a switch to the current accumulating command 4597 in the same form that we received it. 4598 SWITCHNUM identifies the switch; it is an index into 4599 the vector of switches gcc received, which is `switches'. 4600 This cannot fail since it never finishes a command line. 4601 4602 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. 4603 4604 If INCLUDE_BLANKS is nonzero, then we include blanks before each argument 4605 of the switch. */ 4606 4607static void 4608give_switch (switchnum, omit_first_word, include_blanks) 4609 int switchnum; 4610 int omit_first_word; 4611 int include_blanks; 4612{ 4613 if (!omit_first_word) 4614 { 4615 do_spec_1 ("-", 0, NULL_PTR); 4616 do_spec_1 (switches[switchnum].part1, 1, NULL_PTR); 4617 } 4618 4619 if (switches[switchnum].args != 0) 4620 { 4621 char **p; 4622 for (p = switches[switchnum].args; *p; p++) 4623 { 4624 if (include_blanks) 4625 do_spec_1 (" ", 0, NULL_PTR); 4626 do_spec_1 (*p, 1, NULL_PTR); 4627 } 4628 } 4629 4630 do_spec_1 (" ", 0, NULL_PTR); 4631 switches[switchnum].validated = 1; 4632} 4633 4634/* Search for a file named NAME trying various prefixes including the 4635 user's -B prefix and some standard ones. 4636 Return the absolute file name found. If nothing is found, return NAME. */ 4637 4638static const char * 4639find_file (name) 4640 const char *name; 4641{ 4642 char *newname; 4643 4644 /* Try multilib_dir if it is defined. */ 4645 if (multilib_dir != NULL) 4646 { 4647 char *try; 4648 4649 try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2); 4650 strcpy (try, multilib_dir); 4651 strcat (try, dir_separator_str); 4652 strcat (try, name); 4653 4654 newname = find_a_file (&startfile_prefixes, try, R_OK); 4655 4656 /* If we don't find it in the multi library dir, then fall 4657 through and look for it in the normal places. */ 4658 if (newname != NULL) 4659 return newname; 4660 } 4661 4662 newname = find_a_file (&startfile_prefixes, name, R_OK); 4663 return newname ? newname : name; 4664} 4665 4666/* Determine whether a directory exists. If LINKER, return 0 for 4667 certain fixed names not needed by the linker. If not LINKER, it is 4668 only important to return 0 if the host machine has a small ARG_MAX 4669 limit. */ 4670 4671static int 4672is_directory (path1, path2, linker) 4673 const char *path1; 4674 const char *path2; 4675 int linker; 4676{ 4677 int len1 = strlen (path1); 4678 int len2 = strlen (path2); 4679 char *path = (char *) alloca (3 + len1 + len2); 4680 char *cp; 4681 struct stat st; 4682 4683#ifndef SMALL_ARG_MAX 4684 if (! linker) 4685 return 1; 4686#endif 4687 4688 /* Construct the path from the two parts. Ensure the string ends with "/.". 4689 The resulting path will be a directory even if the given path is a 4690 symbolic link. */ 4691 memcpy (path, path1, len1); 4692 memcpy (path + len1, path2, len2); 4693 cp = path + len1 + len2; 4694 if (!IS_DIR_SEPARATOR (cp[-1])) 4695 *cp++ = DIR_SEPARATOR; 4696 *cp++ = '.'; 4697 *cp = '\0'; 4698 4699 /* Exclude directories that the linker is known to search. */ 4700 if (linker 4701 && ((cp - path == 6 4702 && strcmp (path, concat (dir_separator_str, "lib", 4703 dir_separator_str, ".", NULL_PTR)) == 0) 4704 || (cp - path == 10 4705 && strcmp (path, concat (dir_separator_str, "usr", 4706 dir_separator_str, "lib", 4707 dir_separator_str, ".", NULL_PTR)) == 0))) 4708 return 0; 4709 4710 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); 4711} 4712 4713/* On fatal signals, delete all the temporary files. */ 4714 4715static void 4716fatal_error (signum) 4717 int signum; 4718{ 4719 signal (signum, SIG_DFL); 4720 delete_failure_queue (); 4721 delete_temp_files (); 4722 /* Get the same signal again, this time not handled, 4723 so its normal effect occurs. */ 4724 kill (getpid (), signum); 4725} 4726 4727int 4728main (argc, argv) 4729 int argc; 4730 char **argv; 4731{ 4732 register size_t i; 4733 size_t j; 4734 int value; 4735 int linker_was_run = 0; 4736 char *explicit_link_files; 4737 char *specs_file; 4738 const char *p; 4739 struct user_specs *uptr; 4740 4741 p = argv[0] + strlen (argv[0]); 4742 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) 4743 --p; 4744 programname = p; 4745 4746#ifdef HAVE_LC_MESSAGES 4747 setlocale (LC_MESSAGES, ""); 4748#endif 4749 (void) bindtextdomain (PACKAGE, localedir); 4750 (void) textdomain (PACKAGE); 4751 4752 if (signal (SIGINT, SIG_IGN) != SIG_IGN) 4753 signal (SIGINT, fatal_error); 4754#ifdef SIGHUP 4755 if (signal (SIGHUP, SIG_IGN) != SIG_IGN) 4756 signal (SIGHUP, fatal_error); 4757#endif 4758 if (signal (SIGTERM, SIG_IGN) != SIG_IGN) 4759 signal (SIGTERM, fatal_error); 4760#ifdef SIGPIPE 4761 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) 4762 signal (SIGPIPE, fatal_error); 4763#endif 4764 4765 argbuf_length = 10; 4766 argbuf = (char **) xmalloc (argbuf_length * sizeof (char *)); 4767 4768 obstack_init (&obstack); 4769 4770 /* Build multilib_select, et. al from the separate lines that make up each 4771 multilib selection. */ 4772 { 4773 char **q = multilib_raw; 4774 int need_space; 4775 4776 obstack_init (&multilib_obstack); 4777 while ((p = *q++) != (char *) 0) 4778 obstack_grow (&multilib_obstack, p, strlen (p)); 4779 4780 obstack_1grow (&multilib_obstack, 0); 4781 multilib_select = obstack_finish (&multilib_obstack); 4782 4783 q = multilib_matches_raw; 4784 while ((p = *q++) != (char *) 0) 4785 obstack_grow (&multilib_obstack, p, strlen (p)); 4786 4787 obstack_1grow (&multilib_obstack, 0); 4788 multilib_matches = obstack_finish (&multilib_obstack); 4789 4790 need_space = FALSE; 4791 for (i = 0; 4792 i < sizeof (multilib_defaults_raw) / sizeof (multilib_defaults_raw[0]); 4793 i++) 4794 { 4795 if (need_space) 4796 obstack_1grow (&multilib_obstack, ' '); 4797 obstack_grow (&multilib_obstack, 4798 multilib_defaults_raw[i], 4799 strlen (multilib_defaults_raw[i])); 4800 need_space = TRUE; 4801 } 4802 4803 obstack_1grow (&multilib_obstack, 0); 4804 multilib_defaults = obstack_finish (&multilib_obstack); 4805 } 4806 4807 /* Set up to remember the pathname of gcc and any options 4808 needed for collect. We use argv[0] instead of programname because 4809 we need the complete pathname. */ 4810 obstack_init (&collect_obstack); 4811 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1); 4812 obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1); 4813 putenv (obstack_finish (&collect_obstack)); 4814 4815#ifdef INIT_ENVIRONMENT 4816 /* Set up any other necessary machine specific environment variables. */ 4817 putenv (INIT_ENVIRONMENT); 4818#endif 4819 4820 /* Choose directory for temp files. */ 4821 4822#ifndef MKTEMP_EACH_FILE 4823 temp_filename = choose_temp_base (); 4824 temp_filename_length = strlen (temp_filename); 4825#endif 4826 4827 /* Make a table of what switches there are (switches, n_switches). 4828 Make a table of specified input files (infiles, n_infiles). 4829 Decode switches that are handled locally. */ 4830 4831 process_command (argc, argv); 4832 4833 { 4834 int first_time; 4835 4836 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to 4837 the compiler. */ 4838 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=", 4839 sizeof ("COLLECT_GCC_OPTIONS=")-1); 4840 4841 first_time = TRUE; 4842 for (i = 0; (int)i < n_switches; i++) 4843 { 4844 char **args; 4845 const char *p, *q; 4846 if (!first_time) 4847 obstack_grow (&collect_obstack, " ", 1); 4848 4849 first_time = FALSE; 4850 obstack_grow (&collect_obstack, "'-", 2); 4851 q = switches[i].part1; 4852 while ((p = index (q,'\''))) 4853 { 4854 obstack_grow (&collect_obstack, q, p-q); 4855 obstack_grow (&collect_obstack, "'\\''", 4); 4856 q = ++p; 4857 } 4858 obstack_grow (&collect_obstack, q, strlen (q)); 4859 obstack_grow (&collect_obstack, "'", 1); 4860 4861 for (args = switches[i].args; args && *args; args++) 4862 { 4863 obstack_grow (&collect_obstack, " '", 2); 4864 q = *args; 4865 while ((p = index (q,'\''))) 4866 { 4867 obstack_grow (&collect_obstack, q, p-q); 4868 obstack_grow (&collect_obstack, "'\\''", 4); 4869 q = ++p; 4870 } 4871 obstack_grow (&collect_obstack, q, strlen (q)); 4872 obstack_grow (&collect_obstack, "'", 1); 4873 } 4874 } 4875 obstack_grow (&collect_obstack, "\0", 1); 4876 putenv (obstack_finish (&collect_obstack)); 4877 } 4878 4879 /* Initialize the vector of specs to just the default. 4880 This means one element containing 0s, as a terminator. */ 4881 4882 compilers = (struct compiler *) xmalloc (sizeof default_compilers); 4883 bcopy ((char *) default_compilers, (char *) compilers, 4884 sizeof default_compilers); 4885 n_compilers = n_default_compilers; 4886 4887 /* Read specs from a file if there is one. */ 4888 4889 machine_suffix = concat (spec_machine, dir_separator_str, 4890 spec_version, dir_separator_str, NULL_PTR); 4891 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL_PTR); 4892 4893 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK); 4894 /* Read the specs file unless it is a default one. */ 4895 if (specs_file != 0 && strcmp (specs_file, "specs")) 4896 read_specs (specs_file, TRUE); 4897 else 4898 init_spec (); 4899 4900 /* We need to check standard_exec_prefix/just_machine_suffix/specs 4901 for any override of as, ld and libraries. */ 4902 specs_file = (char *) alloca (strlen (standard_exec_prefix) 4903 + strlen (just_machine_suffix) 4904 + sizeof ("specs")); 4905 4906 strcpy (specs_file, standard_exec_prefix); 4907 strcat (specs_file, just_machine_suffix); 4908 strcat (specs_file, "specs"); 4909 if (access (specs_file, R_OK) == 0) 4910 read_specs (specs_file, TRUE); 4911 4912 /* If not cross-compiling, look for startfiles in the standard places. */ 4913 if (*cross_compile == '0') 4914 { 4915#ifdef MD_EXEC_PREFIX 4916 add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR); 4917 add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR); 4918#endif 4919 4920#ifdef MD_STARTFILE_PREFIX 4921 add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC", 4922 0, 0, NULL_PTR); 4923#endif 4924 4925#ifdef MD_STARTFILE_PREFIX_1 4926 add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC", 4927 0, 0, NULL_PTR); 4928#endif 4929 4930 /* If standard_startfile_prefix is relative, base it on 4931 standard_exec_prefix. This lets us move the installed tree 4932 as a unit. If GCC_EXEC_PREFIX is defined, base 4933 standard_startfile_prefix on that as well. */ 4934 if (IS_DIR_SEPARATOR (*standard_startfile_prefix) 4935 || *standard_startfile_prefix == '$' 4936#ifdef HAVE_DOS_BASED_FILESYSTEM 4937 /* Check for disk name on MS-DOS-based systems. */ 4938 || (standard_startfile_prefix[1] == ':' 4939 && (IS_DIR_SEPARATOR (standard_startfile_prefix[2]))) 4940#endif 4941 ) 4942 add_prefix (&startfile_prefixes, standard_startfile_prefix, "BINUTILS", 4943 0, 0, NULL_PTR); 4944 else 4945 { 4946 if (gcc_exec_prefix) 4947 add_prefix (&startfile_prefixes, 4948 concat (gcc_exec_prefix, machine_suffix, 4949 standard_startfile_prefix, NULL_PTR), 4950 NULL_PTR, 0, 0, NULL_PTR); 4951 add_prefix (&startfile_prefixes, 4952 concat (standard_exec_prefix, 4953 machine_suffix, 4954 standard_startfile_prefix, NULL_PTR), 4955 NULL_PTR, 0, 0, NULL_PTR); 4956 } 4957 4958 add_prefix (&startfile_prefixes, standard_startfile_prefix_1, 4959 "BINUTILS", 0, 0, NULL_PTR); 4960 add_prefix (&startfile_prefixes, standard_startfile_prefix_2, 4961 "BINUTILS", 0, 0, NULL_PTR); 4962#if 0 /* Can cause surprises, and one can use -B./ instead. */ 4963 add_prefix (&startfile_prefixes, "./", NULL_PTR, 0, 1, NULL_PTR); 4964#endif 4965 } 4966 else 4967 { 4968 if (!IS_DIR_SEPARATOR (*standard_startfile_prefix) && gcc_exec_prefix) 4969 add_prefix (&startfile_prefixes, 4970 concat (gcc_exec_prefix, machine_suffix, 4971 standard_startfile_prefix, NULL_PTR), 4972 "BINUTILS", 0, 0, NULL_PTR); 4973 } 4974 4975 /* Process any user specified specs in the order given on the command 4976 line. */ 4977 for (uptr = user_specs_head; uptr; uptr = uptr->next) 4978 { 4979 char *filename = find_a_file (&startfile_prefixes, uptr->filename, R_OK); 4980 read_specs (filename ? filename : uptr->filename, FALSE); 4981 } 4982 4983 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */ 4984 if (gcc_exec_prefix) 4985 { 4986 char * temp = (char *) xmalloc (strlen (gcc_exec_prefix) 4987 + strlen (spec_version) 4988 + strlen (spec_machine) + 3); 4989 strcpy (temp, gcc_exec_prefix); 4990 strcat (temp, spec_machine); 4991 strcat (temp, dir_separator_str); 4992 strcat (temp, spec_version); 4993 strcat (temp, dir_separator_str); 4994 gcc_exec_prefix = temp; 4995 } 4996 4997 /* Now we have the specs. 4998 Set the `valid' bits for switches that match anything in any spec. */ 4999 5000 validate_all_switches (); 5001 5002 /* Now that we have the switches and the specs, set 5003 the subdirectory based on the options. */ 5004 set_multilib_dir (); 5005 5006 /* Warn about any switches that no pass was interested in. */ 5007 5008 for (i = 0; (int)i < n_switches; i++) 5009 if (! switches[i].validated) 5010 error ("unrecognized option `-%s'", switches[i].part1); 5011 5012 /* Obey some of the options. */ 5013 5014 if (print_search_dirs) 5015 { 5016 printf ("install: %s%s\n", standard_exec_prefix, machine_suffix); 5017 printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0)); 5018 printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0)); 5019 exit (0); 5020 } 5021 5022 if (print_file_name) 5023 { 5024 printf ("%s\n", find_file (print_file_name)); 5025 exit (0); 5026 } 5027 5028 if (print_prog_name) 5029 { 5030 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK); 5031 printf ("%s\n", (newname ? newname : print_prog_name)); 5032 exit (0); 5033 } 5034 5035 if (print_multi_lib) 5036 { 5037 print_multilib_info (); 5038 exit (0); 5039 } 5040 5041 if (print_multi_directory) 5042 { 5043 if (multilib_dir == NULL) 5044 printf (".\n"); 5045 else 5046 printf ("%s\n", multilib_dir); 5047 exit (0); 5048 } 5049 5050 if (print_help_list) 5051 { 5052 display_help (); 5053 5054 if (! verbose_flag) 5055 { 5056 printf ("\nFor bug reporting instructions, please see:\n"); 5057 printf ("%s.\n", GCCBUGURL); 5058 5059 exit (0); 5060 } 5061 5062 /* We do not exit here. Instead we have created a fake input file 5063 called 'help-dummy' which needs to be compiled, and we pass this 5064 on the the various sub-processes, along with the --help switch. */ 5065 } 5066 5067 if (verbose_flag) 5068 { 5069 int n; 5070 5071 /* compiler_version is truncated at the first space when initialized 5072 from version string, so truncate version_string at the first space 5073 before comparing. */ 5074 for (n = 0; version_string[n]; n++) 5075 if (version_string[n] == ' ') 5076 break; 5077 5078 if (! strncmp (version_string, compiler_version, n) 5079 && compiler_version[n] == 0) 5080 notice ("gcc version %s\n", version_string); 5081 else 5082 notice ("gcc driver version %s executing gcc version %s\n", 5083 version_string, compiler_version); 5084 5085 if (n_infiles == 0) 5086 exit (0); 5087 } 5088 5089 if (n_infiles == added_libraries) 5090 fatal ("No input files"); 5091 5092 /* Make a place to record the compiler output file names 5093 that correspond to the input files. */ 5094 5095 i = n_infiles; 5096 i += lang_specific_extra_outfiles; 5097 outfiles = (const char **) xmalloc (i * sizeof (char *)); 5098 bzero ((char *) outfiles, i * sizeof (char *)); 5099 5100 /* Record which files were specified explicitly as link input. */ 5101 5102 explicit_link_files = xmalloc (n_infiles); 5103 bzero (explicit_link_files, n_infiles); 5104 5105 for (i = 0; (int)i < n_infiles; i++) 5106 { 5107 register struct compiler *cp = 0; 5108 int this_file_error = 0; 5109 5110 /* Tell do_spec what to substitute for %i. */ 5111 5112 input_filename = infiles[i].name; 5113 input_filename_length = strlen (input_filename); 5114 input_file_number = i; 5115 5116 /* Use the same thing in %o, unless cp->spec says otherwise. */ 5117 5118 outfiles[i] = input_filename; 5119 5120 /* Figure out which compiler from the file's suffix. */ 5121 5122 cp = lookup_compiler (infiles[i].name, input_filename_length, 5123 infiles[i].language); 5124 5125 if (cp) 5126 { 5127 /* Ok, we found an applicable compiler. Run its spec. */ 5128 /* First say how much of input_filename to substitute for %b */ 5129 register const char *p; 5130 int len; 5131 5132 if (cp->spec[0][0] == '#') 5133 { 5134 error ("%s: %s compiler not installed on this system", 5135 input_filename, &cp->spec[0][1]); 5136 this_file_error = 1; 5137 } 5138 else 5139 { 5140 input_basename = input_filename; 5141 for (p = input_filename; *p; p++) 5142 if (IS_DIR_SEPARATOR (*p)) 5143 input_basename = p + 1; 5144 5145 /* Find a suffix starting with the last period, 5146 and set basename_length to exclude that suffix. */ 5147 basename_length = strlen (input_basename); 5148 p = input_basename + basename_length; 5149 while (p != input_basename && *p != '.') --p; 5150 if (*p == '.' && p != input_basename) 5151 { 5152 basename_length = p - input_basename; 5153 input_suffix = p + 1; 5154 } 5155 else 5156 input_suffix = ""; 5157 5158 len = 0; 5159 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++) 5160 if (cp->spec[j]) 5161 len += strlen (cp->spec[j]); 5162 5163 { 5164 char *p1 = (char *) xmalloc (len + 1); 5165 5166 len = 0; 5167 for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++) 5168 if (cp->spec[j]) 5169 { 5170 strcpy (p1 + len, cp->spec[j]); 5171 len += strlen (cp->spec[j]); 5172 } 5173 5174 value = do_spec (p1); 5175 free (p1); 5176 } 5177 if (value < 0) 5178 this_file_error = 1; 5179 } 5180 } 5181 5182 /* If this file's name does not contain a recognized suffix, 5183 record it as explicit linker input. */ 5184 5185 else 5186 explicit_link_files[i] = 1; 5187 5188 /* Clear the delete-on-failure queue, deleting the files in it 5189 if this compilation failed. */ 5190 5191 if (this_file_error) 5192 { 5193 delete_failure_queue (); 5194 error_count++; 5195 } 5196 /* If this compilation succeeded, don't delete those files later. */ 5197 clear_failure_queue (); 5198 } 5199 5200 if (error_count == 0) 5201 { 5202 /* Make sure INPUT_FILE_NUMBER points to first available open 5203 slot. */ 5204 input_file_number = n_infiles; 5205 if (lang_specific_pre_link ()) 5206 error_count++; 5207 } 5208 5209 /* Run ld to link all the compiler output files. */ 5210 5211 if (error_count == 0) 5212 { 5213 int tmp = execution_count; 5214 5215 /* We'll use ld if we can't find collect2. */ 5216 if (! strcmp (linker_name_spec, "collect2")) 5217 { 5218 char *s = find_a_file (&exec_prefixes, "collect2", X_OK); 5219 if (s == NULL) 5220 linker_name_spec = "ld"; 5221 } 5222 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables 5223 for collect. */ 5224 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH="); 5225 putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV "="); 5226 5227 value = do_spec (link_command_spec); 5228 if (value < 0) 5229 error_count = 1; 5230 linker_was_run = (tmp != execution_count); 5231 } 5232 5233 /* Warn if a -B option was specified but the prefix was never used. */ 5234 unused_prefix_warnings (&exec_prefixes); 5235 unused_prefix_warnings (&startfile_prefixes); 5236 5237 /* If options said don't run linker, 5238 complain about input files to be given to the linker. */ 5239 5240 if (! linker_was_run && error_count == 0) 5241 for (i = 0; (int)i < n_infiles; i++) 5242 if (explicit_link_files[i]) 5243 error ("%s: linker input file unused since linking not done", 5244 outfiles[i]); 5245 5246 /* Delete some or all of the temporary files we made. */ 5247 5248 if (error_count) 5249 delete_failure_queue (); 5250 delete_temp_files (); 5251 5252 if (print_help_list) 5253 { 5254 printf ("\nFor bug reporting instructions, please see:\n"); 5255 printf ("%s\n", GCCBUGURL); 5256 } 5257 5258 exit (error_count > 0 ? (signal_count ? 2 : 1) : 0); 5259 /* NOTREACHED */ 5260 return 0; 5261} 5262 5263/* Find the proper compilation spec for the file name NAME, 5264 whose length is LENGTH. LANGUAGE is the specified language, 5265 or 0 if this file is to be passed to the linker. */ 5266 5267static struct compiler * 5268lookup_compiler (name, length, language) 5269 const char *name; 5270 size_t length; 5271 const char *language; 5272{ 5273 struct compiler *cp; 5274 5275 /* If this was specified by the user to be a linker input, indicate that. */ 5276 if (language != 0 && language[0] == '*') 5277 return 0; 5278 5279 /* Otherwise, look for the language, if one is spec'd. */ 5280 if (language != 0) 5281 { 5282 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) 5283 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language)) 5284 return cp; 5285 5286 error ("language %s not recognized", language); 5287 return 0; 5288 } 5289 5290 /* Look for a suffix. */ 5291 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) 5292 { 5293 if (/* The suffix `-' matches only the file name `-'. */ 5294 (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) 5295 || (strlen (cp->suffix) < length 5296 /* See if the suffix matches the end of NAME. */ 5297#ifdef OS2 5298 && ((!strcmp (cp->suffix, 5299 name + length - strlen (cp->suffix)) 5300 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) 5301 && !strcasecmp (cp->suffix, 5302 name + length - strlen (cp->suffix))) 5303#else 5304 && !strcmp (cp->suffix, 5305 name + length - strlen (cp->suffix)) 5306#endif 5307 )) 5308 { 5309 if (cp->spec[0][0] == '@') 5310 { 5311 struct compiler *new; 5312 5313 /* An alias entry maps a suffix to a language. 5314 Search for the language; pass 0 for NAME and LENGTH 5315 to avoid infinite recursion if language not found. 5316 Construct the new compiler spec. */ 5317 language = cp->spec[0] + 1; 5318 new = (struct compiler *) xmalloc (sizeof (struct compiler)); 5319 new->suffix = cp->suffix; 5320 bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec, 5321 (char *) new->spec, sizeof new->spec); 5322 return new; 5323 } 5324 5325 /* A non-alias entry: return it. */ 5326 return cp; 5327 } 5328 } 5329 5330 return 0; 5331} 5332 5333PTR 5334xmalloc (size) 5335 size_t size; 5336{ 5337 register PTR value = (PTR) malloc (size); 5338 if (value == 0) 5339 fatal ("virtual memory exhausted"); 5340 return value; 5341} 5342 5343PTR 5344xrealloc (old, size) 5345 PTR old; 5346 size_t size; 5347{ 5348 register PTR ptr; 5349 if (old) 5350 ptr = (PTR) realloc (old, size); 5351 else 5352 ptr = (PTR) malloc (size); 5353 if (ptr == 0) 5354 fatal ("virtual memory exhausted"); 5355 return ptr; 5356} 5357 5358static char * 5359save_string (s, len) 5360 const char *s; 5361 int len; 5362{ 5363 register char *result = xmalloc (len + 1); 5364 5365 bcopy (s, result, len); 5366 result[len] = 0; 5367 return result; 5368} 5369 5370static void 5371pfatal_with_name (name) 5372 const char *name; 5373{ 5374 perror_with_name (name); 5375 delete_temp_files (); 5376 exit (1); 5377} 5378 5379static void 5380perror_with_name (name) 5381 const char *name; 5382{ 5383 error ("%s: %s", name, xstrerror (errno)); 5384} 5385 5386static void 5387pfatal_pexecute (errmsg_fmt, errmsg_arg) 5388 const char *errmsg_fmt; 5389 const char *errmsg_arg; 5390{ 5391 if (errmsg_arg) 5392 { 5393 int save_errno = errno; 5394 5395 /* Space for trailing '\0' is in %s. */ 5396 char *msg = xmalloc (strlen (errmsg_fmt) + strlen (errmsg_arg)); 5397 sprintf (msg, errmsg_fmt, errmsg_arg); 5398 errmsg_fmt = msg; 5399 5400 errno = save_errno; 5401 } 5402 5403 pfatal_with_name (errmsg_fmt); 5404} 5405 5406/* More 'friendly' abort that prints the line and file. 5407 config.h can #define abort fancy_abort if you like that sort of thing. */ 5408 5409void 5410fancy_abort () 5411{ 5412 fatal ("Internal gcc abort."); 5413} 5414 5415/* Output an error message and exit */ 5416 5417void 5418fatal VPROTO((const char *msgid, ...)) 5419{ 5420#ifndef ANSI_PROTOTYPES 5421 const char *msgid; 5422#endif 5423 va_list ap; 5424 5425 VA_START (ap, msgid); 5426 5427#ifndef ANSI_PROTOTYPES 5428 msgid = va_arg (ap, const char *); 5429#endif 5430 5431 fprintf (stderr, "%s: ", programname); 5432 vfprintf (stderr, _(msgid), ap); 5433 va_end (ap); 5434 fprintf (stderr, "\n"); 5435 delete_temp_files (); 5436 exit (1); 5437} 5438 5439static void 5440error VPROTO((const char *msgid, ...)) 5441{ 5442#ifndef ANSI_PROTOTYPES 5443 const char *msgid; 5444#endif 5445 va_list ap; 5446 5447 VA_START (ap, msgid); 5448 5449#ifndef ANSI_PROTOTYPES 5450 msgid = va_arg (ap, const char *); 5451#endif 5452 5453 fprintf (stderr, "%s: ", programname); 5454 vfprintf (stderr, _(msgid), ap); 5455 va_end (ap); 5456 5457 fprintf (stderr, "\n"); 5458} 5459 5460static void 5461notice VPROTO((const char *msgid, ...)) 5462{ 5463#ifndef ANSI_PROTOTYPES 5464 const char *msgid; 5465#endif 5466 va_list ap; 5467 5468 VA_START (ap, msgid); 5469 5470#ifndef ANSI_PROTOTYPES 5471 msgid = va_arg (ap, const char *); 5472#endif 5473 5474 vfprintf (stderr, _(msgid), ap); 5475 va_end (ap); 5476} 5477 5478 5479static void 5480validate_all_switches () 5481{ 5482 struct compiler *comp; 5483 register const char *p; 5484 register char c; 5485 struct spec_list *spec; 5486 5487 for (comp = compilers; comp->spec[0]; comp++) 5488 { 5489 size_t i; 5490 for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++) 5491 { 5492 p = comp->spec[i]; 5493 while ((c = *p++)) 5494 if (c == '%' && *p == '{') 5495 /* We have a switch spec. */ 5496 validate_switches (p + 1); 5497 } 5498 } 5499 5500 /* look through the linked list of specs read from the specs file */ 5501 for (spec = specs; spec ; spec = spec->next) 5502 { 5503 p = *(spec->ptr_spec); 5504 while ((c = *p++)) 5505 if (c == '%' && *p == '{') 5506 /* We have a switch spec. */ 5507 validate_switches (p + 1); 5508 } 5509 5510 p = link_command_spec; 5511 while ((c = *p++)) 5512 if (c == '%' && *p == '{') 5513 /* We have a switch spec. */ 5514 validate_switches (p + 1); 5515} 5516 5517/* Look at the switch-name that comes after START 5518 and mark as valid all supplied switches that match it. */ 5519 5520static void 5521validate_switches (start) 5522 const char *start; 5523{ 5524 register const char *p = start; 5525 const char *filter; 5526 register int i; 5527 int suffix = 0; 5528 5529 if (*p == '|') 5530 ++p; 5531 5532 if (*p == '!') 5533 ++p; 5534 5535 if (*p == '.') 5536 suffix = 1, ++p; 5537 5538 filter = p; 5539 while (*p != ':' && *p != '}') p++; 5540 5541 if (suffix) 5542 ; 5543 else if (p[-1] == '*') 5544 { 5545 /* Mark all matching switches as valid. */ 5546 --p; 5547 for (i = 0; i < n_switches; i++) 5548 if (!strncmp (switches[i].part1, filter, p - filter)) 5549 switches[i].validated = 1; 5550 } 5551 else 5552 { 5553 /* Mark an exact matching switch as valid. */ 5554 for (i = 0; i < n_switches; i++) 5555 { 5556 if (!strncmp (switches[i].part1, filter, p - filter) 5557 && switches[i].part1[p - filter] == 0) 5558 switches[i].validated = 1; 5559 } 5560 } 5561} 5562 5563/* Check whether a particular argument was used. The first time we 5564 canonicalize the switches to keep only the ones we care about. */ 5565 5566static int 5567used_arg (p, len) 5568 const char *p; 5569 int len; 5570{ 5571 struct mswitchstr { 5572 char *str; 5573 char *replace; 5574 int len; 5575 int rep_len; 5576 }; 5577 5578 static struct mswitchstr *mswitches; 5579 static int n_mswitches; 5580 int i, j; 5581 5582 if (!mswitches) 5583 { 5584 struct mswitchstr *matches; 5585 char *q; 5586 int cnt = 0; 5587 5588 /* Break multilib_matches into the component strings of string and replacement 5589 string */ 5590 for (q = multilib_matches; *q != '\0'; q++) 5591 if (*q == ';') 5592 cnt++; 5593 5594 matches = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt); 5595 i = 0; 5596 q = multilib_matches; 5597 while (*q != '\0') 5598 { 5599 matches[i].str = q; 5600 while (*q != ' ') 5601 { 5602 if (*q == '\0') 5603 abort (); 5604 q++; 5605 } 5606 *q = '\0'; 5607 matches[i].len = q - matches[i].str; 5608 5609 matches[i].replace = ++q; 5610 while (*q != ';' && *q != '\0') 5611 { 5612 if (*q == ' ') 5613 abort (); 5614 q++; 5615 } 5616 matches[i].rep_len = q - matches[i].replace; 5617 i++; 5618 if (*q == ';') 5619 *q++ = '\0'; 5620 else 5621 break; 5622 } 5623 5624 /* Now build a list of the replacement string for switches that we care 5625 about. Make sure we allocate at least one entry. This prevents 5626 xmalloc from calling fatal, and prevents us from re-executing this 5627 block of code. */ 5628 mswitches 5629 = (struct mswitchstr *) xmalloc ((sizeof (struct mswitchstr)) 5630 * (n_switches ? n_switches : 1)); 5631 for (i = 0; i < n_switches; i++) 5632 { 5633 int xlen = strlen (switches[i].part1); 5634 for (j = 0; j < cnt; j++) 5635 if (xlen == matches[j].len && ! strcmp (switches[i].part1, matches[j].str)) 5636 { 5637 mswitches[n_mswitches].str = matches[j].replace; 5638 mswitches[n_mswitches].len = matches[j].rep_len; 5639 mswitches[n_mswitches].replace = (char *)0; 5640 mswitches[n_mswitches].rep_len = 0; 5641 n_mswitches++; 5642 break; 5643 } 5644 } 5645 } 5646 5647 for (i = 0; i < n_mswitches; i++) 5648 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len)) 5649 return 1; 5650 5651 return 0; 5652} 5653 5654static int 5655default_arg (p, len) 5656 const char *p; 5657 int len; 5658{ 5659 char *start, *end; 5660 5661 for (start = multilib_defaults; *start != '\0'; start = end+1) 5662 { 5663 while (*start == ' ' || *start == '\t') 5664 start++; 5665 5666 if (*start == '\0') 5667 break; 5668 5669 for (end = start+1; *end != ' ' && *end != '\t' && *end != '\0'; end++) 5670 ; 5671 5672 if ((end - start) == len && strncmp (p, start, len) == 0) 5673 return 1; 5674 5675 if (*end == '\0') 5676 break; 5677 } 5678 5679 return 0; 5680} 5681 5682/* Work out the subdirectory to use based on the 5683 options. The format of multilib_select is a list of elements. 5684 Each element is a subdirectory name followed by a list of options 5685 followed by a semicolon. gcc will consider each line in turn. If 5686 none of the options beginning with an exclamation point are 5687 present, and all of the other options are present, that 5688 subdirectory will be used. */ 5689 5690static void 5691set_multilib_dir () 5692{ 5693 char *p = multilib_select; 5694 int this_path_len; 5695 char *this_path, *this_arg; 5696 int not_arg; 5697 int ok; 5698 5699 while (*p != '\0') 5700 { 5701 /* Ignore newlines. */ 5702 if (*p == '\n') 5703 { 5704 ++p; 5705 continue; 5706 } 5707 5708 /* Get the initial path. */ 5709 this_path = p; 5710 while (*p != ' ') 5711 { 5712 if (*p == '\0') 5713 abort (); 5714 ++p; 5715 } 5716 this_path_len = p - this_path; 5717 5718 /* Check the arguments. */ 5719 ok = 1; 5720 ++p; 5721 while (*p != ';') 5722 { 5723 if (*p == '\0') 5724 abort (); 5725 5726 if (! ok) 5727 { 5728 ++p; 5729 continue; 5730 } 5731 5732 this_arg = p; 5733 while (*p != ' ' && *p != ';') 5734 { 5735 if (*p == '\0') 5736 abort (); 5737 ++p; 5738 } 5739 5740 if (*this_arg != '!') 5741 not_arg = 0; 5742 else 5743 { 5744 not_arg = 1; 5745 ++this_arg; 5746 } 5747 5748 /* If this is a default argument, we can just ignore it. 5749 This is true even if this_arg begins with '!'. Beginning 5750 with '!' does not mean that this argument is necessarily 5751 inappropriate for this library: it merely means that 5752 there is a more specific library which uses this 5753 argument. If this argument is a default, we need not 5754 consider that more specific library. */ 5755 if (! default_arg (this_arg, p - this_arg)) 5756 { 5757 ok = used_arg (this_arg, p - this_arg); 5758 if (not_arg) 5759 ok = ! ok; 5760 } 5761 5762 if (*p == ' ') 5763 ++p; 5764 } 5765 5766 if (ok) 5767 { 5768 if (this_path_len != 1 5769 || this_path[0] != '.') 5770 { 5771 char * new_multilib_dir = xmalloc (this_path_len + 1); 5772 strncpy (new_multilib_dir, this_path, this_path_len); 5773 new_multilib_dir[this_path_len] = '\0'; 5774 multilib_dir = new_multilib_dir; 5775 } 5776 break; 5777 } 5778 5779 ++p; 5780 } 5781} 5782 5783/* Print out the multiple library subdirectory selection 5784 information. This prints out a series of lines. Each line looks 5785 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is 5786 required. Only the desired options are printed out, the negative 5787 matches. The options are print without a leading dash. There are 5788 no spaces to make it easy to use the information in the shell. 5789 Each subdirectory is printed only once. This assumes the ordering 5790 generated by the genmultilib script. */ 5791 5792static void 5793print_multilib_info () 5794{ 5795 char *p = multilib_select; 5796 char *last_path = 0, *this_path; 5797 int skip; 5798 int last_path_len = 0; 5799 5800 while (*p != '\0') 5801 { 5802 /* Ignore newlines. */ 5803 if (*p == '\n') 5804 { 5805 ++p; 5806 continue; 5807 } 5808 5809 /* Get the initial path. */ 5810 this_path = p; 5811 while (*p != ' ') 5812 { 5813 if (*p == '\0') 5814 abort (); 5815 ++p; 5816 } 5817 5818 /* If this is a duplicate, skip it. */ 5819 skip = (last_path != 0 && p - this_path == last_path_len 5820 && ! strncmp (last_path, this_path, last_path_len)); 5821 5822 last_path = this_path; 5823 last_path_len = p - this_path; 5824 5825 /* If this directory requires any default arguments, we can skip 5826 it. We will already have printed a directory identical to 5827 this one which does not require that default argument. */ 5828 if (! skip) 5829 { 5830 char *q; 5831 5832 q = p + 1; 5833 while (*q != ';') 5834 { 5835 char *arg; 5836 5837 if (*q == '\0') 5838 abort (); 5839 5840 if (*q == '!') 5841 arg = NULL; 5842 else 5843 arg = q; 5844 5845 while (*q != ' ' && *q != ';') 5846 { 5847 if (*q == '\0') 5848 abort (); 5849 ++q; 5850 } 5851 5852 if (arg != NULL 5853 && default_arg (arg, q - arg)) 5854 { 5855 skip = 1; 5856 break; 5857 } 5858 5859 if (*q == ' ') 5860 ++q; 5861 } 5862 } 5863 5864 if (! skip) 5865 { 5866 char *p1; 5867 5868 for (p1 = last_path; p1 < p; p1++) 5869 putchar (*p1); 5870 putchar (';'); 5871 } 5872 5873 ++p; 5874 while (*p != ';') 5875 { 5876 int use_arg; 5877 5878 if (*p == '\0') 5879 abort (); 5880 5881 if (skip) 5882 { 5883 ++p; 5884 continue; 5885 } 5886 5887 use_arg = *p != '!'; 5888 5889 if (use_arg) 5890 putchar ('@'); 5891 5892 while (*p != ' ' && *p != ';') 5893 { 5894 if (*p == '\0') 5895 abort (); 5896 if (use_arg) 5897 putchar (*p); 5898 ++p; 5899 } 5900 5901 if (*p == ' ') 5902 ++p; 5903 } 5904 5905 if (! skip) 5906 { 5907 /* If there are extra options, print them now */ 5908 if (multilib_extra && *multilib_extra) 5909 { 5910 int print_at = TRUE; 5911 char *q; 5912 5913 for (q = multilib_extra; *q != '\0'; q++) 5914 { 5915 if (*q == ' ') 5916 print_at = TRUE; 5917 else 5918 { 5919 if (print_at) 5920 putchar ('@'); 5921 putchar (*q); 5922 print_at = FALSE; 5923 } 5924 } 5925 } 5926 putchar ('\n'); 5927 } 5928 5929 ++p; 5930 } 5931} 5932