use alienfile;
use Capture::Tiny qw( capture );

requires 'Capture::Tiny';

plugin 'Probe::CommandLine' => (
  command => 'nasm',
  args    => ['-v'],
  match   => qr/NASM version/,
);

share {

  # TODO: we can now probably do a hierarchical fetch
  plugin 'Download' => (
    url     => 'http://www.nasm.us/pub/nasm/releasebuilds/2.12.02/',
    version => qr/^nasm-([0-9\.]+)\.tar\.gz$/,
  );
  plugin 'Extract' => 'tar.gz';  
  plugin 'Build::MSYS' => ();

  build [
    'sh configure --prefix=%{alien.install.prefix}',
    '%{gmake}',
    '%{gmake} install',
  ];
  
};

gather sub {
  my($build) = @_;
  my($stdout) = capture {
    system($build->runtime_prop->{command}, '-v');
  };
  my($version) = $stdout =~ /NASM version ([0-9\.]+)/;
  $build->runtime_prop->{version} = $version || 'unknown';
};

