]> git.donarmstrong.com Git - debhelper.git/blob - dh_installdocs
r291: * dh_installdocs: if $TMP/usr/share/doc/$PACKAGE is a broken symlink,
[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 BEGIN { push @INC, "debian", "/usr/share/debhelper" }
9 use Dh_Lib;
10 init();
11
12 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
13         $TMP=tmpdir($PACKAGE);
14         $file=pkgfile($PACKAGE,"docs");
15
16         # If this is a dangling symlink, leave it. The maintainer
17         # better know what they're doing.
18         if ( ! -d "$TMP/usr/share/doc/$PACKAGE" && 
19              ! -l "$TMP/usr/share/doc/$PACKAGE") {
20                 doit("install","-d","$TMP/usr/share/doc/$PACKAGE");
21         }
22
23         undef @docs;
24
25         if ($file) {
26                 @docs=filearray($file);
27         }
28
29         if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
30                 push @docs, @ARGV;
31         }
32
33         if (@docs) {
34                 doit("cp","-a",@docs,"$TMP/usr/share/doc/$PACKAGE/");
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         $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","-m","644","-p","$readme_debian",
46                         "$TMP/usr/share/doc/$PACKAGE/README.Debian");
47         }
48
49         $todo=pkgfile($PACKAGE,'TODO');
50         if ($todo) {
51                 if (isnative($PACKAGE)) {
52                         doit("install","-m","644","-p",$todo,
53                                 "$TMP/usr/share/doc/$PACKAGE/TODO");
54                 }
55                 else {
56                         doit("install","-m","644","-p",$todo,
57                                 "$TMP/usr/share/doc/$PACKAGE/TODO.Debian");
58                 }
59         }
60
61         # Support debian/package.copyright, but if not present, fall back
62         # on debian/copyright for all packages, not just the main binary
63         # package.
64         $copyright=pkgfile($PACKAGE,'copyright');
65         if (! $copyright && -e "debian/copyright") {
66                 $copyright="debian/copyright";
67         }
68         if ($copyright) {
69                         doit("install","-m","644","-p",$copyright,
70                                 "$TMP/usr/share/doc/$PACKAGE/copyright");
71         }
72
73         # Add in the /usr/doc compatability symlinks code.
74         if (! $dh{NOSCRIPTS}) {
75                 autoscript($PACKAGE,"postinst","postinst-doc",
76                         "s/#PACKAGE#/$PACKAGE/g",
77                 );
78                 autoscript($PACKAGE,"prerm","prerm-doc",
79                         "s/#PACKAGE#/$PACKAGE/g",
80                 );
81         }
82
83         # Handle doc-base files. There are two filename formats, the usual
84         # plus an extended format (debian/package.*).
85         my %doc_ids;
86         
87         opendir(DEB,"debian/") || error("can't read debian directory: $!");
88         # If this is the main package, we need to handle unprefixed filenames.
89         # For all packages, we must support both the usual filename format plus
90         # that format with a period an something appended.
91         my $regexp="\Q$PACKAGE\E\.";
92         if ($PACKAGE eq $dh{MAINPACKAGE}) {
93                 $regexp="(|$regexp)";
94         }
95         foreach my $fn (grep {/^${regexp}doc-base(\..*)?$/} readdir(DEB)) {
96                 # Parse the file to get the doc id.
97                 open (IN, "debian/$fn") || die "Cannot read debian/$fn.";
98                 while (<IN>) {
99                         if (/^Document:\s+(.*)(\s+)?/) {
100                                 $doc_ids{$fn}=$1;
101                                 last;
102                         }
103                 }
104                 close IN;
105         }
106         closedir(DEB);
107         
108         if (%doc_ids) {
109                 if (! -d "$TMP/usr/share/doc-base/") {
110                         doit("install","-d","$TMP/usr/share/doc-base/");
111                 }
112         }
113         foreach my $fn (keys %doc_ids) {
114                 doit("install","-m644","-p","debian/$fn",
115                      "$TMP/usr/share/doc-base/$doc_ids{$fn}");
116                 if (! $dh{NOSCRIPTS}) {
117                         autoscript($PACKAGE,"postinst","postinst-doc-base",
118                                 "s/#DOC-ID#/$doc_ids{$fn}/",
119                         );
120                         autoscript($PACKAGE,"prerm","prerm-doc-base",
121                                 "s/#DOC-ID#/$doc_ids{$fn}/",
122                         );
123                 }
124         }
125 }