Skip to content

Commit

Permalink
Use Alien::HDF4 in PDL::IO::HDF build
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 1, 2015
1 parent 255adcf commit 03a3bc3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 137 deletions.
133 changes: 11 additions & 122 deletions IO/HDF/Makefile.PL
@@ -1,9 +1,7 @@
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;

our ($hdf_include_path, $hdf_lib_path, $hdf_libs, $szip);
use ExtUtils::Depends;

my $msg = "";
my $forcebuild=0; # Note: forcebuild not used
Expand All @@ -18,123 +16,15 @@ if (defined $PDL::Config{WITH_HDF} && $PDL::Config{WITH_HDF}==1) {
$forcebuild=1;
}

# Look for HDF4 includes/libs
# default locations:
my @HDF_lib_locations = (
'/usr/lib64',
'/usr/local/netcdf/lib',
'/usr/local/lib',
'/usr/local/lib64',
'/usr/lib64/hdf',
'/opt/local/lib',
'/usr/lib',
'/usr/lib/hdf',
'/opt/lib',
split(/ /, $Config{libpth}),
);
my @HDF_inc_locations = (
'/usr/local/include',
'/usr/local/netcdf/include',
'/opt/local/include',
'/usr/include',
'/usr/include/hdf',
'/opt/include',
$Config{usrinc},
);

# get locations from perldl.conf, if specified there:
@HDF_lib_locations = @{$PDL::Config{HDF_LIBS}}
if( defined $PDL::Config{HDF_LIBS} );
@HDF_inc_locations = @{$PDL::Config{HDF_INC}}
if( defined $PDL::Config{HDF_INC} );

#
# Do the search:
#
my $found_df = 0;
my $found_sz = 0;

# Look for the libs:
foreach my $libdir ( @HDF_lib_locations ) {
if (-e "$libdir/libdfalt.a" && !$found_df) {
$found_df = 1;
$hdf_lib_path = $libdir;
$hdf_libs = '-lmfhdfalt -ldfalt';
print "Found libdfalt.a at $libdir/libdfalt.a\n";
}

if (-e "$libdir/libdf.a" && !$found_df) {
$found_df = 1;
$hdf_lib_path = $libdir;
$hdf_libs = '-lmfhdf -ldf';
print "Found libdf.a at $libdir/libdf.a\n";
}

if (-e "$libdir/libhdf.a" && !$found_df) {
$found_df = 1;
$hdf_lib_path = $libdir;
$hdf_libs = '-lmfhdf -lhdf -lxdr';
print "Found libhdf.a at $libdir/libhdf.a\n";
}

# Look for the szip library, which HDF >= 4.2r0 needs, but older versions don't!

if (-e "$libdir/libsz.$Config{so}" && !$found_sz) {
$found_sz = 1;
print "Found libsz.$Config{so} at $libdir/libsz.$Config{so}\n";
}

if (-e "$libdir/libsz$Config{lib_ext}" && !$found_sz) {
$found_sz = 1;
print "Found libsz.$Config{lib_ext} at $libdir/libsz.$Config{lib_ext}\n";
}
} # foreach $libdir...

unless( defined( $hdf_lib_path ) ) {
$msg .= "Cannot find hdf library, libdf.a.\n"
. "Please add the correct library path to Makefile.PL or install HDF\n";
}

warn "Warning: Did not find libsz, necessary for HDF >= 4.2r0\n" unless $found_sz;
$szip = $found_sz ? "-lsz" : "";

# Look for the include files:
foreach my $incdir ( @HDF_inc_locations ) {
if (-e "$incdir/hdf.h") {
$hdf_include_path = ($incdir eq '/usr/local/include' ) ? "" : $incdir;
print "Found hdf.h at $incdir/hdf.h\n";
last;
}
}

unless( defined( $hdf_include_path ) ) {
$msg .= "Cannot find hdf header file, hdf.h.\n"
. "Please add the correct library path to Makefile.PL or install HDF\n";
}

# Set up architecture dependant stuff:
# NOTE TO SELF: The main PDL developers may not like this...
my $cpu = `uname -m`;
chomp $cpu;
my $hdf_defs;
if ($cpu eq 'x86_64') {
$hdf_defs = "-DSWAP -DNDEBUG -DHDF -DBIG_LONGS -DIA64 " .
"-D_BSD_SOURCE -DLINUX -DGCC32";
} elsif ($cpu eq 'i686') {
$hdf_defs = "-DNDEBUG -D_BSD_SOURCE -DLINUX -DGCC32";
} else {
print "WARNING: Unknown cpu type $cpu! Not setting \$hdf_defs. (This may not be a bad thing)\n";
}
print "Final \$hdf_defs flags: \'$hdf_defs\'\n\n";

# Make sure everything we wanted is found:
my $donot = 1;
if( defined( $hdf_include_path ) && defined( $hdf_lib_path ) ) {
my $pkg_hdf4;
if( eval { $pkg_hdf4 = ExtUtils::Depends->new(qw(PDL Alien::HDF4)) } ) {
$donot = 0;
}

if ( $donot ) {
$msg .= "\n Skipping build of PDL::IO::HDF.\n";
$msg .= "Skipping build of PDL::IO::HDF.\n";
}

skip:
Expand All @@ -150,17 +40,16 @@ if ($msg ne "" && $forcebuild==0) {

return if $donot;

$pkg_hdf4->set_inc(&PDL_INCLUDE());
$pkg_hdf4->add_typemaps(&PDL_TYPEMAP());
$pkg_hdf4->add_pm(
'HDF.pm' => '$(INST_LIBDIR)/HDF.pm',
);

WriteMakefile(
NAME => 'PDL::IO::HDF',
DEFINE => $hdf_defs,
#OPTIMIZE => "$hdf_defs",
$pkg_hdf4->get_makefile_vars,
VERSION_FROM => 'HDF.pm',
TYPEMAPS => [ &PDL_TYPEMAP() ],
PM => {
'HDF.pm' => '$(INST_LIBDIR)/HDF.pm',
},
INC => &PDL_INCLUDE() . " -I$hdf_include_path",
LIBS => [ "-L$hdf_lib_path $hdf_libs -ljpeg -lz $szip" ],
dist => {
COMPRESS => 'gzip',
SUFFIX => 'gz',
Expand Down
14 changes: 7 additions & 7 deletions IO/HDF/SD/Makefile.PL
Expand Up @@ -4,20 +4,20 @@ use ExtUtils::MakeMaker;
use Config;

my $package = [ qw(SD.pd SD PDL::IO::HDF::SD) ];
our ($hdf_include_path, $hdf_lib_path, $hdf_libs, $szip);
my $pkg_hdf4 = ExtUtils::Depends->new(qw(PDL Alien::HDF4));
$pkg_hdf4->set_inc(&PDL_INCLUDE());
$pkg_hdf4->add_typemaps(&PDL_TYPEMAP());
$pkg_hdf4->add_pm(
'SD.pm' => '$(INST_LIBDIR)/SD.pm',
);

undef &MY::postamble; # suppress warning
*MY::postamble = sub { pdlpp_postamble_int($package); };

WriteMakefile(
NAME => 'PDL::IO::HDF::SD',
TYPEMAPS => [ &PDL_TYPEMAP() ],
OBJECT => 'SD.o ',
PM => {
'SD.pm' => '$(INST_LIBDIR)/SD.pm',
},
INC => &PDL_INCLUDE() . " -I$hdf_include_path",
LIBS => [ "-L$hdf_lib_path $hdf_libs -ljpeg -lz $szip" ],
$pkg_hdf4->get_makefile_vars,
clean => {
FILES => 'SD.pm SD.xs SD.o SD.c',
},
Expand Down
16 changes: 8 additions & 8 deletions IO/HDF/VS/Makefile.PL
Expand Up @@ -3,22 +3,22 @@ use warnings;
use ExtUtils::MakeMaker;
use Config;

our ($hdf_include_path, $hdf_lib_path, $hdf_libs, $szip);

my $package = [ qw(VS.pd VS PDL::IO::HDF::VS) ];

undef &MY::postamble; # suppress warning
*MY::postamble = sub { pdlpp_postamble_int($package); };

my $pkg_hdf4 = ExtUtils::Depends->new(qw(PDL Alien::HDF4));
$pkg_hdf4->set_inc(&PDL_INCLUDE());
$pkg_hdf4->add_typemaps(&PDL_TYPEMAP());
$pkg_hdf4->add_pm(
'VS.pm' => '$(INST_LIBDIR)/VS.pm',
);

WriteMakefile(
NAME => 'PDL::IO::HDF::VS',
TYPEMAPS => [ &PDL_TYPEMAP() ],
OBJECT => 'VS.o',
PM => {
'VS.pm' => '$(INST_LIBDIR)/VS.pm',
},
INC => &PDL_INCLUDE() . " -I$hdf_include_path",
LIBS => [ "-L$hdf_lib_path $hdf_libs -ljpeg -lz $szip" ],
$pkg_hdf4->get_makefile_vars,
clean => {
FILES => 'VS.pm VS.xs VS.o VS.c',
},
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -438,6 +438,7 @@ my %makefile_hash = (
'Devel::CheckLib' => 1.01,
'Carp' => 1.20, # EU::MM seems to need this not to crash
'ExtUtils::MakeMaker' => 6.56,
'ExtUtils::Depends' => '0.402',
},
'MIN_PERL_VERSION' => '5.010',
'NAME' => 'PDL',
Expand Down

0 comments on commit 03a3bc3

Please sign in to comment.