From 2460a24e103a3eda07c55e482b5f428a78fb7c53 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 21 Sep 2017 21:16:29 +0200
Subject: Haiku patch


diff --git a/SConscript b/SConscript
index 54b6468..b862fc7 100644
--- a/SConscript
+++ b/SConscript
@@ -261,6 +261,9 @@ class Project:
         #if sys.platform == "darwin":
         #    self.env.StaticLibrary("sdlmain", ["src/macosx/SDLmain.m"], [ 'SDL' ])
 
+        if sys.platform == 'haiku1':
+            self.conf.env.Append(LIBS = ['be'])
+
         self.env.Default(self.env.Program('pingus', ['src/main.cpp', libpingus]))
 
         # build test and utils
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 8b80140..84902e7 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -42,6 +42,11 @@
 #define F_OK   0
 #endif
 
+#ifdef __HAIKU__
+# include <FindDirectory.h>
+# include <Path.h>
+#endif
+
 #include "pingus/globals.hpp"
 #include "util/log.hpp"
 #include "util/pathname.hpp"
@@ -299,6 +304,10 @@ System::find_userdir()
 
   return tmpstr;
 
+#elif defined(__HAIKU__)
+	BPath settingsDir;
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsDir) == B_OK)
+		return std::string(settingsDir.Path()) + "/pingus/";
 #else /* !WIN32 */
   char* homedir = getenv("HOME");
 
-- 
2.26.0


From d3bf62c54c3b2735675398ef7209187329042c19 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 8 May 2020 20:47:44 +1000
Subject: Fix build


diff --git a/SConscript b/SConscript
index b862fc7..b416d62 100644
--- a/SConscript
+++ b/SConscript
@@ -126,12 +126,12 @@ class Project:
     def configure_end(self):
         self.env = self.conf.Finish()
 
-        print "Reports:"
-        print self.reports
+        print("Reports:")
+        print(self.reports)
 
         if not self.fatal_error == "":
-            print "Fatal Errors:"
-            print self.fatal_error
+            print("Fatal Errors:")
+            print(self.fatal_error)
             Exit(1)
 
     def configure_gxx(self): 
diff --git a/src/engine/display/display.cpp b/src/engine/display/display.cpp
index 31ba040..5174edf 100644
--- a/src/engine/display/display.cpp
+++ b/src/engine/display/display.cpp
@@ -94,6 +94,7 @@ Display::create_window(FramebufferType framebuffer_type, const Size& size, bool
 
   switch (framebuffer_type)
   {
+#ifndef __HAIKU__
     case OPENGL_FRAMEBUFFER:
 #ifdef HAVE_OPENGL
       s_framebuffer = std::unique_ptr<Framebuffer>(new OpenGLFramebuffer());
@@ -102,7 +103,7 @@ Display::create_window(FramebufferType framebuffer_type, const Size& size, bool
       raise_exception(std::runtime_error, "OpenGL support was not compiled in");
 #endif
       break;
-
+#endif
     case NULL_FRAMEBUFFER:
       s_framebuffer = std::unique_ptr<Framebuffer>(new NullFramebuffer());
       s_framebuffer->set_video_mode(size, fullscreen, resizable);
diff --git a/src/pingus/screens/demo_session.cpp b/src/pingus/screens/demo_session.cpp
index d613756..1ecf762 100644
--- a/src/pingus/screens/demo_session.cpp
+++ b/src/pingus/screens/demo_session.cpp
@@ -16,6 +16,7 @@
 
 #include "pingus/screens/demo_session.hpp"
 
+#include <functional>
 #include <algorithm>
 #include <iostream>
 
-- 
2.26.0


From b9175d071d3b7ef77216d6f0c0aae130db409ced Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 8 May 2020 22:49:23 +1000
Subject: Set working directory


diff --git a/src/main.cpp b/src/main.cpp
index fa3584c..7030963 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,12 +15,24 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <SDL.h>
+#ifdef __HAIKU__
+#include <unistd.h>
+#endif
 
 #include "pingus/pingus_main.hpp"
 
 int main(int argc, char** argv)
 {
   PingusMain app;
+#ifdef __HAIKU__
+	char *binpath = realpath(argv[0], NULL);
+	if (binpath != NULL) {
+		char *appdir = strrchr(binpath, '/');
+		*appdir = '\0';
+		chdir(binpath);
+		free(binpath);
+	}
+#endif
   return app.run(argc, argv);
 }
 
-- 
2.26.0

