Alien-PNG
view release on metacpan or search on metacpan
inc/My/Builder.pm view on Meta::CPAN
my ($self, $url, $sha1sum, $download) = @_;
die "###ERROR### _fetch_file undefined url\n" unless $url;
die "###ERROR### _fetch_file undefined sha1sum\n" unless $sha1sum;
my $ff = File::Fetch->new(uri => $url);
my $fn = catfile($download, $ff->file);
if (-e $fn) {
print "Checking checksum for already existing '$fn'...\n";
return 1 if $self->check_sha1sum($fn, $sha1sum);
unlink $fn; #exists but wrong checksum
}
print "Fetching '$url'...\n";
my $fullpath = $ff->fetch(to => $download);
die "###ERROR### Unable to fetch '$url'" unless $fullpath;
if (-e $fn) {
print "Checking checksum for '$fn'...\n";
return 1 if $self->check_sha1sum($fn, $sha1sum);
die "###ERROR### Checksum failed '$fn'";
}
die "###ERROR### _fetch_file failed '$fn'";
}
sub fetch_binaries {
my ($self, $download) = @_;
my $bp = $self->notes('build_params');
$self->fetch_file($bp->{url}, $bp->{sha1sum}, $download);
}
sub check_prereqs {
my ($self) = @_;
my $bp = $self->notes('build_params');
#print "-l$_\n" foreach (@{$_->{libs}) foreach (@{$bp->{prereqs}});
}
sub fetch_sources {
my ($self, $download) = @_;
my $bp = $self->notes('build_params');
$self->fetch_file($_->{url}, $_->{sha1sum}, $download) foreach (@{$bp->{members}});
}
sub extract_binaries {
my ($self, $download, $build_out) = @_;
# do extract binaries
my $bp = $self->notes('build_params');
my $archive = catfile($download, File::Fetch->new(uri => $bp->{url})->file);
print "Extracting $archive...\n";
my $ae = Archive::Extract->new( archive => $archive );
die "###ERROR###: Cannot extract $archive ", $ae->error unless $ae->extract(to => $build_out);
# fix hardcoded prefix path in bin/libpng-config
my ($version, $prefix, $incdir, $libdir) = find_PNG_dir(rel2abs($build_out));
sed_inplace("$prefix/bin/libpng-config", 's/^prefix=.*/prefix=\''.quotemeta($prefix).'\'/');
}
sub extract_sources {
my ($self, $download, $patches, $build_src) = @_;
my $bp = $self->notes('build_params');
foreach my $pack (@{$bp->{members}}) {
my $srcdir = catfile($build_src, $pack->{dirname});
my $unpack = 'y';
$unpack = $self->prompt("Dir '$srcdir' exists, wanna replace with clean sources?", "n") if (-d $srcdir);
if (lc($unpack) eq 'y') {
my $archive = catfile($download, File::Fetch->new(uri => $pack->{url})->file);
print "Extracting $pack->{pack}...\n";
my $ae = Archive::Extract->new( archive => $archive );
die "###ERROR###: cannot extract $pack ", $ae->error unless $ae->extract(to => $build_src);
foreach my $i (@{$pack->{patches}}) {
chdir $srcdir;
print "Checking affected files for patch '$i'\n";
foreach my $k ($self->patch_get_affected_files($srcdir, catfile($patches, $i))) {
# doing the same like -p1 for 'patch'
$k =~ s/^[^\/]*\/(.*)$/$1/;
if(-e $k) {
print "Preparing file '$k'\n";
sed_inplace( $k, 's/\r\n/\n/gm' ); # converting to UNIX newlines
}
else {
print "###WARN### file '$k' for patch '$i' not found\n";
}
}
print "Applying patch '$i'\n";
my $cmd = $self->patch_command($srcdir, catfile($patches, $i));
if ($cmd) {
print "(cmd: $cmd)\n";
$self->do_system($cmd) or die "###ERROR### [$?] during patch ... ";
}
chdir $self->base_dir();
}
}
}
return 1;
}
sub set_config_data {
my( $self, $build_out ) = @_;
# try to find PNG root dir
my ($version, $prefix, $incdir, $libdir) = find_PNG_dir(rel2abs($build_out));
die "###ERROR### Cannot find PNG directory in 'sharedir'" unless $version;
$self->config_data('share_subdir', abs2rel($prefix, rel2abs('sharedir')));
# set defaults
my $cfg = {
# defaults
version => $version,
prefix => '@PrEfIx@',
libs => '-L' . $self->get_path('@PrEfIx@/lib') . ' -lpng',
cflags => '-I' . $self->get_path('@PrEfIx@/include') . ' -D_GNU_SOURCE=1', # -Dmain=SDL_main
shared_libs => [ ],
};
# overwrite values available via libpng-config
my $bp = $self->config_data('build_prefix') || $prefix;
my $devnull = File::Spec->devnull();
my $script = rel2abs("$prefix/bin/libpng-config");
foreach my $p (qw(version prefix L_opts libs I_opts cflags)) {
my $o=`$script --$p 2>$devnull`;
if ($o) {
$o =~ s/[\r\n]*$//;
$o =~ s/\Q$prefix\E/\@PrEfIx\@/g;
$cfg->{$p} = $o;
( run in 1.232 second using v1.01-cache-2.11-cpan-6aa56a78535 )