2 # Simple pkg-config implementation in perl
3 # jelmer@samba.org, November 2006
8 my @dirs = split(/:/, $ENV{PKG_CONFIG_PATH
});
15 my $result = GetOptions
(
16 'help|h|?' => \
$opt_help,
17 'static' => \
$opt_static,
19 'cflags' => \
$opt_cflags
27 print "pkg-config replacement in perl\n";
28 print "Copyright (C) 2006 Jelmer Vernooij <jelmer\@samba.org>\n";
30 print "Usage: pkg-config [OPTIONS] PACKAGE...\n";
31 print " --help Print this help message\n";
32 print " --static Print flags for static libraries\n";
33 print " --libs Print linker flags\n";
34 print " --cflags Print C compiler flags\n";
42 foreach my $dir (@dirs) {
43 if (-f
"$dir/$name-uninstalled.pc") {
44 return "$dir/$name-uninstalled.pc";
47 foreach my $dir (@dirs) {
48 if (-f
"$dir/$name.pc" ) {
49 return "$dir/$name.pc";
52 die("No such package `$name'");
57 my ($expr, $vars) = @_;
61 while (/(.*)\${([^}]+)}(.*)/) {
62 $_ = "$1$vars->{$2}$3";
71 my $path = find_path
($name);
75 open(IN
, "<$path") or die("Unable to open $path: $!");
79 if (/^([A-Za-z.]+): (.*)$/) {
80 $fields{$1} = ReplaceVars
($2, \
%variables);
81 } elsif (/^([A-Za-z_]+)=(.*)$/) {
82 $variables{$1} = ReplaceVars
($2, \
%variables);
83 } elsif (/^[ \t]*$/) {
85 warn("$path:$lineno: parse error");
95 my $fields = Parse
($name);
96 my @cflags = split(/ /, $fields->{Cflags
});
97 foreach (split(/[, ]/, $fields->{Requires
})) {
98 push (@cflags, Cflags
($_));
106 my $fields = Parse
($name);
107 my @libs = split(/ /, $fields->{Libs
});
108 foreach (split(/[, ]/, $fields->{Requires
})) {
109 push (@libs, Libs
($_));
112 foreach (split(/[ ,]/, $fields->{"Requires.private"})) {
113 push (@libs, Libs
($_));
121 foreach my $pkg (@ARGV)
123 push (@out, Libs
($pkg)) if ($opt_libs);
124 push (@out, Cflags
($pkg)) if ($opt_cflags);
133 next if (defined($seen{$_}));
142 print join(' ', @out) . "\n";