[m-rev.] for review: options variables for specific types of C compiler
Julien Fischer
juliensf at csse.unimelb.edu.au
Fri Aug 5 17:20:45 AEST 2011
For review by anyone.
Branches: main, 11.07
Support new options variables in Mercury.options files that allow flags
for a specific type of C compiler to be given. The new variables are:
GCC_FLAGS - for C compiler flags specific to GCC.
CLANG_FLAGS - for C compiler flags specific to clang.
MSVC_FLAGS - for C compiler flags specific to Visual C.
The above are only passed to the C compiler when the C compiler type
corresponds to the variable; they are ignored if it does not. The motivation
for this addition is that you often need to pass some additional flags to a
specific C compiler, e.g. to suppress a warning or disable an optimization, but
using only mmc --make and options files there is currently no easy way to this.
The above functionality is currently only implemented for mmc --make.
(I don't have any plans to implement it for mmake.)
compiler/options_file.m:
Support the three new variables.
compiler/compile_target_code.m:
When collecting the flags to pass to the C compiler, also gather
up any flags specifically for a C compiler whose type matches the
current C compiler type.
compiler/options.m:
Add new internal options required by the above.
doc/user_guide.texi:
Document the above.
Julien.
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.172
diff -u -r1.172 compile_target_code.m
--- compiler/compile_target_code.m 13 Jul 2011 06:49:20 -0000 1.172
+++ compiler/compile_target_code.m 3 Aug 2011 14:49:40 -0000
@@ -415,6 +415,7 @@
gather_c_compiler_flags(Globals, PIC, AllCFlags) :-
globals.lookup_accumulating_option(Globals, cflags, C_Flags_List),
join_string_list(C_Flags_List, "", "", " ", CFLAGS),
+ gather_compiler_specific_flags(Globals, CC_Specific_CFLAGS),
globals.lookup_bool_option(Globals, use_subdirs, UseSubdirs),
(
@@ -878,12 +879,13 @@
% it can override -fomit-frame-pointer with -fno-omit-frame-pointer.
% Also be careful that each option is separated by spaces.
%
- % In general, user supplied C compiler flags, i.e. CFLAGS below, should
- % be able to override those introduced by the Mercury compiler.
+ % In general, user supplied C compiler flags, i.e. CFLAGS and
+ % CC_Specific_CFLAGS below, should be able to override those introduced by
+ % the Mercury compiler.
% In some circumstances we want to prevent the user doing this, typically
% where we know the behaviour of a particular C compiler is buggy; the
% last option, OverrideOpts, does this -- because of this it must be
- % listed after CFLAGS.
+ % listed after CFLAGS and CC_Specific_CFLAGS.
%
string.append_list([
SubDirInclOpt, InclOpt, " ",
@@ -918,8 +920,30 @@
C_FnAlignOpt,
WarningOpt, " ",
CFLAGS, " ",
+ CC_Specific_CFLAGS, " ",
OverrideOpts], AllCFlags).
+:- pred gather_compiler_specific_flags(globals::in, string::out) is det.
+
+gather_compiler_specific_flags(Globals, Flags) :-
+ globals.get_c_compiler_type(Globals, C_CompilerType),
+ (
+ C_CompilerType = cc_gcc(_, _, _),
+ globals.lookup_accumulating_option(Globals, gcc_flags, FlagsList)
+ ;
+ C_CompilerType = cc_clang(_),
+ globals.lookup_accumulating_option(Globals, clang_flags, FlagsList)
+ ;
+ C_CompilerType = cc_cl(_),
+ globals.lookup_accumulating_option(Globals, msvc_flags, FlagsList)
+ ;
+ ( C_CompilerType = cc_lcc
+ ; C_CompilerType = cc_unknown
+ ),
+ FlagsList = []
+ ),
+ join_string_list(FlagsList, "", "", " ", Flags).
+
:- pred get_maybe_filtercc_command(globals::in, maybe(string)::out) is det.
get_maybe_filtercc_command(Globals, MaybeFilterCmd) :-
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.697
diff -u -r1.697 options.m
--- compiler/options.m 1 Aug 2011 03:30:26 -0000 1.697
+++ compiler/options.m 3 Aug 2011 14:54:50 -0000
@@ -806,6 +806,14 @@
; ansi_c
; inline_alloc
+ % Flags for specific C compilers.
+ ; gcc_flags
+ ; quoted_gcc_flag
+ ; clang_flags
+ ; quoted_clang_flag
+ ; msvc_flags
+ ; quoted_msvc_flag
+
% Auto-configured C compilation options.
; cflags_for_warnings
; cflags_for_optimization
@@ -1660,6 +1668,13 @@
cflags - accumulating([]),
quoted_cflag - string_special,
+ gcc_flags - accumulating([]),
+ quoted_gcc_flag - string_special,
+ clang_flags - accumulating([]),
+ quoted_clang_flag - string_special,
+ msvc_flags - accumulating([]),
+ quoted_msvc_flag - string_special,
+
cflags_for_warnings - string(""),
% The `mmc' script will override the
% default with values determined at
@@ -2596,6 +2611,14 @@
long_option("ansi-c", ansi_c).
long_option("cflags", cflags).
long_option("cflag", quoted_cflag).
+
+long_option("gcc-flags", gcc_flags).
+long_option("gcc-flag", quoted_gcc_flag).
+long_option("clang-flags", clang_flags).
+long_option("clang-flag", quoted_clang_flag).
+long_option("msvc-flags", msvc_flags).
+long_option("msvc-flag", quoted_msvc_flag).
+
long_option("cflags-for-warnings", cflags_for_warnings).
long_option("cflags-for-optimization", cflags_for_optimization).
long_option("cflags-for-ansi", cflags_for_ansi).
@@ -2980,6 +3003,15 @@
special_handler(quoted_cflag, string(Flag),
OptionTable0, ok(OptionTable)) :-
handle_quoted_flag(cflags, Flag, OptionTable0, OptionTable).
+special_handler(quoted_gcc_flag, string(Flag),
+ OptionTable0, ok(OptionTable)) :-
+ handle_quoted_flag(gcc_flags, Flag, OptionTable0, OptionTable).
+special_handler(quoted_clang_flag, string(Flag),
+ OptionTable0, ok(OptionTable)) :-
+ handle_quoted_flag(clang_flags, Flag, OptionTable0, OptionTable).
+special_handler(quoted_msvc_flag, string(Flag),
+ OptionTable0, ok(OptionTable)) :-
+ handle_quoted_flag(msvc_flags, Flag, OptionTable0, OptionTable).
special_handler(quoted_java_flag, string(Flag),
OptionTable0, ok(OptionTable)) :-
handle_quoted_flag(java_flags, Flag, OptionTable0, OptionTable).
@@ -5305,6 +5337,11 @@
"\t`--cflag' should be used for single words which need",
"\tto be quoted when passed to the shell.",
+ % The --gcc-flags, --gcc-flag, --clang-flags, --clang-flag,
+ % --msvc-flags and --msvc-flag options are an internal
+ % part of the implementation of mmc --make; they are deliberately
+ % not documented.
+
% The --cflags-for-regs, --cflags-for-gotos,
% --cflags-for-threads, --cflags-for-pic,
% --cflags-for-warnings, --cflags-for-ansi,
Index: compiler/options_file.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options_file.m,v
retrieving revision 1.58
diff -u -r1.58 options_file.m
--- compiler/options_file.m 23 May 2011 05:08:09 -0000 1.58
+++ compiler/options_file.m 5 Aug 2011 07:01:23 -0000
@@ -885,6 +885,9 @@
---> grade_flags
; mmc_flags
; c_flags
+ ; gcc_flags
+ ; clang_flags
+ ; msvc_flags
; java_flags
; ilasm_flags
; csharp_flags
@@ -914,7 +917,8 @@
% `MCFLAGS'. Settings in `MCFLAGS' (e.g. `--no-mercury-stdlib-dir')
% should override settings of these in the environment.
[grade_flags, linkage, mercury_linkage, lib_grades, lib_linkages,
- stdlib_dir, config_dir, mmc_flags, c_flags, java_flags, ilasm_flags,
+ stdlib_dir, config_dir, mmc_flags, c_flags, gcc_flags, clang_flags,
+ msvc_flags, java_flags, ilasm_flags,
csharp_flags, erlang_flags,
ml_objs, lib_dirs, ld_flags, ld_libflags,
libraries, ml_libs, c2init_args, install_prefix].
@@ -924,6 +928,9 @@
options_variable_name(grade_flags) = "GRADEFLAGS".
options_variable_name(mmc_flags) = "MCFLAGS".
options_variable_name(c_flags) = "CFLAGS".
+options_variable_name(gcc_flags) = "GCC_FLAGS".
+options_variable_name(clang_flags) = "CLANG_FLAGS".
+options_variable_name(msvc_flags) = "MSVC_FLAGS".
options_variable_name(java_flags) = "JAVACFLAGS".
options_variable_name(ilasm_flags) = "ILASMFLAGS".
options_variable_name(csharp_flags) = "CSCFLAGS".
@@ -948,6 +955,9 @@
options_variable_type_is_target_specific(grade_flags) = no.
options_variable_type_is_target_specific(mmc_flags) = yes.
options_variable_type_is_target_specific(c_flags) = yes.
+options_variable_type_is_target_specific(gcc_flags) = yes.
+options_variable_type_is_target_specific(clang_flags) = yes.
+options_variable_type_is_target_specific(msvc_flags) = yes.
options_variable_type_is_target_specific(java_flags) = yes.
options_variable_type_is_target_specific(ilasm_flags) = yes.
options_variable_type_is_target_specific(csharp_flags) = yes.
@@ -1007,6 +1017,9 @@
mmc_option_type(grade_flags) = mmc_flags.
mmc_option_type(mmc_flags) = mmc_flags.
mmc_option_type(c_flags) = option([], "--cflag").
+mmc_option_type(gcc_flags) = option([], "--gcc-flag").
+mmc_option_type(clang_flags) = option([], "--clang-flag").
+mmc_option_type(msvc_flags) = option([], "--msvc-flag").
mmc_option_type(java_flags) = option([], "--java-flag").
mmc_option_type(ilasm_flags) = option([], "--ilasm-flag").
mmc_option_type(csharp_flags) = option([], "--csharp-flag").
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.634
diff -u -r1.634 user_guide.texi
--- doc/user_guide.texi 1 Aug 2011 03:31:03 -0000 1.634
+++ doc/user_guide.texi 3 Aug 2011 15:46:26 -0000
@@ -904,6 +904,35 @@
@end table
+The following variables can also appear in options files but are
+ at emph{only} supported by @samp{mmc --make}.
+
+ at table @code
+
+ at item GCC_FLAGS
+ at vindex GCC_FLAGS
+Options to pass to the C compiler, but only if the C compiler is GCC.
+If the C compiler is not GCC then this variable is ignored.
+These options will be passed @emph{after} any options given by the
+ at samp{CFLAGS} variable.
+
+ at item CLANG_FLAGS
+ at vindex CLANG_FLAGS
+Options to pass to the C compiler, but only if the C compiler is clang.
+If the C compiler is not clang then this variable is ignored.
+These options will be passed @emph{after} any options given by the
+ at samp{CFLAGS} variable.
+
+ at item MSVC_FLAGS
+ at vindex MSVC_FLAGS
+Options to pass to the C compiler, but on if the C compiler is
+Microsoft Visual C.
+If the C compiler is not Visual C then this variable is ignored.
+These options will be passed @emph{after} any options given by the
+ at samp{CFLAGS} variable.
+
+ at end table
+
@c ----------------------------------------------------------------------------
@node Libraries
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list