2009-03-28 21:55:28 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Copyright (C) 2006-2009 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/>.
|
|
|
|
|
2009-11-01 16:15:47 +00:00
|
|
|
# DEFAULTS:
|
2009-09-05 19:38:44 +00:00
|
|
|
# name and location of the config file
|
|
|
|
# relative to the top level source directory of the translations
|
|
|
|
# i.e. the directory containing ./po/
|
2009-11-01 16:15:47 +00:00
|
|
|
CONFIG="po4a.config"
|
|
|
|
# PODIR po directory for manpages/docs
|
|
|
|
PODIR="po"
|
2009-09-05 19:38:44 +00:00
|
|
|
# POTFILE path
|
2009-11-01 16:15:47 +00:00
|
|
|
POTFILE=""
|
|
|
|
# base directory for generated files, e.g. doc
|
|
|
|
BASEDIR=""
|
2009-09-05 19:38:44 +00:00
|
|
|
# the binary packages that will contain generated manpages
|
2009-11-01 16:15:47 +00:00
|
|
|
BINARIES=""
|
2009-09-05 19:38:44 +00:00
|
|
|
# the binary packages with manpages in Section 3.
|
2009-11-01 16:15:47 +00:00
|
|
|
HASMAN3=""
|
2009-09-05 19:38:44 +00:00
|
|
|
# the binary packages using DocBook XML & xsltproc
|
2009-11-01 16:15:47 +00:00
|
|
|
XMLPACKAGES=""
|
2009-09-05 19:38:44 +00:00
|
|
|
# the DocBook XML files (TODO: let this take paths)
|
2009-11-01 16:15:47 +00:00
|
|
|
XMLFILE=""
|
|
|
|
# the pattern to find the XML files
|
|
|
|
XMLDIR=""
|
2009-09-15 15:30:59 +00:00
|
|
|
# the pattern to find the .docbook files
|
|
|
|
DOCBOOKDIR=""
|
2009-09-05 19:38:44 +00:00
|
|
|
# the XSL file to use for Docbook XSL
|
|
|
|
XSLFILE="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"
|
|
|
|
# the POD files (TODO: let this take paths)
|
2009-11-01 16:15:47 +00:00
|
|
|
PODFILE=""
|
2009-09-05 19:38:44 +00:00
|
|
|
# the binary packages using POD
|
2009-11-01 16:15:47 +00:00
|
|
|
PODPACKAGES=""
|
|
|
|
# html output (subdirectory of BASEDIR)
|
|
|
|
HTMLDIR=""
|
2009-09-15 15:30:59 +00:00
|
|
|
# html DocBook file
|
2009-11-01 16:15:47 +00:00
|
|
|
HTMLFILE=""
|
|
|
|
# the XSL file to use for Docbook XSL
|
|
|
|
HTMLXSL="http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl"
|
2009-09-05 19:38:44 +00:00
|
|
|
|
|
|
|
# remember to add something to the clean:: rule in debian/rules
|
|
|
|
# to remove each binary package sub-directory.
|
|
|
|
# $(RM) -r doc/emdebian-rootfs doc/multistrap
|
|
|
|
|
|
|
|
# below this point, no changes should be needed.
|
|
|
|
|
2009-11-01 16:15:47 +00:00
|
|
|
# use a default manpages.cnf in the current directory.
|
|
|
|
FILE="manpages.conf"
|
|
|
|
|
2009-03-28 21:55:28 +00:00
|
|
|
wrap_langs () {
|
|
|
|
if [ -z "$LANGS" ]; then
|
|
|
|
echo "$1 $2" >> $CONFIG
|
|
|
|
else
|
|
|
|
echo "$1 $2 $3" >> $CONFIG
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-11-01 16:15:47 +00:00
|
|
|
usagehelp () {
|
|
|
|
# print out help message
|
|
|
|
cat <<EOF
|
|
|
|
genmanpages - po4a frontend
|
|
|
|
|
|
|
|
Syntax: genmanpages
|
|
|
|
genmanpages --pot-only
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
-?|-h|--help|-version: print this help message and exit
|
|
|
|
--pot-only: only create the POT file
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-f|--file FILE: manpages.conf config file path
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case "$1" in
|
|
|
|
--help|-h|-\?|--version)
|
|
|
|
echo usagehelp
|
|
|
|
exit;
|
|
|
|
;;
|
|
|
|
--pot-only)
|
|
|
|
POTONLY=1
|
|
|
|
break;
|
|
|
|
;;
|
|
|
|
-f|--file)
|
|
|
|
shift
|
|
|
|
FILE=$1
|
|
|
|
break;
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognised command: $1"
|
|
|
|
exit;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ! -f "debian/changelog" ]; then
|
|
|
|
echo "genmanpages started from the wrong directory.";
|
|
|
|
exit 2
|
2009-03-28 21:55:28 +00:00
|
|
|
fi
|
2009-11-01 16:15:47 +00:00
|
|
|
|
|
|
|
if [ ! -f "$FILE" ]; then
|
|
|
|
# without config, there's nothing to do.
|
|
|
|
echo "Cannot find config file! '$FILE'";
|
|
|
|
exit 3
|
|
|
|
else
|
|
|
|
. ./$FILE
|
2009-03-28 21:55:28 +00:00
|
|
|
fi
|
2009-09-05 19:38:44 +00:00
|
|
|
|
2009-03-28 21:55:28 +00:00
|
|
|
# calculate the langs, automatically.
|
2009-11-01 16:15:47 +00:00
|
|
|
LANGS=`ls $PODIR/*.po 2>/dev/null || true`
|
2009-03-28 21:55:28 +00:00
|
|
|
if [ ! -z "$LANGS" ]; then
|
2009-11-01 16:15:47 +00:00
|
|
|
LANGS=`ls $PODIR/*.po | sed -e 's/.*\/\(.*\)\.po/\1 /' || true`
|
2009-03-28 21:55:28 +00:00
|
|
|
fi
|
|
|
|
if [ ! -z "$LANGS" ]; then
|
2009-09-15 20:22:08 +00:00
|
|
|
LANGS=`echo $LANGS|tr -d '\n'`
|
2009-03-28 21:55:28 +00:00
|
|
|
echo "[po4a_langs] $LANGS" > $CONFIG
|
|
|
|
else
|
|
|
|
echo > $CONFIG
|
|
|
|
fi
|
2009-11-02 12:00:43 +00:00
|
|
|
wrap_langs "[po4a_paths]" "$POTFILE" "\$lang:$PODIR/\$lang.po"
|
2009-03-28 21:55:28 +00:00
|
|
|
|
2009-09-15 15:30:59 +00:00
|
|
|
for file in $XMLDIR/*.xml; do
|
2009-03-28 21:55:28 +00:00
|
|
|
LOCAL=`basename $file`
|
2009-09-15 15:34:42 +00:00
|
|
|
wrap_langs "[type:docbook]" "$file" "\$lang:$XMLDIR/\$lang/$LOCAL"
|
2009-03-28 21:55:28 +00:00
|
|
|
done
|
2009-09-15 15:30:59 +00:00
|
|
|
for file in $DOCBOOKDIR; do
|
|
|
|
LOCAL=`basename $file`
|
2009-11-01 16:15:47 +00:00
|
|
|
wrap_langs "[type:docbook]" "$file" "\$lang:$BASEDIR/\$lang/$LOCAL"
|
2009-03-28 21:55:28 +00:00
|
|
|
done
|
2009-09-15 15:30:59 +00:00
|
|
|
if [ -n "$PODFILE" ]; then
|
|
|
|
for file in "$PODFILE"; do
|
2009-11-01 16:15:47 +00:00
|
|
|
wrap_langs "[type:pod]" "$file" "\$lang:$BASEDIR/pod/\$lang/$file"
|
2009-09-15 15:30:59 +00:00
|
|
|
done
|
|
|
|
fi
|
2009-03-28 21:55:28 +00:00
|
|
|
|
2009-11-01 16:15:47 +00:00
|
|
|
if [ "$POTONLY" = "1" ]; then
|
|
|
|
po4a --no-translations $CONFIG
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
for d in $BINARIES; do
|
|
|
|
for l in $LANGS; do
|
|
|
|
mkdir -p $BASEDIR/$d/man/$l/man1/
|
|
|
|
if [ "$d" = "$HASMAN3" ]; then
|
|
|
|
mkdir -p $BASEDIR/$d/man/$l/man3/
|
|
|
|
fi
|
2009-11-01 17:01:14 +00:00
|
|
|
mkdir -p $BASEDIR/$d/$l/$HTMLDIR/
|
2009-11-01 16:15:47 +00:00
|
|
|
done
|
|
|
|
mkdir -p $BASEDIR/$d/man/man1/
|
|
|
|
if [ "$d" = "$HASMAN3" ]; then
|
|
|
|
mkdir -p $BASEDIR/$d/man/man3/
|
|
|
|
fi
|
|
|
|
mkdir -p $BASEDIR/pod/$l/
|
|
|
|
done
|
|
|
|
|
2009-03-28 21:55:28 +00:00
|
|
|
# use -k to create all XML even if untranslated or the XSL breaks the build.
|
|
|
|
po4a -k 0 $CONFIG
|
|
|
|
|
2009-09-05 19:38:44 +00:00
|
|
|
for d in $BINARIES; do
|
|
|
|
for P in $XMLPACKAGES; do
|
2009-11-01 17:01:14 +00:00
|
|
|
if [ $d = $P ]; then
|
|
|
|
for X in $XMLFILE; do
|
|
|
|
echo "Processing untranslated files for $d . . ."
|
|
|
|
XML_CATALOG_FILES="/etc/xml/catalog" \
|
|
|
|
xsltproc -o $BASEDIR/$P/man/ --nonet $XSLFILE $XMLDIR/$X
|
|
|
|
if [ "$d" = "$HASMAN3" ]; then
|
|
|
|
mv $BASEDIR/$P/man/*.3 $BASEDIR/$P/man/man3/
|
|
|
|
else
|
|
|
|
rm -f $BASEDIR/$P/man/*.3
|
|
|
|
fi
|
|
|
|
mv $BASEDIR/$P/man/*.1 $BASEDIR/$P/man/man1/
|
|
|
|
done
|
2009-09-05 19:38:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
for POD in $PODPACKAGES; do
|
2009-11-01 17:01:14 +00:00
|
|
|
if [ $d = "$POD" ]; then
|
|
|
|
echo "Processing untranslated files for $POD . . ."
|
|
|
|
pod2man $PODFILE > $BASEDIR/$POD/man/man1/$PODFILE.1
|
|
|
|
fi
|
2009-09-05 19:38:44 +00:00
|
|
|
done
|
2009-11-01 17:01:14 +00:00
|
|
|
if [ -n "$HTMLDIR" ]; then
|
|
|
|
xsltproc -o $BASEDIR/$d/$HTMLDIR/ --nonet $HTMLXSL $XMLDIR/$HTMLFILE
|
|
|
|
fi
|
2009-09-05 19:38:44 +00:00
|
|
|
for l in $LANGS; do
|
|
|
|
for P in $XMLPACKAGES; do
|
2009-11-01 17:01:14 +00:00
|
|
|
if [ $d = "$P" ]; then
|
|
|
|
echo "Processing $l translations for $d . . ."
|
|
|
|
for X in $XMLFILE; do
|
|
|
|
XML_CATALOG_FILES="/etc/xml/catalog" \
|
|
|
|
xsltproc -o $BASEDIR/$P/man/ --nonet $XSLFILE $XMLDIR/$l/$X
|
|
|
|
done
|
|
|
|
if [ "$d" = "$HASMAN3" ]; then
|
|
|
|
mv $BASEDIR/$P/man/*.3 $BASEDIR/$P/man/$l/man3/
|
|
|
|
else
|
|
|
|
rm -f $BASEDIR/$P/man/*.3
|
|
|
|
fi
|
|
|
|
mv $BASEDIR/$P/man/*.1 $BASEDIR/$P/man/$l/man1/
|
2009-09-05 19:38:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
for POD in $PODPACKAGES; do
|
2009-11-01 17:01:14 +00:00
|
|
|
if [ $d = "$POD" ]; then
|
|
|
|
echo "Processing $l translations for $POD . . ."
|
|
|
|
echo "pod2man $BASEDIR/pod/$l/$PODFILE > $BASEDIR/$POD/man/$l/man1/$PODFILE.1"
|
|
|
|
pod2man $BASEDIR/pod/$l/$PODFILE > $BASEDIR/$POD/man/$l/man1/$PODFILE.1
|
|
|
|
fi
|
2009-09-05 19:38:44 +00:00
|
|
|
done
|
2009-11-01 17:01:14 +00:00
|
|
|
if [ -n "$HTMLDIR" ]; then
|
|
|
|
mkdir -p $BASEDIR/$d/$HTMLDIR/$l/
|
|
|
|
xsltproc -o $BASEDIR/$d/$HTMLDIR/$l/ --nonet $HTMLXSL $XMLDIR/$l/$HTMLFILE
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "$HTMLDIR" ]; then
|
|
|
|
for i in `ls $BASEDIR/$d/$HTMLDIR/*.html`; do
|
|
|
|
iconv -t utf-8 -f iso8859-1 $i > $BASEDIR/$HTMLDIR/tmp
|
|
|
|
sed < $BASEDIR/$HTMLDIR/tmp > $i -e 's:charset=ISO-8859-1:charset=UTF-8:'
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [ -n "$HTMLDIR" ]; then
|
|
|
|
rm -f $BASEDIR/$HTMLDIR/tmp
|
|
|
|
fi
|
2009-09-05 19:38:44 +00:00
|
|
|
done
|
2009-09-15 15:30:59 +00:00
|
|
|
|
2009-03-28 21:55:28 +00:00
|
|
|
for l in $LANGS; do
|
2009-09-15 15:30:59 +00:00
|
|
|
rm -rf $XMLDIR/$l
|
2009-03-28 21:55:28 +00:00
|
|
|
done
|
2009-11-01 16:15:47 +00:00
|
|
|
rm -rf $BASEDIR/pod/
|