From 6b3879484f08f799f8261336d3fb3e7297400127 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sun, 7 Jun 2015 22:05:26 +0000
Subject: Haiku patch


diff --git a/src/include/OpenImageIO/detail/farmhash.h b/src/include/OpenImageIO/detail/farmhash.h
index a1ea8bd..9015ce7 100644
--- a/src/include/OpenImageIO/detail/farmhash.h
+++ b/src/include/OpenImageIO/detail/farmhash.h
@@ -175,6 +175,13 @@
 #define bswap_64(x) bswap64(x)
 #endif
 
+#elif defined(__HAIKU__)
+
+#undef bswap_32
+#undef bswap_64
+#define bswap_32 __builtin_bswap32
+#define bswap_64 __builtin_bswap64
+
 #else
 
 #undef bswap_32
diff --git a/src/libOpenImageIO/CMakeLists.txt b/src/libOpenImageIO/CMakeLists.txt
index 7b89dc0..4abe293 100644
--- a/src/libOpenImageIO/CMakeLists.txt
+++ b/src/libOpenImageIO/CMakeLists.txt
@@ -176,7 +176,9 @@ if (MINGW)
     target_link_libraries (OpenImageIO PRIVATE ws2_32)
 endif()
 
-
+if (__HAIKU__)
+    target_link_libraries (OpenImageIO network)
+endif()
 
 if (MSVC)
     # In some MSVC setups, the IBA functions with huge template expansions
diff --git a/src/libutil/sysutil.cpp b/src/libutil/sysutil.cpp
index 61edc0b..4627990 100644
--- a/src/libutil/sysutil.cpp
+++ b/src/libutil/sysutil.cpp
@@ -58,6 +58,12 @@
 #    include <unistd.h>
 #endif
 
+#if defined (__HAIKU__)
+# include <sys/types.h>
+# include <sys/resource.h>
+# include <unistd.h>
+#endif
+
 #include <OpenImageIO/dassert.h>
 #include <OpenImageIO/strutil.h>
 #include <OpenImageIO/sysutil.h>
@@ -255,7 +261,7 @@ Sysutil::this_program_path()
     size_t cb = sizeof(filename);
     int r     = 1;
     sysctl(mib, 4, filename, &cb, NULL, 0);
-#elif defined(__GNU__) || defined(__OpenBSD__) || defined(_WIN32)
+#elif defined(__GNU__) || defined(__OpenBSD__) || defined(_WIN32) || defined(__HAIKU__)
     int r = 0;
 #else
     // No idea what platform this is
diff --git a/src/libutil/xxhash.cpp b/src/libutil/xxhash.cpp
index 46a8ce1..becaadd 100644
--- a/src/libutil/xxhash.cpp
+++ b/src/libutil/xxhash.cpp
@@ -126,8 +126,10 @@ typedef unsigned long long U64;
 #if defined(__GNUC__)  && !defined(XXH_USE_UNALIGNED_ACCESS)
 #  define _PACKED __attribute__ ((packed))
 #else
+#ifndef __HAIKU__
 #  define _PACKED
 #endif
+#endif
 
 #if !defined(XXH_USE_UNALIGNED_ACCESS) && !defined(__GNUC__)
 #  ifdef __IBMC__
diff --git a/src/make/detectplatform.mk b/src/make/detectplatform.mk
index 90fd11b..a28ee3e 100644
--- a/src/make/detectplatform.mk
+++ b/src/make/detectplatform.mk
@@ -51,6 +51,14 @@ ifeq (${platform},unknown)
     endif
   endif
 
+  # Haiku
+  ifeq (${uname},haiku)
+    platform := haiku
+    ifeq (${hw},x86_64)
+      platform := haiku64
+    endif
+ endif
+
   # Windows
   ifeq (${uname},cygwin)
     platform := windows
-- 
2.30.2


From adfd806d493760052597972e8be99dc1eba4ace7 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Wed, 6 Nov 2019 23:18:49 +0100
Subject: tiff uses uint32 instead of uint32_t


diff --git a/src/tiff.imageio/tiffinput.cpp b/src/tiff.imageio/tiffinput.cpp
index 01c52a4..a651689 100644
--- a/src/tiff.imageio/tiffinput.cpp
+++ b/src/tiff.imageio/tiffinput.cpp
@@ -8,6 +8,7 @@
 #include <cstdio>
 #include <cstdlib>
 
+
 #define AVOID_WIN32_FILEIO
 #include <tiffio.h>
 #include <zlib.h>
@@ -24,6 +25,9 @@
 
 #include "imageio_pvt.h"
 
+#if defined(__HAIKU__) && defined(__INTEL__)
+#define uint32_t        uint32
+#endif
 
 OIIO_PLUGIN_NAMESPACE_BEGIN
 
-- 
2.30.2

