From dfa4371366584bdd59b37e806bfbfd365593dcdb Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 7 Feb 2021 14:54:25 +1000
Subject: Add haiku to configure.in


diff --git a/configure.in b/configure.in
index 8558e9c..2942a2b 100644
--- a/configure.in
+++ b/configure.in
@@ -49,6 +49,15 @@ case "$target_os" in
 		AC_MSG_RESULT(BeOS; Un*x style install)
 		MATHLIB=""
 		;;
+	haiku)
+		AC_MSG_RESULT(Haiku; Un*x style install)
+		unix_scoredir=no
+		DATADIR='EXE>>data'
+		SCOREDIR='HOME>>config/settings/KoboDeluxe/scores'
+		CONFIGDIR='HOME>>config/settings/KoboDeluxe'
+		CONFIGFILE='kobodl.cfg'
+		MATHLIB=""
+		;;
 	mingw32*)
 		AC_MSG_RESULT(Win32 (mingw32); Simple bundle)
 		build_simple_bundle=yes
-- 
2.30.0


From 18079627cf888df8f1e3e102c4fe204b5cda29fc Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 7 Feb 2021 14:54:35 +1000
Subject: Use find_directory for settings dir


diff --git a/kobo.cpp b/kobo.cpp
index 5ae1baa..7e46517 100644
--- a/kobo.cpp
+++ b/kobo.cpp
@@ -106,6 +106,23 @@ int mouse_right = 0;
 
 int exit_game = 0;
 
+#ifdef __HAIKU__
+#include <libgen.h>
+#include <FindDirectory.h>
+
+static int mkpath(const char *dir, mode_t mode)
+{
+	struct stat sb;
+	if (!dir) {
+		errno = EINVAL;
+		return 1;
+	}
+	if (!stat(dir, &sb))
+		return 0;
+	mkpath(dirname(strdup(dir)), mode);
+	return mkdir(dir, mode);
+}
+#endif
 
 static int main_init()
 {
@@ -2055,6 +2072,21 @@ int main(int argc, char *argv[])
 
 	SDL_Init(0);
 
+#ifdef __HAIKU__
+	char *binpath = realpath(argv[0], NULL);
+	if (binpath != NULL) {
+		char *appdir = strrchr(binpath, '/');
+		*appdir = '\0';
+		chdir(binpath);
+		free(binpath);
+	}
+	static char settingsDir[PATH_MAX] = "";
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settingsDir, sizeof(settingsDir)) == B_OK) {
+		strcat(settingsDir, "/KoboDeluxe/scores");
+		mkpath(settingsDir, 0755);
+	}
+#endif
+
 	if(main_init())
 	{
 		fprintf(stderr, "INTERNAL ERROR\n");
-- 
2.30.0

