r120: Initial Import
authorjoey <joey>
Tue, 17 Aug 1999 04:59:59 +0000 (04:59 +0000)
committerjoey <joey>
Tue, 17 Aug 1999 04:59:59 +0000 (04:59 +0000)
Dh_Lib.pm
debian/changelog
dh_installmanpages
doc/TODO

index e707032615df09281f71db94561ad47832dd069f..a3965ec1485443e542918e96fa4bbb776aef07f2 100644 (file)
--- a/Dh_Lib.pm
+++ b/Dh_Lib.pm
@@ -136,7 +136,13 @@ sub warning { my $message=shift;
 
 # Returns the basename of the argument passed to it.
 sub basename { my $fn=shift;
-       $fn=~s:.*/(.*?):$1:;
+       $fn=~s:^.*/(.*?)$:$1:;
+       return $fn;
+}
+
+# Returns the directory name of the argument passed to it.
+sub dirname { my $fn=shift;
+       $fn=~s:^(.*)/.*?$:$1:;
        return $fn;
 }
 
index 05d3981093b260b6e7f97a190750ce6916eab324..3ee300483f740a34e6d7f564ac8abeec6e65f83f 100644 (file)
@@ -1,3 +1,10 @@
+debhelper (1.1.13) unstable; urgency=low
+
+  * dh_installmanpages: rewritten in perl. Allows me to fix bug #26221 (long
+    symlink problem after .so conversion), and is about twice as fast.
+
+ -- Joey Hess <joeyh@master.debian.org>  Sat, 29 Aug 1998 22:06:06 -0700
+
 debhelper (1.1.12) unstable; urgency=low
 
   * dh_installdocs: forgot to pass package name to isnative(). Any native
index a8fb1e992dfda7eaa80f81644540e690efb5601b..34d332899a548d75c3bfef7b78a2c45d41b3d02b 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/usr/bin/perl -w
 #
 # Automatically find and install man pages. However, do not install any man 
 # pages listed on the command line.
 #
 # This is a little bit (hah!) DWIMish, but still very handy.
 
-PATH=debian:$PATH:/usr/lib/debhelper
-. dh_lib
+BEGIN { push @INC, "debian", "/usr/lib/debhelper" }
+use File::Find;
+use Dh_Lib;
+init();
 
-for PACKAGE in $DH_DOPACKAGES; do
-        TMP=`tmpdir $PACKAGE`
+# Check if a file is a man page, for use by File::Find.
+my @manpages;
+sub find_man {
+       # Does its filename look like a man page?
+       # .ex files are examples installed by deb-make,
+       # we don't want those, or .in files, which are
+       # from configure.
+       if (! (-f $_ && /^.*\.[1-9].*$/ && ! /\.(ex|in)$/)) {
+               return;
+       }
+       # It's not in a tmp directory is it?
+       if ($File::Find::dir=~m:debian/.*tmp.*:) {
+               return;
+       }
+       # And file does think it's a real man page?
+       if (! `file $_`=~/roff/) {
+               return;
+       }
 
-       # Find all filenames that look like man pages.
-       # .ex files are examples installed by deb-make, we don't want those, or
-       # .in files, which are from configure.
-       # We also need to exclude all debian/tmp type dirs.
-       EXCLUDE=`grep ^Package: debian/control | \
-               cut -d " " -f 2 | tr "\n" "|"`
-       for file in `find * -type f -name "*.[1-9]*" ! -name "*.ex" \
-               ! -name "*.in" | egrep -v "^debian/(${EXCLUDE}tmp)/"`
-       do
-               # Make sure file thinks they are man pages.
-               if file -L $file|grep -q roff; then
-                       if echo $file|grep -q /; then
-                               NAME=`expr $file : '.*/\(.*\)'`
-                       else
-                               NAME=$file
-                       fi
-                       # Look at the command line and check if we should
-                       # install the file.
-                       install=1
-                       for notinstall in $@; do
-                               if [ "$NAME" = "$notinstall" -o \
-                                    "$file" = "$notinstall" ]; then
-                                       install=""
-                               fi
-                       done
-                       if [ "$install" ]; then
-                               SECTION=man`expr $NAME : '.*\.\([123456789]\)'`
-                               # Test to see if the filename ends with 'x',
-                               # if so, this is an X man page.
-                               if expr $NAME : '.*\.[123456789]x' >/dev/null; then
-                                       EXTDIR="X11R6"
-                               else
-                                       EXTDIR=""
-                               fi
-                               if [ ! -e $TMP/usr/man/$SECTION/$NAME -a \
-                                    ! -e $TMP/usr/X11*/man/$SECTION/$NAME ]; then
-                                       if [ ! -d $TMP/usr/$EXTDIR/man/$SECTION ]; then
-                                               doit "install -d $TMP/usr/$EXTDIR/man/$SECTION"
-                                       fi
-                                       doit "install -p -m644 $file $TMP/usr/$EXTDIR/man/$SECTION/$NAME"
-                               fi
-                       fi
-               fi
-       done
+       # Good enough.
+       push @manpages,"$File::Find::dir/$_";
+}
+
+# Check if a file is a .so man page, for use by File::Find.
+my @sofiles;
+my @sodests;
+sub find_so_man {
+       # The -s test is becuase a .so file tends to be small. We don't want
+       # to open every man page. 1024 is arbitrary.
+       if (! -f $_ || -s $_ > 1024) {
+               return;
+       }
+
+       # Test first line of file for the .so thing.
+       open (SOTEST,$_);
+       my $l=<SOTEST>;
+       close SOTEST;
+       if ($l=~m/\.so\s+(.*)/) {
+               my $solink=$1;
+               # This test is here to prevent links like ... man8/../man8/foo.8
+               if (Dh_Lib::basename($File::Find::dir) eq Dh_Lib::dirname($solink)) {
+                       $solink=Dh_Lib::basename($solink);
+               }
+               else {
+                       $solink="../$solink";
+               }
+       
+               push @sofiles,"$File::Find::dir/$_";
+               push @sodests,$solink;
+       }
+}
 
+foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
+       $TMP=tmpdir($PACKAGE);
+
+       # Find all filenames that look like man pages.
+       @manpages=();
+       find(\&find_man,'.'); # populates @manpages
+       
+       foreach $page (@manpages) {
+               $page=~s:^\./::; # just for looks
+               
+               $basename=Dh_Lib::basename($page);
+               
+               # Skip all files listed on command line.
+               my $install=1;
+               foreach $skip (@ARGV) {
+                       if ($basename eq $skip) {
+                               $install=undef;
+                               last;
+                       }
+               }
+               
+               if ($install) {
+                       my $extdir="";
+                       # Handle X man pages specially.
+                       if ($basename=~/x$/) {
+                               $extdir="X11R6";
+                       }
+                       
+                       my ($section)=$basename=~m/.*\.([1-9])/;
+                       
+                       my $destdir="$TMP/usr/$extdir/man/man$section/";
+                       $destdir=~tr:/:/:s; # just for looks
+                       if (! -e "$destdir/$basename" && !-l "$destdir/$basename") {
+                               if (! -d $destdir) {
+                                       doit "install","-d",$destdir;
+                               }
+                               doit "install","-p","-m644",$page,$destdir;
+                       }
+               }
+       }
+       
        # Now the .so conversion.
-       for file in `find $TMP/usr/man $TMP/usr/X11*/man -type f -size -256c 2>/dev/null`
-       do
-               solink=`expr "\`head -1 $file\`" : '\.so \(.*\)'`
-               if [ "$solink" ]; then
-                       doit "rm -f $file"
-                       # The .so links include the subdir the page is in, 
-                       # thus the ../
-                       doit "ln -s ../$solink $file"
-               fi
-       done
-done
+       @sofiles=@sodests=();
+       foreach $dir (qw{usr/man usr/X11R6/man}) {
+               if (-e "$TMP/$dir") {
+                       find(\&find_so_man, "$TMP/$dir");
+               }
+       }
+       foreach $sofile (@sofiles) {
+               my $sodest=shift(@sodests);
+               doit "rm","-f",$sofile;
+               doit "ln","-sf",$sodest,$sofile;
+       }
+}
index 9f184e3d690e4c83c72578ffb73ee7a3dab71414..c36b1dc6e738887db4e9d504c67cd6e840102571 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -73,6 +73,5 @@ Fixes to backport to 1.0 tree:
 
 * dh_installdocs used -m 655 for a TODO file. (minor, dh_fixperms cleans up
        after it)
-* dh_fixperms had a problkem with removing x bits on examples files -
+* dh_fixperms had a problem with removing x bits on examples files -
        backport fix.
-