Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

add property alien_isolate_dynamic #51

Merged
merged 1 commit into from
Sep 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/Alien/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use Carp;
use DynaLoader ();

use File::ShareDir ();
use File::Spec;
use Scalar::Util qw/blessed/;
use Capture::Tiny 0.17 qw/capture_merged/;
use Text::ParseWords qw/shellwords/;
Expand Down Expand Up @@ -194,6 +195,16 @@ sub split_flags_windows {
shellwords($line);
}

sub dynamic_lib {
my ($class) = @_;
my $dir = File::Spec->catfile($class->dist_dir, 'dynamic');
return unless -d $dir;
opendir(my $dh, $dir);
my @dlls = grep { /\.so/ || /\.(dylib|dll)$/ } grep !/^\./, readdir $dh;
closedir $dh;
grep { ! -l $_ } map { File::Spec->catfile($dir, $_) } @dlls;
}

1;

__END__
Expand Down
22 changes: 22 additions & 0 deletions lib/Alien/Base/ModuleBuild.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use Archive::Extract;
use Sort::Versions;
use List::MoreUtils qw/uniq first_index/;
use ExtUtils::Installed;
use File::Copy qw/move/;

use Alien::Base::PkgConfig;
use Alien::Base::ModuleBuild::Cabinet;
Expand Down Expand Up @@ -101,6 +102,8 @@ __PACKAGE__->add_property( 'alien_repository' => {} );
__PACKAGE__->add_property( 'alien_repository_default' => {} );
__PACKAGE__->add_property( 'alien_repository_class' => {} );

# alien_isolate_dynamic
__PACKAGE__->add_property( 'alien_isolate_dynamic' => 0 );

################
# ConfigData #
Expand Down Expand Up @@ -334,6 +337,25 @@ sub ACTION_alien_install {
$self->alien_do_commands('install') or die "Failed\n";
print "Done\n";
}

if ( $self->alien_isolate_dynamic ) {
local $CWD = $self->alien_library_destination;
print "Isolating dynamic libraries ... ";
mkdir 'dynamic' unless -d 'dynamic';
foreach my $dir (qw( bin lib )) {
next unless -d $dir;
opendir(my $dh, $dir);
my @dlls = grep { /\.so/ || /\.(dylib|la|dll|dll\.a)$/ } grep !/^\./, readdir $dh;
closedir $dh;
foreach my $dll (@dlls) {
my $from = File::Spec->catfile($dir, $dll);
my $to = File::Spec->catfile('dynamic', $dll);
unlink $to if -e $to;
move($from, $to);
}
}
print "Done\n";
}

# refresh metadata after library installation
$self->alien_refresh_manual_pkgconfig( $self->alien_library_destination );
Expand Down
6 changes: 6 additions & 0 deletions lib/Alien/Base/ModuleBuild/API.pod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ These parameters, if specified, augment the information found by F<pkg-config>.

A hashref or arrayref of hashrefs defining the repositories used to find and fetch library tarballs (or zipballs etc.). These attributes are used to create C<Alien::Base::ModuleBuild::Repository> objects (or more likely, subclasses thereof). Which class is created is governed by the C<protocol> attribute and the C<alien_repository_class> property below. Available attributes are:

=item alien_isolate_dynamic

[version 0.005]

If set to true, then dynamic libraries will be moved from the C<lib> directory to a separate C<dynamic> directory. This makes them available for FFI modules (see L<FFI::Raw>), while preferring static libraries when creating XS extensions.

=over

=item protocol
Expand Down