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", "");
12 Set("INSTALL_VAR_PREFIX", "");
14 Set("PREFIX", "/usr/local") unless IsSet("PREFIX");
15 my $ipx = Get("PREFIX");
17 Set("INSTALL_PREFIX", "$ipx/");
18 my $upx = ($ipx eq "" ? "/usr/" : "$ipx/");
19 Set("INSTALL_USR_PREFIX", $upx);
20 $upx =~ s{^/usr\b}{/var};
21 Set("INSTALL_VAR_PREFIX", $upx);
22 Log Get("PREFIX") . "\n";
25 Set("INSTALL_CONFIG_DIR", '$(INSTALL_PREFIX)$(CONFIG_DIR)');
26 Set("INSTALL_BIN_DIR", '$(INSTALL_USR_PREFIX)bin');
27 Set("INSTALL_SBIN_DIR", '$(INSTALL_USR_PREFIX)sbin');
28 Set("INSTALL_LIB_DIR", '$(INSTALL_USR_PREFIX)lib');
29 Set("INSTALL_INCLUDE_DIR", '$(INSTALL_USR_PREFIX)include');
30 Set("INSTALL_PKGCONFIG_DIR", '$(INSTALL_USR_PREFIX)lib/pkgconfig');
31 Set("INSTALL_SHARE_DIR", '$(INSTALL_USR_PREFIX)share');
32 Set("INSTALL_MAN_DIR", '$(INSTALL_USR_PREFIX)share/man');
33 Set("INSTALL_LOG_DIR", '$(INSTALL_VAR_PREFIX)log');
34 Set("INSTALL_STATE_DIR", '$(INSTALL_VAR_PREFIX)lib');
35 Set("INSTALL_RUN_DIR", '$(INSTALL_VAR_PREFIX)run');
39 Test("OS", "Checking on which OS we run", sub {
42 Fail "Unable to determine OS type" if $? || $os eq "";
46 if (Get("OS") eq "Linux") {
48 } elsif (Get("OS") eq "Darwin") {
51 Fail "Don't know how to run on this operating system.";
57 Test("CC", "Checking for C compiler", sub { return "gcc"; });
60 Test("GCCVER", "Checking for GCC version", sub {
62 my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)*\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
64 Fail "Unable to determine GCC version" if $? || $ver eq "";
67 my ($gccmaj, $gccmin) = split(/\./, Get("GCCVER"));
68 my $gccver = 1000*$gccmaj + $gccmin;
69 $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
73 Test("ARCH", "Checking for machine architecture", sub {
74 my $mach = `uname -m`;
76 Fail "Unable to determine machine type" if $? || $mach eq "";
77 if ($mach =~ /^i[0-9]86$/) {
79 } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
86 sub parse_cpuinfo_linux() {
87 open X, "/proc/cpuinfo" || undef;
92 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
95 return ($pc{'vendor_id'},
100 sub parse_cpuinfo_darwin() {
101 @cpu = (`sysctl -n machdep.cpu.vendor`,
102 `sysctl -n machdep.cpu.family`,
103 `sysctl -n machdep.cpu.model`);
108 sub parse_cpuinfo() {
110 if (IsSet("CONFIG_LINUX")) {
111 @cpu = parse_cpuinfo_linux();
112 } elsif (IsSet("CONFIG_DARWIN")) {
113 @cpu = parse_cpuinfo_darwin();
115 $cpu[0] = "" if !defined $cpu[0];
116 $cpu[1] = 0 if !defined $cpu[1];
117 $cpu[2] = 0 if !defined $cpu[2];
121 Test("CPU_ARCH", "Checking for CPU architecture", sub {
122 my $mach = Get("ARCH");
124 if ($mach eq "i386") {
126 UnSet("CPU_64BIT_POINTERS");
127 Set("CPU_LITTLE_ENDIAN");
128 UnSet("CPU_BIG_ENDIAN");
129 Set("CPU_ALLOW_UNALIGNED");
130 Set("CPU_STRUCT_ALIGN" => 4);
131 if (IsSet("CONFIG_EXACT_CPU")) {
132 my ($vendor, $family, $model) = parse_cpuinfo();
133 # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
134 if ($vendor eq "AuthenticAMD") {
136 if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
137 elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
138 else { $arch = "athlon"; }
140 } elsif ($vendor eq "GenuineIntel") {
141 if ($family >= 15 && $gccver >= 3003) {
142 if ($model >= 4) { $arch = "nocona"; }
143 elsif ($model >= 3) { $arch = "prescott"; }
144 else { $arch = "pentium4"; }
145 } elsif ($family == 6 && $gccver >= 3003) {
146 if ($model == 15) { $arch = "prescott"; }
147 elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
148 elsif ($model >= 7) { $arch = "pentium3"; }
149 elsif ($model >= 3) { $arch = "pentium2"; }
153 # No match on vendor, try the family
157 } elsif ($family >= 3) {
158 $arch = "i${family}86";
161 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
166 } elsif ($mach eq "amd64") {
168 Set("CPU_64BIT_POINTERS");
169 Set("CPU_LITTLE_ENDIAN");
170 UnSet("CPU_BIG_ENDIAN");
171 Set("CPU_ALLOW_UNALIGNED");
172 Set("CPU_STRUCT_ALIGN" => 8);
173 if (IsSet("CONFIG_EXACT_CPU")) {
174 # In x86-64 world, the detection is somewhat easier so far...
175 my ($vendor, $family, $model) = parse_cpuinfo();
176 if ($vendor eq "AuthenticAMD") {
178 } elsif ($vendor eq "GenuineIntel") {
181 Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
191 if (Get("CPU_ARCH") eq "unknown") {
192 Warn "CPU architecture not recognized, using defaults, keep fingers crossed.\n";
195 ### Compiler and its Options ###
197 # C flags: tell the compiler we're speaking C99, and disable common symbols
198 Set("CLANG" => "-std=gnu99 -fno-common");
201 Set("COPT" => '-O2');
202 if (Get("CPU_ARCH") ne "unknown" && Get("CPU_ARCH") ne "default") {
203 Append("COPT", '-march=$(CPU_ARCH)');
206 # C optimizations for highly exposed code
207 Set("COPT2" => '-O3');
210 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
211 Set("CWARNS_OFF" => '');
219 # Extra flags for compiling and linking shared libraries
220 Set("CSHARED" => '-fPIC');
221 if (IsSet("CONFIG_LOCAL")) {
222 Set("SONAME_PREFIX" => "lib/");
224 Set("SONAME_PREFIX" => "");
226 if (IsSet("CONFIG_DARWIN")) {
227 Set("LSHARED" => '-dynamiclib -install_name $(SONAME_PREFIX)$(@F)$(SONAME_SUFFIX) -undefined dynamic_lookup');
229 Set("LSHARED" => '-shared -Wl,-soname,$(SONAME_PREFIX)$(@F)$(SONAME_SUFFIX)');
232 # Extra switches depending on GCC version:
233 if ($gccver == 3000) {
234 Append("COPT" => "-fstrict-aliasing");
235 } elsif ($gccver == 3003) {
236 Append("CWARNS" => "-Wundef -Wredundant-decls");
237 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
238 } elsif ($gccver == 3004) {
239 Append("CWARNS" => "-Wundef -Wredundant-decls");
240 Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
241 } elsif ($gccver >= 4000) {
242 Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
243 Append("CWARNS_OFF" => "-Wno-pointer-sign");
244 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
245 if ($gccver >= 4002) {
246 Append("COPT" => "-fgnu89-inline");
249 Warn "Don't know anything about this GCC version, using default switches.\n";
252 if (IsSet("CONFIG_DEBUG")) {
254 Set("DEBUG_ASSERTS");
255 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
256 Set("CDEBUG" => "-ggdb");
258 # If building a release version:
259 Append("COPT" => "-fomit-frame-pointer");
260 Append("LOPT" => "-s");
263 if (IsSet("CONFIG_DARWIN")) {
264 # gcc-4.0 on Darwin doesn't set this in the gnu99 mode
265 Append("CLANG" => "-fnested-functions");
266 # Directory hierarchy of the fink project
267 Append("LIBS" => "-L/sw/lib");
268 Append("COPT" => "-I/sw/include");
269 # Fill in some constants not found in the system header files
270 Set("SOL_TCP" => 6); # missing in /usr/include/netinet/tcp.h
273 # Determine page size
274 Test("CPU_PAGE_SIZE", "Determining page size", sub {
276 if (IsSet("CONFIG_DARWIN")) {
277 $p = `sysctl -n hw.pagesize`;
278 defined $p or Fail "sysctl hw.pagesize failed";
279 } elsif (IsSet("CONFIG_LINUX")) {
280 $p = `getconf PAGE_SIZE`;
281 defined $p or Fail "getconf PAGE_SIZE failed";
287 if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
288 # Use 64-bit versions of file functions
292 # Decide how will ucw/partmap.c work
293 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
295 # Option for ucw/mempool.c
298 # Guess optimal bit width of the radix-sorter
299 if (Get("CPU_ARCH") eq "default" || Get("CPU_ARCH") =~ /^i[345]86$/) {
300 # This should be safe everywhere
301 Set("CONFIG_UCW_RADIX_SORTER_BITS" => 10);
303 # Use this on modern CPU's
304 Set("CONFIG_UCW_RADIX_SORTER_BITS" => 12);
307 # If debugging memory allocations:
310 # Remember PKG_CONFIG_PATH used for building, so that it will be propagated to
311 # pkg-config's run locally in the makefiles.
312 Set("PKG_CONFIG_PATH", $ENV{"PKG_CONFIG_PATH"}) if defined $ENV{"PKG_CONFIG_PATH"};