Skip to content

Commit c53b96e

Browse files
committed
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. rf.: #1150
1 parent a990502 commit c53b96e

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
@@ -78,9 +78,17 @@ endif
7878
# Include retained variables #
7979
##############################
8080

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

8593
BUILD_DIR ?= test/build
8694

@@ -91,6 +99,14 @@ CONFIG := $(BUILD_DIR)/config.mk
9199

92100
-include $(CONFIG)
93101

102+
# After including the cached config, restore environment/command-line values if they were set
103+
define RESTORE_VAR
104+
ifneq ($$($(1)_FROM_ENV),)
105+
$(1) := $$($(1)_FROM_ENV)
106+
endif
107+
endef
108+
$(foreach var,$(RETAINED_VARS),$(eval $(call RESTORE_VAR,$(var))))
109+
94110
$(CONFIG):
95111
@echo " GEN $@"
96112
$(Q)[ -d $(@D) ] || mkdir -p $(@D)

0 commit comments

Comments
 (0)