Alien-MSYS
view release on metacpan or search on metacpan
use alienfile;
use Path::Tiny qw( path );
use File::Glob qw( bsd_glob );
use File::Which qw( which );
use List::Util qw( all );
# no share install unless on windows
delete $ENV{ALIEN_INSTALL_TYPE}
if $^O ne 'MSWin32' && $^O ne 'cygwin';
if($^O eq 'MSWin32')
{
my $ver;
my $err;
{
local $@;
$err = $@ || 'Error' unless eval {
require Win32;
$ver = (Win32::GetOSVersion())[1];
};
}
if($err || $ver < 6)
{
print "Please upgrade to Windows 7 or better (ideally Windows 10).\n";
print "The native crypto libraries on Windows XP, used by mingw-gwt\n";
print "no longer work with sourceforge.\n";
exit;
}
else
{
log "Windows major version $ver ok.\n";
}
}
configure {
requires 'Alien::Build' => '0.99';
requires 'Path::Tiny' => 0;
requires 'File::Glob' => 0;
};
my @exes_to_check = qw( sh.exe perl.exe m4.exe mktemp.exe readlink.exe );
sub msys_is_okay
{
my($dir) = @_;
-d path($dir)
&& (
all { -x path($dir)->child($_ ) } @exes_to_check
)
}
probe sub {
my($build) = @_;
if($^O eq 'MSWin32' || $ENV{PERL_ALIEN_MSYS_FAUX})
{
return 'share'
if defined $ENV{ALIEN_MSYS_INSTALL_TYPE} && $ENV{ALIEN_MSYS_INSTALL_TYPE} eq 'share';
if(defined $ENV{PERL_ALIEN_MSYS_BIN})
{
if(msys_is_okay($ENV{PERL_ALIEN_MSYS_BIN}))
{
$build->runtime_prop->{my_type} = 'PERL_ALIEN_MSYS_BIN';
{
my $from = path($ret->{path});
my $to = $ret->{filename};
if($ret->{tmp})
{
$from->move($to);
}
else
{
$from->copy($to);
}
}
else
{
die 'get did not return a file';
}
};
};
meta->around_hook(
build => sub {
my $orig = shift;
use Env qw( @PATH );
local $ENV{PATH} = $ENV{PATH};
unshift @PATH, path('./bin')->absolute->stringify;
foreach my $dll (grep { $_->basename =~ /\.dll$/ } path('libexec/mingw-get')->children)
{
eval { chmod 0755, $dll };
}
$orig->(@_);
},
);
build [
'mingw-get install msys', # sh.exe, etc.
'mingw-get install msys-m4', # m4.exe
'mingw-get install msys-perl', # perl.exe
'mingw-get install msys-coreutils-ext', # readlink.exe, etc.
'mingw-get install msys-mktemp', # mktemp.exe
sub {
my($build) = @_;
$build->log("checking for @exes_to_check ...");
foreach my $exe (map { "msys/1.0/bin/$_" } @exes_to_check)
{
unless(-f $exe)
{
die "not found: $exe";
}
}
$build->log("remove package cache, and man pages");
# remove var/cache/mingw-get/packages/*
unlink $_ for bsd_glob('var/cache/mingw-get/packages/*');
# remove msys/1.0/share/{doc,man}
eval { path('msys/1.0/share/doc')->remove_tree };
eval { path('msys/1.0/share/man')->remove_tree };
$build->log("moving to @{[ $build->install_prop->{stage} ]}");
if($^O eq 'cygwin')
{
$build->system('mv * %{.install.stage}');
}
elsif($^O eq 'MSWin32')
{
my $stage = path($build->install_prop->{stage})->canonpath;
$build->system("xcopy . $stage /E");
}
else
{
die "huh?";
}
$build->log("checking for @exes_to_check ...");
foreach my $exe (map { "@{[ $build->install_prop->{stage} ]}/msys/1.0/bin/$_" } @exes_to_check)
{
unless(-f $exe)
{
die "not found: $exe";
}
}
},
];
gather sub {
my($build) = @_;
$build->runtime_prop->{my_type} = 'share';
};
};
( run in 0.804 second using v1.01-cache-2.11-cpan-6b5c3043376 )