rpm-build/scripts/find-lang
2003-11-09 16:08:49 +00:00

188 lines
4.1 KiB
Bash
Executable File

#!/bin/sh -e
#
# find-lang - generate list of language specific files.
# Inspired by tool with same name from W. L. Estes <wlestes@uncg.edu>.
#
# $Id$
# Copyright (C) 2000,2003 Dmitry V. Levin <ldv@altlinux.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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
PROG="${0##*/}"
Fatal()
{
echo "${0##*/}: $*" >&2
exit 1
}
Usage()
{
[ "$1" = 0 ] || exec >&2
cat <<EOF
find-lang - generate list of language specific files for inclusion
in an rpm spec %files section.
find-lang is free software, covered by the GNU General Public License.
find-lang comes with ABSOLUTELY NO WARRANTY, see license for details.
Usage: $PROG options PACKAGE_NAME
Valid options are:
--without-mo do not look for locales files;
--with-man look for man pages;
--with-gnome look for GNOME help and omf files;
--append do not truncate output file before writing;
--output=FILENAME filename where to write output, by default PACKAGE_NAME.lang;
--topdir=TOPDIR the top of the tree containing the files to be processed,
by default \$RPM_BUILD_ROOT.
Top directory gets sed'd out of the output list.
PACKAGE_NAME is usually the %{name} of the package. This should also be
the basename of the .mo files.
EOF
[ -n "$1" ] && exit "$1" || exit
}
TEMP=`getopt -n "$PROG" -o h -l without-mo,with-man,with-gnome,append,output:,topdir: -- "$@"` || Usage
eval set -- "$TEMP"
: ${TOPDIR:=$RPM_BUILD_ROOT}
FIND_MO=1
FIND_MAN=
FIND_GNOME=
APPEND=
OUTPUT=
NAME=
while :; do
case "$1" in
--without-mo)
FIND_MO=
shift
;;
--with-man)
FIND_MAN=1
shift
;;
--with-gnome)
FIND_GNOME=1
shift
;;
--append)
APPEND=1
shift
;;
--output)
shift
OUTPUT="$1"
shift
;;
--topdir)
shift
TOPDIR="$1"
shift
;;
-h|--help)
Usage 0
;;
--)
shift
break
;;
*)
Fatal "unrecognized option: $1"
;;
esac
done
# At least one argument, please.
[ "$#" -ge 1 ] || Usage
cd "$TOPDIR"
cd "$OLDPWD"
TOPDIR="$(printf %s "$TOPDIR" |sed '
s:/\(\./\)\+:/:g
s:/\+:/:g
s:/$::
')"
[ -n "$TOPDIR" ] || Fatal "invalid TOPDIR"
FindLang()
{
# truncate if required
[ -n "$APPEND" ] || :>"$OUTFILE"
echo '%defattr(644,root,root,755)' >>"$OUTFILE"
if [ -n "$FIND_MO" ]; then
find "$TOPDIR" -type f |sed '
s:'"$TOPDIR"'::
s:\(.*/share/locale/\)\([^/_]\+\)\(.*'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
s:^\([^%].*\)::
' |grep -v '^$' >> "$OUTFILE" ||:
fi
if [ -n "$FIND_MAN" ]; then
find "$TOPDIR" -type f |sed '
s:'"$TOPDIR"'::
s:\(.*/share/man/\)\([^/_]\+\)\(.*'"$NAME"'\..\)\(\.[^/]*\)\?$:%lang(\2) \1\2\3*:
s:^\([^%].*\)::
s:^%lang(man.*) .*::
' |grep -v '^$' >> "$OUTFILE" ||:
fi
if [ -n "$FIND_GNOME" ]; then
find $TOPDIR -type d |sed '
s:'"$TOPDIR"'::
s:\(.*/gnome/help/'"$NAME"'\)$:%dir \1:
s:\(.*/gnome/help/'"$NAME"'/\)\([^/_]\+\):%dir %lang(\2) \1\2:
s:^\([^%].*\)::
s:%lang(C) ::
' |grep -v '^$' >> "$OUTFILE" ||:
find "$TOPDIR" -type f |sed '
s:'"$TOPDIR"'::
s:\(.*/gnome/help/'"$NAME"'/\)\([^/_]\+\):%lang(\2) \1\2:
s:^\([^%].*\)::
s:%lang(C) ::
' |grep -v '^$' >> "$OUTFILE" ||:
find $TOPDIR -type d |sed '
s:'"$TOPDIR"'::
s:\(.*/share/omf/'"$NAME"'\)$:%dir \1:
s:^\([^%].*\)::
' |grep -v '^$' >> "$OUTFILE" ||:
find "$TOPDIR" -type f |sed '
s:'"$TOPDIR"'::
s:\(.*/share/omf/'"$NAME"'/\)\([^/]*-\)\(.*\)\(\.omf\)$:%lang(\3) \1\2\3\4:
s:^\([^%].*\)::
s:%lang(C) ::
' |grep -v '^$' >> "$OUTFILE" ||:
fi
}
for NAME in "$@"; do
if [ -n "$OUTPUT" ]; then
OUTFILE="$OUTPUT"
[ "$NAME" = "$1" ] || APPEND=1
else
OUTFILE="$NAME.lang"
fi
FindLang
done