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