Skip to content

Commit

Permalink
Release v0.01
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 1, 2015
0 parents commit d040cdc
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MANIFEST
@@ -0,0 +1,7 @@
MANIFEST This list of files
Makefile.PL
common.pl
lib/Alien/HDF4.pm.PL
lib/Alien/HDF4/Install/Files.pm.PL
t/compile.t
t/inline.t
65 changes: 65 additions & 0 deletions Makefile.PL
@@ -0,0 +1,65 @@
#!perl -w
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;
require 'common.pl';
require 5.010;

my ($libpath, $libs) = findlibs();
die <<EOF unless defined $libpath;
Cannot find hdf library, libdf.a.
Please add the correct library path to Makefile.PL or install HDF
EOF

my ($incpath) = findinc();
die <<EOF unless defined $incpath;
Cannot find hdf header file, hdf.h.
Please add the correct library path to Makefile.PL or install HDF
EOF

my $defs = finddefs();
print <<EOF unless length $defs;
WARNING: Unknown cpu type $Config{archname}! Not setting \$hdf_defs.
(This may not be a bad thing)
EOF
print "Final \$hdf_defs flags: '$defs'\n";

my ($szlibs) = findsz();
print "Warning: Did not find libsz, necessary for HDF >= 4.2r0\n"
unless $szlibs;

my $version = get_version();

my @pms = qw(Alien/HDF4.pm Alien/HDF4/Install/Files.pm);
WriteMakefile(
NAME => 'Alien::HDF4',
VERSION => $version,
MIN_PERL_VERSION => '5.010',
BUILD_REQUIRES => {
'IO::All' => 0,
'ExtUtils::Depends' => '0.402',
},
TEST_REQUIRES => {
'Test::More' => '0.88',
},
PL_FILES => { map { ("lib/$_.PL" => "lib/$_") } @pms },
PM => { map { ("lib/$_" => "\$(INST_ARCHLIB)/$_") } @pms },
clean => { FILES => join ' ', map "lib/$_", @pms },
META_MERGE => {
"meta-spec" => { version => 2 },
provides => {
'Alien::HDF4' => {
file => 'lib/Alien/HDF4.pm.PL',
version => $version,
},
},
resources => {
repository => {
type => 'git',
url => 'git://github.com/PDLPorters/Alien-HDF4',
web => 'https://github.com/PDLPorters/Alien-HDF4',
},
},
},
);
93 changes: 93 additions & 0 deletions common.pl
@@ -0,0 +1,93 @@
use strict;
use warnings;
use Config;
use IO::All;

my $version = '0.01';

# 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},
);

sub get_version { $version }

# returns ($libpath, $libs)
sub findlibs {
foreach my $libdir ( @HDF_lib_locations ) {
return (
$libdir, '-lmfhdfalt -ldfalt',
) if -e "$libdir/libdfalt.a";
return (
$libdir, '-lmfhdf -ldf',
) if -e "$libdir/libdf.a";
return (
$libdir, '-lmfhdf -lhdf -lxdr',
) if -e "$libdir/libhdf.a";
}
return;
}

# Look for the szip library, which HDF >= 4.2r0 needs, but older versions don't
# returns $szlibs, or '' if not
sub findsz {
foreach my $libdir ( @HDF_lib_locations ) {
return ("-lsz")
if -e "$libdir/libsz.$Config{so}";
return ("-lsz")
if -e "$libdir/libsz$Config{lib_ext}";
}
return '';
}

# Look for the include files
# return ($incpath)
sub findinc {
foreach my $incdir ( @HDF_inc_locations ) {
return ($incdir) if -e "$incdir/hdf.h";
}
return;
}

# ($defs)
sub finddefs {
if ($Config{archname} =~ /x86_64/) {
return "-DSWAP -DNDEBUG -DHDF -DBIG_LONGS -DIA64 " .
"-D_BSD_SOURCE -DLINUX -DGCC32";
} elsif ($Config{archname} =~ /i686/) {
return "-DNDEBUG -D_BSD_SOURCE -DLINUX -DGCC32";
}
return ''; # not a failure
}

sub get_build {
my ($libpath, $libs) = findlibs();
my ($incpath) = findinc();
my $defs = finddefs();
my ($szlibs) = findsz();
{
cflags => qq{$defs "-I$incpath"},
libs => qq{"-L$libpath" $libs -ljpeg -lz $szlibs},
}
}

1;
56 changes: 56 additions & 0 deletions lib/Alien/HDF4.pm.PL
@@ -0,0 +1,56 @@
#!perl -w

use strict;
use warnings;
use Data::Dumper;
require 'common.pl';

my $version = get_version();
my $config_hash = get_build();

my $cfg = join '', <DATA>;
$cfg =~ s/#VERSION#/$version/;
my $out = shift;
io($out)->print($cfg) or die "$out: $!\n";

__DATA__
package Alien::HDF4;
use strict;
use warnings;
our $VERSION = '#VERSION#';
sub Inline {
require Alien::HDF4::Install::Files;
goto &Alien::HDF4::Install::Files::Inline;
}
1;
__END__
=head1 NAME
Alien::HDF4 - Encapsulate install info for HDF4
=head1 SYNOPSIS
# PDL/Makefile.PL
use ExtUtils::Depends;
my $pkg = ExtUtils::Depends->new(qw(PDL Alien::HDF4)); # HDF4 config info
use Inline with => 'Alien::HDF4';
=head1 DESCRIPTION
Use in your F<Makefile.PL> as above. Produces config info usable via
L<ExtUtils::Depends>.
=head1 AUTHOR
Ed J
=head1 SEE ALSO
L<ExtUtils::Depends>.
14 changes: 14 additions & 0 deletions lib/Alien/HDF4/Install/Files.pm.PL
@@ -0,0 +1,14 @@
#!perl -w

use strict;
use warnings;
use ExtUtils::Depends;

require 'common.pl';
my $build_hash = get_build();

my $pkg = ExtUtils::Depends->new('Alien::HDF4');
my $eud_files = shift;
$pkg->set_inc($build_hash->{cflags});
$pkg->set_libs($build_hash->{libs});
$pkg->save_config($eud_files);
7 changes: 7 additions & 0 deletions t/compile.t
@@ -0,0 +1,7 @@
use strict;
use warnings;
use Test::More;

use_ok 'Alien::HDF4';

done_testing;
9 changes: 9 additions & 0 deletions t/inline.t
@@ -0,0 +1,9 @@
use strict;
use warnings;
use Test::More;

use_ok 'Alien::HDF4';
ok eval { Alien::HDF4->Inline('C') }, 'Inline method returns true';
is $@, '', 'no exception';

done_testing;

0 comments on commit d040cdc

Please sign in to comment.