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('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('libaio.h 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 sys/fs/vx/quota.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('aio.h sys/unistd.h alloca.h float.h')
72 conf
.SET_TARGET_TYPE('tirpc', 'EMPTY')
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',
103 conf
.SET_TARGET_TYPE('nsl', 'SYSLIB')
104 conf
.CHECK_HEADERS('rpc/rpc.h rpcsvc/yp_prot.h', lib
='tirpc nsl')
106 conf
.SET_TARGET_TYPE('nsl', 'SYSLIB')
107 conf
.CHECK_HEADERS('rpcsvc/nis.h rpcsvc/ypclnt.h', lib
='tirpc nsl')
109 conf
.CHECK_HEADERS('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
133 #include <sys/prctl.h>
140 headers
='sys/prctl.h',
141 msg
='Checking for prctl syscall')
148 int main(void) { int fd = open("/dev/null", O_DIRECT); }
150 define
='HAVE_OPEN_O_DIRECT',
152 msg
='Checking for O_DIRECT flag to open(2)')
154 conf
.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
155 conf
.CHECK_TYPE('_Bool', define
='HAVE__Bool')
156 conf
.CHECK_TYPE('bool', define
='HAVE_BOOL')
158 conf
.CHECK_TYPE('int8_t', 'char')
159 conf
.CHECK_TYPE('uint8_t', 'unsigned char')
160 conf
.CHECK_TYPE('int16_t', 'short')
161 conf
.CHECK_TYPE('uint16_t', 'unsigned short')
162 conf
.CHECK_TYPE('int32_t', 'int')
163 conf
.CHECK_TYPE('uint32_t', 'unsigned')
164 conf
.CHECK_TYPE('int64_t', 'long long')
165 conf
.CHECK_TYPE('uint64_t', 'unsigned long long')
166 conf
.CHECK_TYPE('size_t', 'unsigned int')
167 conf
.CHECK_TYPE('ssize_t', 'int')
168 conf
.CHECK_TYPE('ino_t', 'unsigned')
169 conf
.CHECK_TYPE('loff_t', 'off_t')
170 conf
.CHECK_TYPE('offset_t', 'loff_t')
171 conf
.CHECK_TYPE('volatile int', define
='HAVE_VOLATILE')
172 conf
.CHECK_TYPE('uint_t', 'unsigned int')
173 conf
.CHECK_TYPE('blksize_t', 'long', headers
='sys/types.h sys/stat.h unistd.h')
174 conf
.CHECK_TYPE('blkcnt_t', 'long', headers
='sys/types.h sys/stat.h unistd.h')
176 conf
.CHECK_SIZEOF('bool char int "long long" long short size_t ssize_t')
177 conf
.CHECK_SIZEOF('int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t')
178 conf
.CHECK_SIZEOF('void*', define
='SIZEOF_VOID_P')
179 conf
.CHECK_SIZEOF('off_t dev_t ino_t time_t')
181 conf
.CHECK_TYPES('socklen_t', headers
='sys/socket.h')
182 conf
.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h')
183 conf
.CHECK_TYPE_IN('struct addrinfo', 'netdb.h')
184 conf
.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h')
185 conf
.CHECK_CODE('struct sockaddr_in6 x', define
='HAVE_STRUCT_SOCKADDR_IN6',
186 headers
='sys/socket.h netdb.h netinet/in.h')
187 conf
.CHECK_TYPE_IN('struct sockaddr_storage', 'sys/socket.h')
188 conf
.CHECK_TYPE_IN('sa_family_t', 'sys/socket.h')
190 conf
.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define
='HAVE_SIG_ATOMIC_T_TYPE')
191 conf
.CHECK_FUNCS('sigsetmask siggetmask sigprocmask sigblock sigaction sigset')
193 conf
.CHECK_FUNCS_IN('''inet_ntoa inet_aton inet_ntop inet_pton connect gethostbyname
194 getaddrinfo getnameinfo freeaddrinfo gai_strerror socketpair''',
195 'socket nsl', checklibc
=True,
196 headers
='sys/socket.h netinet/in.h arpa/inet.h netdb.h')
198 conf
.CHECK_FUNCS('memset_s memset_explicit')
205 char buf[] = "This is some content";
206 memset(buf, '\0', sizeof(buf)); __asm__ volatile("" : : "g"(&buf) : "memory");
210 define
='HAVE_GCC_VOLATILE_MEMORY_PROTECTION',
212 msg
='Checking for volatile memory protection',
215 # Some old Linux systems have broken header files and
216 # miss the IPV6_V6ONLY define in netinet/in.h,
217 # but have it in linux/in6.h.
218 # We can't include both files so we just check if the value
219 # if defined and do the replacement in system/network.h
220 if not conf
.CHECK_VARIABLE('IPV6_V6ONLY',
221 headers
='sys/socket.h netdb.h netinet/in.h'):
223 #include <linux/in6.h>
224 #if (IPV6_V6ONLY != 26)
225 #error no IPV6_V6ONLY support on linux
227 int main(void) { return IPV6_V6ONLY; }
229 define
='HAVE_LINUX_IPV6_V6ONLY_26',
231 msg
='Checking for IPV6_V6ONLY in linux/in6.h',
235 struct sockaddr_storage sa_store;
236 struct addrinfo *ai = NULL;
237 struct in6_addr in6addr;
238 int idx = if_nametoindex("iface1");
239 int s = socket(AF_INET6, SOCK_STREAM, 0);
240 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
242 const char *es = gai_strerror(ret);
247 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
248 #define IPV6_V6ONLY 26
250 ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
251 (const void *)&val, sizeof(val));
256 headers
='sys/socket.h netdb.h netinet/in.h net/if.h')
258 if conf
.CONFIG_SET('HAVE_SYS_UCONTEXT_H') and conf
.CONFIG_SET('HAVE_SIGNAL_H'):
261 sigaddset(&uc.uc_sigmask, SIGUSR1);
264 msg
="Checking whether we have ucontext_t",
265 headers
='signal.h sys/ucontext.h')
267 # Check for atomic builtins. */
270 (void)__sync_fetch_and_add(&i, 1);
272 'HAVE___SYNC_FETCH_AND_ADD',
273 msg
='Checking for __sync_fetch_and_add compiler builtin')
277 atomic_add_32(&i, 1);
279 'HAVE_ATOMIC_ADD_32',
280 headers
='stdint.h sys/atomic.h',
281 msg
='Checking for atomic_add_32 compiler builtin')
283 # Check for thread fence. */
284 tf
= conf
.CHECK_CODE('atomic_thread_fence(memory_order_seq_cst);',
285 'HAVE_ATOMIC_THREAD_FENCE',
286 headers
='stdatomic.h',
287 msg
='Checking for atomic_thread_fence(memory_order_seq_cst) in stdatomic.h')
289 tf
= conf
.CHECK_CODE('__atomic_thread_fence(__ATOMIC_SEQ_CST);',
290 'HAVE___ATOMIC_THREAD_FENCE',
291 msg
='Checking for __atomic_thread_fence(__ATOMIC_SEQ_CST)')
293 # __sync_synchronize() is available since 2005 in gcc.
294 tf
= conf
.CHECK_CODE('__sync_synchronize();',
295 'HAVE___SYNC_SYNCHRONIZE',
296 msg
='Checking for __sync_synchronize')
298 conf
.DEFINE('HAVE_ATOMIC_THREAD_FENCE_SUPPORT', 1)
301 #define FALL_THROUGH __attribute__((fallthrough))
309 enum direction_e key = UP;
331 'HAVE_FALLTHROUGH_ATTRIBUTE',
334 cflags
=['-Werror=missing-declarations'],
335 msg
='Checking for fallthrough attribute')
337 # these may be builtins, so we need the link=False strategy
338 conf
.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link
=False)
340 # See https://bugzilla.samba.org/show_bug.cgi?id=1097
342 # Ported in from autoconf where it was added with this commit:
343 # commit 804cfb20a067b4b687089dc72a8271b3abf20f31
344 # Author: Simo Sorce <idra@samba.org>
345 # Date: Wed Aug 25 14:24:16 2004 +0000
346 # r2070: Let's try to overload srnlen and strndup for AIX where they are natly broken.
348 host_os
= sys
.platform
349 if host_os
.rfind('aix') > -1:
350 conf
.DEFINE('BROKEN_STRNLEN', 1)
351 conf
.DEFINE('BROKEN_STRNDUP', 1)
353 conf
.CHECK_FUNCS('shl_load shl_unload shl_findsym')
354 conf
.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
355 conf
.CHECK_FUNCS('lstat getpgrp utime utimes setuid seteuid setreuid setresuid setgid setegid')
356 conf
.CHECK_FUNCS('setregid setresgid chroot strerror vsyslog setlinebuf mktime')
357 conf
.CHECK_FUNCS('ftruncate chsize rename waitpid wait4')
358 conf
.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr strsep')
359 conf
.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown')
360 conf
.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
361 conf
.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
362 conf
.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign')
364 if conf
.CONFIG_SET('HAVE_MEMALIGN'):
365 conf
.CHECK_DECLS('memalign', headers
='malloc.h')
367 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
368 if conf
.CHECK_CODE('''
369 #define _XOPEN_SOURCE 600
371 #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
372 #error probably broken posix_fallocate
375 '_POSIX_FALLOCATE_CAPABLE_LIBC',
376 msg
='Checking for posix_fallocate-capable libc'):
377 conf
.CHECK_FUNCS('posix_fallocate')
379 conf
.CHECK_FUNCS('prctl dirname basename')
381 strlcpy_in_bsd
= False
383 # libbsd on some platforms provides strlcpy and strlcat
384 if not conf
.CHECK_FUNCS('strlcpy strlcat'):
385 if conf
.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers
='bsd/string.h',
387 strlcpy_in_bsd
= True
388 if not conf
.CHECK_FUNCS('getpeereid'):
389 conf
.CHECK_FUNCS_IN('getpeereid', 'bsd', headers
='sys/types.h bsd/unistd.h')
390 if not conf
.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers
='setproctitle.h'):
391 conf
.CHECK_FUNCS_IN('setproctitle', 'bsd', headers
='sys/types.h bsd/unistd.h')
392 if not conf
.CHECK_FUNCS('setproctitle_init'):
393 conf
.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers
='sys/types.h bsd/unistd.h')
395 if not conf
.CHECK_FUNCS('closefrom'):
396 conf
.CHECK_FUNCS_IN('closefrom', 'bsd', headers
='bsd/unistd.h')
401 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
403 msg
="Checking whether we can use SO_PEERCRED to get socket credentials",
404 headers
='sys/types.h sys/socket.h')
406 #Some OS (ie. freebsd) return EINVAL if the convertion could not be done, it's not what we expect
407 #Let's detect those cases
408 if conf
.CONFIG_SET('HAVE_STRTOLL'):
410 long long nb = strtoll("Text", NULL, 0);
411 if (errno == EINVAL) {
417 msg
="Checking correct behavior of strtoll",
420 define
= 'HAVE_BSD_STRTOLL',
422 conf
.CHECK_FUNCS('if_nametoindex strerror_r')
423 conf
.CHECK_FUNCS('getdirentries getdents syslog')
424 conf
.CHECK_FUNCS('gai_strerror get_current_dir_name')
425 conf
.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups syscall setsid')
426 conf
.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
427 conf
.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
428 conf
.CHECK_FUNCS('port_create')
429 conf
.CHECK_FUNCS('getprogname')
431 conf
.SET_TARGET_TYPE('attr', 'EMPTY')
433 xattr_headers
='sys/attributes.h attr/xattr.h sys/xattr.h'
435 # default to 1, we set it to 0 if we don't find any EA implementation below:
436 conf
.DEFINE('HAVE_XATTR_SUPPORT', 1)
437 if conf
.CHECK_FUNCS_IN('getxattr', 'attr', checklibc
=True, headers
=xattr_headers
):
438 conf
.DEFINE('HAVE_XATTR_XATTR', 1)
439 # Darwin has extra options to xattr-family functions
440 conf
.CHECK_CODE('getxattr(NULL, NULL, NULL, 0, 0, 0)',
441 headers
=xattr_headers
, local_include
=False,
442 define
='XATTR_ADDITIONAL_OPTIONS',
443 msg
="Checking whether xattr interface takes additional options")
444 elif conf
.CHECK_FUNCS_IN('attr_listf', 'attr', checklibc
=True, headers
=xattr_headers
):
445 conf
.DEFINE('HAVE_XATTR_ATTR', 1)
446 elif conf
.CHECK_FUNCS('extattr_list_fd'):
447 conf
.DEFINE('HAVE_XATTR_EXTATTR', 1)
448 elif conf
.CHECK_FUNCS('flistea'):
449 conf
.DEFINE('HAVE_XATTR_EA', 1)
450 elif not conf
.CHECK_FUNCS('attropen'):
451 conf
.DEFINE('HAVE_XATTR_SUPPORT', 0)
454 conf
.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl',
455 checklibc
=True, headers
='dlfcn.h dl.h')
457 conf
.CHECK_C_PROTOTYPE('dlopen', 'void *dlopen(const char* filename, unsigned int flags)',
458 define
='DLOPEN_TAKES_UNSIGNED_FLAGS', headers
='dlfcn.h dl.h')
460 if conf
.CHECK_FUNCS_IN('fdatasync', 'rt', checklibc
=True):
461 # some systems are missing the declaration
462 conf
.CHECK_DECLS('fdatasync')
464 if conf
.CHECK_FUNCS_IN('clock_gettime', 'rt', checklibc
=True):
465 for c
in ['CLOCK_MONOTONIC', 'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME']:
467 #if TIME_WITH_SYS_TIME
468 # include <sys/time.h>
472 # include <sys/time.h>
477 clockid_t clk = %s''' % c
,
479 msg
='Checking whether the clock_gettime clock ID %s is available' % c
)
481 conf
.CHECK_TYPE('struct timespec', headers
='sys/time.h time.h')
483 # these headers need to be tested as a group on freebsd
484 conf
.CHECK_HEADERS(headers
='sys/socket.h net/if.h', together
=True)
485 conf
.CHECK_HEADERS(headers
='netinet/in.h arpa/nameser.h resolv.h', together
=True)
486 conf
.CHECK_FUNCS_IN('res_search', 'resolv', checklibc
=True,
487 headers
='netinet/in.h arpa/nameser.h resolv.h')
490 # try to find libintl (if --without-gettext is not given)
491 conf
.env
.intl_libs
=''
492 if not Options
.options
.disable_gettext
:
493 conf
.CHECK_HEADERS('libintl.h')
494 conf
.CHECK_LIB('intl')
495 conf
.CHECK_DECLS('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset', headers
="libintl.h")
496 # *textdomain functions are not strictly necessary
497 conf
.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset',
498 '', checklibc
=True, headers
='libintl.h')
499 # gettext and dgettext must exist
500 # on some systems (the ones with glibc, those are in libc)
501 if conf
.CHECK_FUNCS_IN('dgettext gettext', '', checklibc
=True, headers
='libintl.h'):
502 # save for dependency definitions
503 conf
.env
.intl_libs
=''
504 # others (e.g. FreeBSD) have separate libintl
505 elif conf
.CHECK_FUNCS_IN('dgettext gettext', 'intl', checklibc
=False, headers
='libintl.h'):
506 # save for dependency definitions
507 conf
.env
.intl_libs
='intl'
508 # recheck with libintl
509 conf
.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset',
510 'intl', checklibc
=False, headers
='libintl.h')
512 # Some hosts need lib iconv for linking with lib intl
513 # So we try with flags just in case it helps.
514 oldflags
= list(conf
.env
['EXTRA_LDFLAGS']);
515 conf
.env
['EXTRA_LDFLAGS'].extend(["-liconv"])
516 conf
.CHECK_FUNCS_IN('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset',
517 'intl', checklibc
=False, headers
='libintl.h')
518 conf
.env
['EXTRA_LDFLAGS'] = oldflags
519 if conf
.env
['HAVE_GETTEXT'] and conf
.env
['HAVE_DGETTEXT']:
520 # save for dependency definitions
521 conf
.env
.intl_libs
='iconv intl'
523 # did we find both prototypes and a library to link against?
524 # if not, unset the detected values (see Bug #9911)
525 if not (conf
.env
['HAVE_GETTEXT'] and conf
.env
['HAVE_DECL_GETTEXT']):
526 conf
.undefine('HAVE_GETTEXT')
527 conf
.undefine('HAVE_DECL_GETTEXT')
528 if not (conf
.env
['HAVE_DGETTEXT'] and conf
.env
['HAVE_DECL_DGETTEXT']):
529 conf
.undefine('HAVE_DGETTEXT')
530 conf
.undefine('HAVE_DECL_DGETTEXT')
532 conf
.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc
=True, headers
='pthread.h')
534 PTHREAD_CFLAGS
='error'
535 PTHREAD_LDFLAGS
='error'
537 if PTHREAD_LDFLAGS
== 'error':
538 if conf
.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
539 PTHREAD_CFLAGS
='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
540 PTHREAD_LDFLAGS
='-lpthread'
541 if PTHREAD_LDFLAGS
== 'error':
542 if conf
.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
543 PTHREAD_CFLAGS
='-D_THREAD_SAFE'
544 PTHREAD_LDFLAGS
='-lpthreads'
545 if PTHREAD_LDFLAGS
== 'error':
546 if conf
.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
547 PTHREAD_CFLAGS
='-D_THREAD_SAFE -pthread'
548 PTHREAD_LDFLAGS
='-pthread'
549 if PTHREAD_LDFLAGS
== 'error':
550 if conf
.CHECK_FUNCS('pthread_attr_init'):
551 PTHREAD_CFLAGS
='-D_REENTRANT'
552 PTHREAD_LDFLAGS
='-lpthread'
553 # especially for HP-UX, where the CHECK_FUNC macro fails to test for
554 # pthread_attr_init. On pthread_mutex_lock it works there...
555 if PTHREAD_LDFLAGS
== 'error':
556 if conf
.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
557 PTHREAD_CFLAGS
='-D_REENTRANT'
558 PTHREAD_LDFLAGS
='-lpthread'
560 if PTHREAD_CFLAGS
!= 'error' and PTHREAD_LDFLAGS
!= 'error':
561 if conf
.CONFIG_SET('replace_add_global_pthread'):
562 conf
.ADD_CFLAGS(PTHREAD_CFLAGS
)
563 conf
.ADD_LDFLAGS(PTHREAD_LDFLAGS
)
564 conf
.CHECK_HEADERS('pthread.h')
565 conf
.DEFINE('HAVE_PTHREAD', '1')
567 if conf
.CONFIG_SET('HAVE_PTHREAD'):
569 conf
.CHECK_FUNCS_IN('pthread_mutexattr_setrobust', 'pthread',
570 checklibc
=True, headers
='pthread.h')
571 if not conf
.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST'):
572 conf
.CHECK_FUNCS_IN('pthread_mutexattr_setrobust_np', 'pthread',
573 checklibc
=True, headers
='pthread.h')
575 conf
.CHECK_DECLS('PTHREAD_MUTEX_ROBUST', headers
='pthread.h')
576 if not conf
.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST'):
577 conf
.CHECK_DECLS('PTHREAD_MUTEX_ROBUST_NP', headers
='pthread.h')
579 conf
.CHECK_FUNCS_IN('pthread_mutex_consistent', 'pthread',
580 checklibc
=True, headers
='pthread.h')
581 if not conf
.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT'):
582 conf
.CHECK_FUNCS_IN('pthread_mutex_consistent_np', 'pthread',
583 checklibc
=True, headers
='pthread.h')
585 if ((conf
.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST') or
586 conf
.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP')) and
587 (conf
.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST') or
588 conf
.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST_NP')) and
589 (conf
.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT') or
590 conf
.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT_NP'))):
591 conf
.DEFINE('HAVE_ROBUST_MUTEXES', 1)
593 # __thread is available since 2002 in gcc.
603 msg
='Checking for __thread local storage')
605 conf
.CHECK_FUNCS_IN('crypt', 'crypt', checklibc
=True)
606 conf
.CHECK_FUNCS_IN('crypt_r', 'crypt', checklibc
=True)
608 conf
.CHECK_VARIABLE('rl_event_hook', define
='HAVE_DECL_RL_EVENT_HOOK', always
=True,
609 headers
='readline.h readline/readline.h readline/history.h')
610 conf
.CHECK_VARIABLE('program_invocation_short_name', headers
='errno.h')
612 conf
.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf')
614 conf
.CHECK_DECLS('errno', headers
='errno.h', reverse
=True)
615 conf
.CHECK_DECLS('EWOULDBLOCK', headers
='errno.h')
616 conf
.CHECK_DECLS('environ', reverse
=True, headers
='unistd.h')
617 conf
.CHECK_DECLS('getgrent_r getpwent_r', reverse
=True, headers
='pwd.h grp.h')
618 conf
.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse
=True)
620 if conf
.CONFIG_SET('HAVE_EPOLL_CREATE') and conf
.CONFIG_SET('HAVE_SYS_EPOLL_H'):
621 conf
.DEFINE('HAVE_EPOLL', 1)
623 if conf
.CONFIG_SET('HAVE_PORT_CREATE') and conf
.CONFIG_SET('HAVE_PORT_H'):
624 conf
.DEFINE('HAVE_SOLARIS_PORTS', 1)
626 if conf
.CHECK_FUNCS('eventfd', headers
='sys/eventfd.h'):
627 conf
.DEFINE('HAVE_EVENTFD', 1)
629 conf
.CHECK_HEADERS('poll.h')
630 conf
.CHECK_FUNCS('poll')
632 conf
.CHECK_FUNCS('strptime')
633 conf
.CHECK_DECLS('strptime', headers
='time.h')
634 conf
.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME
635 #include "test/strptime.c"''',
636 define
='HAVE_WORKING_STRPTIME',
639 msg
='Checking for working strptime')
641 conf
.CHECK_C_PROTOTYPE('gettimeofday',
642 'int gettimeofday(struct timeval *tv, struct timezone *tz)',
643 define
='HAVE_GETTIMEOFDAY_TZ', headers
='sys/time.h')
645 conf
.CHECK_C_PROTOTYPE('gettimeofday',
646 'int gettimeofday(struct timeval *tv, void *tz)',
647 define
='HAVE_GETTIMEOFDAY_TZ_VOID',
648 headers
='sys/time.h')
650 conf
.CHECK_CODE('#include "test/snprintf.c"',
651 define
="HAVE_C99_VSNPRINTF",
654 msg
="Checking for C99 vsnprintf")
656 conf
.CHECK_CODE('#include "test/shared_mmap.c"',
657 addmain
=False, add_headers
=False, execute
=True,
658 define
='HAVE_SHARED_MMAP',
659 msg
="Checking for HAVE_SHARED_MMAP")
661 conf
.CHECK_CODE('#include "test/shared_mremap.c"',
662 addmain
=False, add_headers
=False, execute
=True,
663 define
='HAVE_MREMAP',
664 msg
="Checking for HAVE_MREMAP")
666 # OpenBSD (and I've heard HPUX) doesn't sync between mmap and write.
667 # FIXME: Anything other than a 0 or 1 exit code should abort configure!
668 conf
.CHECK_CODE('#include "test/incoherent_mmap.c"',
669 addmain
=False, add_headers
=False, execute
=True,
670 define
='HAVE_INCOHERENT_MMAP',
671 msg
="Checking for HAVE_INCOHERENT_MMAP")
673 conf
.SAMBA_BUILD_ENV()
676 typedef struct {unsigned x;} FOOBAR;
677 #define X_FOOBAR(x) ((FOOBAR) { x })
678 #define FOO_ONE X_FOOBAR(1)
680 static const struct {
685 static const FOOBAR f3[] = {FOO_ONE};
687 define
='HAVE_IMMEDIATE_STRUCTURES')
689 conf
.CHECK_CODE('mkdir("foo",0777)', define
='HAVE_MKDIR_MODE', headers
='sys/stat.h')
691 conf
.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec', define
='HAVE_STAT_TV_NSEC',
692 headers
='sys/stat.h')
693 # we need the st_rdev test under two names
694 conf
.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev',
695 define
='HAVE_STRUCT_STAT_ST_RDEV',
696 headers
='sys/stat.h')
697 conf
.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define
='HAVE_ST_RDEV',
698 headers
='sys/stat.h')
699 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family',
700 headers
='sys/socket.h netinet/in.h')
701 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', '__ss_family',
702 headers
='sys/socket.h netinet/in.h')
705 if conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr', 'sa_len',
706 headers
='sys/socket.h netinet/in.h',
707 define
='HAVE_SOCKADDR_SA_LEN'):
708 # the old build system produced both defines
709 conf
.DEFINE('HAVE_STRUCT_SOCKADDR_SA_LEN', 1)
711 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_in', 'sin_len',
712 headers
='sys/socket.h netinet/in.h',
713 define
='HAVE_SOCK_SIN_LEN')
715 conf
.CHECK_STRUCTURE_MEMBER('struct sockaddr_in6', 'sin6_len',
716 headers
='sys/socket.h netinet/in.h',
717 define
='HAVE_SOCK_SIN6_LEN')
719 conf
.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;',
720 define
='HAVE_UNIXSOCKET', headers
='sys/socket.h sys/un.h')
725 char tpl[20]="/tmp/test.XXXXXX";
726 char tpl2[20]="/tmp/test.XXXXXX";
727 int fd = mkstemp(tpl);
728 int fd2 = mkstemp(tpl2);
735 if (fd2 == -1) exit(1);
738 if (fstat(fd, &st) != 0) exit(1);
739 if ((st.st_mode & 0777) != 0600) exit(1);
740 if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
743 if (strcmp(tpl, tpl2) == 0) {
748 define
='HAVE_SECURE_MKSTEMP',
750 mandatory
=True) # lets see if we get a mandatory failure for this one
752 # look for a method of finding the list of network interfaces
753 for method
in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
756 bsd_for_strlcpy
= ' bsd'
757 if conf
.CHECK_CODE('''
759 #define NO_CONFIG_H 1
760 #define AUTOCONF_TEST 1
762 #include "inet_ntop.c"
763 #include "snprintf.c"
764 #include "getifaddrs.c"
765 #define getifaddrs_test main
766 #include "test/getifaddrs.c"
769 lib
='nsl socket' + bsd_for_strlcpy
,
774 conf
.RECURSE('system')
775 conf
.SAMBA_CONFIG_H()
776 if conf
.CHECK_FUNCS('strerror_r'):
777 # Check if strerror_r is XSI-Compatable, the default GNU implementation
779 conf
.CHECK_CODE('int strerror_r(int errnum, char *buf, size_t buflen);',
780 'STRERROR_R_XSI_NOT_GNU',
781 headers
='string.h', addmain
=False, link
=False,
782 msg
="Checking for XSI (rather than GNU) prototype for strerror_r")
785 REPLACEMENT_FUNCTIONS
= {
786 'replace.c': ['ftruncate', 'strlcpy', 'strlcat', 'mktime', 'initgroups',
787 'memmove', 'strdup', 'setlinebuf', 'vsyslog', 'strnlen',
788 'strndup', 'waitpid', 'seteuid', 'setegid', 'chroot',
789 'mkstemp', 'mkdtemp', 'pread', 'pwrite', 'strcasestr',
790 'strsep', 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv',
791 'utime', 'utimes', 'dup2', 'chown', 'link', 'readlink',
792 'symlink', 'lchown', 'realpath', 'memmem', 'vdprintf',
793 'dprintf', 'get_current_dir_name',
794 'strerror_r', 'clock_gettime'],
795 'timegm.c': ['timegm'],
796 # Note: C99_VSNPRINTF is not a function, but a special condition
798 'snprintf.c': ['C99_VSNPRINTF', 'snprintf', 'vsnprintf', 'asprintf', 'vasprintf'],
799 # Note: WORKING_STRPTIME is not a function, but a special condition
801 'strptime.c': ['WORKING_STRPTIME', 'strptime'],
806 bld
.RECURSE('buildtools/wafsamba')
808 REPLACE_HOSTCC_SOURCE
= ''
810 for filename
in REPLACEMENT_FUNCTIONS
.keys():
811 for function
in REPLACEMENT_FUNCTIONS
[filename
]:
812 if not bld
.CONFIG_SET('HAVE_%s' % function
.upper()):
813 REPLACE_HOSTCC_SOURCE
+= ' %s' % filename
817 if bld
.CONFIG_SET('HAVE_LIBBSD'): extra_libs
+= ' bsd'
819 bld
.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC',
820 REPLACE_HOSTCC_SOURCE
,
822 use_global_deps
=False,
823 cflags
='-D_SAMBA_HOSTCC_',
824 group
='compiler_libraries',
828 REPLACE_SOURCE
= REPLACE_HOSTCC_SOURCE
829 REPLACE_SOURCE
+= ' cwrap.c'
831 if not bld
.CONFIG_SET('HAVE_CRYPT'): REPLACE_SOURCE
+= ' crypt.c'
832 if not bld
.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE
+= ' dlfcn.c'
833 if not bld
.CONFIG_SET('HAVE_POLL'): REPLACE_SOURCE
+= ' poll.c'
835 if not bld
.CONFIG_SET('HAVE_SOCKETPAIR'): REPLACE_SOURCE
+= ' socketpair.c'
836 if not bld
.CONFIG_SET('HAVE_CONNECT'): REPLACE_SOURCE
+= ' socket.c'
837 if not bld
.CONFIG_SET('HAVE_GETIFADDRS'): REPLACE_SOURCE
+= ' getifaddrs.c'
838 if not bld
.CONFIG_SET('HAVE_GETADDRINFO'): REPLACE_SOURCE
+= ' getaddrinfo.c'
839 if not bld
.CONFIG_SET('HAVE_INET_NTOA'): REPLACE_SOURCE
+= ' inet_ntoa.c'
840 if not bld
.CONFIG_SET('HAVE_INET_ATON'): REPLACE_SOURCE
+= ' inet_aton.c'
841 if not bld
.CONFIG_SET('HAVE_INET_NTOP'): REPLACE_SOURCE
+= ' inet_ntop.c'
842 if not bld
.CONFIG_SET('HAVE_INET_PTON'): REPLACE_SOURCE
+= ' inet_pton.c'
843 if not bld
.CONFIG_SET('HAVE_GETXATTR') or bld
.CONFIG_SET('XATTR_ADDITIONAL_OPTIONS'):
844 REPLACE_SOURCE
+= ' xattr.c'
846 if not bld
.CONFIG_SET('HAVE_CLOSEFROM'):
847 REPLACE_SOURCE
+= ' closefrom.c'
849 bld
.SAMBA_LIBRARY('replace',
850 source
=REPLACE_SOURCE
,
851 group
='base_libraries',
852 # FIXME: Ideally symbols should be hidden here so they
853 # don't appear in the global namespace when Samba
854 # libraries are loaded, but this doesn't appear to work
856 # hide_symbols=bld.BUILTIN_LIBRARY('replace'),
857 private_library
=True,
858 deps
='crypt dl nsl socket rt attr' + extra_libs
)
860 replace_test_cflags
="-Wno-format-zero-length"
861 if bld
.CONFIG_SET('HAVE_WNO_FORMAT_TRUNCATION'):
862 replace_test_cflags
+= " -Wno-format-truncation"
863 bld
.SAMBA_SUBSYSTEM('replace-test',
864 source
='''test/testsuite.c test/strptime.c
865 test/os2_delete.c test/getifaddrs.c''',
867 cflags
=replace_test_cflags
)
869 if bld
.env
.standalone_replace
:
870 bld
.SAMBA_BINARY('replace_testsuite',
871 source
='test/main.c',
872 deps
='replace replace-test',
875 # build replacements for stdint.h and stdbool.h if needed
876 bld
.SAMBA_GENERATOR('replace_stdint_h',
877 rule
='cp ${SRC} ${TGT}',
878 source
='hdr_replace.h',
880 enabled
= not bld
.CONFIG_SET('HAVE_STDINT_H'))
881 bld
.SAMBA_GENERATOR('replace_stdbool_h',
882 rule
='cp ${SRC} ${TGT}',
883 source
='hdr_replace.h',
885 enabled
= not bld
.CONFIG_SET('HAVE_STDBOOL_H'))
887 bld
.SAMBA_SUBSYSTEM('samba_intl', source
='', use_global_deps
=False,deps
=bld
.env
.intl_libs
)
890 '''makes a tarball for distribution'''