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("ARCH", "Checking for machine 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 } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
52 IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo" || undef;
57 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
61 my $vendor = $pc{'vendor_id'} || "";
62 my $family = $pc{'cpu family'} || 0;
63 my $model = $pc{'model'} || 0;
64 return ($vendor, $family, $model);
67 Test("CPU_ARCH", "Checking for CPU architecture", sub {
68 my $mach = Get("ARCH");
69 if ($mach eq "i386") {
71 UnSet("CPU_64BIT_POINTERS");
72 Set("CPU_LITTLE_ENDIAN");
73 UnSet("CPU_BIG_ENDIAN");
74 Set("CPU_ALLOW_UNALIGNED");
75 Set("CPU_STRUCT_ALIGN" => 4);
77 if (my ($vendor, $family, $model) = parse_cpuinfo()) {
78 # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
79 if ($vendor eq "AuthenticAMD") {
81 if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
82 elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
83 else { $arch = "athlon"; }
85 } elsif ($vendor eq "GenuineIntel") {
86 if ($family >= 15 && $gccver >= 3003) {
87 if ($model >= 4) { $arch = "nocona"; }
88 elsif ($model >= 3) { $arch = "prescott"; }
89 else { $arch = "pentium4"; }
90 } elsif ($family == 6 && $gccver >= 3003) {
91 if (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
92 elsif ($model >= 7) { $arch = "pentium3"; }
93 elsif ($model >= 3) { $arch = "pentium2"; }
97 # No match on vendor, try the family
101 } elsif ($family >= 3) {
102 $arch = "i${family}86";
105 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
107 return $arch ? $arch : "i386";
108 } elsif ($mach eq "amd64") {
110 Set("CPU_64BIT_POINTERS");
111 Set("CPU_LITTLE_ENDIAN");
112 UnSet("CPU_BIG_ENDIAN");
113 Set("CPU_ALLOW_UNALIGNED");
114 Set("CPU_STRUCT_ALIGN" => 8);
115 if (my ($vendor, $family, $model) = parse_cpuinfo()) {
116 # In x86-64 world, the detection is somewhat easier so far...
117 if ($vendor eq "AuthenticAMD") {
119 } elsif ($vendor eq "GenuineIntel") {
122 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
124 return $arch ? $arch : "x86-64";
130 if (!IsSet("CPU_ARCH")) { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
132 ### Compiler and its Options ###
134 # C flags: tell the compiler we're speaking C99
135 Set("CLANG" => "-std=gnu99");
138 Set("COPT" => '-O2');
139 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
141 # C optimizations for highly exposed code
142 Set("COPT2" => '-O3');
145 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
146 Set("CWARNS_OFF" => '');
154 # Extra flags for compiling and linking shared libraries
155 Set("CSHARED" => '-fPIC');
156 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
158 # Extra switches depending on GCC version:
159 if ($gccver == 3000) {
160 Append("COPT" => "-fstrict-aliasing");
161 } elsif ($gccver == 3003) {
162 Append("CWARNS" => "-Wundef -Wredundant-decls");
163 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
164 } elsif ($gccver == 3004) {
165 Append("CWARNS" => "-Wundef -Wredundant-decls");
166 Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
167 } elsif ($gccver == 4000 || $gccver == 4001) {
168 Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
169 Append("CWARNS_OFF" => "-Wno-pointer-sign");
170 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
172 Warn "Don't know anything about this GCC version, using default switches.\n";
175 if (IsSet("CONFIG_DEBUG")) {
177 Set("DEBUG_ASSERTS");
178 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
179 Set("CDEBUG" => "-ggdb");
181 # If building a release version:
182 Append("COPT" => "-fomit-frame-pointer");
183 Append("LOPT" => "-s");
186 # Decide how will lib/partmap.c work
187 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
189 # If debugging memory allocations:
191 #CDEBUG+=-DDEBUG_DMALLOC