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.";
22 Test("CC", "Checking for C compiler", sub { return "gcc"; });
25 Test("GCCVER", "Checking for GCC version", sub {
27 my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
29 Fail "Unable to determine GCC version" if $? || $ver eq "";
32 my ($gccmaj, $gccmin) = split(/\./, Get("GCCVER"));
33 my $gccver = 1000*$gccmaj + $gccmin;
34 $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
38 Test("CPU_ARCH", "Checking for CPU architecture", sub {
39 my $mach = `uname -m`;
41 Fail "Unable to determine machine type" if $? || $mach eq "";
42 if ($mach =~ /^i[0-9]86$/) {
45 if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
50 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
54 # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
55 my $vendor = $pc{'vendor_id'} || "";
56 my $family = $pc{'cpu family'} || 0;
57 my $model = $pc{'model'} || 0;
58 if ($vendor eq "AuthenticAMD") {
60 if ($model >= 31 && $gccver >= 3003) { $arch = "athlon64"; }
61 elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
62 else { $arch = "athlon"; }
64 } elsif ($vendor eq "GenuineIntel") {
65 # We don't recognize Prescott and Nocona cores yet (gcc-3.4+)
66 if ($family >= 15 && $gccver >= 3003) { $arch = "pentium4"; }
67 elsif ($family >= 6 && $gccver >= 3003) {
68 if ($model >= 7) { $arch = "pentium3"; }
69 elsif ($model >= 3) { $arch = "pentium2"; }
73 # No match on vendor, try the family
77 } elsif ($family >= 3) {
78 $arch = "i${family}86";
82 Log "(using /proc/cpuinfo) ";
84 Log "(don't understand /proc/cpuinfo) ";
87 return $arch ? $arch : "i386";
92 if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
94 ### Compiler and its Options ###
96 # C flags: tell the compiler we're speaking C99
97 Set("CLANG" => "-std=gnu99");
100 Set("COPT" => '-O2 -fstrict-aliasing');
101 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
103 # C optimizations for highly exposed code
104 Set("COPT2" => '-O3');
107 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
115 # Extra flags for compiling and linking shared libraries
116 Set("CSHARED" => '-fPIC');
117 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
119 # Extra switches depending on GCC version:
120 if ($gccver == 3000) {
121 } elsif ($gccver == 3003) {
122 Append("CWARNS" => "-Wundef -Wredundant-decls");
123 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
124 } elsif ($gccver == 3004) {
125 Append("CWARNS" => "-Wundef -Wredundant-decls");
126 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
128 Warn "Don't know anything about this GCC version, using default switches.\n";
131 if (IsSet("CONFIG_DEBUG")) {
133 Set("DEBUG_ASSERTS");
134 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
135 Set("CDEBUG" => "-ggdb");
137 # If building a release version:
138 Append("COPT" => "-fomit-frame-pointer");
139 Append("LOPT" => "-s");
142 # If debugging memory allocations:
144 #CDEBUG+=-DDEBUG_DMALLOC
147 ### CPU Type and Features ###
149 Set("CPU_LITTLE_ENDIAN");
151 Set("CPU_ALLOW_UNALIGNED");
152 Set("CPU_STRUCT_ALIGN" => 4);
153 Set("CPU_64BIT_POINTERS");