]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmanpages
r1655: * Added udeb support, as pioneered by di-packages-build. Understands
[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 B<dh_installmanpages> [S<I<debhelper options>>] [S<I<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 (basename($File::Find::dir) eq
116                     dirname($solink)) {
117                         $solink=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         next if is_udeb($package);
130
131         my $tmp=tmpdir($package);
132
133         # Find all filenames that look like man pages.
134         @manpages=();
135         @allpackages=getpackages('');
136         find(\&find_man,'.'); # populates @manpages
137         
138         foreach my $page (@manpages) {
139                 $page=~s:^\./::; # just for looks
140                 
141                 my $basename=basename($page);
142                 
143                 # Skip all files listed on command line.
144                 my $install=1;
145                 foreach my $skip (@ARGV) {
146                         # Look at basename of what's on connect line
147                         # for backwards compatibility.
148                         if ($basename eq basename($skip)) {
149                                 $install=undef;
150                                 last;
151                         }
152                 }
153                 
154                 if ($install) {
155                         my $extdir="share";
156                         # Handle X man pages specially.
157                         if ($basename=~/x$/) {
158                                 $extdir="X11R6";
159                         }
160                         
161                         my ($section)=$basename=~m/.*\.([1-9])/;
162                         
163                         my $destdir="$tmp/usr/$extdir/man/man$section/";
164                         
165                         # Handle translated man pages.
166                         my $instname=$basename;
167                         my ($langcode)=$basename=~m/.*\.([a-z][a-z])\.([1-9])/;
168                         if (defined $langcode && $langcode ne '') {
169                                 $destdir="$tmp/usr/$extdir/man/$langcode/man$section/";
170                                 $instname=~s/\.$langcode\./\./;
171                         }
172                         
173                         $destdir=~tr:/:/:s; # just for looks
174                         
175                         if (! -e "$destdir/$basename" && !-l "$destdir/$basename") {
176                                 if (! -d $destdir) {
177                                         doit "install","-d",$destdir;
178                                 }
179                                 doit "install","-p","-m644",$page,$destdir.$instname;
180                         }
181                 }
182         }
183         
184         # Now the .so conversion.
185         @sofiles=@sodests=();
186         foreach my $dir (qw{usr/share/man usr/X11R6/man}) {
187                 if (-e "$tmp/$dir") {
188                         find(\&find_so_man, "$tmp/$dir");
189                 }
190         }
191         foreach my $sofile (@sofiles) {
192                 my $sodest=shift(@sodests);
193                 doit "rm","-f",$sofile;
194                 doit "ln","-sf",$sodest,$sofile;
195         }
196 }
197
198 =head1 SEE ALSO
199
200 L<debhelper(7)>
201
202 This program is a part of debhelper.
203
204 =head1 AUTHOR
205
206 Joey Hess <joeyh@debian.org>
207
208 =cut