#!perl
use strict;
use warnings;
use Alien::Base::ModuleBuild;

my $mb = Alien::Base::ModuleBuild->new(
    dist_name => 'Alien-QREncode',
    module_name => 'Alien::QREncode',

    alien_name => 'qrencode',
    alien_inline_auto_include => ['qrencode.h'],
    alien_repository => {
        protocol => 'https',
        host => 'fukuchi.org',
        location => '/works/qrencode/index.html.en',
        pattern => qr{^qrencode-(.*?)\.tar\.bz2$},
    },
    configure_requires  => { 'Alien::Base::ModuleBuild' => '0.022' },
    alien_version_check => '%{pkg_config} --atleast-version 3.4.4 %n && %{pkg_config} --modversion %n',

    license => 'gpl',
);

my %png_check = $mb->alien_do_system('%{pkg_config} libpng');
my %sdl_check = $mb->alien_do_system('%{pkg_config} sdl');

if ($png_check{success} && $sdl_check{success}) {
    $mb->alien_build_commands([
        '%c --prefix=%s --with-tests',
        'make',
    ]);
    $mb->alien_test_commands([
        'cd tests && ./create_frame_pattern frame',
        'cd tests && ./test_all.sh',
    ]);
}

$mb->create_build_script;
