From 1b6e4b145dfd738f2a1c7a1b4fe7e87f6ffa7b70 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sun, 29 Mar 2015 02:53:25 +0100 Subject: [PATCH] Alien::Proj4 - fix include ordering error --- Lib/GIS/Proj/Makefile.PL | 4 ++-- Lib/Transform/Proj4/Makefile.PL | 4 ++-- Lib/Transform/Proj4/Proj4.pd | 8 ++++++-- inc/Alien/Proj4.pm | 22 +++++++++++++++------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Lib/GIS/Proj/Makefile.PL b/Lib/GIS/Proj/Makefile.PL index 075a9c44f..1a6822723 100644 --- a/Lib/GIS/Proj/Makefile.PL +++ b/Lib/GIS/Proj/Makefile.PL @@ -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"; @@ -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 diff --git a/Lib/Transform/Proj4/Makefile.PL b/Lib/Transform/Proj4/Makefile.PL index 3d6291781..5bfc218ac 100644 --- a/Lib/Transform/Proj4/Makefile.PL +++ b/Lib/Transform/Proj4/Makefile.PL @@ -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"; @@ -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'; diff --git a/Lib/Transform/Proj4/Proj4.pd b/Lib/Transform/Proj4/Proj4.pd index d93699ff4..bd3212fd1 100644 --- a/Lib/Transform/Proj4/Proj4.pd +++ b/Lib/Transform/Proj4/Proj4.pd @@ -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(); diff --git a/inc/Alien/Proj4.pm b/inc/Alien/Proj4.pm index c16a7d674..596deded0 100644 --- a/inc/Alien/Proj4.pm +++ b/inc/Alien/Proj4.pm @@ -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', @@ -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 { @@ -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; @@ -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 that wants available proj4