Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 78)
+++ trunk/kBuild/footer.kmk	(revision 79)
@@ -66,10 +66,23 @@
 # @param    $2      normalized main target
 # @param    $3      tooltype
-_SOURCE_TOOL = $(strip $(firstword $($1_$2_$(3)TOOL) $($1_$2_TOOL) $($1_$(3)TOOL) $($1_TOOL) $($2_$(3)TOOL) $($2_TOOL) $($(3)TOOL) $(TOOL) ))
+_SOURCE_TOOL = $(strip $(firstword \
+	$($1_$2_$(3)TOOL.$(BUILD_TARGET)) 	$($1_$2_TOOL.$(BUILD_TARGET)) \
+	$($1_$2_$(3)TOOL) $($1_$2_TOOL) \
+	$($1_$(3)TOOL.$(BUILD_TARGET)) $($1_TOOL.$(BUILD_TARGET)) \
+	$($1_$(3)TOOL) $($1_TOOL) \
+	$($2_$(3)TOOL.$(BUILD_TARGET)) $($2_TOOL.$(BUILD_TARGET)) \
+	$($2_$(3)TOOL) $($2_TOOL) \
+	$($(3)TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET)) \
+	$($(3)TOOL) $(TOOL) ))
 
 ## Figure out the tool for a target.
 # @param    $1 		normalized target.
 # @param    $2      tooltype.
-_TARGET_TOOL = $(strip $(firstword $($(1)_$(2)TOOL) $($(1)_TOOL) $($(2)TOOL) $(TOOL) ))
+_TARGET_TOOL = $(strip $(firstword \
+	$($(1)_$(2)TOOL.$(BUILD_TARGET)) $($(1)_$(2)TOOL) \
+	$($(1)_TOOL.$(BUILD_TARGET)) $($(1)_TOOL) \
+	$($(2)TOOL) $($(2)TOOL.$(BUILD_TARGET)) \
+	$(TOOL.$(BUILD_TARGET)) $(TOOL) \
+	))
 
 ## Figure out where to put object files.
@@ -151,4 +164,9 @@
 endif
 endif
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
+ifndef $(target)_$(prop).$(BUILD_TARGET)
+$(eval $(target)_$(prop).$(BUILD_TARGET) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
+endif
+endif
 endef
 
@@ -160,5 +178,13 @@
 $(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
 endif
-#$ (warning 1b $(target)_$(prop)=$($(target)_$(prop)) org=$(origin $(target)_$(prop))  TEMPLATE_$($(target)_TEMPLATE)_$(prop)=$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) org=$(origin TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
+$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
+endif
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
+$(eval $(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)))
+endif
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
+$(eval $(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)))
+endif
 endef
 
@@ -166,5 +192,5 @@
 # @param    $(target)    Target name.
 define def_inherit_template
-$(foreach prop,TOOL ARTOOL CTOOL CXXTOOL ASTOOL\
+$(foreach prop, TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL\
 	,$(eval $(def_inherit_template_one)))
 $(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS\
@@ -182,9 +208,15 @@
 define def_tools_target_source
 $(foreach tool,\
+	$($(source)_TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET))\
 	$($(source)_TOOL) $($(target)_$(source)_TOOL)\
+	$($(source)_CTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CTOOL.$(BUILD_TARGET))\
 	$($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
+	$($(source)_CXXTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CXXTOOL.$(BUILD_TARGET))\
 	$($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
+	$($(source)_ASTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ASTOOL.$(BUILD_TARGET))\
 	$($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
+	$($(source)_ARTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ARTOOL.$(BUILD_TARGET))\
 	$($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
+	$($(source)_LDTOOL.$(BUILD_TARGET)) $($(target)_$(source)_LDTOOL.$(BUILD_TARGET))\
 	$($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
 	,$(eval _TOOLS += $(tool)))
@@ -192,11 +224,17 @@
 define def_tools_target
 $(foreach tool,\
+	$($(target)_TOOL.$(BUILD_TARGET))\
 	$($(target)_TOOL)\
+	$($(target)_CTOOL.$(BUILD_TARGET))\
 	$($(target)_CTOOL)\
+	$($(target)_CXXTOOL.$(BUILD_TARGET))\
 	$($(target)_CXXTOOL)\
+	$($(target)_ASTOOL.$(BUILD_TARGET))\
 	$($(target)_ASTOOL)\
+	$($(target)_ARTOOL.$(BUILD_TARGET))\
 	$($(target)_ARTOOL)\
+	$($(target)_LDTOOL.$(BUILD_TARGET))\
 	$($(target)_LDTOOL)\
-	, $(eval _TOOLS += $(tool)))
+	,$(eval _TOOLS += $(tool)))
 $(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
 endef
@@ -205,4 +243,5 @@
 
 define def_tools_include
+$(warning tool=$(tool))
 ifndef TOOL_$(tool)
 include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
