From 635e16ad8120ad6e99fcc62f2ebde0cce8068c44 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 3 Jun 2023 01:34:14 +0200 Subject: [PATCH] build: Take advantage of gcc warning options not included in -Wall. * autogen.sh (GNULIB_MODULES_RUNTIME_OTHER, GNULIB_MODULES_LIBINTL, GNULIB_MODULES_LIBASPRINTF, GNULIB_MODULES_TOOLS_OTHER): Add manywarnings. * m4/more-warnings.m4: New file. * libtextstyle/autogen.sh (GNULIB_MODULES): Add manywarnings. Copy also more-warnings.m4. * gnulib-local/modules/libxml (Makefile.am): New variable libxml_rpl_la_CFLAGS. * libtextstyle/gnulib-local/modules/libcroco (Makefile.am): New variable libcroco_rpl_la_CFLAGS. * libtextstyle/gnulib-local/modules/libglib (Makefile.am): New variable libglib_rpl_la_CFLAGS. * libtextstyle/configure.ac: Invoke gt_MORE_WARNINGS, gl_CC_INHIBIT_WARNINGS. * libtextstyle/lib/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. (config.h): Do the compilations with GL_CFLAG_INHIBIT_WARNINGS. * gettext-runtime/configure.ac: Invoke gt_MORE_WARNINGS. * gettext-runtime/src/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. * gnulib-local/modules/gettext-runtime-misc (Makefile.am): Add WARN_CFLAGS to AM_CFLAGS. * gettext-runtime/intl/configure.ac: Invoke gt_MORE_WARNINGS. * gettext-runtime/intl/Makefile.am (AM_CFLAGS): Add WARN_CFLAGS. * gnulib-local/modules/gettext-runtime-intl-misc (Makefile.am): Add WARN_CFLAGS to AM_CFLAGS. * gettext-runtime/libasprintf/configure.ac: Invoke gt_MORE_WARNINGS. * gettext-runtime/libasprintf/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. * gettext-tools/configure.ac: Invoke gt_MORE_WARNINGS, gl_CC_INHIBIT_WARNINGS. * gettext-tools/gnulib-lib/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. * gettext-tools/libgrep/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. * gettext-tools/src/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. * gettext-tools/libgettextpo/Makefile.am (AM_CFLAGS): Set to WARN_CFLAGS. (config.h): Do the compilations with GL_CFLAG_INHIBIT_WARNINGS. --- autogen.sh | 4 + gettext-runtime/configure.ac | 4 +- gettext-runtime/intl/Makefile.am | 5 +- gettext-runtime/intl/configure.ac | 2 + gettext-runtime/libasprintf/Makefile.am | 5 +- gettext-runtime/libasprintf/configure.ac | 4 +- gettext-runtime/src/Makefile.am | 3 + gettext-tools/configure.ac | 3 + gettext-tools/gnulib-lib/Makefile.am | 6 +- gettext-tools/libgettextpo/Makefile.am | 5 +- gettext-tools/libgrep/Makefile.am | 5 +- gettext-tools/src/Makefile.am | 4 + .../modules/gettext-runtime-intl-misc | 3 + gnulib-local/modules/gettext-runtime-misc | 3 + gnulib-local/modules/libxml | 4 + libtextstyle/.gitignore | 1 + libtextstyle/autogen.sh | 4 +- libtextstyle/configure.ac | 5 +- libtextstyle/gnulib-local/modules/libcroco | 1 + libtextstyle/gnulib-local/modules/libglib | 1 + libtextstyle/lib/Makefile.am | 9 +- m4/more-warnings.m4 | 190 ++++++++++++++++++ 22 files changed, 258 insertions(+), 13 deletions(-) create mode 100644 m4/more-warnings.m4 diff --git a/autogen.sh b/autogen.sh index 44f9ad59e..462a6b207 100755 --- a/autogen.sh +++ b/autogen.sh @@ -102,6 +102,7 @@ if ! $skip_gnulib; then csharpcomp-script java javacomp-script + manywarnings ' $GNULIB_TOOL --dir=gettext-runtime --lib=libgrt --source-base=gnulib-lib --m4-base=gnulib-m4 --no-libtool --local-dir=gnulib-local --local-symlink \ --import $GNULIB_MODULES_RUNTIME_FOR_SRC $GNULIB_MODULES_RUNTIME_OTHER || exit $? @@ -118,6 +119,7 @@ if ! $skip_gnulib; then localcharset localename lock + manywarnings relocatable-lib-lgpl tsearch vasnprintf-posix @@ -129,6 +131,7 @@ if ! $skip_gnulib; then # In gettext-runtime/libasprintf: GNULIB_MODULES_LIBASPRINTF=' alloca + manywarnings vasnprintf ' $GNULIB_TOOL --dir=gettext-runtime/libasprintf --source-base=gnulib-lib --m4-base=gnulib-m4 --lgpl=2 --libtool --local-dir=gnulib-local --local-symlink \ @@ -289,6 +292,7 @@ if ! $skip_gnulib; then java javacomp-script javaexec-script + manywarnings stdint ' GNULIB_MODULES_TOOLS_LIBUNISTRING_TESTS=' diff --git a/gettext-runtime/configure.ac b/gettext-runtime/configure.ac index 2006d4715..126d0690f 100644 --- a/gettext-runtime/configure.ac +++ b/gettext-runtime/configure.ac @@ -1,5 +1,5 @@ dnl Configuration for the gettext-runtime directory of GNU gettext -dnl Copyright (C) 1995-2010, 2012-2015, 2018-2022 Free Software Foundation, Inc. +dnl Copyright (C) 1995-2010, 2012-2015, 2018-2023 Free Software Foundation, Inc. dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -75,6 +75,8 @@ AM_PROG_CC_C_O dnl Check for build configuration. +gt_MORE_WARNINGS + gl_WOE32_DLL LT_INIT([win32-dll]) diff --git a/gettext-runtime/intl/Makefile.am b/gettext-runtime/intl/Makefile.am index bd1f0077d..f6d8f547b 100644 --- a/gettext-runtime/intl/Makefile.am +++ b/gettext-runtime/intl/Makefile.am @@ -46,13 +46,16 @@ if WOE32 AM_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO=0 endif +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + BISON = @INTLBISON@ BISONFLAGS = --name-prefix=__gettext # Just to shut up Automake "error: Yacc source seen but 'YACC' is undefined". YACC = $(BISON) -d # Tell the ELF linker which symbols to export. -AM_CFLAGS = @CFLAG_VISIBILITY@ +AM_CFLAGS += @CFLAG_VISIBILITY@ # Tell the mingw or Cygwin linker which symbols to export. if WOE32DLL AM_LDFLAGS = -Wl,--export-all-symbols diff --git a/gettext-runtime/intl/configure.ac b/gettext-runtime/intl/configure.ac index 8da339016..3005f63bb 100644 --- a/gettext-runtime/intl/configure.ac +++ b/gettext-runtime/intl/configure.ac @@ -51,6 +51,8 @@ gl_EARLY dnl Check for build configuration. +gt_MORE_WARNINGS + gl_WOE32_DLL LT_INIT([win32-dll]) diff --git a/gettext-runtime/libasprintf/Makefile.am b/gettext-runtime/libasprintf/Makefile.am index 592b6bf44..c0eb4062d 100644 --- a/gettext-runtime/libasprintf/Makefile.am +++ b/gettext-runtime/libasprintf/Makefile.am @@ -1,5 +1,5 @@ ## Makefile for the gettext-runtime/libasprintf subdirectory of GNU gettext -## Copyright (C) 2002-2007, 2009-2011, 2013, 2016, 2018-2019, 2021 Free Software Foundation, Inc. +## Copyright (C) 2002-2007, 2009-2011, 2013, 2016, 2018-2019, 2021, 2023 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU Lesser General Public License as published by @@ -41,6 +41,9 @@ if WOE32 DEFS += -D__USE_MINGW_ANSI_STDIO=0 endif +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # Library include file. diff --git a/gettext-runtime/libasprintf/configure.ac b/gettext-runtime/libasprintf/configure.ac index 0bcd4c311..2fe76cf02 100644 --- a/gettext-runtime/libasprintf/configure.ac +++ b/gettext-runtime/libasprintf/configure.ac @@ -1,5 +1,5 @@ dnl Configuration for the GNU libasprintf library -dnl Copyright (C) 2002-2012, 2016, 2018-2021 Free Software Foundation, Inc. +dnl Copyright (C) 2002-2012, 2016, 2018-2023 Free Software Foundation, Inc. dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -43,6 +43,8 @@ gl_EARLY dnl Check for build configuration. +gt_MORE_WARNINGS + gl_WOE32_DLL LT_INIT([win32-dll]) diff --git a/gettext-runtime/src/Makefile.am b/gettext-runtime/src/Makefile.am index 1fa850745..e9974c4c2 100644 --- a/gettext-runtime/src/Makefile.am +++ b/gettext-runtime/src/Makefile.am @@ -33,6 +33,9 @@ AM_CPPFLAGS = \ -I../gnulib-lib -I$(srcdir)/../gnulib-lib DEFS = -DLOCALEDIR=$(localedir_c_make) @DEFS@ +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # Source dependencies. gettext_SOURCES = gettext.c escapes.h ngettext_SOURCES = ngettext.c escapes.h diff --git a/gettext-tools/configure.ac b/gettext-tools/configure.ac index 4d9bc8e52..18ddcc312 100644 --- a/gettext-tools/configure.ac +++ b/gettext-tools/configure.ac @@ -92,6 +92,9 @@ gtpo_EARLY dnl Check for build configuration. +gt_MORE_WARNINGS +gl_CC_INHIBIT_WARNINGS + gl_WOE32_DLL LT_INIT([win32-dll]) diff --git a/gettext-tools/gnulib-lib/Makefile.am b/gettext-tools/gnulib-lib/Makefile.am index 244c3acfa..e9c517fe9 100644 --- a/gettext-tools/gnulib-lib/Makefile.am +++ b/gettext-tools/gnulib-lib/Makefile.am @@ -1,6 +1,5 @@ ## Makefile for the gettext-tools/gnulib-lib subdirectory of GNU gettext -## Copyright (C) 1995-1998, 2000-2006, 2009, 2016, 2019, 2021 Free Software -## Foundation, Inc. +## Copyright (C) 1995-1998, 2000-2006, 2009, 2016, 2019, 2021, 2023 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -52,6 +51,9 @@ if INCLUDED_LIBXML AM_CPPFLAGS += -DLIBXML_STATIC endif +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # Rules generated and collected by gnulib-tool. include Makefile.gnulib diff --git a/gettext-tools/libgettextpo/Makefile.am b/gettext-tools/libgettextpo/Makefile.am index ee9ed39c4..798ae98f3 100644 --- a/gettext-tools/libgettextpo/Makefile.am +++ b/gettext-tools/libgettextpo/Makefile.am @@ -42,6 +42,9 @@ AM_CPPFLAGS = \ DEFS = -DIN_LIBGETTEXTPO=1 -DOMIT_SETLOCALE_LOCK=1 @DEFS@ +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # libgettextpo contains the public API for PO files. libgettextpo_la_SOURCES = \ gettext-po.c \ @@ -177,7 +180,7 @@ config.h: $(BUILT_SOURCES) sf=`echo "$$f" | sed -e 's,\\.[^.]*$$,,'`.c; \ test -f $$sf || sf=$(srcdir)/$$sf; \ of=`echo "$$f" | sed -e 's,^.*/,,' -e 's,\\.[^.]*$$,,'`.$(OBJEXT); \ - $(COMPILE) $(DEFS) -c $$sf || { rm -f config.h; exit 1; }; \ + $(COMPILE) $(DEFS) $(GL_CFLAG_INHIBIT_WARNINGS) -c $$sf || { rm -f config.h; exit 1; }; \ sh ./exported.sh $$of 1>&5; \ rm -f $$of `echo "$$of" | sed -e 's,\\.$(OBJEXT)$$,.lo,'`; \ ;; \ diff --git a/gettext-tools/libgrep/Makefile.am b/gettext-tools/libgrep/Makefile.am index 37393a2a3..ea5e4f5d0 100644 --- a/gettext-tools/libgrep/Makefile.am +++ b/gettext-tools/libgrep/Makefile.am @@ -1,5 +1,5 @@ ## Makefile for libgrep directory in GNU gettext package. -## Copyright (C) 2005-2007, 2009-2010, 2014, 2021 Free Software Foundation, Inc. +## Copyright (C) 2005-2007, 2009-2010, 2014, 2021, 2023 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -29,6 +29,9 @@ noinst_LIBRARIES = AM_CPPFLAGS = -I.. -I../gnulib-lib -I$(top_srcdir)/gnulib-lib -I../../gettext-runtime/intl +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # Rules generated and collected by gnulib-tool, for building libgrep.a. include Makefile.gnulib diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index ad495ec96..fc3ae2623 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -105,6 +105,10 @@ DEFS = \ -DGETTEXTDATADIR=\"$(pkgdatadir)\" \ -DPROJECTSDIR=\"$(projectsdir)\" \ -DEXEEXT=\"@EXEEXT@\" @DEFS@ + +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # Ensure that defines SIZE_MAX in C++ mode, like it does in C mode. AM_CXXFLAGS = -D__STDC_LIMIT_MACROS diff --git a/gnulib-local/modules/gettext-runtime-intl-misc b/gnulib-local/modules/gettext-runtime-intl-misc index 671b5f6e9..59738717a 100644 --- a/gnulib-local/modules/gettext-runtime-intl-misc +++ b/gnulib-local/modules/gettext-runtime-intl-misc @@ -17,6 +17,9 @@ AM_CPPFLAGS += \ -Dset_relocation_prefix=libintl_set_relocation_prefix \ -DDEPENDS_ON_LIBICONV=1 +# Enable more warning options in this directory. +AM_CFLAGS += @WARN_CFLAGS@ + # Support building libintl.a with -fPIC (needed by GCC). AM_CFLAGS += @PICFLAG@ diff --git a/gnulib-local/modules/gettext-runtime-misc b/gnulib-local/modules/gettext-runtime-misc index 4cad86d65..470b7250c 100644 --- a/gnulib-local/modules/gettext-runtime-misc +++ b/gnulib-local/modules/gettext-runtime-misc @@ -15,6 +15,9 @@ AM_CPPFLAGS += -I$(top_builddir)/intl -I$(top_srcdir)/intl # Parametrization of the 'relocatable' module. AM_CPPFLAGS += -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1 +# Enable more warning options in this directory. +AM_CFLAGS += @WARN_CFLAGS@ + Include: License: diff --git a/gnulib-local/modules/libxml b/gnulib-local/modules/libxml index 948809574..a722b3096 100644 --- a/gnulib-local/modules/libxml +++ b/gnulib-local/modules/libxml @@ -178,6 +178,10 @@ libxml_rpl_la_SOURCES = \ libxml/xpath.c \ libxml/xpointer.c libxml_rpl_la_CPPFLAGS = $(AM_CPPFLAGS) $(NO_CXX) +# We need NO_EXPENSIVE_WARN_CFLAGS, because with gcc 13, the compilation of +# libxml/parser.c requires 1.9 GB of RAM with -fanalyzer, as opposed to +# 0.09 GB of RAM with -fno-analyzer. +libxml_rpl_la_CFLAGS = @FOREIGN_WARN_CFLAGS@ @NO_EXPENSIVE_WARN_CFLAGS@ BUILT_SOURCES += $(LIBXML_H) diff --git a/libtextstyle/.gitignore b/libtextstyle/.gitignore index 1a84e7153..dad3bb540 100644 --- a/libtextstyle/.gitignore +++ b/libtextstyle/.gitignore @@ -284,6 +284,7 @@ /m4/ltsugar.m4 /m4/ltversion.m4 /m4/lt~obsolete.m4 +/m4/more-warnings.m4 /m4/woe32-dll.m4 # Dummy ChangeLogs: /ChangeLog diff --git a/libtextstyle/autogen.sh b/libtextstyle/autogen.sh index 291da4a62..f271fa5c5 100755 --- a/libtextstyle/autogen.sh +++ b/libtextstyle/autogen.sh @@ -6,7 +6,7 @@ # # This script requires autoconf-2.64..2.71 and automake-1.11..1.16 in the PATH. -# Copyright (C) 2003-2022 Free Software Foundation, Inc. +# Copyright (C) 2003-2023 Free Software Foundation, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -78,6 +78,7 @@ if test $skip_gnulib = false; then filename isatty largefile + manywarnings vasprintf-posix xalloc xconcat-filename @@ -108,6 +109,7 @@ cp -p ../INSTALL.windows . mkdir -p m4 cp -p ../m4/libtool.m4 m4/ cp -p ../m4/lt*.m4 m4/ +cp -p ../m4/more-warnings.m4 m4/ cp -p ../m4/woe32-dll.m4 m4/ cp -p ../build-aux/ltmain.sh build-aux/ cp -p ../build-aux/texi2html build-aux/ diff --git a/libtextstyle/configure.ac b/libtextstyle/configure.ac index e79417d6a..55b9ef8f7 100644 --- a/libtextstyle/configure.ac +++ b/libtextstyle/configure.ac @@ -1,5 +1,5 @@ dnl Configuration for the toplevel directory of GNU libtextstyle -dnl Copyright (C) 2009-2021 Free Software Foundation, Inc. +dnl Copyright (C) 2009-2023 Free Software Foundation, Inc. dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -50,6 +50,9 @@ AC_EXEEXT dnl Check for build configuration. +gt_MORE_WARNINGS +gl_CC_INHIBIT_WARNINGS + gl_WOE32_DLL LT_INIT([win32-dll]) diff --git a/libtextstyle/gnulib-local/modules/libcroco b/libtextstyle/gnulib-local/modules/libcroco index 712a7a9ac..a4b4c785b 100644 --- a/libtextstyle/gnulib-local/modules/libcroco +++ b/libtextstyle/gnulib-local/modules/libcroco @@ -117,6 +117,7 @@ libcroco_rpl_la_SOURCES = \ libcroco/cr-token.c \ libcroco/cr-utils.c libcroco_rpl_la_CPPFLAGS = $(AM_CPPFLAGS) $(NO_CXX) +libcroco_rpl_la_CFLAGS = @FOREIGN_WARN_CFLAGS@ if GL_COND_LIBTOOL lib_LDFLAGS += $(LTLIBCROCO) diff --git a/libtextstyle/gnulib-local/modules/libglib b/libtextstyle/gnulib-local/modules/libglib index 776234e0c..1e80de574 100644 --- a/libtextstyle/gnulib-local/modules/libglib +++ b/libtextstyle/gnulib-local/modules/libglib @@ -54,6 +54,7 @@ libglib_rpl_la_SOURCES = \ glib/gstrfuncs.c \ glib/gstring.c libglib_rpl_la_CPPFLAGS = $(AM_CPPFLAGS) $(NO_CXX) +libglib_rpl_la_CFLAGS = @FOREIGN_WARN_CFLAGS@ BUILT_SOURCES += $(LIBGLIB_H) diff --git a/libtextstyle/lib/Makefile.am b/libtextstyle/lib/Makefile.am index 6bf636dc8..411a2e401 100644 --- a/libtextstyle/lib/Makefile.am +++ b/libtextstyle/lib/Makefile.am @@ -1,5 +1,5 @@ ## Makefile for the lib subdirectory of GNU libtextstyle. -## Copyright (C) 2009-2022 Free Software Foundation, Inc. +## Copyright (C) 2009-2023 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -56,6 +56,9 @@ if WOE32 AM_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO=0 endif +# Enable more warning options in this directory. +AM_CFLAGS = @WARN_CFLAGS@ + # Rules generated and collected by gnulib-tool. include Makefile.gnulib @@ -227,8 +230,8 @@ config.h: $(BUILT_SOURCES) libtextstyle.sym sf=`echo "$$f" | sed -e 's,\\.[^.]*$$,,'`.c; \ test -f $$sf || sf=$(srcdir)/$$sf; \ of=`echo "$$f" | sed -e 's,^.*/,,' -e 's,\\.[^.]*$$,,'`.$(OBJEXT); \ - echo "$(COMPILE) -c $$sf" 1>&6; \ - $(COMPILE) -c $$sf || { rm -f config.h; exit 1; }; \ + echo "$(COMPILE) $(GL_CFLAG_INHIBIT_WARNINGS) -c $$sf" 1>&6; \ + $(COMPILE) $(GL_CFLAG_INHIBIT_WARNINGS) -c $$sf || { rm -f config.h; exit 1; }; \ sh ./exported.sh $$of 1>&5; \ rm -f $$of `echo "$$of" | sed -e 's,\\.$(OBJEXT)$$,.lo,'`; \ ;; \ diff --git a/m4/more-warnings.m4 b/m4/more-warnings.m4 new file mode 100644 index 000000000..42c168b10 --- /dev/null +++ b/m4/more-warnings.m4 @@ -0,0 +1,190 @@ +# more-warnings.m4 serial 1 (gettext-0.21.2) +dnl Copyright (C) 2023 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +dnl Use more compiler warnings, beyond '-Wall' (for gcc and clang). +AC_DEFUN([gt_MORE_WARNINGS], +[ + AC_ARG_ENABLE([more-warnings], +AS_HELP_STRING([[--enable-more-warnings]], [enable additional compiler warnings beyond -Wall]) +AS_HELP_STRING([[--disable-more-warnings]], [obey exactly the warning options specified in $CPPFLAGS $CFLAGS]), + [more_warnings=$enableval], + [dnl When to enable the warnings by default? + dnl Some other packages enable the warnings by default in a git checkout + dnl when there is no .tarball version file. This is too unreliable, since + dnl - Often the .tarball-version file is still present after the maintainer + dnl made a release or prerelease. + dnl - It is useful to see the warnings also when doing portability testing, + dnl that is, when building a tarball created by "make distcheck". + dnl Hence, use a different heuristic: Enable the warnings by default if + dnl the option -Wall is already specified. + case " $CC $CPPFLAGS $CFLAGS " in + *" -Wall "*) more_warnings=yes ;; + *) more_warnings=no ;; + esac + ]) + + dnl Warning options for production code, not including tests. + WARN_CFLAGS= + dnl Warning options for production code imported from other packages + dnl (libglib, libxml, libcroco). + FOREIGN_WARN_CFLAGS= + dnl Warning options that turn off expensive processing in the compiler. + NO_EXPENSIVE_WARN_CFLAGS= + if test "x$more_warnings" = xyes; then + dnl Add warning options. But do *not* add options that change the + dnl generated code. (That's because this code here is also in effect + dnl for distro builds.) + + dnl Set up the list of the pointless, undesired warnings. + nw= + dnl First, the warnings that are generated already with -O0: + dnl These warnings enforce a certain programming style that is not ours. + nw="$nw -Wempty-body" + nw="$nw -Wvla" + dnl All warnings produced by these options (in gcc 13) have been false + dnl alarms. + nw="$nw -Wanalyzer-double-fclose" + nw="$nw -Wanalyzer-double-free" + nw="$nw -Wanalyzer-fd-double-close" + nw="$nw -Wanalyzer-null-argument" + nw="$nw -Wanalyzer-null-dereference" + nw="$nw -Wanalyzer-use-of-uninitialized-value" + dnl This warning option is nonsense. It's normal to have to cast, for + dnl example, a 'double' to an 'int'. When that 'double' value is the + dnl result of a function call, this does not make the cast dangerous + dnl in any way. + nw="$nw -Wbad-function-cast" + dnl When we allocate memory for several objects through a single malloc() + dnl call, it's normal that we then have to cast a 'char *' to various + dnl pointer types with varying alignment. + nw="$nw -Wcast-align" + dnl We use computed format strings in a number of places, and glibc's + dnl does it as well. + nw="$nw -Wformat-nonliteral" + dnl We define a few functions for binary backward compatibility only. + dnl These functions are not declared on purpose: So that they cannot be + dnl accidentally used in new code. + nw="$nw -Wmissing-declarations" + nw="$nw -Wmissing-prototypes" + dnl We frequently have a static variable and a local variable in a function + dnl with the same name. This is normal, because the same concept often + dnl occurs in multiple locations in a file. Thus, ignore + dnl "... shadows a global declaration" warnings. Only + dnl "... shadows a parameter" and "... shadows a previous local" warnings + dnl are worth eliminating; see below. + nw="$nw -Wshadow" + dnl Too many warnings. We often use signed types like 'int' or 'idx_t' + dnl for counter variables, yet SIZEOF(array) is an unsigned value. + nw="$nw -Wsign-compare" + dnl This warning is based on older ISO C standards. It warns, in particular, + dnl about function definitions that are valid in ISO C 23 (static and + dnl non-static functions). Cf. + dnl https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00055.html + dnl https://lore.kernel.org/distributions/2354211.7hzS34FegO@nimes/ + nw="$nw -Wold-style-definition" + dnl This warning is based on older ISO C standards. It warns, in particular, + dnl about function definitions that are valid in ISO C 23 (static functions + dnl only). Cf. + dnl https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00055.html + dnl https://lore.kernel.org/distributions/2354211.7hzS34FegO@nimes/ + dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108690 + nw="$nw -Wstrict-prototypes" + dnl There is no reason to warn about an abstract (unimplemented) method in + dnl an abstract class; it has no chance of ever being called. Only the + dnl implementations of the method on concrete subclasses can be called. + nw="$nw -Wsuggest-attribute=noreturn" + dnl There is no reason to warn about code that does not want to make + dnl assumptions about whether a certain type is signed or unsigned. + nw="$nw -Wtype-limits" + dnl Too many warnings. #if preprocessor directives often lead to unused + dnl macros. + nw="$nw -Wunused-macros" + dnl Unused parameters are frequent in functions that are meant to implement + dnl a given function type. + nw="$nw -Wunused-parameter" + dnl + dnl Next, the warnings that are generated with -O2: + dnl This warning option frequently produces false alarms. + dnl See . + nw="$nw -Wclobbered" + dnl I'm not interested in the details of which functions get inlined and + dnl which don't. + nw="$nw -Winline" + dnl Some of these warnings point to functions for which the result's + dnl destruction should be done through fclose(), _free(), etc., + dnl not free(). + nw="$nw -Wsuggest-attribute=malloc" + dnl Too many warnings. It's ridiculous that the developer should spend + dnl brain cycles on things that the compiler could often infer and which + dnl have little effect on the performance of the generated code. + dnl Cf. . + nw="$nw -Wsuggest-attribute=pure" + dnl Too many warnings. It's ridiculous that the developer should spend + dnl brain cycles on things that the compiler could often infer and which + dnl have little effect on the performance of the generated code. + dnl Cf. . + nw="$nw -Wsuggest-attribute=const" + dnl It's ridiculous that the developer should spend brain cycles on things + dnl that the compiler could often infer and which have little effect on the + dnl performance of the generated code. + nw="$nw -Wsuggest-attribute=cold" + + dnl Setup the list of meaningful warning options for the C compiler. + dnl The list comes from manywarnings.m4. Warning options that are not + dnl generally meaningful have already been filtered out (cf. + dnl build-aux/gcc-warning.spec). + gl_MANYWARN_ALL_GCC([possible_warning_options]) + + dnl Compute the list of warning options that are desired. + gl_MANYWARN_COMPLEMENT([desired_warning_options], + [$possible_warning_options], [$nw]) + dnl Compute the list of remaining undesired warning options. + dnl Namely those, that were not in manywarnings.m4 because they were + dnl already listed in build-aux/gcc-warning.spec; this includes those + dnl that are implied by -Wall. + gl_MANYWARN_COMPLEMENT([remaining_undesired_warning_options], + [$nw], [$possible_warning_options]) + + dnl Add the desired warning options to WARN_CFLAGS. + for w in $desired_warning_options; do + gl_WARN_ADD([$w]) + done + + dnl Add the opposites of the remaining undesired warning options to + dnl WARN_CFLAGS. + for w in `echo "$remaining_undesired_warning_options" | sed -e 's/-W/-Wno-/g'`; do + gl_WARN_ADD([$w]) + done + + dnl Cf. -Wshadow, above. + gl_WARN_ADD([-Wshadow=local]) + + dnl For production code imported from other packages, disable some other + dnl warnings. For imported code, I want to minimize difference w.r.t. + dnl upstream. + FOREIGN_WARN_CFLAGS="$WARN_CFLAGS" + fnw= + fnw="$fnw -Wcast-function-type" + fnw="$fnw -Wduplicated-cond" + fnw="$fnw -Wformat" + fnw="$fnw -Wimplicit-fallthrough" + fnw="$fnw -Wnull-dereference" + fnw="$fnw -Wsuggest-attribute=format" + for w in `echo "$fnw" | sed -e 's/-W/-Wno-/g'`; do + gl_WARN_ADD([$w], [FOREIGN_WARN_CFLAGS]) + done + + dnl Warning options that turn off expensive processing in the compiler. + gl_WARN_ADD([-fno-analyzer], [NO_EXPENSIVE_WARN_CFLAGS]) + fi + AC_SUBST([WARN_CFLAGS]) + AC_SUBST([FOREIGN_WARN_CFLAGS]) + AC_SUBST([NO_EXPENSIVE_WARN_CFLAGS]) +]) -- 2.47.2