summaryrefslogtreecommitdiff
path: root/build/macros.mk
diff options
context:
space:
mode:
authorNicolas Schodet2016-01-18 16:54:26 +0100
committerNicolas Schodet2019-10-07 00:44:57 +0200
commit5b3a34d644bbedaf39efdf4a1d99d413eb986146 (patch)
tree411f71fe0ecb0014733c8e1be40c3e4b6971b997 /build/macros.mk
parent242d90c63e56d4cbac9a33a986f40f01f483edb0 (diff)
build: save link flags and rebuild as needed
Diffstat (limited to 'build/macros.mk')
-rw-r--r--build/macros.mk17
1 files changed, 17 insertions, 0 deletions
diff --git a/build/macros.mk b/build/macros.mk
index f77159b..fd6c587 100644
--- a/build/macros.mk
+++ b/build/macros.mk
@@ -10,6 +10,10 @@ ifdefined = $(if $(filter undefined,$(origin $1)),$2)
# $(call defval,A,B)
defval = $(if $(filter undefined,$(origin $1)),$2,$($1))
+# Return words which are in one argument but not in the other one.
+# $(call diff,A,B)
+diff = $(strip $(filter-out $1,$2) $(filter-out $2, $1))
+
# Filter out source file for other targets, return basenames.
# $(call filter_sources,TARGET,SOURCES)
filter_sources = $(call filter_sources_sub,$1,$(basename $2))
@@ -49,6 +53,19 @@ $(foreach target,$(TARGETS),\
endef
source_specific = $(eval $(call source_specific_sub,$1,$2,$3))
+# Handle command line changes.
+# The given variable is saved in savefile, which should be included as target
+# dependencies. If variable content is not the same as in previous build, the
+# savefile is made phony and the target is rebuilt.
+# $(call cmddep,VAR,savefile)
+define cmddep
+-include $2
+.PHONY: $$(if $$(call diff,$$($1_OLD),$$($1)),$2)
+$2:
+ $$(call mkdir_if_needed,$$@)
+ @echo '$1_OLD = $$($1)' > $$@
+endef
+
# Evaluate subvariables.
# $(call foreachsub,LIST,PREFIX)
foreachsub = $(foreach v,$1,$($(subst /,_,$v)_$2))