lib/replace: move lib/replace/closefrom.c from ROKEN_HOSTCC_SOURCE to REPLACE_HOSTCC_...
[Samba.git] / lib / replace / wscript
blob64f305d6df0f5b78ef55d2c9345e32f6497e99a6
1 #!/usr/bin/env python
3 APPNAME = 'libreplace'
4 VERSION = '1.2.1'
6 import sys
7 import os
9 # find the buildtools directory
10 top = '.'
11 while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5:
12 top = top + '/..'
13 sys.path.insert(0, top + '/buildtools/wafsamba')
15 out = 'bin'
17 import wafsamba
18 from wafsamba import samba_dist
19 from waflib import Options, Utils, Logs, Context
21 samba_dist.DIST_DIRS('lib/replace buildtools:buildtools third_party/waf:third_party/waf')
23 def options(opt):
24 opt.BUILTIN_DEFAULT('NONE')
25 opt.PRIVATE_EXTENSION_DEFAULT('')
26 opt.RECURSE('buildtools/wafsamba')
28 @Utils.run_once
29 def configure(conf):
30 conf.RECURSE('buildtools/wafsamba')
32 conf.env.standalone_replace = conf.IN_LAUNCH_DIR()
34 conf.DEFINE('HAVE_LIBREPLACE', 1)
35 conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1)
37 conf.CHECK_HEADERS('linux/types.h crypt.h locale.h acl/libacl.h compat.h')
38 conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h')
39 conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')
40 conf.CHECK_HEADERS('locale.h ndir.h pwd.h')
41 conf.CHECK_HEADERS('shadow.h sys/acl.h')
42 conf.CHECK_HEADERS('sys/attributes.h attr/attributes.h sys/capability.h sys/dir.h sys/epoll.h')
43 conf.CHECK_HEADERS('port.h')
44 conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h')
45 conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h')
46 conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
47 conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h')
48 conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h')
50 if not conf.CHECK_DECLS('malloc', headers='stdlib.h'):
51 conf.CHECK_HEADERS('malloc.h')
53 conf.CHECK_HEADERS('grp.h')
54 conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
55 conf.CHECK_HEADERS('stdarg.h vararg.h sys/mount.h mntent.h')
56 conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
57 conf.CHECK_HEADERS('''sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h
58 netinet/ip.h netinet/tcp.h netinet/in_ip.h
59 sys/sockio.h sys/un.h''', together=True)
60 conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h')
61 conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h')
62 conf.CHECK_HEADERS('errno.h')
63 conf.CHECK_HEADERS('getopt.h iconv.h')
64 conf.CHECK_HEADERS('memory.h nss.h sasl/sasl.h')
66 conf.CHECK_FUNCS_IN('inotify_init', 'inotify', checklibc=True,
67 headers='sys/inotify.h')
69 conf.CHECK_HEADERS('security/pam_appl.h zlib.h asm/unistd.h')
70 conf.CHECK_HEADERS('sys/unistd.h alloca.h float.h')
72 conf.SET_TARGET_TYPE('tirpc', 'EMPTY')
74 if conf.CHECK_CODE(
75 '\n#ifndef _TIRPC_RPC_H\n#error "no tirpc headers in system path"\n#endif\n',
76 'HAVE_RPC_RPC_HEADERS',
77 headers=['rpc/rpc.h', 'rpc/nettype.h'],
78 msg='Checking for tirpc rpc headers in default system path'):
79 if conf.CONFIG_SET('HAVE_RPC_RPC_H'):
80 conf.undefine('HAVE_RPC_RPC_H')
82 if not conf.CONFIG_SET('HAVE_RPC_RPC_H'):
83 if conf.CHECK_CFG(package='libtirpc', args='--cflags --libs',
84 msg='Checking for libtirpc headers',
85 uselib_store='TIRPC'):
86 conf.CHECK_HEADERS('rpc/rpc.h rpc/nettype.h', lib='tirpc', together=True)
87 conf.SET_TARGET_TYPE('tirpc', 'SYSLIB')
88 if not conf.CONFIG_SET('HAVE_RPC_RPC_H'):
89 if conf.CHECK_CFG(package='libntirpc', args='--cflags',
90 msg='Checking for libntirpc headers',
91 uselib_store='TIRPC'):
92 conf.CHECK_HEADERS('rpc/rpc.h rpc/nettype.h', lib='tirpc', together=True)
93 conf.SET_TARGET_TYPE('tirpc', 'SYSLIB')
94 if not conf.CONFIG_SET('HAVE_RPC_RPC_H'):
95 Logs.warn('No rpc/rpc.h header found, tirpc or libntirpc missing?')
97 conf.SET_TARGET_TYPE('nsl', 'EMPTY')
98 conf.CHECK_HEADERS('rpc/rpc.h rpcsvc/yp_prot.h', lib='tirpc')
99 if not conf.CONFIG_SET('HAVE_RPCSVC_YP_PROT_H'):
100 if conf.CHECK_CFG(package='libnsl', args='--cflags --libs',
101 msg='Checking for libnsl',
102 uselib_store='NSL'):
103 conf.SET_TARGET_TYPE('nsl', 'SYSLIB')
104 conf.CHECK_HEADERS('rpc/rpc.h rpcsvc/yp_prot.h', lib='tirpc nsl')
105 else:
106 conf.SET_TARGET_TYPE('nsl', 'SYSLIB')
107 conf.CHECK_HEADERS('rpcsvc/nis.h rpcsvc/ypclnt.h', lib='tirpc nsl')
109 # This file is decprecated with glibc >= 2.30 so we need to check if it
110 # includes a deprecation warning:
111 # #warning "The <sys/sysctl.h> header is deprecated and will be removed."
112 conf.CHECK_CODE('''
113 #include <sys/sysctl.h>
114 int main(void) { return 0; }
115 ''',
116 define='HAVE_SYS_SYSCTL_H',
117 cflags=['-Werror=cpp'],
118 addmain=False,
119 msg='Checking for header sys/sysctl.h')
121 conf.CHECK_HEADERS('sys/fileio.h sys/filesys.h sys/dustat.h sys/sysmacros.h')
122 conf.CHECK_HEADERS('xfs/libxfs.h netgroup.h')
124 conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h')
125 conf.CHECK_HEADERS('valgrind/memcheck.h valgrind/helgrind.h')
126 conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h')
127 conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h')
128 conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h')
129 conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h')
130 conf.CHECK_HEADERS('sys/atomic.h stdatomic.h')
131 conf.CHECK_HEADERS('libgen.h')
133 if conf.CHECK_CFLAGS('-Wno-format-truncation'):
134 conf.define('HAVE_WNO_FORMAT_TRUNCATION', '1')
136 if conf.CHECK_CFLAGS('-Wno-unused-function'):
137 conf.define('HAVE_WNO_UNUSED_FUNCTION', '1')
139 if conf.CHECK_CFLAGS('-Wno-strict-overflow'):
140 conf.define('HAVE_WNO_STRICT_OVERFLOW', '1')
142 # Check for process set name support
143 conf.CHECK_CODE('''
144 #include <sys/prctl.h>
145 int main(void) {
146 prctl(0);
147 return 0;
149 ''',
150 'HAVE_PRCTL',
151 addmain=False,
152 headers='sys/prctl.h',
153 msg='Checking for prctl syscall')
155 conf.CHECK_CODE('''
156 #include <unistd.h>
157 #ifdef HAVE_FCNTL_H
158 #include <fcntl.h>
159 #endif
160 int main(void) { int fd = open("/dev/null", O_DIRECT); }
161 ''',
162 define='HAVE_OPEN_O_DIRECT',
163 addmain=False,
164 msg='Checking for O_DIRECT flag to open(2)')
166 conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
167 conf.CHECK_TYPE('_Bool', define='HAVE__Bool')
168 conf.CHECK_TYPE('bool', define='HAVE_BOOL')
170 conf.CHECK_TYPE('int8_t', 'char')
171 conf.CHECK_TYPE('uint8_t', 'unsigned char')
172 conf.CHECK_TYPE('int16_t', 'short')
173 conf.CHECK_TYPE('uint16_t', 'unsigned short')
174 conf.CHECK_TYPE('int32_t', 'int')
175 conf.CHECK_TYPE('uint32_t', 'unsigned')
176 conf.CHECK_TYPE('int64_t', 'long long')
177 conf.CHECK_TYPE('uint64_t', 'unsigned long long')
178 conf.CHECK_TYPE('size_t', 'unsigned int')
179 conf.CHECK_TYPE('ssize_t', 'int')
180 conf.CHECK_TYPE('ino_t', 'unsigned')
181 conf.CHECK_TYPE('loff_t', 'off_t')
182 conf.CHECK_TYPE('offset_t', 'loff_t')
183 conf.CHECK_TYPE('volatile int', define='HAVE_VOLATILE')
184 conf.CHECK_TYPE('uint_t', 'unsigned int')
185 conf.CHECK_TYPE('blksize_t', 'long', headers='sys/types.h sys/stat.h unistd.h')
186 conf.CHECK_TYPE('blkcnt_t', 'long', headers='sys/types.h sys/stat.h unistd.h')
188 conf.CHECK_SIZEOF('bool char int "long long" long short size_t ssize_t')
189 conf.CHECK_SIZEOF('int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t')
190 conf.CHECK_SIZEOF('void*', define='SIZEOF_VOID_P')
191 conf.CHECK_SIZEOF('off_t dev_t ino_t time_t')
193 conf.CHECK_TYPES('socklen_t', headers='sys/socket.h')
194 conf.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h')
195 conf.CHECK_TYPE_IN('struct addrinfo', 'netdb.h')
196 conf.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h')
197 conf.CHECK_CODE('struct sockaddr_in6 x', define='HAVE_STRUCT_SOCKADDR_IN6',
198 headers='sys/socket.h netdb.h netinet/in.h')
199 conf.CHECK_TYPE_IN('struct sockaddr_storage', 'sys/socket.h')
200 conf.CHECK_TYPE_IN('sa_family_t', 'sys/socket.h')
202 conf.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define='HAVE_SIG_ATOMIC_T_TYPE')
203 conf.CHECK_FUNCS('sigsetmask siggetmask sigprocmask sigblock sigaction sigset')
205 # Those functions are normally available in libc
206 if not conf.CHECK_FUNCS('''
207 inet_ntoa
208 inet_aton
209 inet_ntop
210 inet_pton
211 connect
212 gethostbyname
213 getaddrinfo
214 getnameinfo
215 freeaddrinfo
216 gai_strerror
217 socketpair''',
218 headers='sys/socket.h netinet/in.h arpa/inet.h netdb.h'):
219 conf.CHECK_FUNCS_IN('''
220 inet_ntoa
221 inet_aton
222 inet_ntop
223 inet_pton
224 connect
225 gethostbyname
226 getaddrinfo
227 getnameinfo
228 freeaddrinfo
229 gai_strerror
230 socketpair''',
231 'socket nsl',
232 headers='sys/socket.h netinet/in.h arpa/inet.h netdb.h')
233 conf.DEFINE('REPLACE_REQUIRES_LIBSOCKET_LIBNSL', 1)
235 conf.CHECK_FUNCS('memset_s memset_explicit')
237 conf.CHECK_CODE('''
238 #include <string.h>
240 int main(void)
242 char buf[] = "This is some content";
243 memset(buf, '\0', sizeof(buf)); __asm__ volatile("" : : "g"(&buf) : "memory");
244 return 0;
246 ''',
247 define='HAVE_GCC_VOLATILE_MEMORY_PROTECTION',
248 addmain=False,
249 msg='Checking for volatile memory protection',
250 local_include=False)
252 # Some old Linux systems have broken header files and
253 # miss the IPV6_V6ONLY define in netinet/in.h,
254 # but have it in linux/in6.h.
255 # We can't include both files so we just check if the value
256 # if defined and do the replacement in system/network.h
257 if not conf.CHECK_VARIABLE('IPV6_V6ONLY',
258 headers='sys/socket.h netdb.h netinet/in.h'):
259 conf.CHECK_CODE('''
260 #include <linux/in6.h>
261 #if (IPV6_V6ONLY != 26)
262 #error no IPV6_V6ONLY support on linux
263 #endif
264 int main(void) { return IPV6_V6ONLY; }
265 ''',
266 define='HAVE_LINUX_IPV6_V6ONLY_26',
267 addmain=False,
268 msg='Checking for IPV6_V6ONLY in linux/in6.h',
269 local_include=False)
271 conf.CHECK_CODE('''
272 struct sockaddr_storage sa_store;
273 struct addrinfo *ai = NULL;
274 struct in6_addr in6addr;
275 int idx = if_nametoindex("iface1");
276 int s = socket(AF_INET6, SOCK_STREAM, 0);
277 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
278 if (ret != 0) {
279 const char *es = gai_strerror(ret);
281 freeaddrinfo(ai);
283 int val = 1;
284 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
285 #define IPV6_V6ONLY 26
286 #endif
287 ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
288 (const void *)&val, sizeof(val));
290 ''',
291 define='HAVE_IPV6',
292 lib='nsl socket',
293 headers='sys/socket.h netdb.h netinet/in.h net/if.h')
295 if conf.CONFIG_SET('HAVE_SYS_UCONTEXT_H') and conf.CONFIG_SET('HAVE_SIGNAL_H'):
296 conf.CHECK_CODE('''
297 ucontext_t uc;
298 sigaddset(&uc.uc_sigmask, SIGUSR1);
299 ''',
300 'HAVE_UCONTEXT_T',
301 msg="Checking whether we have ucontext_t",
302 headers='signal.h sys/ucontext.h')
304 # Check for atomic builtins. */
305 conf.CHECK_CODE('''
306 int i;
307 (void)__sync_fetch_and_add(&i, 1);
308 ''',
309 'HAVE___SYNC_FETCH_AND_ADD',
310 msg='Checking for __sync_fetch_and_add compiler builtin')
312 conf.CHECK_CODE('''
313 int32_t i;
314 atomic_add_32(&i, 1);
315 ''',
316 'HAVE_ATOMIC_ADD_32',
317 headers='stdint.h sys/atomic.h',
318 msg='Checking for atomic_add_32 compiler builtin')
320 # Check for thread fence. */
321 tf = conf.CHECK_CODE('atomic_thread_fence(memory_order_seq_cst);',
322 'HAVE_ATOMIC_THREAD_FENCE',
323 headers='stdatomic.h',
324 msg='Checking for atomic_thread_fence(memory_order_seq_cst) in stdatomic.h')
325 if not tf:
326 tf = conf.CHECK_CODE('__atomic_thread_fence(__ATOMIC_SEQ_CST);',
327 'HAVE___ATOMIC_THREAD_FENCE',
328 msg='Checking for __atomic_thread_fence(__ATOMIC_SEQ_CST)')
329 if not tf:
330 # __sync_synchronize() is available since 2005 in gcc.
331 tf = conf.CHECK_CODE('__sync_synchronize();',
332 'HAVE___SYNC_SYNCHRONIZE',
333 msg='Checking for __sync_synchronize')
334 if tf:
335 conf.DEFINE('HAVE_ATOMIC_THREAD_FENCE_SUPPORT', 1)
337 conf.CHECK_CODE('''
338 #define FALL_THROUGH __attribute__((fallthrough))
340 enum direction_e {
341 UP = 0,
342 DOWN,
345 int main(void) {
346 enum direction_e key = UP;
347 int i = 10;
348 int j = 0;
350 switch (key) {
351 case UP:
352 i = 5;
353 FALL_THROUGH;
354 case DOWN:
355 j = i * 2;
356 break;
357 default:
358 break;
361 if (j < i) {
362 return 1;
365 return 0;
367 ''',
368 'HAVE_FALLTHROUGH_ATTRIBUTE',
369 addmain=False,
370 strict=True,
371 cflags=['-Werror=missing-declarations'],
372 msg='Checking for fallthrough attribute')
374 # these may be builtins, so we need the link=False strategy
375 conf.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link=False)
377 # See https://bugzilla.samba.org/show_bug.cgi?id=1097
379 # Ported in from autoconf where it was added with this commit:
380 # commit 804cfb20a067b4b687089dc72a8271b3abf20f31
381 # Author: Simo Sorce <idra@samba.org>
382 # Date: Wed Aug 25 14:24:16 2004 +0000
383 # r2070: Let's try to overload srnlen and strndup for AIX where they are natly broken.
385 host_os = sys.platform
386 if host_os.rfind('aix') > -1:
387 conf.DEFINE('BROKEN_STRNLEN', 1)
388 conf.DEFINE('BROKEN_STRNDUP', 1)
390 conf.CHECK_FUNCS('shl_load shl_unload shl_findsym')
391 conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
392 conf.CHECK_FUNCS('lstat getpgrp utime utimes setuid seteuid setreuid setresuid setgid setegid')
393 conf.CHECK_FUNCS('setregid setresgid chroot strerror vsyslog setlinebuf mktime')
394 conf.CHECK_FUNCS('ftruncate chsize rename waitpid wait4')
395 conf.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr strsep')
396 conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown')
397 conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
398 conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
399 conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign')
400 conf.CHECK_FUNCS('fmemopen')
402 if conf.CONFIG_SET('HAVE_MEMALIGN'):
403 conf.CHECK_DECLS('memalign', headers='malloc.h')
405 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
406 if conf.CHECK_CODE('''
407 #define _XOPEN_SOURCE 600
408 #include <stdlib.h>
409 #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
410 #error probably broken posix_fallocate
411 #endif
412 ''',
413 '_POSIX_FALLOCATE_CAPABLE_LIBC',
414 msg='Checking for posix_fallocate-capable libc'):
415 conf.CHECK_FUNCS('posix_fallocate')
417 conf.CHECK_FUNCS('prctl dirname basename')
419 strlcpy_in_bsd = False
421 # libbsd on some platforms provides strlcpy and strlcat
422 if not conf.CHECK_FUNCS('strlcpy strlcat'):
423 if conf.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers='bsd/string.h',
424 checklibc=True):
425 strlcpy_in_bsd = True
426 if not conf.CHECK_FUNCS('getpeereid'):
427 conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
428 if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
429 conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
430 if not conf.CHECK_FUNCS('setproctitle_init'):
431 conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
433 if not conf.CHECK_FUNCS('closefrom'):
434 conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h')
436 conf.CHECK_CODE('''
437 struct ucred cred;
438 socklen_t cred_len;
439 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
440 'HAVE_PEERCRED',
441 msg="Checking whether we can use SO_PEERCRED to get socket credentials",
442 headers='sys/types.h sys/socket.h')
444 #Some OS (ie. freebsd) return EINVAL if the conversion could not be done, it's not what we expect
445 #Let's detect those cases
446 if conf.CONFIG_SET('HAVE_STRTOLL'):
447 conf.CHECK_CODE('''
448 long long nb = strtoll("Text", NULL, 0);
449 if (errno == EINVAL) {
450 return 0;
451 } else {
452 return 1;
454 ''',
455 msg="Checking correct behavior of strtoll",
456 headers = 'errno.h',
457 execute = True,
458 define = 'HAVE_BSD_STRTOLL',
460 conf.CHECK_FUNCS('if_nametoindex strerror_r')
461 conf.CHECK_FUNCS('syslog')
462 conf.CHECK_FUNCS('gai_strerror get_current_dir_name')
463 conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups syscall setsid')
464 conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
465 conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
466 conf.CHECK_FUNCS('port_create')
467 conf.CHECK_FUNCS('getprogname')
469 conf.SET_TARGET_TYPE('attr', 'EMPTY')
471 xattr_headers='sys/attributes.h attr/xattr.h sys/xattr.h'
473 # default to 1, we set it to 0 if we don't find any EA implementation below:
474 conf.DEFINE('HAVE_XATTR_SUPPORT', 1)
475 if conf.CHECK_FUNCS_IN('getxattr', 'attr', checklibc=True, headers=xattr_headers):
476 conf.DEFINE('HAVE_XATTR_XATTR', 1)
477 # Darwin has extra options to xattr-family functions
478 conf.CHECK_CODE('getxattr(NULL, NULL, NULL, 0, 0, 0)',
479 headers=xattr_headers, local_include=False,
480 define='XATTR_ADDITIONAL_OPTIONS',
481 msg="Checking whether xattr interface takes additional options")
482 elif conf.CHECK_FUNCS_IN('attr_listf', 'attr', checklibc=True, headers=xattr_headers):
483 conf.DEFINE('HAVE_XATTR_ATTR', 1)
484 elif conf.CHECK_FUNCS('extattr_list_fd'):
485 conf.DEFINE('HAVE_XATTR_EXTATTR', 1)
486 elif conf.CHECK_FUNCS('flistea'):
487 conf.DEFINE('HAVE_XATTR_EA', 1)
488 elif not conf.CHECK_FUNCS('attropen'):
489 conf.DEFINE('HAVE_XATTR_SUPPORT', 0)
492 conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl',
493 checklibc=True, headers='dlfcn.h dl.h')
495 conf.CHECK_C_PROTOTYPE('dlopen', 'void *dlopen(const char* filename, unsigned int flags)',
496 define='DLOPEN_TAKES_UNSIGNED_FLAGS', headers='dlfcn.h dl.h')
499 # Check for clock_gettime and fdatasync
501 # First check libc to avoid linking libreplace against librt.
503 if conf.CHECK_FUNCS('fdatasync'):
504 # some systems are missing the declaration
505 conf.CHECK_DECLS('fdatasync')
506 else:
507 if conf.CHECK_FUNCS_IN('fdatasync', 'rt'):
508 # some systems are missing the declaration
509 conf.CHECK_DECLS('fdatasync')
511 has_clock_gettime = False
512 if conf.CHECK_FUNCS('clock_gettime'):
513 has_clock_gettime = True
515 if not has_clock_gettime:
516 if conf.CHECK_FUNCS_IN('clock_gettime', 'rt', checklibc=True):
517 has_clock_gettime = True
519 if has_clock_gettime:
520 for c in ['CLOCK_MONOTONIC', 'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME']:
521 conf.CHECK_CODE('''
522 #if TIME_WITH_SYS_TIME
523 # include <sys/time.h>
524 # include <time.h>
525 #else
526 # if HAVE_SYS_TIME_H
527 # include <sys/time.h>
528 # else
529 # include <time.h>
530 # endif
531 #endif
532 clockid_t clk = %s''' % c,
533 'HAVE_%s' % c,
534 msg='Checking whether the clock_gettime clock ID %s is available' % c)
536 conf.CHECK_TYPE('struct timespec', headers='sys/time.h time.h')
538 # these headers need to be tested as a group on freebsd
539 conf.CHECK_HEADERS(headers='sys/socket.h net/if.h', together=True)
540 conf.CHECK_HEADERS(headers='netinet/in.h arpa/nameser.h resolv.h', together=True)
541 conf.CHECK_FUNCS_IN('res_search', 'resolv', checklibc=True,
542 headers='netinet/in.h arpa/nameser.h resolv.h')
545 # try to find libintl (if --without-gettext is not given)
546 conf.env.intl_libs=''
547 if not Options.options.disable_gettext:
548 conf.CHECK_HEADERS('libintl.h')
549 conf.CHECK_LIB('intl')
550 conf.CHECK_DECLS('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset', headers="libintl.h")
551 # *textdomain functions are not strictly necessary
552 conf.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset',
553 '', checklibc=True, headers='libintl.h')
554 # gettext and dgettext must exist
555 # on some systems (the ones with glibc, those are in libc)
556 if conf.CHECK_FUNCS_IN('dgettext gettext', '', checklibc=True, headers='libintl.h'):
557 # save for dependency definitions
558 conf.env.intl_libs=''
559 # others (e.g. FreeBSD) have separate libintl
560 elif conf.CHECK_FUNCS_IN('dgettext gettext', 'intl', checklibc=False, headers='libintl.h'):
561 # save for dependency definitions
562 conf.env.intl_libs='intl'
563 # recheck with libintl
564 conf.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset',
565 'intl', checklibc=False, headers='libintl.h')
566 else:
567 # Some hosts need lib iconv for linking with lib intl
568 # So we try with flags just in case it helps.
569 oldflags = list(conf.env['EXTRA_LDFLAGS']);
570 conf.env['EXTRA_LDFLAGS'].extend(["-liconv"])
571 conf.CHECK_FUNCS_IN('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset',
572 'intl', checklibc=False, headers='libintl.h')
573 conf.env['EXTRA_LDFLAGS'] = oldflags
574 if conf.env['HAVE_GETTEXT'] and conf.env['HAVE_DGETTEXT']:
575 # save for dependency definitions
576 conf.env.intl_libs='iconv intl'
578 # did we find both prototypes and a library to link against?
579 # if not, unset the detected values (see Bug #9911)
580 if not (conf.env['HAVE_GETTEXT'] and conf.env['HAVE_DECL_GETTEXT']):
581 conf.undefine('HAVE_GETTEXT')
582 conf.undefine('HAVE_DECL_GETTEXT')
583 if not (conf.env['HAVE_DGETTEXT'] and conf.env['HAVE_DECL_DGETTEXT']):
584 conf.undefine('HAVE_DGETTEXT')
585 conf.undefine('HAVE_DECL_DGETTEXT')
587 conf.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc=True, headers='pthread.h')
589 PTHREAD_CFLAGS='error'
590 PTHREAD_LDFLAGS='error'
592 if PTHREAD_LDFLAGS == 'error':
593 # Check if pthread_attr_init() is provided by libc first!
594 if conf.CHECK_FUNCS('pthread_attr_init'):
595 PTHREAD_CFLAGS='-D_REENTRANT'
596 PTHREAD_LDFLAGS=''
597 if PTHREAD_LDFLAGS == 'error':
598 if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
599 PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
600 PTHREAD_LDFLAGS='-lpthread'
601 if PTHREAD_LDFLAGS == 'error':
602 if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
603 PTHREAD_CFLAGS='-D_THREAD_SAFE'
604 PTHREAD_LDFLAGS='-lpthreads'
605 if PTHREAD_LDFLAGS == 'error':
606 if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
607 PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
608 PTHREAD_LDFLAGS='-pthread'
610 # especially for HP-UX, where the CHECK_FUNC macro fails to test for
611 # pthread_attr_init. On pthread_mutex_lock it works there...
612 if PTHREAD_LDFLAGS == 'error':
613 if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
614 PTHREAD_CFLAGS='-D_REENTRANT'
615 PTHREAD_LDFLAGS='-lpthread'
617 if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
618 if conf.CONFIG_SET('replace_add_global_pthread'):
619 conf.ADD_CFLAGS(PTHREAD_CFLAGS)
620 conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
621 conf.CHECK_HEADERS('pthread.h')
622 conf.DEFINE('HAVE_PTHREAD', '1')
624 if conf.CONFIG_SET('HAVE_PTHREAD'):
626 conf.CHECK_FUNCS_IN('pthread_mutexattr_setrobust', 'pthread',
627 checklibc=True, headers='pthread.h')
628 if not conf.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST'):
629 conf.CHECK_FUNCS_IN('pthread_mutexattr_setrobust_np', 'pthread',
630 checklibc=True, headers='pthread.h')
632 conf.CHECK_DECLS('PTHREAD_MUTEX_ROBUST', headers='pthread.h')
633 if not conf.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST'):
634 conf.CHECK_DECLS('PTHREAD_MUTEX_ROBUST_NP', headers='pthread.h')
636 conf.CHECK_FUNCS_IN('pthread_mutex_consistent', 'pthread',
637 checklibc=True, headers='pthread.h')
638 if not conf.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT'):
639 conf.CHECK_FUNCS_IN('pthread_mutex_consistent_np', 'pthread',
640 checklibc=True, headers='pthread.h')
642 if ((conf.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST') or
643 conf.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP')) and
644 (conf.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST') or
645 conf.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST_NP')) and
646 (conf.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT') or
647 conf.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT_NP'))):
648 conf.DEFINE('HAVE_ROBUST_MUTEXES', 1)
650 # __thread is available since 2002 in gcc.
651 conf.CHECK_CODE('''
652 __thread int tls;
654 int main(void) {
655 return 0;
657 ''',
658 'HAVE___THREAD',
659 addmain=False,
660 msg='Checking for __thread local storage')
662 conf.CHECK_FUNCS_IN('crypt', 'crypt', checklibc=True)
663 conf.CHECK_FUNCS_IN('crypt_r', 'crypt', checklibc=True)
664 conf.CHECK_FUNCS_IN('crypt_rn', 'crypt', checklibc=True)
666 conf.CHECK_VARIABLE('rl_event_hook', define='HAVE_DECL_RL_EVENT_HOOK', always=True,
667 headers='readline.h readline/readline.h readline/history.h')
668 conf.CHECK_VARIABLE('program_invocation_short_name', headers='errno.h')
670 conf.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf')
672 conf.CHECK_DECLS('errno', headers='errno.h', reverse=True)
673 conf.CHECK_DECLS('EWOULDBLOCK', headers='errno.h')
674 conf.CHECK_DECLS('environ', reverse=True, headers='unistd.h')
675 conf.CHECK_DECLS('getgrent_r getpwent_r', reverse=True, headers='pwd.h grp.h')
676 conf.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse=True)
678 if conf.CONFIG_SET('HAVE_EPOLL_CREATE') and conf.CONFIG_SET('HAVE_SYS_EPOLL_H'):
679 conf.DEFINE('HAVE_EPOLL', 1)
681 if conf.CONFIG_SET('HAVE_PORT_CREATE') and conf.CONFIG_SET('HAVE_PORT_H'):
682 conf.DEFINE('HAVE_SOLARIS_PORTS', 1)
684 if conf.CHECK_FUNCS('eventfd', headers='sys/eventfd.h'):
685 conf.DEFINE('HAVE_EVENTFD', 1)
687 conf.CHECK_HEADERS('poll.h')
688 conf.CHECK_FUNCS('poll')
690 conf.CHECK_FUNCS('strptime')
691 conf.CHECK_DECLS('strptime', headers='time.h')
692 conf.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME
693 #include "tests/strptime.c"''',
694 define='HAVE_WORKING_STRPTIME',
695 execute=True,
696 addmain=False,
697 msg='Checking for working strptime')
699 conf.CHECK_C_PROTOTYPE('gettimeofday',
700 'int gettimeofday(struct timeval *tv, struct timezone *tz)',
701 define='HAVE_GETTIMEOFDAY_TZ', headers='sys/time.h')
703 conf.CHECK_C_PROTOTYPE('gettimeofday',
704 'int gettimeofday(struct timeval *tv, void *tz)',
705 define='HAVE_GETTIMEOFDAY_TZ_VOID',
706 headers='sys/time.h')
708 conf.CHECK_CODE('#include "tests/snprintf.c"',
709 define="HAVE_C99_VSNPRINTF",
710 execute=True,
711 addmain=False,
712 msg="Checking for C99 vsnprintf")
714 conf.CHECK_CODE('#include "tests/shared_mmap.c"',
715 addmain=False, add_headers=False, execute=True,
716 define='HAVE_SHARED_MMAP',
717 msg="Checking for HAVE_SHARED_MMAP")
719 conf.CHECK_CODE('#include "tests/shared_mremap.c"',
720 addmain=False, add_headers=False, execute=True,
721 define='HAVE_MREMAP',
722 msg="Checking for HAVE_MREMAP")
724 # OpenBSD (and I've heard HPUX) doesn't sync between mmap and write.
725 # FIXME: Anything other than a 0 or 1 exit code should abort configure!
726 conf.CHECK_CODE('#include "tests/incoherent_mmap.c"',
727 addmain=False, add_headers=False, execute=True,
728 define='HAVE_INCOHERENT_MMAP',
729 msg="Checking for HAVE_INCOHERENT_MMAP")
731 conf.SAMBA_BUILD_ENV()
733 conf.CHECK_CODE('''
734 typedef struct {unsigned x;} FOOBAR;
735 #define X_FOOBAR(x) ((FOOBAR) { x })
736 #define FOO_ONE X_FOOBAR(1)
737 FOOBAR f = FOO_ONE;
738 static const struct {
739 FOOBAR y;
740 } f2[] = {
741 {FOO_ONE}
743 static const FOOBAR f3[] = {FOO_ONE};
744 ''',
745 define='HAVE_IMMEDIATE_STRUCTURES')
747 conf.CHECK_CODE('mkdir("foo",0777)', define='HAVE_MKDIR_MODE', headers='sys/stat.h')
749 conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec', define='HAVE_STAT_TV_NSEC',
750 headers='sys/stat.h')
751 # we need the st_rdev test under two names
752 conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev',
753 define='HAVE_STRUCT_STAT_ST_RDEV',
754 headers='sys/stat.h')
755 conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_ST_RDEV',
756 headers='sys/stat.h')
757 conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family',
758 headers='sys/socket.h netinet/in.h')
759 conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', '__ss_family',
760 headers='sys/socket.h netinet/in.h')
763 if conf.CHECK_STRUCTURE_MEMBER('struct sockaddr', 'sa_len',
764 headers='sys/socket.h netinet/in.h',
765 define='HAVE_SOCKADDR_SA_LEN'):
766 # the old build system produced both defines
767 conf.DEFINE('HAVE_STRUCT_SOCKADDR_SA_LEN', 1)
769 conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_in', 'sin_len',
770 headers='sys/socket.h netinet/in.h',
771 define='HAVE_SOCK_SIN_LEN')
773 conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_in6', 'sin6_len',
774 headers='sys/socket.h netinet/in.h',
775 define='HAVE_SOCK_SIN6_LEN')
777 conf.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;',
778 define='HAVE_UNIXSOCKET', headers='sys/socket.h sys/un.h')
781 conf.CHECK_CODE('''
782 struct stat st;
783 char tpl[20]="/tmp/test.XXXXXX";
784 char tpl2[20]="/tmp/test.XXXXXX";
785 int fd = mkstemp(tpl);
786 int fd2 = mkstemp(tpl2);
787 if (fd == -1) {
788 if (fd2 != -1) {
789 unlink(tpl2);
791 exit(1);
793 if (fd2 == -1) exit(1);
794 unlink(tpl);
795 unlink(tpl2);
796 if (fstat(fd, &st) != 0) exit(1);
797 if ((st.st_mode & 0777) != 0600) exit(1);
798 if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
799 exit(1);
801 if (strcmp(tpl, tpl2) == 0) {
802 exit(1);
804 exit(0);
805 ''',
806 define='HAVE_SECURE_MKSTEMP',
807 execute=True,
808 mandatory=True) # lets see if we get a mandatory failure for this one
810 # look for a method of finding the list of network interfaces
811 for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
812 bsd_for_strlcpy = ''
813 if strlcpy_in_bsd:
814 bsd_for_strlcpy = ' bsd'
815 if conf.CHECK_CODE('''
816 #define %s 1
817 #define NO_CONFIG_H 1
818 #define AUTOCONF_TEST 1
819 #include "replace.c"
820 #include "inet_ntop.c"
821 #include "snprintf.c"
822 #include "getifaddrs.c"
823 #define getifaddrs_test main
824 #include "tests/getifaddrs.c"
825 ''' % method,
826 method,
827 lib='nsl socket' + bsd_for_strlcpy,
828 addmain=False,
829 execute=True):
830 break
832 conf.RECURSE('system')
833 conf.SAMBA_CONFIG_H()
834 if conf.CHECK_FUNCS('strerror_r'):
835 # Check if strerror_r is XSI-Compatable, the default GNU implementation
836 # is not
837 conf.CHECK_CODE('int strerror_r(int errnum, char *buf, size_t buflen);',
838 'STRERROR_R_XSI_NOT_GNU',
839 headers='string.h', addmain=False, link=False,
840 msg="Checking for XSI (rather than GNU) prototype for strerror_r")
843 REPLACEMENT_FUNCTIONS = {
844 'replace.c': ['ftruncate', 'strlcpy', 'strlcat', 'mktime', 'initgroups',
845 'memmove', 'strdup', 'setlinebuf', 'vsyslog', 'strnlen',
846 'strndup', 'waitpid', 'seteuid', 'setegid', 'chroot',
847 'mkstemp', 'mkdtemp', 'pread', 'pwrite', 'strcasestr',
848 'strsep', 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv',
849 'utime', 'utimes', 'dup2', 'chown', 'link', 'readlink',
850 'symlink', 'lchown', 'realpath', 'memmem', 'vdprintf',
851 'dprintf', 'get_current_dir_name',
852 'strerror_r', 'clock_gettime', 'memset_s'],
853 'timegm.c': ['timegm'],
854 # Note: C99_VSNPRINTF is not a function, but a special condition
855 # for replacement
856 'snprintf.c': ['C99_VSNPRINTF', 'snprintf', 'vsnprintf', 'asprintf', 'vasprintf'],
857 # Note: WORKING_STRPTIME is not a function, but a special condition
858 # for replacement
859 'strptime.c': ['WORKING_STRPTIME', 'strptime'],
863 def build(bld):
864 bld.RECURSE('buildtools/wafsamba')
866 REPLACE_HOSTCC_SOURCE = ''
868 for filename in REPLACEMENT_FUNCTIONS.keys():
869 for function in REPLACEMENT_FUNCTIONS[filename]:
870 if not bld.CONFIG_SET('HAVE_%s' % function.upper()):
871 REPLACE_HOSTCC_SOURCE += ' %s' % filename
872 break
874 extra_libs = ''
875 if bld.CONFIG_SET('HAVE_LIBBSD'): extra_libs += ' bsd'
876 if bld.CONFIG_SET('HAVE_LIBRT'): extra_libs += ' rt'
877 if bld.CONFIG_SET('REPLACE_REQUIRES_LIBSOCKET_LIBNSL'): extra_libs += ' socket nsl'
879 if not bld.CONFIG_SET('HAVE_CLOSEFROM'):
880 REPLACE_HOSTCC_SOURCE += ' closefrom.c'
882 bld.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC',
883 REPLACE_HOSTCC_SOURCE,
884 use_hostcc=True,
885 use_global_deps=False,
886 cflags='-D_SAMBA_HOSTCC_',
887 group='compiler_libraries',
888 deps = extra_libs
891 REPLACE_SOURCE = REPLACE_HOSTCC_SOURCE
892 REPLACE_SOURCE += ' cwrap.c'
894 if not bld.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE += ' dlfcn.c'
895 if not bld.CONFIG_SET('HAVE_POLL'): REPLACE_SOURCE += ' poll.c'
897 if not bld.CONFIG_SET('HAVE_SOCKETPAIR'): REPLACE_SOURCE += ' socketpair.c'
898 if not bld.CONFIG_SET('HAVE_CONNECT'): REPLACE_SOURCE += ' socket.c'
899 if not bld.CONFIG_SET('HAVE_GETIFADDRS'): REPLACE_SOURCE += ' getifaddrs.c'
900 if not bld.CONFIG_SET('HAVE_GETADDRINFO'): REPLACE_SOURCE += ' getaddrinfo.c'
901 if not bld.CONFIG_SET('HAVE_INET_NTOA'): REPLACE_SOURCE += ' inet_ntoa.c'
902 if not bld.CONFIG_SET('HAVE_INET_ATON'): REPLACE_SOURCE += ' inet_aton.c'
903 if not bld.CONFIG_SET('HAVE_INET_NTOP'): REPLACE_SOURCE += ' inet_ntop.c'
904 if not bld.CONFIG_SET('HAVE_INET_PTON'): REPLACE_SOURCE += ' inet_pton.c'
905 if not bld.CONFIG_SET('HAVE_GETXATTR') or bld.CONFIG_SET('XATTR_ADDITIONAL_OPTIONS'):
906 REPLACE_SOURCE += ' xattr.c'
908 if not bld.CONFIG_SET('HAVE_CLOSEFROM'):
909 REPLACE_SOURCE += ' closefrom.c'
911 bld.SAMBA_LIBRARY('replace',
912 source=REPLACE_SOURCE,
913 group='base_libraries',
914 # FIXME: Ideally symbols should be hidden here so they
915 # don't appear in the global namespace when Samba
916 # libraries are loaded, but this doesn't appear to work
917 # at the moment:
918 # hide_symbols=bld.BUILTIN_LIBRARY('replace'),
919 private_library=True,
920 deps='dl attr' + extra_libs)
922 replace_test_cflags = ''
923 if bld.CONFIG_SET('HAVE_WNO_FORMAT_TRUNCATION'):
924 replace_test_cflags += " -Wno-format-truncation"
925 bld.SAMBA_SUBSYSTEM('replace-test',
926 source='''tests/testsuite.c tests/strptime.c
927 tests/os2_delete.c tests/getifaddrs.c''',
928 deps='replace',
929 cflags=replace_test_cflags)
931 bld.SAMBA_BINARY('replace_testsuite',
932 source='tests/main.c',
933 deps='replace replace-test',
934 install=False)
936 # build replacements for stdint.h and stdbool.h if needed
937 bld.SAMBA_GENERATOR('replace_stdint_h',
938 rule='cp ${SRC} ${TGT}',
939 source='hdr_replace.h',
940 target='stdint.h',
941 enabled = not bld.CONFIG_SET('HAVE_STDINT_H'))
942 bld.SAMBA_GENERATOR('replace_stdbool_h',
943 rule='cp ${SRC} ${TGT}',
944 source='hdr_replace.h',
945 target='stdbool.h',
946 enabled = not bld.CONFIG_SET('HAVE_STDBOOL_H'))
948 bld.SAMBA_SUBSYSTEM('samba_intl', source='', use_global_deps=False,deps=bld.env.intl_libs)
950 def testonly(ctx):
951 '''run talloc testsuite'''
952 import samba_utils
954 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
955 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
957 cmd = os.path.join(Context.g_module.out, 'replace_testsuite')
958 ret = samba_utils.RUN_COMMAND(cmd)
959 print("testsuite returned %d" % ret)
960 sys.exit(ret)
962 # WAF doesn't build the unit tests for this, maybe because they don't link with talloc?
963 # This forces it
964 def test(ctx):
965 Options.commands.append('build')
966 Options.commands.append('testonly')
968 def dist():
969 '''makes a tarball for distribution'''
970 samba_dist.dist()