1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
31 #include "langhooks.h"
32 #include "tree-inline.h"
33 #include "diagnostic.h"
35 #include "cppdefault.h"
36 #include "c-incpath.h"
37 #include "debug.h" /* For debug_hooks. */
39 #ifndef DOLLARS_IN_IDENTIFIERS
40 # define DOLLARS_IN_IDENTIFIERS true
43 #ifndef TARGET_SYSTEM_ROOT
44 # define TARGET_SYSTEM_ROOT NULL
48 # define TARGET_EBCDIC 0
51 static int saved_lineno;
54 static cpp_options *cpp_opts;
57 static const char *in_fname;
59 /* Filename and stream for preprocessed output. */
60 static const char *out_fname;
61 static FILE *out_stream;
63 /* Append dependencies to deps_file. */
64 static bool deps_append;
66 /* If dependency switches (-MF etc.) have been given. */
67 static bool deps_seen;
72 /* Dependency output file. */
73 static const char *deps_file;
75 /* The prefix given by -iprefix, if any. */
76 static const char *iprefix;
78 /* The system root, if any. Overridden by -isysroot. */
79 static const char *sysroot = TARGET_SYSTEM_ROOT;
81 /* Zero disables all standard directories for headers. */
82 static bool std_inc = true;
84 /* Zero disables the C++-specific standard directories for headers. */
85 static bool std_cxx_inc = true;
87 /* If the quote chain has been split by -I-. */
88 static bool quote_chain_split;
90 /* If -Wunused-macros. */
91 static bool warn_unused_macros;
93 /* Number of deferred options, deferred options array size. */
94 static size_t deferred_count, deferred_size;
96 /* Number of deferred options scanned for -include. */
97 static size_t include_cursor;
99 static void missing_arg PARAMS ((size_t));
100 static size_t find_opt PARAMS ((const char *, int));
101 static void set_Wimplicit PARAMS ((int));
102 static void complain_wrong_lang PARAMS ((size_t));
103 static void write_langs PARAMS ((char *, int));
104 static void print_help PARAMS ((void));
105 static void handle_OPT_d PARAMS ((const char *));
106 static void set_std_cxx98 PARAMS ((int));
107 static void set_std_c89 PARAMS ((int, int));
108 static void set_std_c99 PARAMS ((int));
109 static void check_deps_environment_vars PARAMS ((void));
110 static void handle_deferred_opts PARAMS ((void));
111 static void sanitize_cpp_opts PARAMS ((void));
112 static void add_prefixed_path PARAMS ((const char *, size_t));
113 static void push_command_line_include PARAMS ((void));
114 static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
115 static void finish_options PARAMS ((void));
117 #ifndef STDC_0_IN_SYSTEM_HEADERS
118 #define STDC_0_IN_SYSTEM_HEADERS 0
121 #define CL_C_ONLY (1 << 0) /* Only C. */
122 #define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
123 #define CL_CXX_ONLY (1 << 2) /* Only C++. */
124 #define CL_OBJCXX_ONLY (1 << 3) /* Only ObjC++. */
125 #define CL_JOINED (1 << 4) /* If takes joined argument. */
126 #define CL_SEPARATE (1 << 5) /* If takes a separate argument. */
128 #define CL_ARG (CL_JOINED | CL_SEPARATE)
129 #define CL_C (CL_C_ONLY | CL_OBJC_ONLY)
130 #define CL_OBJC (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
131 #define CL_CXX (CL_CXX_ONLY | CL_OBJCXX_ONLY)
132 #define CL_ALL (CL_C | CL_CXX)
134 /* This is the list of all command line options, with the leading "-"
135 removed. It must be sorted in ASCII collating order. All options
136 beginning with "f" or "W" are implicitly assumed to take a "no-"
137 form; this form should not be listed. The variable "on" is true if
138 the positive form is given, otherwise it is false. If you don't
139 want to allow a "no-" form, your handler should reject "on" being
140 false by returning zero. See, for example, the handling of
143 If the user gives an option to a front end that doesn't support it,
144 an error is output, mentioning which front ends the option is valid
145 for. If you don't want this, you must accept it for all front
146 ends, and test for the front end in the option handler. See, for
147 example, the handling of -Wno-strict-prototypes for C++.
149 If you request an argument with CL_JOINED, CL_SEPARATE or their
150 combination CL_ARG, it is stored in the variable "arg", which is
151 guaranteed to be non-NULL and to not be an empty string. It points
152 to the argument either within the argv[] vector or within one of
153 that vector's strings, and so the text is permanent and copies need
154 not be made. Be sure to add an error message in missing_arg() if
155 the default is not appropriate. */
157 #define COMMAND_LINE_OPTIONS \
158 OPT("-help", CL_ALL, OPT__help) \
159 OPT("-output-pch=", CL_ALL | CL_ARG, OPT__output_pch) \
160 OPT("A", CL_ALL | CL_ARG, OPT_A) \
161 OPT("C", CL_ALL, OPT_C) \
162 OPT("CC", CL_ALL, OPT_CC) \
163 OPT("D", CL_ALL | CL_ARG, OPT_D) \
164 OPT("E", CL_ALL, OPT_E) \
165 OPT("H", CL_ALL, OPT_H) \
166 OPT("I", CL_ALL | CL_ARG, OPT_I) \
167 OPT("M", CL_ALL, OPT_M) \
168 OPT("MD", CL_ALL | CL_SEPARATE, OPT_MD) \
169 OPT("MF", CL_ALL | CL_ARG, OPT_MF) \
170 OPT("MG", CL_ALL, OPT_MG) \
171 OPT("MM", CL_ALL, OPT_MM) \
172 OPT("MMD", CL_ALL | CL_SEPARATE, OPT_MMD) \
173 OPT("MP", CL_ALL, OPT_MP) \
174 OPT("MQ", CL_ALL | CL_ARG, OPT_MQ) \
175 OPT("MT", CL_ALL | CL_ARG, OPT_MT) \
176 OPT("P", CL_ALL, OPT_P) \
177 OPT("U", CL_ALL | CL_ARG, OPT_U) \
178 OPT("Wabi", CL_CXX, OPT_Wabi) \
179 OPT("Wall", CL_ALL, OPT_Wall) \
180 OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
181 OPT("Wcast-qual", CL_ALL, OPT_Wcast_qual) \
182 OPT("Wchar-subscripts", CL_ALL, OPT_Wchar_subscripts) \
183 OPT("Wcomment", CL_ALL, OPT_Wcomment) \
184 OPT("Wcomments", CL_ALL, OPT_Wcomments) \
185 OPT("Wconversion", CL_ALL, OPT_Wconversion) \
186 OPT("Wctor-dtor-privacy", CL_CXX, OPT_Wctor_dtor_privacy) \
187 OPT("Wdeprecated", CL_CXX, OPT_Wdeprecated) \
188 OPT("Wdiv-by-zero", CL_C, OPT_Wdiv_by_zero) \
189 OPT("Weffc++", CL_CXX, OPT_Weffcxx) \
190 OPT("Wendif-labels", CL_ALL, OPT_Wendif_labels) \
191 OPT("Werror", CL_ALL, OPT_Werror) \
192 OPT("Werror-implicit-function-declaration", \
193 CL_C, OPT_Werror_implicit_function_decl) \
194 OPT("Wfloat-equal", CL_ALL, OPT_Wfloat_equal) \
195 OPT("Wformat", CL_ALL, OPT_Wformat) \
196 OPT("Wformat-extra-args", CL_ALL, OPT_Wformat_extra_args) \
197 OPT("Wformat-nonliteral", CL_ALL, OPT_Wformat_nonliteral) \
198 OPT("Wformat-security", CL_ALL, OPT_Wformat_security) \
199 OPT("Wformat-y2k", CL_ALL, OPT_Wformat_y2k) \
200 OPT("Wformat-zero-length", CL_C, OPT_Wformat_zero_length) \
201 OPT("Wformat=", CL_ALL | CL_JOINED, OPT_Wformat_eq) \
202 OPT("Wimplicit", CL_ALL, OPT_Wimplicit) \
203 OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
204 OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
205 OPT("Wimport", CL_ALL, OPT_Wimport) \
206 OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
207 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
208 OPT("Wmain", CL_C, OPT_Wmain) \
209 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
210 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
211 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
212 OPT("Wmissing-prototypes", CL_C, OPT_Wmissing_prototypes) \
213 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
214 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
215 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
216 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
217 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
218 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
219 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
220 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
221 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
222 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
223 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
224 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
225 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
226 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
227 OPT("Wselector", CL_OBJC, OPT_Wselector) \
228 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
229 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
230 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
231 OPT("Wstrict-prototypes", CL_C, OPT_Wstrict_prototypes) \
232 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
233 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
234 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
235 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
236 OPT("Wundeclared-selector", CL_OBJC, OPT_Wundeclared_selector) \
237 OPT("Wundef", CL_ALL, OPT_Wundef) \
238 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
239 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
240 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
241 OPT("ansi", CL_ALL, OPT_ansi) \
242 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
243 OPT("fabi-version=", CL_CXX | CL_JOINED, OPT_fabi_version) \
244 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
245 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
246 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
247 OPT("fasm", CL_ALL, OPT_fasm) \
248 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
249 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
250 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
251 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
252 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
253 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
254 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
255 OPT_fconstant_string_class) \
256 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
257 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
258 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
259 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
260 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
261 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
262 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
263 OPT("ffixed-form", CL_C, OPT_ffixed_form) \
264 OPT("ffixed-line-length-", CL_C | CL_JOINED, OPT_ffixed_line_length) \
265 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
266 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
267 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
268 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
269 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
270 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
271 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
272 OPT("fhosted", CL_C, OPT_fhosted) \
273 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
274 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
275 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
276 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
277 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
278 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
279 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
280 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
281 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
282 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
283 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
284 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
285 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
286 OPT("fpch-deps", CL_ALL, OPT_fpch_deps) \
287 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
288 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
289 OPT("frepo", CL_CXX, OPT_frepo) \
290 OPT("frtti", CL_CXX, OPT_frtti) \
291 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
292 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
293 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
294 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
295 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
296 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
297 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
298 OPT("fstats", CL_CXX, OPT_fstats) \
299 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
300 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
301 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
302 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
303 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
304 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
305 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
306 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
307 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
308 OPT("fweak", CL_CXX, OPT_fweak) \
309 OPT("fxref", CL_CXX, OPT_fxref) \
310 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
311 OPT("idirafter", CL_ALL | CL_ARG, OPT_idirafter) \
312 OPT("imacros", CL_ALL | CL_ARG, OPT_imacros) \
313 OPT("include", CL_ALL | CL_ARG, OPT_include) \
314 OPT("iprefix", CL_ALL | CL_ARG, OPT_iprefix) \
315 OPT("isysroot", CL_ALL | CL_ARG, OPT_isysroot) \
316 OPT("isystem", CL_ALL | CL_ARG, OPT_isystem) \
317 OPT("iwithprefix", CL_ALL | CL_ARG, OPT_iwithprefix) \
318 OPT("iwithprefixbefore", CL_ALL | CL_ARG, OPT_iwithprefixbefore) \
319 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
320 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
321 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
322 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
323 OPT("o", CL_ALL | CL_ARG, OPT_o) \
324 OPT("pedantic", CL_ALL, OPT_pedantic) \
325 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
326 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
327 OPT("remap", CL_ALL, OPT_remap) \
328 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
329 OPT("std=c89", CL_C, OPT_std_c89) \
330 OPT("std=c99", CL_C, OPT_std_c99) \
331 OPT("std=c9x", CL_C, OPT_std_c9x) \
332 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
333 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
334 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
335 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
336 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
337 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
338 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
339 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
340 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
341 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
342 OPT("undef", CL_ALL, OPT_undef) \
343 OPT("v", CL_ALL, OPT_v) \
344 OPT("w", CL_ALL, OPT_w)
346 #define OPT(text, flags, code) code,
356 const char *opt_text;
357 unsigned char opt_len;
359 ENUM_BITFIELD (opt_code) opt_code : 2 * CHAR_BIT;
362 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
364 static struct cl_option cl_options[] =
366 static const struct cl_option cl_options[] =
372 #undef COMMAND_LINE_OPTIONS
374 /* Holds switches parsed by c_common_decode_option (), but whose
375 handling is deferred to c_common_post_options (). */
376 static void defer_opt PARAMS ((enum opt_code, const char *));
377 static struct deferred_opt
385 static int opt_comp PARAMS ((const void *, const void *));
387 /* Run-time sorting of options array. */
392 return strcmp (((struct cl_option *) p1)->opt_text,
393 ((struct cl_option *) p2)->opt_text);
397 /* Complain that switch OPT_INDEX expects an argument but none was
400 missing_arg (opt_index)
403 const char *opt_text = cl_options[opt_index].opt_text;
405 switch (cl_options[opt_index].opt_code)
407 case OPT__output_pch:
410 case OPT_fabi_version:
413 case OPT_fname_mangling:
415 case OPT_ftemplate_depth:
417 case OPT_iwithprefix:
418 case OPT_iwithprefixbefore:
420 error ("missing argument to \"-%s\"", opt_text);
423 case OPT_fconstant_string_class:
424 error ("no class name specified with \"-%s\"", opt_text);
428 error ("assertion missing after \"-%s\"", opt_text);
433 error ("macro name missing after \"-%s\"", opt_text);
440 error ("missing path after \"-%s\"", opt_text);
449 error ("missing filename after \"-%s\"", opt_text);
454 error ("missing target after \"-%s\"", opt_text);
459 /* Perform a binary search to find which option the command-line INPUT
460 matches. Returns its index in the option array, and N_OPTS on
463 Complications arise since some options can be suffixed with an
464 argument, and multiple complete matches can occur, e.g. -pedantic
465 and -pedantic-errors. Also, some options are only accepted by some
466 languages. If a switch matches for a different language and
467 doesn't match any alternatives for the true front end, the index of
468 the matched switch is returned anyway. The caller should check for
471 find_opt (input, lang_flag)
477 size_t result = N_OPTS;
487 opt_len = cl_options[md].opt_len;
488 comp = strncmp (input, cl_options[md].opt_text, opt_len);
496 /* The switch matches. It it an exact match? */
497 if (input[opt_len] == '\0')
503 /* If the switch takes no arguments this is not a proper
504 match, so we continue the search (e.g. input="stdc++"
505 match was "stdc"). */
506 if (!(cl_options[md].flags & CL_JOINED))
509 /* Is this switch valid for this front end? */
510 if (!(cl_options[md].flags & lang_flag))
512 /* If subsequently we don't find a better match,
513 return this and let the caller report it as a bad
519 /* Two scenarios remain: we have the switch's argument,
520 or we match a longer option. This can happen with
521 -iwithprefix and -withprefixbefore. The longest
522 possible option match succeeds.
524 Scan forwards, and return an exact match. Otherwise
525 return the longest valid option-accepting match (mx).
526 This loops at most twice with current options. */
528 for (md = md + 1; md < (size_t) N_OPTS; md++)
530 opt_len = cl_options[md].opt_len;
531 if (strncmp (input, cl_options[md].opt_text, opt_len))
533 if (input[opt_len] == '\0')
535 if (cl_options[md].flags & lang_flag
536 && cl_options[md].flags & CL_JOINED)
548 /* Defer option CODE with argument ARG. */
550 defer_opt (code, arg)
554 /* FIXME: this should be in c_common_init_options, which should take
558 extern int save_argc;
559 deferred_size = save_argc;
560 deferred_opts = (struct deferred_opt *)
561 xmalloc (deferred_size * sizeof (struct deferred_opt));
564 if (deferred_count == deferred_size)
567 deferred_opts[deferred_count].code = code;
568 deferred_opts[deferred_count].arg = arg;
572 /* Common initialization before parsing options. */
574 c_common_init_options (lang)
575 enum c_language_kind lang;
578 /* For non-ASCII hosts, the cl_options array needs to be sorted at
580 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
586 for (i = 1; i < N_OPTS; i++)
587 if (strcmp (cl_options[i - 1].opt_text, cl_options[i].opt_text) >= 0)
588 error ("options array incorrectly sorted: %s is before %s",
589 cl_options[i - 1].opt_text, cl_options[i].opt_text);
594 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX,
596 cpp_opts = cpp_get_options (parse_in);
597 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
601 flag_const_strings = (lang == clk_cplusplus);
602 warn_pointer_arith = (lang == clk_cplusplus);
605 /* Handle one command-line option in (argc, argv).
606 Can be called multiple times, to handle multiple sets of options.
607 Returns number of strings consumed. */
609 c_common_decode_option (argc, argv)
613 static const int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
615 const char *opt, *arg = 0;
618 int result = 0, lang_flag;
619 const struct cl_option *option;
624 /* Interpret "-" or a non-switch as a file name. */
625 if (opt[0] != '-' || opt[1] == '\0')
633 error ("too many filenames given. Type %s --help for usage",
641 /* Drop the "no-" from negative switches. */
642 if ((opt[1] == 'W' || opt[1] == 'f')
643 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
645 size_t len = strlen (opt) - 3;
647 dup = xmalloc (len + 1);
650 memcpy (dup + 2, opt + 5, len - 2 + 1);
656 lang_flag = lang_flags[(c_language << 1) + flag_objc];
657 opt_index = find_opt (opt + 1, lang_flag);
658 if (opt_index == N_OPTS)
662 option = &cl_options[opt_index];
664 /* Sort out any argument the switch takes. */
665 if (option->flags & CL_ARG)
667 if (option->flags & CL_JOINED)
669 /* Have arg point to the original switch. This is because
670 some code, such as disable_builtin_function, expects its
671 argument to be persistent until the program exits. */
672 arg = argv[0] + cl_options[opt_index].opt_len + 1;
674 arg += strlen ("no-");
677 /* If we don't have an argument, and CL_SEPARATE, try the next
678 argument in the vector. */
679 if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
685 if (!arg || *arg == '\0')
687 missing_arg (opt_index);
693 /* Complain about the wrong language after we've swallowed any
694 necessary extra argument. Eventually make this a hard error
695 after the call to find_opt, and return argc. */
696 if (!(cl_options[opt_index].flags & lang_flag))
698 complain_wrong_lang (opt_index);
702 switch (code = option->opt_code)
704 case N_OPTS: /* Shut GCC up. */
711 case OPT__output_pch:
716 defer_opt (code, arg);
720 cpp_opts->discard_comments = 0;
724 cpp_opts->discard_comments = 0;
725 cpp_opts->discard_comments_in_macro_exp = 0;
729 defer_opt (code, arg);
733 flag_preprocess_only = 1;
737 cpp_opts->print_include_names = 1;
741 if (strcmp (arg, "-"))
742 add_path (xstrdup (arg), BRACKET, 0);
745 if (quote_chain_split)
746 error ("-I- specified twice");
747 quote_chain_split = true;
748 split_quote_chain ();
754 /* When doing dependencies with -M or -MM, suppress normal
755 preprocessed output, but still do -dM etc. as software
756 depends on this. Preprocessed output does occur if -MD, -MMD
757 or environment var dependency generation is used. */
758 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
760 cpp_opts->inhibit_warnings = 1;
765 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
776 cpp_opts->deps.missing_files = true;
781 cpp_opts->deps.phony_targets = true;
787 defer_opt (code, arg);
791 flag_no_line_commands = 1;
795 defer_opt (code, arg);
806 warn_char_subscripts = on;
807 warn_missing_braces = on;
808 warn_parentheses = on;
809 warn_return_type = on;
810 warn_sequence_point = on; /* Was C only. */
811 if (c_language == clk_cplusplus)
812 warn_sign_compare = on;
814 warn_strict_aliasing = on;
816 /* Only warn about unknown pragmas that are not in system
818 warn_unknown_pragmas = on;
820 /* We save the value of warn_uninitialized, since if they put
821 -Wuninitialized on the command line, we need to generate a
822 warning about not using it without also specifying -O. */
823 if (warn_uninitialized != 1)
824 warn_uninitialized = (on ? 2 : 0);
826 if (c_language == clk_c)
827 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
828 can turn it off only if it's not explicit. */
832 /* C++-specific warnings. */
835 warn_nontemplate_friend = on;
838 cpp_opts->warn_trigraphs = on;
839 cpp_opts->warn_comments = on;
840 cpp_opts->warn_num_sign_change = on;
841 cpp_opts->warn_multichar = on; /* Was C++ only. */
844 case OPT_Wbad_function_cast:
845 warn_bad_function_cast = on;
852 case OPT_Wchar_subscripts:
853 warn_char_subscripts = on;
858 cpp_opts->warn_comments = on;
861 case OPT_Wconversion:
862 warn_conversion = on;
865 case OPT_Wctor_dtor_privacy:
866 warn_ctor_dtor_privacy = on;
869 case OPT_Wdeprecated:
870 warn_deprecated = on;
871 cpp_opts->warn_deprecated = on;
874 case OPT_Wdiv_by_zero:
875 warn_div_by_zero = on;
882 case OPT_Wendif_labels:
883 cpp_opts->warn_endif_labels = on;
887 cpp_opts->warnings_are_errors = on;
890 case OPT_Werror_implicit_function_decl:
894 mesg_implicit_function_declaration = 2;
897 case OPT_Wfloat_equal:
898 warn_float_equal = on;
906 set_Wformat (atoi (arg));
909 case OPT_Wformat_extra_args:
910 warn_format_extra_args = on;
913 case OPT_Wformat_nonliteral:
914 warn_format_nonliteral = on;
917 case OPT_Wformat_security:
918 warn_format_security = on;
921 case OPT_Wformat_y2k:
922 warn_format_y2k = on;
925 case OPT_Wformat_zero_length:
926 warn_format_zero_length = on;
933 case OPT_Wimplicit_function_decl:
934 mesg_implicit_function_declaration = on;
937 case OPT_Wimplicit_int:
938 warn_implicit_int = on;
942 cpp_opts->warn_import = on;
945 case OPT_Winvalid_pch:
946 cpp_opts->warn_invalid_pch = on;
960 case OPT_Wmissing_braces:
961 warn_missing_braces = on;
964 case OPT_Wmissing_declarations:
965 warn_missing_declarations = on;
968 case OPT_Wmissing_format_attribute:
969 warn_missing_format_attribute = on;
972 case OPT_Wmissing_prototypes:
973 warn_missing_prototypes = on;
977 cpp_opts->warn_multichar = on;
980 case OPT_Wnested_externs:
981 warn_nested_externs = on;
984 case OPT_Wnon_template_friend:
985 warn_nontemplate_friend = on;
988 case OPT_Wnon_virtual_dtor:
996 case OPT_Wold_style_cast:
997 warn_old_style_cast = on;
1000 case OPT_Woverloaded_virtual:
1001 warn_overloaded_virtual = on;
1004 case OPT_Wparentheses:
1005 warn_parentheses = on;
1008 case OPT_Wpmf_conversions:
1012 case OPT_Wpointer_arith:
1013 warn_pointer_arith = on;
1024 case OPT_Wredundant_decls:
1025 warn_redundant_decls = on;
1032 case OPT_Wreturn_type:
1033 warn_return_type = on;
1036 case OPT_Wsequence_point:
1037 warn_sequence_point = on;
1040 case OPT_Wsign_compare:
1041 warn_sign_compare = on;
1044 case OPT_Wsign_promo:
1045 warn_sign_promo = on;
1048 case OPT_Wstrict_prototypes:
1049 if (!on && c_language == clk_cplusplus)
1050 warning ("-Wno-strict-prototypes is not supported in C++");
1052 warn_strict_prototypes = on;
1059 case OPT_Wsystem_headers:
1060 cpp_opts->warn_system_headers = on;
1063 case OPT_Wtraditional:
1064 warn_traditional = on;
1065 cpp_opts->warn_traditional = on;
1068 case OPT_Wtrigraphs:
1069 cpp_opts->warn_trigraphs = on;
1072 case OPT_Wundeclared_selector:
1073 warn_undeclared_selector = on;
1077 cpp_opts->warn_undef = on;
1080 case OPT_Wunknown_pragmas:
1081 /* Set to greater than 1, so that even unknown pragmas in
1082 system headers will be warned about. */
1083 warn_unknown_pragmas = on * 2;
1086 case OPT_Wunused_macros:
1087 warn_unused_macros = on;
1090 case OPT_Wwrite_strings:
1091 if (c_language == clk_c)
1092 flag_const_strings = on;
1094 warn_write_strings = on;
1098 if (c_language == clk_c)
1099 set_std_c89 (false, true);
1101 set_std_cxx98 (true);
1108 case OPT_fcond_mismatch:
1109 if (c_language == clk_c)
1111 flag_cond_mismatch = on;
1116 case OPT_fall_virtual:
1117 case OPT_fenum_int_equiv:
1118 case OPT_fguiding_decls:
1119 case OPT_fhonor_std:
1120 case OPT_fhuge_objects:
1121 case OPT_flabels_ok:
1122 case OPT_fname_mangling:
1124 case OPT_fnonnull_objects:
1126 case OPT_fstrict_prototype:
1127 case OPT_fthis_is_variable:
1128 case OPT_fvtable_thunks:
1130 warning ("switch \"%s\" is no longer supported", argv[0]);
1133 case OPT_fabi_version:
1134 flag_abi_version = read_integral_parameter (arg, argv[0], 1);
1137 case OPT_faccess_control:
1138 flag_access_control = on;
1141 case OPT_falt_external_templates:
1142 flag_alt_external_templates = on;
1144 flag_external_templates = true;
1146 warning ("switch \"%s\" is deprecated, please see documentation for details", argv[0]);
1154 flag_no_builtin = !on;
1161 disable_builtin_function (arg);
1164 case OPT_fdollars_in_identifiers:
1165 cpp_opts->dollars_in_ident = on;
1169 if (!on || !dump_switch_p (argv[0] + strlen ("-f")))
1173 case OPT_ffreestanding:
1175 /* Fall through... */
1178 flag_no_builtin = !on;
1179 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
1180 if (!on && warn_main == 2)
1184 case OPT_fshort_double:
1185 flag_short_double = on;
1188 case OPT_fshort_enums:
1189 flag_short_enums = on;
1192 case OPT_fshort_wchar:
1193 flag_short_wchar = on;
1196 case OPT_fsigned_bitfields:
1197 flag_signed_bitfields = on;
1198 explicit_flag_signed_bitfields = 1;
1201 case OPT_fsigned_char:
1202 flag_signed_char = on;
1205 case OPT_funsigned_bitfields:
1206 flag_signed_bitfields = !on;
1207 explicit_flag_signed_bitfields = 1;
1210 case OPT_funsigned_char:
1211 flag_signed_char = !on;
1214 case OPT_fcheck_new:
1215 flag_check_new = on;
1218 case OPT_fconserve_space:
1219 flag_conserve_space = on;
1222 case OPT_fconst_strings:
1223 flag_const_strings = on;
1226 case OPT_fconstant_string_class:
1227 constant_string_class_name = arg;
1230 case OPT_fdefault_inline:
1231 flag_default_inline = on;
1234 case OPT_felide_constructors:
1235 flag_elide_constructors = on;
1238 case OPT_fenforce_eh_specs:
1239 flag_enforce_eh_specs = on;
1242 case OPT_fexternal_templates:
1243 flag_external_templates = on;
1246 case OPT_ffixed_form:
1247 case OPT_ffixed_line_length:
1248 /* Fortran front end options ignored when preprocessing only. */
1249 if (flag_preprocess_only)
1253 case OPT_ffor_scope:
1254 flag_new_for_scope = on;
1257 case OPT_fgnu_keywords:
1258 flag_no_gnu_keywords = !on;
1261 case OPT_fgnu_runtime:
1262 flag_next_runtime = !on;
1265 case OPT_fhandle_exceptions:
1266 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
1267 flag_exceptions = on;
1270 case OPT_fimplement_inlines:
1271 flag_implement_inlines = on;
1274 case OPT_fimplicit_inline_templates:
1275 flag_implicit_inline_templates = on;
1278 case OPT_fimplicit_templates:
1279 flag_implicit_templates = on;
1282 case OPT_fms_extensions:
1283 flag_ms_extensions = on;
1286 case OPT_fnext_runtime:
1287 flag_next_runtime = on;
1290 case OPT_fnonansi_builtins:
1291 flag_no_nonansi_builtin = !on;
1294 case OPT_foperator_names:
1295 cpp_opts->operator_names = on;
1298 case OPT_foptional_diags:
1299 flag_optional_diags = on;
1303 cpp_opts->restore_pch_deps = on;
1306 case OPT_fpermissive:
1307 flag_permissive = on;
1310 case OPT_fpreprocessed:
1311 cpp_opts->preprocessed = on;
1315 flag_use_repository = on;
1317 flag_implicit_templates = 0;
1324 case OPT_fshow_column:
1325 cpp_opts->show_column = on;
1329 flag_detailed_statistics = on;
1333 /* Don't recognize -fno-tabstop=. */
1337 /* It is documented that we silently ignore silly values. */
1340 long tabstop = strtol (arg, &endptr, 10);
1341 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1342 cpp_opts->tabstop = tabstop;
1346 case OPT_ftemplate_depth:
1347 max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
1350 case OPT_fvtable_gc:
1351 flag_vtable_gc = on;
1354 case OPT_fuse_cxa_atexit:
1355 flag_use_cxa_atexit = on;
1363 flag_gen_declaration = 1;
1367 add_path (xstrdup (arg), AFTER, 0);
1372 defer_opt (code, arg);
1384 add_path (xstrdup (arg), SYSTEM, 0);
1387 case OPT_iwithprefix:
1388 add_prefixed_path (arg, SYSTEM);
1391 case OPT_iwithprefixbefore:
1392 add_prefixed_path (arg, BRACKET);
1396 cpp_set_lang (parse_in, CLK_ASM);
1407 case OPT_nostdincplusplus:
1408 std_cxx_inc = false;
1416 error ("output filename specified twice");
1421 /* We need to handle the -pedantic switches here, rather than in
1422 c_common_post_options, so that a subsequent -Wno-endif-labels
1423 is not overridden. */
1424 case OPT_pedantic_errors:
1425 cpp_opts->pedantic_errors = 1;
1428 cpp_opts->pedantic = 1;
1429 cpp_opts->warn_endif_labels = 1;
1432 case OPT_print_objc_runtime_info:
1433 print_struct_values = 1;
1437 cpp_opts->remap = 1;
1440 case OPT_std_cplusplus98:
1441 case OPT_std_gnuplusplus98:
1442 set_std_cxx98 (code == OPT_std_cplusplus98 /* ISO */);
1446 case OPT_std_iso9899_1990:
1447 case OPT_std_iso9899_199409:
1448 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1452 set_std_c89 (false /* c94 */, false /* ISO */);
1457 case OPT_std_iso9899_1999:
1458 case OPT_std_iso9899_199x:
1459 set_std_c99 (true /* ISO */);
1464 set_std_c99 (false /* ISO */);
1468 cpp_opts->trigraphs = 1;
1471 case OPT_traditional_cpp:
1472 cpp_opts->traditional = 1;
1480 cpp_opts->inhibit_warnings = 1;
1494 /* Post-switch processing. */
1496 c_common_post_options (pfilename)
1497 const char **pfilename;
1499 /* Canonicalize the input and output filenames. */
1500 if (in_fname == NULL || !strcmp (in_fname, "-"))
1503 if (out_fname == NULL || !strcmp (out_fname, "-"))
1506 if (cpp_opts->deps.style == DEPS_NONE)
1507 check_deps_environment_vars ();
1509 handle_deferred_opts ();
1511 sanitize_cpp_opts ();
1513 register_include_chains (parse_in, sysroot, iprefix,
1514 std_inc, std_cxx_inc && c_language == clk_cplusplus,
1517 flag_inline_trees = 1;
1519 /* Use tree inlining if possible. Function instrumentation is only
1520 done in the RTL level, so we disable tree inlining. */
1521 if (! flag_instrument_function_entry_exit)
1523 if (!flag_no_inline)
1525 if (flag_inline_functions)
1527 flag_inline_trees = 2;
1528 flag_inline_functions = 0;
1532 /* -Wextra implies -Wsign-compare, but not if explicitly
1534 if (warn_sign_compare == -1)
1535 warn_sign_compare = extra_warnings;
1537 /* Special format checking options don't work without -Wformat; warn if
1539 if (warn_format_y2k && !warn_format)
1540 warning ("-Wformat-y2k ignored without -Wformat");
1541 if (warn_format_extra_args && !warn_format)
1542 warning ("-Wformat-extra-args ignored without -Wformat");
1543 if (warn_format_zero_length && !warn_format)
1544 warning ("-Wformat-zero-length ignored without -Wformat");
1545 if (warn_format_nonliteral && !warn_format)
1546 warning ("-Wformat-nonliteral ignored without -Wformat");
1547 if (warn_format_security && !warn_format)
1548 warning ("-Wformat-security ignored without -Wformat");
1549 if (warn_missing_format_attribute && !warn_format)
1550 warning ("-Wmissing-format-attribute ignored without -Wformat");
1552 if (flag_preprocess_only)
1554 /* Open the output now. We must do so even if flag_no_output is
1555 on, because there may be other output than from the actual
1556 preprocessing (e.g. from -dM). */
1557 if (out_fname[0] == '\0')
1558 out_stream = stdout;
1560 out_stream = fopen (out_fname, "w");
1562 if (out_stream == NULL)
1564 fatal_error ("opening output file %s: %m", out_fname);
1568 init_pp_output (out_stream);
1574 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1578 cpp_get_callbacks (parse_in)->file_change = cb_file_change;
1580 /* NOTE: we use in_fname here, not the one supplied. */
1581 *pfilename = cpp_read_main_file (parse_in, in_fname);
1583 saved_lineno = input_line;
1586 /* If an error has occurred in cpplib, note it so we fail
1588 errorcount += cpp_errors (parse_in);
1590 return flag_preprocess_only;
1593 /* Front end initialization common to C, ObjC and C++. */
1597 input_line = saved_lineno;
1599 /* Set up preprocessor arithmetic. Must be done after call to
1600 c_common_nodes_and_builtins for type nodes to be good. */
1601 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1602 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1603 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1604 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1605 cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
1606 cpp_opts->EBCDIC = TARGET_EBCDIC;
1608 if (flag_preprocess_only)
1611 preprocess_file (parse_in);
1615 /* Has to wait until now so that cpplib has its hash table. */
1621 /* A thin wrapper around the real parser that initializes the
1622 integrated preprocessor after debug output has been initialized.
1623 Also, make sure the start_source_file debug hook gets called for
1624 the primary source file. */
1626 c_common_parse_file (set_yydebug)
1627 int set_yydebug ATTRIBUTE_UNUSED;
1630 yydebug = set_yydebug;
1632 warning ("YYDEBUG not defined");
1635 (*debug_hooks->start_source_file) (input_line, input_filename);
1639 free_parser_stacks ();
1642 /* Common finish hook for the C, ObjC and C++ front ends. */
1646 FILE *deps_stream = NULL;
1648 if (cpp_opts->deps.style != DEPS_NONE)
1650 /* If -M or -MM was seen without -MF, default output to the
1653 deps_stream = out_stream;
1656 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1658 fatal_error ("opening dependency file %s: %m", deps_file);
1662 /* For performance, avoid tearing down cpplib's internal structures
1663 with cpp_destroy (). */
1664 errorcount += cpp_finish (parse_in, deps_stream);
1666 if (deps_stream && deps_stream != out_stream
1667 && (ferror (deps_stream) || fclose (deps_stream)))
1668 fatal_error ("closing dependency file %s: %m", deps_file);
1670 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1671 fatal_error ("when writing output to %s: %m", out_fname);
1674 /* Either of two environment variables can specify output of
1675 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1676 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1677 and DEPS_TARGET is the target to mention in the deps. They also
1678 result in dependency information being appended to the output file
1679 rather than overwriting it, and like Sun's compiler
1680 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1682 check_deps_environment_vars ()
1686 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1688 cpp_opts->deps.style = DEPS_USER;
1691 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1694 cpp_opts->deps.style = DEPS_SYSTEM;
1695 cpp_opts->deps.ignore_main_file = true;
1701 /* Find the space before the DEPS_TARGET, if there is one. */
1702 char *s = strchr (spec, ' ');
1705 /* Let the caller perform MAKE quoting. */
1706 defer_opt (OPT_MT, s + 1);
1710 /* Command line -MF overrides environment variables and default. */
1718 /* Handle deferred command line switches. */
1720 handle_deferred_opts ()
1724 for (i = 0; i < deferred_count; i++)
1726 struct deferred_opt *opt = &deferred_opts[i];
1728 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1729 cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
1733 /* These settings are appropriate for GCC, but not necessarily so for
1734 cpplib as a library. */
1736 sanitize_cpp_opts ()
1738 /* If we don't know what style of dependencies to output, complain
1739 if any other dependency switches have been given. */
1740 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1741 error ("to generate dependencies you must specify either -M or -MM");
1743 /* -dM and dependencies suppress normal output; do it here so that
1744 the last -d[MDN] switch overrides earlier ones. */
1745 if (flag_dump_macros == 'M')
1748 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1749 -dM since at least glibc relies on -M -dM to work. */
1752 if (flag_dump_macros != 'M')
1753 flag_dump_macros = 0;
1754 flag_dump_includes = 0;
1757 cpp_opts->unsigned_char = !flag_signed_char;
1758 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1760 /* We want -Wno-long-long to override -pedantic -std=non-c99
1761 and/or -Wtraditional, whatever the ordering. */
1762 cpp_opts->warn_long_long
1763 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1766 /* Add include path with a prefix at the front of its name. */
1768 add_prefixed_path (suffix, chain)
1774 size_t prefix_len, suffix_len;
1776 suffix_len = strlen (suffix);
1777 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1778 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1780 path = xmalloc (prefix_len + suffix_len + 1);
1781 memcpy (path, prefix, prefix_len);
1782 memcpy (path + prefix_len, suffix, suffix_len);
1783 path[prefix_len + suffix_len] = '\0';
1785 add_path (path, chain, 0);
1788 /* Handle -D, -U, -A, -imacros, and the first -include. */
1792 if (!cpp_opts->preprocessed)
1796 cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
1797 cpp_init_builtins (parse_in, flag_hosted);
1798 c_cpp_builtins (parse_in);
1799 cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
1800 for (i = 0; i < deferred_count; i++)
1802 struct deferred_opt *opt = &deferred_opts[i];
1804 if (opt->code == OPT_D)
1805 cpp_define (parse_in, opt->arg);
1806 else if (opt->code == OPT_U)
1807 cpp_undef (parse_in, opt->arg);
1808 else if (opt->code == OPT_A)
1810 if (opt->arg[0] == '-')
1811 cpp_unassert (parse_in, opt->arg + 1);
1813 cpp_assert (parse_in, opt->arg);
1817 /* Handle -imacros after -D and -U. */
1818 for (i = 0; i < deferred_count; i++)
1820 struct deferred_opt *opt = &deferred_opts[i];
1822 if (opt->code == OPT_imacros
1823 && cpp_push_include (parse_in, opt->arg))
1824 cpp_scan_nooutput (parse_in);
1828 push_command_line_include ();
1831 /* Give CPP the next file given by -include, if any. */
1833 push_command_line_include ()
1835 if (cpp_opts->preprocessed)
1838 while (include_cursor < deferred_count)
1840 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1842 if (opt->code == OPT_include && cpp_push_include (parse_in, opt->arg))
1846 if (include_cursor == deferred_count)
1848 /* Restore the line map from <command line>. */
1849 cpp_change_file (parse_in, LC_RENAME, main_input_filename);
1850 /* -Wunused-macros should only warn about macros defined hereafter. */
1851 cpp_opts->warn_unused_macros = warn_unused_macros;
1856 /* File change callback. Has to handle -include files. */
1858 cb_file_change (pfile, new_map)
1859 cpp_reader *pfile ATTRIBUTE_UNUSED;
1860 const struct line_map *new_map;
1862 if (flag_preprocess_only)
1863 pp_file_change (new_map);
1865 fe_file_change (new_map);
1867 if (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))
1868 push_command_line_include ();
1871 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1872 extensions if ISO). There is no concept of gnu94. */
1874 set_std_c89 (c94, iso)
1877 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1880 flag_no_gnu_keywords = iso;
1881 flag_no_nonansi_builtin = iso;
1882 flag_noniso_default_format_attributes = !iso;
1885 flag_writable_strings = 0;
1888 /* Set the C 99 standard (without GNU extensions if ISO). */
1893 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1895 flag_no_nonansi_builtin = iso;
1896 flag_noniso_default_format_attributes = !iso;
1900 flag_writable_strings = 0;
1903 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1908 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1909 flag_no_gnu_keywords = iso;
1910 flag_no_nonansi_builtin = iso;
1911 flag_noniso_default_format_attributes = !iso;
1915 /* Handle setting implicit to ON. */
1921 warn_implicit_int = on;
1924 if (mesg_implicit_function_declaration != 2)
1925 mesg_implicit_function_declaration = 1;
1928 mesg_implicit_function_declaration = 0;
1931 /* Args to -d specify what to dump. Silently ignore
1932 unrecognized options; they may be aimed at toplev.c. */
1939 while ((c = *arg++) != '\0')
1942 case 'M': /* Dump macros only. */
1943 case 'N': /* Dump names. */
1944 case 'D': /* Dump definitions. */
1945 flag_dump_macros = c;
1949 flag_dump_includes = 1;
1954 /* Write a slash-separated list of languages in FLAGS to BUF. */
1956 write_langs (buf, flags)
1961 if (flags & CL_C_ONLY)
1963 if (flags & CL_OBJC_ONLY)
1967 strcat (buf, "ObjC");
1969 if (flags & CL_CXX_ONLY)
1973 strcat (buf, "C++");
1977 /* Complain that switch OPT_INDEX does not apply to this front end. */
1979 complain_wrong_lang (opt_index)
1982 char ok_langs[60], bad_langs[60];
1983 int ok_flags = cl_options[opt_index].flags;
1985 write_langs (ok_langs, ok_flags);
1986 write_langs (bad_langs, ~ok_flags);
1987 warning ("\"-%s\" is valid for %s but not for %s",
1988 cl_options[opt_index].opt_text, ok_langs, bad_langs);
1991 /* Handle --help output. */
1995 /* To keep the lines from getting too long for some compilers, limit
1996 to about 500 characters (6 lines) per chunk. */
1999 -include <file> Include the contents of <file> before other files\n\
2000 -imacros <file> Accept definition of macros in <file>\n\
2001 -iprefix <path> Specify <path> as a prefix for next two options\n\
2002 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
2003 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
2004 -isystem <dir> Add <dir> to the start of the system include path\n\
2007 -idirafter <dir> Add <dir> to the end of the system include path\n\
2008 -I <dir> Add <dir> to the end of the main include path\n\
2009 -I- Fine-grained include path control; see info docs\n\
2010 -nostdinc Do not search system include directories\n\
2011 (dirs specified with -isystem will still be used)\n\
2012 -nostdinc++ Do not search system include directories for C++\n\
2013 -o <file> Put output into <file>\n\
2016 -trigraphs Support ISO C trigraphs\n\
2017 -std=<std name> Specify the conformance standard; one of:\n\
2018 gnu89, gnu99, c89, c99, iso9899:1990,\n\
2019 iso9899:199409, iso9899:1999, c++98\n\
2020 -w Inhibit warning messages\n\
2021 -W[no-]trigraphs Warn if trigraphs are encountered\n\
2022 -W[no-]comment{s} Warn if one comment starts inside another\n\
2025 -W[no-]traditional Warn about features not present in traditional C\n\
2026 -W[no-]undef Warn if an undefined macro is used by #if\n\
2027 -W[no-]import Warn about the use of the #import directive\n\
2030 -W[no-]error Treat all warnings as errors\n\
2031 -W[no-]system-headers Do not suppress warnings from system headers\n\
2032 -W[no-]all Enable most preprocessor warnings\n\
2035 -M Generate make dependencies\n\
2036 -MM As -M, but ignore system header files\n\
2037 -MD Generate make dependencies and compile\n\
2038 -MMD As -MD, but ignore system header files\n\
2039 -MF <file> Write dependency output to the given file\n\
2040 -MG Treat missing header file as generated files\n\
2043 -MP Generate phony targets for all headers\n\
2044 -MQ <target> Add a MAKE-quoted target\n\
2045 -MT <target> Add an unquoted target\n\
2048 -D<macro> Define a <macro> with string '1' as its value\n\
2049 -D<macro>=<val> Define a <macro> with <val> as its value\n\
2050 -A<question>=<answer> Assert the <answer> to <question>\n\
2051 -A-<question>=<answer> Disable the <answer> to <question>\n\
2052 -U<macro> Undefine <macro> \n\
2053 -v Display the version number\n\
2056 -H Print the name of header files as they are used\n\
2057 -C Do not discard comments\n\
2058 -dM Display a list of macro definitions active at end\n\
2059 -dD Preserve macro definitions in output\n\
2060 -dN As -dD except that only the names are preserved\n\
2061 -dI Include #include directives in the output\n\
2064 -f[no-]preprocessed Treat the input file as already preprocessed\n\
2065 -ftabstop=<number> Distance between tab stops for column reporting\n\
2066 -isysroot <dir> Set <dir> to be the system root directory\n\
2067 -P Do not generate #line directives\n\
2068 -remap Remap file names when including files\n\
2069 --help Display this information\n\