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