diff --git pyobjc_setup.py pyobjc_setup.py --- pyobjc_setup.py +++ pyobjc_setup.py @@ -207,14 +207,28 @@ def get_os_level(): v = pl['ProductVersion'] return '.'.join(v.split('.')[:2]) +def get_sdk(): + env_cflags = os.environ.get('CFLAGS', '') + config_cflags = get_config_var('CFLAGS') + sdk = None + for cflags_str in [env_cflags, config_cflags]: + cflags = shlex.split(cflags_str) + for i, val in enumerate(cflags): + if val == '-isysroot': + sdk = cflags[i+1] + break + elif val.find('-isysroot') == 0: + sdk = val[len('-isysroot'):] + break + if sdk: + break + + return sdk + def get_sdk_level(): - cflags = get_config_var('CFLAGS') - cflags = shlex.split(cflags) - for i, val in enumerate(cflags): - if val == '-isysroot': - sdk = cflags[i+1] - break - else: + sdk = get_sdk() + + if not sdk: return None if sdk == '/': @@ -223,7 +237,13 @@ def get_sdk_level(): sdk = os.path.basename(sdk) assert sdk.startswith('MacOSX') assert sdk.endswith('.sdk') - return sdk[6:-4] + sdk = sdk[6:-4] + if sdk == '': + return get_os_level() + elif '.' not in sdk: + return sdk + '.0' + else: + return sdk class pyobjc_install_lib (install_lib.install_lib): def get_exclusions(self): @@ -396,10 +416,10 @@ def Extension(*args, **kwds): if 'clang' in get_config_var('CC'): cflags.append('-Wno-deprecated-declarations') - CFLAGS = get_config_var('CFLAGS') - if '-isysroot' not in CFLAGS: # and os.path.exists('/usr/include/stdio.h'): - # We're likely on a system with de Xcode Command Line Tools. - # Explicitly use the most recent problems to avoid compile problems. + sdk = get_sdk() + if not sdk: # and os.path.exists('/usr/include/stdio.h'): + # We're likely on a system with the Xcode Command Line Tools. + # Explicitly use the most recent SDK to avoid compile problems. data = os.popen('/usr/bin/xcrun -sdk macosx --show-sdk-path').read() data = data.strip() if data: