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

Jeremy Huddleston jeremyhu at apple.com
Tue Nov 1 13:16:20 PDT 2011


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

diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in
index 3b02190..c4a521f 100644
--- a/xorg-macros.m4.in
+++ b/xorg-macros.m4.in
@@ -1378,6 +1378,33 @@ 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
+#
+# Append the given flag to the given variable if the compiler supports it.
+#
+AC_DEFUN([XORG_TESTSET_CFLAG], [
+# If the module's configure.ac calls AC_PROG_CC later on, CC gets set to C89
+AC_REQUIRE([AC_PROG_CC_C99])
+ifelse([$#], [0], [AC_MSG_ERROR("Incorrect arguments to XORG_TESTSET_CFLAG")],
+       [$#], [1], :,
+       [save_CFLAGS="$CFLAGS"
+        CFLAGS="$CFLAGS $2"
+        AC_MSG_CHECKING([if $CC supports $2])
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE([], [return 0;])],
+                          supported=yes, supported=no)
+        CFLAGS="$save_CFLAGS"
+        if test "$supported" = "yes" ; then
+            AC_MSG_RESULT([yes])
+            $1="$$1 $2"
+        else
+            AC_MSG_RESULT([no])
+            dnl XORG_TESTSET_CFLAG($1, shift(shift($@))))
+        fi
+       ])
+]) # XORG_TESTSET_CFLAG
+
 # XORG_CWARNFLAGS
 # ---------------
 # Minimum version: 1.2.0
-- 
1.7.7



More information about the xorg-devel mailing list