Alien-Libarchive

 view release on metacpan or  search on metacpan

inc/Alien/LZO/Installer.pm  view on Meta::CPAN

B<NOTE:> using this method may require modules returned by the
L<system_requires|Alien::LZO::Installer> method.

B<NOTE:> This form will also use the lzo provided by L<Alien::LZO>
if it is installed.  This makes this method ideal for finding
lzo as an optional dependency.

Options:

=over 4

=item test

Specifies the test type that should be used to verify the integrity
of the system lzo.  Generally this should be
set according to the needs of your module.  Should be one of:

=over 4

=item compile

use L<test_compile_run|Alien::LZO::Installer#test_compile_run> to verify.
This is the default.

=item ffi

use L<test_ffi|Alien::LZO::Installer#test_ffi> to verify

=item both

use both
L<test_compile_run|Alien::LZO::Installer#test_compile_run>
and
L<test_ffi|Alien::LZO::Installer#test_ffi>
to verify

=back

=item alien

If true (the default) then an existing L<Alien::LZO> will be
used if version 0.19 or better is found.  Usually this is what you
want.

=back

=cut

sub system_install
{
  my($class, %options) = @_;

  $options{alien} = 1 unless defined $options{alien};
  $options{test} ||= 'compile';
  die "test must be one of compile, ffi or both"
    unless $options{test} =~ /^(compile|ffi|both)$/;

  if($options{alien} && eval q{ use Alien::LZO 0.01; 1 })
  {
    my $alien = Alien::LZO->new;
    my $build = bless {
      cflags => $alien->cflags,
      libs   => $alien->libs,
    }, $class;
    return $build if $options{test} =~ /^(compile|both)$/ && $build->test_compile_run;
    return $build if $options{test} =~ /^(ffi|both)$/ && $build->test_compile_run;
  }

  my $build = bless {
    cflags => [],
    libs   => ['-llzo2'],
  }, $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;
}

=head2 build_install

 my $installer = Alien::LZO::Installer->build_install( '/usr/local', %options );

B<NOTE:> using this method may (and probably does) require modules
returned by the L<build_requires|Alien::LZO::Installer>
method.

Build and install lzo into the given directory.  If there
is an error an exception will be thrown.  On a successful build, an
instance of L<Alien::LZO::Installer> will be returned.

These options may be passed into build_install:

=over 4

=item tar

Filename where the lzo source tar is located.
If not specified the latest version will be downloaded
from the Internet.

=item dir

Empty directory to be used to extract the lzo
source and to build from.

=item test

Specifies the test type that should be used to verify the integrity
of the build after it has been installed.  Generally this should be
set according to the needs of your module.  Should be one of:

=over 4

=item compile

use L<test_compile_run|Alien::LZO::Installer#test_compile_run> to verify.
This is the default.

=item ffi

use L<test_ffi|Alien::LZO::Installer#test_ffi> to verify

=item both

use both
L<test_compile_run|Alien::LZO::Installer#test_compile_run>
and
L<test_ffi|Alien::LZO::Installer#test_ffi>
to verify

inc/Alien/LZO/Installer.pm  view on Meta::CPAN

      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
either be provided by the system, or have just been built
using L<build_install|Alien::LZO::Installer#build_install>.

=head2 cflags

The compiler flags required to use lzo.

=head2 libs

The linker flags and libraries required to use lzo.

=head2 dlls

List of DLL or .so (or other dynamic library) files that can
be used by L<FFI::Raw> or similar.

=head2 version

The version of lzo

=cut

sub cflags  { shift->{cflags}  }
sub libs    { shift->{libs}    }
sub version { shift->{version} }

sub dlls
{
  my($self, $prefix) = @_;
  
  $prefix = $self->{prefix} unless defined $prefix;
  
  unless(defined $self->{dlls} && defined $self->{dll_dir})
  {
    if($^O eq 'cygwin')



( run in 1.349 second using v1.01-cache-2.11-cpan-0b5f733616e )