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 TARGET_SYSTEM_ROOT
40 # define TARGET_SYSTEM_ROOT NULL
43 static int saved_lineno
;
46 static cpp_options
*cpp_opts
;
49 static const char *in_fname
;
51 /* Filename and stream for preprocessed output. */
52 static const char *out_fname
;
53 static FILE *out_stream
;
55 /* Append dependencies to deps_file. */
56 static bool deps_append
;
58 /* If dependency switches (-MF etc.) have been given. */
59 static bool deps_seen
;
64 /* Dependency output file. */
65 static const char *deps_file
;
67 /* The prefix given by -iprefix, if any. */
68 static const char *iprefix
;
70 /* The system root, if any. Overridden by -isysroot. */
71 static const char *sysroot
= TARGET_SYSTEM_ROOT
;
73 /* Zero disables all standard directories for headers. */
74 static bool std_inc
= true;
76 /* Zero disables the C++-specific standard directories for headers. */
77 static bool std_cxx_inc
= true;
79 /* If the quote chain has been split by -I-. */
80 static bool quote_chain_split
;
82 /* If -Wunused-macros. */
83 static bool warn_unused_macros
;
85 /* Number of deferred options, deferred options array size. */
86 static size_t deferred_count
, deferred_size
;
88 /* Number of deferred options scanned for -include. */
89 static size_t include_cursor
;
91 static void missing_arg
PARAMS ((size_t));
92 static size_t find_opt
PARAMS ((const char *, int));
93 static void set_Wimplicit
PARAMS ((int));
94 static void complain_wrong_lang
PARAMS ((size_t));
95 static void write_langs
PARAMS ((char *, int));
96 static void print_help
PARAMS ((void));
97 static void handle_OPT_d
PARAMS ((const char *));
98 static void set_std_cxx98
PARAMS ((int));
99 static void set_std_c89
PARAMS ((int, int));
100 static void set_std_c99
PARAMS ((int));
101 static void check_deps_environment_vars
PARAMS ((void));
102 static void handle_deferred_opts
PARAMS ((void));
103 static void sanitize_cpp_opts
PARAMS ((void));
104 static void add_prefixed_path
PARAMS ((const char *, size_t));
105 static void push_command_line_include
PARAMS ((void));
106 static void cb_file_change
PARAMS ((cpp_reader
*, const struct line_map
*));
107 static void finish_options
PARAMS ((void));
109 #ifndef STDC_0_IN_SYSTEM_HEADERS
110 #define STDC_0_IN_SYSTEM_HEADERS 0
113 #define CL_C_ONLY (1 << 0) /* Only C. */
114 #define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
115 #define CL_CXX_ONLY (1 << 2) /* Only C++. */
116 #define CL_OBJCXX_ONLY (1 << 3) /* Only ObjC++. */
117 #define CL_JOINED (1 << 4) /* If takes joined argument. */
118 #define CL_SEPARATE (1 << 5) /* If takes a separate argument. */
120 #define CL_ARG (CL_JOINED | CL_SEPARATE)
121 #define CL_C (CL_C_ONLY | CL_OBJC_ONLY)
122 #define CL_OBJC (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
123 #define CL_CXX (CL_CXX_ONLY | CL_OBJCXX_ONLY)
124 #define CL_ALL (CL_C | CL_CXX)
126 /* This is the list of all command line options, with the leading "-"
127 removed. It must be sorted in ASCII collating order. All options
128 beginning with "f" or "W" are implicitly assumed to take a "no-"
129 form; this form should not be listed. The variable "on" is true if
130 the positive form is given, otherwise it is false. If you don't
131 want to allow a "no-" form, your handler should reject "on" being
132 false by returning zero. See, for example, the handling of
135 If the user gives an option to a front end that doesn't support it,
136 an error is output, mentioning which front ends the option is valid
137 for. If you don't want this, you must accept it for all front
138 ends, and test for the front end in the option handler. See, for
139 example, the handling of -Wno-strict-prototypes for C++.
141 If you request an argument with CL_JOINED, CL_SEPARATE or their
142 combination CL_ARG, it is stored in the variable "arg", which is
143 guaranteed to be non-NULL and to not be an empty string. It points
144 to the argument either within the argv[] vector or within one of
145 that vector's strings, and so the text is permanent and copies need
146 not be made. Be sure to add an error message in missing_arg() if
147 the default is not appropriate. */
149 #define COMMAND_LINE_OPTIONS \
150 OPT("-help", CL_ALL, OPT__help) \
151 OPT("-output-pch=", CL_ALL | CL_ARG, OPT__output_pch) \
152 OPT("A", CL_ALL | CL_ARG, OPT_A) \
153 OPT("C", CL_ALL, OPT_C) \
154 OPT("CC", CL_ALL, OPT_CC) \
155 OPT("D", CL_ALL | CL_ARG, OPT_D) \
156 OPT("E", CL_ALL, OPT_E) \
157 OPT("H", CL_ALL, OPT_H) \
158 OPT("I", CL_ALL | CL_ARG, OPT_I) \
159 OPT("M", CL_ALL, OPT_M) \
160 OPT("MD", CL_ALL | CL_SEPARATE, OPT_MD) \
161 OPT("MF", CL_ALL | CL_ARG, OPT_MF) \
162 OPT("MG", CL_ALL, OPT_MG) \
163 OPT("MM", CL_ALL, OPT_MM) \
164 OPT("MMD", CL_ALL | CL_SEPARATE, OPT_MMD) \
165 OPT("MP", CL_ALL, OPT_MP) \
166 OPT("MQ", CL_ALL | CL_ARG, OPT_MQ) \
167 OPT("MT", CL_ALL | CL_ARG, OPT_MT) \
168 OPT("P", CL_ALL, OPT_P) \
169 OPT("U", CL_ALL | CL_ARG, OPT_U) \
170 OPT("Wabi", CL_CXX, OPT_Wabi) \
171 OPT("Wall", CL_ALL, OPT_Wall) \
172 OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
173 OPT("Wcast-qual", CL_ALL, OPT_Wcast_qual) \
174 OPT("Wchar-subscripts", CL_ALL, OPT_Wchar_subscripts) \
175 OPT("Wcomment", CL_ALL, OPT_Wcomment) \
176 OPT("Wcomments", CL_ALL, OPT_Wcomments) \
177 OPT("Wconversion", CL_ALL, OPT_Wconversion) \
178 OPT("Wctor-dtor-privacy", CL_CXX, OPT_Wctor_dtor_privacy) \
179 OPT("Wdeprecated", CL_CXX, OPT_Wdeprecated) \
180 OPT("Wdiv-by-zero", CL_C, OPT_Wdiv_by_zero) \
181 OPT("Weffc++", CL_CXX, OPT_Weffcxx) \
182 OPT("Wendif-labels", CL_ALL, OPT_Wendif_labels) \
183 OPT("Werror", CL_ALL, OPT_Werror) \
184 OPT("Werror-implicit-function-declaration", \
185 CL_C, OPT_Werror_implicit_function_decl) \
186 OPT("Wfloat-equal", CL_ALL, OPT_Wfloat_equal) \
187 OPT("Wformat", CL_ALL, OPT_Wformat) \
188 OPT("Wformat-extra-args", CL_ALL, OPT_Wformat_extra_args) \
189 OPT("Wformat-nonliteral", CL_ALL, OPT_Wformat_nonliteral) \
190 OPT("Wformat-security", CL_ALL, OPT_Wformat_security) \
191 OPT("Wformat-y2k", CL_ALL, OPT_Wformat_y2k) \
192 OPT("Wformat-zero-length", CL_C, OPT_Wformat_zero_length) \
193 OPT("Wformat=", CL_ALL | CL_JOINED, OPT_Wformat_eq) \
194 OPT("Wimplicit", CL_ALL, OPT_Wimplicit) \
195 OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
196 OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
197 OPT("Wimport", CL_ALL, OPT_Wimport) \
198 OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
199 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
200 OPT("Wmain", CL_C, OPT_Wmain) \
201 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
202 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
203 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
204 OPT("Wmissing-prototypes", CL_ALL, OPT_Wmissing_prototypes) \
205 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
206 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
207 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
208 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
209 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
210 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
211 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
212 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
213 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
214 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
215 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
216 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
217 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
218 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
219 OPT("Wselector", CL_OBJC, OPT_Wselector) \
220 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
221 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
222 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
223 OPT("Wstrict-prototypes", CL_ALL, OPT_Wstrict_prototypes) \
224 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
225 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
226 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
227 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
228 OPT("Wundeclared-selector", CL_OBJC, OPT_Wundeclared_selector) \
229 OPT("Wundef", CL_ALL, OPT_Wundef) \
230 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
231 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
232 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
233 OPT("ansi", CL_ALL, OPT_ansi) \
234 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
235 OPT("fabi-version=", CL_CXX | CL_JOINED, OPT_fabi_version) \
236 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
237 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
238 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
239 OPT("fasm", CL_ALL, OPT_fasm) \
240 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
241 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
242 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
243 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
244 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
245 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
246 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
247 OPT_fconstant_string_class) \
248 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
249 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
250 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
251 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
252 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
253 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
254 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
255 OPT("ffixed-form", CL_C, OPT_ffixed_form) \
256 OPT("ffixed-line-length-", CL_C | CL_JOINED, OPT_ffixed_line_length) \
257 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
258 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
259 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
260 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
261 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
262 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
263 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
264 OPT("fhosted", CL_C, OPT_fhosted) \
265 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
266 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
267 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
268 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
269 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
270 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
271 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
272 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
273 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
274 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
275 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
276 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
277 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
278 OPT("fpch-deps", CL_ALL, OPT_fpch_deps) \
279 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
280 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
281 OPT("frepo", CL_CXX, OPT_frepo) \
282 OPT("frtti", CL_CXX, OPT_frtti) \
283 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
284 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
285 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
286 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
287 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
288 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
289 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
290 OPT("fstats", CL_CXX, OPT_fstats) \
291 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
292 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
293 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
294 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
295 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
296 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
297 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
298 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
299 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
300 OPT("fweak", CL_CXX, OPT_fweak) \
301 OPT("fxref", CL_CXX, OPT_fxref) \
302 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
303 OPT("idirafter", CL_ALL | CL_ARG, OPT_idirafter) \
304 OPT("imacros", CL_ALL | CL_ARG, OPT_imacros) \
305 OPT("include", CL_ALL | CL_ARG, OPT_include) \
306 OPT("iprefix", CL_ALL | CL_ARG, OPT_iprefix) \
307 OPT("isysroot", CL_ALL | CL_ARG, OPT_isysroot) \
308 OPT("isystem", CL_ALL | CL_ARG, OPT_isystem) \
309 OPT("iwithprefix", CL_ALL | CL_ARG, OPT_iwithprefix) \
310 OPT("iwithprefixbefore", CL_ALL | CL_ARG, OPT_iwithprefixbefore) \
311 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
312 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
313 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
314 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
315 OPT("o", CL_ALL | CL_ARG, OPT_o) \
316 OPT("pedantic", CL_ALL, OPT_pedantic) \
317 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
318 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
319 OPT("remap", CL_ALL, OPT_remap) \
320 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
321 OPT("std=c89", CL_C, OPT_std_c89) \
322 OPT("std=c99", CL_C, OPT_std_c99) \
323 OPT("std=c9x", CL_C, OPT_std_c9x) \
324 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
325 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
326 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
327 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
328 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
329 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
330 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
331 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
332 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
333 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
334 OPT("undef", CL_ALL, OPT_undef) \
335 OPT("v", CL_ALL, OPT_v) \
336 OPT("w", CL_ALL, OPT_w)
338 #define OPT(text, flags, code) code,
348 const char *opt_text
;
349 unsigned char opt_len
;
351 ENUM_BITFIELD (opt_code
) opt_code
: 2 * CHAR_BIT
;
354 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
356 static struct cl_option cl_options
[] =
358 static const struct cl_option cl_options
[] =
364 #undef COMMAND_LINE_OPTIONS
366 /* Holds switches parsed by c_common_decode_option (), but whose
367 handling is deferred to c_common_post_options (). */
368 static void defer_opt
PARAMS ((enum opt_code
, const char *));
369 static struct deferred_opt
377 static int opt_comp
PARAMS ((const void *, const void *));
379 /* Run-time sorting of options array. */
384 return strcmp (((struct cl_option
*) p1
)->opt_text
,
385 ((struct cl_option
*) p2
)->opt_text
);
389 /* Complain that switch OPT_INDEX expects an argument but none was
392 missing_arg (opt_index
)
395 const char *opt_text
= cl_options
[opt_index
].opt_text
;
397 switch (cl_options
[opt_index
].opt_code
)
399 case OPT__output_pch
:
402 case OPT_fabi_version
:
405 case OPT_fname_mangling
:
407 case OPT_ftemplate_depth
:
409 case OPT_iwithprefix
:
410 case OPT_iwithprefixbefore
:
412 error ("missing argument to \"-%s\"", opt_text
);
415 case OPT_fconstant_string_class
:
416 error ("no class name specified with \"-%s\"", opt_text
);
420 error ("assertion missing after \"-%s\"", opt_text
);
425 error ("macro name missing after \"-%s\"", opt_text
);
432 error ("missing path after \"-%s\"", opt_text
);
441 error ("missing filename after \"-%s\"", opt_text
);
446 error ("missing target after \"-%s\"", opt_text
);
451 /* Perform a binary search to find which option the command-line INPUT
452 matches. Returns its index in the option array, and N_OPTS on
455 Complications arise since some options can be suffixed with an
456 argument, and multiple complete matches can occur, e.g. -pedantic
457 and -pedantic-errors. Also, some options are only accepted by some
458 languages. If a switch matches for a different language and
459 doesn't match any alternatives for the true front end, the index of
460 the matched switch is returned anyway. The caller should check for
463 find_opt (input
, lang_flag
)
469 size_t result
= N_OPTS
;
479 opt_len
= cl_options
[md
].opt_len
;
480 comp
= strncmp (input
, cl_options
[md
].opt_text
, opt_len
);
488 /* The switch matches. It it an exact match? */
489 if (input
[opt_len
] == '\0')
495 /* If the switch takes no arguments this is not a proper
496 match, so we continue the search (e.g. input="stdc++"
497 match was "stdc"). */
498 if (!(cl_options
[md
].flags
& CL_JOINED
))
501 /* Is this switch valid for this front end? */
502 if (!(cl_options
[md
].flags
& lang_flag
))
504 /* If subsequently we don't find a better match,
505 return this and let the caller report it as a bad
511 /* Two scenarios remain: we have the switch's argument,
512 or we match a longer option. This can happen with
513 -iwithprefix and -withprefixbefore. The longest
514 possible option match succeeds.
516 Scan forwards, and return an exact match. Otherwise
517 return the longest valid option-accepting match (mx).
518 This loops at most twice with current options. */
520 for (md
= md
+ 1; md
< (size_t) N_OPTS
; md
++)
522 opt_len
= cl_options
[md
].opt_len
;
523 if (strncmp (input
, cl_options
[md
].opt_text
, opt_len
))
525 if (input
[opt_len
] == '\0')
527 if (cl_options
[md
].flags
& lang_flag
528 && cl_options
[md
].flags
& CL_JOINED
)
540 /* Defer option CODE with argument ARG. */
542 defer_opt (code
, arg
)
546 /* FIXME: this should be in c_common_init_options, which should take
550 extern int save_argc
;
551 deferred_size
= save_argc
;
552 deferred_opts
= (struct deferred_opt
*)
553 xmalloc (deferred_size
* sizeof (struct deferred_opt
));
556 if (deferred_count
== deferred_size
)
559 deferred_opts
[deferred_count
].code
= code
;
560 deferred_opts
[deferred_count
].arg
= arg
;
564 /* Common initialization before parsing options. */
566 c_common_init_options (lang
)
567 enum c_language_kind lang
;
570 /* For non-ASCII hosts, the cl_options array needs to be sorted at
572 qsort (cl_options
, N_OPTS
, sizeof (struct cl_option
), opt_comp
);
578 for (i
= 1; i
< N_OPTS
; i
++)
579 if (strcmp (cl_options
[i
- 1].opt_text
, cl_options
[i
].opt_text
) >= 0)
580 error ("options array incorrectly sorted: %s is before %s",
581 cl_options
[i
- 1].opt_text
, cl_options
[i
].opt_text
);
586 parse_in
= cpp_create_reader (lang
== clk_c
? CLK_GNUC89
: CLK_GNUCXX
);
587 cpp_opts
= cpp_get_options (parse_in
);
591 flag_const_strings
= (lang
== clk_cplusplus
);
592 warn_pointer_arith
= (lang
== clk_cplusplus
);
594 warn_sign_compare
= -1;
597 /* Handle one command-line option in (argc, argv).
598 Can be called multiple times, to handle multiple sets of options.
599 Returns number of strings consumed. */
601 c_common_decode_option (argc
, argv
)
605 static const int lang_flags
[] = {CL_C_ONLY
, CL_C
, CL_CXX_ONLY
, CL_CXX
};
607 const char *opt
, *arg
= 0;
610 int result
= 0, lang_flag
;
611 const struct cl_option
*option
;
616 /* Interpret "-" or a non-switch as a file name. */
617 if (opt
[0] != '-' || opt
[1] == '\0')
625 error ("too many filenames given. Type %s --help for usage",
633 /* Drop the "no-" from negative switches. */
634 if ((opt
[1] == 'W' || opt
[1] == 'f')
635 && opt
[2] == 'n' && opt
[3] == 'o' && opt
[4] == '-')
637 size_t len
= strlen (opt
) - 3;
639 dup
= xmalloc (len
+ 1);
642 memcpy (dup
+ 2, opt
+ 5, len
- 2 + 1);
648 lang_flag
= lang_flags
[(c_language
<< 1) + flag_objc
];
649 opt_index
= find_opt (opt
+ 1, lang_flag
);
650 if (opt_index
== N_OPTS
)
654 option
= &cl_options
[opt_index
];
656 /* Sort out any argument the switch takes. */
657 if (option
->flags
& CL_ARG
)
659 if (option
->flags
& CL_JOINED
)
661 /* Have arg point to the original switch. This is because
662 some code, such as disable_builtin_function, expects its
663 argument to be persistent until the program exits. */
664 arg
= argv
[0] + cl_options
[opt_index
].opt_len
+ 1;
666 arg
+= strlen ("no-");
669 /* If we don't have an argument, and CL_SEPARATE, try the next
670 argument in the vector. */
671 if (!arg
|| (*arg
== '\0' && option
->flags
& CL_SEPARATE
))
677 if (!arg
|| *arg
== '\0')
679 missing_arg (opt_index
);
685 /* Complain about the wrong language after we've swallowed any
686 necessary extra argument. Eventually make this a hard error
687 after the call to find_opt, and return argc. */
688 if (!(cl_options
[opt_index
].flags
& lang_flag
))
690 complain_wrong_lang (opt_index
);
694 switch (code
= option
->opt_code
)
696 case N_OPTS
: /* Shut GCC up. */
703 case OPT__output_pch
:
708 defer_opt (code
, arg
);
712 cpp_opts
->discard_comments
= 0;
716 cpp_opts
->discard_comments
= 0;
717 cpp_opts
->discard_comments_in_macro_exp
= 0;
721 defer_opt (code
, arg
);
725 flag_preprocess_only
= 1;
729 cpp_opts
->print_include_names
= 1;
733 if (strcmp (arg
, "-"))
734 add_path (xstrdup (arg
), BRACKET
, 0);
737 if (quote_chain_split
)
738 error ("-I- specified twice");
739 quote_chain_split
= true;
740 split_quote_chain ();
746 /* When doing dependencies with -M or -MM, suppress normal
747 preprocessed output, but still do -dM etc. as software
748 depends on this. Preprocessed output does occur if -MD, -MMD
749 or environment var dependency generation is used. */
750 cpp_opts
->deps
.style
= (code
== OPT_M
? DEPS_SYSTEM
: DEPS_USER
);
752 cpp_opts
->inhibit_warnings
= 1;
757 cpp_opts
->deps
.style
= (code
== OPT_MD
? DEPS_SYSTEM
: DEPS_USER
);
768 cpp_opts
->deps
.missing_files
= true;
773 cpp_opts
->deps
.phony_targets
= true;
779 defer_opt (code
, arg
);
783 flag_no_line_commands
= 1;
787 defer_opt (code
, arg
);
798 warn_char_subscripts
= on
;
799 warn_missing_braces
= on
;
800 warn_parentheses
= on
;
801 warn_return_type
= on
;
802 warn_sequence_point
= on
; /* Was C only. */
803 warn_sign_compare
= on
; /* Was C++ only. */
805 warn_strict_aliasing
= on
;
807 /* Only warn about unknown pragmas that are not in system
809 warn_unknown_pragmas
= on
;
811 /* We save the value of warn_uninitialized, since if they put
812 -Wuninitialized on the command line, we need to generate a
813 warning about not using it without also specifying -O. */
814 if (warn_uninitialized
!= 1)
815 warn_uninitialized
= (on
? 2 : 0);
817 if (c_language
== clk_c
)
818 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
819 can turn it off only if it's not explicit. */
823 /* C++-specific warnings. */
824 warn_ctor_dtor_privacy
= on
;
827 warn_nontemplate_friend
= on
;
830 cpp_opts
->warn_trigraphs
= on
;
831 cpp_opts
->warn_comments
= on
;
832 cpp_opts
->warn_num_sign_change
= on
;
833 cpp_opts
->warn_multichar
= on
; /* Was C++ only. */
836 case OPT_Wbad_function_cast
:
837 warn_bad_function_cast
= on
;
844 case OPT_Wchar_subscripts
:
845 warn_char_subscripts
= on
;
850 cpp_opts
->warn_comments
= on
;
853 case OPT_Wconversion
:
854 warn_conversion
= on
;
857 case OPT_Wctor_dtor_privacy
:
858 warn_ctor_dtor_privacy
= on
;
861 case OPT_Wdeprecated
:
862 warn_deprecated
= on
;
863 cpp_opts
->warn_deprecated
= on
;
866 case OPT_Wdiv_by_zero
:
867 warn_div_by_zero
= on
;
874 case OPT_Wendif_labels
:
875 cpp_opts
->warn_endif_labels
= on
;
879 cpp_opts
->warnings_are_errors
= on
;
882 case OPT_Werror_implicit_function_decl
:
886 mesg_implicit_function_declaration
= 2;
889 case OPT_Wfloat_equal
:
890 warn_float_equal
= on
;
898 set_Wformat (atoi (arg
));
901 case OPT_Wformat_extra_args
:
902 warn_format_extra_args
= on
;
905 case OPT_Wformat_nonliteral
:
906 warn_format_nonliteral
= on
;
909 case OPT_Wformat_security
:
910 warn_format_security
= on
;
913 case OPT_Wformat_y2k
:
914 warn_format_y2k
= on
;
917 case OPT_Wformat_zero_length
:
918 warn_format_zero_length
= on
;
925 case OPT_Wimplicit_function_decl
:
926 mesg_implicit_function_declaration
= on
;
929 case OPT_Wimplicit_int
:
930 warn_implicit_int
= on
;
934 cpp_opts
->warn_import
= on
;
937 case OPT_Winvalid_pch
:
938 cpp_opts
->warn_invalid_pch
= on
;
952 case OPT_Wmissing_braces
:
953 warn_missing_braces
= on
;
956 case OPT_Wmissing_declarations
:
957 warn_missing_declarations
= on
;
960 case OPT_Wmissing_format_attribute
:
961 warn_missing_format_attribute
= on
;
964 case OPT_Wmissing_prototypes
:
965 warn_missing_prototypes
= on
;
969 cpp_opts
->warn_multichar
= on
;
972 case OPT_Wnested_externs
:
973 warn_nested_externs
= on
;
976 case OPT_Wnon_template_friend
:
977 warn_nontemplate_friend
= on
;
980 case OPT_Wnon_virtual_dtor
:
988 case OPT_Wold_style_cast
:
989 warn_old_style_cast
= on
;
992 case OPT_Woverloaded_virtual
:
993 warn_overloaded_virtual
= on
;
996 case OPT_Wparentheses
:
997 warn_parentheses
= on
;
1000 case OPT_Wpmf_conversions
:
1004 case OPT_Wpointer_arith
:
1005 warn_pointer_arith
= on
;
1016 case OPT_Wredundant_decls
:
1017 warn_redundant_decls
= on
;
1024 case OPT_Wreturn_type
:
1025 warn_return_type
= on
;
1028 case OPT_Wsequence_point
:
1029 warn_sequence_point
= on
;
1032 case OPT_Wsign_compare
:
1033 warn_sign_compare
= on
;
1036 case OPT_Wsign_promo
:
1037 warn_sign_promo
= on
;
1040 case OPT_Wstrict_prototypes
:
1041 if (!on
&& c_language
== clk_cplusplus
)
1042 warning ("-Wno-strict-prototypes is not supported in C++");
1044 warn_strict_prototypes
= on
;
1051 case OPT_Wsystem_headers
:
1052 cpp_opts
->warn_system_headers
= on
;
1055 case OPT_Wtraditional
:
1056 warn_traditional
= on
;
1057 cpp_opts
->warn_traditional
= on
;
1060 case OPT_Wtrigraphs
:
1061 cpp_opts
->warn_trigraphs
= on
;
1064 case OPT_Wundeclared_selector
:
1065 warn_undeclared_selector
= on
;
1069 cpp_opts
->warn_undef
= on
;
1072 case OPT_Wunknown_pragmas
:
1073 /* Set to greater than 1, so that even unknown pragmas in
1074 system headers will be warned about. */
1075 warn_unknown_pragmas
= on
* 2;
1078 case OPT_Wunused_macros
:
1079 warn_unused_macros
= on
;
1082 case OPT_Wwrite_strings
:
1083 if (c_language
== clk_c
)
1084 flag_const_strings
= on
;
1086 warn_write_strings
= on
;
1090 if (c_language
== clk_c
)
1091 set_std_c89 (false, true);
1093 set_std_cxx98 (true);
1100 case OPT_fcond_mismatch
:
1101 if (c_language
== clk_c
)
1103 flag_cond_mismatch
= on
;
1108 case OPT_fall_virtual
:
1109 case OPT_fenum_int_equiv
:
1110 case OPT_fguiding_decls
:
1111 case OPT_fhonor_std
:
1112 case OPT_fhuge_objects
:
1113 case OPT_flabels_ok
:
1114 case OPT_fname_mangling
:
1116 case OPT_fnonnull_objects
:
1118 case OPT_fstrict_prototype
:
1119 case OPT_fthis_is_variable
:
1120 case OPT_fvtable_thunks
:
1122 warning ("switch \"%s\" is no longer supported", argv
[0]);
1125 case OPT_fabi_version
:
1126 flag_abi_version
= read_integral_parameter (arg
, argv
[0], 1);
1129 case OPT_faccess_control
:
1130 flag_access_control
= on
;
1133 case OPT_falt_external_templates
:
1134 flag_alt_external_templates
= on
;
1136 flag_external_templates
= true;
1138 warning ("switch \"%s\" is deprecated, please see documentation for details", argv
[0]);
1146 flag_no_builtin
= !on
;
1153 disable_builtin_function (arg
);
1156 case OPT_fdollars_in_identifiers
:
1157 dollars_in_ident
= on
;
1161 if (!on
|| !dump_switch_p (argv
[0] + strlen ("-f")))
1165 case OPT_ffreestanding
:
1167 /* Fall through... */
1170 flag_no_builtin
= !on
;
1171 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
1172 if (!on
&& warn_main
== 2)
1176 case OPT_fshort_double
:
1177 flag_short_double
= on
;
1180 case OPT_fshort_enums
:
1181 flag_short_enums
= on
;
1184 case OPT_fshort_wchar
:
1185 flag_short_wchar
= on
;
1188 case OPT_fsigned_bitfields
:
1189 flag_signed_bitfields
= on
;
1190 explicit_flag_signed_bitfields
= 1;
1193 case OPT_fsigned_char
:
1194 flag_signed_char
= on
;
1197 case OPT_funsigned_bitfields
:
1198 flag_signed_bitfields
= !on
;
1199 explicit_flag_signed_bitfields
= 1;
1202 case OPT_funsigned_char
:
1203 flag_signed_char
= !on
;
1206 case OPT_fcheck_new
:
1207 flag_check_new
= on
;
1210 case OPT_fconserve_space
:
1211 flag_conserve_space
= on
;
1214 case OPT_fconst_strings
:
1215 flag_const_strings
= on
;
1218 case OPT_fconstant_string_class
:
1219 constant_string_class_name
= arg
;
1222 case OPT_fdefault_inline
:
1223 flag_default_inline
= on
;
1226 case OPT_felide_constructors
:
1227 flag_elide_constructors
= on
;
1230 case OPT_fenforce_eh_specs
:
1231 flag_enforce_eh_specs
= on
;
1234 case OPT_fexternal_templates
:
1235 flag_external_templates
= on
;
1238 case OPT_ffixed_form
:
1239 case OPT_ffixed_line_length
:
1240 /* Fortran front end options ignored when preprocessing only. */
1241 if (flag_preprocess_only
)
1245 case OPT_ffor_scope
:
1246 flag_new_for_scope
= on
;
1249 case OPT_fgnu_keywords
:
1250 flag_no_gnu_keywords
= !on
;
1253 case OPT_fgnu_runtime
:
1254 flag_next_runtime
= !on
;
1257 case OPT_fhandle_exceptions
:
1258 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
1259 flag_exceptions
= on
;
1262 case OPT_fimplement_inlines
:
1263 flag_implement_inlines
= on
;
1266 case OPT_fimplicit_inline_templates
:
1267 flag_implicit_inline_templates
= on
;
1270 case OPT_fimplicit_templates
:
1271 flag_implicit_templates
= on
;
1274 case OPT_fms_extensions
:
1275 flag_ms_extensions
= on
;
1278 case OPT_fnext_runtime
:
1279 flag_next_runtime
= on
;
1282 case OPT_fnonansi_builtins
:
1283 flag_no_nonansi_builtin
= !on
;
1286 case OPT_foperator_names
:
1287 cpp_opts
->operator_names
= on
;
1290 case OPT_foptional_diags
:
1291 flag_optional_diags
= on
;
1295 cpp_opts
->restore_pch_deps
= on
;
1298 case OPT_fpermissive
:
1299 flag_permissive
= on
;
1302 case OPT_fpreprocessed
:
1303 cpp_opts
->preprocessed
= on
;
1307 flag_use_repository
= on
;
1309 flag_implicit_templates
= 0;
1316 case OPT_fshow_column
:
1317 cpp_opts
->show_column
= on
;
1321 flag_detailed_statistics
= on
;
1325 /* Don't recognize -fno-tabstop=. */
1329 /* It is documented that we silently ignore silly values. */
1332 long tabstop
= strtol (arg
, &endptr
, 10);
1333 if (*endptr
== '\0' && tabstop
>= 1 && tabstop
<= 100)
1334 cpp_opts
->tabstop
= tabstop
;
1338 case OPT_ftemplate_depth
:
1339 max_tinst_depth
= read_integral_parameter (arg
, argv
[0], 0);
1342 case OPT_fvtable_gc
:
1343 flag_vtable_gc
= on
;
1346 case OPT_fuse_cxa_atexit
:
1347 flag_use_cxa_atexit
= on
;
1355 flag_gen_declaration
= 1;
1359 add_path (xstrdup (arg
), AFTER
, 0);
1364 defer_opt (code
, arg
);
1376 add_path (xstrdup (arg
), SYSTEM
, 0);
1379 case OPT_iwithprefix
:
1380 add_prefixed_path (arg
, SYSTEM
);
1383 case OPT_iwithprefixbefore
:
1384 add_prefixed_path (arg
, BRACKET
);
1388 cpp_set_lang (parse_in
, CLK_ASM
);
1399 case OPT_nostdincplusplus
:
1400 std_cxx_inc
= false;
1408 error ("output filename specified twice");
1413 /* We need to handle the -pedantic switches here, rather than in
1414 c_common_post_options, so that a subsequent -Wno-endif-labels
1415 is not overridden. */
1416 case OPT_pedantic_errors
:
1417 cpp_opts
->pedantic_errors
= 1;
1420 cpp_opts
->pedantic
= 1;
1421 cpp_opts
->warn_endif_labels
= 1;
1424 case OPT_print_objc_runtime_info
:
1425 print_struct_values
= 1;
1429 cpp_opts
->remap
= 1;
1432 case OPT_std_cplusplus98
:
1433 case OPT_std_gnuplusplus98
:
1434 set_std_cxx98 (code
== OPT_std_cplusplus98
/* ISO */);
1438 case OPT_std_iso9899_1990
:
1439 case OPT_std_iso9899_199409
:
1440 set_std_c89 (code
== OPT_std_iso9899_199409
/* c94 */, true /* ISO */);
1444 set_std_c89 (false /* c94 */, false /* ISO */);
1449 case OPT_std_iso9899_1999
:
1450 case OPT_std_iso9899_199x
:
1451 set_std_c99 (true /* ISO */);
1456 set_std_c99 (false /* ISO */);
1460 cpp_opts
->trigraphs
= 1;
1463 case OPT_traditional_cpp
:
1464 cpp_opts
->traditional
= 1;
1472 cpp_opts
->inhibit_warnings
= 1;
1486 /* Post-switch processing. */
1488 c_common_post_options (pfilename
)
1489 const char **pfilename
;
1491 /* Canonicalize the input and output filenames. */
1492 if (in_fname
== NULL
|| !strcmp (in_fname
, "-"))
1495 if (out_fname
== NULL
|| !strcmp (out_fname
, "-"))
1498 if (cpp_opts
->deps
.style
== DEPS_NONE
)
1499 check_deps_environment_vars ();
1501 handle_deferred_opts ();
1503 sanitize_cpp_opts ();
1505 register_include_chains (parse_in
, sysroot
, iprefix
,
1506 std_inc
, std_cxx_inc
&& c_language
== clk_cplusplus
,
1509 flag_inline_trees
= 1;
1511 /* Use tree inlining if possible. Function instrumentation is only
1512 done in the RTL level, so we disable tree inlining. */
1513 if (! flag_instrument_function_entry_exit
)
1515 if (!flag_no_inline
)
1517 if (flag_inline_functions
)
1519 flag_inline_trees
= 2;
1520 flag_inline_functions
= 0;
1524 /* Special format checking options don't work without -Wformat; warn if
1526 if (warn_format_y2k
&& !warn_format
)
1527 warning ("-Wformat-y2k ignored without -Wformat");
1528 if (warn_format_extra_args
&& !warn_format
)
1529 warning ("-Wformat-extra-args ignored without -Wformat");
1530 if (warn_format_zero_length
&& !warn_format
)
1531 warning ("-Wformat-zero-length ignored without -Wformat");
1532 if (warn_format_nonliteral
&& !warn_format
)
1533 warning ("-Wformat-nonliteral ignored without -Wformat");
1534 if (warn_format_security
&& !warn_format
)
1535 warning ("-Wformat-security ignored without -Wformat");
1536 if (warn_missing_format_attribute
&& !warn_format
)
1537 warning ("-Wmissing-format-attribute ignored without -Wformat");
1539 if (flag_preprocess_only
)
1541 /* Open the output now. We must do so even if flag_no_output is
1542 on, because there may be other output than from the actual
1543 preprocessing (e.g. from -dM). */
1544 if (out_fname
[0] == '\0')
1545 out_stream
= stdout
;
1547 out_stream
= fopen (out_fname
, "w");
1549 if (out_stream
== NULL
)
1551 fatal_io_error ("opening output file %s", out_fname
);
1555 init_pp_output (out_stream
);
1561 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1565 cpp_get_callbacks (parse_in
)->file_change
= cb_file_change
;
1567 /* NOTE: we use in_fname here, not the one supplied. */
1568 *pfilename
= cpp_read_main_file (parse_in
, in_fname
, ident_hash
);
1570 saved_lineno
= lineno
;
1573 /* If an error has occurred in cpplib, note it so we fail
1575 errorcount
+= cpp_errors (parse_in
);
1577 return flag_preprocess_only
;
1580 /* Front end initialization common to C, ObjC and C++. */
1584 lineno
= saved_lineno
;
1586 /* Set up preprocessor arithmetic. Must be done after call to
1587 c_common_nodes_and_builtins for type nodes to be good. */
1588 cpp_opts
->precision
= TYPE_PRECISION (intmax_type_node
);
1589 cpp_opts
->char_precision
= TYPE_PRECISION (char_type_node
);
1590 cpp_opts
->int_precision
= TYPE_PRECISION (integer_type_node
);
1591 cpp_opts
->wchar_precision
= TYPE_PRECISION (wchar_type_node
);
1592 cpp_opts
->unsigned_wchar
= TREE_UNSIGNED (wchar_type_node
);
1594 if (flag_preprocess_only
)
1597 preprocess_file (parse_in
);
1601 /* Has to wait until now so that cpplib has its hash table. */
1607 /* A thin wrapper around the real parser that initializes the
1608 integrated preprocessor after debug output has been initialized.
1609 Also, make sure the start_source_file debug hook gets called for
1610 the primary source file. */
1612 c_common_parse_file (set_yydebug
)
1613 int set_yydebug ATTRIBUTE_UNUSED
;
1616 yydebug
= set_yydebug
;
1618 warning ("YYDEBUG not defined");
1621 (*debug_hooks
->start_source_file
) (lineno
, input_filename
);
1625 free_parser_stacks ();
1628 /* Common finish hook for the C, ObjC and C++ front ends. */
1632 FILE *deps_stream
= NULL
;
1634 if (cpp_opts
->deps
.style
!= DEPS_NONE
)
1636 /* If -M or -MM was seen without -MF, default output to the
1639 deps_stream
= out_stream
;
1642 deps_stream
= fopen (deps_file
, deps_append
? "a": "w");
1644 fatal_io_error ("opening dependency file %s", deps_file
);
1648 /* For performance, avoid tearing down cpplib's internal structures
1649 with cpp_destroy (). */
1650 errorcount
+= cpp_finish (parse_in
, deps_stream
);
1652 if (deps_stream
&& deps_stream
!= out_stream
1653 && (ferror (deps_stream
) || fclose (deps_stream
)))
1654 fatal_io_error ("closing dependency file %s", deps_file
);
1656 if (out_stream
&& (ferror (out_stream
) || fclose (out_stream
)))
1657 fatal_io_error ("when writing output to %s", out_fname
);
1660 /* Either of two environment variables can specify output of
1661 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1662 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1663 and DEPS_TARGET is the target to mention in the deps. They also
1664 result in dependency information being appended to the output file
1665 rather than overwriting it, and like Sun's compiler
1666 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1668 check_deps_environment_vars ()
1672 GET_ENVIRONMENT (spec
, "DEPENDENCIES_OUTPUT");
1674 cpp_opts
->deps
.style
= DEPS_USER
;
1677 GET_ENVIRONMENT (spec
, "SUNPRO_DEPENDENCIES");
1680 cpp_opts
->deps
.style
= DEPS_SYSTEM
;
1681 cpp_opts
->deps
.ignore_main_file
= true;
1687 /* Find the space before the DEPS_TARGET, if there is one. */
1688 char *s
= strchr (spec
, ' ');
1691 /* Let the caller perform MAKE quoting. */
1692 defer_opt (OPT_MT
, s
+ 1);
1696 /* Command line -MF overrides environment variables and default. */
1704 /* Handle deferred command line switches. */
1706 handle_deferred_opts ()
1710 for (i
= 0; i
< deferred_count
; i
++)
1712 struct deferred_opt
*opt
= &deferred_opts
[i
];
1714 if (opt
->code
== OPT_MT
|| opt
->code
== OPT_MQ
)
1715 cpp_add_dependency_target (parse_in
, opt
->arg
, opt
->code
== OPT_MQ
);
1719 /* These settings are appropriate for GCC, but not necessarily so for
1720 cpplib as a library. */
1722 sanitize_cpp_opts ()
1724 /* If we don't know what style of dependencies to output, complain
1725 if any other dependency switches have been given. */
1726 if (deps_seen
&& cpp_opts
->deps
.style
== DEPS_NONE
)
1727 error ("to generate dependencies you must specify either -M or -MM");
1729 /* -dM and dependencies suppress normal output; do it here so that
1730 the last -d[MDN] switch overrides earlier ones. */
1731 if (flag_dump_macros
== 'M')
1734 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1735 -dM since at least glibc relies on -M -dM to work. */
1738 if (flag_dump_macros
!= 'M')
1739 flag_dump_macros
= 0;
1740 flag_dump_includes
= 0;
1743 cpp_opts
->unsigned_char
= !flag_signed_char
;
1744 cpp_opts
->stdc_0_in_system_headers
= STDC_0_IN_SYSTEM_HEADERS
;
1746 /* We want -Wno-long-long to override -pedantic -std=non-c99
1747 and/or -Wtraditional, whatever the ordering. */
1748 cpp_opts
->warn_long_long
1749 = warn_long_long
&& ((!flag_isoc99
&& pedantic
) || warn_traditional
);
1752 /* Add include path with a prefix at the front of its name. */
1754 add_prefixed_path (suffix
, chain
)
1760 size_t prefix_len
, suffix_len
;
1762 suffix_len
= strlen (suffix
);
1763 prefix
= iprefix
? iprefix
: cpp_GCC_INCLUDE_DIR
;
1764 prefix_len
= iprefix
? strlen (iprefix
) : cpp_GCC_INCLUDE_DIR_len
;
1766 path
= xmalloc (prefix_len
+ suffix_len
+ 1);
1767 memcpy (path
, prefix
, prefix_len
);
1768 memcpy (path
+ prefix_len
, suffix
, suffix_len
);
1769 path
[prefix_len
+ suffix_len
] = '\0';
1771 add_path (path
, chain
, 0);
1774 /* Handle -D, -U, -A, -imacros, and the first -include. */
1778 if (!cpp_opts
->preprocessed
)
1782 cpp_rename_file (parse_in
, _("<built-in>"));
1783 cpp_init_builtins (parse_in
);
1784 c_cpp_builtins (parse_in
);
1785 cpp_rename_file (parse_in
, _("<command line>"));
1786 for (i
= 0; i
< deferred_count
; i
++)
1788 struct deferred_opt
*opt
= &deferred_opts
[i
];
1790 if (opt
->code
== OPT_D
)
1791 cpp_define (parse_in
, opt
->arg
);
1792 else if (opt
->code
== OPT_U
)
1793 cpp_undef (parse_in
, opt
->arg
);
1794 else if (opt
->code
== OPT_A
)
1796 if (opt
->arg
[0] == '-')
1797 cpp_unassert (parse_in
, opt
->arg
+ 1);
1799 cpp_assert (parse_in
, opt
->arg
);
1803 /* Handle -imacros after -D and -U. */
1804 for (i
= 0; i
< deferred_count
; i
++)
1806 struct deferred_opt
*opt
= &deferred_opts
[i
];
1808 if (opt
->code
== OPT_imacros
1809 && cpp_push_include (parse_in
, opt
->arg
))
1810 cpp_scan_nooutput (parse_in
);
1814 push_command_line_include ();
1817 /* Give CPP the next file given by -include, if any. */
1819 push_command_line_include ()
1821 if (cpp_opts
->preprocessed
)
1824 while (include_cursor
< deferred_count
)
1826 struct deferred_opt
*opt
= &deferred_opts
[include_cursor
++];
1828 if (opt
->code
== OPT_include
&& cpp_push_include (parse_in
, opt
->arg
))
1832 if (include_cursor
== deferred_count
)
1834 /* Restore the line map from <command line>. */
1835 cpp_rename_file (parse_in
, main_input_filename
);
1836 /* -Wunused-macros should only warn about macros defined hereafter. */
1837 cpp_opts
->warn_unused_macros
= warn_unused_macros
;
1842 /* File change callback. Has to handle -include files. */
1844 cb_file_change (pfile
, new_map
)
1845 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
1846 const struct line_map
*new_map
;
1848 if (flag_preprocess_only
)
1849 pp_file_change (new_map
);
1851 fe_file_change (new_map
);
1853 if (new_map
->reason
== LC_LEAVE
&& MAIN_FILE_P (new_map
))
1854 push_command_line_include ();
1857 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1858 extensions if ISO). There is no concept of gnu94. */
1860 set_std_c89 (c94
, iso
)
1863 cpp_set_lang (parse_in
, c94
? CLK_STDC94
: iso
? CLK_STDC89
: CLK_GNUC89
);
1866 flag_no_gnu_keywords
= iso
;
1867 flag_no_nonansi_builtin
= iso
;
1868 flag_noniso_default_format_attributes
= !iso
;
1871 flag_writable_strings
= 0;
1874 /* Set the C 99 standard (without GNU extensions if ISO). */
1879 cpp_set_lang (parse_in
, iso
? CLK_STDC99
: CLK_GNUC99
);
1881 flag_no_nonansi_builtin
= iso
;
1882 flag_noniso_default_format_attributes
= !iso
;
1886 flag_writable_strings
= 0;
1889 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1894 cpp_set_lang (parse_in
, iso
? CLK_CXX98
: CLK_GNUCXX
);
1895 flag_no_gnu_keywords
= iso
;
1896 flag_no_nonansi_builtin
= iso
;
1897 flag_noniso_default_format_attributes
= !iso
;
1901 /* Handle setting implicit to ON. */
1907 warn_implicit_int
= on
;
1910 if (mesg_implicit_function_declaration
!= 2)
1911 mesg_implicit_function_declaration
= 1;
1914 mesg_implicit_function_declaration
= 0;
1917 /* Args to -d specify what to dump. Silently ignore
1918 unrecognized options; they may be aimed at toplev.c. */
1925 while ((c
= *arg
++) != '\0')
1928 case 'M': /* Dump macros only. */
1929 case 'N': /* Dump names. */
1930 case 'D': /* Dump definitions. */
1931 flag_dump_macros
= c
;
1935 flag_dump_includes
= 1;
1940 /* Write a slash-separated list of languages in FLAGS to BUF. */
1942 write_langs (buf
, flags
)
1947 if (flags
& CL_C_ONLY
)
1949 if (flags
& CL_OBJC_ONLY
)
1953 strcat (buf
, "ObjC");
1955 if (flags
& CL_CXX_ONLY
)
1959 strcat (buf
, "C++");
1963 /* Complain that switch OPT_INDEX does not apply to this front end. */
1965 complain_wrong_lang (opt_index
)
1968 char ok_langs
[60], bad_langs
[60];
1969 int ok_flags
= cl_options
[opt_index
].flags
;
1971 write_langs (ok_langs
, ok_flags
);
1972 write_langs (bad_langs
, ~ok_flags
);
1973 warning ("\"-%s\" is valid for %s but not for %s",
1974 cl_options
[opt_index
].opt_text
, ok_langs
, bad_langs
);
1977 /* Handle --help output. */
1981 /* To keep the lines from getting too long for some compilers, limit
1982 to about 500 characters (6 lines) per chunk. */
1985 -include <file> Include the contents of <file> before other files\n\
1986 -imacros <file> Accept definition of macros in <file>\n\
1987 -iprefix <path> Specify <path> as a prefix for next two options\n\
1988 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1989 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1990 -isystem <dir> Add <dir> to the start of the system include path\n\
1993 -idirafter <dir> Add <dir> to the end of the system include path\n\
1994 -I <dir> Add <dir> to the end of the main include path\n\
1995 -I- Fine-grained include path control; see info docs\n\
1996 -nostdinc Do not search system include directories\n\
1997 (dirs specified with -isystem will still be used)\n\
1998 -nostdinc++ Do not search system include directories for C++\n\
1999 -o <file> Put output into <file>\n\
2002 -trigraphs Support ISO C trigraphs\n\
2003 -std=<std name> Specify the conformance standard; one of:\n\
2004 gnu89, gnu99, c89, c99, iso9899:1990,\n\
2005 iso9899:199409, iso9899:1999, c++98\n\
2006 -w Inhibit warning messages\n\
2007 -W[no-]trigraphs Warn if trigraphs are encountered\n\
2008 -W[no-]comment{s} Warn if one comment starts inside another\n\
2011 -W[no-]traditional Warn about features not present in traditional C\n\
2012 -W[no-]undef Warn if an undefined macro is used by #if\n\
2013 -W[no-]import Warn about the use of the #import directive\n\
2016 -W[no-]error Treat all warnings as errors\n\
2017 -W[no-]system-headers Do not suppress warnings from system headers\n\
2018 -W[no-]all Enable most preprocessor warnings\n\
2021 -M Generate make dependencies\n\
2022 -MM As -M, but ignore system header files\n\
2023 -MD Generate make dependencies and compile\n\
2024 -MMD As -MD, but ignore system header files\n\
2025 -MF <file> Write dependency output to the given file\n\
2026 -MG Treat missing header file as generated files\n\
2029 -MP Generate phony targets for all headers\n\
2030 -MQ <target> Add a MAKE-quoted target\n\
2031 -MT <target> Add an unquoted target\n\
2034 -D<macro> Define a <macro> with string '1' as its value\n\
2035 -D<macro>=<val> Define a <macro> with <val> as its value\n\
2036 -A<question>=<answer> Assert the <answer> to <question>\n\
2037 -A-<question>=<answer> Disable the <answer> to <question>\n\
2038 -U<macro> Undefine <macro> \n\
2039 -v Display the version number\n\
2042 -H Print the name of header files as they are used\n\
2043 -C Do not discard comments\n\
2044 -dM Display a list of macro definitions active at end\n\
2045 -dD Preserve macro definitions in output\n\
2046 -dN As -dD except that only the names are preserved\n\
2047 -dI Include #include directives in the output\n\
2050 -f[no-]preprocessed Treat the input file as already preprocessed\n\
2051 -ftabstop=<number> Distance between tab stops for column reporting\n\
2052 -isysroot <dir> Set <dir> to be the system root directory\n\
2053 -P Do not generate #line directives\n\
2054 -remap Remap file names when including files\n\
2055 --help Display this information\n\