@@ -4,12 +4,6 @@ use PDL::Core::Dev; # Pick up development utilities
44use ExtUtils::MakeMaker;
55use 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
148my $define_bool = ' ' ;
159if ($^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+
5663WriteMakefile(%hash );
5764
5865sub 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