]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/perl/UCW/Configure/C.pm
UCW::CGI: Implemented UTF-8 mode (compatible with `use utf8')
[libucw.git] / ucw / perl / UCW / Configure / C.pm
index ec39630d34b6cdcd5944948511837ebd3aa7fcb1..84c20da00680e08c4eec9aa2f45674fba0a199eb 100644 (file)
@@ -1,5 +1,5 @@
 # UCW Library configuration system: OS and C compiler
 # UCW Library configuration system: OS and C compiler
-# (c) 2005--2008 Martin Mares <mj@ucw.cz>
+# (c) 2005--2010 Martin Mares <mj@ucw.cz>
 # (c) 2006 Robert Spalek <robert@ucw.cz>
 # (c) 2008 Michal Vaner <vorner@ucw.cz>
 
 # (c) 2006 Robert Spalek <robert@ucw.cz>
 # (c) 2008 Michal Vaner <vorner@ucw.cz>
 
@@ -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 {
 ### 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;
        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 {
        if ($mach =~ /^i[0-9]86$/) {
                return "i386";
        } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
                return "amd64";
        } else {
-               return "unknown";
+               return "unknown ($mach)";
        }
 });
 
        }
 });
 
@@ -118,7 +130,8 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                                        elsif ($model >= 3) { $arch = "prescott"; }
                                        else { $arch = "pentium4"; }
                                } elsif ($family == 6 && $gccver >= 3003) {
                                        elsif ($model >= 3) { $arch = "prescott"; }
                                        else { $arch = "pentium4"; }
                                } elsif ($family == 6 && $gccver >= 3003) {
-                                       if ($model == 15) { $arch = "prescott"; }
+                                       if ($model == 23) { $arch = "nocona"; }
+                                       elsif ($model == 15) { $arch = "prescott"; }
                                        elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
                                        elsif ($model >= 7) { $arch = "pentium3"; }
                                        elsif ($model >= 3) { $arch = "pentium2"; }
                                        elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
                                        elsif ($model >= 7) { $arch = "pentium3"; }
                                        elsif ($model >= 3) { $arch = "pentium2"; }
@@ -175,7 +188,7 @@ Set("CLANG" => "-std=gnu99 -fno-common");
 # C optimizations
 Set("COPT" => '-O2');
 if (Get("CPU_ARCH") ne "unknown" && Get("CPU_ARCH") ne "default") {
 # C optimizations
 Set("COPT" => '-O2');
 if (Get("CPU_ARCH") ne "unknown" && Get("CPU_ARCH") ne "default") {
-       Append("COPT", '-march=$(CPU_ARCH)');
+       Append("COPT", '-march=' . Get("CPU_ARCH"));
 }
 
 # C optimizations for highly exposed code
 }
 
 # C optimizations for highly exposed code
@@ -243,6 +256,41 @@ if (IsSet("CONFIG_DARWIN")) {
        Append("COPT" => "-I/sw/include");
        # Fill in some constants not found in the system header files
        Set("SOL_TCP" => 6);            # missing in /usr/include/netinet/tcp.h
        Append("COPT" => "-I/sw/include");
        # Fill in some constants not found in the system header files
        Set("SOL_TCP" => 6);            # missing in /usr/include/netinet/tcp.h
+       if (IsGiven("CONFIG_DIRECT_IO") && IsSet("CONFIG_DIRECT_IO")) {
+               Fail("Direct I/O is not available on darwin");
+       } else {
+               UnSet("CONFIG_DIRECT_IO");
+       }
+       if (!IsSet("CONFIG_POSIX_REGEX") && !IsSet("CONFIG_PCRE")) {
+               Set("CONFIG_POSIX_REGEX" => 1);
+               Warn "BSD regex library on Darwin isn't compatible, using POSIX regex.\n";
+       }
+}
+
+### Compiling test programs ###
+
+sub TestCompile($$) {
+       my ($testname, $source) = @_;
+       my $dir = "conftest-$testname";
+       `rm -rf $dir && mkdir $dir`; $? and Fail "Cannot initialize $dir";
+
+       open SRC, ">$dir/conftest.c";
+       print SRC $source;
+       close SRC;
+
+       my $cmd = join(" ",
+               map { defined($_) ? $_ : "" }
+                       "cd $dir &&",
+                       Get("CC"), Get("CLANG"), Get("COPT"), Get("CEXTRA"), Get("LIBS"),
+                       "conftest.c", "-o", "conftest",
+                       ">conftest.log", "2>&1"
+               );
+       `$cmd`;
+       my $result = !$?;
+
+       `rm -rf $dir` unless Get("KEEP_CONFTEST");
+
+       return $result;
 }
 
 ### Writing C headers with configuration ###
 }
 
 ### Writing C headers with configuration ###