Index: /trunk/Config.kmk
===================================================================
--- /trunk/Config.kmk	(revision 2545)
+++ /trunk/Config.kmk	(revision 2546)
@@ -100,5 +100,5 @@
 # Various platform specific hacks.
 #
-ifn1of ($(KBUILD_TARGET), openbsd)
+ifn1of ($(KBUILD_TARGET), haiku openbsd)
  GCC_Wextra = -Wextra
 endif
Index: /trunk/kBuild/env.sh
===================================================================
--- /trunk/kBuild/env.sh	(revision 2545)
+++ /trunk/kBuild/env.sh	(revision 2546)
@@ -265,4 +265,8 @@
             ;;
 
+        Haiku)
+            KBUILD_HOST=haiku
+            ;;
+
         linux|Linux|GNU/Linux|LINUX)
             KBUILD_HOST=linux
@@ -323,5 +327,5 @@
             KBUILD_HOST_ARCH='amd64'
             ;;
-        x86|i86pc|ia32|i[3456789]86)
+        x86|i86pc|ia32|i[3456789]86|BePC)
             KBUILD_HOST_ARCH='x86'
             ;;
Index: /trunk/kBuild/header.kmk
===================================================================
--- /trunk/kBuild/header.kmk	(revision 2545)
+++ /trunk/kBuild/header.kmk	(revision 2546)
@@ -189,5 +189,5 @@
 # build types. (PORTME)
 #
-KBUILD_OSES   := darwin dos dragonfly freebsd l4 linux netbsd nt openbsd os2 solaris win os-agnostic
+KBUILD_OSES   := darwin dos dragonfly freebsd haiku l4 linux netbsd nt openbsd os2 solaris win os-agnostic
 KBUILD_ARCHES := x86 amd64 sparc32 sparc64 s390 s390x ppc32 ppc64 mips32 mips64 ia64 hppa32 hppa64 arm alpha
 
Index: /trunk/src/kObjCache/kObjCache.c
===================================================================
--- /trunk/src/kObjCache/kObjCache.c	(revision 2545)
+++ /trunk/src/kObjCache/kObjCache.c	(revision 2546)
@@ -73,4 +73,7 @@
 # include <Windows.h>
 # include "quoted_spawn.h"
+#endif
+#if defined(__HAIKU__)
+# include <posix/sys/file.h>
 #endif
 
Index: /trunk/src/kash/Makefile.kmk
===================================================================
--- /trunk/src/kash/Makefile.kmk	(revision 2545)
+++ /trunk/src/kash/Makefile.kmk	(revision 2546)
@@ -37,4 +37,5 @@
 kash_DEFS += SH_FORKED_MODE
 kash_DEFS.debug = DEBUG=2
+kash_DEFS.haiku = BSD
 kash_DEFS.linux = BSD
 kash_DEFS.solaris = BSD
@@ -97,7 +98,13 @@
 	shthread.c \
 	shfile.c
+kash_SOURCES.haiku = \
+	sys_signame.c \
+	strlcpy.c
 kash_SOURCES.linux = \
 	sys_signame.c \
 	strlcpy.c
+kash_SOURCES.solaris = \
+	sys_signame.c \
+        strlcpy.c
 kash_SOURCES.win = \
 	sys_signame.c \
@@ -105,7 +112,4 @@
 	shfork-win.c \
 	shforkA-win.asm
-kash_SOURCES.solaris = \
-	sys_signame.c \
-	strlcpy.c
 
 kash_INTERMEDIATES = \
Index: /trunk/src/kash/error.h
===================================================================
--- /trunk/src/kash/error.h	(revision 2545)
+++ /trunk/src/kash/error.h	(revision 2546)
@@ -60,5 +60,9 @@
  */
 
-#include <setjmp.h>
+#ifndef __HAIKU__
+# include <setjmp.h>
+#else
+# include <posix/setjmp.h> /** @todo silly */
+#endif
 
 struct jmploc {
@@ -121,5 +125,6 @@
  */
 
-#if defined(BSD) && !defined(__SVR4) && !defined(__GLIBC__) && !defined(__KLIBC__) && !defined(_MSC_VER)
+#if defined(BSD) && !defined(__SVR4) && !defined(__GLIBC__) \
+  && !defined(__KLIBC__) && !defined(_MSC_VER) && !defined(__HAIKU__)
 #define setjmp(jmploc)	_setjmp(jmploc)
 #define longjmp(jmploc, val)	_longjmp(jmploc, val)
Index: /trunk/src/kash/shfile.h
===================================================================
--- /trunk/src/kash/shfile.h	(revision 2545)
+++ /trunk/src/kash/shfile.h	(revision 2546)
@@ -1,7 +1,8 @@
 /* $Id$ */
 /** @file
- *
  * File management.
- *
+ */
+
+/*
  * Copyright (c) 2007-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
  *
@@ -47,5 +48,5 @@
 #endif
 #ifndef _MSC_VER
-# include <sys/fcntl.h>
+# include <fcntl.h>
 # include <unistd.h>
 # ifndef O_BINARY
Index: /trunk/src/kash/shinstance.c
===================================================================
--- /trunk/src/kash/shinstance.c	(revision 2545)
+++ /trunk/src/kash/shinstance.c	(revision 2546)
@@ -890,5 +890,4 @@
     return 0;
 }
-#include <setjmp.h>
 
 pid_t sh_fork(shinstance *psh)
Index: /trunk/src/kash/shinstance.h
===================================================================
--- /trunk/src/kash/shinstance.h	(revision 2545)
+++ /trunk/src/kash/shinstance.h	(revision 2546)
@@ -445,4 +445,7 @@
 #else
 #   include <sys/wait.h>
+#   ifdef __HAIKU__
+#       define WCOREDUMP(x) (0) /** @todo check the haiku headers and see if this information is available or not... */
+#   endif
 #endif
 pid_t sh_fork(shinstance *);
Index: /trunk/src/kash/shtypes.h
===================================================================
--- /trunk/src/kash/shtypes.h	(revision 2545)
+++ /trunk/src/kash/shtypes.h	(revision 2546)
@@ -1,7 +1,8 @@
 /* $Id$ */
 /** @file
- *
  * Wrapper for missing types and such.
- *
+ */
+
+/*
  * Copyright (c) 2007-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
  *
@@ -32,5 +33,7 @@
 #include <sys/types.h>
 #include <stdlib.h>
-#ifndef _MSC_VER
+#ifdef __HAIKU__
+# include <posix/signal.h> /* silly */
+#elif !defined(_MSC_VER)
 # include <sys/signal.h>
 #endif
Index: /trunk/src/kmk/Makefile.kmk
===================================================================
--- /trunk/src/kmk/Makefile.kmk	(revision 2545)
+++ /trunk/src/kmk/Makefile.kmk	(revision 2546)
@@ -58,4 +58,5 @@
 TEMPLATE_BIN-KMK_INCS.dragonfly = glob
 TEMPLATE_BIN-KMK_INCS.freebsd = glob
+TEMPLATE_BIN-KMK_INCS.haiku = glob
 TEMPLATE_BIN-KMK_INCS.openbsd = glob
 TEMPLATE_BIN-KMK_INCS.solaris = glob
@@ -99,4 +100,9 @@
 
 kmkmissing_SOURCES.freebsd = \
+	glob/glob.c \
+	glob/fnmatch.c
+
+kmkmissing_SOURCES.haiku = \
+	kmkbuiltin/haikufakes.c \
 	glob/glob.c \
 	glob/fnmatch.c
Index: /trunk/src/kmk/arscan.c
===================================================================
--- /trunk/src/kmk/arscan.c	(revision 2545)
+++ /trunk/src/kmk/arscan.c	(revision 2546)
@@ -232,5 +232,5 @@
 
 #ifndef WINDOWS32
-# ifndef __BEOS__
+# if !defined(__BEOS__) && !defined(__HAIKU__)
 #  include <ar.h>
 # else
Index: /trunk/src/kmk/config.h.haiku
===================================================================
--- /trunk/src/kmk/config.h.haiku	(revision 2546)
+++ /trunk/src/kmk/config.h.haiku	(revision 2546)
@@ -0,0 +1,438 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.in by autoheader.  */
+
+/* Define to 1 if the `closedir' function returns void instead of `int'. */
+/* #undef CLOSEDIR_VOID */
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+   systems. This function is required for `alloca.c' support on those systems.
+   */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define to 1 if using `alloca.c'. */
+/* #undef C_ALLOCA */
+
+/* Define to 1 if using `getloadavg.c'. */
+#define C_GETLOADAVG 1
+
+/* Define to 1 for DGUX with <sys/dg_sys_info.h>. */
+/* #undef DGUX */
+
+/* Use high resolution file timestamps if nonzero. */
+#define FILE_TIMESTAMP_HI_RES 1
+
+/* Define to 1 if the `getloadavg' function needs to be run setuid or setgid.
+   */
+/* #undef GETLOADAVG_PRIVILEGED */
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+#define HAVE_ALLOCA 1
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+#define HAVE_ALLOCA_H 1
+
+/* Define to 1 if your compiler conforms to the ANSI C standard. */
+#define HAVE_ANSI_COMPILER 1
+
+/* Define to 1 if you have the `atexit' function. */
+#define HAVE_ATEXIT 1
+
+/* Define to 1 if you have the `bsd_signal' function. */
+/* #undef HAVE_BSD_SIGNAL */
+
+/* Use case insensitive file names */
+/* #undef HAVE_CASE_INSENSITIVE_FS */
+
+/* Define to 1 if you have the clock_gettime function. */
+/* #undef HAVE_CLOCK_GETTIME */
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+   don't. */
+#define HAVE_DECL_SYS_SIGLIST 1
+
+/* Define to 1 if you have the declaration of `_sys_siglist', and to 0 if you
+   don't. */
+#define HAVE_DECL__SYS_SIGLIST 0
+
+/* Define to 1 if you have the declaration of `__sys_siglist', and to 0 if you
+   don't. */
+#define HAVE_DECL___SYS_SIGLIST 0
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+   */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
+/* #undef HAVE_DOPRNT */
+
+/* Use platform specific coding */
+/* #undef HAVE_DOS_PATHS */
+
+/* Define to 1 if you have the `dup2' function. */
+#define HAVE_DUP2 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fdopen' function. */
+#define HAVE_FDOPEN 1
+
+/* Define to 1 if you have the `fork' function. */
+#define HAVE_FORK 1
+
+/* Define to 1 if you have the `getcwd' function. */
+#define HAVE_GETCWD 1
+
+/* Define to 1 if you have the `getgroups' function. */
+#define HAVE_GETGROUPS 1
+
+/* Define to 1 if you have the `gethostbyname' function. */
+/* #undef HAVE_GETHOSTBYNAME */
+
+/* Define to 1 if you have the `gethostname' function. */
+/* #undef HAVE_GETHOSTNAME */
+
+/* Define to 1 if you have the `getloadavg' function. */
+/* #undef HAVE_GETLOADAVG */
+
+/* Define to 1 if you have the `getrlimit' function. */
+#define HAVE_GETRLIMIT 1
+
+/* Define to 1 if you have a standard gettimeofday function */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `dgc' library (-ldgc). */
+/* #undef HAVE_LIBDGC */
+
+/* Define to 1 if you have the `kstat' library (-lkstat). */
+/* #undef HAVE_LIBKSTAT */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <locale.h> header file. */
+#define HAVE_LOCALE_H 1
+
+/* Define to 1 if you have the `lstat' function. */
+#define HAVE_LSTAT 1
+
+/* Define to 1 if you have the <mach/mach.h> header file. */
+/* #undef HAVE_MACH_MACH_H */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mkstemp' function. */
+#define HAVE_MKSTEMP 1
+
+/* Define to 1 if you have the `mktemp' function. */
+#define HAVE_MKTEMP 1
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+/* #undef HAVE_NDIR_H */
+
+/* Define to 1 if you have the <nlist.h> header file. */
+/* #undef HAVE_NLIST_H */
+
+/* Define to 1 if you have the `pipe' function. */
+#define HAVE_PIPE 1
+
+/* Define to 1 if you have the `pstat_getdynamic' function. */
+/* #undef HAVE_PSTAT_GETDYNAMIC */
+
+/* Define to 1 if you have the `readlink' function. */
+#define HAVE_READLINK 1
+
+/* Define to 1 if you have the `realpath' function. */
+#define HAVE_REALPATH 1
+
+/* Define to 1 if <signal.h> defines the SA_RESTART constant. */
+#define HAVE_SA_RESTART 1
+
+/* Define to 1 if you have the `setegid' function. */
+#define HAVE_SETEGID 1
+
+/* Define to 1 if you have the `seteuid' function. */
+#define HAVE_SETEUID 1
+
+/* Define to 1 if you have the `setlinebuf' function. */
+#define HAVE_SETLINEBUF 1
+
+/* Define to 1 if you have the `setlocale' function. */
+#define HAVE_SETLOCALE 1
+
+/* Define to 1 if you have the `setregid' function. */
+#define HAVE_SETREGID 1
+
+/* Define to 1 if you have the `setreuid' function. */
+#define HAVE_SETREUID 1
+
+/* Define to 1 if you have the `setrlimit' function. */
+#define HAVE_SETRLIMIT 1
+
+/* Define to 1 if you have the `setvbuf' function. */
+#define HAVE_SETVBUF 1
+
+/* Define to 1 if you have the `sigaction' function. */
+#define HAVE_SIGACTION 1
+
+/* Define to 1 if you have the `sigsetmask' function. */
+/* #undef HAVE_SIGSETMASK */
+
+/* Define to 1 if you have the `socket' function. */
+/* #undef HAVE_SOCKET */
+
+/* Define to 1 if you have the <stdarg.h> header file. */
+#define HAVE_STDARG_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#define HAVE_STRCASECMP 1
+
+/* Define to 1 if you have the `strcmpi' function. */
+/* #undef HAVE_STRCMPI */
+
+/* Define to 1 if you have the `strcoll' function and it is properly defined.
+   */
+#define HAVE_STRCOLL 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the `stricmp' function. */
+/* #undef HAVE_STRICMP */
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strsignal' function. */
+#define HAVE_STRSIGNAL 1
+
+/* Define to 1 if `n_un.n_name' is a member of `struct nlist'. */
+/* #undef HAVE_STRUCT_NLIST_N_UN_N_NAME */
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+   */
+/* #undef HAVE_SYS_DIR_H */
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+   */
+/* #undef HAVE_SYS_NDIR_H */
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#define HAVE_SYS_RESOURCE_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/timeb.h> header file. */
+#define HAVE_SYS_TIMEB_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/wait.h> header file. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the \`union wait' type in <sys/wait.h>. */
+/* #undef HAVE_UNION_WAIT */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the <varargs.h> header file. */
+/* #undef HAVE_VARARGS_H */
+
+/* Define to 1 if you have the `vfork' function. */
+#define HAVE_VFORK 1
+
+/* Define to 1 if you have the <vfork.h> header file. */
+/* #undef HAVE_VFORK_H */
+
+/* Define to 1 if you have the `vprintf' function. */
+#define HAVE_VPRINTF 1
+
+/* Define to 1 if you have the `wait3' function. */
+/* #undef HAVE_WAIT3 */
+
+/* Define to 1 if you have the `waitpid' function. */
+#define HAVE_WAITPID 1
+
+/* Define to 1 if `fork' works. */
+#define HAVE_WORKING_FORK 1
+
+/* Define to 1 if `vfork' works. */
+#define HAVE_WORKING_VFORK 1
+
+/* Build host information. (not used by kmk) */
+#define MAKE_HOST "i586-pc-haiku"
+
+/* Define to 1 to enable job server support in GNU make. */
+#define MAKE_JOBSERVER 1
+
+/* Define to 1 to enable symbolic link timestamp checking. */
+#define MAKE_SYMLINKS 1
+
+/* Define to 1 if your `struct nlist' has an `n_un' member. Obsolete, depend
+   on `HAVE_STRUCT_NLIST_N_UN_N_NAME */
+/* #undef NLIST_NAME_UNION */
+
+/* Define to 1 if struct nlist.n_name is a pointer rather than an array. */
+/* #undef NLIST_STRUCT */
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+/* #undef NO_MINUS_C_MINUS_O */
+
+/* Name of package */
+#define PACKAGE "make"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "bug-make@gnu.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "GNU make"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "GNU make 3.81.90"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "make"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "http://www.gnu.org/software/make/"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "3.81.90"
+
+/* Define to the character that separates directories in PATH. */
+#define PATH_SEPARATOR_CHAR ':'
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to the name of the SCCS 'get' command. */
+#define SCCS_GET "get"
+
+/* Define to 1 if the SCCS 'get' command understands the '-G<file>' option. */
+/* #undef SCCS_GET_MINUS_G */
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at runtime.
+	STACK_DIRECTION > 0 => grows toward higher addresses
+	STACK_DIRECTION < 0 => grows toward lower addresses
+	STACK_DIRECTION = 0 => direction of growth unknown */
+/* #undef STACK_DIRECTION */
+
+/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
+/* #undef STAT_MACROS_BROKEN */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define if struct stat contains a nanoseconds field */
+#define ST_MTIM_NSEC tv_nsec
+
+/* Define to 1 on System V Release 4. */
+/* #undef SVR4 */
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Define to 1 for Encore UMAX. */
+/* #undef UMAX */
+
+/* Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h> instead of
+   <sys/cpustats.h>. */
+/* #undef UMAX4_3 */
+
+/* Enable extensions on AIX 3, Interix.  */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris.  */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop.  */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Version number of package */
+#define VERSION "3.81.90"
+
+/* Use platform specific coding */
+/* #undef WINDOWS32 */
+
+/* Define if using the dmalloc debugging malloc package */
+/* #undef WITH_DMALLOC */
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+   this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef gid_t */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef uid_t */
+
+/* Define uintmax_t if not defined in <stdint.h> or <inttypes.h>. */
+/* #undef uintmax_t */
+
+/* Define as `fork' if `vfork' does not work. */
+/* #undef vfork */
+
+#include "inlined_memchr.h"
Index: /trunk/src/kmk/incdep.c
===================================================================
--- /trunk/src/kmk/incdep.c	(revision 2545)
+++ /trunk/src/kmk/incdep.c	(revision 2546)
@@ -636,5 +636,6 @@
 #elif defined(__APPLE__) \
    || defined(__sun__) || defined(__SunOS__) || defined(__sun) || defined(__SunOS) \
-   || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+   || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) \
+   || defined(__HAIKU__)
   /* No broken preload libraries known to be in common use on these platforms... */
 
Index: /trunk/src/kmk/job.c
===================================================================
--- /trunk/src/kmk/job.c	(revision 2545)
+++ /trunk/src/kmk/job.c	(revision 2546)
@@ -2061,5 +2061,5 @@
 load_too_high (void)
 {
-#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__)
+#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__) || defined(__HAIKU__)
   return 1;
 #else
Index: /trunk/src/kmk/kmkbuiltin/chmod.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/chmod.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/chmod.c	(revision 2546)
@@ -53,5 +53,5 @@
 #include <stdlib.h>
 #include <string.h>
-#ifdef _MSC_VER
+#ifndef _MSC_VER
 # include <unistd.h>
 #else
@@ -60,4 +60,7 @@
 #ifdef __sun__
 # include "solfakes.h"
+#endif
+#ifdef __HAIKU__
+# include "haikufakes.h"
 #endif
 #include "getopt.h"
Index: /trunk/src/kmk/kmkbuiltin/cp_utils.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/cp_utils.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/cp_utils.c	(revision 2546)
@@ -36,4 +36,5 @@
 #endif /* not lint */
 
+#define MSC_DO_64_BIT_IO
 #include "config.h"
 #ifndef _MSC_VER
@@ -53,11 +54,15 @@
 #include <stdlib.h>
 #include <signal.h>
-#include <sysexits.h>
+#ifndef __HAIKU__
+# include <sysexits.h>
+#endif
 #include <unistd.h>
 #ifdef __sun__
 # include "solfakes.h"
 #endif
+#ifdef __HAIKU__
+# include "haikufakes.h"
+#endif
 #ifdef _MSC_VER
-# define MSC_DO_64_BIT_IO
 # include "mscfakes.h"
 #else
Index: /trunk/src/kmk/kmkbuiltin/fts.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/fts.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/fts.c	(revision 2546)
@@ -76,5 +76,5 @@
 
 #if ! HAVE_NBTOOL_CONFIG_H
-# if !defined(__sun__) && !defined(__gnu_linux__)
+# if !defined(__sun__) && !defined(__gnu_linux__) && !defined(__HAIKU__)
 #  define HAVE_STRUCT_DIRENT_D_NAMLEN 1
 # endif
Index: /trunk/src/kmk/kmkbuiltin/haikufakes.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/haikufakes.c	(revision 2546)
+++ /trunk/src/kmk/kmkbuiltin/haikufakes.c	(revision 2546)
@@ -0,0 +1,53 @@
+/* $Id$ */
+/** @file
+ * Fake Unix/BSD stuff for Haiku.
+ */
+
+/*
+ * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
+ *
+ * This file is part of kBuild.
+ *
+ * kBuild is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * kBuild is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include "config.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include "haikufakes.h"
+
+
+int haiku_lchmod(const char *pszPath, mode_t mode)
+{
+    /*
+     * Weed out symbolic links.
+     */
+    struct stat s;
+    if (    !lstat(pszPath, &s)
+        &&  S_ISLNK(s.st_mode))
+    {
+        errno = -ENOSYS;
+        return -1;
+    }
+
+    return chmod(pszPath, mode);
+}
+
Index: /trunk/src/kmk/kmkbuiltin/haikufakes.h
===================================================================
--- /trunk/src/kmk/kmkbuiltin/haikufakes.h	(revision 2546)
+++ /trunk/src/kmk/kmkbuiltin/haikufakes.h	(revision 2546)
@@ -0,0 +1,40 @@
+/* $Id$ */
+/** @file
+ * Unix/BSD fakes for Haiku.
+ */
+
+/*
+ * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
+ *
+ * This file is part of kBuild.
+ *
+ * kBuild is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * kBuild is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef ___haikufakes_h
+#define ___haikufakes_h
+
+#define EX_OK 0
+#define EX_OSERR 1
+#define EX_NOUSER 1
+#define EX_USAGE 1
+#define EX_TEMPFAIL 1
+#define EX_SOFTWARE 1
+
+#define lutimes(path, tvs) utimes(path, tvs)
+#define lchmod             haiku_lchmod
+
+#endif
+
Index: /trunk/src/kmk/kmkbuiltin/install.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/install.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/install.c	(revision 2546)
@@ -53,5 +53,7 @@
 #  include <sys/mman.h>
 # endif
-# include <sys/mount.h>
+# ifndef __HAIKU__
+#  include <sys/mount.h>
+# endif
 # include <sys/wait.h>
 # include <sys/time.h>
@@ -69,5 +71,7 @@
 #include <stdlib.h>
 #include <string.h>
-#include <sysexits.h>
+#ifndef __HAIKU__
+# include <sysexits.h>
+#endif
 #include <unistd.h>
 #if defined(__EMX__) || defined(_MSC_VER)
@@ -80,4 +84,7 @@
 #ifdef _MSC_VER
 # include "mscfakes.h"
+#endif
+#ifdef __HAIKU__
+# include "haikufakes.h"
 #endif
 #include "kmkbuiltin.h"
Index: /trunk/src/kmk/kmkbuiltin/mkdir.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/mkdir.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/mkdir.c	(revision 2546)
@@ -54,5 +54,7 @@
 #include <stdlib.h>
 #include <string.h>
-#include <sysexits.h>
+#ifndef __HAIKU__
+# include <sysexits.h>
+#endif
 #include <unistd.h>
 #ifdef HAVE_ALLOCA_H
@@ -60,4 +62,7 @@
 #endif
 #include "getopt.h"
+#ifdef __HAIKU__
+# include "haikufakes.h"
+#endif
 #ifdef _MSC_VER
 # include <malloc.h>
Index: /trunk/src/kmk/kmkbuiltin/mv.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/mv.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/mv.c	(revision 2546)
@@ -56,5 +56,7 @@
 # include <sys/time.h>
 # include <sys/wait.h>
-# include <sys/mount.h>
+# ifndef __HAIKU__
+#  include <sys/mount.h>
+# endif
 #endif
 #include <sys/stat.h>
@@ -70,9 +72,14 @@
 #include <stdlib.h>
 #include <string.h>
-#include <sysexits.h>
+#ifndef __HAIKU__
+# include <sysexits.h>
+#endif
 #include <unistd.h>
 #include "getopt.h"
 #ifdef __sun__
 # include "solfakes.h"
+#endif
+#ifdef __HAIKU__
+# include "haikufakes.h"
 #endif
 #ifdef _MSC_VER
Index: /trunk/src/kmk/kmkbuiltin/rm.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/rm.c	(revision 2545)
+++ /trunk/src/kmk/kmkbuiltin/rm.c	(revision 2546)
@@ -44,5 +44,5 @@
 #include "config.h"
 #include <sys/stat.h>
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__HAIKU__)
 # include <sys/param.h>
 # include <sys/mount.h>
@@ -58,8 +58,13 @@
 #include <stdlib.h>
 #include <string.h>
-#include <sysexits.h>
+#ifndef __HAIKU__
+# include <sysexits.h>
+#endif
 #include <unistd.h>
 #include <ctype.h>
 #include "getopt.h"
+#ifdef __HAIKU__
+# include "haikufakes.h"
+#endif
 #ifdef _MSC_VER
 # include "mscfakes.h"
Index: /trunk/src/kmk/main.c
===================================================================
--- /trunk/src/kmk/main.c	(revision 2545)
+++ /trunk/src/kmk/main.c	(revision 2546)
@@ -55,4 +55,7 @@
 #  define INCL_BASE
 #  include <os2.h>
+# endif
+# ifdef __HAIKU__
+#  include <OS.h>
 # endif
 #endif /* KMK*/
@@ -840,5 +843,5 @@
     if (!SetProcessAffinityMask (GetCurrentProcess (), process_affinity))
       fprintf (stderr, "warning: SetPriorityClass (,%#x) failed with last error %d\n",
-               process_affinity, GetLastError());
+               process_affinity, GetLastError ());
 
   switch (process_priority)
@@ -850,9 +853,28 @@
       case 4:     dwPriority = HIGH_PRIORITY_CLASS; break;
       case 5:     dwPriority = REALTIME_PRIORITY_CLASS; break;
-      default:    fatal(NILF, _("invalid priority %d\n"), process_priority);
+      default:    fatal (NILF, _("invalid priority %d\n"), process_priority);
     }
   if (!SetPriorityClass (GetCurrentProcess (), dwPriority))
     fprintf (stderr, "warning: SetPriorityClass (,%#x) failed with last error %d\n",
              dwPriority, GetLastError ());
+
+#elif defined(__HAIKU__)
+  int32 iNewPriority;
+  status_t error;
+
+  switch (process_priority)
+    {
+      case 0:     return;
+      case 1:     iNewPriority = B_LOWEST_ACTIVE_PRIORITY; break;
+      case 2:     iNewPriority = B_LOW_PRIORITY; break;
+      case 3:     iNewPriority = B_NORMAL_PRIORITY; break;
+      case 4:     iNewPriority = B_URGENT_DISPLAY_PRIORITY; break;
+      case 5:     iNewPriority = B_REAL_TIME_DISPLAY_PRIORITY; break;
+      default:    fatal (NILF, _("invalid priority %d\n"), process_priority);
+    }
+  error = set_thread_priority (find_thread (NULL), iNewPriority);
+  if (error != B_OK)
+    fprintf (stderr, "warning: set_thread_priority (,%d) failed: %s\n",
+             newPriority, strerror (error));
 
 # else /*#elif HAVE_NICE */
@@ -866,5 +888,5 @@
       case 4:     nice_level = -10; break;
       case 5:     nice_level = -19; break;
-      default:    fatal(NILF, _("invalid priority %d\n"), process_priority);
+      default:    fatal (NILF, _("invalid priority %d\n"), process_priority);
     }
   errno = 0;
Index: /trunk/src/lib/k/kDefs.h
===================================================================
--- /trunk/src/lib/k/kDefs.h	(revision 2545)
+++ /trunk/src/lib/k/kDefs.h	(revision 2546)
@@ -43,20 +43,22 @@
 /** FreeBSD. */
 #define K_OS_FREEBSD    3
+/** Haiku. */
+#define K_OS_HAIKU      4
 /** Linux. */
-#define K_OS_LINUX      4
+#define K_OS_LINUX      5
 /** NetBSD. */
-#define K_OS_NETBSD     5
+#define K_OS_NETBSD     6
 /** NT (native). */
-#define K_OS_NT         6
+#define K_OS_NT         7
 /** OpenBSD*/
-#define K_OS_OPENBSD    7
+#define K_OS_OPENBSD    8
 /** OS/2 */
-#define K_OS_OS2        8
+#define K_OS_OS2        9
 /** Solaris */
-#define K_OS_SOLARIS    9
+#define K_OS_SOLARIS    10
 /** Windows. */
-#define K_OS_WINDOWS    10
+#define K_OS_WINDOWS    11
 /** The max K_OS_* value (exclusive). */
-#define K_OS_MAX        11
+#define K_OS_MAX        12
 /** @} */
 
@@ -79,4 +81,6 @@
 # elif defined(__FreeBSD__) /*??*/
 #  define K_OS      K_OS_FREEBSD
+# elif defined(__HAIKU__)
+#  define K_OS      K_OS_HAIKU
 # elif defined(__gnu_linux__)
 #  define K_OS      K_OS_LINUX
Index: /trunk/src/misc/kmk_time.c
===================================================================
--- /trunk/src/misc/kmk_time.c	(revision 2545)
+++ /trunk/src/misc/kmk_time.c	(revision 2546)
@@ -364,4 +364,5 @@
             rc = WEXITSTATUS(rc);
         }
+# ifndef __HAIKU__ /**@todo figure how haiku signals that a core was dumped. */
         else if (WIFSIGNALED(rc) && WCOREDUMP(rc))
         {
@@ -369,4 +370,5 @@
             rc = 10;
         }
+# endif
         else if (WIFSIGNALED(rc))
         {
Index: /trunk/src/sed/Makefile.kmk
===================================================================
--- /trunk/src/sed/Makefile.kmk	(revision 2545)
+++ /trunk/src/sed/Makefile.kmk	(revision 2546)
@@ -70,4 +70,7 @@
 	lib/obstack.c \
 	lib/getline.c
+kmk_sed_SOURCES.haiku = \
+	lib/strverscmp.c \
+	lib/obstack.c
 kmk_sed_SOURCES.openbsd = \
 	lib/strverscmp.c \
@@ -76,5 +79,5 @@
 kmk_sed_SOURCES.solaris = \
 	lib/strverscmp.c \
-	lib/obstack.c 
+	lib/obstack.c
 ifdef KBUILD_SOLARIS_10
 kmk_sed_SOURCES.solaris += \
