Skip to content

Commit 9956a6d

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 9956a6d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

test/mk/config.mk

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

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

8896
ifeq ($(AUTO),1)
8997
include test/mk/auto.mk
@@ -98,6 +106,14 @@ CONFIG := $(BUILD_DIR)/config.mk
98106

99107
-include $(CONFIG)
100108

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

0 commit comments

Comments
 (0)