Source: tevent
Version: 0.10.2-1
Tags: patch upstream
User: debian-cr...@lists.debian.org
Usertags: ftcbfs

Thank you for applying my previous cross build patches. My previous
installment ended with:

> 5. waf has a mandatory run test for determining whether mkstemp works.
> 6. probably more

I've now looked into this and think that there are two bigger steps to
solve these. In the "probably more" department, there is a recurring
scheme of using a "CHECK_VALUEOF". It is used to determine the value of
an integer. If that value happens to be a compile time constant, it can
be determined using bisection. waf already does something similar in
CHECK_SIZEOF. I've implemented it for CHECK_VALUEOF and it now works
similar to autoconf's AC_COMPUTE_INT. In particular, it only does the
expensive bisection during cross compilation. In a native build, it
continues to use the quick run test it did before. I've attached a patch
for this.

For the mkstemp thingy there is little we can do. You cannot check this
property without running code. So during cross compilation, all you can
do is assume that it works. I think the solution will be adding

    --cross-compile --cross-answers=somefile

to the waf invocation and having it tell that mkstemp works. This is
also is similar to what autoconf does except that autoconf has
centralized this answer file into a cross-config package. Does that work
for you?

Therefore please consider applying this patch for CHECK_VALUEOF,
preferrably upstream it. For making it work in the packaging, one must
pass --cross-compile to waf. You can do so using the following snippet:

    $(if $(filter $(DEB_BUILD_ARCH),$(DEB_HOST_ARCH)),,--cross-compile)

Thank you

Helmut
--- tevent-0.10.2.orig/buildtools/wafsamba/samba_autoconf.py
+++ tevent-0.10.2/buildtools/wafsamba/samba_autoconf.py
@@ -348,16 +348,72 @@
     v_define = define
     if v_define is None:
         v_define = 'VALUEOF_%s' % v.upper().replace(' ', '_')
-    if CHECK_CODE(conf,
-                  'printf("%%u", (unsigned)(%s))' % v,
-                  define=v_define,
-                  execute=True,
-                  define_ret=True,
-                  quote=False,
-                  headers=headers,
-                  local_include=False,
-                  msg="Checking value of %s" % v):
-        return int(conf.env[v_define])
+    if conf.env.CROSS_COMPILE:
+        negative = CHECK_CODE(conf,
+                'static int test_array[1 - 2 * !((%s) < 0)];' % v,
+                define=v_define + "_negative",
+                quote=False, addmain=False, link=False,
+                headers=headers,
+                local_include=False,
+                msg="Checking if %s is negative" % v)
+        positive = CHECK_CODE(conf,
+                'static int test_array[1 - 2 * !((%s) > 0)];' % v,
+                define=v_define + "_positive",
+                quote=False, addmain=False, link=False,
+                headers=headers,
+                local_include=False,
+                msg="Checking if %s is positive" % v)
+        zero = CHECK_CODE(conf,
+                'static int test_array[1 - 2 * !((%s) == 0)];' % v,
+                define=v_define + "_zero",
+                quote=False, addmain=False, link=False,
+                headers=headers,
+                local_include=False,
+                msg="Checking if %s is zero" % v)
+        if zero + positive + negative != 1:
+            Logs.warn("Couldn't determine value of '%s'" % v)
+            return None
+        if zero:
+            return 0
+        upper_bound = 1
+        comp = ">=" if negative else "<="
+        sign = -1 if negative else 1
+        while not CHECK_CODE(conf,
+                'static int test_array[1 - 2 * !((%s) %s %d)];' %
+                         (v, comp, sign * upper_bound),
+                define=v_define + "_le_%d" % upper_bound,
+                quote=False, addmain=False, link=False,
+                headers=headers,
+                local_include=False,
+                msg="Checking if %s %s %d" % (v, comp, sign * upper_bound)):
+            upper_bound *= 2
+        lower_bound = upper_bound // 2
+        while lower_bound + 1 < upper_bound:
+            mid = (lower_bound + upper_bound) // 2
+            if CHECK_CODE(conf,
+                    'static int test_array[1 - 2 * !((%s) %s %d)];' %
+                             (v, comp, sign * mid),
+                    define=v_define + "_le_%d" % upper_bound,
+                    quote=False, addmain=False, link=False,
+                    headers=headers,
+                    local_include=False,
+                    msg="Checking if %s %s %d" % (v, comp, sign * mid)):
+                upper_bound = mid
+            else:
+                lower_bound = mid
+        conf.DEFINE(v_define, upper_bound)
+        return upper_bound
+    else:
+        if CHECK_CODE(conf,
+                      'printf("%%u", (unsigned)(%s))' % v,
+                      define=v_define,
+                      execute=True,
+                      define_ret=True,
+                      quote=False,
+                      headers=headers,
+                      local_include=False,
+                      msg="Checking value of %s" % v):
+            return int(conf.env[v_define])
 
     return None
 

Reply via email to