From 9f427611f4bb6db60cb8cbdda6296a3bf66a5a6c Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Tue, 1 Nov 2011 11:39:14 -0700 Subject: Add XORG_TESTSET_CFLAG which can be used to test what flags the compiler supports Signed-off-by: Jeremy Huddleston Reviewed-by: Gaetan Nadon --- xorg-macros.m4.in | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in index 534afba..1ece326 100644 --- a/xorg-macros.m4.in +++ b/xorg-macros.m4.in @@ -1378,6 +1378,58 @@ AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"]) AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) ]) # XORG_COMPILER_BRAND +# XORG_TESTSET_CFLAG(, , [, ...]) +# --------------- +# Minimum version: 1.16.0 +# +# Test if the compiler works when passed the given flag as a command line argument. +# If it succeeds, the flag is appeneded to the given variable. If not, it tries the +# next flag in the list until there are no more options. +# +# Note that this does not guarantee that the compiler supports the flag as some +# compilers will simply ignore arguments that they do not understand, but we do +# attempt to weed out false positives by using -Werror=unknown-warning-option +# +AC_DEFUN([XORG_TESTSET_CFLAG], [ +AC_REQUIRE([AC_PROG_CC_C99]) +m4_if([$#], 0, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])]) +m4_if([$#], 1, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])]) + +xorg_testset_save_CFLAGS="$CFLAGS" + +if test "x$xorg_testset_unknown_warning_option" = "x" ; then + CFLAGS="$CFLAGS -Werror=unknown-warning-option" + AC_MSG_CHECKING([if $CC supports -Werror=unknown-warning-option]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], + [xorg_testset_unknown_warning_option=yes], + [xorg_testset_unknown_warning_option=no]) + AC_MSG_RESULT([$xorg_testset_unknown_warning_option]) + CFLAGS="$xorg_testset_save_CFLAGS" +fi + +found="no" +m4_foreach([flag], m4_cdr($@), [ + if test $found = "no" ; then + if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then + CFLAGS="$CFLAGS -Werror=unknown-warning-option ]flag[" + else + CFLAGS="$CFLAGS ]flag[" + fi + + AC_MSG_CHECKING([if $CC supports ]flag[]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])], + [supported=yes], [supported=no]) + AC_MSG_RESULT([$supported]) + CFLAGS="$xorg_testset_save_CFLAGS" + + if test "$supported" = "yes" ; then + $1="$$1 ]flag[" + found="yes" + fi + fi +]) +]) # XORG_TESTSET_CFLAG + # XORG_CWARNFLAGS # --------------- # Minimum version: 1.2.0 -- cgit v1.2.3