use alienfile;
use Config;
use strict;
use warnings;
probe sub {'share'};    # Always build because we're using a fork of libui
my $osx   = $Config{osname} eq 'darwin';
my $win32 = $Config{osname} eq 'MSWin32';
share {
    requires 'Alien::Meson';
    requires 'Alien::Ninja';
    start_url 'https://github.com/sanko/libui-ng/archive/refs/heads/master.tar.gz';

    #   'https://github.com/libui-ng/libui-ng/archive/refs/heads/master.tar.gz';
    plugin 'Download';
    plugin Extract => 'tar.gz';

    # download ['https://github.com/libui-ng/libui-ng/archive/refs/heads/master.zip'];
    plugin Extract => 'tar.gz';
    my $build_dir = '_build';
    build [
        sub {
            my $build = shift;
            Alien::Build::CommandSequence->new(
                [   Alien::Meson->exe, 'setup', $build_dir,

                    #'-Dtests=false', '-Dexamples=false',
                    '--buildtype=release', '--default-library=shared',
                    '--prefix=%{.install.prefix}',
                ]
            )->execute($build);
        },
        [ '%{ninja}', qw(-C), $build_dir ],
        [ '%{ninja}', qw(-C), $build_dir, "test" ],
        [ '%{ninja}', qw(-C), $build_dir, 'install' ],
    ];

    #gather [
    #   [   'echo "-L%{.install.prefix}/lib"' . ( $osx ? ' --stdlib=libc++' : '' ),
    #       \'%{.runtime.libs}'
    #  ],
    #  [ 'echo "-I%{.install.prefix}/include"', \'%{.runtime.cflags}' ],
    #];
    plugin 'Gather::IsolateDynamic';
};
