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