telepathy-idle: Bring in the compiler/linker warnings from telepathy-glib
Simon McVittie
smcv at kemper.freedesktop.org
Wed May 30 05:08:46 PDT 2012
Module: telepathy-idle
Branch: master
Commit: 2a6ad36e772ec38eb5ad67f2cfa7cf9042fa0b1d
URL: http://cgit.freedesktop.org/telepathy/telepathy-idle/commit/?id=2a6ad36e772ec38eb5ad67f2cfa7cf9042fa0b1d
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Thu May 10 14:18:02 2012 +0100
Bring in the compiler/linker warnings from telepathy-glib
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Xavier Claessens <xavier.claessens at collabora.co.uk>
---
configure.ac | 63 +++++++++++++++++++++++++++----------------
m4/tp-compiler-flag.m4 | 43 ++++++++++++++++++++++++++++++
m4/tp-compiler-warnings.m4 | 49 ++++++++++++++++++++++++++++++++++
m4/tp-linker-flag.m4 | 44 ++++++++++++++++++++++++++++++
src/Makefile.am | 4 +++
tests/Makefile.am | 4 +++
6 files changed, 183 insertions(+), 24 deletions(-)
diff --git a/configure.ac b/configure.ac
index 53b7458..4644956 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,30 +42,45 @@ AC_PROG_CC
AC_PROG_CC_STDC
AM_PROG_AS
-dnl decide error flags
-AS_COMPILER_FLAG(-Wall, ERROR_CFLAGS="-Wall", ERROR_CFLAGS="")
-AS_COMPILER_FLAG(-Werror, werror=yes, werror=no)
-AS_COMPILER_FLAG(-Wextra, wextra=yes, wextra=no)
-AS_COMPILER_FLAG(-Wno-missing-field-initializers,
- wno_missing_field_initializers=yes,
- wno_missing_field_initializers=no)
-AS_COMPILER_FLAG(-Wno-unused-parameter,
- wno_unused_parameter=yes,
- wno_unused_parameter=no)
-
-ifelse(idle_nano_version, 0, [],
- [
- if test x$werror = xyes; then
- ERROR_CFLAGS="$ERROR_CFLAGS -Werror"
- fi
- if test x$wextra = xyes -a \
- x$wno_missing_field_initializers = xyes -a \
- x$wno_unused_parameter = xyes; then
- ERROR_CFLAGS="$ERROR_CFLAGS -Wextra -Wno-missing-field-initializers -Wno-unused-parameter"
- fi
- ])
-
-AC_SUBST(ERROR_CFLAGS)
+AS_IF([test idle_nano_version = 0],
+[ # version x.y.z - "official release",
+ # disable extra checks by default
+ AC_ARG_ENABLE([fatal-warnings],
+ [AC_HELP_STRING([--enable-fatal-warnings],
+ [make various warnings fatal])],
+ [],
+ [enable_fatal_warnings=no])
+],
+[ # version x.y.z.1 - development snapshot,
+ # enable extra checks by default
+ AC_ARG_ENABLE([fatal-warnings],
+ [AC_HELP_STRING([--disable-fatal-warnings],
+ [make various warnings non-fatal])],
+ [],
+ [enable_fatal_warnings=yes])
+])
+
+TP_COMPILER_WARNINGS([ERROR_CFLAGS], [test "x$enable_fatal_warnings" = xyes],
+ [all \
+ extra \
+ declaration-after-statement \
+ shadow \
+ missing-prototypes \
+ nested-externs \
+ pointer-arith \
+ sign-compare \
+ strict-prototypes \
+ format-security \
+ init-self],
+ [missing-field-initializers \
+ unused-parameter])
+AC_SUBST([ERROR_CFLAGS])
+
+# these aren't really error flags but they serve a similar purpose for us -
+# making the toolchain stricter
+if test "x$enable_fatal_warnings" = xyes; then
+ TP_ADD_LINKER_FLAG([ERROR_LDFLAGS], [-Wl,--no-copy-dt-needed-entries])
+fi
AC_HEADER_STDC([])
AC_C_INLINE
diff --git a/m4/tp-compiler-flag.m4 b/m4/tp-compiler-flag.m4
new file mode 100644
index 0000000..06deaba
--- /dev/null
+++ b/m4/tp-compiler-flag.m4
@@ -0,0 +1,43 @@
+dnl A version of AS_COMPILER_FLAG that supports both C and C++.
+dnl Based on:
+
+dnl as-compiler-flag.m4 0.1.0
+dnl autostars m4 macro for detection of compiler flags
+dnl David Schleef <ds at schleef.org>
+dnl $Id: as-compiler-flag.m4,v 1.1 2005/06/18 18:02:46 burgerman Exp $
+
+dnl TP_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CFLAGS and CXXFLAGS.
+dnl
+dnl Runs ACTION-IF-ACCEPTED if the compiler for the currently selected
+dnl AC_LANG can compile with the flags, and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([TP_COMPILER_FLAG],
+[
+ AC_MSG_CHECKING([to see if compiler understands $1])
+
+ save_CFLAGS="$CFLAGS"
+ save_CXXFLAGS="$CXXFLAGS"
+ CFLAGS="$CFLAGS $1"
+ CXXFLAGS="$CXXFLAGS $1"
+
+ AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+ CFLAGS="$save_CFLAGS"
+ CXXFLAGS="$save_CXXFLAGS"
+
+ if test "X$flag_ok" = Xyes ; then
+ $2
+ true
+ else
+ $3
+ true
+ fi
+ AC_MSG_RESULT([$flag_ok])
+])
+
+dnl TP_ADD_COMPILER_FLAG(VARIABLE, CFLAGS)
+dnl Append CFLAGS to VARIABLE if the compiler supports them.
+AC_DEFUN([TP_ADD_COMPILER_FLAG],
+[
+ TP_COMPILER_FLAG([$2], [$1="[$]$1 $2"])
+])
diff --git a/m4/tp-compiler-warnings.m4 b/m4/tp-compiler-warnings.m4
new file mode 100644
index 0000000..ee4af31
--- /dev/null
+++ b/m4/tp-compiler-warnings.m4
@@ -0,0 +1,49 @@
+dnl TP_COMPILER_WARNINGS(VARIABLE, WERROR_BY_DEFAULT, DESIRABLE, UNDESIRABLE)
+dnl $1 (VARIABLE): the variable to put flags into
+dnl $2 (WERROR_BY_DEFAULT): a command returning true if -Werror should be the
+dnl default
+dnl $3 (DESIRABLE): warning flags we want (e.g. all extra shadow)
+dnl $4 (UNDESIRABLE): warning flags we don't want (e.g.
+dnl missing-field-initializers unused-parameter)
+AC_DEFUN([TP_COMPILER_WARNINGS],
+[
+ AC_REQUIRE([AC_ARG_ENABLE])dnl
+ AC_REQUIRE([AC_HELP_STRING])dnl
+ AC_REQUIRE([TP_COMPILER_FLAG])dnl
+
+ tp_warnings=""
+ for tp_flag in $3; do
+ TP_COMPILER_FLAG([-W$tp_flag], [tp_warnings="$tp_warnings -W$tp_flag"])
+ done
+
+ tp_error_flags="-Werror"
+ TP_COMPILER_FLAG([-Werror], [tp_werror=yes], [tp_werror=no])
+
+ for tp_flag in $4; do
+ TP_COMPILER_FLAG([-Wno-$tp_flag],
+ [tp_warnings="$tp_warnings -Wno-$tp_flag"])
+dnl Yes, we do need to use both -Wno-foo and -Wno-error=foo. Simon says:
+dnl some warnings we explicitly don't want, like unused-parameter, but
+dnl they're in -Wall. when a distro using cdbs compiles us, we have:
+dnl -Werror -Wno-unused-parameter -Wall
+dnl ^ from us ^ from cdbs
+dnl which turns -Wunused-parameter back on, in effect
+ TP_COMPILER_FLAG([-Wno-error=$tp_flag],
+ [tp_error_flags="$tp_error_flags -Wno-error=$tp_flag"], [tp_werror=no])
+ done
+
+ AC_ARG_ENABLE([Werror],
+ AC_HELP_STRING([--disable-Werror],
+ [compile without -Werror (normally enabled in development builds)]),
+ tp_werror=$enableval, :)
+
+ if test "x$tp_werror" = xyes && $2; then
+dnl We put -Wno-error=foo before -Wno-foo because clang interprets -Wall
+dnl -Werror -Wno-foo -Wno-error=foo as âmake foo a non-fatal warningâ, but does
+dnl what we want if you reverse them.
+ $1="$tp_error_flags $tp_warnings"
+ else
+ $1="$tp_warnings"
+ fi
+
+])
diff --git a/m4/tp-linker-flag.m4 b/m4/tp-linker-flag.m4
new file mode 100644
index 0000000..8fd3506
--- /dev/null
+++ b/m4/tp-linker-flag.m4
@@ -0,0 +1,44 @@
+dnl A version of AS_COMPILER_FLAG that supports linker flags
+dnl Based on:
+
+dnl as-compiler-flag.m4 0.1.0
+dnl autostars m4 macro for detection of compiler flags
+dnl David Schleef <ds at schleef.org>
+dnl $Id: as-compiler-flag.m4,v 1.1 2005/06/18 18:02:46 burgerman Exp $
+
+dnl TP_LINKER_FLAG(LDFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given LDFLAGS.
+dnl
+dnl Runs ACTION-IF-ACCEPTED if the compiler/linker for the currently selected
+dnl AC_LANG can compile with the flags, and ACTION-IF-NOT-ACCEPTED otherwise.
+dnl
+dnl Note that LDFLAGS are passed to the linker via the compiler, so you
+dnl should check for -Wl,--no-add-needed rather than --no-add-needed.
+
+AC_DEFUN([TP_LINKER_FLAG],
+[
+ AC_MSG_CHECKING([to see if compiler/linker understand $1])
+
+ save_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $1"
+
+ AC_COMPILE_IFELSE(AC_LANG_SOURCE([]), [flag_ok=yes], [flag_ok=no])
+
+ LDFLAGS="$save_LDFLAGS"
+
+ if test "X$flag_ok" = Xyes ; then
+ $2
+ true
+ else
+ $3
+ true
+ fi
+ AC_MSG_RESULT([$flag_ok])
+])
+
+dnl TP_ADD_LINKER_FLAG(VARIABLE, LDFLAGS)
+dnl Append LDFLAGS to VARIABLE if the linker supports them.
+AC_DEFUN([TP_ADD_LINKER_FLAG],
+[
+ TP_LINKER_FLAG([$2], [$1="[$]$1 $2"])
+])
diff --git a/src/Makefile.am b/src/Makefile.am
index 466a362..f7bd6ca 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,6 +59,10 @@ AM_CFLAGS = \
@TELEPATHY_CFLAGS@ \
-std=c99
+AM_LDFLAGS = \
+ $(ERROR_LDFLAGS) \
+ $(NULL)
+
ALL_LIBS = \
@DBUS_LIBS@ \
@GLIB_LIBS@ \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5c1133d..295512a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,10 @@ AM_CFLAGS = \
@TELEPATHY_CFLAGS@ \
@OPENSSL_CFLAGS@
+AM_LDFLAGS = \
+ $(ERROR_LDFLAGS) \
+ $(NULL)
+
ALL_LIBS = \
@DBUS_LIBS@ \
@GLIB_LIBS@ \
More information about the telepathy-commits
mailing list