Index: trunk/kBuild/Examples/Library/Makefile
===================================================================
--- trunk/kBuild/Examples/Library/Makefile	(revision 72)
+++ trunk/kBuild/Examples/Library/Makefile	(revision 72)
@@ -0,0 +1,15 @@
+# $Id$
+
+#
+# Library example file.
+#
+
+
+TEMPLATE			:= mylib								
+LIBRARIES           := libHello
+libHello_SOURCES    := hello.c
+libHello_TEMPLATE   := mylib
+
+DEPTH = ../../..
+include $(DEPTH)/kBuild/rules.kmk
+
Index: trunk/kBuild/Examples/Library/config.kmk
===================================================================
--- trunk/kBuild/Examples/Library/config.kmk	(revision 72)
+++ trunk/kBuild/Examples/Library/config.kmk	(revision 72)
@@ -0,0 +1,22 @@
+
+# define template mylib
+TEMPLATE_mylib := Sample template for testing kBuild
+TEMPLATE_mylib_TOOL       := GCC
+TEMPLATE_mylib_DEFS       := MYLIB_DEFS
+TEMPLATE_mylib_INCS       := /mylib_incs
+
+TEMPLATE_mylib_CDEFS      := MYLIB_CDEFS
+TEMPLATE_mylib_CINCS      := /mylib_cincs
+TEMPLATE_mylib_CFLAGS     := -DMYLIB_CFLAGS=1
+TEMPLATE_mylib_COPTS      := Debug
+
+TEMPLATE_mylib_CXXDEFS    := MYLIB_CXXDEFS
+TEMPLATE_mylib_CXXINCS    := /mylib_cxxincs
+TEMPLATE_mylib_CXXFLAGS   := -DMYLIB_CXXFLAGS=1
+TEMPLATE_mylib_CXXOPTS    := Debug
+
+TEMPLATE_mylib_ASDEFS     := MYLIB_ASDEFS
+TEMPLATE_mylib_ASINCS     := /mylib_asincs
+TEMPLATE_mylib_ASFLAGS    := -DMYLIB_ASFLAGS=1
+TEMPLATE_mylib_ASOPTS     := Debug
+						
Index: trunk/kBuild/Examples/Library/hello.c
===================================================================
--- trunk/kBuild/Examples/Library/hello.c	(revision 72)
+++ trunk/kBuild/Examples/Library/hello.c	(revision 72)
@@ -0,0 +1,6 @@
+#include <stdio.h>
+int main()
+{
+    printf("hello world\n");
+    return 0;
+}
Index: trunk/kBuild/Examples/Outline/Makefile.kmk
===================================================================
--- trunk/kBuild/Examples/Outline/Makefile.kmk	(revision 71)
+++ trunk/kBuild/Examples/Outline/Makefile.kmk	(revision 72)
@@ -15,5 +15,5 @@
 LIBRARIES = helloworld
 
-#include $(DEPTH)/kBuild/footer.kMk
+include $(DEPTH)/kBuild/footer.kMk
 	
 ok:
Index: trunk/kBuild/cfg/x86.win32.vc2003.kmk
===================================================================
--- trunk/kBuild/cfg/x86.win32.vc2003.kmk	(revision 71)
+++ trunk/kBuild/cfg/x86.win32.vc2003.kmk	(revision 72)
@@ -31,5 +31,5 @@
 X86_WIN32_VC2003_CC_RELEASE         := -Ogitb2 -Oy-
 X86_WIN32_VC2003_CC_DEBUG           := -DDEBUG=1 -Od
-X86_WIN32_VC2003_CC_WARN            := -W4
+X86_WIN32_VC2003_CC_WARN            := -W3
 X86_WIN32_VC2003_CC_WARN_LOW        := -W2
 X86_WIN32_VC2003_CC_WARN_ALL        := -Wall
@@ -40,5 +40,5 @@
 X86_WIN32_VC2003_CXX_RELEASE        := -Ogitb2 -Oy-
 X86_WIN32_VC2003_CXX_DEBUG          := -DDEBUG=1 -Od
-X86_WIN32_VC2003_CXX_WARN           := -W4
+X86_WIN32_VC2003_CXX_WARN           := -W3
 X86_WIN32_VC2003_CXX_WARN_LOW       := -W2
 X86_WIN32_VC2003_CXX_WARN_ALL       := -Wall
@@ -59,10 +59,10 @@
 LIB_X86_WIN32_VC2003_MSCOREE        := $(PATH_X86_WIN32_VC2003_LIB)/lib/mscoree.lib
 LIB_X86_WIN32_VC2003_OLDNAMES       := $(PATH_X86_WIN32_VC2003_LIB)/lib/oldnames.lib
-			 
+			
 
 # @todo implement options
 
 
-# C++ sources: $1 == target root dir, $2 == source, $3 == normalized main target
+# C++ sources: $1 == output base name, $2 == source, $3 == normalized main target,
 define def_x86_win32_vc2003_compile_cxx
 $1/$(basename $2)$(SUFF_OBJ): $2 $(dir $1/$(basename $2))
Index: trunk/kBuild/config.kmk
===================================================================
--- trunk/kBuild/config.kmk	(revision 72)
+++ trunk/kBuild/config.kmk	(revision 72)
@@ -0,0 +1,117 @@
+# $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 skipme
+
+.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 72)
+++ trunk/kBuild/footer.kmk	(revision 72)
@@ -0,0 +1,276 @@
+# $Id$
+## @file
+#
+# kBuild - File included at top of makefile.
+#
+# Copyright (c) 2004 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
+#
+#
+
+ifndef __footer_kmk__
+# start-of-file-content
+
+#
+# Variables.
+#
+
+# all targets.
+ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(DRIVERS) $(OTHERS)
+
+# all of a type
+_OBJS   :=
+_LIBS   :=
+_DLLS   :=
+_EXES   :=
+_DIRS   :=
+
+# all objs of a specific target
+define def_objs_var
+_OBJS_$1 :=
+endef
+$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
+
+#
+# Include templates
+#
+_TEMPLATES := $(TEMPLATE)
+define def_templates
+ifdef $(target)_TEMPLATE
+_TEMPLATES += $($(target)_TEMPLATE)
+endif
+endef
+$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
+_TEMPLATES := $(sort $(_TEMPLATES))
+# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
+
+define def_templates_include
+ifndef TEMPLATE_$(template)
+include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
+endif
+endef
+$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
+	
+
+#
+# Common Inheritance
+#
+
+## Inherit defaults property
+# @param    $(prop)     Property name
+# @param    $(target)   Target name.
+define def_inherit_defaults_one
+ifndef $1_$(prop)
+ifdef $(prop)
+$1_$(prop) := $($(prop))
+endif
+endif
+endef
+
+## Inherit default properties for one target.
+# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
+# is inherited from the default properties.
+# @param    $(target)	Target name
+define def_inherit_defaults
+ifdef $(target)_TEMPLATE
+ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
+$(foreach prop, TOOL, $(eval $(def_inherit_defaults_one)))
+endif
+ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
+$(foreach prop, SDKS, $(eval $(def_inherit_defaults_one)))
+endif
+else
+$(foreach prop, TEMPLATE TOOL SDKS, $(eval $(def_inherit_defaults_one)))
+endif
+endef
+# Inherit default properties.
+$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
+
+
+## Inherit one template property.		
+# @param    $(prop)     Property name
+# @param    $(target)	Target name
+define def_inherit_template_one
+ifndef $(target)_$(prop)
+ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
+$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
+endif
+endif
+endef
+
+## Inherit template properties for on target.
+# @param    $(target)    Target name.
+define def_inherit_template
+$(foreach prop,TOOL SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS, \
+	$(eval $(def_inherit_template_one)))
+endef
+# Inherit template properties
+$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
+
+
+
+#
+# Include tools
+# 			
+_TOOLS := $(TOOL)
+define def_tools_target_source
+#$ (warning dbg: src=$(source))
+$(foreach tool,$($(source)_TOOL) $($(target)_$(source)_TOOL),\
+	$(eval _TOOLS += $(tool)))
+endef
+define def_tools_target
+#$ (warning dbg: trg=$(target))
+$(foreach tool, $($(target)_TOOL), $(eval _TOOLS += $(tool)))
+$(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
+endef
+$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
+_TOOLS := $(sort $(_TOOLS))
+#$ (warning dbg: _TOOLS=$(_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)))
+
+
+#
+# Include SDKs
+# 			
+_SDKS := $(SDKS)
+define def_sdks_target_source
+$(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
+	$(eval _SDKS += $(sdk)))
+endef
+define def_sdks_target
+$(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
+$(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
+endef
+$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
+_SDKS := $(sort $(_SDKS))
+#$ (warning dbg: _SDKS=$(_SDKS))
+
+define def_sdks_include
+ifndef SDK_$(sdk)
+include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
+endif
+endef
+$(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
+
+
+#
+# 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)))
+						
+# 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)
+endef
+
+# Process libraries
+$(foreach target, $(LIBRARIES), $(eval $(def_lib)))
+
+
+
+#
+# PROGRAMS
+#
+
+
+
+#
+# DLLS
+#
+
+
+
+#
+# DRIVERS
+#
+
+
+
+#
+# OTHERS
+#
+
+
+
+#
+# DOCS
+#
+
+
+#
+# Directories.
+#
+_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS))))
+
+define def_createdir
+$(dirfile):
+	$(MKDIR) -p $$(@D)
+	echo dir_created > $$@
+endef
+
+$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
+
+#
+# THE MAIN RULES
+#
+all_recursive:
+
+
+objs: $(_OBJS)
+
+
+# end-of-file-content
+__footer_kmk__ := 1
+endif # __footer_kmk__
Index: trunk/kBuild/header.kmk
===================================================================
--- trunk/kBuild/header.kmk	(revision 71)
+++ trunk/kBuild/header.kmk	(revision 72)
@@ -39,23 +39,95 @@
 SUFFIXES :=
 
-#
-# Environment unifications
+
+#
+# Assert build type.
 #
 ifndef BUILD_TYPE
 ifndef BUILD_MODE
-$(error "define BUILD_TYPE you moron!")
+$(error kBuild: You must define BUILD_TYPE!)
 endif
 BUILD_TYPE          := $(BUILD_MODE)
 endif
-
-
-#
-# .
-#
-PATH_ROOT := $(CURDIR)
-define def_root_dir
-PATH_ROOT := $(dir $(PATH_ROOT))
-endef
-PATH_ROOT
+ifeq ($(BUILD_TYPE),DEBUG)
+BUILD_TYPE          := debug
+endif
+ifeq ($(BUILD_TYPE),RELEASE)
+BUILD_TYPE          := release
+endif
+ifeq ($(BUILD_TYPE),PROFILE)
+BUILD_TYPE          := profile
+endif
+
+
+#
+# Assert build platform.
+#
+_BUILD_PLATFORM_OK  := 0
+# OS/2
+ifeq ($(BUILD_PLATFORM),OS2)
+BUILD_PLATFORM      := os2
+endif
+ifeq ($(BUILD_PLATFORM),os2)
+_BUILD_PLATFORM_OK  := 1
+endif
+
+# Linux
+ifeq ($(BUILD_PLATFORM),LINUX)
+BUILD_PLATFORM      := linux
+endif
+ifeq ($(BUILD_PLATFORM),linux)
+_BUILD_PLATFORM_OK  := 1
+endif
+
+# Win32
+ifeq ($(BUILD_PLATFORM),WIN32)
+BUILD_PLATFORM      := win32
+endif
+ifeq ($(BUILD_PLATFORM),WIN32)
+_BUILD_PLATFORM_OK  := 1
+endif
+
+ifeq ($(_BUILD_PLATFORM_OK),0)
+$(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
+endif
+
+
+#
+# Assert target platform.
+#
+ifndef BUILD_TARGET
+# not defined, set to the same as build platform
+BUILD_TARGET        := $(BUILD_PLATFORM)
+else
+_BUILD_TARGET_OK    := 0
+# OS/2
+ifeq ($(BUILD_TARGET),OS2)
+BUILD_TARGET        := os2
+endif
+ifeq ($(BUILD_TARGET),os2)
+_BUILD_TARGET_OK    := 1
+endif
+
+# Linux
+ifeq ($(BUILD_TARGET),LINUX)
+BUILD_TARGET        := linux
+endif
+ifeq ($(BUILD_TARGET),linux)
+_BUILD_TARGET_OK    := 1
+endif
+
+# Win32
+ifeq ($(BUILD_TARGET),WIN32)
+BUILD_TARGET        := win32
+endif
+ifeq ($(BUILD_TARGET),WIN32)
+_BUILD_TARGET_OK    := 1
+endif
+
+ifeq ($(_BUILD_TARGET_OK),0)
+$(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
+endif
+endif
+
 
 #
@@ -69,5 +141,5 @@
 endif
 # Subdirectory relative to the root.
-DIR_DEPTH           := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
+CURSUBDIR           := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
 # Output directories.
 PATH_OUT            := $(PATH_ROOT)/out/$(BUILD_TARGET)/$(BUILD_TYPE)
@@ -76,5 +148,5 @@
 PATH_LIB            := $(PATH_OUT)/lib
 PATH_DOC            := $(PATH_ROOT)/out/doc
-PATH_TARGET          = $(PATH_OUT)/$(DIR_DEPTH)
+PATH_TARGET         := $(PATH_OBJ)/$(CURSUBDIR)
 
 # Usually kBuild is external to the source tree.
@@ -91,4 +163,6 @@
 FILE_KBUILD_FOOTER  := $(PATH_KBUILD)/footer.kmk
 
+SUFF_DEP            := .dep
+
 
 #
@@ -99,13 +173,8 @@
 
 #
-# PLATFORMS (host)
-#
-_BUILD_PLATFORM_OK  := 0
+# Build platform setup.
+#
 # OS/2
-ifeq ($(BUILD_PLATFORM),OS2)
-_BUILD_PLATFORM_OK  := 1
-ifndef BUILD_TARGET
-BUILD_TARGET        := OS2
-endif
+ifeq ($(BUILD_PLATFORM),os2)
 PATH_TOOLS          := $(PATH_TOOLS_OS2)
 EXEC_X86_WIN32      := $(PATH_TOOLS)/bin/innopec.exe
@@ -114,9 +183,5 @@
 
 # Linux
-ifeq ($(BUILD_PLATFORM),LINUX)
-_BUILD_PLATFORM_OK  := 1
-ifndef BUILD_TARGET
-BUILD_TARGET        := LINUX
-endif
+ifeq ($(BUILD_PLATFORM),linux)
 PATH_TOOLS          := $(PATH_TOOLS_LNX)
 EXEC_X86_WIN32      := wine
@@ -125,17 +190,8 @@
 
 # Win32
-ifeq ($(BUILD_PLATFORM),WIN32)
-ifndef BUILD_TARGET
-BUILD_TARGET        := WIN32
-endif
-_BUILD_PLATFORM_OK  := 1
+ifeq ($(BUILD_PLATFORM),win32)
 PATH_TOOLS          := $(PATH_TOOLS_W32)
 EXEC_X86_WIN32      :=
 HOSTSUFF_EXE        := .exe
-endif
-
-# assert build platform
-ifeq ($(_BUILD_PLATFORM_OK),0)
-$(error "BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized")
 endif
 
@@ -180,4 +236,4 @@
 
 # end-of-file-content
-__header_kmk__  := 1
+__header_kmk__ := 1
 endif # __header_kmk__
Index: trunk/kBuild/programs.kmk
===================================================================
--- trunk/kBuild/programs.kmk	(revision 72)
+++ trunk/kBuild/programs.kmk	(revision 72)
@@ -0,0 +1,144 @@
+# $Id$
+## @file
+# This file deals with TARGET_PROGRAMS.
+# It should only be included from rules.kMk.
+#
+# 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
+#
+#
+
+# Assert correct context
+.ifndef __RULES_KMK__
+.error $(MAKEFILE) can only be included from rules.kMk.
+.endif
+
+
+## @page Makefile           Makefile
+#
+# A makefile defines a context. The context consists of a .CURDIR, .OBJDIR,
+# and stuff done by the config.kMk. Sources for instance is always relative
+# to .CURDIR, while objects and other output files are relative to .OBJDIR.
+#
+#
+# @todo move this page
+
+
+
+## @page TARGET_PROGRAMS    TARGET_PROGRAMS
+#
+# Programs to be made. On platforms which enforces extensions for programs
+# the default extension is added.
+# Modules listed in TARGET_PROGRAMS should NOT be listed TARGETS.
+#
+# Let's say TARGET_PROGRAMS = foo. Then you can configure the executable foo
+# using the following macros:
+#
+# foo_SOURCES   - The sources files which object files foo is linked to
+#                 together of.
+#
+# foo_TEMPLATE  - Compiler, linker, and more setup.
+#
+#
+# foo_DEFINES   - Defines used by all tools which support it. No -D should be
+#                 used as this is tool specific. Defines which have a value
+#                 must use '=' as assignment, foo_DEFINES=VER=1 for instance.
+#
+# foo_INCLUDES  - Include directories used by all tools which support it. No -I
+#                 or similar should be used as this is tool specific. Directories
+#                 are separated by ';'.
+#
+# foo_LIBS      - Libraries to link with.
+#
+#
+# C Compilers:
+# foo_CTOOL     - The C compiler tool to use.
+# foo_CDEFS     - C compiler defines.
+# foo_CINCS     - C compiler include directories.
+# foo_COPTS     - C compiler options. This is somewhat compiler independant.
+# foo_CFLAGS    - C compiler flags. Specifying compiler specific flags.
+#
+#
+# C++ Compilers:
+# foo_CXXTOOL   - The C++ compiler tool to use.
+# foo_CXXDEFS   - C++ compiler defines.
+# foo_CXXINCS   - C++ compiler include directories.
+# foo_CXXOPTS   - C++ compiler options. This is somewhat compiler independant.
+# foo_CXXFLAGS  - C++ compiler flags. Specifying compiler specific flags.
+#
+#
+# Assemblers:
+# foo_ASTOOL    - The assembler tool to use.
+# foo_ASDEFS    - Assembler defines.
+# foo_ASINCS    - Assembler include directories.
+# foo_ASOPTS    - Assembler options. This is somewhat assembler independant.
+# foo_ASFLAGS   - Assembler flags. Specifying compiler specific flags.
+#
+#
+# Resource Compilers:
+# foo_RCTOOL    - The Resource compiler tool to use.
+# foo_RCDEFS    - Resource compiler defines.
+# foo_RCINCS    - Resource compiler include directories.
+# foo_RCOPTS    - Resource compiler options. This is somewhat compiler independant.
+# foo_RCFLAGS   - Resource compiler flags. Specifying compiler specific flags.
+#
+#
+# Link Editors:
+# foo_LDTOOL    - The link editor tool to use.
+# foo_LDOPTS    - Link editor options. This is somewhat link editor independant.
+# foo_LDFLAGS   - Link editor flags. Specifying link editor specific flags.
+# foo_LDDEFFILE - Link editor definition file. (PC thingy)
+# foo_LDLIBS    - Link editor . (PC thingy)
+#
+#
+#
+
+
+#
+# Generate program rules.
+#
+.for trgt in ${TARGET_PROGRAMS}
+
+${trgt}_int_objects     :=
+TARGETS                 += ${trgt}${SFX_EXE}
+
+
+# rules for each of the C source files.
+.for src in ${${trgt}_SOURCES:M*.c}
+int_object              := ${src}
+${trgt}_int_objects     += ${int_object}
+
+.endfor
+
+#.for csrc in ${${trgt}_SOURCES:M${SFXS_C:S@^@*@}}
+.for csrc in ${${trgt}_SOURCES:M*.c}
+${trgt}__OBJECTS        += ${csrc:S@.${csrc:E}@${SFX_OBJ}@}
+${csrc:S@.${csrc:E}@${SFX_OBJ}@}: ${csrc}
+    echo "compiling ${.ALLSRC} -> $@"
+.endfor
+
+
+# linking rule
+${trgt}${SFX_EXE}: ${trgt}_int_objects
+    echo "$@"
+
+.endfor
+
+# clean up := variables we've used.
+
Index: trunk/kBuild/tools/GCC.kmk
===================================================================
--- trunk/kBuild/tools/GCC.kmk	(revision 72)
+++ trunk/kBuild/tools/GCC.kmk	(revision 72)
@@ -0,0 +1,57 @@
+# $Id$
+## @file
+#
+# kBuild Tool Config - Generic GCC.
+#
+# Copyright (c) 2004 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
+#
+#
+
+
+TOOL_GCC                := Generic GCC
+TOOL_GCC_CC             := gcc$(HOSTSUFF_EXE)
+TOOL_GCC_CFLAGS         := -g
+TOOL_GCC_CFLAGS.debug   := -O0
+TOOL_GCC_CFLAGS.release := -O2
+TOOL_GCC_CFLAGS.profile := -pg
+TOOL_GCC_CINCS          :=
+
+
+## Compile C source.
+# @param    $1  Output basename (full).
+# @param    $2  Source filename (relative).
+# @param    $3  Normalized main target name.
+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)
+endef
+
