1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
## -*- Mode: CPerl -*-
##
## File: pdlmaker.plm
## Author: Bryan Jurish <moocow@cpan.org>
## Description: hacks for CPAN-friendly PDL module distribution
##
## Usage:
## + optionally set the variable $MY::README (boolean); default is
## $MY::README = grep {-e $_} (<README.txt>,<README.pod>,<README.rpod>)
## + read this file in top-level Makefile.PL:
## require "pdlmaker.plm";
## + call pdlmaker_init([$pdfile, $pmbase, $module]) as for pdlpp_stdargs()
## - will actually call pdlpp_stdargs() and return that hash if called in list context
## + call WriteMakefile() as usual
## + omit the pdlpp_postamble() call from MY::postamble()
## (you still need to 'use PDL::Core::Dev' though)
##
## Effects:
## + clobbers sub ExtUtils::MakeMaker::WriteMakefile()
## - unlinks all @pdpm files before calling "real" WriteMakefile()
## + clobbers/appends MY::depend (appends)
## x- adds @pdpm dependencies to dist,distcheck,create_distdir
## - also adds README.txt dependencies if README.txt or README.rpod is present
## + clobbers/appends MY::special_targets (appends)
## - adds (pm|pod|rpod) -> (txt|html) rules
## + clobbers/appends MY::postamble (appends)
## - adds pdlpp_postamble($package) if $package is specified
package MY;
use ExtUtils::MakeMaker qw();
use ExtUtils::Manifest qw();
use Cwd qw(cwd abs_path);
use File::Basename qw(dirname basename);
use PDL::Core::Dev;
use strict;
##----------------------------------------------------------------------
sub pdlmaker_init {
my $package = shift;
my @pdpm = $package ? "$package->[1].pm" : qw();
my $cwd = cwd();
my $label = "pdlmaker_init [DIR=$cwd]";
#print STDERR "$label\n";
##----------------------------
## read manifest @pdpm (for user info message)
my @manipm = qw();
if (-r 'MANIFEST') {
my $mani = ExtUtils::Manifest::maniread();
my ($pd,$pm);
foreach $pd (grep {/\.pd$/i} keys %$mani) {
if ($mani->{$pd}) {
($pm=$mani->{$pd}) =~ s/^[\#\s]*(?:pm=)?//;
if ($pm) {
push(@manipm,$pm);
next;
}
}
($pm=$pd)=~s/\.pd$/\.pm/i;
push(@manipm,$pm);
}
print STDERR "Info: ignore any warnings about missing $_\n" foreach (@manipm);
}
elsif (0 && $package) {
print STDERR "Info: ignore any warnings about missing $package->[1].pm\n";
;
}
##----------------------------
## $MY::README
if (!defined($MY::README)) {
$MY::README = grep {-e $_} map {glob("README.$_")} qw(txt pod rpod);
}
##----------------------------
## unlink @pdpm files here
foreach (@pdpm) {
#print STDERR "$label: UNLINK $_\n";
unlink($_) if (-e $_);
}
##----------------------------
## @missed = ExtUtils::Manifest::manicheck()
## + ignore @pdpm files in manicheck
my %manipm = (map {($_=>undef)} @manipm,@pdpm);
my $_manicheck0 = \&ExtUtils::Manifest::manicheck;
my $_manicheck1 = sub {
grep {!exists($manipm{$_})} $_manicheck0->(@_);
};
*ExtUtils::Manifest::manicheck = $_manicheck1;
##----------------------------
## depend()
## + add @pdpm, README.txt
my $depend0 = MY->can('depend') || sub {''};
my $depend = sub {
my $inherited = $depend0->(@_) . shift->SUPER::depend(@_);
my $deps = join(' ', ($MY::README ? 'README.txt' : qw()),
#sort keys %manipm
);
return $inherited if (!$deps);
return $inherited .<<EOF;
dist: $deps
distcheck: $deps
create_distdir: $deps
EOF
};
*MY::depend = $depend;
##----------------------------
## special_targets()
## + add .SUFFIXES, (pm|pod|rpod)->(txt|html)
my $special_targets0 = MY->can('special_targets') || sub {''};
my $special_targets = sub {
my $inherited = $special_targets0->(@_) . shift->SUPER::special_targets(@_);
$inherited .= <<EOF;
.SUFFIXES: .pm .pod .rpod .txt .html
.pm.html:
pod2html --outfile \$@ \$<
.pm.txt:
pod2text \$< \$@
.pod.html:
pod2html --outfile \$@ \$<
.pod.txt:
pod2text \$< \$@
.rpod.html:
pod2html --outfile \$@ \$<
.rpod.txt:
pod2text \$< \$@
EOF
foreach (sort keys %manipm) {
my ($dir,$base) = (dirname($_),basename($_));
if ($dir ne '.') {
$inherited .= "$_:\n\t\$(MAKE) -C $dir $base\n\n";
}
}
return $inherited;
};
*MY::special_targets = $special_targets;
##----------------------------
## PDL v2.058 package parameters $callpack,$multi_c
require PDL;
$package = [@$package, undef, 1]
if (@{$package||[]} == 3 && version->parse($PDL::VERSION) >= version->parse('2.058'));
##----------------------------
## postamble()
## + add pdlpp postamble if available
my $postamble0 = MY->can('postamble') || sub {''};
my $postamble = sub {
my $inherited = $postamble0->(@_) . shift->SUPER::postamble();
if (defined($package) && UNIVERSAL::can('PDL::Core::Dev','pdlpp_postamble')) {
$inherited .= PDL::Core::Dev::pdlpp_postamble($package);
}
$inherited;
};
*MY::postamble = $postamble;
##---------------------------
## returning list context? --> call pdlpp_stdargs()
if ($package && wantarray && UNIVERSAL::can('main','pdlpp_stdargs')) {
## + TODO: dodge 'redefined' warnings here for Basic/Core/Types.pm.PL symbols on 1st nested submodule (currently PDL::CCS::Utils)
## > Subroutine typesrtkeys redefined at Basic/Core/Types.pm.PL line 484.
return ::pdlpp_stdargs($package,@_);
}
}
##----------------------------------------------------------------------
package main;
*pdlmaker_init = \&MY::pdlmaker_init;
1; ##-- be happy
|