From c5c0e7a90eb37d75b8bbca3cac412df1cb1ab911 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas@debian.org>
Date: Mon, 29 Jul 2019 14:38:32 +0200
Subject: [PATCH 02/11] scripts/mk: protect files against double inclusion

Architecture.mk is included by default.mk the by buildtools.mk.
Buildapi.mk is included by default.mk and vendor.mk.
---
 scripts/mk/architecture.mk | 5 +++++
 scripts/mk/buildapi.mk     | 5 +++++
 scripts/mk/buildflags.mk   | 6 ++++++
 scripts/mk/buildopts.mk    | 5 +++++
 scripts/mk/buildtools.mk   | 5 +++++
 scripts/mk/default.mk      | 5 +++++
 scripts/mk/pkg-info.mk     | 5 +++++
 scripts/mk/vendor.mk       | 5 +++++
 8 files changed, 41 insertions(+)

diff --git a/scripts/mk/architecture.mk b/scripts/mk/architecture.mk
index c11cada16..1565903c4 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 /usr/share/dpkg/architecture.mk_included
+/usr/share/dpkg/architecture.mk_included = yes
+
 dpkg_lazy_eval ?= $$(or $$(value DPKG_CACHE_$(1)),$$(eval DPKG_CACHE_$(1) := $$(shell $(2)))$$(value DPKG_CACHE_$(1)))
 
 dpkg_architecture_setvar = export $(1) ?= $(call dpkg_lazy_eval,$(1),dpkg-architecture -q$(1))
@@ -9,3 +12,5 @@ dpkg_architecture_setvar = export $(1) ?= $(call dpkg_lazy_eval,$(1),dpkg-archit
 $(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,\
     $(eval $(call dpkg_architecture_setvar,DEB_$(machine)_$(var)))))
+
+endif # ifndef /usr/share/dpkg/architecture.mk_included
diff --git a/scripts/mk/buildapi.mk b/scripts/mk/buildapi.mk
index 668e325c8..cb68d91c2 100644
--- a/scripts/mk/buildapi.mk
+++ b/scripts/mk/buildapi.mk
@@ -1,5 +1,8 @@
 # This Makefile fragment (since dpkg 1.22.0) handles the build API.
 
+ifndef /usr/share/dpkg/buildapi.mk_included
+/usr/share/dpkg/buildapi.mk_included = yes
+
 # Default API level when not set.
 DPKG_BUILD_API ?= $(shell dpkg-buildapi)
 
@@ -7,3 +10,5 @@ DPKG_BUILD_API ?= $(shell dpkg-buildapi)
 # complexity given no integer operators, given that we currently have to
 # fetch the build API level anyway.
 dpkg_build_api_ge = $(shell test "$(DPKG_BUILD_API)" -ge "$(1)" && echo yes)
+
+endif # ifndef /usr/share/dpkg/buildapi.mk_included
diff --git a/scripts/mk/buildflags.mk b/scripts/mk/buildflags.mk
index 4b8a3d8c4..0fb9f8e91 100644
--- a/scripts/mk/buildflags.mk
+++ b/scripts/mk/buildflags.mk
@@ -28,6 +28,10 @@
 # You can also export them in the environment by setting
 # DPKG_EXPORT_BUILDFLAGS to a non-empty value.
 #
+
+ifndef /usr/share/dpkg/buildflags.mk_included
+/usr/share/dpkg/buildflags.mk_included = yes
+
 # This list is kept in sync with the default set of flags returned
 # by dpkg-buildflags.
 
@@ -77,3 +81,5 @@ $(foreach flag,$(DPKG_BUILDFLAGS_LIST),\
 ifdef DPKG_EXPORT_BUILDFLAGS
   export $(DPKG_BUILDFLAGS_LIST)
 endif
+
+endif # ifndef /usr/share/dpkg/buildflags.mk_included
diff --git a/scripts/mk/buildopts.mk b/scripts/mk/buildopts.mk
index c95777719..2aa65f5d0 100644
--- a/scripts/mk/buildopts.mk
+++ b/scripts/mk/buildopts.mk
@@ -5,6 +5,11 @@
 #
 #   DEB_BUILD_OPTION_PARALLEL: the argument for the parallel=N option.
 
+ifndef /usr/share/dpkg/buildopts.mk_included
+/usr/share/dpkg/buildopts.mk_included = yes
+
 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
   DEB_BUILD_OPTION_PARALLEL = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
 endif
+
+endif # ifndef /usr/share/dpkg/buildopts.mk_included
diff --git a/scripts/mk/buildtools.mk b/scripts/mk/buildtools.mk
index 7c6732210..bbf4e799c 100644
--- a/scripts/mk/buildtools.mk
+++ b/scripts/mk/buildtools.mk
@@ -25,6 +25,9 @@
 # The variables are not exported by default. This can be changed by
 # defining DPKG_EXPORT_BUILDTOOLS.
 
+ifndef /usr/share/dpkg/buildtools.mk_included
+/usr/share/dpkg/buildtools.mk_included = yes
+
 dpkg_datadir = $(srcdir)/mk
 include $(dpkg_datadir)/architecture.mk
 
@@ -74,3 +77,5 @@ $(eval $(call dpkg_buildtool_setvar,AR,ar))
 $(eval $(call dpkg_buildtool_setvar,RANLIB,ranlib))
 $(eval $(call dpkg_buildtool_setvar,PKG_CONFIG,pkgconf))
 $(eval $(call dpkg_buildtool_setvar,QMAKE,qmake))
+
+endif # ifndef /usr/share/dpkg/buildtools.mk_included
diff --git a/scripts/mk/default.mk b/scripts/mk/default.mk
index 0b2fd4aca..60c85df2a 100644
--- a/scripts/mk/default.mk
+++ b/scripts/mk/default.mk
@@ -1,6 +1,9 @@
 # This Makefile fragment (since dpkg 1.16.1) includes all the Makefile
 # fragments that define variables that can be useful within debian/rules.
 
+ifndef /usr/share/dpkg/default.mk_included
+/usr/share/dpkg/default.mk_included = yes
+
 dpkg_datadir = $(srcdir)/mk
 include $(dpkg_datadir)/architecture.mk
 include $(dpkg_datadir)/buildapi.mk
@@ -11,3 +14,5 @@ include $(dpkg_datadir)/buildflags.mk
 include $(dpkg_datadir)/buildopts.mk
 include $(dpkg_datadir)/pkg-info.mk
 include $(dpkg_datadir)/vendor.mk
+
+endif # /usr/share/dpkg/default.mk_included
diff --git a/scripts/mk/pkg-info.mk b/scripts/mk/pkg-info.mk
index bccde2317..144c0d758 100644
--- a/scripts/mk/pkg-info.mk
+++ b/scripts/mk/pkg-info.mk
@@ -13,6 +13,9 @@
 #     specified by <https://reproducible-builds.org/specs/source-date-epoch/>
 #     (since dpkg 1.18.8).
 
+ifndef /usr/share/dpkg/pkg-info.mk_included
+/usr/share/dpkg/pkg-info.mk_included = yes
+
 dpkg_late_eval ?= $(or $(value DPKG_CACHE_$(1)),$(eval DPKG_CACHE_$(1) := $(shell $(2)))$(value DPKG_CACHE_$(1)))
 
 DEB_SOURCE = $(call dpkg_late_eval,DEB_SOURCE,dpkg-parsechangelog -SSource)
@@ -25,3 +28,5 @@ DEB_DISTRIBUTION = $(call dpkg_late_eval,DEB_DISTRIBUTION,dpkg-parsechangelog -S
 SOURCE_DATE_EPOCH ?= $(call dpkg_late_eval,SOURCE_DATE_EPOCH,dpkg-parsechangelog -STimestamp)
 
 export SOURCE_DATE_EPOCH
+
+endif # ifndef /usr/share/dpkg/pkg-info.mk_included
diff --git a/scripts/mk/vendor.mk b/scripts/mk/vendor.mk
index 8bdaa235a..03082dc7d 100644
--- a/scripts/mk/vendor.mk
+++ b/scripts/mk/vendor.mk
@@ -33,6 +33,9 @@
 #     ...
 #   endif
 
+ifndef /usr/share/dpkg/vendor.mk_included
+/usr/share/dpkg/vendor.mk_included = yes
+
 dpkg_datadir = $(srcdir)/mk
 include $(dpkg_datadir)/buildapi.mk
 
@@ -49,3 +52,5 @@ dpkg_vendor_derives_from ?= $(dpkg_vendor_derives_from_v1)
 else
 dpkg_vendor_derives_from ?= $(dpkg_vendor_derives_from_v0)
 endif
+
+endif # ifndef /usr/share/dpkg/vendor.mk_included
-- 
2.39.2

