Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / examples / OICMiddle / SConstruct
1 #For Yocto builds, set OS=yocto as a command-line argument to scons once
2 #the Yocto toolchain is installed and configured.
3
4 #For Linux builds, set the following two variables:
5 #Set OIC_RESOURCE_PATH to the root of oic-resource on Ubuntu.
6
7 OIC_RESOURCE_PATH = '../..'
8
9 #Set OIC_LIBS_PATH to path on Ubuntu that contains liboc.so, liboctbstack.so,
10 #liboc_logger.so and libcoap.so.
11
12 OIC_LIBS_PATH = '../../out/linux/x86_64/release'
13
14 env = DefaultEnvironment()
15 target_os = ARGUMENTS.get("OS", "linux").lower()
16 output_dir = env.GetLaunchDir() + "/out/" + target_os
17 env.VariantDir(output_dir, env.GetLaunchDir(), duplicate=0)
18 env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
19 env.AppendUnique(LINKFLAGS = ['-pthread'])
20 env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap'])
21 env.Program(output_dir + '/OICMiddle', [output_dir + '/OICMiddle.cpp',
22                           output_dir + '/Client.cpp',
23                           output_dir + '/Server.cpp',
24                           output_dir + '/WrapResource.cpp',
25                           output_dir + '/LineInput.cpp',
26                           output_dir + '/RestInput.cpp'])
27
28 if target_os == "yocto":
29     '''
30     This code injects Yocto cross-compilation flags into scons' default environment
31     in order to invoke the relevant tools while performing a build.
32     '''
33     import os.path, re
34     sdk_root = ''
35     try:
36         CC = os.environ['CC']
37         sdk_root = re.search(r'--sysroot=\S+', CC).group().split('=')[1]
38         target_prefix = CC.split()[0]
39         target_prefix = target_prefix[:len(target_prefix)-3]
40         tools = {"CC" : target_prefix+"gcc",
41                  "CXX" : target_prefix+"g++",
42                  "AS" : target_prefix+"as",
43                  "LD" : target_prefix+"ld",
44                  "GDB" : target_prefix+"gdb",
45                  "STRIP" : target_prefix+"strip",
46                  "RANLIB" : target_prefix+"ranlib",
47                  "OBJCOPY" : target_prefix+"objcopy",
48                  "OBJDUMP" : target_prefix+"objdump",
49                  "AR" : target_prefix+"ar",
50                  "NM" : target_prefix+"nm",
51                  "M4" : "m4",
52                  "STRINGS": target_prefix+"strings"}
53         PATH = os.environ['PATH'].split(os.pathsep)
54         for tool in tools:
55             if tool in os.environ:
56                 for path in PATH:
57                     if os.path.isfile(os.path.join(path, tools[tool])):
58                         env[tool] = os.path.join(path, os.environ[tool])
59         env.AppendUnique(CPPPATH = [
60                 sdk_root + '/usr/include/oic/',
61                 sdk_root + '/usr/include/oic/stack/',
62                 sdk_root + '/usr/include/oic/ocsocket/',
63                 sdk_root + '/usr/include/oic/oc_logger/',
64                 ])
65     except:
66         print "ERROR configuring Yocto cross-toolchain environment."
67         Exit(1)
68 elif target_os == "linux":
69     if OIC_RESOURCE_PATH == '' or OIC_LIBS_PATH == '':
70         print "ERROR Please set both OIC_RESOURCE_PATH and OIC_LIBS_PATH in SConstruct"
71         Exit(1)
72     env.AppendUnique(CPPPATH = [
73                 OIC_RESOURCE_PATH + '/resource/include',
74                 OIC_RESOURCE_PATH + '/resource/csdk/stack/include',
75                 OIC_RESOURCE_PATH + '/resource/csdk/ocsocket/include',
76                 OIC_RESOURCE_PATH + '/resource/oc_logger/include',
77                 ])
78     env.AppendUnique(LIBPATH = [OIC_LIBS_PATH])
79 else:
80     print "ERROR ", target_os, " is an unsupported target"
81     Exit(1)