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-offsetof", CL_CXX, OPT_Winvalid_offsetof) \
207 OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
208 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
209 OPT("Wmain", CL_C, OPT_Wmain) \
210 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
211 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
212 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
213 OPT("Wmissing-prototypes", CL_C, OPT_Wmissing_prototypes) \
214 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
215 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
216 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
217 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
218 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
219 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
220 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
221 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
222 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
223 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
224 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
225 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
226 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
227 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
228 OPT("Wselector", CL_OBJC, OPT_Wselector) \
229 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
230 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
231 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
232 OPT("Wstrict-prototypes", CL_C, OPT_Wstrict_prototypes) \
233 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
234 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
235 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
236 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
237 OPT("Wundeclared-selector", CL_OBJC, OPT_Wundeclared_selector) \
238 OPT("Wundef", CL_ALL, OPT_Wundef) \
239 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
240 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
241 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
242 OPT("ansi", CL_ALL, OPT_ansi) \
243 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
244 OPT("fabi-version=", CL_CXX | CL_JOINED, OPT_fabi_version) \
245 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
246 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
247 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
248 OPT("fasm", CL_ALL, OPT_fasm) \
249 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
250 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
251 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
252 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
253 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
254 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
255 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
256 OPT_fconstant_string_class) \
257 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
258 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
259 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
260 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
261 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
262 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
263 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
264 OPT("ffixed-form", CL_C, OPT_ffixed_form) \
265 OPT("ffixed-line-length-", CL_C | CL_JOINED, OPT_ffixed_line_length) \
266 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
267 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
268 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
269 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
270 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
271 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
272 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
273 OPT("fhosted", CL_C, OPT_fhosted) \
274 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
275 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
276 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
277 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
278 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
279 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
280 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
281 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
282 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
283 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
284 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
285 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
286 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
287 OPT("fpch-deps", CL_ALL, OPT_fpch_deps) \
288 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
289 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
290 OPT("frepo", CL_CXX, OPT_frepo) \
291 OPT("frtti", CL_CXX, OPT_frtti) \
292 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
293 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
294 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
295 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
296 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
297 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
298 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
299 OPT("fstats", CL_CXX, OPT_fstats) \
300 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
301 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
302 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
303 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
304 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
305 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
306 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
307 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
308 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
309 OPT("fweak", CL_CXX, OPT_fweak) \
310 OPT("fxref", CL_CXX, OPT_fxref) \
311 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
312 OPT("idirafter", CL_ALL | CL_ARG, OPT_idirafter) \
313 OPT("imacros", CL_ALL | CL_ARG, OPT_imacros) \
314 OPT("include", CL_ALL | CL_ARG, OPT_include) \
315 OPT("iprefix", CL_ALL | CL_ARG, OPT_iprefix) \
316 OPT("isysroot", CL_ALL | CL_ARG, OPT_isysroot) \
317 OPT("isystem", CL_ALL | CL_ARG, OPT_isystem) \
318 OPT("iwithprefix", CL_ALL | CL_ARG, OPT_iwithprefix) \
319 OPT("iwithprefixbefore", CL_ALL | CL_ARG, OPT_iwithprefixbefore) \
320 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
321 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
322 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
323 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
324 OPT("o", CL_ALL | CL_ARG, OPT_o) \
325 OPT("pedantic", CL_ALL, OPT_pedantic) \
326 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
327 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
328 OPT("remap", CL_ALL, OPT_remap) \
329 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
330 OPT("std=c89", CL_C, OPT_std_c89) \
331 OPT("std=c99", CL_C, OPT_std_c99) \
332 OPT("std=c9x", CL_C, OPT_std_c9x) \
333 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
334 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
335 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
336 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
337 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
338 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
339 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
340 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
341 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
342 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
343 OPT("undef", CL_ALL, OPT_undef) \
344 OPT("v", CL_ALL, OPT_v) \
345 OPT("w", CL_ALL, OPT_w)
347 #define OPT(text, flags, code) code,
357 const char *opt_text;
358 unsigned char opt_len;
360 ENUM_BITFIELD (opt_code) opt_code : 2 * CHAR_BIT;
363 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
365 static struct cl_option cl_options[] =
367 static const struct cl_option cl_options[] =
373 #undef COMMAND_LINE_OPTIONS
375 /* Holds switches parsed by c_common_decode_option (), but whose
376 handling is deferred to c_common_post_options (). */
377 static void defer_opt PARAMS ((enum opt_code, const char *));
378 static struct deferred_opt
386 static int opt_comp PARAMS ((const void *, const void *));
388 /* Run-time sorting of options array. */
393 return strcmp (((struct cl_option *) p1)->opt_text,
394 ((struct cl_option *) p2)->opt_text);
398 /* Complain that switch OPT_INDEX expects an argument but none was
401 missing_arg (opt_index)
404 const char *opt_text = cl_options[opt_index].opt_text;
406 switch (cl_options[opt_index].opt_code)
408 case OPT__output_pch:
411 case OPT_fabi_version:
414 case OPT_fname_mangling:
416 case OPT_ftemplate_depth:
418 case OPT_iwithprefix:
419 case OPT_iwithprefixbefore:
421 error ("missing argument to \"-%s\"", opt_text);
424 case OPT_fconstant_string_class:
425 error ("no class name specified with \"-%s\"", opt_text);
429 error ("assertion missing after \"-%s\"", opt_text);
434 error ("macro name missing after \"-%s\"", opt_text);
441 error ("missing path after \"-%s\"", opt_text);
450 error ("missing filename after \"-%s\"", opt_text);
455 error ("missing target after \"-%s\"", opt_text);
460 /* Perform a binary search to find which option the command-line INPUT
461 matches. Returns its index in the option array, and N_OPTS on
464 Complications arise since some options can be suffixed with an
465 argument, and multiple complete matches can occur, e.g. -pedantic
466 and -pedantic-errors. Also, some options are only accepted by some
467 languages. If a switch matches for a different language and
468 doesn't match any alternatives for the true front end, the index of
469 the matched switch is returned anyway. The caller should check for
472 find_opt (input, lang_flag)
478 size_t result = N_OPTS;
488 opt_len = cl_options[md].opt_len;
489 comp = strncmp (input, cl_options[md].opt_text, opt_len);
497 /* The switch matches. It it an exact match? */
498 if (input[opt_len] == '\0')
504 /* If the switch takes no arguments this is not a proper
505 match, so we continue the search (e.g. input="stdc++"
506 match was "stdc"). */
507 if (!(cl_options[md].flags & CL_JOINED))
510 /* Is this switch valid for this front end? */
511 if (!(cl_options[md].flags & lang_flag))
513 /* If subsequently we don't find a better match,
514 return this and let the caller report it as a bad
520 /* Two scenarios remain: we have the switch's argument,
521 or we match a longer option. This can happen with
522 -iwithprefix and -withprefixbefore. The longest
523 possible option match succeeds.
525 Scan forwards, and return an exact match. Otherwise
526 return the longest valid option-accepting match (mx).
527 This loops at most twice with current options. */
529 for (md = md + 1; md < (size_t) N_OPTS; md++)
531 opt_len = cl_options[md].opt_len;
532 if (strncmp (input, cl_options[md].opt_text, opt_len))
534 if (input[opt_len] == '\0')
536 if (cl_options[md].flags & lang_flag
537 && cl_options[md].flags & CL_JOINED)
549 /* Defer option CODE with argument ARG. */
551 defer_opt (code, arg)
555 /* FIXME: this should be in c_common_init_options, which should take
559 extern int save_argc;
560 deferred_size = save_argc;
561 deferred_opts = (struct deferred_opt *)
562 xmalloc (deferred_size * sizeof (struct deferred_opt));
565 if (deferred_count == deferred_size)
568 deferred_opts[deferred_count].code = code;
569 deferred_opts[deferred_count].arg = arg;
573 /* Common initialization before parsing options. */
575 c_common_init_options (lang)
576 enum c_language_kind lang;
579 /* For non-ASCII hosts, the cl_options array needs to be sorted at
581 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
587 for (i = 1; i < N_OPTS; i++)
588 if (strcmp (cl_options[i - 1].opt_text, cl_options[i].opt_text) >= 0)
589 error ("options array incorrectly sorted: %s is before %s",
590 cl_options[i - 1].opt_text, cl_options[i].opt_text);
595 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX,
597 cpp_opts = cpp_get_options (parse_in);
598 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
602 flag_const_strings = (lang == clk_cplusplus);
603 warn_pointer_arith = (lang == clk_cplusplus);
606 /* Handle one command-line option in (argc, argv).
607 Can be called multiple times, to handle multiple sets of options.
608 Returns number of strings consumed. */
610 c_common_decode_option (argc, argv)
614 static const int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
616 const char *opt, *arg = 0;
619 int result = 0, lang_flag;
620 const struct cl_option *option;
625 /* Interpret "-" or a non-switch as a file name. */
626 if (opt[0] != '-' || opt[1] == '\0')
634 error ("too many filenames given. Type %s --help for usage",
642 /* Drop the "no-" from negative switches. */
643 if ((opt[1] == 'W' || opt[1] == 'f')
644 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
646 size_t len = strlen (opt) - 3;
648 dup = xmalloc (len + 1);
651 memcpy (dup + 2, opt + 5, len - 2 + 1);
657 lang_flag = lang_flags[(c_language << 1) + flag_objc];
658 opt_index = find_opt (opt + 1, lang_flag);
659 if (opt_index == N_OPTS)
663 option = &cl_options[opt_index];
665 /* Sort out any argument the switch takes. */
666 if (option->flags & CL_ARG)
668 if (option->flags & CL_JOINED)
670 /* Have arg point to the original switch. This is because
671 some code, such as disable_builtin_function, expects its
672 argument to be persistent until the program exits. */
673 arg = argv[0] + cl_options[opt_index].opt_len + 1;
675 arg += strlen ("no-");
678 /* If we don't have an argument, and CL_SEPARATE, try the next
679 argument in the vector. */
680 if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
686 if (!arg || *arg == '\0')
688 missing_arg (opt_index);
694 /* Complain about the wrong language after we've swallowed any
695 necessary extra argument. Eventually make this a hard error
696 after the call to find_opt, and return argc. */
697 if (!(cl_options[opt_index].flags & lang_flag))
699 complain_wrong_lang (opt_index);
703 switch (code = option->opt_code)
705 case N_OPTS: /* Shut GCC up. */
712 case OPT__output_pch:
717 defer_opt (code, arg);
721 cpp_opts->discard_comments = 0;
725 cpp_opts->discard_comments = 0;
726 cpp_opts->discard_comments_in_macro_exp = 0;
730 defer_opt (code, arg);
734 flag_preprocess_only = 1;
738 cpp_opts->print_include_names = 1;
742 if (strcmp (arg, "-"))
743 add_path (xstrdup (arg), BRACKET, 0);
746 if (quote_chain_split)
747 error ("-I- specified twice");
748 quote_chain_split = true;
749 split_quote_chain ();
755 /* When doing dependencies with -M or -MM, suppress normal
756 preprocessed output, but still do -dM etc. as software
757 depends on this. Preprocessed output does occur if -MD, -MMD
758 or environment var dependency generation is used. */
759 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
761 cpp_opts->inhibit_warnings = 1;
766 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
777 cpp_opts->deps.missing_files = true;
782 cpp_opts->deps.phony_targets = true;
788 defer_opt (code, arg);
792 flag_no_line_commands = 1;
796 defer_opt (code, arg);
807 warn_char_subscripts = on;
808 warn_missing_braces = on;
809 warn_parentheses = on;
810 warn_return_type = on;
811 warn_sequence_point = on; /* Was C only. */
812 if (c_language == clk_cplusplus)
813 warn_sign_compare = on;
815 warn_strict_aliasing = on;
817 /* Only warn about unknown pragmas that are not in system
819 warn_unknown_pragmas = on;
821 /* We save the value of warn_uninitialized, since if they put
822 -Wuninitialized on the command line, we need to generate a
823 warning about not using it without also specifying -O. */
824 if (warn_uninitialized != 1)
825 warn_uninitialized = (on ? 2 : 0);
827 if (c_language == clk_c)
828 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
829 can turn it off only if it's not explicit. */
833 /* C++-specific warnings. */
836 warn_nontemplate_friend = on;
839 cpp_opts->warn_trigraphs = on;
840 cpp_opts->warn_comments = on;
841 cpp_opts->warn_num_sign_change = on;
842 cpp_opts->warn_multichar = on; /* Was C++ only. */
845 case OPT_Wbad_function_cast:
846 warn_bad_function_cast = on;
853 case OPT_Wchar_subscripts:
854 warn_char_subscripts = on;
859 cpp_opts->warn_comments = on;
862 case OPT_Wconversion:
863 warn_conversion = on;
866 case OPT_Wctor_dtor_privacy:
867 warn_ctor_dtor_privacy = on;
870 case OPT_Wdeprecated:
871 warn_deprecated = on;
872 cpp_opts->warn_deprecated = on;
875 case OPT_Wdiv_by_zero:
876 warn_div_by_zero = on;
883 case OPT_Wendif_labels:
884 cpp_opts->warn_endif_labels = on;
888 cpp_opts->warnings_are_errors = on;
891 case OPT_Werror_implicit_function_decl:
895 mesg_implicit_function_declaration = 2;
898 case OPT_Wfloat_equal:
899 warn_float_equal = on;
907 set_Wformat (atoi (arg));
910 case OPT_Wformat_extra_args:
911 warn_format_extra_args = on;
914 case OPT_Wformat_nonliteral:
915 warn_format_nonliteral = on;
918 case OPT_Wformat_security:
919 warn_format_security = on;
922 case OPT_Wformat_y2k:
923 warn_format_y2k = on;
926 case OPT_Wformat_zero_length:
927 warn_format_zero_length = on;
934 case OPT_Wimplicit_function_decl:
935 mesg_implicit_function_declaration = on;
938 case OPT_Wimplicit_int:
939 warn_implicit_int = on;
943 cpp_opts->warn_import = on;
946 case OPT_Winvalid_offsetof:
947 warn_invalid_offsetof = on;
950 case OPT_Winvalid_pch:
951 cpp_opts->warn_invalid_pch = on;
965 case OPT_Wmissing_braces:
966 warn_missing_braces = on;
969 case OPT_Wmissing_declarations:
970 warn_missing_declarations = on;
973 case OPT_Wmissing_format_attribute:
974 warn_missing_format_attribute = on;
977 case OPT_Wmissing_prototypes:
978 warn_missing_prototypes = on;
982 cpp_opts->warn_multichar = on;
985 case OPT_Wnested_externs:
986 warn_nested_externs = on;
989 case OPT_Wnon_template_friend:
990 warn_nontemplate_friend = on;
993 case OPT_Wnon_virtual_dtor:
1001 case OPT_Wold_style_cast:
1002 warn_old_style_cast = on;
1005 case OPT_Woverloaded_virtual:
1006 warn_overloaded_virtual = on;
1009 case OPT_Wparentheses:
1010 warn_parentheses = on;
1013 case OPT_Wpmf_conversions:
1017 case OPT_Wpointer_arith:
1018 warn_pointer_arith = on;
1029 case OPT_Wredundant_decls:
1030 warn_redundant_decls = on;
1037 case OPT_Wreturn_type:
1038 warn_return_type = on;
1041 case OPT_Wsequence_point:
1042 warn_sequence_point = on;
1045 case OPT_Wsign_compare:
1046 warn_sign_compare = on;
1049 case OPT_Wsign_promo:
1050 warn_sign_promo = on;
1053 case OPT_Wstrict_prototypes:
1054 if (!on && c_language == clk_cplusplus)
1055 warning ("-Wno-strict-prototypes is not supported in C++");
1057 warn_strict_prototypes = on;
1064 case OPT_Wsystem_headers:
1065 cpp_opts->warn_system_headers = on;
1068 case OPT_Wtraditional:
1069 warn_traditional = on;
1070 cpp_opts->warn_traditional = on;
1073 case OPT_Wtrigraphs:
1074 cpp_opts->warn_trigraphs = on;
1077 case OPT_Wundeclared_selector:
1078 warn_undeclared_selector = on;
1082 cpp_opts->warn_undef = on;
1085 case OPT_Wunknown_pragmas:
1086 /* Set to greater than 1, so that even unknown pragmas in
1087 system headers will be warned about. */
1088 warn_unknown_pragmas = on * 2;
1091 case OPT_Wunused_macros:
1092 warn_unused_macros = on;
1095 case OPT_Wwrite_strings:
1096 if (c_language == clk_c)
1097 flag_const_strings = on;
1099 warn_write_strings = on;
1103 if (c_language == clk_c)
1104 set_std_c89 (false, true);
1106 set_std_cxx98 (true);
1113 case OPT_fcond_mismatch:
1114 if (c_language == clk_c)
1116 flag_cond_mismatch = on;
1121 case OPT_fall_virtual:
1122 case OPT_fenum_int_equiv:
1123 case OPT_fguiding_decls:
1124 case OPT_fhonor_std:
1125 case OPT_fhuge_objects:
1126 case OPT_flabels_ok:
1127 case OPT_fname_mangling:
1129 case OPT_fnonnull_objects:
1131 case OPT_fstrict_prototype:
1132 case OPT_fthis_is_variable:
1133 case OPT_fvtable_thunks:
1135 warning ("switch \"%s\" is no longer supported", argv[0]);
1138 case OPT_fabi_version:
1139 flag_abi_version = read_integral_parameter (arg, argv[0], 1);
1142 case OPT_faccess_control:
1143 flag_access_control = on;
1146 case OPT_falt_external_templates:
1147 flag_alt_external_templates = on;
1149 flag_external_templates = true;
1151 warning ("switch \"%s\" is deprecated, please see documentation for details", argv[0]);
1159 flag_no_builtin = !on;
1166 disable_builtin_function (arg);
1169 case OPT_fdollars_in_identifiers:
1170 cpp_opts->dollars_in_ident = on;
1174 if (!on || !dump_switch_p (argv[0] + strlen ("-f")))
1178 case OPT_ffreestanding:
1180 /* Fall through... */
1183 flag_no_builtin = !on;
1184 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
1185 if (!on && warn_main == 2)
1189 case OPT_fshort_double:
1190 flag_short_double = on;
1193 case OPT_fshort_enums:
1194 flag_short_enums = on;
1197 case OPT_fshort_wchar:
1198 flag_short_wchar = on;
1201 case OPT_fsigned_bitfields:
1202 flag_signed_bitfields = on;
1203 explicit_flag_signed_bitfields = 1;
1206 case OPT_fsigned_char:
1207 flag_signed_char = on;
1210 case OPT_funsigned_bitfields:
1211 flag_signed_bitfields = !on;
1212 explicit_flag_signed_bitfields = 1;
1215 case OPT_funsigned_char:
1216 flag_signed_char = !on;
1219 case OPT_fcheck_new:
1220 flag_check_new = on;
1223 case OPT_fconserve_space:
1224 flag_conserve_space = on;
1227 case OPT_fconst_strings:
1228 flag_const_strings = on;
1231 case OPT_fconstant_string_class:
1232 constant_string_class_name = arg;
1235 case OPT_fdefault_inline:
1236 flag_default_inline = on;
1239 case OPT_felide_constructors:
1240 flag_elide_constructors = on;
1243 case OPT_fenforce_eh_specs:
1244 flag_enforce_eh_specs = on;
1247 case OPT_fexternal_templates:
1248 flag_external_templates = on;
1251 case OPT_ffixed_form:
1252 case OPT_ffixed_line_length:
1253 /* Fortran front end options ignored when preprocessing only. */
1254 if (flag_preprocess_only)
1258 case OPT_ffor_scope:
1259 flag_new_for_scope = on;
1262 case OPT_fgnu_keywords:
1263 flag_no_gnu_keywords = !on;
1266 case OPT_fgnu_runtime:
1267 flag_next_runtime = !on;
1270 case OPT_fhandle_exceptions:
1271 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
1272 flag_exceptions = on;
1275 case OPT_fimplement_inlines:
1276 flag_implement_inlines = on;
1279 case OPT_fimplicit_inline_templates:
1280 flag_implicit_inline_templates = on;
1283 case OPT_fimplicit_templates:
1284 flag_implicit_templates = on;
1287 case OPT_fms_extensions:
1288 flag_ms_extensions = on;
1291 case OPT_fnext_runtime:
1292 flag_next_runtime = on;
1295 case OPT_fnonansi_builtins:
1296 flag_no_nonansi_builtin = !on;
1299 case OPT_foperator_names:
1300 cpp_opts->operator_names = on;
1303 case OPT_foptional_diags:
1304 flag_optional_diags = on;
1308 cpp_opts->restore_pch_deps = on;
1311 case OPT_fpermissive:
1312 flag_permissive = on;
1315 case OPT_fpreprocessed:
1316 cpp_opts->preprocessed = on;
1320 flag_use_repository = on;
1322 flag_implicit_templates = 0;
1329 case OPT_fshow_column:
1330 cpp_opts->show_column = on;
1334 flag_detailed_statistics = on;
1338 /* Don't recognize -fno-tabstop=. */
1342 /* It is documented that we silently ignore silly values. */
1345 long tabstop = strtol (arg, &endptr, 10);
1346 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1347 cpp_opts->tabstop = tabstop;
1351 case OPT_ftemplate_depth:
1352 max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
1355 case OPT_fvtable_gc:
1356 flag_vtable_gc = on;
1359 case OPT_fuse_cxa_atexit:
1360 flag_use_cxa_atexit = on;
1368 flag_gen_declaration = 1;
1372 add_path (xstrdup (arg), AFTER, 0);
1377 defer_opt (code, arg);
1389 add_path (xstrdup (arg), SYSTEM, 0);
1392 case OPT_iwithprefix:
1393 add_prefixed_path (arg, SYSTEM);
1396 case OPT_iwithprefixbefore:
1397 add_prefixed_path (arg, BRACKET);
1401 cpp_set_lang (parse_in, CLK_ASM);
1402 cpp_opts->dollars_in_ident = false;
1413 case OPT_nostdincplusplus:
1414 std_cxx_inc = false;
1422 error ("output filename specified twice");
1427 /* We need to handle the -pedantic switches here, rather than in
1428 c_common_post_options, so that a subsequent -Wno-endif-labels
1429 is not overridden. */
1430 case OPT_pedantic_errors:
1431 cpp_opts->pedantic_errors = 1;
1434 cpp_opts->pedantic = 1;
1435 cpp_opts->warn_endif_labels = 1;
1438 case OPT_print_objc_runtime_info:
1439 print_struct_values = 1;
1443 cpp_opts->remap = 1;
1446 case OPT_std_cplusplus98:
1447 case OPT_std_gnuplusplus98:
1448 set_std_cxx98 (code == OPT_std_cplusplus98 /* ISO */);
1452 case OPT_std_iso9899_1990:
1453 case OPT_std_iso9899_199409:
1454 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1458 set_std_c89 (false /* c94 */, false /* ISO */);
1463 case OPT_std_iso9899_1999:
1464 case OPT_std_iso9899_199x:
1465 set_std_c99 (true /* ISO */);
1470 set_std_c99 (false /* ISO */);
1474 cpp_opts->trigraphs = 1;
1477 case OPT_traditional_cpp:
1478 cpp_opts->traditional = 1;
1486 cpp_opts->inhibit_warnings = 1;
1500 /* Post-switch processing. */
1502 c_common_post_options (pfilename)
1503 const char **pfilename;
1505 /* Canonicalize the input and output filenames. */
1506 if (in_fname == NULL || !strcmp (in_fname, "-"))
1509 if (out_fname == NULL || !strcmp (out_fname, "-"))
1512 if (cpp_opts->deps.style == DEPS_NONE)
1513 check_deps_environment_vars ();
1515 handle_deferred_opts ();
1517 sanitize_cpp_opts ();
1519 register_include_chains (parse_in, sysroot, iprefix,
1520 std_inc, std_cxx_inc && c_language == clk_cplusplus,
1523 flag_inline_trees = 1;
1525 /* Use tree inlining if possible. Function instrumentation is only
1526 done in the RTL level, so we disable tree inlining. */
1527 if (! flag_instrument_function_entry_exit)
1529 if (!flag_no_inline)
1531 if (flag_inline_functions)
1533 flag_inline_trees = 2;
1534 flag_inline_functions = 0;
1538 /* -Wextra implies -Wsign-compare, but not if explicitly
1540 if (warn_sign_compare == -1)
1541 warn_sign_compare = extra_warnings;
1543 /* Special format checking options don't work without -Wformat; warn if
1545 if (warn_format_y2k && !warn_format)
1546 warning ("-Wformat-y2k ignored without -Wformat");
1547 if (warn_format_extra_args && !warn_format)
1548 warning ("-Wformat-extra-args ignored without -Wformat");
1549 if (warn_format_zero_length && !warn_format)
1550 warning ("-Wformat-zero-length ignored without -Wformat");
1551 if (warn_format_nonliteral && !warn_format)
1552 warning ("-Wformat-nonliteral ignored without -Wformat");
1553 if (warn_format_security && !warn_format)
1554 warning ("-Wformat-security ignored without -Wformat");
1555 if (warn_missing_format_attribute && !warn_format)
1556 warning ("-Wmissing-format-attribute ignored without -Wformat");
1558 if (flag_preprocess_only)
1560 /* Open the output now. We must do so even if flag_no_output is
1561 on, because there may be other output than from the actual
1562 preprocessing (e.g. from -dM). */
1563 if (out_fname[0] == '\0')
1564 out_stream = stdout;
1566 out_stream = fopen (out_fname, "w");
1568 if (out_stream == NULL)
1570 fatal_error ("opening output file %s: %m", out_fname);
1574 init_pp_output (out_stream);
1580 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1584 cpp_get_callbacks (parse_in)->file_change = cb_file_change;
1586 /* NOTE: we use in_fname here, not the one supplied. */
1587 *pfilename = cpp_read_main_file (parse_in, in_fname);
1589 saved_lineno = input_line;
1592 /* If an error has occurred in cpplib, note it so we fail
1594 errorcount += cpp_errors (parse_in);
1596 return flag_preprocess_only;
1599 /* Front end initialization common to C, ObjC and C++. */
1603 input_line = saved_lineno;
1605 /* Set up preprocessor arithmetic. Must be done after call to
1606 c_common_nodes_and_builtins for type nodes to be good. */
1607 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1608 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1609 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1610 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1611 cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
1612 cpp_opts->EBCDIC = TARGET_EBCDIC;
1614 if (flag_preprocess_only)
1617 preprocess_file (parse_in);
1621 /* Has to wait until now so that cpplib has its hash table. */
1627 /* A thin wrapper around the real parser that initializes the
1628 integrated preprocessor after debug output has been initialized.
1629 Also, make sure the start_source_file debug hook gets called for
1630 the primary source file. */
1632 c_common_parse_file (set_yydebug)
1633 int set_yydebug ATTRIBUTE_UNUSED;
1636 yydebug = set_yydebug;
1638 warning ("YYDEBUG not defined");
1641 (*debug_hooks->start_source_file) (input_line, input_filename);
1645 free_parser_stacks ();
1648 /* Common finish hook for the C, ObjC and C++ front ends. */
1652 FILE *deps_stream = NULL;
1654 if (cpp_opts->deps.style != DEPS_NONE)
1656 /* If -M or -MM was seen without -MF, default output to the
1659 deps_stream = out_stream;
1662 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1664 fatal_error ("opening dependency file %s: %m", deps_file);
1668 /* For performance, avoid tearing down cpplib's internal structures
1669 with cpp_destroy (). */
1670 errorcount += cpp_finish (parse_in, deps_stream);
1672 if (deps_stream && deps_stream != out_stream
1673 && (ferror (deps_stream) || fclose (deps_stream)))
1674 fatal_error ("closing dependency file %s: %m", deps_file);
1676 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1677 fatal_error ("when writing output to %s: %m", out_fname);
1680 /* Either of two environment variables can specify output of
1681 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1682 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1683 and DEPS_TARGET is the target to mention in the deps. They also
1684 result in dependency information being appended to the output file
1685 rather than overwriting it, and like Sun's compiler
1686 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1688 check_deps_environment_vars ()
1692 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1694 cpp_opts->deps.style = DEPS_USER;
1697 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1700 cpp_opts->deps.style = DEPS_SYSTEM;
1701 cpp_opts->deps.ignore_main_file = true;
1707 /* Find the space before the DEPS_TARGET, if there is one. */
1708 char *s = strchr (spec, ' ');
1711 /* Let the caller perform MAKE quoting. */
1712 defer_opt (OPT_MT, s + 1);
1716 /* Command line -MF overrides environment variables and default. */
1724 /* Handle deferred command line switches. */
1726 handle_deferred_opts ()
1730 for (i = 0; i < deferred_count; i++)
1732 struct deferred_opt *opt = &deferred_opts[i];
1734 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1735 cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
1739 /* These settings are appropriate for GCC, but not necessarily so for
1740 cpplib as a library. */
1742 sanitize_cpp_opts ()
1744 /* If we don't know what style of dependencies to output, complain
1745 if any other dependency switches have been given. */
1746 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1747 error ("to generate dependencies you must specify either -M or -MM");
1749 /* -dM and dependencies suppress normal output; do it here so that
1750 the last -d[MDN] switch overrides earlier ones. */
1751 if (flag_dump_macros == 'M')
1754 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1755 -dM since at least glibc relies on -M -dM to work. */
1758 if (flag_dump_macros != 'M')
1759 flag_dump_macros = 0;
1760 flag_dump_includes = 0;
1763 cpp_opts->unsigned_char = !flag_signed_char;
1764 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1766 /* We want -Wno-long-long to override -pedantic -std=non-c99
1767 and/or -Wtraditional, whatever the ordering. */
1768 cpp_opts->warn_long_long
1769 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1772 /* Add include path with a prefix at the front of its name. */
1774 add_prefixed_path (suffix, chain)
1780 size_t prefix_len, suffix_len;
1782 suffix_len = strlen (suffix);
1783 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1784 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1786 path = xmalloc (prefix_len + suffix_len + 1);
1787 memcpy (path, prefix, prefix_len);
1788 memcpy (path + prefix_len, suffix, suffix_len);
1789 path[prefix_len + suffix_len] = '\0';
1791 add_path (path, chain, 0);
1794 /* Handle -D, -U, -A, -imacros, and the first -include. */
1798 if (!cpp_opts->preprocessed)
1802 cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
1803 cpp_init_builtins (parse_in, flag_hosted);
1804 c_cpp_builtins (parse_in);
1805 cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
1806 for (i = 0; i < deferred_count; i++)
1808 struct deferred_opt *opt = &deferred_opts[i];
1810 if (opt->code == OPT_D)
1811 cpp_define (parse_in, opt->arg);
1812 else if (opt->code == OPT_U)
1813 cpp_undef (parse_in, opt->arg);
1814 else if (opt->code == OPT_A)
1816 if (opt->arg[0] == '-')
1817 cpp_unassert (parse_in, opt->arg + 1);
1819 cpp_assert (parse_in, opt->arg);
1823 /* Handle -imacros after -D and -U. */
1824 for (i = 0; i < deferred_count; i++)
1826 struct deferred_opt *opt = &deferred_opts[i];
1828 if (opt->code == OPT_imacros
1829 && cpp_push_include (parse_in, opt->arg))
1830 cpp_scan_nooutput (parse_in);
1834 push_command_line_include ();
1837 /* Give CPP the next file given by -include, if any. */
1839 push_command_line_include ()
1841 if (cpp_opts->preprocessed)
1844 while (include_cursor < deferred_count)
1846 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1848 if (opt->code == OPT_include && cpp_push_include (parse_in, opt->arg))
1852 if (include_cursor == deferred_count)
1854 /* Restore the line map from <command line>. */
1855 cpp_change_file (parse_in, LC_RENAME, main_input_filename);
1856 /* -Wunused-macros should only warn about macros defined hereafter. */
1857 cpp_opts->warn_unused_macros = warn_unused_macros;
1862 /* File change callback. Has to handle -include files. */
1864 cb_file_change (pfile, new_map)
1865 cpp_reader *pfile ATTRIBUTE_UNUSED;
1866 const struct line_map *new_map;
1868 if (flag_preprocess_only)
1869 pp_file_change (new_map);
1871 fe_file_change (new_map);
1873 if (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))
1874 push_command_line_include ();
1877 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1878 extensions if ISO). There is no concept of gnu94. */
1880 set_std_c89 (c94, iso)
1883 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1886 flag_no_gnu_keywords = iso;
1887 flag_no_nonansi_builtin = iso;
1888 flag_noniso_default_format_attributes = !iso;
1891 flag_writable_strings = 0;
1894 /* Set the C 99 standard (without GNU extensions if ISO). */
1899 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1901 flag_no_nonansi_builtin = iso;
1902 flag_noniso_default_format_attributes = !iso;
1906 flag_writable_strings = 0;
1909 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1914 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1915 flag_no_gnu_keywords = iso;
1916 flag_no_nonansi_builtin = iso;
1917 flag_noniso_default_format_attributes = !iso;
1921 /* Handle setting implicit to ON. */
1927 warn_implicit_int = on;
1930 if (mesg_implicit_function_declaration != 2)
1931 mesg_implicit_function_declaration = 1;
1934 mesg_implicit_function_declaration = 0;
1937 /* Args to -d specify what to dump. Silently ignore
1938 unrecognized options; they may be aimed at toplev.c. */
1945 while ((c = *arg++) != '\0')
1948 case 'M': /* Dump macros only. */
1949 case 'N': /* Dump names. */
1950 case 'D': /* Dump definitions. */
1951 flag_dump_macros = c;
1955 flag_dump_includes = 1;
1960 /* Write a slash-separated list of languages in FLAGS to BUF. */
1962 write_langs (buf, flags)
1967 if (flags & CL_C_ONLY)
1969 if (flags & CL_OBJC_ONLY)
1973 strcat (buf, "ObjC");
1975 if (flags & CL_CXX_ONLY)
1979 strcat (buf, "C++");
1983 /* Complain that switch OPT_INDEX does not apply to this front end. */
1985 complain_wrong_lang (opt_index)
1988 char ok_langs[60], bad_langs[60];
1989 int ok_flags = cl_options[opt_index].flags;
1991 write_langs (ok_langs, ok_flags);
1992 write_langs (bad_langs, ~ok_flags);
1993 warning ("\"-%s\" is valid for %s but not for %s",
1994 cl_options[opt_index].opt_text, ok_langs, bad_langs);
1997 /* Handle --help output. */
2001 /* To keep the lines from getting too long for some compilers, limit
2002 to about 500 characters (6 lines) per chunk. */
2005 -include <file> Include the contents of <file> before other files\n\
2006 -imacros <file> Accept definition of macros in <file>\n\
2007 -iprefix <path> Specify <path> as a prefix for next two options\n\
2008 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
2009 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
2010 -isystem <dir> Add <dir> to the start of the system include path\n\
2013 -idirafter <dir> Add <dir> to the end of the system include path\n\
2014 -I <dir> Add <dir> to the end of the main include path\n\
2015 -I- Fine-grained include path control; see info docs\n\
2016 -nostdinc Do not search system include directories\n\
2017 (dirs specified with -isystem will still be used)\n\
2018 -nostdinc++ Do not search system include directories for C++\n\
2019 -o <file> Put output into <file>\n\
2022 -trigraphs Support ISO C trigraphs\n\
2023 -std=<std name> Specify the conformance standard; one of:\n\
2024 gnu89, gnu99, c89, c99, iso9899:1990,\n\
2025 iso9899:199409, iso9899:1999, c++98\n\
2026 -w Inhibit warning messages\n\
2027 -W[no-]trigraphs Warn if trigraphs are encountered\n\
2028 -W[no-]comment{s} Warn if one comment starts inside another\n\
2031 -W[no-]traditional Warn about features not present in traditional C\n\
2032 -W[no-]undef Warn if an undefined macro is used by #if\n\
2033 -W[no-]import Warn about the use of the #import directive\n\
2036 -W[no-]error Treat all warnings as errors\n\
2037 -W[no-]system-headers Do not suppress warnings from system headers\n\
2038 -W[no-]all Enable most preprocessor warnings\n\
2041 -M Generate make dependencies\n\
2042 -MM As -M, but ignore system header files\n\
2043 -MD Generate make dependencies and compile\n\
2044 -MMD As -MD, but ignore system header files\n\
2045 -MF <file> Write dependency output to the given file\n\
2046 -MG Treat missing header file as generated files\n\
2049 -MP Generate phony targets for all headers\n\
2050 -MQ <target> Add a MAKE-quoted target\n\
2051 -MT <target> Add an unquoted target\n\
2054 -D<macro> Define a <macro> with string '1' as its value\n\
2055 -D<macro>=<val> Define a <macro> with <val> as its value\n\
2056 -A<question>=<answer> Assert the <answer> to <question>\n\
2057 -A-<question>=<answer> Disable the <answer> to <question>\n\
2058 -U<macro> Undefine <macro> \n\
2059 -v Display the version number\n\
2062 -H Print the name of header files as they are used\n\
2063 -C Do not discard comments\n\
2064 -dM Display a list of macro definitions active at end\n\
2065 -dD Preserve macro definitions in output\n\
2066 -dN As -dD except that only the names are preserved\n\
2067 -dI Include #include directives in the output\n\
2070 -f[no-]preprocessed Treat the input file as already preprocessed\n\
2071 -ftabstop=<number> Distance between tab stops for column reporting\n\
2072 -isysroot <dir> Set <dir> to be the system root directory\n\
2073 -P Do not generate #line directives\n\
2074 -remap Remap file names when including files\n\
2075 --help Display this information\n\