Description: use pkg-config (via ExtUtils::PkgConfig) instead of the removed gdlib-config.
 Additionally remove parts from try_to_autoconfigure which are not needed, at least on Debian,
 and adjust some variable to the different output of pkg-config.
 pkg-config doesn't return "features", so we're hardcoding it for now, taken from gdlib-config
 as of src:libgd2 2.2.3-1.1 (rebuilt with gdlib-config re-enabled).
 .
 This patch might need more massaging before upstreaming it wrt non-Debian systems,
 and inclusion of ExtUtils::PkgConfig into the distributions metadata.
Origin: vendor
Bug: https://rt.cpan.org/Ticket/Display.html?id=114788
Bug-Debian: https://bugs.debian.org/825629
Forwarded: no
Author: gregor herrmann <gregoa@debian.org>
Last-Update: 2016-09-25

--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,6 +1,7 @@
 use ExtUtils::MakeMaker qw(prompt WriteMakefile);
 use Config;
 use strict;
+use ExtUtils::PkgConfig;
 
 # if this is a dev version the version number can be a string with underscores
 # remove them to prevent a warning and that's what perl will do it it was
@@ -273,27 +274,23 @@
 
 sub try_to_autoconfigure {
   my ($options,$lib_gd_path,$INC,$LIBPATH,$LIBS) = @_;
-  my $config = `gdlib-config --all`;
-  return unless $config;
+  my %config = ExtUtils::PkgConfig->find ('gdlib');
+  return unless %config;
   $AUTOCONFIG++;
 
-  my ($version) = $config =~ /^GD library\s+(\S+)/m;
+  my ($version) = $config{modversion};
   warn "Configuring for libgd version $version.\n";
 
-  my ($cflags)     = $config =~ /^cflags:\s+(.+)/m;
-  my ($ldflags)    = $config =~ /^ldflags:\s+(.+)/m;
-  my ($libs)       = $config =~ /^libs:\s+(.+)/m;
-  my ($libdir)     = $config =~ /^libdir:\s+(.+)/m;
-  my ($features)   = $config =~ /^features:\s+(.+)/m;
-  my ($includedir) = $config =~ /^includedir:\s+(.+)/m;
+  my ($cflags)     = $config{cflags};
+  my ($libs)       = $config{libs};
+  my ($libdir)     = ExtUtils::PkgConfig->variable('gdlib', 'libdir');
+  my ($features)   = 'GD_GIF GD_GIFANIM GD_OPENPOLYGON GD_ZLIB GD_PNG GD_FREETYPE GD_FONTCONFIG GD_JPEG GD_XPM GD_TIFF GD_WEBP';
 
   @$INC          = map {s/^-I// && "-I$_"} split /\s+/,$cflags;
-  @$LIBPATH      = map {s/^-L// && "-L$_"} split /\s+/,$ldflags;
   @$LIBS         = split /\s+/,$libs;
 
-  push @$LIBS,"-lgd";
   push @$LIBPATH,"-L$libdir";
-  ($$lib_gd_path = $libdir) =~ s!/[^/]+$!!;
+  $$lib_gd_path  = $libdir;
   $$options      = $features;
 
   my ($minor, $patch)    = $version =~ /^2\.(\d+)\.(\d+)$/;
@@ -301,8 +298,6 @@
     $$options     .= " GD_UNCLOSEDPOLY GD_ANIMGIF GD_FTCIRCLE VERSION_33";
   }
 
-  my @correct_inc = map {s/^-I// && $_} split /\s+/,$cflags;
-  check_for_stray_headers($includedir,@correct_inc);
   return 1;
 }