From 773114220ddac23364e836d0f217d1cd185d7d26 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Fri, 2 Oct 2020 00:03:12 +0200
Subject: [PATCH 15/25] cross compile darwin

By Isuru Fernando.
---
 Lib/platform.py | 7 ++++++-
 configure       | 5 ++++-
 configure.ac    | 5 ++++-
 setup.py        | 6 +++---
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/Lib/platform.py b/Lib/platform.py
index 9b9d88bf58..9b2807d61f 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -414,7 +414,12 @@ def win32_ver(release='', version='', csd='', ptype=''):
 def _mac_ver_xml():
     fn = '/System/Library/CoreServices/SystemVersion.plist'
     if not os.path.exists(fn):
-        return None
+        if 'SDKROOT' in os.environ:
+            fn = os.environ['SDKROOT'] + fn
+            if not os.path.exists(fn):
+                return None
+        else:
+            return None
 
     try:
         import plistlib
diff --git a/configure b/configure
index af4a5bbfdf..839d73be58 100755
--- a/configure
+++ b/configure
@@ -3876,6 +3876,9 @@ if test "$cross_compiling" = yes; then
 			_host_cpu=$host_cpu
 		esac
 		;;
+	*-*-darwin*)
+		_host_cpu=$host_cpu
+		;;
 	*-*-cygwin*)
 		_host_cpu=
 		;;
@@ -7209,7 +7212,7 @@ esac
   fi
 fi
 
-if test "$cross_compiling" = yes; then
+if test "$cross_compiling" = yes -a "$ac_sys_system" != "Darwin"; then
     case "$READELF" in
 	readelf|:)
 	as_fn_error $? "readelf for the host is required for cross builds" "$LINENO" 5
diff --git a/configure.ac b/configure.ac
index e1cbb7c7fb..8a3ef67c46 100644
--- a/configure.ac
+++ b/configure.ac
@@ -597,6 +597,9 @@ if test "$cross_compiling" = yes; then
 			_host_cpu=$host_cpu
 		esac
 		;;
+	*-*-darwin*)
+		_host_cpu=$host_cpu
+		;;
 	*-*-cygwin*)
 		_host_cpu=
 		;;
@@ -1626,7 +1629,7 @@ then
 fi
 
 AC_CHECK_TOOLS([READELF], [readelf], [:])
-if test "$cross_compiling" = yes; then
+if test "$cross_compiling" = yes -a "$ac_sys_system" != "Darwin"; then
     case "$READELF" in
 	readelf|:)
 	AC_MSG_ERROR([readelf for the host is required for cross builds])
diff --git a/setup.py b/setup.py
index 95ee953e0e..3288fea376 100644
--- a/setup.py
+++ b/setup.py
@@ -81,7 +81,7 @@ def get_platform():
 HOST_PLATFORM = get_platform()
 MS_WINDOWS = (HOST_PLATFORM == 'win32')
 CYGWIN = (HOST_PLATFORM == 'cygwin')
-MACOS = (HOST_PLATFORM == 'darwin')
+MACOS = (HOST_PLATFORM.startswith('darwin'))
 AIX = (HOST_PLATFORM.startswith('aix'))
 VXWORKS = ('vxworks' in HOST_PLATFORM)
 EMSCRIPTEN = HOST_PLATFORM == 'emscripten-wasm32'
@@ -1070,11 +1070,11 @@ def detect_readline_curses(self):
                 readline_lib = 'readline'
             do_readline = self.compiler.find_library_file(self.lib_dirs,
                 readline_lib)
-            if CROSS_COMPILING:
+            if CROSS_COMPILING and not MACOS:
                 ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
                                 % (sysconfig.get_config_var('READELF'),
                                    do_readline, tmpfile))
-            elif find_executable('ldd'):
+            elif find_executable('ldd') and not MACOS:
                 ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
             else:
                 ret = 1
