X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=build_common%2FSConscript;h=7f4c6504a4d10808f894be9cc13a7f8d94c1ae8c;hb=9b4d2db29adf50c9b502349197e54345804c390c;hp=22501f23c351816a91d15920411ccddb855894ba;hpb=49b334b7cca00c924001c8e2620aee08577b5dff;p=platform%2Fupstream%2Fiotivity.git diff --git a/build_common/SConscript b/build_common/SConscript index 22501f2..7f4c650 100644 --- a/build_common/SConscript +++ b/build_common/SConscript @@ -22,7 +22,7 @@ os_arch_map = { 'darwin': ['i386', 'x86_64'], 'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'], 'arduino': ['avr', 'arm'], - 'yocto': ['x86', 'x86_64'], + 'yocto': ['i586', 'x86_64', 'arm', 'powerpc', 'powerpc64', 'mips', 'mipsel'], } host = platform.system().lower() @@ -40,24 +40,74 @@ 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) -default_arch = platform.machine() +if target_os == 'android': + default_arch = 'x86' +else: + default_arch = platform.machine() + if default_arch not in os_arch_map[target_os]: default_arch = os_arch_map[target_os][0].lower() target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch +# True if binary needs to be installed on board. (Might need root permissions) +# set to 'no', 'false' or 0 for only compilation +require_upload = ARGUMENTS.get('UPLOAD', False) + +# Get the device name. This name can be used as network display name wherever possible +device_name = ARGUMENTS.get('DEVICE_NAME', "OIC-DEVICE") + +if ARGUMENTS.get('TEST'): + 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) + + + ###################################################################### # Common build options (release, target os, target arch) ###################################################################### +targets_disallow_multitransport = ['arduino', 'android'] + help_vars = Variables() +help_vars.Add(BoolVariable('VERBOSE', 'Show compilation', False)) help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host])) + + +help_vars.Add(BoolVariable('WITH_RA', 'Build with Remote Access module', False)) + +if target_os in targets_disallow_multitransport: + help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP'])) +else: + help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP'])) + 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'))) +help_vars.Add(EnumVariable('TEST', 'Run unit tests', '0', allowed_values=('0', '1'))) +help_vars.Add(BoolVariable('LOGGING', 'Enable stack logging', logging_default)) +help_vars.Add(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload)) +help_vars.Add(EnumVariable('BUILD_SAMPLE', 'Build with sample', 'ON', allowed_values=('ON', 'OFF'))) +help_vars.AddVariables(('DEVICE_NAME', 'Network display name for device (For Arduino)', device_name, None, None),) +help_vars.Add(PathVariable('ANDROID_NDK', 'Android NDK path', None, PathVariable.PathAccept)) +help_vars.Add(PathVariable('ANDROID_HOME', 'Android SDK path', None, PathVariable.PathAccept)) +help_vars.Add(PathVariable('ANDROID_GRADLE', 'Gradle binary file', None, PathVariable.PathIsFile)) + +AddOption('--prefix', + dest='prefix', + type='string', + nargs=1, + action='store', + metavar='DIR', + help='installation prefix') ###################################################################### # Platform(build target) specific options: SDK/NDK & toolchain ###################################################################### -targets_support_cc = ['linux', 'arduino'] +targets_support_cc = ['linux', 'arduino', 'tizen'] if target_os in targets_support_cc: # Set cross compile toolchain @@ -71,7 +121,7 @@ if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compil tools = ['gnulink', 'gcc', 'g++', 'ar', 'as'] ) else: - env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os) + env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os, PREFIX = GetOption('prefix')) Help(help_vars.GenerateHelpText(env)) @@ -82,6 +132,15 @@ tc_set_msg = ''' * cause inexplicable errors. * ******************************************************************************* ''' +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" if target_os in targets_support_cc: prefix = env.get('TC_PREFIX') @@ -95,7 +154,7 @@ if target_os in targets_support_cc: if tc_path: env.PrependENVPath('PATH', tc_path) - sys_root = os.path.abspath(os.path.join(tc_path, '..')) + sys_root = os.path.abspath(tc_path + '/../') env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root]) env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root]) @@ -114,7 +173,7 @@ env.SConscriptChdir(1) # env.get('BUILD_DIR') def __set_dir(env, dir): - if not os.path.exists(os.path.join(dir, 'SConstruct')): + if not os.path.exists(dir + '/SConstruct'): print ''' *************************************** Error ********************************* * The directory(%s) seems isn't a source code directory, no SConstruct file is @@ -123,11 +182,10 @@ def __set_dir(env, dir): ''' % dir Exit(1) - build_dir = os.path.join(dir, 'out', target_os, target_arch) if env.get('RELEASE'): - build_dir = os.path.join(build_dir, 'release') + build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/' else: - build_dir = os.path.join(build_dir, 'debug') + build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/' env.VariantDir(build_dir, dir, duplicate=0) env.Replace(BUILD_DIR = build_dir) @@ -144,6 +202,22 @@ def __install(ienv, targets, name): 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) @@ -167,7 +241,10 @@ 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') @@ -176,8 +253,8 @@ Export('env') ###################################################################### if target_os == "yocto": ''' - This code injects Yocto cross-compilation tools+flags into scons' - build environment in order to invoke the relevant tools while + 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 @@ -205,6 +282,7 @@ if target_os == "yocto": 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) @@ -215,55 +293,28 @@ if target_os == "yocto": env['TARGET_OS'] = 'linux' ''' We want to preserve debug symbols to allow BitBake to generate both DEBUG and - RELEASE packages for OIC. + RELEASE packages for OIC. + ''' + env.AppendUnique(CCFLAGS = ['-g']) + ''' + Additional flags to pass to the Yocto toolchain. ''' - env['CCFLAGS'].append('-g') + 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 - if target_os in ['linux', 'tizen']: - env.SConscript('linux/SConscript') - else: - env.SConscript(target_os + '/SConscript') - -# ------------------------------------------------------------------- -# Configure the build as needed, e.g. detecting and setting -# appropriate build flags, etc. -# -# This is done after the platform-specific configuration is loaded to -# make sure we give the automated build configuration below an -# opportunity to detect platform-specific anomalies. -# ------------------------------------------------------------------- -Import('targets_csdk_only') -import iotivityconfig -from iotivityconfig import * - -conf = env.Configure( - custom_tests = { - 'CheckC99Flags' : iotivityconfig.check_c99_flags, - 'CheckCXX11Flags' : iotivityconfig.check_cxx11_flags - } ) - -# IoTivity requires support for C99 for the C SDK. -if not conf.CheckC99Flags(): - print('C99 support is required!') - Exit(1) - -# IoTivity requires support for C++11 for the C++ SDK. -# -# However, some platforms, such as Arduino, only support the C SDK. -# Don't bother running the C++11 check in those cases. -if target_os not in targets_csdk_only and not conf.CheckCXX11Flags(): - print('C++11 support is required!') - Exit(1) - -env = conf.Finish() -# ------------------------------------------------------------------- - -env.SConscript('external_libs.scons') + env.SConscript(target_os + '/SConscript') # Delete the temp files of configuration if env.GetOption('clean'): @@ -271,31 +322,30 @@ if env.GetOption('clean'): 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 if C/C++ compiler is installed -cc = env.get('CC', '') -cxx = env.get('CXX', '') +###################################################################### +# Check for PThreads support +###################################################################### +import iotivityconfig +from iotivityconfig import * -if not cc: - print ''' -*************************************** Error ********************************* -* * -* Didn't find C compiler, please install C compiler (e.g. gcc >= 4.6). * -* * -******************************************************************************* -''' - Exit(1) +conf = Configure(env, + custom_tests = + { + 'CheckPThreadsSupport' : iotivityconfig.check_pthreads + } ) -if not cxx: - print ''' -*************************************** Error ********************************* -* * -* Didn't find C++ compiler, please install C++ compiler (e.g. g++ >= 4.6) * -* * -******************************************************************************* -''' - Exit(1) +# 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() +###################################################################### +env.SConscript('external_libs.scons') Return('env')