DNS-Unbound
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
use File::Temp;
use File::Spec;
use JSON::PP;
my $ccpath = $ENV{'CC'} || $Config::Config{'cc'};
print "Your C compiler appears to be: $ccpath\n";
if ( eval { require ExtUtils::PkgConfig } ) {
print "Oh good! You have ExtUtils::PkgConfig. :)\n";
# These can fail because older libunbound versions (e.g., 1.4.22)
# didnât include a pkg-config file.
$cflags = ExtUtils::PkgConfig->cflags($pkgconfig_name);
$ldflags = ExtUtils::PkgConfig->libs($pkgconfig_name);
$libdir = ExtUtils::PkgConfig->libs_only_L($pkgconfig_name);
}
else {
print "Hmm. You donât seem to have ExtUtils::PkgConfig.\n";
print "Iâll try running `pkg-config` directly â¦\n";
my $cmd = "pkg-config --cflags $pkgconfig_name";
$cflags = `$cmd`;
if ($?) {
warn "`$cmd` failed (CHILD_ERROR=$?)\n";
}
else {
print "Cool. It looks like pkg-config works.\n";
$ldflags = `pkg-config --libs $pkgconfig_name`;
$libdir = `pkg-config --libs-only-L $pkgconfig_name`;
}
$_ && chomp for $cflags, $ldflags, $libdir;
}
$libdir =~ s<\A-L><>;
# In case pkg-config didnât give us anything.
if (!$ldflags) {
warn "I didnât find libunbound via pkg-config. :(\n";
warn "Now Iâll look for libunbound via ExtUtils::Liblist â¦\n";
my ($xtralibs, $bsloadlibs, $ldloadlibs, $ld_run_path, $where_ar) = ExtUtils::Liblist->ext('-lunbound', 0, 1);
if (@$where_ar) {
print "Libunbound found at: @$where_ar\n";
my @pieces = File::Spec->splitdir($where_ar->[0]);
pop @pieces;
$libdir = File::Spec->catdir(@pieces);
$ldflags = "-L$libdir -lunbound";
if (!$cflags) {
print "Looking for unbound.h â¦$/";
require Config;
my @incdirs = (
$Config::Config{'usrinc'},
map { split m<\s+> } (
$Config::Config{'incpth'},
$Config::Config{'locincpth'},
),
);
while (@pieces > 1) {
pop @pieces;
push @incdirs, File::Spec->catdir(@pieces, "include"),
}
my %checked;
for my $dir (@incdirs) {
next if !$dir;
next if $checked{$dir};
$checked{$dir}++;
print "Checking $dir â¦$/";
if (-s File::Spec->catdir($dir, 'unbound.h')) {
print "Found it!$/";
$cflags = "-I$dir";
last;
}
else {
print "⦠nope. :($/";
}
}
if (!$cflags) {
print "I didnât find unbound.h, but maybe your compiler can?$/";
}
}
}
else {
# Useful for Travis CI. Not sure if itâs relevant in production â¦
warn "That didnât work, either. This doesnât look good. :-/\n";
warn "As a last resort, letâs just try compiling with libunbound â¦\n";
my ($tfh, $tpath) = File::Temp::tempfile( CLEANUP => 1 );
print {$tfh} "#include <unbound.h>\nint main() { return 0; }\n";
close $tfh;
my $cmd = "$ccpath $cflags -xc -lunbound $tpath";
print "Trying: `$cmd`\n";
my $out = `$cmd`;
if ($?) {
die "$ccpath failed to use libunbound (CHILD_ERROR=$?): $out";
}
else {
print "Huh, weird ⦠the compiler can use and link libunbound.\n";
print "Maybe thereâs a bug in ExtUtils::Liblist?\n";
print "Anyway, letâs get on with our business â¦\n";
}
}
( run in 1.301 second using v1.01-cache-2.11-cpan-71847e10f99 )