Makefile: Fix dependency tracking for linker scripts

When the memlayout framework was initially developed in the Chromium OS
tree, the accompanying build system changes unified handling for all
file types (including .ld and .asl) in a single template. This had the
advantage that compiler invocation options pertaining to the build
system itself could be centralized in a single place.

On upstreaming this was reverted for some reason, keeping the old
special handling for ASL files and writing a custom template for LD. The
duplicated compiler invocation code for the latter was missing the -MMD
flag required for dependency tracking. It was also missing at least one
$-sign which causes the $(<class>-ld-ccopts) variable to be evaluated at
the time it's parsing the template generator (before the subdirectory
pass). This should not cause any issues with current code, but all the
ccopts variables were meant to be evaluated after the subdirectory pass
(so things like archs and SoCs can manipulate them if needed), so this
patch fixes both issues.

TEST='make; touch src/soc/.../memlayout.ld; make' re-links all stages
and includes the changed symbol addresses from the new address map.

Change-Id: I4be458112908380268229b3220cfa0062add5c5d
Signed-off-by: Patrick Georgi <>
Original-Commit-Id: e8a36f994ef6a819ded7bf6b39b1e0fce8e52279
Original-Change-Id: If2310b46b53d888975cb2113edce20a896be39ef
Original-Signed-off-by: Julius Werner <>
Original-Reviewed-by: Aaron Durbin <>
Original-Reviewed-by: Patrick Georgi <>
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <>
Tested-by: Raptor Engineering Automated Test Stand <>
diff --git a/ b/
index 984c886..8be9b5a 100644
--- a/
+++ b/
@@ -169,8 +169,7 @@
 de$(EMPTY)fine $(1)-objs_ld_template
 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
 	@printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
-	$$(CC_$(1)) $$(CPPFLAGS_$(1)) $($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h $$$$< > $$$$@.tmp
-	mv $$$$@.tmp $$$$@
+	$$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<