File: pkgconfig.pm

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (112 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package Alien::FFI::pkgconfig;

use strict;
use warnings;
use Config;
use IPC::Cmd ();
use Capture::Tiny qw( capture );
use Env qw( @PKG_CONFIG_PATH );
use File::Glob qw( bsd_glob );

our $VERBOSE = !!$ENV{V};

sub pkg_config_exe
{
  foreach my $cmd ($ENV{PKG_CONFIG}, qw( pkgconf pkg-config ))
  {
    next unless defined $cmd;
    return $cmd if IPC::Cmd::can_run($cmd);
  }
  return;
}

sub _pkg_config
{
  my(@args) = @_;

  local $ENV{PKG_CONFIG_PATH} = $ENV{PKG_CONFIG_PATH};

  if($^O eq 'darwin' && -d '/usr/local/Cellar/libffi')
  {
    my($dir) = bsd_glob '/usr/local/Cellar/libffi/*/lib/pkgconfig';
    push @PKG_CONFIG_PATH, $dir if $dir && -d $dir;
  }

  my $cmd = pkg_config_exe;
  if(defined $cmd)
  {
    my @cmd = ($cmd, @args);
    print "+@cmd\n" if $VERBOSE;
    my($out, $err, $ret) = capture {
      system @cmd;
      $?;
    };
    chomp $out; chomp $err;
    print "[out]\n$out\n" if $out ne '' && $VERBOSE;
    print "[err]\n$err\n" if $err ne '' && $VERBOSE;
    die "command failed" if $ret;
    my $value = $out;
    $value;
  }
  else
  {
    print "no pkg-config.\n" if $VERBOSE;
    return;
  }
}

my $version;
my $exists;
my $cflags;
my $libs;

sub exists
{
  return $exists if defined $exists;
  return $exists = '' unless pkg_config_exe;
  $exists = !!eval { _pkg_config('--exists', 'libffi'); 1 };
}

sub version
{
  unless(defined $version)
  {
    $version = _pkg_config('--modversion', 'libffi');
  }

  $version;
}

sub config
{
  my($class, $key) = @_;
  die "unimplemented for $key" unless $key eq 'version';
  $class->version;
}

sub cflags
{
  unless(defined $cflags)
  {
    $cflags = _pkg_config('--cflags', 'libffi');
  }

  $cflags;
}

sub libs
{
  unless(defined $libs)
  {
    $libs = _pkg_config('--libs', 'libffi');
  }

  $libs;
}

sub install_type {'system'}

sub runtime_prop { return {} }

1;