Alien-Libarchive-Installer
view release on metacpan or search on metacpan
lib/Alien/Libarchive/Installer.pm view on Meta::CPAN
}, $class;
if($options{test} =~ /^(ffi|both)$/)
{
my @dir_search_list;
if($^O eq 'MSWin32')
{
# On MSWin32 the entire path is not included in dl_library_path
# but that is the most likely place that we will find dlls.
@dir_search_list = grep { -d $_ } split /;/, $ENV{PATH};
}
else
{
require DynaLoader;
@dir_search_list = grep { -d $_ } @DynaLoader::dl_library_path
}
found_dll: foreach my $dir (@dir_search_list)
{
my $dh;
opendir($dh, $dir) || next;
# sort by filename length so that libarchive.so.12.0.4
# is preferred over libarchive.so.12 or libarchive.so
# if only to make diagnostics point to the more specific
# version.
foreach my $file (sort { length $b <=> length $a } readdir $dh)
{
if($^O eq 'MSWin32')
{
next unless $file =~ /^libarchive-[0-9]+\.dll$/i;
}
elsif($^O eq 'cygwin')
{
next unless $file =~ /^cygarchive-[0-9]+\.dll$/i;
}
else
{
next unless $file =~ /^libarchive\.(dylib|so(\.[0-9]+)*)$/;
}
require File::Spec;
my($v,$d) = File::Spec->splitpath($dir, 1);
$build->{dll_dir} = [File::Spec->splitdir($d)];
$build->{prefix} = $v;
$build->{dlls} = [$file];
closedir $dh;
last found_dll;
}
closedir $dh;
}
}
$build->test_compile_run || die $build->error if $options{test} =~ /^(compile|both)$/;
$build->test_ffi || die $build->error if $options{test} =~ /^(ffi|both)$/;
$build;
}
sub _try_pkg_config
{
my($dir, $field, $guess, $extra) = @_;
unless(defined $dir)
{
require File::Temp;
$dir = File::Temp::tempdir(CLEANUP => 1);
}
require Config;
local $ENV{PKG_CONFIG_PATH} = join $Config::Config{path_sep}, $dir, split /$Config::Config{path_sep}/, ($ENV{PKG_CONFIG_PATH}||'');
my $value = eval {
# you probably think I am crazy...
eval q{ use PkgConfig 0.07620 };
die $@ if $@;
my $value = `$^X $INC{'PkgConfig.pm'} --silence-errors libarchive $extra --$field`;
die if $?;
$value;
};
unless(defined $value) {
no warnings;
$value = `pkg-config --silence-errors libarchive $extra --$field`;
return $guess if $?;
}
chomp $value;
require Text::ParseWords;
[Text::ParseWords::shellwords($value)];
}
sub _msys
{
my($sub) = @_;
require Config;
if($^O eq 'MSWin32')
{
if($Config::Config{cc} !~ /cl(\.exe)?$/i)
{
require Alien::MSYS;
return Alien::MSYS::msys(sub{ $sub->('make') });
}
}
$sub->($Config::Config{make});
}
sub build_install
{
my($class, $prefix, %options) = @_;
$options{test} ||= 'compile';
die "test must be one of compile, ffi or both"
unless $options{test} =~ /^(compile|ffi|both)$/;
die "need an install prefix" unless $prefix;
$prefix =~ s{\\}{/}g;
my $dir = $options{dir} || do { require File::Temp; File::Temp::tempdir( CLEANUP => 1 ) };
require Archive::Tar;
my $tar = Archive::Tar->new;
$tar->read($options{tar} || $class->fetch);
require Cwd;
my $save = Cwd::getcwd();
chdir $dir;
my $build = eval {
$tar->extract;
chdir do {
opendir my $dh, '.';
my(@list) = grep !/^\./,readdir $dh;
close $dh;
die "unable to find source in build root" if @list == 0;
die "confused by multiple entries in the build root" if @list > 1;
$list[0];
};
do {
$DB::single = 1;
my $share_dir = dist_dir('Alien-Libarchive-Installer');
my($version) = [File::Spec->splitpath(Cwd::getcwd())]->[2] =~ /libarchive-([0-9\.]+)/;
( run in 1.159 second using v1.01-cache-2.11-cpan-e1769b4cff6 )