]> git.donarmstrong.com Git - debhelper.git/blob - dh_installman
r432: more podization, will it ever end?
[debhelper.git] / dh_installman
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installman - install man pages into package build directories
6
7 =cut
8
9 use strict;
10 use File::Find;
11 use Debian::Debhelper::Dh_Lib;
12
13 =head1 SYNOPSIS
14
15   dh_installman [debhelper options] [manpage ...]
16
17 =head1 DESCRIPTION
18
19 dh_installman is a debhelper program that is responsible for installing
20 man pages into the correct locations in package build directories. You tell
21 it what man pages go in your package(s), and it figures out where to
22 install them based on the section field in their .TH line and their filename
23 extention.
24
25 Any man page filenames specified as parameters will be installed into the
26 first package dh_installman is told to act on. By default, this is the
27 first binary package in debian/control, but if you use -p, -i, or -a flags,
28 it will be the first package specified by those flags.
29
30 Files named debian/package.manpages can list other man pages to be
31 installed.
32
33 After the man page installation step, dh_installman will check to see if
34 any of the man pages in the temporary directories of any of the packages it
35 is acting on contain ".so" links. If so, it changes them to symlinks.
36
37 =head1 OPTIONS
38
39 =over 4
40
41 =item B<-A>, B<--all>
42
43 Install all files specified by command line parameters in ALL packages
44 acted on.
45
46 =item I<manpage ...>
47
48 Install these man pages into the first package acted on. (Or in all
49 packages if -A is specified).
50
51 =back
52
53 =head1 NOTES
54
55 An older version of this program, L<dh_installmanpages(1)>, is still used
56 by some packages, and so is still included in debhelper.
57 It is, however, deprecated, due to its counterintuiitive and inconsistent
58 interface. Use this program instead.
59
60 =cut
61
62 init();
63
64 foreach my $package (@{$dh{DOPACKAGES}}) {
65         my $tmp=tmpdir($package);
66         my $file=pkgfile($package,"manpages");
67         my @manpages;
68
69         if ($file) {
70                 @manpages=filearray($file, ".");
71         }
72
73         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
74                 push @manpages, @ARGV;
75         }
76
77         foreach my $page (@manpages) {
78                 my $basename=Debian::Debhelper::Dh_Lib::basename($page);
79
80                 # Support compressed pages.
81                 my $gz='';
82                 if ($basename=~m/(.*)(\.gz)/) {
83                         $basename=$1;
84                         $gz=$2;
85                 }
86
87                 my $section;
88                 # See if there is a .TH entry in the man page. If so,
89                 # we'll pull the section field from that.
90                 if ($gz) {
91                         open (IN, "zcat $page|") or die "$page: $!";
92                 }
93                 else {
94                         open (IN, $page) or die "$page: $!";
95                 }
96                 while (<IN>) {
97                         if (/^\.TH\s+[^         ]+\s+(\d+[^     ]*)\s/) {
98                                 $section=$1;
99                                 last;
100                         }
101                 }
102                 # Failing that, we can try to get it from the filename.
103                 if (! $section) {
104                         ($section)=$basename=~m/.*\.([1-9][^ ]*)/;
105                 }
106
107                 # Now get the numeric component of the section.
108                 my ($realsection)=$section=~m/^(\d)/ if defined $section;
109                 
110                 # If there is no numeric section, bail.
111                 if (! $realsection) {
112                         error("Could not determine section for $page");
113                 }
114                 
115                 my $destdir="$tmp/usr/share/man/man$realsection/";
116                 # Translated man pages are typically specified by adding the
117                 # language code to the filename, so detect that and
118                 # redirect to appropriate directory.
119                 my ($langcode)=$basename=~m/.*\.([a-z][a-z](?:_[A-Z][A-Z])?)\.(?:[1-9]|man)/;
120                 if (defined $langcode && $langcode ne '') {
121                         $destdir="$tmp/usr/share/man/$langcode/man$section/";
122                 }
123                 $destdir=~tr:/:/:s; # just for looks
124
125                 # Get the man page's name -- everything up to the last dot.
126                 my ($instname)=$basename=~m/^(.*)\./;
127         
128                 if (! -e "$destdir/$instname.$section" && 
129                     ! -l "$destdir/$instname.$section") {
130                         if (! -d $destdir) {
131                                 doit "install","-d",$destdir;
132                         }
133                         doit "install","-p","-m644",$page,
134                                 "$destdir$instname.$section$gz";
135                 }
136                 
137         }
138
139         # Now the .so conversion.
140         my @sofiles;
141         my @sodests;
142         foreach my $dir (qw{usr/share/man usr/X11R6/man}) {
143                 if (-e "$tmp/$dir") {
144                         find(\&find_so_man, "$tmp/$dir");
145                 }
146         }
147         foreach my $sofile (@sofiles) {
148                 my $sodest=shift(@sodests);
149                 doit "rm","-f",$sofile;
150                 doit "ln","-sf",$sodest,$sofile;
151         }
152 }
153
154 # Check if a file is a .so man page, for use by File::Find.
155 my @sofiles;
156 my @sodests;
157 sub find_so_man {
158         # The -s test is becuase a .so file tends to be small. We don't want
159         # to open every man page. 1024 is arbitrary.
160         if (! -f $_ || -s $_ > 1024) {
161                 return;
162         }
163
164         # Test first line of file for the .so thing.
165         open (SOTEST,$_);
166         my $l=<SOTEST>;
167         close SOTEST;
168         if ($l=~m/\.so\s+(.*)/) {
169                 my $solink=$1;
170                 # This test is here to prevent links like ... man8/../man8/foo.8
171                 if (Debian::Debhelper::Dh_Lib::basename($File::Find::dir) eq
172                     Debian::Debhelper::Dh_Lib::dirname($solink)) {
173                         $solink=Debian::Debhelper::Dh_Lib::basename($solink);
174                 }
175                 else {
176                         $solink="../$solink";
177                 }
178         
179                 push @sofiles,"$File::Find::dir/$_";
180                 push @sodests,$solink;
181         }
182 }
183
184 =head1 SEE ALSO
185
186 L<debhelper(1)>
187
188 This program is a part of debhelper.
189
190 =head1 AUTHOR
191
192 Joey Hess <joeyh@debian.org>
193
194 =cut