Index: unk/kBuild/config.kmk
===================================================================
--- /trunk/kBuild/config.kmk	(revision 352)
+++ 	(revision )
@@ -1,117 +1,0 @@
-# $Id$
-#
-# Base config for kBuild
-#
-# It is recommended to include this file in your config.kMk file and then
-# override any default options defined there. In addition you will have to
-# decide the location of the object directory in your config.kMk file, and
-# of course manage to find this file.
-#
-#
-# Copyright (c) 2003 knut st. osmundsen <bird-srcspam@anduin.net>
-#
-#
-# This file is part of kBuild.
-#
-# kBuild is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# kBuild is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with kBuild; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-#
-
-ifdef rewrite_me
-
-.ifndef __KBLD_config_kMk_
-__KBLD_config_kMk_ = 1
-
-#
-# Determin default target (if not set) / Check default target (if set)
-#
-.ifndef TARGET_MACHINE_TYPE
-## The TARGET_MACHINE_TYPE is a generalized machine type for the
-# default target machine. Current types are "UX" for UNIX like systems
-# and "PC" for PC like systems. PC like systems are DOS, OS/2, and Win32.
-# While the rest is UNIX like at the moment.
-.if ${MACHINE} == "ibmos2" || ${MACHINE} == "win32" || ${MACHINE} == "dos"
-TARGET_MACHINE_TYPE := PC
-.else
-TARGET_MACHINE_TYPE := UX
-.endif
-
-.elif ${TARGET_MACHINE_TYPE} != "UX" && ${TARGET_MACHINE_TYPE} != "PC"
-.error Invalid TARGET_MACHINE_TYPE define. Must be either UX or PC.
-.endif
-
-## @group Typical PC Suffixes
-# Note that suffixes includes the '.' if present.
-# @{
-SFX_EXE_PC      := .exe
-SFX_DLL_PC      := .dll
-SFX_DEF_PC      := .def
-SFX_RES_PC      := .res
-SFX_OBJ_PC      := .obj
-SFX_CLS_PC      := .class
-# @}
-
-## @group Typical UNIX Suffixes
-# Note that suffixes includes the '.' if present.
-# @{
-SFX_EXE_UX      :=
-SFX_DLL_UX      := .so
-SFX_OBJ_UX      := .o
-SFX_CLS_UX      := .class
-# @}
-
-
-## @group Default Target Suffixes.
-# @{
-## Executable Program.
-SFX_EXE         = ${SFX_EXE_${TARGET_MACHINE_TYPE}}
-## DLL/Shared Library.
-SFX_DLL         = ${SFX_DLL_${TARGET_MACHINE_TYPE}}
-## Object file.
-SFX_OBJ         = ${SFX_OBJ_${TARGET_MACHINE_TYPE}}
-## Resource object file (PC thingy).
-SFX_RES         = ${SFX_RES_${TARGET_MACHINE_TYPE}}
-## Definition (~=linkerscript) file (PC thingy).
-SFX_DEF         = ${SFX_RES_${TARGET_MACHINE_TYPE}}
-## Java class files
-SFX_CLS         = ${SFX_RES_${TARGET_MACHINE_TYPE}}
-## @}
-
-
-## @group Suffix lists used for transformations
-# @{
-## C source file suffixes
-SFXS_C          := .c
-## C++ source file suffixes
-SFXS_CXX        := .cpp .cxx .cc .c++
-## C/C++ header file suffixes (list)
-SFXS_H          := .h .hpp
-## Java source file suffixes
-SFXS_JAVA       := .java .jav
-## IDL source file suffixes
-SFXS_IDL        := .idl
-## @}
-
-
-## @group kBuild helper defines.
-# @{
-## The kBuild path.
-KBUILD_PATH     := $(MAKEFILE:H)
-## The rules file.
-KBUILD_RULEZ    := $(KBUILD_PATH)/rules.kMk
-## @}
-
-.endif
-endif
Index: /trunk/kBuild/footer.kmk
===================================================================
--- /trunk/kBuild/footer.kmk	(revision 352)
+++ /trunk/kBuild/footer.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild - File included at top of makefile.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -21,5 +21,5 @@
 # You should have received a copy of the GNU General Public License
 # along with kBuild; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite typetype0, Boston, MA  0sourcetargettargettarget-targettype07  USA
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 #
@@ -34,5 +34,5 @@
 
 # all targets.
-ALL_TARGETS := \
+ALL_TARGETS += \
 	$(BLDPROGS)    $(BLDPROGS.$(BUILD_PLATFORM)) \
 	$(LIBRARIES)   $(LIBRARIES.$(BUILD_TARGET)) \
@@ -41,4 +41,5 @@
 	$(PROGRAMS)    $(PROGRAMS.$(BUILD_TARGET)) \
 	$(SYSMODS)     $(SYSMODS.$(BUILD_TARGET)) \
+	$(INSTALLS)    $(INSTALLS.$(BUILD_TARGET)) \
 	$(OTHERS)      $(OTHERS.$(BUILD_TARGET))
 
@@ -50,4 +51,7 @@
 # required dependency file must add those output files to this variable.
 _OUT_FILES :=
+
+# Files which only requires cleaning up.
+_CLEAN_FILES :=
 
 # all of a type
@@ -58,5 +62,7 @@
 _PROGRAMS :=
 _SYSMODS  :=
-_DIRS     :=
+_INSTALLS :=
+_OTHERS   :=
+_DIRS     := $(PATH_TARGET)/
 _IMPORT_LIBS :=
 
@@ -64,10 +70,4 @@
 pass_prev :=
 
-
-# all objs of a specific target
-define def_objs_var
-_OBJS_$target :=
-endef
-$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
 
 #
@@ -136,4 +136,12 @@
 
 
+## Figure out the actual name of an installed file.
+# @param	$1		The file to install.
+# @param	$2		The target name.
+# @param	$3		The _INST value (can be empty).
+# @param	$4		The default directory to use when $3 is empty.
+_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
+
+
 #
 # Check syntax which leads to weird syntax errors.
@@ -165,5 +173,5 @@
 define def_templates_include
 ifndef TEMPLATE_$(template)
-include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
+include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
 endif
 endef
@@ -213,5 +221,5 @@
 
 
-## Inherit one template property in a accumulative manner.
+## Inherit one template property in a non-accumulative manner.
 # @param    $(prop)     Property name
 # @param    $(target)	Target name
@@ -220,12 +228,32 @@
 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
 ifndef $(target)_$(prop)
-#$$ (warning dbgtarget: $(target)_$(prop):='$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
-$$(target)_$$(prop) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop))
+$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
+#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
 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))
+#$ (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))
+endif
+endif
+endef
+
+## Inherit one template property in a non-accumulative manner, deferred expansion.
+# @param    1: $(prop)     Property name
+# @param    2: $(target)	Target name
+# @todo fix the precedence order for some properties.
+# @remark this define relies on double evaluation
+define def_inherit_template_one_deferred
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
+ifndef $(target)_$(prop)
+$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
+#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
+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))
 endif
 endif
@@ -237,38 +265,36 @@
 define def_inherit_template_one_accumulate
 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
-#$$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
-$$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
-#$$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
+#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
+$(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
+#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
 endif
 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
-#$$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
-$$(eval $(target)_$(prop).$(BUILD_TYPE) := $($(target)_$(prop).$(BUILD_TYPE)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)))
+#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
+$(target)_$(prop).$(BUILD_TYPE) := $($(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))
-$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
+#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
+$(target)_$(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))
-$$(eval $(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)))
+#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
+$(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)
-#$$ (warning dbg6: 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
-
+#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
+$(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
+endif
+endef
 
 ## Inherit template properties for on target.
 # @param    $(target)    Target name.
 define def_inherit_template
-$$(foreach prop, TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL INST NOINST\
-	,$$(eval $$(def_inherit_template_one)))
-$$(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS LDFLAGS LIBS LIBPATH \
-	        BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
-	,$$(eval $$(def_inherit_template_one_accumulate)))
-endef
+$(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 $(value def_inherit_template_one_accumulate)))
+endef
+
 # Inherit template properties
-$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_template)))
+$(foreach target, $(ALL_TARGETS),$(eval $(value def_inherit_template)))
 
 
@@ -278,46 +304,35 @@
 _TOOLS := $(TOOL)
 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)))
-endef
+$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
+	$($(source)_$(prop).$(BUILD_TARGET)) \
+	$($(target)_$(source)_$(prop).$(BUILD_TARGET)) \
+	$($(source)_$(prop)) \
+	$($(target)_$(source)_$(prop))))
+endef
+
 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)))
-$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TYPE)) \
-	, $(eval $(def_tools_target_source)))
-endef
-$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
+$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
+	$($(target)_$(prop).$(BUILD_TARGET)) \
+	$($(target)_$(prop))))
+$(foreach source, \
+	$($(target)_SOURCES.$(BUILD_TARGET)) \
+	$($(target)_SOURCES.$(BUILD_TYPE)) \
+	$($(target)_SOURCES) \
+	, $(eval $(value def_tools_target_source)))
+endef
+
+$(foreach target, $(ALL_TARGETS), $(eval $(value def_tools_target)))
 _TOOLS := $(sort $(_TOOLS))
 
 define def_tools_include
 ifndef TOOL_$(tool)
-include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
-endif
-endef
-$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
+TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
+ifeq ($(TOOL_$(tool)_KMK_FILE),)
+$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
+endif
+include $(TOOL_$(tool)_KMK_FILE)
+endif
+endef
+$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
 
 
@@ -342,12 +357,25 @@
 define def_sdks_include_one
 ifndef SDK_$(sdk)
-include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
-endif
-endef
-$(foreach sdk, $(_SDKS), $(eval $(def_sdks_include_one)))
+SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
+ifeq ($(SDK_$(sdk)_KMK_FILE),)
+$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
+endif
+include $(SDK_$(sdk)_KMK_FILE)
+endif
+endef
+$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
 
 #
 # Object processing.
 #
+
+## Generates the '::' rule for building all objects of a source file.
+# @param    $(obj)    The object file.
+define def_target_obj_rule
+$(basename $(notdir $(obj))).o::
+	+ $$(MAKE) -B -f $$(MAKEFILE) $(obj)
+$(basename $$(notdir $$(obj))).obj::
+	+ $$(MAKE) -B -f $$(MAKEFILE) $(obj)
+endef
 
 
@@ -366,9 +394,9 @@
 #$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
 
-$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
-$(eval outbase     := $(call _OBJECT_BASE,$(source),$(target)))
-$(eval PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase))))
-$(eval dirdep      := $(dir $(outbase)).dir_created)
-$(eval defs        :=\
+tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
+outbase     := $(call _OBJECT_BASE,$(source),$(target))
+PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
+dirdep      := $(call DIRDEP,$(dir $(outbase)))
+defs        :=\
 	$(TOOL_$(tool)_DEFS)\
 	$(TOOL_$(tool)_DEFS.$(bld_type))\
@@ -381,14 +409,14 @@
 				   $(SDKS.$(bld_type)) \
 				   $(SDKS),\
-	$(SDK_$(sdk)_DEFS)\
-	$(SDK_$(sdk)_DEFS.$(bld_type))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)DEFS)\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
+		$(SDK_$(sdk)_DEFS)\
+		$(SDK_$(sdk)_DEFS.$(bld_type))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)DEFS)\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
 	$(DEFS)\
 	$(DEFS.$(bld_type))\
@@ -404,14 +432,14 @@
 				   $($(target)_SDKS.$(bld_type)) \
 				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_DEFS)\
-	$(SDK_$(sdk)_DEFS.$(bld_type))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)DEFS)\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
+		$(SDK_$(sdk)_DEFS)\
+		$(SDK_$(sdk)_DEFS.$(bld_type))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)DEFS)\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
 	$($(target)_DEFS)\
 	$($(target)_DEFS.$(bld_type))\
@@ -427,14 +455,14 @@
 				   $($(source)_SDKS.$(bld_type)) \
 				   $($(source)_SDKS),\
-	$(SDK_$(sdk)_DEFS)\
-	$(SDK_$(sdk)_DEFS.$(bld_type))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)DEFS)\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
+		$(SDK_$(sdk)_DEFS)\
+		$(SDK_$(sdk)_DEFS.$(bld_type))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)DEFS)\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
 	$($(source)_DEFS)\
 	$($(source)_DEFS.$(bld_type))\
@@ -450,14 +478,14 @@
 				   $($(target)_$(source)_SDKS.$(bld_type)) \
 				   $($(target)_$(source)_SDKS),\
-	$(SDK_$(sdk)_DEFS)\
-	$(SDK_$(sdk)_DEFS.$(bld_type))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)DEFS)\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
+		$(SDK_$(sdk)_DEFS)\
+		$(SDK_$(sdk)_DEFS.$(bld_type))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)DEFS)\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
 	$($(target)_$(source)_DEFS)\
 	$($(target)_$(source)_DEFS.$(bld_type))\
@@ -469,7 +497,6 @@
 	$($(target)_$(source)_$(type)DEFS.$(bld_trg))\
 	$($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
-	$($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))\
-	)
-$(eval incs        :=\
+	$($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
+incs        :=\
 	$($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
 	$($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
@@ -485,14 +512,14 @@
 				   $($(target)_$(source)_SDKS.$(bld_type)) \
 				   $($(target)_$(source)_SDKS),\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)INCS)\
-	$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_INCS.$(bld_trg))\
-	$(SDK_$(sdk)_INCS.$(bld_type))\
-	$(SDK_$(sdk)_INCS))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)INCS)\
+		$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_INCS.$(bld_trg))\
+		$(SDK_$(sdk)_INCS.$(bld_type))\
+		$(SDK_$(sdk)_INCS))\
 	$($(source)_$(type)INCS.$(bld_trg_cpu))\
 	$($(source)_$(type)INCS.$(bld_trg_arch))\
@@ -508,14 +535,14 @@
 				   $($(source)_SDKS.$(bld_type)) \
 				   $($(source)_SDKS),\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)INCS)\
-	$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_INCS.$(bld_trg))\
-	$(SDK_$(sdk)_INCS.$(bld_type))\
-	$(SDK_$(sdk)_INCS))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)INCS)\
+		$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_INCS.$(bld_trg))\
+		$(SDK_$(sdk)_INCS.$(bld_type))\
+		$(SDK_$(sdk)_INCS))\
 	$($(target)_$(type)INCS.$(bld_trg_cpu))\
 	$($(target)_$(type)INCS.$(bld_trg_arch))\
@@ -531,14 +558,14 @@
 				   $($(target)_SDKS.$(bld_type)) \
 				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)INCS)\
-	$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_INCS.$(bld_trg))\
-	$(SDK_$(sdk)_INCS.$(bld_type))\
-	$(SDK_$(sdk)_INCS))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)INCS)\
+		$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_INCS.$(bld_trg))\
+		$(SDK_$(sdk)_INCS.$(bld_type))\
+		$(SDK_$(sdk)_INCS))\
 	$(INCS.$(bld_trg_cpu))\
 	$(INCS.$(bld_trg_arch))\
@@ -549,21 +576,20 @@
 				   $(SDKS.$(bld_type)) \
 				   $(SDKS),\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
-	$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
-	$(SDK_$(sdk)_$(type)INCS)\
-	$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_INCS.$(bld_trg))\
-	$(SDK_$(sdk)_INCS.$(bld_type))\
-	$(SDK_$(sdk)_INCS))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
+		$(SDK_$(sdk)_$(type)INCS.$(bld_type))\
+		$(SDK_$(sdk)_$(type)INCS)\
+		$(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_INCS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_INCS.$(bld_trg))\
+		$(SDK_$(sdk)_INCS.$(bld_type))\
+		$(SDK_$(sdk)_INCS))\
 	$(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
 	$(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
 	$(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
 	$(TOOL_$(tool)_$(type)INCS.$(bld_type))\
-	$(TOOL_$(tool)_$(type)INCS)\
-	)
-$(eval flags        :=\
+	$(TOOL_$(tool)_$(type)INCS)
+flags        :=\
 	$(TOOL_$(tool)_$(type)FLAGS)\
 	$(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
@@ -590,7 +616,6 @@
 	$($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
 	$($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
-	$($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))\
-	)
-$(eval objsuff     := $(firstword \
+	$($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
+objsuff     := $(firstword \
 	$($(target)_$(source)_OBJSUFF.$(bld_trg))\
 	$($(target)_$(source)_OBJSUFF)\
@@ -601,26 +626,27 @@
 	$(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
 	$(TOOL_$(tool)_$(type)OBJSUFF)\
-	$(SUFF_OBJ)\
-	))
-$(eval obj         := $(outbase)$(objsuff))
-$(eval dep         := $(outbase)$(SUFF_DEP))
-$(eval deps        := \
+	$(SUFF_OBJ))
+obj         := $(outbase)$(objsuff)
+dep         := $(outbase)$(SUFF_DEP)
+deps        := \
 	$($(target)_$(source)_DEPS)\
-    $($(target)_$(source)_DEPS.$(bld_type))\
-    $($(target)_$(source)_DEPS.$(bld_trg))\
-    $($(target)_$(source)_DEPS.$(bld_trg_arch))\
-    $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
+	$($(target)_$(source)_DEPS.$(bld_type))\
+	$($(target)_$(source)_DEPS.$(bld_trg))\
+	$($(target)_$(source)_DEPS.$(bld_trg_arch))\
+	$($(target)_$(source)_DEPS.$(bld_trg_cpu))\
 	$($(source)_DEPS)\
 	$($(source)_DEPS.$(bld_type))\
 	$($(source)_DEPS.$(bld_trg))\
+	$($(source)_DEPS.$(bld_trg_arch))\
+	$($(source)_DEPS.$(bld_trg_cpu))\
 	$($(target)_DEPS)\
+	$($(target)_DEPS.$(bld_type))\
 	$($(target)_DEPS.$(bld_trg_arch))\
-	$($(target)_DEPS.$(bld_trg_cpu)))
+	$($(target)_DEPS.$(bld_trg_cpu))
 
 
 #$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
 ifndef TOOL_$(tool)_COMPILE_$(type)
-$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
-$$(warning kBuild: tools: \
+$(warning kBuild: tools: \
 	1 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
 	2 $($(target)_$(source)_$(type)TOOL) \
@@ -639,14 +665,14 @@
 	15 $(TOOL.$(bld_trg)) \
 	16 $(TOOL) )
-endif
+$(error kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
+endif
+
+# generate the rules
 $(eval $(TOOL_$(tool)_COMPILE_$(type)))
 
-$$(basename $$(notdir $$(obj))).o::
-	+ $$(MAKE) -B -f $$(MAKEFILE) $(obj)
-$$(basename $$(notdir $$(obj))).obj::
-	+ $$(MAKE) -B -f $$(MAKEFILE) $(obj)
-
-$(eval _OBJS_$(target) += $(obj))
-$(eval _DEPFILES       += $(dep))
+$(eval $(def_target_obj_rule))
+
+$(target)_OBJS_ += $(obj)
+_DEPFILES       += $(dep)
 
 endef
@@ -657,44 +683,181 @@
 #$ (warning def_target_sources)
 # C sources
-$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(def_target_source_c_cpp_asm)) ))
+type := C
+$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
+	,$(eval $(value def_target_source_c_cpp_asm)) )
 
 # C++ sources
-$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(def_target_source_c_cpp_asm)) ))
+type := CXX
+$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
+	,$(eval $(value def_target_source_c_cpp_asm)) )
 
 # ASM sources
-$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(def_target_source_c_cpp_asm)) ))
-endef
-
-
-#
-# BLDPROGS
-#
-
-## Build program (one).
-# @param    $(target)   Normalized target (program) name.
-define def_bldprog
+type := AS
+$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
+	,$(eval $(value def_target_source_c_cpp_asm)) )
+
+endef
+
+## Generate the link & lib install rule
+# @param    $(target)   Normalized target name.
+# @param    $(out)      The build target.
+# @param    $(INSTARGET_$(target))  The installation targets.
+define def_link_install_rule
+$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
+	$(RM) -f $$@
+	$(CP) $(out) $$@
+endef
+
+
+
+## Generic macro for generating the install rule(s) for a target
+# and update the globals with default out.
+#
+# @param	$(target)   Normalized target name.
+# @param	$(out)      The output file.
+# @param	$(definst)  The default _INST value.
+# @param	$(typevar)  The name of the variable with all the root targets of its type.
+# @obsolete
+define def_target_install_pluss
+ifndef $(target)_NOINST
+INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
+	$(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
+
+$(eval $(def_link_install_rule))
+
+_INSTALLS  += $(INSTARGET_$(target))
+
+ifdef KBUILD_DO_AUTO_INSTALL
+$(typevar)  += $(INSTARGET_$(target))
+else
+$(typevar)  += $(out)
+endif
+else # _NOINST
+$(typevar)  += $(out)
+endif
+
+_OUT_FILES += $(out)
+_CLEAN_FILES += $($(target)_CLEAN)
+_OBJS += $($(target)_OBJS_)
+
+endef
+
+
+
+#
+# LIBRARIES
+#
+
+## Library (one).
+# @param    $(target)   Normalized library (target) name.
+define def_lib
+# library basics
+## @todo prefix
+bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE))
+bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_TARGET))
+bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
+bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU))
+tool        := $(call _TARGET_TOOL,$(target),AR)
+ifeq ($(tool),)
+$(error kBuild: Library target $(target) does not have a tool defined!)
+endif
+outbase     := $(call _TARGET_BASE,$(target),$(target))
+PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
+suff        := $(firstword\
+	$($(target)_LIBSUFF.$(bld_trg))\
+	$($(target)_LIBSUFF)\
+	$(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
+	$(TOOL_$(tool)_ARLIBSUFF)\
+	$(SUFF_LIB))
+out         := $(outbase)$(suff)
+TARGET_$(target) := $(out)
+$(target)_OBJS_ := $(filter %.o %.obj, \
+	$($(target)_SOURCES) \
+	$($(target)_SOURCES.$(bld_trg)) \
+	$($(target)_SOURCES.$(bld_trg_arch)) \
+	$($(target)_SOURCES.$(bld_trg_cpu)) \
+	$($(target)_SOURCES.$(bld_type)))
+
+
+# source -> object
+$(eval $(value def_target_sources))
+
+# library linking
+tool        := $(call _TARGET_TOOL,$(target),AR)
+outbase     := $(call _TARGET_BASE,$(target),$(target))
+flags       :=\
+	$(TOOL_$(tool)_ARFLAGS)\
+	$(TOOL_$(tool)_ARFLAGS.$(bld_type))\
+	$(ARFLAGS)\
+	$(ARFLAGS.$(bld_type))\
+	$($(target)_ARFLAGS)\
+	$($(target)_ARFLAGS.$(bld_type))
+othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
+	$($(target)_SOURCES) \
+	$($(target)_SOURCES.$(bld_trg)) \
+	$($(target)_SOURCES.$(bld_trg_arch)) \
+	$($(target)_SOURCES.$(bld_trg_cpu)) \
+	$($(target)_SOURCES.$(bld_type)))
+objs         = $($(target)_OBJS_)
+dirdep      := $(call DIRDEP,$(dir $(out)))
+## @todo fix dependencies on makefiles an such
+deps        := $($(target)_DEPS)
+
+lib     := $(out)
+libsuff := $(suff)
+$(eval $(TOOL_$(tool)_LINK_LIBRARY))
+
+# installing and globals
+definst := $(PATH_LIB)
+typevar :=_LIBS
+$(eval $(value def_target_install_pluss))
+endef
+
+# Process libraries
+$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(value def_lib)))
+
+
+#
+# Link operations.
+#
+
+##
+# Link prolog
+#
+# @param    $(target)   Normalized target name.
+# @param    $(EXT)      EXE,DLL,SYS.
+# @param    $(definst)  The default _INST value.
+# @param    $(typevar)  The name of the variable with all the root targets of its type.
+define def_link_prolog
 # basics
-$(eval bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE)))
-$(eval bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_PLATFORM)))
-$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_PLATFORM_ARCH)))
-$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_PLATFORM_CPU)))
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
-$(eval exesuff     := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(HOSTSUFF_EXE)))
-$(eval exe         := $(outbase)$(exesuff))
-$(eval TARGET_$(target) := $(exe))
+bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE))
+bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_$(bld_trg_base_var)))
+bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
+bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_$(bld_trg_base_var)_CPU))
+
+tool        := $(call _TARGET_TOOL,$(target),LD)
+outbase     := $(call _TARGET_BASE,$(target),$(target))
+suff        := $(firstword \
+	$($(target)_$(EXT)SUFF) \
+	$($(target)_$(EXT)SUFF) \
+	$(TOOL_$(tool)_LD$(EXT)SUFF) \
+	$($(EXTPRE)SUFF_$(EXT)))
+out         := $(outbase)$(suff)
+PATH_$(target)   := $(patsubst %/,%,$(dir $(outbase)))
+TARGET_$(target) := $(out)
+$(target)_OBJS_  := $(filter %.o %.obj, \
+	$($(target)_SOURCES) \
+	$($(target)_SOURCES.$(bld_trg)) \
+	$($(target)_SOURCES.$(bld_trg_arch)) \
+	$($(target)_SOURCES.$(bld_trg_cpu)) \
+	$($(target)_SOURCES.$(bld_type)))
 
 # source -> object
-$(eval $(def_target_sources))
+$(eval $(value def_target_sources))
 
 # more library stuff.
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval objs         = $(_OBJS_$(target)) $(filter %.o %.obj, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-$(eval flags       :=\
+tool        := $(call _TARGET_TOOL,$(target),LD)
+outbase     := $(call _TARGET_BASE,$(target),$(target))
+flags       :=\
 	$(TOOL_$(tool)_LDFLAGS)\
 	$(TOOL_$(tool)_LDFLAGS.$(bld_type))\
@@ -711,7 +874,13 @@
 	$($(target)_LDFLAGS.$(bld_trg))\
 	$($(target)_LDFLAGS.$(bld_trg_arch))\
-	$($(target)_LDFLAGS.$(bld_trg_cpu))\
-)
-$(eval libs        :=\
+	$($(target)_LDFLAGS.$(bld_trg_cpu))
+othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
+	$($(target)_SOURCES)\
+	$($(target)_SOURCES.$(bld_trg)) \
+	$($(target)_SOURCES.$(bld_trg_arch)) \
+	$($(target)_SOURCES.$(bld_trg_cpu)) \
+	$($(target)_SOURCES.$(bld_type)))
+objs         = $($(target)_OBJS_)
+libs        :=\
 	$($(target)_LIBS.$(bld_trg_cpu))\
 	$($(target)_LIBS.$(bld_trg_arch))\
@@ -722,9 +891,9 @@
 				   $($(target)_SDKS.$(bld_type)) \
 				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
+		$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_LIBS.$(bld_trg))\
+		$(SDK_$(sdk)_LIBS.$(bld_type))\
+		$(SDK_$(sdk)_LIBS))\
 	$(LIBS.$(bld_trg_cpu))\
 	$(LIBS.$(bld_trg_arch))\
@@ -735,16 +904,15 @@
 				   $(SDKS.$(bld_type)) \
 				   $(SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
+		$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
+		$(SDK_$(sdk)_LIBS.$(bld_trg))\
+		$(SDK_$(sdk)_LIBS.$(bld_type))\
+		$(SDK_$(sdk)_LIBS))\
 	$(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
 	$(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
 	$(TOOL_$(tool)_LIBS.$(bld_trg))\
 	$(TOOL_$(tool)_LIBS.$(bld_type))\
-	$(TOOL_$(tool)_LIBS)\
-)
-$(eval libpath    :=\
+	$(TOOL_$(tool)_LIBS)
+libpath    :=\
 	$($(target)_LIBPATH.$(bld_trg_cpu))\
 	$($(target)_LIBPATH.$(bld_trg_arch))\
@@ -755,9 +923,9 @@
 				   $($(target)_SDKS.$(bld_type)) \
 				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_type))\
+		$(SDK_$(sdk)_LIBPATH))\
 	$(LIBPATH.$(bld_trg_cpu))\
 	$(LIBPATH.$(bld_trg_arch))\
@@ -768,20 +936,20 @@
 				   $(SDKS.$(bld_type)) \
 				   $(SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
+		$(SDK_$(sdk)_LIBPATH.$(bld_type))\
+		$(SDK_$(sdk)_LIBPATH))\
 	$(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
 	$(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
 	$(TOOL_$(tool)_LIBPATH.$(bld_trg))\
 	$(TOOL_$(tool)_LIBPATH.$(bld_type))\
-	$(TOOL_$(tool)_LIBPATH)\
-)
-$(eval dirdep      := $(dir $(exe)).dir_created)
+	$(TOOL_$(tool)_LIBPATH)
+dirdep      := $(call DIRDEP,$(dir $(out)))
 ## @todo fix dependencies
-$(eval deps        := $($(target)_DEPS))
-#
-$(eval custom_pre    := $(strip $(firstword
+deps        := $($(target)_DEPS)
+
+## @todo this stuff can't be working.
+custom_pre  := $(strip $(firstword \
 	$($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
 	$($(target)_CUSTOM_PRE.$(bld_trg))\
@@ -792,6 +960,6 @@
 	$(CUSTOM_PRE.$(bld_type))\
 	$(CUSTOM_PRE)\
-)))
-$(eval custom_post    := $(strip $(firstword
+))
+custom_post    := $(strip $(firstword \
 	$($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
 	$($(target)_CUSTOM_POST.$(bld_trg))\
@@ -802,10 +970,60 @@
 	$(CUSTOM_POST.$(bld_type))\
 	$(CUSTOM_POST)\
-)))
-$(eval othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
+))
+
+# installation targets
+ifndef $(target)_NOINST
+INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
+	$(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
+ifdef KBUILD_DO_AUTO_INSTALL
+$(typevar)  += $(INSTARGET_$(target))
+else
+$(typevar)  += $(out)
+endif
+# generate the install rule
+$(eval $(def_link_install_rule))
+
+else # NOINST
+INSTARGET_$(target) :=
+$(typevar)  += $(out)
+endif # NOINST
+
+endef
+
+
+##
+# Typical link epilog.
+#
+# @param	$(target)   Normalized target name.
+# @param	$(out)      The output file.
+define def_link_epilog
+
+_INSTALLS    += $(INSTARGET_$(target))
+_OBJS        += $($(target)_OBJS_)
+_OUT_FILES   += $(out)
+_CLEAN_FILES += $($(target)_CLEAN)
+
+endef
+
+
+#
+# BLDPROGS
+#
+
+## Build program (one).
+# @param    $(target)   Normalized target (program) name.
+define def_bldprog
+
+# set NOINST if not forced installation.
+ifndef $(target)_INST
+$(target)_NOINST := 1
+endif
+
+# prolog
+$(eval $(value def_link_prolog))
+
+# body
 ifndef TOOL_$(tool)_LINK_PROGRAM
-$$(warning kBuild: TOOL_$(tool)_LINK_PROGRAM is not defined. target=$(target) )
-$$(warning kBuild: tools: \
+$(warning kBuild: tools: \
 	1 $($(target)_$(source)TOOL.$(bld_trg)) \
 	2 $($(target)_$(source)TOOL) \
@@ -814,116 +1032,20 @@
 	5 $(TOOL.$(bld_trg)) \
 	6 $(TOOL) )
-endif
-
+$(error kBuild: TOOL_$(tool)_LINK_PROGRAM is not defined. target=$(target) )
+endif
 $(eval $(TOOL_$(tool)_LINK_PROGRAM))
 
-# installing
-ifdef $(target)_INST
-#ifndef KBUILD_NEW_STUFF
-$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
-$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
-	$(RM) -f $(pubexe)
-	$(CP) $(exe) $(pubexe)
-#else
-#$ (eval pubexe := $(patsubst %/,%/$(notdir $(exe)), \
-#	$ (if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(PATH_BIN)/)))
-#$ (pubexe) : $(exe) $(addsuffix .dir_created, $(dir $(pubexe)))
-#	$ (RM) -f $$@
-#	$ (CP) $(exe) $$@
-#endif
-
-_BLDPROGS  += $(pubexe)
-_OUT_FILES += $(exe) $(pubexe)
-_DIRS      += $(dir $(pubexe))
-else
-_BLDPROGS  += $(exe)
-_OUT_FILES += $(exe)
-endif
-_OBJS += $(_OBJS_$(target))
+# epilog
+$(eval $(value def_link_epilog))
+
 endef
 
 # Process build programs.
-$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)), $(eval $(def_bldprog)))
-
-
-
-#
-# LIBRARIES
-#
-
-## Library (one).
-# @param    $(target)   Normalized library (target) name.
-define def_lib
-# library basics
-## @todo prefix
-$(eval bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE)))
-$(eval bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_TARGET)))
-$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
-$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU)))
-$(eval tool        := $(call _TARGET_TOOL,$(target),AR))
-ifeq ($(tool),)
-$$(error kBuild: Library target $(target) doesn't have a tool defined!)
-endif
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
-$(eval libsuff     := $(firstword\
-	$($(target)_LIBSUFF.$(bld_trg))\
-	$($(target)_LIBSUFF)\
-	$(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
-	$(TOOL_$(tool)_ARLIBSUFF)\
-	$(SUFF_LIB)\
-))
-$(eval lib         := $(outbase)$(libsuff))
-$(eval TARGET_$(target) := $(lib))
-
-# source -> object
-$(eval $(def_target_sources))
-
-# library linking
-$(eval tool        := $(call _TARGET_TOOL,$(target),AR))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval flags       :=\
-	$(TOOL_$(tool)_ARFLAGS)\
-	$(TOOL_$(tool)_ARFLAGS.$(bld_type))\
-	$(ARFLAGS)\
-	$(ARFLAGS.$(bld_type))\
-	$($(target)_ARFLAGS)\
-	$($(target)_ARFLAGS.$(bld_type))\
-	)
-$(eval objs         = $(_OBJS_$(target)) $(filter %.o %.obj, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-$(eval othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-$(eval dirdep      := $(dir $(lib)).dir_created)
-## @todo fix dependencies on makefiles an such
-$(eval deps        := $($(target)_DEPS))
-
-$(eval $(TOOL_$(tool)_LINK_LIBRARY))
-
-# installing
-ifndef $(target)_NOINST
-# ifndef KBUILD_NEW_STUFF
-$(eval publib := $(PATH_LIB)/$(notdir $(lib)))
-$(publib) : $(lib) $(dir $(publib)).dir_created
-	$(RM) -f $(publib)
-	$(CP) $(lib) $(publib)
-#else
-#$ ( eval publib := $(patsubst %/,%/$(notdir $(lib)), \
-#	$ ( if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(PATH_LIB)/)))
-#$ ( publib) : $(lib) $(addsuffix .dir_created, $(dir $(publib)))
-#	$ ( RM) -f $$@
-#	$ ( CP) $(lib) $$@
-#endif
-
-_LIBS      += $(publib)
-_OUT_FILES += $(lib) $(publib)
-_DIRS      += $(dir $(publib))
-else
-_LIBS += $(lib)
-_OUT_FILES += $(lib)
-endif
-_OBJS += $(_OBJS_$(target))
-endef
-
-# Process libraries
-$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(def_lib)))
+EXT     := EXE
+EXTPRE  := HOST
+definst := $(PATH_BIN)
+typevar := _BLDPROGS
+bld_trg_base_var := PLATFORM
+$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)), $(eval $(value def_bldprog)))
 
 
@@ -936,136 +1058,11 @@
 # @param    $(target)   Normalized target (program) name.
 define def_dll
-# dllmod basics
-$(eval bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE)))
-$(eval bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_TARGET)))
-$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
-$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU)))
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
-$(eval dllsuff     := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
-$(eval dll         := $(outbase)$(dllsuff))
-$(eval TARGET_$(target) := $(dll))
-
-# source -> object
-$(eval $(def_target_sources))
-
-# dllmod linking.
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval objs         = $(_OBJS_$(target)) $(filter %.o %.obj, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
-$(eval flags       :=\
-	$(TOOL_$(tool)_LDFLAGS)\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_type))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
-	$(LDFLAGS)\
-	$(LDFLAGS.$(bld_type))\
-	$(LDFLAGS.$(bld_trg))\
-	$(LDFLAGS.$(bld_trg_arch))\
-	$(LDFLAGS.$(bld_trg_cpu))\
-	$($(target)_LDFLAGS)\
-	$($(target)_LDFLAGS.$(bld_type))\
-	$($(target)_LDFLAGS.$(bld_trg))\
-	$($(target)_LDFLAGS.$(bld_trg_arch))\
-	$($(target)_LDFLAGS.$(bld_trg_cpu))\
-)
-$(eval libs        :=\
-	$($(target)_LIBS.$(bld_trg_cpu))\
-	$($(target)_LIBS.$(bld_trg_arch))\
-	$($(target)_LIBS.$(bld_trg))\
-	$($(target)_LIBS.$(bld_type))\
-	$($(target)_LIBS)\
-	$(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
-				   $($(target)_SDKS.$(bld_type)) \
-				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
-	$(LIBS.$(bld_trg_cpu))\
-	$(LIBS.$(bld_trg_arch))\
-	$(LIBS.$(bld_trg))\
-	$(LIBS.$(bld_type))\
-	$(LIBS)\
-	$(foreach sdk, $(SDKS.$(bld_trg)) \
-				   $(SDKS.$(bld_type)) \
-				   $(SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg))\
-	$(TOOL_$(tool)_LIBS.$(bld_type))\
-	$(TOOL_$(tool)_LIBS)\
-)
-$(eval libpath    :=\
-	$($(target)_LIBPATH.$(bld_trg_cpu))\
-	$($(target)_LIBPATH.$(bld_trg_arch))\
-	$($(target)_LIBPATH.$(bld_trg))\
-	$($(target)_LIBPATH.$(bld_type))\
-	$($(target)_LIBPATH)\
-	$(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
-				   $($(target)_SDKS.$(bld_type)) \
-				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
-	$(LIBPATH.$(bld_trg_cpu))\
-	$(LIBPATH.$(bld_trg_arch))\
-	$(LIBPATH.$(bld_trg))\
-	$(LIBPATH.$(bld_type))\
-	$(LIBPATH)\
-	$(foreach sdk, $(SDKS.$(bld_trg)) \
-				   $(SDKS.$(bld_type)) \
-				   $(SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_type))\
-	$(TOOL_$(tool)_LIBPATH)\
-)
-$(eval dirdep      := $(dir $(dll)).dir_created)
-## @todo fix dependencies
-$(eval deps        := $($(target)_DEPS))
-#
-$(eval custom_pre    := $(strip $(firstword
-	$($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
-	$($(target)_CUSTOM_PRE.$(bld_trg))\
-	$($(target)_CUSTOM_PRE.$(bld_type))\
-	$($(target)_CUSTOM_PRE)\
-	$(CUSTOM_PRE.$(bld_trg).$(bld_type))\
-	$(CUSTOM_PRE.$(bld_trg))\
-	$(CUSTOM_PRE.$(bld_type))\
-	$(CUSTOM_PRE)\
-)))
-$(eval custom_post    := $(strip $(firstword
-	$($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
-	$($(target)_CUSTOM_POST.$(bld_trg))\
-	$($(target)_CUSTOM_POST.$(bld_type))\
-	$($(target)_CUSTOM_POST)\
-	$(CUSTOM_POST.$(bld_trg).$(bld_type))\
-	$(CUSTOM_POST.$(bld_trg))\
-	$(CUSTOM_POST.$(bld_type))\
-	$(CUSTOM_POST)\
-)))
-$(eval othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
+
+# prolog
+$(eval $(value def_link_prolog))
+
+# body
 ifndef TOOL_$(tool)_LINK_DLL
-$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
-$$(warning kBuild: tools: \
+$(warning kBuild: tools: \
 	1 $($(target)_$(source)TOOL.$(bld_trg)) \
 	2 $($(target)_$(source)TOOL) \
@@ -1076,37 +1073,20 @@
 	7 $(TOOL.$(bld_trg)) \
 	8 $(TOOL) )
-endif
-
+$(error kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
+endif
 $(eval $(TOOL_$(tool)_LINK_DLL))
 
-
-# installing
-ifndef $(target)_NOINST
-#ifndef KBUILD_NEW_STUFF
-$(eval pubdll := $(PATH_BIN)/$(notdir $(dll)))
-$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
-	$(RM) -f $(pubdll)
-	$(CP) $(dll) $(pubdll)
-#else
-#$ (eval pubdll := $(patsubst %/,%/$(notdir $(dll)), \
-#	$ (if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(PATH_DLL)/)))
-#$ (pubdll) : $(dll) $(addsuffix .dir_created, $(dir $(publib)))
-#	$(RM) -f $$@
-#	$(CP) $(dll) $$@
-#endif
-
-$(eval TARGET_PUB_$(target) := $(pubdll))
-_DLLS      += $(pubdll)
-_OUT_FILES += $(dll) $(pubdll)
-_DIRS      += $(dir $(pubdll))
-else
-_DLLS      += $(dll)
-_OUT_FILES += $(dll)
-endif
-_OBJS += $(_OBJS_$(target))
+# epilog
+$(eval $(value def_link_epilog))
+
 endef
 
 # Process dlls
-$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
+EXT     := DLL
+EXTPRE  :=
+definst := $(PATH_DLL)
+typevar := _DLLS
+bld_trg_base_var := TARGET
+$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(value def_dll)))
 
 
@@ -1118,10 +1098,10 @@
 #   - On other platforms they are fake DLLs.
 ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
-$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_lib)))
+$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(value def_lib)))
 else
-$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_dll)))
-endif
-$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval _IMPORT_LIBS += $(firstword $(TARGET_PUB_$(target)) $(TARGET_$(target)))))
-
+$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(value def_dll)))
+endif
+$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), \
+	$(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
 
 
@@ -1133,304 +1113,11 @@
 # @param    $(target)   Normalized target (program) name.
 define def_program
-# basics
-$(eval bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE)))
-$(eval bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_TARGET)))
-$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
-$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU)))
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
-$(eval exesuff     := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
-$(eval exe         := $(outbase)$(exesuff))
-$(eval TARGET_$(target) := $(exe))
-
-# source -> object
-$(eval $(def_target_sources))
-
-# more library stuff.
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval objs         = $(_OBJS_$(target)) $(filter %.o %.obj, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
-$(eval flags       :=\
-	$(TOOL_$(tool)_LDFLAGS)\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_type))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
-	$(LDFLAGS)\
-	$(LDFLAGS.$(bld_type))\
-	$(LDFLAGS.$(bld_trg))\
-	$(LDFLAGS.$(bld_trg_arch))\
-	$(LDFLAGS.$(bld_trg_cpu))\
-	$($(target)_LDFLAGS)\
-	$($(target)_LDFLAGS.$(bld_type))\
-	$($(target)_LDFLAGS.$(bld_trg))\
-	$($(target)_LDFLAGS.$(bld_trg_arch))\
-	$($(target)_LDFLAGS.$(bld_trg_cpu))\
-)
-$(eval libs        :=\
-	$($(target)_LIBS.$(bld_trg_cpu))\
-	$($(target)_LIBS.$(bld_trg_arch))\
-	$($(target)_LIBS.$(bld_trg))\
-	$($(target)_LIBS.$(bld_type))\
-	$($(target)_LIBS)\
-	$(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
-				   $($(target)_SDKS.$(bld_type)) \
-				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
-	$(LIBS.$(bld_trg_cpu))\
-	$(LIBS.$(bld_trg_arch))\
-	$(LIBS.$(bld_trg))\
-	$(LIBS.$(bld_type))\
-	$(LIBS)\
-	$(foreach sdk, $(SDKS.$(bld_trg)) \
-				   $(SDKS.$(bld_type)) \
-				   $(SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg))\
-	$(TOOL_$(tool)_LIBS.$(bld_type))\
-	$(TOOL_$(tool)_LIBS)\
-)
-$(eval libpath    :=\
-	$($(target)_LIBPATH.$(bld_trg_cpu))\
-	$($(target)_LIBPATH.$(bld_trg_arch))\
-	$($(target)_LIBPATH.$(bld_trg))\
-	$($(target)_LIBPATH.$(bld_type))\
-	$($(target)_LIBPATH)\
-	$(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
-				   $($(target)_SDKS.$(bld_type)) \
-				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
-	$(LIBPATH.$(bld_trg_cpu))\
-	$(LIBPATH.$(bld_trg_arch))\
-	$(LIBPATH.$(bld_trg))\
-	$(LIBPATH.$(bld_type))\
-	$(LIBPATH)\
-	$(foreach sdk, $(SDKS.$(bld_trg)) \
-				   $(SDKS.$(bld_type)) \
-				   $(SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_type))\
-	$(TOOL_$(tool)_LIBPATH)\
-)
-$(eval dirdep      := $(dir $(exe)).dir_created)
-## @todo fix dependencies
-$(eval deps        := $($(target)_DEPS))
-#
-$(eval custom_pre    := $(strip $(firstword
-	$($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
-	$($(target)_CUSTOM_PRE.$(bld_trg))\
-	$($(target)_CUSTOM_PRE.$(bld_type))\
-	$($(target)_CUSTOM_PRE)\
-	$(CUSTOM_PRE.$(bld_trg).$(bld_type))\
-	$(CUSTOM_PRE.$(bld_trg))\
-	$(CUSTOM_PRE.$(bld_type))\
-	$(CUSTOM_PRE)\
-)))
-$(eval custom_post    := $(strip $(firstword
-	$($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
-	$($(target)_CUSTOM_POST.$(bld_trg))\
-	$($(target)_CUSTOM_POST.$(bld_type))\
-	$($(target)_CUSTOM_POST)\
-	$(CUSTOM_POST.$(bld_trg).$(bld_type))\
-	$(CUSTOM_POST.$(bld_trg))\
-	$(CUSTOM_POST.$(bld_type))\
-	$(CUSTOM_POST)\
-)))
-$(eval othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
-$(eval $(TOOL_$(tool)_LINK_PROGRAM))
-
-# installing
-ifndef $(target)_NOINST
-#ifndef KBUILD_NEW_STUFF
-$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
-$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
-	$(RM) -f $(pubexe)
-	$(CP) $(exe) $(pubexe)
-#else
-#$ (eval pubexe := $(patsubst %/,%/$(notdir $(exe)), \
-#	$(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(PATH_BIN)/)))
-#$ (pubexe) : $(exe) $(addsuffix .dir_created, $(dir $(pubexe)))
-#	$(RM) -f $$@
-#	$(CP) $(exe) $$@
-#endif
-
-_PROGRAMS  += $(pubexe)
-_OUT_FILES += $(exe) $(pubexe)
-_DIRS      += $(dir $(pubexe))
-else
-_PROGRAMS  += $(exe)
-_OUT_FILES += $(exe)
-endif
-_OBJS += $(_OBJS_$(target))
-endef
-
-# Process libraries
-$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(def_program)))
-
-
-
-#
-# SYSMODS
-#
-
-## System module (one).
-# @param    $(target)   Normalized target (program) name.
-define def_sysmod
-# sysmod basics
-$(eval bld_type    := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE)))
-$(eval bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_TARGET)))
-$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
-$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU)))
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
-$(eval syssuff     := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
-$(eval sys         := $(outbase)$(syssuff))
-$(eval TARGET_$(target) := $(sys))
-
-# source -> object
-$(eval $(def_target_sources))
-
-# sysmod linking
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(eval objs         = $(_OBJS_$(target)) $(filter %.o %.obj, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
-$(eval flags       :=\
-	$(TOOL_$(tool)_LDFLAGS)\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_type))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
-	$(LDFLAGS)\
-	$(LDFLAGS.$(bld_type))\
-	$(LDFLAGS.$(bld_trg))\
-	$(LDFLAGS.$(bld_trg_arch))\
-	$(LDFLAGS.$(bld_trg_cpu))\
-	$($(target)_LDFLAGS)\
-	$($(target)_LDFLAGS.$(bld_type))\
-	$($(target)_LDFLAGS.$(bld_trg))\
-	$($(target)_LDFLAGS.$(bld_trg_arch))\
-	$($(target)_LDFLAGS.$(bld_trg_cpu))\
-)
-$(eval libs        :=\
-	$($(target)_LIBS.$(bld_trg_cpu))\
-	$($(target)_LIBS.$(bld_trg_arch))\
-	$($(target)_LIBS.$(bld_trg))\
-	$($(target)_LIBS.$(bld_type))\
-	$($(target)_LIBS)\
-	$(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
-				   $($(target)_SDKS.$(bld_type)) \
-				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
-	$(LIBS.$(bld_trg_cpu))\
-	$(LIBS.$(bld_trg_arch))\
-	$(LIBS.$(bld_trg))\
-	$(LIBS.$(bld_type))\
-	$(LIBS)\
-	$(foreach sdk, $(SDKS.$(bld_trg)) \
-				   $(SDKS.$(bld_type)) \
-				   $(SDKS),\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBS.$(bld_trg))\
-	$(SDK_$(sdk)_LIBS.$(bld_type))\
-	$(SDK_$(sdk)_LIBS))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LIBS.$(bld_trg))\
-	$(TOOL_$(tool)_LIBS.$(bld_type))\
-	$(TOOL_$(tool)_LIBS)\
-)
-$(eval libpath    :=\
-	$($(target)_LIBPATH.$(bld_trg_cpu))\
-	$($(target)_LIBPATH.$(bld_trg_arch))\
-	$($(target)_LIBPATH.$(bld_trg))\
-	$($(target)_LIBPATH.$(bld_type))\
-	$($(target)_LIBPATH)\
-	$(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
-				   $($(target)_SDKS.$(bld_type)) \
-				   $($(target)_SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
-	$(LIBPATH.$(bld_trg_cpu))\
-	$(LIBPATH.$(bld_trg_arch))\
-	$(LIBPATH.$(bld_trg))\
-	$(LIBPATH.$(bld_type))\
-	$(LIBPATH)\
-	$(foreach sdk, $(SDKS.$(bld_trg)) \
-				   $(SDKS.$(bld_type)) \
-				   $(SDKS),\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
-	$(SDK_$(sdk)_LIBPATH.$(bld_type))\
-	$(SDK_$(sdk)_LIBPATH))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_trg))\
-	$(TOOL_$(tool)_LIBPATH.$(bld_type))\
-	$(TOOL_$(tool)_LIBPATH)\
-)
-$(eval dirdep      := $(dir $(sys)).dir_created)
-## @todo fix dependencies
-$(eval deps        := $($(target)_DEPS))
-#
-$(eval custom_pre    := $(strip $(firstword
-	$($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
-	$($(target)_CUSTOM_PRE.$(bld_trg))\
-	$($(target)_CUSTOM_PRE.$(bld_type))\
-	$($(target)_CUSTOM_PRE)\
-	$(CUSTOM_PRE.$(bld_trg).$(bld_type))\
-	$(CUSTOM_PRE.$(bld_trg))\
-	$(CUSTOM_PRE.$(bld_type))\
-	$(CUSTOM_PRE)\
-)))
-$(eval custom_post    := $(strip $(firstword
-	$($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
-	$($(target)_CUSTOM_POST.$(bld_trg))\
-	$($(target)_CUSTOM_POST.$(bld_type))\
-	$($(target)_CUSTOM_POST)\
-	$(CUSTOM_POST.$(bld_trg).$(bld_type))\
-	$(CUSTOM_POST.$(bld_trg))\
-	$(CUSTOM_POST.$(bld_type))\
-	$(CUSTOM_POST)\
-)))
-$(eval othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
-
-ifndef TOOL_$(tool)_LINK_SYSMOD
-$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
-$$(warning kBuild: tools: \
+
+# prolog
+$(eval $(value def_link_prolog))
+
+# body
+ifndef TOOL_$(tool)_LINK_PROGRAM
+$(warning kBuild: tools: \
 	1 $($(target)_$(source)TOOL.$(bld_trg)) \
 	2 $($(target)_$(source)TOOL) \
@@ -1441,43 +1128,201 @@
 	7 $(TOOL.$(bld_trg)) \
 	8 $(TOOL) )
-endif
-
+$(error kBuild: TOOL_$(tool)_LINK_PROGRAM is not defined. target=$(target) )
+endif
+$(eval $(TOOL_$(tool)_LINK_PROGRAM))
+
+# epilog
+$(eval $(value def_link_epilog))
+
+endef
+
+# Process programs
+EXT     := EXE
+EXTPRE  :=
+definst := $(PATH_BIN)
+typevar := _PROGRAMS
+bld_trg_base_var := TARGET
+$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(value def_program)))
+
+
+
+#
+# SYSMODS
+#
+
+## System module (one).
+# @param    $(target)   Normalized target (program) name.
+define def_sysmod
+
+# prolog
+$(eval $(value def_link_prolog))
+
+# body
+ifndef TOOL_$(tool)_LINK_SYSMOD
+$(warning kBuild: tools: \
+	1 $($(target)_$(source)TOOL.$(bld_trg)) \
+	2 $($(target)_$(source)TOOL) \
+	3 $($(target)_TOOL.$(bld_trg)) \
+	4 $($(target)_TOOL) \
+	5 $($(source)TOOL) \
+	6 $($(source)TOOL.$(bld_trg)) \
+	7 $(TOOL.$(bld_trg)) \
+	8 $(TOOL) )
+$(error kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
+endif
 $(eval $(TOOL_$(tool)_LINK_SYSMOD))
 
-# installing
-ifndef $(target)_NOINST
-#ifndef KBUILD_NEW_STUFF
-$(eval pubsys := $(PATH_BIN)/$(notdir $(sys)))
-$(pubsys): $(sys) $(dir $(pubsys)).dir_created
-	$(RM) -f $(pubsys)
-	$(CP) $(sys) $(pubsys)
-#else
-#$ (eval pubsys := $(patsubst %/,%/$(notdir $(sys)), \
-#	$(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(PATH_SYS)/)))
-#$ (pubsys) : $(sys) $(addsuffix .dir_created, $(dir $(pubsys)))
-#	$(RM) -f $$@
-#	$(CP) $(sys) $$@
-#endif
-
-$(eval _SYSMODS += $(pubsys))
-$(eval _OUT_FILES += $(sys) $(pubsys))
-_DIRS      += $(dir $(pubsys))
+# epilog
+$(eval $(value def_link_epilog))
+
+endef
+
+# Process sysmods
+EXT     := SYS
+EXTPRE  :=
+definst := $(PATH_SYS)
+typevar := _SYSMODS
+bld_trg_base_var := TARGET
+$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(value def_sysmod)))
+
+
+#
+# OTHERS
+#
+_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
+
+
+#
+# INSTALLS
+#
+
+## generate the install rule
+define def_install_src_rule
+# the install rule
+$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
+	$$(RM) -f $$@
+	$(inscmd)
+endef
+
+## install one file
+define def_install_src
+
+# deal with '=>' in the source file name.
+srcdst := $(subst =>, ,$(src))
+srcsrc := $(firstword $(srcdst))
+srcdst := $(word $(words $(srcdst)),$(srcdst))
+
+# _INSTFUN
+ifdef $(srcsrc)_INSTFUN
+instfun := $(srcsrc)_INSTFUN
 else
-$(eval _SYSMODS += $(sys))
-$(eval _OUT_FILES += $(sys))
-endif
-_OBJS += $(_OBJS_$(target))
-endef
-
-# Process sysmods
-$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(def_sysmod)))
-
-
-
-#
-# OTHERS
-#
-_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
-
+ifdef $(target)_INSTFUN
+instfun := $(target)_INSTFUN
+else
+instfun := _INSTALL_FILE
+endif
+endif
+
+# _INST
+ifdef $(srcsrc)_INST
+inst = $(srcsrc)_INST
+else
+ifdef $(target)_INST
+inst = $(target)_INST
+else
+inst =
+endif
+endif
+
+# calc target
+insdst := $(call $(instfun),$(srcdst),$(target),$($(inst)),$(PATH_INS))
+#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) srcdst=$(srcsrc) inst=$(inst) => insdst=$(insdst))
+
+# create the command
+ifdef $(srcsrc)_INSTALLER
+inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
+else
+ifdef $(target)_INSTALLER
+inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
+else
+inscmd := $$(CP) $(srcsrc) $(insdst)
+endif
+endif
+
+# generate the rule (need double evaluation here)
+$(eval $(def_install_src_rule))
+
+INSTARGET_$(target) += $(insdst)
+endef
+
+
+## generate the symlink rule
+define def_install_symlink_rule
+# the install rule
+$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
+	$$(RM) -f $$@
+	$$(LN_SYMLINK) $(srcsrc) $(insdst)
+endef
+
+## create one symlink
+define def_install_symlink
+
+# deal with '=>' in the source file name.
+srcdst := $(subst =>, ,$(src))
+srcsrc := $(firstword $(srcdst))
+srcdst := $(word $(words $(srcdst)),$(srcdst))
+
+# _INSTFUN
+ifdef $(srcsrc)_INSTFUN
+instfun := $(srcsrc)_INSTFUN
+else
+ifdef $(target)_INSTFUN
+instfun := $(target)_INSTFUN
+else
+instfun := _INSTALL_FILE
+endif
+endif
+
+# _INST
+ifdef $(srcsrc)_INST
+inst = $(srcsrc)_INST
+else
+ifdef $(target)_INST
+inst = $(target)_INST
+else
+inst =
+endif
+endif
+
+# calc target
+insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
+#$(warning srcsrc=$(srcsrc) srcdst=$(srcdst) insdst=$(insdst))
+
+# generate the rule (need double evaluation here)
+$(eval $(def_install_symlink_rule))
+
+INSTARGET_$(target) += $(insdst)
+endef
+
+## process one install target.
+define def_install
+bld_type  := $(firstword $($(target)_BLD_TYPE)     $(BUILD_TYPE))
+bld_trg   := $(firstword $($(target)_BLD_TRG)      $(BUILD_TARGET))
+bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
+bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU))
+
+INSTARGET_$(target) :=
+$(foreach src,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)), \
+	$(eval $(value def_install_src)))
+
+$(foreach src,$($(target)_SYMLINKS) $($(target)_SYMLINKS.$(bld_trg)) $($(target)_SYMLINKS.$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_cpu)) $($(target)_SYMLINKS.$(bld_type)), \
+	$(eval $(value def_install_symlink)))
+
+_INSTALLS  += $(INSTARGET_$(target))
+endef
+
+## process all install targets
+$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)), \
+	$(eval $(value def_install)))
 
 
@@ -1488,22 +1333,35 @@
 
 #
-# Directories.
-#
-_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
-
-define def_createdir
-$(dirfile):
-	$(call MSG_L1,Creating directory $$(@D))
-	$(MKDIR) -p $$(@D)
-	@echo dir_created > $$@
-endef
-
-$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
-
-
-#
-# Include dependency files.
-#
-$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
+# PACKING
+#
+packing::
+
+
+#
+# DIRECTORIES
+#
+_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
+
+define def_mkdir_rule
+$(directory):
+	$(call MSG_L1,Creating directory $$@)
+	$(MKDIR) -p $$@
+endef
+
+$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
+
+
+#
+# NOTHING
+#
+do-nothing:
+	$(call MSG_L1,Did nothing in $(CURDIR))
+
+
+#
+# CLEAN UP
+#
+do-clean:
+	$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_CLEAN_FILES) $(OTHER_CLEAN)
 
 
@@ -1511,14 +1369,4 @@
 # PASSES (including directory and makefile walking)
 #
-# Do all the default passes if it's unspecified.
-
-#PASSES ?= bldprogs libraries binaries others publish
-PASSES ?= bldprogs libraries dlls binaries others
-
-## @todo figure out a generic way of configuring how pass works!
-
-## Proritized list of the default makefile when walking subdirectories.
-# The user can overload this list.
-DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
 
 ## Subdir
@@ -1542,8 +1390,33 @@
 endef
 
-
 ## Execute a pass.
 # @param	$(pass)		Lowercase pass name.
 # @param	$(PASS)		Uppercase pass name.
+define def_pass_old
+$(eval SUBDIRS_$(PASS)          ?= $(SUBDIRS)          $(SUBDIRS.$(BUILD_TARGET)))
+$(eval SUBDIRS_AFTER_$(PASS)    ?= $(SUBDIRS_AFTER)    $(SUBDIRS_AFTER.$(BUILD_TARGET)))
+$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
+$(eval MAKEFILES_AFTER_$(PASS)  ?= $(MAKEFILES_AFTER)  $(MAKEFILES_AFTER.$(BUILD_TARGET)))
+
+$(eval tag:=_before)
+$(eval dep:=)
+$(foreach subdir,$(SUBDIRS_$(PASS))            $(SUBDIRS_$(PASS).$(BUILD_TARGET))         ,$(eval $(def_pass_subdir)))
+$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
+
+$(eval tag:=_after)
+$(eval dep:=pass_$(pass)_doit)
+$(foreach subdir,$(SUBDIRS_AFTER_$(PASS))      $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET))   ,$(eval $(def_pass_subdir)))
+$(foreach makefile,$(MAKEFILES_AFTER_$(PASS))  $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
+
+.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
+.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
+pass_$(pass)_doit: 	$(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
+pass_$(pass)_this:      pass_$(pass)_before
+	+ $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
+pass_$(pass)_after::    pass_$(pass)_this
+pass_$(pass):           pass_$(pass)_after
+
+endef
+
 define def_pass
 $(eval SUBDIRS_$(PASS)          ?= $(SUBDIRS)          $(SUBDIRS.$(BUILD_TARGET)))
@@ -1562,88 +1435,30 @@
 $(foreach makefile,$(MAKEFILES_AFTER_$(PASS))  $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
 
-.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
-.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
+ifdef KBUILD_SAFE_PARALLELL
+.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
+.PHONY:       pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
+pass_$(pass)_doit: 	    $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
 pass_$(pass)_this:      pass_$(pass)_before
 	+ $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
 pass_$(pass)_after::    pass_$(pass)_this
 pass_$(pass):           pass_$(pass)_after
-
-endef
-
-
-## PASS: bldprogs
-# This pass builds targets which are required for building the rest.
-pass_bldprogs_doit: $(_BLDPROGS)
-pass := bldprogs
-PASS := BLDPROGS
-$(eval $(def_pass))
-
-## PASS: libraries
-# This pass builds library targets.
-pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
-pass := libraries
-PASS := LIBRARIES
-$(eval $(def_pass))
-
-## PASS: binaries
-# This pass builds dll targets.
-pass_dlls_doit: $(_DLLS) $(_OTHER_DLLS)
-pass := dlls
-PASS := DLLS
-$(eval $(def_pass))
-
-## PASS: binaries
-# This pass builds binary targets, i.e. programs, system modules and stuff.
-pass_binaries_doit: $(_PROGRAMS) $(_SYSMODS) $(_OTHER_BINARIES)
-pass := binaries
-PASS := BINARIES
-$(eval $(def_pass))
-
-## PASS: others
-# This pass builds other targets.
-pass_others_doit: $(_OTHERS)
-pass := others
-PASS := OTHERS
-$(eval $(def_pass))
-
-## PASS: publish
-# This pass installs the built entities to a sandbox area.
-pass_publish_doit: publish
-publish::
-pass := publish
-PASS := PUBLISH
-# $(sort).. not nice.
-SUBDIRS_PUBLISH         ?= $(sort $(SUBDIRS)          $(SUBDIRS.$(BUILD_TARGET))          $(SUBDIRS_LIBRARIES)          $(SUBDIRS_LIBRARIES.$(BUILD_TARGET))          $(SUBDIRS_BINARIES)          $(SUBDIRS_BINARIES.$(BUILD_TARGET))          $(SUBDIRS_OTHERS)          $(SUBDIRS_OTHERS.$(BUILD_TARGET)))
-SUBDIRS_AFTER_PUBLISH   ?= $(sort $(SUBDIRS_AFTER)    $(SUBDIRS_AFTER.$(BUILD_TARGET))    $(SUBDIRS_AFTER_LIBRARIES)    $(SUBDIRS_AFTER_LIBRARIES.$(BUILD_TARGET))    $(SUBDIRS_AFTER_BINARIES)    $(SUBDIRS_AFTER_BINARIES.$(BUILD_TARGET))    $(SUBDIRS_AFTER_OTHERS)    $(SUBDIRS_AFTER_OTHERS.$(BUILD_TARGET)))
-MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_LIBRARIES.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_BINARIES.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_OTHERS) $(MAKEFILES_BEFORE_OTHERS.$(BUILD_TARGET)))
-MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER)  $(MAKEFILES_AFTER.$(BUILD_TARGET))  $(MAKEFILES_AFTER_LIBRARIES)  $(MAKEFILES_AFTER_LIBRARIES.$(BUILD_TARGET))  $(MAKEFILES_AFTER_BINARIES)  $(MAKEFILES_AFTER_BINARIES.$(BUILD_TARGET))  $(MAKEFILES_AFTER_OTHERS)  $(MAKEFILES_AFTER_OTHERS.$(BUILD_TARGET)))
-$(eval $(def_pass))
-
-## PASS: packing
-# This pass processes custom packing rules.
-pass_packing_doit: packing
-packing::
-pass := packing
-PASS := PACKING
-$(eval $(def_pass))
-
-## PASS: clean
-# This pass removes all generated files.
-pass_clean_doit:
-	$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES) $(OTHER_CLEAN)
-pass := clean
-PASS := CLEAN
-$(eval $(def_pass))
-clean: pass_clean
-
-## PASS: nothing
-# This pass just walks the tree.
-pass_nothing_doit:
-	$(call MSG_L1,Did nothing in $(CURDIR))
-pass := nothing
-PASS := NOTHING
-$(eval $(def_pass))
-nothing: pass_nothing
-
+else
+.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after
+.PHONY:       pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
+pass_$(pass)_doit: pass_$(pass)_before \
+		$(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
+pass_$(pass): \
+		pass_$(pass)_before \
+		pass_$(pass)_doit \
+		pass_$(pass)_after
+endif
+
+#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
+endef
+
+# Generate the defined passes.
+$(foreach PASS, $(PASSES), \
+	$(eval pass := $(PASS_$(PASS)_pass)) \
+	$(eval $(def_pass)))
 
 ## Pass order
@@ -1651,8 +1466,20 @@
 # @param	$(prev_pass)	The previous pass name.
 define def_pass_order
+ifdef KBUILD_SAFE_PARALLELL
+.NOTPARALLEL: pass_$(pass)_order
+.PHONY: pass_$(pass)_order
 pass_$(pass)_order: $(pass_prev)
-	$(call MSG_L1,Pass $(pass))
+	$(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
 	+ $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
-.NOTPARALLEL: pass_$(pass)_order
+else
+.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
+.PHONY: pass_$(pass)_order pass_$(pass)_banner
+pass_$(pass)_banner:
+	$(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
+pass_$(pass)_order: \
+		$(pass_prev) \
+		pass_$(pass)_banner \
+		pass_$(pass)
+endif
 $(eval pass_prev := pass_$(pass)_order)
 endef
@@ -1661,5 +1488,7 @@
 # Use dependencies to ensure correct pass order.
 pass_prev :=
-$(foreach pass,$(PASSES),$(eval $(def_pass_order)))
+$(foreach PASS,$(DEFAULT_PASSES),\
+	$(eval pass := $(PASS_$(PASS)_pass)) \
+	$(eval $(def_pass_order)))
 
 
@@ -1672,7 +1501,9 @@
 	+ $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
 
+uninstall:
+	$(RM) -f $(_INSTALLS)
 
 # misc shortcuts.
-target:    bldprogs libraries binaries others
+targets:   bldprogs libraries dlls programs sysmods others install
 objects:   $(_OBJS)
 bldprogs:  $(_BLDPROGS)
@@ -1681,4 +1512,43 @@
 programs:  $(_PROGRAMS)
 sysmods:   $(_SYSMODS)
+others:    $(_OTHERS)
+install:   $(_INSTALLS)
+
+
+#
+# kBuild debugging stuff.
+#
+_SPACE := $(subst ., ,.)
+_TAB := $(subst .,	,.)
+define _NEWLINE
+
+
+endef
+NLTAB = $(_NEWLINE)$(TAB)
+show_targets:
+	@$(foreach target, $(ALL_TARGETS),\
+	@$(ECHO) "target: $(target)" $(NLTAB)\
+	@$(ECHO) "  PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
+	@$(ECHO) "  TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
+	@$(ECHO) "  INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
+$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_, \
+	$(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
+	$(if $($(target)_$(prop).$(_tmp)),\
+		@$(ECHO) "  $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
+	$(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) "  $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
+)\
+$(foreach prop,$(PROPS_DEFERRED), \
+	$(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
+	$(if $(value $(target)_$(prop).$(_tmp)),\
+		@$(ECHO) '  $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
+	$(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) '  $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
+))
+
+
+
+#
+# Include dependency files.
+#
+$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
 
 
Index: /trunk/kBuild/header.kmk
===================================================================
--- /trunk/kBuild/header.kmk	(revision 352)
+++ /trunk/kBuild/header.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild - File included at top of makefile.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -119,5 +119,5 @@
 
 # Fill in defaults if needed.
-ifndef BUILD_PLATFORM_ARCH 
+ifndef BUILD_PLATFORM_ARCH
 BUILD_PLATFORM_ARCH   := x86
 endif
@@ -234,19 +234,14 @@
 PATH_OUT            := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)
 endif
-endif # !x86 
+endif # !x86
 endif # !define PATH_OUT
-PATH_OBJ            := $(PATH_OUT)/obj
-PATH_TARGET         := $(PATH_OBJ)/$(CURSUBDIR)
-ifndef KBUILD_NEW_STUFF
-PATH_BIN            := $(PATH_OUT)/bin
-PATH_LIB            := $(PATH_OUT)/lib
-PATH_DOC            := $(PATH_ROOT)/out/doc
-else
-PATH_INS            := $(PATH_OUT)
-PATH_BIN            := $(PATH_INS)/bin
-PATH_DLL            := $(PATH_INS)/bin
-PATH_LIB            := $(PATH_INS)/lib
-PATH_DOC            := $(PATH_INS)/doc
-endif
+PATH_OBJ             = $(PATH_OUT)/obj
+PATH_TARGET          = $(PATH_OBJ)/$(CURSUBDIR)
+PATH_INS             = $(PATH_OUT)
+PATH_BIN             = $(PATH_INS)/bin
+PATH_DLL             = $(PATH_INS)/bin
+PATH_SYS             = $(PATH_INS)/bin
+PATH_LIB             = $(PATH_INS)/lib
+PATH_DOC             = $(PATH_INS)/doc
 
 # Usually kBuild is external to the source tree.
@@ -348,5 +343,5 @@
 endif
 
-# Standard Unix shell utils.
+# Standard Unix shell utils
 ifdef KMK_BUILTIN
 ECHO                := kmk_builtin_echo
@@ -359,4 +354,5 @@
 RM                  := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
 CP                  := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
+APPEND              := $(PATH_TOOLS)/append$(HOSTSUFF_EXE)
 endif
 CP_EXT              := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
@@ -364,4 +360,6 @@
 SED                 := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
 CAT                 := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
+LN_SYMLINK          := $(CP)
+#LN_SYMLINK          := ln -s
 # Bourn shell clone.
 MAKESHELL           := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
@@ -369,4 +367,11 @@
 export SHELL MAKESHELL
 
+# kBuild utils.
+ifeq ($(filter append,$(KMK_BUILTIN)),append)
+APPEND              := kmk_builtin_append
+else
+APPEND              := $(PATH_TOOLS)/append$(HOSTSUFF_EXE)
+endif
+
 
 #
@@ -410,9 +415,13 @@
                       $(path))))
 endif
-					  
+
 ## DIRDEP - make create directory dependencies.
 #
 # @param	$1	The paths to the directories which must be created.
-DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
+ifeq ($(BUILD_PLATFORM),win32)
+DIRDEP = $(patsubst %/,%,$(1))
+else
+DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
+endif
 
 
@@ -428,4 +437,143 @@
 CYGPATHMIXED = $(1)
 endif
+
+#
+# Initialize some of the globals which the Config.kmk and
+# others can add stuff to if they like for processing in the footer.
+#
+
+## ALL_TARGET
+# This is the list of all targets.
+ALL_TARGETS :=
+
+## TEMPLATE_PATHS
+# List a paths (separated by space) where templates can be found.
+TEMPLATE_PATHS :=
+
+## TOOL_PATHS
+# List of paths (separated by space) where tools can be found.
+TOOL_PATHS :=
+
+## SDK_PATHS
+# List of paths (separated by space) where SDKs can be found.
+SDK_PATHS :=
+
+## Proritized list of the default makefile when walking subdirectories.
+# The user can overload this list.
+DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
+
+## PROPS_SINGLE
+# The list of non-accumulative target properties.
+# A Config.kmk file can add it's own properties to this list and kBuild
+# will do the necessary inheritance from templates to targets.
+PROPS_SINGLE := TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL INST NOINST
+
+## PROPS_DEFERRED
+# This list of non-accumulative target properties which are functions,
+# and thus should not be expanded until the very last moment.
+PROPS_DEFERRED := INSTFUN INSTALLER
+
+## PROPS_ACCUMULATE
+# The list of accumulative target properties.
+# A Config.kmk file can add it's own properties to this list and kBuild
+# will do the necessary inheritance from templates to targets.
+PROPS_ACCUMULATE := \
+	SDKS DEFS INCS SOURCES \
+	COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS \
+	ASOPTS ASFLAGS ASDEFS ASINCS \
+	LDFLAGS LIBS LIBPATH \
+	BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU \
+	SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
+
+
+## PROPS_TOOLS
+# This is a subset of the other PROPS
+PROPS_TOOLS := TOOL CTOOL CXXTOOL ASTOOL ARTOOL LDTOOL
+
+
+#
+# Pass configuration.
+#
+# The PASS_<passname>_trgs variable is listing the targets.
+# The PASS_<passname>_vars variable is listing the target variables.
+# The PASS_<passname>_pass variable is the lowercased passname.
+#
+
+## PASS: bldprogs
+# This pass builds targets which are required for building the rest.
+PASS_BLDPROGS       := Build Programs
+PASS_BLDPROGS_trgs  :=
+PASS_BLDPROGS_vars  := _BLDPROGS
+PASS_BLDPROGS_pass  := bldprogs
+
+## PASS: libraries
+# This pass builds library targets.
+PASS_LIBRARIES      := Libraries
+PASS_LIBRARIES_trgs :=
+PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
+PASS_LIBRARIES_pass := libraries
+
+## PASS: binaries
+# This pass builds dll targets.
+PASS_DLLS           := DLLs
+PASS_DLLS_trgs      :=
+PASS_DLLS_vars      := _DLLS _OTHER_DLLS
+PASS_DLLS_pass      := dlls
+
+## PASS: binaries
+# This pass builds binary targets, i.e. programs, system modules and stuff.
+PASS_BINARIES       := Programs
+PASS_BINARIES_trgs  :=
+PASS_BINARIES_vars  := _PROGRAMS _SYSMODS _OTHER_BINARIES
+PASS_BINARIES_pass  := binaries
+
+## PASS: others
+# This pass builds other targets.
+PASS_OTHERS         := Other Stuff
+PASS_OTHERS_trgs    :=
+PASS_OTHERS_vars    := _OTHERS
+PASS_OTHERS_pass    := others
+
+## PASS: install
+# This pass installs the built entities to a sandbox area.
+PASS_INSTALLS       := Install
+PASS_INSTALLS_trgs  :=
+PASS_INSTALLS_vars  := _INSTALLS
+PASS_INSTALLS_pass  := installs
+
+## PASS: packing
+# This pass processes custom packing rules.
+PASS_PACKING        := Packing
+PASS_PACKING_trgs   := packing
+PASS_PACKING_vars   :=
+PASS_PACKING_pass   := packing
+
+## PASS: clean
+# This pass removes all generated files.
+PASS_CLEAN          := Clean
+PASS_CLEAN_trgs     := do-clean
+PASS_CLEAN_vars     :=
+PASS_CLEAN_pass     := clean
+# alias
+clean: pass_clean
+
+## PASS: nothing
+# This pass just walks the tree.
+PASS_NOTHING        := Nothing
+PASS_NOTHING_trgs   := do-nothing
+PASS_NOTHING_vars   :=
+PASS_NOTHING_pass   := nothing
+# alias
+nothing: pass_nothing
+
+## DEFAULT_PASSES
+# The default passes and their order.
+DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS
+
+## PASSES
+# The passes that should be defined. This must include
+# all passes mentioned by DEFAULT_PASSES.
+PASSES := $(DEFAULT_PASSES) NOTHING CLEAN
+
 
 #
Index: /trunk/kBuild/tools/ALP.kmk
===================================================================
--- /trunk/kBuild/tools/ALP.kmk	(revision 352)
+++ /trunk/kBuild/tools/ALP.kmk	(revision 353)
@@ -57,5 +57,5 @@
 define TOOL_ALP_COMPILE_AS
 #$ (warning dbg: TOOL_ALP_COMPILE_AS: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
-$(obj): $(deps) $(source) | $(dirdep)
+$(obj) $(outbase).lst: $(deps) $(source) | $(dirdep)
 	$(call MSG_L2,Compiling $$@ using ALP)
 	$(TOOL_ALP_AS) \
@@ -69,3 +69,2 @@
 endef
 
-
Index: /trunk/kBuild/tools/GCC.kmk
===================================================================
--- /trunk/kBuild/tools/GCC.kmk	(revision 352)
+++ /trunk/kBuild/tools/GCC.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild Tool Config - Generic GCC.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -139,5 +139,5 @@
 ## Link program
 # @param    $(target)   Normalized main target name.
-# @param    $(exe)		Program name.
+# @param    $(out)		Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -152,6 +152,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC_LINK_PROGRAM
-#$ (warning dbg: TOOL_GCC_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_GCC_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -167,7 +167,7 @@
 
 
-## Link program
+## Link DLL
 # @param    $(target)   Normalized main target name.
-# @param    $(exe)		Program name.
+# @param    $(out)		Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -182,6 +182,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC_LINK_DLL
-#$ (warning dbg: TOOL_GCC_LINK_DLL: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_GCC_LINK_DLL: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -189,5 +189,5 @@
 endif
 	$(TOOL_GCC_LD) $(TOOL_GCC_LDFLAGS.dll) $(flags) -o $$@ $(objs) \
-	$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
+		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
 ifneq ($(custom_post),)
 	$(eval $(custom_post))
Index: /trunk/kBuild/tools/GCC3.kmk
===================================================================
--- /trunk/kBuild/tools/GCC3.kmk	(revision 352)
+++ /trunk/kBuild/tools/GCC3.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild Tool Config - Generic GCC.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -146,5 +146,5 @@
 define TOOL_GCC3_LINK_LIBRARY_ADDMOD
 
-	echo "ADDMOD $(o)" >> $$@.ar-script
+	echo "ADDMOD $(o)" >> $(lib).ar-script
 endef
 
@@ -153,5 +153,5 @@
 	$(MKDIR) -p $(dir $(outbase))ar.extract/$(notdir $(srclib))
 	cd $(dir $(outbase))ar.extract/$(notdir $(srclib)) && $(TOOL_GCC3_AR) x $(srclib)
-	for o in `$(TOOL_GCC3_AR) t $(srclib)`; do echo "ADDMOD $(dir $(outbase))ar.extract/$(notdir $(srclib))/$$$${o}" >> $$@.ar-script; done
+	for o in `$(TOOL_GCC3_AR) t $(srclib)`; do echo "ADDMOD $(dir $(outbase))ar.extract/$(notdir $(srclib))/$$$${o}" >> $(lib).ar-script; done
 endef
 
@@ -162,11 +162,13 @@
 	$(RM) -f $$@
 ifneq ($(strip $(filter %.a %.lib,$(othersrc))),)
-	echo "CREATE $$@" > $$@.ar-script
+	echo "CREATE $$@" > $(lib).ar-script
 	$(foreach o, $(objs),$(TOOL_GCC3_LINK_LIBRARY_ADDMOD))
 	$(foreach srclib, $(filter %.a %.lib,$(othersrc)),$(TOOL_GCC3_LINK_LIBRARY_EXPAND_LIB))
-	echo "SAVE" >> $$@.ar-script
-	echo "END" >> $$@.ar-script
-	$(TOOL_GCC3_AR) -M < $$@.ar-script
+	echo "SAVE" >> $(lib).ar-script
+	echo "END" >> $(lib).ar-script
+	$(TOOL_GCC3_AR) -M < $(lib).ar-script
 	$(RM) -Rf "$(dir $(outbase))ar.extract/"
+
+_OUT_FILES += $(lib).ar-script
 else
 	$(TOOL_GCC3_AR) $(flags) $$@ $(objs)
@@ -178,5 +180,5 @@
 ## Link program
 # @param    $(target)   Normalized main target name.
-# @param    $(exe)		Program name.
+# @param    $(out)		Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -191,6 +193,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC3_LINK_PROGRAM
-#$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out) $(outbase).map: $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -212,5 +214,5 @@
 ## Link DLL
 # @param    $(target)   Normalized main target name.
-# @param    $(dll)		Program name.
+# @param    $(out)		Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -225,6 +227,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC3_LINK_DLL
-#$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(dll): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out) $(outbase).map: $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -233,5 +235,5 @@
 	$(RM) -f $$@
 	$(TOOL_GCC3_LD) $(TOOL_GCC3_LDFLAGS.dll) $(flags) -o $$@ \
-		$(if $(filter-out win32 os2, $(BUILD_TARGET)),$(call TOOL_GCC3_LD_SONAME,$(target),$(dll))) \
+		$(if $(filter-out win32 os2, $(BUILD_TARGET)),$(call TOOL_GCC3_LD_SONAME,$(target),$(out))) \
 		$(objs) \
 		$(foreach p,$(libpath), -L$(p)) \
@@ -247,5 +249,5 @@
 ## Link system module (windows aka driver, linux aka kernel module)
 # @param    $(target)   Normalized main target name.
-# @param    $(sys)		System module name.
+# @param    $(out)		System module name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -260,6 +262,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC3_LINK_SYSMOD
-#$ (warning dbg: TOOL_GCC3_LINK_SYSMOD: target=$(target) sys=$(sys) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
-$(sys): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_GCC3_LINK_SYSMOD: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(out) $(outbase).map: $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
Index: /trunk/kBuild/tools/GCC3OMF.kmk
===================================================================
--- /trunk/kBuild/tools/GCC3OMF.kmk	(revision 352)
+++ /trunk/kBuild/tools/GCC3OMF.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild Tool Config - OS/2 GCC v3 OMF.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -149,5 +149,5 @@
 ## Link program
 # @param    $(target)   Normalized main target name.
-# @param    $(exe)		Program name.
+# @param    $(out)		Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -162,6 +162,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC3OMF_LINK_PROGRAM
-#$ (warning dbg: TOOL_GCC3OMF_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(filter %.def, $(othersrc)) | $(dirdep)
+#$ (warning dbg: TOOL_GCC3OMF_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out) $(outbase).map: $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(filter %.def, $(othersrc)) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -183,5 +183,5 @@
 ## Link DLL
 # @param    $(target)   Normalized main target name.
-# @param    $(dll)		Program name.
+# @param    $(out)		Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -196,6 +196,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC3OMF_LINK_DLL
-#$ (warning dbg: TOOL_GCC3OMF_LINK_PROGRAM: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(dll): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(filter %.def, $(othersrc)) | $(dirdep)
+#$ (warning dbg: TOOL_GCC3OMF_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out) $(outbase).map: $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(filter %.def, $(othersrc)) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -216,5 +216,5 @@
 ## Link system module (windows aka driver, linux aka kernel module)
 # @param    $(target)   Normalized main target name.
-# @param    $(sys)		System module name.
+# @param    $(out)		System module name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -229,6 +229,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_GCC3OMF_LINK_SYSMOD
-#$ (warning dbg: TOOL_GCC3OMF_LINK_SYSMOD: target=$(target) sys=$(sys) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
-$(sys): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(filter %.def, $(othersrc)) | $(dirdep)
+#$ (warning dbg: TOOL_GCC3OMF_LINK_SYSMOD: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(out) $(outbase).map: $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(filter %.def, $(othersrc)) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
Index: /trunk/kBuild/tools/MINGW32.kmk
===================================================================
--- /trunk/kBuild/tools/MINGW32.kmk	(revision 352)
+++ /trunk/kBuild/tools/MINGW32.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild Tool Config - MINGW32 GCC.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -150,9 +150,9 @@
 ## Link library
 # @param    $(target)   Normalized main target name.
-# @param    $(lib)		Library name.
+# @param    $(lib)      Library name.
 # @param    $(objs)     Object files to put in the library.
 # @param    $(flags)    Flags.
 # @param    $(dirdep)   Directory creation dependency.
-# @param    $(deps)		Other dependencies.
+# @param    $(deps)     Other dependencies.
 #
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
@@ -169,5 +169,5 @@
 ## Link program
 # @param    $(target)   Normalized main target name.
-# @param    $(exe)		Program name.
+# @param    $(out)      Program name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -175,6 +175,6 @@
 # @param    $(flags)    Flags.
 # @param    $(dirdep)   Directory creation dependency.
-# @param    $(deps)		Other dependencies.
-# @param    $(othersrc) Unhandled sources.
+# @param    $(deps)     Other dependencies.
+# @param    $(othersrc)     Unhandled sources.
 # @param    $(custom_pre)   Custom step invoked before linking.
 # @param    $(custom_post)  Custom step invoked after linking.
@@ -182,6 +182,6 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_MINGW32_LINK_PROGRAM
-#$ (warning dbg: TOOL_MINGW32_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
-$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_MINGW32_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(out): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -198,7 +198,7 @@
 
 
-## Link system module (windows aka driver, linux aka kernel module)
-# @param    $(target)   Normalized main target name.
-# @param    $(dll)		System module name.
+## Link DLL.
+# @param    $(target)   Normalized main target name.
+# @param    $(out)      DLL name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -206,6 +206,6 @@
 # @param    $(flags)    Flags.
 # @param    $(dirdep)   Directory creation dependency.
-# @param    $(deps)		Other dependencies.
-# @param    $(othersrc) Unhandled sources.
+# @param    $(deps)     Other dependencies.
+# @param    $(othersrc)     Unhandled sources.
 # @param    $(custom_pre)   Custom step invoked before linking.
 # @param    $(custom_post)  Custom step invoked after linking.
@@ -213,6 +213,7 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_MINGW32_LINK_DLL
-#$ (warning dbg: TOOL_MINGW32_LINK_DLL: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
-$(dll): $(deps) $(call DIRDEP,$(PATH_LIB)) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
+#$ (warning dbg: TOOL_MINGW32_LINK_DLL: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(out) $(outbase).a $(outbase).exp: \
+		$(deps) $(call DIRDEP,$(PATH_LIB)) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -220,5 +221,5 @@
 endif
 	$(TOOL_MINGW32_DLLWRAP) $(flags) \
-		--dllname=$(dll) \
+		--dllname=$(out) \
 		--output-exp=$(outbase).exp \
 		--output-lib=$(outbase).a \
@@ -234,6 +235,6 @@
 	$(eval $(custom_post))
 endif
-_OUT_FILES += $(outbase).map $(outbase).a $(outbase).exp
-
-endef
-
+_OUT_FILES += $(outbase).a $(outbase).exp
+
+endef
+
Index: /trunk/kBuild/tools/NASM.kmk
===================================================================
--- /trunk/kBuild/tools/NASM.kmk	(revision 352)
+++ /trunk/kBuild/tools/NASM.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild Tool Config - NASM	0.98 or later.
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -57,5 +57,5 @@
 define TOOL_NASM_COMPILE_AS
 #$ (warning dbg: TOOL_NASM_COMPILE_AS: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
-$(obj): $(deps) $(source) | $(dirdep)
+$(obj) $(outbase).lst: $(deps) $(source) | $(dirdep)
 	$(call MSG_L2,Compiling $$@ using NASM)
 	$(TOOL_NASM_AS) \
@@ -68,3 +68,2 @@
 endef
 
-
Index: /trunk/kBuild/tools/VCC70.kmk
===================================================================
--- /trunk/kBuild/tools/VCC70.kmk	(revision 352)
+++ /trunk/kBuild/tools/VCC70.kmk	(revision 353)
@@ -4,5 +4,5 @@
 # kBuild Tool Config - Visual C++ 7.0 (aka Visual .NET)
 #
-# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -84,9 +84,9 @@
 define TOOL_VCC70_COMPILE_C
 #$ (warning dbg: TOOL_VCC70_COMPILE_C: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
-$(obj): $(deps) $(source) | $(dirdep)
+$(obj) $(call TOOL_VCC70_PDB, $(outbase)-obj): $(deps) $(source) | $(dirdep)
 	$(call MSG_L2,Compiling $$@ using VCC70)
 	$(TOOL_VCC70_CC) -c\
 		$(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
-		-Fd$(outbase).pdb \
+		-Fd$(outbase)-obj.pdb \
 		-Fo$(obj)\
 		$(subst /,\\,$(call ABSPATH,$(source)))
@@ -95,5 +95,5 @@
 		$(subst /,\\,$(call ABSPATH,$(source)))\
 		| $(DEP_PRE) -f -s -o $(dep) -t $(obj) -
-_OUT_FILES += $(call TOOL_VCC70_PDB, $(outbase))
+_OUT_FILES += $(call TOOL_VCC70_PDB, $(outbase)-obj)
 
 endef
@@ -115,9 +115,9 @@
 define TOOL_VCC70_COMPILE_CXX
 #$ (warning dbg: TOOL_VCC70_COMPILE_CXX: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
-$(obj): $(deps) $(source) | $(dirdep)
+$(obj) $(call TOOL_VCC70_PDB, $(outbase)-obj): $(deps) $(source) | $(dirdep)
 	$(call MSG_L2,Compiling $$@ using VCC70)
 	$(TOOL_VCC70_CXX) -c\
 		$(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
-		-Fd$(outbase).pdb \
+		-Fd$(outbase)-obj.pdb \
 		-Fo$(obj)\
 		$(subst /,\\,$(call ABSPATH,$(source)))
@@ -126,5 +126,5 @@
 		$(subst /,\\,$(call ABSPATH,$(source)))\
 		| $(DEP_PRE) -f -s -o $(dep) -t $(obj) -
-_OUT_FILES += $(call TOOL_VCC70_PDB, $(outbase))
+_OUT_FILES += $(call TOOL_VCC70_PDB, $(outbase)-obj)
 
 endef
@@ -143,5 +143,5 @@
 define TOOL_VCC70_LINK_LIBRARY
 #$ (warning dbg: TOOL_VCC70_LINK_LIBRARY: target=$(target) lib=$(lib) objs=$(objs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) outbase=$(outbase))
-$(lib): $(deps) $(objs) $(othersrc) | $(dirdep)
+$(lib) $(outbase).lst $(outbase).exp $(call TOOL_VCC70_PDB, $(outbase)): $(deps) $(objs) $(othersrc) | $(dirdep)
 	$(call MSG_L1,Creating Library $$@)
 	$(RM) -f $$@
@@ -155,5 +155,5 @@
 ## Link program
 # @param    $(target)       Normalized main target name.
-# @param    $(exe)          Program name.
+# @param    $(out)          Program name.
 # @param    $(objs)         Object files to link together.
 # @param    $(libs)         Libraries to search.
@@ -168,6 +168,7 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_VCC70_LINK_PROGRAM
-#$ (warning dbg: TOOL_VCC70_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
-$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc) | $(dirdep)
+#$ (warning dbg: TOOL_VCC70_LINK_PROGRAM: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(out) $(outbase).map $(outbase).lib $(outbase).exp $(call TOOL_VCC70_PDB, $(outbase)) $(outbase).ilk: \
+		$(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -175,5 +176,5 @@
 endif
 	$(TOOL_VCC70_LD) $(flags) \
-		/OUT:$(exe) \
+		/OUT:$(out) \
 		/MAPINFO:EXPORTS /MAPINFO:LINES \
 		/MAP:$(outbase).map \
@@ -193,5 +194,5 @@
 ## Link system module (windows aka driver, linux aka kernel module)
 # @param    $(target)       Normalized main target name.
-# @param    $(sys)          System module name.
+# @param    $(out)          System module name.
 # @param    $(objs)         Object files to link together.
 # @param    $(libs)         Libraries to search.
@@ -206,6 +207,7 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_VCC70_LINK_SYSMOD
-#$ (warning dbg: TOOL_VCC70_LINK_SYSMOD: target=$(target) sys=$(sys) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
-$(sys): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc) | $(dirdep)
+#$ (warning dbg: TOOL_VCC70_LINK_SYSMOD: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(out) $(outbase).map $(outbase).lib $(outbase).exp $(call TOOL_VCC70_PDB, $(outbase)) $(outbase).ilk: \
+		$(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -213,5 +215,5 @@
 endif
 	$(TOOL_VCC70_LD) $(flags) \
-		/OUT:$(sys) \
+		/OUT:$(out) \
 		/MAPINFO:EXPORTS /MAPINFO:LINES \
 		/MAP:$(outbase).map \
@@ -229,7 +231,7 @@
 
 
-## Link system module (windows aka driver, linux aka kernel module)
-# @param    $(target)   Normalized main target name.
-# @param    $(dll)		System module name.
+## Link DLL.
+# @param    $(target)   Normalized main target name.
+# @param    $(out)      DLL name.
 # @param    $(objs)     Object files to link together.
 # @param    $(libs)     Libraries to search.
@@ -237,6 +239,6 @@
 # @param    $(flags)    Flags.
 # @param    $(dirdep)   Directory creation dependency.
-# @param    $(deps)		Other dependencies.
-# @param    $(othersrc) Unhandled sources.
+# @param    $(deps)     Other dependencies.
+# @param    $(othersrc)     Unhandled sources.
 # @param    $(custom_pre)   Custom step invoked before linking.
 # @param    $(custom_post)  Custom step invoked after linking.
@@ -244,6 +246,7 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_VCC70_LINK_DLL
-#$ (warning dbg: TOOL_VCC70_LINK_DLL: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
-$(dll): $(deps) $(call DIRDEP,$(PATH_LIB)) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc) | $(dirdep)
+#$ (warning dbg: TOOL_VCC70_LINK_DLL: target=$(target) out=$(out) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(out) $(outbase).map $(outbase).lib $(outbase).exp $(call TOOL_VCC70_PDB, $(outbase)) $(outbase).ilk: \
+		$(deps) $(call DIRDEP,$(PATH_LIB)) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc) | $(dirdep)
 	$(call MSG_L1,Creating Program $$@)
 ifneq ($(custom_pre),)
@@ -251,5 +254,5 @@
 endif
 	$(TOOL_VCC70_LD) $(flags) \
-		/OUT:$(dll) \
+		/OUT:$(out) \
 		/IMPLIB:$(outbase).lib \
 		/MAPINFO:EXPORTS /MAPINFO:LINES \
