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