]>
Commit | Line | Data |
---|---|---|
d7a9644e | 1 | /* Compiler driver program that can handle many languages. |
2c815aff | 2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
91e64380 | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
87c75316 | 4 | Free Software Foundation, Inc. |
d7a9644e | 5 | |
f12b58b3 | 6 | This file is part of GCC. |
d7a9644e | 7 | |
f12b58b3 | 8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 10 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 11 | version. |
d7a9644e | 12 | |
f12b58b3 | 13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
d7a9644e | 17 | |
18 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 19 | along with GCC; see the file COPYING3. If not see |
3d70fb39 | 20 | <http://www.gnu.org/licenses/>. */ |
d7a9644e | 21 | |
22 | /* This program is the user interface to the C compiler and possibly to | |
23 | other compilers. It is used because compilation is a complicated procedure | |
24 | which involves running several programs and passing temporary files between | |
25 | them, forwarding the users switches to those programs selectively, | |
26 | and deleting the temporary files at the end. | |
27 | ||
28 | CC recognizes how to compile each input file by suffixes in the file names. | |
29 | Once it knows which kind of compilation to perform, the procedure for | |
30 | compilation is specified by a string called a "spec". */ | |
7014838c | 31 | |
833a5c07 | 32 | /* A Short Introduction to Adding a Command-Line Option. |
33 | ||
34 | Before adding a command-line option, consider if it is really | |
35 | necessary. Each additional command-line option adds complexity and | |
36 | is difficult to remove in subsequent versions. | |
37 | ||
38 | In the following, consider adding the command-line argument | |
39 | `--bar'. | |
40 | ||
41 | 1. Each command-line option is specified in the specs file. The | |
42 | notation is described below in the comment entitled "The Specs | |
43 | Language". Read it. | |
44 | ||
45 | 2. In this file, add an entry to "option_map" equating the long | |
46 | `--' argument version and any shorter, single letter version. Read | |
47 | the comments in the declaration of "struct option_map" for an | |
48 | explanation. Do not omit the first `-'. | |
49 | ||
50 | 3. Look in the "specs" file to determine which program or option | |
51 | list should be given the argument, e.g., "cc1_options". Add the | |
52 | appropriate syntax for the shorter option version to the | |
53 | corresponding "const char *" entry in this file. Omit the first | |
54 | `-' from the option. For example, use `-bar', rather than `--bar'. | |
55 | ||
56 | 4. If the argument takes an argument, e.g., `--baz argument1', | |
57 | modify either DEFAULT_SWITCH_TAKES_ARG or | |
7cdbad2a | 58 | DEFAULT_WORD_SWITCH_TAKES_ARG in gcc.h. Omit the first `-' |
833a5c07 | 59 | from `--baz'. |
60 | ||
61 | 5. Document the option in this file's display_help(). If the | |
62 | option is passed to a subprogram, modify its corresponding | |
63 | function, e.g., cppinit.c:print_help() or toplev.c:display_help(), | |
64 | instead. | |
65 | ||
66 | 6. Compile and test. Make sure that your new specs file is being | |
67 | read. For example, use a debugger to investigate the value of | |
68 | "specs_file" in main(). */ | |
69 | ||
0dbd1c74 | 70 | #include "config.h" |
405711de | 71 | #include "system.h" |
805e22b2 | 72 | #include "coretypes.h" |
0a2326d6 | 73 | #include "multilib.h" /* before tm.h */ |
805e22b2 | 74 | #include "tm.h" |
405711de | 75 | #include <signal.h> |
6b917287 | 76 | #if ! defined( SIGCHLD ) && defined( SIGCLD ) |
77 | # define SIGCHLD SIGCLD | |
78 | #endif | |
9b1f316f | 79 | #include "xregex.h" |
fe8833f8 | 80 | #include "obstack.h" |
be2828ce | 81 | #include "intl.h" |
7bcdc3c7 | 82 | #include "prefix.h" |
7f0b0c27 | 83 | #include "gcc.h" |
a6a0d17a | 84 | #include "flags.h" |
a1baa5f1 | 85 | #include "opts.h" |
4ee8d66a | 86 | |
71278019 | 87 | #ifdef HAVE_MMAP_FILE |
88 | # include <sys/mman.h> | |
89 | # ifdef HAVE_MINCORE | |
90 | /* This is on Solaris. */ | |
91 | # include <sys/types.h> | |
92 | # endif | |
93 | #endif | |
94 | ||
95 | #ifndef MAP_FAILED | |
96 | # define MAP_FAILED ((void *)-1) | |
97 | #endif | |
98 | ||
10f57222 | 99 | /* By default there is no special suffix for target executables. */ |
100 | /* FIXME: when autoconf is fixed, remove the host check - dj */ | |
101 | #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX) | |
102 | #define HAVE_TARGET_EXECUTABLE_SUFFIX | |
d7a9644e | 103 | #endif |
99b832c9 | 104 | |
10f57222 | 105 | /* By default there is no special suffix for host executables. */ |
106 | #ifdef HOST_EXECUTABLE_SUFFIX | |
107 | #define HAVE_HOST_EXECUTABLE_SUFFIX | |
9ec04dd9 | 108 | #else |
10f57222 | 109 | #define HOST_EXECUTABLE_SUFFIX "" |
110 | #endif | |
111 | ||
112 | /* By default, the suffix for target object files is ".o". */ | |
113 | #ifdef TARGET_OBJECT_SUFFIX | |
114 | #define HAVE_TARGET_OBJECT_SUFFIX | |
115 | #else | |
116 | #define TARGET_OBJECT_SUFFIX ".o" | |
499a0933 | 117 | #endif |
118 | ||
e99c3a1d | 119 | static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; |
b9374a77 | 120 | |
397f1574 | 121 | /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */ |
122 | #ifndef LIBRARY_PATH_ENV | |
123 | #define LIBRARY_PATH_ENV "LIBRARY_PATH" | |
124 | #endif | |
125 | ||
ad87de1e | 126 | #ifndef HAVE_KILL |
127 | #define kill(p,s) raise(s) | |
128 | #endif | |
129 | ||
d7a9644e | 130 | /* If a stage of compilation returns an exit status >= 1, |
131 | compilation of that file ceases. */ | |
132 | ||
133 | #define MIN_FATAL_STATUS 1 | |
134 | ||
258d3911 | 135 | /* Flag set by cppspec.c to 1. */ |
136 | int is_cpp_driver; | |
137 | ||
80777cd8 | 138 | /* Flag set to nonzero if an @file argument has been supplied to gcc. */ |
c159e0b7 | 139 | static bool at_file_supplied; |
140 | ||
155b05dc | 141 | /* Flag saying to pass the greatest exit code returned by a sub-process |
142 | to the calling program. */ | |
143 | static int pass_exit_codes; | |
144 | ||
4a0e2d42 | 145 | /* Definition of string containing the arguments given to configure. */ |
146 | #include "configargs.h" | |
147 | ||
71cee7b1 | 148 | /* Flag saying to print the directories gcc will search through looking for |
149 | programs, libraries, etc. */ | |
150 | ||
151 | static int print_search_dirs; | |
152 | ||
1c1a1c70 | 153 | /* Flag saying to print the full filename of this file |
5e3dea2b | 154 | as found through our usual search mechanism. */ |
155 | ||
e40d43cc | 156 | static const char *print_file_name = NULL; |
1c1a1c70 | 157 | |
a92771b8 | 158 | /* As print_file_name, but search for executable file. */ |
1c1a1c70 | 159 | |
e40d43cc | 160 | static const char *print_prog_name = NULL; |
5e3dea2b | 161 | |
9577d478 | 162 | /* Flag saying to print the relative path we'd use to |
163 | find libgcc.a given the current compiler flags. */ | |
164 | ||
165 | static int print_multi_directory; | |
166 | ||
098cc23f | 167 | static int print_sysroot; |
168 | ||
c954ff02 | 169 | /* Flag saying to print the relative path we'd use to |
170 | find OS libraries given the current compiler flags. */ | |
171 | ||
172 | static int print_multi_os_directory; | |
173 | ||
9577d478 | 174 | /* Flag saying to print the list of subdirectories and |
175 | compiler flags used to select them in a standard form. */ | |
176 | ||
177 | static int print_multi_lib; | |
178 | ||
8ace789a | 179 | /* Flag saying to print the command line options understood by gcc and its |
180 | sub-processes. */ | |
181 | ||
182 | static int print_help_list; | |
183 | ||
39932bd2 | 184 | /* Flag saying to print the version of gcc and its sub-processes. */ |
185 | ||
186 | static int print_version; | |
187 | ||
6ea4242f | 188 | /* Flag saying to print the sysroot suffix used for searching for |
189 | headers. */ | |
190 | ||
191 | static int print_sysroot_headers_suffix; | |
192 | ||
d7a9644e | 193 | /* Flag indicating whether we should print the command and arguments */ |
194 | ||
195 | static int verbose_flag; | |
196 | ||
74e4079a | 197 | /* Flag indicating whether we should ONLY print the command and |
198 | arguments (like verbose_flag) without executing the command. | |
199 | Displayed arguments are quoted so that the generated command | |
200 | line is suitable for execution. This is intended for use in | |
201 | shell scripts to capture the driver-generated command line. */ | |
202 | static int verbose_only_flag; | |
203 | ||
87c75316 | 204 | /* Flag indicating how to print command line options of sub-processes. */ |
7a6882ca | 205 | |
87c75316 | 206 | static int print_subprocess_help; |
7a6882ca | 207 | |
a876e5f8 | 208 | /* Flag indicating whether we should report subprocess execution times |
209 | (if this is supported by the system - see pexecute.c). */ | |
210 | ||
211 | static int report_times; | |
212 | ||
4537c5d9 | 213 | /* Whether we should report subprocess execution times to a file. */ |
214 | ||
215 | FILE *report_times_to_file = NULL; | |
216 | ||
805e22b2 | 217 | /* Nonzero means place this string before uses of /, so that include |
218 | and library files can be found in an alternate location. */ | |
219 | ||
d68c6656 | 220 | #ifdef TARGET_SYSTEM_ROOT |
805e22b2 | 221 | static const char *target_system_root = TARGET_SYSTEM_ROOT; |
d68c6656 | 222 | #else |
223 | static const char *target_system_root = 0; | |
224 | #endif | |
805e22b2 | 225 | |
17acc97a | 226 | /* Nonzero means pass the updated target_system_root to the compiler. */ |
227 | ||
228 | static int target_system_root_changed; | |
229 | ||
4ea70922 | 230 | /* Nonzero means append this string to target_system_root. */ |
231 | ||
232 | static const char *target_sysroot_suffix = 0; | |
233 | ||
234 | /* Nonzero means append this string to target_system_root for headers. */ | |
235 | ||
236 | static const char *target_sysroot_hdrs_suffix = 0; | |
237 | ||
d7a9644e | 238 | /* Nonzero means write "temp" files in source directory |
239 | and use the source file's name in them, and don't delete them. */ | |
240 | ||
cc92bc82 | 241 | static enum save_temps { |
242 | SAVE_TEMPS_NONE, /* no -save-temps */ | |
243 | SAVE_TEMPS_CWD, /* -save-temps in current directory */ | |
244 | SAVE_TEMPS_OBJ /* -save-temps in object directory */ | |
245 | } save_temps_flag; | |
246 | ||
247 | /* Output file to use to get the object directory for -save-temps=obj */ | |
248 | static char *save_temps_prefix = 0; | |
249 | static size_t save_temps_length = 0; | |
d7a9644e | 250 | |
dc1dd09b | 251 | /* Nonzero means pass multiple source files to the compiler at one time. */ |
252 | ||
253 | static int combine_flag = 0; | |
254 | ||
805e22b2 | 255 | /* Nonzero means use pipes to communicate between subprocesses. |
256 | Overridden by either of the above two flags. */ | |
257 | ||
258 | static int use_pipes; | |
259 | ||
4dd56bd9 | 260 | /* The compiler version. */ |
d7a9644e | 261 | |
e772a198 | 262 | static const char *compiler_version; |
4dd56bd9 | 263 | |
264 | /* The target version specified with -V */ | |
265 | ||
3443e1be | 266 | static const char *const spec_version = DEFAULT_TARGET_VERSION; |
d7a9644e | 267 | |
268 | /* The target machine specified with -b. */ | |
269 | ||
e40d43cc | 270 | static const char *spec_machine = DEFAULT_TARGET_MACHINE; |
d7a9644e | 271 | |
a45072dd | 272 | /* Nonzero if cross-compiling. |
273 | When -b is used, the value comes from the `specs' file. */ | |
274 | ||
29d774d0 | 275 | #ifdef CROSS_DIRECTORY_STRUCTURE |
e772a198 | 276 | static const char *cross_compile = "1"; |
a45072dd | 277 | #else |
e772a198 | 278 | static const char *cross_compile = "0"; |
a45072dd | 279 | #endif |
280 | ||
d2537617 | 281 | #ifdef MODIFY_TARGET_NAME |
282 | ||
283 | /* Information on how to alter the target name based on a command-line | |
284 | switch. The only case we support now is simply appending or deleting a | |
285 | string to or from the end of the first part of the configuration name. */ | |
286 | ||
0b09525f | 287 | enum add_del {ADD, DELETE}; |
288 | ||
e7c691ac | 289 | static const struct modify_target |
d2537617 | 290 | { |
e99c3a1d | 291 | const char *const sw; |
0b09525f | 292 | const enum add_del add_del; |
e99c3a1d | 293 | const char *const str; |
d2537617 | 294 | } |
295 | modify_target[] = MODIFY_TARGET_NAME; | |
296 | #endif | |
3cfec666 | 297 | |
d1a3c9a3 | 298 | /* The number of errors that have occurred; the link phase will not be |
6ef828f9 | 299 | run if this is nonzero. */ |
d1a3c9a3 | 300 | static int error_count = 0; |
301 | ||
155b05dc | 302 | /* Greatest exit code of sub-processes that has been encountered up to |
303 | now. */ | |
304 | static int greatest_status = 1; | |
305 | ||
d7a9644e | 306 | /* This is the obstack which we use to allocate many strings. */ |
307 | ||
308 | static struct obstack obstack; | |
309 | ||
8894538a | 310 | /* This is the obstack to build an environment variable to pass to |
4bbea254 | 311 | collect2 that describes all of the relevant switches of what to |
8894538a | 312 | pass the compiler in building the list of pointers to constructors |
313 | and destructors. */ | |
314 | ||
315 | static struct obstack collect_obstack; | |
316 | ||
0bfd146e | 317 | /* This is a list of a wrapper program and its arguments. |
318 | e.g. wrapper_string of "strace,-c" | |
319 | will cause all programs to run as | |
320 | strace -c program arguments | |
321 | instead of just | |
322 | program arguments */ | |
323 | static const char *wrapper_string; | |
324 | ||
cbc3c863 | 325 | /* Forward declaration for prototypes. */ |
326 | struct path_prefix; | |
42bbc7e6 | 327 | struct prefix_list; |
cbc3c863 | 328 | |
952f0048 | 329 | static void init_spec (void); |
330 | static void store_arg (const char *, int, int); | |
0bfd146e | 331 | static void insert_wrapper (const char *); |
952f0048 | 332 | static char *load_specs (const char *); |
333 | static void read_specs (const char *, int); | |
334 | static void set_spec (const char *, const char *); | |
335 | static struct compiler *lookup_compiler (const char *, size_t, const char *); | |
067277c3 | 336 | static char *build_search_list (const struct path_prefix *, const char *, |
337 | bool, bool); | |
e8105390 | 338 | static void xputenv (const char *); |
067277c3 | 339 | static void putenv_from_prefixes (const struct path_prefix *, const char *, |
340 | bool); | |
952f0048 | 341 | static int access_check (const char *, int); |
067277c3 | 342 | static char *find_a_file (const struct path_prefix *, const char *, int, bool); |
952f0048 | 343 | static void add_prefix (struct path_prefix *, const char *, const char *, |
2af84186 | 344 | int, int, int); |
952f0048 | 345 | static void add_sysrooted_prefix (struct path_prefix *, const char *, |
2af84186 | 346 | const char *, int, int, int); |
952f0048 | 347 | static void translate_options (int *, const char *const **); |
348 | static char *skip_whitespace (char *); | |
349 | static void delete_if_ordinary (const char *); | |
350 | static void delete_temp_files (void); | |
351 | static void delete_failure_queue (void); | |
352 | static void clear_failure_queue (void); | |
353 | static int check_live_switch (int, int); | |
354 | static const char *handle_braces (const char *); | |
355 | static inline bool input_suffix_matches (const char *, const char *); | |
356 | static inline bool switch_matches (const char *, const char *, int); | |
357 | static inline void mark_matching_switches (const char *, const char *, int); | |
358 | static inline void process_marked_switches (void); | |
359 | static const char *process_brace_body (const char *, const char *, const char *, int, int); | |
360 | static const struct spec_function *lookup_spec_function (const char *); | |
361 | static const char *eval_spec_function (const char *, const char *); | |
362 | static const char *handle_spec_function (const char *); | |
363 | static char *save_string (const char *, int); | |
364 | static void set_collect_gcc_options (void); | |
365 | static int do_spec_1 (const char *, int, const char *); | |
366 | static int do_spec_2 (const char *); | |
367 | static void do_option_spec (const char *, const char *); | |
368 | static void do_self_spec (const char *); | |
369 | static const char *find_file (const char *); | |
067277c3 | 370 | static int is_directory (const char *, bool); |
952f0048 | 371 | static const char *validate_switches (const char *); |
372 | static void validate_all_switches (void); | |
373 | static inline void validate_switches_from_spec (const char *); | |
374 | static void give_switch (int, int); | |
375 | static int used_arg (const char *, int); | |
376 | static int default_arg (const char *, int); | |
377 | static void set_multilib_dir (void); | |
378 | static void print_multilib_info (void); | |
379 | static void perror_with_name (const char *); | |
87011ef0 | 380 | static void fatal_ice (const char *, ...) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; |
952f0048 | 381 | static void notice (const char *, ...) ATTRIBUTE_PRINTF_1; |
382 | static void display_help (void); | |
383 | static void add_preprocessor_option (const char *, int); | |
384 | static void add_assembler_option (const char *, int); | |
385 | static void add_linker_option (const char *, int); | |
9300babd | 386 | static void process_command (int, const char **); |
952f0048 | 387 | static int execute (void); |
388 | static void alloc_args (void); | |
389 | static void clear_args (void); | |
390 | static void fatal_error (int); | |
ecbfdc87 | 391 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
952f0048 | 392 | static void init_gcc_specs (struct obstack *, const char *, const char *, |
393 | const char *); | |
b51d5c7c | 394 | #endif |
7e6b5e54 | 395 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
952f0048 | 396 | static const char *convert_filename (const char *, int, int); |
7e6b5e54 | 397 | #endif |
c21b3276 | 398 | |
0305c755 | 399 | static const char *getenv_spec_function (int, const char **); |
952f0048 | 400 | static const char *if_exists_spec_function (int, const char **); |
401 | static const char *if_exists_else_spec_function (int, const char **); | |
2288041e | 402 | static const char *replace_outfile_spec_function (int, const char **); |
9b1f316f | 403 | static const char *version_compare_spec_function (int, const char **); |
1e8e9920 | 404 | static const char *include_spec_function (int, const char **); |
ceac8e8c | 405 | static const char *print_asm_header_spec_function (int, const char **); |
71278019 | 406 | static const char *compare_debug_dump_opt_spec_function (int, const char **); |
407 | static const char *compare_debug_self_opt_spec_function (int, const char **); | |
408 | static const char *compare_debug_auxbase_opt_spec_function (int, const char **); | |
d7a9644e | 409 | \f |
833a5c07 | 410 | /* The Specs Language |
411 | ||
412 | Specs are strings containing lines, each of which (if not blank) | |
d7a9644e | 413 | is made up of a program name, and arguments separated by spaces. |
414 | The program name must be exact and start from root, since no path | |
415 | is searched and it is unreliable to depend on the current working directory. | |
416 | Redirection of input or output is not supported; the subprograms must | |
417 | accept filenames saying what files to read and write. | |
418 | ||
419 | In addition, the specs can contain %-sequences to substitute variable text | |
420 | or for conditional text. Here is a table of all defined %-sequences. | |
421 | Note that spaces are not generated automatically around the results of | |
422 | expanding these sequences; therefore, you can concatenate them together | |
423 | or with constant text in a single argument. | |
424 | ||
425 | %% substitute one % into the program name or argument. | |
426 | %i substitute the name of the input file being processed. | |
427 | %b substitute the basename of the input file being processed. | |
428 | This is the substring up to (and not including) the last period | |
cc92bc82 | 429 | and not including the directory unless -save-temps was specified |
d7ee9e9b | 430 | to put temporaries in a different location. |
1cf79a1a | 431 | %B same as %b, but include the file suffix (text after the last period). |
c78c5ee7 | 432 | %gSUFFIX |
433 | substitute a file name that has suffix SUFFIX and is chosen | |
434 | once per compilation, and mark the argument a la %d. To reduce | |
435 | exposure to denial-of-service attacks, the file name is now | |
436 | chosen in a way that is hard to predict even when previously | |
437 | chosen file names are known. For example, `%g.s ... %g.o ... %g.s' | |
438 | might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches | |
b78b6a05 | 439 | the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it |
2c2aaf10 | 440 | had been pre-processed. Previously, %g was simply substituted |
441 | with a file name chosen once per compilation, without regard | |
442 | to any appended suffix (which was therefore treated just like | |
443 | ordinary text), making such attacks more likely to succeed. | |
805e22b2 | 444 | %|SUFFIX |
445 | like %g, but if -pipe is in effect, expands simply to "-". | |
446 | %mSUFFIX | |
447 | like %g, but if -pipe is in effect, expands to nothing. (We have both | |
448 | %| and %m to accommodate differences between system assemblers; see | |
449 | the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.) | |
c78c5ee7 | 450 | %uSUFFIX |
451 | like %g, but generates a new temporary file name even if %uSUFFIX | |
452 | was already seen. | |
453 | %USUFFIX | |
454 | substitutes the last file name generated with %uSUFFIX, generating a | |
455 | new one if there is no such last file name. In the absence of any | |
456 | %uSUFFIX, this is just like %gSUFFIX, except they don't share | |
457 | the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' | |
458 | would involve the generation of two distinct file names, one | |
459 | for each `%g.s' and another for each `%U.s'. Previously, %U was | |
460 | simply substituted with a file name chosen for the previous %u, | |
461 | without regard to any appended suffix. | |
655a58fa | 462 | %jSUFFIX |
463 | substitutes the name of the HOST_BIT_BUCKET, if any, and if it is | |
464 | writable, and if save-temps is off; otherwise, substitute the name | |
465 | of a temporary file, just like %u. This temporary file is not | |
466 | meant for communication between processes, but rather as a junk | |
467 | disposal mechanism. | |
bdbd5352 | 468 | %.SUFFIX |
469 | substitutes .SUFFIX for the suffixes of a matched switch's args when | |
470 | it is subsequently output with %*. SUFFIX is terminated by the next | |
471 | space or %. | |
d7a9644e | 472 | %d marks the argument containing or following the %d as a |
c68bcf58 | 473 | temporary file name, so that that file will be deleted if GCC exits |
d7a9644e | 474 | successfully. Unlike %g, this contributes no text to the argument. |
475 | %w marks the argument containing or following the %w as the | |
476 | "output file" of this compilation. This puts the argument | |
477 | into the sequence of arguments that %o will substitute later. | |
573aba85 | 478 | %V indicates that this compilation produces no "output file". |
d7a9644e | 479 | %W{...} |
480 | like %{...} but mark last argument supplied within | |
481 | as a file to be deleted on failure. | |
482 | %o substitutes the names of all the output files, with spaces | |
483 | automatically placed around them. You should write spaces | |
484 | around the %o as well or the results are undefined. | |
485 | %o is for use in the specs for running the linker. | |
486 | Input files whose names have no recognized suffix are not compiled | |
487 | at all, but they are included among the output files, so they will | |
488 | be linked. | |
c78c5ee7 | 489 | %O substitutes the suffix for object files. Note that this is |
2c2aaf10 | 490 | handled specially when it immediately follows %g, %u, or %U |
491 | (with or without a suffix argument) because of the need for | |
492 | those to form complete file names. The handling is such that | |
493 | %O is treated exactly as if it had already been substituted, | |
494 | except that %g, %u, and %U do not currently support additional | |
495 | SUFFIX characters following %O as they would following, for | |
496 | example, `.o'. | |
17acc97a | 497 | %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot |
72779020 | 498 | (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH |
499 | and -B options) and -imultilib as necessary. | |
d7a9644e | 500 | %s current argument is the name of a library or startup file of some sort. |
501 | Search for that file in a standard list of directories | |
502 | and substitute the full name found. | |
503 | %eSTR Print STR as an error message. STR is terminated by a newline. | |
504 | Use this when inconsistent options are detected. | |
edc2a478 | 505 | %nSTR Print STR as a notice. STR is terminated by a newline. |
d7a9644e | 506 | %x{OPTION} Accumulate an option for %X. |
507 | %X Output the accumulated linker options specified by compilations. | |
69587571 | 508 | %Y Output the accumulated assembler options specified by compilations. |
391d9b6e | 509 | %Z Output the accumulated preprocessor options specified by compilations. |
d7a9644e | 510 | %a process ASM_SPEC as a spec. |
511 | This allows config.h to specify part of the spec for running as. | |
512 | %A process ASM_FINAL_SPEC as a spec. A capital A is actually | |
513 | used here. This can be used to run a post-processor after the | |
9e042f31 | 514 | assembler has done its job. |
b9374a77 | 515 | %D Dump out a -L option for each directory in startfile_prefixes. |
9577d478 | 516 | If multilib_dir is set, extra entries are generated with it affixed. |
d7a9644e | 517 | %l process LINK_SPEC as a spec. |
518 | %L process LIB_SPEC as a spec. | |
b7c87ff2 | 519 | %G process LIBGCC_SPEC as a spec. |
b6bcc48f | 520 | %R Output the concatenation of target_system_root and |
521 | target_sysroot_suffix. | |
d7a9644e | 522 | %S process STARTFILE_SPEC as a spec. A capital S is actually used here. |
523 | %E process ENDFILE_SPEC as a spec. A capital E is actually used here. | |
43198b29 | 524 | %C process CPP_SPEC as a spec. |
d7a9644e | 525 | %1 process CC1_SPEC as a spec. |
526 | %2 process CC1PLUS_SPEC as a spec. | |
527 | %* substitute the variable part of a matched option. (See below.) | |
528 | Note that each comma in the substituted string is replaced by | |
529 | a single space. | |
805e22b2 | 530 | %<S remove all occurrences of -S from the command line. |
531 | Note - this command is position dependent. % commands in the | |
532 | spec string before this one will see -S, % commands in the | |
533 | spec string after this one will not. | |
534 | %<S* remove all occurrences of all switches beginning with -S from the | |
535 | command line. | |
c21b3276 | 536 | %:function(args) |
537 | Call the named function FUNCTION, passing it ARGS. ARGS is | |
538 | first processed as a nested spec string, then split into an | |
539 | argument vector in the usual fashion. The function returns | |
540 | a string which is processed as if it had appeared literally | |
541 | as part of the current spec. | |
c68bcf58 | 542 | %{S} substitutes the -S switch, if that switch was given to GCC. |
d7a9644e | 543 | If that switch was not specified, this substitutes nothing. |
544 | Here S is a metasyntactic variable. | |
c68bcf58 | 545 | %{S*} substitutes all the switches specified to GCC whose names start |
e1478c0f | 546 | with -S. This is used for -o, -I, etc; switches that take |
c68bcf58 | 547 | arguments. GCC considers `-o foo' as being one switch whose |
d7a9644e | 548 | name starts with `o'. %{o*} would substitute this text, |
549 | including the space; thus, two arguments would be generated. | |
e1478c0f | 550 | %{S*&T*} likewise, but preserve order of S and T options (the order |
952f0048 | 551 | of S and T in the spec is not significant). Can be any number |
552 | of ampersand-separated variables; for each the wild card is | |
553 | optional. Useful for CPP as %{D*&U*&A*}. | |
805e22b2 | 554 | |
c68bcf58 | 555 | %{S:X} substitutes X, if the -S switch was given to GCC. |
556 | %{!S:X} substitutes X, if the -S switch was NOT given to GCC. | |
805e22b2 | 557 | %{S*:X} substitutes X if one or more switches whose names start |
c68bcf58 | 558 | with -S was given to GCC. Normally X is substituted only |
805e22b2 | 559 | once, no matter how many such switches appeared. However, |
560 | if %* appears somewhere in X, then X will be substituted | |
561 | once for each matching switch, with the %* replaced by the | |
562 | part of that switch that matched the '*'. | |
563 | %{.S:X} substitutes X, if processing a file with suffix S. | |
564 | %{!.S:X} substitutes X, if NOT processing a file with suffix S. | |
90e35d1a | 565 | %{,S:X} substitutes X, if processing a file which will use spec S. |
566 | %{!,S:X} substitutes X, if NOT processing a file which will use spec S. | |
d7ee9e9b | 567 | |
c68bcf58 | 568 | %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be |
90e35d1a | 569 | combined with '!', '.', ',', and '*' as above binding stronger |
570 | than the OR. | |
805e22b2 | 571 | If %* appears in X, all of the alternatives must be starred, and |
572 | only the first matching alternative is substituted. | |
c68bcf58 | 573 | %{S:X; if S was given to GCC, substitutes X; |
574 | T:Y; else if T was given to GCC, substitutes Y; | |
805e22b2 | 575 | :D} else substitutes D. There can be as many clauses as you need. |
90e35d1a | 576 | This may be combined with '.', '!', ',', '|', and '*' as above. |
805e22b2 | 577 | |
8894538a | 578 | %(Spec) processes a specification defined in a specs file as *Spec: |
50bcc52e | 579 | %[Spec] as above, but put __ around -D arguments |
d7a9644e | 580 | |
805e22b2 | 581 | The conditional text X in a %{S:X} or similar construct may contain |
d7a9644e | 582 | other nested % constructs or spaces, or even newlines. They are |
805e22b2 | 583 | processed as usual, as described above. Trailing white space in X is |
584 | ignored. White space may also appear anywhere on the left side of the | |
585 | colon in these constructs, except between . or * and the corresponding | |
586 | word. | |
d7a9644e | 587 | |
d870e215 | 588 | The -O, -f, -m, and -W switches are handled specifically in these |
cde688ab | 589 | constructs. If another value of -O or the negated form of a -f, -m, or |
590 | -W switch is found later in the command line, the earlier switch | |
d870e215 | 591 | value is ignored, except with {S*} where S is just one letter; this |
592 | passes all matching options. | |
cde688ab | 593 | |
ae70654c | 594 | The character | at the beginning of the predicate text is used to indicate |
595 | that a command should be piped to the following command, but only if -pipe | |
596 | is specified. | |
d7a9644e | 597 | |
c68bcf58 | 598 | Note that it is built into GCC which switches take arguments and which |
d7a9644e | 599 | do not. You might think it would be useful to generalize this to |
600 | allow each compiler's spec to say which switches take arguments. But | |
c68bcf58 | 601 | this cannot be done in a consistent fashion. GCC cannot even decide |
d7a9644e | 602 | which input files have been specified without knowing which switches |
603 | take arguments, and it must know which input files to compile in order | |
604 | to tell which compilers to run. | |
605 | ||
c68bcf58 | 606 | GCC also knows implicitly that arguments starting in `-l' are to be |
d7a9644e | 607 | treated as compiler output files, and passed to the linker in their |
608 | proper position among the other output files. */ | |
609 | \f | |
537c4bc6 | 610 | /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */ |
d7a9644e | 611 | |
612 | /* config.h can define ASM_SPEC to provide extra args to the assembler | |
613 | or extra switch-translations. */ | |
614 | #ifndef ASM_SPEC | |
615 | #define ASM_SPEC "" | |
616 | #endif | |
617 | ||
618 | /* config.h can define ASM_FINAL_SPEC to run a post processor after | |
619 | the assembler has run. */ | |
620 | #ifndef ASM_FINAL_SPEC | |
621 | #define ASM_FINAL_SPEC "" | |
622 | #endif | |
623 | ||
624 | /* config.h can define CPP_SPEC to provide extra args to the C preprocessor | |
625 | or extra switch-translations. */ | |
626 | #ifndef CPP_SPEC | |
627 | #define CPP_SPEC "" | |
628 | #endif | |
629 | ||
630 | /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus | |
631 | or extra switch-translations. */ | |
632 | #ifndef CC1_SPEC | |
633 | #define CC1_SPEC "" | |
634 | #endif | |
635 | ||
636 | /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus | |
637 | or extra switch-translations. */ | |
638 | #ifndef CC1PLUS_SPEC | |
639 | #define CC1PLUS_SPEC "" | |
640 | #endif | |
641 | ||
642 | /* config.h can define LINK_SPEC to provide extra args to the linker | |
643 | or extra switch-translations. */ | |
644 | #ifndef LINK_SPEC | |
645 | #define LINK_SPEC "" | |
646 | #endif | |
647 | ||
648 | /* config.h can define LIB_SPEC to override the default libraries. */ | |
649 | #ifndef LIB_SPEC | |
b7c87ff2 | 650 | #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" |
651 | #endif | |
652 | ||
4ee9c684 | 653 | /* mudflap specs */ |
654 | #ifndef MFWRAP_SPEC | |
655 | /* XXX: valid only for GNU ld */ | |
656 | /* XXX: should exactly match hooks provided by libmudflap.a */ | |
657 | #define MFWRAP_SPEC " %{static: %{fmudflap|fmudflapth: \ | |
658 | --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\ | |
659 | --wrap=mmap --wrap=munmap --wrap=alloca\ | |
ee3213a3 | 660 | } %{fmudflapth: --wrap=pthread_create\ |
4ee9c684 | 661 | }} %{fmudflap|fmudflapth: --wrap=main}" |
662 | #endif | |
663 | #ifndef MFLIB_SPEC | |
2f2c6aee | 664 | #define MFLIB_SPEC "%{fmudflap|fmudflapth: -export-dynamic}" |
4ee9c684 | 665 | #endif |
666 | ||
b7c87ff2 | 667 | /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is |
668 | included. */ | |
669 | #ifndef LIBGCC_SPEC | |
ecbfdc87 | 670 | #if defined(REAL_LIBGCC_SPEC) |
671 | #define LIBGCC_SPEC REAL_LIBGCC_SPEC | |
03829d4a | 672 | #elif defined(LINK_LIBGCC_SPECIAL_1) |
b7c87ff2 | 673 | /* Have gcc do the search for libgcc.a. */ |
21eaebc3 | 674 | #define LIBGCC_SPEC "libgcc.a%s" |
b7c87ff2 | 675 | #else |
21eaebc3 | 676 | #define LIBGCC_SPEC "-lgcc" |
b7c87ff2 | 677 | #endif |
d7a9644e | 678 | #endif |
679 | ||
680 | /* config.h can define STARTFILE_SPEC to override the default crt0 files. */ | |
681 | #ifndef STARTFILE_SPEC | |
682 | #define STARTFILE_SPEC \ | |
995c1b4d | 683 | "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" |
d7a9644e | 684 | #endif |
685 | ||
08309729 | 686 | /* config.h can define SWITCHES_NEED_SPACES to control which options |
274d4128 | 687 | require spaces between the option and the argument. |
688 | ||
689 | We define SWITCHES_NEED_SPACES to include "o" by default. This | |
690 | causes "-ofoo.o" to be split into "-o foo.o" during the initial | |
691 | processing of the command-line, before being seen by the specs | |
692 | machinery. This makes sure we record "foo.o" as the temporary file | |
693 | to be deleted in the case of error, rather than "-ofoo.o". */ | |
d7a9644e | 694 | #ifndef SWITCHES_NEED_SPACES |
274d4128 | 695 | #define SWITCHES_NEED_SPACES "o" |
d7a9644e | 696 | #endif |
697 | ||
698 | /* config.h can define ENDFILE_SPEC to override the default crtn files. */ | |
699 | #ifndef ENDFILE_SPEC | |
700 | #define ENDFILE_SPEC "" | |
701 | #endif | |
702 | ||
0c787992 | 703 | #ifndef LINKER_NAME |
704 | #define LINKER_NAME "collect2" | |
705 | #endif | |
706 | ||
5f1f2de5 | 707 | #ifdef HAVE_AS_DEBUG_PREFIX_MAP |
708 | #define ASM_MAP " %{fdebug-prefix-map=*:--debug-prefix-map %*}" | |
709 | #else | |
710 | #define ASM_MAP "" | |
711 | #endif | |
712 | ||
1a6f9700 | 713 | /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g' |
714 | to the assembler. */ | |
715 | #ifndef ASM_DEBUG_SPEC | |
82505826 | 716 | # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \ |
717 | && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) | |
5f1f2de5 | 718 | # define ASM_DEBUG_SPEC \ |
719 | (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \ | |
674ca8bf | 720 | ? "%{!g0:%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}}" ASM_MAP \ |
721 | : "%{!g0:%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP) | |
82505826 | 722 | # else |
723 | # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) | |
674ca8bf | 724 | # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gstabs}}" ASM_MAP |
82505826 | 725 | # endif |
726 | # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) | |
674ca8bf | 727 | # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gdwarf2}}" ASM_MAP |
1a6f9700 | 728 | # endif |
1a6f9700 | 729 | # endif |
730 | #endif | |
a6a0d17a | 731 | #ifndef ASM_DEBUG_SPEC |
732 | # define ASM_DEBUG_SPEC "" | |
733 | #endif | |
1a6f9700 | 734 | |
1cf79a1a | 735 | /* Here is the spec for running the linker, after compiling all files. */ |
736 | ||
da98d114 | 737 | /* This is overridable by the target in case they need to specify the |
738 | -lgcc and -lc order specially, yet not require them to override all | |
739 | of LINK_COMMAND_SPEC. */ | |
740 | #ifndef LINK_GCC_C_SEQUENCE_SPEC | |
741 | #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G" | |
742 | #endif | |
743 | ||
0d55f4d0 | 744 | #ifndef LINK_SSP_SPEC |
745 | #ifdef TARGET_LIBC_PROVIDES_SSP | |
746 | #define LINK_SSP_SPEC "%{fstack-protector:}" | |
747 | #else | |
9fe3fba9 | 748 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}" |
0d55f4d0 | 749 | #endif |
750 | #endif | |
751 | ||
c3ce66b0 | 752 | #ifndef LINK_PIE_SPEC |
753 | #ifdef HAVE_LD_PIE | |
754 | #define LINK_PIE_SPEC "%{pie:-pie} " | |
755 | #else | |
756 | #define LINK_PIE_SPEC "%{pie:} " | |
757 | #endif | |
758 | #endif | |
759 | ||
8271b966 | 760 | #ifndef LINK_BUILDID_SPEC |
761 | # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID) | |
762 | # define LINK_BUILDID_SPEC "%{!r:--build-id} " | |
763 | # endif | |
764 | #endif | |
765 | ||
766 | ||
1cf79a1a | 767 | /* -u* was put back because both BSD and SysV seem to support it. */ |
768 | /* %{static:} simply prevents an error message if the target machine | |
769 | doesn't handle -static. */ | |
770 | /* We want %{T*} after %{L*} and %D so that it can be used to specify linker | |
771 | scripts which exist in user specified directories, or in standard | |
772 | directories. */ | |
7bfefa9d | 773 | /* We pass any -flto and -fwhopr flags on to the linker, which is expected |
774 | to understand them. In practice, this means it had better be collect2. */ | |
1cf79a1a | 775 | #ifndef LINK_COMMAND_SPEC |
776 | #define LINK_COMMAND_SPEC "\ | |
777 | %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ | |
7bfefa9d | 778 | %(linker) \ |
386fbe6a | 779 | %{fuse-linker-plugin: \ |
7bfefa9d | 780 | -plugin %(linker_plugin_file) \ |
781 | -plugin-opt=%(lto_wrapper) \ | |
782 | -plugin-opt=%(lto_gcc) \ | |
783 | %{static|static-libgcc:-plugin-opt=-pass-through=%(lto_libgcc)} \ | |
0da276d2 | 784 | %{static:-plugin-opt=-pass-through=-lc} \ |
7bfefa9d | 785 | %{O*:-plugin-opt=-O%*} \ |
786 | %{w:-plugin-opt=-w} \ | |
787 | %{f*:-plugin-opt=-f%*} \ | |
788 | } \ | |
789 | %{flto} %{fwhopr} %l " LINK_PIE_SPEC \ | |
790 | "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\ | |
c3ce66b0 | 791 | %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ |
33238887 | 792 | %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\ |
061202f8 | 793 | %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)} %(mflib)\ |
57187d90 | 794 | %{fprofile-arcs|fprofile-generate*|coverage:-lgcov}\ |
b21d5608 | 795 | %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\ |
1cf79a1a | 796 | %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}" |
797 | #endif | |
798 | ||
799 | #ifndef LINK_LIBGCC_SPEC | |
03829d4a | 800 | /* Generate -L options for startfile prefix list. */ |
801 | # define LINK_LIBGCC_SPEC "%D" | |
1cf79a1a | 802 | #endif |
803 | ||
4ae4e5e8 | 804 | #ifndef STARTFILE_PREFIX_SPEC |
805 | # define STARTFILE_PREFIX_SPEC "" | |
806 | #endif | |
807 | ||
b6bcc48f | 808 | #ifndef SYSROOT_SPEC |
809 | # define SYSROOT_SPEC "--sysroot=%R" | |
810 | #endif | |
811 | ||
4ea70922 | 812 | #ifndef SYSROOT_SUFFIX_SPEC |
813 | # define SYSROOT_SUFFIX_SPEC "" | |
814 | #endif | |
815 | ||
816 | #ifndef SYSROOT_HEADERS_SUFFIX_SPEC | |
817 | # define SYSROOT_HEADERS_SUFFIX_SPEC "" | |
818 | #endif | |
819 | ||
a4de3479 | 820 | static const char *asm_debug; |
e772a198 | 821 | static const char *cpp_spec = CPP_SPEC; |
e772a198 | 822 | static const char *cc1_spec = CC1_SPEC; |
823 | static const char *cc1plus_spec = CC1PLUS_SPEC; | |
da98d114 | 824 | static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC; |
0d55f4d0 | 825 | static const char *link_ssp_spec = LINK_SSP_SPEC; |
e772a198 | 826 | static const char *asm_spec = ASM_SPEC; |
827 | static const char *asm_final_spec = ASM_FINAL_SPEC; | |
828 | static const char *link_spec = LINK_SPEC; | |
829 | static const char *lib_spec = LIB_SPEC; | |
4ee9c684 | 830 | static const char *mfwrap_spec = MFWRAP_SPEC; |
831 | static const char *mflib_spec = MFLIB_SPEC; | |
1e8e9920 | 832 | static const char *link_gomp_spec = ""; |
e772a198 | 833 | static const char *libgcc_spec = LIBGCC_SPEC; |
834 | static const char *endfile_spec = ENDFILE_SPEC; | |
835 | static const char *startfile_spec = STARTFILE_SPEC; | |
836 | static const char *switches_need_spaces = SWITCHES_NEED_SPACES; | |
837 | static const char *linker_name_spec = LINKER_NAME; | |
7bfefa9d | 838 | static const char *linker_plugin_file_spec = ""; |
839 | static const char *lto_wrapper_spec = ""; | |
840 | static const char *lto_gcc_spec = ""; | |
841 | static const char *lto_libgcc_spec = ""; | |
1cf79a1a | 842 | static const char *link_command_spec = LINK_COMMAND_SPEC; |
843 | static const char *link_libgcc_spec = LINK_LIBGCC_SPEC; | |
4ae4e5e8 | 844 | static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC; |
b6bcc48f | 845 | static const char *sysroot_spec = SYSROOT_SPEC; |
4ea70922 | 846 | static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC; |
847 | static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC; | |
1cf79a1a | 848 | |
849 | /* Standard options to cpp, cc1, and as, to reduce duplication in specs. | |
850 | There should be no need to override these in target dependent files, | |
851 | but we need to copy them to the specs file so that newer versions | |
852 | of the GCC driver can correctly drive older tool chains with the | |
853 | appropriate -B options. */ | |
854 | ||
62683efd | 855 | /* When cpplib handles traditional preprocessing, get rid of this, and |
856 | call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so | |
857 | that we default the front end language better. */ | |
1cf79a1a | 858 | static const char *trad_capable_cpp = |
17df7fec | 859 | "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}"; |
1cf79a1a | 860 | |
eb95e7f7 | 861 | /* We don't wrap .d files in %W{} since a missing .d file, and |
862 | therefore no dependency entry, confuses make into thinking a .o | |
863 | file that happens to exist is up-to-date. */ | |
a182c763 | 864 | static const char *cpp_unique_options = |
fd6f6435 | 865 | "%{C|CC:%{!E:%eGCC does not support -C or -CC without -E}}\ |
065e625b | 866 | %{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\ |
eb95e7f7 | 867 | %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ |
868 | %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ | |
869 | %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ | |
e238d235 | 870 | %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ |
a8c200f7 | 871 | %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\ |
872 | %{H} %C %{D*&U*&A*} %{i*} %Z %i\ | |
4ee9c684 | 873 | %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\ |
874 | %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\ | |
5ca8af9f | 875 | %{E|M|MM:%W{o*}}"; |
a182c763 | 876 | |
877 | /* This contains cpp options which are common with cc1_options and are passed | |
39c188c5 | 878 | only when preprocessing only to avoid duplication. We pass the cc1 spec |
879 | options to the preprocessor so that it the cc1 spec may manipulate | |
880 | options used to set target flags. Those special target flags settings may | |
881 | in turn cause preprocessor symbols to be defined specially. */ | |
a182c763 | 882 | static const char *cpp_options = |
52367767 | 883 | "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ |
cbf55437 | 884 | %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\ |
cc92bc82 | 885 | %{undef} %{save-temps*:-fpch-preprocess}"; |
1cf79a1a | 886 | |
4702fc25 | 887 | /* This contains cpp options which are not passed when the preprocessor |
888 | output will be used by another program. */ | |
889 | static const char *cpp_debug_options = "%{d*}"; | |
890 | ||
68f4c740 | 891 | /* NB: This is shared amongst all front-ends, except for Ada. */ |
1cf79a1a | 892 | static const char *cc1_options = |
893 | "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ | |
894 | %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\ | |
71278019 | 895 | %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \ |
896 | %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \ | |
52367767 | 897 | %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\ |
1ed9d5f5 | 898 | %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\ |
05dfd2e8 | 899 | %{Qn:-fno-ident} %{--help:--help}\ |
7a6882ca | 900 | %{--target-help:--target-help}\ |
87c75316 | 901 | %{--help=*:--help=%(VALUE)}\ |
655a58fa | 902 | %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\ |
4ee9c684 | 903 | %{fsyntax-only:-o %j} %{-param*}\ |
2c669579 | 904 | %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\ |
905 | %{coverage:-fprofile-arcs -ftest-coverage}"; | |
1cf79a1a | 906 | |
907 | static const char *asm_options = | |
c6429fa9 | 908 | "%{--target-help:%:print-asm-header()} " |
909 | #if HAVE_GNU_AS | |
910 | /* If GNU AS is used, then convert -w (no warnings), -I, and -v | |
911 | to the assembler equivalents. */ | |
912 | "%{v} %{w:-W} %{I*} " | |
913 | #endif | |
914 | "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}"; | |
709c4e1b | 915 | |
99b02af1 | 916 | static const char *invoke_as = |
805e22b2 | 917 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
7bfefa9d | 918 | "%{!fwpa:\ |
919 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ | |
920 | %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\ | |
921 | }"; | |
805e22b2 | 922 | #else |
7bfefa9d | 923 | "%{!fwpa:\ |
924 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ | |
925 | %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\ | |
926 | }"; | |
805e22b2 | 927 | #endif |
99b02af1 | 928 | |
709c4e1b | 929 | /* Some compilers have limits on line lengths, and the multilib_select |
3d97d965 | 930 | and/or multilib_matches strings can be very long, so we build them at |
931 | run time. */ | |
709c4e1b | 932 | static struct obstack multilib_obstack; |
e772a198 | 933 | static const char *multilib_select; |
934 | static const char *multilib_matches; | |
935 | static const char *multilib_defaults; | |
936 | static const char *multilib_exclusions; | |
3d97d965 | 937 | |
938 | /* Check whether a particular argument is a default argument. */ | |
939 | ||
940 | #ifndef MULTILIB_DEFAULTS | |
941 | #define MULTILIB_DEFAULTS { "" } | |
942 | #endif | |
943 | ||
026f2c7a | 944 | static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS; |
d7a9644e | 945 | |
73023f49 | 946 | #ifndef DRIVER_SELF_SPECS |
947 | #define DRIVER_SELF_SPECS "" | |
948 | #endif | |
949 | ||
1e8e9920 | 950 | /* Adding -fopenmp should imply pthreads. This is particularly important |
951 | for targets that use different start files and suchlike. */ | |
952 | #ifndef GOMP_SELF_SPECS | |
061202f8 | 953 | #define GOMP_SELF_SPECS "%{fopenmp|ftree-parallelize-loops=*: -pthread}" |
1e8e9920 | 954 | #endif |
955 | ||
956 | static const char *const driver_self_specs[] = { | |
9845d120 | 957 | "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns", |
1e8e9920 | 958 | DRIVER_SELF_SPECS, GOMP_SELF_SPECS |
959 | }; | |
73023f49 | 960 | |
7dd97ab6 | 961 | #ifndef OPTION_DEFAULT_SPECS |
962 | #define OPTION_DEFAULT_SPECS { "", "" } | |
963 | #endif | |
964 | ||
965 | struct default_spec | |
966 | { | |
967 | const char *name; | |
968 | const char *spec; | |
969 | }; | |
970 | ||
971 | static const struct default_spec | |
972 | option_default_specs[] = { OPTION_DEFAULT_SPECS }; | |
973 | ||
d4ea3b1f | 974 | struct user_specs |
975 | { | |
9d70d39c | 976 | struct user_specs *next; |
e40d43cc | 977 | const char *filename; |
9d70d39c | 978 | }; |
979 | ||
980 | static struct user_specs *user_specs_head, *user_specs_tail; | |
981 | ||
2648b739 | 982 | #ifndef SWITCH_TAKES_ARG |
983 | #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR) | |
d7a9644e | 984 | #endif |
985 | ||
b5d8f44c | 986 | #ifndef WORD_SWITCH_TAKES_ARG |
987 | #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR) | |
d7a9644e | 988 | #endif |
989 | \f | |
10f57222 | 990 | #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX |
42fe96d7 | 991 | /* This defines which switches stop a full compilation. */ |
992 | #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \ | |
a2000777 | 993 | ((CHAR) == 'c' || (CHAR) == 'S' || (CHAR) == 'E') |
42fe96d7 | 994 | |
995 | #ifndef SWITCH_CURTAILS_COMPILATION | |
996 | #define SWITCH_CURTAILS_COMPILATION(CHAR) \ | |
997 | DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) | |
998 | #endif | |
999 | #endif | |
1000 | ||
d7a9644e | 1001 | /* Record the mapping from file suffixes for compilation specs. */ |
1002 | ||
1003 | struct compiler | |
1004 | { | |
e40d43cc | 1005 | const char *suffix; /* Use this compiler for input files |
d7a9644e | 1006 | whose names end in this suffix. */ |
6db05d3a | 1007 | |
1cf79a1a | 1008 | const char *spec; /* To use this compiler, run this spec. */ |
96842e40 | 1009 | |
1010 | const char *cpp_spec; /* If non-NULL, substitute this spec | |
1011 | for `%C', rather than the usual | |
1012 | cpp_spec. */ | |
365db11e | 1013 | const int combinable; /* If nonzero, compiler can deal with |
dc1dd09b | 1014 | multiple source files at once (IMA). */ |
365db11e | 1015 | const int needs_preprocessing; /* If nonzero, source files need to |
dc1dd09b | 1016 | be run through a preprocessor. */ |
d7a9644e | 1017 | }; |
1018 | ||
1019 | /* Pointer to a vector of `struct compiler' that gives the spec for | |
1020 | compiling a file, based on its suffix. | |
1021 | A file that does not end in any of these suffixes will be passed | |
1022 | unchanged to the loader and nothing else will be done to it. | |
1023 | ||
1024 | An entry containing two 0s is used to terminate the vector. | |
1025 | ||
1026 | If multiple entries match a file, the last matching one is used. */ | |
1027 | ||
1028 | static struct compiler *compilers; | |
1029 | ||
1030 | /* Number of entries in `compilers', not counting the null terminator. */ | |
1031 | ||
1032 | static int n_compilers; | |
1033 | ||
1034 | /* The default list of file name suffixes and their compilation specs. */ | |
1035 | ||
c077395f | 1036 | static const struct compiler default_compilers[] = |
d7a9644e | 1037 | { |
6e8b4b1d | 1038 | /* Add lists of suffixes of known languages here. If those languages |
0dbd1c74 | 1039 | were not present when we built the driver, we will hit these copies |
1040 | and be given a more meaningful error than "file not used since | |
6e8b4b1d | 1041 | linking is not done". */ |
dc1dd09b | 1042 | {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0}, |
9728bde3 | 1043 | {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0}, |
1044 | {".mii", "#Objective-C++", 0, 0, 0}, | |
2f2c6aee | 1045 | {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, |
1046 | {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, | |
dc1dd09b | 1047 | {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, |
1048 | {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, | |
1049 | {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0}, | |
00c6e780 | 1050 | {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, |
1051 | {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, | |
1052 | {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0}, | |
1053 | {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0}, | |
1054 | {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, | |
1055 | {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0}, | |
1056 | {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0}, | |
1057 | {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0}, | |
dc1dd09b | 1058 | {".r", "#Ratfor", 0, 0, 0}, |
1059 | {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, | |
1060 | {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, | |
1061 | {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0}, | |
6e8b4b1d | 1062 | /* Next come the entries for C. */ |
dc1dd09b | 1063 | {".c", "@c", 0, 1, 1}, |
d7a9644e | 1064 | {"@c", |
99b02af1 | 1065 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
455730ef | 1066 | external preprocessor if -save-temps is given. */ |
3ae4c9f3 | 1067 | "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
99b02af1 | 1068 | %{!E:%{!M:%{!MM:\ |
455730ef | 1069 | %{traditional|ftraditional:\ |
1070 | %eGNU C no longer supports -traditional without -E}\ | |
dc1dd09b | 1071 | %{!combine:\ |
cc92bc82 | 1072 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1073 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ | |
1074 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ | |
4e6a6999 | 1075 | %(cc1_options)}\ |
cc92bc82 | 1076 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
6f60f118 | 1077 | cc1 %(cpp_unique_options) %(cc1_options)}}}\ |
dc1dd09b | 1078 | %{!fsyntax-only:%(invoke_as)}} \ |
1079 | %{combine:\ | |
cc92bc82 | 1080 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1081 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i}}\ | |
1082 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ | |
dc1dd09b | 1083 | cc1 %(cpp_unique_options) %(cc1_options)}}\ |
1084 | %{!fsyntax-only:%(invoke_as)}}}}}}", 0, 1, 1}, | |
d7a9644e | 1085 | {"-", |
a5050534 | 1086 | "%{!E:%e-E or -x required when input is from standard input}\ |
dc1dd09b | 1087 | %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0}, |
1088 | {".h", "@c-header", 0, 0, 0}, | |
d7a9644e | 1089 | {"@c-header", |
573aba85 | 1090 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
1091 | external preprocessor if -save-temps is given. */ | |
1092 | "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ | |
1093 | %{!E:%{!M:%{!MM:\ | |
cc92bc82 | 1094 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1095 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ | |
1096 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ | |
4e6a6999 | 1097 | %(cc1_options)\ |
49045bb4 | 1098 | -o %g.s %{!o*:--output-pch=%i.gch}\ |
573aba85 | 1099 | %W{o*:--output-pch=%*}%V}\ |
cc92bc82 | 1100 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
573aba85 | 1101 | cc1 %(cpp_unique_options) %(cc1_options)\ |
49045bb4 | 1102 | -o %g.s %{!o*:--output-pch=%i.gch}\ |
dc1dd09b | 1103 | %W{o*:--output-pch=%*}%V}}}}}}", 0, 0, 0}, |
1104 | {".i", "@cpp-output", 0, 1, 0}, | |
d7a9644e | 1105 | {"@cpp-output", |
f0fad829 | 1106 | "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 1, 0}, |
dc1dd09b | 1107 | {".s", "@assembler", 0, 1, 0}, |
d7a9644e | 1108 | {"@assembler", |
dc1dd09b | 1109 | "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 1, 0}, |
eaf43256 | 1110 | {".sx", "@assembler-with-cpp", 0, 1, 0}, |
dc1dd09b | 1111 | {".S", "@assembler-with-cpp", 0, 1, 0}, |
d7a9644e | 1112 | {"@assembler-with-cpp", |
805e22b2 | 1113 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
8d3e018c | 1114 | "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
4702fc25 | 1115 | %{E|M|MM:%(cpp_debug_options)}\ |
805e22b2 | 1116 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
1117 | as %(asm_debug) %(asm_options) %|.s %A }}}}" | |
1118 | #else | |
8d3e018c | 1119 | "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
805e22b2 | 1120 | %{E|M|MM:%(cpp_debug_options)}\ |
1121 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ | |
1122 | as %(asm_debug) %(asm_options) %m.s %A }}}}" | |
1123 | #endif | |
dc1dd09b | 1124 | , 0, 1, 0}, |
952f0048 | 1125 | |
45b17600 | 1126 | #include "specs.h" |
2358393e | 1127 | /* Mark end of table. */ |
dc1dd09b | 1128 | {0, 0, 0, 0, 0} |
d7a9644e | 1129 | }; |
1130 | ||
1131 | /* Number of elements in default_compilers, not counting the terminator. */ | |
1132 | ||
3585dac7 | 1133 | static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1; |
d7a9644e | 1134 | |
d7a9644e | 1135 | /* A vector of options to give to the linker. |
fcdc45aa | 1136 | These options are accumulated by %x, |
d7a9644e | 1137 | and substituted into the linker command with %X. */ |
1138 | static int n_linker_options; | |
1139 | static char **linker_options; | |
69587571 | 1140 | |
1141 | /* A vector of options to give to the assembler. | |
1142 | These options are accumulated by -Wa, | |
391d9b6e | 1143 | and substituted into the assembler command with %Y. */ |
69587571 | 1144 | static int n_assembler_options; |
1145 | static char **assembler_options; | |
391d9b6e | 1146 | |
1147 | /* A vector of options to give to the preprocessor. | |
1148 | These options are accumulated by -Wp, | |
1149 | and substituted into the preprocessor command with %Z. */ | |
1150 | static int n_preprocessor_options; | |
1151 | static char **preprocessor_options; | |
d7a9644e | 1152 | \f |
62daf19f | 1153 | /* Define how to map long options into short ones. */ |
1154 | ||
1155 | /* This structure describes one mapping. */ | |
1156 | struct option_map | |
1157 | { | |
1158 | /* The long option's name. */ | |
e99c3a1d | 1159 | const char *const name; |
62daf19f | 1160 | /* The equivalent short option. */ |
e99c3a1d | 1161 | const char *const equivalent; |
62daf19f | 1162 | /* Argument info. A string of flag chars; NULL equals no options. |
1163 | a => argument required. | |
1164 | o => argument optional. | |
1165 | j => join argument to equivalent, making one word. | |
873b55ec | 1166 | * => require other text after NAME as an argument. */ |
e99c3a1d | 1167 | const char *const arg_info; |
62daf19f | 1168 | }; |
1169 | ||
1170 | /* This is the table of mappings. Mappings are tried sequentially | |
1171 | for each option encountered; the first one that matches, wins. */ | |
1172 | ||
e99c3a1d | 1173 | static const struct option_map option_map[] = |
62daf19f | 1174 | { |
873b55ec | 1175 | {"--all-warnings", "-Wall", 0}, |
1176 | {"--ansi", "-ansi", 0}, | |
1177 | {"--assemble", "-S", 0}, | |
1178 | {"--assert", "-A", "a"}, | |
f95cdfd1 | 1179 | {"--classpath", "-fclasspath=", "aj"}, |
5609b23b | 1180 | {"--bootclasspath", "-fbootclasspath=", "aj"}, |
1181 | {"--CLASSPATH", "-fclasspath=", "aj"}, | |
dc1dd09b | 1182 | {"--combine", "-combine", 0}, |
873b55ec | 1183 | {"--comments", "-C", 0}, |
d3f7919d | 1184 | {"--comments-in-macros", "-CC", 0}, |
62daf19f | 1185 | {"--compile", "-c", 0}, |
873b55ec | 1186 | {"--debug", "-g", "oj"}, |
60572824 | 1187 | {"--define-macro", "-D", "aj"}, |
873b55ec | 1188 | {"--dependencies", "-M", 0}, |
62daf19f | 1189 | {"--dump", "-d", "a"}, |
873b55ec | 1190 | {"--dumpbase", "-dumpbase", "a"}, |
0ad8600e | 1191 | {"--encoding", "-fencoding=", "aj"}, |
62daf19f | 1192 | {"--entry", "-e", 0}, |
873b55ec | 1193 | {"--extra-warnings", "-W", 0}, |
0ad8600e | 1194 | {"--extdirs", "-fextdirs=", "aj"}, |
873b55ec | 1195 | {"--for-assembler", "-Wa", "a"}, |
1196 | {"--for-linker", "-Xlinker", "a"}, | |
1197 | {"--force-link", "-u", "a"}, | |
2c669579 | 1198 | {"--coverage", "-coverage", 0}, |
62daf19f | 1199 | {"--imacros", "-imacros", "a"}, |
873b55ec | 1200 | {"--include", "-include", "a"}, |
1201 | {"--include-barrier", "-I-", 0}, | |
60572824 | 1202 | {"--include-directory", "-I", "aj"}, |
62daf19f | 1203 | {"--include-directory-after", "-idirafter", "a"}, |
873b55ec | 1204 | {"--include-prefix", "-iprefix", "a"}, |
62daf19f | 1205 | {"--include-with-prefix", "-iwithprefix", "a"}, |
f3500718 | 1206 | {"--include-with-prefix-before", "-iwithprefixbefore", "a"}, |
1207 | {"--include-with-prefix-after", "-iwithprefix", "a"}, | |
873b55ec | 1208 | {"--language", "-x", "a"}, |
1209 | {"--library-directory", "-L", "a"}, | |
62daf19f | 1210 | {"--machine", "-m", "aj"}, |
873b55ec | 1211 | {"--machine-", "-m", "*j"}, |
d05a1771 | 1212 | {"--no-canonical-prefixes", "-no-canonical-prefixes", 0}, |
6f60f118 | 1213 | {"--no-integrated-cpp", "-no-integrated-cpp", 0}, |
873b55ec | 1214 | {"--no-line-commands", "-P", 0}, |
1215 | {"--no-precompiled-includes", "-noprecomp", 0}, | |
62daf19f | 1216 | {"--no-standard-includes", "-nostdinc", 0}, |
1217 | {"--no-standard-libraries", "-nostdlib", 0}, | |
62daf19f | 1218 | {"--no-warnings", "-w", 0}, |
62daf19f | 1219 | {"--optimize", "-O", "oj"}, |
873b55ec | 1220 | {"--output", "-o", "a"}, |
701f1a96 | 1221 | {"--output-class-directory", "-foutput-class-dir=", "ja"}, |
833a5c07 | 1222 | {"--param", "--param", "a"}, |
6fb1c485 | 1223 | {"--pass-exit-codes", "-pass-exit-codes", 0}, |
62daf19f | 1224 | {"--pedantic", "-pedantic", 0}, |
1225 | {"--pedantic-errors", "-pedantic-errors", 0}, | |
c3ce66b0 | 1226 | {"--pie", "-pie", 0}, |
873b55ec | 1227 | {"--pipe", "-pipe", 0}, |
1228 | {"--prefix", "-B", "a"}, | |
1229 | {"--preprocess", "-E", 0}, | |
71cee7b1 | 1230 | {"--print-search-dirs", "-print-search-dirs", 0}, |
1c1a1c70 | 1231 | {"--print-file-name", "-print-file-name=", "aj"}, |
873b55ec | 1232 | {"--print-libgcc-file-name", "-print-libgcc-file-name", 0}, |
1233 | {"--print-missing-file-dependencies", "-MG", 0}, | |
9577d478 | 1234 | {"--print-multi-lib", "-print-multi-lib", 0}, |
1235 | {"--print-multi-directory", "-print-multi-directory", 0}, | |
c954ff02 | 1236 | {"--print-multi-os-directory", "-print-multi-os-directory", 0}, |
873b55ec | 1237 | {"--print-prog-name", "-print-prog-name=", "aj"}, |
098cc23f | 1238 | {"--print-sysroot", "-print-sysroot", 0}, |
6ea4242f | 1239 | {"--print-sysroot-headers-suffix", "-print-sysroot-headers-suffix", 0}, |
873b55ec | 1240 | {"--profile", "-p", 0}, |
1241 | {"--profile-blocks", "-a", 0}, | |
1242 | {"--quiet", "-q", 0}, | |
39471a6e | 1243 | {"--resource", "-fcompile-resource=", "aj"}, |
873b55ec | 1244 | {"--save-temps", "-save-temps", 0}, |
62daf19f | 1245 | {"--shared", "-shared", 0}, |
873b55ec | 1246 | {"--silent", "-q", 0}, |
9d70d39c | 1247 | {"--specs", "-specs=", "aj"}, |
873b55ec | 1248 | {"--static", "-static", 0}, |
75bd5ada | 1249 | {"--std", "-std=", "aj"}, |
62daf19f | 1250 | {"--symbolic", "-symbolic", 0}, |
2f2c6aee | 1251 | {"--sysroot", "--sysroot=", "aj"}, |
a876e5f8 | 1252 | {"--time", "-time", 0}, |
873b55ec | 1253 | {"--trace-includes", "-H", 0}, |
1254 | {"--traditional", "-traditional", 0}, | |
1255 | {"--traditional-cpp", "-traditional-cpp", 0}, | |
1256 | {"--trigraphs", "-trigraphs", 0}, | |
60572824 | 1257 | {"--undefine-macro", "-U", "aj"}, |
873b55ec | 1258 | {"--user-dependencies", "-MM", 0}, |
1259 | {"--verbose", "-v", 0}, | |
873b55ec | 1260 | {"--warn-", "-W", "*j"}, |
1261 | {"--write-dependencies", "-MD", 0}, | |
1262 | {"--write-user-dependencies", "-MMD", 0}, | |
62daf19f | 1263 | {"--", "-f", "*j"} |
1264 | }; | |
1265 | \f | |
522355d9 | 1266 | |
1267 | #ifdef TARGET_OPTION_TRANSLATE_TABLE | |
e99c3a1d | 1268 | static const struct { |
1269 | const char *const option_found; | |
1270 | const char *const replacements; | |
522355d9 | 1271 | } target_option_translations[] = |
1272 | { | |
1273 | TARGET_OPTION_TRANSLATE_TABLE, | |
1274 | { 0, 0 } | |
1275 | }; | |
1276 | #endif | |
1277 | ||
62daf19f | 1278 | /* Translate the options described by *ARGCP and *ARGVP. |
1279 | Make a new vector and store it back in *ARGVP, | |
f0b5f617 | 1280 | and store its length in *ARGCP. */ |
62daf19f | 1281 | |
1282 | static void | |
952f0048 | 1283 | translate_options (int *argcp, const char *const **argvp) |
62daf19f | 1284 | { |
274c11d8 | 1285 | int i; |
62daf19f | 1286 | int argc = *argcp; |
826f6505 | 1287 | const char *const *argv = *argvp; |
522355d9 | 1288 | int newvsize = (argc + 2) * 2 * sizeof (const char *); |
25a1c410 | 1289 | const char **newv = XNEWVAR (const char *, newvsize); |
62daf19f | 1290 | int newindex = 0; |
1291 | ||
1292 | i = 0; | |
1293 | newv[newindex++] = argv[i++]; | |
1294 | ||
1295 | while (i < argc) | |
1296 | { | |
522355d9 | 1297 | #ifdef TARGET_OPTION_TRANSLATE_TABLE |
1298 | int tott_idx; | |
1299 | ||
1300 | for (tott_idx = 0; | |
1301 | target_option_translations[tott_idx].option_found; | |
1302 | tott_idx++) | |
1303 | { | |
1304 | if (strcmp (target_option_translations[tott_idx].option_found, | |
1305 | argv[i]) == 0) | |
1306 | { | |
1307 | int spaces = 1; | |
1308 | const char *sp; | |
1309 | char *np; | |
1310 | ||
1311 | for (sp = target_option_translations[tott_idx].replacements; | |
1312 | *sp; sp++) | |
1313 | { | |
1314 | if (*sp == ' ') | |
1315 | spaces ++; | |
1316 | } | |
1317 | ||
1318 | newvsize += spaces * sizeof (const char *); | |
225ab426 | 1319 | newv = XRESIZEVAR (const char *, newv, newvsize); |
522355d9 | 1320 | |
1321 | sp = target_option_translations[tott_idx].replacements; | |
47950139 | 1322 | np = xstrdup (sp); |
522355d9 | 1323 | |
1324 | while (1) | |
1325 | { | |
1326 | while (*np == ' ') | |
1327 | np++; | |
1328 | if (*np == 0) | |
1329 | break; | |
1330 | newv[newindex++] = np; | |
1331 | while (*np != ' ' && *np) | |
1332 | np++; | |
1333 | if (*np == 0) | |
1334 | break; | |
1335 | *np++ = 0; | |
1336 | } | |
1337 | ||
1338 | i ++; | |
1339 | break; | |
1340 | } | |
1341 | } | |
1342 | if (target_option_translations[tott_idx].option_found) | |
1343 | continue; | |
1344 | #endif | |
1345 | ||
62daf19f | 1346 | /* Translate -- options. */ |
1347 | if (argv[i][0] == '-' && argv[i][1] == '-') | |
1348 | { | |
274c11d8 | 1349 | size_t j; |
62daf19f | 1350 | /* Find a mapping that applies to this option. */ |
3098b2d3 | 1351 | for (j = 0; j < ARRAY_SIZE (option_map); j++) |
62daf19f | 1352 | { |
8a1f692f | 1353 | size_t optlen = strlen (option_map[j].name); |
1354 | size_t arglen = strlen (argv[i]); | |
1355 | size_t complen = arglen > optlen ? optlen : arglen; | |
e40d43cc | 1356 | const char *arginfo = option_map[j].arg_info; |
9ef4d1af | 1357 | |
1358 | if (arginfo == 0) | |
1359 | arginfo = ""; | |
873b55ec | 1360 | |
62daf19f | 1361 | if (!strncmp (argv[i], option_map[j].name, complen)) |
1362 | { | |
e40d43cc | 1363 | const char *arg = 0; |
62daf19f | 1364 | |
873b55ec | 1365 | if (arglen < optlen) |
1366 | { | |
274c11d8 | 1367 | size_t k; |
3098b2d3 | 1368 | for (k = j + 1; k < ARRAY_SIZE (option_map); k++) |
873b55ec | 1369 | if (strlen (option_map[k].name) >= arglen |
1370 | && !strncmp (argv[i], option_map[k].name, arglen)) | |
1371 | { | |
cb8bacb6 | 1372 | error ("ambiguous abbreviation %s", argv[i]); |
873b55ec | 1373 | break; |
1374 | } | |
1375 | ||
3098b2d3 | 1376 | if (k != ARRAY_SIZE (option_map)) |
873b55ec | 1377 | break; |
1378 | } | |
1379 | ||
1380 | if (arglen > optlen) | |
62daf19f | 1381 | { |
1382 | /* If the option has an argument, accept that. */ | |
1383 | if (argv[i][optlen] == '=') | |
1384 | arg = argv[i] + optlen + 1; | |
873b55ec | 1385 | |
1386 | /* If this mapping requires extra text at end of name, | |
62daf19f | 1387 | accept that as "argument". */ |
78dbff7c | 1388 | else if (strchr (arginfo, '*') != 0) |
62daf19f | 1389 | arg = argv[i] + optlen; |
873b55ec | 1390 | |
62daf19f | 1391 | /* Otherwise, extra text at end means mismatch. |
1392 | Try other mappings. */ | |
1393 | else | |
1394 | continue; | |
1395 | } | |
873b55ec | 1396 | |
78dbff7c | 1397 | else if (strchr (arginfo, '*') != 0) |
873b55ec | 1398 | { |
1e5fcbe2 | 1399 | error ("incomplete '%s' option", option_map[j].name); |
873b55ec | 1400 | break; |
1401 | } | |
62daf19f | 1402 | |
1403 | /* Handle arguments. */ | |
78dbff7c | 1404 | if (strchr (arginfo, 'a') != 0) |
62daf19f | 1405 | { |
1406 | if (arg == 0) | |
1407 | { | |
1408 | if (i + 1 == argc) | |
873b55ec | 1409 | { |
1e5fcbe2 | 1410 | error ("missing argument to '%s' option", |
873b55ec | 1411 | option_map[j].name); |
1412 | break; | |
1413 | } | |
1414 | ||
62daf19f | 1415 | arg = argv[++i]; |
1416 | } | |
1417 | } | |
78dbff7c | 1418 | else if (strchr (arginfo, '*') != 0) |
b9c6f437 | 1419 | ; |
78dbff7c | 1420 | else if (strchr (arginfo, 'o') == 0) |
62daf19f | 1421 | { |
1422 | if (arg != 0) | |
1e5fcbe2 | 1423 | error ("extraneous argument to '%s' option", |
62daf19f | 1424 | option_map[j].name); |
1425 | arg = 0; | |
1426 | } | |
1427 | ||
1428 | /* Store the translation as one argv elt or as two. */ | |
78dbff7c | 1429 | if (arg != 0 && strchr (arginfo, 'j') != 0) |
3441e5dd | 1430 | newv[newindex++] = concat (option_map[j].equivalent, arg, |
4e2023c8 | 1431 | NULL); |
62daf19f | 1432 | else if (arg != 0) |
1433 | { | |
1434 | newv[newindex++] = option_map[j].equivalent; | |
1435 | newv[newindex++] = arg; | |
1436 | } | |
1437 | else | |
1438 | newv[newindex++] = option_map[j].equivalent; | |
1439 | ||
1440 | break; | |
1441 | } | |
1442 | } | |
1443 | i++; | |
1444 | } | |
873b55ec | 1445 | |
62daf19f | 1446 | /* Handle old-fashioned options--just copy them through, |
1447 | with their arguments. */ | |
1448 | else if (argv[i][0] == '-') | |
1449 | { | |
e40d43cc | 1450 | const char *p = argv[i] + 1; |
62daf19f | 1451 | int c = *p; |
1452 | int nskip = 1; | |
1453 | ||
1454 | if (SWITCH_TAKES_ARG (c) > (p[1] != 0)) | |
1455 | nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0); | |
1456 | else if (WORD_SWITCH_TAKES_ARG (p)) | |
1457 | nskip += WORD_SWITCH_TAKES_ARG (p); | |
0d52bda0 | 1458 | else if ((c == 'B' || c == 'b' || c == 'x') |
f39cf4ce | 1459 | && p[1] == 0) |
1460 | nskip += 1; | |
1461 | else if (! strcmp (p, "Xlinker")) | |
1462 | nskip += 1; | |
805e22b2 | 1463 | else if (! strcmp (p, "Xpreprocessor")) |
1464 | nskip += 1; | |
1465 | else if (! strcmp (p, "Xassembler")) | |
1466 | nskip += 1; | |
62daf19f | 1467 | |
9a1a1063 | 1468 | /* Watch out for an option at the end of the command line that |
1469 | is missing arguments, and avoid skipping past the end of the | |
1470 | command line. */ | |
1471 | if (nskip + i > argc) | |
1472 | nskip = argc - i; | |
1473 | ||
62daf19f | 1474 | while (nskip > 0) |
1475 | { | |
1476 | newv[newindex++] = argv[i++]; | |
1477 | nskip--; | |
1478 | } | |
1479 | } | |
1480 | else | |
1481 | /* Ordinary operands, or +e options. */ | |
1482 | newv[newindex++] = argv[i++]; | |
1483 | } | |
1484 | ||
1485 | newv[newindex] = 0; | |
1486 | ||
1487 | *argvp = newv; | |
1488 | *argcp = newindex; | |
1489 | } | |
1490 | \f | |
d7a9644e | 1491 | static char * |
952f0048 | 1492 | skip_whitespace (char *p) |
d7a9644e | 1493 | { |
1494 | while (1) | |
1495 | { | |
1496 | /* A fully-blank line is a delimiter in the SPEC file and shouldn't | |
1497 | be considered whitespace. */ | |
1498 | if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') | |
1499 | return p + 1; | |
1500 | else if (*p == '\n' || *p == ' ' || *p == '\t') | |
1501 | p++; | |
1502 | else if (*p == '#') | |
1503 | { | |
026f2c7a | 1504 | while (*p != '\n') |
1505 | p++; | |
d7a9644e | 1506 | p++; |
1507 | } | |
1508 | else | |
1509 | break; | |
1510 | } | |
1511 | ||
1512 | return p; | |
1513 | } | |
bfb9bc39 | 1514 | /* Structures to keep track of prefixes to try when looking for files. */ |
1515 | ||
1516 | struct prefix_list | |
1517 | { | |
afe739a7 | 1518 | const char *prefix; /* String to prepend to the path. */ |
bfb9bc39 | 1519 | struct prefix_list *next; /* Next in linked list. */ |
1520 | int require_machine_suffix; /* Don't use without machine_suffix. */ | |
1521 | /* 2 means try both machine_suffix and just_machine_suffix. */ | |
c954ff02 | 1522 | int priority; /* Sort key - priority within list. */ |
1523 | int os_multilib; /* 1 if OS multilib scheme should be used, | |
1524 | 0 for GCC multilib scheme. */ | |
bfb9bc39 | 1525 | }; |
1526 | ||
1527 | struct path_prefix | |
1528 | { | |
1529 | struct prefix_list *plist; /* List of prefixes to try */ | |
1530 | int max_len; /* Max length of a prefix in PLIST */ | |
1531 | const char *name; /* Name of this list (used in config stuff) */ | |
1532 | }; | |
1533 | ||
1534 | /* List of prefixes to try when looking for executables. */ | |
1535 | ||
1536 | static struct path_prefix exec_prefixes = { 0, 0, "exec" }; | |
1537 | ||
1538 | /* List of prefixes to try when looking for startup (crt0) files. */ | |
1539 | ||
1540 | static struct path_prefix startfile_prefixes = { 0, 0, "startfile" }; | |
1541 | ||
1542 | /* List of prefixes to try when looking for include files. */ | |
1543 | ||
1544 | static struct path_prefix include_prefixes = { 0, 0, "include" }; | |
1545 | ||
1546 | /* Suffix to attach to directories searched for commands. | |
1547 | This looks like `MACHINE/VERSION/'. */ | |
1548 | ||
1549 | static const char *machine_suffix = 0; | |
1550 | ||
1551 | /* Suffix to attach to directories searched for commands. | |
1552 | This is just `MACHINE/'. */ | |
1553 | ||
1554 | static const char *just_machine_suffix = 0; | |
1555 | ||
1556 | /* Adjusted value of GCC_EXEC_PREFIX envvar. */ | |
1557 | ||
1558 | static const char *gcc_exec_prefix; | |
1559 | ||
9db45a87 | 1560 | /* Adjusted value of standard_libexec_prefix. */ |
1561 | ||
1562 | static const char *gcc_libexec_prefix; | |
1563 | ||
bfb9bc39 | 1564 | /* Default prefixes to attach to command names. */ |
1565 | ||
3c2ba0de | 1566 | #ifndef STANDARD_STARTFILE_PREFIX_1 |
1567 | #define STANDARD_STARTFILE_PREFIX_1 "/lib/" | |
1568 | #endif | |
1569 | #ifndef STANDARD_STARTFILE_PREFIX_2 | |
1570 | #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" | |
1571 | #endif | |
2f2c6aee | 1572 | |
29d774d0 | 1573 | #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */ |
bfb9bc39 | 1574 | #undef MD_EXEC_PREFIX |
1575 | #undef MD_STARTFILE_PREFIX | |
1576 | #undef MD_STARTFILE_PREFIX_1 | |
1577 | #endif | |
1578 | ||
1579 | /* If no prefixes defined, use the null string, which will disable them. */ | |
1580 | #ifndef MD_EXEC_PREFIX | |
1581 | #define MD_EXEC_PREFIX "" | |
1582 | #endif | |
1583 | #ifndef MD_STARTFILE_PREFIX | |
1584 | #define MD_STARTFILE_PREFIX "" | |
1585 | #endif | |
1586 | #ifndef MD_STARTFILE_PREFIX_1 | |
1587 | #define MD_STARTFILE_PREFIX_1 "" | |
1588 | #endif | |
1589 | ||
c4328bcc | 1590 | /* These directories are locations set at configure-time based on the |
1591 | --prefix option provided to configure. Their initializers are | |
1592 | defined in Makefile.in. These paths are not *directly* used when | |
1593 | gcc_exec_prefix is set because, in that case, we know where the | |
1594 | compiler has been installed, and use paths relative to that | |
1595 | location instead. */ | |
35823b64 | 1596 | static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX; |
c4328bcc | 1597 | static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX; |
1598 | static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX; | |
1599 | static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; | |
1600 | ||
1601 | /* For native compilers, these are well-known paths containing | |
1602 | components that may be provided by the system. For cross | |
1603 | compilers, these paths are not used. */ | |
bfb9bc39 | 1604 | static const char *md_exec_prefix = MD_EXEC_PREFIX; |
bfb9bc39 | 1605 | static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; |
1606 | static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; | |
87c75316 | 1607 | static const char *const standard_startfile_prefix_1 |
3c2ba0de | 1608 | = STANDARD_STARTFILE_PREFIX_1; |
1609 | static const char *const standard_startfile_prefix_2 | |
1610 | = STANDARD_STARTFILE_PREFIX_2; | |
bfb9bc39 | 1611 | |
c4328bcc | 1612 | /* A relative path to be used in finding the location of tools |
1613 | relative to the driver. */ | |
35823b64 | 1614 | static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX; |
9db45a87 | 1615 | |
bfb9bc39 | 1616 | /* Subdirectory to use for locating libraries. Set by |
1617 | set_multilib_dir based on the compilation options. */ | |
1618 | ||
1619 | static const char *multilib_dir; | |
c954ff02 | 1620 | |
1621 | /* Subdirectory to use for locating libraries in OS conventions. Set by | |
1622 | set_multilib_dir based on the compilation options. */ | |
1623 | ||
1624 | static const char *multilib_os_dir; | |
d7a9644e | 1625 | \f |
a92771b8 | 1626 | /* Structure to keep track of the specs that have been defined so far. |
50bcc52e | 1627 | These are accessed using %(specname) or %[specname] in a compiler |
1628 | or link spec. */ | |
d7a9644e | 1629 | |
1630 | struct spec_list | |
1631 | { | |
988c0ffe | 1632 | /* The following 2 fields must be first */ |
1633 | /* to allow EXTRA_SPECS to be initialized */ | |
e772a198 | 1634 | const char *name; /* name of the spec. */ |
1635 | const char *ptr; /* available ptr if no static pointer */ | |
988c0ffe | 1636 | |
1637 | /* The following fields are not initialized */ | |
1638 | /* by EXTRA_SPECS */ | |
e772a198 | 1639 | const char **ptr_spec; /* pointer to the spec itself. */ |
988c0ffe | 1640 | struct spec_list *next; /* Next spec in linked list. */ |
1641 | int name_len; /* length of the name */ | |
1642 | int alloc_p; /* whether string was allocated */ | |
d7a9644e | 1643 | }; |
1644 | ||
988c0ffe | 1645 | #define INIT_STATIC_SPEC(NAME,PTR) \ |
d946ea19 | 1646 | { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 } |
988c0ffe | 1647 | |
d4ea3b1f | 1648 | /* List of statically defined specs. */ |
1649 | static struct spec_list static_specs[] = | |
1650 | { | |
988c0ffe | 1651 | INIT_STATIC_SPEC ("asm", &asm_spec), |
1a6f9700 | 1652 | INIT_STATIC_SPEC ("asm_debug", &asm_debug), |
988c0ffe | 1653 | INIT_STATIC_SPEC ("asm_final", &asm_final_spec), |
1cf79a1a | 1654 | INIT_STATIC_SPEC ("asm_options", &asm_options), |
99b02af1 | 1655 | INIT_STATIC_SPEC ("invoke_as", &invoke_as), |
988c0ffe | 1656 | INIT_STATIC_SPEC ("cpp", &cpp_spec), |
1cf79a1a | 1657 | INIT_STATIC_SPEC ("cpp_options", &cpp_options), |
4702fc25 | 1658 | INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options), |
a182c763 | 1659 | INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options), |
1cf79a1a | 1660 | INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp), |
988c0ffe | 1661 | INIT_STATIC_SPEC ("cc1", &cc1_spec), |
1cf79a1a | 1662 | INIT_STATIC_SPEC ("cc1_options", &cc1_options), |
988c0ffe | 1663 | INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec), |
da98d114 | 1664 | INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec), |
0d55f4d0 | 1665 | INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec), |
988c0ffe | 1666 | INIT_STATIC_SPEC ("endfile", &endfile_spec), |
1667 | INIT_STATIC_SPEC ("link", &link_spec), | |
1668 | INIT_STATIC_SPEC ("lib", &lib_spec), | |
4ee9c684 | 1669 | INIT_STATIC_SPEC ("mfwrap", &mfwrap_spec), |
1670 | INIT_STATIC_SPEC ("mflib", &mflib_spec), | |
1e8e9920 | 1671 | INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec), |
988c0ffe | 1672 | INIT_STATIC_SPEC ("libgcc", &libgcc_spec), |
1673 | INIT_STATIC_SPEC ("startfile", &startfile_spec), | |
1674 | INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces), | |
988c0ffe | 1675 | INIT_STATIC_SPEC ("cross_compile", &cross_compile), |
1676 | INIT_STATIC_SPEC ("version", &compiler_version), | |
1677 | INIT_STATIC_SPEC ("multilib", &multilib_select), | |
1678 | INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults), | |
1679 | INIT_STATIC_SPEC ("multilib_extra", &multilib_extra), | |
1680 | INIT_STATIC_SPEC ("multilib_matches", &multilib_matches), | |
54518c3b | 1681 | INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions), |
c954ff02 | 1682 | INIT_STATIC_SPEC ("multilib_options", &multilib_options), |
0c787992 | 1683 | INIT_STATIC_SPEC ("linker", &linker_name_spec), |
7bfefa9d | 1684 | INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec), |
1685 | INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec), | |
1686 | INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec), | |
1687 | INIT_STATIC_SPEC ("lto_libgcc", <o_libgcc_spec), | |
1cf79a1a | 1688 | INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec), |
bfb9bc39 | 1689 | INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix), |
1690 | INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix), | |
1691 | INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1), | |
4ae4e5e8 | 1692 | INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec), |
b6bcc48f | 1693 | INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec), |
4ea70922 | 1694 | INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec), |
1695 | INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec), | |
988c0ffe | 1696 | }; |
1697 | ||
1698 | #ifdef EXTRA_SPECS /* additional specs needed */ | |
6b40eba4 | 1699 | /* Structure to keep track of just the first two args of a spec_list. |
d4ea3b1f | 1700 | That is all that the EXTRA_SPECS macro gives us. */ |
6b40eba4 | 1701 | struct spec_list_1 |
1702 | { | |
e99c3a1d | 1703 | const char *const name; |
1704 | const char *const ptr; | |
6b40eba4 | 1705 | }; |
1706 | ||
e99c3a1d | 1707 | static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS }; |
026f2c7a | 1708 | static struct spec_list *extra_specs = (struct spec_list *) 0; |
988c0ffe | 1709 | #endif |
1710 | ||
1711 | /* List of dynamically allocates specs that have been defined so far. */ | |
1712 | ||
2c815aff | 1713 | static struct spec_list *specs = (struct spec_list *) 0; |
988c0ffe | 1714 | \f |
c21b3276 | 1715 | /* List of static spec functions. */ |
1716 | ||
1717 | static const struct spec_function static_spec_functions[] = | |
1718 | { | |
0305c755 | 1719 | { "getenv", getenv_spec_function }, |
c21b3276 | 1720 | { "if-exists", if_exists_spec_function }, |
68d74c02 | 1721 | { "if-exists-else", if_exists_else_spec_function }, |
2288041e | 1722 | { "replace-outfile", replace_outfile_spec_function }, |
9b1f316f | 1723 | { "version-compare", version_compare_spec_function }, |
1e8e9920 | 1724 | { "include", include_spec_function }, |
ceac8e8c | 1725 | { "print-asm-header", print_asm_header_spec_function }, |
71278019 | 1726 | { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function }, |
1727 | { "compare-debug-self-opt", compare_debug_self_opt_spec_function }, | |
1728 | { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function }, | |
4009b53f | 1729 | #ifdef EXTRA_SPEC_FUNCTIONS |
1730 | EXTRA_SPEC_FUNCTIONS | |
1731 | #endif | |
c21b3276 | 1732 | { 0, 0 } |
1733 | }; | |
1734 | ||
1735 | static int processing_spec_function; | |
1736 | \f | |
5cb4c868 | 1737 | /* Add appropriate libgcc specs to OBSTACK, taking into account |
1738 | various permutations of -shared-libgcc, -shared, and such. */ | |
1739 | ||
ecbfdc87 | 1740 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
be4e8b82 | 1741 | |
1742 | #ifndef USE_LD_AS_NEEDED | |
1743 | #define USE_LD_AS_NEEDED 0 | |
1744 | #endif | |
1745 | ||
5cb4c868 | 1746 | static void |
952f0048 | 1747 | init_gcc_specs (struct obstack *obstack, const char *shared_name, |
1748 | const char *static_name, const char *eh_name) | |
5cb4c868 | 1749 | { |
48285a3c | 1750 | char *buf; |
1751 | ||
e885c832 | 1752 | buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}" |
1753 | "%{!static:%{!static-libgcc:" | |
be4e8b82 | 1754 | #if USE_LD_AS_NEEDED |
e885c832 | 1755 | "%{!shared-libgcc:", |
1756 | static_name, " --as-needed ", shared_name, " --no-as-needed" | |
1757 | "}" | |
1758 | "%{shared-libgcc:", | |
1759 | shared_name, "%{!shared: ", static_name, "}" | |
1760 | "}" | |
6a40149e | 1761 | #else |
e885c832 | 1762 | "%{!shared:" |
1763 | "%{!shared-libgcc:", static_name, " ", eh_name, "}" | |
1764 | "%{shared-libgcc:", shared_name, " ", static_name, "}" | |
1765 | "}" | |
0d6378a9 | 1766 | #ifdef LINK_EH_SPEC |
e885c832 | 1767 | "%{shared:" |
1768 | "%{shared-libgcc:", shared_name, "}" | |
1769 | "%{!shared-libgcc:", static_name, "}" | |
1770 | "}" | |
0d6378a9 | 1771 | #else |
e885c832 | 1772 | "%{shared:", shared_name, "}" |
6a40149e | 1773 | #endif |
0d6378a9 | 1774 | #endif |
e885c832 | 1775 | "}}", NULL); |
48285a3c | 1776 | |
1777 | obstack_grow (obstack, buf, strlen (buf)); | |
1778 | free (buf); | |
5cb4c868 | 1779 | } |
b51d5c7c | 1780 | #endif /* ENABLE_SHARED_LIBGCC */ |
5cb4c868 | 1781 | |
988c0ffe | 1782 | /* Initialize the specs lookup routines. */ |
1783 | ||
1784 | static void | |
a046944b | 1785 | init_spec (void) |
988c0ffe | 1786 | { |
2c815aff | 1787 | struct spec_list *next = (struct spec_list *) 0; |
1788 | struct spec_list *sl = (struct spec_list *) 0; | |
988c0ffe | 1789 | int i; |
1790 | ||
1791 | if (specs) | |
d4ea3b1f | 1792 | return; /* Already initialized. */ |
988c0ffe | 1793 | |
4582d741 | 1794 | if (verbose_flag) |
f4ec69cb | 1795 | notice ("Using built-in specs.\n"); |
4582d741 | 1796 | |
988c0ffe | 1797 | #ifdef EXTRA_SPECS |
25a1c410 | 1798 | extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1)); |
2c815aff | 1799 | |
3098b2d3 | 1800 | for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--) |
810309ce | 1801 | { |
1802 | sl = &extra_specs[i]; | |
6b40eba4 | 1803 | sl->name = extra_specs_1[i].name; |
1804 | sl->ptr = extra_specs_1[i].ptr; | |
810309ce | 1805 | sl->next = next; |
1806 | sl->name_len = strlen (sl->name); | |
1807 | sl->ptr_spec = &sl->ptr; | |
1808 | next = sl; | |
1809 | } | |
988c0ffe | 1810 | #endif |
1811 | ||
3098b2d3 | 1812 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
988c0ffe | 1813 | { |
1814 | sl = &static_specs[i]; | |
1815 | sl->next = next; | |
1816 | next = sl; | |
1817 | } | |
1818 | ||
ecbfdc87 | 1819 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
43198b29 | 1820 | /* ??? If neither -shared-libgcc nor --static-libgcc was |
1821 | seen, then we should be making an educated guess. Some proposed | |
1822 | heuristics for ELF include: | |
1823 | ||
1824 | (1) If "-Wl,--export-dynamic", then it's a fair bet that the | |
1825 | program will be doing dynamic loading, which will likely | |
1826 | need the shared libgcc. | |
1827 | ||
1828 | (2) If "-ldl", then it's also a fair bet that we're doing | |
1829 | dynamic loading. | |
1830 | ||
1831 | (3) For each ET_DYN we're linking against (either through -lfoo | |
1832 | or /some/path/foo.so), check to see whether it or one of | |
424da949 | 1833 | its dependencies depends on a shared libgcc. |
43198b29 | 1834 | |
1835 | (4) If "-shared" | |
1836 | ||
1837 | If the runtime is fixed to look for program headers instead | |
1838 | of calling __register_frame_info at all, for each object, | |
1839 | use the shared libgcc if any EH symbol referenced. | |
1840 | ||
1841 | If crtstuff is fixed to not invoke __register_frame_info | |
1842 | automatically, for each object, use the shared libgcc if | |
1843 | any non-empty unwind section found. | |
1844 | ||
1845 | Doing any of this probably requires invoking an external program to | |
1846 | do the actual object file scanning. */ | |
1847 | { | |
1848 | const char *p = libgcc_spec; | |
1849 | int in_sep = 1; | |
3cfec666 | 1850 | |
6fba09a6 | 1851 | /* Transform the extant libgcc_spec into one that uses the shared libgcc |
43198b29 | 1852 | when given the proper command line arguments. */ |
1853 | while (*p) | |
1854 | { | |
3cfec666 | 1855 | if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0) |
43198b29 | 1856 | { |
5cb4c868 | 1857 | init_gcc_specs (&obstack, |
5cb4c868 | 1858 | "-lgcc_s" |
8bdf23ae | 1859 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1860 | " -lunwind" | |
805e22b2 | 1861 | #endif |
81e210c3 | 1862 | , |
1863 | "-lgcc", | |
1864 | "-lgcc_eh" | |
805e22b2 | 1865 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
79f90e2b | 1866 | # ifdef HAVE_LD_STATIC_DYNAMIC |
1867 | " %{!static:-Bstatic} -lunwind %{!static:-Bdynamic}" | |
1868 | # else | |
805e22b2 | 1869 | " -lunwind" |
79f90e2b | 1870 | # endif |
43198b29 | 1871 | #endif |
81e210c3 | 1872 | ); |
1873 | ||
21eaebc3 | 1874 | p += 5; |
43198b29 | 1875 | in_sep = 0; |
1876 | } | |
21eaebc3 | 1877 | else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0) |
43198b29 | 1878 | { |
1879 | /* Ug. We don't know shared library extensions. Hope that | |
1880 | systems that use this form don't do shared libraries. */ | |
5cb4c868 | 1881 | init_gcc_specs (&obstack, |
6ffda34c | 1882 | "-lgcc_s", |
0d6378a9 | 1883 | "libgcc.a%s", |
974df224 | 1884 | "libgcc_eh.a%s" |
1885 | #ifdef USE_LIBUNWIND_EXCEPTIONS | |
1886 | " -lunwind" | |
1887 | #endif | |
1888 | ); | |
21eaebc3 | 1889 | p += 10; |
43198b29 | 1890 | in_sep = 0; |
1891 | } | |
1892 | else | |
1893 | { | |
1894 | obstack_1grow (&obstack, *p); | |
1895 | in_sep = (*p == ' '); | |
1896 | p += 1; | |
1897 | } | |
1898 | } | |
1899 | ||
1900 | obstack_1grow (&obstack, '\0'); | |
4fac984f | 1901 | libgcc_spec = XOBFINISH (&obstack, const char *); |
43198b29 | 1902 | } |
1903 | #endif | |
c3f311c4 | 1904 | #ifdef USE_AS_TRADITIONAL_FORMAT |
1905 | /* Prepend "--traditional-format" to whatever asm_spec we had before. */ | |
1906 | { | |
e99c3a1d | 1907 | static const char tf[] = "--traditional-format "; |
c3f311c4 | 1908 | obstack_grow (&obstack, tf, sizeof(tf) - 1); |
1909 | obstack_grow0 (&obstack, asm_spec, strlen (asm_spec)); | |
4fac984f | 1910 | asm_spec = XOBFINISH (&obstack, const char *); |
c3f311c4 | 1911 | } |
1912 | #endif | |
8271b966 | 1913 | |
1914 | #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC | |
1915 | # ifdef LINK_BUILDID_SPEC | |
1916 | /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */ | |
1917 | obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof(LINK_BUILDID_SPEC) - 1); | |
1918 | # endif | |
1919 | # ifdef LINK_EH_SPEC | |
0d6378a9 | 1920 | /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ |
1921 | obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1); | |
8271b966 | 1922 | # endif |
0d6378a9 | 1923 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
4fac984f | 1924 | link_spec = XOBFINISH (&obstack, const char *); |
0d6378a9 | 1925 | #endif |
43198b29 | 1926 | |
988c0ffe | 1927 | specs = sl; |
1928 | } | |
d7a9644e | 1929 | \f |
1930 | /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is | |
1931 | removed; If the spec starts with a + then SPEC is added to the end of the | |
a92771b8 | 1932 | current spec. */ |
d7a9644e | 1933 | |
1934 | static void | |
952f0048 | 1935 | set_spec (const char *name, const char *spec) |
d7a9644e | 1936 | { |
1937 | struct spec_list *sl; | |
e772a198 | 1938 | const char *old_spec; |
988c0ffe | 1939 | int name_len = strlen (name); |
1940 | int i; | |
1941 | ||
d4ea3b1f | 1942 | /* If this is the first call, initialize the statically allocated specs. */ |
4582d741 | 1943 | if (!specs) |
1944 | { | |
2c815aff | 1945 | struct spec_list *next = (struct spec_list *) 0; |
3098b2d3 | 1946 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
4582d741 | 1947 | { |
1948 | sl = &static_specs[i]; | |
1949 | sl->next = next; | |
1950 | next = sl; | |
1951 | } | |
1952 | specs = sl; | |
1953 | } | |
1954 | ||
d4ea3b1f | 1955 | /* See if the spec already exists. */ |
d7a9644e | 1956 | for (sl = specs; sl; sl = sl->next) |
988c0ffe | 1957 | if (name_len == sl->name_len && !strcmp (sl->name, name)) |
d7a9644e | 1958 | break; |
1959 | ||
1960 | if (!sl) | |
1961 | { | |
d4ea3b1f | 1962 | /* Not found - make it. */ |
4c36ffe6 | 1963 | sl = XNEW (struct spec_list); |
713829e9 | 1964 | sl->name = xstrdup (name); |
988c0ffe | 1965 | sl->name_len = name_len; |
1966 | sl->ptr_spec = &sl->ptr; | |
1967 | sl->alloc_p = 0; | |
1968 | *(sl->ptr_spec) = ""; | |
d7a9644e | 1969 | sl->next = specs; |
1970 | specs = sl; | |
1971 | } | |
1972 | ||
988c0ffe | 1973 | old_spec = *(sl->ptr_spec); |
274c11d8 | 1974 | *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1])) |
4e2023c8 | 1975 | ? concat (old_spec, spec + 1, NULL) |
713829e9 | 1976 | : xstrdup (spec)); |
8b351d3c | 1977 | |
4582d741 | 1978 | #ifdef DEBUG_SPECS |
1979 | if (verbose_flag) | |
be2828ce | 1980 | notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec)); |
4582d741 | 1981 | #endif |
1982 | ||
d4ea3b1f | 1983 | /* Free the old spec. */ |
988c0ffe | 1984 | if (old_spec && sl->alloc_p) |
e47a6f81 | 1985 | free (CONST_CAST(char *, old_spec)); |
988c0ffe | 1986 | |
1987 | sl->alloc_p = 1; | |
d7a9644e | 1988 | } |
1989 | \f | |
1990 | /* Accumulate a command (program name and args), and run it. */ | |
1991 | ||
1992 | /* Vector of pointers to arguments in the current line of specifications. */ | |
1993 | ||
2508fdc3 | 1994 | static const char **argbuf; |
d7a9644e | 1995 | |
1996 | /* Number of elements allocated in argbuf. */ | |
1997 | ||
1998 | static int argbuf_length; | |
1999 | ||
2000 | /* Number of elements in argbuf currently in use (containing args). */ | |
2001 | ||
2002 | static int argbuf_index; | |
2003 | ||
dc1dd09b | 2004 | /* Position in the argbuf array containing the name of the output file |
2005 | (the value associated with the "-o" flag). */ | |
2006 | ||
2007 | static int have_o_argbuf_index = 0; | |
2008 | ||
a2000777 | 2009 | /* Were the options -c, -S or -E passed. */ |
89dfd38d | 2010 | static int have_c = 0; |
2011 | ||
2012 | /* Was the option -o passed. */ | |
2013 | static int have_o = 0; | |
2014 | ||
655a58fa | 2015 | /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated |
2016 | temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for | |
2017 | it here. */ | |
4576c73f | 2018 | |
2019 | static struct temp_name { | |
e40d43cc | 2020 | const char *suffix; /* suffix associated with the code. */ |
4576c73f | 2021 | int length; /* strlen (suffix). */ |
2022 | int unique; /* Indicates whether %g or %u/%U was used. */ | |
e40d43cc | 2023 | const char *filename; /* associated filename. */ |
4576c73f | 2024 | int filename_length; /* strlen (filename). */ |
2025 | struct temp_name *next; | |
2026 | } *temp_names; | |
1526a87c | 2027 | |
d7a9644e | 2028 | /* Number of commands executed so far. */ |
2029 | ||
2030 | static int execution_count; | |
2031 | ||
68360609 | 2032 | /* Number of commands that exited with a signal. */ |
2033 | ||
2034 | static int signal_count; | |
2035 | ||
d7a9644e | 2036 | /* Name with which this program was invoked. */ |
2037 | ||
e40d43cc | 2038 | static const char *programname; |
d7a9644e | 2039 | \f |
c21b3276 | 2040 | /* Allocate the argument vector. */ |
2041 | ||
2042 | static void | |
a046944b | 2043 | alloc_args (void) |
c21b3276 | 2044 | { |
2045 | argbuf_length = 10; | |
4c36ffe6 | 2046 | argbuf = XNEWVEC (const char *, argbuf_length); |
c21b3276 | 2047 | } |
2048 | ||
d7a9644e | 2049 | /* Clear out the vector of arguments (after a command is executed). */ |
2050 | ||
2051 | static void | |
952f0048 | 2052 | clear_args (void) |
d7a9644e | 2053 | { |
2054 | argbuf_index = 0; | |
2055 | } | |
2056 | ||
2057 | /* Add one argument to the vector at the end. | |
2058 | This is done when a space is seen or at the end of the line. | |
2059 | If DELETE_ALWAYS is nonzero, the arg is a filename | |
2060 | and the file should be deleted eventually. | |
2061 | If DELETE_FAILURE is nonzero, the arg is a filename | |
2062 | and the file should be deleted if this compilation fails. */ | |
2063 | ||
2064 | static void | |
952f0048 | 2065 | store_arg (const char *arg, int delete_always, int delete_failure) |
d7a9644e | 2066 | { |
2067 | if (argbuf_index + 1 == argbuf_length) | |
25a1c410 | 2068 | argbuf = XRESIZEVEC (const char *, argbuf, (argbuf_length *= 2)); |
d7a9644e | 2069 | |
2070 | argbuf[argbuf_index++] = arg; | |
2071 | argbuf[argbuf_index] = 0; | |
2072 | ||
dc1dd09b | 2073 | if (strcmp (arg, "-o") == 0) |
2074 | have_o_argbuf_index = argbuf_index; | |
d7a9644e | 2075 | if (delete_always || delete_failure) |
2076 | record_temp_file (arg, delete_always, delete_failure); | |
2077 | } | |
2078 | \f | |
424da949 | 2079 | /* Load specs from a file name named FILENAME, replacing occurrences of |
2c815aff | 2080 | various different types of line-endings, \r\n, \n\r and just \r, with |
bee69028 | 2081 | a single \n. */ |
4582d741 | 2082 | |
026f2c7a | 2083 | static char * |
952f0048 | 2084 | load_specs (const char *filename) |
4582d741 | 2085 | { |
2086 | int desc; | |
2087 | int readlen; | |
2088 | struct stat statbuf; | |
2089 | char *buffer; | |
bee69028 | 2090 | char *buffer_p; |
2091 | char *specs; | |
2092 | char *specs_p; | |
4582d741 | 2093 | |
2094 | if (verbose_flag) | |
be2828ce | 2095 | notice ("Reading specs from %s\n", filename); |
4582d741 | 2096 | |
2097 | /* Open and stat the file. */ | |
2098 | desc = open (filename, O_RDONLY, 0); | |
2099 | if (desc < 0) | |
2100 | pfatal_with_name (filename); | |
2101 | if (stat (filename, &statbuf) < 0) | |
2102 | pfatal_with_name (filename); | |
2103 | ||
2104 | /* Read contents of file into BUFFER. */ | |
4c36ffe6 | 2105 | buffer = XNEWVEC (char, statbuf.st_size + 1); |
4582d741 | 2106 | readlen = read (desc, buffer, (unsigned) statbuf.st_size); |
2107 | if (readlen < 0) | |
2108 | pfatal_with_name (filename); | |
2109 | buffer[readlen] = 0; | |
2110 | close (desc); | |
2111 | ||
4c36ffe6 | 2112 | specs = XNEWVEC (char, readlen + 1); |
bee69028 | 2113 | specs_p = specs; |
2114 | for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++) | |
2115 | { | |
2116 | int skip = 0; | |
2117 | char c = *buffer_p; | |
2118 | if (c == '\r') | |
026f2c7a | 2119 | { |
2120 | if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */ | |
bee69028 | 2121 | skip = 1; |
026f2c7a | 2122 | else if (*(buffer_p + 1) == '\n') /* \r\n */ |
bee69028 | 2123 | skip = 1; |
2124 | else /* \r */ | |
2125 | c = '\n'; | |
2126 | } | |
2127 | if (! skip) | |
2128 | *specs_p++ = c; | |
2129 | } | |
2130 | *specs_p = '\0'; | |
2131 | ||
2132 | free (buffer); | |
2133 | return (specs); | |
2134 | } | |
2135 | ||
2136 | /* Read compilation specs from a file named FILENAME, | |
2137 | replacing the default ones. | |
2138 | ||
2139 | A suffix which starts with `*' is a definition for | |
2140 | one of the machine-specific sub-specs. The "suffix" should be | |
537c4bc6 | 2141 | *asm, *cc1, *cpp, *link, *startfile, etc. |
bee69028 | 2142 | The corresponding spec is stored in asm_spec, etc., |
2143 | rather than in the `compilers' vector. | |
2144 | ||
2145 | Anything invalid in the file is a fatal error. */ | |
2146 | ||
2147 | static void | |
952f0048 | 2148 | read_specs (const char *filename, int main_p) |
bee69028 | 2149 | { |
2150 | char *buffer; | |
19cb6b50 | 2151 | char *p; |
bee69028 | 2152 | |
2153 | buffer = load_specs (filename); | |
2154 | ||
4582d741 | 2155 | /* Scan BUFFER for specs, putting them in the vector. */ |
2156 | p = buffer; | |
2157 | while (1) | |
2158 | { | |
2159 | char *suffix; | |
2160 | char *spec; | |
2161 | char *in, *out, *p1, *p2, *p3; | |
2162 | ||
2163 | /* Advance P in BUFFER to the next nonblank nocomment line. */ | |
2164 | p = skip_whitespace (p); | |
2165 | if (*p == 0) | |
2166 | break; | |
2167 | ||
2168 | /* Is this a special command that starts with '%'? */ | |
2169 | /* Don't allow this for the main specs file, since it would | |
2170 | encourage people to overwrite it. */ | |
2171 | if (*p == '%' && !main_p) | |
2172 | { | |
2173 | p1 = p; | |
0dbd1c74 | 2174 | while (*p && *p != '\n') |
2175 | p++; | |
2176 | ||
026f2c7a | 2177 | /* Skip '\n'. */ |
2178 | p++; | |
4582d741 | 2179 | |
026f2c7a | 2180 | if (!strncmp (p1, "%include", sizeof ("%include") - 1) |
0dbd1c74 | 2181 | && (p1[sizeof "%include" - 1] == ' ' |
2182 | || p1[sizeof "%include" - 1] == '\t')) | |
4582d741 | 2183 | { |
2184 | char *new_filename; | |
2185 | ||
2186 | p1 += sizeof ("%include"); | |
0dbd1c74 | 2187 | while (*p1 == ' ' || *p1 == '\t') |
2188 | p1++; | |
4582d741 | 2189 | |
2190 | if (*p1++ != '<' || p[-2] != '>') | |
9d4072d8 | 2191 | fatal ("specs %%include syntax malformed after %ld characters", |
2192 | (long) (p1 - buffer + 1)); | |
4582d741 | 2193 | |
2194 | p[-2] = '\0'; | |
067277c3 | 2195 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
4582d741 | 2196 | read_specs (new_filename ? new_filename : p1, FALSE); |
2197 | continue; | |
2198 | } | |
0dbd1c74 | 2199 | else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1) |
2200 | && (p1[sizeof "%include_noerr" - 1] == ' ' | |
2201 | || p1[sizeof "%include_noerr" - 1] == '\t')) | |
4582d741 | 2202 | { |
2203 | char *new_filename; | |
2204 | ||
0dbd1c74 | 2205 | p1 += sizeof "%include_noerr"; |
026f2c7a | 2206 | while (*p1 == ' ' || *p1 == '\t') |
2207 | p1++; | |
4582d741 | 2208 | |
2209 | if (*p1++ != '<' || p[-2] != '>') | |
9d4072d8 | 2210 | fatal ("specs %%include syntax malformed after %ld characters", |
2211 | (long) (p1 - buffer + 1)); | |
4582d741 | 2212 | |
2213 | p[-2] = '\0'; | |
067277c3 | 2214 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
4582d741 | 2215 | if (new_filename) |
2216 | read_specs (new_filename, FALSE); | |
2217 | else if (verbose_flag) | |
68435912 | 2218 | notice ("could not find specs file %s\n", p1); |
4582d741 | 2219 | continue; |
2220 | } | |
0dbd1c74 | 2221 | else if (!strncmp (p1, "%rename", sizeof "%rename" - 1) |
2222 | && (p1[sizeof "%rename" - 1] == ' ' | |
2223 | || p1[sizeof "%rename" - 1] == '\t')) | |
4582d741 | 2224 | { |
2225 | int name_len; | |
2226 | struct spec_list *sl; | |
1686d9b4 | 2227 | struct spec_list *newsl; |
4582d741 | 2228 | |
1686d9b4 | 2229 | /* Get original name. */ |
0dbd1c74 | 2230 | p1 += sizeof "%rename"; |
2231 | while (*p1 == ' ' || *p1 == '\t') | |
2232 | p1++; | |
2233 | ||
2c815aff | 2234 | if (! ISALPHA ((unsigned char) *p1)) |
9d4072d8 | 2235 | fatal ("specs %%rename syntax malformed after %ld characters", |
2236 | (long) (p1 - buffer)); | |
4582d741 | 2237 | |
2238 | p2 = p1; | |
2c815aff | 2239 | while (*p2 && !ISSPACE ((unsigned char) *p2)) |
0dbd1c74 | 2240 | p2++; |
2241 | ||
4582d741 | 2242 | if (*p2 != ' ' && *p2 != '\t') |
9d4072d8 | 2243 | fatal ("specs %%rename syntax malformed after %ld characters", |
2244 | (long) (p2 - buffer)); | |
4582d741 | 2245 | |
2246 | name_len = p2 - p1; | |
2247 | *p2++ = '\0'; | |
0dbd1c74 | 2248 | while (*p2 == ' ' || *p2 == '\t') |
2249 | p2++; | |
2250 | ||
2c815aff | 2251 | if (! ISALPHA ((unsigned char) *p2)) |
9d4072d8 | 2252 | fatal ("specs %%rename syntax malformed after %ld characters", |
2253 | (long) (p2 - buffer)); | |
4582d741 | 2254 | |
026f2c7a | 2255 | /* Get new spec name. */ |
4582d741 | 2256 | p3 = p2; |
2c815aff | 2257 | while (*p3 && !ISSPACE ((unsigned char) *p3)) |
0dbd1c74 | 2258 | p3++; |
2259 | ||
026f2c7a | 2260 | if (p3 != p - 1) |
9d4072d8 | 2261 | fatal ("specs %%rename syntax malformed after %ld characters", |
2262 | (long) (p3 - buffer)); | |
4582d741 | 2263 | *p3 = '\0'; |
2264 | ||
2265 | for (sl = specs; sl; sl = sl->next) | |
2266 | if (name_len == sl->name_len && !strcmp (sl->name, p1)) | |
2267 | break; | |
2268 | ||
2269 | if (!sl) | |
2270 | fatal ("specs %s spec was not found to be renamed", p1); | |
2271 | ||
0dbd1c74 | 2272 | if (strcmp (p1, p2) == 0) |
4582d741 | 2273 | continue; |
2274 | ||
1686d9b4 | 2275 | for (newsl = specs; newsl; newsl = newsl->next) |
2276 | if (strcmp (newsl->name, p2) == 0) | |
2277 | fatal ("%s: attempt to rename spec '%s' to already defined spec '%s'", | |
2278 | filename, p1, p2); | |
2279 | ||
4582d741 | 2280 | if (verbose_flag) |
2281 | { | |
be2828ce | 2282 | notice ("rename spec %s to %s\n", p1, p2); |
4582d741 | 2283 | #ifdef DEBUG_SPECS |
be2828ce | 2284 | notice ("spec is '%s'\n\n", *(sl->ptr_spec)); |
4582d741 | 2285 | #endif |
2286 | } | |
2287 | ||
2288 | set_spec (p2, *(sl->ptr_spec)); | |
2289 | if (sl->alloc_p) | |
e47a6f81 | 2290 | free (CONST_CAST (char *, *(sl->ptr_spec))); |
4582d741 | 2291 | |
2292 | *(sl->ptr_spec) = ""; | |
2293 | sl->alloc_p = 0; | |
2294 | continue; | |
2295 | } | |
2296 | else | |
9d4072d8 | 2297 | fatal ("specs unknown %% command after %ld characters", |
2298 | (long) (p1 - buffer)); | |
4582d741 | 2299 | } |
2300 | ||
2301 | /* Find the colon that should end the suffix. */ | |
2302 | p1 = p; | |
0dbd1c74 | 2303 | while (*p1 && *p1 != ':' && *p1 != '\n') |
2304 | p1++; | |
2305 | ||
4582d741 | 2306 | /* The colon shouldn't be missing. */ |
2307 | if (*p1 != ':') | |
9d4072d8 | 2308 | fatal ("specs file malformed after %ld characters", |
2309 | (long) (p1 - buffer)); | |
0dbd1c74 | 2310 | |
4582d741 | 2311 | /* Skip back over trailing whitespace. */ |
2312 | p2 = p1; | |
0dbd1c74 | 2313 | while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) |
2314 | p2--; | |
2315 | ||
4582d741 | 2316 | /* Copy the suffix to a string. */ |
2317 | suffix = save_string (p, p2 - p); | |
2318 | /* Find the next line. */ | |
2319 | p = skip_whitespace (p1 + 1); | |
2320 | if (p[1] == 0) | |
9d4072d8 | 2321 | fatal ("specs file malformed after %ld characters", |
2322 | (long) (p - buffer)); | |
0dbd1c74 | 2323 | |
4582d741 | 2324 | p1 = p; |
623feb20 | 2325 | /* Find next blank line or end of string. */ |
2326 | while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0'))) | |
0dbd1c74 | 2327 | p1++; |
2328 | ||
4582d741 | 2329 | /* Specs end at the blank line and do not include the newline. */ |
2330 | spec = save_string (p, p1 - p); | |
2331 | p = p1; | |
2332 | ||
2333 | /* Delete backslash-newline sequences from the spec. */ | |
2334 | in = spec; | |
2335 | out = spec; | |
2336 | while (*in != 0) | |
2337 | { | |
2338 | if (in[0] == '\\' && in[1] == '\n') | |
2339 | in += 2; | |
2340 | else if (in[0] == '#') | |
0dbd1c74 | 2341 | while (*in && *in != '\n') |
2342 | in++; | |
2343 | ||
4582d741 | 2344 | else |
2345 | *out++ = *in++; | |
2346 | } | |
2347 | *out = 0; | |
2348 | ||
2349 | if (suffix[0] == '*') | |
2350 | { | |
2351 | if (! strcmp (suffix, "*link_command")) | |
2352 | link_command_spec = spec; | |
2353 | else | |
2354 | set_spec (suffix + 1, spec); | |
2355 | } | |
2356 | else | |
2357 | { | |
2358 | /* Add this pair to the vector. */ | |
2359 | compilers | |
25a1c410 | 2360 | = XRESIZEVEC (struct compiler, compilers, n_compilers + 2); |
0dbd1c74 | 2361 | |
4582d741 | 2362 | compilers[n_compilers].suffix = suffix; |
1cf79a1a | 2363 | compilers[n_compilers].spec = spec; |
4582d741 | 2364 | n_compilers++; |
7f0b0c27 | 2365 | memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]); |
4582d741 | 2366 | } |
2367 | ||
2368 | if (*suffix == 0) | |
2369 | link_command_spec = spec; | |
2370 | } | |
2371 | ||
2372 | if (link_command_spec == 0) | |
2373 | fatal ("spec file has no spec for linking"); | |
2374 | } | |
2375 | \f | |
d7a9644e | 2376 | /* Record the names of temporary files we tell compilers to write, |
2377 | and delete them at the end of the run. */ | |
2378 | ||
2379 | /* This is the common prefix we use to make temp file names. | |
2380 | It is chosen once for each run of this program. | |
655a58fa | 2381 | It is substituted into a spec by %g or %j. |
d7a9644e | 2382 | Thus, all temp file names contain this prefix. |
2383 | In practice, all temp file names start with this prefix. | |
2384 | ||
2385 | This prefix comes from the envvar TMPDIR if it is defined; | |
2386 | otherwise, from the P_tmpdir macro if that is defined; | |
3441e5dd | 2387 | otherwise, in /usr/tmp or /tmp; |
2388 | or finally the current directory if all else fails. */ | |
d7a9644e | 2389 | |
e40d43cc | 2390 | static const char *temp_filename; |
d7a9644e | 2391 | |
2392 | /* Length of the prefix. */ | |
2393 | ||
2394 | static int temp_filename_length; | |
2395 | ||
2396 | /* Define the list of temporary files to delete. */ | |
2397 | ||
2398 | struct temp_file | |
2399 | { | |
e40d43cc | 2400 | const char *name; |
d7a9644e | 2401 | struct temp_file *next; |
2402 | }; | |
2403 | ||
2404 | /* Queue of files to delete on success or failure of compilation. */ | |
2405 | static struct temp_file *always_delete_queue; | |
2406 | /* Queue of files to delete on failure of compilation. */ | |
2407 | static struct temp_file *failure_delete_queue; | |
2408 | ||
2409 | /* Record FILENAME as a file to be deleted automatically. | |
2410 | ALWAYS_DELETE nonzero means delete it if all compilation succeeds; | |
2411 | otherwise delete it in any case. | |
2412 | FAIL_DELETE nonzero means delete it if a compilation step fails; | |
2413 | otherwise delete it in any case. */ | |
2414 | ||
833a5c07 | 2415 | void |
952f0048 | 2416 | record_temp_file (const char *filename, int always_delete, int fail_delete) |
d7a9644e | 2417 | { |
19cb6b50 | 2418 | char *const name = xstrdup (filename); |
d7a9644e | 2419 | |
2420 | if (always_delete) | |
2421 | { | |
19cb6b50 | 2422 | struct temp_file *temp; |
d7a9644e | 2423 | for (temp = always_delete_queue; temp; temp = temp->next) |
2424 | if (! strcmp (name, temp->name)) | |
2425 | goto already1; | |
0dbd1c74 | 2426 | |
4c36ffe6 | 2427 | temp = XNEW (struct temp_file); |
d7a9644e | 2428 | temp->next = always_delete_queue; |
2429 | temp->name = name; | |
2430 | always_delete_queue = temp; | |
0dbd1c74 | 2431 | |
d7a9644e | 2432 | already1:; |
2433 | } | |
2434 | ||
2435 | if (fail_delete) | |
2436 | { | |
19cb6b50 | 2437 | struct temp_file *temp; |
d7a9644e | 2438 | for (temp = failure_delete_queue; temp; temp = temp->next) |
2439 | if (! strcmp (name, temp->name)) | |
2440 | goto already2; | |
0dbd1c74 | 2441 | |
4c36ffe6 | 2442 | temp = XNEW (struct temp_file); |
d7a9644e | 2443 | temp->next = failure_delete_queue; |
2444 | temp->name = name; | |
2445 | failure_delete_queue = temp; | |
0dbd1c74 | 2446 | |
d7a9644e | 2447 | already2:; |
2448 | } | |
2449 | } | |
2450 | ||
2451 | /* Delete all the temporary files whose names we previously recorded. */ | |
2452 | ||
767efd18 | 2453 | #ifndef DELETE_IF_ORDINARY |
2454 | #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \ | |
2455 | do \ | |
2456 | { \ | |
2457 | if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ | |
2458 | if (unlink (NAME) < 0) \ | |
2459 | if (VERBOSE_FLAG) \ | |
2460 | perror_with_name (NAME); \ | |
2461 | } while (0) | |
2462 | #endif | |
2463 | ||
8149a4fc | 2464 | static void |
952f0048 | 2465 | delete_if_ordinary (const char *name) |
8149a4fc | 2466 | { |
2467 | struct stat st; | |
2468 | #ifdef DEBUG | |
2469 | int i, c; | |
2470 | ||
2471 | printf ("Delete %s? (y or n) ", name); | |
2472 | fflush (stdout); | |
2473 | i = getchar (); | |
2474 | if (i != '\n') | |
0dbd1c74 | 2475 | while ((c = getchar ()) != '\n' && c != EOF) |
2476 | ; | |
2477 | ||
8149a4fc | 2478 | if (i == 'y' || i == 'Y') |
2479 | #endif /* DEBUG */ | |
767efd18 | 2480 | DELETE_IF_ORDINARY (name, st, verbose_flag); |
8149a4fc | 2481 | } |
2482 | ||
d7a9644e | 2483 | static void |
952f0048 | 2484 | delete_temp_files (void) |
d7a9644e | 2485 | { |
19cb6b50 | 2486 | struct temp_file *temp; |
d7a9644e | 2487 | |
2488 | for (temp = always_delete_queue; temp; temp = temp->next) | |
8149a4fc | 2489 | delete_if_ordinary (temp->name); |
d7a9644e | 2490 | always_delete_queue = 0; |
2491 | } | |
2492 | ||
2493 | /* Delete all the files to be deleted on error. */ | |
2494 | ||
2495 | static void | |
952f0048 | 2496 | delete_failure_queue (void) |
d7a9644e | 2497 | { |
19cb6b50 | 2498 | struct temp_file *temp; |
d7a9644e | 2499 | |
2500 | for (temp = failure_delete_queue; temp; temp = temp->next) | |
8149a4fc | 2501 | delete_if_ordinary (temp->name); |
d7a9644e | 2502 | } |
2503 | ||
2504 | static void | |
952f0048 | 2505 | clear_failure_queue (void) |
d7a9644e | 2506 | { |
2507 | failure_delete_queue = 0; | |
2508 | } | |
8894538a | 2509 | \f |
067277c3 | 2510 | /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK |
2511 | returns non-NULL. | |
2512 | If DO_MULTI is true iterate over the paths twice, first with multilib | |
2513 | suffix then without, otherwise iterate over the paths once without | |
2514 | adding a multilib suffix. When DO_MULTI is true, some attempt is made | |
2515 | to avoid visiting the same path twice, but we could do better. For | |
2516 | instance, /usr/lib/../lib is considered different from /usr/lib. | |
2517 | At least EXTRA_SPACE chars past the end of the path passed to | |
2518 | CALLBACK are available for use by the callback. | |
2519 | CALLBACK_INFO allows extra parameters to be passed to CALLBACK. | |
2520 | ||
2521 | Returns the value returned by CALLBACK. */ | |
2522 | ||
2523 | static void * | |
2524 | for_each_path (const struct path_prefix *paths, | |
2525 | bool do_multi, | |
2526 | size_t extra_space, | |
2527 | void *(*callback) (char *, void *), | |
2528 | void *callback_info) | |
8894538a | 2529 | { |
067277c3 | 2530 | struct prefix_list *pl; |
2531 | const char *multi_dir = NULL; | |
2532 | const char *multi_os_dir = NULL; | |
2533 | const char *multi_suffix; | |
2534 | const char *just_multi_suffix; | |
2535 | char *path = NULL; | |
2536 | void *ret = NULL; | |
2537 | bool skip_multi_dir = false; | |
2538 | bool skip_multi_os_dir = false; | |
2539 | ||
2540 | multi_suffix = machine_suffix; | |
2541 | just_multi_suffix = just_machine_suffix; | |
2542 | if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0) | |
8894538a | 2543 | { |
067277c3 | 2544 | multi_dir = concat (multilib_dir, dir_separator_str, NULL); |
2545 | multi_suffix = concat (multi_suffix, multi_dir, NULL); | |
2546 | just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL); | |
2547 | } | |
2548 | if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0) | |
2549 | multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL); | |
8894538a | 2550 | |
067277c3 | 2551 | while (1) |
2552 | { | |
2553 | size_t multi_dir_len = 0; | |
2554 | size_t multi_os_dir_len = 0; | |
2555 | size_t suffix_len; | |
2556 | size_t just_suffix_len; | |
2557 | size_t len; | |
2558 | ||
2559 | if (multi_dir) | |
2560 | multi_dir_len = strlen (multi_dir); | |
2561 | if (multi_os_dir) | |
2562 | multi_os_dir_len = strlen (multi_os_dir); | |
2563 | suffix_len = strlen (multi_suffix); | |
2564 | just_suffix_len = strlen (just_multi_suffix); | |
2565 | ||
2566 | if (path == NULL) | |
8894538a | 2567 | { |
067277c3 | 2568 | len = paths->max_len + extra_space + 1; |
2569 | if (suffix_len > multi_os_dir_len) | |
2570 | len += suffix_len; | |
2571 | else | |
2572 | len += multi_os_dir_len; | |
4c36ffe6 | 2573 | path = XNEWVEC (char, len); |
8894538a | 2574 | } |
2575 | ||
067277c3 | 2576 | for (pl = paths->plist; pl != 0; pl = pl->next) |
3ec1fc1b | 2577 | { |
067277c3 | 2578 | len = strlen (pl->prefix); |
2579 | memcpy (path, pl->prefix, len); | |
2c815aff | 2580 | |
067277c3 | 2581 | /* Look first in MACHINE/VERSION subdirectory. */ |
2582 | if (!skip_multi_dir) | |
2583 | { | |
2584 | memcpy (path + len, multi_suffix, suffix_len + 1); | |
2585 | ret = callback (path, callback_info); | |
2586 | if (ret) | |
2587 | break; | |
2588 | } | |
2589 | ||
2590 | /* Some paths are tried with just the machine (ie. target) | |
2591 | subdir. This is used for finding as, ld, etc. */ | |
2592 | if (!skip_multi_dir | |
2593 | && pl->require_machine_suffix == 2) | |
2594 | { | |
2595 | memcpy (path + len, just_multi_suffix, just_suffix_len + 1); | |
2596 | ret = callback (path, callback_info); | |
2597 | if (ret) | |
2598 | break; | |
2599 | } | |
2600 | ||
2601 | /* Now try the base path. */ | |
2602 | if (!pl->require_machine_suffix | |
2603 | && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) | |
2604 | { | |
2605 | const char *this_multi; | |
2606 | size_t this_multi_len; | |
2607 | ||
2608 | if (pl->os_multilib) | |
2609 | { | |
2610 | this_multi = multi_os_dir; | |
2611 | this_multi_len = multi_os_dir_len; | |
2612 | } | |
2613 | else | |
2614 | { | |
2615 | this_multi = multi_dir; | |
2616 | this_multi_len = multi_dir_len; | |
2617 | } | |
2618 | ||
2619 | if (this_multi_len) | |
2620 | memcpy (path + len, this_multi, this_multi_len + 1); | |
2621 | else | |
2622 | path[len] = '\0'; | |
2623 | ||
2624 | ret = callback (path, callback_info); | |
2625 | if (ret) | |
2626 | break; | |
2627 | } | |
3ec1fc1b | 2628 | } |
067277c3 | 2629 | if (pl) |
2630 | break; | |
3ec1fc1b | 2631 | |
067277c3 | 2632 | if (multi_dir == NULL && multi_os_dir == NULL) |
2633 | break; | |
8894538a | 2634 | |
067277c3 | 2635 | /* Run through the paths again, this time without multilibs. |
2636 | Don't repeat any we have already seen. */ | |
2637 | if (multi_dir) | |
2638 | { | |
e47a6f81 | 2639 | free (CONST_CAST (char *, multi_dir)); |
067277c3 | 2640 | multi_dir = NULL; |
e47a6f81 | 2641 | free (CONST_CAST (char *, multi_suffix)); |
067277c3 | 2642 | multi_suffix = machine_suffix; |
e47a6f81 | 2643 | free (CONST_CAST (char *, just_multi_suffix)); |
067277c3 | 2644 | just_multi_suffix = just_machine_suffix; |
8894538a | 2645 | } |
067277c3 | 2646 | else |
2647 | skip_multi_dir = true; | |
2648 | if (multi_os_dir) | |
2649 | { | |
e47a6f81 | 2650 | free (CONST_CAST (char *, multi_os_dir)); |
067277c3 | 2651 | multi_os_dir = NULL; |
2652 | } | |
2653 | else | |
2654 | skip_multi_os_dir = true; | |
2655 | } | |
2656 | ||
2657 | if (multi_dir) | |
2658 | { | |
e47a6f81 | 2659 | free (CONST_CAST (char *, multi_dir)); |
2660 | free (CONST_CAST (char *, multi_suffix)); | |
2661 | free (CONST_CAST (char *, just_multi_suffix)); | |
8894538a | 2662 | } |
067277c3 | 2663 | if (multi_os_dir) |
e47a6f81 | 2664 | free (CONST_CAST (char *, multi_os_dir)); |
067277c3 | 2665 | if (ret != path) |
2666 | free (path); | |
2667 | return ret; | |
2668 | } | |
2669 | ||
2670 | /* Callback for build_search_list. Adds path to obstack being built. */ | |
2671 | ||
2672 | struct add_to_obstack_info { | |
2673 | struct obstack *ob; | |
2674 | bool check_dir; | |
2675 | bool first_time; | |
2676 | }; | |
2677 | ||
2678 | static void * | |
2679 | add_to_obstack (char *path, void *data) | |
2680 | { | |
25a1c410 | 2681 | struct add_to_obstack_info *info = (struct add_to_obstack_info *) data; |
067277c3 | 2682 | |
2683 | if (info->check_dir && !is_directory (path, false)) | |
2684 | return NULL; | |
2685 | ||
2686 | if (!info->first_time) | |
2687 | obstack_1grow (info->ob, PATH_SEPARATOR); | |
2688 | ||
2689 | obstack_grow (info->ob, path, strlen (path)); | |
2690 | ||
2691 | info->first_time = false; | |
2692 | return NULL; | |
2693 | } | |
2694 | ||
99c00302 | 2695 | /* Add or change the value of an environment variable, outputting the |
2696 | change to standard error if in verbose mode. */ | |
2697 | static void | |
e8105390 | 2698 | xputenv (const char *string) |
99c00302 | 2699 | { |
2700 | if (verbose_flag) | |
2701 | notice ("%s\n", string); | |
e8105390 | 2702 | putenv (CONST_CAST (char *, string)); |
99c00302 | 2703 | } |
2704 | ||
067277c3 | 2705 | /* Build a list of search directories from PATHS. |
2706 | PREFIX is a string to prepend to the list. | |
2707 | If CHECK_DIR_P is true we ensure the directory exists. | |
2708 | If DO_MULTI is true, multilib paths are output first, then | |
2709 | non-multilib paths. | |
2710 | This is used mostly by putenv_from_prefixes so we use `collect_obstack'. | |
2711 | It is also used by the --print-search-dirs flag. */ | |
2712 | ||
2713 | static char * | |
2714 | build_search_list (const struct path_prefix *paths, const char *prefix, | |
2715 | bool check_dir, bool do_multi) | |
2716 | { | |
2717 | struct add_to_obstack_info info; | |
2718 | ||
2719 | info.ob = &collect_obstack; | |
2720 | info.check_dir = check_dir; | |
2721 | info.first_time = true; | |
2722 | ||
2723 | obstack_grow (&collect_obstack, prefix, strlen (prefix)); | |
2724 | obstack_1grow (&collect_obstack, '='); | |
2725 | ||
2726 | for_each_path (paths, do_multi, 0, add_to_obstack, &info); | |
0dbd1c74 | 2727 | |
4347db8e | 2728 | obstack_1grow (&collect_obstack, '\0'); |
4fac984f | 2729 | return XOBFINISH (&collect_obstack, char *); |
8894538a | 2730 | } |
2731 | ||
a92771b8 | 2732 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
2733 | for collect. */ | |
71cee7b1 | 2734 | |
2735 | static void | |
067277c3 | 2736 | putenv_from_prefixes (const struct path_prefix *paths, const char *env_var, |
2737 | bool do_multi) | |
71cee7b1 | 2738 | { |
99c00302 | 2739 | xputenv (build_search_list (paths, env_var, true, do_multi)); |
71cee7b1 | 2740 | } |
d7a9644e | 2741 | \f |
4d5a901b | 2742 | /* Check whether NAME can be accessed in MODE. This is like access, |
2743 | except that it never considers directories to be executable. */ | |
2744 | ||
2745 | static int | |
952f0048 | 2746 | access_check (const char *name, int mode) |
4d5a901b | 2747 | { |
2748 | if (mode == X_OK) | |
2749 | { | |
2750 | struct stat st; | |
2751 | ||
2752 | if (stat (name, &st) < 0 | |
2753 | || S_ISDIR (st.st_mode)) | |
2754 | return -1; | |
2755 | } | |
2756 | ||
2757 | return access (name, mode); | |
2758 | } | |
2759 | ||
067277c3 | 2760 | /* Callback for find_a_file. Appends the file name to the directory |
2761 | path. If the resulting file exists in the right mode, return the | |
2762 | full pathname to the file. */ | |
2763 | ||
2764 | struct file_at_path_info { | |
2765 | const char *name; | |
2766 | const char *suffix; | |
2767 | int name_len; | |
2768 | int suffix_len; | |
2769 | int mode; | |
2770 | }; | |
2771 | ||
2772 | static void * | |
2773 | file_at_path (char *path, void *data) | |
2774 | { | |
25a1c410 | 2775 | struct file_at_path_info *info = (struct file_at_path_info *) data; |
067277c3 | 2776 | size_t len = strlen (path); |
2777 | ||
2778 | memcpy (path + len, info->name, info->name_len); | |
2779 | len += info->name_len; | |
2780 | ||
2781 | /* Some systems have a suffix for executable files. | |
2782 | So try appending that first. */ | |
2783 | if (info->suffix_len) | |
2784 | { | |
2785 | memcpy (path + len, info->suffix, info->suffix_len + 1); | |
2786 | if (access_check (path, info->mode) == 0) | |
2787 | return path; | |
2788 | } | |
2789 | ||
2790 | path[len] = '\0'; | |
2791 | if (access_check (path, info->mode) == 0) | |
2792 | return path; | |
2793 | ||
2794 | return NULL; | |
2795 | } | |
2796 | ||
d7a9644e | 2797 | /* Search for NAME using the prefix list PREFIXES. MODE is passed to |
067277c3 | 2798 | access to check permissions. If DO_MULTI is true, search multilib |
2799 | paths then non-multilib paths, otherwise do not search multilib paths. | |
a92771b8 | 2800 | Return 0 if not found, otherwise return its name, allocated with malloc. */ |
d7a9644e | 2801 | |
2802 | static char * | |
067277c3 | 2803 | find_a_file (const struct path_prefix *pprefix, const char *name, int mode, |
2804 | bool do_multi) | |
d7a9644e | 2805 | { |
067277c3 | 2806 | struct file_at_path_info info; |
d7a9644e | 2807 | |
f07251bc | 2808 | #ifdef DEFAULT_ASSEMBLER |
7d3bd8c0 | 2809 | if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) |
713829e9 | 2810 | return xstrdup (DEFAULT_ASSEMBLER); |
f07251bc | 2811 | #endif |
2812 | ||
2813 | #ifdef DEFAULT_LINKER | |
713829e9 | 2814 | if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) |
2815 | return xstrdup (DEFAULT_LINKER); | |
f07251bc | 2816 | #endif |
2817 | ||
d7a9644e | 2818 | /* Determine the filename to execute (special case for absolute paths). */ |
2819 | ||
a5c088d4 | 2820 | if (IS_ABSOLUTE_PATH (name)) |
d7a9644e | 2821 | { |
f07251bc | 2822 | if (access (name, mode) == 0) |
067277c3 | 2823 | return xstrdup (name); |
757f7e66 | 2824 | |
067277c3 | 2825 | return NULL; |
2826 | } | |
757f7e66 | 2827 | |
067277c3 | 2828 | info.name = name; |
2829 | info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : ""; | |
2830 | info.name_len = strlen (info.name); | |
2831 | info.suffix_len = strlen (info.suffix); | |
2832 | info.mode = mode; | |
d7a9644e | 2833 | |
25a1c410 | 2834 | return (char*) for_each_path (pprefix, do_multi, |
2835 | info.name_len + info.suffix_len, | |
2836 | file_at_path, &info); | |
d7a9644e | 2837 | } |
2838 | ||
acd84059 | 2839 | /* Ranking of prefixes in the sort list. -B prefixes are put before |
2c815aff | 2840 | all others. */ |
acd84059 | 2841 | |
2842 | enum path_prefix_priority | |
2843 | { | |
2844 | PREFIX_PRIORITY_B_OPT, | |
2845 | PREFIX_PRIORITY_LAST | |
2846 | }; | |
2847 | ||
98667efb | 2848 | /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending |
acd84059 | 2849 | order according to PRIORITY. Within each PRIORITY, new entries are |
2850 | appended. | |
d7a9644e | 2851 | |
2852 | If WARN is nonzero, we will warn if no file is found | |
2853 | through this prefix. WARN should point to an int | |
3ec1fc1b | 2854 | which will be set to 1 if this entry is used. |
2855 | ||
0dbd1c74 | 2856 | COMPONENT is the value to be passed to update_path. |
2857 | ||
3ec1fc1b | 2858 | REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without |
2859 | the complete value of machine_suffix. | |
2860 | 2 means try both machine_suffix and just_machine_suffix. */ | |
d7a9644e | 2861 | |
2862 | static void | |
952f0048 | 2863 | add_prefix (struct path_prefix *pprefix, const char *prefix, |
2864 | const char *component, /* enum prefix_priority */ int priority, | |
2af84186 | 2865 | int require_machine_suffix, int os_multilib) |
d7a9644e | 2866 | { |
2867 | struct prefix_list *pl, **prev; | |
2868 | int len; | |
2869 | ||
acd84059 | 2870 | for (prev = &pprefix->plist; |
2871 | (*prev) != NULL && (*prev)->priority <= priority; | |
2872 | prev = &(*prev)->next) | |
2873 | ; | |
d7a9644e | 2874 | |
2358393e | 2875 | /* Keep track of the longest prefix. */ |
d7a9644e | 2876 | |
0dbd1c74 | 2877 | prefix = update_path (prefix, component); |
d7a9644e | 2878 | len = strlen (prefix); |
2879 | if (len > pprefix->max_len) | |
2880 | pprefix->max_len = len; | |
2881 | ||
4c36ffe6 | 2882 | pl = XNEW (struct prefix_list); |
17b80c08 | 2883 | pl->prefix = prefix; |
d7a9644e | 2884 | pl->require_machine_suffix = require_machine_suffix; |
acd84059 | 2885 | pl->priority = priority; |
c954ff02 | 2886 | pl->os_multilib = os_multilib; |
d7a9644e | 2887 | |
2358393e | 2888 | /* Insert after PREV. */ |
acd84059 | 2889 | pl->next = (*prev); |
2890 | (*prev) = pl; | |
d7a9644e | 2891 | } |
805e22b2 | 2892 | |
2893 | /* Same as add_prefix, but prepending target_system_root to prefix. */ | |
c4328bcc | 2894 | /* The target_system_root prefix has been relocated by gcc_exec_prefix. */ |
805e22b2 | 2895 | static void |
952f0048 | 2896 | add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix, |
2897 | const char *component, | |
2898 | /* enum prefix_priority */ int priority, | |
2af84186 | 2899 | int require_machine_suffix, int os_multilib) |
805e22b2 | 2900 | { |
a5c088d4 | 2901 | if (!IS_ABSOLUTE_PATH (prefix)) |
1e5fcbe2 | 2902 | fatal ("system path '%s' is not absolute", prefix); |
805e22b2 | 2903 | |
2904 | if (target_system_root) | |
2905 | { | |
4ea70922 | 2906 | if (target_sysroot_suffix) |
2907 | prefix = concat (target_sysroot_suffix, prefix, NULL); | |
805e22b2 | 2908 | prefix = concat (target_system_root, prefix, NULL); |
4ea70922 | 2909 | |
805e22b2 | 2910 | /* We have to override this because GCC's notion of sysroot |
2911 | moves along with GCC. */ | |
2912 | component = "GCC"; | |
2913 | } | |
2914 | ||
2915 | add_prefix (pprefix, prefix, component, priority, | |
2af84186 | 2916 | require_machine_suffix, os_multilib); |
805e22b2 | 2917 | } |
d7a9644e | 2918 | \f |
2919 | /* Execute the command specified by the arguments on the current line of spec. | |
2920 | When using pipes, this includes several piped-together commands | |
2921 | with `|' between them. | |
2922 | ||
2923 | Return 0 if successful, -1 if failed. */ | |
2924 | ||
2925 | static int | |
952f0048 | 2926 | execute (void) |
d7a9644e | 2927 | { |
2928 | int i; | |
2929 | int n_commands; /* # of command. */ | |
2930 | char *string; | |
288e5bba | 2931 | struct pex_obj *pex; |
d7a9644e | 2932 | struct command |
026f2c7a | 2933 | { |
2934 | const char *prog; /* program name. */ | |
2935 | const char **argv; /* vector of args. */ | |
026f2c7a | 2936 | }; |
d7a9644e | 2937 | |
2938 | struct command *commands; /* each command buffer with above info. */ | |
2939 | ||
5e8f3c31 | 2940 | gcc_assert (!processing_spec_function); |
c21b3276 | 2941 | |
0bfd146e | 2942 | if (wrapper_string) |
2943 | { | |
2944 | string = find_a_file (&exec_prefixes, argbuf[0], X_OK, false); | |
2945 | argbuf[0] = (string) ? string : argbuf[0]; | |
2946 | insert_wrapper (wrapper_string); | |
2947 | } | |
2948 | ||
d7a9644e | 2949 | /* Count # of piped commands. */ |
2950 | for (n_commands = 1, i = 0; i < argbuf_index; i++) | |
2951 | if (strcmp (argbuf[i], "|") == 0) | |
2952 | n_commands++; | |
2953 | ||
2954 | /* Get storage for each command. */ | |
25a1c410 | 2955 | commands = (struct command *) alloca (n_commands * sizeof (struct command)); |
d7a9644e | 2956 | |
2957 | /* Split argbuf into its separate piped processes, | |
2958 | and record info about each one. | |
2959 | Also search for the programs that are to be run. */ | |
2960 | ||
2961 | commands[0].prog = argbuf[0]; /* first command. */ | |
2962 | commands[0].argv = &argbuf[0]; | |
48e1416a | 2963 | |
0bfd146e | 2964 | if (!wrapper_string) |
2965 | { | |
2966 | string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); | |
2967 | commands[0].argv[0] = (string) ? string : commands[0].argv[0]; | |
2968 | } | |
d7a9644e | 2969 | |
2970 | for (n_commands = 1, i = 0; i < argbuf_index; i++) | |
2971 | if (strcmp (argbuf[i], "|") == 0) | |
2972 | { /* each command. */ | |
35151e7a | 2973 | #if defined (__MSDOS__) || defined (OS2) || defined (VMS) |
026f2c7a | 2974 | fatal ("-pipe not supported"); |
d7a9644e | 2975 | #endif |
2976 | argbuf[i] = 0; /* termination of command args. */ | |
2977 | commands[n_commands].prog = argbuf[i + 1]; | |
2978 | commands[n_commands].argv = &argbuf[i + 1]; | |
c954ff02 | 2979 | string = find_a_file (&exec_prefixes, commands[n_commands].prog, |
067277c3 | 2980 | X_OK, false); |
d7a9644e | 2981 | if (string) |
2982 | commands[n_commands].argv[0] = string; | |
2983 | n_commands++; | |
2984 | } | |
2985 | ||
2986 | argbuf[argbuf_index] = 0; | |
2987 | ||
2988 | /* If -v, print what we are about to do, and maybe query. */ | |
2989 | ||
8894538a | 2990 | if (verbose_flag) |
d7a9644e | 2991 | { |
8ace789a | 2992 | /* For help listings, put a blank line between sub-processes. */ |
2993 | if (print_help_list) | |
2994 | fputc ('\n', stderr); | |
2c815aff | 2995 | |
d7a9644e | 2996 | /* Print each piped command as a separate line. */ |
026f2c7a | 2997 | for (i = 0; i < n_commands; i++) |
d7a9644e | 2998 | { |
826f6505 | 2999 | const char *const *j; |
d7a9644e | 3000 | |
3cfec666 | 3001 | if (verbose_only_flag) |
3002 | { | |
74e4079a | 3003 | for (j = commands[i].argv; *j; j++) |
3004 | { | |
7cc1628d | 3005 | const char *p; |
74e4079a | 3006 | fprintf (stderr, " \""); |
3007 | for (p = *j; *p; ++p) | |
3008 | { | |
3009 | if (*p == '"' || *p == '\\' || *p == '$') | |
3010 | fputc ('\\', stderr); | |
3011 | fputc (*p, stderr); | |
3012 | } | |
3013 | fputc ('"', stderr); | |
3014 | } | |
3cfec666 | 3015 | } |
3016 | else | |
74e4079a | 3017 | for (j = commands[i].argv; *j; j++) |
3018 | fprintf (stderr, " %s", *j); | |
d7a9644e | 3019 | |
3020 | /* Print a pipe symbol after all but the last command. */ | |
3021 | if (i + 1 != n_commands) | |
3022 | fprintf (stderr, " |"); | |
3023 | fprintf (stderr, "\n"); | |
3024 | } | |
3025 | fflush (stderr); | |
74e4079a | 3026 | if (verbose_only_flag != 0) |
0f709d72 | 3027 | { |
3028 | /* verbose_only_flag should act as if the spec was | |
3029 | executed, so increment execution_count before | |
c7bf1374 | 3030 | returning. This prevents spurious warnings about |
0f709d72 | 3031 | unused linker input files, etc. */ |
3032 | execution_count++; | |
3033 | return 0; | |
3034 | } | |
d7a9644e | 3035 | #ifdef DEBUG |
be2828ce | 3036 | notice ("\nGo ahead? (y or n) "); |
d7a9644e | 3037 | fflush (stderr); |
3038 | i = getchar (); | |
3039 | if (i != '\n') | |
0dbd1c74 | 3040 | while (getchar () != '\n') |
3041 | ; | |
3042 | ||
d7a9644e | 3043 | if (i != 'y' && i != 'Y') |
3044 | return 0; | |
3045 | #endif /* DEBUG */ | |
3046 | } | |
3047 | ||
0fa54ff1 | 3048 | #ifdef ENABLE_VALGRIND_CHECKING |
98667efb | 3049 | /* Run the each command through valgrind. To simplify prepending the |
0fa54ff1 | 3050 | path to valgrind and the option "-q" (for quiet operation unless |
3051 | something triggers), we allocate a separate argv array. */ | |
3052 | ||
3053 | for (i = 0; i < n_commands; i++) | |
3054 | { | |
3055 | const char **argv; | |
3056 | int argc; | |
3057 | int j; | |
3058 | ||
3059 | for (argc = 0; commands[i].argv[argc] != NULL; argc++) | |
3060 | ; | |
3061 | ||
561c1db5 | 3062 | argv = XALLOCAVEC (const char *, argc + 3); |
0fa54ff1 | 3063 | |
3064 | argv[0] = VALGRIND_PATH; | |
3065 | argv[1] = "-q"; | |
3066 | for (j = 2; j < argc + 2; j++) | |
3067 | argv[j] = commands[i].argv[j - 2]; | |
3068 | argv[j] = NULL; | |
3069 | ||
3070 | commands[i].argv = argv; | |
3071 | commands[i].prog = argv[0]; | |
3072 | } | |
3073 | #endif | |
3074 | ||
d7a9644e | 3075 | /* Run each piped subprocess. */ |
3076 | ||
4537c5d9 | 3077 | pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) |
3078 | ? PEX_RECORD_TIMES : 0), | |
288e5bba | 3079 | programname, temp_filename); |
3080 | if (pex == NULL) | |
3081 | pfatal_with_name (_("pex_init failed")); | |
3082 | ||
d7a9644e | 3083 | for (i = 0; i < n_commands; i++) |
3084 | { | |
288e5bba | 3085 | const char *errmsg; |
3086 | int err; | |
2508fdc3 | 3087 | const char *string = commands[i].argv[0]; |
d7a9644e | 3088 | |
288e5bba | 3089 | errmsg = pex_run (pex, |
3090 | ((i + 1 == n_commands ? PEX_LAST : 0) | |
3091 | | (string == commands[i].prog ? PEX_SEARCH : 0)), | |
e47a6f81 | 3092 | string, CONST_CAST (char **, commands[i].argv), |
288e5bba | 3093 | NULL, NULL, &err); |
3094 | if (errmsg != NULL) | |
3095 | { | |
3096 | if (err == 0) | |
3097 | fatal (errmsg); | |
3098 | else | |
3099 | { | |
3100 | errno = err; | |
3101 | pfatal_with_name (errmsg); | |
3102 | } | |
3103 | } | |
d7a9644e | 3104 | |
3105 | if (string != commands[i].prog) | |
e47a6f81 | 3106 | free (CONST_CAST (char *, string)); |
d7a9644e | 3107 | } |
3108 | ||
3109 | execution_count++; | |
3110 | ||
288e5bba | 3111 | /* Wait for all the subprocesses to finish. */ |
d7a9644e | 3112 | |
3113 | { | |
288e5bba | 3114 | int *statuses; |
3115 | struct pex_time *times = NULL; | |
d7a9644e | 3116 | int ret_code = 0; |
3117 | ||
25a1c410 | 3118 | statuses = (int *) alloca (n_commands * sizeof (int)); |
288e5bba | 3119 | if (!pex_get_status (pex, n_commands, statuses)) |
3120 | pfatal_with_name (_("failed to get exit status")); | |
3121 | ||
4537c5d9 | 3122 | if (report_times || report_times_to_file) |
d7a9644e | 3123 | { |
25a1c410 | 3124 | times = (struct pex_time *) alloca (n_commands * sizeof (struct pex_time)); |
288e5bba | 3125 | if (!pex_get_times (pex, n_commands, times)) |
3126 | pfatal_with_name (_("failed to get process times")); | |
3127 | } | |
d7a9644e | 3128 | |
288e5bba | 3129 | pex_free (pex); |
d7a9644e | 3130 | |
288e5bba | 3131 | for (i = 0; i < n_commands; ++i) |
3132 | { | |
3133 | int status = statuses[i]; | |
a876e5f8 | 3134 | |
288e5bba | 3135 | if (WIFSIGNALED (status)) |
3136 | { | |
4ed34b76 | 3137 | #ifdef SIGPIPE |
288e5bba | 3138 | /* SIGPIPE is a special case. It happens in -pipe mode |
3139 | when the compiler dies before the preprocessor is done, | |
3140 | or the assembler dies before the compiler is done. | |
3141 | There's generally been an error already, and this is | |
3142 | just fallout. So don't generate another error unless | |
3143 | we would otherwise have succeeded. */ | |
3144 | if (WTERMSIG (status) == SIGPIPE | |
3145 | && (signal_count || greatest_status >= MIN_FATAL_STATUS)) | |
d4523b3e | 3146 | { |
3147 | signal_count++; | |
3148 | ret_code = -1; | |
3149 | } | |
288e5bba | 3150 | else |
3151 | #endif | |
87011ef0 | 3152 | fatal_ice ("\ |
4ed34b76 | 3153 | Internal error: %s (program %s)\n\ |
3154 | Please submit a full bug report.\n\ | |
3155 | See %s for instructions.", | |
87011ef0 | 3156 | strsignal (WTERMSIG (status)), commands[i].prog, |
3157 | bug_report_url); | |
288e5bba | 3158 | } |
3159 | else if (WIFEXITED (status) | |
3160 | && WEXITSTATUS (status) >= MIN_FATAL_STATUS) | |
3161 | { | |
3162 | if (WEXITSTATUS (status) > greatest_status) | |
3163 | greatest_status = WEXITSTATUS (status); | |
3164 | ret_code = -1; | |
3165 | } | |
3166 | ||
4537c5d9 | 3167 | if (report_times || report_times_to_file) |
288e5bba | 3168 | { |
3169 | struct pex_time *pt = ×[i]; | |
3170 | double ut, st; | |
3171 | ||
3172 | ut = ((double) pt->user_seconds | |
3173 | + (double) pt->user_microseconds / 1.0e6); | |
3174 | st = ((double) pt->system_seconds | |
3175 | + (double) pt->system_microseconds / 1.0e6); | |
3176 | ||
3177 | if (ut + st != 0) | |
4537c5d9 | 3178 | { |
3179 | if (report_times) | |
3180 | notice ("# %s %.2f %.2f\n", commands[i].prog, ut, st); | |
3181 | ||
3182 | if (report_times_to_file) | |
3183 | { | |
3184 | int c = 0; | |
3185 | const char *const *j; | |
3186 | ||
3187 | fprintf (report_times_to_file, "%g %g", ut, st); | |
3188 | ||
3189 | for (j = &commands[i].prog; *j; j = &commands[i].argv[++c]) | |
3190 | { | |
3191 | const char *p; | |
3192 | for (p = *j; *p; ++p) | |
3193 | if (*p == '"' || *p == '\\' || *p == '$' | |
3194 | || ISSPACE (*p)) | |
3195 | break; | |
3196 | ||
3197 | if (*p) | |
3198 | { | |
3199 | fprintf (report_times_to_file, " \""); | |
3200 | for (p = *j; *p; ++p) | |
3201 | { | |
3202 | if (*p == '"' || *p == '\\' || *p == '$') | |
3203 | fputc ('\\', report_times_to_file); | |
3204 | fputc (*p, report_times_to_file); | |
3205 | } | |
3206 | fputc ('"', report_times_to_file); | |
3207 | } | |
3208 | else | |
3209 | fprintf (report_times_to_file, " %s", *j); | |
3210 | } | |
3211 | ||
3212 | fputc ('\n', report_times_to_file); | |
3213 | } | |
3214 | } | |
288e5bba | 3215 | } |
d7a9644e | 3216 | } |
288e5bba | 3217 | |
d7a9644e | 3218 | return ret_code; |
3219 | } | |
3220 | } | |
3221 | \f | |
3222 | /* Find all the switches given to us | |
3223 | and make a vector describing them. | |
3224 | The elements of the vector are strings, one per switch given. | |
3225 | If a switch uses following arguments, then the `part1' field | |
3226 | is the switch itself and the `args' field | |
3227 | is a null-terminated vector containing the following arguments. | |
79d52444 | 3228 | Bits in the `live_cond' field are: |
3229 | SWITCH_LIVE to indicate this switch is true in a conditional spec. | |
3230 | SWITCH_FALSE to indicate this switch is overridden by a later switch. | |
3231 | SWITCH_IGNORE to indicate this switch should be ignored (used in %<S). | |
be2828ce | 3232 | The `validated' field is nonzero if any spec has looked at this switch; |
d7a9644e | 3233 | if it remains zero at the end of the run, it must be meaningless. */ |
3234 | ||
79d52444 | 3235 | #define SWITCH_LIVE 0x1 |
3236 | #define SWITCH_FALSE 0x2 | |
3237 | #define SWITCH_IGNORE 0x4 | |
4a10d696 | 3238 | |
d7a9644e | 3239 | struct switchstr |
3240 | { | |
e40d43cc | 3241 | const char *part1; |
2508fdc3 | 3242 | const char **args; |
79d52444 | 3243 | unsigned int live_cond; |
e1478c0f | 3244 | unsigned char validated; |
3245 | unsigned char ordering; | |
d7a9644e | 3246 | }; |
3247 | ||
3248 | static struct switchstr *switches; | |
3249 | ||
3250 | static int n_switches; | |
3251 | ||
71278019 | 3252 | /* Set to zero if -fcompare-debug is disabled, positive if it's |
3253 | enabled and we're running the first compilation, negative if it's | |
3254 | enabled and we're running the second compilation. For most of the | |
3255 | time, it's in the range -1..1, but it can be temporarily set to 2 | |
3256 | or 3 to indicate that the -fcompare-debug flags didn't come from | |
3257 | the command-line, but rather from the GCC_COMPARE_DEBUG environment | |
3258 | variable, until a synthesized -fcompare-debug flag is added to the | |
3259 | command line. */ | |
3260 | int compare_debug; | |
3261 | ||
3262 | /* Set to nonzero if we've seen the -fcompare-debug-second flag. */ | |
3263 | int compare_debug_second; | |
3264 | ||
3265 | /* Set to the flags that should be passed to the second compilation in | |
3266 | a -fcompare-debug compilation. */ | |
3267 | const char *compare_debug_opt; | |
3268 | ||
3269 | static struct switchstr *switches_debug_check[2]; | |
3270 | ||
3271 | static int n_switches_debug_check[2]; | |
3272 | ||
3273 | static char *debug_check_temp_file[2]; | |
3274 | ||
fbf54d9a | 3275 | /* Language is one of three things: |
3276 | ||
3277 | 1) The name of a real programming language. | |
3278 | 2) NULL, indicating that no one has figured out | |
3279 | what it is yet. | |
3280 | 3) '*', indicating that the file should be passed | |
3281 | to the linker. */ | |
d7a9644e | 3282 | struct infile |
3283 | { | |
e40d43cc | 3284 | const char *name; |
3285 | const char *language; | |
dc1dd09b | 3286 | struct compiler *incompiler; |
3287 | bool compiled; | |
3288 | bool preprocessed; | |
d7a9644e | 3289 | }; |
3290 | ||
3291 | /* Also a vector of input files specified. */ | |
3292 | ||
3293 | static struct infile *infiles; | |
3294 | ||
943bf3c7 | 3295 | int n_infiles; |
d7a9644e | 3296 | |
40109983 | 3297 | /* True if multiple input files are being compiled to a single |
3298 | assembly file. */ | |
3299 | ||
3300 | static bool combine_inputs; | |
3301 | ||
cdf76fe2 | 3302 | /* This counts the number of libraries added by lang_specific_driver, so that |
9e56255a | 3303 | we can tell if there were any user supplied any files or libraries. */ |
3304 | ||
3305 | static int added_libraries; | |
3306 | ||
d7a9644e | 3307 | /* And a vector of corresponding output files is made up later. */ |
3308 | ||
943bf3c7 | 3309 | const char **outfiles; |
2e58e75e | 3310 | \f |
10f57222 | 3311 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
2e58e75e | 3312 | |
3313 | /* Convert NAME to a new name if it is the standard suffix. DO_EXE | |
c5025ad6 | 3314 | is true if we should look for an executable suffix. DO_OBJ |
3315 | is true if we should look for an object suffix. */ | |
2e58e75e | 3316 | |
7e6b5e54 | 3317 | static const char * |
952f0048 | 3318 | convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED, |
3319 | int do_obj ATTRIBUTE_UNUSED) | |
2e58e75e | 3320 | { |
7e6b5e54 | 3321 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
2e58e75e | 3322 | int i; |
7e6b5e54 | 3323 | #endif |
2e3ecf64 | 3324 | int len; |
3325 | ||
3326 | if (name == NULL) | |
3327 | return NULL; | |
2c815aff | 3328 | |
2e3ecf64 | 3329 | len = strlen (name); |
2e58e75e | 3330 | |
10f57222 | 3331 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
3332 | /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */ | |
c5025ad6 | 3333 | if (do_obj && len > 2 |
2e58e75e | 3334 | && name[len - 2] == '.' |
3335 | && name[len - 1] == 'o') | |
3336 | { | |
7c8c3232 | 3337 | obstack_grow (&obstack, name, len - 2); |
10f57222 | 3338 | obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
4fac984f | 3339 | name = XOBFINISH (&obstack, const char *); |
2e58e75e | 3340 | } |
3341 | #endif | |
3342 | ||
10f57222 | 3343 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
2e58e75e | 3344 | /* If there is no filetype, make it the executable suffix (which includes |
3345 | the "."). But don't get confused if we have just "-o". */ | |
10f57222 | 3346 | if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-')) |
2e58e75e | 3347 | return name; |
3348 | ||
dea8dca4 | 3349 | for (i = len - 1; i >= 0; i--) |
79b23a1e | 3350 | if (IS_DIR_SEPARATOR (name[i])) |
dea8dca4 | 3351 | break; |
3352 | ||
3353 | for (i++; i < len; i++) | |
2e58e75e | 3354 | if (name[i] == '.') |
3355 | return name; | |
3356 | ||
3357 | obstack_grow (&obstack, name, len); | |
ee866761 | 3358 | obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX, |
3359 | strlen (TARGET_EXECUTABLE_SUFFIX)); | |
4fac984f | 3360 | name = XOBFINISH (&obstack, const char *); |
2e58e75e | 3361 | #endif |
3362 | ||
3363 | return name; | |
3364 | } | |
3365 | #endif | |
8ace789a | 3366 | \f |
3367 | /* Display the command line switches accepted by gcc. */ | |
3368 | static void | |
952f0048 | 3369 | display_help (void) |
8ace789a | 3370 | { |
a4db0a1d | 3371 | printf (_("Usage: %s [options] file...\n"), programname); |
3372 | fputs (_("Options:\n"), stdout); | |
8ace789a | 3373 | |
a4db0a1d | 3374 | fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout); |
3375 | fputs (_(" --help Display this information\n"), stdout); | |
7a6882ca | 3376 | fputs (_(" --target-help Display target specific command line options\n"), stdout); |
fad6b6bb | 3377 | fputs (_(" --help={target|optimizers|warnings|params|[^]{joined|separate|undocumented}}[,...]\n"), stdout); |
87c75316 | 3378 | fputs (_(" Display specific types of command line options\n"), stdout); |
8ace789a | 3379 | if (! verbose_flag) |
a4db0a1d | 3380 | fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout); |
53f9a00b | 3381 | fputs (_(" --version Display compiler version information\n"), stdout); |
a4db0a1d | 3382 | fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout); |
3383 | fputs (_(" -dumpversion Display the version of the compiler\n"), stdout); | |
3384 | fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout); | |
3385 | fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout); | |
3386 | fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout); | |
3387 | fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout); | |
3388 | fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout); | |
3389 | fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout); | |
3390 | fputs (_("\ | |
3391 | -print-multi-lib Display the mapping between command line options and\n\ | |
3392 | multiple library search directories\n"), stdout); | |
c954ff02 | 3393 | fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout); |
098cc23f | 3394 | fputs (_(" -print-sysroot Display the target libraries directory\n"), stdout); |
6ea4242f | 3395 | fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers\n"), stdout); |
a4db0a1d | 3396 | fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout); |
3397 | fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout); | |
3398 | fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout); | |
805e22b2 | 3399 | fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler\n"), stdout); |
3400 | fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor\n"), stdout); | |
a4db0a1d | 3401 | fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout); |
dc1dd09b | 3402 | fputs (_(" -combine Pass multiple source files to compiler at once\n"), stdout); |
a4db0a1d | 3403 | fputs (_(" -save-temps Do not delete intermediate files\n"), stdout); |
cc92bc82 | 3404 | fputs (_(" -save-temps=<arg> Do not delete intermediate files\n"), stdout); |
d05a1771 | 3405 | fputs (_("\ |
3406 | -no-canonical-prefixes Do not canonicalize paths when building relative\n\ | |
3407 | prefixes to other gcc components\n"), stdout); | |
a4db0a1d | 3408 | fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout); |
3409 | fputs (_(" -time Time the execution of each subprocess\n"), stdout); | |
f4ec69cb | 3410 | fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout); |
a4db0a1d | 3411 | fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout); |
a99be165 | 3412 | fputs (_("\ |
3413 | --sysroot=<directory> Use <directory> as the root directory for headers\n\ | |
6702edc2 | 3414 | and libraries\n"), stdout); |
a4db0a1d | 3415 | fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout); |
3416 | fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout); | |
3417 | fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout); | |
3418 | fputs (_(" -v Display the programs invoked by the compiler\n"), stdout); | |
74e4079a | 3419 | fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout); |
a4db0a1d | 3420 | fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout); |
3421 | fputs (_(" -S Compile only; do not assemble or link\n"), stdout); | |
3422 | fputs (_(" -c Compile and assemble, but do not link\n"), stdout); | |
3423 | fputs (_(" -o <file> Place the output into <file>\n"), stdout); | |
3424 | fputs (_("\ | |
3425 | -x <language> Specify the language of the following input files\n\ | |
6122f188 | 3426 | Permissible languages include: c c++ assembler none\n\ |
1d8c4563 | 3427 | 'none' means revert to the default behavior of\n\ |
a4db0a1d | 3428 | guessing the language based on the file's extension\n\ |
3429 | "), stdout); | |
3430 | ||
60933322 | 3431 | printf (_("\ |
833a5c07 | 3432 | \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\ |
3433 | passed on to the various sub-processes invoked by %s. In order to pass\n\ | |
3434 | other options on to these processes the -W<letter> options must be used.\n\ | |
60933322 | 3435 | "), programname); |
8ace789a | 3436 | |
3437 | /* The rest of the options are displayed by invocations of the various | |
3438 | sub-processes. */ | |
3439 | } | |
3440 | ||
2c815aff | 3441 | static void |
952f0048 | 3442 | add_preprocessor_option (const char *option, int len) |
2c815aff | 3443 | { |
e40d43cc | 3444 | n_preprocessor_options++; |
2c815aff | 3445 | |
e40d43cc | 3446 | if (! preprocessor_options) |
4c36ffe6 | 3447 | preprocessor_options = XNEWVEC (char *, n_preprocessor_options); |
e40d43cc | 3448 | else |
25a1c410 | 3449 | preprocessor_options = XRESIZEVEC (char *, preprocessor_options, |
3450 | n_preprocessor_options); | |
2c815aff | 3451 | |
e40d43cc | 3452 | preprocessor_options [n_preprocessor_options - 1] = |
3453 | save_string (option, len); | |
9a109943 | 3454 | } |
2c815aff | 3455 | |
3456 | static void | |
952f0048 | 3457 | add_assembler_option (const char *option, int len) |
e40d43cc | 3458 | { |
3459 | n_assembler_options++; | |
3460 | ||
3461 | if (! assembler_options) | |
4c36ffe6 | 3462 | assembler_options = XNEWVEC (char *, n_assembler_options); |
e40d43cc | 3463 | else |
25a1c410 | 3464 | assembler_options = XRESIZEVEC (char *, assembler_options, |
3465 | n_assembler_options); | |
e40d43cc | 3466 | |
3467 | assembler_options [n_assembler_options - 1] = save_string (option, len); | |
8ace789a | 3468 | } |
2c815aff | 3469 | |
3470 | static void | |
952f0048 | 3471 | add_linker_option (const char *option, int len) |
e40d43cc | 3472 | { |
3473 | n_linker_options++; | |
3474 | ||
3475 | if (! linker_options) | |
4c36ffe6 | 3476 | linker_options = XNEWVEC (char *, n_linker_options); |
e40d43cc | 3477 | else |
d7ee9e9b | 3478 | linker_options = XRESIZEVEC (char *, linker_options, n_linker_options); |
e40d43cc | 3479 | |
3480 | linker_options [n_linker_options - 1] = save_string (option, len); | |
9a109943 | 3481 | } |
2e58e75e | 3482 | \f |
d7a9644e | 3483 | /* Create the vector `switches' and its contents. |
3484 | Store its length in `n_switches'. */ | |
3485 | ||
3486 | static void | |
9300babd | 3487 | process_command (int argc, const char **argv) |
d7a9644e | 3488 | { |
19cb6b50 | 3489 | int i; |
e40d43cc | 3490 | const char *temp; |
3491 | char *temp1; | |
2508fdc3 | 3492 | const char *spec_lang = 0; |
d7a9644e | 3493 | int last_language_n_infiles; |
e71cc307 | 3494 | int lang_n_infiles = 0; |
d2537617 | 3495 | #ifdef MODIFY_TARGET_NAME |
3496 | int is_modify_target_name; | |
f3494975 | 3497 | unsigned int j; |
d2537617 | 3498 | #endif |
c4328bcc | 3499 | const char *tooldir_prefix; |
d05a1771 | 3500 | char *(*get_relative_prefix) (const char *, const char *, |
3501 | const char *) = NULL; | |
d7a9644e | 3502 | |
f16449b7 | 3503 | GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX"); |
bfef3e2f | 3504 | |
d7a9644e | 3505 | n_switches = 0; |
3506 | n_infiles = 0; | |
9e56255a | 3507 | added_libraries = 0; |
0d3f9dba | 3508 | |
4dd56bd9 | 3509 | /* Figure compiler version from version string. */ |
3510 | ||
2c815aff | 3511 | compiler_version = temp1 = xstrdup (version_string); |
713829e9 | 3512 | |
e40d43cc | 3513 | for (; *temp1; ++temp1) |
4dd56bd9 | 3514 | { |
e40d43cc | 3515 | if (*temp1 == ' ') |
4dd56bd9 | 3516 | { |
e40d43cc | 3517 | *temp1 = '\0'; |
4dd56bd9 | 3518 | break; |
3519 | } | |
3520 | } | |
d7a9644e | 3521 | |
3443e1be | 3522 | /* If there is a -V or -b option (or both), process it now, before |
1e8e9920 | 3523 | trying to interpret the rest of the command line. |
151ff5fc | 3524 | Use heuristic that all configuration names must have at least |
3525 | one dash '-'. This allows us to pass options starting with -b. */ | |
3443e1be | 3526 | if (argc > 1 && argv[1][0] == '-' |
43315373 | 3527 | && (argv[1][1] == 'V' |
3528 | || (argv[1][1] == 'b' | |
3529 | && (argv[1][2] == '\0' | |
3530 | || NULL != strchr (argv[1] + 2, '-'))))) | |
3443e1be | 3531 | { |
3532 | const char *new_version = DEFAULT_TARGET_VERSION; | |
3533 | const char *new_machine = DEFAULT_TARGET_MACHINE; | |
fe920472 | 3534 | const char *progname = argv[0]; |
3535 | char **new_argv; | |
3443e1be | 3536 | char *new_argv0; |
3537 | int baselen; | |
91e64380 | 3538 | int status = 0; |
3539 | int err = 0; | |
3540 | const char *errmsg; | |
952f0048 | 3541 | |
fe920472 | 3542 | while (argc > 1 && argv[1][0] == '-' |
43315373 | 3543 | && (argv[1][1] == 'V' |
3544 | || (argv[1][1] == 'b' | |
3545 | && (argv[1][2] == '\0' | |
3546 | || NULL != strchr (argv[1] + 2, '-'))))) | |
3443e1be | 3547 | { |
fe920472 | 3548 | char opt = argv[1][1]; |
3443e1be | 3549 | const char *arg; |
fe920472 | 3550 | if (argv[1][2] != '\0') |
3443e1be | 3551 | { |
fe920472 | 3552 | arg = argv[1] + 2; |
3443e1be | 3553 | argc -= 1; |
fe920472 | 3554 | argv += 1; |
3443e1be | 3555 | } |
3556 | else if (argc > 2) | |
3557 | { | |
fe920472 | 3558 | arg = argv[2]; |
3443e1be | 3559 | argc -= 2; |
fe920472 | 3560 | argv += 2; |
3443e1be | 3561 | } |
3562 | else | |
1e5fcbe2 | 3563 | fatal ("'-%c' option must have argument", opt); |
3443e1be | 3564 | if (opt == 'V') |
3565 | new_version = arg; | |
3566 | else | |
3567 | new_machine = arg; | |
3568 | } | |
3569 | ||
fe920472 | 3570 | for (baselen = strlen (progname); baselen > 0; baselen--) |
3571 | if (IS_DIR_SEPARATOR (progname[baselen-1])) | |
3443e1be | 3572 | break; |
65b198c2 | 3573 | new_argv0 = XDUPVAR (char, progname, baselen, |
3443e1be | 3574 | baselen + concat_length (new_version, new_machine, |
3575 | "-gcc-", NULL) + 1); | |
3576 | strcpy (new_argv0 + baselen, new_machine); | |
3577 | strcat (new_argv0, "-gcc-"); | |
3578 | strcat (new_argv0, new_version); | |
3579 | ||
65b198c2 | 3580 | new_argv = XDUPVEC (char *, argv, argc + 1); |
3443e1be | 3581 | new_argv[0] = new_argv0; |
3582 | ||
91e64380 | 3583 | errmsg = pex_one (PEX_SEARCH, new_argv0, new_argv, progname, NULL, |
3584 | NULL, &status, &err); | |
3585 | ||
3586 | if (errmsg) | |
3587 | { | |
3588 | if (err == 0) | |
3589 | fatal ("couldn't run '%s': %s", new_argv0, errmsg); | |
3590 | else | |
3591 | fatal ("couldn't run '%s': %s: %s", new_argv0, errmsg, | |
3592 | xstrerror (err)); | |
3593 | } | |
3594 | exit (status); | |
3443e1be | 3595 | } |
3596 | ||
d05a1771 | 3597 | /* Convert new-style -- options to old-style. */ |
3598 | translate_options (&argc, | |
3599 | CONST_CAST2 (const char *const **, const char ***, | |
3600 | &argv)); | |
3601 | ||
3602 | /* Do language-specific adjustment/addition of flags. */ | |
3603 | lang_specific_driver (&argc, | |
3604 | CONST_CAST2 (const char *const **, const char ***, | |
3605 | &argv), | |
3606 | &added_libraries); | |
3607 | ||
3608 | /* Handle any -no-canonical-prefixes flag early, to assign the function | |
3609 | that builds relative prefixes. This function creates default search | |
3610 | paths that are needed later in normal option handling. */ | |
3611 | ||
3612 | for (i = 1; i < argc; i++) | |
3613 | { | |
3614 | if (! strcmp (argv[i], "-no-canonical-prefixes")) | |
3615 | { | |
3616 | get_relative_prefix = make_relative_prefix_ignore_links; | |
3617 | break; | |
3618 | } | |
3619 | } | |
3620 | if (! get_relative_prefix) | |
3621 | get_relative_prefix = make_relative_prefix; | |
3622 | ||
b155ba2f | 3623 | /* Set up the default search paths. If there is no GCC_EXEC_PREFIX, |
3624 | see if we can create it from the pathname specified in argv[0]. */ | |
3625 | ||
9db45a87 | 3626 | gcc_libexec_prefix = standard_libexec_prefix; |
b155ba2f | 3627 | #ifndef VMS |
3628 | /* FIXME: make_relative_prefix doesn't yet work for VMS. */ | |
3629 | if (!gcc_exec_prefix) | |
3630 | { | |
d05a1771 | 3631 | gcc_exec_prefix = get_relative_prefix (argv[0], |
3632 | standard_bindir_prefix, | |
3633 | standard_exec_prefix); | |
3634 | gcc_libexec_prefix = get_relative_prefix (argv[0], | |
3635 | standard_bindir_prefix, | |
3636 | standard_libexec_prefix); | |
b155ba2f | 3637 | if (gcc_exec_prefix) |
99c00302 | 3638 | xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL)); |
b155ba2f | 3639 | } |
9db45a87 | 3640 | else |
01b26439 | 3641 | { |
3642 | /* make_relative_prefix requires a program name, but | |
3643 | GCC_EXEC_PREFIX is typically a directory name with a trailing | |
3644 | / (which is ignored by make_relative_prefix), so append a | |
3645 | program name. */ | |
3646 | char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL); | |
d05a1771 | 3647 | gcc_libexec_prefix = get_relative_prefix (tmp_prefix, |
3648 | standard_exec_prefix, | |
3649 | standard_libexec_prefix); | |
c4328bcc | 3650 | |
3651 | /* The path is unrelocated, so fallback to the original setting. */ | |
3652 | if (!gcc_libexec_prefix) | |
3653 | gcc_libexec_prefix = standard_libexec_prefix; | |
3654 | ||
01b26439 | 3655 | free (tmp_prefix); |
3656 | } | |
9db45a87 | 3657 | #else |
b155ba2f | 3658 | #endif |
c4328bcc | 3659 | /* From this point onward, gcc_exec_prefix is non-null if the toolchain |
3660 | is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX | |
3661 | or an automatically created GCC_EXEC_PREFIX from argv[0]. */ | |
d7a9644e | 3662 | |
bfef3e2f | 3663 | if (gcc_exec_prefix) |
d7a9644e | 3664 | { |
055237ef | 3665 | int len = strlen (gcc_exec_prefix); |
7d3bd8c0 | 3666 | |
9db45a87 | 3667 | if (len > (int) sizeof ("/lib/gcc/") - 1 |
79b23a1e | 3668 | && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1]))) |
055237ef | 3669 | { |
9db45a87 | 3670 | temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1; |
79b23a1e | 3671 | if (IS_DIR_SEPARATOR (*temp) |
026f2c7a | 3672 | && strncmp (temp + 1, "lib", 3) == 0 |
79b23a1e | 3673 | && IS_DIR_SEPARATOR (temp[4]) |
c201d78b | 3674 | && strncmp (temp + 5, "gcc", 3) == 0) |
9db45a87 | 3675 | len -= sizeof ("/lib/gcc/") - 1; |
055237ef | 3676 | } |
3677 | ||
3678 | set_std_prefix (gcc_exec_prefix, len); | |
9db45a87 | 3679 | add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC", |
2af84186 | 3680 | PREFIX_PRIORITY_LAST, 0, 0); |
acd84059 | 3681 | add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", |
2af84186 | 3682 | PREFIX_PRIORITY_LAST, 0, 0); |
d7a9644e | 3683 | } |
3684 | ||
3685 | /* COMPILER_PATH and LIBRARY_PATH have values | |
3686 | that are lists of directory names with colons. */ | |
3687 | ||
f16449b7 | 3688 | GET_ENVIRONMENT (temp, "COMPILER_PATH"); |
d7a9644e | 3689 | if (temp) |
3690 | { | |
e40d43cc | 3691 | const char *startp, *endp; |
25a1c410 | 3692 | char *nstore = (char *) alloca (strlen (temp) + 3); |
d7a9644e | 3693 | |
3694 | startp = endp = temp; | |
3695 | while (1) | |
3696 | { | |
99b832c9 | 3697 | if (*endp == PATH_SEPARATOR || *endp == 0) |
d7a9644e | 3698 | { |
026f2c7a | 3699 | strncpy (nstore, startp, endp - startp); |
d7a9644e | 3700 | if (endp == startp) |
4e2023c8 | 3701 | strcpy (nstore, concat (".", dir_separator_str, NULL)); |
79b23a1e | 3702 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
d7a9644e | 3703 | { |
026f2c7a | 3704 | nstore[endp - startp] = DIR_SEPARATOR; |
3705 | nstore[endp - startp + 1] = 0; | |
d7a9644e | 3706 | } |
3707 | else | |
026f2c7a | 3708 | nstore[endp - startp] = 0; |
acd84059 | 3709 | add_prefix (&exec_prefixes, nstore, 0, |
2af84186 | 3710 | PREFIX_PRIORITY_LAST, 0, 0); |
42bbc7e6 | 3711 | add_prefix (&include_prefixes, nstore, 0, |
2af84186 | 3712 | PREFIX_PRIORITY_LAST, 0, 0); |
d7a9644e | 3713 | if (*endp == 0) |
3714 | break; | |
3715 | endp = startp = endp + 1; | |
3716 | } | |
3717 | else | |
3718 | endp++; | |
3719 | } | |
3720 | } | |
3721 | ||
f16449b7 | 3722 | GET_ENVIRONMENT (temp, LIBRARY_PATH_ENV); |
c6456dcd | 3723 | if (temp && *cross_compile == '0') |
d7a9644e | 3724 | { |
e40d43cc | 3725 | const char *startp, *endp; |
25a1c410 | 3726 | char *nstore = (char *) alloca (strlen (temp) + 3); |
d7a9644e | 3727 | |
3728 | startp = endp = temp; | |
3729 | while (1) | |
3730 | { | |
99b832c9 | 3731 | if (*endp == PATH_SEPARATOR || *endp == 0) |
d7a9644e | 3732 | { |
026f2c7a | 3733 | strncpy (nstore, startp, endp - startp); |
d7a9644e | 3734 | if (endp == startp) |
4e2023c8 | 3735 | strcpy (nstore, concat (".", dir_separator_str, NULL)); |
79b23a1e | 3736 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
d7a9644e | 3737 | { |
026f2c7a | 3738 | nstore[endp - startp] = DIR_SEPARATOR; |
3739 | nstore[endp - startp + 1] = 0; | |
d7a9644e | 3740 | } |
3741 | else | |
026f2c7a | 3742 | nstore[endp - startp] = 0; |
d946ea19 | 3743 | add_prefix (&startfile_prefixes, nstore, NULL, |
2af84186 | 3744 | PREFIX_PRIORITY_LAST, 0, 1); |
d7a9644e | 3745 | if (*endp == 0) |
3746 | break; | |
3747 | endp = startp = endp + 1; | |
3748 | } | |
3749 | else | |
3750 | endp++; | |
3751 | } | |
3752 | } | |
3753 | ||
3754 | /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ | |
f16449b7 | 3755 | GET_ENVIRONMENT (temp, "LPATH"); |
c6456dcd | 3756 | if (temp && *cross_compile == '0') |
d7a9644e | 3757 | { |
e40d43cc | 3758 | const char *startp, *endp; |
25a1c410 | 3759 | char *nstore = (char *) alloca (strlen (temp) + 3); |
d7a9644e | 3760 | |
3761 | startp = endp = temp; | |
3762 | while (1) | |
3763 | { | |
99b832c9 | 3764 | if (*endp == PATH_SEPARATOR || *endp == 0) |
d7a9644e | 3765 | { |
026f2c7a | 3766 | strncpy (nstore, startp, endp - startp); |
d7a9644e | 3767 | if (endp == startp) |
4e2023c8 | 3768 | strcpy (nstore, concat (".", dir_separator_str, NULL)); |
79b23a1e | 3769 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
d7a9644e | 3770 | { |
026f2c7a | 3771 | nstore[endp - startp] = DIR_SEPARATOR; |
3772 | nstore[endp - startp + 1] = 0; | |
d7a9644e | 3773 | } |
3774 | else | |
026f2c7a | 3775 | nstore[endp - startp] = 0; |
d946ea19 | 3776 | add_prefix (&startfile_prefixes, nstore, NULL, |
2af84186 | 3777 | PREFIX_PRIORITY_LAST, 0, 1); |
d7a9644e | 3778 | if (*endp == 0) |
3779 | break; | |
3780 | endp = startp = endp + 1; | |
3781 | } | |
3782 | else | |
3783 | endp++; | |
3784 | } | |
3785 | } | |
3786 | ||
3787 | /* Scan argv twice. Here, the first time, just count how many switches | |
3788 | there will be in their vector, and how many input files in theirs. | |
3789 | Here we also parse the switches that cc itself uses (e.g. -v). */ | |
3790 | ||
3791 | for (i = 1; i < argc; i++) | |
3792 | { | |
3793 | if (! strcmp (argv[i], "-dumpspecs")) | |
3794 | { | |
988c0ffe | 3795 | struct spec_list *sl; |
810309ce | 3796 | init_spec (); |
988c0ffe | 3797 | for (sl = specs; sl; sl = sl->next) |
3798 | printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec)); | |
026f2c7a | 3799 | if (link_command_spec) |
3800 | printf ("*link_command:\n%s\n\n", link_command_spec); | |
d7a9644e | 3801 | exit (0); |
3802 | } | |
3803 | else if (! strcmp (argv[i], "-dumpversion")) | |
3804 | { | |
997d68fe | 3805 | printf ("%s\n", spec_version); |
d7a9644e | 3806 | exit (0); |
3807 | } | |
1591f84a | 3808 | else if (! strcmp (argv[i], "-dumpmachine")) |
3809 | { | |
3810 | printf ("%s\n", spec_machine); | |
026f2c7a | 3811 | exit (0); |
1591f84a | 3812 | } |
6e50451f | 3813 | else if (strcmp (argv[i], "-fversion") == 0) |
3814 | { | |
3815 | /* translate_options () has turned --version into -fversion. */ | |
39932bd2 | 3816 | print_version = 1; |
3817 | ||
3818 | /* We will be passing a dummy file on to the sub-processes. */ | |
3819 | n_infiles++; | |
3820 | n_switches++; | |
3821 | ||
3822 | /* CPP driver cannot obtain switch from cc1_options. */ | |
3823 | if (is_cpp_driver) | |
3824 | add_preprocessor_option ("--version", strlen ("--version")); | |
3825 | add_assembler_option ("--version", strlen ("--version")); | |
3826 | add_linker_option ("--version", strlen ("--version")); | |
6e50451f | 3827 | } |
8ace789a | 3828 | else if (strcmp (argv[i], "-fhelp") == 0) |
3829 | { | |
3830 | /* translate_options () has turned --help into -fhelp. */ | |
3831 | print_help_list = 1; | |
3832 | ||
3833 | /* We will be passing a dummy file on to the sub-processes. */ | |
3834 | n_infiles++; | |
3835 | n_switches++; | |
2c815aff | 3836 | |
258d3911 | 3837 | /* CPP driver cannot obtain switch from cc1_options. */ |
3838 | if (is_cpp_driver) | |
3839 | add_preprocessor_option ("--help", 6); | |
8ace789a | 3840 | add_assembler_option ("--help", 6); |
3841 | add_linker_option ("--help", 6); | |
3842 | } | |
87c75316 | 3843 | else if (strncmp (argv[i], "-fhelp=", 7) == 0) |
3844 | { | |
3845 | /* translate_options () has turned --help into -fhelp. */ | |
3846 | print_subprocess_help = 2; | |
3847 | ||
3848 | /* We will be passing a dummy file on to the sub-processes. */ | |
3849 | n_infiles++; | |
3850 | n_switches++; | |
3851 | } | |
7a6882ca | 3852 | else if (strcmp (argv[i], "-ftarget-help") == 0) |
3cfec666 | 3853 | { |
3854 | /* translate_options() has turned --target-help into -ftarget-help. */ | |
87c75316 | 3855 | print_subprocess_help = 1; |
7a6882ca | 3856 | |
3cfec666 | 3857 | /* We will be passing a dummy file on to the sub-processes. */ |
3858 | n_infiles++; | |
3859 | n_switches++; | |
7a6882ca | 3860 | |
258d3911 | 3861 | /* CPP driver cannot obtain switch from cc1_options. */ |
3862 | if (is_cpp_driver) | |
3863 | add_preprocessor_option ("--target-help", 13); | |
3cfec666 | 3864 | add_assembler_option ("--target-help", 13); |
3865 | add_linker_option ("--target-help", 13); | |
3866 | } | |
155b05dc | 3867 | else if (! strcmp (argv[i], "-pass-exit-codes")) |
3868 | { | |
3869 | pass_exit_codes = 1; | |
3870 | n_switches++; | |
3871 | } | |
71cee7b1 | 3872 | else if (! strcmp (argv[i], "-print-search-dirs")) |
3873 | print_search_dirs = 1; | |
5e3dea2b | 3874 | else if (! strcmp (argv[i], "-print-libgcc-file-name")) |
71cee7b1 | 3875 | print_file_name = "libgcc.a"; |
1c1a1c70 | 3876 | else if (! strncmp (argv[i], "-print-file-name=", 17)) |
71cee7b1 | 3877 | print_file_name = argv[i] + 17; |
1c1a1c70 | 3878 | else if (! strncmp (argv[i], "-print-prog-name=", 17)) |
71cee7b1 | 3879 | print_prog_name = argv[i] + 17; |
9577d478 | 3880 | else if (! strcmp (argv[i], "-print-multi-lib")) |
3881 | print_multi_lib = 1; | |
3882 | else if (! strcmp (argv[i], "-print-multi-directory")) | |
3883 | print_multi_directory = 1; | |
098cc23f | 3884 | else if (! strcmp (argv[i], "-print-sysroot")) |
3885 | print_sysroot = 1; | |
c954ff02 | 3886 | else if (! strcmp (argv[i], "-print-multi-os-directory")) |
3887 | print_multi_os_directory = 1; | |
6ea4242f | 3888 | else if (! strcmp (argv[i], "-print-sysroot-headers-suffix")) |
3889 | print_sysroot_headers_suffix = 1; | |
71278019 | 3890 | else if (! strcmp (argv[i], "-fcompare-debug-second")) |
3891 | { | |
3892 | compare_debug_second = 1; | |
3893 | n_switches++; | |
3894 | } | |
3895 | else if (! strcmp (argv[i], "-fno-compare-debug")) | |
3896 | { | |
3897 | argv[i] = "-fcompare-debug="; | |
3898 | goto compare_debug_with_arg; | |
3899 | } | |
3900 | else if (! strcmp (argv[i], "-fcompare-debug")) | |
3901 | { | |
3902 | argv[i] = "-fcompare-debug=-gtoggle"; | |
3903 | goto compare_debug_with_arg; | |
3904 | } | |
3905 | #define OPT "-fcompare-debug=" | |
3906 | else if (! strncmp (argv[i], OPT, sizeof (OPT) - 1)) | |
3907 | { | |
3908 | const char *opt; | |
3909 | compare_debug_with_arg: | |
3910 | opt = argv[i] + sizeof (OPT) - 1; | |
3911 | #undef OPT | |
3912 | if (*opt) | |
3913 | compare_debug = 1; | |
3914 | else | |
3915 | compare_debug = -1; | |
3916 | if (compare_debug < 0) | |
3917 | compare_debug_opt = NULL; | |
3918 | else | |
3919 | compare_debug_opt = opt; | |
3920 | n_switches++; | |
3921 | } | |
69587571 | 3922 | else if (! strncmp (argv[i], "-Wa,", 4)) |
3923 | { | |
3924 | int prev, j; | |
3925 | /* Pass the rest of this option to the assembler. */ | |
3926 | ||
69587571 | 3927 | /* Split the argument at commas. */ |
3928 | prev = 4; | |
3929 | for (j = 4; argv[i][j]; j++) | |
3930 | if (argv[i][j] == ',') | |
3931 | { | |
8ace789a | 3932 | add_assembler_option (argv[i] + prev, j - prev); |
69587571 | 3933 | prev = j + 1; |
3934 | } | |
2c815aff | 3935 | |
69587571 | 3936 | /* Record the part after the last comma. */ |
8ace789a | 3937 | add_assembler_option (argv[i] + prev, j - prev); |
69587571 | 3938 | } |
391d9b6e | 3939 | else if (! strncmp (argv[i], "-Wp,", 4)) |
3940 | { | |
3941 | int prev, j; | |
3942 | /* Pass the rest of this option to the preprocessor. */ | |
3943 | ||
391d9b6e | 3944 | /* Split the argument at commas. */ |
3945 | prev = 4; | |
3946 | for (j = 4; argv[i][j]; j++) | |
3947 | if (argv[i][j] == ',') | |
3948 | { | |
8ace789a | 3949 | add_preprocessor_option (argv[i] + prev, j - prev); |
391d9b6e | 3950 | prev = j + 1; |
3951 | } | |
2c815aff | 3952 | |
391d9b6e | 3953 | /* Record the part after the last comma. */ |
8ace789a | 3954 | add_preprocessor_option (argv[i] + prev, j - prev); |
391d9b6e | 3955 | } |
2266b13d | 3956 | else if (argv[i][0] == '+' && argv[i][1] == 'e') |
62daf19f | 3957 | /* The +e options to the C++ front-end. */ |
2266b13d | 3958 | n_switches++; |
fcdc45aa | 3959 | else if (strncmp (argv[i], "-Wl,", 4) == 0) |
4c4f1912 | 3960 | { |
3961 | int j; | |
3962 | /* Split the argument at commas. */ | |
3963 | for (j = 3; argv[i][j]; j++) | |
3964 | n_infiles += (argv[i][j] == ','); | |
3965 | } | |
fcdc45aa | 3966 | else if (strcmp (argv[i], "-Xlinker") == 0) |
3967 | { | |
3968 | if (i + 1 == argc) | |
1e5fcbe2 | 3969 | fatal ("argument to '-Xlinker' is missing"); |
fcdc45aa | 3970 | |
6f38252e | 3971 | n_infiles++; |
3972 | i++; | |
3973 | } | |
805e22b2 | 3974 | else if (strcmp (argv[i], "-Xpreprocessor") == 0) |
3975 | { | |
3976 | if (i + 1 == argc) | |
1e5fcbe2 | 3977 | fatal ("argument to '-Xpreprocessor' is missing"); |
805e22b2 | 3978 | |
3979 | add_preprocessor_option (argv[i+1], strlen (argv[i+1])); | |
3980 | } | |
3981 | else if (strcmp (argv[i], "-Xassembler") == 0) | |
3982 | { | |
3983 | if (i + 1 == argc) | |
1e5fcbe2 | 3984 | fatal ("argument to '-Xassembler' is missing"); |
805e22b2 | 3985 | |
3986 | add_assembler_option (argv[i+1], strlen (argv[i+1])); | |
3987 | } | |
6f38252e | 3988 | else if (strcmp (argv[i], "-l") == 0) |
3989 | { | |
3990 | if (i + 1 == argc) | |
1e5fcbe2 | 3991 | fatal ("argument to '-l' is missing"); |
6f38252e | 3992 | |
fcdc45aa | 3993 | n_infiles++; |
3994 | i++; | |
3995 | } | |
3996 | else if (strncmp (argv[i], "-l", 2) == 0) | |
3997 | n_infiles++; | |
e71cc307 | 3998 | else if (strcmp (argv[i], "-save-temps") == 0) |
3999 | { | |
cc92bc82 | 4000 | save_temps_flag = SAVE_TEMPS_CWD; |
4001 | n_switches++; | |
4002 | } | |
4003 | else if (strncmp (argv[i], "-save-temps=", 12) == 0) | |
4004 | { | |
e71cc307 | 4005 | n_switches++; |
cc92bc82 | 4006 | if (strcmp (argv[i]+12, "cwd") == 0) |
4007 | save_temps_flag = SAVE_TEMPS_CWD; | |
4008 | else if (strcmp (argv[i]+12, "obj") == 0 | |
4009 | || strcmp (argv[i]+12, "object") == 0) | |
4010 | save_temps_flag = SAVE_TEMPS_OBJ; | |
4011 | else | |
4012 | fatal ("'%s' is an unknown -save-temps option", argv[i]); | |
e71cc307 | 4013 | } |
d05a1771 | 4014 | else if (strcmp (argv[i], "-no-canonical-prefixes") == 0) |
4015 | /* Already handled as a special case, so ignored here. */ | |
4016 | ; | |
dc1dd09b | 4017 | else if (strcmp (argv[i], "-combine") == 0) |
4018 | { | |
4019 | combine_flag = 1; | |
4020 | n_switches++; | |
4021 | } | |
9d70d39c | 4022 | else if (strcmp (argv[i], "-specs") == 0) |
4023 | { | |
4c36ffe6 | 4024 | struct user_specs *user = XNEW (struct user_specs); |
9d70d39c | 4025 | if (++i >= argc) |
1e5fcbe2 | 4026 | fatal ("argument to '-specs' is missing"); |
9d70d39c | 4027 | |
2c815aff | 4028 | user->next = (struct user_specs *) 0; |
9d70d39c | 4029 | user->filename = argv[i]; |
4030 | if (user_specs_tail) | |
4031 | user_specs_tail->next = user; | |
4032 | else | |
4033 | user_specs_head = user; | |
4034 | user_specs_tail = user; | |
4035 | } | |
4036 | else if (strncmp (argv[i], "-specs=", 7) == 0) | |
4037 | { | |
4c36ffe6 | 4038 | struct user_specs *user = XNEW (struct user_specs); |
9d70d39c | 4039 | if (strlen (argv[i]) == 7) |
1e5fcbe2 | 4040 | fatal ("argument to '-specs=' is missing"); |
9d70d39c | 4041 | |
2c815aff | 4042 | user->next = (struct user_specs *) 0; |
026f2c7a | 4043 | user->filename = argv[i] + 7; |
9d70d39c | 4044 | if (user_specs_tail) |
4045 | user_specs_tail->next = user; | |
4046 | else | |
4047 | user_specs_head = user; | |
4048 | user_specs_tail = user; | |
4049 | } | |
a876e5f8 | 4050 | else if (strcmp (argv[i], "-time") == 0) |
4051 | report_times = 1; | |
4537c5d9 | 4052 | else if (strncmp (argv[i], "-time=", sizeof ("-time=") - 1) == 0) |
4053 | { | |
4054 | if (report_times_to_file) | |
4055 | fclose (report_times_to_file); | |
4056 | report_times_to_file = fopen (argv[i] + sizeof ("-time=") - 1, "a"); | |
4057 | } | |
805e22b2 | 4058 | else if (strcmp (argv[i], "-pipe") == 0) |
4059 | { | |
4060 | /* -pipe has to go into the switches array as well as | |
4061 | setting a flag. */ | |
4062 | use_pipes = 1; | |
4063 | n_switches++; | |
4064 | } | |
0bfd146e | 4065 | else if (strcmp (argv[i], "-wrapper") == 0) |
4066 | { | |
4067 | if (++i >= argc) | |
4068 | fatal ("argument to '-wrapper' is missing"); | |
4069 | ||
4070 | wrapper_string = argv[i]; | |
4071 | n_switches++; | |
4072 | n_switches++; | |
4073 | } | |
74e4079a | 4074 | else if (strcmp (argv[i], "-###") == 0) |
4075 | { | |
4076 | /* This is similar to -v except that there is no execution | |
4077 | of the commands and the echoed arguments are quoted. It | |
4078 | is intended for use in shell scripts to capture the | |
4079 | driver-generated command line. */ | |
4080 | verbose_only_flag++; | |
4081 | verbose_flag++; | |
4082 | } | |
fcdc45aa | 4083 | else if (argv[i][0] == '-' && argv[i][1] != 0) |
d7a9644e | 4084 | { |
19cb6b50 | 4085 | const char *p = &argv[i][1]; |
4086 | int c = *p; | |
d7a9644e | 4087 | |
4088 | switch (c) | |
4089 | { | |
4090 | case 'b': | |
43315373 | 4091 | if (p[1] && NULL == strchr (argv[i] + 2, '-')) |
fb244a46 | 4092 | goto normal_switch; |
4093 | ||
4094 | /* Fall through. */ | |
3443e1be | 4095 | case 'V': |
1e5fcbe2 | 4096 | fatal ("'-%c' must come at the start of the command line", c); |
d7a9644e | 4097 | break; |
4098 | ||
4099 | case 'B': | |
4100 | { | |
2508fdc3 | 4101 | const char *value; |
68a20780 | 4102 | int len; |
4103 | ||
d7a9644e | 4104 | if (p[1] == 0 && i + 1 == argc) |
1e5fcbe2 | 4105 | fatal ("argument to '-B' is missing"); |
d7a9644e | 4106 | if (p[1] == 0) |
4107 | value = argv[++i]; | |
4108 | else | |
4109 | value = p + 1; | |
68a20780 | 4110 | |
4111 | len = strlen (value); | |
4112 | ||
4113 | /* Catch the case where the user has forgotten to append a | |
9bccb7a3 | 4114 | directory separator to the path. Note, they may be using |
68a20780 | 4115 | -B to add an executable name prefix, eg "i386-elf-", in |
4116 | order to distinguish between multiple installations of | |
4117 | GCC in the same directory. Hence we must check to see | |
4118 | if appending a directory separator actually makes a | |
4119 | valid directory name. */ | |
4120 | if (! IS_DIR_SEPARATOR (value [len - 1]) | |
067277c3 | 4121 | && is_directory (value, false)) |
68a20780 | 4122 | { |
4c36ffe6 | 4123 | char *tmp = XNEWVEC (char, len + 2); |
6e1bbca9 | 4124 | strcpy (tmp, value); |
4125 | tmp[len] = DIR_SEPARATOR; | |
4126 | tmp[++ len] = 0; | |
4127 | value = tmp; | |
68a20780 | 4128 | } |
3cfec666 | 4129 | |
d946ea19 | 4130 | add_prefix (&exec_prefixes, value, NULL, |
2af84186 | 4131 | PREFIX_PRIORITY_B_OPT, 0, 0); |
d946ea19 | 4132 | add_prefix (&startfile_prefixes, value, NULL, |
2af84186 | 4133 | PREFIX_PRIORITY_B_OPT, 0, 0); |
42bbc7e6 | 4134 | add_prefix (&include_prefixes, value, NULL, |
2af84186 | 4135 | PREFIX_PRIORITY_B_OPT, 0, 0); |
026f2c7a | 4136 | n_switches++; |
d7a9644e | 4137 | } |
4138 | break; | |
4139 | ||
4140 | case 'v': /* Print our subcommands and print versions. */ | |
d7a9644e | 4141 | n_switches++; |
3e4aaf67 | 4142 | /* If they do anything other than exactly `-v', don't set |
4143 | verbose_flag; rather, continue on to give the error. */ | |
4144 | if (p[1] != 0) | |
4145 | break; | |
4146 | verbose_flag++; | |
d7a9644e | 4147 | break; |
4148 | ||
42fe96d7 | 4149 | case 'S': |
e71cc307 | 4150 | case 'c': |
a2000777 | 4151 | case 'E': |
e71cc307 | 4152 | if (p[1] == 0) |
d7a9644e | 4153 | { |
e71cc307 | 4154 | have_c = 1; |
bfef3e2f | 4155 | n_switches++; |
d7a9644e | 4156 | break; |
4157 | } | |
4ac725ee | 4158 | goto normal_switch; |
53ff1753 | 4159 | |
53ff1753 | 4160 | case 'o': |
89dfd38d | 4161 | have_o = 1; |
10f57222 | 4162 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
42fe96d7 | 4163 | if (! have_c) |
4164 | { | |
4165 | int skip; | |
2c815aff | 4166 | |
a2000777 | 4167 | /* Forward scan, just in case -S, -E or -c is specified |
42fe96d7 | 4168 | after -o. */ |
4169 | int j = i + 1; | |
4170 | if (p[1] == 0) | |
4171 | ++j; | |
4172 | while (j < argc) | |
4173 | { | |
4174 | if (argv[j][0] == '-') | |
4175 | { | |
4176 | if (SWITCH_CURTAILS_COMPILATION (argv[j][1]) | |
4177 | && argv[j][2] == 0) | |
4178 | { | |
4179 | have_c = 1; | |
4180 | break; | |
4181 | } | |
f7359493 | 4182 | else if ((skip = SWITCH_TAKES_ARG (argv[j][1]))) |
42fe96d7 | 4183 | j += skip - (argv[j][2] != 0); |
f7359493 | 4184 | else if ((skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))) |
42fe96d7 | 4185 | j += skip; |
4186 | } | |
4187 | j++; | |
4188 | } | |
4189 | } | |
4190 | #endif | |
10f57222 | 4191 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX) |
2e58e75e | 4192 | if (p[1] == 0) |
c5025ad6 | 4193 | argv[i + 1] = convert_filename (argv[i + 1], ! have_c, 0); |
42fe96d7 | 4194 | else |
c5025ad6 | 4195 | argv[i] = convert_filename (argv[i], ! have_c, 0); |
2e58e75e | 4196 | #endif |
cc92bc82 | 4197 | /* Save the output name in case -save-temps=obj was used. */ |
aa052e98 | 4198 | if ((p[1] == 0) && argv[i + 1]) |
4199 | save_temps_prefix = xstrdup(argv[i + 1]); | |
4200 | else | |
4201 | save_temps_prefix = xstrdup(argv[i] + 1); | |
4ac725ee | 4202 | goto normal_switch; |
53ff1753 | 4203 | |
d7a9644e | 4204 | default: |
4ac725ee | 4205 | normal_switch: |
d2537617 | 4206 | |
4207 | #ifdef MODIFY_TARGET_NAME | |
4208 | is_modify_target_name = 0; | |
4209 | ||
3585dac7 | 4210 | for (j = 0; j < ARRAY_SIZE (modify_target); j++) |
d2537617 | 4211 | if (! strcmp (argv[i], modify_target[j].sw)) |
4212 | { | |
225ab426 | 4213 | char *new_name = XNEWVEC (char, strlen (modify_target[j].str) |
f0af5a88 | 4214 | + strlen (spec_machine)); |
d2537617 | 4215 | const char *p, *r; |
4216 | char *q; | |
4217 | int made_addition = 0; | |
4218 | ||
4219 | is_modify_target_name = 1; | |
4220 | for (p = spec_machine, q = new_name; *p != 0; ) | |
4221 | { | |
4222 | if (modify_target[j].add_del == DELETE | |
4223 | && (! strncmp (q, modify_target[j].str, | |
4224 | strlen (modify_target[j].str)))) | |
4225 | p += strlen (modify_target[j].str); | |
4226 | else if (modify_target[j].add_del == ADD | |
4227 | && ! made_addition && *p == '-') | |
4228 | { | |
4229 | for (r = modify_target[j].str; *r != 0; ) | |
4230 | *q++ = *r++; | |
4231 | made_addition = 1; | |
4232 | } | |
4233 | ||
4234 | *q++ = *p++; | |
4235 | } | |
4236 | ||
4237 | spec_machine = new_name; | |
4238 | } | |
4239 | ||
4240 | if (is_modify_target_name) | |
4241 | break; | |
3cfec666 | 4242 | #endif |
d2537617 | 4243 | |
d7a9644e | 4244 | n_switches++; |
4245 | ||
4246 | if (SWITCH_TAKES_ARG (c) > (p[1] != 0)) | |
4247 | i += SWITCH_TAKES_ARG (c) - (p[1] != 0); | |
4248 | else if (WORD_SWITCH_TAKES_ARG (p)) | |
4249 | i += WORD_SWITCH_TAKES_ARG (p); | |
4250 | } | |
4251 | } | |
4252 | else | |
e71cc307 | 4253 | { |
4254 | n_infiles++; | |
4255 | lang_n_infiles++; | |
4256 | } | |
d7a9644e | 4257 | } |
4258 | ||
cc92bc82 | 4259 | /* If -save-temps=obj and -o name, create the prefix to use for %b. |
4260 | Otherwise just make -save-temps=obj the same as -save-temps=cwd. */ | |
4261 | if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL) | |
4262 | { | |
4263 | save_temps_length = strlen (save_temps_prefix); | |
4264 | temp = strrchr (lbasename (save_temps_prefix), '.'); | |
4265 | if (temp) | |
4266 | { | |
4267 | save_temps_length -= strlen (temp); | |
4268 | save_temps_prefix[save_temps_length] = '\0'; | |
4269 | } | |
4270 | ||
4271 | } | |
4272 | else if (save_temps_prefix != NULL) | |
4273 | { | |
4274 | free (save_temps_prefix); | |
4275 | save_temps_prefix = NULL; | |
4276 | } | |
4277 | ||
288e5bba | 4278 | if (save_temps_flag && use_pipes) |
805e22b2 | 4279 | { |
4280 | /* -save-temps overrides -pipe, so that temp files are produced */ | |
4281 | if (save_temps_flag) | |
4282 | error ("warning: -pipe ignored because -save-temps specified"); | |
805e22b2 | 4283 | use_pipes = 0; |
4284 | } | |
952f0048 | 4285 | |
71278019 | 4286 | if (!compare_debug) |
4287 | { | |
4288 | const char *gcd = getenv ("GCC_COMPARE_DEBUG"); | |
4289 | ||
4290 | if (gcd && gcd[0] == '-') | |
4291 | { | |
4292 | compare_debug = 2; | |
4293 | compare_debug_opt = gcd; | |
4294 | n_switches++; | |
4295 | } | |
4296 | else if (gcd && *gcd && strcmp (gcd, "0")) | |
4297 | { | |
4298 | compare_debug = 3; | |
4299 | compare_debug_opt = "-gtoggle"; | |
4300 | n_switches++; | |
4301 | } | |
4302 | } | |
4303 | else if (compare_debug < 0) | |
4304 | { | |
4305 | compare_debug = 0; | |
4306 | gcc_assert (!compare_debug_opt); | |
4307 | } | |
4308 | ||
c4328bcc | 4309 | /* Set up the search paths. We add directories that we expect to |
4310 | contain GNU Toolchain components before directories specified by | |
4311 | the machine description so that we will find GNU components (like | |
48e1416a | 4312 | the GNU assembler) before those of the host system. */ |
d7a9644e | 4313 | |
c4328bcc | 4314 | /* If we don't know where the toolchain has been installed, use the |
4315 | configured-in locations. */ | |
4316 | if (!gcc_exec_prefix) | |
4317 | { | |
b9374a77 | 4318 | #ifndef OS2 |
c4328bcc | 4319 | add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC", |
4320 | PREFIX_PRIORITY_LAST, 1, 0); | |
4321 | add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS", | |
4322 | PREFIX_PRIORITY_LAST, 2, 0); | |
4323 | add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS", | |
4324 | PREFIX_PRIORITY_LAST, 2, 0); | |
b9374a77 | 4325 | #endif |
c4328bcc | 4326 | add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS", |
4327 | PREFIX_PRIORITY_LAST, 1, 0); | |
4328 | } | |
d7a9644e | 4329 | |
c4328bcc | 4330 | gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix)); |
2c815aff | 4331 | tooldir_prefix = concat (tooldir_base_prefix, spec_machine, |
4e2023c8 | 4332 | dir_separator_str, NULL); |
6c6aff9e | 4333 | |
c4328bcc | 4334 | /* Look for tools relative to the location from which the driver is |
4335 | running, or, if that is not available, the configured prefix. */ | |
4336 | tooldir_prefix | |
4337 | = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix, | |
4338 | spec_machine, dir_separator_str, | |
4339 | spec_version, dir_separator_str, tooldir_prefix, NULL); | |
6c6aff9e | 4340 | |
2c815aff | 4341 | add_prefix (&exec_prefixes, |
4e2023c8 | 4342 | concat (tooldir_prefix, "bin", dir_separator_str, NULL), |
2af84186 | 4343 | "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0); |
b9374a77 | 4344 | add_prefix (&startfile_prefixes, |
4e2023c8 | 4345 | concat (tooldir_prefix, "lib", dir_separator_str, NULL), |
2af84186 | 4346 | "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1); |
06e67e16 | 4347 | |
17acc97a | 4348 | #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS) |
4349 | /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix, | |
4350 | then consider it to relocate with the rest of the GCC installation | |
4351 | if GCC_EXEC_PREFIX is set. | |
4352 | ``make_relative_prefix'' is not compiled for VMS, so don't call it. */ | |
805e22b2 | 4353 | if (target_system_root && gcc_exec_prefix) |
4354 | { | |
d05a1771 | 4355 | char *tmp_prefix = get_relative_prefix (argv[0], |
4356 | standard_bindir_prefix, | |
4357 | target_system_root); | |
805e22b2 | 4358 | if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0) |
17acc97a | 4359 | { |
4360 | target_system_root = tmp_prefix; | |
4361 | target_system_root_changed = 1; | |
4362 | } | |
805e22b2 | 4363 | } |
17acc97a | 4364 | #endif |
805e22b2 | 4365 | |
a45072dd | 4366 | /* More prefixes are enabled in main, after we read the specs file |
4367 | and determine whether this is cross-compilation or not. */ | |
d7a9644e | 4368 | |
d7a9644e | 4369 | /* Then create the space for the vectors and scan again. */ |
4370 | ||
4c36ffe6 | 4371 | switches = XNEWVEC (struct switchstr, n_switches + 1); |
4372 | infiles = XNEWVEC (struct infile, n_infiles + 1); | |
d7a9644e | 4373 | n_switches = 0; |
4374 | n_infiles = 0; | |
4375 | last_language_n_infiles = -1; | |
4376 | ||
4377 | /* This, time, copy the text of each switch and store a pointer | |
4378 | to the copy in the vector of switches. | |
4379 | Store all the infiles in their vector. */ | |
4380 | ||
4381 | for (i = 1; i < argc; i++) | |
4382 | { | |
9cab0da7 | 4383 | /* Just skip the switches that were handled by the preceding loop. */ |
d2537617 | 4384 | #ifdef MODIFY_TARGET_NAME |
4385 | is_modify_target_name = 0; | |
4386 | ||
3585dac7 | 4387 | for (j = 0; j < ARRAY_SIZE (modify_target); j++) |
d2537617 | 4388 | if (! strcmp (argv[i], modify_target[j].sw)) |
4389 | is_modify_target_name = 1; | |
4390 | ||
4391 | if (is_modify_target_name) | |
4392 | ; | |
4393 | else | |
4394 | #endif | |
fcdc45aa | 4395 | if (! strncmp (argv[i], "-Wa,", 4)) |
9cab0da7 | 4396 | ; |
391d9b6e | 4397 | else if (! strncmp (argv[i], "-Wp,", 4)) |
4398 | ; | |
d05a1771 | 4399 | else if (! strcmp (argv[i], "-no-canonical-prefixes")) |
4400 | ; | |
155b05dc | 4401 | else if (! strcmp (argv[i], "-pass-exit-codes")) |
4402 | ; | |
71cee7b1 | 4403 | else if (! strcmp (argv[i], "-print-search-dirs")) |
4404 | ; | |
5e3dea2b | 4405 | else if (! strcmp (argv[i], "-print-libgcc-file-name")) |
9cab0da7 | 4406 | ; |
1c1a1c70 | 4407 | else if (! strncmp (argv[i], "-print-file-name=", 17)) |
4408 | ; | |
4409 | else if (! strncmp (argv[i], "-print-prog-name=", 17)) | |
4410 | ; | |
9577d478 | 4411 | else if (! strcmp (argv[i], "-print-multi-lib")) |
4412 | ; | |
4413 | else if (! strcmp (argv[i], "-print-multi-directory")) | |
4414 | ; | |
098cc23f | 4415 | else if (! strcmp (argv[i], "-print-sysroot")) |
4416 | ; | |
c954ff02 | 4417 | else if (! strcmp (argv[i], "-print-multi-os-directory")) |
4418 | ; | |
6ea4242f | 4419 | else if (! strcmp (argv[i], "-print-sysroot-headers-suffix")) |
4420 | ; | |
a99be165 | 4421 | else if (! strncmp (argv[i], "--sysroot=", strlen ("--sysroot="))) |
4422 | { | |
4423 | target_system_root = argv[i] + strlen ("--sysroot="); | |
4424 | target_system_root_changed = 1; | |
4425 | } | |
5caedb3c | 4426 | else if (argv[i][0] == '+' && argv[i][1] == 'e') |
4427 | { | |
4428 | /* Compensate for the +e options to the C++ front-end; | |
91a48688 | 4429 | they're there simply for cfront call-compatibility. We do |
5caedb3c | 4430 | some magic in default_compilers to pass them down properly. |
4431 | Note we deliberately start at the `+' here, to avoid passing | |
4432 | -e0 or -e1 down into the linker. */ | |
4433 | switches[n_switches].part1 = &argv[i][0]; | |
4434 | switches[n_switches].args = 0; | |
79d52444 | 4435 | switches[n_switches].live_cond = 0; |
be2828ce | 4436 | switches[n_switches].validated = 0; |
5caedb3c | 4437 | n_switches++; |
4438 | } | |
fcdc45aa | 4439 | else if (strncmp (argv[i], "-Wl,", 4) == 0) |
4440 | { | |
4c4f1912 | 4441 | int prev, j; |
4442 | /* Split the argument at commas. */ | |
4443 | prev = 4; | |
4444 | for (j = 4; argv[i][j]; j++) | |
4445 | if (argv[i][j] == ',') | |
4446 | { | |
997d68fe | 4447 | infiles[n_infiles].language = "*"; |
4c4f1912 | 4448 | infiles[n_infiles++].name |
4449 | = save_string (argv[i] + prev, j - prev); | |
4450 | prev = j + 1; | |
4451 | } | |
4452 | /* Record the part after the last comma. */ | |
997d68fe | 4453 | infiles[n_infiles].language = "*"; |
4c4f1912 | 4454 | infiles[n_infiles++].name = argv[i] + prev; |
fcdc45aa | 4455 | } |
4456 | else if (strcmp (argv[i], "-Xlinker") == 0) | |
4457 | { | |
997d68fe | 4458 | infiles[n_infiles].language = "*"; |
fcdc45aa | 4459 | infiles[n_infiles++].name = argv[++i]; |
4460 | } | |
cdc02080 | 4461 | /* Xassembler and Xpreprocessor were already handled in the first argv |
4462 | scan, so all we need to do here is ignore them and their argument. */ | |
805e22b2 | 4463 | else if (strcmp (argv[i], "-Xassembler") == 0) |
cdc02080 | 4464 | i++; |
805e22b2 | 4465 | else if (strcmp (argv[i], "-Xpreprocessor") == 0) |
cdc02080 | 4466 | i++; |
6f38252e | 4467 | else if (strcmp (argv[i], "-l") == 0) |
4468 | { /* POSIX allows separation of -l and the lib arg; | |
4469 | canonicalize by concatenating -l with its arg */ | |
4470 | infiles[n_infiles].language = "*"; | |
4e2023c8 | 4471 | infiles[n_infiles++].name = concat ("-l", argv[++i], NULL); |
6f38252e | 4472 | } |
fcdc45aa | 4473 | else if (strncmp (argv[i], "-l", 2) == 0) |
4474 | { | |
997d68fe | 4475 | infiles[n_infiles].language = "*"; |
fcdc45aa | 4476 | infiles[n_infiles++].name = argv[i]; |
4477 | } | |
0bfd146e | 4478 | else if (strcmp (argv[i], "-wrapper") == 0) |
4479 | i++; | |
9d70d39c | 4480 | else if (strcmp (argv[i], "-specs") == 0) |
4481 | i++; | |
4482 | else if (strncmp (argv[i], "-specs=", 7) == 0) | |
4483 | ; | |
a876e5f8 | 4484 | else if (strcmp (argv[i], "-time") == 0) |
4485 | ; | |
4537c5d9 | 4486 | else if (strncmp (argv[i], "-time=", sizeof ("-time=") - 1) == 0) |
4487 | ; | |
74e4079a | 4488 | else if (strcmp (argv[i], "-###") == 0) |
4489 | ; | |
fcdc45aa | 4490 | else if (argv[i][0] == '-' && argv[i][1] != 0) |
d7a9644e | 4491 | { |
2508fdc3 | 4492 | const char *p = &argv[i][1]; |
4493 | int c = *p; | |
d7a9644e | 4494 | |
d7a9644e | 4495 | if (c == 'x') |
4496 | { | |
4497 | if (p[1] == 0 && i + 1 == argc) | |
1e5fcbe2 | 4498 | fatal ("argument to '-x' is missing"); |
d7a9644e | 4499 | if (p[1] == 0) |
4500 | spec_lang = argv[++i]; | |
4501 | else | |
4502 | spec_lang = p + 1; | |
4503 | if (! strcmp (spec_lang, "none")) | |
747bd44c | 4504 | /* Suppress the warning if -xnone comes after the last input |
4505 | file, because alternate command interfaces like g++ might | |
4506 | find it useful to place -xnone after each input file. */ | |
d7a9644e | 4507 | spec_lang = 0; |
4508 | else | |
4509 | last_language_n_infiles = n_infiles; | |
4510 | continue; | |
4511 | } | |
4512 | switches[n_switches].part1 = p; | |
4513 | /* Deal with option arguments in separate argv elements. */ | |
4514 | if ((SWITCH_TAKES_ARG (c) > (p[1] != 0)) | |
54959bb0 | 4515 | || WORD_SWITCH_TAKES_ARG (p)) |
4516 | { | |
4517 | int j = 0; | |
4518 | int n_args = WORD_SWITCH_TAKES_ARG (p); | |
d7a9644e | 4519 | |
54959bb0 | 4520 | if (n_args == 0) |
4521 | { | |
4522 | /* Count only the option arguments in separate argv elements. */ | |
4523 | n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0); | |
4524 | } | |
4525 | if (i + n_args >= argc) | |
1e5fcbe2 | 4526 | fatal ("argument to '-%s' is missing", p); |
54959bb0 | 4527 | switches[n_switches].args |
4c36ffe6 | 4528 | = XNEWVEC (const char *, n_args + 1); |
54959bb0 | 4529 | while (j < n_args) |
4530 | switches[n_switches].args[j++] = argv[++i]; | |
4531 | /* Null-terminate the vector. */ | |
4532 | switches[n_switches].args[j] = 0; | |
d7a9644e | 4533 | } |
78dbff7c | 4534 | else if (strchr (switches_need_spaces, c)) |
54959bb0 | 4535 | { |
08309729 | 4536 | /* On some systems, ld cannot handle some options without |
4537 | a space. So split the option from its argument. */ | |
4c36ffe6 | 4538 | char *part1 = XNEWVEC (char, 2); |
08309729 | 4539 | part1[0] = c; |
4540 | part1[1] = '\0'; | |
2c815aff | 4541 | |
08309729 | 4542 | switches[n_switches].part1 = part1; |
4c36ffe6 | 4543 | switches[n_switches].args = XNEWVEC (const char *, 2); |
47950139 | 4544 | switches[n_switches].args[0] = xstrdup (p+1); |
54959bb0 | 4545 | switches[n_switches].args[1] = 0; |
4546 | } | |
4547 | else | |
d7a9644e | 4548 | switches[n_switches].args = 0; |
cde688ab | 4549 | |
79d52444 | 4550 | switches[n_switches].live_cond = 0; |
be2828ce | 4551 | switches[n_switches].validated = 0; |
63d882f5 | 4552 | switches[n_switches].ordering = 0; |
9a61fba1 | 4553 | /* These are always valid, since gcc.c itself understands the |
4554 | first four and gfortranspec.c understands -static-libgfortran. */ | |
43198b29 | 4555 | if (!strcmp (p, "save-temps") |
4556 | || !strcmp (p, "static-libgcc") | |
805e22b2 | 4557 | || !strcmp (p, "shared-libgcc") |
9a61fba1 | 4558 | || !strcmp (p, "pipe") |
4559 | || !strcmp (p, "static-libgfortran")) | |
be2828ce | 4560 | switches[n_switches].validated = 1; |
026f2c7a | 4561 | else |
4562 | { | |
4563 | char ch = switches[n_switches].part1[0]; | |
3443e1be | 4564 | if (ch == 'B') |
026f2c7a | 4565 | switches[n_switches].validated = 1; |
4566 | } | |
d7a9644e | 4567 | n_switches++; |
4568 | } | |
4569 | else | |
4570 | { | |
06b9e52b | 4571 | const char *p = strchr (argv[i], '@'); |
4572 | char *fname; | |
10f57222 | 4573 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
c5025ad6 | 4574 | argv[i] = convert_filename (argv[i], 0, access (argv[i], F_OK)); |
9ec04dd9 | 4575 | #endif |
06b9e52b | 4576 | if (!p) |
4577 | fname = xstrdup (argv[i]); | |
4578 | else | |
4579 | { | |
4580 | fname = (char *)xmalloc (p - argv[i] + 1); | |
4581 | memcpy (fname, argv[i], p - argv[i]); | |
4582 | fname[p - argv[i]] = '\0'; | |
4583 | } | |
4584 | ||
4585 | if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) | |
4586 | { | |
4587 | perror_with_name (fname); | |
4588 | error_count++; | |
4589 | } | |
4590 | else | |
4591 | { | |
4592 | infiles[n_infiles].language = spec_lang; | |
4593 | infiles[n_infiles++].name = argv[i]; | |
4594 | } | |
4595 | ||
4596 | free (fname); | |
d7a9644e | 4597 | } |
4598 | } | |
4599 | ||
b0e7b414 | 4600 | if (n_infiles == last_language_n_infiles && spec_lang != 0) |
1e5fcbe2 | 4601 | error ("warning: '-x %s' after last input file has no effect", spec_lang); |
d7a9644e | 4602 | |
71278019 | 4603 | if (compare_debug == 2 || compare_debug == 3) |
4604 | { | |
4605 | switches[n_switches].part1 = concat ("fcompare-debug=", | |
4606 | compare_debug_opt, | |
4607 | NULL); | |
4608 | switches[n_switches].args = 0; | |
4609 | switches[n_switches].live_cond = 0; | |
4610 | switches[n_switches].validated = 0; | |
4611 | switches[n_switches].ordering = 0; | |
4612 | n_switches++; | |
4613 | compare_debug = 1; | |
4614 | } | |
4615 | ||
258d3911 | 4616 | /* Ensure we only invoke each subprocess once. */ |
39932bd2 | 4617 | if (print_subprocess_help || print_help_list || print_version) |
258d3911 | 4618 | { |
4619 | n_infiles = 1; | |
4620 | ||
87c75316 | 4621 | /* Create a dummy input file, so that we can pass |
4622 | the help option on to the various sub-processes. */ | |
258d3911 | 4623 | infiles[0].language = "c"; |
4624 | infiles[0].name = "help-dummy"; | |
258d3911 | 4625 | } |
4626 | ||
d7a9644e | 4627 | switches[n_switches].part1 = 0; |
4628 | infiles[n_infiles].name = 0; | |
4629 | } | |
32d661fc | 4630 | |
805e22b2 | 4631 | /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS |
32d661fc | 4632 | and place that in the environment. */ |
4633 | ||
4634 | static void | |
952f0048 | 4635 | set_collect_gcc_options (void) |
32d661fc | 4636 | { |
4637 | int i; | |
4638 | int first_time; | |
4639 | ||
4640 | /* Build COLLECT_GCC_OPTIONS to have all of the options specified to | |
4641 | the compiler. */ | |
4642 | obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=", | |
4643 | sizeof ("COLLECT_GCC_OPTIONS=") - 1); | |
4644 | ||
4645 | first_time = TRUE; | |
4646 | for (i = 0; (int) i < n_switches; i++) | |
4647 | { | |
4648 | const char *const *args; | |
4649 | const char *p, *q; | |
4650 | if (!first_time) | |
4651 | obstack_grow (&collect_obstack, " ", 1); | |
4652 | ||
4653 | first_time = FALSE; | |
4654 | ||
4655 | /* Ignore elided switches. */ | |
79d52444 | 4656 | if ((switches[i].live_cond & SWITCH_IGNORE) != 0) |
32d661fc | 4657 | continue; |
4658 | ||
4659 | obstack_grow (&collect_obstack, "'-", 2); | |
4660 | q = switches[i].part1; | |
4661 | while ((p = strchr (q, '\''))) | |
4662 | { | |
4663 | obstack_grow (&collect_obstack, q, p - q); | |
4664 | obstack_grow (&collect_obstack, "'\\''", 4); | |
4665 | q = ++p; | |
4666 | } | |
4667 | obstack_grow (&collect_obstack, q, strlen (q)); | |
4668 | obstack_grow (&collect_obstack, "'", 1); | |
4669 | ||
4670 | for (args = switches[i].args; args && *args; args++) | |
4671 | { | |
4672 | obstack_grow (&collect_obstack, " '", 2); | |
4673 | q = *args; | |
4674 | while ((p = strchr (q, '\''))) | |
4675 | { | |
4676 | obstack_grow (&collect_obstack, q, p - q); | |
4677 | obstack_grow (&collect_obstack, "'\\''", 4); | |
4678 | q = ++p; | |
4679 | } | |
4680 | obstack_grow (&collect_obstack, q, strlen (q)); | |
4681 | obstack_grow (&collect_obstack, "'", 1); | |
4682 | } | |
4683 | } | |
4684 | obstack_grow (&collect_obstack, "\0", 1); | |
99c00302 | 4685 | xputenv (XOBFINISH (&collect_obstack, char *)); |
32d661fc | 4686 | } |
d7a9644e | 4687 | \f |
4688 | /* Process a spec string, accumulating and running commands. */ | |
4689 | ||
4690 | /* These variables describe the input file name. | |
4691 | input_file_number is the index on outfiles of this file, | |
4692 | so that the output file name can be stored for later use by %o. | |
4693 | input_basename is the start of the part of the input file | |
4694 | sans all directory names, and basename_length is the number | |
4695 | of characters starting there excluding the suffix .c or whatever. */ | |
4696 | ||
bca5a169 | 4697 | static const char *input_filename; |
d7a9644e | 4698 | static int input_file_number; |
f9b7c0b9 | 4699 | size_t input_filename_length; |
d7a9644e | 4700 | static int basename_length; |
1cf79a1a | 4701 | static int suffixed_basename_length; |
e40d43cc | 4702 | static const char *input_basename; |
4703 | static const char *input_suffix; | |
030ec15c | 4704 | #ifndef HOST_LACKS_INODE_NUMBERS |
74e4079a | 4705 | static struct stat input_stat; |
030ec15c | 4706 | #endif |
74e4079a | 4707 | static int input_stat_set; |
d7a9644e | 4708 | |
96842e40 | 4709 | /* The compiler used to process the current input file. */ |
4710 | static struct compiler *input_file_compiler; | |
4711 | ||
d7a9644e | 4712 | /* These are variables used within do_spec and do_spec_1. */ |
4713 | ||
4714 | /* Nonzero if an arg has been started and not yet terminated | |
4715 | (with space, tab or newline). */ | |
4716 | static int arg_going; | |
4717 | ||
4718 | /* Nonzero means %d or %g has been seen; the next arg to be terminated | |
4719 | is a temporary file name. */ | |
4720 | static int delete_this_arg; | |
4721 | ||
4722 | /* Nonzero means %w has been seen; the next arg to be terminated | |
4723 | is the output file name of this compilation. */ | |
4724 | static int this_is_output_file; | |
4725 | ||
4726 | /* Nonzero means %s has been seen; the next arg to be terminated | |
4727 | is the name of a library file and we should try the standard | |
4728 | search dirs for it. */ | |
4729 | static int this_is_library_file; | |
4730 | ||
d7ee9e9b | 4731 | /* Nonzero means %T has been seen; the next arg to be terminated |
4732 | is the name of a linker script and we should try all of the | |
4733 | standard search dirs for it. If it is found insert a --script | |
4734 | command line switch and then substitute the full path in place, | |
4735 | otherwise generate an error message. */ | |
4736 | static int this_is_linker_script; | |
4737 | ||
f90016ef | 4738 | /* Nonzero means that the input of this command is coming from a pipe. */ |
4739 | static int input_from_pipe; | |
4740 | ||
bdbd5352 | 4741 | /* Nonnull means substitute this for any suffix when outputting a switches |
aa40f561 | 4742 | arguments. */ |
bdbd5352 | 4743 | static const char *suffix_subst; |
4744 | ||
558cc3be | 4745 | /* If there is an argument being accumulated, terminate it and store it. */ |
4746 | ||
4747 | static void | |
4748 | end_going_arg (void) | |
4749 | { | |
4750 | if (arg_going) | |
4751 | { | |
4752 | const char *string; | |
4753 | ||
4754 | obstack_1grow (&obstack, 0); | |
4755 | string = XOBFINISH (&obstack, const char *); | |
4756 | if (this_is_library_file) | |
4757 | string = find_file (string); | |
d7ee9e9b | 4758 | if (this_is_linker_script) |
4759 | { | |
4760 | char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true); | |
4761 | ||
4762 | if (full_script_path == NULL) | |
4763 | { | |
4764 | error (_("unable to locate default linker script '%s' in the library search paths"), string); | |
4765 | /* Script was not found on search path. */ | |
4766 | return; | |
4767 | } | |
4768 | store_arg ("--script", false, false); | |
4769 | string = full_script_path; | |
4770 | } | |
558cc3be | 4771 | store_arg (string, delete_this_arg, this_is_output_file); |
4772 | if (this_is_output_file) | |
4773 | outfiles[input_file_number] = string; | |
4774 | arg_going = 0; | |
4775 | } | |
4776 | } | |
4777 | ||
0bfd146e | 4778 | |
4779 | /* Parse the WRAPPER string which is a comma separated list of the command line | |
4780 | and insert them into the beginning of argbuf. */ | |
4781 | ||
4782 | static void | |
4783 | insert_wrapper (const char *wrapper) | |
4784 | { | |
4785 | int n = 0; | |
4786 | int i; | |
4787 | char *buf = xstrdup (wrapper); | |
4788 | char *p = buf; | |
4789 | ||
4790 | do | |
4791 | { | |
4792 | n++; | |
4793 | while (*p == ',') | |
4794 | p++; | |
4795 | } | |
4796 | while ((p = strchr (p, ',')) != NULL); | |
4797 | ||
4798 | if (argbuf_index + n >= argbuf_length) | |
4799 | { | |
4800 | argbuf_length = argbuf_length * 2; | |
4801 | while (argbuf_length < argbuf_index + n) | |
4802 | argbuf_length *= 2; | |
25a1c410 | 4803 | argbuf = XRESIZEVEC (const char *, argbuf, argbuf_length); |
0bfd146e | 4804 | } |
4805 | for (i = argbuf_index - 1; i >= 0; i--) | |
4806 | argbuf[i + n] = argbuf[i]; | |
4807 | ||
4808 | i = 0; | |
4809 | p = buf; | |
4810 | do | |
4811 | { | |
4812 | while (*p == ',') | |
4813 | { | |
4814 | *p = 0; | |
4815 | p++; | |
4816 | } | |
4817 | argbuf[i++] = p; | |
4818 | } | |
4819 | while ((p = strchr (p, ',')) != NULL); | |
4820 | gcc_assert (i == n); | |
4821 | argbuf_index += n; | |
4822 | } | |
4823 | ||
d7a9644e | 4824 | /* Process the spec SPEC and run the commands specified therein. |
4825 | Returns 0 if the spec is successfully processed; -1 if failed. */ | |
4826 | ||
f9b7c0b9 | 4827 | int |
952f0048 | 4828 | do_spec (const char *spec) |
d7a9644e | 4829 | { |
4830 | int value; | |
4831 | ||
4ae4e5e8 | 4832 | value = do_spec_2 (spec); |
d7a9644e | 4833 | |
4834 | /* Force out any unfinished command. | |
4835 | If -pipe, this forces out the last command if it ended in `|'. */ | |
4836 | if (value == 0) | |
4837 | { | |
4838 | if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) | |
4839 | argbuf_index--; | |
4840 | ||
32d661fc | 4841 | set_collect_gcc_options (); |
4842 | ||
d7a9644e | 4843 | if (argbuf_index > 0) |
4844 | value = execute (); | |
4845 | } | |
4846 | ||
4847 | return value; | |
4848 | } | |
4849 | ||
4ae4e5e8 | 4850 | static int |
952f0048 | 4851 | do_spec_2 (const char *spec) |
4ae4e5e8 | 4852 | { |
5842765d | 4853 | int result; |
4854 | ||
4ae4e5e8 | 4855 | clear_args (); |
4856 | arg_going = 0; | |
4857 | delete_this_arg = 0; | |
4858 | this_is_output_file = 0; | |
4859 | this_is_library_file = 0; | |
d7ee9e9b | 4860 | this_is_linker_script = 0; |
4ae4e5e8 | 4861 | input_from_pipe = 0; |
4862 | suffix_subst = NULL; | |
4863 | ||
5842765d | 4864 | result = do_spec_1 (spec, 0, NULL); |
4865 | ||
558cc3be | 4866 | end_going_arg (); |
5842765d | 4867 | |
4868 | return result; | |
4ae4e5e8 | 4869 | } |
4870 | ||
73023f49 | 4871 | |
7dd97ab6 | 4872 | /* Process the given spec string and add any new options to the end |
4873 | of the switches/n_switches array. */ | |
4874 | ||
4875 | static void | |
952f0048 | 4876 | do_option_spec (const char *name, const char *spec) |
7dd97ab6 | 4877 | { |
4878 | unsigned int i, value_count, value_len; | |
4879 | const char *p, *q, *value; | |
4880 | char *tmp_spec, *tmp_spec_p; | |
4881 | ||
4882 | if (configure_default_options[0].name == NULL) | |
4883 | return; | |
4884 | ||
4885 | for (i = 0; i < ARRAY_SIZE (configure_default_options); i++) | |
4886 | if (strcmp (configure_default_options[i].name, name) == 0) | |
4887 | break; | |
4888 | if (i == ARRAY_SIZE (configure_default_options)) | |
4889 | return; | |
4890 | ||
4891 | value = configure_default_options[i].value; | |
4892 | value_len = strlen (value); | |
4893 | ||
4894 | /* Compute the size of the final spec. */ | |
4895 | value_count = 0; | |
4896 | p = spec; | |
4897 | while ((p = strstr (p, "%(VALUE)")) != NULL) | |
4898 | { | |
4899 | p ++; | |
4900 | value_count ++; | |
4901 | } | |
4902 | ||
4903 | /* Replace each %(VALUE) by the specified value. */ | |
25a1c410 | 4904 | tmp_spec = (char *) alloca (strlen (spec) + 1 |
7dd97ab6 | 4905 | + value_count * (value_len - strlen ("%(VALUE)"))); |
4906 | tmp_spec_p = tmp_spec; | |
4907 | q = spec; | |
4908 | while ((p = strstr (q, "%(VALUE)")) != NULL) | |
4909 | { | |
4910 | memcpy (tmp_spec_p, q, p - q); | |
4911 | tmp_spec_p = tmp_spec_p + (p - q); | |
4912 | memcpy (tmp_spec_p, value, value_len); | |
4913 | tmp_spec_p += value_len; | |
4914 | q = p + strlen ("%(VALUE)"); | |
4915 | } | |
4916 | strcpy (tmp_spec_p, q); | |
4917 | ||
4918 | do_self_spec (tmp_spec); | |
4919 | } | |
4920 | ||
73023f49 | 4921 | /* Process the given spec string and add any new options to the end |
4922 | of the switches/n_switches array. */ | |
4923 | ||
4924 | static void | |
952f0048 | 4925 | do_self_spec (const char *spec) |
73023f49 | 4926 | { |
4927 | do_spec_2 (spec); | |
4928 | do_spec_1 (" ", 0, NULL); | |
4929 | ||
4930 | if (argbuf_index > 0) | |
4931 | { | |
71278019 | 4932 | int i; |
73023f49 | 4933 | |
71278019 | 4934 | switches = XRESIZEVEC (struct switchstr, switches, |
4935 | n_switches + argbuf_index + 1); | |
73023f49 | 4936 | |
73023f49 | 4937 | for (i = 0; i < argbuf_index; i++) |
4938 | { | |
4939 | struct switchstr *sw; | |
71278019 | 4940 | const char *p = argbuf[i]; |
4941 | int c = *p; | |
73023f49 | 4942 | |
4943 | /* Each switch should start with '-'. */ | |
71278019 | 4944 | if (c != '-') |
5e8f3c31 | 4945 | fatal ("switch '%s' does not start with '-'", argbuf[i]); |
73023f49 | 4946 | |
71278019 | 4947 | p++; |
4948 | c = *p; | |
4949 | ||
4950 | sw = &switches[n_switches++]; | |
4951 | sw->part1 = p; | |
79d52444 | 4952 | sw->live_cond = 0; |
73023f49 | 4953 | sw->validated = 0; |
4954 | sw->ordering = 0; | |
71278019 | 4955 | |
4956 | /* Deal with option arguments in separate argv elements. */ | |
4957 | if ((SWITCH_TAKES_ARG (c) > (p[1] != 0)) | |
4958 | || WORD_SWITCH_TAKES_ARG (p)) | |
4959 | { | |
4960 | int j = 0; | |
4961 | int n_args = WORD_SWITCH_TAKES_ARG (p); | |
4962 | ||
4963 | if (n_args == 0) | |
4964 | { | |
4965 | /* Count only the option arguments in separate argv elements. */ | |
4966 | n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0); | |
4967 | } | |
4968 | if (i + n_args >= argbuf_index) | |
4969 | fatal ("argument to '-%s' is missing", p); | |
4970 | sw->args | |
4971 | = XNEWVEC (const char *, n_args + 1); | |
4972 | while (j < n_args) | |
4973 | sw->args[j++] = argbuf[++i]; | |
4974 | /* Null-terminate the vector. */ | |
4975 | sw->args[j] = 0; | |
4976 | } | |
4977 | else if (strchr (switches_need_spaces, c)) | |
4978 | { | |
4979 | /* On some systems, ld cannot handle some options without | |
4980 | a space. So split the option from its argument. */ | |
4981 | char *part1 = XNEWVEC (char, 2); | |
4982 | part1[0] = c; | |
4983 | part1[1] = '\0'; | |
4984 | ||
4985 | sw->part1 = part1; | |
4986 | sw->args = XNEWVEC (const char *, 2); | |
4987 | sw->args[0] = xstrdup (p+1); | |
4988 | sw->args[1] = 0; | |
4989 | } | |
4990 | else | |
4991 | sw->args = 0; | |
73023f49 | 4992 | } |
71278019 | 4993 | |
4994 | switches[n_switches].part1 = 0; | |
73023f49 | 4995 | } |
4996 | } | |
4997 | ||
067277c3 | 4998 | /* Callback for processing %D and %I specs. */ |
4999 | ||
5000 | struct spec_path_info { | |
5001 | const char *option; | |
5002 | const char *append; | |
5003 | size_t append_len; | |
5004 | bool omit_relative; | |
5005 | bool separate_options; | |
5006 | }; | |
5007 | ||
5008 | static void * | |
5009 | spec_path (char *path, void *data) | |
42bbc7e6 | 5010 | { |
25a1c410 | 5011 | struct spec_path_info *info = (struct spec_path_info *) data; |
067277c3 | 5012 | size_t len = 0; |
5013 | char save = 0; | |
42bbc7e6 | 5014 | |
067277c3 | 5015 | if (info->omit_relative && !IS_ABSOLUTE_PATH (path)) |
5016 | return NULL; | |
5017 | ||
5018 | if (info->append_len != 0) | |
42bbc7e6 | 5019 | { |
067277c3 | 5020 | len = strlen (path); |
5021 | memcpy (path + len, info->append, info->append_len + 1); | |
42bbc7e6 | 5022 | } |
5023 | ||
067277c3 | 5024 | if (!is_directory (path, true)) |
5025 | return NULL; | |
42bbc7e6 | 5026 | |
067277c3 | 5027 | do_spec_1 (info->option, 1, NULL); |
5028 | if (info->separate_options) | |
5029 | do_spec_1 (" ", 0, NULL); | |
5030 | ||
5031 | if (info->append_len == 0) | |
42bbc7e6 | 5032 | { |
067277c3 | 5033 | len = strlen (path); |
5034 | save = path[len - 1]; | |
5035 | if (IS_DIR_SEPARATOR (path[len - 1])) | |
5036 | path[len - 1] = '\0'; | |
42bbc7e6 | 5037 | } |
067277c3 | 5038 | |
5039 | do_spec_1 (path, 1, NULL); | |
5040 | do_spec_1 (" ", 0, NULL); | |
5041 | ||
5042 | /* Must not damage the original path. */ | |
5043 | if (info->append_len == 0) | |
5044 | path[len - 1] = save; | |
5045 | ||
5046 | return NULL; | |
42bbc7e6 | 5047 | } |
5048 | ||
46782931 | 5049 | /* Create a temporary FILE with the contents of ARGV. Add @FILE to the |
5050 | argument list. */ | |
5051 | ||
5052 | static void | |
5053 | create_at_file (char **argv) | |
5054 | { | |
5055 | char *temp_file = make_temp_file (""); | |
5056 | char *at_argument = concat ("@", temp_file, NULL); | |
5057 | FILE *f = fopen (temp_file, "w"); | |
5058 | int status; | |
5059 | ||
5060 | if (f == NULL) | |
5061 | fatal ("could not open temporary response file %s", | |
5062 | temp_file); | |
5063 | ||
5064 | status = writeargv (argv, f); | |
5065 | ||
5066 | if (status) | |
5067 | fatal ("could not write to temporary response file %s", | |
5068 | temp_file); | |
5069 | ||
5070 | status = fclose (f); | |
5071 | ||
5072 | if (EOF == status) | |
5073 | fatal ("could not close temporary response file %s", | |
5074 | temp_file); | |
5075 | ||
5076 | store_arg (at_argument, 0, 0); | |
5077 | ||
5078 | record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); | |
5079 | } | |
5080 | ||
5081 | /* True if we should compile INFILE. */ | |
5082 | ||
5083 | static bool | |
5084 | compile_input_file_p (struct infile *infile) | |
5085 | { | |
5086 | if ((!infile->language) || (infile->language[0] != '*')) | |
5087 | if (infile->incompiler == input_file_compiler) | |
5088 | return true; | |
5089 | return false; | |
5090 | } | |
5091 | ||
d7a9644e | 5092 | /* Process the sub-spec SPEC as a portion of a larger spec. |
5093 | This is like processing a whole spec except that we do | |
5094 | not initialize at the beginning and we do not supply a | |
5095 | newline by default at the end. | |
5096 | INSWITCH nonzero means don't process %-sequences in SPEC; | |
5097 | in this case, % is treated as an ordinary character. | |
5098 | This is used while substituting switches. | |
5099 | INSWITCH nonzero also causes SPC not to terminate an argument. | |
5100 | ||
5101 | Value is zero unless a line was finished | |
5102 | and the command on that line reported an error. */ | |
5103 | ||
5104 | static int | |
952f0048 | 5105 | do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) |
d7a9644e | 5106 | { |
19cb6b50 | 5107 | const char *p = spec; |
5108 | int c; | |
d7a9644e | 5109 | int i; |
fd8c18f0 | 5110 | int value; |
d7a9644e | 5111 | |
00e598e3 | 5112 | while ((c = *p++)) |
d7a9644e | 5113 | /* If substituting a switch, treat all chars like letters. |
5114 | Otherwise, NL, SPC, TAB and % are special. */ | |
5115 | switch (inswitch ? 'a' : c) | |
5116 | { | |
5117 | case '\n': | |
558cc3be | 5118 | end_going_arg (); |
d7a9644e | 5119 | |
5120 | if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) | |
5121 | { | |
d7a9644e | 5122 | /* A `|' before the newline means use a pipe here, |
5123 | but only if -pipe was specified. | |
5124 | Otherwise, execute now and don't pass the `|' as an arg. */ | |
805e22b2 | 5125 | if (use_pipes) |
d7a9644e | 5126 | { |
f90016ef | 5127 | input_from_pipe = 1; |
d7a9644e | 5128 | break; |
5129 | } | |
5130 | else | |
5131 | argbuf_index--; | |
5132 | } | |
5133 | ||
32d661fc | 5134 | set_collect_gcc_options (); |
5135 | ||
d7a9644e | 5136 | if (argbuf_index > 0) |
5137 | { | |
fd8c18f0 | 5138 | value = execute (); |
d7a9644e | 5139 | if (value) |
5140 | return value; | |
5141 | } | |
5142 | /* Reinitialize for a new command, and for a new argument. */ | |
5143 | clear_args (); | |
5144 | arg_going = 0; | |
5145 | delete_this_arg = 0; | |
5146 | this_is_output_file = 0; | |
5147 | this_is_library_file = 0; | |
d7ee9e9b | 5148 | this_is_linker_script = 0; |
f90016ef | 5149 | input_from_pipe = 0; |
d7a9644e | 5150 | break; |
5151 | ||
5152 | case '|': | |
558cc3be | 5153 | end_going_arg (); |
d7a9644e | 5154 | |
5155 | /* Use pipe */ | |
5156 | obstack_1grow (&obstack, c); | |
5157 | arg_going = 1; | |
5158 | break; | |
5159 | ||
5160 | case '\t': | |
5161 | case ' ': | |
558cc3be | 5162 | end_going_arg (); |
5163 | ||
d7a9644e | 5164 | /* Reinitialize for a new argument. */ |
d7a9644e | 5165 | delete_this_arg = 0; |
5166 | this_is_output_file = 0; | |
5167 | this_is_library_file = 0; | |
d7ee9e9b | 5168 | this_is_linker_script = 0; |
d7a9644e | 5169 | break; |
5170 | ||
5171 | case '%': | |
5172 | switch (c = *p++) | |
5173 | { | |
5174 | case 0: | |
5e8f3c31 | 5175 | fatal ("spec '%s' invalid", spec); |
d7a9644e | 5176 | |
5177 | case 'b': | |
cc92bc82 | 5178 | if (save_temps_length) |
5179 | obstack_grow (&obstack, save_temps_prefix, save_temps_length); | |
5180 | else | |
5181 | obstack_grow (&obstack, input_basename, basename_length); | |
71278019 | 5182 | if (compare_debug < 0) |
5183 | obstack_grow (&obstack, ".gk", 3); | |
d7a9644e | 5184 | arg_going = 1; |
5185 | break; | |
5186 | ||
1cf79a1a | 5187 | case 'B': |
cc92bc82 | 5188 | if (save_temps_length) |
5189 | obstack_grow (&obstack, save_temps_prefix, save_temps_length); | |
5190 | else | |
5191 | obstack_grow (&obstack, input_basename, suffixed_basename_length); | |
71278019 | 5192 | if (compare_debug < 0) |
5193 | obstack_grow (&obstack, ".gk", 3); | |
1cf79a1a | 5194 | arg_going = 1; |
5195 | break; | |
5196 | ||
d7a9644e | 5197 | case 'd': |
5198 | delete_this_arg = 2; | |
5199 | break; | |
5200 | ||
5201 | /* Dump out the directories specified with LIBRARY_PATH, | |
a45072dd | 5202 | followed by the absolute directories |
5203 | that we search for startfiles. */ | |
d7a9644e | 5204 | case 'D': |
466996dd | 5205 | { |
067277c3 | 5206 | struct spec_path_info info; |
9942f943 | 5207 | |
067277c3 | 5208 | info.option = "-L"; |
5209 | info.append_len = 0; | |
42bbc7e6 | 5210 | #ifdef RELATIVE_PREFIX_NOT_LINKDIR |
067277c3 | 5211 | /* Used on systems which record the specified -L dirs |
5212 | and use them to search for dynamic linking. | |
5213 | Relative directories always come from -B, | |
5214 | and it is better not to use them for searching | |
5215 | at run time. In particular, stage1 loses. */ | |
5216 | info.omit_relative = true; | |
42bbc7e6 | 5217 | #else |
067277c3 | 5218 | info.omit_relative = false; |
a45072dd | 5219 | #endif |
067277c3 | 5220 | info.separate_options = false; |
5221 | ||
5222 | for_each_path (&startfile_prefixes, true, 0, spec_path, &info); | |
466996dd | 5223 | } |
d7a9644e | 5224 | break; |
5225 | ||
5226 | case 'e': | |
be2828ce | 5227 | /* %efoo means report an error with `foo' as error message |
d7a9644e | 5228 | and don't execute any more commands for this file. */ |
5229 | { | |
e40d43cc | 5230 | const char *q = p; |
d7a9644e | 5231 | char *buf; |
026f2c7a | 5232 | while (*p != 0 && *p != '\n') |
5233 | p++; | |
25a1c410 | 5234 | buf = (char *) alloca (p - q + 1); |
d7a9644e | 5235 | strncpy (buf, q, p - q); |
5236 | buf[p - q] = 0; | |
e4ba8ded | 5237 | error ("%s", buf); |
d7a9644e | 5238 | return -1; |
5239 | } | |
5240 | break; | |
90286764 | 5241 | case 'n': |
edc2a478 | 5242 | /* %nfoo means report a notice with `foo' on stderr. */ |
90286764 | 5243 | { |
5244 | const char *q = p; | |
5245 | char *buf; | |
5246 | while (*p != 0 && *p != '\n') | |
5247 | p++; | |
25a1c410 | 5248 | buf = (char *) alloca (p - q + 1); |
90286764 | 5249 | strncpy (buf, q, p - q); |
5250 | buf[p - q] = 0; | |
5251 | notice ("%s\n", buf); | |
5252 | if (*p) | |
5253 | p++; | |
5254 | } | |
5255 | break; | |
d7a9644e | 5256 | |
026f2c7a | 5257 | case 'j': |
5258 | { | |
5259 | struct stat st; | |
5260 | ||
805e22b2 | 5261 | /* If save_temps_flag is off, and the HOST_BIT_BUCKET is |
5262 | defined, and it is not a directory, and it is | |
5263 | writable, use it. Otherwise, treat this like any | |
5264 | other temporary file. */ | |
026f2c7a | 5265 | |
5266 | if ((!save_temps_flag) | |
5267 | && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode)) | |
5268 | && (access (HOST_BIT_BUCKET, W_OK) == 0)) | |
5269 | { | |
5270 | obstack_grow (&obstack, HOST_BIT_BUCKET, | |
5271 | strlen (HOST_BIT_BUCKET)); | |
5272 | delete_this_arg = 0; | |
5273 | arg_going = 1; | |
5274 | break; | |
5275 | } | |
5276 | } | |
805e22b2 | 5277 | goto create_temp_file; |
5278 | case '|': | |
5279 | if (use_pipes) | |
5280 | { | |
5281 | obstack_1grow (&obstack, '-'); | |
5282 | delete_this_arg = 0; | |
5283 | arg_going = 1; | |
5284 | ||
5285 | /* consume suffix */ | |
b78b6a05 | 5286 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
805e22b2 | 5287 | p++; |
5288 | if (p[0] == '%' && p[1] == 'O') | |
5289 | p += 2; | |
952f0048 | 5290 | |
805e22b2 | 5291 | break; |
5292 | } | |
5293 | goto create_temp_file; | |
5294 | case 'm': | |
5295 | if (use_pipes) | |
5296 | { | |
5297 | /* consume suffix */ | |
b78b6a05 | 5298 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
805e22b2 | 5299 | p++; |
5300 | if (p[0] == '%' && p[1] == 'O') | |
5301 | p += 2; | |
952f0048 | 5302 | |
805e22b2 | 5303 | break; |
5304 | } | |
5305 | goto create_temp_file; | |
d7a9644e | 5306 | case 'g': |
5ee0d826 | 5307 | case 'u': |
e70085f9 | 5308 | case 'U': |
805e22b2 | 5309 | create_temp_file: |
d7a9644e | 5310 | { |
4576c73f | 5311 | struct temp_name *t; |
c78c5ee7 | 5312 | int suffix_length; |
e40d43cc | 5313 | const char *suffix = p; |
2c2aaf10 | 5314 | char *saved_suffix = NULL; |
c78c5ee7 | 5315 | |
b78b6a05 | 5316 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
2c2aaf10 | 5317 | p++; |
5318 | suffix_length = p - suffix; | |
c78c5ee7 | 5319 | if (p[0] == '%' && p[1] == 'O') |
5320 | { | |
97c9de01 | 5321 | p += 2; |
c78c5ee7 | 5322 | /* We don't support extra suffix characters after %O. */ |
b78b6a05 | 5323 | if (*p == '.' || ISALNUM ((unsigned char) *p)) |
1e5fcbe2 | 5324 | fatal ("spec '%s' has invalid '%%0%c'", spec, *p); |
2c2aaf10 | 5325 | if (suffix_length == 0) |
10f57222 | 5326 | suffix = TARGET_OBJECT_SUFFIX; |
2c2aaf10 | 5327 | else |
5328 | { | |
5329 | saved_suffix | |
4c36ffe6 | 5330 | = XNEWVEC (char, suffix_length |
f0af5a88 | 5331 | + strlen (TARGET_OBJECT_SUFFIX)); |
2c2aaf10 | 5332 | strncpy (saved_suffix, suffix, suffix_length); |
5333 | strcpy (saved_suffix + suffix_length, | |
10f57222 | 5334 | TARGET_OBJECT_SUFFIX); |
2c2aaf10 | 5335 | } |
10f57222 | 5336 | suffix_length += strlen (TARGET_OBJECT_SUFFIX); |
c78c5ee7 | 5337 | } |
3cfec666 | 5338 | |
71278019 | 5339 | if (compare_debug < 0) |
5340 | { | |
5341 | suffix = concat (".gk", suffix, NULL); | |
5342 | suffix_length += 3; | |
5343 | } | |
5344 | ||
cc92bc82 | 5345 | /* If -save-temps=obj and -o were specified, use that for the |
5346 | temp file. */ | |
5347 | if (save_temps_length) | |
5348 | { | |
5349 | char *tmp; | |
5350 | temp_filename_length | |
5351 | = save_temps_length + suffix_length + 1; | |
5352 | tmp = (char *) alloca (temp_filename_length); | |
5353 | memcpy (tmp, save_temps_prefix, save_temps_length); | |
5354 | memcpy (tmp + save_temps_length, suffix, suffix_length); | |
5355 | tmp[save_temps_length + suffix_length] = '\0'; | |
5356 | temp_filename = save_string (tmp, | |
5357 | temp_filename_length + 1); | |
5358 | obstack_grow (&obstack, temp_filename, | |
5359 | temp_filename_length); | |
5360 | arg_going = 1; | |
5361 | delete_this_arg = 0; | |
5362 | break; | |
5363 | } | |
5364 | ||
74e4079a | 5365 | /* If the input_filename has the same suffix specified |
5366 | for the %g, %u, or %U, and -save-temps is specified, | |
5367 | we could end up using that file as an intermediate | |
5368 | thus clobbering the user's source file (.e.g., | |
5369 | gcc -save-temps foo.s would clobber foo.s with the | |
5370 | output of cpp0). So check for this condition and | |
5371 | generate a temp file as the intermediate. */ | |
3cfec666 | 5372 | |
74e4079a | 5373 | if (save_temps_flag) |
5374 | { | |
5d1b319b | 5375 | char *tmp; |
cc92bc82 | 5376 | temp_filename_length = basename_length + suffix_length + 1; |
5377 | tmp = (char *) alloca (temp_filename_length); | |
5378 | memcpy (tmp, input_basename, basename_length); | |
5379 | memcpy (tmp + basename_length, suffix, suffix_length); | |
5380 | tmp[basename_length + suffix_length] = '\0'; | |
5d1b319b | 5381 | temp_filename = tmp; |
cc92bc82 | 5382 | |
74e4079a | 5383 | if (strcmp (temp_filename, input_filename) != 0) |
5384 | { | |
030ec15c | 5385 | #ifndef HOST_LACKS_INODE_NUMBERS |
952f0048 | 5386 | struct stat st_temp; |
3cfec666 | 5387 | |
952f0048 | 5388 | /* Note, set_input() resets input_stat_set to 0. */ |
5389 | if (input_stat_set == 0) | |
5390 | { | |
5391 | input_stat_set = stat (input_filename, &input_stat); | |
5392 | if (input_stat_set >= 0) | |
5393 | input_stat_set = 1; | |
5394 | } | |
3cfec666 | 5395 | |
952f0048 | 5396 | /* If we have the stat for the input_filename |
5397 | and we can do the stat for the temp_filename | |
5398 | then the they could still refer to the same | |
5399 | file if st_dev/st_ino's are the same. */ | |
74e4079a | 5400 | if (input_stat_set != 1 |
5401 | || stat (temp_filename, &st_temp) < 0 | |
5402 | || input_stat.st_dev != st_temp.st_dev | |
5403 | || input_stat.st_ino != st_temp.st_ino) | |
030ec15c | 5404 | #else |
5405 | /* Just compare canonical pathnames. */ | |
5406 | char* input_realname = lrealpath (input_filename); | |
5407 | char* temp_realname = lrealpath (temp_filename); | |
5408 | bool files_differ = strcmp (input_realname, temp_realname); | |
5409 | free (input_realname); | |
5410 | free (temp_realname); | |
2f2c6aee | 5411 | if (files_differ) |
030ec15c | 5412 | #endif |
3cfec666 | 5413 | { |
74e4079a | 5414 | temp_filename = save_string (temp_filename, |
5415 | temp_filename_length + 1); | |
5416 | obstack_grow (&obstack, temp_filename, | |
952f0048 | 5417 | temp_filename_length); |
74e4079a | 5418 | arg_going = 1; |
03b358c6 | 5419 | delete_this_arg = 0; |
74e4079a | 5420 | break; |
5421 | } | |
5422 | } | |
5423 | } | |
4576c73f | 5424 | |
5425 | /* See if we already have an association of %g/%u/%U and | |
5426 | suffix. */ | |
5427 | for (t = temp_names; t; t = t->next) | |
c78c5ee7 | 5428 | if (t->length == suffix_length |
5429 | && strncmp (t->suffix, suffix, suffix_length) == 0 | |
5f6af493 | 5430 | && t->unique == (c == 'u' || c == 'U' || c == 'j')) |
4576c73f | 5431 | break; |
5432 | ||
d362e897 | 5433 | /* Make a new association if needed. %u and %j |
5434 | require one. */ | |
655a58fa | 5435 | if (t == 0 || c == 'u' || c == 'j') |
4576c73f | 5436 | { |
5437 | if (t == 0) | |
5438 | { | |
25a1c410 | 5439 | t = XNEW (struct temp_name); |
4576c73f | 5440 | t->next = temp_names; |
5441 | temp_names = t; | |
5442 | } | |
c78c5ee7 | 5443 | t->length = suffix_length; |
d362e897 | 5444 | if (saved_suffix) |
5445 | { | |
5446 | t->suffix = saved_suffix; | |
5447 | saved_suffix = NULL; | |
5448 | } | |
5449 | else | |
5450 | t->suffix = save_string (suffix, suffix_length); | |
5f6af493 | 5451 | t->unique = (c == 'u' || c == 'U' || c == 'j'); |
c78c5ee7 | 5452 | temp_filename = make_temp_file (t->suffix); |
3441e5dd | 5453 | temp_filename_length = strlen (temp_filename); |
4576c73f | 5454 | t->filename = temp_filename; |
5455 | t->filename_length = temp_filename_length; | |
5456 | } | |
5457 | ||
2c2aaf10 | 5458 | if (saved_suffix) |
5459 | free (saved_suffix); | |
5460 | ||
4576c73f | 5461 | obstack_grow (&obstack, t->filename, t->filename_length); |
e2a5805f | 5462 | delete_this_arg = 1; |
d7a9644e | 5463 | } |
5464 | arg_going = 1; | |
5465 | break; | |
5466 | ||
5467 | case 'i': | |
40109983 | 5468 | if (combine_inputs) |
5469 | { | |
46782931 | 5470 | if (at_file_supplied) |
5471 | { | |
5472 | /* We are going to expand `%i' to `@FILE', where FILE | |
5473 | is a newly-created temporary filename. The filenames | |
5474 | that would usually be expanded in place of %o will be | |
5475 | written to the temporary file. */ | |
5476 | char **argv; | |
5477 | int n_files = 0; | |
5478 | int j; | |
5479 | ||
5480 | for (i = 0; i < n_infiles; i++) | |
5481 | if (compile_input_file_p (&infiles[i])) | |
5482 | n_files++; | |
5483 | ||
5484 | argv = (char **) alloca (sizeof (char *) * (n_files + 1)); | |
5485 | ||
5486 | /* Copy the strings over. */ | |
5487 | for (i = 0, j = 0; i < n_infiles; i++) | |
5488 | if (compile_input_file_p (&infiles[i])) | |
5489 | { | |
5490 | argv[j] = CONST_CAST (char *, infiles[i].name); | |
5491 | infiles[i].compiled = true; | |
5492 | j++; | |
5493 | } | |
5494 | argv[j] = NULL; | |
5495 | ||
5496 | create_at_file (argv); | |
5497 | } | |
5498 | else | |
5499 | for (i = 0; (int) i < n_infiles; i++) | |
5500 | if (compile_input_file_p (&infiles[i])) | |
dc1dd09b | 5501 | { |
5502 | store_arg (infiles[i].name, 0, 0); | |
5503 | infiles[i].compiled = true; | |
5504 | } | |
40109983 | 5505 | } |
5506 | else | |
5507 | { | |
5508 | obstack_grow (&obstack, input_filename, input_filename_length); | |
5509 | arg_going = 1; | |
5510 | } | |
d7a9644e | 5511 | break; |
5512 | ||
bfef3e2f | 5513 | case 'I': |
524c2193 | 5514 | { |
067277c3 | 5515 | struct spec_path_info info; |
524c2193 | 5516 | |
72779020 | 5517 | if (multilib_dir) |
5518 | { | |
5519 | do_spec_1 ("-imultilib", 1, NULL); | |
5520 | /* Make this a separate argument. */ | |
5521 | do_spec_1 (" ", 0, NULL); | |
5522 | do_spec_1 (multilib_dir, 1, NULL); | |
5523 | do_spec_1 (" ", 0, NULL); | |
5524 | } | |
5525 | ||
524c2193 | 5526 | if (gcc_exec_prefix) |
5527 | { | |
d946ea19 | 5528 | do_spec_1 ("-iprefix", 1, NULL); |
524c2193 | 5529 | /* Make this a separate argument. */ |
d946ea19 | 5530 | do_spec_1 (" ", 0, NULL); |
5531 | do_spec_1 (gcc_exec_prefix, 1, NULL); | |
5532 | do_spec_1 (" ", 0, NULL); | |
524c2193 | 5533 | } |
5534 | ||
4ea70922 | 5535 | if (target_system_root_changed || |
5536 | (target_system_root && target_sysroot_hdrs_suffix)) | |
17acc97a | 5537 | { |
5538 | do_spec_1 ("-isysroot", 1, NULL); | |
5539 | /* Make this a separate argument. */ | |
5540 | do_spec_1 (" ", 0, NULL); | |
5541 | do_spec_1 (target_system_root, 1, NULL); | |
4ea70922 | 5542 | if (target_sysroot_hdrs_suffix) |
5543 | do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL); | |
17acc97a | 5544 | do_spec_1 (" ", 0, NULL); |
5545 | } | |
5546 | ||
067277c3 | 5547 | info.option = "-isystem"; |
5548 | info.append = "include"; | |
5549 | info.append_len = strlen (info.append); | |
5550 | info.omit_relative = false; | |
5551 | info.separate_options = true; | |
5552 | ||
5553 | for_each_path (&include_prefixes, false, info.append_len, | |
5554 | spec_path, &info); | |
d3036f42 | 5555 | |
5556 | info.append = "include-fixed"; | |
6ea4242f | 5557 | if (*sysroot_hdrs_suffix_spec) |
5558 | info.append = concat (info.append, dir_separator_str, | |
5559 | multilib_dir, NULL); | |
d3036f42 | 5560 | info.append_len = strlen (info.append); |
5561 | for_each_path (&include_prefixes, false, info.append_len, | |
5562 | spec_path, &info); | |
524c2193 | 5563 | } |
bfef3e2f | 5564 | break; |
5565 | ||
d7a9644e | 5566 | case 'o': |
2b191381 | 5567 | { |
5568 | int max = n_infiles; | |
2b191381 | 5569 | max += lang_specific_extra_outfiles; |
cdf76fe2 | 5570 | |
c159e0b7 | 5571 | if (HAVE_GNU_LD && at_file_supplied) |
5572 | { | |
5573 | /* We are going to expand `%o' to `@FILE', where FILE | |
5574 | is a newly-created temporary filename. The filenames | |
5575 | that would usually be expanded in place of %o will be | |
5576 | written to the temporary file. */ | |
5577 | ||
c159e0b7 | 5578 | char **argv; |
46782931 | 5579 | int n_files, j; |
c159e0b7 | 5580 | |
5581 | /* Convert OUTFILES into a form suitable for writeargv. */ | |
5582 | ||
5583 | /* Determine how many are non-NULL. */ | |
5584 | for (n_files = 0, i = 0; i < max; i++) | |
5585 | n_files += outfiles[i] != NULL; | |
5586 | ||
25a1c410 | 5587 | argv = (char **) alloca (sizeof (char *) * (n_files + 1)); |
c159e0b7 | 5588 | |
5589 | /* Copy the strings over. */ | |
5590 | for (i = 0, j = 0; i < max; i++) | |
5591 | if (outfiles[i]) | |
5592 | { | |
e47a6f81 | 5593 | argv[j] = CONST_CAST (char *, outfiles[i]); |
c159e0b7 | 5594 | j++; |
5595 | } | |
5596 | argv[j] = NULL; | |
5597 | ||
46782931 | 5598 | create_at_file (argv); |
c159e0b7 | 5599 | } |
5600 | else | |
5601 | for (i = 0; i < max; i++) | |
5602 | if (outfiles[i]) | |
5603 | store_arg (outfiles[i], 0, 0); | |
2b191381 | 5604 | break; |
5605 | } | |
d7a9644e | 5606 | |
499a0933 | 5607 | case 'O': |
10f57222 | 5608 | obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
499a0933 | 5609 | arg_going = 1; |
5610 | break; | |
5611 | ||
d7a9644e | 5612 | case 's': |
5613 | this_is_library_file = 1; | |
5614 | break; | |
5615 | ||
d7ee9e9b | 5616 | case 'T': |
5617 | this_is_linker_script = 1; | |
5618 | break; | |
5619 | ||
573aba85 | 5620 | case 'V': |
5621 | outfiles[input_file_number] = NULL; | |
5622 | break; | |
5623 | ||
d7a9644e | 5624 | case 'w': |
5625 | this_is_output_file = 1; | |
5626 | break; | |
5627 | ||
5628 | case 'W': | |
5629 | { | |
2867e77d | 5630 | int cur_index = argbuf_index; |
d7a9644e | 5631 | /* Handle the {...} following the %W. */ |
5632 | if (*p != '{') | |
1e5fcbe2 | 5633 | fatal ("spec '%s' has invalid '%%W%c", spec, *p); |
d7a9644e | 5634 | p = handle_braces (p + 1); |
5635 | if (p == 0) | |
5636 | return -1; | |
558cc3be | 5637 | end_going_arg (); |
d7a9644e | 5638 | /* If any args were output, mark the last one for deletion |
5639 | on failure. */ | |
2867e77d | 5640 | if (argbuf_index != cur_index) |
d7a9644e | 5641 | record_temp_file (argbuf[argbuf_index - 1], 0, 1); |
5642 | break; | |
5643 | } | |
5644 | ||
5645 | /* %x{OPTION} records OPTION for %X to output. */ | |
5646 | case 'x': | |
5647 | { | |
e40d43cc | 5648 | const char *p1 = p; |
d7a9644e | 5649 | char *string; |
5650 | ||
5651 | /* Skip past the option value and make a copy. */ | |
5652 | if (*p != '{') | |
1e5fcbe2 | 5653 | fatal ("spec '%s' has invalid '%%x%c'", spec, *p); |
d7a9644e | 5654 | while (*p++ != '}') |
5655 | ; | |
5656 | string = save_string (p1 + 1, p - p1 - 2); | |
5657 | ||
5658 | /* See if we already recorded this option. */ | |
5659 | for (i = 0; i < n_linker_options; i++) | |
5660 | if (! strcmp (string, linker_options[i])) | |
5661 | { | |
5662 | free (string); | |
5663 | return 0; | |
5664 | } | |
5665 | ||
5666 | /* This option is new; add it. */ | |
8ace789a | 5667 | add_linker_option (string, strlen (string)); |
d7a9644e | 5668 | } |
5669 | break; | |
5670 | ||
fcdc45aa | 5671 | /* Dump out the options accumulated previously using %x. */ |
d7a9644e | 5672 | case 'X': |
5673 | for (i = 0; i < n_linker_options; i++) | |
5674 | { | |
d946ea19 | 5675 | do_spec_1 (linker_options[i], 1, NULL); |
d7a9644e | 5676 | /* Make each accumulated option a separate argument. */ |
d946ea19 | 5677 | do_spec_1 (" ", 0, NULL); |
d7a9644e | 5678 | } |
5679 | break; | |
5680 | ||
69587571 | 5681 | /* Dump out the options accumulated previously using -Wa,. */ |
5682 | case 'Y': | |
5683 | for (i = 0; i < n_assembler_options; i++) | |
5684 | { | |
d946ea19 | 5685 | do_spec_1 (assembler_options[i], 1, NULL); |
69587571 | 5686 | /* Make each accumulated option a separate argument. */ |
d946ea19 | 5687 | do_spec_1 (" ", 0, NULL); |
69587571 | 5688 | } |
5689 | break; | |
5690 | ||
391d9b6e | 5691 | /* Dump out the options accumulated previously using -Wp,. */ |
5692 | case 'Z': | |
5693 | for (i = 0; i < n_preprocessor_options; i++) | |
5694 | { | |
d946ea19 | 5695 | do_spec_1 (preprocessor_options[i], 1, NULL); |
391d9b6e | 5696 | /* Make each accumulated option a separate argument. */ |
d946ea19 | 5697 | do_spec_1 (" ", 0, NULL); |
391d9b6e | 5698 | } |
5699 | break; | |
5700 | ||
d7a9644e | 5701 | /* Here are digits and numbers that just process |
5702 | a certain constant string as a spec. */ | |
5703 | ||
5704 | case '1': | |
d946ea19 | 5705 | value = do_spec_1 (cc1_spec, 0, NULL); |
fd8c18f0 | 5706 | if (value != 0) |
5707 | return value; | |
d7a9644e | 5708 | break; |
5709 | ||
5710 | case '2': | |
d946ea19 | 5711 | value = do_spec_1 (cc1plus_spec, 0, NULL); |
fd8c18f0 | 5712 | if (value != 0) |
5713 | return value; | |
d7a9644e | 5714 | break; |
5715 | ||
5716 | case 'a': | |
d946ea19 | 5717 | value = do_spec_1 (asm_spec, 0, NULL); |
fd8c18f0 | 5718 | if (value != 0) |
5719 | return value; | |
d7a9644e | 5720 | break; |
5721 | ||
5722 | case 'A': | |
d946ea19 | 5723 | value = do_spec_1 (asm_final_spec, 0, NULL); |
fd8c18f0 | 5724 | if (value != 0) |
5725 | return value; | |
d7a9644e | 5726 | break; |
5727 | ||
d7a9644e | 5728 | case 'C': |
96842e40 | 5729 | { |
0d95286f | 5730 | const char *const spec |
3cfec666 | 5731 | = (input_file_compiler->cpp_spec |
5732 | ? input_file_compiler->cpp_spec | |
96842e40 | 5733 | : cpp_spec); |
d946ea19 | 5734 | value = do_spec_1 (spec, 0, NULL); |
96842e40 | 5735 | if (value != 0) |
5736 | return value; | |
5737 | } | |
d7a9644e | 5738 | break; |
5739 | ||
5740 | case 'E': | |
d946ea19 | 5741 | value = do_spec_1 (endfile_spec, 0, NULL); |
fd8c18f0 | 5742 | if (value != 0) |
5743 | return value; | |
d7a9644e | 5744 | break; |
5745 | ||
5746 | case 'l': | |
d946ea19 | 5747 | value = do_spec_1 (link_spec, 0, NULL); |
fd8c18f0 | 5748 | if (value != 0) |
5749 | return value; | |
d7a9644e | 5750 | break; |
5751 | ||
5752 | case 'L': | |
d946ea19 | 5753 | value = do_spec_1 (lib_spec, 0, NULL); |
fd8c18f0 | 5754 | if (value != 0) |
5755 | return value; | |
d7a9644e | 5756 | break; |
5757 | ||
b7c87ff2 | 5758 | case 'G': |
d946ea19 | 5759 | value = do_spec_1 (libgcc_spec, 0, NULL); |
b7c87ff2 | 5760 | if (value != 0) |
5761 | return value; | |
5762 | break; | |
5763 | ||
805e22b2 | 5764 | case 'R': |
5765 | /* We assume there is a directory | |
5766 | separator at the end of this string. */ | |
5767 | if (target_system_root) | |
952f0048 | 5768 | { |
5769 | obstack_grow (&obstack, target_system_root, | |
4ea70922 | 5770 | strlen (target_system_root)); |
5771 | if (target_sysroot_suffix) | |
952f0048 | 5772 | obstack_grow (&obstack, target_sysroot_suffix, |
4ea70922 | 5773 | strlen (target_sysroot_suffix)); |
5774 | } | |
805e22b2 | 5775 | break; |
5776 | ||
d7a9644e | 5777 | case 'S': |
d946ea19 | 5778 | value = do_spec_1 (startfile_spec, 0, NULL); |
fd8c18f0 | 5779 | if (value != 0) |
5780 | return value; | |
d7a9644e | 5781 | break; |
5782 | ||
5783 | /* Here we define characters other than letters and digits. */ | |
5784 | ||
5785 | case '{': | |
5786 | p = handle_braces (p); | |
5787 | if (p == 0) | |
5788 | return -1; | |
5789 | break; | |
5790 | ||
c21b3276 | 5791 | case ':': |
5792 | p = handle_spec_function (p); | |
5793 | if (p == 0) | |
5794 | return -1; | |
5795 | break; | |
5796 | ||
d7a9644e | 5797 | case '%': |
5798 | obstack_1grow (&obstack, '%'); | |
5799 | break; | |
5800 | ||
3cfec666 | 5801 | case '.': |
5802 | { | |
5803 | unsigned len = 0; | |
bdbd5352 | 5804 | |
3cfec666 | 5805 | while (p[len] && p[len] != ' ' && p[len] != '%') |
5806 | len++; | |
5807 | suffix_subst = save_string (p - 1, len + 1); | |
5808 | p += len; | |
5809 | } | |
bdbd5352 | 5810 | break; |
3cfec666 | 5811 | |
805e22b2 | 5812 | /* Henceforth ignore the option(s) matching the pattern |
5813 | after the %<. */ | |
5814 | case '<': | |
5815 | { | |
5816 | unsigned len = 0; | |
5817 | int have_wildcard = 0; | |
5818 | int i; | |
5819 | ||
5820 | while (p[len] && p[len] != ' ' && p[len] != '\t') | |
5821 | len++; | |
5822 | ||
5823 | if (p[len-1] == '*') | |
5824 | have_wildcard = 1; | |
5825 | ||
5826 | for (i = 0; i < n_switches; i++) | |
5827 | if (!strncmp (switches[i].part1, p, len - have_wildcard) | |
5828 | && (have_wildcard || switches[i].part1[len] == '\0')) | |
5829 | { | |
79d52444 | 5830 | switches[i].live_cond |= SWITCH_IGNORE; |
805e22b2 | 5831 | switches[i].validated = 1; |
5832 | } | |
5833 | ||
5834 | p += len; | |
5835 | } | |
5836 | break; | |
5837 | ||
d7a9644e | 5838 | case '*': |
d4ea3b1f | 5839 | if (soft_matched_part) |
5840 | { | |
d946ea19 | 5841 | do_spec_1 (soft_matched_part, 1, NULL); |
5842 | do_spec_1 (" ", 0, NULL); | |
d4ea3b1f | 5843 | } |
5844 | else | |
5845 | /* Catch the case where a spec string contains something like | |
0c6d8c36 | 5846 | '%{foo:%*}'. i.e. there is no * in the pattern on the left |
d4ea3b1f | 5847 | hand side of the :. */ |
1d8c4563 | 5848 | error ("spec failure: '%%*' has not been initialized by pattern match"); |
d7a9644e | 5849 | break; |
5850 | ||
5851 | /* Process a string found as the value of a spec given by name. | |
5852 | This feature allows individual machine descriptions | |
50bcc52e | 5853 | to add and use their own specs. |
5854 | %[...] modifies -D options the way %P does; | |
5855 | %(...) uses the spec unmodified. */ | |
5856 | case '[': | |
cb8bacb6 | 5857 | error ("warning: use of obsolete %%[ operator in specs"); |
d7a9644e | 5858 | case '(': |
d7a9644e | 5859 | { |
e40d43cc | 5860 | const char *name = p; |
d7a9644e | 5861 | struct spec_list *sl; |
5862 | int len; | |
5863 | ||
5864 | /* The string after the S/P is the name of a spec that is to be | |
a92771b8 | 5865 | processed. */ |
50bcc52e | 5866 | while (*p && *p != ')' && *p != ']') |
d7a9644e | 5867 | p++; |
5868 | ||
d4ea3b1f | 5869 | /* See if it's in the list. */ |
d7a9644e | 5870 | for (len = p - name, sl = specs; sl; sl = sl->next) |
988c0ffe | 5871 | if (sl->name_len == len && !strncmp (sl->name, name, len)) |
d7a9644e | 5872 | { |
988c0ffe | 5873 | name = *(sl->ptr_spec); |
4582d741 | 5874 | #ifdef DEBUG_SPECS |
be2828ce | 5875 | notice ("Processing spec %c%s%c, which is '%s'\n", |
5876 | c, sl->name, (c == '(') ? ')' : ']', name); | |
4582d741 | 5877 | #endif |
d7a9644e | 5878 | break; |
5879 | } | |
5880 | ||
5881 | if (sl) | |
5882 | { | |
50bcc52e | 5883 | if (c == '(') |
5884 | { | |
d946ea19 | 5885 | value = do_spec_1 (name, 0, NULL); |
50bcc52e | 5886 | if (value != 0) |
5887 | return value; | |
5888 | } | |
5889 | else | |
5890 | { | |
25a1c410 | 5891 | char *x = (char *) alloca (strlen (name) * 2 + 1); |
50bcc52e | 5892 | char *buf = x; |
e40d43cc | 5893 | const char *y = name; |
50bcc52e | 5894 | int flag = 0; |
5895 | ||
5896 | /* Copy all of NAME into BUF, but put __ after | |
d4ea3b1f | 5897 | every -D and at the end of each arg. */ |
50bcc52e | 5898 | while (1) |
5899 | { | |
5900 | if (! strncmp (y, "-D", 2)) | |
5901 | { | |
5902 | *x++ = '-'; | |
5903 | *x++ = 'D'; | |
5904 | *x++ = '_'; | |
5905 | *x++ = '_'; | |
5906 | y += 2; | |
5907 | flag = 1; | |
5908 | continue; | |
5909 | } | |
026f2c7a | 5910 | else if (flag |
5911 | && (*y == ' ' || *y == '\t' || *y == '=' | |
5912 | || *y == '}' || *y == 0)) | |
50bcc52e | 5913 | { |
5914 | *x++ = '_'; | |
5915 | *x++ = '_'; | |
5916 | flag = 0; | |
5917 | } | |
026f2c7a | 5918 | if (*y == 0) |
50bcc52e | 5919 | break; |
5920 | else | |
5921 | *x++ = *y++; | |
5922 | } | |
5923 | *x = 0; | |
5924 | ||
d946ea19 | 5925 | value = do_spec_1 (buf, 0, NULL); |
50bcc52e | 5926 | if (value != 0) |
5927 | return value; | |
5928 | } | |
d7a9644e | 5929 | } |
8894538a | 5930 | |
50bcc52e | 5931 | /* Discard the closing paren or bracket. */ |
8894538a | 5932 | if (*p) |
5933 | p++; | |
d7a9644e | 5934 | } |
5935 | break; | |
5936 | ||
5937 | default: | |
1d8c4563 | 5938 | error ("spec failure: unrecognized spec option '%c'", c); |
d4ea3b1f | 5939 | break; |
d7a9644e | 5940 | } |
5941 | break; | |
5942 | ||
5943 | case '\\': | |
5944 | /* Backslash: treat next character as ordinary. */ | |
5945 | c = *p++; | |
5946 | ||
b4b174c3 | 5947 | /* Fall through. */ |
d7a9644e | 5948 | default: |
5949 | /* Ordinary character: put it into the current argument. */ | |
5950 | obstack_1grow (&obstack, c); | |
5951 | arg_going = 1; | |
5952 | } | |
5953 | ||
c21b3276 | 5954 | /* End of string. If we are processing a spec function, we need to |
5955 | end any pending argument. */ | |
558cc3be | 5956 | if (processing_spec_function) |
5957 | end_going_arg (); | |
c21b3276 | 5958 | |
026f2c7a | 5959 | return 0; |
d7a9644e | 5960 | } |
5961 | ||
c21b3276 | 5962 | /* Look up a spec function. */ |
5963 | ||
5964 | static const struct spec_function * | |
952f0048 | 5965 | lookup_spec_function (const char *name) |
c21b3276 | 5966 | { |
c21b3276 | 5967 | const struct spec_function *sf; |
c21b3276 | 5968 | |
0bb0fa6a | 5969 | for (sf = static_spec_functions; sf->name != NULL; sf++) |
5970 | if (strcmp (sf->name, name) == 0) | |
5971 | return sf; | |
c21b3276 | 5972 | |
5973 | return NULL; | |
5974 | } | |
5975 | ||
5976 | /* Evaluate a spec function. */ | |
5977 | ||
5978 | static const char * | |
952f0048 | 5979 | eval_spec_function (const char *func, const char *args) |
c21b3276 | 5980 | { |
5981 | const struct spec_function *sf; | |
5982 | const char *funcval; | |
5983 | ||
5984 | /* Saved spec processing context. */ | |
5985 | int save_argbuf_index; | |
5986 | int save_argbuf_length; | |
5987 | const char **save_argbuf; | |
5988 | ||
5989 | int save_arg_going; | |
5990 | int save_delete_this_arg; | |
5991 | int save_this_is_output_file; | |
5992 | int save_this_is_library_file; | |
5993 | int save_input_from_pipe; | |
d7ee9e9b | 5994 | int save_this_is_linker_script; |
c21b3276 | 5995 | const char *save_suffix_subst; |
5996 | ||
5997 | ||
5998 | sf = lookup_spec_function (func); | |
5999 | if (sf == NULL) | |
1e5fcbe2 | 6000 | fatal ("unknown spec function '%s'", func); |
c21b3276 | 6001 | |
6002 | /* Push the spec processing context. */ | |
6003 | save_argbuf_index = argbuf_index; | |
6004 | save_argbuf_length = argbuf_length; | |
6005 | save_argbuf = argbuf; | |
6006 | ||
6007 | save_arg_going = arg_going; | |
6008 | save_delete_this_arg = delete_this_arg; | |
6009 | save_this_is_output_file = this_is_output_file; | |
6010 | save_this_is_library_file = this_is_library_file; | |
d7ee9e9b | 6011 | save_this_is_linker_script = this_is_linker_script; |
c21b3276 | 6012 | save_input_from_pipe = input_from_pipe; |
6013 | save_suffix_subst = suffix_subst; | |
6014 | ||
6015 | /* Create a new spec processing context, and build the function | |
6016 | arguments. */ | |
6017 | ||
6018 | alloc_args (); | |
6019 | if (do_spec_2 (args) < 0) | |
1e5fcbe2 | 6020 | fatal ("error in args to spec function '%s'", func); |
c21b3276 | 6021 | |
6022 | /* argbuf_index is an index for the next argument to be inserted, and | |
6023 | so contains the count of the args already inserted. */ | |
6024 | ||
6025 | funcval = (*sf->func) (argbuf_index, argbuf); | |
6026 | ||
6027 | /* Pop the spec processing context. */ | |
6028 | argbuf_index = save_argbuf_index; | |
6029 | argbuf_length = save_argbuf_length; | |
6030 | free (argbuf); | |
6031 | argbuf = save_argbuf; | |
6032 | ||
6033 | arg_going = save_arg_going; | |
6034 | delete_this_arg = save_delete_this_arg; | |
6035 | this_is_output_file = save_this_is_output_file; | |
6036 | this_is_library_file = save_this_is_library_file; | |
d7ee9e9b | 6037 | this_is_linker_script = save_this_is_linker_script; |
c21b3276 | 6038 | input_from_pipe = save_input_from_pipe; |
6039 | suffix_subst = save_suffix_subst; | |
6040 | ||
6041 | return funcval; | |
6042 | } | |
6043 | ||
6044 | /* Handle a spec function call of the form: | |
6045 | ||
6046 | %:function(args) | |
6047 | ||
6048 | ARGS is processed as a spec in a separate context and split into an | |
6049 | argument vector in the normal fashion. The function returns a string | |
6050 | containing a spec which we then process in the caller's context, or | |
6051 | NULL if no processing is required. */ | |
6052 | ||
6053 | static const char * | |
952f0048 | 6054 | handle_spec_function (const char *p) |
c21b3276 | 6055 | { |
6056 | char *func, *args; | |
6057 | const char *endp, *funcval; | |
6058 | int count; | |
6059 | ||
6060 | processing_spec_function++; | |
6061 | ||
6062 | /* Get the function name. */ | |
6063 | for (endp = p; *endp != '\0'; endp++) | |
6064 | { | |
6065 | if (*endp == '(') /* ) */ | |
6066 | break; | |
6067 | /* Only allow [A-Za-z0-9], -, and _ in function names. */ | |
6068 | if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_')) | |
6069 | fatal ("malformed spec function name"); | |
6070 | } | |
6071 | if (*endp != '(') /* ) */ | |
6072 | fatal ("no arguments for spec function"); | |
6073 | func = save_string (p, endp - p); | |
6074 | p = ++endp; | |
6075 | ||
6076 | /* Get the arguments. */ | |
6077 | for (count = 0; *endp != '\0'; endp++) | |
6078 | { | |
6079 | /* ( */ | |
6080 | if (*endp == ')') | |
6081 | { | |
6082 | if (count == 0) | |
6083 | break; | |
6084 | count--; | |
6085 | } | |
6086 | else if (*endp == '(') /* ) */ | |
6087 | count++; | |
6088 | } | |
6089 | /* ( */ | |
6090 | if (*endp != ')') | |
6091 | fatal ("malformed spec function arguments"); | |
6092 | args = save_string (p, endp - p); | |
6093 | p = ++endp; | |
6094 | ||
6095 | /* p now points to just past the end of the spec function expression. */ | |
6096 | ||
6097 | funcval = eval_spec_function (func, args); | |
6098 | if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0) | |
6099 | p = NULL; | |
6100 | ||
6101 | free (func); | |
6102 | free (args); | |
6103 | ||
6104 | processing_spec_function--; | |
6105 | ||
6106 | return p; | |
6107 | } | |
6108 | ||
805e22b2 | 6109 | /* Inline subroutine of handle_braces. Returns true if the current |
6110 | input suffix matches the atom bracketed by ATOM and END_ATOM. */ | |
6111 | static inline bool | |
952f0048 | 6112 | input_suffix_matches (const char *atom, const char *end_atom) |
805e22b2 | 6113 | { |
6114 | return (input_suffix | |
6115 | && !strncmp (input_suffix, atom, end_atom - atom) | |
6116 | && input_suffix[end_atom - atom] == '\0'); | |
6117 | } | |
d7a9644e | 6118 | |
90e35d1a | 6119 | /* Subroutine of handle_braces. Returns true if the current |
6120 | input file's spec name matches the atom bracketed by ATOM and END_ATOM. */ | |
6121 | static bool | |
6122 | input_spec_matches (const char *atom, const char *end_atom) | |
6123 | { | |
6124 | return (input_file_compiler | |
6125 | && input_file_compiler->suffix | |
6126 | && input_file_compiler->suffix[0] != '\0' | |
6127 | && !strncmp (input_file_compiler->suffix + 1, atom, | |
6128 | end_atom - atom) | |
6129 | && input_file_compiler->suffix[end_atom - atom + 1] == '\0'); | |
6130 | } | |
6131 | ||
1e8e9920 | 6132 | /* Subroutine of handle_braces. Returns true if a switch |
805e22b2 | 6133 | matching the atom bracketed by ATOM and END_ATOM appeared on the |
6134 | command line. */ | |
1e8e9920 | 6135 | static bool |
952f0048 | 6136 | switch_matches (const char *atom, const char *end_atom, int starred) |
d7a9644e | 6137 | { |
805e22b2 | 6138 | int i; |
6139 | int len = end_atom - atom; | |
6140 | int plen = starred ? len : -1; | |
d7a9644e | 6141 | |
805e22b2 | 6142 | for (i = 0; i < n_switches; i++) |
6143 | if (!strncmp (switches[i].part1, atom, len) | |
6144 | && (starred || switches[i].part1[len] == '\0') | |
6145 | && check_live_switch (i, plen)) | |
6146 | return true; | |
4a10d696 | 6147 | |
805e22b2 | 6148 | return false; |
6149 | } | |
d7a9644e | 6150 | |
805e22b2 | 6151 | /* Inline subroutine of handle_braces. Mark all of the switches which |
6152 | match ATOM (extends to END_ATOM; STARRED indicates whether there | |
6153 | was a star after the atom) for later processing. */ | |
6154 | static inline void | |
952f0048 | 6155 | mark_matching_switches (const char *atom, const char *end_atom, int starred) |
805e22b2 | 6156 | { |
6157 | int i; | |
6158 | int len = end_atom - atom; | |
6159 | int plen = starred ? len : -1; | |
6160 | ||
6161 | for (i = 0; i < n_switches; i++) | |
6162 | if (!strncmp (switches[i].part1, atom, len) | |
6163 | && (starred || switches[i].part1[len] == '\0') | |
6164 | && check_live_switch (i, plen)) | |
6165 | switches[i].ordering = 1; | |
6166 | } | |
ae70654c | 6167 | |
805e22b2 | 6168 | /* Inline subroutine of handle_braces. Process all the currently |
6169 | marked switches through give_switch, and clear the marks. */ | |
6170 | static inline void | |
952f0048 | 6171 | process_marked_switches (void) |
805e22b2 | 6172 | { |
6173 | int i; | |
d7a9644e | 6174 | |
805e22b2 | 6175 | for (i = 0; i < n_switches; i++) |
6176 | if (switches[i].ordering == 1) | |
6177 | { | |
6178 | switches[i].ordering = 0; | |
6179 | give_switch (i, 0); | |
6180 | } | |
6181 | } | |
d7a9644e | 6182 | |
805e22b2 | 6183 | /* Handle a %{ ... } construct. P points just inside the leading {. |
6184 | Returns a pointer one past the end of the brace block, or 0 | |
6185 | if we call do_spec_1 and that returns -1. */ | |
d7a9644e | 6186 | |
805e22b2 | 6187 | static const char * |
952f0048 | 6188 | handle_braces (const char *p) |
805e22b2 | 6189 | { |
6190 | const char *atom, *end_atom; | |
6191 | const char *d_atom = NULL, *d_end_atom = NULL; | |
5e8f3c31 | 6192 | const char *orig = p; |
4a10d696 | 6193 | |
805e22b2 | 6194 | bool a_is_suffix; |
90e35d1a | 6195 | bool a_is_spectype; |
805e22b2 | 6196 | bool a_is_starred; |
6197 | bool a_is_negated; | |
6198 | bool a_matched; | |
ae70654c | 6199 | |
805e22b2 | 6200 | bool a_must_be_last = false; |
6201 | bool ordered_set = false; | |
6202 | bool disjunct_set = false; | |
6203 | bool disj_matched = false; | |
6204 | bool disj_starred = true; | |
6205 | bool n_way_choice = false; | |
6206 | bool n_way_matched = false; | |
6207 | ||
6208 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) | |
ae70654c | 6209 | |
805e22b2 | 6210 | do |
d7a9644e | 6211 | { |
805e22b2 | 6212 | if (a_must_be_last) |
5e8f3c31 | 6213 | goto invalid; |
ae70654c | 6214 | |
805e22b2 | 6215 | /* Scan one "atom" (S in the description above of %{}, possibly |
90e35d1a | 6216 | with '!', '.', '@', ',', or '*' modifiers). */ |
6217 | a_matched = false; | |
6218 | a_is_suffix = false; | |
6219 | a_is_starred = false; | |
6220 | a_is_negated = false; | |
6221 | a_is_spectype = false; | |
2c815aff | 6222 | |
805e22b2 | 6223 | SKIP_WHITE(); |
6224 | if (*p == '!') | |
6225 | p++, a_is_negated = true; | |
d7a9644e | 6226 | |
805e22b2 | 6227 | SKIP_WHITE(); |
6228 | if (*p == '.') | |
6229 | p++, a_is_suffix = true; | |
90e35d1a | 6230 | else if (*p == ',') |
6231 | p++, a_is_spectype = true; | |
d7a9644e | 6232 | |
805e22b2 | 6233 | atom = p; |
6234 | while (ISIDNUM(*p) || *p == '-' || *p == '+' || *p == '=' | |
bf2285ef | 6235 | || *p == ',' || *p == '.' || *p == '@') |
805e22b2 | 6236 | p++; |
6237 | end_atom = p; | |
d7a9644e | 6238 | |
805e22b2 | 6239 | if (*p == '*') |
6240 | p++, a_is_starred = 1; | |
e1478c0f | 6241 | |
805e22b2 | 6242 | SKIP_WHITE(); |
5e8f3c31 | 6243 | switch (*p) |
805e22b2 | 6244 | { |
5e8f3c31 | 6245 | case '&': case '}': |
805e22b2 | 6246 | /* Substitute the switch(es) indicated by the current atom. */ |
6247 | ordered_set = true; | |
6248 | if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix | |
90e35d1a | 6249 | || a_is_spectype || atom == end_atom) |
5e8f3c31 | 6250 | goto invalid; |
d7a9644e | 6251 | |
805e22b2 | 6252 | mark_matching_switches (atom, end_atom, a_is_starred); |
6253 | ||
6254 | if (*p == '}') | |
6255 | process_marked_switches (); | |
5e8f3c31 | 6256 | break; |
6257 | ||
6258 | case '|': case ':': | |
805e22b2 | 6259 | /* Substitute some text if the current atom appears as a switch |
6260 | or suffix. */ | |
6261 | disjunct_set = true; | |
6262 | if (ordered_set) | |
5e8f3c31 | 6263 | goto invalid; |
d7a9644e | 6264 | |
805e22b2 | 6265 | if (atom == end_atom) |
d7a9644e | 6266 | { |
805e22b2 | 6267 | if (!n_way_choice || disj_matched || *p == '|' |
48e1416a | 6268 | || a_is_negated || a_is_suffix || a_is_spectype |
90e35d1a | 6269 | || a_is_starred) |
5e8f3c31 | 6270 | goto invalid; |
805e22b2 | 6271 | |
6272 | /* An empty term may appear as the last choice of an | |
6273 | N-way choice set; it means "otherwise". */ | |
6274 | a_must_be_last = true; | |
6275 | disj_matched = !n_way_matched; | |
6276 | disj_starred = false; | |
d7a9644e | 6277 | } |
805e22b2 | 6278 | else |
d7a9644e | 6279 | { |
90e35d1a | 6280 | if ((a_is_suffix || a_is_spectype) && a_is_starred) |
6281 | goto invalid; | |
d7ee9e9b | 6282 | |
90e35d1a | 6283 | if (!a_is_starred) |
6284 | disj_starred = false; | |
6285 | ||
6286 | /* Don't bother testing this atom if we already have a | |
6287 | match. */ | |
6288 | if (!disj_matched && !n_way_matched) | |
6289 | { | |
6290 | if (a_is_suffix) | |
6291 | a_matched = input_suffix_matches (atom, end_atom); | |
6292 | else if (a_is_spectype) | |
6293 | a_matched = input_spec_matches (atom, end_atom); | |
6294 | else | |
6295 | a_matched = switch_matches (atom, end_atom, a_is_starred); | |
d7ee9e9b | 6296 | |
90e35d1a | 6297 | if (a_matched != a_is_negated) |
6298 | { | |
6299 | disj_matched = true; | |
6300 | d_atom = atom; | |
6301 | d_end_atom = end_atom; | |
6302 | } | |
6303 | } | |
d7a9644e | 6304 | } |
d7a9644e | 6305 | |
805e22b2 | 6306 | if (*p == ':') |
d7a9644e | 6307 | { |
805e22b2 | 6308 | /* Found the body, that is, the text to substitute if the |
6309 | current disjunction matches. */ | |
6310 | p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred, | |
6311 | disj_matched && !n_way_matched); | |
6312 | if (p == 0) | |
6313 | return 0; | |
d7a9644e | 6314 | |
805e22b2 | 6315 | /* If we have an N-way choice, reset state for the next |
6316 | disjunction. */ | |
6317 | if (*p == ';') | |
d7a9644e | 6318 | { |
805e22b2 | 6319 | n_way_choice = true; |
6320 | n_way_matched |= disj_matched; | |
6321 | disj_matched = false; | |
6322 | disj_starred = true; | |
6323 | d_atom = d_end_atom = NULL; | |
d7a9644e | 6324 | } |
6325 | } | |
5e8f3c31 | 6326 | break; |
6327 | ||
6328 | default: | |
6329 | goto invalid; | |
d7a9644e | 6330 | } |
805e22b2 | 6331 | } |
6332 | while (*p++ != '}'); | |
d7a9644e | 6333 | |
805e22b2 | 6334 | return p; |
2f2c6aee | 6335 | |
5e8f3c31 | 6336 | invalid: |
1e5fcbe2 | 6337 | fatal ("braced spec '%s' is invalid at '%c'", orig, *p); |
2f2c6aee | 6338 | |
805e22b2 | 6339 | #undef SKIP_WHITE |
6340 | } | |
6341 | ||
6342 | /* Subroutine of handle_braces. Scan and process a brace substitution body | |
6343 | (X in the description of %{} syntax). P points one past the colon; | |
6344 | ATOM and END_ATOM bracket the first atom which was found to be true | |
6345 | (present) in the current disjunction; STARRED indicates whether all | |
6346 | the atoms in the current disjunction were starred (for syntax validation); | |
6347 | MATCHED indicates whether the disjunction matched or not, and therefore | |
6348 | whether or not the body is to be processed through do_spec_1 or just | |
6349 | skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1 | |
6350 | returns -1. */ | |
6351 | ||
6352 | static const char * | |
952f0048 | 6353 | process_brace_body (const char *p, const char *atom, const char *end_atom, |
6354 | int starred, int matched) | |
805e22b2 | 6355 | { |
6356 | const char *body, *end_body; | |
6357 | unsigned int nesting_level; | |
6358 | bool have_subst = false; | |
6359 | ||
6360 | /* Locate the closing } or ;, honoring nested braces. | |
6361 | Trim trailing whitespace. */ | |
6362 | body = p; | |
6363 | nesting_level = 1; | |
6364 | for (;;) | |
6365 | { | |
6366 | if (*p == '{') | |
6367 | nesting_level++; | |
6368 | else if (*p == '}') | |
d7a9644e | 6369 | { |
805e22b2 | 6370 | if (!--nesting_level) |
6371 | break; | |
d7a9644e | 6372 | } |
805e22b2 | 6373 | else if (*p == ';' && nesting_level == 1) |
6374 | break; | |
6375 | else if (*p == '%' && p[1] == '*' && nesting_level == 1) | |
6376 | have_subst = true; | |
6377 | else if (*p == '\0') | |
5e8f3c31 | 6378 | goto invalid; |
805e22b2 | 6379 | p++; |
d7a9644e | 6380 | } |
952f0048 | 6381 | |
805e22b2 | 6382 | end_body = p; |
6383 | while (end_body[-1] == ' ' || end_body[-1] == '\t') | |
6384 | end_body--; | |
d7a9644e | 6385 | |
805e22b2 | 6386 | if (have_subst && !starred) |
5e8f3c31 | 6387 | goto invalid; |
ae70654c | 6388 | |
805e22b2 | 6389 | if (matched) |
e1478c0f | 6390 | { |
805e22b2 | 6391 | /* Copy the substitution body to permanent storage and execute it. |
6392 | If have_subst is false, this is a simple matter of running the | |
6393 | body through do_spec_1... */ | |
6394 | char *string = save_string (body, end_body - body); | |
6395 | if (!have_subst) | |
6396 | { | |
6397 | if (do_spec_1 (string, 0, NULL) < 0) | |
6398 | return 0; | |
6399 | } | |
6400 | else | |
6401 | { | |
6402 | /* ... but if have_subst is true, we have to process the | |
6403 | body once for each matching switch, with %* set to the | |
6404 | variant part of the switch. */ | |
6405 | unsigned int hard_match_len = end_atom - atom; | |
6406 | int i; | |
e1478c0f | 6407 | |
805e22b2 | 6408 | for (i = 0; i < n_switches; i++) |
6409 | if (!strncmp (switches[i].part1, atom, hard_match_len) | |
6410 | && check_live_switch (i, hard_match_len)) | |
6411 | { | |
6412 | if (do_spec_1 (string, 0, | |
6413 | &switches[i].part1[hard_match_len]) < 0) | |
6414 | return 0; | |
6415 | /* Pass any arguments this switch has. */ | |
6416 | give_switch (i, 1); | |
6417 | suffix_subst = NULL; | |
6418 | } | |
6419 | } | |
dead3293 | 6420 | } |
6421 | ||
805e22b2 | 6422 | return p; |
5e8f3c31 | 6423 | |
6424 | invalid: | |
1e5fcbe2 | 6425 | fatal ("braced spec body '%s' is invalid", body); |
d7a9644e | 6426 | } |
cde688ab | 6427 | \f |
d870e215 | 6428 | /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch |
6429 | on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*} | |
6430 | spec, or -1 if either exact match or %* is used. | |
cde688ab | 6431 | |
6432 | A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch | |
6433 | whose value does not begin with "no-" is obsoleted by the same value | |
6434 | with the "no-", similarly for a switch with the "no-" prefix. */ | |
6435 | ||
6436 | static int | |
952f0048 | 6437 | check_live_switch (int switchnum, int prefix_length) |
cde688ab | 6438 | { |
e40d43cc | 6439 | const char *name = switches[switchnum].part1; |
cde688ab | 6440 | int i; |
6441 | ||
71278019 | 6442 | /* If we already processed this switch and determined if it was |
6443 | live or not, return our past determination. */ | |
6444 | if (switches[switchnum].live_cond != 0) | |
6445 | return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0 | |
6446 | && (switches[switchnum].live_cond & SWITCH_FALSE) == 0 | |
6447 | && (switches[switchnum].live_cond & SWITCH_IGNORE) == 0); | |
6448 | ||
d870e215 | 6449 | /* In the common case of {<at-most-one-letter>*}, a negating |
cde688ab | 6450 | switch would always match, so ignore that case. We will just |
6451 | send the conflicting switches to the compiler phase. */ | |
d870e215 | 6452 | if (prefix_length >= 0 && prefix_length <= 1) |
cde688ab | 6453 | return 1; |
6454 | ||
cde688ab | 6455 | /* Now search for duplicate in a manner that depends on the name. */ |
6456 | switch (*name) | |
6457 | { | |
6458 | case 'O': | |
026f2c7a | 6459 | for (i = switchnum + 1; i < n_switches; i++) |
6460 | if (switches[i].part1[0] == 'O') | |
6461 | { | |
6462 | switches[switchnum].validated = 1; | |
6463 | switches[switchnum].live_cond = SWITCH_FALSE; | |
6464 | return 0; | |
6465 | } | |
cde688ab | 6466 | break; |
d7a9644e | 6467 | |
cde688ab | 6468 | case 'W': case 'f': case 'm': |
d870e215 | 6469 | if (! strncmp (name + 1, "no-", 3)) |
cde688ab | 6470 | { |
a92771b8 | 6471 | /* We have Xno-YYY, search for XYYY. */ |
cde688ab | 6472 | for (i = switchnum + 1; i < n_switches; i++) |
6473 | if (switches[i].part1[0] == name[0] | |
6474 | && ! strcmp (&switches[i].part1[1], &name[4])) | |
026f2c7a | 6475 | { |
6476 | switches[switchnum].validated = 1; | |
6477 | switches[switchnum].live_cond = SWITCH_FALSE; | |
6478 | return 0; | |
6479 | } | |
cde688ab | 6480 | } |
6481 | else | |
6482 | { | |
6483 | /* We have XYYY, search for Xno-YYY. */ | |
6484 | for (i = switchnum + 1; i < n_switches; i++) | |
6485 | if (switches[i].part1[0] == name[0] | |
6486 | && switches[i].part1[1] == 'n' | |
6487 | && switches[i].part1[2] == 'o' | |
6488 | && switches[i].part1[3] == '-' | |
6489 | && !strcmp (&switches[i].part1[4], &name[1])) | |
026f2c7a | 6490 | { |
6491 | switches[switchnum].validated = 1; | |
6492 | switches[switchnum].live_cond = SWITCH_FALSE; | |
6493 | return 0; | |
6494 | } | |
cde688ab | 6495 | } |
6496 | break; | |
6497 | } | |
6498 | ||
6499 | /* Otherwise the switch is live. */ | |
79d52444 | 6500 | switches[switchnum].live_cond |= SWITCH_LIVE; |
cde688ab | 6501 | return 1; |
6502 | } | |
6503 | \f | |
d7a9644e | 6504 | /* Pass a switch to the current accumulating command |
6505 | in the same form that we received it. | |
6506 | SWITCHNUM identifies the switch; it is an index into | |
6507 | the vector of switches gcc received, which is `switches'. | |
6508 | This cannot fail since it never finishes a command line. | |
6509 | ||
805e22b2 | 6510 | If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */ |
d7a9644e | 6511 | |
6512 | static void | |
952f0048 | 6513 | give_switch (int switchnum, int omit_first_word) |
d7a9644e | 6514 | { |
79d52444 | 6515 | if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0) |
4a10d696 | 6516 | return; |
6517 | ||
d7a9644e | 6518 | if (!omit_first_word) |
6519 | { | |
d946ea19 | 6520 | do_spec_1 ("-", 0, NULL); |
6521 | do_spec_1 (switches[switchnum].part1, 1, NULL); | |
d7a9644e | 6522 | } |
3796373b | 6523 | |
d7a9644e | 6524 | if (switches[switchnum].args != 0) |
6525 | { | |
2508fdc3 | 6526 | const char **p; |
d7a9644e | 6527 | for (p = switches[switchnum].args; *p; p++) |
6528 | { | |
bdbd5352 | 6529 | const char *arg = *p; |
6530 | ||
805e22b2 | 6531 | do_spec_1 (" ", 0, NULL); |
bdbd5352 | 6532 | if (suffix_subst) |
6533 | { | |
6534 | unsigned length = strlen (arg); | |
633199a0 | 6535 | int dot = 0; |
bdbd5352 | 6536 | |
6537 | while (length-- && !IS_DIR_SEPARATOR (arg[length])) | |
6538 | if (arg[length] == '.') | |
6539 | { | |
e47a6f81 | 6540 | (CONST_CAST(char *, arg))[length] = 0; |
633199a0 | 6541 | dot = 1; |
bdbd5352 | 6542 | break; |
6543 | } | |
d946ea19 | 6544 | do_spec_1 (arg, 1, NULL); |
633199a0 | 6545 | if (dot) |
e47a6f81 | 6546 | (CONST_CAST(char *, arg))[length] = '.'; |
633199a0 | 6547 | do_spec_1 (suffix_subst, 1, NULL); |
bdbd5352 | 6548 | } |
6549 | else | |
d946ea19 | 6550 | do_spec_1 (arg, 1, NULL); |
d7a9644e | 6551 | } |
6552 | } | |
3796373b | 6553 | |
d946ea19 | 6554 | do_spec_1 (" ", 0, NULL); |
be2828ce | 6555 | switches[switchnum].validated = 1; |
d7a9644e | 6556 | } |
6557 | \f | |
6558 | /* Search for a file named NAME trying various prefixes including the | |
6559 | user's -B prefix and some standard ones. | |
6560 | Return the absolute file name found. If nothing is found, return NAME. */ | |
6561 | ||
e40d43cc | 6562 | static const char * |
952f0048 | 6563 | find_file (const char *name) |
d7a9644e | 6564 | { |
067277c3 | 6565 | char *newname = find_a_file (&startfile_prefixes, name, R_OK, true); |
d7a9644e | 6566 | return newname ? newname : name; |
6567 | } | |
6568 | ||
c049b2ee | 6569 | /* Determine whether a directory exists. If LINKER, return 0 for |
067277c3 | 6570 | certain fixed names not needed by the linker. */ |
d7a9644e | 6571 | |
6572 | static int | |
067277c3 | 6573 | is_directory (const char *path1, bool linker) |
d7a9644e | 6574 | { |
067277c3 | 6575 | int len1; |
6576 | char *path; | |
d7a9644e | 6577 | char *cp; |
6578 | struct stat st; | |
6579 | ||
067277c3 | 6580 | /* Ensure the string ends with "/.". The resulting path will be a |
6581 | directory even if the given path is a symbolic link. */ | |
6582 | len1 = strlen (path1); | |
25a1c410 | 6583 | path = (char *) alloca (3 + len1); |
d7e36a01 | 6584 | memcpy (path, path1, len1); |
067277c3 | 6585 | cp = path + len1; |
79b23a1e | 6586 | if (!IS_DIR_SEPARATOR (cp[-1])) |
b9374a77 | 6587 | *cp++ = DIR_SEPARATOR; |
d7a9644e | 6588 | *cp++ = '.'; |
6589 | *cp = '\0'; | |
6590 | ||
6591 | /* Exclude directories that the linker is known to search. */ | |
c049b2ee | 6592 | if (linker |
067277c3 | 6593 | && IS_DIR_SEPARATOR (path[0]) |
b9374a77 | 6594 | && ((cp - path == 6 |
067277c3 | 6595 | && strncmp (path + 1, "lib", 3) == 0) |
b9374a77 | 6596 | || (cp - path == 10 |
067277c3 | 6597 | && strncmp (path + 1, "usr", 3) == 0 |
6598 | && IS_DIR_SEPARATOR (path[4]) | |
6599 | && strncmp (path + 5, "lib", 3) == 0))) | |
d7a9644e | 6600 | return 0; |
6601 | ||
6602 | return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); | |
6603 | } | |
397f1574 | 6604 | |
6605 | /* Set up the various global variables to indicate that we're processing | |
6606 | the input file named FILENAME. */ | |
6607 | ||
32d661fc | 6608 | void |
952f0048 | 6609 | set_input (const char *filename) |
397f1574 | 6610 | { |
19cb6b50 | 6611 | const char *p; |
397f1574 | 6612 | |
6613 | input_filename = filename; | |
6614 | input_filename_length = strlen (input_filename); | |
cc92bc82 | 6615 | input_basename = lbasename (input_filename); |
397f1574 | 6616 | |
6617 | /* Find a suffix starting with the last period, | |
6618 | and set basename_length to exclude that suffix. */ | |
6619 | basename_length = strlen (input_basename); | |
1cf79a1a | 6620 | suffixed_basename_length = basename_length; |
397f1574 | 6621 | p = input_basename + basename_length; |
026f2c7a | 6622 | while (p != input_basename && *p != '.') |
6623 | --p; | |
397f1574 | 6624 | if (*p == '.' && p != input_basename) |
6625 | { | |
6626 | basename_length = p - input_basename; | |
6627 | input_suffix = p + 1; | |
6628 | } | |
6629 | else | |
6630 | input_suffix = ""; | |
3cfec666 | 6631 | |
74e4079a | 6632 | /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then |
6633 | we will need to do a stat on the input_filename. The | |
6634 | INPUT_STAT_SET signals that the stat is needed. */ | |
6635 | input_stat_set = 0; | |
397f1574 | 6636 | } |
d7a9644e | 6637 | \f |
6638 | /* On fatal signals, delete all the temporary files. */ | |
6639 | ||
6640 | static void | |
952f0048 | 6641 | fatal_error (int signum) |
d7a9644e | 6642 | { |
6643 | signal (signum, SIG_DFL); | |
6644 | delete_failure_queue (); | |
6645 | delete_temp_files (); | |
6646 | /* Get the same signal again, this time not handled, | |
6647 | so its normal effect occurs. */ | |
6648 | kill (getpid (), signum); | |
6649 | } | |
6650 | ||
71278019 | 6651 | /* Compare the contents of the two files named CMPFILE[0] and |
6652 | CMPFILE[1]. Return zero if they're identical, nonzero | |
6653 | otherwise. */ | |
6654 | ||
6655 | static int | |
6656 | compare_files (char *cmpfile[]) | |
6657 | { | |
6658 | int ret = 0; | |
6659 | FILE *temp[2] = { NULL, NULL }; | |
6660 | int i; | |
6661 | ||
6662 | #if HAVE_MMAP_FILE | |
6663 | { | |
6664 | size_t length[2]; | |
6665 | void *map[2] = { NULL, NULL }; | |
6666 | ||
6667 | for (i = 0; i < 2; i++) | |
6668 | { | |
6669 | struct stat st; | |
6670 | ||
6671 | if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode)) | |
6672 | { | |
6673 | error ("%s: could not determine length of compare-debug file %s", | |
6674 | input_filename, cmpfile[i]); | |
6675 | ret = 1; | |
6676 | break; | |
6677 | } | |
6678 | ||
6679 | length[i] = st.st_size; | |
6680 | } | |
6681 | ||
6682 | if (!ret && length[0] != length[1]) | |
6683 | { | |
6684 | error ("%s: -fcompare-debug failure (length)", input_filename); | |
6685 | ret = 1; | |
6686 | } | |
6687 | ||
6688 | if (!ret) | |
6689 | for (i = 0; i < 2; i++) | |
6690 | { | |
6691 | int fd = open (cmpfile[i], O_RDONLY); | |
6692 | if (fd < 0) | |
6693 | { | |
6694 | error ("%s: could not open compare-debug file %s", | |
6695 | input_filename, cmpfile[i]); | |
6696 | ret = 1; | |
6697 | break; | |
6698 | } | |
6699 | ||
6700 | map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0); | |
6701 | close (fd); | |
6702 | ||
6703 | if (map[i] == (void *) MAP_FAILED) | |
6704 | { | |
6705 | ret = -1; | |
6706 | break; | |
6707 | } | |
6708 | } | |
6709 | ||
6710 | if (!ret) | |
6711 | { | |
6712 | if (memcmp (map[0], map[1], length[0]) != 0) | |
6713 | { | |
6714 | error ("%s: -fcompare-debug failure", input_filename); | |
6715 | ret = 1; | |
6716 | } | |
6717 | } | |
6718 | ||
6719 | for (i = 0; i < 2; i++) | |
6720 | if (map[i]) | |
7a63ab96 | 6721 | munmap ((caddr_t) map[i], length[i]); |
71278019 | 6722 | |
6723 | if (ret >= 0) | |
6724 | return ret; | |
6725 | ||
6726 | ret = 0; | |
6727 | } | |
6728 | #endif | |
6729 | ||
6730 | for (i = 0; i < 2; i++) | |
6731 | { | |
6732 | temp[i] = fopen (cmpfile[i], "r"); | |
6733 | if (!temp[i]) | |
6734 | { | |
6735 | error ("%s: could not open compare-debug file %s", | |
6736 | input_filename, cmpfile[i]); | |
6737 | ret = 1; | |
6738 | break; | |
6739 | } | |
6740 | } | |
6741 | ||
6742 | if (!ret && temp[0] && temp[1]) | |
6743 | for (;;) | |
6744 | { | |
6745 | int c0, c1; | |
6746 | c0 = fgetc (temp[0]); | |
6747 | c1 = fgetc (temp[1]); | |
6748 | ||
6749 | if (c0 != c1) | |
6750 | { | |
6751 | error ("%s: -fcompare-debug failure", | |
6752 | input_filename); | |
6753 | ret = 1; | |
6754 | break; | |
6755 | } | |
6756 | ||
6757 | if (c0 == EOF) | |
6758 | break; | |
6759 | } | |
6760 | ||
6761 | for (i = 1; i >= 0; i--) | |
6762 | { | |
6763 | if (temp[i]) | |
6764 | fclose (temp[i]); | |
6765 | } | |
6766 | ||
6767 | return ret; | |
6768 | } | |
6769 | ||
b71cbc18 | 6770 | extern int main (int, char **); |
2ff5acce | 6771 | |
d7a9644e | 6772 | int |
b71cbc18 | 6773 | main (int argc, char **argv) |
d7a9644e | 6774 | { |
1cf79a1a | 6775 | size_t i; |
d7a9644e | 6776 | int value; |
d7a9644e | 6777 | int linker_was_run = 0; |
dc1dd09b | 6778 | int lang_n_infiles = 0; |
573aba85 | 6779 | int num_linker_inputs = 0; |
d7a9644e | 6780 | char *explicit_link_files; |
6781 | char *specs_file; | |
e40d43cc | 6782 | const char *p; |
9d70d39c | 6783 | struct user_specs *uptr; |
c159e0b7 | 6784 | char **old_argv = argv; |
d7a9644e | 6785 | |
9db54d6e | 6786 | /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes |
6787 | on ?: in file-scope variable initializations. */ | |
6788 | asm_debug = ASM_DEBUG_SPEC; | |
6789 | ||
1764779d | 6790 | p = argv[0] + strlen (argv[0]); |
79b23a1e | 6791 | while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) |
6792 | --p; | |
1764779d | 6793 | programname = p; |
d7a9644e | 6794 | |
6deeea15 | 6795 | xmalloc_set_program_name (programname); |
6796 | ||
64271450 | 6797 | expandargv (&argc, &argv); |
6798 | ||
c159e0b7 | 6799 | /* Determine if any expansions were made. */ |
6800 | if (argv != old_argv) | |
6801 | at_file_supplied = true; | |
6802 | ||
a1baa5f1 | 6803 | prune_options (&argc, &argv); |
6804 | ||
4e79af62 | 6805 | #ifdef GCC_DRIVER_HOST_INITIALIZATION |
424da949 | 6806 | /* Perform host dependent initialization when needed. */ |
4e79af62 | 6807 | GCC_DRIVER_HOST_INITIALIZATION; |
6808 | #endif | |
6809 | ||
4367c81f | 6810 | /* Unlock the stdio streams. */ |
9c8f076b | 6811 | unlock_std_streams (); |
4367c81f | 6812 | |
eb718689 | 6813 | gcc_init_libintl (); |
be2828ce | 6814 | |
d7a9644e | 6815 | if (signal (SIGINT, SIG_IGN) != SIG_IGN) |
6816 | signal (SIGINT, fatal_error); | |
294a029f | 6817 | #ifdef SIGHUP |
d7a9644e | 6818 | if (signal (SIGHUP, SIG_IGN) != SIG_IGN) |
6819 | signal (SIGHUP, fatal_error); | |
294a029f | 6820 | #endif |
d7a9644e | 6821 | if (signal (SIGTERM, SIG_IGN) != SIG_IGN) |
6822 | signal (SIGTERM, fatal_error); | |
6823 | #ifdef SIGPIPE | |
6824 | if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) | |
6825 | signal (SIGPIPE, fatal_error); | |
6826 | #endif | |
6b917287 | 6827 | #ifdef SIGCHLD |
1a3768bc | 6828 | /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will |
6829 | receive the signal. A different setting is inheritable */ | |
6830 | signal (SIGCHLD, SIG_DFL); | |
6b917287 | 6831 | #endif |
d7a9644e | 6832 | |
c21b3276 | 6833 | /* Allocate the argument vector. */ |
6834 | alloc_args (); | |
d7a9644e | 6835 | |
6836 | obstack_init (&obstack); | |
6837 | ||
3d97d965 | 6838 | /* Build multilib_select, et. al from the separate lines that make up each |
6839 | multilib selection. */ | |
709c4e1b | 6840 | { |
e772a198 | 6841 | const char *const *q = multilib_raw; |
3d97d965 | 6842 | int need_space; |
709c4e1b | 6843 | |
6844 | obstack_init (&multilib_obstack); | |
a92771b8 | 6845 | while ((p = *q++) != (char *) 0) |
709c4e1b | 6846 | obstack_grow (&multilib_obstack, p, strlen (p)); |
6847 | ||
6848 | obstack_1grow (&multilib_obstack, 0); | |
4fac984f | 6849 | multilib_select = XOBFINISH (&multilib_obstack, const char *); |
3d97d965 | 6850 | |
6851 | q = multilib_matches_raw; | |
6852 | while ((p = *q++) != (char *) 0) | |
6853 | obstack_grow (&multilib_obstack, p, strlen (p)); | |
6854 | ||
6855 | obstack_1grow (&multilib_obstack, 0); | |
4fac984f | 6856 | multilib_matches = XOBFINISH (&multilib_obstack, const char *); |
3d97d965 | 6857 | |
54518c3b | 6858 | q = multilib_exclusions_raw; |
6859 | while ((p = *q++) != (char *) 0) | |
026f2c7a | 6860 | obstack_grow (&multilib_obstack, p, strlen (p)); |
54518c3b | 6861 | |
6862 | obstack_1grow (&multilib_obstack, 0); | |
4fac984f | 6863 | multilib_exclusions = XOBFINISH (&multilib_obstack, const char *); |
2c815aff | 6864 | |
3d97d965 | 6865 | need_space = FALSE; |
3098b2d3 | 6866 | for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++) |
3d97d965 | 6867 | { |
6868 | if (need_space) | |
6869 | obstack_1grow (&multilib_obstack, ' '); | |
6870 | obstack_grow (&multilib_obstack, | |
6871 | multilib_defaults_raw[i], | |
6872 | strlen (multilib_defaults_raw[i])); | |
6873 | need_space = TRUE; | |
6874 | } | |
6875 | ||
6876 | obstack_1grow (&multilib_obstack, 0); | |
4fac984f | 6877 | multilib_defaults = XOBFINISH (&multilib_obstack, const char *); |
709c4e1b | 6878 | } |
6879 | ||
bba01ba8 | 6880 | #ifdef INIT_ENVIRONMENT |
6881 | /* Set up any other necessary machine specific environment variables. */ | |
99c00302 | 6882 | xputenv (INIT_ENVIRONMENT); |
bba01ba8 | 6883 | #endif |
6884 | ||
d7a9644e | 6885 | /* Make a table of what switches there are (switches, n_switches). |
6886 | Make a table of specified input files (infiles, n_infiles). | |
6887 | Decode switches that are handled locally. */ | |
6888 | ||
402ba866 | 6889 | process_command (argc, CONST_CAST2 (const char **, char **, argv)); |
d7a9644e | 6890 | |
6891 | /* Initialize the vector of specs to just the default. | |
6892 | This means one element containing 0s, as a terminator. */ | |
6893 | ||
25a1c410 | 6894 | compilers = XNEWVAR (struct compiler, sizeof default_compilers); |
f0af5a88 | 6895 | memcpy (compilers, default_compilers, sizeof default_compilers); |
d7a9644e | 6896 | n_compilers = n_default_compilers; |
6897 | ||
6898 | /* Read specs from a file if there is one. */ | |
6899 | ||
3441e5dd | 6900 | machine_suffix = concat (spec_machine, dir_separator_str, |
4e2023c8 | 6901 | spec_version, dir_separator_str, NULL); |
6902 | just_machine_suffix = concat (spec_machine, dir_separator_str, NULL); | |
d7a9644e | 6903 | |
067277c3 | 6904 | specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true); |
d7a9644e | 6905 | /* Read the specs file unless it is a default one. */ |
6906 | if (specs_file != 0 && strcmp (specs_file, "specs")) | |
4582d741 | 6907 | read_specs (specs_file, TRUE); |
6908 | else | |
6909 | init_spec (); | |
8b351d3c | 6910 | |
c71f4af0 | 6911 | /* We need to check standard_exec_prefix/just_machine_suffix/specs |
d4ea3b1f | 6912 | for any override of as, ld and libraries. */ |
25a1c410 | 6913 | specs_file = (char *) alloca (strlen (standard_exec_prefix) |
f0af5a88 | 6914 | + strlen (just_machine_suffix) + sizeof ("specs")); |
c71f4af0 | 6915 | |
6916 | strcpy (specs_file, standard_exec_prefix); | |
6917 | strcat (specs_file, just_machine_suffix); | |
6918 | strcat (specs_file, "specs"); | |
6919 | if (access (specs_file, R_OK) == 0) | |
6920 | read_specs (specs_file, TRUE); | |
2c815aff | 6921 | |
7dd97ab6 | 6922 | /* Process any configure-time defaults specified for the command line |
6923 | options, via OPTION_DEFAULT_SPECS. */ | |
6924 | for (i = 0; i < ARRAY_SIZE (option_default_specs); i++) | |
6925 | do_option_spec (option_default_specs[i].name, | |
6926 | option_default_specs[i].spec); | |
6927 | ||
d0faeb9d | 6928 | /* Process DRIVER_SELF_SPECS, adding any new options to the end |
6929 | of the command line. */ | |
6930 | ||
6931 | for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++) | |
6932 | do_self_spec (driver_self_specs[i]); | |
6933 | ||
71278019 | 6934 | if (compare_debug) |
6935 | { | |
6936 | enum save_temps save; | |
6937 | ||
6938 | if (!compare_debug_second) | |
6939 | { | |
6940 | n_switches_debug_check[1] = n_switches; | |
6941 | switches_debug_check[1] = XDUPVEC (struct switchstr, switches, | |
6942 | n_switches + 1); | |
6943 | ||
6944 | do_self_spec ("%:compare-debug-self-opt()"); | |
6945 | n_switches_debug_check[0] = n_switches; | |
6946 | switches_debug_check[0] = switches; | |
6947 | ||
6948 | n_switches = n_switches_debug_check[1]; | |
6949 | switches = switches_debug_check[1]; | |
6950 | } | |
6951 | ||
6952 | /* Avoid crash when computing %j in this early. */ | |
6953 | save = save_temps_flag; | |
6954 | save_temps_flag = SAVE_TEMPS_NONE; | |
6955 | ||
6956 | compare_debug = -compare_debug; | |
6957 | do_self_spec ("%:compare-debug-self-opt()"); | |
6958 | ||
6959 | save_temps_flag = save; | |
6960 | ||
6961 | if (!compare_debug_second) | |
6962 | { | |
6963 | n_switches_debug_check[1] = n_switches; | |
6964 | switches_debug_check[1] = switches; | |
6965 | compare_debug = -compare_debug; | |
6966 | n_switches = n_switches_debug_check[0]; | |
6967 | switches = switches_debug_check[0]; | |
6968 | } | |
6969 | } | |
6970 | ||
805e22b2 | 6971 | /* If not cross-compiling, look for executables in the standard |
6972 | places. */ | |
6973 | if (*cross_compile == '0') | |
a45072dd | 6974 | { |
bfb9bc39 | 6975 | if (*md_exec_prefix) |
6976 | { | |
6977 | add_prefix (&exec_prefixes, md_exec_prefix, "GCC", | |
2af84186 | 6978 | PREFIX_PRIORITY_LAST, 0, 0); |
bfb9bc39 | 6979 | } |
805e22b2 | 6980 | } |
6981 | ||
6473f3f4 | 6982 | /* Process sysroot_suffix_spec. */ |
4ea70922 | 6983 | if (*sysroot_suffix_spec != 0 |
6984 | && do_spec_2 (sysroot_suffix_spec) == 0) | |
6985 | { | |
6986 | if (argbuf_index > 1) | |
0a81f5a0 | 6987 | error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); |
4ea70922 | 6988 | else if (argbuf_index == 1) |
6989 | target_sysroot_suffix = xstrdup (argbuf[argbuf_index -1]); | |
6990 | } | |
6991 | ||
b6bcc48f | 6992 | #ifdef HAVE_LD_SYSROOT |
6993 | /* Pass the --sysroot option to the linker, if it supports that. If | |
6994 | there is a sysroot_suffix_spec, it has already been processed by | |
6995 | this point, so target_system_root really is the system root we | |
6996 | should be using. */ | |
6997 | if (target_system_root) | |
6998 | { | |
6999 | obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) ")); | |
7000 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); | |
4fac984f | 7001 | set_spec ("link", XOBFINISH (&obstack, const char *)); |
b6bcc48f | 7002 | } |
7003 | #endif | |
7004 | ||
6473f3f4 | 7005 | /* Process sysroot_hdrs_suffix_spec. */ |
4ea70922 | 7006 | if (*sysroot_hdrs_suffix_spec != 0 |
7007 | && do_spec_2 (sysroot_hdrs_suffix_spec) == 0) | |
7008 | { | |
7009 | if (argbuf_index > 1) | |
0a81f5a0 | 7010 | error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); |
4ea70922 | 7011 | else if (argbuf_index == 1) |
7012 | target_sysroot_hdrs_suffix = xstrdup (argbuf[argbuf_index -1]); | |
7013 | } | |
7014 | ||
805e22b2 | 7015 | /* Look for startfiles in the standard places. */ |
7016 | if (*startfile_prefix_spec != 0 | |
7017 | && do_spec_2 (startfile_prefix_spec) == 0 | |
7018 | && do_spec_1 (" ", 0, NULL) == 0) | |
7019 | { | |
7020 | int ndx; | |
7021 | for (ndx = 0; ndx < argbuf_index; ndx++) | |
7022 | add_sysrooted_prefix (&startfile_prefixes, argbuf[ndx], "BINUTILS", | |
2af84186 | 7023 | PREFIX_PRIORITY_LAST, 0, 1); |
805e22b2 | 7024 | } |
7025 | /* We should eventually get rid of all these and stick to | |
7026 | startfile_prefix_spec exclusively. */ | |
7027 | else if (*cross_compile == '0' || target_system_root) | |
7028 | { | |
bfb9bc39 | 7029 | if (*md_startfile_prefix) |
805e22b2 | 7030 | add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix, |
2af84186 | 7031 | "GCC", PREFIX_PRIORITY_LAST, 0, 1); |
a45072dd | 7032 | |
bfb9bc39 | 7033 | if (*md_startfile_prefix_1) |
805e22b2 | 7034 | add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1, |
2af84186 | 7035 | "GCC", PREFIX_PRIORITY_LAST, 0, 1); |
1121f96b | 7036 | |
86e5f097 | 7037 | /* If standard_startfile_prefix is relative, base it on |
7038 | standard_exec_prefix. This lets us move the installed tree | |
7039 | as a unit. If GCC_EXEC_PREFIX is defined, base | |
1fbb4a86 | 7040 | standard_startfile_prefix on that as well. |
7041 | ||
7042 | If the prefix is relative, only search it for native compilers; | |
7043 | otherwise we will search a directory containing host libraries. */ | |
a5c088d4 | 7044 | if (IS_ABSOLUTE_PATH (standard_startfile_prefix)) |
805e22b2 | 7045 | add_sysrooted_prefix (&startfile_prefixes, |
7046 | standard_startfile_prefix, "BINUTILS", | |
2af84186 | 7047 | PREFIX_PRIORITY_LAST, 0, 1); |
1fbb4a86 | 7048 | else if (*cross_compile == '0') |
86e5f097 | 7049 | { |
b9374a77 | 7050 | add_prefix (&startfile_prefixes, |
48e1416a | 7051 | concat (gcc_exec_prefix |
7052 | ? gcc_exec_prefix : standard_exec_prefix, | |
7053 | machine_suffix, | |
4e2023c8 | 7054 | standard_startfile_prefix, NULL), |
2af84186 | 7055 | NULL, PREFIX_PRIORITY_LAST, 0, 1); |
2c815aff | 7056 | } |
86e5f097 | 7057 | |
c4328bcc | 7058 | /* Sysrooted prefixes are relocated because target_system_root is |
7059 | also relocated by gcc_exec_prefix. */ | |
3c2ba0de | 7060 | if (*standard_startfile_prefix_1) |
7061 | add_sysrooted_prefix (&startfile_prefixes, | |
7062 | standard_startfile_prefix_1, "BINUTILS", | |
2af84186 | 7063 | PREFIX_PRIORITY_LAST, 0, 1); |
3c2ba0de | 7064 | if (*standard_startfile_prefix_2) |
7065 | add_sysrooted_prefix (&startfile_prefixes, | |
7066 | standard_startfile_prefix_2, "BINUTILS", | |
2af84186 | 7067 | PREFIX_PRIORITY_LAST, 0, 1); |
a45072dd | 7068 | } |
4ae4e5e8 | 7069 | |
c15af0eb | 7070 | /* Process any user specified specs in the order given on the command |
7071 | line. */ | |
7072 | for (uptr = user_specs_head; uptr; uptr = uptr->next) | |
7073 | { | |
c954ff02 | 7074 | char *filename = find_a_file (&startfile_prefixes, uptr->filename, |
067277c3 | 7075 | R_OK, true); |
c15af0eb | 7076 | read_specs (filename ? filename : uptr->filename, FALSE); |
7077 | } | |
7078 | ||
533d7727 | 7079 | /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */ |
7080 | if (gcc_exec_prefix) | |
47950139 | 7081 | gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str, |
7082 | spec_version, dir_separator_str, NULL); | |
a45072dd | 7083 | |
d7a9644e | 7084 | /* Now we have the specs. |
7085 | Set the `valid' bits for switches that match anything in any spec. */ | |
7086 | ||
7087 | validate_all_switches (); | |
7088 | ||
9577d478 | 7089 | /* Now that we have the switches and the specs, set |
7090 | the subdirectory based on the options. */ | |
7091 | set_multilib_dir (); | |
7092 | ||
7bfefa9d | 7093 | /* Set up to remember the pathname of gcc and any options |
7094 | needed for collect. We use argv[0] instead of programname because | |
7095 | we need the complete pathname. */ | |
7096 | obstack_init (&collect_obstack); | |
7097 | obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1); | |
7098 | obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1); | |
7099 | xputenv (XOBFINISH (&collect_obstack, char *)); | |
7100 | ||
7101 | /* Set up to remember the pathname of the lto wrapper. */ | |
7102 | ||
7103 | lto_wrapper_spec = find_a_file (&exec_prefixes, "lto-wrapper", X_OK, false); | |
7104 | if (lto_wrapper_spec) | |
7105 | { | |
7106 | obstack_init (&collect_obstack); | |
7107 | obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=", | |
7108 | sizeof ("COLLECT_LTO_WRAPPER=") - 1); | |
7109 | obstack_grow (&collect_obstack, lto_wrapper_spec, | |
7110 | strlen (lto_wrapper_spec) + 1); | |
7111 | xputenv (XOBFINISH (&collect_obstack, char *)); | |
7112 | } | |
7113 | ||
d7a9644e | 7114 | /* Warn about any switches that no pass was interested in. */ |
7115 | ||
026f2c7a | 7116 | for (i = 0; (int) i < n_switches; i++) |
be2828ce | 7117 | if (! switches[i].validated) |
1e5fcbe2 | 7118 | error ("unrecognized option '-%s'", switches[i].part1); |
d7a9644e | 7119 | |
1c1a1c70 | 7120 | /* Obey some of the options. */ |
7121 | ||
71cee7b1 | 7122 | if (print_search_dirs) |
7123 | { | |
c4328bcc | 7124 | printf (_("install: %s%s\n"), |
7125 | gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix, | |
7126 | gcc_exec_prefix ? "" : machine_suffix); | |
067277c3 | 7127 | printf (_("programs: %s\n"), |
7128 | build_search_list (&exec_prefixes, "", false, false)); | |
7129 | printf (_("libraries: %s\n"), | |
7130 | build_search_list (&startfile_prefixes, "", false, true)); | |
7f0b0c27 | 7131 | return (0); |
71cee7b1 | 7132 | } |
7133 | ||
1c1a1c70 | 7134 | if (print_file_name) |
5e3dea2b | 7135 | { |
1c1a1c70 | 7136 | printf ("%s\n", find_file (print_file_name)); |
7f0b0c27 | 7137 | return (0); |
5e3dea2b | 7138 | } |
7139 | ||
1c1a1c70 | 7140 | if (print_prog_name) |
7141 | { | |
c954ff02 | 7142 | char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0); |
1c1a1c70 | 7143 | printf ("%s\n", (newname ? newname : print_prog_name)); |
7f0b0c27 | 7144 | return (0); |
1c1a1c70 | 7145 | } |
d7a9644e | 7146 | |
9577d478 | 7147 | if (print_multi_lib) |
7148 | { | |
7149 | print_multilib_info (); | |
7f0b0c27 | 7150 | return (0); |
9577d478 | 7151 | } |
7152 | ||
7153 | if (print_multi_directory) | |
7154 | { | |
7155 | if (multilib_dir == NULL) | |
7156 | printf (".\n"); | |
7157 | else | |
7158 | printf ("%s\n", multilib_dir); | |
7f0b0c27 | 7159 | return (0); |
9577d478 | 7160 | } |
7161 | ||
098cc23f | 7162 | if (print_sysroot) |
7163 | { | |
7164 | if (target_system_root) | |
7165 | { | |
7166 | if (target_sysroot_suffix) | |
7167 | printf ("%s%s\n", target_system_root, target_sysroot_suffix); | |
7168 | else | |
7169 | printf ("%s\n", target_system_root); | |
7170 | } | |
7171 | return (0); | |
7172 | } | |
7173 | ||
c954ff02 | 7174 | if (print_multi_os_directory) |
7175 | { | |
7176 | if (multilib_os_dir == NULL) | |
7177 | printf (".\n"); | |
7178 | else | |
7179 | printf ("%s\n", multilib_os_dir); | |
7180 | return (0); | |
7181 | } | |
7182 | ||
6ea4242f | 7183 | if (print_sysroot_headers_suffix) |
7184 | { | |
7185 | if (*sysroot_hdrs_suffix_spec) | |
7186 | { | |
021d874e | 7187 | printf("%s\n", (target_sysroot_hdrs_suffix |
7188 | ? target_sysroot_hdrs_suffix | |
7189 | : "")); | |
6ea4242f | 7190 | return (0); |
7191 | } | |
7192 | else | |
7193 | /* The error status indicates that only one set of fixed | |
7194 | headers should be built. */ | |
7195 | fatal ("not configured with sysroot headers suffix"); | |
7196 | } | |
7197 | ||
8ace789a | 7198 | if (print_help_list) |
7199 | { | |
7200 | display_help (); | |
7201 | ||
7202 | if (! verbose_flag) | |
7203 | { | |
a4db0a1d | 7204 | printf (_("\nFor bug reporting instructions, please see:\n")); |
4b5ee00b | 7205 | printf ("%s.\n", bug_report_url); |
2c815aff | 7206 | |
7f0b0c27 | 7207 | return (0); |
8ace789a | 7208 | } |
7209 | ||
7210 | /* We do not exit here. Instead we have created a fake input file | |
7211 | called 'help-dummy' which needs to be compiled, and we pass this | |
0445c349 | 7212 | on the various sub-processes, along with the --help switch. |
7213 | Ensure their output appears after ours. */ | |
7214 | fputc ('\n', stdout); | |
7215 | fflush (stdout); | |
8ace789a | 7216 | } |
2c815aff | 7217 | |
39932bd2 | 7218 | if (print_version) |
7219 | { | |
7220 | printf (_("%s %s%s\n"), programname, pkgversion_string, | |
7221 | version_string); | |
7222 | printf ("Copyright %s 2009 Free Software Foundation, Inc.\n", | |
7223 | _("(C)")); | |
7224 | fputs (_("This is free software; see the source for copying conditions. There is NO\n\ | |
7225 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), | |
7226 | stdout); | |
7227 | if (! verbose_flag) | |
7228 | return 0; | |
7229 | ||
7230 | /* We do not exit here. We use the same mechanism of --help to print | |
7231 | the version of the sub-processes. */ | |
7232 | fputc ('\n', stdout); | |
7233 | fflush (stdout); | |
7234 | } | |
7235 | ||
d7a9644e | 7236 | if (verbose_flag) |
7237 | { | |
e3ccb76d | 7238 | int n; |
d1cac662 | 7239 | const char *thrmod; |
e3ccb76d | 7240 | |
f7e464d3 | 7241 | notice ("Target: %s\n", spec_machine); |
4a0e2d42 | 7242 | notice ("Configured with: %s\n", configuration_arguments); |
7243 | ||
d1cac662 | 7244 | #ifdef THREAD_MODEL_SPEC |
7245 | /* We could have defined THREAD_MODEL_SPEC to "%*" by default, | |
7246 | but there's no point in doing all this processing just to get | |
7247 | thread_model back. */ | |
7248 | obstack_init (&obstack); | |
7249 | do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model); | |
7250 | obstack_1grow (&obstack, '\0'); | |
4fac984f | 7251 | thrmod = XOBFINISH (&obstack, const char *); |
d1cac662 | 7252 | #else |
7253 | thrmod = thread_model; | |
7254 | #endif | |
7255 | ||
7256 | notice ("Thread model: %s\n", thrmod); | |
6d72c630 | 7257 | |
e3ccb76d | 7258 | /* compiler_version is truncated at the first space when initialized |
7259 | from version string, so truncate version_string at the first space | |
7260 | before comparing. */ | |
7261 | for (n = 0; version_string[n]; n++) | |
7262 | if (version_string[n] == ' ') | |
7263 | break; | |
7264 | ||
7265 | if (! strncmp (version_string, compiler_version, n) | |
7266 | && compiler_version[n] == 0) | |
d25dc80e | 7267 | notice ("gcc version %s %s\n", version_string, pkgversion_string); |
845bccef | 7268 | else |
d25dc80e | 7269 | notice ("gcc driver version %s %sexecuting gcc version %s\n", |
7270 | version_string, pkgversion_string, compiler_version); | |
845bccef | 7271 | |
d7a9644e | 7272 | if (n_infiles == 0) |
7f0b0c27 | 7273 | return (0); |
d7a9644e | 7274 | } |
7275 | ||
9e56255a | 7276 | if (n_infiles == added_libraries) |
cb8bacb6 | 7277 | fatal ("no input files"); |
d7a9644e | 7278 | |
7279 | /* Make a place to record the compiler output file names | |
7280 | that correspond to the input files. */ | |
7281 | ||
f9b7c0b9 | 7282 | i = n_infiles; |
5272ae11 | 7283 | i += lang_specific_extra_outfiles; |
4c36ffe6 | 7284 | outfiles = XCNEWVEC (const char *, i); |
d7a9644e | 7285 | |
7286 | /* Record which files were specified explicitly as link input. */ | |
7287 | ||
468329f6 | 7288 | explicit_link_files = XCNEWVEC (char, n_infiles); |
d7a9644e | 7289 | |
dc1dd09b | 7290 | if (combine_flag) |
7291 | combine_inputs = true; | |
7292 | else | |
1e8e9920 | 7293 | combine_inputs = false; |
dc1dd09b | 7294 | |
7295 | for (i = 0; (int) i < n_infiles; i++) | |
40109983 | 7296 | { |
dc1dd09b | 7297 | const char *name = infiles[i].name; |
2f2c6aee | 7298 | struct compiler *compiler = lookup_compiler (name, |
7299 | strlen (name), | |
dc1dd09b | 7300 | infiles[i].language); |
2f2c6aee | 7301 | |
dc1dd09b | 7302 | if (compiler && !(compiler->combinable)) |
7303 | combine_inputs = false; | |
2f2c6aee | 7304 | |
dc1dd09b | 7305 | if (lang_n_infiles > 0 && compiler != input_file_compiler |
7306 | && infiles[i].language && infiles[i].language[0] != '*') | |
7307 | infiles[i].incompiler = compiler; | |
7308 | else if (compiler) | |
7309 | { | |
7310 | lang_n_infiles++; | |
7311 | input_file_compiler = compiler; | |
7312 | infiles[i].incompiler = compiler; | |
7313 | } | |
7314 | else | |
7315 | { | |
7316 | /* Since there is no compiler for this input file, assume it is a | |
0bed3869 | 7317 | linker file. */ |
dc1dd09b | 7318 | explicit_link_files[i] = 1; |
7319 | infiles[i].incompiler = NULL; | |
7320 | } | |
7321 | infiles[i].compiled = false; | |
7322 | infiles[i].preprocessed = false; | |
40109983 | 7323 | } |
1e8e9920 | 7324 | |
1c15f131 | 7325 | if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) |
a2000777 | 7326 | fatal ("cannot specify -o with -c, -S or -E with multiple files"); |
2f2c6aee | 7327 | |
dc1dd09b | 7328 | if (combine_flag && save_temps_flag) |
7329 | { | |
7330 | bool save_combine_inputs = combine_inputs; | |
7331 | /* Must do a separate pre-processing pass for C & Objective-C files, to | |
7332 | obtain individual .i files. */ | |
7333 | ||
7334 | combine_inputs = false; | |
7335 | for (i = 0; (int) i < n_infiles; i++) | |
7336 | { | |
7337 | int this_file_error = 0; | |
2f2c6aee | 7338 | |
dc1dd09b | 7339 | input_file_number = i; |
7340 | set_input (infiles[i].name); | |
7341 | if (infiles[i].incompiler | |
7342 | && (infiles[i].incompiler)->needs_preprocessing) | |
7343 | input_file_compiler = infiles[i].incompiler; | |
7344 | else | |
7345 | continue; | |
7346 | ||
7347 | if (input_file_compiler) | |
7348 | { | |
7349 | if (input_file_compiler->spec[0] == '#') | |
7350 | { | |
7351 | error ("%s: %s compiler not installed on this system", | |
7352 | input_filename, &input_file_compiler->spec[1]); | |
7353 | this_file_error = 1; | |
7354 | } | |
7355 | else | |
7356 | { | |
7357 | value = do_spec (input_file_compiler->spec); | |
7358 | infiles[i].preprocessed = true; | |
5e8f3c31 | 7359 | if (!have_o_argbuf_index) |
1e5fcbe2 | 7360 | fatal ("spec '%s' is invalid", input_file_compiler->spec); |
5e8f3c31 | 7361 | infiles[i].name = argbuf[have_o_argbuf_index]; |
7362 | infiles[i].incompiler | |
7363 | = lookup_compiler (infiles[i].name, | |
7364 | strlen (infiles[i].name), | |
7365 | infiles[i].language); | |
dc1dd09b | 7366 | |
7367 | if (value < 0) | |
e40d30f5 | 7368 | this_file_error = 1; |
dc1dd09b | 7369 | } |
7370 | } | |
7371 | ||
7372 | if (this_file_error) | |
7373 | { | |
7374 | delete_failure_queue (); | |
7375 | error_count++; | |
e40d30f5 | 7376 | break; |
dc1dd09b | 7377 | } |
7378 | clear_failure_queue (); | |
7379 | } | |
7380 | combine_inputs = save_combine_inputs; | |
7381 | } | |
7382 | ||
7383 | for (i = 0; (int) i < n_infiles; i++) | |
d7a9644e | 7384 | { |
d7a9644e | 7385 | int this_file_error = 0; |
7386 | ||
7387 | /* Tell do_spec what to substitute for %i. */ | |
7388 | ||
d7a9644e | 7389 | input_file_number = i; |
397f1574 | 7390 | set_input (infiles[i].name); |
d7a9644e | 7391 | |
dc1dd09b | 7392 | if (infiles[i].compiled) |
7393 | continue; | |
7394 | ||
d7a9644e | 7395 | /* Use the same thing in %o, unless cp->spec says otherwise. */ |
7396 | ||
7397 | outfiles[i] = input_filename; | |
7398 | ||
7399 | /* Figure out which compiler from the file's suffix. */ | |
7400 | ||
40109983 | 7401 | if (! combine_inputs) |
7402 | input_file_compiler | |
7403 | = lookup_compiler (infiles[i].name, input_filename_length, | |
7404 | infiles[i].language); | |
dc1dd09b | 7405 | else |
7406 | input_file_compiler = infiles[i].incompiler; | |
3cfec666 | 7407 | |
96842e40 | 7408 | if (input_file_compiler) |
d7a9644e | 7409 | { |
7410 | /* Ok, we found an applicable compiler. Run its spec. */ | |
d7a9644e | 7411 | |
96842e40 | 7412 | if (input_file_compiler->spec[0] == '#') |
ce52dcfa | 7413 | { |
7414 | error ("%s: %s compiler not installed on this system", | |
7415 | input_filename, &input_file_compiler->spec[1]); | |
7416 | this_file_error = 1; | |
7417 | } | |
7418 | else | |
7419 | { | |
71278019 | 7420 | if (compare_debug) |
7421 | { | |
7422 | if (debug_check_temp_file[0]) | |
7423 | free (debug_check_temp_file[0]); | |
7424 | debug_check_temp_file[0] = NULL; | |
7425 | ||
7426 | if (debug_check_temp_file[1]) | |
7427 | free (debug_check_temp_file[1]); | |
7428 | debug_check_temp_file[1] = NULL; | |
7429 | } | |
7430 | ||
ce52dcfa | 7431 | value = do_spec (input_file_compiler->spec); |
dc1dd09b | 7432 | infiles[i].compiled = true; |
ce52dcfa | 7433 | if (value < 0) |
e40d30f5 | 7434 | this_file_error = 1; |
71278019 | 7435 | else if (compare_debug && debug_check_temp_file[0]) |
7436 | { | |
7437 | if (verbose_flag) | |
7438 | error ("Recompiling with -fcompare-debug"); | |
7439 | ||
7440 | compare_debug = -compare_debug; | |
7441 | n_switches = n_switches_debug_check[1]; | |
7442 | switches = switches_debug_check[1]; | |
7443 | ||
7444 | value = do_spec (input_file_compiler->spec); | |
7445 | ||
7446 | compare_debug = -compare_debug; | |
7447 | n_switches = n_switches_debug_check[0]; | |
7448 | switches = switches_debug_check[0]; | |
7449 | ||
7450 | if (value < 0) | |
7451 | { | |
7452 | error ("during -fcompare-debug recompilation"); | |
7453 | this_file_error = 1; | |
7454 | } | |
7455 | ||
7456 | gcc_assert (debug_check_temp_file[1] | |
7457 | && strcmp (debug_check_temp_file[0], | |
7458 | debug_check_temp_file[1])); | |
7459 | ||
7460 | if (verbose_flag) | |
7461 | error ("Comparing final insns dumps"); | |
7462 | ||
7463 | if (compare_files (debug_check_temp_file)) | |
7464 | this_file_error = 1; | |
7465 | } | |
7466 | ||
7467 | if (compare_debug) | |
7468 | { | |
7469 | if (debug_check_temp_file[0]) | |
7470 | free (debug_check_temp_file[0]); | |
7471 | debug_check_temp_file[0] = NULL; | |
7472 | ||
7473 | if (debug_check_temp_file[1]) | |
7474 | free (debug_check_temp_file[1]); | |
7475 | debug_check_temp_file[1] = NULL; | |
7476 | } | |
ce52dcfa | 7477 | } |
d7a9644e | 7478 | } |
7479 | ||
7480 | /* If this file's name does not contain a recognized suffix, | |
7481 | record it as explicit linker input. */ | |
7482 | ||
7483 | else | |
7484 | explicit_link_files[i] = 1; | |
7485 | ||
7486 | /* Clear the delete-on-failure queue, deleting the files in it | |
7487 | if this compilation failed. */ | |
7488 | ||
7489 | if (this_file_error) | |
7490 | { | |
7491 | delete_failure_queue (); | |
7492 | error_count++; | |
7493 | } | |
7494 | /* If this compilation succeeded, don't delete those files later. */ | |
7495 | clear_failure_queue (); | |
7496 | } | |
7497 | ||
fbf54d9a | 7498 | /* Reset the input file name to the first compile/object file name, for use |
7499 | with %b in LINK_SPEC. We use the first input file that we can find | |
2f2c6aee | 7500 | a compiler to compile it instead of using infiles.language since for |
fbf54d9a | 7501 | languages other than C we use aliases that we then lookup later. */ |
397f1574 | 7502 | if (n_infiles > 0) |
fbf54d9a | 7503 | { |
7504 | int i; | |
7505 | ||
7506 | for (i = 0; i < n_infiles ; i++) | |
fdc57a98 | 7507 | if (infiles[i].language && infiles[i].language[0] != '*') |
fbf54d9a | 7508 | { |
7509 | set_input (infiles[i].name); | |
7510 | break; | |
7511 | } | |
7512 | } | |
397f1574 | 7513 | |
2b191381 | 7514 | if (error_count == 0) |
7515 | { | |
7516 | /* Make sure INPUT_FILE_NUMBER points to first available open | |
7517 | slot. */ | |
7518 | input_file_number = n_infiles; | |
7519 | if (lang_specific_pre_link ()) | |
7520 | error_count++; | |
7521 | } | |
f9b7c0b9 | 7522 | |
573aba85 | 7523 | /* Determine if there are any linker input files. */ |
7524 | num_linker_inputs = 0; | |
7525 | for (i = 0; (int) i < n_infiles; i++) | |
7526 | if (explicit_link_files[i] || outfiles[i] != NULL) | |
7527 | num_linker_inputs++; | |
7528 | ||
d7a9644e | 7529 | /* Run ld to link all the compiler output files. */ |
7530 | ||
4b70b183 | 7531 | if (num_linker_inputs > 0 && error_count == 0 && print_subprocess_help < 2) |
d7a9644e | 7532 | { |
7533 | int tmp = execution_count; | |
386fbe6a | 7534 | const char *fuse_linker_plugin = "fuse-linker-plugin"; |
8894538a | 7535 | |
2c815aff | 7536 | /* We'll use ld if we can't find collect2. */ |
0c787992 | 7537 | if (! strcmp (linker_name_spec, "collect2")) |
7538 | { | |
067277c3 | 7539 | char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false); |
0c787992 | 7540 | if (s == NULL) |
7541 | linker_name_spec = "ld"; | |
7542 | } | |
7bfefa9d | 7543 | |
386fbe6a | 7544 | if (switch_matches (fuse_linker_plugin, |
7545 | fuse_linker_plugin + strlen (fuse_linker_plugin), 0)) | |
7bfefa9d | 7546 | { |
7547 | linker_plugin_file_spec = find_a_file (&exec_prefixes, | |
7548 | "liblto_plugin.so", X_OK, | |
7549 | false); | |
7550 | if (!linker_plugin_file_spec) | |
386fbe6a | 7551 | fatal ("-fuse-linker-plugin, but liblto_plugin.so not found"); |
7bfefa9d | 7552 | |
7553 | lto_libgcc_spec = find_a_file (&startfile_prefixes, "libgcc.a", | |
7554 | R_OK, true); | |
7555 | if (!lto_libgcc_spec) | |
c0c9519f | 7556 | fatal ("could not find libgcc.a"); |
7bfefa9d | 7557 | } |
7558 | lto_gcc_spec = argv[0]; | |
7559 | ||
8894538a | 7560 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
7561 | for collect. */ | |
067277c3 | 7562 | putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false); |
7563 | putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true); | |
8894538a | 7564 | |
ceac8e8c | 7565 | if (print_subprocess_help == 1) |
7566 | { | |
7567 | printf (_("\nLinker options\n==============\n\n")); | |
7568 | printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\"" | |
7569 | " to the linker.\n\n")); | |
7570 | fflush (stdout); | |
7571 | } | |
d7a9644e | 7572 | value = do_spec (link_command_spec); |
7573 | if (value < 0) | |
7574 | error_count = 1; | |
7575 | linker_was_run = (tmp != execution_count); | |
7576 | } | |
7577 | ||
d7a9644e | 7578 | /* If options said don't run linker, |
7579 | complain about input files to be given to the linker. */ | |
7580 | ||
06774693 | 7581 | if (! linker_was_run && error_count == 0) |
026f2c7a | 7582 | for (i = 0; (int) i < n_infiles; i++) |
3293d046 | 7583 | if (explicit_link_files[i] |
7584 | && !(infiles[i].language && infiles[i].language[0] == '*')) | |
0a218888 | 7585 | error ("%s: linker input file unused because linking not done", |
d7a9644e | 7586 | outfiles[i]); |
7587 | ||
7588 | /* Delete some or all of the temporary files we made. */ | |
7589 | ||
7590 | if (error_count) | |
7591 | delete_failure_queue (); | |
7592 | delete_temp_files (); | |
7593 | ||
8ace789a | 7594 | if (print_help_list) |
7595 | { | |
a4db0a1d | 7596 | printf (("\nFor bug reporting instructions, please see:\n")); |
4b5ee00b | 7597 | printf ("%s\n", bug_report_url); |
8ace789a | 7598 | } |
2c815aff | 7599 | |
155b05dc | 7600 | return (signal_count != 0 ? 2 |
7601 | : error_count > 0 ? (pass_exit_codes ? greatest_status : 1) | |
7602 | : 0); | |
d7a9644e | 7603 | } |
7604 | ||
7605 | /* Find the proper compilation spec for the file name NAME, | |
a45072dd | 7606 | whose length is LENGTH. LANGUAGE is the specified language, |
997d68fe | 7607 | or 0 if this file is to be passed to the linker. */ |
d7a9644e | 7608 | |
7609 | static struct compiler * | |
952f0048 | 7610 | lookup_compiler (const char *name, size_t length, const char *language) |
d7a9644e | 7611 | { |
7612 | struct compiler *cp; | |
7613 | ||
d4ea3b1f | 7614 | /* If this was specified by the user to be a linker input, indicate that. */ |
997d68fe | 7615 | if (language != 0 && language[0] == '*') |
7616 | return 0; | |
7617 | ||
7618 | /* Otherwise, look for the language, if one is spec'd. */ | |
d7a9644e | 7619 | if (language != 0) |
7620 | { | |
7621 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) | |
997d68fe | 7622 | if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language)) |
7623 | return cp; | |
7624 | ||
d7a9644e | 7625 | error ("language %s not recognized", language); |
997d68fe | 7626 | return 0; |
d7a9644e | 7627 | } |
7628 | ||
7629 | /* Look for a suffix. */ | |
7630 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) | |
7631 | { | |
a3102c3c | 7632 | if (/* The suffix `-' matches only the file name `-'. */ |
7633 | (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) | |
997d68fe | 7634 | || (strlen (cp->suffix) < length |
7635 | /* See if the suffix matches the end of NAME. */ | |
997d68fe | 7636 | && !strcmp (cp->suffix, |
7637 | name + length - strlen (cp->suffix)) | |
997d68fe | 7638 | )) |
3cfec666 | 7639 | break; |
22869eeb | 7640 | } |
997d68fe | 7641 | |
22869eeb | 7642 | #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM) |
aab2cf92 | 7643 | /* Look again, but case-insensitively this time. */ |
22869eeb | 7644 | if (cp < compilers) |
7645 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) | |
7646 | { | |
7647 | if (/* The suffix `-' matches only the file name `-'. */ | |
7648 | (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) | |
7649 | || (strlen (cp->suffix) < length | |
7650 | /* See if the suffix matches the end of NAME. */ | |
7651 | && ((!strcmp (cp->suffix, | |
7652 | name + length - strlen (cp->suffix)) | |
7653 | || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) | |
7654 | && !strcasecmp (cp->suffix, | |
7655 | name + length - strlen (cp->suffix))) | |
7656 | )) | |
7657 | break; | |
7658 | } | |
7659 | #endif | |
7660 | ||
22869eeb | 7661 | if (cp >= compilers) |
7662 | { | |
1cf79a1a | 7663 | if (cp->spec[0] != '@') |
7664 | /* A non-alias entry: return it. */ | |
7665 | return cp; | |
2c815aff | 7666 | |
1cf79a1a | 7667 | /* An alias entry maps a suffix to a language. |
7668 | Search for the language; pass 0 for NAME and LENGTH | |
7669 | to avoid infinite recursion if language not found. */ | |
d946ea19 | 7670 | return lookup_compiler (NULL, 0, cp->spec + 1); |
d7a9644e | 7671 | } |
d7a9644e | 7672 | return 0; |
7673 | } | |
7674 | \f | |
d7a9644e | 7675 | static char * |
952f0048 | 7676 | save_string (const char *s, int len) |
d7a9644e | 7677 | { |
4c36ffe6 | 7678 | char *result = XNEWVEC (char, len + 1); |
d7a9644e | 7679 | |
d5130039 | 7680 | memcpy (result, s, len); |
d7a9644e | 7681 | result[len] = 0; |
7682 | return result; | |
7683 | } | |
7684 | ||
833a5c07 | 7685 | void |
952f0048 | 7686 | pfatal_with_name (const char *name) |
d7a9644e | 7687 | { |
be2828ce | 7688 | perror_with_name (name); |
7689 | delete_temp_files (); | |
7690 | exit (1); | |
d7a9644e | 7691 | } |
7692 | ||
7693 | static void | |
952f0048 | 7694 | perror_with_name (const char *name) |
d7a9644e | 7695 | { |
99e61852 | 7696 | error ("%s: %s", name, xstrerror (errno)); |
d7a9644e | 7697 | } |
7698 | ||
2358393e | 7699 | /* Output an error message and exit. */ |
d7a9644e | 7700 | |
7701 | void | |
117115d0 | 7702 | fancy_abort (const char *file, int line, const char *func) |
d7a9644e | 7703 | { |
87011ef0 | 7704 | fatal_ice ("internal gcc abort in %s, at %s:%d", func, file, line); |
d7a9644e | 7705 | } |
7706 | \f | |
2358393e | 7707 | /* Output an error message and exit. */ |
d7a9644e | 7708 | |
87011ef0 | 7709 | void |
7710 | fatal_ice (const char *cmsgid, ...) | |
7711 | { | |
7712 | va_list ap; | |
7713 | ||
7714 | va_start (ap, cmsgid); | |
7715 | ||
7716 | fprintf (stderr, "%s: ", programname); | |
7717 | vfprintf (stderr, _(cmsgid), ap); | |
7718 | va_end (ap); | |
7719 | fprintf (stderr, "\n"); | |
7720 | delete_temp_files (); | |
7721 | exit (pass_exit_codes ? ICE_EXIT_CODE : 1); | |
7722 | } | |
7723 | ||
7f0b0c27 | 7724 | void |
380c6697 | 7725 | fatal (const char *cmsgid, ...) |
d7a9644e | 7726 | { |
ee582a61 | 7727 | va_list ap; |
952f0048 | 7728 | |
380c6697 | 7729 | va_start (ap, cmsgid); |
d7a9644e | 7730 | |
d7a9644e | 7731 | fprintf (stderr, "%s: ", programname); |
380c6697 | 7732 | vfprintf (stderr, _(cmsgid), ap); |
ee582a61 | 7733 | va_end (ap); |
d7a9644e | 7734 | fprintf (stderr, "\n"); |
7735 | delete_temp_files (); | |
7736 | exit (1); | |
7737 | } | |
7738 | ||
380c6697 | 7739 | /* The argument is actually c-format, not gcc-internal-format, |
7740 | but because functions with identical names are used through | |
7741 | the rest of the compiler with gcc-internal-format, we just | |
7742 | need to hope all users of these functions use the common | |
7743 | subset between c-format and gcc-internal-format. */ | |
7744 | ||
833a5c07 | 7745 | void |
380c6697 | 7746 | error (const char *gmsgid, ...) |
d7a9644e | 7747 | { |
ee582a61 | 7748 | va_list ap; |
952f0048 | 7749 | |
380c6697 | 7750 | va_start (ap, gmsgid); |
d7a9644e | 7751 | fprintf (stderr, "%s: ", programname); |
380c6697 | 7752 | vfprintf (stderr, _(gmsgid), ap); |
ee582a61 | 7753 | va_end (ap); |
d7a9644e | 7754 | |
7755 | fprintf (stderr, "\n"); | |
7756 | } | |
be2828ce | 7757 | |
7758 | static void | |
380c6697 | 7759 | notice (const char *cmsgid, ...) |
be2828ce | 7760 | { |
ee582a61 | 7761 | va_list ap; |
952f0048 | 7762 | |
380c6697 | 7763 | va_start (ap, cmsgid); |
7764 | vfprintf (stderr, _(cmsgid), ap); | |
ee582a61 | 7765 | va_end (ap); |
be2828ce | 7766 | } |
d7a9644e | 7767 | \f |
805e22b2 | 7768 | static inline void |
952f0048 | 7769 | validate_switches_from_spec (const char *spec) |
805e22b2 | 7770 | { |
7771 | const char *p = spec; | |
7772 | char c; | |
7773 | while ((c = *p++)) | |
7774 | if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{'))) | |
7775 | /* We have a switch spec. */ | |
7776 | p = validate_switches (p + 1); | |
7777 | } | |
7778 | ||
d7a9644e | 7779 | static void |
952f0048 | 7780 | validate_all_switches (void) |
d7a9644e | 7781 | { |
7782 | struct compiler *comp; | |
8894538a | 7783 | struct spec_list *spec; |
d7a9644e | 7784 | |
1cf79a1a | 7785 | for (comp = compilers; comp->spec; comp++) |
805e22b2 | 7786 | validate_switches_from_spec (comp->spec); |
d7a9644e | 7787 | |
d4ea3b1f | 7788 | /* Look through the linked list of specs read from the specs file. */ |
026f2c7a | 7789 | for (spec = specs; spec; spec = spec->next) |
805e22b2 | 7790 | validate_switches_from_spec (*spec->ptr_spec); |
8894538a | 7791 | |
805e22b2 | 7792 | validate_switches_from_spec (link_command_spec); |
d7a9644e | 7793 | } |
7794 | ||
7795 | /* Look at the switch-name that comes after START | |
7796 | and mark as valid all supplied switches that match it. */ | |
7797 | ||
805e22b2 | 7798 | static const char * |
952f0048 | 7799 | validate_switches (const char *start) |
d7a9644e | 7800 | { |
19cb6b50 | 7801 | const char *p = start; |
805e22b2 | 7802 | const char *atom; |
7803 | size_t len; | |
19cb6b50 | 7804 | int i; |
805e22b2 | 7805 | bool suffix = false; |
7806 | bool starred = false; | |
952f0048 | 7807 | |
805e22b2 | 7808 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) |
952f0048 | 7809 | |
dead3293 | 7810 | next_member: |
805e22b2 | 7811 | SKIP_WHITE (); |
7812 | ||
d7a9644e | 7813 | if (*p == '!') |
805e22b2 | 7814 | p++; |
d7a9644e | 7815 | |
805e22b2 | 7816 | SKIP_WHITE (); |
90e35d1a | 7817 | if (*p == '.' || *p == ',') |
805e22b2 | 7818 | suffix = true, p++; |
d7a9644e | 7819 | |
805e22b2 | 7820 | atom = p; |
7821 | while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '=' | |
9a4a603c | 7822 | || *p == ',' || *p == '.' || *p == '@') |
026f2c7a | 7823 | p++; |
805e22b2 | 7824 | len = p - atom; |
d7a9644e | 7825 | |
805e22b2 | 7826 | if (*p == '*') |
7827 | starred = true, p++; | |
7828 | ||
7829 | SKIP_WHITE (); | |
7830 | ||
7831 | if (!suffix) | |
d7a9644e | 7832 | { |
7833 | /* Mark all matching switches as valid. */ | |
d7a9644e | 7834 | for (i = 0; i < n_switches; i++) |
805e22b2 | 7835 | if (!strncmp (switches[i].part1, atom, len) |
7836 | && (starred || switches[i].part1[len] == 0)) | |
be2828ce | 7837 | switches[i].validated = 1; |
d7a9644e | 7838 | } |
805e22b2 | 7839 | |
49aaac6f | 7840 | if (*p) p++; |
7841 | if (*p && (p[-1] == '|' || p[-1] == '&')) | |
805e22b2 | 7842 | goto next_member; |
7843 | ||
49aaac6f | 7844 | if (*p && p[-1] == ':') |
d7a9644e | 7845 | { |
805e22b2 | 7846 | while (*p && *p != ';' && *p != '}') |
d7a9644e | 7847 | { |
805e22b2 | 7848 | if (*p == '%') |
7849 | { | |
7850 | p++; | |
7851 | if (*p == '{' || *p == '<') | |
7852 | p = validate_switches (p+1); | |
7853 | else if (p[0] == 'W' && p[1] == '{') | |
7854 | p = validate_switches (p+2); | |
7855 | } | |
41b8b07e | 7856 | else |
7857 | p++; | |
d7a9644e | 7858 | } |
805e22b2 | 7859 | |
49aaac6f | 7860 | if (*p) p++; |
7861 | if (*p && p[-1] == ';') | |
805e22b2 | 7862 | goto next_member; |
d7a9644e | 7863 | } |
dead3293 | 7864 | |
805e22b2 | 7865 | return p; |
7866 | #undef SKIP_WHITE | |
d7a9644e | 7867 | } |
9577d478 | 7868 | \f |
c954ff02 | 7869 | struct mdswitchstr |
7870 | { | |
7871 | const char *str; | |
7872 | int len; | |
7873 | }; | |
7874 | ||
7875 | static struct mdswitchstr *mdswitches; | |
7876 | static int n_mdswitches; | |
7877 | ||
3d97d965 | 7878 | /* Check whether a particular argument was used. The first time we |
ad87de1e | 7879 | canonicalize the switches to keep only the ones we care about. */ |
9577d478 | 7880 | |
7881 | static int | |
952f0048 | 7882 | used_arg (const char *p, int len) |
9577d478 | 7883 | { |
d4ea3b1f | 7884 | struct mswitchstr |
7885 | { | |
e772a198 | 7886 | const char *str; |
7887 | const char *replace; | |
3d97d965 | 7888 | int len; |
7889 | int rep_len; | |
7890 | }; | |
7891 | ||
7892 | static struct mswitchstr *mswitches; | |
7893 | static int n_mswitches; | |
7894 | int i, j; | |
7895 | ||
7896 | if (!mswitches) | |
7897 | { | |
7898 | struct mswitchstr *matches; | |
e772a198 | 7899 | const char *q; |
d0fdc842 | 7900 | int cnt = 0; |
3d97d965 | 7901 | |
026f2c7a | 7902 | /* Break multilib_matches into the component strings of string |
7903 | and replacement string. */ | |
c4fa40de | 7904 | for (q = multilib_matches; *q != '\0'; q++) |
7905 | if (*q == ';') | |
3d97d965 | 7906 | cnt++; |
7907 | ||
25a1c410 | 7908 | matches |
7909 | = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt); | |
3d97d965 | 7910 | i = 0; |
7911 | q = multilib_matches; | |
7912 | while (*q != '\0') | |
7913 | { | |
7914 | matches[i].str = q; | |
7915 | while (*q != ' ') | |
7916 | { | |
7917 | if (*q == '\0') | |
5e8f3c31 | 7918 | { |
7919 | invalid_matches: | |
1e5fcbe2 | 7920 | fatal ("multilib spec '%s' is invalid", multilib_matches); |
5e8f3c31 | 7921 | } |
3d97d965 | 7922 | q++; |
7923 | } | |
3d97d965 | 7924 | matches[i].len = q - matches[i].str; |
9577d478 | 7925 | |
3d97d965 | 7926 | matches[i].replace = ++q; |
7927 | while (*q != ';' && *q != '\0') | |
7928 | { | |
7929 | if (*q == ' ') | |
5e8f3c31 | 7930 | goto invalid_matches; |
3d97d965 | 7931 | q++; |
7932 | } | |
7933 | matches[i].rep_len = q - matches[i].replace; | |
7934 | i++; | |
401574b8 | 7935 | if (*q == ';') |
7936 | q++; | |
3d97d965 | 7937 | } |
9577d478 | 7938 | |
0a4dc6a9 | 7939 | /* Now build a list of the replacement string for switches that we care |
7940 | about. Make sure we allocate at least one entry. This prevents | |
7941 | xmalloc from calling fatal, and prevents us from re-executing this | |
7942 | block of code. */ | |
7943 | mswitches | |
4c36ffe6 | 7944 | = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1)); |
3d97d965 | 7945 | for (i = 0; i < n_switches; i++) |
79d52444 | 7946 | if ((switches[i].live_cond & SWITCH_IGNORE) == 0) |
0c76b21e | 7947 | { |
7948 | int xlen = strlen (switches[i].part1); | |
7949 | for (j = 0; j < cnt; j++) | |
7950 | if (xlen == matches[j].len | |
7951 | && ! strncmp (switches[i].part1, matches[j].str, xlen)) | |
7952 | { | |
7953 | mswitches[n_mswitches].str = matches[j].replace; | |
7954 | mswitches[n_mswitches].len = matches[j].rep_len; | |
7955 | mswitches[n_mswitches].replace = (char *) 0; | |
7956 | mswitches[n_mswitches].rep_len = 0; | |
7957 | n_mswitches++; | |
7958 | break; | |
7959 | } | |
7960 | } | |
c954ff02 | 7961 | |
7962 | /* Add MULTILIB_DEFAULTS switches too, as long as they were not present | |
7963 | on the command line nor any options mutually incompatible with | |
7964 | them. */ | |
7965 | for (i = 0; i < n_mdswitches; i++) | |
7966 | { | |
7967 | const char *r; | |
7968 | ||
7969 | for (q = multilib_options; *q != '\0'; q++) | |
7970 | { | |
7971 | while (*q == ' ') | |
7972 | q++; | |
7973 | ||
7974 | r = q; | |
7975 | while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0 | |
7976 | || strchr (" /", q[mdswitches[i].len]) == NULL) | |
7977 | { | |
7978 | while (*q != ' ' && *q != '/' && *q != '\0') | |
7979 | q++; | |
7980 | if (*q != '/') | |
7981 | break; | |
7982 | q++; | |
7983 | } | |
7984 | ||
7985 | if (*q != ' ' && *q != '\0') | |
7986 | { | |
7987 | while (*r != ' ' && *r != '\0') | |
7988 | { | |
7989 | q = r; | |
7990 | while (*q != ' ' && *q != '/' && *q != '\0') | |
7991 | q++; | |
7992 | ||
7993 | if (used_arg (r, q - r)) | |
7994 | break; | |
7995 | ||
7996 | if (*q != '/') | |
7997 | { | |
7998 | mswitches[n_mswitches].str = mdswitches[i].str; | |
7999 | mswitches[n_mswitches].len = mdswitches[i].len; | |
8000 | mswitches[n_mswitches].replace = (char *) 0; | |
8001 | mswitches[n_mswitches].rep_len = 0; | |
8002 | n_mswitches++; | |
8003 | break; | |
8004 | } | |
8005 | ||
8006 | r = q + 1; | |
8007 | } | |
8008 | break; | |
8009 | } | |
8010 | } | |
8011 | } | |
3d97d965 | 8012 | } |
48583106 | 8013 | |
3d97d965 | 8014 | for (i = 0; i < n_mswitches; i++) |
8015 | if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len)) | |
8016 | return 1; | |
48583106 | 8017 | |
3d97d965 | 8018 | return 0; |
8019 | } | |
48583106 | 8020 | |
8021 | static int | |
952f0048 | 8022 | default_arg (const char *p, int len) |
48583106 | 8023 | { |
c954ff02 | 8024 | int i; |
618c6dbb | 8025 | |
c954ff02 | 8026 | for (i = 0; i < n_mdswitches; i++) |
8027 | if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len)) | |
8028 | return 1; | |
48583106 | 8029 | |
8030 | return 0; | |
8031 | } | |
8032 | ||
54518c3b | 8033 | /* Work out the subdirectory to use based on the options. The format of |
8034 | multilib_select is a list of elements. Each element is a subdirectory | |
8035 | name followed by a list of options followed by a semicolon. The format | |
8036 | of multilib_exclusions is the same, but without the preceding | |
8037 | directory. First gcc will check the exclusions, if none of the options | |
8038 | beginning with an exclamation point are present, and all of the other | |
8039 | options are present, then we will ignore this completely. Passing | |
8040 | that, gcc will consider each multilib_select in turn using the same | |
8041 | rules for matching the options. If a match is found, that subdirectory | |
8042 | will be used. */ | |
9577d478 | 8043 | |
8044 | static void | |
952f0048 | 8045 | set_multilib_dir (void) |
9577d478 | 8046 | { |
e772a198 | 8047 | const char *p; |
d4ea3b1f | 8048 | unsigned int this_path_len; |
e772a198 | 8049 | const char *this_path, *this_arg; |
c954ff02 | 8050 | const char *start, *end; |
48583106 | 8051 | int not_arg; |
c954ff02 | 8052 | int ok, ndfltok, first; |
8053 | ||
8054 | n_mdswitches = 0; | |
8055 | start = multilib_defaults; | |
8056 | while (*start == ' ' || *start == '\t') | |
8057 | start++; | |
8058 | while (*start != '\0') | |
8059 | { | |
8060 | n_mdswitches++; | |
8061 | while (*start != ' ' && *start != '\t' && *start != '\0') | |
8062 | start++; | |
8063 | while (*start == ' ' || *start == '\t') | |
8064 | start++; | |
8065 | } | |
8066 | ||
8067 | if (n_mdswitches) | |
8068 | { | |
8069 | int i = 0; | |
8070 | ||
4c36ffe6 | 8071 | mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches); |
c954ff02 | 8072 | for (start = multilib_defaults; *start != '\0'; start = end + 1) |
8073 | { | |
8074 | while (*start == ' ' || *start == '\t') | |
8075 | start++; | |
8076 | ||
8077 | if (*start == '\0') | |
8078 | break; | |
952f0048 | 8079 | |
c954ff02 | 8080 | for (end = start + 1; |
8081 | *end != ' ' && *end != '\t' && *end != '\0'; end++) | |
8082 | ; | |
8083 | ||
8084 | obstack_grow (&multilib_obstack, start, end - start); | |
8085 | obstack_1grow (&multilib_obstack, 0); | |
4fac984f | 8086 | mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *); |
c954ff02 | 8087 | mdswitches[i++].len = end - start; |
8088 | ||
8089 | if (*end == '\0') | |
8090 | break; | |
8091 | } | |
8092 | } | |
9577d478 | 8093 | |
54518c3b | 8094 | p = multilib_exclusions; |
8095 | while (*p != '\0') | |
8096 | { | |
8097 | /* Ignore newlines. */ | |
8098 | if (*p == '\n') | |
026f2c7a | 8099 | { |
8100 | ++p; | |
8101 | continue; | |
8102 | } | |
54518c3b | 8103 | |
8104 | /* Check the arguments. */ | |
8105 | ok = 1; | |
8106 | while (*p != ';') | |
026f2c7a | 8107 | { |
8108 | if (*p == '\0') | |
5e8f3c31 | 8109 | { |
8110 | invalid_exclusions: | |
1e5fcbe2 | 8111 | fatal ("multilib exclusions '%s' is invalid", |
5e8f3c31 | 8112 | multilib_exclusions); |
8113 | } | |
026f2c7a | 8114 | |
8115 | if (! ok) | |
8116 | { | |
8117 | ++p; | |
8118 | continue; | |
8119 | } | |
8120 | ||
8121 | this_arg = p; | |
8122 | while (*p != ' ' && *p != ';') | |
8123 | { | |
8124 | if (*p == '\0') | |
5e8f3c31 | 8125 | goto invalid_exclusions; |
026f2c7a | 8126 | ++p; |
8127 | } | |
8128 | ||
8129 | if (*this_arg != '!') | |
8130 | not_arg = 0; | |
8131 | else | |
8132 | { | |
8133 | not_arg = 1; | |
8134 | ++this_arg; | |
8135 | } | |
2c815aff | 8136 | |
54518c3b | 8137 | ok = used_arg (this_arg, p - this_arg); |
8138 | if (not_arg) | |
8139 | ok = ! ok; | |
8140 | ||
026f2c7a | 8141 | if (*p == ' ') |
8142 | ++p; | |
8143 | } | |
54518c3b | 8144 | |
8145 | if (ok) | |
d4ea3b1f | 8146 | return; |
54518c3b | 8147 | |
8148 | ++p; | |
8149 | } | |
8150 | ||
c954ff02 | 8151 | first = 1; |
54518c3b | 8152 | p = multilib_select; |
9577d478 | 8153 | while (*p != '\0') |
8154 | { | |
8155 | /* Ignore newlines. */ | |
8156 | if (*p == '\n') | |
8157 | { | |
8158 | ++p; | |
8159 | continue; | |
8160 | } | |
8161 | ||
8162 | /* Get the initial path. */ | |
8163 | this_path = p; | |
8164 | while (*p != ' ') | |
8165 | { | |
8166 | if (*p == '\0') | |
5e8f3c31 | 8167 | { |
8168 | invalid_select: | |
1e5fcbe2 | 8169 | fatal ("multilib select '%s' is invalid", |
5e8f3c31 | 8170 | multilib_select); |
8171 | } | |
9577d478 | 8172 | ++p; |
8173 | } | |
8174 | this_path_len = p - this_path; | |
8175 | ||
8176 | /* Check the arguments. */ | |
48583106 | 8177 | ok = 1; |
c954ff02 | 8178 | ndfltok = 1; |
9577d478 | 8179 | ++p; |
8180 | while (*p != ';') | |
8181 | { | |
8182 | if (*p == '\0') | |
5e8f3c31 | 8183 | goto invalid_select; |
9577d478 | 8184 | |
48583106 | 8185 | if (! ok) |
9577d478 | 8186 | { |
8187 | ++p; | |
8188 | continue; | |
8189 | } | |
8190 | ||
8191 | this_arg = p; | |
8192 | while (*p != ' ' && *p != ';') | |
8193 | { | |
8194 | if (*p == '\0') | |
5e8f3c31 | 8195 | goto invalid_select; |
9577d478 | 8196 | ++p; |
8197 | } | |
8198 | ||
48583106 | 8199 | if (*this_arg != '!') |
8200 | not_arg = 0; | |
9577d478 | 8201 | else |
48583106 | 8202 | { |
8203 | not_arg = 1; | |
8204 | ++this_arg; | |
8205 | } | |
8206 | ||
8207 | /* If this is a default argument, we can just ignore it. | |
8208 | This is true even if this_arg begins with '!'. Beginning | |
8209 | with '!' does not mean that this argument is necessarily | |
8210 | inappropriate for this library: it merely means that | |
8211 | there is a more specific library which uses this | |
8212 | argument. If this argument is a default, we need not | |
8213 | consider that more specific library. */ | |
c954ff02 | 8214 | ok = used_arg (this_arg, p - this_arg); |
8215 | if (not_arg) | |
8216 | ok = ! ok; | |
8217 | ||
8218 | if (! ok) | |
8219 | ndfltok = 0; | |
8220 | ||
8221 | if (default_arg (this_arg, p - this_arg)) | |
8222 | ok = 1; | |
9577d478 | 8223 | |
8224 | if (*p == ' ') | |
8225 | ++p; | |
8226 | } | |
8227 | ||
c954ff02 | 8228 | if (ok && first) |
9577d478 | 8229 | { |
8230 | if (this_path_len != 1 | |
8231 | || this_path[0] != '.') | |
8232 | { | |
4c36ffe6 | 8233 | char *new_multilib_dir = XNEWVEC (char, this_path_len + 1); |
c954ff02 | 8234 | char *q; |
8235 | ||
e40d43cc | 8236 | strncpy (new_multilib_dir, this_path, this_path_len); |
8237 | new_multilib_dir[this_path_len] = '\0'; | |
c954ff02 | 8238 | q = strchr (new_multilib_dir, ':'); |
8239 | if (q != NULL) | |
8240 | *q = '\0'; | |
e40d43cc | 8241 | multilib_dir = new_multilib_dir; |
9577d478 | 8242 | } |
c954ff02 | 8243 | first = 0; |
8244 | } | |
8245 | ||
8246 | if (ndfltok) | |
8247 | { | |
8248 | const char *q = this_path, *end = this_path + this_path_len; | |
8249 | ||
8250 | while (q < end && *q != ':') | |
8251 | q++; | |
a2770a85 | 8252 | if (q < end) |
c954ff02 | 8253 | { |
4c36ffe6 | 8254 | char *new_multilib_os_dir = XNEWVEC (char, end - q); |
a2770a85 | 8255 | memcpy (new_multilib_os_dir, q + 1, end - q - 1); |
8256 | new_multilib_os_dir[end - q - 1] = '\0'; | |
c954ff02 | 8257 | multilib_os_dir = new_multilib_os_dir; |
8258 | break; | |
8259 | } | |
9577d478 | 8260 | } |
8261 | ||
8262 | ++p; | |
2c815aff | 8263 | } |
c954ff02 | 8264 | |
8265 | if (multilib_dir == NULL && multilib_os_dir != NULL | |
8266 | && strcmp (multilib_os_dir, ".") == 0) | |
8267 | { | |
e47a6f81 | 8268 | free (CONST_CAST (char *, multilib_os_dir)); |
c954ff02 | 8269 | multilib_os_dir = NULL; |
8270 | } | |
8271 | else if (multilib_dir != NULL && multilib_os_dir == NULL) | |
8272 | multilib_os_dir = multilib_dir; | |
9577d478 | 8273 | } |
8274 | ||
8275 | /* Print out the multiple library subdirectory selection | |
8276 | information. This prints out a series of lines. Each line looks | |
8277 | like SUBDIRECTORY;@OPTION@OPTION, with as many options as is | |
8278 | required. Only the desired options are printed out, the negative | |
8279 | matches. The options are print without a leading dash. There are | |
8280 | no spaces to make it easy to use the information in the shell. | |
8281 | Each subdirectory is printed only once. This assumes the ordering | |
54518c3b | 8282 | generated by the genmultilib script. Also, we leave out ones that match |
8283 | the exclusions. */ | |
9577d478 | 8284 | |
8285 | static void | |
952f0048 | 8286 | print_multilib_info (void) |
9577d478 | 8287 | { |
e772a198 | 8288 | const char *p = multilib_select; |
8289 | const char *last_path = 0, *this_path; | |
48583106 | 8290 | int skip; |
d4ea3b1f | 8291 | unsigned int last_path_len = 0; |
9577d478 | 8292 | |
8293 | while (*p != '\0') | |
8294 | { | |
54518c3b | 8295 | skip = 0; |
9577d478 | 8296 | /* Ignore newlines. */ |
8297 | if (*p == '\n') | |
8298 | { | |
8299 | ++p; | |
8300 | continue; | |
8301 | } | |
8302 | ||
8303 | /* Get the initial path. */ | |
8304 | this_path = p; | |
8305 | while (*p != ' ') | |
8306 | { | |
8307 | if (*p == '\0') | |
5e8f3c31 | 8308 | { |
8309 | invalid_select: | |
1e5fcbe2 | 8310 | fatal ("multilib select '%s' is invalid", multilib_select); |
5e8f3c31 | 8311 | } |
2f2c6aee | 8312 | |
9577d478 | 8313 | ++p; |
8314 | } | |
8315 | ||
a2770a85 | 8316 | /* When --disable-multilib was used but target defines |
8317 | MULTILIB_OSDIRNAMES, entries starting with .: are there just | |
8318 | to find multilib_os_dir, so skip them from output. */ | |
8319 | if (this_path[0] == '.' && this_path[1] == ':') | |
8320 | skip = 1; | |
8321 | ||
54518c3b | 8322 | /* Check for matches with the multilib_exclusions. We don't bother |
8323 | with the '!' in either list. If any of the exclusion rules match | |
8324 | all of its options with the select rule, we skip it. */ | |
026f2c7a | 8325 | { |
8326 | const char *e = multilib_exclusions; | |
8327 | const char *this_arg; | |
54518c3b | 8328 | |
026f2c7a | 8329 | while (*e != '\0') |
8330 | { | |
8331 | int m = 1; | |
8332 | /* Ignore newlines. */ | |
8333 | if (*e == '\n') | |
8334 | { | |
8335 | ++e; | |
8336 | continue; | |
8337 | } | |
54518c3b | 8338 | |
026f2c7a | 8339 | /* Check the arguments. */ |
8340 | while (*e != ';') | |
8341 | { | |
8342 | const char *q; | |
8343 | int mp = 0; | |
54518c3b | 8344 | |
026f2c7a | 8345 | if (*e == '\0') |
5e8f3c31 | 8346 | { |
8347 | invalid_exclusion: | |
1e5fcbe2 | 8348 | fatal ("multilib exclusion '%s' is invalid", |
5e8f3c31 | 8349 | multilib_exclusions); |
8350 | } | |
2c815aff | 8351 | |
026f2c7a | 8352 | if (! m) |
8353 | { | |
8354 | ++e; | |
8355 | continue; | |
8356 | } | |
54518c3b | 8357 | |
026f2c7a | 8358 | this_arg = e; |
2c815aff | 8359 | |
026f2c7a | 8360 | while (*e != ' ' && *e != ';') |
8361 | { | |
8362 | if (*e == '\0') | |
5e8f3c31 | 8363 | goto invalid_exclusion; |
026f2c7a | 8364 | ++e; |
8365 | } | |
54518c3b | 8366 | |
026f2c7a | 8367 | q = p + 1; |
8368 | while (*q != ';') | |
8369 | { | |
8370 | const char *arg; | |
8371 | int len = e - this_arg; | |
54518c3b | 8372 | |
026f2c7a | 8373 | if (*q == '\0') |
5e8f3c31 | 8374 | goto invalid_select; |
54518c3b | 8375 | |
026f2c7a | 8376 | arg = q; |
8377 | ||
8378 | while (*q != ' ' && *q != ';') | |
8379 | { | |
8380 | if (*q == '\0') | |
5e8f3c31 | 8381 | goto invalid_select; |
54518c3b | 8382 | ++q; |
026f2c7a | 8383 | } |
54518c3b | 8384 | |
5e8f3c31 | 8385 | if (! strncmp (arg, this_arg, |
8386 | (len < q - arg) ? q - arg : len) | |
8387 | || default_arg (this_arg, e - this_arg)) | |
026f2c7a | 8388 | { |
8389 | mp = 1; | |
8390 | break; | |
8391 | } | |
54518c3b | 8392 | |
026f2c7a | 8393 | if (*q == ' ') |
8394 | ++q; | |
8395 | } | |
2c815aff | 8396 | |
026f2c7a | 8397 | if (! mp) |
8398 | m = 0; | |
54518c3b | 8399 | |
026f2c7a | 8400 | if (*e == ' ') |
8401 | ++e; | |
8402 | } | |
8403 | ||
8404 | if (m) | |
8405 | { | |
8406 | skip = 1; | |
8407 | break; | |
8408 | } | |
8409 | ||
8410 | if (*e != '\0') | |
8411 | ++e; | |
8412 | } | |
8413 | } | |
54518c3b | 8414 | |
8415 | if (! skip) | |
026f2c7a | 8416 | { |
8417 | /* If this is a duplicate, skip it. */ | |
5e8f3c31 | 8418 | skip = (last_path != 0 |
8419 | && (unsigned int) (p - this_path) == last_path_len | |
026f2c7a | 8420 | && ! strncmp (last_path, this_path, last_path_len)); |
9577d478 | 8421 | |
026f2c7a | 8422 | last_path = this_path; |
8423 | last_path_len = p - this_path; | |
54518c3b | 8424 | } |
9577d478 | 8425 | |
48583106 | 8426 | /* If this directory requires any default arguments, we can skip |
8427 | it. We will already have printed a directory identical to | |
8428 | this one which does not require that default argument. */ | |
8429 | if (! skip) | |
8430 | { | |
e772a198 | 8431 | const char *q; |
48583106 | 8432 | |
8433 | q = p + 1; | |
8434 | while (*q != ';') | |
8435 | { | |
e772a198 | 8436 | const char *arg; |
48583106 | 8437 | |
8438 | if (*q == '\0') | |
5e8f3c31 | 8439 | goto invalid_select; |
48583106 | 8440 | |
8441 | if (*q == '!') | |
8442 | arg = NULL; | |
8443 | else | |
8444 | arg = q; | |
8445 | ||
8446 | while (*q != ' ' && *q != ';') | |
8447 | { | |
8448 | if (*q == '\0') | |
5e8f3c31 | 8449 | goto invalid_select; |
48583106 | 8450 | ++q; |
8451 | } | |
8452 | ||
8453 | if (arg != NULL | |
8454 | && default_arg (arg, q - arg)) | |
8455 | { | |
8456 | skip = 1; | |
8457 | break; | |
8458 | } | |
8459 | ||
8460 | if (*q == ' ') | |
8461 | ++q; | |
8462 | } | |
8463 | } | |
8464 | ||
9577d478 | 8465 | if (! skip) |
8466 | { | |
e772a198 | 8467 | const char *p1; |
9577d478 | 8468 | |
c954ff02 | 8469 | for (p1 = last_path; p1 < p && *p1 != ':'; p1++) |
9577d478 | 8470 | putchar (*p1); |
8471 | putchar (';'); | |
8472 | } | |
8473 | ||
8474 | ++p; | |
8475 | while (*p != ';') | |
8476 | { | |
8477 | int use_arg; | |
8478 | ||
8479 | if (*p == '\0') | |
5e8f3c31 | 8480 | goto invalid_select; |
9577d478 | 8481 | |
8482 | if (skip) | |
8483 | { | |
8484 | ++p; | |
8485 | continue; | |
8486 | } | |
8487 | ||
8488 | use_arg = *p != '!'; | |
8489 | ||
8490 | if (use_arg) | |
8491 | putchar ('@'); | |
8492 | ||
8493 | while (*p != ' ' && *p != ';') | |
8494 | { | |
8495 | if (*p == '\0') | |
5e8f3c31 | 8496 | goto invalid_select; |
9577d478 | 8497 | if (use_arg) |
8498 | putchar (*p); | |
8499 | ++p; | |
8500 | } | |
8501 | ||
8502 | if (*p == ' ') | |
8503 | ++p; | |
8504 | } | |
8505 | ||
8506 | if (! skip) | |
3d97d965 | 8507 | { |
d4ea3b1f | 8508 | /* If there are extra options, print them now. */ |
3d97d965 | 8509 | if (multilib_extra && *multilib_extra) |
8510 | { | |
8511 | int print_at = TRUE; | |
e772a198 | 8512 | const char *q; |
3d97d965 | 8513 | |
8514 | for (q = multilib_extra; *q != '\0'; q++) | |
8515 | { | |
8516 | if (*q == ' ') | |
8517 | print_at = TRUE; | |
8518 | else | |
8519 | { | |
8520 | if (print_at) | |
8521 | putchar ('@'); | |
8522 | putchar (*q); | |
8523 | print_at = FALSE; | |
8524 | } | |
8525 | } | |
8526 | } | |
2c815aff | 8527 | |
3d97d965 | 8528 | putchar ('\n'); |
8529 | } | |
9577d478 | 8530 | |
8531 | ++p; | |
8532 | } | |
8533 | } | |
c21b3276 | 8534 | \f |
0305c755 | 8535 | /* getenv built-in spec function. |
8536 | ||
8537 | Returns the value of the environment variable given by its first | |
8538 | argument, concatenated with the second argument. If the | |
8539 | environment variable is not defined, a fatal error is issued. */ | |
8540 | ||
8541 | static const char * | |
8542 | getenv_spec_function (int argc, const char **argv) | |
8543 | { | |
8544 | char *value; | |
4b20bbaf | 8545 | char *result; |
8546 | char *ptr; | |
8547 | size_t len; | |
0305c755 | 8548 | |
8549 | if (argc != 2) | |
8550 | return NULL; | |
8551 | ||
8552 | value = getenv (argv[0]); | |
8553 | if (!value) | |
8554 | fatal ("environment variable \"%s\" not defined", argv[0]); | |
8555 | ||
4b20bbaf | 8556 | /* We have to escape every character of the environment variable so |
f0b5f617 | 8557 | they are not interpreted as active spec characters. A |
8558 | particularly painful case is when we are reading a variable | |
4b20bbaf | 8559 | holding a windows path complete with \ separators. */ |
8560 | len = strlen (value) * 2 + strlen (argv[1]) + 1; | |
25a1c410 | 8561 | result = XNEWVAR (char, len); |
4b20bbaf | 8562 | for (ptr = result; *value; ptr += 2) |
8563 | { | |
8564 | ptr[0] = '\\'; | |
8565 | ptr[1] = *value++; | |
8566 | } | |
48e1416a | 8567 | |
4b20bbaf | 8568 | strcpy (ptr, argv[1]); |
48e1416a | 8569 | |
4b20bbaf | 8570 | return result; |
0305c755 | 8571 | } |
8572 | ||
c21b3276 | 8573 | /* if-exists built-in spec function. |
8574 | ||
8575 | Checks to see if the file specified by the absolute pathname in | |
8576 | ARGS exists. Returns that pathname if found. | |
8577 | ||
8578 | The usual use for this function is to check for a library file | |
8579 | (whose name has been expanded with %s). */ | |
8580 | ||
8581 | static const char * | |
952f0048 | 8582 | if_exists_spec_function (int argc, const char **argv) |
c21b3276 | 8583 | { |
8584 | /* Must have only one argument. */ | |
a5c088d4 | 8585 | if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK)) |
c21b3276 | 8586 | return argv[0]; |
8587 | ||
8588 | return NULL; | |
8589 | } | |
68d74c02 | 8590 | |
8591 | /* if-exists-else built-in spec function. | |
8592 | ||
8593 | This is like if-exists, but takes an additional argument which | |
8594 | is returned if the first argument does not exist. */ | |
8595 | ||
8596 | static const char * | |
952f0048 | 8597 | if_exists_else_spec_function (int argc, const char **argv) |
68d74c02 | 8598 | { |
8599 | /* Must have exactly two arguments. */ | |
8600 | if (argc != 2) | |
8601 | return NULL; | |
8602 | ||
a5c088d4 | 8603 | if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK)) |
68d74c02 | 8604 | return argv[0]; |
8605 | ||
8606 | return argv[1]; | |
8607 | } | |
2288041e | 8608 | |
8609 | /* replace-outfile built-in spec function. | |
9b1f316f | 8610 | |
8611 | This looks for the first argument in the outfiles array's name and | |
8612 | replaces it with the second argument. */ | |
2288041e | 8613 | |
8614 | static const char * | |
8615 | replace_outfile_spec_function (int argc, const char **argv) | |
8616 | { | |
8617 | int i; | |
8618 | /* Must have exactly two arguments. */ | |
8619 | if (argc != 2) | |
8620 | abort (); | |
2f2c6aee | 8621 | |
2288041e | 8622 | for (i = 0; i < n_infiles; i++) |
8623 | { | |
8624 | if (outfiles[i] && !strcmp (outfiles[i], argv[0])) | |
8625 | outfiles[i] = xstrdup (argv[1]); | |
8626 | } | |
8627 | return NULL; | |
8628 | } | |
8629 | ||
2f2c6aee | 8630 | /* Given two version numbers, compares the two numbers. |
9b1f316f | 8631 | A version number must match the regular expression |
8632 | ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))* | |
8633 | */ | |
8634 | static int | |
8635 | compare_version_strings (const char *v1, const char *v2) | |
8636 | { | |
8637 | int rresult; | |
8638 | regex_t r; | |
2f2c6aee | 8639 | |
9b1f316f | 8640 | if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$", |
8641 | REG_EXTENDED | REG_NOSUB) != 0) | |
8642 | abort (); | |
8643 | rresult = regexec (&r, v1, 0, NULL, 0); | |
8644 | if (rresult == REG_NOMATCH) | |
8645 | fatal ("invalid version number `%s'", v1); | |
8646 | else if (rresult != 0) | |
8647 | abort (); | |
8648 | rresult = regexec (&r, v2, 0, NULL, 0); | |
8649 | if (rresult == REG_NOMATCH) | |
8650 | fatal ("invalid version number `%s'", v2); | |
8651 | else if (rresult != 0) | |
8652 | abort (); | |
8653 | ||
8654 | return strverscmp (v1, v2); | |
8655 | } | |
8656 | ||
8657 | ||
8658 | /* version_compare built-in spec function. | |
8659 | ||
8660 | This takes an argument of the following form: | |
8661 | ||
8662 | <comparison-op> <arg1> [<arg2>] <switch> <result> | |
8663 | ||
8664 | and produces "result" if the comparison evaluates to true, | |
8665 | and nothing if it doesn't. | |
8666 | ||
8667 | The supported <comparison-op> values are: | |
2f2c6aee | 8668 | |
9b1f316f | 8669 | >= true if switch is a later (or same) version than arg1 |
8670 | !> opposite of >= | |
8671 | < true if switch is an earlier version than arg1 | |
8672 | !< opposite of < | |
8673 | >< true if switch is arg1 or later, and earlier than arg2 | |
8674 | <> true if switch is earlier than arg1 or is arg2 or later | |
8675 | ||
8676 | If the switch is not present, the condition is false unless | |
8677 | the first character of the <comparison-op> is '!'. | |
8678 | ||
8679 | For example, | |
8680 | %:version-compare(>= 10.3 mmacosx-version-min= -lmx) | |
8681 | adds -lmx if -mmacosx-version-min=10.3.9 was passed. */ | |
8682 | ||
8683 | static const char * | |
8684 | version_compare_spec_function (int argc, const char **argv) | |
8685 | { | |
8686 | int comp1, comp2; | |
8687 | size_t switch_len; | |
8688 | const char *switch_value = NULL; | |
8689 | int nargs = 1, i; | |
8690 | bool result; | |
8691 | ||
8692 | if (argc < 3) | |
bbdc1b6b | 8693 | fatal ("too few arguments to %%:version-compare"); |
9b1f316f | 8694 | if (argv[0][0] == '\0') |
8695 | abort (); | |
8696 | if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!') | |
8697 | nargs = 2; | |
8698 | if (argc != nargs + 3) | |
bbdc1b6b | 8699 | fatal ("too many arguments to %%:version-compare"); |
9b1f316f | 8700 | |
8701 | switch_len = strlen (argv[nargs + 1]); | |
8702 | for (i = 0; i < n_switches; i++) | |
8703 | if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len) | |
8704 | && check_live_switch (i, switch_len)) | |
8705 | switch_value = switches[i].part1 + switch_len; | |
8706 | ||
8707 | if (switch_value == NULL) | |
8708 | comp1 = comp2 = -1; | |
8709 | else | |
8710 | { | |
8711 | comp1 = compare_version_strings (switch_value, argv[1]); | |
8712 | if (nargs == 2) | |
8713 | comp2 = compare_version_strings (switch_value, argv[2]); | |
8714 | else | |
8715 | comp2 = -1; /* This value unused. */ | |
8716 | } | |
8717 | ||
8718 | switch (argv[0][0] << 8 | argv[0][1]) | |
8719 | { | |
8720 | case '>' << 8 | '=': | |
8721 | result = comp1 >= 0; | |
8722 | break; | |
8723 | case '!' << 8 | '<': | |
8724 | result = comp1 >= 0 || switch_value == NULL; | |
8725 | break; | |
8726 | case '<' << 8: | |
8727 | result = comp1 < 0; | |
8728 | break; | |
8729 | case '!' << 8 | '>': | |
8730 | result = comp1 < 0 || switch_value == NULL; | |
8731 | break; | |
8732 | case '>' << 8 | '<': | |
8733 | result = comp1 >= 0 && comp2 < 0; | |
8734 | break; | |
8735 | case '<' << 8 | '>': | |
8736 | result = comp1 < 0 || comp2 >= 0; | |
8737 | break; | |
2f2c6aee | 8738 | |
9b1f316f | 8739 | default: |
23e3cdee | 8740 | fatal ("unknown operator '%s' in %%:version-compare", argv[0]); |
9b1f316f | 8741 | } |
8742 | if (! result) | |
8743 | return NULL; | |
8744 | ||
8745 | return argv[nargs + 2]; | |
8746 | } | |
1e8e9920 | 8747 | |
8748 | /* %:include builtin spec function. This differs from %include in that it | |
8749 | can be nested inside a spec, and thus be conditionalized. It takes | |
8750 | one argument, the filename, and looks for it in the startfile path. | |
8751 | The result is always NULL, i.e. an empty expansion. */ | |
8752 | ||
8753 | static const char * | |
8754 | include_spec_function (int argc, const char **argv) | |
8755 | { | |
8756 | char *file; | |
8757 | ||
8758 | if (argc != 1) | |
8759 | abort (); | |
8760 | ||
f9ebe19f | 8761 | file = find_a_file (&startfile_prefixes, argv[0], R_OK, true); |
1e8e9920 | 8762 | read_specs (file ? file : argv[0], FALSE); |
8763 | ||
8764 | return NULL; | |
8765 | } | |
ceac8e8c | 8766 | |
8767 | /* %:print-asm-header spec function. Print a banner to say that the | |
8768 | following output is from the assembler. */ | |
8769 | ||
8770 | static const char * | |
8771 | print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED, | |
8772 | const char **argv ATTRIBUTE_UNUSED) | |
8773 | { | |
666137bc | 8774 | printf (_("Assembler options\n=================\n\n")); |
ceac8e8c | 8775 | printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n")); |
8776 | fflush (stdout); | |
8777 | return NULL; | |
8778 | } | |
71278019 | 8779 | |
9845d120 | 8780 | /* Compute a timestamp to initialize flag_random_seed. */ |
8781 | ||
8782 | static unsigned | |
8783 | get_local_tick (void) | |
8784 | { | |
8785 | unsigned ret = 0; | |
8786 | ||
8787 | /* Get some more or less random data. */ | |
8788 | #ifdef HAVE_GETTIMEOFDAY | |
8789 | { | |
8790 | struct timeval tv; | |
8791 | ||
8792 | gettimeofday (&tv, NULL); | |
8793 | ret = tv.tv_sec * 1000 + tv.tv_usec / 1000; | |
8794 | } | |
8795 | #else | |
8796 | { | |
8797 | time_t now = time (NULL); | |
8798 | ||
8799 | if (now != (time_t)-1) | |
8800 | ret = (unsigned) now; | |
8801 | } | |
8802 | #endif | |
8803 | ||
8804 | return ret; | |
8805 | } | |
8806 | ||
71278019 | 8807 | /* %:compare-debug-dump-opt spec function. Save the last argument, |
8808 | expected to be the last -fdump-final-insns option, or generate a | |
8809 | temporary. */ | |
8810 | ||
8811 | static const char * | |
8812 | compare_debug_dump_opt_spec_function (int arg, | |
8813 | const char **argv ATTRIBUTE_UNUSED) | |
8814 | { | |
8815 | const char *ret; | |
8816 | char *name; | |
8817 | int which; | |
9845d120 | 8818 | static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; |
71278019 | 8819 | |
8820 | if (arg != 0) | |
8821 | fatal ("too many arguments to %%:compare-debug-dump-opt"); | |
8822 | ||
71278019 | 8823 | do_spec_2 ("%{fdump-final-insns=*:%*}"); |
8824 | do_spec_1 (" ", 0, NULL); | |
8825 | ||
9845d120 | 8826 | if (argbuf_index > 0 && strcmp (argv[argbuf_index - 1], ".")) |
71278019 | 8827 | { |
9845d120 | 8828 | if (!compare_debug) |
8829 | return NULL; | |
8830 | ||
71278019 | 8831 | name = xstrdup (argv[argbuf_index - 1]); |
8832 | ret = NULL; | |
8833 | } | |
8834 | else | |
8835 | { | |
9845d120 | 8836 | const char *ext = NULL; |
8837 | ||
8838 | if (argbuf_index > 0) | |
8839 | { | |
8840 | do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}"); | |
8841 | ext = ".gkd"; | |
8842 | } | |
8843 | else if (!compare_debug) | |
8844 | return NULL; | |
8845 | else | |
8846 | do_spec_2 ("%g.gkd"); | |
71278019 | 8847 | |
71278019 | 8848 | do_spec_1 (" ", 0, NULL); |
71278019 | 8849 | |
8850 | gcc_assert (argbuf_index > 0); | |
8851 | ||
9845d120 | 8852 | name = concat (argbuf[argbuf_index - 1], ext, NULL); |
8853 | ||
8854 | ret = concat ("-fdump-final-insns=", name, NULL); | |
71278019 | 8855 | } |
8856 | ||
8857 | which = compare_debug < 0; | |
8858 | debug_check_temp_file[which] = name; | |
8859 | ||
9845d120 | 8860 | if (!which) |
8861 | { | |
8862 | unsigned HOST_WIDE_INT value = get_local_tick () ^ getpid (); | |
8863 | ||
8864 | sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); | |
8865 | } | |
8866 | ||
8867 | if (*random_seed) | |
8868 | ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ", | |
8869 | ret, NULL); | |
8870 | ||
8871 | if (which) | |
8872 | *random_seed = 0; | |
71278019 | 8873 | |
8874 | return ret; | |
8875 | } | |
8876 | ||
8877 | static const char *debug_auxbase_opt; | |
8878 | ||
8879 | /* %:compare-debug-self-opt spec function. Expands to the options | |
8880 | that are to be passed in the second compilation of | |
8881 | compare-debug. */ | |
8882 | ||
8883 | static const char * | |
8884 | compare_debug_self_opt_spec_function (int arg, | |
8885 | const char **argv ATTRIBUTE_UNUSED) | |
8886 | { | |
8887 | if (arg != 0) | |
8888 | fatal ("too many arguments to %%:compare-debug-self-opt"); | |
8889 | ||
8890 | if (compare_debug >= 0) | |
8891 | return NULL; | |
8892 | ||
8893 | do_spec_2 ("%{c|S:%{o*:%*}}"); | |
8894 | do_spec_1 (" ", 0, NULL); | |
8895 | ||
8896 | if (argbuf_index > 0) | |
8897 | debug_auxbase_opt = concat ("-auxbase-strip ", | |
8898 | argbuf[argbuf_index - 1], | |
8899 | NULL); | |
8900 | else | |
8901 | debug_auxbase_opt = NULL; | |
8902 | ||
8903 | return concat ("\ | |
8904 | %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \ | |
8905 | %<fdump-final-insns=* -w -S -o %j \ | |
8906 | %{!fcompare-debug-second:-fcompare-debug-second} \ | |
8907 | ", compare_debug_opt, NULL); | |
8908 | } | |
8909 | ||
8910 | /* %:compare-debug-auxbase-opt spec function. Expands to the auxbase | |
8911 | options that are to be passed in the second compilation of | |
8912 | compare-debug. It expects, as an argument, the basename of the | |
8913 | current input file name, with the .gk suffix appended to it. */ | |
8914 | ||
8915 | static const char * | |
8916 | compare_debug_auxbase_opt_spec_function (int arg, | |
8917 | const char **argv) | |
8918 | { | |
8919 | char *name; | |
8920 | int len; | |
8921 | ||
8922 | if (arg == 0) | |
8923 | fatal ("too few arguments to %%:compare-debug-auxbase-opt"); | |
8924 | ||
8925 | if (arg != 1) | |
8926 | fatal ("too many arguments to %%:compare-debug-auxbase-opt"); | |
8927 | ||
8928 | if (compare_debug >= 0) | |
8929 | return NULL; | |
8930 | ||
8931 | len = strlen (argv[0]); | |
8932 | if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0) | |
8933 | fatal ("argument to %%:compare-debug-auxbase-opt does not end in .gk"); | |
8934 | ||
8935 | if (debug_auxbase_opt) | |
8936 | return debug_auxbase_opt; | |
8937 | ||
8938 | #define OPT "-auxbase " | |
8939 | ||
8940 | len -= 3; | |
8941 | name = (char*) xmalloc (sizeof (OPT) + len); | |
8942 | memcpy (name, OPT, sizeof (OPT) - 1); | |
8943 | memcpy (name + sizeof (OPT) - 1, argv[0], len); | |
8944 | name[sizeof (OPT) - 1 + len] = '\0'; | |
8945 | ||
9845d120 | 8946 | #undef OPT |
8947 | ||
71278019 | 8948 | return name; |
8949 | } |