From: Bruno Haible Date: Wed, 5 Jan 2022 17:21:55 +0000 (+0100) Subject: gnulib-tool: Avoid known warnings that reflect Gnulib's coding style. X-Git-Tag: v1.0~2421 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0c8a563f65d44752b33aec42cceec25bd485f2d5;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index a60192b923..f10b0b2aad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2022-01-05 Bruno Haible + + 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 license: fix GPLv3 texts to use a comma instead of semicolon. diff --git a/gnulib-tool b/gnulib-tool index 02d4f8661d..a91847f55a 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -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 diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 87a9a751b6..179aac7aa1 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -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