build: expand CHECK_CODE() function
authorAndrew Tridgell <tridge@samba.org>
Sun, 7 Mar 2010 06:00:22 +0000 (17:00 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:26:43 +0000 (20:26 +1000)
buildtools/wafsamba/samba_autoconf.py

index 3dc2a308845b3ef5034ce8a86ab8f79440d9a0f7..804e65391c47d7c908e072a0e860fe0e78995193 100644 (file)
@@ -166,9 +166,10 @@ def CHECK_SIZEOF(conf, vars, headers=None, define=None):
 
 
 @conf
-def CHECK_CODE_COMPILES(conf, code, define,
-                        always=False, headers=None):
-    '''check if some code compiles'''
+def CHECK_CODE(conf, code, define,
+               always=False, execute=False, addmain=True,
+               headers=None, msg=None):
+    '''check if some code compiles and/or runs'''
     hdrs=''
     if headers is not None:
         hlist = to_list(headers)
@@ -176,15 +177,27 @@ def CHECK_CODE_COMPILES(conf, code, define,
         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):
+
+    if execute:
+        execute = 1
+    else:
+        execute = 0
+
+    if addmain:
+        fragment='#include "confdefs.h"\n%s\n int main(void) { %s; return 0; }' % (hdrs, code)
+    else:
+        fragment='#include "confdefs.h"\n%s\n%s' % (hdrs, code)
+
+    conf.write_config_header('confdefs.h', top=True)
+
+    if msg is None:
+        msg="Checking for %s" % define
+
+    if conf.check(fragment=fragment,
+                  execute=execute,
+                  ccflags='-I%s' % conf.curdir,
+                  includes='# . ../default',
+                  msg=msg):
         conf.DEFINE(define, 1)
         return True
     elif always: