Alien-Libarchive-Installer

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


     # as an optional dep
     use Alien::Libarchive::Installer;
     use Module::Build;
     
     my %build_args;
     
     my $installer = eval { Alien::Libarchive::Installer->system_install };
     if($installer)
     {
       $build_args{extra_compiler_flags} = $installer->cflags,
       $build_args{extra_linker_flags}   = $installer->libs,
     }
     
     my $build = Module::Build->new(%build_args);
     $build->create_build_script;

    Build.PL

     # require 3.0
     use Alien::Libarchive::Installer;
     use Module::Build;

README  view on Meta::CPAN

     my $installer = eval {
       my $system_installer = Alien::Libarchive::Installer->system_install;
       die "we require 3.0.x or better"
         if $system_installer->version !~ /^([0-9]+)\./ && $1 >= 3;
       $system_installer;
          # reasonably assumes that build_install will never download
          # a version older that 3.0
     } || Alien::Libarchive::Installer->build_install("dir");
     
     my $build = Module::Build->new(
       extra_compiler_flags => $installer->cflags,
       extra_linker_flags   => $installer->libs,
     );
     $build->create_build_script;

    FFI::Raw

     # as an optional dep
     use Alien::Libarchive::Installer;
     use FFI::Raw;
     
     eval {

README  view on Meta::CPAN

      both

	use both test_compile_run and test_ffi to verify

ATTRIBUTES

    Attributes of an Alien::Libarchive::Installer provide the information
    needed to use an existing libarchive (which may either be provided by
    the system, or have just been built using build_install.

 cflags

    The compiler flags required to use libarchive.

 libs

    The linker flags and libraries required to use libarchive.

 dlls

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

 version

    The version of libarchive

author.yml  view on Meta::CPAN

---
pod_spelling_system:
  skip: 0
  # list of words that are spelled correctly
  # (regardless of what spell check thinks)
  stopwords:
    - cbuilder
    - libarchive
    - cflags
    - libs
    - DLL
    - dlls
    - ffi
    - internet
    - org

pod_coverage:
  skip: 0
  # format is "Class#method" or "Class", regex allowed

lib/Alien/Libarchive/Installer.pm  view on Meta::CPAN

    
    require File::Spec;
    my $dir;
    my(@dlls) = map { 
      my($v,$d,$f) = File::Spec->splitpath($_); 
      $dir = [$v,File::Spec->splitdir($d)]; 
      $f;
    } $alien->dlls;
    
    my $build = bless {
      cflags  => [$alien->cflags],
      libs    => [$alien->libs],
      dll_dir => $dir,
      dlls    => \@dlls,
      prefix  => File::Spec->rootdir,
    }, $class;
    eval {
      $build->test_compile_run || die $build->error if $options{test} =~ /^(compile|both)$/;
      $build->test_ffi || die $build->error if $options{test} =~ /^(ffi|both)$/;
    };
    return $build unless $@;
  }

  my $build = bless {
    cflags => _try_pkg_config(undef, 'cflags', '', ''),
    libs   => _try_pkg_config(undef, 'libs',   '-larchive', ''),
  }, $class;
  
  if($options{test} =~ /^(ffi|both)$/)
  {
    my @dir_search_list;
    
    if($^O eq 'MSWin32')
    {
      # On MSWin32 the entire path is not included in dl_library_path

lib/Alien/Libarchive/Installer.pm  view on Meta::CPAN

      {
        # TODO: later when we know the version with more
        # certainty, we can update this file with the
        # Version
        @content = join "\n", "prefix=\${pcfiledir}/../..",
                              "exec_prefix=\${prefix}",
                              "libdir=\${exec_prefix}/lib",
                              "includedir=\${prefix}/include",
                              "Name: libarchive",
                              "Description: library that can create and read several streaming archive formats",
                              "Cflags: -I\${includedir}",
                              "Libs: advapi32.lib \${libdir}/archive_static.lib",
                              "Libs.private: ",
                              "";
        require File::Path;
        File::Path::mkpath($pkg_config_dir, 0, 0755);
      }
      
      my($version) = map { /^Version:\s*(.*)$/; $1 } grep /^Version: /, @content;
      # older versions apparently didn't include the necessary -I and -L flags
      if(defined $version && $version =~ /^[12]\./)
      {
        for(@content)
        {
          s/^Libs: /Libs: -L\${libdir} /;
        }
        push @content, "Cflags: -I\${includedir}\n";
      }
      
      open my $fh, '>', $pcfile;
      print $fh @content;
      close $fh;
    };
    
    my $build = bless {
      cflags  => _try_pkg_config($pkg_config_dir, 'cflags', '-I' . File::Spec->catdir($prefix, 'include'), '--static'),
      libs    => _try_pkg_config($pkg_config_dir, 'libs',   '-L' . File::Spec->catdir($prefix, 'lib'),     '--static'),
      prefix  => $prefix,
      dll_dir => [ 'dll' ],
      dlls    => do {
        opendir(my $dh, File::Spec->catdir($prefix, 'dll'));
        [grep { ! -l File::Spec->catfile($prefix, 'dll', $_) } grep { /\.so/ || /\.(dll|dylib)$/ } grep !/^\./, readdir $dh];
      },
    }, $class;
    
    if($^O eq 'cygwin' || $^O eq 'MSWin32')
    {
      # TODO: should this go in the munged pc file?
      unshift @{ $build->{cflags} }, '-DLIBARCHIVE_STATIC';
    }

    $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;
}


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

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

lib/Alien/Libarchive/Installer.pm  view on Meta::CPAN

              "{\n",
              "  printf(\"version = '%d'\\n\", archive_version_number());\n",
              "  return 0;\n",
              "}\n";
    close $fh;
  };
  
  my $test_object = eval {
    $cbuilder->compile(
      source               => $fn,
      extra_compiler_flags => $self->{cflags} || [],
    );
  };
  
  if(my $error = $@)
  {
    $self->{error} = $error;
    return;
  }
  
  my $test_exe = eval {
    $cbuilder->link_executable(
      objects            => $test_object,
      extra_linker_flags => $self->{libs} || [],
    );
  };
  
  if(my $error = $@)
  {
    $self->{error} = $error;
    return;
  }
  
  if($test_exe =~ /\s/)

lib/Alien/Libarchive/Installer.pm  view on Meta::CPAN


 # as an optional dep
 use Alien::Libarchive::Installer;
 use Module::Build;
 
 my %build_args;
 
 my $installer = eval { Alien::Libarchive::Installer->system_install };
 if($installer)
 {
   $build_args{extra_compiler_flags} = $installer->cflags,
   $build_args{extra_linker_flags}   = $installer->libs,
 }
 
 my $build = Module::Build->new(%build_args);
 $build->create_build_script;

Build.PL

 # require 3.0
 use Alien::Libarchive::Installer;
 use Module::Build;

lib/Alien/Libarchive/Installer.pm  view on Meta::CPAN

 my $installer = eval {
   my $system_installer = Alien::Libarchive::Installer->system_install;
   die "we require 3.0.x or better"
     if $system_installer->version !~ /^([0-9]+)\./ && $1 >= 3;
   $system_installer;
      # reasonably assumes that build_install will never download
      # a version older that 3.0
 } || Alien::Libarchive::Installer->build_install("dir");
 
 my $build = Module::Build->new(
   extra_compiler_flags => $installer->cflags,
   extra_linker_flags   => $installer->libs,
 );
 $build->create_build_script;

FFI::Raw

 # as an optional dep
 use Alien::Libarchive::Installer;
 use FFI::Raw;
 
 eval {

lib/Alien/Libarchive/Installer.pm  view on Meta::CPAN


=back

=head1 ATTRIBUTES

Attributes of an L<Alien::Libarchive::Installer> provide the
information needed to use an existing libarchive (which may
either be provided by the system, or have just been built
using L<build_install|Alien::Libarchive::Installer#build_install>.

=head2 cflags

The compiler flags required to use libarchive.

=head2 libs

The linker flags and libraries required to use libarchive.

=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 libarchive

t/build_install.t  view on Meta::CPAN

    plan skip_all => "not testing $version on cygwin"
      if $^O eq 'cygwin' && $version ne '2.8.4';
    plan tests => 5;
    my $tar = Alien::Libarchive::Installer->fetch( version => $version );
    my $installer = eval { Alien::Libarchive::Installer->build_install( File::Spec->catdir($prefix, $version), tar => $tar, test => $type ) };
    is $@, '', 'no error';
    SKIP: {
      skip "can't test \$installer without a sucessful build", 4 if $@ ne '';
      is $installer->version, $version,  "version = $version";
      ok $installer->{libs},  "libs = ". join(' ', @{ $installer->libs });
      ok $installer->{cflags}, "cflags = ". join(' ', @{ $installer->cflags });
      my $exe = File::Spec->catfile($prefix, $version, 'bin', 'bsdtar' . ($^O =~ /^(MSWin32|cygwin)$/ ? '.exe' : ''));
      ok -r $exe, "created executable $exe";
    };
  };
}

done_testing;

t/test_compile_run.t  view on Meta::CPAN

BEGIN {
  plan skip_all => 'test  requires Devel::CheckLib'
    unless eval q{ use Devel::CheckLib; 1};
}

plan skip_all => 'requires libarchive already installed'
  unless check_lib( lib => 'archive', header => 'archive.h' );

plan tests => 1;

my $installer = bless { cflags => [], libs => ['-larchive'] }, 'Alien::Libarchive::Installer';

my $version = $installer->test_compile_run;
like $version, qr{^[1-9][0-9]*(\.[0-9]+){2}$}, "version = $version";

t/test_ffi.t  view on Meta::CPAN

use Alien::Libarchive::Installer;
use DynaLoader;

plan skip_all => 'test requires FFI::Raw'
  unless eval { require FFI::Raw };
plan skip_all => 'test requires dynamic libarchive'
  unless (defined DynaLoader::dl_findfile('-larchive')) || ($^O eq 'cygwin' && -e '/usr/bin/cygarchive-13.dll');

plan tests => 1;

my $installer = bless { cflags => [], libs => ['-larchive'] }, 'Alien::Libarchive::Installer';

my $version = $installer->test_ffi;
like $version, qr{^[1-9][0-9]*(\.[0-9]+){2}$}, "version = $version";



( run in 0.402 second using v1.01-cache-2.11-cpan-94b05bcf43c )