5 dh_perl - calculates perl scripts & modules dependencies
10 use Debian::Debhelper::Dh_Lib;
14 dh_perl [debhelper options] [-k] [-d] [library dirs ...]
18 dh_perl is a debhelper program that is responsible for generating
19 the perl:Depends substitutions and adding them to substvars files.
21 The program will look for the location of installed modules and will
22 use this information to generate a dependency (at the present time
23 it can only be perl5, perl5-thread, perl-5.X or perl-5.X-thread).
24 The dependancy will be substituted into your package's control file
25 wherever you place the token "${perl:Depends}".
27 It will also look at #! lines of perl scripts in order to be able
28 to calculate a dependency for perl scripts and not only perl modules.
30 In addition it will automatically remove .packlist file and will
31 remove the directory in which it was if it's empty. You can
32 switch off this option by passing -k.
44 In some specific cases you may want to depend on a -base package
45 (ie perl-5.6-base or perl5-base). If so, you can pass
46 the -d option to make dh_perl generate a dependency on the correct base
47 package. This is only necessary for some packages that are included in the
52 If your package installs perl modules in non-standard
53 directories, you can make dh_perl check those directories by passing their
54 names on the command line. It will only check usr/lib/perl5 by default.
60 Debian policy, version 3.0.1
62 Perl policy, version 1.0
69 my $lib_dir = 'usr/lib/perl5';
71 # Figure out the version of perl. If $ENV{PERL} is set, query the perl binary
72 # it points to, otherwise query perl directly.
74 # This is pretty gawd-aweful ugly, because we need "5.00[45]"
75 # and "5.[6789]" to be returned depending on perl version.
77 if (defined $ENV{PERL}) {
78 $version=`$ENV{PERL} -e '\$] < 5.006 ? printf "%.3f", \$] : printf "%vd", substr \$^V, 0, -1'`;
81 $version=$] < 5.006 ? sprintf "%.3f", $] : sprintf "%vd", substr $^V, 0, -1;
84 # Cleaning the paths given on the command line
90 # If -d is given, then we'll try to depend on one of the perl-5.00X-base
91 # package instead of perl-5.00X
92 $perlext='-base' if ($dh{'D_FLAG'});
94 foreach my $package (@{$dh{DOPACKAGES}}) {
95 my $tmp=tmpdir($package);
96 my $ext=pkgext($package);
98 my ($file, $v, $arch);
103 # Check also for alternate locations given on the command line
105 foreach ($lib_dir, @ARGV) {
106 $dirs .= "$tmp/$_ " if (-d "$tmp/$_");
108 my $re = '(?:' . join('|', ($lib_dir, @ARGV)) . ')';
110 # Look for perl modules and check where they are installed
112 foreach $file (split(/\n/,`find $dirs -type f \\( -name "*.pm" -or -name "*.so" \\)`)) {
114 if ($file =~ m<^$tmp/$re/(\d\.\d+)/([^/]+)/>) {
117 check_module_version ($v, $version);
118 $v .= '-thread' if ($arch =~ /-thread/);
119 $dep_arch = add_deps ($dep_arch, "perl-$v");
120 } elsif ($file =~ m<^$tmp/$re/(\d.\d+)/>) {
122 check_module_version ($v, $version);
123 $dep_arch = add_deps ($dep_arch, "perl-$v");
128 if ($found and not $dep_arch) {
129 $dep = "perl5$perlext";
130 } elsif ($dep_arch) {
134 # Look for perl scripts
136 foreach $file (split(/\n/,`find $tmp -type f \\( -name "*.pl" -or -perm +111 \\)`)) {
139 $newdep = dep_from_script ($file);
140 $dep = add_deps ($dep, $newdep) if $newdep;
144 # Remove .packlist files and eventually some empty directories
145 if (not $dh{'K_FLAG'}) {
146 foreach $file (split(/\n/,`find $tmp -type f -name .packlist`))
149 # Get the directory name
150 while ($file =~ s#/[^/]+$##){
151 last if (not -d $file);
152 last if (not rmdir $file);
159 if (-e "debian/${ext}substvars") {
160 open (IN, "<debian/${ext}substvars");
161 my @lines=grep { ! /^perl:Depends=/ } <IN>;
163 open (OUT, ">debian/${ext}substvars");
166 open (OUT, ">debian/${ext}substvars");
168 print OUT "perl:Depends=$dep\n";
173 my ($dep, $new) = @_;
175 # If the $new-base package can exist then add $perlext to $new
176 $new = "$new$perlext" if ($new =~ m/^(?:perl5|perl-\d\.\d+)$/);
178 # If $new = perl5 or perl5-thread check if perl-X.XXX(-thread)?
179 # is not already in the dependencies
180 if ($new eq "perl5") {
181 return $dep if ($dep =~ m/(^|\s)perl-5\.\d+(\s|,|$)/);
182 } elsif ($new eq "perl5-thread") {
183 return $dep if ($dep =~ m/(^|\s)perl-5\.\d+-thread(\s|,|$)/);
189 $dep .= ", $new" unless ($dep =~ m/(^|\s)$new(\s|,|$)/);
195 sub check_module_version {
197 unless ($v1 eq $v2) {
198 warning("A module has been found in perl-$v1 arch directory. But perl-$v2 is the perl currently used ...\n");
202 sub dep_from_script {
204 my ($line, $perl, $dep);
205 open (SCRIPT, "<$file") || die "Can't open $file: $!\n";
208 if ($line =~ m<^#!\s*/usr/bin/(perl\S*)(?:\s+|$)>) {
210 if ($perl eq "perl") {
212 } elsif ($perl eq "perl-thread") {
213 $dep = "perl5-thread";
214 } elsif ($perl =~ m/^perl-\d\.\d+(?:-thread)?$/) {
216 } elsif ($perl =~ m/^perl(\d\.\d+)(\d\d)$/) {
217 # Should never happen but ...
218 $dep = "perl-$1 (=$1.$2)";
228 This program is a part of debhelper.
232 Joey Hess <joeyh@debian.org>