lib/replace: xattr wrappers in lib/replace rather than source3/lib/system.c
[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 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,0);
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('linux') > -1:
309             conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
310             conf.CHECK_FUNCS_IN('getxattr', 'attr')
311             if conf.CHECK_CODE('''
312 acl_t acl;
313 int entry_id;
314 acl_entry_t *entry_p;
315 return acl_get_entry(acl, entry_id, entry_p);
316 ''',
317                         'HAVE_POSIX_ACLS',
318                         headers='sys/types.h sys/acl.h', link=False,
319                         msg="Checking for POSIX ACL support") :
320                 conf.CHECK_CODE('''
321 acl_permset_t permset_d;
322 acl_perm_t perm;
323 return acl_get_perm_np(permset_d, perm);
324 ''',
325                         'HAVE_ACL_GET_PERM_NP',
326                         headers='sys/types.h sys/acl.h', link=True,
327                         msg="Checking whether acl_get_perm_np() is available")
328         else:
329             conf.DEFINE('HAVE_NO_ACLS', 1)
330             conf.SET_TARGET_TYPE('acl', 'EMPTY')
331     else:
332         conf.DEFINE('HAVE_NO_ACLS', 1)
333         conf.SET_TARGET_TYPE('acl', 'EMPTY')
334
335     if conf.CHECK_FUNCS('dirfd'):
336         conf.DEFINE('HAVE_DIRFD_DECL', 1)
337
338     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
339                     'HAVE_STATFS_F_FSID',
340                     msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
341                     headers='sys/types.h sys/statfs.h',
342                     execute=True)
343
344     if conf.CONFIG_SET('HAVE_FALLOCATE'):
345         conf.CHECK_CODE('''
346                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
347                 'HAVE_LINUX_FALLOCATE',
348                 msg="Checking whether the Linux 'fallocate' function is available",
349                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
350     conf.CHECK_CODE('''
351                 ssize_t err = readahead(0,0,0x80000);''',
352                 'HAVE_LINUX_READAHEAD',
353                 msg="Checking whether Linux readahead is available",
354                 headers='unistd.h fcntl.h')
355     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
356
357     if Options.options.with_aio_support:
358         conf.CHECK_FUNCS_IN('aio_read', 'aio')
359         conf.CHECK_FUNCS_IN('aio_read', 'rt')
360         conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
361                         'HAVE_AIO',
362                         msg='Checking for asynchronous io support',
363                         headers='sys/types.h aio.h',
364                         lib='aio rt')
365         if conf.CONFIG_SET('HAVE_AIO'):
366             conf.DEFINE('WITH_AIO', '1')
367         if conf.CONFIG_SET('HAVE_AIO'):
368             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
369             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
370             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')
371             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
372             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
373             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')
374             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')
375             if host_os.rfind('linux') > -1:
376                 conf.CHECK_FUNCS_IN('io_submit', 'aio')
377                 conf.CHECK_CODE('''
378 struct io_event ioev;
379 struct iocb *ioc;
380 io_context_t ctx;
381 struct timespec ts;
382 int fd;
383 char *buf;
384 fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
385 io_queue_init(128,&ctx);
386 io_prep_pwrite(ioc, 1, buf, 1, 0);
387 io_prep_pread(ioc, 1, buf, 1, 0);
388 io_set_eventfd(ioc, fd);
389 io_set_callback(ioc, (io_callback_t)(0));
390 io_submit(ctx, 1, &ioc);
391 io_getevents(ctx, 1, 1, &ioev, &ts);
392 ''',
393                         'HAVE_LINUX_KERNEL_AIO',
394                         msg='Checking for linux kernel asynchronous io support',
395                         headers='unistd.h stdlib.h sys/types.h fcntl.h sys/eventfd.h libaio.h',
396                         lib='aio')
397
398         if not conf.CONFIG_SET('HAVE_AIO'):
399             conf.DEFINE('HAVE_NO_AIO', '1')
400     else:
401         conf.DEFINE('HAVE_NO_AIO', '1')
402
403     conf.CHECK_CODE('''
404 struct msghdr msg;
405 union {
406         struct cmsghdr cm;
407         char control[CMSG_SPACE(sizeof(int))];
408 } control_un;
409 msg.msg_control = control_un.control;
410 msg.msg_controllen = sizeof(control_un.control);
411 ''',
412         'HAVE_MSGHDR_MSG_CONTROL',
413         msg='Checking if we can use msg_control for passing file descriptors',
414         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
415     conf.CHECK_CODE('''
416 struct msghdr msg;
417 int fd;
418 msg.msg_acctrights = (caddr_t) &fd;
419 msg.msg_acctrightslen = sizeof(fd);
420 ''',
421         'HAVE_MSGHDR_MSG_ACCTRIGHTS',
422         msg='Checking if we can use msg_acctrights for passing file descriptors',
423         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
424
425     if Options.options.with_winbind:
426         conf.env.build_winbind = True
427         conf.DEFINE('WITH_WINBIND', '1')
428
429     conf.find_program('awk', var='AWK')
430     conf.find_program('perl', var='PERL')
431
432     conf.CHECK_HEADERS('asm/types.h')
433
434     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
435                     headers='unistd.h sys/types.h',
436                     msg="Checking for major macro")
437
438     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
439                     headers='unistd.h sys/types.h',
440                     msg="Checking for minor macro")
441
442     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
443                                 headers='unistd.h sys/types.h dirent.h',
444                                 define='HAVE_DIRENT_D_OFF')
445
446     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
447     if conf.CHECK_CFLAGS('-Werror-implicit-function-declaration'):
448         netgrent_cflags = '-Werror-implicit-function-declaration'
449     else:
450         netgrent_cflags = ''
451     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
452                     msg="Checking for setnetgrent prototype",
453                     headers='netdb.h netgroup.h',
454                     cflags=netgrent_cflags)
455     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
456                     msg="Checking for getnetgrent prototype",
457                     headers='netdb.h netgroup.h',
458                     cflags=netgrent_cflags)
459     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
460                     msg="Checking for endnetgrent prototype",
461                     headers='netdb.h netgroup.h',
462                     cflags=netgrent_cflags)
463
464
465     # Look for CUPS
466     if Options.options.with_cups:
467         conf.find_program('cups-config', var='CUPS_CONFIG')
468         if conf.env.CUPS_CONFIG:
469             # we would normally use --libs here, but cups-config incorrectly adds
470             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
471             # of an in-tree heimdal kerberos
472             conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
473                            package="", uselib_store="CUPS")
474         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
475         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
476         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
477             conf.DEFINE('HAVE_CUPS', '1')
478         else:
479             conf.undefine('HAVE_CUPS')
480             conf.SET_TARGET_TYPE('cups', 'EMPTY')
481     else:
482         # define an empty subsystem for cups, to allow it to be used as an empty dependency
483         conf.SET_TARGET_TYPE('cups', 'EMPTY')
484
485     if Options.options.with_iprint:
486         if conf.CONFIG_SET('HAVE_CUPS'):
487             conf.DEFINE('HAVE_IPRINT', '1')
488         else:
489             Logs.warn("--enable-iprint=yes but cups support not sufficient")
490     if Options.options.with_syslog:
491         conf.DEFINE('WITH_SYSLOG', '1')
492     if Options.options.with_automount:
493         conf.DEFINE('WITH_AUTOMOUNT', '1')
494
495     # Check for LDAP
496     if Options.options.with_ldap:
497         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
498         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
499         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
500         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
501
502         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
503         # for the samba logs
504         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
505                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
506
507         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
508         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
509
510         # Check if ldap_set_rebind_proc() takes three arguments
511         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
512                            'LDAP_SET_REBIND_PROC_ARGS',
513                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
514                            headers='ldap.h lber.h', link=False):
515             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
516         else:
517             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
518
519         # last but not least, if ldap_init() exists, we want to use ldap
520         if conf.CONFIG_SET('HAVE_LDAP_INIT'):
521             conf.DEFINE('HAVE_LDAP', '1')
522             conf.DEFINE('LDAP_DEPRECATED', '1')
523             conf.env['HAVE_LDAP'] = '1'
524             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
525             # SASL wrapping hooks
526             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
527                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
528                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
529     else:
530         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
531         conf.SET_TARGET_TYPE('lber', 'EMPTY')
532
533     if Options.options.with_ads:
534         use_ads=True
535         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
536            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
537             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
538             use_ads=False
539         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
540             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
541             use_ads=False
542         if not conf.CONFIG_SET('HAVE_KRB5_GET_HOST_REALM'):
543             Logs.warn("krb5_get_host_realm not found in -lkrb5")
544             use_ads=False
545         if not conf.CONFIG_SET('HAVE_KRB5_FREE_HOST_REALM'):
546             Logs.warn("krb5_free_host_realm not found in -lkrb5")
547             use_ads=False
548         if not conf.CONFIG_SET('HAVE_KRB5_FWD_TGT_CREDS'):
549             Logs.warn("krb5_fwd_tgt_creds found in -lkrb5")
550             use_ads=False
551         if not conf.CONFIG_SET('HAVE_KRB5_GET_INIT_CREDS_OPT_ALLOC'):
552             Logs.warn("krb5_get_init_creds_opt_alloc not found in -lkrb5")
553             use_ads=False
554         if not conf.CONFIG_SET('KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT'):
555             Logs.warn("krb5_get_init_creds_opt_free was not found or was too old in -lkrb5")
556             use_ads=False
557         if not conf.CONFIG_SET('HAVE_KRB5_GET_RENEWED_CREDS'):
558             Logs.warn("krb5_get_renewed_creds not found in -lkrb5")
559             use_ads=False
560         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL_COMPARE_ANY_REALM'):
561             Logs.warn("krb5_principal_compare_any_realm not found in -lkrb5")
562             use_ads=False
563         if not conf.CONFIG_SET('HAVE_KRB5_C_STRING_TO_KEY') and \
564            not conf.CONFIG_SET('HAVE_KRB5_STRING_TO_KEY_SALT'):
565             Logs.warn("krb5_c_string_to_key not found in -lkrb5")
566             use_ads=False
567         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
568            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
569             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
570             use_ads=False
571         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
572            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
573             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
574             use_ads=False
575         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
576            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
577             Logs.warn("no KT_FREE_FUNCTION detected")
578             use_ads=False
579         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM'):
580             Logs.warn("krb5_c_verify_checksum_compare not found in -lkrb5")
581             use_ads=False
582
583         # We don't actually use
584         # gsskrb5_extract_authz_data_from_sec_context, but it is a
585         # clue that this Heimdal, which does the PAC processing we
586         # need on the standard gss_inquire_sec_context_by_oid
587         if not conf.CONFIG_SET('HAVE_GSS_GET_NAME_ATTRIBUTE') and \
588             not (conf.CONFIG_SET('HAVE_GSSKRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT') and \
589                      conf.CONFIG_SET('HAVE_GSS_INQUIRE_SEC_CONTEXT_BY_OID')):
590             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")
591             use_ads=False
592
593         if not conf.CONFIG_SET('HAVE_GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT'):
594             Logs.warn("need gss_krb5_export_lucid_sec_context for SPNEGO and gss_wrap support")
595             use_ads=False
596
597         if use_ads:
598             conf.DEFINE('WITH_ADS', '1')
599             conf.DEFINE('HAVE_KRB5', '1')
600             if conf.CONFIG_SET('HAVE_LDAP'):
601                 conf.env['HAVE_ADS'] = '1'
602         else:
603             Logs.warn("krb5 libs don't have all features required for Active Directory support")
604             conf.undefine('HAVE_KRB5_H')
605             conf.undefine('HAVE_GSSAPI_H')
606             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
607             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
608
609     if Options.options.with_utmp:
610         conf.env.with_utmp = True
611         if not conf.CHECK_HEADERS('utmp.h'): conf.env.with_utmp = False
612         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
613         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
614                                     define='HAVE_UT_UT_NAME')
615         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
616                                     define='HAVE_UT_UT_USER')
617         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
618                                     define='HAVE_UT_UT_ID')
619         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
620                                     define='HAVE_UT_UT_HOST')
621         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
622                                     define='HAVE_UT_UT_TIME')
623         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
624                                     define='HAVE_UT_UT_TV')
625         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
626                                     define='HAVE_UT_UT_TYPE')
627         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
628                                     define='HAVE_UT_UT_PID')
629         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
630                                     define='HAVE_UT_UT_EXIT')
631         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
632                                     define='HAVE_UT_UT_ADDR_V6')
633         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
634                                     define='HAVE_UT_UT_ADDR')
635         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
636                                     define='HAVE_UX_UT_SYSLEN')
637         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
638                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
639                         msg="Checking whether pututline returns pointer")
640         if conf.env.with_utmp:
641             conf.DEFINE('WITH_UTMP', 1)
642
643     if Options.options.with_avahi:
644         conf.env.with_avahi = True
645         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
646         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
647         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
648         if conf.env.with_avahi:
649             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
650     else:
651         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
652         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
653
654     if Options.options.with_iconv:
655         conf.env.with_iconv = True
656         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
657             conf.env.with_iconv = False
658         if conf.env.with_iconv:
659             conf.DEFINE('HAVE_ICONV', 1)
660
661     if Options.options.with_pam:
662         use_pam=True
663         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
664         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
665             Logs.warn("--with-pam=yes but pam_appl.h not found")
666             use_pam=False
667         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
668         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
669         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
670             Logs.warn("--with-pam=yes but pam_modules.h not found")
671             use_pam=False
672         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
673         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
674         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
675         conf.CHECK_CODE('''
676 #if defined(HAVE_SECURITY_PAM_APPL_H)
677 #include <security/pam_appl.h>
678 #elif defined(HAVE_PAM_PAM_APPL_H)
679 #include <pam/pam_appl.h>
680 #endif
681 pam_set_item(0, PAM_RHOST, 0);
682 ''',
683             'HAVE_PAM_RHOST',
684             lib='pam',
685             msg="Checking whether PAM_RHOST is available");
686         conf.CHECK_CODE('''
687 #if defined(HAVE_SECURITY_PAM_APPL_H)
688 #include <security/pam_appl.h>
689 #elif defined(HAVE_PAM_PAM_APPL_H)
690 #include <pam/pam_appl.h>
691 #endif
692 pam_set_item(0, PAM_TTY, 0);
693 ''',
694             'HAVE_PAM_TTY',
695             lib='pam',
696             msg="Checking whether PAM_TTY is available");
697         conf.CHECK_CODE('''
698 #if (!defined(LINUX))
699
700 #define PAM_EXTERN extern
701 #if defined(HAVE_SECURITY_PAM_APPL_H)
702 #include <security/pam_appl.h>
703 #elif defined(HAVE_PAM_PAM_APPL_H)
704 #include <pam/pam_appl.h>
705 #endif
706
707 #endif
708
709 #if defined(HAVE_SECURITY_PAM_MODULES_H)
710 #include <security/pam_modules.h>
711 #elif defined(HAVE_PAM_PAM_MODULES_H)
712 #include <pam/pam_modules.h>
713 #endif
714
715 #if defined(HAVE_SECURITY__PAM_MACROS_H)
716 #include <security/_pam_macros.h>
717 #elif defined(HAVE_PAM__PAM_MACROS_H)
718 #include <pam/_pam_macros.h>
719 #endif
720
721 #ifdef HAVE_SECURITY_PAM_EXT_H
722 #include <security/pam_ext.h>
723 #endif
724
725 int i; i = PAM_RADIO_TYPE;
726 ''',
727             'HAVE_PAM_RADIO_TYPE',
728             lib='pam',
729             msg="Checking whether PAM_RADIO_TYPE is available");
730         if use_pam:
731             conf.DEFINE('WITH_PAM', 1)
732             conf.DEFINE('WITH_PAM_MODULES', 1)
733
734     seteuid = False
735     if not seteuid:
736         seteuid = conf.CHECK_CODE('''
737                                 #define AUTOCONF_TEST 1
738                                 #define USE_SETREUID 1
739                                 #include "./lib/util_sec.c"
740                                 ''',
741                                 'USE_SETREUID',
742                                 addmain=False,
743                                 execute=True,
744                                 msg="Checking whether setreuid is available")
745     if not seteuid:
746         seteuid = conf.CHECK_CODE('''
747                                 #define AUTOCONF_TEST 1
748                                 #define USE_SETRESUID 1
749                                 #include "./lib/util_sec.c"
750                                 ''',
751                                 'USE_SETRESUID',
752                                 addmain=False,
753                                 execute=True,
754                                 msg="Checking whether setresuid is available")
755     if not seteuid:
756         seteuid = conf.CHECK_CODE('''
757                                 #define AUTOCONF_TEST 1
758                                 #define USE_SETEUID 1
759                                 #include "./lib/util_sec.c"
760                                 ''',
761                                 'USE_SETEUID',
762                                 addmain=False,
763                                 execute=True,
764                                 msg="Checking whether seteuid is available")
765     if not seteuid:
766         seteuid = conf.CHECK_CODE('''
767                                 #define AUTOCONF_TEST 1
768                                 #define USE_SETUIDX 1
769                                 #include "./lib/util_sec.c"
770                                 ''',
771                                 'USE_SETUIDX',
772                                 addmain=False,
773                                 execute=True,
774                                 mandatory=True,
775                                 msg="Checking whether setuidx is available")
776     if Options.options.with_dnsupdate:
777         if not conf.CONFIG_SET('HAVE_KRB5'):
778             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
779         else:
780             conf.DEFINE('WITH_DNS_UPDATES', 1)
781     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
782     if Options.options.developer:
783         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
784             conf.DEFINE('VALGRIND', '1')
785
786     if conf.CHECK_CODE('''
787 #include <bits/sockaddr.h>
788 #include <linux/netlink.h>
789 ''',
790                 'HAVE_LINUX_NETLINK_H',
791                 msg="Checking whether Linux netlink is available"):
792         conf.CHECK_CODE('''
793 #include <bits/sockaddr.h>
794 #include <linux/netlink.h>
795 #include <linux/rtnetlink.h>
796 ''',
797                 'HAVE_LINUX_RTNETLINK_H',
798                 msg='Checking whether Linux rtnetlink is available')
799     conf.CHECK_CODE('''
800 #include "../tests/fcntl_lock.c"
801 ''',
802                 'HAVE_FCNTL_LOCK',
803                 addmain=False,
804                 execute=True,
805                 msg='Checking whether fcntl locking is available')
806
807     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
808                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
809     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
810                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
811     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
812                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
813     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
814                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
815     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
816                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
817     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
818        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
819        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
820        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
821        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
822         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
823
824     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
825     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
826                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
827     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
828                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
829     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
830                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
831
832     conf.CHECK_CODE('''
833 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
834 ''',
835                 'HAVE_POSIX_FADVISE',
836                 msg='Checking whether posix_fadvise is available',
837                 headers='unistd.h fcntl.h')
838
839     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
840         conf.CHECK_CODE('''
841                         #include <unistd.h>
842                         return sysconf(%s) == -1 ? 1 : 0;
843                         ''' % v,
844                         'SYSCONF%s' % v,
845                         msg='Checking whether sysconf(%s) is available' % v)
846
847     conf.CHECK_CODE('''
848 #include <sys/syscall.h>
849 #include <unistd.h>
850 syscall(SYS_initgroups, 16, NULL, NULL, 0);
851                     ''',
852                     'HAVE_DARWIN_INITGROUPS',
853                     msg='Checking whether to use the Darwin-specific initgroups system call')
854
855     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
856                     'HAVE_UTIMBUF',
857                     headers='sys/types.h utime.h',
858                     msg='Checking whether struct utimbuf is available')
859
860     if conf.CHECK_CODE('''struct sigevent s;''',
861                     'HAVE_STRUCT_SIGEVENT',
862                     headers='sys/types.h stdlib.h stddef.h signal.h',
863                     msg='Checking whether we have the struct sigevent'):
864         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
865                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
866                                     headers='signal.h');
867         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
868                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
869                                     headers='signal.h');
870
871     if os.path.exists('/proc/sys/kernel/core_pattern'):
872         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
873
874     if conf.CHECK_CODE('''
875 #include <time.h>
876 main() {
877         struct tm *tm;
878         if (sizeof(time_t) == 8) {
879                 time_t max_time = 0x7fffffffffffffffll;
880                 tm = gmtime(&max_time);
881                 /* This should fail with 32-bit tm_year. */
882                 if (tm == NULL) {
883                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
884                         max_time = 67768036191676799ll;
885                         tm = gmtime(&max_time);
886                         if (tm) {
887                                 exit(0);
888                         }
889                 }
890         }
891         exit(1);
892 }''',
893         '__TIME_T_MAX',
894         addmain=False,
895         execute=True,
896         msg="Checking for the maximum value of the 'time_t' type"):
897             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
898
899     conf.CHECK_CODE('''
900 #if defined(HAVE_UNISTD_H)
901 #include <unistd.h>
902 #endif
903 #include <sys/types.h>
904 main() { dev_t dev = makedev(1,2); return 0; }
905 ''',
906         'HAVE_MAKEDEV',
907         addmain=False,
908         msg='Checking whether the macro for makedev is available')
909
910     conf.CHECK_CODE('''
911 #include <stdio.h>
912 #include <limits.h>
913 #include <signal.h>
914
915 void exit_on_core(int ignored) {
916         exit(1);
917 }
918
919 main() {
920         char *newpath;
921         signal(SIGSEGV, exit_on_core);
922         newpath = realpath("/tmp", NULL);
923         exit((newpath != NULL) ? 0 : 1);
924 }
925 ''',
926         'REALPATH_TAKES_NULL',
927         addmain=False,
928         execute=True,
929         msg='Checking whether the realpath function allows a NULL argument')
930
931     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
932                     'HAVE_FTRUNCATE_EXTEND',
933                     msg='Checking for ftruncate extend',
934                     addmain=False,
935                     execute=True)
936     if os.getenv('RUN_FROM_BUILD_FARM'):
937         Logs.info("enabling buildfarm hacks")
938         conf.DEFINE('ENABLE_BUILD_FARM_HACKS', '1')
939
940     if Options.options.with_sendfile_support:
941         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):
942             conf.CHECK_CODE('''
943                             int tofd, fromfd;
944                             off_t offset;
945                             size_t total;
946                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
947                             ''',
948                             '_HAVE_SENDFILE',
949                             headers='sys/sendfile',
950                             msg='Checking for linux sendfile support')
951
952             # Try and cope with broken Linux sendfile....
953             conf.CHECK_CODE('''#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
954                             #undef _FILE_OFFSET_BITS
955                             #endif
956                             #include <sys/sendfile.h>
957                             int tofd, fromfd;
958                             off_t offset;
959                             size_t total;
960                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
961                             ''',
962                             '_HAVE_BROKEN_LINUX_SENDFILE',
963                             msg='Checking for broken linux sendfile support')
964             if conf.CONFIG_SET('_HAVE_SENDFILE'):
965                 conf.DEFINE('HAVE_SENDFILE', '1')
966                 conf.DEFINE('LINUX_SENDFILE_API', '1')
967                 conf.DEFINE('WITH_SENDFILE', '1')
968             elif conf.CONFIG_SET('_HAVE_BROKEN_LINUX_SENDFILE'):
969                 conf.DEFINE('LINUX_BROKEN_SENDFILE_API', '1')
970                 conf.DEFINE('WITH_SENDFILE', '1')
971         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
972             conf.CHECK_CODE('''
973                             #include <sys/types.h>
974                             #include <unistd.h>
975                             #include <sys/socket.h>
976                             #include <sys/uio.h>
977                             int fromfd, tofd, ret, total=0;
978                             off_t offset, nwritten;
979                             struct sf_hdtr hdr;
980                             struct iovec hdtrl;
981                             hdr.headers = &hdtrl;
982                             hdr.hdr_cnt = 1;
983                             hdr.trailers = NULL;
984                             hdr.trl_cnt = 0;
985                             hdtrl.iov_base = NULL;
986                             hdtrl.iov_len = 0;
987                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
988                             ''',
989                             '_HAVE_SENDFILE',
990                             msg='Checking for freebsd sendfile support')
991             if conf.CONFIG_SET('_HAVE_SENDFILE'):
992                 conf.DEFINE('HAVE_SENDFILE', '1')
993                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
994                 conf.DEFINE('WITH_SENDFILE', '1')
995         elif (host_os.rfind('hpux') > -1):
996             conf.CHECK_CODE('''
997                             #include <sys/socket.h>
998                             #include <sys/uio.h>
999                             int fromfd, tofd;
1000                             size_t total=0;
1001                             struct iovec hdtrl[2];
1002                             ssize_t nwritten;
1003                             off_t offset;
1004                             hdtrl[0].iov_base = 0;
1005                             hdtrl[0].iov_len = 0;
1006                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1007                             ''',
1008                             '_HAVE_SENDFILE',
1009                             msg='Checking for hpux sendfile support')
1010             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1011                 conf.DEFINE('HAVE_SENDFILE', '1')
1012                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1013                 conf.DEFINE('WITH_SENDFILE', '1')
1014         elif (host_os.rfind('solaris') > -1):
1015             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1016             conf.CHECK_CODE('''
1017                             #include <sys/sendfile.h>,
1018                             int sfvcnt;
1019                             size_t xferred;
1020                             struct sendfilevec vec[2];
1021                             ssize_t nwritten;
1022                             int tofd;
1023                             sfvcnt = 2;
1024                             vec[0].sfv_fd = SFV_FD_SELF;
1025                             vec[0].sfv_flag = 0;
1026                             vec[0].sfv_off = 0;
1027                             vec[0].sfv_len = 0;
1028                             vec[1].sfv_fd = 0;
1029                             vec[1].sfv_flag = 0;
1030                             vec[1].sfv_off = 0;
1031                             vec[1].sfv_len = 0;
1032                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1033                             ''',
1034                             '_HAVE_SENDFILEV',
1035                             msg='Checking for solaris sendfilev support')
1036             if conf.CONFIG_SET('_HAVE_SENDFILEV'):
1037                 conf.DEFINE('HAVE_SENDFILEV', '1')
1038                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1039                 conf.DEFINE('WITH_SENDFILE', '1')
1040         elif (host_os.rfind('aix') > -1):
1041             conf.CHECK_CODE('''
1042                             #include <sys/socket.h>
1043                             int fromfd, tofd;
1044                             size_t total=0;
1045                             struct sf_parms hdtrl;
1046                             ssize_t nwritten;
1047                             hdtrl.header_data = 0;
1048                             hdtrl.header_length = 0;
1049                             hdtrl.file_descriptor = fromfd;
1050                             hdtrl.file_offset = 0;
1051                             hdtrl.file_bytes = 0;
1052                             hdtrl.trailer_data = 0;
1053                             hdtrl.trailer_length = 0;
1054                             nwritten = send_file(&tofd, &hdtrl, 0);
1055                             ''',
1056                             '_HAVE_SENDFILE',
1057                             msg='Checking for AIX send_file support')
1058             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1059                 conf.DEFINE('HAVE_SENDFILE', '1')
1060                 conf.DEFINE('AIX_SENDFILE_API', '1')
1061                 conf.DEFINE('WITH_SENDFILE', '1')
1062
1063     # Check for getcwd allowing a NULL arg.
1064     conf.CHECK_CODE('''
1065 #include <unistd.h>
1066 main() {
1067         char *s = getcwd(NULL,0);
1068         exit(s != NULL ?  0 : 1);
1069 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1070         msg="getcwd takes a NULL argument")
1071
1072
1073     # UnixWare 7.x has its getspnam in -lgen
1074     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1075     conf.CHECK_FUNCS_IN('getspnam', 'security')
1076     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1077
1078     if Options.options.with_quotas:
1079         # For quotas on Veritas VxFS filesystems
1080         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1081         # For quotas on Linux XFS filesystems
1082         conf.CHECK_HEADERS('linux/dqblk_xfs.h')
1083         # For sys/quota.h and linux/quota.h
1084         conf.CHECK_HEADERS('sys/quota.h')
1085
1086
1087     #
1088     # checking for clustering extensions (CTDB)
1089     #
1090     if not Options.options.with_cluster_support:
1091         have_cluster_support = False
1092
1093     else:
1094
1095         if Options.options.ctdb_dir:
1096             conf.ADD_EXTRA_INCLUDES(Options.options.ctdb_dir + '/include')
1097
1098         srcdir = os.path.realpath(conf.srcdir)
1099         if 'EXTRA_INCLUDES' in conf.env:
1100             includes = ' '.join(conf.env['EXTRA_INCLUDES']).replace('#', srcdir + '/')
1101         else:
1102             includes = ''
1103
1104         have_cluster_support = True
1105         ctdb_broken = ""
1106
1107         conf.CHECK_CODE('''
1108             #define NO_CONFIG_H
1109             #include "replace.h"
1110             #include "system/wait.h"
1111             #include "system/network.h"
1112             #define private #error __USED_RESERVED_WORD_private__
1113             #include <talloc.h>
1114             #include <tdb.h>
1115             #include <ctdb.h>
1116
1117             int main(void)
1118             {
1119                 return 0;
1120             }
1121             ''',
1122             'HAVE_CTDB_H',
1123             addmain=False,
1124             includes=includes,
1125             msg='Checking for header ctdb.h')
1126
1127         if not conf.CONFIG_SET('HAVE_CTDB_H'):
1128             have_cluster_support = False
1129             ctdb_broken = "ctdb.h is required for cluster support"
1130
1131         if have_cluster_support:
1132             conf.CHECK_CODE('''
1133                 #define NO_CONFIG_H
1134                 #include "replace.h"
1135                 #include "system/wait.h"
1136                 #include "system/network.h"
1137                 #define private #error __USED_RESERVED_WORD_private__
1138                 #include <talloc.h>
1139                 #include <tdb.h>
1140                 #include <ctdb.h>
1141                 #include <ctdb_private.h>
1142
1143                 int main(void)
1144                 {
1145                     return 0;
1146                 }
1147                 ''',
1148                 'HAVE_CTDB_PRIVATE_H',
1149                 addmain=False,
1150                 includes=includes,
1151                 msg='Checking for header ctdb_private.h')
1152
1153             if not conf.CONFIG_SET('HAVE_CTDB_PRIVATE_H'):
1154                 have_cluster_support = False
1155                 ctdb_broken = "ctdb_private.h is required for cluster support"
1156
1157         if have_cluster_support:
1158             conf.CHECK_CODE('''
1159                 #define NO_CONFIG_H
1160                 #include "replace.h"
1161                 #include "system/wait.h"
1162                 #include "system/network.h"
1163                 #include <talloc.h>
1164                 #include <tdb.h>
1165                 #include <ctdb.h>
1166                 #include <ctdb_private.h>
1167
1168                 int main(void)
1169                 {
1170                    int i = (int)CTDB_CONTROL_TRANS3_COMMIT;
1171                    return 0;
1172                 }
1173                 ''',
1174                 'HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL',
1175                 addmain=False,
1176                 includes=includes,
1177                 msg='Checking for transaction support (TRANS3_COMMIT control)')
1178
1179             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL'):
1180                 have_cluster_support = False
1181                 ctdb_broken = "ctdb transaction support missing or too old"
1182
1183         if have_cluster_support:
1184             conf.CHECK_CODE('''
1185                 #define NO_CONFIG_H
1186                 #include "replace.h"
1187                 #include "system/wait.h"
1188                 #include "system/network.h"
1189                 #include <talloc.h>
1190                 #include <tdb.h>
1191                 #include <ctdb.h>
1192                 #include <ctdb_private.h>
1193
1194                 int main(void)
1195                 {
1196                     int i = (int)CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1197                     return 0;
1198                 }
1199                 ''',
1200                 'HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL',
1201                 addmain=False,
1202                 includes=includes,
1203                 msg='Checking for SCHEDULE_FOR_DELETION control')
1204
1205             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL'):
1206                 if not Options.options.enable_old_ctdb:
1207                     have_cluster_support = False
1208                     ctdb_broken = "SCHEDULE_FOR_DELETION control missing"
1209                 else:
1210                     Logs.warn("ignoring missing SCHEDULE_FOR_DELETION control (--enable-old-ctdb)")
1211
1212         if have_cluster_support:
1213             conf.CHECK_CODE('''
1214                 #define NO_CONFIG_H
1215                 #include "replace.h"
1216                 #include "system/wait.h"
1217                 #include "system/network.h"
1218                 #include <talloc.h>
1219                 #include <tdb.h>
1220                 #include <ctdb.h>
1221                 #include <ctdb_private.h>
1222
1223                 int main(void)
1224                 {
1225                     struct ctdb_control_tcp _x;
1226                     return 0;
1227                 }
1228                 ''',
1229                 'HAVE_STRUCT_CTDB_CONTROL_TCP',
1230                 addmain=False,
1231                 includes=includes,
1232                 msg='Checking for ctdb ipv4 support')
1233
1234             if not conf.CONFIG_SET('HAVE_STRUCT_CTDB_CONTROL_TCP'):
1235                 have_cluster_support = False
1236                 ctdb_broken = "missing struct ctdb_control_tcp"
1237
1238         if have_cluster_support:
1239             conf.CHECK_CODE('''
1240                 #define NO_CONFIG_H
1241                 #include "replace.h"
1242                 #include "system/wait.h"
1243                 #include "system/network.h"
1244                 #include <talloc.h>
1245                 #include <tdb.h>
1246                 #include <ctdb.h>
1247                 #include <ctdb_private.h>
1248
1249                 int main(void)
1250                 {
1251                     struct ctdb_control_tcp_addr _x;
1252                     return 0;
1253                 }
1254                 ''',
1255                 'HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR',
1256                 addmain=False,
1257                 includes=includes,
1258                 msg='Checking for ctdb ipv6 support')
1259
1260         if have_cluster_support:
1261             conf.CHECK_CODE('''
1262                 #define NO_CONFIG_H
1263                 #include "replace.h"
1264                 #include "system/wait.h"
1265                 #include "system/network.h"
1266                 #include <talloc.h>
1267                 #include <tdb.h>
1268                 #include <ctdb.h>
1269                 #include <ctdb_private.h>
1270
1271                 int main(void)
1272                 {
1273                     int i = (int)CTDB_CONTROL_CHECK_SRVIDS;
1274                     return 0;
1275                 }
1276                 ''',
1277                 'HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL',
1278                 addmain=False,
1279                 includes=includes,
1280                 msg='Checking for CHECK_SRVIDS control')
1281
1282             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL'):
1283                 if not Options.options.enable_old_ctdb:
1284                     have_cluster_support = False
1285                     ctdb_broken = "CHECK_SRVIDS control missing"
1286                 else:
1287                     Logs.warn("ignoring missing CHECK_SRVIDS control (--enable-old-ctdb)")
1288
1289     if have_cluster_support:
1290         Logs.info("building with cluster support")
1291         conf.DEFINE('CLUSTER_SUPPORT', 1);
1292     else:
1293         if not Options.options.with_cluster_support:
1294             Logs.info("building without cluster support")
1295         else:
1296             Logs.warn("building without cluster support: " + ctdb_broken)
1297         conf.undefine('CLUSTER_SUPPORT')
1298
1299
1300
1301     conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1302                     'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1303                     addmain=False,
1304                     link=False,
1305                     msg='Checking whether we can compile with __attribute__((destructor))')
1306
1307     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1308                     'SEEKDIR_RETURNS_VOID',
1309                     headers='sys/types.h dirent.h',
1310                     msg='Checking whether seekdir returns void')
1311
1312     if Options.options.with_profiling_data:
1313         conf.DEFINE('WITH_PROFILE', 1);
1314
1315     PTHREAD_CFLAGS='error'
1316     PTHREAD_LDFLAGS='error'
1317
1318     if PTHREAD_LDFLAGS == 'error':
1319         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
1320             PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
1321             PTHREAD_LDFLAGS='-lpthread'
1322     if PTHREAD_LDFLAGS == 'error':
1323         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
1324             PTHREAD_CFLAGS='-D_THREAD_SAFE'
1325             PTHREAD_LDFLAGS='-lpthreads'
1326     if PTHREAD_LDFLAGS == 'error':
1327         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
1328             PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
1329             PTHREAD_LDFLAGS='-pthread'
1330     if PTHREAD_LDFLAGS == 'error':
1331         if conf.CHECK_FUNC('pthread_attr_init'):
1332             PTHREAD_CFLAGS='-D_REENTRANT'
1333             PTHREAD_LDFLAGS='-lpthread'
1334     # especially for HP-UX, where the CHECK_FUNC macro fails to test for
1335     # pthread_attr_init. On pthread_mutex_lock it works there...
1336     if PTHREAD_LDFLAGS == 'error':
1337         if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
1338             PTHREAD_CFLAGS='-D_REENTRANT'
1339             PTHREAD_LDFLAGS='-lpthread'
1340
1341     if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
1342         conf.ADD_CFLAGS(PTHREAD_CFLAGS)
1343         conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
1344         conf.CHECK_HEADERS('pthread.h')
1345         conf.DEFINE('HAVE_PTHREAD', '1')
1346
1347     if Options.options.with_pthreadpool:
1348         if conf.CONFIG_SET('HAVE_PTHREAD'):
1349             conf.DEFINE('WITH_PTHREADPOOL', '1')
1350         else:
1351             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
1352             conf.undefine('WITH_PTHREADPOOL')
1353
1354     if conf.CHECK_HEADERS('gpfs_gpl.h'):
1355         conf.DEFINE('HAVE_GPFS', '1')
1356
1357     # Note that all charset 'modules' must actually be static, due to dependency loop issues 
1358     # if we include the module loader in iconv
1359
1360     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1361                                       auth_sam auth_unix auth_winbind auth_wbc
1362                                       auth_domain auth_builtin vfs_default
1363                                       nss_info_template idmap_tdb idmap_passdb
1364                                       idmap_nss''')
1365
1366     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1367                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1368                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
1369                                       auth_script vfs_readahead vfs_xattr_tdb vfs_posix_eadb
1370                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1371                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1372                                       vfs_crossrename vfs_linux_xfs_sgid
1373                                       vfs_time_audit idmap_autorid''')
1374
1375     if Options.options.developer:
1376         default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond charset_weird'))
1377         default_shared_modules.extend(TO_LIST('perfcount_test'))
1378         default_shared_modules.extend(TO_LIST('vfs_skel_opaque vfs_skel_transparent vfs_shadow_copy_test'))
1379         default_shared_modules.extend(TO_LIST('auth_skel pdb_test'))
1380
1381     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
1382         default_static_modules.extend(TO_LIST('pdb_samba4 auth_samba4 vfs_dfs_samba4'))
1383
1384     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
1385         default_static_modules.extend(TO_LIST('vfs_posixacl'))
1386
1387     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1388         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1389
1390     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1391         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1392
1393     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1394         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1395
1396     if conf.CONFIG_SET('HAVE_AIO') and (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
1397         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1398
1399     if conf.CONFIG_SET('HAVE_AIO') and Options.options.with_pthreadpool:
1400         default_shared_modules.extend(TO_LIST('vfs_aio_pthread'))
1401
1402     if conf.CONFIG_SET('HAVE_AIO') and conf.CONFIG_SET('HAVE_LINUX_KERNEL_AIO'):
1403         default_shared_modules.extend(TO_LIST('vfs_aio_linux'))
1404
1405     if conf.CONFIG_SET('HAVE_LDAP'):
1406         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
1407
1408     if conf.CONFIG_SET('DARWINOS'):
1409         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1410
1411     if conf.CONFIG_SET('HAVE_GPFS'):
1412         default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
1413
1414     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1415     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1416
1417     final_static_modules = default_static_modules
1418     final_shared_modules = default_shared_modules
1419
1420     for m in explicit_static_modules:
1421         if m in final_shared_modules:
1422             final_shared_modules.remove(m)
1423         final_static_modules.append(m)
1424     for m in explicit_shared_modules:
1425         if m in final_static_modules:
1426             final_static_modules.remove(m)
1427         final_shared_modules.append(m)
1428
1429     conf.env['static_modules'] = final_static_modules
1430     conf.env['shared_modules'] = final_shared_modules
1431
1432     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1433
1434     static_list = {}
1435     shared_list = {}
1436
1437     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1438     conf.env['MODULE_PREFIXES'] = prefixes
1439     for p in prefixes:
1440         for m in final_static_modules:
1441             if m.find(p) == 0:
1442                 if not p in static_list:
1443                     static_list[p] = []
1444                 static_list[p].append(m)
1445         for m in final_shared_modules:
1446             if m.find(p) == 0:
1447                 if not p in shared_list:
1448                     shared_list[p] = []
1449                 shared_list[p].append(m)
1450
1451     for p in prefixes:
1452         static_env = "%s_STATIC" % p.upper()
1453         shared_env = "%s_SHARED" % p.upper()
1454         conf.env[static_env] = []
1455         conf.env[shared_env] = []
1456         if p in static_list:
1457             decl_list=""
1458             for entry in static_list[p]:
1459                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1460                 conf.env[static_env].append('%s' % entry)
1461             decl_list = decl_list.rstrip()
1462             conf.DEFINE('static_decl_%s' % p, decl_list)
1463             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1464         else:
1465             conf.DEFINE('static_decl_%s' % p, '')
1466             conf.DEFINE('static_init_%s' % p, '{}')
1467         if p in shared_list:
1468             for entry in shared_list[p]:
1469                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
1470                 conf.env[shared_env].append('%s' % entry)
1471
1472     conf.SAMBA_CONFIG_H('include/config.h')
1473
1474 def ctags(ctx):
1475     "build 'tags' file using ctags"
1476     import Utils
1477     source_root = os.path.dirname(Utils.g_module.root_path)
1478     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1479     print("Running: %s" % cmd)
1480     os.system(cmd)
1481