Codebase list cli-common / debian/0.2.1 dh_makeclilibs
debian/0.2.1

Tree @debian/0.2.1 (Download .tar.gz)

dh_makeclilibs @debian/0.2.1raw · history · blame

#!/usr/bin/perl -w

=head1 NAME

dh_makeclilibs - automatically create clilibs file

=cut

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

=head1 SYNOPSIS

B<dh_makeclilibs> [S<I<debhelper options>>] [B<-r>] [B<-V>I<[dependancies]>] [B<-m>I<minversion>] [B<-l>I<nextincompatible>] [B<-X>I<item>]

=head1 DESCRIPTION

dh_makeclilibs is a debhelper program that automatically scans for
versioned CIL (.NET) assemblies, and generates a clilibs file for the
libraries it finds.

By default, dh_makeclilibs scans the .dll files in the package
directories and writes the discovered compatibility data (major/minor,
build, token) to "clilibs" files in the appropriate packages.
 
However, if a file like debian/package.clilibs is found, this one will
be installed and no scanning is performed.

=head1 OPTIONS

=over 4

=item B<-V>, B<-V>I<dependancies>

=item B<--version-info>, B<--version-info=>I<dependancies>

By default, the clilibs file generated by this program does not make packages
depend on any particular version of the package containing the assembly.
It may be necessary for you to add some version dependency
information to the clilibs file. If -V is specified with no dependency
information, the current version of the package is plugged into a
dependency that looks like "packagename (>= packageversion)". If -V is
specified with parameters, the parameters can be used to specify the exact
dependency information needed (be sure to include the package name).

Beware of using -V without any parameters; this is a conservative setting
that always ensures that other packages' shared library dependencies are at
least as tight as they need to be, so that if the maintainer screws up then
they won't break. The flip side is that packages might end up with
dependencies that are too tight and so find it harder to be upgraded.

=item B<-m>I<minversion>

Like -V, but specifies only the version string, the package name comes
from the package that is actually processed. This option is more
flexible if you try to set a range of valid versions for different
assembly packages coming from one source package.

=item B<-l>I<nextincompatible>

Specifies the (expected) version of this package when the compatibility
to the current assemblies will break.

=item B<-r>

An experimental option to automaticaly guess the next incompatible
upstream version and insert them (like working with -l and -m options,
see above). Do not expect the guessed values to be always correct -
normally, the usualy assumed version string has the form
generation.major.minor where versions with changes in "minor" are
compatible and "major" versions break with compatibility.

=item B<-X>I<item>, B<--exclude=>I<item>

Exclude files that contain "item" anywhere in their filename or directory 
from being treated as shared libraries.

=item B<--internal-mono>

Uses the mono runtime in . (used for bootstrapping mono packages)

=back

=head1 EXAMPLES

 dh_makeclilibs

Assuming this is a package named libfoobar0.9x-cil, generates a clilibs file that
looks something like:
 libfoobar  1.0.2345.0_23a12f34  libfoobar0.9x-cil

 dh_makeclilibs -V

Assuming the current version of the package is 0.93-3, generates a clilibs
file that looks something like:
 libfoobar 1.0.2345.0_23a12f34 libfoobar0.9x-cil (>= 0.93-3)

 dh_makeclilibs -V 'libfoobar0.9x-cil (>= 0.92)'

Generates a clilibs file that looks something like:
  libfoobar 1.0.2345.0_23a12f34 libfoobar0.9x-cil (>= 0.92)

Assuming that your package creates libfoobar-cil and liblafasel-cil,
which are compatible to 0.92 versions but the upstream is going to break
compatibility in the next version, 0.94:

 dh_makeclilibs -m 0.92 -l 0.94

Generates clilibs file that looks something like:

  libfoobar 1.0.2345.0_23a12f34 libfoobar-cil (>= 0.92), libfoobar-cil (<< 0.94)

and

  liblafasel 1.0.2345.0_23a12f34 liblafasel-cil (>= 0.92), liblafasel-cil (<< 0.94)

=cut

init();

my $clr;
my $cli = '/usr/bin/cli';
my $cli_version = `$cli --version 2>&1`;
my $cli_parser;
my $sn = 'sn';

if (defined($ARGV[0]) && $ARGV[0] eq "internal-mono") {
    $clr = "mono";
    my $mono_path = "MONO_PATH=debian/tmp/usr/lib/mono/1.0:debian/tmp/usr/lib/mono/2.0";
    $cli_parser = "$mono_path debian/tmp/usr/bin/monodis";
    $sn = "$mono_path debian/tmp/usr/bin/mono debian/tmp/usr/lib/mono/1.0/sn.exe";
    verbose_print("Will use build Mono (debian/tmp/usr/bin/monodis) for CIL parsing.");
} elsif (-x "/usr/bin/monodis") {
    $clr = "mono";
    $cli_parser = "/usr/bin/monodis";
    verbose_print("Will use Mono (/usr/bin/monodis) for CIL parsing.");
} elsif (-x "/usr/bin/ildasm") {
    $clr = "pnet";
    $cli_parser = "/usr/share/cli-common/ildasm-monodis";
    verbose_print("Will use Portable.NET (/usr/bin/ildasm) for CIL parsing.");
} else {
    error("Could not find a CIL disassembler, aborting.");
}

{
  local $/="";
  open(FILE, 'debian/control');
  my @filedata = <FILE>;
  close FILE;
  if (!($filedata[0] =~ /Build-Depends(-Indep)?: .*cli-common \(>= 0\.2\.0\)/)) {
      warning("Warning! No Build-Depends(-Indep) on cli-common (>= 0.2.0)!");
  }
}

my $fh;
my %shlibdata;

foreach my $package (@{$dh{DOPACKAGES}}) {
    next if is_udeb($package);

    my $tmp = tmpdir($package);

    my %seen;
    my $need_ldconfig = 0;

    doit("rm", "-f", "$tmp/DEBIAN/clilibs");
    if (-e "debian/$package.clilibs" ) {
        complex_doit("cat debian/$package.clilibs > $tmp/DEBIAN/clilibs");
    } else {
        # So, we look for files or links to existing files with names that
        # match "*.so*". Matching *.so.* is not good enough because of
        # broken crap like db3. And we only look at real files not
        # symlinks, so we don't accidentually add clilibs data to -dev
        # packages. This may have a few false positives, which is ok,
        # because only if we can get a library name and a major number from
        # objdump is anything actually added.
        my $exclude = '';
        if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
            $exclude = "! \\( $dh{EXCLUDE_FIND} \\) ";
        }
        open(FIND, "find $tmp -type f \\( -name '*.dll' \\) $exclude |");
        
        dll:
        while (<FIND>) {
            chomp;
            my ($library, $ver, $libfile);
            $libfile = $_;
            my $sig = `$sn -T $_ 2> /dev/null`;
            $sig =~ s/.*key token: (\w+).*/$1/is;
            if ($sig=~/\s/) {
               warning "$libfile has no valid signature, ignoring";
               next dll;
            }
            my $dis = `$cli_parser --assembly $libfile 2>&1`;
            if ($dis =~ m/Name:\s+(\S+)/) {
               $library = $1;
               $dis =~ m/Version:\s+(\S+)/;
               $ver = $1;
            } else {
               # completely broken code, we need a mature app not
               # depending on assembly loading
               # verbose_print("trouble parsing monodis output, components not installed? Fallback to parsing the pure monodis output.");
               # $dis = `monodis $libfile 2>&1`;
               # $dis =~ /^module (\S+)/is;
               # $library = $1;
               # $library =~ s/'|"//;
               warning("$cli_parser could not open $libfile, maybe some components not installed yet. Using filename to guess the assembly name :(");
               $libfile=~ m,/(\d+\.\d+.\d+.\d+)__(\w+)/([^/]+)\.dll$,is;
               next dll if (!($1 && $2 && $3));
               $ver=$1;
               $sig=$2;
               $library=$3;
            }

            if (!-d "$tmp/DEBIAN") {
                doit("install", "-d", "$tmp/DEBIAN");
            }
            my $deps = $package;

            # Call isnative becuase it sets $dh{VERSION}
            # as a side effect.
            isnative($package);
            my $version = $dh{VERSION};

            # Old compatibility levels include the
            # debian revision, while new do not.
            if (!compat(3)) {
                # Remove debian version, if any.
                $version =~ s/-[^-]+$//;
            }

            if (defined($dh{M_PARAMS}) && $dh{M_PARAMS} ne '') {
                $version = $dh{M_PARAMS};
            }
            if ($dh{V_FLAG_SET}) {
                if ( $dh{V_FLAG} ne '' ) {
                    $deps = $dh{V_FLAG};
                } else {
                    $deps = "$package (>= $version)";
                }
            }
            if (defined( $dh{R_FLAG})) {
                $version =~ s/-[^-]+$//;
                my @uvers = split ( /\./, $version );
                $uvers[1]++;
                $deps = "$package (>= $version), $package (<< ".join(".", @uvers).")";
            }
            if (defined( $dh{M_PARAMS})) {
                $deps = "$package (>= ".$dh{M_PARAMS}.")";
            }
            if (defined( $dh{L_PARAMS})) {
                $deps .= ", $package (<< ".$dh{L_PARAMS}.")";
            }
            if (defined($library) &&
                defined($ver) &&
                defined($deps) &&
                $library ne '' &&
                $ver ne '' &&
                $deps ne '') {
                # Prevent duplicate lines from entering the file.
                my $line = "$library $ver" . "__$sig $deps";

                # extra dependencies are to be resolved by dh_clideps,
                # don't forward the dependency libs to the apps where it
                # does not belong to
#                if ( my $extra = extraDeps ($libfile) )   { $line .= ", $extra";  }
                if (!$seen{$line}) {
                    $seen{$line} = 1;
                    complex_doit("echo '$line' >> $tmp/DEBIAN/clilibs");
                }
            }
        }
    }
    close FIND;

    if (-e "$tmp/DEBIAN/clilibs") {
        doit("chmod", 644,   "$tmp/DEBIAN/clilibs");
        doit("chown", "0:0", "$tmp/DEBIAN/clilibs");
    }
}

sub extraDeps {
   my $config=$_[0].".config";
   my $ret=undef;

   if (!%shlibdata) {
      open($fh, "cat /var/lib/dpkg/info/*.shlibs debian/shlibs.local debian/*/DEBIAN/shlibs 2>/dev/null |");
      while (<$fh>) {
         /(\S+)\s+(\S+)\s+(\w.*)\n?/;
         $shlibdata{"$1.so.$2"} = $3;
      }
   }

   if (-r $config) {
      $config = `cat $config`;
      while($config=~s/\Wtarget\W*=\W*(\w[\w.\-\d]+)//) {
         $ret.= (", ".$shlibdata{$1}) if(defined($shlibdata{$1}));
      }
   }
   $ret=~s/^, // if $ret;
   return $ret;
}

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of cli-common.

=head1 KNOWN BUGS

Will possibly not work correctly with DH_COMPAT levels 1 and 2.

=head1 AUTHOR

Mirco Bauer <meebey@meebey.net>, Eduard Bloch <blade@debian.org>,
inspired by dh_makeshlibs by Joey Hess <joeyh@debian.org>

=cut