Skip to content

Commit

Permalink
Alien::Proj4 - fix include ordering error
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 29, 2015
1 parent 931dcc0 commit 1b6e4b1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Lib/GIS/Proj/Makefile.PL
Expand Up @@ -40,7 +40,7 @@ EOF
return;
}

my $lib_path = Alien::Proj4->libdir;
my $libflags = Alien::Proj4->libflags;
my $incflags = Alien::Proj4->incflags;

print "Building $package_name. Turn off $config_flag if there are any problems\n";
Expand All @@ -51,7 +51,7 @@ my $package = [$ppfile, 'Proj', $package_name];
my %hash = pdlpp_stdargs($package);
$hash{VERSION_FROM} = $ppfile;
#$hash{TYPEMAPS} = [&PDL_TYPEMAP()];
$hash{LIBS} = ["-L$lib_path -lproj -lm"];
$hash{LIBS} = [ $libflags ];
$hash{INC} = PDL_INCLUDE() . " $incflags";

undef &MY::postamble; # suppress warning
Expand Down
4 changes: 2 additions & 2 deletions Lib/Transform/Proj4/Makefile.PL
Expand Up @@ -38,7 +38,7 @@ EOF
return;
}

my $lib_path = Alien::Proj4->libdir;
my $libflags = Alien::Proj4->libflags;
my $incflags = Alien::Proj4->incflags;

print "Building $package_name. Turn off $config_flag if there are any problems\n";
Expand All @@ -49,7 +49,7 @@ my $package = [$ppfile, 'Proj4', $package_name];
my %hash = pdlpp_stdargs($package);
$hash{VERSION_FROM} = $ppfile;
#$hash{TYPEMAPS} = [&PDL_TYPEMAP()];
$hash{LIBS} = ["-L$lib_path -lproj -lm"];
$hash{LIBS} = [ $libflags ];
$hash{INC} = PDL_INCLUDE() . " $incflags";
$hash{realclean} = { FILES => '' } unless $hash{realclean};
$hash{realclean}{FILES} .= ' _Inline';
Expand Down
8 changes: 6 additions & 2 deletions Lib/Transform/Proj4/Proj4.pd
Expand Up @@ -375,9 +375,13 @@ push( @export_funcs, 't_proj' );

# Add in the auto-generated projection classes:
require Alien::Proj4;
require PDL::Config;
my @inc = Alien::Proj4->default_inc;
@inc = @{$PDL::Config{PROJ_INC}}
if $PDL::Config{PROJ_INC} and @{$PDL::Config{PROJ_INC}};
my $supplied = File::Spec->catdir((File::Spec->updir) x 2, qw(GIS Proj include));
$supplied = File::Spec->rel2abs($supplied); # because Inline builds elsewhere
Alien::Proj4->import(undef, [ Alien::Proj4->default_inc, $supplied ]);
push @inc, File::Spec->rel2abs($supplied); # because Inline builds elsewhere
Alien::Proj4->import($PDL::Config{PROJ_LIBS}, \@inc);

my $projections = Alien::Proj4->load_projection_information();

Expand Down
22 changes: 15 additions & 7 deletions inc/Alien/Proj4.pm
Expand Up @@ -9,8 +9,6 @@ my $transform_proj4_lib_path;
my $include_path;

my $find_libs = [ "libproj.$Config{dlext}", "libproj$Config{lib_ext}" ];
my $config_libs = 'PROJ_LIBS';
my $config_incs = 'PROJ_INC';
my @NEEDED = qw(projects.h proj_api.h);
my @DEFAULT_LIB = (
'/usr/lib64',
Expand Down Expand Up @@ -49,23 +47,33 @@ sub libdir {
my ($class) = @_;
foreach my $libdir ( @lib_locations ) {
foreach my $find_lib ( @$find_libs ) {
return $libdir if -e "$libdir/$find_lib";
next unless -e "$libdir/$find_lib";
return $libdir;
}
}
}

sub libflags {
my ($class) = @_;
my $lib_path = $class->libdir;
my $libflags = qq{"-L$lib_path" -lproj -lm};
$libflags;
}

sub incflags {
my ($class) = @_;
my %dir2true;
my %stillneeded = map { ($_=>1) } @NEEDED;
my @inc; # array because need to keep ordering
foreach my $incdir ( @inc_locations ) {
foreach my $find_inc ( keys %stillneeded ) {
next unless -e "$incdir/$find_inc";
push @inc, $incdir unless $dir2true{$incdir};
$dir2true{$incdir} = 1;
delete $stillneeded{$find_inc};
}
}
join ' ', map qq{"-I$_"}, sort keys %dir2true;
join ' ', map qq{"-I$_"}, @inc;
}

sub installed {
Expand All @@ -85,10 +93,10 @@ sub installed {
# dup of code currently in PDL::GIS::Proj
sub load_projection_descriptions {
my ($class) = @_;
my $lib_path = $class->libdir;
my $libflags = $class->libflags;
my $incflags = $class->incflags;
require Inline;
Inline->bind(C => <<'EOF', inc => $incflags, libs => "-L$lib_path -lproj -lm") unless defined &list_projections;
Inline->bind(C => <<'EOF', inc => $incflags, libs => $libflags) unless defined &list_projections;
#include "projects.h"
HV *list_projections() {
struct PJ_LIST *lp;
Expand Down Expand Up @@ -173,7 +181,7 @@ In Makefile.PL:
use Alien::Proj4 [ 'overridelibdirs' ], [ 'overrideincdirs' ];
my $proj4_installed = Alien::Proj4->installed;
my $proj4_lib = Alien::Proj4->libdir;
my $proj4_lib = Alien::Proj4->libflags;
my $proj4_inc = Alien::Proj4->incflags;
In a module like L<PDL::Transform::Proj4> that wants available proj4
Expand Down

0 comments on commit 1b6e4b1

Please sign in to comment.