[build] Use AS_COMPILER_FLAGS
authorEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 22 Jun 2009 17:15:17 +0000 (18:15 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 22 Jun 2009 17:16:10 +0000 (18:16 +0100)
We should use the AS_COMPILER_FLAGS m4 macro to allow for graceful
handling of compiler flags on different versions of GCC and on
different compilers.

build/autotools/Makefile.am
build/autotools/as-compiler-flag.m4 [new file with mode: 0644]
configure.ac

index 8b1268d..b911023 100644 (file)
@@ -1,3 +1,8 @@
-EXTRA_DIST = shave-libtool.in shave.in shave.m4 introspection.m4
+EXTRA_DIST = \
+       shave-libtool.in        \
+       shave.in                \
+       shave.m4                \
+       introspection.m4        \
+       as-compiler-flag.m4
 
 DISTCLEANFILES = shave-libtool shave
diff --git a/build/autotools/as-compiler-flag.m4 b/build/autotools/as-compiler-flag.m4
new file mode 100644 (file)
index 0000000..0f660cf
--- /dev/null
@@ -0,0 +1,62 @@
+dnl as-compiler-flag.m4 0.1.0
+
+dnl autostars m4 macro for detection of compiler flags
+
+dnl David Schleef <ds@schleef.org>
+
+dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $
+
+dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CFLAGS.
+dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
+dnl and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([AS_COMPILER_FLAG],
+[
+  AC_MSG_CHECKING([to see if compiler understands $1])
+
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $1"
+
+  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+  CFLAGS="$save_CFLAGS"
+
+  if test "X$flag_ok" = Xyes ; then
+    m4_ifvaln([$2],[$2])
+    true
+  else
+    m4_ifvaln([$3],[$3])
+    true
+  fi
+  AC_MSG_RESULT([$flag_ok])
+])
+
+dnl AS_COMPILER_FLAGS(VAR, FLAGS)
+dnl Tries to compile with the given CFLAGS.
+
+AC_DEFUN([AS_COMPILER_FLAGS],
+[
+  list=$2
+  flags_supported=""
+  flags_unsupported=""
+  AC_MSG_CHECKING([for supported compiler flags])
+  for each in $list
+  do
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS $each"
+    AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+    CFLAGS="$save_CFLAGS"
+
+    if test "X$flag_ok" = Xyes ; then
+      flags_supported="$flags_supported $each"
+    else
+      flags_unsupported="$flags_unsupported $each"
+    fi
+  done
+  AC_MSG_RESULT([$flags_supported])
+  if test "X$flags_unsupported" != X ; then
+    AC_MSG_WARN([unsupported compiler flags: $flags_unsupported])
+  fi
+  $1="$$1 $flags_supported"
+])
+
index 7c9a213..7884b18 100644 (file)
@@ -132,7 +132,10 @@ AC_ARG_ENABLE([maintainer-flags],
 MAINTAINER_CFLAGS=""
 AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
       [
-        MAINTAINER_CFLAGS="-Werror -Wall -Wshadow -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self"
+        AS_COMPILER_FLAGS([MAINTAINER_CFLAGS],
+                          ["-Werror -Wall -Wshadow -Wcast-align
+                            -Wno-uninitialized -Wempty-body -Wformat-security
+                            -Winit-self"])
       ]
 )