Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 72)
+++ trunk/kBuild/footer.kmk	(revision 73)
@@ -30,4 +30,5 @@
 #
 # Variables.
+# (Some of these need initialization before including definitions using them.)
 #
 
@@ -47,4 +48,28 @@
 endef
 $(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
+
+# misc
+type :=
+
+
+#
+# Basic macros
+#
+
+## Figure out the tool for a source
+# @param    $1      source file
+# @param    $2      normalized main target
+_SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL) )
+
+## Figure out where to put object files.
+# @param    $1      source file
+# @param    $2      normalized main target
+_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
+
+## Figure out where to put object files.
+# @param    $1      real target name.
+# @param    $2      normalized main target
+_TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
+
 
 #
@@ -154,5 +179,5 @@
 #
 # Include SDKs
-# 			
+#
 _SDKS := $(SDKS)
 define def_sdks_target_source
@@ -175,43 +200,108 @@
 $(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
 
+#
+# Object processing.
+#
+
+## 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}
+#
+# @remark   I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
+define def_target_source_c_cpp_asm
+#$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
+
+$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target)))
+$(eval defs        :=\
+	$($(target)_$(source)_$(type)DEFS)\
+	$($(target)_$(source)_DEFS)\
+	$($(source)_$(type)DEFS)\
+	$($(source)_DEFS)\
+	$($(target)_$(type)DEFS)\
+	$($(target)_DEFS)\
+	$(DEFS)\
+	$(TOOL_$(tool)_$(type)DEFS)\
+	)
+$(eval incs        :=\
+	$($(target)_$(source)_$(type)INCS)\
+	$($(target)_$(source)_INCS)\
+	$($(source)_$(type)INCS)\
+	$($(source)_INCS)\
+	$($(target)_$(type)INCS)\
+	$($(target)_INCS)\
+	$(INCS)\
+	$(TOOL_$(tool)_$(type)INCS)\
+	)
+$(eval flags        :=\
+	$(TOOL_$(tool)_$(type)FLAGS)\
+	$(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
+	$($(type)FLAGS)\
+	$($(type)FLAGS.$(BUILD_TYPE))\
+	$($(target)_$(type)FLAGS)\
+	$($(target)_$(type)FLAGS.$(BUILD_TYPE))\
+	$($(source)_$(type)FLAGS)\
+	$($(source)_$(type)FLAGS.$(BUILD_TYPE))\
+	$($(target)_$(source)_$(type)FLAGS)\
+	$($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
+	)
+$(eval outbase     := $(call _OBJECT_BASE,$(source),$(target)))
+$(eval dirdep      := $(dir $(outbase)).dir_created)
+$(eval objsuff     := $(firstword $($(target)_$(source)_OBJSUFF) $($(source)_OBJSUFF) $($(target)_OBJSUFF) $(TOOL_$(tool)_$(type)OBJSUFF) $(SUFF_OBJ)))
+$(eval obj         := $(outbase)$(objsuff))
+$(eval depfile     := $(outbase)$(SUFF_DEP))
+
+#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
+$(eval $(TOOL_$(tool)_COMPILE_$(type)))
+
+$(eval _OBJS_$(target) += $(obj))
+$(eval _DEPFILES       += $(dep))
+
+endef
+
+## Generic macro for processing all target sources.
+# @param    $target     Normalized target name.
+define def_target_sources
+#$ (warning def_target_sources)
+# C sources
+$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
+	,$(eval $(def_target_source_c_cpp_asm)) ))
+
+# C++ sources
+$(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
+	,$(eval $(def_target_source_c_cpp_asm)) ))
+
+# ASM sources
+$(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
+	,$(eval $(def_target_source_c_cpp_asm)) ))
+endef
+
 
 #
 # LIBRARIES
-#		
-
-## Figure out the tool for a source
-# @param    $1      source file
-# @param    $2      normalized main target
-_SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL))
-## Figure out where to put object files.
-# @param    $1      source file
-# @param    $2      normalized main target
-_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $1)
-	
+#
+
 ## Library (one).
 # @param    $(lib)  Library name
 define def_lib
-#$ (warning dbg: Processing library $(target))
-
-# C++ sources
-#$(foreach o, $(filter %.cpp,$($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
-#$(foreach o, $(filter %.cxx,$($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
-#$(foreach o, $(filter %.cc, $($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
-
-# C sources
-$(foreach source, $(filter %.c, $($(target)_SOURCES)), \
-	$(eval $(call TOOL_$(call _SOURCE_TOOL,$(source),$(target))_COMPILE_C,$(call _OBJECT_BASE,$(source),$(target)),$(source),$(target)) ) )
-
-## ASM sources
-#$(foreach o, $(filter %.asm,$($1_SOURCES)), $(eval $(call def_lib_asm,$1,$o)))
-						
+# source -> object
+$(eval $(def_target_sources))
+
 # library
-#$$(PATH_TARGET)/$1$(SUFF_LIB): \
-#		$$(PATH_TARGET) \
-#		$$(_OBJS_$1)
-#	$$(AR) $($1_ARFLAGS) $(ARFLAGS) $(AROUT)$$(@:/=\) $$(_OBJS_$1)
-#
-_OBJS += $(_OBJS_$(target))		
-_LIBS += $(PATH_TARGET)/$1$(SUFF_LIB)
+$(eval tool        := $(firstword $($(target)_TOOL) $(TOOL)))
+$(eval flags       := $($(target)_ARFLAGS) $(ARFLAGS) $(TOOL_$(tool)_ARFLAGS))
+$(eval libsuff     := $(firstword $($(target)_LIBSUFF) $($(target)_LIBSUFF) $(TOOL_$(tool)_ARLIBSUFF) $(SUFF_LIB)))
+## @todo prefix
+$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
+$(eval lib         := $(outbase)$(libsuff))
+$(eval objs         = $(_OBJS_$(target)))
+$(eval dirdep      := $(dir $(lib)).dir_created)
+## @todo fix dependencies
+$(eval deps        := )
+
+$(eval $(TOOL_$(tool)_LINK_LIBRARY))
+
+_OBJS += $(_OBJS_$(target))
+_LIBS += $(lib)
 endef
 
@@ -257,6 +347,7 @@
 define def_createdir
 $(dirfile):
+	$(call MSG_L1,Creating directory $$(@D))
 	$(MKDIR) -p $$(@D)
-	echo dir_created > $$@
+	@echo dir_created > $$@
 endef
 
@@ -270,4 +361,8 @@
 
 objs: $(_OBJS)
+	echo "dbg: _OBJS = $(_OBJS)"
+
+libs: $(_LIBS)
+	echo "dbg: _LIBS = $(_LIBS)"
 
 
Index: trunk/kBuild/header.kmk
===================================================================
--- trunk/kBuild/header.kmk	(revision 72)
+++ trunk/kBuild/header.kmk	(revision 73)
@@ -194,4 +194,32 @@
 EXEC_X86_WIN32      :=
 HOSTSUFF_EXE        := .exe
+endif
+
+#
+# Build target setup.
+#
+ifeq ($(BUILD_TARGET),os2)
+SUFF_OBJ            := .obj
+SUFF_LIB            := .lib
+SUFF_DLL            := .dll
+SUFF_EXE            := .exe
+SUFF_DRV            := .sys
+SUFF_RES            := .res
+endif
+ifeq ($(BUILD_TARGET),win32)
+SUFF_OBJ            := .obj
+SUFF_LIB            := .lib
+SUFF_DLL            := .dll
+SUFF_EXE            := .exe
+SUFF_DRV            := .sys
+SUFF_RES            := .res
+endif
+ifeq ($(BUILD_TARGET),linux)
+SUFF_OBJ            := .o
+SUFF_LIB            := .a
+SUFF_DLL            := .so
+SUFF_EXE            :=
+SUFF_DRV            := .a
+SUFF_RES            :=
 endif
 
@@ -215,4 +243,25 @@
 
 #
+# Message macros.
+#					
+ifndef BUILD_QUIET
+MSG_L1		= @echo "kBuild: $1"
+ifdef BUILD_VERBOSE
+MSG_L2		= @echo "kBuild: $1"
+else
+MSG_L2		=
+endif
+ifdef BUILD_DEBUG
+MSG_L3      = @echo "kBuild: $1"
+else
+MSG_L3      =
+endif
+else
+MSG_L1		=
+MSG_L2      =
+MSG_L3      =
+endif
+
+#
 # This is how we find the closest config.kmk.
 # It's a little hacky but I think it works fine.
Index: trunk/kBuild/tools/GCC.kmk
===================================================================
--- trunk/kBuild/tools/GCC.kmk	(revision 72)
+++ trunk/kBuild/tools/GCC.kmk	(revision 73)
@@ -27,5 +27,7 @@
 
 TOOL_GCC                := Generic GCC
+
 TOOL_GCC_CC             := gcc$(HOSTSUFF_EXE)
+TOOL_GCC_COBJSUFF       := .o
 TOOL_GCC_CFLAGS         := -g
 TOOL_GCC_CFLAGS.debug   := -O0
@@ -33,25 +35,58 @@
 TOOL_GCC_CFLAGS.profile := -pg
 TOOL_GCC_CINCS          :=
+TOOL_GCC_CDEFS          :=
+
+TOOL_GCC_CC             := gcc$(HOSTSUFF_EXE)
+TOOL_GCC_CXXOBJSUFF     := .o
+
+TOOL_GCC_AS             := as$(HOSTSUFF_EXE)
+TOOL_GCC_ASOBJSUFF      := .o
+
+TOOL_GCC_AR             := ar$(HOSTSUFF_EXE)
+TOOL_GCC_ARFLAGS        := cr
+TOOL_GCC_ARLIBSUFF      := .a
 
 
 ## Compile C source.
-# @param    $1  Output basename (full).
-# @param    $2  Source filename (relative).
-# @param    $3  Normalized main target name.
+# @param    $(target)   Normalized main target name.
+# @param    $(source)   Source filename (relative).
+# @param	$(obj)      Object file name. This shall be (re)created by the compilation.
+# @param    $(dep)	    Dependcy file. This shall be (re)created by the compilation.
+# @param    $(flags)    Flags.
+# @param    $(defs)     Definitions. No -D or something.
+# @param    $(incs)     Includes. No -I or something.
+# @param	$(dirdep)   Directory creation dependency.
+#
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+# @param	$(objsuff)  Object suffix.
 define TOOL_GCC_COMPILE_C
-#$ (warning dbg GCC: 1=$1 2=$2 3=$3 4=$4 5=$5)
-$1.o: $(PATH_CURRENT)/$2 $(dir $1).dir_created
-	$(TOOL_GCC_CC) -c \
-		$($3_$2_CFLAGS) $($3_$2_CFLAGS.$(BUILD_TYPE)) \
-		$($2_CFLAGS) $($2_CFLAGS.$(BUILD_TYPE)) \
-		$($3_CFLAGS) $($3_CFLAGS.$(BUILD_TYPE)) \
-		$(TOOL_GCC_CFLAGS) $(TOOL_GCC_CFLAGS.$(BUILD_TYPE)) \
-		$(addprefix -I, $($3_$2_CINCS) $($3_$2_INCS) $($2_CINCS) $($2_INCS) $($3_CINCS) $($3_INCS) $(INCS) \
-						$(TOOL_GCC_CINCS)) \
-		$(addprefix -D, $($3_$2_CDEFS) $($3_$2_DEFS) $($2_CDEFS) $($2_DEFS) $($3_CDEFS) $($3_DEFS) $(DEFS) $(TOOL_GCC_CDEFS)) \
-		-o $$@ -Wp,-MT,$1$(SUFF_DEP) -Wp,-MD,$$@ \
-        $(PATH_CURRENT)/$2		
-_OBJS_$(3) += $1.o
-_DEPFILES += $1$(SUFF_DEP)
+#$ (warning dbg: GCC: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
+$(obj): $(dirdep) $(PATH_CURRENT)/$(source)
+	$(call MSG_L2,Compiling $$@ using GCC)
+	$(TOOL_GCC_CC) -c\
+		$(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
+		-Wp,-MT,$(dep) -Wp,-MD,$$@\
+		-o $$@\
+        $(PATH_CURRENT)/$(source)		
+		
 endef
 
+
+## Link library
+# @param    $(target)   Normalized main target 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    $(outbase)  Output basename (full). Use this for list files and such.
+define TOOL_GCC_LINK_LIBRARY
+#$ (warning dbg: GCC: target=$(target) lib=$(lib) objs=$(objs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) outbase=$(outbase))
+$(lib): $(dirdep) $(objs) $(deps)
+	$(call MSG_L1,Creating Library $$@)
+	$(RM) -f $$@
+	$(TOOL_GCC_AR) $(flags) $$@ $(objs)
+	
+endef
+
