[PATCHv2] build: make wafsamba CHECK_SIZEOF cross-compile friendly

Gustavo Zacarias gustavo at zacarias.com.ar
Tue Apr 1 13:25:06 MDT 2014


Use the same trick as commit 0d9bb86293c9d39298786df095c73a6251b08b7e
We do the same array trick iteratively starting from 1 (byte) by powers
of 2 up to 32.

Signed-off-by: Gustavo Zacarias <gustavo at zacarias.com.ar>
---
v2:
* Fail if value isn't found.
---
 buildtools/wafsamba/samba_autoconf.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index e726536..1a6faea 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -306,21 +306,25 @@ def CHECK_FUNCS(conf, list, link=True, lib=None, headers=None):
 @conf
 def CHECK_SIZEOF(conf, vars, headers=None, define=None):
     '''check the size of a type'''
-    ret = True
     for v in TO_LIST(vars):
         v_define = define
+        ret = False
         if v_define is None:
             v_define = 'SIZEOF_%s' % v.upper().replace(' ', '_')
-        if not CHECK_CODE(conf,
-                          'printf("%%u", (unsigned)sizeof(%s))' % v,
+            for size in list((1, 2, 4, 8, 16, 32)):
+                if CHECK_CODE(conf,
+                          'static int test_array[1 - 2 * !(((long int)(sizeof(%s))) <= %d)];' % (v, size),
                           define=v_define,
-                          execute=True,
-                          define_ret=True,
                           quote=False,
                           headers=headers,
                           local_include=False,
-                          msg="Checking size of %s" % v):
-            ret = False
+                          msg="Checking if size of %s == %d" % (v, size)):
+                    conf.DEFINE(v_define, size)
+                    ret = True
+                    break
+            if not ret:
+                Logs.error("Couldn't determine size of '%s'" % v)
+                sys.exit(1)
     return ret
 
 @conf
-- 
1.8.3.2



More information about the samba-technical mailing list