From 79e93c0d0b825f516e5623696f9cf4ed1f8d4faf Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas@debian.org>
Date: Mon, 29 Jul 2024 17:56:24 +0200
Subject: [PATCH 2/2] scripts/mk: mark dpkg_{late,lazy}_eval as deprecated

and rename dpkg_lazy_eval to dpkg_lazy (back), at least for now.
---
 scripts/mk/Readme          | 19 +++++++++++++------
 scripts/mk/architecture.mk |  2 ++
 scripts/mk/buildapi.mk     |  4 ++--
 scripts/mk/buildflags.mk   |  7 +++++--
 scripts/mk/pkg-info.mk     |  6 ++++--
 scripts/mk/vendor.mk       |  6 ++++--
 6 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/scripts/mk/Readme b/scripts/mk/Readme
index 6e582cede..56f73f465 100644
--- a/scripts/mk/Readme
+++ b/scripts/mk/Readme
@@ -1,3 +1,7 @@
+This file explains the lazy evaluation used by the Makefile snippets
+in this directory.  Things described here are private, and not part of
+the public API.
+
 $(call dpkg_lazy_set,VARIABLE,COMPUTATION)
 
   Assigns VARIABLE so that the first $(VARIABLE) expansion triggers
@@ -15,15 +19,18 @@ $(call dpkg_lazy_set,VARIABLE,COMPUTATION)
   meaning, although DEB_CFLAGS_MAINT_APPEND:=foo and similar
   constructs should be preferred when possible.
 
-$(eval $(call dpkg_lazy_eval,VAR1,COMPUTATION))
-$(eval $(call dpkg_lazy_eval,VAR2,COMPUTATION))
-...
+  When debugging the lazy evaluation, it may be convenient to set
+  COMPUTATION to $$(computation) and start the definition of
+  computation with $(info RUN).
 
+$(eval $(call dpkg_lazy,VAR1,COMPUTATION))
+$(eval $(call dpkg_lazy,VAR2,COMPUTATION))
+...
   Assigns VAR1, VAR2... so that the first expansion of any variable
   triggers COMPUTATION.  COMPUTATION must return an empty string and
   its side effects must assign all of DPKG_CACHE_VAR1,
   DPKG_CACHE_VAR2... with :=.
 
-When debugging the lazy evaluation, it may be convenient to set
-COMPUTATION to $$(computation) and start the definition of computation
-with $(info RUN).
+dpkg_late_eval
+dpkg_lazy_eval
+  are deprecated.
diff --git a/scripts/mk/architecture.mk b/scripts/mk/architecture.mk
index 755863257..761463bdf 100644
--- a/scripts/mk/architecture.mk
+++ b/scripts/mk/architecture.mk
@@ -6,6 +6,8 @@
 ifndef dpkg_architecture_mk_included
 dpkg_architecture_mk_included = yes
 
+dpkg_lazy_eval ?= $$(or $$(value DPKG_CACHE_$(1)),$$(eval DPKG_CACHE_$(1) := $$(shell $(2)))$$(value DPKG_CACHE_$(1)))$(warning dpkg_lazy_eval is deprecated)
+
 # Run a subprocess then assign all unset or empty variables.
 dpkg_architecture_run = \
   $(foreach line,$(shell dpkg-architecture),\
diff --git a/scripts/mk/buildapi.mk b/scripts/mk/buildapi.mk
index 4ee5b7115..2381bfad8 100644
--- a/scripts/mk/buildapi.mk
+++ b/scripts/mk/buildapi.mk
@@ -3,11 +3,11 @@
 ifndef dpkg_buildapi_mk_included
 dpkg_buildapi_mk_included = yes
 
-define dpkg_lazy_eval ?=
+define dpkg_lazy ?=
   $1 = $$(DPKG_CACHE_$1)
   DPKG_CACHE_$1 = $2$$(call DPKG_CACHE_$1)
 endef
-dpkg_lazy_set ?= $(eval $(call dpkg_lazy_eval,$1,$$(eval DPKG_CACHE_$1 := $2)))
+dpkg_lazy_set ?= $(eval $(call dpkg_lazy,$1,$$(eval DPKG_CACHE_$1 := $2)))
 
 # Default API level when not set.
 ifndef DPKG_BUILD_API
diff --git a/scripts/mk/buildflags.mk b/scripts/mk/buildflags.mk
index 0533d6a72..537bf2710 100644
--- a/scripts/mk/buildflags.mk
+++ b/scripts/mk/buildflags.mk
@@ -32,13 +32,16 @@
 ifndef dpkg_buildflags_mk_included
 dpkg_buildflags_mk_included = yes
 
-define dpkg_lazy_eval ?=
+define dpkg_lazy ?=
   $1 = $$(DPKG_CACHE_$1)
   DPKG_CACHE_$1 = $2$$(call DPKG_CACHE_$1)
 endef
 
 # This list is kept in sync with the default set of flags returned
 # by dpkg-buildflags.
+
+dpkg_lazy_eval ?= $$(or $$(value DPKG_CACHE_$(1)),$$(eval DPKG_CACHE_$(1) := $$(shell $(2)))$$(value DPKG_CACHE_$(1)))$(warning dpkg_lazy_eval is deprecated)
+
 DPKG_BUILDFLAGS_LIST := $(foreach var,\
   ASFLAGS \
   CFLAGS \
@@ -66,7 +69,7 @@ dpkg_buildflags_run = $(eval $(shell \
   dpkg-buildflags | sed 's/\([^=]*\)\(.*\)/$$(eval DPKG_CACHE_\1:\2)/'))
 
 $(foreach flag,$(DPKG_BUILDFLAGS_LIST),\
-  $(eval $(call dpkg_lazy_eval,$(flag),$$(dpkg_buildflags_run))))
+  $(eval $(call dpkg_lazy,$(flag),$$(dpkg_buildflags_run))))
 
 ifdef DPKG_EXPORT_BUILDFLAGS
   export $(DPKG_BUILDFLAGS_LIST)
diff --git a/scripts/mk/pkg-info.mk b/scripts/mk/pkg-info.mk
index 7f52d93d3..61ac124ac 100644
--- a/scripts/mk/pkg-info.mk
+++ b/scripts/mk/pkg-info.mk
@@ -21,7 +21,9 @@
 ifndef dpkg_pkg_info_mk_included
 dpkg_pkg_info_mk_included = yes
 
-define dpkg_lazy_eval ?=
+dpkg_late_eval ?= $(or $(value DPKG_CACHE_$(1)),$(eval DPKG_CACHE_$(1) := $(shell $(2)))$(value DPKG_CACHE_$(1)))$(warning dpkg_late_eval is deprecated)
+
+define dpkg_lazy ?=
   $1 = $$(DPKG_CACHE_$1)
   DPKG_CACHE_$1 = $2$$(call DPKG_CACHE_$1)
 endef
@@ -46,7 +48,7 @@ $(foreach var,\
   VERSION_UPSTREAM \
   DISTRIBUTION \
   TIMESTAMP \
-  ,$(eval $(call dpkg_lazy_eval,DEB_$(var),$$(dpkg_parsechangelog_run))))
+  ,$(eval $(call dpkg_lazy,DEB_$(var),$$(dpkg_parsechangelog_run))))
 
 SOURCE_DATE_EPOCH ?= $(DEB_TIMESTAMP)
 export SOURCE_DATE_EPOCH
diff --git a/scripts/mk/vendor.mk b/scripts/mk/vendor.mk
index 61db1133c..44e9f43ac 100644
--- a/scripts/mk/vendor.mk
+++ b/scripts/mk/vendor.mk
@@ -41,11 +41,13 @@ ifndef dpkg_datadir
 endif
 include $(dpkg_datadir)/buildapi.mk
 
-define dpkg_lazy_eval ?=
+dpkg_late_eval ?= $(or $(value DPKG_CACHE_$(1)),$(eval DPKG_CACHE_$(1) := $(shell $(2)))$(value DPKG_CACHE_$(1)))$(warning dpkg_late_eval is deprecated)
+
+define dpkg_lazy ?=
   $1 = $$(DPKG_CACHE_$1)
   DPKG_CACHE_$1 = $2$$(call DPKG_CACHE_$1)
 endef
-dpkg_lazy_set ?= $(eval $(call dpkg_lazy_eval,$1,$$(eval DPKG_CACHE_$1 := $2)))
+dpkg_lazy_set ?= $(eval $(call dpkg_lazy,$1,$$(eval DPKG_CACHE_$1 := $2)))
 
 $(call dpkg_lazy_set,DEB_VENDOR,$$(shell dpkg-vendor --query Vendor))
 $(call dpkg_lazy_set,DEB_PARENT_VENDOR,$$(shell dpkg-vendor --query Parent))
-- 
2.39.2

