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