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

Commit

Permalink
Merge pull request #51 from plicease/isolate
Browse files Browse the repository at this point in the history
add property alien_isolate_dynamic
  • Loading branch information
plicease committed Sep 4, 2014
2 parents 7b79a52 + 4eafd37 commit 041df2a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Alien/Base.pm
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
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 @@ -336,6 +339,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
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

0 comments on commit 041df2a

Please sign in to comment.