]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmanpages
r482: * Spellpatch, Closes: #101553
[debhelper.git] / dh_installmanpages
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installmanpages - old-style man page installer
6
7 =cut
8
9 use strict;
10 use File::Find;
11 use Debian::Debhelper::Dh_Lib;
12
13 =head1 SYNOPSIS
14
15   dh_installmanpages [debhelper options] [file ...]
16
17 =head1 DESCRIPTION
18
19 dh_installmanpages is a debhelper program that is responsible for
20 automatically installing man pages into usr/share/man/ and usr/X11R6/man/
21 in package build directories.
22
23 This is a DWIM-style program, with an interface unlike the rest of
24 debhelper. You are encouraged to use L<dh_installman(1)> instead.
25
26 dh_installmanpages scans the current directory and all subdirectories for
27 filenames that look like man pages. (Note that only real files are looked
28 at; symlinks are ignored.) It uses L<file(1)> to verify that the files are
29 in the correct format. Then, based on the files' extensions, it installs 
30 them into the correct man directory.
31
32 All filenames specified as parameters will be skipped by dh_installmanpages.
33 This is useful if by default it installs some man pages that you do not
34 want to be installed.
35
36 After the man page installation step, dh_installmanpages will check to see
37 if any of the man pages are ".so" links. If so, it changes them to symlinks.
38
39 =head1 OPTIONS
40
41 =over 4
42
43 =item I<file ...>
44
45 Do not install these files as man pages, even if they look like valid man
46 pages.
47
48 =back
49
50 =head1 BUGS
51
52 dh_installmanpages will install the man pages it finds into B<all> packages
53 you tell it to act on, since it can't tell what package the man
54 pages belong in. This is almost never what you really want (use -p to work
55 around this, or use the much better L<dh_installman(1)> program instead).
56
57 Files ending in I<.man> will be ignored.
58
59 Files specified as parameters that contain spaces in their filenames will
60 not be processed properly.
61
62 =cut
63
64 init();
65
66 # Check if a file is a man page, for use by File::Find.
67 my @manpages;
68 my @allpackages;
69 sub find_man {
70         # Does its filename look like a man page?
71         # .ex files are examples installed by deb-make,
72         # we don't want those, or .in files, which are
73         # from configure, nor do we want CVS .#* files.
74         if (! (-f $_ && /^.*\.[1-9].*$/ && ! /\.(ex|in)$/ && ! /^\.#/)) {
75                 return;
76         }
77         
78         # It's not in a tmp directory is it?
79         if ($File::Find::dir=~m:debian/.*tmp.*:) {
80                 return;
81         }
82         foreach my $dir (@allpackages) {
83                 if ($File::Find::dir=~m:debian/\Q$dir\E:) {
84                         return;
85                 }
86         }
87         
88         # And file does think it's a real man page?
89         my $type=`file -z $_`;
90         if ($type !~ m/:.*roff/) {
91                 return;
92         }
93
94         # Good enough.
95         push @manpages,"$File::Find::dir/$_";
96 }
97
98 # Check if a file is a .so man page, for use by File::Find.
99 my @sofiles;
100 my @sodests;
101 sub find_so_man {
102         # The -s test is becuase a .so file tends to be small. We don't want
103         # to open every man page. 1024 is arbitrary.
104         if (! -f $_ || -s $_ > 1024) {
105                 return;
106         }
107
108         # Test first line of file for the .so thing.
109         open (SOTEST,$_);
110         my $l=<SOTEST>;
111         close SOTEST;
112         if ($l=~m/\.so\s+(.*)/) {
113                 my $solink=$1;
114                 # This test is here to prevent links like ... man8/../man8/foo.8
115                 if (Debian::Debhelper::Dh_Lib::basename($File::Find::dir) eq
116                     Debian::Debhelper::Dh_Lib::dirname($solink)) {
117                         $solink=Debian::Debhelper::Dh_Lib::basename($solink);
118                 }
119                 else {
120                         $solink="../$solink";
121                 }
122         
123                 push @sofiles,"$File::Find::dir/$_";
124                 push @sodests,$solink;
125         }
126 }
127
128 foreach my $package (@{$dh{DOPACKAGES}}) {
129         my $tmp=tmpdir($package);
130
131         # Find all filenames that look like man pages.
132         @manpages=();
133         @allpackages=GetPackages('');
134         find(\&find_man,'.'); # populates @manpages
135         
136         foreach my $page (@manpages) {
137                 $page=~s:^\./::; # just for looks
138                 
139                 my $basename=basename($page);
140                 
141                 # Skip all files listed on command line.
142                 my $install=1;
143                 foreach my $skip (@ARGV) {
144                         # Look at basename of what's on connect line
145                         # for backwards compatibility.
146                         if ($basename eq basename($skip)) {
147                                 $install=undef;
148                                 last;
149                         }
150                 }
151                 
152                 if ($install) {
153                         my $extdir="share";
154                         # Handle X man pages specially.
155                         if ($basename=~/x$/) {
156                                 $extdir="X11R6";
157                         }
158                         
159                         my ($section)=$basename=~m/.*\.([1-9])/;
160                         
161                         my $destdir="$tmp/usr/$extdir/man/man$section/";
162                         
163                         # Handle translated man pages.
164                         my $instname=$basename;
165                         my ($langcode)=$basename=~m/.*\.([a-z][a-z])\.([1-9])/;
166                         if (defined $langcode && $langcode ne '') {
167                                 $destdir="$tmp/usr/$extdir/man/$langcode/man$section/";
168                                 $instname=~s/\.$langcode\./\./;
169                         }
170                         
171                         $destdir=~tr:/:/:s; # just for looks
172                         
173                         if (! -e "$destdir/$basename" && !-l "$destdir/$basename") {
174                                 if (! -d $destdir) {
175                                         doit "install","-d",$destdir;
176                                 }
177                                 doit "install","-p","-m644",$page,$destdir.$instname;
178                         }
179                 }
180         }
181         
182         # Now the .so conversion.
183         @sofiles=@sodests=();
184         foreach my $dir (qw{usr/share/man usr/X11R6/man}) {
185                 if (-e "$tmp/$dir") {
186                         find(\&find_so_man, "$tmp/$dir");
187                 }
188         }
189         foreach my $sofile (@sofiles) {
190                 my $sodest=shift(@sodests);
191                 doit "rm","-f",$sofile;
192                 doit "ln","-sf",$sodest,$sofile;
193         }
194 }
195
196 =head1 SEE ALSO
197
198 L<debhelper(1)>
199
200 This program is a part of debhelper.
201
202 =head1 AUTHOR
203
204 Joey Hess <joeyh@debian.org>
205
206 =cut