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