lib/PDL/Core/Dev.pm

filter: Statementstmt 40.8% 123 / 301 Branchbran 22.9% 33 / 144 Conditioncond 18.8% 16 / 85 MC/DCmcdc 10.4% 5 / 48 Subroutinesub 71.4% 25 / 35 Podpod 17.3% 4 / 23 totaltotal 32.3% 206 / 636 CC 115 SCAR 55.6
CC
115
Cov
32%
trylink
650.0
pdlpp_mkgen
506.0
pdlpp_eumm_update_deep
420.0
CRAP 259.8
« 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 B<As of 2.106> please note that if you have a pure-Perl top-level
109 driving module, like L<PDL::Graphics::TriD> or L<PDL::LinearAlgebra>,
110 that top-level module's C<FUNCTIONS> will be added to the C<pdldoc>
111 documentation, by the above incantation, without further addition
112 by you. If it has a C<pdldoc_add> call, that will be silently and
113 correctly handled.
114  
115 If you have a B<pure Perl> distribution, you will need:
116  
117 sub postamble { ::pdldoc_add() }
118  
119 =head1 FUNCTIONS
120  
121 =cut
122  
123 # Stuff used in development/install environment of PDL Makefile.PL's
124 # - not part of PDL itself.
125  
126 package PDL::Core::Dev;
127  
128 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 13 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 13 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 13 require Exporter;
133 13 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 13 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 13 eval { require Devel::CheckLib };
136  
137 13 our @ISA = qw( Exporter );
138  
139 13 our @EXPORT = qw( isbigendian
140 PDL_INCLUDE PDL_TYPEMAP
141 PDL_AUTO_INCLUDE PDL_BOOT
142 PDL_INST_INCLUDE PDL_INST_TYPEMAP
143 pdlpp_eumm_update_deep pdldoc_add doc_distro
144 pdlpp_postamble_int pdlpp_stdargs_int
145 pdlpp_postamble pdlpp_stdargs write_dummy_make
146 unsupported trylink get_maths_libs
147 pdlpp_mkgen
148 got_complex_version
149 );
150  
151 # Installation locations
152 7 ▶sub PDL_INCLUDE { '"-I'.catdir(whereami_any(), 'Core').'"' }
Subroutine PDL_INCLUDE: called CC=1 SCAR=0.0
Pod undocumented
153 11 ▶sub PDL_TYPEMAP { catfile(whereami_any(), qw(Core typemap)) }
Subroutine PDL_TYPEMAP: called CC=1 SCAR=0.0
Pod undocumented
154  
155 # The INST are here still just in case we want to change something later.
156 13 *PDL_INST_INCLUDE = \&PDL_INCLUDE;
157 13 *PDL_INST_TYPEMAP = \&PDL_TYPEMAP;
158  
159 1 ▶sub PDL_AUTO_INCLUDE {
Subroutine PDL_AUTO_INCLUDE: called CC=2 SCAR=7.1
Pod undocumented
160 1 my ($symname) = @_;
161 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
162 1 return << "EOR";
163 #include <pdlcore.h>
164 static Core* $symname; /* Structure holds core C functions */
165 EOR
166 }
167  
168 5 ▶sub PDL_BOOT {
Subroutine PDL_BOOT: called CC=3 SCAR=11.4
Pod undocumented
169 5 my ($symname, $module) = @_;
170 5 ▶ $symname ||= 'PDL';
Condition50%1/2
$symname ||= "PDL"
l!l
50
MC/DC0%0/1
$symname ||= "PDL"
$symname
Truth table50%1/2
A
A= $symname
Aresult
11
00
171 5 ▶ $module ||= 'The code';
Condition50%1/2
$module ||= "The code"
l!l
50
MC/DC0%0/1
$module ||= "The code"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
172 5 return << "EOR";
173 perl_require_pv ("PDL/Core.pm"); /* make sure PDL::Core is loaded */
174 #ifndef aTHX_
175 #define aTHX_
176 #endif
177 if (SvTRUE (ERRSV)) Perl_croak(aTHX_ "%s",SvPV_nolen (ERRSV));
178 SV* CoreSV = perl_get_sv("PDL::SHARE",FALSE); /* var with core structure */
179 if (!CoreSV)
180 Perl_croak(aTHX_ "We require the PDL::Core module, which was not found");
181 if (!($symname = INT2PTR(Core*,SvIV( CoreSV )))) /* Core* value */
182 Perl_croak(aTHX_ "Got NULL pointer for $symname");
183 if ($symname->Version != PDL_CORE_VERSION)
184 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);
185 EOR
186 }
187  
188 13 ▶use Cwd qw/abs_path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 13 my $MY_FILE = abs_path(__FILE__); # capture at load-time because EUMM chdirs
190 13 my $MY_DIR2 = dirname(dirname($MY_FILE));
191 25 ▶sub whereami_any { $MY_DIR2 } # something containing "Core/Dev.pm"
Subroutine whereami_any: called CC=1 SCAR=0.0
Pod undocumented
192  
193 =head2 isbigendian
194  
195 =for ref
196  
197 Is the machine big or little endian?
198  
199 =for example
200  
201 print "Your machins is big endian.\n" if isbigendian();
202  
203 returns 1 if the machine is big endian, 0 if little endian,
204 or dies if neither. It uses the C<byteorder> element of
205 perl's C<%Config> array.
206  
207 =for usage
208  
209 my $retval = isbigendian();
210  
211 =cut
212  
213 # ' emacs parsing dummy
214  
215 # big/little endian?
216 0 ▶sub isbigendian {
Subroutine isbigendian: not called CC=6 SCAR=37.4
Pod documented
217 my $byteorder = $Config{byteorder} ||
218 0 ▶ die "ERROR: Unable to find 'byteorder' in perl's Config\n";
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
219 0 ▶ return 1 if $byteorder eq "4321";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 4321 0 0 0
220 0 ▶ return 1 if $byteorder eq "87654321";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 87654321 0 0 0
221 0 ▶ return 0 if $byteorder eq "1234";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 1234 0 0 0
222 0 ▶ return 0 if $byteorder eq "12345678";
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder eq 12345678 0 0 0
223 0 die "ERROR: PDL does not understand your machine's byteorder ($byteorder)\n";
224 }
225  
226 3 ▶sub _oneliner {
Subroutine _oneliner: called CC=1 SCAR=0.0
227 3 my ($cmd, @flags) = @_;
228 3 require ExtUtils::MM;
229 3 my $MM = bless { NAME => 'Fake' }, 'MM';
230 3 $MM->oneliner($cmd, \@flags);
231 }
232  
233 # Expects list in format:
234 # [gtest.pd, GTest, PDL::GTest[, PDL::XSPkg] ], [...]
235 # source, prefix,module/package, optional pp_addxs destination
236 # The idea is to support in future several packages in same dir - EUMM
237 # 7.06 supports
238  
239 13 my %flist_cache;
240 3 ▶sub _pp_call_arg {
Subroutine _pp_call_arg: called CC=1 SCAR=0.0
241 3 "-MPDL::PP=".join ',', @_
242 }
243 3 ▶sub _postamble {
Subroutine _postamble: called CC=7 SCAR=20.1
244 3 my ($w, $internal, $src, $base, $mod, $callpack, $multi_c, $deep) = @_;
245 3 ▶ $callpack //= '';
Condition100%2/2
$callpack //= ""
l!l
21
MC/DC100%1/1
$callpack //= ""
$callpack
Truth table100%2/2
A
A= $callpack
Aresult
11
00
246 3 $w = dirname($w);
247 3 my $perlrun = "\$(PERLRUN) \"-I$w\"";
248 3 my ($pmdep, $pdldoc, $cdep) = ($src, doc_distro(), '');
249 3 ▶ 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)} ? : 1 2 3
Condition66%2/3
$multi_c and $flist_cache{File::Spec::Functions::rel2abs($src)}
!ll&&!rl&&r
201
MC/DC50%1/2
$multi_c and $flist_cache{File::Spec::Functions::rel2abs($src)}
$multi_c $flist_cache{File::Spec::Functions::rel2abs($src)}
Truth table66%2/3
A and B
A= $multi_cB= $flist_cache{File::Spec::Functions::rel2abs($src)}
ABresult
0X0
100
111
250 ? map "\$($_)", pdlpp_mod_vars($mod)
251 : pdlpp_mod_values($internal, $src, $base, $multi_c);
252 3 ▶ if ($internal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($internal) 0 3 3
253 0 my $ppdir = File::Spec::Functions::abs2rel(catdir($w, qw(PDL)));
254 0 ▶ $pmdep .= join ' ', '', catfile($ppdir, 'PP.pm'), glob(catfile($ppdir, 'PP/*'));
Subroutine BEGIN: called CC=1 SCAR=0.2
255 0 $cdep .= join ' ', $ppo, ':', map catfile($ppdir, qw(Core), $_),
256 qw(pdl.h pdlcore.h pdlbroadcast.h pdlmagic.h);
257 }
258 3 ▶ my $pp_call_arg = _pp_call_arg($mod, $mod, $base, $callpack, $multi_c||'',$deep||'');
Condition75%3/4
$multi_c || ''
l!l
12
$deep || ''
l!l
03
MC/DC100%1/1
$multi_c || ''
$multi_c
MC/DC0%0/1
$deep || ''
$deep
Truth table100%2/2
A
A= $multi_c
Aresult
11
00
Truth table50%1/2
A
A= $deep
Aresult
11
00
259 3 qq|
260  
261 $base.pm : $pmdep
262 $perlrun \"$pp_call_arg\" $src
263 \$(TOUCH) $base.pm
264  
265 $ppc : $base.pm
266 \$(NOECHO) \$(NOOP)
267  
268 $cdep
269 $pdldoc|
270 }
271  
272 0 ▶sub pdlpp_postamble_int {
Subroutine pdlpp_postamble_int: not called CC=1 SCAR=6.9
Pod undocumented
273 0 my $w = whereami_any();
274 0 join '', map _postamble($w, 1, @$_[0..3], 1, @$_[5..$#$_]), @_;
275 }
276  
277 # This is the function to be used outside the PDL tree.
278 # same format as pdlpp_postamble_int
279 3 ▶sub pdlpp_postamble {
Subroutine pdlpp_postamble: called CC=1 SCAR=0.0
Pod undocumented
280 3 my $w = whereami_any();
281 3 join '', map _postamble($w, 0, @$_), @_;
282 }
283  
284 13 *pdldoc_add = \&doc_distro;
285  
286 13 my $EMITTED_PDLDOC = 0;
287 3 ▶sub doc_distro {
Subroutine doc_distro: called CC=3 SCAR=12.5
Pod undocumented
288 # if Makefile.PL above, is in subdir, which doesn't have right DISTNAME
289 3 ▶ return '' if -f catfile(updir, 'Makefile.PL') or $EMITTED_PDLDOC++;
Branch: 1 branch
BranchTrueFalseTotal
if -f catfile("..", "Makefile.PL") or $EMITTED_PDLDOC++ 0 3 3
Condition33%1/3
-f catfile("..", "Makefile.PL") or $EMITTED_PDLDOC++
l!l&&r!l&&!r
003
MC/DC0%0/2
-f catfile("..", "Makefile.PL") or $EMITTED_PDLDOC++
-f catfile("..", "Makefile.PL") $EMITTED_PDLDOC++
Truth table33%1/3
A or B
A= -f catfile("..", "Makefile.PL")B= $EMITTED_PDLDOC++
ABresult
1X1
011
000
290 3 my $libdir = dirname(whereami_any());
291 # deliberate space in oneliner arg to force "" on Windows
292 3 sprintf <<'EOF', _oneliner(q{PDL::Doc::gen_db( @ARGV )}, qq{"-I$libdir"}, qw(-MPDL::Doc));
293  
294 PDL_DOC_DB = $(INST_LIB)$(DIRFILESEP)PDL$(DIRFILESEP)Pdldoc$(DIRFILESEP)$(DISTNAME).db
295  
296 pure_all :: $(PDL_DOC_DB)
297  
298 $(PDL_DOC_DB) :: pm_to_blib subdirs
299 $(NOECHO) $(ECHO) "Building documentation database for $(NAME)"
300 %s "$@" "$(INST_LIB)" script
301 EOF
302 }
303  
304 13 our %EXTRAS;
305 0 ▶sub pdlpp_eumm_update_deep {
Subroutine pdlpp_eumm_update_deep: not called CC=20 SCAR=60.4
Pod undocumented
306 0 my ($eumm) = @_;
307 0 my $pm = $eumm->{PM};
308 0 delete @$pm{grep /(?:\.(?:c|xs|bs)|\Q$Config{obj_ext}\E)$/, keys %$pm};
309 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
310 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
311 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
312 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
313 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
314 0 my $pdl_inc = PDL_INCLUDE();
315 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
316 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
317 0 my $pdl_tm = PDL_TYPEMAP();
318 0 ▶ push @$tms, $pdl_tm if !grep $_ eq $pdl_tm, @$tms;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($_ eq $pdl_tm), @$tms) 0 0 0
319 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
320 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
321 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
322 0 my $global_version = $eumm->parse_version($eumm->{VERSION_FROM});
323 0 my @pd_srcs;
324 0 for my $f (grep /\.pd$/, keys %$pm) {
325 0 delete $pm->{$f};
326 0 my $nolib = (my $base = $f =~ s/\.pd$//r) =~ s#^lib/##r;
327 0 $xs->{ "$base.xs" } = "$base.c";
328 0 my $pmfile = "$base.pm";
329 0 $pm->{$pmfile} = "\$(INST_LIB)/$nolib.pm";
330 0 my @macro_vars = pdlpp_mod_vars(my $mod = join '::', split /\//, $nolib);
331 0 @$macro{@macro_vars} = pdlpp_mod_values(1, $f, $base, 1, 1);
332 0 $eumm->{OBJECT} .= " $base\$(OBJ_EXT)";
333 0 $xsb->{$base}{OBJECT} = "\$($macro_vars[1])";
334 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
335 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
336 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
337 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
338 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
339 0 print $fh "package $mod;\nour \$VER"."SION = '$global_version';\n1;\n"; # break is so cpanm doesn't try to parse as version
340 0 close $fh;
341 0 utime $mtime - 120, $mtime - 120, $pmfile; # so is out of date
342 0 push @pd_srcs, [$f, $base, $mod, '', 1, 1];
343 0 my $clean_extra = join ' ', '', $pmfile, map "\$($_)", @macro_vars;
344 0 ▶ $clean_extra .= $EXTRAS{$f}{OBJECT} if $EXTRAS{$f}{OBJECT};
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Core::Dev::EXTRAS{$f}{"OBJECT"} 0 0 0
345 0 ▶ if (ref $eumm->{clean}{FILES}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $eumm->{'clean'}{'FILES'}) { } 0 0 0
346 0 push @{$eumm->{clean}{FILES}}, $clean_extra;
347 } else {
348 0 $eumm->{clean}{FILES} .= $clean_extra;
349 }
350 }
351 0 delete @$pm{grep /\.c$/, keys %$pm};
352 0 @pd_srcs;
353 }
354  
355 1 ▶sub pdlpp_list_functions {
Subroutine pdlpp_list_functions: called CC=3 SCAR=11.0
Pod undocumented
356 1 my ($src, $internal, $base) = @_;
357 1 my $abs_src = File::Spec::Functions::rel2abs($src);
358 1 ▶ if (!$flist_cache{$abs_src}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flist_cache{$abs_src}) 1 0 1
359 1 my $w = whereami_any();
360 1 ▶ if (!$INC{'PDL/Types.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"PDL/Types.pm"}) 1 0 1
361 1 my $typespm = catfile($w, 'Types.pm');
362 1 require $typespm;
363 1 $INC{'PDL/Types.pm'} = 1;
364 }
365 1 require ''.catfile($w, qw(PP.pm));
366 1 $::PDLBASE = $base;
367 1 $flist_cache{$abs_src} = [ PDL::PP::list_functions($src) ];
368 }
369 1 @{ $flist_cache{$abs_src} };
370 }
371  
372 2 ▶sub pdlpp_mod_vars {
Subroutine pdlpp_mod_vars: called CC=2 SCAR=7.0
Pod undocumented
373 2 my @parts = split /::/, $_[0];
374 2 ▶ shift @parts if $parts[0] eq 'PDL';
Branch: 1 branch
BranchTrueFalseTotal
if $parts[0] eq "PDL" 2 0 2
375 2 my $mangled = join '_', @parts;
376 2 map "PDL_MULTIC_${mangled}_$_", qw(C O);
377 }
378 3 ▶sub pdlpp_mod_values {
Subroutine pdlpp_mod_values: called CC=3 SCAR=11.0
Pod undocumented
379 3 my ($internal, $src, $base, $multi_c, $deep) = @_;
380 3 ▶ return ("$base.xs", "$base\$(OBJ_EXT)") if !$multi_c;
Branch: 1 branch
BranchTrueFalseTotal
unless $multi_c 2 1 3
381 1 ▶ my $cfileprefix = $deep ? "$base-" : '';
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 0 1 1
382 1 my @cbase = map $cfileprefix."pp-$_", pdlpp_list_functions($src, $internal, $base);
383 1 (join(' ', "$base.xs", map "$_.c", @cbase),
384 join(' ', map "$_\$(OBJ_EXT)", $base, @cbase));
385 }
386 3 ▶sub _stdargs {
Subroutine _stdargs: called CC=5 SCAR=16.5
387 3 my ($w, $internal, $src, $base, $mod, $callpack, $multi_c) = @_;
388 3 my ($clean, %hash) = '';
389 3 ▶ if ($multi_c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_c) { } 1 2 3
390 1 my ($mangled_c, $mangled_o) = pdlpp_mod_vars($mod);
391 1 my ($mangled_c_val, $mangled_o_val) = pdlpp_mod_values($internal, $src, $base, $multi_c);
392 1 %hash = (%hash,
393 macro => {
394 $mangled_c => $mangled_c_val, $mangled_o => $mangled_o_val,
395 },
396 OBJECT => "\$($mangled_o)",
397 );
398 1 $clean .= " \$($mangled_c)";
399 } else {
400 2 %hash = (%hash, OBJECT => "$base\$(OBJ_EXT)");
401 2 $clean .= " $base.xs";
402 }
403 3 ▶ if ($internal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($internal) 0 3 3
404 $hash{depend} = {
405 0 "$base\$(OBJ_EXT)" => File::Spec::Functions::abs2rel(catfile($w, qw(PDL Core pdlperl.h))),
406 };
407 }
408 (
409 3 ▶ NAME => $mod,
Branch: 2 branches
BranchTrueFalseTotal
$internal ? : 0 3 3
$internal ? : 0 3 3
410 VERSION_FROM => ($internal ? catfile($w, qw(PDL Core.pm)) : $src),
411 TYPEMAPS => [PDL_TYPEMAP()],
412 PM => {"$base.pm" => "\$(INST_LIBDIR)/$base.pm"},
413 MAN3PODS => {"$base.pm" => "\$(INST_MAN3DIR)/$mod.\$(MAN3EXT)"},
414 INC => PDL_INCLUDE(),
415 LIBS => [''],
416 clean => {FILES => "$base.pm $base.c$clean"},
417 %hash,
418 ($internal
419 ? (NO_MYMETA => 1)
420 : (dist => {PREOP => '$(PERLRUNINST) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' })
421 ),
422 );
423 }
424  
425 0 ▶sub pdlpp_stdargs_int {
Subroutine pdlpp_stdargs_int: not called CC=1 SCAR=6.9
Pod undocumented
426 0 _stdargs(dirname($MY_DIR2), 1, @{$_[0]}[0..3], 1);
427 }
428  
429 3 ▶sub pdlpp_stdargs {
Subroutine pdlpp_stdargs: called CC=1 SCAR=0.0
Pod undocumented
430 3 _stdargs(undef, 0, @{$_[0]});
431 }
432  
433 # pdlpp_mkgen($dir)
434 # - scans $dir/MANIFEST for all *.pd files and creates corresponding *.pm files
435 # in $dir/GENERATED/ subdir; needed for proper doc rendering at metacpan.org
436 # - it is used in Makefile.PL like:
437 # dist => { PREOP=>'$(PERL) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' }
438 # so all the magic *.pm generation happens during "make dist"
439 # - it is intended to be called as a one-liner:
440 # perl -MPDL::Core::Dev -e pdlpp_mkgen DirName
441 # - it relies on finding "=head1 NAME" and the module name in *.pd, though can be in comment
442 #
443 0 ▶sub pdlpp_mkgen {
Subroutine pdlpp_mkgen: not called CC=22 SCAR=62.3
Pod undocumented
444 0 require File::Copy;
445 0 require ExtUtils::Manifest;
446 0 ▶ my $dir = @_ > 0 ? $_[0] : $ARGV[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 ? : 0 0 0
447 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
448 0 my $file = "$dir/MANIFEST";
449 0 ▶ die "pdlpp_mkgen: non-existing '$file\'" unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
450 0 my @pairs = ();
451 0 my $manifest = ExtUtils::Manifest::maniread($file);
452 0 ▶ for (grep !/^(t|xt)\// && /\.(?:pd|pod\.PL)$/ && -f, sort keys %$manifest) {
Condition0%0/6
!m[^(t|xt)/] && /\.(?:pd|pod\.PL)$/ && -f $_
!ll&&!rl&&r
000
not m[^(t|xt)/] and /\.(?:pd|pod\.PL)$/
!ll&&!rl&&r
000
MC/DC0%0/3
!m[^(t|xt)/] && /\.(?:pd|pod\.PL)$/ && -f $_
not m[^(t|xt)/] /\.(?:pd|pod\.PL)$/ -f $_
Truth table0%0/4
not(A) and B && C
A= not m[^(t|xt)/]B= /\.(?:pd|pod\.PL)$/C= -f $_
ABCresult
0XX0
10X0
1100
1111
453 0 my $content = do { local $/; open my $in, '<', $_; <$in> };
454 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
455 if !(my ($name) = $content =~ /=head1\s+NAME\s+(\S+)\s+/sg);
456 0 push @pairs, [$_, $name];
457 }
458 0 my %added = ();
459 0 my @in = map "-I".File::Spec::Functions::rel2abs($_), @INC;
460 0 for (@pairs) {
461 0 my ($pd, $mod) = @$_;
462 0 (my $prefix = $mod) =~ s|::|/|g;
463 0 my $outfile = File::Spec::Functions::rel2abs("$dir/GENERATED/$prefix.pm");
464 0 File::Path::mkpath(dirname($outfile));
465 0 ▶ if ($pd =~ /\.pod\.PL$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pd =~ /\.pod\.PL$/) { } 0 0 0
466 0 my $rv = system $^X, @in, $pd, $outfile;
467 0 ▶ die "pdlpp_mkgen: cannot extract '$pd'\n" unless $rv == 0 && -f $outfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $rv == 0 and -f $outfile 0 0 0
Condition0%0/3
$rv == 0 and -f $outfile
!ll&&!rl&&r
000
MC/DC0%0/2
$rv == 0 and -f $outfile
$rv == 0 -f $outfile
Truth table0%0/3
A and B
A= $rv == 0B= -f $outfile
ABresult
0X0
100
111
468 } else {
469 0 my $old_cwd = Cwd::cwd();
470 0 my $maybe_lib_base = "lib/$prefix";
471 0 my $maybe_lib_path = "$maybe_lib_base.pd";
472 0 my $is_lib_path = substr($pd, -length $maybe_lib_path) eq $maybe_lib_path;
473 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
474 0 ▶ chdir $todir if $todir;
Branch: 1 branch
BranchTrueFalseTotal
if $todir 0 0 0
475 0 ▶ my $basename = $is_lib_path ? $maybe_lib_base : (split '/', $prefix)[-1];
Branch: 1 branch
BranchTrueFalseTotal
$is_lib_path ? : 0 0 0
476 0 my $pp_call_arg = _pp_call_arg($mod, $mod, $basename, '', 0); # 0 so guarantee not create pp-*.c
477 #there is no way to use PDL::PP from perl code, thus calling via system()
478 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
479 0 my $basefile = "$basename.pm";
480 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
481 0 ▶ File::Copy::copy($basefile, $outfile) or die "$outfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy($basefile, $outfile) or die "${outfile}: $!" 0 0 0
482 0 unlink $basefile; # Transform::Proj4.pm is wrong without GIS::Proj built
483 0 unlink "$basename.xs"; # since may have been recreated wrong
484 0 ▶ chdir $old_cwd or die "chdir $old_cwd: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $old_cwd or die "chdir ${old_cwd}: $!" 0 0 0
485 }
486 0 $added{"GENERATED/$prefix.pm"} = "mod=$mod pd=$pd (added by pdlpp_mkgen)";
487 }
488 0 ▶ if (scalar(keys %added) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %added > 0) 0 0 0
489 #maniadd works only with this global variable
490 0 local $ExtUtils::Manifest::MANIFEST = $file;
491 0 ExtUtils::Manifest::maniadd(\%added);
492 }
493 }
494  
495 0 ▶sub unsupported {
Subroutine unsupported: not called CC=1 SCAR=6.9
Pod undocumented
496 0 my ($package,$os) = @_;
497 0 "No support for $package on $os platform yet. Will skip build process";
498 }
499  
500 0 ▶sub write_dummy_make {
Subroutine write_dummy_make: not called CC=1 SCAR=6.9
Pod undocumented
501 0 my ($msg) = @_;
502 0 $msg =~ s#\n*\z#\n#;
503 0 $msg =~ s#^\s*#\n#gm;
504 0 print $msg;
505 0 require ExtUtils::MakeMaker;
506 0 ExtUtils::MakeMaker::WriteEmptyMakefile(NAME => 'Dummy', DIR => []);
507 }
508  
509 0 ▶sub getcyglib {
Subroutine getcyglib: not called CC=1 SCAR=6.9
Pod undocumented
510 0 my ($lib) = @_;
511 0 my $lp = `gcc -print-file-name=lib$lib.a`;
512 0 $lp =~ s|/[^/]+$||;
513 0 $lp =~ s|^([a-z,A-Z]):|//$1|g;
514 0 return "-L$lp -l$lib";
515 }
516  
517 =head2 trylink
518  
519 =for ref
520  
521 a perl configure clone
522  
523 =for example
524  
525 if (trylink 'libGL', '', 'char glBegin(); glBegin();', '-lGL') {
526 $libs = '-lGLU -lGL';
527 $have_GL = 1;
528 } else {
529 $have_GL = 0;
530 }
531 $maybe =
532 trylink 'libwhatever', '', $body, $libs, $cflags,
533 {MakeMaker=>1, Hide=>0, Clean=>1};
534  
535 Try to link some C-code making up the body of a function
536 with a given set of library specifiers
537  
538 return 1 if successful, 0 otherwise
539  
540 =for usage
541  
542 trylink $infomsg, $include, $progbody, $libs [,$cflags,{OPTIONS}];
543  
544 Takes 4 + 2 optional arguments.
545  
546 =over 5
547  
548 =item *
549  
550 an informational message to print (can be empty)
551  
552 =item *
553  
554 any commands to be included at the top of the generated C program
555 (typically something like C<#include "mylib.h">)
556  
557 =item *
558  
559 the body of the program (in function main)
560  
561 =item *
562  
563 library flags to use for linking. Preprocessing
564 by MakeMaker should be performed as needed (see options and example).
565  
566 =item *
567  
568 compilation flags. For example, something like C<-I/usr/local/lib>.
569 Optional argument. Empty if omitted.
570  
571 =item *
572  
573 OPTIONS
574  
575 =over
576  
577 =item MakeMaker
578  
579 Preprocess library strings in the way MakeMaker does things. This is
580 advisable to ensure that your code will actually work after the link
581 specs have been processed by MakeMaker.
582  
583 =item Hide
584  
585 Controls if linking output etc is hidden from the user or not.
586 On by default but overridable with environment variable C<HIDE_TRYLINK> if set.
587  
588 =item Clean
589  
590 Remove temporary files. Enabled by default. You might want to switch
591 it off during debugging.
592  
593 =back
594  
595 =back
596  
597 =cut
598  
599 0 ▶sub trylink {
Subroutine trylink: not called CC=25 SCAR=64.8
Pod documented
600 0 ▶ my $opt = ref $_[$#_] eq 'HASH' ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[$#_] eq 'HASH' ? : 0 0 0
601 0 my ($txt,$inc,$body,$libs,$cflags) = @_;
602 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
603 0 require File::Temp;
604 # check if MakeMaker should be used to preprocess the libs
605 0 for my $key(keys %$opt) {$opt->{lc $key} = $opt->{$key}}
606 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
607 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
608 0 ▶ my $clean = exists $opt->{clean} ? $opt->{clean} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'clean'} ? : 0 0 0
609 0 ▶ if ($mmprocess) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mmprocess) 0 0 0
610 0 require ExtUtils::MakeMaker;
611 0 require ExtUtils::Liblist;
612 0 my $self = ExtUtils::MakeMaker->new({DIR => [],'NAME' => 'NONE'});
613 0 my @libs = $self->ext($libs, 0);
614 0 ▶ print "processed LIBS: $libs[0]\n" unless $hide;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide 0 0 0
615 0 $libs = $libs[0]; # replace by preprocessed libs
616 }
617 0 ▶ print " Trying $txt...\n " if $txt =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $txt =~ /\S/ 0 0 0
618 0 ▶ my $HIDE = !$hide ? '' : '>/dev/null 2>&1';
Branch: 1 branch
BranchTrueFalseTotal
!$hide ? : 0 0 0
619 0 ▶ if($^O =~ /mswin32/i) {$HIDE = '>NUL 2>&1'}
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /mswin32/i) 0 0 0
620 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
621 0 my ($tc,$te) = map catfile($tempd,"testfile$_"), ('.c','');
622 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
623 0 my $prog = <<"EOF";
624 $inc
625 int main(void) {
626 $body
627 return 0;
628 }
629 EOF
630 0 print FILE $prog;
631 0 close FILE;
632 # print "test prog:\n$prog\n";
633 # make sure we can overwrite the executable. shouldn't need this,
634 # but if it fails and HIDE is on, the user will never see the error.
635 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
636 0 close T;
637 0 my $cmd = "$Config{cc} $cflags -o $te $tc $libs $HIDE";
638 0 ▶ print "$cmd ...\n" unless $hide;
Branch: 1 branch
BranchTrueFalseTotal
unless $hide 0 0 0
639 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
640 0 ▶ unlink $te, $tc if $clean;
Branch: 1 branch
BranchTrueFalseTotal
if $clean 0 0 0
641 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
642 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
643 if $txt =~ /^\s*$/ && !$hide;
644 0 return $success;
645 }
646  
647 0 ▶sub get_maths_libs {
Subroutine get_maths_libs: not called CC=13 SCAR=52.0
Pod undocumented
648 0 ▶ return '' if $^O =~ /MSWin/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /MSWin/ 0 0 0
649 0 ▶ return getcyglib('m') if $^O =~ /cygwin/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /cygwin/ 0 0 0
650 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
651 0 my $libs = '-lm';
652 # try to guess where sunmath is
653 0 my @d = split /:+/, $ENV{LD_LIBRARY_PATH};
654 0 my $ok = 0;
655 0 for my $d (@d) {
656 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
657 0 $libs = "-lsunmath $libs";
658 0 $ok = 1;
659 0 last;
660 }
661 }
662 0 ▶ return $libs if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
663 0 print "libsunmath not found in LD_LIBRARY_PATH: looking elsewhere\n";
664 # get root directory of compiler; may be off of there
665 0 require File::Which;
666 0 my @dirs = map dirname($_).'/lib', grep defined, scalar File::Which::which($Config{cc});
667 0 push @dirs, '/opt/SUNWspro/lib'; # default location if all else fails
668 0 for my $d ( @dirs ) {
669 0 ▶ if (-e "$d/libsunmath.so") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$d/libsunmath.so") 0 0 0
670 0 $libs = "-R$d -L$d -lsunmath $libs";
671 0 $ok = 1;
672 0 last;
673 }
674 0 ▶ if (-e "$d/libsunmath.a") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$d/libsunmath.a") 0 0 0
675 0 $libs = "-L$d -lsunmath $libs";
676 0 $ok = 1;
677 0 last;
678 }
679 }
680 0 ▶ print <<'EOF' if !$ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
681 Couldn't find sunmath library in standard places
682 If you can find libsunmath.a or libsunmath.so
683 please let us know at pdl-devel@lists.sourceforge.net
684 EOF
685 0 $libs;
686 }
687  
688 =head2 generate_core_flags
689  
690 =for ref
691  
692 prints on C<STDOUT> XS text with core flags, for F<Core.xs>.
693  
694 =cut
695  
696 13 my %flags = (
697 hdrcpy => { set => 1 },
698 fflows => { FLAG => "DATAFLOW_F" },
699 is_readonly => { FLAG => "READONLY" },
700 is_inplace => { FLAG => "INPLACE", postset => 1 },
701 set_inplace => { FLAG => "INPLACE", noret => 1 },
702 donttouch => { FLAG => "DONTTOUCHDATA" },
703 allocated => { },
704 vaffine => { FLAG => "OPT_VAFFTRANSOK" },
705 anychgd => { FLAG => "ANYCHANGED" },
706 datachgd => { FLAG => "PARENTDATACHANGED" },
707 dimschgd => { FLAG => "PARENTDIMSCHANGED" },
708 );
709  
710 1 ▶sub generate_core_flags {
Subroutine generate_core_flags: called CC=12 SCAR=24.9
Pod documented
711 # access (read, if set is true then write as well; if postset true then
712 # read first and write new value after that)
713 # to ndarray's state
714 1 foreach my $name ( sort keys %flags ) {
715 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
716 11 my $ref = $flags{$name};
717 11 my $with_mode = grep $ref->{$_}, qw(set postset noret);
718 11 ▶ my $mode_dflt = (grep $ref->{$_}, qw(set postset)) ? "=0" : "";
Branch: 1 branch
BranchTrueFalseTotal
grep($ref->{$_}, ('set', 'postset')) ? : 2 9 11
719 11 ▶ my @mode = $with_mode ? (",mode$mode_dflt", "\n int mode") : ('', '');
Branch: 1 branch
BranchTrueFalseTotal
$with_mode ? : 3 8 11
720 11 ▶ printf <<'EOF', $ref->{noret} ? 'void' : 'int', $name, @mode;
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'noret'} ? : 1 10 11
721 %s
722 %s(x%s)
723 pdl *x%s
724 CODE:
725 EOF
726 11 ▶ my $cond = $ref->{noret} ? "" : "if (items>1) ";
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'noret'} ? : 1 10 11
727 11 my $set = " ${cond}setflag(x->state,$flag,mode);\n";
728 11 my $ret = " RETVAL = ((x->state & $flag) > 0);\n";
729 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
730 11 ▶ print $ret if !$ref->{noret};
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->{"noret"} 10 1 11
731 11 ▶ print $set if $ref->{postset};
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"postset"} 1 10 11
732 11 ▶ print " OUTPUT:\n RETVAL\n" if !$ref->{noret};
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->{"noret"} 10 1 11
733 11 print "\n";
734 } # foreach: keys %flags
735 }
736  
737 =head2 got_complex_version
738  
739 =for ref
740  
741 PDL::Core::Dev::got_complex_version($func_name, $num_params)
742  
743 For a given function appearing in C99's C<complex.h>, will return a
744 boolean of whether the system being compiled on has the complex version
745 of that. E.g. for C<sin>, will test whether C<csinl> exists (before 2.069,
746 would only check for C<csin>, causing build failures on non-C99 compliant
747 C<libc> which mandates long-double versions).
748  
749 =cut
750  
751 13 my %got_complex_cache;
752 2 ▶sub got_complex_version {
Subroutine got_complex_version: called CC=3 SCAR=11.4
Pod documented
753 2 my ($name, $params) = @_;
754 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
755 2 my $args = join ',', ('(double complex)1') x $params;
756 $got_complex_cache{$name} = Devel::CheckLib::check_lib(
757 2 ▶ ($Config{gccversion} ? (ccflags => '-O0') : ()), # stop GCC optimising test code away
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Core::Dev::Config{'gccversion'} ? : 2 0 2
758 lib => 'm',
759 header => 'complex.h',
760 function => sprintf('double num; num = creal(c%sl(%s)); return 0;', $name, $args),
761 );
762 }
763  
764 13 1;
« lib/PDL/IO/Misc.pd ↑ Summary blib/lib/PDL/IO/FlexRaw.pm »