-#!/bin/sh -e
+#!/usr/bin/perl -w
#
# Automatically generate shlibs files.
-PATH=debian:$PATH:/usr/lib/debhelper
-. dh_lib
+use strict;
+use Debian::Debhelper::Dh_Lib;
+init();
-for PACKAGE in $DH_DOPACKAGES; do
- TMP=`tmpdir $PACKAGE`
+foreach my $package (@{$dh{DOPACKAGES}}) {
+ my $tmp=tmpdir($package);
- if [ -e "debian/$TMP/DEBIAN/shlibs" ]; then
- error "debian/$TMP/DEBIAN/shlibs already exists."
- fi
+ my %seen;
+ my $need_ldconfig = 0;
- for file in `find debian/$TMP -type f -name "*.so*" | tr "\n" " "` ; do
- LIBRARY=`expr $file : ".*/\(.*\)\.so\..*"` || true
- VERSION=`expr $file : ".*/.*\.so\.\(.*\)"` || true
- MAJOR=`expr $VERSION : "\([0-9]*\)\."` || true
- LIBSTUB=`expr $file : "\(.*\/.*\.so\)\..*"` || true
- if [ ! -d "debian/$TMP/DEBIAN" ] ; then
- doit "install -d debian/$TMP/DEBIAN"
- fi
- verbose_echo "echo \"$LIBRARY $MAJOR $PACKAGE\" >>debian/$TMP/DEBIAN/shlibs"
- echo "$LIBRARY $MAJOR $PACKAGE" >>debian/$TMP/DEBIAN/shlibs
- done
+ doit("rm", "-f", "$tmp/DEBIAN/shlibs");
- if [ -e "debian/$TMP/DEBIAN/shlibs" ]; then
- doit "chown root.root debian/$TMP/DEBIAN/shlibs"
- fi
-done
+ open (FIND, "find $tmp -xtype f -name '*.so*' |");
+ while (<FIND>) {
+ my $library;
+ my $major;
+
+ chomp;
+ $need_ldconfig=1;
+ # The second evil regexp is for db3, whose author should
+ # be shot.
+ if (m#.*/([^/]*)\.so\.(\d*)\.?# || m#.*/([^/]*)-([^\s/]+)\.so$#) {
+ $library = $1;
+ $major = $2;
+ }
+ if (defined($dh{M_PARAMS}) && $dh{M_PARAMS} ne '') {
+ $major=$dh{M_PARAMS};
+ }
+ if (! -d "$tmp/DEBIAN") {
+ doit("install","-d","$tmp/DEBIAN");
+ }
+ my $deps=$package;
+ if ($dh{V_FLAG_SET}) {
+ if ($dh{V_FLAG} ne '') {
+ $deps=$dh{V_FLAG};
+ }
+ else {
+ # Call isnative becuase it sets $dh{VERSION}
+ # as a side effect.
+ isnative($package);
+ $deps="$package (>= $dh{VERSION})";
+ }
+ }
+ if (defined($library) && defined($major) && defined($deps) &&
+ $library ne '' && $major ne '' && $deps ne '') {
+ # Prevent duplicate lines from entering the file.
+ my $line="$library $major $deps";
+ if (! $seen{$line}) {
+ $seen{$line}=1;
+ complex_doit("echo '$line' >>$tmp/DEBIAN/shlibs");
+ }
+ }
+ }
+ close FIND;
+
+ # New as of dh_v3.
+ if (! compat(2) && ! $dh{NOSCRIPTS} && $need_ldconfig) {
+ autoscript($package,"postinst","postinst-makeshlibs");
+ autoscript($package,"postrm","postrm-makeshlibs");
+ }
+
+ if (-e "$tmp/DEBIAN/shlibs") {
+ doit("chmod",644,"$tmp/DEBIAN/shlibs");
+ doit("chown","0.0","$tmp/DEBIAN/shlibs");
+ }
+}