From 97bd72a420e0832463b52948d8c692ab46d88607 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 12 Apr 2005 19:05:14 +0000 Subject: [PATCH] Automatic detection of host OS and also partial automatic detection of the CPU architecture. --- build/sherlock.cfg | 3 +++ lib/autoconf.cfg | 57 +++++++++++++++++++++++++++++++++++++------ lib/perl/Configure.pm | 8 ++++-- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/build/sherlock.cfg b/build/sherlock.cfg index e09e8d92..a1ba1ceb 100644 --- a/build/sherlock.cfg +++ b/build/sherlock.cfg @@ -10,6 +10,9 @@ Set("INSTALL_DIR" => "~/run-3.5"); # Compile everything with debug information and ASSERT's UnSet("CONFIG_DEBUG"); +# Enable aggressive optimizations depending on exact CPU type (don't use for portable packages) +UnSet("CONFIG_EXACT_CPU"); + ### Standard modules available in all releases of Sherlock ### # Gatherer (the gatherer library and some utilities) [FIXME: decide automatically?] diff --git a/lib/autoconf.cfg b/lib/autoconf.cfg index fed6f6c9..7bb50c70 100644 --- a/lib/autoconf.cfg +++ b/lib/autoconf.cfg @@ -1,6 +1,54 @@ # Automatic configuration of the UCW Library # (c) 2005 Martin Mares +### OS ### + +Test("OS", "Checking on which OS we run", sub { + my $os = `uname`; + chomp $os; + Fail "Unable to determine OS type" if $? || $os eq ""; + return $os; +}); + +if (Get("OS") eq "Linux") { + Set("CONFIG_LINUX"); +} else { + Fail "Don't know how to run on this operating system."; +} + +### CPU ### + +Test("CPU_ARCH", "Checking for CPU architecture", sub { + my $mach = `uname -m`; + chomp $mach; + Fail "Unable to determine machine type" if $? || $mach eq ""; + if ($mach =~ /^i[0-9]86$/) { + Set("CPU_I386"); + 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 ($pc{'vendor_id'} eq "AuthenticAMD" && $pc{'cpu family'} >= 6) { + $arch = "i686"; + } + if ($arch ne "") { + Log "(according to /proc/cpuinfo) "; + } else { + Log "(don't understand /proc/cpuinfo) "; + } + } + return $arch ? $arch : "i386"; + } else { + return "unknown"; + } +}); +if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; } + ### Compiler and its Options ### # Default compiler @@ -20,6 +68,7 @@ Set("CLANG" => "-std=gnu99"); # C optimizations Set("COPT" => '-O2 -fstrict-aliasing -march=$(CPU_ARCH)'); +Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH"); # C optimizations for highly exposed code Set("COPT2" => '-O3'); @@ -46,7 +95,7 @@ if (Get("GCCVER") eq "3.0") { 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"); } else { - Log "WARNING: Don't know anything about this GCC version, using default switches.\n"; + Warn "Don't know anything about this GCC version, using default switches.\n"; } if (IsSet("CONFIG_DEBUG")) { @@ -67,17 +116,11 @@ if (IsSet("CONFIG_DEBUG")) { ### CPU Type and Features ### -Set("CPU_ARCH" => 'i686') if !IsSet("CPU_ARCH"); -Set("CPU_I386"); Set("CPU_LITTLE_ENDIAN"); #CPU_BIG_ENDIAN=1 Set("CPU_ALLOW_UNALIGNED"); Set("CPU_STRUCT_ALIGN" => 4); Set("CPU_64BIT_POINTERS"); -### OS Type ### - -Set("CONFIG_LINUX"); - # Return success 1; diff --git a/lib/perl/Configure.pm b/lib/perl/Configure.pm index ee1c83df..f251ce62 100644 --- a/lib/perl/Configure.pm +++ b/lib/perl/Configure.pm @@ -16,7 +16,7 @@ BEGIN { our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.0; @ISA = qw(Exporter); - @EXPORT = qw(&Init &Log &Notice &Fail &IsSet &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile); + @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile); @EXPORT_OK = qw(); %EXPORT_TAGS = (); } @@ -32,8 +32,12 @@ sub Notice($) { print @_ if $vars{"VERBOSE"}; } +sub Warn($) { + print "WARNING: ", @_; +} + sub Fail($) { - Log((shift @_) . "\n"); + Log("ERROR: " . (shift @_) . "\n"); exit 1; } -- 2.39.2