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