Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 471)
+++ trunk/kBuild/footer.kmk	(revision 472)
@@ -147,7 +147,7 @@
 # @remark There are two major hacks here:
 #           1. Source files in the output directory are translated into a gen/ subdir.
-#         	2. Catch anyone specifying $(PATH_CURRENT)/sourcefile.c.
+#         	2. Catch anyone specifying $(PATH_SUB_CURRENT)/sourcefile.c.
 _OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename \
-	$(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
+	$(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_SUB_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
 
 ## Figure out where to put object files.
@@ -457,5 +457,5 @@
 		$($(target)_$(source)_DEPORD_)
 	$(call MSG_L1,Creating $$@)
-	$(RM) -f $(dep) $(out) $($(target)_$(source)_OUTPUT_)
+	$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_)
 	$(custom_pre)
 
Index: trunk/kBuild/header.kmk
===================================================================
--- trunk/kBuild/header.kmk	(revision 471)
+++ trunk/kBuild/header.kmk	(revision 472)
@@ -248,5 +248,11 @@
 #
 ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
+
 PATH_CURRENT        := $(abspath $(CURDIR))
+ifneq ($(strip $(SUB_DEPTH)),)
+PATH_SUB_CURRENT    := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
+else
+PATH_SUB_CURRENT    := $(PATH_CURRENT)
+endif
 PATH_ROOT           := $(abspath $(PATH_CURRENT)/$(DEPTH))
 
@@ -254,5 +260,10 @@
 
 PATH_CURRENT        := $(CURDIR)
-# Get the real root path.
+PATH_SUB_CURRENT    := $(PATH_CURRENT)
+ifneq ($(strip $(SUB_DEPTH)),)
+ifneq ($(SUB_DEPTH),.)
+$(foreach d,$(subst /, ,$(SUB_DEPTH)), $(eval PATH_SUB_CURRENT := $(patsubst %/,%,$(dir $(PATH_SUB_CURRENT)))) )
+endif
+endif
 PATH_ROOT           := $(PATH_CURRENT)
 ifneq ($(DEPTH),.)
@@ -261,7 +272,8 @@
 
 endif
+
 # Subdirectory relative to the root.
 ifneq ($(PATH_ROOT),$(PATH_CURRENT))
-CURSUBDIR           := $(patsubst $(PATH_ROOT)/%,%,$(PATH_CURRENT))
+CURSUBDIR           := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_CURRENT))
 else
 CURSUBDIR           := .
Index: trunk/kBuild/subfooter.kmk
===================================================================
--- trunk/kBuild/subfooter.kmk	(revision 472)
+++ trunk/kBuild/subfooter.kmk	(revision 472)
@@ -0,0 +1,31 @@
+# $Id: $
+## @file
+#
+# kBuild - File included at bottom of a makefile or sub-makefile.
+#
+# Copyright (c) 2006 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
+#
+#
+
+_SUB_MAKEFILE_STACK := $(filter-out $(words $(_SUB_MAKEFILE_STACK)), $(_SUB_MAKEFILE_STACK))
+ifeq ($(words $(_SUB_MAKEFILE_STACK)),0)
+include $(PATH_KBUILD)/footer.kmk
+endif
+
Index: trunk/kBuild/subheader.kmk
===================================================================
--- trunk/kBuild/subheader.kmk	(revision 472)
+++ trunk/kBuild/subheader.kmk	(revision 472)
@@ -0,0 +1,33 @@
+# $Id: $
+## @file
+#
+# kBuild - File included at top of a makefile or sub-makefile.
+#
+# Copyright (c) 2006 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 _SUB_MAKEFILE_STACK
+_SUB_MAKEFILE_STACK := 1
+include $(PATH_KBUILD)/header.kmk
+else
+_SUB_MAKEFILE_STACK := $(_SUB_MAKEFILE_STACK) $(words $(_SUB_MAKEFILE_STACK) 1)
+endif
+
