From 8d56f7a3e1d87f52a62b0db57a8b7fba4dc921e1 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 22 Dec 2021 16:50:04 +0300
Subject: Fix build on Haiku


diff --git a/configure.ac b/configure.ac
index 77e4287..6397879 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1803,7 +1803,7 @@ INSTALL_D="install -D"
 CFLAGS=`echo "$CFLAGS" | sed 's/\(^\| \+\)-g[[0-9]]*//' | sed 's/[[[:space:]]]\{2,\}/ /g'`
 MODULE_CFLAGS="-fno-exceptions -fPIC $HAVE_GCC_FORMAT_CHECK $HAVE_BLOCK_RETURN"
 MODULE_CPPFLAGS="$HAVE_NO_OVERLOAD_VIRT_WARN $RTTI_OPT $MODULE_CFLAGS"
-MODULE_LDRELAX="-rdynamic -shared"
+MODULE_LDRELAX="-shared"
 MODULE_SYMBOLS="-Wl,--retain-symbols-file,/dev/null"
 SONAME_OPT="-shared -Wl,-soname="
 case "x$uname_os" in
diff --git a/engine/Engine.cpp b/engine/Engine.cpp
index da817a0..34ff80c 100644
--- a/engine/Engine.cpp
+++ b/engine/Engine.cpp
@@ -44,6 +44,10 @@ __declspec(dllimport) BOOL WINAPI SHGetSpecialFolderPathA(HWND,LPSTR,INT,BOOL);
 
 #else // _WINDOWS
 
+#ifdef __HAIKU__
+typedef void (*sighandler_t)(int);
+#endif
+
 #include "yatepaths.h"
 #include <dirent.h>
 #include <dlfcn.h>
diff --git a/engine/Mutex.cpp b/engine/Mutex.cpp
index 40c5d95..2ecccd7 100644
--- a/engine/Mutex.cpp
+++ b/engine/Mutex.cpp
@@ -32,7 +32,7 @@ typedef HANDLE HSEMAPHORE;
 
 #ifdef MUTEX_HACK
 extern "C" {
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__HAIKU__)
 extern int pthread_mutexattr_settype(pthread_mutexattr_t *__attr, int __kind);
 #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
 #else
diff --git a/engine/Socket.cpp b/engine/Socket.cpp
index 103a736..405b44f 100644
--- a/engine/Socket.cpp
+++ b/engine/Socket.cpp
@@ -40,7 +40,7 @@
 #endif
 
 #undef HAS_AF_UNIX
-
+#undef HAVE_GHBN_R
 #ifndef _WINDOWS
 
 #include <net/if.h>
diff --git a/engine/Thread.cpp b/engine/Thread.cpp
index b62626c..80adb2f 100644
--- a/engine/Thread.cpp
+++ b/engine/Thread.cpp
@@ -201,6 +201,7 @@ ThreadPrivate* ThreadPrivate::create(Thread* t,const char* name,Thread::Priority
 	    default:
 		break;
 	}
+#ifndef __HAIKU__
 	int err = ::pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
 	if (!err)
 	    err = ::pthread_attr_setschedpolicy(&attr,policy);
@@ -218,6 +219,7 @@ ThreadPrivate* ThreadPrivate::create(Thread* t,const char* name,Thread::Priority
 #ifdef XDEBUG
 	else
 	    Debug(DebugInfo,"Successfully set high thread priority %d",prio);
+#endif
 #endif
     }
 #endif /* _WINDOWS */
@@ -250,7 +252,7 @@ ThreadPrivate* ThreadPrivate::create(Thread* t,const char* name,Thread::Priority
 	}
 #else /* _WINDOWS */
 	e = ::pthread_create(&p->thread,&attr,startFunc,p);
-#ifdef PTHREAD_INHERIT_SCHED
+#if defined(PTHREAD_INHERIT_SCHED) && !defined(__HAIKU__)
 	if ((0 == i) && (EPERM == e) && (prio > Thread::Normal)) {
 	    Debug(DebugWarn,"Failed to create thread with priority %d, trying with inherited",prio);
 	    ::pthread_attr_setinheritsched(&attr,PTHREAD_INHERIT_SCHED);
diff --git a/yatemath.h b/yatemath.h
index 2a42426..7207e3e 100644
--- a/yatemath.h
+++ b/yatemath.h
@@ -25,6 +25,9 @@
 #include <yateclass.h>
 #include <math.h>
 #include <string.h>
+#ifdef __HAIKU__
+#undef bzero
+#endif
 
 namespace TelEngine {
 
-- 
2.30.2

