From 6554891108c0e2a9cc68eb28f033172f92280b95 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 19 Jul 2014 18:27:44 +0200
Subject: [PATCH 1/3] Add support for building under Haiku

We need -lnetwork for sockets.
---
 makefile | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/makefile b/makefile
index ec86998..2800826 100644
--- a/makefile
+++ b/makefile
@@ -201,25 +201,30 @@ ifeq ($(WIN32),)  #*nix Environments (&& cygwin)
                 OS_LDFLAGS += -L/opt/freeware/lib
               endif
             else
-              ifeq (,$(findstring NetBSD,$(OSTYPE)))
-                ifneq (no ldconfig,$(findstring no ldconfig,$(shell which ldconfig 2>&1)))
-                  LDSEARCH :=$(shell ldconfig -r | grep 'search directories' | awk '{print $$3}' | sed 's/:/ /g')
-                endif
-                ifneq (,$(LDSEARCH))
-                  LIBPATH := $(LDSEARCH)
-                else
-                  ifeq (,$(strip $(LPATH)))
-                    $(info *** Warning ***)
-                    $(info *** Warning *** The library search path on your $(OSTYPE) platform can't be)
-                    $(info *** Warning *** determined.  This should be resolved before you can expect)
-                    $(info *** Warning *** to have fully working simulators.)
-                    $(info *** Warning ***)
-                    $(info *** Warning *** You can specify your library paths via the LPATH environment)
-                    $(info *** Warning *** variable.)
-                    $(info *** Warning ***)
+              ifneq (,$(findstring Haiku,$(OSTYPE)))
+                OS_LDFLAGS += -lnetwork
+                LIBPATH += $(subst :, ,$(LIBRARY_PATH))
+              else
+                ifeq (,$(findstring NetBSD,$(OSTYPE)))
+                  ifneq (no ldconfig,$(findstring no ldconfig,$(shell which ldconfig 2>&1)))
+                    LDSEARCH :=$(shell ldconfig -r | grep 'search directories' | awk '{print $$3}' | sed 's/:/ /g')
+                  endif
+                  ifneq (,$(LDSEARCH))
+                    LIBPATH := $(LDSEARCH)
                   else
-                    LIBPATH = $(subst :, ,$(LPATH))
-                    OS_LDFLAGS += $(patsubst %,-L%,$(LIBPATH))
+                    ifeq (,$(strip $(LPATH)))
+                      $(info *** Warning ***)
+                      $(info *** Warning *** The library search path on your $(OSTYPE) platform can't be)
+                      $(info *** Warning *** determined.  This should be resolved before you can expect)
+                      $(info *** Warning *** to have fully working simulators.)
+                      $(info *** Warning ***)
+                      $(info *** Warning *** You can specify your library paths via the LPATH environment)
+                      $(info *** Warning *** variable.)
+                      $(info *** Warning ***)
+                    else
+                      LIBPATH = $(subst :, ,$(LPATH))
+                      OS_LDFLAGS += $(patsubst %,-L%,$(LIBPATH))
+                    endif
                   endif
                 endif
               endif
-- 
1.8.3.4


From d050424a3c05924a2388ccfed6df6b74aabaeeab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 19 Jul 2014 18:29:06 +0200
Subject: [PATCH 2/3] Work around missing nice() on Haiku

---
 sim_console.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sim_console.c b/sim_console.c
index d1bf515..7d6afef 100644
--- a/sim_console.c
+++ b/sim_console.c
@@ -127,6 +127,10 @@
 #include "sim_timer.h"
 #include <ctype.h>
 
+#ifdef __HAIKU__
+#define nice(n) ({})
+#endif
+
 /* Forward Declaraations of Platform specific routines */
 
 static t_stat sim_os_poll_kbd (void);
-- 
1.8.3.4


From 868e7d40c686120493b06a64c7ca9f97b6326dbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 19 Jul 2014 18:29:43 +0200
Subject: [PATCH 3/3] Haiku has socklen_t

---
 sim_sock.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/sim_sock.c b/sim_sock.c
index 4773c65..ccccb4e 100644
--- a/sim_sock.c
+++ b/sim_sock.c
@@ -775,7 +775,8 @@ if (fl == -1)
 sta = fcntl (sock, F_SETFL, fl | O_NONBLOCK);           /* set nonblock */
 if (sta == -1)
     return SOCKET_ERROR;
-#if !defined (macintosh) && !defined (__EMX__)          /* Unix only */
+#if !defined (macintosh) && !defined (__EMX__) && \
+    !defined (__HAIKU__)                                /* Unix only */
 sta = fcntl (sock, F_SETOWN, getpid());                 /* set ownership */
 if (sta == -1)
     return SOCKET_ERROR;
@@ -1029,7 +1030,8 @@ int32 sta, err;
 #if defined (macintosh) || defined (__linux) || defined (__linux__) || \
     defined (__APPLE__) || defined (__OpenBSD__) || \
     defined(__NetBSD__) || defined(__FreeBSD__) || \
-    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED))
+    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+    defined (__HAIKU__)
 socklen_t size;
 #elif defined (_WIN32) || defined (__EMX__) || \
      (defined (__ALPHA) && defined (__unix__)) || \
@@ -1087,7 +1089,8 @@ struct sockaddr_storage peername;
 #if defined (macintosh) || defined (__linux) || defined (__linux__) || \
     defined (__APPLE__) || defined (__OpenBSD__) || \
     defined(__NetBSD__) || defined(__FreeBSD__) || \
-    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED))
+    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+    defined (__HAIKU__)
 socklen_t peernamesize = (socklen_t)sizeof(peername);
 #elif defined (_WIN32) || defined (__EMX__) || \
      (defined (__ALPHA) && defined (__unix__)) || \
@@ -1121,7 +1124,8 @@ static int32 _sim_getaddrname (struct sockaddr *addr, size_t addrsize, char *hos
 #if defined (macintosh) || defined (__linux) || defined (__linux__) || \
     defined (__APPLE__) || defined (__OpenBSD__) || \
     defined(__NetBSD__) || defined(__FreeBSD__) || \
-    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED))
+    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+    defined (__HAIKU__)
 socklen_t size = (socklen_t)addrsize;
 #elif defined (_WIN32) || defined (__EMX__) || \
      (defined (__ALPHA) && defined (__unix__)) || \
@@ -1154,7 +1158,8 @@ struct sockaddr_storage sockname, peername;
 #if defined (macintosh) || defined (__linux) || defined (__linux__) || \
     defined (__APPLE__) || defined (__OpenBSD__) || \
     defined(__NetBSD__) || defined(__FreeBSD__) || \
-    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED))
+    (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+    defined (__HAIKU__)
 socklen_t socknamesize = (socklen_t)sizeof(sockname);
 socklen_t peernamesize = (socklen_t)sizeof(peername);
 #elif defined (_WIN32) || defined (__EMX__) || \
-- 
1.8.3.4

