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 SConscript('#resource/third_party_libs.scons', 'lib_env')
29 liboctbstack_env = lib_env.Clone()
31 target_os = env.get('TARGET_OS')
32 rd_mode = env.get('RD_MODE')
33 with_ra = env.get('WITH_RA')
34 with_ra_ibb = env.get('WITH_RA_IBB')
35 with_tcp = env.get('WITH_TCP')
36 with_mq = env.get('WITH_MQ')
37 # As in the source code, it includes arduino Time library (C++)
38 # It requires compile the .c with g++
39 if target_os == 'arduino':
40 liboctbstack_env.Replace(CC = env.get('CXX'))
41 liboctbstack_env.Replace(CFLAGS = env.get('CXXFLAGS'))
43 ######################################################################
45 ######################################################################
46 with_upstream_libcoap = liboctbstack_env.get('WITH_UPSTREAM_LIBCOAP')
47 if with_upstream_libcoap == '1':
48 # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
49 liboctbstack_env.PrependUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
51 # For bring up purposes only, the forked version will live here.
52 liboctbstack_env.PrependUnique(CPPPATH = ['connectivity/lib/libcoap-4.1.1/include'])
54 liboctbstack_env.PrependUnique(CPPPATH = [
55 '../../extlibs/cjson/',
56 '../../extlibs/timer/',
59 'stack/include/internal',
60 '../oc_logger/include',
61 'connectivity/common/inc',
63 'connectivity/inc/pkix',
65 'connectivity/external/inc',
67 'security/include/internal',
68 'security/provisioning/include',
72 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
74 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
75 if 'BROKER' in with_mq:
76 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
78 if target_os not in ['arduino', 'windows']:
79 liboctbstack_env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '_GNU_SOURCE'])
80 liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
82 if liboctbstack_env.get('ROUTING') == 'GW':
83 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
84 elif liboctbstack_env.get('ROUTING') == 'EP':
85 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
87 if liboctbstack_env.get('WITH_PROXY'):
88 liboctbstack_env.AppendUnique(CPPDEFINES = ['WITH_CHPROXY'])
90 if target_os not in ['windows']:
91 liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
93 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
95 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
97 if target_os in ['tizen']:
98 liboctbstack_env.AppendUnique(LIBS = ['pthread'])
100 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
101 liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
103 if env.get('SECURED') == '1':
104 liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
106 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows', 'tizenrt']:
107 liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
110 liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
113 liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
115 if target_os in ['windows', 'msys_nt']:
116 # octbstack.def specifies the list of functions exported by octbstack.dll.
117 liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
118 if env.get('TEST') == '1':
119 liboctbstack_env.Textfile(target = 'octbstack_not_secured.def', source = [File('octbstack_product.def'), File('octbstack_test.def')])
121 liboctbstack_env.Textfile(target = 'octbstack_not_secured.def', source = [File('octbstack_product.def')])
123 if env.get('SECURED') == '1':
124 # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
125 liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
126 if env.get('MULTIPLE_OWNER') == '1':
127 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_not_secured.def'), File('octbstack_product_secured.def'), File('octbstack_product_secured_mot.def')])
129 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_not_secured.def'), File('octbstack_product_secured.def')])
131 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_not_secured.def')])
133 liboctbstack_env.AppendUnique(LIBS = ['ws2_32', 'advapi32', 'iphlpapi', 'bcrypt'])
135 liboctbstack_env.AppendUnique(LIBS = ['m'])
137 if target_os in ['tizen', 'linux']:
138 liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
139 if target_os in ['tizen']:
140 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
142 if target_os == 'arduino':
143 liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
144 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
145 liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
146 if target_os in ['darwin', 'ios']:
147 env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
148 liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
149 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
150 if target_os not in ['arduino', 'windows']:
151 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
152 if target_os == 'android':
153 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
155 if env.get('LOGGING'):
156 liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
158 liboctbstack_env.Append(LIBS = ['c_common'])
160 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
161 liboctbstack_env.Prepend(LIBS = ['routingmanager'])
163 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
164 if 'CLIENT' in rd_mode:
165 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
166 if 'SERVER' in rd_mode:
167 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
168 if target_os in ['tizen']:
169 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
171 liboctbstack_env.AppendUnique(CPPPATH = ['#extlibs/sqlite3'])
173 ######################################################################
174 # Source files and Targets
175 ######################################################################
176 OCTBSTACK_SRC = 'stack/src/'
178 '../../extlibs/timer/timer.c',
179 OCTBSTACK_SRC + 'ocstack.c',
180 OCTBSTACK_SRC + 'ocpayload.c',
181 OCTBSTACK_SRC + 'ocpayloadparse.c',
182 OCTBSTACK_SRC + 'ocpayloadconvert.c',
183 OCTBSTACK_SRC + 'occlientcb.c',
184 OCTBSTACK_SRC + 'ocresource.c',
185 OCTBSTACK_SRC + 'ocobserve.c',
186 OCTBSTACK_SRC + 'ocserverrequest.c',
187 OCTBSTACK_SRC + 'occollection.c',
188 OCTBSTACK_SRC + 'oicgroup.c'
191 if target_os != 'tizenrt':
192 liboctbstack_src.append('../../extlibs/cjson/cJSON.c')
195 liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
196 liboctbstack_env.UserInstallTargetHeader('stack/include/oickeepalive.h', 'resource', 'oickeepalive.h')
198 if 'SERVER' in rd_mode:
199 liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
200 if target_os not in ['tizen']:
201 liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c')
203 if target_os in ['linux']:
204 # Linux uses a Shared library because SCons chooses the shared library on Linux
205 # when only 'octbstack' is added to the LIBS.
206 # TODO: Switch Linux to use a Static library for testing like every other OS.
207 test_liboctbstack = liboctbstack_env.SharedLibrary('octbstack_test', liboctbstack_src)
209 test_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_test', liboctbstack_src)
211 octbstack_libs = Flatten(test_liboctbstack)
213 if target_os in ['windows', 'msys_nt']:
214 # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
215 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
217 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
219 octbstack_libs = Flatten(static_liboctbstack)
221 if target_os not in ['arduino','darwin','ios','tizenrt'] :
222 shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
223 octbstack_libs += Flatten(shared_liboctbstack)
224 liboctbstack_env.UserInstallTargetHeader('stack/include/ocstack.h', 'resource', 'ocstack.h')
225 liboctbstack_env.UserInstallTargetHeader('stack/include/ocpresence.h', 'resource', 'ocpresence.h')
227 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
228 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
230 liboctbstack_env.UserInstallTargetHeader('stack/include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
231 liboctbstack_env.UserInstallTargetHeader('stack/include/octypes.h', 'resource', 'octypes.h')
232 liboctbstack_env.UserInstallTargetHeader('stack/include/ocpayload.h', 'resource', 'ocpayload.h')