#!/usr/bin/perl -w
#
# Find dependancies. Simple dpkg-shlibdeps wrapper.

BEGIN { push @INC, "debian", "/usr/lib/debhelper" }
use Dh_Lib;
init();

foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
	$TMP=tmpdir($PACKAGE);
	$EXT=pkgext($PACKAGE);

	my @filelist;
	my $ff;

	# Generate a list of all ELF binaries in the package.
	foreach $file (split(/\n/,`find $TMP -type f \\( -perm +111 -or -name "*.so*" \\)`)) {
		# TODO: this is slow, optimize. Ie, file can run once on multiple files..
		$ff=`file $file`;
		if ($ff=~m/ELF/) {
			push @filelist,$file;
		}
	}

	if (@filelist) {
		doit("dpkg-shlibdeps","-Tdebian/$EXT\substvars",@{$dh{U_PARAMS}},@filelist);
	}
}
