use alienfile;

plugin PkgConfig => 'libzstd';
plugin 'Probe::CommandLine' => (
  command   => 'zstd',
  args      => [ '--version' ],
  match     => qr/zstd command line interface/,
  secondary => 1,
);

share {
  plugin 'Download::GitHub' => (
    github_user => 'facebook',
    github_repo => 'zstd',
  );
  plugin Extract => 'tar.gz';
  plugin 'Build::CMake';
  my $build_dir = '_build';
  build [
    ['%{cmake}',
      @{ meta->prop->{plugin_build_cmake}->{args} },

      qw(-DZSTD_BUILD_PROGRAMS=ON), # tool
      qw(-DZSTD_BUILD_STATIC=ON),   # xs
      qw(-DZSTD_BUILD_SHARED=ON),   # ffi

      qw(-DZSTD_BUILD_TESTS=OFF),

      qw(-S), '%{.install.extract}/build/cmake',
      qw(-B), $build_dir,
    ],
    [ '%{make}', qw( -C ), $build_dir ],
    [ '%{make}', qw( -C ), $build_dir, 'install' ],
  ];
  plugin 'Gather::IsolateDynamic';
}
