Index: /trunk/kBuild/footer.kmk
===================================================================
--- /trunk/kBuild/footer.kmk	(revision 728)
+++ /trunk/kBuild/footer.kmk	(revision 729)
@@ -123,37 +123,4 @@
 # Basic macros
 #
-
-## Figure out the tool for a source
-# @param    target       source file
-# @param    source       normalized main target
-# @param    type         tooltype
-# @param    bld_trg      build target.
-# @param    bld_trg_arch build target architecture.
-# @remark 	Obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
-_SOURCE_TOOL = $(strip $(firstword \
-	$($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
-	$($(target)_$(source)_$(type)TOOL) \
-	$($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_$(source)_TOOL.$(bld_trg)) \
-	$($(target)_$(source)_TOOL) \
-	$($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(source)_$(type)TOOL.$(bld_trg)) \
-	$($(source)_$(type)TOOL) \
-	$($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(source)_TOOL.$(bld_trg)) \
-	$($(source)_TOOL) \
-	$($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_$(type)TOOL.$(bld_trg)) \
-	$($(target)_$(type)TOOL) \
-	$($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(target)_TOOL.$(bld_trg)) \
-	$($(target)_TOOL) \
-	$($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$($(type)TOOL.$(bld_trg)) \
-	$($(type)TOOL) \
-	$(TOOL.$(bld_trg).$(bld_trg_arch)) \
-	$(TOOL.$(bld_trg)) \
-	$(TOOL) ))
 
 ## Figure out the tool for a target.
@@ -193,14 +160,4 @@
 ,$(if $(subst :$(call no-root-slash,$(call no-drive,$(_fix_path))):,,:$(_fix_path):),$(_fix_path),$(abspath $2/$(_fix_path))))
 endif
-
-## Figure out where to put object files.
-# @param    $1      source file
-# @param    $2      normalized main target
-# @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_SUB_CURRENT)/sourcefile.c.
-# @remark 	obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
-_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename \
-	$(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_SUB_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
 
 ## Figure out where to put object files.
@@ -930,5 +887,5 @@
 $(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
 	$$(QUIET)$$(RM) -f $$@
-	$$(call MSG_L1,$$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst),Re-fetching,Fetching),Removing) $(target)...)
+	$$(call MSG_L1,$$(if $$(wildcard $(out).lst),$$(if $$(_TARGET_$(target)_DIGEST),Re-fetching,Removing),Fetching) $(target)...)
 	$$(QUIET)$$(if $$(wildcard $(out).lst      ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
 	$$(QUIET)$$(if  $$(_TARGET_$(target)_DIGEST),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out).lst,$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@))
@@ -1127,5 +1084,5 @@
 # @param    bld_trg_arch  Build target arch.
 # @param    bld_trg_cpu   Build target cpu.
-def_target_source_c_cpp_asm_rc_new = $(kb-src-one x)
+def_target_source_c_cpp_asm_rc_new = $(kb-src-one )
 ifneq ($(filter kb-src-one,$(KMK_FEATURES)),)
  def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new
@@ -1139,27 +1096,4 @@
 # @param    much-more...
 define def_target_sources
-
-# Apply any default path on the sources first.
-ifneq ($(defpath),)
- ifdef $(target)_SOURCES
-  $(target)_SOURCES := $(call abspathex,$($(target)_SOURCES),$(defpath))
- endif
- ifdef $(target)_SOURCES.$(bld_trg)
-  $(target)_SOURCES.$(bld_trg) := $(call abspathex,$($(target)_SOURCES.$(bld_trg)),$(defpath))
- endif
- ifdef $(target)_SOURCES.$(bld_trg).$(bld_trg_arch)
-  $(target)_SOURCES.$(bld_trg).$(bld_trg_arch) := $(call abspathex,$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)),$(defpath))
- endif
- ifdef $(target)_SOURCES.$(bld_trg_arch)
-  $(target)_SOURCES.$(bld_trg_arch) := $(call abspathex,$($(target)_SOURCES.$(bld_trg_arch)),$(defpath))
- endif
- ifdef $(target)_SOURCES.$(bld_trg_cpu)
-  $(target)_SOURCES.$(bld_trg_cpu) := $(call abspathex,$($(target)_SOURCES.$(bld_trg_cpu)),$(defpath))
- endif
- ifdef $(target)_SOURCES.$(bld_type)
-  $(target)_SOURCES.$(bld_type) := $(call abspathex,$($(target)_SOURCES.$(bld_type)),$(defpath))
- endif
-endif
-
 #$ (warning def_target_sources)
 # C sources
@@ -1194,5 +1128,5 @@
 # @param	$(definst)  The default _INST value.
 # @param	$(typevar)  The name of the variable with all the root targets of its type.
-# @obsolete Only library uses this now.
+# @remark   Only library uses this now.
 define def_target_install_pluss
 ifndef $(target)_NOINST
Index: /trunk/kBuild/gnumake-footer.kmk
===================================================================
--- /trunk/kBuild/gnumake-footer.kmk	(revision 728)
+++ /trunk/kBuild/gnumake-footer.kmk	(revision 729)
@@ -24,4 +24,47 @@
 #
 #
+
+## Figure out the tool for a source
+# @param    target       source file
+# @param    source       normalized main target
+# @param    type         tooltype
+# @param    bld_trg      build target.
+# @param    bld_trg_arch build target architecture.
+# @remark 	Obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
+_SOURCE_TOOL = $(strip $(firstword \
+	$($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
+	$($(target)_$(source)_$(type)TOOL) \
+	$($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(target)_$(source)_TOOL.$(bld_trg)) \
+	$($(target)_$(source)_TOOL) \
+	$($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(source)_$(type)TOOL.$(bld_trg)) \
+	$($(source)_$(type)TOOL) \
+	$($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(source)_TOOL.$(bld_trg)) \
+	$($(source)_TOOL) \
+	$($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(target)_$(type)TOOL.$(bld_trg)) \
+	$($(target)_$(type)TOOL) \
+	$($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(target)_TOOL.$(bld_trg)) \
+	$($(target)_TOOL) \
+	$($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$($(type)TOOL.$(bld_trg)) \
+	$($(type)TOOL) \
+	$(TOOL.$(bld_trg).$(bld_trg_arch)) \
+	$(TOOL.$(bld_trg)) \
+	$(TOOL) ))
+
+## Figure out where to put object files.
+# @param    $1      source file
+# @param    $2      normalized main target
+# @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_SUB_CURRENT)/sourcefile.c.
+# @remark 	obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
+_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename \
+	$(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_SUB_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
 
 
Index: /trunk/kBuild/subfooter.kmk
===================================================================
--- /trunk/kBuild/subfooter.kmk	(revision 728)
+++ /trunk/kBuild/subfooter.kmk	(revision 729)
@@ -57,5 +57,5 @@
 #
 MAKEFILE_CURRENT := $(call stack-pop,_SUB_MAKEFILE_STACK)
-PATH_SUB_CURRENT := $(abspath $(patsubst %/,%,$(dir $(MAKEFILE_CURRENT))))
+PATH_SUB_CURRENT := $(abspath $(dir $(MAKEFILE_CURRENT)))
 
 #
@@ -66,2 +66,3 @@
 endif
 
+
Index: /trunk/kBuild/subheader.kmk
===================================================================
--- /trunk/kBuild/subheader.kmk	(revision 728)
+++ /trunk/kBuild/subheader.kmk	(revision 729)
@@ -25,10 +25,12 @@
 #
 
-ifndef _SUB_MAKEFILE_STACK
+ifndef _SUB_MAKEFILE_NOT_FIRST
+
  #
  # The first time we just take the makefile context set by header.kmk.
  #
+ _SUB_MAKEFILE_NOT_FIRST := 1
  include $(PATH_KBUILD)/header.kmk
-
+ 
 else
 
@@ -63,10 +65,13 @@
  # Switch context.
  #
+
+ # push the current old makefile onto the stack.
+ $(call stack-push,_SUB_MAKEFILE_STACK,$(MAKEFILE_CURRENT))
+
+ # the current makefile is the 2nd from the end of the MAKEFILE_LIST (we're the last one).
  __tmp := $(MAKEFILE_LIST)
  $(call stack-popv,__tmp)
  MAKEFILE_CURRENT := $(call stack-top,__tmp)
- PATH_SUB_CURRENT := $(abspath $(patsubst %/,%,$(dir $(MAKEFILE_CURRENT))))
+ PATH_SUB_CURRENT := $(abspath $(dir $(MAKEFILE_CURRENT)))
 endif
 
-$(call stack-push,_SUB_MAKEFILE_STACK,$(MAKEFILE_CURRENT))
-
Index: /trunk/src/gmake/function.c
===================================================================
--- /trunk/src/gmake/function.c	(revision 728)
+++ /trunk/src/gmake/function.c	(revision 729)
@@ -1933,6 +1933,9 @@
 /* Return the absolute name of file NAME which does not contain any `.',
    `..' components nor any repeated path separators ('/').   */
-
-static char *
+#ifdef KMK
+char *
+#else
+static char *
+#endif 
 abspath (const char *name, char *apath)
 {
@@ -2454,6 +2457,6 @@
   { STRING_SIZE_TUPLE("kb-obj-base"),   1,  1,  0,  func_kbuild_object_base},
   { STRING_SIZE_TUPLE("kb-obj-suff"),   1,  1,  0,  func_kbuild_object_suffix},
-  { STRING_SIZE_TUPLE("kb-src-prop"),   3,  3,  0,  func_kbuild_source_prop},
-  { STRING_SIZE_TUPLE("kb-src-one"),    1,  1,  0,  func_kbuild_source_one},
+  { STRING_SIZE_TUPLE("kb-src-prop"),   4,  4,  0,  func_kbuild_source_prop},
+  { STRING_SIZE_TUPLE("kb-src-one"),    0,  1,  0,  func_kbuild_source_one},
 #endif 
 };
Index: /trunk/src/gmake/kbuild.c
===================================================================
--- /trunk/src/gmake/kbuild.c	(revision 728)
+++ /trunk/src/gmake/kbuild.c	(revision 729)
@@ -43,4 +43,112 @@
 #endif
 
+/* function.c */
+char * abspath(const char *name, char *apath);
+
+/**
+ * Applies the specified default path to any relative paths in *ppsz.
+ * 
+ * @param   pDefPath        The default path.
+ * @param   ppsz            Pointer to the string pointer. If we expand anything, *ppsz 
+ *                          will be replaced and the caller is responsible for calling free() on it.
+ * @param   pcch            IN: *pcch contains the current string length.
+ *                          OUT: *pcch contains the new string length.
+ * @param   pcchAlloc       *pcchAlloc contains the length allocated for the string. Can be NULL.
+ * @param   fCanFree        Whether *ppsz should be freed when we replace it.
+ */
+static void 
+kbuild_apply_defpath(struct variable *pDefPath, char **ppsz, int *pcch, int *pcchAlloc, int fCanFree)
+{
+    char *pszIterator;
+    const char *pszInCur;
+    unsigned int cchInCur;
+    unsigned int cRelativePaths; 
+
+    /* 
+     * The first pass, count the relative paths. 
+     */
+    cRelativePaths = 0;
+    pszIterator = *ppsz;
+    while ((pszInCur = find_next_token(&pszIterator, &cchInCur)))
+    {
+        /* is relative? */
+#ifdef HAVE_DOS_PATHS
+        if (pszInCur[0] != '/' && pszInCur[0] != '\\' && (cchInCur < 2 || pszInCur[1] != ':'))
+#else
+        if (pszInCur[0] != '/')
+#endif 
+            cRelativePaths++;
+    } 
+
+    /* 
+     * The second pass construct the new string. 
+     */
+    if (cRelativePaths)
+    {
+        const size_t cchOut = *pcch + cRelativePaths * (pDefPath->value_length + 1) + 1;
+        char *pszOut = xmalloc(cchOut);
+        char *pszOutCur = pszOut;
+        const char *pszInNextCopy = *ppsz;
+
+        cRelativePaths = 0;
+        pszIterator = *ppsz;
+        while ((pszInCur = find_next_token(&pszIterator, &cchInCur)))
+        {
+            /* is relative? */
+#ifdef HAVE_DOS_PATHS
+            if (pszInCur[0] != '/' && pszInCur[0] != '\\' && (cchInCur < 2 || pszInCur[1] != ':'))
+#else
+            if (pszInCur[0] != '/')
+#endif 
+            {
+                PATH_VAR(szAbsPathIn);
+                PATH_VAR(szAbsPathOut);
+
+                if (pDefPath->value_length + cchInCur + 1 >= GET_PATH_MAX)
+                    continue;
+
+                /* Create the abspath input. */
+                memcpy(szAbsPathIn, pDefPath->value, pDefPath->value_length);
+                szAbsPathIn[pDefPath->value_length] = '/';
+                memcpy(&szAbsPathIn[pDefPath->value_length + 1], pszInCur, cchInCur);
+                szAbsPathIn[pDefPath->value_length + 1 + cchInCur] = '\0';
+
+                if (abspath(szAbsPathIn, szAbsPathOut) != NULL)
+                {
+                    const size_t cchAbsPathOut = strlen(szAbsPathOut);
+                    assert(cchAbsPathOut <= pDefPath->value_length + 1 + cchInCur);
+
+                    /* copy leading input */
+                    if (pszInCur != pszInNextCopy)
+                    {
+                        const size_t cchCopy = pszInCur - pszInNextCopy;
+                        memcpy(pszOutCur, pszInNextCopy, cchCopy);
+                        pszOutCur += cchCopy;
+                    }
+                    pszInNextCopy = pszInCur + cchInCur;
+
+                    /* copy out the abspath. */
+                    memcpy(pszOutCur, szAbsPathOut, cchAbsPathOut);
+                    pszOutCur += cchAbsPathOut;
+                }
+            }
+        } 
+        /* the final copy (includes the nil). */
+        cchInCur = *ppsz + *pcch - pszInNextCopy;
+        memcpy(pszOutCur, pszInNextCopy, cchInCur);
+        pszOutCur += cchInCur;
+        *pszOutCur = '\0';
+        assert((size_t)(pszOutCur - pszOut) < cchOut);
+
+        /* set return values */
+        if (fCanFree)
+            free(*ppsz);
+        *ppsz = pszOut;
+        *pcch = pszOutCur - pszOut;
+        if (pcchAlloc)
+            *pcchAlloc = cchOut;
+    }
+}
+
 
 /**
@@ -157,8 +265,25 @@
 }
 
+/**
+ * Looks up a variable and applies default a path to all relative paths.
+ * The value_length field is valid upon successful return.
+ *
+ * @returns Pointer to the variable. NULL if not found.
+ * @param   pDefPath    The default path.
+ * @param   pszName     The variable name.
+ */
+static struct variable *
+kbuild_lookup_variable_defpath(struct variable *pDefPath, const char *pszName)
+{
+    struct variable *pVar = kbuild_lookup_variable(pszName);
+    if (pVar && pDefPath)
+        kbuild_apply_defpath(pDefPath, &pVar->value, &pVar->value_length, &pVar->value_alloc_len, 1);
+    return pVar;
+}
+
 /** Same as kbuild_lookup_variable except that a '%s' in the name string
  * will be substituted with the values of the variables in the va list.  */
 static struct variable *
-kbuild_lookup_variable_fmt_va(const char *pszNameFmt, va_list va)
+kbuild_lookup_variable_fmt_va(struct variable *pDefPath, const char *pszNameFmt, va_list va)
 {
     va_list va2;
@@ -206,4 +331,6 @@
     va_end(va2);
 
+    if (pDefPath)
+        return kbuild_lookup_variable_defpath(pDefPath, pszName);
     return kbuild_lookup_variable(pszName);
 }
@@ -212,10 +339,10 @@
  * will be substituted with the values of the variables in the ellipsis.  */
 static struct variable *
-kbuild_lookup_variable_fmt(const char *pszNameFmt, ...)
+kbuild_lookup_variable_fmt(struct variable *pDefPath, const char *pszNameFmt, ...)
 {
     struct variable *pVar;
     va_list va;
     va_start(va, pszNameFmt);
-    pVar = kbuild_lookup_variable_fmt_va(pszNameFmt, va);
+    pVar = kbuild_lookup_variable_fmt_va(pDefPath, pszNameFmt, va);
     va_end(va);
     return pVar;
@@ -240,35 +367,35 @@
     PropF2.value_length = strlen(pszPropF2);
 
-    if (    (pVar = kbuild_lookup_variable_fmt("%_%_%%.%.%",pTarget, pSource, pType, &PropF2, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%_%%.%",  pTarget, pSource, pType, &PropF2, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%_%%",    pTarget, pSource, pType, &PropF2))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%_%.%.%", pTarget, pSource, &PropF2, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%_%.%",   pTarget, pSource, &PropF2, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%_%",     pTarget, pSource, &PropF2))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%%.%.%",  pSource, pType, &PropF2, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%%.%",    pSource, pType, &PropF2, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%%",      pSource, pType, &PropF2))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%.%.%",   pSource, &PropF2, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%.%",     pSource, &PropF2, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%",       pSource, &PropF2))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%%.%.%",  pTarget, pType, &PropF2, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%%.%",    pTarget, pType, &PropF2, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%%",      pTarget, pType, &PropF2))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%.%.%",   pTarget, &PropF2, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%.%",     pTarget, &PropF2, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%_%",       pTarget, &PropF2))
-
-        ||  (pTool && (pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%.%",   pTool, pType, &PropF2, pBldTrg, pBldTrgArch)))
-        ||  (pTool && (pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%",     pTool, pType, &PropF2, pBldTrg)))
-        ||  (pTool && (pVar = kbuild_lookup_variable_fmt("TOOL_%_%%",       pTool, pType, &PropF2)))
-        ||  (pTool && (pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%.%",    pTool, &PropF2, pBldTrg, pBldTrgArch)))
-        ||  (pTool && (pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%",      pTool, &PropF2, pBldTrg)))
-        ||  (pTool && (pVar = kbuild_lookup_variable_fmt("TOOL_%_%",        pTool, &PropF2)))
-
-        ||  (pVar = kbuild_lookup_variable_fmt("%%.%.%",    pType, &PropF1, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%%.%",      pType, &PropF1, pBldTrg))
-        ||  (pVar = kbuild_lookup_variable_fmt("%%",        pType, &PropF1))
-        ||  (pVar = kbuild_lookup_variable_fmt("%.%.%",     &PropF1, pBldTrg, pBldTrgArch))
-        ||  (pVar = kbuild_lookup_variable_fmt("%.%",       &PropF1, pBldTrg))
+    if (    (pVar = kbuild_lookup_variable_fmt(NULL, "%_%_%%.%.%",pTarget, pSource, pType, &PropF2, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%_%%.%",  pTarget, pSource, pType, &PropF2, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%_%%",    pTarget, pSource, pType, &PropF2))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%_%.%.%", pTarget, pSource, &PropF2, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%_%.%",   pTarget, pSource, &PropF2, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%_%",     pTarget, pSource, &PropF2))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%%.%.%",  pSource, pType, &PropF2, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%%.%",    pSource, pType, &PropF2, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%%",      pSource, pType, &PropF2))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%.%.%",   pSource, &PropF2, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%.%",     pSource, &PropF2, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%",       pSource, &PropF2))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%%.%.%",  pTarget, pType, &PropF2, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%%.%",    pTarget, pType, &PropF2, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%%",      pTarget, pType, &PropF2))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%.%.%",   pTarget, &PropF2, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%.%",     pTarget, &PropF2, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%_%",       pTarget, &PropF2))
+
+        ||  (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%.%",   pTool, pType, &PropF2, pBldTrg, pBldTrgArch)))
+        ||  (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%",     pTool, pType, &PropF2, pBldTrg)))
+        ||  (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%",       pTool, pType, &PropF2)))
+        ||  (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%.%",    pTool, &PropF2, pBldTrg, pBldTrgArch)))
+        ||  (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%",      pTool, &PropF2, pBldTrg)))
+        ||  (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%",        pTool, &PropF2)))
+
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%%.%.%",    pType, &PropF1, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%%.%",      pType, &PropF1, pBldTrg))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%%",        pType, &PropF1))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%.%.%",     &PropF1, pBldTrg, pBldTrgArch))
+        ||  (pVar = kbuild_lookup_variable_fmt(NULL, "%.%",       &PropF1, pBldTrg))
         ||  (pVar = kbuild_lookup_variable(pszPropF1))
        )
@@ -651,4 +778,5 @@
 
 /* releases resources allocated in the kbuild_get_sdks. */
+static void
 kbuild_put_sdks(struct kbuild_sdks *pSdks)
 {
@@ -799,5 +927,5 @@
     {
         struct variable    *pVar;
-        size_t              cchExp;
+        int                 cchExp;
         char               *pszExp;
     } *paVars;
@@ -817,17 +945,17 @@
     iVar = 0;
     /* the tool (lowest priority) */
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%",      pTool, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%",    pTool, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%",    pTool, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%",    pTool, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%.%",  pTool, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%.%",    pTool, &Prop, pBldTrgCpu);
-
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%%",     pTool, pType, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%",   pTool, pType, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%",   pTool, pType, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%",   pTool, pType, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%.%", pTool, pType, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("TOOL_%_%%.%",   pTool, pType, &Prop, pBldTrgCpu);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%",      pTool, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%",    pTool, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%",    pTool, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%",    pTool, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%.%",  pTool, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%.%",    pTool, &Prop, pBldTrgCpu);
+
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%",     pTool, pType, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%",   pTool, pType, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%",   pTool, pType, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%",   pTool, pType, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%.%", pTool, pType, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "TOOL_%_%%.%",   pTool, pType, &Prop, pBldTrgCpu);
 
     /* the global sdks */
@@ -838,33 +966,33 @@
     {
         struct variable *pSdk = &pSdks->pa[iSdk];
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%",      pSdk, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
-
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%",     pSdk, pType, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%",      pSdk, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
+
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%",     pSdk, pType, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
     }
 
     /* the globals */
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%",      &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%.%",    &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%.%",    &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%.%",    &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%.%.%",  &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%.%",    &Prop, pBldTrgCpu);
-
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%%",     pType, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%%.%",   pType, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%%.%",   pType, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%%.%",   pType, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%%.%.%", pType, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%%.%",   pType, &Prop, pBldTrgCpu);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%",      &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%.%",    &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%.%",    &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%.%",    &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%.%.%",  &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%.%",    &Prop, pBldTrgCpu);
+
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%%",     pType, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%%.%",   pType, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%%.%",   pType, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%%.%",   pType, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%%.%.%", pType, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "%%.%",   pType, &Prop, pBldTrgCpu);
 
     /* the target sdks */
@@ -875,33 +1003,33 @@
     {
         struct variable *pSdk = &pSdks->pa[iSdk];
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%",      pSdk, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
-
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%",     pSdk, pType, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%",      pSdk, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
+
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%",     pSdk, pType, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
     }
 
     /* the target */
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%",      pTarget, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pTarget, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pTarget, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pTarget, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%.%",  pTarget, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pTarget, &Prop, pBldTrgCpu);
-
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%",     pTarget, pType, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pTarget, pType, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pTarget, pType, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pTarget, pType, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%.%", pTarget, pType, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pTarget, pType, &Prop, pBldTrgCpu);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%",      pTarget, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pTarget, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pTarget, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pTarget, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%.%",  pTarget, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pTarget, &Prop, pBldTrgCpu);
+
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%",     pTarget, pType, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pTarget, pType, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pTarget, pType, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pTarget, pType, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%.%", pTarget, pType, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pTarget, pType, &Prop, pBldTrgCpu);
 
     /* the source sdks */
@@ -912,33 +1040,33 @@
     {
         struct variable *pSdk = &pSdks->pa[iSdk];
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%",      pSdk, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
-
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%",     pSdk, pType, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%",      pSdk, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
+
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%",     pSdk, pType, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
     }
 
     /* the source */
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%",      pSource, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pSource, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pSource, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pSource, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%.%",  pSource, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%.%",    pSource, &Prop, pBldTrgCpu);
-
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%",     pSource, pType, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pSource, pType, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pSource, pType, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pSource, pType, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%.%", pSource, pType, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%%.%",   pSource, pType, &Prop, pBldTrgCpu);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%",      pSource, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pSource, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pSource, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pSource, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%.%",  pSource, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%.%",    pSource, &Prop, pBldTrgCpu);
+
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%",     pSource, pType, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pSource, pType, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pSource, pType, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pSource, pType, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%.%", pSource, pType, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%%.%",   pSource, pType, &Prop, pBldTrgCpu);
 
 
@@ -950,33 +1078,33 @@
     {
         struct variable *pSdk = &pSdks->pa[iSdk];
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%",      pSdk, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
-
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%",     pSdk, pType, &Prop);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
-        paVars[iVar++].pVar = kbuild_lookup_variable_fmt("SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%",      pSdk, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%.%",  pSdk, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%.%",    pSdk, &Prop, pBldTrgCpu);
+
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%",     pSdk, pType, &Prop);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldType);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrg);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%.%", pSdk, pType, &Prop, pBldTrg, pBldTrgArch);
+        paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, "SDK_%_%%.%",   pSdk, pType, &Prop, pBldTrgCpu);
     }
 
     /* the target + source */
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%",      pTarget, pSource, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%.%",    pTarget, pSource, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%.%",    pTarget, pSource, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%.%",    pTarget, pSource, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%.%.%",  pTarget, pSource, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%.%",    pTarget, pSource, &Prop, pBldTrgCpu);
-
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%%",     pTarget, pSource, pType, &Prop);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldType);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldTrg);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%%.%.%", pTarget, pSource, pType, &Prop, pBldTrg, pBldTrgArch);
-    paVars[iVar++].pVar = kbuild_lookup_variable_fmt("%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldTrgCpu);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%",      pTarget, pSource, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%.%",    pTarget, pSource, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%.%",    pTarget, pSource, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%.%",    pTarget, pSource, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%.%.%",  pTarget, pSource, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%.%",    pTarget, pSource, &Prop, pBldTrgCpu);
+
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%%",     pTarget, pSource, pType, &Prop);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldType);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldTrg);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%%.%.%", pTarget, pSource, pType, &Prop, pBldTrg, pBldTrgArch);
+    paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, "%_%_%%.%",   pTarget, pSource, pType, &Prop, pBldTrgCpu);
 
     assert(cVars == iVar);
@@ -1004,7 +1132,6 @@
         }
         if (pDefPath)
-        {
-            /** @todo */
-        }
+            kbuild_apply_defpath(pDefPath, &paVars[iVar].pszExp, &paVars[iVar].cchExp, NULL,
+                                 paVars[iVar].pszExp != paVars[iVar].pVar->value);
         cchTotal += paVars[iVar].cchExp + 1;
     }
@@ -1041,4 +1168,5 @@
     struct variable *pTarget = kbuild_get_variable("target");
     struct variable *pSource = kbuild_get_variable("source");
+    struct variable *pDefPath = NULL;
     struct variable *pType = kbuild_get_variable("type");
     struct variable *pTool = kbuild_get_variable("tool");
@@ -1056,4 +1184,6 @@
     else
         fatal(NILF, _("incorrect direction argument `%s'!"), argv[2]);
+    if (argv[3])
+        pDefPath = kbuild_get_variable("defpath");
 
     kbuild_get_sdks(&Sdks, pTarget, pSource, pBldType, pBldTrg, pBldTrgArch);
@@ -1061,5 +1191,5 @@
     pVar = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType,
                                       pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu,
-                                      NULL,
+                                      pDefPath,
                                       argv[0], argv[1], iDirection);
     if (pVar)
@@ -1212,4 +1342,8 @@
     size_t cch;
     struct kbuild_sdks Sdks;
+
+    /*
+     * Gather properties.
+     */
     kbuild_get_sdks(&Sdks, pTarget, pSource, pBldType, pBldTrg, pBldTrgArch);
 
@@ -1218,10 +1352,18 @@
     pDefs  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
                                         "DEFS", "defs", 1/* left-to-right */);
-    pIncs  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
+    pIncs  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
                                         "INCS", "incs", -1/* right-to-left */);
-    pFlags = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
+    pFlags = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
                                         "FLAGS", "flags", 1/* left-to-right */);
     pDeps  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
                                         "DEPS", "deps", 1/* left-to-right */);
+
+    /*
+     * If we've got a default path, we must expand the source now.
+     * If we do this too early, "<source>_property = stuff" won't work becuase 
+     * our 'source' value isn't what the user expects.
+     */
+    if (pDefPath)
+        kbuild_apply_defpath(pDefPath, &pSource->value, &pSource->value_length, &pSource->value_alloc_len, 1 /* can free */);
 
     /*
