#!/usr/bin/perl

# Copyright (c) 2005  Rafael Laboissiere <rafael@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

=head1 NAME

erlang-depends - calculates Erlang dependencies

=cut

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

=head1 SYNOPSIS

B<erlang-depends> [S<I<debhelper options>>]

=head1 DESCRIPTION

erlang-depends is a debhelper-like program that is responsible for generating
the ${erlang-base:Depends}, ${erlang-nox:Depends}, ${erlang-x11:Depends}, and
${erlang-dev:Depends} substitutions and adding them to substvars files.

Also, ${erlang-abi:Depends} substitution adds current erlang ABI virtual
package to substvar files. It is useful if your package uses C-based
extensions.

If you use this program, your package must build-depend on erlang-dev
(>= 1:11.b.2-3). If you want your package to depend on virtual package
provided by ${erlang-abi:Depends} then it must build-depend on erlang-dev
(>= 1:11.b.4-4).


=cut

init ();

# The current Erlang version
my $version = '1:12.b.3-dfsg';
my $abi_version = '11.b.3';

# The list of HiPE enabled architectures (with added 'all' architecture)
my @hipe_arches = split(/\s+/, 'amd64 i386 powerpc sparc all');

foreach my $package (@{$dh{DOPACKAGES}}) {
  delsubstvar($package, "erlang-abi:Depends");
  addsubstvar($package, "erlang-abi:Depends", "erlang-abi-$abi_version");
  delsubstvar($package, "erlang-base:Depends");
  my $arch = package_arch($package);
  if (grep(/^$arch$/, @hipe_arches)) {
    addsubstvar($package, "erlang-base:Depends",
      "erlang-base (>= $version) | erlang-base-hipe (>= $version)");
  } else {
    addsubstvar($package, "erlang-base:Depends", "erlang-base (>= $version)");
  }
  delsubstvar($package, "erlang-nox:Depends");
  addsubstvar($package, "erlang-nox:Depends", "erlang-nox (>= $version)");
  delsubstvar($package, "erlang-x11:Depends");
  addsubstvar($package, "erlang-x11:Depends", "erlang-x11 (>= $version)");
  delsubstvar($package, "erlang-dev:Depends");
  addsubstvar($package, "erlang-dev:Depends", "erlang-dev (>= $version)");
}

=head1 SEE ALSO

L<debhelper(7)>

This program is not part of debhelper.

=head1 AUTHOR

Torsten Werner <twerner@debian.org>

Most ideas borrowed from octave-depends by Rafael Laboissiere
<rafael@debian.org>.

=cut
