aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-11-26 11:26:13 +0100
committerAlexis La Goutte <alexis.lagoutte@gmail.com>2015-11-26 13:02:42 +0000
commit470c745a7a0a5b930bdfb0edd8874436cb9beea0 (patch)
tree8dbb5e741f8143705a5d8f55f769055756d5f647
parenta198f47c06723fabef174cb3983b26ead24f5bc9 (diff)
autotools: do not apply CFLAGS in reverse order
Fixes false "-Wvariadic-macros" because "-Wpedantic" came after "-Wno-variadic-macros". While at it, avoid (unintentionally?) adding -fPIE to all C++ programs (via CXXFLAGS). Availability of flags is checked by appending a flag (in case the user has something like CFLAGS=-Wno-error). This removes a -fPIE check for CXXFLAGS and removes 5 -Woverlength-strings and 9 -Wvariadic-macros warnings from make with Clang 3.7.0. configure and compile times were equal. (A diff between the configure outputs showed no other changes.) This reverts commit cf0d762d7304aa569ea25faf999c74bbe94f9023 and applies a different approach. Ping-Bug: 10791 Change-Id: Ic7b4137e2d98b06bc7625091be9bc7dd69182586 Reviewed-on: https://code.wireshark.org/review/12175 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
-rw-r--r--acinclude.m442
-rw-r--r--configure.ac32
2 files changed, 41 insertions, 33 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 14e39c43cc..1851503956 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1532,7 +1532,9 @@ AC_DEFUN([AC_WIRESHARK_CHECK_NON_CXX_WARNING_OPTION_ERROR],
#
# The macro first determines if the compiler supports GCC-style flags.
# Then it attempts to compile with the defined cflags. The defined
-# flags are added to CFLAGS only if the compilation succeeds.
+# flags are added to WS_CHECKED_CFLAGS only if the compilation succeeds.
+# CFLAGS remains unchanged. can_add_to_cflags is set to "no" when the
+# flag is checked but unavailable. (Like-wise for CXXFLAGS.)
#
# We do this because not all such options are necessarily supported by
# the version of the particular compiler we're using.
@@ -1560,17 +1562,18 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
#
AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
CFLAGS_saved="$CFLAGS"
+ CFLAGS="$WS_CHECKED_CFLAGS $CFLAGS"
if expr "x$GCC_OPTION" : "x-W.*" >/dev/null
then
- CFLAGS="$ac_wireshark_unknown_warning_option_error $GCC_OPTION $CFLAGS"
+ CFLAGS="$CFLAGS $ac_wireshark_unknown_warning_option_error $GCC_OPTION"
elif expr "x$GCC_OPTION" : "x-f.*" >/dev/null
then
- CFLAGS="-Werror $GCC_OPTION $CFLAGS"
+ CFLAGS="$CFLAGS -Werror $GCC_OPTION"
elif expr "x$GCC_OPTION" : "x-m.*" >/dev/null
then
- CFLAGS="-Werror $GCC_OPTION $CFLAGS"
+ CFLAGS="$CFLAGS -Werror $GCC_OPTION"
else
- CFLAGS="$GCC_OPTION $CFLAGS"
+ CFLAGS="$CFLAGS $GCC_OPTION"
fi
AC_COMPILE_IFELSE(
[
@@ -1591,7 +1594,7 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
CFLAGS="$CFLAGS -Werror"
AC_MSG_CHECKING(whether $GCC_OPTION $4)
AC_COMPILE_IFELSE(
- [AC_LANG_SOURCE($3)],
+ [AC_LANG_SOURCE($3)],
[
AC_MSG_RESULT(no)
#
@@ -1599,19 +1602,18 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
# added them, by setting CFLAGS to the saved value plus
# just the new option.
#
- CFLAGS="$GCC_OPTION $CFLAGS_saved"
+ WS_CHECKED_CFLAGS="$WS_CHECKED_CFLAGS $GCC_OPTION"
if test "$CC" = "$CC_FOR_BUILD"; then
#
# We're building the build tools with the same compiler
# with which we're building Wireshark, so add the flags
# to the flags for that compiler as well.
#
- CFLAGS_FOR_BUILD="$GCC_OPTION $CFLAGS_FOR_BUILD"
+ CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $GCC_OPTION"
fi
],
[
AC_MSG_RESULT(yes)
- CFLAGS="$CFLAGS_saved"
])
else
#
@@ -1619,22 +1621,22 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
# added them, by setting CFLAGS to the saved value plus
# just the new option.
#
- CFLAGS="$GCC_OPTION $CFLAGS_saved"
+ WS_CHECKED_CFLAGS="$WS_CHECKED_CFLAGS $GCC_OPTION"
if test "$CC" = "$CC_FOR_BUILD"; then
#
# We're building the build tools with the same compiler
# with which we're building Wireshark, so add the flags
# to the flags for that compiler as well.
#
- CFLAGS_FOR_BUILD="$GCC_OPTION $CFLAGS_FOR_BUILD"
+ CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $GCC_OPTION"
fi
fi
],
[
AC_MSG_RESULT(no)
can_add_to_cflags=no
- CFLAGS="$CFLAGS_saved"
])
+ CFLAGS="$CFLAGS_saved"
fi
#
# Did we find a C++ compiler?
@@ -1666,17 +1668,18 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
#
AC_MSG_CHECKING(whether we can add $GCC_OPTION to CXXFLAGS)
CXXFLAGS_saved="$CXXFLAGS"
+ CXXFLAGS="$WS_CHECKED_CXXFLAGS $CXXFLAGS"
if expr "x$GCC_OPTION" : "x-W.*" >/dev/null
then
- CXXFLAGS="$ac_wireshark_unknown_warning_option_error $ac_wireshark_non_cxx_warning_option_error $GCC_OPTION $CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $ac_wireshark_unknown_warning_option_error $ac_wireshark_non_cxx_warning_option_error $GCC_OPTION"
elif expr "x$GCC_OPTION" : "x-f.*" >/dev/null
then
- CXXFLAGS="-Werror $GCC_OPTION $CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS -Werror $GCC_OPTION"
elif expr "x$GCC_OPTION" : "x-m.*" >/dev/null
then
- CXXFLAGS="-Werror $GCC_OPTION $CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS -Werror $GCC_OPTION"
else
- CXXFLAGS="$GCC_OPTION $CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $GCC_OPTION"
fi
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE(
@@ -1706,11 +1709,10 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
# added them, by setting CXXFLAGS to the saved value plus
# just the new option.
#
- CXXFLAGS="$GCC_OPTION $CXXFLAGS_saved"
+ WS_CHECKED_CXXFLAGS="$WS_CHECKED_CXXFLAGS $GCC_OPTION"
],
[
AC_MSG_RESULT(yes)
- CXXFLAGS="$CXXFLAGS_saved"
])
else
#
@@ -1718,14 +1720,14 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
# added them, by setting CXXFLAGS to the saved value plus
# just the new option.
#
- CXXFLAGS="$GCC_OPTION $CXXFLAGS_saved"
+ WS_CHECKED_CXXFLAGS="$WS_CHECKED_CXXFLAGS $GCC_OPTION"
fi
],
[
AC_MSG_RESULT(no)
can_add_to_cxxflags=no
- CXXFLAGS="$CXXFLAGS_saved"
])
+ CXXFLAGS="$CXXFLAGS_saved"
AC_LANG_POP([C++])
fi
if test "(" "$can_add_to_cflags" = "yes" -a "$can_add_to_cxxflags" = "no" ")" \
diff --git a/configure.ac b/configure.ac
index 9cfa254e5f..71b3e7d233 100644
--- a/configure.ac
+++ b/configure.ac
@@ -941,6 +941,7 @@ AC_ARG_ENABLE(asan,
# and no yet all leak is fixed...
# use ASAN_OPTIONS=detect_leaks=0 to disable detect_leaks
#
+ # XXX shouldn't this also be added to LDFLAGS?
AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fsanitize=address)
],)
@@ -1048,18 +1049,16 @@ AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fexcess-precision=fast)
# failures to export symbols, rather than having that fail only on
# Windows.
#
-CFLAGS_before_fvhidden="$CFLAGS"
-#
# GCC and GCC-compatible compilers
#
AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fvisibility=hidden)
-if test "x$CFLAGS" = "x$CFLAGS_before_fvhidden"
+if test "x$can_add_to_cflags" = "xno"
then
#
# Sun^WOracle C.
#
AC_WIRESHARK_COMPILER_FLAGS_CHECK(-xldscope=hidden)
- if test "x$CFLAGS" = "x$CFLAGS_before_fvhidden"
+ if test "x$can_add_to_cflags" = "xno"
then
# TODO add other ways of hiding symbols
AC_MSG_WARN(Compiler will export all symbols from shared libraries)
@@ -1079,12 +1078,12 @@ AC_WIRESHARK_LDFLAGS_CHECK([-Wl,--as-needed])
# privileges, and using PIE means the OS can run it at random locations
# in the address space to make attacks more difficult.
#
-CFLAGS_before_pie="$CFLAGS"
-AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fPIE)
-if test "x$CFLAGS" != "x$CFLAGS_before_pie"
+WS_CHECKED_CFLAGS_before_pie="$WS_CHECKED_CFLAGS"
+AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fPIE, C)
+if test "x$can_add_to_cflags" = "xyes"
then
# Restore CFLAGS
- CFLAGS="$CFLAGS_before_pie"
+ WS_CHECKED_CFLAGS="$WS_CHECKED_CFLAGS_before_pie"
LDFLAGS_before_pie="$LDFLAGS"
AC_WIRESHARK_LDFLAGS_CHECK([-fPIE -pie])
@@ -1102,9 +1101,9 @@ fi
AC_SUBST(PIE_CFLAGS)
AC_SUBST(PIE_LDFLAGS)
-CFLAGS_before_simd="$CFLAGS"
+WS_CHECKED_CFLAGS_before_simd="$WS_CHECKED_CFLAGS"
AC_WIRESHARK_COMPILER_FLAGS_CHECK(-msse4.2, C)
-if test "x$CFLAGS" != "x$CFLAGS_before_simd"
+if test "x$can_add_to_cflags" = "xyes"
then
#
# The compiler supports -msse4.2; use that to enable SSE 4.2.
@@ -1114,14 +1113,14 @@ then
# is run only if the hardware supports it, but other
# code would do no such checks.
#
- CFLAGS="$CFLAGS_before_simd"
+ WS_CHECKED_CFLAGS="$WS_CHECKED_CFLAGS_before_simd"
ac_sse4_2_flag=-msse4.2
else
#
# Try -xarch=sse4_2; that's the flag for Sun's compiler.
#
AC_WIRESHARK_COMPILER_FLAGS_CHECK(-xarch=sse4_2, C)
- if test "x$CFLAGS" != "x$CFLAGS_before_simd"
+ if test "x$can_add_to_cflags" = "xyes"
then
#
# The compiler supports -xarch=sse4_2; use that to
@@ -1129,11 +1128,18 @@ else
#
# Restore CFLAGS; see above.
#
- CFLAGS="$CFLAGS_before_simd"
+ WS_CHECKED_CFLAGS="$WS_CHECKED_CFLAGS_before_simd"
ac_sse4_2_flag=-xarch=sse4_2
fi
fi
+#
+# All AC_WIRESHARK_COMPILER_FLAGS_CHECK are done, do not call it again!
+# Prepend them to the user-specified CFLAGS/CXXFLAGS.
+#
+CFLAGS="$WS_CHECKED_CFLAGS $CFLAGS"
+CXXFLAGS="$WS_CHECKED_CXXFLAGS $CXXFLAGS"
+
if test "x$ac_sse4_2_flag" != x; then
#
# OK, we have a compiler flag to enable SSE 4.2.