From aec3aea0c865154a35d7f04dfa86da95fdaea4da Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 13 Mar 2022 20:01:12 +0100 Subject: [PATCH 1/1] Updated UCW::Configure to the version from current LibUCW Taken from LibUCW commit 7308e240b306041667fc8b3ac99263c1e9ecf4e6. --- perl/UCW/Configure.pm | 18 ++++-- perl/UCW/Configure/C.pm | 39 ++++++++++-- perl/UCW/Configure/Doc.pm | 32 ++++++++++ perl/UCW/Configure/LibUCW.pm | 116 +++++++++++++++++++++++++++++++++++ perl/UCW/Configure/Perl.pm | 24 ++++++++ perl/UCW/Configure/Pkg.pm | 16 +++-- 6 files changed, 232 insertions(+), 13 deletions(-) create mode 100644 perl/UCW/Configure/Doc.pm create mode 100644 perl/UCW/Configure/LibUCW.pm create mode 100644 perl/UCW/Configure/Perl.pm diff --git a/perl/UCW/Configure.pm b/perl/UCW/Configure.pm index 5d458ad..dc1dac8 100644 --- a/perl/UCW/Configure.pm +++ b/perl/UCW/Configure.pm @@ -9,6 +9,7 @@ package UCW::Configure; use strict; use warnings; +use IO::File; BEGIN { # The somewhat hairy Perl export mechanism @@ -33,14 +34,17 @@ sub DebugDump() { sub Log($) { print @_; + STDOUT->flush; } sub Notice($) { print @_ if $vars{"VERBOSE"}; + STDOUT->flush; } sub Warn($) { print "WARNING: ", @_; + STDOUT->flush; } sub Fail($) { @@ -105,16 +109,22 @@ sub TestBool($$$) { 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; diff --git a/perl/UCW/Configure/C.pm b/perl/UCW/Configure/C.pm index e961ca0..730b514 100644 --- a/perl/UCW/Configure/C.pm +++ b/perl/UCW/Configure/C.pm @@ -65,6 +65,8 @@ Test("ARCH", "Checking for machine architecture", sub { return "i386"; } elsif ($mach =~ /^(x86[_-]|amd)64$/) { return "amd64"; + } elsif ($mach eq 'powerpc') { + return $mach; } else { return "unknown ($mach)"; } @@ -85,6 +87,20 @@ if ($arch eq 'i386') { 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."; } @@ -119,17 +135,20 @@ Set("LIBS" => ""); # 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 $?; } }; } @@ -167,6 +186,16 @@ if (IsSet("CONFIG_DEBUG")) { 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"); diff --git a/perl/UCW/Configure/Doc.pm b/perl/UCW/Configure/Doc.pm new file mode 100644 index 0000000..fe36592 --- /dev/null +++ b/perl/UCW/Configure/Doc.pm @@ -0,0 +1,32 @@ +# UCW Library configuration system: documentation requirements +# (c) 2008 Michal Vaner + +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; diff --git a/perl/UCW/Configure/LibUCW.pm b/perl/UCW/Configure/LibUCW.pm new file mode 100644 index 0000000..7feef1e --- /dev/null +++ b/perl/UCW/Configure/LibUCW.pm @@ -0,0 +1,116 @@ +# UCW Library configuration system: parameters of the library +# (c) 2005--2012 Martin Mares +# (c) 2006 Robert Spalek +# (c) 2008 Michal Vaner + +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 +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; diff --git a/perl/UCW/Configure/Perl.pm b/perl/UCW/Configure/Perl.pm new file mode 100644 index 0000000..5c1b83f --- /dev/null +++ b/perl/UCW/Configure/Perl.pm @@ -0,0 +1,24 @@ +# UCW Library configuration system: Perl paths +# (c) 2017 Martin Mares + +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; diff --git a/perl/UCW/Configure/Pkg.pm b/perl/UCW/Configure/Pkg.pm index 5f3dc33..a31d616 100644 --- a/perl/UCW/Configure/Pkg.pm +++ b/perl/UCW/Configure/Pkg.pm @@ -1,5 +1,6 @@ # UCW Library configuration system: pkg-config and friends # (c) 2008 Martin Mares +# (c) 2017 Pavel Charvat package UCW::Configure::Pkg; use UCW::Configure; @@ -57,14 +58,21 @@ sub PkgConfig($@) { 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; } @@ -72,9 +80,9 @@ sub PkgConfig($@) { 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; } -- 2.39.5