From 6a094cdd65da5b9e113ce71f6dd4a063d50f4d09 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas@debian.org>
Date: Sun, 13 Feb 2022 14:17:20 +0100
Subject: [PATCH 5/6] scripts/mk: protect against repeated inclusion

For example, buildtools.mk implicitly includes architecture.mk.
---
 scripts/mk/architecture.mk | 5 +++++
 scripts/mk/buildflags.mk   | 6 ++++++
 scripts/mk/buildopts.mk    | 5 +++++
 scripts/mk/buildtools.mk   | 5 +++++
 scripts/mk/pkg-info.mk     | 6 ++++++
 scripts/mk/vendor.mk       | 5 +++++
 6 files changed, 32 insertions(+)

diff --git a/scripts/mk/architecture.mk b/scripts/mk/architecture.mk
index 198e5e145..963293e05 100644
--- a/scripts/mk/architecture.mk
+++ b/scripts/mk/architecture.mk
@@ -2,6 +2,9 @@
 # DEB_BUILD_* variables that dpkg-architecture can return. Existing values
 # of those variables are preserved as per policy.
 
+ifndef dpkg_architecture_mk_already_included
+dpkg_architecture_mk_already_included :=
+
 dpkg-architecture_vars := \
 $(foreach machine,BUILD HOST TARGET,\
   $(foreach var,ARCH ARCH_ABI ARCH_LIBC ARCH_OS ARCH_CPU ARCH_BITS ARCH_ENDIAN GNU_CPU GNU_SYSTEM GNU_TYPE MULTIARCH,\
@@ -17,3 +20,5 @@ ifneq (,$(filter undefined,$(foreach v,$(dpkg-architecture_vars),$(origin $(v)))
 endif
 
 export $(dpkg-architecture_vars)
+
+endif
diff --git a/scripts/mk/buildflags.mk b/scripts/mk/buildflags.mk
index 868581a7f..34a66fd01 100644
--- a/scripts/mk/buildflags.mk
+++ b/scripts/mk/buildflags.mk
@@ -15,6 +15,10 @@
 # You can also export them in the environment by setting
 # DPKG_EXPORT_BUILDFLAGS to a non-empty value.
 #
+
+ifndef dpkg_buildflags_mk_already_included
+dpkg_buildflags_mk_already_included :=
+
 # This list is kept in sync with the default set of flags returned
 # by dpkg-buildflags.
 
@@ -55,3 +59,5 @@ else
   $(foreach var,$(DPKG_BUILDFLAGS_LIST),\
     $(eval $(var)=$$(dpkg-buildflags_run)$$($(var))))
 endif
+
+endif
diff --git a/scripts/mk/buildopts.mk b/scripts/mk/buildopts.mk
index 420b6359c..c087ad3a4 100644
--- a/scripts/mk/buildopts.mk
+++ b/scripts/mk/buildopts.mk
@@ -5,5 +5,10 @@
 #
 #   DEB_BUILD_OPTION_PARALLEL: the argument for the parallel=N option.
 
+ifndef dpkg_buildopts_mk_already_included
+dpkg_buildopts_mk_already_included :=
+
 DEB_BUILD_OPTION_PARALLEL := $(patsubst parallel=%,%,\
                                $(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+
+endif
diff --git a/scripts/mk/buildtools.mk b/scripts/mk/buildtools.mk
index 02c16ec92..ac9809c36 100644
--- a/scripts/mk/buildtools.mk
+++ b/scripts/mk/buildtools.mk
@@ -26,6 +26,9 @@
 # The variables are not exported by default. This can be changed by
 # defining DPKG_EXPORT_BUILDTOOLS.
 
+ifndef dpkg_buildtool_mk_already_included
+dpkg_buildtool_mk_already_included :=
+
 dpkg_datadir ?= $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
 include $(dpkg_datadir)/architecture.mk
 
@@ -76,3 +79,5 @@ $(eval $(call dpkg_buildtool_setvar,AR,ar))
 $(eval $(call dpkg_buildtool_setvar,RANLIB,ranlib))
 $(eval $(call dpkg_buildtool_setvar,PKG_CONFIG,pkg-config))
 $(eval $(call dpkg_buildtool_setvar,QMAKE,qmake))
+
+endif
diff --git a/scripts/mk/pkg-info.mk b/scripts/mk/pkg-info.mk
index 27e16c50c..21ed26b36 100644
--- a/scripts/mk/pkg-info.mk
+++ b/scripts/mk/pkg-info.mk
@@ -15,6 +15,8 @@
 #     If it is undefined, the date of the latest changelog entry is used.
 #     In both cases, the value is exported.
 
+ifndef dpkg_pkg_info_mk_already_included
+dpkg_pkg_info_mk_already_included :=
 
 # This variable is only expanded on demand, and we ensure that it
 # happens at most once..
@@ -33,6 +35,8 @@ dpkg-parsechangelog_sed := \
     $$(eval DEB_DISTRIBUTION              := \1)/p
 
 ifdef SOURCE_DATE_EPOCH
+  # dpkg-buildpackage exports SOURCE_DATE_EPOCH.
+
   # Only parse the changelog if a variable is actually used,
   # but then replace each recursive definition with a non-recursive one
   # (and of course return the asked value).
@@ -53,3 +57,5 @@ else
 endif
 
 export SOURCE_DATE_EPOCH
+
+endif
diff --git a/scripts/mk/vendor.mk b/scripts/mk/vendor.mk
index f7c61bf6f..d6050d965 100644
--- a/scripts/mk/vendor.mk
+++ b/scripts/mk/vendor.mk
@@ -32,6 +32,9 @@
 #     ...
 #   endif
 
+ifndef dpkg_vendor_mk_already_included
+dpkg_vendor_mk_already_included :=
+
 dpkg_late_eval ?= $(or $(value DPKG_CACHE_$(1)),$(eval DPKG_CACHE_$(1) := $(shell $(2)))$(value DPKG_CACHE_$(1)))
 
 DEB_VENDOR = $(call dpkg_late_eval,DEB_VENDOR,dpkg-vendor --query Vendor)
@@ -41,3 +44,5 @@ dpkg_vendor_derives_from_v0 = dpkg-vendor --derives-from $(1) && echo yes || ech
 dpkg_vendor_derives_from_v1 = $(shell $(dpkg_vendor_derives_from_v0))
 
 dpkg_vendor_derives_from ?= $(dpkg_vendor_derives_from_v0)
+
+endif
-- 
2.30.2

