Alien-Libarchive

 view release on metacpan or  search on metacpan

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

  my @libs = @{ $cf->config("libs") };
  if($class->install_type eq 'share')
  {
    if($cf->config('msvc'))
    {
      unshift @libs, '/libpath:' . _catdir(_share_dir, 'libarchive019', 'lib');
      @libs = map { s{^.*(\\|/)}{} if m/archive_static\.lib$/; $_ } @libs;
    }
    else
    {
      unshift @libs, '-L' . _catdir(_share_dir, 'libarchive019', 'lib');
    }
  }
  wantarray ? @libs : "@libs";
}


sub dlls
{
  my($class) = @_;
  my @list;
  if($class->install_type eq 'system')
  {
    require Alien::Libarchive::Installer;
    @list = Alien::Libarchive::Installer->system_install( alien => 0, test => 'ffi' )->dlls;
  }
  else
  {
    @list = map { _catfile(_share_dir, 'libarchive019', 'dll', $_) }
            @{ $cf->config("dlls") };
  }
  wantarray ? @list : $list[0];
}


sub version
{
  $cf->config("version");
}


sub install_type
{
  $cf->config("install_type");
}


sub pkg_config_dir
{
  _catdir(_share_dir, 'libarchive019', 'lib', 'pkgconfig');
}


sub pkg_config_name
{
  'libarchive';
}

# extract the macros from the header files, this is a private function
# because it may not be portable.  Used by the Archive::Libarchive::XS
# build process (and maybe Archive::Libarchive::FFI) to automatically
# generate constants
# UPDATE: this maybe should use C::Scan or C::Scan::Constants
sub _macro_list
{
  require Config;
  require File::Temp;
  require File::Spec;

  my $alien = Alien::Libarchive->new;
  my $cc = "$Config::Config{ccname} $Config::Config{ccflags} " . $alien->cflags;

  my $fn = File::Spec->catfile(File::Temp::tempdir( CLEANUP => 1 ), "test.c");

  do {
    open my $fh, '>', $fn;
    print $fh "#include <archive.h>\n";
    print $fh "#include <archive_entry.h>\n";
    close $fh;
  };

  my @list;
  my $cmd = "$cc -E -dM $fn";
  foreach my $line (`$cmd`)
  {
    if($line =~ /^#define ((AE|ARCHIVE)_\S+)/)
    {
      push @list, $1;
    }
  }
  sort @list;
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Alien::Libarchive - Build and make available libarchive

=head1 VERSION

version 0.28

=head1 SYNOPSIS

Build.PL

 use Alien::Libarchive;
 use Module::Build;
 
 my $alien = Alien::Libarchive->new;
 my $build = Module::Build->new(
   ...
   extra_compiler_flags => [$alien->cflags],



( run in 2.825 seconds using v1.01-cache-2.11-cpan-13bb782fe5a )