Alien-Libarchive3

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

use alienfile;
use Config;
use FFI::CheckLib qw( find_lib_or_die );
use File::Glob qw( bsd_glob );
use Env qw( @PKG_CONFIG_PATH );

my @lib;

if($^O eq 'darwin')
{
  if(-d '/usr/local/Cellar/libarchive')
  {
    push @PKG_CONFIG_PATH, grep { -d $_ } bsd_glob '/usr/local/Cellar/libarchive/*/lib/pkgconfig';
    push @lib, grep { -d $_ } bsd_glob '/usr/local/Cellar/libarchive/*/lib'
  }
}

plugin 'PkgConfig' => (
  pkg_name => 'libarchive',
  minimum_version => '3.2.0',
);

plugin 'Probe::CBuilder' => (
  libs    => '-larchive',
  version => qr/version = '(.*?)[,']/,
  program => q{
#include <archive.h>
#include <archive_entry.h>

int main(int argc, char *argv[])
{
  int r;
  archive_read a;

  a = archive_read_new();
  if(a == NULL)
    return 2;

  r = archive_read_free(a);
  if(r != ARCHIVE_OK)
    return 2;

  printf("version = '%s'\n", ARCHIVE_VERSION_ONLY_STRING);
  return 0;
}
},
);

meta->around_hook('probe' => sub {
  my $orig = shift;
  my $build = shift;
  my $type = $orig->($build, @_);
  return $type if $type eq 'share';
  find_lib_or_die lib => 'archive', symbol => [
    'archive_read_free',
    'archive_write_free',
    'archive_free',
  ], libpath => [@lib];
  return $type;
});

share {

  requires 'Env::ShellWords' => '0.01';

  plugin Download => (
    url     => 'https://libarchive.org',
    version => qr/^libarchive-([0-9\.]+)\.tar\.gz$/,
  );

  plugin Extract => 'tar.gz';

  # TODO: lz4 https://github.com/lz4/lz4/releases
  # TODO: http://zlib.net/



( run in 1.402 second using v1.01-cache-2.11-cpan-e1769b4cff6 )