home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / gcc-2.5.8-src.lha / src / amiga / gcc-2.5.8 / gcc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-22  |  117.1 KB  |  4,407 lines

  1. /* Compiler driver program that can handle many languages.
  2.    Copyright (C) 1987, 1989, 1992, 1993 Free Software Foundation, Inc.
  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>
  37. #include <sys/file.h>   /* May get R_OK, etc. on some systems.  */
  38.  
  39. #include "config.h"
  40. #include "obstack.h"
  41. #include "gvarargs.h"
  42. #include <stdio.h>
  43.  
  44. #ifndef R_OK
  45. #define R_OK 4
  46. #define W_OK 2
  47. #define X_OK 1
  48. #endif
  49.  
  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.  
  68. #ifdef USG
  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
  76. #define P_tmpdir "."
  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
  94.  
  95. /* By default, colon separates directories in a path.  */
  96. #ifndef PATH_SEPARATOR
  97. #define PATH_SEPARATOR ':'
  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;
  107. #if defined(bsd4_4)
  108. extern const char *const sys_errlist[];
  109. #else
  110. extern char *sys_errlist[];
  111. #endif
  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.  
  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.  
  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.  
  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.  
  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.  
  155. /* This is the obstack which we use to allocate many strings.  */
  156.  
  157. static struct obstack obstack;
  158.  
  159. /* This is the obstack to build an environment variable to pass to
  160.    collect2 that describes all of the relevant switches of what to
  161.    pass the compiler in building the list of pointers to constructors
  162.    and destructors.  */
  163.  
  164. static struct obstack collect_obstack;
  165.  
  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 ();
  180. static int is_directory ();
  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.
  215.  %u    like %g, but make the temporary file name unique.
  216.  %U    returns the last file name generated with %u.
  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.
  238.  %I    Substitute a -iprefix option made from GCC_EXEC_PREFIX.
  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.
  246.  %Y    Output the accumulated assembler options specified by compilations.
  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.)
  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.
  256.  %D    Dump out a -L option for each directory in startfile_prefix.
  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.
  265.  %|    output "-" if the input for the current command is coming from a pipe.
  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.
  277.  %{S*:X} substitutes X if one or more switches whose names start with -S are
  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
  280.     occurrence of %* within X.
  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.
  287.  %(Spec) processes a specification defined in a specs file as *Spec:
  288.  %[Spec] as above, but put __ around -D arguments
  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
  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
  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.  
  405. #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR)        \
  406.  (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext")    \
  407.   || !strcmp (STR, "Tbss") || !strcmp (STR, "include")    \
  408.   || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
  409.   || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
  410.   || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore"))
  411.  
  412. #ifndef WORD_SWITCH_TAKES_ARG
  413. #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
  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.  */
  422.  
  423.   char *spec[4];        /* To use this compiler, concatenate these
  424.                    specs and pass to do_spec.  */
  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",
  448.    "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  449.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  450.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
  451.         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  452.     %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  453.     %{!undef:%{!ansi:%p} %P} %{trigraphs} \
  454.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  455.         %{traditional-cpp:-traditional}\
  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 \
  459.            %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
  460.            %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
  461.            %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
  462.            %{aux-info*}\
  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\
  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}\
  467.                       %{!pipe:%g.s} %A\n }}}}"},
  468.   {"-",
  469.    "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  470.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  471.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
  472.         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  473.     %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  474.     %{!undef:%{!ansi:%p} %P} %{trigraphs}\
  475.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  476.         %{traditional-cpp:-traditional}\
  477.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  478.         %i %W{o*}}\
  479.     %{!E:%e-E required when input is from standard input}"},
  480.   {".m", "@objective-c"},
  481.   {"@objective-c",
  482.    "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  483.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  484.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
  485.         -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  486.      %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  487.     %{!undef:%{!ansi:%p} %P} %{trigraphs}\
  488.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  489.         %{traditional-cpp:-traditional}\
  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 \
  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} \
  497.            %{aux-info*}\
  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\
  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}\
  502.                       %{!pipe:%g.s} %A\n }}}}"},
  503.   {".h", "@c-header"},
  504.   {"@c-header",
  505.    "%{!E:%eCompilation of header file requested} \
  506.     cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  507.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  508.      %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
  509.         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  510.      %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  511.     %{!undef:%{!ansi:%p} %P} %{trigraphs}\
  512.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  513.         %{traditional-cpp:-traditional}\
  514.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  515.         %i %W{o*}"},
  516.   {".cc", "@c++"},
  517.   {".cxx", "@c++"},
  518.   {".C", "@c++"},
  519.   {"@c++",
  520.    "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  521.     %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
  522.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
  523.     -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
  524.     %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
  525.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  526.         %{traditional-cpp:-traditional} %{trigraphs}\
  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\
  530.            %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
  531.            %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{traditional}\
  532.            %{v:-version} %{pg:-p} %{p} %{f*} %{+e*}\
  533.            %{aux-info*}\
  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\
  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}\
  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*}\
  544.     %{aux-info*}\
  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\
  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 }"},
  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}\
  553.         %{v:-version} %{pg:-p} %{p} %{f*} %{+e*}\
  554.         %{aux-info*}\
  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\
  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}\
  559.            %{!pipe:%g.s} %A\n }"},
  560.   {".s", "@assembler"},
  561.   {"@assembler",
  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 }"},
  564.   {".S", "@assembler-with-cpp"},
  565.   {"@assembler-with-cpp",
  566.    "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  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__ \
  570.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  571.         %{traditional-cpp:-traditional}\
  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}\
  576.             %{!pipe:%g.s} %A\n }}}}"},
  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}}} "},
  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.  
  600. /* -u* was put back because both BSD and SysV seem to support it.  */
  601. /* %{static:} simply prevents an error message if the target machine
  602.    doesn't handle -static.  */
  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.  */
  606. #ifdef LINK_LIBGCC_SPECIAL_1
  607. /* Have gcc do the search for libgcc.a, but generate -L options as usual.  */
  608. static char *link_command_spec = "\
  609. %{!fsyntax-only: \
  610.  %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
  611.             %{r} %{s} %{t} %{u*} %{x} %{z}\
  612.             %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
  613.             %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
  614. #else
  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 = "\
  618. %{!fsyntax-only: \
  619.  %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
  620.             %{r} %{s} %{t} %{u*} %{x} %{z}\
  621.             %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
  622.             %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
  623. #else
  624. /* Use -L and have the linker do the search for -lgcc.  */
  625. static char *link_command_spec = "\
  626. %{!fsyntax-only: \
  627.  %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
  628.             %{r} %{s} %{t} %{u*} %{x} %{z}\
  629.             %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
  630.             %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}";
  631. #endif
  632. #endif
  633.  
  634. /* A vector of options to give to the linker.
  635.    These options are accumulated by -Xlinker and -Wl,
  636.    and substituted into the linker command with %X.  */
  637. static int n_linker_options;
  638. static char **linker_options;
  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;
  645.  
  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"},
  679.    {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
  680.    {"--include-with-prefix-after", "-iwithprefix", "a"},
  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},
  692.    {"--version", "-dumpversion", 0},
  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.             }
  803.           else if (index (arginfo, '*') != 0)
  804.             ;
  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.  
  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.  */
  891.   buffer = xmalloc ((unsigned) statbuf.st_size + 1);
  892.   read (desc, buffer, (unsigned) statbuf.st_size);
  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;
  961.       bzero (compilers[n_compilers].spec,
  962.          sizeof compilers[n_compilers].spec);
  963.       compilers[n_compilers].spec[0] = spec;
  964.       n_compilers++;
  965.       bzero (&compilers[n_compilers], sizeof compilers[n_compilers]);
  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
  1001.    are accessed using %(specname) or %[specname] in a compiler or link spec. */
  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]))
  1043.     sl->spec = concat (old_spec, spec + 1, "");
  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;
  1071.   else if (! strcmp (name, "cross_compile"))
  1072.     cross_compile = atoi (sl->spec);
  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.  
  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.  
  1104. /* Number of commands executed so far.  */
  1105.  
  1106. static int execution_count;
  1107.  
  1108. /* Number of commands that exited with a signal.  */
  1109.  
  1110. static int signal_count;
  1111.  
  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.  */
  1123.   /* 2 means try both machine_suffix and just_machine_suffix.  */
  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.  
  1142. /* Suffix to attach to directories searched for commands.
  1143.    This looks like `MACHINE/VERSION/'.  */
  1144.  
  1145. static char *machine_suffix = 0;
  1146.  
  1147. /* Suffix to attach to directories searched for commands.
  1148.    This is just `MACHINE/'.  */
  1149.  
  1150. static char *just_machine_suffix = 0;
  1151.  
  1152. /* Adjusted value of GCC_EXEC_PREFIX envvar.  */
  1153.  
  1154. static char *gcc_exec_prefix;
  1155.  
  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
  1161. #undef MD_STARTFILE_PREFIX_1
  1162. #endif
  1163.  
  1164. #ifndef STANDARD_EXEC_PREFIX
  1165. #define STANDARD_EXEC_PREFIX "/gnu/lib/gcc-lib/"
  1166. #endif /* !defined STANDARD_EXEC_PREFIX */
  1167.  
  1168. static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
  1169. static char *standard_exec_prefix_1 = "/local/lib/gcc-lib/";
  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 "/gnu/lib/"
  1176. #endif /* !defined STANDARD_STARTFILE_PREFIX */
  1177.  
  1178. #ifdef MD_STARTFILE_PREFIX
  1179. static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
  1180. #endif
  1181. #ifdef MD_STARTFILE_PREFIX_1
  1182. static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
  1183. #endif
  1184. static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
  1185. static char *standard_startfile_prefix_1 = "/local/lib/";
  1186. static char *standard_startfile_prefix_2 = "/local/lib/";
  1187.  
  1188. #ifndef TOOLDIR_BASE_PREFIX
  1189. #define TOOLDIR_BASE_PREFIX "/local/"
  1190. #endif
  1191. static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
  1192. static char *tooldir_prefix;
  1193.  
  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.  
  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.  
  1387. static void
  1388. choose_temp_base ()
  1389. {
  1390.   char *base = 0;
  1391.   int len;
  1392.  
  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.  
  1397. #ifdef P_tmpdir
  1398.   base = choose_temp_base_try (P_tmpdir, base);
  1399. #endif
  1400.  
  1401. #ifdef amigados
  1402.   base = "ram:";
  1403. #else
  1404.   base = choose_temp_base_try ("/usr/tmp", base);
  1405.   base = choose_temp_base_try ("/tmp", base);
  1406. #endif
  1407.  
  1408.   /* If all else fails, use the current directory! */  
  1409.   if (base == (char *)0)
  1410.     base = "./";
  1411.  
  1412.   len = strlen (base);
  1413.   temp_filename = xmalloc (len + sizeof("/ccXXXXXX") + 1);
  1414.   strcpy (temp_filename, base);
  1415.   if (len > 0 && temp_filename[len-1] != '/'
  1416. #ifdef amigados
  1417.                         && temp_filename[len-1] != ':'
  1418. #endif
  1419.                                     )
  1420.     temp_filename[len++] = '/';
  1421.   strcpy (temp_filename + len, "ccXXXXXX");
  1422.  
  1423.   mktemp (temp_filename);
  1424.   temp_filename_length = strlen (temp_filename);
  1425.   if (temp_filename_length == 0)
  1426.     abort ();
  1427. }
  1428.  
  1429.  
  1430. /* Routine to add variables to the environment.  We do this to pass
  1431.    the pathname of the gcc driver, and the directories search to the
  1432.    collect2 program, which is being run as ld.  This way, we can be
  1433.    sure of executing the right compiler when collect2 wants to build
  1434.    constructors and destructors.  Since the environment variables we
  1435.    use come from an obstack, we don't have to worry about allocating
  1436.    space for them.  */
  1437.  
  1438. #ifndef HAVE_PUTENV
  1439.  
  1440. void
  1441. putenv (str)
  1442.      char *str;
  1443. {
  1444. #ifndef VMS            /* nor about VMS */
  1445.  
  1446.   extern char **environ;
  1447.   char **old_environ = environ;
  1448.   char **envp;
  1449.   int num_envs = 0;
  1450.   int name_len = 1;
  1451.   int str_len = strlen (str);
  1452.   char *p = str;
  1453.   int ch;
  1454.  
  1455.   while ((ch = *p++) != '\0' && ch != '=')
  1456.     name_len++;
  1457.  
  1458.   if (!ch)
  1459.     abort ();
  1460.  
  1461.   /* Search for replacing an existing environment variable, and
  1462.      count the number of total environment variables.  */
  1463.   for (envp = old_environ; *envp; envp++)
  1464.     {
  1465.       num_envs++;
  1466.       if (!strncmp (str, *envp, name_len))
  1467.     {
  1468.       *envp = str;
  1469.       return;
  1470.     }
  1471.     }
  1472.  
  1473.   /* Add a new environment variable */
  1474.   environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
  1475.   *environ = str;
  1476.   bcopy (old_environ, environ+1, sizeof (char *) * (num_envs+1));
  1477.  
  1478. #endif    /* VMS */
  1479. }
  1480.  
  1481. #endif    /* HAVE_PUTENV */
  1482.  
  1483.  
  1484. /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect.  */
  1485.  
  1486. static void
  1487. putenv_from_prefixes (paths, env_var)
  1488.      struct path_prefix *paths;
  1489.      char *env_var;
  1490. {
  1491.   int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
  1492.   int just_suffix_len
  1493.     = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
  1494.   int first_time = TRUE;
  1495.   struct prefix_list *pprefix;
  1496.  
  1497.   obstack_grow (&collect_obstack, env_var, strlen (env_var));
  1498.  
  1499.   for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
  1500.     {
  1501.       int len = strlen (pprefix->prefix);
  1502.  
  1503.       if (machine_suffix
  1504.       && is_directory (pprefix->prefix, machine_suffix, 0))
  1505.     {
  1506.       if (!first_time)
  1507.         obstack_1grow (&collect_obstack, PATH_SEPARATOR);
  1508.         
  1509.       first_time = FALSE;
  1510.       obstack_grow (&collect_obstack, pprefix->prefix, len);
  1511.       obstack_grow (&collect_obstack, machine_suffix, suffix_len);
  1512.     }
  1513.  
  1514.       if (just_machine_suffix
  1515.       && pprefix->require_machine_suffix == 2
  1516.       && is_directory (pprefix->prefix, just_machine_suffix, 0))
  1517.     {
  1518.       if (!first_time)
  1519.         obstack_1grow (&collect_obstack, PATH_SEPARATOR);
  1520.         
  1521.       first_time = FALSE;
  1522.       obstack_grow (&collect_obstack, pprefix->prefix, len);
  1523.       obstack_grow (&collect_obstack, just_machine_suffix,
  1524.             just_suffix_len);
  1525.     }
  1526.  
  1527.       if (!pprefix->require_machine_suffix)
  1528.     {
  1529.       if (!first_time)
  1530.         obstack_1grow (&collect_obstack, PATH_SEPARATOR);
  1531.  
  1532.       first_time = FALSE;
  1533.       obstack_grow (&collect_obstack, pprefix->prefix, len);
  1534.     }
  1535.     }
  1536.   obstack_1grow (&collect_obstack, '\0');
  1537.   putenv (obstack_finish (&collect_obstack));
  1538. }
  1539.  
  1540.  
  1541. /* Search for NAME using the prefix list PREFIXES.  MODE is passed to
  1542.    access to check permissions.
  1543.    Return 0 if not found, otherwise return its name, allocated with malloc. */
  1544.  
  1545. static char *
  1546. find_a_file (pprefix, name, mode)
  1547.      struct path_prefix *pprefix;
  1548.      char *name;
  1549.      int mode;
  1550. {
  1551.   char *temp;
  1552.   char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
  1553.   struct prefix_list *pl;
  1554.   int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
  1555.  
  1556.   if (machine_suffix)
  1557.     len += strlen (machine_suffix);
  1558.  
  1559.   temp = xmalloc (len);
  1560.  
  1561.   /* Determine the filename to execute (special case for absolute paths).  */
  1562.  
  1563.   if (*name == '/'
  1564. #ifdef amigados
  1565.           || index (name, ':')
  1566. #endif
  1567.                     )
  1568.     {
  1569.       if (access (name, mode))
  1570.     {
  1571.       strcpy (temp, name);
  1572.       return temp;
  1573.     }
  1574.     }
  1575.   else
  1576.     for (pl = pprefix->plist; pl; pl = pl->next)
  1577.       {
  1578.     if (machine_suffix)
  1579.       {
  1580.         strcpy (temp, pl->prefix);
  1581.         strcat (temp, machine_suffix);
  1582.         strcat (temp, name);
  1583.         if (access (temp, mode) == 0)
  1584.           {
  1585.         if (pl->used_flag_ptr != 0)
  1586.           *pl->used_flag_ptr = 1;
  1587.         return temp;
  1588.           }
  1589.         /* Some systems have a suffix for executable files.
  1590.            So try appending that.  */
  1591.         if (file_suffix[0] != 0)
  1592.           {
  1593.         strcat (temp, file_suffix);
  1594.         if (access (temp, mode) == 0)
  1595.           {
  1596.             if (pl->used_flag_ptr != 0)
  1597.               *pl->used_flag_ptr = 1;
  1598.             return temp;
  1599.           }
  1600.           }
  1601.       }
  1602.     /* Certain prefixes are tried with just the machine type,
  1603.        not the version.  This is used for finding as, ld, etc.  */
  1604.     if (just_machine_suffix && pl->require_machine_suffix == 2)
  1605.       {
  1606.         strcpy (temp, pl->prefix);
  1607.         strcat (temp, just_machine_suffix);
  1608.         strcat (temp, name);
  1609.         if (access (temp, mode) == 0)
  1610.           {
  1611.         if (pl->used_flag_ptr != 0)
  1612.           *pl->used_flag_ptr = 1;
  1613.         return temp;
  1614.           }
  1615.         /* Some systems have a suffix for executable files.
  1616.            So try appending that.  */
  1617.         if (file_suffix[0] != 0)
  1618.           {
  1619.         strcat (temp, file_suffix);
  1620.         if (access (temp, mode) == 0)
  1621.           {
  1622.             if (pl->used_flag_ptr != 0)
  1623.               *pl->used_flag_ptr = 1;
  1624.             return temp;
  1625.           }
  1626.           }
  1627.       }
  1628.     /* Certain prefixes can't be used without the machine suffix
  1629.        when the machine or version is explicitly specified.  */
  1630.     if (!pl->require_machine_suffix)
  1631.       {
  1632.         strcpy (temp, pl->prefix);
  1633.         strcat (temp, name);
  1634.         if (access (temp, mode) == 0)
  1635.           {
  1636.         if (pl->used_flag_ptr != 0)
  1637.           *pl->used_flag_ptr = 1;
  1638.         return temp;
  1639.           }
  1640.         /* Some systems have a suffix for executable files.
  1641.            So try appending that.  */
  1642.         if (file_suffix[0] != 0)
  1643.           {
  1644.         strcat (temp, file_suffix);
  1645.         if (access (temp, mode) == 0)
  1646.           {
  1647.             if (pl->used_flag_ptr != 0)
  1648.               *pl->used_flag_ptr = 1;
  1649.             return temp;
  1650.           }
  1651.           }
  1652.       }
  1653.       }
  1654.  
  1655.   free (temp);
  1656.   return 0;
  1657. }
  1658.  
  1659. /* Add an entry for PREFIX in PLIST.  If FIRST is set, it goes
  1660.    at the start of the list, otherwise it goes at the end.
  1661.  
  1662.    If WARN is nonzero, we will warn if no file is found
  1663.    through this prefix.  WARN should point to an int
  1664.    which will be set to 1 if this entry is used.
  1665.  
  1666.    REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
  1667.    the complete value of machine_suffix.
  1668.    2 means try both machine_suffix and just_machine_suffix.  */
  1669.  
  1670. static void
  1671. add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
  1672.      struct path_prefix *pprefix;
  1673.      char *prefix;
  1674.      int first;
  1675.      int require_machine_suffix;
  1676.      int *warn;
  1677. {
  1678.   struct prefix_list *pl, **prev;
  1679.   int len;
  1680.  
  1681.   if (!first && pprefix->plist)
  1682.     {
  1683.       for (pl = pprefix->plist; pl->next; pl = pl->next)
  1684.     ;
  1685.       prev = &pl->next;
  1686.     }
  1687.   else
  1688.     prev = &pprefix->plist;
  1689.  
  1690.   /* Keep track of the longest prefix */
  1691.  
  1692.   len = strlen (prefix);
  1693.   if (len > pprefix->max_len)
  1694.     pprefix->max_len = len;
  1695.  
  1696.   pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
  1697.   pl->prefix = save_string (prefix, len);
  1698.   pl->require_machine_suffix = require_machine_suffix;
  1699.   pl->used_flag_ptr = warn;
  1700.   if (warn)
  1701.     *warn = 0;
  1702.  
  1703.   if (*prev)
  1704.     pl->next = *prev;
  1705.   else
  1706.     pl->next = (struct prefix_list *) 0;
  1707.   *prev = pl;
  1708. }
  1709.  
  1710. /* Print warnings for any prefixes in the list PPREFIX that were not used.  */
  1711.  
  1712. static void
  1713. unused_prefix_warnings (pprefix)
  1714.      struct path_prefix *pprefix;
  1715. {
  1716.   struct prefix_list *pl = pprefix->plist;
  1717.  
  1718.   while (pl)
  1719.     {
  1720.       if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
  1721.     {
  1722.       error ("file path prefix `%s' never used",
  1723.          pl->prefix);
  1724.       /* Prevent duplicate warnings.  */
  1725.       *pl->used_flag_ptr = 1;
  1726.     }
  1727.       pl = pl->next;
  1728.     }
  1729. }
  1730.  
  1731. /* Get rid of all prefixes built up so far in *PLISTP. */
  1732.  
  1733. static void
  1734. free_path_prefix (pprefix)
  1735.      struct path_prefix *pprefix;
  1736. {
  1737.   struct prefix_list *pl = pprefix->plist;
  1738.   struct prefix_list *temp;
  1739.  
  1740.   while (pl)
  1741.     {
  1742.       temp = pl;
  1743.       pl = pl->next;
  1744.       free (temp->prefix);
  1745.       free ((char *) temp);
  1746.     }
  1747.   pprefix->plist = (struct prefix_list *) 0;
  1748. }
  1749.  
  1750. /* stdin file number.  */
  1751. #define STDIN_FILE_NO 0
  1752.  
  1753. /* stdout file number.  */
  1754. #define STDOUT_FILE_NO 1
  1755.  
  1756. /* value of `pipe': port index for reading.  */
  1757. #define READ_PORT 0
  1758.  
  1759. /* value of `pipe': port index for writing.  */
  1760. #define WRITE_PORT 1
  1761.  
  1762. /* Pipe waiting from last process, to be used as input for the next one.
  1763.    Value is STDIN_FILE_NO if no pipe is waiting
  1764.    (i.e. the next command is the first of a group).  */
  1765.  
  1766. static int last_pipe_input;
  1767.  
  1768. /* Fork one piped subcommand.  FUNC is the system call to use
  1769.    (either execv or execvp).  ARGV is the arg vector to use.
  1770.    NOT_LAST is nonzero if this is not the last subcommand
  1771.    (i.e. its output should be piped to the next one.)  */
  1772.  
  1773. #ifndef PEXECUTE
  1774. #ifndef OS2
  1775. #ifdef __MSDOS__
  1776.  
  1777. /* Declare these to avoid compilation error.  They won't be called.  */
  1778. int execv(const char *a, const char **b){}
  1779. int execvp(const char *a, const char **b){}
  1780.  
  1781. static int
  1782. pexecute (search_flag, program, argv, not_last)
  1783.      int search_flag;
  1784.      char *program;
  1785.      char *argv[];
  1786.      int not_last;
  1787. {
  1788.   char *scmd, *rf;
  1789.   FILE *argfile;
  1790.   int i, el = search_flag ? 0 : 4;
  1791.  
  1792.   scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6 + el);
  1793.   rf = scmd + strlen(program) + 2 + el;
  1794.   sprintf (scmd, "%s%s @%s.gp", program,
  1795.        (search_flag ? "" : ".exe"), temp_filename);
  1796.   argfile = fopen (rf, "w");
  1797.   if (argfile == 0)
  1798.     pfatal_with_name (rf);
  1799.  
  1800.   for (i=1; argv[i]; i++)
  1801.     {
  1802.       char *cp;
  1803.       for (cp = argv[i]; *cp; cp++)
  1804.     {
  1805.       if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
  1806.         fputc ('\\', argfile);
  1807.       fputc (*cp, argfile);
  1808.     }
  1809.       fputc ('\n', argfile);
  1810.     }
  1811.   fclose (argfile);
  1812.  
  1813.   i = system (scmd);
  1814.  
  1815.   remove (rf);
  1816.   
  1817.   if (i == -1)
  1818.     {
  1819.       perror_exec (program);
  1820.       return MIN_FATAL_STATUS << 8;
  1821.     }
  1822.  
  1823.   return i << 8;
  1824. }
  1825.  
  1826. #else /* not __MSDOS__ */
  1827.  
  1828. static int
  1829. pexecute (search_flag, program, argv, not_last)
  1830.      int search_flag;
  1831.      char *program;
  1832.      char *argv[];
  1833.      int not_last;
  1834. {
  1835.   int (*func)() = (search_flag ? execv : execvp);
  1836.   int pid;
  1837.   int pdes[2];
  1838.   int input_desc = last_pipe_input;
  1839.   int output_desc = STDOUT_FILE_NO;
  1840.   int retries, sleep_interval;
  1841.  
  1842.   /* If this isn't the last process, make a pipe for its output,
  1843.      and record it as waiting to be the input to the next process.  */
  1844.  
  1845.   if (not_last)
  1846.     {
  1847.       if (pipe (pdes) < 0)
  1848.     pfatal_with_name ("pipe");
  1849.       output_desc = pdes[WRITE_PORT];
  1850.       last_pipe_input = pdes[READ_PORT];
  1851.     }
  1852.   else
  1853.     last_pipe_input = STDIN_FILE_NO;
  1854.  
  1855.   /* Fork a subprocess; wait and retry if it fails.  */
  1856.   sleep_interval = 1;
  1857.   for (retries = 0; retries < 4; retries++)
  1858.     {
  1859.       pid = vfork ();
  1860.       if (pid >= 0)
  1861.     break;
  1862.       sleep (sleep_interval);
  1863.       sleep_interval *= 2;
  1864.     }
  1865.  
  1866.   switch (pid)
  1867.     {
  1868.     case -1:
  1869. #ifdef vfork
  1870.       pfatal_with_name ("fork");
  1871. #else
  1872.       pfatal_with_name ("vfork");
  1873. #endif
  1874.       /* NOTREACHED */
  1875.       return 0;
  1876.  
  1877.     case 0: /* child */
  1878.       /* Move the input and output pipes into place, if nec.  */
  1879.       if (input_desc != STDIN_FILE_NO)
  1880.     {
  1881.       close (STDIN_FILE_NO);
  1882.       dup (input_desc);
  1883.       close (input_desc);
  1884.     }
  1885.       if (output_desc != STDOUT_FILE_NO)
  1886.     {
  1887.       close (STDOUT_FILE_NO);
  1888.       dup (output_desc);
  1889.       close (output_desc);
  1890.     }
  1891.  
  1892.       /* Close the parent's descs that aren't wanted here.  */
  1893.       if (last_pipe_input != STDIN_FILE_NO)
  1894.     close (last_pipe_input);
  1895.  
  1896.       /* Exec the program.  */
  1897.       (*func) (program, argv);
  1898.       perror_exec (program);
  1899.       exit (-1);
  1900.       /* NOTREACHED */
  1901.       return 0;
  1902.  
  1903.     default:
  1904.       /* In the parent, after forking.
  1905.      Close the descriptors that we made for this child.  */
  1906.       if (input_desc != STDIN_FILE_NO)
  1907.     close (input_desc);
  1908.       if (output_desc != STDOUT_FILE_NO)
  1909.     close (output_desc);
  1910.  
  1911.       /* Return child's process number.  */
  1912.       return pid;
  1913.     }
  1914. }
  1915.  
  1916. #endif /* not __MSDOS__ */
  1917. #else /* not OS2 */
  1918.  
  1919. static int
  1920. pexecute (search_flag, program, argv, not_last)
  1921.      int search_flag;
  1922.      char *program;
  1923.      char *argv[];
  1924.      int not_last;
  1925. {
  1926.   return (search_flag ? spawnv : spawnvp) (1, program, argv);
  1927. }
  1928. #endif /* not OS2 */
  1929. #endif /* !defined (PEXECUTE) */
  1930.  
  1931. /* Execute the command specified by the arguments on the current line of spec.
  1932.    When using pipes, this includes several piped-together commands
  1933.    with `|' between them.
  1934.  
  1935.    Return 0 if successful, -1 if failed.  */
  1936.  
  1937. static int
  1938. execute ()
  1939. {
  1940.   int i;
  1941.   int n_commands;        /* # of command.  */
  1942.   char *string;
  1943.   struct command
  1944.     {
  1945.       char *prog;        /* program name.  */
  1946.       char **argv;        /* vector of args.  */
  1947.       int pid;            /* pid of process for this command.  */
  1948.     };
  1949.  
  1950.   struct command *commands;    /* each command buffer with above info.  */
  1951.  
  1952.   /* Count # of piped commands.  */
  1953.   for (n_commands = 1, i = 0; i < argbuf_index; i++)
  1954.     if (strcmp (argbuf[i], "|") == 0)
  1955.       n_commands++;
  1956.  
  1957.   /* Get storage for each command.  */
  1958.   commands
  1959.     = (struct command *) alloca (n_commands * sizeof (struct command));
  1960.  
  1961.   /* Split argbuf into its separate piped processes,
  1962.      and record info about each one.
  1963.      Also search for the programs that are to be run.  */
  1964.  
  1965.   commands[0].prog = argbuf[0]; /* first command.  */
  1966.   commands[0].argv = &argbuf[0];
  1967.   string = find_a_file (&exec_prefix, commands[0].prog, X_OK);
  1968.   if (string)
  1969.     commands[0].argv[0] = string;
  1970.  
  1971.   for (n_commands = 1, i = 0; i < argbuf_index; i++)
  1972.     if (strcmp (argbuf[i], "|") == 0)
  1973.       {                /* each command.  */
  1974. #ifdef __MSDOS__
  1975.         fatal ("-pipe not supported under MS-DOS");
  1976. #endif
  1977.     argbuf[i] = 0;    /* termination of command args.  */
  1978.     commands[n_commands].prog = argbuf[i + 1];
  1979.     commands[n_commands].argv = &argbuf[i + 1];
  1980.     string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK);
  1981.     if (string)
  1982.       commands[n_commands].argv[0] = string;
  1983.     n_commands++;
  1984.       }
  1985.  
  1986.   argbuf[argbuf_index] = 0;
  1987.  
  1988.   /* If -v, print what we are about to do, and maybe query.  */
  1989.  
  1990.   if (verbose_flag)
  1991.     {
  1992.       /* Print each piped command as a separate line.  */
  1993.       for (i = 0; i < n_commands ; i++)
  1994.     {
  1995.       char **j;
  1996.  
  1997.       for (j = commands[i].argv; *j; j++)
  1998.         fprintf (stderr, " %s", *j);
  1999.  
  2000.       /* Print a pipe symbol after all but the last command.  */
  2001.       if (i + 1 != n_commands)
  2002.         fprintf (stderr, " |");
  2003.       fprintf (stderr, "\n");
  2004.     }
  2005.       fflush (stderr);
  2006. #ifdef DEBUG
  2007.       fprintf (stderr, "\nGo ahead? (y or n) ");
  2008.       fflush (stderr);
  2009.       i = getchar ();
  2010.       if (i != '\n')
  2011.     while (getchar () != '\n') ;
  2012.       if (i != 'y' && i != 'Y')
  2013.     return 0;
  2014. #endif /* DEBUG */
  2015.     }
  2016.  
  2017.   /* Run each piped subprocess.  */
  2018.  
  2019.   last_pipe_input = STDIN_FILE_NO;
  2020.   for (i = 0; i < n_commands; i++)
  2021.     {
  2022.       char *string = commands[i].argv[0];
  2023.  
  2024. #ifdef PEXECUTE
  2025.       commands[i].pid = PEXECUTE (string != commands[i].prog,
  2026.                   string, commands[i].argv,
  2027.                   i + 1 < n_commands);
  2028. #else
  2029.       commands[i].pid = pexecute (string != commands[i].prog,
  2030.                   string, commands[i].argv,
  2031.                   i + 1 < n_commands);
  2032. #endif
  2033.  
  2034.       if (string != commands[i].prog)
  2035.     free (string);
  2036.     }
  2037.  
  2038.   execution_count++;
  2039.  
  2040.   /* Wait for all the subprocesses to finish.
  2041.      We don't care what order they finish in;
  2042.      we know that N_COMMANDS waits will get them all.  */
  2043.  
  2044.   {
  2045.     int ret_code = 0;
  2046.  
  2047.     for (i = 0; i < n_commands; i++)
  2048.       {
  2049.     int status;
  2050.     int pid;
  2051.     char *prog;
  2052.  
  2053. #ifdef PEXECUTE_RESULT
  2054.     pid = PEXECUTE_RESULT (status, commands[i]);
  2055. #else /* PEXECUTE_RESULT */
  2056. #ifdef __MSDOS__
  2057.         status = pid = commands[i].pid;
  2058. #else
  2059.     pid = wait (&status);
  2060. #endif
  2061. #endif /* PEXECUTE_RESULT */
  2062.     if (pid < 0)
  2063.       abort ();
  2064.  
  2065.     if (status != 0)
  2066.       {
  2067.         int j;
  2068.         for (j = 0; j < n_commands; j++)
  2069.           if (commands[j].pid == pid)
  2070.         prog = commands[j].prog;
  2071.  
  2072.         if ((status & 0x7F) != 0)
  2073.           {
  2074.         fatal ("Internal compiler error: program %s got fatal signal %d",
  2075.                prog, (status & 0x7F));
  2076.         signal_count++;
  2077.           }
  2078.         if (((status & 0xFF00) >> 8) >= MIN_FATAL_STATUS)
  2079.           ret_code = -1;
  2080.       }
  2081.       }
  2082.     return ret_code;
  2083.   }
  2084. }
  2085.  
  2086. /* Find all the switches given to us
  2087.    and make a vector describing them.
  2088.    The elements of the vector are strings, one per switch given.
  2089.    If a switch uses following arguments, then the `part1' field
  2090.    is the switch itself and the `args' field
  2091.    is a null-terminated vector containing the following arguments.
  2092.    The `valid' field is nonzero if any spec has looked at this switch;
  2093.    if it remains zero at the end of the run, it must be meaningless.  */
  2094.  
  2095. struct switchstr
  2096. {
  2097.   char *part1;
  2098.   char **args;
  2099.   int valid;
  2100. };
  2101.  
  2102. static struct switchstr *switches;
  2103.  
  2104. static int n_switches;
  2105.  
  2106. struct infile
  2107. {
  2108.   char *name;
  2109.   char *language;
  2110. };
  2111.  
  2112. /* Also a vector of input files specified.  */
  2113.  
  2114. static struct infile *infiles;
  2115.  
  2116. static int n_infiles;
  2117.  
  2118. /* And a vector of corresponding output files is made up later.  */
  2119.  
  2120. static char **outfiles;
  2121.  
  2122. /* Create the vector `switches' and its contents.
  2123.    Store its length in `n_switches'.  */
  2124.  
  2125. static void
  2126. process_command (argc, argv)
  2127.      int argc;
  2128.      char **argv;
  2129. {
  2130.   register int i;
  2131.   char *temp;
  2132.   char *spec_lang = 0;
  2133.   int last_language_n_infiles;
  2134.  
  2135.   gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
  2136.  
  2137.   n_switches = 0;
  2138.   n_infiles = 0;
  2139.  
  2140.   /* Default for -V is our version number, ending at first space.  */
  2141.   spec_version = save_string (version_string, strlen (version_string));
  2142.   for (temp = spec_version; *temp && *temp != ' '; temp++);
  2143.   if (*temp) *temp = '\0';
  2144.  
  2145.   /* Set up the default search paths.  */
  2146.  
  2147.   if (gcc_exec_prefix)
  2148.     {
  2149.       add_prefix (&exec_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
  2150.       add_prefix (&startfile_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
  2151.     }
  2152.  
  2153.   /* COMPILER_PATH and LIBRARY_PATH have values
  2154.      that are lists of directory names with colons.  */
  2155.  
  2156.   temp = getenv ("COMPILER_PATH");
  2157.   if (temp)
  2158.     {
  2159.       char *startp, *endp;
  2160.       char *nstore = (char *) alloca (strlen (temp) + 3);
  2161.  
  2162.       startp = endp = temp;
  2163.       while (1)
  2164.     {
  2165.       if (*endp == PATH_SEPARATOR || *endp == 0)
  2166.         {
  2167.           strncpy (nstore, startp, endp-startp);
  2168. #ifndef amigados
  2169.           if (endp == startp)
  2170.         {
  2171.           strcpy (nstore, "./");
  2172.         }
  2173.           else if (endp[-1] != '/')
  2174.         {
  2175.           nstore[endp-startp] = '/';
  2176.           nstore[endp-startp+1] = 0;
  2177.         }
  2178.           else
  2179.         nstore[endp-startp] = 0;
  2180. #else
  2181.           if (endp[-1] != '/' && endp[-1] != ':')
  2182.         {
  2183.           nstore[endp-startp] = '/';
  2184.           nstore[endp-startp+1] = 0;
  2185.         }
  2186.           else
  2187.         nstore[endp-startp] = 0;
  2188. #endif
  2189.           add_prefix (&exec_prefix, nstore, 0, 0, NULL_PTR);
  2190.           if (*endp == 0)
  2191.         break;
  2192.           endp = startp = endp + 1;
  2193.         }
  2194.       else
  2195.         endp++;
  2196.     }
  2197.     }
  2198.  
  2199.   temp = getenv ("LIBRARY_PATH");
  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.     {
  2208.       if (*endp == PATH_SEPARATOR || *endp == 0)
  2209.         {
  2210.           strncpy (nstore, startp, endp-startp);
  2211. #ifndef amigados
  2212.           if (endp == startp)
  2213.         {
  2214.           strcpy (nstore, "./");
  2215.         }
  2216.           else if (endp[-1] != '/')
  2217.         {
  2218.           nstore[endp-startp] = '/';
  2219.           nstore[endp-startp+1] = 0;
  2220.         }
  2221.           else
  2222.         nstore[endp-startp] = 0;
  2223. #else
  2224.           if (endp[-1] != '/' && endp[-1] != ':')
  2225.         {
  2226.           nstore[endp-startp] = '/';
  2227.           nstore[endp-startp+1] = 0;
  2228.         }
  2229.           else
  2230.         nstore[endp-startp] = 0;
  2231. #endif
  2232.           add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
  2233.           if (*endp == 0)
  2234.         break;
  2235.           endp = startp = endp + 1;
  2236.         }
  2237.       else
  2238.         endp++;
  2239.     }
  2240.     }
  2241.  
  2242.   /* Use LPATH like LIBRARY_PATH (for the CMU build program).  */
  2243.   temp = getenv ("LPATH");
  2244.   if (temp)
  2245.     {
  2246.       char *startp, *endp;
  2247.       char *nstore = (char *) alloca (strlen (temp) + 3);
  2248.  
  2249.       startp = endp = temp;
  2250.       while (1)
  2251.     {
  2252.       if (*endp == PATH_SEPARATOR || *endp == 0)
  2253.         {
  2254.           strncpy (nstore, startp, endp-startp);
  2255. #ifndef amigados
  2256.           if (endp == startp)
  2257.         {
  2258.           strcpy (nstore, "./");
  2259.         }
  2260.           else if (endp[-1] != '/')
  2261.         {
  2262.           nstore[endp-startp] = '/';
  2263.           nstore[endp-startp+1] = 0;
  2264.         }
  2265.           else
  2266.         nstore[endp-startp] = 0;
  2267. #else
  2268.           if (endp[-1] != '/' && endp[-1] != ':')
  2269.         {
  2270.           nstore[endp-startp] = '/';
  2271.           nstore[endp-startp+1] = 0;
  2272.         }
  2273.           else
  2274.         nstore[endp-startp] = 0;
  2275. #endif
  2276.           add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
  2277.           if (*endp == 0)
  2278.         break;
  2279.           endp = startp = endp + 1;
  2280.         }
  2281.       else
  2282.         endp++;
  2283.     }
  2284.     }
  2285.  
  2286.   /* Convert new-style -- options to old-style.  */
  2287.   translate_options (&argc, &argv);
  2288.  
  2289.   /* Scan argv twice.  Here, the first time, just count how many switches
  2290.      there will be in their vector, and how many input files in theirs.
  2291.      Here we also parse the switches that cc itself uses (e.g. -v).  */
  2292.  
  2293.   for (i = 1; i < argc; i++)
  2294.     {
  2295.       if (! strcmp (argv[i], "-dumpspecs"))
  2296.     {
  2297.       printf ("*asm:\n%s\n\n", asm_spec);
  2298.       printf ("*asm_final:\n%s\n\n", asm_final_spec);
  2299.       printf ("*cpp:\n%s\n\n", cpp_spec);
  2300.       printf ("*cc1:\n%s\n\n", cc1_spec);
  2301.       printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
  2302.       printf ("*endfile:\n%s\n\n", endfile_spec);
  2303.       printf ("*link:\n%s\n\n", link_spec);
  2304.       printf ("*lib:\n%s\n\n", lib_spec);
  2305.       printf ("*startfile:\n%s\n\n", startfile_spec);
  2306.       printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
  2307.       printf ("*signed_char:\n%s\n\n", signed_char_spec);
  2308.       printf ("*predefines:\n%s\n\n", cpp_predefines);
  2309.       printf ("*cross_compile:\n%d\n\n", cross_compile);
  2310.  
  2311.       exit (0);
  2312.     }
  2313.       else if (! strcmp (argv[i], "-dumpversion"))
  2314.     {
  2315.       printf ("%s\n", version_string);
  2316.       exit (0);
  2317.     }
  2318.       else if (! strcmp (argv[i], "-print-libgcc-file-name"))
  2319.     {
  2320.       print_libgcc_file_name = 1;
  2321.     }
  2322.       else if (! strcmp (argv[i], "-Xlinker"))
  2323.     {
  2324.       /* Pass the argument of this option to the linker when we link.  */
  2325.  
  2326.       if (i + 1 == argc)
  2327.         fatal ("argument to `-Xlinker' is missing");
  2328.  
  2329.       n_linker_options++;
  2330.       if (!linker_options)
  2331.         linker_options
  2332.           = (char **) xmalloc (n_linker_options * sizeof (char **));
  2333.       else
  2334.         linker_options
  2335.           = (char **) xrealloc (linker_options,
  2336.                     n_linker_options * sizeof (char **));
  2337.  
  2338.       linker_options[n_linker_options - 1] = argv[++i];
  2339.     }
  2340.       else if (! strncmp (argv[i], "-Wl,", 4))
  2341.     {
  2342.       int prev, j;
  2343.       /* Pass the rest of this option to the linker when we link.  */
  2344.  
  2345.       n_linker_options++;
  2346.       if (!linker_options)
  2347.         linker_options
  2348.           = (char **) xmalloc (n_linker_options * sizeof (char **));
  2349.       else
  2350.         linker_options
  2351.           = (char **) xrealloc (linker_options,
  2352.                     n_linker_options * sizeof (char **));
  2353.  
  2354.       /* Split the argument at commas.  */
  2355.       prev = 4;
  2356.       for (j = 4; argv[i][j]; j++)
  2357.         if (argv[i][j] == ',')
  2358.           {
  2359.         linker_options[n_linker_options - 1]
  2360.           = save_string (argv[i] + prev, j - prev);
  2361.         n_linker_options++;
  2362.         linker_options
  2363.           = (char **) xrealloc (linker_options,
  2364.                     n_linker_options * sizeof (char **));
  2365.         prev = j + 1;
  2366.           }
  2367.       /* Record the part after the last comma.  */
  2368.       linker_options[n_linker_options - 1] = argv[i] + prev;
  2369.     }
  2370.       else if (! strncmp (argv[i], "-Wa,", 4))
  2371.     {
  2372.       int prev, j;
  2373.       /* Pass the rest of this option to the assembler.  */
  2374.  
  2375.       n_assembler_options++;
  2376.       if (!assembler_options)
  2377.         assembler_options
  2378.           = (char **) xmalloc (n_assembler_options * sizeof (char **));
  2379.       else
  2380.         assembler_options
  2381.           = (char **) xrealloc (assembler_options,
  2382.                     n_assembler_options * sizeof (char **));
  2383.  
  2384.       /* Split the argument at commas.  */
  2385.       prev = 4;
  2386.       for (j = 4; argv[i][j]; j++)
  2387.         if (argv[i][j] == ',')
  2388.           {
  2389.         assembler_options[n_assembler_options - 1]
  2390.           = save_string (argv[i] + prev, j - prev);
  2391.         n_assembler_options++;
  2392.         assembler_options
  2393.           = (char **) xrealloc (assembler_options,
  2394.                     n_assembler_options * sizeof (char **));
  2395.         prev = j + 1;
  2396.           }
  2397.       /* Record the part after the last comma.  */
  2398.       assembler_options[n_assembler_options - 1] = argv[i] + prev;
  2399.     }
  2400.       else if (argv[i][0] == '+' && argv[i][1] == 'e')
  2401.     /* The +e options to the C++ front-end.  */
  2402.     n_switches++;
  2403.       else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
  2404.     {
  2405.       register char *p = &argv[i][1];
  2406.       register int c = *p;
  2407.  
  2408.       switch (c)
  2409.         {
  2410.         case 'b':
  2411.           if (p[1] == 0 && i + 1 == argc)
  2412.         fatal ("argument to `-b' is missing");
  2413.           if (p[1] == 0)
  2414.         spec_machine = argv[++i];
  2415.           else
  2416.         spec_machine = p + 1;
  2417.           break;
  2418.  
  2419.         case 'B':
  2420.           {
  2421.         int *temp = (int *) xmalloc (sizeof (int));
  2422.         char *value;
  2423.         if (p[1] == 0 && i + 1 == argc)
  2424.           fatal ("argument to `-B' is missing");
  2425.         if (p[1] == 0)
  2426.           value = argv[++i];
  2427.         else
  2428.           value = p + 1;
  2429.         add_prefix (&exec_prefix, value, 1, 0, temp);
  2430.         add_prefix (&startfile_prefix, value, 1, 0, temp);
  2431.           }
  2432.           break;
  2433.  
  2434.         case 'v':    /* Print our subcommands and print versions.  */
  2435.           n_switches++;
  2436.           /* If they do anything other than exactly `-v', don't set
  2437.          verbose_flag; rather, continue on to give the error.  */
  2438.           if (p[1] != 0)
  2439.         break;
  2440.           verbose_flag++;
  2441.           break;
  2442.  
  2443.         case 'V':
  2444.           if (p[1] == 0 && i + 1 == argc)
  2445.         fatal ("argument to `-V' is missing");
  2446.           if (p[1] == 0)
  2447.         spec_version = argv[++i];
  2448.           else
  2449.         spec_version = p + 1;
  2450.           break;
  2451.  
  2452.         case 's':
  2453.           if (!strcmp (p, "save-temps"))
  2454.         {
  2455.           save_temps_flag = 1;
  2456.           n_switches++;
  2457.           break;
  2458.         }
  2459.         default:
  2460.           n_switches++;
  2461.  
  2462.           if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
  2463.         i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
  2464.           else if (WORD_SWITCH_TAKES_ARG (p))
  2465.         i += WORD_SWITCH_TAKES_ARG (p);
  2466.         }
  2467.     }
  2468.       else
  2469.     n_infiles++;
  2470.     }
  2471.  
  2472.   /* Set up the search paths before we go looking for config files.  */
  2473.  
  2474.   /* These come before the md prefixes so that we will find gcc's subcommands
  2475.      (such as cpp) rather than those of the host system.  */
  2476.   /* Use 2 as fourth arg meaning try just the machine as a suffix,
  2477.      as well as trying the machine and the version.  */
  2478.   add_prefix (&exec_prefix, standard_exec_prefix, 0, 2, NULL_PTR);
  2479.   add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 2, NULL_PTR);
  2480.  
  2481.   add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, NULL_PTR);
  2482.   add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, NULL_PTR);
  2483.  
  2484.   tooldir_prefix = concat (tooldir_base_prefix, spec_machine, "/");
  2485.  
  2486.   /* If tooldir is relative, base it on exec_prefix.  A relative
  2487.      tooldir lets us move the installed tree as a unit.
  2488.  
  2489.      If GCC_EXEC_PREFIX is defined, then we want to add two relative
  2490.      directories, so that we can search both the user specified directory
  2491.      and the standard place.  */
  2492.  
  2493.   if (*tooldir_prefix != '/')
  2494.     {
  2495.       if (gcc_exec_prefix)
  2496.     {
  2497.       char *gcc_exec_tooldir_prefix
  2498.         = concat (concat (gcc_exec_prefix, spec_machine, "/"),
  2499.               concat (spec_version, "/", tooldir_prefix),
  2500.               "");
  2501.  
  2502.       add_prefix (&exec_prefix, concat (gcc_exec_tooldir_prefix, "bin", "/"),
  2503.               0, 0, NULL_PTR);
  2504.       add_prefix (&startfile_prefix, concat (gcc_exec_tooldir_prefix, "lib", "/"),
  2505.               0, 0, NULL_PTR);
  2506.     }
  2507.  
  2508.       tooldir_prefix = concat (concat (standard_exec_prefix, spec_machine, "/"),
  2509.                    concat (spec_version, "/", tooldir_prefix),
  2510.                    "");
  2511.     }
  2512.  
  2513.   add_prefix (&exec_prefix, concat (tooldir_prefix, "bin", "/"),
  2514.           0, 0, NULL_PTR);
  2515.   add_prefix (&startfile_prefix, concat (tooldir_prefix, "lib", "/"),
  2516.           0, 0, NULL_PTR);
  2517.  
  2518.   /* More prefixes are enabled in main, after we read the specs file
  2519.      and determine whether this is cross-compilation or not.  */
  2520.  
  2521.  
  2522.   /* Then create the space for the vectors and scan again.  */
  2523.  
  2524.   switches = ((struct switchstr *)
  2525.           xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
  2526.   infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
  2527.   n_switches = 0;
  2528.   n_infiles = 0;
  2529.   last_language_n_infiles = -1;
  2530.  
  2531.   /* This, time, copy the text of each switch and store a pointer
  2532.      to the copy in the vector of switches.
  2533.      Store all the infiles in their vector.  */
  2534.  
  2535.   for (i = 1; i < argc; i++)
  2536.     {
  2537.       /* Just skip the switches that were handled by the preceding loop.  */
  2538.       if (!strcmp (argv[i], "-Xlinker"))
  2539.     i++;
  2540.       else if (! strncmp (argv[i], "-Wl,", 4))
  2541.     ;
  2542.       else if (! strncmp (argv[i], "-Wa,", 4))
  2543.     ;
  2544.       else if (! strcmp (argv[i], "-print-libgcc-file-name"))
  2545.     ;
  2546.       else if (argv[i][0] == '+' && argv[i][1] == 'e')
  2547.     {
  2548.       /* Compensate for the +e options to the C++ front-end;
  2549.          they're there simply for cfront call-compatibility.  We do
  2550.          some magic in default_compilers to pass them down properly.
  2551.          Note we deliberately start at the `+' here, to avoid passing
  2552.          -e0 or -e1 down into the linker.  */
  2553.       switches[n_switches].part1 = &argv[i][0];
  2554.       switches[n_switches].args = 0;
  2555.       switches[n_switches].valid = 0;
  2556.       n_switches++;
  2557.     }
  2558.       else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
  2559.     {
  2560.       register char *p = &argv[i][1];
  2561.       register int c = *p;
  2562.  
  2563.       if (c == 'B' || c == 'b' || c == 'V')
  2564.         {
  2565.           /* Skip a separate arg, if any.  */
  2566.           if (p[1] == 0)
  2567.         i++;
  2568.           continue;
  2569.         }
  2570.       if (c == 'x')
  2571.         {
  2572.           if (p[1] == 0 && i + 1 == argc)
  2573.         fatal ("argument to `-x' is missing");
  2574.           if (p[1] == 0)
  2575.         spec_lang = argv[++i];
  2576.           else
  2577.         spec_lang = p + 1;
  2578.           if (! strcmp (spec_lang, "none"))
  2579.         /* Suppress the warning if -xnone comes after the last input file,
  2580.            because alternate command interfaces like g++ might find it
  2581.            useful to place -xnone after each input file.  */
  2582.         spec_lang = 0;
  2583.           else
  2584.         last_language_n_infiles = n_infiles;
  2585.           continue;
  2586.         }
  2587.       switches[n_switches].part1 = p;
  2588.       /* Deal with option arguments in separate argv elements.  */
  2589.       if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
  2590.           || WORD_SWITCH_TAKES_ARG (p))
  2591.         {
  2592.           int j = 0;
  2593.           int n_args = WORD_SWITCH_TAKES_ARG (p);
  2594.  
  2595.           if (n_args == 0)
  2596.         {
  2597.           /* Count only the option arguments in separate argv elements.  */
  2598.           n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
  2599.         }
  2600.           if (i + n_args >= argc)
  2601.         fatal ("argument to `-%s' is missing", p);
  2602.           switches[n_switches].args
  2603.         = (char **) xmalloc ((n_args + 1) * sizeof (char *));
  2604.           while (j < n_args)
  2605.         switches[n_switches].args[j++] = argv[++i];
  2606.           /* Null-terminate the vector.  */
  2607.           switches[n_switches].args[j] = 0;
  2608.         }
  2609.       else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L'))
  2610.         {
  2611.           /* On some systems, ld cannot handle -o or -L without space.
  2612.          So split the -o or -L from its argument.  */
  2613.           switches[n_switches].part1 = (c == 'o' ? "o" : "L");
  2614.           switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
  2615.           switches[n_switches].args[0] = xmalloc (strlen (p));
  2616.           strcpy (switches[n_switches].args[0], &p[1]);
  2617.           switches[n_switches].args[1] = 0;
  2618.         }
  2619.       else
  2620.         switches[n_switches].args = 0;
  2621.       switches[n_switches].valid = 0;
  2622.       /* This is always valid, since gcc.c itself understands it.  */
  2623.       if (!strcmp (p, "save-temps"))
  2624.         switches[n_switches].valid = 1;
  2625.       n_switches++;
  2626.     }
  2627.       else
  2628.     {
  2629.       if ((argv[i][0] != '-' || argv[i][1] != 'l')
  2630.           && strcmp (argv[i], "-")
  2631.           && access (argv[i], R_OK) < 0)
  2632.         {
  2633.           perror_with_name (argv[i]);
  2634.           error_count++;
  2635.         }
  2636.       else
  2637.         {
  2638.           infiles[n_infiles].language = spec_lang;
  2639.           infiles[n_infiles++].name = argv[i];
  2640.         }
  2641.     }
  2642.     }
  2643.  
  2644.   if (n_infiles == last_language_n_infiles && spec_lang != 0)
  2645.     error ("Warning: `-x %s' after last input file has no effect", spec_lang);
  2646.  
  2647.   switches[n_switches].part1 = 0;
  2648.   infiles[n_infiles].name = 0;
  2649.  
  2650.   /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake.  */
  2651.   if (gcc_exec_prefix)
  2652.     {
  2653.       temp = (char *) xmalloc (strlen (gcc_exec_prefix) + strlen (spec_version)
  2654.                    + strlen (spec_machine) + 3);
  2655.       strcpy (temp, gcc_exec_prefix);
  2656.       strcat (temp, spec_machine);
  2657.       strcat (temp, "/");
  2658.       strcat (temp, spec_version);
  2659.       strcat (temp, "/");
  2660.       gcc_exec_prefix = temp;
  2661.     }
  2662. }
  2663.  
  2664. /* Process a spec string, accumulating and running commands.  */
  2665.  
  2666. /* These variables describe the input file name.
  2667.    input_file_number is the index on outfiles of this file,
  2668.    so that the output file name can be stored for later use by %o.
  2669.    input_basename is the start of the part of the input file
  2670.    sans all directory names, and basename_length is the number
  2671.    of characters starting there excluding the suffix .c or whatever.  */
  2672.  
  2673. static char *input_filename;
  2674. static int input_file_number;
  2675. static int input_filename_length;
  2676. static int basename_length;
  2677. static char *input_basename;
  2678. static char *input_suffix;
  2679.  
  2680. /* These are variables used within do_spec and do_spec_1.  */
  2681.  
  2682. /* Nonzero if an arg has been started and not yet terminated
  2683.    (with space, tab or newline).  */
  2684. static int arg_going;
  2685.  
  2686. /* Nonzero means %d or %g has been seen; the next arg to be terminated
  2687.    is a temporary file name.  */
  2688. static int delete_this_arg;
  2689.  
  2690. /* Nonzero means %w has been seen; the next arg to be terminated
  2691.    is the output file name of this compilation.  */
  2692. static int this_is_output_file;
  2693.  
  2694. /* Nonzero means %s has been seen; the next arg to be terminated
  2695.    is the name of a library file and we should try the standard
  2696.    search dirs for it.  */
  2697. static int this_is_library_file;
  2698.  
  2699. /* Nonzero means that the input of this command is coming from a pipe.  */
  2700. static int input_from_pipe;
  2701.  
  2702. /* Process the spec SPEC and run the commands specified therein.
  2703.    Returns 0 if the spec is successfully processed; -1 if failed.  */
  2704.  
  2705. static int
  2706. do_spec (spec)
  2707.      char *spec;
  2708. {
  2709.   int value;
  2710.  
  2711.   clear_args ();
  2712.   arg_going = 0;
  2713.   delete_this_arg = 0;
  2714.   this_is_output_file = 0;
  2715.   this_is_library_file = 0;
  2716.   input_from_pipe = 0;
  2717.  
  2718.   value = do_spec_1 (spec, 0, NULL_PTR);
  2719.  
  2720.   /* Force out any unfinished command.
  2721.      If -pipe, this forces out the last command if it ended in `|'.  */
  2722.   if (value == 0)
  2723.     {
  2724.       if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
  2725.     argbuf_index--;
  2726.  
  2727.       if (argbuf_index > 0)
  2728.     value = execute ();
  2729.     }
  2730.  
  2731.   return value;
  2732. }
  2733.  
  2734. /* Process the sub-spec SPEC as a portion of a larger spec.
  2735.    This is like processing a whole spec except that we do
  2736.    not initialize at the beginning and we do not supply a
  2737.    newline by default at the end.
  2738.    INSWITCH nonzero means don't process %-sequences in SPEC;
  2739.    in this case, % is treated as an ordinary character.
  2740.    This is used while substituting switches.
  2741.    INSWITCH nonzero also causes SPC not to terminate an argument.
  2742.  
  2743.    Value is zero unless a line was finished
  2744.    and the command on that line reported an error.  */
  2745.  
  2746. static int
  2747. do_spec_1 (spec, inswitch, soft_matched_part)
  2748.      char *spec;
  2749.      int inswitch;
  2750.      char *soft_matched_part;
  2751. {
  2752.   register char *p = spec;
  2753.   register int c;
  2754.   int i;
  2755.   char *string;
  2756.   int value;
  2757.  
  2758.   while (c = *p++)
  2759.     /* If substituting a switch, treat all chars like letters.
  2760.        Otherwise, NL, SPC, TAB and % are special.  */
  2761.     switch (inswitch ? 'a' : c)
  2762.       {
  2763.       case '\n':
  2764.     /* End of line: finish any pending argument,
  2765.        then run the pending command if one has been started.  */
  2766.     if (arg_going)
  2767.       {
  2768.         obstack_1grow (&obstack, 0);
  2769.         string = obstack_finish (&obstack);
  2770.         if (this_is_library_file)
  2771.           string = find_file (string);
  2772.         store_arg (string, delete_this_arg, this_is_output_file);
  2773.         if (this_is_output_file)
  2774.           outfiles[input_file_number] = string;
  2775.       }
  2776.     arg_going = 0;
  2777.  
  2778.     if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
  2779.       {
  2780.         int i;
  2781.         for (i = 0; i < n_switches; i++)
  2782.           if (!strcmp (switches[i].part1, "pipe"))
  2783.         break;
  2784.  
  2785.         /* A `|' before the newline means use a pipe here,
  2786.            but only if -pipe was specified.
  2787.            Otherwise, execute now and don't pass the `|' as an arg.  */
  2788.         if (i < n_switches)
  2789.           {
  2790.         input_from_pipe = 1;
  2791.         switches[i].valid = 1;
  2792.         break;
  2793.           }
  2794.         else
  2795.           argbuf_index--;
  2796.       }
  2797.  
  2798.     if (argbuf_index > 0)
  2799.       {
  2800.         value = execute ();
  2801.         if (value)
  2802.           return value;
  2803.       }
  2804.     /* Reinitialize for a new command, and for a new argument.  */
  2805.     clear_args ();
  2806.     arg_going = 0;
  2807.     delete_this_arg = 0;
  2808.     this_is_output_file = 0;
  2809.     this_is_library_file = 0;
  2810.     input_from_pipe = 0;
  2811.     break;
  2812.  
  2813.       case '|':
  2814.     /* End any pending argument.  */
  2815.     if (arg_going)
  2816.       {
  2817.         obstack_1grow (&obstack, 0);
  2818.         string = obstack_finish (&obstack);
  2819.         if (this_is_library_file)
  2820.           string = find_file (string);
  2821.         store_arg (string, delete_this_arg, this_is_output_file);
  2822.         if (this_is_output_file)
  2823.           outfiles[input_file_number] = string;
  2824.       }
  2825.  
  2826.     /* Use pipe */
  2827.     obstack_1grow (&obstack, c);
  2828.     arg_going = 1;
  2829.     break;
  2830.  
  2831.       case '\t':
  2832.       case ' ':
  2833.     /* Space or tab ends an argument if one is pending.  */
  2834.     if (arg_going)
  2835.       {
  2836.         obstack_1grow (&obstack, 0);
  2837.         string = obstack_finish (&obstack);
  2838.         if (this_is_library_file)
  2839.           string = find_file (string);
  2840.         store_arg (string, delete_this_arg, this_is_output_file);
  2841.         if (this_is_output_file)
  2842.           outfiles[input_file_number] = string;
  2843.       }
  2844.     /* Reinitialize for a new argument.  */
  2845.     arg_going = 0;
  2846.     delete_this_arg = 0;
  2847.     this_is_output_file = 0;
  2848.     this_is_library_file = 0;
  2849.     break;
  2850.  
  2851.       case '%':
  2852.     switch (c = *p++)
  2853.       {
  2854.       case 0:
  2855.         fatal ("Invalid specification!  Bug in cc.");
  2856.  
  2857.       case 'b':
  2858.         obstack_grow (&obstack, input_basename, basename_length);
  2859.         arg_going = 1;
  2860.         break;
  2861.  
  2862.       case 'd':
  2863.         delete_this_arg = 2;
  2864.         break;
  2865.  
  2866.       /* Dump out the directories specified with LIBRARY_PATH,
  2867.          followed by the absolute directories
  2868.          that we search for startfiles.  */
  2869.       case 'D':
  2870.         {
  2871.           struct prefix_list *pl = startfile_prefix.plist;
  2872.           int bufsize = 100;
  2873.           char *buffer = (char *) xmalloc (bufsize);
  2874.           int idx;
  2875.  
  2876.           for (; pl; pl = pl->next)
  2877.         {
  2878. #ifdef RELATIVE_PREFIX_NOT_LINKDIR
  2879.           /* Used on systems which record the specified -L dirs
  2880.              and use them to search for dynamic linking.  */
  2881.           /* Relative directories always come from -B,
  2882.              and it is better not to use them for searching
  2883.              at run time.  In particular, stage1 loses  */
  2884.           if (pl->prefix[0] != '/')
  2885.             continue;
  2886. #endif
  2887.           if (machine_suffix)
  2888.             {
  2889.               if (is_directory (pl->prefix, machine_suffix, 1))
  2890.             {
  2891.               do_spec_1 ("-L", 0, NULL_PTR);
  2892. #ifdef SPACE_AFTER_L_OPTION
  2893.               do_spec_1 (" ", 0, NULL_PTR);
  2894. #endif
  2895.               do_spec_1 (pl->prefix, 1, NULL_PTR);
  2896.               /* Remove slash from machine_suffix.  */
  2897.               if (strlen (machine_suffix) >= bufsize)
  2898.                 bufsize = strlen (machine_suffix) * 2 + 1;
  2899.               buffer = (char *) xrealloc (buffer, bufsize);
  2900.               strcpy (buffer, machine_suffix);
  2901.               idx = strlen (buffer);
  2902.               if (buffer[idx - 1] == '/')
  2903.                 buffer[idx - 1] = 0;
  2904.               do_spec_1 (buffer, 1, NULL_PTR);
  2905.               /* Make this a separate argument.  */
  2906.               do_spec_1 (" ", 0, NULL_PTR);
  2907.             }
  2908.             }
  2909.           if (!pl->require_machine_suffix)
  2910.             {
  2911.               if (is_directory (pl->prefix, "", 1))
  2912.             {
  2913.               do_spec_1 ("-L", 0, NULL_PTR);
  2914. #ifdef SPACE_AFTER_L_OPTION
  2915.               do_spec_1 (" ", 0, NULL_PTR);
  2916. #endif
  2917.               /* Remove slash from pl->prefix.  */
  2918.               if (strlen (pl->prefix) >= bufsize)
  2919.                 bufsize = strlen (pl->prefix) * 2 + 1;
  2920.               buffer = (char *) xrealloc (buffer, bufsize);
  2921.               strcpy (buffer, pl->prefix);
  2922.               idx = strlen (buffer);
  2923.               if (buffer[idx - 1] == '/')
  2924.                 buffer[idx - 1] = 0;
  2925.               do_spec_1 (buffer, 1, NULL_PTR);
  2926.               /* Make this a separate argument.  */
  2927.               do_spec_1 (" ", 0, NULL_PTR);
  2928.             }
  2929.             }
  2930.         }
  2931.           free (buffer);
  2932.         }
  2933.         break;
  2934.  
  2935.       case 'e':
  2936.         /* {...:%efoo} means report an error with `foo' as error message
  2937.            and don't execute any more commands for this file.  */
  2938.         {
  2939.           char *q = p;
  2940.           char *buf;
  2941.           while (*p != 0 && *p != '\n') p++;
  2942.           buf = (char *) alloca (p - q + 1);
  2943.           strncpy (buf, q, p - q);
  2944.           buf[p - q] = 0;
  2945.           error ("%s", buf);
  2946.           return -1;
  2947.         }
  2948.         break;
  2949.  
  2950.       case 'g':
  2951.       case 'u':
  2952.       case 'U':
  2953.         if (save_temps_flag)
  2954.           obstack_grow (&obstack, input_basename, basename_length);
  2955.         else
  2956.           {
  2957. #ifdef MKTEMP_EACH_FILE
  2958.         /* ??? This has a problem: the total number of
  2959.            values mktemp can return is limited.
  2960.            That matters for the names of object files.
  2961.            In 2.4, do something about that.  */
  2962.         struct temp_name *t;
  2963.         char *suffix = p;
  2964.         while (*p == '.' || isalpha (*p))
  2965.           p++;
  2966.  
  2967.         /* See if we already have an association of %g/%u/%U and
  2968.            suffix.  */
  2969.         for (t = temp_names; t; t = t->next)
  2970.           if (t->length == p - suffix
  2971.               && strncmp (t->suffix, suffix, p - suffix) == 0
  2972.               && t->unique == (c != 'g'))
  2973.             break;
  2974.  
  2975.         /* Make a new association if needed.  %u requires one.  */
  2976.         if (t == 0 || c == 'u')
  2977.           {
  2978.             if (t == 0)
  2979.               {
  2980.             t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
  2981.             t->next = temp_names;
  2982.             temp_names = t;
  2983.               }
  2984.             t->length = p - suffix;
  2985.             t->suffix = save_string (suffix, p - suffix);
  2986.             t->unique = (c != 'g');
  2987.             choose_temp_base ();
  2988.             t->filename = temp_filename;
  2989.             t->filename_length = temp_filename_length;
  2990.           }
  2991.  
  2992.         obstack_grow (&obstack, t->filename, t->filename_length);
  2993.         delete_this_arg = 1;
  2994. #else
  2995.         obstack_grow (&obstack, temp_filename, temp_filename_length);
  2996.         if (c == 'u' || c == 'U')
  2997.           {
  2998.             static int unique;
  2999.             char buff[9];
  3000.             if (c == 'u')
  3001.               unique++;
  3002.             sprintf (buff, "%d", unique);
  3003.             obstack_grow (&obstack, buff, strlen (buff));
  3004.           }
  3005. #endif
  3006.         delete_this_arg = 1;
  3007.           }
  3008.         arg_going = 1;
  3009.         break;
  3010.  
  3011.       case 'i':
  3012.         obstack_grow (&obstack, input_filename, input_filename_length);
  3013.         arg_going = 1;
  3014.         break;
  3015.  
  3016.       case 'I':
  3017.         if (gcc_exec_prefix)
  3018.           {
  3019.         do_spec_1 ("-iprefix", 1, NULL_PTR);
  3020.         /* Make this a separate argument.  */
  3021.         do_spec_1 (" ", 0, NULL_PTR);
  3022.         do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
  3023.         do_spec_1 (" ", 0, NULL_PTR);
  3024.           }
  3025.         break;
  3026.  
  3027.       case 'o':
  3028.         {
  3029.           register int f;
  3030.           for (f = 0; f < n_infiles; f++)
  3031.         store_arg (outfiles[f], 0, 0);
  3032.         }
  3033.         break;
  3034.  
  3035.       case 's':
  3036.         this_is_library_file = 1;
  3037.         break;
  3038.  
  3039.       case 'w':
  3040.         this_is_output_file = 1;
  3041.         break;
  3042.  
  3043.       case 'W':
  3044.         {
  3045.           int index = argbuf_index;
  3046.           /* Handle the {...} following the %W.  */
  3047.           if (*p != '{')
  3048.         abort ();
  3049.           p = handle_braces (p + 1);
  3050.           if (p == 0)
  3051.         return -1;
  3052.           /* If any args were output, mark the last one for deletion
  3053.          on failure.  */
  3054.           if (argbuf_index != index)
  3055.         record_temp_file (argbuf[argbuf_index - 1], 0, 1);
  3056.           break;
  3057.         }
  3058.  
  3059.       /* %x{OPTION} records OPTION for %X to output.  */
  3060.       case 'x':
  3061.         {
  3062.           char *p1 = p;
  3063.           char *string;
  3064.  
  3065.           /* Skip past the option value and make a copy.  */
  3066.           if (*p != '{')
  3067.         abort ();
  3068.           while (*p++ != '}')
  3069.         ;
  3070.           string = save_string (p1 + 1, p - p1 - 2);
  3071.  
  3072.           /* See if we already recorded this option.  */
  3073.           for (i = 0; i < n_linker_options; i++)
  3074.         if (! strcmp (string, linker_options[i]))
  3075.           {
  3076.             free (string);
  3077.             return 0;
  3078.           }
  3079.  
  3080.           /* This option is new; add it.  */
  3081.           n_linker_options++;
  3082.           if (!linker_options)
  3083.         linker_options
  3084.           = (char **) xmalloc (n_linker_options * sizeof (char **));
  3085.           else
  3086.         linker_options
  3087.           = (char **) xrealloc (linker_options,
  3088.                     n_linker_options * sizeof (char **));
  3089.  
  3090.           linker_options[n_linker_options - 1] = string;
  3091.         }
  3092.         break;
  3093.  
  3094.       /* Dump out the options accumulated previously using %x,
  3095.          -Xlinker and -Wl,.  */
  3096.       case 'X':
  3097.         for (i = 0; i < n_linker_options; i++)
  3098.           {
  3099.         do_spec_1 (linker_options[i], 1, NULL_PTR);
  3100.         /* Make each accumulated option a separate argument.  */
  3101.         do_spec_1 (" ", 0, NULL_PTR);
  3102.           }
  3103.         break;
  3104.  
  3105.       /* Dump out the options accumulated previously using -Wa,.  */
  3106.       case 'Y':
  3107.         for (i = 0; i < n_assembler_options; i++)
  3108.           {
  3109.         do_spec_1 (assembler_options[i], 1, NULL_PTR);
  3110.         /* Make each accumulated option a separate argument.  */
  3111.         do_spec_1 (" ", 0, NULL_PTR);
  3112.           }
  3113.         break;
  3114.  
  3115.         /* Here are digits and numbers that just process
  3116.            a certain constant string as a spec.  */
  3117.  
  3118.       case '1':
  3119.         value = do_spec_1 (cc1_spec, 0, NULL_PTR);
  3120.         if (value != 0)
  3121.           return value;
  3122.         break;
  3123.  
  3124.       case '2':
  3125.         value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
  3126.         if (value != 0)
  3127.           return value;
  3128.         break;
  3129.  
  3130.       case 'a':
  3131.         value = do_spec_1 (asm_spec, 0, NULL_PTR);
  3132.         if (value != 0)
  3133.           return value;
  3134.         break;
  3135.  
  3136.       case 'A':
  3137.         value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
  3138.         if (value != 0)
  3139.           return value;
  3140.         break;
  3141.  
  3142.       case 'c':
  3143.         value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
  3144.         if (value != 0)
  3145.           return value;
  3146.         break;
  3147.  
  3148.       case 'C':
  3149.         value = do_spec_1 (cpp_spec, 0, NULL_PTR);
  3150.         if (value != 0)
  3151.           return value;
  3152.         break;
  3153.  
  3154.       case 'E':
  3155.         value = do_spec_1 (endfile_spec, 0, NULL_PTR);
  3156.         if (value != 0)
  3157.           return value;
  3158.         break;
  3159.  
  3160.       case 'l':
  3161.         value = do_spec_1 (link_spec, 0, NULL_PTR);
  3162.         if (value != 0)
  3163.           return value;
  3164.         break;
  3165.  
  3166.       case 'L':
  3167.         value = do_spec_1 (lib_spec, 0, NULL_PTR);
  3168.         if (value != 0)
  3169.           return value;
  3170.         break;
  3171.  
  3172.       case 'p':
  3173.         {
  3174.           char *x = (char *) alloca (strlen (cpp_predefines) + 1);
  3175.           char *buf = x;
  3176.           char *y;
  3177.  
  3178.           /* Copy all of the -D options in CPP_PREDEFINES into BUF.  */
  3179.           y = cpp_predefines;
  3180.           while (*y != 0)
  3181.         {
  3182.           if (! strncmp (y, "-D", 2))
  3183.             /* Copy the whole option.  */
  3184.             while (*y && *y != ' ' && *y != '\t')
  3185.               *x++ = *y++;
  3186.           else if (*y == ' ' || *y == '\t')
  3187.             /* Copy whitespace to the result.  */
  3188.             *x++ = *y++;
  3189.           /* Don't copy other options.  */
  3190.           else
  3191.             y++;
  3192.         }
  3193.  
  3194.           *x = 0;
  3195.  
  3196.           value = do_spec_1 (buf, 0, NULL_PTR);
  3197.           if (value != 0)
  3198.         return value;
  3199.         }
  3200.         break;
  3201.  
  3202.       case 'P':
  3203.         {
  3204.           char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
  3205.           char *buf = x;
  3206.           char *y;
  3207.  
  3208.           /* Copy all of CPP_PREDEFINES into BUF,
  3209.          but put __ after every -D and at the end of each arg.  */
  3210.           y = cpp_predefines;
  3211.           while (*y != 0)
  3212.         {
  3213.           if (! strncmp (y, "-D", 2))
  3214.             {
  3215.               int flag = 0;
  3216.  
  3217.               *x++ = *y++;
  3218.               *x++ = *y++;
  3219.  
  3220.               if (strncmp (y, "__", 2))
  3221.                 {
  3222.               /* Stick __ at front of macro name.  */
  3223.               *x++ = '_';
  3224.               *x++ = '_';
  3225.               /* Arrange to stick __ at the end as well.  */
  3226.               flag = 1;
  3227.             }
  3228.  
  3229.               /* Copy the macro name.  */
  3230.               while (*y && *y != '=' && *y != ' ' && *y != '\t')
  3231.             *x++ = *y++;
  3232.  
  3233.               if (flag)
  3234.                 {
  3235.               *x++ = '_';
  3236.               *x++ = '_';
  3237.             }
  3238.  
  3239.               /* Copy the value given, if any.  */
  3240.               while (*y && *y != ' ' && *y != '\t')
  3241.             *x++ = *y++;
  3242.             }
  3243.           else if (*y == ' ' || *y == '\t')
  3244.             /* Copy whitespace to the result.  */
  3245.             *x++ = *y++;
  3246.           /* Don't copy -A options  */
  3247.           else
  3248.             y++;
  3249.         }
  3250.           *x++ = ' ';
  3251.  
  3252.           /* Copy all of CPP_PREDEFINES into BUF,
  3253.          but put __ after every -D.  */
  3254.           y = cpp_predefines;
  3255.           while (*y != 0)
  3256.         {
  3257.           if (! strncmp (y, "-D", 2))
  3258.             {
  3259.               *x++ = *y++;
  3260.               *x++ = *y++;
  3261.  
  3262.               if (strncmp (y, "__", 2))
  3263.                 {
  3264.               /* Stick __ at front of macro name.  */
  3265.               *x++ = '_';
  3266.               *x++ = '_';
  3267.             }
  3268.  
  3269.               /* Copy the macro name.  */
  3270.               while (*y && *y != '=' && *y != ' ' && *y != '\t')
  3271.             *x++ = *y++;
  3272.  
  3273.               /* Copy the value given, if any.  */
  3274.               while (*y && *y != ' ' && *y != '\t')
  3275.             *x++ = *y++;
  3276.             }
  3277.           else if (*y == ' ' || *y == '\t')
  3278.             /* Copy whitespace to the result.  */
  3279.             *x++ = *y++;
  3280.           /* Don't copy -A options  */
  3281.           else
  3282.             y++;
  3283.         }
  3284.           *x++ = ' ';
  3285.  
  3286.           /* Copy all of the -A options in CPP_PREDEFINES into BUF.  */
  3287.           y = cpp_predefines;
  3288.           while (*y != 0)
  3289.         {
  3290.           if (! strncmp (y, "-A", 2))
  3291.             /* Copy the whole option.  */
  3292.             while (*y && *y != ' ' && *y != '\t')
  3293.               *x++ = *y++;
  3294.           else if (*y == ' ' || *y == '\t')
  3295.             /* Copy whitespace to the result.  */
  3296.             *x++ = *y++;
  3297.           /* Don't copy other options.  */
  3298.           else
  3299.             y++;
  3300.         }
  3301.  
  3302.           *x = 0;
  3303.  
  3304.           value = do_spec_1 (buf, 0, NULL_PTR);
  3305.           if (value != 0)
  3306.         return value;
  3307.         }
  3308.         break;
  3309.  
  3310.       case 'S':
  3311.         value = do_spec_1 (startfile_spec, 0, NULL_PTR);
  3312.         if (value != 0)
  3313.           return value;
  3314.         break;
  3315.  
  3316.         /* Here we define characters other than letters and digits.  */
  3317.  
  3318.       case '{':
  3319.         p = handle_braces (p);
  3320.         if (p == 0)
  3321.           return -1;
  3322.         break;
  3323.  
  3324.       case '%':
  3325.         obstack_1grow (&obstack, '%');
  3326.         break;
  3327.  
  3328.       case '*':
  3329.         do_spec_1 (soft_matched_part, 1, NULL_PTR);
  3330.         do_spec_1 (" ", 0, NULL_PTR);
  3331.         break;
  3332.  
  3333.         /* Process a string found as the value of a spec given by name.
  3334.            This feature allows individual machine descriptions
  3335.            to add and use their own specs.
  3336.            %[...] modifies -D options the way %P does;
  3337.            %(...) uses the spec unmodified.  */
  3338.       case '(':
  3339.       case '[':
  3340.         {
  3341.           char *name = p;
  3342.           struct spec_list *sl;
  3343.           int len;
  3344.  
  3345.           /* The string after the S/P is the name of a spec that is to be
  3346.          processed. */
  3347.           while (*p && *p != ')' && *p != ']')
  3348.         p++;
  3349.  
  3350.           /* See if it's in the list */
  3351.           for (len = p - name, sl = specs; sl; sl = sl->next)
  3352.         if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
  3353.           {
  3354.             name = sl->spec;
  3355.             break;
  3356.           }
  3357.  
  3358.           if (sl)
  3359.         {
  3360.           if (c == '(')
  3361.             {
  3362.               value = do_spec_1 (name, 0, NULL_PTR);
  3363.               if (value != 0)
  3364.             return value;
  3365.             }
  3366.           else
  3367.             {
  3368.               char *x = (char *) alloca (strlen (name) * 2 + 1);
  3369.               char *buf = x;
  3370.               char *y = name;
  3371.  
  3372.               /* Copy all of NAME into BUF, but put __ after
  3373.              every -D and at the end of each arg,  */
  3374.               while (1)
  3375.             {
  3376.               if (! strncmp (y, "-D", 2))
  3377.                 {
  3378.                   *x++ = '-';
  3379.                   *x++ = 'D';
  3380.                   *x++ = '_';
  3381.                   *x++ = '_';
  3382.                   y += 2;
  3383.                 }
  3384.               else if (*y == ' ' || *y == 0)
  3385.                 {
  3386.                   *x++ = '_';
  3387.                   *x++ = '_';
  3388.                   if (*y == 0)
  3389.                 break;
  3390.                   else
  3391.                 *x++ = *y++;
  3392.                 }
  3393.               else
  3394.                 *x++ = *y++;
  3395.             }
  3396.               *x = 0;
  3397.  
  3398.               value = do_spec_1 (buf, 0, NULL_PTR);
  3399.               if (value != 0)
  3400.             return value;
  3401.             }
  3402.         }
  3403.  
  3404.           /* Discard the closing paren or bracket.  */
  3405.           if (*p)
  3406.         p++;
  3407.         }
  3408.         break;
  3409.  
  3410.       case 'v':
  3411.         {
  3412.           int c1 = *p++;  /* Select first or second version number.  */
  3413.           char *p = spec_version;
  3414.           char *q, *copy;
  3415.           /* If desired, advance to second version number.  */
  3416.           if (c1 == '2')
  3417.         {
  3418.           /* Set P after the first period.  */
  3419.           while (*p != '.') p++;
  3420.           p++;
  3421.         }
  3422.           /* Set Q at the next period or at the end.  */
  3423.           q = p;
  3424.           while (*q != '.' && *q != 0) q++;
  3425.           /* Put that part into the command.  */
  3426.           obstack_grow (&obstack, p, q - p);
  3427.           arg_going = 1;
  3428.         }
  3429.         break;
  3430.  
  3431.       case '|':
  3432.         if (input_from_pipe)
  3433.           do_spec_1 ("-", 0, NULL_PTR);
  3434.         break;
  3435.  
  3436.       default:
  3437.         abort ();
  3438.       }
  3439.     break;
  3440.  
  3441.       case '\\':
  3442.     /* Backslash: treat next character as ordinary.  */
  3443.     c = *p++;
  3444.  
  3445.     /* fall through */
  3446.       default:
  3447.     /* Ordinary character: put it into the current argument.  */
  3448.     obstack_1grow (&obstack, c);
  3449.     arg_going = 1;
  3450.       }
  3451.  
  3452.   return 0;        /* End of string */
  3453. }
  3454.  
  3455. /* Return 0 if we call do_spec_1 and that returns -1.  */
  3456.  
  3457. static char *
  3458. handle_braces (p)
  3459.      register char *p;
  3460. {
  3461.   register char *q;
  3462.   char *filter;
  3463.   int pipe = 0;
  3464.   int negate = 0;
  3465.   int suffix = 0;
  3466.  
  3467.   if (*p == '|')
  3468.     /* A `|' after the open-brace means,
  3469.        if the test fails, output a single minus sign rather than nothing.
  3470.        This is used in %{|!pipe:...}.  */
  3471.     pipe = 1, ++p;
  3472.  
  3473.   if (*p == '!')
  3474.     /* A `!' after the open-brace negates the condition:
  3475.        succeed if the specified switch is not present.  */
  3476.     negate = 1, ++p;
  3477.  
  3478.   if (*p == '.')
  3479.     /* A `.' after the open-brace means test against the current suffix.  */
  3480.     {
  3481.       if (pipe)
  3482.     abort ();
  3483.  
  3484.       suffix = 1;
  3485.       ++p;
  3486.     }
  3487.  
  3488.   filter = p;
  3489.   while (*p != ':' && *p != '}') p++;
  3490.   if (*p != '}')
  3491.     {
  3492.       register int count = 1;
  3493.       q = p + 1;
  3494.       while (count > 0)
  3495.     {
  3496.       if (*q == '{')
  3497.         count++;
  3498.       else if (*q == '}')
  3499.         count--;
  3500.       else if (*q == 0)
  3501.         abort ();
  3502.       q++;
  3503.     }
  3504.     }
  3505.   else
  3506.     q = p + 1;
  3507.  
  3508.   if (suffix)
  3509.     {
  3510.       int found = (input_suffix != 0
  3511.            && strlen (input_suffix) == p - filter
  3512.            && strncmp (input_suffix, filter, p - filter) == 0);
  3513.  
  3514.       if (p[0] == '}')
  3515.     abort ();
  3516.  
  3517.       if (negate != found
  3518.       && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
  3519.     return 0;
  3520.  
  3521.       return q;
  3522.     }
  3523.   else if (p[-1] == '*' && p[0] == '}')
  3524.     {
  3525.       /* Substitute all matching switches as separate args.  */
  3526.       register int i;
  3527.       --p;
  3528.       for (i = 0; i < n_switches; i++)
  3529.     if (!strncmp (switches[i].part1, filter, p - filter))
  3530.       give_switch (i, 0);
  3531.     }
  3532.   else
  3533.     {
  3534.       /* Test for presence of the specified switch.  */
  3535.       register int i;
  3536.       int present = 0;
  3537.  
  3538.       /* If name specified ends in *, as in {x*:...},
  3539.      check for %* and handle that case.  */
  3540.       if (p[-1] == '*' && !negate)
  3541.     {
  3542.       int substitution;
  3543.       char *r = p;
  3544.  
  3545.       /* First see whether we have %*.  */
  3546.       substitution = 0;
  3547.       while (r < q)
  3548.         {
  3549.           if (*r == '%' && r[1] == '*')
  3550.         substitution = 1;
  3551.           r++;
  3552.         }
  3553.       /* If we do, handle that case.  */
  3554.       if (substitution)
  3555.         {
  3556.           /* Substitute all matching switches as separate args.
  3557.          But do this by substituting for %*
  3558.          in the text that follows the colon.  */
  3559.  
  3560.           unsigned hard_match_len = p - filter - 1;
  3561.           char *string = save_string (p + 1, q - p - 2);
  3562.  
  3563.           for (i = 0; i < n_switches; i++)
  3564.         if (!strncmp (switches[i].part1, filter, hard_match_len))
  3565.           {
  3566.             do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
  3567.             /* Pass any arguments this switch has.  */
  3568.             give_switch (i, 1);
  3569.           }
  3570.  
  3571.           return q;
  3572.         }
  3573.     }
  3574.  
  3575.       /* If name specified ends in *, as in {x*:...},
  3576.      check for presence of any switch name starting with x.  */
  3577.       if (p[-1] == '*')
  3578.     {
  3579.       for (i = 0; i < n_switches; i++)
  3580.         {
  3581.           unsigned hard_match_len = p - filter - 1;
  3582.  
  3583.           if (!strncmp (switches[i].part1, filter, hard_match_len))
  3584.         {
  3585.           switches[i].valid = 1;
  3586.           present = 1;
  3587.         }
  3588.         }
  3589.     }
  3590.       /* Otherwise, check for presence of exact name specified.  */
  3591.       else
  3592.     {
  3593.       for (i = 0; i < n_switches; i++)
  3594.         {
  3595.           if (!strncmp (switches[i].part1, filter, p - filter)
  3596.           && switches[i].part1[p - filter] == 0)
  3597.         {
  3598.           switches[i].valid = 1;
  3599.           present = 1;
  3600.           break;
  3601.         }
  3602.         }
  3603.     }
  3604.  
  3605.       /* If it is as desired (present for %{s...}, absent for %{-s...})
  3606.      then substitute either the switch or the specified
  3607.      conditional text.  */
  3608.       if (present != negate)
  3609.     {
  3610.       if (*p == '}')
  3611.         {
  3612.           give_switch (i, 0);
  3613.         }
  3614.       else
  3615.         {
  3616.           if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
  3617.         return 0;
  3618.         }
  3619.     }
  3620.       else if (pipe)
  3621.     {
  3622.       /* Here if a %{|...} conditional fails: output a minus sign,
  3623.          which means "standard output" or "standard input".  */
  3624.       do_spec_1 ("-", 0, NULL_PTR);
  3625.     }
  3626.     }
  3627.  
  3628.   return q;
  3629. }
  3630.  
  3631. /* Pass a switch to the current accumulating command
  3632.    in the same form that we received it.
  3633.    SWITCHNUM identifies the switch; it is an index into
  3634.    the vector of switches gcc received, which is `switches'.
  3635.    This cannot fail since it never finishes a command line.
  3636.  
  3637.    If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.  */
  3638.  
  3639. static void
  3640. give_switch (switchnum, omit_first_word)
  3641.      int switchnum;
  3642.      int omit_first_word;
  3643. {
  3644.   if (!omit_first_word)
  3645.     {
  3646.       do_spec_1 ("-", 0, NULL_PTR);
  3647.       do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
  3648.     }
  3649.   do_spec_1 (" ", 0, NULL_PTR);
  3650.   if (switches[switchnum].args != 0)
  3651.     {
  3652.       char **p;
  3653.       for (p = switches[switchnum].args; *p; p++)
  3654.     {
  3655.       do_spec_1 (*p, 1, NULL_PTR);
  3656.       do_spec_1 (" ", 0, NULL_PTR);
  3657.     }
  3658.     }
  3659.   switches[switchnum].valid = 1;
  3660. }
  3661.  
  3662. /* Search for a file named NAME trying various prefixes including the
  3663.    user's -B prefix and some standard ones.
  3664.    Return the absolute file name found.  If nothing is found, return NAME.  */
  3665.  
  3666. static char *
  3667. find_file (name)
  3668.      char *name;
  3669. {
  3670.   char *newname;
  3671.  
  3672.   newname = find_a_file (&startfile_prefix, name, R_OK);
  3673.   return newname ? newname : name;
  3674. }
  3675.  
  3676. /* Determine whether a directory exists.  If LINKER, return 0 for
  3677.    certain fixed names not needed by the linker.  If not LINKER, it is
  3678.    only important to return 0 if the host machine has a small ARG_MAX
  3679.    limit.  */
  3680.  
  3681. static int
  3682. is_directory (path1, path2, linker)
  3683.      char *path1;
  3684.      char *path2;
  3685.      int linker;
  3686. {
  3687.   int len1 = strlen (path1);
  3688.   int len2 = strlen (path2);
  3689.   char *path = (char *) alloca (3 + len1 + len2);
  3690.   char *cp;
  3691.   struct stat st;
  3692.  
  3693. #ifndef SMALL_ARG_MAX
  3694.   if (! linker)
  3695.     return 1;
  3696. #endif
  3697.  
  3698.   /* Construct the path from the two parts.  Ensure the string ends with "/.".
  3699.      The resulting path will be a directory even if the given path is a
  3700.      symbolic link.  */
  3701.   bcopy (path1, path, len1);
  3702.   bcopy (path2, path + len1, len2);
  3703.   cp = path + len1 + len2;
  3704.   if (cp[-1] != '/')
  3705.     *cp++ = '/';
  3706.   *cp++ = '.';
  3707.   *cp = '\0';
  3708.  
  3709.   /* Exclude directories that the linker is known to search.  */
  3710.   if (linker
  3711.       && ((cp - path == 6 && strcmp (path, "/lib/.") == 0)
  3712.       || (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0)))
  3713.     return 0;
  3714.  
  3715.   return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
  3716. }
  3717.  
  3718. /* On fatal signals, delete all the temporary files.  */
  3719.  
  3720. static void
  3721. fatal_error (signum)
  3722.      int signum;
  3723. {
  3724.   signal (signum, SIG_DFL);
  3725.   delete_failure_queue ();
  3726.   delete_temp_files ();
  3727.   /* Get the same signal again, this time not handled,
  3728.      so its normal effect occurs.  */
  3729.   kill (getpid (), signum);
  3730. }
  3731.  
  3732. int
  3733. main (argc, argv)
  3734.      int argc;
  3735.      char **argv;
  3736. {
  3737.   register int i;
  3738.   int j;
  3739.   int value;
  3740.   int linker_was_run = 0;
  3741.   char *explicit_link_files;
  3742.   char *specs_file;
  3743.   char *p;
  3744.  
  3745.   p = argv[0] + strlen (argv[0]);
  3746.   while (p != argv[0] && p[-1] != '/') --p;
  3747.   programname = p;
  3748.  
  3749.   if (signal (SIGINT, SIG_IGN) != SIG_IGN)
  3750.     signal (SIGINT, fatal_error);
  3751. #ifdef SIGHUP
  3752.   if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
  3753.     signal (SIGHUP, fatal_error);
  3754. #endif
  3755.   if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
  3756.     signal (SIGTERM, fatal_error);
  3757. #ifdef SIGPIPE
  3758.   if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
  3759.     signal (SIGPIPE, fatal_error);
  3760. #endif
  3761.  
  3762.   argbuf_length = 10;
  3763.   argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
  3764.  
  3765.   obstack_init (&obstack);
  3766.  
  3767.   /* Set up to remember the pathname of gcc and any options
  3768.      needed for collect.  We use argv[0] instead of programname because
  3769.      we need the complete pathname.  */
  3770.   obstack_init (&collect_obstack);
  3771.   obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
  3772.   obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
  3773.   putenv (obstack_finish (&collect_obstack));
  3774.  
  3775.   /* Choose directory for temp files.  */
  3776.  
  3777.   choose_temp_base ();
  3778.  
  3779.   /* Make a table of what switches there are (switches, n_switches).
  3780.      Make a table of specified input files (infiles, n_infiles).
  3781.      Decode switches that are handled locally.  */
  3782.  
  3783.   process_command (argc, argv);
  3784.  
  3785.   /* Initialize the vector of specs to just the default.
  3786.      This means one element containing 0s, as a terminator.  */
  3787.  
  3788.   compilers = (struct compiler *) xmalloc (sizeof default_compilers);
  3789.   bcopy (default_compilers, compilers, sizeof default_compilers);
  3790.   n_compilers = n_default_compilers;
  3791.  
  3792.   /* Read specs from a file if there is one.  */
  3793.  
  3794.   machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", ""));
  3795.   just_machine_suffix = concat (spec_machine, "/", "");
  3796.  
  3797.   specs_file = find_a_file (&startfile_prefix, "specs", R_OK);
  3798.   /* Read the specs file unless it is a default one.  */
  3799.   if (specs_file != 0 && strcmp (specs_file, "specs"))
  3800.     read_specs (specs_file);
  3801.  
  3802.   /* If not cross-compiling, look for startfiles in the standard places.  */
  3803.   /* The fact that these are done here, after reading the specs file,
  3804.      means that it cannot be found in these directories.
  3805.      But that's okay.  It should never be there anyway.  */
  3806.   if (!cross_compile)
  3807.     {
  3808. #ifdef MD_EXEC_PREFIX
  3809.       add_prefix (&exec_prefix, md_exec_prefix, 0, 0, NULL_PTR);
  3810.       add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, NULL_PTR);
  3811. #endif
  3812.  
  3813. #ifdef MD_STARTFILE_PREFIX
  3814.       add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, NULL_PTR);
  3815. #endif
  3816.  
  3817. #ifdef MD_STARTFILE_PREFIX_1
  3818.       add_prefix (&startfile_prefix, md_startfile_prefix_1, 0, 0, NULL_PTR);
  3819. #endif
  3820.  
  3821.       /* If standard_startfile_prefix is relative, base it on
  3822.      standard_exec_prefix.  This lets us move the installed tree
  3823.      as a unit.  If GCC_EXEC_PREFIX is defined, base
  3824.      standard_startfile_prefix on that as well.  */
  3825.       if (*standard_startfile_prefix == '/')
  3826.     add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0,
  3827.             NULL_PTR);
  3828.       else
  3829.     {
  3830.       if (gcc_exec_prefix)
  3831.         add_prefix (&startfile_prefix,
  3832.             concat (gcc_exec_prefix,
  3833.                 standard_startfile_prefix,
  3834.                 ""),
  3835.             0, 0, NULL_PTR);
  3836.       add_prefix (&startfile_prefix,
  3837.               concat (standard_exec_prefix,
  3838.                   machine_suffix,
  3839.                   standard_startfile_prefix),
  3840.               0, 0, NULL_PTR);
  3841.     }               
  3842.  
  3843.       add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0,
  3844.           NULL_PTR);
  3845.       add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0,
  3846.           NULL_PTR);
  3847. #if 0 /* Can cause surprises, and one can use -B./ instead.  */
  3848.       add_prefix (&startfile_prefix, "./", 0, 1, NULL_PTR);
  3849. #endif
  3850.     }
  3851.  
  3852.   /* Now we have the specs.
  3853.      Set the `valid' bits for switches that match anything in any spec.  */
  3854.  
  3855.   validate_all_switches ();
  3856.  
  3857.   /* Warn about any switches that no pass was interested in.  */
  3858.  
  3859.   for (i = 0; i < n_switches; i++)
  3860.     if (! switches[i].valid)
  3861.       error ("unrecognized option `-%s'", switches[i].part1);
  3862.  
  3863.   if (print_libgcc_file_name)
  3864.     {
  3865.       printf ("%s\n", find_file ("libgcc.a"));
  3866.       exit (0);
  3867.     }
  3868.  
  3869.   /* Obey some of the options.  */
  3870.  
  3871.   if (verbose_flag)
  3872.     {
  3873.       fprintf (stderr, "gcc version %s\n", version_string);
  3874.       if (n_infiles == 0)
  3875.     exit (0);
  3876.     }
  3877.  
  3878.   if (n_infiles == 0)
  3879.     fatal ("No input files");
  3880.  
  3881.   /* Make a place to record the compiler output file names
  3882.      that correspond to the input files.  */
  3883.  
  3884.   outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
  3885.   bzero (outfiles, n_infiles * sizeof (char *));
  3886.  
  3887.   /* Record which files were specified explicitly as link input.  */
  3888.  
  3889.   explicit_link_files = xmalloc (n_infiles);
  3890.   bzero (explicit_link_files, n_infiles);
  3891.  
  3892.   for (i = 0; i < n_infiles; i++)
  3893.     {
  3894.       register struct compiler *cp = 0;
  3895.       int this_file_error = 0;
  3896.  
  3897.       /* Tell do_spec what to substitute for %i.  */
  3898.  
  3899.       input_filename = infiles[i].name;
  3900.       input_filename_length = strlen (input_filename);
  3901.       input_file_number = i;
  3902.  
  3903.       /* Use the same thing in %o, unless cp->spec says otherwise.  */
  3904.  
  3905.       outfiles[i] = input_filename;
  3906.  
  3907.       /* Figure out which compiler from the file's suffix.  */
  3908.  
  3909.       cp = lookup_compiler (infiles[i].name, input_filename_length,
  3910.                 infiles[i].language);
  3911.  
  3912.       if (cp)
  3913.     {
  3914.       /* Ok, we found an applicable compiler.  Run its spec.  */
  3915.       /* First say how much of input_filename to substitute for %b  */
  3916.       register char *p;
  3917.       int len;
  3918.  
  3919. #ifdef FILE_NAME_NONDIRECTORY
  3920.       input_basename = FILE_NAME_NONDIRECTORY (input_filename);
  3921. #else
  3922.       input_basename = input_filename;
  3923.       for (p = input_filename; *p; p++)
  3924.         if (*p == '/')
  3925.           input_basename = p + 1;
  3926. #endif
  3927.  
  3928.       /* Find a suffix starting with the last period,
  3929.          and set basename_length to exclude that suffix.  */
  3930.       basename_length = strlen (input_basename);
  3931.       p = input_basename + basename_length;
  3932.       while (p != input_basename && *p != '.') --p;
  3933.       if (*p == '.' && p != input_basename)
  3934.         {
  3935.           basename_length = p - input_basename;
  3936.           input_suffix = p + 1;
  3937.         }
  3938.       else
  3939.         input_suffix = "";
  3940.  
  3941.       len = 0;
  3942.       for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
  3943.         if (cp->spec[j])
  3944.           len += strlen (cp->spec[j]);
  3945.  
  3946.       p = (char *) xmalloc (len + 1);
  3947.  
  3948.       len = 0;
  3949.       for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
  3950.         if (cp->spec[j])
  3951.           {
  3952.         strcpy (p + len, cp->spec[j]);
  3953.         len += strlen (cp->spec[j]);
  3954.           }
  3955.  
  3956.       value = do_spec (p);
  3957.       free (p);
  3958.       if (value < 0)
  3959.         this_file_error = 1;
  3960.     }
  3961.  
  3962.       /* If this file's name does not contain a recognized suffix,
  3963.      record it as explicit linker input.  */
  3964.  
  3965.       else
  3966.     explicit_link_files[i] = 1;
  3967.  
  3968.       /* Clear the delete-on-failure queue, deleting the files in it
  3969.      if this compilation failed.  */
  3970.  
  3971.       if (this_file_error)
  3972.     {
  3973.       delete_failure_queue ();
  3974.       error_count++;
  3975.     }
  3976.       /* If this compilation succeeded, don't delete those files later.  */
  3977.       clear_failure_queue ();
  3978.     }
  3979.  
  3980.   /* Run ld to link all the compiler output files.  */
  3981.  
  3982.   if (error_count == 0)
  3983.     {
  3984.       int tmp = execution_count;
  3985.       int i;
  3986.       int first_time;
  3987.  
  3988.       /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
  3989.      for collect.  */
  3990.       putenv_from_prefixes (&exec_prefix, "COMPILER_PATH=");
  3991.       putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH=");
  3992.  
  3993.       /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
  3994.      the compiler.  */
  3995.       obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
  3996.             sizeof ("COLLECT_GCC_OPTIONS=")-1);
  3997.  
  3998.       first_time = TRUE;
  3999.       for (i = 0; i < n_switches; i++)
  4000.     {
  4001.       char **args;
  4002.       if (!first_time)
  4003.         obstack_grow (&collect_obstack, " ", 1);
  4004.  
  4005.       first_time = FALSE;
  4006.       obstack_grow (&collect_obstack, "-", 1);
  4007.       obstack_grow (&collect_obstack, switches[i].part1,
  4008.             strlen (switches[i].part1));
  4009.  
  4010.       for (args = switches[i].args; args && *args; args++)
  4011.         {
  4012.           obstack_grow (&collect_obstack, " ", 1);
  4013.           obstack_grow (&collect_obstack, *args, strlen (*args));
  4014.         }
  4015.     }
  4016.       obstack_grow (&collect_obstack, "\0", 1);
  4017.       putenv (obstack_finish (&collect_obstack));
  4018.  
  4019.       value = do_spec (link_command_spec);
  4020.       if (value < 0)
  4021.     error_count = 1;
  4022.       linker_was_run = (tmp != execution_count);
  4023.     }
  4024.  
  4025.   /* Warn if a -B option was specified but the prefix was never used.  */
  4026.   unused_prefix_warnings (&exec_prefix);
  4027.   unused_prefix_warnings (&startfile_prefix);
  4028.  
  4029.   /* If options said don't run linker,
  4030.      complain about input files to be given to the linker.  */
  4031.  
  4032.   if (! linker_was_run && error_count == 0)
  4033.     for (i = 0; i < n_infiles; i++)
  4034.       if (explicit_link_files[i])
  4035.     error ("%s: linker input file unused since linking not done",
  4036.            outfiles[i]);
  4037.  
  4038.   /* Delete some or all of the temporary files we made.  */
  4039.  
  4040.   if (error_count)
  4041.     delete_failure_queue ();
  4042.   delete_temp_files ();
  4043.  
  4044.   exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
  4045.   /* NOTREACHED */
  4046.   return 0;
  4047. }
  4048.  
  4049. /* Find the proper compilation spec for the file name NAME,
  4050.    whose length is LENGTH.  LANGUAGE is the specified language,
  4051.    or 0 if none specified.  */
  4052.  
  4053. static struct compiler *
  4054. lookup_compiler (name, length, language)
  4055.      char *name;
  4056.      int length;
  4057.      char *language;
  4058. {
  4059.   struct compiler *cp;
  4060.  
  4061.   /* Look for the language, if one is spec'd.  */
  4062.   if (language != 0)
  4063.     {
  4064.       for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  4065.     {
  4066.       if (language != 0)
  4067.         {
  4068.           if (cp->suffix[0] == '@'
  4069.           && !strcmp (cp->suffix + 1, language))
  4070.         return cp;
  4071.         }
  4072.     }
  4073.       error ("language %s not recognized", language);
  4074.     }
  4075.  
  4076.   /* Look for a suffix.  */
  4077.   for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  4078.     {
  4079.       if (/* The suffix `-' matches only the file name `-'.  */
  4080.       (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
  4081.       ||
  4082.       (strlen (cp->suffix) < length
  4083.        /* See if the suffix matches the end of NAME.  */
  4084.        && !strcmp (cp->suffix,
  4085.                name + length - strlen (cp->suffix))))
  4086.     {
  4087.       if (cp->spec[0][0] == '@')
  4088.         {
  4089.           struct compiler *new;
  4090.           /* An alias entry maps a suffix to a language.
  4091.          Search for the language; pass 0 for NAME and LENGTH
  4092.          to avoid infinite recursion if language not found.
  4093.          Construct the new compiler spec.  */
  4094.           language = cp->spec[0] + 1;
  4095.           new = (struct compiler *) xmalloc (sizeof (struct compiler));
  4096.           new->suffix = cp->suffix;
  4097.           bcopy (lookup_compiler (NULL_PTR, 0, language)->spec,
  4098.              new->spec, sizeof new->spec);
  4099.           return new;
  4100.         }
  4101.       /* A non-alias entry: return it.  */
  4102.       return cp;
  4103.     }
  4104.     }
  4105.  
  4106.   return 0;
  4107. }
  4108.  
  4109. char *
  4110. xmalloc (size)
  4111.      unsigned size;
  4112. {
  4113.   register char *value = (char *) malloc (size);
  4114.   if (value == 0)
  4115.     fatal ("virtual memory exhausted");
  4116.   return value;
  4117. }
  4118.  
  4119. char *
  4120. xrealloc (ptr, size)
  4121.      char *ptr;
  4122.      unsigned size;
  4123. {
  4124.   register char *value = (char *) realloc (ptr, size);
  4125.   if (value == 0)
  4126.     fatal ("virtual memory exhausted");
  4127.   return value;
  4128. }
  4129.  
  4130. /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3.  */
  4131.  
  4132. static char *
  4133. concat (s1, s2, s3)
  4134.      char *s1, *s2, *s3;
  4135. {
  4136.   int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
  4137.   char *result = xmalloc (len1 + len2 + len3 + 1);
  4138.  
  4139.   strcpy (result, s1);
  4140.   strcpy (result + len1, s2);
  4141.   strcpy (result + len1 + len2, s3);
  4142.   *(result + len1 + len2 + len3) = 0;
  4143.  
  4144.   return result;
  4145. }
  4146.  
  4147. static char *
  4148. save_string (s, len)
  4149.      char *s;
  4150.      int len;
  4151. {
  4152.   register char *result = xmalloc (len + 1);
  4153.  
  4154.   bcopy (s, result, len);
  4155.   result[len] = 0;
  4156.   return result;
  4157. }
  4158.  
  4159. static void
  4160. pfatal_with_name (name)
  4161.      char *name;
  4162. {
  4163.   char *s;
  4164.  
  4165.   if (errno < sys_nerr)
  4166.     s = concat ("%s: ", sys_errlist[errno], "");
  4167.   else
  4168.     s = "cannot open %s";
  4169.   fatal (s, name);
  4170. }
  4171.  
  4172. static void
  4173. perror_with_name (name)
  4174.      char *name;
  4175. {
  4176.   char *s;
  4177.  
  4178.   if (errno < sys_nerr)
  4179.     s = concat ("%s: ", sys_errlist[errno], "");
  4180.   else
  4181.     s = "cannot open %s";
  4182.   error (s, name);
  4183. }
  4184.  
  4185. static void
  4186. perror_exec (name)
  4187.      char *name;
  4188. {
  4189.   char *s;
  4190.  
  4191.   if (errno < sys_nerr)
  4192.     s = concat ("installation problem, cannot exec %s: ",
  4193.         sys_errlist[errno], "");
  4194.   else
  4195.     s = "installation problem, cannot exec %s";
  4196.   error (s, name);
  4197. }
  4198.  
  4199. /* More 'friendly' abort that prints the line and file.
  4200.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  4201.  
  4202. void
  4203. fancy_abort ()
  4204. {
  4205.   fatal ("Internal gcc abort.");
  4206. }
  4207.  
  4208. #ifdef HAVE_VPRINTF
  4209.  
  4210. /* Output an error message and exit */
  4211.  
  4212. static void
  4213. fatal (va_alist)
  4214.      va_dcl
  4215. {
  4216.   va_list ap;
  4217.   char *format;
  4218.  
  4219.   va_start (ap);
  4220.   format = va_arg (ap, char *);
  4221.   fprintf (stderr, "%s: ", programname);
  4222.   vfprintf (stderr, format, ap);
  4223.   va_end (ap);
  4224.   fprintf (stderr, "\n");
  4225.   delete_temp_files ();
  4226.   exit (1);
  4227. }
  4228.  
  4229. static void
  4230. error (va_alist)
  4231.      va_dcl
  4232. {
  4233.   va_list ap;
  4234.   char *format;
  4235.  
  4236.   va_start (ap);
  4237.   format = va_arg (ap, char *);
  4238.   fprintf (stderr, "%s: ", programname);
  4239.   vfprintf (stderr, format, ap);
  4240.   va_end (ap);
  4241.  
  4242.   fprintf (stderr, "\n");
  4243. }
  4244.  
  4245. #else /* not HAVE_VPRINTF */
  4246.  
  4247. static void
  4248. fatal (msg, arg1, arg2)
  4249.      char *msg, *arg1, *arg2;
  4250. {
  4251.   error (msg, arg1, arg2);
  4252.   delete_temp_files ();
  4253.   exit (1);
  4254. }
  4255.  
  4256. static void
  4257. error (msg, arg1, arg2)
  4258.      char *msg, *arg1, *arg2;
  4259. {
  4260.   fprintf (stderr, "%s: ", programname);
  4261.   fprintf (stderr, msg, arg1, arg2);
  4262.   fprintf (stderr, "\n");
  4263. }
  4264.  
  4265. #endif /* not HAVE_VPRINTF */
  4266.  
  4267.  
  4268. static void
  4269. validate_all_switches ()
  4270. {
  4271.   struct compiler *comp;
  4272.   register char *p;
  4273.   register char c;
  4274.   struct spec_list *spec;
  4275.  
  4276.   for (comp = compilers; comp->spec[0]; comp++)
  4277.     {
  4278.       int i;
  4279.       for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
  4280.     {
  4281.       p = comp->spec[i];
  4282.       while (c = *p++)
  4283.         if (c == '%' && *p == '{')
  4284.           /* We have a switch spec.  */
  4285.           validate_switches (p + 1);
  4286.     }
  4287.     }
  4288.  
  4289.   /* look through the linked list of extra specs read from the specs file */
  4290.   for (spec = specs; spec ; spec = spec->next)
  4291.     {
  4292.       p = spec->spec;
  4293.       while (c = *p++)
  4294.     if (c == '%' && *p == '{')
  4295.       /* We have a switch spec.  */
  4296.       validate_switches (p + 1);
  4297.     }
  4298.  
  4299.   p = link_command_spec;
  4300.   while (c = *p++)
  4301.     if (c == '%' && *p == '{')
  4302.       /* We have a switch spec.  */
  4303.       validate_switches (p + 1);
  4304.  
  4305.   /* Now notice switches mentioned in the machine-specific specs.  */
  4306.  
  4307.   p = asm_spec;
  4308.   while (c = *p++)
  4309.     if (c == '%' && *p == '{')
  4310.       /* We have a switch spec.  */
  4311.       validate_switches (p + 1);
  4312.  
  4313.   p = asm_final_spec;
  4314.   while (c = *p++)
  4315.     if (c == '%' && *p == '{')
  4316.       /* We have a switch spec.  */
  4317.       validate_switches (p + 1);
  4318.  
  4319.   p = cpp_spec;
  4320.   while (c = *p++)
  4321.     if (c == '%' && *p == '{')
  4322.       /* We have a switch spec.  */
  4323.       validate_switches (p + 1);
  4324.  
  4325.   p = signed_char_spec;
  4326.   while (c = *p++)
  4327.     if (c == '%' && *p == '{')
  4328.       /* We have a switch spec.  */
  4329.       validate_switches (p + 1);
  4330.  
  4331.   p = cc1_spec;
  4332.   while (c = *p++)
  4333.     if (c == '%' && *p == '{')
  4334.       /* We have a switch spec.  */
  4335.       validate_switches (p + 1);
  4336.  
  4337.   p = cc1plus_spec;
  4338.   while (c = *p++)
  4339.     if (c == '%' && *p == '{')
  4340.       /* We have a switch spec.  */
  4341.       validate_switches (p + 1);
  4342.  
  4343.   p = link_spec;
  4344.   while (c = *p++)
  4345.     if (c == '%' && *p == '{')
  4346.       /* We have a switch spec.  */
  4347.       validate_switches (p + 1);
  4348.  
  4349.   p = lib_spec;
  4350.   while (c = *p++)
  4351.     if (c == '%' && *p == '{')
  4352.       /* We have a switch spec.  */
  4353.       validate_switches (p + 1);
  4354.  
  4355.   p = startfile_spec;
  4356.   while (c = *p++)
  4357.     if (c == '%' && *p == '{')
  4358.       /* We have a switch spec.  */
  4359.       validate_switches (p + 1);
  4360. }
  4361.  
  4362. /* Look at the switch-name that comes after START
  4363.    and mark as valid all supplied switches that match it.  */
  4364.  
  4365. static void
  4366. validate_switches (start)
  4367.      char *start;
  4368. {
  4369.   register char *p = start;
  4370.   char *filter;
  4371.   register int i;
  4372.   int suffix = 0;
  4373.  
  4374.   if (*p == '|')
  4375.     ++p;
  4376.  
  4377.   if (*p == '!')
  4378.     ++p;
  4379.  
  4380.   if (*p == '.')
  4381.     suffix = 1, ++p;
  4382.  
  4383.   filter = p;
  4384.   while (*p != ':' && *p != '}') p++;
  4385.  
  4386.   if (suffix)
  4387.     ;
  4388.   else if (p[-1] == '*')
  4389.     {
  4390.       /* Mark all matching switches as valid.  */
  4391.       --p;
  4392.       for (i = 0; i < n_switches; i++)
  4393.     if (!strncmp (switches[i].part1, filter, p - filter))
  4394.       switches[i].valid = 1;
  4395.     }
  4396.   else
  4397.     {
  4398.       /* Mark an exact matching switch as valid.  */
  4399.       for (i = 0; i < n_switches; i++)
  4400.     {
  4401.       if (!strncmp (switches[i].part1, filter, p - filter)
  4402.           && switches[i].part1[p - filter] == 0)
  4403.         switches[i].valid = 1;
  4404.     }
  4405.     }
  4406. }
  4407.