Skip to content

Commit

Permalink
PDL::Bad switch to new lib/*.pd scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 17, 2024
1 parent fb7042b commit c22dd93
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ nytprof*
_Inline/
t/*.dll*
pp-*.c
*-pp-*.c
3 changes: 3 additions & 0 deletions Basic/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
lib/PDL/Bad.c
lib/PDL/Bad.pm
lib/PDL/Bad.xs
lib/PDL/Core.c
lib/PDL/Core/pdl.h
script/pdl
3 changes: 0 additions & 3 deletions Basic/Bad/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions Basic/Bad/Makefile.PL

This file was deleted.

7 changes: 5 additions & 2 deletions Basic/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ my @exe_files = map catfile('script', $_), qw(perldl pdldoc pptemplate);
push @exe_files, "$pdlroot$Config{exe_ext}" if $^O !~ /MSWin/;
my @cleanup = ("$pdlroot$Config{exe_ext}");

my @pd_srcs;
undef &MY::postamble; # suppress warning
*MY::postamble = sub {
my ($self) = @_;
Expand All @@ -36,6 +37,7 @@ coretest : core
update-ppport:
\$(PERLRUN) -MDevel::PPPort -e'Devel::PPPort::WriteFile' && \$(PERLRUN) lib/PDL/Core/ppport.h --strip
EOF
$text .= pdlpp_postamble_int(@pd_srcs);
$text;
};

Expand All @@ -62,8 +64,8 @@ my $cobj = join ' ', map catfile(qw(lib PDL Core), qq{$_\$(OBJ_EXT)}), @cfiles;
push @cleanup, $cobj;
my $core_obj = catfile(qw(lib PDL), 'Core$(OBJ_EXT)');

my @BUILD_MODULES = qw(Core);
my @DIRS_CORE = qw(Bad Ops Ufunc Primitive Slices Math MatrixOps);
my @BUILD_MODULES = qw(Bad Core);
my @DIRS_CORE = qw(Ops Ufunc Primitive Slices Math MatrixOps);
# the modules needed in "use PDL"
my @DIRS_BASIC = qw(IO-Misc IO-Pnm Lib-Compression Lib-FFT Lib-ImageND Lib-ImageRGB);
WriteMakefile(
Expand Down Expand Up @@ -115,6 +117,7 @@ sub init_PM {
for my $f (grep /\.PL$/, keys %$pm) {
$pm->{ $plf->{$f} = _nopl($f) } = _nopl(delete $pm->{$f});
}
@pd_srcs = ::pdlpp_eumm_update_deep($self);
delete @$pm{grep /\.c$/, keys %$pm};
}
}
Expand Down
File renamed without changes.
43 changes: 37 additions & 6 deletions Basic/lib/PDL/Core/Dev.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ our @EXPORT = qw( isbigendian
PDL_INCLUDE PDL_TYPEMAP
PDL_AUTO_INCLUDE PDL_BOOT
PDL_INST_INCLUDE PDL_INST_TYPEMAP
pdlpp_eumm_update_deep
pdlpp_postamble_int pdlpp_stdargs_int
pdlpp_postamble pdlpp_stdargs write_dummy_make
unsupported getcyglib trylink
pdlpp_mkgen pdlpp_list_functions pdlpp_mod_vars pdlpp_mod_values
pdlpp_mkgen
got_complex_version
);

Expand Down Expand Up @@ -136,7 +137,7 @@ sub _pp_call_arg {
"-MPDL::PP=".join ',', @_
}
sub _postamble {
my ($w, $internal, $src, $base, $mod, $callpack, $multi_c) = @_;
my ($w, $internal, $src, $base, $mod, $callpack, $multi_c, $deep) = @_;
$callpack //= '';
$w = dirname($w);
my $perlrun = "\$(PERLRUN) \"-I$w\"";
Expand All @@ -153,7 +154,7 @@ sub _postamble {
my $oneliner = _oneliner(qq{exit if \$ENV{DESTDIR}; use PDL::Doc; eval { PDL::Doc::add_module(q{$mod}); }});
$install = qq|\ninstall ::\n\t\@echo "Updating PDL documentation database...";\n\t$oneliner\n|;
}
my $pp_call_arg = _pp_call_arg($mod, $mod, $base, $callpack, $multi_c||'');
my $pp_call_arg = _pp_call_arg($mod, $mod, $base, $callpack, $multi_c||'',$deep||'');
qq|
$base.pm : $pmdep
Expand All @@ -169,7 +170,7 @@ $install|

sub pdlpp_postamble_int {
my $w = whereami_any();
join '', map _postamble($w, 1, @$_[0..3], 1), @_;
join '', map _postamble($w, 1, @$_[0..3], 1, @$_[4..$#$_]), @_;
}

# This is the function to be used outside the PDL tree.
Expand All @@ -179,6 +180,35 @@ sub pdlpp_postamble {
join '', map _postamble($w, 0, @$_), @_;
}

sub pdlpp_eumm_update_deep {
my ($eumm) = @_;
my $pm = $eumm->{PM};
my $macro = $eumm->{macro} ||= {};
my $xsb = $eumm->{XSBUILD}{xs} ||= {};
$eumm->{clean}{FILES} ||= '';
my $xs = $eumm->{XS} ||= {};
my $global_version = $eumm->parse_version($eumm->{VERSION_FROM});
my @pd_srcs;
for my $f (grep /\.pd$/, keys %$pm) {
delete $pm->{$f};
my $nolib = (my $base = $f =~ s/\.pd$//r) =~ s#^lib/##r;
$xs->{ "$base.xs" } = "$base.c";
my $pmfile = "$base.pm";
$pm->{$pmfile} = "\$(INST_LIB)/$nolib.pm";
my @macro_vars = pdlpp_mod_vars(my $mod = join '::', split /\//, $nolib);
@$macro{@macro_vars} = pdlpp_mod_values(1, $f, $base, 1, 1);
$xsb->{$base}{OBJECT} = "\$($macro_vars[1])";
my $mtime = (stat $f)[9] // die "$f: $!";
open my $fh, ">", $pmfile or die "$pmfile: $!"; # XSMULTI needs this
print $fh "package $mod;\nour \$VER"."SION = '$global_version';\n1;\n"; # break is so cpanm doesn't try to parse as version
close $fh;
utime $mtime - 120, $mtime - 120, $pmfile; # so is out of date
push @pd_srcs, [$f, $base, $mod, '', 1];
$eumm->{clean}{FILES} .= join ' ', '', $pmfile, map "\$($_)", @macro_vars;
}
@pd_srcs;
}

sub pdlpp_list_functions {
my ($src, $internal) = @_;
my $abs_src = File::Spec::Functions::rel2abs($src);
Expand All @@ -202,9 +232,10 @@ sub pdlpp_mod_vars {
map "PDL_MULTIC_${mangled}_$_", qw(C O);
}
sub pdlpp_mod_values {
my ($internal, $src, $base, $multi_c) = @_;
my ($internal, $src, $base, $multi_c, $deep) = @_;
return ("$base.xs", "$base\$(OBJ_EXT)") if !$multi_c;
my @cbase = map "pp-$_", pdlpp_list_functions($src, $internal);
my $cfileprefix = $deep ? "$base-" : '';
my @cbase = map $cfileprefix."pp-$_", pdlpp_list_functions($src, $internal);
(join(' ', "$base.xs", map "$_.c", @cbase),
join(' ', map "$_\$(OBJ_EXT)", $base, @cbase));
}
Expand Down
6 changes: 3 additions & 3 deletions Basic/lib/PDL/PP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,14 @@ use Carp;
sub nopm { $::PDLPACK eq 'NONE' } # flag that we don't want to generate a PM

sub import {
my ($mod,$modname, $packname, $base, $callpack, $multi_c) = @_;
my ($mod,$modname, $packname, $base, $callpack, $multi_c, $deep) = @_;
# Allow for users to not specify the packname
($packname, $base, $callpack) = ($modname, $packname, $base)
if ($packname =~ m|/|);

$::PDLMOD=$modname; $::PDLPACK=$packname; $::PDLBASE=$base;
$::CALLPACK = $callpack || $::PDLMOD;
$::PDLMULTI_C = $multi_c; # one pp-*.c per function
$::PDLMULTI_C_PREFIX = $deep ? "$base-" : "";
$::PDLOBJ = "PDL"; # define pp-funcs in this package
$::PDLXS="";
$::PDLBEGIN="";
Expand Down Expand Up @@ -841,7 +841,7 @@ sub pp_def {
)});
if ($::PDLMULTI_C) {
PDL::PP->printxsc(undef, "$obj{RunFuncHdr};\n");
PDL::PP->printxsc("pp-$obj{Name}.c", $ctext);
PDL::PP->printxsc($::PDLMULTI_C_PREFIX."pp-$obj{Name}.c", $ctext);
} else {
PDL::PP->printxsc(undef, $ctext);
}
Expand Down
3 changes: 1 addition & 2 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Basic/Bad/bad.pd
Basic/Bad/Makefile.PL
Basic/examples/Benchmark/Bench.pm
Basic/examples/Benchmark/Bench.xs
Basic/examples/Benchmark/Makefile.PL
Expand Down Expand Up @@ -59,6 +57,7 @@ Basic/lib/Inline/Pdlpp.pm
Basic/lib/PDL.pm
Basic/lib/PDL/API.pod
Basic/lib/PDL/AutoLoader.pm
Basic/lib/PDL/Bad.pd
Basic/lib/PDL/BadValues.pod
Basic/lib/PDL/Basic.pm
Basic/lib/PDL/Broadcasting.pod
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.SKIP
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RCS
\.tar\.gz$
/core$
\b_eumm/
^Basic/Bad/Bad\..*
^Basic/lib/PDL/Bad(\.(pm|xs|c)$|-pp-)
^Basic/lib/PDL/Core\.c$
^Basic/lib/PDL/Core/pdl\.h$
^Basic/IO-Misc/Misc\..*
Expand Down

0 comments on commit c22dd93

Please sign in to comment.