Last active
August 29, 2015 14:12
-
-
Save kmx/5d740bc6f959c014516f to your computer and use it in GitHub Desktop.
PDL - improved ExtUtils::MakeMaker support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Basic/Core/Dev.pm b/Basic/Core/Dev.pm | |
index 2e67877..5a75b50 100644 | |
--- a/Basic/Core/Dev.pm | |
+++ b/Basic/Core/Dev.pm | |
@@ -34,9 +34,22 @@ use English; require Exporter; | |
pdlpp_postamble_int pdlpp_stdargs_int | |
pdlpp_postamble pdlpp_stdargs write_dummy_make | |
unsupported getcyglib trylink | |
- pdlpp_genpm | |
+ pdlpp_genpm pdlpp_eumm | |
); | |
+my $previous_postamble; | |
+ | |
+sub import { | |
+ my $package = shift; | |
+ my ($module, $program) = caller; | |
+ if ($program =~ /Makefile\.PL$/) { | |
+ no strict 'refs'; | |
+ $previous_postamble = \&MY::postamble; | |
+ *{'MY::postamble'} = \&_postamble_handler; | |
+ } | |
+ __PACKAGE__->export_to_level(1, $package, @_); | |
+} | |
+ | |
# Installation locations | |
# beware: whereami_any now appends the /Basic or /PDL directory as appropriate | |
@@ -758,5 +771,66 @@ EOF | |
return $success; | |
} | |
+sub pdlpp_eumm { | |
+ my %args = @_; | |
+ # merge TYPEMAPS | |
+ if (ref $args{TYPEMAPS} eq 'ARRAY') { | |
+ push @{$args{TYPEMAPS}}, PDL_INST_TYPEMAP(); | |
+ } | |
+ # merge INC | |
+ $args{INC} = defined $args{INC} ? "$args{INC} " : ""; | |
+ $args{INC} .= PDL_INST_INCLUDE() . " $inc"; | |
+ # merge LIBS | |
+ if ($libs) { | |
+ if (ref $args{LIBS} eq 'ARRAY') { | |
+ $_ .= " $libs " for (@{$args{LIBS}}); | |
+ } | |
+ elsif (defined $args{LIBS}) { | |
+ $args{LIBS} .= " $libs "; | |
+ } | |
+ } | |
+ # merge dist => PREOP | |
+ if ($args{dist}{PREOP}) { | |
+ $args{dist}{PREOP} = '$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -MPDL::Core::Dev -e pdlpp_genpm $(DISTVNAME) && ' . $args{dist}{PREOP}; | |
+ } | |
+ else { | |
+ $args{dist}{PREOP} = '$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -MPDL::Core::Dev -e pdlpp_genpm $(DISTVNAME)'; | |
+ } | |
+ # put PDL into PREREQ - pdlpp_eumm was introduced in PDL-2.009 | |
+ $args{CONFIGURE_REQUIRES}{PDL} = 2.009 unless defined $args{CONFIGURE_REQUIRES}{PDL}; | |
+ $args{BUILD_REQUIRES}{PDL} = 2.009 unless defined $args{BUILD_REQUIRES}{PDL}; | |
+ $args{PREREQ_PM}{PDL} = 2.009 unless defined $args{PREREQ_PM}{PDL}; | |
+ # process PDL_PD | |
+ my $H = delete $args{PDL_PD}; | |
+ if (ref $H eq 'HASH') { | |
+ my @objs = (); | |
+ my @clean = (); | |
+ my @post = (); | |
+ while (my ($pd, $mod) = each %$H) { | |
+ die "pdlpp_eumm: non-existing pd file '$pd'\n" unless -f $pd; | |
+ (my $pref = $pd) =~ s/\.pd$//; | |
+ push @objs, "$pref\$(OBJ_EXT)"; | |
+ push @clean, ("$pref.xs", "$pref.pm", "$pref\$(OBJ_EXT)", "$pref.c"); | |
+ push @post, [$pd, $pref, $mod]; | |
+ (my $mpref = $mod) =~ s/::/\//g; | |
+ $args{PM}{"$pref.pm"} = "\$(INST_LIB)/$mpref.pm"; | |
+ $args{MAN3PODS}{"$pref.pm"} = "\$(INST_MAN3DIR)/$mod.\$(MAN3EXT)"; | |
+ } | |
+ $args{clean}{FILES} .= " " . join(" ", @clean) if @clean; | |
+ $args{OBJECT} .= " " . join(" ", @objs) if @objs; | |
+ $args{postamble}{pdlpp_eumm} = \@post if @post; | |
+ } | |
+ return %args; | |
+} | |
+ | |
+sub _postamble_handler { | |
+ my ($mm, %args) = @_; | |
+ my $rv = eval { $previous_postamble->() } || ''; | |
+ if (ref $args{pdlpp_eumm} eq 'ARRAY') { | |
+ $rv .= "\n" . pdlpp_postamble(@{$args{pdl_eumm}}); | |
+ } | |
+ return $rv; | |
+} | |
+ | |
1; # Return OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment