From: Kishen Maloor Date: Wed, 17 Dec 2014 01:43:22 +0000 (-0800) Subject: OIC scons build patch for Yocto X-Git-Tag: 0.9.0-CM-RC1~8^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=585ea764d6919815454632f93422b3c348233f0b;p=contrib%2Fiotivity.git OIC scons build patch for Yocto Function: Adds Yocto as a build target for OIC. Code is executed ONLY when TARGET_OS=yocto. It WILL NOT affect a build for any other target. Background: Yocto cross-toolchains for platforms would have to be fetched, installed and configured in their standard way. This configuration is done by sourcing in an “environment setup” script that comes with the toolchain. scons is run after this step. Details: The code in this patch reads the variables set by Yocto’s script and: 1) Learns of tool names and build flags (varies by target and arch.), 2) Finds absolute path of these tools (yocto’s script adds these to PATH) by looking in PATH, 3) Modifies the scons construction environment to point to tools + all their required flags, 4) Switches TARGET_OS to Linux so that it uses the Linux build configuration for OIC, 5) Elects to preserve debug symbols (using -g) so that Yocto’s build process can generate both DEBUG and RELEASE packages for OIC (This is the default recommendation of Yocto’s BitBake) Additional notes: -The pre-existing TC_PREFIX/TC_PATH framework is not sufficient to support Yocto’s cross-toolchain. -Supported architectures for the yocto target are x86 and x86_64. These have been tested to work for Intel Edison and Minnowboard platforms. Usage: From a user’s perspective, there are no unexpected steps. 1) source 2) …/oic-resource$ scons TARGET_OS=yocto For eg. “scons TARGET_OS=yocto TARGET_ARCH=x86 RELEASE=1” The results of a build will now go into “out/yocto/x86/…”. If step 1) hasn’t been done before step 2), the build will fail with an error message. Change-Id: I55efab20f9c174f46446e9d59e3fca6eef3df7f2 Signed-off-by: Kishen Maloor --- diff --git a/build_common/SConscript b/build_common/SConscript index c6708e4..dd1fb3b 100644 --- a/build_common/SConscript +++ b/build_common/SConscript @@ -7,7 +7,7 @@ import platform # Map of host os and allowed target os (host: allowed target os) host_target_map = { - 'linux': ['linux', 'android', 'arduino'], + 'linux': ['linux', 'android', 'arduino', 'yocto'], 'windows': ['windows', 'winrt', 'android', 'arduino'], 'darwin': ['darwin', 'ios', 'android', 'arduino'], } @@ -21,6 +21,7 @@ os_arch_map = { 'darwin': ['i386', 'x86_64'], 'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'], 'arduino': ['avr', 'arm'], + 'yocto': ['x86', 'x86_64'], } host = platform.system().lower() @@ -167,8 +168,60 @@ env.SetDir(env.GetLaunchDir()) Export('env') -# Load config of target os -env.SConscript(target_os + '/SConscript') +###################################################################### +# 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 + 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['CCFLAGS'].append('-g') + 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'):