]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS.
authorBruno Haible <bruno@clisp.org>
Wed, 3 Sep 2025 22:15:19 +0000 (00:15 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 3 Sep 2025 22:24:48 +0000 (00:24 +0200)
Reported by Pádraig Brady in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-09/>.

* gnulib-tool.sh (func_emit_tests_Makefile_am): Append the
warning-protection options to AM_CFLAGS and AM_CXXFLAGS, in addition to
initializing CFLAGS and CXXFLAGS.
* pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
* doc/gnulib-tool.texi (Modified build rules): Document the need to
initialize AM_CFLAGS and AM_CXXFLAGS in tests directories.
* NEWS: Mention the new requirement.

ChangeLog
NEWS
doc/gnulib-tool.texi
gnulib-tool.sh
pygnulib/GLEmiter.py

index 7d7c44aea52127dae3a5b33febd7c1bc628e997a..956c4ab407ffce41300c9b406b79d6e04fbcb15d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-09-03  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS.
+       Reported by Pádraig Brady in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2025-09/msg00018.html>.
+       * gnulib-tool.sh (func_emit_tests_Makefile_am): Append the
+       warning-protection options to AM_CFLAGS and AM_CXXFLAGS, in addition to
+       initializing CFLAGS and CXXFLAGS.
+       * pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
+       * doc/gnulib-tool.texi (Modified build rules): Document the need to
+       initialize AM_CFLAGS and AM_CXXFLAGS in tests directories.
+       * NEWS: Mention the new requirement.
+
 2025-09-03  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool: Improve C++ awareness of 2021-06-10 / 2024-03-06 commit.
diff --git a/NEWS b/NEWS
index 664007395de556f5ddcb742d89311383d72bdea9..de89ddb78c6b6e9ef303c5ae736d8819c19fcec2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@ Important general notes
 
 Date        Modules         Changes
 
+2025-09-03  gnulib-tool     If you use --makefile-name with --with-tests, you
+                            now need to initialize AM_CFLAGS before the
+                            'include <gnulib-generated-makefile>' statement.
+
 2022-07-24  bootstrap       To specify a reference directory for the 'gnulib'
                             submodule, use the environment variable
                             GNULIB_REFDIR instead of GNULIB_SRCDIR or the
index 2ee6fd83de59ffae77c907ffbd5dd98fcb789746..e9ee83703c0b57a6d47d028728a34d2293ee9bf7 100644 (file)
@@ -747,8 +747,11 @@ through a line such as
 @smallexample
 include Makefile.gnulib
 @end smallexample
-Before this include, you need to initialize this set of @code{Makefile.am}
-variables:
+Before this include, you need to initialize a set of @code{Makefile.am}
+variables.
+
+For the directory into which @code{gnulib-tool} copies the gnulib source files,
+the set of variables to initialize is:
 @itemize @bullet
 @item
 @code{AUTOMAKE_OPTIONS}
@@ -789,6 +792,17 @@ The other variables can be initialized to empty.  However, you will most
 likely want to initialize some of them with non-empty values, in order
 to achieve the desired customization.
 
+For the directory into which @code{gnulib-tool} copies
+the gnulib unit test files
+(when option @samp{--with-tests} is used),
+the set of variables to initialize is:
+@itemize @bullet
+@item
+@code{AM_CFLAGS}
+@item
+@code{AM_CXXFLAGS} (when this directory contains some C++ code)
+@end itemize
+
 The other approach, the kitchen-sink module, is more advanced.  See
 chapter @ref{Extending Gnulib}.
 
index e3a9b92de6c6a004c8043afbc041748c88de30ad..2e9e70036c833aed1a62961f91b18793c9e113e0 100755 (executable)
@@ -4459,6 +4459,17 @@ func_emit_tests_Makefile_am ()
     # Enable or disable warnings as suitable for the Gnulib coding style.
     cflags_for_gnulib_code=" \$(GL_CFLAG_GNULIB_WARNINGS)"
   fi
+  # The primary place to add these options is AM_CFLAGS.
+  echo "AM_CFLAGS += @GL_CFLAG_ALLOW_WARNINGS@${cflags_for_gnulib_code}"
+  if test -n "$uses_cxx"; then
+    echo "AM_CXXFLAGS += @GL_CXXFLAG_ALLOW_WARNINGS@"
+  fi
+  echo
+  # The secondary place to add these options is CFLAGS. This is less reliable,
+  # because the user can invoke e.g. "make CFLAGS=-O2"; see
+  # <https://www.gnu.org/software/automake/manual/html_node/User-Variables.html>
+  # But it is a protection against packages which do  AM_CFLAGS += -Werror
+  # after including this generated Makefile (such as GNU grep).
   echo "CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@${cflags_for_gnulib_code} @CFLAGS@"
   if test -n "$uses_cxx"; then
     echo "CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@"
index 9d02210518bcee10ed07aedb1239cc56ff6df384..4abbacb71031ff019c6900293cc72812b426b00e 100644 (file)
@@ -1242,6 +1242,16 @@ AC_DEFUN([%V1%_LIBSOURCES], [
         if not for_test:
             # Enable or disable warnings as suitable for the Gnulib coding style.
             cflags_for_gnulib_code = ' $(GL_CFLAG_GNULIB_WARNINGS)'
+        # The primary place to add these options is AM_CFLAGS.
+        emit += 'AM_CFLAGS += @GL_CFLAG_ALLOW_WARNINGS@%s\n' % (cflags_for_gnulib_code)
+        if uses_cxx:
+            emit += 'AM_CXXFLAGS += @GL_CXXFLAG_ALLOW_WARNINGS@\n'
+        emit += '\n'
+        # The secondary place to add these options is CFLAGS. This is less reliable,
+        # because the user can invoke e.g. "make CFLAGS=-O2"; see
+        # <https://www.gnu.org/software/automake/manual/html_node/User-Variables.html>
+        # But it is a protection against packages which do  AM_CFLAGS += -Werror
+        # after including this generated Makefile (such as GNU grep).
         emit += 'CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@%s @CFLAGS@\n' % (cflags_for_gnulib_code)
         if uses_cxx:
             emit += 'CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@\n'