3 # Find dependencies on perl stuff
4 # Remove .packlist files
6 BEGIN { push @INC, "debian", "/usr/share/debhelper" }
11 my $lib_dir = 'usr/lib/perl5';
13 # Figure out the version of perl. If $ENV{PERL} is set, query the perl binary
14 # it points to, otherwise query perl directly.
15 my $version=sprintf("%.3f", $]);
16 if (defined $ENV{PERL}) {
17 $version=`$ENV{PERL} -e 'printf "%.3f", \$]'`;
20 # Cleaning the paths given on the command line
26 # If -d is given, then we'll try to depend on one of the perl-5.00X-base
27 # package instead of perl-5.00X
28 $ext='-base' if ($dh{'D_FLAG'});
30 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
31 $TMP=tmpdir($PACKAGE);
32 $EXT=pkgext($PACKAGE);
34 my ($file, $v, $arch);
39 # Check also for alternate locations given on the command line
41 foreach ($lib_dir, @ARGV) {
42 $dirs .= "$TMP/$_ " if (-d "$TMP/$_");
44 my $re = '(?:' . join('|', ($lib_dir, @ARGV)) . ')';
46 # Look for perl modules and check where they are installed
48 foreach $file (split(/\n/,`find $dirs -type f \\( -name "*.pm" -or -name "*.so" \\)`)) {
50 if ($file =~ m<^$TMP/$re/(\d\.\d{3})/([^/]+)/>) {
53 check_module_version ($v, $version);
54 $v .= '-thread' if ($arch =~ /-thread/);
55 $dep_arch = add_deps ($dep_arch, "perl-$v");
56 } elsif ($file =~ m<^$TMP/$re/(\d.\d{3})/>) {
58 check_module_version ($v, $version);
59 $dep_arch = add_deps ($dep_arch, "perl-$v");
64 if ($found and not $dep_arch) {
70 # Look for perl scripts
72 foreach $file (split(/\n/,`find $TMP -type f \\( -name "*.pl" -or -perm +111 \\)`)) {
75 $newdep = dep_from_script ($file);
76 $dep = add_deps ($dep, $newdep) if $newdep;
80 # Remove .packlist files and eventually some empty directories
81 if (not $dh{'K_FLAG'}) {
82 foreach $file (split(/\n/,`find $TMP -type f -name .packlist`))
85 # Get the directory name
86 while ($file =~ s#/[^/]+$##){
87 last if (not -d $file);
88 last if (not rmdir $file);
95 if (-e "debian/$EXT\substvars") {
96 open (IN, "<debian/$EXT\substvars");
97 my @lines=grep { ! /^perl:Depends=/ } <IN>;
99 open (OUT, ">debian/$EXT\substvars");
102 open (OUT, ">debian/$EXT\substvars");
104 print OUT "perl:Depends=$dep\n";
109 my ($dep, $new) = @_;
111 # If the $new-base package can exist then add $ext to $new
112 $new = "$new$ext" if ($new =~ m/^(?:perl5|perl-\d\.\d{3})$/);
114 # If $new = perl5 or perl5-thread check if perl-X.XXX(-thread)?
115 # is not already in the dependencies
116 if ($new eq "perl5") {
117 return $dep if ($dep =~ m/(^|\s)perl-5\.\d{3}(\s|,|$)/);
118 } elsif ($new eq "perl5-thread") {
119 return $dep if ($dep =~ m/(^|\s)perl-5\.\d{3}-thread(\s|,|$)/);
125 $dep .= ", $new" unless ($dep =~ m/(^|\s)$new(\s|,|$)/);
131 sub check_module_version {
133 unless ($v1 eq $v2) {
134 warning("A module has been found in perl-$v1 arch directory. But perl-$v2 is the perl currently used ...\n");
138 sub dep_from_script {
140 my ($line, $perl, $dep);
141 open (SCRIPT, "<$file") || die "Can't open $file: $!\n";
144 if ($line =~ m<^#!\s*/usr/bin/(perl\S*)(?:\s+|$)>) {
146 if ($perl eq "perl") {
148 } elsif ($perl eq "perl-thread") {
149 $dep = "perl5-thread";
150 } elsif ($perl =~ m/^perl-\d\.\d{3}(?:-thread)?$/) {
152 } elsif ($perl =~ m/^perl(\d\.\d{3})(\d\d)$/) {
153 # Should never happen but ...
154 $dep = "perl-$1 (=$1.$2)";