+# -*- mode: python; python-indent-offset: 4; indent-tabs-mode: nil -*-
##
# This script set darwin specific flags (GNU GCC)
#
##
+import os
import platform
+import subprocess
+from distutils.version import StrictVersion
-Import('env', 'RELEASE_BUILD', 'BUILD_TARGET', 'TARGET_CPU_ARCH', 'SYS_VERSION')
+Import('env')
-if SYS_VERSION is None:
- print '''
-*********************************** Error *************************************
-* MAC OSX/IOS version isn't set, please set it in command line as : *
-* # scons SYS_VERSION=<version> ... *
-* To get the version, please see: *
-* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ *
-* /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ *
-*******************************************************************************
-'''
- Exit(1)
+target_arch = env.get('TARGET_ARCH')
+target_os = env.get('TARGET_OS')
+
+tc_path=subprocess.getoutput('xcode-select -p')
+
+tc_sdks=subprocess.getoutput('xcodebuild -showsdks')
+
+#Find the SDK's that are installed
+sdks=[]
+for line in tc_sdks.split('\n'):
+ if (line == ''):
+ bIn=False
+ if (line[:10] == 'OS X SDKs:'):
+ bIn=(target_os == 'darwin')
+ elif (line[:9] == 'iOS SDKs:'):
+ bIn=(target_os == 'ios')
+ elif bIn:
+ sdks.append(line[:14].strip())
+
+#find the latest
+maxsdk='0.0'
+if len(sdks) > 0:
+ for sdk in sdks:
+ p = sdk.rsplit(' ',1)[1]
+ if (StrictVersion(p)) > StrictVersion(maxsdk):
+ maxsdk=p
+
+# SYS_VERSION build option
+help_vars = Variables()
+help_vars.Add('SYS_VERSION', 'MAC OS X SDK version / IOS SDK version', os.environ.get('SYS_VERSION'))
+help_vars.Update(env)
+Help(help_vars.GenerateHelpText(env))
+
+sys_version = env.get('SYS_VERSION')
+
+#if they didn't explictly set it use the auto-detected one
+if sys_version is None:
+ sys_version=maxsdk
+
+env['SYS_VERSION']=sys_version
# Set release/debug flags
-if RELEASE_BUILD:
- env.AppendUnique(CFLAGS = ['-Os'])
- env.AppendUnique(CXXFLAGS = ['-Os'])
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
- env.AppendUnique(CFLAGS = ['-g'])
- env.AppendUnique(CXXFLAGS = ['-g'])
+ env.AppendUnique(CCFLAGS = ['-g'])
+ env.AppendUnique(LINKFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-if BUILD_TARGET == 'darwin':
- SYS_ROOT = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + SYS_VERSION + '.sdk/'
+if target_os == 'darwin':
+ sys_root = tc_path + '/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + sys_version + '.sdk/'
else:
- if TARGET_CPU_ARCH in ['i386', 'x86_64']:
- SYS_ROOT = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator' + SYS_VERSION + '.sdk/'
+ if target_arch in ['i386', 'x86_64']:
+ sys_root = tc_path + '/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator' + sys_version + '.sdk/'
else:
- SYS_ROOT = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS' + SYS_VERSION + '.sdk/'
+ sys_root = tc_path + '/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS' + sys_version + '.sdk/'
# Set arch flags
-env.AppendUnique(CXXFLAGS = ['-arch', TARGET_CPU_ARCH, '-isysroot', SYS_ROOT])
-env.AppendUnique(CCFLAGS = ['-arch', TARGET_CPU_ARCH, '-isysroot', SYS_ROOT])
-env.AppendUnique(LINKFLAGS = ['-arch', TARGET_CPU_ARCH, '-isysroot', SYS_ROOT])
+env.AppendUnique(CCFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
+env.AppendUnique(LINKFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
-if BUILD_TARGET == 'darwin':
- flag = '-mmacosx-version-min=' + SYS_VERSION
- env.AppendUnique(CXXFLAGS = [flag])
+if target_os == 'darwin':
+ flag = '-mmacosx-version-min=' + sys_version
env.AppendUnique(CCFLAGS = [flag])
- env.AppendUnique(LINKFLAGS = [flag])
\ No newline at end of file
+ env.AppendUnique(LINKFLAGS = [flag])