build: added functions for compound configuration testing
authorAndrew Tridgell <tridge@samba.org>
Tue, 30 Mar 2010 03:41:08 +0000 (14:41 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:27:18 +0000 (20:27 +1000)
This allows us to give a single 'Checking ...' msg for a compound
set of tests.

buildtools/wafsamba/samba_autoconf.py
buildtools/wafsamba/wscript

index c7c04f636415376326c32e3075296aefb397e1f2..4ee0852b75ac862f6720ceb481eb868ae702af43 100644 (file)
@@ -32,6 +32,43 @@ def hlist_to_string(conf, headers=None):
     return hdrs
 
 
+@conf
+def COMPOUND_START(conf, msg):
+    '''start a compound test'''
+    def null_check_message_1(self,*k,**kw):
+        return
+    def null_check_message_2(self,*k,**kw):
+        return
+
+    v = getattr(conf.env, 'in_compound', [])
+    if v != [] and v != 0:
+        conf.env.in_compound = v + 1
+        return
+    conf.check_message_1(msg)
+    conf.saved_check_message_1 = conf.check_message_1
+    conf.check_message_1 = null_check_message_1
+    conf.saved_check_message_2 = conf.check_message_2
+    conf.check_message_2 = null_check_message_2
+    conf.env.in_compound = 1
+
+
+@conf
+def COMPOUND_END(conf, result):
+    '''start a compound test'''
+    conf.env.in_compound -= 1
+    if conf.env.in_compound != 0:
+        return
+    conf.check_message_1 = conf.saved_check_message_1
+    conf.check_message_2 = conf.saved_check_message_2
+    p = conf.check_message_2
+    if result == True:
+        p('ok ')
+    elif result == False:
+        p('not found', 'YELLOW')
+    else:
+        p(result)
+
+
 @feature('nolink')
 def nolink(self):
     '''using the nolink type in conf.check() allows us to avoid
@@ -191,27 +228,27 @@ def CHECK_FUNC(conf, f, link=True, lib=None, headers=None):
     '''check for a function'''
     define='HAVE_%s' % f.upper()
 
-    # there are two ways to find a function. The first is
-    # to see if there is a declaration of the function, the
-    # 2nd is to try and link a program that calls the function
-    # unfortunately both strategies have problems.
-    # the 'check the declaration' approach works fine as long
-    # as the function has a declaraion in a header. If there is
-    # no header declaration we can get a false negative.
-    # The link method works fine as long as the compiler
-    # doesn't have a builtin for the function, which could cause
-    # a false negative due to mismatched parameters
-    # so to be sure, we need to try both
     ret = False
 
+    conf.COMPOUND_START('Checking for %s' % f)
+
     if link is None or link == True:
         ret = CHECK_CODE(conf,
-                         '''int main(void) {
-                         #ifndef %s
-                         extern void %s(void); %s();
+                         # this is based on the autoconf strategy
+                         '''
+                         #define %s __fake__%s
+                         #ifdef HAVE_LIMITS_H
+                         # include <limits.h>
+                         #else
+                         # include <assert.h>
                          #endif
-                         return 0;
-                         }''' % (f, f, f),
+                         #undef %s
+                         #if defined __stub_%s || defined __stub___%s
+                         #error "bad glibc stub"
+                         #endif
+                         extern char %s();
+                         int main() { return %s(); }
+                         ''' % (f, f, f, f, f, f, f),
                          execute=False,
                          link=True,
                          addmain=False,
@@ -222,11 +259,26 @@ def CHECK_FUNC(conf, f, link=True, lib=None, headers=None):
                          headers=headers,
                          msg='Checking for %s' % f)
 
+        if not ret:
+            ret = CHECK_CODE(conf,
+                             # it might be a macro
+                             'void *__x = (void *)%s' % f,
+                             execute=False,
+                             link=True,
+                             addmain=True,
+                             add_headers=True,
+                             define=define,
+                             local_include=False,
+                             lib=lib,
+                             headers=headers,
+                             msg='Checking for macro %s' % f)
+
     if not ret and (link is None or link == False):
         ret = CHECK_VARIABLE(conf, f,
                              define=define,
                              headers=headers,
                              msg='Checking for declaration of %s' % f)
+    conf.COMPOUND_END(ret)
     return ret
 
 
index bf2488a8801633e8d784cc303bf33991422e9cbb..89046f578f806de61cbf4540952df8e7d027b4ac 100644 (file)
@@ -127,6 +127,7 @@ def configure(conf):
                        add_headers=True)
     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
     conf.CHECK_HEADERS('ctype.h standards.h stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
+    conf.CHECK_HEADERS('limits.h assert.h')
 
     # see if we need special largefile flags
     conf.CHECK_LARGEFILE()