build: added CHECK_CODE_COMPILES()
authorAndrew Tridgell <tridge@samba.org>
Sun, 7 Mar 2010 05:18:33 +0000 (16:18 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:26:43 +0000 (20:26 +1000)
buildtools/wafsamba/samba_autoconf.py
lib/util/wscript_configure

index c5114e5a280523231844c309289ecdd26069c391..3dc2a308845b3ef5034ce8a86ab8f79440d9a0f7 100644 (file)
@@ -165,6 +165,33 @@ def CHECK_SIZEOF(conf, vars, headers=None, define=None):
                    msg="Checking size of %s" % v)
 
 
+@conf
+def CHECK_CODE_COMPILES(conf, code, define,
+                        always=False, headers=None):
+    '''check if some code compiles'''
+    hdrs=''
+    if headers is not None:
+        hlist = to_list(headers)
+    else:
+        hlist = conf.env.hlist
+    for h in hlist:
+        hdrs += '#include <%s>\n' % h
+    if conf.check(fragment='''
+                  %s
+                  int main(void) {
+                    %s;
+                    return 0;
+                  }
+                  ''' % (hdrs, code),
+                  execute=0,
+                  msg="Checking %s" % define):
+        conf.DEFINE(define, 1)
+        return True
+    elif always:
+        conf.DEFINE(define, 0)
+        return False
+
+
 @conf
 def CHECK_STRUCTURE_MEMBER(conf, structname, member,
                            always=False, define=None, headers=None):
index 0b2949cd83db81fe9a3b1342a2095a32bc706cf9..a2f1c256a3eb537d9906891a2c5a88d698034115 100644 (file)
@@ -10,3 +10,5 @@ conf.CHECK_HEADERS('sys/attributes.h attr/xattr.h sys/xattr.h')
 conf.CHECK_FUNCS_IN('flistxattr', 'attr', checklibc=True)
 
 conf.CHECK_STRUCTURE_MEMBER('struct statvfs', 'f_frsize', define='HAVE_FRSIZE')
+
+conf.CHECK_CODE_COMPILES('gettimeofday(NULL, NULL)', 'HAVE_GETTIMEOFDAY_TZ')