Subject: bug#72237: diffutils "make dist" not compliant with the GNU Coding Standards

From: Bruno Haible <[email-masked]>
Date: Sun, 21 Jul 2024 21:31:52 +0200

Hi,

According to the GNU Coding Standard
https://www.gnu.org/prep/standards/html_node/Standard-Targets.html
  "The dist target should explicitly depend on all non-source files
   that are in the distribution, to make sure they are up to date
   in the distribution."

An easy way to test whether the 'dist' target has this property
is to run

   $ ./configure
   $ make dist

or (in a VPATH build)

   $ ../configure
   $ make dist

without doing "make" before "make dist".

Distributed non-source files that make this difficult are the man pages
for programs, that are generated from the '--help' output using help2man.

While packages that only have a top-level Makefile.am (such as GNU sed
or GNU coreutils) get this right, it is a little bit more complicated
in packages with a Makefile.am per directory (such as GNU diffutils and
GNU gettext). Originally reported for GNU gettext at
<https://lists.gnu.org/archive/html/bug-gettext/2024-07/msg00010.html>.

In GNU diffutils
  $ ./configure; make dist V=1
fails like this:

make[3]: Entering directory '/DIFFUTILS/diffutils/man'
make  distdir-am
make[4]: Entering directory '/DIFFUTILS/diffutils/man'
base=`expr cmp.1 : '\(.*\).1'`                          \
  && test -x ../src/$base                                       \
  && (echo '[NAME]'                                             \
              && sed 's@/\* *@@; s/-/\\-/;s/^GNU //; q' ../src/$base.c) \
     | PATH="../src:$PATH"                      \
       ./help2man -i - -i ./$base.x             \
         -S 'diffutils 2024-05-21' $base > cmp.1-t && mv cmp.1-t cmp.1
make[4]: *** [Makefile:2483: cmp.1] Error 1
make[4]: Leaving directory '/DIFFUTILS/diffutils/man'
make[3]: *** [Makefile:2322: distdir] Error 2
make[3]: Leaving directory '/DIFFUTILS/diffutils/man'

The attached patch fixes it. Tested also with VPATH builds, with
  - GNU make,
  - FreeBSD make,
  - NetBSD make.
Tested also with parallel make, through

   $ ./configure; make -j8 dist V=1

>From 9c8b154025243e4527ccc1640cde75d4d9ae50f4 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email-masked]>
Date: Sun, 21 Jul 2024 21:25:01 +0200
Subject: [PATCH] build: Fix failure of "./configure; make dist"

* Makefile.am (BUILT_SOURCES): New variable.
(man/cmp.1, man/diff.1, man/diff3.1, man/sdiff.1): New targets.
(gen-man1): New phony target.
---
 Makefile.am | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 59084bc..564b46a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,24 @@ SUBDIRS = lib src tests doc man po gnulib-tests
 ACLOCAL_AMFLAGS = -I m4
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 
+# Ensure that the manual pages are up-to-date when "make dist" runs.
+BUILT_SOURCES = \
+  man/cmp.1 \
+  man/diff.1 \
+  man/diff3.1 \
+  man/sdiff.1
+man/cmp.1 man/diff.1 man/diff3.1 man/sdiff.1 : gen-man1
+.PHONY: gen-man1
+gen-man1: $(top_srcdir)/src/cmp.c man/cmp.x \
+          $(top_srcdir)/src/diff.c man/diff.x \
+          $(top_srcdir)/src/diff3.c man/diff3.x \
+          $(top_srcdir)/src/sdiff.c man/sdiff.x
+	$(AM_V_GEN)(cd lib && $(MAKE) $(AM_MAKEFLAGS)) \
+	  && (cd src \
+	      && $(MAKE) $(AM_MAKEFLAGS) \
+	         cmp$(EXEEXT) diff$(EXEEXT) diff3$(EXEEXT) sdiff$(EXEEXT)) \
+	  && (cd man && $(MAKE) $(AM_MAKEFLAGS) cmp.1 diff.1 diff3.1 sdiff.1)
+
 # Arrange so that .tarball-version appears only in the distribution
 # tarball, and never in a checked-out repository.
 dist-hook: gen-ChangeLog
-- 
2.34.1