From b6d9c94d3bb9e992b6130de378bb5700316adb74 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Tue, 6 Aug 2019 01:33:18 +0200
Subject: [PATCH 22/24] macOS: Allow SDK dir suffixes (e.g. /usr/include) into
 the result of add_dir_to_list()

---
 setup.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index eb7a6b14c8..c353369fe5 100644
--- a/setup.py
+++ b/setup.py
@@ -38,15 +38,23 @@ disabled_module_list = []
 def add_dir_to_list(dirlist, dir):
     """Add the directory 'dir' to the list 'dirlist' (at the front) if
     1) 'dir' is not already in 'dirlist'
-    2) 'dir' actually exists, and is a directory."""
+    2) 'dir' actually exists, and is a directory.
+    3) 'dir' is suffix for a macOS SDK directory (e.g. /usr/include) and
+        our host_platform is 'darwin' and appending macosx_sdk_root() to
+        dir[1:] (i.e. skipping the '/') is a directory. """
     if dir is not None and os.path.isdir(dir) and dir not in dirlist:
         dirlist.insert(0, dir)
+    if (dir is not None and host_platform == 'darwin' and
+       os.path.isdir(os.path.join(macosx_sdk_root(), dir[1:]))):
+        dirlist.insert(0, dir)
 
 def macosx_sdk_root():
     """
     Return the directory of the current OSX SDK,
     or '/' if no SDK was specified.
     """
+    if 'CONDA_BUILD_SYSROOT' in os.environ:
+        return os.environ['CONDA_BUILD_SYSROOT']
     cflags = sysconfig.get_config_var('CFLAGS')
     m = re.search(r'-isysroot\s+(\S+)', cflags)
     if m is None:
-- 
2.23.0

