From 5f0033ca301c9dcf57603cee1e54aa64035c4a50 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 19 Apr 2010 19:29:29 +0100 Subject: Use telepathy-glib's macro to wrap desired and undesired compiler warnings --- configure.ac | 60 ++++++++++++++++++++++------------------------ m4/as-compiler-flag.m4 | 33 ------------------------- m4/tp-compiler-flag.m4 | 36 ++++++++++++++++++++++++++++ m4/tp-compiler-warnings.m4 | 40 +++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 65 deletions(-) delete mode 100644 m4/as-compiler-flag.m4 create mode 100644 m4/tp-compiler-flag.m4 create mode 100644 m4/tp-compiler-warnings.m4 diff --git a/configure.ac b/configure.ac index a7369ac..813d93f 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,10 @@ DBUS_SERVICES_DIR="$datadir/dbus-1/services" AC_SUBST(DBUS_SERVICES_DIR) AC_DEFINE_UNQUOTED(DBUS_SERVICES_DIR, "$DBUS_SERVICES_DIR", [Where services dir for DBUS is]) +ifelse(tpl_released, 1, + [ official_release=yes ], + [ official_release=no ]) + AC_PREREQ(2.59) AC_COPYRIGHT([ Copyright (C) 2003-2007 Imendio AB @@ -94,47 +98,39 @@ AM_CONDITIONAL([WANT_TWISTED_TESTS], test false != "$TEST_PYTHON") # ----------------------------------------------------------- # Error flags # ----------------------------------------------------------- -AS_COMPILER_FLAG(-Wall, ERROR_CFLAGS="-Wall", ERROR_CFLAGS="") -AS_COMPILER_FLAG(-Werror, werror=yes, werror=no) -AC_ARG_ENABLE(debug, - AC_HELP_STRING([--disable-debug],[compile without debug code]), - enable_debug=$enableval, enable_debug=yes) +TP_COMPILER_WARNINGS([ERROR_CFLAGS], [test "x$official_release" = xno], + [all \ + extra \ + missing-prototypes \ + shadow \ + sign-compare \ + strict-prototypes], + [missing-field-initializers \ + unused-parameter]) + +# things that telepathy-glib uses, but we don't here: +# declaration-after-statement \ +# format-security \ +# init-self \ +# nested-externs \ +# pointer-arith \ +# +# of which d-a-s seems to be deliberate (this code fails it). AC_ARG_ENABLE(Werror, AC_HELP_STRING([--disable-Werror],[compile without -Werror (normally enabled in development builds)]), werror=$enableval, werror=yes) -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(tpl_released, 1, [], - [ - 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 - ]) - -AS_COMPILER_FLAG(-D_POSIX_SOURCE, ERROR_CFLAGS="$ERROR_CFLAGS -D_POSIX_SOURCE") -AS_COMPILER_FLAG(-std=c99, ERROR_CFLAGS="$ERROR_CFLAGS -std=c99") -#AS_COMPILER_FLAG(-Wdeclaration-after-statement, ERROR_CFLAGS="$ERROR_CFLAGS -Wdeclaration-after-statement") -AS_COMPILER_FLAG(-Wshadow, ERROR_CFLAGS="$ERROR_CFLAGS -Wshadow") -AS_COMPILER_FLAG(-Wmissing-prototypes, ERROR_CFLAGS="$ERROR_CFLAGS -Wmissing-prototypes") -AS_COMPILER_FLAG(-Wmissing-declarations, ERROR_CFLAGS="$ERROR_CFLAGS -Wmissing-declarations") -AS_COMPILER_FLAG(-Wstrict-prototypes, ERROR_CFLAGS="$ERROR_CFLAGS -Wstrict-prototypes") +TP_COMPILER_FLAG(-D_POSIX_SOURCE, ERROR_CFLAGS="$ERROR_CFLAGS -D_POSIX_SOURCE") +TP_COMPILER_FLAG(-std=c99, ERROR_CFLAGS="$ERROR_CFLAGS -std=c99") AC_SUBST(ERROR_CFLAGS) +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--disable-debug],[compile without debug code]), + enable_debug=$enableval, enable_debug=yes) + # ----------------------------------------------------------- # Pkg-Config dependency checks # ----------------------------------------------------------- diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4 deleted file mode 100644 index 605708a..0000000 --- a/m4/as-compiler-flag.m4 +++ /dev/null @@ -1,33 +0,0 @@ -dnl as-compiler-flag.m4 0.1.0 - -dnl autostars m4 macro for detection of compiler flags - -dnl David Schleef - -dnl $Id: as-compiler-flag.m4,v 1.1 2005/06/18 18:02:46 burgerman 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 - $2 - true - else - $3 - true - fi - AC_MSG_RESULT([$flag_ok]) -]) - diff --git a/m4/tp-compiler-flag.m4 b/m4/tp-compiler-flag.m4 new file mode 100644 index 0000000..fc05e9e --- /dev/null +++ b/m4/tp-compiler-flag.m4 @@ -0,0 +1,36 @@ +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 +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]) +]) diff --git a/m4/tp-compiler-warnings.m4 b/m4/tp-compiler-warnings.m4 new file mode 100644 index 0000000..fab5dc8 --- /dev/null +++ b/m4/tp-compiler-warnings.m4 @@ -0,0 +1,40 @@ +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"]) + 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 + $1="$tp_warnings $tp_error_flags" + else + $1="$tp_warnings" + fi + +]) -- cgit v1.2.1