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"
38 #ifndef TARGET_SYSTEM_ROOT
39 # define TARGET_SYSTEM_ROOT NULL
43 static cpp_options
*cpp_opts
;
46 static const char *in_fname
;
48 /* Filename and stream for preprocessed output. */
49 static const char *out_fname
;
50 static FILE *out_stream
;
52 /* Append dependencies to deps_file. */
53 static bool deps_append
;
55 /* If dependency switches (-MF etc.) have been given. */
56 static bool deps_seen
;
61 /* Dependency output file. */
62 static const char *deps_file
;
64 /* The prefix given by -iprefix, if any. */
65 static const char *iprefix
;
67 /* The system root, if any. Overridden by -isysroot. */
68 static const char *sysroot
= TARGET_SYSTEM_ROOT
;
70 /* Zero disables all standard directories for headers. */
71 static bool std_inc
= true;
73 /* Zero disables the C++-specific standard directories for headers. */
74 static bool std_cxx_inc
= true;
76 /* If the quote chain has been split by -I-. */
77 static bool quote_chain_split
;
79 /* Number of deferred options, deferred options array size. */
80 static size_t deferred_count
, deferred_size
;
82 static void missing_arg
PARAMS ((size_t));
83 static size_t find_opt
PARAMS ((const char *, int));
84 static void set_Wimplicit
PARAMS ((int));
85 static void complain_wrong_lang
PARAMS ((size_t));
86 static void write_langs
PARAMS ((char *, int));
87 static void print_help
PARAMS ((void));
88 static void handle_OPT_d
PARAMS ((const char *));
89 static void set_std_cxx98
PARAMS ((int));
90 static void set_std_c89
PARAMS ((int, int));
91 static void set_std_c99
PARAMS ((int));
92 static void check_deps_environment_vars
PARAMS ((void));
93 static void preprocess_file
PARAMS ((void));
94 static void handle_deferred_opts
PARAMS ((void));
95 static void sanitize_cpp_opts
PARAMS ((void));
96 static void add_prefixed_path
PARAMS ((const char *, size_t));
98 #ifndef STDC_0_IN_SYSTEM_HEADERS
99 #define STDC_0_IN_SYSTEM_HEADERS 0
102 #define CL_C_ONLY (1 << 0) /* Only C. */
103 #define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
104 #define CL_CXX_ONLY (1 << 2) /* Only C++. */
105 #define CL_OBJCXX_ONLY (1 << 3) /* Only ObjC++. */
106 #define CL_JOINED (1 << 4) /* If takes joined argument. */
107 #define CL_SEPARATE (1 << 5) /* If takes a separate argument. */
109 #define CL_ARG (CL_JOINED | CL_SEPARATE)
110 #define CL_C (CL_C_ONLY | CL_OBJC_ONLY)
111 #define CL_OBJC (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
112 #define CL_CXX (CL_CXX_ONLY | CL_OBJCXX_ONLY)
113 #define CL_ALL (CL_C | CL_CXX)
115 /* This is the list of all command line options, with the leading "-"
116 removed. It must be sorted in ASCII collating order. All options
117 beginning with "f" or "W" are implicitly assumed to take a "no-"
118 form; this form should not be listed. The variable "on" is true if
119 the positive form is given, otherwise it is false. If you don't
120 want to allow a "no-" form, your handler should reject "on" being
121 false by returning zero. See, for example, the handling of
124 If the user gives an option to a front end that doesn't support it,
125 an error is output, mentioning which front ends the option is valid
126 for. If you don't want this, you must accept it for all front
127 ends, and test for the front end in the option handler. See, for
128 example, the handling of -Wno-strict-prototypes for C++.
130 If you request an argument with CL_JOINED, CL_SEPARATE or their
131 combination CL_ARG, it is stored in the variable "arg", which is
132 guaranteed to be non-NULL and to not be an empty string. It points
133 to the argument either within the argv[] vector or within one of
134 that vector's strings, and so the text is permanent and copies need
135 not be made. Be sure to add an error message in missing_arg() if
136 the default is not appropriate. */
138 #define COMMAND_LINE_OPTIONS \
139 OPT("-help", CL_ALL, OPT__help) \
140 OPT("-output-pch=", CL_ALL | CL_ARG, OPT__output_pch) \
141 OPT("C", CL_ALL, OPT_C) \
142 OPT("CC", CL_ALL, OPT_CC) \
143 OPT("E", CL_ALL, OPT_E) \
144 OPT("H", CL_ALL, OPT_H) \
145 OPT("I", CL_ALL | CL_ARG, OPT_I) \
146 OPT("M", CL_ALL, OPT_M) \
147 OPT("MD", CL_ALL | CL_SEPARATE, OPT_MD) \
148 OPT("MF", CL_ALL | CL_ARG, OPT_MF) \
149 OPT("MG", CL_ALL, OPT_MG) \
150 OPT("MM", CL_ALL, OPT_MM) \
151 OPT("MMD", CL_ALL | CL_SEPARATE, OPT_MMD) \
152 OPT("MP", CL_ALL, OPT_MP) \
153 OPT("MQ", CL_ALL | CL_ARG, OPT_MQ) \
154 OPT("MT", CL_ALL | CL_ARG, OPT_MT) \
155 OPT("P", CL_ALL, OPT_P) \
156 OPT("Wabi", CL_CXX, OPT_Wabi) \
157 OPT("Wall", CL_ALL, OPT_Wall) \
158 OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
159 OPT("Wcast-qual", CL_ALL, OPT_Wcast_qual) \
160 OPT("Wchar-subscripts", CL_ALL, OPT_Wchar_subscripts) \
161 OPT("Wcomment", CL_ALL, OPT_Wcomment) \
162 OPT("Wcomments", CL_ALL, OPT_Wcomments) \
163 OPT("Wconversion", CL_ALL, OPT_Wconversion) \
164 OPT("Wctor-dtor-privacy", CL_CXX, OPT_Wctor_dtor_privacy) \
165 OPT("Wdeprecated", CL_CXX, OPT_Wdeprecated) \
166 OPT("Wdiv-by-zero", CL_C, OPT_Wdiv_by_zero) \
167 OPT("Weffc++", CL_CXX, OPT_Weffcxx) \
168 OPT("Wendif-labels", CL_ALL, OPT_Wendif_labels) \
169 OPT("Werror", CL_ALL, OPT_Werror) \
170 OPT("Werror-implicit-function-declaration", \
171 CL_C, OPT_Werror_implicit_function_decl) \
172 OPT("Wfloat-equal", CL_ALL, OPT_Wfloat_equal) \
173 OPT("Wformat", CL_ALL, OPT_Wformat) \
174 OPT("Wformat-extra-args", CL_ALL, OPT_Wformat_extra_args) \
175 OPT("Wformat-nonliteral", CL_ALL, OPT_Wformat_nonliteral) \
176 OPT("Wformat-security", CL_ALL, OPT_Wformat_security) \
177 OPT("Wformat-y2k", CL_ALL, OPT_Wformat_y2k) \
178 OPT("Wformat-zero-length", CL_C, OPT_Wformat_zero_length) \
179 OPT("Wformat=", CL_ALL | CL_JOINED, OPT_Wformat_eq) \
180 OPT("Wimplicit", CL_ALL, OPT_Wimplicit) \
181 OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
182 OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
183 OPT("Wimport", CL_ALL, OPT_Wimport) \
184 OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
185 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
186 OPT("Wmain", CL_C, OPT_Wmain) \
187 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
188 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
189 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
190 OPT("Wmissing-prototypes", CL_ALL, OPT_Wmissing_prototypes) \
191 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
192 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
193 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
194 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
195 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
196 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
197 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
198 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
199 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
200 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
201 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
202 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
203 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
204 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
205 OPT("Wselector", CL_OBJC, OPT_Wselector) \
206 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
207 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
208 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
209 OPT("Wstrict-prototypes", CL_ALL, OPT_Wstrict_prototypes) \
210 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
211 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
212 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
213 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
214 OPT("Wundeclared-selector", CL_OBJC, OPT_Wundeclared_selector) \
215 OPT("Wundef", CL_ALL, OPT_Wundef) \
216 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
217 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
218 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
219 OPT("ansi", CL_ALL, OPT_ansi) \
220 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
221 OPT("fabi-version=", CL_CXX | CL_JOINED, OPT_fabi_version) \
222 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
223 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
224 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
225 OPT("fasm", CL_ALL, OPT_fasm) \
226 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
227 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
228 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
229 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
230 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
231 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
232 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
233 OPT_fconstant_string_class) \
234 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
235 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
236 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
237 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
238 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
239 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
240 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
241 OPT("ffixed-form", CL_C, OPT_ffixed_form) \
242 OPT("ffixed-line-length-", CL_C | CL_JOINED, OPT_ffixed_line_length) \
243 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
244 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
245 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
246 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
247 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
248 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
249 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
250 OPT("fhosted", CL_C, OPT_fhosted) \
251 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
252 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
253 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
254 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
255 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
256 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
257 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
258 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
259 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
260 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
261 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
262 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
263 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
264 OPT("fpch-deps", CL_ALL, OPT_fpch_deps) \
265 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
266 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
267 OPT("frepo", CL_CXX, OPT_frepo) \
268 OPT("frtti", CL_CXX, OPT_frtti) \
269 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
270 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
271 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
272 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
273 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
274 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
275 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
276 OPT("fstats", CL_CXX, OPT_fstats) \
277 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
278 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
279 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
280 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
281 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
282 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
283 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
284 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
285 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
286 OPT("fweak", CL_CXX, OPT_fweak) \
287 OPT("fxref", CL_CXX, OPT_fxref) \
288 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
289 OPT("idirafter", CL_ALL | CL_ARG, OPT_idirafter) \
290 OPT("iprefix", CL_ALL | CL_ARG, OPT_iprefix) \
291 OPT("isysroot", CL_ALL | CL_ARG, OPT_isysroot) \
292 OPT("isystem", CL_ALL | CL_ARG, OPT_isystem) \
293 OPT("iwithprefix", CL_ALL | CL_ARG, OPT_iwithprefix) \
294 OPT("iwithprefixbefore", CL_ALL | CL_ARG, OPT_iwithprefixbefore) \
295 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
296 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
297 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
298 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
299 OPT("o", CL_ALL | CL_ARG, OPT_o) \
300 OPT("pedantic", CL_ALL, OPT_pedantic) \
301 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
302 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
303 OPT("remap", CL_ALL, OPT_remap) \
304 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
305 OPT("std=c89", CL_C, OPT_std_c89) \
306 OPT("std=c99", CL_C, OPT_std_c99) \
307 OPT("std=c9x", CL_C, OPT_std_c9x) \
308 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
309 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
310 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
311 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
312 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
313 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
314 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
315 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
316 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
317 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
318 OPT("undef", CL_ALL, OPT_undef) \
319 OPT("v", CL_ALL, OPT_v) \
320 OPT("w", CL_ALL, OPT_w)
322 #define OPT(text, flags, code) code,
332 const char *opt_text
;
333 unsigned char opt_len
;
335 ENUM_BITFIELD (opt_code
) opt_code
: 2 * CHAR_BIT
;
338 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
340 static struct cl_option cl_options
[] =
342 static const struct cl_option cl_options
[] =
348 #undef COMMAND_LINE_OPTIONS
350 /* Holds switches parsed by c_common_decode_option (), but whose
351 handling is deferred to c_common_post_options (). */
352 static void defer_opt
PARAMS ((enum opt_code
, const char *));
353 static struct deferred_opt
361 static int opt_comp
PARAMS ((const void *, const void *));
363 /* Run-time sorting of options array. */
368 return strcmp (((struct cl_option
*) p1
)->opt_text
,
369 ((struct cl_option
*) p2
)->opt_text
);
373 /* Complain that switch OPT_INDEX expects an argument but none was
376 missing_arg (opt_index
)
379 const char *opt_text
= cl_options
[opt_index
].opt_text
;
381 switch (cl_options
[opt_index
].opt_code
)
383 case OPT__output_pch
:
386 case OPT_fabi_version
:
389 case OPT_fname_mangling
:
391 case OPT_ftemplate_depth
:
393 case OPT_iwithprefix
:
394 case OPT_iwithprefixbefore
:
396 error ("missing argument to \"-%s\"", opt_text
);
399 case OPT_fconstant_string_class
:
400 error ("no class name specified with \"-%s\"", opt_text
);
407 error ("missing path after \"-%s\"", opt_text
);
414 error ("missing filename after \"-%s\"", opt_text
);
419 error ("missing target after \"-%s\"", opt_text
);
424 /* Perform a binary search to find which option the command-line INPUT
425 matches. Returns its index in the option array, and N_OPTS on
428 Complications arise since some options can be suffixed with an
429 argument, and multiple complete matches can occur, e.g. -pedantic
430 and -pedantic-errors. Also, some options are only accepted by some
431 languages. If a switch matches for a different language and
432 doesn't match any alternatives for the true front end, the index of
433 the matched switch is returned anyway. The caller should check for
436 find_opt (input
, lang_flag
)
442 size_t result
= N_OPTS
;
452 opt_len
= cl_options
[md
].opt_len
;
453 comp
= strncmp (input
, cl_options
[md
].opt_text
, opt_len
);
461 /* The switch matches. It it an exact match? */
462 if (input
[opt_len
] == '\0')
468 /* If the switch takes no arguments this is not a proper
469 match, so we continue the search (e.g. input="stdc++"
470 match was "stdc"). */
471 if (!(cl_options
[md
].flags
& CL_JOINED
))
474 /* Is this switch valid for this front end? */
475 if (!(cl_options
[md
].flags
& lang_flag
))
477 /* If subsequently we don't find a better match,
478 return this and let the caller report it as a bad
484 /* Two scenarios remain: we have the switch's argument,
485 or we match a longer option. This can happen with
486 -iwithprefix and -withprefixbefore. The longest
487 possible option match succeeds.
489 Scan forwards, and return an exact match. Otherwise
490 return the longest valid option-accepting match (mx).
491 This loops at most twice with current options. */
493 for (md
= md
+ 1; md
< (size_t) N_OPTS
; md
++)
495 opt_len
= cl_options
[md
].opt_len
;
496 if (strncmp (input
, cl_options
[md
].opt_text
, opt_len
))
498 if (input
[opt_len
] == '\0')
500 if (cl_options
[md
].flags
& lang_flag
501 && cl_options
[md
].flags
& CL_JOINED
)
513 /* Defer option CODE with argument ARG. */
515 defer_opt (code
, arg
)
519 /* FIXME: this should be in c_common_init_options, which should take
523 extern int save_argc
;
524 deferred_size
= save_argc
;
525 deferred_opts
= (struct deferred_opt
*)
526 xmalloc (deferred_size
* sizeof (struct deferred_opt
));
529 if (deferred_count
== deferred_size
)
532 deferred_opts
[deferred_count
].code
= code
;
533 deferred_opts
[deferred_count
].arg
= arg
;
537 /* Common initialization before parsing options. */
539 c_common_init_options (lang
)
540 enum c_language_kind lang
;
543 /* For non-ASCII hosts, the cl_options array needs to be sorted at
545 qsort (cl_options
, N_OPTS
, sizeof (struct cl_option
), opt_comp
);
551 for (i
= 1; i
< N_OPTS
; i
++)
552 if (strcmp (cl_options
[i
- 1].opt_text
, cl_options
[i
].opt_text
) >= 0)
553 error ("options array incorrectly sorted: %s is before %s",
554 cl_options
[i
- 1].opt_text
, cl_options
[i
].opt_text
);
559 parse_in
= cpp_create_reader (lang
== clk_c
? CLK_GNUC89
: CLK_GNUCXX
);
560 cpp_opts
= cpp_get_options (parse_in
);
564 flag_const_strings
= (lang
== clk_cplusplus
);
565 warn_pointer_arith
= (lang
== clk_cplusplus
);
567 warn_sign_compare
= -1;
570 /* Handle one command-line option in (argc, argv).
571 Can be called multiple times, to handle multiple sets of options.
572 Returns number of strings consumed. */
574 c_common_decode_option (argc
, argv
)
578 static const int lang_flags
[] = {CL_C_ONLY
, CL_C
, CL_CXX_ONLY
, CL_CXX
};
580 const char *opt
, *arg
= 0;
583 int result
, lang_flag
;
584 const struct cl_option
*option
;
589 /* Interpret "-" or a non-switch as a file name. */
590 if (opt
[0] != '-' || opt
[1] == '\0')
598 error ("too many filenames given. Type %s --help for usage",
606 /* Drop the "no-" from negative switches. */
607 if ((opt
[1] == 'W' || opt
[1] == 'f')
608 && opt
[2] == 'n' && opt
[3] == 'o' && opt
[4] == '-')
610 size_t len
= strlen (opt
) - 3;
612 dup
= xmalloc (len
+ 1);
615 memcpy (dup
+ 2, opt
+ 5, len
- 2 + 1);
620 result
= cpp_handle_option (parse_in
, argc
, argv
);
623 lang_flag
= lang_flags
[(c_language
<< 1) + flag_objc
];
624 opt_index
= find_opt (opt
+ 1, lang_flag
);
625 if (opt_index
== N_OPTS
)
629 option
= &cl_options
[opt_index
];
631 /* Sort out any argument the switch takes. */
632 if (option
->flags
& CL_ARG
)
634 if (option
->flags
& CL_JOINED
)
636 /* Have arg point to the original switch. This is because
637 some code, such as disable_builtin_function, expects its
638 argument to be persistent until the program exits. */
639 arg
= argv
[0] + cl_options
[opt_index
].opt_len
+ 1;
641 arg
+= strlen ("no-");
644 /* If we don't have an argument, and CL_SEPARATE, try the next
645 argument in the vector. */
646 if (!arg
|| (*arg
== '\0' && option
->flags
& CL_SEPARATE
))
652 if (!arg
|| *arg
== '\0')
654 missing_arg (opt_index
);
660 /* Complain about the wrong language after we've swallowed any
661 necessary extra argument. Eventually make this a hard error
662 after the call to find_opt, and return argc. */
663 if (!(cl_options
[opt_index
].flags
& lang_flag
))
665 complain_wrong_lang (opt_index
);
669 switch (code
= option
->opt_code
)
671 case N_OPTS
: /* Shut GCC up. */
678 case OPT__output_pch
:
683 cpp_opts
->discard_comments
= 0;
687 cpp_opts
->discard_comments
= 0;
688 cpp_opts
->discard_comments_in_macro_exp
= 0;
692 flag_preprocess_only
= 1;
696 cpp_opts
->print_include_names
= 1;
700 if (strcmp (arg
, "-"))
701 add_path (xstrdup (arg
), BRACKET
, 0);
704 if (quote_chain_split
)
705 error ("-I- specified twice");
706 quote_chain_split
= true;
707 split_quote_chain ();
713 /* When doing dependencies with -M or -MM, suppress normal
714 preprocessed output, but still do -dM etc. as software
715 depends on this. Preprocessed output does occur if -MD, -MMD
716 or environment var dependency generation is used. */
717 cpp_opts
->deps
.style
= (code
== OPT_M
? DEPS_SYSTEM
: DEPS_USER
);
718 cpp_opts
->no_output
= 1;
719 cpp_opts
->inhibit_warnings
= 1;
724 cpp_opts
->deps
.style
= (code
== OPT_MD
? DEPS_SYSTEM
: DEPS_USER
);
735 cpp_opts
->deps
.missing_files
= true;
740 cpp_opts
->deps
.phony_targets
= true;
746 defer_opt (code
, arg
);
750 cpp_opts
->no_line_commands
= 1;
761 warn_char_subscripts
= on
;
762 warn_missing_braces
= on
;
763 warn_parentheses
= on
;
764 warn_return_type
= on
;
765 warn_sequence_point
= on
; /* Was C only. */
766 warn_sign_compare
= on
; /* Was C++ only. */
768 warn_strict_aliasing
= on
;
770 /* Only warn about unknown pragmas that are not in system
772 warn_unknown_pragmas
= on
;
774 /* We save the value of warn_uninitialized, since if they put
775 -Wuninitialized on the command line, we need to generate a
776 warning about not using it without also specifying -O. */
777 if (warn_uninitialized
!= 1)
778 warn_uninitialized
= (on
? 2 : 0);
780 if (c_language
== clk_c
)
781 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
782 can turn it off only if it's not explicit. */
786 /* C++-specific warnings. */
787 warn_ctor_dtor_privacy
= on
;
790 warn_nontemplate_friend
= on
;
793 cpp_opts
->warn_trigraphs
= on
;
794 cpp_opts
->warn_comments
= on
;
795 cpp_opts
->warn_num_sign_change
= on
;
796 cpp_opts
->warn_multichar
= on
; /* Was C++ only. */
799 case OPT_Wbad_function_cast
:
800 warn_bad_function_cast
= on
;
807 case OPT_Wchar_subscripts
:
808 warn_char_subscripts
= on
;
813 cpp_opts
->warn_comments
= on
;
816 case OPT_Wconversion
:
817 warn_conversion
= on
;
820 case OPT_Wctor_dtor_privacy
:
821 warn_ctor_dtor_privacy
= on
;
824 case OPT_Wdeprecated
:
825 warn_deprecated
= on
;
826 cpp_opts
->warn_deprecated
= on
;
829 case OPT_Wdiv_by_zero
:
830 warn_div_by_zero
= on
;
837 case OPT_Wendif_labels
:
838 cpp_opts
->warn_endif_labels
= on
;
842 cpp_opts
->warnings_are_errors
= on
;
845 case OPT_Werror_implicit_function_decl
:
849 mesg_implicit_function_declaration
= 2;
852 case OPT_Wfloat_equal
:
853 warn_float_equal
= on
;
861 set_Wformat (atoi (arg
));
864 case OPT_Wformat_extra_args
:
865 warn_format_extra_args
= on
;
868 case OPT_Wformat_nonliteral
:
869 warn_format_nonliteral
= on
;
872 case OPT_Wformat_security
:
873 warn_format_security
= on
;
876 case OPT_Wformat_y2k
:
877 warn_format_y2k
= on
;
880 case OPT_Wformat_zero_length
:
881 warn_format_zero_length
= on
;
888 case OPT_Wimplicit_function_decl
:
889 mesg_implicit_function_declaration
= on
;
892 case OPT_Wimplicit_int
:
893 warn_implicit_int
= on
;
897 cpp_opts
->warn_import
= on
;
900 case OPT_Winvalid_pch
:
901 cpp_opts
->warn_invalid_pch
= on
;
915 case OPT_Wmissing_braces
:
916 warn_missing_braces
= on
;
919 case OPT_Wmissing_declarations
:
920 warn_missing_declarations
= on
;
923 case OPT_Wmissing_format_attribute
:
924 warn_missing_format_attribute
= on
;
927 case OPT_Wmissing_prototypes
:
928 warn_missing_prototypes
= on
;
932 cpp_opts
->warn_multichar
= on
;
935 case OPT_Wnested_externs
:
936 warn_nested_externs
= on
;
939 case OPT_Wnon_template_friend
:
940 warn_nontemplate_friend
= on
;
943 case OPT_Wnon_virtual_dtor
:
951 case OPT_Wold_style_cast
:
952 warn_old_style_cast
= on
;
955 case OPT_Woverloaded_virtual
:
956 warn_overloaded_virtual
= on
;
959 case OPT_Wparentheses
:
960 warn_parentheses
= on
;
963 case OPT_Wpmf_conversions
:
967 case OPT_Wpointer_arith
:
968 warn_pointer_arith
= on
;
979 case OPT_Wredundant_decls
:
980 warn_redundant_decls
= on
;
987 case OPT_Wreturn_type
:
988 warn_return_type
= on
;
991 case OPT_Wsequence_point
:
992 warn_sequence_point
= on
;
995 case OPT_Wsign_compare
:
996 warn_sign_compare
= on
;
999 case OPT_Wsign_promo
:
1000 warn_sign_promo
= on
;
1003 case OPT_Wstrict_prototypes
:
1004 if (!on
&& c_language
== clk_cplusplus
)
1005 warning ("-Wno-strict-prototypes is not supported in C++");
1007 warn_strict_prototypes
= on
;
1014 case OPT_Wsystem_headers
:
1015 cpp_opts
->warn_system_headers
= on
;
1018 case OPT_Wtraditional
:
1019 warn_traditional
= on
;
1020 cpp_opts
->warn_traditional
= on
;
1023 case OPT_Wtrigraphs
:
1024 cpp_opts
->warn_trigraphs
= on
;
1027 case OPT_Wundeclared_selector
:
1028 warn_undeclared_selector
= on
;
1032 cpp_opts
->warn_undef
= on
;
1035 case OPT_Wunknown_pragmas
:
1036 /* Set to greater than 1, so that even unknown pragmas in
1037 system headers will be warned about. */
1038 warn_unknown_pragmas
= on
* 2;
1041 case OPT_Wunused_macros
:
1042 cpp_opts
->warn_unused_macros
= on
;
1045 case OPT_Wwrite_strings
:
1046 if (c_language
== clk_c
)
1047 flag_const_strings
= on
;
1049 warn_write_strings
= on
;
1053 if (c_language
== clk_c
)
1054 set_std_c89 (false, true);
1056 set_std_cxx98 (true);
1063 case OPT_fcond_mismatch
:
1064 if (c_language
== clk_c
)
1066 flag_cond_mismatch
= on
;
1071 case OPT_fall_virtual
:
1072 case OPT_fenum_int_equiv
:
1073 case OPT_fguiding_decls
:
1074 case OPT_fhonor_std
:
1075 case OPT_fhuge_objects
:
1076 case OPT_flabels_ok
:
1077 case OPT_fname_mangling
:
1079 case OPT_fnonnull_objects
:
1081 case OPT_fstrict_prototype
:
1082 case OPT_fthis_is_variable
:
1083 case OPT_fvtable_thunks
:
1085 warning ("switch \"%s\" is no longer supported", argv
[0]);
1088 case OPT_fabi_version
:
1089 flag_abi_version
= read_integral_parameter (arg
, argv
[0], 1);
1092 case OPT_faccess_control
:
1093 flag_access_control
= on
;
1096 case OPT_falt_external_templates
:
1097 flag_alt_external_templates
= on
;
1099 flag_external_templates
= true;
1101 warning ("switch \"%s\" is deprecated, please see documentation for details", argv
[0]);
1109 flag_no_builtin
= !on
;
1116 disable_builtin_function (arg
);
1119 case OPT_fdollars_in_identifiers
:
1120 dollars_in_ident
= on
;
1124 if (!on
|| !dump_switch_p (argv
[0] + strlen ("-f")))
1128 case OPT_ffreestanding
:
1130 /* Fall through... */
1133 flag_no_builtin
= !on
;
1134 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
1135 if (!on
&& warn_main
== 2)
1139 case OPT_fshort_double
:
1140 flag_short_double
= on
;
1143 case OPT_fshort_enums
:
1144 flag_short_enums
= on
;
1147 case OPT_fshort_wchar
:
1148 flag_short_wchar
= on
;
1151 case OPT_fsigned_bitfields
:
1152 flag_signed_bitfields
= on
;
1153 explicit_flag_signed_bitfields
= 1;
1156 case OPT_fsigned_char
:
1157 flag_signed_char
= on
;
1160 case OPT_funsigned_bitfields
:
1161 flag_signed_bitfields
= !on
;
1162 explicit_flag_signed_bitfields
= 1;
1165 case OPT_funsigned_char
:
1166 flag_signed_char
= !on
;
1169 case OPT_fcheck_new
:
1170 flag_check_new
= on
;
1173 case OPT_fconserve_space
:
1174 flag_conserve_space
= on
;
1177 case OPT_fconst_strings
:
1178 flag_const_strings
= on
;
1181 case OPT_fconstant_string_class
:
1182 constant_string_class_name
= arg
;
1185 case OPT_fdefault_inline
:
1186 flag_default_inline
= on
;
1189 case OPT_felide_constructors
:
1190 flag_elide_constructors
= on
;
1193 case OPT_fenforce_eh_specs
:
1194 flag_enforce_eh_specs
= on
;
1197 case OPT_fexternal_templates
:
1198 flag_external_templates
= on
;
1201 case OPT_ffixed_form
:
1202 case OPT_ffixed_line_length
:
1203 /* Fortran front end options ignored when preprocessing only. */
1204 if (flag_preprocess_only
)
1208 case OPT_ffor_scope
:
1209 flag_new_for_scope
= on
;
1212 case OPT_fgnu_keywords
:
1213 flag_no_gnu_keywords
= !on
;
1216 case OPT_fgnu_runtime
:
1217 flag_next_runtime
= !on
;
1220 case OPT_fhandle_exceptions
:
1221 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
1222 flag_exceptions
= on
;
1225 case OPT_fimplement_inlines
:
1226 flag_implement_inlines
= on
;
1229 case OPT_fimplicit_inline_templates
:
1230 flag_implicit_inline_templates
= on
;
1233 case OPT_fimplicit_templates
:
1234 flag_implicit_templates
= on
;
1237 case OPT_fms_extensions
:
1238 flag_ms_extensions
= on
;
1241 case OPT_fnext_runtime
:
1242 flag_next_runtime
= on
;
1245 case OPT_fnonansi_builtins
:
1246 flag_no_nonansi_builtin
= !on
;
1249 case OPT_foperator_names
:
1250 cpp_opts
->operator_names
= on
;
1253 case OPT_foptional_diags
:
1254 flag_optional_diags
= on
;
1258 cpp_opts
->restore_pch_deps
= on
;
1261 case OPT_fpermissive
:
1262 flag_permissive
= on
;
1265 case OPT_fpreprocessed
:
1266 cpp_opts
->preprocessed
= on
;
1270 flag_use_repository
= on
;
1272 flag_implicit_templates
= 0;
1279 case OPT_fshow_column
:
1280 cpp_opts
->show_column
= on
;
1284 flag_detailed_statistics
= on
;
1288 /* Don't recognize -fno-tabstop=. */
1292 /* It is documented that we silently ignore silly values. */
1295 long tabstop
= strtol (arg
, &endptr
, 10);
1296 if (*endptr
== '\0' && tabstop
>= 1 && tabstop
<= 100)
1297 cpp_opts
->tabstop
= tabstop
;
1301 case OPT_ftemplate_depth
:
1302 max_tinst_depth
= read_integral_parameter (arg
, argv
[0], 0);
1305 case OPT_fvtable_gc
:
1306 flag_vtable_gc
= on
;
1309 case OPT_fuse_cxa_atexit
:
1310 flag_use_cxa_atexit
= on
;
1318 flag_gen_declaration
= 1;
1322 add_path (xstrdup (arg
), AFTER
, 0);
1334 add_path (xstrdup (arg
), SYSTEM
, 0);
1337 case OPT_iwithprefix
:
1338 add_prefixed_path (arg
, SYSTEM
);
1341 case OPT_iwithprefixbefore
:
1342 add_prefixed_path (arg
, BRACKET
);
1346 cpp_set_lang (parse_in
, CLK_ASM
);
1357 case OPT_nostdincplusplus
:
1358 std_cxx_inc
= false;
1366 error ("output filename specified twice");
1371 /* We need to handle the -pedantic switches here, rather than in
1372 c_common_post_options, so that a subsequent -Wno-endif-labels
1373 is not overridden. */
1374 case OPT_pedantic_errors
:
1375 cpp_opts
->pedantic_errors
= 1;
1378 cpp_opts
->pedantic
= 1;
1379 cpp_opts
->warn_endif_labels
= 1;
1382 case OPT_print_objc_runtime_info
:
1383 print_struct_values
= 1;
1387 cpp_opts
->remap
= 1;
1390 case OPT_std_cplusplus98
:
1391 case OPT_std_gnuplusplus98
:
1392 set_std_cxx98 (code
== OPT_std_cplusplus98
/* ISO */);
1396 case OPT_std_iso9899_1990
:
1397 case OPT_std_iso9899_199409
:
1398 set_std_c89 (code
== OPT_std_iso9899_199409
/* c94 */, true /* ISO */);
1402 set_std_c89 (false /* c94 */, false /* ISO */);
1407 case OPT_std_iso9899_1999
:
1408 case OPT_std_iso9899_199x
:
1409 set_std_c99 (true /* ISO */);
1414 set_std_c99 (false /* ISO */);
1418 cpp_opts
->trigraphs
= 1;
1421 case OPT_traditional_cpp
:
1422 cpp_opts
->traditional
= 1;
1430 cpp_opts
->inhibit_warnings
= 1;
1444 /* Post-switch processing. */
1446 c_common_post_options ()
1448 /* Canonicalize the input and output filenames. */
1449 if (in_fname
== NULL
|| !strcmp (in_fname
, "-"))
1452 if (out_fname
== NULL
|| !strcmp (out_fname
, "-"))
1455 if (cpp_opts
->deps
.style
== DEPS_NONE
)
1456 check_deps_environment_vars ();
1458 handle_deferred_opts ();
1460 sanitize_cpp_opts ();
1462 register_include_chains (parse_in
, sysroot
, iprefix
,
1463 std_inc
, std_cxx_inc
&& c_language
== clk_cplusplus
,
1466 flag_inline_trees
= 1;
1468 /* Use tree inlining if possible. Function instrumentation is only
1469 done in the RTL level, so we disable tree inlining. */
1470 if (! flag_instrument_function_entry_exit
)
1472 if (!flag_no_inline
)
1474 if (flag_inline_functions
)
1476 flag_inline_trees
= 2;
1477 flag_inline_functions
= 0;
1481 /* Special format checking options don't work without -Wformat; warn if
1483 if (warn_format_y2k
&& !warn_format
)
1484 warning ("-Wformat-y2k ignored without -Wformat");
1485 if (warn_format_extra_args
&& !warn_format
)
1486 warning ("-Wformat-extra-args ignored without -Wformat");
1487 if (warn_format_zero_length
&& !warn_format
)
1488 warning ("-Wformat-zero-length ignored without -Wformat");
1489 if (warn_format_nonliteral
&& !warn_format
)
1490 warning ("-Wformat-nonliteral ignored without -Wformat");
1491 if (warn_format_security
&& !warn_format
)
1492 warning ("-Wformat-security ignored without -Wformat");
1493 if (warn_missing_format_attribute
&& !warn_format
)
1494 warning ("-Wmissing-format-attribute ignored without -Wformat");
1496 /* If an error has occurred in cpplib, note it so we fail
1498 errorcount
+= cpp_errors (parse_in
);
1500 return flag_preprocess_only
;
1503 /* Preprocess the input file to out_stream. */
1507 /* Open the output now. We must do so even if no_output is on,
1508 because there may be other output than from the actual
1509 preprocessing (e.g. from -dM). */
1510 if (out_fname
[0] == '\0')
1511 out_stream
= stdout
;
1513 out_stream
= fopen (out_fname
, "w");
1515 if (out_stream
== NULL
)
1516 fatal_io_error ("opening output file %s", out_fname
);
1518 cpp_preprocess_file (parse_in
, in_fname
, out_stream
);
1521 /* Front end initialization common to C, ObjC and C++. */
1523 c_common_init (filename
)
1524 const char *filename
;
1526 /* Set up preprocessor arithmetic. Must be done after call to
1527 c_common_nodes_and_builtins for type nodes to be good. */
1528 cpp_opts
->precision
= TYPE_PRECISION (intmax_type_node
);
1529 cpp_opts
->char_precision
= TYPE_PRECISION (char_type_node
);
1530 cpp_opts
->int_precision
= TYPE_PRECISION (integer_type_node
);
1531 cpp_opts
->wchar_precision
= TYPE_PRECISION (wchar_type_node
);
1532 cpp_opts
->unsigned_wchar
= TREE_UNSIGNED (wchar_type_node
);
1534 /* Register preprocessor built-ins before calls to
1536 cpp_get_callbacks (parse_in
)->register_builtins
= cb_register_builtins
;
1538 /* NULL is passed up to toplev.c and we exit quickly. */
1539 if (flag_preprocess_only
)
1545 /* Do this before initializing pragmas, as then cpplib's hash table
1546 has been set up. NOTE: we are using our own file name here, not
1547 the one supplied. */
1548 filename
= init_c_lex (in_fname
);
1555 /* Common finish hook for the C, ObjC and C++ front ends. */
1559 FILE *deps_stream
= NULL
;
1561 if (cpp_opts
->deps
.style
!= DEPS_NONE
)
1563 /* If -M or -MM was seen without -MF, default output to the
1566 deps_stream
= out_stream
;
1569 deps_stream
= fopen (deps_file
, deps_append
? "a": "w");
1571 fatal_io_error ("opening dependency file %s", deps_file
);
1575 /* For performance, avoid tearing down cpplib's internal structures
1576 with cpp_destroy (). */
1577 errorcount
+= cpp_finish (parse_in
, deps_stream
);
1579 if (deps_stream
&& deps_stream
!= out_stream
1580 && (ferror (deps_stream
) || fclose (deps_stream
)))
1581 fatal_io_error ("closing dependency file %s", deps_file
);
1583 if (out_stream
&& (ferror (out_stream
) || fclose (out_stream
)))
1584 fatal_io_error ("when writing output to %s", out_fname
);
1587 /* Either of two environment variables can specify output of
1588 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1589 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1590 and DEPS_TARGET is the target to mention in the deps. They also
1591 result in dependency information being appended to the output file
1592 rather than overwriting it, and like Sun's compiler
1593 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1595 check_deps_environment_vars ()
1599 GET_ENVIRONMENT (spec
, "DEPENDENCIES_OUTPUT");
1601 cpp_opts
->deps
.style
= DEPS_USER
;
1604 GET_ENVIRONMENT (spec
, "SUNPRO_DEPENDENCIES");
1607 cpp_opts
->deps
.style
= DEPS_SYSTEM
;
1608 cpp_opts
->deps
.ignore_main_file
= true;
1614 /* Find the space before the DEPS_TARGET, if there is one. */
1615 char *s
= strchr (spec
, ' ');
1618 /* Let the caller perform MAKE quoting. */
1619 defer_opt (OPT_MT
, s
+ 1);
1623 /* Command line -MF overrides environment variables and default. */
1631 /* Handle deferred command line switches. */
1633 handle_deferred_opts ()
1637 for (i
= 0; i
< deferred_count
; i
++)
1639 struct deferred_opt
*opt
= &deferred_opts
[i
];
1645 cpp_add_dependency_target (parse_in
, opt
->arg
, opt
->code
== OPT_MQ
);
1653 free (deferred_opts
);
1656 /* These settings are appropriate for GCC, but not necessarily so for
1657 cpplib as a library. */
1659 sanitize_cpp_opts ()
1661 /* If we don't know what style of dependencies to output, complain
1662 if any other dependency switches have been given. */
1663 if (deps_seen
&& cpp_opts
->deps
.style
== DEPS_NONE
)
1664 error ("to generate dependencies you must specify either -M or -MM");
1666 /* -dM and dependencies suppress normal output; do it here so that
1667 the last -d[MDN] switch overrides earlier ones. */
1668 if (cpp_opts
->dump_macros
== dump_only
)
1669 cpp_opts
->no_output
= 1;
1671 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1672 -dM since at least glibc relies on -M -dM to work. */
1673 if (cpp_opts
->no_output
)
1675 if (cpp_opts
->dump_macros
!= dump_only
)
1676 cpp_opts
->dump_macros
= dump_none
;
1677 cpp_opts
->dump_includes
= 0;
1680 cpp_opts
->unsigned_char
= !flag_signed_char
;
1681 cpp_opts
->stdc_0_in_system_headers
= STDC_0_IN_SYSTEM_HEADERS
;
1683 /* We want -Wno-long-long to override -pedantic -std=non-c99
1684 and/or -Wtraditional, whatever the ordering. */
1685 cpp_opts
->warn_long_long
1686 = warn_long_long
&& ((!flag_isoc99
&& pedantic
) || warn_traditional
);
1689 /* Add include path with a prefix at the front of its name. */
1691 add_prefixed_path (suffix
, chain
)
1697 prefix
= iprefix
? iprefix
: cpp_GCC_INCLUDE_DIR
;
1698 add_path (concat (prefix
, suffix
), chain
, 0);
1701 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1702 extensions if ISO). There is no concept of gnu94. */
1704 set_std_c89 (c94
, iso
)
1707 cpp_set_lang (parse_in
, c94
? CLK_STDC94
: iso
? CLK_STDC89
: CLK_GNUC89
);
1710 flag_no_gnu_keywords
= iso
;
1711 flag_no_nonansi_builtin
= iso
;
1712 flag_noniso_default_format_attributes
= !iso
;
1715 flag_writable_strings
= 0;
1718 /* Set the C 99 standard (without GNU extensions if ISO). */
1723 cpp_set_lang (parse_in
, iso
? CLK_STDC99
: CLK_GNUC99
);
1725 flag_no_nonansi_builtin
= iso
;
1726 flag_noniso_default_format_attributes
= !iso
;
1730 flag_writable_strings
= 0;
1733 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1738 cpp_set_lang (parse_in
, iso
? CLK_CXX98
: CLK_GNUCXX
);
1739 flag_no_gnu_keywords
= iso
;
1740 flag_no_nonansi_builtin
= iso
;
1741 flag_noniso_default_format_attributes
= !iso
;
1745 /* Handle setting implicit to ON. */
1751 warn_implicit_int
= on
;
1754 if (mesg_implicit_function_declaration
!= 2)
1755 mesg_implicit_function_declaration
= 1;
1758 mesg_implicit_function_declaration
= 0;
1761 /* Args to -d specify what to dump. Silently ignore
1762 unrecognized options; they may be aimed at toplev.c. */
1769 while ((c
= *arg
++) != '\0')
1773 cpp_opts
->dump_macros
= dump_only
;
1777 cpp_opts
->dump_macros
= dump_names
;
1781 cpp_opts
->dump_macros
= dump_definitions
;
1785 cpp_opts
->dump_includes
= 1;
1790 /* Write a slash-separated list of languages in FLAGS to BUF. */
1792 write_langs (buf
, flags
)
1797 if (flags
& CL_C_ONLY
)
1799 if (flags
& CL_OBJC_ONLY
)
1803 strcat (buf
, "ObjC");
1805 if (flags
& CL_CXX_ONLY
)
1809 strcat (buf
, "C++");
1813 /* Complain that switch OPT_INDEX does not apply to this front end. */
1815 complain_wrong_lang (opt_index
)
1818 char ok_langs
[60], bad_langs
[60];
1819 int ok_flags
= cl_options
[opt_index
].flags
;
1821 write_langs (ok_langs
, ok_flags
);
1822 write_langs (bad_langs
, ~ok_flags
);
1823 warning ("\"-%s\" is valid for %s but not for %s",
1824 cl_options
[opt_index
].opt_text
, ok_langs
, bad_langs
);
1827 /* Handle --help output. */
1831 /* To keep the lines from getting too long for some compilers, limit
1832 to about 500 characters (6 lines) per chunk. */
1835 -include <file> Include the contents of <file> before other files\n\
1836 -imacros <file> Accept definition of macros in <file>\n\
1837 -iprefix <path> Specify <path> as a prefix for next two options\n\
1838 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1839 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1840 -isystem <dir> Add <dir> to the start of the system include path\n\
1843 -idirafter <dir> Add <dir> to the end of the system include path\n\
1844 -I <dir> Add <dir> to the end of the main include path\n\
1845 -I- Fine-grained include path control; see info docs\n\
1846 -nostdinc Do not search system include directories\n\
1847 (dirs specified with -isystem will still be used)\n\
1848 -nostdinc++ Do not search system include directories for C++\n\
1849 -o <file> Put output into <file>\n\
1852 -trigraphs Support ISO C trigraphs\n\
1853 -std=<std name> Specify the conformance standard; one of:\n\
1854 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1855 iso9899:199409, iso9899:1999, c++98\n\
1856 -w Inhibit warning messages\n\
1857 -W[no-]trigraphs Warn if trigraphs are encountered\n\
1858 -W[no-]comment{s} Warn if one comment starts inside another\n\
1861 -W[no-]traditional Warn about features not present in traditional C\n\
1862 -W[no-]undef Warn if an undefined macro is used by #if\n\
1863 -W[no-]import Warn about the use of the #import directive\n\
1866 -W[no-]error Treat all warnings as errors\n\
1867 -W[no-]system-headers Do not suppress warnings from system headers\n\
1868 -W[no-]all Enable most preprocessor warnings\n\
1871 -M Generate make dependencies\n\
1872 -MM As -M, but ignore system header files\n\
1873 -MD Generate make dependencies and compile\n\
1874 -MMD As -MD, but ignore system header files\n\
1875 -MF <file> Write dependency output to the given file\n\
1876 -MG Treat missing header file as generated files\n\
1879 -MP Generate phony targets for all headers\n\
1880 -MQ <target> Add a MAKE-quoted target\n\
1881 -MT <target> Add an unquoted target\n\
1884 -D<macro> Define a <macro> with string '1' as its value\n\
1885 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1886 -A<question>=<answer> Assert the <answer> to <question>\n\
1887 -A-<question>=<answer> Disable the <answer> to <question>\n\
1888 -U<macro> Undefine <macro> \n\
1889 -v Display the version number\n\
1892 -H Print the name of header files as they are used\n\
1893 -C Do not discard comments\n\
1894 -dM Display a list of macro definitions active at end\n\
1895 -dD Preserve macro definitions in output\n\
1896 -dN As -dD except that only the names are preserved\n\
1897 -dI Include #include directives in the output\n\
1900 -f[no-]preprocessed Treat the input file as already preprocessed\n\
1901 -ftabstop=<number> Distance between tab stops for column reporting\n\
1902 -isysroot <dir> Set <dir> to be the system root directory\n\
1903 -P Do not generate #line directives\n\
1904 -remap Remap file names when including files\n\
1905 --help Display this information\n\