| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::PkgConfig::PP; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 7 |  |  | 7 |  | 981 | use strict; | 
|  | 7 |  |  |  |  | 18 |  | 
|  | 7 |  |  |  |  | 207 |  | 
| 4 | 7 |  |  | 7 |  | 44 | use warnings; | 
|  | 7 |  |  |  |  | 16 |  | 
|  | 7 |  |  |  |  | 181 |  | 
| 5 | 7 |  |  | 7 |  | 118 | use 5.008004; | 
|  | 7 |  |  |  |  | 24 |  | 
| 6 | 7 |  |  | 7 |  | 397 | use Alien::Build::Plugin; | 
|  | 7 |  |  |  |  | 14 |  | 
|  | 7 |  |  |  |  | 41 |  | 
| 7 | 7 |  |  | 7 |  | 41 | use Carp (); | 
|  | 7 |  |  |  |  | 29 |  | 
|  | 7 |  |  |  |  | 110 |  | 
| 8 | 7 |  |  | 7 |  | 1303 | use File::Which (); | 
|  | 7 |  |  |  |  | 2748 |  | 
|  | 7 |  |  |  |  | 186 |  | 
| 9 | 7 |  |  | 7 |  | 2428 | use Env qw( @PKG_CONFIG_PATH ); | 
|  | 7 |  |  |  |  | 10521 |  | 
|  | 7 |  |  |  |  | 58 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # ABSTRACT: Probe system and determine library or tool properties using PkgConfig.pm | 
| 12 |  |  |  |  |  |  | our $VERSION = '2.47'; # VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has '+pkg_name' => sub { | 
| 16 |  |  |  |  |  |  | Carp::croak "pkg_name is a required property"; | 
| 17 |  |  |  |  |  |  | }; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | has atleast_version => undef; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | has exact_version => undef; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | has max_version => undef; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | has minimum_version => undef; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 7 |  |  | 7 |  | 1804 | use constant _min_version => '0.14026'; | 
|  | 7 |  |  |  |  | 25 |  | 
|  | 7 |  |  |  |  | 7235 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | # private for now, used by negotiator | 
| 35 |  |  |  |  |  |  | has register_prereqs => 1; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub available | 
| 38 |  |  |  |  |  |  | { | 
| 39 | 19 |  |  | 19 | 1 | 133467 | !!eval { require PkgConfig; PkgConfig->VERSION(_min_version) }; | 
|  | 19 |  |  |  |  | 2000 |  | 
|  | 19 |  |  |  |  | 351161 |  | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub _cleanup | 
| 43 |  |  |  |  |  |  | { | 
| 44 | 16 |  |  | 16 |  | 2221 | my($value) = @_; | 
| 45 | 16 |  |  |  |  | 95 | $value =~ s{\s*$}{ }; | 
| 46 | 16 |  |  |  |  | 44 | $value; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub init | 
| 50 |  |  |  |  |  |  | { | 
| 51 | 28 |  |  | 28 | 1 | 121 | my($self, $meta) = @_; | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 28 | 50 |  |  |  | 86 | unless(defined $meta->prop->{env}->{PKG_CONFIG}) | 
| 54 |  |  |  |  |  |  | { | 
| 55 |  |  |  |  |  |  | # TODO: Better would be to to "execute" lib/PkgConfig.pm | 
| 56 |  |  |  |  |  |  | # as that should always be available, and will match the | 
| 57 |  |  |  |  |  |  | # exact version of PkgConfig.pm that we are using here. | 
| 58 |  |  |  |  |  |  | # there are a few corner cases to deal with before we | 
| 59 |  |  |  |  |  |  | # can do this.  What is here should handle most use cases. | 
| 60 | 28 | 0 |  |  |  | 132 | my $command_line = | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | File::Which::which('ppkg-config') | 
| 62 |  |  |  |  |  |  | ? 'ppkg-config' | 
| 63 |  |  |  |  |  |  | : File::Which::which('pkg-config.pl') | 
| 64 |  |  |  |  |  |  | ? 'pkg-config.pl' | 
| 65 |  |  |  |  |  |  | : File::Which::which('pkg-config') | 
| 66 |  |  |  |  |  |  | ? 'pkg-config' | 
| 67 |  |  |  |  |  |  | : undef; | 
| 68 | 28 | 50 |  |  |  | 4043 | $meta->prop->{env}->{PKG_CONFIG} = $command_line | 
| 69 |  |  |  |  |  |  | if defined $command_line; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 28 | 100 |  |  |  | 130 | if($self->register_prereqs) | 
| 73 |  |  |  |  |  |  | { | 
| 74 | 21 |  |  |  |  | 77 | $meta->add_requires('configure' => 'PkgConfig' => _min_version); | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 28 | 100 |  |  |  | 99 | my($pkg_name, @alt_names) = (ref $self->pkg_name) ? (@{ $self->pkg_name }) : ($self->pkg_name); | 
|  | 2 |  |  |  |  | 8 |  | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | $meta->register_hook( | 
| 80 |  |  |  |  |  |  | probe => sub { | 
| 81 | 20 |  |  | 20 |  | 45 | my($build) = @_; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 20 |  | 33 |  |  | 64 | $build->runtime_prop->{legacy}->{name} ||= $pkg_name; | 
| 84 | 20 |  |  |  |  | 115 | $build->hook_prop->{probe_class} = __PACKAGE__; | 
| 85 | 20 |  |  |  |  | 96 | $build->hook_prop->{probe_instance_id} = $self->instance_id; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 20 |  |  |  |  | 110 | require PkgConfig; | 
| 88 | 20 |  |  |  |  | 142 | my $pkg = PkgConfig->find($pkg_name); | 
| 89 | 20 | 100 |  |  |  | 70685 | die "package @{[ $pkg_name ]} not found" if $pkg->errmsg; | 
|  | 3 |  |  |  |  | 73 |  | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 17 |  |  |  |  | 296 | $build->hook_prop->{version} = $pkg->pkg_version; | 
| 92 | 17 |  |  |  |  | 251 | my $version = PkgConfig::Version->new($pkg->pkg_version); | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 17 |  |  |  |  | 306 | my $atleast_version = $self->atleast_version; | 
| 95 | 17 | 100 |  |  |  | 89 | $atleast_version = $self->minimum_version unless defined $atleast_version; | 
| 96 | 17 | 100 |  |  |  | 49 | if(defined $atleast_version) | 
| 97 |  |  |  |  |  |  | { | 
| 98 | 7 |  |  |  |  | 16 | my $need    = PkgConfig::Version->new($atleast_version); | 
| 99 | 7 | 100 |  |  |  | 78 | if($version < $need) | 
| 100 |  |  |  |  |  |  | { | 
| 101 | 2 |  |  |  |  | 74 | die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but at least $atleast_version is required."; | 
|  | 2 |  |  |  |  | 9 |  | 
|  | 2 |  |  |  |  | 33 |  | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 15 | 100 |  |  |  | 185 | if(defined $self->exact_version) | 
| 106 |  |  |  |  |  |  | { | 
| 107 | 4 |  |  |  |  | 12 | my $need = PkgConfig::Version->new($self->exact_version); | 
| 108 | 4 | 100 |  |  |  | 35 | if($version != $need) | 
| 109 |  |  |  |  |  |  | { | 
| 110 | 3 |  |  |  |  | 81 | die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but exactly @{[ $self->exact_version ]} is required."; | 
|  | 3 |  |  |  |  | 15 |  | 
|  | 3 |  |  |  |  | 47 |  | 
|  | 3 |  |  |  |  | 32 |  | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 12 | 100 |  |  |  | 77 | if(defined $self->max_version) | 
| 115 |  |  |  |  |  |  | { | 
| 116 | 5 |  |  |  |  | 25 | my $need = PkgConfig::Version->new($self->max_version); | 
| 117 | 5 | 100 |  |  |  | 43 | if($version > $need) | 
| 118 |  |  |  |  |  |  | { | 
| 119 | 2 |  |  |  |  | 64 | die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but max of @{[ $self->max_version ]} is required."; | 
|  | 2 |  |  |  |  | 52 |  | 
|  | 2 |  |  |  |  | 40 |  | 
|  | 2 |  |  |  |  | 21 |  | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 10 |  |  |  |  | 113 | foreach my $alt (@alt_names) | 
| 124 |  |  |  |  |  |  | { | 
| 125 | 1 |  |  |  |  | 5 | my $pkg = PkgConfig->find($alt); | 
| 126 | 1 | 50 |  |  |  | 3475 | die "package $alt not found" if $pkg->errmsg; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 10 |  |  |  |  | 84 | 'system'; | 
| 130 |  |  |  |  |  |  | }, | 
| 131 | 28 |  |  |  |  | 329 | ); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | $meta->register_hook( | 
| 134 |  |  |  |  |  |  | $_ => sub { | 
| 135 | 4 |  |  | 4 |  | 13 | my($build) = @_; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | return if $build->hook_prop->{name} eq 'gather_system' | 
| 138 | 4 | 100 | 100 |  |  | 16 | &&        ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id; | 
|  |  |  | 100 |  |  |  |  | 
| 139 |  |  |  |  |  |  |  | 
| 140 | 3 |  |  |  |  | 19 | require PkgConfig; | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 3 |  |  |  |  | 8 | foreach my $name ($pkg_name, @alt_names) | 
| 143 |  |  |  |  |  |  | { | 
| 144 | 4 |  |  |  |  | 16 | require PkgConfig; | 
| 145 | 4 |  |  |  |  | 30 | my $pkg = PkgConfig->find($name, search_path => [@PKG_CONFIG_PATH]); | 
| 146 | 4 | 50 |  |  |  | 14262 | if($pkg->errmsg) | 
| 147 |  |  |  |  |  |  | { | 
| 148 | 0 |  |  |  |  | 0 | $build->log("Trying to load the pkg-config information from the source code build"); | 
| 149 | 0 |  |  |  |  | 0 | $build->log("of your package failed"); | 
| 150 | 0 |  |  |  |  | 0 | $build->log("You are currently using the pure-perl implementation of pkg-config"); | 
| 151 | 0 |  |  |  |  | 0 | $build->log("(AB Plugin is named PkgConfig::PP, which uses PkgConfig.pm"); | 
| 152 | 0 |  |  |  |  | 0 | $build->log("It may work better with the real pkg-config."); | 
| 153 | 0 |  |  |  |  | 0 | $build->log("Try installing your OS' version of pkg-config or unset ALIEN_BUILD_PKG_CONFIG"); | 
| 154 | 0 |  |  |  |  | 0 | die "second load of PkgConfig.pm @{[ $name ]} failed: @{[ $pkg->errmsg ]}" | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 155 |  |  |  |  |  |  | } | 
| 156 | 4 |  |  |  |  | 51 | my %prop; | 
| 157 | 4 |  |  |  |  | 16 | $prop{cflags}  = _cleanup scalar $pkg->get_cflags; | 
| 158 | 4 |  |  |  |  | 15 | $prop{libs}    = _cleanup scalar $pkg->get_ldflags; | 
| 159 | 4 |  |  |  |  | 55 | $prop{version} = $pkg->pkg_version; | 
| 160 | 4 |  |  |  |  | 39 | $pkg = PkgConfig->find($name, static => 1, search_path => [@PKG_CONFIG_PATH]); | 
| 161 | 4 |  |  |  |  | 14283 | $prop{cflags_static} = _cleanup scalar $pkg->get_cflags; | 
| 162 | 4 |  |  |  |  | 15 | $prop{libs_static}   = _cleanup scalar $pkg->get_ldflags; | 
| 163 | 4 |  |  |  |  | 16 | $build->runtime_prop->{alt}->{$name} = \%prop; | 
| 164 |  |  |  |  |  |  | } | 
| 165 | 3 |  |  |  |  | 10 | foreach my $key (keys %{ $build->runtime_prop->{alt}->{$pkg_name} }) | 
|  | 3 |  |  |  |  | 9 |  | 
| 166 |  |  |  |  |  |  | { | 
| 167 | 15 |  |  |  |  | 26 | $build->runtime_prop->{$key} = $build->runtime_prop->{alt}->{$pkg_name}->{$key}; | 
| 168 |  |  |  |  |  |  | } | 
| 169 | 3 | 100 |  |  |  | 6 | if(keys %{ $build->runtime_prop->{alt} } == 1) | 
|  | 3 |  |  |  |  | 9 |  | 
| 170 |  |  |  |  |  |  | { | 
| 171 | 2 |  |  |  |  | 6 | delete $build->runtime_prop->{alt}; | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  | } | 
| 174 | 28 |  |  |  |  | 271 | ) for qw( gather_system gather_share ); | 
| 175 |  |  |  |  |  |  |  | 
| 176 | 28 |  |  |  |  | 79 | $self; | 
| 177 |  |  |  |  |  |  | } | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | 1; | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | __END__ |