blib/lib/PDL/Core/Dev.pm

filter: Statementstmt 24.6% 73 / 296 Branchbran 15.7% 22 / 140 Conditioncond 9.8% 8 / 81 MC/DCmcdc 4.4% 2 / 45 Subroutinesub 47.0% 16 / 34 Podpod 17.3% 4 / 23 totaltotal 20.1% 125 / 619 CC 112 SCAR 54.9
CC
112
Cov
20%
trylink
650.0
pdlpp_eumm_update_deep
420.0
pdlpp_mkgen
380.0
CRAP 243.0
« lib/PDL/IO/Misc.pd ↑ Summary blib/lib/PDL/IO/FlexRaw.pm »
1 =head1 NAME
2  
3 PDL::Core::Dev - PDL development module
4  
5 =head1 SYNOPSIS
6  
7 use PDL::Core::Dev;
8  
9 =head1 DESCRIPTION
10  
11 This module encapsulates most of the stuff useful for
12 PDL development and is often used from within Makefile.PL's.
13  
14 =head1 BUILD MODES
15  
16 =head2 Old Skool
17  
18 The original scheme, which still works, was one PDL module per
19 L<ExtUtils::MakeMaker> (EUMM) "module", i.e. directory. There has
20 been work with Module::Build, but as that is now deprecated, it
21 will not be further discussed. That module would generate a C<.xs>
22 and C<.pm> file in its directory, according to its F<Makefile.PL>,
23 such as linking extra objects, or other libraries.
24  
25 To have several distinct PDL modules in a CPAN
26 distribution, you made several directories, each with a F<Makefile.PL>.
27 Parallel building was not normally possible between modules, though
28 see PDL's top-level F<Makefile.PL> as of about 2015, which gained a
29 C<coretest> target that did build in parallel despite subdirectories
30 and "recursive make". Any change to any C code caused a rebuild of
31 the whole C<.xs> file (for Slices this was upwards of 40,000 lines),
32 and being one compilation unit, it could not be parallelised.
33  
34 =head2 Multi-C files
35  
36 As of 2.058, a new "multi-C" mode was added for all internal PDL
37 modules, and external ones that opted in (by adding a 5th, true,
38 element to the array-ref describing the package). This creates one
39 C file per operation, so parallel building is possible. This makes
40 for quicker builds, both for those installing the package, and those
41 developing it.
42  
43 It can also avoid unnecessary rebuilds if only one operation got
44 changed - it only recompiles that C file.
45 This is possible due to some trickiness by L<PDL::PP>,
46 which detects if each C file that it I<would> output is the same
47 as the one already on disk, first removing any C<#line> directives so
48 that line renumbering will not force a rebuild, and not writing
49 anything unless a real change happened.
50  
51 It is opt-in because if the module adds C functions with C<pp_addhdr>
52 without scoping them appropriately, they get incorporated in each
53 generated C file, which causes linking problems. Moving those to
54 separate C files solves that.
55  
56 But parallel building (without the "cleverness" of the C<coretest>
57 work) is only possible within each module.
58  
59 =head2 Deep mode
60  
61 EUMM pure-Perl distributions in the modern era have
62 a F<lib> directory, whose structure matches the hierarchy of modules.
63 Until 2.096, PDL used this in its F<Basic> subdirectory, so there was e.g.
64 F<lib/PDL/Core.pm> under that. As of EUMM 7.12 (shipped with Perl
65 5.26), it's also possible
66 to put C<.xs> files next to their respective C<.pm> files, by giving
67 a true value for C<XSMULTI>.
68  
69 As of 2.096, another new mode was added, which automatically engages
70 "multi-C" mode. This allows you to place your C<.pd> file under a
71 F<lib> directory, whose location tells the build system its package
72 name, which means the previous schemes' need to communicate that
73 in each F<Makefile.PL> is no more. Now, the configuration is
74 communicated by each C<.pd> file by setting values in a hash, e.g.:
75  
76 { no warnings 'once'; # pass info back to Makefile.PL
77 $PDL::Core::Dev::EXTRAS{$::PDLMOD}{OBJECT} .= join '', map " $::PDLBASE/$_\$(OBJ_EXT)", qw(fftn);
78 $PDL::Core::Dev::EXTRAS{$::PDLMOD}{DEFINE} .= qq{ -DFFT_FLOAT -DFFT_DOUBLE -DFFT_LDOUBLE};
79 $PDL::Core::Dev::EXTRAS{$::PDLMOD}{INC} .= qq{ "-I$::PDLBASE"};
80 }
81  
82 This works because PDL needs to make an entry in the Makefile for
83 each operation defined, which it does by loading the C<.pd> file,
84 and making its version of C<pp_def> just record the operation name.
85 As a side effect, the setting of the C<EXTRAS> value can be seen
86 by the build process.
87  
88 To have the only F<Makefile.PL> work in this new scheme, converting
89 it from the previous one(s), you need to add this key to the
90 C<WriteMakefile> call:
91  
92 VERSION_FROM => 'lib/PDL/GSL/CDF.pd',
93  
94 Note that the ones supplied by C<pdlpp_stdargs> are added for you. You I<do>
95 need to provide overrides for C<postamble> as before, and also C<init_PM>:
96  
97 {
98 my @pd_srcs;
99 package MY; # so that "SUPER" works right
100 sub init_PM {
101 my ($self) = @_;
102 $self->SUPER::init_PM;
103 @pd_srcs = ::pdlpp_eumm_update_deep($self);
104 }
105 sub postamble { ::pdlpp_postamble(@pd_srcs) }
106 }
107  
108 Please note that if you have a pure-Perl top-level driving module,
109 like L<PDL::Graphics::TriD> or L<PDL::LinearAlgebra>, and you want
110 that top-level module's C<FUNCTIONS> added to the C<pdldoc>
111 documentation, you will want to replace the C<postamble> definition
112 with something a lot like:
113  
114 sub postamble { ::pdlpp_postamble(@pd_srcs) . ::pdldoc_add() }
115  
116 =head1 FUNCTIONS
117  
118 =cut
119  
120 # Stuff used in development/install environment of PDL Makefile.PL's
121 # - not part of PDL itself.
122  
123 package PDL::Core::Dev;
124  
125 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 7 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 7 require Exporter;
130 7 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 7 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 7 eval { require Devel::CheckLib };
133  
134 7 our @ISA = qw( Exporter );
135  
136 7 our @EXPORT = qw( isbigendian
137 PDL_INCLUDE PDL_TYPEMAP
138 PDL_AUTO_INCLUDE PDL_BOOT
139 PDL_INST_INCLUDE PDL_INST_TYPEMAP
140 pdlpp_eumm_update_deep pdldoc_add
141 pdlpp_postamble_int pdlpp_stdargs_int
142 pdlpp_postamble pdlpp_stdargs write_dummy_make
143 unsupported trylink get_maths_libs
144 pdlpp_mkgen
145 got_complex_version
146 );
147  
148 # Installation locations
149 6 ▶sub PDL_INCLUDE { '"-I'.catdir(whereami_any(), 'Core').'"' }
Subroutine PDL_INCLUDE: called CC=1 SCAR=0.0
Pod undocumented
150 8 ▶sub PDL_TYPEMAP { catfile(whereami_any(), qw(Core typemap)) }
Subroutine PDL_TYPEMAP: called CC=1 SCAR=0.0
Pod undocumented
151  
152 # The INST are here still just in case we want to change something later.
153 7 *PDL_INST_INCLUDE = \&PDL_INCLUDE;
154 7 *PDL_INST_TYPEMAP = \&PDL_TYPEMAP;
155  
156 sub PDL_AUTO_INCLUDE {
157 1 ▶ my ($symname) = @_;
Subroutine PDL_AUTO_INCLUDE: called CC=2 SCAR=7.1
Pod undocumented
158 1 ▶ $symname ||= 'PDL';
Condition50%1/2
$symname ||= "PDL"
l!l
10
MC/DC0%0/1
$symname ||= "PDL"
$symname
Truth table50%1/2
A
A= $symname
Aresult
11
00
159 1 return << "EOR";
160 #include <pdlcore.h>
161 static Core* $symname; /* Structure holds core C functions */
162 EOR
163 }
164  
165 sub PDL_BOOT {
166 2 ▶ my ($symname, $module) = @_;
Subroutine PDL_BOOT: called CC=3 SCAR=11.4
Pod undocumented
167 2 ▶ $symname ||= 'PDL';
Condition50%1/2
$symname ||= "PDL"
l!l
20
MC/DC0%0/1
$symname ||= "PDL"
$symname
Truth table50%1/2
A
A= $symname
Aresult
11
00
168 2 ▶ $module ||= 'The code';
Condition50%1/2
$module ||= "The code"
l!l
20
MC/DC0%0/1
$module ||= "The code"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
169 2 return << "EOR";
170 perl_require_pv ("PDL/Core.pm"); /* make sure PDL::Core is loaded */
171 #ifndef aTHX_
172 #define aTHX_
173 #endif
174 if (SvTRUE (ERRSV)) Perl_croak(aTHX_ "%s",SvPV_nolen (ERRSV));
175 SV* CoreSV = perl_get_sv("PDL::SHARE",FALSE); /* var with core structure */
176 if (!CoreSV)
177 Perl_croak(aTHX_ "We require the PDL::Core module, which was not found");
178 if (!($symname = INT2PTR(Core*,SvIV( CoreSV )))) /* Core* value */
179 Perl_croak(aTHX_ "Got NULL pointer for $symname");
180 if ($symname->Version != PDL_CORE_VERSION)
181 Perl_croak(aTHX_ "[$symname->Version: \%ld PDL_CORE_VERSION: \%ld XS_VERSION: \%s] $module needs to be recompiled against the newly installed PDL", (long int)$symname->Version, (long int)PDL_CORE_VERSION, XS_VERSION);
182 EOR
183 }
184  
185 7 ▶use Cwd qw/abs_path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
186 7 my $MY_FILE = abs_path(__FILE__); # capture at load-time because EUMM chdirs
187 7 my $MY_DIR2 = dirname(dirname($MY_FILE));
188 14 ▶sub whereami_any { $MY_DIR2 } # something containing "Core/Dev.pm"
Subroutine whereami_any: called CC=1 SCAR=0.0
Pod undocumented
189  
190 =head2 isbigendian
191  
192 =for ref
193  
194 Is the machine big or little endian?
195  
196 =for example
197  
198 print "Your machins is big endian.\n" if isbigendian();
199  
200 returns 1 if the machine is big endian, 0 if little endian,
201 or dies if neither. It uses the C<byteorder> element of
202 perl's C<%Config> array.
203  
204 =for usage
205  
206 my $retval = isbigendian();
207  
208 =cut
209  
210 # ' emacs parsing dummy
211  
212 # big/little endian?
213 sub isbigendian {
214 my $byteorder = $Config{byteorder} ||
215 0 ▶ die "ERROR: Unable to find 'byteorder' in perl's Config\n";
Subroutine isbigendian: not called CC=6 SCAR=37.4
Pod documented
Condition0%0/2
$PDL::Core::Dev::Config{'byteorder'} || die("ERROR: Unable to find 'byteorder' in perl's Config\n")
l!l
00
MC/DC0%0/1
$PDL::Core::Dev::Config{'byteorder'} || die("ERROR: Unable to find 'byteorder' in perl's Config\n")
$PDL::Core::Dev::Config{'byteorder'}
Truth table0%0/2
A
A= $PDL::Core::Dev::Config{'byteorder'}
Aresult
11
00
216 0 ▶ return 1 if $byteorder eq "4321";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 4321 0 0 0
217 0 ▶ return 1 if $byteorder eq "87654321";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 87654321 0 0 0
218 0 ▶ return 0 if $byteorder eq "1234";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 1234 0 0 0
219 0 ▶ return 0 if $byteorder eq "12345678";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 12345678 0 0 0
220 0 die "ERROR: PDL does not understand your machine's byteorder ($byteorder)\n";
221 }
222  
223 sub _oneliner {
224 0 ▶ my ($cmd, @flags) = @_;
Subroutine _oneliner: not called CC=1 SCAR=6.9
225 0 require ExtUtils::MM;
226 0 my $MM = bless { NAME => 'Fake' }, 'MM';
227 0 $MM->oneliner($cmd, \@flags);
228 }
229  
230 # Expects list in format:
231 # [gtest.pd, GTest, PDL::GTest[, PDL::XSPkg] ], [...]
232 # source, prefix,module/package, optional pp_addxs destination
233 # The idea is to support in future several packages in same dir - EUMM
234 # 7.06 supports
235  
236 7 my %flist_cache;
237 sub _pp_call_arg {
238 0 ▶ "-MPDL::PP=".join ',', @_
Subroutine _pp_call_arg: not called CC=1 SCAR=6.9
239 }
240 sub _postamble {
241 0 ▶ my ($w, $internal, $src, $base, $mod, $callpack, $multi_c, $deep) = @_;
Subroutine _postamble: not called CC=7 SCAR=40.3
242 0 ▶ $callpack //= '';
Condition0%0/2
$callpack //= ""
l!l
00
MC/DC0%0/1
$callpack //= ""
$callpack
Truth table0%0/2
A
A= $callpack
Aresult
11
00
243 0 $w = dirname($w);
244 0 my $perlrun = "\$(PERLRUN) \"-I$w\"";
245 0 my ($pmdep, $install, $cdep) = ($src, '', '');
246 0 ▶ my ($ppc, $ppo) = ($multi_c && $flist_cache{File::Spec::Functions::rel2abs($src)})
Branch: 1 branch
BranchTrueFalseTotal
$multi_c && $flist_cache{File::Spec::Functions::rel2abs($src)} ? : 0 0 0
Condition0%0/3
$multi_c and $flist_cache{File::Spec::Functions::rel2abs($src)}
!ll&&!rl&&r
000
MC/DC0%0/2
$multi_c and $flist_cache{File::Spec::Functions::rel2abs($src)}
$multi_c $flist_cache{File::Spec::Functions::rel2abs($src)}
Truth table0%0/3
A and B
A= $multi_cB= $flist_cache{File::Spec::Functions::rel2abs($src)}
ABresult
0X0
100
111
247 ? map "\$($_)", pdlpp_mod_vars($mod)
248 : pdlpp_mod_values($internal, $src, $base, $multi_c);
249 0 ▶ if ($internal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($internal) { } 0 0 0
250 0 my $ppdir = File::Spec::Functions::abs2rel(catdir($w, qw(PDL)));
251 0 $pmdep .= join ' ', '', catfile($ppdir, 'PP.pm'), glob(catfile($ppdir, 'PP/*'));
252 0 $cdep .= join ' ', $ppo, ':', map catfile($ppdir, qw(Core), $_),
253 qw(pdl.h pdlcore.h pdlbroadcast.h pdlmagic.h);
254 } else {
255 0 $install = pdldoc_add($mod);
256 }
257 0 ▶ my $pp_call_arg = _pp_call_arg($mod, $mod, $base, $callpack, $multi_c||'',$deep||'');
Condition0%0/4
$multi_c || ''
l!l
00
$deep || ''
l!l
00
MC/DC0%0/1
$multi_c || ''
$multi_c
MC/DC0%0/1
$deep || ''
$deep
Truth table0%0/2
A
A= $multi_c
Aresult
11
00
Truth table0%0/2
A
A= $deep
Aresult
11
00
258 0 qq|
259  
260 $base.pm : $pmdep
261 $perlrun \"$pp_call_arg\" $src
262 \$(TOUCH) $base.pm
263  
264 $ppc : $base.pm
265 \$(NOECHO) \$(NOOP)
266  
267 $cdep
268 $install|
269 }
270  
271 sub pdlpp_postamble_int {
272 0 ▶ my $w = whereami_any();
Subroutine pdlpp_postamble_int: not called CC=1 SCAR=6.9
Pod undocumented
273 0 join '', map _postamble($w, 1, @$_[0..3], 1, @$_[5..$#$_]), @_;
274 }
275  
276 # This is the function to be used outside the PDL tree.
277 # same format as pdlpp_postamble_int
278 sub pdlpp_postamble {
279 0 ▶ my $w = whereami_any();
Subroutine pdlpp_postamble: not called CC=1 SCAR=6.9
Pod undocumented
280 0 join '', map _postamble($w, 0, @$_), @_;
281 }
282  
283 sub pdldoc_add {
284 0 ▶ my ($mod) = @_;
Subroutine pdldoc_add: not called CC=3 SCAR=24.8
Pod undocumented
285 0 ▶ my $end = defined $mod ? '' : " \$(NAME)";
Branch: 1 branch
BranchTrueFalseTotal
defined $mod ? : 0 0 0
286 0 ▶ $mod //= 'shift';
Condition0%0/2
$mod //= "shift"
l!l
00
MC/DC0%0/1
$mod //= "shift"
$mod
Truth table0%0/2
A
A= $mod
Aresult
11
00
287 0 my $oneliner = _oneliner(qq{exit if \$ENV{DESTDIR}; use PDL::Doc; eval { PDL::Doc::add_module($mod); }});
288 0 qq|\ninstall :: pure_install\n\t$oneliner$end\n|;
289 }
290  
291 7 our %EXTRAS;
292 sub pdlpp_eumm_update_deep {
293 0 ▶ my ($eumm) = @_;
Subroutine pdlpp_eumm_update_deep: not called CC=20 SCAR=60.4
Pod undocumented
294 0 my $pm = $eumm->{PM};
295 0 delete @$pm{grep /(?:\.(?:c|xs|bs)|\Q$Config{obj_ext}\E)$/, keys %$pm};
296 0 ▶ my $macro = $eumm->{macro} ||= {};
Condition0%0/2
$eumm->{"macro"} ||= {}
l!l
00
MC/DC0%0/1
$eumm->{"macro"} ||= {}
$eumm->{"macro"}
Truth table0%0/2
A
A= $eumm->{"macro"}
Aresult
11
00
297 0 ▶ my $xsb = $eumm->{XSBUILD}{xs} ||= {};
Condition0%0/2
$eumm->{"XSBUILD"}{"xs"} ||= {}
l!l
00
MC/DC0%0/1
$eumm->{"XSBUILD"}{"xs"} ||= {}
$eumm->{"XSBUILD"}{"xs"}
Truth table0%0/2
A
A= $eumm->{"XSBUILD"}{"xs"}
Aresult
11
00
298 0 ▶ $eumm->{clean}{FILES} ||= '';
Condition0%0/2
$eumm->{"clean"}{"FILES"} ||= ""
l!l
00
MC/DC0%0/1
$eumm->{"clean"}{"FILES"} ||= ""
$eumm->{"clean"}{"FILES"}
Truth table0%0/2
A
A= $eumm->{"clean"}{"FILES"}
Aresult
11
00
299 0 ▶ $eumm->{OBJECT} ||= '';
Condition0%0/2
$eumm->{"OBJECT"} ||= ""
l!l
00
MC/DC0%0/1
$eumm->{"OBJECT"} ||= ""
$eumm->{"OBJECT"}
Truth table0%0/2
A
A= $eumm->{"OBJECT"}
Aresult
11
00
300 0 ▶ $eumm->{INC} ||= '';
Condition0%0/2
$eumm->{"INC"} ||= ""
l!l
00
MC/DC0%0/1
$eumm->{"INC"} ||= ""
$eumm->{"INC"}
Truth table0%0/2
A
A= $eumm->{"INC"}
Aresult
11
00
301 0 my $pdl_inc = PDL_INCLUDE();
302 0 ▶ $eumm->{INC} .= ' '.$pdl_inc if index($eumm->{INC}, $pdl_inc) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($eumm->{"INC"}, $pdl_inc) == -1 0 0 0
303 0 ▶ my $tms = $eumm->{TYPEMAPS} ||= [];
Condition0%0/2
$eumm->{"TYPEMAPS"} ||= []
l!l
00
MC/DC0%0/1
$eumm->{"TYPEMAPS"} ||= []
$eumm->{"TYPEMAPS"}
Truth table0%0/2
A
A= $eumm->{"TYPEMAPS"}
Aresult
11
00
304 0 my $pdl_tm = PDL_TYPEMAP();
305 0 ▶ push @$tms, $pdl_tm if !grep $_ eq $pdl_tm, @$tms;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($_ eq $pdl_tm), @$tms) 0 0 0
306 0 ▶ $eumm->{XSMULTI} ||= 1;
Condition0%0/2
$eumm->{"XSMULTI"} ||= 1
l!l
00
MC/DC0%0/1
$eumm->{"XSMULTI"} ||= 1
$eumm->{"XSMULTI"}
Truth table0%0/2
A
A= $eumm->{"XSMULTI"}
Aresult
11
00
307 0 ▶ $eumm->{dist}{PREOP} ||= '$(PERLRUNINST) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)';
Condition0%0/2
$eumm->{"dist"}{"PREOP"} ||= "\$(PERLRUNINST) -MPDL::Core::Dev -e pdlpp_mkgen \$(DISTVNAME)"
l!l
00
MC/DC0%0/1
$eumm->{"dist"}{"PREOP"} ||= "\$(PERLRUNINST) -MPDL::Core::Dev -e pdlpp_mkgen \$(DISTVNAME)"
$eumm->{"dist"}{"PREOP"}
Truth table0%0/2
A
A= $eumm->{"dist"}{"PREOP"}
Aresult
11
00
308 0 ▶ my $xs = $eumm->{XS} ||= {};
Condition0%0/2
$eumm->{"XS"} ||= {}
l!l
00
MC/DC0%0/1
$eumm->{"XS"} ||= {}
$eumm->{"XS"}
Truth table0%0/2
A
A= $eumm->{"XS"}
Aresult
11
00
309 0 my $global_version = $eumm->parse_version($eumm->{VERSION_FROM});
310 0 my @pd_srcs;
311 0 for my $f (grep /\.pd$/, keys %$pm) {
312 0 delete $pm->{$f};
313 0 my $nolib = (my $base = $f =~ s/\.pd$//r) =~ s#^lib/##r;
314 0 $xs->{ "$base.xs" } = "$base.c";
315 0 my $pmfile = "$base.pm";
316 0 $pm->{$pmfile} = "\$(INST_LIB)/$nolib.pm";
317 0 my @macro_vars = pdlpp_mod_vars(my $mod = join '::', split /\//, $nolib);
318 0 @$macro{@macro_vars} = pdlpp_mod_values(1, $f, $base, 1, 1);
319 0 $eumm->{OBJECT} .= " $base\$(OBJ_EXT)";
320 0 $xsb->{$base}{OBJECT} = "\$($macro_vars[1])";
321 0 ▶ $xsb->{$base}{OBJECT} .= $EXTRAS{$f}{OBJECT} if $EXTRAS{$f}{OBJECT};
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Core::Dev::EXTRAS{$f}{"OBJECT"} 0 0 0
322 0 ▶ $eumm->{DEFINE} .= $EXTRAS{$f}{DEFINE} if $EXTRAS{$f}{DEFINE}; # global
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Core::Dev::EXTRAS{$f}{"DEFINE"} 0 0 0
323 0 ▶ $eumm->{INC} .= " $EXTRAS{$f}{INC}" if $EXTRAS{$f}{INC}; # global
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Core::Dev::EXTRAS{$f}{"INC"} 0 0 0
324 0 ▶ my $mtime = (stat $f)[9] // die "$f: $!";
Condition0%0/2
(stat $f)[9] // die("${f}: $!")
l!l
00
MC/DC0%0/1
(stat $f)[9] // die("${f}: $!")
(stat $f)[9]
Truth table0%0/2
A
A= (stat $f)[9]
Aresult
11
00
325 0 ▶ open my $fh, ">", $pmfile or die "$pmfile: $!"; # XSMULTI needs this
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $pmfile or die "${pmfile}: $!" 0 0 0
326 0 print $fh "package $mod;\nour \$VER"."SION = '$global_version';\n1;\n"; # break is so cpanm doesn't try to parse as version
327 0 close $fh;
328 0 utime $mtime - 120, $mtime - 120, $pmfile; # so is out of date
329 0 push @pd_srcs, [$f, $base, $mod, '', 1, 1];
330 0 my $clean_extra = join ' ', '', $pmfile, map "\$($_)", @macro_vars;
331 0 ▶ $clean_extra .= $EXTRAS{$f}{OBJECT} if $EXTRAS{$f}{OBJECT};
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Core::Dev::EXTRAS{$f}{"OBJECT"} 0 0 0
332 0 ▶ if (ref $eumm->{clean}{FILES}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $eumm->{'clean'}{'FILES'}) { } 0 0 0
333 0 push @{$eumm->{clean}{FILES}}, $clean_extra;
334 } else {
335 0 $eumm->{clean}{FILES} .= $clean_extra;
336 }
337 }
338 0 delete @$pm{grep /\.c$/, keys %$pm};
339 0 @pd_srcs;
340 }
341  
342 sub pdlpp_list_functions {
343 0 ▶ my ($src, $internal, $base) = @_;
Subroutine pdlpp_list_functions: not called CC=3 SCAR=24.8
Pod undocumented
344 0 my $abs_src = File::Spec::Functions::rel2abs($src);
345 0 ▶ if (!$flist_cache{$abs_src}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flist_cache{$abs_src}) 0 0 0
346 0 my $w = whereami_any();
347 0 ▶ if (!$INC{'PDL/Types.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"PDL/Types.pm"}) 0 0 0
348 0 my $typespm = catfile($w, 'Types.pm');
349 0 require $typespm;
350 0 $INC{'PDL/Types.pm'} = 1;
351 }
352 0 require ''.catfile($w, qw(PP.pm));
353 0 $::PDLBASE = $base;
354 0 $flist_cache{$abs_src} = [ PDL::PP::list_functions($src) ];
355 }
356 0 @{ $flist_cache{$abs_src} };
357 }
358  
359 sub pdlpp_mod_vars {
360 0 ▶ my @parts = split /::/, $_[0];
Subroutine pdlpp_mod_vars: not called CC=2 SCAR=17.9
Pod undocumented
361 0 ▶ shift @parts if $parts[0] eq 'PDL';
Branch: 1 branch
BranchTrueFalseTotal
if $parts[0] eq "PDL" 0 0 0
362 0 my $mangled = join '_', @parts;
363 0 map "PDL_MULTIC_${mangled}_$_", qw(C O);
364 }
365 sub pdlpp_mod_values {
366 0 ▶ my ($internal, $src, $base, $multi_c, $deep) = @_;
Subroutine pdlpp_mod_values: not called CC=3 SCAR=24.8
Pod undocumented
367 0 ▶ return ("$base.xs", "$base\$(OBJ_EXT)") if !$multi_c;
Branch: 1 branch
BranchTrueFalseTotal
unless $multi_c 0 0 0
368 0 ▶ my $cfileprefix = $deep ? "$base-" : '';
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 0 0 0
369 0 my @cbase = map $cfileprefix."pp-$_", pdlpp_list_functions($src, $internal, $base);
370 0 (join(' ', "$base.xs", map "$_.c", @cbase),
371 join(' ', map "$_\$(OBJ_EXT)", $base, @cbase));
372 }
373 sub _stdargs {
374 2 ▶ my ($w, $internal, $src, $base, $mod, $callpack, $multi_c) = @_;
Subroutine _stdargs: called CC=5 SCAR=19.8
375 2 my ($clean, %hash) = '';
376 2 ▶ if ($multi_c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_c) { } 0 2 2
377 0 my ($mangled_c, $mangled_o) = pdlpp_mod_vars($mod);
378 0 my ($mangled_c_val, $mangled_o_val) = pdlpp_mod_values($internal, $src, $base, $multi_c);
379 0 %hash = (%hash,
380 macro => {
381 $mangled_c => $mangled_c_val, $mangled_o => $mangled_o_val,
382 },
383 OBJECT => "\$($mangled_o)",
384 );
385 0 $clean .= " \$($mangled_c)";
386 } else {
387 2 %hash = (%hash, OBJECT => "$base\$(OBJ_EXT)");
388 2 $clean .= " $base.xs";
389 }
390 2 ▶ if ($internal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($internal) 0 2 2
391 $hash{depend} = {
392 0 "$base\$(OBJ_EXT)" => File::Spec::Functions::abs2rel(catfile($w, qw(PDL Core pdlperl.h))),
393 };
394 }
395 (
396 2 ▶ NAME => $mod,
Branch: 2 branches
BranchTrueFalseTotal
$internal ? : 0 2 2
$internal ? : 0 2 2
397 VERSION_FROM => ($internal ? catfile($w, qw(PDL Core.pm)) : $src),
398 TYPEMAPS => [PDL_TYPEMAP()],
399 PM => {"$base.pm" => "\$(INST_LIBDIR)/$base.pm"},
400 MAN3PODS => {"$base.pm" => "\$(INST_MAN3DIR)/$mod.\$(MAN3EXT)"},
401 INC => PDL_INCLUDE(),
402 LIBS => [''],
403 clean => {FILES => "$base.pm $base.c$clean"},
404 %hash,
405 ($internal
406 ? (NO_MYMETA => 1)
407 : (dist => {PREOP => '$(PERLRUNINST) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' })
408 ),
409 );
410 }
411  
412 sub pdlpp_stdargs_int {
413 0 ▶ _stdargs(dirname($MY_DIR2), 1, @{$_[0]}[0..3], 1);
Subroutine pdlpp_stdargs_int: not called CC=1 SCAR=6.9
Pod undocumented
414 }
415  
416 sub pdlpp_stdargs {
417 2 ▶ _stdargs(undef, 0, @{$_[0]});
Subroutine pdlpp_stdargs: called CC=1 SCAR=0.0
Pod undocumented
418 }
419  
420 # pdlpp_mkgen($dir)
421 # - scans $dir/MANIFEST for all *.pd files and creates corresponding *.pm files
422 # in $dir/GENERATED/ subdir; needed for proper doc rendering at metacpan.org
423 # - it is used in Makefile.PL like:
424 # dist => { PREOP=>'$(PERL) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' }
425 # so all the magic *.pm generation happens during "make dist"
426 # - it is intended to be called as a one-liner:
427 # perl -MPDL::Core::Dev -e pdlpp_mkgen DirName
428 # - it relies on finding "=head1 NAME" and the module name in *.pd, though can be in comment
429 #
430 sub pdlpp_mkgen {
431 0 ▶ require File::Copy;
Subroutine pdlpp_mkgen: not called CC=19 SCAR=59.4
Pod undocumented
432 0 require ExtUtils::Manifest;
433 0 ▶ my $dir = @_ > 0 ? $_[0] : $ARGV[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 ? : 0 0 0
434 0 ▶ die "pdlpp_mkgen: unspecified directory" unless defined $dir && -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and -d $dir 0 0 0
Condition0%0/3
defined $dir and -d $dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dir and -d $dir
defined $dir -d $dir
Truth table0%0/3
A and B
A= defined $dirB= -d $dir
ABresult
0X0
100
111
435 0 my $file = "$dir/MANIFEST";
436 0 ▶ die "pdlpp_mkgen: non-existing '$file\'" unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
437 0 my @pairs = ();
438 0 my $manifest = ExtUtils::Manifest::maniread($file);
439 0 ▶ for (grep !/^(t|xt)\// && /\.pd$/ && -f, sort keys %$manifest) {
Condition0%0/6
!m[^(t|xt)/] && /\.pd$/ && -f $_
!ll&&!rl&&r
000
not m[^(t|xt)/] and /\.pd$/
!ll&&!rl&&r
000
MC/DC0%0/3
!m[^(t|xt)/] && /\.pd$/ && -f $_
not m[^(t|xt)/] /\.pd$/ -f $_
Truth table0%0/4
not(A) and B && C
A= not m[^(t|xt)/]B= /\.pd$/C= -f $_
ABCresult
0XX0
10X0
1100
1111
440 0 my $content = do { local $/; open my $in, '<', $_; <$in> };
441 0 ▶ warn("pdlpp_mkgen: unknown module name for '$_' (use proper '=head1 NAME' section)\n"), next
Branch: 1 branch
BranchTrueFalseTotal
unless my($name) = $content =~ /=head1\s+NAME\s+(\S+)\s+/gs 0 0 0
442 if !(my ($name) = $content =~ /=head1\s+NAME\s+(\S+)\s+/sg);
443 0 push @pairs, [$_, $name];
444 }
445 0 my %added = ();
446 0 my @in = map "-I".File::Spec::Functions::rel2abs($_), @INC;
447 0 for (@pairs) {
448 0 my ($pd, $mod) = @$_;
449 0 (my $prefix = $mod) =~ s|::|/|g;
450 0 my $outfile = File::Spec::Functions::rel2abs("$dir/GENERATED/$prefix.pm");
451 0 File::Path::mkpath(dirname($outfile));
452 0 my $old_cwd = Cwd::cwd();
453 0 my $maybe_lib_base = "lib/$prefix";
454 0 my $maybe_lib_path = "$maybe_lib_base.pd";
455 0 my $is_lib_path = substr($pd, -length $maybe_lib_path) eq $maybe_lib_path;
456 0 ▶ my $todir = $is_lib_path ? substr($pd, 0, -length($maybe_lib_path)-1) : dirname($pd);
Branch: 1 branch
BranchTrueFalseTotal
$is_lib_path ? : 0 0 0
457 0 ▶ chdir $todir if $todir;
Branch: 1 branch
BranchTrueFalseTotal
if $todir 0 0 0
458 0 ▶ my $basename = $is_lib_path ? $maybe_lib_base : (split '/', $prefix)[-1];
Branch: 1 branch
BranchTrueFalseTotal
$is_lib_path ? : 0 0 0
459 0 my $pp_call_arg = _pp_call_arg($mod, $mod, $basename, '', 0); # 0 so guarantee not create pp-*.c
460 #there is no way to use PDL::PP from perl code, thus calling via system()
461 0 ▶ my $rv = system $^X, @in, $pp_call_arg, $is_lib_path ? "$basename.pd" : basename($pd);
Branch: 1 branch
BranchTrueFalseTotal
$is_lib_path ? : 0 0 0
462 0 my $basefile = "$basename.pm";
463 0 ▶ die "pdlpp_mkgen: cannot convert '$pd'\n" unless $rv == 0 && -f $basefile;
Branch: 1 branch
BranchTrueFalseTotal
unless $rv == 0 and -f $basefile 0 0 0
Condition0%0/3
$rv == 0 and -f $basefile
!ll&&!rl&&r
000
MC/DC0%0/2
$rv == 0 and -f $basefile
$rv == 0 -f $basefile
Truth table0%0/3
A and B
A= $rv == 0B= -f $basefile
ABresult
0X0
100
111
464 0 ▶ File::Copy::copy($basefile, $outfile) or die "$outfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy($basefile, $outfile) or die "${outfile}: $!" 0 0 0
465 0 unlink $basefile; # Transform::Proj4.pm is wrong without GIS::Proj built
466 0 unlink "$basename.xs"; # since may have been recreated wrong
467 0 ▶ chdir $old_cwd or die "chdir $old_cwd: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $old_cwd or die "chdir ${old_cwd}: $!" 0 0 0
468 0 $added{"GENERATED/$prefix.pm"} = "mod=$mod pd=$pd (added by pdlpp_mkgen)";
469 }
470 0 ▶ if (scalar(keys %added) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %added > 0) 0 0 0
471 #maniadd works only with this global variable
472 0 local $ExtUtils::Manifest::MANIFEST = $file;
473 0 ExtUtils::Manifest::maniadd(\%added);
474 }
475 }
476  
477 sub unsupported {
478 0 ▶ my ($package,$os) = @_;
Subroutine unsupported: not called CC=1 SCAR=6.9
Pod undocumented
479 0 "No support for $package on $os platform yet. Will skip build process";
480 }
481  
482 sub write_dummy_make {
483 0 ▶ my ($msg) = @_;
Subroutine write_dummy_make: not called CC=1 SCAR=6.9
Pod undocumented
484 0 $msg =~ s#\n*\z#\n#;
485 0 $msg =~ s#^\s*#\n#gm;
486 0 print $msg;
487 0 require ExtUtils::MakeMaker;
488 0 ExtUtils::MakeMaker::WriteEmptyMakefile(NAME => 'Dummy', DIR => []);
489 }
490  
491 sub getcyglib {
492 0 ▶my ($lib) = @_;
Subroutine getcyglib: not called CC=1 SCAR=6.9
Pod undocumented
493 0 my $lp = `gcc -print-file-name=lib$lib.a`;
494 0 $lp =~ s|/[^/]+$||;
495 0 $lp =~ s|^([a-z,A-Z]):|//$1|g;
496 0 return "-L$lp -l$lib";
497 }
498  
499 =head2 trylink
500  
501 =for ref
502  
503 a perl configure clone
504  
505 =for example
506  
507 if (trylink 'libGL', '', 'char glBegin(); glBegin();', '-lGL') {
508 $libs = '-lGLU -lGL';
509 $have_GL = 1;
510 } else {
511 $have_GL = 0;
512 }
513 $maybe =
514 trylink 'libwhatever', '', $body, $libs, $cflags,
515 {MakeMaker=>1, Hide=>0, Clean=>1};
516  
517 Try to link some C-code making up the body of a function
518 with a given set of library specifiers
519  
520 return 1 if successful, 0 otherwise
521  
522 =for usage
523  
524 trylink $infomsg, $include, $progbody, $libs [,$cflags,{OPTIONS}];
525  
526 Takes 4 + 2 optional arguments.
527  
528 =over 5
529  
530 =item *
531  
532 an informational message to print (can be empty)
533  
534 =item *
535  
536 any commands to be included at the top of the generated C program
537 (typically something like C<#include "mylib.h">)
538  
539 =item *
540  
541 the body of the program (in function main)
542  
543 =item *
544  
545 library flags to use for linking. Preprocessing
546 by MakeMaker should be performed as needed (see options and example).
547  
548 =item *
549  
550 compilation flags. For example, something like C<-I/usr/local/lib>.
551 Optional argument. Empty if omitted.
552  
553 =item *
554  
555 OPTIONS
556  
557 =over
558  
559 =item MakeMaker
560  
561 Preprocess library strings in the way MakeMaker does things. This is
562 advisable to ensure that your code will actually work after the link
563 specs have been processed by MakeMaker.
564  
565 =item Hide
566  
567 Controls if linking output etc is hidden from the user or not.
568 On by default but overridable with environment variable C<HIDE_TRYLINK> if set.
569  
570 =item Clean
571  
572 Remove temporary files. Enabled by default. You might want to switch
573 it off during debugging.
574  
575 =back
576  
577 =back
578  
579 =cut
580  
581 sub trylink {
582 0 ▶ my $opt = ref $_[$#_] eq 'HASH' ? pop : {};
Subroutine trylink: not called CC=25 SCAR=64.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[$#_] eq 'HASH' ? : 0 0 0
583 0 my ($txt,$inc,$body,$libs,$cflags) = @_;
584 0 ▶ $cflags ||= '';
Condition0%0/2
$cflags ||= ""
l!l
00
MC/DC0%0/1
$cflags ||= ""
$cflags
Truth table0%0/2
A
A= $cflags
Aresult
11
00
585 0 require File::Temp;
586 # check if MakeMaker should be used to preprocess the libs
587 0 for my $key(keys %$opt) {$opt->{lc $key} = $opt->{$key}}
588 0 ▶ my $mmprocess = exists $opt->{makemaker} && $opt->{makemaker};
Condition0%0/3
exists $opt->{'makemaker'} && $opt->{'makemaker'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt->{'makemaker'} && $opt->{'makemaker'}
exists $opt->{'makemaker'} $opt->{'makemaker'}
Truth table0%0/3
A && B
A= exists $opt->{'makemaker'}B= $opt->{'makemaker'}
ABresult
0X0
100
111
589 0 ▶ my $hide = $opt->{hide} // $ENV{HIDE_TRYLINK} // 1;
Condition0%0/5
($opt->{"hide"} // $ENV{"HIDE_TRYLINK"}) // 1
l!l
00
$opt->{"hide"} // $ENV{"HIDE_TRYLINK"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($opt->{"hide"} // $ENV{"HIDE_TRYLINK"}) // 1
$opt->{"hide"} $ENV{"HIDE_TRYLINK"}
Truth table0%0/3
A // B
A= $opt->{"hide"}B= $ENV{"HIDE_TRYLINK"}
ABresult
1X1
011
000
590 0 ▶ my $clean = exists $opt->{clean} ? $opt->{clean} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'clean'} ? : 0 0 0
591 0 ▶ if ($mmprocess) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mmprocess) 0 0 0
592 0 require ExtUtils::MakeMaker;
593 0 require ExtUtils::Liblist;
594 0 my $self = ExtUtils::MakeMaker->new({DIR => [],'NAME' => 'NONE'});
595 0 my @libs = $self->ext($libs, 0);
596 0 ▶ print "processed LIBS: $libs[0]\n" unless $hide;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide 0 0 0
597 0 $libs = $libs[0]; # replace by preprocessed libs
598 }
599 0 ▶ print " Trying $txt...\n " if $txt =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $txt =~ /\S/ 0 0 0
600 0 ▶ my $HIDE = !$hide ? '' : '>/dev/null 2>&1';
Branch: 1 branch
BranchTrueFalseTotal
!$hide ? : 0 0 0
601 0 ▶ if($^O =~ /mswin32/i) {$HIDE = '>NUL 2>&1'}
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /mswin32/i) 0 0 0
602 0 ▶ my $tempd = File::Temp::tempdir(CLEANUP=>1) || die "trylink: could not make temp dir";
Condition0%0/2
File::Temp::tempdir('CLEANUP', 1) || die('trylink: could not make temp dir')
l!l
00
MC/DC0%0/1
File::Temp::tempdir('CLEANUP', 1) || die('trylink: could not make temp dir')
File::Temp::tempdir('CLEANUP', 1)
Truth table0%0/2
A
A= File::Temp::tempdir('CLEANUP', 1)
Aresult
11
00
603 0 my ($tc,$te) = map catfile($tempd,"testfile$_"), ('.c','');
604 0 ▶ open FILE,">$tc" or die "trylink: couldn't open testfile `$tc' for writing, $!";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$tc" or die "trylink: couldn't open testfile `${tc}' for writing, $!" 0 0 0
605 0 my $prog = <<"EOF";
606 $inc
607 int main(void) {
608 $body
609 return 0;
610 }
611 EOF
612 0 print FILE $prog;
613 0 close FILE;
614 # print "test prog:\n$prog\n";
615 # make sure we can overwrite the executable. shouldn't need this,
616 # but if it fails and HIDE is on, the user will never see the error.
617 0 ▶ open(T, ">$te") or die( "unable to write to test executable `$te'");
Branch: 1 branch
BranchTrueFalseTotal
open T, ">$te" or die "unable to write to test executable `${te}'" 0 0 0
618 0 close T;
619 0 my $cmd = "$Config{cc} $cflags -o $te $tc $libs $HIDE";
620 0 ▶ print "$cmd ...\n" unless $hide;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide 0 0 0
621 0 ▶ my $success = (system($cmd) == 0) && -e $te ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
system($cmd) == 0 && -e $te ? : 0 0 0
Condition0%0/3
system($cmd) == 0 and -e $te
!ll&&!rl&&r
000
MC/DC0%0/2
system($cmd) == 0 and -e $te
system($cmd) == 0 -e $te
Truth table0%0/3
A and B
A= system($cmd) == 0B= -e $te
ABresult
0X0
100
111
622 0 ▶ unlink $te, $tc if $clean;
Branch: 1 branch
BranchTrueFalseTotal
if $clean 0 0 0
623 0 ▶ print $success ? "\t\tYES\n" : "\t\tNO\n" unless $txt =~ /^\s*$/;
Branch: 2 branches
BranchTrueFalseTotal
unless $txt =~ /^\s*$/ 0 0 0
$success ? : 0 0 0
624 0 ▶ print $success ? "\t\tSUCCESS\n" : "\t\tFAILED\n"
Branch: 2 branches
BranchTrueFalseTotal
if $txt =~ /^\s*$/ and not $hide 0 0 0
$success ? : 0 0 0
Condition0%0/3
$txt =~ /^\s*$/ and not $hide
!ll&&!rl&&r
000
MC/DC0%0/2
$txt =~ /^\s*$/ and not $hide
$txt =~ /^\s*$/ not $hide
Truth table0%0/3
A and not(B)
A= $txt =~ /^\s*$/B= not $hide
ABresult
0X0
100
111
625 if $txt =~ /^\s*$/ && !$hide;
626 0 return $success;
627 }
628  
629 sub get_maths_libs {
630 0 ▶ return '' if $^O =~ /MSWin/;
Subroutine get_maths_libs: not called CC=13 SCAR=52.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /MSWin/ 0 0 0
631 0 ▶ return getcyglib('m') if $^O =~ /cygwin/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /cygwin/ 0 0 0
632 0 ▶ return '-lm' if !($^O eq 'solaris' or $^O eq 'sunos');
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "solaris" or $^O eq "sunos" 0 0 0
Condition0%0/3
$^O eq "solaris" or $^O eq "sunos"
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O eq "solaris" or $^O eq "sunos"
$^O eq "solaris" $^O eq "sunos"
Truth table0%0/3
A or B
A= $^O eq "solaris"B= $^O eq "sunos"
ABresult
1X1
011
000
633 0 my $libs = '-lm';
634 # try to guess where sunmath is
635 0 my @d = split /:+/, $ENV{LD_LIBRARY_PATH};
636 0 my $ok = 0;
637 0 for my $d (@d) {
638 0 ▶ if (-e "$d/libsunmath.so" or -e "$d/libsunmath.a" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$d/libsunmath.so" or -e "$d/libsunmath.a") 0 0 0
Condition0%0/3
-e "$d/libsunmath.so" or -e "$d/libsunmath.a"
l!l&&r!l&&!r
000
MC/DC0%0/2
-e "$d/libsunmath.so" or -e "$d/libsunmath.a"
-e "$d/libsunmath.so" -e "$d/libsunmath.a"
Truth table0%0/3
A or B
A= -e "$d/libsunmath.so"B= -e "$d/libsunmath.a"
ABresult
1X1
011
000
639 0 $libs = "-lsunmath $libs";
640 0 $ok = 1;
641 0 last;
642 }
643 }
644 0 ▶ return $libs if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
645 0 print "libsunmath not found in LD_LIBRARY_PATH: looking elsewhere\n";
646 # get root directory of compiler; may be off of there
647 0 require File::Which;
648 0 my @dirs = map dirname($_).'/lib', grep defined, scalar File::Which::which($Config{cc});
649 0 push @dirs, '/opt/SUNWspro/lib'; # default location if all else fails
650 0 for my $d ( @dirs ) {
651 0 ▶ if (-e "$d/libsunmath.so") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$d/libsunmath.so") 0 0 0
652 0 $libs = "-R$d -L$d -lsunmath $libs";
653 0 $ok = 1;
654 0 last;
655 }
656 0 ▶ if (-e "$d/libsunmath.a") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$d/libsunmath.a") 0 0 0
657 0 $libs = "-L$d -lsunmath $libs";
658 0 $ok = 1;
659 0 last;
660 }
661 }
662 0 ▶ print <<'EOF' if !$ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
663 Couldn't find sunmath library in standard places
664 If you can find libsunmath.a or libsunmath.so
665 please let us know at pdl-devel@lists.sourceforge.net
666 EOF
667 0 $libs;
668 }
669  
670 =head2 generate_core_flags
671  
672 =for ref
673  
674 prints on C<STDOUT> XS text with core flags, for F<Core.xs>.
675  
676 =cut
677  
678 7 my %flags = (
679 hdrcpy => { set => 1 },
680 fflows => { FLAG => "DATAFLOW_F" },
681 is_readonly => { FLAG => "READONLY" },
682 is_inplace => { FLAG => "INPLACE", postset => 1 },
683 set_inplace => { FLAG => "INPLACE", noret => 1 },
684 donttouch => { FLAG => "DONTTOUCHDATA" },
685 allocated => { },
686 vaffine => { FLAG => "OPT_VAFFTRANSOK" },
687 anychgd => { FLAG => "ANYCHANGED" },
688 datachgd => { FLAG => "PARENTDATACHANGED" },
689 dimschgd => { FLAG => "PARENTDIMSCHANGED" },
690 );
691  
692 sub generate_core_flags {
693 # access (read, if set is true then write as well; if postset true then
694 # read first and write new value after that)
695 # to ndarray's state
696 1 ▶ foreach my $name ( sort keys %flags ) {
Subroutine generate_core_flags: called CC=12 SCAR=24.9
Pod documented
697 11 ▶ my $flag = "PDL_" . ($flags{$name}{FLAG} || uc($name));
Condition66%2/3
$flags{$name}{'FLAG'} || uc $name
l!l&&r!l&&!r
920
MC/DC0%0/2
$flags{$name}{'FLAG'} || uc $name
$flags{$name}{'FLAG'} uc $name
Truth table66%2/3
A || B
A= $flags{$name}{'FLAG'}B= uc $name
ABresult
1X1
011
000
698 11 my $ref = $flags{$name};
699 11 my $with_mode = grep $ref->{$_}, qw(set postset noret);
700 11 ▶ my $mode_dflt = (grep $ref->{$_}, qw(set postset)) ? "=0" : "";
Branch: 1 branch
BranchTrueFalseTotal
grep($ref->{$_}, ('set', 'postset')) ? : 2 9 11
701 11 ▶ my @mode = $with_mode ? (",mode$mode_dflt", "\n int mode") : ('', '');
Branch: 1 branch
BranchTrueFalseTotal
$with_mode ? : 3 8 11
702 11 ▶ printf <<'EOF', $ref->{noret} ? 'void' : 'int', $name, @mode;
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'noret'} ? : 1 10 11
703 %s
704 %s(x%s)
705 pdl *x%s
706 CODE:
707 EOF
708 11 ▶ my $cond = $ref->{noret} ? "" : "if (items>1) ";
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'noret'} ? : 1 10 11
709 11 my $set = " ${cond}setflag(x->state,$flag,mode);\n";
710 11 my $ret = " RETVAL = ((x->state & $flag) > 0);\n";
711 11 ▶ print $set if $ref->{set} || $ref->{noret};
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"set"} or $ref->{"noret"} 2 9 11
Condition100%3/3
$ref->{"set"} or $ref->{"noret"}
l!l&&r!l&&!r
119
MC/DC100%2/2
$ref->{"set"} or $ref->{"noret"}
$ref->{"set"} $ref->{"noret"}
Truth table100%3/3
A or B
A= $ref->{"set"}B= $ref->{"noret"}
ABresult
1X1
011
000
712 11 ▶ print $ret if !$ref->{noret};
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->{"noret"} 10 1 11
713 11 ▶ print $set if $ref->{postset};
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"postset"} 1 10 11
714 11 ▶ print " OUTPUT:\n RETVAL\n" if !$ref->{noret};
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->{"noret"} 10 1 11
715 11 print "\n";
716 } # foreach: keys %flags
717 }
718  
719 =head2 got_complex_version
720  
721 =for ref
722  
723 PDL::Core::Dev::got_complex_version($func_name, $num_params)
724  
725 For a given function appearing in C99's C<complex.h>, will return a
726 boolean of whether the system being compiled on has the complex version
727 of that. E.g. for C<sin>, will test whether C<csinl> exists (before 2.069,
728 would only check for C<csin>, causing build failures on non-C99 compliant
729 C<libc> which mandates long-double versions).
730  
731 =cut
732  
733 7 my %got_complex_cache;
734 sub got_complex_version {
735 2 ▶ my ($name, $params) = @_;
Subroutine got_complex_version: called CC=3 SCAR=11.4
Pod documented
736 2 ▶ return $got_complex_cache{$name} if defined $got_complex_cache{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $got_complex_cache{$name} 0 2 2
737 2 my $args = join ',', ('(double complex)1') x $params;
738 $got_complex_cache{$name} = Devel::CheckLib::check_lib(
739 2 ▶ ($Config{gccversion} ? (ccflags => '-O0') : ()), # stop GCC optimising test code away
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Core::Dev::Config{'gccversion'} ? : 2 0 2
740 lib => 'm',
741 header => 'complex.h',
742 function => sprintf('double num; num = creal(c%sl(%s)); return 0;', $name, $args),
743 );
744 }
745  
746 7 1;
« lib/PDL/IO/Misc.pd ↑ Summary blib/lib/PDL/IO/FlexRaw.pm »