From b00423aa4195fc140328219d36b12cee4d24e17f 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 25/30] cross compile darwin

By Isuru Fernando.
---
 Lib/platform.py | 7 ++++++-
 configure       | 8 ++++++--
 setup.py        | 2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index a8e2400a15..f13bc8cbe0 100755
--- a/configure	2022-03-21 11:00:52.813037750 +0300
+++ b/configure	2022-03-21 11:01:04.145251523 +0300
@@ -3354,6 +3354,8 @@
 $as_echo "\"$MACHDEP\"" >&6; }
 
 
+if test -z "${_PYTHON_HOST_PLATFORM}"
+then
 if test "$cross_compiling" = yes; then
 	case "$host" in
 	*-*-linux*)
@@ -3378,6 +3380,7 @@
 	esac
 	_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
 fi
+fi
 
 # Some systems cannot stand _XOPEN_SOURCE being defined at all; they
 # disable features if it is defined, without any means to access these
@@ -6238,7 +6241,7 @@
 if test "$cross_compiling" = yes; then
     case "$READELF" in
 	readelf|:)
-	as_fn_error $? "readelf for the host is required for cross builds" "$LINENO" 5
+	#as_fn_error $? "readelf for the host is required for cross builds" "$LINENO" 5
 	;;
     esac
 fi
@@ -9389,7 +9392,7 @@
   conftest.$ac_objext conftest.beam conftest.$ac_ext
 fi
 
-
+    if test -z "${MACOSX_DEFAULT_ARCH}"; then
     if test "${ac_osx_32bit}" = "yes"; then
     	case `/usr/bin/arch` in
     	i386)
@@ -9419,6 +9422,7 @@
     	esac
 
     fi
+    fi
 
     LIBTOOL_CRUFT=$LIBTOOL_CRUFT" -lSystem -lSystemStubs -arch_only ${MACOSX_DEFAULT_ARCH}"
     LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
diff --git a/Lib/platform.py b/Lib/platform.py
index e9f50ab622..408587d36c 100755
--- a/Lib/platform.py	2022-03-21 11:00:52.813037750 +0300
+++ b/Lib/platform.py	2022-03-21 11:01:04.145251523 +0300
@@ -411,7 +411,12 @@
 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/setup.py b/setup.py
index f2769081e8..a95162b43a 100644
--- a/setup.py	2022-03-21 11:00:52.813037750 +0300
+++ b/setup.py	2022-03-21 11:01:04.149251599 +0300
@@ -62,7 +62,7 @@
 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)
 CC = os.environ.get("CC")
