[PATCH util-macros v2 2/6] Add XORG_TESTSET_CFLAG which can be used to test what flags the compiler supports

Jeremy Huddleston jeremyhu at apple.com
Thu Nov 3 01:19:36 PDT 2011


Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
---
 xorg-macros.m4.in |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

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(<variable>, <flag>, [<alternative flag>, ...])
+# ---------------
+# 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
-- 
1.7.7



More information about the xorg-devel mailing list