Index: /trunk/src/kmk/arch.c
===================================================================
--- /trunk/src/kmk/arch.c	(revision 26)
+++ /trunk/src/kmk/arch.c	(revision 27)
@@ -98,7 +98,12 @@
 #include    <sys/time.h>
 #include    <sys/param.h>
-#include    <ctype.h>
+# include    <ctype.h>
 #include    <ar.h>
-#include    <utime.h>
+#if defined(__IBMC__)
+# include    <limits.h>
+# include    <sys/utime.h>
+#else
+# include    <utime.h>
+#endif
 #include    <stdio.h>
 #include    <stdlib.h>
@@ -107,4 +112,9 @@
 #include    "dir.h"
 #include    "config.h"
+#if defined(__IBMC__)
+# ifndef MAXPATHLEN
+#  define MAXPATHLEN _MAX_PATH
+# endif
+#endif
 
 static Lst	  archives;   /* Lst of archives we've already examined */
Index: /trunk/src/kmk/compat.c
===================================================================
--- /trunk/src/kmk/compat.c	(revision 26)
+++ /trunk/src/kmk/compat.c	(revision 27)
@@ -62,5 +62,8 @@
 #include    <sys/types.h>
 #include    <sys/stat.h>
+#ifdef __IBMC__
+#else
 #include    <sys/wait.h>
+#endif
 #include    <ctype.h>
 #include    <errno.h>
@@ -86,6 +89,6 @@
 static int CompatMake __P((ClientData, ClientData));
 
-static char *sh_builtin[] = { 
-	"alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit", 
+static char *sh_builtin[] = {
+	"alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
 	"unalias", "umask", "unset", "wait", ":", 0};
 
@@ -343,9 +346,9 @@
     }
 
-    /* 
+    /*
      * we need to print out the command associated with this Gnode in
      * Targ_PrintCmd from Targ_PrintGraph when debugging at level g2,
      * in main(), Fatal() and DieHorribly(), therefore do not free it
-     * when debugging. 
+     * when debugging.
      */
     if (!DEBUG(GRAPH2)) {
Index: /trunk/src/kmk/job.c
===================================================================
--- /trunk/src/kmk/job.c	(revision 26)
+++ /trunk/src/kmk/job.c	(revision 27)
@@ -108,10 +108,20 @@
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/file.h>
-#include <sys/time.h>
-#include <sys/wait.h>
+#if defined(__IBMC__)
+# include <io.h>
+# include <process.h>
+# include <sys/utime.h>
+#else
+# include <sys/file.h>
+#endif
+# include <sys/time.h>
+#if !defined(__IBMC__)
+# include <sys/wait.h>
+#endif
 #include <fcntl.h>
 #include <errno.h>
-#include <utime.h>
+#if !defined(__IBMC__)
+# include <utime.h>
+#endif
 #include <stdio.h>
 #include <string.h>
@@ -126,5 +136,9 @@
 # define STATIC
 #else
-# define STATIC static
+# if defined(__IBMC__)
+#  define STATIC
+# else
+#  define STATIC static
+# endif
 #endif
 
@@ -165,5 +179,5 @@
 /*
  * tfile is used to build temp file names to store shell commands to
- * execute. 
+ * execute.
  */
 static char     tfile[sizeof(TMPPAT)];
Index: /trunk/src/kmk/lst.lib/lstInt.h
===================================================================
--- /trunk/src/kmk/lst.lib/lstInt.h	(revision 26)
+++ /trunk/src/kmk/lst.lib/lstInt.h	(revision 27)
@@ -51,8 +51,15 @@
 	struct ListNode	*prevPtr;   /* previous element in list */
 	struct ListNode	*nextPtr;   /* next in list */
+#ifdef __IBMC__
+	int	    	useCount:8, /* Count of functions using the node.
+				     * node may not be deleted until count
+				     * goes to 0 */
+ 	    	    	flags:8;    /* Node status flags */
+#else
 	short	    	useCount:8, /* Count of functions using the node.
 				     * node may not be deleted until count
 				     * goes to 0 */
  	    	    	flags:8;    /* Node status flags */
+#endif
 	ClientData	datum;	    /* datum associated with this element */
 } *ListNode;
Index: /trunk/src/kmk/main.c
===================================================================
--- /trunk/src/kmk/main.c	(revision 26)
+++ /trunk/src/kmk/main.c	(revision 27)
@@ -79,9 +79,15 @@
  */
 
+#ifdef USE_KLIB
+ #include <kLib/kLib.h>
+#endif
+
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/param.h>
+#if !defined(__IBMC__)
 #include <sys/resource.h>
 #include <sys/signal.h>
+#endif
 #include <sys/stat.h>
 #if defined(__i386__)
@@ -89,17 +95,37 @@
 #endif
 #ifndef MACHINE
-#include <sys/utsname.h>
-#endif
+# if !defined(__IBMC__)
+#  include <sys/utsname.h>
+# endif
+#endif
+#if !defined(__IBMC__)
 #include <sys/wait.h>
 #include <err.h>
+#endif
 #include <stdlib.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#if !defined(__IBMC__)
 #include <sysexits.h>
-#ifdef __STDC__
+#endif
+#if defined(__STDC__) || defined(__IBMC__)
 #include <stdarg.h>
 #else
 #include <varargs.h>
+#endif
+#if defined(__IBMC__)
+ #include <io.h>
+ #include <direct.h>
+ #ifndef MAXPATHLEN
+  #define MAXPATHLEN _MAX_PATH
+ #endif
+ #ifndef EISDIR
+  #define EISDIR 21                     /* unused in errno.h, defined like this in DDK header. */
+ #endif
+ #ifndef S_ISDIR
+  #define S_IFMT   (S_IFDIR | S_IFCHR | S_IFREG)
+  #define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
+ #endif
 #endif
 #include "make.h"
@@ -629,5 +655,9 @@
 
 #ifdef WANT_ENV_PWD
+        #ifdef USE_KLIB
+	kEnvSet("PWD", objdir);
+        #else
 	setenv("PWD", objdir, 1);
+        #endif
 #endif
 
@@ -791,7 +821,15 @@
 	if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1)) != NULL) && *p)
 #ifdef POSIX
+                #ifdef USE_KLIB
+                kEnvSet("MAKEFLAGS", p);
+                #else
 		setenv("MAKEFLAGS", p, 1);
+                #endif
 #else
+                #ifdef USE_KLIB
+		kEnvSet("MAKE", p);
+                #else
 		setenv("MAKE", p, 1);
+                #endif
 #endif
 	efree(p1);
@@ -1131,5 +1169,5 @@
 /* VARARGS */
 void
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 Error(char *fmt, ...)
 #else
@@ -1139,5 +1177,5 @@
 {
 	va_list ap;
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 	va_start(ap, fmt);
 #else
@@ -1166,5 +1204,5 @@
 /* VARARGS */
 void
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 Fatal(char *fmt, ...)
 #else
@@ -1174,5 +1212,5 @@
 {
 	va_list ap;
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 	va_start(ap, fmt);
 #else
@@ -1208,5 +1246,5 @@
 /* VARARGS */
 void
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 Punt(char *fmt, ...)
 #else
@@ -1216,5 +1254,5 @@
 {
 	va_list ap;
-#if __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 	va_start(ap, fmt);
 #else
Index: /trunk/src/kmk/make.h
===================================================================
--- /trunk/src/kmk/make.h	(revision 26)
+++ /trunk/src/kmk/make.h	(revision 27)
@@ -54,9 +54,10 @@
 #include <err.h>
 
-#if !defined(MAKE_BOOTSTRAP) && defined(BSD4_4)
+#if !defined(MAKE_BOOTSTRAP) && defined(BSD4_4) && !defined(__IBMC__)
 # include <sys/cdefs.h>
 #else
 # ifndef __P
-#  if defined(__STDC__) || defined(__cplusplus)
+/*kso: #  if defined(__STDC__) || defined(__cplusplus) */
+#  if defined(__STDC__) || defined(__cplusplus) || defined(__IBMC__)
 #   define	__P(protos)	protos		/* full-blown ANSI C */
 #  else
@@ -64,5 +65,6 @@
 #  endif
 # endif
-# ifndef __STDC__
+/*kso: # ifndef __STDC__*/
+# if !defined(__STDC__) && !defined(__IBMC__)
 #  ifndef const
 #   define const
@@ -74,8 +76,13 @@
 #endif
 
-#ifdef __STDC__
+#if defined(__IBMC__)
+#include <stdlib.h>
+#include <time.h>
+/*#ifdef __STDC__*/
+#elif defined(__STDC__)
 #include <stdlib.h>
 #include <unistd.h>
 #endif
+
 #include "sprite.h"
 #include "lst.h"
@@ -364,5 +371,6 @@
 #define DEBUG_LOUD	0x0800
 
-#ifdef __STDC__
+/*#ifdef __STDC__*/
+#if defined(__STDC__) || defined(__IBMC__)
 #define CONCAT(a,b)	a##b
 #else
@@ -370,4 +378,6 @@
 #define CONCAT(a,b)	I(a)b
 #endif /* __STDC__ */
+
+
 
 #define	DEBUG(module)	(debug & CONCAT(DEBUG_,module))
Index: /trunk/src/kmk/parse.c
===================================================================
--- /trunk/src/kmk/parse.c	(revision 26)
+++ /trunk/src/kmk/parse.c	(revision 27)
@@ -88,5 +88,5 @@
  */
 
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 #include <stdarg.h>
 #else
@@ -315,5 +315,5 @@
 /* VARARGS */
 void
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 Parse_Error(int type, char *fmt, ...)
 #else
@@ -323,5 +323,5 @@
 {
 	va_list ap;
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__IBMC__)
 	va_start(ap, fmt);
 #else
@@ -2422,5 +2422,5 @@
 		} else if (strncmp (cp, "error", 5) == 0) {
 		    ParseDoError(cp + 5);
-	            goto nextLine;	    
+	            goto nextLine;	
 		} else if (strncmp(cp, "undef", 5) == 0) {
 		    char *cp2;
Index: /trunk/src/kmk/var.c
===================================================================
--- /trunk/src/kmk/var.c	(revision 26)
+++ /trunk/src/kmk/var.c	(revision 27)
@@ -88,4 +88,8 @@
  */
 
+#ifdef USE_KLIB
+ #include <kLib/kLib.h>
+#endif
+
 #include    <ctype.h>
 #include    <sys/types.h>
@@ -163,6 +167,6 @@
 } VarPattern;
 
-typedef struct { 
-    regex_t	   re; 
+typedef struct {
+    regex_t	   re;
     int		   nsub;
     regmatch_t	  *matches;
@@ -309,7 +313,11 @@
     }
     if ((var == NILLNODE) && (flags & FIND_ENV)) {
-	char *env;
-
+        #ifdef USE_KLIB
+	const char *env;
+	if ((env = kEnvGet (name)) != NULL) {
+        #else
+        char *env;
 	if ((env = getenv (name)) != NULL) {
+        #endif
 	    int	  	len;
 
@@ -493,5 +501,9 @@
      */
     if (ctxt == VAR_CMD) {
+        #ifdef USE_KLIB
+        kEnvSet(name, val);
+        #else
 	setenv(name, val, 1);
+        #endif
     }
 }
@@ -1547,5 +1559,5 @@
 			Boolean	rfree;
 			char*	rval = Var_Parse(tstr, ctxt, err, &rlen, &rfree);
-                
+
 			if (rval == var_Error) {
 				Fatal("Error expanding embedded variable.");
