#! perl

use strict;
use warnings;

use alienfile;
use Path::Tiny;
use File::Which;

my $pkg_name = 'cpgplot';
my $pkg_version = '5.2.2-9';

plugin 'Gather::IsolateDynamic';

plugin PkgConfig => (
   pkg_name => $pkg_name,
);

share {
    start_url "https://github.com/djerius/pgplot-autotool/releases/download/${pkg_version}/pgplot-${pkg_version}.tar.gz";
    plugin Download => (
       version => qr/(\d+\.\d+\.\d+-\d+)[.]tar[.].*$/,
    );

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

# find path to executables for system install, if found.
sys {
    after 'gather' => sub {
        my ( $build) = @_;

        if ( defined( my $exe = which( 'pgxwin_server' ) ) ) {
            $build->runtime_prop->{system_bin_dir} = path($exe)->parent->stringify;
        }
    };
}
