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