+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.
#!/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
# 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;
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.
# 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