From 3cd4c88bb5cc2eabf23568a1b8ff556c8ff8bd2a Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 10 Jun 2020 22:35:16 +1000
Subject: Haiku patches


diff --git a/3rdparty/asio/include/asio/detail/config.hpp b/3rdparty/asio/include/asio/detail/config.hpp
index 0c651be..aebab8c 100644
--- a/3rdparty/asio/include/asio/detail/config.hpp
+++ b/3rdparty/asio/include/asio/detail/config.hpp
@@ -1080,6 +1080,8 @@
 #   define ASIO_HAS_THREADS 1
 #  elif defined(__APPLE__)
 #   define ASIO_HAS_THREADS 1
+#  elif defined(__HAIKU__)
+#   define ASIO_HAS_THREADS 1
 #  elif defined(_POSIX_THREADS) && (_POSIX_THREADS + 0 >= 0)
 #   define ASIO_HAS_THREADS 1
 #  elif defined(_PTHREADS)
@@ -1095,6 +1097,8 @@
 #   define ASIO_HAS_PTHREADS 1
 #  elif defined(_POSIX_THREADS) && (_POSIX_THREADS + 0 >= 0)
 #   define ASIO_HAS_PTHREADS 1
+#  elif defined(__HAIKU__)
+#   define ASIO_HAS_PTHREADS 1
 #  endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS)
 # endif // defined(ASIO_HAS_THREADS)
 #endif // !defined(ASIO_HAS_PTHREADS)
diff --git a/3rdparty/bgfx/3rdparty/dear-imgui/widgets/file_list.inl b/3rdparty/bgfx/3rdparty/dear-imgui/widgets/file_list.inl
index 75f1fc5..c44be05 100644
--- a/3rdparty/bgfx/3rdparty/dear-imgui/widgets/file_list.inl
+++ b/3rdparty/bgfx/3rdparty/dear-imgui/widgets/file_list.inl
@@ -32,6 +32,7 @@ namespace ImGui
 				}
 				else if (0 != ImStricmp(item->d_name, ".") )
 				{
+#ifndef __HAIKU__
 					if (item->d_type & DT_DIR)
 					{
 						FileList.push_back(ImFileInfo(item->d_name, -1) );
@@ -42,6 +43,7 @@ namespace ImGui
 						stat(item->d_name, &statbuf);
 						FileList.push_back(ImFileInfo(item->d_name, statbuf.st_size) );
 					}
+#endif
 				}
 			}
 
diff --git a/3rdparty/bx/include/bx/platform.h b/3rdparty/bx/include/bx/platform.h
index d4445d3..80124be 100644
--- a/3rdparty/bx/include/bx/platform.h
+++ b/3rdparty/bx/include/bx/platform.h
@@ -61,6 +61,7 @@
 #define BX_PLATFORM_WINDOWS    0
 #define BX_PLATFORM_WINRT      0
 #define BX_PLATFORM_XBOXONE    0
+#define BX_PLATFORM_HAIKU      0
 
 // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
 #if defined(__clang__)
@@ -275,6 +276,7 @@
 	||  BX_PLATFORM_PS4        \
 	||  BX_PLATFORM_RPI        \
 	||  BX_PLATFORM_STEAMLINK  \
+	||  BX_PLATFORM_HAIKU      \
 	)
 
 ///
@@ -294,6 +296,7 @@
 	||  BX_PLATFORM_WINDOWS    \
 	||  BX_PLATFORM_WINRT      \
 	||  BX_PLATFORM_XBOXONE    \
+	||  BX_PLATFORM_HAIKU      \
 	)
 
 ///
@@ -398,6 +401,8 @@
 #	define BX_PLATFORM_NAME "WinRT"
 #elif BX_PLATFORM_XBOXONE
 #	define BX_PLATFORM_NAME "Xbox One"
+#elif BX_PLATFORM_HAIKU
+#	define BX_PLATFORM_NAME "Haiku"
 #else
 #	error "Unknown BX_PLATFORM!"
 #endif // BX_PLATFORM_
diff --git a/3rdparty/bx/src/file.cpp b/3rdparty/bx/src/file.cpp
index aea285e..c158af0 100644
--- a/3rdparty/bx/src/file.cpp
+++ b/3rdparty/bx/src/file.cpp
@@ -76,7 +76,8 @@ namespace bx
 	  || BX_PLATFORM_BSD     \
 	  || BX_PLATFORM_HAIKU   \
 	  || BX_PLATFORM_IOS     \
-	  || BX_PLATFORM_OSX
+	  || BX_PLATFORM_OSX     \
+	  || BX_PLATFORM_HAIKU
 #		define fseeko64 fseeko
 #		define ftello64 ftello
 #	elif BX_PLATFORM_PS4
diff --git a/3rdparty/bx/src/mutex.cpp b/3rdparty/bx/src/mutex.cpp
index 2fe5eaf..c9ce444 100644
--- a/3rdparty/bx/src/mutex.cpp
+++ b/3rdparty/bx/src/mutex.cpp
@@ -18,6 +18,7 @@
 	|| BX_PLATFORM_IOS     \
 	|| BX_PLATFORM_OSX     \
 	|| BX_PLATFORM_PS4     \
+	|| BX_PLATFORM_HAIKU   \
 	|| BX_PLATFORM_RPI
 #	include <pthread.h>
 #elif  BX_PLATFORM_WINDOWS \
diff --git a/3rdparty/bx/src/thread.cpp b/3rdparty/bx/src/thread.cpp
index 9525105..cebcb82 100644
--- a/3rdparty/bx/src/thread.cpp
+++ b/3rdparty/bx/src/thread.cpp
@@ -21,6 +21,7 @@
 	|| BX_PLATFORM_IOS     \
 	|| BX_PLATFORM_OSX     \
 	|| BX_PLATFORM_PS4     \
+	|| BX_PLATFORM_HAIKU  \
 	|| BX_PLATFORM_RPI
 #	include <pthread.h>
 #	if defined(__FreeBSD__)
diff --git a/3rdparty/genie/build/gmake.haiku/Makefile b/3rdparty/genie/build/gmake.haiku/Makefile
new file mode 100644
index 0000000..be9880c
--- /dev/null
+++ b/3rdparty/genie/build/gmake.haiku/Makefile
@@ -0,0 +1,34 @@
+# GNU Make solution makefile autogenerated by GENie
+# Type "make help" for usage help
+
+ifndef config
+  config=release
+endif
+export config
+
+PROJECTS := genie
+
+.PHONY: all clean help $(PROJECTS)
+
+all: $(PROJECTS)
+
+genie: 
+	@echo "==== Building genie ($(config)) ===="
+	@${MAKE} --no-print-directory -C . -f genie.make
+
+clean:
+	@${MAKE} --no-print-directory -C . -f genie.make clean
+
+help:
+	@echo "Usage: make [config=name] [target]"
+	@echo ""
+	@echo "CONFIGURATIONS:"
+	@echo "   release"
+	@echo "   debug"
+	@echo ""
+	@echo "TARGETS:"
+	@echo "   all (default)"
+	@echo "   clean"
+	@echo "   genie"
+	@echo ""
+	@echo "For more information, see https://github.com/bkaradzic/genie"
diff --git a/3rdparty/genie/build/gmake.haiku/genie.make b/3rdparty/genie/build/gmake.haiku/genie.make
new file mode 100644
index 0000000..73f650c
--- /dev/null
+++ b/3rdparty/genie/build/gmake.haiku/genie.make
@@ -0,0 +1,488 @@
+# GNU Make project makefile autogenerated by GENie
+ifndef config
+  config=release
+endif
+
+ifndef verbose
+  SILENT = @
+endif
+
+SHELLTYPE := msdos
+ifeq (,$(ComSpec)$(COMSPEC))
+  SHELLTYPE := posix
+endif
+ifeq (/bin,$(findstring /bin,$(SHELL)))
+  SHELLTYPE := posix
+endif
+ifeq (/bin,$(findstring /bin,$(MAKESHELL)))
+  SHELLTYPE := posix
+endif
+
+ifeq (posix,$(SHELLTYPE))
+  MKDIR = $(SILENT) mkdir -p "$(1)"
+  COPY  = $(SILENT) cp -fR "$(1)" "$(2)"
+  RM    = $(SILENT) rm -f "$(1)"
+else
+  MKDIR = $(SILENT) mkdir "$(subst /,\\,$(1))" 2> nul || exit 0
+  COPY  = $(SILENT) copy /Y "$(subst /,\\,$(1))" "$(subst /,\\,$(2))"
+  RM    = $(SILENT) del /F "$(subst /,\\,$(1))" 2> nul || exit 0
+endif
+
+CC  = gcc
+CXX = g++
+AR  = ar
+
+ifndef RESCOMP
+  ifdef WINDRES
+    RESCOMP = $(WINDRES)
+  else
+    RESCOMP = windres
+  endif
+endif
+
+MAKEFILE = genie.make
+
+ifeq ($(config),release)
+  OBJDIR              = obj/Release
+  TARGETDIR           = ../../bin/haiku
+  override TARGET              = $(TARGETDIR)/genie
+  DEFINES            += -DNDEBUG -DLUA_COMPAT_MODULE -DLUA_USE_POSIX -DLUA_USE_DLOPEN
+  INCLUDES           += -I"../../src/host/lua-5.3.0/src"
+  INCLUDES           +=
+  ALL_CPPFLAGS       += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES)
+  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os
+  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os
+  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os
+  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os
+  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os
+  ALL_RESFLAGS       += $(RESFLAGS) $(DEFINES) $(INCLUDES)
+  ALL_LDFLAGS        += $(LDFLAGS) -L. -s
+  LDDEPS             +=
+  LIBS               += $(LDDEPS) -lm -lbsd
+  EXTERNAL_LIBS      +=
+  LINKCMD             = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
+  OBJECTS := \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lapi.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lauxlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lbaselib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lbitlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lcode.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lcorolib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lctype.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldblib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldebug.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldo.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldump.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lfunc.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lgc.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/linit.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/liolib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/llex.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lmathlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lmem.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/loadlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lobject.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lopcodes.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/loslib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lparser.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lstate.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lstring.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lstrlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ltable.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ltablib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ltm.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lundump.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lutf8lib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lvm.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lzio.o \
+	$(OBJDIR)/src/host/os_chdir.o \
+	$(OBJDIR)/src/host/os_copyfile.o \
+	$(OBJDIR)/src/host/os_getcwd.o \
+	$(OBJDIR)/src/host/os_is64bit.o \
+	$(OBJDIR)/src/host/os_isdir.o \
+	$(OBJDIR)/src/host/os_isfile.o \
+	$(OBJDIR)/src/host/os_match.o \
+	$(OBJDIR)/src/host/os_mkdir.o \
+	$(OBJDIR)/src/host/os_pathsearch.o \
+	$(OBJDIR)/src/host/os_rmdir.o \
+	$(OBJDIR)/src/host/os_stat.o \
+	$(OBJDIR)/src/host/os_ticks.o \
+	$(OBJDIR)/src/host/os_uuid.o \
+	$(OBJDIR)/src/host/path_getabsolute.o \
+	$(OBJDIR)/src/host/path_getrelative.o \
+	$(OBJDIR)/src/host/path_helpers.o \
+	$(OBJDIR)/src/host/path_isabsolute.o \
+	$(OBJDIR)/src/host/premake.o \
+	$(OBJDIR)/src/host/premake_main.o \
+	$(OBJDIR)/src/host/scripts.o \
+	$(OBJDIR)/src/host/string_endswith.o \
+	$(OBJDIR)/src/host/string_hash.o \
+
+  define PREBUILDCMDS
+  endef
+  define PRELINKCMDS
+  endef
+  define POSTBUILDCMDS
+  endef
+endif
+
+ifeq ($(config),debug)
+  OBJDIR              = obj/Debug
+  TARGETDIR           = ../../bin/linux
+  override TARGET              = $(TARGETDIR)/genie
+  DEFINES            += -D_DEBUG -DLUA_COMPAT_MODULE -DLUA_USE_POSIX -DLUA_USE_DLOPEN
+  INCLUDES           += -I"../../src/host/lua-5.3.0/src"
+  INCLUDES           +=
+  ALL_CPPFLAGS       += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES)
+  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+  ALL_RESFLAGS       += $(RESFLAGS) $(DEFINES) $(INCLUDES)
+  ALL_LDFLAGS        += $(LDFLAGS) -L.
+  LDDEPS             +=
+  LIBS               += $(LDDEPS) -lm -lbsd
+  EXTERNAL_LIBS      +=
+  LINKCMD             = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
+  OBJECTS := \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lapi.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lauxlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lbaselib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lbitlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lcode.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lcorolib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lctype.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldblib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldebug.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldo.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ldump.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lfunc.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lgc.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/linit.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/liolib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/llex.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lmathlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lmem.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/loadlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lobject.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lopcodes.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/loslib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lparser.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lstate.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lstring.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lstrlib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ltable.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ltablib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/ltm.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lundump.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lutf8lib.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lvm.o \
+	$(OBJDIR)/src/host/lua-5.3.0/src/lzio.o \
+	$(OBJDIR)/src/host/os_chdir.o \
+	$(OBJDIR)/src/host/os_copyfile.o \
+	$(OBJDIR)/src/host/os_getcwd.o \
+	$(OBJDIR)/src/host/os_is64bit.o \
+	$(OBJDIR)/src/host/os_isdir.o \
+	$(OBJDIR)/src/host/os_isfile.o \
+	$(OBJDIR)/src/host/os_match.o \
+	$(OBJDIR)/src/host/os_mkdir.o \
+	$(OBJDIR)/src/host/os_pathsearch.o \
+	$(OBJDIR)/src/host/os_rmdir.o \
+	$(OBJDIR)/src/host/os_stat.o \
+	$(OBJDIR)/src/host/os_ticks.o \
+	$(OBJDIR)/src/host/os_uuid.o \
+	$(OBJDIR)/src/host/path_getabsolute.o \
+	$(OBJDIR)/src/host/path_getrelative.o \
+	$(OBJDIR)/src/host/path_helpers.o \
+	$(OBJDIR)/src/host/path_isabsolute.o \
+	$(OBJDIR)/src/host/premake.o \
+	$(OBJDIR)/src/host/premake_main.o \
+	$(OBJDIR)/src/host/scripts.o \
+	$(OBJDIR)/src/host/string_endswith.o \
+	$(OBJDIR)/src/host/string_hash.o \
+
+  define PREBUILDCMDS
+  endef
+  define PRELINKCMDS
+  endef
+  define POSTBUILDCMDS
+  endef
+endif
+
+OBJDIRS := \
+	$(OBJDIR) \
+	$(OBJDIR)/src/host \
+	$(OBJDIR)/src/host/lua-5.3.0/src \
+
+RESOURCES := \
+
+.PHONY: clean prebuild prelink
+
+all: $(OBJDIRS) $(TARGETDIR) prebuild prelink $(TARGET)
+	@:
+
+$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(EXTERNAL_LIBS) $(RESOURCES) | $(TARGETDIR) $(OBJDIRS)
+	@echo Linking genie
+	$(SILENT) $(LINKCMD)
+	$(POSTBUILDCMDS)
+
+$(TARGETDIR):
+	@echo Creating $(TARGETDIR)
+	-$(call MKDIR,$(TARGETDIR))
+
+$(OBJDIRS):
+	@echo Creating $(@)
+	-$(call MKDIR,$@)
+
+clean:
+	@echo Cleaning genie
+ifeq (posix,$(SHELLTYPE))
+	$(SILENT) rm -f  $(TARGET)
+	$(SILENT) rm -rf $(OBJDIR)
+else
+	$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
+	$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
+endif
+
+prebuild:
+	$(PREBUILDCMDS)
+
+prelink:
+	$(PRELINKCMDS)
+
+ifneq (,$(PCH))
+$(GCH): $(PCH) $(MAKEFILE) | $(OBJDIR)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) -x c-header $(DEFINES) $(INCLUDES) -o "$@" -c "$<"
+
+$(GCH_OBJC): $(PCH) $(MAKEFILE) | $(OBJDIR)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_OBJCFLAGS) -x objective-c-header $(DEFINES) $(INCLUDES) -o "$@" -c "$<"
+endif
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lapi.o: ../../src/host/lua-5.3.0/src/lapi.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lauxlib.o: ../../src/host/lua-5.3.0/src/lauxlib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lbaselib.o: ../../src/host/lua-5.3.0/src/lbaselib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lbitlib.o: ../../src/host/lua-5.3.0/src/lbitlib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lcode.o: ../../src/host/lua-5.3.0/src/lcode.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lcorolib.o: ../../src/host/lua-5.3.0/src/lcorolib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lctype.o: ../../src/host/lua-5.3.0/src/lctype.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ldblib.o: ../../src/host/lua-5.3.0/src/ldblib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ldebug.o: ../../src/host/lua-5.3.0/src/ldebug.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ldo.o: ../../src/host/lua-5.3.0/src/ldo.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ldump.o: ../../src/host/lua-5.3.0/src/ldump.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lfunc.o: ../../src/host/lua-5.3.0/src/lfunc.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lgc.o: ../../src/host/lua-5.3.0/src/lgc.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/linit.o: ../../src/host/lua-5.3.0/src/linit.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/liolib.o: ../../src/host/lua-5.3.0/src/liolib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/llex.o: ../../src/host/lua-5.3.0/src/llex.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lmathlib.o: ../../src/host/lua-5.3.0/src/lmathlib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lmem.o: ../../src/host/lua-5.3.0/src/lmem.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/loadlib.o: ../../src/host/lua-5.3.0/src/loadlib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lobject.o: ../../src/host/lua-5.3.0/src/lobject.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lopcodes.o: ../../src/host/lua-5.3.0/src/lopcodes.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/loslib.o: ../../src/host/lua-5.3.0/src/loslib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lparser.o: ../../src/host/lua-5.3.0/src/lparser.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lstate.o: ../../src/host/lua-5.3.0/src/lstate.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lstring.o: ../../src/host/lua-5.3.0/src/lstring.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lstrlib.o: ../../src/host/lua-5.3.0/src/lstrlib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ltable.o: ../../src/host/lua-5.3.0/src/ltable.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ltablib.o: ../../src/host/lua-5.3.0/src/ltablib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/ltm.o: ../../src/host/lua-5.3.0/src/ltm.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lundump.o: ../../src/host/lua-5.3.0/src/lundump.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lutf8lib.o: ../../src/host/lua-5.3.0/src/lutf8lib.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lvm.o: ../../src/host/lua-5.3.0/src/lvm.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/lua-5.3.0/src/lzio.o: ../../src/host/lua-5.3.0/src/lzio.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_chdir.o: ../../src/host/os_chdir.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_copyfile.o: ../../src/host/os_copyfile.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_getcwd.o: ../../src/host/os_getcwd.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_is64bit.o: ../../src/host/os_is64bit.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_isdir.o: ../../src/host/os_isdir.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_isfile.o: ../../src/host/os_isfile.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_match.o: ../../src/host/os_match.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_mkdir.o: ../../src/host/os_mkdir.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_pathsearch.o: ../../src/host/os_pathsearch.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_rmdir.o: ../../src/host/os_rmdir.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_stat.o: ../../src/host/os_stat.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_ticks.o: ../../src/host/os_ticks.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/os_uuid.o: ../../src/host/os_uuid.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/path_getabsolute.o: ../../src/host/path_getabsolute.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/path_getrelative.o: ../../src/host/path_getrelative.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/path_helpers.o: ../../src/host/path_helpers.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/path_isabsolute.o: ../../src/host/path_isabsolute.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/premake.o: ../../src/host/premake.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/premake_main.o: ../../src/host/premake_main.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/scripts.o: ../../src/host/scripts.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/string_endswith.o: ../../src/host/string_endswith.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+$(OBJDIR)/src/host/string_hash.o: ../../src/host/string_hash.c $(GCH) $(MAKEFILE)
+	@echo $(notdir $<)
+	$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<"
+
+-include $(OBJECTS:%.o=%.d)
+ifneq (,$(PCH))
+  -include $(OBJDIR)/$(notdir $(PCH)).d
+  -include $(OBJDIR)/$(notdir $(PCH))_objc.d
+endif
diff --git a/3rdparty/genie/makefile b/3rdparty/genie/makefile
index 48f6fb8..b844440 100644
--- a/3rdparty/genie/makefile
+++ b/3rdparty/genie/makefile
@@ -4,7 +4,7 @@
 #
 
 UNAME := $(shell uname)
-ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin SunOS FreeBSD GNU/kFreeBSD NetBSD OpenBSD GNU))
+ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin SunOS FreeBSD GNU/kFreeBSD NetBSD OpenBSD GNU Haiku))
 ifeq ($(UNAME),$(filter $(UNAME),Darwin))
 OS=darwin
 else
@@ -14,10 +14,14 @@ else
 ifeq ($(UNAME),$(filter $(UNAME),FreeBSD GNU/kFreeBSD NetBSD OpenBSD))
 OS=bsd
 else
+ifeq ($(UNAME),$(filter $(UNAME),Haiku))
+OS=haiku
+else
 OS=linux
 endif
 endif
 endif
+endif
 else
 OS=windows
 endif
@@ -43,6 +47,7 @@ projgen:
 	$(SILENT) $(GENIE) --to=../build/$(PROJECT_TYPE).linux   --os=linux $(PROJECT_TYPE)
 	$(SILENT) $(GENIE) --to=../build/$(PROJECT_TYPE).darwin  --os=macosx --platform=universal32 $(PROJECT_TYPE)
 	$(SILENT) $(GENIE) --to=../build/$(PROJECT_TYPE).freebsd --os=bsd $(PROJECT_TYPE)
+	$(SILENT) $(GENIE) --to=../build/$(PROJECT_TYPE).haiku   --os=haiku $(PROJECT_TYPE)
 
 rebuild:
 	$(SILENT) $(MAKE) -C build/$(PROJECT_TYPE).$(OS) clean all
@@ -56,6 +61,7 @@ release-linux: $(GENIE)
 	$(SILENT) $(GENIE) release
 	$(SILENT) $(MAKE) -C build/$(PROJECT_TYPE).darwin  clean all CC=x86_64-apple-darwin15-clang
 	$(SILENT) $(MAKE) -C build/$(PROJECT_TYPE).linux   clean all
+	$(SILENT) $(MAKE) -C build/$(PROJECT_TYPE).haiku   clean all
 	$(SILENT) $(MAKE) -C build/$(PROJECT_TYPE).windows clean all CC=x86_64-w64-mingw32-gcc
 	$(SILENT) git checkout src/host/version.h
 
@@ -65,3 +71,4 @@ dist: release
 	cp bin/linux/genie       ../bx/tools/bin/linux/
 	cp bin/windows/genie.exe ../bx/tools/bin/windows/
 	cp bin/darwin/genie      ../bx/tools/bin/darwin/
+	cp bin/haiku/genie       ../bx/tools/bin/haiku/
diff --git a/3rdparty/genie/scripts/genie.lua b/3rdparty/genie/scripts/genie.lua
index 7e64ad9..fefb444 100644
--- a/3rdparty/genie/scripts/genie.lua
+++ b/3rdparty/genie/scripts/genie.lua
@@ -88,6 +88,11 @@
 
 		configuration {}
 
+		configuration "haiku"
+			targetdir   "../bin/haiku"
+			defines     { "LUA_USE_POSIX", "LUA_USE_DLOPEN" }
+			links       { "root bsd" }
+
 
 --
 -- A more thorough cleanup.
diff --git a/3rdparty/genie/scripts/release.lua b/3rdparty/genie/scripts/release.lua
index d1173d5..39bcaa5 100644
--- a/3rdparty/genie/scripts/release.lua
+++ b/3rdparty/genie/scripts/release.lua
@@ -40,6 +40,7 @@ function dorelease()
 	exec(_PREMAKE_COMMAND .. " /to=../build/gmake.windows /os=windows gmake")
 	exec(_PREMAKE_COMMAND .. " /to=../build/gmake.linux /os=linux gmake")
 	exec(_PREMAKE_COMMAND .. " /to=../build/gmake.darwin /os=macosx /platform=universal32 gmake")
+	exec(_PREMAKE_COMMAND .. " /to=../build/gmake.haiku /os=haiku gmake")
 
 	print("")
 	print( "Finished.")
diff --git a/3rdparty/genie/src/base/cmdline.lua b/3rdparty/genie/src/base/cmdline.lua
index c3357b7..dcdc637 100644
--- a/3rdparty/genie/src/base/cmdline.lua
+++ b/3rdparty/genie/src/base/cmdline.lua
@@ -57,6 +57,7 @@
 			{ "macosx",   "Apple Mac OS X" },
 			{ "solaris",  "Solaris" },
 			{ "windows",  "Microsoft Windows" },
+			{ "haiku",    "Haiku" },
 		}
 	}
 
diff --git a/3rdparty/genie/src/base/os.lua b/3rdparty/genie/src/base/os.lua
index ae88c0a..b2c1cfa 100644
--- a/3rdparty/genie/src/base/os.lua
+++ b/3rdparty/genie/src/base/os.lua
@@ -66,6 +66,9 @@
 			if os.is("macosx") then
 				formats = { "lib%s.dylib", "%s.dylib" }
 				path = os.getenv("DYLD_LIBRARY_PATH")
+			elseif os.is("haiku") then
+				formats = { "lib%s.so", "%s.so" }
+				path = os.getenv("LIBRARY_PATH")
 			else
 				formats = { "lib%s.so", "%s.so" }
 				path = os.getenv("LD_LIBRARY_PATH") or ""
diff --git a/3rdparty/genie/src/host/premake.h b/3rdparty/genie/src/host/premake.h
index f0782db..5a3a636 100644
--- a/3rdparty/genie/src/host/premake.h
+++ b/3rdparty/genie/src/host/premake.h
@@ -27,6 +27,9 @@
 #elif defined(__OS2__)
 #define PLATFORM_OS2      (1)
 #define PLATFORM_STRING   "os2"
+#elif defined(__HAIKU__)
+#define PLATFORM_HAIKU      (1)
+#define PLATFORM_STRING   "haiku"
 #else
 #define PLATFORM_WINDOWS  (1)
 #define PLATFORM_STRING   "windows"
diff --git a/makefile b/makefile
index 4e0182d..1543f17 100644
--- a/makefile
+++ b/makefile
@@ -216,6 +216,7 @@ GENIEOS := darwin
 endif
 ifeq ($(firstword $(filter Haiku,$(UNAME))),Haiku)
 OS := haiku
+GENIEOS := haiku
 endif
 ifndef OS
 $(error Unable to detect OS from uname -a: $(UNAME))
@@ -471,6 +472,10 @@ endif
 ifeq ($(TARGETOS),asmjs)
 OSD := sdl
 endif
+
+ifeq ($(TARGETOS),haiku)
+OSD := sdl
+endif
 endif
 
 #-------------------------------------------------
@@ -1643,6 +1648,28 @@ endif
 	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR_SDL)/$(MAKETYPE)-ci20 config=$(CONFIG) precompile
 	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR_SDL)/$(MAKETYPE)-ci20 config=$(CONFIG)
 
+#-------------------------------------------------
+# gmake-haiku
+#-------------------------------------------------
+
+$(PROJECTDIR)/$(MAKETYPE)-haiku/Makefile: makefile $(SCRIPTS) $(GENIE)
+	$(SILENT) $(GENIE) $(PARAMS) $(TARGET_PARAMS) --gcc=haiku --gcc_version=$(GCC_VERSION) $(MAKETYPE)
+
+.PHONY: haiku_x64
+haiku_x64: generate $(PROJECTDIR)/$(MAKETYPE)-haiku/Makefile
+	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-haiku config=$(CONFIG)64 precompile
+	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-haiku config=$(CONFIG)64
+
+.PHONY: haiku_x86
+haiku_x86: generate $(PROJECTDIR)/$(MAKETYPE)-haiku/Makefile
+	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-haiku config=$(CONFIG)32 precompile
+	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-haiku config=$(CONFIG)32
+
+.PHONY: haiku
+haiku: generate $(PROJECTDIR)/$(MAKETYPE)-haiku/Makefile
+	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-haiku config=$(CONFIG) precompile
+	$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-haiku config=$(CONFIG)
+
 #-------------------------------------------------
 # cmake
 #-------------------------------------------------
diff --git a/scripts/toolchain.lua b/scripts/toolchain.lua
index 3eb2acf..7c919c9 100644
--- a/scripts/toolchain.lua
+++ b/scripts/toolchain.lua
@@ -41,6 +41,7 @@ newoption {
 		{ "solaris",       "Solaris"                },
 		{ "steamlink",     "Steam Link"             },
 		{ "ci20",          "Creator-Ci20"           },
+		{ "haiku",         "Haiku"                  },
 	},
 }
 
@@ -253,6 +254,10 @@ function toolchain(_buildDir, _subDir)
 			location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-ci20")
 		end
 
+		if "haiku" == _OPTIONS["gcc"] then
+			location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-haiku")
+		end
+
 		if "mingw32-gcc" == _OPTIONS["gcc"] then
 			if not os.getenv("MINGW32") then
 				print("Set MINGW32 envrionment variable.")
@@ -329,6 +334,10 @@ function toolchain(_buildDir, _subDir)
 		if "ci20" == _OPTIONS["gcc"] then
 			location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-ci20")
 		end
+
+		if "haiku" == _OPTIONS["gcc"] then
+			location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-haiku")
+		end
 	elseif _ACTION == "vs2015" or _ACTION == "vs2015-fastbuild" then
 
 		if (_ACTION .. "-clang") == _OPTIONS["vs"] then
diff --git a/src/osd/modules/file/posixfile.cpp b/src/osd/modules/file/posixfile.cpp
index 4f56a84..6b0c3a0 100644
--- a/src/osd/modules/file/posixfile.cpp
+++ b/src/osd/modules/file/posixfile.cpp
@@ -93,7 +93,7 @@ public:
 	{
 		ssize_t result;
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(__EMSCRIPTEN__) || defined(__ANDROID__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(__EMSCRIPTEN__) || defined(__ANDROID__) || defined(__HAIKU__)
 		result = ::pread(m_fd, buffer, size_t(count), off_t(std::make_unsigned_t<off_t>(offset)));
 #elif defined(WIN32) || defined(SDLMAME_NO64BITIO)
 		if (lseek(m_fd, off_t(std::make_unsigned_t<off_t>(offset)), SEEK_SET) < 0)
@@ -114,7 +114,7 @@ public:
 	{
 		ssize_t result;
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(__EMSCRIPTEN__) || defined(__ANDROID__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(__EMSCRIPTEN__) || defined(__ANDROID__) || defined(__HAIKU__)
 		result = ::pwrite(m_fd, buffer, size_t(count), off_t(std::make_unsigned_t<off_t>(offset)));
 #elif defined(WIN32) || defined(SDLMAME_NO64BITIO)
 		if (lseek(m_fd, off_t(std::make_unsigned_t<off_t>(offset)), SEEK_SET) < 0)
diff --git a/src/osd/modules/file/posixptty.cpp b/src/osd/modules/file/posixptty.cpp
index 5ecb370..a960e80 100644
--- a/src/osd/modules/file/posixptty.cpp
+++ b/src/osd/modules/file/posixptty.cpp
@@ -19,6 +19,10 @@
 #include <unistd.h>
 #include <cstdlib>
 
+#ifdef __HAIKU__
+#define _BSD_SOURCE
+#endif
+
 #if defined(__FreeBSD__) || defined(__DragonFly__)
 #include <termios.h>
 #include <libutil.h>
diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp
index 39f11a2..61c4baa 100644
--- a/src/osd/modules/render/drawbgfx.cpp
+++ b/src/osd/modules/render/drawbgfx.cpp
@@ -176,7 +176,7 @@ static void* sdlNativeWindowHandle(SDL_Window* _window)
 	return wmi.info.win.window;
 #   elif BX_PLATFORM_STEAMLINK
 	return wmi.info.vivante.window;
-#   elif BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_ANDROID
+#   elif BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_ANDROID || BX_PLATFORM_HAIKU
 	return nullptr;
 #   endif // BX_PLATFORM_
 }
-- 
2.28.0


From 22fff4a338284fe1bca14b61db9111e3a8ad1b5a Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 11 Jun 2020 08:59:34 +1000
Subject: Use stat Haiku


diff --git a/3rdparty/bx/src/file.cpp b/3rdparty/bx/src/file.cpp
index c158af0..2d6aa3e 100644
--- a/3rdparty/bx/src/file.cpp
+++ b/3rdparty/bx/src/file.cpp
@@ -650,7 +650,14 @@ namespace bx
 					break;
 				}
 
+#ifdef __HAIKU__
+				struct stat sp;
+				stat(item->d_name, &sp);
+
+				if (S_ISDIR(sp.st_mode))
+#else
 				if (0 != (item->d_type & DT_DIR) )
+#endif
 				{
 					_out.type = FileType::Dir;
 					_out.size = UINT64_MAX;
@@ -658,7 +665,11 @@ namespace bx
 					return true;
 				}
 
+#ifdef __HAIKU__
+				if (S_ISREG(sp.st_mode))
+#else
 				if (0 != (item->d_type & DT_REG) )
+#endif
 				{
 					_out.type = FileType::File;
 					_out.size = UINT64_MAX;
-- 
2.28.0


From 6db75a40c1da45e0a95484c894b37a708867b961 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 11 Jun 2020 09:00:11 +1000
Subject: Disable ptty


diff --git a/src/osd/modules/file/posixptty.cpp b/src/osd/modules/file/posixptty.cpp
index a960e80..76cae4c 100644
--- a/src/osd/modules/file/posixptty.cpp
+++ b/src/osd/modules/file/posixptty.cpp
@@ -113,7 +113,7 @@ bool posix_check_ptty_path(std::string const &path)
 
 osd_file::error posix_open_ptty(std::uint32_t openflags, osd_file::ptr &file, std::uint64_t &filesize, std::string &name)
 {
-#if defined(__ANDROID__)
+#if defined(__ANDROID__) || defined(__HAIKU__)
 	return osd_file::error::FAILURE;
 #else // defined(__ANDROID__)
 #if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
-- 
2.28.0


From f0d45284a7b0c006ead6494f3b629c6413d4c2c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolt=C3=A1n=20Mizsei?= <zmizsei@extrowerk.com>
Date: Thu, 29 Oct 2020 07:05:28 +0100
Subject: Build fix


diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h
index 9243645..00fe44e 100644
--- a/src/lib/netlist/plib/palloc.h
+++ b/src/lib/netlist/plib/palloc.h
@@ -422,7 +422,7 @@ namespace plib {
 		#if (PUSE_ALIGNED_ALLOCATION)
 		#if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
 			return _aligned_malloc(size, alignment);
-		#elif defined(__APPLE__) || defined(__ANDROID__)
+		#elif defined(__APPLE__) || defined(__ANDROID__) || defined(__HAIKU__)
 			void* p;
 			if (::posix_memalign(&p, alignment, size) != 0) {
 				p = nullptr;
-- 
2.28.0

