Subject: bug#69315: [PATCH] Build system fixes

From: Jonas Hahnfeld <[email-masked]>
Date: Thu, 22 Feb 2024 22:14:04 +0100

Dear Guile maintainers,

please find attached two patches for changes that we have been carrying
downstream in LilyPond so far: one fix to make a sed invocation fully
portable, and a fix for cross-compilation in out-of-tree-builds.

Regards
Jonas
From 428d1b17c5f664d3cb8da4cd5687bd47bdd87877 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <[email-masked]>
Date: Thu, 22 Feb 2024 21:57:41 +0100
Subject: [PATCH 1/2] build: Make sed invocation fully portable

Commit 08041d216f attempted to make the "invocation compatible with
BSD sed", but moving '-i' first does not solve the problem because
it still requires to pass an argument. Instead just redirect the
instantiated output into a temporary file and install that.

* libguile/Makefile.am: Remove '-i' from INSTANTIATE.
---
 libguile/Makefile.am | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libguile/Makefile.am b/libguile/Makefile.am
index 249e44a49..2641e7f69 100644
--- a/libguile/Makefile.am
+++ b/libguile/Makefile.am
@@ -492,9 +492,9 @@ install-exec-hook:
 
 ## Instantiate a template.
 INSTANTIATE =									\
-  $(SED) -i -e 's,[@]pkgdatadir[@],$(pkgdatadir),g'				\
-            -e 's,[@]pkglibdir[@],$(pkglibdir),g'				\
-            -e 's,[@]GUILE_EFFECTIVE_VERSION[@],$(GUILE_EFFECTIVE_VERSION),g'
+  $(SED) -e 's,[@]pkgdatadir[@],$(pkgdatadir),g'				\
+         -e 's,[@]pkglibdir[@],$(pkglibdir),g'					\
+         -e 's,[@]GUILE_EFFECTIVE_VERSION[@],$(GUILE_EFFECTIVE_VERSION),g'
 
 install-data-hook: libguile-@[email-masked]
 	@$(MKDIR_P) $(DESTDIR)$(libdir)
@@ -518,9 +518,9 @@ install-data-hook: libguile-@[email-masked]
 	cd $$here;						\
 	echo " $(INSTALL_DATA) $<				\
 $(DESTDIR)$(libdir)/$$libname-gdb.scm";				\
-	$(INSTALL_DATA) "$<"					\
-	    "$(DESTDIR)$(libdir)/$$libname-gdb.scm";		\
-	$(INSTANTIATE) "$(DESTDIR)$(libdir)/$$libname-gdb.scm"
+	$(INSTANTIATE) "$<" > $$libname-gdb.scm;		\
+	$(INSTALL_DATA) $$libname-gdb.scm			\
+	    "$(DESTDIR)$(libdir)/$$libname-gdb.scm";
 
 # Remove the GDB support file and the Info 'dir' file that
 # 'install-info' 5.x installs.
-- 
2.43.2

From ad01912391b449fcf547ac52ed468f9b572cb0ad Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <[email-masked]>
Date: Thu, 22 Feb 2024 22:10:06 +0100
Subject: [PATCH 2/2] build: Fix cross-compilation in out-of-tree-builds

gen-scmconfig.h is generated in libguile, not $(top_builddir).

* libguile/Makefile.am: Add '-I.' when compiling gen-scmconfig.o.
---
 libguile/Makefile.am | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libguile/Makefile.am b/libguile/Makefile.am
index 2641e7f69..f5d43cc01 100644
--- a/libguile/Makefile.am
+++ b/libguile/Makefile.am
@@ -62,14 +62,15 @@ gen_scmconfig_SOURCES = gen-scmconfig.c
 ## Override default rule; this should be compiled for BUILD host.  Note
 ## that we don't add $(AM_CPPFLAGS) here, as we need to run this
 ## program, but $(top_srcdir)/lib has a gnulib configured for the
-## target.  Instead we manually add $(top_builddir), in order to pick up
-## the generated config.h and gen-scmconfig.h.  Nothing else from Guile
-## is included by this code generator.
+## target.  Instead we manually add $(top_builddir) and the current
+## directory, in order to pick up the generated config.h and
+## gen-scmconfig.h.  Nothing else from Guile is included by this code
+## generator.
 gen-scmconfig.$(OBJEXT): gen-scmconfig.c
 	$(AM_V_GEN) \
 	if [ "$(cross_compiling)" = "yes" ]; then \
 		$(CC_FOR_BUILD) $(DEFS) $(DEFAULT_INCLUDES) -I$(top_builddir) \
-		   -c -o $@ $<; \
+		   -I. -c -o $@ $<; \
 	else \
 		$(COMPILE) -c -o $@ $<; \
 	fi
-- 
2.43.2