[json-glib] [build] Add AS_COMPILER_FLAGS
- From: Emmanuele Bassi <ebassi src gnome org>
- To: svn-commits-list gnome org
- Subject: [json-glib] [build] Add AS_COMPILER_FLAGS
- Date: Tue, 9 Jun 2009 06:35:17 -0400 (EDT)
commit 3ddeb7a8779a4c51453289aa15af130af480eea6
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Tue Jun 9 11:24:54 2009 +0100
[build] Add AS_COMPILER_FLAGS
Use the m4 AS_COMPILER_FLAGS macro to check for the maintainer
compiler flags supported by the C compiler. This should allow the
build to handle gracefully different versions of GCC.
---
.gitignore | 1 +
Makefile.am | 2 +
build/autotools/Makefile.am | 2 +-
build/autotools/as-compiler-flag.m4 | 62 +++++++++++++++++++++++++++++++++++
configure.ac | 5 ++-
5 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
index 7963496..048ec7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ aclocal.m4
autom4te.cache
/build/autotools/*.m4
!/build/autotools/shave.m4
+!/build/autotools/as-compiler-flag.m4
configure
config.guess
config.h
diff --git a/Makefile.am b/Makefile.am
index d06623f..88aea79 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,7 @@
include $(top_srcdir)/Makefile.decl
+ACLOCAL_AMFLAGS = -I build/autotools
+
SUBDIRS = json-glib doc
if ENABLE_GLIB_TEST
diff --git a/build/autotools/Makefile.am b/build/autotools/Makefile.am
index a17717f..899cbc9 100644
--- a/build/autotools/Makefile.am
+++ b/build/autotools/Makefile.am
@@ -1,3 +1,3 @@
-EXTRA_DIST = shave-libtool.in shave.in shave.m4
+EXTRA_DIST = shave-libtool.in shave.in shave.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
index 0000000..0f660cf
--- /dev/null
+++ b/build/autotools/as-compiler-flag.m4
@@ -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"
+])
+
diff --git a/configure.ac b/configure.ac
index 1d3e939..ef2d166 100644
--- a/configure.ac
+++ b/configure.ac
@@ -108,7 +108,10 @@ AC_ARG_ENABLE([maintainer-flags],
AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
[
- MAINTAINER_CFLAGS="-Werror -Wall -Wshadow -Wcast-align -Wno-uninitialized -Wformat-security -Winit-self"
+ AS_COMPILER_FLAGS([MAINTAINER_CFLAGS],
+ ["-Werror -Wall -Wshadow -Wcast-align
+ -Wno-uninitialized -Wformat-security
+ -Winit-self -Wempty-body"])
]
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]