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