#!/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:13.b.1-dfsg';
my $abi_version = '13.a';

# The list of HiPE enabled architectures (with added 'all' architecture)
my @hipe_arches = split(/\s+/, 'amd64 i386 powerpc sparc solaris-i386 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)");
  }
  foreach my $pkg ("appmon", "asn1", "common-test", "corba", "crypto", "debugger",
		   "dialyzer", "docbuilder", "edoc", "et", "eunit", "gs", "ic",
		   "inets", "inviso", "megaco", "mnesia", "observer", "odbc",
		   "os-mon", "parsetools", "percept", "pman", "public-key",
		   "reltool", "runtime-tools", "snmp", "ssh", "ssl",
		   "syntax-tools", "test-server", "toolbar", "tools", "tv",
		   "typer", "webtool", "wx", "xmerl", "nox", "x11", "dev") {
    delsubstvar($package, "erlang-$pkg:Depends");
    addsubstvar($package, "erlang-$pkg:Depends", "erlang-$pkg (>= $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
