From 4eafd377cea943753e864c36d05e2c927b260c76 Mon Sep 17 00:00:00 2001 From: Graham Ollis Date: Tue, 2 Sep 2014 11:08:33 -0400 Subject: [PATCH] add property alien_isolate_dynamic --- lib/Alien/Base.pm | 11 +++++++++++ lib/Alien/Base/ModuleBuild.pm | 22 ++++++++++++++++++++++ lib/Alien/Base/ModuleBuild/API.pod | 6 ++++++ 3 files changed, 39 insertions(+) diff --git a/lib/Alien/Base.pm b/lib/Alien/Base.pm index bda33429..0fa5c339 100644 --- a/lib/Alien/Base.pm +++ b/lib/Alien/Base.pm @@ -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/; @@ -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__ diff --git a/lib/Alien/Base/ModuleBuild.pm b/lib/Alien/Base/ModuleBuild.pm index 5af952a7..b80766b3 100644 --- a/lib/Alien/Base/ModuleBuild.pm +++ b/lib/Alien/Base/ModuleBuild.pm @@ -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; @@ -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 # @@ -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 ); diff --git a/lib/Alien/Base/ModuleBuild/API.pod b/lib/Alien/Base/ModuleBuild/API.pod index dc37feb0..f04318e0 100644 --- a/lib/Alien/Base/ModuleBuild/API.pod +++ b/lib/Alien/Base/ModuleBuild/API.pod @@ -71,6 +71,12 @@ These parameters, if specified, augment the information found by F. 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 objects (or more likely, subclasses thereof). Which class is created is governed by the C attribute and the C 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 directory to a separate C directory. This makes them available for FFI modules (see L), while preferring static libraries when creating XS extensions. + =over =item protocol