From 0923ec70cbaed6b87069bbccef77c9d142f34481 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 28 Feb 2021 17:54:22 +1000
Subject: Add haiku support


diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6a0d22..3b71804 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -184,7 +184,7 @@ install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
 install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
 
-if(UNIX AND NOT APPLE)
+if(UNIX AND NOT APPLE AND NOT HAIKU)
 	install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
 	install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
 	install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
diff --git a/cmake/Modules/FindIrrlicht.cmake b/cmake/Modules/FindIrrlicht.cmake
index 6f361e8..15d6f87 100644
--- a/cmake/Modules/FindIrrlicht.cmake
+++ b/cmake/Modules/FindIrrlicht.cmake
@@ -42,6 +42,7 @@ else()
 		PATHS
 		/usr/local/include/irrlicht
 		/usr/include/irrlicht
+		/system/develop/headers/x86/irrlicht #Haiku hybrid
 		/system/develop/headers/irrlicht #Haiku
 		PATH_SUFFIXES "include/irrlicht"
 	)
@@ -50,6 +51,7 @@ else()
 		PATHS
 		/usr/local/lib
 		/usr/lib
+		/system/develop/lib/x86 #Haiku hybrid
 		/system/develop/lib # Haiku
 	)
 endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7bcf8d6..2b2db7d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -312,7 +312,11 @@ else()
 	endif(BUILD_CLIENT)
 
 	find_package(ZLIB REQUIRED)
-	set(PLATFORM_LIBS -lpthread ${CMAKE_DL_LIBS})
+	if(HAIKU)
+		set(PLATFORM_LIBS ${PLATFORM_LIBS} -lintl -lnetwork -lbe)
+	else()
+		set(PLATFORM_LIBS -lpthread ${CMAKE_DL_LIBS})
+	endif(HAIKU)
 	if(APPLE)
 		set(PLATFORM_LIBS "-framework CoreFoundation" ${PLATFORM_LIBS})
 	else()
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index cda9530..eaf7c1e 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -456,6 +456,11 @@ void set_default_settings()
 	settings->setDefault("fps_max", "0");
 #endif
 
+#ifdef __HAIKU__
+	settings->setDefault("enable_shaders", "false");
+	settings->setDefault("video_driver", "burningsvideo");
+#endif
+
 	// Altered settings for Android
 #ifdef __ANDROID__
 	settings->setDefault("screen_w", "0");
diff --git a/src/porting.cpp b/src/porting.cpp
index 4c87bdd..334d4d3 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -60,6 +60,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
         #include <FindDirectory.h>
 #endif
 
+#if defined(__HAIKU__)
+#include <Application.h>
+#include <FindDirectory.h>
+#include <Path.h>
+#include <Roster.h>
+#include <OS.h>
+#endif
+
 #include "config.h"
 #include "debug.h"
 #include "filesys.h"
@@ -248,7 +256,16 @@ bool getCurrentWorkingDir(char *buf, size_t len)
 
 bool getExecPathFromProcfs(char *buf, size_t buflen)
 {
-#ifndef _WIN32
+#if defined(__HAIKU__)
+	app_info appInfo;
+	if (be_app->GetAppInfo(&appInfo) == B_OK) {
+		BPath path(&appInfo.ref);
+		sprintf(buf, path.Path());
+	} else {
+		sprintf(buf, "/system/apps/Minetest/Minetest");
+	}
+	return true;
+#elif defined(_WIN32)
 	buflen--;
 
 	ssize_t len;
@@ -506,6 +523,19 @@ bool setSystemPaths()
 	return true;
 }
 
+//// Haiku
+#elif defined(__HAIKU__)
+
+bool setSystemPaths()
+{
+	path_share = STATIC_SHAREDIR;
+	static char dir[PATH_MAX] = "";
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) != B_OK)
+		sprintf(dir, "/boot/home/config/settings");
+	dir[sizeof(dir) - 1] = 0;
+	path_user  = std::string(dir) + "/" + lowercase(PROJECT_NAME);
+	return true;
+}
 
 #else
 
-- 
2.30.0

