Skip to content

Commit 928a3b8

Browse files
authored
Merge pull request #9 from wwlwpd/issue-8
Allow use of "nc-config" as fall back if check_lib() fails
2 parents 594f883 + df928df commit 928a3b8

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

Makefile.PL

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ use PDL::Core::Dev; # Pick up development utilities
44
use ExtUtils::MakeMaker;
55
use Devel::CheckLib qw(check_lib);
66

7-
my %pathpars = find_macos_pars();
8-
check_lib(
9-
header => 'netcdf.h', lib => 'netcdf',
10-
%pathpars,
11-
) or die "Cannot find netcdf library. Please install NetCDF.";
12-
137
# Check if compiled under gcc/Linux. In which case, define bool for the compiler
148
my $define_bool = '';
159
if ($^O =~ /linux/) {
@@ -50,17 +44,22 @@ my %more_items = (
5044
);
5145
%hash = (%hash, %more_items);
5246
$hash{INC} .= " $define_bool" if $define_bool;
53-
$hash{LIBS}[0] .= " -lnetcdf";
54-
$hash{INC} .= qq{ "-I$pathpars{incpath}"} if %pathpars;
55-
$hash{LIBS}[0] .= (%pathpars ? qq{ "-L$pathpars{libpath}"} : '')." -lnetcdf";
47+
48+
if (check_lib( header => 'netcdf.h', lib => 'netcdf',)) {
49+
$hash{LIBS}[0] .= " -lnetcdf";
50+
}
51+
elsif (qx{which nc-config 2> /dev/null}) {
52+
warn "Could not find NetCDF libraries using check_lib, falling back to nc-config ...\n";
53+
my $inc = qx/nc-config --cflags/;
54+
chomp $inc;
55+
$hash{INC} .= " $inc";
56+
my $libs = qx/nc-config --libs/;
57+
$hash{LIBS}[0] .= $libs;
58+
}
59+
else {
60+
die "Cannot find NetCDF libraries, tried check_lib and looked for nc-config. Please install NetCDF.";
61+
}
62+
5663
WriteMakefile(%hash);
5764

5865
sub MY::postamble { pdlpp_postamble($package); }
59-
60-
sub find_macos_pars {
61-
return if $^O ne 'darwin';
62-
my $pref = `brew --prefix netcdf`;
63-
return if !$pref;
64-
chomp $pref;
65-
(libpath=>"$pref/lib", incpath=>"$pref/include");
66-
}

0 commit comments

Comments
 (0)