build: add a check for _ss_family as it used on aix to replace ss_family
[metze/samba/wip.git] / lib / replace / wscript
index fef366317cd3dba045c071d270e30ff3fa3957dc..7b309408b3ce763c281d76c13eed3c08b8d4f84a 100644 (file)
@@ -20,13 +20,15 @@ samba_dist.DIST_DIRS('lib/replace buildtools:buildtools')
 
 def set_options(opt):
     opt.BUILTIN_DEFAULT('NONE')
-    opt.BUNDLED_EXTENSION_DEFAULT('')
+    opt.PRIVATE_EXTENSION_DEFAULT('')
     opt.RECURSE('buildtools/wafsamba')
 
 @wafsamba.runonce
 def configure(conf):
     conf.RECURSE('buildtools/wafsamba')
 
+    conf.env.standalone_replace = conf.IN_LAUNCH_DIR()
+
     conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1)
 
     # on Tru64 certain features are only available with _OSF_SOURCE set to 1
@@ -71,8 +73,10 @@ def configure(conf):
 
     conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
     conf.CHECK_TYPE('_Bool', define='HAVE__Bool')
+    conf.CHECK_TYPE('bool', define='HAVE_BOOL')
 
     conf.CHECK_TYPE('int8_t', 'char')
+    conf.CHECK_TYPE('uint8_t', 'unsigned char')
     conf.CHECK_TYPE('int16_t', 'short')
     conf.CHECK_TYPE('uint16_t', 'unsigned short')
     conf.CHECK_TYPE('int32_t', 'int')
@@ -83,11 +87,15 @@ def configure(conf):
     conf.CHECK_TYPE('ssize_t', 'int')
     conf.CHECK_TYPE('ino_t', 'unsigned')
     conf.CHECK_TYPE('loff_t', 'off_t')
-    conf.CHECK_TYPE('bool', 'off_t')
     conf.CHECK_TYPE('offset_t', 'loff_t')
     conf.CHECK_TYPE('volatile int', define='HAVE_VOLATILE')
     conf.CHECK_TYPE('uint_t', 'unsigned int')
 
+    conf.CHECK_SIZEOF('bool char int "long long" long short size_t ssize_t')
+    conf.CHECK_SIZEOF('int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t')
+    conf.CHECK_SIZEOF('void*', define='SIZEOF_VOID_P')
+    conf.CHECK_SIZEOF('off_t dev_t ino_t time_t')
+
     conf.CHECK_TYPES('socklen_t', headers='sys/socket.h')
     conf.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h')
     conf.CHECK_TYPE_IN('struct addrinfo', 'netdb.h')
@@ -131,7 +139,7 @@ def configure(conf):
                        int s = socket(AF_INET6, SOCK_STREAM, 0);
                        int ret = getaddrinfo(NULL, NULL, NULL, &ai);
                        if (ret != 0) {
-                         const char *es = gai_strerror(ret);
+                           const char *es = gai_strerror(ret);
                        }
                        freeaddrinfo(ai);
                        {
@@ -160,6 +168,23 @@ def configure(conf):
     conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
     conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
     conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq')
+    #Some OS (ie. freebsd) return EINVAL if the convertion could not be done, it's not what we expect
+    #Let's detect those cases
+    if conf.CONFIG_SET('HAVE_STRTOLL'):
+        conf.CHECK_CODE('''
+                        long long nb = strtoll("Text", NULL, 0);
+                        if (errno == EINVAL) {
+                            return 0;
+                        } else {
+                            return 1;
+                        }
+                        ''',
+                        msg="Checking correct behavior of strtoll",
+                        headers = 'errno.h',
+                        execute = True,
+                        define_ret = True,
+                        define = 'HAVE_BSD_STRTOLL',
+                        )
     conf.CHECK_FUNCS('if_nametoindex strerror_r')
     conf.CHECK_FUNCS('getdirentries getdents syslog')
     conf.CHECK_FUNCS('gai_strerror get_current_dir_name')
@@ -173,7 +198,10 @@ def configure(conf):
     conf.CHECK_C_PROTOTYPE('dlopen', 'void *dlopen(const char* filename, unsigned int flags)',
                            define='DLOPEN_TAKES_UNSIGNED_FLAGS', headers='dlfcn.h dl.h')
 
-    conf.CHECK_FUNCS_IN('fdatasync', 'rt', checklibc=True)
+    if conf.CHECK_FUNCS_IN('fdatasync', 'rt', checklibc=True):
+        # some systems are missing the declaration
+        conf.CHECK_DECLS('fdatasync')
+
     conf.CHECK_FUNCS_IN('clock_gettime', 'rt', checklibc=True)
 
     # these headers need to be tested as a group on freebsd
@@ -182,7 +210,18 @@ def configure(conf):
     conf.CHECK_FUNCS_IN('res_search', 'resolv', checklibc=True,
                         headers='netinet/in.h arpa/nameser.h resolv.h')
 
-    conf.CHECK_FUNCS_IN('gettext', 'intl', checklibc=True, headers='libintl.h')
+
+    if not conf.CHECK_FUNCS_IN('gettext', 'intl', checklibc=True, headers='libintl.h'):
+    # Some hosts need lib iconv for linking with lib intl
+    # So we try with flags just in case it helps.
+        oldflags = conf.env['LDFLAGS_INTL']
+        conf.env['LDFLAGS_INTL'] = "-liconv"
+        if not conf.CHECK_LIB('intl'):
+            conf.env['LDFLAGS_INTL'] = oldflags
+        else:
+            conf.CHECK_FUNCS_IN('gettext', 'intl', checklibc=True, headers='libintl.h')
+
+    conf.CHECK_FUNCS_IN('dgettext gettext', 'intl', headers='libintl.h')
     conf.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc=True, headers='pthread.h')
 
     conf.CHECK_FUNCS_IN('crypt', 'crypt', checklibc=True)
@@ -196,19 +235,34 @@ def configure(conf):
     conf.CHECK_DECLS('environ getgrent_r getpwent_r', reverse=True, headers='pwd.h grp.h')
     conf.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse=True)
 
-    conf.CHECK_SIZEOF('char int "long long" long off_t short size_t ssize_t')
-    conf.CHECK_SIZEOF('dev_t ino_t time_t')
-    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)
 
     if not conf.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME
-                      #include "test/strptime.c"''',
+                           #include "test/strptime.c"''',
                            define='HAVE_STRPTIME',
                            addmain=False,
                            msg='Checking for working strptime'):
         conf.DEFINE('REPLACE_STRPTIME', 1)
+    else:
+       conf.CHECK_CODE('''
+                        const char *s = "20070414101546Z";
+                        char *ret;
+                        struct tm t;
+                        memset(&t, 0, sizeof(t));
+                        ret = strptime(s, "%Y%m%d%H%M%S", &t);
+                        if (ret == NULL || t.tm_wday != 6) {
+                            return 0;
+                        } else {
+                            return 1;
+                        }
+                        ''',
+                        msg="Checking correct behavior of strptime",
+                        headers = 'time.h',
+                        execute = True,
+                        define_ret = True,
+                        define = 'REPLACE_STRPTIME',
+                        )
 
     if conf.CONFIG_SET('HAVE_KRB5_H'):
         # Check for KRB5_DEPRECATED handling
@@ -229,7 +283,7 @@ def configure(conf):
     conf.SAMBA_BUILD_ENV()
 
     conf.CHECK_CODE('''
-                   typedef struct {unsigned x;} FOOBAR;
+                    typedef struct {unsigned x;} FOOBAR;
                     #define X_FOOBAR(x) ((FOOBAR) { x })
                     #define FOO_ONE X_FOOBAR(1)
                     FOOBAR f = FOO_ONE;
@@ -254,6 +308,8 @@ def configure(conf):
                                 headers='sys/stat.h')
     conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family',
                                 headers='sys/socket.h netinet/in.h')
+    conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', '_ss_family',
+                                headers='sys/socket.h netinet/in.h')
 
 
     if conf.CHECK_STRUCTURE_MEMBER('struct sockaddr', 'sa_len',
@@ -360,21 +416,24 @@ def build(bld):
     bld.SAMBA_LIBRARY('replace',
                       source=REPLACE_SOURCE,
                       group='base_libraries',
-                                         # FIXME: Ideally symbols should be hidden here so they 
-                                         # don't appear in the global namespace when Samba 
-                                         # libraries are loaded, but this doesn't appear to work 
-                                         # at the moment:
-                                         # hide_symbols=bld.BUILTIN_LIBRARY('replace'),
+                      # FIXME: Ideally symbols should be hidden here so they 
+                      # don't appear in the global namespace when Samba 
+                      # libraries are loaded, but this doesn't appear to work 
+                      # at the moment:
+                      # hide_symbols=bld.BUILTIN_LIBRARY('replace'),
+                      private_library=True,
                       deps='crypt dl nsl socket rt')
 
-    TEST_SOURCES = '''test/testsuite.c test/main.c test/strptime.c
-                      test/os2_delete.c test/getifaddrs.c'''
-
+    bld.SAMBA_SUBSYSTEM('replace-test',
+                      source='''test/testsuite.c test/strptime.c
+                      test/os2_delete.c test/getifaddrs.c''',
+                      deps='replace')
 
-    bld.SAMBA_BINARY('replace_testsuite',
-                     TEST_SOURCES,
-                     deps='replace',
-                     install=False)
+    if bld.env.standalone_replace:
+        bld.SAMBA_BINARY('replace_testsuite',
+                         source='test/main.c',
+                         deps='replace replace-test',
+                         install=False)
 
     # build replacements for stdint.h and stdbool.h if needed
     bld.SAMBA_GENERATOR('replace_stdint_h',