]> git.donarmstrong.com Git - debhelper.git/blob - dh_perl
r496: * Man page cleanups, Closes: #119335
[debhelper.git] / dh_perl
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_perl - calculates perl scripts & modules dependencies
6
7 =cut
8
9 use strict;
10 use Config;
11 use File::Find;
12 use Debian::Debhelper::Dh_Lib;
13
14 =head1 SYNOPSIS
15
16 B<dh_perl> [S<I<debhelper options>>] [B<-d>] [S<I<library dirs ...>>]
17
18 =head1 DESCRIPTION
19
20 dh_perl is a debhelper program that is responsible for generating
21 the perl:Depends substitutions and adding them to substvars files.
22
23 The program will look at perl scripts and modules in your package,
24 and will use this information to generate a dependency.
25 The dependency will be substituted into your package's control file
26 wherever you place the token "${perl:Depends}".
27
28 =head1 OPTIONS
29
30 =over 4
31
32 =item B<-d>
33
34 In some specific cases you may want to depend on perl-base rather than the
35 full perl package. If so, you can pass the -d option to make dh_perl generate
36 a dependency on the correct base package. This is only necessary for some
37 packages that are included in the base system.
38
39 =item B<-V>
40
41 By default, scripts and architecture independent modules don't depend
42 on any specific version of perl.  The -V option causes the current
43 version of the perl (or perl-base with -d) package to be specified.
44
45 =item I<library dirs>
46
47 If your package installs perl modules in non-standard
48 directories, you can make dh_perl check those directories by passing their
49 names on the command line. It will only check the vendorlib and vendorarch
50 directories by default.
51
52 =back
53
54 =head1 CONFORMS TO
55
56 Debian policy, version 3.0.1
57
58 Perl policy, version 1.18
59
60 =cut
61
62 init();
63
64 my $vendorlib = substr $Config{vendorlib}, 1;
65 my $vendorarch = substr $Config{vendorarch}, 1;
66
67 # the installation dir for arch-indep modules changed to
68 # /usr/share/perl5 in this version:
69 my $min_version = '5.6.0-16';
70
71 # Cleaning the paths given on the command line
72 foreach (@ARGV) {
73         s#/$##;
74         s#^/##;
75 }
76
77 my $perl = 'perl';
78 # If -d is given, then the dependency is on perl-base rather than perl.
79 $perl .= '-base' if $dh{D_FLAG};
80 my $version;
81
82 # dependency types
83 use constant PROGRAM   => 1;
84 use constant PM_MODULE => 2;
85 use constant XS_MODULE => 4;
86
87 foreach my $package (@{$dh{DOPACKAGES}}) {
88         my $tmp = tmpdir($package);
89         my $ext = pkgext($package);
90
91         # For idempotency, remove anything this program might have
92         # previously added to the substvars file.
93         if (-e "debian/${ext}substvars") {
94                 complex_doit("grep -v ^perl:Depends= debian/${ext}substvars > debian/${ext}substvars.new || true");
95                 doit("mv", "debian/${ext}substvars.new","debian/${ext}substvars");
96         }
97
98         # Check also for alternate locations given on the command line
99         my @dirs = grep -d, map "$tmp/$_", $vendorlib, $vendorarch, @ARGV;
100
101         # Look for perl modules and check where they are installed
102         my $deps = 0;
103         find sub {
104                 return unless -f;
105                 $deps |= PM_MODULE if /\.pm$/;
106                 $deps |= XS_MODULE if /\.so$/;
107         }, @dirs if @dirs;
108
109         # find scripts
110         find sub {
111                 return unless -f and (-x or /\.pl$/);
112                 local *F;
113                 return unless open F, $_;
114                 if (read F, local $_, 32 and m%^#!\s*/usr/bin/perl\s%) {
115                         $deps |= PROGRAM;
116                 }
117                 close F;
118         }, $tmp;
119
120         if ($deps) {
121                 my $perl_depends = $perl;
122                 if ($deps & XS_MODULE or $dh{V_FLAG_SET}) {
123                         ($version) = `dpkg -s $perl` =~ /^Version:\s*(\S+)/m
124                                 unless $version;
125                         $perl_depends .= " (>= $version)";
126                 }
127                 elsif ($deps & PM_MODULE) {
128                         $perl_depends .= " (>= $min_version)";
129                 }
130
131                 # add perlapi-<ver> for XS modules
132                 $perl_depends .= ", perlapi-$Config{version}"
133                         if $deps & XS_MODULE;
134
135                 # don't need to depend on an un-versioned perl-base, it's
136                 # essential
137                 unless ($perl_depends eq 'perl-base') {
138                         complex_doit("echo 'perl:Depends=$perl_depends' >> debian/${ext}substvars");
139                 }
140         }
141 }
142
143 =head1 SEE ALSO
144
145 L<debhelper(1)>
146
147 This program is a part of debhelper.
148
149 =head1 AUTHOR
150
151 Brendan O'Dea <bod@debian.org>
152
153 =cut