iotivity 0.9.0
[platform/upstream/iotivity.git] / examples / OICSensorBoard / SConstruct
1 #This script builds edisonclient for Ubuntu and edisonserver for Yocto. 
2
3 #Client build for Ubuntu
4 #Set IOTIVITY_ROOT to the root of oic-resource on Ubuntu.
5 IOTIVITY_ROOT = '' 
6 #Set IOTIVITY_LIBS_PATH to path on Ubuntu that contains liboc.so, liboctbstack.so, liboc_logger.so and libcoap.so.               
7 IOTIVITY_LIBS_PATH = ''
8
9 env = DefaultEnvironment()
10 env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
11 env.AppendUnique(LINKFLAGS = ['-pthread'])
12 env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap'])
13
14 envClient = env.Clone()
15 envClient.AppendUnique(CPPPATH = [
16                 IOTIVITY_ROOT + '/resource/include', 
17                 IOTIVITY_ROOT + '/resource/csdk/stack/include',
18                 IOTIVITY_ROOT + '/resource/csdk/ocsocket/include',
19                 IOTIVITY_ROOT + '/resource/oc_logger/include',
20                 ])
21 envClient.AppendUnique(LIBPATH = [IOTIVITY_LIBS_PATH])
22 envClient.Program('edisonclient', 'client.cpp')
23
24 #Server build
25 envServer = env.Clone()
26 '''
27 This code injects Yocto cross-compilation flags into scons' default environment
28 in order to invoke the relevant tools while performing a build.
29 '''
30 import os.path, re
31 sdk_root = ''
32 try:
33     CC = os.environ['CC']
34     sdk_root = re.search(r'--sysroot=\S+', CC).group().split('=')[1]
35     target_prefix = CC.split()[0]
36     target_prefix = target_prefix[:len(target_prefix)-3]
37     tools = {"CC" : target_prefix+"gcc",
38              "CXX" : target_prefix+"g++",
39              "AS" : target_prefix+"as",
40              "LD" : target_prefix+"ld",
41              "GDB" : target_prefix+"gdb",
42              "STRIP" : target_prefix+"strip",
43              "RANLIB" : target_prefix+"ranlib",
44              "OBJCOPY" : target_prefix+"objcopy",
45              "OBJDUMP" : target_prefix+"objdump",
46              "AR" : target_prefix+"ar",
47              "NM" : target_prefix+"nm",
48              "M4" : "m4",
49              "STRINGS": target_prefix+"strings"}
50     PATH = os.environ['PATH'].split(os.pathsep)
51     for tool in tools:
52         if tool in os.environ:
53             for path in PATH:
54                     if os.path.isfile(os.path.join(path, tools[tool])):
55                         envServer[tool] = os.path.join(path, os.environ[tool])
56     envServer.Program('edisonserver', ['server.cpp', 'observer.cpp'])
57     envServer.AppendUnique(LIBS = ['mraa'])
58     envServer.AppendUnique(CPPPATH = [
59                 sdk_root + '/usr/include/iotivity/',
60                 sdk_root + '/usr/include/iotivity/stack/',
61                 sdk_root + '/usr/include/iotivity/ocsocket/',
62                 sdk_root + '/usr/include/iotivity/oc_logger/',
63                 ])                      
64 except:
65     print "ERROR configuring Yocto cross-toolchain environment. This is required for building the server"