build: add cflags from pkg_config results to header/function tests
authorAndrew Tridgell <tridge@samba.org>
Tue, 23 Mar 2010 17:48:32 +0000 (04:48 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:27:01 +0000 (20:27 +1000)
When we find a package with pkg_config we may need to use the
resulting ccflags and ldflags in later tests.

Support this by adding lib= options to CHECK_FUNC and CHECK_HEADER

This gets gnutls on FreeBSD working

buildtools/wafsamba/samba_autoconf.py
buildtools/wafsamba/samba_utils.py
lib/replace/wscript
source4/lib/tls/wscript

index fa241093637ce88da1aa7e3e7abbc1a3244268b8..aafa4c8c6b3fc899503ef07bb1fad037578b5e23 100644 (file)
@@ -40,7 +40,7 @@ def nolink(self):
     pass
 
 
     pass
 
 
-def CHECK_HEADER(conf, h, add_headers=False):
+def CHECK_HEADER(conf, h, add_headers=False, lib=None):
     '''check for a header'''
     if h in missing_headers:
         return False
     '''check for a header'''
     if h in missing_headers:
         return False
@@ -53,10 +53,13 @@ def CHECK_HEADER(conf, h, add_headers=False):
                 conf.env.hlist.append(h)
         return True
 
                 conf.env.hlist.append(h)
         return True
 
+    (ccflags, ldflags) = library_flags(conf, lib)
+
     hdrs = hlist_to_string(conf, headers=h)
     ret = conf.check(fragment='%s\nint main(void) { return 0; }' % hdrs,
                      type='nolink',
                      execute=0,
     hdrs = hlist_to_string(conf, headers=h)
     ret = conf.check(fragment='%s\nint main(void) { return 0; }' % hdrs,
                      type='nolink',
                      execute=0,
+                     ccflags=ccflags,
                      msg="Checking for header %s" % h)
     if not ret:
         missing_headers.add(h)
                      msg="Checking for header %s" % h)
     if not ret:
         missing_headers.add(h)
@@ -69,7 +72,7 @@ def CHECK_HEADER(conf, h, add_headers=False):
 
 
 @conf
 
 
 @conf
-def CHECK_HEADERS(conf, headers, add_headers=False, together=False):
+def CHECK_HEADERS(conf, headers, add_headers=False, together=False, lib=None):
     '''check for a list of headers
 
     when together==True, then the headers accumulate within this test.
     '''check for a list of headers
 
     when together==True, then the headers accumulate within this test.
@@ -82,25 +85,25 @@ def CHECK_HEADERS(conf, headers, add_headers=False, together=False):
     else:
         set_add_headers = add_headers
     for hdr in TO_LIST(headers):
     else:
         set_add_headers = add_headers
     for hdr in TO_LIST(headers):
-        if not CHECK_HEADER(conf, hdr, set_add_headers):
+        if not CHECK_HEADER(conf, hdr, set_add_headers, lib=lib):
             ret = False
     if not add_headers and together:
         conf.env.hlist = saved_hlist
     return ret
 
 
             ret = False
     if not add_headers and together:
         conf.env.hlist = saved_hlist
     return ret
 
 
-def header_list(conf, headers=None):
+def header_list(conf, headers=None, lib=None):
     '''form a list of headers which exist, as a string'''
     hlist=[]
     if headers is not None:
         for h in TO_LIST(headers):
     '''form a list of headers which exist, as a string'''
     hlist=[]
     if headers is not None:
         for h in TO_LIST(headers):
-            if CHECK_HEADER(conf, h, add_headers=False):
+            if CHECK_HEADER(conf, h, add_headers=False, lib=lib):
                 hlist.append(h)
     return hlist_to_string(conf, headers=hlist)
 
 
 @conf
                 hlist.append(h)
     return hlist_to_string(conf, headers=hlist)
 
 
 @conf
-def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None):
+def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None, lib=None):
     '''check for a single type'''
     if define is None:
         define = 'HAVE_' + t.upper().replace(' ', '_')
     '''check for a single type'''
     if define is None:
         define = 'HAVE_' + t.upper().replace(' ', '_')
@@ -110,6 +113,7 @@ def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None):
                      headers=headers,
                      msg='Checking for %s' % t,
                      local_include=False,
                      headers=headers,
                      msg='Checking for %s' % t,
                      local_include=False,
+                     lib=lib,
                      link=False)
     if not ret and alternate:
         conf.DEFINE(t, alternate)
                      link=False)
     if not ret and alternate:
         conf.DEFINE(t, alternate)
@@ -117,11 +121,12 @@ def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None):
 
 
 @conf
 
 
 @conf
-def CHECK_TYPES(conf, list, headers=None, define=None, alternate=None):
+def CHECK_TYPES(conf, list, headers=None, define=None, alternate=None, lib=None):
     '''check for a list of types'''
     ret = True
     for t in TO_LIST(list):
     '''check for a list of types'''
     ret = True
     for t in TO_LIST(list):
-        if not CHECK_TYPE(conf, t, headers=headers, define=define, alternate=alternate):
+        if not CHECK_TYPE(conf, t, headers=headers,
+                          define=define, alternate=alternate, lib=lib):
             ret = False
     return ret
 
             ret = False
     return ret
 
@@ -133,7 +138,8 @@ def CHECK_TYPE_IN(conf, t, headers=None, alternate=None, define=None):
 
 
 @conf
 
 
 @conf
-def CHECK_VARIABLE(conf, v, define=None, always=False, headers=None, msg=None):
+def CHECK_VARIABLE(conf, v, define=None, always=False,
+                   headers=None, msg=None, lib=None):
     '''check for a variable declaration (or define)'''
     if define is None:
         define = 'HAVE_%s' % v.upper()
     '''check for a variable declaration (or define)'''
     if define is None:
         define = 'HAVE_%s' % v.upper()
@@ -152,6 +158,7 @@ def CHECK_VARIABLE(conf, v, define=None, always=False, headers=None, msg=None):
                       link=False,
                       msg=msg,
                       local_include=False,
                       link=False,
                       msg=msg,
                       local_include=False,
+                      lib=lib,
                       headers=headers,
                       define=define,
                       always=always)
                       headers=headers,
                       define=define,
                       always=always)
@@ -261,10 +268,10 @@ def CHECK_CODE(conf, code, define,
         return True
 
     if headers is not None:
         return True
 
     if headers is not None:
-        CHECK_HEADERS(conf, headers=headers)
+        CHECK_HEADERS(conf, headers=headers, lib=lib)
 
     if add_headers:
 
     if add_headers:
-        hdrs = header_list(conf, headers=headers)
+        hdrs = header_list(conf, headers=headers, lib=lib)
     else:
         hdrs = ''
     if execute:
     else:
         hdrs = ''
     if execute:
@@ -293,16 +300,19 @@ def CHECK_CODE(conf, code, define,
     else:
         type='cprogram'
 
     else:
         type='cprogram'
 
-    if lib is not None:
-        uselib = TO_LIST(lib)
-    else:
-        uselib = []
+    uselib = TO_LIST(lib)
+
+    (ccflags, ldflags) = library_flags(conf, uselib)
+
+    cflags = TO_LIST(cflags)
+    cflags.extend(ccflags)
 
     ret = conf.check(fragment=fragment,
                      execute=execute,
                      define_name = define,
                      mandatory = mandatory,
 
     ret = conf.check(fragment=fragment,
                      execute=execute,
                      define_name = define,
                      mandatory = mandatory,
-                     ccflags=TO_LIST(cflags),
+                     ccflags=cflags,
+                     ldflags=ldflags,
                      includes=includes,
                      uselib=uselib,
                      type=type,
                      includes=includes,
                      uselib=uselib,
                      type=type,
@@ -359,16 +369,34 @@ def CONFIG_SET(conf, option):
 Build.BuildContext.CONFIG_SET = CONFIG_SET
 
 
 Build.BuildContext.CONFIG_SET = CONFIG_SET
 
 
+def library_flags(conf, libs):
+    '''work out flags from pkg_config'''
+    ccflags = []
+    ldflags = []
+    for lib in TO_LIST(libs):
+        inc_path = None
+        inc_path = getattr(conf.env, 'CPPPATH_%s' % lib.upper(), [])
+        lib_path = getattr(conf.env, 'LIBPATH_%s' % lib.upper(), [])
+        for i in inc_path:
+            ccflags.append('-I%s' % i)
+        for l in lib_path:
+            ldflags.append('-L%s' % l)
+    return (ccflags, ldflags)
+
+
 @conf
 @conf
-def CHECK_LIB(conf, libs):
+def CHECK_LIB(conf, libs, mandatory=False):
     '''check if a set of libraries exist'''
     '''check if a set of libraries exist'''
-    liblist   = TO_LIST(library)
 
 
+    liblist  = TO_LIST(libs)
     ret = True
     for lib in liblist[:]:
         if GET_TARGET_TYPE(conf, lib):
             continue
     ret = True
     for lib in liblist[:]:
         if GET_TARGET_TYPE(conf, lib):
             continue
-        if not conf.check(lib=lib, uselib_store=lib):
+
+        (ccflags, ldflags) = library_flags(conf, lib)
+
+        if not conf.check(lib=lib, uselib_store=lib, ccflags=ccflags, ldflags=ldflags):
             conf.ASSERT(not mandatory,
                         "Mandatory library '%s' not found for functions '%s'" % (lib, list))
             # if it isn't a mandatory library, then remove it from dependency lists
             conf.ASSERT(not mandatory,
                         "Mandatory library '%s' not found for functions '%s'" % (lib, list))
             # if it isn't a mandatory library, then remove it from dependency lists
@@ -416,23 +444,14 @@ def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False, header
                 SET_TARGET_TYPE(conf, lib, 'EMPTY')
         return True
 
                 SET_TARGET_TYPE(conf, lib, 'EMPTY')
         return True
 
-    ret = True
+    conf.CHECK_LIB(liblist)
     for lib in liblist[:]:
     for lib in liblist[:]:
-        if GET_TARGET_TYPE(conf, lib):
-            continue
-        if not conf.check(lib=lib, uselib_store=lib):
+        if not GET_TARGET_TYPE(conf, lib) == 'SYSLIB':
             conf.ASSERT(not mandatory,
                         "Mandatory library '%s' not found for functions '%s'" % (lib, list))
             # if it isn't a mandatory library, then remove it from dependency lists
             conf.ASSERT(not mandatory,
                         "Mandatory library '%s' not found for functions '%s'" % (lib, list))
             # if it isn't a mandatory library, then remove it from dependency lists
-            SET_TARGET_TYPE(conf, lib, 'EMPTY')
-            ret = False
-        else:
-            conf.define('HAVE_LIB%s' % lib.upper().replace('-','_'), 1)
-            conf.env['LIB_' + lib.upper()] = lib
-            LOCAL_CACHE_SET(conf, 'TARGET_TYPE', lib, 'SYSLIB')
-
-    if not ret:
-        return ret
+            liblist.remove(lib)
+            continue
 
     ret = True
     for f in remaining:
 
     ret = True
     for f in remaining:
index 8bd913f7202f90cabe4cdf12f2435b0b590f7c0e..fe290a33e17bed22b722c5c0efe53ed4ff56480c 100644 (file)
@@ -236,6 +236,8 @@ def unique_list(seq):
 
 def TO_LIST(str):
     '''Split a list, preserving quoted strings and existing lists'''
 
 def TO_LIST(str):
     '''Split a list, preserving quoted strings and existing lists'''
+    if str is None:
+        return []
     if isinstance(str, list):
         return str
     lst = str.split()
     if isinstance(str, list):
         return str
     lst = str.split()
index 63f96313dd92184d8ba2662f7ab8053598836d36..6be82570161b808dd44e5ed3ec84998821405541 100644 (file)
@@ -112,7 +112,7 @@ def configure(conf):
     conf.CHECK_HEADERS('crypt.h locale.h acl/libacl.h compat.h')
     conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h')
     conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')
     conf.CHECK_HEADERS('crypt.h locale.h acl/libacl.h compat.h')
     conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h')
     conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')
-    conf.CHECK_HEADERS('libaio.h locale.h ndir.h net/if.h pwd.h')
+    conf.CHECK_HEADERS('libaio.h locale.h ndir.h pwd.h')
     conf.CHECK_HEADERS('shadow.h sys/acl.h')
     conf.CHECK_HEADERS('sys/attributes.h sys/capability.h sys/dir.h sys/epoll.h')
     conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h sys/fs/vx/quota.h')
     conf.CHECK_HEADERS('shadow.h sys/acl.h')
     conf.CHECK_HEADERS('sys/attributes.h sys/capability.h sys/dir.h sys/epoll.h')
     conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h sys/fs/vx/quota.h')
@@ -123,11 +123,12 @@ def configure(conf):
     conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
     conf.CHECK_HEADERS('sys/time.h time.h stdarg.h vararg.h sys/mount.h mntent.h')
     conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
     conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
     conf.CHECK_HEADERS('sys/time.h time.h stdarg.h vararg.h sys/mount.h mntent.h')
     conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
-    conf.CHECK_HEADERS('sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h')
-    conf.CHECK_HEADERS('netinet/ip.h netinet/tcp.h netinet/in_ip.h sys/sockio.h sys/un.h')
+    conf.CHECK_HEADERS('''sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h
+                          netinet/ip.h netinet/tcp.h netinet/in_ip.h
+                          sys/sockio.h sys/un.h''', together=True)
     conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h')
     conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h')
     conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h')
     conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h')
-    conf.CHECK_HEADERS('resolv.h libintl.h errno.h')
+    conf.CHECK_HEADERS('libintl.h errno.h')
     conf.CHECK_HEADERS('gcrypt.h getopt.h iconv.h')
     conf.CHECK_HEADERS('sys/inotify.h memory.h nss.h popt.h sasl/sasl.h')
     conf.CHECK_HEADERS('security/pam_appl.h sys/inotify.h zlib.h asm/unistd.h')
     conf.CHECK_HEADERS('gcrypt.h getopt.h iconv.h')
     conf.CHECK_HEADERS('sys/inotify.h memory.h nss.h popt.h sasl/sasl.h')
     conf.CHECK_HEADERS('security/pam_appl.h sys/inotify.h zlib.h asm/unistd.h')
@@ -231,10 +232,16 @@ def configure(conf):
     conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
     conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
 
     conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
     conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
 
-    conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl', checklibc=True, headers='dlfcn.h dl.h')
+    conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl',
+                        checklibc=True, headers='dlfcn.h dl.h')
     conf.CHECK_FUNCS_IN('poptGetContext', 'popt')
     conf.CHECK_FUNCS_IN('poptGetContext', 'popt')
+
+    # these headers need to be tested as a group on freebsd
+    conf.CHECK_HEADERS(headers='sys/socket.h net/if.h', together=True)
+    conf.CHECK_HEADERS(headers='netinet/in.h arpa/nameser.h resolv.h', together=True)
     conf.CHECK_FUNCS_IN('res_search', 'resolv', checklibc=True,
                         headers='netinet/in.h arpa/nameser.h resolv.h')
     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')
     conf.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc=True, headers='pthread.h')
 
     conf.CHECK_FUNCS_IN('gettext', 'intl', checklibc=True, headers='libintl.h')
     conf.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc=True, headers='pthread.h')
 
@@ -329,10 +336,24 @@ def configure(conf):
     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec', define='HAVE_STAT_TV_NSEC',
                                 headers='sys/stat.h')
     # we need the st_rdev test under two names
     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec', define='HAVE_STAT_TV_NSEC',
                                 headers='sys/stat.h')
     # we need the st_rdev test under two names
-    conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_STRUCT_STAT_ST_RDEV',
+    conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev',
+                                define='HAVE_STRUCT_STAT_ST_RDEV',
+                                headers='sys/stat.h')
+    conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_ST_RDEV',
                                 headers='sys/stat.h')
                                 headers='sys/stat.h')
-    conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_ST_RDEV', 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',
+                                   headers='sys/socket.h netinet/in.h',
+                                   define='HAVE_SOCKADDR_SA_LEN'):
+        # the old build system produced both defines
+        conf.DEFINE('HAVE_STRUCT_SOCKADDR_SA_LEN', 1)
+
+    conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_in', 'sin_len',
+                                headers='sys/socket.h netinet/in.h',
+                                define='HAVE_SOCK_SIN_LEN')
 
     conf.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;',
                     define='HAVE_UNIXSOCKET', headers='sys/socket.h sys/un.h')
 
     conf.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;',
                     define='HAVE_UNIXSOCKET', headers='sys/socket.h sys/un.h')
index 66cc762b988febb48cbc94374fec2069486da2b3..4fbbd0deaa02168ffba607a67d552d92e76b9a15 100644 (file)
@@ -15,17 +15,21 @@ def configure(conf):
     if 'HAVE_GNUTLS' in conf.env and not Options.options.disable_gnutls:
         conf.DEFINE('ENABLE_GNUTLS', 1)
 
     if 'HAVE_GNUTLS' in conf.env and not Options.options.disable_gnutls:
         conf.DEFINE('ENABLE_GNUTLS', 1)
 
-    conf.CHECK_FUNCS_IN('gnutls_global_init', 'gnutls', headers='gnutls/gnutls.h')
+    conf.CHECK_FUNCS_IN('gnutls_global_init', 'gnutls',
+                        headers='gnutls/gnutls.h')
 
     conf.CHECK_VARIABLE('gnutls_x509_crt_set_version',
                         headers='gnutls/gnutls.h gnutls/x509.h',
 
     conf.CHECK_VARIABLE('gnutls_x509_crt_set_version',
                         headers='gnutls/gnutls.h gnutls/x509.h',
-                        define='HAVE_GNUTLS_X509_CRT_SET_VERSION')
+                        define='HAVE_GNUTLS_X509_CRT_SET_VERSION',
+                        lib='gnutls')
     conf.CHECK_VARIABLE('gnutls_x509_crt_set_subject_key_id',
                         headers='gnutls/gnutls.h gnutls/x509.h',
     conf.CHECK_VARIABLE('gnutls_x509_crt_set_subject_key_id',
                         headers='gnutls/gnutls.h gnutls/x509.h',
-                        define='HAVE_GNUTLS_X509_CRT_SET_SUBJECT_KEY_ID')
+                        define='HAVE_GNUTLS_X509_CRT_SET_SUBJECT_KEY_ID',
+                        lib='gnutls')
 
     # check for gnutls_datum types
 
     # check for gnutls_datum types
-    conf.CHECK_TYPES('gnutls_datum gnutls_datum_t', headers='gnutls/gnutls.h')
+    conf.CHECK_TYPES('gnutls_datum gnutls_datum_t',
+                     headers='gnutls/gnutls.h', lib='gnutls')
 
     conf.CHECK_FUNCS_IN('gcry_control', 'gcrypt', headers='gcrypt.h')
     conf.CHECK_FUNCS_IN('gpg_err_code_from_errno', 'gpg-error')
 
     conf.CHECK_FUNCS_IN('gcry_control', 'gcrypt', headers='gcrypt.h')
     conf.CHECK_FUNCS_IN('gpg_err_code_from_errno', 'gpg-error')