# Automatic configuration of the UCW Library
# (c) 2005 Martin Mares <mj@ucw.cz>
-Set("CC" => "gcc-3.0");
+### 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 (<X>) {
+ 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
+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/'`;
+ chomp $ver;
+ Fail "Unable to determine GCC version" if $? || $ver eq "";
+ return $ver;
+});
# C flags: tell the compiler we're speaking C99
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');
Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
# Extra switches depending on GCC version:
-# [FIXME]
-#GCCVER:=$(shell $(CC) --version | sed '2,$$d; s/^\(.* \)\?\([0-9]*\.[0-9]*\).*/\2/')
-#ifeq ($(GCCVER),3.3)
-#CWARNS+=-Wundef -Wredundant-decls
-#COPT+=-finline-limit=20000 --param max-inline-insns-auto=1000
-#endif
-#ifeq ($(GCCVER),3.4)
-#CWARNS+=-Wundef -Wredundant-decls
-#COPT+=-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400
-#endif
-
-# If debugging:
-Set("CDEBUG" => '-DDEBUG_ASSERTS -ggdb');
-#CDEBUG+=-DDEBUG_DIE_BY_ABORT
+if (Get("GCCVER") eq "3.0") {
+} elsif (Get("GCCVER") eq "3.3") {
+ Append("CWARNS" => "-Wundef -Wredundant-decls");
+ Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
+} elsif (Get("GCCVER") eq "3.4") {
+ 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 {
+ Warn "Don't know anything about this GCC version, using default switches.\n";
+}
+
+if (IsSet("CONFIG_DEBUG")) {
+ # If debugging:
+ Set("DEBUG_ASSERTS");
+ Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
+ Set("CDEBUG" => "-ggdb");
+} else {
+ # If building a release version:
+ Append("COPT" => "-fomit-frame-pointer");
+ Append("LOPT" => "-s");
+}
# If debugging memory allocations:
#LIBS+=-lefence
#CDEBUG+=-DDEBUG_DMALLOC
#LIBS+=-ldmalloc
-# If building release versions:
-#CDEBUG=
-#COPT+=-fomit-frame-pointer
-#LOPT+=-s
-
### CPU Type and Features ###
-Set("CPU_ARCH" => 'i686');
-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;