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