X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fautoconf.cfg;h=43e4a7ec6ce94d1b861afb5b815c9a3c88fa6ef5;hb=7b52ebbcc1ef1faaeb666bf42d72604b6e84f84a;hp=668c83ea14051294f1e59f58bbee964984062028;hpb=47a0795e8a28e8ad6ff55cda89e300267d9e590c;p=libucw.git diff --git a/lib/autoconf.cfg b/lib/autoconf.cfg index 668c83ea..43e4a7ec 100644 --- a/lib/autoconf.cfg +++ b/lib/autoconf.cfg @@ -1,5 +1,6 @@ # Automatic configuration of the UCW Library -# (c) 2005 Martin Mares +# (c) 2005--2007 Martin Mares +# (c) 2006 Robert Spalek ### OS ### @@ -12,6 +13,8 @@ Test("OS", "Checking on which OS we run", sub { if (Get("OS") eq "Linux") { Set("CONFIG_LINUX"); +} elsif (Get("OS") eq "Darwin") { + Set("CONFIG_DARWIN"); } else { Fail "Don't know how to run on this operating system."; } @@ -24,7 +27,7 @@ Test("CC", "Checking for C compiler", sub { return "gcc"; }); # GCC version Test("GCCVER", "Checking for GCC version", sub { my $gcc = Get("CC"); - my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`; + my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)*\\([0-9]*\\.[0-9]*\\).*/\\2/'`; chomp $ver; Fail "Unable to determine GCC version" if $? || $ver eq ""; return $ver; @@ -48,8 +51,44 @@ Test("ARCH", "Checking for machine architecture", sub { } }); +sub parse_cpuinfo_linux() { + open X, "/proc/cpuinfo" || undef; + my %pc = (); + while () { + chomp; + /^$/ && last; + /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2; + } + close X; + return ($pc{'vendor_id'}, + $pc{'cpu family'}, + $pc{'model'}); +} + +sub parse_cpuinfo_darwin() { + @cpu = (`sysctl -n machdep.cpu.vendor`, + `sysctl -n machdep.cpu.family`, + `sysctl -n machdep.cpu.model`); + chomp @cpu; + return @cpu; +} + +sub parse_cpuinfo() { + my @cpu; + if (IsSet("CONFIG_LINUX")) { + @cpu = parse_cpuinfo_linux(); + } elsif (IsSet("CONFIG_DARWIN")) { + @cpu = parse_cpuinfo_darwin(); + } + $cpu[0] = "" if !defined $cpu[0]; + $cpu[1] = 0 if !defined $cpu[1]; + $cpu[2] = 0 if !defined $cpu[2]; + return @cpu; +} + Test("CPU_ARCH", "Checking for CPU architecture", sub { my $mach = Get("ARCH"); + my $arch = ""; if ($mach eq "i386") { Set("CPU_I386"); UnSet("CPU_64BIT_POINTERS"); @@ -57,20 +96,9 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub { UnSet("CPU_BIG_ENDIAN"); 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 () { - chomp; - /^$/ && last; - /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2; - } - close X; - + if (IsSet("CONFIG_EXACT_CPU")) { + 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 >= 3004) { $arch = "athlon64"; } @@ -78,10 +106,14 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub { 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 == 15) { $arch = "prescott"; } + elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; } + elsif ($model >= 7) { $arch = "pentium3"; } elsif ($model >= 3) { $arch = "pentium2"; } } } @@ -94,13 +126,11 @@ 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; + } else { + return "default"; } - return $arch ? $arch : "i386"; } elsif ($mach eq "amd64") { Set("CPU_AMD64"); Set("CPU_64BIT_POINTERS"); @@ -108,22 +138,38 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub { UnSet("CPU_BIG_ENDIAN"); Set("CPU_ALLOW_UNALIGNED"); Set("CPU_STRUCT_ALIGN" => 8); - return "x86-64"; + if (IsSet("CONFIG_EXACT_CPU")) { + # In x86-64 world, the detection is somewhat easier so far... + my ($vendor, $family, $model) = parse_cpuinfo(); + 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; + } else { + return "default"; + } } else { - return undef; + return "unknown"; } }); -if (!IsSet("CPU_ARCH")) { Warn "CPU type not recognized, using defaults, keep fingers crossed."; } +if (Get("CPU_ARCH") eq "unknown") { + Warn "CPU architecture not recognized, using defaults, keep fingers crossed.\n"; +} ### Compiler and its Options ### -# C flags: tell the compiler we're speaking C99 -Set("CLANG" => "-std=gnu99"); +# C flags: tell the compiler we're speaking C99, and disable common symbols +Set("CLANG" => "-std=gnu99 -fno-common"); # C optimizations Set("COPT" => '-O2'); -Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH"); +if (Get("CPU_ARCH") ne "unknown" && Get("CPU_ARCH") ne "default") { + Append("COPT", '-march=$(CPU_ARCH)'); +} # C optimizations for highly exposed code Set("COPT2" => '-O3'); @@ -140,7 +186,11 @@ Set("LIBS" => ""); # Extra flags for compiling and linking shared libraries Set("CSHARED" => '-fPIC'); -Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)'); +if (IsSet("CONFIG_DARWIN")) { + Set("LSHARED" => '-dynamiclib -install_name lib/$(@F) -undefined dynamic_lookup'); +} else { + Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)'); +} # Extra switches depending on GCC version: if ($gccver == 3000) { @@ -170,6 +220,35 @@ if (IsSet("CONFIG_DEBUG")) { Append("LOPT" => "-s"); } +if (IsSet("CONFIG_DARWIN")) { + # gcc-4.0 on Darwin doesn't set this in the gnu99 mode + Append("CLANG" => "-fnested-functions"); + # Directory hierarchy of the fink project + Append("LIBS" => "-L/sw/lib"); + 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 +} + +# Determine page size +Test("CPU_PAGE_SIZE", "Determining page size", sub { + my $p; + if (IsSet("CONFIG_DARWIN")) { + $p = `sysctl -n hw.pagesize`; + defined $p or Fail "sysctl hw.pagesize failed"; + } elsif (IsSet("CONFIG_LINUX")) { + $p = `getconf PAGE_SIZE`; + defined $p or Fail "getconf PAGE_SIZE failed"; + } + chomp $p; + return $p; +}); + +if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) { + # Use 64-bit versions of file functions + Set("CONFIG_LFS"); +} + # Decide how will lib/partmap.c work Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");