From: Reuben Thomas <rrt@sc3d.org>
Date: Sat, 13 Jan 2018 22:41:57 +0000 (+0000)
Subject: Use gnulib's manywarnings module
X-Git-Tag: v3.7~142
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27d8b57863161eb0772cc1c88b148dc916fcf8e9;p=recode

Use gnulib's manywarnings module
---

diff --git a/bootstrap.conf b/bootstrap.conf
index a67fc32..86f4ed5 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -1,4 +1,4 @@
-# bootstrap.conf (Recode) version 2017-12-09
+# bootstrap.conf (Recode) version 2018-01-13
 
 # This file is part of Recode.
 #
@@ -50,6 +50,7 @@ gnulib_modules='
         gettext-h
         hash
         localcharset
+        manywarnings
         pathmax
         pipe-posix
         quotearg
diff --git a/configure.ac b/configure.ac
index abc053f..29665db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,51 @@ AC_SUBST([objdir])
 LT_SYS_MODULE_EXT
 AC_SUBST([shlibext], [$libltdl_cv_shlibext])
 
+dnl Extra warnings with GCC and compatible compilers
+AC_ARG_ENABLE([gcc-warnings],
+  [AS_HELP_STRING([--disable-gcc-warnings],
+                  [turn off lots of GCC warnings])],
+  [case $enableval in
+     yes|no) ;;
+     *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
+   esac
+   gl_gcc_warnings=$enableval],
+  [gl_gcc_warnings=yes]
+)
+if test "$gl_gcc_warnings" = yes; then
+  dnl Set up the list of undesired warnings.
+  nw=
+  nw="$nw -Wsystem-headers"   # Don’t let system headers trigger warnings
+  nw="$nw -Wundef"            # All compiler preprocessors support #if UNDEF
+  nw="$nw -Wtraditional"      # All compilers nowadays support ANSI C
+  nw="$nw -Wdeclaration-after-statement" # We require C99.
+  nw="$nw -Wstrict-overflow"  # Use a lower level (see below).
+  nw="$nw -Wconversion"       # These warnings usually don’t point to mistakes.
+  nw="$nw -Wsign-conversion"  # Likewise.
+
+  gl_MANYWARN_ALL_GCC([warnings])
+
+  dnl Enable all GCC warnings not in this list.
+  gl_MANYWARN_COMPLEMENT([warnings], [$warnings], [$nw])
+  for w in $warnings; do
+    gl_WARN_ADD([$w])
+  done
+
+  dnl Add an extra warning
+  gl_WARN_ADD([-Wstrict-overflow=1])
+  dnl Add some more safety measures
+  gl_WARN_ADD([-D_FORTIFY_SOURCE=2])
+  dnl Remove a warning being promoted to error: we trigger this and can't turn it off with pragmas.
+  gl_WARN_ADD([-Wno-error=format-security])
+
+  # When compiling with GCC, prefer -isystem to -I when including system
+  # include files, to avoid generating useless diagnostics for the files.
+  ISYSTEM='-isystem '
+else
+  ISYSTEM='-I'
+fi
+AC_SUBST([ISYSTEM])
+
 AC_CONFIG_HEADERS([config.h])
 AC_HEADER_STDC
 AM_ICONV
diff --git a/src/Makefile.am b/src/Makefile.am
index fec887c..f563edb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,7 +68,7 @@ MNEMONICS_DS = $(KELD)/iso10646.def $(KELD)/other.def $(KELD)/control.def
 RFC1345_TXT = $(KELD)/rfc1345.txt
 NOMS_CARACS = $(ALAIN)/NomsSeulsfinal.lst
 
-AM_CPPFLAGS = -I.. -I$(srcdir) -I$(top_srcdir)/lib
+AM_CPPFLAGS = -I.. -I$(srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib $(WARN_CFLAGS)
 DEFS = -DLIBDIR=\"$(libdir)\" @DEFS@
 
 ETAGS_ARGS = $(L_STEPS)