]> git.donarmstrong.com Git - debhelper.git/blobdiff - dh_installdocs
r226: Initial Import
[debhelper.git] / dh_installdocs
index 336ed6eedf201c18c2dfec7de7362502377798e3..54e5b8e7904b52b2ca9f643b819a3321595eca01 100755 (executable)
-#!/bin/sh -e
+#!/usr/bin/perl -w
 #
 # Reads debian/docs, installs all files listed there into /usr/doc/$PACKAGE
 # Also installs the debian/copyright and debian/README.debian and debian/TODO
+# and handles debian/doc-base.
 
-PATH=debian:$PATH:/usr/lib/debhelper
-source dh_lib
-
-for PACKAGE in $DH_DOPACKAGES; do
-       TMP=`tmpdir $PACKAGE`
-       EXT=`pkgext $PACKAGE`
-
-       if [ ! -d debian/$TMP/usr/doc/$PACKAGE ]; then
-               doit "install -d debian/$TMP/usr/doc/$PACKAGE"
-       fi
-
-       docs=""
-
-       if [ -e debian/${EXT}docs ]; then
-               docs=`cat debian/${EXT}docs | tr "\n" " "`
-       fi
-
-       if [ "$PACKAGE" = "$MAINPACKAGE" -a "$*" ]; then
-               docs="$* $docs"
-       fi
-
-       if [ "$docs" ]; then
-               for file in $docs; do
-                       doit "cp -a $file debian/$TMP/usr/doc/$PACKAGE/"
-               done
-       fi
-
-       # Install these files only into the main package by default.
-       if [ "$PACKAGE" = "$MAINPACKAGE" ]; then
-               for file in README.debian TODO ; do
-                       if [ -f debian/$file ]; then
-                               doit "install -m 644 -p debian/$file debian/$TMP/usr/doc/$PACKAGE/"
-                       fi
-               done
-       fi
-
-       if [ -f debian/copyright ]; then
-                       doit "install -m 644 -p debian/copyright debian/$TMP/usr/doc/$PACKAGE/"
-       fi
-done
+BEGIN { push @INC, "debian", "/usr/lib/debhelper" }
+use Dh_Lib;
+init();
+
+foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
+       $TMP=tmpdir($PACKAGE);
+       $file=pkgfile($PACKAGE,"docs");
+
+       if ( ! -d "$TMP/usr/doc/$PACKAGE") {
+               doit("install","-d","$TMP/usr/doc/$PACKAGE");
+       }
+
+       undef @docs;
+
+       if ($file) {
+               @docs=filearray($file);
+       }
+
+       if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
+               push @docs, @ARGV;
+       }
+
+       if (@docs) {
+               doit("cp","-a",@docs,"$TMP/usr/doc/$PACKAGE/");
+               doit("chmod","-R","go=rX","$TMP/usr/doc");
+               doit("chmod","-R","u+rw","$TMP/usr/doc");
+       }
+
+       # .Debian is correct, according to policy, but I'm easy.
+       $readme_debian=pkgfile($PACKAGE,'README.Debian');
+       if (! $readme_debian) {
+               $readme_debian=pkgfile($PACKAGE,'README.debian');
+       }
+       if ($readme_debian) {
+               doit("install","-m","644","-p","$readme_debian","$TMP/usr/doc/$PACKAGE/README.Debian");
+       }
+
+       $todo=pkgfile($PACKAGE,'TODO');
+       if ($todo) {
+               if (isnative($PACKAGE)) {
+                       doit("install","-m","644","-p",$todo,"$TMP/usr/doc/$PACKAGE/TODO");
+               }
+               else {
+                       doit("install","-m","644","-p",$todo,"$TMP/usr/doc/$PACKAGE/TODO.Debian");
+               }
+       }
+
+       # Support debian/package.copyright, but if not present, fall back
+       # on debian/copyright for all packages, not just the main binary
+       # package.
+       $copyright=pkgfile($PACKAGE,'copyright');
+       if (! $copyright && -e "debian/copyright") {
+               $copyright="debian/copyright";
+       }
+       if ($copyright) {
+                       doit("install","-m","644","-p",$copyright,"$TMP/usr/doc/$PACKAGE/copyright");
+       }
+       
+       # Handle doc-base files. There are two filename formats, the usual plus
+       # an extended format (debian/package.doc-base.<doc-id>). Have to
+       # come up with good document-id's too.
+       my %doc_ids;
+       
+       opendir(DEB,"debian/") || error("can't read debian directory: $!");
+       foreach (grep {/^\Q$PACKAGE\E\.doc-base\..*$/} readdir(DEB)) {
+               $id=$_;
+               $id=~s/\.doc-base\./-/;
+               $doc_ids{$id}="debian/$_";
+       }
+       closedir(DEB);
+       
+       # These next lines handle the format debian/doc-base.<doc-id>, 
+       # which is in for completeness.
+       if ($PACKAGE eq $dh{MAINPACKAGE}) {
+               opendir(DEB,"debian/") || error("can't read debian directory: $!");
+               foreach (grep {/^doc-base\..*$/} readdir(DEB)) {
+                       $id=$_;
+                       $id=~s/doc-base\./$PACKAGE-/;
+                       $doc_ids{$id}="debian/$_";
+               }
+               closedir(DEB);
+       }
+       
+       # And this handles the normal format of course.
+       $file=pkgfile($PACKAGE,"doc-base");
+       if ($file ne '') {
+               $doc_ids{$PACKAGE}=$file;
+       }
+       
+       if (%doc_ids) {
+               if (! -d "$TMP/usr/share/doc-base/") {
+                       doit("install","-d","$TMP/usr/share/doc-base/");
+               }
+       }
+       foreach $doc_id (keys %doc_ids) {
+               doit("install","-m644","-p",$doc_ids{$doc_id},
+                    "$TMP/usr/share/doc-base/$doc_id");
+               if (! $dh{NOSCRIPTS}) {
+                       autoscript($PACKAGE,"postinst","postinst-doc-base",
+                               "s/#DOC-ID#/$doc_id/",
+                       );
+                       autoscript($PACKAGE,"prerm","prerm-doc-base",
+                               "s/#DOC-ID#/$doc_id/",
+                       );
+               }
+       }
+}