1 # Automatic configuration of the UCW Library
2 # (c) 2005 Martin Mares <mj@ucw.cz>
3 # (c) 2006 Robert Spalek <robert@ucw.cz>
7 Test("OS", "Checking on which OS we run", sub {
10 Fail "Unable to determine OS type" if $? || $os eq "";
14 if (Get("OS") eq "Linux") {
16 } elsif (Get("OS") eq "Darwin") {
19 Fail "Don't know how to run on this operating system.";
25 Test("CC", "Checking for C compiler", sub { return "gcc"; });
28 Test("GCCVER", "Checking for GCC version", sub {
30 my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)*\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
32 Fail "Unable to determine GCC version" if $? || $ver eq "";
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.";
41 Test("ARCH", "Checking for machine architecture", sub {
42 my $mach = `uname -m`;
44 Fail "Unable to determine machine type" if $? || $mach eq "";
45 if ($mach =~ /^i[0-9]86$/) {
47 } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
54 sub parse_cpuinfo_linux() {
55 open X, "/proc/cpuinfo" || undef;
60 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
63 return ($pc{'vendor_id'},
68 sub parse_cpuinfo_darwin() {
69 @cpu = (`sysctl -n machdep.cpu.vendor`,
70 `sysctl -n machdep.cpu.family`,
71 `sysctl -n machdep.cpu.model`);
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();
85 $cpu[0] = "" if !defined $cpu[0];
86 $cpu[1] = 0 if !defined $cpu[1];
87 $cpu[2] = 0 if !defined $cpu[2];
91 Test("CPU_ARCH", "Checking for CPU architecture", sub {
92 my $mach = Get("ARCH");
94 if ($mach eq "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") {
105 if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
106 elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
107 else { $arch = "athlon"; }
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"; }
122 # No match on vendor, try the family
126 } elsif ($family >= 3) {
127 $arch = "i${family}86";
130 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
133 } elsif ($mach eq "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") {
144 } elsif ($vendor eq "GenuineIntel") {
147 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
155 ### Compiler and its Options ###
157 # C flags: tell the compiler we're speaking C99, and disable common symbols
158 Set("CLANG" => "-std=gnu99 -fno-common");
161 Set("COPT" => '-O2');
162 if (Get("CPU_ARCH") eq "") {
163 Warn "CPU type not recognized, using defaults, keep fingers crossed.";
165 Append("COPT", '-march=$(CPU_ARCH)');
168 # C optimizations for highly exposed code
169 Set("COPT2" => '-O3');
172 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
173 Set("CWARNS_OFF" => '');
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');
186 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
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");
203 Warn "Don't know anything about this GCC version, using default switches.\n";
206 if (IsSet("CONFIG_DEBUG")) {
208 Set("DEBUG_ASSERTS");
209 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
210 Set("CDEBUG" => "-ggdb");
212 # If building a release version:
213 Append("COPT" => "-fomit-frame-pointer");
214 Append("LOPT" => "-s");
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
228 if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
229 # Use 64-bit versions of file functions
233 # Decide how will lib/partmap.c work
234 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
236 # If debugging memory allocations:
238 #CDEBUG+=-DDEBUG_DMALLOC