summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2011-11-01 11:39:14 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2011-11-06 16:07:55 -0800
commit9f427611f4bb6db60cb8cbdda6296a3bf66a5a6c (patch)
treef06d128a2b536331302cf6351007636b587e30f1
parent4a6ecc7b8e338483fb5ea6bfc9b2fb26f890807b (diff)
Add XORG_TESTSET_CFLAG which can be used to test what flags the compiler supports
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com> Reviewed-by: Gaetan Nadon <memsize@videotron.ca>
-rw-r--r--xorg-macros.m4.in52
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