+def __set_dir(env, dir):
+ if not os.path.exists(dir + '/SConstruct'):
+ print '''
+*************************************** Error *********************************
+* The directory(%s) seems isn't a source code directory, no SConstruct file is
+* found. *
+*******************************************************************************
+''' % dir
+ Exit(1)
+
+ if env.get('RELEASE'):
+ build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
+ else:
+ build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
+ env.VariantDir(build_dir, dir, duplicate=0)
+
+ env.Replace(BUILD_DIR = build_dir)
+ env.Replace(SRC_DIR = dir)
+
+def __src_to_obj(env, src, home = ''):
+ obj = env.get('BUILD_DIR') + src.replace(home, '')
+ if env.get('OBJSUFFIX'):
+ obj += env.get('OBJSUFFIX')
+ return env.Object(obj, src)
+
+def __install(ienv, targets, name):
+ i_n = ienv.Install(env.get('BUILD_DIR'), targets)
+ Alias(name, i_n)
+ env.AppendUnique(TS = [name])
+
+def __installlib(ienv, targets, name):
+ user_prefix = env.get('PREFIX')
+ if user_prefix:
+ i_n = ienv.Install(user_prefix + '/lib', targets)
+ else:
+ i_n = ienv.Install(env.get('BUILD_DIR'), targets)
+ ienv.Alias("install", i_n)
+
+def __installbin(ienv, targets, name):
+ user_prefix = env.get('PREFIX')
+ if user_prefix:
+ i_n = ienv.Install(user_prefix + '/bin', targets)
+ else:
+ i_n = ienv.Install(env.get('BUILD_DIR'), targets)
+ ienv.Alias("install", i_n)
+
+def __append_target(ienv, name, targets = None):
+ if targets:
+ env.Alias(name, targets)
+ env.AppendUnique(TS = [name])
+
+def __print_targets(env):
+ Help('''
+===============================================================================
+Targets:\n ''')
+ for t in env.get('TS'):
+ Help(t + ' ')
+ Help('''
+\nDefault all targets will be built. You can specify the target to build:
+
+ $ scons [options] [target]
+===============================================================================
+''')
+
+env.AddMethod(__set_dir, 'SetDir')
+env.AddMethod(__print_targets, 'PrintTargets')
+env.AddMethod(__src_to_obj, 'SrcToObj')
+env.AddMethod(__append_target, 'AppendTarget')
+env.AddMethod(__install, 'InstallTarget')
+env.AddMethod(__installlib, 'UserInstallTargetLib')
+env.AddMethod(__installbin, 'UserInstallTargetBin')
+env.SetDir(env.GetLaunchDir())
+env['ROOT_DIR']=env.GetLaunchDir()+'/..'
+
+Export('env')
+
+######################################################################
+# Link scons to Yocto cross-toolchain ONLY when target_os is yocto
+######################################################################
+if target_os == "yocto":
+ '''
+ This code injects Yocto cross-compilation tools+flags into scons'
+ build environment in order to invoke the relevant tools while
+ performing a build.
+ '''
+ import os.path
+ try:
+ CC = os.environ['CC']
+ target_prefix = CC.split()[0]
+ target_prefix = target_prefix[:len(target_prefix)-3]
+ tools = {"CC" : target_prefix+"gcc",
+ "CXX" : target_prefix+"g++",
+ "AS" : target_prefix+"as",
+ "LD" : target_prefix+"ld",
+ "GDB" : target_prefix+"gdb",
+ "STRIP" : target_prefix+"strip",
+ "RANLIB" : target_prefix+"ranlib",
+ "OBJCOPY" : target_prefix+"objcopy",
+ "OBJDUMP" : target_prefix+"objdump",
+ "AR" : target_prefix+"ar",
+ "NM" : target_prefix+"nm",
+ "M4" : "m4",
+ "STRINGS": target_prefix+"strings"}
+ PATH = os.environ['PATH'].split(os.pathsep)
+ for tool in tools:
+ if tool in os.environ:
+ for path in PATH:
+ if os.path.isfile(os.path.join(path, tools[tool])):
+ env[tool] = os.path.join(path, os.environ[tool])
+ break
+ env['CROSS_COMPILE'] = target_prefix[:len(target_prefix) - 1]
+ except:
+ print "ERROR in Yocto cross-toolchain environment"
+ Exit(1)
+ '''
+ Now reset TARGET_OS to linux so that all linux specific build configurations
+ hereupon apply for the entirety of the build process.
+ '''
+ env['TARGET_OS'] = 'linux'
+ '''
+ We want to preserve debug symbols to allow BitBake to generate both DEBUG and
+ RELEASE packages for OIC.
+ '''
+ env.AppendUnique(CCFLAGS = ['-g'])
+ '''
+ Additional flags to pass to the Yocto toolchain.
+ '''
+ if env.get('RELEASE'):
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+ if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+ env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__linux__', '_GNU_SOURCE'])
+ env.AppendUnique(CFLAGS = ['-std=gnu99'])
+ env.AppendUnique(CCFLAGS = ['-Wall', '-Wextra', '-fPIC'])
+ env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread'])
+ env.AppendUnique(LIBS = ['uuid'])
+ Export('env')
+else:
+ '''
+ If target_os is not Yocto, continue with the regular build process
+ '''
+ # Load config of target os
+ env.SConscript(target_os + '/SConscript')
+
+# Delete the temp files of configuration
+if env.GetOption('clean'):
+ dir = env.get('SRC_DIR')
+
+ if os.path.exists(dir + '/config.log'):
+ Execute(Delete(dir + '/config.log'))
+ if os.path.exists(dir + '/.sconsign.dblite'):
+ Execute(Delete(dir + '/.sconsign.dblite'))
+ if os.path.exists(dir + '/.sconf_temp'):
+ Execute(Delete(dir + '/.sconf_temp'))
+
+######################################################################
+# Check for PThreads support
+######################################################################
+import iotivityconfig
+from iotivityconfig import *
+
+conf = Configure(env,
+ custom_tests =
+ {
+ 'CheckPThreadsSupport' : iotivityconfig.check_pthreads
+ } )
+
+# Identify whether we have pthreads support, which is necessary for
+# threading and mutexes. This will set the environment variable
+# POSIX_SUPPORTED, 1 if it is supported, 0 otherwise
+conf.CheckPThreadsSupport()
+
+env = conf.Finish()
+######################################################################