]> git.donarmstrong.com Git - debhelper.git/blob - dh_perl
r1653: * dh_strip: Add note to man page that the detached debugging symbols options
[debhelper.git] / dh_perl
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_perl - calculates perl 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 on perl or
25 perlapi. The dependency will be substituted into your package's control
26 file 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 Note that this flag may cause no dependency on perl-base to be generated at
40 all. perl-base is Essential, so its dependency can be left out, unless a
41 versioned dependency is needed.
42
43 =item B<-V>
44
45 By default, scripts and architecture independent modules don't depend
46 on any specific version of perl.  The -V option causes the current
47 version of the perl (or perl-base with -d) package to be specified.
48
49 =item I<library dirs>
50
51 If your package installs perl modules in non-standard
52 directories, you can make dh_perl check those directories by passing their
53 names on the command line. It will only check the vendorlib and vendorarch
54 directories by default.
55
56 =back
57
58 =head1 CONFORMS TO
59
60 Debian policy, version 3.0.1
61
62 Perl policy, version 1.18
63
64 =cut
65
66 init();
67
68 my $vendorlib = substr $Config{vendorlib}, 1;
69 my $vendorarch = substr $Config{vendorarch}, 1;
70
71 # the installation dir for arch-indep modules changed to
72 # /usr/share/perl5 in this version:
73 my $min_version = '5.6.0-16';
74
75 # Cleaning the paths given on the command line
76 foreach (@ARGV) {
77         s#/$##;
78         s#^/##;
79 }
80
81 my $perl = 'perl';
82 # If -d is given, then the dependency is on perl-base rather than perl.
83 $perl .= '-base' if $dh{D_FLAG};
84 my $version;
85
86 # dependency types
87 use constant PROGRAM   => 1;
88 use constant PM_MODULE => 2;
89 use constant XS_MODULE => 4;
90
91 foreach my $package (@{$dh{DOPACKAGES}}) {
92         my $tmp=tmpdir($package);
93
94         delsubstvar($package, "perl:Depends"); # for idempotency
95         
96         # Check also for alternate locations given on the command line
97         my @dirs = grep -d, map "$tmp/$_", $vendorlib, $vendorarch, @ARGV;
98
99         # Look for perl modules and check where they are installed
100         my $deps = 0;
101         find sub {
102                 return unless -f;
103                 $deps |= PM_MODULE if /\.pm$/;
104                 $deps |= XS_MODULE if /\.so$/;
105         }, @dirs if @dirs;
106
107         # find scripts
108         find sub {
109                 return unless -f and (-x or /\.pl$/);
110                 local *F;
111                 return unless open F, $_;
112                 if (read F, local $_, 32 and m%^#!\s*(/usr/bin/perl|/usr/bin/env\s+perl)\s%) {
113                         $deps |= PROGRAM;
114                 }
115                 close F;
116         }, $tmp;
117
118         if ($deps) {
119                 my $version="";
120                 if ($deps & XS_MODULE or $dh{V_FLAG_SET}) {
121                         ($version) = `dpkg -s $perl` =~ /^Version:\s*(\S+)/m
122                                 unless $version;
123                         $version = ">= $version";
124                 }
125                 elsif ($deps & PM_MODULE) {
126                         $version = ">= $min_version";
127                 }
128                 
129                 # no need to depend on an un-versioned perl-base -- it's
130                 # essential
131                 addsubstvar($package, "perl:Depends", $perl, $version)
132                         unless $perl eq 'perl-base' && ! length($version);
133
134                 # add perlapi-<ver> for XS modules
135                 addsubstvar($package, "perl:Depends", "perlapi-$Config{version}")
136                         if $deps & XS_MODULE;
137         }
138 }
139
140 =head1 SEE ALSO
141
142 L<debhelper(7)>
143
144 This program is a part of debhelper.
145
146 =head1 AUTHOR
147
148 Brendan O'Dea <bod@debian.org>
149
150 =cut