From a2a569a65a10f9b8df4ab9a5284dc14e29c0306b Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Mon, 15 Aug 2016 19:46:03 +0200 Subject: Test compiler and linker flags with AX_COMPILER_FLAGS_* macros The autoconf macros AX_COMPILER_FLAGS_{CFLAGS|CXXFLAGS|LDFLAGS} test for compiler and linker support of various flags, and add the flags to the generated output. If the command-line option '--enable-compile-warnings' is specified to 'configure', a number of additional warning options is also added to the output. This is the default. The AX_COMPILER_FLAGS_* macros add stricter warnings then before. The patch disables some of them to make DBus build without errors. A later patch set should fix the warnings and remove the compiler flags. Signed-off-by: Thomas Zimmermann --- configure.ac | 102 +++++++++++++++++++++++++-------------------- m4/tp-compiler-warnings.m4 | 49 ---------------------- 2 files changed, 57 insertions(+), 94 deletions(-) delete mode 100644 m4/tp-compiler-warnings.m4 diff --git a/configure.ac b/configure.ac index 926d6bf..644364e 100644 --- a/configure.ac +++ b/configure.ac @@ -323,14 +323,30 @@ if test x$enable_verbose_mode = xyes; then AC_DEFINE(DBUS_ENABLE_VERBOSE_MODE,1,[Support a verbose mode]) fi +dnl Intentional: +dnl - $DISABLE_WARNINGS disables unused-label warnings if not +dnl checking or not asserting +dnl - missing field initializers being 0 is a C feature, not a bug +dnl - unused-parameter is to make writing callbacks less annoying +dnl +dnl To be fixed one day: +dnl - pointer-sign is a workaround for fd.o #15522 +dnl - type-limits is probably a bug too, but having the rest of -Wextra +dnl is better than nothing +DISABLE_WARNINGS="$DISABLE_WARNINGS + -Wno-missing-field-initializers + -Wno-type-limits + -Wno-unused-parameter" + if test x$enable_asserts = xno; then AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking]) - DISABLE_UNUSED_WARNINGS="unused-label" + DISABLE_WARNINGS="$DISABLE_WARNINGS -Wno-unused-label" R_DYNAMIC_LDFLAG="" if test x$enable_embedded_tests = xyes; then - DISABLE_UNUSED_WARNINGS="$DISABLE_UNUSED_WARNINGS \ - unused-but-set-variable unused-variable \ - unused-function" + DISABLE_WARNINGS="$DISABLE_WARNINGS + -Wno-unused-but-set-variable + -Wno-unused-variable + -Wno-unused-function" fi else # -rdynamic is needed for glibc's backtrace_symbols to work. @@ -348,7 +364,7 @@ AC_SUBST(R_DYNAMIC_LDFLAG) if test x$enable_checks = xno; then AC_DEFINE(DBUS_DISABLE_CHECKS,1,[Disable public API sanity checking]) AC_DEFINE(G_DISABLE_CHECKS,1,[Disable GLib public API sanity checking]) - DISABLE_UNUSED_WARNINGS="unused-label" + DISABLE_WARNINGS="$DISABLE_WARNINGS -Wno-unused-label" fi AH_BOTTOM([ @@ -1344,46 +1360,41 @@ cc_supports_flag() { test "x$rc" = xyes } -TP_COMPILER_WARNINGS([WARNING_CFLAGS], - dnl Use -Werror by default if: - dnl - we're not on Windows (too many warnings), and - dnl - we're in developer mode (a D-Bus developer, not a distro or end-user) - dnl Override with --enable-Werror or --disable-Werror - [test x$dbus_win != xyes -a x$dbus_cygwin != xyes -a x$enable_developer = xyes], - - dnl Enable these warnings if possible: - [all \ - extra \ - char-subscripts \ - missing-declarations \ - missing-prototypes \ - nested-externs \ - pointer-arith \ - pointer-sign \ - cast-align \ - no-address \ - float-equal \ - declaration-after-statement \ - ], - - dnl Disable these warnings if possible, make them non-fatal if possible, - dnl and don't enable -Werror unless we succeeded. - dnl - dnl Intentional: - dnl - $DISABLE_UNUSED_WARNINGS disables unused-label warnings if not - dnl checking or not asserting - dnl - missing field initializers being 0 is a C feature, not a bug - dnl - unused-parameter is to make writing callbacks less annoying - dnl - dnl To be fixed one day: - dnl - pointer-sign is a workaround for fd.o #15522 - dnl - type-limits is probably a bug too, but having the rest of -Wextra - dnl is better than nothing - [$DISABLE_UNUSED_WARNINGS \ - missing-field-initializers \ - unused-parameter \ - type-limits \ - ]) +dnl TODO: The compiler flags below disable warnings that the +dnl compiler emits while building DBus. Fix the source +dnl code and remove these flags. +DISABLE_WARNINGS="DISABLE_WARNINGS + -Wno-discarded-qualifiers + -Wno-format-nonliteral + -Wno-redundant-decls + -Wno-suggest-attribute=format + -Wno-suggest-attribute=noreturn + -Wno-shadow + -Wno-switch-default + -Wno-switch-enum + -Wno-undef" + +AX_COMPILER_FLAGS + +AX_COMPILER_FLAGS_CFLAGS([EXTRA_CFLAGS],[],[], + [-Wchar-subscripts \ + -Wfloat-equal \ + -Wno-address \ + -Wpointer-sign \ + $DISABLE_WARNINGS]) + +AX_COMPILER_FLAGS_CXXFLAGS([EXTRA_CXXFLAGS],[],[], + [-Wchar-subscripts \ + -Wfloat-equal \ + -Wno-address \ + -Wpointer-sign \ + $DISABLE_WARNINGS]) + +AX_COMPILER_FLAGS_LDFLAGS([EXTRA_LDFLAGS]) + +CFLAGS="$EXTRA_CFLAGS $CFLAGS" +CXXFLAGS="$EXTRA_CXXFLAGS $CXXFLAGS" +LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS" if test "x$GCC" = "xyes"; then # We're treating -fno-common like a warning: it makes the linker more @@ -1914,6 +1925,7 @@ echo " cflags: ${CFLAGS} cppflags: ${CPPFLAGS} cxxflags: ${CXXFLAGS} + ldflags: ${LDFLAGS} 64-bit int: ${DBUS_INT64_TYPE} 32-bit int: ${DBUS_INT32_TYPE} 16-bit int: ${DBUS_INT16_TYPE} diff --git a/m4/tp-compiler-warnings.m4 b/m4/tp-compiler-warnings.m4 deleted file mode 100644 index ee4af31..0000000 --- a/m4/tp-compiler-warnings.m4 +++ /dev/null @@ -1,49 +0,0 @@ -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 - -]) -- 2.7.4