--- native/Makefile.orig	2018-10-07 17:48:55.000000000 -0400
+++ native/Makefile	2020-09-19 14:37:49.382748000 -0400
@@ -39,12 +39,15 @@
 # protection simply by defining HAVE_PROTECTION.  This option has been only
 # been enabled for those platforms on which it has been tested successfully.
 
+unexport LDFLAGS
+
 OS=$(shell uname | sed -e 's/CYGWIN.*/win32/g' \
 	                -e 's/MINGW32.*/win32/g' \
                         -e 's/SunOS.*/solaris/g' \
                         -e 's/NetBSD/netbsd/g' \
                         -e 's/GNU\/kFreeBSD/kfreebsd/g' \
                         -e 's/FreeBSD/freebsd/g' \
+                        -e 's/MidnightBSD/midnightbsd/g' \
                         -e 's/OpenBSD/openbsd/g' \
                         -e 's/Darwin.*/darwin/g' \
                         -e 's/AIX.*/aix/g' \
@@ -278,8 +281,11 @@
 ifneq (,$(findstring bsd,$(OS)))
 ARCH=$(shell uname -m | sed 's/i.86/i386/g')
 PCFLAGS+=-fPIC
-CINCLUDES+=-I/usr/X11R6/include
+CINCLUDES+=-I/usr/local/include
 LDFLAGS=-o $@ -shared
+ifeq ($(ARCH),i386)
+LDFLAGS+=-Wl,-z,notext
+endif
 CDEFINES+=-DHAVE_PROTECTION -DFFI_MMAP_EXEC_WRIT -DUSE_DEAFULT_LIBNAME_ENCODING
 endif
 
@@ -337,11 +343,11 @@
     GCC_MAJOR_VERSION = $(shell gcc -dumpversion | cut -f 1 -d '.')
     ifneq ($(GCC_MAJOR_VERSION),4)
 	ifneq ($(GCC_MAJOR_VERSION),3)
-	    LOC_CC_OPTS=-Wno-unknown-warning-option -Werror -Wno-clobbered -Wno-unused-variable
+	    LOC_CC_OPTS=-Wno-unused-variable
 	endif
     endif
 else
-    LOC_CC_OPTS=-Wno-unknown-warning-option -Werror -Wno-clobbered -Wno-unused-variable
+    LOC_CC_OPTS=-Wno-unused-variable
 endif
 
 # Enable 64-bit builds if the arch demands it
