From 33e29a8c2f19b290ed6e9056a60aac6fd27426c6 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Sun, 6 Apr 2014 14:54:36 +0200
Subject: [PATCH 1/4] Fix search paths for SDL2 header files.

---
 bear/cmake-helper/FindSDL2.cmake       | 2 +-
 bear/cmake-helper/FindSDL2_mixer.cmake | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bear/cmake-helper/FindSDL2.cmake b/bear/cmake-helper/FindSDL2.cmake
index 7665a55..bcd3050 100644
--- a/bear/cmake-helper/FindSDL2.cmake
+++ b/bear/cmake-helper/FindSDL2.cmake
@@ -70,7 +70,7 @@
 find_path(SDL2_INCLUDE_DIR SDL.h
   HINTS
     ENV SDL2DIR
-  PATH_SUFFIXES include/SDL2 include
+  PATH_SUFFIXES include/SDL2 include SDL2
 )
 
 # SDL2-1.1 is the name used by FreeBSD ports...
diff --git a/bear/cmake-helper/FindSDL2_mixer.cmake b/bear/cmake-helper/FindSDL2_mixer.cmake
index 59ed911..d795965 100644
--- a/bear/cmake-helper/FindSDL2_mixer.cmake
+++ b/bear/cmake-helper/FindSDL2_mixer.cmake
@@ -40,7 +40,7 @@ find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h
   HINTS
     ENV SDL2MIXERDIR
     ENV SDL2DIR
-  PATH_SUFFIXES include/SDL2 include
+  PATH_SUFFIXES include/SDL2 include SDL2
 )
 
 if(NOT SDL2_MIXER_LIBRARY AND SDL2MIXER_LIBRARY)
-- 
1.8.3.4

From 864a651724bec4acce7b92fd3e1bddaa00f17c19 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Sun, 6 Apr 2014 17:02:35 +0200
Subject: [PATCH 2/4] Link libintl on haiku.

---
 bear/bear-engine/running_bear/CMakeLists.txt | 2 +-
 plee-the-bear/launcher/src/CMakeLists.txt    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bear/bear-engine/running_bear/CMakeLists.txt b/bear/bear-engine/running_bear/CMakeLists.txt
index 8b04d89..4fffd94 100644
--- a/bear/bear-engine/running_bear/CMakeLists.txt
+++ b/bear/bear-engine/running_bear/CMakeLists.txt
@@ -38,7 +38,7 @@ set(
   ${CLAW_APPLICATION_LIBRARIES}
   )
 
-if(WIN32)
+if(WIN32 OR HAIKU)
   set(
     RUNNING_BEAR_LINK_LIBRARIES
     ${RUNNING_BEAR_LINK_LIBRARIES}
diff --git a/plee-the-bear/launcher/src/CMakeLists.txt b/plee-the-bear/launcher/src/CMakeLists.txt
index 9ed5d32..ff88206 100644
--- a/plee-the-bear/launcher/src/CMakeLists.txt
+++ b/plee-the-bear/launcher/src/CMakeLists.txt
@@ -121,7 +121,7 @@ set(
   ${CLAW_APPLICATION_LIBRARIES}
   )
 
-if(WIN32)
+if(WIN32 OR HAIKU)
   set(
     PTB_LAUNCHER_LINK_LIBRARIES
     ${PTB_LAUNCHER_LINK_LIBRARIES}
-- 
1.8.3.4

From d04f6bda69bbf66b5aa9e3dd8e06c0b6f487bc0f Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Sun, 6 Apr 2014 19:41:58 +0200
Subject: [PATCH 3/4] Fix install directories.

---
 bear/cmake-helper/bear-config.cmake | 2 +-
 bear/cmake-module/CMakeLists.txt    | 2 +-
 plee-the-bear/CMakeLists.txt        | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/bear/cmake-helper/bear-config.cmake b/bear/cmake-helper/bear-config.cmake
index e66d79e..b483445 100644
--- a/bear/cmake-helper/bear-config.cmake
+++ b/bear/cmake-helper/bear-config.cmake
@@ -47,7 +47,7 @@ if( NOT BEAR_ENGINE_INSTALL_LIBRARY_DIR )
       "${BEAR_ENGINE_INSTALL_EXECUTABLE_DIR}"
       )
   else( WIN32 )
-    set( BEAR_ENGINE_INSTALL_LIBRARY_DIR lib )
+	  set( BEAR_ENGINE_INSTALL_LIBRARY_DIR lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR} )
   endif( WIN32 )
 endif( NOT BEAR_ENGINE_INSTALL_LIBRARY_DIR )
 
diff --git a/bear/cmake-module/CMakeLists.txt b/bear/cmake-module/CMakeLists.txt
index e182689..24c2113 100644
--- a/bear/cmake-module/CMakeLists.txt
+++ b/bear/cmake-module/CMakeLists.txt
@@ -1,7 +1,7 @@
 project(bear:cmake-modules)
 
 if( NOT BEAR_CMAKE_MODULES_INSTALL_PATH )
-  set( BEAR_CMAKE_MODULES_INSTALL_PATH "share/cmake/bear-engine" )
+  set( BEAR_CMAKE_MODULES_INSTALL_PATH "data/cmake/bear-engine" )
 endif( NOT BEAR_CMAKE_MODULES_INSTALL_PATH )
 
 set( BEAR_CMAKE_MODULES
diff --git a/plee-the-bear/CMakeLists.txt b/plee-the-bear/CMakeLists.txt
index 6a123d9..3d81af2 100644
--- a/plee-the-bear/CMakeLists.txt
+++ b/plee-the-bear/CMakeLists.txt
@@ -23,12 +23,12 @@ include( docbook-to-man )
 #-------------------------------------------------------------------------------
 # where the game resources are installed
 if( NOT PTB_INSTALL_DATA_DIR )
-  set( PTB_INSTALL_DATA_DIR share/plee-the-bear )
+  set( PTB_INSTALL_DATA_DIR data/plee-the-bear )
 endif( NOT PTB_INSTALL_DATA_DIR )
 
 # where the game executables are installed
 if( NOT PTB_INSTALL_EXECUTABLE_DIR )
-  set( PTB_INSTALL_EXECUTABLE_DIR bin )
+  set( PTB_INSTALL_EXECUTABLE_DIR bin${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR} )
 endif( NOT PTB_INSTALL_EXECUTABLE_DIR )
 
 # where the game libraries (the items) are installed
@@ -38,7 +38,7 @@ if( NOT PTB_INSTALL_CUSTOM_LIBRARY_DIR )
       "${PTB_INSTALL_EXECUTABLE_DIR}"
       )
   else( WIN32 )
-    set( PTB_INSTALL_CUSTOM_LIBRARY_DIR lib )
+    set( PTB_INSTALL_CUSTOM_LIBRARY_DIR lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR} )
   endif( WIN32 )
 endif( NOT PTB_INSTALL_CUSTOM_LIBRARY_DIR )
 
@@ -154,7 +154,7 @@ subdirs(
 
 install(
   DIRECTORY "lib/item-description"
-  DESTINATION "share/bear-factory/plee-the-bear"
+  DESTINATION "data/bear-factory/plee-the-bear"
   FILE_PERMISSIONS OWNER_READ OWNER_WRITE
   GROUP_READ
   WORLD_READ
-- 
1.8.3.4

From c842dde59df8ca44ecf4e318e8641bcc335e1ec5 Mon Sep 17 00:00:00 2001
From: Theodore Kokkoris <t.kokkoris@gmail.com>
Date: Wed, 24 Dec 2014 23:53:14 +0200
Subject: [PATCH 4/4] Change settings location on Haiku

---
 .../bear-engine/core/src/engine/code/game_local_client.cpp | 14 ++++++++++++++
 .../src/engine/system/code/default_game_filesystem.cpp     |  6 +++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/bear/bear-engine/core/src/engine/code/game_local_client.cpp b/bear/bear-engine/core/src/engine/code/game_local_client.cpp
index 51c055b..83ab880 100644
--- a/bear/bear-engine/core/src/engine/code/game_local_client.cpp
+++ b/bear/bear-engine/core/src/engine/code/game_local_client.cpp
@@ -51,6 +51,11 @@
 #include <claw/string_algorithm.hpp>
 #include <sstream>
 
+#if defined(__HAIKU__)
+  #include <FindDirectory.h>
+  #include <Path.h>
+#endif
+
 /*----------------------------------------------------------------------------*/
 /**
  * \brief Print the options of the program.
@@ -1107,6 +1112,15 @@ void bear::engine::game_local_client::init_game_filesystem()
   m_game_filesystem =
     freedesktop_game_filesystem( m_game_description.game_name() );
 
+#elif defined( __HAIKU__ )
+  BPath path;
+  status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
+  if (status < B_OK)
+    // fall back to default
+    m_game_filesystem = default_game_filesystem( m_game_description.game_name() );
+  else
+    m_game_filesystem = default_game_filesystem( m_game_description.game_name(), path.Path());
+
 #else
 
   m_game_filesystem = default_game_filesystem( m_game_description.game_name() );
diff --git a/bear/bear-engine/core/src/engine/system/code/default_game_filesystem.cpp b/bear/bear-engine/core/src/engine/system/code/default_game_filesystem.cpp
index 99ea2f8..0435b5a 100644
--- a/bear/bear-engine/core/src/engine/system/code/default_game_filesystem.cpp
+++ b/bear/bear-engine/core/src/engine/system/code/default_game_filesystem.cpp
@@ -107,7 +107,11 @@ std::string bear::engine::default_game_filesystem::get_game_directory() const
   boost::filesystem::path dir( m_root );
 
   std::string result;
-  std::string subdir = '.' + get_name_as_filename( m_game_name );
+  #if defined(__HAIKU__)
+    std::string subdir = get_name_as_filename( m_game_name );
+  #else
+    std::string subdir = '.' + get_name_as_filename( m_game_name );
+  #endif
 
   dir /= boost::filesystem::path( subdir );
 
-- 
1.8.3.4

