Index: setup.py =================================================================== --- setup.py (revision 80172) +++ setup.py (working copy) @@ -40,15 +40,29 @@ 'paths' is a list of additional locations to check; if the file is found in one of them, the resulting list will contain the directory. """ + if sys.platform == 'darwin': + # Try to honor any specified SDK roots on MacOSX + cflags = sysconfig.get_config_var('CFLAGS') + m = re.search(r'-isysroot\s+(\S+)', cflags) + if m is None: + sysroot = '/' + else: + sysroot = m.group(1) # Check the standard locations for dir in std_dirs: - f = os.path.join(dir, filename) + if sys.platform == 'darwin' and dir.startswith('/System') or dir.startswith('/usr'): + f = os.path.join(sysroot, dir[1:], filename) + else: + f = os.path.join(dir, filename) if os.path.exists(f): return [] # Check the additional directories for dir in paths: - f = os.path.join(dir, filename) + if sys.platform == 'darwin' and dir.startswith('/System') or dir.startswith('/usr'): + f = os.path.join(sysroot, dir[1:], filename) + else: + f = os.path.join(dir, filename) if os.path.exists(f): return [dir] @@ -60,11 +74,25 @@ if result is None: return None + if sys.platform == 'darwin': + # Try to honor any specified SDK roots on MacOSX + cflags = sysconfig.get_config_var('CFLAGS') + m = re.search(r'-isysroot\s+(\S+)', cflags) + if m is None: + sysroot = '/' + else: + sysroot = m.group(1) + # Check whether the found file is in one of the standard directories dirname = os.path.dirname(result) for p in std_dirs: # Ensure path doesn't end with path separator p = p.rstrip(os.sep) + + if sys.platform == 'darwin': + if os.path.join(sysroot, p[1:]) == dirname: + return [ ] + if p == dirname: return [ ] @@ -73,6 +101,11 @@ for p in paths: # Ensure path doesn't end with path separator p = p.rstrip(os.sep) + + if sys.platform == 'darwin': + if os.path.join(sysroot, p[1:]) == dirname: + return [ p ] + if p == dirname: return [p] else: @@ -641,22 +674,26 @@ openssl_ver = 0 openssl_ver_re = re.compile( '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' ) - for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in: - name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h') - if os.path.isfile(name): + opensslv_h = find_file('openssl/opensslv.h', inc_dirs, search_for_ssl_incs_in) + if opensslv_h: + #for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in: + #name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h') + #if os.path.isfile(name): + if 1: + name = opensslv_h[0] try: incfile = open(name, 'r') for line in incfile: m = openssl_ver_re.match(line) if m: openssl_ver = eval(m.group(1)) - break + #break except IOError: pass # first version found is what we'll use (as the compiler should) - if openssl_ver: - break + #if openssl_ver: + #break #print 'openssl_ver = 0x%08x' % openssl_ver min_openssl_ver = 0x00907000 Index: Lib/distutils/unixccompiler.py =================================================================== --- Lib/distutils/unixccompiler.py (revision 80172) +++ Lib/distutils/unixccompiler.py (working copy) @@ -15,7 +15,7 @@ __revision__ = "$Id$" -import os, sys +import os, sys, re from types import StringType, NoneType from distutils import sysconfig @@ -305,10 +305,30 @@ dylib_f = self.library_filename(lib, lib_type='dylib') static_f = self.library_filename(lib, lib_type='static') + if sys.platform == 'darwin': + # On OSX users can specify an alternate SDK using + # '-isysroot', calculate the SDK root if it is specified + # (and use it further on) + cflags = sysconfig.get_config_var('CFLAGS') + m = re.search(r'-isysroot\s+(\S+)', cflags) + if m is None: + sysroot = '/' + else: + sysroot = m.group(1) + + + for dir in dirs: - shared = os.path.join(dir, shared_f) - dylib = os.path.join(dir, dylib_f) - static = os.path.join(dir, static_f) + if sys.platform == 'darwin' and dir.startswith('/System/') or dir.startswith('/usr/'): + shared = os.path.join(sysroot, dir[1:], shared_f) + dylib = os.path.join(sysroot, dir[1:], dylib_f) + static = os.path.join(sysroot, dir[1:], static_f) + + else: + shared = os.path.join(dir, shared_f) + dylib = os.path.join(dir, dylib_f) + static = os.path.join(dir, static_f) + # We're second-guessing the linker here, with not much hard # data to go on: GCC seems to prefer the shared library, so I'm # assuming that *all* Unix C compilers do. And of course I'm