summaryrefslogtreecommitdiff
path: root/cmake/debcontrol2cmake.pl
blob: fc160dee9f18ef8bb91cc1a92a71186a13be1a01 (plain)
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
#!/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;

# 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;
    }
}

# 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};
    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;
    }
}