1 # Automatic configuration of the UCW Library
2 # (c) 2005 Martin Mares <mj@ucw.cz>
6 Test("OS", "Checking on which OS we run", sub {
9 Fail "Unable to determine OS type" if $? || $os eq "";
13 if (Get("OS") eq "Linux") {
16 Fail "Don't know how to run on this operating system.";
21 Test("CPU_ARCH", "Checking for CPU architecture", sub {
22 my $mach = `uname -m`;
24 Fail "Unable to determine machine type" if $? || $mach eq "";
25 if ($mach =~ /^i[0-9]86$/) {
28 if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
33 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
37 # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
38 my $vendor = $pc{'vendor_id'} || "";
39 my $family = $pc{'cpu family'} || 0;
40 my $model = $pc{'model'} || 0;
41 if ($vendor eq "AuthenticAMD") {
43 if ($model >= 31) { $arch = "athlon64"; }
44 elsif ($model >= 6) { $arch = "athlon-xp"; }
45 else { $arch = "athlon"; }
47 } elsif ($vendor eq "GenuineIntel") {
48 # We don't recognize Prescott and Nocona cores yet
49 if ($family >= 15) { $arch = "pentium4"; }
50 elsif ($family >= 6) {
51 if ($model >= 7) { $arch = "pentium3"; }
52 elsif ($model >= 3) { $arch = "pentium2"; }
56 # No match on vendor, try the family
60 } elsif ($family >= 3) {
61 $arch = "i${family}86";
65 Log "(using /proc/cpuinfo) ";
67 Log "(don't understand /proc/cpuinfo) ";
70 return $arch ? $arch : "i386";
75 if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
77 ### Compiler and its Options ###
80 Test("CC", "Checking for C compiler", sub { return "gcc"; });
83 Test("GCCVER", "Checking for GCC version", sub {
85 my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
87 Fail "Unable to determine GCC version" if $? || $ver eq "";
91 # C flags: tell the compiler we're speaking C99
92 Set("CLANG" => "-std=gnu99");
95 Set("COPT" => '-O2 -fstrict-aliasing -march=$(CPU_ARCH)');
96 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
98 # C optimizations for highly exposed code
99 Set("COPT2" => '-O3');
102 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
110 # Extra flags for compiling and linking shared libraries
111 Set("CSHARED" => '-fPIC');
112 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
114 # Extra switches depending on GCC version:
115 if (Get("GCCVER") eq "3.0") {
116 } elsif (Get("GCCVER") eq "3.3") {
117 Append("CWARNS" => "-Wundef -Wredundant-decls");
118 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
119 } elsif (Get("GCCVER") eq "3.4") {
120 Append("CWARNS" => "-Wundef -Wredundant-decls");
121 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
123 Warn "Don't know anything about this GCC version, using default switches.\n";
126 if (IsSet("CONFIG_DEBUG")) {
128 Set("DEBUG_ASSERTS");
129 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
130 Set("CDEBUG" => "-ggdb");
132 # If building a release version:
133 Append("COPT" => "-fomit-frame-pointer");
134 Append("LOPT" => "-s");
137 # If debugging memory allocations:
139 #CDEBUG+=-DDEBUG_DMALLOC
142 ### CPU Type and Features ###
144 Set("CPU_LITTLE_ENDIAN");
146 Set("CPU_ALLOW_UNALIGNED");
147 Set("CPU_STRUCT_ALIGN" => 4);
148 Set("CPU_64BIT_POINTERS");