]> git.donarmstrong.com Git - debhelper.git/blob - dh_perl
64cb362bc8bc755092c6145ec2bf3cdce3d7201b
[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   dh_perl [debhelper options] [-d] [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 dependancy 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 I<library dirs>
40
41 If your package installs perl modules in non-standard
42 directories, you can make dh_perl check those directories by passing their
43 names on the command line. It will only check the vendorlib and vendorarch
44 directories by default.
45
46 =back
47
48 =head1 CONFORMS TO
49
50 Debian policy, version 3.0.1
51
52 Perl policy, version 1.15
53
54 =cut
55
56 init();
57
58 my $vendorlib = substr $Config{vendorlib}, 1;
59 my $vendorarch = substr $Config{vendorarch}, 1;
60
61 # Cleaning the paths given on the command line
62 foreach (@ARGV) {
63         s#/$##;
64         s#^/##;
65 }
66
67 my $perl = 'perl';
68 # If -d is given, then the dependency is on perl-base rather than perl.
69 $perl .= '-base' if $dh{D_FLAG};
70 my $version;
71
72 # dependency types
73 use constant PROGRAM   => 1;
74 use constant PM_MODULE => 2;
75 use constant XS_MODULE => 4;
76
77 foreach my $package (@{$dh{DOPACKAGES}}) {
78         my $tmp = tmpdir($package);
79         my $ext = pkgext($package);
80
81         # Check also for alternate locations given on the command line
82         my @dirs = grep -d, map "$tmp/$_", $vendorlib, $vendorarch, @ARGV;
83
84         # Look for perl modules and check where they are installed
85         my $deps = 0;
86         find sub {
87                 return unless -f;
88                 $deps |= PM_MODULE if /\.pm$/;
89                 $deps |= XS_MODULE if /\.so$/;
90             }, @dirs if @dirs;
91
92         # find scripts
93         find sub {
94                 return unless -f and (-x or /\.pl$/);
95                 local *F;
96                 return unless open F, $_;
97                 if (read F, local $_, 32 and m%^#!\s*/usr/bin/perl\s%)
98                 {
99                     $deps |= PROGRAM;
100                 }
101
102                 close F;
103             }, $tmp;
104
105         next unless $deps;
106
107         my $perl_depends = $perl;
108         if ($deps & XS_MODULE or $dh{V_FLAG_SET})
109         {
110             ($version) = `dpkg -p $perl` =~ /^Version:\s*(\S+)/m
111                 unless $version;
112
113             $perl_depends .= " (>= $version)";
114         }
115
116         # add perlapi-<ver> for XS modules
117         $perl_depends .= ", perlapi-$Config{version}"
118             if $deps & XS_MODULE;
119
120         # don't need to depend on an un-versioned perl-base, it's
121         # essential
122         next if $perl_depends eq 'perl-base';
123
124         if (-e "debian/${ext}substvars") {
125                 open (IN, "<debian/${ext}substvars");
126                 my @lines=grep { ! /^perl:Depends=/ } <IN>;
127                 close IN;
128                 open (OUT, ">debian/${ext}substvars");
129                 print OUT @lines;
130         } else {
131                 open (OUT, ">debian/${ext}substvars");
132         }
133         print OUT "perl:Depends=$perl_depends\n";
134         close OUT;
135 }
136
137 =head1 SEE ALSO
138
139 L<debhelper(1)>
140
141 This program is a part of debhelper.
142
143 =head1 AUTHOR
144
145 Brendan O'Dea <bod@debian.org>
146
147 =cut