]> mj.ucw.cz Git - libucw.git/blob - lib/autoconf.cfg
Merged mainline with parallel shep-reap:
[libucw.git] / lib / autoconf.cfg
1 # Automatic configuration of the UCW Library
2 # (c) 2005 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_EXACT_CPU")) {
79                 if (IsSet("CONFIG_LINUX")) {
80                         @cpu = parse_cpuinfo_linux();
81                 } elsif (IsSet("CONFIG_DARWIN")) {
82                         @cpu = parse_cpuinfo_darwin();
83                 }
84         }
85         $cpu[0] = "" if !defined $cpu[0];
86         $cpu[1] = 0 if !defined $cpu[1];
87         $cpu[2] = 0 if !defined $cpu[2];
88         return @cpu;
89 }
90
91 Test("CPU_ARCH", "Checking for CPU architecture", sub {
92         my $mach = Get("ARCH");
93         my $arch = "";
94         if ($mach eq "i386") {
95                 Set("CPU_I386");
96                 UnSet("CPU_64BIT_POINTERS");
97                 Set("CPU_LITTLE_ENDIAN");
98                 UnSet("CPU_BIG_ENDIAN");
99                 Set("CPU_ALLOW_UNALIGNED");
100                 Set("CPU_STRUCT_ALIGN" => 4);
101                 if (my ($vendor, $family, $model) = parse_cpuinfo()) {
102                         # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
103                         if ($vendor eq "AuthenticAMD") {
104                                 if ($family >= 6) {
105                                         if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
106                                         elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
107                                         else { $arch = "athlon"; }
108                                 }
109                         } elsif ($vendor eq "GenuineIntel") {
110                                 if ($family >= 15 && $gccver >= 3003) {
111                                         if ($model >= 4) { $arch = "nocona"; }
112                                         elsif ($model >= 3) { $arch = "prescott"; }
113                                         else { $arch = "pentium4"; }
114                                 } elsif ($family == 6 && $gccver >= 3003) {
115                                         if ($model == 15) { $arch = "prescott"; }
116                                         elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
117                                         elsif ($model >= 7) { $arch = "pentium3"; }
118                                         elsif ($model >= 3) { $arch = "pentium2"; }
119                                 }
120                         }
121
122                         # No match on vendor, try the family
123                         if ($arch eq "") {
124                                 if ($family >= 6) {
125                                         $arch = "i686";
126                                 } elsif ($family >= 3) {
127                                         $arch = "i${family}86";
128                                 }
129                         }
130                         Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
131                 }
132                 return $arch;
133         } elsif ($mach eq "amd64") {
134                 Set("CPU_AMD64");
135                 Set("CPU_64BIT_POINTERS");
136                 Set("CPU_LITTLE_ENDIAN");
137                 UnSet("CPU_BIG_ENDIAN");
138                 Set("CPU_ALLOW_UNALIGNED");
139                 Set("CPU_STRUCT_ALIGN" => 8);
140                 if (my ($vendor, $family, $model) = parse_cpuinfo()) {
141                         # In x86-64 world, the detection is somewhat easier so far...
142                         if ($vendor eq "AuthenticAMD") {
143                                 $arch = "athlon64";
144                         } elsif ($vendor eq "GenuineIntel") {
145                                 $arch = "nocona";
146                         }
147                         Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
148                 }
149                 return $arch;
150         } else {
151                 return "";
152         }
153 });
154
155 ### Compiler and its Options ###
156
157 # C flags: tell the compiler we're speaking C99, and disable common symbols
158 Set("CLANG" => "-std=gnu99 -fno-common");
159
160 # C optimizations
161 Set("COPT" => '-O2');
162 if (Get("CPU_ARCH") eq "") {
163         Warn "CPU type not recognized, using defaults, keep fingers crossed.";
164 } else {
165         Append("COPT", '-march=$(CPU_ARCH)');
166 }
167
168 # C optimizations for highly exposed code
169 Set("COPT2" => '-O3');
170
171 # Warnings
172 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
173 Set("CWARNS_OFF" => '');
174
175 # Linker flags
176 Set("LOPT" => "");
177
178 # Extra libraries
179 Set("LIBS" => "");
180
181 # Extra flags for compiling and linking shared libraries
182 Set("CSHARED" => '-fPIC');
183 if (IsSet("CONFIG_DARWIN")) {
184         Set("LSHARED" => '-dynamiclib -install_name lib/$(@F) -undefined dynamic_lookup');
185 } else {
186         Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
187 }
188
189 # Extra switches depending on GCC version:
190 if ($gccver == 3000) {
191         Append("COPT" => "-fstrict-aliasing");
192 } elsif ($gccver == 3003) {
193         Append("CWARNS" => "-Wundef -Wredundant-decls");
194         Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
195 } elsif ($gccver == 3004) {
196         Append("CWARNS" => "-Wundef -Wredundant-decls");
197         Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
198 } elsif ($gccver == 4000 || $gccver == 4001) {
199         Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
200         Append("CWARNS_OFF" => "-Wno-pointer-sign");
201         Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
202 } else {
203         Warn "Don't know anything about this GCC version, using default switches.\n";
204 }
205
206 if (IsSet("CONFIG_DEBUG")) {
207         # If debugging:
208         Set("DEBUG_ASSERTS");
209         Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
210         Set("CDEBUG" => "-ggdb");
211 } else {
212         # If building a release version:
213         Append("COPT" => "-fomit-frame-pointer");
214         Append("LOPT" => "-s");
215 }
216
217 if (IsSet("CONFIG_DARWIN")) {
218         # gcc-4.0 on Darwin doesn't set this in the gnu99 mode
219         Append("CLANG" => "-fnested-functions");
220         # Directory hierarchy of the fink project
221         Append("LIBS" => "-L/sw/lib");
222         Append("COPT" => "-I/sw/include");
223         # Fill in some constants not found in the system header files
224         Set("PAGE_SIZE" => `sysctl -n hw.pagesize`);
225         Set("SOL_TCP" => 6);            #missing in /usr/include/netinet/tcp.h
226 }
227
228 if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
229         # Use 64-bit versions of file functions
230         Set("CONFIG_LFS");
231 }
232
233 # Decide how will lib/partmap.c work
234 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
235
236 # If debugging memory allocations:
237 #LIBS+=-lefence
238 #CDEBUG+=-DDEBUG_DMALLOC
239 #LIBS+=-ldmalloc
240
241 # Return success
242 1;