Annotation of src/usr.bin/pkg-config/pkg-config, Revision 1.42
1.1 ckuethe 1: #!/usr/bin/perl
1.42 ! espie 2: # $OpenBSD: pkg-config,v 1.41 2011/03/18 18:21:40 jasper Exp $
1.40 jasper 3: # $CSK: pkgconfig.pl,v 1.39 2006/11/27 16:26:20 ckuethe Exp $
1.1 ckuethe 4:
5: # Copyright (c) 2006 Chris Kuethe <ckuethe@openbsd.org>
1.40 jasper 6: # Copyright (c) 2011 Jasper Lievisse Adriaanse <jasper@openbsd.org>
1.1 ckuethe 7: #
8: # Permission to use, copy, modify, and distribute this software for any
9: # purpose with or without fee is hereby granted, provided that the above
10: # copyright notice and this permission notice appear in all copies.
11: #
12: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19:
20: use strict;
21: use warnings;
22: use Getopt::Long;
1.4 espie 23: use File::Basename;
1.11 espie 24: use OpenBSD::PkgConfig;
1.1 ckuethe 25:
1.27 jasper 26: my @PKGPATH = qw(/usr/lib/pkgconfig /usr/local/lib/pkgconfig /usr/X11R6/lib/pkgconfig);
1.1 ckuethe 27:
1.16 espie 28: if (defined($ENV{PKG_CONFIG_LIBDIR}) && $ENV{PKG_CONFIG_LIBDIR}) {
29: @PKGPATH = split /:/, $ENV{PKG_CONFIG_LIBDIR};
30: } elsif (defined($ENV{PKG_CONFIG_PATH}) && $ENV{PKG_CONFIG_PATH}) {
1.24 ckuethe 31: unshift(@PKGPATH, split /:/, $ENV{PKG_CONFIG_PATH});
1.1 ckuethe 32: }
33:
34: my $logfile = '';
1.16 espie 35: if (defined($ENV{PKG_CONFIG_LOGFILE}) && $ENV{PKG_CONFIG_LOGFILE}) {
36: $logfile = $ENV{PKG_CONFIG_LOGFILE};
1.1 ckuethe 37: }
38:
1.33 jasper 39: my $allow_uninstalled =
1.16 espie 40: defined $ENV{PKG_CONFIG_DISABLE_UNINSTALLED} ? 0 : 1;
1.14 espie 41: my $found_uninstalled = 0;
42:
1.32 jasper 43: my $version = 0.23; # pretend to be this version of pkgconfig
1.10 espie 44:
45: my %configs = ();
1.35 espie 46: setup_self();
47:
1.10 espie 48: my %mode = ();
1.11 espie 49: my $variables = {};
1.10 espie 50: my $D = 0; # debug flag
1.1 ckuethe 51:
1.35 espie 52: $variables->{pc_top_builddir} = $ENV{PKG_CONFIG_TOP_BUILD_DIR} //
53: '$(top_builddir)';
54:
55: $variables->{pc_sysrootdir} //= $ENV{PKG_CONFIG_SYSROOT_DIR};
56: # The default '/' is implied.
1.29 jasper 57:
1.35 espie 58: $D = 1 if defined $ENV{PKG_CONFIG_DEBUG_SPEW};
1.7 ckuethe 59:
1.4 espie 60: if ($logfile) {
1.35 espie 61: open my $L, ">>" , $logfile or die;
62: print $L beautify_list($_, @ARGV), "\n";
1.4 espie 63: close $L;
1.1 ckuethe 64: }
65:
66: # combo arg-parsing and dependency resolution loop. Hopefully when the loop
67: # terminates, we have a full list of packages upon which we depend, and the
68: # right set of compiler and linker flags to use them.
69: #
70: # as each .pc file is loaded, it is stored in %configs, indexed by package
71: # name. this makes it possible to then pull out flags or do substitutions
1.34 jasper 72: # without having to go back and reload the files from disk.
1.1 ckuethe 73:
74: Getopt::Long::Configure('no_ignore_case');
75: GetOptions( 'debug' => \$D,
76: 'help' => \&help, #does not return
77: 'usage' => \&help, #does not return
1.14 espie 78: 'list-all' => \$mode{list},
1.1 ckuethe 79: 'version' => sub { print "$version\n" ; exit(0);} ,
1.11 espie 80: 'errors-to-stdout' => sub { $mode{estdout} = 1},
81: 'print-errors' => sub { $mode{printerr} = 1},
82: 'silence-errors' => sub { $mode{printerr} = 0},
1.23 jasper 83: 'short-errors' => sub { $mode{printerr} = 0},
1.14 espie 84: 'atleast-pkgconfig-version=s' => \$mode{myminvers},
1.30 jasper 85: 'print-provides' => \$mode{printprovides},
86: 'print-requires' => \$mode{printrequires},
87: 'print-requires-private' => \$mode{printrequiresprivate},
1.11 espie 88:
89: 'cflags' => sub { $mode{cflags} = 3},
90: 'cflags-only-I' => sub { $mode{cflags} |= 1},
91: 'cflags-only-other' => sub { $mode{cflags} |= 2},
92: 'libs' => sub { $mode{libs} = 7},
93: 'libs-only-l' => sub { $mode{libs} |= 1},
94: 'libs-only-L' => sub { $mode{libs} |= 2},
95: 'libs-only-other' => sub { $mode{libs} |= 4},
96: 'exists' => sub { $mode{exists} = 1} ,
97: 'static' => sub { $mode{static} = 1},
98: 'uninstalled' => sub { $mode{uninstalled} = 1},
1.14 espie 99: 'atleast-version=s' => \$mode{minversion},
100: 'exact-version=s' => \$mode{exactversion},
101: 'max-version=s' => \$mode{maxversion},
1.13 espie 102: 'modversion' => \$mode{modversion},
1.11 espie 103: 'variable=s' => \$mode{variable},
104: 'define-variable=s' => $variables,
1.1 ckuethe 105: );
106:
1.14 espie 107: # Initial value of printerr depends on the options...
108: if (!defined $mode{printerr}) {
1.33 jasper 109: if (defined $mode{libs} || defined $mode{cflags}
1.14 espie 110: || defined $mode{version} || defined $mode{list}) {
111: $mode{printerr} = 1;
112: } else {
113: $mode{printerr} = 0;
114: }
115: }
116:
1.35 espie 117: print STDERR "\n", beautify_list($0, @ARGV), "\n" if $D;
1.13 espie 118:
119: my $rc = 0;
1.1 ckuethe 120:
1.14 espie 121: # XXX pkg-config is a bit weird
1.10 espie 122: {
123: my $p = join(' ', @ARGV);
1.14 espie 124: $p =~ s/^\s+//;
1.35 espie 125: @ARGV = split /\,?\s+/, $p;
1.10 espie 126: }
1.1 ckuethe 127:
1.14 espie 128: if ($mode{myminvers}) {
129: exit self_version($mode{myminvers});
130: }
131:
132: if ($mode{list}) {
133: exit do_list();
1.1 ckuethe 134: }
135:
1.13 espie 136: my $cfg_full_list = [];
1.14 espie 137: my $top_config = [];
1.1 ckuethe 138:
139: while (@ARGV){
1.13 espie 140: my $p = shift @ARGV;
141: my $op = undef;
142: my $v = undef;
1.35 espie 143: if (@ARGV >= 2 && $ARGV[0] =~ /^[<=>]+$/ &&
1.42 ! espie 144: $ARGV[1] =~ /^[\d\.]+\w?$/) {
1.13 espie 145: $op = shift @ARGV;
146: $v = shift @ARGV;
1.1 ckuethe 147: }
1.13 espie 148: handle_config($p, $op, $v, $cfg_full_list);
1.14 espie 149: push(@$top_config, $p);
150: }
151:
152: if ($mode{exists}) {
153: exit $rc;
154: }
155:
156: if ($mode{uninstalled}) {
157: $rc = 1 unless $found_uninstalled;
158: exit $rc;
1.11 espie 159: }
1.1 ckuethe 160:
1.30 jasper 161: if ($mode{modversion} || $mode{printprovides}) {
1.14 espie 162: for my $pkg (@$top_config) {
163: do_modversion($pkg);
164: }
165: }
1.13 espie 166:
1.30 jasper 167: if ($mode{printrequires} || $mode{printrequiresprivate}) {
168: for my $pkg (@$top_config) {
169: print_requires($pkg);
170: }
171: }
172:
1.14 espie 173: if ($mode{minversion}) {
174: my $v = $mode{minversion};
175: for my $pkg (@$top_config) {
176: $rc = 1 unless versionmatch($configs{$pkg}, '>=', $v);
177: }
178: exit $rc;
179: }
180:
181: if ($mode{exactversion}) {
182: my $v = $mode{exactversion};
183: for my $pkg (@$top_config) {
184: $rc = 1 unless versionmatch($configs{$pkg}, '=', $v);
185: }
186: exit $rc;
187: }
188:
189: if ($mode{minversion}) {
190: my $v = $mode{maxversion};
191: for my $pkg (@$top_config) {
192: $rc = 1 unless versionmatch($configs{$pkg}, '<=', $v);
193: }
194: exit $rc;
195: }
196:
197: my @vlist = ();
198:
199: if ($mode{variable}) {
200: for my $pkg (@$top_config) {
201: do_variable($pkg, $mode{variable});
202: }
203: }
204:
205: my $dep_cfg_list = simplify_and_reverse($cfg_full_list);
206:
207: if ($mode{cflags} || $mode{libs} || $mode{variable}) {
208: push @vlist, do_cflags($dep_cfg_list) if $mode{cflags};
209: push @vlist, do_libs($dep_cfg_list) if $mode{libs};
1.17 espie 210: print join(' ', @vlist), "\n" if $rc == 0;
1.1 ckuethe 211: }
212:
1.13 espie 213: exit $rc;
1.1 ckuethe 214:
215: ###########################################################################
216:
1.11 espie 217: sub handle_config
218: {
1.13 espie 219: my ($p, $op, $v, $list) = @_;
1.35 espie 220: my $cfg = cache_find_config($p);
1.13 espie 221:
1.35 espie 222: unshift @$list, $p if defined $cfg;
1.11 espie 223:
1.35 espie 224: if (!defined $cfg) {
225: $rc = 1;
226: return undef;
227: }
1.15 espie 228:
1.35 espie 229: if (defined $op) {
230: if (!versionmatch($cfg, $op, $v)) {
231: mismatch($p, $cfg, $op, $v) if $mode{printerr};
1.13 espie 232: $rc = 1;
233: return undef;
234: }
1.35 espie 235: }
1.11 espie 236:
1.35 espie 237: my $deps = $cfg->get_property('Requires', $variables);
238: if (defined $deps) {
239: for my $dep (@$deps) {
240: if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+)$/) {
241: handle_config($1, $2, $3, $list);
242: } else {
243: handle_config($dep, undef, undef, $list);
1.26 jasper 244: }
245: }
1.35 espie 246: print STDERR "package $p requires ",
247: join(',', @$deps), "\n" if $D;
248: }
1.26 jasper 249:
1.35 espie 250: $deps = $cfg->get_property('Requires.private', $variables);
251: if (defined $deps) {
252: for my $dep (@$deps) {
253: if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+)$/) {
254: handle_config($1, $2, $3, $list);
255: } else {
256: handle_config($dep, undef, undef, $list);
1.13 espie 257: }
258: }
1.35 espie 259: print STDERR "package $p requires (private)",
260: join(',', @$deps), "\n" if $D;
1.11 espie 261: }
262: }
263:
1.1 ckuethe 264: # look for the .pc file in each of the PKGPATH elements. Return the path or
265: # undef if it's not there
1.4 espie 266: sub pathresolve
267: {
268: my ($p) = @_;
269:
1.14 espie 270: if ($allow_uninstalled && $p !~ m/\-uninstalled$/) {
271: foreach my $d (@PKGPATH) {
272: my $f = "$d/$p-uninstalled.pc";
273: print STDERR "pathresolve($p) looking in $f\n" if $D;
274: if (-f $f) {
275: $found_uninstalled = 1;
276: return $f;
277: }
278: }
279: }
280:
1.4 espie 281: foreach my $d (@PKGPATH) {
1.10 espie 282: my $f = "$d/$p.pc";
1.4 espie 283: print STDERR "pathresolve($p) looking in $f\n" if $D;
1.10 espie 284: return $f if -f $f;
1.1 ckuethe 285: }
1.10 espie 286: return undef;
1.1 ckuethe 287: }
288:
1.11 espie 289: sub get_config
290: {
291: my ($f) = @_;
292:
293: my $cfg;
1.33 jasper 294: eval {
1.11 espie 295: $cfg = OpenBSD::PkgConfig->read_file($f);
296: };
297: if (!$@) {
1.37 jasper 298: return validate_config($f, $cfg);
1.11 espie 299: } else {
1.12 espie 300: print STDERR $@, "\n" if $D;
1.11 espie 301: }
302: return undef;
303: }
304:
1.13 espie 305: sub cache_find_config
306: {
307: my $name = shift;
308:
309: print STDERR "processing $name\n" if $D;
310:
311: if (exists $configs{$name}) {
312: return $configs{$name};
313: } else {
314: return $configs{$name} = find_config($name);
315: }
1.37 jasper 316: }
317:
318: # Required elements for a valid .pc file: Name, Description, Version
319: sub validate_config
320: {
321: my ($f, $cfg) = @_;
322: my @required_elems = ('Name', 'Description', 'Version');
323: my $e;
324:
325: foreach (@required_elems) {
326: $e = $cfg->get_property($_, $variables);
327: if (!defined $e) {
1.39 jasper 328: $f =~ s/(^.*\/)(.*?)\.pc$/$2/g;
329: print STDERR "Package '$f' has no $_: field\n";
1.37 jasper 330: return undef;
331: }
332: }
333:
334: return $cfg;
1.13 espie 335: }
336:
1.35 espie 337: # pkg-config won't install a pkg-config.pc file itself, but it may be
338:
339: # listed as a dependency in other files.
340: # so, prime the cache with self
341: sub setup_self
342: {
343: my $pkg_pc = OpenBSD::PkgConfig->new;
344: $pkg_pc->add_property('Version', $version);
1.38 jasper 345: $pkg_pc->add_variable('pc_path', join(":", @PKGPATH));
1.35 espie 346: $configs{'pkg-config'} = $pkg_pc;
347: }
348:
1.11 espie 349: sub find_config
350: {
351: my ($p) = @_;
352: my $f = pathresolve($p);
353: if (defined $f) {
354: return get_config($f);
355: }
1.13 espie 356: if ($mode{printerr}) {
1.33 jasper 357: print STDERR
1.13 espie 358: "Package $p was not found in the pkg-config search path\n";
359: }
1.11 espie 360: return undef;
361: }
1.1 ckuethe 362:
1.11 espie 363: sub stringize
1.4 espie 364: {
1.11 espie 365: my $list = shift;
1.21 simon 366: my $sep = shift || ',';
1.4 espie 367:
1.11 espie 368: if (defined $list) {
1.21 simon 369: return join($sep, @$list)
1.11 espie 370: } else {
371: return '';
1.1 ckuethe 372: }
373: }
374:
375: #if the variable option is set, pull out the named variable
1.4 espie 376: sub do_variable
377: {
1.11 espie 378: my ($p, $v) = @_;
1.1 ckuethe 379:
1.13 espie 380: my $cfg = cache_find_config($p);
381:
382: if (defined $cfg) {
1.11 espie 383: my $value = $cfg->get_variable($v, $variables);
384: if (defined $value) {
1.13 espie 385: push(@vlist, $value);
1.11 espie 386: }
1.19 espie 387: return undef;
1.11 espie 388: }
1.19 espie 389: $rc = 1;
1.1 ckuethe 390: }
391:
1.30 jasper 392: #if the modversion or print-provides options are set,
393: #pull out the compiler flags
1.4 espie 394: sub do_modversion
395: {
1.11 espie 396: my ($p) = @_;
1.1 ckuethe 397:
1.13 espie 398: my $cfg = cache_find_config($p);
399:
400: if (defined $cfg) {
1.11 espie 401: my $value = $cfg->get_property('Version', $variables);
402: if (defined $value) {
1.30 jasper 403: if (!defined($mode{printprovides})){
404: print stringize($value), "\n";
405: return undef;
406: } else {
407: print "$p = " . stringize($value) . "\n";
408: return undef;
409: }
1.11 espie 410: }
411: }
1.13 espie 412: $rc = 1;
1.1 ckuethe 413: }
414:
415: #if the cflags option is set, pull out the compiler flags
1.4 espie 416: sub do_cflags
417: {
1.14 espie 418: my $list = shift;
419:
1.11 espie 420: my $cflags = [];
1.1 ckuethe 421:
1.14 espie 422: foreach my $pkg (@$list) {
1.11 espie 423: my $l = $configs{$pkg}->get_property('Cflags', $variables);
424: push(@$cflags, @$l) if defined $l;
425: }
1.32 jasper 426: my $a = OpenBSD::PkgConfig->compress($cflags,
1.11 espie 427: sub {
428: local $_ = shift;
429: if (($mode{cflags} & 1) && /^-I/ ||
430: ($mode{cflags} & 2) && !/^-I/) {
431: return 1;
432: } else {
433: return 0;
1.4 espie 434: }
1.11 espie 435: });
1.32 jasper 436: if (defined($a) && defined($variables->{pc_sysrootdir})){
1.36 jasper 437: $a =~ s/[\w]?-I/$&$variables->{pc_sysrootdir}/g;
1.32 jasper 438: }
439:
440: return $a;
1.1 ckuethe 441: }
442:
443: #if the lib option is set, pull out the linker flags
1.4 espie 444: sub do_libs
445: {
1.14 espie 446: my $list = shift;
447:
1.11 espie 448: my $libs = [];
1.1 ckuethe 449:
1.14 espie 450: foreach my $pkg (@$list) {
1.11 espie 451: my $l = $configs{$pkg}->get_property('Libs', $variables);
452: push(@$libs, @$l) if defined $l;
453: }
1.13 espie 454: my $a = OpenBSD::PkgConfig->compress($libs,
1.11 espie 455: sub {
456: local $_ = shift;
1.13 espie 457: if (($mode{libs} & 2) && /^-L/ ||
1.11 espie 458: ($mode{libs} & 4) && !/^-[lL]/) {
459: return 1;
460: } else {
461: return 0;
1.4 espie 462: }
1.11 espie 463: });
1.32 jasper 464:
465: if (defined($variables->{pc_sysrootdir})){
1.36 jasper 466: $a =~ s/[\w]?-[lL]/$&$variables->{pc_sysrootdir}/g;
1.32 jasper 467: }
468:
1.13 espie 469: if ($mode{libs} & 1) {
470: my $b = OpenBSD::PkgConfig->rcompress($libs,
471: sub { shift =~ m/^-l/; });
472: return ($a, $b);
473: } else {
474: return $a;
475: }
1.1 ckuethe 476: }
477:
478: #list all packages
1.4 espie 479: sub do_list
480: {
1.1 ckuethe 481: my ($p, $x, $y, @files, $fname, $name);
1.20 espie 482: my $error = 0;
483:
1.33 jasper 484: foreach my $p (@PKGPATH) {
485: push(@files, <$p/*.pc>);
1.4 espie 486: }
1.1 ckuethe 487:
488: # Scan the lengths of the package names so I can make a format
489: # string to line the list up just like the real pkgconfig does.
490: $x = 0;
1.4 espie 491: foreach my $f (@files) {
492: $fname = basename($f, '.pc');
493: $y = length $fname;
1.1 ckuethe 494: $x = (($y > $x) ? $y : $x);
495: }
496: $x *= -1;
497:
1.4 espie 498: foreach my $f (@files) {
1.11 espie 499: my $cfg = get_config($f);
1.20 espie 500: if (!defined $cfg) {
501: print STDERR "Problem reading file $f\n";
502: $error = 1;
503: next;
504: }
1.4 espie 505: $fname = basename($f, '.pc');
1.33 jasper 506: printf("%${x}s %s - %s\n", $fname,
507: stringize($cfg->get_property('Name', $variables)),
1.21 simon 508: stringize($cfg->get_property('Description', $variables),
509: ' '));
1.1 ckuethe 510: }
1.20 espie 511: return $error;
1.1 ckuethe 512: }
513:
1.4 espie 514: sub help
515: {
1.1 ckuethe 516: print <<EOF
517: Usage: $0 [options]
518: --debug - turn on debugging output
519: --help - this message
520: --usage - this message
521: --list-all - show all packages that $0 can find
1.8 ckuethe 522: --version - print version of pkgconfig
523: --errors-to-stdout - direct error messages to stdout rather than stderr
524: --print-errors - print error messages in case of error
1.34 jasper 525: --print-provides - print all the modules the given package provides
526: --print-requires - print all the modules the given package requires
527: --print-requires-private - print all the private modules the given package requires
1.8 ckuethe 528: --silence-errors - don't print error messages in case of error
1.1 ckuethe 529: --atleast-pkgconfig-version [version] - require a certain version of pkgconfig
530: --cflags package [versionspec] [package [versionspec]]
531: --cflags-only-I - only output -Iincludepath flags
532: --cflags-only-other - only output flags that are not -I
1.11 espie 533: --define-variable=NAME=VALUE - define variables
1.1 ckuethe 534: --libs package [versionspec] [package [versionspec]]
535: --libs-only-l - only output -llib flags
536: --libs-only-L - only output -Llibpath flags
537: --libs-only-other - only output flags that are not -l or -L
538: --exists package [versionspec] [package [versionspec]]
539: --uninstalled - allow for uninstalled versions to be used
1.8 ckuethe 540: --static - adjust output for static linking
541: --atleast-version [version] - require a certain version of a package
542: --modversion [package] - query the version of a package
543: --variable var package - return the definition of <var> in <package>
1.1 ckuethe 544: EOF
545: ;
1.22 simon 546: exit 0;
1.1 ckuethe 547: }
548:
549: # do we meet/beat the version the caller requested?
1.4 espie 550: sub self_version
551: {
552: my ($v) = @_;
553: my (@a, @b);
554:
555: @a = split /\./, $v;
556: @b = split /\./, $version;
1.1 ckuethe 557:
1.4 espie 558: if (($b[0] >= $a[0]) && ($b[1] >= $a[1])) {
1.14 espie 559: return 0;
1.1 ckuethe 560: } else {
1.14 espie 561: return 1;
562: }
563: }
564:
565: sub compare
566: {
567: my ($a, $b) = @_;
568:
1.28 jasper 569: return 0 if ($a eq $b);
1.14 espie 570:
571: my @a = split /\./, $a;
572: my @b = split /\./, $b;
573:
574: while (@a && @b) { #so long as both lists have something
575: return 1 if $a[0] > $b[0];
576: return -1 if $a[0] < $b[0];
577: shift @a; shift @b;
578: }
579: return 1 if @a;
580: return -1 if @b;
581: return 0;
1.1 ckuethe 582: }
583:
584: # got a package meeting the requested specific version?
1.4 espie 585: sub versionmatch
586: {
1.14 espie 587: my ($cfg, $op, $want) = @_;
1.33 jasper 588:
1.1 ckuethe 589: # can't possibly match if we can't find the file
1.11 espie 590: return 0 if !defined $cfg;
591:
1.14 espie 592: my $inst = stringize($cfg->get_property('Version', $variables));
1.11 espie 593:
1.1 ckuethe 594: # can't possibly match if we can't find the version string
1.14 espie 595: return 0 if $inst eq '';
1.1 ckuethe 596:
1.14 espie 597: print "comparing $want (wanted) to $inst (installed)\n" if $D;
598: my $value = compare($inst, $want);
1.31 jasper 599: if ($op eq '>=') { return $value >= 0; }
600: elsif ($op eq '=') { return $value == 0; }
601: elsif ($op eq '!=') { return $value != 0; }
602: elsif ($op eq '<') { return $value < 0; }
603: elsif ($op eq '>') { return $value > 0; }
604: elsif ($op eq '<=') { return $value <= 0; }
1.13 espie 605: }
606:
607: sub mismatch
608: {
609: my ($p, $cfg, $op, $v) = @_;
1.41 jasper 610: my $name = stringize($cfg->get_property('Name'));
611: my $version = stringize($cfg->get_property('Version'));
612: my $url = stringize($cfg->get_property('URL'));
613:
614: print STDERR "Requested '$p $op $v' but version of $name is $version\n";
615: print STDERR "You may find new versions of $name at $url\n" if $url;
1.13 espie 616: }
617:
618: sub simplify_and_reverse
619: {
620: my $reqlist = shift;
621: my $dejavu = {};
622: my $result = [];
623:
624: for my $item (@$reqlist) {
625: if (!$dejavu->{$item}) {
626: unshift @$result, $item;
627: $dejavu->{$item} = 1;
628: }
629: }
630: return $result;
1.30 jasper 631: }
632:
633: # retrieve and print Requires(.private)
634: sub print_requires
635: {
636: my ($p) = @_;
637:
638: my $cfg = cache_find_config($p);
639:
640: if (defined($cfg)) {
641: my $value;
642:
643: if (defined($mode{printrequires})) {
644: $value = $cfg->get_property('Requires', $variables);
645: } elsif (defined($mode{printrequiresprivate})) {
646: $value = $cfg->get_property('Requires.private', $variables);
647: } else {
648: print STDERR "Unknown mode for print_requires.\n" if $D;
649: return 1;
650: }
651:
652: if (defined($value)) {
653: print "$_\n" foreach (@$value);
654: return undef;
655: }
656: }
657:
658: $rc = 1;
1.35 espie 659: }
660:
661: sub beautify_list
662: {
663: return join(' ', map {"[$_]"} @_);
1.1 ckuethe 664: }