riscv64: Add support for RISC-V
[platform/upstream/iotivity.git] / resource / csdk / connectivity / build / SConscript
index 55eb3c6..946dd49 100644 (file)
@@ -8,21 +8,20 @@ import platform
 # Map of host os and allowed target os (host: allowed target os)
 host_target_map = {
                'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
-               'windows': ['windows', 'winrt', 'android', 'arduino'],
+               'windows': ['windows', 'android', 'arduino'],
                'darwin': ['darwin', 'ios', 'android', 'arduino'],
                }
 
 # Map of os and allowed archs (os: allowed archs)
 os_arch_map = {
                'linux': ['x86', 'x86_64', 'arm', 'arm64'],
-               'tizen': ['x86', 'x86_64', 'arm', 'arm64'],
+               'tizen': ['x86', 'x86_64', 'arm', 'arm64', 'riscv64'],
                'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
                'windows': ['x86', 'amd64', 'arm'],
-               'winrt': ['arm'],
                'darwin': ['i386', 'x86_64'],
                'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
                'arduino': ['avr', 'arm'],
-               'yocto': ['x86', 'x86_64'],
+                'yocto': ['i586', 'i686', 'x86_64', 'arm', 'aarch64', 'powerpc', 'powerpc64', 'mips', 'mipsel'],
                }
 
 host = platform.system().lower()
@@ -58,19 +57,33 @@ device_name = ARGUMENTS.get('DEVICE_NAME', "OIC-DEVICE")
 ######################################################################
 help_vars = Variables()
 help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
+help_vars.Add(BoolVariable('LOGGING', 'Enable stack logging', False))
 help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
-help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'WIFI', 'BT', 'BLE', 'ETHERNET']))
+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(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload))
+help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP')))
 help_vars.Add(EnumVariable('BUILD_SAMPLE', 'Build with sample', 'ON', allowed_values=('ON', 'OFF')))
+help_vars.Add(BoolVariable('WITH_TCP', 'Enable TCP', False))
+help_vars.Add(BoolVariable('DISABLE_TCP_SERVER', 'Disable TCP server', False))
+help_vars.Add(BoolVariable('DISABLE_BLE_SERVER', 'Disable BLE server', False))
+help_vars.Add(ListVariable('WITH_MQ', 'Build with MQ publisher/subscriber/broker', 'OFF', ['OFF', 'SUB', 'PUB', 'BROKER']))
 
 help_vars.AddVariables(('DEVICE_NAME', 'Network display name for device', 'OIC-DEVICE', None, None),)
-       
+
+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', 'tizen', 'android']
+targets_support_cc = ['linux', 'arduino', 'tizen']
 
 if target_os in targets_support_cc:
        # Set cross compile toolchain
@@ -84,7 +97,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))
 
@@ -141,9 +154,9 @@ def __set_dir(env, dir):
                Exit(1)
 
        if env.get('RELEASE'):
-               build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
+               build_dir = os.path.join(dir, 'out', target_os, target_arch, 'release') + os.sep
        else:
-               build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
+               build_dir = os.path.join(dir, 'out', target_os, target_arch, 'debug') + os.sep
        env.VariantDir(build_dir, dir, duplicate=0)
 
        env.Replace(BUILD_DIR = build_dir)
@@ -160,6 +173,21 @@ 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:
+               install_lib_dir = os.path.join(user_prefix, 'lib')
+       else:
+               install_lib_dir = os.path.join(env.get('BUILD_DIR'), 'lib')
+       i_n = ienv.Install(install_lib_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)
+
 def __append_target(ienv, target):
        env.AppendUnique(TS = [target])
 
@@ -181,6 +209,8 @@ 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()+'/..'
 
@@ -220,6 +250,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)
@@ -232,7 +263,19 @@ if target_os == "yocto":
     We want to preserve debug symbols to allow BitBake to generate both DEBUG and
     RELEASE packages for OIC.
     '''
-    env['CCFLAGS'].append('-g')
+    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', '-fPIC'])
+    if target_os in ['linux']:
+        env.AppendUnique(LIBS = ['dl', 'pthread'])
     Export('env')
 else:
     '''
@@ -254,4 +297,3 @@ if env.GetOption('clean'):
                Execute(Delete(dir + '/.sconf_temp'))
 
 Return('env')
-