]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmanpages
cmake: Pass CPPFLAGS in CFLAGS. Closes: #668813 Thanks, Simon Ruderich for the patch...
[debhelper.git] / dh_installmanpages
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installmanpages - old-style man page installer (deprecated)
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 B<dh_installmanpages> is a debhelper program that is responsible for
20 automatically installing man pages into F<usr/share/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 B<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 B<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, B<dh_installmanpages> will check to see
38 if any of the man pages are F<.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 B<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 B<-p> to work
56 around this, or use the much better L<dh_installman(1)> program instead).
57
58 Files ending in F<.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                         
160                         my ($section)=$basename=~m/.*\.([1-9])/;
161                         
162                         my $destdir="$tmp/usr/$extdir/man/man$section/";
163                         
164                         # Handle translated man pages.
165                         my $instname=$basename;
166                         my ($langcode)=$basename=~m/.*\.([a-z][a-z])\.([1-9])/;
167                         if (defined $langcode && $langcode ne '') {
168                                 $destdir="$tmp/usr/$extdir/man/$langcode/man$section/";
169                                 $instname=~s/\.$langcode\./\./;
170                         }
171                         
172                         $destdir=~tr:/:/:s; # just for looks
173                         
174                         if (! -e "$destdir/$basename" && !-l "$destdir/$basename") {
175                                 if (! -d $destdir) {
176                                         doit "install","-d",$destdir;
177                                 }
178                                 doit "install","-p","-m644",$page,$destdir.$instname;
179                         }
180                 }
181         }
182         
183         # Now the .so conversion.
184         @sofiles=@sodests=();
185         foreach my $dir (qw{usr/share/man}) {
186                 if (-e "$tmp/$dir") {
187                         find(\&find_so_man, "$tmp/$dir");
188                 }
189         }
190         foreach my $sofile (@sofiles) {
191                 my $sodest=shift(@sodests);
192                 doit "rm","-f",$sofile;
193                 doit "ln","-sf",$sodest,$sofile;
194         }
195 }
196
197 =head1 SEE ALSO
198
199 L<debhelper(7)>
200
201 This program is a part of debhelper.
202
203 =head1 AUTHOR
204
205 Joey Hess <joeyh@debian.org>
206
207 =cut