Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 1420)
+++ trunk/kBuild/footer.kmk	(revision 1424)
@@ -1952,18 +1952,51 @@
 
 
-## Generic macro for processing C, C++ and Assembly sources.
-# @param    $(target)     Normalized target name.
-# @param    $(source)     Source file name.
-# @param    $(type)       Source type. {C,CXX,AS,OBJC}
-# @param    bld_type      Build type.
-# @param    bld_trg       Build target.
-# @param    bld_trg_arch  Build target arch.
-# @param    bld_trg_cpu   Build target cpu.
-def_target_source_c_cpp_objc_asm_rc_new = $(kb-src-one )
-ifdef KMK_VERSION
- def_target_source_c_cpp_objc_asm_rc_var = def_target_source_c_cpp_objc_asm_rc_new
+## def_src_handler_*
+#
+# @{
+define def_src_handler_c
+$(warning def_src_handler_c: source=$(source))
+type := C
+ $(kb-src-one )
+endef
+
+define def_src_handler_cxx
+type := CXX
+ $(kb-src-one )
+endef
+
+define def_src_handler_objc
+type := OBJC
+ $(kb-src-one )
+endef
+
+define def_src_handler_asm
+type := AS
+ $(kb-src-one )
+endef
+
+define def_src_handler_rc
+type := RC
+ $(kb-src-one )
+endef
+
+define def_src_handler_obj
+$(target)_OBJS_ += $(source)
+endef
+## @}
+
+## Handle one source.
+# .
+define def_src_handler_one
+suff := $(suffix $(source))
+src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
+handler := $(patsubst $(suff):%,%,$(src_handler))
+#$ (warning def_src_handler_one: source=$(source) suff=$(suff) src_handler=$(src_handler) handler=$(handler))
+ifneq ($(handler),)
+$(eval $(value $(handler)))
 else
- def_target_source_c_cpp_objc_asm_rc_var = def_target_source_c_cpp_objc_asm_rc_old
-endif
+othersrc += $(sources)
+endif
+endef
 
 ## Generic macro for processing all target sources.
@@ -1971,30 +2004,16 @@
 # @param    $(defpath)
 # @param    much-more...
+# @returns	othersrc, $(target)_OBJS_, ++
 define def_target_sources
-#$ (warning def_target_sources)
-# C sources
-type := C
-$(foreach source, $(filter %.c             , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
-   ,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
-
-# C++ sources
-type := CXX
-$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
-
-# Objective-C sources
-type := OBJC
-$(foreach source, $(filter %.m,              $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
-
-# ASM sources
-type := AS
-$(foreach source, $(filter %.asm %.s %.S   , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
-
-# Resource sources
-type := RC
-$(foreach source, $(filter %.rc            , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
-	,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
+
+target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
+$(foreach source,\
+	$($(target)_SOURCES)\
+	$($(target)_SOURCES.$(bld_trg))\
+	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
+	$($(target)_SOURCES.$(bld_trg_arch))\
+	$($(target)_SOURCES.$(bld_trg_cpu))\
+	$($(target)_SOURCES.$(bld_type))\
+	,$(eval $(value def_src_handler_one)) )
 
 endef
@@ -2081,4 +2100,5 @@
 $(target)_OBJS_ :=
 defpath := $($(target)_PATH)
+othersrc :=
 
 # source -> object
@@ -2106,19 +2126,4 @@
 	$($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
 	$($(target)_ARFLAGS.$(bld_trg_cpu))
-othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.m %.s %.S %.asm %.rc %.o %.obj %.res,\
-	$($(target)_SOURCES) \
-	$($(target)_SOURCES.$(bld_trg)) \
-	$($(target)_SOURCES.$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg_cpu)) \
-	$($(target)_SOURCES.$(bld_type)))
-objs         = $(filter %.o %.obj %.res, \
-	$($(target)_SOURCES) \
-	$($(target)_SOURCES.$(bld_trg)) \
-	$($(target)_SOURCES.$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg_cpu)) \
-	$($(target)_SOURCES.$(bld_type))) \
-    $($(target)_OBJS_)
 dirdep      := $(call DIRDEP,$(dir $(out)))
 deps        := $($(target)_DEPS)
@@ -2127,5 +2132,5 @@
 # Adjust paths if we got a default path.
 ifneq ($(defpath),)
- objs := $(abspathex $(objs),$(defpath))
+ $(target)_OBJS_ := $(abspathex $($(target)_OBJS_),$(defpath))
  deps := $(abspathex $(deps),$(defpath))
  orderdeps := $(abspathex $(orderdeps),$(defpath))
@@ -2196,4 +2201,7 @@
 endif
 
+# eliminate this guy?
+objs = $($(target)_OBJS_)
+
 # dependency file
 dep := $(out)$(SUFF_DEP)
@@ -2231,5 +2239,5 @@
 $(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
 $(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
-$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
+$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_OBJS_)
 $(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
 
@@ -2298,4 +2306,5 @@
 $(target)_OBJS_  :=
 defpath := $($(target)_PATH)
+othersrc :=
 
 # source -> object
@@ -2353,19 +2362,4 @@
 	$($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
 	$($(target)_LDFLAGS.$(bld_trg_cpu))
-othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.m %.s %.S %.asm %.rc %.o %.obj %.res,\
-	$($(target)_SOURCES)\
-	$($(target)_SOURCES.$(bld_trg)) \
-	$($(target)_SOURCES.$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg_cpu)) \
-	$($(target)_SOURCES.$(bld_type)))
-objs         = $(filter %.o %.obj %.res, \
-	$($(target)_SOURCES) \
-	$($(target)_SOURCES.$(bld_trg)) \
-	$($(target)_SOURCES.$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_SOURCES.$(bld_trg_cpu)) \
-	$($(target)_SOURCES.$(bld_type))) \
-	$($(target)_OBJS_)
 libs        :=\
 	$($(target)_LIBS.$(bld_trg_cpu))\
@@ -2457,5 +2451,5 @@
 ifneq ($(defpath),)
  libpath := $(abspathex $(libpath),$(defpath))
- objs := $(abspathex $(objs),$(defpath))
+ $(target)_OBJS_ := $(abspathex $($(target)_OBJS_),$(defpath))
  deps := $(abspathex $(deps),$(defpath))
  orderdeps := $(abspathex $(orderdeps),$(defpath))
@@ -2526,4 +2520,7 @@
 endif
 
+# eliminate this guy?
+objs = $($(target)_OBJS_)
+
 # installation targets
 ifndef $(target)_NOINST
@@ -2578,5 +2575,5 @@
 $(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
 $(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
-$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
+$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_OBJS_)
 $(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
 
Index: trunk/kBuild/header.kmk
===================================================================
--- trunk/kBuild/header.kmk	(revision 1420)
+++ trunk/kBuild/header.kmk	(revision 1424)
@@ -584,4 +584,28 @@
 DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
 
+## KBUILD_SRC_HANDLERS
+# The list of source handlers, pair of extension and handler.
+# The user can overload this list to provide additional or custom
+# handlers. On a per-target/template see SRC_HANDLERS.
+KBUILD_SRC_HANDLERS := \
+  .c:def_src_handler_c \
+  .C:def_src_handler_c \
+.cxx:def_src_handler_cxx \
+.CXX:def_src_handler_cxx \
+.cpp:def_src_handler_cxx \
+.CPP:def_src_handler_cxx \
+ .cc:def_src_handler_cxx \
+ .CC:def_src_handler_cxx \
+  .m:def_src_handler_objc \
+.asm:def_src_handler_asm \
+.ASM:def_src_handler_asm \
+  .s:def_src_handler_asm \
+  .S:def_src_handler_asm \
+ .rc:def_src_handler_rc \
+.obj:def_src_handler_obj \
+  .o:def_src_handler_obj \
+.res:def_src_handler_obj \
+.lib:def_src_handler_obj \
+  .a:def_src_handler_obj \
 
 ## PROPS_TOOLS
@@ -639,5 +663,5 @@
 # will do the necessary inheritance from templates to targets.
 PROPS_ACCUMULATE_L := \
-	SDKS SOURCES \
+	SDKS SOURCES SRC_HANDLERS \
 	INCS CINCS CXXINCS OBJCINCS ASINCS RCINCS \
 	LIBS LIBPATH \
@@ -646,5 +670,5 @@
 # Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
 PROPS_ACCUMULATE_L_LNK := \
-	SDKS SOURCES \
+	SDKS SOURCES SRC_HANDLERS \
 	INCS CINCS CXXINCS OBJCINCS ASINCS RCINCS \
 	BLDDIRS CLEAN
