f64c3c83638ca8d310a30713a2a8bcfda3787304
[platform/upstream/iotivity.git] / resource / c_common / SConscript
1 #******************************************************************
2 #
3 # Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 #
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 #
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
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21
22 Import('env')
23 import os
24 import datetime
25
26 target_os = env.get('TARGET_OS')
27 target_arch = env.get('TARGET_ARCH')
28
29 ######################################################################
30 # Generate iotivity_config.h using presence of headers
31 ######################################################################
32
33 config_h_env = env.Clone()
34 conf = Configure(config_h_env)
35
36 config_h_header = '''
37 /* ****************************************************************************
38  * iotivity_config.h - IoTivity platform-specific configuration header.
39  *
40  * Auto-generated code for the %s %s platform.
41  *
42  * Generated at %s
43  *
44  *************************************************************************** */
45
46 #ifndef IOTIVITY_CONFIG_H__
47 #define IOTIVITY_CONFIG_H__
48
49 ''' % (str(target_os), str(target_arch), str(datetime.datetime.utcnow()))
50
51 config_h_body = ''
52
53 config_h_footer = '''
54
55 #include "platform_features.h"
56
57 #endif // IOTIVITY_CONFIG_H__
58
59 '''
60
61 cxx_headers = ['arpa/inet.h',
62                'fcntl.h',
63                'grp.h',
64                'in6addr.h',
65                'linux/limits.h',
66                'memory.h',
67                'net/if.h',
68                'netdb.h',
69                'netinet/in.h',
70                'pthread.h',
71                'pwd.h',
72                'stdlib.h',
73                'string.h',
74                'strings.h',
75                'sys/ioctl.h',
76                'sys/poll.h',
77                'sys/select.h',
78                'sys/socket.h',
79                'sys/stat.h',
80                'sys/time.h',
81                'sys/timeb.h',
82                'sys/types.h',
83                'sys/unistd.h',
84                'syslog.h',
85                'time.h',
86                'unistd.h',
87                'uuid/uuid.h',
88                'windows.h',
89                'winsock2.h',
90                'ws2tcpip.h']
91
92 if target_os == 'arduino':
93         # Detection of headers on the Arduino platform is currently broken.
94         cxx_headers = []
95
96 if target_os == 'msys_nt':
97         # WinPThread provides a pthread.h, but we want to use native threads.
98         cxx_headers.remove('pthread.h')
99
100 def get_define_from_header_file(header_file):
101         header_file_converted = header_file.replace("/","_").replace(".","_").upper()
102         return "HAVE_" + header_file_converted
103
104 for header_file_name in cxx_headers:
105         if conf.CheckCXXHeader(header_file_name):
106                 config_h_body += "#define %s 1\n\n" % get_define_from_header_file(header_file_name)
107 conf.Finish()
108
109 # Autoconf feature doesn't work with Jenkins' arduino toolchain, so hardcode it here.
110 if target_os == 'arduino':
111         config_h_body += "#define HAVE_ARDUINO_TIME_H\n\n"
112
113 # Generate the file
114 src_dir = env.get('SRC_DIR')
115 config_h_file_path = os.path.join(src_dir, 'resource', 'c_common', 'iotivity_config.h')
116 if os.path.exists(config_h_file_path):
117         os.remove(config_h_file_path)
118 config_h_file = open(config_h_file_path, "w")
119 config_h_file.write(config_h_header + config_h_body + config_h_footer)
120 config_h_file.close()
121
122 # Sanity check to ensure that the above block created the file.
123 if not os.path.exists(config_h_file_path):
124         print "Error: iotivity_config.h file not created!"
125
126 # iotivity_config.h should be copied to the build dir
127 env.UserInstallTargetHeader(config_h_file_path, 'c_common', 'iotivity_config.h')
128
129 # Use the generated file internally
130 env.AppendUnique(CPPPATH = [os.path.join(src_dir, 'resource', 'c_common')])
131
132 ######################################################################
133
134 env.AppendUnique(CPPPATH = [
135             os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
136             os.path.join(Dir('.').abspath, 'oic_string', 'include'),
137             os.path.join(Dir('.').abspath, 'oic_time', 'include'),
138             os.path.join(Dir('.').abspath, 'ocatomic', 'include'),
139             os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
140             os.path.join(Dir('.').abspath, 'octhread', 'include')
141         ])
142
143 if target_os == 'tizen':
144         env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
145 else:
146         env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common')])
147
148 if target_os in ['tizen', 'linux']:
149         env.ParseConfig("pkg-config --cflags --libs uuid")
150
151 common_env = env.Clone()
152
153 ######################################################################
154 # Enable treating all warnings as errors
155 ######################################################################
156
157 if target_os in ['windows', 'msys_nt']:
158         common_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
159
160 ######################################################################
161 # Add platform-specific helper library
162 ######################################################################
163
164 if target_os in ['windows', 'msys_nt']:
165         SConscript('windows/SConscript', 'common_env')
166
167 ######################################################################
168 # Source files and Targets
169 ######################################################################
170 common_src = [
171         'oic_string/src/oic_string.c',
172         'oic_malloc/src/oic_malloc.c',
173         'oic_time/src/oic_time.c',
174         'ocrandom/src/ocrandom.c'
175         ]
176
177 if env['POSIX_SUPPORTED']:
178         common_src.append('octhread/src/posix/octhread.c')
179 elif target_os  in ['windows']:
180         common_src.append('octhread/src/windows/octhread.c')
181 else:
182         common_src.append('octhread/src/noop/octhread.c')
183
184 if target_os in ['windows', 'msys_nt']:
185         common_src.append('ocatomic/src/windows/ocatomic.c')
186 elif target_os in ['arduino']:
187         common_src.append('ocatomic/src/arduino/ocatomic.c')
188 else:
189         common_src.append('ocatomic/src/others/ocatomic.c')
190
191 common_env.AppendUnique(LIBS = ['logger'])
192 common_env.AppendUnique(CPPPATH = ['#resource/csdk/logger/include'])
193 commonlib = common_env.StaticLibrary('c_common', common_src)
194 common_env.InstallTarget(commonlib, 'c_common')
195 common_env.UserInstallTargetLib(commonlib, 'c_common')
196 common_env.UserInstallTargetHeader('iotivity_debug.h', 'c_common', 'iotivity_debug.h')
197 common_env.UserInstallTargetHeader('platform_features.h', 'c_common', 'platform_features.h')
198
199 env.PrependUnique(LIBS = ['c_common'])