summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2011-03-18 14:55:33 +0000
committerMarc Espie <espie@cvs.openbsd.org>2011-03-18 14:55:33 +0000
commita7111da6fde851121feee0de325938706713201a (patch)
tree67a9210bc332e5f055ab64386def27f7a0680e8a
parent79c568118348ed6eb87864727baef342b069fe37 (diff)
minor related tweaks:
- use //= instead of if (!defined) - don't special-case code for pkg-config itself, prime cache with versioning info. - more accurate regexps for parsing arguments - don't use join() when we mean map() leads to: - fix bug in argument splitting, zap ", " used as argument separation. okay jasper@, tested by landry@
-rw-r--r--usr.bin/pkg-config/pkg-config124
1 files changed, 59 insertions, 65 deletions
diff --git a/usr.bin/pkg-config/pkg-config b/usr.bin/pkg-config/pkg-config
index 01b730c25a5..49d268b7559 100644
--- a/usr.bin/pkg-config/pkg-config
+++ b/usr.bin/pkg-config/pkg-config
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $OpenBSD: pkg-config,v 1.34 2011/03/14 08:43:59 jasper Exp $
+# $OpenBSD: pkg-config,v 1.35 2011/03/18 14:55:32 espie Exp $
#$CSK: pkgconfig.pl,v 1.39 2006/11/27 16:26:20 ckuethe Exp $
# Copyright (c) 2006 Chris Kuethe <ckuethe@openbsd.org>
@@ -42,30 +42,23 @@ my $found_uninstalled = 0;
my $version = 0.23; # pretend to be this version of pkgconfig
my %configs = ();
+setup_self();
+
my %mode = ();
my $variables = {};
my $D = 0; # debug flag
-{
- my $d = $ENV{PKG_CONFIG_TOP_BUILD_DIR};
- if (defined $d) {
- $variables->{pc_top_builddir} = $d;
- } else {
- $variables->{pc_top_builddir} = '$(top_builddir)';
- }
+$variables->{pc_top_builddir} = $ENV{PKG_CONFIG_TOP_BUILD_DIR} //
+ '$(top_builddir)';
- my $s = $ENV{PKG_CONFIG_SYSROOT_DIR};
- if (defined $s) {
- $variables->{pc_sysrootdir} = $s;
- }
- # The default '/' is implied.
-}
+$variables->{pc_sysrootdir} //= $ENV{PKG_CONFIG_SYSROOT_DIR};
+# The default '/' is implied.
-$D = 1 if defined($ENV{PKG_CONFIG_DEBUG_SPEW});
+$D = 1 if defined $ENV{PKG_CONFIG_DEBUG_SPEW};
if ($logfile) {
- open my $L, ">>" . $logfile;
- print $L '[' . join('] [', $0, @ARGV) . "]\n";
+ open my $L, ">>" , $logfile or die;
+ print $L beautify_list($_, @ARGV), "\n";
close $L;
}
@@ -120,7 +113,7 @@ if (!defined $mode{printerr}) {
}
}
-print STDERR "\n[" . join('] [', $0, @ARGV) . "]\n" if $D;
+print STDERR "\n", beautify_list($0, @ARGV), "\n" if $D;
my $rc = 0;
@@ -128,7 +121,7 @@ my $rc = 0;
{
my $p = join(' ', @ARGV);
$p =~ s/^\s+//;
-@ARGV = split /\s+/, $p;
+@ARGV = split /\,?\s+/, $p;
}
if ($mode{myminvers}) {
@@ -146,12 +139,11 @@ while (@ARGV){
my $p = shift @ARGV;
my $op = undef;
my $v = undef;
- if (@ARGV >= 2 && $ARGV[0] =~ /[<=>]+/ &&
- $ARGV[1] =~ /[0-9\.]+/) {
+ if (@ARGV >= 2 && $ARGV[0] =~ /^[<=>]+$/ &&
+ $ARGV[1] =~ /^[\d\.]+$/) {
$op = shift @ARGV;
$v = shift @ARGV;
}
- $p =~ s/,//g;
handle_config($p, $op, $v, $cfg_full_list);
push(@$top_config, $p);
}
@@ -224,61 +216,47 @@ exit $rc;
sub handle_config
{
my ($p, $op, $v, $list) = @_;
- my $cfg;
+ my $cfg = cache_find_config($p);
- # pkg-config won't install a pkg-config.pc file itself, but it may be
- # listed as a dependency in other files.
- # If we encounter a dependency on pkg-config, check if our version
- # is sufficient and error out if not.
- if ($p eq "pkg-config"){
- if ($v > $version) {
- print STDERR "pkg-config version $version too old, $v required.\n" if $D;
- $rc = 1;
- return undef;
- }
- } else {
- $cfg = cache_find_config($p);
+ unshift @$list, $p if defined $cfg;
- unshift @$list, $p if defined $cfg;
+ if (!defined $cfg) {
+ $rc = 1;
+ return undef;
+ }
- if (!defined $cfg) {
+ if (defined $op) {
+ if (!versionmatch($cfg, $op, $v)) {
+ mismatch($p, $cfg, $op, $v) if $mode{printerr};
$rc = 1;
return undef;
}
+ }
- if (defined $op) {
- if (!versionmatch($cfg, $op, $v)) {
- mismatch($p, $cfg, $op, $v) if $mode{printerr};
- $rc = 1;
- return undef;
- }
- }
-
- my $deps = $cfg->get_property('Requires', $variables);
- if (defined $deps) {
- for my $dep (@$deps) {
- if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+)$/) {
- handle_config($1, $2, $3, $list);
- } else {
- handle_config($dep, undef, undef, $list);
- }
+ my $deps = $cfg->get_property('Requires', $variables);
+ if (defined $deps) {
+ for my $dep (@$deps) {
+ if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+)$/) {
+ handle_config($1, $2, $3, $list);
+ } else {
+ handle_config($dep, undef, undef, $list);
}
- print STDERR "package $p requires ",
- join(',', @$deps), "\n" if $D;
}
+ print STDERR "package $p requires ",
+ join(',', @$deps), "\n" if $D;
+ }
- $deps = $cfg->get_property('Requires.private', $variables);
- if (defined $deps) {
- for my $dep (@$deps) {
- if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+)$/) {
- handle_config($1, $2, $3, $list);
- } else {
- handle_config($dep, undef, undef, $list);
- }
+ $deps = $cfg->get_property('Requires.private', $variables);
+ if (defined $deps) {
+ for my $dep (@$deps) {
+ if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+)$/) {
+ handle_config($1, $2, $3, $list);
+ } else {
+ handle_config($dep, undef, undef, $list);
}
- print STDERR "package $p requires (private)",
- join(',', @$deps), "\n" if $D;
}
+ print STDERR "package $p requires (private)",
+ join(',', @$deps), "\n" if $D;
}
}
@@ -336,6 +314,17 @@ sub cache_find_config
}
}
+# pkg-config won't install a pkg-config.pc file itself, but it may be
+
+# listed as a dependency in other files.
+# so, prime the cache with self
+sub setup_self
+{
+ my $pkg_pc = OpenBSD::PkgConfig->new;
+ $pkg_pc->add_property('Version', $version);
+ $configs{'pkg-config'} = $pkg_pc;
+}
+
sub find_config
{
my ($p) = @_;
@@ -644,3 +633,8 @@ sub print_requires
$rc = 1;
}
+
+sub beautify_list
+{
+ return join(' ', map {"[$_]"} @_);
+}