1 #******************************************************************
3 # Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 # liboctbstack (share library) build script
26 liboctbstack_env = env.Clone()
29 SConscript('samples/SConscript', exports = { 'stacksamples_env' : liboctbstack_env })
31 SConscript('#resource/third_party_libs.scons', exports = { 'lib_env' : liboctbstack_env })
33 target_os = env.get('TARGET_OS')
34 rd_mode = env.get('RD_MODE')
35 with_ra = env.get('WITH_RA')
36 with_ra_ibb = env.get('WITH_RA_IBB')
37 with_tcp = env.get('WITH_TCP')
38 with_mq = env.get('WITH_MQ')
39 # As in the source code, it includes arduino Time library (C++)
40 # It requires compile the .c with g++
41 if target_os == 'arduino':
42 liboctbstack_env.Replace(CC = env.get('CXX'))
43 liboctbstack_env.Replace(CFLAGS = env.get('CXXFLAGS'))
45 ######################################################################
47 ######################################################################
48 with_upstream_libcoap = liboctbstack_env.get('WITH_UPSTREAM_LIBCOAP')
49 if with_upstream_libcoap == '1':
50 # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
51 liboctbstack_env.PrependUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
53 # For bring up purposes only, the forked version will live here.
54 liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/connectivity/lib/libcoap-4.1.1/include'])
56 liboctbstack_env.PrependUnique(CPPPATH = [
58 '#resource/csdk/logger/include',
59 '#resource/csdk/include',
62 '#resource/oc_logger/include',
63 '#resource/csdk/connectivity/common/inc',
64 '#resource/csdk/connectivity/inc',
65 '#resource/csdk/connectivity/inc/pkix',
66 '#resource/csdk/connectivity/api',
67 '#resource/csdk/connectivity/external/inc',
68 '#resource/csdk/security/include',
69 '#resource/csdk/security/include/internal',
70 '#resource/csdk/security/provisioning/include',
74 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
76 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
77 if 'BROKER' in with_mq:
78 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
80 if target_os not in ['arduino', 'windows']:
81 liboctbstack_env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '_GNU_SOURCE'])
82 liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
84 if liboctbstack_env.get('ROUTING') == 'GW':
85 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
86 elif liboctbstack_env.get('ROUTING') == 'EP':
87 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
89 if target_os not in ['windows']:
90 liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
92 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
94 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap', 'timer'])
96 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
97 liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
99 if env.get('SECURED') == '1':
100 liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto', 'tinydtls'])
102 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
103 liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
106 liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
109 liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
111 if target_os not in ['windows', 'msys_nt']:
112 liboctbstack_env.AppendUnique(LIBS = ['m'])
114 # octbstack.def specifies the list of functions exported by octbstack.dll.
115 liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
117 if env.get('SECURED') != '1':
118 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def')])
120 # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
121 liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
124 liboctbstack_env.Textfile(target = 'octbstack_temp.def', source = [File('octbstack_product.def'), File('octbstack_product_with_tcp.def')])
126 liboctbstack_env.Textfile(target = 'octbstack_temp.def', source = [File('octbstack_product.def')])
128 if env.get('MULTIPLE_OWNER') == '1':
129 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp.def'), File('octbstack_product_secured.def'), File('octbstack_product_secured_mot.def')])
131 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp.def'), File('octbstack_product_secured.def')])
133 if target_os in ['tizen', 'linux']:
134 liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
135 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
137 if target_os == 'arduino':
138 liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
139 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
140 liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
141 if target_os in ['darwin', 'ios']:
142 env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
143 liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
144 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
145 if target_os not in ['arduino', 'windows']:
146 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
147 if target_os == 'android':
148 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
150 if env.get('LOGGING'):
151 liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
153 liboctbstack_env.Append(LIBS = ['c_common'])
155 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
156 liboctbstack_env.Prepend(LIBS = ['routingmanager'])
158 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
159 liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/resource-directory/include'])
160 if 'CLIENT' in rd_mode:
161 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
162 if 'SERVER' in rd_mode:
163 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
164 if target_os in ['tizen']:
165 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
167 liboctbstack_env.AppendUnique(CPPPATH = ['#extlibs/sqlite3'])
169 ######################################################################
170 # Source files and Targets
171 ######################################################################
172 OCTBSTACK_SRC = 'src/'
174 OCTBSTACK_SRC + 'ocstack.c',
175 OCTBSTACK_SRC + 'ocpayload.c',
176 OCTBSTACK_SRC + 'ocpayloadparse.c',
177 OCTBSTACK_SRC + 'ocpayloadconvert.c',
178 OCTBSTACK_SRC + 'occlientcb.c',
179 OCTBSTACK_SRC + 'ocresource.c',
180 OCTBSTACK_SRC + 'ocobserve.c',
181 OCTBSTACK_SRC + 'ocserverrequest.c',
182 OCTBSTACK_SRC + 'occollection.c',
183 OCTBSTACK_SRC + 'oicgroup.c',
184 OCTBSTACK_SRC + 'ocendpoint.c'
188 liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
190 if 'SERVER' in rd_mode:
191 liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
192 if target_os not in ['linux', 'tizen']:
193 liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c')
195 if target_os in ['linux']:
196 # Linux uses a Shared library because SCons chooses the shared library on Linux
197 # when only 'octbstack' is added to the LIBS.
198 # TODO: Switch Linux to use a Static library for testing like every other OS.
199 test_liboctbstack = liboctbstack_env.SharedLibrary('octbstack_test', liboctbstack_src)
201 test_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_test', liboctbstack_src)
203 octbstack_libs = Flatten(test_liboctbstack)
205 if target_os in ['windows', 'msys_nt']:
206 # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
207 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
209 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
211 octbstack_libs += Flatten(static_liboctbstack)
213 if target_os not in ['arduino','darwin','ios'] :
214 shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
215 octbstack_libs += Flatten(shared_liboctbstack)
216 liboctbstack_env.UserInstallTargetHeader('include/ocstack.h', 'resource', 'ocstack.h')
217 liboctbstack_env.UserInstallTargetHeader('include/ocpresence.h', 'resource', 'ocpresence.h')
219 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
220 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
222 liboctbstack_env.UserInstallTargetHeader('include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
223 liboctbstack_env.UserInstallTargetHeader('include/ocpayload.h', 'resource', 'ocpayload.h')