Imported Upstream version 1.2.0
[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', '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         'darwin': ['i386', 'x86_64'],
42         'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
43         'arduino': ['avr', 'arm'],
44                 'yocto': ['x86', 'x86_64'],
45         'tizen': ['armv7'],
46         }
47
48 host = platform.system().lower()
49
50 if not host_target_map.has_key(host):
51     print "\nError: Current system (%s) isn't supported\n" % host
52     Exit(1)
53
54 ######################################################################
55 # Get build options (the optins from command line)
56 ######################################################################
57 target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
58
59 if target_os not in host_target_map[host]:
60     print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
61     Exit(1)
62
63 default_arch = platform.machine()
64 if default_arch not in os_arch_map[target_os]:
65     default_arch = os_arch_map[target_os][0].lower()
66
67 target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
68
69 ######################################################################
70 # Common build options (release, target os, target arch)
71 ######################################################################
72 help_vars = Variables()
73 help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
74 help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
75 help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'IP', 'BT', 'BLE']))
76 help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
77 help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
78 help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP')))
79
80 ######################################################################
81 # Platform(build target) specific options: SDK/NDK & toolchain
82 ######################################################################
83 targets_support_cc = ['tizen']
84
85 if target_os in targets_support_cc:
86     # Set cross compile toolchain
87     help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
88     help_vars.Add(PathVariable('TC_PATH',
89             'Toolchain path (Generally only be required for cross-compiling)',
90             os.environ.get('TC_PATH')))
91
92 if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
93     env = Environment(variables = help_vars,
94             tools = ['gnulink', 'gcc', 'g++', 'ar', 'as']
95             )
96 else:
97     env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
98
99 Help(help_vars.GenerateHelpText(env))
100
101 tc_set_msg = '''
102 ************************************ Warning **********************************
103 *   Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
104 * toolchain, if it isn't what you expect you should unset it, otherwise it may*
105 * cause inexplicable errors.                                                  *
106 *******************************************************************************
107 '''
108
109 if target_os in targets_support_cc:
110     prefix = env.get('TC_PREFIX')
111     tc_path = env.get('TC_PATH')
112     if prefix:
113         env.Replace(CC = prefix + 'gcc')
114         env.Replace(CXX = prefix + 'g++')
115         env.Replace(AR = prefix + 'ar')
116         env.Replace(AS = prefix + 'as')
117         env.Replace(LINK = prefix + 'ld')
118         env.Replace(RANLIB = prefix + 'ranlib')
119
120     if tc_path:
121         env.PrependENVPath('PATH', tc_path)
122         sys_root = os.path.abspath(tc_path + '/../')
123         env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
124         env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
125
126     if prefix or tc_path:
127         print tc_set_msg
128
129 # Ensure scons be able to change its working directory
130 env.SConscriptChdir(1)
131
132 # Set the source directory and build directory
133 #   Source directory: 'dir'
134 #   Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
135 #
136 # You can get the directory as following:
137 #   env.get('SRC_DIR')
138 #   env.get('BUILD_DIR')
139
140 def __set_dir(env, dir):
141     if not os.path.exists(dir + '/SConstruct'):
142         print '''
143 *************************************** Error *********************************
144 * The directory(%s) seems isn't a source code directory, no SConstruct file is
145 * found. *
146 *******************************************************************************
147 ''' % dir
148         Exit(1)
149
150     if env.get('RELEASE'):
151         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
152     else:
153         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
154     env.VariantDir(build_dir, dir, duplicate=0)
155
156     env.Replace(BUILD_DIR = build_dir)
157     env.Replace(SRC_DIR = dir)
158
159 def __src_to_obj(env, src, home = ''):
160     obj = env.get('BUILD_DIR') + src.replace(home, '')
161     if env.get('OBJSUFFIX'):
162         obj += env.get('OBJSUFFIX')
163     return env.Object(obj, src)
164
165 def __install(ienv, targets, name):
166     i_n = ienv.Install(env.get('BUILD_DIR'), targets)
167     Alias(name, i_n)
168     env.AppendUnique(TS = [name])
169
170 def __append_target(ienv, target):
171     env.AppendUnique(TS = [target])
172
173 def __print_targets(env):
174     Help('''
175 ===============================================================================
176 Targets:\n    ''')
177     for t in env.get('TS'):
178         Help(t + ' ')
179     Help('''
180 \nDefault all targets will be built. You can specify the target to build:
181
182     $ scons [options] [target]
183 ===============================================================================
184 ''')
185
186 env.AddMethod(__set_dir, 'SetDir')
187 env.AddMethod(__print_targets, 'PrintTargets')
188 env.AddMethod(__src_to_obj, 'SrcToObj')
189 env.AddMethod(__append_target, 'AppendTarget')
190 env.AddMethod(__install, 'InstallTarget')
191 env.SetDir(env.GetLaunchDir())
192 env['ROOT_DIR']=env.GetLaunchDir()
193
194 env.AppendUnique(CPPDEFINES = ['TB_LOG'])
195 env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
196
197 Export('env')
198
199 ######################################################################
200 # continue with the regular build process. Load config of target os
201 ######################################################################
202 env.SConscript(target_os + '/SConscript')
203
204 # Delete the temp files of configuration
205 if env.GetOption('clean'):
206     dir = env.get('SRC_DIR')
207
208     if os.path.exists(dir + '/config.log'):
209         Execute(Delete(dir + '/config.log'))
210         Execute(Delete(dir + '/.sconsign.dblite'))
211         Execute(Delete(dir + '/.sconf_temp'))
212
213 Return('env')
214