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

VERSION=`dpkg-parsechangelog | awk '/^Version:/ {print $2}' | sed -e 's/^[0-9]*://' -e 's/-.*//' -e 's/[+~]dfsg$//'`
NAME=`grep "^Description:" debian/control | sed 's/^Description: *//' | head -n1`
PROGNAME=`grep "^Package:" debian/control | sed 's/^Package: *//' | head -n1`

AUTHOR=".SH AUTHOR\n \
This manpage was written by $DEBFULLNAME for the Debian distribution and\n \
can be used for any other usage of the program.\
"

# If program name is different from package name or title should be
# different from package short description change this here
progname=bed2bed_display
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="Convert BED file to BED format suitable for displaying ChIP-seq peaks." \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=bed2sga
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="Convert BED format into SGA format." \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

# Provided upstream:
#  chipcenter
#  chipcor
#  chipextract
#  chippart
#  chippeak
#  chipscore

progname=compactsga
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="reads a ChIP-seq data file and merges equal tag positions into a single line" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=countsga
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="read a ChIP-seq data file and computes the total number of tag counts" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=featreplace
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="read a ChIP-seq data file and changes the name of the feature field" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=filter_counts
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="read a ChIP-seq data file and filters out all read counts" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=fps2sga.pl
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="convert fps to sga" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=gff2sga.pl
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="convert gff to sga" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=partit2bed.pl
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="converts the output of the ChIP-Seq partitioning program to BED format" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=sga2bed
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="Convert SGA format into BED format" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=sga2fps.pl
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="Convert SGA format into FPS format" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=sga2gff.pl
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="Convert SGA format into GFF format" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

progname=sga2wig
help2man --no-info --no-discard-stderr --help-option=" -h" \
         --name="Convert SGA format into Wiggle Track format" \
            --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
echo $AUTHOR >> $MANDIR/${progname}.1

echo "*1.gz" > debian/${PROGNAME}.manpages
echo "$MANDIR/*.1" >> debian/${PROGNAME}.manpages

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