# Map of host os and allowed target os (host: allowed target os)
host_target_map = {
- 'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
- 'windows': ['windows', 'android', 'arduino'],
- 'darwin': ['darwin', 'ios', 'android', 'arduino'],
- 'msys_nt' :['msys_nt'],
- }
+ 'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
+ 'windows': ['windows', 'android', 'arduino'],
+ 'darwin': ['darwin', 'ios', 'android', 'arduino'],
+ 'msys_nt' :['msys_nt'],
+}
# Map of os and allowed archs (os: allowed archs)
os_arch_map = {
- 'linux': ['x86', 'x86_64', 'arm', 'arm-v7a', 'arm64'],
- 'tizen': ['x86', 'x86_64', 'arm', 'arm-v7a', 'armeabi-v7a', 'arm64'],
- 'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
- 'windows': ['x86', 'amd64', 'arm'],
- 'msys_nt':['x86', 'x86_64'],
- 'darwin': ['i386', 'x86_64'],
- 'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
- 'arduino': ['avr', 'arm'],
- 'yocto': ['i586', 'i686', 'x86_64', 'arm', 'powerpc', 'powerpc64', 'mips', 'mipsel'],
- }
+ 'linux': ['x86', 'x86_64', 'arm', 'arm-v7a', 'arm64'],
+ 'tizen': ['x86', 'x86_64', 'arm', 'arm-v7a', 'armeabi-v7a', 'arm64'],
+ 'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
+ 'windows': ['x86', 'amd64', 'arm'],
+ 'msys_nt':['x86', 'x86_64'],
+ 'darwin': ['i386', 'x86_64'],
+ 'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
+ 'arduino': ['avr', 'arm'],
+ 'yocto': ['i586', 'i686', 'x86_64', 'arm', 'powerpc', 'powerpc64', 'mips', 'mipsel'],
+}
host = platform.system().lower()
# the host string contains version of windows. 6.3, 6.4, 10.0 which is 8.0, 8.1, and 10 respectively.
# Let's canonicalize the msys_nt-XX.X system name by stripping version off.
if 'msys_nt' in host:
- host = 'msys_nt'
+ host = 'msys_nt'
if not host_target_map.has_key(host):
- print "\nError: Current system (%s) isn't supported\n" % host
- Exit(1)
+ print "\nError: Current system (%s) isn't supported\n" % host
+ Exit(1)
######################################################################
# Get build options (the optins from command line)
target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
if target_os not in host_target_map[host]:
- print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
- Exit(1)
+ print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
+ Exit(1)
if target_os == 'android':
- default_arch = 'x86'
+ default_arch = 'x86'
else:
- default_arch = platform.machine()
+ default_arch = platform.machine()
if default_arch not in os_arch_map[target_os]:
- default_arch = os_arch_map[target_os][0].lower()
+ default_arch = os_arch_map[target_os][0].lower()
target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
default_with_upstream_libcoap = 0
if ARGUMENTS.get('TEST'):
- logging_default = False
+ logging_default = False
else:
- release_mode = False
- if ARGUMENTS.get('RELEASE', True) in ['y', 'yes', 'true', 't', '1', 'on', 'all', True]:
- release_mode = True
- logging_default = (release_mode == False)
+ release_mode = False
+ if ARGUMENTS.get('RELEASE', True) in ['y', 'yes', 'true', 't', '1', 'on', 'all', True]:
+ release_mode = True
+ logging_default = (release_mode == False)
# targets that do not support the DTLS build (SECURED=1 build option)
targets_without_dtls_support = ['arduino'];
if target_os in targets_disallow_multitransport:
- help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP', 'NFC']))
+ help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP', 'NFC']))
else:
- help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP', 'NFC']))
+ help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP', 'NFC']))
help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
targets_support_cc = ['linux', 'arduino', 'tizen']
if target_os in targets_support_cc:
- # Set cross compile toolchain
- help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
- help_vars.Add(PathVariable('TC_PATH',
- 'Toolchain path (Generally only be required for cross-compiling)',
- os.environ.get('TC_PATH')))
+ # Set cross compile toolchain
+ help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
+ help_vars.Add(PathVariable('TC_PATH',
+ 'Toolchain path (Generally only be required for cross-compiling)',
+ os.environ.get('TC_PATH')))
if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
- env = Environment(variables = help_vars,
- tools = ['gnulink', 'gcc', 'g++', 'ar', 'as', 'textfile']
- )
+ env = Environment(variables = help_vars,
+ tools = ['gnulink', 'gcc', 'g++', 'ar', 'as', 'textfile']
+ )
else:
- env = Environment(variables = help_vars, tools = ['default', 'textfile'],
- TARGET_ARCH = target_arch, TARGET_OS = target_os,
- PREFIX = GetOption('prefix'),
- LIB_INSTALL_DIR = ARGUMENTS.get('LIB_INSTALL_DIR') #for 64bit build
- )
+ env = Environment(variables = help_vars, tools = ['default', 'textfile'],
+ TARGET_ARCH = target_arch, TARGET_OS = target_os,
+ PREFIX = GetOption('prefix'),
+ LIB_INSTALL_DIR = ARGUMENTS.get('LIB_INSTALL_DIR') #for 64bit build
+ )
Help(help_vars.GenerateHelpText(env))
tc_set_msg = '''
*******************************************************************************
'''
if env.get('VERBOSE') == False:
- env['CCCOMSTR'] = "Compiling $TARGET"
- env['SHCCCOMSTR'] = "Compiling $TARGET"
- env['CXXCOMSTR'] = "Compiling $TARGET"
- env['SHCXXCOMSTR'] = "Compiling $TARGET"
- env['LINKCOMSTR'] = "Linking $TARGET"
- env['SHLINKCOMSTR'] = "Linking $TARGET"
- env['ARCOMSTR'] = "Archiving $TARGET"
- env['RANLIBCOMSTR'] = "Indexing Archive $TARGET"
+ env['CCCOMSTR'] = "Compiling $TARGET"
+ env['SHCCCOMSTR'] = "Compiling $TARGET"
+ env['CXXCOMSTR'] = "Compiling $TARGET"
+ env['SHCXXCOMSTR'] = "Compiling $TARGET"
+ env['LINKCOMSTR'] = "Linking $TARGET"
+ env['SHLINKCOMSTR'] = "Linking $TARGET"
+ env['ARCOMSTR'] = "Archiving $TARGET"
+ env['RANLIBCOMSTR'] = "Indexing Archive $TARGET"
if target_os in targets_support_cc:
- prefix = env.get('TC_PREFIX')
- tc_path = env.get('TC_PATH')
- if prefix:
- env.Replace(CC = prefix + env.get('CC', 'gcc'))
- env.Replace(CXX = prefix + env.get('CXX', 'g++'))
- env.Replace(AR = prefix + env.get('AR', 'ar'))
- env.Replace(AS = prefix + env.get('AS', 'as'))
- env.Replace(RANLIB = prefix + env.get('RANLIB', 'ranlib'))
-
- if tc_path:
- env.PrependENVPath('PATH', tc_path)
- sys_root = os.path.abspath(tc_path + '/../')
- env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
- env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
-
- if prefix or tc_path:
- print tc_set_msg
+ prefix = env.get('TC_PREFIX')
+ tc_path = env.get('TC_PATH')
+ if prefix:
+ env.Replace(CC = prefix + env.get('CC', 'gcc'))
+ env.Replace(CXX = prefix + env.get('CXX', 'g++'))
+ env.Replace(AR = prefix + env.get('AR', 'ar'))
+ env.Replace(AS = prefix + env.get('AS', 'as'))
+ env.Replace(RANLIB = prefix + env.get('RANLIB', 'ranlib'))
+
+ if tc_path:
+ env.PrependENVPath('PATH', tc_path)
+ sys_root = os.path.abspath(tc_path + '/../')
+ env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
+ env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
+
+ if prefix or tc_path:
+ print tc_set_msg
# Import env variables only if reproductibility is ensured
if target_os in ['yocto']:
# env.get('BUILD_DIR')
def __set_dir(env, dir):
- if not os.path.exists(dir + '/SConstruct'):
- print '''
+ 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)
+ 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)
+ 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)
+ 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)
+ 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])
+ 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:
- user_lib = env.get('LIB_INSTALL_DIR')
- if user_lib:
- i_n = ienv.Install(user_lib, targets)
- else:
- i_n = ienv.Install(user_prefix + '/lib', targets)
- ienv.Alias("install", i_n)
- else:
- i_n = ienv.Install(env.get('BUILD_DIR'), targets)
- ienv.Alias("install", i_n)
+ user_prefix = env.get('PREFIX')
+ if user_prefix:
+ user_lib = env.get('LIB_INSTALL_DIR')
+ if user_lib:
+ i_n = ienv.Install(user_lib, targets)
+ else:
+ i_n = ienv.Install(user_prefix + '/lib', targets)
+ ienv.Alias("install", i_n)
+ 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)
- ienv.Alias("install", i_n)
+ user_prefix = env.get('PREFIX')
+ if user_prefix:
+ i_n = ienv.Install(user_prefix + '/bin', targets)
+ ienv.Alias("install", i_n)
def __installheader(ienv, targets, dir, name):
- user_prefix = env.get('PREFIX')
- if user_prefix:
- i_n = ienv.Install(user_prefix + '/include/' + dir ,targets)
- else:
- i_n = ienv.Install(os.path.join(env.get('BUILD_DIR'), 'include', dir), targets)
- ienv.Alias("install", i_n)
+ user_prefix = env.get('PREFIX')
+ if user_prefix:
+ i_n = ienv.Install(user_prefix + '/include/' + dir ,targets)
+ else:
+ i_n = ienv.Install(os.path.join(env.get('BUILD_DIR'), 'include', dir), targets)
+ ienv.Alias("install", i_n)
def __installpcfile(ienv, targets, name):
- user_prefix = env.get('PREFIX')
- if user_prefix:
- user_lib = env.get('LIB_INSTALL_DIR')
- if user_lib:
- i_n = ienv.Install(user_lib + '/pkgconfig', targets)
- else:
- i_n = ienv.Install(user_prefix + '/lib/pkgconfig', targets)
- else:
- i_n = ienv.Install(env.get('BUILD_DIR') + 'lib/pkgconfig', targets)
- ienv.Alias("install", i_n)
+ user_prefix = env.get('PREFIX')
+ if user_prefix:
+ user_lib = env.get('LIB_INSTALL_DIR')
+ if user_lib:
+ i_n = ienv.Install(user_lib + '/pkgconfig', targets)
+ else:
+ i_n = ienv.Install(user_prefix + '/lib/pkgconfig', targets)
+ else:
+ i_n = ienv.Install(env.get('BUILD_DIR') + 'lib/pkgconfig', targets)
+ ienv.Alias("install", i_n)
def __append_target(ienv, name, targets = None):
- if targets:
- env.Alias(name, targets)
- env.AppendUnique(TS = [name])
+ if targets:
+ env.Alias(name, targets)
+ env.AppendUnique(TS = [name])
def __print_targets(env):
- Help('''
+ Help('''
===============================================================================
Targets:\n ''')
- for t in env.get('TS'):
- Help(t + ' ')
- Help('''
+ 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]
# 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'))
+ 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