|
|
1.1 root 1: /* Compiler driver program that can handle many languages. 1.1.1.6 ! root 2: Copyright (C) 1987, 1989, 1992, 1993 Free Software Foundation, Inc. 1.1 root 3: 4: This file is part of GNU CC. 5: 6: GNU CC is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU CC is distributed in the hope that it will be useful, 12: but WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14: GNU General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU CC; see the file COPYING. If not, write to 18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19: 20: This paragraph is here to try to keep Sun CC from dying. 21: The number of chars here seems crucial!!!! */ 22: 23: /* This program is the user interface to the C compiler and possibly to 24: other compilers. It is used because compilation is a complicated procedure 25: which involves running several programs and passing temporary files between 26: them, forwarding the users switches to those programs selectively, 27: and deleting the temporary files at the end. 28: 29: CC recognizes how to compile each input file by suffixes in the file names. 30: Once it knows which kind of compilation to perform, the procedure for 31: compilation is specified by a string called a "spec". */ 32: 33: #include <sys/types.h> 34: #include <ctype.h> 35: #include <signal.h> 36: #include <sys/stat.h> 1.1.1.3 root 37: #include <sys/file.h> /* May get R_OK, etc. on some systems. */ 1.1 root 38: 39: #include "config.h" 40: #include "obstack.h" 41: #include "gvarargs.h" 1.1.1.4 root 42: #include <stdio.h> 1.1 root 43: 44: #ifndef R_OK 45: #define R_OK 4 46: #define W_OK 2 47: #define X_OK 1 48: #endif 49: 1.1.1.4 root 50: /* Define a generic NULL if one hasn't already been defined. */ 51: 52: #ifndef NULL 53: #define NULL 0 54: #endif 55: 56: #ifndef GENERIC_PTR 57: #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) 58: #define GENERIC_PTR void * 59: #else 60: #define GENERIC_PTR char * 61: #endif 62: #endif 63: 64: #ifndef NULL_PTR 65: #define NULL_PTR ((GENERIC_PTR)0) 66: #endif 67: 1.1.1.3 root 68: #ifdef USG 1.1 root 69: #define vfork fork 70: #endif /* USG */ 71: 72: /* On MSDOS, write temp files in current dir 73: because there's no place else we can expect to use. */ 74: #if __MSDOS__ 75: #ifndef P_tmpdir 1.1.1.6 ! root 76: #define P_tmpdir "." 1.1 root 77: #endif 78: #endif 79: 80: /* Test if something is a normal file. */ 81: #ifndef S_ISREG 82: #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 83: #endif 84: 85: /* Test if something is a directory. */ 86: #ifndef S_ISDIR 87: #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 88: #endif 89: 90: /* By default there is no special suffix for executables. */ 91: #ifndef EXECUTABLE_SUFFIX 92: #define EXECUTABLE_SUFFIX "" 93: #endif 1.1.1.3 root 94: 95: /* By default, colon separates directories in a path. */ 96: #ifndef PATH_SEPARATOR 97: #define PATH_SEPARATOR ':' 1.1 root 98: #endif 99: 100: #define obstack_chunk_alloc xmalloc 101: #define obstack_chunk_free free 102: 103: extern void free (); 104: extern char *getenv (); 105: 106: extern int errno, sys_nerr; 1.1.1.6 ! root 107: #if defined(bsd4_4) ! 108: extern const char *const sys_errlist[]; ! 109: #else 1.1 root 110: extern char *sys_errlist[]; 1.1.1.6 ! root 111: #endif 1.1 root 112: 113: extern int execv (), execvp (); 114: 115: /* If a stage of compilation returns an exit status >= 1, 116: compilation of that file ceases. */ 117: 118: #define MIN_FATAL_STATUS 1 119: 1.1.1.3 root 120: /* Flag saying to print the full filename of libgcc.a 121: as found through our usual search mechanism. */ 122: 123: static int print_libgcc_file_name; 124: 1.1 root 125: /* Flag indicating whether we should print the command and arguments */ 126: 127: static int verbose_flag; 128: 129: /* Nonzero means write "temp" files in source directory 130: and use the source file's name in them, and don't delete them. */ 131: 132: static int save_temps_flag; 133: 134: /* The compiler version specified with -V */ 135: 136: static char *spec_version; 137: 138: /* The target machine specified with -b. */ 139: 140: static char *spec_machine = DEFAULT_TARGET_MACHINE; 141: 1.1.1.2 root 142: /* Nonzero if cross-compiling. 143: When -b is used, the value comes from the `specs' file. */ 144: 145: #ifdef CROSS_COMPILE 146: static int cross_compile = 1; 147: #else 148: static int cross_compile = 0; 149: #endif 150: 1.1.1.5 root 151: /* The number of errors that have occurred; the link phase will not be 152: run if this is non-zero. */ 153: static int error_count = 0; 154: 1.1 root 155: /* This is the obstack which we use to allocate many strings. */ 156: 157: static struct obstack obstack; 158: 1.1.1.2 root 159: /* This is the obstack to build an environment variable to pass to 1.1.1.3 root 160: collect2 that describes all of the relevant switches of what to 1.1.1.2 root 161: pass the compiler in building the list of pointers to constructors 162: and destructors. */ 163: 164: static struct obstack collect_obstack; 165: 1.1 root 166: extern char *version_string; 167: 168: static void set_spec (); 169: static struct compiler *lookup_compiler (); 170: static char *find_a_file (); 171: static void add_prefix (); 172: static char *skip_whitespace (); 173: static void record_temp_file (); 174: static char *handle_braces (); 175: static char *save_string (); 176: static char *concat (); 177: static int do_spec (); 178: static int do_spec_1 (); 179: static char *find_file (); 1.1.1.5 root 180: static int is_directory (); 1.1 root 181: static void validate_switches (); 182: static void validate_all_switches (); 183: static void give_switch (); 184: static void pfatal_with_name (); 185: static void perror_with_name (); 186: static void perror_exec (); 187: static void fatal (); 188: static void error (); 189: void fancy_abort (); 190: char *xmalloc (); 191: char *xrealloc (); 192: 193: /* Specs are strings containing lines, each of which (if not blank) 194: is made up of a program name, and arguments separated by spaces. 195: The program name must be exact and start from root, since no path 196: is searched and it is unreliable to depend on the current working directory. 197: Redirection of input or output is not supported; the subprograms must 198: accept filenames saying what files to read and write. 199: 200: In addition, the specs can contain %-sequences to substitute variable text 201: or for conditional text. Here is a table of all defined %-sequences. 202: Note that spaces are not generated automatically around the results of 203: expanding these sequences; therefore, you can concatenate them together 204: or with constant text in a single argument. 205: 206: %% substitute one % into the program name or argument. 207: %i substitute the name of the input file being processed. 208: %b substitute the basename of the input file being processed. 209: This is the substring up to (and not including) the last period 210: and not including the directory. 211: %g substitute the temporary-file-name-base. This is a string chosen 212: once per compilation. Different temporary file names are made by 213: concatenation of constant strings on the end, as in `%g.s'. 214: %g also has the same effect of %d. 1.1.1.4 root 215: %u like %g, but make the temporary file name unique. 216: %U returns the last file name generated with %u. 1.1 root 217: %d marks the argument containing or following the %d as a 218: temporary file name, so that that file will be deleted if CC exits 219: successfully. Unlike %g, this contributes no text to the argument. 220: %w marks the argument containing or following the %w as the 221: "output file" of this compilation. This puts the argument 222: into the sequence of arguments that %o will substitute later. 223: %W{...} 224: like %{...} but mark last argument supplied within 225: as a file to be deleted on failure. 226: %o substitutes the names of all the output files, with spaces 227: automatically placed around them. You should write spaces 228: around the %o as well or the results are undefined. 229: %o is for use in the specs for running the linker. 230: Input files whose names have no recognized suffix are not compiled 231: at all, but they are included among the output files, so they will 232: be linked. 233: %p substitutes the standard macro predefinitions for the 234: current target machine. Use this when running cpp. 235: %P like %p, but puts `__' before and after the name of each macro. 236: (Except macros that already have __.) 237: This is for ANSI C. 1.1.1.3 root 238: %I Substitute a -iprefix option made from GCC_EXEC_PREFIX. 1.1 root 239: %s current argument is the name of a library or startup file of some sort. 240: Search for that file in a standard list of directories 241: and substitute the full name found. 242: %eSTR Print STR as an error message. STR is terminated by a newline. 243: Use this when inconsistent options are detected. 244: %x{OPTION} Accumulate an option for %X. 245: %X Output the accumulated linker options specified by compilations. 1.1.1.4 root 246: %Y Output the accumulated assembler options specified by compilations. 1.1.1.6 ! root 247: %v1 Substitute the major version number of GCC. ! 248: (For version 2.5.n, this is 2.) ! 249: %v2 Substitute the minor version number of GCC. ! 250: (For version 2.5.n, this is 5.) 1.1 root 251: %a process ASM_SPEC as a spec. 252: This allows config.h to specify part of the spec for running as. 253: %A process ASM_FINAL_SPEC as a spec. A capital A is actually 254: used here. This can be used to run a post-processor after the 255: assembler has done it's job. 1.1.1.5 root 256: %D Dump out a -L option for each directory in startfile_prefix. 1.1 root 257: %l process LINK_SPEC as a spec. 258: %L process LIB_SPEC as a spec. 259: %S process STARTFILE_SPEC as a spec. A capital S is actually used here. 260: %E process ENDFILE_SPEC as a spec. A capital E is actually used here. 261: %c process SIGNED_CHAR_SPEC as a spec. 262: %C process CPP_SPEC as a spec. A capital C is actually used here. 263: %1 process CC1_SPEC as a spec. 264: %2 process CC1PLUS_SPEC as a spec. 1.1.1.5 root 265: %| output "-" if the input for the current command is coming from a pipe. 1.1 root 266: %* substitute the variable part of a matched option. (See below.) 267: Note that each comma in the substituted string is replaced by 268: a single space. 269: %{S} substitutes the -S switch, if that switch was given to CC. 270: If that switch was not specified, this substitutes nothing. 271: Here S is a metasyntactic variable. 272: %{S*} substitutes all the switches specified to CC whose names start 273: with -S. This is used for -o, -D, -I, etc; switches that take 274: arguments. CC considers `-o foo' as being one switch whose 275: name starts with `o'. %{o*} would substitute this text, 276: including the space; thus, two arguments would be generated. 1.1.1.4 root 277: %{S*:X} substitutes X if one or more switches whose names start with -S are 1.1 root 278: specified to CC. Note that the tail part of the -S option 279: (i.e. the part matched by the `*') will be substituted for each 1.1.1.3 root 280: occurrence of %* within X. 1.1 root 281: %{S:X} substitutes X, but only if the -S switch was given to CC. 282: %{!S:X} substitutes X, but only if the -S switch was NOT given to CC. 283: %{|S:X} like %{S:X}, but if no S switch, substitute `-'. 284: %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'. 285: %{.S:X} substitutes X, but only if processing a file with suffix S. 286: %{!.S:X} substitutes X, but only if NOT processing a file with suffix S. 1.1.1.2 root 287: %(Spec) processes a specification defined in a specs file as *Spec: 288: %[Spec] as above, but put __ around -D arguments 1.1 root 289: 290: The conditional text X in a %{S:X} or %{!S:X} construct may contain 291: other nested % constructs or spaces, or even newlines. They are 292: processed as usual, as described above. 293: 294: The character | is used to indicate that a command should be piped to 295: the following command, but only if -pipe is specified. 296: 297: Note that it is built into CC which switches take arguments and which 298: do not. You might think it would be useful to generalize this to 299: allow each compiler's spec to say which switches take arguments. But 300: this cannot be done in a consistent fashion. CC cannot even decide 301: which input files have been specified without knowing which switches 302: take arguments, and it must know which input files to compile in order 303: to tell which compilers to run. 304: 305: CC also knows implicitly that arguments starting in `-l' are to be 306: treated as compiler output files, and passed to the linker in their 307: proper position among the other output files. */ 308: 309: /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */ 310: 311: /* config.h can define ASM_SPEC to provide extra args to the assembler 312: or extra switch-translations. */ 313: #ifndef ASM_SPEC 314: #define ASM_SPEC "" 315: #endif 316: 317: /* config.h can define ASM_FINAL_SPEC to run a post processor after 318: the assembler has run. */ 319: #ifndef ASM_FINAL_SPEC 320: #define ASM_FINAL_SPEC "" 321: #endif 322: 323: /* config.h can define CPP_SPEC to provide extra args to the C preprocessor 324: or extra switch-translations. */ 325: #ifndef CPP_SPEC 326: #define CPP_SPEC "" 327: #endif 328: 329: /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus 330: or extra switch-translations. */ 331: #ifndef CC1_SPEC 332: #define CC1_SPEC "" 333: #endif 334: 335: /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus 336: or extra switch-translations. */ 337: #ifndef CC1PLUS_SPEC 338: #define CC1PLUS_SPEC "" 339: #endif 340: 341: /* config.h can define LINK_SPEC to provide extra args to the linker 342: or extra switch-translations. */ 343: #ifndef LINK_SPEC 344: #define LINK_SPEC "" 345: #endif 346: 347: /* config.h can define LIB_SPEC to override the default libraries. */ 348: #ifndef LIB_SPEC 349: #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}" 350: #endif 351: 352: /* config.h can define STARTFILE_SPEC to override the default crt0 files. */ 353: #ifndef STARTFILE_SPEC 354: #define STARTFILE_SPEC \ 355: "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}" 356: #endif 357: 358: /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L. 359: Make the string nonempty to require spaces there. */ 360: #ifndef SWITCHES_NEED_SPACES 361: #define SWITCHES_NEED_SPACES "" 362: #endif 363: 364: /* config.h can define ENDFILE_SPEC to override the default crtn files. */ 365: #ifndef ENDFILE_SPEC 366: #define ENDFILE_SPEC "" 367: #endif 368: 369: /* This spec is used for telling cpp whether char is signed or not. */ 370: #ifndef SIGNED_CHAR_SPEC 1.1.1.4 root 371: /* Use #if rather than ?: 372: because MIPS C compiler rejects like ?: in initializers. */ 373: #if DEFAULT_SIGNED_CHAR 374: #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}" 375: #else 376: #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}" 377: #endif 1.1 root 378: #endif 379: 380: static char *cpp_spec = CPP_SPEC; 381: static char *cpp_predefines = CPP_PREDEFINES; 382: static char *cc1_spec = CC1_SPEC; 383: static char *cc1plus_spec = CC1PLUS_SPEC; 384: static char *signed_char_spec = SIGNED_CHAR_SPEC; 385: static char *asm_spec = ASM_SPEC; 386: static char *asm_final_spec = ASM_FINAL_SPEC; 387: static char *link_spec = LINK_SPEC; 388: static char *lib_spec = LIB_SPEC; 389: static char *endfile_spec = ENDFILE_SPEC; 390: static char *startfile_spec = STARTFILE_SPEC; 391: static char *switches_need_spaces = SWITCHES_NEED_SPACES; 392: 393: /* This defines which switch letters take arguments. */ 394: 395: #ifndef SWITCH_TAKES_ARG 396: #define SWITCH_TAKES_ARG(CHAR) \ 397: ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \ 398: || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \ 399: || (CHAR) == 'I' || (CHAR) == 'm' \ 400: || (CHAR) == 'L' || (CHAR) == 'A') 401: #endif 402: 403: /* This defines which multi-letter switches take arguments. */ 404: 1.1.1.5 root 405: #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR) \ 1.1.1.4 root 406: (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext") \ 407: || !strcmp (STR, "Tbss") || !strcmp (STR, "include") \ 1.1.1.5 root 408: || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \ 409: || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \ 1.1.1.6 ! root 410: || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore")) 1.1.1.5 root 411: 412: #ifndef WORD_SWITCH_TAKES_ARG 413: #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR) 1.1 root 414: #endif 415: 416: /* Record the mapping from file suffixes for compilation specs. */ 417: 418: struct compiler 419: { 420: char *suffix; /* Use this compiler for input files 421: whose names end in this suffix. */ 1.1.1.4 root 422: 423: char *spec[4]; /* To use this compiler, concatenate these 424: specs and pass to do_spec. */ 1.1 root 425: }; 426: 427: /* Pointer to a vector of `struct compiler' that gives the spec for 428: compiling a file, based on its suffix. 429: A file that does not end in any of these suffixes will be passed 430: unchanged to the loader and nothing else will be done to it. 431: 432: An entry containing two 0s is used to terminate the vector. 433: 434: If multiple entries match a file, the last matching one is used. */ 435: 436: static struct compiler *compilers; 437: 438: /* Number of entries in `compilers', not counting the null terminator. */ 439: 440: static int n_compilers; 441: 442: /* The default list of file name suffixes and their compilation specs. */ 443: 444: static struct compiler default_compilers[] = 445: { 446: {".c", "@c"}, 447: {"@c", 1.1.1.4 root 448: "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ 1.1 root 449: %{C:%{!E:%eGNU C does not support -C without using -E}}\ 450: %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\ 1.1.1.6 ! root 451: -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ ! 452: %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\ 1.1.1.4 root 453: %{!undef:%{!ansi:%p} %P} %{trigraphs} \ 1.1.1.5 root 454: %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ 1.1 root 455: %{traditional-cpp:-traditional}\ 1.1.1.4 root 456: %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\ 457: %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", 458: "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \ 1.1 root 459: %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\ 460: %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \ 461: %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\ 1.1.1.2 root 462: %{aux-info*}\ 1.1 root 463: %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 464: %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 1.1.1.4 root 465: %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 466: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\ 1.1 root 467: %{!pipe:%g.s} %A\n }}}}"}, 468: {"-", 1.1.1.4 root 469: "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ 1.1 root 470: %{C:%{!E:%eGNU C does not support -C without using -E}}\ 471: %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\ 1.1.1.6 ! root 472: -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ ! 473: %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\ 1.1 root 474: %{!undef:%{!ansi:%p} %P} %{trigraphs}\ 1.1.1.5 root 475: %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ 1.1 root 476: %{traditional-cpp:-traditional}\ 1.1.1.4 root 477: %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\ 1.1 root 478: %i %W{o*}}\ 479: %{!E:%e-E required when input is from standard input}"}, 480: {".m", "@objective-c"}, 481: {"@objective-c", 1.1.1.4 root 482: "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ 1.1 root 483: %{C:%{!E:%eGNU C does not support -C without using -E}}\ 484: %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\ 1.1.1.6 ! root 485: -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ ! 486: %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\ 1.1 root 487: %{!undef:%{!ansi:%p} %P} %{trigraphs}\ 1.1.1.5 root 488: %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ 1.1 root 489: %{traditional-cpp:-traditional}\ 1.1.1.4 root 490: %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\ 491: %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", 492: "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \ 1.1 root 493: %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\ 494: %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \ 495: %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \ 496: -lang-objc %{gen-decls} \ 1.1.1.2 root 497: %{aux-info*}\ 1.1 root 498: %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 499: %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 1.1.1.4 root 500: %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 501: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\ 1.1 root 502: %{!pipe:%g.s} %A\n }}}}"}, 503: {".h", "@c-header"}, 504: {"@c-header", 505: "%{!E:%eCompilation of header file requested} \ 1.1.1.4 root 506: cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ 1.1 root 507: %{C:%{!E:%eGNU C does not support -C without using -E}}\ 508: %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \ 1.1.1.6 ! root 509: -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ ! 510: %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\ 1.1 root 511: %{!undef:%{!ansi:%p} %P} %{trigraphs}\ 1.1.1.5 root 512: %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ 1.1 root 513: %{traditional-cpp:-traditional}\ 1.1.1.4 root 514: %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\ 1.1 root 515: %i %W{o*}"}, 516: {".cc", "@c++"}, 517: {".cxx", "@c++"}, 518: {".C", "@c++"}, 519: {"@c++", 1.1.1.4 root 520: "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ 1.1 root 521: %{C:%{!E:%eGNU C++ does not support -C without using -E}}\ 522: %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \ 1.1.1.6 ! root 523: -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\ 1.1 root 524: %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\ 1.1.1.5 root 525: %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ 1.1 root 526: %{traditional-cpp:-traditional} %{trigraphs}\ 1.1.1.4 root 527: %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\ 528: %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", 529: "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.i} %1 %2\ 1.1 root 530: %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\ 531: %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\ 1.1.1.4 root 532: %{v:-version} %{pg:-p} %{p} %{f*} %{+e*}\ 1.1.1.2 root 533: %{aux-info*}\ 1.1 root 534: %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 535: %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 1.1.1.4 root 536: %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 537: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\ 1.1 root 538: %{!pipe:%g.s} %A\n }}}}"}, 539: {".i", "@cpp-output"}, 540: {"@cpp-output", 541: "cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\ 542: %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\ 543: %{v:-version} %{pg:-p} %{p} %{f*}\ 1.1.1.2 root 544: %{aux-info*}\ 1.1 root 545: %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 546: %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 1.1.1.4 root 547: %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 548: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n }"}, 1.1 root 549: {".ii", "@c++-cpp-output"}, 550: {"@c++-cpp-output", 551: "cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\ 552: %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\ 1.1.1.4 root 553: %{v:-version} %{pg:-p} %{p} %{f*} %{+e*}\ 1.1.1.2 root 554: %{aux-info*}\ 1.1 root 555: %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ 556: %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ 1.1.1.4 root 557: %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 558: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\ 1.1 root 559: %{!pipe:%g.s} %A\n }"}, 560: {".s", "@assembler"}, 561: {"@assembler", 1.1.1.4 root 562: "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 563: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o} %i %A\n }"}, 1.1 root 564: {".S", "@assembler-with-cpp"}, 565: {"@assembler-with-cpp", 1.1.1.4 root 566: "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ 1.1 root 567: %{C:%{!E:%eGNU C does not support -C without using -E}}\ 568: %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \ 569: -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \ 1.1.1.5 root 570: %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ 1.1 root 571: %{traditional-cpp:-traditional}\ 1.1.1.4 root 572: %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\ 573: %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", 574: "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ 575: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\ 1.1 root 576: %{!pipe:%g.s} %A\n }}}}"}, 1.1.1.6 ! root 577: {".ads", "@ada"}, ! 578: {".adb", "@ada"}, ! 579: {".ada", "@ada"}, ! 580: {"@ada", ! 581: "gnat1 %{gnat*} %{k8:-gnatk8} %{w:-gnatws}\ ! 582: -dumpbase %b.ada\ ! 583: %{g*} %{O*} %{p} %{pg:-p} %{f*} %{d*}\ ! 584: %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ ! 585: %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} | \n", ! 586: "%{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\ ! 587: %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\ ! 588: %{!pipe:%g.s} %A\n}}} "}, 1.1 root 589: /* Mark end of table */ 590: {0, 0} 591: }; 592: 593: /* Number of elements in default_compilers, not counting the terminator. */ 594: 595: static int n_default_compilers 596: = (sizeof default_compilers / sizeof (struct compiler)) - 1; 597: 598: /* Here is the spec for running the linker, after compiling all files. */ 599: 1.1.1.3 root 600: /* -u* was put back because both BSD and SysV seem to support it. */ 1.1.1.4 root 601: /* %{static:} simply prevents an error message if the target machine 602: doesn't handle -static. */ 1.1.1.6 ! root 603: /* We want %{T*} after %{L*} and %D so that it can be used to specify linker ! 604: scripts which exist in user specified directories, or in standard ! 605: directories. */ 1.1.1.4 root 606: #ifdef LINK_LIBGCC_SPECIAL_1 607: /* Have gcc do the search for libgcc.a, but generate -L options as usual. */ 1.1 root 608: static char *link_command_spec = "\ 1.1.1.5 root 609: %{!fsyntax-only: \ 610: %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \ 1.1.1.6 ! root 611: %{r} %{s} %{t} %{u*} %{x} %{z}\ 1.1.1.5 root 612: %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\ 1.1.1.6 ! root 613: %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}"; 1.1 root 614: #else 1.1.1.4 root 615: #ifdef LINK_LIBGCC_SPECIAL 616: /* Have gcc do the search for libgcc.a, and don't generate -L options. */ 617: static char *link_command_spec = "\ 1.1.1.5 root 618: %{!fsyntax-only: \ 619: %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \ 1.1.1.6 ! root 620: %{r} %{s} %{t} %{u*} %{x} %{z}\ 1.1.1.5 root 621: %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\ 1.1.1.6 ! root 622: %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}"; 1.1.1.4 root 623: #else 1.1.1.3 root 624: /* Use -L and have the linker do the search for -lgcc. */ 1.1 root 625: static char *link_command_spec = "\ 1.1.1.5 root 626: %{!fsyntax-only: \ 627: %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \ 1.1.1.6 ! root 628: %{r} %{s} %{t} %{u*} %{x} %{z}\ 1.1.1.5 root 629: %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\ 1.1.1.6 ! root 630: %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}"; 1.1 root 631: #endif 1.1.1.4 root 632: #endif 1.1 root 633: 634: /* A vector of options to give to the linker. 1.1.1.4 root 635: These options are accumulated by -Xlinker and -Wl, 1.1 root 636: and substituted into the linker command with %X. */ 637: static int n_linker_options; 638: static char **linker_options; 1.1.1.4 root 639: 640: /* A vector of options to give to the assembler. 641: These options are accumulated by -Wa, 642: and substituted into the assembler command with %X. */ 643: static int n_assembler_options; 644: static char **assembler_options; 1.1 root 645: 1.1.1.5 root 646: /* Define how to map long options into short ones. */ 647: 648: /* This structure describes one mapping. */ 649: struct option_map 650: { 651: /* The long option's name. */ 652: char *name; 653: /* The equivalent short option. */ 654: char *equivalent; 655: /* Argument info. A string of flag chars; NULL equals no options. 656: a => argument required. 657: o => argument optional. 658: j => join argument to equivalent, making one word. 659: * => allow other text after NAME as an argument. */ 660: char *arg_info; 661: }; 662: 663: /* This is the table of mappings. Mappings are tried sequentially 664: for each option encountered; the first one that matches, wins. */ 665: 666: struct option_map option_map[] = 667: { 668: {"--profile-blocks", "-a", 0}, 669: {"--target", "-b", "a"}, 670: {"--compile", "-c", 0}, 671: {"--dump", "-d", "a"}, 672: {"--entry", "-e", 0}, 673: {"--debug", "-g", "oj"}, 674: {"--include", "-include", "a"}, 675: {"--imacros", "-imacros", "a"}, 676: {"--include-prefix", "-iprefix", "a"}, 677: {"--include-directory-after", "-idirafter", "a"}, 678: {"--include-with-prefix", "-iwithprefix", "a"}, 1.1.1.6 ! root 679: {"--include-with-prefix-before", "-iwithprefixbefore", "a"}, ! 680: {"--include-with-prefix-after", "-iwithprefix", "a"}, 1.1.1.5 root 681: {"--machine-", "-m", "*j"}, 682: {"--machine", "-m", "aj"}, 683: {"--no-standard-includes", "-nostdinc", 0}, 684: {"--no-standard-libraries", "-nostdlib", 0}, 685: {"--no-precompiled-includes", "-noprecomp", 0}, 686: {"--output", "-o", "a"}, 687: {"--profile", "-p", 0}, 688: {"--quiet", "-q", 0}, 689: {"--silent", "-q", 0}, 690: {"--force-link", "-u", "a"}, 691: {"--verbose", "-v", 0}, 1.1.1.6 ! root 692: {"--version", "-dumpversion", 0}, 1.1.1.5 root 693: {"--no-warnings", "-w", 0}, 694: {"--language", "-x", "a"}, 695: 696: {"--assert", "-A", "a"}, 697: {"--prefix", "-B", "a"}, 698: {"--comments", "-C", 0}, 699: {"--define-macro", "-D", "a"}, 700: {"--preprocess", "-E", 0}, 701: {"--trace-includes", "-H", 0}, 702: {"--include-directory", "-I", "a"}, 703: {"--include-barrier", "-I-", 0}, 704: {"--library-directory", "-L", "a"}, 705: {"--dependencies", "-M", 0}, 706: {"--user-dependencies", "-MM", 0}, 707: {"--write-dependencies", "-MD", 0}, 708: {"--write-user-dependencies", "-MMD", 0}, 709: {"--optimize", "-O", "oj"}, 710: {"--no-line-commands", "-P", 0}, 711: {"--assemble", "-S", 0}, 712: {"--undefine-macro", "-U", "a"}, 713: {"--use-version", "-V", "a"}, 714: {"--for-assembler", "-Wa", "a"}, 715: {"--extra-warnings", "-W", 0}, 716: {"--all-warnings", "-Wall", 0}, 717: {"--warn-", "-W", "*j"}, 718: {"--for-linker", "-Xlinker", "a"}, 719: 720: {"--ansi", "-ansi", 0}, 721: {"--traditional", "-traditional", 0}, 722: {"--traditional-cpp", "-traditional-cpp", 0}, 723: {"--trigraphs", "-trigraphs", 0}, 724: {"--pipe", "-pipe", 0}, 725: {"--dumpbase", "-dumpbase", "a"}, 726: {"--pedantic", "-pedantic", 0}, 727: {"--pedantic-errors", "-pedantic-errors", 0}, 728: {"--save-temps", "-save-temps", 0}, 729: {"--print-libgcc-file-name", "-print-libgcc-file-name", 0}, 730: {"--static", "-static", 0}, 731: {"--shared", "-shared", 0}, 732: {"--symbolic", "-symbolic", 0}, 733: {"--", "-f", "*j"} 734: }; 735: 736: /* Translate the options described by *ARGCP and *ARGVP. 737: Make a new vector and store it back in *ARGVP, 738: and store its length in *ARGVC. */ 739: 740: static void 741: translate_options (argcp, argvp) 742: int *argcp; 743: char ***argvp; 744: { 745: int i, j; 746: int argc = *argcp; 747: char **argv = *argvp; 748: char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *)); 749: int newindex = 0; 750: 751: i = 0; 752: newv[newindex++] = argv[i++]; 753: 754: while (i < argc) 755: { 756: /* Translate -- options. */ 757: if (argv[i][0] == '-' && argv[i][1] == '-') 758: { 759: /* Find a mapping that applies to this option. */ 760: for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++) 761: { 762: int optlen = strlen (option_map[j].name); 763: int complen = strlen (argv[i]); 764: char *arginfo = option_map[j].arg_info; 765: 766: if (arginfo == 0) 767: arginfo = ""; 768: if (complen > optlen) 769: complen = optlen; 770: if (!strncmp (argv[i], option_map[j].name, complen)) 771: { 772: int extra = strlen (argv[i]) > optlen; 773: char *arg = 0; 774: 775: if (extra) 776: { 777: /* If the option has an argument, accept that. */ 778: if (argv[i][optlen] == '=') 779: arg = argv[i] + optlen + 1; 780: /* If this mapping allows extra text at end of name, 781: accept that as "argument". */ 782: else if (index (arginfo, '*') != 0) 783: arg = argv[i] + optlen; 784: /* Otherwise, extra text at end means mismatch. 785: Try other mappings. */ 786: else 787: continue; 788: } 789: else if (index (arginfo, '*') != 0) 790: error ("Incomplete `%s' option", option_map[j].name); 791: 792: /* Handle arguments. */ 793: if (index (arginfo, 'o') != 0) 794: { 795: if (arg == 0) 796: { 797: if (i + 1 == argc) 798: error ("Missing argument to `%s' option", 799: option_map[j].name); 800: arg = argv[++i]; 801: } 802: } 1.1.1.6 ! root 803: else if (index (arginfo, '*') != 0) ! 804: ; 1.1.1.5 root 805: else if (index (arginfo, 'a') == 0) 806: { 807: if (arg != 0) 808: error ("Extraneous argument to `%s' option", 809: option_map[j].name); 810: arg = 0; 811: } 812: 813: /* Store the translation as one argv elt or as two. */ 814: if (arg != 0 && index (arginfo, 'j') != 0) 815: newv[newindex++] = concat (option_map[j].equivalent, 816: arg, ""); 817: else if (arg != 0) 818: { 819: newv[newindex++] = option_map[j].equivalent; 820: newv[newindex++] = arg; 821: } 822: else 823: newv[newindex++] = option_map[j].equivalent; 824: 825: break; 826: } 827: } 828: i++; 829: } 830: /* Handle old-fashioned options--just copy them through, 831: with their arguments. */ 832: else if (argv[i][0] == '-') 833: { 834: char *p = argv[i] + 1; 835: int c = *p; 836: int nskip = 1; 837: 838: if (SWITCH_TAKES_ARG (c) > (p[1] != 0)) 839: nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0); 840: else if (WORD_SWITCH_TAKES_ARG (p)) 841: nskip += WORD_SWITCH_TAKES_ARG (p); 842: 843: while (nskip > 0) 844: { 845: newv[newindex++] = argv[i++]; 846: nskip--; 847: } 848: } 849: else 850: /* Ordinary operands, or +e options. */ 851: newv[newindex++] = argv[i++]; 852: } 853: 854: newv[newindex] = 0; 855: 856: *argvp = newv; 857: *argcp = newindex; 858: } 859: 1.1 root 860: /* Read compilation specs from a file named FILENAME, 861: replacing the default ones. 862: 863: A suffix which starts with `*' is a definition for 864: one of the machine-specific sub-specs. The "suffix" should be 865: *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc. 866: The corresponding spec is stored in asm_spec, etc., 867: rather than in the `compilers' vector. 868: 869: Anything invalid in the file is a fatal error. */ 870: 871: static void 872: read_specs (filename) 873: char *filename; 874: { 875: int desc; 876: struct stat statbuf; 877: char *buffer; 878: register char *p; 879: 880: if (verbose_flag) 881: fprintf (stderr, "Reading specs from %s\n", filename); 882: 883: /* Open and stat the file. */ 884: desc = open (filename, 0, 0); 885: if (desc < 0) 886: pfatal_with_name (filename); 887: if (stat (filename, &statbuf) < 0) 888: pfatal_with_name (filename); 889: 890: /* Read contents of file into BUFFER. */ 1.1.1.4 root 891: buffer = xmalloc ((unsigned) statbuf.st_size + 1); 892: read (desc, buffer, (unsigned) statbuf.st_size); 1.1 root 893: buffer[statbuf.st_size] = 0; 894: close (desc); 895: 896: /* Scan BUFFER for specs, putting them in the vector. */ 897: p = buffer; 898: while (1) 899: { 900: char *suffix; 901: char *spec; 902: char *in, *out, *p1, *p2; 903: 904: /* Advance P in BUFFER to the next nonblank nocomment line. */ 905: p = skip_whitespace (p); 906: if (*p == 0) 907: break; 908: 909: /* Find the colon that should end the suffix. */ 910: p1 = p; 911: while (*p1 && *p1 != ':' && *p1 != '\n') p1++; 912: /* The colon shouldn't be missing. */ 913: if (*p1 != ':') 914: fatal ("specs file malformed after %d characters", p1 - buffer); 915: /* Skip back over trailing whitespace. */ 916: p2 = p1; 917: while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--; 918: /* Copy the suffix to a string. */ 919: suffix = save_string (p, p2 - p); 920: /* Find the next line. */ 921: p = skip_whitespace (p1 + 1); 922: if (p[1] == 0) 923: fatal ("specs file malformed after %d characters", p - buffer); 924: p1 = p; 925: /* Find next blank line. */ 926: while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++; 927: /* Specs end at the blank line and do not include the newline. */ 928: spec = save_string (p, p1 - p); 929: p = p1; 930: 931: /* Delete backslash-newline sequences from the spec. */ 932: in = spec; 933: out = spec; 934: while (*in != 0) 935: { 936: if (in[0] == '\\' && in[1] == '\n') 937: in += 2; 938: else if (in[0] == '#') 939: { 940: while (*in && *in != '\n') in++; 941: } 942: else 943: *out++ = *in++; 944: } 945: *out = 0; 946: 947: if (suffix[0] == '*') 948: { 949: if (! strcmp (suffix, "*link_command")) 950: link_command_spec = spec; 951: else 952: set_spec (suffix + 1, spec); 953: } 954: else 955: { 956: /* Add this pair to the vector. */ 957: compilers 958: = ((struct compiler *) 959: xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler))); 960: compilers[n_compilers].suffix = suffix; 1.1.1.4 root 961: bzero (compilers[n_compilers].spec, 962: sizeof compilers[n_compilers].spec); 963: compilers[n_compilers].spec[0] = spec; 1.1 root 964: n_compilers++; 1.1.1.6 ! root 965: bzero (&compilers[n_compilers], sizeof compilers[n_compilers]); 1.1 root 966: } 967: 968: if (*suffix == 0) 969: link_command_spec = spec; 970: } 971: 972: if (link_command_spec == 0) 973: fatal ("spec file has no spec for linking"); 974: } 975: 976: static char * 977: skip_whitespace (p) 978: char *p; 979: { 980: while (1) 981: { 982: /* A fully-blank line is a delimiter in the SPEC file and shouldn't 983: be considered whitespace. */ 984: if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') 985: return p + 1; 986: else if (*p == '\n' || *p == ' ' || *p == '\t') 987: p++; 988: else if (*p == '#') 989: { 990: while (*p != '\n') p++; 991: p++; 992: } 993: else 994: break; 995: } 996: 997: return p; 998: } 999: 1000: /* Structure to keep track of the specs that have been defined so far. These 1.1.1.2 root 1001: are accessed using %(specname) or %[specname] in a compiler or link spec. */ 1.1 root 1002: 1003: struct spec_list 1004: { 1005: char *name; /* Name of the spec. */ 1006: char *spec; /* The spec itself. */ 1007: struct spec_list *next; /* Next spec in linked list. */ 1008: }; 1009: 1010: /* List of specs that have been defined so far. */ 1011: 1012: static struct spec_list *specs = (struct spec_list *) 0; 1013: 1014: /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is 1015: removed; If the spec starts with a + then SPEC is added to the end of the 1016: current spec. */ 1017: 1018: static void 1019: set_spec (name, spec) 1020: char *name; 1021: char *spec; 1022: { 1023: struct spec_list *sl; 1024: char *old_spec; 1025: 1026: /* See if the spec already exists */ 1027: for (sl = specs; sl; sl = sl->next) 1028: if (strcmp (sl->name, name) == 0) 1029: break; 1030: 1031: if (!sl) 1032: { 1033: /* Not found - make it */ 1034: sl = (struct spec_list *) xmalloc (sizeof (struct spec_list)); 1035: sl->name = save_string (name, strlen (name)); 1036: sl->spec = save_string ("", 0); 1037: sl->next = specs; 1038: specs = sl; 1039: } 1040: 1041: old_spec = sl->spec; 1042: if (name && spec[0] == '+' && isspace (spec[1])) 1.1.1.3 root 1043: sl->spec = concat (old_spec, spec + 1, ""); 1.1 root 1044: else 1045: sl->spec = save_string (spec, strlen (spec)); 1046: 1047: if (! strcmp (name, "asm")) 1048: asm_spec = sl->spec; 1049: else if (! strcmp (name, "asm_final")) 1050: asm_final_spec = sl->spec; 1051: else if (! strcmp (name, "cc1")) 1052: cc1_spec = sl->spec; 1053: else if (! strcmp (name, "cc1plus")) 1054: cc1plus_spec = sl->spec; 1055: else if (! strcmp (name, "cpp")) 1056: cpp_spec = sl->spec; 1057: else if (! strcmp (name, "endfile")) 1058: endfile_spec = sl->spec; 1059: else if (! strcmp (name, "lib")) 1060: lib_spec = sl->spec; 1061: else if (! strcmp (name, "link")) 1062: link_spec = sl->spec; 1063: else if (! strcmp (name, "predefines")) 1064: cpp_predefines = sl->spec; 1065: else if (! strcmp (name, "signed_char")) 1066: signed_char_spec = sl->spec; 1067: else if (! strcmp (name, "startfile")) 1068: startfile_spec = sl->spec; 1069: else if (! strcmp (name, "switches_need_spaces")) 1070: switches_need_spaces = sl->spec; 1.1.1.2 root 1071: else if (! strcmp (name, "cross_compile")) 1072: cross_compile = atoi (sl->spec); 1.1 root 1073: /* Free the old spec */ 1074: if (old_spec) 1075: free (old_spec); 1076: } 1077: 1078: /* Accumulate a command (program name and args), and run it. */ 1079: 1080: /* Vector of pointers to arguments in the current line of specifications. */ 1081: 1082: static char **argbuf; 1083: 1084: /* Number of elements allocated in argbuf. */ 1085: 1086: static int argbuf_length; 1087: 1088: /* Number of elements in argbuf currently in use (containing args). */ 1089: 1090: static int argbuf_index; 1091: 1.1.1.4 root 1092: /* This is the list of suffixes and codes (%g/%u/%U) and the associated 1093: temp file. Used only if MKTEMP_EACH_FILE. */ 1094: 1095: static struct temp_name { 1096: char *suffix; /* suffix associated with the code. */ 1097: int length; /* strlen (suffix). */ 1098: int unique; /* Indicates whether %g or %u/%U was used. */ 1099: char *filename; /* associated filename. */ 1100: int filename_length; /* strlen (filename). */ 1101: struct temp_name *next; 1102: } *temp_names; 1103: 1.1 root 1104: /* Number of commands executed so far. */ 1105: 1106: static int execution_count; 1107: 1.1.1.4 root 1108: /* Number of commands that exited with a signal. */ 1109: 1110: static int signal_count; 1111: 1.1 root 1112: /* Name with which this program was invoked. */ 1113: 1114: static char *programname; 1115: 1116: /* Structures to keep track of prefixes to try when looking for files. */ 1117: 1118: struct prefix_list 1119: { 1120: char *prefix; /* String to prepend to the path. */ 1121: struct prefix_list *next; /* Next in linked list. */ 1122: int require_machine_suffix; /* Don't use without machine_suffix. */ 1.1.1.4 root 1123: /* 2 means try both machine_suffix and just_machine_suffix. */ 1.1 root 1124: int *used_flag_ptr; /* 1 if a file was found with this prefix. */ 1125: }; 1126: 1127: struct path_prefix 1128: { 1129: struct prefix_list *plist; /* List of prefixes to try */ 1130: int max_len; /* Max length of a prefix in PLIST */ 1131: char *name; /* Name of this list (used in config stuff) */ 1132: }; 1133: 1134: /* List of prefixes to try when looking for executables. */ 1135: 1136: static struct path_prefix exec_prefix = { 0, 0, "exec" }; 1137: 1138: /* List of prefixes to try when looking for startup (crt0) files. */ 1139: 1140: static struct path_prefix startfile_prefix = { 0, 0, "startfile" }; 1141: 1.1.1.4 root 1142: /* Suffix to attach to directories searched for commands. 1143: This looks like `MACHINE/VERSION/'. */ 1.1 root 1144: 1145: static char *machine_suffix = 0; 1146: 1.1.1.4 root 1147: /* Suffix to attach to directories searched for commands. 1148: This is just `MACHINE/'. */ 1149: 1150: static char *just_machine_suffix = 0; 1151: 1.1.1.3 root 1152: /* Adjusted value of GCC_EXEC_PREFIX envvar. */ 1153: 1154: static char *gcc_exec_prefix; 1155: 1.1 root 1156: /* Default prefixes to attach to command names. */ 1157: 1158: #ifdef CROSS_COMPILE /* Don't use these prefixes for a cross compiler. */ 1159: #undef MD_EXEC_PREFIX 1160: #undef MD_STARTFILE_PREFIX 1.1.1.3 root 1161: #undef MD_STARTFILE_PREFIX_1 1.1 root 1162: #endif 1163: 1164: #ifndef STANDARD_EXEC_PREFIX 1.1.1.2 root 1165: #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-lib/" 1.1 root 1166: #endif /* !defined STANDARD_EXEC_PREFIX */ 1167: 1168: static char *standard_exec_prefix = STANDARD_EXEC_PREFIX; 1169: static char *standard_exec_prefix_1 = "/usr/lib/gcc/"; 1170: #ifdef MD_EXEC_PREFIX 1171: static char *md_exec_prefix = MD_EXEC_PREFIX; 1172: #endif 1173: 1174: #ifndef STANDARD_STARTFILE_PREFIX 1175: #define STANDARD_STARTFILE_PREFIX "/usr/local/lib/" 1176: #endif /* !defined STANDARD_STARTFILE_PREFIX */ 1177: 1178: #ifdef MD_STARTFILE_PREFIX 1179: static char *md_startfile_prefix = MD_STARTFILE_PREFIX; 1180: #endif 1.1.1.3 root 1181: #ifdef MD_STARTFILE_PREFIX_1 1182: static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; 1183: #endif 1.1 root 1184: static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; 1185: static char *standard_startfile_prefix_1 = "/lib/"; 1186: static char *standard_startfile_prefix_2 = "/usr/lib/"; 1187: 1.1.1.5 root 1188: #ifndef TOOLDIR_BASE_PREFIX 1189: #define TOOLDIR_BASE_PREFIX "/usr/local/" 1190: #endif 1191: static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX; 1192: static char *tooldir_prefix; 1193: 1.1 root 1194: /* Clear out the vector of arguments (after a command is executed). */ 1195: 1196: static void 1197: clear_args () 1198: { 1199: argbuf_index = 0; 1200: } 1201: 1202: /* Add one argument to the vector at the end. 1203: This is done when a space is seen or at the end of the line. 1204: If DELETE_ALWAYS is nonzero, the arg is a filename 1205: and the file should be deleted eventually. 1206: If DELETE_FAILURE is nonzero, the arg is a filename 1207: and the file should be deleted if this compilation fails. */ 1208: 1209: static void 1210: store_arg (arg, delete_always, delete_failure) 1211: char *arg; 1212: int delete_always, delete_failure; 1213: { 1214: if (argbuf_index + 1 == argbuf_length) 1215: { 1216: argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *)); 1217: } 1218: 1219: argbuf[argbuf_index++] = arg; 1220: argbuf[argbuf_index] = 0; 1221: 1222: if (delete_always || delete_failure) 1223: record_temp_file (arg, delete_always, delete_failure); 1224: } 1225: 1226: /* Record the names of temporary files we tell compilers to write, 1227: and delete them at the end of the run. */ 1228: 1229: /* This is the common prefix we use to make temp file names. 1230: It is chosen once for each run of this program. 1231: It is substituted into a spec by %g. 1232: Thus, all temp file names contain this prefix. 1233: In practice, all temp file names start with this prefix. 1234: 1235: This prefix comes from the envvar TMPDIR if it is defined; 1236: otherwise, from the P_tmpdir macro if that is defined; 1237: otherwise, in /usr/tmp or /tmp. */ 1238: 1239: static char *temp_filename; 1240: 1241: /* Length of the prefix. */ 1242: 1243: static int temp_filename_length; 1244: 1245: /* Define the list of temporary files to delete. */ 1246: 1247: struct temp_file 1248: { 1249: char *name; 1250: struct temp_file *next; 1251: }; 1252: 1253: /* Queue of files to delete on success or failure of compilation. */ 1254: static struct temp_file *always_delete_queue; 1255: /* Queue of files to delete on failure of compilation. */ 1256: static struct temp_file *failure_delete_queue; 1257: 1258: /* Record FILENAME as a file to be deleted automatically. 1259: ALWAYS_DELETE nonzero means delete it if all compilation succeeds; 1260: otherwise delete it in any case. 1261: FAIL_DELETE nonzero means delete it if a compilation step fails; 1262: otherwise delete it in any case. */ 1263: 1264: static void 1265: record_temp_file (filename, always_delete, fail_delete) 1266: char *filename; 1267: int always_delete; 1268: int fail_delete; 1269: { 1270: register char *name; 1271: name = xmalloc (strlen (filename) + 1); 1272: strcpy (name, filename); 1273: 1274: if (always_delete) 1275: { 1276: register struct temp_file *temp; 1277: for (temp = always_delete_queue; temp; temp = temp->next) 1278: if (! strcmp (name, temp->name)) 1279: goto already1; 1280: temp = (struct temp_file *) xmalloc (sizeof (struct temp_file)); 1281: temp->next = always_delete_queue; 1282: temp->name = name; 1283: always_delete_queue = temp; 1284: already1:; 1285: } 1286: 1287: if (fail_delete) 1288: { 1289: register struct temp_file *temp; 1290: for (temp = failure_delete_queue; temp; temp = temp->next) 1291: if (! strcmp (name, temp->name)) 1292: goto already2; 1293: temp = (struct temp_file *) xmalloc (sizeof (struct temp_file)); 1294: temp->next = failure_delete_queue; 1295: temp->name = name; 1296: failure_delete_queue = temp; 1297: already2:; 1298: } 1299: } 1300: 1301: /* Delete all the temporary files whose names we previously recorded. */ 1302: 1303: static void 1304: delete_temp_files () 1305: { 1306: register struct temp_file *temp; 1307: 1308: for (temp = always_delete_queue; temp; temp = temp->next) 1309: { 1310: #ifdef DEBUG 1311: int i; 1312: printf ("Delete %s? (y or n) ", temp->name); 1313: fflush (stdout); 1314: i = getchar (); 1315: if (i != '\n') 1316: while (getchar () != '\n') ; 1317: if (i == 'y' || i == 'Y') 1318: #endif /* DEBUG */ 1319: { 1320: struct stat st; 1321: if (stat (temp->name, &st) >= 0) 1322: { 1323: /* Delete only ordinary files. */ 1324: if (S_ISREG (st.st_mode)) 1325: if (unlink (temp->name) < 0) 1326: if (verbose_flag) 1327: perror_with_name (temp->name); 1328: } 1329: } 1330: } 1331: 1332: always_delete_queue = 0; 1333: } 1334: 1335: /* Delete all the files to be deleted on error. */ 1336: 1337: static void 1338: delete_failure_queue () 1339: { 1340: register struct temp_file *temp; 1341: 1342: for (temp = failure_delete_queue; temp; temp = temp->next) 1343: { 1344: #ifdef DEBUG 1345: int i; 1346: printf ("Delete %s? (y or n) ", temp->name); 1347: fflush (stdout); 1348: i = getchar (); 1349: if (i != '\n') 1350: while (getchar () != '\n') ; 1351: if (i == 'y' || i == 'Y') 1352: #endif /* DEBUG */ 1353: { 1354: if (unlink (temp->name) < 0) 1355: if (verbose_flag) 1356: perror_with_name (temp->name); 1357: } 1358: } 1359: } 1360: 1361: static void 1362: clear_failure_queue () 1363: { 1364: failure_delete_queue = 0; 1365: } 1366: 1367: /* Compute a string to use as the base of all temporary file names. 1368: It is substituted for %g. */ 1369: 1.1.1.6 ! root 1370: static char * ! 1371: choose_temp_base_try (try, base) ! 1372: char *try; ! 1373: char *base; ! 1374: { ! 1375: char *rv; ! 1376: if (base) ! 1377: rv = base; ! 1378: else if (try == (char *)0) ! 1379: rv = 0; ! 1380: else if (access (try, R_OK | W_OK) != 0) ! 1381: rv = 0; ! 1382: else ! 1383: rv = try; ! 1384: return rv; ! 1385: } ! 1386: 1.1 root 1387: static void 1388: choose_temp_base () 1389: { 1.1.1.6 ! root 1390: char *base = 0; 1.1 root 1391: int len; 1392: 1.1.1.6 ! root 1393: base = choose_temp_base_try (getenv ("TMPDIR"), base); ! 1394: base = choose_temp_base_try (getenv ("TMP"), base); ! 1395: base = choose_temp_base_try (getenv ("TEMP"), base); ! 1396: 1.1 root 1397: #ifdef P_tmpdir 1.1.1.6 ! root 1398: base = choose_temp_base_try (P_tmpdir, base); 1.1 root 1399: #endif 1.1.1.6 ! root 1400: ! 1401: base = choose_temp_base_try ("/usr/tmp", base); ! 1402: base = choose_temp_base_try ("/tmp", base); ! 1403: ! 1404: /* If all else fails, use the current directory! */ ! 1405: if (base == (char *)0) ! 1406: base = "./"; 1.1 root 1407: 1408: len = strlen (base); 1.1.1.6 ! root 1409: temp_filename = xmalloc (len + sizeof("/ccXXXXXX") + 1); 1.1 root 1410: strcpy (temp_filename, base); 1411: if (len > 0 && temp_filename[len-1] != '/') 1412: temp_filename[len++] = '/'; 1413: strcpy (temp_filename + len, "ccXXXXXX"); 1414: 1415: mktemp (temp_filename); 1416: temp_filename_length = strlen (temp_filename); 1.1.1.4 root 1417: if (temp_filename_length == 0) 1418: abort (); 1.1 root 1419: } 1420: 1.1.1.2 root 1421: 1422: /* Routine to add variables to the environment. We do this to pass 1423: the pathname of the gcc driver, and the directories search to the 1424: collect2 program, which is being run as ld. This way, we can be 1425: sure of executing the right compiler when collect2 wants to build 1426: constructors and destructors. Since the environment variables we 1427: use come from an obstack, we don't have to worry about allocating 1428: space for them. */ 1429: 1430: #ifndef HAVE_PUTENV 1431: 1.1.1.5 root 1432: void 1.1.1.2 root 1433: putenv (str) 1434: char *str; 1435: { 1436: #ifndef VMS /* nor about VMS */ 1437: 1438: extern char **environ; 1439: char **old_environ = environ; 1440: char **envp; 1441: int num_envs = 0; 1442: int name_len = 1; 1443: int str_len = strlen (str); 1444: char *p = str; 1445: int ch; 1446: 1447: while ((ch = *p++) != '\0' && ch != '=') 1448: name_len++; 1449: 1450: if (!ch) 1451: abort (); 1452: 1453: /* Search for replacing an existing environment variable, and 1454: count the number of total environment variables. */ 1455: for (envp = old_environ; *envp; envp++) 1456: { 1457: num_envs++; 1458: if (!strncmp (str, *envp, name_len)) 1459: { 1460: *envp = str; 1461: return; 1462: } 1463: } 1464: 1465: /* Add a new environment variable */ 1466: environ = (char **) xmalloc (sizeof (char *) * (num_envs+2)); 1467: *environ = str; 1468: bcopy (old_environ, environ+1, sizeof (char *) * (num_envs+1)); 1469: 1470: #endif /* VMS */ 1471: } 1472: 1473: #endif /* HAVE_PUTENV */ 1474: 1475: 1476: /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect. */ 1477: 1478: static void 1479: putenv_from_prefixes (paths, env_var) 1480: struct path_prefix *paths; 1481: char *env_var; 1482: { 1483: int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0; 1.1.1.5 root 1484: int just_suffix_len 1485: = (just_machine_suffix) ? strlen (just_machine_suffix) : 0; 1.1.1.2 root 1486: int first_time = TRUE; 1487: struct prefix_list *pprefix; 1488: 1489: obstack_grow (&collect_obstack, env_var, strlen (env_var)); 1490: 1491: for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next) 1492: { 1493: int len = strlen (pprefix->prefix); 1494: 1.1.1.5 root 1495: if (machine_suffix 1496: && is_directory (pprefix->prefix, machine_suffix, 0)) 1.1.1.2 root 1497: { 1498: if (!first_time) 1.1.1.5 root 1499: obstack_1grow (&collect_obstack, PATH_SEPARATOR); 1.1.1.2 root 1500: 1501: first_time = FALSE; 1502: obstack_grow (&collect_obstack, pprefix->prefix, len); 1503: obstack_grow (&collect_obstack, machine_suffix, suffix_len); 1504: } 1505: 1.1.1.5 root 1506: if (just_machine_suffix 1507: && pprefix->require_machine_suffix == 2 1508: && is_directory (pprefix->prefix, just_machine_suffix, 0)) 1.1.1.4 root 1509: { 1510: if (!first_time) 1.1.1.5 root 1511: obstack_1grow (&collect_obstack, PATH_SEPARATOR); 1.1.1.4 root 1512: 1513: first_time = FALSE; 1514: obstack_grow (&collect_obstack, pprefix->prefix, len); 1.1.1.5 root 1515: obstack_grow (&collect_obstack, just_machine_suffix, 1516: just_suffix_len); 1.1.1.4 root 1517: } 1518: 1.1.1.2 root 1519: if (!pprefix->require_machine_suffix) 1520: { 1521: if (!first_time) 1.1.1.5 root 1522: obstack_1grow (&collect_obstack, PATH_SEPARATOR); 1.1.1.2 root 1523: 1524: first_time = FALSE; 1525: obstack_grow (&collect_obstack, pprefix->prefix, len); 1526: } 1527: } 1.1.1.5 root 1528: obstack_1grow (&collect_obstack, '\0'); 1.1.1.2 root 1529: putenv (obstack_finish (&collect_obstack)); 1530: } 1531: 1532: 1.1 root 1533: /* Search for NAME using the prefix list PREFIXES. MODE is passed to 1534: access to check permissions. 1535: Return 0 if not found, otherwise return its name, allocated with malloc. */ 1536: 1537: static char * 1538: find_a_file (pprefix, name, mode) 1539: struct path_prefix *pprefix; 1540: char *name; 1541: int mode; 1542: { 1543: char *temp; 1.1.1.2 root 1544: char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : ""); 1.1 root 1545: struct prefix_list *pl; 1546: int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1; 1547: 1548: if (machine_suffix) 1549: len += strlen (machine_suffix); 1550: 1551: temp = xmalloc (len); 1552: 1553: /* Determine the filename to execute (special case for absolute paths). */ 1554: 1555: if (*name == '/') 1556: { 1557: if (access (name, mode)) 1558: { 1559: strcpy (temp, name); 1560: return temp; 1561: } 1562: } 1563: else 1564: for (pl = pprefix->plist; pl; pl = pl->next) 1565: { 1566: if (machine_suffix) 1567: { 1568: strcpy (temp, pl->prefix); 1569: strcat (temp, machine_suffix); 1570: strcat (temp, name); 1571: if (access (temp, mode) == 0) 1572: { 1573: if (pl->used_flag_ptr != 0) 1574: *pl->used_flag_ptr = 1; 1575: return temp; 1576: } 1577: /* Some systems have a suffix for executable files. 1578: So try appending that. */ 1579: if (file_suffix[0] != 0) 1580: { 1581: strcat (temp, file_suffix); 1582: if (access (temp, mode) == 0) 1583: { 1584: if (pl->used_flag_ptr != 0) 1585: *pl->used_flag_ptr = 1; 1586: return temp; 1587: } 1588: } 1589: } 1.1.1.4 root 1590: /* Certain prefixes are tried with just the machine type, 1591: not the version. This is used for finding as, ld, etc. */ 1592: if (just_machine_suffix && pl->require_machine_suffix == 2) 1593: { 1594: strcpy (temp, pl->prefix); 1595: strcat (temp, just_machine_suffix); 1596: strcat (temp, name); 1597: if (access (temp, mode) == 0) 1598: { 1599: if (pl->used_flag_ptr != 0) 1600: *pl->used_flag_ptr = 1; 1601: return temp; 1602: } 1603: /* Some systems have a suffix for executable files. 1604: So try appending that. */ 1605: if (file_suffix[0] != 0) 1606: { 1607: strcat (temp, file_suffix); 1608: if (access (temp, mode) == 0) 1609: { 1610: if (pl->used_flag_ptr != 0) 1611: *pl->used_flag_ptr = 1; 1612: return temp; 1613: } 1614: } 1615: } 1.1 root 1616: /* Certain prefixes can't be used without the machine suffix 1617: when the machine or version is explicitly specified. */ 1.1.1.2 root 1618: if (!pl->require_machine_suffix) 1.1 root 1619: { 1620: strcpy (temp, pl->prefix); 1621: strcat (temp, name); 1622: if (access (temp, mode) == 0) 1623: { 1624: if (pl->used_flag_ptr != 0) 1625: *pl->used_flag_ptr = 1; 1626: return temp; 1627: } 1628: /* Some systems have a suffix for executable files. 1629: So try appending that. */ 1630: if (file_suffix[0] != 0) 1631: { 1632: strcat (temp, file_suffix); 1633: if (access (temp, mode) == 0) 1634: { 1635: if (pl->used_flag_ptr != 0) 1636: *pl->used_flag_ptr = 1; 1637: return temp; 1638: } 1639: } 1640: } 1641: } 1642: 1643: free (temp); 1644: return 0; 1645: } 1646: 1647: /* Add an entry for PREFIX in PLIST. If FIRST is set, it goes 1648: at the start of the list, otherwise it goes at the end. 1649: 1650: If WARN is nonzero, we will warn if no file is found 1651: through this prefix. WARN should point to an int 1.1.1.4 root 1652: which will be set to 1 if this entry is used. 1653: 1654: REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without 1655: the complete value of machine_suffix. 1656: 2 means try both machine_suffix and just_machine_suffix. */ 1.1 root 1657: 1658: static void 1659: add_prefix (pprefix, prefix, first, require_machine_suffix, warn) 1660: struct path_prefix *pprefix; 1661: char *prefix; 1662: int first; 1663: int require_machine_suffix; 1664: int *warn; 1665: { 1666: struct prefix_list *pl, **prev; 1667: int len; 1668: 1669: if (!first && pprefix->plist) 1670: { 1671: for (pl = pprefix->plist; pl->next; pl = pl->next) 1672: ; 1673: prev = &pl->next; 1674: } 1675: else 1676: prev = &pprefix->plist; 1677: 1678: /* Keep track of the longest prefix */ 1679: 1680: len = strlen (prefix); 1681: if (len > pprefix->max_len) 1682: pprefix->max_len = len; 1683: 1684: pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list)); 1685: pl->prefix = save_string (prefix, len); 1686: pl->require_machine_suffix = require_machine_suffix; 1687: pl->used_flag_ptr = warn; 1688: if (warn) 1689: *warn = 0; 1690: 1691: if (*prev) 1692: pl->next = *prev; 1693: else 1694: pl->next = (struct prefix_list *) 0; 1695: *prev = pl; 1696: } 1697: 1698: /* Print warnings for any prefixes in the list PPREFIX that were not used. */ 1699: 1700: static void 1701: unused_prefix_warnings (pprefix) 1702: struct path_prefix *pprefix; 1703: { 1704: struct prefix_list *pl = pprefix->plist; 1705: 1706: while (pl) 1707: { 1708: if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr) 1709: { 1710: error ("file path prefix `%s' never used", 1711: pl->prefix); 1712: /* Prevent duplicate warnings. */ 1713: *pl->used_flag_ptr = 1; 1714: } 1715: pl = pl->next; 1716: } 1717: } 1718: 1719: /* Get rid of all prefixes built up so far in *PLISTP. */ 1720: 1721: static void 1722: free_path_prefix (pprefix) 1723: struct path_prefix *pprefix; 1724: { 1725: struct prefix_list *pl = pprefix->plist; 1726: struct prefix_list *temp; 1727: 1728: while (pl) 1729: { 1730: temp = pl; 1731: pl = pl->next; 1732: free (temp->prefix); 1733: free ((char *) temp); 1734: } 1735: pprefix->plist = (struct prefix_list *) 0; 1736: } 1737: 1738: /* stdin file number. */ 1739: #define STDIN_FILE_NO 0 1740: 1741: /* stdout file number. */ 1742: #define STDOUT_FILE_NO 1 1743: 1744: /* value of `pipe': port index for reading. */ 1745: #define READ_PORT 0 1746: 1747: /* value of `pipe': port index for writing. */ 1748: #define WRITE_PORT 1 1749: 1750: /* Pipe waiting from last process, to be used as input for the next one. 1751: Value is STDIN_FILE_NO if no pipe is waiting 1752: (i.e. the next command is the first of a group). */ 1753: 1754: static int last_pipe_input; 1755: 1756: /* Fork one piped subcommand. FUNC is the system call to use 1757: (either execv or execvp). ARGV is the arg vector to use. 1758: NOT_LAST is nonzero if this is not the last subcommand 1759: (i.e. its output should be piped to the next one.) */ 1760: 1.1.1.3 root 1761: #ifndef OS2 1.1 root 1762: #ifdef __MSDOS__ 1763: 1764: /* Declare these to avoid compilation error. They won't be called. */ 1765: int execv(const char *a, const char **b){} 1766: int execvp(const char *a, const char **b){} 1767: 1768: static int 1.1.1.3 root 1769: pexecute (search_flag, program, argv, not_last) 1770: int search_flag; 1.1 root 1771: char *program; 1772: char *argv[]; 1773: int not_last; 1774: { 1.1.1.6 ! root 1775: char *scmd, *rf; 1.1 root 1776: FILE *argfile; 1.1.1.6 ! root 1777: int i, el = search_flag ? 0 : 4; 1.1 root 1778: 1.1.1.6 ! root 1779: scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6 + el); ! 1780: rf = scmd + strlen(program) + 2 + el; ! 1781: sprintf (scmd, "%s%s @%s.gp", program, ! 1782: (search_flag ? "" : ".exe"), temp_filename); ! 1783: argfile = fopen (rf, "w"); 1.1 root 1784: if (argfile == 0) 1.1.1.6 ! root 1785: pfatal_with_name (rf); 1.1 root 1786: 1787: for (i=1; argv[i]; i++) 1.1.1.6 ! root 1788: { ! 1789: char *cp; ! 1790: for (cp = argv[i]; *cp; cp++) ! 1791: { ! 1792: if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp)) ! 1793: fputc ('\\', argfile); ! 1794: fputc (*cp, argfile); ! 1795: } ! 1796: fputc ('\n', argfile); ! 1797: } 1.1.1.3 root 1798: fclose (argfile); 1.1 root 1799: 1.1.1.3 root 1800: i = system (scmd); 1.1 root 1801: 1.1.1.6 ! root 1802: remove (rf); ! 1803: ! 1804: if (i == -1) ! 1805: { ! 1806: perror_exec (program); ! 1807: return MIN_FATAL_STATUS << 8; ! 1808: } ! 1809: 1.1 root 1810: return i << 8; 1811: } 1812: 1813: #else /* not __MSDOS__ */ 1814: 1815: static int 1.1.1.3 root 1816: pexecute (search_flag, program, argv, not_last) 1817: int search_flag; 1.1 root 1818: char *program; 1819: char *argv[]; 1820: int not_last; 1821: { 1.1.1.3 root 1822: int (*func)() = (search_flag ? execv : execvp); 1.1 root 1823: int pid; 1824: int pdes[2]; 1825: int input_desc = last_pipe_input; 1826: int output_desc = STDOUT_FILE_NO; 1827: int retries, sleep_interval; 1828: 1829: /* If this isn't the last process, make a pipe for its output, 1830: and record it as waiting to be the input to the next process. */ 1831: 1832: if (not_last) 1833: { 1834: if (pipe (pdes) < 0) 1835: pfatal_with_name ("pipe"); 1836: output_desc = pdes[WRITE_PORT]; 1837: last_pipe_input = pdes[READ_PORT]; 1838: } 1839: else 1840: last_pipe_input = STDIN_FILE_NO; 1841: 1842: /* Fork a subprocess; wait and retry if it fails. */ 1843: sleep_interval = 1; 1844: for (retries = 0; retries < 4; retries++) 1845: { 1846: pid = vfork (); 1847: if (pid >= 0) 1848: break; 1849: sleep (sleep_interval); 1850: sleep_interval *= 2; 1851: } 1852: 1853: switch (pid) 1854: { 1855: case -1: 1856: #ifdef vfork 1857: pfatal_with_name ("fork"); 1858: #else 1859: pfatal_with_name ("vfork"); 1860: #endif 1861: /* NOTREACHED */ 1862: return 0; 1863: 1864: case 0: /* child */ 1865: /* Move the input and output pipes into place, if nec. */ 1866: if (input_desc != STDIN_FILE_NO) 1867: { 1868: close (STDIN_FILE_NO); 1869: dup (input_desc); 1870: close (input_desc); 1871: } 1872: if (output_desc != STDOUT_FILE_NO) 1873: { 1874: close (STDOUT_FILE_NO); 1875: dup (output_desc); 1876: close (output_desc); 1877: } 1878: 1879: /* Close the parent's descs that aren't wanted here. */ 1880: if (last_pipe_input != STDIN_FILE_NO) 1881: close (last_pipe_input); 1882: 1883: /* Exec the program. */ 1884: (*func) (program, argv); 1885: perror_exec (program); 1886: exit (-1); 1887: /* NOTREACHED */ 1888: return 0; 1889: 1890: default: 1891: /* In the parent, after forking. 1892: Close the descriptors that we made for this child. */ 1893: if (input_desc != STDIN_FILE_NO) 1894: close (input_desc); 1895: if (output_desc != STDOUT_FILE_NO) 1896: close (output_desc); 1897: 1898: /* Return child's process number. */ 1899: return pid; 1900: } 1901: } 1902: 1903: #endif /* not __MSDOS__ */ 1.1.1.3 root 1904: #else /* not OS2 */ 1905: 1906: static int 1907: pexecute (search_flag, program, argv, not_last) 1908: int search_flag; 1909: char *program; 1910: char *argv[]; 1911: int not_last; 1912: { 1913: return (search_flag ? spawnv : spawnvp) (1, program, argv); 1914: } 1915: #endif /* not OS2 */ 1.1 root 1916: 1917: /* Execute the command specified by the arguments on the current line of spec. 1918: When using pipes, this includes several piped-together commands 1919: with `|' between them. 1920: 1921: Return 0 if successful, -1 if failed. */ 1922: 1923: static int 1924: execute () 1925: { 1926: int i; 1927: int n_commands; /* # of command. */ 1928: char *string; 1929: struct command 1930: { 1931: char *prog; /* program name. */ 1932: char **argv; /* vector of args. */ 1933: int pid; /* pid of process for this command. */ 1934: }; 1935: 1936: struct command *commands; /* each command buffer with above info. */ 1937: 1938: /* Count # of piped commands. */ 1939: for (n_commands = 1, i = 0; i < argbuf_index; i++) 1940: if (strcmp (argbuf[i], "|") == 0) 1941: n_commands++; 1942: 1943: /* Get storage for each command. */ 1944: commands 1945: = (struct command *) alloca (n_commands * sizeof (struct command)); 1946: 1947: /* Split argbuf into its separate piped processes, 1948: and record info about each one. 1949: Also search for the programs that are to be run. */ 1950: 1951: commands[0].prog = argbuf[0]; /* first command. */ 1952: commands[0].argv = &argbuf[0]; 1953: string = find_a_file (&exec_prefix, commands[0].prog, X_OK); 1954: if (string) 1955: commands[0].argv[0] = string; 1956: 1957: for (n_commands = 1, i = 0; i < argbuf_index; i++) 1958: if (strcmp (argbuf[i], "|") == 0) 1959: { /* each command. */ 1960: #ifdef __MSDOS__ 1961: fatal ("-pipe not supported under MS-DOS"); 1962: #endif 1963: argbuf[i] = 0; /* termination of command args. */ 1964: commands[n_commands].prog = argbuf[i + 1]; 1965: commands[n_commands].argv = &argbuf[i + 1]; 1966: string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK); 1967: if (string) 1968: commands[n_commands].argv[0] = string; 1969: n_commands++; 1970: } 1971: 1972: argbuf[argbuf_index] = 0; 1973: 1974: /* If -v, print what we are about to do, and maybe query. */ 1975: 1976: if (verbose_flag) 1977: { 1978: /* Print each piped command as a separate line. */ 1979: for (i = 0; i < n_commands ; i++) 1980: { 1981: char **j; 1982: 1983: for (j = commands[i].argv; *j; j++) 1984: fprintf (stderr, " %s", *j); 1985: 1986: /* Print a pipe symbol after all but the last command. */ 1987: if (i + 1 != n_commands) 1988: fprintf (stderr, " |"); 1989: fprintf (stderr, "\n"); 1990: } 1991: fflush (stderr); 1992: #ifdef DEBUG 1993: fprintf (stderr, "\nGo ahead? (y or n) "); 1994: fflush (stderr); 1995: i = getchar (); 1996: if (i != '\n') 1997: while (getchar () != '\n') ; 1998: if (i != 'y' && i != 'Y') 1999: return 0; 2000: #endif /* DEBUG */ 2001: } 2002: 2003: /* Run each piped subprocess. */ 2004: 2005: last_pipe_input = STDIN_FILE_NO; 2006: for (i = 0; i < n_commands; i++) 2007: { 2008: char *string = commands[i].argv[0]; 2009: 1.1.1.3 root 2010: commands[i].pid = pexecute (string != commands[i].prog, 1.1 root 2011: string, commands[i].argv, 2012: i + 1 < n_commands); 2013: 2014: if (string != commands[i].prog) 2015: free (string); 2016: } 2017: 2018: execution_count++; 2019: 2020: /* Wait for all the subprocesses to finish. 2021: We don't care what order they finish in; 2022: we know that N_COMMANDS waits will get them all. */ 2023: 2024: { 2025: int ret_code = 0; 2026: 2027: for (i = 0; i < n_commands; i++) 2028: { 2029: int status; 2030: int pid; 2031: char *prog; 2032: 2033: #ifdef __MSDOS__ 2034: status = pid = commands[i].pid; 2035: #else 2036: pid = wait (&status); 2037: #endif 2038: if (pid < 0) 2039: abort (); 2040: 2041: if (status != 0) 2042: { 2043: int j; 2044: for (j = 0; j < n_commands; j++) 2045: if (commands[j].pid == pid) 2046: prog = commands[j].prog; 2047: 2048: if ((status & 0x7F) != 0) 1.1.1.4 root 2049: { 2050: fatal ("Internal compiler error: program %s got fatal signal %d", 2051: prog, (status & 0x7F)); 2052: signal_count++; 2053: } 1.1 root 2054: if (((status & 0xFF00) >> 8) >= MIN_FATAL_STATUS) 2055: ret_code = -1; 2056: } 2057: } 2058: return ret_code; 2059: } 2060: } 2061: 2062: /* Find all the switches given to us 2063: and make a vector describing them. 2064: The elements of the vector are strings, one per switch given. 2065: If a switch uses following arguments, then the `part1' field 2066: is the switch itself and the `args' field 2067: is a null-terminated vector containing the following arguments. 2068: The `valid' field is nonzero if any spec has looked at this switch; 2069: if it remains zero at the end of the run, it must be meaningless. */ 2070: 2071: struct switchstr 2072: { 2073: char *part1; 2074: char **args; 2075: int valid; 2076: }; 2077: 2078: static struct switchstr *switches; 2079: 2080: static int n_switches; 2081: 2082: struct infile 2083: { 2084: char *name; 2085: char *language; 2086: }; 2087: 2088: /* Also a vector of input files specified. */ 2089: 2090: static struct infile *infiles; 2091: 2092: static int n_infiles; 2093: 2094: /* And a vector of corresponding output files is made up later. */ 2095: 2096: static char **outfiles; 2097: 2098: /* Create the vector `switches' and its contents. 2099: Store its length in `n_switches'. */ 2100: 2101: static void 2102: process_command (argc, argv) 2103: int argc; 2104: char **argv; 2105: { 2106: register int i; 2107: char *temp; 2108: char *spec_lang = 0; 2109: int last_language_n_infiles; 2110: 1.1.1.3 root 2111: gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX"); 2112: 1.1 root 2113: n_switches = 0; 2114: n_infiles = 0; 1.1.1.4 root 2115: 2116: /* Default for -V is our version number, ending at first space. */ 2117: spec_version = save_string (version_string, strlen (version_string)); 2118: for (temp = spec_version; *temp && *temp != ' '; temp++); 2119: if (*temp) *temp = '\0'; 1.1 root 2120: 2121: /* Set up the default search paths. */ 2122: 1.1.1.3 root 2123: if (gcc_exec_prefix) 1.1 root 2124: { 1.1.1.4 root 2125: add_prefix (&exec_prefix, gcc_exec_prefix, 0, 0, NULL_PTR); 2126: add_prefix (&startfile_prefix, gcc_exec_prefix, 0, 0, NULL_PTR); 1.1 root 2127: } 2128: 2129: /* COMPILER_PATH and LIBRARY_PATH have values 2130: that are lists of directory names with colons. */ 2131: 2132: temp = getenv ("COMPILER_PATH"); 2133: if (temp) 2134: { 2135: char *startp, *endp; 2136: char *nstore = (char *) alloca (strlen (temp) + 3); 2137: 2138: startp = endp = temp; 2139: while (1) 2140: { 1.1.1.3 root 2141: if (*endp == PATH_SEPARATOR || *endp == 0) 1.1 root 2142: { 2143: strncpy (nstore, startp, endp-startp); 2144: if (endp == startp) 2145: { 2146: strcpy (nstore, "./"); 2147: } 2148: else if (endp[-1] != '/') 2149: { 2150: nstore[endp-startp] = '/'; 2151: nstore[endp-startp+1] = 0; 2152: } 2153: else 2154: nstore[endp-startp] = 0; 1.1.1.4 root 2155: add_prefix (&exec_prefix, nstore, 0, 0, NULL_PTR); 1.1 root 2156: if (*endp == 0) 2157: break; 2158: endp = startp = endp + 1; 2159: } 2160: else 2161: endp++; 2162: } 2163: } 2164: 2165: temp = getenv ("LIBRARY_PATH"); 2166: if (temp) 2167: { 2168: char *startp, *endp; 2169: char *nstore = (char *) alloca (strlen (temp) + 3); 2170: 2171: startp = endp = temp; 2172: while (1) 2173: { 1.1.1.3 root 2174: if (*endp == PATH_SEPARATOR || *endp == 0) 1.1 root 2175: { 2176: strncpy (nstore, startp, endp-startp); 2177: if (endp == startp) 2178: { 2179: strcpy (nstore, "./"); 2180: } 2181: else if (endp[-1] != '/') 2182: { 2183: nstore[endp-startp] = '/'; 2184: nstore[endp-startp+1] = 0; 2185: } 2186: else 2187: nstore[endp-startp] = 0; 1.1.1.4 root 2188: add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR); 1.1 root 2189: if (*endp == 0) 2190: break; 2191: endp = startp = endp + 1; 2192: } 2193: else 2194: endp++; 2195: } 2196: } 2197: 2198: /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ 2199: temp = getenv ("LPATH"); 2200: if (temp) 2201: { 2202: char *startp, *endp; 2203: char *nstore = (char *) alloca (strlen (temp) + 3); 2204: 2205: startp = endp = temp; 2206: while (1) 2207: { 1.1.1.3 root 2208: if (*endp == PATH_SEPARATOR || *endp == 0) 1.1 root 2209: { 2210: strncpy (nstore, startp, endp-startp); 2211: if (endp == startp) 2212: { 2213: strcpy (nstore, "./"); 2214: } 2215: else if (endp[-1] != '/') 2216: { 2217: nstore[endp-startp] = '/'; 2218: nstore[endp-startp+1] = 0; 2219: } 2220: else 2221: nstore[endp-startp] = 0; 1.1.1.4 root 2222: add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR); 1.1 root 2223: if (*endp == 0) 2224: break; 2225: endp = startp = endp + 1; 2226: } 2227: else 2228: endp++; 2229: } 2230: } 2231: 1.1.1.5 root 2232: /* Convert new-style -- options to old-style. */ 2233: translate_options (&argc, &argv); 2234: 1.1 root 2235: /* Scan argv twice. Here, the first time, just count how many switches 2236: there will be in their vector, and how many input files in theirs. 2237: Here we also parse the switches that cc itself uses (e.g. -v). */ 2238: 2239: for (i = 1; i < argc; i++) 2240: { 2241: if (! strcmp (argv[i], "-dumpspecs")) 2242: { 2243: printf ("*asm:\n%s\n\n", asm_spec); 2244: printf ("*asm_final:\n%s\n\n", asm_final_spec); 2245: printf ("*cpp:\n%s\n\n", cpp_spec); 2246: printf ("*cc1:\n%s\n\n", cc1_spec); 2247: printf ("*cc1plus:\n%s\n\n", cc1plus_spec); 2248: printf ("*endfile:\n%s\n\n", endfile_spec); 2249: printf ("*link:\n%s\n\n", link_spec); 2250: printf ("*lib:\n%s\n\n", lib_spec); 2251: printf ("*startfile:\n%s\n\n", startfile_spec); 2252: printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces); 2253: printf ("*signed_char:\n%s\n\n", signed_char_spec); 2254: printf ("*predefines:\n%s\n\n", cpp_predefines); 1.1.1.2 root 2255: printf ("*cross_compile:\n%d\n\n", cross_compile); 1.1 root 2256: 2257: exit (0); 2258: } 2259: else if (! strcmp (argv[i], "-dumpversion")) 2260: { 2261: printf ("%s\n", version_string); 2262: exit (0); 2263: } 1.1.1.3 root 2264: else if (! strcmp (argv[i], "-print-libgcc-file-name")) 2265: { 2266: print_libgcc_file_name = 1; 2267: } 1.1 root 2268: else if (! strcmp (argv[i], "-Xlinker")) 2269: { 2270: /* Pass the argument of this option to the linker when we link. */ 2271: 2272: if (i + 1 == argc) 2273: fatal ("argument to `-Xlinker' is missing"); 2274: 2275: n_linker_options++; 2276: if (!linker_options) 2277: linker_options 2278: = (char **) xmalloc (n_linker_options * sizeof (char **)); 2279: else 2280: linker_options 2281: = (char **) xrealloc (linker_options, 2282: n_linker_options * sizeof (char **)); 2283: 2284: linker_options[n_linker_options - 1] = argv[++i]; 2285: } 1.1.1.4 root 2286: else if (! strncmp (argv[i], "-Wl,", 4)) 2287: { 2288: int prev, j; 2289: /* Pass the rest of this option to the linker when we link. */ 2290: 2291: n_linker_options++; 2292: if (!linker_options) 2293: linker_options 2294: = (char **) xmalloc (n_linker_options * sizeof (char **)); 2295: else 2296: linker_options 2297: = (char **) xrealloc (linker_options, 2298: n_linker_options * sizeof (char **)); 2299: 2300: /* Split the argument at commas. */ 2301: prev = 4; 2302: for (j = 4; argv[i][j]; j++) 2303: if (argv[i][j] == ',') 2304: { 2305: linker_options[n_linker_options - 1] 2306: = save_string (argv[i] + prev, j - prev); 2307: n_linker_options++; 2308: linker_options 2309: = (char **) xrealloc (linker_options, 2310: n_linker_options * sizeof (char **)); 2311: prev = j + 1; 2312: } 2313: /* Record the part after the last comma. */ 2314: linker_options[n_linker_options - 1] = argv[i] + prev; 2315: } 2316: else if (! strncmp (argv[i], "-Wa,", 4)) 2317: { 2318: int prev, j; 2319: /* Pass the rest of this option to the assembler. */ 2320: 2321: n_assembler_options++; 2322: if (!assembler_options) 2323: assembler_options 2324: = (char **) xmalloc (n_assembler_options * sizeof (char **)); 2325: else 2326: assembler_options 2327: = (char **) xrealloc (assembler_options, 2328: n_assembler_options * sizeof (char **)); 2329: 2330: /* Split the argument at commas. */ 2331: prev = 4; 2332: for (j = 4; argv[i][j]; j++) 2333: if (argv[i][j] == ',') 2334: { 2335: assembler_options[n_assembler_options - 1] 2336: = save_string (argv[i] + prev, j - prev); 2337: n_assembler_options++; 2338: assembler_options 2339: = (char **) xrealloc (assembler_options, 2340: n_assembler_options * sizeof (char **)); 2341: prev = j + 1; 2342: } 2343: /* Record the part after the last comma. */ 2344: assembler_options[n_assembler_options - 1] = argv[i] + prev; 2345: } 2346: else if (argv[i][0] == '+' && argv[i][1] == 'e') 1.1.1.5 root 2347: /* The +e options to the C++ front-end. */ 1.1.1.4 root 2348: n_switches++; 1.1 root 2349: else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l') 2350: { 2351: register char *p = &argv[i][1]; 2352: register int c = *p; 2353: 2354: switch (c) 2355: { 2356: case 'b': 2357: if (p[1] == 0 && i + 1 == argc) 2358: fatal ("argument to `-b' is missing"); 2359: if (p[1] == 0) 2360: spec_machine = argv[++i]; 2361: else 2362: spec_machine = p + 1; 2363: break; 2364: 2365: case 'B': 2366: { 2367: int *temp = (int *) xmalloc (sizeof (int)); 2368: char *value; 2369: if (p[1] == 0 && i + 1 == argc) 2370: fatal ("argument to `-B' is missing"); 2371: if (p[1] == 0) 2372: value = argv[++i]; 2373: else 2374: value = p + 1; 2375: add_prefix (&exec_prefix, value, 1, 0, temp); 2376: add_prefix (&startfile_prefix, value, 1, 0, temp); 2377: } 2378: break; 2379: 2380: case 'v': /* Print our subcommands and print versions. */ 2381: n_switches++; 1.1.1.4 root 2382: /* If they do anything other than exactly `-v', don't set 2383: verbose_flag; rather, continue on to give the error. */ 2384: if (p[1] != 0) 2385: break; 2386: verbose_flag++; 1.1 root 2387: break; 2388: 2389: case 'V': 2390: if (p[1] == 0 && i + 1 == argc) 2391: fatal ("argument to `-V' is missing"); 2392: if (p[1] == 0) 2393: spec_version = argv[++i]; 2394: else 2395: spec_version = p + 1; 2396: break; 2397: 2398: case 's': 2399: if (!strcmp (p, "save-temps")) 2400: { 2401: save_temps_flag = 1; 1.1.1.3 root 2402: n_switches++; 1.1 root 2403: break; 2404: } 2405: default: 2406: n_switches++; 2407: 2408: if (SWITCH_TAKES_ARG (c) > (p[1] != 0)) 2409: i += SWITCH_TAKES_ARG (c) - (p[1] != 0); 2410: else if (WORD_SWITCH_TAKES_ARG (p)) 2411: i += WORD_SWITCH_TAKES_ARG (p); 2412: } 2413: } 2414: else 2415: n_infiles++; 2416: } 2417: 2418: /* Set up the search paths before we go looking for config files. */ 2419: 2420: /* These come before the md prefixes so that we will find gcc's subcommands 2421: (such as cpp) rather than those of the host system. */ 1.1.1.4 root 2422: /* Use 2 as fourth arg meaning try just the machine as a suffix, 2423: as well as trying the machine and the version. */ 2424: add_prefix (&exec_prefix, standard_exec_prefix, 0, 2, NULL_PTR); 2425: add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 2, NULL_PTR); 1.1 root 2426: 1.1.1.4 root 2427: add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, NULL_PTR); 2428: add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, NULL_PTR); 1.1 root 2429: 1.1.1.5 root 2430: tooldir_prefix = concat (tooldir_base_prefix, spec_machine, "/"); 2431: 2432: /* If tooldir is relative, base it on exec_prefix. A relative 2433: tooldir lets us move the installed tree as a unit. 2434: 2435: If GCC_EXEC_PREFIX is defined, then we want to add two relative 2436: directories, so that we can search both the user specified directory 2437: and the standard place. */ 2438: 2439: if (*tooldir_prefix != '/') 2440: { 2441: if (gcc_exec_prefix) 2442: { 2443: char *gcc_exec_tooldir_prefix 2444: = concat (concat (gcc_exec_prefix, spec_machine, "/"), 2445: concat (spec_version, "/", tooldir_prefix), 2446: ""); 2447: 2448: add_prefix (&exec_prefix, concat (gcc_exec_tooldir_prefix, "bin", "/"), 2449: 0, 0, NULL_PTR); 2450: add_prefix (&startfile_prefix, concat (gcc_exec_tooldir_prefix, "lib", "/"), 2451: 0, 0, NULL_PTR); 2452: } 2453: 2454: tooldir_prefix = concat (concat (standard_exec_prefix, spec_machine, "/"), 2455: concat (spec_version, "/", tooldir_prefix), 2456: ""); 2457: } 2458: 2459: add_prefix (&exec_prefix, concat (tooldir_prefix, "bin", "/"), 2460: 0, 0, NULL_PTR); 2461: add_prefix (&startfile_prefix, concat (tooldir_prefix, "lib", "/"), 2462: 0, 0, NULL_PTR); 2463: 1.1.1.2 root 2464: /* More prefixes are enabled in main, after we read the specs file 2465: and determine whether this is cross-compilation or not. */ 1.1 root 2466: 2467: 2468: /* Then create the space for the vectors and scan again. */ 2469: 2470: switches = ((struct switchstr *) 2471: xmalloc ((n_switches + 1) * sizeof (struct switchstr))); 2472: infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile)); 2473: n_switches = 0; 2474: n_infiles = 0; 2475: last_language_n_infiles = -1; 2476: 2477: /* This, time, copy the text of each switch and store a pointer 2478: to the copy in the vector of switches. 2479: Store all the infiles in their vector. */ 2480: 2481: for (i = 1; i < argc; i++) 2482: { 1.1.1.4 root 2483: /* Just skip the switches that were handled by the preceding loop. */ 1.1 root 2484: if (!strcmp (argv[i], "-Xlinker")) 2485: i++; 1.1.1.4 root 2486: else if (! strncmp (argv[i], "-Wl,", 4)) 2487: ; 2488: else if (! strncmp (argv[i], "-Wa,", 4)) 2489: ; 1.1.1.3 root 2490: else if (! strcmp (argv[i], "-print-libgcc-file-name")) 1.1.1.4 root 2491: ; 2492: else if (argv[i][0] == '+' && argv[i][1] == 'e') 2493: { 2494: /* Compensate for the +e options to the C++ front-end; 1.1.1.5 root 2495: they're there simply for cfront call-compatibility. We do 1.1.1.4 root 2496: some magic in default_compilers to pass them down properly. 2497: Note we deliberately start at the `+' here, to avoid passing 2498: -e0 or -e1 down into the linker. */ 2499: switches[n_switches].part1 = &argv[i][0]; 2500: switches[n_switches].args = 0; 2501: switches[n_switches].valid = 0; 2502: n_switches++; 2503: } 1.1 root 2504: else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l') 2505: { 2506: register char *p = &argv[i][1]; 2507: register int c = *p; 2508: 2509: if (c == 'B' || c == 'b' || c == 'V') 2510: { 2511: /* Skip a separate arg, if any. */ 2512: if (p[1] == 0) 2513: i++; 2514: continue; 2515: } 2516: if (c == 'x') 2517: { 2518: if (p[1] == 0 && i + 1 == argc) 2519: fatal ("argument to `-x' is missing"); 2520: if (p[1] == 0) 2521: spec_lang = argv[++i]; 2522: else 2523: spec_lang = p + 1; 2524: if (! strcmp (spec_lang, "none")) 2525: /* Suppress the warning if -xnone comes after the last input file, 2526: because alternate command interfaces like g++ might find it 2527: useful to place -xnone after each input file. */ 2528: spec_lang = 0; 2529: else 2530: last_language_n_infiles = n_infiles; 2531: continue; 2532: } 2533: switches[n_switches].part1 = p; 2534: /* Deal with option arguments in separate argv elements. */ 2535: if ((SWITCH_TAKES_ARG (c) > (p[1] != 0)) 1.1.1.6 ! root 2536: || WORD_SWITCH_TAKES_ARG (p)) ! 2537: { ! 2538: int j = 0; ! 2539: int n_args = WORD_SWITCH_TAKES_ARG (p); ! 2540: ! 2541: if (n_args == 0) ! 2542: { ! 2543: /* Count only the option arguments in separate argv elements. */ ! 2544: n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0); ! 2545: } ! 2546: if (i + n_args >= argc) ! 2547: fatal ("argument to `-%s' is missing", p); ! 2548: switches[n_switches].args ! 2549: = (char **) xmalloc ((n_args + 1) * sizeof (char *)); ! 2550: while (j < n_args) ! 2551: switches[n_switches].args[j++] = argv[++i]; ! 2552: /* Null-terminate the vector. */ ! 2553: switches[n_switches].args[j] = 0; 1.1 root 2554: } 1.1.1.6 ! root 2555: else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L')) ! 2556: { ! 2557: /* On some systems, ld cannot handle -o or -L without space. ! 2558: So split the -o or -L from its argument. */ ! 2559: switches[n_switches].part1 = (c == 'o' ? "o" : "L"); ! 2560: switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *)); ! 2561: switches[n_switches].args[0] = xmalloc (strlen (p)); ! 2562: strcpy (switches[n_switches].args[0], &p[1]); ! 2563: switches[n_switches].args[1] = 0; ! 2564: } ! 2565: else 1.1 root 2566: switches[n_switches].args = 0; 2567: switches[n_switches].valid = 0; 2568: /* This is always valid, since gcc.c itself understands it. */ 2569: if (!strcmp (p, "save-temps")) 2570: switches[n_switches].valid = 1; 2571: n_switches++; 2572: } 2573: else 2574: { 1.1.1.5 root 2575: if ((argv[i][0] != '-' || argv[i][1] != 'l') 1.1.1.6 ! root 2576: && strcmp (argv[i], "-") 1.1.1.5 root 2577: && access (argv[i], R_OK) < 0) 2578: { 2579: perror_with_name (argv[i]); 2580: error_count++; 2581: } 2582: else 2583: { 2584: infiles[n_infiles].language = spec_lang; 2585: infiles[n_infiles++].name = argv[i]; 2586: } 1.1 root 2587: } 2588: } 2589: 1.1.1.6 ! root 2590: if (n_infiles == last_language_n_infiles && spec_lang != 0) 1.1 root 2591: error ("Warning: `-x %s' after last input file has no effect", spec_lang); 2592: 2593: switches[n_switches].part1 = 0; 2594: infiles[n_infiles].name = 0; 1.1.1.3 root 2595: 2596: /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */ 2597: if (gcc_exec_prefix) 2598: { 2599: temp = (char *) xmalloc (strlen (gcc_exec_prefix) + strlen (spec_version) 2600: + strlen (spec_machine) + 3); 2601: strcpy (temp, gcc_exec_prefix); 2602: strcat (temp, spec_machine); 2603: strcat (temp, "/"); 2604: strcat (temp, spec_version); 2605: strcat (temp, "/"); 2606: gcc_exec_prefix = temp; 2607: } 1.1 root 2608: } 2609: 2610: /* Process a spec string, accumulating and running commands. */ 2611: 2612: /* These variables describe the input file name. 2613: input_file_number is the index on outfiles of this file, 2614: so that the output file name can be stored for later use by %o. 2615: input_basename is the start of the part of the input file 2616: sans all directory names, and basename_length is the number 2617: of characters starting there excluding the suffix .c or whatever. */ 2618: 2619: static char *input_filename; 2620: static int input_file_number; 2621: static int input_filename_length; 2622: static int basename_length; 2623: static char *input_basename; 2624: static char *input_suffix; 2625: 2626: /* These are variables used within do_spec and do_spec_1. */ 2627: 2628: /* Nonzero if an arg has been started and not yet terminated 2629: (with space, tab or newline). */ 2630: static int arg_going; 2631: 2632: /* Nonzero means %d or %g has been seen; the next arg to be terminated 2633: is a temporary file name. */ 2634: static int delete_this_arg; 2635: 2636: /* Nonzero means %w has been seen; the next arg to be terminated 2637: is the output file name of this compilation. */ 2638: static int this_is_output_file; 2639: 2640: /* Nonzero means %s has been seen; the next arg to be terminated 2641: is the name of a library file and we should try the standard 2642: search dirs for it. */ 2643: static int this_is_library_file; 2644: 1.1.1.5 root 2645: /* Nonzero means that the input of this command is coming from a pipe. */ 2646: static int input_from_pipe; 2647: 1.1 root 2648: /* Process the spec SPEC and run the commands specified therein. 2649: Returns 0 if the spec is successfully processed; -1 if failed. */ 2650: 2651: static int 2652: do_spec (spec) 2653: char *spec; 2654: { 2655: int value; 2656: 2657: clear_args (); 2658: arg_going = 0; 2659: delete_this_arg = 0; 2660: this_is_output_file = 0; 2661: this_is_library_file = 0; 1.1.1.5 root 2662: input_from_pipe = 0; 1.1 root 2663: 1.1.1.4 root 2664: value = do_spec_1 (spec, 0, NULL_PTR); 1.1 root 2665: 2666: /* Force out any unfinished command. 2667: If -pipe, this forces out the last command if it ended in `|'. */ 2668: if (value == 0) 2669: { 2670: if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) 2671: argbuf_index--; 2672: 2673: if (argbuf_index > 0) 2674: value = execute (); 2675: } 2676: 2677: return value; 2678: } 2679: 2680: /* Process the sub-spec SPEC as a portion of a larger spec. 2681: This is like processing a whole spec except that we do 2682: not initialize at the beginning and we do not supply a 2683: newline by default at the end. 2684: INSWITCH nonzero means don't process %-sequences in SPEC; 2685: in this case, % is treated as an ordinary character. 2686: This is used while substituting switches. 2687: INSWITCH nonzero also causes SPC not to terminate an argument. 2688: 2689: Value is zero unless a line was finished 2690: and the command on that line reported an error. */ 2691: 2692: static int 2693: do_spec_1 (spec, inswitch, soft_matched_part) 2694: char *spec; 2695: int inswitch; 2696: char *soft_matched_part; 2697: { 2698: register char *p = spec; 2699: register int c; 2700: int i; 2701: char *string; 1.1.1.5 root 2702: int value; 1.1 root 2703: 2704: while (c = *p++) 2705: /* If substituting a switch, treat all chars like letters. 2706: Otherwise, NL, SPC, TAB and % are special. */ 2707: switch (inswitch ? 'a' : c) 2708: { 2709: case '\n': 2710: /* End of line: finish any pending argument, 2711: then run the pending command if one has been started. */ 2712: if (arg_going) 2713: { 2714: obstack_1grow (&obstack, 0); 2715: string = obstack_finish (&obstack); 2716: if (this_is_library_file) 2717: string = find_file (string); 2718: store_arg (string, delete_this_arg, this_is_output_file); 2719: if (this_is_output_file) 2720: outfiles[input_file_number] = string; 2721: } 2722: arg_going = 0; 2723: 2724: if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) 2725: { 2726: int i; 2727: for (i = 0; i < n_switches; i++) 2728: if (!strcmp (switches[i].part1, "pipe")) 2729: break; 2730: 2731: /* A `|' before the newline means use a pipe here, 2732: but only if -pipe was specified. 2733: Otherwise, execute now and don't pass the `|' as an arg. */ 2734: if (i < n_switches) 2735: { 1.1.1.5 root 2736: input_from_pipe = 1; 1.1 root 2737: switches[i].valid = 1; 2738: break; 2739: } 2740: else 2741: argbuf_index--; 2742: } 2743: 2744: if (argbuf_index > 0) 2745: { 1.1.1.5 root 2746: value = execute (); 1.1 root 2747: if (value) 2748: return value; 2749: } 2750: /* Reinitialize for a new command, and for a new argument. */ 2751: clear_args (); 2752: arg_going = 0; 2753: delete_this_arg = 0; 2754: this_is_output_file = 0; 2755: this_is_library_file = 0; 1.1.1.5 root 2756: input_from_pipe = 0; 1.1 root 2757: break; 2758: 2759: case '|': 2760: /* End any pending argument. */ 2761: if (arg_going) 2762: { 2763: obstack_1grow (&obstack, 0); 2764: string = obstack_finish (&obstack); 2765: if (this_is_library_file) 2766: string = find_file (string); 2767: store_arg (string, delete_this_arg, this_is_output_file); 2768: if (this_is_output_file) 2769: outfiles[input_file_number] = string; 2770: } 2771: 2772: /* Use pipe */ 2773: obstack_1grow (&obstack, c); 2774: arg_going = 1; 2775: break; 2776: 2777: case '\t': 2778: case ' ': 2779: /* Space or tab ends an argument if one is pending. */ 2780: if (arg_going) 2781: { 2782: obstack_1grow (&obstack, 0); 2783: string = obstack_finish (&obstack); 2784: if (this_is_library_file) 2785: string = find_file (string); 2786: store_arg (string, delete_this_arg, this_is_output_file); 2787: if (this_is_output_file) 2788: outfiles[input_file_number] = string; 2789: } 2790: /* Reinitialize for a new argument. */ 2791: arg_going = 0; 2792: delete_this_arg = 0; 2793: this_is_output_file = 0; 2794: this_is_library_file = 0; 2795: break; 2796: 2797: case '%': 2798: switch (c = *p++) 2799: { 2800: case 0: 2801: fatal ("Invalid specification! Bug in cc."); 2802: 2803: case 'b': 2804: obstack_grow (&obstack, input_basename, basename_length); 2805: arg_going = 1; 2806: break; 2807: 2808: case 'd': 2809: delete_this_arg = 2; 2810: break; 2811: 2812: /* Dump out the directories specified with LIBRARY_PATH, 2813: followed by the absolute directories 2814: that we search for startfiles. */ 2815: case 'D': 1.1.1.5 root 2816: { 2817: struct prefix_list *pl = startfile_prefix.plist; 2818: int bufsize = 100; 2819: char *buffer = (char *) xmalloc (bufsize); 2820: int idx; 1.1.1.3 root 2821: 1.1.1.5 root 2822: for (; pl; pl = pl->next) 2823: { 1.1 root 2824: #ifdef RELATIVE_PREFIX_NOT_LINKDIR 1.1.1.5 root 2825: /* Used on systems which record the specified -L dirs 2826: and use them to search for dynamic linking. */ 2827: /* Relative directories always come from -B, 2828: and it is better not to use them for searching 2829: at run time. In particular, stage1 loses */ 2830: if (pl->prefix[0] != '/') 2831: continue; 1.1 root 2832: #endif 1.1.1.5 root 2833: if (machine_suffix) 2834: { 2835: if (is_directory (pl->prefix, machine_suffix, 1)) 2836: { 2837: do_spec_1 ("-L", 0, NULL_PTR); 1.1 root 2838: #ifdef SPACE_AFTER_L_OPTION 1.1.1.5 root 2839: do_spec_1 (" ", 0, NULL_PTR); 1.1 root 2840: #endif 1.1.1.5 root 2841: do_spec_1 (pl->prefix, 1, NULL_PTR); 2842: /* Remove slash from machine_suffix. */ 2843: if (strlen (machine_suffix) >= bufsize) 2844: bufsize = strlen (machine_suffix) * 2 + 1; 2845: buffer = (char *) xrealloc (buffer, bufsize); 2846: strcpy (buffer, machine_suffix); 2847: idx = strlen (buffer); 2848: if (buffer[idx - 1] == '/') 2849: buffer[idx - 1] = 0; 2850: do_spec_1 (buffer, 1, NULL_PTR); 2851: /* Make this a separate argument. */ 2852: do_spec_1 (" ", 0, NULL_PTR); 2853: } 2854: } 2855: if (!pl->require_machine_suffix) 2856: { 2857: if (is_directory (pl->prefix, "", 1)) 2858: { 2859: do_spec_1 ("-L", 0, NULL_PTR); 1.1 root 2860: #ifdef SPACE_AFTER_L_OPTION 1.1.1.5 root 2861: do_spec_1 (" ", 0, NULL_PTR); 1.1 root 2862: #endif 1.1.1.5 root 2863: /* Remove slash from pl->prefix. */ 2864: if (strlen (pl->prefix) >= bufsize) 2865: bufsize = strlen (pl->prefix) * 2 + 1; 2866: buffer = (char *) xrealloc (buffer, bufsize); 2867: strcpy (buffer, pl->prefix); 2868: idx = strlen (buffer); 2869: if (buffer[idx - 1] == '/') 2870: buffer[idx - 1] = 0; 2871: do_spec_1 (buffer, 1, NULL_PTR); 2872: /* Make this a separate argument. */ 2873: do_spec_1 (" ", 0, NULL_PTR); 2874: } 2875: } 2876: } 2877: free (buffer); 2878: } 1.1 root 2879: break; 2880: 2881: case 'e': 2882: /* {...:%efoo} means report an error with `foo' as error message 2883: and don't execute any more commands for this file. */ 2884: { 2885: char *q = p; 2886: char *buf; 2887: while (*p != 0 && *p != '\n') p++; 2888: buf = (char *) alloca (p - q + 1); 2889: strncpy (buf, q, p - q); 2890: buf[p - q] = 0; 2891: error ("%s", buf); 2892: return -1; 2893: } 2894: break; 2895: 2896: case 'g': 1.1.1.4 root 2897: case 'u': 2898: case 'U': 1.1 root 2899: if (save_temps_flag) 2900: obstack_grow (&obstack, input_basename, basename_length); 2901: else 2902: { 1.1.1.4 root 2903: #ifdef MKTEMP_EACH_FILE 2904: /* ??? This has a problem: the total number of 2905: values mktemp can return is limited. 2906: That matters for the names of object files. 2907: In 2.4, do something about that. */ 2908: struct temp_name *t; 2909: char *suffix = p; 2910: while (*p == '.' || isalpha (*p)) 2911: p++; 2912: 2913: /* See if we already have an association of %g/%u/%U and 2914: suffix. */ 2915: for (t = temp_names; t; t = t->next) 2916: if (t->length == p - suffix 2917: && strncmp (t->suffix, suffix, p - suffix) == 0 2918: && t->unique == (c != 'g')) 2919: break; 2920: 2921: /* Make a new association if needed. %u requires one. */ 2922: if (t == 0 || c == 'u') 2923: { 2924: if (t == 0) 2925: { 2926: t = (struct temp_name *) xmalloc (sizeof (struct temp_name)); 2927: t->next = temp_names; 2928: temp_names = t; 2929: } 2930: t->length = p - suffix; 2931: t->suffix = save_string (suffix, p - suffix); 2932: t->unique = (c != 'g'); 2933: choose_temp_base (); 2934: t->filename = temp_filename; 2935: t->filename_length = temp_filename_length; 2936: } 2937: 2938: obstack_grow (&obstack, t->filename, t->filename_length); 2939: delete_this_arg = 1; 2940: #else 1.1 root 2941: obstack_grow (&obstack, temp_filename, temp_filename_length); 1.1.1.4 root 2942: if (c == 'u' || c == 'U') 2943: { 2944: static int unique; 2945: char buff[9]; 2946: if (c == 'u') 2947: unique++; 2948: sprintf (buff, "%d", unique); 2949: obstack_grow (&obstack, buff, strlen (buff)); 2950: } 2951: #endif 1.1 root 2952: delete_this_arg = 1; 2953: } 2954: arg_going = 1; 2955: break; 2956: 2957: case 'i': 2958: obstack_grow (&obstack, input_filename, input_filename_length); 2959: arg_going = 1; 2960: break; 2961: 1.1.1.3 root 2962: case 'I': 2963: if (gcc_exec_prefix) 2964: { 1.1.1.4 root 2965: do_spec_1 ("-iprefix", 1, NULL_PTR); 1.1.1.3 root 2966: /* Make this a separate argument. */ 1.1.1.4 root 2967: do_spec_1 (" ", 0, NULL_PTR); 2968: do_spec_1 (gcc_exec_prefix, 1, NULL_PTR); 2969: do_spec_1 (" ", 0, NULL_PTR); 1.1.1.3 root 2970: } 2971: break; 2972: 1.1 root 2973: case 'o': 2974: { 2975: register int f; 2976: for (f = 0; f < n_infiles; f++) 2977: store_arg (outfiles[f], 0, 0); 2978: } 2979: break; 2980: 2981: case 's': 2982: this_is_library_file = 1; 2983: break; 2984: 2985: case 'w': 2986: this_is_output_file = 1; 2987: break; 2988: 2989: case 'W': 2990: { 2991: int index = argbuf_index; 2992: /* Handle the {...} following the %W. */ 2993: if (*p != '{') 2994: abort (); 2995: p = handle_braces (p + 1); 2996: if (p == 0) 2997: return -1; 2998: /* If any args were output, mark the last one for deletion 2999: on failure. */ 3000: if (argbuf_index != index) 3001: record_temp_file (argbuf[argbuf_index - 1], 0, 1); 3002: break; 3003: } 3004: 3005: /* %x{OPTION} records OPTION for %X to output. */ 3006: case 'x': 3007: { 3008: char *p1 = p; 3009: char *string; 3010: 3011: /* Skip past the option value and make a copy. */ 3012: if (*p != '{') 3013: abort (); 3014: while (*p++ != '}') 3015: ; 3016: string = save_string (p1 + 1, p - p1 - 2); 3017: 3018: /* See if we already recorded this option. */ 3019: for (i = 0; i < n_linker_options; i++) 3020: if (! strcmp (string, linker_options[i])) 3021: { 3022: free (string); 3023: return 0; 3024: } 3025: 3026: /* This option is new; add it. */ 3027: n_linker_options++; 3028: if (!linker_options) 3029: linker_options 3030: = (char **) xmalloc (n_linker_options * sizeof (char **)); 3031: else 3032: linker_options 3033: = (char **) xrealloc (linker_options, 3034: n_linker_options * sizeof (char **)); 3035: 3036: linker_options[n_linker_options - 1] = string; 3037: } 3038: break; 3039: 1.1.1.4 root 3040: /* Dump out the options accumulated previously using %x, 3041: -Xlinker and -Wl,. */ 1.1 root 3042: case 'X': 3043: for (i = 0; i < n_linker_options; i++) 3044: { 1.1.1.4 root 3045: do_spec_1 (linker_options[i], 1, NULL_PTR); 1.1 root 3046: /* Make each accumulated option a separate argument. */ 1.1.1.4 root 3047: do_spec_1 (" ", 0, NULL_PTR); 3048: } 3049: break; 3050: 3051: /* Dump out the options accumulated previously using -Wa,. */ 3052: case 'Y': 3053: for (i = 0; i < n_assembler_options; i++) 3054: { 3055: do_spec_1 (assembler_options[i], 1, NULL_PTR); 3056: /* Make each accumulated option a separate argument. */ 3057: do_spec_1 (" ", 0, NULL_PTR); 1.1 root 3058: } 3059: break; 3060: 3061: /* Here are digits and numbers that just process 3062: a certain constant string as a spec. */ 3063: 3064: case '1': 1.1.1.5 root 3065: value = do_spec_1 (cc1_spec, 0, NULL_PTR); 3066: if (value != 0) 3067: return value; 1.1 root 3068: break; 3069: 3070: case '2': 1.1.1.5 root 3071: value = do_spec_1 (cc1plus_spec, 0, NULL_PTR); 3072: if (value != 0) 3073: return value; 1.1 root 3074: break; 3075: 3076: case 'a': 1.1.1.5 root 3077: value = do_spec_1 (asm_spec, 0, NULL_PTR); 3078: if (value != 0) 3079: return value; 1.1 root 3080: break; 3081: 3082: case 'A': 1.1.1.5 root 3083: value = do_spec_1 (asm_final_spec, 0, NULL_PTR); 3084: if (value != 0) 3085: return value; 1.1 root 3086: break; 3087: 3088: case 'c': 1.1.1.5 root 3089: value = do_spec_1 (signed_char_spec, 0, NULL_PTR); 3090: if (value != 0) 3091: return value; 1.1 root 3092: break; 3093: 3094: case 'C': 1.1.1.5 root 3095: value = do_spec_1 (cpp_spec, 0, NULL_PTR); 3096: if (value != 0) 3097: return value; 1.1 root 3098: break; 3099: 3100: case 'E': 1.1.1.5 root 3101: value = do_spec_1 (endfile_spec, 0, NULL_PTR); 3102: if (value != 0) 3103: return value; 1.1 root 3104: break; 3105: 3106: case 'l': 1.1.1.5 root 3107: value = do_spec_1 (link_spec, 0, NULL_PTR); 3108: if (value != 0) 3109: return value; 1.1 root 3110: break; 3111: 3112: case 'L': 1.1.1.5 root 3113: value = do_spec_1 (lib_spec, 0, NULL_PTR); 3114: if (value != 0) 3115: return value; 1.1 root 3116: break; 3117: 3118: case 'p': 3119: { 3120: char *x = (char *) alloca (strlen (cpp_predefines) + 1); 3121: char *buf = x; 3122: char *y; 3123: 3124: /* Copy all of the -D options in CPP_PREDEFINES into BUF. */ 3125: y = cpp_predefines; 3126: while (*y != 0) 3127: { 3128: if (! strncmp (y, "-D", 2)) 3129: /* Copy the whole option. */ 3130: while (*y && *y != ' ' && *y != '\t') 3131: *x++ = *y++; 3132: else if (*y == ' ' || *y == '\t') 3133: /* Copy whitespace to the result. */ 3134: *x++ = *y++; 3135: /* Don't copy other options. */ 3136: else 3137: y++; 3138: } 3139: 3140: *x = 0; 3141: 1.1.1.5 root 3142: value = do_spec_1 (buf, 0, NULL_PTR); 3143: if (value != 0) 3144: return value; 1.1 root 3145: } 3146: break; 3147: 3148: case 'P': 3149: { 3150: char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1); 3151: char *buf = x; 3152: char *y; 3153: 3154: /* Copy all of CPP_PREDEFINES into BUF, 3155: but put __ after every -D and at the end of each arg. */ 3156: y = cpp_predefines; 3157: while (*y != 0) 3158: { 3159: if (! strncmp (y, "-D", 2)) 3160: { 3161: int flag = 0; 3162: 3163: *x++ = *y++; 3164: *x++ = *y++; 3165: 3166: if (strncmp (y, "__", 2)) 3167: { 3168: /* Stick __ at front of macro name. */ 3169: *x++ = '_'; 3170: *x++ = '_'; 3171: /* Arrange to stick __ at the end as well. */ 3172: flag = 1; 3173: } 3174: 3175: /* Copy the macro name. */ 3176: while (*y && *y != '=' && *y != ' ' && *y != '\t') 3177: *x++ = *y++; 3178: 3179: if (flag) 3180: { 3181: *x++ = '_'; 3182: *x++ = '_'; 3183: } 3184: 3185: /* Copy the value given, if any. */ 3186: while (*y && *y != ' ' && *y != '\t') 3187: *x++ = *y++; 3188: } 3189: else if (*y == ' ' || *y == '\t') 3190: /* Copy whitespace to the result. */ 3191: *x++ = *y++; 3192: /* Don't copy -A options */ 3193: else 3194: y++; 3195: } 3196: *x++ = ' '; 3197: 3198: /* Copy all of CPP_PREDEFINES into BUF, 3199: but put __ after every -D. */ 3200: y = cpp_predefines; 3201: while (*y != 0) 3202: { 3203: if (! strncmp (y, "-D", 2)) 3204: { 3205: *x++ = *y++; 3206: *x++ = *y++; 3207: 3208: if (strncmp (y, "__", 2)) 3209: { 3210: /* Stick __ at front of macro name. */ 3211: *x++ = '_'; 3212: *x++ = '_'; 3213: } 3214: 3215: /* Copy the macro name. */ 3216: while (*y && *y != '=' && *y != ' ' && *y != '\t') 3217: *x++ = *y++; 3218: 3219: /* Copy the value given, if any. */ 3220: while (*y && *y != ' ' && *y != '\t') 3221: *x++ = *y++; 3222: } 3223: else if (*y == ' ' || *y == '\t') 3224: /* Copy whitespace to the result. */ 3225: *x++ = *y++; 3226: /* Don't copy -A options */ 3227: else 3228: y++; 3229: } 3230: *x++ = ' '; 3231: 3232: /* Copy all of the -A options in CPP_PREDEFINES into BUF. */ 3233: y = cpp_predefines; 3234: while (*y != 0) 3235: { 3236: if (! strncmp (y, "-A", 2)) 3237: /* Copy the whole option. */ 3238: while (*y && *y != ' ' && *y != '\t') 3239: *x++ = *y++; 3240: else if (*y == ' ' || *y == '\t') 3241: /* Copy whitespace to the result. */ 3242: *x++ = *y++; 3243: /* Don't copy other options. */ 3244: else 3245: y++; 3246: } 3247: 3248: *x = 0; 3249: 1.1.1.5 root 3250: value = do_spec_1 (buf, 0, NULL_PTR); 3251: if (value != 0) 3252: return value; 1.1 root 3253: } 3254: break; 3255: 3256: case 'S': 1.1.1.5 root 3257: value = do_spec_1 (startfile_spec, 0, NULL_PTR); 3258: if (value != 0) 3259: return value; 1.1 root 3260: break; 3261: 3262: /* Here we define characters other than letters and digits. */ 3263: 3264: case '{': 3265: p = handle_braces (p); 3266: if (p == 0) 3267: return -1; 3268: break; 3269: 3270: case '%': 3271: obstack_1grow (&obstack, '%'); 3272: break; 3273: 3274: case '*': 1.1.1.4 root 3275: do_spec_1 (soft_matched_part, 1, NULL_PTR); 3276: do_spec_1 (" ", 0, NULL_PTR); 1.1 root 3277: break; 3278: 3279: /* Process a string found as the value of a spec given by name. 3280: This feature allows individual machine descriptions 3281: to add and use their own specs. 3282: %[...] modifies -D options the way %P does; 3283: %(...) uses the spec unmodified. */ 3284: case '(': 3285: case '[': 3286: { 3287: char *name = p; 3288: struct spec_list *sl; 3289: int len; 3290: 3291: /* The string after the S/P is the name of a spec that is to be 3292: processed. */ 3293: while (*p && *p != ')' && *p != ']') 3294: p++; 3295: 3296: /* See if it's in the list */ 3297: for (len = p - name, sl = specs; sl; sl = sl->next) 3298: if (strncmp (sl->name, name, len) == 0 && !sl->name[len]) 3299: { 3300: name = sl->spec; 3301: break; 3302: } 3303: 3304: if (sl) 3305: { 3306: if (c == '(') 1.1.1.5 root 3307: { 3308: value = do_spec_1 (name, 0, NULL_PTR); 3309: if (value != 0) 3310: return value; 3311: } 1.1 root 3312: else 3313: { 3314: char *x = (char *) alloca (strlen (name) * 2 + 1); 3315: char *buf = x; 3316: char *y = name; 3317: 3318: /* Copy all of NAME into BUF, but put __ after 3319: every -D and at the end of each arg, */ 3320: while (1) 3321: { 3322: if (! strncmp (y, "-D", 2)) 3323: { 3324: *x++ = '-'; 3325: *x++ = 'D'; 3326: *x++ = '_'; 3327: *x++ = '_'; 3328: y += 2; 3329: } 3330: else if (*y == ' ' || *y == 0) 3331: { 3332: *x++ = '_'; 3333: *x++ = '_'; 3334: if (*y == 0) 3335: break; 3336: else 3337: *x++ = *y++; 3338: } 3339: else 3340: *x++ = *y++; 3341: } 3342: *x = 0; 3343: 1.1.1.5 root 3344: value = do_spec_1 (buf, 0, NULL_PTR); 3345: if (value != 0) 3346: return value; 1.1 root 3347: } 3348: } 1.1.1.2 root 3349: 3350: /* Discard the closing paren or bracket. */ 3351: if (*p) 3352: p++; 1.1 root 3353: } 3354: break; 3355: 1.1.1.6 ! root 3356: case 'v': ! 3357: { ! 3358: int c1 = *p++; /* Select first or second version number. */ ! 3359: char *p = spec_version; ! 3360: char *q, *copy; ! 3361: /* If desired, advance to second version number. */ ! 3362: if (c1 == '2') ! 3363: { ! 3364: /* Set P after the first period. */ ! 3365: while (*p != '.') p++; ! 3366: p++; ! 3367: } ! 3368: /* Set Q at the next period or at the end. */ ! 3369: q = p; ! 3370: while (*q != '.' && *q != 0) q++; ! 3371: /* Put that part into the command. */ ! 3372: obstack_grow (&obstack, p, q - p); ! 3373: arg_going = 1; ! 3374: } ! 3375: break; ! 3376: 1.1.1.5 root 3377: case '|': 3378: if (input_from_pipe) 3379: do_spec_1 ("-", 0, NULL_PTR); 3380: break; 3381: 1.1 root 3382: default: 3383: abort (); 3384: } 3385: break; 3386: 3387: case '\\': 3388: /* Backslash: treat next character as ordinary. */ 3389: c = *p++; 3390: 3391: /* fall through */ 3392: default: 3393: /* Ordinary character: put it into the current argument. */ 3394: obstack_1grow (&obstack, c); 3395: arg_going = 1; 3396: } 3397: 3398: return 0; /* End of string */ 3399: } 3400: 3401: /* Return 0 if we call do_spec_1 and that returns -1. */ 3402: 3403: static char * 3404: handle_braces (p) 3405: register char *p; 3406: { 3407: register char *q; 3408: char *filter; 3409: int pipe = 0; 3410: int negate = 0; 3411: int suffix = 0; 3412: 3413: if (*p == '|') 3414: /* A `|' after the open-brace means, 3415: if the test fails, output a single minus sign rather than nothing. 3416: This is used in %{|!pipe:...}. */ 3417: pipe = 1, ++p; 3418: 3419: if (*p == '!') 3420: /* A `!' after the open-brace negates the condition: 3421: succeed if the specified switch is not present. */ 3422: negate = 1, ++p; 3423: 3424: if (*p == '.') 3425: /* A `.' after the open-brace means test against the current suffix. */ 3426: { 3427: if (pipe) 3428: abort (); 3429: 3430: suffix = 1; 3431: ++p; 3432: } 3433: 3434: filter = p; 3435: while (*p != ':' && *p != '}') p++; 3436: if (*p != '}') 3437: { 3438: register int count = 1; 3439: q = p + 1; 3440: while (count > 0) 3441: { 3442: if (*q == '{') 3443: count++; 3444: else if (*q == '}') 3445: count--; 3446: else if (*q == 0) 3447: abort (); 3448: q++; 3449: } 3450: } 3451: else 3452: q = p + 1; 3453: 3454: if (suffix) 3455: { 3456: int found = (input_suffix != 0 1.1.1.2 root 3457: && strlen (input_suffix) == p - filter 1.1 root 3458: && strncmp (input_suffix, filter, p - filter) == 0); 3459: 3460: if (p[0] == '}') 3461: abort (); 3462: 3463: if (negate != found 1.1.1.4 root 3464: && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0) 1.1 root 3465: return 0; 3466: 3467: return q; 3468: } 3469: else if (p[-1] == '*' && p[0] == '}') 3470: { 3471: /* Substitute all matching switches as separate args. */ 3472: register int i; 3473: --p; 3474: for (i = 0; i < n_switches; i++) 3475: if (!strncmp (switches[i].part1, filter, p - filter)) 3476: give_switch (i, 0); 3477: } 3478: else 3479: { 3480: /* Test for presence of the specified switch. */ 3481: register int i; 3482: int present = 0; 3483: 3484: /* If name specified ends in *, as in {x*:...}, 3485: check for %* and handle that case. */ 3486: if (p[-1] == '*' && !negate) 3487: { 3488: int substitution; 3489: char *r = p; 3490: 3491: /* First see whether we have %*. */ 3492: substitution = 0; 1.1.1.2 root 3493: while (r < q) 1.1 root 3494: { 3495: if (*r == '%' && r[1] == '*') 3496: substitution = 1; 3497: r++; 3498: } 3499: /* If we do, handle that case. */ 3500: if (substitution) 3501: { 3502: /* Substitute all matching switches as separate args. 3503: But do this by substituting for %* 3504: in the text that follows the colon. */ 3505: 3506: unsigned hard_match_len = p - filter - 1; 3507: char *string = save_string (p + 1, q - p - 2); 3508: 3509: for (i = 0; i < n_switches; i++) 3510: if (!strncmp (switches[i].part1, filter, hard_match_len)) 3511: { 3512: do_spec_1 (string, 0, &switches[i].part1[hard_match_len]); 3513: /* Pass any arguments this switch has. */ 3514: give_switch (i, 1); 3515: } 3516: 3517: return q; 3518: } 3519: } 3520: 3521: /* If name specified ends in *, as in {x*:...}, 3522: check for presence of any switch name starting with x. */ 3523: if (p[-1] == '*') 3524: { 3525: for (i = 0; i < n_switches; i++) 3526: { 3527: unsigned hard_match_len = p - filter - 1; 3528: 3529: if (!strncmp (switches[i].part1, filter, hard_match_len)) 3530: { 3531: switches[i].valid = 1; 3532: present = 1; 3533: } 3534: } 3535: } 3536: /* Otherwise, check for presence of exact name specified. */ 3537: else 3538: { 3539: for (i = 0; i < n_switches; i++) 3540: { 3541: if (!strncmp (switches[i].part1, filter, p - filter) 3542: && switches[i].part1[p - filter] == 0) 3543: { 3544: switches[i].valid = 1; 3545: present = 1; 3546: break; 3547: } 3548: } 3549: } 3550: 3551: /* If it is as desired (present for %{s...}, absent for %{-s...}) 3552: then substitute either the switch or the specified 3553: conditional text. */ 3554: if (present != negate) 3555: { 3556: if (*p == '}') 3557: { 3558: give_switch (i, 0); 3559: } 3560: else 3561: { 1.1.1.4 root 3562: if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0) 1.1 root 3563: return 0; 3564: } 3565: } 3566: else if (pipe) 3567: { 3568: /* Here if a %{|...} conditional fails: output a minus sign, 3569: which means "standard output" or "standard input". */ 1.1.1.4 root 3570: do_spec_1 ("-", 0, NULL_PTR); 1.1 root 3571: } 3572: } 3573: 3574: return q; 3575: } 3576: 3577: /* Pass a switch to the current accumulating command 3578: in the same form that we received it. 3579: SWITCHNUM identifies the switch; it is an index into 3580: the vector of switches gcc received, which is `switches'. 3581: This cannot fail since it never finishes a command line. 3582: 3583: If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */ 3584: 3585: static void 3586: give_switch (switchnum, omit_first_word) 3587: int switchnum; 3588: int omit_first_word; 3589: { 3590: if (!omit_first_word) 3591: { 1.1.1.4 root 3592: do_spec_1 ("-", 0, NULL_PTR); 3593: do_spec_1 (switches[switchnum].part1, 1, NULL_PTR); 1.1 root 3594: } 1.1.1.4 root 3595: do_spec_1 (" ", 0, NULL_PTR); 1.1 root 3596: if (switches[switchnum].args != 0) 3597: { 3598: char **p; 3599: for (p = switches[switchnum].args; *p; p++) 3600: { 1.1.1.4 root 3601: do_spec_1 (*p, 1, NULL_PTR); 3602: do_spec_1 (" ", 0, NULL_PTR); 1.1 root 3603: } 3604: } 3605: switches[switchnum].valid = 1; 3606: } 3607: 3608: /* Search for a file named NAME trying various prefixes including the 3609: user's -B prefix and some standard ones. 3610: Return the absolute file name found. If nothing is found, return NAME. */ 3611: 3612: static char * 3613: find_file (name) 3614: char *name; 3615: { 3616: char *newname; 3617: 3618: newname = find_a_file (&startfile_prefix, name, R_OK); 3619: return newname ? newname : name; 3620: } 3621: 1.1.1.5 root 3622: /* Determine whether a directory exists. If LINKER, return 0 for 3623: certain fixed names not needed by the linker. If not LINKER, it is 3624: only important to return 0 if the host machine has a small ARG_MAX 3625: limit. */ 1.1 root 3626: 3627: static int 1.1.1.5 root 3628: is_directory (path1, path2, linker) 1.1 root 3629: char *path1; 3630: char *path2; 1.1.1.5 root 3631: int linker; 1.1 root 3632: { 3633: int len1 = strlen (path1); 3634: int len2 = strlen (path2); 3635: char *path = (char *) alloca (3 + len1 + len2); 3636: char *cp; 3637: struct stat st; 3638: 1.1.1.5 root 3639: #ifndef SMALL_ARG_MAX 3640: if (! linker) 3641: return 1; 3642: #endif 3643: 1.1 root 3644: /* Construct the path from the two parts. Ensure the string ends with "/.". 3645: The resulting path will be a directory even if the given path is a 3646: symbolic link. */ 3647: bcopy (path1, path, len1); 3648: bcopy (path2, path + len1, len2); 3649: cp = path + len1 + len2; 3650: if (cp[-1] != '/') 3651: *cp++ = '/'; 3652: *cp++ = '.'; 3653: *cp = '\0'; 3654: 3655: /* Exclude directories that the linker is known to search. */ 1.1.1.5 root 3656: if (linker 3657: && ((cp - path == 6 && strcmp (path, "/lib/.") == 0) 3658: || (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0))) 1.1 root 3659: return 0; 3660: 3661: return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); 3662: } 3663: 3664: /* On fatal signals, delete all the temporary files. */ 3665: 3666: static void 3667: fatal_error (signum) 3668: int signum; 3669: { 3670: signal (signum, SIG_DFL); 3671: delete_failure_queue (); 3672: delete_temp_files (); 3673: /* Get the same signal again, this time not handled, 3674: so its normal effect occurs. */ 3675: kill (getpid (), signum); 3676: } 3677: 3678: int 3679: main (argc, argv) 3680: int argc; 3681: char **argv; 3682: { 3683: register int i; 1.1.1.4 root 3684: int j; 1.1 root 3685: int value; 3686: int linker_was_run = 0; 3687: char *explicit_link_files; 3688: char *specs_file; 1.1.1.5 root 3689: char *p; 1.1 root 3690: 1.1.1.5 root 3691: p = argv[0] + strlen (argv[0]); 3692: while (p != argv[0] && p[-1] != '/') --p; 3693: programname = p; 1.1 root 3694: 3695: if (signal (SIGINT, SIG_IGN) != SIG_IGN) 3696: signal (SIGINT, fatal_error); 1.1.1.5 root 3697: #ifdef SIGHUP 1.1 root 3698: if (signal (SIGHUP, SIG_IGN) != SIG_IGN) 3699: signal (SIGHUP, fatal_error); 1.1.1.5 root 3700: #endif 1.1 root 3701: if (signal (SIGTERM, SIG_IGN) != SIG_IGN) 3702: signal (SIGTERM, fatal_error); 3703: #ifdef SIGPIPE 3704: if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) 3705: signal (SIGPIPE, fatal_error); 3706: #endif 3707: 3708: argbuf_length = 10; 3709: argbuf = (char **) xmalloc (argbuf_length * sizeof (char *)); 3710: 3711: obstack_init (&obstack); 3712: 1.1.1.2 root 3713: /* Set up to remember the pathname of gcc and any options 1.1.1.5 root 3714: needed for collect. We use argv[0] instead of programname because 3715: we need the complete pathname. */ 1.1.1.2 root 3716: obstack_init (&collect_obstack); 3717: obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1); 1.1.1.5 root 3718: obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1); 1.1.1.2 root 3719: putenv (obstack_finish (&collect_obstack)); 3720: 1.1 root 3721: /* Choose directory for temp files. */ 3722: 3723: choose_temp_base (); 3724: 3725: /* Make a table of what switches there are (switches, n_switches). 3726: Make a table of specified input files (infiles, n_infiles). 3727: Decode switches that are handled locally. */ 3728: 3729: process_command (argc, argv); 3730: 3731: /* Initialize the vector of specs to just the default. 3732: This means one element containing 0s, as a terminator. */ 3733: 3734: compilers = (struct compiler *) xmalloc (sizeof default_compilers); 3735: bcopy (default_compilers, compilers, sizeof default_compilers); 3736: n_compilers = n_default_compilers; 3737: 3738: /* Read specs from a file if there is one. */ 3739: 3740: machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", "")); 1.1.1.4 root 3741: just_machine_suffix = concat (spec_machine, "/", ""); 1.1 root 3742: 3743: specs_file = find_a_file (&startfile_prefix, "specs", R_OK); 3744: /* Read the specs file unless it is a default one. */ 3745: if (specs_file != 0 && strcmp (specs_file, "specs")) 3746: read_specs (specs_file); 3747: 1.1.1.2 root 3748: /* If not cross-compiling, look for startfiles in the standard places. */ 3749: /* The fact that these are done here, after reading the specs file, 3750: means that it cannot be found in these directories. 3751: But that's okay. It should never be there anyway. */ 3752: if (!cross_compile) 3753: { 3754: #ifdef MD_EXEC_PREFIX 1.1.1.4 root 3755: add_prefix (&exec_prefix, md_exec_prefix, 0, 0, NULL_PTR); 3756: add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, NULL_PTR); 1.1.1.2 root 3757: #endif 3758: 3759: #ifdef MD_STARTFILE_PREFIX 1.1.1.4 root 3760: add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, NULL_PTR); 1.1.1.2 root 3761: #endif 3762: 1.1.1.3 root 3763: #ifdef MD_STARTFILE_PREFIX_1 1.1.1.4 root 3764: add_prefix (&startfile_prefix, md_startfile_prefix_1, 0, 0, NULL_PTR); 1.1.1.3 root 3765: #endif 3766: 1.1.1.6 ! root 3767: /* If standard_startfile_prefix is relative, base it on ! 3768: standard_exec_prefix. This lets us move the installed tree ! 3769: as a unit. If GCC_EXEC_PREFIX is defined, base ! 3770: standard_startfile_prefix on that as well. */ ! 3771: if (*standard_startfile_prefix == '/') ! 3772: add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0, ! 3773: NULL_PTR); ! 3774: else ! 3775: { ! 3776: if (gcc_exec_prefix) ! 3777: add_prefix (&startfile_prefix, ! 3778: concat (gcc_exec_prefix, ! 3779: standard_startfile_prefix, ! 3780: ""), ! 3781: 0, 0, NULL_PTR); ! 3782: add_prefix (&startfile_prefix, ! 3783: concat (standard_exec_prefix, ! 3784: machine_suffix, ! 3785: standard_startfile_prefix), ! 3786: 0, 0, NULL_PTR); ! 3787: } ! 3788: 1.1.1.4 root 3789: add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0, 3790: NULL_PTR); 3791: add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0, 3792: NULL_PTR); 1.1.1.2 root 3793: #if 0 /* Can cause surprises, and one can use -B./ instead. */ 1.1.1.4 root 3794: add_prefix (&startfile_prefix, "./", 0, 1, NULL_PTR); 1.1.1.2 root 3795: #endif 3796: } 3797: 1.1 root 3798: /* Now we have the specs. 3799: Set the `valid' bits for switches that match anything in any spec. */ 3800: 3801: validate_all_switches (); 3802: 3803: /* Warn about any switches that no pass was interested in. */ 3804: 3805: for (i = 0; i < n_switches; i++) 3806: if (! switches[i].valid) 3807: error ("unrecognized option `-%s'", switches[i].part1); 3808: 1.1.1.3 root 3809: if (print_libgcc_file_name) 3810: { 3811: printf ("%s\n", find_file ("libgcc.a")); 3812: exit (0); 3813: } 3814: 1.1 root 3815: /* Obey some of the options. */ 3816: 3817: if (verbose_flag) 3818: { 3819: fprintf (stderr, "gcc version %s\n", version_string); 3820: if (n_infiles == 0) 3821: exit (0); 3822: } 3823: 3824: if (n_infiles == 0) 1.1.1.6 ! root 3825: fatal ("No input files"); 1.1 root 3826: 3827: /* Make a place to record the compiler output file names 3828: that correspond to the input files. */ 3829: 3830: outfiles = (char **) xmalloc (n_infiles * sizeof (char *)); 3831: bzero (outfiles, n_infiles * sizeof (char *)); 3832: 3833: /* Record which files were specified explicitly as link input. */ 3834: 3835: explicit_link_files = xmalloc (n_infiles); 3836: bzero (explicit_link_files, n_infiles); 3837: 3838: for (i = 0; i < n_infiles; i++) 3839: { 3840: register struct compiler *cp = 0; 3841: int this_file_error = 0; 3842: 3843: /* Tell do_spec what to substitute for %i. */ 3844: 3845: input_filename = infiles[i].name; 3846: input_filename_length = strlen (input_filename); 3847: input_file_number = i; 3848: 3849: /* Use the same thing in %o, unless cp->spec says otherwise. */ 3850: 3851: outfiles[i] = input_filename; 3852: 3853: /* Figure out which compiler from the file's suffix. */ 3854: 3855: cp = lookup_compiler (infiles[i].name, input_filename_length, 3856: infiles[i].language); 3857: 3858: if (cp) 3859: { 3860: /* Ok, we found an applicable compiler. Run its spec. */ 3861: /* First say how much of input_filename to substitute for %b */ 3862: register char *p; 1.1.1.4 root 3863: int len; 1.1 root 3864: 3865: input_basename = input_filename; 3866: for (p = input_filename; *p; p++) 3867: if (*p == '/') 3868: input_basename = p + 1; 3869: 3870: /* Find a suffix starting with the last period, 3871: and set basename_length to exclude that suffix. */ 3872: basename_length = strlen (input_basename); 3873: p = input_basename + basename_length; 3874: while (p != input_basename && *p != '.') --p; 3875: if (*p == '.' && p != input_basename) 3876: { 3877: basename_length = p - input_basename; 3878: input_suffix = p + 1; 3879: } 3880: else 3881: input_suffix = ""; 3882: 1.1.1.4 root 3883: len = 0; 3884: for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++) 3885: if (cp->spec[j]) 3886: len += strlen (cp->spec[j]); 3887: 3888: p = (char *) xmalloc (len + 1); 3889: 3890: len = 0; 3891: for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++) 3892: if (cp->spec[j]) 3893: { 3894: strcpy (p + len, cp->spec[j]); 3895: len += strlen (cp->spec[j]); 3896: } 3897: 3898: value = do_spec (p); 3899: free (p); 1.1 root 3900: if (value < 0) 3901: this_file_error = 1; 3902: } 3903: 3904: /* If this file's name does not contain a recognized suffix, 3905: record it as explicit linker input. */ 3906: 3907: else 3908: explicit_link_files[i] = 1; 3909: 3910: /* Clear the delete-on-failure queue, deleting the files in it 3911: if this compilation failed. */ 3912: 3913: if (this_file_error) 3914: { 3915: delete_failure_queue (); 3916: error_count++; 3917: } 3918: /* If this compilation succeeded, don't delete those files later. */ 3919: clear_failure_queue (); 3920: } 3921: 3922: /* Run ld to link all the compiler output files. */ 3923: 3924: if (error_count == 0) 3925: { 3926: int tmp = execution_count; 1.1.1.2 root 3927: int i; 3928: int first_time; 3929: 3930: /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables 3931: for collect. */ 3932: putenv_from_prefixes (&exec_prefix, "COMPILER_PATH="); 3933: putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH="); 3934: 3935: /* Build COLLECT_GCC_OPTIONS to have all of the options specified to 3936: the compiler. */ 3937: obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=", 3938: sizeof ("COLLECT_GCC_OPTIONS=")-1); 3939: 3940: first_time = TRUE; 3941: for (i = 0; i < n_switches; i++) 3942: { 3943: char **args; 3944: if (!first_time) 3945: obstack_grow (&collect_obstack, " ", 1); 3946: 3947: first_time = FALSE; 3948: obstack_grow (&collect_obstack, "-", 1); 3949: obstack_grow (&collect_obstack, switches[i].part1, 3950: strlen (switches[i].part1)); 3951: 3952: for (args = switches[i].args; args && *args; args++) 3953: { 3954: obstack_grow (&collect_obstack, " ", 1); 3955: obstack_grow (&collect_obstack, *args, strlen (*args)); 3956: } 3957: } 3958: obstack_grow (&collect_obstack, "\0", 1); 3959: putenv (obstack_finish (&collect_obstack)); 3960: 1.1 root 3961: value = do_spec (link_command_spec); 3962: if (value < 0) 3963: error_count = 1; 3964: linker_was_run = (tmp != execution_count); 3965: } 3966: 3967: /* Warn if a -B option was specified but the prefix was never used. */ 3968: unused_prefix_warnings (&exec_prefix); 3969: unused_prefix_warnings (&startfile_prefix); 3970: 3971: /* If options said don't run linker, 3972: complain about input files to be given to the linker. */ 3973: 3974: if (! linker_was_run && error_count == 0) 3975: for (i = 0; i < n_infiles; i++) 3976: if (explicit_link_files[i]) 3977: error ("%s: linker input file unused since linking not done", 3978: outfiles[i]); 3979: 3980: /* Delete some or all of the temporary files we made. */ 3981: 3982: if (error_count) 3983: delete_failure_queue (); 3984: delete_temp_files (); 3985: 1.1.1.4 root 3986: exit (error_count > 0 ? (signal_count ? 2 : 1) : 0); 1.1 root 3987: /* NOTREACHED */ 3988: return 0; 3989: } 3990: 3991: /* Find the proper compilation spec for the file name NAME, 3992: whose length is LENGTH. LANGUAGE is the specified language, 3993: or 0 if none specified. */ 3994: 3995: static struct compiler * 3996: lookup_compiler (name, length, language) 3997: char *name; 3998: int length; 3999: char *language; 4000: { 4001: struct compiler *cp; 4002: 4003: /* Look for the language, if one is spec'd. */ 4004: if (language != 0) 4005: { 4006: for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) 4007: { 4008: if (language != 0) 4009: { 4010: if (cp->suffix[0] == '@' 4011: && !strcmp (cp->suffix + 1, language)) 4012: return cp; 4013: } 4014: } 4015: error ("language %s not recognized", language); 4016: } 4017: 4018: /* Look for a suffix. */ 4019: for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) 4020: { 1.1.1.5 root 4021: if (/* The suffix `-' matches only the file name `-'. */ 4022: (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) 4023: || 4024: (strlen (cp->suffix) < length 4025: /* See if the suffix matches the end of NAME. */ 4026: && !strcmp (cp->suffix, 4027: name + length - strlen (cp->suffix)))) 1.1 root 4028: { 1.1.1.4 root 4029: if (cp->spec[0][0] == '@') 1.1 root 4030: { 4031: struct compiler *new; 4032: /* An alias entry maps a suffix to a language. 4033: Search for the language; pass 0 for NAME and LENGTH 4034: to avoid infinite recursion if language not found. 4035: Construct the new compiler spec. */ 1.1.1.4 root 4036: language = cp->spec[0] + 1; 1.1 root 4037: new = (struct compiler *) xmalloc (sizeof (struct compiler)); 4038: new->suffix = cp->suffix; 1.1.1.4 root 4039: bcopy (lookup_compiler (NULL_PTR, 0, language)->spec, 4040: new->spec, sizeof new->spec); 1.1 root 4041: return new; 4042: } 4043: /* A non-alias entry: return it. */ 4044: return cp; 4045: } 4046: } 4047: 4048: return 0; 4049: } 4050: 4051: char * 4052: xmalloc (size) 4053: unsigned size; 4054: { 4055: register char *value = (char *) malloc (size); 4056: if (value == 0) 4057: fatal ("virtual memory exhausted"); 4058: return value; 4059: } 4060: 4061: char * 4062: xrealloc (ptr, size) 4063: char *ptr; 4064: unsigned size; 4065: { 4066: register char *value = (char *) realloc (ptr, size); 4067: if (value == 0) 4068: fatal ("virtual memory exhausted"); 4069: return value; 4070: } 4071: 4072: /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ 4073: 4074: static char * 4075: concat (s1, s2, s3) 4076: char *s1, *s2, *s3; 4077: { 4078: int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); 4079: char *result = xmalloc (len1 + len2 + len3 + 1); 4080: 4081: strcpy (result, s1); 4082: strcpy (result + len1, s2); 4083: strcpy (result + len1 + len2, s3); 4084: *(result + len1 + len2 + len3) = 0; 4085: 4086: return result; 4087: } 4088: 4089: static char * 4090: save_string (s, len) 4091: char *s; 4092: int len; 4093: { 4094: register char *result = xmalloc (len + 1); 4095: 4096: bcopy (s, result, len); 4097: result[len] = 0; 4098: return result; 4099: } 4100: 4101: static void 4102: pfatal_with_name (name) 4103: char *name; 4104: { 4105: char *s; 4106: 4107: if (errno < sys_nerr) 4108: s = concat ("%s: ", sys_errlist[errno], ""); 4109: else 4110: s = "cannot open %s"; 4111: fatal (s, name); 4112: } 4113: 4114: static void 4115: perror_with_name (name) 4116: char *name; 4117: { 4118: char *s; 4119: 4120: if (errno < sys_nerr) 4121: s = concat ("%s: ", sys_errlist[errno], ""); 4122: else 4123: s = "cannot open %s"; 4124: error (s, name); 4125: } 4126: 4127: static void 4128: perror_exec (name) 4129: char *name; 4130: { 4131: char *s; 4132: 4133: if (errno < sys_nerr) 4134: s = concat ("installation problem, cannot exec %s: ", 4135: sys_errlist[errno], ""); 4136: else 4137: s = "installation problem, cannot exec %s"; 4138: error (s, name); 4139: } 4140: 4141: /* More 'friendly' abort that prints the line and file. 4142: config.h can #define abort fancy_abort if you like that sort of thing. */ 4143: 4144: void 4145: fancy_abort () 4146: { 4147: fatal ("Internal gcc abort."); 4148: } 4149: 4150: #ifdef HAVE_VPRINTF 4151: 4152: /* Output an error message and exit */ 4153: 4154: static void 4155: fatal (va_alist) 4156: va_dcl 4157: { 4158: va_list ap; 4159: char *format; 4160: 4161: va_start (ap); 4162: format = va_arg (ap, char *); 4163: fprintf (stderr, "%s: ", programname); 4164: vfprintf (stderr, format, ap); 4165: va_end (ap); 4166: fprintf (stderr, "\n"); 4167: delete_temp_files (); 4168: exit (1); 4169: } 4170: 4171: static void 4172: error (va_alist) 4173: va_dcl 4174: { 4175: va_list ap; 4176: char *format; 4177: 4178: va_start (ap); 4179: format = va_arg (ap, char *); 4180: fprintf (stderr, "%s: ", programname); 4181: vfprintf (stderr, format, ap); 4182: va_end (ap); 4183: 4184: fprintf (stderr, "\n"); 4185: } 4186: 4187: #else /* not HAVE_VPRINTF */ 4188: 4189: static void 4190: fatal (msg, arg1, arg2) 4191: char *msg, *arg1, *arg2; 4192: { 4193: error (msg, arg1, arg2); 4194: delete_temp_files (); 4195: exit (1); 4196: } 4197: 4198: static void 4199: error (msg, arg1, arg2) 4200: char *msg, *arg1, *arg2; 4201: { 4202: fprintf (stderr, "%s: ", programname); 4203: fprintf (stderr, msg, arg1, arg2); 4204: fprintf (stderr, "\n"); 4205: } 4206: 4207: #endif /* not HAVE_VPRINTF */ 4208: 4209: 4210: static void 4211: validate_all_switches () 4212: { 4213: struct compiler *comp; 4214: register char *p; 4215: register char c; 1.1.1.2 root 4216: struct spec_list *spec; 1.1 root 4217: 1.1.1.4 root 4218: for (comp = compilers; comp->spec[0]; comp++) 1.1 root 4219: { 1.1.1.4 root 4220: int i; 4221: for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++) 4222: { 4223: p = comp->spec[i]; 4224: while (c = *p++) 4225: if (c == '%' && *p == '{') 4226: /* We have a switch spec. */ 4227: validate_switches (p + 1); 4228: } 1.1 root 4229: } 4230: 1.1.1.2 root 4231: /* look through the linked list of extra specs read from the specs file */ 1.1.1.4 root 4232: for (spec = specs; spec ; spec = spec->next) 1.1.1.2 root 4233: { 4234: p = spec->spec; 4235: while (c = *p++) 4236: if (c == '%' && *p == '{') 4237: /* We have a switch spec. */ 4238: validate_switches (p + 1); 4239: } 4240: 1.1 root 4241: p = link_command_spec; 4242: while (c = *p++) 4243: if (c == '%' && *p == '{') 4244: /* We have a switch spec. */ 4245: validate_switches (p + 1); 4246: 4247: /* Now notice switches mentioned in the machine-specific specs. */ 4248: 4249: p = asm_spec; 4250: while (c = *p++) 4251: if (c == '%' && *p == '{') 4252: /* We have a switch spec. */ 4253: validate_switches (p + 1); 4254: 4255: p = asm_final_spec; 4256: while (c = *p++) 4257: if (c == '%' && *p == '{') 4258: /* We have a switch spec. */ 4259: validate_switches (p + 1); 4260: 4261: p = cpp_spec; 4262: while (c = *p++) 4263: if (c == '%' && *p == '{') 4264: /* We have a switch spec. */ 4265: validate_switches (p + 1); 4266: 4267: p = signed_char_spec; 4268: while (c = *p++) 4269: if (c == '%' && *p == '{') 4270: /* We have a switch spec. */ 4271: validate_switches (p + 1); 4272: 4273: p = cc1_spec; 4274: while (c = *p++) 4275: if (c == '%' && *p == '{') 4276: /* We have a switch spec. */ 4277: validate_switches (p + 1); 4278: 4279: p = cc1plus_spec; 4280: while (c = *p++) 4281: if (c == '%' && *p == '{') 4282: /* We have a switch spec. */ 4283: validate_switches (p + 1); 4284: 4285: p = link_spec; 4286: while (c = *p++) 4287: if (c == '%' && *p == '{') 4288: /* We have a switch spec. */ 4289: validate_switches (p + 1); 4290: 4291: p = lib_spec; 4292: while (c = *p++) 4293: if (c == '%' && *p == '{') 4294: /* We have a switch spec. */ 4295: validate_switches (p + 1); 4296: 4297: p = startfile_spec; 4298: while (c = *p++) 4299: if (c == '%' && *p == '{') 4300: /* We have a switch spec. */ 4301: validate_switches (p + 1); 4302: } 4303: 4304: /* Look at the switch-name that comes after START 4305: and mark as valid all supplied switches that match it. */ 4306: 4307: static void 4308: validate_switches (start) 4309: char *start; 4310: { 4311: register char *p = start; 4312: char *filter; 4313: register int i; 4314: int suffix = 0; 4315: 4316: if (*p == '|') 4317: ++p; 4318: 4319: if (*p == '!') 4320: ++p; 4321: 4322: if (*p == '.') 4323: suffix = 1, ++p; 4324: 4325: filter = p; 4326: while (*p != ':' && *p != '}') p++; 4327: 4328: if (suffix) 4329: ; 4330: else if (p[-1] == '*') 4331: { 4332: /* Mark all matching switches as valid. */ 4333: --p; 4334: for (i = 0; i < n_switches; i++) 4335: if (!strncmp (switches[i].part1, filter, p - filter)) 4336: switches[i].valid = 1; 4337: } 4338: else 4339: { 4340: /* Mark an exact matching switch as valid. */ 4341: for (i = 0; i < n_switches; i++) 4342: { 4343: if (!strncmp (switches[i].part1, filter, p - filter) 4344: && switches[i].part1[p - filter] == 0) 4345: switches[i].valid = 1; 4346: } 4347: } 4348: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.