X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fperl%2FUCW%2FConfigure%2FC.pm;h=e3a7fdf859440f8b9d0187e3df3675b282f6241b;hb=8c416794bc7282bfc03fcc0500898aa2483c338a;hp=eb30caee8ff467535cb7dd5960146ec46be7cbe4;hpb=72fed97042cf09d12c7a2445f636694bc891fa48;p=libucw.git diff --git a/ucw/perl/UCW/Configure/C.pm b/ucw/perl/UCW/Configure/C.pm index eb30caee..e3a7fdf8 100644 --- a/ucw/perl/UCW/Configure/C.pm +++ b/ucw/perl/UCW/Configure/C.pm @@ -8,6 +8,9 @@ package UCW::Configure::C; use UCW::Configure; +use strict; +use warnings; + Test("OS", "Checking on which OS we run", sub { my $os = `uname`; chomp $os; @@ -43,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)"; } }); @@ -70,9 +85,9 @@ sub parse_cpuinfo_linux() { } sub parse_cpuinfo_darwin() { - @cpu = (`sysctl -n machdep.cpu.vendor`, - `sysctl -n machdep.cpu.family`, - `sysctl -n machdep.cpu.model`); + my @cpu = (`sysctl -n machdep.cpu.vendor`, + `sysctl -n machdep.cpu.family`, + `sysctl -n machdep.cpu.model`); chomp @cpu; return @cpu; } @@ -115,7 +130,8 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub { 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"; } @@ -240,6 +256,15 @@ 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 + 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"; + } } ### Writing C headers with configuration ### @@ -250,8 +275,8 @@ sub ConfigHeader($$) { open X, ">obj/$hdr" or Fail $!; print X "/* Generated automatically by $0, please don't touch manually. */\n"; - sub match_rules($) { - my ($name) = @_; + sub match_rules($$) { + my ($rules, $name) = @_; for (my $i=0; $i < scalar @$rules; $i++) { my ($r, $v) = ($rules->[$i], $rules->[$i+1]); return $v if $name =~ $r; @@ -260,7 +285,7 @@ sub ConfigHeader($$) { } foreach my $x (sort keys %UCW::Configure::vars) { - next unless match_rules($x); + next unless match_rules($rules, $x); my $v = $UCW::Configure::vars{$x}; # Try to add quotes if necessary $v = '"' . $v . '"' unless ($v =~ /^"/ || $v =~ /^\d*$/);