Alien-Libjio
view release on metacpan or search on metacpan
lib/Alien/Libjio.pm view on Meta::CPAN
return @{ $self->{ldflags} } if wantarray;
return $self->{ldflags};
}
# Glob to create an alias to ldflags
*linker_flags = *ldflags;
sub cflags {
my ($self) = @_;
Carp::croak('You must call this method as an object') unless ref($self);
# Return early if called in void context
return unless defined wantarray;
# If calling in array context, dereference and return
return @{ $self->{cflags} } if wantarray;
return $self->{cflags};
}
*compiler_flags = *cflags;
sub method {
my ($self) = @_;
Carp::croak('You must call this method as an object') unless ref($self);
return $self->{method};
}
*how = *method;
# Private methods to find & fill out information
use IPC::Open3 ('open3');
sub _get_pc {
my ($key) = @_;
my $read;
my $pid = open3(undef, $read, undef, 'pkg-config', 'libjio', '--' . $key);
# We're using blocking wait, so the return value doesn't matter
## no critic(RequireCheckedSyscalls)
waitpid($pid, 0);
# Check the exit status; 0 = success - nonzero = failure
if (($? >> 8) == 0) {
# The value we got back
return <$read>;
}
return (undef, <$read>) if wantarray;
return;
}
sub _try_pkg_config {
my ($self) = @_;
my ($value, $err) = _get_pc('cflags');
return unless (defined $value && length $value);
#if (defined $err && length $err) {
# #warn "Problem with pkg-config; using ExtUtils::Liblist instead\n";
# return;
#}
$self->{installed} = 1;
$self->{method} = 'pkg-config';
# pkg-config returns things with a newline, so remember to remove it
$self->{cflags} = [ split(' ', $value) ];
$self->{ldflags} = [ split(' ', _get_pc('libs')) ];
$self->{version} = _get_pc('modversion');
return 1;
}
sub _try_liblist {
my ($self) = @_;
use ExtUtils::Liblist ();
local $SIG{__WARN__} = sub { }; # mask warnings
my (undef, undef, $ldflags, $ldpath) = ExtUtils::Liblist->ext('-ljio');
return unless (defined($ldflags) && length($ldflags));
$self->{installed} = 1;
$self->{method} = 'ExtUtils::Liblist';
# Empty out cflags; initialize it
$self->{cflags} = [];
my $read;
my $pid = open3(undef, $read, undef, 'getconf', 'LFS_CFLAGS');
# We're using blocking wait, so the return value doesn't matter
## no critic(RequireCheckedSyscalls)
waitpid($pid, 0);
# Check the status code
if (($? >> 8) == 0) {
# This only takes the first line
push(@{ $self->{cflags} }, split(' ', <$read>));
}
else {
warn 'Problem using getconf: ', <$read>, "\n";
push(@{ $self->{cflags} },
'-D_LARGEFILE_SOURCE',
'-D_FILE_OFFSET_BITS=64',
);
}
# Used for resolving the include path, relative to lib
use Cwd ();
use File::Spec ();
push(@{ $self->{cflags} },
# The include path is taken as: $libpath/../include
'-I' . Cwd::realpath(File::Spec->catfile(
$ldpath,
File::Spec->updir(),
'include'
))
);
push(@{ $self->{ldflags} },
'-L' . $ldpath,
$ldflags,
);
return 1;
}
__END__
=pod
=head1 NAME
Alien::Libjio - Utility package to install and locate libjio
=head1 VERSION
version 1.004
=head1 SYNOPSIS
( run in 2.083 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )