build: Reduce build systems to just top level waf and autoconf
[amitay/samba.git] / source3 / wscript
index 6081ac9d4da2b43ebd244af02f4bd405ce5bbb31..f725b623fabcf3b30bf8877cec8ac0ff3e4149cd 100644 (file)
@@ -1,10 +1,6 @@
 #! /usr/bin/env python
 
-srcdir = '..'
-blddir = 'bin'
-
-APPNAME='samba'
-VERSION=None
+srcdir=".."
 
 import sys, os
 from optparse import SUPPRESS_HELP
@@ -15,17 +11,9 @@ import build.charset
 import samba_utils, samba_version
 import samba3
 
+Options.default_prefix = '/usr/local/samba'
+
 def set_options(opt):
-    if not os.getenv('TOPLEVEL_BUILD'):
-        opt.BUILTIN_DEFAULT('NONE')
-        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')
-        opt.RECURSE('../lib/tdb')
 
     opt.add_option('--with-static-modules',
                    help=("Comma-separated list of names of modules to statically link in"),
@@ -40,7 +28,7 @@ def set_options(opt):
     opt.SAMBA3_ADD_OPTION('winbind')
     opt.SAMBA3_ADD_OPTION('swat')
     opt.SAMBA3_ADD_OPTION('ads')
-    opt.SAMBA3_ADD_OPTION('krb5')
+    opt.SAMBA3_ADD_OPTION('mit-krb5-checks', default=False)
     opt.SAMBA3_ADD_OPTION('ldap')
     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
@@ -59,7 +47,7 @@ def set_options(opt):
     opt.SAMBA3_ADD_OPTION('syslog')
     opt.SAMBA3_ADD_OPTION('automount')
     opt.SAMBA3_ADD_OPTION('aio-support')
-    opt.SAMBA3_ADD_OPTION('profiling-data')
+    opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
 
     opt.SAMBA3_ADD_OPTION('cluster-support')
 
@@ -75,12 +63,6 @@ def set_options(opt):
 def configure(conf):
     from samba_utils import TO_LIST
 
-    if not conf.env.toplevel_build:
-        version = samba_version.load_version(env=conf.env)
-        conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
-        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')
         conf.env.developer = True
@@ -88,29 +70,6 @@ def configure(conf):
     if Options.options.with_swat:
         conf.env['build_swat'] = True
 
-    if not conf.env.toplevel_build:
-        conf.RECURSE('../lib/replace')
-        conf.RECURSE('build')
-        conf.RECURSE('../lib/tdb')
-        conf.RECURSE('../lib/talloc')
-        conf.RECURSE('../lib/tevent')
-        conf.RECURSE('../lib/popt')
-        conf.RECURSE('../lib/nss_wrapper')
-        conf.RECURSE('../lib/socket_wrapper')
-        conf.RECURSE('../lib/zlib')
-        conf.RECURSE('../libcli/smbreadline')
-        conf.RECURSE('../lib/util')
-
-        conf.ADD_EXTRA_INCLUDES('''#source3 #source3/include #lib/replace''')
-        if not conf.env.USING_SYSTEM_TDB:
-            conf.ADD_EXTRA_INCLUDES('#lib/tdb/include')
-        if not conf.env.USING_SYSTEM_TEVENT:
-            conf.ADD_EXTRA_INCLUDES('#lib/tevent')
-        if not conf.env.USING_SYSTEM_TALLOC:
-            conf.ADD_EXTRA_INCLUDES('#lib/talloc')
-        if not conf.env.USING_SYSTEM_POPT:
-            conf.ADD_EXTRA_INCLUDES('#lib/popt')
-
     conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
 
     conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
@@ -129,14 +88,14 @@ def configure(conf):
     conf.CHECK_FUNCS('opendir64 readdir64 seekdir64 telldir64 rewinddir64 closedir64')
     conf.CHECK_FUNCS('fdopendir fdopendir64')
     conf.CHECK_FUNCS('getpwent_r getdents64 setenv strcasecmp fcvt fcvtl')
-    conf.CHECK_FUNCS('syslog vsyslog timegm setlocale nl_langinfo')
+    conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
     conf.CHECK_FUNCS('shmget')
     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
-    conf.CHECK_FUNCS('gettext dgettext bindtextdomain textdomain')
+    conf.CHECK_FUNCS('gettext dgettext bindtextdomain textdomain bind_textdomain_codeset')
     #FIXME: for some reason this one still fails
     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
@@ -287,7 +246,7 @@ inotify_init lgetea lgetxattr listea listxattr llistea llistxattr
 llseek _llseek __llseek lremoveea lremovexattr _lseek __lseek lseek64
 lsetea lsetxattr _lstat __lstat lstat64 _lstat64 __lstat64 lutimes
 __lxstat memalign mknod mknod64 mlock mlockall munlock munlockall
-nl_langinfo _open __open open64 _open64 __open64 _opendir __opendir
+_open __open open64 _open64 __open64 _opendir __opendir
 opendir64 pathconf poll posix_fallocate posix_fallocate64
 posix_memalign prctl pread _pread __pread pread64 _pread64 __pread64
 pwrite _pwrite __pwrite pwrite64 _pwrite64
@@ -306,7 +265,6 @@ utimensat vsyslog _write __write __xstat
 
     # FIXME: these should be tests for features, but the old build system just
     # checks for OSes.
-    import sys
     host_os = sys.platform
     Logs.info("building on %s" % host_os)
 
@@ -327,7 +285,7 @@ utimensat vsyslog _write __write __xstat
         conf.ADD_CFLAGS('-fno-common')
     elif (host_os.rfind('freebsd') > -1):
         if conf.CHECK_HEADERS('sunacl.h'):
-            conf.define('HAVE_FREEBSD_SUNACL_H', '1')
+            conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
             conf.CHECK_FUNCS_IN('acl', 'sunacl')
         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
     elif (host_os.rfind('netbsd') > -1):
@@ -417,13 +375,12 @@ return acl_get_perm_np(permset_d, perm);
     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
 
     conf.CHECK_CODE('''
-               #include <sys/types.h>
-               #include <sys/socket.h>],
                struct ucred cred;
                socklen_t cred_len;
                int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
                'HAVE_PEERCRED',
-               msg="Checking whether we can use SO_PEERCRED to get socket credentials")
+               msg="Checking whether we can use SO_PEERCRED to get socket credentials",
+               headers='sys/types.h sys/socket.h')
 
     conf.CHECK_CODE('''
                #if defined(HAVE_LONGLONG) && (defined(HAVE_OFF64_T) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)))
@@ -574,7 +531,7 @@ msg.msg_acctrightslen = sizeof(fd);
 
     # Check for LDAP
     if Options.options.with_ldap:
-        conf.CHECK_HEADERS('ldap.h lber.h')
+        conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
@@ -584,7 +541,7 @@ msg.msg_acctrightslen = sizeof(fd);
         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
 
-        conf.CHECK_FUNCS_IN('ldap_init ldap_initialize ldap_set_rebind_proc', 'ldap')
+        conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
 
         # Check if ldap_set_rebind_proc() takes three arguments
@@ -612,27 +569,27 @@ msg.msg_acctrightslen = sizeof(fd);
 
     # Check for kerberos
     have_gssapi=False
-    if Options.options.with_krb5 and not conf.env.toplevel_build:
+    if Options.options.with_mit_krb5_checks and conf.env.developer:
         Logs.info("Looking for kerberos features")
         conf.find_program('krb5-config', var='KRB5_CONFIG')
         if conf.env.KRB5_CONFIG:
             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 gssapi/gssapi_ext.h com_err.h', lib='krb5')
+        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')
 
         if conf.CONFIG_SET('HAVE_KRB5_LOCATE_PLUGIN_H'):
             conf.env['WINBIND_KRB5_LOCATOR'] = 'bin/winbind_krb5_locator.so'
 
         conf.CHECK_FUNCS_IN('_et_list', 'com_err')
         conf.CHECK_FUNCS_IN('krb5_encrypt_data', 'k5crypto')
-        conf.CHECK_FUNCS_IN('crypto', 'des_set_key')
+       conf.CHECK_FUNCS_IN('des_set_key','crypto')
         conf.CHECK_FUNCS_IN('copy_Authenticator', 'asn1')
         conf.CHECK_FUNCS_IN('roken_getaddrinfo_hostspec', 'roken')
         if conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi') or \
            conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi_krb5'):
             have_gssapi=True
-        conf.CHECK_FUNCS_IN('gss_wrap_iov gss_krb5_import_cred gss_get_name_attribute', 'gssapi gssapi_krb5 krb5')
+        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')
         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
@@ -805,12 +762,6 @@ return krb5_kt_resolve(context, "WRFILE:api", &keytab);
         'HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER', addmain=False,
         link=False,
         msg="Checking for KRB5_DEPRECATED define taking an identifier")
-    elif not conf.env.toplevel_build:
-        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_ads:
         use_ads=True
@@ -1419,6 +1370,16 @@ main() {
                 conf.DEFINE('AIX_SENDFILE_API', '1')
                 conf.DEFINE('WITH_SENDFILE', '1')
 
+    # Check for getcwd allowing a NULL arg.
+    conf.CHECK_CODE('''
+#include <unistd.h>
+main() {
+       char *s = getcwd(NULL,0);
+        exit(s != NULL ?  0 : 1);
+}''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
+        msg="getcwd takes a NULL argument")
+
+
     conf.CHECK_CODE('''enum TDB_ERROR err = TDB_ERR_NESTING''',
                    'HAVE_TDB_ERR_NESTING',
                    headers='tdb.h',
@@ -1637,6 +1598,50 @@ main() {
     if Options.options.with_profiling_data:
         conf.DEFINE('WITH_PROFILE', 1);
 
+    PTHREAD_CFLAGS='error'
+    PTHREAD_LDFLAGS='error'
+
+    if PTHREAD_LDFLAGS == 'error':
+        if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
+            PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
+            PTHREAD_LDFLAGS='-lpthread'
+    if PTHREAD_LDFLAGS == 'error':
+        if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
+            PTHREAD_CFLAGS='-D_THREAD_SAFE'
+            PTHREAD_LDFLAGS='-lpthreads'
+    if PTHREAD_LDFLAGS == 'error':
+        if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
+            PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
+            PTHREAD_LDFLAGS='-pthread'
+    if PTHREAD_LDFLAGS == 'error':
+        if conf.CHECK_FUNC('pthread_attr_init'):
+            PTHREAD_CFLAGS='-D_REENTRANT'
+            PTHREAD_LDFLAGS='-lpthread'
+    # especially for HP-UX, where the CHECK_FUNC macro fails to test for
+    # pthread_attr_init. On pthread_mutex_lock it works there...
+    if PTHREAD_LDFLAGS == 'error':
+        if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
+            PTHREAD_CFLAGS='-D_REENTRANT'
+            PTHREAD_LDFLAGS='-lpthread'
+
+    if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
+        conf.ADD_CFLAGS(PTHREAD_CFLAGS)
+        conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
+        conf.CHECK_HEADERS('pthread.h')
+        conf.DEFINE('HAVE_PTHREAD', '1')
+
+    if Options.options.with_pthreadpool:
+        if conf.CONFIG_SET('HAVE_PTHREAD'):
+            conf.DEFINE('WITH_PTHREADPOOL', '1')
+        else:
+            Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
+            conf.undefine('WITH_PTHREADPOOL')
+
+    if conf.CHECK_HEADERS('gpfs_gpl.h'):
+        conf.DEFINE('HAVE_GPFS', '1')
+
+    # Note that all charset 'modules' must actually be static, due to dependency loop issues 
+    # if we include the module loader in iconv
 
     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
                                       auth_sam auth_unix auth_winbind auth_wbc auth_server
@@ -1646,16 +1651,18 @@ main() {
 
     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
-                                      vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 charset_CP850
-                                      charset_CP437 auth_script vfs_readahead vfs_xattr_tdb
+                                      vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
+                                      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_linux_xfs_sgid
                                       vfs_time_audit idmap_autorid''')
 
     if Options.options.developer:
-        default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond'))
-        default_shared_modules.extend(TO_LIST('charset_weird perfcount_test'))
+        default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond charset_weird'))
+        default_shared_modules.extend(TO_LIST('perfcount_test'))
+
+    default_static_modules.extend(TO_LIST('pdb_samba4 auth_samba4'))
 
     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
         default_static_modules.extend(TO_LIST('vfs_posixacl'))
@@ -1676,7 +1683,10 @@ main() {
         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
 
     if conf.CONFIG_SET('DARWINOS'):
-       default_shared_modules.extend(TO_LIST('charset_macosxfs'))
+       default_static_modules.extend(TO_LIST('charset_macosxfs'))
+
+    if conf.CONFIG_SET('HAVE_GPFS'):
+       default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
 
     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
@@ -1733,7 +1743,7 @@ main() {
             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.DEFINE('%s_init' % entry, 'samba_init_module')
                 conf.env[shared_env].append('%s' % entry)
 
     conf.SAMBA_CONFIG_H('include/config.h')
@@ -1746,12 +1756,3 @@ def ctags(ctx):
     print("Running: %s" % cmd)
     os.system(cmd)
 
-if not os.getenv('TOPLEVEL_BUILD'):
-    def wildcard_cmd(cmd):
-        '''called on a unknown command'''
-        from samba_wildcard import run_named_build_task
-        run_named_build_task(cmd)
-    def main():
-        from samba_wildcard import wildcard_main
-        wildcard_main(wildcard_cmd)
-    Scripting.main = main