3 # Find dependencies on perl stuff
4 # Remove .packlist files
6 use Debian::Debhelper::Dh_Lib;
10 my $lib_dir = 'usr/lib/perl5';
12 # Figure out the version of perl. If $ENV{PERL} is set, query the perl binary
13 # it points to, otherwise query perl directly.
14 my $version=sprintf("%.3f", $]);
15 if (defined $ENV{PERL}) {
16 $version=`$ENV{PERL} -e 'printf "%.3f", \$]'`;
19 # Cleaning the paths given on the command line
25 # If -d is given, then we'll try to depend on one of the perl-5.00X-base
26 # package instead of perl-5.00X
27 $ext='-base' if ($dh{'D_FLAG'});
29 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
30 $TMP=tmpdir($PACKAGE);
31 $EXT=pkgext($PACKAGE);
33 my ($file, $v, $arch);
38 # Check also for alternate locations given on the command line
40 foreach ($lib_dir, @ARGV) {
41 $dirs .= "$TMP/$_ " if (-d "$TMP/$_");
43 my $re = '(?:' . join('|', ($lib_dir, @ARGV)) . ')';
45 # Look for perl modules and check where they are installed
47 foreach $file (split(/\n/,`find $dirs -type f \\( -name "*.pm" -or -name "*.so" \\)`)) {
49 if ($file =~ m<^$TMP/$re/(\d\.\d{3})/([^/]+)/>) {
52 check_module_version ($v, $version);
53 $v .= '-thread' if ($arch =~ /-thread/);
54 $dep_arch = add_deps ($dep_arch, "perl-$v");
55 } elsif ($file =~ m<^$TMP/$re/(\d.\d{3})/>) {
57 check_module_version ($v, $version);
58 $dep_arch = add_deps ($dep_arch, "perl-$v");
63 if ($found and not $dep_arch) {
69 # Look for perl scripts
71 foreach $file (split(/\n/,`find $TMP -type f \\( -name "*.pl" -or -perm +111 \\)`)) {
74 $newdep = dep_from_script ($file);
75 $dep = add_deps ($dep, $newdep) if $newdep;
79 # Remove .packlist files and eventually some empty directories
80 if (not $dh{'K_FLAG'}) {
81 foreach $file (split(/\n/,`find $TMP -type f -name .packlist`))
84 # Get the directory name
85 while ($file =~ s#/[^/]+$##){
86 last if (not -d $file);
87 last if (not rmdir $file);
94 if (-e "debian/${EXT}substvars") {
95 open (IN, "<debian/${EXT}substvars");
96 my @lines=grep { ! /^perl:Depends=/ } <IN>;
98 open (OUT, ">debian/${EXT}substvars");
101 open (OUT, ">debian/${EXT}substvars");
103 print OUT "perl:Depends=$dep\n";
108 my ($dep, $new) = @_;
110 # If the $new-base package can exist then add $ext to $new
111 $new = "$new$ext" if ($new =~ m/^(?:perl5|perl-\d\.\d{3})$/);
113 # If $new = perl5 or perl5-thread check if perl-X.XXX(-thread)?
114 # is not already in the dependencies
115 if ($new eq "perl5") {
116 return $dep if ($dep =~ m/(^|\s)perl-5\.\d{3}(\s|,|$)/);
117 } elsif ($new eq "perl5-thread") {
118 return $dep if ($dep =~ m/(^|\s)perl-5\.\d{3}-thread(\s|,|$)/);
124 $dep .= ", $new" unless ($dep =~ m/(^|\s)$new(\s|,|$)/);
130 sub check_module_version {
132 unless ($v1 eq $v2) {
133 warning("A module has been found in perl-$v1 arch directory. But perl-$v2 is the perl currently used ...\n");
137 sub dep_from_script {
139 my ($line, $perl, $dep);
140 open (SCRIPT, "<$file") || die "Can't open $file: $!\n";
143 if ($line =~ m<^#!\s*/usr/bin/(perl\S*)(?:\s+|$)>) {
145 if ($perl eq "perl") {
147 } elsif ($perl eq "perl-thread") {
148 $dep = "perl5-thread";
149 } elsif ($perl =~ m/^perl-\d\.\d{3}(?:-thread)?$/) {
151 } elsif ($perl =~ m/^perl(\d\.\d{3})(\d\d)$/) {
152 # Should never happen but ...
153 $dep = "perl-$1 (=$1.$2)";