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 # This is pretty gawd-aweful ugly, because we need "5.00[45]"
17 # and "5.[6789]" to be returned.
18 $version=`$ENV{PERL} -e '\$] < 5.006 ? printf "%.3f", \$] : printf "%vd\n", substr \$^V, 0, -1'`;
21 # Cleaning the paths given on the command line
27 # If -d is given, then we'll try to depend on one of the perl-5.00X-base
28 # package instead of perl-5.00X
29 $ext='-base' if ($dh{'D_FLAG'});
31 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
32 $TMP=tmpdir($PACKAGE);
33 $EXT=pkgext($PACKAGE);
35 my ($file, $v, $arch);
40 # Check also for alternate locations given on the command line
42 foreach ($lib_dir, @ARGV) {
43 $dirs .= "$TMP/$_ " if (-d "$TMP/$_");
45 my $re = '(?:' . join('|', ($lib_dir, @ARGV)) . ')';
47 # Look for perl modules and check where they are installed
49 foreach $file (split(/\n/,`find $dirs -type f \\( -name "*.pm" -or -name "*.so" \\)`)) {
51 if ($file =~ m<^$TMP/$re/(\d\.\d{3})/([^/]+)/>) {
54 check_module_version ($v, $version);
55 $v .= '-thread' if ($arch =~ /-thread/);
56 $dep_arch = add_deps ($dep_arch, "perl-$v");
57 } elsif ($file =~ m<^$TMP/$re/(\d.\d{3})/>) {
59 check_module_version ($v, $version);
60 $dep_arch = add_deps ($dep_arch, "perl-$v");
65 if ($found and not $dep_arch) {
71 # Look for perl scripts
73 foreach $file (split(/\n/,`find $TMP -type f \\( -name "*.pl" -or -perm +111 \\)`)) {
76 $newdep = dep_from_script ($file);
77 $dep = add_deps ($dep, $newdep) if $newdep;
81 # Remove .packlist files and eventually some empty directories
82 if (not $dh{'K_FLAG'}) {
83 foreach $file (split(/\n/,`find $TMP -type f -name .packlist`))
86 # Get the directory name
87 while ($file =~ s#/[^/]+$##){
88 last if (not -d $file);
89 last if (not rmdir $file);
96 if (-e "debian/${EXT}substvars") {
97 open (IN, "<debian/${EXT}substvars");
98 my @lines=grep { ! /^perl:Depends=/ } <IN>;
100 open (OUT, ">debian/${EXT}substvars");
103 open (OUT, ">debian/${EXT}substvars");
105 print OUT "perl:Depends=$dep\n";
110 my ($dep, $new) = @_;
112 # If the $new-base package can exist then add $ext to $new
113 $new = "$new$ext" if ($new =~ m/^(?:perl5|perl-\d\.\d{3})$/);
115 # If $new = perl5 or perl5-thread check if perl-X.XXX(-thread)?
116 # is not already in the dependencies
117 if ($new eq "perl5") {
118 return $dep if ($dep =~ m/(^|\s)perl-5\.\d{3}(\s|,|$)/);
119 } elsif ($new eq "perl5-thread") {
120 return $dep if ($dep =~ m/(^|\s)perl-5\.\d{3}-thread(\s|,|$)/);
126 $dep .= ", $new" unless ($dep =~ m/(^|\s)$new(\s|,|$)/);
132 sub check_module_version {
134 unless ($v1 eq $v2) {
135 warning("A module has been found in perl-$v1 arch directory. But perl-$v2 is the perl currently used ...\n");
139 sub dep_from_script {
141 my ($line, $perl, $dep);
142 open (SCRIPT, "<$file") || die "Can't open $file: $!\n";
145 if ($line =~ m<^#!\s*/usr/bin/(perl\S*)(?:\s+|$)>) {
147 if ($perl eq "perl") {
149 } elsif ($perl eq "perl-thread") {
150 $dep = "perl5-thread";
151 } elsif ($perl =~ m/^perl-\d\.\d{3}(?:-thread)?$/) {
153 } elsif ($perl =~ m/^perl(\d\.\d{3})(\d\d)$/) {
154 # Should never happen but ...
155 $dep = "perl-$1 (=$1.$2)";