[PATCH macros 2/2] Define BASE_CXXFLAGS when C++ is the chosen language

Chase Douglas chase.douglas at canonical.com
Wed Feb 29 15:54:16 PST 2012


On 02/29/2012 02:58 PM, Gaetan Nadon wrote:
> On 12-02-29 03:24 PM, Chase Douglas wrote:
>> Set the language to C++ before calling XORG_DEFAULT_OPTIONS. This can be
>> done by calling AC_LANG(C++).
> Is this sentence a recommendation of what to do in a module or does it
> describe what the patch does?
> I am a little confused.

You're right, I should have prefixed it with "You can use this by ...":

You can use this functionality by setting the language to C++ before 
calling XORG_DEFAULT_OPTIONS. This can accomplished with AC_LANG(C++).

>>
>> Signed-off-by: Chase Douglas<chase.douglas at canonical.com>
>> ---
>>   xorg-macros.m4.in |  166 ++++++++++++++++++++++++++++++----------------------
>>   1 files changed, 96 insertions(+), 70 deletions(-)
>>
>> diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in
>> index 9041542..e5b468f 100644
>> --- a/xorg-macros.m4.in
>> +++ b/xorg-macros.m4.in
>> @@ -1528,13 +1528,13 @@ dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname
>>   # ---------------
>>   # Minimum version: 1.16.0
>>   #
>> -# Defines BASE_CFLAGS to contain a set of command line arguments supported
>> -# by the selected compiler which do NOT alter the generated code.  These
>> -# arguments will cause the compiler to print various warnings during
>> -# compilation AND turn a conservative set of warnings into errors.
>> +# Defines BASE_CFLAGS or BASE_CXXFLAGS to contain a set of command line
>> +# arguments supported by the selected compiler which do NOT alter the generated
>> +# code.  These arguments will cause the compiler to print various warnings
>> +# during compilation AND turn a conservative set of warnings into errors.
>>   #
>> -# The set of flags supported by BASE_CFLAGS will grow in future
>> -# versions of util-macros as options are added to new compilers.
>> +# The set of flags supported by BASE_CFLAGS and BASE_CXXFLAGS will grow in
>> +# future versions of util-macros as options are added to new compilers.
>>   #
>>   AC_DEFUN([XORG_COMPILER_FLAGS], [
>>   AC_REQUIRE([XORG_COMPILER_BRAND])
> Note that XORG_COMPILER_BRAND calls AC_PROG_CC_C99 which I think can
> reset the language back to C.

Perhaps I should use AC_LANG_CASE() in XORG_COMPILER_BRAND as well? I 
think wrapping AC_REQUIRE([AC_PROG_CC_C99]) would suffice. The rest 
should be fine for CC and CXX both. Any issues with that?

>> @@ -1545,76 +1545,89 @@ AC_ARG_ENABLE(selective-werror,
>>                 [SELECTIVE_WERROR=$enableval],
>>                 [SELECTIVE_WERROR=yes])
>>
>> +AC_LANG_CASE(
> So the test here would always result in C. I am not sure, it's hard to
> follow.

Your logic seems right, but I can confirm that it works as I intedended. 
Hopefully with the fix to XORG_COMPILER_BRAND we will be working 
properly for sure.

> The reason you see some AC_PROG_CC_C99 is that there is always a
> theoretical possibility  that a be called without the module having
> first called XORG_DEFAULT_OPTIONS. By usage, this will not happen as all
> modules call XORG_DEFAULT_OPTIONS early up. It is safe to removing it if
> it gets too much in the way.

I'm not sure what you are commenting on here...

I am guessing that you meant to comment below where AC_PROG_CC_C99 is 
called, which is the case in one of the AC_LANG_CASE statements. If so, 
I'm happy to remove it, leave it, or change it. Just let me know.

> All of X.Org is compiled with C, so it is not surprising to see this
> assumption everywhere.
>
> This is great.
>> +        [C], [
>> +                define([PREFIX], [C])
>> +        ],
>> +        [C++], [
>> +                define([PREFIX], [CXX])
>> +        ]
>> +)
>>   # -v is too short to test reliably with XORG_TESTSET_CFLAG
>>   if test "x$SUNCC" = "xyes"; then
>> -    BASE_CFLAGS="-v"
>> +    [BASE_]PREFIX[FLAGS]="-v"
>>   else
>> -    BASE_CFLAGS=""
>> +    [BASE_]PREFIX[FLAGS]=""
>>   fi
>>
>>   # This chunk of warnings were those that existed in the legacy CWARNFLAGS
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wall])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wpointer-arith])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wstrict-prototypes])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wmissing-prototypes])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wmissing-declarations])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wnested-externs])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wbad-function-cast])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wformat=2], [-Wformat])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wold-style-definition])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wdeclaration-after-statement])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wall])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-arith])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-declarations])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wformat=2], [-Wformat])
>> +
>> +AC_LANG_CASE(
>> +	[C], [
>> +		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wstrict-prototypes])
>> +		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-prototypes])
>> +		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnested-externs])
>> +		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wbad-function-cast])
>> +		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wold-style-definition])
>> +		XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wdeclaration-after-statement])
>> +	]
>> +)
>>
>>   # This chunk adds additional warnings that could catch undesired effects.
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wunused])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wuninitialized])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wshadow])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wcast-qual])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wmissing-noreturn])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wmissing-format-attribute])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wredundant-decls])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wunused])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wuninitialized])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wshadow])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-qual])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-noreturn])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-format-attribute])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wredundant-decls])
>>
>>   # These are currently disabled because they are noisy.  They will be enabled
>>   # in the future once the codebase is sufficiently modernized to silence
>>   # them.  For now, I don't want them to drown out the other warnings.
>> -# XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wlogical-op])
>> -# XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wparentheses])
>> -# XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wcast-align])
>> +# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op])
>> +# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses])
>> +# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align])
>>
>>   # Turn some warnings into errors, so we don't accidently get successful builds
>>   # when there are problems that should be fixed.
>>
>>   if test "x$SELECTIVE_WERROR" = "xyes" ; then
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=nonnull])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=init-self])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=main])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=missing-braces])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=sequence-point])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=trigraphs])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=array-bounds])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=write-strings])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=address])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=nonnull])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=init-self])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=main])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=missing-braces])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=sequence-point])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=trigraphs])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=array-bounds])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=write-strings])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=address])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION
>>   else
>>   AC_MSG_WARN([You have chosen not to turn some select compiler warnings into errors.  This should not be necessary.  Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wimplicit])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wnonnull])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Winit-self])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wmain])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wmissing-braces])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wsequence-point])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wreturn-type])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wtrigraphs])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Warray-bounds])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wwrite-strings])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Waddress])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wint-to-pointer-cast])
>> -XORG_TESTSET_CFLAG([BASE_CFLAGS], [-Wpointer-to-int-cast])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wimplicit])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnonnull])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Winit-self])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmain])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-braces])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wsequence-point])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wreturn-type])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wtrigraphs])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Warray-bounds])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wwrite-strings])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Waddress])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wint-to-pointer-cast])
>> +XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-to-int-cast])
>>   fi
>>
>> -AC_SUBST([BASE_CFLAGS])
>> +AC_SUBST([BASE_]PREFIX[FLAGS])
>>   ]) # XORG_COMPILER_FLAGS
>>
>>   # XORG_CWARNFLAGS
>> @@ -1632,11 +1645,15 @@ AC_SUBST([BASE_CFLAGS])
>>   AC_DEFUN([XORG_CWARNFLAGS], [
>>   AC_REQUIRE([XORG_COMPILER_FLAGS])
>>   AC_REQUIRE([XORG_COMPILER_BRAND])
>> -CWARNFLAGS="$BASE_CFLAGS"
>> -if  test "x$GCC" = xyes ; then
>> -    CWARNFLAGS="$CWARNFLAGS -fno-strict-aliasing"
>> -fi
>> -AC_SUBST(CWARNFLAGS)
>> +AC_LANG_CASE(
>> +	[C], [
>> +		CWARNFLAGS="$BASE_CFLAGS"
>> +		if  test "x$GCC" = xyes ; then
>> +		    CWARNFLAGS="$CWARNFLAGS -fno-strict-aliasing"
>> +		fi
>> +		AC_SUBST(CWARNFLAGS)
>> +	]
>> +)
>>   ]) # XORG_CWARNFLAGS
>>
>>   # XORG_STRICT_OPTION
>> @@ -1646,7 +1663,7 @@ AC_SUBST(CWARNFLAGS)
>>   # Add configure option to enable strict compilation flags, such as treating
>>   # warnings as fatal errors.
>>   # If --enable-strict-compilation is passed to configure, adds strict flags to
>> -# $BASE_CFLAGS and the deprecated $CWARNFLAGS.
>> +# $BASE_CFLAGS or $BASE_CXXFLAGS and the deprecated $CWARNFLAGS.
>>   #
>>   # Starting in 1.14.0 also exports $STRICT_CFLAGS for use in other tests or
>>   # when strict compilation is unconditionally desired.
>> @@ -1659,21 +1676,30 @@ AC_ARG_ENABLE(strict-compilation,
>>   			  [Enable all warnings from compiler and make them errors (default: disabled)]),
>>   			  [STRICT_COMPILE=$enableval], [STRICT_COMPILE=no])
>>
>> -STRICT_CFLAGS=""
>> -XORG_TESTSET_CFLAG([STRICT_CFLAGS], [-pedantic])
>> -XORG_TESTSET_CFLAG([STRICT_CFLAGS], [-Werror], [-errwarn])
>> +AC_LANG_CASE(
>> +        [C], [
>> +                define([PREFIX], [C])
>> +        ],
>> +        [C++], [
>> +                define([PREFIX], [CXX])
>> +        ]
>> +)
>> +
>> +[STRICT_]PREFIX[FLAGS]=""
>> +XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-pedantic])
>> +XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror], [-errwarn])
>>
>>   # Earlier versions of gcc (eg: 4.2) support -Werror=attributes, but do not
>>   # activate it with -Werror, so we add it here explicitly.
>> -XORG_TESTSET_CFLAG([STRICT_CFLAGS], [-Werror=attributes])
>> +XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror=attributes])
>>
>>   if test "x$STRICT_COMPILE" = "xyes"; then
>> -    BASE_CFLAGS="$BASE_CFLAGS $STRICT_CFLAGS"
>> -    CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"
>> +    [BASE_]PREFIX[FLAGS]="$[BASE_]PREFIX[FLAGS] $[STRICT_]PREFIX[FLAGS]"
>> +    AC_LANG_CASE([C], [CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"])
>>   fi
>> -AC_SUBST([STRICT_CFLAGS])
>> -AC_SUBST([BASE_CFLAGS])
>> -AC_SUBST([CWARNFLAGS])
>> +AC_SUBST([STRICT_]PREFIX[FLAGS])
>> +AC_SUBST([BASE_]PREFIX[FLAGS])
>> +AC_LANG_CASE([C], AC_SUBST([CWARNFLAGS]))
>>   ]) # XORG_STRICT_OPTION
>>
>>   # XORG_DEFAULT_OPTIONS
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>



More information about the xorg-devel mailing list