#!/usr/bin/perl

use warnings;
use strict;

sub to_list($)
{
	my $f = $_[0];

	open(D, $f) or return '';
	my @PACKAGES = grep(!/^\s*(#.*|\s)$/, <D>);
	chomp(@PACKAGES);
	return join(", ", @PACKAGES);
	close(D);
}

sub gen_substvars($)
{
	my ($pkgname) = @_;
	open(S, ">>debian/$pkgname.substvars") or die;
	print S "meta:Depends=".to_list("debian/$pkgname.depends")."\n";
	close(S);
}

open(CONTROL, 'debian/control') or
	die("cannot read debian/control: $!\n");
while (<CONTROL>) {
	chomp;
	s/\s+$//;
	if (/^Package:\s*(.*)/) {
		gen_substvars($1);
	}
}
