]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmanpages
r74: Initial Import
[debhelper.git] / dh_installmanpages
1 #!/bin/sh -e
2 #
3 # Automatically find and install man pages. However, do not install any man 
4 # pages listed on the command line.
5 # Also change man pages with .so commands in them into symlinks.
6 #
7 # This is a little bit (hah!) DWIMish, but still very handy.
8
9 PATH=debian:$PATH:/usr/lib/debhelper
10 . dh_lib
11
12 for PACKAGE in $DH_DOPACKAGES; do
13         TMP=`tmpdir $PACKAGE`
14
15         # Find all filenames that look like man pages.
16         # .ex files are examples installed by deb-make, we don't want those, or
17         # .in files, which are from configure.
18         # We also need to exclude all debian/tmp type dirs.
19         EXCLUDE=`grep ^Package: debian/control | \
20                 cut -d " " -f 2 | tr "\n" "|"`
21         for file in `find * -type f -name "*.[1-9]*" ! -name "*.ex" \
22                 ! -name "*.in" | egrep -v "^debian/(${EXCLUDE}tmp)/"`
23         do
24                 # Make sure file thinks they are man pages.
25                 if file -L $file|grep -q roff; then
26                         if echo $file|grep -q /; then
27                                 NAME=`expr $file : '.*/\(.*\)'`
28                         else
29                                 NAME=$file
30                         fi
31                         # Look at the command line and check if we should
32                         # install the file.
33                         install=1
34                         for notinstall in $@; do
35                                 if [ "$NAME" = "$notinstall" -o \
36                                      "$file" = "$notinstall" ]; then
37                                         install=""
38                                 fi
39                         done
40                         if [ "$install" ]; then
41                                 SECTION=man`expr $NAME : '.*\.\([123456789]\)'`
42                                 # Test to see if the filename ends with 'x',
43                                 # if so, this is an X man page.
44                                 if expr $NAME : '.*\.[123456789]x' >/dev/null; then
45                                         EXTDIR="X11R6"
46                                 else
47                                         EXTDIR=""
48                                 fi
49                                 if [ ! -e $TMP/usr/man/$SECTION/$NAME -a \
50                                      ! -e $TMP/usr/X11*/man/$SECTION/$NAME ]; then
51                                         if [ ! -d $TMP/usr/$EXTDIR/man/$SECTION ]; then
52                                                 doit "install -d $TMP/usr/$EXTDIR/man/$SECTION"
53                                         fi
54                                         doit "install -p -m644 $file $TMP/usr/$EXTDIR/man/$SECTION/$NAME"
55                                 fi
56                         fi
57                 fi
58         done
59
60         # Now the .so conversion.
61         for file in `find $TMP/usr/man $TMP/usr/X11*/man -type f -size -256c 2>/dev/null`
62         do
63                 solink=`expr "\`head -1 $file\`" : '\.so \(.*\)'`
64                 if [ "$solink" ]; then
65                         doit "rm -f $file"
66                         # The .so links include the subdir the page is in, 
67                         # thus the ../
68                         doit "ln -s ../$solink $file"
69                 fi
70         done
71 done