=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/pkg-config/pkg-config,v retrieving revision 1.12 retrieving revision 1.13 diff -c -r1.12 -r1.13 *** src/usr.bin/pkg-config/pkg-config 2006/12/02 18:58:46 1.12 --- src/usr.bin/pkg-config/pkg-config 2006/12/04 22:05:41 1.13 *************** *** 1,5 **** #!/usr/bin/perl ! # $OpenBSD: pkg-config,v 1.12 2006/12/02 18:58:46 espie Exp $ #$CSK: pkgconfig.pl,v 1.39 2006/11/27 16:26:20 ckuethe Exp $ # Copyright (c) 2006 Chris Kuethe --- 1,5 ---- #!/usr/bin/perl ! # $OpenBSD: pkg-config,v 1.13 2006/12/04 22:05:41 espie Exp $ #$CSK: pkgconfig.pl,v 1.39 2006/11/27 16:26:20 ckuethe Exp $ # Copyright (c) 2006 Chris Kuethe *************** *** 36,42 **** my $version = 0.19; # pretend to be this version of pkgconfig my %configs = (); - my $cfg_list = []; my %mode = (); my $variables = {}; my $D = 0; # debug flag --- 36,41 ---- *************** *** 80,101 **** 'static' => sub { $mode{static} = 1}, 'uninstalled' => sub { $mode{uninstalled} = 1}, 'atleast-version=s' => \$mode{'atleast-version'}, ! 'modversion:s' => \$mode{modversion}, 'variable=s' => \$mode{variable}, 'define-variable=s' => $variables, ); print STDERR "\n[" . join('] [', $0, @ARGV) . "]\n" if $D; self_version($mode{minvers}) if $mode{minvers}; #does not return - if (defined $mode{modversion}) { - if ($mode{modversion}) { - do_modversion($mode{modversion}) ; #does not return - } else { - print $version . "\n"; - exit 0; - } - } { my $p = join(' ', @ARGV); $p =~ s/\s+/ /g; --- 79,94 ---- 'static' => sub { $mode{static} = 1}, 'uninstalled' => sub { $mode{uninstalled} = 1}, 'atleast-version=s' => \$mode{'atleast-version'}, ! 'modversion' => \$mode{modversion}, 'variable=s' => \$mode{variable}, 'define-variable=s' => $variables, ); print STDERR "\n[" . join('] [', $0, @ARGV) . "]\n" if $D; self_version($mode{minvers}) if $mode{minvers}; #does not return + my $rc = 0; + { my $p = join(' ', @ARGV); $p =~ s/\s+/ /g; *************** *** 105,177 **** if (defined $mode{exists}) { while (@ARGV) { ! if ((@ARGV >= 2) && ($ARGV[1] =~ /[<=>]+/) && ! ($ARGV[2] =~ /[0-9\.]+/)) { ! exit 1 unless versionmatch(@ARGV); ! shift @ARGV; shift @ARGV; shift @ARGV; ! } else { ! exit 1 unless pathresolve($ARGV[0]); ! shift @ARGV; } } ! exit 0; } ! do_variable($ARGV[0], $mode{variable}) if $mode{variable}; while (@ARGV){ ! my $p = $ARGV[0]; ! if ((@ARGV >= 2) && ($ARGV[1] =~ /[<=>]+/) && ! ($ARGV[2] =~ /[0-9\.]+/)) { ! shift @ARGV; ! shift @ARGV; } - shift @ARGV; $p =~ s/,//g; ! handle_config($p); } ! if ($mode{cflags} || $mode{libs}) { ! my @l = (); ! push @l, do_cflags() if $mode{cflags}; ! push @l, do_libs() if $mode{libs}; ! print join(' ', @l), "\n"; } ! exit 0; ########################################################################### sub handle_config { ! my $p = shift; - return if $configs{$p}; ! print STDERR "processing $p\n" if $D; ! my $cfg = find_config($p); ! if (!defined $cfg) { ! warn "can't find $p\n" if $mode{printerr}; ! exit 1; } - return undef if defined $mode{exists}; ! push(@$cfg_list, $p); ! $configs{$p} = $cfg; my $deps = $cfg->get_property('Requires', $variables); if (defined $deps) { ! # XXX don't handle version yet ! map { s/\s*[<=>]+\s*[\d\.]+//; handle_config($_) } @$deps; print STDERR "package $p requires ", join(',', @$deps), "\n" if $D; } $deps = $cfg->get_property('Requires.private', $variables); if (defined $deps) { ! # XXX don't handle version yet ! map { s/\s*[<=>]+\s*[\d\.]+//; handle_config($_) } @$deps; print STDERR "package $p requires (private)", join(',', @$deps), "\n" if $D; } --- 98,186 ---- if (defined $mode{exists}) { while (@ARGV) { ! my $p = shift @ARGV; ! my $cfg = cache_find_config($p); ! exit 1 if !defined $cfg; ! if (@ARGV >= 2 && $ARGV[0] =~ /[<=>]+/ && ! $ARGV[1] =~ /[0-9\.]+/) { ! $rc = 1 unless versionmatch($cfg, @ARGV); ! shift @ARGV; shift @ARGV; } } ! exit $rc; } ! my $cfg_full_list = []; ! my @vlist = (); while (@ARGV){ ! my $p = shift @ARGV; ! my $op = undef; ! my $v = undef; ! if (@ARGV >= 2 && $ARGV[0] =~ /[<=>]+/ && ! $ARGV[1] =~ /[0-9\.]+/) { ! $op = shift @ARGV; ! $v = shift @ARGV; } $p =~ s/,//g; ! handle_config($p, $op, $v, $cfg_full_list); ! do_modversion($p) if defined $mode{modversion}; ! do_variable($p, $mode{variable}) if $mode{variable}; } ! my $cfg_list = simplify_and_reverse($cfg_full_list); ! ! if ($mode{cflags} || $mode{libs}|| $mode{variable}) { ! push @vlist, do_cflags() if $mode{cflags}; ! push @vlist, do_libs() if $mode{libs}; ! print join(' ', @vlist), "\n"; } ! exit $rc; ########################################################################### sub handle_config { ! my ($p, $op, $v, $list) = @_; ! my $cfg = cache_find_config($p); ! unshift @$list, $p if defined $cfg; ! ! if (defined $op) { ! if (!versionmatch($cfg, $op, $v)) { ! mismatch($p, $cfg, $op, $v) if $mode{printerr}; ! $rc = 1; ! return undef; ! } } ! return undef if !defined $cfg; 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; } $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; } *************** *** 207,212 **** --- 216,234 ---- return undef; } + sub cache_find_config + { + my $name = shift; + + print STDERR "processing $name\n" if $D; + + if (exists $configs{$name}) { + return $configs{$name}; + } else { + return $configs{$name} = find_config($name); + } + } + sub find_config { my ($p) = @_; *************** *** 214,219 **** --- 236,245 ---- if (defined $f) { return get_config($f); } + if ($mode{printerr}) { + print STDERR + "Package $p was not found in the pkg-config search path\n"; + } return undef; } *************** *** 233,246 **** { my ($p, $v) = @_; ! if (my $cfg = find_config($p)) { my $value = $cfg->get_variable($v, $variables); if (defined $value) { ! print $value, "\n"; ! exit 1; } } ! exit 0; } #if the modversion option is set, pull out the compiler flags --- 259,274 ---- { my ($p, $v) = @_; ! my $cfg = cache_find_config($p); ! ! if (defined $cfg) { my $value = $cfg->get_variable($v, $variables); if (defined $value) { ! push(@vlist, $value); ! return undef; } } ! $rc = 1; } #if the modversion option is set, pull out the compiler flags *************** *** 248,261 **** { my ($p) = @_; ! if (my $cfg = find_config($p)) { my $value = $cfg->get_property('Version', $variables); if (defined $value) { print stringize($value), "\n"; ! exit 1; } } ! exit 0; } #if the cflags option is set, pull out the compiler flags --- 276,291 ---- { my ($p) = @_; ! my $cfg = cache_find_config($p); ! ! if (defined $cfg) { my $value = $cfg->get_property('Version', $variables); if (defined $value) { print stringize($value), "\n"; ! return undef; } } ! $rc = 1; } #if the cflags option is set, pull out the compiler flags *************** *** 288,304 **** my $l = $configs{$pkg}->get_property('Libs', $variables); push(@$libs, @$l) if defined $l; } ! return OpenBSD::PkgConfig->compress($libs, sub { local $_ = shift; ! if (($mode{libs} & 1) && /^-l/ || ! ($mode{libs} & 2) && /^-L/ || ($mode{libs} & 4) && !/^-[lL]/) { return 1; } else { return 0; } }); } #list all packages --- 318,340 ---- my $l = $configs{$pkg}->get_property('Libs', $variables); push(@$libs, @$l) if defined $l; } ! my $a = OpenBSD::PkgConfig->compress($libs, sub { local $_ = shift; ! if (($mode{libs} & 2) && /^-L/ || ($mode{libs} & 4) && !/^-[lL]/) { return 1; } else { return 0; } }); + if ($mode{libs} & 1) { + my $b = OpenBSD::PkgConfig->rcompress($libs, + sub { shift =~ m/^-l/; }); + return ($a, $b); + } else { + return $a; + } } #list all packages *************** *** 380,394 **** # got a package meeting the requested specific version? sub versionmatch { ! my ($pname, $op, $ver) = @_; ! print STDERR "pname = '$pname'\n" if $D; ! my $cfg = find_config($pname); # can't possibly match if we can't find the file return 0 if !defined $cfg; - $configs{$pname} = $cfg; - my $v = stringize($cfg->get_property('Version', $variables)); # can't possibly match if we can't find the version string --- 416,428 ---- # got a package meeting the requested specific version? sub versionmatch { ! my ($cfg, $op, $ver) = @_; ! # XXX assumes op is >= for now. ! # can't possibly match if we can't find the file return 0 if !defined $cfg; my $v = stringize($cfg->get_property('Version', $variables)); # can't possibly match if we can't find the version string *************** *** 410,413 **** --- 444,470 ---- return 0 if @want; # and after all that, the version is good enough return 1; + } + + sub mismatch + { + my ($p, $cfg, $op, $v) = @_; + print STDERR "Requested '$p $op $v' but version of ", + stringize($cfg->get_property('Name')), " is ", + stringize($cfg->get_property('Version')), "\n"; + } + + sub simplify_and_reverse + { + my $reqlist = shift; + my $dejavu = {}; + my $result = []; + + for my $item (@$reqlist) { + if (!$dejavu->{$item}) { + unshift @$result, $item; + $dejavu->{$item} = 1; + } + } + return $result; }