my %probe =
(
name => "PNG",
+ altname => "Generic",
pkg => [ qw/libpng14 libpng12 libpng10 libpng/ ],
inccheck => sub { -e File::Spec->catfile($_[0], "png.h") },
libbase => "png",
testcodeheaders => [ "png.h", "stdio.h" ],
incpath => join($Config{path_sep}, @incpaths),
libpath => join($Config{path_sep}, @libpaths),
+ alternatives =>
+ [
+ {
+ altname => "v1.4",
+ incsuffix => "libpng14",
+ libbase => "png14",
+ },
+ {
+ altname => "v1.2",
+ incsuffix => "libpng12",
+ libbase => "png12",
+ },
+ {
+ altname => "v1.0",
+ incsuffix => "libpng10",
+ libbase => "png10",
+ },
+ ],
);
my $probe_res = Imager::Probe->probe(\%probe);
use File::Spec;
use Config;
+my @alt_transfer = qw/altname incsuffix libbase/;
+
sub probe {
my ($class, $req) = @_;
$result = _probe_pkg($req);
}
if (!$result && $req->{inccheck} && ($req->{libcheck} || $req->{libbase})) {
+ $req->{altname} ||= "main";
$result = _probe_check($req);
}
+ if (!$result && $req->{alternatives}) {
+ ALTCHECK:
+ my $index = 1;
+ for my $alt (@{$req->{alternatives}}) {
+ $req->{altname} ||= "alt $index";
+ $req->{verbose}
+ and print "$req->{name}: Trying alternative $index\n";
+ my %work = %$req;
+ for my $key (@alt_transfer) {
+ exists $alt->{$key} and $work{$key} = $alt->{$key};
+ }
+ $result = _probe_check(\%work)
+ and last;
+ ++$index;
+ }
+ }
if (!$result && $req->{testcode}) {
$result = _probe_fake($req);
}
}
- print "$req->{name}: includes ", $found_incpath ? "" : "not ",
+ my $alt = "";
+ if ($req->{alternatives}) {
+ $alt = " $req->{altname}:";
+ }
+ print "$req->{name}:$alt includes ", $found_incpath ? "" : "not ",
"found - libraries ", $found_libpath ? "" : "not ", "found\n";
$found_libpath && $found_incpath
sub _inc_paths {
my ($req) = @_;
- return _paths
+ my @paths = _paths
(
$ENV{IM_INCPATH},
$req->{incpath},
"/usr/include",
"/usr/local/include",
);
+
+ if ($req->{incsuffix}) {
+ @paths = map File::Spec->catdir($_, $req->{incsuffix}), @paths;
+ }
+
+ return @paths;
}
sub _paths {