5 dh_installman - install man pages into package build directories
11 use Debian::Debhelper::Dh_Lib;
15 B<dh_installman> [S<I<debhelper options>>] [S<I<manpage ...>>]
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. If you have a
23 properly formatted .TH line, your man page will be installed into the right
24 directory, with the right name (this includes proper handling of pages
25 with a subsection, like "3perl", which are placed in man3, and given an
26 extension of ".3perl"). If your .TH line is incorrect or missing, the program
27 may guess wrong based on the file extension.
29 It also supports translated man pages, by looking for extensions
30 like .ll.8 and .ll_LL.8, or by use of the --language switch.
32 If dh_installman seems to install a man page into the wrong section or with
33 the wrong extension, this is because the man page has the wrong section
34 listed in its .TH line. Edit the man page and correct the section, and
35 dh_installman will follow suit. See L<man(7)> for details about the .TH
36 section. If dh_installman seems to install a man page into a directory
37 like /usr/share/man/pl/man1/, that is because your program has a
38 name like "foo.pl", and dh_installman assumes that means it is translated
39 into Polish. Use --language=C to avoid this.
41 Any man page filenames specified as parameters will be installed into the
42 first package dh_installman is told to act on. By default, this is the
43 first binary package in debian/control, but if you use -p, -i, or -a flags,
44 it will be the first package specified by those flags.
46 Files named debian/package.manpages can list other man pages to be
49 After the man page installation step, dh_installman will check to see if
50 any of the man pages in the temporary directories of any of the packages it
51 is acting on contain ".so" links. If so, it changes them to symlinks.
53 Also, dh_installman will use man to guess the character encoding of each
54 manual page and convert it to UTF-8. If the guesswork fails for some
55 reason, you can override it using an encoding declaration. See
56 L<manconv(1)> for details.
64 Install all files specified by command line parameters in ALL packages
67 =item B<--language>=ll
69 Use this to specify that the man pages being acted on are written in the
74 Install these man pages into the first package acted on. (Or in all
75 packages if -A is specified).
81 An older version of this program, L<dh_installmanpages(1)>, is still used
82 by some packages, and so is still included in debhelper.
83 It is, however, deprecated, due to its counterintuitive and inconsistent
84 interface. Use this program instead.
89 "language=s" => \$dh{LANGUAGE},
95 foreach my $package (@{$dh{DOPACKAGES}}) {
96 next if is_udeb($package);
98 my $tmp=tmpdir($package);
99 my $file=pkgfile($package,"manpages");
102 @manpages=filearray($file, ".") if $file;
104 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
105 push @manpages, @ARGV;
108 foreach my $page (@manpages) {
109 my $basename=basename($page);
111 # Support compressed pages.
113 if ($basename=~m/(.*)(\.gz)/) {
119 # See if there is a .TH entry in the man page. If so,
120 # we'll pull the section field from that.
122 open (IN, "zcat $page|") or die "$page: $!";
125 open (IN, $page) or die "$page: $!";
128 if (/^\.TH\s+\S+\s+"?(\d+[^"\s]*)"?/) {
133 # Failing that, we can try to get it from the filename.
135 ($section)=$basename=~m/.*\.([1-9]\S*)/;
138 # Now get the numeric component of the section.
139 my ($realsection)=$section=~m/^(\d)/ if defined $section;
140 if (! $realsection) {
141 error("Could not determine section for $page");
144 # Get the man page's name -- everything up to the last dot.
145 my ($instname)=$basename=~m/^(.*)\./;
147 my $destdir="$tmp/usr/share/man/man$realsection/";
149 if (! defined $dh{LANGUAGE} || ! exists $dh{LANGUAGE}) {
150 # Translated man pages are typically specified by adding the
151 # language code to the filename, so detect that and
152 # redirect to appropriate directory, stripping the code.
153 ($langcode)=$basename=~m/.*\.([a-z][a-z](?:_[A-Z][A-Z])?)\.(?:[1-9]|man)/;
155 elsif ($dh{LANGUAGE} ne 'C') {
156 $langcode=$dh{LANGUAGE};
159 if (defined $langcode && $langcode ne '') {
160 # Strip the language code from the instname.
161 $instname=~s/\.$langcode$//;
164 if (defined $langcode && $langcode ne '') {
165 $destdir="$tmp/usr/share/man/$langcode/man$realsection/";
167 $destdir=~tr:/:/:s; # just for looks
168 my $instpage="$destdir/$instname.$section";
170 next if -l $instpage;
171 next if compat(5) && -e $instpage;
174 doit "install","-d",$destdir;
177 complex_doit "zcat \Q$page\E > \Q$instpage\E";
180 doit "install","-p","-m644",$page,$instpage;
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");
191 foreach my $sofile (@sofiles) {
192 my $sodest=shift(@sodests);
193 doit "rm","-f",$sofile;
194 doit "ln","-sf",$sodest,$sofile;
197 # Now utf-8 conversion.
198 foreach my $dir (qw{usr/share/man usr/X11R6/man}) {
199 if (-e "$tmp/$dir") {
201 return if ! -f $_ || -l $_;
202 my ($tmp, $orig)=($_.".new", $_);
203 complex_doit "man --recode UTF-8 ./\Q$orig\E > \Q$tmp\E";
204 # recode uncompresses compressed pages
205 doit "rm", "-f", $orig if s/\.(gz|Z)$//;
206 doit "chmod", 644, $tmp;
207 doit "mv", "-f", $tmp, $_;
213 # Check if a file is a .so man page, for use by File::Find.
215 # The -s test is becuase a .so file tends to be small. We don't want
216 # to open every man page. 1024 is arbitrary.
217 if (! -f $_ || -s $_ > 1024 || -s == 0) {
221 # Test first line of file for the .so thing.
223 open (SOTEST, "zcat $_|") or die "$_: $!";
226 open (SOTEST,$_) || die "$_: $!";
232 error("failed to read $_");
235 if ($l=~m/\.so\s+(.*)\s*/) {
237 # This test is here to prevent links like ... man8/../man8/foo.8
238 if (basename($File::Find::dir) eq
240 $solink=basename($solink);
243 $solink="../$solink";
246 push @sofiles,"$File::Find::dir/$_";
247 push @sodests,$solink;
255 This program is a part of debhelper.
259 Joey Hess <joeyh@debian.org>