From c22dd93990240d5bc9077da81137f9e5d6757f14 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sun, 17 Nov 2024 04:37:57 +0000 Subject: [PATCH] PDL::Bad switch to new lib/*.pd scheme --- .gitignore | 1 + Basic/.gitignore | 3 ++ Basic/Bad/.gitignore | 3 -- Basic/Bad/Makefile.PL | 15 ---------- Basic/Makefile.PL | 7 +++-- Basic/{Bad/bad.pd => lib/PDL/Bad.pd} | 0 Basic/lib/PDL/Core/Dev.pm | 43 ++++++++++++++++++++++++---- Basic/lib/PDL/PP.pm | 6 ++-- MANIFEST | 3 +- MANIFEST.SKIP | 2 +- 10 files changed, 51 insertions(+), 32 deletions(-) delete mode 100644 Basic/Bad/.gitignore delete mode 100644 Basic/Bad/Makefile.PL rename Basic/{Bad/bad.pd => lib/PDL/Bad.pd} (100%) diff --git a/.gitignore b/.gitignore index be957ce4d..fb4650cc1 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ nytprof* _Inline/ t/*.dll* pp-*.c +*-pp-*.c diff --git a/Basic/.gitignore b/Basic/.gitignore index 002407891..0a14da5b1 100644 --- a/Basic/.gitignore +++ b/Basic/.gitignore @@ -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 diff --git a/Basic/Bad/.gitignore b/Basic/Bad/.gitignore deleted file mode 100644 index 8970dc6b3..000000000 --- a/Basic/Bad/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -Bad.c -Bad.pm -Bad.xs diff --git a/Basic/Bad/Makefile.PL b/Basic/Bad/Makefile.PL deleted file mode 100644 index 6cf767f1c..000000000 --- a/Basic/Bad/Makefile.PL +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; -use ExtUtils::MakeMaker; -use File::Spec::Functions; - -my @pack = (["bad.pd",qw(Bad PDL::Bad)]); - -my %hash = pdlpp_stdargs_int(@pack); - -undef &MY::postamble; # suppress warning -*MY::postamble = sub { - pdlpp_postamble_int(@pack); -}; - -WriteMakefile(%hash); diff --git a/Basic/Makefile.PL b/Basic/Makefile.PL index eb915f07a..81ac5d665 100644 --- a/Basic/Makefile.PL +++ b/Basic/Makefile.PL @@ -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) = @_; @@ -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; }; @@ -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( @@ -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}; } } diff --git a/Basic/Bad/bad.pd b/Basic/lib/PDL/Bad.pd similarity index 100% rename from Basic/Bad/bad.pd rename to Basic/lib/PDL/Bad.pd diff --git a/Basic/lib/PDL/Core/Dev.pm b/Basic/lib/PDL/Core/Dev.pm index 79da57916..db93abdfa 100644 --- a/Basic/lib/PDL/Core/Dev.pm +++ b/Basic/lib/PDL/Core/Dev.pm @@ -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 ); @@ -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\""; @@ -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 @@ -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. @@ -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); @@ -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)); } diff --git a/Basic/lib/PDL/PP.pm b/Basic/lib/PDL/PP.pm index 67abc96bf..42ec9484c 100644 --- a/Basic/lib/PDL/PP.pm +++ b/Basic/lib/PDL/PP.pm @@ -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=""; @@ -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); } diff --git a/MANIFEST b/MANIFEST index f871bcd4c..95b4da5cc 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 @@ -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 diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 9947f6baf..e26445b8e 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -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\..*