]> git.donarmstrong.com Git - debhelper.git/blob - dh_installdocs
r231: Initial Import
[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/lib/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 plus
66         # an extended format (debian/package.doc-base.<doc-id>). Have to
67         # come up with good document-id's too.
68         my %doc_ids;
69         
70         opendir(DEB,"debian/") || error("can't read debian directory: $!");
71         foreach (grep {/^\Q$PACKAGE\E\.doc-base\..*$/} readdir(DEB)) {
72                 $id=$_;
73                 $id=~s/\.doc-base\./-/;
74                 $doc_ids{$id}="debian/$_";
75         }
76         closedir(DEB);
77         
78         # These next lines handle the format debian/doc-base.<doc-id>, 
79         # which is in for completeness.
80         if ($PACKAGE eq $dh{MAINPACKAGE}) {
81                 opendir(DEB,"debian/") || error("can't read debian directory: $!");
82                 foreach (grep {/^doc-base\..*$/} readdir(DEB)) {
83                         $id=$_;
84                         $id=~s/doc-base\./$PACKAGE-/;
85                         $doc_ids{$id}="debian/$_";
86                 }
87                 closedir(DEB);
88         }
89         
90         # And this handles the normal format of course.
91         $file=pkgfile($PACKAGE,"doc-base");
92         if ($file ne '') {
93                 $doc_ids{$PACKAGE}=$file;
94         }
95         
96         if (%doc_ids) {
97                 if (! -d "$TMP/usr/share/doc-base/") {
98                         doit("install","-d","$TMP/usr/share/doc-base/");
99                 }
100         }
101         foreach $doc_id (keys %doc_ids) {
102                 doit("install","-m644","-p",$doc_ids{$doc_id},
103                      "$TMP/usr/share/doc-base/$doc_id");
104                 if (! $dh{NOSCRIPTS}) {
105                         autoscript($PACKAGE,"postinst","postinst-doc-base",
106                                 "s/#DOC-ID#/$doc_id/",
107                         );
108                         autoscript($PACKAGE,"prerm","prerm-doc-base",
109                                 "s/#DOC-ID#/$doc_id/",
110                         );
111                 }
112         }
113 }