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
27 liboctbstack_env = env.Clone()
30 SConscript('samples/SConscript', exports = { 'stacksamples_env' : liboctbstack_env })
32 SConscript('#resource/third_party_libs.scons', exports = { 'lib_env' : liboctbstack_env })
34 target_os = env.get('TARGET_OS')
35 rd_mode = env.get('RD_MODE')
36 with_ra = env.get('WITH_RA')
37 with_ra_ibb = env.get('WITH_RA_IBB')
38 with_tcp = env.get('WITH_TCP')
39 with_cloud = env.get('WITH_CLOUD')
40 with_mq = env.get('WITH_MQ')
41 # As in the source code, it includes arduino Time library (C++)
42 # It requires compile the .c with g++
43 if target_os == 'arduino':
44 liboctbstack_env.Replace(CC = env.get('CXX'))
45 liboctbstack_env.Replace(CFLAGS = env.get('CXXFLAGS'))
47 ######################################################################
49 ######################################################################
50 with_upstream_libcoap = liboctbstack_env.get('WITH_UPSTREAM_LIBCOAP')
51 if with_upstream_libcoap == '1':
52 # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
53 liboctbstack_env.PrependUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
55 # For bring up purposes only, the forked version will live here.
56 liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/connectivity/lib/libcoap-4.1.1/include'])
58 liboctbstack_env.PrependUnique(CPPPATH = [
59 '#resource/c_common/octimer/include',
60 '#resource/c_common/ocatomic/include',
61 '#resource/csdk/logger/include',
62 '#resource/csdk/include',
65 '#resource/oc_logger/include',
66 '#resource/csdk/connectivity/common/inc',
67 '#resource/csdk/connectivity/inc',
68 '#resource/csdk/connectivity/inc/pkix',
69 '#resource/csdk/connectivity/api',
70 '#resource/csdk/connectivity/external/inc',
71 '#resource/csdk/security/include',
72 '#resource/csdk/security/include/internal',
73 '#resource/csdk/security/provisioning/include',
77 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
79 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
80 if 'BROKER' in with_mq:
81 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
83 if target_os not in ['arduino', 'windows']:
84 liboctbstack_env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '_GNU_SOURCE'])
85 liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
87 if liboctbstack_env.get('ROUTING') == 'GW':
88 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
89 elif liboctbstack_env.get('ROUTING') == 'EP':
90 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
92 if target_os not in ['windows']:
93 liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
95 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
97 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
98 liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
100 if env.get('SECURED') == '1':
101 liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509'])
103 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
104 liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
107 liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
110 liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
112 if target_os not in ['windows', 'msys_nt']:
113 liboctbstack_env.AppendUnique(LIBS = ['m'])
115 liboctbstack_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
117 # octbstack.def specifies the list of functions exported by octbstack.dll.
118 liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
120 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
122 # - octbstack.dll is exporting resource_directory C APIs
123 # - resource_directory.lib contains just the implementation of the C++ RD APIs
124 liboctbstack_env.PrependUnique(LIBS = ['resource_directory_internal'])
126 if 'CLIENT' in rd_mode:
127 liboctbstack_env.Textfile(target = 'octbstack_temp1.def', source = [File('octbstack_product.def'), File('octbstack_rd_client.def')])
129 liboctbstack_env.Textfile(target = 'octbstack_temp1.def', source = [File('octbstack_product.def')])
131 if 'SERVER' in rd_mode:
132 liboctbstack_env.Textfile(target = 'octbstack_temp2.def', source = [File('octbstack_temp1.def'), File('octbstack_rd_server.def')])
134 liboctbstack_env.Textfile(target = 'octbstack_temp2.def', source = [File('octbstack_temp1.def')])
136 if env.get('SECURED') != '1':
137 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp2.def')])
139 # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
140 liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
142 liboctbstack_env.Textfile(target = 'octbstack_temp3.def', source = [File('octbstack_temp2.def'), File('octbstack_product_secured.def')])
145 liboctbstack_env.Textfile(target = 'octbstack_temp4.def', source = [File('octbstack_temp3.def'), File('octbstack_product_with_tcp.def')])
147 liboctbstack_env.Textfile(target = 'octbstack_temp4.def', source = [File('octbstack_temp3.def')])
149 if env.get('MULTIPLE_OWNER') == '1':
150 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp4.def'), File('octbstack_product_secured_mot.def')])
152 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp4.def')])
154 if target_os in ['tizen', 'linux']:
155 liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
156 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
158 if target_os == 'arduino':
159 liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
160 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
161 liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
162 if target_os in ['darwin', 'ios']:
163 env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
164 liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
165 if target_os not in ['arduino', 'windows']:
166 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
167 if target_os == 'android':
168 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
170 if env.get('LOGGING'):
171 liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
173 liboctbstack_env.Append(LIBS = ['c_common', 'mbedcrypto'])
175 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
176 liboctbstack_env.Prepend(LIBS = ['routingmanager'])
178 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
179 liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/resource-directory/include'])
181 if target_os in ['windows']:
182 liboctbstack_env.AppendUnique(LIBS = ['sqlite3'])
184 if 'CLIENT' in rd_mode:
185 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
187 if 'SERVER' in rd_mode:
188 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
189 if target_os in ['tizen']:
190 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
192 liboctbstack_env.AppendUnique(CPPPATH = ['#extlibs/sqlite3'])
194 ######################################################################
195 # Source files and Targets
196 ######################################################################
197 OCTBSTACK_SRC = 'src/'
199 OCTBSTACK_SRC + 'ocstack.c',
200 OCTBSTACK_SRC + 'ocpayload.c',
201 OCTBSTACK_SRC + 'ocpayloadparse.c',
202 OCTBSTACK_SRC + 'ocpayloadconvert.c',
203 OCTBSTACK_SRC + 'occlientcb.c',
204 OCTBSTACK_SRC + 'ocresource.c',
205 OCTBSTACK_SRC + 'ocobserve.c',
206 OCTBSTACK_SRC + 'ocserverrequest.c',
207 OCTBSTACK_SRC + 'occollection.c',
208 OCTBSTACK_SRC + 'oicgroup.c',
209 OCTBSTACK_SRC + 'ocendpoint.c'
213 liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
214 if with_cloud == True:
215 liboctbstack_src.append(OCTBSTACK_SRC + 'occonnectionmanager.c')
217 if 'SERVER' in rd_mode:
218 liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
219 if target_os not in ['linux', 'tizen', 'windows']:
220 liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c')
222 if target_os in ['linux']:
223 # Linux uses a Shared library because SCons chooses the shared library on Linux
224 # when only 'octbstack' is added to the LIBS.
225 # TODO: Switch Linux to use a Static library for testing like every other OS.
226 test_liboctbstack = liboctbstack_env.SharedLibrary('octbstack_test', liboctbstack_src)
228 test_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_test', liboctbstack_src)
230 octbstack_libs = Flatten(test_liboctbstack)
232 if target_os in ['windows', 'msys_nt']:
233 # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
234 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
236 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
238 octbstack_libs += Flatten(static_liboctbstack)
240 if target_os not in ['arduino','darwin','ios'] :
241 shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
242 octbstack_libs += Flatten(shared_liboctbstack)
243 liboctbstack_env.UserInstallTargetHeader('include/ocstack.h', 'resource', 'ocstack.h')
244 liboctbstack_env.UserInstallTargetHeader('include/ocpresence.h', 'resource', 'ocpresence.h')
246 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
247 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
249 liboctbstack_env.UserInstallTargetHeader('include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
250 liboctbstack_env.UserInstallTargetHeader('include/ocpayload.h', 'resource', 'ocpayload.h')