Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 446)
+++ trunk/kBuild/footer.kmk	(revision 447)
@@ -43,4 +43,19 @@
 	$(INSTALLS)    $(INSTALLS.$(BUILD_TARGET)) \
 	$(OTHERS)      $(OTHERS.$(BUILD_TARGET))
+
+# all $(BUILD_TARGET) targets.
+_ALL_BUILD_TARGET_TARGETS += \
+	$(BLDPROGS)    $(BLDPROGS.$(BUILD_PLATFORM)) \
+	$(LIBRARIES)   $(LIBRARIES.$(BUILD_TARGET)) \
+	$(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
+	$(DLLS)        $(DLLS.$(BUILD_TARGET)) \
+	$(PROGRAMS)    $(PROGRAMS.$(BUILD_TARGET)) \
+	$(SYSMODS)     $(SYSMODS.$(BUILD_TARGET)) \
+	$(INSTALLS)    $(INSTALLS.$(BUILD_TARGET)) \
+	$(OTHERS)      $(OTHERS.$(BUILD_TARGET))
+
+# all $(BUILD_TARGET) targets.
+_ALL_BUILD_PLATFORM_TARGETS += \
+	$(BLDPROGS)    $(BLDPROGS.$(BUILD_PLATFORM))
 
 # dependency files.
@@ -218,12 +233,15 @@
 # @param    $(prop)     Property name
 # @param    $(target)   Target name.
+# @param    $(bld_trg)  Build target name.
 define def_inherit_defaults_one
 ifndef $(target)_$(prop)
-ifndef $(target)_$(prop).$(BUILD_TARGET)
+ifndef $(target)_$(prop).$(bld_trg)
 ifdef $(prop)
 $$(eval $(target)_$(prop) := $($(prop)))
-endif
-ifdef $(prop).$(BUILD_TARGET)
-$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(prop).$(BUILD_TARGET)))
+#$ (warning dbg idefone: $(target)_$(prop):=$($(prop)))
+endif
+ifdef $(prop).$(bld_trg)
+$$(eval $(target)_$(prop).$(bld_trg) := $($(prop).$(bld_trg)))
+#$ (warning dbg idefone: $(target)_$(prop).$(bld_trg) := $($(prop).$(bld_trg)))
 endif
 endif
@@ -235,11 +253,12 @@
 # is inherited from the default properties.
 # @param    $(target)	Target name
+# @param    $(bld_trg)  Build target name.
 #
 define def_inherit_defaults
 ifdef $(target)_TEMPLATE
-ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(BUILD_TARGET))),)
+ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(bld_trg))),)
 $$(foreach prop,TOOL, $$(eval $$(def_inherit_defaults_one)))
 endif
-ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(BUILD_TARGET))),)
+ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(bld_trg))),)
 $$(foreach prop,SDKS, $$(eval $$(def_inherit_defaults_one)))
 endif
@@ -250,5 +269,8 @@
 # Inherit default properties.
 # !!!!!!THIS IS MESSY AND NOT NECESSARY!!!!!!
-$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_defaults)))
+#bld_trg := $(BUILD_TARGET)
+#$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(def_inherit_defaults)))
+#bld_trg := $(BUILD_PLATFORM)
+#$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(def_inherit_defaults)))
 
 
@@ -264,8 +286,8 @@
 endif
 endif
-ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
-ifndef $(target)_$(prop).$(BUILD_TARGET)
-#$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
-$(target)_$(prop).$(BUILD_TARGET) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
+ifndef $(target)_$(prop).$(bld_trg)
+#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
+$(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
 endif
 endif
@@ -284,8 +306,8 @@
 endif
 endif
-ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
-ifndef $(target)_$(prop).$(BUILD_TARGET)
-#$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
-$(target)_$(prop).$(BUILD_TARGET) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
+ifndef $(target)_$(prop).$(bld_trg)
+#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
+$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
 endif
 endif
@@ -305,15 +327,15 @@
 $(target)_$(prop).$(BUILD_TYPE) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
 endif
-ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
-#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
-$(target)_$(prop).$(BUILD_TARGET) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
-endif
-ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
-#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
-$(target)_$(prop).$(BUILD_TARGET_CPU) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
-endif
-ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
-#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
-$(target)_$(prop).$(BUILD_TARGET_ARCH) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
+#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
+$(target)_$(prop).$(bld_trg) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
+endif
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
+#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
+$(target)_$(prop).$(bld_trg_cpu) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
+endif
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
+#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
+$(target)_$(prop).$(bld_trg_arch) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
 endif
 endef
@@ -322,11 +344,28 @@
 # @param    $(target)    Target name.
 define def_inherit_template
+# Inherit any default template.
+ifdef TEMPLATE
+ifeq ($($(target)_TEMPLATE),)
+$(eval $(target)_TEMPLATE:=$(TEMPLATE))
+endif
+endif
+# Expand the template if specified.
+ifneq ($($(target)_TEMPLATE),)
 $(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
 $(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
 $(foreach prop,$(PROPS_ACCUMULATE),$(eval $(def_inherit_template_one_accumulate))) # += works fine (better) without value.
+endif
 endef
 
 # Inherit template properties
-$(foreach target, $(ALL_TARGETS),$(eval $(value def_inherit_template)))
+bld_trg := $(BUILD_TARGET)
+bld_trg_arch := $(BUILD_TARGET_ARCH)
+bld_trg_cpu := $(BUILD_TARGET_CPU)
+$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
+
+bld_trg := $(BUILD_PLATFORM)
+bld_trg_arch := $(BUILD_PLATFORM_ARCH)
+bld_trg_cpu := $(BUILD_PLATFORM_CPU)
+$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
 
 
