4c0d37
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
4c0d37
From: Rick Mark <rickmark@outlook.com>
4c0d37
Date: Fri, 27 Oct 2017 14:05:39 -0700
4c0d37
Subject: [PATCH] Support for building on macOS systems
4c0d37
4c0d37
---
4c0d37
 Make.defaults       | 12 ++++++++++--
4c0d37
 lib/x86_64/setjmp.S | 15 +++++++++++----
4c0d37
 2 files changed, 21 insertions(+), 6 deletions(-)
4c0d37
4c0d37
diff --git a/Make.defaults b/Make.defaults
4c0d37
index 5695b2ac1ab..5d34ff47157 100755
4c0d37
--- a/Make.defaults
4c0d37
+++ b/Make.defaults
4c0d37
@@ -65,7 +65,7 @@ OS           := $(shell uname -s)
4c0d37
 HOSTARCH     ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
4c0d37
 ARCH         ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
4c0d37
 
4c0d37
-# Get ARCH from the compiler if cross compiling 
4c0d37
+# Get ARCH from the compiler if cross compiling
4c0d37
 ifneq ($(CROSS_COMPILE),)
4c0d37
   override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
4c0d37
 endif
4c0d37
@@ -165,7 +165,10 @@ ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE)))
4c0d37
   CFLAGS += -fpic
4c0d37
 endif
4c0d37
 
4c0d37
-ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
4c0d37
+IS_FREEBSD = $(findstring FreeBSD, $(OS))
4c0d37
+IS_DARWIN = $(findstring Darwin, $(OS))
4c0d37
+
4c0d37
+ifneq "$(or $(IS_FREEBSD), $(IS_DARWIN))" ""
4c0d37
 CFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
4c0d37
            -fshort-wchar -fno-strict-aliasing \
4c0d37
            -ffreestanding -fno-stack-protector
4c0d37
@@ -177,7 +180,12 @@ CFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
4c0d37
            $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
4c0d37
 endif
4c0d37
 
4c0d37
+ifeq "$(IS_DARWIN)" ""
4c0d37
+ARFLAGS += -U
4c0d37
+else
4c0d37
 ARFLAGS := rDv
4c0d37
+endif
4c0d37
+
4c0d37
 ASFLAGS += $(ARCH3264)
4c0d37
 LDFLAGS	+= -nostdlib --warn-common --no-undefined --fatal-warnings \
4c0d37
 	   --build-id=sha1
4c0d37
diff --git a/lib/x86_64/setjmp.S b/lib/x86_64/setjmp.S
4c0d37
index e870aef703a..e3e51959719 100644
4c0d37
--- a/lib/x86_64/setjmp.S
4c0d37
+++ b/lib/x86_64/setjmp.S
4c0d37
@@ -1,10 +1,14 @@
4c0d37
 	.text
4c0d37
 	.globl	setjmp
4c0d37
-#ifndef __MINGW32__
4c0d37
+
4c0d37
+#ifndef __APPLE__
4c0d37
+# ifndef __MINGW32__
4c0d37
 	.type setjmp, @function
4c0d37
-#else
4c0d37
+# else
4c0d37
 	.def setjmp; .scl 2; .type 32; .endef
4c0d37
+# endif
4c0d37
 #endif
4c0d37
+
4c0d37
 setjmp:
4c0d37
 	pop	%rsi
4c0d37
 	movq	%rbx,0x00(%rdi)
4c0d37
@@ -20,11 +24,14 @@ setjmp:
4c0d37
 	ret
4c0d37
 
4c0d37
 	.globl	longjmp
4c0d37
-#ifndef __MINGW32__
4c0d37
+#ifndef __APPLE__
4c0d37
+# ifndef __MINGW32__
4c0d37
 	.type	longjmp, @function
4c0d37
-#else
4c0d37
+# else
4c0d37
 	.def longjmp; .scl 2; .type 32; .endef
4c0d37
+# endif
4c0d37
 #endif
4c0d37
+
4c0d37
 longjmp:
4c0d37
 	movl	%esi, %eax
4c0d37
 	movq	0x00(%rdi), %rbx