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.
74 =item B<--link-doc=>I<package>
76 Make the documentation directory of all packages acted on be a symlink to
77 the documentation directory of I<package>. This has no effect when acting on
78 I<package> itself, or if the documentation directory to be created already
79 exists when B<dh_installdocs> is run. To comply with policy, I<package> must
80 be a binary package that comes from the same source package.
82 debhelper will try to avoid installing files into linked documentation
83 directories that would cause conflicts with the linked package. The B<-A>
84 option will have no effect on packages with linked documentation
85 directories, and copyright, changelog, README.Debian, and TODO files will
90 Install these files as documentation into the first package acted on. (Or
91 in all packages if B<-A> is specified).
97 This is an example of a debian/package.docs file:
101 debian/notes-for-maintainers.txt
108 Note that dh_installdocs will happily copy entire directory hierarchies if
109 you ask it to (similar to cp -a). If it is asked to install a
110 directory, it will install the complete contents of the directory.
112 Note that this command is not idempotent. L<dh_prep(1)> should be called
113 between invocations of this command. Otherwise, it may cause multiple
114 instances of the same text to be added to maintainer scripts.
119 # Create documentation directories on demand. This allows us to use dangling
120 # symlinks for linked documentation directories unless additional files need
124 return if $docdir_created{$package};
125 my $tmp=tmpdir($package);
128 if ($dh{LINK_DOC} && $dh{LINK_DOC} ne $package) {
129 $target="$tmp/usr/share/doc/$dh{LINK_DOC}";
132 $target="$tmp/usr/share/doc/$package";
135 # If this is a symlink, leave it alone.
136 if (! -d $target && ! -l $target) {
137 doit("install","-g",0,"-o",0,"-d",$target);
139 $docdir_created{$package}=1;
143 "link-doc=s" => \$dh{LINK_DOC},
146 foreach my $package (@{$dh{DOPACKAGES}}) {
147 next if is_udeb($package);
149 my $tmp=tmpdir($package);
150 my $file=pkgfile($package,"docs");
151 my $link_doc=($dh{LINK_DOC} && $dh{LINK_DOC} ne $package);
154 # Make sure that the parent directory exists.
155 if (! -d "$tmp/usr/share/doc" && ! -l "$tmp/usr/share/doc") {
156 doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc");
158 # Create symlink to another documentation directory if
160 if (! -d "$tmp/usr/share/doc/$package" &&
161 ! -l "$tmp/usr/share/doc/$package") {
162 doit("ln", "-sf", $dh{LINK_DOC}, "$tmp/usr/share/doc/$package");
163 # Policy says that if you make your documentation
164 # directory a symlink, then you have to depend on
166 addsubstvar($package, "misc:Depends", $dh{LINK_DOC});
170 ensure_docdir($package);
176 @docs=filearray($file, ".");
179 if (($package eq $dh{FIRSTPACKAGE} || ($dh{PARAMS_ALL} && ! $link_doc)) && @ARGV) {
185 if ($dh{EXCLUDE_FIND}) {
186 $exclude .= ' -and ! \( '.$dh{EXCLUDE_FIND}.' \)';
189 # ignore empty files in subdirs
190 $exclude .= ' -and ! -empty';
192 foreach my $doc (@docs) {
193 next if excludefile($doc);
194 next if -e $doc && ! -s $doc && ! compat(4); # ignore empty files
195 ensure_docdir($package);
196 if (-d $doc && length $exclude) {
197 my $basename = basename($doc);
198 my $dir = ($basename eq '.') ? $doc : "$doc/..";
201 complex_doit("cd '$dir' && find '$basename' \\( -type f -or -type l \\)$exclude -exec cp --parents -dp {} $pwd/$tmp/usr/share/doc/$package \\;");
204 doit("cp", "-a", $doc, "$tmp/usr/share/doc/$package");
207 doit("chown","-R","0:0","$tmp/usr/share/doc");
208 doit("chmod","-R","go=rX","$tmp/usr/share/doc");
209 doit("chmod","-R","u+rw","$tmp/usr/share/doc");
212 # .Debian is correct, according to policy, but I'm easy.
213 my $readme_debian=pkgfile($package,'README.Debian');
214 if (! $readme_debian) {
215 $readme_debian=pkgfile($package,'README.debian');
217 if (! $link_doc && $readme_debian && ! excludefile($readme_debian)) {
218 ensure_docdir($package);
219 doit("install","-g",0,"-o",0,"-m","644","-p","$readme_debian",
220 "$tmp/usr/share/doc/$package/README.Debian");
223 my $todo=pkgfile($package,'TODO');
224 if (! $link_doc && $todo && ! excludefile($todo)) {
225 ensure_docdir($package);
226 if (isnative($package)) {
227 doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
228 "$tmp/usr/share/doc/$package/TODO");
231 doit("install","-g",0,"-o",0,"-m","644","-p",$todo,
232 "$tmp/usr/share/doc/$package/TODO.Debian");
236 # If the "directory" is a dangling symlink, then don't install
237 # the copyright file. This is useful for multibinary packages
238 # that share a doc directory.
239 if (! $link_doc && (! -l "$tmp/usr/share/doc/$package" || -d "$tmp/usr/share/doc/$package")) {
240 # Support debian/package.copyright, but if not present, fall
241 # back on debian/copyright for all packages, not just the
242 # main binary package.
243 my $copyright=pkgfile($package,'copyright');
244 if (! $copyright && -e "debian/copyright") {
245 $copyright="debian/copyright";
247 if ($copyright && ! excludefile($copyright)) {
248 ensure_docdir($package);
249 doit("install","-g",0,"-o",0,"-m","644","-p",$copyright,
250 "$tmp/usr/share/doc/$package/copyright");
254 # Handle doc-base files. There are two filename formats, the usual
255 # plus an extended format (debian/package.*).
258 opendir(DEB,"debian/") || error("can't read debian directory: $!");
259 # If this is the main package, we need to handle unprefixed filenames.
260 # For all packages, we must support both the usual filename format plus
261 # that format with a period an something appended.
262 my $regexp="\Q$package\E\.";
263 if ($package eq $dh{MAINPACKAGE}) {
264 $regexp="(|$regexp)";
266 foreach my $fn (grep {/^${regexp}doc-base(\..*)?$/} readdir(DEB)) {
267 # .EX are example files, generated by eg, dh-make
268 next if $fn=~/\.EX$/;
269 next if excludefile($fn);
270 # Parse the file to get the doc id.
271 open (IN, "debian/$fn") || die "Cannot read debian/$fn.";
274 if (/^Document\s*:\s*(.*)/) {
284 if (! -d "$tmp/usr/share/doc-base/") {
285 doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc-base/");
288 foreach my $fn (keys %doc_ids) {
289 doit("install","-g",0,"-o",0,"-m644","-p","debian/$fn",
290 "$tmp/usr/share/doc-base/$doc_ids{$fn}");
298 This program is a part of debhelper.
302 Joey Hess <joeyh@debian.org>