]> mj.ucw.cz Git - libucw.git/blobdiff - lib/autoconf.cfg
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / autoconf.cfg
index 815583f9dbfea9789355ae9df011f2eff49294aa..39317a256fcffbad4da122cd812c63fb79c2e174 100644 (file)
@@ -35,11 +35,38 @@ $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
 
 ### CPU ###
 
-Test("CPU_ARCH", "Checking for CPU architecture", sub {
+Test("ARCH", "Checking for machine architecture", sub {
        my $mach = `uname -m`;
        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";
+       }
+});
+
+sub parse_cpuinfo() {
+       IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo" || undef;
+       my %pc = ();
+       while (<X>) {
+               chomp;
+               /^$/ && last;
+               /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
+       }
+       close X;
+
+       my $vendor = $pc{'vendor_id'} || "";
+       my $family = $pc{'cpu family'} || 0;
+       my $model  = $pc{'model'} || 0;
+       return ($vendor, $family, $model);
+}
+
+Test("CPU_ARCH", "Checking for CPU architecture", sub {
+       my $mach = Get("ARCH");
+       if ($mach eq "i386") {
                Set("CPU_I386");
                UnSet("CPU_64BIT_POINTERS");
                Set("CPU_LITTLE_ENDIAN");
@@ -47,30 +74,22 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                Set("CPU_ALLOW_UNALIGNED");
                Set("CPU_STRUCT_ALIGN" => 4);
                my $arch = "";
-               if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
-                       my %pc = ();
-                       while (<X>) {
-                               chomp;
-                               /^$/ && last;
-                               /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
-                       }
-                       close X;
-
+               if (my ($vendor, $family, $model) = parse_cpuinfo()) {
                        # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
-                       my $vendor = $pc{'vendor_id'} || "";
-                       my $family = $pc{'cpu family'} || 0;
-                       my $model  = $pc{'model'} || 0;
                        if ($vendor eq "AuthenticAMD") {
                                if ($family >= 6) {
-                                       if ($model >= 31 && $gccver >= 3003) { $arch = "athlon64"; }
+                                       if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
                                        elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
                                        else { $arch = "athlon"; }
                                }
                        } elsif ($vendor eq "GenuineIntel") {
-                               # We don't recognize Prescott and Nocona cores yet (gcc-3.4+)
-                               if ($family >= 15 && $gccver >= 3003) { $arch = "pentium4"; }
-                               elsif ($family >= 6 && $gccver >= 3003) {
-                                       if ($model >= 7) { $arch = "pentium3"; }
+                               if ($family >= 15 && $gccver >= 3003) {
+                                       if ($model >= 4) { $arch = "nocona"; }
+                                       elsif ($model >= 3) { $arch = "prescott"; }
+                                       else { $arch = "pentium4"; }
+                               } elsif ($family == 6 && $gccver >= 3003) {
+                                       if (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
+                                       elsif ($model >= 7) { $arch = "pentium3"; }
                                        elsif ($model >= 3) { $arch = "pentium2"; }
                                }
                        }
@@ -83,18 +102,32 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                                        $arch = "i${family}86";
                                }
                        }
-                       if ($arch ne "") {
-                               Log "(using /proc/cpuinfo) ";
-                       } else {
-                               Log "(don't understand /proc/cpuinfo) ";
-                       }
+                       Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
                }
                return $arch ? $arch : "i386";
+       } elsif ($mach eq "amd64") {
+               Set("CPU_AMD64");
+               Set("CPU_64BIT_POINTERS");
+               Set("CPU_LITTLE_ENDIAN");
+               UnSet("CPU_BIG_ENDIAN");
+               Set("CPU_ALLOW_UNALIGNED");
+               Set("CPU_STRUCT_ALIGN" => 8);
+               if (my ($vendor, $family, $model) = parse_cpuinfo()) {
+                       # In x86-64 world, the detection is somewhat easier so far...
+                       if ($vendor eq "AuthenticAMD") {
+                               $arch = "athlon64";
+                       } elsif ($vendor eq "GenuineIntel") {
+                               $arch = "nocona";
+                       }
+                       Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
+               }
+               return $arch ? $arch : "x86-64";
        } else {
-               return "unknown";
+               return undef;
        }
 });
-if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
+
+if (!IsSet("CPU_ARCH")) { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
 
 ### Compiler and its Options ###
 
@@ -130,8 +163,8 @@ if ($gccver == 3000) {
        Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
 } elsif ($gccver == 3004) {
        Append("CWARNS" => "-Wundef -Wredundant-decls");
-       Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
-} elsif ($gccver == 4000) {
+       Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
+} elsif ($gccver == 4000 || $gccver == 4001) {
        Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
        Append("CWARNS_OFF" => "-Wno-pointer-sign");
        Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
@@ -150,6 +183,9 @@ if (IsSet("CONFIG_DEBUG")) {
        Append("LOPT" => "-s");
 }
 
+# Decide how will lib/partmap.c work
+Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
+
 # If debugging memory allocations:
 #LIBS+=-lefence
 #CDEBUG+=-DDEBUG_DMALLOC