summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2016-01-18 16:54:26 +0100
committerNicolas Schodet2019-10-07 00:44:57 +0200
commit5b3a34d644bbedaf39efdf4a1d99d413eb986146 (patch)
tree411f71fe0ecb0014733c8e1be40c3e4b6971b997
parent242d90c63e56d4cbac9a33a986f40f01f483edb0 (diff)
build: save link flags and rebuild as needed
-rw-r--r--build/arch.mk12
-rw-r--r--build/macros.mk17
2 files changed, 26 insertions, 3 deletions
diff --git a/build/arch.mk b/build/arch.mk
index 33b8379..6b6410b 100644
--- a/build/arch.mk
+++ b/build/arch.mk
@@ -38,10 +38,14 @@ all.$1: elf.$1
elf.$1: $$($1_ELFS)
define $1_PROG_template
-$$1.$1$$$$($1_ELF_SUFFIX): $$$$(patsubst %,$$(OBJDIR)/%.$1.o,\
+$1_$$1_LINKFLAGS = $$$$($1_CFLAGS) $$$$($1_CXXFLAGS) $$$$($1_LDFLAGS)
+$$(call cmddep,$1_$$1_LINKFLAGS,$$$$(OBJDIR)/$$1.$1.linkflags)
+$1_$$1_OBJECTS = $$$$(patsubst %,$$(OBJDIR)/%.$1.o,\
$$$$(call filter_sources,$1,$$$$($$1_SOURCES)))
+$$1.$1$$$$($1_ELF_SUFFIX): $$$$($1_$$1_OBJECTS) $$$$(OBJDIR)/$$1.$1.linkflags
@echo "LINK [$1] $$$$@"
- $$$$Q$$$$($1_LINK.$$(call iscxx,$$($$1_SOURCES))) $$$$^ $$$$($1_LDLIBS) -o $$$$@
+ $$$$Q$$$$($1_LINK.$$(call iscxx,$$($$1_SOURCES))) $$$$($1_$$1_OBJECTS) \
+ $$$$($1_LDLIBS) -o $$$$@
endef
$$(foreach prog,$$($1_PROGS),$$(eval $$(call $1_PROG_template,$$(prog))))
@@ -169,9 +173,11 @@ define arch_misc_rules
clean: clean.$1
clean.$1:
- @echo rm -f '$$(OBJDIR)/.../*.$1.[od]' $$($1_ELFS) $$($1_EXTRA_CLEAN)
+ @echo rm -f '$$(OBJDIR)/.../*.$1.[od]' '$$(OBJDIR)/*.$1.linkflags' \
+ $$($1_ELFS) $$($1_EXTRA_CLEAN)
$$Qrm -f $$(patsubst %,$$(OBJDIR)/%.$1.[od],\
$$(call filter_sources,$1,$$(ALL_SOURCES))) \
+ $$($1_PROGS:%=$(OBJDIR)/%.$1.linkflags) \
$$($1_ELFS) $$($1_EXTRA_CLEAN)
endef
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))