1 # Automatic configuration of the UCW Library
2 # (c) 2005--2008 Martin Mares <mj@ucw.cz>
3 # (c) 2006 Robert Spalek <robert@ucw.cz>
5 ### Installation paths ###
7 Log "Determining installation prefix ... ";
8 if (IsSet("CONFIG_LOCAL")) {
10 Set("INSTALL_PREFIX", "");
11 Set("INSTALL_USR_PREFIX", "");
13 Set("PREFIX", "/usr/local") unless IsSet("PREFIX");
14 my $ipx = Get("PREFIX");
16 Set("INSTALL_PREFIX", "$ipx/");
17 Set("INSTALL_USR_PREFIX", ($ipx eq "" ? "/usr/" : "$ipx/"));
18 Log Get("PREFIX") . "\n";
21 Set("INSTALL_CONFIG_DIR", '$(INSTALL_PREFIX)$(CONFIG_DIR)');
22 Set("INSTALL_BIN_DIR", '$(INSTALL_USR_PREFIX)bin');
23 Set("INSTALL_SBIN_DIR", '$(INSTALL_USR_PREFIX)sbin');
24 Set("INSTALL_LIB_DIR", '$(INSTALL_USR_PREFIX)lib');
25 Set("INSTALL_INCLUDE_DIR", '$(INSTALL_USR_PREFIX)include');
26 Set("INSTALL_PKGCONFIG_DIR", '$(INSTALL_USR_PREFIX)lib/pkgconfig');
27 Set("INSTALL_SHARE_DIR", '$(INSTALL_USR_PREFIX)share');
28 Set("INSTALL_MAN_DIR", '$(INSTALL_USR_PREFIX)share/man');
32 Test("OS", "Checking on which OS we run", sub {
35 Fail "Unable to determine OS type" if $? || $os eq "";
39 if (Get("OS") eq "Linux") {
41 } elsif (Get("OS") eq "Darwin") {
44 Fail "Don't know how to run on this operating system.";
50 Test("CC", "Checking for C compiler", sub { return "gcc"; });
53 Test("GCCVER", "Checking for GCC version", sub {
55 my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)*\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
57 Fail "Unable to determine GCC version" if $? || $ver eq "";
60 my ($gccmaj, $gccmin) = split(/\./, Get("GCCVER"));
61 my $gccver = 1000*$gccmaj + $gccmin;
62 $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
66 Test("ARCH", "Checking for machine architecture", sub {
67 my $mach = `uname -m`;
69 Fail "Unable to determine machine type" if $? || $mach eq "";
70 if ($mach =~ /^i[0-9]86$/) {
72 } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
79 sub parse_cpuinfo_linux() {
80 open X, "/proc/cpuinfo" || undef;
85 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
88 return ($pc{'vendor_id'},
93 sub parse_cpuinfo_darwin() {
94 @cpu = (`sysctl -n machdep.cpu.vendor`,
95 `sysctl -n machdep.cpu.family`,
96 `sysctl -n machdep.cpu.model`);
101 sub parse_cpuinfo() {
103 if (IsSet("CONFIG_LINUX")) {
104 @cpu = parse_cpuinfo_linux();
105 } elsif (IsSet("CONFIG_DARWIN")) {
106 @cpu = parse_cpuinfo_darwin();
108 $cpu[0] = "" if !defined $cpu[0];
109 $cpu[1] = 0 if !defined $cpu[1];
110 $cpu[2] = 0 if !defined $cpu[2];
114 Test("CPU_ARCH", "Checking for CPU architecture", sub {
115 my $mach = Get("ARCH");
117 if ($mach eq "i386") {
119 UnSet("CPU_64BIT_POINTERS");
120 Set("CPU_LITTLE_ENDIAN");
121 UnSet("CPU_BIG_ENDIAN");
122 Set("CPU_ALLOW_UNALIGNED");
123 Set("CPU_STRUCT_ALIGN" => 4);
124 if (IsSet("CONFIG_EXACT_CPU")) {
125 my ($vendor, $family, $model) = parse_cpuinfo();
126 # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
127 if ($vendor eq "AuthenticAMD") {
129 if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
130 elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
131 else { $arch = "athlon"; }
133 } elsif ($vendor eq "GenuineIntel") {
134 if ($family >= 15 && $gccver >= 3003) {
135 if ($model >= 4) { $arch = "nocona"; }
136 elsif ($model >= 3) { $arch = "prescott"; }
137 else { $arch = "pentium4"; }
138 } elsif ($family == 6 && $gccver >= 3003) {
139 if ($model == 15) { $arch = "prescott"; }
140 elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
141 elsif ($model >= 7) { $arch = "pentium3"; }
142 elsif ($model >= 3) { $arch = "pentium2"; }
146 # No match on vendor, try the family
150 } elsif ($family >= 3) {
151 $arch = "i${family}86";
154 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
159 } elsif ($mach eq "amd64") {
161 Set("CPU_64BIT_POINTERS");
162 Set("CPU_LITTLE_ENDIAN");
163 UnSet("CPU_BIG_ENDIAN");
164 Set("CPU_ALLOW_UNALIGNED");
165 Set("CPU_STRUCT_ALIGN" => 8);
166 if (IsSet("CONFIG_EXACT_CPU")) {
167 # In x86-64 world, the detection is somewhat easier so far...
168 my ($vendor, $family, $model) = parse_cpuinfo();
169 if ($vendor eq "AuthenticAMD") {
171 } elsif ($vendor eq "GenuineIntel") {
174 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
184 if (Get("CPU_ARCH") eq "unknown") {
185 Warn "CPU architecture not recognized, using defaults, keep fingers crossed.\n";
188 ### Compiler and its Options ###
190 # C flags: tell the compiler we're speaking C99, and disable common symbols
191 Set("CLANG" => "-std=gnu99 -fno-common");
194 Set("COPT" => '-O2');
195 if (Get("CPU_ARCH") ne "unknown" && Get("CPU_ARCH") ne "default") {
196 Append("COPT", '-march=$(CPU_ARCH)');
199 # C optimizations for highly exposed code
200 Set("COPT2" => '-O3');
203 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
204 Set("CWARNS_OFF" => '');
212 # Extra flags for compiling and linking shared libraries
213 Set("CSHARED" => '-fPIC');
214 if (IsSet("CONFIG_LOCAL")) {
215 Set("SONAME_PREFIX" => "lib/");
217 Set("SONAME_PREFIX" => "");
219 if (IsSet("CONFIG_DARWIN")) {
220 Set("LSHARED" => '-dynamiclib -install_name $(SONAME_PREFIX)$(@F) -undefined dynamic_lookup');
222 Set("LSHARED" => '-shared -Wl,-soname,$(SONAME_PREFIX)$(@F)');
225 # Extra switches depending on GCC version:
226 if ($gccver == 3000) {
227 Append("COPT" => "-fstrict-aliasing");
228 } elsif ($gccver == 3003) {
229 Append("CWARNS" => "-Wundef -Wredundant-decls");
230 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
231 } elsif ($gccver == 3004) {
232 Append("CWARNS" => "-Wundef -Wredundant-decls");
233 Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
234 } elsif ($gccver >= 4000) {
235 Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
236 Append("CWARNS_OFF" => "-Wno-pointer-sign");
237 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
238 if ($gccver >= 4002) {
239 Append("COPT" => "-fgnu89-inline");
242 Warn "Don't know anything about this GCC version, using default switches.\n";
245 if (IsSet("CONFIG_DEBUG")) {
247 Set("DEBUG_ASSERTS");
248 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
249 Set("CDEBUG" => "-ggdb");
251 # If building a release version:
252 Append("COPT" => "-fomit-frame-pointer");
253 Append("LOPT" => "-s");
256 if (IsSet("CONFIG_DARWIN")) {
257 # gcc-4.0 on Darwin doesn't set this in the gnu99 mode
258 Append("CLANG" => "-fnested-functions");
259 # Directory hierarchy of the fink project
260 Append("LIBS" => "-L/sw/lib");
261 Append("COPT" => "-I/sw/include");
262 # Fill in some constants not found in the system header files
263 Set("SOL_TCP" => 6); # missing in /usr/include/netinet/tcp.h
266 # Determine page size
267 Test("CPU_PAGE_SIZE", "Determining page size", sub {
269 if (IsSet("CONFIG_DARWIN")) {
270 $p = `sysctl -n hw.pagesize`;
271 defined $p or Fail "sysctl hw.pagesize failed";
272 } elsif (IsSet("CONFIG_LINUX")) {
273 $p = `getconf PAGE_SIZE`;
274 defined $p or Fail "getconf PAGE_SIZE failed";
280 if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
281 # Use 64-bit versions of file functions
285 # Decide how will lib/partmap.c work
286 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
288 # Option for lib/mempool.c
291 # Guess optimal bit width of the radix-sorter
292 if (Get("CPU_ARCH") eq "default" || Get("CPU_ARCH") =~ /^i[345]86$/) {
293 # This should be safe everywhere
294 Set("CONFIG_UCW_RADIX_SORTER_BITS" => 10);
296 # Use this on modern CPU's
297 Set("CONFIG_UCW_RADIX_SORTER_BITS" => 12);
300 # If debugging memory allocations:
302 #CDEBUG+=-DDEBUG_DMALLOC
305 # Remember PKG_CONFIG_PATH used for building, so that it will be propagated to
306 # pkg-config's run locally in the makefiles.
307 Set("PKG_CONFIG_PATH", $ENV{"PKG_CONFIG_PATH"}) if defined $ENV{"PKG_CONFIG_PATH"};