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