#!/bin/bash
#
# mkpod
# Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
# 
#
# simple script to generate man pages from pod sources
# TODO: process version parameter.... need to be able to pass one in.
#
usage='mkpod <input-file>, input file should be a pod file.'

infile=$1
if [[ -z $infile ]]
then
	echo $usage
fi

# Check if SVN is available.  If not, then abort.
which svn >/dev/null 2>&1
if [ $? != 0 ] ; then
  echo "No SubVersion available."
  exit 1
fi
which svnversion >/dev/null 2>&1
if [ $? != 0 ] ; then
  echo "No svnversion available."
  exit 1
fi

name=${infile%.pod}
# Man format (*roff)
#version is the svn version use svn info to get it, can only specify
# release in the pod2man translator.
version="`svn info | grep '^Revision:' | awk '{print $2}'`"
#echo "\$version is:$version"
if [ "$version" == "" ]
then
	echo "Setting version to 1.x(unknown)"
	version='1.x(unknown)'
fi
pod2man --center="$name" --release="Version: $version" "$infile" > "$name.1"

# HTML
pod2html --infile=$infile --outfile=$name.html

#Text
pod2text $infile $name.txt

