Alien-Libarchive
view release on metacpan or search on metacpan
inc/Alien/LZO/Installer.pm view on Meta::CPAN
close $dh;
die "unable to find source in build root" if @list == 0;
die "confused by multiple entries in the build root" if @list > 1;
$list[0];
};
_msys(sub {
# TODO this will only work with gcc
my($make) = @_;
system 'sh', 'configure', "--prefix=$prefix", '--with-pic', '--enable-shared';
die "configure failed" if $?;
system $make, 'all';
die "make all failed" if $?;
system $make, 'install';
die "make install failed" if $?;
});
if($^O eq 'MSWin32')
{
# TODO: this will only work with gcc
require File::Temp;
my $dir = File::Temp::tempdir( CLEANUP => 1 );
# TODO: use Archive::Ar when it is a little less broken
require Archive::Ar;
my $ar = Archive::Ar->new(_catfile($prefix, 'lib', 'liblzo2.a'));
my @objects = grep { $_ ne '/' } $ar->list_files;
foreach my $object (@objects)
{
my $fh;
my $fn = _catfile($dir, $object);
open($fh, '>', $fn) || die "unable to write $fn $!";
binmode $fh;
print $fh $ar->get_content($object)->{data};
close $fh;
}
system 'dlltool',
'--export-all-symbols',
-e => _catfile($dir, 'exports.o'),
-l => _catfile($prefix, 'lib', 'liblzo2.dll.a'),
map { _catfile($dir, $_) } @objects;
die "dlltool failed" if $?;
system 'gcc',
'--shared',
-o => _catfile($prefix, 'lib', 'liblzo2.dll'),
_catfile($dir, 'exports.o'),
map { _catfile($dir, $_) } @objects;
do {
my($in,$out);
open($in, '<', _catfile($prefix, 'lib', 'liblzo2.la'));
open($out, '>', _catfile($prefix, 'lib', 'liblzo2.la.tmp'));
while(<$in>)
{
s{^dlname='.*?'}{dlname='../dll/liblzo2.dll'};
s{^library_names='.*?'}{library_names='../dll/liblzo2.dll.a'};
print $out $_;
}
close $in;
close $out;
unlink _catfile($prefix, 'lib', 'liblzo2.la');
rename _catfile($prefix, 'lib', 'liblzo2.la.tmp'),
_catfile($prefix, 'lib', 'liblzo2.la');
};
}
foreach my $name ('lib')
{
do {
my $static_dir = _catdir($prefix, $name);
my $dll_dir = _catdir($prefix, 'dll');
require File::Path;
File::Path::mkpath($dll_dir, 0, 0755);
my $dh;
opendir $dh, $static_dir;
my @list = readdir $dh;
@list = grep { /\.so/ || /\.(dylib|la|dll|dll\.a)$/} grep !/^\./, @list;
closedir $dh;
foreach my $basename (@list)
{
my $from = _catfile($static_dir, $basename);
my $to = _catfile($dll_dir, $basename);
if(-l $from)
{
symlink(readlink $from, $to);
unlink($from);
}
else
{
require File::Copy;
File::Copy::move($from, $to);
}
}
};
}
my $build = bless {
cflags => ['-I' . _catdir($prefix, 'include')],
libs => ['-L' . _catdir($prefix, 'lib'), '-llzo2'],
prefix => $prefix,
dll_dir => [ 'dll' ],
dlls => do {
opendir(my $dh, _catdir($prefix, 'dll'));
[grep { ! -l _catfile($prefix, 'dll', $_) } grep { /\.so/ || /\.(dll|dylib)$/ } grep !/^\./, readdir $dh];
},
}, $class;
$build->test_compile_run || die $build->error if $options{test} =~ /^(compile|both)$/;
$build->test_ffi || die $build->error if $options{test} =~ /^(ffi|both)$/;
$build;
};
my $error = $@;
chdir $save;
die $error if $error;
$build;
}
=head1 ATTRIBUTES
Attributes of an L<Alien::LZO::Installer> provide the
information needed to use an existing lzo (which may
( run in 0.970 second using v1.01-cache-2.11-cpan-e1769b4cff6 )