9 # find the buildtools directory
11 while not os
.path
.exists(top
+'/buildtools') and len(top
.split('/')) < 5:
13 sys
.path
.insert(0, top
+ '/buildtools/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')
24 opt
.BUILTIN_DEFAULT('NONE')
25 opt
.PRIVATE_EXTENSION_DEFAULT('')
26 opt
.RECURSE('buildtools/wafsamba')
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')
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."
102 #include <sys/sysctl.h>
103 int main(void) { return 0; }
105 define
='HAVE_SYS_SYSCTL_H',
106 cflags
=['-Werror=cpp'],
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 if conf
.CHECK_CFLAGS('-Wuse-after-free=1'):
132 conf
.define('HAVE_WUSE_AFTER_FREE_1', '1')
134 # Check for process set name support
136 #include <sys/prctl.h>
144 headers
='sys/prctl.h',
145 msg
='Checking for prctl syscall')
152 int main(void) { int fd = open("/dev/null", O_DIRECT); }
154 define
='HAVE_OPEN_O_DIRECT',
156 msg
='Checking for O_DIRECT flag to open(2)')
158 conf
.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
159 if not conf
.CHECK_TYPE('bool', define
='HAVE_BOOL'):
160 if not conf
.CHECK_TYPE('_Bool', define
='HAVE__Bool'):
161 raise Errors
.WafError('Samba requires a genuine boolean type')
163 conf
.CHECK_TYPE('int8_t', 'char')
164 conf
.CHECK_TYPE('uint8_t', 'unsigned char')
165 conf
.CHECK_TYPE('int16_t', 'short')
166 conf
.CHECK_TYPE('uint16_t', 'unsigned short')
167 conf
.CHECK_TYPE('int32_t', 'int')
168 conf
.CHECK_TYPE('uint32_t', 'unsigned')
169 conf
.CHECK_TYPE('int64_t', 'long long')
170 conf
.CHECK_TYPE('uint64_t', 'unsigned long long')
171 conf
.CHECK_TYPE('size_t', 'unsigned int')
172 conf
.CHECK_TYPE('ssize_t', 'int')
173 conf
.CHECK_TYPE('ino_t', 'unsigned')
174 conf
.CHECK_TYPE('loff_t', 'off_t')
175 conf
.CHECK_TYPE('offset_t', 'loff_t')
176 conf
.CHECK_TYPE('volatile int', define
='HAVE_VOLATILE')
177 conf
.CHECK_TYPE('uint_t', 'unsigned int')
178 conf
.CHECK_TYPE('blksize_t', 'long', headers
='sys/types.h sys/stat.h unistd.h')
179 conf
.CHECK_TYPE('blkcnt_t', 'long', headers
='sys/types.h sys/stat.h unistd.h')
181 conf
.CHECK_SIZEOF('bool char int "long long" long short size_t ssize_t')
182 conf
.CHECK_SIZEOF('int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t')
183 conf
.CHECK_SIZEOF('void*', define
='SIZEOF_VOID_P')
184 conf
.CHECK_SIZEOF('off_t dev_t ino_t time_t')
186 conf
.CHECK_TYPES('socklen_t', headers
='sys/socket.h')
187 conf
.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h')
188 conf
.CHECK_TYPE_IN('struct addrinfo', 'netdb.h')
189 conf
.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h')
190 conf
.CHECK_CODE('struct sockaddr_in6 x', define
='HAVE_STRUCT_SOCKADDR_IN6',
191 headers
='sys/socket.h netdb.h netinet/in.h')
192 conf
.CHECK_TYPE_IN('struct sockaddr_storage', 'sys/socket.h')
193 conf
.CHECK_TYPE_IN('sa_family_t', 'sys/socket.h')
195 conf
.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define
='HAVE_SIG_ATOMIC_T_TYPE')
196 conf
.CHECK_FUNCS('sigsetmask siggetmask sigprocmask sigblock sigaction sigset')
198 # Those functions are normally available in libc
199 if not conf
.CHECK_FUNCS('''
211 headers
='sys/socket.h netinet/in.h arpa/inet.h netdb.h'):
212 conf
.CHECK_FUNCS_IN('''
225 headers
='sys/socket.h netinet/in.h arpa/inet.h netdb.h')
226 conf
.DEFINE('REPLACE_REQUIRES_LIBSOCKET_LIBNSL', 1)
228 conf
.CHECK_FUNCS('memset_s memset_explicit')
235 char buf[] = "This is some content";
236 memset(buf, '\0', sizeof(buf)); __asm__ volatile("" : : "g"(&buf) : "memory");
240 define
='HAVE_GCC_VOLATILE_MEMORY_PROTECTION',
242 msg
='Checking for volatile memory protection',
245 # Some old Linux systems have broken header files and
246 # miss the IPV6_V6ONLY define in netinet/in.h,
247 # but have it in linux/in6.h.
248 # We can't include both files so we just check if the value
249 # if defined and do the replacement in system/network.h
250 if not conf
.CHECK_VARIABLE('IPV6_V6ONLY',
251 headers
='sys/socket.h netdb.h netinet/in.h'):
253 #include <linux/in6.h>
254 #if (IPV6_V6ONLY != 26)
255 #error no IPV6_V6ONLY support on linux
257 int main(void) { return IPV6_V6ONLY; }
259 define
='HAVE_LINUX_IPV6_V6ONLY_26',
261 msg
='Checking for IPV6_V6ONLY in linux/in6.h',
265 struct sockaddr_storage sa_store;
266 struct addrinfo *ai = NULL;
267 struct in6_addr in6addr;
268 int idx = if_nametoindex("iface1");
269 int s = socket(AF_INET6, SOCK_STREAM, 0);
270 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
272 const char *es = gai_strerror(ret);
277 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
278 #define IPV6_V6ONLY 26
280 ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
281 (const void *)&val, sizeof(val));
286 headers
='sys/socket.h netdb.h netinet/in.h net/if.h')
288 if conf
.CONFIG_SET('HAVE_SYS_UCONTEXT_H') and conf
.CONFIG_SET('HAVE_SIGNAL_H'):
291 sigaddset(&uc.uc_sigmask, SIGUSR1);
294 msg
="Checking whether we have ucontext_t",
295 headers
='signal.h sys/ucontext.h')
297 # Check for atomic builtins. */
300 (void)__sync_fetch_and_add(&i, 1);
302 'HAVE___SYNC_FETCH_AND_ADD',
303 msg
='Checking for __sync_fetch_and_add compiler builtin')
307 (void)__sync_add_and_fetch(&i, 1);
309 'HAVE___SYNC_ADD_AND_FETCH',
310 msg
='Checking for __sync_add_and_fetch compiler builtin')
314 atomic_add_32(&i, 1);
316 'HAVE_ATOMIC_ADD_32',
317 headers
='stdint.h sys/atomic.h',
318 msg
='Checking for atomic_add_32 compiler builtin')
322 j = __atomic_add_fetch(&i,1,__ATOMIC_SEQ_CST)
324 'HAVE___ATOMIC_ADD_FETCH',
326 msg
='Checking for __atomic_add_fetch compiler builtin')
330 __atomic_load(&i,&j,__ATOMIC_SEQ_CST)
332 'HAVE___ATOMIC_ADD_LOAD',
334 msg
='Checking for __atomic_load compiler builtin')
336 # Check for thread fence. */
337 tf
= conf
.CHECK_CODE('atomic_thread_fence(memory_order_seq_cst);',
338 'HAVE_ATOMIC_THREAD_FENCE',
339 headers
='stdatomic.h',
340 msg
='Checking for atomic_thread_fence(memory_order_seq_cst) in stdatomic.h')
342 tf
= conf
.CHECK_CODE('__atomic_thread_fence(__ATOMIC_SEQ_CST);',
343 'HAVE___ATOMIC_THREAD_FENCE',
344 msg
='Checking for __atomic_thread_fence(__ATOMIC_SEQ_CST)')
346 # __sync_synchronize() is available since 2005 in gcc.
347 tf
= conf
.CHECK_CODE('__sync_synchronize();',
348 'HAVE___SYNC_SYNCHRONIZE',
349 msg
='Checking for __sync_synchronize')
351 conf
.DEFINE('HAVE_ATOMIC_THREAD_FENCE_SUPPORT', 1)
354 #define FALL_THROUGH __attribute__((fallthrough))
362 enum direction_e key = UP;
384 'HAVE_FALLTHROUGH_ATTRIBUTE',
387 cflags
=['-Werror=missing-declarations'],
388 msg
='Checking for fallthrough attribute')
390 # these may be builtins, so we need the link=False strategy
391 conf
.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link
=False)
393 # See https://bugzilla.samba.org/show_bug.cgi?id=1097
395 # Ported in from autoconf where it was added with this commit:
396 # commit 804cfb20a067b4b687089dc72a8271b3abf20f31
397 # Author: Simo Sorce <idra@samba.org>
398 # Date: Wed Aug 25 14:24:16 2004 +0000
399 # r2070: Let's try to overload srnlen and strndup for AIX where they are natly broken.
401 host_os
= sys
.platform
402 if host_os
.rfind('aix') > -1:
403 conf
.DEFINE('BROKEN_STRNLEN', 1)
404 conf
.DEFINE('BROKEN_STRNDUP', 1)
406 conf
.CHECK_FUNCS('shl_load shl_unload shl_findsym')
407 conf
.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
408 conf
.CHECK_FUNCS('lstat getpgrp utime utimes setuid seteuid setreuid setresuid setgid setegid')
409 conf
.CHECK_FUNCS('setregid setresgid chroot strerror vsyslog setlinebuf mktime')
410 conf
.CHECK_FUNCS('ftruncate chsize rename waitpid wait4')
411 conf
.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr strsep')
412 conf
.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown')
413 conf
.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
414 conf
.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
415 conf
.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign')
416 conf
.CHECK_FUNCS('fmemopen')
418 if conf
.CONFIG_SET('HAVE_MEMALIGN'):
419 conf
.CHECK_DECLS('memalign', headers
='malloc.h')
421 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
422 if conf
.CHECK_CODE('''
423 #define _XOPEN_SOURCE 600
425 #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
426 #error probably broken posix_fallocate
429 '_POSIX_FALLOCATE_CAPABLE_LIBC',
430 msg
='Checking for posix_fallocate-capable libc'):
431 conf
.CHECK_FUNCS('posix_fallocate')
433 conf
.CHECK_FUNCS('prctl dirname basename')
435 strlcpy_in_bsd
= False
437 # libbsd on some platforms provides strlcpy and strlcat
438 if not conf
.CHECK_FUNCS('strlcpy strlcat'):
439 if conf
.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers
='bsd/string.h',
441 strlcpy_in_bsd
= True
442 if not conf
.CHECK_FUNCS('getpeereid'):
443 conf
.CHECK_FUNCS_IN('getpeereid', 'bsd', headers
='sys/types.h bsd/unistd.h')
444 if not conf
.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers
='setproctitle.h'):
445 conf
.CHECK_FUNCS_IN('setproctitle', 'bsd', headers
='sys/types.h bsd/unistd.h')
446 if not conf
.CHECK_FUNCS('setproctitle_init'):
447 conf
.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers
='sys/types.h bsd/unistd.h')
449 if not conf
.CHECK_FUNCS('closefrom'):
450 conf
.CHECK_FUNCS_IN('closefrom', 'bsd', headers
='bsd/unistd.h')
455 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
457 msg
="Checking whether we can use SO_PEERCRED to get socket credentials",
458 headers
='sys/types.h sys/socket.h')
460 #Some OS (ie. freebsd) return EINVAL if the conversion could not be done, it's not what we expect
461 #Let's detect those cases
462 if conf
.CONFIG_SET('HAVE_STRTOLL'):
464 long long nb = strtoll("Text", NULL, 0);
465 if (errno == EINVAL) {
471 msg
="Checking correct behavior of strtoll",
474 define
= 'HAVE_BSD_STRTOLL',
476 conf
.CHECK_FUNCS('if_nameindex if_nametoindex strerror_r')
477 conf
.CHECK_FUNCS('syslog')
478 conf
.CHECK_FUNCS('gai_strerror get_current_dir_name')
479 conf
.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups syscall setsid')
480 conf
.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
481 conf
.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
482 conf
.CHECK_FUNCS('port_create')
483 conf
.CHECK_FUNCS('getprogname')
484 if not conf
.CHECK_FUNCS('copy_file_range'):
486 syscall(SYS_copy_file_range,0,NULL,0,NULL,0,0);
488 'HAVE_SYSCALL_COPY_FILE_RANGE',
489 headers
='sys/syscall.h unistd.h',
490 msg
='Checking whether we have copy_file_range system call')
492 conf
.SET_TARGET_TYPE('attr', 'EMPTY')
494 xattr_headers
='sys/attributes.h attr/xattr.h sys/xattr.h'
496 # default to 1, we set it to 0 if we don't find any EA implementation below:
497 conf
.DEFINE('HAVE_XATTR_SUPPORT', 1)
498 if conf
.CHECK_FUNCS_IN('getxattr', 'attr', checklibc
=True, headers
=xattr_headers
):
499 conf
.DEFINE('HAVE_XATTR_XATTR', 1)
500 # Darwin has extra options to xattr-family functions
501 conf
.CHECK_CODE('getxattr(NULL, NULL, NULL, 0, 0, 0)',
502 headers
=xattr_headers
, local_include
=False,
503 define
='XATTR_ADDITIONAL_OPTIONS',
504 msg
="Checking whether xattr interface takes additional options")
505 elif conf
.CHECK_FUNCS_IN('attr_listf', 'attr', checklibc
=True, headers
=xattr_headers
):
506 conf
.DEFINE('HAVE_XATTR_ATTR', 1)
507 elif conf
.CHECK_FUNCS('extattr_list_fd'):
508 conf
.DEFINE('HAVE_XATTR_EXTATTR', 1)
509 elif conf
.CHECK_FUNCS('flistea'):
510 conf
.DEFINE('HAVE_XATTR_EA', 1)
511 elif not conf
.CHECK_FUNCS('attropen'):
512 conf
.DEFINE('HAVE_XATTR_SUPPORT', 0)
515 conf
.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl',
516 checklibc
=True, headers
='dlfcn.h dl.h')
518 conf
.CHECK_C_PROTOTYPE('dlopen', 'void *dlopen(const char* filename, unsigned int flags)',
519 define
='DLOPEN_TAKES_UNSIGNED_FLAGS', headers
='dlfcn.h dl.h')
522 # Check for clock_gettime and fdatasync
524 # First check libc to avoid linking libreplace against librt.
526 if conf
.CHECK_FUNCS('fdatasync'):
527 # some systems are missing the declaration
528 conf
.CHECK_DECLS('fdatasync')
530 if conf
.CHECK_FUNCS_IN('fdatasync', 'rt'):
531 # some systems are missing the declaration
532 conf
.CHECK_DECLS('fdatasync')
534 has_clock_gettime
= False
535 if conf
.CHECK_FUNCS('clock_gettime'):
536 has_clock_gettime
= True
538 if not has_clock_gettime
:
539 if conf
.CHECK_FUNCS_IN('clock_gettime', 'rt', checklibc
=True):
540 has_clock_gettime
= True
542 if has_clock_gettime
:
543 for c
in ['CLOCK_MONOTONIC', 'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME']:
545 #if TIME_WITH_SYS_TIME
546 # include <sys/time.h>
550 # include <sys/time.h>
555 clockid_t clk = %s''' % c
,
557 msg
='Checking whether the clock_gettime clock ID %s is available' % c
)
559 conf
.CHECK_TYPE('struct timespec', headers
='sys/time.h time.h')
561 # these headers need to be tested as a group on freebsd
562 conf
.CHECK_HEADERS(headers
='sys/socket.h net/if.h', together
=True)
563 conf
.CHECK_HEADERS(headers
='netinet/in.h arpa/nameser.h resolv.h', together
=True)
564 conf
.CHECK_FUNCS_IN('res_search', 'resolv', checklibc
=True,
565 headers
='netinet/in.h arpa/nameser.h resolv.h')
568 # try to find libintl (if --without-gettext is not given)
569 conf
.env
.intl_libs
=''
570 if not Options
.options
.disable_gettext
:
571 conf
.CHECK_HEADERS('libintl.h')
572 conf
.CHECK_LIB('intl')
573 conf
.CHECK_DECLS('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset', headers
="libintl.h")
574 # *textdomain functions are not strictly necessary
575 conf
.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset',
576 '', checklibc
=True, headers
='libintl.h')
577 # gettext and dgettext must exist
578 # on some systems (the ones with glibc, those are in libc)
579 if conf
.CHECK_FUNCS_IN('dgettext gettext', '', checklibc
=True, headers
='libintl.h'):
580 # save for dependency definitions
581 conf
.env
.intl_libs
=''
582 # others (e.g. FreeBSD) have separate libintl
583 elif conf
.CHECK_FUNCS_IN('dgettext gettext', 'intl', checklibc
=False, headers
='libintl.h'):
584 # save for dependency definitions
585 conf
.env
.intl_libs
='intl'
586 # recheck with libintl
587 conf
.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset',
588 'intl', checklibc
=False, headers
='libintl.h')
590 # Some hosts need lib iconv for linking with lib intl
591 # So we try with flags just in case it helps.
592 oldflags
= list(conf
.env
['EXTRA_LDFLAGS']);
593 conf
.env
['EXTRA_LDFLAGS'].extend(["-liconv"])
594 conf
.CHECK_FUNCS_IN('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset',
595 'intl', checklibc
=False, headers
='libintl.h')
596 conf
.env
['EXTRA_LDFLAGS'] = oldflags
597 if conf
.env
['HAVE_GETTEXT'] and conf
.env
['HAVE_DGETTEXT']:
598 # save for dependency definitions
599 conf
.env
.intl_libs
='iconv intl'
601 # did we find both prototypes and a library to link against?
602 # if not, unset the detected values (see Bug #9911)
603 if not (conf
.env
['HAVE_GETTEXT'] and conf
.env
['HAVE_DECL_GETTEXT']):
604 conf
.undefine('HAVE_GETTEXT')
605 conf
.undefine('HAVE_DECL_GETTEXT')
606 if not (conf
.env
['HAVE_DGETTEXT'] and conf
.env
['HAVE_DECL_DGETTEXT']):
607 conf
.undefine('HAVE_DGETTEXT')
608 conf
.undefine('HAVE_DECL_DGETTEXT')
610 conf
.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc
=True, headers
='pthread.h')
612 PTHREAD_CFLAGS
='error'
613 PTHREAD_LDFLAGS
='error'
615 if PTHREAD_LDFLAGS
== 'error':
616 # Check if pthread_attr_init() is provided by libc first!
617 if conf
.CHECK_FUNCS('pthread_attr_init'):
618 PTHREAD_CFLAGS
='-D_REENTRANT'
620 if PTHREAD_LDFLAGS
== 'error':
621 if conf
.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
622 PTHREAD_CFLAGS
='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
623 PTHREAD_LDFLAGS
='-lpthread'
624 if PTHREAD_LDFLAGS
== 'error':
625 if conf
.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
626 PTHREAD_CFLAGS
='-D_THREAD_SAFE'
627 PTHREAD_LDFLAGS
='-lpthreads'
628 if PTHREAD_LDFLAGS
== 'error':
629 if conf
.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
630 PTHREAD_CFLAGS
='-D_THREAD_SAFE -pthread'
631 PTHREAD_LDFLAGS
='-pthread'
633 # especially for HP-UX, where the CHECK_FUNC macro fails to test for
634 # pthread_attr_init. On pthread_mutex_lock it works there...
635 if PTHREAD_LDFLAGS
== 'error':
636 if conf
.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
637 PTHREAD_CFLAGS
='-D_REENTRANT'
638 PTHREAD_LDFLAGS
='-lpthread'
640 if PTHREAD_CFLAGS
!= 'error' and PTHREAD_LDFLAGS
!= 'error':
641 if conf
.CONFIG_SET('replace_add_global_pthread'):
642 conf
.ADD_CFLAGS(PTHREAD_CFLAGS
)
643 conf
.ADD_LDFLAGS(PTHREAD_LDFLAGS
)
644 conf
.CHECK_HEADERS('pthread.h')
645 conf
.DEFINE('HAVE_PTHREAD', '1')
647 if conf
.CONFIG_SET('HAVE_PTHREAD'):
649 conf
.CHECK_FUNCS_IN('pthread_mutexattr_setrobust', 'pthread',
650 checklibc
=True, headers
='pthread.h')
651 if not conf
.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST'):
652 conf
.CHECK_FUNCS_IN('pthread_mutexattr_setrobust_np', 'pthread',
653 checklibc
=True, headers
='pthread.h')
655 conf
.CHECK_DECLS('PTHREAD_MUTEX_ROBUST', headers
='pthread.h')
656 if not conf
.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST'):
657 conf
.CHECK_DECLS('PTHREAD_MUTEX_ROBUST_NP', headers
='pthread.h')
659 conf
.CHECK_FUNCS_IN('pthread_mutex_consistent', 'pthread',
660 checklibc
=True, headers
='pthread.h')
661 if not conf
.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT'):
662 conf
.CHECK_FUNCS_IN('pthread_mutex_consistent_np', 'pthread',
663 checklibc
=True, headers
='pthread.h')
665 if ((conf
.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST') or
666 conf
.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP')) and
667 (conf
.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST') or
668 conf
.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST_NP')) and
669 (conf
.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT') or
670 conf
.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT_NP'))):
671 conf
.DEFINE('HAVE_ROBUST_MUTEXES', 1)
673 # __thread is available since 2002 in gcc.
683 msg
='Checking for __thread local storage')
685 conf
.CHECK_FUNCS_IN('crypt', 'crypt', checklibc
=True)
686 conf
.CHECK_FUNCS_IN('crypt_r', 'crypt', checklibc
=True)
687 conf
.CHECK_FUNCS_IN('crypt_rn', 'crypt', checklibc
=True)
689 conf
.CHECK_VARIABLE('rl_event_hook', define
='HAVE_DECL_RL_EVENT_HOOK', always
=True,
690 headers
='readline.h readline/readline.h readline/history.h')
691 conf
.CHECK_VARIABLE('program_invocation_short_name', headers
='errno.h')
693 conf
.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf')
695 conf
.CHECK_DECLS('errno', headers
='errno.h', reverse
=True)
696 conf
.CHECK_DECLS('EWOULDBLOCK', headers
='errno.h')
697 conf
.CHECK_DECLS('environ', reverse
=True, headers
='unistd.h')
698 conf
.CHECK_DECLS('getgrent_r getpwent_r', reverse
=True, headers
='pwd.h grp.h')
699 conf
.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse
=True)
701 if conf
.CONFIG_SET('HAVE_EPOLL_CREATE') and conf
.CONFIG_SET('HAVE_SYS_EPOLL_H'):
702 conf
.DEFINE('HAVE_EPOLL', 1)
704 if conf
.CONFIG_SET('HAVE_PORT_CREATE') and conf
.CONFIG_SET('HAVE_PORT_H'):
705 conf
.DEFINE('HAVE_SOLARIS_PORTS', 1)
707 if conf
.CHECK_FUNCS('eventfd', headers
='sys/eventfd.h'):
708 conf
.DEFINE('HAVE_EVENTFD', 1)
710 conf
.CHECK_HEADERS('poll.h')
711 conf
.CHECK_FUNCS('poll')
713 conf
.CHECK_FUNCS('strptime')
714 conf
.CHECK_DECLS('strptime', headers
='time.h')
715 conf
.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME
716 #include "tests/strptime.c"''',
717 define
='HAVE_WORKING_STRPTIME',
720 msg
='Checking for working strptime')
722 conf
.CHECK_C_PROTOTYPE('gettimeofday',
723 'int gettimeofday(struct timeval *tv, struct timezone *tz)',
724 define
='HAVE_GETTIMEOFDAY_TZ', headers
='sys/time.h')
726 conf
.CHECK_C_PROTOTYPE('gettimeofday',
727 'int gettimeofday(struct timeval *tv, void *tz)',
728 define
='HAVE_GETTIMEOFDAY_TZ_VOID',
729 headers
='sys/time.h')
731 conf
.CHECK_CODE('#include "tests/snprintf.c"',
732 define
="HAVE_C99_VSNPRINTF",
735 msg
="Checking for C99 vsnprintf")
737 conf
.CHECK_CODE('#include "tests/shared_mmap.c"',
738 addmain
=False, add_headers
=False, execute
=True,
739 define
='HAVE_SHARED_MMAP',
740 msg
="Checking for HAVE_SHARED_MMAP")
742 conf
.CHECK_CODE('#include "tests/shared_mremap.c"',
743 addmain
=False, add_headers
=False, execute
=True,
744 define
='HAVE_MREMAP',
745 msg
="Checking for HAVE_MREMAP")
747 # OpenBSD (and I've heard HPUX) doesn't sync between mmap and write.
748 # FIXME: Anything other than a 0 or 1 exit code should abort configure!
749 conf
.CHECK_CODE('#include "tests/incoherent_mmap.c"',
750 addmain
=False, add_headers
=False, execute
=True,
751 define
='HAVE_INCOHERENT_MMAP',
752 msg
="Checking for HAVE_INCOHERENT_MMAP")
754 conf
.SAMBA_BUILD_ENV()
757 typedef struct {unsigned x;} FOOBAR;
758 #define X_FOOBAR(x) ((FOOBAR) { x })
759 #define FOO_ONE X_FOOBAR(1)
761 static const struct {
766 static const FOOBAR f3[] = {FOO_ONE};
768 define
='HAVE_IMMEDIATE_STRUCTURES')
770 conf
.CHECK_CODE('mkdir("foo",0777)', define
='HAVE_MKDIR_MODE', headers
='sys/stat.h')
772 # we need the st_rdev test under two names
773 conf
.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev',
774 define
='HAVE_STRUCT_STAT_ST_RDEV',
775 headers
='sys/stat.h')
776 conf
.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define
='HAVE_ST_RDEV',
777 headers
='sys/stat.h')
778 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family',
779 headers
='sys/socket.h netinet/in.h')
780 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', '__ss_family',
781 headers
='sys/socket.h netinet/in.h')
784 if conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr', 'sa_len',
785 headers
='sys/socket.h netinet/in.h',
786 define
='HAVE_SOCKADDR_SA_LEN'):
787 # the old build system produced both defines
788 conf
.DEFINE('HAVE_STRUCT_SOCKADDR_SA_LEN', 1)
790 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_in', 'sin_len',
791 headers
='sys/socket.h netinet/in.h',
792 define
='HAVE_SOCK_SIN_LEN')
794 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_in6', 'sin6_len',
795 headers
='sys/socket.h netinet/in.h',
796 define
='HAVE_SOCK_SIN6_LEN')
798 conf
.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;',
799 define
='HAVE_UNIXSOCKET', headers
='sys/socket.h sys/un.h')
804 char tpl[20]="/tmp/test.XXXXXX";
805 char tpl2[20]="/tmp/test.XXXXXX";
806 int fd = mkstemp(tpl);
807 int fd2 = mkstemp(tpl2);
814 if (fd2 == -1) exit(1);
817 if (fstat(fd, &st) != 0) exit(1);
818 if ((st.st_mode & 0777) != 0600) exit(1);
819 if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
822 if (strcmp(tpl, tpl2) == 0) {
827 define
='HAVE_SECURE_MKSTEMP',
829 mandatory
=True) # lets see if we get a mandatory failure for this one
831 # look for a method of finding the list of network interfaces
832 for method
in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
835 bsd_for_strlcpy
= ' bsd'
836 if conf
.CHECK_CODE('''
838 #define NO_CONFIG_H 1
839 #define AUTOCONF_TEST 1
841 #include "inet_ntop.c"
842 #include "snprintf.c"
843 #include "getifaddrs.c"
844 #define getifaddrs_test main
845 #include "tests/getifaddrs.c"
848 lib
='nsl socket' + bsd_for_strlcpy
,
853 conf
.RECURSE('system')
854 conf
.SAMBA_CONFIG_H()
855 if conf
.CHECK_FUNCS('strerror_r'):
856 # Check if strerror_r is XSI-Compatable, the default GNU implementation
858 conf
.CHECK_CODE('int strerror_r(int errnum, char *buf, size_t buflen);',
859 'STRERROR_R_XSI_NOT_GNU',
860 headers
='string.h', addmain
=False, link
=False,
861 msg
="Checking for XSI (rather than GNU) prototype for strerror_r")
864 REPLACEMENT_FUNCTIONS
= {
865 'replace.c': ['ftruncate', 'strlcpy', 'strlcat', 'mktime', 'initgroups',
866 'memmove', 'strdup', 'setlinebuf', 'vsyslog', 'strnlen',
867 'strndup', 'waitpid', 'seteuid', 'setegid', 'chroot',
868 'mkstemp', 'mkdtemp', 'pread', 'pwrite', 'strcasestr',
869 'strsep', 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv',
870 'utime', 'utimes', 'dup2', 'chown', 'link', 'readlink',
871 'symlink', 'lchown', 'realpath', 'memmem', 'vdprintf',
872 'dprintf', 'get_current_dir_name', 'copy_file_range',
873 'strerror_r', 'clock_gettime', 'memset_s'],
874 'timegm.c': ['timegm'],
875 # Note: C99_VSNPRINTF is not a function, but a special condition
877 'snprintf.c': ['C99_VSNPRINTF', 'snprintf', 'vsnprintf', 'asprintf', 'vasprintf'],
878 # Note: WORKING_STRPTIME is not a function, but a special condition
880 'strptime.c': ['WORKING_STRPTIME', 'strptime'],
885 bld
.RECURSE('buildtools/wafsamba')
887 REPLACE_HOSTCC_SOURCE
= ''
889 for filename
in REPLACEMENT_FUNCTIONS
.keys():
890 for function
in REPLACEMENT_FUNCTIONS
[filename
]:
891 if not bld
.CONFIG_SET('HAVE_%s' % function
.upper()):
892 REPLACE_HOSTCC_SOURCE
+= ' %s' % filename
896 if bld
.CONFIG_SET('HAVE_LIBBSD'): extra_libs
+= ' bsd'
897 if bld
.CONFIG_SET('HAVE_LIBRT'): extra_libs
+= ' rt'
898 if bld
.CONFIG_SET('REPLACE_REQUIRES_LIBSOCKET_LIBNSL'): extra_libs
+= ' socket nsl'
900 if not bld
.CONFIG_SET('HAVE_CLOSEFROM'):
901 REPLACE_HOSTCC_SOURCE
+= ' closefrom.c'
903 bld
.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC',
904 REPLACE_HOSTCC_SOURCE
,
906 use_global_deps
=False,
907 group
='hostcc_base_build_main',
911 REPLACE_SOURCE
= REPLACE_HOSTCC_SOURCE
913 if not bld
.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE
+= ' dlfcn.c'
914 if not bld
.CONFIG_SET('HAVE_POLL'): REPLACE_SOURCE
+= ' poll.c'
916 if not bld
.CONFIG_SET('HAVE_SOCKETPAIR'): REPLACE_SOURCE
+= ' socketpair.c'
917 if not bld
.CONFIG_SET('HAVE_CONNECT'): REPLACE_SOURCE
+= ' socket.c'
918 if not bld
.CONFIG_SET('HAVE_GETIFADDRS'): REPLACE_SOURCE
+= ' getifaddrs.c'
919 if not bld
.CONFIG_SET('HAVE_GETADDRINFO'): REPLACE_SOURCE
+= ' getaddrinfo.c'
920 if not bld
.CONFIG_SET('HAVE_INET_NTOA'): REPLACE_SOURCE
+= ' inet_ntoa.c'
921 if not bld
.CONFIG_SET('HAVE_INET_ATON'): REPLACE_SOURCE
+= ' inet_aton.c'
922 if not bld
.CONFIG_SET('HAVE_INET_NTOP'): REPLACE_SOURCE
+= ' inet_ntop.c'
923 if not bld
.CONFIG_SET('HAVE_INET_PTON'): REPLACE_SOURCE
+= ' inet_pton.c'
924 if not bld
.CONFIG_SET('HAVE_GETXATTR') or bld
.CONFIG_SET('XATTR_ADDITIONAL_OPTIONS'):
925 REPLACE_SOURCE
+= ' xattr.c'
927 if not bld
.CONFIG_SET('HAVE_CLOSEFROM'):
928 REPLACE_SOURCE
+= ' closefrom.c'
930 bld
.SAMBA_LIBRARY('replace',
931 source
=REPLACE_SOURCE
,
932 group
='base_libraries',
933 # FIXME: Ideally symbols should be hidden here so they
934 # don't appear in the global namespace when Samba
935 # libraries are loaded, but this doesn't appear to work
937 # hide_symbols=bld.BUILTIN_LIBRARY('replace'),
938 private_library
=True,
939 provide_builtin_linking
=True,
940 deps
='dl attr' + extra_libs
)
942 replace_test_cflags
= ''
943 if bld
.CONFIG_SET('HAVE_WNO_FORMAT_TRUNCATION'):
944 replace_test_cflags
+= " -Wno-format-truncation"
945 bld
.SAMBA_SUBSYSTEM('replace-test',
946 source
='''tests/testsuite.c tests/strptime.c
947 tests/os2_delete.c tests/getifaddrs.c''',
949 cflags
=replace_test_cflags
)
951 bld
.SAMBA_BINARY('replace_testsuite',
952 source
='tests/main.c',
953 deps
='replace replace-test',
956 # build replacements for stdint.h and stdbool.h if needed
957 bld
.SAMBA_GENERATOR('replace_stdint_h',
958 rule
='cp ${SRC} ${TGT}',
959 source
='hdr_replace.h',
961 enabled
= not bld
.CONFIG_SET('HAVE_STDINT_H'))
962 bld
.SAMBA_GENERATOR('replace_stdbool_h',
963 rule
='cp ${SRC} ${TGT}',
964 source
='hdr_replace.h',
966 enabled
= not bld
.CONFIG_SET('HAVE_STDBOOL_H'))
968 bld
.SAMBA_SUBSYSTEM('samba_intl', source
='', use_global_deps
=False,deps
=bld
.env
.intl_libs
)
971 '''run talloc testsuite'''
974 samba_utils
.ADD_LD_LIBRARY_PATH('bin/shared')
975 samba_utils
.ADD_LD_LIBRARY_PATH('bin/shared/private')
977 cmd
= os
.path
.join(Context
.g_module
.out
, 'replace_testsuite')
978 ret
= samba_utils
.RUN_COMMAND(cmd
)
979 print("testsuite returned %d" % ret
)
982 # WAF doesn't build the unit tests for this, maybe because they don't link with talloc?
985 Options
.commands
.append('build')
986 Options
.commands
.append('testonly')
989 '''makes a tarball for distribution'''