]> git.donarmstrong.com Git - debhelper.git/blob - dh_installdocs
r430: the great pod juggernaught rolls on through the night
[debhelper.git] / dh_installdocs
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installdocs - install documentation into package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14   dh_installdocs debhelper options] [-A] [-n] [file ...]
15
16 =head1 DESCRIPTION
17
18 dh_installdocs is a debhelper program that is responsible for installing
19 documentation into usr/share/doc/package in package build directories.
20
21 dh_installdocs automatically installs debian/copyright if it exists. If
22 dh_installdocs is acting on multiple packages, debian/copyright files will be
23 installed into all packages. However, if you need to have seperate copyright
24 files for different binary packages, you can use files named
25 debian/package.copyright.
26
27 Any filenames specified as parameters will be installed into the first
28 package dh_installdocs is told to act on. By default, this is the first
29 binary package in debian/control, but if you use -p, -i, or -a flags, it
30 will be the first package specified by those flags.
31
32 Also, debian/README.Debian (or debian/README.debian) and debian/TODO, if
33 they exist, will be installed into the first binary package listed in
34 debian/control, if dh_installdocs is acting on that package. Note that
35 debian/TODO will be installed named TODO.Debian, if the package is not a
36 debian native package. Also note that README.debian is installed as
37 README.Debian, for consitency. Note that debian/package.README.Debian and
38 debian/package.TODO can be used to specify files for subpackages.
39
40 Files named debian/package.docs can list other files to be installed.
41
42 This program will automatically generate postinst and prerm commands to
43 maintain a compatibility symlink, /usr/doc/package, to the documentation in
44 /usr/share/doc/package. See L<dh_installdeb(1)> for an explanation of how
45 this works.
46
47 Files named debian/package.doc-base, will be installed as doc-base control
48 files, and will make this program automatically generate the postinst and
49 prerm commands needed to interface with the doc-base package. Note that the
50 doc-id will be determined from the "Document:" entry in the
51 doc-base control file in question.
52
53 If your package needs to register more than one document, you need multiple
54 files. To accomplish this, you can use files named debian/package.doc-base.*
55
56 =head1 OPTIONS
57
58 =over 4
59
60 =item B<-A>, B<--all>
61
62 Install all files specified by command line parameters in ALL packages
63 acted on.
64
65 =item B<-n>, B<--noscripts>
66
67 Do not modify postinst/prerm scripts.
68
69 =item I<file ...>
70
71 Install these files as documentation into the first package acted on. (Or
72 in all packages if -A is specified).
73
74 =back
75
76 =head1 NOTES
77
78 Note that dh_installdocs will happily copy entire directory hierarchies if
79 you ask it to (it uses cp -a internally). If it is asked to install a
80 directory, it will install the complete contents of the directory.
81
82 Note that this command is not idempotent. "dh_clean -k" should be called
83 between invocations of this command. Otherwise, it may cause multiple
84 instances of the same text to be added to maintainer scripts.
85
86 =cut
87
88 init();
89
90 foreach my $package (@{$dh{DOPACKAGES}}) {
91         my $tmp=tmpdir($package);
92         my $file=pkgfile($package,"docs");
93
94         # If this is a symlink, leave it alone.
95         if ( ! -d "$tmp/usr/share/doc/$package" &&
96              ! -l "$tmp/usr/share/doc/$package") {
97                 doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc/$package");
98         }
99
100         my @docs;
101
102         if ($file) {
103                 @docs=filearray($file, ".");
104         }
105
106         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
107                 push @docs, @ARGV;
108         }
109
110         if (@docs) {
111                 doit("cp", "-a",@docs,"$tmp/usr/share/doc/$package/");
112                 doit("chown","-R","0.0","$tmp/usr/share/doc");
113                 doit("chmod","-R","go=rX","$tmp/usr/share/doc");
114                 doit("chmod","-R","u+rw","$tmp/usr/share/doc");
115         }
116
117         # .Debian is correct, according to policy, but I'm easy.
118         my $readme_debian=pkgfile($package,'README.Debian');
119         if (! $readme_debian) {
120                 $readme_debian=pkgfile($package,'README.debian');
121         }
122         if ($readme_debian) {
123                 doit("install","-g",0,"-o",0,"-m","644","-p","$readme_debian",
124                         "$tmp/usr/share/doc/$package/README.Debian");
125         }
126
127         my $todo=pkgfile($package,'TODO');
128         if ($todo) {
129                 if (isnative($package)) {
130                         doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
131                                 "$tmp/usr/share/doc/$package/TODO");
132                 }
133                 else {
134                         doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
135                                 "$tmp/usr/share/doc/$package/TODO.Debian");
136                 }
137         }
138
139         # If the "directory" is a dangling symlink, then don't install
140         # the copyright file. This is useful for multibinary packages 
141         # that share a doc directory.
142         if (-d "$tmp/usr/share/doc/$package") {
143                 # Support debian/package.copyright, but if not present, fall
144                 # back on debian/copyright for all packages, not just the 
145                 # main binary package.
146                 my $copyright=pkgfile($package,'copyright');
147                 if (! $copyright && -e "debian/copyright") {
148                         $copyright="debian/copyright";
149                 }
150                 if ($copyright) {
151                                 doit("install","-g",0,"-o",0,"-m","644","-p",$copyright,
152                                         "$tmp/usr/share/doc/$package/copyright");
153                 }
154         }
155
156         # Add in the /usr/doc compatability symlinks code.
157         if (! $dh{NOSCRIPTS}) {
158                 autoscript($package,"postinst","postinst-doc",
159                         "s/#PACKAGE#/$package/g",
160                 );
161                 autoscript($package,"prerm","prerm-doc",
162                         "s/#PACKAGE#/$package/g",
163                 );
164         }
165
166         # Handle doc-base files. There are two filename formats, the usual
167         # plus an extended format (debian/package.*).
168         my %doc_ids;
169         
170         opendir(DEB,"debian/") || error("can't read debian directory: $!");
171         # If this is the main package, we need to handle unprefixed filenames.
172         # For all packages, we must support both the usual filename format plus
173         # that format with a period an something appended.
174         my $regexp="\Q$package\E\.";
175         if ($package eq $dh{MAINPACKAGE}) {
176                 $regexp="(|$regexp)";
177         }
178         foreach my $fn (grep {/^${regexp}doc-base(\..*)?$/} readdir(DEB)) {
179                 # Parse the file to get the doc id.
180                 open (IN, "debian/$fn") || die "Cannot read debian/$fn.";
181                 while (<IN>) {
182                         if (/^Document:\s+(.*)(\s+)?/) {
183                                 $doc_ids{$fn}=$1;
184                                 last;
185                         }
186                 }
187                 close IN;
188         }
189         closedir(DEB);
190         
191         if (%doc_ids) {
192                 if (! -d "$tmp/usr/share/doc-base/") {
193                         doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc-base/");
194                 }
195         }
196         foreach my $fn (keys %doc_ids) {
197                 doit("install","-g",0,"-o",0,"-m644","-p","debian/$fn",
198                      "$tmp/usr/share/doc-base/$doc_ids{$fn}");
199                 if (! $dh{NOSCRIPTS}) {
200                         autoscript($package,"postinst","postinst-doc-base",
201                                 "s/#DOC-ID#/$doc_ids{$fn}/",
202                         );
203                         autoscript($package,"prerm","prerm-doc-base",
204                                 "s/#DOC-ID#/$doc_ids{$fn}/",
205                         );
206                 }
207         }
208 }
209
210 =head1 SEE ALSO
211
212 L<debhelper(1)>
213
214 This program is a part of debhelper.
215
216 =head1 AUTHOR
217
218 Joey Hess <joeyh@debian.org>
219
220 =cut