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