replace : iotivity -> iotivity-sec
[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 AddOption('--prefix',
81                   dest='prefix',
82                   type='string',
83                   nargs=1,
84                   action='store',
85                   metavar='DIR',
86                   help='installation prefix')
87 ######################################################################
88 # Platform(build target) specific options: SDK/NDK & toolchain
89 ######################################################################
90 targets_support_cc = ['tizen']
91
92 if target_os in targets_support_cc:
93     # Set cross compile toolchain
94     help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
95     help_vars.Add(PathVariable('TC_PATH',
96             'Toolchain path (Generally only be required for cross-compiling)',
97             os.environ.get('TC_PATH')))
98
99 if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
100     env = Environment(variables = help_vars,
101             tools = ['gnulink', 'gcc', 'g++', 'ar', 'as']
102             )
103 else:
104     env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
105
106 Help(help_vars.GenerateHelpText(env))
107
108 tc_set_msg = '''
109 ************************************ Warning **********************************
110 *   Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
111 * toolchain, if it isn't what you expect you should unset it, otherwise it may*
112 * cause inexplicable errors.                                                  *
113 *******************************************************************************
114 '''
115
116 if target_os in targets_support_cc:
117     prefix = env.get('TC_PREFIX')
118     tc_path = env.get('TC_PATH')
119     if prefix:
120         env.Replace(CC = prefix + 'gcc')
121         env.Replace(CXX = prefix + 'g++')
122         env.Replace(AR = prefix + 'ar')
123         env.Replace(AS = prefix + 'as')
124         env.Replace(LINK = prefix + 'ld')
125         env.Replace(RANLIB = prefix + 'ranlib')
126
127     if tc_path:
128         env.PrependENVPath('PATH', tc_path)
129         sys_root = os.path.abspath(tc_path + '/../')
130         env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
131         env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
132
133     if prefix or tc_path:
134         print tc_set_msg
135
136 # Ensure scons be able to change its working directory
137 env.SConscriptChdir(1)
138
139 # Set the source directory and build directory
140 #   Source directory: 'dir'
141 #   Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
142 #
143 # You can get the directory as following:
144 #   env.get('SRC_DIR')
145 #   env.get('BUILD_DIR')
146
147 def __set_dir(env, dir):
148     if not os.path.exists(dir + '/SConstruct'):
149         print '''
150 *************************************** Error *********************************
151 * The directory(%s) seems isn't a source code directory, no SConstruct file is
152 * found. *
153 *******************************************************************************
154 ''' % dir
155         Exit(1)
156
157     if env.get('RELEASE'):
158         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
159     else:
160         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
161     env.VariantDir(build_dir, dir, duplicate=0)
162
163     env.Replace(BUILD_DIR = build_dir)
164     env.Replace(SRC_DIR = dir)
165
166 def __src_to_obj(env, src, home = ''):
167     obj = env.get('BUILD_DIR') + src.replace(home, '')
168     if env.get('OBJSUFFIX'):
169         obj += env.get('OBJSUFFIX')
170     return env.Object(obj, src)
171
172 def __install(ienv, targets, name):
173     i_n = ienv.Install(env.get('BUILD_DIR'), targets)
174     Alias(name, i_n)
175     env.AppendUnique(TS = [name])
176
177 def __append_target(ienv, target):
178     env.AppendUnique(TS = [target])
179
180 def __print_targets(env):
181     Help('''
182 ===============================================================================
183 Targets:\n    ''')
184     for t in env.get('TS'):
185         Help(t + ' ')
186     Help('''
187 \nDefault all targets will be built. You can specify the target to build:
188
189     $ scons [options] [target]
190 ===============================================================================
191 ''')
192
193 env.AddMethod(__set_dir, 'SetDir')
194 env.AddMethod(__print_targets, 'PrintTargets')
195 env.AddMethod(__src_to_obj, 'SrcToObj')
196 env.AddMethod(__append_target, 'AppendTarget')
197 env.AddMethod(__install, 'InstallTarget')
198 env.SetDir(env.GetLaunchDir())
199 env['ROOT_DIR']=env.GetLaunchDir()
200
201 env.AppendUnique(CPPDEFINES = ['TB_LOG'])
202 env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
203
204 Export('env')
205
206 ######################################################################
207 # continue with the regular build process. Load config of target os
208 ######################################################################
209 env.SConscript(target_os + '/SConscript')
210
211 # Delete the temp files of configuration
212 if env.GetOption('clean'):
213     dir = env.get('SRC_DIR')
214
215     if os.path.exists(dir + '/config.log'):
216         Execute(Delete(dir + '/config.log'))
217         Execute(Delete(dir + '/.sconsign.dblite'))
218         Execute(Delete(dir + '/.sconf_temp'))
219
220 Return('env')
221