]> git.donarmstrong.com Git - debhelper.git/blob - dh_installdocs
r420: big monsta changes
[debhelper.git] / dh_installdocs
1 #!/usr/bin/perl -w
2 #
3 # Reads debian/docs, installs all files listed there into
4 # /usr/share/doc/$package
5 # Also installs the debian/copyright and debian/README.debian and debian/TODO
6 # and handles debian/doc-base.
7
8 use strict;
9 use Debian::Debhelper::Dh_Lib;
10 init();
11
12 foreach my $package (@{$dh{DOPACKAGES}}) {
13         my $tmp=tmpdir($package);
14         my $file=pkgfile($package,"docs");
15
16         # If this is a symlink, leave it alone.
17         if ( ! -d "$tmp/usr/share/doc/$package" &&
18              ! -l "$tmp/usr/share/doc/$package") {
19                 doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc/$package");
20         }
21
22         my @docs;
23
24         if ($file) {
25                 @docs=filearray($file, ".");
26         }
27
28         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
29                 push @docs, @ARGV;
30         }
31
32         if (@docs) {
33                 doit("cp", "-a",@docs,"$tmp/usr/share/doc/$package/");
34                 doit("chown","-R","0.0","$tmp/usr/share/doc");
35                 doit("chmod","-R","go=rX","$tmp/usr/share/doc");
36                 doit("chmod","-R","u+rw","$tmp/usr/share/doc");
37         }
38
39         # .Debian is correct, according to policy, but I'm easy.
40         my $readme_debian=pkgfile($package,'README.Debian');
41         if (! $readme_debian) {
42                 $readme_debian=pkgfile($package,'README.debian');
43         }
44         if ($readme_debian) {
45                 doit("install","-g",0,"-o",0,"-m","644","-p","$readme_debian",
46                         "$tmp/usr/share/doc/$package/README.Debian");
47         }
48
49         my $todo=pkgfile($package,'TODO');
50         if ($todo) {
51                 if (isnative($package)) {
52                         doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
53                                 "$tmp/usr/share/doc/$package/TODO");
54                 }
55                 else {
56                         doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
57                                 "$tmp/usr/share/doc/$package/TODO.Debian");
58                 }
59         }
60
61         # If the "directory" is a dangling symlink, then don't install
62         # the copyright file. This is useful for multibinary packages 
63         # that share a doc directory.
64         if (-d "$tmp/usr/share/doc/$package") {
65                 # Support debian/package.copyright, but if not present, fall
66                 # back on debian/copyright for all packages, not just the 
67                 # main binary package.
68                 my $copyright=pkgfile($package,'copyright');
69                 if (! $copyright && -e "debian/copyright") {
70                         $copyright="debian/copyright";
71                 }
72                 if ($copyright) {
73                                 doit("install","-g",0,"-o",0,"-m","644","-p",$copyright,
74                                         "$tmp/usr/share/doc/$package/copyright");
75                 }
76         }
77
78         # Add in the /usr/doc compatability symlinks code.
79         if (! $dh{NOSCRIPTS}) {
80                 autoscript($package,"postinst","postinst-doc",
81                         "s/#PACKAGE#/$package/g",
82                 );
83                 autoscript($package,"prerm","prerm-doc",
84                         "s/#PACKAGE#/$package/g",
85                 );
86         }
87
88         # Handle doc-base files. There are two filename formats, the usual
89         # plus an extended format (debian/package.*).
90         my %doc_ids;
91         
92         opendir(DEB,"debian/") || error("can't read debian directory: $!");
93         # If this is the main package, we need to handle unprefixed filenames.
94         # For all packages, we must support both the usual filename format plus
95         # that format with a period an something appended.
96         my $regexp="\Q$package\E\.";
97         if ($package eq $dh{MAINPACKAGE}) {
98                 $regexp="(|$regexp)";
99         }
100         foreach my $fn (grep {/^${regexp}doc-base(\..*)?$/} readdir(DEB)) {
101                 # Parse the file to get the doc id.
102                 open (IN, "debian/$fn") || die "Cannot read debian/$fn.";
103                 while (<IN>) {
104                         if (/^Document:\s+(.*)(\s+)?/) {
105                                 $doc_ids{$fn}=$1;
106                                 last;
107                         }
108                 }
109                 close IN;
110         }
111         closedir(DEB);
112         
113         if (%doc_ids) {
114                 if (! -d "$tmp/usr/share/doc-base/") {
115                         doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc-base/");
116                 }
117         }
118         foreach my $fn (keys %doc_ids) {
119                 doit("install","-g",0,"-o",0,"-m644","-p","debian/$fn",
120                      "$tmp/usr/share/doc-base/$doc_ids{$fn}");
121                 if (! $dh{NOSCRIPTS}) {
122                         autoscript($package,"postinst","postinst-doc-base",
123                                 "s/#DOC-ID#/$doc_ids{$fn}/",
124                         );
125                         autoscript($package,"prerm","prerm-doc-base",
126                                 "s/#DOC-ID#/$doc_ids{$fn}/",
127                         );
128                 }
129         }
130 }