use strict;
use warnings;
+use IO::File;
BEGIN {
# The somewhat hairy Perl export mechanism
sub Log($) {
print @_;
+ STDOUT->flush;
}
sub Notice($) {
print @_ if $vars{"VERBOSE"};
+ STDOUT->flush;
}
sub Warn($) {
print "WARNING: ", @_;
+ STDOUT->flush;
}
sub Fail($) {
Log ((Get($var) ? "yes" : "no") . " (set)\n");
} else {
my ($val, $comment) = &$sub();
- Set($var, $val);
+ if ($val) {
+ Set($var);
+ } else {
+ UnSet($var);
+ }
Log (($val ? "yes" : "no") . "\n");
}
}
sub TryFindFile($) {
my ($f) = @_;
- if (-f $f) {
- return $f;
- } elsif ($f !~ /^\// && -f (Get("SRCDIR")."/$f")) {
+ if ($f =~ m{^/}) {
+ return (-f $f) ? $f : undef;
+ } elsif (-f $f) {
+ return "./$f";
+ } elsif (-f (Get("SRCDIR")."/$f")) {
return Get("SRCDIR")."/$f";
} else {
return undef;
return "i386";
} elsif ($mach =~ /^(x86[_-]|amd)64$/) {
return "amd64";
+ } elsif ($mach eq 'powerpc') {
+ return $mach;
} else {
return "unknown ($mach)";
}
UnSet("CPU_BIG_ENDIAN");
Set("CPU_ALLOW_UNALIGNED");
Set("CPU_STRUCT_ALIGN" => 8);
+} elsif ($arch eq "powerpc") {
+ Set("CPU_AMD64");
+ UnSet("CPU_64BIT_POINTERS");
+ UnSet("CPU_LITTLE_ENDIAN");
+ Set("CPU_BIG_ENDIAN");
+ UnSet("CPU_ALLOW_UNALIGNED");
+ Set("CPU_STRUCT_ALIGN" => 4);
+} elsif ($arch eq "armhf") {
+ Set("CPU_ARM");
+ UnSet("CPU_64BIT_POINTERS");
+ Set("CPU_LITTLE_ENDIAN");
+ UnSet("CPU_BIG_ENDIAN");
+ UnSet("CPU_ALLOW_UNALIGNED");
+ Set("CPU_STRUCT_ALIGN" => 4);
} elsif (!Get("CPU_LITTLE_ENDIAN") && !Get("CPU_BIG_ENDIAN")) {
Fail "Architecture not recognized, please set CPU_xxx variables manually.";
}
# Extra flags for compiling and linking shared libraries
Set("CSHARED" => '-fPIC');
-Append("LOPT" => "-Wl,--rpath-link,run/lib");
-if (Get("INSTALL_LIB_DIR") eq "/usr/lib") {
+Append("LOPT" => "-Wl,--rpath-link,run/lib -Lrun/lib");
+if (!IsSet("CONFIG_LOCAL")) {
+ # Beware that in non-local builds the INSTALL_LIB_DIR must exist in
+ # standard search paths for shared libraries.
Set("SO_LINK_PATH" => '');
}
else {
+ # In local builds, we need to link binaries with custom --rpath.
+ # GCC seems to fail when this directory does not exist.
Set("SO_LINK_PATH" => "-Wl,--rpath," . Get("INSTALL_LIB_DIR"));
AtWrite {
- # FIXME: This is a hack. GCC would otherwise fail to link binaries.
my $libdir = Get("INSTALL_LIB_DIR");
- if (IsSet("CONFIG_SHARED") && !(-d $libdir)) {
- `install -d -m 755 $libdir`; Fail("Cannot create $libdir") if $?;
+ if (IsSet("CONFIG_SHARED")) {
+ `mkdir -p $libdir`; Fail("Cannot create $libdir") if $?;
}
};
}
Append("LOPT" => "-s");
}
+# Link-time optimization (experimental)
+# This is currently very inefficient, because we do not attempt to disable
+# optimizations when compiling individual modules. Therefore, we optimize
+# each shared library module twice: when compiling and when linking.
+# Doing it properly would require hacking makefiles.
+if (IsSet("CONFIG_LTO")) {
+ Append("LOPT", "-flto");
+ Append("COPT", "-flto");
+}
+
if (IsSet("CONFIG_DARWIN")) {
# gcc-4.0 on Darwin doesn't set this in the gnu99 mode
Append("CLANG" => "-fnested-functions");
--- /dev/null
+# UCW Library configuration system: documentation requirements
+# (c) 2008 Michal Vaner <vorner@ucw.cz>
+
+package UCW::Configure::Doc;
+use UCW::Configure;
+
+use strict;
+use warnings;
+
+if (!IsGiven("CONFIG_DOC") || IsSet("CONFIG_DOC")) {
+ Test("HAVE_ASCII_DOC", "Checking for AsciiDoc", sub {
+ my $version = `asciidoc --version 2>&1`;
+ return "none" if !defined $version || $version eq "";
+ my( $vnum ) = $version =~ / (\d+\.\S*)$/;
+ return $vnum;
+ });
+
+ my( $major ) = Get("HAVE_ASCII_DOC") =~ /^(\d+)/;
+ if (defined $major && $major >= 7) {
+ Set("CONFIG_DOC");
+ } else {
+ if (IsGiven("CONFIG_DOC")) {
+ Fail("Need asciidoc >= 7\n");
+ } else {
+ Warn("Need asciidoc >= 7 to build documentation\n");
+ UnSet("CONFIG_DOC");
+ }
+ }
+}
+
+# We succeeded
+1;
--- /dev/null
+# UCW Library configuration system: parameters of the library
+# (c) 2005--2012 Martin Mares <mj@ucw.cz>
+# (c) 2006 Robert Spalek <robert@ucw.cz>
+# (c) 2008 Michal Vaner <vorner@ucw.cz>
+
+package UCW::Configure::LibUCW;
+use UCW::Configure;
+
+use strict;
+use warnings;
+
+# Turn on debugging support if CONFIG_DEBUG
+if (Get("CONFIG_DEBUG")) {
+ Set("CONFIG_UCW_DEBUG");
+}
+
+# Determine page size
+Test("CPU_PAGE_SIZE", "Determining page size", sub {
+ my $p;
+ if (IsSet("CONFIG_DARWIN")) {
+ $p = `sysctl -n hw.pagesize`;
+ defined $p or Fail "sysctl hw.pagesize failed";
+ } elsif (IsSet("CONFIG_LINUX")) {
+ $p = `getconf PAGE_SIZE`;
+ defined $p or Fail "getconf PAGE_SIZE failed";
+ }
+ chomp $p;
+ return $p;
+});
+
+# Decide how will ucw/partmap.c work
+Set("CONFIG_UCW_PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
+
+# Option for ucw/mempool.c
+Set("CONFIG_UCW_POOL_IS_MMAP");
+
+# Guess optimal bit width of the radix-sorter
+Test("CONFIG_UCW_RADIX_SORTER_BITS", "Determining radix sorter bucket width", sub {
+ if (Get("CPU_AMD64")) {
+ # All amd64 CPUs have large enough L1 cache
+ return 12;
+ } else {
+ # This should be safe everywhere
+ return 10;
+ }
+});
+
+# Detect if thread-local storage is supported
+if (Get("CONFIG_UCW_THREADS")) {
+ TestBool("CONFIG_UCW_TLS", "Checking if GCC supports thread-local storage", sub {
+ if (UCW::Configure::C::TestCompile("__thread", "__thread int i;\nint main(void) { return 0; }\n")) {
+ return 1;
+ } else {
+ return 0;
+ }
+ });
+}
+
+# Detect if we have the epoll() syscall
+TestBool("CONFIG_UCW_EPOLL", "Checking for epoll", sub {
+ return UCW::Configure::C::TestCompile("epoll", <<'FINIS' ) ? 1 : 0;
+#include <sys/epoll.h>
+int main(void)
+{
+ epoll_create(256);
+ return 0;
+}
+FINIS
+});
+
+# Check if we want to use monotonic clock
+TestBool("CONFIG_UCW_MONOTONIC_CLOCK", "Checking for monotonic clock", sub {
+ return Get("CONFIG_LINUX");
+});
+
+if (IsSet("CONFIG_DARWIN")) {
+ # Darwin does not support BSD regexes, fix up
+ if (!IsSet("CONFIG_UCW_POSIX_REGEX") && !IsSet("CONFIG_UCW_PCRE")) {
+ Set("CONFIG_UCW_POSIX_REGEX" => 1);
+ Warn "BSD regex library on Darwin isn't compatible, using POSIX regex.\n";
+ }
+
+ # Fill in some constants not found in the system header files
+ Set("SOL_TCP" => 6); # missing in /usr/include/netinet/tcp.h
+ if (IsGiven("CONFIG_UCW_DIRECT_IO") && IsSet("CONFIG_UCW_DIRECT_IO")) {
+ Fail("Direct I/O is not available on darwin");
+ } else {
+ UnSet("CONFIG_UCW_DIRECT_IO");
+ }
+}
+
+PostConfig {
+ AtWrite {
+ UCW::Configure::C::ConfigHeader("ucw/autoconf.h", [
+ # Included symbols
+ '^CONFIG_UCW_' => 1,
+ '^CPU_' => 1,
+ '^UCW_VERSION(_|$)' => 1,
+ ]);
+ } if Get("CONFIG_INSTALL_API");
+
+ # Include direct FB?
+ if (!IsSet("CONFIG_UCW_THREADS") || !IsSet("CONFIG_UCW_DIRECT_IO")) {
+ if (IsGiven("CONFIG_UCW_FB_DIRECT") && IsSet("CONFIG_UCW_FB_DIRECT")) {
+ if (!IsSet("CONFIG_UCW_THREADS")) {
+ Fail("CONFIG_UCW_FB_DIRECT needs CONFIG_UCW_THREADS");
+ } else {
+ Fail("CONFIG_UCW_FB_DIRECT needs CONFIG_UCW_DIRECT_IO");
+ }
+ }
+ UnSet("CONFIG_UCW_FB_DIRECT");
+ }
+};
+
+# We succeeded
+1;
--- /dev/null
+# UCW Library configuration system: Perl paths
+# (c) 2017 Martin Mares <mj@ucw.cz>
+
+package UCW::Configure::Perl;
+use UCW::Configure;
+
+use strict;
+use warnings;
+use Config;
+
+Log "Determining Perl module path ... ";
+my $prefix = $Config{installprefix};
+$prefix .= '/' unless $prefix =~ m{/$};
+my $lib = substr($Config{installvendorlib}, length $prefix);
+Set('INSTALL_PERL_DIR', Get('INSTALL_USR_PREFIX') . $lib);
+Log Get('INSTALL_PERL_DIR') . "\n";
+
+Log "Determining Perl arch-dependent module path ... ";
+my $archlib = substr($Config{installvendorarch}, length $prefix);
+Set('INSTALL_PERL_ARCH_DIR', Get('INSTALL_USR_PREFIX') . $archlib);
+Log Get('INSTALL_PERL_ARCH_DIR') . "\n";
+
+# We succeeded
+1;
# UCW Library configuration system: pkg-config and friends
# (c) 2008 Martin Mares <mj@ucw.cz>
+# (c) 2017 Pavel Charvat <pchar@ucw.cz>
package UCW::Configure::Pkg;
use UCW::Configure;
Log("NONE: pkg-config missing\n");
return 0;
}
- my $ver = TryCmd("pkg-config --modversion $pkg 2>/dev/null");
+ my $pc = "pkg-config";
+ if (defined($opts{path})) {
+ $pc = "PKG_CONFIG_PATH=$opts{path} $pc";
+ }
+ if (defined($opts{args})) {
+ $pc = "$pc $opts{args}";
+ }
+ my $ver = TryCmd("$pc --modversion $pkg 2>/dev/null");
if (!defined $ver) {
Log("NONE\n");
return 0;
}
if (defined($opts{minversion})) {
my $min = $opts{minversion};
- if (!defined TryCmd("pkg-config --atleast-version=$min $pkg")) {
+ if (!defined TryCmd("$pc --atleast-version=$min $pkg")) {
Log("NO: version $ver is too old (need >= $min)\n");
return 0;
}
Log("YES: version $ver\n");
Set("CONFIG_HAVE_$upper" => 1);
Set("CONFIG_VER_$upper" => $ver);
- my $cf = TryCmd("pkg-config --cflags $pkg");
+ my $cf = TryCmd("$pc --cflags $pkg");
Set("${upper}_CFLAGS" => $cf) if defined $cf;
- my $lf = TryCmd("pkg-config --libs $pkg");
+ my $lf = TryCmd("$pc --libs $pkg");
Set("${upper}_LIBS" => $lf) if defined $lf;
return 1;
}