| 1 | package Alien::Build::Plugin::PkgConfig::MakeStatic; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use 5.008004; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use Alien::Build::Plugin; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use Path::Tiny (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | # ABSTRACT: Convert .pc files into static | ||||||||||||||
| 10 | 2 | our $VERSION = '2.88'; # VERSION | |||||||||||||
| 11 | |||||||||||||||
| 12 | |||||||||||||||
| 13 | 2 | has path => undef; | |||||||||||||
| 14 | |||||||||||||||
| 15 | sub _convert | ||||||||||||||
| 16 | 2 | ▶ | { | ||||||||||||
|
Subroutine
_convert: called CC=8 SCAR=21.0
| |||||||||||||||
| 17 | 2 | my($self, $build, $path) = @_; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 2 | ▶ | die "unable to read $path" unless -r $path; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 2 | ▶ | die "unable to write $path" unless -w $path; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | 2 | $build->log("converting $path to static"); | |||||||||||||
| 23 | |||||||||||||||
| 24 | my %h = map { | ||||||||||||||
| 25 | 2 | my($key, $value) = /^(.*?):(.*?)$/; | |||||||||||||
| 26 | 6 | $value =~ s{^\s+}{}; | |||||||||||||
| 27 | 6 | $value =~ s{\s+$}{}; | |||||||||||||
| 28 | 6 | ($key => $value); | |||||||||||||
| 29 | } grep /^(?:Libs|Cflags)(?:\.private)?:/, $path->lines; | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 2 | ▶ | $h{Cflags} = '' unless defined $h{Cflags}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 2 | ▶ | $h{Libs} = '' unless defined $h{Libs}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | ▶ | $h{Cflags} .= ' ' . $h{"Cflags.private"} if defined $h{"Cflags.private"}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 2 | ▶ | $h{Libs} .= ' ' . $h{"Libs.private"} if defined $h{"Libs.private"}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | 2 | $h{"Cflags.private"} = ''; | |||||||||||||
| 38 | 2 | $h{"Libs.private"} = ''; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 8 | ▶ | $path->edit_lines(sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||
| 41 | |||||||||||||||
| 42 | 8 | ▶ | if(/^(.*?):/) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | { | ||||||||||||||
| 44 | 6 | my $key = $1; | |||||||||||||
| 45 | 6 | ▶ | if(defined $h{$key}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | { | ||||||||||||||
| 47 | 6 | s/^(.*?):.*$/$1: $h{$key} /; | |||||||||||||
| 48 | 6 | delete $h{$key}; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 2 | }); | |||||||||||||
| 53 | |||||||||||||||
| 54 | 2 | $path->append("$_: $h{$_}\n") foreach keys %h; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | sub _recurse | ||||||||||||||
| 58 | 3 | ▶ | { | ||||||||||||
|
Subroutine
_recurse: called CC=4 SCAR=13.9
| |||||||||||||||
| 59 | 3 | my($self, $build, $dir) = @_; | |||||||||||||
| 60 | |||||||||||||||
| 61 | 3 | foreach my $child ($dir->children) | |||||||||||||
| 62 | { | ||||||||||||||
| 63 | 4 | ▶ | if(-d $child) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 64 | { | ||||||||||||||
| 65 | 2 | $self->_recurse($build, $child); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | elsif($child->basename =~ /\.pc$/) | ||||||||||||||
| 68 | { | ||||||||||||||
| 69 | 2 | $self->_convert($build, $child); | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | sub init | ||||||||||||||
| 75 | 1 | ▶ | { | ||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||
| 76 | 1 | my($self, $meta) = @_; | |||||||||||||
| 77 | |||||||||||||||
| 78 | 1 | $meta->add_requires('configure' => 'Alien::Build::Plugin::Build::SearchDep' => '0.35'); | |||||||||||||
| 79 | |||||||||||||||
| 80 | $meta->before_hook( | ||||||||||||||
| 81 | 1 | ▶ | gather_share => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||
| 82 | 1 | my($build) = @_; | |||||||||||||
| 83 | |||||||||||||||
| 84 | 1 | ▶ | if($self->path) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | { | ||||||||||||||
| 86 | 0 | $self->_convert($build, Path::Tiny->new($self->path)->absolute); | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | else | ||||||||||||||
| 89 | { | ||||||||||||||
| 90 | 1 | $self->_recurse($build, Path::Tiny->new(".")->absolute); | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | }, | ||||||||||||||
| 94 | 1 | ); | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 2 | 1; | |||||||||||||
| 98 | |||||||||||||||
| 99 | __END__ | ||||||||||||||