mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 01:18:00 +03:00
Use gnulib's manywarnings & warnings modules
Remove custom code for checking compiler warnings, using gl_WARN_ADD instead. Don't list all flags ourselves, use gnulib's gl_MANYWARN_ALL_GCC to get all possible GCC flags, then turn off the ones we don't want yet. * acinclude.m4: Rewrite to use gl_WARN_ADD and gl_MANYWARN_ALL_GCC * bootstrap.conf: Add warnings & manywarnings * configure.ac: Switch to gl_WARN_ADD * m4/compiler-flags.m4: Obsoleted by gl_WARN_ADD
This commit is contained in:
parent
222402417d
commit
0e867555bd
181
acinclude.m4
181
acinclude.m4
@ -1,11 +1,6 @@
|
||||
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 Enable all known GCC compiler warnings, except for those
|
||||
dnl we can't yet cope with
|
||||
dnl
|
||||
AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
|
||||
dnl ******************************
|
||||
@ -13,91 +8,129 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
|
||||
dnl ******************************
|
||||
|
||||
AC_ARG_ENABLE(compile-warnings,
|
||||
[AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
|
||||
[AC_HELP_STRING([--enable-compile-warnings=@<:@no/yes/error@:>@],
|
||||
[Turn on compiler warnings])],,
|
||||
[enable_compile_warnings="m4_default([$1],[maximum])"])
|
||||
|
||||
warnCFLAGS=
|
||||
|
||||
common_flags=
|
||||
common_flags="$common_flags -Wp,-D_FORTIFY_SOURCE=2"
|
||||
common_flags="$common_flags -fexceptions"
|
||||
common_flags="$common_flags -fasynchronous-unwind-tables"
|
||||
common_flags="$common_flags -fdiagnostics-show-option"
|
||||
[enable_compile_warnings="m4_default([$1],[yes])"])
|
||||
|
||||
case "$enable_compile_warnings" in
|
||||
no)
|
||||
try_compiler_flags=""
|
||||
;;
|
||||
minimum)
|
||||
try_compiler_flags="-Wall -Wformat -Wformat-security $common_flags"
|
||||
;;
|
||||
yes)
|
||||
try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes $common_flags"
|
||||
;;
|
||||
maximum|error)
|
||||
try_compiler_flags="-Wall -Wformat -Wformat-security"
|
||||
try_compiler_flags="$try_compiler_flags -Wmissing-prototypes"
|
||||
try_compiler_flags="$try_compiler_flags -Wnested-externs "
|
||||
try_compiler_flags="$try_compiler_flags -Wpointer-arith"
|
||||
try_compiler_flags="$try_compiler_flags -Wextra -Wshadow"
|
||||
try_compiler_flags="$try_compiler_flags -Wcast-align"
|
||||
try_compiler_flags="$try_compiler_flags -Wwrite-strings"
|
||||
try_compiler_flags="$try_compiler_flags -Waggregate-return"
|
||||
try_compiler_flags="$try_compiler_flags -Wstrict-prototypes"
|
||||
try_compiler_flags="$try_compiler_flags -Winline"
|
||||
try_compiler_flags="$try_compiler_flags -Wredundant-decls"
|
||||
try_compiler_flags="$try_compiler_flags -Wno-sign-compare"
|
||||
try_compiler_flags="$try_compiler_flags -Wlogical-op"
|
||||
try_compiler_flags="$try_compiler_flags -Wjump-misses-init"
|
||||
try_compiler_flags="$try_compiler_flags $common_flags"
|
||||
if test "$enable_compile_warnings" = "error" ; then
|
||||
try_compiler_flags="$try_compiler_flags -Werror"
|
||||
fi
|
||||
yes|minimum|maximum|error)
|
||||
|
||||
# List of warnings that are not relevant / wanted
|
||||
|
||||
# Don't care about C++ compiler compat
|
||||
dontwarn="$dontwarn -Wc++-compat"
|
||||
# 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"
|
||||
# GNULIB gettext.h violates
|
||||
dontwarn="$dontwarn -Wvla"
|
||||
# Many GNULIB header violations
|
||||
dontwarn="$dontwarn -Wundef"
|
||||
# Need to allow bad cast for execve()
|
||||
dontwarn="$dontwarn -Wcast-qual"
|
||||
# We need to use long long in many places
|
||||
dontwarn="$dontwarn -Wlong-long"
|
||||
# We allow manual list of all enum cases without default:
|
||||
dontwarn="$dontwarn -Wswitch-default"
|
||||
# We allow optional default: instead of listing all enum values
|
||||
dontwarn="$dontwarn -Wswitch-enum"
|
||||
# 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"
|
||||
# Things like virAsprintf mean we can't use this
|
||||
dontwarn="$dontwarn -Wformat-nonliteral"
|
||||
|
||||
# We might fundamentally need some of these disabled forever, but ideally
|
||||
# we'd turn many of them on
|
||||
dontwarn="$dontwarn -Wfloat-equal"
|
||||
dontwarn="$dontwarn -Wdeclaration-after-statement"
|
||||
dontwarn="$dontwarn -Wcast-qual"
|
||||
dontwarn="$dontwarn -Wconversion"
|
||||
dontwarn="$dontwarn -Wsign-conversion"
|
||||
dontwarn="$dontwarn -Wold-style-definition"
|
||||
dontwarn="$dontwarn -Wmissing-noreturn"
|
||||
dontwarn="$dontwarn -Wpacked"
|
||||
dontwarn="$dontwarn -Wunused-macros"
|
||||
dontwarn="$dontwarn -Woverlength-strings"
|
||||
dontwarn="$dontwarn -Wmissing-format-attribute"
|
||||
dontwarn="$dontwarn -Wstack-protector"
|
||||
|
||||
# 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])
|
||||
|
||||
# Check for $CC support of each warning
|
||||
for w in $wantwarn; do
|
||||
gl_WARN_ADD([$w])
|
||||
done
|
||||
|
||||
# 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...
|
||||
gl_WARN_ADD([-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
|
||||
gl_WARN_ADD([-Wjump-misses-init])
|
||||
|
||||
# This should be < 256 really, but with PATH_MAX everywhere
|
||||
# we have doom, even with 4096. In fact we have some functions
|
||||
# with several PATH_MAX sized variables :-( We should kill off
|
||||
# all PATH_MAX usage and then lower this limit
|
||||
gl_WARN_ADD([-Wframe-larger-than=65700])
|
||||
dnl gl_WARN_ADD([-Wframe-larger-than=4096])
|
||||
dnl gl_WARN_ADD([-Wframe-larger-than=256])
|
||||
|
||||
# Extra special flags
|
||||
gl_WARN_ADD([-Wp,-D_FORTIFY_SOURCE=2])
|
||||
dnl Fedora only uses -fstack-protector, but doesn't seem to
|
||||
dnl be great overhead in adding -fstack-protector-all instead
|
||||
dnl gl_WARN_ADD([-fstack-protector])
|
||||
gl_WARN_ADD([-fstack-protector-all])
|
||||
gl_WARN_ADD([--param=ssp-buffer-size=4])
|
||||
gl_WARN_ADD([-fexceptions])
|
||||
gl_WARN_ADD([-fasynchronous-unwind-tables])
|
||||
gl_WARN_ADD([-fdiagnostics-show-option])
|
||||
|
||||
if test "$enable_compile_warnings" = "error"
|
||||
then
|
||||
gl_WARN_ADD([-Werror])
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPILER_FLAGS=
|
||||
for option in $try_compiler_flags; do
|
||||
gl_COMPILER_FLAGS($option)
|
||||
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"
|
||||
WARN_LDFLAGS=$WARN_CFLAGS
|
||||
AC_SUBST([WARN_CFLAGS])
|
||||
AC_SUBST([WARN_LDFLAGS])
|
||||
|
||||
dnl Needed to keep compile quiet on python 2.4
|
||||
COMPILER_FLAGS=
|
||||
gl_COMPILER_FLAGS(-Wno-redundant-decls)
|
||||
WARN_PYTHON_CFLAGS=$COMPILER_FLAGS
|
||||
save_WARN_CFLAGS=$WARN_CFLAGS
|
||||
WARN_CFLAGS=
|
||||
gl_WARN_ADD([-Wno-redundant-decls])
|
||||
WARN_PYTHON_CFLAGS=$WARN_CFLAGS
|
||||
AC_SUBST(WARN_PYTHON_CFLAGS)
|
||||
WARN_CFLAGS=$save_WARN_CFLAGS
|
||||
])
|
||||
|
||||
|
||||
|
@ -45,6 +45,7 @@ ignore-value
|
||||
inet_pton
|
||||
ioctl
|
||||
maintainer-makefile
|
||||
manywarnings
|
||||
mkstemp
|
||||
mkstemps
|
||||
mktempd
|
||||
@ -85,6 +86,7 @@ vasprintf
|
||||
verify
|
||||
vc-list-files
|
||||
waitpid
|
||||
warnings
|
||||
'
|
||||
|
||||
# Additional xgettext options to use. Use "\\\newline" to break lines.
|
||||
|
15
configure.ac
15
configure.ac
@ -1970,12 +1970,14 @@ AC_ARG_ENABLE([test-coverage],
|
||||
enable_coverage=$enableval
|
||||
|
||||
if test "${enable_coverage}" = yes; then
|
||||
COMPILER_FLAGS=
|
||||
gl_COMPILER_FLAGS(-fprofile-arcs)
|
||||
gl_COMPILER_FLAGS(-ftest-coverage)
|
||||
AC_SUBST([COVERAGE_CFLAGS], [$COMPILER_FLAGS])
|
||||
AC_SUBST([COVERAGE_LDFLAGS], [$COMPILER_FLAGS])
|
||||
COMPILER_FLAGS=
|
||||
save_WARN_CFLAGS=$WARN_CFLAGS
|
||||
WARN_CFLAGS=
|
||||
gl_WARN_ADD([-fprofile-arcs])
|
||||
gl_WARN_ADD([-ftest-coverage])
|
||||
COVERAGE_FLAGS=$WARN_CFLAGS
|
||||
AC_SUBST([COVERAGE_CFLAGS], [$COVERAGE_FLAGS])
|
||||
AC_SUBST([COVERAGE_LDFLAGS], [$COVERAGE_FLAGS])
|
||||
WARN_CFLAGS=$save_WARN_CFLAGS
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([test-oom],
|
||||
@ -2538,6 +2540,7 @@ AC_MSG_NOTICE([Miscellaneous])
|
||||
AC_MSG_NOTICE([])
|
||||
AC_MSG_NOTICE([ Debug: $enable_debug])
|
||||
AC_MSG_NOTICE([ Warnings: $enable_compile_warnings])
|
||||
AC_MSG_NOTICE([Warning Flags: $WARN_CFLAGS])
|
||||
AC_MSG_NOTICE([ Readline: $lv_use_readline])
|
||||
AC_MSG_NOTICE([ Python: $with_python])
|
||||
AC_MSG_NOTICE([ DTrace: $with_dtrace])
|
||||
|
@ -1,48 +0,0 @@
|
||||
# serial 4
|
||||
# Find valid warning flags for the C Compiler. -*-Autoconf-*-
|
||||
#
|
||||
# Copyright (C) 2010 Red Hat, Inc.
|
||||
# Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA
|
||||
|
||||
# Written by Jesse Thilo.
|
||||
|
||||
AC_DEFUN([gl_COMPILER_FLAGS],
|
||||
[AC_MSG_CHECKING(whether compiler accepts $1)
|
||||
ac_save_CFLAGS="$CFLAGS"
|
||||
dnl Some flags are dependant, so we set all previously checked
|
||||
dnl flags when testing. Except for -Werror which we have to
|
||||
dnl check on its own, because some of our compiler flags cause
|
||||
dnl warnings from the autoconf test program!
|
||||
if test "$1" = "-Werror" ; then
|
||||
CFLAGS="$CFLAGS $1"
|
||||
else
|
||||
CFLAGS="$CFLAGS $COMPILER_FLAGS $1"
|
||||
fi
|
||||
AC_TRY_LINK([], [], has_option=yes, has_option=no,)
|
||||
echo 'int x;' >conftest.c
|
||||
$CC $CFLAGS -c conftest.c 2>conftest.err
|
||||
ret=$?
|
||||
if test $ret != 0 || test -s conftest.err || test $has_option = "no"; then
|
||||
AC_MSG_RESULT(no)
|
||||
else
|
||||
AC_MSG_RESULT(yes)
|
||||
COMPILER_FLAGS="$COMPILER_FLAGS $1"
|
||||
fi
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
rm -f conftest*
|
||||
])
|
Loading…
Reference in New Issue
Block a user