]> mj.ucw.cz Git - moe.git/blob - lib/autoconf.cfg
Added libucw from Sherlock v3.12.2.
[moe.git] / lib / autoconf.cfg
1 # Automatic configuration of the UCW Library
2 # (c) 2005--2007 Martin Mares <mj@ucw.cz>
3 # (c) 2006 Robert Spalek <robert@ucw.cz>
4
5 ### OS ###
6
7 Test("OS", "Checking on which OS we run", sub {
8         my $os = `uname`;
9         chomp $os;
10         Fail "Unable to determine OS type" if $? || $os eq "";
11         return $os;
12 });
13
14 if (Get("OS") eq "Linux") {
15         Set("CONFIG_LINUX");
16 } elsif (Get("OS") eq "Darwin") {
17         Set("CONFIG_DARWIN");
18 } else {
19         Fail "Don't know how to run on this operating system.";
20 }
21
22 ### Compiler ###
23
24 # Default compiler
25 Test("CC", "Checking for C compiler", sub { return "gcc"; });
26
27 # GCC version
28 Test("GCCVER", "Checking for GCC version", sub {
29         my $gcc = Get("CC");
30         my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)*\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
31         chomp $ver;
32         Fail "Unable to determine GCC version" if $? || $ver eq "";
33         return $ver;
34 });
35 my ($gccmaj, $gccmin) = split(/\./, Get("GCCVER"));
36 my $gccver = 1000*$gccmaj + $gccmin;
37 $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
38
39 ### CPU ###
40
41 Test("ARCH", "Checking for machine architecture", sub {
42         my $mach = `uname -m`;
43         chomp $mach;
44         Fail "Unable to determine machine type" if $? || $mach eq "";
45         if ($mach =~ /^i[0-9]86$/) {
46                 return "i386";
47         } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
48                 return "amd64";
49         } else {
50                 return "unknown";
51         }
52 });
53
54 sub parse_cpuinfo_linux() {
55         open X, "/proc/cpuinfo" || undef;
56         my %pc = ();
57         while (<X>) {
58                 chomp;
59                 /^$/ && last;
60                 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
61         }
62         close X;
63         return ($pc{'vendor_id'},
64                 $pc{'cpu family'},
65                 $pc{'model'});
66 }
67
68 sub parse_cpuinfo_darwin() {
69         @cpu = (`sysctl -n machdep.cpu.vendor`,
70                 `sysctl -n machdep.cpu.family`,
71                 `sysctl -n machdep.cpu.model`);
72         chomp @cpu;
73         return @cpu;
74 }
75
76 sub parse_cpuinfo() {
77         my @cpu;
78         if (IsSet("CONFIG_LINUX")) {
79                 @cpu = parse_cpuinfo_linux();
80         } elsif (IsSet("CONFIG_DARWIN")) {
81                 @cpu = parse_cpuinfo_darwin();
82         }
83         $cpu[0] = "" if !defined $cpu[0];
84         $cpu[1] = 0 if !defined $cpu[1];
85         $cpu[2] = 0 if !defined $cpu[2];
86         return @cpu;
87 }
88
89 Test("CPU_ARCH", "Checking for CPU architecture", sub {
90         my $mach = Get("ARCH");
91         my $arch = "";
92         if ($mach eq "i386") {
93                 Set("CPU_I386");
94                 UnSet("CPU_64BIT_POINTERS");
95                 Set("CPU_LITTLE_ENDIAN");
96                 UnSet("CPU_BIG_ENDIAN");
97                 Set("CPU_ALLOW_UNALIGNED");
98                 Set("CPU_STRUCT_ALIGN" => 4);
99                 if (IsSet("CONFIG_EXACT_CPU")) {
100                         my ($vendor, $family, $model) = parse_cpuinfo();
101                         # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
102                         if ($vendor eq "AuthenticAMD") {
103                                 if ($family >= 6) {
104                                         if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
105                                         elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
106                                         else { $arch = "athlon"; }
107                                 }
108                         } elsif ($vendor eq "GenuineIntel") {
109                                 if ($family >= 15 && $gccver >= 3003) {
110                                         if ($model >= 4) { $arch = "nocona"; }
111                                         elsif ($model >= 3) { $arch = "prescott"; }
112                                         else { $arch = "pentium4"; }
113                                 } elsif ($family == 6 && $gccver >= 3003) {
114                                         if ($model == 15) { $arch = "prescott"; }
115                                         elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
116                                         elsif ($model >= 7) { $arch = "pentium3"; }
117                                         elsif ($model >= 3) { $arch = "pentium2"; }
118                                 }
119                         }
120
121                         # No match on vendor, try the family
122                         if ($arch eq "") {
123                                 if ($family >= 6) {
124                                         $arch = "i686";
125                                 } elsif ($family >= 3) {
126                                         $arch = "i${family}86";
127                                 }
128                         }
129                         Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
130                         return $arch;
131                 } else {
132                         return "default";
133                 }
134         } elsif ($mach eq "amd64") {
135                 Set("CPU_AMD64");
136                 Set("CPU_64BIT_POINTERS");
137                 Set("CPU_LITTLE_ENDIAN");
138                 UnSet("CPU_BIG_ENDIAN");
139                 Set("CPU_ALLOW_UNALIGNED");
140                 Set("CPU_STRUCT_ALIGN" => 8);
141                 if (IsSet("CONFIG_EXACT_CPU")) {
142                         # In x86-64 world, the detection is somewhat easier so far...
143                         my ($vendor, $family, $model) = parse_cpuinfo();
144                         if ($vendor eq "AuthenticAMD") {
145                                 $arch = "athlon64";
146                         } elsif ($vendor eq "GenuineIntel") {
147                                 $arch = "nocona";
148                         }
149                         Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
150                         return $arch;
151                 } else {
152                         return "default";
153                 }
154         } else {
155                 return "unknown";
156         }
157 });
158
159 if (Get("CPU_ARCH") eq "unknown") {
160         Warn "CPU architecture not recognized, using defaults, keep fingers crossed.\n";
161 }
162
163 ### Compiler and its Options ###
164
165 # C flags: tell the compiler we're speaking C99, and disable common symbols
166 Set("CLANG" => "-std=gnu99 -fno-common");
167
168 # C optimizations
169 Set("COPT" => '-O2');
170 if (Get("CPU_ARCH") ne "unknown" && Get("CPU_ARCH") ne "default") {
171         Append("COPT", '-march=$(CPU_ARCH)');
172 }
173
174 # C optimizations for highly exposed code
175 Set("COPT2" => '-O3');
176
177 # Warnings
178 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
179 Set("CWARNS_OFF" => '');
180
181 # Linker flags
182 Set("LOPT" => "");
183
184 # Extra libraries
185 Set("LIBS" => "");
186
187 # Extra flags for compiling and linking shared libraries
188 Set("CSHARED" => '-fPIC');
189 if (IsSet("CONFIG_DARWIN")) {
190         Set("LSHARED" => '-dynamiclib -install_name lib/$(@F) -undefined dynamic_lookup');
191 } else {
192         Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
193 }
194
195 # Extra switches depending on GCC version:
196 if ($gccver == 3000) {
197         Append("COPT" => "-fstrict-aliasing");
198 } elsif ($gccver == 3003) {
199         Append("CWARNS" => "-Wundef -Wredundant-decls");
200         Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
201 } elsif ($gccver == 3004) {
202         Append("CWARNS" => "-Wundef -Wredundant-decls");
203         Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
204 } elsif ($gccver == 4000 || $gccver == 4001) {
205         Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
206         Append("CWARNS_OFF" => "-Wno-pointer-sign");
207         Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
208 } elsif ($gccver == 4002) {
209         Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
210         Append("CWARNS_OFF" => "-Wno-pointer-sign");
211         Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400 -fgnu89-inline");
212 } else {
213         Warn "Don't know anything about this GCC version, using default switches.\n";
214 }
215
216 if (IsSet("CONFIG_DEBUG")) {
217         # If debugging:
218         Set("DEBUG_ASSERTS");
219         Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
220         Set("CDEBUG" => "-ggdb");
221 } else {
222         # If building a release version:
223         Append("COPT" => "-fomit-frame-pointer");
224         Append("LOPT" => "-s");
225 }
226
227 if (IsSet("CONFIG_DARWIN")) {
228         # gcc-4.0 on Darwin doesn't set this in the gnu99 mode
229         Append("CLANG" => "-fnested-functions");
230         # Directory hierarchy of the fink project
231         Append("LIBS" => "-L/sw/lib");
232         Append("COPT" => "-I/sw/include");
233         # Fill in some constants not found in the system header files
234         Set("SOL_TCP" => 6);            # missing in /usr/include/netinet/tcp.h
235 }
236
237 # Determine page size
238 Test("CPU_PAGE_SIZE", "Determining page size", sub {
239         my $p;
240         if (IsSet("CONFIG_DARWIN")) {
241                 $p = `sysctl -n hw.pagesize`;
242                 defined $p or Fail "sysctl hw.pagesize failed";
243         } elsif (IsSet("CONFIG_LINUX")) {
244                 $p = `getconf PAGE_SIZE`;
245                 defined $p or Fail "getconf PAGE_SIZE failed";
246         }
247         chomp $p;
248         return $p;
249 });
250
251 if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
252         # Use 64-bit versions of file functions
253         Set("CONFIG_LFS");
254 }
255
256 # Decide how will lib/partmap.c work
257 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
258
259 # Option for lib/mempool.c
260 Set("POOL_IS_MMAP");
261
262 # Guess optimal bit width of the radix-sorter
263 if (Get("CPU_ARCH") eq "default" || Get("CPU_ARCH") =~ /^i[345]86$/) {
264         # This should be safe everywhere
265         Set("CONFIG_UCW_RADIX_SORTER_BITS" => 10);
266 } else {
267         # Use this on modern CPU's
268         Set("CONFIG_UCW_RADIX_SORTER_BITS" => 12);
269 }
270
271 # If debugging memory allocations:
272 #LIBS+=-lefence
273 #CDEBUG+=-DDEBUG_DMALLOC
274 #LIBS+=-ldmalloc
275
276 # Return success
277 1;