Alien-nasm
view release on metacpan or search on metacpan
use alienfile;
use Capture::Tiny qw( capture );
use Config;
configure { requires 'Capture::Tiny' };
plugin 'Probe::CommandLine' => (
command => 'nasm',
args => ['-v'],
match => qr/NASM version/,
);
plugin 'Probe::CommandLine' => (
command => 'ndisasm',
args => ['-v'],
match_stderr => qr/NDISASM version/,
secondary => 1,
);
share {
requires 'Path::Tiny';
plugin 'Fetch::HTTPTiny' => 'https://www.nasm.us/pub/nasm/releasebuilds';
plugin 'Decode::Mojo' => ();
plugin 'Prefer::SortVersions' => ();
download sub {
my($build) = @_;
my $res = $build->decode($build->fetch('https://www.nasm.us/pub/nasm/releasebuilds'));
$res->{list} = [grep { $_->{filename} =~ /^[0-9\.]+$/ } @{ $res->{list} }];
$res = $build->prefer($res);
die "unable to find first level candidate"
unless @{ $res->{list} } > 0;
my $url;
my $regex;
if($^O eq 'MSWin32')
{
my $bits = $Config{ptrsize} == 4 ? '32' : '64';
$url = $res->{list}->[0]->{url} . "/win$bits";
$regex = qr/^nasm-[0-9\.]+-win$bits\.zip$/;
}
else
{
$url = $res->{list}->[0]->{url};
$regex = qr/^nasm-[0-9\.]+\.tar\.gz$/;
}
$res = $build->decode($build->fetch($url));
$res->{list} = [grep { $_->{filename} =~ $regex } @{ $res->{list} }];
$res = $build->prefer($res);
die "unable to find second level candidate"
unless @{ $res->{list} } > 0;
$res = $build->fetch($res->{list}->[0]->{url});
Path::Tiny->new($res->{filename})->spew_raw($res->{content});
$build->runtime_prop->{command} = 'nasm';
};
if($^O eq 'MSWin32')
{
requires 'Path::Tiny';
plugin 'Extract' => 'zip';
build sub {
my($build) = @_;
my $dest = Path::Tiny->new($build->install_prop->{prefix})->child('bin');
$dest->mkpath;
foreach my $exe (qw( nasm.exe ndisasm.exe ))
{
Path::Tiny->new($exe)->copy($dest->child($exe));
}
};
}
else
{
plugin 'Extract' => 'tar.gz';
plugin 'Build::MSYS' => ();
build [
'sh configure --prefix=%{alien.install.prefix}',
'%{gmake}',
'%{gmake} install',
];
}
};
gather sub {
my($build) = @_;
my($stdout,$stderr) = capture {
system('nasm', '-v');
};
my $version = 'unknown';
if($stdout =~ /NASM version ([0-9\.]+)/)
{ $version = $1 }
elsif($stderr =~ /NASM version ([0-9\.]+)/)
{ $version = $1 }
$build->runtime_prop->{version} = $version;
};
( run in 0.322 second using v1.01-cache-2.11-cpan-adec679a428 )