Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,326 @@
package Alien::Build::Plugin::PkgConfig::CommandLine;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Carp ();
# ABSTRACT: Probe system and determine library or tool properties using the pkg-config command line interface
our $VERSION = '2.38'; # VERSION
has '+pkg_name' => sub {
Carp::croak "pkg_name is a required property";
};
# NOT used, for compat with other PkgConfig plugins
has register_prereqs => 1;
sub _bin_name {
# We prefer pkgconf to pkg-config because it seems to be the future.
require File::Which;
File::Which::which($ENV{PKG_CONFIG})
? $ENV{PKG_CONFIG}
: File::Which::which('pkgconf')
? 'pkgconf'
: File::Which::which('pkg-config')
? 'pkg-config'
: undef;
};
has bin_name => \&_bin_name;
has atleast_version => undef;
has exact_version => undef;
has max_version => undef;
has minimum_version => undef;
sub _val
{
my($build, $args, $prop_name) = @_;
my $string = $args->{out};
chomp $string;
$string =~ s{^\s+}{};
if($prop_name =~ /version$/)
{ $string =~ s{\s*$}{} }
else
{ $string =~ s{\s*$}{ } }
if($prop_name =~ /^(.*?)\.(.*?)\.(.*?)$/)
{ $build->runtime_prop->{$1}->{$2}->{$3} = $string }
else
{ $build->runtime_prop->{$prop_name} = $string }
();
}
sub available
{
!!_bin_name();
}
sub init
{
my($self, $meta) = @_;
my @probe;
my @gather;
my $pkgconf = $self->bin_name;
unless(defined $meta->prop->{env}->{PKG_CONFIG})
{
$meta->prop->{env}->{PKG_CONFIG} = $pkgconf;
}
my($pkg_name, @alt_names) = (ref $self->pkg_name) ? (@{ $self->pkg_name }) : ($self->pkg_name);
push @probe, map { [$pkgconf, '--exists', $_] } ($pkg_name, @alt_names);
if(defined $self->minimum_version)
{
push @probe, [ $pkgconf, '--atleast-version=' . $self->minimum_version, $pkg_name ];
}
elsif(defined $self->atleast_version)
{
push @probe, [ $pkgconf, '--atleast-version=' . $self->atleast_version, $pkg_name ];
}
if(defined $self->exact_version)
{
push @probe, [ $pkgconf, '--exact-version=' . $self->exact_version, $pkg_name ];
}
if(defined $self->max_version)
{
push @probe, [ $pkgconf, '--max-version=' . $self->max_version, $pkg_name ];
}
push @probe, [ $pkgconf, '--modversion', $pkg_name, sub {
my($build, $args) = @_;
my $version = $args->{out};
$version =~ s{^\s+}{};
$version =~ s{\s*$}{};
$build->hook_prop->{version} = $version;
}];
unshift @probe, sub {
my($build) = @_;
$build->runtime_prop->{legacy}->{name} ||= $pkg_name;
$build->hook_prop->{probe_class} = __PACKAGE__;
$build->hook_prop->{probe_instance_id} = $self->instance_id;
};
$meta->register_hook(
probe => \@probe
);
push @gather, sub {
my($build) = @_;
die 'pkg-config command line probe does not match gather' if $build->hook_prop->{name} eq 'gather_system'
&& ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id;
};
push @gather, map { [ $pkgconf, '--exists', $_] } ($pkg_name, @alt_names);
foreach my $prop_name (qw( cflags libs version ))
{
my $flag = $prop_name eq 'version' ? '--modversion' : "--$prop_name";
push @gather,
[ $pkgconf, $flag, $pkg_name, sub { _val @_, $prop_name } ];
if(@alt_names)
{
foreach my $alt ($pkg_name, @alt_names)
{
push @gather,
[ $pkgconf, $flag, $alt, sub { _val @_, "alt.$alt.$prop_name" } ];
}
}
}
foreach my $prop_name (qw( cflags libs ))
{
push @gather,
[ $pkgconf, '--static', "--$prop_name", $pkg_name, sub { _val @_, "${prop_name}_static" } ];
if(@alt_names)
{
foreach my $alt ($pkg_name, @alt_names)
{
push @gather,
[ $pkgconf, '--static', "--$prop_name", $alt, sub { _val @_, "alt.$alt.${prop_name}_static" } ];
}
}
}
$meta->register_hook(gather_system => [@gather]);
if($meta->prop->{platform}->{system_type} eq 'windows-mingw')
{
@gather = map {
if(ref $_ eq 'ARRAY') {
my($pkgconf, @rest) = @$_;
[$pkgconf, '--dont-define-prefix', @rest],
} else {
$_
}
} @gather;
}
$meta->register_hook(gather_share => [@gather]);
$meta->after_hook(
$_ => sub {
my($build) = @_;
if(keys %{ $build->runtime_prop->{alt} } < 2)
{
delete $build->runtime_prop->{alt};
}
},
) for qw( gather_system gather_share );
$self;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::PkgConfig::CommandLine - Probe system and determine library or tool properties using the pkg-config command line interface
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'PkgConfig::CommandLine' => (
pkg_name => 'libfoo',
);
=head1 DESCRIPTION
Note: in most case you will want to use L<Alien::Build::Plugin::PkgConfig::Negotiate>
instead. It picks the appropriate fetch plugin based on your platform and environment.
In some cases you may need to use this plugin directly instead.
This plugin provides Probe and Gather steps for pkg-config based packages. It uses
the best command line tools to accomplish this task.
=head1 PROPERTIES
=head2 pkg_name
The package name. If this is a list reference then .pc files with all those package
names must be present.
=head2 atleast_version
The minimum required version that is acceptable version as provided by the system.
=head2 exact_version
The exact required version that is acceptable version as provided by the system.
=head2 max_version
The max required version that is acceptable version as provided by the system.
=head2 minimum_version
Alias for C<atleast_version> for backward compatibility.
=head1 METHODS
=head2 available
my $bool = Alien::Build::Plugin::PkgConfig::CommandLine->available;
Returns true if the necessary prereqs for this plugin are I<already> installed.
=head1 SEE ALSO
L<Alien::Build::Plugin::PkgConfig::Negotiate>, L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,301 @@
package Alien::Build::Plugin::PkgConfig::LibPkgConf;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Carp ();
# ABSTRACT: Probe system and determine library or tool properties using PkgConfig::LibPkgConf
our $VERSION = '2.38'; # VERSION
has '+pkg_name' => sub {
Carp::croak "pkg_name is a required property";
};
has atleast_version => undef;
has exact_version => undef;
has max_version => undef;
has minimum_version => undef;
# private for now, used by negotiator
has register_prereqs => 1;
use constant _min_version => '0.04';
sub available
{
!!eval { require PkgConfig::LibPkgConf; PkgConfig::LibPkgConf->VERSION(_min_version) };
}
sub init
{
my($self, $meta) = @_;
unless(defined $meta->prop->{env}->{PKG_CONFIG})
{
# TODO: this doesn't yet find pkgconf in the bin dir of a share
# install.
my $command_line =
File::Which::which('pkgconf')
? 'pkgconf'
: File::Which::which('pkg-config')
? 'pkg-config'
: undef;
$meta->prop->{env}->{PKG_CONFIG} = $command_line
if defined $command_line;
}
if($self->register_prereqs)
{
# Also update in Neotiate.pm
$meta->add_requires('configure' => 'PkgConfig::LibPkgConf::Client' => _min_version);
if(defined $self->minimum_version || defined $self->atleast_version || defined $self->exact_version || defined $self->max_version)
{
$meta->add_requires('configure' => 'PkgConfig::LibPkgConf::Util' => _min_version);
}
}
my($pkg_name, @alt_names) = (ref $self->pkg_name) ? (@{ $self->pkg_name }) : ($self->pkg_name);
$meta->register_hook(
probe => sub {
my($build) = @_;
$build->runtime_prop->{legacy}->{name} ||= $pkg_name;
$build->hook_prop->{probe_class} = __PACKAGE__;
$build->hook_prop->{probe_instance_id} = $self->instance_id;
require PkgConfig::LibPkgConf::Client;
my $client = PkgConfig::LibPkgConf::Client->new;
my $pkg = $client->find($pkg_name);
die "package $pkg_name not found" unless $pkg;
$build->hook_prop->{version} = $pkg->version;
my $atleast_version = $self->atleast_version;
$atleast_version = $self->minimum_version unless defined $self->atleast_version;
if($atleast_version)
{
require PkgConfig::LibPkgConf::Util;
if(PkgConfig::LibPkgConf::Util::compare_version($pkg->version, $atleast_version) < 0)
{
die "package $pkg_name is version @{[ $pkg->version ]}, but at least $atleast_version is required.";
}
}
if($self->exact_version)
{
require PkgConfig::LibPkgConf::Util;
if(PkgConfig::LibPkgConf::Util::compare_version($pkg->version, $self->exact_version) != 0)
{
die "package $pkg_name is version @{[ $pkg->version ]}, but exactly @{[ $self->exact_version ]} is required.";
}
}
if($self->max_version)
{
require PkgConfig::LibPkgConf::Util;
if(PkgConfig::LibPkgConf::Util::compare_version($pkg->version, $self->max_version) > 0)
{
die "package $pkg_name is version @{[ $pkg->version ]}, but max @{[ $self->max_version ]} is required.";
}
}
foreach my $alt (@alt_names)
{
my $pkg = $client->find($alt);
die "package $alt not found" unless $pkg;
}
'system';
},
);
$meta->register_hook(
$_ => sub {
my($build) = @_;
return if $build->hook_prop->{name} eq 'gather_system'
&& ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id;
require PkgConfig::LibPkgConf::Client;
my $client = PkgConfig::LibPkgConf::Client->new;
foreach my $name ($pkg_name, @alt_names)
{
my $pkg = $client->find($name);
die "reload of package $name failed" unless defined $pkg;
my %prop;
$prop{version} = $pkg->version;
$prop{cflags} = $pkg->cflags;
$prop{libs} = $pkg->libs;
$prop{cflags_static} = $pkg->cflags_static;
$prop{libs_static} = $pkg->libs_static;
$build->runtime_prop->{alt}->{$name} = \%prop;
}
foreach my $key (keys %{ $build->runtime_prop->{alt}->{$pkg_name} })
{
$build->runtime_prop->{$key} = $build->runtime_prop->{alt}->{$pkg_name}->{$key};
}
if(keys %{ $build->runtime_prop->{alt} } == 1)
{
delete $build->runtime_prop->{alt};
}
},
) for qw( gather_system gather_share );
$self;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::PkgConfig::LibPkgConf - Probe system and determine library or tool properties using PkgConfig::LibPkgConf
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'PkgConfig::LibPkgConf' => (
pkg_name => 'libfoo',
);
=head1 DESCRIPTION
Note: in most case you will want to use L<Alien::Build::Plugin::PkgConfig::Negotiate>
instead. It picks the appropriate fetch plugin based on your platform and environment.
In some cases you may need to use this plugin directly instead.
This plugin provides Probe and Gather steps for pkg-config based packages. It uses
L<PkgConfig::LibPkgConf> to accomplish this task.
This plugin is part of the Alien::Build core For Now, but may be removed in a future
date. While It Seemed Like A Good Idea at the time, it may not be appropriate to keep
it in core. If it is spun off it will get its own distribution some time in the future.
=head1 PROPERTIES
=head2 pkg_name
The package name. If this is a list reference then .pc files with all those package
names must be present.
=head2 atleast_version
The minimum required version that is acceptable version as provided by the system.
=head2 exact_version
The exact required version that is acceptable version as provided by the system.
=head2 max_version
The max required version that is acceptable version as provided by the system.
=head2 minimum_version
Alias for C<atleast_version> for backward compatibility.
=head1 METHODS
=head2 available
my $bool = Alien::Build::Plugin::PkgConfig::LibPkgConf->available;
Returns true if the necessary prereqs for this plugin are I<already> installed.
=head1 SEE ALSO
L<Alien::Build::Plugin::PkgConfig::Negotiate>, L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,200 @@
package Alien::Build::Plugin::PkgConfig::MakeStatic;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Path::Tiny ();
# ABSTRACT: Convert .pc files into static
our $VERSION = '2.38'; # VERSION
has path => undef;
sub _convert
{
my($self, $build, $path) = @_;
die "unable to read $path" unless -r $path;
die "unable to write $path" unless -w $path;
$build->log("converting $path to static");
my %h = map {
my($key, $value) = /^(.*?):(.*?)$/;
$value =~ s{^\s+}{};
$value =~ s{\s+$}{};
($key => $value);
} grep /^(?:Libs|Cflags)(?:\.private)?:/, $path->lines;
$h{Cflags} = '' unless defined $h{Cflags};
$h{Libs} = '' unless defined $h{Libs};
$h{Cflags} .= ' ' . $h{"Cflags.private"} if defined $h{"Cflags.private"};
$h{Libs} .= ' ' . $h{"Libs.private"} if defined $h{"Libs.private"};
$h{"Cflags.private"} = '';
$h{"Libs.private"} = '';
$path->edit_lines(sub {
if(/^(.*?):/)
{
my $key = $1;
if(defined $h{$key})
{
s/^(.*?):.*$/$1: $h{$key} /;
delete $h{$key};
}
}
});
$path->append("$_: $h{$_}\n") foreach keys %h;
}
sub _recurse
{
my($self, $build, $dir) = @_;
foreach my $child ($dir->children)
{
if(-d $child)
{
$self->_recurse($build, $child);
}
elsif($child->basename =~ /\.pc$/)
{
$self->_convert($build, $child);
}
}
}
sub init
{
my($self, $meta) = @_;
$meta->add_requires('configure' => 'Alien::Build::Plugin::Build::SearchDep' => '0.35');
$meta->before_hook(
gather_share => sub {
my($build) = @_;
if($self->path)
{
$self->_convert($build, Path::Tiny->new($self->path)->absolute);
}
else
{
$self->_recurse($build, Path::Tiny->new(".")->absolute);
}
},
);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::PkgConfig::MakeStatic - Convert .pc files into static
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'PkgConfig::MakeStatic' => (
path => 'lib/pkgconfig/foo.pc',
);
=head1 DESCRIPTION
Convert C<.pc> file to use static linkage by default. This is an experimental
plugin, so use with caution.
=head1 PROPERTIES
=head2 path
The path to the C<.pc> file. If not provided, all C<.pc> files in the stage
directory will be converted.
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,248 @@
package Alien::Build::Plugin::PkgConfig::Negotiate;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Alien::Build::Plugin::PkgConfig::PP;
use Alien::Build::Plugin::PkgConfig::LibPkgConf;
use Alien::Build::Plugin::PkgConfig::CommandLine;
use Alien::Build::Util qw( _perl_config );
use Carp ();
# ABSTRACT: Package configuration negotiation plugin
our $VERSION = '2.38'; # VERSION
has '+pkg_name' => sub {
Carp::croak "pkg_name is a required property";
};
has atleast_version => undef;
has exact_version => undef;
has max_version => undef;
has minimum_version => undef;
sub pick
{
my($class) = @_;
return $ENV{ALIEN_BUILD_PKG_CONFIG} if $ENV{ALIEN_BUILD_PKG_CONFIG};
if(Alien::Build::Plugin::PkgConfig::LibPkgConf->available)
{
return 'PkgConfig::LibPkgConf';
}
if(Alien::Build::Plugin::PkgConfig::CommandLine->available)
{
# TODO: determine environment or flags necessary for using pkg-config
# on solaris 64 bit.
# Some advice on pkg-config and 64 bit Solaris
# https://docs.oracle.com/cd/E53394_01/html/E61689/gplhi.html
my $is_solaris64 = (_perl_config('osname') eq 'solaris' && _perl_config('ptrsize') == 8);
# PkgConfig.pm is more reliable on windows
my $is_windows = _perl_config('osname') eq 'MSWin32';
if(!$is_solaris64 && !$is_windows)
{
return 'PkgConfig::CommandLine';
}
}
if(Alien::Build::Plugin::PkgConfig::PP->available)
{
return 'PkgConfig::PP';
}
else
{
# this is a fata error. because we check for a pkg-config implementation
# at configure time, we expect at least one of these to work. (and we
# fallback on installing PkgConfig.pm as a prereq if nothing else is avail).
# we therefore expect at least one of these to work, if not, then the configuration
# of the system has shifted from underneath us.
Carp::croak("Could not find an appropriate pkg-config or pkgconf implementation, please install PkgConfig.pm, PkgConfig::LibPkgConf, pkg-config or pkgconf");
}
}
sub init
{
my($self, $meta) = @_;
my $plugin = $self->pick;
Alien::Build->log("Using PkgConfig plugin: $plugin");
if(ref($self->pkg_name) eq 'ARRAY')
{
$meta->add_requires('configure', 'Alien::Build::Plugin::PkgConfig::Negotiate' => '0.79');
}
if($self->atleast_version || $self->exact_version || $self->max_version)
{
$meta->add_requires('configure', 'Alien::Build::Plugin::PkgConfig::Negotiate' => '1.53');
}
my @args;
push @args, pkg_name => $self->pkg_name;
push @args, register_prereqs => 0;
foreach my $method (map { "${_}_version" } qw( minimum atleast exact max ))
{
push @args, $method => $self->$method if defined $self->$method;
}
$meta->apply_plugin($plugin, @args);
$self;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::PkgConfig::Negotiate - Package configuration negotiation plugin
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'PkgConfig' => (
pkg_name => 'libfoo',
);
=head1 DESCRIPTION
This plugin provides Probe and Gather steps for pkg-config based packages. It picks
the best C<PkgConfig> plugin depending your platform and environment.
=head1 PROPERTIES
=head2 pkg_name
The package name.
=head2 atleast_version
The minimum required version that is acceptable version as provided by the system.
=head2 exact_version
The exact required version that is acceptable version as provided by the system.
=head2 max_version
The max required version that is acceptable version as provided by the system.
=head2 minimum_version
Alias for C<atleast_version> for backward compatibility.
=head1 METHODS
=head2 pick
my $name = Alien::Build::Plugijn::PkgConfig::Negotiate->pick;
Returns the name of the negotiated plugin.
=head1 ENVIRONMENT
=over 4
=item ALIEN_BUILD_PKG_CONFIG
If set, this plugin will be used instead of the build in logic
which attempts to automatically pick the best plugin.
=back
=head1 SEE ALSO
L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,313 @@
package Alien::Build::Plugin::PkgConfig::PP;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Carp ();
use File::Which ();
use Env qw( @PKG_CONFIG_PATH );
# ABSTRACT: Probe system and determine library or tool properties using PkgConfig.pm
our $VERSION = '2.38'; # VERSION
has '+pkg_name' => sub {
Carp::croak "pkg_name is a required property";
};
has atleast_version => undef;
has exact_version => undef;
has max_version => undef;
has minimum_version => undef;
use constant _min_version => '0.14026';
# private for now, used by negotiator
has register_prereqs => 1;
sub available
{
!!eval { require PkgConfig; PkgConfig->VERSION(_min_version) };
}
sub _cleanup
{
my($value) = @_;
$value =~ s{\s*$}{ };
$value;
}
sub init
{
my($self, $meta) = @_;
unless(defined $meta->prop->{env}->{PKG_CONFIG})
{
# TODO: Better would be to to "execute" lib/PkgConfig.pm
# as that should always be available, and will match the
# exact version of PkgConfig.pm that we are using here.
# there are a few corner cases to deal with before we
# can do this. What is here should handle most use cases.
my $command_line =
File::Which::which('ppkg-config')
? 'ppkg-config'
: File::Which::which('pkg-config.pl')
? 'pkg-config.pl'
: File::Which::which('pkg-config')
? 'pkg-config'
: undef;
$meta->prop->{env}->{PKG_CONFIG} = $command_line
if defined $command_line;
}
if($self->register_prereqs)
{
$meta->add_requires('configure' => 'PkgConfig' => _min_version);
}
my($pkg_name, @alt_names) = (ref $self->pkg_name) ? (@{ $self->pkg_name }) : ($self->pkg_name);
$meta->register_hook(
probe => sub {
my($build) = @_;
$build->runtime_prop->{legacy}->{name} ||= $pkg_name;
$build->hook_prop->{probe_class} = __PACKAGE__;
$build->hook_prop->{probe_instance_id} = $self->instance_id;
require PkgConfig;
my $pkg = PkgConfig->find($pkg_name);
die "package @{[ $pkg_name ]} not found" if $pkg->errmsg;
$build->hook_prop->{version} = $pkg->pkg_version;
my $version = PkgConfig::Version->new($pkg->pkg_version);
my $atleast_version = $self->atleast_version;
$atleast_version = $self->minimum_version unless defined $atleast_version;
if(defined $atleast_version)
{
my $need = PkgConfig::Version->new($atleast_version);
if($version < $need)
{
die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but at least $atleast_version is required.";
}
}
if(defined $self->exact_version)
{
my $need = PkgConfig::Version->new($self->exact_version);
if($version != $need)
{
die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but exactly @{[ $self->exact_version ]} is required.";
}
}
if(defined $self->max_version)
{
my $need = PkgConfig::Version->new($self->max_version);
if($version > $need)
{
die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but max of @{[ $self->max_version ]} is required.";
}
}
foreach my $alt (@alt_names)
{
my $pkg = PkgConfig->find($alt);
die "package $alt not found" if $pkg->errmsg;
}
'system';
},
);
$meta->register_hook(
$_ => sub {
my($build) = @_;
return if $build->hook_prop->{name} eq 'gather_system'
&& ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id;
require PkgConfig;
foreach my $name ($pkg_name, @alt_names)
{
require PkgConfig;
my $pkg = PkgConfig->find($name, search_path => [@PKG_CONFIG_PATH]);
if($pkg->errmsg)
{
$build->log("Trying to load the pkg-config information from the source code build");
$build->log("of your package failed");
$build->log("You are currently using the pure-perl implementation of pkg-config");
$build->log("(AB Plugin is named PkgConfig::PP, which uses PkgConfig.pm");
$build->log("It may work better with the real pkg-config.");
$build->log("Try installing your OS' version of pkg-config or unset ALIEN_BUILD_PKG_CONFIG");
die "second load of PkgConfig.pm @{[ $name ]} failed: @{[ $pkg->errmsg ]}"
}
my %prop;
$prop{cflags} = _cleanup scalar $pkg->get_cflags;
$prop{libs} = _cleanup scalar $pkg->get_ldflags;
$prop{version} = $pkg->pkg_version;
$pkg = PkgConfig->find($name, static => 1, search_path => [@PKG_CONFIG_PATH]);
$prop{cflags_static} = _cleanup scalar $pkg->get_cflags;
$prop{libs_static} = _cleanup scalar $pkg->get_ldflags;
$build->runtime_prop->{alt}->{$name} = \%prop;
}
foreach my $key (keys %{ $build->runtime_prop->{alt}->{$pkg_name} })
{
$build->runtime_prop->{$key} = $build->runtime_prop->{alt}->{$pkg_name}->{$key};
}
if(keys %{ $build->runtime_prop->{alt} } == 1)
{
delete $build->runtime_prop->{alt};
}
}
) for qw( gather_system gather_share );
$self;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::PkgConfig::PP - Probe system and determine library or tool properties using PkgConfig.pm
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'PkgConfig::PP' => (
pkg_name => 'libfoo',
);
=head1 DESCRIPTION
Note: in most case you will want to use L<Alien::Build::Plugin::PkgConfig::Negotiate>
instead. It picks the appropriate fetch plugin based on your platform and environment.
In some cases you may need to use this plugin directly instead.
This plugin provides Probe and Gather steps for pkg-config based packages. It uses
L<PkgConfig> to accomplish this task.
=head1 PROPERTIES
=head2 pkg_name
The package name. If this is a list reference then .pc files with all those package
names must be present.
=head2 atleast_version
The minimum required version that is acceptable version as provided by the system.
=head2 exact_version
The exact required version that is acceptable version as provided by the system.
=head2 max_version
The max required version that is acceptable version as provided by the system.
=head2 minimum_version
Alias for C<atleast_version> for backward compatibility.
=head1 METHODS
=head2 available
my $bool = Alien::Build::Plugin::PkgConfig::PP->available;
Returns true if the necessary prereqs for this plugin are I<already> installed.
=head1 SEE ALSO
L<Alien::Build::Plugin::PkgConfig::Negotiate>, L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut