From e419ec41c9666dc6b6ef065ea723a491abb8c4fe 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 6704cf0..d506079 100755
--- a/erts/configure
+++ b/erts/configure
@@ -6871,7 +6871,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
@@ -6934,7 +6934,7 @@ if test $ac_cv_lib_m_sin = yes; then
 #define HAVE_LIBM 1
 _ACEOF
 
-  LIBS="-lm $LIBS"
+  LIBS=" $LIBS"
 
 fi
 
@@ -21631,7 +21631,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 6459fa0..e3abf72 100644
--- a/erts/emulator/sys/unix/sys.c
+++ b/erts/emulator/sys/unix/sys.c
@@ -611,7 +611,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 cb053a1..a018799 100644
--- a/erts/etc/common/Makefile.in
+++ b/erts/etc/common/Makefile.in
@@ -99,7 +99,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 2b2e0e4..b27fba4 100644
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -2049,7 +2049,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 b23644d..343b9ef 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 c193fd8..8c7218b 100644
--- a/lib/erl_interface/src/connect/ei_connect.c
+++ b/lib/erl_interface/src/connect/ei_connect.c
@@ -1150,6 +1150,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 c1f8ef0ef7004c329a529e9b2709a07dea504c51 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 e425b99..66af7ae 100644
--- a/erts/emulator/drivers/unix/ttsl_drv.c
+++ b/erts/emulator/drivers/unix/ttsl_drv.c
@@ -1277,17 +1277,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);
@@ -1297,7 +1297,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;
       }
@@ -1305,7 +1305,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;
@@ -1327,7 +1327,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

