From 3ce0b2aa74df8c8e32b15d5cf66665b5555961aa Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 26 Dec 2021 11:50:09 +1000
Subject: Fix build for Haiku


diff --git a/src/engine/endian_h2.h b/src/engine/endian_h2.h
index 7d1fa27..7a194c3 100644
--- a/src/engine/endian_h2.h
+++ b/src/engine/endian_h2.h
@@ -21,7 +21,7 @@
 #ifndef ENDIAN_H2_H
 #define ENDIAN_H2_H
 
-#if defined( __linux__ )
+#if defined( __linux__ ) || defined( __HAIKU__)
 #include <endian.h>
 
 #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ )
diff --git a/src/engine/system.cpp b/src/engine/system.cpp
index 853206c..8bc6354 100644
--- a/src/engine/system.cpp
+++ b/src/engine/system.cpp
@@ -26,6 +26,11 @@
 #include <map>
 #include <memory>
 
+#if defined( __HAIKU__ )
+#include <Path.h>
+#include <FindDirectory.h>
+#endif
+
 #if defined( ANDROID ) || defined( _MSC_VER )
 #include <clocale>
 #endif
@@ -138,6 +143,11 @@ std::string System::GetConfigDirectory( const std::string & prog )
 
     return std::string();
 #else
+#if defined( __HAIKU__ )
+	BPath settingsDir;
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsDir) == B_OK)
+		return std::string(settingsDir.Path()) + std::string("/fheroes2");
+#endif
     return GetHomeDirectory( prog );
 #endif
 }
@@ -157,6 +167,11 @@ std::string System::GetDataDirectory( const std::string & prog )
 
     return std::string();
 #else
+#if defined( __HAIKU__ )
+	BPath dataDir;
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, &dataDir) == B_OK)
+		return std::string(dataDir.Path()) +  std::string("/fheroes2");
+#endif
     return GetHomeDirectory( prog );
 #endif
 }
diff --git a/src/fheroes2/CMakeLists.txt b/src/fheroes2/CMakeLists.txt
index 0f9b8c8..e47fcd3 100644
--- a/src/fheroes2/CMakeLists.txt
+++ b/src/fheroes2/CMakeLists.txt
@@ -45,4 +45,8 @@ target_link_libraries(fheroes2
 	ZLIB::ZLIB
 	)
 
+if(HAIKU)
+	target_link_libraries(fheroes2 be)
+endif(HAIKU)
+
 install(TARGETS fheroes2 DESTINATION ${CMAKE_INSTALL_BINDIR})
-- 
2.30.2

