Have AC_WIRESHARK_GCC_CFLAGS_CHECK take an optional second flag to

indicate whether the flag is C-only, C++-only, or for both compilers;
pass the appropriate value for C-only flags.  Have the "Checking for..."
message indicate whether we're adding to CFLAGS, CXXFLAGS, or both.

(Yes, the macro should probably be renamed.  "GCC" refers to the GNU
Compiler Collection, which includes a C++ compiler, although that's also
used for compilers that are more-or-less compatible with the ones from
the GNU Compiler Collection, such as the clang compilers.)

We set -Wformat-security whether or not --enable-extra-gcc-checks was
specified, so we don't need to do it again if it was specified.

svn path=/trunk/; revision=41586
This commit is contained in:
Guy Harris 2012-03-16 00:49:01 +00:00
parent 74f884820e
commit b53e379447
2 changed files with 80 additions and 23 deletions

View File

@ -1574,6 +1574,7 @@ fi
# AC_WIRESHARK_GCC_CFLAGS_CHECK
#
# $1 : cflags to test
# $2 : if supplied, C for C-only flags, CXX for C++-only flags
#
# The macro first determines if the compiler supports GCC-style flags.
# Then it attempts to compile with the defined cflags. The defined
@ -1590,24 +1591,81 @@ fi
#
AC_DEFUN([AC_WIRESHARK_GCC_CFLAGS_CHECK],
[GCC_OPTION="$1"
AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
case "$2" in
C)
AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
;;
CXX)
AC_MSG_CHECKING(whether we can add $GCC_OPTION to CXXFLAGS)
;;
*)
AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS and CXXFLAGS)
;;
esac
if test "x$ac_supports_gcc_flags" = "xyes" ; then
CFLAGS_saved="$CFLAGS"
CFLAGS="$CFLAGS $GCC_OPTION"
if test "x$CC" = "xclang" ; then
CFLAGS="$CFLAGS -Werror=unknown-warning-option"
if test "$2" != CXX ; then
#
# Not C++-only; if this can be added to the C compiler flags, add them.
#
CFLAGS_saved="$CFLAGS"
CFLAGS="$CFLAGS $GCC_OPTION"
if test "x$CC" = "xclang" ; then
#
# Force clang to fail on an unknown warning option; by default,
# it whines but doesn't fail, so we add unknown options and,
# as a result, get a lot of that whining when we compile.
#
CFLAGS="$CFLAGS -Werror=unknown-warning-option"
fi
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
int foo;
]])],
[
AC_MSG_RESULT(yes)
#
# Remove -Werror=unknown-warning-option, if we
# added it, by setting CFLAGS to the saved value
# plus just the new option.
#
CFLAGS="$CFLAGS_saved $GCC_OPTION"
if test "$2" != C ; then
#
# Add it to the C++ flags as well.
#
CXXFLAGS="$CXXFLAGS $GCC_OPTION"
fi
],
[
AC_MSG_RESULT(no)
CFLAGS="$CFLAGS_saved"
])
else
#
# C++-only; if this can be added to the C++ compiler flags, add them.
#
CXXFLAGS_saved="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $GCC_OPTION"
if test "x$CC" = "xclang" ; then
CXXFLAGS="$CXXFLAGS -Werror=unknown-warning-option"
fi
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
int foo;
]])],
[
AC_MSG_RESULT(yes)
],
[
AC_MSG_RESULT(no)
CXXFLAGS="$CXXFLAGS_saved"
])
AC_LANG_POP([C++])
fi
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
int foo;
]])],
[
AC_MSG_RESULT(yes)
],
[
AC_MSG_RESULT(no)
CFLAGS="$CFLAGS_saved"
])
else
AC_MSG_RESULT(no)
fi

View File

@ -324,19 +324,18 @@ AC_ARG_ENABLE(extra-gcc-checks,
# AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wunreachable-code)
# AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wunsafe-loop-optimizations)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wno-long-long)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wbad-function-cast)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wbad-function-cast, C)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wcast-qual)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Waddress)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Warray-bounds)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wattributes)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wdiv-by-zero)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wformat-security)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wignored-qualifiers)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wpragmas)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wredundant-decls)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wvla)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wc++-compat)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wjump-misses-init)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wc++-compat, C)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wjump-misses-init, C)
#
# epan/dissectors/packet-ncp2222.inc blocks this one
# for now.
@ -363,14 +362,14 @@ AC_ARG_ENABLE(extra-gcc-checks,
],)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wall -W) # -W is now known as -Wextra
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wextra) # -W is now known as -Wextra
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wdeclaration-after-statement)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wdeclaration-after-statement, C)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wendif-labels)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wpointer-arith)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wno-pointer-sign)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wno-pointer-sign, C)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Warray-bounds)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wcast-align)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wformat-security)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wold-style-definition)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wold-style-definition, C)
AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wno-error=unused-but-set-variable) ## for now
#
# Use the faster pre gcc 4.5 floating point precision if available;