[unique] [build] Use the AS_COMPILER_FLAGS m4 macro
- From: Emmanuele Bassi <ebassi src gnome org>
- To: svn-commits-list gnome org
- Subject: [unique] [build] Use the AS_COMPILER_FLAGS m4 macro
- Date: Sun, 14 Jun 2009 05:58:32 -0400 (EDT)
commit dd79ac1bd92afe4002c5ce6d99fda1ebadd26337
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sun Jun 14 10:52:19 2009 +0100
[build] Use the AS_COMPILER_FLAGS m4 macro
We need to check if the compiler we use has support for the anal-retentive
maintainer flags we enable with --enable-maintainer-flags. The m4 macro
AS_COMPILER_FLAGS allows us to fall back gracefully to the subset of flags
that the compiler supports.
.gitignore | 4 ++-
build/autotools/Makefile.am | 2 +-
build/autotools/as-compiler-flag.m4 | 62 +++++++++++++++++++++++++++++++++++
configure.ac | 12 ++++--
4 files changed, 74 insertions(+), 6 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 77e14ed..40e9c84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,9 @@ INSTALL
Makefile
Makefile.in
aclocal.m4
-/build/autotools/gtk-doc.m4
+!/build/autotools/shave.m4
+!/build/autotools/as-compiler-flag.m4
+/build/autotools/*.m4
/build/autotools/shave
/build/autotools/shave-libtool
config.guess
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 5341ec5..bdba30c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,7 +106,7 @@ AS_CASE([$enable_dbus],
[no], [have_dbus=no],
- [*], [AC_MSG_ERROR([Unknown argument to --enable-dbus])]
+ [AC_MSG_ERROR([Unknown argument to --enable-dbus])]
)
AS_IF([test "x$have_dbus" = "xyes"],
@@ -170,11 +170,15 @@ 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 -Wempty-body -Wformat-security -Winit-self"
- AC_SUBST(MAINTAINER_CFLAGS)
+ AS_COMPILER_FLAGS([MAINTAINER_CFLAGS],
+ ["-Werror -Wall -Wshadow -Wcast-align
+ -Wno-uninitialized -Wempty-body -Wformat-security
+ -Winit-self"])
]
)
+AC_SUBST(MAINTAINER_CFLAGS)
+
# enable debug flags and symbols
m4_define([debug_default], [m4_if(m4_eval(unique_minor_version % 2), [1], [yes], [minimum])])
AC_ARG_ENABLE([debug],
@@ -201,7 +205,7 @@ AS_CASE([$enable_debug],
UNIQUE_DEBUG_CFLAGS="-DG_DISABLE_CAST_CHECKS"
]
- [*], [AC_MSG_ERROR([Unknown argument to --enable-debug])]
+ [AC_MSG_ERROR([Unknown argument to --enable-debug])]
)
AC_SUBST(UNIQUE_DEBUG_CFLAGS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]