#! perl

use strict;
use warnings;

use alienfile;
use Path::Tiny;

plugin PkgConfig => 'xpa';

probe [ 'pkg-config --exists xpa' ];

share {
    start_url 'https://github.com/ericmandel/xpa/releases/latest';

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

    plugin Extract => 'tar.gz';

    patch sub {
        my ( $build ) = @_;

        # 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 libcxcregion', \'%{.runtime.version}' ],
  [ 'pkg-config --cflags     libcxcregion', \'%{.runtime.cflags}'  ],
  [ 'pkg-config --libs       libcxcregion', \'%{.runtime.libs}'    ],
];
