use alienfile;

configure {
  requires 'Alien::Build' => '1.74';
  requires 'Alien::Build::Plugin::Decode::Mojo';
  requires 'Alien::Build::Plugin::Probe::GnuWin32' => '0.59';
};

plugin 'Probe::GnuWin32' => (
  registry_key_regex  => qr/^flex/i,
  exe_name            => 'bison',
  exe_version         => qr/bison .*?([0-9\.]+)/,
  exe_match           => qr/bison/,
  exe_args            => ['--version'],
);

plugin 'Probe::CommandLine' => (
  command => 'bison',
  args    => ['--version'],
  match   => qr/bison/,
  version => qr/bison .*?([0-9\.]+)/,
);

share {

  requires 'Alien::m4'    => '0.08';

  patch [ '%{patch} -p1 < %{alien.install.patch}/bison-3_0_2.diff' ] if $^O eq 'MSWin32';

  plugin 'Download' => (
    url     => 'http://ftp.gnu.org/gnu/bison/',
    version => qr/^bison-([0-9\.]+)\.tar\.gz$/,
    decoder => 'Decode::Mojo',
  );

  plugin 'Extract' => 'tar.gz';  
  
  plugin 'Build::Autoconf' => ();

  gather sub {
    my($build) = @_;
    if(`bison --version` =~ /bison .*?([0-9\.]+)/)
    {
      $build->runtime_prop->{version} = $1;
    }
    else
    {
      $build->runtime_prop->{version} ||= 'unknown';
    }
  };

}

