use alienfile;

plugin 'PkgConfig' => 'libyara';

probe sub {
  require FFI::CheckLib;
  return FFI::CheckLib::check_lib( lib => 'yara' ) ? 'system' : 'share';
};

share {
  start_url 'https://github.com/VirusTotal/yara/archive/refs/tags/v4.5.0.tar.gz';

  plugin 'Download' => (
    filter => qr/^yara-?([\d\.]+)\.tar\.gz$/,
  );
  plugin 'Extract' => 'tar.gz';

  # Pass custom arguments directly to the autoconf script via 'args'
  plugin 'Build::Autoconf' => (
    args => [ '--with-pic', '--disable-shared' ],
  );

  # Hook into the 'build' stage to run bootstrap BEFORE Autoconf triggers
  before 'build' => sub {
    my ($build) = @_;
    $build->command_sequence->run('sh', 'bootstrap.sh');
  };
};
