Skip to content

Commit 6dd90f5

Browse files
AndreasL-series
authored andcommitted
Makefile: keep track of environment variables
Previously, only values variables passed as Makefile variables (make VAR=value) triggered rebuilds when changed. Now environment variables (VAR=value make) are also tracked. Signed-off-by: Andreas Hatziiliou <andreas.hatziiliou@savoirfairelinux.com>
1 parent db475c1 commit 6dd90f5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

test/mk/config.mk

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,19 @@ endif
8080
# Include retained variables #
8181
##############################
8282

83+
84+
RETAINED_VARS := CROSS_PREFIX CYCLES OPT AUTO
85+
86+
# Capture values of environment variables before setting defaults,
87+
# this ensures we can detect when they change in order to trigger a rebuild.
88+
define CAPTURE_VAR
89+
$(1)_FROM_ENV := $$($(1))
90+
endef
91+
$(foreach var,$(RETAINED_VARS),$(eval $(call CAPTURE_VAR,$(var))))
92+
8393
AUTO ?= 1
8494
CYCLES ?=
8595
OPT ?= 1
86-
RETAINED_VARS := CROSS_PREFIX CYCLES OPT AUTO
8796

8897
ifeq ($(AUTO),1)
8998
include test/mk/auto.mk
@@ -98,6 +107,14 @@ CONFIG := $(BUILD_DIR)/config.mk
98107

99108
-include $(CONFIG)
100109

110+
# After including the cached config, restore environment/command-line values if they were set
111+
define RESTORE_VAR
112+
ifneq ($$($(1)_FROM_ENV),)
113+
$(1) := $$($(1)_FROM_ENV)
114+
endif
115+
endef
116+
$(foreach var,$(RETAINED_VARS),$(eval $(call RESTORE_VAR,$(var))))
117+
101118
$(CONFIG):
102119
@echo " GEN $@"
103120
$(Q)[ -d $(@D) ] || mkdir -p $(@D)

0 commit comments

Comments
 (0)