Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / build_common / darwin / SConscript
1 ##
2 # This script set darwin specific flags (GNU GCC)
3 #
4 ##
5 import os
6 import platform
7 import commands
8 from distutils.version import StrictVersion
9
10 Import('env')
11
12 target_arch = env.get('TARGET_ARCH')
13 target_os = env.get('TARGET_OS')
14
15 tc_path=commands.getoutput('xcode-select -p')
16
17 tc_sdks=commands.getoutput('xcodebuild -showsdks')
18
19 #Find the SDK's that are installed
20 sdks=[]
21 for line in tc_sdks.split('\n'):
22     if (line == ''):
23         bIn=False
24     if (line[:10] == 'OS X SDKs:'):
25         bIn=(target_os == 'darwin')
26     elif (line[:9] == 'iOS SDKs:'):
27         bIn=(target_os == 'ios')
28     elif bIn:
29         sdks.append(line[:14].strip())
30
31 #find the latest
32 maxsdk='0.0'
33 if len(sdks) > 0:
34     for sdk in sdks:
35         p = sdk.rsplit(' ',1)[1]
36         if (StrictVersion(p)) > StrictVersion(maxsdk):
37             maxsdk=p
38
39 # SYS_VERSION build option
40 help_vars = Variables()
41 help_vars.Add('SYS_VERSION', 'MAC OS X SDK version / IOS SDK version', os.environ.get('SYS_VERSION'))
42 help_vars.Update(env)
43 Help(help_vars.GenerateHelpText(env))
44
45 sys_version = env.get('SYS_VERSION')
46
47 #if they didn't explictly set it use the auto-detected one
48 if sys_version is None:
49     sys_version=maxsdk
50
51 env['SYS_VERSION']=sys_version
52
53 # Set release/debug flags
54 if env.get('RELEASE'):
55         env.AppendUnique(CCFLAGS = ['-Os'])
56         env.AppendUnique(CPPDEFINES = ['NDEBUG'])
57 else:
58         env.AppendUnique(CCFLAGS = ['-g'])
59         env.AppendUnique(LINKFLAGS = ['-g'])
60
61 if env.get('LOGGING'):
62     env.AppendUnique(CPPDEFINES = ['-DTB_LOG'])
63
64 if target_os == 'darwin':
65         sys_root = tc_path + '/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + sys_version + '.sdk/'
66 else:
67         if target_arch in ['i386', 'x86_64']:
68                 sys_root = tc_path + '/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator' + sys_version + '.sdk/'
69         else:
70                 sys_root = tc_path + '/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS' + sys_version + '.sdk/'
71
72 # Set arch flags
73 env.AppendUnique(CCFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
74 env.AppendUnique(LINKFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
75
76 if target_os == 'darwin':
77         flag = '-mmacosx-version-min=' + sys_version
78         env.AppendUnique(CCFLAGS = [flag])
79         env.AppendUnique(LINKFLAGS = [flag])