use alienfile;

plugin 'Probe::Vcpkg' => (
  name     => 'hunspell',
  ffi_name => 'libhunspell',
  include  => 'hunspell',
);
plugin 'PkgConfig' => (
  pkg_name => 'hunspell',
);

share {

  requires 'Alien::Build'     => '0.75';

  plugin 'Prefer::BadVersion' => ['1.7.0'] if $^O eq 'MSWin32';

  my $version = $^O eq 'MSWin32' ? '1.6.2.1' : '1.7.0.1';

  plugin 'Download' => (
    # trying to autoreconf + patch + whatnot hunspell has jus become too much
    # trouble, so we're using a prepatched copy that already has been autoreconf'd
    url => "https://github.com/PerlAlien/hunspell/archive/alien-$version.tar.gz",
    version => qr/^([0-9\.]+)\\.[0-9]+.tar\.gz$/,
  );

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

  my @acflags;
  unshift @acflags, '--disable-nls' if $^O =~ /^(?:MSWin32|darwin|freebsd)/;

  build [
    "%{configure} --disable-shared --enable-static @acflags",
    '%{make}',
    '%{make} install',
  ];

  ffi {
    build [
      "%{configure} --disable-static --enable-shared --libdir=%{.install.autoconf_prefix}/dynamic @acflags",
      '%{make}',
      '%{make} install',
    ];
  };
};
