Fix build error with scons-4.4.0 version which is based on python3
[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                'netdb.h',
68                'netinet/in.h',
69                'pthread.h',
70                'pwd.h',
71                'stdlib.h',
72                'string.h',
73                'strings.h',
74                'sys/socket.h',
75                'sys/stat.h',
76                'sys/time.h',
77                'sys/timeb.h',
78                'sys/types.h',
79                'sys/unistd.h',
80                'syslog.h',
81                'time.h',
82                'unistd.h',
83                'uuid/uuid.h',
84                'windows.h',
85                'winsock2.h',
86                'ws2tcpip.h']
87
88 if target_os == 'arduino':
89         # Detection of headers on the Arduino platform is currently broken.
90         cxx_headers = []
91
92 if target_os in ['tizenrt']:
93         env.AppendUnique(CCFLAGS = ['-std=c99'])
94         env.AppendUnique(CCFLAGS = ['-w'])
95         cxx_headers.remove('sys/timeb.h')
96         config_h_body += "#include <tinyara/config.h>\n\n"
97
98 if target_os == 'msys_nt':
99         # WinPThread provides a pthread.h, but we want to use native threads.
100         cxx_headers.remove('pthread.h')
101
102 def get_define_from_header_file(header_file):
103         header_file_converted = header_file.replace("/","_").replace(".","_").upper()
104         return "HAVE_" + header_file_converted
105
106 for header_file_name in cxx_headers:
107         if target_os == 'tizenrt':
108                 if conf.CheckCHeader(header_file_name):
109                         config_h_body += "#define %s 1\n\n" % get_define_from_header_file(header_file_name)
110         else:
111                 if conf.CheckCXXHeader(header_file_name):
112                         config_h_body += "#define %s 1\n\n" % get_define_from_header_file(header_file_name)
113 conf.Finish()
114
115 # Autoconf feature doesn't work with Jenkins' arduino toolchain, so hardcode it here.
116 if target_os == 'arduino':
117         config_h_body += "#define HAVE_ARDUINO_TIME_H\n\n"
118
119 # Generate the file
120 src_dir = env.get('SRC_DIR')
121 config_h_file_path = os.path.join(src_dir, 'resource', 'c_common', 'iotivity_config.h')
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()
127
128 # Sanity check to ensure that the above block created the file.
129 if not os.path.exists(config_h_file_path):
130         print("Error: iotivity_config.h file not created!")
131
132 # iotivity_config.h should be copied to the build dir
133 env.UserInstallTargetHeader(config_h_file_path, 'c_common', 'iotivity_config.h')
134
135 # Use the generated file internally
136 env.AppendUnique(CPPPATH = [os.path.join(src_dir, 'resource', 'c_common')])
137
138 if not env.get('RELEASE'):
139     env.PrependUnique(LIBS = ['gcov'])
140     env.AppendUnique(CCFLAGS = ['--coverage'])
141
142 ######################################################################
143
144 ######################################################################
145 # Add platform-specific helper library
146 ######################################################################
147
148 if target_os in ['windows', 'msys_nt']:
149         SConscript('windows/SConscript')
150
151 env.AppendUnique(CPPPATH = [
152             os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
153             os.path.join(Dir('.').abspath, 'oic_string', 'include'),
154             os.path.join(Dir('.').abspath, 'oic_time', 'include'),
155             os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
156             os.path.join(Dir('.').abspath, 'octhread', 'include'),
157             os.path.join(Dir('.').abspath, 'ocevent', 'include')
158         ])
159
160 if target_os == 'tizen':
161         env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
162 else:
163         env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common')])
164
165 if target_os in ['tizen', 'linux']:
166         env.ParseConfig("pkg-config --cflags --libs uuid")
167
168 common_env = env.Clone()
169
170 ######################################################################
171 # Source files and Targets
172 ######################################################################
173 common_src = [
174         'oic_string/src/oic_string.c',
175         'oic_malloc/src/oic_malloc.c',
176         'oic_time/src/oic_time.c',
177         'ocrandom/src/ocrandom.c'
178         ]
179
180 if env['POSIX_SUPPORTED']:
181         common_src.append('octhread/src/posix/octhread.c')
182 elif target_os  in ['windows']:
183         common_src.append('octhread/src/windows/octhread.c')
184 else:
185         common_src.append('octhread/src/noop/octhread.c')
186
187 if target_os in ['windows']:
188     common_src.append('ocevent/src/windows/ocevent.c')
189 else:
190     common_src.append('ocevent/src/others/ocevent.c')
191
192 commonlib = common_env.StaticLibrary('c_common', common_src)
193 common_env.InstallTarget(commonlib, 'c_common')
194 common_env.UserInstallTargetLib(commonlib, 'c_common')
195 common_env.UserInstallTargetHeader('platform_features.h', 'c_common', 'platform_features.h')
196
197 env.PrependUnique(LIBS = ['c_common'])