#!/bin/sh
#
# Install tclx man pages in debian build directory.

DESTDIR=${1:-./debian/tmp}
MAN3DIR=${DESTDIR}/usr/share/man/man3
MANNDIR=${DESTDIR}/usr/share/man/mann

mkdir -p ${MAN3DIR}

# Move manpages from mann to man3
for f in ${MANNDIR}/*; do
    test -e "$f" || continue
    name=${f##*/}; name=${name%.n}.3tcl
    # Replace section TCL with 3tcl
    #mv -f $f ${MAN3DIR}/$name
    cat $f | sed '/^\.TH/ s/TCL/3tcl/' > ${MAN3DIR}/$name; rm $f
    gzip -f9 ${MAN3DIR}/$name
done

# Install manpages in man3
for f in doc/*.3; do
    test -e "$f" || continue
    name=${f##*/}tcl
    names=$(cat $f | sed '1,/\.SH NAME/d; s/.-.*//g; s/,//g; q')
    # Replace section TCL with 3tcl
    #cp -fp $f ${MAN3DIR}/$name
    cat $f | sed '/^\.TH/ s/TCL/3tcl/' > ${MAN3DIR}/$name
    gzip -f9 ${MAN3DIR}/$name
    for n in $names; do
	test -e ${MAN3DIR}/$n.3tcl.gz && continue
	ln -nfs $name.gz ${MAN3DIR}/$n.3tcl.gz
    done
done

# end of file
