1 ##########################################################################
3 # Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 ##########################################################################
22 # This script includes generic build options:
23 # release/debug, target os, target arch, cross toolchain, build environment etc
28 print "Inside the Config SConscript"
29 # Map of host os and allowed target os (host: allowed target os)
31 'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
32 'windows': ['windows', 'android', 'arduino', 'tizen'],
33 'darwin': ['darwin', 'ios', 'android', 'arduino'],
36 # Map of os and allowed archs (os: allowed archs)
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'],
48 host = platform.system().lower()
50 if not host_target_map.has_key(host):
51 print "\nError: Current system (%s) isn't supported\n" % host
54 ######################################################################
55 # Get build options (the optins from command line)
56 ######################################################################
57 target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
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])
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()
67 target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
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')))
80 ######################################################################
81 # Platform(build target) specific options: SDK/NDK & toolchain
82 ######################################################################
83 targets_support_cc = ['tizen']
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')))
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']
97 env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
99 Help(help_vars.GenerateHelpText(env))
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 *******************************************************************************
109 if target_os in targets_support_cc:
110 prefix = env.get('TC_PREFIX')
111 tc_path = env.get('TC_PATH')
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')
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])
126 if prefix or tc_path:
129 # Ensure scons be able to change its working directory
130 env.SConscriptChdir(1)
132 # Set the source directory and build directory
133 # Source directory: 'dir'
134 # Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
136 # You can get the directory as following:
138 # env.get('BUILD_DIR')
140 def __set_dir(env, dir):
141 if not os.path.exists(dir + '/SConstruct'):
143 *************************************** Error *********************************
144 * The directory(%s) seems isn't a source code directory, no SConstruct file is
146 *******************************************************************************
150 if env.get('RELEASE'):
151 build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
153 build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
154 env.VariantDir(build_dir, dir, duplicate=0)
156 env.Replace(BUILD_DIR = build_dir)
157 env.Replace(SRC_DIR = dir)
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)
165 def __install(ienv, targets, name):
166 i_n = ienv.Install(env.get('BUILD_DIR'), targets)
168 env.AppendUnique(TS = [name])
170 def __append_target(ienv, target):
171 env.AppendUnique(TS = [target])
173 def __print_targets(env):
175 ===============================================================================
177 for t in env.get('TS'):
180 \nDefault all targets will be built. You can specify the target to build:
182 $ scons [options] [target]
183 ===============================================================================
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()
194 env.AppendUnique(CPPDEFINES = ['TB_LOG'])
195 env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
199 ######################################################################
200 # continue with the regular build process. Load config of target os
201 ######################################################################
202 env.SConscript(target_os + '/SConscript')
204 # Delete the temp files of configuration
205 if env.GetOption('clean'):
206 dir = env.get('SRC_DIR')
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'))