Alien-IUP
view release on metacpan or search on metacpan
inc/My/Builder.pm view on Meta::CPAN
}
sub fetch_file {
my ($self, %args) = @_;
my $url = $args{url};
my $sha1 = $args{sha1};
my $localdir = $args{localdir};
my $localfile = $args{localfile};
die "###ERROR### fetch_file: undefined url\n" unless $url;
# create $localdir if necessary
File::Path::mkpath($localdir) unless $localdir && -d $localdir;
# handle redirects
my $head = head($url);
$url = $head->request->uri if defined $head;
# download destination
unless ($localfile) {
$localfile = $url;
$localfile =~ s/^.*?([^\\\/]+)$/$1/; #skip all but file part of URL
$localfile =~ s/\?.*$//; #skip URL params
}
$localfile = File::Spec->catfile($localdir, $localfile) if $localdir;
# check existing file
if (-f $localfile) {
if ($sha1) {
if ($self->check_sha1sum($localfile, $sha1)) {
return rel2abs($localfile);
}
else {
warn "Checksum FAILURE";
}
}
unlink $localfile; # if sha1 not given we force re-download
}
# download
warn "Fetching '$url'...\n";
my $rv = getstore($url, $localfile);
die "###ERROR### fetch_file: download error - return code '$rv'\n" unless $rv == 200;
die "###ERROR### fetch_file: download error - '$localfile' not saved\n" unless -f $localfile;
# checksum
if ($sha1) {
die "###ERROR### fetch_file: checksum failed" unless $self->check_sha1sum($localfile, $sha1);
}
return rel2abs($localfile);
}
sub check_sha1sum {
my ($self, $file, $sha1sum) = @_;
return 1 if $sha1sum eq 'DO_NOT_CHECK_SHA1';
warn "Checking checksum for '$file'...\n";
my $sha1 = Digest::SHA->new;
my $fh;
open($fh, $file) or die "###ERROR## Cannot check checksum for '$file'\n";
binmode($fh);
$sha1->addfile($fh);
close($fh);
my $file_sha1sum = $sha1->hexdigest;
my $rv = ($file_sha1sum eq $sha1sum) ? 1 : 0;
warn "###WARN## sha1 mismatch: got '", $file_sha1sum , "'\n",
"###WARN## sha1 mismatch: expected '", $sha1sum, "'\n",
"###WARN## sha1 mismatch: filesize ", (-s $file) unless $rv;
return $rv;
}
sub build_binaries {
die "###ERROR### My::Builder is not able to build, use rather My::Builder::<platform>";
}
sub quote_literal {
# this needs to be overriden in My::Builder::<platform>
my ($self, $path) = @_;
return $path;
}
sub check_installed_lib {
my ($self) = @_;
#xxxTODO
#we not only need to detect the presence we also need to exactly know what libs are there - necessary for havelib() function
print STDERR "\nNOTICE:\nDetection of preinstalled iup+cd+im is disabled since v0.115!\nPlease contact the module author if you are missing this feature.\n\n";
return 0;
my $idir = $ENV{IUP_DIR} || '';
my @candidates;
push(@candidates, { L => "$idir/lib", I => "$idir/include" }) if -d $idir;
push(@candidates, { L => '', I => '' });
push(@candidates, { L => '', I => $Config{usrinc} }) if -d $Config{usrinc};
push(@candidates, { L => '/usr/local/lib', I => '/usr/local/include' }) if -d '/usr/local/lib' && -d '/usr/local/include';
push(@candidates, { L => '/usr/lib', I => '/usr/include' }) if -d '/usr/lib' && -d '/usr/include';
print STDERR "Checking iup+im+cd already installed on your system ...\n";
foreach my $i (@candidates) {
my $lflags = $i->{L} ? '-L'.$self->quote_literal($i->{L}) : '';
my $cflags = $i->{I} ? '-I'.$self->quote_literal($i->{I}) : '';
#xxx does not work with MSVC compiler
#xxx $lflags = ExtUtils::Liblist->ext($lflags) if($Config{make} =~ /nmake/ && $Config{cc} =~ /cl/); # MSVC compiler hack
print STDERR "- testing: $cflags $lflags\n";
my $rv1 = $self->check_header( [ 'iup.h', 'im.h', 'cd.h' ], $cflags);
#xxx maybe we need to link with more libs
if ($self->check_lib( [ 'iup', 'im', 'cd' ], $cflags, $lflags)){
print STDERR "- iup+im+cd FOUND!\n";
$self->notes('already_installed_lib', { lflags => "$lflags -liup -lim -lcd", cflags => $cflags } );
return 1;
}
elsif ($self->check_lib( [ 'iupwin', 'im', 'cdwin' ], $cflags, $lflags)) {
print STDERR "- iupwin+im+cdwin FOUND!\n";
$self->notes('already_installed_lib', { lflags => "$lflags -liupwin -lim -lcdwin", cflags => $cflags } );
return 1;
}
elsif ($self->check_lib( [ 'iupgtk', 'im', 'cdgdk' ], $cflags, $lflags)) {
print STDERR "- iupgtk+im+cdgdk FOUND!\n";
$self->notes('already_installed_lib', { lflags => "$lflags -liupgtk -lim -lcdgdk", cflags => $cflags } );
return 1;
}
( run in 0.973 second using v1.01-cache-2.11-cpan-2ed5026b665 )