1package Alien::Build::Plugin::Gather::IsolateDynamic; 2 3use strict; 4use warnings; 5use 5.008004; 6use Alien::Build::Plugin; 7use Path::Tiny (); 8use Alien::Build::Util qw( _destdir_prefix ); 9use File::Copy (); 10 11# ABSTRACT: Plugin to gather dynamic libraries into a separate directory 12our $VERSION = '2.45'; # VERSION 13 14 15sub init 16{ 17 my($self, $meta) = @_; 18 19 # plugin was introduced in 0.42, but had a bug which was fixed in 0.48 20 $meta->add_requires('share' => 'Alien::Build::Plugin::Gather::IsolateDynamic' => '0.48' ); 21 22 $meta->after_hook( 23 gather_share => sub { 24 my($build) = @_; 25 $build->log("Isolating dynamic libraries ..."); 26 27 my $install_root; 28 if($build->meta_prop->{destdir}) 29 { 30 my $destdir = $ENV{DESTDIR}; 31 $install_root = Path::Tiny->new(_destdir_prefix($ENV{DESTDIR}, $build->install_prop->{prefix})); 32 } 33 else 34 { 35 $install_root = Path::Tiny->new($build->install_prop->{stage}); 36 } 37 38 foreach my $dir (map { $install_root->child($_) } qw( bin lib )) 39 { 40 next unless -d $dir; 41 foreach my $from ($dir->children) 42 { 43 next unless $from->basename =~ /\.so/ 44 || $from->basename =~ /\.(dylib|bundle|la|dll|dll\.a)$/; 45 my $to = $install_root->child('dynamic', $from->basename); 46 $to->parent->mkpath; 47 unlink "$to" if -e $to; 48 $build->log("move @{[ $from->parent->basename ]}/@{[ $from->basename ]} => dynamic/@{[ $to->basename ]}"); 49 File::Copy::move("$from", "$to") || die "unable to move $from => $to $!"; 50 } 51 } 52 53 $build->log(" Done!"); 54 }, 55 ); 56} 57 581; 59 60__END__ 61 62=pod 63 64=encoding UTF-8 65 66=head1 NAME 67 68Alien::Build::Plugin::Gather::IsolateDynamic - Plugin to gather dynamic libraries into a separate directory 69 70=head1 VERSION 71 72version 2.45 73 74=head1 SYNOPSIS 75 76 use alienfile; 77 plugin 'Gather::IsolateDynamic'; 78 79=head1 DESCRIPTION 80 81This plugin moves dynamic libraries from the C<lib> and C<bin> directories and puts them in 82their own C<dynamic> directory. This allows them to be used by FFI modules, but to be ignored 83by XS modules. 84 85This plugin provides the equivalent functionality of the C<alien_isolate_dynamic> attribute 86from L<Alien::Base::ModuleBuild>. 87 88=head1 SEE ALSO 89 90L<Alien::Build>, L<alienfile> 91 92=head1 AUTHOR 93 94Author: Graham Ollis E<lt>plicease@cpan.orgE<gt> 95 96Contributors: 97 98Diab Jerius (DJERIUS) 99 100Roy Storey (KIWIROY) 101 102Ilya Pavlov 103 104David Mertens (run4flat) 105 106Mark Nunberg (mordy, mnunberg) 107 108Christian Walde (Mithaldu) 109 110Brian Wightman (MidLifeXis) 111 112Zaki Mughal (zmughal) 113 114mohawk (mohawk2, ETJ) 115 116Vikas N Kumar (vikasnkumar) 117 118Flavio Poletti (polettix) 119 120Salvador Fandiño (salva) 121 122Gianni Ceccarelli (dakkar) 123 124Pavel Shaydo (zwon, trinitum) 125 126Kang-min Liu (劉康民, gugod) 127 128Nicholas Shipp (nshp) 129 130Juan Julián Merelo Guervós (JJ) 131 132Joel Berger (JBERGER) 133 134Petr Písař (ppisar) 135 136Lance Wicks (LANCEW) 137 138Ahmad Fatoum (a3f, ATHREEF) 139 140José Joaquín Atria (JJATRIA) 141 142Duke Leto (LETO) 143 144Shoichi Kaji (SKAJI) 145 146Shawn Laffan (SLAFFAN) 147 148Paul Evans (leonerd, PEVANS) 149 150Håkon Hægland (hakonhagland, HAKONH) 151 152nick nauwelaerts (INPHOBIA) 153 154=head1 COPYRIGHT AND LICENSE 155 156This software is copyright (c) 2011-2020 by Graham Ollis. 157 158This is free software; you can redistribute it and/or modify it under 159the same terms as the Perl 5 programming language system itself. 160 161=cut 162