#!/bin/sh
set -e

#  Copyright (C) 2006-2008  Neil Williams <codehelp@debian.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  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, see <http://www.gnu.org/licenses/>.

if [ -d "./doc/" ]; then
	cd doc/
fi
for file in `ls xml/*.xml`; do
	xmllint --format "$file" --output "$file"
	LIST="${LIST} $file"
done
xml2po -o ../po/xml.pot $LIST
LIST=
for file in emdebcheck emtargetcmp emprunecross Emdebian/Tools.pm em_installtdeb emrecent; do
	if [ "$file" = "Emdebian/Tools.pm" ]; then
		pod2html -outfile html/EmdebianTools.html -title $file < ../$file
	else
		pod2html -outfile html/$file.html -title $file < ../$file
	fi
	if [ "$file" = "Emdebian/Tools.pm" ]; then
		pod2man ../$file > man/Emdebian::Tools.3
	else
		pod2man ../$file > man/$file.1
	fi
	LIST="${LIST} -m ../$file"
done

po4a-gettextize -f pod $LIST -M UTF-8 -p ../po/perl.pot
msgcat -o ../po/emdebian-tools.pot ../po/xml.pot ../po/perl.pot
rm ../po/xml.pot ../po/perl.pot
rm -f pod2htmd.tmp pod2htmi.tmp

# just make sure the XML catalog is available for XSL.
XML_CATALOG_FILES="/etc/xml/catalog" \
xsltproc -o man/ -''-nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl xml/emdebian-tools.1.xml
xsltproc -o html/ -nonet http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl xml/emdebian-tools.1.xml
for i in `ls ./html/*.html`; do iconv -t utf-8 -f iso8859-1 $i > html/tmp;
   sed < html/tmp > $i -e 's:charset=ISO-8859-1:charset=UTF-8:'; done;
rm -f html/tmp
