[BACK]Return to pkg-config CVS log [TXT][DIR] Up to [local] / src / usr.bin / pkg-config

Annotation of src/usr.bin/pkg-config/pkg-config, Revision 1.38

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