#! perl

use v5.10;
use strict;
use warnings;

use alienfile;
use Path::Tiny;

our $VERSION = 'v2.1.20.0';

use constant PACKAGE_VERSION => '2.1.20';
use constant PACKAGE_NAME => 'xpa';

plugin 'Gather::IsolateDynamic';

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

share {
    start_url 'src/xpa-2.1.20.tar.gz';

    plugin Download => (
       filter  => qr/(?:\d+[.]\d+[.]\d+)[.]tar[.]gz$/,
        version => qr/(\d+[.]\d+[.]\d+)[.]tar[.]gz$/,
    );

    plugin Extract => 'tar.gz';

    patch sub {

        # Makefile.in uses INSTALL_ROOT instead of DESTDIR
        path( 'Makefile.in' )->edit_lines(
            sub {
                s/^INSTALL_ROOT\s*=\s*$//;
                s/INSTALL_ROOT/DESTDIR/g;
            } );
    };

    plugin 'Build::Autoconf';
    build [ '%{configure}', '%{make} CFLAGS=-fPIC', '%{make} install' ];
};

gather [
    [ 'pkg-config --modversion xpa', \'%{.runtime.version}' ],
    [ 'pkg-config --cflags     xpa', \'%{.runtime.cflags}' ],
    [ 'pkg-config --libs       xpa', \'%{.runtime.libs}' ],
];
