summaryrefslogtreecommitdiff
path: root/source4/script/pkg-config
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-11-23 17:27:04 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:28:26 -0500
commit1aec9389ed5e0079ce7b69b81e5438da6ec8bde3 (patch)
treeb247580abab21bcfe95913fb11a355a462ad5b45 /source4/script/pkg-config
parent8d870db811ef4f120d7df3b3f50243b47d94da2f (diff)
downloadsamba-1aec9389ed5e0079ce7b69b81e5438da6ec8bde3.tar.gz
samba-1aec9389ed5e0079ce7b69b81e5438da6ec8bde3.tar.bz2
samba-1aec9389ed5e0079ce7b69b81e5438da6ec8bde3.zip
r19861: Add simple pkg-config replacement.
(This used to be commit a42220c35673317c637e27d59c1a307bedb711a6)
Diffstat (limited to 'source4/script/pkg-config')
-rwxr-xr-xsource4/script/pkg-config130
1 files changed, 130 insertions, 0 deletions
diff --git a/source4/script/pkg-config b/source4/script/pkg-config
new file mode 100755
index 0000000000..bb94e1514a
--- /dev/null
+++ b/source4/script/pkg-config
@@ -0,0 +1,130 @@
+#!/usr/bin/perl
+# Simple pkg-config implementation in perl
+# jelmer@samba.org, November 2006
+
+use strict;
+use Getopt::Long;
+
+my @dirs = split(/:/, $ENV{PKG_CONFIG_PATH});
+
+my $opt_help = 0;
+my $opt_libs = 0;
+my $opt_cflags = 0;
+my $opt_static = 0;
+
+my $result = GetOptions (
+ 'help|h|?' => \$opt_help,
+ 'static' => \$opt_static,
+ 'libs' => \$opt_libs,
+ 'cflags' => \$opt_cflags
+ );
+
+if (not $result) {
+ exit(1);
+}
+
+if ($opt_help) {
+ print "pkg-config replacement in perl\n";
+ print "Copyright (C) 2006 Jelmer Vernooij <jelmer\@samba.org>\n";
+ print "\n";
+ print " --help Print this help message\n";
+ print " --static Print flags for static libraries\n";
+ print " --libs Print linker flags\n";
+ print " --cflags Print C compiler flags\n";
+ print "\n";
+ exit(0);
+}
+
+sub find_path($)
+{
+ my $name = shift;
+ foreach my $dir (@dirs) {
+ if (-f "$dir/$name-uninstalled.pc") {
+ return "$dir/$name-uninstalled.pc";
+ }
+ }
+ foreach my $dir (@dirs) {
+ if (-f "$dir/$name.pc" ) {
+ return "$dir/$name.pc";
+ }
+ }
+ die("No such package `$name'");
+}
+
+sub ReplaceVars($$)
+{
+ my ($expr, $vars) = @_;
+
+ $_ = $expr;
+
+ while (/(.*)\${([^}]+)}(.*)/) {
+ $_ = "$1$vars->{$2}$3";
+ }
+
+ return $_;
+}
+
+sub Parse($)
+{
+ my $name = shift;
+ my $path = find_path($name);
+ my %variables = ();
+ my %fields = ();
+ my $lineno = 0;
+ open(IN, "<$path") or die("Unable to open $path: $!");
+ foreach (<IN>) {
+ $lineno+=1;
+ next if (/^#.*/);
+ if (/^([A-Za-z.]+): (.*)$/) {
+ $fields{$1} = ReplaceVars($2, \%variables);
+ } elsif (/^([A-Za-z_]+)=(.*)$/) {
+ $variables{$1} = ReplaceVars($2, \%variables);
+ } elsif (/^[ \t]*$/) {
+ } else {
+ warn("$path:$lineno: parse error");
+ }
+ }
+ close(IN);
+ return \%fields;
+}
+
+sub Cflags($)
+{
+ my $name = shift;
+ my $fields = Parse($name);
+ my $cflags = $fields->{Cflags};
+ foreach (split(/[, ]/, $fields->{Requires})) {
+ $cflags .= " ".Cflags($_);
+ }
+ return split(/ /, $cflags);
+}
+
+sub Libs($)
+{
+ my $name = shift;
+ my $fields = Parse($name);
+ my $libs = $fields->{Libs};
+ foreach (split(/[, ]/, $fields->{Requires})) {
+ $libs .= " ".Libs($_);
+ }
+ if ($opt_static) {
+ foreach (split(/[ ,]/, $fields->{"Requires.private"})) {
+ $libs .= " ".Libs($_);
+ }
+ }
+ return split(/ /, $libs);
+}
+
+my @out = ();
+
+foreach my $pkg (@ARGV)
+{
+ push (@out, Libs($pkg)) if ($opt_libs);
+ push (@out, Cflags($pkg)) if ($opt_cflags);
+}
+
+if ($#out >= 0) {
+ print join(' ', @out) . "\n";
+}
+
+exit 0;