MAJOR=4
MINOR=15
DEVNAME=tty15
  O   )ˆl—ß=¿Jõ2Ž¥2 _¸Ë×uLZ7ÿ�þYeæÖnQ�¶è¥q ?É„!yÿÌa–äY>” ”¾R( 	Å €jà^S�ÿÐ 3…    )#! /usr/bin/perl -w

=head1 NAME

dh_girepository - compute dependencies for GObject introspection packages

=cut

use strict;
use File::Find;
use Dpkg::Deps;
use Dpkg::Control;
use Debian::Debhelper::Dh_Lib;

=head1 SYNOPSIS

B<dh_girepository> [I<debhelper options>] [-lI<directory>] [-pI<directory>] [-XI<item>] [I<private [...]>]

=head1 DESCRIPTION

dh_girepository is a debhelper program to compute dependencies for packages
shipping GObject introspection data.

The dependencies are generated in the ${gir:Depends} substitution variable.

The minimal version of the generated dependencies is calculated by looking
first at the version of the packages declared in the build-dependencies of the
building package. If a package is not declared in the build-dependencies, the
minimal version of that package is calculated by looking at the version of the
package containing the corresponding .gir file defined in the
build-dependencies.

Note that dh_girepository will not be executed automatically by dh; you
need to use C<dh $@ --with gir> for C<dh> to include it.

=head1 OPTIONS

=over 4

=item B<-l>I<directory>

Specify a directory (or a colon-separated list of directories) where to look
for the .gir XML files that were used to generate the .typelib files that
are scanned. This option is only necessary if those files are not shipped in
another, architecture-dependent package.

=item B<-p>I<directory>

Specify a directory (or a colon-separated list of directories) where to look
for the dependencies. This is useful when a dependency ships the .typelib
in a private directory.

=item B<-X>I<item>

Exclude files that contain I<item> anywhere in their filename from being
analyzed.

=item I<private [...]>
List of directories where to look for typelibs and the corresponding .gir
files. Useful when the package installs its typelibs in a private
directory, such as /usr/lib/<package>. Library dependencies are also looked
there, in case your typelib depends on a library that you ship on a private
directory.

=back

=head1 CONFORMS TO

GObject introspection mini policy as of 2011-03-30.

=cut

# Initialisation code
init(options => {
    "l=s", => \$dh{L_PARAMS},
    "p=s", => \$dh{P_PARAMS},
});
my @paths_first = ();
my @privdirs = ();
if ($dh{L_PARAMS}) {
    push @paths_first, split /:/, $dh{L_PARAMS};
}
if ($dh{P_PARAMS}) {
    push @privdirs, split /:/, $dh{P_PARAMS};
}
isnative($dh{MAINPACKAGE}); # Necessary to have $dh{VERSION}
my $bin_version = $dh{VERSION};
my @archpackages = getpackages("arch");

my $triplet = `dpkg-architecture -qDEB_HOST_MULTIARCH`;
chomp $triplet;
my $typelib_multiarch_path = "/usr/lib/$triplet/girepository-1.0";
my $typelib_path = "/usr/lib/girepository-1.0";

my @typelibdirs = (@ARGV, $typelib_path, $typelib_multiarch_path);
my $gir_path = "/usr/share/gir-1.0";
my @girdirs = (@ARGV, $gir_path);
my $arch_triplet = `dpkg-architecture -qDEB_HOST_MULTIARCH`;
chomp $arch_triplet;
my @privlibdirs = (@ARGV);
my @libdirs = ("/lib/$arch_triplet", "/lib", "/usr/lib/$arch_triplet", "/usr/lib", @privlibdirs);
my $format;

# Get Build-Depends in an array
my @bdeps;

my $ctrl = Dpkg::Control->new(type => CTRL_INFO_SRC);
$ctrl->load('debian/control');
foreach my $field (qw(Build-Depends Build-Depends-Arch Build-Depends-Indep)) {
    if (defined $ctrl->{$field}) {
        my $value = deps_parse($ctrl->{$field}, build_dep => 1);
        push @bdeps, split ', ', $value->output;
    }
}

# We canâ€™t parse .typelib files, so we need the corresponding .gir
# somewhere in the same source package (or with -l).

sub find_gir {
    my $req = shift;
    $req =~ s/\.typelib$//;
    my $f;
    foreach my $path (@paths_first) {
        $f = "$path/$req.gir";
        if (-f $f) {
            verbose_print ("Found $req.gir in $path");
            return $f;
        }
    }
    foreach my $otherpkg (@archpackages) {
        foreach my $girdir (@girdirs) {
            $f = tmpdir($otherpkg)."$girdir/$req.gir";
        