#! /usr/bin/perl

# Dump (on stdout) the list of binary pkgs. buildable from the source package.
# Given by the path to the debian/control file.
# one per line.

use Dpkg::Control::Info;
use Getopt::Long::Descriptive;

my $arch_only=0;
my $debug=0;

my ($opt, $usage) = describe_options(
    'my-program %o <some-arg>',
    [ 'archonly|a', "only the architecture dependant", {  } ], # required => 0
    # [ 'archonly', "", {} ],
    [],
    [ 'verbose|v',  "print extra stuff"            ],
    [ 'help|h',       "print usage message and exit", { shortcircuit => 1 } ],
    );

print($usage->text), exit if $opt->help;

if ( $opt->archonly) {
    $arch_only=1
}

my ($option, $value, $pretty);

my $file=shift;

if ( -d $file ) {
    $file .= "/debian/control";
}

unless  (-f $file) {
    $file=$file . ".in";
    unless (-f $file) {
        die("non-existent file");
    }
}

$p= Dpkg::Control::Info->new($file);
$p->get_packages();

foreach $_ ($p->get_packages())
{
    if (! $arch_only || ($_->{Architecture} ne "all")) {
        print $_->{Package}, "\n";
#    print $_->{Architecture}, "\n";
    }
}
