From d813e6dd2e97d49b862b972ddc8bdeceaa89b69e Mon Sep 17 00:00:00 2001
From: Calvin Hill <calvin@hakobaito.co.uk>
Date: Mon, 27 Feb 2017 14:21:40 +0000
Subject: Haiku fixes


diff --git a/erts/configure b/erts/configure
index 4473e9c..e37bf70 100755
--- a/erts/configure
+++ b/erts/configure
@@ -6950,7 +6950,7 @@ if test "${ac_cv_lib_m_sin+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lm  $LIBS"
+LIBS=" $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -7013,7 +7013,7 @@ if test $ac_cv_lib_m_sin = yes; then
 #define HAVE_LIBM 1
 _ACEOF
 
-  LIBS="-lm $LIBS"
+  LIBS=" $LIBS"
 
 fi
 
@@ -21710,7 +21710,9 @@ _ACEOF
     if test "$gcc_dw_cmpxchg_asm" = "yes"; then
 
 cat >>confdefs.h <<\_ACEOF
-#define ETHR_GCC_HAVE_DW_CMPXCHG_ASM_SUPPORT 1
+#undef ETHR_GCC_HAVE_DW_CMPXCHG_ASM_SUPPORT
+#undef ERTS_SMP
+#undef USE_THREADS
 _ACEOF
 
     fi;;
diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c
index c1fa660..bb711f2 100644
--- a/erts/emulator/sys/unix/sys.c
+++ b/erts/emulator/sys/unix/sys.c
@@ -643,7 +643,7 @@ prepare_crash_dump(int secs)
 	if (nice_val > 39) {
 	    nice_val = 39;
 	}
-	erts_silence_warn_unused_result(nice(nice_val));
+	erts_silence_warn_unused_result(nice_val);
     }
 
     UnUseTmpHeapNoproc(NUFBUF);
diff --git a/erts/epmd/src/Makefile.in b/erts/epmd/src/Makefile.in
index da4370d..d72a002 100644
--- a/erts/epmd/src/Makefile.in
+++ b/erts/epmd/src/Makefile.in
@@ -56,7 +56,7 @@ else
 ifeq ($(findstring vxworks,$(TARGET)),vxworks)
 ERTS_INTERNAL_LIBS=-L../../lib/internal/$(TARGET) -lerts_internal$(ERTS_LIB_TYPEMARKER) @ERTS_INTERNAL_X_LIBS@
 else
-ERTS_INTERNAL_LIBS=-L../../lib/internal/$(TARGET) -lerts_internal$(ERTS_LIB_TYPEMARKER) @ERTS_INTERNAL_X_LIBS@ -lm
+ERTS_INTERNAL_LIBS=-L../../lib/internal/$(TARGET) -lerts_internal$(ERTS_LIB_TYPEMARKER) @ERTS_INTERNAL_X_LIBS@ 
 endif
 endif
 
diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in
index 5b1b911..615bda8 100644
--- a/erts/etc/common/Makefile.in
+++ b/erts/etc/common/Makefile.in
@@ -102,7 +102,7 @@ endif
 ifeq ($(TARGET),win32)
 ERTS_INTERNAL_LIBS=-L../../lib/internal/$(TARGET) -lerts_internal_r$(ERTS_LIB_TYPEMARKER) @ERTS_INTERNAL_X_LIBS@
 else
-ERTS_INTERNAL_LIBS=-L../../lib/internal/$(TARGET) -lerts_internal$(ERTS_LIB_TYPEMARKER) @ERTS_INTERNAL_X_LIBS@ -lm
+ERTS_INTERNAL_LIBS=-L../../lib/internal/$(TARGET) -lerts_internal$(ERTS_LIB_TYPEMARKER) @ERTS_INTERNAL_X_LIBS@ 
 endif
 
 ERTS_LIB = $(ERL_TOP)/erts/lib_src/obj/$(TARGET)/$(TYPE)/MADE
diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c
index 51ed2d0..65014c7 100644
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -2026,7 +2026,7 @@ initial_argv_massage(int *argc, char ***argv)
 
     vix = 0;
 
-    av = build_args_from_env("ERL_OTP" OTP_SYSTEM_VERSION "_FLAGS");
+    av = build_args_from_env("ERL_HAIKU_FLAGS");
     if (av)
 	avv[vix++].argv = av;
 
diff --git a/erts/include/internal/ethread.h b/erts/include/internal/ethread.h
index fa35bf3..576b693 100644
--- a/erts/include/internal/ethread.h
+++ b/erts/include/internal/ethread.h
@@ -27,9 +27,7 @@
 #ifndef ETHREAD_H__
 #define ETHREAD_H__
 
-#ifndef ETHR_HAVE_ETHREAD_DEFINES
-#  include "ethread_header_config.h"
-#endif
+#include "ethread_header_config.h"
 
 #include <stdlib.h>
 #include "ethread_inline.h"
diff --git a/erts/include/internal/i386/ethr_dw_atomic.h b/erts/include/internal/i386/ethr_dw_atomic.h
index 91acdb0..83bfb2a 100644
--- a/erts/include/internal/i386/ethr_dw_atomic.h
+++ b/erts/include/internal/i386/ethr_dw_atomic.h
@@ -26,6 +26,8 @@
 #ifndef ETHR_X86_DW_ATOMIC_H__
 #define ETHR_X86_DW_ATOMIC_H__
 
+#include "ethread_header_config.h"
+
 #ifdef ETHR_GCC_HAVE_DW_CMPXCHG_ASM_SUPPORT
 
 #define ETHR_HAVE_NATIVE_DW_ATOMIC
diff --git a/lib/asn1/c_src/Makefile b/lib/asn1/c_src/Makefile
index 1f714df..cb606fd 100644
--- a/lib/asn1/c_src/Makefile
+++ b/lib/asn1/c_src/Makefile
@@ -71,7 +71,7 @@ LN=cp
 else
 NIF_SHARED_OBJ_FILE = $(LIBDIR)/asn1rt_nif.so
 NIF_LIB_FILE = $(LIBDIR)/asn1rt_nif.a
-CLIB_FLAGS = -lc
+CLIB_FLAGS =
 LN= ln -s
 endif
 
diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c
index ea9ecb3..6020fd6 100644
--- a/lib/erl_interface/src/connect/ei_connect.c
+++ b/lib/erl_interface/src/connect/ei_connect.c
@@ -1153,6 +1153,8 @@ static unsigned int gen_challenge(void)
 
 #else  /* some unix */
 
+int gethostid() { return 108; }
+
 static unsigned int gen_challenge(void)
 {
     struct {
-- 
2.14.2


From f13ad75bd0cac454b7b4dc208eca4b9454fcd511 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sun, 8 Oct 2017 22:34:10 +0200
Subject: avoid using false, which we define.


diff --git a/erts/emulator/drivers/unix/ttsl_drv.c b/erts/emulator/drivers/unix/ttsl_drv.c
index 2a508b0..f0d7657 100644
--- a/erts/emulator/drivers/unix/ttsl_drv.c
+++ b/erts/emulator/drivers/unix/ttsl_drv.c
@@ -1323,17 +1323,17 @@ static int start_termcap(void)
 
     capbuf = driver_alloc(1024);
     if (!capbuf)
-	goto false;
+	goto _false;
     eres = erl_drv_getenv("TERM", capbuf, &envsz);
     if (eres == 0)
 	env = capbuf;
     else if (eres < 0) {
         DEBUGLOG(("start_termcap: failure in erl_drv_getenv(\"TERM\", ..) = %d\n", eres));
-	goto false;
+	goto _false;
     } else /* if (eres > 1) */ {
       char *envbuf = driver_alloc(envsz);
       if (!envbuf)
-	  goto false;
+	  goto _false;
       while (1) {
 	  char *newenvbuf;
 	  eres = erl_drv_getenv("TERM", envbuf, &envsz);
@@ -1343,7 +1343,7 @@ static int start_termcap(void)
           if (eres < 0 || !newenvbuf) {
               DEBUGLOG(("start_termcap: failure in erl_drv_getenv(\"TERM\", ..) = %d or realloc buf == %p\n", eres, newenvbuf));
 	      env = newenvbuf ? newenvbuf : envbuf;
-	      goto false;
+	      goto _false;
 	  }
 	  envbuf = newenvbuf;
       }
@@ -1351,7 +1351,7 @@ static int start_termcap(void)
     }
     if ((tres = tgetent((char*)lbuf, env)) <= 0) {
         DEBUGLOG(("start_termcap: failure in tgetent(..) = %d\n", tres));
-        goto false;
+        goto _false;
     }
     if (env != capbuf) {
 	env = NULL;
@@ -1373,7 +1373,7 @@ static int start_termcap(void)
         return TRUE;
     }
     DEBUGLOG(("start_termcap: failed start\n"));
- false:
+ _false:
     if (env && env != capbuf)
 	driver_free(env);
     if (capbuf)
-- 
2.14.2


From fdcf91292b46f6778353f540a3d9894b462bfcec Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 6 Nov 2017 22:47:39 +0100
Subject: setrlimit for RLIMIT_STACK fails on Haiku.


diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c
index 5206d75..6e305dd 100644
--- a/erts/emulator/beam/erl_init.c
+++ b/erts/emulator/beam/erl_init.c
@@ -1246,7 +1246,7 @@ static void set_main_stack_size(void)
 {
     char c;
     UWord stacksize;
-# if HAVE_DECL_GETRLIMIT && HAVE_DECL_SETRLIMIT && HAVE_DECL_RLIMIT_STACK
+# if HAVE_DECL_GETRLIMIT && HAVE_DECL_SETRLIMIT && HAVE_DECL_RLIMIT_STACK && !defined(__HAIKU__)
     struct rlimit rl;
     int bytes;
     stacksize = erts_sched_thread_suggested_stack_size * sizeof(Uint) * 1024;
-- 
2.14.2


From ce126fcf57777b6dc5dc1382346a20fc5f795d8e Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 6 Nov 2017 22:49:51 +0100
Subject: reset configure


diff --git a/erts/configure b/erts/configure
index e37bf70..6eae9ed 100755
--- a/erts/configure
+++ b/erts/configure
@@ -21710,9 +21710,7 @@ _ACEOF
     if test "$gcc_dw_cmpxchg_asm" = "yes"; then
 
 cat >>confdefs.h <<\_ACEOF
-#undef ETHR_GCC_HAVE_DW_CMPXCHG_ASM_SUPPORT
-#undef ERTS_SMP
-#undef USE_THREADS
+#define ETHR_GCC_HAVE_DW_CMPXCHG_ASM_SUPPORT 1
 _ACEOF
 
     fi;;
-- 
2.14.2

