s3-waf: add valgrind configure checks.
[metze/samba/wip.git] / source3 / wscript
index 6dc05c8bf41414590c3736c7dc94231face5a150..8f6ad598d02c61b72f9a79e8d8152087ba6880af 100644 (file)
@@ -3,6 +3,9 @@
 srcdir = '..'
 blddir = 'bin'
 
+APPNAME='samba'
+VERSION=None
+
 import sys, os
 from optparse import SUPPRESS_HELP
 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
@@ -11,11 +14,23 @@ import build.charset
 import samba_utils
 import samba3
 
+def load_version(env=None):
+    '''load samba versions either from ./VERSION or git
+    return a version object for detailed breakdown'''
+    import samba_utils, Utils
+    if not env:
+        env = samba_utils.LOAD_ENVIRONMENT()
+
+    version = wafsamba.samba_version_file("./VERSION", "..", env=env)
+    Utils.g_module.VERSION = version.STRING
+    return version
+
 def set_options(opt):
     opt.BUILTIN_DEFAULT('NONE')
-    opt.BUNDLED_EXTENSION_DEFAULT('s3')
+    opt.PRIVATE_EXTENSION_DEFAULT('s3')
     opt.RECURSE('../lib/replace')
     opt.RECURSE('build')
+    opt.RECURSE('selftest')
     opt.RECURSE('../lib/nss_wrapper')
     opt.RECURSE('../lib/socket_wrapper')
     opt.RECURSE('../lib/tevent')
@@ -23,10 +38,10 @@ def set_options(opt):
 
     opt.add_option('--with-static-modules',
                    help=("Comma-separated list of names of modules to statically link in"),
-                   action="store", dest='static_modules', default='')
+                   action="store", dest='static_modules', default=None)
     opt.add_option('--with-shared-modules',
                    help=("Comma-separated list of names of modules to build shared"),
-                   action="store", dest='shared_modules', default='')
+                   action="store", dest='shared_modules', default=None)
     opt.add_option('--enable-selftest',
                   help=("enable options necessary for selftest"),
                   action="store_true", dest='enable_selftest', default=False)
@@ -44,31 +59,28 @@ def set_options(opt):
     opt.SAMBA3_ADD_OPTION('sendfile-support')
     opt.SAMBA3_ADD_OPTION('utmp')
     opt.SAMBA3_ADD_OPTION('pthreadpool', with_name="enable", without_name="disable")
+    opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
+    opt.SAMBA3_ADD_OPTION('iconv')
+    opt.SAMBA3_ADD_OPTION('acl-support')
+    opt.SAMBA3_ADD_OPTION('dnsupdate')
 
 
 def configure(conf):
     from samba_utils import TO_LIST
 
-    conf.define('PACKAGE_NAME', 'Samba')
-    conf.define('PACKAGE_STRING', 'Samba 3')
-    conf.define('PACKAGE_TARNAME', 'samba')
-    conf.define('PACKAGE_URL', '')
-    conf.define('PACKAGE_VERSION', '3')
-    conf.define('PACKAGE_BUGREPORT', 'samba-technical@samba.org')
+    version = load_version(env=conf.env)
 
     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
-    conf.DEFINE('_SAMBA_BUILD_', 3, add_to_cflags=True)
+    conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
+
     if Options.options.developer:
         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
-        conv.env['developer'] = True
+        conf.env['developer'] = True
 
     if Options.options.with_swat:
         conf.env['build_swat'] = True
 
-    # set a limit on recursing in the waf preprocessor
-    conf.env.preprocessor_recursion_limit = 10
-
     conf.ADD_EXTRA_INCLUDES('''#source3 #source3/include #lib/replace #lib/talloc
                                #lib/tevent #source3/libaddns #source3/librpc
                                #source3/lib #lib/tdb/include #lib/popt #source4''')
@@ -82,14 +94,15 @@ def configure(conf):
     conf.RECURSE('../lib/nss_wrapper')
     conf.RECURSE('../lib/socket_wrapper')
     conf.RECURSE('../lib/zlib')
+    conf.RECURSE('../libcli/smbreadline')
 
-    conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h')
+    conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
 
     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod mknod64')
     conf.CHECK_FUNCS('strtol strchr strupr chflags')
     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
-    conf.CHECK_FUNCS('sigprocmask sigblock sigaction sigset innetgr setnetgrent getnetgrent endnetgrent')
+    conf.CHECK_FUNCS('sigprocmask sigblock sigaction sigset innetgr')
     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups sysconf stat64 fstat64')
     conf.CHECK_FUNCS('lstat64 fopen64 atexit grantpt lseek64 ftruncate64 posix_fallocate posix_fallocate64')
@@ -197,6 +210,9 @@ main() {
         conf.CHECK_CODE('uint32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
                         headers='sys/types.h rpc/rpc.h',
                         msg="Checking for uint32 typedef included by rpc/rpc.h")
+    conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
+                    headers='sys/types.h sys/acl.h rpcsvc/nis.h',
+                    msg="Checking for broken nisplus include files")
 
     # Check if the compiler will optimize out functions
     conf.CHECK_CODE('''
@@ -207,12 +223,18 @@ if (0) {
 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
         msg="Checking if the compiler will optimize out functions")
 
+    # Check if the compiler supports the LL suffix on long long integers
+    # AIX needs this
+    conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
+                    headers='stdio.h',
+                    msg="Checking for LL suffix on long long integers")
+
     conf.CHECK_FUNCS('''
 _acl __acl add_proplist_entry atexit attr_getf attr_list attr_listf
 attropen attr_remove attr_removef attr_set attr_setf backtrace_symbols
 bindtextdomain _chdir __chdir chflags chmod _close __close _closedir
 __closedir closedir64 creat64 crypt16 delproplist devnm dgettext dirfd
-DNSServiceRegister _dup __dup _dup2 __dup2 endmntent endnetgrent execl
+DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
 extattr_delete_fd extattr_delete_link extattr_get_fd extattr_get_file
 extattr_get_link extattr_list_fd extattr_list_file extattr_list_link
 extattr_set_fd extattr_set_file extattr_set_link _facl __facl _fchdir
@@ -222,9 +244,9 @@ _fork __fork fremoveea fremovexattr fseek64 fseeko64 fsetea
 fsetproplist fsetxattr _fstat __fstat fstat64 _fstat64 __fstat64 fsync
 ftell64 ftello64 ftruncate64 futimens futimes __fxstat getauthuid
 getcwd _getcwd __getcwd getdents __getdents getdents64 getdirentries
-getgrent getgrnam getgrouplist getmntent getnetgrent getpagesize
+getgrent getgrnam getgrouplist getmntent getpagesize
 getproplist get_proplist_entry getpwanam getpwent_r getrlimit gettext
-getutmpx getutxent glob grantpt hstrerror initgroups innetgr
+glob grantpt hstrerror initgroups innetgr
 inotify_init lgetea lgetxattr listea listxattr llistea llistxattr
 llseek _llseek __llseek lremoveea lremovexattr _lseek __lseek lseek64
 lsetea lsetxattr _lstat __lstat lstat64 _lstat64 __lstat64 lutimes
@@ -232,29 +254,87 @@ __lxstat memalign mknod mknod64 mlock mlockall munlock munlockall
 nl_langinfo _open __open open64 _open64 __open64 _opendir __opendir
 opendir64 pathconf poll posix_fallocate posix_fallocate64
 posix_memalign prctl pread _pread __pread pread64 _pread64 __pread64
-pututline pututxline pwrite _pwrite __pwrite pwrite64 _pwrite64
+pwrite _pwrite __pwrite pwrite64 _pwrite64
 __pwrite64 rdchk _read __read _readdir __readdir readdir64 _readdir64
 __readdir64 removeea removexattr rewinddir64 _seekdir __seekdir
 seekdir64 select setea setenv setgidx setgroups setlocale setluid
-setmntent setnetgrent setpgid setpriv setproplist setsid setuidx
+setmntent setpgid setpriv setproplist setsid setuidx
 setxattr shmget shm_open sigaction sigblock sigprocmask sigset
 sizeof_proplist_entry _stat __stat stat64 _stat64 __stat64 statvfs
 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctlbyname
 __sys_llseek syslog _telldir __telldir telldir64 textdomain timegm
-updwtmp updwtmpx utimensat vsyslog _write __write __xstat
+utimensat vsyslog _write __write __xstat
 ''')
 
     conf.CHECK_TYPE('struct timespec', headers='sys/time.h time.h')
 
     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
 
+    # FIXME: these should be tests for features, but the old build system just
+    # checks for OSes.
+    import sys
+    host_os = sys.platform
 
-    default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam rpc_lsarpc rpc_samr
+    # Python doesn't have case switches... :/
+    # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
+    # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
+    if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
+        if host_os.rfind('linux') > -1:
+            conf.DEFINE('LINUX', '1')
+        elif host_os.rfind('qnx') > -1:
+            conf.DEFINE('QNX', '1')
+        conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
+    elif (host_os.rfind('darwin') > -1):
+        conf.DEFINE('DARWINOS', 1)
+        conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
+        conf.ADD_CFLAGS('-fno-common')
+    # FIXME: Add more checks here.
+    else:
+        print "Unknown host_os '%s', please report this to samba-technical@samba.org" % host_os
+
+    #FIXME: add more checks
+    if Options.options.with_acl_support:
+        if host_os.rfind('linux') > -1:
+           conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
+           conf.CHECK_FUNCS_IN('getxattr', 'attr')
+            if conf.CHECK_CODE('''
+acl_t acl;
+int entry_id;
+acl_entry_t *entry_p;
+return acl_get_entry(acl, entry_id, entry_p);
+''',
+                        'HAVE_POSIX_ACLS',
+                        headers='sys/types.h sys/acl.h', link=False,
+                       msg="Checking for POSIX ACL support") :
+                conf.CHECK_CODE('''
+acl_permset_t permset_d;
+acl_perm_t perm;
+return acl_get_perm_np(permset_d, perm);
+''',
+                        'HAVE_ACL_GET_PERM_NP',
+                        headers='sys/types.h sys/acl.h', link=True,
+                        msg="Checking whether acl_get_perm_np() is available")
+    else:
+        conf.DEFINE('HAVE_NO_ACLS', 1)
+        conf.SET_TARGET_TYPE('acl', 'EMPTY')
+        conf.SET_TARGET_TYPE('attr', 'EMPTY')
+
+    if conf.CHECK_FUNCS('dirfd'):
+        conf.DEFINE('HAVE_DIRFD_DECL', 1)
+
+    conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
+                    'HAVE_STATFS_F_FSID',
+                    msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
+                    headers='sys/types.h sys/statfs.h',
+                    execute=True)
+
+    default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam pdb_ldap rpc_lsarpc rpc_samr
                                       rpc_winreg rpc_initshutdown rpc_dssetup rpc_wkssvc rpc_svcctl
                                       rpc_ntsvcs rpc_netlogon rpc_netdfs rpc_srvsvc rpc_spoolss
                                       rpc_eventlog auth_sam auth_unix auth_winbind auth_wbc auth_server
                                       auth_domain auth_builtin auth_netlogond vfs_default
-                                      nss_info_template''')
+                                      nss_info_template idmap_ldap idmap_tdb idmap_passdb
+                                      idmap_nss''')
 
     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
@@ -262,25 +342,41 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
                                       charset_CP437 auth_script vfs_readahead vfs_xattr_tdb
                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
-                                      vfs_crossrename''')
+                                      vfs_crossrename vfs_linux_xfs_sgid
+                                      vfs_time_audit idmap_autorid''')
 
     if Options.options.developer:
         default_static_modules.extend(TO_LIST('rpc_rpcecho pdb_ads'))
         default_shared_modules.extend(TO_LIST('charset_weird perfcount_test'))
 
-    move_to_shared = TO_LIST(Options.options.shared_modules)
-    move_to_static = TO_LIST(Options.options.static_modules)
+    if Options.options.with_acl_support:
+        default_static_modules.extend(TO_LIST('vfs_posixacl'))
+
+    if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
+       default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
+
+    if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
+       default_shared_modules.extend(TO_LIST('vfs_fileid'))
 
-    for m in move_to_static:
-        if m in default_shared_modules:
-            default_shared_modules.remove(m)
-            default_static_modules.append(m)
-    for m in move_to_shared:
-        if m in default_static_modules:
-            default_static_modules.remove(m)
-            default_shared_modules.append(m)
+    explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
+    explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
 
-    conf.DEFINE('STRING_STATIC_MODULES', ' '.join(default_static_modules), quote=True)
+    final_static_modules = default_static_modules
+    final_shared_modules = default_shared_modules
+
+    for m in explicit_static_modules:
+        if m in final_shared_modules:
+            final_shared_modules.remove(m)
+        final_static_modules.append(m)
+    for m in explicit_shared_modules:
+        if m in final_static_modules:
+            final_static_modules.remove(m)
+        final_shared_modules.append(m)
+
+    conf.env['static_modules'] = final_static_modules
+    conf.env['shared_modules'] = final_shared_modules
+
+    conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
 
     static_list = {}
     shared_list = {}
@@ -288,12 +384,12 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
     prefixes = ['vfs', 'pdb', 'rpc', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
     conf.env['MODULE_PREFIXES'] = prefixes
     for p in prefixes:
-        for m in default_static_modules:
+        for m in final_static_modules:
             if m.find(p) == 0:
                 if not p in static_list:
                     static_list[p] = []
                 static_list[p].append(m)
-        for m in default_shared_modules:
+        for m in final_shared_modules:
             if m.find(p) == 0:
                 if not p in shared_list:
                     shared_list[p] = []
@@ -306,25 +402,34 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
         conf.env[shared_env] = []
         if p in static_list:
             decl_list=""
-            for entry in static_list[p]:
-                decl_list += "extern NTSTATUS %s_init(void); " % entry
-                conf.env[static_env].append('%s' % entry.upper())
-            decl_list = decl_list.rstrip()
-            conf.DEFINE('static_decl_%s' % p, decl_list)
-            conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
+            if p == "rpc":
+                for entry in static_list[p]:
+                    decl_list += "extern NTSTATUS %s_init(const struct rpc_srv_callbacks *rpc_srv_cb); " % entry
+                    conf.env[static_env].append('%s' % entry)
+                decl_list = decl_list.rstrip()
+                conf.DEFINE('static_decl_%s' % p, decl_list)
+                conf.DEFINE('static_init_%s' % p, '{ %s_init(NULL); }' % '_init(NULL);  '.join(static_list[p]))
+            else:
+                for entry in static_list[p]:
+                    decl_list += "extern NTSTATUS %s_init(void); " % entry
+                    conf.env[static_env].append('%s' % entry)
+                decl_list = decl_list.rstrip()
+                conf.DEFINE('static_decl_%s' % p, decl_list)
+                conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
         else:
             conf.DEFINE('static_decl_%s' % p, '')
             conf.DEFINE('static_init_%s' % p, '{}')
         if p in shared_list:
             for entry in shared_list[p]:
                 conf.DEFINE('%s_init' % entry, 'init_samba_module')
-                conf.env[shared_env].append('%s' % entry.upper())
+                conf.env[shared_env].append('%s' % entry)
 
     if Options.options.with_winbind:
         conf.env.build_winbind = True
         conf.DEFINE('WITH_WINBIND', '1')
 
     conf.find_program('awk', var='AWK')
+    conf.find_program('perl', var='PERL')
 
     # Darwin has extra options to xattr-family functions
     conf.CHECK_CODE('getxattr(0, 0, 0, 0, 0, 0);',
@@ -332,6 +437,34 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
                     msg="Checking whether xattr interface takes additional options",
                     headers='sys/types.h attr/xattr.h sys/xattr.h')
 
+    conf.CHECK_HEADERS('asm/types.h')
+
+    conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
+                    headers='unistd.h sys/types.h',
+                    msg="Checking for major macro")
+
+    conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
+                    headers='unistd.h sys/types.h',
+                    msg="Checking for minor macro")
+
+    conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
+                                headers='unistd.h sys/types.h dirent.h',
+                                define='HAVE_DIRENT_D_OFF')
+
+    conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
+    conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
+                    msg="Checking for setnetgrent prototype",
+                    headers='netdb.h netgroup.h',
+                    cflags="-Werror-implicit-function-declaration")
+    conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
+                    msg="Checking for getnetgrent prototype",
+                    headers='netdb.h netgroup.h',
+                    cflags="-Werror-implicit-function-declaration")
+    conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
+                    msg="Checking for endnetgrent prototype",
+                    headers='netdb.h netgroup.h',
+                    cflags="-Werror-implicit-function-declaration")
+
     #FIXME: Should just be set when krb5 and ldap requirements are fulfilled
     if Options.options.with_ads:
         conf.DEFINE('WITH_ADS', '1')
@@ -343,6 +476,7 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
                        package="", uselib_store="cups")
         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
         conf.CHECK_LIB('cups')
+        conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
     else:
         # define an empty subsystem for cups, to allow it to be used as an empty dependency
         conf.SET_TARGET_TYPE('cups', 'EMPTY')
@@ -392,7 +526,7 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
         conf.check_cfg(path="krb5-config", args="--cflags --libs",
                        package="gssapi", uselib_store="krb5")
         conf.CHECK_HEADERS('krb5.h krb5/locate_plugin.h', lib='krb5')
-        conf.CHECK_HEADERS('gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h com_err.h', lib='krb5')
+        conf.CHECK_HEADERS('gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h gssapi/gssapi_ext.h com_err.h', lib='krb5')
 
         if conf.CONFIG_SET('HAVE_KRB5_LOCATE_PLUGIN_H'):
             conf.env['WINBIND_KRB5_LOCATOR'] = 'bin/winbind_krb5_locator.so'
@@ -402,7 +536,9 @@ updwtmp updwtmpx utimensat vsyslog _write __write __xstat
         conf.CHECK_FUNCS_IN('crypto', 'des_set_key')
         conf.CHECK_FUNCS_IN('copy_Authenticator', 'asn1')
         conf.CHECK_FUNCS_IN('roken_getaddrinfo_hostspec', 'roken')
-        conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi gssapi_krb5')
+        if conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi gssapi_krb5'):
+            conf.DEFINE('HAVE_GSSAPI', '1')
+        conf.CHECK_FUNCS_IN('gss_wrap_iov', 'gssapi gssapi_krb5 krb5')
         conf.CHECK_FUNCS_IN('krb5_mk_req_extended krb5_kt_compare', 'krb5')
         conf.CHECK_FUNCS('''
 krb5_set_real_time krb5_set_default_in_tkt_etypes krb5_set_default_tgs_enctypes
@@ -444,7 +580,21 @@ krb5_get_credentials_for_user krb5_get_host_realm krb5_free_host_realm''',
                                     define='HAVE_KRB5_KEYBLOCK_IN_CREDS')
         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'session', headers='krb5.h',
                                     define='HAVE_KRB5_SESSION_IN_CREDS')
+        conf.CHECK_STRUCTURE_MEMBER('krb5_ap_req', 'ticket', headers='krb5.h',
+                                    define='HAVE_TICKET_POINTER_IN_KRB5_AP_REQ')
+
         conf.CHECK_TYPE('krb5_encrypt_block', headers='krb5.h')
+
+        conf.CHECK_CODE('''
+krb5_ticket ticket;
+krb5_kvno kvno;
+krb5_enctype enctype;
+enctype = ticket.enc_part.enctype;
+kvno = ticket.enc_part.kvno;
+''',
+                        'KRB5_TICKET_HAS_KEYINFO',
+                        headers='krb5.h', link=False,
+                        msg="Checking whether the krb5_ticket structure contains the kvno and enctype")
         conf.CHECK_CODE('''
 krb5_context ctx;
 krb5_get_init_creds_opt *opt = NULL;
@@ -467,30 +617,267 @@ pkdata = krb5_princ_component(context, principal, 0);
                         headers='krb5.h', lib='krb5',
                         msg="Checking whether krb5_princ_component is available")
 
+        conf.CHECK_CODE('''
+int main(void) {
+char buf[256];
+krb5_enctype_to_string(1, buf, 256);
+return 0;
+}''',
+                        'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG',
+                        headers='krb5.h', lib='krb5',
+                        addmain=False, cflags='-Werror',
+                        msg="Checking whether krb5_enctype_to_string takes size_t argument")
+
+        conf.CHECK_CODE('''
+int main(void) {
+krb5_context context = NULL;
+char *str = NULL;
+krb5_enctype_to_string(context, 1, &str);
+if (str) free (str);
+return 0;
+}''',
+                        'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG',
+                        headers='krb5.h stdlib.h', lib='krb5',
+                        addmain=False, cflags='-Werror',
+                        msg="Checking whether krb5_enctype_to_string takes krb5_context argument")
+        conf.CHECK_CODE('''
+int main(void) {
+krb5_context ctx = NULL;
+krb5_principal princ = NULL;
+const char *str = krb5_princ_realm(ctx, princ)->data;
+return 0;
+}''',
+                        'HAVE_KRB5_PRINC_REALM',
+                        headers='krb5.h', lib='krb5',
+                        addmain=False,
+                        msg="Checking whether the macro krb5_princ_realm is defined")
+        if conf.CHECK_CODE('''krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);''',
+                        'KRB5_VERIFY_CHECKSUM_ARGS',
+                        headers='krb5.h', lib='krb5',
+                       msg="Checking whether krb5_verify_checksum takes 7 arguments"):
+            conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '7')
+       else:
+            conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '6')
+
+       conf.CHECK_CODE('''
+krb5_enctype enctype;
+enctype = ENCTYPE_ARCFOUR_HMAC_MD5;
+''',
+            '_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5',
+            headers='krb5.h', lib='krb5',
+            msg="Checking whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available");
+       conf.CHECK_CODE('''
+krb5_keytype keytype;
+keytype = KEYTYPE_ARCFOUR_56;
+''',
+            '_HAVE_KEYTYPE_ARCFOUR_56',
+            headers='krb5.h', lib='krb5',
+            msg="Checking whether the HAVE_KEYTYPE_ARCFOUR_56 key type definition is available");
+       if conf.CONFIG_SET('_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and conf.CONFIG_SET('_HAVE_KEYTYPE_ARCFOUR_56'):
+            conf.DEFINE('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5', '1')
+
+       conf.CHECK_CODE('''
+krb5_enctype enctype;
+enctype = ENCTYPE_ARCFOUR_HMAC;
+''',
+            'HAVE_ENCTYPE_ARCFOUR_HMAC',
+            headers='krb5.h', lib='krb5',
+            msg="Checking whether the ENCTYPE_ARCFOUR_HMAC key type definition is available");
+
+       conf.CHECK_CODE('''
+krb5_context context;
+krb5_keytab keytab;
+krb5_init_context(&context);
+return krb5_kt_resolve(context, "WRFILE:api", &keytab);
+''',
+            'HAVE_WRFILE_KEYTAB',
+            headers='krb5.h', lib='krb5', execute=True,
+            msg="Checking whether the WRFILE:-keytab is supported");
+
+        conf.DEFINE('HAVE_KRB5', '1')
+
     else:
         conf.SET_TARGET_TYPE('krb5', 'EMPTY')
         conf.SET_TARGET_TYPE('gssapi', 'EMPTY')
         conf.SET_TARGET_TYPE('gssapi_krb5', 'EMPTY')
+        conf.SET_TARGET_TYPE('com_err', 'EMPTY')
+        conf.SET_TARGET_TYPE('k5crypto', 'EMPTY')
+
+    if Options.options.with_utmp:
+        conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
+                                    define='HAVE_UT_UT_NAME')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
+                                    define='HAVE_UT_UT_USER')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
+                                    define='HAVE_UT_UT_ID')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
+                                    define='HAVE_UT_UT_HOST')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
+                                    define='HAVE_UT_UT_TIME')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
+                                    define='HAVE_UT_UT_TV')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
+                                    define='HAVE_UT_UT_TYPE')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
+                                    define='HAVE_UT_UT_PID')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
+                                    define='HAVE_UT_UT_EXIT')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
+                                    define='HAVE_UT_UT_ADDR_V6')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
+                                    define='HAVE_UT_UT_ADDR')
+        conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
+                                    define='HAVE_UX_UT_SYSLEN')
+        conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
+                        'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
+                        msg="Checking whether pututline returns pointer")
+        conf.DEFINE('WITH_UTMP', 1)
+
+    if Options.options.with_avahi:
+        conf.env.with_avahi = True
+        if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
+        if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
+        if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
+        if conf.env.with_avahi:
+            conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
+    else:
+        conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
+        conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
+
+    if Options.options.with_iconv:
+        conf.env.with_iconv = True
+        if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
+            conf.env.with_iconv = False
+        if conf.env.with_iconv:
+            conf.DEFINE('HAVE_ICONV', 1)
+
+    if Options.options.with_pam:
+        conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
+        if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
+            print "--with-pam=yes but pam_appl.h not found"
+            sys.exit(1)
+        conf.CHECK_FUNCS_IN('pam_get_data', 'pam', mandatory=True)
+       conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
+       if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
+            print "--with-pam=yes but pam_modules.h not found"
+            sys.exit(1)
+        conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
+        conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
+        conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
+       conf.CHECK_CODE('''
+#if defined(HAVE_SECURITY_PAM_APPL_H)
+#include <security/pam_appl.h>
+#elif defined(HAVE_PAM_PAM_APPL_H)
+#include <pam/pam_appl.h>
+#endif
+pam_set_item(0, PAM_RHOST, 0);
+''',
+            'HAVE_PAM_RHOST',
+            lib='pam',
+            msg="Checking whether PAM_RHOST is available");
+       conf.CHECK_CODE('''
+#if defined(HAVE_SECURITY_PAM_APPL_H)
+#include <security/pam_appl.h>
+#elif defined(HAVE_PAM_PAM_APPL_H)
+#include <pam/pam_appl.h>
+#endif
+pam_set_item(0, PAM_TTY, 0);
+''',
+            'HAVE_PAM_TTY',
+            lib='pam',
+            msg="Checking whether PAM_TTY is available");
+       conf.CHECK_CODE('''
+#if (!defined(LINUX))
+
+#define PAM_EXTERN extern
+#if defined(HAVE_SECURITY_PAM_APPL_H)
+#include <security/pam_appl.h>
+#elif defined(HAVE_PAM_PAM_APPL_H)
+#include <pam/pam_appl.h>
+#endif
 
-    # FIXME: these should be tests for features, but the old build system just
-    # checks for OSes.
-    import sys
-    host_os = sys.platform
+#endif
 
-    # Python doesn't have case switches... :/
-    # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
-    # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
-    if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
-        if host_os.rfind('linux') > -1:
-            conf.DEFINE('LINUX', '1')
-        elif host_os.rfind('qnx') > -1:
-            conf.DEFINE('QNX', '1')
-        conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
-    elif (host_os.rfind('darwin') > -1):
-        conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
-    # FIXME: Add more checks here.
+#if defined(HAVE_SECURITY_PAM_MODULES_H)
+#include <security/pam_modules.h>
+#elif defined(HAVE_PAM_PAM_MODULES_H)
+#include <pam/pam_modules.h>
+#endif
+
+#if defined(HAVE_SECURITY__PAM_MACROS_H)
+#include <security/_pam_macros.h>
+#elif defined(HAVE_PAM__PAM_MACROS_H)
+#include <pam/_pam_macros.h>
+#endif
+
+#ifdef HAVE_SECURITY_PAM_EXT_H
+#include <security/pam_ext.h>
+#endif
+
+int i; i = PAM_RADIO_TYPE;
+''',
+            'HAVE_PAM_RADIO_TYPE',
+            lib='pam',
+            msg="Checking whether PAM_RADIO_TYPE is available");
+        conf.DEFINE('WITH_PAM', 1)
+        conf.DEFINE('WITH_PAM_MODULES', 1)
+
+    seteuid = False
+    if not seteuid:
+        seteuid = conf.CHECK_CODE('''
+                               #define AUTOCONF_TEST 1
+                               #define USE_SETREUID 1
+                               #include "./lib/util_sec.c"
+                               ''',
+                               'USE_SETREUID',
+                               addmain=False,
+                               execute=True,
+                               msg="Checking whether setreuid is available")
+    if not seteuid:
+        seteuid = conf.CHECK_CODE('''
+                               #define AUTOCONF_TEST 1
+                               #define USE_SETRESUID 1
+                               #include "./lib/util_sec.c"
+                               ''',
+                               'USE_SETRESUID',
+                               addmain=False,
+                               execute=True,
+                               msg="Checking whether setresuid is available")
+    if not seteuid:
+        seteuid = conf.CHECK_CODE('''
+                               #define AUTOCONF_TEST 1
+                               #define USE_SETEUID 1
+                               #include "./lib/util_sec.c"
+                               ''',
+                               'USE_SETEUID',
+                               addmain=False,
+                               execute=True,
+                               msg="Checking whether seteuid is available")
+    if not seteuid:
+        seteuid = conf.CHECK_CODE('''
+                               #define AUTOCONF_TEST 1
+                               #define USE_SETUIDX 1
+                               #include "./lib/util_sec.c"
+                               ''',
+                               'USE_SETUIDX',
+                               addmain=False,
+                               execute=True,
+                               mandatory=True,
+                               msg="Checking whether setuidx is available")
+    if Options.options.with_dnsupdate:
+        conf.CHECK_HEADERS('uuid/uuid.h')
+        conf.CHECK_FUNCS_IN('uuid_generate', 'uuid')
+        if not conf.CONFIG_SET('HAVE_UUID_UUID_H') and not conf.CONFIG_SET('HAVE_UUID_GENERATE'):
+            print "--with-dnsupdate=yes but uuid support not sufficient"
+            sys.exit(1)
+        conf.DEFINE('WITH_DNS_UPDATES', 1)
     else:
-        print "Unknown host_os '%s', please report this to samba-technical@samba.org" % host_os
+        conf.SET_TARGET_TYPE('uuid', 'EMPTY')
+    conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
+    if Options.options.developer:
+        if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
+            conf.DEFINE('VALGRIND', '1')
 
     conf.SAMBA_CONFIG_H('include/config.h')