From 8e69182566c9b2b2540bf6b054b8df82e5588b03 Mon Sep 17 00:00:00 2001
From: Christopher Friedt <chris@mmbnetworks.com>
Date: Fri, 29 Apr 2016 12:16:43 -0400
Subject: [PATCH 1/4] some (not all) mac-specific fixes

---
 Makefile                                 | 48 +++++++++++++++++++++++-
 patches/musl/00-broken-mac-os-x-ar.patch | 17 +++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 patches/musl/00-broken-mac-os-x-ar.patch

diff --git a/Makefile b/Makefile
index 3daa48c..f56e549 100644
--- a/Makefile
+++ b/Makefile
@@ -95,7 +95,16 @@ binutils-$(BINUTILS_VER)/.mcm_configured: binutils-$(BINUTILS_VER)/.mcm_extracte
 	touch $@
 
 binutils-$(BINUTILS_VER)/.mcm_built: binutils-$(BINUTILS_VER)/.mcm_configured
-	cd binutils-$(BINUTILS_VER) && $(MAKE)
+ifeq ($(shell uname),Darwin)
+	echo '#define HAVE_STDLIB_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+	echo '#define HAVE_STRING_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+	echo '#define HAVE_SYS_TYPES_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+	echo '#define HAVE_SYS_STAT_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+	echo '#define HAVE_UNISTD_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+	echo '#define HAVE_FCNTL_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
+endif
+	$(MAKE) -C binutils-$(BINUTILS_VER)
 	touch $@
 
 binutils-$(BINUTILS_VER)/.mcm_installed: binutils-$(BINUTILS_VER)/.mcm_built
@@ -114,6 +123,24 @@ gcc-$(GCC_VER)/.mcm_extracted: $(SOURCES)/gcc-$(GCC_VER).tar.bz2 $(SOURCES)/conf
 gcc-$(GCC_VER)/build0/.mcm_configured: gcc-$(GCC_VER)/.mcm_extracted | binutils-$(BINUTILS_VER)/.mcm_installed
 	mkdir -p gcc-$(GCC_VER)/build0
 	test -e gcc-$(GCC_VER)/build0/config.status || ( cd gcc-$(GCC_VER)/build0 && $(GCC0_VARS) ../configure $(GCC0_CONFIG) )
+ifeq ($(shell uname),Darwin)
+	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
+	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build0/gcc/auto-host.h
+	echo '#define HAVE_SYS_PARAM_H 1' >> gcc-$(GCC_VER)/build0/gcc/auto-host.h
+endif
 	touch $@
 
 gcc-$(GCC_VER)/build0/.mcm_built: gcc-$(GCC_VER)/build0/.mcm_configured
@@ -123,6 +150,24 @@ gcc-$(GCC_VER)/build0/.mcm_built: gcc-$(GCC_VER)/build0/.mcm_configured
 gcc-$(GCC_VER)/build/.mcm_configured:  gcc-$(GCC_VER)/.mcm_extracted | binutils-$(BINUTILS_VER)/.mcm_installed musl/.mcm_installed
 	mkdir -p gcc-$(GCC_VER)/build
 	test -e gcc-$(GCC_VER)/build/config.status || ( cd gcc-$(GCC_VER)/build && ../configure $(GCC_CONFIG) )
+ifeq ($(shell uname),Darwin)
+	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
+	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build/gcc/auto-host.h
+	echo '#define HAVE_SYS_PARAM_H 1' >> gcc-$(GCC_VER)/build/gcc/auto-host.h
+endif
 	touch $@
 
 gcc-$(GCC_VER)/build/.mcm_built: gcc-$(GCC_VER)/build/.mcm_configured
@@ -139,6 +184,7 @@ gcc-$(GCC_VER)/build/.mcm_installed: gcc-$(GCC_VER)/build/.mcm_built
 
 musl/.mcm_cloned:
 	test -d musl || git clone -b $(MUSL_TAG) git://git.musl-libc.org/musl musl
+	cat patches/musl/* | ( cd musl && patch -p1 )
 	touch $@
 
 musl/.mcm_configured: musl/.mcm_cloned gcc-$(GCC_VER)/build0/.mcm_built
diff --git a/patches/musl/00-broken-mac-os-x-ar.patch b/patches/musl/00-broken-mac-os-x-ar.patch
new file mode 100644
index 0000000..ce27316
--- /dev/null
+++ b/patches/musl/00-broken-mac-os-x-ar.patch
@@ -0,0 +1,17 @@
+diff --git a/Makefile b/Makefile
+index ec54880..b048cbd 100644
+--- a/Makefile
++++ b/Makefile
+@@ -170,7 +170,12 @@ lib/libc.a: $(AOBJS)
+ 
+ $(EMPTY_LIBS):
+ 	rm -f $@
++ifeq ($(shell uname),Darwin)
++	touch .empty.o
++	$(AR) rc $@ .empty.o
++else
+ 	$(AR) rc $@
++endif
+ 
+ lib/%.o: obj/crt/$(ARCH)/%.o
+ 	cp $< $@

From b6af1d4b8578acc700b4ff8e5d0dfcd57ad04b49 Mon Sep 17 00:00:00 2001
From: Christopher Friedt <chris@mmbnetworks.com>
Date: Fri, 29 Apr 2016 12:47:41 -0400
Subject: [PATCH 2/4] slight modification for config.h settings for mac

---
 Makefile | 52 +++++++++++++---------------------------------------
 1 file changed, 13 insertions(+), 39 deletions(-)

diff --git a/Makefile b/Makefile
index f56e549..a3f137d 100644
--- a/Makefile
+++ b/Makefile
@@ -92,9 +92,6 @@ binutils-$(BINUTILS_VER)/.mcm_extracted: $(SOURCES)/binutils-$(BINUTILS_VER).tar
 
 binutils-$(BINUTILS_VER)/.mcm_configured: binutils-$(BINUTILS_VER)/.mcm_extracted
 	test -e binutils-$(BINUTILS_VER)/config.status || ( cd binutils-$(BINUTILS_VER) && ./configure $(BINUTILS_CONFIG) )
-	touch $@
-
-binutils-$(BINUTILS_VER)/.mcm_built: binutils-$(BINUTILS_VER)/.mcm_configured
 ifeq ($(shell uname),Darwin)
 	echo '#define HAVE_STDLIB_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
 	echo '#define HAVE_LIMITS_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
@@ -104,6 +101,9 @@ ifeq ($(shell uname),Darwin)
 	echo '#define HAVE_UNISTD_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
 	echo '#define HAVE_FCNTL_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
 endif
+	touch $@
+
+binutils-$(BINUTILS_VER)/.mcm_built: binutils-$(BINUTILS_VER)/.mcm_configured
 	$(MAKE) -C binutils-$(BINUTILS_VER)
 	touch $@
 
@@ -118,29 +118,21 @@ gcc-$(GCC_VER)/.mcm_extracted: $(SOURCES)/gcc-$(GCC_VER).tar.bz2 $(SOURCES)/conf
 	tar jxvf $<
 	cat patches/gcc-$(GCC_VER)/* | ( cd gcc-$(GCC_VER) && patch -p1 )
 	cp $(SOURCES)/config.sub gcc-$(GCC_VER)
+ifeq ($(shell uname),Darwin)
+	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
+	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
+	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
+	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
+	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/libiberty/config.inø
+	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
+	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/gcc/auto-host.h
+	echo '#define HAVE_SYS_PARAM_H 1' >> gcc-$(GCC_VER)/gcc/auto-host.h
+endif
 	touch $@
 
 gcc-$(GCC_VER)/build0/.mcm_configured: gcc-$(GCC_VER)/.mcm_extracted | binutils-$(BINUTILS_VER)/.mcm_installed
 	mkdir -p gcc-$(GCC_VER)/build0
 	test -e gcc-$(GCC_VER)/build0/config.status || ( cd gcc-$(GCC_VER)/build0 && $(GCC0_VARS) ../configure $(GCC0_CONFIG) )
-ifeq ($(shell uname),Darwin)
-	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build0/libiberty/config.h
-	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build0/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build0/gcc/auto-host.h
-	echo '#define HAVE_SYS_PARAM_H 1' >> gcc-$(GCC_VER)/build0/gcc/auto-host.h
-endif
 	touch $@
 
 gcc-$(GCC_VER)/build0/.mcm_built: gcc-$(GCC_VER)/build0/.mcm_configured
@@ -150,24 +142,6 @@ gcc-$(GCC_VER)/build0/.mcm_built: gcc-$(GCC_VER)/build0/.mcm_configured
 gcc-$(GCC_VER)/build/.mcm_configured:  gcc-$(GCC_VER)/.mcm_extracted | binutils-$(BINUTILS_VER)/.mcm_installed musl/.mcm_installed
 	mkdir -p gcc-$(GCC_VER)/build
 	test -e gcc-$(GCC_VER)/build/config.status || ( cd gcc-$(GCC_VER)/build && ../configure $(GCC_CONFIG) )
-ifeq ($(shell uname),Darwin)
-	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build/libiberty/config.h
-	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/build/build-i386-apple-darwin$(shell uname -r)/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/build/gcc/auto-host.h
-	echo '#define HAVE_SYS_PARAM_H 1' >> gcc-$(GCC_VER)/build/gcc/auto-host.h
-endif
 	touch $@
 
 gcc-$(GCC_VER)/build/.mcm_built: gcc-$(GCC_VER)/build/.mcm_configured

From a3b756c312dbf3721bb6f81f9dee20a298bcebde Mon Sep 17 00:00:00 2001
From: Christopher Friedt <chris@mmbnetworks.com>
Date: Fri, 29 Apr 2016 12:57:13 -0400
Subject: [PATCH 3/4] remove -lpthread check from gcc-4.2.1 (really only
 necessary for Mac OS X, which does not have a libpthread)

---
 .../gcc-4.2.1/0013-macosx-has-pthreads.diff   | 115 ++++++++++++++++++
 1 file changed, 115 insertions(+)
 create mode 100644 patches/gcc-4.2.1/0013-macosx-has-pthreads.diff

diff --git a/patches/gcc-4.2.1/0013-macosx-has-pthreads.diff b/patches/gcc-4.2.1/0013-macosx-has-pthreads.diff
new file mode 100644
index 0000000..f70192c
--- /dev/null
+++ b/patches/gcc-4.2.1/0013-macosx-has-pthreads.diff
@@ -0,0 +1,115 @@
+diff --git a/libgomp/configure b/libgomp/configure
+index af4254c..eee4673 100755
+--- a/libgomp/configure
++++ b/libgomp/configure
+@@ -8462,110 +8462,6 @@ fi
+ # ----------------- done all checks, emit header -------------
+           ac_config_commands="$ac_config_commands gstdint.h"
+ 
+-
+-
+-
+-# Check to see if -pthread or -lpthread is needed.  Prefer the former.
+-# In case the pthread.h system header is not found, this test will fail.
+-XPCFLAGS=""
+-CFLAGS="$CFLAGS -pthread"
+-cat >conftest.$ac_ext <<_ACEOF
+-/* confdefs.h.  */
+-_ACEOF
+-cat confdefs.h >>conftest.$ac_ext
+-cat >>conftest.$ac_ext <<_ACEOF
+-/* end confdefs.h.  */
+-#include <pthread.h>
+-   void *g(void *d) { return NULL; }
+-int
+-main ()
+-{
+-pthread_t t; pthread_create(&t,NULL,g,NULL);
+-  ;
+-  return 0;
+-}
+-_ACEOF
+-rm -f conftest.$ac_objext conftest$ac_exeext
+-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+-  (eval $ac_link) 2>conftest.er1
+-  ac_status=$?
+-  grep -v '^ *+' conftest.er1 >conftest.err
+-  rm -f conftest.er1
+-  cat conftest.err >&5
+-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+-  (exit $ac_status); } &&
+-	 { ac_try='test -z "$ac_c_werror_flag"
+-			 || test ! -s conftest.err'
+-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+-  (eval $ac_try) 2>&5
+-  ac_status=$?
+-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+-  (exit $ac_status); }; } &&
+-	 { ac_try='test -s conftest$ac_exeext'
+-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+-  (eval $ac_try) 2>&5
+-  ac_status=$?
+-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+-  (exit $ac_status); }; }; then
+-  XPCFLAGS=" -Wc,-pthread"
+-else
+-  echo "$as_me: failed program was:" >&5
+-sed 's/^/| /' conftest.$ac_ext >&5
+-
+-CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
+-  cat >conftest.$ac_ext <<_ACEOF
+-/* confdefs.h.  */
+-_ACEOF
+-cat confdefs.h >>conftest.$ac_ext
+-cat >>conftest.$ac_ext <<_ACEOF
+-/* end confdefs.h.  */
+-#include <pthread.h>
+-     void *g(void *d) { return NULL; }
+-int
+-main ()
+-{
+-pthread_t t; pthread_create(&t,NULL,g,NULL);
+-  ;
+-  return 0;
+-}
+-_ACEOF
+-rm -f conftest.$ac_objext conftest$ac_exeext
+-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+-  (eval $ac_link) 2>conftest.er1
+-  ac_status=$?
+-  grep -v '^ *+' conftest.er1 >conftest.err
+-  rm -f conftest.er1
+-  cat conftest.err >&5
+-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+-  (exit $ac_status); } &&
+-	 { ac_try='test -z "$ac_c_werror_flag"
+-			 || test ! -s conftest.err'
+-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+-  (eval $ac_try) 2>&5
+-  ac_status=$?
+-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+-  (exit $ac_status); }; } &&
+-	 { ac_try='test -s conftest$ac_exeext'
+-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+-  (eval $ac_try) 2>&5
+-  ac_status=$?
+-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+-  (exit $ac_status); }; }; then
+-  :
+-else
+-  echo "$as_me: failed program was:" >&5
+-sed 's/^/| /' conftest.$ac_ext >&5
+-
+-{ { echo "$as_me:$LINENO: error: Pthreads are required to build libgomp" >&5
+-echo "$as_me: error: Pthreads are required to build libgomp" >&2;}
+-   { (exit 1); exit 1; }; }
+-fi
+-rm -f conftest.err conftest.$ac_objext \
+-      conftest$ac_exeext conftest.$ac_ext
+-fi
+-rm -f conftest.err conftest.$ac_objext \
+-      conftest$ac_exeext conftest.$ac_ext
+-
+ # Check for functions needed.
+ 
+ 

From d49ca4bfd71301caef1b52eb7b58544235be52b3 Mon Sep 17 00:00:00 2001
From: Christopher Friedt <chris@mmbnetworks.com>
Date: Fri, 29 Apr 2016 13:46:00 -0400
Subject: [PATCH 4/4] reduced required changes for building on mac to solely
 creating fake empty static libraries with touch (because Apples ar errors out
 when trying to create an empty static library)

---
 Makefile                                      |  21 +---
 .../gcc-4.2.1/0013-macosx-has-pthreads.diff   | 115 ------------------
 ...-x-ar.patch => 00-broken-mac-os-x-ar.diff} |   5 +-
 3 files changed, 3 insertions(+), 138 deletions(-)
 delete mode 100644 patches/gcc-4.2.1/0013-macosx-has-pthreads.diff
 rename patches/musl/{00-broken-mac-os-x-ar.patch => 00-broken-mac-os-x-ar.diff} (73%)

diff --git a/Makefile b/Makefile
index a3f137d..5a47cfd 100644
--- a/Makefile
+++ b/Makefile
@@ -92,19 +92,10 @@ binutils-$(BINUTILS_VER)/.mcm_extracted: $(SOURCES)/binutils-$(BINUTILS_VER).tar
 
 binutils-$(BINUTILS_VER)/.mcm_configured: binutils-$(BINUTILS_VER)/.mcm_extracted
 	test -e binutils-$(BINUTILS_VER)/config.status || ( cd binutils-$(BINUTILS_VER) && ./configure $(BINUTILS_CONFIG) )
-ifeq ($(shell uname),Darwin)
-	echo '#define HAVE_STDLIB_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-	echo '#define HAVE_LIMITS_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-	echo '#define HAVE_STRING_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-	echo '#define HAVE_SYS_TYPES_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-	echo '#define HAVE_SYS_STAT_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-	echo '#define HAVE_UNISTD_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-	echo '#define HAVE_FCNTL_H 1' >> binutils-$(BINUTILS_VER)/libiberty/config.h
-endif
 	touch $@
 
 binutils-$(BINUTILS_VER)/.mcm_built: binutils-$(BINUTILS_VER)/.mcm_configured
-	$(MAKE) -C binutils-$(BINUTILS_VER)
+	cd binutils-$(BINUTILS_VER) && $(MAKE)
 	touch $@
 
 binutils-$(BINUTILS_VER)/.mcm_installed: binutils-$(BINUTILS_VER)/.mcm_built
@@ -118,16 +109,6 @@ gcc-$(GCC_VER)/.mcm_extracted: $(SOURCES)/gcc-$(GCC_VER).tar.bz2 $(SOURCES)/conf
 	tar jxvf $<
 	cat patches/gcc-$(GCC_VER)/* | ( cd gcc-$(GCC_VER) && patch -p1 )
 	cp $(SOURCES)/config.sub gcc-$(GCC_VER)
-ifeq ($(shell uname),Darwin)
-	echo '#define HAVE_STDLIB_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
-	echo '#define HAVE_LIMITS_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
-	echo '#define HAVE_STRING_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
-	echo '#define HAVE_SYS_TYPES_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
-	echo '#define HAVE_SYS_STAT_H 1' >> gcc-$(GCC_VER)/libiberty/config.inø
-	echo '#define HAVE_UNISTD_H 1' >> gcc-$(GCC_VER)/libiberty/config.in
-	echo '#define HAVE_FCNTL_H 1' >> gcc-$(GCC_VER)/gcc/auto-host.h
-	echo '#define HAVE_SYS_PARAM_H 1' >> gcc-$(GCC_VER)/gcc/auto-host.h
-endif
 	touch $@
 
 gcc-$(GCC_VER)/build0/.mcm_configured: gcc-$(GCC_VER)/.mcm_extracted | binutils-$(BINUTILS_VER)/.mcm_installed
diff --git a/patches/gcc-4.2.1/0013-macosx-has-pthreads.diff b/patches/gcc-4.2.1/0013-macosx-has-pthreads.diff
deleted file mode 100644
index f70192c..0000000
--- a/patches/gcc-4.2.1/0013-macosx-has-pthreads.diff
+++ /dev/null
@@ -1,115 +0,0 @@
-diff --git a/libgomp/configure b/libgomp/configure
-index af4254c..eee4673 100755
---- a/libgomp/configure
-+++ b/libgomp/configure
-@@ -8462,110 +8462,6 @@ fi
- # ----------------- done all checks, emit header -------------
-           ac_config_commands="$ac_config_commands gstdint.h"
- 
--
--
--
--# Check to see if -pthread or -lpthread is needed.  Prefer the former.
--# In case the pthread.h system header is not found, this test will fail.
--XPCFLAGS=""
--CFLAGS="$CFLAGS -pthread"
--cat >conftest.$ac_ext <<_ACEOF
--/* confdefs.h.  */
--_ACEOF
--cat confdefs.h >>conftest.$ac_ext
--cat >>conftest.$ac_ext <<_ACEOF
--/* end confdefs.h.  */
--#include <pthread.h>
--   void *g(void *d) { return NULL; }
--int
--main ()
--{
--pthread_t t; pthread_create(&t,NULL,g,NULL);
--  ;
--  return 0;
--}
--_ACEOF
--rm -f conftest.$ac_objext conftest$ac_exeext
--if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
--  (eval $ac_link) 2>conftest.er1
--  ac_status=$?
--  grep -v '^ *+' conftest.er1 >conftest.err
--  rm -f conftest.er1
--  cat conftest.err >&5
--  echo "$as_me:$LINENO: \$? = $ac_status" >&5
--  (exit $ac_status); } &&
--	 { ac_try='test -z "$ac_c_werror_flag"
--			 || test ! -s conftest.err'
--  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
--  (eval $ac_try) 2>&5
--  ac_status=$?
--  echo "$as_me:$LINENO: \$? = $ac_status" >&5
--  (exit $ac_status); }; } &&
--	 { ac_try='test -s conftest$ac_exeext'
--  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
--  (eval $ac_try) 2>&5
--  ac_status=$?
--  echo "$as_me:$LINENO: \$? = $ac_status" >&5
--  (exit $ac_status); }; }; then
--  XPCFLAGS=" -Wc,-pthread"
--else
--  echo "$as_me: failed program was:" >&5
--sed 's/^/| /' conftest.$ac_ext >&5
--
--CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
--  cat >conftest.$ac_ext <<_ACEOF
--/* confdefs.h.  */
--_ACEOF
--cat confdefs.h >>conftest.$ac_ext
--cat >>conftest.$ac_ext <<_ACEOF
--/* end confdefs.h.  */
--#include <pthread.h>
--     void *g(void *d) { return NULL; }
--int
--main ()
--{
--pthread_t t; pthread_create(&t,NULL,g,NULL);
--  ;
--  return 0;
--}
--_ACEOF
--rm -f conftest.$ac_objext conftest$ac_exeext
--if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
--  (eval $ac_link) 2>conftest.er1
--  ac_status=$?
--  grep -v '^ *+' conftest.er1 >conftest.err
--  rm -f conftest.er1
--  cat conftest.err >&5
--  echo "$as_me:$LINENO: \$? = $ac_status" >&5
--  (exit $ac_status); } &&
--	 { ac_try='test -z "$ac_c_werror_flag"
--			 || test ! -s conftest.err'
--  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
--  (eval $ac_try) 2>&5
--  ac_status=$?
--  echo "$as_me:$LINENO: \$? = $ac_status" >&5
--  (exit $ac_status); }; } &&
--	 { ac_try='test -s conftest$ac_exeext'
--  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
--  (eval $ac_try) 2>&5
--  ac_status=$?
--  echo "$as_me:$LINENO: \$? = $ac_status" >&5
--  (exit $ac_status); }; }; then
--  :
--else
--  echo "$as_me: failed program was:" >&5
--sed 's/^/| /' conftest.$ac_ext >&5
--
--{ { echo "$as_me:$LINENO: error: Pthreads are required to build libgomp" >&5
--echo "$as_me: error: Pthreads are required to build libgomp" >&2;}
--   { (exit 1); exit 1; }; }
--fi
--rm -f conftest.err conftest.$ac_objext \
--      conftest$ac_exeext conftest.$ac_ext
--fi
--rm -f conftest.err conftest.$ac_objext \
--      conftest$ac_exeext conftest.$ac_ext
--
- # Check for functions needed.
- 
- 
diff --git a/patches/musl/00-broken-mac-os-x-ar.patch b/patches/musl/00-broken-mac-os-x-ar.diff
similarity index 73%
rename from patches/musl/00-broken-mac-os-x-ar.patch
rename to patches/musl/00-broken-mac-os-x-ar.diff
index ce27316..f2d08f0 100644
--- a/patches/musl/00-broken-mac-os-x-ar.patch
+++ b/patches/musl/00-broken-mac-os-x-ar.diff
@@ -2,13 +2,12 @@ diff --git a/Makefile b/Makefile
 index ec54880..b048cbd 100644
 --- a/Makefile
 +++ b/Makefile
-@@ -170,7 +170,12 @@ lib/libc.a: $(AOBJS)
+@@ -170,7 +170,11 @@ lib/libc.a: $(AOBJS)
  
  $(EMPTY_LIBS):
  	rm -f $@
 +ifeq ($(shell uname),Darwin)
-+	touch .empty.o
-+	$(AR) rc $@ .empty.o
++	touch $@
 +else
  	$(AR) rc $@
 +endif