Pádraig Brady wrote:
> Latest gnulib is failing coreutils CI because of a mismatch in mkdir && cd 
> due to prefixes.
> In the generated Makefile I'm seeing: $(MKDIR_P) lib/crc-tmp
> I.e. MKDIR_P has been processed to add in the lib prefix.
> However the subsequent `cd crc-tmp` doesn't have the prefix, and the build 
> fails.

Thanks for the report. This patch fixes it.


2024-11-03  Bruno Haible  <br...@clisp.org>

        crc: Fix build rules with Automake's option 'subdir-objects'.
        Reported by Pádraig Brady in
        <https://lists.gnu.org/archive/html/bug-gnulib/2024-11/msg00011.html>.
        * build-aux/prefix-gnulib-mk: Add comments.
        (usage): Mark this usage as deprecated.
        * modules/crc (Makefile.am): Use %reldir%. Write $(srcdir)/. instead of
        $(srcdir).

diff --git a/build-aux/prefix-gnulib-mk b/build-aux/prefix-gnulib-mk
index a6de78bf2c..4387d50f0d 100755
--- a/build-aux/prefix-gnulib-mk
+++ b/build-aux/prefix-gnulib-mk
@@ -1,8 +1,6 @@
 #!/bin/sh
 #! -*-perl-*-
 
-# Rewrite a gnulib.mk, adding prefixes to work with automake's subdir-objects.
-
 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
@@ -33,6 +31,47 @@ my $VERSION = '2024-07-04 10:56'; # UTC
 # If you change this file with Emacs, please let the write hook
 # do its job.  Otherwise, update this string manually.
 
+# Overview
+# ========
+#
+# Automake is usually used with a separate Makefile.am in each subdirectory
+# that contains sources.  The advantage is that the build infrastructure of
+# the package is composable.
+#
+# An alternative way to use Automake is to have a Makefile.am at the top-level
+# only, and each subdirectory contains a Makefile.am fragment, called
+# <something>.mk, that is included by the top-level Makefile.am.
+# This is called "non-recursive Automake" and is explained in
+# <https://autotools.info/automake/nonrecursive.html>.  This way makes it
+# easier to use a library in one subdirectory from sources in another
+# subdirectory, and still have 'make' check dependencies in an optimal way.
+#
+# The "non-recursive Automake" is activated through the Automake option
+# 'subdir-objects'.
+#
+# There are two ways to support this mode with Gnulib:
+#   (a) The gnulib-tool option --automake-subdir.
+#   (b) The deprecated 'non-recursive-gnulib-prefix-hack' module.
+# Both make use of this script.  This script rewrites the a Makefile.am portion
+# made for the usual way, so that it can be used in the non-recursive way.
+#
+# This script can be invoked in two ways:
+#   (a) Through an invocation of build-aux/prefix-gnulib-mk from within
+#       gnulib-tool, with options such as
+#         --from-gnulib-tool --lib-name=libgnu --prefix=lib/
+#   (b) Through an invocation of build-aux/prefix-gnulib-mk from the package's
+#       build system (deprecated).
+#
+# The official way to write Makefile.am snippets that supports both ways is
+# through the %reldir% token, that is explained in
+# <https://www.gnu.org/software/automake/manual/html_node/Include.html>.
+# Doing this would, however, lead to hundreds of occurrences of %reldir%,
+# which is not pretty to work with.  Therefore, what Gnulib does is:
+#   - This script adds the prefix (e.g. 'lib/') in most places, based on
+#     simple patterns (e.g. before source file names and after $(MKDIR_P)).
+#   - In other places, that are not covered by this script, we use %reldir%
+#     explicitly.
+
 use strict;
 use IO::File;
 use Getopt::Long;
@@ -55,7 +94,7 @@ sub usage ($)
   else
     {
       print $STREAM <<EOF;
-Usage: $ME --lib-name=NAME FILE
+Usage: $ME --lib-name=NAME FILE  (deprecated)
    or: $ME [--help|--version]
 Rewrite a gnulib-tool-generated FILE like lib/gnulib.mk to work with
 automake's subdir-objects.
diff --git a/modules/crc b/modules/crc
index 618623eee7..c8dc462a27 100644
--- a/modules/crc
+++ b/modules/crc
@@ -29,12 +29,12 @@ lib_SOURCES += crc.c
 # gnulib-generated stdio.h and stdlib.h files are not visible.
 $(srcdir)/crc-sliceby8.h: $(srcdir)/crc-generate-table.c
        if test -n '$(BUILD_CC)'; then \
-         $(MKDIR_P) crc-tmp \
-         && abs_srcdir=`cd $(srcdir) && pwd` \
-         && (cd crc-tmp \
+         $(MKDIR_P) '%reldir%/crc-tmp' \
+         && abs_srcdir=`cd $(srcdir)/. && pwd` \
+         && (cd '%reldir%/crc-tmp' \
              && $(BUILD_CC) $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) 
-o crc-generate-table $$abs_srcdir/crc-generate-table.c) \
-         && crc-tmp/crc-generate-table $(srcdir)/crc-sliceby8.h-t \
-         && rm -rf crc-tmp \
+         && '%reldir%/crc-tmp/crc-generate-table' $(srcdir)/crc-sliceby8.h-t \
+         && rm -rf '%reldir%/crc-tmp' \
          && mv $(srcdir)/crc-sliceby8.h-t $(srcdir)/crc-sliceby8.h; \
        fi
 BUILT_SOURCES        += crc-sliceby8.h




Reply via email to