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$/) {
44 UnSet("CPU_64BIT_POINTERS");
45 Set("CPU_LITTLE_ENDIAN");
46 UnSet("CPU_BIG_ENDIAN");
47 Set("CPU_ALLOW_UNALIGNED");
48 Set("CPU_STRUCT_ALIGN" => 4);
50 if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
55 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
59 # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
60 my $vendor = $pc{'vendor_id'} || "";
61 my $family = $pc{'cpu family'} || 0;
62 my $model = $pc{'model'} || 0;
63 if ($vendor eq "AuthenticAMD") {
65 if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
66 elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
67 else { $arch = "athlon"; }
69 } elsif ($vendor eq "GenuineIntel") {
70 # We don't recognize Prescott and Nocona cores yet (gcc-3.4+)
71 if ($family >= 15 && $gccver >= 3003) { $arch = "pentium4"; }
72 elsif ($family >= 6 && $gccver >= 3003) {
73 if ($model >= 7) { $arch = "pentium3"; }
74 elsif ($model >= 3) { $arch = "pentium2"; }
78 # No match on vendor, try the family
82 } elsif ($family >= 3) {
83 $arch = "i${family}86";
87 Log "(using /proc/cpuinfo) ";
89 Log "(don't understand /proc/cpuinfo) ";
92 return $arch ? $arch : "i386";
93 } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
95 Set("CPU_64BIT_POINTERS");
96 Set("CPU_LITTLE_ENDIAN");
97 UnSet("CPU_BIG_ENDIAN");
98 Set("CPU_ALLOW_UNALIGNED");
99 Set("CPU_STRUCT_ALIGN" => 8);
105 if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
107 ### Compiler and its Options ###
109 # C flags: tell the compiler we're speaking C99
110 Set("CLANG" => "-std=gnu99");
113 Set("COPT" => '-O2');
114 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
116 # C optimizations for highly exposed code
117 Set("COPT2" => '-O3');
120 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
121 Set("CWARNS_OFF" => '');
129 # Extra flags for compiling and linking shared libraries
130 Set("CSHARED" => '-fPIC');
131 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
133 # Extra switches depending on GCC version:
134 if ($gccver == 3000) {
135 Append("COPT" => "-fstrict-aliasing");
136 } elsif ($gccver == 3003) {
137 Append("CWARNS" => "-Wundef -Wredundant-decls");
138 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
139 } elsif ($gccver == 3004) {
140 Append("CWARNS" => "-Wundef -Wredundant-decls");
141 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
142 } elsif ($gccver == 4000) {
143 Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
144 Append("CWARNS_OFF" => "-Wno-pointer-sign");
145 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
147 Warn "Don't know anything about this GCC version, using default switches.\n";
150 if (IsSet("CONFIG_DEBUG")) {
152 Set("DEBUG_ASSERTS");
153 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
154 Set("CDEBUG" => "-ggdb");
156 # If building a release version:
157 Append("COPT" => "-fomit-frame-pointer");
158 Append("LOPT" => "-s");
161 # If debugging memory allocations:
163 #CDEBUG+=-DDEBUG_DMALLOC