#! /usr/bin/perl
#
# Hook for automatic backports.
#
# Target dist: Debian Lenny

use warnings;
use strict;
use Carp;

open(F, "debian/control") or croak;
my $first = 1;
my $file;
my $field = '';
while(<F>) {
  chomp();
  if (/^(\S+):/) {
    $field = $1;
  }
  if ($first) {
    $file .= $_;
    $first = 0;
  } elsif (/^$/) {
    $file .= "\n";
  } elsif ($field eq 'Description' || /^[^ ]/ || /^$/) {
    $file .= "\n" . $_;
  } else {
    $file .= $_;
  }
}
close(F);

$file .= "\n";

$file =~ s/\nBuild-Depends: [^\n]+/\nBuild-Depends: debhelper (>= 5.0.51~), po-debconf, libboost-dev, libqt4-dev, libssl-dev, libzeroc-ice32-dev, ice32-translators, protobuf-compiler, libprotobuf-dev, libcap-dev/g;
$file =~ s/Package: mumble(-11x|)\nArchitecture: any/Package: mumble$1\nArchitecture: none/g;

open(F, ">debian/control") or croak;
print F $file;
close(F);

$file = '';
open(F, "debian/rules") or croak;
while (<F>) {
  $file .= $_;
}
close(F);

$file =~ s/CONFIG.=no-bundled-speex/CONFIG*=no-client/;
$file =~ s/\nifeq \(.+?\nendif/\n/smg;

open(F, ">debian/rules") or croak;
print F $file;
close(F);

