File: debcontrol2cmake.pl

package info (click to toggle)
pkg-kde-tools 0.19.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 916 kB
  • sloc: perl: 4,242; python: 675; ansic: 628; sh: 441; makefile: 5
file content (76 lines) | stat: -rwxr-xr-x 2,280 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl

# Copyright (C) 2011 Modestas Vainius <modax@debian.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

use strict;
use warnings;

use Dpkg::Control::Info;
use Dpkg::Control;
use Dpkg::Arch;

sub samearch {
    my $arch = shift;
    my @archlist = split(/\s+/, shift);

    foreach my $a (@archlist) {
        if (system("dpkg-architecture", "-a$arch", "-i$a") == 0) {
            return 1;
        }
    }

    return 0;
}

# Parse command line arguments
my @fields;
my $prefix = "debcontrol_";
for (my $i = 0; $i < @ARGV; $i++) {
    if ($ARGV[$i] eq "-F") {
        push @fields, $ARGV[++$i];
    } elsif ($ARGV[$i] =~ /^-F(.+)$/) {
        push @fields, $1;
    } elsif ($ARGV[$i] eq "-s") {
        $prefix = $ARGV[++$i];
    } elsif ($ARGV[$i] =~ /^-s(.+)$/) {
        $prefix = $1;
    }
}

my $arch = Dpkg::Arch::get_build_arch();

# Retrieve requested fields and generate set statements
my $control = Dpkg::Control::Info->new("debian/control");
foreach my $pkg ($control->{source}, @{$control->{packages}}) {
    my $pkgok;
    my $pkgname = ($pkg->get_type() ==  CTRL_INFO_SRC) ? "Source" : $pkg->{Package};
    next if $pkg->get_type() == CTRL_INFO_PKG && !samearch($arch, $pkg->{"Architecture"});
    foreach my $field (@fields) {
        my $val;
        if (exists $pkg->{$field}) {
            $val = $pkg->{$field};
        } elsif (my $f = $pkg->find_custom_field($field)) {
            $val = $pkg->{$f};
        }
        if (defined $val) {
            $pkgok = 1;
            printf "set(%s%s_%s \"%s\")\n", $prefix, $pkgname, $field, $val;
        }
    }
    if ($pkgok) {
        printf "list(APPEND %spackages \"%s\")\n", $prefix, $pkgname;
    }
}