]> git.donarmstrong.com Git - debhelper.git/blob - dh_installdocs
r281: * dh_installdocs: create the compatability symlink before calling
[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         # Add in the /usr/doc compatability symlinks code.
71         if (! $dh{NOSCRIPTS}) {
72                 autoscript($PACKAGE,"postinst","postinst-doc",
73                         "s/#PACKAGE#/$PACKAGE/g",
74                 );
75                 autoscript($PACKAGE,"prerm","prerm-doc",
76                         "s/#PACKAGE#/$PACKAGE/g",
77                 );
78         }
79
80         # Handle doc-base files. There are two filename formats, the usual
81         # plus an extended format (debian/package.*).
82         my %doc_ids;
83         
84         opendir(DEB,"debian/") || error("can't read debian directory: $!");
85         # If this is the main package, we need to handle unprefixed filenames.
86         # For all packages, we must support both the usual filename format plus
87         # that format with a period an something appended.
88         my $regexp="\Q$PACKAGE\E\.";
89         if ($PACKAGE eq $dh{MAINPACKAGE}) {
90                 $regexp="(|$regexp)";
91         }
92         foreach my $fn (grep {/^${regexp}doc-base(\..*)?$/} readdir(DEB)) {
93                 # Parse the file to get the doc id.
94                 open (IN, "debian/$fn") || die "Cannot read debian/$fn.";
95                 while (<IN>) {
96                         if (/^Document:\s+(.*)(\s+)?/) {
97                                 $doc_ids{$fn}=$1;
98                                 last;
99                         }
100                 }
101                 close IN;
102         }
103         closedir(DEB);
104         
105         if (%doc_ids) {
106                 if (! -d "$TMP/usr/share/doc-base/") {
107                         doit("install","-d","$TMP/usr/share/doc-base/");
108                 }
109         }
110         foreach my $fn (keys %doc_ids) {
111                 doit("install","-m644","-p","debian/$fn",
112                      "$TMP/usr/share/doc-base/$doc_ids{$fn}");
113                 if (! $dh{NOSCRIPTS}) {
114                         autoscript($PACKAGE,"postinst","postinst-doc-base",
115                                 "s/#DOC-ID#/$doc_ids{$fn}/",
116                         );
117                         autoscript($PACKAGE,"prerm","prerm-doc-base",
118                                 "s/#DOC-ID#/$doc_ids{$fn}/",
119                         );
120                 }
121         }
122 }