Subject: bug#76735: Shepherd parallel make help2man issue

From: Ludovic Courtès <[email-masked]>
Date: Sun, 09 Mar 2025 21:32:31 +0100

Hi Simon,

Simon Josefsson <[email-masked]> skribis:

> I got the build error below.  Presumably it happens because the jobs to
> create the tools has not finished before the help2man jobs has started.

Am I right that you’re building from a Git checkout?

The problem is that the Makefile rules for man pages are meant for
developers building the tarball; the tarball already includes man pages,
so someone building from the tarball doesn’t trigger any of these rules.

The changes below fix dependencies, but it also means that now everyone
will be building man pages from source, even if they’re already included
in the tarball.  That’s probably the right thing to do longer term, but
I’d rather not do it in the middle of a stable series.

WDYT?

Ludo’.

diff --git a/Makefile.am b/Makefile.am
index 23d1360..9d5e053 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -131,15 +131,18 @@ AM_V_HELP2MAN_0 = @echo "  HELP2MAN" $@;
 HELP2MANFLAGS = --source=GNU --info-page=$(PACKAGE_TARNAME)
 gen_man = $(AM_V_HELP2MAN)LANGUAGE= $(HELP2MAN) $(HELP2MANFLAGS)
 
-doc/shepherd.1: modules/shepherd.scm configure.ac
+doc/shepherd.1: shepherd $(nodist_shepherdsub_DATA) modules/shepherd.scm configure.ac
+	$(MKDIR_P) doc
 	$(gen_man) --name="Service manager for the GNU system" \
 	--output="$@" "$(top_builddir)/`basename "$@" .1`"
 
-doc/herd.1: modules/shepherd/scripts/herd.scm configure.ac
+doc/herd.1: herd $(nodist_shepherdsub_DATA) modules/shepherd/scripts/herd.scm configure.ac
+	$(MKDIR_P) doc
 	$(gen_man) --name="Control the shepherd(1) service manager" \
 	--output="$@" "$(top_builddir)/`basename "$@" .1`"
 
-doc/%.8: modules/shepherd/scripts/%.scm configure.ac
+doc/%.8: % $(nodist_shepherdsub_DATA) modules/shepherd/scripts/%.scm configure.ac
+	$(MKDIR_P) doc
 	$(gen_man) --section=8 --output="$@"	\
 	  "$(top_builddir)/`basename "$@" .8`"
 
@@ -223,13 +226,13 @@ instantiate =						\
 
 # Emit a 'chmod +x' command only if $@ matches one of the scripts.
 maybe_executable =					\
-   $(subst $@,chmod +x $@,				\
+   $(subst $@,chmod +x "$@.tmp",			\
       $(findstring $@,$(bin_SCRIPTS) $(sbin_SCRIPTS)))
 
 %: %.in Makefile
 	$(AM_V_GEN)$(MKDIR_P) "`dirname $@`" ;		\
-	$(SED) $(instantiate) < $< >$@ ;		\
-	$(maybe_executable)
+	$(SED) $(instantiate) < "$<" > "$@.tmp" ;	\
+	$(maybe_executable) ; mv "$@.tmp" "$@"
 
 modules/shepherd/config.scm: modules/shepherd/config.scm.in Makefile
 	$(MKDIR_P) "`dirname $@`"
diff --git a/halt.in b/halt.in
index 93ac83c..6516cf2 100644
--- a/halt.in
+++ b/halt.in
@@ -2,6 +2,6 @@
 -*- scheme -*-
 !#
 
-(set! %load-path (cons "%modsrcdir%" %load-path))
+(set! %load-path (append '("%modbuilddir%" "%modsrcdir%") %load-path))
 (set! %load-compiled-path (cons "%modbuilddir%" %load-compiled-path))
 (apply (@ (shepherd scripts halt) main) (cdr (command-line)))
diff --git a/herd.in b/herd.in
index e61d26b..09e2fd7 100644
--- a/herd.in
+++ b/herd.in
@@ -3,7 +3,7 @@
 !#
 
 (set! %load-path
-      (append '("%modsrcdir%" "%FIBERS_SOURCE_DIRECTORY%") %load-path))
+      (append '("%modbuilddir%" "%modsrcdir%" "%FIBERS_SOURCE_DIRECTORY%") %load-path))
 (set! %load-compiled-path
       (append '("%modbuilddir%" "%FIBERS_OBJECT_DIRECTORY%") %load-compiled-path))
 
diff --git a/reboot.in b/reboot.in
index 254b095..7bd93fa 100644
--- a/reboot.in
+++ b/reboot.in
@@ -2,6 +2,6 @@
 -*- scheme -*-
 !#
 
-(set! %load-path (cons "%modsrcdir%" %load-path))
+(set! %load-path (append '("%modbuilddir%" "%modsrcdir%") %load-path))
 (set! %load-compiled-path (cons "%modbuilddir%" %load-compiled-path))
 (apply (@ (shepherd scripts reboot) main) (cdr (command-line)))
diff --git a/shepherd.in b/shepherd.in
index 29a8227..b61fd35 100644
--- a/shepherd.in
+++ b/shepherd.in
@@ -3,7 +3,7 @@
 !#
 
 (set! %load-path
-      (append '("%modsrcdir%" "%FIBERS_SOURCE_DIRECTORY%") %load-path))
+      (append '("%modbuilddir%" "%modsrcdir%" "%FIBERS_SOURCE_DIRECTORY%") %load-path))
 (set! %load-compiled-path
       (append '("%modbuilddir%" "%FIBERS_OBJECT_DIRECTORY%") %load-compiled-path))