From 8a4643025a314570d8ff667461aa8a88b433bd38 Mon Sep 17 00:00:00 2001
From: Kacper Kasper <kacperkasper@gmail.com>
Date: Sat, 5 Jul 2014 02:12:23 +0200
Subject: Haiku support


diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index 750696d..b53cfea 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -7,7 +7,7 @@ include $(CORE_DEPTH)/coreconf/UNIX.mk
 
 XP_DEFINE := $(XP_DEFINE:-DXP_UNIX=-DXP_BEOS)
 
-USE_PTHREADS = 
+USE_PTHREADS = 1
 
 ifeq ($(USE_PTHREADS),1)
 	IMPL_STRATEGY = _PTH
@@ -27,7 +27,7 @@ else
 	CPU_ARCH	= x86
 endif
 
-MKSHLIB		= $(CC) -nostart -Wl,-soname -Wl,$(@:$(OBJDIR)/%.so=%.so)
+MKSHLIB		= $(CC) -shared -Wl,-soname -Wl,$(@:$(OBJDIR)/%.so=%.so)
 ifdef BUILD_OPT
 	OPTIMIZER	= -O2
 endif
diff --git a/coreconf/arch.mk b/coreconf/arch.mk
index cc13ced..8035236 100644
--- a/coreconf/arch.mk
+++ b/coreconf/arch.mk
@@ -33,6 +33,14 @@ else
     OS_RELEASE := $(shell uname -r)
 endif
 
+#
+# Force the Haiku machines to use BeOS.
+#
+
+ifeq ($(OS_ARCH),Haiku)
+	OS_ARCH = BeOS
+endif
+
 #
 # Force the IRIX64 machines to use IRIX.
 #
diff --git a/lib/dbm/include/mcom_db.h b/lib/dbm/include/mcom_db.h
index e961dd1..58a6481 100644
--- a/lib/dbm/include/mcom_db.h
+++ b/lib/dbm/include/mcom_db.h
@@ -60,7 +60,7 @@ typedef PRUint32 uint32;
 #include <sys/byteorder.h>
 #endif
 
-#if defined(__linux) || defined(__BEOS__)
+#if defined(__linux) || defined(BEOS)
 #include <endian.h>
 #ifndef BYTE_ORDER
 #define BYTE_ORDER __BYTE_ORDER
-- 
2.27.0


From 86324060d4790fc18325e1a19c277dd5c6d1c329 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 25 Sep 2014 13:09:35 +0000
Subject: define RTLD_NOLOAD


diff --git a/lib/freebl/stubs.c b/lib/freebl/stubs.c
index c42f694..edee40a 100644
--- a/lib/freebl/stubs.c
+++ b/lib/freebl/stubs.c
@@ -718,6 +718,10 @@ freebl_InitNSSUtil(void *lib)
     return SECSuccess;
 }
 
+#ifndef RTLD_NOLOAD
+    #define RTLD_NOLOAD 0
+#endif
+
 /*
  * fetch the library if it's loaded. For NSS it should already be loaded
  */
-- 
2.28.0


From 28a3097e65d9cb2cef61e850ce3b7302419c0cc7 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 25 Sep 2014 13:40:13 +0000
Subject: skip optionally the signing part


diff --git a/cmd/shlibsign/Makefile b/cmd/shlibsign/Makefile
index a119205..9e38c1c 100644
--- a/cmd/shlibsign/Makefile
+++ b/cmd/shlibsign/Makefile
@@ -95,7 +95,9 @@ else
     endif
 endif
 
+ifndef SKIP_SHLIBSIGN
 libs: install
+endif
 ifdef CHECKLOC
 	$(MAKE) $(CHECKLOC)
 endif
diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index b53cfea..51fe162 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -45,3 +45,5 @@ ARCH			= beos
 
 DSO_CFLAGS		= -fPIC
 DSO_LDOPTS		=
+
+SKIP_SHLIBSIGN=1
-- 
2.27.0


From dc372022c2e912e0676962d5f5581b18726565ec Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 25 Sep 2014 14:14:26 +0000
Subject: use system libs


diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index 51fe162..fe54580 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -47,3 +47,6 @@ DSO_CFLAGS		= -fPIC
 DSO_LDOPTS		=
 
 SKIP_SHLIBSIGN=1
+USE_SYSTEM_ZLIB = 1
+ZLIB_LIBS = -lz
+NSS_USE_SYSTEM_SQLITE=1
-- 
2.27.0


From 877f57c12e2633a5a7a4109f9f504d137b09255e Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Tue, 24 Nov 2015 19:12:08 +0000
Subject: avoid some tests.


diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index fe54580..3bc0ce3 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -50,3 +50,4 @@ SKIP_SHLIBSIGN=1
 USE_SYSTEM_ZLIB = 1
 ZLIB_LIBS = -lz
 NSS_USE_SYSTEM_SQLITE=1
+NSS_DISABLE_GTESTS=1
-- 
2.27.0


From 13e9de942b492ba8f8273957d39592e53c5ff638 Mon Sep 17 00:00:00 2001
From: Kacper Kasper <kacperkasper@gmail.com>
Date: Fri, 27 Apr 2018 21:38:56 +0200
Subject: Enable -Bsymbolic for BeOS target

* Fixes infinite loop in RNG_RNGInit.

diff --git a/lib/freebl/Makefile b/lib/freebl/Makefile
index 4a60041..32cfca1 100644
--- a/lib/freebl/Makefile
+++ b/lib/freebl/Makefile
@@ -333,7 +333,7 @@ endif
 # to bind the blapi function references in FREEBLVector vector
 # (ldvector.c) to the blapi functions defined in the freebl
 # shared libraries.
-ifeq (,$(filter-out BSD_OS FreeBSD Linux NetBSD OpenBSD, $(OS_TARGET)))
+ifeq (,$(filter-out BSD_OS FreeBSD Linux NetBSD OpenBSD BeOS, $(OS_TARGET)))
     MKSHLIB += -Wl,-Bsymbolic
 endif
 
-- 
2.27.0


From f2e06593a78fd477b7c6aa9ee25ed9b37737b142 Mon Sep 17 00:00:00 2001
From: Kacper Kasper <kacperkasper@gmail.com>
Date: Sat, 11 Aug 2018 00:46:36 +0200
Subject: Define XP_HAIKU

* Fixes build error caused by BeOS defines in NSPR header.

diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index 3bc0ce3..d25df28 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -5,7 +5,7 @@
 
 include $(CORE_DEPTH)/coreconf/UNIX.mk
 
-XP_DEFINE := $(XP_DEFINE:-DXP_UNIX=-DXP_BEOS)
+XP_DEFINE := $(XP_DEFINE:-DXP_UNIX=-DXP_BEOS -DXP_HAIKU)
 
 USE_PTHREADS = 1
 
-- 
2.27.0


From 4df03694cb13a45742418097685e3aa18cb2136e Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 14 Aug 2018 09:00:06 +1000
Subject: Fix build for x64


diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index d25df28..9cc8afc 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -27,6 +27,10 @@ else
 	CPU_ARCH	= x86
 endif
 
+ifeq ($(USE_64),1)
+	CPU_ARCH	= x86_64
+endif
+
 MKSHLIB		= $(CC) -shared -Wl,-soname -Wl,$(@:$(OBJDIR)/%.so=%.so)
 ifdef BUILD_OPT
 	OPTIMIZER	= -O2
-- 
2.27.0


From ddcc242da5891ad734286a856a9d528285fa0b04 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 15 Aug 2018 11:12:46 +1000
Subject: Fix build for x86


diff --git a/cmd/httpserv/httpserv.c b/cmd/httpserv/httpserv.c
index c7277f3..eb806e2 100644
--- a/cmd/httpserv/httpserv.c
+++ b/cmd/httpserv/httpserv.c
@@ -1325,7 +1325,7 @@ main(int argc, char **argv)
         FILE *tmpfile = fopen(pidFile, "w+");
 
         if (tmpfile) {
-            fprintf(tmpfile, "%d", getpid());
+            fprintf(tmpfile, "%d", (int)getpid());
             fclose(tmpfile);
         }
     }
diff --git a/cmd/selfserv/selfserv.c b/cmd/selfserv/selfserv.c
index 1584d7e..0c899b0 100644
--- a/cmd/selfserv/selfserv.c
+++ b/cmd/selfserv/selfserv.c
@@ -2668,7 +2668,7 @@ main(int argc, char **argv)
         FILE *tmpfile = fopen(pidFile, "w+");
 
         if (tmpfile) {
-            fprintf(tmpfile, "%d", getpid());
+            fprintf(tmpfile, "%d", (int)getpid());
             fclose(tmpfile);
         }
     }
-- 
2.27.0


From 891b22aa8e45f600bb86c36ebd241885cb0bfa18 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sun, 28 Feb 2021 18:25:30 +0100
Subject: Mapfile for Haiku


diff --git a/coreconf/BeOS.mk b/coreconf/BeOS.mk
index 9cc8afc..9370890 100644
--- a/coreconf/BeOS.mk
+++ b/coreconf/BeOS.mk
@@ -48,10 +48,17 @@ endif
 ARCH			= beos
 
 DSO_CFLAGS		= -fPIC
-DSO_LDOPTS		=
+DSO_LDOPTS		= -shared
 
 SKIP_SHLIBSIGN=1
 USE_SYSTEM_ZLIB = 1
 ZLIB_LIBS = -lz
 NSS_USE_SYSTEM_SQLITE=1
 NSS_DISABLE_GTESTS=1
+
+MKSHLIB			= $(CC) $(DSO_LDOPTS)
+ifdef MAPFILE
+	MKSHLIB += -Wl,--version-script,$(MAPFILE)
+endif
+PROCESS_MAP_FILE = grep -v ';-' $< | \
+        sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
-- 
2.30.0

