build: waf quicktest nearly works
[nivanova/samba-autobuild/.git] / lib / replace / wscript
index 674307845118b1b99d3361422d8e86cde58ed8d4..ab7ef9783d582efbccf3d77e5fad924a849b2ab0 100644 (file)
@@ -26,16 +26,24 @@ def set_options(opt):
     opt.add_option('--enable-developer',
                    help=("Turn on developer warnings and debugging"),
                    action="store_true", dest='developer', default=False)
+    opt.add_option('--timestamp-dependencies',
+                   help=("use file timestamps instead of content for build dependencies (BROKEN)"),
+                   action="store_true", dest='timestamp_dependencies', default=False)
 
 @wafsamba.runonce
 def configure(conf):
     conf.env.hlist = []
     conf.env.srcdir = conf.srcdir
 
+    if Options.options.timestamp_dependencies:
+        conf.ENABLE_TIMESTAMP_DEPENDENCIES()
+
     # load our local waf extensions
     conf.check_tool('wafsamba', tooldir=conf.srcdir + "/buildtools/wafsamba")
 
     conf.check_tool('compiler_cc')
+    # gccdeps can be useful for debugging recursion in #include lines
+    conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
 
     # make the install paths available in environment
     conf.env.LIBDIR = Options.options.LIBDIR
@@ -44,11 +52,14 @@ def configure(conf):
 
     conf.env.RPATH_ON_INSTALL = Options.options.enable_rpath
 
+    # we should use the PIC options in waf instead
+    conf.ADD_CFLAGS('-fPIC')
+
     # check for pkgconfig
     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
 
-    conf.DEFINE('_GNU_SOURCE', 1)
-    conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1)
+    conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
+    conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
     conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1)
 
     conf.CHECK_HEADERS('unistd.h sys/types.h stdlib.h stdio.h stddef.h')
@@ -86,6 +97,7 @@ def configure(conf):
 
     conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t')
     conf.CHECK_TYPES('comparison_fn_t socklen_t bool')
+    conf.CHECK_TYPE('_Bool', define='HAVE__Bool')
 
     conf.CHECK_TYPE('int8_t', 'char')
     conf.CHECK_TYPE('int16_t', 'short')
@@ -111,6 +123,25 @@ def configure(conf):
 
     conf.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define='HAVE_SIG_ATOMIC_T_TYPE')
 
+    conf.CHECK_CODE('''
+                       struct sockaddr_storage sa_store;
+                       struct addrinfo *ai = NULL;
+                       struct in6_addr in6addr;
+                       int idx = if_nametoindex("iface1");
+                       int s = socket(AF_INET6, SOCK_STREAM, 0);
+                       int ret = getaddrinfo(NULL, NULL, NULL, &ai);
+                       if (ret != 0) {
+                         const char *es = gai_strerror(ret);
+                       }
+                       freeaddrinfo(ai);
+                       ''',
+                    define='HAVE_IPV6')
+
+    # check if signal() takes a void function
+    if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1', define='RETSIGTYPE_INT', msg='Checking return type of signal handlers'):
+        conf.DEFINE('RETSIGTYPE', 'int')
+    else:
+        conf.DEFINE('RETSIGTYPE', 'void')
 
     conf.CHECK_FUNCS('shl_load shl_unload shl_findsym')
     conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
@@ -135,6 +166,7 @@ def configure(conf):
     conf.CHECK_FUNCS_IN('poptGetContext', 'popt')
     conf.CHECK_FUNCS_IN('res_search', 'resolv')
     conf.CHECK_FUNCS_IN('gettext', 'intl')
+    conf.CHECK_FUNCS_IN('pthread_create', 'pthread')
 
     conf.CHECK_FUNCS_IN('crypt', 'crypt', checklibc=True)
 
@@ -151,20 +183,16 @@ def configure(conf):
     conf.CHECK_SIZEOF('void*', define='SIZEOF_VOID_P')
 
     if conf.CONFIG_SET('HAVE_EPOLL_CREATE') and conf.CONFIG_SET('HAVE_SYS_EPOLL_H'):
-        conf.define('HAVE_EPOLL', 1)
-
-    conf.check_cc(fragment='''
-    #include <stdarg.h>
-    va_list ap1,ap2;
-    va_copy(ap1,ap2);
-    int main(void)
-    { return 0; }''',
-                define_name="HAVE_VA_COPY",
-               execute=0,
-               link=0,
-                define_ret=0,
-                quote=0,
-               msg="Checking for va_copy")
+        conf.DEFINE('HAVE_EPOLL', 1)
+
+    conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
+                    define="HAVE_VA_COPY",
+                    msg="Checking for va_copy")
+
+    conf.CHECK_CODE('''
+                    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
+                    eprintf("bla", "bar")
+                    ''', define='HAVE__VA_ARGS__MACRO')
 
     conf.CHECK_CODE('gettimeofday(NULL, NULL)', 'HAVE_GETTIMEOFDAY_TZ', execute=False)
 
@@ -175,7 +203,7 @@ def configure(conf):
                     msg="Checking for C99 vsnprintf")
 
     if Options.options.developer:
-        conf.ADD_CFLAGS('-Wall -g -Wfatal-errors -DDEVELOPER -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k')
+        conf.ADD_CFLAGS('-Wall -g -Wfatal-errors -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k')
 
     conf.SAMBA_CONFIG_H()
     conf.SAMBA_BUILD_ENV()
@@ -245,6 +273,16 @@ def configure(conf):
                         cflags=conf.env.VISIBILITY_CFLAGS,
                         define='HAVE_VISIBILITY_ATTR')
 
+    if conf.CHECK_FUNCS('getpass getpassphrase'):
+        # if we have both, then we prefer getpassphrase
+        conf.DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1)
+        conf.DEFINE(REPLACE_GETPASS, 1)
+
+    conf.CHECK_CODE('''#include "getpass.c"
+                       int main(void) { return 0; }''',
+                    addmain=False,
+                    define='REPLACE_GETPASS',
+                    cflags='-DNO_CONFIG_H')
 
 def build(bld):
     bld.set_rpath()
@@ -258,7 +296,8 @@ def build(bld):
 
     bld.SAMBA_LIBRARY('replace',
                       source=REPLACE_SOURCE,
-                      group='base_libraries')
+                      group='base_libraries',
+                      deps='LIBREPLACE_GETPASS')
 
     TEST_SOURCES = '''test/testsuite.c test/main.c test/strptime.c
                       test/os2_delete.c test/getifaddrs.c'''
@@ -274,10 +313,15 @@ def build(bld):
     if bld.CONFIG_SET('HAVE_INET_PTON'):  NET_SOURCES.append('inet_pton.c')
     if bld.CONFIG_SET('HAVE_SOCKETPAIR'): NET_SOURCES.append('socketpair.c')
 
-    bld.SAMBA_SUBSYSTEM('LIBREPLACE_NETWORK', NET_SOURCES)
+    bld.SAMBA_SUBSYSTEM('LIBREPLACE_NETWORK', NET_SOURCES, deps='replace')
 
 
     CRYPT_SOURCES = []
     if not 'HAVE_CRYPT' in bld.env: CRYPT_SOURCES.append('crypt.c')
 
     bld.SAMBA_SUBSYSTEM('LIBREPLACE_EXT', CRYPT_SOURCES)
+
+    bld.SAMBA_SUBSYSTEM('LIBREPLACE_GETPASS', 'getpass.c',
+                        enabled=bld.CONFIG_SET('REPLACE_GETPASS'))
+
+    bld.CHECK_PROJECT_RULES()