From a3c450d7c077a76ddc6e892529a61e7aa649a5c8 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 19 Mar 2021 08:13:09 +1000
Subject: Fix for Haiku


diff --git a/extern/wcwidth/wcwidth.h b/extern/wcwidth/wcwidth.h
index 3039a50..68f21b6 100644
--- a/extern/wcwidth/wcwidth.h
+++ b/extern/wcwidth/wcwidth.h
@@ -21,7 +21,7 @@
 #define __WCWIDTH_H__
 
 #ifndef __cplusplus
-#  if defined(__APPLE__) || defined(__NetBSD__)
+#  if defined(__APPLE__) || defined(__NetBSD__) || defined(__HAIKU__)
 /* The <uchar.h> standard header is missing on macOS. */
 #include <stddef.h>
 typedef unsigned int char32_t;
diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index 4f71e3a..4d55d5d 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -177,7 +177,7 @@ void BLI_thread_queue_nowait(ThreadQueue *queue);
 
 /* Thread local storage */
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__HAIKU__)
 #  define ThreadLocal(type) pthread_key_t
 #  define BLI_thread_local_create(name) pthread_key_create(&name, NULL)
 #  define BLI_thread_local_delete(name) pthread_key_delete(name)
diff --git a/source/blender/windowmanager/intern/wm_platform_support.c b/source/blender/windowmanager/intern/wm_platform_support.c
index 54fc454..89514f3 100644
--- a/source/blender/windowmanager/intern/wm_platform_support.c
+++ b/source/blender/windowmanager/intern/wm_platform_support.c
@@ -118,7 +118,7 @@ bool WM_platform_support_perform_checks()
   char link[WM_PLATFORM_SUPPORT_TEXT_SIZE];
 
   bool result = true;
-
+#ifndef __HAIKU__
   eGPUSupportLevel support_level = GPU_platform_support_level();
   const char *platform_key = GPU_platform_support_level_key();
 
@@ -216,6 +216,6 @@ bool WM_platform_support_perform_checks()
     WM_ghost_show_message_box(
         title, message, "Find Latest Drivers", "Continue Anyway", link, dialog_options);
   }
-
+#endif
   return result;
 }
-- 
2.30.2


From e42f83b51d19c603044a187fecaa602978898300 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 19 Mar 2021 11:33:53 +1000
Subject: Fix hangs on exit


diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 1a45e53..df233cb 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -624,6 +624,10 @@ void WM_exit_ex(bContext *C, const bool do_python)
 
   ED_file_exit(); /* for fsmenu */
 
+  /* No need to call this early, rather do it late so that other
+   * pieces of Blender using sound may exit cleanly, see also T50676. */
+  BKE_sound_exit();
+
   UI_exit();
   BKE_blender_userdef_data_free(&U, false);
 
@@ -642,10 +646,6 @@ void WM_exit_ex(bContext *C, const bool do_python)
   BLI_threadapi_exit();
   BLI_task_scheduler_exit();
 
-  /* No need to call this early, rather do it late so that other
-   * pieces of Blender using sound may exit cleanly, see also T50676. */
-  BKE_sound_exit();
-
   BKE_appdir_exit();
   CLG_exit();
 
-- 
2.30.2


From 1b366a4083109e8eb645bdcb1a8e71a64a93d914 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 26 Dec 2021 17:05:15 +1000
Subject: applying patch openexr3.patch


diff --git a/build_files/cmake/Modules/FindOpenEXR.cmake b/build_files/cmake/Modules/FindOpenEXR.cmake
index 090f80b..a2f7b4c 100644
--- a/build_files/cmake/Modules/FindOpenEXR.cmake
+++ b/build_files/cmake/Modules/FindOpenEXR.cmake
@@ -34,11 +34,10 @@ ENDIF()
 SET(_openexr_libs_ver_init "2.0")
 
 SET(_openexr_FIND_COMPONENTS
-  Half
   Iex
-  IlmImf
-  IlmThread
   Imath
+  OpenEXR
+  IlmThread
 )
 
 SET(_openexr_SEARCH_DIRS
@@ -120,7 +119,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR  DEFAULT_MSG
 IF(OPENEXR_FOUND)
   SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES})
   # Both include paths are needed because of dummy OSL headers mixing #include <OpenEXR/foo.h> and #include <foo.h> :(
-  SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR_INCLUDE_DIR}/OpenEXR)
+  SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR_INCLUDE_DIR}/OpenEXR ${OPENEXR_INCLUDE_DIR}/Imath)
 ENDIF()
 
 MARK_AS_ADVANCED(
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index adf09f8..4784a9b 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -38,8 +38,10 @@
 #include <ImfChannelList.h>
 #include <ImfCompression.h>
 #include <ImfCompressionAttribute.h>
+#include <ImfFrameBuffer.h>
 #include <ImfIO.h>
 #include <ImfInputFile.h>
+#include <ImfInt64.h>
 #include <ImfOutputFile.h>
 #include <ImfPixelType.h>
 #include <ImfStandardAttributes.h>
-- 
2.30.2


From d6c36dcc77d6f7b691dddee7c17fb8749f0e77f9 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 26 Dec 2021 20:55:05 +1000
Subject: Link with icu


diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index fc0c37e..1876bae 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -505,7 +505,7 @@ endif()
 
 # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
 if(HAIKU)
-  list(APPEND PLATFORM_LINKLIBS -lnetwork)
+  list(APPEND PLATFORM_LINKLIBS -lnetwork -liconv -licuuc -licui18n)
 else()
   list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm)
 endif()
-- 
2.30.2


From f3c84cddd8ca36f931e7260194dd69f93c776ccf Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 26 Dec 2021 20:55:26 +1000
Subject: Use clock_gettime for Haiku


diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc
index de4602b..300aa93 100644
--- a/source/blender/blenlib/intern/uuid.cc
+++ b/source/blender/blenlib/intern/uuid.cc
@@ -42,7 +42,7 @@ bUUID BLI_uuid_generate_random()
     static_assert(std::mt19937_64::max() == 0xffffffffffffffffLL);
 
     struct timespec ts;
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__HAIKU__)
     /* `timespec_get()` is only available on macOS 10.15+, so until that's the minimum version
      * supported by Blender, use another function to get the timespec.
      *
-- 
2.30.2

