Index: /trunk/Config.kmk
===================================================================
--- /trunk/Config.kmk	(revision 1502)
+++ /trunk/Config.kmk	(revision 1503)
@@ -64,6 +64,6 @@
 NIX_INSTALL_DIR_SHARE := $(patsubst /%,%,$(NIX_INSTALL_DIR))/share/kBuild
 DEFS += \
-	PATH_KBUILD=\"/$(NIX_INSTALL_DIR_SHARE)\" \
-	PATH_KBUILD_BIN=\"/$(NIX_INSTALL_DIR_BIN)\"
+	KBUILD_PATH=\"/$(NIX_INSTALL_DIR_SHARE)\" \
+	KBUILD_PATH_BIN=\"/$(NIX_INSTALL_DIR_BIN)\"
 endif
 
Index: /trunk/src/kmk/Makefile.am
===================================================================
--- /trunk/src/kmk/Makefile.am	(revision 1502)
+++ /trunk/src/kmk/Makefile.am	(revision 1503)
@@ -129,7 +129,7 @@
 	-DCONFIG_PRETTY_COMMAND_PRINTING \
 	\
-	-DBUILD_PLATFORM=\"$(BUILD_TARGET)\" \
-	-DBUILD_PLATFORM_ARCH=\"$(BUILD_TARGET_ARCH)\" \
-	-DBUILD_PLATFORM_CPU=\"$(BUILD_TARGET_CPU)\" \
+	-DKBUILD_HOST=\"$(BUILD_TARGET)\" \
+	-DKBUILD_HOST_ARCH=\"$(BUILD_TARGET_ARCH)\" \
+	-DKBUILD_HOST_CPU=\"$(BUILD_TARGET_CPU)\" \
 	\
 	-DKBUILD_VERSION_MAJOR=0 \
Index: /trunk/src/kmk/Makefile.kmk
===================================================================
--- /trunk/src/kmk/Makefile.kmk	(revision 1502)
+++ /trunk/src/kmk/Makefile.kmk	(revision 1503)
@@ -133,7 +133,7 @@
 	CONFIG_PRETTY_COMMAND_PRINTING \
 	\
-	BUILD_PLATFORM=\"$(BUILD_TARGET)\" \
-	BUILD_PLATFORM_ARCH=\"$(BUILD_TARGET_ARCH)\" \
-	BUILD_PLATFORM_CPU=\"$(BUILD_TARGET_CPU)\"
+	KBUILD_HOST=\"$(BUILD_TARGET)\" \
+	KBUILD_HOST_ARCH=\"$(BUILD_TARGET_ARCH)\" \
+	KBUILD_HOST_CPU=\"$(BUILD_TARGET_CPU)\"
 kmk_DEFS.x86 = CONFIG_WITH_OPTIMIZATION_HACKS
 kmk_DEFS.amd64 = CONFIG_WITH_OPTIMIZATION_HACKS
Index: /trunk/src/kmk/kbuild.c
===================================================================
--- /trunk/src/kmk/kbuild.c	(revision 1502)
+++ /trunk/src/kmk/kbuild.c	(revision 1503)
@@ -205,9 +205,9 @@
 
 /**
- * Determin the PATH_KBUILD value.
+ * Determin the KBUILD_PATH value.
  *
  * @returns Pointer to static a buffer containing the value (consider it read-only).
  */
-const char *get_path_kbuild(void)
+const char *get_kbuild_path(void)
 {
     static const char *s_pszPath = NULL;
@@ -215,18 +215,23 @@
     {
         PATH_VAR(szTmpPath);
-        const char *pszEnvVar = getenv("PATH_KBUILD");
+        const char *pszEnvVar = getenv("KBUILD_PATH");
         if (    !pszEnvVar
             ||  !my_abspath(pszEnvVar, szTmpPath))
         {
-#ifdef PATH_KBUILD
-            return s_pszPath = PATH_KBUILD;
+            const char *pszEnvVar = getenv("PATH_KBUILD");
+            if (    !pszEnvVar
+                ||  !my_abspath(pszEnvVar, szTmpPath))
+            {
+#ifdef KBUILD_PATH
+                return s_pszPath = KBUILD_PATH;
 #else
-            /* $(abspath $(PATH_KBUILD_BIN)/../..)*/
-            size_t cch = strlen(get_path_kbuild_bin());
-            char *pszTmp2 = alloca(cch + sizeof("/../.."));
-            strcat(strcpy(pszTmp2, get_path_kbuild_bin()), "/../..");
-            if (!my_abspath(pszTmp2, szTmpPath))
-                fatal(NILF, _("failed to determin PATH_KBUILD"));
-#endif
+                /* $(abspath $(KBUILD_BIN_PATH)/../..)*/
+                size_t cch = strlen(get_kbuild_bin_path());
+                char *pszTmp2 = alloca(cch + sizeof("/../.."));
+                strcat(strcpy(pszTmp2, get_kbuild_bin_path()), "/../..");
+                if (!my_abspath(pszTmp2, szTmpPath))
+                    fatal(NILF, _("failed to determin KBUILD_PATH"));
+#endif
+            }
         }
         s_pszPath = xstrdup(szTmpPath);
@@ -237,9 +242,9 @@
 
 /**
- * Determin the PATH_KBUILD_BIN value.
+ * Determin the KBUILD_BIN_PATH value.
  *
  * @returns Pointer to static a buffer containing the value (consider it read-only).
  */
-const char *get_path_kbuild_bin(void)
+const char *get_kbuild_bin_path(void)
 {
     static const char *s_pszPath = NULL;
@@ -247,30 +252,36 @@
     {
         PATH_VAR(szTmpPath);
-        const char *pszEnvVar = getenv("PATH_KBUILD_BIN");
+
+        const char *pszEnvVar = getenv("KBUILD_BIN_PATH");
         if (    !pszEnvVar
             ||  !my_abspath(pszEnvVar, szTmpPath))
         {
-#ifdef PATH_KBUILD
-            return s_pszPath = PATH_KBUILD_BIN;
+            const char *pszEnvVar = getenv("PATH_KBUILD_BIN");
+            if (    !pszEnvVar
+                ||  !my_abspath(pszEnvVar, szTmpPath))
+            {
+#ifdef KBUILD_PATH
+                return s_pszPath = KBUILD_BIN_PATH;
 #else
-            /* $(abspath $(dir $(ARGV0)).) */
-            size_t cch = strlen(g_pszExeName);
-            char *pszTmp2 = alloca(cch + sizeof("."));
-            char *pszSep = pszTmp2 + cch - 1;
-            memcpy(pszTmp2, g_pszExeName, cch);
-#ifdef HAVE_DOS_PATHS
-            while (pszSep >= pszTmp2 && *pszSep != '/' && *pszSep != '\\' && *pszSep != ':')
-#else
-            while (pszSep >= pszTmp2 && *pszSep != '/')
-#endif
-                pszSep--;
-            if (pszSep >= pszTmp2)
-              strcpy(pszSep + 1, ".");
-            else
-              strcpy(pszTmp2, ".");
-
-            if (!my_abspath(pszTmp2, szTmpPath))
-                fatal(NILF, _("failed to determin PATH_KBUILD_BIN (pszTmp2=%s szTmpPath=%s)"), pszTmp2, szTmpPath);
-#endif
+                /* $(abspath $(dir $(ARGV0)).) */
+                size_t cch = strlen(g_pszExeName);
+                char *pszTmp2 = alloca(cch + sizeof("."));
+                char *pszSep = pszTmp2 + cch - 1;
+                memcpy(pszTmp2, g_pszExeName, cch);
+# ifdef HAVE_DOS_PATHS
+                while (pszSep >= pszTmp2 && *pszSep != '/' && *pszSep != '\\' && *pszSep != ':')
+# else
+                while (pszSep >= pszTmp2 && *pszSep != '/')
+# endif
+                    pszSep--;
+                if (pszSep >= pszTmp2)
+                  strcpy(pszSep + 1, ".");
+                else
+                  strcpy(pszTmp2, ".");
+    
+                if (!my_abspath(pszTmp2, szTmpPath))
+                    fatal(NILF, _("failed to determin KBUILD_BIN_PATH (pszTmp2=%s szTmpPath=%s)"), pszTmp2, szTmpPath);
+#endif /* !KBUILD_PATH */
+            }
         }
         s_pszPath = xstrdup(szTmpPath);
@@ -289,5 +300,5 @@
     static char *s_pszDefaultShell = NULL;
     if (!s_pszDefaultShell)
-      {
+    {
 #if defined(__OS2__) || defined(_WIN32) || defined(WINDOWS32)
         static const char s_szShellName[] = "/kmk_ash.exe";
@@ -295,10 +306,10 @@
         static const char s_szShellName[] = "/kmk_ash";
 #endif
-        const char *pszBin = get_path_kbuild_bin();
+        const char *pszBin = get_kbuild_bin_path();
         size_t cchBin = strlen(pszBin);
         s_pszDefaultShell = xmalloc(cchBin + sizeof(s_szShellName));
         memcpy(s_pszDefaultShell, pszBin, cchBin);
         memcpy(&s_pszDefaultShell[cchBin], s_szShellName, sizeof(s_szShellName));
-      }
+    }
     return s_pszDefaultShell;
 }
Index: /trunk/src/kmk/kbuild.h
===================================================================
--- /trunk/src/kmk/kbuild.h	(revision 1502)
+++ /trunk/src/kmk/kbuild.h	(revision 1503)
@@ -35,6 +35,6 @@
 
 void init_kbuild(int argc, char **argv);
-const char *get_path_kbuild(void);
-const char *get_path_kbuild_bin(void);
+const char *get_kbuild_path(void);
+const char *get_kbuild_bin_path(void);
 const char *get_default_kbuild_shell(void);
 
Index: /trunk/src/kmk/main.c
===================================================================
--- /trunk/src/kmk/main.c	(revision 1502)
+++ /trunk/src/kmk/main.c	(revision 1503)
@@ -1294,5 +1294,9 @@
     argv[0] = "";
   if (argv[0][0] == '\0')
+#ifdef KMK
+    program = "kmk";
+#else
     program = "make";
+#endif
   else
     {
@@ -1499,6 +1503,6 @@
 
 #ifdef KMK
-  decode_env_switches (STRING_SIZE_TUPLE ("KMKFLAGS"));
-#endif
+  decode_env_switches (STRING_SIZE_TUPLE ("KMK_FLAGS"));
+#else /* !KMK */
   decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
 #if 0
@@ -1508,4 +1512,5 @@
   decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
 #endif
+#endif /* !KMK */
   decode_switches (argc, argv, 0);
 #ifdef WINDOWS32
@@ -1643,5 +1648,9 @@
          allow the user's setting of MAKEOVERRIDES to affect MAKEFLAGS, so
          a reference to this hidden variable is written instead. */
+#ifdef KMK
+      (void) define_variable ("KMK_OVERRIDES", 13,
+#else
       (void) define_variable ("MAKEOVERRIDES", 13,
+#endif
 			      "${-*-command-variables-*-}", o_env, 1);
     }
@@ -1753,5 +1762,5 @@
   {
     extern char *default_shell;
-    const char *bin = get_path_kbuild_bin();
+    const char *bin = get_kbuild_bin_path();
     size_t len = strlen (bin);
     default_shell = xmalloc (len + sizeof("/kmk_ash.exe"));
@@ -1994,10 +2003,11 @@
   /* Decode switches again, in case the variables were set by the makefile.  */
 #ifdef KMK
-  decode_env_switches (STRING_SIZE_TUPLE ("KMKFLAGS"));
-#endif
+  decode_env_switches (STRING_SIZE_TUPLE ("KMK_FLAGS"));
+#else /* !KMK */
   decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
 #if 0
   decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
 #endif
+#endif /* !KMK */
 
 #if defined (__MSDOS__) || defined (__EMX__)
@@ -2766,8 +2776,8 @@
   if (!remote_description || *remote_description == '\0')
     printf (_("\nThis program is built for %s/%s/%s [" __DATE__ " " __TIME__ "]\n"),
-            BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description);
+            KBUILD_HOST, KBUILD_HOST_ARCH, KBUILD_HOST_CPU, remote_description);
   else
     printf (_("\nThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"),
-            BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description);
+            KBUILD_HOST, KBUILD_HOST_ARCH, KBUILD_HOST_CPU, remote_description);
 #else  /* !KMK */
   if (!remote_description || *remote_description == '\0')
@@ -3051,5 +3061,9 @@
 define_makeflags (int all, int makefile)
 {
+#ifdef KMK
+  static const char ref[] = "$(KMK_OVERRIDES)";
+#else
   static const char ref[] = "$(MAKEOVERRIDES)";
+#endif
   static const char posixref[] = "$(-*-command-variables-*-)";
   register const struct command_switch *cs;
@@ -3241,7 +3255,9 @@
     *p = '\0';
 
+#ifdef KMK
   /* Since MFLAGS is not parsed for flags, there is no reason to
      override any makefile redefinition.  */
   (void) define_variable ("MFLAGS", 6, flagstring, o_env, 1);
+#endif /* !KMK */
 
   if (all && command_variables != 0)
@@ -3290,5 +3306,9 @@
   *p = '\0';
 
+#ifdef KMK
+  v = define_variable ("KMK_FLAGS", 9,
+#else
   v = define_variable ("MAKEFLAGS", 9,
+#endif
 		       /* If there are switches, omit the leading dash
 			  unless it is a single long option with two
@@ -3381,25 +3401,25 @@
 
 #ifdef KMK
-# ifdef PATH_KBUILD
+# ifdef KBUILD_PATH
   printf (_("%s\n\
-%sPATH_KBUILD:     '%s' (default '%s')\n\
-%sPATH_KBUILD_BIN: '%s' (default '%s')\n"),
+%sKBUILD_PATH:     '%s' (default '%s')\n\
+%sKBUILD_BIN_PATH: '%s' (default '%s')\n"),
           precede,
-          precede, get_path_kbuild(), PATH_KBUILD,
-          precede, get_path_kbuild_bin(), PATH_KBUILD_BIN);
-# else  /* !PATH_KBUILD */
+          precede, get_kbuild_path(), KBUILD_PATH,
+          precede, get_kbuild_bin_path(), KBUILD_BIN_PATH);
+# else  /* !KBUILD_PATH */
   printf (_("%s\n\
-%sPATH_KBUILD:     '%s'\n\
-%sPATH_KBUILD_BIN: '%s'\n"),
+%sKBUILD_PATH:     '%s'\n\
+%sKBUILD_BIN_PATH: '%s'\n"),
           precede,
-          precede, get_path_kbuild(),
-          precede, get_path_kbuild_bin());
-# endif /* !PATH_KBUILD */
+          precede, get_kbuild_path(),
+          precede, get_kbuild_bin_path());
+# endif /* !KBUILD_PATH */
   if (!remote_description || *remote_description == '\0')
     printf (_("\n%sThis program is built for %s/%s/%s [" __DATE__ " " __TIME__ "]\n"),
-            precede, BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description);
+            precede, KBUILD_HOST, KBUILD_HOST_ARCH, KBUILD_HOST_CPU, remote_description);
   else
     printf (_("\n%sThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"),
-            precede, BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description);
+            precede, KBUILD_HOST, KBUILD_HOST_ARCH, KBUILD_HOST_CPU, remote_description);
 #else
   if (!remote_description || *remote_description == '\0')
Index: /trunk/src/kmk/read.c
===================================================================
--- /trunk/src/kmk/read.c	(revision 1502)
+++ /trunk/src/kmk/read.c	(revision 1503)
@@ -3651,8 +3651,8 @@
 #endif
 #ifdef KMK
-  /* Add $(PATH_KBUILD). */
+  /* Add $(KBUILD_PATH). */
   {
-    size_t len = strlen (get_path_kbuild ());
-    dirs[idx++] = strcache_add_len (get_path_kbuild (), len);
+    size_t len = strlen (get_kbuild_path ());
+    dirs[idx++] = strcache_add_len (get_kbuild_path (), len);
     if (len > max_incl_len)
       max_incl_len = len;
Index: /trunk/src/kmk/variable.c
===================================================================
--- /trunk/src/kmk/variable.c	(revision 1502)
+++ /trunk/src/kmk/variable.c	(revision 1503)
@@ -1124,5 +1124,7 @@
 #else
   char buf[1024];
-  const char *envvar;
+  const char *val;
+  struct variable *envvar1;
+  struct variable *envvar2;
 #endif
 
@@ -1136,7 +1138,8 @@
 	   (remote_description == 0 || remote_description[0] == '\0')
 	   ? "" : remote_description);
+#ifndef KMK
   (void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
-
-#ifdef KMK
+#else /* KMK */
+
   /* Define KMK_VERSION to indicate kMk. */
   (void) define_variable ("KMK_VERSION", 11, buf, o_default, 0);
@@ -1157,23 +1160,51 @@
                    buf, o_default, 0);
 
-  /* The build platform defaults. */
-  envvar = getenv ("BUILD_PLATFORM");
-  if (!envvar)
-      define_variable ("BUILD_PLATFORM", sizeof ("BUILD_PLATFORM") - 1,
-                       BUILD_PLATFORM, o_default, 0);
-  envvar = getenv ("BUILD_PLATFORM_ARCH");
-  if (!envvar)
-      define_variable ("BUILD_PLATFORM_ARCH", sizeof ("BUILD_PLATFORM_ARCH") - 1,
-                       BUILD_PLATFORM_ARCH, o_default, 0);
-  envvar = getenv ("BUILD_PLATFORM_CPU");
-  if (!envvar)
-      define_variable ("BUILD_PLATFORM_CPU", sizeof ("BUILD_PLATFORM_CPU") - 1,
-                       BUILD_PLATFORM_CPU, o_default, 0);
+  /* The host defaults. The BUILD_* stuff will be replaced by KBUILD_* soon. */
+  envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST"));
+  envvar2 = lookup_variable (STRING_SIZE_TUPLE ("BUILD_PLATFORM"));
+  val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST;
+  if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
+    error (NULL, _("KBUILD_HOST and BUILD_PLATFORM differs, using KBUILD_HOST=%s."), val);
+  if (!envvar1)
+    define_variable ("KBUILD_HOST", sizeof ("KBUILD_HOST") - 1,
+                     val, o_default, 0);
+  if (!envvar2)
+    define_variable ("BUILD_PLATFORM", sizeof ("BUILD_PLATFORM") - 1,
+                     val, o_default, 0);
+
+  envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_ARCH"));
+  envvar2 = lookup_variable (STRING_SIZE_TUPLE ("BUILD_PLATFORM_ARCH"));
+  val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST_ARCH;
+  if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
+    error (NULL, _("KBUILD_HOST_ARCH and BUILD_PLATFORM_ARCH differs, using KBUILD_HOST_ARCH=%s."), val);
+  if (!envvar1)
+    define_variable ("KBUILD_HOST_ARCH", sizeof ("KBUILD_HOST_ARCH") - 1,
+                     val, o_default, 0);
+  if (!envvar2)
+    define_variable ("BUILD_PLATFORM_ARCH", sizeof ("BUILD_PLATFORM_ARCH") - 1,
+                     val, o_default, 0);
+
+  envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_CPU"));
+  envvar2 = lookup_variable (STRING_SIZE_TUPLE ("BUILD_PLATFORM_CPU"));
+  val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST_CPU;
+  if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
+    error (NULL, _("KBUILD_HOST_CPU and BUILD_PLATFORM_CPU differs, using KBUILD_HOST_CPU=%s."), val);
+  if (!envvar1)
+    define_variable ("KBUILD_HOST_CPU", sizeof ("KBUILD_HOST_CPU") - 1,
+                     val, o_default, 0);
+  if (!envvar2)
+    define_variable ("BUILD_PLATFORM_CPU", sizeof ("BUILD_PLATFORM_CPU") - 1,
+                     val, o_default, 0);
 
   /* The kBuild locations. */
+  define_variable ("KBUILD_PATH", sizeof ("KBUILD_PATH") - 1,
+                   get_kbuild_path (), o_default, 0);
+  define_variable ("KBUILD_BIN_PATH", sizeof ("KBUILD_BIN_PATH") - 1,
+                   get_kbuild_bin_path (), o_default, 0);
+
   define_variable ("PATH_KBUILD", sizeof ("PATH_KBUILD") - 1,
-                   get_path_kbuild (), o_default, 0);
+                   get_kbuild_path (), o_default, 0);
   define_variable ("PATH_KBUILD_BIN", sizeof ("PATH_KBUILD_BIN") - 1,
-                   get_path_kbuild_bin (), o_default, 0);
+                   get_kbuild_bin_path (), o_default, 0);
 
   /* Define KMK_FEATURES to indicate various working KMK features. */
Index: /trunk/src/kmk/variable.h
===================================================================
--- /trunk/src/kmk/variable.h	(revision 1502)
+++ /trunk/src/kmk/variable.h	(revision 1503)
@@ -279,4 +279,8 @@
 extern int export_all_variables;
 
+#ifdef KMK
+# define MAKELEVEL_NAME "KMK_LEVEL"
+#else
 #define MAKELEVEL_NAME "MAKELEVEL"
+#endif
 #define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
