3 # Reads debian/manpages, installs all man pages there into appropriate
4 # man page directory tree.
8 use Debian::Debhelper::Dh_Lib;
11 foreach my $package (@{$dh{DOPACKAGES}}) {
12 my $tmp=tmpdir($package);
13 my $file=pkgfile($package,"manpages");
17 @manpages=filearray($file, ".");
20 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
21 push @manpages, @ARGV;
24 foreach my $page (@manpages) {
25 my $basename=Debian::Debhelper::Dh_Lib::basename($page);
27 # Support compressed pages.
29 if ($basename=~m/(.*)(\.gz)/) {
35 # See if there is a .TH entry in the man page. If so,
36 # we'll pull the section field from that.
38 open (IN, "zcat $page|") or die "$page: $!";
41 open (IN, $page) or die "$page: $!";
44 if (/^\.TH\s+[^ ]+\s+(\d+[^ ]*)\s/) {
49 # Failing that, we can try to get it from the filename.
51 ($section)=$basename=~m/.*\.([1-9][^ ]*)/;
54 # Now get the numeric component of the section.
55 my ($realsection)=$section=~m/^(\d)/ if defined $section;
57 # If there is no numeric section, bail.
59 error("Could not determine section for $page");
62 my $destdir="$tmp/usr/share/man/man$realsection/";
63 # Translated man pages are typically specified by adding the
64 # language code to the filename, so detect that and
65 # redirect to appropriate directory.
66 my ($langcode)=$basename=~m/.*\.([a-z][a-z](?:_[A-Z][A-Z])?)\.(?:[1-9]|man)/;
67 if (defined $langcode && $langcode ne '') {
68 $destdir="$tmp/usr/share/man/$langcode/man$section/";
70 $destdir=~tr:/:/:s; # just for looks
72 # Get the man page's name -- everything up to the last dot.
73 my ($instname)=$basename=~m/^(.*)\./;
75 if (! -e "$destdir/$instname.$section" &&
76 ! -l "$destdir/$instname.$section") {
78 doit "install","-d",$destdir;
80 doit "install","-p","-m644",$page,
81 "$destdir$instname.$section$gz";
86 # Now the .so conversion.
89 foreach my $dir (qw{usr/share/man usr/X11R6/man}) {
91 find(\&find_so_man, "$tmp/$dir");
94 foreach my $sofile (@sofiles) {
95 my $sodest=shift(@sodests);
96 doit "rm","-f",$sofile;
97 doit "ln","-sf",$sodest,$sofile;
101 # Check if a file is a .so man page, for use by File::Find.
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) {
111 # Test first line of file for the .so thing.
115 if ($l=~m/\.so\s+(.*)/) {
117 # This test is here to prevent links like ... man8/../man8/foo.8
118 if (Debian::Debhelper::Dh_Lib::basename($File::Find::dir) eq
119 Debian::Debhelper::Dh_Lib::dirname($solink)) {
120 $solink=Debian::Debhelper::Dh_Lib::basename($solink);
123 $solink="../$solink";
126 push @sofiles,"$File::Find::dir/$_";
127 push @sodests,$solink;