Index: trunk/src/VBox/Main/Config.kmk
===================================================================
--- trunk/src/VBox/Main/Config.kmk	(revision 49802)
+++ trunk/src/VBox/Main/Config.kmk	(revision 49803)
@@ -27,4 +27,5 @@
 # Globals.
 #
-VBOX_MAIN_APIWRAPPER_INCS := $(call TARGET_PATH,VBoxAPIWrap)
+VBOX_MAIN_APIWRAPPER_DIR  := $(abspath $(call TARGET_PATH,VBoxAPIWrap))
+VBOX_MAIN_APIWRAPPER_INCS := $(VBOX_MAIN_APIWRAPPER_DIR)
 
Index: trunk/src/VBox/Main/Makefile.kmk
===================================================================
--- trunk/src/VBox/Main/Makefile.kmk	(revision 49802)
+++ trunk/src/VBox/Main/Makefile.kmk	(revision 49803)
@@ -174,7 +174,5 @@
 LIBRARIES += VBoxAPIWrap
 VBoxAPIWrap_TEMPLATE        = VBoxMainLib
-VBoxAPIWrap_SOURCES         = $(VBoxAPIWrap_VBOX_GENERATEDCPP)
-VBoxAPIWrap_VBOX_GENERATEDCPP = $(filter %.cpp,$(VBoxAPIWrap_VBOX_GENERATEDSOURCES))
-VBoxAPIWrap_VBOX_GENERATEDSOURCES = $(addprefix $(VBoxAPIWrap_0_OUTDIR)/,$(VBoxAPIWrap_VBOX_APIWRAPPERFILES))
+VBoxAPIWrap_SOURCES         = $(filter %.cpp,$(VBOX_MAIN_APIWRAPPER_GEN_FILES))
 VBoxAPIWrap_VBOX_RAWSRC     = \
 	$(VBoxAPIWrap_0_OUTDIR)/apiwrappers
@@ -189,4 +187,7 @@
 	$(wildcard $(VBoxAPIWrap_0_OUTDIR)/*.h) \
 	$(VBoxAPIWrap_VBOX_RAWSRC)
+
+# This include file (generated at the bottom of this file), defines
+# VBOX_MAIN_APIWRAPPER_GEN_FILES and VBOX_MAIN_APIWRAPPER_GEN_HDRS.
 VBoxAPIWrap_VBOX_KMK_FILE   = $(PATH_OUT)/vboxapiwrap.kmk
 include $(VBoxAPIWrap_VBOX_KMK_FILE)
@@ -292,6 +293,4 @@
 VBoxSVC_CXXFLAGS = $(filter-out -Wno-unused,$(TEMPLATE_VBOXMAINEXE_CXXFLAGS))
 
-VBoxSVC_DEPS = $(filter %.h,$(VBoxAPIWrap_VBOX_GENERATEDSOURCES))
-
 VBoxSVC_INCS = \
 	include \
@@ -322,5 +321,6 @@
 	$(VBOX_MAIN_PREREQS) \
 	$(VBOX_XML_SCHEMADEFS_H) \
-	$(VBOX_AUTOGEN_EVENT_H)
+	$(VBOX_AUTOGEN_EVENT_H) \
+	$(VBOX_MAIN_APIWRAPPER_GEN_HDRS)
 
 VBoxSVC_SOURCES = \
@@ -620,6 +620,4 @@
 endif
 
-VBoxC_DEPS = $(filter %.h,$(VBoxAPIWrap_VBOX_GENERATEDSOURCES))
-
 VBoxC_INCS          = \
 	include \
@@ -659,5 +657,6 @@
 	$(VBOX_MAIN_PREREQS) \
 	$(VBOX_XML_SCHEMADEFS_H) \
-	$(VBOX_AUTOGEN_EVENT_H)
+	$(VBOX_AUTOGEN_EVENT_H) \
+	$(VBOX_MAIN_APIWRAPPER_GEN_HDRS)
 
 VBoxC_SOURCES = \
@@ -1054,5 +1053,5 @@
 # Moved those rules to the end so that VBoxAPIWrap_0_OUTDIR can be expanded without $$ trickery.
 $(VBoxAPIWrap_VBOX_RAWSRC) \
-+| $(VBoxAPIWrap_VBOX_GENERATEDSOURCES): \
++| $(VBOX_MAIN_APIWRAPPER_GEN_FILES): \
 		$(VBOX_XIDL_FILE) \
 		$(VBoxAPIWrap_XSLT) \
@@ -1060,5 +1059,5 @@
 		| $$(dir $$@)
 	$(call MSG_L1,Generating C++ Server API wrapper files from XIDL)
-	$(QUIET)$(RM) -f $(filter-out $(VBoxAPIWrap_VBOX_GENERATEDSOURCES),$(wildcard $(VBoxAPIWrap_0_OUTDIR)/*.cpp) $(wildcard $(VBoxAPIWrap_0_OUTDIR)/*.h))
+	$(QUIET)$(RM) -f $(filter-out $(VBOX_MAIN_APIWRAPPER_GEN_FILES),$(wildcard $(VBoxAPIWrap_0_OUTDIR)/*.cpp) $(wildcard $(VBoxAPIWrap_0_OUTDIR)/*.h))
 	$(QUIET)$(VBOX_XSLTPROC) --stringparam filelistonly "" -o $@ $(VBoxAPIWrap_XSLT) $<
 	$(QUIET)$(VBOX_FILESPLIT) $@ $(VBoxAPIWrap_0_OUTDIR)
@@ -1068,5 +1067,8 @@
 	$(QUIET)$(RM) -f $@
 	$(QUIET)$(MKDIR) -p $(@D)
-	$(QUIET)$(VBOX_XSLTPROC) --stringparam filelistonly VBoxAPIWrap_VBOX_APIWRAPPERFILES -o $@ $(VBoxAPIWrap_XSLT) $<
+	$(QUIET)$(VBOX_XSLTPROC) --stringparam filelistonly VBOX_MAIN_APIWRAPPER_GEN_FILES -o $@ $(VBoxAPIWrap_XSLT) $<
+	$(QUIET)$(APPEND) -n "$@" "" "" \
+		'VBOX_MAIN_APIWRAPPER_GEN_FILES := $$(addprefix $$(VBOX_MAIN_APIWRAPPER_DIR)/,$$(VBOX_MAIN_APIWRAPPER_GEN_FILES))' \
+		'VBOX_MAIN_APIWRAPPER_GEN_HDRS = $$(filter %.h,$$(VBOX_MAIN_APIWRAPPER_GEN_FILES))'
 	$(QUIET)$(CP) --changed -fv $@ $(VBoxAPIWrap_VBOX_KMK_FILE)
 
Index: trunk/src/VBox/Main/testcase/Makefile.kmk
===================================================================
--- trunk/src/VBox/Main/testcase/Makefile.kmk	(revision 49802)
+++ trunk/src/VBox/Main/testcase/Makefile.kmk	(revision 49803)
@@ -110,13 +110,20 @@
 # tstCollector
 #
+# Note! VBOX_MAIN_APIWRAPPER_GEN_HDRS is only defined if kmk is executed a
+#       parent directory.  Since the rules for generating the files listed by
+#       the variable lives in the parent makefile, this is not a problem.
+#
 tstCollector_TEMPLATE = VBOXMAINCLIENTTSTEXE
 tstCollector_SOURCES  = \
 	tstCollector.cpp \
 	../src-server/Performance.cpp
-tstCollector_INCS     = ../include $(VBOX_MAIN_APIWRAPPER_INCS)
-tstCollector_DEFS    += VBOX_COLLECTOR_TEST_CASE
-tstCollector_LDFLAGS.darwin  += -lproc
-tstCollector_LDFLAGS.solaris += -lkstat -lnvpair
-tstCollector_LDFLAGS.win     += psapi.lib powrprof.lib
+tstCollector_INCS            = \
+	../include \
+	$(VBOX_MAIN_APIWRAPPER_INCS)
+tstCollector_INTERMEDIATES   = $(VBOX_MAIN_APIWRAPPER_GEN_HDRS)
+tstCollector_DEFS            = VBOX_COLLECTOR_TEST_CASE
+tstCollector_LDFLAGS.darwin  = -lproc
+tstCollector_LDFLAGS.solaris = -lkstat -lnvpair
+tstCollector_LDFLAGS.win     = psapi.lib powrprof.lib
 
 
