#! /usr/bin/perl -w

=head1 NAME

dh_gaim - depend on the appropriate version of gaim

=cut

use strict;
use Debian::Debhelper::Dh_Lib;

=head1 SYNOPSIS

B<dh_gaim> [S<I<debhelper options>>]

=head1 DESCRIPTION

dh_gaim is a debhelper program that is responsible for generating 
the ${misc:Depends} substutions that depend on the correct versions of gaim,
and adding them to substvars files.

To use this program, make sure it is executed in debian/rules at some point
during the build process (normally during the install), and make sure that
your Depends: field in debian/control contains ${misc:Depends}.

=cut

init();

my ($gaim_epoch, $gaim_version, $next_version, $gaim_major, $gaim_minor,
    $gaim_rest);
$gaim_version = `dpkg -s gaim`;
$gaim_version =~ /^Version:\s*([\S]+)/m;
$gaim_version = $1;

if (! defined $gaim_version) {
     error("gaim is not installed.  (Probably forgot to Build-Depend on gaim)");
}
if ($gaim_version =~ m/(\d+:)?(\d+)\.(\d+)\.(.*)/) {
     $gaim_epoch = $1;
     $gaim_major = $2;
     $gaim_minor = $3;
     $gaim_rest = $4;
} else {
     error("Unable to parse gaim version out of '$gaim_version'");
}

$next_version = $gaim_epoch . ($gaim_major + 1) . ".0";
$gaim_version = $gaim_epoch . $gaim_major . "." .$gaim_minor;

foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmp=tmpdir($package);
        addsubstvar($package, "misc:Depends", "gaim", ">= $gaim_version");
        addsubstvar($package, "misc:Depends", "gaim", "<< $next_version");
}

=head1 SEE ALSO

L<debhelper(7)>

=head1 AUTHOR

Written by Tollef Fog Heen <tfheen@debian.org>, based on various other
dh_* commands written by Joey Hess <joeyh@debian.org>.

=cut
