build: fixed uname output to be on target machine when cross compiling
authorAndrew Tridgell <tridge@samba.org>
Wed, 21 Apr 2010 05:15:55 +0000 (15:15 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 21 Apr 2010 05:16:01 +0000 (15:16 +1000)
this also makes the output of define_ret configure tests show up
in the configure output

buildtools/wafsamba/samba_autoconf.py
buildtools/wafsamba/samba_conftests.py
buildtools/wafsamba/samba_cross.py
buildtools/wafsamba/wscript

index fa58e8f2499a0bf5730e62da1253e6ebea5a11e7..c35db9b45fba966427d0ef26020d5da5498fd887 100644 (file)
@@ -307,7 +307,7 @@ def CHECK_SIZEOF(conf, vars, headers=None, define=None):
         if v_define is None:
             v_define = 'SIZEOF_%s' % v.upper().replace(' ', '_')
         if not CHECK_CODE(conf,
-                          'printf("%%u\\n", (unsigned)sizeof(%s))' % v,
+                          'printf("%%u", (unsigned)sizeof(%s))' % v,
                           define=v_define,
                           execute=True,
                           define_ret=True,
@@ -326,7 +326,8 @@ def CHECK_CODE(conf, code, define,
                add_headers=True, mandatory=False,
                headers=None, msg=None, cflags='', includes='# .',
                local_include=True, lib=None, link=True,
-               define_ret=False, quote=False):
+               define_ret=False, quote=False,
+               on_target=True):
     '''check if some code compiles and/or runs'''
 
     if CONFIG_SET(conf, define):
@@ -372,7 +373,12 @@ def CHECK_CODE(conf, code, define,
     cflags = TO_LIST(cflags)
     cflags.extend(ccflags)
 
-    exec_args = conf.SAMBA_CROSS_ARGS(msg=msg)
+    if on_target:
+        exec_args = conf.SAMBA_CROSS_ARGS(msg=msg)
+    else:
+        exec_args = []
+
+    conf.COMPOUND_START(msg)
 
     ret = conf.check(fragment=fragment,
                      execute=execute,
@@ -394,9 +400,13 @@ def CHECK_CODE(conf, code, define,
     if ret:
         if not define_ret:
             conf.DEFINE(define, 1)
+            conf.COMPOUND_END(True)
+        else:
+            conf.COMPOUND_END(conf.env[define])
         return True
     if always:
         conf.DEFINE(define, 0)
+    conf.COMPOUND_END(False)
     return False
 
 
index 17947582eb388e6acf0a6de8868f682002f61a52..ecdf8e7abd2872a63ef36a1615f8e0744c9ef9ae 100644 (file)
@@ -240,15 +240,19 @@ WriteMakefile(
 
 
 @conf
-def CHECK_UNAME(conf, flags=None, msg=None, define=None):
-    '''return uname result'''
-    cmd = ['uname']
-    if flags is not None:
-        cmd.append(flags)
+def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True):
+    '''run a command and return result'''
     if msg is None:
-        msg = 'Checking uname'
+        msg = 'Checking %s' % ' '.join(cmd)
     conf.COMPOUND_START(msg)
-    ret = Utils.cmd_output(cmd)
+    cmd = cmd[:]
+    if on_target:
+        cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
+    try:
+        ret = Utils.cmd_output(cmd)
+    except:
+        conf.COMPOUND_END(False)
+        return False
     ret = ret.strip()
     conf.COMPOUND_END(ret)
     if define:
@@ -256,3 +260,22 @@ def CHECK_UNAME(conf, flags=None, msg=None, define=None):
     return ret
 
 
+@conf
+def CHECK_UNAME(conf):
+    '''setup SYSTEM_UNAME_* defines'''
+    ret = True
+    for v in "sysname machine release version".split():
+        if not conf.CHECK_CODE('''
+                               struct utsname n;
+                               if (uname(&n) != 0) return -1;
+                               printf("%%s", n.%s);
+                               ''' % v,
+                               define='SYSTEM_UNAME_%s' % v.upper(),
+                               execute=True,
+                               define_ret=True,
+                               quote=True,
+                               headers='sys/utsname.h',
+                               local_include=False,
+                               msg="Checking uname %s type" % v):
+            ret = False
+    return ret
index b20555f673d77dc7c0b3eae2077645069e422674..3838e34ec48244d093e48c17f5ebdc2d302f45f4 100644 (file)
@@ -96,7 +96,7 @@ class cross_Popen(Utils.pproc.Popen):
                 global cross_answers_incomplete
                 cross_answers_incomplete = True
             (retcode, retstring) = ans
-            args = ['/bin/sh', '-c', "echo '%s'; exit %d" % (retstring, retcode)]
+            args = ['/bin/sh', '-c', "echo -n '%s'; exit %d" % (retstring, retcode)]
         real_Popen.__init__(*(obj, args), **kw)
 
 
index 66e1ae518ee197df11c9c097fee32896696629aa..72e0e90fbf36890d784514a49f116e7bc7f6811a 100644 (file)
@@ -130,9 +130,6 @@ def configure(conf):
     conf.check_tool('gnu_dirs')
     conf.check_tool('wafsamba')
 
-    conf.CHECK_UNAME(msg='Checking system type', define='SYSTEM_UNAME')
-    conf.CHECK_UNAME(flags='-a')
-
     conf.CHECK_CC_ENV()
 
     conf.check_tool('compiler_cc')
@@ -177,8 +174,14 @@ def configure(conf):
     if Options.options.ABI_CHECK_DISABLE:
         conf.env.ABI_CHECK = False
 
+    conf.CHECK_COMMAND(['uname', '-a'],
+                       msg='Checking build system',
+                       define='BUILD_SYSTEM',
+                       on_target=False)
+    conf.CHECK_UNAME()
+
     # see if we can compile and run a simple C program
-    conf.CHECK_CODE('printf("hello world\\n")',
+    conf.CHECK_CODE('printf("hello world")',
                     define='HAVE_SIMPLE_C_PROG',
                     mandatory=True,
                     execute=True,