search more places for PNG headers and libraries
authorTony Cook <tony@develop=help.com>
Mon, 6 Sep 2010 10:15:06 +0000 (10:15 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 6 Sep 2010 10:15:06 +0000 (10:15 +0000)
PNG/Makefile.PL
lib/Imager/Probe.pm

index c79d31799cbd2195223fe5d83ac7f54c0c8532e4..c7924ddb0b022699deb94c3f86b02db8b5c17f8c 100644 (file)
@@ -72,6 +72,7 @@ require Imager::Probe;
 my %probe =
   (
    name => "PNG",
+   altname => "Generic",
    pkg => [ qw/libpng14 libpng12 libpng10 libpng/ ],
    inccheck => sub { -e File::Spec->catfile($_[0], "png.h") },
    libbase => "png",
@@ -79,6 +80,24 @@ my %probe =
    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);
index 8e0c3274f53d9ab9ec663928dd80ecc076d2738d..b133e19ce99b620326f43f7c1d9b5df9971ab0c4 100644 (file)
@@ -3,6 +3,8 @@ use strict;
 use File::Spec;
 use Config;
 
+my @alt_transfer = qw/altname incsuffix libbase/;
+
 sub probe {
   my ($class, $req) = @_;
 
@@ -17,8 +19,25 @@ sub probe {
     $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);
@@ -149,7 +168,11 @@ sub _probe_check {
     }
   }
 
-  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
@@ -255,7 +278,7 @@ sub _lib_paths {
 sub _inc_paths {
   my ($req) = @_;
 
-  return _paths
+  my @paths = _paths
     (
      $ENV{IM_INCPATH},
      $req->{incpath},
@@ -269,6 +292,12 @@ sub _inc_paths {
      "/usr/include",
      "/usr/local/include",
     );
+
+  if ($req->{incsuffix}) {
+    @paths = map File::Spec->catdir($_, $req->{incsuffix}), @paths;
+  }
+
+  return @paths;
 }
 
 sub _paths {