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