#!/bin/sh
MANDIR=debian
mkdir -p $MANDIR

VERSION=`dpkg-parsechangelog | awk '/^Version:/ {print $2}' | sed -e 's/^[0-9]*://' -e 's/-.*//' -e 's/[+~]dfsg$//'`

for bin in fastml gainLoss indelCoder ; do
  echo "cat debian/${bin}.out" > debian/${bin}.sh
  chmod 755 debian/${bin}.sh
  ${bin} 2>&1 | tee | \
    sed -e 's/^ *+--\++ *//' -e 's/|\(.*[^ ]\) *|/\1/' | \
    grep -v -- '-------- HELP: ----------' \
   > debian/${bin}.out
done

help2man --no-info --no-discard-stderr --help-option=" " \
         --name='maximum likelihood ancestral amino-acid sequence reconstruction' \
            --version-string="$VERSION" debian/fastml.sh > $MANDIR/fastml.1

help2man --no-info --no-discard-stderr --help-option=" " \
         --name='Analysis of Phyletic Patterns in a Likelihood Framework' \
            --version-string="$VERSION" debian/gainLoss.sh > $MANDIR/gainLoss.1

help2man --no-info --no-discard-stderr --help-option=" " \
         --name='FastML indelCoder' \
            --version-string="$VERSION" debian/indelCoder.sh > $MANDIR/indelCoder.1

cat <<EOT
Please enhance the help2man output.
The following web page might be helpful in doing so:
    http://liw.fi/manpages/
EOT

rm debian/*.out debian/*.sh
