5 dh_installdocs - install documentation into package build directories
10 use Debian::Debhelper::Dh_Lib;
14 B<dh_installdocs> [S<I<debhelper options>>] [B<-A>] [B<-X>I<item>] [S<I<file ...>>]
18 dh_installdocs is a debhelper program that is responsible for installing
19 documentation into usr/share/doc/package in package build directories.
25 =item debian/I<package>.docs
27 List documentaton files to be installed into I<package>.
29 =item debian/copyright
31 =item debian/README.Debian
35 =item debian/I<package>.copyright
37 =item debian/I<package>.README.Debian
39 =item debian/I<package>.TODO
41 Each of these files is automatically installed if present. Use the package
42 specific name if I<package> needs a different version of the file.
44 Note that debian/README.debian is also installed as README.Debian,
45 and debian/TODO will be installed as TODO.Debian in non-native packages.
47 =item debian/I<package>.doc-base
49 Installed as doc-base control files. Note that the doc-id will be
50 determined from the "Document:" entry in the doc-base control file in
53 =item debian/I<package>.doc-base.*
55 If your package needs to register more than one document, you need multiple
56 doc-base files, and can name them like this.
66 Install all files specified by command line parameters in ALL packages
69 =item B<-Xitem>, B<--exclude=item>
71 Exclude files that contain "item" anywhere in their filename from
72 being installed. Note that this includes doc-base files.
76 Install these files as documentation into the first package acted on. (Or
77 in all packages if B<-A> is specified).
83 This is an example of a debian/package.docs file:
87 debian/notes-for-maintainers.txt
94 Note that dh_installdocs will happily copy entire directory hierarchies if
95 you ask it to (similar to cp -a). If it is asked to install a
96 directory, it will install the complete contents of the directory.
98 Note that this command is not idempotent. L<dh_prep(1)> should be called
99 between invocations of this command. Otherwise, it may cause multiple
100 instances of the same text to be added to maintainer scripts.
106 foreach my $package (@{$dh{DOPACKAGES}}) {
107 next if is_udeb($package);
109 my $tmp=tmpdir($package);
110 my $file=pkgfile($package,"docs");
112 # If this is a symlink, leave it alone.
113 if ( ! -d "$tmp/usr/share/doc/$package" &&
114 ! -l "$tmp/usr/share/doc/$package") {
115 doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc/$package");
121 @docs=filearray($file, ".");
124 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
130 if ($dh{EXCLUDE_FIND}) {
131 $exclude .= ' -and ! \( '.$dh{EXCLUDE_FIND}.' \)';
134 # ignore empty files in subdirs
135 $exclude .= ' -and ! -empty';
137 foreach my $doc (@docs) {
138 next if excludefile($doc);
139 next if -e $doc && ! -s $doc && ! compat(4); # ignore empty files
140 if (-d $doc && length $exclude) {
141 my $basename = basename($doc);
142 my $dir = ($basename eq '.') ? $doc : "$doc/..";
145 complex_doit("cd '$dir' && find '$basename' \\( -type f -or -type l \\)$exclude -exec cp --parents -dp {} $pwd/$tmp/usr/share/doc/$package \\;");
148 doit("cp", "-a", $doc, "$tmp/usr/share/doc/$package");
151 doit("chown","-R","0:0","$tmp/usr/share/doc");
152 doit("chmod","-R","go=rX","$tmp/usr/share/doc");
153 doit("chmod","-R","u+rw","$tmp/usr/share/doc");
156 # .Debian is correct, according to policy, but I'm easy.
157 my $readme_debian=pkgfile($package,'README.Debian');
158 if (! $readme_debian) {
159 $readme_debian=pkgfile($package,'README.debian');
161 if ($readme_debian && ! excludefile($readme_debian)) {
162 doit("install","-g",0,"-o",0,"-m","644","-p","$readme_debian",
163 "$tmp/usr/share/doc/$package/README.Debian");
166 my $todo=pkgfile($package,'TODO');
167 if ($todo && ! excludefile($todo)) {
168 if (isnative($package)) {
169 doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
170 "$tmp/usr/share/doc/$package/TODO");
173 doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
174 "$tmp/usr/share/doc/$package/TODO.Debian");
178 # If the "directory" is a dangling symlink, then don't install
179 # the copyright file. This is useful for multibinary packages
180 # that share a doc directory.
181 if (-d "$tmp/usr/share/doc/$package") {
182 # Support debian/package.copyright, but if not present, fall
183 # back on debian/copyright for all packages, not just the
184 # main binary package.
185 my $copyright=pkgfile($package,'copyright');
186 if (! $copyright && -e "debian/copyright") {
187 $copyright="debian/copyright";
189 if ($copyright && ! excludefile($copyright)) {
190 doit("install","-g",0,"-o",0,"-m","644","-p",$copyright,
191 "$tmp/usr/share/doc/$package/copyright");
195 # Handle doc-base files. There are two filename formats, the usual
196 # plus an extended format (debian/package.*).
199 opendir(DEB,"debian/") || error("can't read debian directory: $!");
200 # If this is the main package, we need to handle unprefixed filenames.
201 # For all packages, we must support both the usual filename format plus
202 # that format with a period an something appended.
203 my $regexp="\Q$package\E\.";
204 if ($package eq $dh{MAINPACKAGE}) {
205 $regexp="(|$regexp)";
207 foreach my $fn (grep {/^${regexp}doc-base(\..*)?$/} readdir(DEB)) {
208 # .EX are example files, generated by eg, dh-make
209 next if $fn=~/\.EX$/;
210 next if excludefile($fn);
211 # Parse the file to get the doc id.
212 open (IN, "debian/$fn") || die "Cannot read debian/$fn.";
215 if (/^Document\s*:\s*(.*)/) {
225 if (! -d "$tmp/usr/share/doc-base/") {
226 doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc-base/");
229 foreach my $fn (keys %doc_ids) {
230 doit("install","-g",0,"-o",0,"-m644","-p","debian/$fn",
231 "$tmp/usr/share/doc-base/$doc_ids{$fn}");
239 This program is a part of debhelper.
243 Joey Hess <joeyh@debian.org>