1b7f0e7745a951ab42a6c873527fc41752d41cde
[mat/samba.git] / source3 / wscript
1 #! /usr/bin/env python
2
3 srcdir = '..'
4 blddir = 'bin'
5
6 APPNAME='samba'
7 VERSION=None
8
9 import sys, os
10 from optparse import SUPPRESS_HELP
11 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
12 sys.path.insert(0, "source3")
13 import wafsamba, Options, Logs, Utils, Scripting
14 import build.charset
15 import samba_utils, samba_version
16 import samba3
17
18 Options.default_prefix = '/usr/local/samba'
19
20 def set_options(opt):
21     if not os.getenv('TOPLEVEL_BUILD'):
22         opt.BUILTIN_DEFAULT('NONE')
23         opt.PRIVATE_EXTENSION_DEFAULT('s3')
24         opt.RECURSE('../lib/replace')
25         opt.RECURSE('../dynconfig')
26         opt.RECURSE('selftest')
27         opt.RECURSE('../lib/nss_wrapper')
28         opt.RECURSE('../lib/socket_wrapper')
29         opt.RECURSE('../lib/tevent')
30         opt.RECURSE('../lib/tdb_compat')
31
32     opt.add_option('--with-static-modules',
33                    help=("Comma-separated list of names of modules to statically link in"),
34                    action="store", dest='static_modules', default=None)
35     opt.add_option('--with-shared-modules',
36                    help=("Comma-separated list of names of modules to build shared"),
37                    action="store", dest='shared_modules', default=None)
38     opt.add_option('--enable-selftest',
39                   help=("enable options necessary for selftest"),
40                   action="store_true", dest='enable_selftest', default=False)
41
42     opt.SAMBA3_ADD_OPTION('winbind')
43     opt.SAMBA3_ADD_OPTION('swat')
44     opt.SAMBA3_ADD_OPTION('ads')
45     opt.SAMBA3_ADD_OPTION('krb5')
46     opt.SAMBA3_ADD_OPTION('ldap')
47     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
48     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
49     opt.SAMBA3_ADD_OPTION('merged-build', with_name="enable", without_name="disable")
50     opt.SAMBA3_ADD_OPTION('pam')
51     opt.SAMBA3_ADD_OPTION('pam_smbpass')
52     opt.SAMBA3_ADD_OPTION('quotas')
53     opt.SAMBA3_ADD_OPTION('sys-quotas')
54     opt.SAMBA3_ADD_OPTION('sendfile-support')
55     opt.SAMBA3_ADD_OPTION('utmp')
56     opt.SAMBA3_ADD_OPTION('pthreadpool', with_name="enable", without_name="disable")
57     opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
58     opt.SAMBA3_ADD_OPTION('iconv')
59     opt.SAMBA3_ADD_OPTION('acl-support')
60     opt.SAMBA3_ADD_OPTION('dnsupdate')
61     opt.SAMBA3_ADD_OPTION('syslog')
62     opt.SAMBA3_ADD_OPTION('automount')
63     opt.SAMBA3_ADD_OPTION('aio-support')
64     opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
65
66     opt.SAMBA3_ADD_OPTION('cluster-support')
67
68     opt.add_option('--with-ctdb-dir',
69                    help=("Directory under which ctdb is installed"),
70                    action="store", dest='ctdb_dir', default=None)
71     opt.add_option('--enable-old-ctdb',
72                   help=("enable building against (too) old version of ctdb (default=false)"),
73                   action="store_true", dest='enable_old_ctdb', default=False)
74
75
76
77 def configure(conf):
78     from samba_utils import TO_LIST
79
80     if not conf.env.toplevel_build:
81         version = samba_version.load_version(env=conf.env)
82         conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
83         conf.DEFINE('_SAMBA_WAF_BUILD_', version.MAJOR)
84         conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
85         conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
86
87     if Options.options.developer:
88         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
89         conf.env.developer = True
90
91     if Options.options.with_swat:
92         conf.env['build_swat'] = True
93
94     if not conf.env.toplevel_build:
95
96         conf.RECURSE('../lib/replace')
97
98         conf.find_program('python', var='PYTHON', mandatory=True)
99         conf.find_program('perl', var='PERL', mandatory=True)
100         conf.find_program('xsltproc', var='XSLTPROC')
101
102         # enable tool to build python extensions
103         conf.check_tool('python')
104         conf.check_python_version((2,4,2))
105         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
106
107         if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
108             # Mac OSX needs to have this and it's also needed that the python is compiled with this
109             # otherwise you face errors about common symbols
110             if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
111                 conf.ADD_CFLAGS('-fno-common')
112             if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
113                 conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
114         if int(conf.env['PYTHON_VERSION'][0]) >= 3:
115            raise Utils.WafError('Python version 3.x is not supported by Samba yet')
116
117         conf.RECURSE('../dynconfig')
118         conf.RECURSE('../lib/ccan')
119         conf.RECURSE('../lib/tdb_compat')
120         conf.RECURSE('../lib/talloc')
121         conf.RECURSE('../lib/tevent')
122         conf.RECURSE('../lib/popt')
123         conf.RECURSE('../lib/nss_wrapper')
124         conf.RECURSE('../lib/socket_wrapper')
125         conf.RECURSE('../lib/zlib')
126         conf.RECURSE('../libcli/smbreadline')
127         conf.RECURSE('../lib/util')
128         conf.RECURSE('../lib/util/charset')
129
130         conf.ADD_EXTRA_INCLUDES('''#source3 #source3/include #lib/replace #lib''')
131         if not conf.env.USING_SYSTEM_TDB:
132             conf.ADD_EXTRA_INCLUDES('#lib/tdb_compat')
133         if not conf.env.USING_SYSTEM_TEVENT:
134             conf.ADD_EXTRA_INCLUDES('#lib/tevent')
135         if not conf.env.USING_SYSTEM_TALLOC:
136             conf.ADD_EXTRA_INCLUDES('#lib/talloc')
137         if not conf.env.USING_SYSTEM_POPT:
138             conf.ADD_EXTRA_INCLUDES('#lib/popt')
139
140     conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
141
142     conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
143     conf.CHECK_HEADERS('linux/falloc.h')
144
145     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod mknod64')
146     conf.CHECK_FUNCS('strtol strchr strupr chflags')
147     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
148     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
149     conf.CHECK_FUNCS('sigprocmask sigblock sigaction sigset innetgr')
150     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
151     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups sysconf stat64 fstat64')
152     conf.CHECK_FUNCS('lstat64 fopen64 atexit grantpt lseek64 ftruncate64 fallocate fallocate64 posix_fallocate posix_fallocate64')
153     conf.CHECK_FUNCS('fseek64 fseeko64 ftell64 ftello64 setluid')
154     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
155     conf.CHECK_FUNCS('opendir64 readdir64 seekdir64 telldir64 rewinddir64 closedir64')
156     conf.CHECK_FUNCS('fdopendir fdopendir64')
157     conf.CHECK_FUNCS('getpwent_r getdents64 setenv strcasecmp fcvt fcvtl')
158     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
159     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
160     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
161     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
162     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
163     conf.CHECK_FUNCS('shmget')
164     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
165     conf.CHECK_FUNCS('gettext dgettext bindtextdomain textdomain bind_textdomain_codeset')
166     #FIXME: for some reason this one still fails
167     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
168     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
169     conf.CHECK_DECLS('fdatasync', reverse=True)
170     conf.CHECK_DECLS('readahead', reverse=True, headers='fcntl.h')
171
172     if conf.CONFIG_SET('HAVE_LONG_LONG'):
173         conf.DEFINE('HAVE_LONGLONG', 1)
174
175     if conf.CHECK_CODE('''
176 #if defined(HAVE_UNISTD_H)
177 #include <unistd.h>
178 #endif
179 long ret = splice(0,0,1,0,400,0);
180 ''',
181         'HAVE_LINUX_SPLICE',
182         headers='fcntl.h'):
183         conf.CHECK_DECLS('splice', reverse=True, headers='fcntl.h')
184
185     # Check for inotify support
186     conf.CHECK_HEADERS('linux/inotify.h asm/unistd.h sys/inotify.h')
187     conf.CHECK_FUNCS('inotify_init')
188     if "HAVE_LINUX_INOTIFY_H" in conf.env and "HAVE_INOTIFY_INIT" in conf.env:
189         conf.DEFINE('HAVE_INOTIFY', 1)
190
191     # Check for kernel change notify support
192     conf.CHECK_CODE('''
193 #ifndef F_NOTIFY
194 #define F_NOTIFY 1026
195 #endif
196 main() {
197         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
198 }''', 'HAVE_KERNEL_CHANGE_NOTIFY', addmain=False, execute=True,
199         headers='fcntl.h signal.h',
200         msg="Checking for kernel change notify support")
201
202     # Check for Linux kernel oplocks
203     conf.CHECK_CODE('''
204 #include <sys/types.h>
205 #include <fcntl.h>
206 #include <signal.h>
207 #ifndef F_NOTIFY
208 #define F_NOTIFY 1026
209 #endif
210 main() {
211         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
212 }''', 'HAVE_KERNEL_OPLOCKS_LINUX', addmain=False, execute=True,
213         msg="Checking for Linux kernel oplocks")
214
215     # Check for IRIX kernel oplock types
216     conf.CHECK_CODE('oplock_stat_t t; t.os_state = OP_REVOKE; t.os_dev = 1; t.os_ino = 1;',
217                     'HAVE_KERNEL_OPLOCKS_IRIX', headers='fcntl.h',
218                     msg="Checking for IRIX kernel oplock types")
219
220     # Check for kernel share modes
221     conf.CHECK_CODE('''
222 #include <sys/types.h>
223 #include <fcntl.h>
224 #include <signal.h>
225 #include <sys/file.h>
226 #ifndef LOCK_MAND
227 #define LOCK_MAND       32
228 #define LOCK_READ       64
229 #endif
230 main() {
231         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
232 }''', 'HAVE_KERNEL_SHARE_MODES', addmain=False, execute=True,
233         msg="Checking for krenel share modes")
234
235     # Check for various members of the stat structure
236     conf.CHECK_TYPES('blksize_t blkcnt_t')
237     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
238                                 headers='sys/stat.h')
239     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blksize', define='HAVE_STAT_ST_BLKSIZE',
240                                 headers='sys/stat.h')
241     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_flags', define='HAVE_STAT_ST_FLAGS',
242                                 headers='sys/types.h sys/stat.h unistd.h')
243
244     # Check for POSIX capability support
245     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
246
247     if "HAVE_SYS_CAPABILITY_H" in conf.env:
248         conf.CHECK_CODE('''
249         cap_t cap;
250         cap_value_t vals[1];
251         if (!(cap = cap_get_proc())) exit(1);
252         vals[0] = CAP_CHOWN;
253         cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
254         cap_set_proc(cap);''',
255                         'HAVE_POSIX_CAPABILITIES', execute=True, lib="cap",
256                         headers='sys/capability.h',
257                         msg="Checking whether POSIX capabilities are available")
258
259     # Check for int16, uint16, int32 and uint32 in rpc/types.h included from
260     # rpc/rpc.h. This is *really* broken but some systems (DEC OSF1) do this.
261     # -- JRA.
262     if conf.CONFIG_SET("HAVE_RPC_RPC_H"):
263         conf.CHECK_TYPE('int16', headers='rpc/rpc.h',
264                         define='HAVE_INT16_FROM_RPC_RPC_H',
265                         msg="Checking for int16 typedef included by rpc/rpc.h")
266         conf.CHECK_CODE('uint16 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
267                         headers='sys/types.h rpc/rpc.h',
268                         msg="Checking for uint16 typedef included by rpc/rpc.h")
269         conf.CHECK_CODE('int32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
270                         headers='sys/types.h rpc/rpc.h',
271                         msg="Checking for int32 typedef included by rpc/rpc.h")
272         conf.CHECK_CODE('uint32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
273                         headers='sys/types.h rpc/rpc.h',
274                         msg="Checking for uint32 typedef included by rpc/rpc.h")
275     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
276                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
277                     msg="Checking for broken nisplus include files")
278
279     # Check if the compiler will optimize out functions
280     conf.CHECK_CODE('''
281 if (0) {
282     this_function_does_not_exist();
283 } else {
284     return 1;
285 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
286         msg="Checking if the compiler will optimize out functions")
287
288     # Check if the compiler supports the LL suffix on long long integers
289     # AIX needs this
290     conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
291                     headers='stdio.h',
292                     msg="Checking for LL suffix on long long integers")
293
294     conf.CHECK_FUNCS('''
295 _acl __acl add_proplist_entry atexit attr_getf attr_list attr_listf
296 attropen attr_remove attr_removef attr_set attr_setf backtrace_symbols
297 bindtextdomain _chdir __chdir chflags chmod _close __close _closedir
298 __closedir closedir64 creat64 crypt16 delproplist devnm dgettext dirfd
299 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
300 extattr_delete_fd extattr_delete_link extattr_get_fd extattr_get_file
301 extattr_get_link extattr_list_fd extattr_list_file extattr_list_link
302 extattr_set_fd extattr_set_file extattr_set_link _facl __facl _fchdir
303 __fchdir fchmod fchown _fcntl __fcntl fcvt fcvtl fdatasync
304 fdelproplist fgetea fgetproplist fgetxattr flistea flistxattr fopen64
305 _fork __fork fremoveea fremovexattr fseek64 fseeko64 fsetea
306 fsetproplist fsetxattr _fstat __fstat fstat64 _fstat64 __fstat64 fsync
307 ftell64 ftello64 ftruncate64 futimens futimes __fxstat getauthuid
308 getcwd _getcwd __getcwd getdents __getdents getdents64 getdirentries
309 getgrent getgrnam getgrouplist getgrset getmntent getpagesize
310 getproplist get_proplist_entry getpwanam getpwent_r getrlimit gettext
311 glob grantpt hstrerror initgroups innetgr
312 inotify_init lgetea lgetxattr listea listxattr llistea llistxattr
313 llseek _llseek __llseek lremoveea lremovexattr _lseek __lseek lseek64
314 lsetea lsetxattr _lstat __lstat lstat64 _lstat64 __lstat64 lutimes
315 __lxstat memalign mknod mknod64 mlock mlockall munlock munlockall
316 _open __open open64 _open64 __open64 _opendir __opendir
317 opendir64 pathconf poll posix_fallocate posix_fallocate64
318 posix_memalign prctl pread _pread __pread pread64 _pread64 __pread64
319 pwrite _pwrite __pwrite pwrite64 _pwrite64
320 __pwrite64 rdchk _read __read _readdir __readdir readdir64 _readdir64
321 __readdir64 removeea removexattr rewinddir64 _seekdir __seekdir
322 seekdir64 select setea setenv setgidx setgroups setlocale setluid
323 setmntent setpgid setpriv setproplist setsid setuidx
324 setxattr shmget shm_open sigaction sigblock sigprocmask sigset
325 sizeof_proplist_entry _stat __stat stat64 _stat64 __stat64 statvfs
326 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctlbyname
327 __sys_llseek syslog _telldir __telldir telldir64 textdomain timegm
328 utimensat vsyslog _write __write __xstat
329 ''')
330
331     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
332
333     # FIXME: these should be tests for features, but the old build system just
334     # checks for OSes.
335     host_os = sys.platform
336     Logs.info("building on %s" % host_os)
337
338     # Python doesn't have case switches... :/
339     # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
340     # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
341
342     conf.SET_TARGET_TYPE('sunacl', 'EMPTY')
343     if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
344         if host_os.rfind('linux') > -1:
345             conf.DEFINE('LINUX', '1')
346         elif host_os.rfind('qnx') > -1:
347             conf.DEFINE('QNX', '1')
348         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
349     elif (host_os.rfind('darwin') > -1):
350         conf.DEFINE('DARWINOS', 1)
351         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
352         conf.ADD_CFLAGS('-fno-common')
353     elif (host_os.rfind('freebsd') > -1):
354         if conf.CHECK_HEADERS('sunacl.h'):
355             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
356             conf.CHECK_FUNCS_IN('acl', 'sunacl')
357         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
358     elif (host_os.rfind('netbsd') > -1):
359         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
360     elif (host_os.rfind('openbsd') > -1):
361         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
362     elif (host_os.rfind('sunos') > -1):
363         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
364     # FIXME: Add more checks here.
365     else:
366         Logs.warn("Unknown host_os '%s', please report this to samba-technical@samba.org" % host_os)
367
368     #FIXME: add more checks
369     if Options.options.with_acl_support:
370         if host_os.rfind('linux') > -1:
371             conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
372             conf.CHECK_FUNCS_IN('getxattr', 'attr')
373             if conf.CHECK_CODE('''
374 acl_t acl;
375 int entry_id;
376 acl_entry_t *entry_p;
377 return acl_get_entry(acl, entry_id, entry_p);
378 ''',
379                         'HAVE_POSIX_ACLS',
380                         headers='sys/types.h sys/acl.h', link=False,
381                         msg="Checking for POSIX ACL support") :
382                 conf.CHECK_CODE('''
383 acl_permset_t permset_d;
384 acl_perm_t perm;
385 return acl_get_perm_np(permset_d, perm);
386 ''',
387                         'HAVE_ACL_GET_PERM_NP',
388                         headers='sys/types.h sys/acl.h', link=True,
389                         msg="Checking whether acl_get_perm_np() is available")
390         else:
391             conf.DEFINE('HAVE_NO_ACLS', 1)
392             conf.SET_TARGET_TYPE('acl', 'EMPTY')
393     else:
394         conf.DEFINE('HAVE_NO_ACLS', 1)
395         conf.SET_TARGET_TYPE('acl', 'EMPTY')
396
397     if conf.CHECK_FUNCS('dirfd'):
398         conf.DEFINE('HAVE_DIRFD_DECL', 1)
399
400     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
401                     'HAVE_STATFS_F_FSID',
402                     msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
403                     headers='sys/types.h sys/statfs.h',
404                     execute=True)
405
406     if conf.CONFIG_SET('HAVE_FALLOCATE'):
407         conf.CHECK_CODE('''
408                 #if defined(HAVE_UNISTD_H)
409                 #include <unistd.h>
410                 #endif
411                 #include <sys/types.h>
412                 #define _GNU_SOURCE
413                 #include <fcntl.h>
414                 #if defined(HAVE_LINUX_FALLOC_H)
415                 #include <linux/falloc.h>
416                 #endif
417                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
418                 'HAVE_LINUX_FALLOCATE',
419                 msg="Checking whether the Linux 'fallocate' function is available")
420     if conf.CONFIG_SET('HAVE_FALLOCATE64'):
421         conf.CHECK_CODE('''
422                 #if defined(HAVE_UNISTD_H)
423                 #include <unistd.h>
424                 #endif
425                 #include <sys/types.h>
426                 #define _GNU_SOURCE
427                 #include <fcntl.h>
428                 #if defined(HAVE_LINUX_FALLOC_H)
429                 #include <linux/falloc.h>
430                 #endif
431                 int ret = fallocate64(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
432                 'HAVE_LINUX_FALLOCATE64',
433                 msg="Checking whether the Linux 'fallocate64' function is available")
434     conf.CHECK_CODE('''
435                 #if defined(HAVE_UNISTD_H)
436                 #include <unistd.h>
437                 #endif
438                 #include <fcntl.h>
439                 ssize_t err = readahead(0,0,0x80000);''',
440                 'HAVE_LINUX_READAHEAD',
441                 msg="Checking whether Linux readahead is available")
442     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
443
444     conf.CHECK_CODE('''
445                 #include <sys/types.h>
446                 #include <sys/socket.h>
447                 struct ucred cred;
448                 socklen_t cred_len;
449                 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
450                 'HAVE_PEERCRED',
451                 msg="Checking whether we can use SO_PEERCRED to get socket credentials")
452
453     conf.CHECK_CODE('''
454                 #if defined(HAVE_LONGLONG) && (defined(HAVE_OFF64_T) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)))
455                 #include <sys/types.h>
456                 #else
457                 __COMPILE_ERROR_
458                 #endif
459                 int i;''',
460                 'HAVE_EXPLICIT_LARGEFILE_SUPPORT',
461                 msg="Checking whether large file support can be enabled")
462
463     if Options.options.with_aio_support:
464         conf.CHECK_FUNCS_IN('aio_read', 'aio')
465         conf.CHECK_FUNCS_IN('aio_read', 'rt')
466         conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
467                         'HAVE_AIO',
468                         msg='Checking for asynchronous io support',
469                         headers='sys/types.h aio.h',
470                         lib='aio rt')
471         conf.CHECK_CODE('struct aiocb64 a; return aio_read64(&a);',
472                         'HAVE_AIO64',
473                         msg='Checking for 64-bit asynchronous io support',
474                         headers='sys/types.h aio.h',
475                         lib='aio rt')
476         if conf.CONFIG_SET('HAVE_AIO64'):
477             conf.DEFINE('HAVE_AIOCB64', '1')
478             conf.DEFINE('WITH_AIO', '1')
479         elif conf.CONFIG_SET('HAVE_AIO'):
480             conf.DEFINE('WITH_AIO', '1')
481         if conf.CONFIG_SET('HAVE_AIO'):
482             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
483             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
484             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')
485             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
486             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
487             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')
488             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')
489         if conf.CONFIG_SET('HAVE_AIO64'):
490             conf.CHECK_CODE('struct aiocb a; return aio_read64(&a);', 'HAVE_AIO_READ64', msg='Checking for aio_read64', headers='aio.h', lib='aio rt')
491             conf.CHECK_CODE('struct aiocb a; return aio_write64(&a);', 'HAVE_AIO_WRITE64', msg='Checking for aio_write64', headers='aio.h', lib='aio rt')
492             conf.CHECK_CODE('struct aiocb a; return aio_fsync64(1, &a);', 'HAVE_AIO_FSYNC64', msg='Checking for aio_fsync64', headers='aio.h', lib='aio rt')
493             conf.CHECK_CODE('struct aiocb a; return aio_return64(&a);', 'HAVE_AIO_RETURN64', msg='Checking for aio_return64', headers='aio.h', lib='aio rt')
494             conf.CHECK_CODE('struct aiocb a; return aio_error64(&a);', 'HAVE_AIO_ERROR64', msg='Checking for aio_error64', headers='aio.h', lib='aio rt')
495             conf.CHECK_CODE('struct aiocb a; return aio_cancel64(1, &a);', 'HAVE_AIO_CANCEL64', msg='Checking for aio_cancel64', headers='aio.h', lib='aio rt')
496             conf.CHECK_CODE('struct aiocb a; return aio_suspend64(&a, 1, NULL);', 'HAVE_AIO_SUSPEND64', msg='Checking for aio_suspend64', headers='aio.h', lib='aio rt')
497         if not conf.CONFIG_SET('HAVE_AIO'):
498             conf.DEFINE('HAVE_NO_AIO', '1')
499     else:
500         conf.DEFINE('HAVE_NO_AIO', '1')
501
502     conf.CHECK_CODE('''
503 struct msghdr msg;
504 union {
505         struct cmsghdr cm;
506         char control[CMSG_SPACE(sizeof(int))];
507 } control_un;
508 msg.msg_control = control_un.control;
509 msg.msg_controllen = sizeof(control_un.control);
510 ''',
511         'HAVE_MSGHDR_MSG_CONTROL',
512         msg='Checking if we can use msg_control for passing file descriptors',
513         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
514     conf.CHECK_CODE('''
515 struct msghdr msg;
516 int fd;
517 msg.msg_acctrights = (caddr_t) &fd;
518 msg.msg_acctrightslen = sizeof(fd);
519 ''',
520         'HAVE_MSGHDR_MSG_ACCTRIGHTS',
521         msg='Checking if we can use msg_acctrights for passing file descriptors',
522         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
523
524     if Options.options.with_winbind:
525         conf.env.build_winbind = True
526         conf.DEFINE('WITH_WINBIND', '1')
527
528     conf.find_program('awk', var='AWK')
529     conf.find_program('perl', var='PERL')
530
531     # Darwin has extra options to xattr-family functions
532     conf.CHECK_CODE('getxattr(0, 0, 0, 0, 0, 0);',
533                     'XATTR_ADD_OPT',
534                     msg="Checking whether xattr interface takes additional options",
535                     headers='sys/types.h attr/xattr.h sys/xattr.h')
536
537     conf.CHECK_HEADERS('asm/types.h')
538
539     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
540                     headers='unistd.h sys/types.h',
541                     msg="Checking for major macro")
542
543     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
544                     headers='unistd.h sys/types.h',
545                     msg="Checking for minor macro")
546
547     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
548                                 headers='unistd.h sys/types.h dirent.h',
549                                 define='HAVE_DIRENT_D_OFF')
550
551     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
552     if conf.CHECK_CFLAGS('-Werror-implicit-function-declaration'):
553         netgrent_cflags = '-Werror-implicit-function-declaration'
554     else:
555         netgrent_cflags = ''
556     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
557                     msg="Checking for setnetgrent prototype",
558                     headers='netdb.h netgroup.h',
559                     cflags=netgrent_cflags)
560     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
561                     msg="Checking for getnetgrent prototype",
562                     headers='netdb.h netgroup.h',
563                     cflags=netgrent_cflags)
564     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
565                     msg="Checking for endnetgrent prototype",
566                     headers='netdb.h netgroup.h',
567                     cflags=netgrent_cflags)
568
569
570     # Look for CUPS
571     if Options.options.with_cups:
572         conf.find_program('cups-config', var='CUPS_CONFIG')
573         if conf.env.CUPS_CONFIG:
574             # we would normally use --libs here, but cups-config incorrectly adds
575             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
576             # of an in-tree heimdal kerberos
577             conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
578                            package="", uselib_store="cups")
579         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
580         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
581         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
582             conf.DEFINE('HAVE_CUPS', '1')
583         else:
584             conf.undefine('HAVE_CUPS')
585             conf.SET_TARGET_TYPE('cups', 'EMPTY')
586     else:
587         # define an empty subsystem for cups, to allow it to be used as an empty dependency
588         conf.SET_TARGET_TYPE('cups', 'EMPTY')
589
590     if Options.options.with_iprint:
591         if conf.CONFIG_SET('HAVE_CUPS'):
592             conf.DEFINE('HAVE_IPRINT', '1')
593         else:
594             Logs.warn("--enable-iprint=yes but cups support not sufficient")
595     if Options.options.with_syslog:
596         conf.DEFINE('WITH_SYSLOG', '1')
597     if Options.options.with_automount:
598         conf.DEFINE('WITH_AUTOMOUNT', '1')
599
600     # Check for LDAP
601     if Options.options.with_ldap:
602         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
603         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
604         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
605         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
606
607         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
608         # for the samba logs
609         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
610                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
611
612         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
613         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
614
615         # Check if ldap_set_rebind_proc() takes three arguments
616         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
617                            'LDAP_SET_REBIND_PROC_ARGS',
618                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
619                            headers='ldap.h lber.h', link=False):
620             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
621         else:
622             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
623
624         # last but not least, if ldap_init() exists, we want to use ldap
625         if conf.CONFIG_SET('HAVE_LDAP_INIT'):
626             conf.DEFINE('HAVE_LDAP', '1')
627             conf.DEFINE('LDAP_DEPRECATED', '1')
628             conf.env['HAVE_LDAP'] = '1'
629             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
630             # SASL wrapping hooks
631             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
632                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
633                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
634     else:
635         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
636         conf.SET_TARGET_TYPE('lber', 'EMPTY')
637
638     # Check for kerberos
639     have_gssapi=False
640     if Options.options.with_krb5 and not conf.env.toplevel_build:
641         Logs.info("Looking for kerberos features")
642         conf.find_program('krb5-config', var='KRB5_CONFIG')
643         if conf.env.KRB5_CONFIG:
644             conf.check_cfg(path="krb5-config", args="--cflags --libs",
645                        package="gssapi", uselib_store="krb5")
646         conf.CHECK_HEADERS('krb5.h krb5/locate_plugin.h', lib='krb5')
647         conf.CHECK_HEADERS('gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h gssapi/gssapi_ext.h gssapi/gssapi_krb5.h com_err.h', lib='krb5')
648
649         if conf.CONFIG_SET('HAVE_KRB5_LOCATE_PLUGIN_H'):
650             conf.env['WINBIND_KRB5_LOCATOR'] = 'bin/winbind_krb5_locator.so'
651
652         conf.CHECK_FUNCS_IN('_et_list', 'com_err')
653         conf.CHECK_FUNCS_IN('krb5_encrypt_data', 'k5crypto')
654         conf.CHECK_FUNCS_IN('des_set_key','crypto')
655         conf.CHECK_FUNCS_IN('copy_Authenticator', 'asn1')
656         conf.CHECK_FUNCS_IN('roken_getaddrinfo_hostspec', 'roken')
657         if conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi') or \
658            conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi_krb5'):
659             have_gssapi=True
660         conf.CHECK_FUNCS_IN('gss_wrap_iov gss_krb5_import_cred gss_get_name_attribute gss_mech_krb5 gss_oid_equal gss_inquire_sec_context_by_oid', 'gssapi gssapi_krb5 krb5')
661         conf.CHECK_FUNCS_IN('krb5_mk_req_extended krb5_kt_compare', 'krb5')
662         conf.CHECK_FUNCS('''
663 krb5_set_real_time krb5_set_default_in_tkt_etypes krb5_set_default_tgs_enctypes
664 krb5_set_default_tgs_ktypes krb5_principal2salt krb5_use_enctype
665 krb5_string_to_key krb5_get_pw_salt krb5_string_to_key_salt krb5_auth_con_setkey
666 krb5_auth_con_setuseruserkey krb5_locate_kdc krb5_get_permitted_enctypes
667 krb5_get_default_in_tkt_etypes krb5_free_data_contents
668 krb5_principal_get_comp_string krb5_free_unparsed_name
669 krb5_free_keytab_entry_contents krb5_kt_free_entry krb5_krbhst_init
670 krb5_krbhst_get_addrinfo krb5_c_enctype_compare krb5_enctypes_compatible_keys
671 krb5_crypto_init krb5_crypto_destroy krb5_decode_ap_req free_AP_REQ
672 krb5_verify_checksum krb5_c_verify_checksum krb5_principal_compare_any_realm
673 krb5_parse_name_norealm krb5_princ_size krb5_get_init_creds_opt_set_pac_request
674 krb5_get_renewed_creds krb5_get_kdc_cred krb5_free_error_contents
675 initialize_krb5_error_table krb5_get_init_creds_opt_alloc
676 krb5_get_init_creds_opt_free krb5_get_init_creds_opt_get_error
677 krb5_enctype_to_string krb5_fwd_tgt_creds krb5_auth_con_set_req_cksumtype
678 krb5_get_creds_opt_alloc krb5_get_creds_opt_set_impersonate krb5_get_creds
679 krb5_get_credentials_for_user krb5_get_host_realm krb5_free_host_realm''',
680                          lib='krb5 k5crypto')
681         conf.CHECK_DECLS('''krb5_get_credentials_for_user
682                             krb5_auth_con_set_req_cksumtype''',
683                             headers='krb5.h', always=True)
684         conf.CHECK_VARIABLE('AP_OPTS_USE_SUBKEY', headers='krb5.h')
685         conf.CHECK_VARIABLE('KV5M_KEYTAB', headers='krb5.h')
686         conf.CHECK_VARIABLE('KRB5_KU_OTHER_CKSUM', headers='krb5.h')
687         conf.CHECK_VARIABLE('KRB5_KEYUSAGE_APP_DATA_CKSUM', headers='krb5.h')
688         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'key', headers='krb5.h',
689                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEY')
690         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'keyblock', headers='krb5.h',
691                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK')
692         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'magic', headers='krb5.h',
693                                     define='HAVE_MAGIC_IN_KRB5_ADDRESS')
694         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'addrtype', headers='krb5.h',
695                                     define='HAVE_ADDRTYPE_IN_KRB5_ADDRESS')
696         conf.CHECK_STRUCTURE_MEMBER('krb5_ticket', 'enc_part2', headers='krb5.h',
697                                     define='HAVE_KRB5_TKT_ENC_PART2')
698         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'keyblock', headers='krb5.h',
699                                     define='HAVE_KRB5_KEYBLOCK_IN_CREDS')
700         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'session', headers='krb5.h',
701                                     define='HAVE_KRB5_SESSION_IN_CREDS')
702         conf.CHECK_STRUCTURE_MEMBER('krb5_ap_req', 'ticket', headers='krb5.h',
703                                     define='HAVE_TICKET_POINTER_IN_KRB5_AP_REQ')
704
705         conf.CHECK_TYPE('krb5_encrypt_block', headers='krb5.h')
706
707         conf.CHECK_CODE('''
708 krb5_ticket ticket;
709 krb5_kvno kvno;
710 krb5_enctype enctype;
711 enctype = ticket.enc_part.enctype;
712 kvno = ticket.enc_part.kvno;
713 ''',
714                         'KRB5_TICKET_HAS_KEYINFO',
715                         headers='krb5.h', link=False,
716                         msg="Checking whether the krb5_ticket structure contains the kvno and enctype")
717         conf.CHECK_CODE('''
718 krb5_context ctx;
719 krb5_get_init_creds_opt *opt = NULL;
720 krb5_get_init_creds_opt_free(ctx, opt);
721 ''',
722                         'KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT',
723                         headers='krb5.h', link=False,
724                         msg="Checking whether krb5_get_init_creds_opt_free takes a context argument")
725         conf.CHECK_CODE('krb5_mk_error(0,0,0)',
726                         'HAVE_SHORT_KRB5_MK_ERROR_INTERFACE',
727                         headers='krb5.h', link=False,
728                         msg="Checking whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal")
729         conf.CHECK_CODE('''
730 const krb5_data *pkdata;
731 krb5_context context;
732 krb5_principal principal;
733 pkdata = krb5_princ_component(context, principal, 0);
734 ''',
735                         'HAVE_KRB5_PRINC_COMPONENT',
736                         headers='krb5.h', lib='krb5',
737                         msg="Checking whether krb5_princ_component is available")
738
739         conf.CHECK_CODE('''
740 int main(void) {
741 char buf[256];
742 krb5_enctype_to_string(1, buf, 256);
743 return 0;
744 }''',
745                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG',
746                         headers='krb5.h', lib='krb5 k5crypto',
747                         addmain=False, cflags='-Werror',
748                         msg="Checking whether krb5_enctype_to_string takes size_t argument")
749
750         conf.CHECK_CODE('''
751 int main(void) {
752 krb5_context context = NULL;
753 char *str = NULL;
754 krb5_enctype_to_string(context, 1, &str);
755 if (str) free (str);
756 return 0;
757 }''',
758                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG',
759                         headers='krb5.h stdlib.h', lib='krb5',
760                         addmain=False, cflags='-Werror',
761                         msg="Checking whether krb5_enctype_to_string takes krb5_context argument")
762         conf.CHECK_CODE('''
763 int main(void) {
764 krb5_context ctx = NULL;
765 krb5_principal princ = NULL;
766 const char *str = krb5_princ_realm(ctx, princ)->data;
767 return 0;
768 }''',
769                         'HAVE_KRB5_PRINC_REALM',
770                         headers='krb5.h', lib='krb5',
771                         addmain=False,
772                         msg="Checking whether the macro krb5_princ_realm is defined")
773         conf.CHECK_CODE('''
774 int main(void) {
775     krb5_context context;
776     krb5_principal principal;
777     const char *realm; realm = krb5_principal_get_realm(context, principal);
778     return 0;
779 }''',
780                         'HAVE_KRB5_PRINCIPAL_GET_REALM',
781                         headers='krb5.h', lib='krb5',
782                         addmain=False,
783                         msg="Checking whether krb5_principal_get_realm is defined")
784         if conf.CHECK_CODE('''krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);''',
785                         'KRB5_VERIFY_CHECKSUM_ARGS',
786                         headers='krb5.h', lib='krb5',
787                         msg="Checking whether krb5_verify_checksum takes 7 arguments"):
788             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '7')
789         else:
790             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '6')
791
792         conf.CHECK_CODE('''
793 krb5_enctype enctype;
794 enctype = ENCTYPE_ARCFOUR_HMAC_MD5;
795 ''',
796             '_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5',
797             headers='krb5.h', lib='krb5',
798             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available");
799         conf.CHECK_CODE('''
800 krb5_keytype keytype;
801 keytype = KEYTYPE_ARCFOUR_56;
802 ''',
803             '_HAVE_KEYTYPE_ARCFOUR_56',
804             headers='krb5.h', lib='krb5',
805             msg="Checking whether the HAVE_KEYTYPE_ARCFOUR_56 key type definition is available");
806         if conf.CONFIG_SET('_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and conf.CONFIG_SET('_HAVE_KEYTYPE_ARCFOUR_56'):
807             conf.DEFINE('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5', '1')
808
809         conf.CHECK_CODE('''
810 krb5_enctype enctype;
811 enctype = ENCTYPE_ARCFOUR_HMAC;
812 ''',
813             'HAVE_ENCTYPE_ARCFOUR_HMAC',
814             headers='krb5.h', lib='krb5',
815             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC key type definition is available");
816
817         conf.CHECK_CODE('''
818 krb5_context context;
819 krb5_keytab keytab;
820 krb5_init_context(&context);
821 return krb5_kt_resolve(context, "WRFILE:api", &keytab);
822 ''',
823             'HAVE_WRFILE_KEYTAB',
824             headers='krb5.h', lib='krb5', execute=True,
825             msg="Checking whether the WRFILE:-keytab is supported");
826
827         # Check for KRB5_DEPRECATED handling
828         conf.CHECK_CODE('''#define KRB5_DEPRECATED 1
829 #include <krb5.h>''',
830         'HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER', addmain=False,
831         link=False,
832         msg="Checking for KRB5_DEPRECATED define taking an identifier")
833     elif not conf.env.toplevel_build:
834         conf.SET_TARGET_TYPE('krb5', 'EMPTY')
835         conf.SET_TARGET_TYPE('gssapi', 'EMPTY')
836         conf.SET_TARGET_TYPE('gssapi_krb5', 'EMPTY')
837         conf.SET_TARGET_TYPE('com_err', 'EMPTY')
838         conf.SET_TARGET_TYPE('k5crypto', 'EMPTY')
839
840     if Options.options.with_ads:
841         use_ads=True
842         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
843            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
844             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
845             use_ads=False
846         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
847             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
848             use_ads=False
849         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
850            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
851             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
852             use_ads=False
853         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
854            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
855             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
856             use_ads=False
857         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
858            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
859             Logs.warn("no KT_FREE_FUNCTION detected")
860             use_ads=False
861         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM') and \
862            not conf.CONFIG_SET('HAVE_KRB5_VERIFY_CHECKSUM'):
863             Logs.warn("no KRB5_VERIFY_CHECKSUM_FUNCTION detected")
864             use_ads=False
865         if not conf.CONFIG_SET('KRB5_TICKET_HAS_KEYINFO'):
866             # We only need the following functions if we can't get the enctype
867             # and kvno out of the ticket directly (ie. on Heimdal).
868             if not conf.CONFIG_SET('HAVE_FREE_AP_REQ'):
869                 Logs.warn("no KRB5_AP_REQ_FREE_FUNCTION detected")
870                 use_ads=False
871             if not conf.CONFIG_SET('HAVE_KRB5_DECODE_AP_REQ'):
872                 Logs.warn("no KRB5_AP_REQ_DECODING_FUNCTION detected")
873                 use_ads=False
874         if use_ads:
875             conf.DEFINE('WITH_ADS', '1')
876             conf.DEFINE('HAVE_KRB5', '1')
877             if have_gssapi:
878                 conf.DEFINE('HAVE_GSSAPI', '1')
879             if conf.CONFIG_SET('HAVE_LDAP'):
880                 conf.env['HAVE_ADS'] = '1'
881         else:
882             Logs.warn("krb5 libs don't have all features required for Active Directory support")
883             conf.undefine('HAVE_KRB5_H')
884             conf.undefine('HAVE_GSSAPI_H')
885             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
886             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
887
888     if Options.options.with_utmp:
889         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
890         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
891                                     define='HAVE_UT_UT_NAME')
892         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
893                                     define='HAVE_UT_UT_USER')
894         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
895                                     define='HAVE_UT_UT_ID')
896         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
897                                     define='HAVE_UT_UT_HOST')
898         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
899                                     define='HAVE_UT_UT_TIME')
900         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
901                                     define='HAVE_UT_UT_TV')
902         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
903                                     define='HAVE_UT_UT_TYPE')
904         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
905                                     define='HAVE_UT_UT_PID')
906         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
907                                     define='HAVE_UT_UT_EXIT')
908         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
909                                     define='HAVE_UT_UT_ADDR_V6')
910         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
911                                     define='HAVE_UT_UT_ADDR')
912         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
913                                     define='HAVE_UX_UT_SYSLEN')
914         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
915                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
916                         msg="Checking whether pututline returns pointer")
917         conf.DEFINE('WITH_UTMP', 1)
918
919     if Options.options.with_avahi:
920         conf.env.with_avahi = True
921         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
922         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
923         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
924         if conf.env.with_avahi:
925             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
926     else:
927         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
928         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
929
930     if Options.options.with_iconv:
931         conf.env.with_iconv = True
932         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
933             conf.env.with_iconv = False
934         if conf.env.with_iconv:
935             conf.DEFINE('HAVE_ICONV', 1)
936
937     if Options.options.with_pam:
938         use_pam=True
939         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
940         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
941             Logs.warn("--with-pam=yes but pam_appl.h not found")
942             use_pam=False
943         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
944         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
945         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
946             Logs.warn("--with-pam=yes but pam_modules.h not found")
947             use_pam=False
948         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
949         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
950         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
951         conf.CHECK_CODE('''
952 #if defined(HAVE_SECURITY_PAM_APPL_H)
953 #include <security/pam_appl.h>
954 #elif defined(HAVE_PAM_PAM_APPL_H)
955 #include <pam/pam_appl.h>
956 #endif
957 pam_set_item(0, PAM_RHOST, 0);
958 ''',
959             'HAVE_PAM_RHOST',
960             lib='pam',
961             msg="Checking whether PAM_RHOST is available");
962         conf.CHECK_CODE('''
963 #if defined(HAVE_SECURITY_PAM_APPL_H)
964 #include <security/pam_appl.h>
965 #elif defined(HAVE_PAM_PAM_APPL_H)
966 #include <pam/pam_appl.h>
967 #endif
968 pam_set_item(0, PAM_TTY, 0);
969 ''',
970             'HAVE_PAM_TTY',
971             lib='pam',
972             msg="Checking whether PAM_TTY is available");
973         conf.CHECK_CODE('''
974 #if (!defined(LINUX))
975
976 #define PAM_EXTERN extern
977 #if defined(HAVE_SECURITY_PAM_APPL_H)
978 #include <security/pam_appl.h>
979 #elif defined(HAVE_PAM_PAM_APPL_H)
980 #include <pam/pam_appl.h>
981 #endif
982
983 #endif
984
985 #if defined(HAVE_SECURITY_PAM_MODULES_H)
986 #include <security/pam_modules.h>
987 #elif defined(HAVE_PAM_PAM_MODULES_H)
988 #include <pam/pam_modules.h>
989 #endif
990
991 #if defined(HAVE_SECURITY__PAM_MACROS_H)
992 #include <security/_pam_macros.h>
993 #elif defined(HAVE_PAM__PAM_MACROS_H)
994 #include <pam/_pam_macros.h>
995 #endif
996
997 #ifdef HAVE_SECURITY_PAM_EXT_H
998 #include <security/pam_ext.h>
999 #endif
1000
1001 int i; i = PAM_RADIO_TYPE;
1002 ''',
1003             'HAVE_PAM_RADIO_TYPE',
1004             lib='pam',
1005             msg="Checking whether PAM_RADIO_TYPE is available");
1006         if use_pam:
1007             conf.DEFINE('WITH_PAM', 1)
1008             conf.DEFINE('WITH_PAM_MODULES', 1)
1009
1010     seteuid = False
1011     if not seteuid:
1012         seteuid = conf.CHECK_CODE('''
1013                                 #define AUTOCONF_TEST 1
1014                                 #define USE_SETREUID 1
1015                                 #include "./lib/util_sec.c"
1016                                 ''',
1017                                 'USE_SETREUID',
1018                                 addmain=False,
1019                                 execute=True,
1020                                 msg="Checking whether setreuid is available")
1021     if not seteuid:
1022         seteuid = conf.CHECK_CODE('''
1023                                 #define AUTOCONF_TEST 1
1024                                 #define USE_SETRESUID 1
1025                                 #include "./lib/util_sec.c"
1026                                 ''',
1027                                 'USE_SETRESUID',
1028                                 addmain=False,
1029                                 execute=True,
1030                                 msg="Checking whether setresuid is available")
1031     if not seteuid:
1032         seteuid = conf.CHECK_CODE('''
1033                                 #define AUTOCONF_TEST 1
1034                                 #define USE_SETEUID 1
1035                                 #include "./lib/util_sec.c"
1036                                 ''',
1037                                 'USE_SETEUID',
1038                                 addmain=False,
1039                                 execute=True,
1040                                 msg="Checking whether seteuid is available")
1041     if not seteuid:
1042         seteuid = conf.CHECK_CODE('''
1043                                 #define AUTOCONF_TEST 1
1044                                 #define USE_SETUIDX 1
1045                                 #include "./lib/util_sec.c"
1046                                 ''',
1047                                 'USE_SETUIDX',
1048                                 addmain=False,
1049                                 execute=True,
1050                                 mandatory=True,
1051                                 msg="Checking whether setuidx is available")
1052     if Options.options.with_dnsupdate:
1053         conf.CHECK_HEADERS('uuid/uuid.h')
1054         conf.CHECK_FUNCS_IN('uuid_generate', 'uuid')
1055         if not conf.CONFIG_SET('HAVE_UUID_UUID_H') and not conf.CONFIG_SET('HAVE_UUID_GENERATE'):
1056             Logs.warn("--with-dnsupdate=yes but uuid support not sufficient")
1057         elif not conf.CONFIG_SET('HAVE_GSSAPI'):
1058             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
1059         else:
1060             conf.DEFINE('WITH_DNS_UPDATES', 1)
1061     else:
1062         conf.SET_TARGET_TYPE('uuid', 'EMPTY')
1063     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
1064     if Options.options.developer:
1065         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
1066             conf.DEFINE('VALGRIND', '1')
1067
1068     if conf.CHECK_CODE('''
1069 #include <bits/sockaddr.h>
1070 #include <linux/netlink.h>
1071 ''',
1072                 'HAVE_LINUX_NETLINK_H',
1073                 msg="Checking whether Linux netlink is available"):
1074         conf.CHECK_CODE('''
1075 #include <bits/sockaddr.h>
1076 #include <linux/netlink.h>
1077 #include <linux/rtnetlink.h>
1078 ''',
1079                 'HAVE_LINUX_RTNETLINK_H',
1080                 msg='Checking whether Linux rtnetlink is available')
1081     if conf.CHECK_TYPE('struct dirent64', headers='sys/types.h dirent.h') and conf.CONFIG_SET('HAVE_READDIR64'):
1082         conf.DEFINE('HAVE_STRUCT_DIRENT64', '1')
1083     else:
1084         conf.undefine('HAVE_STRUCT_DIRENT64')
1085
1086     conf.CHECK_CODE('''
1087 #include "../tests/fcntl_lock.c"
1088 ''',
1089                 'HAVE_FCNTL_LOCK',
1090                 addmain=False,
1091                 execute=True,
1092                 msg='Checking whether fcntl locking is available')
1093
1094     conf.CHECK_CODE('''
1095 #include "../tests/fcntl_lock64.c"
1096 ''',
1097                 'HAVE_BROKEN_FCNTL64_LOCKS',
1098                 addmain=False,
1099                 execute=True,
1100                 msg='Checking whether fcntl64 locks are broken')
1101
1102     if not conf.CONFIG_SET('HAVE_BROKEN_FCNTL64_LOCKS'):
1103         conf.CHECK_CODE('''
1104 #if defined(HAVE_UNISTD_H)
1105 #include <unistd.h>
1106 #endif
1107 #include <stdio.h>
1108 #include <stdlib.h>
1109
1110 #ifdef HAVE_FCNTL_H
1111 #include <fcntl.h>
1112 #endif
1113
1114 #ifdef HAVE_SYS_FCNTL_H
1115 #include <sys/fcntl.h>
1116 #endif
1117 main() { struct flock64 fl64;
1118 #if defined(F_SETLKW64) && defined(F_SETLK64) && defined(F_GETLK64)
1119 exit(0);
1120 #else
1121 exit(1);
1122 #endif
1123 }
1124 ''',
1125                 'HAVE_STRUCT_FLOCK64',
1126                 addmain=False,
1127                 execute=True,
1128                 msg="Checking whether the flock64 struct is available")
1129
1130     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
1131                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
1132     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
1133                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
1134     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
1135                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
1136     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
1137                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
1138     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
1139                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
1140     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
1141        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
1142        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
1143        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
1144        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
1145         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
1146
1147     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
1148     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
1149                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
1150     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
1151                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
1152     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
1153                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
1154
1155     conf.CHECK_CODE('''
1156 #if defined(HAVE_UNISTD_H)
1157 #include <unistd.h>
1158 #endif
1159 #include <fcntl.h>],
1160 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
1161 ''',
1162                 'HAVE_POSIX_FADVISE',
1163                 msg='Checking whether posix_fadvise is available')
1164
1165     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
1166         conf.CHECK_CODE('''
1167                         #include <unistd.h>
1168                         return sysconf(%s) == -1 ? 1 : 0;
1169                         ''' % v,
1170                         'SYSCONF%s' % v,
1171                         msg='Checking whether sysconf(%s) is available' % v)
1172
1173     conf.CHECK_DECLS('__NR_inotify_init', reverse=True, headers='asm/unistd.h')
1174
1175     conf.CHECK_CODE('''
1176 #include <sys/syscall.h>
1177 #include <unistd.h>
1178 syscall(SYS_initgroups, 16, NULL, NULL, 0);
1179                     ''',
1180                     'HAVE_DARWIN_INITGROUPS',
1181                     msg='Checking whether to use the Darwin-specific initgroups system call')
1182
1183     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
1184                     'HAVE_UTIMBUF',
1185                     headers='sys/types.h utime.h',
1186                     msg='Checking whether struct utimbuf is available')
1187
1188     if conf.CHECK_CODE('''struct sigevent s;''',
1189                     'HAVE_STRUCT_SIGEVENT',
1190                     headers='sys/types.h stdlib.h stddef.h signal.h',
1191                     msg='Checking whether we have the struct sigevent'):
1192         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
1193                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
1194                                     headers='signal.h');
1195         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
1196                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
1197                                     headers='signal.h');
1198
1199     if os.path.exists('/proc/sys/kernel/core_pattern'):
1200         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
1201
1202     if conf.CHECK_CODE('''
1203 #include <time.h>
1204 main() {
1205         struct tm *tm;
1206         if (sizeof(time_t) == 8) {
1207                 time_t max_time = 0x7fffffffffffffffll;
1208                 tm = gmtime(&max_time);
1209                 /* This should fail with 32-bit tm_year. */
1210                 if (tm == NULL) {
1211                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
1212                         max_time = 67768036191676799ll;
1213                         tm = gmtime(&max_time);
1214                         if (tm) {
1215                                 exit(0);
1216                         }
1217                 }
1218         }
1219         exit(1);
1220 }''',
1221         '__TIME_T_MAX',
1222         addmain=False,
1223         execute=True,
1224         msg="Checking for the maximum value of the 'time_t' type"):
1225             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
1226
1227     conf.CHECK_CODE('''
1228 #if defined(HAVE_UNISTD_H)
1229 #include <unistd.h>
1230 #endif
1231 #include <sys/types.h>
1232 main() { dev_t dev = makedev(1,2); return 0; }
1233 ''',
1234         'HAVE_MAKEDEV',
1235         addmain=False,
1236         msg='Checking whether the macro for makedev is available')
1237
1238     conf.CHECK_CODE('''
1239 #include <stdio.h>
1240 #include <limits.h>
1241 #include <signal.h>
1242
1243 void exit_on_core(int ignored) {
1244         exit(1);
1245 }
1246
1247 main() {
1248         char *newpath;
1249         signal(SIGSEGV, exit_on_core);
1250         newpath = realpath("/tmp", NULL);
1251         exit((newpath != NULL) ? 0 : 1);
1252 }
1253 ''',
1254         'REALPATH_TAKES_NULL',
1255         addmain=False,
1256         execute=True,
1257         msg='Checking whether the realpath function allows a NULL argument')
1258
1259     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
1260                     'HAVE_FTRUNCATE_EXTEND',
1261                     msg='Checking for ftruncate extend',
1262                     addmain=False,
1263                     execute=True)
1264     if os.getenv('RUN_FROM_BUILD_FARM'):
1265         Logs.info("enabling buildfarm hacks")
1266         conf.DEFINE('ENABLE_BUILD_FARM_HACKS', '1')
1267
1268     if Options.options.with_sendfile_support:
1269         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):
1270             conf.CHECK_CODE('''
1271                             int tofd, fromfd;
1272                             off64_t offset;
1273                             size_t total;
1274                             ssize_t nwritten = sendfile64(tofd, fromfd, &offset, total);
1275                             ''',
1276                             '_HAVE_SENDFILE64',
1277                             headers='sys/sendfile',
1278                             msg='Checking for linux sendfile64 support')
1279             conf.CHECK_CODE('''
1280                             int tofd, fromfd;
1281                             off_t offset;
1282                             size_t total;
1283                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1284                             ''',
1285                             '_HAVE_SENDFILE',
1286                             headers='sys/sendfile',
1287                             msg='Checking for linux sendfile support')
1288
1289             # Try and cope with broken Linux sendfile....
1290             conf.CHECK_CODE('''#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
1291                             #undef _FILE_OFFSET_BITS
1292                             #endif
1293                             #include <sys/sendfile.h>
1294                             int tofd, fromfd;
1295                             off_t offset;
1296                             size_t total;
1297                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1298                             ''',
1299                             '_HAVE_BROKEN_LINUX_SENDFILE',
1300                             msg='Checking for broken linux sendfile support')
1301             if conf.CONFIG_SET('_HAVE_SENDFILE64'):
1302                 conf.DEFINE('HAVE_SENDFILE64', '1')
1303                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1304                 conf.DEFINE('WITH_SENDFILE', '1')
1305             elif conf.CONFIG_SET('_HAVE_SENDFILE'):
1306                 conf.DEFINE('HAVE_SENDFILE', '1')
1307                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1308                 conf.DEFINE('WITH_SENDFILE', '1')
1309             elif conf.CONFIG_SET('_HAVE_BROKEN_LINUX_SENDFILE'):
1310                 conf.DEFINE('LINUX_BROKEN_SENDFILE_API', '1')
1311                 conf.DEFINE('WITH_SENDFILE', '1')
1312         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
1313             conf.CHECK_CODE('''
1314                             #include <sys/types.h>
1315                             #include <unistd.h>
1316                             #include <sys/socket.h>
1317                             #include <sys/uio.h>
1318                             int fromfd, tofd, ret, total=0;
1319                             off_t offset, nwritten;
1320                             struct sf_hdtr hdr;
1321                             struct iovec hdtrl;
1322                             hdr.headers = &hdtrl;
1323                             hdr.hdr_cnt = 1;
1324                             hdr.trailers = NULL;
1325                             hdr.trl_cnt = 0;
1326                             hdtrl.iov_base = NULL;
1327                             hdtrl.iov_len = 0;
1328                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
1329                             ''',
1330                             '_HAVE_SENDFILE',
1331                             msg='Checking for freebsd sendfile support')
1332             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1333                 conf.DEFINE('HAVE_SENDFILE', '1')
1334                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
1335                 conf.DEFINE('WITH_SENDFILE', '1')
1336         elif (host_os.rfind('hpux') > -1):
1337             conf.CHECK_CODE('''
1338                             #include <sys/socket.h>
1339                             #include <sys/uio.h>
1340                             int fromfd, tofd;
1341                             size_t total=0;
1342                             struct iovec hdtrl[2];
1343                             ssize_t nwritten;
1344                             off64_t offset;
1345                             hdtrl[0].iov_base = 0;
1346                             hdtrl[0].iov_len = 0;
1347                             nwritten = sendfile64(tofd, fromfd, offset, total, &hdtrl[0], 0);
1348                             ''',
1349                             '_HAVE_SENDFILE64',
1350                             msg='Checking for hpux sendfile64 support')
1351             conf.CHECK_CODE('''
1352                             #include <sys/socket.h>
1353                             #include <sys/uio.h>
1354                             int fromfd, tofd;
1355                             size_t total=0;
1356                             struct iovec hdtrl[2];
1357                             ssize_t nwritten;
1358                             off_t offset;
1359                             hdtrl[0].iov_base = 0;
1360                             hdtrl[0].iov_len = 0;
1361                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1362                             ''',
1363                             '_HAVE_SENDFILE',
1364                             msg='Checking for hpux sendfile support')
1365             if conf.CONFIG_SET('_HAVE_SENDFILE64'):
1366                 conf.DEFINE('HAVE_SENDFILE64', '1')
1367                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1368                 conf.DEFINE('WITH_SENDFILE', '1')
1369             elif conf.CONFIG_SET('_HAVE_SENDFILE'):
1370                 conf.DEFINE('HAVE_SENDFILE', '1')
1371                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1372                 conf.DEFINE('WITH_SENDFILE', '1')
1373         elif (host_os.rfind('solaris') > -1):
1374             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1375             conf.CHECK_CODE('''
1376                             #include <sys/sendfile.h>
1377                             int sfvcnt;
1378                             size_t xferred;
1379                             struct sendfilevec vec[2];
1380                             ssize_t nwritten;
1381                             int tofd;
1382                             sfvcnt = 2;
1383                             vec[0].sfv_fd = SFV_FD_SELF;
1384                             vec[0].sfv_flag = 0;
1385                             vec[0].sfv_off = 0;
1386                             vec[0].sfv_len = 0;
1387                             vec[1].sfv_fd = 0;
1388                             vec[1].sfv_flag = 0;
1389                             vec[1].sfv_off = 0;
1390                             vec[1].sfv_len = 0;
1391                             nwritten = sendfilev64(tofd, vec, sfvcnt, &xferred);
1392                             ''',
1393                             '_HAVE_SENDFILEV64',
1394                             msg='Checking for solaris sendfilev64 support')
1395             conf.CHECK_CODE('''
1396                             #include <sys/sendfile.h>,
1397                             int sfvcnt;
1398                             size_t xferred;
1399                             struct sendfilevec vec[2];
1400                             ssize_t nwritten;
1401                             int tofd;
1402                             sfvcnt = 2;
1403                             vec[0].sfv_fd = SFV_FD_SELF;
1404                             vec[0].sfv_flag = 0;
1405                             vec[0].sfv_off = 0;
1406                             vec[0].sfv_len = 0;
1407                             vec[1].sfv_fd = 0;
1408                             vec[1].sfv_flag = 0;
1409                             vec[1].sfv_off = 0;
1410                             vec[1].sfv_len = 0;
1411                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1412                             ''',
1413                             '_HAVE_SENDFILEV',
1414                             msg='Checking for solaris sendfilev support')
1415             if conf.CONFIG_SET('_HAVE_SENDFILEV64'):
1416                 conf.DEFINE('HAVE_SENDFILEV64', '1')
1417                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1418                 conf.DEFINE('WITH_SENDFILE', '1')
1419             elif conf.CONFIG_SET('_HAVE_SENDFILEV'):
1420                 conf.DEFINE('HAVE_SENDFILEV', '1')
1421                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1422                 conf.DEFINE('WITH_SENDFILE', '1')
1423         elif (host_os.rfind('aix') > -1):
1424             conf.CHECK_CODE('''
1425                             #include <sys/socket.h>
1426                             int fromfd, tofd;
1427                             size_t total=0;
1428                             struct sf_parms hdtrl;
1429                             ssize_t nwritten;
1430                             off64_t offset;
1431                             hdtrl.header_data = 0;
1432                             hdtrl.header_length = 0;
1433                             hdtrl.file_descriptor = fromfd;
1434                             hdtrl.file_offset = 0;
1435                             hdtrl.file_bytes = 0;
1436                             hdtrl.trailer_data = 0;
1437                             hdtrl.trailer_length = 0;
1438                             nwritten = send_file(&tofd, &hdtrl, 0);
1439                             ''',
1440                             '_HAVE_SENDFILE',
1441                             msg='Checking for AIX send_file support')
1442             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1443                 conf.DEFINE('HAVE_SENDFILE', '1')
1444                 conf.DEFINE('AIX_SENDFILE_API', '1')
1445                 conf.DEFINE('WITH_SENDFILE', '1')
1446
1447     # Check for getcwd allowing a NULL arg.
1448     conf.CHECK_CODE('''
1449 #include <unistd.h>
1450 main() {
1451         char *s = getcwd(NULL,0);
1452         exit(s != NULL ?  0 : 1);
1453 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1454         msg="getcwd takes a NULL argument")
1455
1456
1457     conf.CHECK_CODE('''enum TDB_ERROR err = TDB_ERR_NESTING''',
1458                     'HAVE_TDB_ERR_NESTING',
1459                     headers='tdb.h',
1460                     msg='Checking whether we have TDB_ERR_NESTING')
1461
1462     # UnixWare 7.x has its getspnam in -lgen
1463     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1464     conf.CHECK_FUNCS_IN('getspnam', 'security')
1465     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1466
1467     if Options.options.with_quotas:
1468         # For quotas on Veritas VxFS filesystems
1469         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1470         # For quotas on Linux XFS filesystems
1471         conf.CHECK_HEADERS('linux/dqblk_xfs.h')
1472         # For sys/quota.h and linux/quota.h
1473         conf.CHECK_HEADERS('sys/quota.h')
1474
1475
1476     #
1477     # checking for clustering extensions (CTDB)
1478     #
1479     if not Options.options.with_cluster_support:
1480         have_cluster_support = False
1481
1482     else:
1483
1484         if Options.options.ctdb_dir:
1485             conf.ADD_EXTRA_INCLUDES(Options.options.ctdb_dir + '/include')
1486
1487         srcdir = os.path.realpath(conf.srcdir)
1488         if 'EXTRA_INCLUDES' in conf.env:
1489             includes = ' '.join(conf.env['EXTRA_INCLUDES']).replace('#', srcdir + '/')
1490         else:
1491             includes = ''
1492
1493         have_cluster_support = True
1494         ctdb_broken = ""
1495
1496         conf.CHECK_CODE('''
1497             #define NO_CONFIG_H
1498             #include "replace.h"
1499             #include "system/wait.h"
1500             #include "system/network.h"
1501             #define private #error __USED_RESERVED_WORD_private__
1502             #include <talloc.h>
1503             #include <tdb.h>
1504             #include <ctdb.h>
1505
1506             int main(void)
1507             {
1508                 return 0;
1509             }
1510             ''',
1511             'HAVE_CTDB_H',
1512             addmain=False,
1513             includes=includes,
1514             msg='Checking for header ctdb.h')
1515
1516         if not conf.CONFIG_SET('HAVE_CTDB_H'):
1517             have_cluster_support = False
1518             ctdb_broken = "ctdb.h is required for cluster support"
1519
1520         if have_cluster_support:
1521             conf.CHECK_CODE('''
1522                 #define NO_CONFIG_H
1523                 #include "replace.h"
1524                 #include "system/wait.h"
1525                 #include "system/network.h"
1526                 #define private #error __USED_RESERVED_WORD_private__
1527                 #include <talloc.h>
1528                 #include <tdb.h>
1529                 #include <ctdb.h>
1530                 #include <ctdb_private.h>
1531
1532                 int main(void)
1533                 {
1534                     return 0;
1535                 }
1536                 ''',
1537                 'HAVE_CTDB_PRIVATE_H',
1538                 addmain=False,
1539                 includes=includes,
1540                 msg='Checking for header ctdb_private.h')
1541
1542             if not conf.CONFIG_SET('HAVE_CTDB_PRIVATE_H'):
1543                 have_cluster_support = False
1544                 ctdb_broken = "ctdb_private.h is required for cluster support"
1545
1546         if have_cluster_support:
1547             conf.CHECK_CODE('''
1548                 #define NO_CONFIG_H
1549                 #include "replace.h"
1550                 #include "system/wait.h"
1551                 #include "system/network.h"
1552                 #include <talloc.h>
1553                 #include <tdb.h>
1554                 #include <ctdb.h>
1555                 #include <ctdb_private.h>
1556
1557                 int main(void)
1558                 {
1559                    int i = (int)CTDB_CONTROL_TRANS3_COMMIT;
1560                    return 0;
1561                 }
1562                 ''',
1563                 'HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL',
1564                 addmain=False,
1565                 includes=includes,
1566                 msg='Checking for transaction support (TRANS3_COMMIT control)')
1567
1568             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL'):
1569                 have_cluster_support = False
1570                 ctdb_broken = "ctdb transaction support missing or too old"
1571
1572         if have_cluster_support:
1573             conf.CHECK_CODE('''
1574                 #define NO_CONFIG_H
1575                 #include "replace.h"
1576                 #include "system/wait.h"
1577                 #include "system/network.h"
1578                 #include <talloc.h>
1579                 #include <tdb.h>
1580                 #include <ctdb.h>
1581                 #include <ctdb_private.h>
1582
1583                 int main(void)
1584                 {
1585                     int i = (int)CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1586                     return 0;
1587                 }
1588                 ''',
1589                 'HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL',
1590                 addmain=False,
1591                 includes=includes,
1592                 msg='Checking for SCHEDULE_FOR_DELETION control')
1593
1594             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL'):
1595                 if not Options.options.enable_old_ctdb:
1596                     have_cluster_support = False
1597                     ctdb_broken = "SCHEDULE_FOR_DELETION control missing"
1598                 else:
1599                     Logs.warn("ignoring missing SCHEDULE_FOR_DELETION control (--enable-old-ctdb)")
1600
1601         if have_cluster_support:
1602             conf.CHECK_CODE('''
1603                 #define NO_CONFIG_H
1604                 #include "replace.h"
1605                 #include "system/wait.h"
1606                 #include "system/network.h"
1607                 #include <talloc.h>
1608                 #include <tdb.h>
1609                 #include <ctdb.h>
1610                 #include <ctdb_private.h>
1611
1612                 int main(void)
1613                 {
1614                     struct ctdb_control_tcp _x;
1615                     return 0;
1616                 }
1617                 ''',
1618                 'HAVE_STRUCT_CTDB_CONTROL_TCP',
1619                 addmain=False,
1620                 includes=includes,
1621                 msg='Checking for ctdb ipv4 support')
1622
1623             if not conf.CONFIG_SET('HAVE_STRUCT_CTDB_CONTROL_TCP'):
1624                 have_cluster_support = False
1625                 ctdb_broken = "missing struct ctdb_control_tcp"
1626
1627         if have_cluster_support:
1628             conf.CHECK_CODE('''
1629                 #define NO_CONFIG_H
1630                 #include "replace.h"
1631                 #include "system/wait.h"
1632                 #include "system/network.h"
1633                 #include <talloc.h>
1634                 #include <tdb.h>
1635                 #include <ctdb.h>
1636                 #include <ctdb_private.h>
1637
1638                 int main(void)
1639                 {
1640                     struct ctdb_control_tcp_addr _x;
1641                     return 0;
1642                 }
1643                 ''',
1644                 'HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR',
1645                 addmain=False,
1646                 includes=includes,
1647                 msg='Checking for ctdb ipv6 support')
1648
1649     if have_cluster_support:
1650         Logs.info("building with cluster support")
1651         conf.DEFINE('CLUSTER_SUPPORT', 1);
1652     else:
1653         if not Options.options.with_cluster_support:
1654             Logs.info("building without cluster support")
1655         else:
1656             Logs.warn("building without cluster support: " + ctdb_broken)
1657         conf.undefine('CLUSTER_SUPPORT')
1658
1659
1660
1661     conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1662                     'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1663                     addmain=False,
1664                     link=False,
1665                     msg='Checking whether we can compile with __attribute__((destructor))')
1666
1667     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1668                     'SEEKDIR_RETURNS_VOID',
1669                     headers='sys/types.h dirent.h',
1670                     msg='Checking whether seekdir returns void')
1671
1672     if Options.options.with_profiling_data:
1673         conf.DEFINE('WITH_PROFILE', 1);
1674
1675     PTHREAD_CFLAGS='error'
1676     PTHREAD_LDFLAGS='error'
1677
1678     if PTHREAD_LDFLAGS == 'error':
1679         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
1680             PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
1681             PTHREAD_LDFLAGS='-lpthread'
1682     if PTHREAD_LDFLAGS == 'error':
1683         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
1684             PTHREAD_CFLAGS='-D_THREAD_SAFE'
1685             PTHREAD_LDFLAGS='-lpthreads'
1686     if PTHREAD_LDFLAGS == 'error':
1687         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
1688             PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
1689             PTHREAD_LDFLAGS='-pthread'
1690     if PTHREAD_LDFLAGS == 'error':
1691         if conf.CHECK_FUNC('pthread_attr_init'):
1692             PTHREAD_CFLAGS='-D_REENTRANT'
1693             PTHREAD_LDFLAGS='-lpthread'
1694     # especially for HP-UX, where the CHECK_FUNC macro fails to test for
1695     # pthread_attr_init. On pthread_mutex_lock it works there...
1696     if PTHREAD_LDFLAGS == 'error':
1697         if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
1698             PTHREAD_CFLAGS='-D_REENTRANT'
1699             PTHREAD_LDFLAGS='-lpthread'
1700
1701     if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
1702         conf.ADD_CFLAGS(PTHREAD_CFLAGS)
1703         conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
1704         conf.CHECK_HEADERS('pthread.h')
1705         conf.DEFINE('HAVE_PTHREAD', '1')
1706
1707     if Options.options.with_pthreadpool:
1708         if conf.CONFIG_SET('HAVE_PTHREAD'):
1709             conf.DEFINE('WITH_PTHREADPOOL', '1')
1710         else:
1711             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
1712             conf.undefine('WITH_PTHREADPOOL')
1713
1714     if conf.CHECK_HEADERS('gpfs_gpl.h'):
1715         conf.DEFINE('HAVE_GPFS', '1')
1716
1717     # Note that all charset 'modules' must actually be static, due to dependency loop issues 
1718     # if we include the module loader in iconv
1719
1720     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1721                                       auth_sam auth_unix auth_winbind auth_wbc auth_server
1722                                       auth_domain auth_builtin vfs_default
1723                                       nss_info_template idmap_tdb idmap_passdb
1724                                       idmap_nss''')
1725
1726     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1727                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1728                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
1729                                       auth_script vfs_readahead vfs_xattr_tdb
1730                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1731                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1732                                       vfs_crossrename vfs_linux_xfs_sgid
1733                                       vfs_time_audit idmap_autorid''')
1734
1735     if Options.options.developer:
1736         default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond charset_weird'))
1737         default_shared_modules.extend(TO_LIST('perfcount_test'))
1738
1739     if Options.options.developer or not conf.CONFIG_SET('HAVE_NATIVE_ICONV'):
1740         default_static_modules.extend(TO_LIST('charset_CP850 charset_CP437'))
1741
1742     if conf.env.toplevel_build:
1743         default_static_modules.extend(TO_LIST('pdb_samba4 auth_samba4'))
1744
1745     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
1746         default_static_modules.extend(TO_LIST('vfs_posixacl'))
1747
1748     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1749         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1750
1751     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1752         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1753
1754     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1755         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1756
1757     if conf.CONFIG_SET('HAVE_AIO') and (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
1758         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1759
1760     if conf.CONFIG_SET('HAVE_LDAP'):
1761         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
1762
1763     if conf.CONFIG_SET('DARWINOS'):
1764         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1765
1766     if conf.CONFIG_SET('HAVE_GPFS'):
1767         default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
1768
1769     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1770     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1771
1772     final_static_modules = default_static_modules
1773     final_shared_modules = default_shared_modules
1774
1775     for m in explicit_static_modules:
1776         if m in final_shared_modules:
1777             final_shared_modules.remove(m)
1778         final_static_modules.append(m)
1779     for m in explicit_shared_modules:
1780         if m in final_static_modules:
1781             final_static_modules.remove(m)
1782         final_shared_modules.append(m)
1783
1784     conf.env['static_modules'] = final_static_modules
1785     conf.env['shared_modules'] = final_shared_modules
1786
1787     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1788
1789     static_list = {}
1790     shared_list = {}
1791
1792     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1793     conf.env['MODULE_PREFIXES'] = prefixes
1794     for p in prefixes:
1795         for m in final_static_modules:
1796             if m.find(p) == 0:
1797                 if not p in static_list:
1798                     static_list[p] = []
1799                 static_list[p].append(m)
1800         for m in final_shared_modules:
1801             if m.find(p) == 0:
1802                 if not p in shared_list:
1803                     shared_list[p] = []
1804                 shared_list[p].append(m)
1805
1806     for p in prefixes:
1807         static_env = "%s_STATIC" % p.upper()
1808         shared_env = "%s_SHARED" % p.upper()
1809         conf.env[static_env] = []
1810         conf.env[shared_env] = []
1811         if p in static_list:
1812             decl_list=""
1813             for entry in static_list[p]:
1814                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1815                 conf.env[static_env].append('%s' % entry)
1816             decl_list = decl_list.rstrip()
1817             conf.DEFINE('static_decl_%s' % p, decl_list)
1818             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1819         else:
1820             conf.DEFINE('static_decl_%s' % p, '')
1821             conf.DEFINE('static_init_%s' % p, '{}')
1822         if p in shared_list:
1823             for entry in shared_list[p]:
1824                 conf.DEFINE('%s_init' % entry, 'init_samba_module')
1825                 conf.env[shared_env].append('%s' % entry)
1826
1827     if not os.getenv('TOPLEVEL_BUILD'):
1828         # we don't want PYTHONDIR in config.h, as otherwise changing
1829         # --prefix causes a complete rebuild
1830         del(conf.env.defines['PYTHONDIR'])
1831         del(conf.env.defines['PYTHONARCHDIR'])
1832
1833     conf.SAMBA_CONFIG_H('include/config.h')
1834
1835 def ctags(ctx):
1836     "build 'tags' file using ctags"
1837     import Utils
1838     source_root = os.path.dirname(Utils.g_module.root_path)
1839     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1840     print("Running: %s" % cmd)
1841     os.system(cmd)
1842
1843 if not os.getenv('TOPLEVEL_BUILD'):
1844     def wildcard_cmd(cmd):
1845         '''called on a unknown command'''
1846         from samba_wildcard import run_named_build_task
1847         run_named_build_task(cmd)
1848     def main():
1849         from samba_wildcard import wildcard_main
1850         wildcard_main(wildcard_cmd)
1851     Scripting.main = main