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 host not in host_target_map:
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')))
86 help='installation prefix')
87 ######################################################################
88 # Platform(build target) specific options: SDK/NDK & toolchain
89 ######################################################################
90 targets_support_cc = ['tizen']
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')))
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']
104 env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
106 Help(help_vars.GenerateHelpText(env))
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 *******************************************************************************
116 if target_os in targets_support_cc:
117 prefix = env.get('TC_PREFIX')
118 tc_path = env.get('TC_PATH')
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')
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])
133 if prefix or tc_path:
136 # Ensure scons be able to change its working directory
137 env.SConscriptChdir(1)
139 # Set the source directory and build directory
140 # Source directory: 'dir'
141 # Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
143 # You can get the directory as following:
145 # env.get('BUILD_DIR')
147 def __set_dir(env, dir):
148 if not os.path.exists(dir + '/SConstruct'):
150 *************************************** Error *********************************
151 * The directory(%s) seems isn't a source code directory, no SConstruct file is
153 *******************************************************************************
157 if env.get('RELEASE'):
158 build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
160 build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
161 env.VariantDir(build_dir, dir, duplicate=0)
163 env.Replace(BUILD_DIR = build_dir)
164 env.Replace(SRC_DIR = dir)
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)
172 def __install(ienv, targets, name):
173 i_n = ienv.Install(env.get('BUILD_DIR'), targets)
175 env.AppendUnique(TS = [name])
177 def __append_target(ienv, target):
178 env.AppendUnique(TS = [target])
180 def __print_targets(env):
182 ===============================================================================
184 for t in env.get('TS'):
187 \nDefault all targets will be built. You can specify the target to build:
189 $ scons [options] [target]
190 ===============================================================================
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()
201 env.AppendUnique(CPPDEFINES = ['TB_LOG'])
202 env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
206 ######################################################################
207 # continue with the regular build process. Load config of target os
208 ######################################################################
209 env.SConscript(target_os + '/SConscript')
211 # Delete the temp files of configuration
212 if env.GetOption('clean'):
213 dir = env.get('SRC_DIR')
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'))