Index: /trunk/src/gmakenew/kbuild.c
===================================================================
--- /trunk/src/gmakenew/kbuild.c	(revision 916)
+++ /trunk/src/gmakenew/kbuild.c	(revision 917)
@@ -27,6 +27,8 @@
 /* No GNU coding style here! */
 
-#ifdef KMK_HELPERS
-
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
 #include "make.h"
 #include "filedef.h"
@@ -43,6 +45,95 @@
 #endif
 
+
+/*******************************************************************************
+*   Internal Functions                                                         *
+*******************************************************************************/
 /* function.c */
 char * abspath(const char *name, char *apath);
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** The argv[0] passed to main. */
+static const char *g_argv0 = "";
+
+
+/**
+ * Initialize kBuild stuff.
+ *
+ * @param   argc    Number of arguments to main().
+ * @param   argv    The main() argument vector.
+ */
+void init_kbuild(int argc, char **argv)
+{
+    g_argv0 = argv[0];
+}
+
+
+/**
+ * Determin the PATH_KBUILD value.
+ *
+ * @returns Pointer to static buffer to be treated as read only!
+ */
+const char *get_path_kbuild(void)
+{
+    static const char *s_pszPath = NULL;
+    if (!s_pszPath)
+    {
+        PATH_VAR(szTmpPath);
+        const char *pszEnvVar = getenv("PATH_KBUILD");
+        if (    !pszEnvVar
+            ||  !abspath(pszEnvVar, szTmpPath))
+        {
+#ifdef PATH_KBUILD
+            return s_pszPath = PATH_KBUILD;
+#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 (!abspath(pszTmp2, szTmpPath))
+                fatal(NILF, _("failed to determin PATH_KBUILD"));
+#endif
+        }
+        s_pszPath = xstrdup(szTmpPath);
+    }
+    return s_pszPath;
+}
+
+
+/**
+ * Determin the PATH_KBUILD_BIN value.
+ *
+ * @returns Pointer to static buffer to be treated as read only!
+ */
+const char *get_path_kbuild_bin(void)
+{
+    static const char *s_pszPath = NULL;
+    if (!s_pszPath)
+    {
+        PATH_VAR(szTmpPath);
+        const char *pszEnvVar = getenv("PATH_KBUILD_BIN");
+        if (    !pszEnvVar
+            ||  !abspath(pszEnvVar, szTmpPath))
+        {
+#ifdef PATH_KBUILD
+            return s_pszPath = PATH_KBUILD_BIN;
+#else
+            /* $(abspath $(ARGV0)/../../..) - the filename shouldn't cause trouble... */
+            size_t cch = strlen(g_argv0);
+            char *pszTmp2 = alloca(cch + sizeof("/../../.."));
+            strcat(strcpy(pszTmp2, g_argv0), "/../../..");
+            if (!abspath(pszTmp2, szTmpPath))
+                fatal(NILF, _("failed to determin PATH_KBUILD_BIN"));
+#endif
+        }
+        s_pszPath = xstrdup(szTmpPath);
+    }
+    return s_pszPath;
+}
+
+
+#ifdef KMK_HELPERS
 
 /**
@@ -1475,2 +1566,3 @@
 
 #endif /* KMK_HELPERS */
+
Index: /trunk/src/gmakenew/kbuild.h
===================================================================
--- /trunk/src/gmakenew/kbuild.h	(revision 916)
+++ /trunk/src/gmakenew/kbuild.h	(revision 917)
@@ -34,3 +34,7 @@
 char *func_kbuild_source_one(char *o, char **argv, const char *pszFuncName);
 
+void init_kbuild(int argc, char **argv);
+const char *get_path_kbuild(void);
+const char *get_path_kbuild_bin(void);
+
 #endif
Index: /trunk/src/gmakenew/main.c
===================================================================
--- /trunk/src/gmakenew/main.c	(revision 916)
+++ /trunk/src/gmakenew/main.c	(revision 917)
@@ -26,4 +26,7 @@
 #include "debug.h"
 #include "getopt.h"
+#ifdef KMK
+# include "kbuild.h"
+#endif
 
 #include <assert.h>
@@ -1113,4 +1116,8 @@
   initialize_main(&argc, &argv);
 
+#ifdef KMK
+  init_kbuild (argc, argv);
+#endif
+
   default_goal_file = 0;
   reading_file = 0;
@@ -1130,6 +1137,8 @@
   /* Set up gettext/internationalization support.  */
   setlocale (LC_ALL, "");
+#ifndef LOCALEDIR /* bird */
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
+#endif
 
 #ifdef	POSIX
@@ -3244,8 +3253,17 @@
 # ifdef PATH_KBUILD
   printf (_("%s\n\
-%sPATH_KBUILD default:     '%s'\n\
-%sPATH_KBUILD_BIN default: '%s'\n"),
-          precede, precede, PATH_KBUILD, precede, PATH_KBUILD_BIN);
-# endif /* PATH_KBUILD */
+%sPATH_KBUILD:     '%s' (default '%s')\n\
+%sPATH_KBUILD_BIN: '%s' (default '%s')\n"),
+          precede,
+          precede, get_path_kbuild(), PATH_KBUILD
+          precede, get_path_kbuild_bin(), PATH_KBUILD_BIN);
+# else  /* !PATH_KBUILD */
+  printf (_("%s\n\
+%sPATH_KBUILD:     '%s'\n\
+%sPATH_KBUILD_BIN: '%s'\n"),
+          precede,
+          precede, get_path_kbuild(),
+          precede, get_path_kbuild_bin());
+# endif /* !PATH_KBUILD */
   if (!remote_description || *remote_description == '\0')
     printf (_("\n%sThis program is built for %s/%s/%s [" __DATE__ " " __TIME__ "]\n"),
Index: /trunk/src/gmakenew/read.c
===================================================================
--- /trunk/src/gmakenew/read.c	(revision 916)
+++ /trunk/src/gmakenew/read.c	(revision 917)
@@ -31,4 +31,7 @@
 #include "debug.h"
 #include "hash.h"
+#ifdef KMK
+# include "kbuild.h"
+#endif
 
 
@@ -91,4 +94,5 @@
 static const char *default_include_directories[] =
   {
+#ifndef KMK
 #if defined(WINDOWS32) && !defined(INCLUDEDIR)
 /* This completely up to the user when they install MSVC or other packages.
@@ -102,4 +106,5 @@
     "/usr/include",
 #endif
+#endif /* !KMK */
     0
   };
@@ -3006,4 +3011,8 @@
   ++idx;
 #endif
+#ifdef KMK
+  /* Add one for the kBuild directory. */
+  ++idx;
+#endif
 
   dirs = xmalloc (idx * sizeof (const char *));
@@ -3064,4 +3073,13 @@
           max_incl_len = len;
       }
+  }
+#endif
+#ifdef KMK
+  /* Add $(PATH_KBUILD). */
+  {
+    size_t len = strlen (get_path_kbuild ());
+    dirs[idx++] = strcache_add_len (get_path_kbuild (), len);
+    if (len > max_incl_len)
+      max_incl_len = len;
   }
 #endif
@@ -3226,5 +3244,5 @@
         {
           gl.gl_pathc = 1;
-          gl.gl_pathv = (char *)&gname;
+          gl.gl_pathv = (char **)&gname;
           rc = 0;
         }
Index: /trunk/src/gmakenew/remake.c
===================================================================
--- /trunk/src/gmakenew/remake.c	(revision 916)
+++ /trunk/src/gmakenew/remake.c	(revision 917)
@@ -1457,4 +1457,7 @@
   static char *dirs[] =
     {
+#ifdef KMK
+      ".",
+#else /* !KMK */
 #ifndef _AMIGA
       "/lib",
@@ -1469,4 +1472,5 @@
 #endif
       LIBDIR,			/* Defined by configuration.  */
+#endif /* !KMK */
       0
     };
Index: /trunk/src/gmakenew/variable.c
===================================================================
--- /trunk/src/gmakenew/variable.c	(revision 916)
+++ /trunk/src/gmakenew/variable.c	(revision 917)
@@ -31,4 +31,7 @@
 #endif
 #include "hash.h"
+#ifdef KMK
+# include "kbuild.h"
+#endif
 
 /* Chain of all pattern-specific variables.  */
@@ -990,45 +993,36 @@
   /* Define KBUILD_VERSION* */
   sprintf (buf, "%d", KBUILD_VERSION_MAJOR);
-  (void) define_variable ("KBUILD_VERSION_MAJOR", sizeof("KBUILD_VERSION_MAJOR") - 1,
-                          buf, o_default, 0);
+  define_variable ("KBUILD_VERSION_MAJOR", sizeof ("KBUILD_VERSION_MAJOR") - 1,
+                   buf, o_default, 0);
   sprintf (buf, "%d", KBUILD_VERSION_MINOR);
-  (void) define_variable ("KBUILD_VERSION_MINOR", sizeof("KBUILD_VERSION_MINOR") - 1,
-                          buf, o_default, 0);
+  define_variable ("KBUILD_VERSION_MINOR", sizeof("KBUILD_VERSION_MINOR") - 1,
+                   buf, o_default, 0);
   sprintf (buf, "%d", KBUILD_VERSION_PATCH);
-  (void) define_variable ("KBUILD_VERSION_PATCH", sizeof("KBUILD_VERSION_PATCH") - 1,
-                          buf, o_default, 0);
+  define_variable ("KBUILD_VERSION_PATCH", sizeof ("KBUILD_VERSION_PATCH") - 1,
+                   buf, o_default, 0);
 
   sprintf (buf, "%d.%d.%d", KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH);
-  (void) define_variable ("KBUILD_VERSION", sizeof("KBUILD_VERSION") - 1,
-                          buf, o_default, 0);
+  define_variable ("KBUILD_VERSION", sizeof ("KBUILD_VERSION") - 1,
+                   buf, o_default, 0);
 
   /* The build platform defaults. */
   envvar = getenv ("BUILD_PLATFORM");
   if (!envvar)
-      (void) define_variable ("BUILD_PLATFORM", sizeof("BUILD_PLATFORM") - 1,
-                              BUILD_PLATFORM, o_default, 0);
+      define_variable ("BUILD_PLATFORM", sizeof ("BUILD_PLATFORM") - 1,
+                       BUILD_PLATFORM, o_default, 0);
   envvar = getenv ("BUILD_PLATFORM_ARCH");
   if (!envvar)
-      (void) define_variable ("BUILD_PLATFORM_ARCH", sizeof("BUILD_PLATFORM_ARCH") - 1,
-                              BUILD_PLATFORM_ARCH, o_default, 0);
+      define_variable ("BUILD_PLATFORM_ARCH", sizeof ("BUILD_PLATFORM_ARCH") - 1,
+                       BUILD_PLATFORM_ARCH, o_default, 0);
   envvar = getenv ("BUILD_PLATFORM_CPU");
   if (!envvar)
-      (void) define_variable ("BUILD_PLATFORM_CPU", sizeof("BUILD_PLATFORM_CPU") - 1,
-                              BUILD_PLATFORM_CPU, o_default, 0);
-
-# ifdef PATH_KBUILD
-  /* define the installed. */
-  envvar = getenv("PATH_KBUILD");
-  if (!envvar)
-  {
-      (void) define_variable ("PATH_KBUILD", sizeof("PATH_KBUILD") - 1,
-                              PATH_KBUILD, o_default, 0);
-      envvar = getenv("PATH_KBUILD_BIN");
-      if (!envvar)
-          (void) define_variable ("PATH_KBUILD_BIN", sizeof("PATH_KBUILD_BIN") - 1,
-                                  PATH_KBUILD_BIN, o_default, 0);
-  }
-# endif
-
+      define_variable ("BUILD_PLATFORM_CPU", sizeof ("BUILD_PLATFORM_CPU") - 1,
+                       BUILD_PLATFORM_CPU, o_default, 0);
+
+  /* The kBuild locations. */
+  define_variable ("PATH_KBUILD", sizeof ("PATH_KBUILD") - 1,
+                   get_path_kbuild (), o_default, 0);
+  define_variable ("PATH_KBUILD_BIN", sizeof ("PATH_KBUILD_BIN") - 1,
+                   get_path_kbuild_bin (), o_default, 0);
 
   /* Define KMK_FEATURES to indicate various working KMK features. */
@@ -1053,28 +1047,28 @@
                           , o_default, 0);
 # else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */
-  strcpy(buf, "append-dash-n abspath");
-#  if defined(CONFIG_WITH_RSORT)
-  strcat(buf, " rsort");
+  strcpy (buf, "append-dash-n abspath");
+#  if defined (CONFIG_WITH_RSORT)
+  strcat (buf, " rsort");
 #  endif
-#  if defined(CONFIG_WITH_ABSPATHEX)
-  strcat(buf, " abspathex");
+#  if defined (CONFIG_WITH_ABSPATHEX)
+  strcat (buf, " abspathex");
 #  endif
-#  if defined(CONFIG_WITH_TOUPPER_TOLOWER)
-  strcat(buf, " toupper tolower");
+#  if defined (CONFIG_WITH_TOUPPER_TOLOWER)
+  strcat (buf, " toupper tolower");
 #  endif
-#  if defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE)
-  strcat(buf, " comp-vars comp-cmds");
+#  if defined (CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE)
+  strcat (buf, " comp-vars comp-cmds");
 #  endif
-#  if defined(CONFIG_WITH_STACK)
-  strcat(buf, " stack");
+#  if defined (CONFIG_WITH_STACK)
+  strcat (buf, " stack");
 #  endif
-#  if defined(CONFIG_WITH_MATH)
-  strcat(buf, " math-int");
+#  if defined (CONFIG_WITH_MATH)
+  strcat (buf, " math-int");
 #  endif
-#  if defined(CONFIG_WITH_XARGS)
-  strcat(buf, " xargs");
+#  if defined (CONFIG_WITH_XARGS)
+  strcat (buf, " xargs");
 #  endif
 #  ifdef KMK_HELPERS
-  strcat(buf, " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one");
+  strcat (buf, " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one");
 #  endif
   (void) define_variable ("KMK_FEATURES", 12, buf, o_default, 0);
