Move back to using per-thread credentials on Linux. Fixes the glibc native AIO lost...
[samba.git] / source3 / wscript
1 #! /usr/bin/env python
2
3 srcdir=".."
4
5 import sys, os
6 from optparse import SUPPRESS_HELP
7 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
8 sys.path.insert(0, "source3")
9 import wafsamba, Options, Logs, Utils, Scripting
10 import build.charset
11 import samba_utils, samba_version
12 import samba3
13
14 Options.default_prefix = '/usr/local/samba'
15
16 def set_options(opt):
17
18     opt.add_option('--with-static-modules',
19                    help=("Comma-separated list of names of modules to statically link in"),
20                    action="store", dest='static_modules', default=None)
21     opt.add_option('--with-shared-modules',
22                    help=("Comma-separated list of names of modules to build shared"),
23                    action="store", dest='shared_modules', default=None)
24     opt.add_option('--enable-selftest',
25                   help=("enable options necessary for selftest"),
26                   action="store_true", dest='enable_selftest', default=False)
27
28     opt.SAMBA3_ADD_OPTION('winbind')
29     opt.SAMBA3_ADD_OPTION('swat')
30     opt.SAMBA3_ADD_OPTION('ads')
31     opt.SAMBA3_ADD_OPTION('ldap')
32     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
33     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
34     opt.SAMBA3_ADD_OPTION('pam')
35     opt.SAMBA3_ADD_OPTION('pam_smbpass')
36     opt.SAMBA3_ADD_OPTION('quotas')
37     opt.SAMBA3_ADD_OPTION('sys-quotas')
38     opt.SAMBA3_ADD_OPTION('sendfile-support')
39     opt.SAMBA3_ADD_OPTION('utmp')
40     opt.SAMBA3_ADD_OPTION('pthreadpool', with_name="enable", without_name="disable")
41     opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
42     opt.SAMBA3_ADD_OPTION('iconv')
43     opt.SAMBA3_ADD_OPTION('acl-support')
44     opt.SAMBA3_ADD_OPTION('dnsupdate')
45     opt.SAMBA3_ADD_OPTION('syslog')
46     opt.SAMBA3_ADD_OPTION('automount')
47     opt.SAMBA3_ADD_OPTION('aio-support')
48     opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
49
50     opt.SAMBA3_ADD_OPTION('cluster-support')
51
52     opt.add_option('--with-ctdb-dir',
53                    help=("Directory under which ctdb is installed"),
54                    action="store", dest='ctdb_dir', default=None)
55     opt.add_option('--enable-old-ctdb',
56                   help=("enable building against (too) old version of ctdb (default=false)"),
57                   action="store_true", dest='enable_old_ctdb', default=False)
58
59
60
61 def configure(conf):
62     from samba_utils import TO_LIST
63
64     if Options.options.developer:
65         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
66         conf.env.developer = True
67
68     if Options.options.with_swat:
69         conf.env['build_swat'] = True
70
71     if sys.platform != 'openbsd5':
72         conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
73
74     conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
75     conf.CHECK_HEADERS('linux/falloc.h')
76
77     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod')
78     conf.CHECK_FUNCS('strtol strchr strupr chflags')
79     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
80     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
81     conf.CHECK_FUNCS('sigprocmask sigblock sigaction sigset innetgr')
82     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
83     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups syscall sysconf')
84     conf.CHECK_FUNCS('atexit grantpt fallocate posix_fallocate')
85     conf.CHECK_FUNCS('fseeko setluid')
86     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
87     conf.CHECK_FUNCS('fdopendir')
88     conf.CHECK_FUNCS('getpwent_r setenv strcasecmp fcvt fcvtl')
89     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
90     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
91     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
92     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
93     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
94     conf.CHECK_FUNCS('shmget')
95     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
96     conf.CHECK_FUNCS('gettext dgettext bindtextdomain textdomain bind_textdomain_codeset')
97     #FIXME: for some reason this one still fails
98     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
99     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
100     conf.CHECK_DECLS('fdatasync', reverse=True)
101     conf.CHECK_DECLS('readahead', reverse=True, headers='fcntl.h')
102
103     if conf.CONFIG_SET('HAVE_LONG_LONG'):
104         conf.DEFINE('HAVE_LONGLONG', 1)
105
106     if conf.CHECK_CODE('''
107 #if defined(HAVE_UNISTD_H)
108 #include <unistd.h>
109 #endif
110 long ret = splice(0,0,1,0,400,SPLICE_F_MOVE);
111 ''',
112         'HAVE_LINUX_SPLICE',
113         headers='fcntl.h'):
114         conf.CHECK_DECLS('splice', reverse=True, headers='fcntl.h')
115
116     # Check for inotify support
117     conf.CHECK_HEADERS('sys/inotify.h')
118     if "HAVE_SYS_INOTIFY_H" in conf.env:
119         conf.DEFINE('HAVE_INOTIFY', 1)
120
121     # Check for kernel change notify support
122     conf.CHECK_CODE('''
123 #ifndef F_NOTIFY
124 #define F_NOTIFY 1026
125 #endif
126 main() {
127         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
128 }''', 'HAVE_KERNEL_CHANGE_NOTIFY', addmain=False, execute=True,
129         headers='fcntl.h signal.h',
130         msg="Checking for kernel change notify support")
131
132     # Check for Linux kernel oplocks
133     conf.CHECK_CODE('''
134 #include <sys/types.h>
135 #include <fcntl.h>
136 #include <signal.h>
137 #ifndef F_NOTIFY
138 #define F_NOTIFY 1026
139 #endif
140 main() {
141         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
142 }''', 'HAVE_KERNEL_OPLOCKS_LINUX', addmain=False, execute=True,
143         msg="Checking for Linux kernel oplocks")
144
145     # Check for IRIX kernel oplock types
146     conf.CHECK_CODE('oplock_stat_t t; t.os_state = OP_REVOKE; t.os_dev = 1; t.os_ino = 1;',
147                     'HAVE_KERNEL_OPLOCKS_IRIX', headers='fcntl.h',
148                     msg="Checking for IRIX kernel oplock types")
149
150     # Check for kernel share modes
151     conf.CHECK_CODE('''
152 #include <sys/types.h>
153 #include <fcntl.h>
154 #include <signal.h>
155 #include <sys/file.h>
156 #ifndef LOCK_MAND
157 #define LOCK_MAND        32
158 #define LOCK_READ        64
159 #endif
160 main() {
161         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
162 }''', 'HAVE_KERNEL_SHARE_MODES', addmain=False, execute=True,
163         msg="Checking for krenel share modes")
164
165     # Check for various members of the stat structure
166     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
167                                 headers='sys/stat.h')
168     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blksize', define='HAVE_STAT_ST_BLKSIZE',
169                                 headers='sys/stat.h')
170     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_flags', define='HAVE_STAT_ST_FLAGS',
171                                 headers='sys/types.h sys/stat.h unistd.h')
172
173     if "HAVE_BLKCNT_T" in conf.env:
174         conf.CHECK_CODE('''
175         return sizeof(blkcnt_t) == 4 ? 0 : 1''',
176                 'SIZEOF_BLKCNT_T_4', execute=True,
177                 headers='replace.h sys/types.h sys/stat.h unistd.h',
178                 msg="Checking whether blkcnt_t is 32 bit")
179
180     if "HAVE_BLKCNT_T" in conf.env:
181         conf.CHECK_CODE('''
182         return sizeof(blkcnt_t) == 8 ? 0 : 1''',
183                 'SIZEOF_BLKCNT_T_8', execute=True,
184                 headers='replace.h sys/types.h sys/stat.h unistd.h',
185                 msg="Checking whether blkcnt_t is 64 bit")
186
187     # Check for POSIX capability support
188     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
189
190     if "HAVE_SYS_CAPABILITY_H" in conf.env:
191         conf.CHECK_CODE('''
192         cap_t cap;
193         cap_value_t vals[1];
194         if (!(cap = cap_get_proc())) exit(1);
195         vals[0] = CAP_CHOWN;
196         cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
197         cap_set_proc(cap);''',
198                         'HAVE_POSIX_CAPABILITIES', execute=True, lib="cap",
199                         headers='sys/capability.h',
200                         msg="Checking whether POSIX capabilities are available")
201
202     # Check for int16, uint16, int32 and uint32 in rpc/types.h included from
203     # rpc/rpc.h. This is *really* broken but some systems (DEC OSF1) do this.
204     # -- JRA.
205     if conf.CONFIG_SET("HAVE_RPC_RPC_H"):
206         conf.CHECK_TYPE('int16', headers='rpc/rpc.h',
207                         define='HAVE_INT16_FROM_RPC_RPC_H',
208                         msg="Checking for int16 typedef included by rpc/rpc.h")
209         conf.CHECK_CODE('uint16 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
210                         headers='sys/types.h rpc/rpc.h',
211                         msg="Checking for uint16 typedef included by rpc/rpc.h")
212         conf.CHECK_CODE('int32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
213                         headers='sys/types.h rpc/rpc.h',
214                         msg="Checking for int32 typedef included by rpc/rpc.h")
215         conf.CHECK_CODE('uint32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
216                         headers='sys/types.h rpc/rpc.h',
217                         msg="Checking for uint32 typedef included by rpc/rpc.h")
218     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
219                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
220                     msg="Checking for broken nisplus include files")
221
222     # Check if the compiler will optimize out functions
223     conf.CHECK_CODE('''
224 if (0) {
225     this_function_does_not_exist();
226 } else {
227     return 1;
228 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
229         msg="Checking if the compiler will optimize out functions")
230
231     # Check if the compiler supports the LL suffix on long long integers
232     # AIX needs this
233     conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
234                     headers='stdio.h',
235                     msg="Checking for LL suffix on long long integers")
236
237     conf.CHECK_FUNCS('''
238 _acl __acl atexit 
239 bindtextdomain _chdir __chdir chflags chmod _close __close _closedir
240 __closedir crypt16 devnm dgettext dirfd
241 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
242 _facl __facl _fchdir
243 __fchdir fchmod fchown _fcntl __fcntl fcvt fcvtl fdatasync
244 _fork __fork fseeko
245 fsetxattr _fstat __fstat fsync
246 futimens futimes __fxstat getauthuid
247 getcwd _getcwd __getcwd getdents __getdents getdirentries
248 getgrent getgrnam getgrouplist getgrset getmntent getpagesize
249 getpwanam getpwent_r getrlimit gettext
250 glob grantpt hstrerror initgroups innetgr
251 llseek _llseek __llseek _lseek __lseek
252 _lstat __lstat lutimes
253 __lxstat memalign mknod mlock mlockall munlock munlockall
254 _open __open _opendir __opendir
255 pathconf poll posix_fallocate
256 posix_memalign prctl pread _pread __pread
257 pwrite _pwrite __pwrite
258 rdchk _read __read _readdir __readdir
259 _seekdir __seekdir
260 select setenv setgidx setgroups setlocale setluid
261 setmntent setpgid setpriv setsid setuidx
262 shmget shm_open sigaction sigblock sigprocmask sigset
263 _stat __stat statvfs
264 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctl sysctlbyname
265 __sys_llseek syslog _telldir __telldir textdomain timegm
266 utimensat vsyslog _write __write __xstat
267 ''')
268
269     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
270
271     # FIXME: these should be tests for features, but the old build system just
272     # checks for OSes.
273     host_os = sys.platform
274     Logs.info("building on %s" % host_os)
275
276     # Python doesn't have case switches... :/
277     # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
278     # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
279
280     conf.SET_TARGET_TYPE('sunacl', 'EMPTY')
281     if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
282         if host_os.rfind('linux') > -1:
283             conf.DEFINE('LINUX', '1')
284         elif host_os.rfind('qnx') > -1:
285             conf.DEFINE('QNX', '1')
286         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
287     elif (host_os.rfind('darwin') > -1):
288         conf.DEFINE('DARWINOS', 1)
289         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
290         conf.ADD_CFLAGS('-fno-common')
291     elif (host_os.rfind('freebsd') > -1):
292         if conf.CHECK_HEADERS('sunacl.h'):
293             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
294             conf.CHECK_FUNCS_IN('acl', 'sunacl')
295         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
296     elif (host_os.rfind('netbsd') > -1):
297         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
298     elif (host_os.rfind('openbsd') > -1):
299         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
300     elif (host_os.rfind('sunos') > -1):
301         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
302     # FIXME: Add more checks here.
303     else:
304         Logs.warn("Unknown host_os '%s', please report this to samba-technical@samba.org" % host_os)
305
306     #FIXME: add more checks
307     if Options.options.with_acl_support:
308         if (host_os.rfind('darwin') > -1):
309             conf.DEFINE('HAVE_NO_ACLS', 1)
310             conf.SET_TARGET_TYPE('acl', 'EMPTY')
311         else:
312             conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
313             if conf.CHECK_CODE('''
314 acl_t acl;
315 int entry_id;
316 acl_entry_t *entry_p;
317 return acl_get_entry(acl, entry_id, entry_p);
318 ''',
319                         'HAVE_POSIX_ACLS',
320                         headers='sys/types.h sys/acl.h', link=False,
321                         msg="Checking for POSIX ACL support") :
322                 conf.CHECK_CODE('''
323 acl_permset_t permset_d;
324 acl_perm_t perm;
325 return acl_get_perm_np(permset_d, perm);
326 ''',
327                         'HAVE_ACL_GET_PERM_NP',
328                         headers='sys/types.h sys/acl.h', link=True,
329                         msg="Checking whether acl_get_perm_np() is available")
330     else:
331         conf.DEFINE('HAVE_NO_ACLS', 1)
332         conf.SET_TARGET_TYPE('acl', 'EMPTY')
333
334     if conf.CHECK_FUNCS('dirfd'):
335         conf.DEFINE('HAVE_DIRFD_DECL', 1)
336
337     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
338                     'HAVE_STATFS_F_FSID',
339                     msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
340                     headers='sys/types.h sys/statfs.h',
341                     execute=True)
342
343     if conf.CONFIG_SET('HAVE_FALLOCATE'):
344         conf.CHECK_CODE('''
345                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
346                 'HAVE_LINUX_FALLOCATE',
347                 msg="Checking whether the Linux 'fallocate' function is available",
348                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
349     conf.CHECK_CODE('''
350                 ssize_t err = readahead(0,0,0x80000);''',
351                 'HAVE_LINUX_READAHEAD',
352                 msg="Checking whether Linux readahead is available",
353                 headers='unistd.h fcntl.h')
354     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
355
356     if Options.options.with_aio_support:
357         conf.CHECK_FUNCS_IN('aio_read', 'aio')
358         conf.CHECK_FUNCS_IN('aio_read', 'rt')
359         conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
360                         'HAVE_AIO',
361                         msg='Checking for asynchronous io support',
362                         headers='sys/types.h aio.h',
363                         lib='aio rt')
364         if conf.CONFIG_SET('HAVE_AIO'):
365             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
366             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
367             conf.CHECK_CODE('struct aiocb a; return aio_fsync(1, &a);', 'HAVE_AIO_FSYNC', msg='Checking for aio_fsync', headers='aio.h', lib='aio rt')
368             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
369             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
370             conf.CHECK_CODE('struct aiocb a; return aio_cancel(1, &a);', 'HAVE_AIO_CANCEL', msg='Checking for aio_cancel', headers='aio.h', lib='aio rt')
371             conf.CHECK_CODE('struct aiocb a; return aio_suspend(&a, 1, NULL);', 'HAVE_AIO_SUSPEND', msg='Checking for aio_suspend', headers='aio.h', lib='aio rt')
372             if host_os.rfind('linux') > -1:
373                 conf.CHECK_FUNCS_IN('io_submit', 'aio')
374                 conf.CHECK_CODE('''
375 struct io_event ioev;
376 struct iocb *ioc;
377 io_context_t ctx;
378 struct timespec ts;
379 int fd;
380 char *buf;
381 fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
382 io_queue_init(128,&ctx);
383 io_prep_pwrite(ioc, 1, buf, 1, 0);
384 io_prep_pread(ioc, 1, buf, 1, 0);
385 io_set_eventfd(ioc, fd);
386 io_set_callback(ioc, (io_callback_t)(0));
387 io_submit(ctx, 1, &ioc);
388 io_getevents(ctx, 1, 1, &ioev, &ts);
389 ''',
390                         'HAVE_LINUX_KERNEL_AIO',
391                         msg='Checking for linux kernel asynchronous io support',
392                         headers='unistd.h stdlib.h sys/types.h fcntl.h sys/eventfd.h libaio.h',
393                         lib='aio')
394
395         if not conf.CONFIG_SET('HAVE_AIO'):
396             conf.DEFINE('HAVE_NO_AIO', '1')
397     else:
398         conf.DEFINE('HAVE_NO_AIO', '1')
399
400     conf.CHECK_CODE('''
401 struct msghdr msg;
402 union {
403         struct cmsghdr cm;
404         char control[CMSG_SPACE(sizeof(int))];
405 } control_un;
406 msg.msg_control = control_un.control;
407 msg.msg_controllen = sizeof(control_un.control);
408 ''',
409         'HAVE_MSGHDR_MSG_CONTROL',
410         msg='Checking if we can use msg_control for passing file descriptors',
411         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
412     conf.CHECK_CODE('''
413 struct msghdr msg;
414 int fd;
415 msg.msg_acctrights = (caddr_t) &fd;
416 msg.msg_acctrightslen = sizeof(fd);
417 ''',
418         'HAVE_MSGHDR_MSG_ACCTRIGHTS',
419         msg='Checking if we can use msg_acctrights for passing file descriptors',
420         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
421
422     if Options.options.with_winbind:
423         conf.env.build_winbind = True
424         conf.DEFINE('WITH_WINBIND', '1')
425
426     conf.find_program('awk', var='AWK')
427     conf.find_program('perl', var='PERL')
428
429     conf.CHECK_HEADERS('asm/types.h')
430
431     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
432                     headers='unistd.h sys/types.h',
433                     msg="Checking for major macro")
434
435     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
436                     headers='unistd.h sys/types.h',
437                     msg="Checking for minor macro")
438
439     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
440                                 headers='unistd.h sys/types.h dirent.h',
441                                 define='HAVE_DIRENT_D_OFF')
442
443     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
444     if conf.CHECK_CFLAGS('-Werror-implicit-function-declaration'):
445         netgrent_cflags = '-Werror-implicit-function-declaration'
446     else:
447         netgrent_cflags = ''
448     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
449                     msg="Checking for setnetgrent prototype",
450                     headers='netdb.h netgroup.h',
451                     cflags=netgrent_cflags)
452     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
453                     msg="Checking for getnetgrent prototype",
454                     headers='netdb.h netgroup.h',
455                     cflags=netgrent_cflags)
456     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
457                     msg="Checking for endnetgrent prototype",
458                     headers='netdb.h netgroup.h',
459                     cflags=netgrent_cflags)
460
461
462     # Look for CUPS
463     if Options.options.with_cups:
464         conf.find_program('cups-config', var='CUPS_CONFIG')
465         if conf.env.CUPS_CONFIG:
466             # we would normally use --libs here, but cups-config incorrectly adds
467             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
468             # of an in-tree heimdal kerberos
469             conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
470                            package="", uselib_store="CUPS")
471         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
472         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
473         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
474             conf.DEFINE('HAVE_CUPS', '1')
475         else:
476             conf.undefine('HAVE_CUPS')
477             conf.SET_TARGET_TYPE('cups', 'EMPTY')
478     else:
479         # define an empty subsystem for cups, to allow it to be used as an empty dependency
480         conf.SET_TARGET_TYPE('cups', 'EMPTY')
481
482     if Options.options.with_iprint:
483         if conf.CONFIG_SET('HAVE_CUPS'):
484             conf.DEFINE('HAVE_IPRINT', '1')
485         else:
486             Logs.warn("--enable-iprint=yes but cups support not sufficient")
487     if Options.options.with_syslog:
488         conf.DEFINE('WITH_SYSLOG', '1')
489     if Options.options.with_automount:
490         conf.DEFINE('WITH_AUTOMOUNT', '1')
491
492     # Check for LDAP
493     if Options.options.with_ldap:
494         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
495         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
496         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
497         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
498
499         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
500         # for the samba logs
501         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
502                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
503
504         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
505         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
506
507         # Check if ldap_set_rebind_proc() takes three arguments
508         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
509                            'LDAP_SET_REBIND_PROC_ARGS',
510                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
511                            headers='ldap.h lber.h', link=False):
512             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
513         else:
514             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
515
516         # last but not least, if ldap_init() exists, we want to use ldap
517         if conf.CONFIG_SET('HAVE_LDAP_INIT'):
518             conf.DEFINE('HAVE_LDAP', '1')
519             conf.DEFINE('LDAP_DEPRECATED', '1')
520             conf.env['HAVE_LDAP'] = '1'
521             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
522             # SASL wrapping hooks
523             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
524                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
525                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
526     else:
527         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
528         conf.SET_TARGET_TYPE('lber', 'EMPTY')
529
530     if Options.options.with_ads:
531         use_ads=True
532         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
533            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
534             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
535             use_ads=False
536         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
537             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
538             use_ads=False
539         if not conf.CONFIG_SET('HAVE_KRB5_GET_HOST_REALM'):
540             Logs.warn("krb5_get_host_realm not found in -lkrb5")
541             use_ads=False
542         if not conf.CONFIG_SET('HAVE_KRB5_FREE_HOST_REALM'):
543             Logs.warn("krb5_free_host_realm not found in -lkrb5")
544             use_ads=False
545         if not conf.CONFIG_SET('HAVE_KRB5_FWD_TGT_CREDS'):
546             Logs.warn("krb5_fwd_tgt_creds found in -lkrb5")
547             use_ads=False
548         if not conf.CONFIG_SET('HAVE_KRB5_GET_INIT_CREDS_OPT_ALLOC'):
549             Logs.warn("krb5_get_init_creds_opt_alloc not found in -lkrb5")
550             use_ads=False
551         if not conf.CONFIG_SET('KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT'):
552             Logs.warn("krb5_get_init_creds_opt_free was not found or was too old in -lkrb5")
553             use_ads=False
554         if not conf.CONFIG_SET('HAVE_KRB5_GET_RENEWED_CREDS'):
555             Logs.warn("krb5_get_renewed_creds not found in -lkrb5")
556             use_ads=False
557         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL_COMPARE_ANY_REALM'):
558             Logs.warn("krb5_principal_compare_any_realm not found in -lkrb5")
559             use_ads=False
560         if not conf.CONFIG_SET('HAVE_KRB5_C_STRING_TO_KEY') and \
561            not conf.CONFIG_SET('HAVE_KRB5_STRING_TO_KEY_SALT'):
562             Logs.warn("krb5_c_string_to_key not found in -lkrb5")
563             use_ads=False
564         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
565            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
566             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
567             use_ads=False
568         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
569            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
570             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
571             use_ads=False
572         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
573            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
574             Logs.warn("no KT_FREE_FUNCTION detected")
575             use_ads=False
576         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM'):
577             Logs.warn("krb5_c_verify_checksum_compare not found in -lkrb5")
578             use_ads=False
579
580         # We don't actually use
581         # gsskrb5_extract_authz_data_from_sec_context, but it is a
582         # clue that this Heimdal, which does the PAC processing we
583         # need on the standard gss_inquire_sec_context_by_oid
584         if not conf.CONFIG_SET('HAVE_GSS_GET_NAME_ATTRIBUTE') and \
585             not (conf.CONFIG_SET('HAVE_GSSKRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT') and \
586                      conf.CONFIG_SET('HAVE_GSS_INQUIRE_SEC_CONTEXT_BY_OID')):
587             Logs.warn("need eiterh gss_get_name_attribute or gsskrb5_extract_authz_data_from_sec_context and gss_inquire_sec_context_by_oid in -lgssapi for PAC support")
588             use_ads=False
589
590         if not conf.CONFIG_SET('HAVE_GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT'):
591             Logs.warn("need gss_krb5_export_lucid_sec_context for SPNEGO and gss_wrap support")
592             use_ads=False
593
594         if use_ads:
595             conf.DEFINE('WITH_ADS', '1')
596             conf.DEFINE('HAVE_KRB5', '1')
597             if conf.CONFIG_SET('HAVE_LDAP'):
598                 conf.env['HAVE_ADS'] = '1'
599         else:
600             Logs.warn("krb5 libs don't have all features required for Active Directory support")
601             conf.undefine('HAVE_KRB5_H')
602             conf.undefine('HAVE_GSSAPI_H')
603             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
604             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
605
606     if Options.options.with_utmp:
607         conf.env.with_utmp = True
608         if not conf.CHECK_HEADERS('utmp.h'): conf.env.with_utmp = False
609         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
610         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
611                                     define='HAVE_UT_UT_NAME')
612         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
613                                     define='HAVE_UT_UT_USER')
614         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
615                                     define='HAVE_UT_UT_ID')
616         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
617                                     define='HAVE_UT_UT_HOST')
618         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
619                                     define='HAVE_UT_UT_TIME')
620         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
621                                     define='HAVE_UT_UT_TV')
622         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
623                                     define='HAVE_UT_UT_TYPE')
624         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
625                                     define='HAVE_UT_UT_PID')
626         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
627                                     define='HAVE_UT_UT_EXIT')
628         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
629                                     define='HAVE_UT_UT_ADDR_V6')
630         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
631                                     define='HAVE_UT_UT_ADDR')
632         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
633                                     define='HAVE_UX_UT_SYSLEN')
634         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
635                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
636                         msg="Checking whether pututline returns pointer")
637         if conf.env.with_utmp:
638             conf.DEFINE('WITH_UTMP', 1)
639
640     if Options.options.with_avahi:
641         conf.env.with_avahi = True
642         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
643         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
644         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
645         if conf.env.with_avahi:
646             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
647     else:
648         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
649         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
650
651     if Options.options.with_iconv:
652         conf.env.with_iconv = True
653         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
654             conf.env.with_iconv = False
655         if conf.env.with_iconv:
656             conf.DEFINE('HAVE_ICONV', 1)
657
658     if Options.options.with_pam:
659         use_pam=True
660         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
661         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
662             Logs.warn("--with-pam=yes but pam_appl.h not found")
663             use_pam=False
664         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
665         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
666         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
667             Logs.warn("--with-pam=yes but pam_modules.h not found")
668             use_pam=False
669         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
670         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
671         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
672         conf.CHECK_CODE('''
673 #if defined(HAVE_SECURITY_PAM_APPL_H)
674 #include <security/pam_appl.h>
675 #elif defined(HAVE_PAM_PAM_APPL_H)
676 #include <pam/pam_appl.h>
677 #endif
678 pam_set_item(0, PAM_RHOST, 0);
679 ''',
680             'HAVE_PAM_RHOST',
681             lib='pam',
682             msg="Checking whether PAM_RHOST is available");
683         conf.CHECK_CODE('''
684 #if defined(HAVE_SECURITY_PAM_APPL_H)
685 #include <security/pam_appl.h>
686 #elif defined(HAVE_PAM_PAM_APPL_H)
687 #include <pam/pam_appl.h>
688 #endif
689 pam_set_item(0, PAM_TTY, 0);
690 ''',
691             'HAVE_PAM_TTY',
692             lib='pam',
693             msg="Checking whether PAM_TTY is available");
694         conf.CHECK_CODE('''
695 #if (!defined(LINUX))
696
697 #define PAM_EXTERN extern
698 #if defined(HAVE_SECURITY_PAM_APPL_H)
699 #include <security/pam_appl.h>
700 #elif defined(HAVE_PAM_PAM_APPL_H)
701 #include <pam/pam_appl.h>
702 #endif
703
704 #endif
705
706 #if defined(HAVE_SECURITY_PAM_MODULES_H)
707 #include <security/pam_modules.h>
708 #elif defined(HAVE_PAM_PAM_MODULES_H)
709 #include <pam/pam_modules.h>
710 #endif
711
712 #if defined(HAVE_SECURITY__PAM_MACROS_H)
713 #include <security/_pam_macros.h>
714 #elif defined(HAVE_PAM__PAM_MACROS_H)
715 #include <pam/_pam_macros.h>
716 #endif
717
718 #ifdef HAVE_SECURITY_PAM_EXT_H
719 #include <security/pam_ext.h>
720 #endif
721
722 int i; i = PAM_RADIO_TYPE;
723 ''',
724             'HAVE_PAM_RADIO_TYPE',
725             lib='pam',
726             msg="Checking whether PAM_RADIO_TYPE is available");
727         if use_pam:
728             conf.DEFINE('WITH_PAM', 1)
729             conf.DEFINE('WITH_PAM_MODULES', 1)
730
731     seteuid = False
732     if not seteuid:
733         seteuid = conf.CHECK_CODE('''
734                                 #define AUTOCONF_TEST 1
735                                 #define USE_LINUX_THREAD_CREDENTIALS 1
736                                 #include "./lib/util_sec.c"
737                                 ''',
738                                 'USE_LINUX_THREAD_CREDENTIALS',
739                                 addmain=False,
740                                 execute=True,
741                                 msg="Checking whether we can use Linux thread-specific credentials")
742     if not seteuid:
743         seteuid = conf.CHECK_CODE('''
744                                 #define AUTOCONF_TEST 1
745                                 #define USE_SETREUID 1
746                                 #include "./lib/util_sec.c"
747                                 ''',
748                                 'USE_SETREUID',
749                                 addmain=False,
750                                 execute=True,
751                                 msg="Checking whether setreuid is available")
752     if not seteuid:
753         seteuid = conf.CHECK_CODE('''
754                                 #define AUTOCONF_TEST 1
755                                 #define USE_SETRESUID 1
756                                 #include "./lib/util_sec.c"
757                                 ''',
758                                 'USE_SETRESUID',
759                                 addmain=False,
760                                 execute=True,
761                                 msg="Checking whether setresuid is available")
762     if not seteuid:
763         seteuid = conf.CHECK_CODE('''
764                                 #define AUTOCONF_TEST 1
765                                 #define USE_SETEUID 1
766                                 #include "./lib/util_sec.c"
767                                 ''',
768                                 'USE_SETEUID',
769                                 addmain=False,
770                                 execute=True,
771                                 msg="Checking whether seteuid is available")
772     if not seteuid:
773         seteuid = conf.CHECK_CODE('''
774                                 #define AUTOCONF_TEST 1
775                                 #define USE_SETUIDX 1
776                                 #include "./lib/util_sec.c"
777                                 ''',
778                                 'USE_SETUIDX',
779                                 addmain=False,
780                                 execute=True,
781                                 mandatory=True,
782                                 msg="Checking whether setuidx is available")
783     if Options.options.with_dnsupdate:
784         if not conf.CONFIG_SET('HAVE_KRB5'):
785             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
786         else:
787             conf.DEFINE('WITH_DNS_UPDATES', 1)
788     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
789     if Options.options.developer:
790         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
791             conf.DEFINE('VALGRIND', '1')
792
793     if conf.CHECK_CODE('''
794 #include <bits/sockaddr.h>
795 #include <linux/netlink.h>
796 ''',
797                 'HAVE_LINUX_NETLINK_H',
798                 msg="Checking whether Linux netlink is available"):
799
800         conf.CHECK_CODE('''
801 #include <bits/sockaddr.h>
802 #include <linux/netlink.h>
803 #include <linux/rtnetlink.h>
804 ''',
805                 'HAVE_LINUX_RTNETLINK_H',
806                 msg='Checking whether Linux rtnetlink is available')
807
808     conf.CHECK_CODE('''
809 #include "../tests/fcntl_lock.c"
810 ''',
811                 'HAVE_FCNTL_LOCK',
812                 addmain=False,
813                 execute=True,
814                 msg='Checking whether fcntl locking is available')
815
816 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
817     if not conf.CHECK_CODE('''
818 #define _XOPEN_SOURCE 600
819 #include <stdlib.h>
820 #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
821 #error probably broken posix_fallocate
822 #endif
823 ''',
824                            '_HAVE_UNBROKEN_POSIX_FALLOCATE',
825                            msg='Checking for broken posix_fallocate'):
826         conf.DEFINE('HAVE_BROKEN_POSIX_FALLOCATE', '1')
827
828
829     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
830                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
831     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
832                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
833     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
834                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
835     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
836                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
837     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
838                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
839     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
840        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
841        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
842        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
843        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
844         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
845
846     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
847     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
848                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
849     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
850                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
851     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
852                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
853
854     conf.CHECK_CODE('''
855 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
856 ''',
857                 'HAVE_POSIX_FADVISE',
858                 msg='Checking whether posix_fadvise is available',
859                 headers='unistd.h fcntl.h')
860
861     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
862         conf.CHECK_CODE('''
863                         #include <unistd.h>
864                         return sysconf(%s) == -1 ? 1 : 0;
865                         ''' % v,
866                         'SYSCONF%s' % v,
867                         msg='Checking whether sysconf(%s) is available' % v)
868
869     conf.CHECK_CODE('''
870 #include <sys/syscall.h>
871 #include <unistd.h>
872 syscall(SYS_initgroups, 16, NULL, NULL, 0);
873                     ''',
874                     'HAVE_DARWIN_INITGROUPS',
875                     msg='Checking whether to use the Darwin-specific initgroups system call')
876
877     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
878                     'HAVE_UTIMBUF',
879                     headers='sys/types.h utime.h',
880                     msg='Checking whether struct utimbuf is available')
881
882     if conf.CHECK_CODE('''struct sigevent s;''',
883                     'HAVE_STRUCT_SIGEVENT',
884                     headers='sys/types.h stdlib.h stddef.h signal.h',
885                     msg='Checking whether we have the struct sigevent'):
886         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
887                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
888                                     headers='signal.h');
889         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
890                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
891                                     headers='signal.h');
892
893     if os.path.exists('/proc/sys/kernel/core_pattern'):
894         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
895
896     if conf.CHECK_CODE('''
897 #include <time.h>
898 main() {
899         struct tm *tm;
900         if (sizeof(time_t) == 8) {
901                 time_t max_time = 0x7fffffffffffffffll;
902                 tm = gmtime(&max_time);
903                 /* This should fail with 32-bit tm_year. */
904                 if (tm == NULL) {
905                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
906                         max_time = 67768036191676799ll;
907                         tm = gmtime(&max_time);
908                         if (tm) {
909                                 exit(0);
910                         }
911                 }
912         }
913         exit(1);
914 }''',
915         '__TIME_T_MAX',
916         addmain=False,
917         execute=True,
918         msg="Checking for the maximum value of the 'time_t' type"):
919             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
920
921     conf.CHECK_CODE('''
922 #if defined(HAVE_UNISTD_H)
923 #include <unistd.h>
924 #endif
925 #include <sys/types.h>
926 main() { dev_t dev = makedev(1,2); return 0; }
927 ''',
928         'HAVE_MAKEDEV',
929         addmain=False,
930         msg='Checking whether the macro for makedev is available')
931
932     conf.CHECK_CODE('''
933 #include <stdio.h>
934 #include <limits.h>
935 #include <signal.h>
936
937 void exit_on_core(int ignored) {
938         exit(1);
939 }
940
941 main() {
942         char *newpath;
943         signal(SIGSEGV, exit_on_core);
944         newpath = realpath("/tmp", NULL);
945         exit((newpath != NULL) ? 0 : 1);
946 }
947 ''',
948         'REALPATH_TAKES_NULL',
949         addmain=False,
950         execute=True,
951         msg='Checking whether the realpath function allows a NULL argument')
952
953     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
954                     'HAVE_FTRUNCATE_EXTEND',
955                     msg='Checking for ftruncate extend',
956                     addmain=False,
957                     execute=True)
958     if os.getenv('RUN_FROM_BUILD_FARM'):
959         Logs.info("enabling buildfarm hacks")
960         conf.DEFINE('ENABLE_BUILD_FARM_HACKS', '1')
961
962     if Options.options.with_sendfile_support:
963         if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('k*bsd*-gnu') > -1) or (host_os.rfind('kopensolaris*-gnu') > -1):
964             conf.CHECK_CODE('''
965                             int tofd, fromfd;
966                             off_t offset;
967                             size_t total;
968                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
969                             ''',
970                             '_HAVE_SENDFILE',
971                             headers='sys/sendfile.h',
972                             msg='Checking for linux sendfile support')
973
974             if conf.CONFIG_SET('_HAVE_SENDFILE'):
975                 conf.DEFINE('HAVE_SENDFILE', '1')
976                 conf.DEFINE('LINUX_SENDFILE_API', '1')
977                 conf.DEFINE('WITH_SENDFILE', '1')
978         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
979             conf.CHECK_CODE('''
980                             #include <sys/types.h>
981                             #include <unistd.h>
982                             #include <sys/socket.h>
983                             #include <sys/uio.h>
984                             int fromfd, tofd, ret, total=0;
985                             off_t offset, nwritten;
986                             struct sf_hdtr hdr;
987                             struct iovec hdtrl;
988                             hdr.headers = &hdtrl;
989                             hdr.hdr_cnt = 1;
990                             hdr.trailers = NULL;
991                             hdr.trl_cnt = 0;
992                             hdtrl.iov_base = NULL;
993                             hdtrl.iov_len = 0;
994                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
995                             ''',
996                             '_HAVE_SENDFILE',
997                             msg='Checking for freebsd sendfile support')
998             if conf.CONFIG_SET('_HAVE_SENDFILE'):
999                 conf.DEFINE('HAVE_SENDFILE', '1')
1000                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
1001                 conf.DEFINE('WITH_SENDFILE', '1')
1002         elif (host_os.rfind('hpux') > -1):
1003             conf.CHECK_CODE('''
1004                             #include <sys/socket.h>
1005                             #include <sys/uio.h>
1006                             int fromfd, tofd;
1007                             size_t total=0;
1008                             struct iovec hdtrl[2];
1009                             ssize_t nwritten;
1010                             off_t offset;
1011                             hdtrl[0].iov_base = 0;
1012                             hdtrl[0].iov_len = 0;
1013                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1014                             ''',
1015                             '_HAVE_SENDFILE',
1016                             msg='Checking for hpux sendfile support')
1017             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1018                 conf.DEFINE('HAVE_SENDFILE', '1')
1019                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1020                 conf.DEFINE('WITH_SENDFILE', '1')
1021         elif (host_os.rfind('solaris') > -1):
1022             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1023             conf.CHECK_CODE('''
1024                             #include <sys/sendfile.h>,
1025                             int sfvcnt;
1026                             size_t xferred;
1027                             struct sendfilevec vec[2];
1028                             ssize_t nwritten;
1029                             int tofd;
1030                             sfvcnt = 2;
1031                             vec[0].sfv_fd = SFV_FD_SELF;
1032                             vec[0].sfv_flag = 0;
1033                             vec[0].sfv_off = 0;
1034                             vec[0].sfv_len = 0;
1035                             vec[1].sfv_fd = 0;
1036                             vec[1].sfv_flag = 0;
1037                             vec[1].sfv_off = 0;
1038                             vec[1].sfv_len = 0;
1039                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1040                             ''',
1041                             '_HAVE_SENDFILEV',
1042                             msg='Checking for solaris sendfilev support')
1043             if conf.CONFIG_SET('_HAVE_SENDFILEV'):
1044                 conf.DEFINE('HAVE_SENDFILEV', '1')
1045                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1046                 conf.DEFINE('WITH_SENDFILE', '1')
1047         elif (host_os.rfind('aix') > -1):
1048             conf.CHECK_CODE('''
1049                             #include <sys/socket.h>
1050                             int fromfd, tofd;
1051                             size_t total=0;
1052                             struct sf_parms hdtrl;
1053                             ssize_t nwritten;
1054                             hdtrl.header_data = 0;
1055                             hdtrl.header_length = 0;
1056                             hdtrl.file_descriptor = fromfd;
1057                             hdtrl.file_offset = 0;
1058                             hdtrl.file_bytes = 0;
1059                             hdtrl.trailer_data = 0;
1060                             hdtrl.trailer_length = 0;
1061                             nwritten = send_file(&tofd, &hdtrl, 0);
1062                             ''',
1063                             '_HAVE_SENDFILE',
1064                             msg='Checking for AIX send_file support')
1065             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1066                 conf.DEFINE('HAVE_SENDFILE', '1')
1067                 conf.DEFINE('AIX_SENDFILE_API', '1')
1068                 conf.DEFINE('WITH_SENDFILE', '1')
1069
1070     # Check for getcwd allowing a NULL arg.
1071     conf.CHECK_CODE('''
1072 #include <unistd.h>
1073 main() {
1074         char *s = getcwd(NULL,0);
1075         exit(s != NULL ?  0 : 1);
1076 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1077         msg="getcwd takes a NULL argument")
1078
1079
1080     # UnixWare 7.x has its getspnam in -lgen
1081     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1082     conf.CHECK_FUNCS_IN('getspnam', 'security')
1083     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1084
1085     if Options.options.with_quotas:
1086         # For quotas on Veritas VxFS filesystems
1087         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1088         # For quotas on Linux XFS filesystems
1089         conf.CHECK_HEADERS('linux/dqblk_xfs.h')
1090         # For sys/quota.h and linux/quota.h
1091         conf.CHECK_HEADERS('sys/quota.h')
1092
1093
1094     #
1095     # checking for clustering extensions (CTDB)
1096     #
1097     if not Options.options.with_cluster_support:
1098         have_cluster_support = False
1099
1100     else:
1101
1102         if Options.options.ctdb_dir:
1103             conf.ADD_EXTRA_INCLUDES(Options.options.ctdb_dir + '/include')
1104
1105         srcdir = os.path.realpath(conf.srcdir)
1106         if 'EXTRA_INCLUDES' in conf.env:
1107             includes = ' '.join(conf.env['EXTRA_INCLUDES']).replace('#', srcdir + '/')
1108         else:
1109             includes = ''
1110
1111         have_cluster_support = True
1112         ctdb_broken = ""
1113
1114         conf.CHECK_CODE('''
1115             #define NO_CONFIG_H
1116             #include "replace.h"
1117             #include "system/wait.h"
1118             #include "system/network.h"
1119             #define private #error __USED_RESERVED_WORD_private__
1120             #include <talloc.h>
1121             #include <tdb.h>
1122             #include <ctdb.h>
1123
1124             int main(void)
1125             {
1126                 return 0;
1127             }
1128             ''',
1129             'HAVE_CTDB_H',
1130             addmain=False,
1131             includes=includes,
1132             msg='Checking for header ctdb.h')
1133
1134         if not conf.CONFIG_SET('HAVE_CTDB_H'):
1135             have_cluster_support = False
1136             ctdb_broken = "ctdb.h is required for cluster support"
1137
1138         if have_cluster_support:
1139             conf.CHECK_CODE('''
1140                 #define NO_CONFIG_H
1141                 #include "replace.h"
1142                 #include "system/wait.h"
1143                 #include "system/network.h"
1144                 #define private #error __USED_RESERVED_WORD_private__
1145                 #include <talloc.h>
1146                 #include <tdb.h>
1147                 #include <ctdb.h>
1148                 #include <ctdb_private.h>
1149
1150                 int main(void)
1151                 {
1152                     return 0;
1153                 }
1154                 ''',
1155                 'HAVE_CTDB_PRIVATE_H',
1156                 addmain=False,
1157                 includes=includes,
1158                 msg='Checking for header ctdb_private.h')
1159
1160             if not conf.CONFIG_SET('HAVE_CTDB_PRIVATE_H'):
1161                 have_cluster_support = False
1162                 ctdb_broken = "ctdb_private.h is required for cluster support"
1163
1164         if have_cluster_support:
1165             conf.CHECK_CODE('''
1166                 #define NO_CONFIG_H
1167                 #include "replace.h"
1168                 #include "system/wait.h"
1169                 #include "system/network.h"
1170                 #include <talloc.h>
1171                 #include <tdb.h>
1172                 #include <ctdb.h>
1173                 #include <ctdb_private.h>
1174
1175                 int main(void)
1176                 {
1177                    int i = (int)CTDB_CONTROL_TRANS3_COMMIT;
1178                    return 0;
1179                 }
1180                 ''',
1181                 'HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL',
1182                 addmain=False,
1183                 includes=includes,
1184                 msg='Checking for transaction support (TRANS3_COMMIT control)')
1185
1186             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL'):
1187                 have_cluster_support = False
1188                 ctdb_broken = "ctdb transaction support missing or too old"
1189
1190         if have_cluster_support:
1191             conf.CHECK_CODE('''
1192                 #define NO_CONFIG_H
1193                 #include "replace.h"
1194                 #include "system/wait.h"
1195                 #include "system/network.h"
1196                 #include <talloc.h>
1197                 #include <tdb.h>
1198                 #include <ctdb.h>
1199                 #include <ctdb_private.h>
1200
1201                 int main(void)
1202                 {
1203                     int i = (int)CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1204                     return 0;
1205                 }
1206                 ''',
1207                 'HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL',
1208                 addmain=False,
1209                 includes=includes,
1210                 msg='Checking for SCHEDULE_FOR_DELETION control')
1211
1212             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL'):
1213                 if not Options.options.enable_old_ctdb:
1214                     have_cluster_support = False
1215                     ctdb_broken = "SCHEDULE_FOR_DELETION control missing"
1216                 else:
1217                     Logs.warn("ignoring missing SCHEDULE_FOR_DELETION control (--enable-old-ctdb)")
1218
1219         if have_cluster_support:
1220             conf.CHECK_CODE('''
1221                 #define NO_CONFIG_H
1222                 #include "replace.h"
1223                 #include "system/wait.h"
1224                 #include "system/network.h"
1225                 #include <talloc.h>
1226                 #include <tdb.h>
1227                 #include <ctdb.h>
1228                 #include <ctdb_private.h>
1229
1230                 int main(void)
1231                 {
1232                     struct ctdb_control_tcp _x;
1233                     return 0;
1234                 }
1235                 ''',
1236                 'HAVE_STRUCT_CTDB_CONTROL_TCP',
1237                 addmain=False,
1238                 includes=includes,
1239                 msg='Checking for ctdb ipv4 support')
1240
1241             if not conf.CONFIG_SET('HAVE_STRUCT_CTDB_CONTROL_TCP'):
1242                 have_cluster_support = False
1243                 ctdb_broken = "missing struct ctdb_control_tcp"
1244
1245         if have_cluster_support:
1246             conf.CHECK_CODE('''
1247                 #define NO_CONFIG_H
1248                 #include "replace.h"
1249                 #include "system/wait.h"
1250                 #include "system/network.h"
1251                 #include <talloc.h>
1252                 #include <tdb.h>
1253                 #include <ctdb.h>
1254                 #include <ctdb_private.h>
1255
1256                 int main(void)
1257                 {
1258                     struct ctdb_control_tcp_addr _x;
1259                     return 0;
1260                 }
1261                 ''',
1262                 'HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR',
1263                 addmain=False,
1264                 includes=includes,
1265                 msg='Checking for ctdb ipv6 support')
1266
1267         if have_cluster_support:
1268             conf.CHECK_CODE('''
1269                 #define NO_CONFIG_H
1270                 #include "replace.h"
1271                 #include "system/wait.h"
1272                 #include "system/network.h"
1273                 #include <talloc.h>
1274                 #include <tdb.h>
1275                 #include <ctdb.h>
1276                 #include <ctdb_private.h>
1277
1278                 int main(void)
1279                 {
1280                     int i = (int)CTDB_CONTROL_CHECK_SRVIDS;
1281                     return 0;
1282                 }
1283                 ''',
1284                 'HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL',
1285                 addmain=False,
1286                 includes=includes,
1287                 msg='Checking for CHECK_SRVIDS control')
1288
1289             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL'):
1290                 if not Options.options.enable_old_ctdb:
1291                     have_cluster_support = False
1292                     ctdb_broken = "CHECK_SRVIDS control missing"
1293                 else:
1294                     Logs.warn("ignoring missing CHECK_SRVIDS control (--enable-old-ctdb)")
1295
1296     if have_cluster_support:
1297         Logs.info("building with cluster support")
1298         conf.DEFINE('CLUSTER_SUPPORT', 1);
1299     else:
1300         if not Options.options.with_cluster_support:
1301             Logs.info("building without cluster support")
1302         else:
1303             Logs.warn("building without cluster support: " + ctdb_broken)
1304         conf.undefine('CLUSTER_SUPPORT')
1305
1306
1307
1308     conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1309                     'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1310                     addmain=False,
1311                     link=False,
1312                     msg='Checking whether we can compile with __attribute__((destructor))')
1313
1314     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1315                     'SEEKDIR_RETURNS_VOID',
1316                     headers='sys/types.h dirent.h',
1317                     msg='Checking whether seekdir returns void')
1318
1319     if Options.options.with_profiling_data:
1320         conf.DEFINE('WITH_PROFILE', 1);
1321
1322     PTHREAD_CFLAGS='error'
1323     PTHREAD_LDFLAGS='error'
1324
1325     if PTHREAD_LDFLAGS == 'error':
1326         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
1327             PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
1328             PTHREAD_LDFLAGS='-lpthread'
1329     if PTHREAD_LDFLAGS == 'error':
1330         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
1331             PTHREAD_CFLAGS='-D_THREAD_SAFE'
1332             PTHREAD_LDFLAGS='-lpthreads'
1333     if PTHREAD_LDFLAGS == 'error':
1334         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
1335             PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
1336             PTHREAD_LDFLAGS='-pthread'
1337     if PTHREAD_LDFLAGS == 'error':
1338         if conf.CHECK_FUNCS('pthread_attr_init'):
1339             PTHREAD_CFLAGS='-D_REENTRANT'
1340             PTHREAD_LDFLAGS='-lpthread'
1341     # especially for HP-UX, where the CHECK_FUNC macro fails to test for
1342     # pthread_attr_init. On pthread_mutex_lock it works there...
1343     if PTHREAD_LDFLAGS == 'error':
1344         if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
1345             PTHREAD_CFLAGS='-D_REENTRANT'
1346             PTHREAD_LDFLAGS='-lpthread'
1347
1348     if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
1349         conf.ADD_CFLAGS(PTHREAD_CFLAGS)
1350         conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
1351         conf.CHECK_HEADERS('pthread.h')
1352         conf.DEFINE('HAVE_PTHREAD', '1')
1353
1354     if Options.options.with_pthreadpool:
1355         if conf.CONFIG_SET('HAVE_PTHREAD'):
1356             conf.DEFINE('WITH_PTHREADPOOL', '1')
1357         else:
1358             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
1359             conf.undefine('WITH_PTHREADPOOL')
1360
1361     if conf.CHECK_HEADERS('gpfs_gpl.h'):
1362         conf.DEFINE('HAVE_GPFS', '1')
1363
1364     # Note that all charset 'modules' must actually be static, due to dependency loop issues 
1365     # if we include the module loader in iconv
1366
1367     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1368                                       auth_sam auth_unix auth_winbind auth_wbc
1369                                       auth_domain auth_builtin vfs_default
1370                                       nss_info_template idmap_tdb idmap_passdb
1371                                       idmap_nss''')
1372
1373     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1374                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1375                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
1376                                       auth_script vfs_readahead vfs_xattr_tdb vfs_posix_eadb
1377                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1378                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1379                                       vfs_crossrename vfs_linux_xfs_sgid
1380                                       vfs_time_audit idmap_autorid idmap_tdb2
1381                                       idmap_rid idmap_hash''')
1382
1383     if Options.options.developer:
1384         default_static_modules.extend(TO_LIST('charset_weird'))
1385         default_shared_modules.extend(TO_LIST('perfcount_test'))
1386         default_shared_modules.extend(TO_LIST('vfs_skel_opaque vfs_skel_transparent vfs_shadow_copy_test'))
1387         default_shared_modules.extend(TO_LIST('auth_skel pdb_test'))
1388
1389     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
1390         default_static_modules.extend(TO_LIST('pdb_samba4 auth_samba4 vfs_dfs_samba4'))
1391
1392     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
1393         default_static_modules.extend(TO_LIST('vfs_posixacl'))
1394
1395     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1396         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1397
1398     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1399         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1400
1401     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1402         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1403
1404     if conf.CONFIG_SET('HAVE_AIO') and (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
1405         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1406
1407     if conf.CONFIG_SET('HAVE_AIO') and Options.options.with_pthreadpool:
1408         default_shared_modules.extend(TO_LIST('vfs_aio_pthread'))
1409
1410     if conf.CONFIG_SET('HAVE_AIO') and conf.CONFIG_SET('HAVE_LINUX_KERNEL_AIO'):
1411         default_shared_modules.extend(TO_LIST('vfs_aio_linux'))
1412
1413     if conf.CONFIG_SET('HAVE_LDAP'):
1414         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
1415
1416     if conf.CONFIG_SET('DARWINOS'):
1417         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1418
1419     if conf.CONFIG_SET('HAVE_GPFS'):
1420         default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
1421
1422     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1423     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1424
1425     final_static_modules = default_static_modules
1426     final_shared_modules = default_shared_modules
1427
1428     for m in explicit_static_modules:
1429         if m in final_shared_modules:
1430             final_shared_modules.remove(m)
1431         final_static_modules.append(m)
1432     for m in explicit_shared_modules:
1433         if m in final_static_modules:
1434             final_static_modules.remove(m)
1435         final_shared_modules.append(m)
1436
1437     conf.env['static_modules'] = final_static_modules
1438     conf.env['shared_modules'] = final_shared_modules
1439
1440     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1441
1442     static_list = {}
1443     shared_list = {}
1444
1445     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1446     conf.env['MODULE_PREFIXES'] = prefixes
1447     for p in prefixes:
1448         for m in final_static_modules:
1449             if m.find(p) == 0:
1450                 if not p in static_list:
1451                     static_list[p] = []
1452                 static_list[p].append(m)
1453         for m in final_shared_modules:
1454             if m.find(p) == 0:
1455                 if not p in shared_list:
1456                     shared_list[p] = []
1457                 shared_list[p].append(m)
1458
1459     for p in prefixes:
1460         static_env = "%s_STATIC" % p.upper()
1461         shared_env = "%s_SHARED" % p.upper()
1462         conf.env[static_env] = []
1463         conf.env[shared_env] = []
1464         if p in static_list:
1465             decl_list=""
1466             for entry in static_list[p]:
1467                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1468                 conf.env[static_env].append('%s' % entry)
1469             decl_list = decl_list.rstrip()
1470             conf.DEFINE('static_decl_%s' % p, decl_list)
1471             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1472         else:
1473             conf.DEFINE('static_decl_%s' % p, '')
1474             conf.DEFINE('static_init_%s' % p, '{}')
1475         if p in shared_list:
1476             for entry in shared_list[p]:
1477                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
1478                 conf.env[shared_env].append('%s' % entry)
1479
1480     conf.SAMBA_CONFIG_H('include/config.h')
1481
1482 def ctags(ctx):
1483     "build 'tags' file using ctags"
1484     import Utils
1485     source_root = os.path.dirname(Utils.g_module.root_path)
1486     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1487     print("Running: %s" % cmd)
1488     os.system(cmd)
1489