Fix x86 and x86_64 build errors
authorCaiwen Zhang <caiwen.zhang@intel.com>
Fri, 3 Apr 2015 06:26:40 +0000 (14:26 +0800)
committerErich Keane <erich.keane@intel.com>
Wed, 8 Apr 2015 16:54:15 +0000 (16:54 +0000)
1) fix linux x86 cross compile error
2) fix android x86_64 build error

Change-Id: I07f8f821b596712766f9f7330020a22e23e4b66a
Signed-off-by: Caiwen Zhang<caiwen.zhang@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/642
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
build_common/android/SConscript
build_common/arduino/SConscript
extlibs/boost/SConscript
resource/csdk/SConscript [changed mode: 0755->0644]
service/protocol-plugin/SConscript
service/protocol-plugin/sample-app/SConscript
service/protocol-plugin/sample-app/linux/SConscript

index 21c5fbe..17eb348 100644 (file)
@@ -126,7 +126,6 @@ for flags in p.stdout.readlines():
        elif cmp(flags[0:8], 'SYSROOT=') == 0:
                sysroot = flags[8:].strip()
                env.AppendUnique(LINKFLAGS = ['--sysroot=' + sysroot])
-               env.AppendUnique(LIBPATH = [sysroot + '/usr/lib'])
 
        elif cmp(flags[0:8], 'LDFLAGS=') == 0:
                env.AppendUnique(LINKFLAGS = Split(flags[8:]))
index d635a66..5df0318 100644 (file)
@@ -113,11 +113,13 @@ def __import_lib(env, lib):
        lib_src.extend(__search_files(lib_path, '*.c'))
        lib_src.extend(__search_files(lib_path, '*.cpp'))
 
-       build_dir = env.get('BUILD_DIR')
-       if build_dir:
-               lib_a = env.StaticLibrary(build_dir + lib, __src_to_obj(env, lib_src))
-       else:
-               lib_a = env.StaticLibrary(lib, __src_to_obj(env, lib_src))
+       prefix = env.get('BOARD') + '_'
+       if env.get('CPU'):
+               prefix += env.get('CPU') + '_'
+
+       lib = env.get('BUILD_DIR', '.') + '/arduino/' + prefix + lib
+       lib_a = env.StaticLibrary(lib, __src_to_obj(env, lib_src))
+
        env.AppendUnique(LIBS = [File(lib_a[0])])
 
 def __build_core(env):
@@ -130,11 +132,14 @@ def __build_core(env):
        core_src.extend(__search_files(variant_folder, '*.cpp'))
 
        core_obj = __src_to_obj(env, core_src)
-       build_dir = env.get('BUILD_DIR')
-       if build_dir:
-               s_core = env.StaticLibrary(build_dir + 'core', core_obj)
-       else:
-               s_core = env.StaticLibrary('core', core_obj)
+
+       prefix = env.get('BOARD') + '_'
+       if env.get('CPU'):
+               prefix += env.get('CPU') + '_'
+
+       core = env.get('BUILD_DIR', '.') + '/arduino/' + prefix + 'core'
+       s_core = env.StaticLibrary(core, core_obj)
+
        env.AppendUnique(LIBS = [File(s_core[0])])
 
        # To avoid compiler issue. Otherewise there may be warnings:
index f4c0858..2cefa8b 100644 (file)
@@ -7,6 +7,7 @@ boost_env = env.Clone()
 modules = ['thread','program_options']
 
 target_os = env.get('TARGET_OS')
+target_arch = env.get('TARGET_ARCH')
 
 boost_version   = '1.57.0'
 boost_base_name  = 'boost_'+string.replace(boost_version,'.','_')
@@ -27,50 +28,63 @@ boost_zip = boost_env.Download(boost_arch_name, boost_url)
 
 # Unpack source code
 if not os.path.exists(boost_bootstrap):
-       boost_env.UnpackAll(boost_bootstrap, boost_zip)
+    boost_env.UnpackAll(boost_bootstrap, boost_zip)
+
+# Fix android x86_64 build error due to missing asm/page.h
+if target_os == 'android':
+    file_object = open(boost_base_name + '/boost/thread/pthread/thread_data.hpp', 'r+')
+    try:
+        content = file_object.read()
+        idx = content.find('#include <asm/page.h>')
+        if idx > 0 :
+            if content[idx -1] != '/' :
+                content = content.replace('#include <asm/page.h>', '//#include <asm/page.h>')
+                file_object.seek(0)
+                file_object.write(content)
+    finally:
+        file_object.close( )
 
 # Run bootstrap.sh
 if not os.path.exists(boost_b2_name):
-       boost_env.Configure(boost_base_name, './bootstrap.sh')
+    boost_env.Configure(boost_base_name, './bootstrap.sh')
 
 cmd = None
 
 # Windows...
 if boost_env["PLATFORM"] in ["win32"] :
-       if boost_env.WhereIs("cmd") :
-               # TODO: Add Windows Support
-               cmd = None
+    if boost_env.WhereIs("cmd") :
+        # TODO: Add Windows Support
+        cmd = None
 
 # read the tools on *nix systems and sets the default parameters
 elif boost_env["PLATFORM"] in ["darwin", "linux", "posix"] :
-       if boost_env.WhereIs("sh") :
-               cmd = ['./b2']
+    if boost_env.WhereIs("sh") :
+        cmd = ['./b2']
 
 if not cmd :
-       raise SCons.Errors.StopError("Boost build system not supported on this platform [%s]" % (boost_env["PLATFORM"]))
+    raise SCons.Errors.StopError("Boost build system not supported on this platform [%s]" % (boost_env["PLATFORM"]))
 
 # We need to be in the target's directory
 cwd = boost_base_name
 
 # Gather all of the path, bin and flags
 version     = boost_env.get('VERSION','')
-target_os   = boost_env['TARGET_OS']
-target_arch = boost_env['TARGET_ARCH']
 tool_path   = os.path.dirname(boost_env['CXX'])
 cxx_bin     = os.path.basename(boost_env['CXX'])
 ar_bin      = os.path.basename(boost_env['AR'])
 ranlib_bin  = os.path.basename(boost_env['RANLIB'])
-ccflags     = list(boost_env['CFLAGS'])
+cflags     = list(boost_env['CFLAGS'])
+ccflags    = list(boost_env['CCFLAGS'])
 cxxflags    = list(boost_env['CXXFLAGS'])
 
 try:
-       cxxflags.remove('-fno-rtti')
+    cxxflags.remove('-fno-rtti')
 except ValueError:
-       pass
+    pass
 try:
-       cxxflags.remove('-fno-exceptions')
+    cxxflags.remove('-fno-exceptions')
 except ValueError:
-       pass
+    pass
 
 # Write a user-config for this variant
 user_config_name = os.path.join(cwd, 'tools', 'build', 'src', 'user-config.jam')
@@ -84,16 +98,18 @@ user_config_file.write(' '+cxx_bin+' :\n')
 user_config_file.write('    <archiver>'+ar_bin+'\n')
 user_config_file.write('    <ranlib>'+ranlib_bin+'\n')
 for value in boost_env['CPPDEFINES'] :
-       if len(value) > 1 :
-               user_config_file.write('    <compileflags>-D'+value[0]+'='+value[1]+'\n')
-       else :
-               user_config_file.write('    <compileflags>-D'+value[0]+'\n')
+    if len(value) > 1 :
+        user_config_file.write('    <compileflags>-D'+value[0]+'='+value[1]+'\n')
+    else :
+        user_config_file.write('    <compileflags>-D'+value[0]+'\n')
 for value in boost_env['CPPPATH'] :
-       user_config_file.write('    <compileflags>-I'+value+'\n')
+    user_config_file.write('    <compileflags>-I'+value+'\n')
 for flag in ccflags :
-       user_config_file.write('    <compileflags>'+flag+'\n')
+    user_config_file.write('    <compileflags>'+flag+'\n')
+for flag in cflags :
+    user_config_file.write('    <cflags>'+flag+'\n')
 for flag in cxxflags :
-       user_config_file.write('    <cxxflags>'+flag+'\n')
+    user_config_file.write('    <cxxflags>'+flag+'\n')
 user_config_file.write('    ;\n')
 user_config_file.close();
 
@@ -112,7 +128,7 @@ cmd.append('--build-type=minimal')
 cmd.append('--prefix='+ build_path + os.sep + 'install_tmp')
 cmd.append('--build-dir='+build_path)
 for module in modules :
-       cmd.append('--with-'+module)
+    cmd.append('--with-'+module)
 cmd.append('headers')
 cmd.append('install')
 
@@ -122,12 +138,12 @@ print "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name)
 handle  = subprocess.Popen(cmd, env=penv, cwd=cwd)#, stdout=devnull )
 
 if handle.wait() <> 0 :
-       raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name) )
+    raise SCons.Errors.BuildError( "Building boost [%s] on the source [%s]" % (cmd, boost_b2_name) )
 
 # Use Copy instead of InstallXXX to make sure boost is installed immediately
 Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'include'),
-       os.path.join(boost_base_name, build_path, 'install_tmp', 'include')))
+    os.path.join(boost_base_name, build_path, 'install_tmp', 'include')))
 
 Execute(Copy(os.path.join(env.get('SRC_DIR'), 'deps', target_os, 'lib', target_arch),
-       os.path.join(boost_base_name, build_path, 'install_tmp', 'lib')))
+    os.path.join(boost_base_name, build_path, 'install_tmp', 'lib')))
 
old mode 100755 (executable)
new mode 100644 (file)
index ad6c5c2..c15a878
@@ -38,6 +38,9 @@ if target_os not in ['windows', 'winrt']:
 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 liboctbstack_env.AppendUnique(LIBS = ['coap', 'm'])
 
+if target_os not in ['android', 'arduino', 'windows', 'winrt']:
+       liboctbstack_env.AppendUnique(LIBS = ['pthread'])
+
 if target_os == 'arduino':
        liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
 
index d8db971..909f8e6 100644 (file)
@@ -1,13 +1,16 @@
 ##
 # protocol plugin build script
 ##
+import platform
+
 Import('env')
 
 SConscript('lib/cpluff/SConscript')
 SConscript('plugin-manager/SConscript')
 
-#The code include pthread_cancel method, can't build on android
-if env.get('TARGET_OS') != 'android':
+# The code include pthread_cancel method, can't build on android
+# MQTT requires openssl, forbid cross compile as it isn't ready
+if env.get('TARGET_OS') != 'android' and env.get('TARGET_ARCH') == platform.machine():
        SConscript('plugins/SConscript')
 
 SConscript('sample-app/SConscript')
index 413dd94..f0d28d2 100644 (file)
@@ -1,10 +1,12 @@
 ##
 #sample-app build script
 ##
+import platform
 
 Import('env')
 
 target_os = env.get('TARGET_OS')
 
 if target_os == 'linux':
-       SConscript('linux/SConscript')
+    if env.get('TARGET_ARCH') == platform.machine():
+        SConscript('linux/SConscript')
index 258b4fb..7629c55 100644 (file)
@@ -21,8 +21,8 @@ sample_env.AppendUnique(CPPPATH = [
 if target_os not in ['windows', 'winrt']:
        sample_env.AppendUnique(CXXFLAGS = ['-Wall', '-pthread'])
 
-sample_env.AppendUnique(LIBS = ['oc', 'oc_logger', 'octbstack', 'coap', 'ppm', 'pmimpl', 'boost_system', 'boost_thread', 'dl'])
-sample_env.AppendUnique(LIBS = ['pthread'])
+sample_env.AppendUnique(LIBS = ['oc', 'oc_logger', 'octbstack', 'coap', 'ppm',
+       'pmimpl', 'boost_system', 'boost_thread', 'dl', 'pthread', 'expat'])
 
 ######################################################################
 # Source files and Targets