Skip to content

Commit

Permalink
use macros eg PDL_MULTIC_Primitive_C so can add functions w/o rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 7, 2024
1 parent 75a71d7 commit 9cb70d1
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions Basic/Core/Dev.pm
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ sub _postamble {
$w = dirname($w);
my $perlrun = $internal ? '$(PERLRUNINST)' : "\$(PERL) \"-I$w\"";
my ($pmdep, $install, $cdep) = ($src, '', '');
my @cbase = $multi_c ? map "pp-$_", _pp_list_functions($src, $internal) : ();
my @objs = map "$_\$(OBJ_EXT)", $pref, @cbase;
my ($ppc, $ppo) = $multi_c ? map "\$($_)", _mod_vars($mod) :
_mod_values($internal, $src, $pref, $multi_c);
if ($internal) {
require File::Spec::Functions;
my $top = File::Spec::Functions::abs2rel($w);
Expand All @@ -154,21 +154,20 @@ sub _postamble {
File::Spec::Functions::catfile($top, qw(Basic Gen pm_to_blib)),
File::Spec::Functions::catfile($core, qw(pm_to_blib)),
;
$cdep .= join ' ', @objs, ':', map File::Spec::Functions::catfile($core, $_),
$cdep .= join ' ', $ppo, ':', map File::Spec::Functions::catfile($core, $_),
qw(pdl.h pdlcore.h pdlbroadcast.h pdlmagic.h);
} else {
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 @generanda = ("$pref.xs", map "$_.c", @cbase);
my $pp_call_arg = _pp_call_arg($mod, $mod, $pref, $callpack, $multi_c||'');
qq|
$pref.pm : $pmdep
$perlrun \"$pp_call_arg\" $src
\$(TOUCH) $pref.pm
@generanda : $pref.pm
$ppc : $pref.pm
\$(NOECHO) \$(NOOP)
$cdep
Expand Down Expand Up @@ -204,22 +203,45 @@ sub _pp_list_functions {
@{ $flist_cache{$abs_src} };
}

sub _mod_vars {
my @parts = split /::/, $_[0];
shift @parts if $parts[0] eq 'PDL';
my $mangled = join '_', @parts;
map "PDL_MULTIC_${mangled}_$_", qw(C O);
}
sub _mod_values {
my ($internal, $src, $pref, $multi_c) = @_;
return ("$pref.xs", "$pref\$(OBJ_EXT)") if !$multi_c;
my @cbase = map "pp-$_", _pp_list_functions($src, $internal);
(join(' ', "$pref.xs", map "$_.c", @cbase),
join(' ', map "$_\$(OBJ_EXT)", $pref, @cbase));
}
sub _stdargs {
my ($w, $internal, $src, $pref, $mod, $callpack, $multi_c) = @_;
my @cbase = $pref;
push @cbase, map "pp-$_", _pp_list_functions($src, $internal) if $multi_c;
my @cfiles = ("$pref.xs", map "$_.c", @cbase);
my @objs = map "$_\$(OBJ_EXT)", @cbase;
my ($clean, %hash) = '';
if ($multi_c) {
my ($mangled_c, $mangled_o) = _mod_vars($mod);
my ($mangled_c_val, $mangled_o_val) = _mod_values($internal, $src, $pref, $multi_c);
%hash = (%hash,
macro => {
$mangled_c => $mangled_c_val, $mangled_o => $mangled_o_val,
},
OBJECT => "\$($mangled_o)",
);
$clean .= " \$($mangled_c)";
} else {
%hash = (%hash, OBJECT => "$pref\$(OBJ_EXT)");
}
(
NAME => $mod,
VERSION_FROM => ($internal ? "$w/Basic/PDL.pm" : $src),
TYPEMAPS => [PDL_TYPEMAP()],
OBJECT => join(' ', @objs),
PM => {"$pref.pm" => "\$(INST_LIBDIR)/$pref.pm"},
MAN3PODS => {"$pref.pm" => "\$(INST_MAN3DIR)/$mod.\$(MAN3EXT)"},
INC => PDL_INCLUDE(),
LIBS => [''],
clean => {FILES => "$pref.pm @cfiles"},
clean => {FILES => "$pref.pm $pref.c$clean"},
%hash,
($internal
? (NO_MYMETA => 1)
: (dist => {PREOP => '$(PERLRUNINST) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' })
Expand Down

0 comments on commit 9cb70d1

Please sign in to comment.