@@ -257,6 +257,41 @@ index bf0d4333f9..8a4ba3666a 100644
257257 def test_check_environ(self):
258258 util._environ_checked = 0
259259 os.environ.pop('HOME', None)
260+ diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
261+ index d00c48981e..5d12b4779d 100644
262+ --- a/Lib/distutils/unixccompiler.py
263+ +++ b/Lib/distutils/unixccompiler.py
264+ @@ -270,9 +270,9 @@
265+ static_f = self.library_filename(lib, lib_type='static')
266+
267+ if sys.platform == 'darwin':
268+ - # On OSX users can specify an alternate SDK using
269+ - # '-isysroot', calculate the SDK root if it is specified
270+ - # (and use it further on)
271+ + # On macOS users can specify an alternate SDK using
272+ + # '-isysroot <path>' or --sysroot=<path>, calculate the SDK root
273+ + # if it is specified (and use it further on)
274+ #
275+ # Note that, as of Xcode 7, Apple SDKs may contain textual stub
276+ # libraries with .tbd extensions rather than the normal .dylib
277+ @@ -291,12 +291,14 @@
278+ cflags = sysconfig.get_config_var('CFLAGS')
279+ m = re.search(r'-isysroot\s*(\S+)', cflags)
280+ if m is None:
281+ - sysroot = _osx_support._default_sysroot(sysconfig.get_config_var('CC'))
282+ + m = re.search(r'--sysroot=(\S+)', cflags)
283+ + if m is None:
284+ + sysroot = _osx_support._default_sysroot(sysconfig.get_config_var('CC'))
285+ + else:
286+ + sysroot = m.group(1)
287+ else:
288+ sysroot = m.group(1)
289+
290+ -
291+ -
292+ for dir in dirs:
293+ shared = os.path.join(dir, shared_f)
294+ dylib = os.path.join(dir, dylib_f)
260295diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
261296index f3828b10e1..7e86539bfa 100644
262297--- a/Lib/importlib/_bootstrap_external.py
@@ -3429,7 +3464,7 @@ index aa515da465..81f956f3d2 100644
34293464 # Check for use of the system libmpdec library
34303465 AC_MSG_CHECKING(for --with-system-libmpdec)
34313466diff --git a/setup.py b/setup.py
3432- index 0bec170d3f..4e64c30d26 100644
3467+ index 0bec170d3f..284eee3f51 100644
34333468--- a/setup.py
34343469+++ b/setup.py
34353470@@ -63,6 +63,9 @@
@@ -3442,7 +3477,38 @@ index 0bec170d3f..4e64c30d26 100644
34423477 AIX = (HOST_PLATFORM.startswith('aix'))
34433478 VXWORKS = ('vxworks' in HOST_PLATFORM)
34443479 CC = os.environ.get("CC")
3445- @@ -2122,6 +2125,11 @@
3480+ @@ -142,16 +145,20 @@
3481+ for var_name in make_vars:
3482+ var = sysconfig.get_config_var(var_name)
3483+ if var is not None:
3484+ - m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
3485+ - if m is not None:
3486+ - sysroot = m.group(1).strip('"')
3487+ - for subdir in subdirs:
3488+ - if os.path.isabs(subdir):
3489+ - subdir = subdir[1:]
3490+ - path = os.path.join(sysroot, subdir)
3491+ - if os.path.isdir(path):
3492+ - dirs.append(path)
3493+ - break
3494+ + for pattern in [
3495+ + r'-isysroot\s*([^"]\S*|"[^"]+")',
3496+ + r'--sysroot=([^"]\S*|"[^"]+")',
3497+ + ]:
3498+ + m = re.search(pattern, var)
3499+ + if m is not None:
3500+ + sysroot = m.group(1).strip('"')
3501+ + for subdir in subdirs:
3502+ + if os.path.isabs(subdir):
3503+ + subdir = subdir[1:]
3504+ + path = os.path.join(sysroot, subdir)
3505+ + if os.path.isdir(path):
3506+ + dirs.append(path)
3507+ + break
3508+ return dirs
3509+
3510+
3511+ @@ -2122,6 +2129,11 @@
34463512 extra_compile_args.append('-DMACOSX')
34473513 include_dirs.append('_ctypes/darwin')
34483514
@@ -3454,7 +3520,7 @@ index 0bec170d3f..4e64c30d26 100644
34543520 elif HOST_PLATFORM == 'sunos5':
34553521 # XXX This shouldn't be necessary; it appears that some
34563522 # of the assembler code is non-PIC (i.e. it has relocations
3457- @@ -2151,7 +2159 ,8 @@
3523+ @@ -2151,7 +2163 ,8 @@
34583524 libraries=['m']))
34593525
34603526 ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
@@ -3464,15 +3530,15 @@ index 0bec170d3f..4e64c30d26 100644
34643530
34653531 ffi_inc_dirs = self.inc_dirs.copy()
34663532 if MACOS:
3467- @@ -2180,6 +2189 ,7 @@
3533+ @@ -2180,6 +2193 ,7 @@
34683534 for lib_name in ('ffi', 'ffi_pic'):
34693535 if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
34703536 ffi_lib = lib_name
34713537+ self.use_system_libffi = True
34723538 break
34733539
34743540 if ffi_inc and ffi_lib:
3475- @@ -2193,7 +2203 ,8 @@
3541+ @@ -2193,7 +2207 ,8 @@
34763542
34773543 ext.include_dirs.append(ffi_inc)
34783544 ext.libraries.append(ffi_lib)
0 commit comments