Merge branch 'master' into iot-1785
[platform/upstream/iotivity.git] / build_common / SConscript
1 # -*- mode: python; python-indent-offset: 4; indent-tabs-mode: nil -*-
2 ##
3 # This script includes generic build options:
4 #    release/debug, target os, target arch, cross toolchain, build environment etc
5 ##
6 import os
7 import platform
8
9 project_version = '1.3.0'
10
11 # Map of host os and allowed target os (host: allowed target os)
12 host_target_map = {
13     'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
14     'windows': ['windows', 'android', 'arduino'],
15     'darwin': ['darwin', 'ios', 'android', 'arduino'],
16     'msys_nt' :['msys_nt'],
17 }
18
19 # Map of os and allowed archs (os: allowed archs)
20 os_arch_map = {
21     'linux': ['x86', 'x86_64', 'arm', 'arm-v7a', 'armeabi-v7a', 'arm64', 'mips', 'mipsel', 'mips64', 'mips64el', 'i386', 'powerpc', 'sparc', 'aarch64'],
22     'tizen': ['x86', 'x86_64', 'arm', 'arm-v7a', 'armeabi-v7a', 'arm64'],
23     'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
24     'windows': ['x86', 'amd64', 'arm'],
25     'msys_nt':['x86', 'x86_64'],
26     'darwin': ['i386', 'x86_64'],
27     'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
28     'arduino': ['avr', 'arm'],
29     'yocto': ['i586', 'i686', 'x86_64', 'arm', 'aarch64', 'powerpc', 'powerpc64', 'mips', 'mipsel'],
30 }
31
32 host = platform.system().lower()
33
34 # the host string contains version of windows. 6.3, 6.4, 10.0 which is 8.0, 8.1, and 10 respectively.
35 # Let's canonicalize the msys_nt-XX.X system name by stripping version off.
36 if 'msys_nt' in host:
37     host = 'msys_nt'
38
39 if not host_target_map.has_key(host):
40     print "\nError: Current system (%s) isn't supported\n" % host
41     Exit(1)
42
43 ######################################################################
44 # Get build options (the optins from command line)
45 ######################################################################
46 target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
47
48 if target_os not in host_target_map[host]:
49     print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
50     Exit(1)
51
52 if target_os == 'android':
53     default_arch = 'x86'
54 else:
55     default_arch = platform.machine()
56     if target_os == 'windows':
57         default_arch = default_arch.lower()
58
59 target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
60
61 # True if binary needs to be installed on board. (Might need root permissions)
62 # set to 'no', 'false' or 0 for only compilation
63 require_upload = ARGUMENTS.get('UPLOAD', False)
64
65 # Get the device name. This name can be used as network display name wherever possible
66 device_name = ARGUMENTS.get('DEVICE_NAME', "OIC-DEVICE")
67
68 default_with_upstream_libcoap = 0
69
70 if ARGUMENTS.get('TEST'):
71     logging_default = False
72 else:
73     release_mode = False
74     if ARGUMENTS.get('RELEASE', True) in ['y', 'yes', 'true', 't', '1', 'on', 'all', True]:
75         release_mode = True
76     logging_default = (release_mode == False)
77
78 # targets that do not support the DTLS build (SECURED=1 build option)
79 targets_without_dtls_support = ['arduino'];
80 if ARGUMENTS.get('SECURED') == '1' and target_os in targets_without_dtls_support:
81         print "\nError: DTLS not supported on target os: %s MUST build with SECURED=0\n" % (target_os)
82         Exit(1)
83
84 ######################################################################
85 # Common build options (release, target os, target arch)
86 ######################################################################
87 targets_disallow_multitransport = ['arduino']
88
89 help_vars = Variables()
90 help_vars.Add(BoolVariable('VERBOSE', 'Show compilation', False))
91 help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
92 help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
93
94
95 help_vars.Add(BoolVariable('WITH_RA', 'Build with Remote Access module', False))
96 help_vars.Add(BoolVariable('WITH_TCP', 'Build with TCP adapter', False))
97 help_vars.Add(BoolVariable('WITH_PROXY', 'Build with CoAP-HTTP Proxy', False))
98 help_vars.Add(ListVariable('WITH_MQ', 'Build with MQ publisher/broker', 'OFF', ['OFF', 'SUB', 'PUB', 'BROKER']))
99 help_vars.Add(BoolVariable('WITH_CLOUD', 'Build including AccountManager class and Cloud Client sample', False))
100 help_vars.Add(ListVariable('RD_MODE', 'Resource Directory build mode', 'CLIENT', ['CLIENT', 'SERVER']))
101
102 help_vars.Add(BoolVariable('SIMULATOR', 'Build with simulator module', False))
103
104 help_vars.Add(BoolVariable('WITH_RA_IBB', 'Build with Remote Access module(workssys)', False))
105
106
107 if target_os in targets_disallow_multitransport:
108     help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP', 'NFC']))
109 else:
110     help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP', 'NFC']))
111
112 help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
113 if target_os in targets_without_dtls_support:
114     help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
115 else:
116     help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '1', allowed_values=('0', '1')))
117 help_vars.Add(EnumVariable('MULTIPLE_OWNER', 'Enable multiple owner', '0', allowed_values=('0', '1')))
118 help_vars.Add(EnumVariable('EXC_PROV_SUPPORT', 'Except OCPMAPI library(libocpmapi.so)', '0', allowed_values=('0', '1')))
119 help_vars.Add(EnumVariable('TEST', 'Run unit tests', '0', allowed_values=('0', '1')))
120 help_vars.Add(BoolVariable('LOGGING', 'Enable stack logging', logging_default))
121 help_vars.Add(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload))
122 help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP')))
123 help_vars.Add(EnumVariable('BUILD_SAMPLE', 'Build with sample', 'ON', allowed_values=('ON', 'OFF')))
124 help_vars.AddVariables(('DEVICE_NAME', 'Network display name for device (For Arduino)', device_name, None, None),)
125 help_vars.Add(PathVariable('ANDROID_NDK', 'Android NDK path', None, PathVariable.PathAccept))
126 help_vars.Add(PathVariable('ANDROID_HOME', 'Android SDK path', None, PathVariable.PathAccept))
127 help_vars.Add(PathVariable('ANDROID_GRADLE', 'Gradle binary file', None, PathVariable.PathIsFile))
128 help_vars.Add(EnumVariable('WITH_UPSTREAM_LIBCOAP', 'Use latest stable version of LibCoAP downloaded from github', default_with_upstream_libcoap, allowed_values=('0','1')))
129
130 if target_os == 'windows':
131         # For VS2013, MSVC_VERSION is '12.0'. For VS2015, MSVC_VERSION is '14.0'.
132         # Default value is None, meaning that SCons has to choose automatically a VS version.
133         help_vars.Add(EnumVariable('MSVC_VERSION', 'MSVC compiler version - Windows', None, allowed_values=('12.0', '14.0')))
134
135 help_vars.Add(BoolVariable('BUILD_JAVA', 'Build Java bindings', False))
136 help_vars.Add(PathVariable('JAVA_HOME', 'JDK directory', os.environ.get('JAVA_HOME'), PathVariable.PathAccept))
137
138 AddOption('--prefix',
139                   dest='prefix',
140                   type='string',
141                   nargs=1,
142                   action='store',
143                   metavar='DIR',
144                   help='installation prefix')
145
146 ######################################################################
147 # Platform(build target) specific options: SDK/NDK & toolchain
148 ######################################################################
149 targets_support_cc = ['linux', 'arduino', 'tizen']
150
151 if target_os in targets_support_cc:
152     # Set cross compile toolchain
153     help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
154     help_vars.Add(PathVariable('TC_PATH',
155             'Toolchain path (Generally only be required for cross-compiling)',
156             os.environ.get('TC_PATH')))
157
158 if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
159     env = Environment(variables = help_vars,
160             tools = ['gnulink', 'gcc', 'g++', 'ar', 'as', 'textfile']
161             )
162 else:
163     env = Environment(variables = help_vars, tools = ['default', 'textfile'],
164             TARGET_ARCH = target_arch, TARGET_OS = target_os,
165             PREFIX = GetOption('prefix'),
166             LIB_INSTALL_DIR = ARGUMENTS.get('LIB_INSTALL_DIR') #for 64bit build
167             )
168 Help(help_vars.GenerateHelpText(env))
169
170 tc_set_msg = '''
171 ************************************ Warning **********************************
172 *   Environment variable TC_PREFIX/TC_PATH is set. It will change the default *
173 * toolchain, if it isn't what you expect you should unset it, otherwise it may*
174 * cause inexplicable errors.                                                  *
175 *******************************************************************************
176 '''
177 if env.get('VERBOSE') == False:
178     env['CCCOMSTR'] = "Compiling $TARGET"
179     env['SHCCCOMSTR'] = "Compiling $TARGET"
180     env['CXXCOMSTR'] = "Compiling $TARGET"
181     env['SHCXXCOMSTR'] = "Compiling $TARGET"
182     env['LINKCOMSTR'] = "Linking $TARGET"
183     env['SHLINKCOMSTR'] = "Linking $TARGET"
184     env['ARCOMSTR'] = "Archiving $TARGET"
185     env['RANLIBCOMSTR'] = "Indexing Archive $TARGET"
186
187 if target_os in targets_support_cc:
188     prefix = env.get('TC_PREFIX')
189     tc_path = env.get('TC_PATH')
190     if prefix:
191         env.Replace(CC = prefix + env.get('CC', 'gcc'))
192         env.Replace(CXX = prefix + env.get('CXX', 'g++'))
193         env.Replace(AR = prefix + env.get('AR', 'ar'))
194         env.Replace(AS = prefix + env.get('AS', 'as'))
195         env.Replace(RANLIB = prefix + env.get('RANLIB', 'ranlib'))
196
197     if tc_path:
198         env.PrependENVPath('PATH', tc_path)
199         sys_root = os.path.abspath(tc_path + '/../')
200         env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
201         env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
202
203     if prefix or tc_path:
204         print tc_set_msg
205
206 # Import env variables only if reproductibility is ensured
207 if target_os in ['yocto']:
208     env['CONFIG_ENVIRONMENT_IMPORT'] = True
209 else:
210     env['CONFIG_ENVIRONMENT_IMPORT'] = False
211
212 if env['CONFIG_ENVIRONMENT_IMPORT'] == True:
213     print "warning: importing some environment variables for OS: %s" % target_os
214     for ev in ['PATH', 'PKG_CONFIG', 'PKG_CONFIG_PATH', 'PKG_CONFIG_SYSROOT_DIR']:
215         if os.environ.get(ev) != None:
216             env['ENV'][ev] = os.environ.get(ev)
217     if os.environ['LDFLAGS'] != None:
218         env.AppendUnique(LINKFLAGS = Split(os.environ['LDFLAGS']))
219
220 # Ensure scons be able to change its working directory
221 env.SConscriptChdir(1)
222
223 # Set the source directory and build directory
224 #   Source directory: 'dir'
225 #   Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
226 #
227 # You can get the directory as following:
228 #   env.get('SRC_DIR')
229 #   env.get('BUILD_DIR')
230
231 def __set_dir(env, dir):
232     if not os.path.exists(dir + '/SConstruct'):
233         print '''
234 *************************************** Error *********************************
235 * The directory(%s) seems isn't a source code directory, no SConstruct file is
236 * found. *
237 *******************************************************************************
238 ''' % dir
239         Exit(1)
240
241     if env.get('RELEASE'):
242         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
243     else:
244         build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
245     env.VariantDir(build_dir, dir, duplicate=0)
246
247     env.Replace(BUILD_DIR = build_dir)
248     env.Replace(SRC_DIR = dir)
249
250 def __src_to_obj(env, src, home = ''):
251     obj = env.get('BUILD_DIR') + src.replace(home, '')
252     if env.get('OBJSUFFIX'):
253         obj += env.get('OBJSUFFIX')
254     return env.Object(obj, src)
255
256 def __install(ienv, targets, name):
257     i_n = ienv.Install(env.get('BUILD_DIR'), targets)
258     Alias(name, i_n)
259     env.AppendUnique(TS = [name])
260
261 def __installlib(ienv, targets, name):
262     user_prefix = env.get('PREFIX')
263     if user_prefix:
264         user_lib = env.get('LIB_INSTALL_DIR')
265         if user_lib:
266             i_n = ienv.Install(user_lib, targets)
267         else:
268             i_n = ienv.Install(user_prefix + '/lib', targets)
269         ienv.Alias("install", i_n)
270     else:
271         i_n = ienv.Install(env.get('BUILD_DIR'), targets)
272     ienv.Alias("install", i_n)
273
274 def __installbin(ienv, targets, name):
275     user_prefix = env.get('PREFIX')
276     if user_prefix:
277         i_n = ienv.Install(user_prefix + '/bin', targets)
278         ienv.Alias("install", i_n)
279
280 def __installheader(ienv, targets, dir, name):
281     user_prefix = env.get('PREFIX')
282     if user_prefix:
283         i_n = ienv.Install(user_prefix + '/include/' + dir ,targets)
284     else:
285         i_n = ienv.Install(os.path.join(env.get('BUILD_DIR'), 'include', dir), targets)
286     ienv.Alias("install", i_n)
287
288 def __installpcfile(ienv, targets, name):
289     user_prefix = env.get('PREFIX')
290     if user_prefix:
291         user_lib = env.get('LIB_INSTALL_DIR')
292         if user_lib:
293             i_n = ienv.Install(user_lib + '/pkgconfig', targets)
294         else:
295             i_n = ienv.Install(user_prefix + '/lib/pkgconfig', targets)
296     else:
297         i_n = ienv.Install(env.get('BUILD_DIR') + 'lib/pkgconfig', targets)
298     ienv.Alias("install", i_n)
299
300 def __append_target(ienv, name, targets = None):
301     if targets:
302         env.Alias(name, targets)
303     env.AppendUnique(TS = [name])
304
305 def __print_targets(env):
306     Help('''
307 ===============================================================================
308 Targets:\n    ''')
309     for t in env.get('TS'):
310         Help(t + ' ')
311     Help('''
312 \nDefault all targets will be built. You can specify the target to build:
313
314     $ scons [options] [target]
315 ===============================================================================
316 ''')
317
318 env.AddMethod(__set_dir, 'SetDir')
319 env.AddMethod(__print_targets, 'PrintTargets')
320 env.AddMethod(__src_to_obj, 'SrcToObj')
321 env.AddMethod(__append_target, 'AppendTarget')
322 env.AddMethod(__install, 'InstallTarget')
323 env.AddMethod(__installlib, 'UserInstallTargetLib')
324 env.AddMethod(__installbin, 'UserInstallTargetBin')
325 env.AddMethod(__installheader, 'UserInstallTargetHeader')
326 env.AddMethod(__installpcfile, 'UserInstallTargetPCFile')
327 env.SetDir(env.GetLaunchDir())
328 env['ROOT_DIR']=env.GetLaunchDir()+'/..'
329
330 Export('env')
331
332 ######################################################################
333 # Scons to generate the iotivity.pc file from iotivity.pc.in file
334 ######################################################################
335 pc_file = env.get('SRC_DIR') + '/iotivity.pc.in'
336
337 user_prefix = env.get('PREFIX')
338 user_lib = env.get('LIB_INSTALL_DIR')
339
340 if not user_prefix:
341     user_prefix = env.get('BUILD_DIR').encode('string_escape')
342
343 if not user_lib:
344     user_lib = '$${prefix}/lib'
345
346 defines = []
347 if env.get('LOGGING'):
348     defines.append('-DTB_LOG=1')
349
350 if env.get('ROUTING') == 'GW':
351     defines.append('-DROUTING_GATEWAY=1')
352 elif env.get('ROUTING') == 'EP':
353     defines.append('-DROUTING_EP=1')
354
355 libs = []
356 if env.get('WITH_TCP'):
357     defines.append('-DTCP_ADAPTER=1')
358     if env.get('SECURED') == '1':
359         defines.append('-D__WITH_TLS__=1')
360
361 if env.get('SECURED') == '1':
362     defines.append('-D__WITH_DTLS__=1')
363     if env.get('EXC_PROV_SUPPORT') == '0':
364         libs.append('-locpmapi')
365
366 pc_vars = {
367     '\@VERSION\@': project_version,
368     '\@PREFIX\@': user_prefix,
369     '\@EXEC_PREFIX\@': user_prefix,
370     '\@LIB_INSTALL_DIR\@': user_lib,
371     '\@DEFINES\@': " ".join(defines),
372     '\@LIBS\@': " ".join(libs)
373 }
374
375 env.Substfile(pc_file, SUBST_DICT = pc_vars)
376
377 ######################################################################
378 # Setting global CPPDEFINES
379 ######################################################################
380 target_transport = env.get('TARGET_TRANSPORT')
381 with_mq = env.get('WITH_MQ')
382 with_ra = env.get('WITH_RA')
383 with_tcp = env.get('WITH_TCP')
384 rd_mode = env.get('RD_MODE')
385 with_ra_ibb = env.get('WITH_RA_IBB')
386
387 if (env.get('WITH_UPSTREAM_LIBCOAP') == '1'):
388     env.AppendUnique(CPPDEFINES = ['WITH_UPSTREAM_LIBCOAP'])
389
390 if (target_os not in ['arduino', 'windows']):
391     env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
392
393 if (target_os in ['darwin','ios']):
394     env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
395
396 if (env.get('SECURED') == '1'):
397     env.AppendUnique(CPPDEFINES = ['__WITH_DTLS__'])
398
399 if ((env.get('SECURED') == '1') and with_tcp):
400     env.AppendUnique(CPPDEFINES = ['__WITH_TLS__'])
401
402 if (env.get('MULTIPLE_OWNER') == '1'):
403     env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER'])
404
405 if (env.get('ROUTING') == 'GW'):
406     env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
407 elif (env.get('ROUTING') == 'EP'):
408     env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
409
410 if (target_os == 'arduino'):
411     env.AppendUnique(CPPDEFINES = ['SINGLE_THREAD'])
412     env.AppendUnique(CPPDEFINES = ['WITH_ARDUINO'])
413 elif (('IP' in target_transport) or ('ALL' in target_transport)):
414         env.AppendUnique(CPPDEFINES = ['WITH_BWT'])
415
416 if (target_os in ['linux', 'tizen', 'android'] and with_tcp):
417     env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
418
419 if (target_os in ['linux', 'tizen', 'android', 'arduino', 'ios']):
420     if (('BLE' in target_transport) or ('BT' in target_transport) or ('ALL' in target_transport)):
421         env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
422
423 if 'ALL' in target_transport:
424     if with_ra:
425         env.AppendUnique(CPPDEFINES = ['RA_ADAPTER'])
426     if with_tcp:
427         env.AppendUnique(CPPDEFINES = ['TCP_ADAPTER'])
428     if (target_os in ['linux']):
429         env.AppendUnique(CPPDEFINES = ['IP_ADAPTER', 'NO_EDR_ADAPTER', 'LE_ADAPTER'])
430     elif (target_os == 'android'):
431         env.AppendUnique(CPPDEFINES = ['IP_ADAPTER', 'EDR_ADAPTER', 'LE_ADAPTER', 'NFC_ADAPTER'])
432     elif (target_os in['darwin', 'ios', 'msys_nt', 'windows']):
433         env.AppendUnique(CPPDEFINES = ['IP_ADAPTER', 'NO_EDR_ADAPTER', 'NO_LE_ADAPTER'])
434     else:
435         env.AppendUnique(CPPDEFINES = ['IP_ADAPTER', 'EDR_ADAPTER', 'LE_ADAPTER'])
436 else:
437     if ('BT' in target_transport):
438         if (target_os == 'linux'):
439             print "CA Transport BT is not supported "
440             Exit(1)
441         else:
442             env.AppendUnique(CPPDEFINES = ['EDR_ADAPTER'])
443     else:
444         env.AppendUnique(CPPDEFINES = ['NO_EDR_ADAPTER'])
445
446     if ('BLE' in target_transport):
447         env.AppendUnique(CPPDEFINES = ['LE_ADAPTER'])
448     else:
449         env.AppendUnique(CPPDEFINES = ['NO_LE_ADAPTER'])
450
451     if ('IP' in target_transport):
452         env.AppendUnique(CPPDEFINES = ['IP_ADAPTER'])
453     else:
454         env.AppendUnique(CPPDEFINES = ['NO_IP_ADAPTER'])
455
456     if with_tcp:
457         if (target_os in ['linux', 'tizen', 'android', 'arduino', 'ios', 'windows']):
458             env.AppendUnique(CPPDEFINES = ['TCP_ADAPTER', 'WITH_TCP'])
459         else:
460             print "CA Transport TCP is not supported "
461             Exit(1)
462     else:
463         env.AppendUnique(CPPDEFINES = ['NO_TCP_ADAPTER'])
464
465     if ('NFC' in target_transport):
466         if (target_os == 'android'):
467             env.AppendUnique(CPPDEFINES = ['NFC_ADAPTER'])
468         else:
469             print "CA Transport NFC is not supported "
470             Exit(1)
471     else:
472         env.AppendUnique(CPPDEFINES = ['NO_NFC_ADAPTER'])
473
474 if ('SUB' in with_mq):
475     env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
476
477 if ('PUB' in with_mq):
478     env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
479
480 if ('BROKER' in with_mq):
481     env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
482
483 if env.get('LOGGING'):
484     env.AppendUnique(CPPDEFINES = ['TB_LOG'])
485
486 if env.get('WITH_CLOUD') and with_tcp:
487     env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
488
489 if 'CLIENT' in rd_mode:
490     env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
491
492 if 'SERVER' in rd_mode:
493     env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
494
495 if with_ra_ibb:
496     env.AppendUnique(CPPDEFINES = ['RA_ADAPTER_IBB'])
497 ######################################################################
498 # Link scons to Yocto cross-toolchain ONLY when target_os is yocto
499 ######################################################################
500 if target_os == "yocto":
501     '''
502     This code injects Yocto cross-compilation tools+flags into scons'
503     build environment in order to invoke the relevant tools while
504     performing a build.
505     '''
506     import os.path
507     try:
508         CC = os.environ['CC']
509         target_prefix = CC.split()[0]
510         target_prefix = target_prefix[:len(target_prefix)-3]
511         tools = {"CC" : target_prefix+"gcc",
512                 "CXX" : target_prefix+"g++",
513                 "AS" : target_prefix+"as",
514                 "LD" : target_prefix+"ld",
515                 "GDB" : target_prefix+"gdb",
516                 "STRIP" : target_prefix+"strip",
517                 "RANLIB" : target_prefix+"ranlib",
518                 "OBJCOPY" : target_prefix+"objcopy",
519                 "OBJDUMP" : target_prefix+"objdump",
520                 "AR" : target_prefix+"ar",
521                 "NM" : target_prefix+"nm",
522                 "M4" : "m4",
523                 "STRINGS": target_prefix+"strings"}
524         PATH = os.environ['PATH'].split(os.pathsep)
525         for tool in tools:
526             if tool in os.environ:
527                 for path in PATH:
528                     if os.path.isfile(os.path.join(path, tools[tool])):
529                         env[tool] = os.path.join(path, os.environ[tool])
530                         break
531         env['CROSS_COMPILE'] = target_prefix[:len(target_prefix) - 1]
532     except:
533         print "ERROR in Yocto cross-toolchain environment"
534         Exit(1)
535     '''
536     Now reset TARGET_OS to linux so that all linux specific build configurations
537     hereupon apply for the entirety of the build process.
538     '''
539     env['TARGET_OS'] = 'linux'
540     '''
541     We want to preserve debug symbols to allow BitBake to generate both DEBUG and
542     RELEASE packages for OIC.
543     '''
544     env.AppendUnique(CCFLAGS = ['-g'])
545     '''
546     Additional flags to pass to the Yocto toolchain.
547     '''
548     if env.get('RELEASE'):
549         env.AppendUnique(CPPDEFINES = ['NDEBUG'])
550     env.AppendUnique(CPPDEFINES = ['__linux__', '_GNU_SOURCE'])
551     env.AppendUnique(CFLAGS = ['-std=gnu99'])
552     env.AppendUnique(CCFLAGS = ['-Wall', '-Wextra', '-fPIC'])
553     env.AppendUnique(LIBS = ['dl', 'pthread', 'uuid'])
554     Export('env')
555 else:
556     '''
557     If target_os is not Yocto, continue with the regular build process
558     '''
559     # Load config of target os
560     env.SConscript(target_os + '/SConscript')
561
562 # Delete the temp files of configuration
563 if env.GetOption('clean'):
564     dir = env.get('SRC_DIR')
565
566     if os.path.exists(dir + '/config.log'):
567         Execute(Delete(dir + '/config.log'))
568     if os.path.exists(dir + '/.sconsign.dblite'):
569         Execute(Delete(dir + '/.sconsign.dblite'))
570     if os.path.exists(dir + '/.sconf_temp'):
571         Execute(Delete(dir + '/.sconf_temp'))
572
573 ######################################################################
574 # Check for PThreads support
575 ######################################################################
576 import iotivityconfig
577 from iotivityconfig import *
578
579 conf = Configure(env,
580         custom_tests =
581         {
582             'CheckPThreadsSupport' : iotivityconfig.check_pthreads
583         } )
584
585 # Identify whether we have pthreads support, which is necessary for
586 # threading and mutexes.  This will set the environment variable
587 # POSIX_SUPPORTED, 1 if it is supported, 0 otherwise
588 conf.CheckPThreadsSupport()
589
590 env = conf.Finish()
591 ######################################################################
592
593 env.SConscript('external_libs.scons')
594 Return('env')