From 2e4189f3087ad3a0e350c69d165a5c2bbdc6b8f4 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Sun, 20 Aug 2017 00:22:22 +0100
Subject: [PATCH 10/22] Darwin: Look in ${sysroot}/usr/{lib,include} if sysroot
 is set

---
 setup.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index bf90600eaa..21b393a441 100644
--- a/setup.py
+++ b/setup.py
@@ -643,7 +643,13 @@ class PyBuildExt(build_ext):
         # lib_dirs and inc_dirs are used to search for files;
         # if a file is found in one of those directories, it can
         # be assumed that no additional -I,-L directives are needed.
-        if not cross_compiling:
+        # If we are using a macosx sysroot then ensure we look in
+        # sysroot/usr/{lib,include} (irrespective of whether we consider
+        # this cross_compiling or not).
+        if macosx_sdk_root() != '/':
+            lib_dirs = self.compiler.library_dirs + ['/usr/lib']
+            inc_dirs = self.compiler.include_dirs + ['/usr/include']
+        elif not cross_compiling:
             lib_dirs = self.compiler.library_dirs + system_lib_dirs
             inc_dirs = self.compiler.include_dirs + system_include_dirs
         else:
-- 
2.23.0

