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 liboctbstack_env.PrependUnique(CPPPATH = [
47 '../../extlibs/cjson/',
48 '../../extlibs/timer/',
51 'stack/include/internal',
52 '../oc_logger/include',
53 'connectivity/lib/libcoap-4.1.1',
54 'connectivity/common/inc',
56 'connectivity/inc/pkix',
58 'connectivity/external/inc',
60 'security/include/internal',
61 'security/provisioning/include',
65 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
67 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
68 if 'BROKER' in with_mq:
69 liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
71 if target_os not in ['arduino', 'windows']:
72 liboctbstack_env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '_GNU_SOURCE'])
73 liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
75 if liboctbstack_env.get('ROUTING') == 'GW':
76 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
77 elif liboctbstack_env.get('ROUTING') == 'EP':
78 liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
80 if liboctbstack_env.get('WITH_PROXY'):
81 liboctbstack_env.AppendUnique(CPPDEFINES = ['WITH_CHPROXY'])
83 if target_os not in ['windows']:
84 liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
86 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
88 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
90 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
91 liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
93 if env.get('SECURED') == '1':
94 liboctbstack_env.AppendUnique(LIBS = ['tinydtls'])
95 if env.get('WITH_TCP') == True:
96 liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
98 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
99 liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
102 liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
105 liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
107 if target_os in ['windows', 'msys_nt']:
108 # octbstack.def specifies the list of functions exported by octbstack.dll.
109 liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
110 if env.get('TEST') == '1':
111 liboctbstack_env.Textfile(target = 'octbstack_not_secured.def', source = [File('octbstack_product.def'), File('octbstack_test.def')])
113 liboctbstack_env.Textfile(target = 'octbstack_not_secured.def', source = [File('octbstack_product.def')])
115 if env.get('SECURED') == '1':
116 # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
117 liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
118 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_not_secured.def'), File('octbstack_product_secured.def')])
120 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_not_secured.def')])
122 liboctbstack_env.AppendUnique(LIBS = ['ws2_32', 'advapi32', 'iphlpapi'])
124 liboctbstack_env.AppendUnique(LIBS = ['m'])
126 if target_os in ['tizen', 'linux']:
127 liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
128 if target_os in ['tizen']:
129 liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
131 if target_os == 'arduino':
132 liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
133 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
134 liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
135 if target_os in ['darwin', 'ios']:
136 env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
137 liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
138 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
139 if target_os not in ['arduino', 'windows']:
140 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
141 if target_os == 'android':
142 liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
144 if env.get('LOGGING'):
145 liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
147 if env.get('DTLS_WITH_X509') == '1':
148 liboctbstack_env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
150 liboctbstack_env.Append(LIBS = ['c_common'])
152 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
153 liboctbstack_env.Prepend(LIBS = ['routingmanager'])
155 ######################################################################
156 # Source files and Targets
157 ######################################################################
158 OCTBSTACK_SRC = 'stack/src/'
160 '../../extlibs/cjson/cJSON.c',
161 '../../extlibs/timer/timer.c',
162 OCTBSTACK_SRC + 'ocstack.c',
163 OCTBSTACK_SRC + 'ocpayload.c',
164 OCTBSTACK_SRC + 'ocpayloadparse.c',
165 OCTBSTACK_SRC + 'ocpayloadconvert.c',
166 OCTBSTACK_SRC + 'occlientcb.c',
167 OCTBSTACK_SRC + 'ocresource.c',
168 OCTBSTACK_SRC + 'ocobserve.c',
169 OCTBSTACK_SRC + 'ocserverrequest.c',
170 OCTBSTACK_SRC + 'occollection.c',
171 OCTBSTACK_SRC + 'oicgroup.c'
174 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
175 liboctbstack_src.append(OCTBSTACK_SRC + 'rdpayload.c')
176 liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
177 if 'CLIENT' in rd_mode:
178 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
179 if 'SERVER' in rd_mode:
180 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
183 liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
185 liboctbstack_src.extend(env['cbor_files'])
187 # Insert a hack for Arduino, whose compiler may not support all defines expected
189 if target_os in ['arduino']:
190 liboctbstack_env.AppendUnique(CPPDEFINES = ['INT64_MAX=0x7FFFFFFFFFFFFFFF'])
192 if target_os in ['windows', 'msys_nt']:
193 # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
194 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
196 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
198 octbstack_libs = Flatten(static_liboctbstack)
200 if target_os not in ['arduino','darwin','ios'] :
201 shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
202 octbstack_libs += Flatten(shared_liboctbstack)
203 liboctbstack_env.UserInstallTargetHeader('stack/include/ocstack.h', 'resource', 'ocstack.h')
204 liboctbstack_env.UserInstallTargetHeader('stack/include/ocpresence.h', 'resource', 'ocpresence.h')
206 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
207 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
209 liboctbstack_env.UserInstallTargetHeader('stack/include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
210 liboctbstack_env.UserInstallTargetHeader('stack/include/octypes.h', 'resource', 'octypes.h')
211 liboctbstack_env.UserInstallTargetHeader('stack/include/ocpayload.h', 'resource', 'ocpayload.h')