script/ppkg-config

filter: Statementstmt 83.8% 463 / 552 Branchbran 65.5% 181 / 276 Conditioncond 64.4% 69 / 107 MC/DCmcdc 43.8% 25 / 57 Subroutinesub 84.7% 39 / 46 Podpod n/a totaltotal 74.8% 777 / 1038 CC 88 SCAR 21.7
CC
88
Cov
76%
get_list
30.0
_split_flags
20.0
version_check
20.0
CRAP 8.8
« blib/script/pkg-config.pl ↑ Summary run_test.pl »
1 #!/usr/bin/perl
2  
3 # lightweight no-dependency version of pkg-config. This will work on any machine
4 # with Perl installed.
5  
6 # Copyright (C) 2012 M. Nunberg.
7 # You may use and distribute this software under the same terms and conditions
8 # as Perl itself.
9  
10 package PkgConfig;
11  
12 #First two digits are Perl version, second two are pkg-config version
13 1122 our $VERSION = '0.26026';
14  
15 1122 $VERSION =~ /([0-9]{2})$/;
16 1122 my $compat_version = $1;
17  
18 1191 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1150 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1170 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1170 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1134 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1134 ▶use File::Glob 'bsd_glob';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1134 ▶use Class::Struct; #in core since 5.004
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1197 ▶use File::Basename qw( dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1129 ▶use Text::ParseWords qw( shellwords );
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1122 our $UseDebugging;
29  
30 ################################################################################
31 ### Check for Log::Fu ###
32 ################################################################################
33 1132 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
34 0 ▶ my $ret = eval q{
Subroutine BEGIN: called CC=1 SCAR=0.2
35 use Log::Fu 0.25 { level => "warn" };
36 1;
37 };
38  
39 1134 ▶ if(!$ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ret) 1129 0 1129
40 0 ▶ my $log_base = sub {
Subroutine __ANON__: not called CC=1 SCAR=0.0
41 5 my (@args) = @_;
42 5 print STDERR "[DEBUG] ", join(' ', @args);
43 25 print STDERR "\n";
44 1134 };
45 1134 ▶ *log_debug = *log_debugf = sub { return unless $UseDebugging; goto &$log_base };
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
unless $UseDebugging 138885 0 138885
46 1134 *log_err = *log_errf = *log_warn = *log_warnf = *log_info = *log_infof =
47 $log_base;
48  
49 }
50 }
51  
52 ################################################################################
53 ### Sane Defaults ###
54 ################################################################################
55 1122 our @DEFAULT_SEARCH_PATH = qw(
56 /usr/local/lib/pkgconfig /usr/local/share/pkgconfig
57 /usr/lib/pkgconfig /usr/share/pkgconfig
58  
59 );
60  
61 1122 our @DEFAULT_EXCLUDE_CFLAGS = qw(-I/usr/include -I/usr/local/include);
62 # don't include default link/search paths!
63 1122 our @DEFAULT_EXCLUDE_LFLAGS = map { ( "-L$_", "-R$_" ) } qw( /lib /lib32 /lib64 /usr/lib /usr/lib32 /usr/lib/64 /usr/local/lib /usr/local/lib32 /usr/local/lib64 );
64  
65 1122 ▶if($ENV{PKG_CONFIG_NO_OS_CUSTOMIZATION}) {
Branch: 13 branches
BranchTrueFalseTotal
if ($ENV{'PKG_CONFIG_NO_OS_CUSTOMIZATION'}) { } 1117 5 1122
elsif ($ENV{'PKG_CONFIG_LIBDIR'}) { } 63 4 67
elsif ($^O eq 'msys') { } 0 4 4
elsif ($^O eq 'solaris' and $PkgConfig::Config{'ptrsize'} == 8) { } 0 4 4
elsif ($^O eq 'linux' and -f '/etc/gentoo-release') { } 0 4 4
elsif ($^O =~ /^(gnukfreebsd|linux)$/ and -r '/etc/debian_version') { } 4 0 4
elsif ($^O eq 'linux' and -r '/etc/redhat-release') { } 0 41 41
elsif ($^O eq 'linux' and -r '/etc/slackware-version') { } 5 36 41
elsif ($^O eq 'freebsd') { } 32 50 82
elsif ($^O eq 'netbsd') { } 0 32 32
elsif ($^O eq 'openbsd') { } 0 50 50
elsif ($^O eq 'MSWin32') { } 0 15 15
elsif ($^O eq 'darwin') { } 0 5 5
66  
67 # use the defaults regardless of detected platform
68  
69 } elsif($ENV{PKG_CONFIG_LIBDIR}) {
70  
71 4 @DEFAULT_SEARCH_PATH = split $Config{path_sep}, $ENV{PKG_CONFIG_LIBDIR};
72  
73 } elsif($^O eq 'msys') {
74  
75 # MSYS2 seems to actually set PKG_CONFIG_PATH in its /etc/profile
76 # god bless it. But. The defaults if you unset the environment
77 # variable are different
78 3 @DEFAULT_SEARCH_PATH = qw(
79 /usr/lib/pkgconfig
80 /usr/share/pkgconfig
81 );
82  
83 ▶} elsif($^O eq 'solaris' && $Config{ptrsize} == 8) {
Condition33%1/3
$^O eq "solaris" and $PkgConfig::Config{"ptrsize"} == 8
!ll&&!rl&&r
400
MC/DC0%0/2
$^O eq "solaris" and $PkgConfig::Config{"ptrsize"} == 8
$^O eq "solaris" $PkgConfig::Config{"ptrsize"} == 8
Truth table33%1/3
A and B
A= $^O eq "solaris"B= $PkgConfig::Config{"ptrsize"} == 8
ABresult
0X0
100
111
84  
85 3 @DEFAULT_SEARCH_PATH = qw(
86 /usr/local/lib/64/pkgconfig /usr/local/share/pkgconfig
87 /usr/lib/64/pkgconfig /usr/share/pkgconfig
88 );
89  
90 ▶} elsif($^O eq 'linux' and -f '/etc/gentoo-release') {
Condition33%1/3
$^O eq "linux" and -f "/etc/gentoo-release"
!ll&&!rl&&r
0450
MC/DC0%0/2
$^O eq "linux" and -f "/etc/gentoo-release"
$^O eq "linux" -f "/etc/gentoo-release"
Truth table33%1/3
A and B
A= $^O eq "linux"B= -f "/etc/gentoo-release"
ABresult
0X0
100
111
91 # OK, we're running on Gentoo
92  
93 # Fetch ptrsize value
94 3 my $ptrsize = $Config{ptrsize};
95  
96 # Are we running on 64 bit system?
97 3 ▶ if ($ptrsize eq 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ptrsize eq 8) { } 0 5 5
98 # We do
99 3 @DEFAULT_SEARCH_PATH = qw!
100 /usr/lib64/pkgconfig/ /usr/share/pkgconfig/
101 !;
102 } else {
103 # We're running on a 32 bit system (hopefully)
104 3 @DEFAULT_SEARCH_PATH = qw!
105 /usr/lib/pkgconfig/ /usr/share/pkgconfig/
106 !;
107 }
108  
109 ▶} elsif($^O =~ /^(gnukfreebsd|linux)$/ && -r "/etc/debian_version") {
Condition100%3/3
$^O =~ /^(gnukfreebsd|linux)$/ and -r "/etc/debian_version"
!ll&&!rl&&r
16209
MC/DC100%2/2
$^O =~ /^(gnukfreebsd|linux)$/ and -r "/etc/debian_version"
$^O =~ /^(gnukfreebsd|linux)$/ -r "/etc/debian_version"
Truth table100%3/3
A and B
A= $^O =~ /^(gnukfreebsd|linux)$/B= -r "/etc/debian_version"
ABresult
0X0
100
111
110  
111 7 my $arch;
112 7 ▶ if(-x "/usr/bin/dpkg-architecture") {
Branch: 2 branches
BranchTrueFalseTotal
if (-x '/usr/bin/dpkg-architecture') { } 0 9 9
elsif (-x '/usr/bin/gcc') { } 4 0 4
113 # works if dpkg-dev is installed
114 # rt96694
115 3 ($arch) = map { chomp; (split /=/)[1] }
116 grep /^DEB_HOST_MULTIARCH=/,
117 `/usr/bin/dpkg-architecture`;
118 } elsif(-x "/usr/bin/gcc") {
119 # works if gcc is installed
120 7 $arch = `/usr/bin/gcc -dumpmachine`;
121 7 chomp $arch;
122 } else {
123 3 my $deb_arch = `dpkg --print-architecture`;
124 3 ▶ if($deb_arch =~ /^amd64/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($deb_arch =~ /^amd64/) { } 0 5 5
elsif ($deb_arch =~ /^i386/) { } 0 5 5
125 3 ▶ if($^O eq 'linux') {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'linux') { } 0 0 0
elsif ($^O eq 'gnukfreebsd') { } 0 0 0
126 3 $arch = 'x86_64-linux-gnu';
127 } elsif($^O eq 'gnukfreebsd') {
128 3 $arch = 'x86_64-kfreebsd-gnu';
129 }
130 } elsif($deb_arch =~ /^i386/) {
131 3 ▶ if($^O eq 'linux') {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'linux') { } 0 0 0
elsif ($^O eq 'gnukfreebsd') { } 20 0 20
132 3 $arch = 'i386-linux-gnu';
133 } elsif($^O eq 'gnukfreebsd') {
134 3 $arch = 'i386-kfreebsd-gnu';
135 }
136 }
137 }
138  
139 7 ▶ if($arch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arch) { } 4 0 4
140 4 ▶ if(scalar grep /--print-foreign-architectures/, `dpkg --help`)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep(/--print-foreign-architectures/, `dpkg --help`)) { } 4 6 10
141 {
142 # multi arch support / Debian 7+
143 4 @DEFAULT_SEARCH_PATH = (
144 "/usr/local/lib/$arch/pkgconfig",
145 "/usr/local/lib/pkgconfig",
146 "/usr/local/share/pkgconfig",
147 "/usr/lib/$arch/pkgconfig",
148 "/usr/lib/pkgconfig",
149 "/usr/share/pkgconfig",
150 );
151  
152 7 push @DEFAULT_EXCLUDE_LFLAGS, map { ("-L$_", "-R$_") }
153 "/usr/local/lib/$arch",
154 "/usr/lib/$arch";
155  
156 } else {
157  
158 3 @DEFAULT_SEARCH_PATH = (
159 "/usr/local/lib/pkgconfig",
160 "/usr/local/lib/pkgconfig/$arch",
161 "/usr/local/share/pkgconfig",
162 "/usr/lib/pkgconfig",
163 "/usr/lib/pkgconfig/$arch",
164 "/usr/share/pkgconfig",
165 );
166 }
167  
168 } else {
169  
170 3 @DEFAULT_SEARCH_PATH = (
171 "/usr/local/lib/pkgconfig",
172 "/usr/local/share/pkgconfig",
173 "/usr/lib/pkgconfig",
174 "/usr/share/pkgconfig",
175 );
176  
177 }
178  
179 ▶} elsif($^O eq 'linux' && -r "/etc/redhat-release") {
Condition33%1/3
$^O eq "linux" and -r "/etc/redhat-release"
!ll&&!rl&&r
0032
MC/DC0%0/2
$^O eq "linux" and -r "/etc/redhat-release"
$^O eq "linux" -r "/etc/redhat-release"
Truth table33%1/3
A and B
A= $^O eq "linux"B= -r "/etc/redhat-release"
ABresult
0X0
100
111
180  
181 3 ▶ if(-d "/usr/lib64/pkgconfig") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d '/usr/lib64/pkgconfig') { } 8 2 10
182 3 @DEFAULT_SEARCH_PATH = qw(
183 /usr/lib64/pkgconfig
184 /usr/share/pkgconfig
185 );
186 } else {
187 3 @DEFAULT_SEARCH_PATH = qw(
188 /usr/lib/pkgconfig
189 /usr/share/pkgconfig
190 );
191 }
192  
193 ▶} elsif($^O eq 'linux' && -r "/etc/slackware-version") {
Condition33%1/3
$^O eq "linux" and -r "/etc/slackware-version"
!ll&&!rl&&r
0150
MC/DC0%0/2
$^O eq "linux" and -r "/etc/slackware-version"
$^O eq "linux" -r "/etc/slackware-version"
Truth table33%1/3
A and B
A= $^O eq "linux"B= -r "/etc/slackware-version"
ABresult
0X0
100
111
194  
195 # Fetch ptrsize value
196 3 my $ptrsize = $Config{ptrsize};
197  
198 # Are we running on 64 bit system?
199 3 ▶ if ($ptrsize == 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ptrsize == 8) { } 3 0 3
200 # We do
201 3 @DEFAULT_SEARCH_PATH = qw!
202 /usr/lib64/pkgconfig/ /usr/share/pkgconfig/
203 !;
204 } else {
205 # We're running on a 32 bit system (hopefully)
206 3 @DEFAULT_SEARCH_PATH = qw!
207 /usr/lib/pkgconfig/ /usr/share/pkgconfig/
208 !;
209 }
210  
211  
212 } elsif($^O eq 'freebsd') {
213  
214 # TODO: FreeBSD 10-12's version of pkg-config does not
215 # support PKG_CONFIG_DEBUG_SPEW so I can't verify
216 # the path there.
217 3 @DEFAULT_SEARCH_PATH = qw(
218 /usr/local/libdata/pkgconfig
219 /usr/libdata/pkgconfig
220 );
221  
222 } elsif($^O eq 'netbsd') {
223  
224 3 @DEFAULT_SEARCH_PATH = qw(
225 /usr/pkg/lib/pkgconfig
226 /usr/pkg/share/pkgconfig
227 /usr/X11R7/lib/pkgconfig
228 /usr/lib/pkgconfig
229 );
230 } elsif($^O eq 'openbsd') {
231  
232 3 @DEFAULT_SEARCH_PATH = qw(
233 /usr/lib/pkgconfig
234 /usr/local/lib/pkgconfig
235 /usr/local/share/pkgconfig
236 /usr/X11R6/lib/pkgconfig
237 /usr/X11R6/share/pkgconfig
238 );
239  
240 } elsif($^O eq 'MSWin32') {
241  
242 # Caveats:
243 # 1. This pulls in Config,
244 # which we don't load on non MSWin32
245 # but it is in the core.
246 # 2. Slight semantic difference in that we are treating
247 # Strawberry as the "system" rather than Windows, but
248 # since pkg-config is rarely used in MSWin32, it is
249 # better to have something that is useful rather than
250 # worry about if it is exactly the same as other
251 # platforms.
252 # 3. It is a little brittle in that Strawberry might
253 # one day change its layouts. If it has and you are
254 # reading this, please send a pull request or simply
255 # let me know -plicease
256 3 require Config;
257 3 ▶ if($Config::Config{myuname} =~ /strawberry-perl/)
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"myuname"} =~ /strawberry-perl/) 2 1 3
258 {
259 # handle PAR::Packer executables which have $^X eq "perl.exe"
260 3 ▶ if ($ENV{PAR_0})
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'PAR_0'}) { } 0 1 1
261 {
262 3 my $path = $ENV{PAR_TEMP};
263 0 $path =~ s{\\}{/}g;
264 0 @DEFAULT_SEARCH_PATH = ($path);
265 }
266 else {
267 0 my($vol, $dir, $file) = File::Spec->splitpath($^X);
268 62 my @dirs = File::Spec->splitdir($dir);
269 0 splice @dirs, -3;
270 0 my $path = (File::Spec->catdir($vol, @dirs, qw( c lib pkgconfig )));
271 0 $path =~ s{\\}{/}g;
272 0 @DEFAULT_SEARCH_PATH = $path;
273 }
274 }
275  
276 0 my @reg_paths;
277  
278 0 eval q{
279 package
280 PkgConfig::WinReg;
281  
282 use Win32API::Registry 0.21 qw( :ALL );
283  
284 foreach my $top (HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER) {
285 my $key;
286 RegOpenKeyEx( $top, "Software\\\\pkgconfig\\\\PKG_CONFIG_PATH", 0, KEY_READ, $key) || next;
287 my $nlen = 1024;
288 my $pos = 0;
289 my $name = '';
290  
291 while(RegEnumValue($key, $pos++, $name, $nlen, [], [], [], [])) {
292 my $type;
293 my $data;
294 RegQueryValueEx($key, $name, [], $type, $data, []);
295 push @reg_paths, $data;
296 }
297  
298 RegCloseKey( $key );
299 }
300 };
301  
302 0 ▶ unless($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 1 1
303 0 unshift @DEFAULT_SEARCH_PATH, @reg_paths;
304 }
305  
306 0 ▶ if($Config::Config{cc} =~ /cl(\.exe)?$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{'cc'} =~ /cl(\.exe)?$/i) { } 0 0 0
307 {
308 0 @DEFAULT_EXCLUDE_LFLAGS = ();
309 0 @DEFAULT_EXCLUDE_CFLAGS = ();
310 }
311 else
312 {
313 0 @DEFAULT_EXCLUDE_LFLAGS = (
314 "-L/mingw/lib",
315 "-R/mingw/lib",
316 "-L/mingw/lib/pkgconfig/../../lib",
317 "-R/mingw/lib/pkgconfig/../../lib",
318 );
319 0 @DEFAULT_EXCLUDE_CFLAGS = (
320 "-I/mingw/include",
321 "-I/mingw/lib/pkgconfig/../../include",
322 );
323 }
324  
325 # See caveats above for Strawberry and PAR::Packer
326 0 require Config;
327 0 ▶ if(not $ENV{PAR_0} and $Config::Config{myuname} =~ /strawberry-perl/)
Branch: 1 branch
BranchTrueFalseTotal
if (not $ENV{"PAR_0"} and $Config::Config{"myuname"} =~ /strawberry-perl/) 6 62 68
Condition33%1/3
not $ENV{"PAR_0"} and $Config::Config{"myuname"} =~ /strawberry-perl/
!ll&&!rl&&r
050
MC/DC0%0/2
not $ENV{"PAR_0"} and $Config::Config{"myuname"} =~ /strawberry-perl/
not $ENV{"PAR_0"} $Config::Config{"myuname"} =~ /strawberry-perl/
Truth table33%1/3
not(A) and B
A= not $ENV{"PAR_0"}B= $Config::Config{"myuname"} =~ /strawberry-perl/
ABresult
0X0
100
111
328 {
329 0 my($vol, $dir, $file) = File::Spec->splitpath($^X);
330 0 my @dirs = File::Spec->splitdir($dir);
331 0 splice @dirs, -3;
332 0 my $path = (File::Spec->catdir($vol, @dirs, qw( c )));
333 0 $path =~ s{\\}{/}g;
334 0 push @DEFAULT_EXCLUDE_LFLAGS, (
335 "-L$path/lib",
336 "-L$path/lib/pkgconfig/../../lib",
337 "-R$path/lib",
338 "-R$path/lib/pkgconfig/../../lib",
339 );
340 0 push @DEFAULT_EXCLUDE_CFLAGS, (
341 "-I$path/include",
342 "-I$path/lib/pkgconfig/../../include",
343 );
344 }
345 } elsif($^O eq 'darwin') {
346  
347 0 ▶ if(-x '/usr/local/Homebrew/bin/brew') {
Branch: 1 branch
BranchTrueFalseTotal
if (-x "/usr/local/Homebrew/bin/brew") 0 62 62
348 # Mac OS X with homebrew installed
349 0 push @DEFAULT_SEARCH_PATH,
350 bsd_glob '/usr/local/opt/*/lib/pkgconfig'
351 ;
352 }
353  
354 }
355  
356 1119 ▶my @ENV_SEARCH_PATH = split($Config{path_sep}, $ENV{PKG_CONFIG_PATH} || "");
Condition100%2/2
$ENV{'PKG_CONFIG_PATH'} || ''
l!l
111510
MC/DC100%1/1
$ENV{'PKG_CONFIG_PATH'} || ''
$ENV{'PKG_CONFIG_PATH'}
Truth table100%2/2
A
A= $ENV{'PKG_CONFIG_PATH'}
Aresult
11
00
357  
358 1119 unshift @DEFAULT_SEARCH_PATH, @ENV_SEARCH_PATH;
359  
360 1119 ▶if($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 28 1153 1181
361 0 ▶ @DEFAULT_SEARCH_PATH = map { s{\\}{/}g; $_ } map { /\s/ ? Win32::GetShortPathName($_) : $_ } @DEFAULT_SEARCH_PATH;
Branch: 1 branch
BranchTrueFalseTotal
/\s/ ? : 21 41 62
362 }
363  
364 1119 ▶if($ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"}) 5 1119 1124
365 0 @DEFAULT_EXCLUDE_CFLAGS = ();
366 }
367  
368 1160 ▶if($ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PKG_CONFIG_ALLOW_SYSTEM_LIBS"}) 0 1124 1124
369 41 @DEFAULT_EXCLUDE_LFLAGS = ();
370 }
371  
372 1124 my $LD_OUTPUT_RE = qr/
373 SEARCH_DIR\("
374 ([^"]+)
375 "\)
376 /x;
377  
378 0 ▶sub GuessPaths {
Subroutine GuessPaths: not called CC=7 SCAR=26.1
379 0 my $pkg = shift;
380 0 local $ENV{LD_LIBRARY_PATH} = "";
381 0 local $ENV{C_INCLUDE_PATH} = "";
382 0 local $ENV{LD_RUN_PATH} = "";
383  
384 5 ▶ my $ld = $ENV{LD} || 'ld';
Condition0%0/3
$ENV{'LD'} || 'ld'
l!l
000
MC/DC0%0/1
$ENV{'LD'} || 'ld'
$ENV{'LD'}
Truth table0%0/2
A
A= $ENV{'LD'}
Aresult
11
00
385 5 my $ld_output = qx(ld -verbose);
386 5 my @defl_search_dirs = ($ld_output =~ m/$LD_OUTPUT_RE/g);
387  
388 0 @DEFAULT_EXCLUDE_LFLAGS = ();
389 0 foreach my $path (@defl_search_dirs) {
390 0 push @DEFAULT_EXCLUDE_LFLAGS, (map { "$_".$path }
391 (qw(-R -L -rpath= -rpath-link= -rpath -rpath-link)));
392 }
393 0 log_debug("Determined exclude LDFLAGS", @DEFAULT_EXCLUDE_LFLAGS);
394  
395 #now get the include paths:
396 41 my @cpp_output = qx(cpp --verbose 2>&1 < /dev/null);
397 5 @cpp_output = map { chomp $_; $_ } @cpp_output;
398 #log_info(join("!", @cpp_output));
399 5 ▶ while (my $cpp_line = shift @cpp_output) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cpp_line = shift @cpp_output) 0 0 0
400 5 chomp($cpp_line);
401 5 ▶ if($cpp_line =~ /\s*#include\s*<.+search starts here/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cpp_line =~ /\s*#include\s*<.+search starts here/) 0 0 0
402 1 last;
403 }
404 }
405 #log_info(@cpp_output);
406 1 my @include_paths;
407 1 ▶ while (my $path = shift @cpp_output) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = shift @cpp_output) 0 0 0
408 1 ▶ if($path =~ /\s*End of search list/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\s*End of search list/) 0 0 0
409 1 last;
410 }
411 1 push @include_paths, $path;
412 }
413 1 @DEFAULT_EXCLUDE_CFLAGS = map { "-I$_" } @include_paths;
414 1 log_debug("Determine exclude CFLAGS", @DEFAULT_EXCLUDE_CFLAGS);
415 }
416  
417  
418 ################################################################################
419 ### Define our fields ###
420 ################################################################################
421 1124 struct(
422 __PACKAGE__,
423 [
424 # .pc search paths, defaults to PKG_CONFIG_PATH in environment
425 'search_path' => '@',
426  
427 # whether to also spit out static dependencies
428 'static' => '$',
429  
430 # whether we replace references to -L and friends with -Wl,-rpath, etc.
431 'rpath' => '$',
432  
433 # build rpath-search,
434  
435 # no recursion. set if we just want a version, or to see if the
436 # package exists.
437 'no_recurse' => '$',
438  
439 #list of cflags and ldflags to exclude
440 'exclude_ldflags' => '@',
441 'exclude_cflags' => '@',
442  
443 # what level of recursion we're at
444 'recursion' => '$',
445  
446 # hash of libraries, keyed by recursion levels. Lower recursion numbers
447 # will be listed first
448 'libs_deplist' => '*%',
449  
450 # cumulative cflags and ldflags
451 'ldflags' => '*@',
452 'cflags' => '*@',
453  
454 # whether we print the c/ldflags
455 'print_cflags' => '$',
456 'print_ldflags' => '$',
457  
458 # information about our top-level package
459 'pkg' => '$',
460 'pkg_exists' => '$',
461 'pkg_version' => '$',
462 'pkg_url', => '$',
463 'pkg_description' => '$',
464 'errmsg' => '$',
465  
466 'filevars' => '*%',
467 'uservars' => '*%',
468  
469 # options for printing variables
470 'print_variables' => '$',
471 'print_variable' => '$',
472 'print_values' => '$',
473 'defined_variables' => '*%',
474  
475 # for creating PkgConfig objects with identical
476 # settings
477 'original' => '$',
478 ]
479 );
480  
481 ################################################################################
482 ################################################################################
483 ### Variable Storage ###
484 ################################################################################
485 ################################################################################
486  
487 99192 ▶sub assign_var {
Subroutine assign_var: called CC=10 SCAR=23.0
488 99152 my ($self,$field,$value,$force) = @_;
489 # if the user has provided a definition, use that.
490 99152 ▶ if (!$force && exists $self->uservars->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $force and exists $self->uservars->{$field}) 5154 93999 99153
Condition100%3/3
not $force and exists $self->uservars->{$field}
!ll&&!rl&&r
5181888185152
MC/DC100%2/2
not $force and exists $self->uservars->{$field}
not $force exists $self->uservars->{$field}
Truth table100%3/3
not(A) and B
A= not $forceB= exists $self->uservars->{$field}
ABresult
0X0
100
111
491 5153 log_debug("Prefix already defined by user");
492 5153 return;
493 }
494 94000 my $filevars = $self->filevars;
495 94000 ▶ if ($field =~ /(dir|prefix)$/ && $value !~ /\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /(dir|prefix)$/ and not $value =~ /\$/) 21879 72122 94001
Condition100%3/3
$field =~ /(dir|prefix)$/ and not $value =~ /\$/
!ll&&!rl&&r
397713235121877
MC/DC100%2/2
$field =~ /(dir|prefix)$/ and not $value =~ /\$/
$field =~ /(dir|prefix)$/ not $value =~ /\$/
Truth table100%3/3
A and not(B)
A= $field =~ /(dir|prefix)$/B= not $value =~ /\$/
ABresult
0X0
100
111
496 # heuristic - it's a directory
497 21878 $filevars->{$field} = [grep length, $value];
498 21912 return;
499 }
500 72157 my (@inwords, @outwords) = shellwords $value; # FIRST split it
501 72157 for my $inword (@inwords) { # THEN sub
502 96926 my ($word, $outword) = ($inword, '');
503 96926 ▶ while ($word =~ s/(^|.*?[^\$])\$\{([a-z_.]+)\}//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ s/(^|.*?[^\$])\$\{([a-z_.]+)\}//s) 54496 96926 151422
504 54496 my ($start, $var) = ($1, $2);
505 54496 $outword .= $start;
506 54496 my $val = $filevars->{$var};
507 54496 ▶ next if !defined($val) or !grep length, @$val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and grep length($_), @$val 14 54482 54496
Condition66%2/3
defined $val and grep length($_), @$val
!ll&&!rl&&r
01454482
MC/DC50%1/2
defined $val and grep length($_), @$val
defined $val grep length($_), @$val
Truth table66%2/3
A and B
A= defined $valB= grep length($_), @$val
ABresult
0X0
100
111
508 54482 $outword .= "@$val";
509 }
510 96926 $outword .= $word; # what's left
511 96926 ▶ next if !length $outword;
Branch: 1 branch
BranchTrueFalseTotal
unless length $outword 14 96912 96926
512 96912 $outword =~ s/\$\$/\$/g; # pkg-config escapes a '$' with a '$$'
513 96912 push @outwords, $outword;
514 }
515 72122 $filevars->{$field} = \@outwords;
516 }
517  
518 10388 ▶sub prepare_vars {
Subroutine prepare_vars: called CC=2 SCAR=6.9
519 10383 my $self = shift;
520 10383 my $uv = $self->uservars;
521 10383 $self->assign_var($_, $uv->{$_}, 1) for keys %$uv;
522 }
523  
524 ################################################################################
525 ################################################################################
526 ### Initializer ###
527 ################################################################################
528 ################################################################################
529 10394 ▶sub find {
Subroutine find: called CC=15 SCAR=27.1
530 10389 my ($cls,$library,%options) = @_;
531 10389 my @uspecs = (
532 ['search_path', \@DEFAULT_SEARCH_PATH],
533 ['exclude_ldflags', \@DEFAULT_EXCLUDE_LFLAGS],
534 ['exclude_cflags', \@DEFAULT_EXCLUDE_CFLAGS]
535 );
536  
537 10389 my %original = %options;
538  
539 10389 foreach (@uspecs) {
540 31167 my ($basekey,$default) = @$_;
541 31167 ▶ my $list = [ @{$options{$basekey} ||= [] } ];
Condition66%2/3
$options{$basekey} ||= []
l!l
11311560
MC/DC100%1/1
$options{$basekey} ||= []
$options{$basekey}
Truth table100%2/2
A
A= $options{$basekey}
Aresult
11
00
542 31174 ▶ if($options{$basekey . "_override"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{$basekey . '_override'}) { } 10371 20796 31167
543 10378 @$list = @{ delete $options{$basekey."_override"} };
544 } else {
545 20796 push @$list, @$default;
546 }
547  
548 31177 $options{$basekey} = $list;
549 #print "$basekey: " . Dumper($list);
550 }
551  
552 10399 $options{filevars} = {};
553 10396 ▶ $options{uservars} = {$options{VARS} ? %{ delete $options{VARS} } : ()};
Branch: 1 branch
BranchTrueFalseTotal
$options{'VARS'} ? : 10376 13 10389
554 10395 $options{original} = \%original;
555  
556 10395 my $o = $cls->new(%options);
557  
558 10397 my @libraries;
559 10437 ▶ if(ref $library eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $library eq 'ARRAY') { } 1119 9270 10389
560 1119 @libraries = @$library;
561 } else {
562 9278 @libraries = ($library);
563 }
564  
565 10395 ▶ if($options{file_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'file_path'}) { } 2 10387 10389
566  
567 2 ▶ if(-r $options{file_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $options{'file_path'}) { } 1 1 2
568 1 $o->recursion(1);
569 1 $o->parse_pcfile($options{file_path});
570 1 $o->recursion(0);
571 } else {
572 1 $o->errmsg("No such file $options{file_path}\n");
573 }
574  
575 } else {
576  
577 10387 foreach my $lib (@libraries) {
578 10387 $o->recursion(0);
579 10387 my($op,$ver);
580 10387 ▶ ($lib,$op,$ver) = ($1,$2,PkgConfig::Version->new($3))
Branch: 1 branch
BranchTrueFalseTotal
if $lib =~ /^(.*)\s+(!=|=|>=|<=|>|<)\s+(.*)$/ 208 10182 10390
581 if $lib =~ /^(.*)\s+(!=|=|>=|<=|>|<)\s+(.*)$/;
582 10387 $o->find_pcfile($lib);
583  
584 10387 ▶ if(!$o->errmsg && defined $op) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->errmsg and defined $op) 208 10179 10387
Condition100%3/3
not $o->errmsg and defined $op
!ll&&!rl&&r
610173208
MC/DC100%2/2
not $o->errmsg and defined $op
not $o->errmsg defined $op
Truth table100%3/3
not(A) and B
A= not $o->errmsgB= defined $op
ABresult
0X0
100
111
585 208 ▶ $op = '==' if $op eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "=" 18 193 211
586 208 ▶ unless(eval qq{ PkgConfig::Version->new(\$o->pkg_version) $op \$ver })
Branch: 1 branch
BranchTrueFalseTotal
unless (eval " PkgConfig::Version->new(\$o->pkg_version) $op \$ver ") 0 211 211
587 {
588 0 ▶ $o->errmsg("Requested '$lib $op $ver' but version of $lib is " .
Branch: 1 branch
BranchTrueFalseTotal
$o->pkg_version ? : 3 0 3
589 ($o->pkg_version ? $o->pkg_version : '') . "\n");
590 }
591 }
592 }
593 }
594  
595 10389 $o;
596 }
597  
598 ################################################################################
599 ################################################################################
600 ### Modify our flags stack ###
601 ################################################################################
602 ################################################################################
603 19647 ▶sub append_ldflags {
Subroutine append_ldflags: called CC=6 SCAR=17.9
604 19641 my ($self,@ld_flags) = @_;
605  
606 19641 foreach my $ldflag (@ld_flags) {
607 59657 ▶ next unless $ldflag =~ /^-Wl/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ldflag =~ /^-Wl/ 59633 24 59657
608  
609 24 my (@wlflags) = split(/,/, $ldflag);
610 24 shift @wlflags; #first is -Wl,
611 24 filter_omit(\@wlflags, $self->exclude_ldflags);
612  
613 24 ▶ if(!@wlflags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@wlflags) 2 22 24
614 2 $ldflag = "";
615 2 next;
616 }
617  
618 22 $ldflag = join(",", '-Wl', @wlflags);
619 }
620  
621 19641 @ld_flags = grep $_, @ld_flags;
622 19644 ▶ return unless @ld_flags;
Branch: 1 branch
BranchTrueFalseTotal
unless @ld_flags 633 19008 19641
623  
624 19011 ▶ push @{($self->libs_deplist->{$self->recursion} ||=[])},
Condition66%2/3
$self->libs_deplist->{$self->recursion} ||= []
l!l
8948100600
MC/DC100%1/1
$self->libs_deplist->{$self->recursion} ||= []
$self->libs_deplist->{$self->recursion}
Truth table100%2/2
A
A= $self->libs_deplist->{$self->recursion}
Aresult
11
00
625 @ld_flags;
626 }
627  
628 # notify us about extra compiler flags
629 19647 ▶sub append_cflags {
Subroutine append_cflags: called CC=1 SCAR=0.0
630 19644 my ($self,@flags) = @_;
631 19644 push @{$self->cflags}, @flags;
632 }
633  
634  
635 ################################################################################
636 ################################################################################
637 ### All sorts of parsing is here ###
638 ################################################################################
639 ################################################################################
640 20776 ▶sub get_requires {
Subroutine get_requires: called CC=8 SCAR=20.8
641 20769 my ($self,$requires) = @_;
642 20793 ▶ return () unless $requires;
Branch: 1 branch
BranchTrueFalseTotal
unless $requires 14722 6044 20766
643  
644 6047 my @reqlist = split(/[\s,]+/, $requires);
645 6044 my @ret;
646 6044 ▶ while (defined (my $req = shift @reqlist) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $req = shift @reqlist)) 14587 154 14741
647 14587 my $reqlet = [ $req ];
648 14587 push @ret, $reqlet;
649 14587 ▶ last unless @reqlist;
Branch: 1 branch
BranchTrueFalseTotal
unless @reqlist 5890 8697 14587
650 #check if we need some version scanning:
651  
652 8697 my $cmp_op;
653 my $want;
654  
655 GT_PARSE_REQ:
656 {
657 #all in one word:
658 10671 ($cmp_op) = ($req =~ /([<>=]+)/);
659 10673 ▶ if($cmp_op) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp_op) { } 1974 8697 10671
elsif ($reqlist[0] =~ /[<>=]+/) { } 1974 6723 8697
660 1974 ▶ if($req =~ /[<>=]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req =~ /[<>=]+$/) { } 1974 0 1974
661 1974 log_debug("comparison operator spaced ($cmp_op)");
662 1974 ($want) = ($req =~ /([^<>=]+$)/);
663 1976 ▶ $want ||= shift @reqlist;
Condition33%1/3
$want ||= shift @reqlist
l!l&&r!l&&!r
019740
MC/DC0%0/2
$want ||= shift @reqlist
$want shift @reqlist
Truth table33%1/3
A ||= B
A= $wantB= shift @reqlist
ABresult
1X1
011
000
664 } else {
665 2 $want = shift @reqlist;
666 }
667 1974 push @$reqlet, ($cmp_op, $want);
668 } elsif ($reqlist[0] =~ /[<>=]+/) {
669 1974 $req = shift @reqlist;
670 1974 goto GT_PARSE_REQ;
671 }
672 }
673 }
674 #log_debug(@ret);
675 6044 @ret;
676 }
677  
678 148479 ▶sub parse_line {
Subroutine parse_line: called CC=6 SCAR=17.9
679 148411 my ($self,$line) = @_;
680  
681 148411 $line =~ s/#[^#]+$//g; # strip comments
682 148411 ▶ return unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 16352 132059 148411
683  
684 132059 my ($tok) = ($line =~ /([=:])/);
685  
686 132061 my ($field,$value) = split(/[=:]/, $line, 2);
687 132061 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 300 131759 132059
688  
689 131761 ▶ if($tok eq '=') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "=") 68307 63452 131759
690 68309 $self->defined_variables->{$field} = $value;
691 }
692  
693 #strip trailing/leading whitespace:
694 131763 $field =~ s/(^\s+)|(\s+)$//msg;
695  
696 #remove trailing/leading whitespace from value
697 131759 $value =~ s/(^\s+)|(\s+$)//msg;
698  
699 131759 log_debugf("Field %s, Value %s", $field, $value);
700  
701 131759 $field = lc($field);
702  
703 131759 my $filevars = $self->filevars;
704 131759 ▶ if ($tok eq ':' and $field !~ /^(cflags|libs)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq ":" and not $field =~ /^(cflags|libs)/) 37789 93970 131759
Condition100%3/3
$tok eq ":" and not $field =~ /^(cflags|libs)/
!ll&&!rl&&r
683072566337789
MC/DC100%2/2
$tok eq ":" and not $field =~ /^(cflags|libs)/
$tok eq ":" not $field =~ /^(cflags|libs)/
Truth table100%3/3
A and not(B)
A= $tok eq ":"B= not $field =~ /^(cflags|libs)/
ABresult
0X0
100
111
705 37789 $value =~ s/(^|[^\$])\$\{([a-z_.]+)\}/$1$filevars->{$2}[0]/g;
706 37789 $filevars->{$field} = [grep length, $value]; # no need quoting
707 37789 return;
708 }
709  
710 #remove quotes from field names
711 93970 $field =~ s/['"]//g;
712  
713 93970 $value =~ s/(\$\{[^}]+\})/lc($1)/ge;
714  
715 #get existent variables from our hash:
716 93970 $self->assign_var($field, $value);
717 }
718  
719 10388 ▶sub parse_pcfile {
Subroutine parse_pcfile: called CC=12 SCAR=25.4
720 10383 my ($self,$pcfile,$wantversion) = @_;
721 #log_warn("Requesting $pcfile");
722 10383 ▶ open my $fh, "<", $pcfile or die "$pcfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $pcfile or die "${pcfile}: $!" 10383 0 10383
723  
724 10383 $self->prepare_vars();
725  
726 10383 my @lines = (<$fh>);
727 10383 close($fh);
728  
729 10383 my $text = join("", @lines);
730 10383 $text =~ s,\\[\r\n],,g;
731 10383 @lines = split(/[\r\n]/, $text);
732  
733 #Fold lines:
734  
735 10383 my $pcfiledir = dirname $pcfile;
736 10383 $pcfiledir =~ s{\\}{/}g;
737  
738 10383 foreach my $line ("pcfiledir=$pcfiledir", @lines) {
739 148411 $self->parse_line($line);
740 }
741  
742 #now that we have eval strings, evaluate them all within the same
743 #lexical scope:
744  
745  
746 10383 $self->append_cflags( $self->get_var('cflags') );
747 10383 ▶ if($self->static) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->static) 0 10383 10383
748 0 $self->append_cflags( $self->get_var('cflags.private') );
749 }
750 10383 $self->append_ldflags( $self->get_var('libs') );
751 10383 ▶ if($self->static) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->static) 0 10383 10383
752 0 $self->append_ldflags( $self->get_var('libs.private') );
753 }
754  
755 10383 my @deps;
756 10383 my @deps_dynamic = $self->get_requires( $self->get_var('requires'));
757 10383 my @deps_static = $self->get_requires( $self->get_var('requires.private') );
758 10383 @deps = @deps_dynamic;
759  
760  
761 10383 ▶ if($self->static) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->static) 0 10383 10383
762 0 push @deps, @deps_static;
763 }
764  
765 10383 ▶ if($self->recursion == 1 && (!$self->pkg_exists())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->recursion == 1 and not $self->pkg_exists) 10383 0 10383
Condition33%1/3
$self->recursion == 1 and not $self->pkg_exists
!ll&&!rl&&r
0010383
MC/DC0%0/2
$self->recursion == 1 and not $self->pkg_exists
$self->recursion == 1 not $self->pkg_exists
Truth table33%1/3
A and not(B)
A= $self->recursion == 1B= not $self->pkg_exists
ABresult
0X0
100
111
766 10383 $self->pkg_version( $self->get_var('version') );
767 10383 $self->pkg_url( $self->get_var('url') );
768 10383 $self->pkg_description( $self->get_var('description') );
769 10383 $self->pkg_exists(1);
770 }
771  
772 10383 ▶ unless ($self->no_recurse) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->no_recurse) 10381 2 10383
773 10381 foreach (@deps) {
774 9259 my ($dep,$cmp_op,$version) = @$_;
775 9262 ▶ $dep = "$dep $cmp_op $version" if defined $cmp_op;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmp_op 208 9051 9259
776 9262 my $other = PkgConfig->find($dep, %{ $self->original });
777 9259 ▶ if($other->errmsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->errmsg) 1 9258 9259
778 1 $self->errmsg($other->errmsg);
779 1 last;
780 }
781 9258 $self->append_cflags( $other->get_cflags );
782 9261 $self->append_ldflags( $other->get_ldflags );
783 }
784 }
785 }
786  
787  
788 ################################################################################
789 ################################################################################
790 ### Locate and process a .pc file ###
791 ################################################################################
792 ################################################################################
793 10392 ▶sub find_pcfile {
Subroutine find_pcfile: called CC=3 SCAR=11.0
794 10387 my ($self,$libname,$version) = @_;
795  
796 10390 $self->recursion($self->recursion + 1);
797  
798 10387 my $pcfile = "$libname.pc";
799 10390 my $found = 0;
800 my @found_paths = (grep {
801 41574 -e File::Spec->catfile($_, $pcfile)
802 10390 } @{$self->search_path});
803  
804 10387 ▶ if(!@found_paths) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@found_paths) 5 10382 10387
805 5 my @search_paths = @{$self->search_path};
806 5 ▶ $self->errmsg(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->errmsg 5 0 5
807 join("\n",
808 "Can't find $pcfile in any of @search_paths",
809 "use the PKG_CONFIG_PATH environment variable, or",
810 "specify extra search paths via 'search_paths'",
811 ""
812 )
813 ) unless $self->errmsg();
814 5 return;
815 }
816  
817 10382 $pcfile = File::Spec->catfile($found_paths[0], $pcfile);
818  
819 10382 $self->parse_pcfile($pcfile);
820  
821 10382 $self->recursion($self->recursion - 1);
822 }
823  
824 ################################################################################
825 ################################################################################
826 ### Public Getters ###
827 ################################################################################
828 ################################################################################
829  
830 3001 ▶sub _quote_protect {
Subroutine _quote_protect: called CC=4 SCAR=13.9
831 3001 my ($v) = @_;
832 3001 ▶ return qq{""} if !length($v); # empty strings get preserved
Branch: 1 branch
BranchTrueFalseTotal
unless length $v 0 3001 3001
833 3001 ▶ return $v if $v !~ /['"\s\\]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /['"\s\\]/ 2991 10 3001
834 10 $v =~ s/["\\]/\\$&/g; # the "" will already protect from ' and space
835 10 ▶ $v =~ /['\s]/ ? qq{"$v"} : $v;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /['\s]/ ? : 9 1 10
836 }
837 92927 ▶sub _return_context {
Subroutine _return_context: called CC=2 SCAR=6.9
838 92886 ▶ wantarray ? @_ : join ' ', map _quote_protect($_), @_;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 92320 566 92886
839 }
840  
841 9835 ▶sub get_cflags {
Subroutine get_cflags: called CC=1 SCAR=0.0
842 9830 my $self = shift;
843 9830 my @cflags = @{$self->cflags};
844  
845 9830 filter_omit(\@cflags, $self->exclude_cflags);
846 9830 filter_dups(\@cflags);
847 9830 _return_context @cflags;
848 }
849  
850 9815 ▶sub get_ldflags {
Subroutine get_ldflags: called CC=2 SCAR=6.9
851 9814 my $self = shift;
852 9814 my @ordered_libs;
853 9814 my @lib_levels = sort keys %{$self->libs_deplist};
854 9814 my @ret;
855  
856 9814 @ordered_libs = @{$self->libs_deplist}{@lib_levels};
857 9814 foreach my $liblist (@ordered_libs) {
858 9556 my $lcopy = [ @$liblist ];
859 9556 filter_dups($lcopy);
860 9556 filter_omit($lcopy, $self->exclude_ldflags);
861 9556 push @ret, @$lcopy;
862 }
863  
864 9814 @ret = reverse @ret;
865 9814 filter_dups(\@ret);
866 9814 @ret = reverse(@ret);
867 9814 _return_context @ret;
868 }
869  
870 72718 ▶sub get_var {
Subroutine get_var: called CC=1 SCAR=0.0
871 72683 my($self, $name) = @_;
872 72683 _return_context @{ $self->filevars->{$name} };
873 }
874  
875 0 ▶sub get_list {
Subroutine get_list: not called CC=5 SCAR=34.0
876 0 my $self = shift;
877 0 my @search_paths = @{$self->search_path};
878 0 my @rv = ();
879 0 $self->recursion(0);
880 0 for my $d (@search_paths) {
881 0 ▶ next unless -d $d;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $d 0 0 0
882 0 for my $pc (bsd_glob("$d/*.pc")) {
883 0 ▶ if ($pc =~ m|/([^\\\/]+)\.pc$|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pc =~ m[/([^\\\/]+)\.pc$]) 0 0 0
884 0 $self->parse_pcfile($pc);
885 0 push @rv, [$1, $self->get_var('name') . ' - ' . $self->get_var('description')];
886 }
887 }
888 }
889 0 @rv;
890 }
891  
892  
893 ################################################################################
894 ################################################################################
895 ### Utility functions ###
896 ################################################################################
897 ################################################################################
898  
899 #split a list of tokens by spaces
900 0 ▶sub _split_flags {
Subroutine _split_flags: not called CC=4 SCAR=30.0
901 0 my @flags = @_;
902 0 ▶ if(!@flags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@flags) 0 0 0
903 0 return @flags;
904 }
905 0 ▶ if(@flags == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@flags == 1) 0 0 0
906 0 my $str = shift @flags;
907 0 ▶ return () if !$str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 0 0
908 0 @flags = shellwords $str;
909 }
910 0 @flags = grep $_, @flags;
911 0 @flags;
912 }
913  
914  
915  
916 29207 ▶sub filter_dups {
Subroutine filter_dups: called CC=3 SCAR=11.0
917 29200 my $array = shift;
918 29200 my @ret;
919 my %seen_hash;
920 29200 foreach my $elem (@$array) {
921 130396 ▶ if(exists $seen_hash{$elem}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_hash{$elem}) 22240 108156 130396
922 22240 next;
923 }
924 108156 $seen_hash{$elem} = 1;
925 108156 push @ret, $elem;
926 }
927 #print Dumper(\%seen_hash);
928 29200 @$array = @ret;
929 }
930  
931 19416 ▶sub filter_omit {
Subroutine filter_omit: called CC=3 SCAR=11.0
932 19410 my ($have,$exclude) = @_;
933 19410 my @ret;
934 #print Dumper($have);
935 19410 foreach my $elem (@$have) {
936 #log_warn("Checking '$elem'");
937 79513 ▶ if(grep { $_ eq $elem } @$exclude) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $elem;} @$exclude) 4944 74569 79513
938 #log_warn("Found illegal flag '$elem'");
939 4944 next;
940 }
941 74569 push @ret, $elem;
942 }
943 19410 @$have = @ret;
944 }
945  
946 0 ▶sub version_2_array {
Subroutine version_2_array: not called CC=3 SCAR=24.8
947 0 my $string = shift;
948 0 my @chunks = split(/\./, $string);
949 0 my @ret;
950 my $chunk;
951 0 ▶ while( ($chunk = pop @chunks)
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk = pop @chunks and $chunk =~ /^\d+$/) 0 0 0
Condition0%0/3
$chunk = pop @chunks and $chunk =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$chunk = pop @chunks and $chunk =~ /^\d+$/
$chunk = pop @chunks $chunk =~ /^\d+$/
Truth table0%0/3
A and B
A= $chunk = pop @chunksB= $chunk =~ /^\d+$/
ABresult
0X0
100
111
952 && $chunk =~ /^\d+$/) {
953 0 push @ret, $chunk;
954 }
955 0 @ret;
956 }
957  
958  
959 0 ▶sub version_check {
Subroutine version_check: not called CC=4 SCAR=30.0
960 0 my ($want,$have) = @_;
961 0 my @a_want = version_2_array($want);
962 0 my @a_have = version_2_array($have);
963  
964 0 ▶ my $max_elem = scalar @a_want > scalar @a_have
Branch: 1 branch
BranchTrueFalseTotal
scalar @a_want > scalar @a_have ? : 0 0 0
965 ? scalar @a_have
966 : scalar @a_want;
967  
968 0 ▶ for(my $i = 0; $i < $max_elem; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_elem) 0 0 0
969 0 ▶ if($a_want[$i] > $a_have[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_want[$i] > $a_have[$i]) 0 0 0
970 0 return 0;
971 }
972 }
973 0 1;
974 }
975  
976  
977 1155 ▶if(caller) {
Branch: 1 branch
BranchTrueFalseTotal
if (caller) 0 1124 1124
978 36 return 1;
979 }
980  
981 package
982 PkgConfig::Version;
983  
984 use overload
985 216 ▶ '<=>' => sub { $_[0]->cmp($_[1]) },
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=1 SCAR=0.0
986 0 ▶ '""' => sub { $_[0]->as_string },
Subroutine __ANON__: not called CC=1 SCAR=6.9
987 1134 fallback => 1;
988  
989 422 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
990 422 my($class, $value) = @_;
991 422 ▶ bless [split /\./, defined $value ? $value : ''], $class;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 422 0 422
992 }
993  
994 3 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
995 3 __PACKAGE__->new(shift->as_string);
996 }
997  
998 3 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
999 3 my($self) = @_;
1000 3 join '.', @{ $self };
1001 }
1002  
1003 490 ▶sub cmp {
Subroutine cmp: called CC=4 SCAR=13.9
1004 490 my($self, $other) = @_;
1005 1134 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1006 490 ▶ defined($self->[0]) || defined($other->[0]) ? ($self->[0] <=> $other->[0]) || &cmp([@{$self}[1..$#$self]], [@{$other}[1..$#$other]]) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[0] || defined $other->[0] ? : 468 22 490
Condition100%6/6
defined $self->[0] or defined $other->[0]
l!l&&r!l&&!r
466222
$self->[0] <=> $other->[0] or &cmp([@{$self;}[1 .. $self->$#*]], [@{$other;}[1 .. $other->$#*]])
l!l&&r!l&&!r
19420470
MC/DC100%2/2
defined $self->[0] or defined $other->[0]
defined $self->[0] defined $other->[0]
MC/DC100%2/2
$self->[0] <=> $other->[0] or &cmp([@{$self;}[1 .. $self->$#*]], [@{$other;}[1 .. $other->$#*]])
$self->[0] <=> $other->[0] &cmp([@{$self;}[1 .. $self->$#*]], [@{$other;}[1 .. $other->$#*]])
Truth table100%3/3
A or B
A= defined $self->[0]B= defined $other->[0]
ABresult
1X1
011
000
Truth table100%3/3
A or B
A= $self->[0] <=> $other->[0]B= &cmp([@{$self;}[1 .. $self->$#*]], [@{$other;}[1 .. $other->$#*]])
ABresult
1X1
011
000
1007 }
1008  
1009 ################################################################################
1010 ################################################################################
1011 ################################################################################
1012 ################################################################################
1013 ### Script-Only stuff ###
1014 ################################################################################
1015 ################################################################################
1016 ################################################################################
1017 ################################################################################
1018 package PkgConfig::Script;
1019 1130 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1020 1130 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1021 1129 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
1022 1134 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
1023  
1024 1169 my $print_errors = 0;
1025 1169 my @ARGV_PRESERVE = @ARGV;
1026  
1027 1151 my @POD_USAGE_SECTIONS = (
1028 "NAME",
1029 'DESCRIPTION/SCRIPT OPTIONS/USAGE',
1030 "DESCRIPTION/SCRIPT OPTIONS/ARGUMENTS|ENVIRONMENT",
1031 "AUTHOR & COPYRIGHT"
1032 );
1033  
1034 1151 my @POD_USAGE_OPTIONS = (
1035 -verbose => 99,
1036 -sections => \@POD_USAGE_SECTIONS
1037 );
1038  
1039 1151 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("libs", \my $PrintLibs, "libs-only-L", \my $PrintLibsOnlyL, "libs-only-l", \my $PrintLibsOnlyl, "libs-only-other", \my $PrintLibsOnlyOther, "list-all", \my $ListAll, "static", \my $UseStatic, "cflags", \my $PrintCflags, "cflags-only-I", \my $PrintCflagsOnlyI, "cflags-only-other", \my $PrintCflagsOnlyOther, "exists", \my $PrintExists, "atleast-version=s", \my $AtLeastVersion, "atleast-pkgconfig-version=s", \my $AtLeastPkgConfigVersion, "exact-version=s", \my $ExactVersion, "max-version=s", \my $MaxVersion, "silence-errors", \my $SilenceErrors, "print-errors", \my $PrintErrors, "errors-to-stdout", \my $ErrToStdOut, "short-errors", \my $ShortErrors, "define-variable=s", \my %UserVariables, "print-variables", \my $PrintVariables, "print-values", \my $PrintValues, "variable=s", \my $OutputVariableValue, "modversion", \my $PrintVersion, "version", \my $PrintAPIversion, "real-version", \my $PrintRealVersion, "debug", \my $Debug, "with-path=s", \my @ExtraPaths, "env-only", \my $EnvOnly, "guess-paths", \my $GuessPaths, "h|help|?", \my $WantHelp) or pod2usage(@POD_USAGE_OPTIONS) 1119 5 1124
1040 'libs' => \my $PrintLibs,
1041 'libs-only-L' => \my $PrintLibsOnlyL,
1042 'libs-only-l' => \my $PrintLibsOnlyl,
1043 'libs-only-other' => \my $PrintLibsOnlyOther,
1044 'list-all' => \my $ListAll,
1045 'static' => \my $UseStatic,
1046 'cflags' => \my $PrintCflags,
1047 'cflags-only-I' => \my $PrintCflagsOnlyI,
1048 'cflags-only-other' => \my $PrintCflagsOnlyOther,
1049 'exists' => \my $PrintExists,
1050 'atleast-version=s' => \my $AtLeastVersion,
1051 'atleast-pkgconfig-version=s' => \my $AtLeastPkgConfigVersion,
1052 'exact-version=s' => \my $ExactVersion,
1053 'max-version=s' => \my $MaxVersion,
1054  
1055 'silence-errors' => \my $SilenceErrors,
1056 'print-errors' => \my $PrintErrors,
1057 'errors-to-stdout' => \my $ErrToStdOut,
1058 'short-errors' => \my $ShortErrors,
1059  
1060 'define-variable=s', => \my %UserVariables,
1061  
1062 'print-variables' => \my $PrintVariables,
1063 'print-values' => \my $PrintValues,
1064 'variable=s', => \my $OutputVariableValue,
1065  
1066 'modversion' => \my $PrintVersion,
1067 'version', => \my $PrintAPIversion,
1068 'real-version' => \my $PrintRealVersion,
1069  
1070 'debug' => \my $Debug,
1071 'with-path=s', => \my @ExtraPaths,
1072 'env-only', => \my $EnvOnly,
1073 'guess-paths', => \my $GuessPaths,
1074  
1075 'h|help|?' => \my $WantHelp
1076 ) or pod2usage(@POD_USAGE_OPTIONS);
1077  
1078 1151 ▶if($^O eq 'msys' && !$ENV{PKG_CONFIG_NO_OS_CUSTOMIZATION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "msys" and not $ENV{"PKG_CONFIG_NO_OS_CUSTOMIZATION"}) 5 1119 1124
Condition33%1/3
$^O eq "msys" and not $ENV{"PKG_CONFIG_NO_OS_CUSTOMIZATION"}
!ll&&!rl&&r
111900
MC/DC0%0/2
$^O eq "msys" and not $ENV{"PKG_CONFIG_NO_OS_CUSTOMIZATION"}
$^O eq "msys" not $ENV{"PKG_CONFIG_NO_OS_CUSTOMIZATION"}
Truth table33%1/3
A and not(B)
A= $^O eq "msys"B= not $ENV{"PKG_CONFIG_NO_OS_CUSTOMIZATION"}
ABresult
0X0
100
111
1079 32 $UseStatic = 1;
1080 }
1081  
1082 1169 ▶if($WantHelp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WantHelp) 5 1119 1124
1083 50 pod2usage(@POD_USAGE_OPTIONS, -exitval => 0);
1084 }
1085  
1086 1169 ▶if($Debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Debug) 0 1120 1120
1087 50 eval {
1088 36 Log::Fu::set_log_level('PkgConfig', 'DEBUG');
1089 };
1090 5 $PkgConfig::UseDebugging = 1;
1091 }
1092  
1093 1124 ▶if($GuessPaths) {
Branch: 1 branch
BranchTrueFalseTotal
if ($GuessPaths) 0 1120 1120
1094 5 PkgConfig->GuessPaths();
1095 }
1096  
1097 1124 ▶if($PrintAPIversion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintAPIversion) 0 1124 1124
1098 5 print '0.', $compat_version, "\n";
1099 5 exit(0);
1100 }
1101  
1102 1124 ▶if($AtLeastPkgConfigVersion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($AtLeastPkgConfigVersion) 0 1119 1119
1103 15 my($major,$minor,$patch) = split /\./, $AtLeastPkgConfigVersion;
1104 15 ▶ exit 1 if $major > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $major > 0 0 0 0
1105 15 ▶ exit 1 if $minor > $compat_version;
Branch: 1 branch
BranchTrueFalseTotal
if $minor > $compat_version 0 0 0
1106 15 ▶ exit 1 if $minor == $compat_version && $patch > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $minor == $compat_version and $patch > 0 0 0 0
Condition100%3/3
$minor == $compat_version and $patch > 0
!ll&&!rl&&r
281321
MC/DC100%2/2
$minor == $compat_version and $patch > 0
$minor == $compat_version $patch > 0
Truth table100%3/3
A and B
A= $minor == $compat_versionB= $patch > 0
ABresult
0X0
100
111
1107 0 exit 0;
1108 }
1109  
1110 1119 ▶if($PrintRealVersion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintRealVersion) 41 1119 1160
1111  
1112 15 printf STDOUT ("ppkg-config - cruftless pkg-config\n" .
1113 "Version: %s\n", $PkgConfig::VERSION);
1114 15 exit(0);
1115 }
1116  
1117 1124 ▶if($PrintErrors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintErrors) 1 1118 1119
1118 6 $print_errors = 1;
1119 }
1120  
1121 1119 ▶if($SilenceErrors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SilenceErrors) 1 1118 1119
1122 6 $print_errors = 0;
1123 }
1124  
1125 # This option takes precedence over all other options
1126 # be it:
1127 # --silence-errors
1128 # or
1129 # --print-errors
1130 1124 ▶if ($ErrToStdOut) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ErrToStdOut) 1 1118 1119
1131 6 $print_errors = 2;
1132 }
1133  
1134 1124 ▶my $WantFlags = ($PrintCflags || $PrintLibs || $PrintLibsOnlyL || $PrintCflagsOnlyI || $PrintCflagsOnlyOther || $PrintLibsOnlyOther || $PrintLibsOnlyl || $PrintVersion);
Condition80%17/21
$PrintCflags || $PrintLibs || $PrintLibsOnlyL || $PrintCflagsOnlyI || $PrintCflagsOnlyOther || $PrintLibsOnlyOther || $PrintLibsOnlyl || $PrintVersion
l!l&&r!l&&!r
5591564
$PrintCflags or $PrintLibs or $PrintLibsOnlyL or $PrintCflagsOnlyI or $PrintCflagsOnlyOther or $PrintLibsOnlyOther or $PrintLibsOnlyl
l!l&&r!l&&!r
5590560
$PrintCflags or $PrintLibs or $PrintLibsOnlyL or $PrintCflagsOnlyI or $PrintCflagsOnlyOther or $PrintLibsOnlyOther
l!l&&r!l&&!r
5590560
$PrintCflags or $PrintLibs or $PrintLibsOnlyL or $PrintCflagsOnlyI or $PrintCflagsOnlyOther
l!l&&r!l&&!r
5590560
$PrintCflags or $PrintLibs or $PrintLibsOnlyL or $PrintCflagsOnlyI
l!l&&r!l&&!r
5610560
$PrintCflags or $PrintLibs or $PrintLibsOnlyL
l!l&&r!l&&!r
5592560
$PrintCflags or $PrintLibs
l!l&&r!l&&!r
5581562
MC/DC37%3/8
$PrintCflags || $PrintLibs || $PrintLibsOnlyL || $PrintCflagsOnlyI || $PrintCflagsOnlyOther || $PrintLibsOnlyOther || $PrintLibsOnlyl || $PrintVersion
$PrintCflags $PrintLibs $PrintLibsOnlyL $PrintCflagsOnlyI $PrintCflagsOnlyOther $PrintLibsOnlyOther $PrintLibsOnlyl $PrintVersion
Truth table44%4/9
A or B or C or D or E or F or G || H
A= $PrintCflagsB= $PrintLibsC= $PrintLibsOnlyLD= $PrintCflagsOnlyIE= $PrintCflagsOnlyOtherF= $PrintLibsOnlyOtherG= $PrintLibsOnlylH= $PrintVersion
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
1135  
1136 1119 ▶if($WantFlags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WantFlags) 560 559 1119
1137 565 ▶ $print_errors = 1 unless $SilenceErrors;
Branch: 1 branch
BranchTrueFalseTotal
unless $SilenceErrors 560 0 560
1138 }
1139  
1140 1124 my %pc_options;
1141 1119 ▶if($PrintExists || $AtLeastVersion || $ExactVersion || $MaxVersion || $PrintVersion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintExists or $AtLeastVersion or $ExactVersion or $MaxVersion or $PrintVersion) 2 1127 1129
Condition83%10/12
$PrintExists or $AtLeastVersion or $ExactVersion or $MaxVersion or $PrintVersion
l!l&&r!l&&!r
111117
$PrintExists or $AtLeastVersion or $ExactVersion or $MaxVersion
l!l&&r!l&&!r
101118
$PrintExists or $AtLeastVersion or $ExactVersion
l!l&&r!l&&!r
101118
$PrintExists or $AtLeastVersion
l!l&&r!l&&!r
221118
MC/DC40%2/5
$PrintExists or $AtLeastVersion or $ExactVersion or $MaxVersion or $PrintVersion
$PrintExists $AtLeastVersion $ExactVersion $MaxVersion $PrintVersion
Truth table50%3/6
A or B or C or D or E
A= $PrintExistsB= $AtLeastVersionC= $ExactVersionD= $MaxVersionE= $PrintVersion
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1142 2 $pc_options{no_recurse} = 1;
1143 }
1144  
1145  
1146 1119 $pc_options{static} = $UseStatic;
1147 1119 $pc_options{search_path} = \@ExtraPaths;
1148  
1149 1119 ▶if($EnvOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($EnvOnly) 1114 13 1127
1150 1119 delete $pc_options{search_path};
1151 1119 $pc_options{search_path_override} = [ @ExtraPaths, @ENV_SEARCH_PATH];
1152 }
1153  
1154 1124 $pc_options{print_variables} = $PrintVariables;
1155 1124 $pc_options{print_values} = $PrintValues;
1156 1124 $pc_options{VARS} = \%UserVariables;
1157  
1158 1124 ▶if($ListAll) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ListAll) 0 1119 1119
1159 0 my $o = PkgConfig->find([], %pc_options);
1160 0 my @list = $o->get_list();
1161  
1162 # can't use List::Util::max as it wasn't core until Perl 5.8
1163 0 my $max_length = 0;
1164 5 foreach my $length (map { length $_->[0] } @list) {
1165 6 ▶ $max_length = $length if $length > $max_length;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $max_length 0 0 0
1166 }
1167  
1168 20 printf "%-${max_length}s %s\n", $_->[0], $_->[1] for @list;
1169 0 exit(0);
1170 }
1171  
1172 1119 ▶my @FINDLIBS = @ARGV or die "Must specify at least one library";
Branch: 1 branch
BranchTrueFalseTotal
my(@FINDLIBS) = @ARGV or die "Must specify at least one library" 1119 0 1119
1173  
1174 1119 ▶if($AtLeastVersion) {
Branch: 3 branches
BranchTrueFalseTotal
if ($AtLeastVersion) { } 0 1119 1119
elsif ($MaxVersion) { } 0 1119 1119
elsif ($ExactVersion) { } 0 1119 1119
1175 0 @FINDLIBS = map { "$_ >= $AtLeastVersion" } @FINDLIBS;
1176 } elsif($MaxVersion) {
1177 0 @FINDLIBS = map { "$_ <= $MaxVersion" } @FINDLIBS;
1178 } elsif($ExactVersion) {
1179 6 @FINDLIBS = map { "$_ = $ExactVersion" } @FINDLIBS;
1180 }
1181  
1182 1125 my $o = PkgConfig->find(\@FINDLIBS, %pc_options);
1183  
1184 1125 ▶if($o->errmsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->errmsg) 5 1117 1122
1185 # --errors-to-stdout
1186 10 ▶ if ($print_errors == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($print_errors == 2) { } 1 5 6
elsif ($print_errors == 1) { } 1 4 5
1187 7 print STDOUT $o->errmsg;
1188 # --print-errors
1189 } elsif ($print_errors == 1) {
1190 7 print STDERR $o->errmsg;
1191 }
1192 # --silence-errors
1193 14 exit(1);
1194 }
1195  
1196 1125 ▶if($o->print_variables) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->print_variables) 0 1117 1117
1197 2 ▶ while (my ($k,$v) = each %{$o->defined_variables}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$o->defined_variables;}) 0 2 2
1198 2 print $k;
1199 3 ▶ if($o->print_values) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->print_values) { } 2 0 2
1200 3 print "=$v";
1201 } else {
1202 3 print "\n";
1203 }
1204 }
1205 }
1206  
1207 1116 ▶if($OutputVariableValue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OutputVariableValue) 0 1115 1115
1208 1 ▶ my $val = $o->get_var($OutputVariableValue) || "";
Condition0%0/3
$o->get_var($OutputVariableValue) || ''
l!l
000
MC/DC0%0/1
$o->get_var($OutputVariableValue) || ''
$o->get_var($OutputVariableValue)
Truth table0%0/2
A
A= $o->get_var($OutputVariableValue)
Aresult
11
00
1209 1 print $val . "\n";
1210 }
1211  
1212 1116 ▶if(!$WantFlags) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($WantFlags) 555 560 1115
1213 555 exit(0);
1214 }
1215  
1216 560 ▶if($PrintVersion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintVersion) 1 559 560
1217 1 print $o->pkg_version . "\n";
1218 1 exit(0);
1219 }
1220  
1221 559 my @print_flags;
1222  
1223 559 ▶if($PrintCflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintCflags) 558 1 559
1224 558 @print_flags = $o->get_cflags;
1225 }
1226  
1227 559 ▶if($PrintCflagsOnlyI) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintCflagsOnlyI) 0 559 559
1228 2 @print_flags = grep /^-I/, $o->get_cflags;
1229 }
1230  
1231 627 ▶if($PrintCflagsOnlyOther) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintCflagsOnlyOther) 0 559 559
1232 68 @print_flags = grep /^-[^I]/, $o->get_cflags;
1233 }
1234  
1235 627 ▶if($PrintLibs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintLibs) 554 5 559
1236 616 @print_flags = $o->get_ldflags;
1237 }
1238  
1239 621 ▶if ($PrintLibsOnlyOther) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PrintLibsOnlyOther) 0 559 559
1240 62 @print_flags = grep /^-[^LRl]/, $o->get_ldflags;
1241 }
1242  
1243 # handle --libs-only-L and --libs-only-l but watch the case when
1244 # we got 'ppkg-config --libs-only-L --libs-only-l foo' which must behave just like
1245 # 'ppkg-config --libs-only-l foo'
1246  
1247 621 ▶if($PrintLibsOnlyl or ($PrintLibsOnlyl and $PrintLibsOnlyL)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($PrintLibsOnlyl or $PrintLibsOnlyl and $PrintLibsOnlyL) { } 0 561 561
elsif ($PrintLibsOnlyL) { } 2 559 561
Condition33%2/6
$PrintLibsOnlyl or $PrintLibsOnlyl and $PrintLibsOnlyL
l!l&&r!l&&!r
00559
$PrintLibsOnlyl and $PrintLibsOnlyL
!ll&&!rl&&r
55900
MC/DC0%0/3
$PrintLibsOnlyl or $PrintLibsOnlyl and $PrintLibsOnlyL
$PrintLibsOnlyl $PrintLibsOnlyl $PrintLibsOnlyL
Truth table25%1/4
A or B and C
A= $PrintLibsOnlylB= $PrintLibsOnlylC= $PrintLibsOnlyL
ABCresult
1XX1
0111
00X0
0100
1248 28 @print_flags = grep /^-l/, $o->get_ldflags;
1249 } elsif ($PrintLibsOnlyL) {
1250 62 @print_flags = grep /^-[LR]/, $o->get_ldflags;
1251 }
1252  
1253 621 print scalar PkgConfig::_return_context(@print_flags);
1254 621 print "\n";
1255 621 exit(0);
1256  
1257 __END__
« blib/script/pkg-config.pl ↑ Summary run_test.pl »