]> mj.ucw.cz Git - libucw.git/commitdiff
Configure: A better test for architecture type.
authorMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2008 21:41:09 +0000 (22:41 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2008 21:41:09 +0000 (22:41 +0100)
We have to ask GCC for the target architecture, because it may
differ from what uname tells us. This can happen even if we are
not cross-compiling, for example on Linux with amd64 kernel, but
i386 userspace.

ucw/perl/UCW/Configure/C.pm

index ec39630d34b6cdcd5944948511837ebd3aa7fcb1..a5b37fc78242485124b0bc53ed6c4c4077d4629d 100644 (file)
@@ -46,15 +46,27 @@ $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
 ### CPU ###
 
 Test("ARCH", "Checking for machine architecture", sub {
-       my $mach = `uname -m`;
+       #
+       # We have to ask GCC for the target architecture, because it may
+       # differ from what uname tells us. This can happen even if we are
+       # not cross-compiling, for example on Linux with amd64 kernel, but
+       # i386 userspace.
+       #
+       my $gcc = Get("CC");
+       my $mach = `$gcc -dumpmachine 2>/dev/null`;
+       if (!$? && $mach ne "") {
+               $mach =~ s/-.*//;
+       } else {
+               $mach = `uname -m`;
+               Fail "Unable to determine machine type" if $? || $mach eq "";
+       }
        chomp $mach;
-       Fail "Unable to determine machine type" if $? || $mach eq "";
        if ($mach =~ /^i[0-9]86$/) {
                return "i386";
        } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
                return "amd64";
        } else {
-               return "unknown";
+               return "unknown ($mach)";
        }
 });