Hello.

Previous implementation was preventing one expansion with $(value),
but this quotation is now counter-productive.

Three commits are attached:
 2/ regression test
 3/ patch
 1/ an unrelated suggestion inspired by this bug
>From 67c012557c29edf884a6535d8b3120d36d6ebd85 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Fri, 19 Jul 2024 13:20:06 +0200
Subject: [PATCH 1/3] scripts/mk: ensure dpkg_datadir is computed once

dpkg_datadir ?= $(dir $(lastword $(MAKEFILE_LIST)))
is equivalent to
ifndef dpkg_datadir
  dpkg_datadir = $(..)
endif
$(..) is computed each time dpkg_datadir is expanded, so the result
will be wrong if MAKEFILE_LIST has grown meanwhile.

Assign with := so that the value is computed and never expanded again.
---
 scripts/mk/buildtools.mk | 4 +++-
 scripts/mk/vendor.mk     | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/mk/buildtools.mk b/scripts/mk/buildtools.mk
index 1f63beede..def15c103 100644
--- a/scripts/mk/buildtools.mk
+++ b/scripts/mk/buildtools.mk
@@ -28,7 +28,9 @@
 ifndef dpkg_buildtools_mk_included
 dpkg_buildtools_mk_included = yes
 
-dpkg_datadir ?= $(dir $(lastword $(MAKEFILE_LIST)))
+ifndef dpkg_datadir
+  dpkg_datadir := $(dir $(lastword $(MAKEFILE_LIST)))
+endif
 include $(dpkg_datadir)/architecture.mk
 
 # We set the TOOL_FOR_BUILD variables to the specified value, and the TOOL
diff --git a/scripts/mk/vendor.mk b/scripts/mk/vendor.mk
index 43898d956..d257eddcb 100644
--- a/scripts/mk/vendor.mk
+++ b/scripts/mk/vendor.mk
@@ -36,7 +36,9 @@
 ifndef dpkg_vendor_mk_included
 dpkg_vendor_mk_included = yes
 
-dpkg_datadir ?= $(dir $(lastword $(MAKEFILE_LIST)))
+ifndef dpkg_datadir
+  dpkg_datadir := $(dir $(lastword $(MAKEFILE_LIST)))
+endif
 include $(dpkg_datadir)/buildapi.mk
 
 dpkg_lazy_eval ?= $(eval $(1) = $(2)$$($(1)))
-- 
2.39.2

>From 5360de48a1534b0d72229f5476fd4b2f65a237bc Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Fri, 19 Jul 2024 14:24:22 +0200
Subject: [PATCH 2/3] scripts/mk: test expansions passed to dpkg-buildflags

Regression test for #1076568.
---
 scripts/t/mk/buildflags.mk | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/t/mk/buildflags.mk b/scripts/t/mk/buildflags.mk
index 74ccac04b..bc7e6a849 100644
--- a/scripts/t/mk/buildflags.mk
+++ b/scripts/t/mk/buildflags.mk
@@ -10,6 +10,10 @@ TEST_CXXFLAGS          := set-host
 DEB_CXXFLAGS_FOR_BUILD_MAINT_SET := set-build
 TEST_CXXFLAGS_FOR_BUILD          := set-build
 
+DEB_CFLAGS_MAINT_APPEND = -DTEST_MAKE_EXPANSION=$(expanded_on_demand)
+expanded_on_demand := contents
+TEST_CFLAGS += -DTEST_MAKE_EXPANSION=contents
+
 DPKG_EXPORT_BUILDFLAGS := 1
 
 include $(srcdir)/mk/buildflags.mk
-- 
2.39.2

>From 9ef54cf63a24e489802dcf8a814618b633c8308a Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Fri, 19 Jul 2024 14:08:10 +0200
Subject: [PATCH 3/3] scripts/mk: fix expansions passed to dpkg-buildflags.
 Closes: #1076568

---
 scripts/mk/buildflags.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/mk/buildflags.mk b/scripts/mk/buildflags.mk
index a8eac9e54..bc0448881 100644
--- a/scripts/mk/buildflags.mk
+++ b/scripts/mk/buildflags.mk
@@ -57,7 +57,7 @@ dpkg_buildflags_run = $(eval $(shell \
       $(foreach operation,SET STRIP APPEND PREPEND,\
         DEB_$(flag)_MAINT_$(operation))),\
     $(if $(value $(exported)),\
-      $(exported)="$(value $(exported))"))\
+      $(exported)="$($(exported))"))\
   dpkg-buildflags | sed 's/\([^=]*\)\(.*\)/$$(eval \1:\2)/'))
 
 ifdef DPKG_EXPORT_BUILDFLAGS
-- 
2.39.2

Reply via email to