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 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 target_os = env.get('TARGET_OS')
27 target_arch = env.get('TARGET_ARCH')
28 src_dir = env.get('SRC_DIR')
30 ######################################################################
31 # Generate iotivity_config.h using presence of headers
32 ######################################################################
33 config_h_file_path = os.path.join(src_dir, 'resource', 'c_common', 'iotivity_config.h')
35 if (os.path.exists(config_h_file_path)) and (env.GetOption('clean')):
36 os.remove(config_h_file_path)
38 if (not os.path.isfile(config_h_file_path)) and (not env.GetOption('clean')):
39 conf = Configure(env.Clone(LIBS = []))
42 /* ****************************************************************************
43 * iotivity_config.h - IoTivity platform-specific configuration header.
45 * Auto-generated code for the %s %s platform.
47 *************************************************************************** */
49 #ifndef IOTIVITY_CONFIG_H__
50 #define IOTIVITY_CONFIG_H__
52 ''' % (str(target_os), str(target_arch))
58 #include "platform_features.h"
60 #endif // IOTIVITY_CONFIG_H__
64 cxx_headers = ['arpa/inet.h',
94 cxx_functions = ['strptime']
96 if target_os == 'arduino':
97 # Detection of headers on the Arduino platform is currently broken.
100 if target_os == 'msys_nt':
101 # WinPThread provides a pthread.h, but we want to use native threads.
102 cxx_headers.remove('pthread.h')
104 def get_define_from_string(header_file):
105 header_file_converted = header_file.replace("/","_").replace(".","_").upper()
106 return "HAVE_" + header_file_converted
108 for header_file_name in cxx_headers:
109 if conf.CheckCXXHeader(header_file_name):
110 config_h_body += "#define %s 1\n\n" % get_define_from_string(header_file_name)
112 for function_name in cxx_functions:
113 if conf.CheckFunc(function_name):
114 config_h_body += "#define %s 1\n\n" % get_define_from_string(function_name)
117 # Autoconf feature doesn't work with Jenkins' arduino toolchain, so hardcode it here.
118 if target_os == 'arduino':
119 config_h_body += "#define HAVE_ARDUINO_TIME_H\n\n"
122 if os.path.exists(config_h_file_path):
123 os.remove(config_h_file_path)
124 config_h_file = open(config_h_file_path, "w")
125 config_h_file.write(config_h_header + config_h_body + config_h_footer)
126 config_h_file.close()
128 # Sanity check to ensure that the above block created the file.
129 if (not os.path.exists(config_h_file_path)) and (not env.GetOption('clean')):
130 print "Error: iotivity_config.h file not created!"
133 # iotivity_config.h should be copied to the build dir
134 env.UserInstallTargetHeader(config_h_file_path, 'c_common', 'iotivity_config.h')
136 # Use the generated file internally
137 env.AppendUnique(CPPPATH = [os.path.join(src_dir, 'resource', 'c_common')])
139 ######################################################################
141 env.AppendUnique(CPPPATH = [
142 os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
143 os.path.join(Dir('.').abspath, 'oic_string', 'include'),
144 os.path.join(Dir('.').abspath, 'oic_time', 'include'),
145 os.path.join(Dir('.').abspath, 'ocatomic', 'include'),
146 os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
147 os.path.join(Dir('.').abspath, 'octhread', 'include'),
148 os.path.join(Dir('.').abspath, 'oic_platform', 'include'),
149 os.path.join(Dir('.').abspath, 'octimer', 'include'),
150 '#/extlibs/mbedtls/mbedtls/include'
153 if target_os not in ['tizen']:
154 env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common')])
156 if target_os in ['tizen', 'linux']:
157 env.ParseConfig("pkg-config --cflags --libs uuid")
159 common_env = env.Clone()
161 ######################################################################
162 # Enable treating all warnings as errors
163 ######################################################################
165 if target_os in ['windows', 'msys_nt']:
166 common_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
168 ######################################################################
169 # Add platform-specific helper library
170 ######################################################################
172 if target_os in ['windows', 'msys_nt']:
173 SConscript('windows/SConscript', 'common_env')
175 ######################################################################
176 # Source files and Targets
177 ######################################################################
179 'oic_string/src/oic_string.c',
180 'oic_malloc/src/oic_malloc.c',
181 'oic_time/src/oic_time.c',
182 'ocrandom/src/ocrandom.c',
183 'oic_platform/src/oic_platform.c'
186 if env['POSIX_SUPPORTED']:
187 common_src.append('octhread/src/posix/octhread.c')
188 elif target_os in ['windows']:
189 common_src.append('octhread/src/windows/octhread.c')
191 common_src.append('octhread/src/noop/octhread.c')
193 if target_os in ['windows', 'msys_nt']:
194 common_src.append('ocatomic/src/windows/ocatomic.c')
195 elif target_os in ['arduino']:
196 common_src.append('ocatomic/src/arduino/ocatomic.c')
198 common_src.append('ocatomic/src/others/ocatomic.c')
200 if target_os in ['windows']:
201 common_src.append('oic_platform/src/windows/oic_winplatform.cpp')
203 common_src.append('oic_platform/src/others/oic_otherplatforms.c')
205 # C++ Arduino's <Timer.h> is included so use C++ compiler/flags
206 if target_os in ['arduino']:
207 octimer_env = common_env.Clone()
208 octimer_env.Replace(CC = env.get('CXX'))
209 octimer_env.Replace(CFLAGS = env.get('CXXFLAGS'))
210 octimer = octimer_env.Object('octimer/src/octimer.c')
211 common_src.append(octimer)
213 common_src.append('octimer/src/octimer.c')
215 common_env.AppendUnique(LIBS = ['logger'])
216 common_env.AppendUnique(CPPPATH = ['#resource/csdk/logger/include'])
217 commonlib = common_env.StaticLibrary('c_common', common_src)
218 common_env.InstallTarget(commonlib, 'c_common')
219 common_env.UserInstallTargetLib(commonlib, 'c_common')
220 common_env.UserInstallTargetHeader('iotivity_debug.h', 'c_common', 'iotivity_debug.h')
221 common_env.UserInstallTargetHeader('platform_features.h', 'c_common', 'platform_features.h')
223 Clean(commonlib, config_h_file_path)
225 # c_common calls into logger.
226 env.PrependUnique(LIBS = ['c_common', 'logger'])