]> Savannah Git Hosting - gnulib.git/commitdiff
crc: Fix build rules with Automake's option 'subdir-objects'.
authorBruno Haible <bruno@clisp.org>
Sun, 3 Nov 2024 20:18:29 +0000 (21:18 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 3 Nov 2024 20:18:54 +0000 (21:18 +0100)
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).

ChangeLog
build-aux/prefix-gnulib-mk
modules/crc

index 6ab3a1ca835d1ce21a3e4872087a2ed63a185669..1381089ad83c3942910705867b8d659fa828fa61 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-11-03  Bruno Haible  <bruno@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).
+
 2024-11-01  Bruno Haible  <bruno@clisp.org>
 
        select: Document a Haiku bug.
index a6de78bf2c877178af2945e5ae3f7443558e4e78..4387d50f0dcd546cae67f5b5747e0f2c129b9371 100755 (executable)
@@ -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.
index 618623eee7337d77320c22adff1e530fbcfcd36f..c8dc462a27964152eb698427fd036e67a836e10a 100644 (file)
@@ -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