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