Skip to content

Commit

Permalink
math.pd to pass build info back via Core::Dev::EXTRA
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 17, 2024
1 parent 8d8b832 commit 537a058
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
33 changes: 2 additions & 31 deletions Basic/Math/Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
use strict;
use warnings;
use ExtUtils::MakeMaker;

# Files for each routine (.c assumed)
my %source = qw(
j0 j0
j1 j1
jn jn
y0 j0
y1 j1
yn yn
);
my @keys = sort keys %source;

my $libs = get_maths_libs();
# Test for presence of besfuncs
my $include = qq{#include "mconf.h"};
$source{$_} = 'system' for grep trylink('', $include, "$_(1.);", $libs), qw(j0 j1 y0 y1);
$source{$_} = 'system' for grep trylink('', $include, "$_(1,1.);", $libs), qw(jn yn);

my @pack = (["math.pd", qw(Math PDL::Math)]);
my %hash = pdlpp_stdargs_int(@pack);

my %seen; # Build object file list
foreach my $func (@keys) {
my $file = $source{$func};
next if $file eq 'system';
die "File for function $func not found\n" if $file eq '';
$hash{OBJECT} .= " $file\$(OBJ_EXT)" unless $seen{$file}++;
}

# Add support routines
$hash{OBJECT} .= join '', map " $_\$(OBJ_EXT)", qw(const mtherr polevl cpoly ndtri);

$hash{LIBS}[0] .= " $libs";
$hash{OBJECT} .= $PDL::Core::Dev::EXTRAS{'math.pd'}{OBJECT};
$hash{LIBS}[0] .= " " . PDL::Core::Dev::get_maths_libs();

undef &MY::postamble; # suppress warning
*MY::postamble = sub {
Expand Down
28 changes: 28 additions & 0 deletions Basic/Math/math.pd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ use Config;
use PDL::Types qw(ppdefs ppdefs_complex types);
require PDL::Core::Dev;

{ # pass info back to Makefile.PL
# Files for each routine (.c assumed)
my %source = qw(
j0 j0
j1 j1
jn jn
y0 j0
y1 j1
yn yn
);
my @keys = sort keys %source;
my $libs = PDL::Core::Dev::get_maths_libs();
# Test for presence of besfuncs
require File::Spec::Functions;
my $include = qq{#include "}.File::Spec::Functions::rel2abs('mconf.h').qq{"};
$source{$_} = 'system' for grep PDL::Core::Dev::trylink('', $include, "$_(1.);", $libs), qw(j0 j1 y0 y1);
$source{$_} = 'system' for grep PDL::Core::Dev::trylink('', $include, "$_(1,1.);", $libs), qw(jn yn);
my %seen; # Build object file list
foreach my $func (@keys) {
my $file = $source{$func};
next if $file eq 'system';
die "File for function $func not found\n" if $file eq '';
$PDL::Core::Dev::EXTRAS{$::PDLMOD}{OBJECT} .= " $file\$(OBJ_EXT)" unless $seen{$file}++;
}
# Add support routines
$PDL::Core::Dev::EXTRAS{$::PDLMOD}{OBJECT} .= join '', map " $_\$(OBJ_EXT)", qw(const mtherr polevl cpoly ndtri);
}

my $R = [ppdefs()];
my $F = [map $_->ppsym, grep $_->real && !$_->integer, types()];
my $C = [ppdefs_complex()];
Expand Down
9 changes: 2 additions & 7 deletions Basic/lib/PDL/Core/Dev.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ perl's C<%Config> array.

# big/little endian?
sub isbigendian {
use Config;
my $byteorder = $Config{byteorder} ||
die "ERROR: Unable to find 'byteorder' in perl's Config\n";
return 1 if $byteorder eq "4321";
Expand Down Expand Up @@ -446,11 +445,7 @@ sub trylink {
my $opt = ref $_[$#_] eq 'HASH' ? pop : {};
my ($txt,$inc,$body,$libs,$cflags) = @_;
$cflags ||= '';
require File::Spec;
require File::Temp;
my $cdir = sub { return File::Spec->catdir(@_)};
my $cfile = sub { return File::Spec->catfile(@_)};
use Config;
# check if MakeMaker should be used to preprocess the libs
for my $key(keys %$opt) {$opt->{lc $key} = $opt->{$key}}
my $mmprocess = exists $opt->{makemaker} && $opt->{makemaker};
Expand All @@ -464,11 +459,11 @@ sub trylink {
print "processed LIBS: $libs[0]\n" unless $hide;
$libs = $libs[0]; # replace by preprocessed libs
}
print " Trying $txt...\n " unless $txt =~ /^\s*$/;
print " Trying $txt...\n " if $txt =~ /\S/;
my $HIDE = !$hide ? '' : '>/dev/null 2>&1';
if($^O =~ /mswin32/i) {$HIDE = '>NUL 2>&1'}
my $tempd = File::Temp::tempdir(CLEANUP=>1) || die "trylink: could not make temp dir";
my ($tc,$te) = map {&$cfile($tempd,"testfile$_")} ('.c','');
my ($tc,$te) = map catfile($tempd,"testfile$_"), ('.c','');
open FILE,">$tc" or die "trylink: couldn't open testfile `$tc' for writing, $!";
my $prog = <<"EOF";
$inc
Expand Down
3 changes: 2 additions & 1 deletion Basic/lib/PDL/PP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ sub list_functions {
local *PDL::PP::pp_def = sub { push @funcs, (_pp_parsename($_[0]))[0]};
undef &PDL::PP::pp_done;
local *PDL::PP::pp_done = sub {};
$_ = '' for $::PDLMOD, $::CALLPACK, $::PDLOBJ; # stop warnings
$::PDLMOD = $file;
$_ ||= '' for $::CALLPACK, $::PDLOBJ; # stop warnings
require File::Spec::Functions;
do ''.File::Spec::Functions::rel2abs($file);
die $@ if $@;
Expand Down

0 comments on commit 537a058

Please sign in to comment.