Merge branch 'master' into cloud-interface
[platform/upstream/iotivity.git] / service / easy-setup / sampleapp / enrollee / tizen-sdb / EnrolleeSample / SConscript
1 ##########################################################################
2 #
3 # Copyright 2015 Samsung Electronics All Rights Reserved.
4 #
5 #
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 ##########################################################################
20
21 ##
22 # This script includes generic build options:
23 #    release/debug, target os, target arch, cross toolchain, build environment etc
24 ##
25 import os
26 import platform
27
28 print "Inside the Config SConscript"
29 # Map of host os and allowed target os (host: allowed target os)
30 host_target_map = {
31         'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
32         'windows': ['windows', 'winrt', 'android', 'arduino', 'tizen'],
33         'darwin': ['darwin', 'ios', 'android', 'arduino'],
34         }
35
36 # Map of os and allowed archs (os: allowed archs)
37 os_arch_map = {
38         'linux': ['x86', 'x86_64', 'arm', 'arm64'],
39         'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
40         'windows': ['x86', 'amd64', 'arm'],
41         'winrt': ['arm'],
42         'darwin': ['i386', 'x86_64'],
43         'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
44         'arduino': ['avr', 'arm'],
45                 'yocto': ['x86', 'x86_64'],
46         'tizen': ['armv7'],
47         }
48
49 host = platform.system().lower()
50
51 if not host_target_map.has_key(host):
52     print "\nError: Current system (%s) isn't supported\n" % host
53     Exit(1)
54
55 ######################################################################
56 # Get build options (the optins from command line)
57 ######################################################################
58 target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
59
60 if target_os not in host_target_map[host]:
61     print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
62     Exit(1)
63
64 default_arch = platform.machine()
65 if default_arch not in os_arch_map[target_os]:
66     default_arch = os_arch_map[target_os][0].lower()
67
68 target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
69
70 ######################################################################
71 # Common build options (release, target os, target arch)
72 ######################################################################
73 help_vars = Variables()
74 help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
75 help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
76 help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'IP', 'BT', 'BLE']))
77 help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
78 help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
79 help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP')))
80
81 ######################################################################
82 # Platform(build target) specific options: SDK/NDK & toolchain
83 ######################################################################
84 targets_support_cc = ['tizen']
85
86 if target_os in targets_support_cc:
87     # Set cross compile toolchain
88     help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
89     help_vars.Add(PathVariable('TC_PATH',
90             'Toolchain path (Generally only be required for cross-compiling)',
91             os.environ.get('TC_PATH')))
92
93 if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
94     env = Environment(variables = help_vars,
95             tools = ['gnulink', 'gcc', 'g++', 'ar', 'as']
96             )
97 else:
98     env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
99
100 Help(help_vars.GenerateHelpText(env))
101
102 tc_set_msg = '''
103 ************************************ Warning **********************************
104 *   Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
105 * toolchain, if it isn't what you expect you should unset it, otherwise it may*
106 * cause inexplicable errors.                                                  *
107 *******************************************************************************
108 '''
109
110 if target_os in targets_support_cc:
111     prefix = env.get('TC_PREFIX')
112     tc_path = env.get('TC_PATH')
113     if prefix:
114         env.Replace(CC = prefix + 'gcc')
115         env.Replace(CXX = prefix + 'g++')
116         env.Replace(AR = prefix + 'ar')
117         env.Replace(AS = prefix + 'as')
118         env.Replace(LINK = prefix + 'ld')
119         env.Replace(RANLIB = prefix + 'ranlib')
120
121     if tc_path:
122         env.PrependENVPath('PATH', tc_path)
123         sys_root = os.path.abspath(tc_path + '/../')
124         env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
125         env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
126
127     if prefix or tc_path:
128         print tc_set_msg
129
130 # Ensure scons be able to change its working directory
131 env.SConscriptChdir(1)
132
133 # Set the source directory and build directory
134 #   Source directory: 'dir'
135 #   Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
136 #
137 # You can get the directory as following:
138 #   env.get('SRC_DIR')
139 #   env.get('BUILD_DIR')
140
141 def __set_dir(env, dir):
142     if not os.path.exists(dir + '/SConstruct'):
143         print '''
144 *************************************** Error *********************************
145 * The directory(%s) seems isn't a source code directory, no SConstruct file is
146 * found. *
147 *******************************************************************************
148 ''' % dir
149         Exit(1)
150
151     if env.get('RELEASE'):
152         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
153     else:
154         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
155     env.VariantDir(build_dir, dir, duplicate=0)
156
157     env.Replace(BUILD_DIR = build_dir)
158     env.Replace(SRC_DIR = dir)
159
160 def __src_to_obj(env, src, home = ''):
161     obj = env.get('BUILD_DIR') + src.replace(home, '')
162     if env.get('OBJSUFFIX'):
163         obj += env.get('OBJSUFFIX')
164     return env.Object(obj, src)
165
166 def __install(ienv, targets, name):
167     i_n = ienv.Install(env.get('BUILD_DIR'), targets)
168     Alias(name, i_n)
169     env.AppendUnique(TS = [name])
170
171 def __append_target(ienv, target):
172     env.AppendUnique(TS = [target])
173
174 def __print_targets(env):
175     Help('''
176 ===============================================================================
177 Targets:\n    ''')
178     for t in env.get('TS'):
179         Help(t + ' ')
180     Help('''
181 \nDefault all targets will be built. You can specify the target to build:
182
183     $ scons [options] [target]
184 ===============================================================================
185 ''')
186
187 env.AddMethod(__set_dir, 'SetDir')
188 env.AddMethod(__print_targets, 'PrintTargets')
189 env.AddMethod(__src_to_obj, 'SrcToObj')
190 env.AddMethod(__append_target, 'AppendTarget')
191 env.AddMethod(__install, 'InstallTarget')
192 env.SetDir(env.GetLaunchDir())
193 env['ROOT_DIR']=env.GetLaunchDir()
194
195 env.AppendUnique(CPPDEFINES = ['TB_LOG'])
196 if env.get('ROUTING') == 'GW':
197     env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
198 elif env.get('ROUTING') == 'EP':
199     env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
200 env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
201
202 Export('env')
203
204 ######################################################################
205 # continue with the regular build process. Load config of target os
206 ######################################################################
207 env.SConscript(target_os + '/SConscript')
208
209 # Delete the temp files of configuration
210 if env.GetOption('clean'):
211     dir = env.get('SRC_DIR')
212
213     if os.path.exists(dir + '/config.log'):
214         Execute(Delete(dir + '/config.log'))
215         Execute(Delete(dir + '/.sconsign.dblite'))
216         Execute(Delete(dir + '/.sconf_temp'))
217
218 Return('env')
219