Alien-PNG
view release on metacpan or search on metacpan
inc/My/Utility.pm view on Meta::CPAN
$p->{buildtype} = 'build_from_sources';
}
return $source_packs;
}
sub find_file {
my ($dir, $re) = @_;
my @files;
$re ||= qr/.*/;
find({ wanted => sub { push @files, rel2abs($_) if /$re/ }, follow => 1, no_chdir => 1 , follow_skip => 2}, $dir);
return @files;
}
sub find_PNG_dir {
my $root = shift;
my ($version, $prefix, $incdir, $libdir);
return unless $root;
# try to find png.h
my ($found) = find_file($root, qr/png\.h$/i ); # take just the first one
return unless $found;
# get version info
open(DAT, $found) || return;
my @raw=<DAT>;
close(DAT);
my ($v_maj) = grep(/^#define[ \t]+PNG_LIBPNG_VER_MAJOR[ \t]+[0-9]+/, @raw);
$v_maj =~ s/^#define[ \t]+PNG_LIBPNG_VER_MAJOR[ \t]+([0-9]+)[.\r\n]*$/$1/;
my ($v_min) = grep(/^#define[ \t]+PNG_LIBPNG_VER_MINOR[ \t]+[0-9]+/, @raw);
$v_min =~ s/^#define[ \t]+PNG_LIBPNG_VER_MINOR[ \t]+([0-9]+)[.\r\n]*$/$1/;
my ($v_pat) = grep(/^#define[ \t]+PNG_LIBPNG_VER_RELEASE[ \t]+[0-9]+/, @raw);
$v_pat =~ s/^#define[ \t]+PNG_LIBPNG_VER_RELEASE[ \t]+([0-9]+)[.\r\n]*$/$1/;
return if (($v_maj eq '')||($v_min eq '')||($v_pat eq ''));
$version = "$v_maj.$v_min.$v_pat";
# get prefix dir
my ($v, $d, $f) = splitpath($found);
my @pp = reverse splitdir($d);
shift(@pp) if(defined($pp[0]) && $pp[0] eq '');
shift(@pp) if(defined($pp[0]) && $pp[0] =~ /libpng\d+/);
if(defined($pp[0]) && $pp[0] eq 'include') {
shift(@pp);
@pp = reverse @pp;
return (
$version,
catpath($v, catdir(@pp), ''),
catpath($v, catdir(@pp, 'include'), ''),
catpath($v, catdir(@pp, 'lib'), ''),
);
}
}
sub sed_inplace {
# we expect to be called like this:
# sed_inplace("filename.txt", 's/0x([0-9]*)/n=$1/g');
my ($file, $re) = @_;
if (-e $file) {
cp($file, "$file.bak") or die "###ERROR### cp: $!";
open INPF, "<", "$file.bak" or die "###ERROR### open<: $!";
open OUTF, ">", $file or die "###ERROR### open>: $!";
binmode OUTF; # we do not want Windows newlines
while (<INPF>) {
eval( "$re" );
print OUTF $_;
}
close INPF;
close OUTF;
}
}
1;
( run in 0.723 second using v1.01-cache-2.11-cpan-adec679a428 )