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