From 48725c521ee23f6eb6db23860304faf0a10821fd Mon Sep 17 00:00:00 2001
From: Slaven Rezic <cpansand@prod4>
Date: Mon, 17 Apr 2017 09:49:25 +0000
Subject: [PATCH] use pkg-config instead of curl-config if available (RT
 #120736)

---
 Makefile.PL | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index f9170bb..415d09f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -10,10 +10,15 @@ license			'mit';
 perl_version		'5.006001';
 no_index		directory => 'template';
 repository		'http://github.com/szbalint/WWW--Curl';
+
+my $curl_config;
 # This is a hack. If you have libcurl installed, just specify curl.h below
 # and comment out this line.
 if ($^O ne 'MSWin32') {
-    if (!$ENV{CURL_CONFIG}) {
+    system 'pkg-config', 'libcurl', '--exists';
+    if ($? == 0) {
+	    $curl_config = 'pkg-config libcurl';
+    } elsif (!$ENV{CURL_CONFIG}) {
 	    requires_external_bin	'curl-config';
     }
 } else {
@@ -22,16 +27,28 @@ if ($^O ne 'MSWin32') {
 	exit(0);
 }
 
-my $curl_config = $ENV{CURL_CONFIG} || 'curl-config';
+if (!defined $curl_config) {
+	$curl_config = $ENV{CURL_CONFIG} || 'curl-config';
+}
 
-my $vernum = `${curl_config} --vernum`; chomp $vernum;
-my $version = `${curl_config} --version`; chomp $version; 
+my $minimum_ver = '7.10.8';
+my($vernum, $version, $version_too_low);
+if ($curl_config =~ m{pkg-config}) {
+	# no support for vernum
+	$version = `$curl_config --modversion`; chomp $version;
+	system 'pkg-config', 'libcurl', '--atleast-version', $minimum_ver;
+	$version_too_low = 1 if $? != 0;
+} else {
+	my $minimum_ver = hex(join '', map { sprintf "%02x", $_ } split /\./, $minimum_ver);
+	$vernum = `${curl_config} --vernum`; chomp $vernum;
+	$version = `${curl_config} --version`; chomp $version; 
+	$version_too_low = 1 if $vernum && hex($vernum) <= $minimum_ver;
+}
 
-my $minimum_ver = hex("070a08");
 
-if ($vernum && hex($vernum) <= $minimum_ver) {
+if ($version_too_low) {
 	print	"Your currently installed libcurl version - $version - is too old.\n".
-		"This module doesn't seek compatibility with versions older than 7.10.8\n".
+		"This module doesn't seek compatibility with versions older than $minimum_ver\n".
 		"Proceed manually if you know what you're doing.\n";
 	exit(0);
 }
-- 
2.1.2