Hi Bruno,

Bruno Haible via Gnulib discussion list <[email protected]> writes:

> Yesterday I wrote:
>> gnulib-tool with option --makefile-name will be changed to append the
>> '-Wno-error' and related options also to AM_CFLAGS.
>
> Done through the attached two patches. (The lists.gnu.org reference needs to
> be updated a posteriori.)
>
>> This will break coreutils and some other packages, which don't initialize
>> the necessary variables, mentioned in [2].
>
> In fact, only those packages are affected that use --makefile-name and
> --with-tests together. These are:
>   - libunistring
>   - gettext
>   - coreutils
>   - diffutils
>   - idutils
>   - sed
>   - m4
>   - grep
>
> I'll follow up with each of them.

Thanks.

It also breaks --create-testdir though:

    $ gnulib-tool --create-testdir --dir testdir1 crypto/sha3
    [...]
    gllib/Makefile.am: installing 'build-aux/depcomp'
    gltests/Makefile.am:46: error: AM_CFLAGS must be set with '=' before using 
'+='

I pushed the attatched patch to fix both gnulib-tool.sh and
gnulib-tool.py. We can just initialize them to an empty value if we
'for_tests' is true.

Collin

>From 7e676bbade56be51db3ad65c5ca1c5f3f6aa2c8c Mon Sep 17 00:00:00 2001
Message-ID: <7e676bbade56be51db3ad65c5ca1c5f3f6aa2c8c.1756956052.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Wed, 3 Sep 2025 20:18:04 -0700
Subject: [PATCH] gnulib-tool: Avoid Automake error when using --create-testdir
 (regr. today).

* gnulib-tool.sh (func_emit_tests_Makefile_am): Initialize AM_CFLAGS and
AM_CXXFLAGS when creating a test directory.
* pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
---
 ChangeLog            | 7 +++++++
 gnulib-tool.sh       | 8 ++++++++
 pygnulib/GLEmiter.py | 7 +++++++
 3 files changed, 22 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 956c4ab407..a016eec8f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-09-03  Collin Funk  <[email protected]>
+
+	gnulib-tool: Avoid Automake error when using --create-testdir (regr. today).
+	* gnulib-tool.sh (func_emit_tests_Makefile_am): Initialize AM_CFLAGS and
+	AM_CXXFLAGS when creating a test directory.
+	* pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
+
 2025-09-03  Bruno Haible  <[email protected]>
 
 	gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS.
diff --git a/gnulib-tool.sh b/gnulib-tool.sh
index 2e9e70036c..566525742a 100755
--- a/gnulib-tool.sh
+++ b/gnulib-tool.sh
@@ -4458,6 +4458,14 @@ func_emit_tests_Makefile_am ()
   if ! $for_test; then
     # Enable or disable warnings as suitable for the Gnulib coding style.
     cflags_for_gnulib_code=" \$(GL_CFLAG_GNULIB_WARNINGS)"
+  else
+    # Make sure AM_CFLAGS is set or Automake will error when we append to it
+    # using '+='.
+    echo 'AM_CFLAGS ='
+    # Likewise for AM_CXXFLAGS.
+    if test -n "$uses_cxx"; then
+      echo 'AM_CXXFLAGS ='
+    fi
   fi
   # The primary place to add these options is AM_CFLAGS.
   echo "AM_CFLAGS += @GL_CFLAG_ALLOW_WARNINGS@${cflags_for_gnulib_code}"
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 4abbacb710..c055786a03 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -1242,6 +1242,13 @@ def tests_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable:
         if not for_test:
             # Enable or disable warnings as suitable for the Gnulib coding style.
             cflags_for_gnulib_code = ' $(GL_CFLAG_GNULIB_WARNINGS)'
+        else:
+            # Make sure AM_CFLAGS is set or Automake will error when we append to it
+            # using '+='.
+            emit += 'AM_CFLAGS =\n'
+            # Likewise for AM_CXXFLAGS.
+            if uses_cxx:
+                emit += 'AM_CXXFLAGS =\n'
         # 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:
-- 
2.51.0

Reply via email to