I've attached a pretty simple patch that fixes an item in
gnulib-tool.py.TODO. It fixes a lot of the remaining lines in the diff
between gnulib-tool and gnulib-tool.py which is nice.

Specifically, it fixes the CFLAGS value used for building the Gnulib
source files. Then it adds some extra rules to the Makefile.ams and
some lines in the configure script to clean up *.Po files.

I decided to change GLEmiter.initmacro_end to use f-strings. It seems
more readable to me than using %V1%, %V2%, etc. and then replacing
those strings.

For testing I just used a script like this:

gnulib-tool.py --create-testdir --dir test-python readme-release
gnulib-tool --create-testdir --dir test-shell readme-release
(cd test-python && gnulib-tool.py --import --with-tests --libtool fts)
(cd test-shell && gnulib-tool --import --with-tests --libtool fts)
git diff --no-index test-python test-shell

and checked with and without --libtool since that affects the output
of a change in GLEmiter.initmacro_end.

Collin
From 5afda4bcd2671f6c62fb5d067c58d398123830f0 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 11 Mar 2024 18:50:28 -0700
Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 55.

Follow gnulib-tool changes
2022-01-05  Bruno Haible  <br...@clisp.org>
gnulib-tool: Avoid known warnings that reflect Gnulib's coding style.
2022-01-08  Bruno Haible  <br...@clisp.org>

gnulib-tool: Remove all *.Po files upon distclean (regr. 2022-01-05).
* pygnulib/GLEmiter.py (GLEmiter.initmacro_end): Collect the *.Po or
*.Plo files to remove into an AC_SUBSTed variable gl_LIBOBJDEPS. Use
Python f-strings instead of string replacements.
(GLEmiter.lib_Makefile_am): Add the GL_CFLAG_GNULIB_WARNINGS to the
CFLAGS of all the compilation units of the library. Extend the distclean
and maintainer-clean rules.
(GLEmiter.tests_Makefile_am): Add the GL_CFLAG_GNULIB_WARNINGS to the
CFLAGS.
* pygnulib/GLImport.py (GLImport.gnulib_comp): Emit an invocation of
gl_CC_GNULIB_WARNINGS.
---
 ChangeLog            | 19 +++++++++++++
 gnulib-tool.py.TODO  | 30 --------------------
 pygnulib/GLEmiter.py | 66 +++++++++++++++++++++++++++++++-------------
 pygnulib/GLImport.py |  1 +
 4 files changed, 67 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 83979be9f4..2a9e9d70a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-03-11  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Follow gnulib-tool changes, part 55.
+	Follow gnulib-tool changes
+	2022-01-05  Bruno Haible  <br...@clisp.org>
+	gnulib-tool: Avoid known warnings that reflect Gnulib's coding style.
+	2022-01-08  Bruno Haible  <br...@clisp.org>
+	gnulib-tool: Remove all *.Po files upon distclean (regr. 2022-01-05).
+	* pygnulib/GLEmiter.py (GLEmiter.initmacro_end): Collect the *.Po or
+	*.Plo files to remove into an AC_SUBSTed variable gl_LIBOBJDEPS. Use
+	Python f-strings instead of string replacements.
+	(GLEmiter.lib_Makefile_am): Add the GL_CFLAG_GNULIB_WARNINGS to the
+	CFLAGS of all the compilation units of the library. Extend the distclean
+	and maintainer-clean rules.
+	(GLEmiter.tests_Makefile_am): Add the GL_CFLAG_GNULIB_WARNINGS to the
+	CFLAGS.
+	* pygnulib/GLImport.py (GLImport.gnulib_comp): Emit an invocation of
+	gl_CC_GNULIB_WARNINGS.
+
 2024-03-11  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 54.
diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO
index 69d3cf7d72..47e3fe56dc 100644
--- a/gnulib-tool.py.TODO
+++ b/gnulib-tool.py.TODO
@@ -98,36 +98,6 @@ Date:   Sun Jan 9 15:38:51 2022 +0100
 
 --------------------------------------------------------------------------------
 
-commit 9abc30c383303fab68aa5ed2841113876bfa90d1
-Author: Bruno Haible <br...@clisp.org>
-Date:   Sat Jan 8 22:10:54 2022 +0100
-
-    gnulib-tool: Remove all *.Po files upon distclean (regr. 2022-01-05).
-
-    Reported by Mohammad Akhlaghi <moham...@akhlaghi.org> in
-    <https://lists.gnu.org/archive/html/bug-gnulib/2022-01/msg00061.html>.
-
-    * gnulib-tool (func_emit_initmacro_end): Collect the *.Po or *.Plo files
-    to remove into an AC_SUBSTed variable gl_LIBOBJDEPS.
-    (func_emit_lib_Makefile_am): Extend the distclean and maintainer-clean
-    rules.
-
-commit 0c8a563f65d44752b33aec42cceec25bd485f2d5
-Author: Bruno Haible <br...@clisp.org>
-Date:   Wed Jan 5 18:21:55 2022 +0100
-
-    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.
-
---------------------------------------------------------------------------------
-
 commit 87e6634b28df65084321fed22f60d114a0931d21
 Author: Bernhard Voelker <m...@bernhard-voelker.de>
 Date:   Tue Jan 4 00:16:50 2022 +0100
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index bfb7d51c01..c403df6141 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -606,6 +606,7 @@ USE_MSGCTXT = no\n"""
                             % type(gentests).__name__)
         sourcebase = self.config['sourcebase']
         automake_subdir = self.config['automake_subdir']
+        libtool = self.config['libtool']
         emit = ''
         # Check the presence of files that are mentioned as AC_LIBSOURCES
         # arguments. The check is performed only when autoconf is run from the
@@ -615,12 +616,16 @@ USE_MSGCTXT = no\n"""
             subdir = f'{sourcebase}/'
         else:
             subdir = ''
-        emit += r'''
-  m4_ifval(%V1%_LIBSOURCES_LIST, [
-    m4_syscmd([test ! -d ]m4_defn([%V1%_LIBSOURCES_DIR])[ ||
-      for gl_file in ]%V1%_LIBSOURCES_LIST[ ; do
-        if test ! -r ]m4_defn([%V1%_LIBSOURCES_DIR])[/$gl_file ; then
-          echo "missing file ]m4_defn([%V1%_LIBSOURCES_DIR])[/$gl_file" >&2
+        if libtool:
+            libobjdeps = f'{macro_prefix_arg}_libobjdeps="${macro_prefix_arg}_libobjdeps {subdir}$i_dir/\$(DEPDIR)/$i_base.Plo"'
+        else:
+            libobjdeps = f'{macro_prefix_arg}_libobjdeps="${macro_prefix_arg}_libobjdeps {subdir}$i_dir/\$(DEPDIR)/$i_base.Po"'
+        emit += fr'''
+  m4_ifval({macro_prefix_arg}_LIBSOURCES_LIST, [
+    m4_syscmd([test ! -d ]m4_defn([{macro_prefix_arg}_LIBSOURCES_DIR])[ ||
+      for gl_file in ]{macro_prefix_arg}_LIBSOURCES_LIST[ ; do
+        if test ! -r ]m4_defn([{macro_prefix_arg}_LIBSOURCES_DIR])[/$gl_file ; then
+          echo "missing file ]m4_defn([{macro_prefix_arg}_LIBSOURCES_DIR])[/$gl_file" >&2
           exit 1
         fi
       done])dnl
@@ -629,28 +634,38 @@ USE_MSGCTXT = no\n"""
   ])
   m4_popdef([GL_MODULE_INDICATOR_PREFIX])
   m4_popdef([GL_MACRO_PREFIX])
-  m4_popdef([%V1%_LIBSOURCES_DIR])
-  m4_popdef([%V1%_LIBSOURCES_LIST])
+  m4_popdef([{macro_prefix_arg}_LIBSOURCES_DIR])
+  m4_popdef([{macro_prefix_arg}_LIBSOURCES_LIST])
   m4_popdef([AC_LIBSOURCES])
   m4_popdef([AC_REPLACE_FUNCS])
   m4_popdef([AC_LIBOBJ])
   AC_CONFIG_COMMANDS_PRE([
-    %V1%_libobjs=
-    %V1%_ltlibobjs=
-    if test -n "$%V1%_LIBOBJS"; then
+    {macro_prefix_arg}_libobjs=
+    {macro_prefix_arg}_ltlibobjs=
+    {macro_prefix_arg}_libobjdeps=
+    if test -n "${macro_prefix_arg}_LIBOBJS"; then
       # Remove the extension.
+changequote(,)dnl
       sed_drop_objext='s/\.o$//;s/\.obj$//'
-      for i in `for i in $%V1%_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do
-        %V1%_libobjs="$%V1%_libobjs %V2%$i.$ac_objext"
-        %V1%_ltlibobjs="$%V1%_ltlibobjs %V2%$i.lo"
+      sed_dirname1='s,//*,/,g'
+      sed_dirname2='s,\(.\)/$,\1,'
+      sed_dirname3='s,^[^/]*$,.,'
+      sed_dirname4='s,\(.\)/[^/]*$,\1,'
+      sed_basename1='s,.*/,,'
+changequote([, ])dnl
+      for i in `for i in ${macro_prefix_arg}_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do
+        {macro_prefix_arg}_libobjs="${macro_prefix_arg}_libobjs {subdir}$i.$ac_objext"
+        {macro_prefix_arg}_ltlibobjs="${macro_prefix_arg}_ltlibobjs {subdir}$i.lo"
+        i_dir=`echo "$i" | sed -e "$sed_dirname1" -e "$sed_dirname2" -e "$sed_dirname3" -e "$sed_dirname4"`
+        i_base=`echo "$i" | sed -e "$sed_basename1"`
+        {libobjdeps}
       done
     fi
-    AC_SUBST([%V1%_LIBOBJS], [$%V1%_libobjs])
-    AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs])
+    AC_SUBST([{macro_prefix_arg}_LIBOBJS], [${macro_prefix_arg}_libobjs])
+    AC_SUBST([{macro_prefix_arg}_LTLIBOBJS], [${macro_prefix_arg}_ltlibobjs])
+    AC_SUBST([{macro_prefix_arg}_LIBOBJDEPS], [${macro_prefix_arg}_libobjdeps])
   ])
 '''
-        emit = emit.replace('%V1%', macro_prefix_arg)
-        emit = emit.replace('%V2%', subdir)
         return emit
 
     def initmacro_done(self, macro_prefix_arg, sourcebase_arg):
@@ -960,6 +975,8 @@ AC_DEFUN([%V1%_LIBSOURCES], [
 
         emit += '\n'
         emit += '%s_%s_SOURCES =\n' % (libname, libext)
+        if not for_test:
+            emit += '%s_%s_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)\n' % (libname, libext)
         # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
         # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
         emit += '%s_%s_LIBADD = $(%s_%sLIBOBJS)\n' % (libname, libext, macro_prefix, perhapsLT)
@@ -998,6 +1015,13 @@ AC_DEFUN([%V1%_LIBSOURCES], [
         emit += '\t  fi; \\\n'
         emit += '\tdone; \\\n'
         emit += '\t:\n'
+        # Emit rules to erase .Po and .Plo files for AC_LIBOBJ invocations.
+        # Extend the 'distclean' rule.
+        emit += 'distclean-local: distclean-gnulib-libobjs\n'
+        emit += 'distclean-gnulib-libobjs:\n'
+        emit += '\t-rm -f @%s_LIBOBJDEPS@\n' % (macro_prefix)
+        # Extend the 'maintainer-clean' rule.
+        emit += 'maintainer-clean-local: distclean-gnulib-libobjs\n'
         result = tuple([emit, uses_subdirs])
         return result
 
@@ -1242,7 +1266,11 @@ AC_DEFUN([%V1%_LIBSOURCES], [
         #   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'.
-        emit += 'CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@ @CFLAGS@\n'
+        cflags_for_gnulib_code = ''
+        if not for_test:
+            # Enable or disable warnings as suitable for the Gnulib coding style.
+            cflags_for_gnulib_code = ' $(GL_CFLAG_GNULIB_WARNINGS)'
+        emit += 'CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@%s @CFLAGS@\n' % (cflags_for_gnulib_code)
         emit += 'CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@\n'
         emit += '\n'
 
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 1dabccd201..db8c1c24a6 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -744,6 +744,7 @@ AC_DEFUN([%s_INIT],
                                               moduletable, 0, True, True, True, replace_auxdir)
         emit += '  m4_popdef([gl_MODULE_INDICATOR_CONDITION])\n'
         emit += self.emitter.initmacro_end('%stests' % macro_prefix, gentests)
+        emit += '  AC_REQUIRE([gl_CC_GNULIB_WARNINGS])\n'
         # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
         # created using libtool, because libtool already handles the dependencies.
         if not libtool:
-- 
2.44.0

Reply via email to