From e06440cb80c414cb8f9dcc3f8ae04f8a9bcb8779 Mon Sep 17 00:00:00 2001
From: BenjaminAmos <24301287+BenjaminAmos@users.noreply.github.com>
Date: Fri, 15 Nov 2019 22:07:00 +0100
Subject: Haiku patch

---
 build/premake/extern_libs4.lua                |   7 +-
 build/premake/extern_libs5.lua                |   5 +
 build/premake/premake4.lua                    |  17 +-
 .../premake4/build/gmake.unix/Premake4.make   | 384 +++++++++---------
 build/premake/premake4/premake4.lua           |   2 +-
 build/premake/premake5.lua                    |  19 +-
 .../premake5/build/gmake.unix/Premake5.make   |   8 +-
 .../premake5/contrib/curl/lib/curl_setup.h    |   4 +
 .../premake/premake5/contrib/curl/lib/if2ip.c |   3 +
 .../premake5/contrib/curl/premake5.lua        |   2 +-
 build/premake/premake5/premake5.lua           |   8 +-
 .../premake/premake5/src/host/os_getversion.c |   2 +-
 build/premake/premake5/src/host/premake.c     |   6 +
 build/premake/premake5/src/host/premake.h     |   2 +-
 build/workspaces/update-workspaces.sh         |   5 +-
 .../fcollada/include/FCDocument/FCDocument.h  |   2 +-
 .../fcollada/include/FUtils/Platforms.h       |   4 +-
 .../fcollada/src/FCollada/FUtils/FUAssert.cpp |   4 +
 .../src/FCollada/FUtils/FUPluginManager.cpp   |  11 +
 .../src/FCollada/FUtils/FUStringBuilder.h     |   2 +-
 .../source/nvtt/src/src/nvcore/Debug.cpp      |   8 +
 libraries/source/nvtt/src/src/nvcore/nvcore.h |   3 +
 .../source/nvtt/src/src/nvcore/poshlib/posh.h |   5 +
 .../source/nvtt/src/src/nvimage/ImageIO.cpp   |  10 +
 .../source/spidermonkey/FixHaikuBuild.diff    | 197 +++++++++
 libraries/source/spidermonkey/build.sh        |  51 +++
 libraries/source/spidermonkey/patch.sh        |   3 +
 source/lib/allocators/page_aligned.cpp        |   8 +
 source/lib/config2.h                          |   2 +-
 source/lib/posix/posix_aio.h                  |   2 +-
 source/lib/secure_crt.h                       |   4 +-
 source/lib/sysdep/os.h                        |  10 +-
 source/lib/sysdep/os/haiku/dir_watch.cpp      |  36 ++
 source/lib/sysdep/os/haiku/haiku.cpp          | 147 +++++++
 source/lib/sysdep/os/haiku/hcpu.cpp           | 120 ++++++
 source/lib/sysdep/os/haiku/hdbg.cpp           |  46 +++
 .../os/unix/unix_executable_pathname.cpp      |   4 +-
 source/lib/sysdep/os/unix/uvm.cpp             |   3 +
 source/main.cpp                               |   2 +-
 source/ps/GameSetup/GameSetup.cpp             |   5 +-
 source/ps/GameSetup/Paths.cpp                 |   8 +
 source/third_party/tinygettext/src/iconv.cpp  |   2 +-
 42 files changed, 942 insertions(+), 231 deletions(-)
 create mode 100644 libraries/source/spidermonkey/FixHaikuBuild.diff
 create mode 100644 source/lib/sysdep/os/haiku/dir_watch.cpp
 create mode 100644 source/lib/sysdep/os/haiku/haiku.cpp
 create mode 100644 source/lib/sysdep/os/haiku/hcpu.cpp
 create mode 100644 source/lib/sysdep/os/haiku/hdbg.cpp

diff --git a/build/premake/extern_libs4.lua b/build/premake/extern_libs4.lua
index fed12da..3e97e22 100644
--- a/build/premake/extern_libs4.lua
+++ b/build/premake/extern_libs4.lua
@@ -347,7 +347,7 @@ extern_lib_defs = {
 			elseif os.is("macosx") then
 				add_default_include_paths("iconv")
 				defines { "LIBICONV_STATIC" }
-			elseif os.getversion().description == "FreeBSD" then
+			elseif os.getversion().description == "FreeBSD" or os.is("haiku") then
 				defines { "HAVE_ICONV_CONST" }
 				defines { "ICONV_CONST=const" }
 			end
@@ -359,6 +359,7 @@ extern_lib_defs = {
 			add_default_links({
 				win_names  = { "libiconv" },
 				osx_names = { "iconv" },
+				unix_names = { "iconv" },
 				dbg_suffix = "",
 				no_delayload = 1,
 			})
@@ -724,14 +725,14 @@ extern_lib_defs = {
 		link_settings = function()
 			add_default_links({
 				win_names  = { },
-				unix_names = { "X11" },
+--				unix_names = { "X11" },
 			})
 		end,
 	},
 	xcursor = {
 		link_settings = function()
 			add_default_links({
-				unix_names = { "Xcursor" },
+--				unix_names = { "Xcursor" },
 			})
 		end,
 	},
diff --git a/build/premake/extern_libs5.lua b/build/premake/extern_libs5.lua
index 710cc55..eb13e63 100644
--- a/build/premake/extern_libs5.lua
+++ b/build/premake/extern_libs5.lua
@@ -320,6 +320,7 @@ extern_lib_defs = {
 			add_default_links({
 				win_names  = { "libiconv" },
 				osx_names = { "iconv" },
+				unix_names = { "iconv" },
 				dbg_suffix = "",
 				no_delayload = 1,
 			})
@@ -694,17 +695,21 @@ extern_lib_defs = {
 	},
 	x11 = {
 		link_settings = function()
+			if not os.istarget("haiku") then
 			add_default_links({
 				win_names  = { },
 				unix_names = { "X11" },
 			})
+			end
 		end,
 	},
 	xcursor = {
 		link_settings = function()
+			if not os.istarget("haiku") then
 			add_default_links({
 				unix_names = { "Xcursor" },
 			})
+			end
 		end,
 	},
 	zlib = {
diff --git a/build/premake/premake4.lua b/build/premake/premake4.lua
index 8b997e2..dcb763d 100644
--- a/build/premake/premake4.lua
+++ b/build/premake/premake4.lua
@@ -382,7 +382,7 @@ end
 -- add X11 includes paths after all the others so they don't conflict with
 -- bundled libs
 function project_add_x11_dirs()
-	if not os.is("windows") and not os.is("macosx") then
+	if not os.is("windows") and not os.is("macosx") and not os.is("haiku") then
 		-- X11 includes may be installed in one of a gadzillion of five places
 		-- Famous last words: "You can't include too much! ;-)"
 		includedirs {
@@ -835,6 +835,7 @@ function setup_all_libs ()
 		windows = { "lib/sysdep/os/win", "lib/sysdep/os/win/wposix", "lib/sysdep/os/win/whrt" },
 		macosx = { "lib/sysdep/os/osx", "lib/sysdep/os/unix" },
 		bsd = { "lib/sysdep/os/bsd", "lib/sysdep/os/unix", "lib/sysdep/os/unix/x" },
+		haiku = { "lib/sysdep/os/haiku", "lib/sysdep/os/unix" }
 	}
 	for i,v in pairs(sysdep_dirs[os.get()]) do
 		table.insert(source_dirs, v);
@@ -1022,6 +1023,13 @@ function setup_main_exe ()
 		linkoptions { "-framework ApplicationServices", "-framework Cocoa", "-framework CoreFoundation" }
 
 	end
+
+	if os.is("haiku") then
+		linkoptions {
+		links { "be" }
+			"/boot/system/lib/libnetwork.so"
+		}
+	end
 end
 
 
@@ -1458,6 +1466,13 @@ function setup_tests()
 
 		includedirs { source_root .. "pch/test/" }
 	end
+
+	if os.is("haiku") then
+		linkoptions {
+		links { "be" }
+			"/boot/system/lib/libnetwork.so"
+		}
+	end
 end
 
 -- must come first, so that VC sets it as the default project and therefore
diff --git a/build/premake/premake4/build/gmake.unix/Premake4.make b/build/premake/premake4/build/gmake.unix/Premake4.make
index f5f979c..cab0abb 100644
--- a/build/premake/premake4/build/gmake.unix/Premake4.make
+++ b/build/premake/premake4/build/gmake.unix/Premake4.make
@@ -28,8 +28,8 @@ ifeq ($(config),release)
   CPPFLAGS  += -MMD -MP $(DEFINES) $(INCLUDES)
   CFLAGS    += $(CPPFLAGS) -Wall -Os
   CXXFLAGS  += $(CPPFLAGS) -Wall -Os
-  LDFLAGS   += -s -rdynamic
-  LIBS      += -lm -ldl 
+  LDFLAGS   += -s -Wl,--export-dynamic
+  LIBS      += -lm
   RESFLAGS  += $(DEFINES) $(INCLUDES) 
   LDDEPS    += 
   LINKCMD    = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS)
@@ -50,8 +50,8 @@ ifeq ($(config),debug)
   CPPFLAGS  += -MMD -MP $(DEFINES) $(INCLUDES)
   CFLAGS    += $(CPPFLAGS) -Wall -g
   CXXFLAGS  += $(CPPFLAGS) -Wall -g
-  LDFLAGS   += -rdynamic
-  LIBS      += -lm -ldl 
+  LDFLAGS   += -Wl,--export-dynamic
+  LIBS      += -lm
   RESFLAGS  += $(DEFINES) $(INCLUDES) 
   LDDEPS    += 
   LINKCMD    = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS)
@@ -61,56 +61,56 @@ ifeq ($(config),debug)
   endef
   define POSTBUILDCMDS
   endef
-endif
-
-OBJECTS := \
-	$(OBJDIR)/path_isabsolute.o \
-	$(OBJDIR)/os_getversion.o \
-	$(OBJDIR)/os_isfile.o \
-	$(OBJDIR)/os_uuid.o \
-	$(OBJDIR)/os_chdir.o \
-	$(OBJDIR)/os_pathsearch.o \
-	$(OBJDIR)/os_rmdir.o \
-	$(OBJDIR)/os_match.o \
-	$(OBJDIR)/scripts.o \
-	$(OBJDIR)/os_copyfile.o \
-	$(OBJDIR)/os_isdir.o \
-	$(OBJDIR)/os_mkdir.o \
-	$(OBJDIR)/os_getcwd.o \
-	$(OBJDIR)/premake.o \
-	$(OBJDIR)/string_endswith.o \
-	$(OBJDIR)/loadlib.o \
-	$(OBJDIR)/ldebug.o \
-	$(OBJDIR)/lstring.o \
-	$(OBJDIR)/lparser.o \
-	$(OBJDIR)/lfunc.o \
-	$(OBJDIR)/ldump.o \
-	$(OBJDIR)/liolib.o \
-	$(OBJDIR)/lgc.o \
-	$(OBJDIR)/lundump.o \
-	$(OBJDIR)/lopcodes.o \
-	$(OBJDIR)/lmem.o \
-	$(OBJDIR)/lstate.o \
-	$(OBJDIR)/ltm.o \
-	$(OBJDIR)/ldo.o \
-	$(OBJDIR)/lzio.o \
-	$(OBJDIR)/lstrlib.o \
-	$(OBJDIR)/lapi.o \
-	$(OBJDIR)/lbaselib.o \
-	$(OBJDIR)/ltablib.o \
-	$(OBJDIR)/llex.o \
-	$(OBJDIR)/loslib.o \
-	$(OBJDIR)/ltable.o \
-	$(OBJDIR)/linit.o \
-	$(OBJDIR)/ldblib.o \
-	$(OBJDIR)/lmathlib.o \
-	$(OBJDIR)/lobject.o \
-	$(OBJDIR)/lvm.o \
-	$(OBJDIR)/lcode.o \
-	$(OBJDIR)/lauxlib.o \
-
-RESOURCES := \
-
+endif
+
+OBJECTS := \
+	$(OBJDIR)/path_isabsolute.o \
+	$(OBJDIR)/os_getversion.o \
+	$(OBJDIR)/os_isfile.o \
+	$(OBJDIR)/os_uuid.o \
+	$(OBJDIR)/os_chdir.o \
+	$(OBJDIR)/os_pathsearch.o \
+	$(OBJDIR)/os_rmdir.o \
+	$(OBJDIR)/os_match.o \
+	$(OBJDIR)/scripts.o \
+	$(OBJDIR)/os_copyfile.o \
+	$(OBJDIR)/os_isdir.o \
+	$(OBJDIR)/os_mkdir.o \
+	$(OBJDIR)/os_getcwd.o \
+	$(OBJDIR)/premake.o \
+	$(OBJDIR)/string_endswith.o \
+	$(OBJDIR)/loadlib.o \
+	$(OBJDIR)/ldebug.o \
+	$(OBJDIR)/lstring.o \
+	$(OBJDIR)/lparser.o \
+	$(OBJDIR)/lfunc.o \
+	$(OBJDIR)/ldump.o \
+	$(OBJDIR)/liolib.o \
+	$(OBJDIR)/lgc.o \
+	$(OBJDIR)/lundump.o \
+	$(OBJDIR)/lopcodes.o \
+	$(OBJDIR)/lmem.o \
+	$(OBJDIR)/lstate.o \
+	$(OBJDIR)/ltm.o \
+	$(OBJDIR)/ldo.o \
+	$(OBJDIR)/lzio.o \
+	$(OBJDIR)/lstrlib.o \
+	$(OBJDIR)/lapi.o \
+	$(OBJDIR)/lbaselib.o \
+	$(OBJDIR)/ltablib.o \
+	$(OBJDIR)/llex.o \
+	$(OBJDIR)/loslib.o \
+	$(OBJDIR)/ltable.o \
+	$(OBJDIR)/linit.o \
+	$(OBJDIR)/ldblib.o \
+	$(OBJDIR)/lmathlib.o \
+	$(OBJDIR)/lobject.o \
+	$(OBJDIR)/lvm.o \
+	$(OBJDIR)/lcode.o \
+	$(OBJDIR)/lauxlib.o \
+
+RESOURCES := \
+
 SHELLTYPE := msdos
 ifeq (,$(ComSpec)$(COMSPEC))
   SHELLTYPE := posix
@@ -165,141 +165,141 @@ ifneq (,$(PCH))
 $(GCH): $(PCH) | $(OBJDIR)
 	@echo $(notdir $<)
 	-$(SILENT) cp $< $(OBJDIR)
-	$(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<"
-endif
-
-$(OBJDIR)/path_isabsolute.o: ../../src/host/path_isabsolute.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/path_isabsolute.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_getversion.o: ../../src/host/os_getversion.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getversion.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_isfile.o: ../../src/host/os_isfile.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isfile.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_uuid.o: ../../src/host/os_uuid.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_uuid.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_chdir.o: ../../src/host/os_chdir.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_chdir.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_pathsearch.o: ../../src/host/os_pathsearch.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_pathsearch.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_rmdir.o: ../../src/host/os_rmdir.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_rmdir.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_match.o: ../../src/host/os_match.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_match.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/scripts.o: ../../src/host/scripts.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/scripts.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_copyfile.o: ../../src/host/os_copyfile.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_copyfile.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_isdir.o: ../../src/host/os_isdir.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isdir.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_mkdir.o: ../../src/host/os_mkdir.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_mkdir.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/os_getcwd.o: ../../src/host/os_getcwd.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getcwd.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/premake.o: ../../src/host/premake.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/premake.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/string_endswith.o: ../../src/host/string_endswith.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/string_endswith.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/loadlib.o: ../../src/host/lua-5.1.4/src/loadlib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loadlib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ldebug.o: ../../src/host/lua-5.1.4/src/ldebug.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldebug.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lstring.o: ../../src/host/lua-5.1.4/src/lstring.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstring.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lparser.o: ../../src/host/lua-5.1.4/src/lparser.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lparser.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lfunc.o: ../../src/host/lua-5.1.4/src/lfunc.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lfunc.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ldump.o: ../../src/host/lua-5.1.4/src/ldump.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldump.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/liolib.o: ../../src/host/lua-5.1.4/src/liolib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/liolib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lgc.o: ../../src/host/lua-5.1.4/src/lgc.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lgc.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lundump.o: ../../src/host/lua-5.1.4/src/lundump.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lundump.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lopcodes.o: ../../src/host/lua-5.1.4/src/lopcodes.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lopcodes.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lmem.o: ../../src/host/lua-5.1.4/src/lmem.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmem.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lstate.o: ../../src/host/lua-5.1.4/src/lstate.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstate.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ltm.o: ../../src/host/lua-5.1.4/src/ltm.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltm.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ldo.o: ../../src/host/lua-5.1.4/src/ldo.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldo.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lzio.o: ../../src/host/lua-5.1.4/src/lzio.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lzio.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lstrlib.o: ../../src/host/lua-5.1.4/src/lstrlib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstrlib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lapi.o: ../../src/host/lua-5.1.4/src/lapi.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lapi.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lbaselib.o: ../../src/host/lua-5.1.4/src/lbaselib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lbaselib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ltablib.o: ../../src/host/lua-5.1.4/src/ltablib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltablib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/llex.o: ../../src/host/lua-5.1.4/src/llex.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/llex.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/loslib.o: ../../src/host/lua-5.1.4/src/loslib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loslib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ltable.o: ../../src/host/lua-5.1.4/src/ltable.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltable.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/linit.o: ../../src/host/lua-5.1.4/src/linit.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/linit.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/ldblib.o: ../../src/host/lua-5.1.4/src/ldblib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldblib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lmathlib.o: ../../src/host/lua-5.1.4/src/lmathlib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmathlib.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lobject.o: ../../src/host/lua-5.1.4/src/lobject.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lobject.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lvm.o: ../../src/host/lua-5.1.4/src/lvm.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lvm.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lcode.o: ../../src/host/lua-5.1.4/src/lcode.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lcode.d -MT "$@" -o "$@" -c "$<"
-$(OBJDIR)/lauxlib.o: ../../src/host/lua-5.1.4/src/lauxlib.c $(GCH) | prebuild
-	@echo $(notdir $<)
-	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lauxlib.d -MT "$@" -o "$@" -c "$<"
-
--include $(OBJECTS:%.o=%.d)
--include $(GCH:%.h.gch=%.h.d)
\ No newline at end of file
+	$(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<"
+endif
+
+$(OBJDIR)/path_isabsolute.o: ../../src/host/path_isabsolute.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/path_isabsolute.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_getversion.o: ../../src/host/os_getversion.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getversion.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_isfile.o: ../../src/host/os_isfile.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isfile.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_uuid.o: ../../src/host/os_uuid.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_uuid.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_chdir.o: ../../src/host/os_chdir.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_chdir.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_pathsearch.o: ../../src/host/os_pathsearch.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_pathsearch.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_rmdir.o: ../../src/host/os_rmdir.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_rmdir.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_match.o: ../../src/host/os_match.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_match.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/scripts.o: ../../src/host/scripts.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/scripts.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_copyfile.o: ../../src/host/os_copyfile.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_copyfile.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_isdir.o: ../../src/host/os_isdir.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isdir.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_mkdir.o: ../../src/host/os_mkdir.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_mkdir.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/os_getcwd.o: ../../src/host/os_getcwd.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getcwd.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/premake.o: ../../src/host/premake.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/premake.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/string_endswith.o: ../../src/host/string_endswith.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/string_endswith.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/loadlib.o: ../../src/host/lua-5.1.4/src/loadlib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loadlib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ldebug.o: ../../src/host/lua-5.1.4/src/ldebug.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldebug.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lstring.o: ../../src/host/lua-5.1.4/src/lstring.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstring.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lparser.o: ../../src/host/lua-5.1.4/src/lparser.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lparser.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lfunc.o: ../../src/host/lua-5.1.4/src/lfunc.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lfunc.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ldump.o: ../../src/host/lua-5.1.4/src/ldump.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldump.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/liolib.o: ../../src/host/lua-5.1.4/src/liolib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/liolib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lgc.o: ../../src/host/lua-5.1.4/src/lgc.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lgc.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lundump.o: ../../src/host/lua-5.1.4/src/lundump.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lundump.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lopcodes.o: ../../src/host/lua-5.1.4/src/lopcodes.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lopcodes.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lmem.o: ../../src/host/lua-5.1.4/src/lmem.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmem.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lstate.o: ../../src/host/lua-5.1.4/src/lstate.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstate.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ltm.o: ../../src/host/lua-5.1.4/src/ltm.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltm.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ldo.o: ../../src/host/lua-5.1.4/src/ldo.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldo.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lzio.o: ../../src/host/lua-5.1.4/src/lzio.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lzio.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lstrlib.o: ../../src/host/lua-5.1.4/src/lstrlib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstrlib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lapi.o: ../../src/host/lua-5.1.4/src/lapi.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lapi.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lbaselib.o: ../../src/host/lua-5.1.4/src/lbaselib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lbaselib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ltablib.o: ../../src/host/lua-5.1.4/src/ltablib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltablib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/llex.o: ../../src/host/lua-5.1.4/src/llex.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/llex.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/loslib.o: ../../src/host/lua-5.1.4/src/loslib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loslib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ltable.o: ../../src/host/lua-5.1.4/src/ltable.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltable.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/linit.o: ../../src/host/lua-5.1.4/src/linit.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/linit.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/ldblib.o: ../../src/host/lua-5.1.4/src/ldblib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldblib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lmathlib.o: ../../src/host/lua-5.1.4/src/lmathlib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmathlib.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lobject.o: ../../src/host/lua-5.1.4/src/lobject.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lobject.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lvm.o: ../../src/host/lua-5.1.4/src/lvm.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lvm.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lcode.o: ../../src/host/lua-5.1.4/src/lcode.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lcode.d -MT "$@" -o "$@" -c "$<"
+$(OBJDIR)/lauxlib.o: ../../src/host/lua-5.1.4/src/lauxlib.c $(GCH) | prebuild
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lauxlib.d -MT "$@" -o "$@" -c "$<"
+
+-include $(OBJECTS:%.o=%.d)
+-include $(GCH:%.h.gch=%.h.d)
diff --git a/build/premake/premake4/premake4.lua b/build/premake/premake4/premake4.lua
index 78f461e..c75e7ec 100644
--- a/build/premake/premake4/premake4.lua
+++ b/build/premake/premake4/premake4.lua
@@ -66,7 +66,7 @@
 			linkoptions { "-mmacosx-version-min=10.4" }
 
 		configuration { "not windows", "not solaris", "not macosx" }
-			linkoptions { "-rdynamic" }
+			linkoptions { "-Wl,--export-dynamic" }
 			
 		configuration { "solaris" }
 			linkoptions { "-Wl,--export-dynamic" }
diff --git a/build/premake/premake5.lua b/build/premake/premake5.lua
index 36928fb..1d3985b 100644
--- a/build/premake/premake5.lua
+++ b/build/premake/premake5.lua
@@ -344,7 +344,7 @@ function project_set_build_flags()
 			defines { "INSTALLED_LIBDIR=" .. _OPTIONS["libdir"] }
 		end
 
-		if os.istarget("linux") or os.istarget("bsd") then
+		if os.istarget("linux") or os.istarget("bsd") or os.istarget("haiku") then
 			-- To use our local shared libraries, they need to be found in the
 			-- runtime dynamic linker path. Add their path to -rpath.
 			if _OPTIONS["libdir"] then
@@ -370,7 +370,7 @@ end
 -- add X11 includes paths after all the others so they don't conflict with
 -- bundled libs
 function project_add_x11_dirs()
-	if not os.istarget("windows") and not os.istarget("macosx") then
+	if not os.istarget("windows") and not os.istarget("macosx") and not os.istarget("haiku") then
 		-- X11 includes may be installed in one of a gadzillion of five places
 		-- Famous last words: "You can't include too much! ;-)"
 		sysincludedirs {
@@ -835,6 +835,7 @@ function setup_all_libs ()
 		windows = { "lib/sysdep/os/win", "lib/sysdep/os/win/wposix", "lib/sysdep/os/win/whrt" },
 		macosx = { "lib/sysdep/os/osx", "lib/sysdep/os/unix" },
 		bsd = { "lib/sysdep/os/bsd", "lib/sysdep/os/unix", "lib/sysdep/os/unix/x" },
+		haiku = { "lib/sysdep/os/haiku", "lib/sysdep/os/unix" }
 	}
 	for i,v in pairs(sysdep_dirs[os.target()]) do
 		table.insert(source_dirs, v);
@@ -1036,6 +1037,13 @@ function setup_main_exe ()
 		links { "ApplicationServices.framework", "Cocoa.framework", "CoreFoundation.framework" }
 
 	end
+
+	if os.istarget("haiku") then
+		links { "be" }
+		linkoptions {
+			"/boot/system/lib/libnetwork.so"
+		}
+	end
 end
 
 
@@ -1420,6 +1428,13 @@ function setup_tests()
 
 		includedirs { source_root .. "pch/test/" }
 	end
+
+	if os.istarget("haiku") then
+		links { "be" }
+		linkoptions {
+			"/boot/system/lib/libnetwork.so"
+		}
+	end
 end
 
 -- must come first, so that VC sets it as the default project and therefore
diff --git a/build/premake/premake5/build/gmake.unix/Premake5.make b/build/premake/premake5/build/gmake.unix/Premake5.make
index 70812a9..384b1e2 100644
--- a/build/premake/premake5/build/gmake.unix/Premake5.make
+++ b/build/premake/premake5/build/gmake.unix/Premake5.make
@@ -22,9 +22,9 @@ ifeq ($(config),release)
   ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -Wextra
   ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -Wextra -fno-stack-protector
   ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
-  LIBS += bin/Release/liblua-lib.a bin/Release/libzip-lib.a bin/Release/libzlib-lib.a bin/Release/libcurl-lib.a bin/Release/libmbedtls-lib.a -lm -ldl -lrt
+  LIBS += bin/Release/liblua-lib.a bin/Release/libzip-lib.a bin/Release/libzlib-lib.a bin/Release/libcurl-lib.a bin/Release/libmbedtls-lib.a -lm -lnetwork -lbsd
   LDDEPS += bin/Release/liblua-lib.a bin/Release/libzip-lib.a bin/Release/libzlib-lib.a bin/Release/libcurl-lib.a bin/Release/libmbedtls-lib.a
-  ALL_LDFLAGS += $(LDFLAGS) -s -rdynamic
+  ALL_LDFLAGS += $(LDFLAGS) -s
   LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
   define PREBUILDCMDS
   endef
@@ -49,9 +49,9 @@ ifeq ($(config),debug)
   ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra
   ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -Wall -Wextra
   ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
-  LIBS += bin/Debug/liblua-lib.a bin/Debug/libzip-lib.a bin/Debug/libzlib-lib.a bin/Debug/libcurl-lib.a bin/Debug/libmbedtls-lib.a -lm -ldl -lrt
+  LIBS += bin/Debug/liblua-lib.a bin/Debug/libzip-lib.a bin/Debug/libzlib-lib.a bin/Debug/libcurl-lib.a bin/Debug/libmbedtls-lib.a -lm -lnetwork
   LDDEPS += bin/Debug/liblua-lib.a bin/Debug/libzip-lib.a bin/Debug/libzlib-lib.a bin/Debug/libcurl-lib.a bin/Debug/libmbedtls-lib.a
-  ALL_LDFLAGS += $(LDFLAGS) -rdynamic
+  ALL_LDFLAGS += $(LDFLAGS)
   LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
   define PREBUILDCMDS
   endef
diff --git a/build/premake/premake5/contrib/curl/lib/curl_setup.h b/build/premake/premake5/contrib/curl/lib/curl_setup.h
index f75d7ed..fd67635 100644
--- a/build/premake/premake5/contrib/curl/lib/curl_setup.h
+++ b/build/premake/premake5/contrib/curl/lib/curl_setup.h
@@ -86,6 +86,10 @@
 #  include "config-linux.h"
 #endif
 
+#ifdef __HAIKU__
+#  include "config-linux.h"
+#endif
+
 #ifdef __APPLE__ && __MACH__
 #  include "config-osx.h"
 #endif
diff --git a/build/premake/premake5/contrib/curl/lib/if2ip.c b/build/premake/premake5/contrib/curl/lib/if2ip.c
index d876615..7ee26c5 100644
--- a/build/premake/premake5/contrib/curl/lib/if2ip.c
+++ b/build/premake/premake5/contrib/curl/lib/if2ip.c
@@ -40,6 +40,9 @@
 #ifdef HAVE_SYS_SOCKIO_H
 #  include <sys/sockio.h>
 #endif
+#ifdef __HAIKU__
+#  include <sys/sockio.h>
+#endif
 #ifdef HAVE_IFADDRS_H
 #  include <ifaddrs.h>
 #endif
diff --git a/build/premake/premake5/contrib/curl/premake5.lua b/build/premake/premake5/contrib/curl/premake5.lua
index da5face..5c83c03 100644
--- a/build/premake/premake5/contrib/curl/premake5.lua
+++ b/build/premake/premake5/contrib/curl/premake5.lua
@@ -27,7 +27,7 @@ project "curl-lib"
 		defines { "USE_MBEDTLS" }
 
 	filter { "system:linux or bsd" }
-		defines { "CURL_HIDDEN_SYMBOLS" }
+		defines { "CURL_HIDDEN_SYMBOLS", "_BSD_SOURCE" }
 
 		-- find the location of the ca bundle
 		local ca = nil
diff --git a/build/premake/premake5/premake5.lua b/build/premake/premake5/premake5.lua
index 77cbb14..8d37526 100644
--- a/build/premake/premake5/premake5.lua
+++ b/build/premake/premake5/premake5.lua
@@ -160,12 +160,12 @@
 		filter "system:windows"
 			links       { "ole32", "ws2_32", "advapi32" }
 
-		filter "system:linux or bsd or hurd"
+		filter "system:linux or bsd or hurd or haiku"
 			defines     { "LUA_USE_POSIX", "LUA_USE_DLOPEN" }
-			links       { "m" }
-			linkoptions { "-rdynamic" }
+			links       { "m", "dl", "network" }
+			linkoptions { "-Wl,--export-all-symbols" }
 
-		filter "system:linux or hurd"
+		filter { "system:linux or hurd", "system:not bsd" }
 			links       { "dl", "rt" }
 
 		filter { "system:not windows", "system:not macosx" }
diff --git a/build/premake/premake5/src/host/os_getversion.c b/build/premake/premake5/src/host/os_getversion.c
index 40b0c83..35ae071 100644
--- a/build/premake/premake5/src/host/os_getversion.c
+++ b/build/premake/premake5/src/host/os_getversion.c
@@ -193,7 +193,7 @@ int getversion(struct OsVersionInfo* info)
 
 /*************************************************************/
 
-#elif defined(PLATFORM_BSD) || defined(PLATFORM_LINUX) || defined(PLATFORM_SOLARIS) || defined(PLATFORM_HURD)
+#elif defined(PLATFORM_BSD) || defined(PLATFORM_LINUX) || defined(PLATFORM_SOLARIS) || defined(PLATFORM_HURD) || defined(__HAIKU__)
 
 #include <string.h>
 #include <sys/utsname.h>
diff --git a/build/premake/premake5/src/host/premake.c b/build/premake/premake5/src/host/premake.c
index bdfa56b..fbc63fa 100644
--- a/build/premake/premake5/src/host/premake.c
+++ b/build/premake/premake5/src/host/premake.c
@@ -368,6 +368,7 @@ int premake_locate_executable(lua_State* L, const char* argv0)
 	}
 #endif
 
+#if !defined(__HAIKU__)
 	/* As a fallback, search the PATH with argv[0] */
 	if (!path)
 	{
@@ -400,6 +401,11 @@ int premake_locate_executable(lua_State* L, const char* argv0)
 
 		path = lua_tostring(L, -1);
 	}
+#else
+	/* The fallback logic is broken and always was. This re-implements it correctly IN C. */
+	getcwd(buffer, PATH_MAX);
+	path = buffer;
+#endif
 
 	lua_pushstring(L, path);
 	return 1;
diff --git a/build/premake/premake5/src/host/premake.h b/build/premake/premake5/src/host/premake.h
index 0a0c0d3..a3cae56 100644
--- a/build/premake/premake5/src/host/premake.h
+++ b/build/premake/premake5/src/host/premake.h
@@ -43,7 +43,7 @@
 #define PLATFORM_STRING   "windows"
 #endif
 
-#define PLATFORM_POSIX  (PLATFORM_LINUX || PLATFORM_BSD || PLATFORM_MACOSX || PLATFORM_SOLARIS)
+#define PLATFORM_POSIX  (PLATFORM_LINUX || PLATFORM_BSD || PLATFORM_MACOSX || PLATFORM_SOLARIS || PLATFORM_HAIKU)
 
 
 /* Pull in platform-specific headers required by built-in functions */
diff --git a/build/workspaces/update-workspaces.sh b/build/workspaces/update-workspaces.sh
index e7764b4..b91bf34 100755
--- a/build/workspaces/update-workspaces.sh
+++ b/build/workspaces/update-workspaces.sh
@@ -1,7 +1,8 @@
 #!/bin/sh
 
-if [ "$(id -u)" = "0" ]; then
-   echo "Running as root will mess up file permissions. Aborting ..." 1>&2
+if [ "`uname -s`" != "Haiku" -a "$(id -u)" = "0" ]; then
+   echo "Running as root will mess up file permissions. Aborting ..."
+1>&2
    exit 1
 fi
 
diff --git a/libraries/source/fcollada/include/FCDocument/FCDocument.h b/libraries/source/fcollada/include/FCDocument/FCDocument.h
index de23d94..c7127ef 100644
--- a/libraries/source/fcollada/include/FCDocument/FCDocument.h
+++ b/libraries/source/fcollada/include/FCDocument/FCDocument.h
@@ -30,7 +30,7 @@
 #if defined(WIN32)
 template <class T> class FCOLLADA_EXPORT FCDLibrary; /**< Trick Doxygen. */
 template <class T> class FCOLLADA_EXPORT FUUniqueStringMapT; /**< Trick Doxygen. */
-#elif defined(LINUX) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
+#elif defined(LINUX) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__HAIKU__)
 template <class T> class FCDLibrary; /**< Trick Doxygen. */
 template <class T> class FUUniqueStringMapT; /**< Trick Doxygen. */
 #endif // LINUX
diff --git a/libraries/source/fcollada/include/FUtils/Platforms.h b/libraries/source/fcollada/include/FUtils/Platforms.h
index 8498d99..e3bc3cc 100644
--- a/libraries/source/fcollada/include/FUtils/Platforms.h
+++ b/libraries/source/fcollada/include/FUtils/Platforms.h
@@ -74,7 +74,7 @@
 #include <wchar.h>
 #include <stdint.h>
 
-#elif defined(LINUX) || defined(__PPU__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
+#elif defined(LINUX) || defined(__PPU__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__HAIKU__)
 #include <ctype.h>
 #include <wctype.h>
 #include <unistd.h>
@@ -125,7 +125,7 @@ typedef uint8_t byte;
 #endif // PLATFORMS
 
 // Important functions that some OSes have missing!
-#if defined(__APPLE__) || defined(LINUX) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
+#if defined(__APPLE__) || defined(LINUX) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__HAIKU__)
 inline char* strlower(char* str) { char* it = str; while (*it != 0) { *it = tolower(*it); ++it; } return str; }
 inline wchar_t* wcslwr(wchar_t* str) { wchar_t* it = str; while (*it != 0) { *it = towlower(*it); ++it; } return str; }
 inline int wcsicmp(const wchar_t* s1, const wchar_t* s2) { wchar_t c1 = *s1, c2 = *s2; while (c1 != 0 && c2 != 0) { if (c1 >= 'a' && c1 <= 'z') c1 -= 'a' + 'A'; if (c2 >= 'a' && c2 <= 'z') c2 -= 'a' + 'A'; if (c2 < c1) return -1; else if (c2 > c1) return 1; c1 = *(++s1); c2 = *(++s2); } return 0; }
diff --git a/libraries/source/fcollada/src/FCollada/FUtils/FUAssert.cpp b/libraries/source/fcollada/src/FCollada/FUtils/FUAssert.cpp
index ba5f3d5..4cc2601 100644
--- a/libraries/source/fcollada/src/FCollada/FUtils/FUAssert.cpp
+++ b/libraries/source/fcollada/src/FCollada/FUtils/FUAssert.cpp
@@ -12,8 +12,12 @@
 #include "FUAssert.h"
 
 #ifndef WIN32
+	#ifdef __HAIKU__
+		#include <signal.h>
+	#else
 	#include "sys/signal.h" // Used for throw(SIGTRAP) on UNIX-like systems
 #endif
+#endif
 
 #ifdef __APPLE__
 	#include <CoreServices/CoreServices.h>
diff --git a/libraries/source/fcollada/src/FCollada/FUtils/FUPluginManager.cpp b/libraries/source/fcollada/src/FCollada/FUtils/FUPluginManager.cpp
index 88308d4..abb06f5 100644
--- a/libraries/source/fcollada/src/FCollada/FUtils/FUPluginManager.cpp
+++ b/libraries/source/fcollada/src/FCollada/FUtils/FUPluginManager.cpp
@@ -27,6 +27,9 @@
 #elif defined(__APPLE__) || defined(LINUX)
 	#include <dlfcn.h>
 	#include <dirent.h>
+#endif
+#if defined(__HAIKU__)
+	#include <sys/stat.h>
 #endif //WIN32
 
 //
@@ -129,6 +132,9 @@ void FUPluginManager::LoadPluginsInFolderName(const fstring& folderName, const f
 		}
 
 #elif defined(__APPLE__) || defined(LINUX)
+		#ifdef __HAIKU__
+			struct stat s;
+		#endif
 		fm::string s_filter = TO_STRING(filter);
 		if (s_filter.length() > 0 && s_filter.front() == '*') s_filter.erase(0, 1);
 		if (s_filter.length() > 0 && s_filter.back() == '*') s_filter.pop_back();
@@ -139,7 +145,12 @@ void FUPluginManager::LoadPluginsInFolderName(const fstring& folderName, const f
 		dirent* directoryEntry;
 		while ((directoryEntry = readdir(directory)) != NULL)
 		{
+		#ifdef __HAIKU__
+			stat(directoryEntry->d_name, &s);
+			if (S_ISDIR(s.st_mode)) continue;
+		#else
 			if (directoryEntry->d_type == DT_DIR) continue; // skip sub-folders.
+		#endif
 			if (strstr((const char*) directoryEntry->d_name, s_filter.c_str()) != NULL)
 			{
 				// We have a match.
diff --git a/libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.h b/libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.h
index 781885b..6b93e29 100644
--- a/libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.h
+++ b/libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.h
@@ -135,7 +135,7 @@ public:
 #else
 	inline void append(unsigned int i) { append((uint32) i); } /**< See above. */
 #endif
-#elif defined(__APPLE__) || defined(__OpenBSD__)
+#elif defined(__APPLE__) || defined(__OpenBSD__) || (defined(__HAIKU__) && defined(__i386__))
 	inline void append(size_t i) { append((uint64)i); }
 #endif // defined(WIN32)
 
diff --git a/libraries/source/nvtt/src/src/nvcore/Debug.cpp b/libraries/source/nvtt/src/src/nvcore/Debug.cpp
index 7aa119e..33fedcc 100644
--- a/libraries/source/nvtt/src/src/nvcore/Debug.cpp
+++ b/libraries/source/nvtt/src/src/nvcore/Debug.cpp
@@ -221,6 +221,14 @@ namespace
 			ucontext_t * ucp = (ucontext_t *)secret;
 			return (void *)ucp->sc_eip;
 #		endif
+#	elif defined(__HAIKU__)
+#		if NV_CPU_X86_64
+			ucontext_t * ucp = (ucontext_t *)secret;
+			return (void *)ucp->uc_mcontext.rip;
+#		elif NV_CPU_X86
+			ucontext_t * ucp = (ucontext_t *)secret;
+			return (void* )ucp->uc_mcontext.eip;
+#		endif
 #	else
 #		if NV_CPU_X86_64
 			// #define REG_RIP REG_INDEX(rip) // seems to be 16
diff --git a/libraries/source/nvtt/src/src/nvcore/nvcore.h b/libraries/source/nvtt/src/src/nvcore/nvcore.h
index 5cd1565..2634cfc 100644
--- a/libraries/source/nvtt/src/src/nvcore/nvcore.h
+++ b/libraries/source/nvtt/src/src/nvcore/nvcore.h
@@ -58,6 +58,9 @@
 #	define NV_OS_WIN32 1
 #elif defined POSH_OS_WIN64
 #	define NV_OS_WIN64 1
+#elif defined POSH_OS_HAIKU
+#	define NV_OS_LINUX 1
+#	define NV_OS_UNIX 1
 #else
 #	error "Unsupported OS"
 #endif
diff --git a/libraries/source/nvtt/src/src/nvcore/poshlib/posh.h b/libraries/source/nvtt/src/src/nvcore/poshlib/posh.h
index 2a178ab..a0110d0 100644
--- a/libraries/source/nvtt/src/src/nvcore/poshlib/posh.h
+++ b/libraries/source/nvtt/src/src/nvcore/poshlib/posh.h
@@ -303,6 +303,11 @@ Metrowerks:
 #  define POSH_OS_STRING "OpenBSD"
 #endif
 
+#if defined __HAIKU__
+#  define POSH_OS_HAIKU 1
+#  define POSH_OS_STRING "Haiku"
+#endif
+
 #if defined __CYGWIN32__
 #  define POSH_OS_CYGWIN32 1
 #  define POSH_OS_STRING "Cygwin"
diff --git a/libraries/source/nvtt/src/src/nvimage/ImageIO.cpp b/libraries/source/nvtt/src/src/nvimage/ImageIO.cpp
index e7a14f1..56b8724 100644
--- a/libraries/source/nvtt/src/src/nvimage/ImageIO.cpp
+++ b/libraries/source/nvtt/src/src/nvimage/ImageIO.cpp
@@ -28,7 +28,17 @@ extern "C" {
 
 #if defined(HAVE_TIFF)
 #	define _TIFF_DATA_TYPEDEFS_
+#if defined(__HAIKU__)
+#	define int32 int32_old
+#	define uint32 uint32_old
+#	define TRUE TRUE_OLD
+#endif
 #	include <tiffio.h>
+#if defined(__HAIKU__)
+#	define int32_old int32
+#	define uint32_old uint32
+#	define TRUE_OLD TRUE
+#endif
 #endif
 
 #if defined(HAVE_OPENEXR)
diff --git a/libraries/source/spidermonkey/FixHaikuBuild.diff b/libraries/source/spidermonkey/FixHaikuBuild.diff
new file mode 100644
index 0000000..74d6f47
--- /dev/null
+++ b/libraries/source/spidermonkey/FixHaikuBuild.diff
@@ -0,0 +1,197 @@
+diff -ur mozjs-38.0.0-old/js/src/asmjs/AsmJSSignalHandlers.cpp mozjs-38.0.0-new/js/src/asmjs/AsmJSSignalHandlers.cpp
+--- mozjs-38.0.0-old/js/src/asmjs/AsmJSSignalHandlers.cpp	2015-09-17 20:12:18.030670848 +0000
++++ mozjs-38.0.0-new/js/src/asmjs/AsmJSSignalHandlers.cpp	2017-12-16 09:53:06.911736832 +0000
+@@ -200,6 +200,28 @@
+ #elif defined(XP_MACOSX)
+ # define EIP_sig(p) ((p)->uc_mcontext->__ss.__eip)
+ # define RIP_sig(p) ((p)->uc_mcontext->__ss.__rip)
++#elif defined(__HAIKU__)
++# define EIP_sig(p) ((p)->uc_mcontext.eip)
++# if defined(__x86_64__)
++#  define RIP_sig(p) ((p)->uc_mcontext.rip)
++#  define RAX_sig(p) ((p)->uc_mcontext.rax)
++#  define RCX_sig(p) ((p)->uc_mcontext.rcx)
++#  define RDX_sig(p) ((p)->uc_mcontext.rdx)
++#  define RBX_sig(p) ((p)->uc_mcontext.rbx)
++#  define RSP_sig(p) ((p)->uc_mcontext.rsp)
++#  define RBP_sig(p) ((p)->uc_mcontext.rbp)
++#  define RSI_sig(p) ((p)->uc_mcontext.rsi)
++#  define RDI_sig(p) ((p)->uc_mcontext.rdi)
++#  define R8_sig(p) ((p)->uc_mcontext.r8)
++#  define R9_sig(p) ((p)->uc_mcontext.r9)
++#  define R10_sig(p) ((p)->uc_mcontext.r10)
++#  define R11_sig(p) ((p)->uc_mcontext.r11)
++#  define R12_sig(p) ((p)->uc_mcontext.r12)
++#  define R13_sig(p) ((p)->uc_mcontext.r13)
++#  define R14_sig(p) ((p)->uc_mcontext.r14)
++#  define R15_sig(p) ((p)->uc_mcontext.r15)
++#  define XMM_sig(p,i) ((p)->uc_mcontext.fpu.fp_fxsave.xmm[i])
++# endif
+ #else
+ # error "Don't know how to read/write to the thread state via the mcontext_t."
+ #endif
+diff -ur mozjs-38.0.0-old/js/src/configure mozjs-38.0.0-new/js/src/configure
+--- mozjs-38.0.0-old/js/src/configure	2017-12-16 10:03:35.259260416 +0000
++++ mozjs-38.0.0-new/js/src/configure	2017-12-16 10:28:47.306446336 +0000
+@@ -4408,7 +4408,12 @@
+   esac
+ fi
+
++#HACK: The python modules search path is not being correctly set. This is done manually here.
++echo import site > $MOZ_BUILD_ROOT/_virtualenv/lib/python2.7/site-packages/sitecustomize.py
++echo "site.addsitedir('$MOZ_BUILD_ROOT/_virtualenv/non-packaged/lib/python2.7/site-packages/')" >> $MOZ_BUILD_ROOT/_virtualenv/lib/python2.7/site-packages/sitecustomize.py
+
++#HACK: The process.py script cannot detect the built-in variable so it should be redefined.
++export SHELL=/bin/bash
+
+ echo $ac_n "checking Python environment is Mozilla virtualenv""... $ac_c" 1>&6
+ echo "configure:4479: checking Python environment is Mozilla virtualenv" >&5
+diff -ur mozjs-38.0.0-old/js/src/gc/Memory.cpp mozjs-38.0.0-new/js/src/gc/Memory.cpp
+--- mozjs-38.0.0-old/js/src/gc/Memory.cpp	2015-09-17 20:12:18.031719424 +0000
++++ mozjs-38.0.0-new/js/src/gc/Memory.cpp	2017-12-16 09:53:06.915931136 +0000
+@@ -22,7 +22,7 @@
+ #include <sys/mman.h>
+ #include <unistd.h>
+
+-#elif defined(XP_UNIX)
++#elif defined(XP_UNIX) || defined(__HAIKU__)
+
+ #include <algorithm>
+ #include <errno.h>
+@@ -44,7 +44,7 @@
+ // The OS allocation granularity may not match the page size.
+ static size_t allocGranularity = 0;
+
+-#if defined(XP_UNIX)
++#if defined(XP_UNIX) || defined(__HAIKU__)
+ // The addresses handed out by mmap may grow up or down.
+ static mozilla::Atomic<int, mozilla::Relaxed> growthDirection(0);
+ #endif
+@@ -366,7 +366,7 @@
+     // Not implemented.
+ }
+
+-#elif defined(XP_UNIX)
++#elif defined(XP_UNIX) || defined(__HAIKU__)
+
+ void
+ InitMemorySubsystem()
+@@ -604,7 +604,11 @@
+         return false;
+
+     MOZ_ASSERT(OffsetFromAligned(p, pageSize) == 0);
++#if defined(__HAIKU__)
++    int result = posix_madvise(p, size, POSIX_MADV_DONTNEED);
++#else
+     int result = madvise(p, size, MADV_DONTNEED);
++#endif
+     return result != -1;
+ }
+
+@@ -625,7 +629,12 @@
+     int err = getrusage(RUSAGE_SELF, &usage);
+     if (err)
+         return 0;
++#if defined(__HAIKU__)
++	//HACK: the ru_majfly variable does not exist in POSIX
++	return 0;
++#else
+     return usage.ru_majflt;
++#endif
+ }
+
+ void*
+diff -ur mozjs-38.0.0-old/js/src/jsnativestack.cpp mozjs-38.0.0-new/js/src/jsnativestack.cpp
+--- mozjs-38.0.0-old/js/src/jsnativestack.cpp	2015-09-17 20:12:22.031195136 +0000
++++ mozjs-38.0.0-new/js/src/jsnativestack.cpp	2017-12-16 09:53:06.916455424 +0000
+@@ -9,9 +9,11 @@
+ #ifdef XP_WIN
+ # include "jswin.h"
+
+-#elif defined(XP_MACOSX) || defined(DARWIN) || defined(XP_UNIX)
++#elif defined(XP_MACOSX) || defined(DARWIN) || defined(XP_UNIX) || defined(__HAIKU__)
+ # include <pthread.h>
+-
++# if defined(__HAIKU__)
++   #include <OS.h>
++# endif
+ # if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+ #  include <pthread_np.h>
+ # endif
+@@ -101,6 +103,9 @@
+ #  elif defined(PTHREAD_NP_H) || defined(_PTHREAD_NP_H_) || defined(NETBSD)
+     /* e.g. on FreeBSD 4.8 or newer, neundorf@kde.org */
+     pthread_attr_get_np(thread, &sattr);
++#  elif defined(__HAIKU__)
++    //HACK: Haiku does not implement pthread_getattr_np as it is not POSIX
++    //get_thread_info(thread, &sattr->id);
+ #  else
+     /*
+      * FIXME: this function is non-portable;
+@@ -143,6 +148,8 @@
+         // For non main-threads pthread allocates the stack itself so it tells
+         // the truth.
+         rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);
++# elif defined(__HAIKU__)
++    rc = 0;
+ # else
+     rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);
+ # endif
+diff -ur mozjs-38.0.0-old/js/src/shell/js.cpp mozjs-38.0.0-new/js/src/shell/js.cpp
+--- mozjs-38.0.0-old/js/src/shell/js.cpp	2015-09-17 20:12:22.004194304 +0000
++++ mozjs-38.0.0-new/js/src/shell/js.cpp	2017-12-16 09:53:06.917766144 +0000
+@@ -32,7 +32,7 @@
+ #include <string.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+-#ifdef XP_UNIX
++#if defined(XP_UNIX) || defined(__HAIKU__)
+ # include <sys/mman.h>
+ # include <sys/stat.h>
+ # include <sys/wait.h>
+@@ -5892,7 +5892,7 @@
+     if (!ptr)
+         return 0;
+
+-#if defined(HAVE_MALLOC_USABLE_SIZE)
++#if defined(HAVE_MALLOC_USABLE_SIZE) && !defined(__HAIKU__)
+     return malloc_usable_size(ptr);
+ #elif defined(HAVE_MALLOC_SIZE)
+     return malloc_size(ptr);
+Only in mozjs-38.0.0-new/layout/tools/reftest/reftest: __init__.pyc
+diff -ur mozjs-38.0.0-old/mfbt/Poison.cpp mozjs-38.0.0-new/mfbt/Poison.cpp
+--- mozjs-38.0.0-old/mfbt/Poison.cpp	2015-09-17 20:12:16.000524288 +0000
++++ mozjs-38.0.0-new/mfbt/Poison.cpp	2017-12-16 09:53:06.918552576 +0000
+@@ -129,7 +129,11 @@
+ static bool
+ ProbeRegion(uintptr_t aRegion, uintptr_t aSize)
+ {
++#ifdef __HAIKU__
++  if (posix_madvise(reinterpret_cast<void*>(aRegion), aSize, POSIX_MADV_NORMAL)) {
++#else
+   if (madvise(reinterpret_cast<void*>(aRegion), aSize, MADV_NORMAL)) {
++#endif
+     return true;
+   } else {
+     return false;
+diff -ur mozjs-38.0.0-old/python/psutil/setup.py mozjs-38.0.0-new/python/psutil/setup.py
+--- mozjs-38.0.0-old/python/psutil/setup.py	2015-09-17 20:12:23.004456448 +0000
++++ mozjs-38.0.0-new/python/psutil/setup.py	2017-12-16 09:53:06.919076864 +0000
+@@ -125,6 +125,18 @@
+         libraries=['kstat', 'nsl'],),
+         posix_extension,
+     ]
++# Haiku
++elif sys.platform.startswith("haiku"):
++    extensions = []
++    """extensions = [Extension(
++        '_psutil_haiku',
++        sources=[
++            #'psutil/_psutil_bsd.c',
++            'psutil/_psutil_common.c',
++            #'psutil/arch/bsd/process_info.c'
++        ]),
++        posix_extension,
++    ]"""
+ else:
+     sys.exit('platform %s is not supported' % sys.platform)
diff --git a/libraries/source/spidermonkey/build.sh b/libraries/source/spidermonkey/build.sh
index 18202e7..c1473f2 100755
--- a/libraries/source/spidermonkey/build.sh
+++ b/libraries/source/spidermonkey/build.sh
@@ -103,6 +103,54 @@ rm -rf build-release
 perl -i.bak -pe 's/(SHARED_LIBRARY_NAME\s+=).*/$1 '\''mozjs38-ps-debug'\''/' moz.build
 mkdir -p build-debug
 cd build-debug
+
+fixHaikuBuild()
+{
+	baseDir=$(pwd)
+
+	# HACK: HaikuPorter does not work with pip and virtual env at the moment.
+	mkdir -p _virtualenv
+	mkdir -p _virtualenv/non-packaged
+	mkdir -p _virtualenv/non-packaged/lib/
+	mkdir -p _virtualenv/non-packaged/lib/python2.7/
+	mkdir -p _virtualenv/non-packaged/lib/python2.7/site-packages/
+	cd _virtualenv/non-packaged/lib/python2.7/site-packages/
+
+	echo testing/marionette/transport > marionette_transport.pth
+	echo testing/marionette/driver > marionette_driver.pth
+	echo testing/marionette/client > marionette.pth
+	echo python/blessings > blessings.pth
+	echo python/configobj > configobj.pth
+	echo python/jsmin > jsmin.pth
+	echo python/mach > mach.pth
+	echo python/mozbuild > mozbuild.pth
+	echo build/pymake > pymake.pth
+	#optional:setup.py:python/psutil:build_ext:--inplace
+	#optional:psutil.pth:python/psutil
+	echo python/which > which.pth
+	echo other-licenses/ply/ > ply.pth
+	echo python/mock-1.0.0 > mock.pth
+	echo build > mozilla.pth
+	echo config > mozilla.pth
+	echo xpcom/typelib/xpt/tools >> mozilla.pth
+	echo dom/bindings >> mozilla.pth
+	echo dom/bindings/parser >> mozilla.pth
+	echo layout/tools/reftest >> mozilla.pth
+	echo tools/docs > moztreedocs.pth
+	#copy:build/buildconfig.py
+	#packages.txt:testing/mozbase/packages.txt
+	#objdir:build
+	echo media/webrtc/trunk/tools/gyp/pylib > gyp.pth
+	echo python/pyasn1 > pyasn1.pth
+	echo python/bitstring > bitstring.pth
+	echo python/redo > redo.pth
+	echo python/requests > requests.pth
+
+	cd $baseDir
+}
+
+fixHaikuBuild
+
 CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --with-nspr-libs="$NSPR_LIBS" --with-nspr-cflags="$NSPR_INCLUDES" --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal
 ${MAKE} ${MAKE_OPTS}
 cd ..
@@ -110,6 +158,9 @@ cd ..
 perl -i.bak -pe 's/(SHARED_LIBRARY_NAME\s+=).*/$1 '\''mozjs38-ps-release'\''/' moz.build
 mkdir -p build-release
 cd build-release
+
+fixHaikuBuild
+
 CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --with-nspr-libs="$NSPR_LIBS" --with-nspr-cflags="$NSPR_INCLUDES" --enable-optimize  # --enable-gczeal --enable-debug-symbols
 ${MAKE} ${MAKE_OPTS}
 cd ..
diff --git a/libraries/source/spidermonkey/patch.sh b/libraries/source/spidermonkey/patch.sh
index b10d82f..28faab9 100644
--- a/libraries/source/spidermonkey/patch.sh
+++ b/libraries/source/spidermonkey/patch.sh
@@ -53,3 +53,6 @@ patch -p1  < ../FixTracelogger.diff
 # Based on: https://svnweb.freebsd.org/ports/head/sysutils/py-psutil121/files/patch-_psutil_bsd.c?revision=436575&view=markup
 # Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1238983
 patch -p0 < ../FixpsutilFreeBSD.diff
+
+# Fixes the build on Haiku by adding it as a recognised platform
+patch -p1 < ../FixHaikuBuild.diff
diff --git a/source/lib/allocators/page_aligned.cpp b/source/lib/allocators/page_aligned.cpp
index 4dea320..6bc326b 100644
--- a/source/lib/allocators/page_aligned.cpp
+++ b/source/lib/allocators/page_aligned.cpp
@@ -49,7 +49,11 @@ static const int mmap_flags = MAP_PRIVATE|MAP_ANONYMOUS;
 Status mem_Reserve(size_t size, u8** pp)
 {
 	errno = 0;
+#if !__HAIKU__
 	void* ret = mmap(0, size, PROT_NONE, mmap_flags|MAP_NORESERVE, -1, 0);
+#else
+	void* ret = mmap(0, size, PROT_NONE, mmap_flags, -1, 0);
+#endif
 	*pp = (u8*)ret;
 	return StatusFromMap(ret);
 }
@@ -76,7 +80,11 @@ Status mem_Commit(u8* p, size_t size, int prot)
 Status mem_Decommit(u8* p, size_t size)
 {
 	errno = 0;
+#if !__HAIKU__
 	void* ret = mmap(p, size, PROT_NONE, mmap_flags|MAP_NORESERVE|MAP_FIXED, -1, 0);
+#else
+	void* ret = mmap(p, size, PROT_NONE, mmap_flags|MAP_FIXED, -1, 0);
+#endif
 	return StatusFromMap(ret);
 }
 
diff --git a/source/lib/config2.h b/source/lib/config2.h
index 19ea91e..bc8b89c 100644
--- a/source/lib/config2.h
+++ b/source/lib/config2.h
@@ -60,7 +60,7 @@
 // work around a bug introduced in Linux 2.6.38
 // (http://www.wildfiregames.com/forum/index.php?showtopic=14561&view=findpost&p=217710)
 // OpenBSD doesn't provide aio.h so we disable its use
-# if OS_LINUX || OS_OPENBSD
+# if OS_LINUX || OS_OPENBSD || OS_HAIKU
 #  define CONFIG2_FILE_ENABLE_AIO 0
 # else
 #  define CONFIG2_FILE_ENABLE_AIO 1
diff --git a/source/lib/posix/posix_aio.h b/source/lib/posix/posix_aio.h
index 1246840..16ac282 100644
--- a/source/lib/posix/posix_aio.h
+++ b/source/lib/posix/posix_aio.h
@@ -30,7 +30,7 @@
 
 #if OS_WIN
 # include "lib/sysdep/os/win/wposix/waio.h"
-#elif OS_ANDROID || OS_OPENBSD
+#elif OS_ANDROID || OS_OPENBSD || OS_HAIKU
 // Android doesn't provide aio.h. We don't actually use aio on Linuxes (see
 // CONFIG2_FILE_ENABLE_AIO) but we use its symbols and structs, so define
 // them here
diff --git a/source/lib/secure_crt.h b/source/lib/secure_crt.h
index 1eaa8f7..300a88f 100644
--- a/source/lib/secure_crt.h
+++ b/source/lib/secure_crt.h
@@ -47,13 +47,13 @@ namespace ERR
 #if EMULATE_SECURE_CRT
 
 // (conflicts with glibc definitions)
-#if !OS_UNIX || OS_MACOSX || OS_OPENBSD
+#if !OS_UNIX || OS_MACOSX || OS_OPENBSD || OS_HAIKU
 // return length [in characters] of a string, not including the trailing
 // null character. to protect against access violations, only the
 // first <max_len> characters are examined; if the null character is
 // not encountered by then, <max_len> is returned.
 // strnlen is available on OpenBSD
-#if !OS_OPENBSD
+#if !OS_OPENBSD && !OS_HAIKU
 extern size_t strnlen(const char* str, size_t max_len);
 #endif
 extern size_t wcsnlen(const wchar_t* str, size_t max_len);
diff --git a/source/lib/sysdep/os.h b/source/lib/sysdep/os.h
index a958b83..cb8b1e3 100644
--- a/source/lib/sysdep/os.h
+++ b/source/lib/sysdep/os.h
@@ -84,11 +84,11 @@
 #else
 # define OS_SOLARIS 0
 #endif
-// BeOS
-#if defined(__BEOS__)
-# define OS_BEOS 1
+// Haiku
+#if defined(__HAIKU__)
+# define OS_HAIKU 1
 #else
-# define OS_BEOS 0
+# define OS_HAIKU 0
 #endif
 // Mac OS 9 or below
 #if defined(macintosh)
@@ -112,7 +112,7 @@
 // convenience: additionally set OS_UNIX for Unix-based OSes
 // note: doing this in an separate section instead of adding the extra define
 // to all affected OSes saves a few undefs or macro redefinition warnings.
-#if OS_LINUX || OS_MACOSX || OS_BSD || OS_SOLARIS
+#if OS_LINUX || OS_MACOSX || OS_BSD || OS_SOLARIS || OS_HAIKU
 # undef OS_UNIX
 # define OS_UNIX 1
 #endif
diff --git a/source/lib/sysdep/os/haiku/dir_watch.cpp b/source/lib/sysdep/os/haiku/dir_watch.cpp
new file mode 100644
index 0000000..749946e
--- /dev/null
+++ b/source/lib/sysdep/os/haiku/dir_watch.cpp
@@ -0,0 +1,36 @@
+/* Copyright (C) 2012 Wildfire Games.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "precompiled.h"
+#include "lib/sysdep/dir_watch.h"
+
+// stub implementations
+
+Status dir_watch_Add(const OsPath& UNUSED(path), PDirWatch& UNUSED(dirWatch))
+{
+	return INFO::OK;
+}
+
+Status dir_watch_Poll(DirWatchNotifications& UNUSED(notifications))
+{
+	return INFO::OK;
+}
diff --git a/source/lib/sysdep/os/haiku/haiku.cpp b/source/lib/sysdep/os/haiku/haiku.cpp
new file mode 100644
index 0000000..a584af8
--- /dev/null
+++ b/source/lib/sysdep/os/haiku/haiku.cpp
@@ -0,0 +1,147 @@
+/* Copyright (C) 2014 Wildfire Games.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *cd
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "precompiled.h"
+
+#include "lib/sysdep/sysdep.h"
+#include "lib/sysdep/clipboard.h"
+#include "lib/sysdep/os/unix/unix_executable_pathname.h"
+#include "lib/sysdep/gfx.h"
+#include "lib/sysdep/cursor.h"
+
+#include "ps/VideoMode.h"
+
+#include "SDL.h"
+#include "SDL_syswm.h"
+
+#include <cstdlib>
+
+#define debug_printf debug_printf_old
+#include <Clipboard.h>
+#define debug_printf_old debug_printf
+
+OsPath sys_ExecutablePathname()
+{
+	return unix_ExecutablePathname();
+}
+
+wchar_t *sys_clipboard_get()
+{
+	be_clipboard->Lock();
+	BMessage* clipBoard = be_clipboard->Data();
+	wchar_t* data = NULL;
+	if (clipBoard != NULL)
+	{
+		const char* clipData;
+		ssize_t length;
+		clipBoard->FindData("text/plain", B_MIME_TYPE, (const void**)&clipData, &length);
+		std::wstring dataString = wstring_from_utf8(clipData);
+		size_t dataStringSize = dataString.size() + 1;
+		data = new wchar_t[dataStringSize];
+		memcpy(data, dataString.c_str(), dataStringSize * sizeof(wchar_t));
+	}
+	be_clipboard->Unlock();
+
+	return data == NULL ? const_cast<wchar_t*>(L"") : data;
+}
+
+Status sys_clipboard_free(wchar_t *clip_buf)
+{
+	if (clip_buf != NULL)
+	{
+		delete clip_buf;
+	}
+	return INFO::OK;
+}
+
+Status sys_clipboard_set(const wchar_t *str)
+{
+	be_clipboard->Lock();
+	BMessage* clipBoard = be_clipboard->Data();
+	if (clipBoard != NULL)
+	{
+		be_clipboard->Clear();
+		std::string dataString = utf8_from_wstring(str);
+		const char* data = dataString.c_str();
+		clipBoard->AddData("text/plain", B_MIME_TYPE, (const void*)data, dataString.size());
+		be_clipboard->Commit();
+	}
+	be_clipboard->Unlock();
+	return INFO::OK;
+}
+
+Status sys_cursor_create()
+{
+	return INFO::OK;
+}
+
+Status sys_cursor_create_empty()
+{
+	return INFO::OK;
+}
+
+Status sys_cursor_set(sys_cursor cursor)
+{
+	return INFO::OK;
+}
+
+Status sys_cursor_free(sys_cursor cursor)
+{
+	return INFO::OK;
+}
+
+Status sys_cursor_reset()
+{
+	return INFO::OK;
+}
+
+namespace gfx
+{
+	static bool get_wminfo(SDL_SysWMinfo& wminfo)
+	{
+		SDL_VERSION(&wminfo.version);
+
+		const int ret = SDL_GetWindowWMInfo(g_VideoMode.GetWindow(), &wminfo);
+
+		if(ret == 1)
+			return true;
+
+		if(ret == -1)
+		{
+			debug_printf("SDL_GetWMInfo failed\n");
+			return false;
+		}
+		if(ret == 0)
+		{
+			debug_printf("SDL_GetWMInfo is not implemented on this platform\n");
+			return false;
+		}
+
+		debug_printf("SDL_GetWMInfo returned an unknown value: %d\n", ret);
+		return false;
+	}
+
+	Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
+	{
+		return INFO::OK;
+	}
+}
diff --git a/source/lib/sysdep/os/haiku/hcpu.cpp b/source/lib/sysdep/os/haiku/hcpu.cpp
new file mode 100644
index 0000000..2c966d2
--- /dev/null
+++ b/source/lib/sysdep/os/haiku/hcpu.cpp
@@ -0,0 +1,120 @@
+/* Copyright (C) 2012 Wildfire Games.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "precompiled.h"
+
+#include "lib/sysdep/os_cpu.h"
+#include "lib/alignment.h"
+#include "lib/bits.h"
+#include "lib/module_init.h"
+
+#include "valgrind.h"
+#include <unistd.h>
+#define debug_printf debug_printf_old
+#include <OS.h>
+#define debug_printf_old debug_printf
+
+size_t os_cpu_NumProcessors()
+{
+	static size_t numProcessors;
+
+	if(numProcessors == 0)
+	{
+		// Valgrind reports the number of real CPUs, but only emulates a single CPU.
+		// That causes problems when we expect all those CPUs to be distinct, so
+		// just pretend there's only one CPU
+		if (RUNNING_ON_VALGRIND)
+			numProcessors = 1;
+		else
+		{
+			long res = sysconf(_SC_NPROCESSORS_CONF);
+			ENSURE(res != -1);
+			numProcessors = (size_t)res;
+		}
+	}
+
+	return numProcessors;
+}
+
+
+uintptr_t os_cpu_ProcessorMask()
+{
+	static uintptr_t processorMask;
+
+	if(!processorMask)
+		processorMask = bit_mask<uintptr_t>(os_cpu_NumProcessors());
+
+	return processorMask;
+}
+
+
+size_t os_cpu_PageSize()
+{
+	static size_t pageSize;
+
+	if(!pageSize)
+		pageSize = (size_t)sysconf(_SC_PAGESIZE);
+
+	return pageSize;
+}
+
+
+size_t os_cpu_LargePageSize()
+{
+	// assume they're unsupported.
+	return 0;
+}
+
+
+size_t os_cpu_QueryMemorySize()
+{
+	system_info info;
+	get_system_info(&info);
+	size_t memorySize = (size_t) (info.max_pages * (B_PAGE_SIZE / 1048576.0f) + 0.5f);
+	return memorySize;
+}
+
+
+size_t os_cpu_MemoryAvailable()
+{
+	system_info info;
+	get_system_info(&info);
+	return (100 * info.used_pages / info.max_pages);
+}
+
+uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t UNUSED(processorMask))
+{
+	// not yet implemented
+	return os_cpu_ProcessorMask();
+}
+
+Status os_cpu_CallByEachCPU(OsCpuCallback cb, uintptr_t cbData)
+{
+	for(size_t processor = 0; processor < os_cpu_NumProcessors(); processor++)
+	{
+		const uintptr_t processorMask = uintptr_t(1) << processor;
+		os_cpu_SetThreadAffinityMask(processorMask);
+		cb(processor, cbData);
+	}
+
+	return INFO::OK;
+}
diff --git a/source/lib/sysdep/os/haiku/hdbg.cpp b/source/lib/sysdep/os/haiku/hdbg.cpp
new file mode 100644
index 0000000..4030b3e
--- /dev/null
+++ b/source/lib/sysdep/os/haiku/hdbg.cpp
@@ -0,0 +1,46 @@
+/* Copyright (C) 2012 Wildfire Games.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "precompiled.h"
+
+#include "lib/sysdep/sysdep.h"
+#include "lib/debug.h"
+
+void* debug_GetCaller(void* UNUSED(context), const wchar_t* UNUSED(lastFuncToSkip))
+{
+	return NULL;
+}
+
+Status debug_DumpStack(wchar_t* buf, size_t max_chars, void* UNUSED(context), const wchar_t* UNUSED(lastFuncToSkip))
+{
+	return INFO::OK;
+}
+
+Status debug_ResolveSymbol(void* ptr_of_interest, wchar_t* sym_name, wchar_t* file, int* line)
+{
+	return INFO::OK;
+}
+
+void debug_SetThreadName(char const* UNUSED(name))
+{
+    // Currently unimplemented
+}
diff --git a/source/lib/sysdep/os/unix/unix_executable_pathname.cpp b/source/lib/sysdep/os/unix/unix_executable_pathname.cpp
index fc4acb1..a62b396 100644
--- a/source/lib/sysdep/os/unix/unix_executable_pathname.cpp
+++ b/source/lib/sysdep/os/unix/unix_executable_pathname.cpp
@@ -35,7 +35,7 @@ OsPath unix_ExecutablePathname()
 	// Find the executable's filename
 	Dl_info dl_info;
 	memset(&dl_info, 0, sizeof(dl_info));
-	if (!T::dladdr((void *)sys_ExecutablePathname, &dl_info) || !dl_info.dli_fname)
+	if (!dladdr((void *)sys_ExecutablePathname, &dl_info) || !dl_info.dli_fname)
 		return OsPath();
 	const char* path = dl_info.dli_fname;
 
@@ -53,7 +53,7 @@ OsPath unix_ExecutablePathname()
 	if (strchr(path, '/'))
 	{
 		char cwd[PATH_MAX];
-		if (!T::getcwd(cwd, PATH_MAX))
+		if (!getcwd(cwd, PATH_MAX))
 			return OsPath();
 
 		char absolute[PATH_MAX];
diff --git a/source/lib/sysdep/os/unix/uvm.cpp b/source/lib/sysdep/os/unix/uvm.cpp
index 8a3f81e..e777c83 100644
--- a/source/lib/sysdep/os/unix/uvm.cpp
+++ b/source/lib/sysdep/os/unix/uvm.cpp
@@ -32,6 +32,9 @@
 #ifndef MAP_ANONYMOUS
 # define MAP_ANONYMOUS MAP_ANON
 #endif
+#ifndef MAP_NORESERVE
+# define MAP_NORESERVE 0
+#endif
 
 static const int mmap_flags = MAP_PRIVATE|MAP_ANONYMOUS;
 
diff --git a/source/main.cpp b/source/main.cpp
index bd00fd3..3edf8e5 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -659,7 +659,7 @@ extern "C" __attribute__((visibility ("default"))) int main(int argc, char* argv
 
 extern "C" int main(int argc, char* argv[])
 {
-#if OS_UNIX
+#if OS_UNIX && !OS_HAIKU
 	// Don't allow people to run the game with root permissions,
 	//	because bad things can happen, check before we do anything
 	if (geteuid() == 0)
diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp
index 255cac6..7e5557c 100644
--- a/source/ps/GameSetup/GameSetup.cpp
+++ b/source/ps/GameSetup/GameSetup.cpp
@@ -88,7 +88,7 @@
 #include "tools/atlas/GameInterface/GameLoop.h"
 #include "tools/atlas/GameInterface/View.h"
 
-#if !(OS_WIN || OS_MACOSX || OS_ANDROID) // assume all other platforms use X11 for wxWidgets
+#if !(OS_WIN || OS_MACOSX || OS_ANDROID || __HAIKU__) // assume all other platforms use X11 for wxWidgets
 #define MUST_INIT_X11 1
 #include <X11/Xlib.h>
 #else
@@ -788,7 +788,8 @@ from_config:
 #if OS_UNIX
 static void FixLocales()
 {
-#if OS_MACOSX || OS_BSD
+#if OS_MACOSX || OS_BSD || defined(__HAIKU__)
+	// NOTE: The Haiku clipboard code relies on UTF-8 to convert strings.
 	// OS X requires a UTF-8 locale in LC_CTYPE so that *wprintf can handle
 	// wide characters. Peculiarly the string "UTF-8" seems to be acceptable
 	// despite not being a real locale, and it's conveniently language-agnostic,
diff --git a/source/ps/GameSetup/Paths.cpp b/source/ps/GameSetup/Paths.cpp
index 474364e..bd51315 100644
--- a/source/ps/GameSetup/Paths.cpp
+++ b/source/ps/GameSetup/Paths.cpp
@@ -141,12 +141,20 @@ Paths::Paths(const CmdLineArgs& args)
 		const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/"     ) / subdirectoryName;
 		const OsPath xdgCache  = XDG_Path("XDG_CACHE_HOME",  home, home/".cache/"      ) / subdirectoryName;
 
+#if !defined(__HAIKU__)
 		// We don't make the game vs. user data distinction on Unix
 		m_gameData = xdgData/"";
 		m_userData = m_gameData;
 		m_cache  = xdgCache/"";
 		m_config = xdgConfig / "config"/"";
 		m_logs   = xdgConfig / "logs"/"";
+#else
+		m_gameData = OsPath("/boot/system/settings/0ad/");
+		m_userData = home / "config" / "settings" / "0ad" / "";
+		m_cache = m_userData / "cache" / "";
+		m_config = m_userData / "config"/"";
+		m_logs = m_userData / "logs" / "";
+#endif
 
 #endif
 	}
diff --git a/source/third_party/tinygettext/src/iconv.cpp b/source/third_party/tinygettext/src/iconv.cpp
index 7712bdd..0fd73da 100644
--- a/source/third_party/tinygettext/src/iconv.cpp
+++ b/source/third_party/tinygettext/src/iconv.cpp
@@ -117,7 +117,7 @@ IConv::convert(const std::string& text)
     char* outbuf = &result[0];
 
     // Try to convert the text.
-    size_t ret = tinygettext_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+    size_t ret = tinygettext_iconv(cd, const_cast<char**>(&inbuf), &inbytesleft, &outbuf, &outbytesleft);
     if (ret == static_cast<size_t>(-1))
     {
       if (errno == EILSEQ || errno == EINVAL)
-- 
2.17.1

