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