[libvirt-sandbox][PATCH 3/4] m4: sync macros with libvirt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The macros under the m4 directory are outdated a bit. When trying
to compile with newer gcc I see some errors:

make[4]: Entering directory '/home/zippy/work/libvirt/libvirt-sanbox.git/libvirt-sandbox'
  CC       libvirt_sandbox_1_0_la-libvirt-sandbox-main.lo
gcc: warning: switch '-Wmudflap' is no longer supported

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 m4/manywarnings.m4          | 217 ++++++++++++++++++++++++++++----------------
 m4/virt-compile-warnings.m4 | 216 +++++++++++++++++++++++++++++++------------
 m4/warnings.m4              |  82 +++++++++++++----
 3 files changed, 361 insertions(+), 154 deletions(-)

diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index fd0e372..3e6dd21 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,5 +1,5 @@
-# manywarnings.m4 serial 3
-dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
+# manywarnings.m4 serial 7
+dnl Copyright (C) 2008-2014 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.
@@ -35,14 +35,12 @@ AC_DEFUN([gl_MANYWARN_COMPLEMENT],
 # make sure your gcc understands it.
 AC_DEFUN([gl_MANYWARN_ALL_GCC],
 [
-  dnl First, check if -Wno-missing-field-initializers is needed.
-  dnl -Wmissing-field-initializers is implied by -W, but that issues
-  dnl warnings with GCC version before 4.7, for the common idiom
-  dnl of initializing types on the stack to zero, using { 0, }
+  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 First, check -W -Werror -Wno-missing-field-initializers is supported
+    dnl Check if -W -Werror -Wno-missing-field-initializers is supported
     dnl with the current $CC $CFLAGS $CPPFLAGS.
     AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
     AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
@@ -77,108 +75,171 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
       ])
       AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
     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_MSG_CHECKING([whether -Wuninitialized is supported])
+    AC_CACHE_VAL([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"])
+    AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
+
   fi
 
+  # List all gcc warning categories.
+  # To compare this list to your installed GCC's, run this Bash command:
+  #
+  # comm -3 \
+  #  <(sed -n 's/^  *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
+  #  <(gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort |
+  #      grep -v -x -f <(
+  #         awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
+
   gl_manywarn_set=
   for gl_manywarn_item in \
-    -Wall \
     -W \
-    -Wformat-y2k \
-    -Wformat-nonliteral \
-    -Wformat-security \
-    -Winit-self \
-    -Wmissing-include-dirs \
-    -Wswitch-default \
-    -Wswitch-enum \
-    -Wunused \
-    -Wunknown-pragmas \
-    -Wstrict-aliasing \
-    -Wstrict-overflow \
-    -Wsystem-headers \
-    -Wfloat-equal \
-    -Wtraditional \
-    -Wtraditional-conversion \
-    -Wdeclaration-after-statement \
-    -Wundef \
-    -Wshadow \
-    -Wunsafe-loop-optimizations \
-    -Wpointer-arith \
-    -Wbad-function-cast \
-    -Wc++-compat \
-    -Wcast-qual \
-    -Wcast-align \
-    -Wwrite-strings \
-    -Wconversion \
-    -Wsign-conversion \
-    -Wlogical-op \
-    -Waggregate-return \
-    -Wstrict-prototypes \
-    -Wold-style-definition \
-    -Wmissing-prototypes \
-    -Wmissing-declarations \
-    -Wmissing-noreturn \
-    -Wmissing-format-attribute \
-    -Wpacked \
-    -Wpadded \
-    -Wredundant-decls \
-    -Wnested-externs \
-    -Wunreachable-code \
-    -Winline \
-    -Winvalid-pch \
-    -Wlong-long \
-    -Wvla \
-    -Wvolatile-register-var \
-    -Wdisabled-optimization \
-    -Wstack-protector \
-    -Woverlength-strings \
-    -Wbuiltin-macro-redefined \
-    -Wmudflap \
-    -Wpacked-bitfield-compat \
-    -Wsync-nand \
-    ; do
-    gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
-  done
-  # The following are not documented in the manual but are included in
-  # output from gcc --help=warnings.
-  for gl_manywarn_item in \
-    -Wattributes \
-    -Wcoverage-mismatch \
-    -Wmultichar \
-    -Wunused-macros \
-    ; do
-    gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
-  done
-  # More warnings from gcc 4.6.2 --help=warnings.
-  for gl_manywarn_item in \
     -Wabi \
+    -Waddress \
+    -Waggressive-loop-optimizations \
+    -Wall \
+    -Warray-bounds \
+    -Wattributes \
+    -Wbad-function-cast \
+    -Wbuiltin-macro-redefined \
+    -Wcast-align \
+    -Wchar-subscripts \
+    -Wclobbered \
+    -Wcomment \
+    -Wcomments \
+    -Wcoverage-mismatch \
     -Wcpp \
+    -Wdate-time \
     -Wdeprecated \
     -Wdeprecated-declarations \
+    -Wdisabled-optimization \
     -Wdiv-by-zero \
     -Wdouble-promotion \
+    -Wempty-body \
     -Wendif-labels \
+    -Wenum-compare \
     -Wextra \
     -Wformat-contains-nul \
     -Wformat-extra-args \
+    -Wformat-nonliteral \
+    -Wformat-security \
+    -Wformat-y2k \
     -Wformat-zero-length \
-    -Wformat=2 \
+    -Wfree-nonheap-object \
+    -Wignored-qualifiers \
+    -Wimplicit \
+    -Wimplicit-function-declaration \
+    -Wimplicit-int \
+    -Winit-self \
+    -Winline \
+    -Wint-to-pointer-cast \
+    -Winvalid-memory-model \
+    -Winvalid-pch \
+    -Wjump-misses-init \
+    -Wlogical-op \
+    -Wmain \
+    -Wmaybe-uninitialized \
+    -Wmissing-braces \
+    -Wmissing-declarations \
+    -Wmissing-field-initializers \
+    -Wmissing-include-dirs \
+    -Wmissing-parameter-type \
+    -Wmissing-prototypes \
     -Wmultichar \
-    -Wnormalized=nfc \
+    -Wnarrowing \
+    -Wnested-externs \
+    -Wnonnull \
+    -Wold-style-declaration \
+    -Wold-style-definition \
+    -Wopenmp-simd \
     -Woverflow \
+    -Woverlength-strings \
+    -Woverride-init \
+    -Wpacked \
+    -Wpacked-bitfield-compat \
+    -Wparentheses \
+    -Wpointer-arith \
+    -Wpointer-sign \
     -Wpointer-to-int-cast \
     -Wpragmas \
+    -Wreturn-local-addr \
+    -Wreturn-type \
+    -Wsequence-point \
+    -Wshadow \
+    -Wsizeof-pointer-memaccess \
+    -Wstack-protector \
+    -Wstrict-aliasing \
+    -Wstrict-overflow \
+    -Wstrict-prototypes \
     -Wsuggest-attribute=const \
+    -Wsuggest-attribute=format \
     -Wsuggest-attribute=noreturn \
     -Wsuggest-attribute=pure \
+    -Wswitch \
+    -Wswitch-default \
+    -Wsync-nand \
+    -Wsystem-headers \
     -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
 
-  # Disable the missing-field-initializers warning if needed
+  # gcc --help=warnings outputs an unusual form for this option; list
+  # it here so that the above 'comm' command doesn't report a false match.
+  gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
+
+  # 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
 ])
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 894ab59..532a777 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -2,7 +2,7 @@ dnl
 dnl Enable all known GCC compiler warnings, except for those
 dnl we can't yet cope with
 dnl
-AC_DEFUN([LIBVIRT_SANDBOX_COMPILE_WARNINGS],[
+AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     dnl ******************************
     dnl More compiler warnings
     dnl ******************************
@@ -33,19 +33,96 @@ AC_DEFUN([LIBVIRT_SANDBOX_COMPILE_WARNINGS],[
     dontwarn="$dontwarn -Wpadded"
     # GCC very confused with -O2
     dontwarn="$dontwarn -Wunreachable-code"
-    # We explicitly need to remove const sometimes
+    # 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"
-    # Allow vars decl in the middle of blocks
-    dontwarn="$dontwarn -Wdeclaration-after-statement"
-    # Using long long is fine
+    # We need to use long long in many places
     dontwarn="$dontwarn -Wlong-long"
-    # Unused macros are ok
+    # 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"
+    # Gnulib's stat-time.h violates this
+    dontwarn="$dontwarn -Waggregate-return"
+    # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall
+    dontwarn="$dontwarn -Wenum-compare"
+
+    # gcc 4.2 treats attribute(format) as an implicit attribute(nonnull),
+    # which triggers spurious warnings for our usage
+    AC_CACHE_CHECK([whether the C compiler's -Wformat allows NULL strings],
+      [lv_cv_gcc_wformat_null_works], [
+      save_CFLAGS=$CFLAGS
+      CFLAGS='-Wunknown-pragmas -Werror -Wformat'
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <stddef.h>
+        static __attribute__ ((__format__ (__printf__, 1, 2))) int
+        foo (const char *fmt, ...) { return !fmt; }
+      ]], [[
+        return foo(NULL);
+      ]])],
+      [lv_cv_gcc_wformat_null_works=yes],
+      [lv_cv_gcc_wformat_null_works=no])
+      CFLAGS=$save_CFLAGS])
+
+    # Gnulib uses '#pragma GCC diagnostic push' to silence some
+    # warnings, but older gcc doesn't support this.
+    AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
+      [lv_cv_gcc_pragma_push_works], [
+      save_CFLAGS=$CFLAGS
+      CFLAGS='-Wunknown-pragmas -Werror'
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #pragma GCC diagnostic push
+        #pragma GCC diagnostic pop
+      ]])],
+      [lv_cv_gcc_pragma_push_works=yes],
+      [lv_cv_gcc_pragma_push_works=no])
+      CFLAGS=$save_CFLAGS])
+    if test $lv_cv_gcc_pragma_push_works = no; then
+      dontwarn="$dontwarn -Wmissing-prototypes"
+      dontwarn="$dontwarn -Wmissing-declarations"
+      dontwarn="$dontwarn -Wcast-align"
+    else
+      AC_DEFINE_UNQUOTED([WORKING_PRAGMA_PUSH], 1,
+       [Define to 1 if gcc supports pragma push/pop])
+    fi
+
+    dnl Check whether strchr(s, char variable) causes a bogus compile
+    dnl warning, which is the case with GCC < 4.6 on some glibc
+    AC_CACHE_CHECK([whether the C compiler's -Wlogical-op gives bogus warnings],
+      [lv_cv_gcc_wlogical_op_broken], [
+      save_CFLAGS="$CFLAGS"
+      CFLAGS="-O2 -Wlogical-op -Werror"
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <string.h>
+        ]], [[
+        const char *haystack;
+        char needle;
+        return strchr(haystack, needle) == haystack;]])],
+        [lv_cv_gcc_wlogical_op_broken=no],
+        [lv_cv_gcc_wlogical_op_broken=yes])
+      CFLAGS="$save_CFLAGS"])
+
+    # 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 -Wpacked"
     dontwarn="$dontwarn -Wunused-macros"
-
-
-    # g_clear_object & G_ATOMIC_OP_USE_GCC_BUILTINS causes
-    # violations with this. XXX Fix glib ?
-    dontwarn="$dontwarn -Wbad-function-cast"
+    dontwarn="$dontwarn -Woverlength-strings"
+    dontwarn="$dontwarn -Wstack-protector"
 
     # Get all possible GCC warnings
     gl_MANYWARN_ALL_GCC([maybewarn])
@@ -53,78 +130,105 @@ AC_DEFUN([LIBVIRT_SANDBOX_COMPILE_WARNINGS],[
     # 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])
-
-    # Due to gutils.h bug in g_bit_storage
-    gl_WARN_ADD([-Wno-sign-conversion])
-    gl_WARN_ADD([-Wno-conversion])
-    gl_WARN_ADD([-Wno-unused-parameter])
-    # We can't enable this due to horrible spice_usb_device_get_description
-    # signature
-    gl_WARN_ADD([-Wno-format-nonliteral])
-
-
+    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
-    gl_WARN_ADD([-Wjump-misses-init])
+    wantwarn="$wantwarn -Wjump-misses-init"
+
+    # GNULIB turns on -Wformat=2 which implies -Wformat-nonliteral,
+    # so we need to manually re-exclude it.  Also, older gcc 4.2
+    # added an implied ATTRIBUTE_NONNULL on any parameter marked
+    # ATTRIBUTE_FMT_PRINT, which causes -Wformat failure on our
+    # intentional use of virReportError(code, NULL).
+    wantwarn="$wantwarn -Wno-format-nonliteral"
+    if test $lv_cv_gcc_wformat_null_works = no; then
+      wantwarn="$wantwarn -Wno-format"
+    fi
 
     # 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
-    gl_WARN_ADD([-Wframe-larger-than=4096])
-
-    # Use improved glibc headers
-    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
-    ])
+    wantwarn="$wantwarn -Wframe-larger-than=4096"
+    dnl wantwarn="$wantwarn -Wframe-larger-than=256"
 
     # 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 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])
+       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
-    gl_WARN_ADD([-fexceptions])
-    gl_WARN_ADD([-fasynchronous-unwind-tables])
-    gl_WARN_ADD([-fdiagnostics-show-option])
-    gl_WARN_ADD([-funit-at-a-time])
+    wantwarn="$wantwarn -fexceptions"
+    wantwarn="$wantwarn -fasynchronous-unwind-tables"
 
     # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure
     # fire even without -O.
-    gl_WARN_ADD([-fipa-pure-const])
-
+    wantwarn="$wantwarn -fipa-pure-const"
     # We should eventually enable this, but right now there are at
     # least 75 functions triggering warnings.
-    gl_WARN_ADD([-Wno-suggest-attribute=pure])
-    gl_WARN_ADD([-Wno-suggest-attribute=const])
-
+    wantwarn="$wantwarn -Wno-suggest-attribute=pure"
+    wantwarn="$wantwarn -Wno-suggest-attribute=const"
 
     if test "$set_werror" = "yes"
     then
-      gl_WARN_ADD([-Werror])
+      wantwarn="$wantwarn -Werror"
     fi
 
-    WARN_LDFLAGS=$WARN_CFLAGS
-    AC_SUBST([WARN_CFLAGS])
-    AC_SUBST([WARN_LDFLAGS])
+    # 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
+
+    # Silence certain warnings in gnulib, and use improved glibc headers
+    AC_DEFINE([lint], [1],
+      [Define to 1 if the compiler is checking for lint.])
+    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
+    ])
+
+    if test "$gl_cv_warn_c__Wlogical_op" = yes &&
+       test "$lv_cv_gcc_wlogical_op_broken" = yes; then
+      AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP], 1,
+       [Define to 1 if gcc -Wlogical-op reports false positives on strchr])
+    fi
 ])
diff --git a/m4/warnings.m4 b/m4/warnings.m4
index 69d05a6..43156f4 100644
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -1,5 +1,5 @@
-# warnings.m4 serial 5
-dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
+# warnings.m4 serial 11
+dnl Copyright (C) 2008-2014 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.
@@ -14,24 +14,66 @@ m4_ifdef([AS_VAR_APPEND],
 [m4_define([gl_AS_VAR_APPEND],
 [AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
 
-# gl_WARN_ADD(PARAMETER, [VARIABLE = WARN_CFLAGS])
-# ------------------------------------------------
-# Adds parameter to WARN_CFLAGS if the compiler supports it.  For example,
-# gl_WARN_ADD([-Wparentheses]).
-AC_DEFUN([gl_WARN_ADD],
-dnl FIXME: gl_Warn must be used unquoted until we can assume
-dnl autoconf 2.64 or newer.
-[AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_$1])dnl
-AC_CACHE_CHECK([whether compiler handles $1], m4_defn([gl_Warn]), [
-  gl_save_CPPFLAGS="$CPPFLAGS"
-  CPPFLAGS="${CPPFLAGS} $1"
-  AC_PREPROC_IFELSE([AC_LANG_PROGRAM([])],
-                    [AS_VAR_SET(gl_Warn, [yes])],
-                    [AS_VAR_SET(gl_Warn, [no])])
-  CPPFLAGS="$gl_save_CPPFLAGS"
+
+# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
+#                       [PROGRAM = AC_LANG_PROGRAM()])
+# -----------------------------------------------------------------
+# Check if the compiler supports OPTION when compiling PROGRAM.
+#
+# FIXME: gl_Warn must be used unquoted until we can assume Autoconf
+# 2.64 or newer.
+AC_DEFUN([gl_COMPILER_OPTION_IF],
+[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],
-  [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])])
+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
-m4_ifval([$2], [AS_LITERAL_IF([$2], [AC_SUBST([$2])], [])])dnl
 ])
+
+# gl_UNKNOWN_WARNINGS_ARE_ERRORS
+# ------------------------------
+# Clang doesn't complain about unknown warning options unless one also
+# specifies -Wunknown-warning-option -Werror.  Detect this.
+AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
+[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],
+#             [PROGRAM = AC_LANG_PROGRAM()])
+# ---------------------------------------------
+# Adds parameter to WARN_CFLAGS if the compiler supports it when
+# compiling PROGRAM.  For example, gl_WARN_ADD([-Wparentheses]).
+#
+# If VARIABLE is a variable name, AC_SUBST it.
+AC_DEFUN([gl_WARN_ADD],
+[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS])
+gl_COMPILER_OPTION_IF([$1],
+  [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])],
+  [],
+  [$3])
+m4_ifval([$2],
+         [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
+         [AC_SUBST([WARN_CFLAGS])])dnl
+])
+
+# Local Variables:
+# mode: autoconf
+# End:
-- 
2.0.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]