Summary of inadvertently private mails:
mk-bsd-sed-quotation-mark.diff hopefully fixes the build on BSD.

Assuming this, and that I am not missing the point again,
mk-unhardcode-datadir.diff can be applied again.
The attachment improves its readability.

 * It replaces "ifndef ... := ... endif" with "?=".
   The variable will be searched for $ on each expansion, but the
   performance difference is probably quite small.

 * It removes the comment explaining where dpkg_datadir might already
   be defined.
   Anyone working on this will know about default.mk.

 * It replaces $(patsubst ...) with $(dir ...).
   This was the original suggestion.
   You once answered:
> to avoid changing all pathname concatenation I changed dpkg_datadir to
> «$(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))».
   then I did suggest  $(patsubst %/current.mk/,%,$(lastword $(MAKEFILE_LIST))),
   but, thinking about it again, there seems to be no problem with a
   double path component separator.
>From 467d7aa41c95796f6d7ef43bb4c8fda925728791 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Tue, 2 Jul 2024 11:54:55 +0200
Subject: scripts/mk: Stop hard-coding dpkg_datadir

This path differ during tests and after installation.  Instead of
rewriting the file with a hardcoded path, compute it within Make.

diff --git a/build-aux/subst.am b/build-aux/subst.am
index 7785e4af7..9c96e5ce0 100644
--- a/build-aux/subst.am
+++ b/build-aux/subst.am
@@ -45,11 +45,3 @@ SUFFIXES += .pl
 	@test -d `dirname $@` || $(MKDIR_P) `dirname $@`
 	$(AM_V_GEN) $(subst_perl_filter) <$< >$@
 	$(AM_V_at) chmod +x $@
-
-# Makefile support.
-
-subst_make_rules = "\
-	s{dpkg_datadir\s*=\s*[^\s]*}{dpkg_datadir = $(pkgdatadir)}; \
-	"
-
-subst_make_file = $(PERL) -i -p -e $(subst_make_rules)
diff --git a/scripts/mk/Makefile.am b/scripts/mk/Makefile.am
index be6076b2c..6e85e17b9 100644
--- a/scripts/mk/Makefile.am
+++ b/scripts/mk/Makefile.am
@@ -10,13 +10,3 @@ dist_pkgdata_DATA = \
 	pkg-info.mk \
 	vendor.mk \
 	# EOL
-
-SUFFIXES =
-
-include $(top_srcdir)/build-aux/subst.am
-
-install-data-hook:
-	$(subst_make_file) $(DESTDIR)$(pkgdatadir)/default.mk
-	$(subst_make_file) $(DESTDIR)$(pkgdatadir)/buildtools.mk
-	$(subst_make_file) $(DESTDIR)$(pkgdatadir)/pkg-info.mk
-	$(subst_make_file) $(DESTDIR)$(pkgdatadir)/vendor.mk
diff --git a/scripts/mk/buildtools.mk b/scripts/mk/buildtools.mk
index 6ce9642cd..1f63beede 100644
--- a/scripts/mk/buildtools.mk
+++ b/scripts/mk/buildtools.mk
@@ -28,7 +28,7 @@
 ifndef dpkg_buildtools_mk_included
 dpkg_buildtools_mk_included = yes
 
-dpkg_datadir = $(srcdir)/mk
+dpkg_datadir ?= $(dir $(lastword $(MAKEFILE_LIST)))
 include $(dpkg_datadir)/architecture.mk
 
 # We set the TOOL_FOR_BUILD variables to the specified value, and the TOOL
diff --git a/scripts/mk/default.mk b/scripts/mk/default.mk
index c4e408b01..14e5be0cd 100644
--- a/scripts/mk/default.mk
+++ b/scripts/mk/default.mk
@@ -4,7 +4,8 @@
 ifndef dpkg_default_mk_included
 dpkg_default_mk_included = yes
 
-dpkg_datadir = $(srcdir)/mk
+dpkg_datadir := $(dir $(lastword $(MAKEFILE_LIST)))
+
 include $(dpkg_datadir)/architecture.mk
 include $(dpkg_datadir)/buildapi.mk
 ifeq ($(call dpkg_build_api_ge,1),yes)
diff --git a/scripts/mk/vendor.mk b/scripts/mk/vendor.mk
index 746503a33..43898d956 100644
--- a/scripts/mk/vendor.mk
+++ b/scripts/mk/vendor.mk
@@ -36,7 +36,7 @@
 ifndef dpkg_vendor_mk_included
 dpkg_vendor_mk_included = yes
 
-dpkg_datadir = $(srcdir)/mk
+dpkg_datadir ?= $(dir $(lastword $(MAKEFILE_LIST)))
 include $(dpkg_datadir)/buildapi.mk
 
 dpkg_lazy_eval ?= $(eval $(1) = $(2)$$($(1)))
>From ca50a267435a14fddd8679771b1e3c1178160ee1 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Tue, 2 Jul 2024 10:44:20 +0200
Subject: scripts/mk: replace more GNU sed constructs with POSIX ones

This hopefully fixes tests with BSD sed.

diff --git a/scripts/mk/pkg-info.mk b/scripts/mk/pkg-info.mk
index cfd456af1..ddda4f736 100644
--- a/scripts/mk/pkg-info.mk
+++ b/scripts/mk/pkg-info.mk
@@ -21,7 +21,7 @@ dpkg_pkg_info_mk_included = yes
 dpkg_parsechangelog_run = $(eval $(shell dpkg-parsechangelog | sed -n '\
   s/^Distribution: \(.*\)/$$(eval DEB_DISTRIBUTION:=\1)/p;\
   s/^Source: \(.*\)/$$(eval DEB_SOURCE:=\1)/p;\
-  s/^Version: \([0-9]*:\)\?\([^-]*\)\(\(.*\)-[^-]*\)\?$$/\
+  s/^Version: \([0-9]*:\)\{0,1\}\([^-]*\)\(\(.*\)-[^-]*\)\{0,1\}$$/\
     $$(eval DEB_VERSION:=\1\2\3)\
     $$(eval DEB_VERSION_EPOCH_UPSTREAM:=\1\2\4)\
     $$(eval DEB_VERSION_UPSTREAM_REVISION:=\2\3)\

Reply via email to