]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool: Avoid known warnings that reflect Gnulib's coding style.
authorBruno Haible <bruno@clisp.org>
Wed, 5 Jan 2022 17:21:55 +0000 (18:21 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 5 Jan 2022 17:21:55 +0000 (18:21 +0100)
* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): New macro.
* gnulib-tool (func_emit_lib_Makefile_am): Add the
GL_CFLAG_GNULIB_WARNINGS to the CFLAGS of all the compilation units of
the library.
(func_emit_tests_Makefile_am): Add the GL_CFLAG_GNULIB_WARNINGS to the
CFLAGS.
(func_import): Emit an invocation of gl_CC_GNULIB_WARNINGS.

ChangeLog
gnulib-tool
m4/gnulib-common.m4

index a60192b9234fd628231fe975e668ab9de38b63df..f10b0b2aadf0c82475284c121bfd93d9efdfbeeb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-01-05  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool: Avoid known warnings that reflect Gnulib's coding style.
+       * m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): New macro.
+       * gnulib-tool (func_emit_lib_Makefile_am): Add the
+       GL_CFLAG_GNULIB_WARNINGS to the CFLAGS of all the compilation units of
+       the library.
+       (func_emit_tests_Makefile_am): Add the GL_CFLAG_GNULIB_WARNINGS to the
+       CFLAGS.
+       (func_import): Emit an invocation of gl_CC_GNULIB_WARNINGS.
+
 2022-01-04  Bernhard Voelker  <mail@bernhard-voelker.de>
 
        license: fix GPLv3 texts to use a comma instead of semicolon.
index 02d4f8661d1bfd706eb1cd42564d0f9d71739dd7..a91847f55a5a85bf7d41bca492681faad6b38521 100755 (executable)
@@ -3974,6 +3974,9 @@ func_emit_lib_Makefile_am ()
   fi
   echo
   echo "${libname}_${libext}_SOURCES ="
+  if ! $for_test; then
+    echo "${libname}_${libext}_CFLAGS = \$(AM_CFLAGS) \$(GL_CFLAG_GNULIB_WARNINGS)"
+  fi
   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
   # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
@@ -4343,7 +4346,12 @@ func_emit_tests_Makefile_am ()
   #   CFLAGS, they have asked for errors, they will get errors. But they have
   #   no right to complain about these errors, because Gnulib does not support
   #   '-Werror'.
-  echo "CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@ @CFLAGS@"
+  cflags_for_gnulib_code=
+  if ! $for_test; then
+    # Enable or disable warnings as suitable for the Gnulib coding style.
+    cflags_for_gnulib_code=" \$(GL_CFLAG_GNULIB_WARNINGS)"
+  fi
+  echo "CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@${cflags_for_gnulib_code} @CFLAGS@"
   echo "CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@"
   echo
   echo "AM_CPPFLAGS = \\"
@@ -6056,6 +6064,7 @@ s,//*$,/,'
     func_emit_autoconf_snippets "$testsrelated_modules" "$main_modules $testsrelated_modules" func_verify_module true true true
     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
     func_emit_initmacro_end ${macro_prefix}tests $gentests
+    echo "  AC_REQUIRE([gl_CC_GNULIB_WARNINGS])"
     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
     # created using libtool, because libtool already handles the dependencies.
     if test "$libtool" != true; then
index 87a9a751b6ad5ead6a5ce254de1391bb69f9fc54..179aac7aa1e461e1172776a4ccad6928c55551d3 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 69
+# gnulib-common.m4 serial 70
 dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -879,6 +879,70 @@ AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
   AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
 ])
 
+# gl_CC_GNULIB_WARNINGS
+# sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
+# set that enables or disables warnings as suitable for the Gnulib coding style.
+AC_DEFUN([gl_CC_GNULIB_WARNINGS],
+[
+  AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
+  dnl Assume that the compiler supports -Wno-* options only if it also supports
+  dnl -Wno-error.
+  GL_CFLAG_GNULIB_WARNINGS=''
+  if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
+    dnl Enable these warning options:
+    dnl
+    dnl                                       GCC             clang
+    dnl -Wno-cast-qual                        >= 3            >= 3.9
+    dnl -Wno-conversion                       >= 3            >= 3.9
+    dnl -Wno-float-conversion                 >= 4.9          >= 3.9
+    dnl -Wno-float-equal                      >= 3            >= 3.9
+    dnl -Wimplicit-fallthrough                >= 3            >= 3.9
+    dnl -Wno-pedantic                         >= 4.8          >= 3.9
+    dnl -Wno-sign-compare                     >= 3            >= 3.9
+    dnl -Wno-sign-conversion                  >= 4.3          >= 3.9
+    dnl -Wno-type-limits                      >= 4.3          >= 3.9
+    dnl -Wno-undef                            >= 3            >= 3.9
+    dnl -Wno-unsuffixed-float-constants       >= 4.5
+    dnl -Wno-unused-function                  >= 3            >= 3.9
+    dnl -Wno-unused-parameter                 >= 3            >= 3.9
+    dnl
+    cat > conftest.c <<\EOF
+      #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      -Wno-cast-qual
+      -Wno-conversion
+      -Wno-float-equal
+      -Wimplicit-fallthrough
+      -Wno-sign-compare
+      -Wno-undef
+      -Wno-unused-function
+      -Wno-unused-parameter
+      #endif
+      #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      -Wno-float-conversion
+      #endif
+      #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      -Wno-pedantic
+      #endif
+      #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      -Wno-sign-conversion
+      -Wno-type-limits
+      #endif
+      #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+      -Wno-unsuffixed-float-constants
+      #endif
+EOF
+    gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
+    if AC_TRY_EVAL([gl_command]); then
+      gl_options=`grep -v '#' conftest.out`
+      for word in $gl_options; do
+        GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
+      done
+    fi
+    rm -f conftest.c conftest.out
+  fi
+  AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
+])
+
 dnl gl_CONDITIONAL_HEADER([foo.h])
 dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
 dnl and produces