Index: trunk/kBuild/env.sh
===================================================================
--- trunk/kBuild/env.sh	(revision 556)
+++ trunk/kBuild/env.sh	(revision 557)
@@ -29,10 +29,6 @@
 # kBuild path.
 if [ -z "$PATH_KBUILD" ]; then
-    if which realpath > /dev/null 2>&1; then
-        PATH_KBUILD=`realpath $0`
-    else
-        PATH_KBUILD=`readlink -f $0`
-    fi
-    PATH_KBUILD=`dirname "$PATH_KBUILD"`
+    PATH_KBUILD=`dirname "$0"`
+    PATH_KBUILD=`cd "$PATH_KBUILD" ; /bin/pwd`
 fi
 if [ ! -f "$PATH_KBUILD/footer.kmk" -o ! -f "$PATH_KBUILD/header.kmk" -o ! -f "$PATH_KBUILD/rules.kmk" ]; then
@@ -104,4 +100,8 @@
         netbsd|NetBSD|NETBSD)
             BUILD_PLATFORM=netbsd
+            ;;
+
+        Darwin|darwin)
+            BUILD_PLATFORM=darwin
             ;;
 
Index: trunk/kBuild/header.kmk
===================================================================
--- trunk/kBuild/header.kmk	(revision 556)
+++ trunk/kBuild/header.kmk	(revision 557)
@@ -104,5 +104,5 @@
 else
  BUILD_PLATFORM     := $(strip $(BUILD_PLATFORM))
- ifneq ($(words $(BUILD_PLATFORM))$(filter-out freebsd l4 linux nt os2 win win32 win64,$(BUILD_PLATFORM)),1)
+ ifneq ($(words $(BUILD_PLATFORM))$(filter-out darwin freebsd l4 linux nt os2 win win32 win64,$(BUILD_PLATFORM)),1)
   # OS/2 (have uppercase legacy)
   ifeq ($(BUILD_PLATFORM),OS2)
@@ -138,5 +138,5 @@
 else
  BUILD_TARGET       := $(strip $(BUILD_TARGET))
- ifneq ($(words $(BUILD_TARGET))$(filter-out freebsd l4 linux nt os2 win win32 win64,$(BUILD_TARGET)),1)
+ ifneq ($(words $(BUILD_TARGET))$(filter-out darwin freebsd l4 linux nt os2 win win32 win64,$(BUILD_TARGET)),1)
   # OS/2 (have uppercase legacy)
   ifeq ($(BUILD_TARGET),OS2)
@@ -248,4 +248,11 @@
 HOSTSUFF_EXE        :=
 endif
+
+# Darwin / Mac OS X
+ifeq ($(BUILD_PLATFORM),darwin)
+EXEC_X86_WIN32      := false
+HOSTSUFF_EXE        :=
+endif
+
 
 PATH_TOOLS          := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM)
@@ -285,4 +292,12 @@
 SUFF_RES            :=
 endif
+ifeq ($(BUILD_TARGET),darwin)
+SUFF_OBJ            := .o
+SUFF_LIB            := .a
+SUFF_DLL            := .dylib
+SUFF_EXE            :=
+SUFF_SYS            := .a
+SUFF_RES            :=
+endif
 ifndef SUFF_OBJ
 SUFF_OBJ            := .o
Index: trunk/kBuild/tools/GCC3.kmk
===================================================================
--- trunk/kBuild/tools/GCC3.kmk	(revision 556)
+++ trunk/kBuild/tools/GCC3.kmk	(revision 557)
@@ -74,10 +74,7 @@
 ifeq ($(BUILD_TARGET),os2)
 TOOL_GCC3_LD_MAP              = -Zmap=$(1)
+TOOL_GCC3_LD_SYSMOD_MAP       = -Zmap=$(1)
 else
 TOOL_GCC3_LD_MAP              = -Wl,-Map -Wl,$(1) -Wl,--cref
-endif
-ifeq ($(BUILD_TARGET),os2)
-TOOL_GCC3_LD_SYSMOD_MAP       = -Zmap=$(1)
-else
 TOOL_GCC3_LD_SYSMOD_MAP       = -Map $(1) --cref
 endif
Index: trunk/kBuild/tools/GCC4MACH.kmk
===================================================================
--- trunk/kBuild/tools/GCC4MACH.kmk	(revision 557)
+++ trunk/kBuild/tools/GCC4MACH.kmk	(revision 557)
@@ -0,0 +1,242 @@
+# $Id: GCC4MACH.kmk 474 2006-07-16 03:43:04Z bird $
+## @file
+#
+# kBuild Tool Config - Darwin / Mac OS X / Mach GCC (v4).
+#
+# Copyright (c) 2004-2006 knut st. osmundsen <bird-srcspam@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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#
+
+TOOL_GCC4MACH                    := Mach GCC v4
+
+TOOL_GCC4MACH_CC                 := gcc$(HOSTSUFF_EXE)
+TOOL_GCC4MACH_COBJSUFF           := .o
+TOOL_GCC4MACH_CFLAGS             := -g
+TOOL_GCC4MACH_CFLAGS.debug       := -O0
+TOOL_GCC4MACH_CFLAGS.release     := -O2
+TOOL_GCC4MACH_CFLAGS.profile     := -O2 #-pg
+TOOL_GCC4MACH_CINCS              :=
+TOOL_GCC4MACH_CDEFS              :=
+
+TOOL_GCC4MACH_CXX                := g++$(HOSTSUFF_EXE)
+TOOL_GCC4MACH_CXXOBJSUFF         := .o
+TOOL_GCC4MACH_CXXOBJSUFF         := .o
+TOOL_GCC4MACH_CXXFLAGS           := -g
+TOOL_GCC4MACH_CXXFLAGS.debug     := -O0
+TOOL_GCC4MACH_CXXFLAGS.release   := -O2
+TOOL_GCC4MACH_CXXFLAGS.profile   := -O2 #-pg
+TOOL_GCC4MACH_CXXINCS            :=
+TOOL_GCC4MACH_CXXDEFS            :=
+
+TOOL_GCC4MACH_AS                 := gcc$(HOSTSUFF_EXE)
+TOOL_GCC4MACH_ASFLAGS            := -g -x assembler-with-cpp
+TOOL_GCC4MACH_ASOBJSUFF          := .o
+
+TOOL_GCC4MACH_AR                 := ar$(HOSTSUFF_EXE)
+TOOL_GCC4MACH_ARFLAGS            := -c -rs
+TOOL_GCC4MACH_ARLIBSUFF          := .a
+
+TOOL_GCC4MACH_AR_IMP             := $(ECHO) not supported!
+
+TOOL_GCC4MACH_LD                 := g++$(HOSTSUFF_EXE)
+TOOL_GCC4MACH_LD_SYSMOD          := ld$(HOSTSUFF_EXE)
+TOOL_GCC4MACH_LDFLAGS            :=
+TOOL_GCC4MACH_LDFLAGS.debug      := -g
+TOOL_GCC4MACH_LDFLAGS.release    := -s
+ifndef TOOL_GCC4MACH_LDFLAGS.$(BUILD_TARGET)
+TOOL_GCC4MACH_LDFLAGS.dll        := -shared
+else
+TOOL_GCC4MACH_LDFLAGS.dll        := $(TOOL_GCC4MACH_LDFLAGS.$(BUILD_TARGET))
+endif
+TOOL_GCC4MACH_LDFLAGS.sysmod     := -r
+TOOL_GCC4MACH_LD_SONAME           = -Wl,-soname=$(firstword $($(1)_SONAME.$(BUILD_TARGET).$(BUILD_TYPE)) $($(1)_SONAME.$(BUILD_TARGET)) $($(1)_SONAME.$(BUILD_TYPE)) $($(1)_SONAME) $(notdir $(2)))
+TOOL_GCC4MACH_LD_MAP              =
+TOOL_GCC4MACH_LD_SYSMOD_MAP       =
+
+ifdef SLKRUNS
+TOOL_GCC4MACH_CC  += -fmessage-length=0
+TOOL_GCC4MACH_CXX += -fmessage-length=0
+endif
+
+
+## Compile C source.
+# @param    $(target)   Normalized main target name.
+# @param    $(source)   Source filename (relative).
+# @param    $(obj)      Object file name. This shall be (re)created by the compilation.
+# @param    $(dep)	    Dependcy file. This shall be (re)created by the compilation.
+# @param    $(flags)    Flags.
+# @param    $(defs)     Definitions. No -D or something.
+# @param    $(incs)     Includes. No -I or something.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)		Other dependencies.
+#
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+# @param    $(objsuff)  Object suffix.
+TOOL_GCC4MACH_COMPILE_C_OUTPUT =
+TOOL_GCC4MACH_COMPILE_C_DEPEND =
+TOOL_GCC4MACH_COMPILE_C_DEPORD =
+define TOOL_GCC4MACH_COMPILE_C_CMDS
+	$(TOOL_GCC4MACH_CC) -c\
+		$(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
+		-Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
+		-o $(obj)\
+		$(call ABSPATH,$(source))
+endef
+
+
+## Compile C++ source.
+# @param    $(target)   Normalized main target name.
+# @param    $(source)   Source filename (relative).
+# @param    $(obj)      Object file name. This shall be (re)created by the compilation.
+# @param    $(dep)	    Dependcy file. This shall be (re)created by the compilation.
+# @param    $(flags)    Flags.
+# @param    $(defs)     Definitions. No -D or something.
+# @param    $(incs)     Includes. No -I or something.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)		Other dependencies.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+# @param    $(objsuff)  Object suffix.
+TOOL_GCC4MACH_COMPILE_CXX_OUTPUT =
+TOOL_GCC4MACH_COMPILE_CXX_DEPEND =
+TOOL_GCC4MACH_COMPILE_CXX_DEPORD =
+define TOOL_GCC4MACH_COMPILE_CXX_CMDS
+	$(TOOL_GCC4MACH_CXX) -c\
+		$(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
+		-Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
+		-o $(obj)\
+		$(call ABSPATH,$(source))
+endef
+
+
+## Compile Assembly source.
+# @param    $(target)   Normalized main target name.
+# @param    $(source)   Source filename (relative).
+# @param    $(obj)      Object file name. This shall be (re)created by the compilation.
+# @param    $(dep)      Dependcy file. This shall be (re)created by the compilation.
+# @param    $(flags)    Flags.
+# @param    $(defs)     Definitions. No -D or something.
+# @param    $(incs)     Includes. No -I or something.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)     Other dependencies.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+# @param    $(objsuff)  Object suffix.
+#
+TOOL_GCC4MACH_COMPILE_AS_OUTPUT =
+TOOL_GCC4MACH_COMPILE_AS_DEPEND =
+TOOL_GCC4MACH_COMPILE_AS_DEPORD =
+define TOOL_GCC4MACH_COMPILE_AS_CMDS
+	$(TOOL_GCC4MACH_AS) -c\
+		$(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
+		-Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
+		-o $(obj)\
+		$(call ABSPATH,$(source))
+endef
+
+
+## Link library
+# @param    $(target)   Normalized main target name.
+# @param    $(out)		Library name.
+# @param    $(objs)     Object files to put in the library.
+# @param    $(flags)    Flags.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)		Other dependencies.
+# @param    $(othersrc) Unhandled sources.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+TOOL_GCC4MACH_LINK_LIBRARY_OUTPUT = 
+TOOL_GCC4MACH_LINK_LIBRARY_DEPEND = $(filter %.a %.lib %.def %.imp,$(othersrc))
+TOOL_GCC4MACH_LINK_LIBRARY_DEPORD =
+define TOOL_GCC4MACH_LINK_LIBRARY_CMDS
+	$(TOOL_GCC4MACH_AR) $(flags) $(out) $(objs) $(filter %.a %.lib, $(othersrc))
+endef
+
+
+## Link program
+# @param    $(target)   Normalized main target name.
+# @param    $(out)		Program name.
+# @param    $(objs)     Object files to link together.
+# @param    $(libs)     Libraries to search.
+# @param    $(libpath)  Library search paths.
+# @param    $(flags)    Flags.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)		Other dependencies.
+# @param    $(othersrc) Unhandled sources.
+# @param    $(custom_pre)   Custom step invoked before linking.
+# @param    $(custom_post)  Custom step invoked after linking.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+TOOL_GCC4MACH_LINK_PROGRAM_OUTPUT = $(outbase).map
+TOOL_GCC4MACH_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
+TOOL_GCC4MACH_LINK_PROGRAM_DEPORD =
+define TOOL_GCC4MACH_LINK_PROGRAM_CMDS
+	$(TOOL_GCC4MACH_LD) $(flags) -o $(out) $(objs)\
+		$(foreach p,$(libpath), -L$(p))\
+		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
+		$(call TOOL_GCC4MACH_LD_MAP,$(outbase).map)
+endef
+
+
+## Link DLL
+# @param    $(target)   Normalized main target name.
+# @param    $(out)		Program name.
+# @param    $(objs)     Object files to link together.
+# @param    $(libs)     Libraries to search.
+# @param    $(libpath)  Library search paths.
+# @param    $(flags)    Flags.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)		Other dependencies.
+# @param    $(othersrc) Unhandled sources.
+# @param    $(custom_pre)   Custom step invoked before linking.
+# @param    $(custom_post)  Custom step invoked after linking.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+TOOL_GCC4MACH_LINK_DLL_OUTPUT = $(outbase).map
+TOOL_GCC4MACH_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
+TOOL_GCC4MACH_LINK_DLL_DEPORD =
+define TOOL_GCC4MACH_LINK_DLL_CMDS
+	$(TOOL_GCC4MACH_LD) $(TOOL_GCC4MACH_LDFLAGS.dll) $(flags) -o $(out)\
+		$(if $(filter-out win32 os2, $(BUILD_TARGET)),$(call TOOL_GCC4MACH_LD_SONAME,$(target),$(out)))\
+		$(objs)\
+		$(foreach p,$(libpath), -L$(p))\
+		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
+		$(call TOOL_GCC4MACH_LD_MAP,$(outbase).map)
+endef
+
+
+## Link system module (windows aka driver, linux aka kernel module)
+# @param    $(target)   Normalized main target name.
+# @param    $(out)		System module name.
+# @param    $(objs)     Object files to link together.
+# @param    $(libs)     Libraries to search.
+# @param    $(libpath)  Library search paths.
+# @param    $(flags)    Flags.
+# @param    $(dirdep)   Directory creation dependency.
+# @param    $(deps)		Other dependencies.
+# @param    $(othersrc) Unhandled sources.
+# @param    $(custom_pre)   Custom step invoked before linking.
+# @param    $(custom_post)  Custom step invoked after linking.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+TOOL_GCC4MACH_LINK_SYSMOD_OUTPUT = $(outbase).map
+TOOL_GCC4MACH_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
+TOOL_GCC4MACH_LINK_SYSMOD_DEPORD =
+define TOOL_GCC4MACH_LINK_SYSMOD_CMDS
+	$(TOOL_GCC4MACH_LD_SYSMOD) $(TOOL_GCC4MACH_LDFLAGS.sysmod) $(flags) -o $(out) $(objs)\
+		$(foreach p,$(libpath), -L$(p))\
+		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
+		$(call TOOL_GCC4MACH_LD_SYSMOD_MAP,$(outbase).map)
+endef
+
