Fix darwin/ios build issues
[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
9 Import('env')
10
11 target_arch = env.get('TARGET_ARCH')
12 target_os = env.get('TARGET_OS')
13
14 tc_path=commands.getoutput('xcode-select -p')
15
16
17 # SYS_VERSION build option
18 help_vars = Variables()
19 help_vars.Add('SYS_VERSION', 'MAC OS X version / IOS version', os.environ.get('SYS_VERSION'))
20 help_vars.Update(env)
21 Help(help_vars.GenerateHelpText(env))
22
23 sys_version = env.get('SYS_VERSION')
24
25 if sys_version is None:
26         print '''
27 *********************************** Error *************************************
28 *   MAC OSX/IOS version isn't set, please set it in command line as :         *
29 *      # scons TARGET_ARCH=<arch> TARGET_OS=<os> SYS_VERSION=<version> ...    *
30 *   To get the version, please see:                                                               *
31 * /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/   *
32 * /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ *
33 *   <arch> is 'armv7','armv7s','arm64','i386', 'x86_64'
34 *   <os> is 'darwin','ios'
35 *******************************************************************************
36 '''
37         Exit(1)
38
39 # Set release/debug flags
40 if env.get('RELEASE'):
41         env.AppendUnique(CCFLAGS = ['-Os'])
42         env.AppendUnique(CPPDEFINES = ['NDEBUG'])
43 else:
44         env.AppendUnique(CCFLAGS = ['-g'])
45         env.AppendUnique(LINKFLAGS = ['-g'])
46
47 if target_os == 'darwin':
48         sys_root = tc_path + '/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + sys_version + '.sdk/'
49 else:
50         if target_arch in ['i386', 'x86_64']:
51                 sys_root = tc_path + '/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator' + sys_version + '.sdk/'
52         else:
53                 sys_root = tc_path + '/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS' + sys_version + '.sdk/'
54
55 # Set arch flags
56 env.AppendUnique(CCFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
57 env.AppendUnique(LINKFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
58
59 if target_os == 'darwin':
60         flag = '-mmacosx-version-min=' + sys_version
61         env.AppendUnique(CCFLAGS = [flag])
62         env.AppendUnique(LINKFLAGS = [flag])