#!/usr/bin/perl

use Modern::Perl;

my @exclusions = (
    'debhelper',
);

open my $control_fh, '<', 'debian/control' or die "Cannot open debian/control";
my @lines = <$control_fh>;
close $control_fh;

my @build_depends;
my $in_build_depends_block;
for my $line ( @lines ) {
    chomp $line;
    if ( $line =~ m|Build-Depends:| ) {
        $in_build_depends_block = 1;
        $line =~ s|Build-Depends:||;
    }
    next unless $in_build_depends_block;
    if ( $line =~ m|^\s*$| ) {
        last;
    }
    for my $dep ( split ',', $line ) {
        $dep =~ s|^\s*||;
        push @build_depends, $dep unless ( map { ( $dep =~ m|$_| ) ? 1 : () } @exclusions);
    }
}
print 'koha:Depends=' . join ( ', ', @build_depends ) . "\n";
