[virt-tools-list] [virt-viewer PATCH 5/5] Switch to gnulib's compiler warning flags
Daniel P. Berrangé
berrange at redhat.com
Wed Feb 13 17:04:41 UTC 2019
This enables many more compiler warnings than the current code. It also
ensures that -Werror is enabled by default when building from GIT so
that maintainers see regressions as hard failures.
Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
acinclude.m4 | 98 -----------
configure.ac | 2 +-
m4/manywarnings.m4 | 334 +++++++++++++++++++++++++++++++++++++
m4/virt-viewer-warnings.m4 | 159 ++++++++++++++++++
m4/warnings.m4 | 115 +++++++++++++
prepare-release.sh | 2 +-
6 files changed, 610 insertions(+), 100 deletions(-)
delete mode 100644 acinclude.m4
create mode 100644 m4/manywarnings.m4
create mode 100644 m4/virt-viewer-warnings.m4
create mode 100644 m4/warnings.m4
diff --git a/acinclude.m4 b/acinclude.m4
deleted file mode 100644
index 68398a6..0000000
--- a/acinclude.m4
+++ /dev/null
@@ -1,98 +0,0 @@
-dnl
-dnl Taken from gnome-common/macros2/gnome-compiler-flags.m4
-dnl
-dnl We've added:
-dnl -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls
-dnl We've removed
-dnl CFLAGS="$realsave_CFLAGS"
-dnl to avoid clobbering user-specified CFLAGS
-dnl
-AC_DEFUN([VIRT_VIEWER_COMPILE_WARNINGS],[
- dnl ******************************
- dnl More compiler warnings
- dnl ******************************
-
- AC_ARG_ENABLE(compile-warnings,
- AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
- [Turn on compiler warnings]),,
- [enable_compile_warnings="m4_default([$1],[maximum])"])
-
- warnCFLAGS=
-
- try_compiler_flags="-fexceptions -fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables"
-
- case "$enable_compile_warnings" in
- no)
- ;;
- minimum)
- try_compiler_flags="$try_compiler_flags -Wall"
- ;;
- yes)
- try_compiler_flags="$try_compiler_flags -Wall -Wmissing-prototypes -std=c99"
- ;;
- maximum|error)
- try_compiler_flags="$try_compiler_flags -Wall -Wmissing-prototypes -std=c99 -Wnested-externs -Wpointer-arith"
- try_compiler_flags="$try_compiler_flags -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return"
- # Removed -Wstrict-prototypes to avoid GTK bug
- try_compiler_flags="$try_compiler_flags -Winline -Wredundant-decls -Wdeprecated-declarations -Wno-sign-compare"
- # Remove as glib function casts hit
- try_compiler_flags="$try_compiler_flags -Wno-cast-function-type"
- if test "$enable_compile_warnings" = "error" ; then
- try_compiler_flags="$try_compiler_flags -Werror"
- fi
- ;;
- *)
- AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
- ;;
- esac
-
- AH_VERBATIM([FORTIFY_SOURCE],
- [/* Enable compile-time and run-time bounds-checking, and some warnings. */
- #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
- # define _FORTIFY_SOURCE 2
- #endif
- ])
-
- compiler_flags=
- for option in $try_compiler_flags; do
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $option"
- AC_MSG_CHECKING([whether gcc understands $option])
- AC_TRY_COMPILE([], [],
- has_option=yes,
- has_option=no,)
- CFLAGS="$SAVE_CFLAGS"
- AC_MSG_RESULT($has_option)
- if test $has_option = yes; then
- compiler_flags="$compiler_flags $option"
- fi
- unset has_option
- unset SAVE_CFLAGS
- done
- unset option
- unset try_compiler_flags
-
- AC_ARG_ENABLE(iso-c,
- AC_HELP_STRING([--enable-iso-c],
- [Try to warn if code is not ISO C ]),,
- [enable_iso_c=no])
-
- AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
- complCFLAGS=
- if test "x$enable_iso_c" != "xno"; then
- if test "x$GCC" = "xyes"; then
- case " $CFLAGS " in
- *[\ \ ]-ansi[\ \ ]*) ;;
- *) complCFLAGS="$complCFLAGS -ansi" ;;
- esac
- case " $CFLAGS " in
- *[\ \ ]-pedantic[\ \ ]*) ;;
- *) complCFLAGS="$complCFLAGS -pedantic" ;;
- esac
- fi
- fi
- AC_MSG_RESULT($complCFLAGS)
-
- WARN_CFLAGS="$compiler_flags $complCFLAGS"
- AC_SUBST(WARN_CFLAGS)
-])
diff --git a/configure.ac b/configure.ac
index 5598c61..8ff69ac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,7 +90,7 @@ m4_if(m4_version_compare([2.61a.100],
[AC_CONFIG_LINKS([$GNUmakefile:$GNUmakefile], [],
[GNUmakefile=$GNUmakefile])])
-VIRT_VIEWER_COMPILE_WARNINGS(maximum)
+VIRT_VIEWER_COMPILE_WARNINGS()
GETTEXT_PACKAGE=virt-viewer
AC_SUBST(GETTEXT_PACKAGE)
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
new file mode 100644
index 0000000..e0488a5
--- /dev/null
+++ b/m4/manywarnings.m4
@@ -0,0 +1,334 @@
+# manywarnings.m4 serial 17
+dnl Copyright (C) 2008-2019 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Simon Josefsson
+
+# gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR)
+# --------------------------------------------------
+# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR.
+# Elements separated by whitespace. In set logic terms, the function
+# does OUTVAR = LISTVAR \ REMOVEVAR.
+AC_DEFUN([gl_MANYWARN_COMPLEMENT],
+[
+ gl_warn_set=
+ set x $2; shift
+ for gl_warn_item
+ do
+ case " $3 " in
+ *" $gl_warn_item "*)
+ ;;
+ *)
+ gl_warn_set="$gl_warn_set $gl_warn_item"
+ ;;
+ esac
+ done
+ $1=$gl_warn_set
+])
+
+# gl_MANYWARN_ALL_GCC(VARIABLE)
+# -----------------------------
+# Add all documented GCC warning parameters to variable VARIABLE.
+# Note that you need to test them using gl_WARN_ADD if you want to
+# make sure your gcc understands it.
+#
+# The effects of this macro depend on the current language (_AC_LANG).
+AC_DEFUN([gl_MANYWARN_ALL_GCC],
+[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+
+# Specialization for _AC_LANG = C.
+# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
+m4_defun([gl_MANYWARN_ALL_GCC(C)],
+[
+ AC_LANG_PUSH([C])
+
+ dnl First, check for some issues that only occur when combining multiple
+ dnl gcc warning categories.
+ AC_REQUIRE([AC_PROG_CC])
+ if test -n "$GCC"; then
+
+ dnl Check if -W -Werror -Wno-missing-field-initializers is supported
+ dnl with the current $CC $CFLAGS $CPPFLAGS.
+ AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported],
+ [gl_cv_cc_nomfi_supported],
+ [gl_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers"
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[]], [[]])],
+ [gl_cv_cc_nomfi_supported=yes],
+ [gl_cv_cc_nomfi_supported=no])
+ CFLAGS="$gl_save_CFLAGS"
+ ])
+
+ if test "$gl_cv_cc_nomfi_supported" = yes; then
+ dnl Now check whether -Wno-missing-field-initializers is needed
+ dnl for the { 0, } construct.
+ AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
+ [gl_cv_cc_nomfi_needed],
+ [gl_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -W -Werror"
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[int f (void)
+ {
+ typedef struct { int a; int b; } s_t;
+ s_t s1 = { 0, };
+ return s1.b;
+ }
+ ]],
+ [[]])],
+ [gl_cv_cc_nomfi_needed=no],
+ [gl_cv_cc_nomfi_needed=yes])
+ CFLAGS="$gl_save_CFLAGS"
+ ])
+ fi
+
+ dnl Next, check if -Werror -Wuninitialized is useful with the
+ dnl user's choice of $CFLAGS; some versions of gcc warn that it
+ dnl has no effect if -O is not also used
+ AC_CACHE_CHECK([whether -Wuninitialized is supported],
+ [gl_cv_cc_uninitialized_supported],
+ [gl_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -Werror -Wuninitialized"
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[]], [[]])],
+ [gl_cv_cc_uninitialized_supported=yes],
+ [gl_cv_cc_uninitialized_supported=no])
+ CFLAGS="$gl_save_CFLAGS"
+ ])
+
+ fi
+
+ # List all gcc warning categories.
+ # To compare this list to your installed GCC's, run this Bash command:
+ #
+ # comm -3 \
+ # <((sed -n 's/^ *\(-[^ 0-9][^ ]*\) .*/\1/p' manywarnings.m4; \
+ # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \
+ # <(LC_ALL=C gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort)
+
+ gl_manywarn_set=
+ for gl_manywarn_item in -fno-common \
+ -W \
+ -Waddress \
+ -Waggressive-loop-optimizations \
+ -Wall \
+ -Wattribute-alias \
+ -Wattributes \
+ -Wbad-function-cast \
+ -Wbool-compare \
+ -Wbool-operation \
+ -Wbuiltin-declaration-mismatch \
+ -Wbuiltin-macro-redefined \
+ -Wcast-align \
+ -Wcast-align=strict \
+ -Wcast-function-type \
+ -Wchar-subscripts \
+ -Wclobbered \
+ -Wcomment \
+ -Wcomments \
+ -Wcoverage-mismatch \
+ -Wcpp \
+ -Wdangling-else \
+ -Wdate-time \
+ -Wdeprecated \
+ -Wdeprecated-declarations \
+ -Wdesignated-init \
+ -Wdisabled-optimization \
+ -Wdiscarded-array-qualifiers \
+ -Wdiscarded-qualifiers \
+ -Wdiv-by-zero \
+ -Wdouble-promotion \
+ -Wduplicated-branches \
+ -Wduplicated-cond \
+ -Wduplicate-decl-specifier \
+ -Wempty-body \
+ -Wendif-labels \
+ -Wenum-compare \
+ -Wexpansion-to-defined \
+ -Wextra \
+ -Wformat-contains-nul \
+ -Wformat-extra-args \
+ -Wformat-nonliteral \
+ -Wformat-security \
+ -Wformat-signedness \
+ -Wformat-y2k \
+ -Wformat-zero-length \
+ -Wframe-address \
+ -Wfree-nonheap-object \
+ -Whsa \
+ -Wif-not-aligned \
+ -Wignored-attributes \
+ -Wignored-qualifiers \
+ -Wimplicit \
+ -Wimplicit-function-declaration \
+ -Wimplicit-int \
+ -Wincompatible-pointer-types \
+ -Winit-self \
+ -Winline \
+ -Wint-conversion \
+ -Wint-in-bool-context \
+ -Wint-to-pointer-cast \
+ -Winvalid-memory-model \
+ -Winvalid-pch \
+ -Wlogical-not-parentheses \
+ -Wlogical-op \
+ -Wmain \
+ -Wmaybe-uninitialized \
+ -Wmemset-elt-size \
+ -Wmemset-transposed-args \
+ -Wmisleading-indentation \
+ -Wmissing-attributes \
+ -Wmissing-braces \
+ -Wmissing-declarations \
+ -Wmissing-field-initializers \
+ -Wmissing-include-dirs \
+ -Wmissing-parameter-type \
+ -Wmissing-prototypes \
+ -Wmultichar \
+ -Wmultistatement-macros \
+ -Wnarrowing \
+ -Wnested-externs \
+ -Wnonnull \
+ -Wnonnull-compare \
+ -Wnull-dereference \
+ -Wodr \
+ -Wold-style-declaration \
+ -Wold-style-definition \
+ -Wopenmp-simd \
+ -Woverflow \
+ -Woverlength-strings \
+ -Woverride-init \
+ -Wpacked \
+ -Wpacked-bitfield-compat \
+ -Wpacked-not-aligned \
+ -Wparentheses \
+ -Wpointer-arith \
+ -Wpointer-compare \
+ -Wpointer-sign \
+ -Wpointer-to-int-cast \
+ -Wpragmas \
+ -Wpsabi \
+ -Wrestrict \
+ -Wreturn-local-addr \
+ -Wreturn-type \
+ -Wscalar-storage-order \
+ -Wsequence-point \
+ -Wshadow \
+ -Wshift-count-negative \
+ -Wshift-count-overflow \
+ -Wshift-negative-value \
+ -Wsizeof-array-argument \
+ -Wsizeof-pointer-div \
+ -Wsizeof-pointer-memaccess \
+ -Wstack-protector \
+ -Wstrict-aliasing \
+ -Wstrict-overflow \
+ -Wstrict-prototypes \
+ -Wstringop-truncation \
+ -Wsuggest-attribute=cold \
+ -Wsuggest-attribute=const \
+ -Wsuggest-attribute=format \
+ -Wsuggest-attribute=malloc \
+ -Wsuggest-attribute=noreturn \
+ -Wsuggest-attribute=pure \
+ -Wsuggest-final-methods \
+ -Wsuggest-final-types \
+ -Wswitch \
+ -Wswitch-bool \
+ -Wswitch-unreachable \
+ -Wsync-nand \
+ -Wsystem-headers \
+ -Wtautological-compare \
+ -Wtrampolines \
+ -Wtrigraphs \
+ -Wtype-limits \
+ -Wuninitialized \
+ -Wunknown-pragmas \
+ -Wunsafe-loop-optimizations \
+ -Wunused \
+ -Wunused-but-set-parameter \
+ -Wunused-but-set-variable \
+ -Wunused-function \
+ -Wunused-label \
+ -Wunused-local-typedefs \
+ -Wunused-macros \
+ -Wunused-parameter \
+ -Wunused-result \
+ -Wunused-value \
+ -Wunused-variable \
+ -Wvarargs \
+ -Wvariadic-macros \
+ -Wvector-operation-performance \
+ -Wvla \
+ -Wvolatile-register-var \
+ -Wwrite-strings \
+ \
+ ; do
+ gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
+ done
+
+ # gcc --help=warnings outputs an unusual form for these options; list
+ # them here so that the above 'comm' command doesn't report a false match.
+ # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal.
+ # Also, AC_COMPUTE_INT requires it to fit in a long; it is 2**63 on
+ # the only platforms where it does not fit in a long, so make that
+ # a special case.
+ AC_MSG_CHECKING([max safe object size])
+ AC_COMPUTE_INT([gl_alloc_max],
+ [LONG_MAX < (PTRDIFF_MAX < (size_t) -1 ? PTRDIFF_MAX : (size_t) -1)
+ ? -1
+ : PTRDIFF_MAX < (size_t) -1 ? (long) PTRDIFF_MAX : (long) (size_t) -1],
+ [[#include <limits.h>
+ #include <stddef.h>
+ #include <stdint.h>
+ ]],
+ [gl_alloc_max=2147483647])
+ case $gl_alloc_max in
+ -1) gl_alloc_max=9223372036854775807;;
+ esac
+ AC_MSG_RESULT([$gl_alloc_max])
+ gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$gl_alloc_max"
+ gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
+ gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
+ gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
+ gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
+ gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
+ gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
+ gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
+ gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
+ gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
+
+ # These are needed for older GCC versions.
+ if test -n "$GCC"; then
+ case `($CC --version) 2>/dev/null` in
+ 'gcc (GCC) '[[0-3]].* | \
+ 'gcc (GCC) '4.[[0-7]].*)
+ gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
+ gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
+ ;;
+ esac
+ fi
+
+ # Disable specific options as needed.
+ if test "$gl_cv_cc_nomfi_needed" = yes; then
+ gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
+ fi
+
+ if test "$gl_cv_cc_uninitialized_supported" = no; then
+ gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
+ fi
+
+ $1=$gl_manywarn_set
+
+ AC_LANG_POP([C])
+])
+
+# Specialization for _AC_LANG = C++.
+# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
+m4_defun([gl_MANYWARN_ALL_GCC(C++)],
+[
+ gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])
+])
diff --git a/m4/virt-viewer-warnings.m4 b/m4/virt-viewer-warnings.m4
new file mode 100644
index 0000000..4036b75
--- /dev/null
+++ b/m4/virt-viewer-warnings.m4
@@ -0,0 +1,159 @@
+dnl
+dnl Enable all known GCC compiler warnings, except for those
+dnl we can't yet cope with
+dnl
+AC_DEFUN([VIRT_VIEWER_COMPILE_WARNINGS],[
+ dnl ******************************
+ dnl More compiler warnings
+ dnl ******************************
+
+ AC_ARG_ENABLE([werror],
+ AS_HELP_STRING([--enable-werror], [Use -Werror (if supported)]),
+ [set_werror="$enableval"],
+ [if test -d $srcdir/.git; then
+ is_git_version=true
+ set_werror=yes
+ else
+ set_werror=no
+ fi])
+
+ # List of warnings that are not relevant / wanted
+
+ # Don't care about C++ compiler compat
+ dontwarn="$dontwarn -Wc++-compat"
+ dontwarn="$dontwarn -Wabi"
+ dontwarn="$dontwarn -Wdeprecated"
+ # Don't care about ancient C standard compat
+ dontwarn="$dontwarn -Wtraditional"
+ # Don't care about ancient C standard compat
+ dontwarn="$dontwarn -Wtraditional-conversion"
+ # Ignore warnings in /usr/include
+ dontwarn="$dontwarn -Wsystem-headers"
+ # Happy for compiler to add struct padding
+ dontwarn="$dontwarn -Wpadded"
+ # GCC very confused with -O2
+ dontwarn="$dontwarn -Wunreachable-code"
+ # Too many to deal with
+ dontwarn="$dontwarn -Wconversion"
+ # Too many to deal with
+ dontwarn="$dontwarn -Wsign-conversion"
+ # We need to use long long in many places
+ dontwarn="$dontwarn -Wlong-long"
+ # Not a problem since we don't use -fstrict-overflow
+ dontwarn="$dontwarn -Wstrict-overflow"
+ # Not a problem since we don't use -funsafe-loop-optimizations
+ dontwarn="$dontwarn -Wunsafe-loop-optimizations"
+ # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall
+ dontwarn="$dontwarn -Wenum-compare"
+ # /usr/include/spice-1/spice/protocol.h triggers violations
+ dontwarn="$dontwarn -Wpacked"
+
+ # g_clear_object & G_ATOMIC_OP_USE_GCC_BUILTINS causes
+ # violations with this. XXX Fix glib ?
+ dontwarn="$dontwarn -Wbad-function-cast"
+
+ # Due to gutils.h bug in g_bit_storage
+ wantwarn="$wantwarn -Wno-sign-conversion"
+ wantwarn="$wantwarn -Wno-conversion"
+ # We can't enable this due to horrible spice_usb_device_get_description
+ # signature
+# wantwarn="$wantwarn -Wno-format-nonliteral"
+
+ # Get all possible GCC warnings
+ gl_MANYWARN_ALL_GCC([maybewarn])
+
+ # Remove the ones we don't want, blacklisted earlier
+ gl_MANYWARN_COMPLEMENT([wantwarn], [$maybewarn], [$dontwarn])
+
+ # GNULIB uses '-W' (aka -Wextra) which includes a bunch of stuff.
+ # Unfortunately, this means you can't simply use '-Wsign-compare'
+ # with gl_MANYWARN_COMPLEMENT
+ # So we have -W enabled, and then have to explicitly turn off...
+ wantwarn="$wantwarn -Wno-sign-compare"
+
+ # GNULIB expects this to be part of -Wc++-compat, but we turn
+ # that one off, so we need to manually enable this again
+ wantwarn="$wantwarn -Wjump-misses-init"
+
+ # We do "bad" function casts all the time for event callbacks
+ wantwarn="$wantwarn -Wno-cast-function-type"
+
+ # GNULIB turns on -Wformat=2 which implies -Wformat-nonliteral,
+ # so we need to manually re-exclude it.
+ wantwarn="$wantwarn -Wno-format-nonliteral"
+
+ # This should be < 256 really. Currently we're down to 4096,
+ # but using 1024 bytes sized buffers (mostly for virStrerror)
+ # stops us from going down further
+ wantwarn="$wantwarn -Wframe-larger-than=4096"
+
+ # We want to allow use of comments to annotate switch fallthrough
+ wantwarn="$wantwarn -Wimplicit-fallthrough=2"
+
+ # Extra special flags
+ dnl -fstack-protector stuff passes gl_WARN_ADD with gcc
+ dnl on Mingw32, but fails when actually used
+ case $host in
+ aarch64-*-*)
+ dnl "error: -fstack-protector not supported for this target [-Werror]"
+ ;;
+ *-*-linux*)
+ dnl Prefer -fstack-protector-strong if it's available.
+ dnl There doesn't seem to be great overhead in adding
+ dnl -fstack-protector-all instead of -fstack-protector.
+ dnl
+ dnl We also don't need ssp-buffer-size with -all or -strong,
+ dnl since functions are protected regardless of buffer size.
+ dnl wantwarn="$wantwarn --param=ssp-buffer-size=4"
+ wantwarn="$wantwarn -fstack-protector-strong"
+ ;;
+ *-*-freebsd*)
+ dnl FreeBSD ships old gcc 4.2.1 which doesn't handle
+ dnl -fstack-protector-all well
+ wantwarn="$wantwarn -fstack-protector"
+
+ wantwarn="$wantwarn -Wno-unused-command-line-argument"
+ ;;
+ esac
+ wantwarn="$wantwarn -fexceptions"
+ wantwarn="$wantwarn -fasynchronous-unwind-tables"
+
+ # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure
+ # fire even without -O.
+ wantwarn="$wantwarn -fipa-pure-const"
+ # We should eventually enable this, but right now there are at
+ # least 75 functions triggering warnings.
+ wantwarn="$wantwarn -Wno-suggest-attribute=pure"
+ wantwarn="$wantwarn -Wno-suggest-attribute=const"
+
+ if test "$set_werror" = "yes"
+ then
+ wantwarn="$wantwarn -Werror"
+ fi
+
+ # Check for $CC support of each warning
+ for w in $wantwarn; do
+ gl_WARN_ADD([$w])
+ done
+
+ case $host in
+ *-*-linux*)
+ dnl Fall back to -fstack-protector-all if -strong is not available
+ case $WARN_CFLAGS in
+ *-fstack-protector-strong*)
+ ;;
+ *)
+ gl_WARN_ADD(["-fstack-protector-all"])
+ ;;
+ esac
+ ;;
+ esac
+
+ AH_VERBATIM([FORTIFY_SOURCE],
+ [/* Enable compile-time and run-time bounds-checking, and some warnings,
+ without upsetting newer glibc. */
+ #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
+ # define _FORTIFY_SOURCE 2
+ #endif
+ ])
+])
diff --git a/m4/warnings.m4 b/m4/warnings.m4
new file mode 100644
index 0000000..235cac6
--- /dev/null
+++ b/m4/warnings.m4
@@ -0,0 +1,115 @@
+# warnings.m4 serial 14
+dnl Copyright (C) 2008-2019 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Simon Josefsson
+
+# gl_AS_VAR_APPEND(VAR, VALUE)
+# ----------------------------
+# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it.
+m4_ifdef([AS_VAR_APPEND],
+[m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])],
+[m4_define([gl_AS_VAR_APPEND],
+[AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
+
+
+# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
+# [PROGRAM = AC_LANG_PROGRAM()])
+# -----------------------------------------------------------------
+# Check if the compiler supports OPTION when compiling PROGRAM.
+#
+# The effects of this macro depend on the current language (_AC_LANG).
+AC_DEFUN([gl_COMPILER_OPTION_IF],
+[
+dnl FIXME: gl_Warn must be used unquoted until we can assume Autoconf
+dnl 2.64 or newer.
+AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
+AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
+AS_LITERAL_IF([$1],
+ [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
+ [gl_positive="$1"
+case $gl_positive in
+ -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;;
+esac
+m4_pushdef([gl_Positive], [$gl_positive])])dnl
+AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
+ gl_save_compiler_FLAGS="$gl_Flags"
+ gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
+ [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
+ AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
+ [AS_VAR_SET(gl_Warn, [yes])],
+ [AS_VAR_SET(gl_Warn, [no])])
+ gl_Flags="$gl_save_compiler_FLAGS"
+])
+AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
+m4_popdef([gl_Positive])dnl
+AS_VAR_POPDEF([gl_Flags])dnl
+AS_VAR_POPDEF([gl_Warn])dnl
+])
+
+# gl_UNKNOWN_WARNINGS_ARE_ERRORS
+# ------------------------------
+# Clang doesn't complain about unknown warning options unless one also
+# specifies -Wunknown-warning-option -Werror. Detect this.
+#
+# The effects of this macro depend on the current language (_AC_LANG).
+AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
+[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+
+# Specialization for _AC_LANG = C. This macro can be AC_REQUIREd.
+# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
+m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)],
+[
+ AC_LANG_PUSH([C])
+ gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
+ AC_LANG_POP([C])
+])
+
+# Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd.
+# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
+m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)],
+[
+ AC_LANG_PUSH([C++])
+ gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
+ AC_LANG_POP([C++])
+])
+
+# Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd.
+# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
+m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)],
+[
+ AC_LANG_PUSH([Objective C])
+ gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
+ AC_LANG_POP([Objective C])
+])
+
+AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL],
+[gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
+ [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
+ [gl_unknown_warnings_are_errors=])])
+
+# gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
+# [PROGRAM = AC_LANG_PROGRAM()])
+# -----------------------------------------------------------
+# Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it
+# when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]).
+#
+# If VARIABLE is a variable name, AC_SUBST it.
+#
+# The effects of this macro depend on the current language (_AC_LANG).
+AC_DEFUN([gl_WARN_ADD],
+[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)])
+gl_COMPILER_OPTION_IF([$1],
+ [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])],
+ [],
+ [$3])
+m4_ifval([$2],
+ [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
+ [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
+])
+
+# Local Variables:
+# mode: autoconf
+# End:
diff --git a/prepare-release.sh b/prepare-release.sh
index c2fbfdb..11e6abb 100755
--- a/prepare-release.sh
+++ b/prepare-release.sh
@@ -14,7 +14,7 @@ mkdir build
cd build
../autogen.sh --prefix=$INSTALL_ROOT \
- --enable-compile-warnings=error
+ --enable-werror
make
make install
--
2.20.1
More information about the virt-tools-list
mailing list