2002-03-25 23:37:46 +03:00
#!/bin/sh -e
#
# find-lang - generate list of language specific files.
# Inspired by tool with same name from W. L. Estes <wlestes@uncg.edu>.
#
2013-03-12 03:15:51 +04:00
# Copyright (C) 2000-2013 Dmitry V. Levin <ldv@altlinux.org>
2002-03-25 23:37:46 +03:00
#
2012-05-24 17:44:54 +04:00
# 2012-05-23 Igor Vlasenko <viy@altlinux.org>
# * added PLD/fedora compatible all-name option (mkochano,pascalek@PLD)
#
2002-03-25 23:37:46 +03:00
# 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
2013-03-12 03:15:51 +04:00
# along with this program; if not, see <http://www.gnu.org/licenses/>.
2002-03-25 23:37:46 +03:00
#
2003-11-09 20:42:53 +03:00
: ${RPMCONFIGDIR:=@RPMCONFIGDIR@}
. "$RPMCONFIGDIR/functions"
2011-10-07 00:38:04 +04:00
[ -n "${RPM_DATADIR-}" ] || RPM_DATADIR="$(rpm --eval %_datadir)"
2003-11-09 19:08:49 +03:00
2003-11-07 22:34:00 +03:00
Usage()
2002-03-25 23:37:46 +03:00
{
2003-11-09 19:08:49 +03:00
[ "$1" = 0 ] || exec >&2
2002-03-25 23:37:46 +03:00
cat <<EOF
2004-06-29 19:27:48 +04:00
find-lang - generate list of language specific files for inclusion in an rpm spec %files section.
2002-03-25 23:37:46 +03:00
2008-08-29 16:40:37 +04:00
Usage: $PROG options PACKAGE_NAME...
2002-03-25 23:37:46 +03:00
2004-06-29 19:27:48 +04:00
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.
2002-03-25 23:37:46 +03:00
Valid options are:
2004-06-29 19:27:48 +04:00
--without-mo do not look for locales files;
--with-man look for man pages;
--with-gnome look for GNOME help and omf files;
--with-kde look for KDE help files;
2013-03-08 21:07:49 +04:00
--with-qt look for QT translation files;
2012-05-24 17:44:54 +04:00
--all-name match all package/domain names;
2004-06-29 19:27:48 +04:00
--custom-dir-script=FILE look for directories using specified sed script;
--custom-file-script=FILE look for files using specified sed script;
--custom-link-script=FILE look for symlinks using specified sed script;
--append do not truncate output file before writing;
--output=FILENAME filename where to write output,
PACKAGE_NAME.lang by default;
--topdir=TOPDIR the top of the tree containing the files to be
processed, \$RPM_BUILD_ROOT by default;
--version print program version and exit;
--help show this text and exit.
Report bugs to http://bugs.altlinux.ru/
2002-03-25 23:37:46 +03:00
EOF
[ -n "$1" ] && exit "$1" || exit
}
2004-06-29 19:27:48 +04:00
print_version()
{
2004-07-11 21:15:40 +04:00
local revision=`printf %s '$Revision$' |sed -ne 's/^\$Revision: \+\([^ ]\+\).*/\1/p'` ||:
2004-06-29 19:27:48 +04:00
cat <<EOF
find-lang version $revision
2013-03-12 03:15:51 +04:00
Copyright (C) 2000-2013 Dmitry V. Levin <ldv@altlinux.org>
2004-06-29 19:27:48 +04:00
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Dmitry V. Levin <ldv@altlinux.org>
EOF
exit 0
}
2013-03-10 04:04:56 +04:00
TEMP=`getopt -n "$PROG" -o h -l without-mo,with-man,with-gnome,with-kde,with-qt,all-name,custom-dir-script:,custom-file-script:,custom-link-script:,append,output:,topdir:,help,version -- "$@"` || Usage
2002-03-25 23:37:46 +03:00
eval set -- "$TEMP"
: ${TOPDIR:=$RPM_BUILD_ROOT}
FIND_MO=1
FIND_MAN=
FIND_GNOME=
2004-01-04 16:06:40 +03:00
FIND_KDE=
2013-03-08 21:07:49 +04:00
FIND_QT=
2012-05-24 17:44:54 +04:00
ALL_NAME=
2004-06-29 19:27:48 +04:00
CUSTOM_DIR_SCRIPT=
CUSTOM_FILE_SCRIPT=
CUSTOM_LINK_SCRIPT=
2002-03-25 23:37:46 +03:00
APPEND=
OUTPUT=
NAME=
while :; do
case "$1" in
--without-mo)
FIND_MO=
;;
--with-man)
FIND_MAN=1
;;
--with-gnome)
FIND_GNOME=1
;;
2004-01-04 16:06:40 +03:00
--with-kde)
FIND_KDE=1
;;
2013-03-08 21:07:49 +04:00
--with-qt)
FIND_QT=1
;;
2002-03-25 23:37:46 +03:00
--append)
APPEND=1
2004-06-29 19:27:48 +04:00
;;
2012-05-24 17:44:54 +04:00
--all-name)
ALL_NAME=1
;;
2004-06-29 19:27:48 +04:00
--custom-dir-script)
shift
CUSTOM_DIR_SCRIPT="$1"
;;
--custom-file-script)
2002-03-25 23:37:46 +03:00
shift
2004-06-29 19:27:48 +04:00
CUSTOM_FILE_SCRIPT="$1"
;;
--custom-link-script)
shift
CUSTOM_LINK_SCRIPT="$1"
2002-03-25 23:37:46 +03:00
;;
--output)
shift
OUTPUT="$1"
;;
--topdir)
shift
TOPDIR="$1"
;;
-h|--help)
2003-11-07 22:34:00 +03:00
Usage 0
2002-03-25 23:37:46 +03:00
;;
2004-06-29 19:27:48 +04:00
--version) print_version
;;
2002-03-25 23:37:46 +03:00
--)
shift
break
;;
*)
2003-11-09 19:08:49 +03:00
Fatal "unrecognized option: $1"
2002-03-25 23:37:46 +03:00
;;
esac
2004-06-29 19:27:48 +04:00
shift
2002-03-25 23:37:46 +03:00
done
2003-11-07 22:34:00 +03:00
# At least one argument, please.
[ "$#" -ge 1 ] || Usage
2002-03-25 23:37:46 +03:00
cd "$TOPDIR"
cd "$OLDPWD"
2004-06-29 19:27:48 +04:00
TOPDIR="$(printf %s "$TOPDIR" |sed -e '
2002-03-25 23:37:46 +03:00
s:/\(\./\)\+:/:g
s:/\+:/:g
s:/$::
')"
2003-11-09 19:08:49 +03:00
[ -n "$TOPDIR" ] || Fatal "invalid TOPDIR"
2002-03-25 23:37:46 +03:00
FindLang()
{
2013-03-10 04:21:00 +04:00
local RLOCALE='\([a-z]\{2,3\}\)\(_[A-Z]\{2\}\)\?\(@[a-z]\{3,\}\)\?\(\.[A-Z][a-zA-Z0-9]\+\(-[A-Z0-9]\)\?\)\?'
2013-03-12 02:38:28 +04:00
local RCLOCALE='\(C\|[a-z]\{2,3\}\)\(_[A-Z]\{2\}\)\?\(@[a-z]\{3,\}\)\?\(\.[A-Z][a-zA-Z0-9]\+\(-[A-Z0-9]\)\?\)\?'
2013-03-10 04:21:00 +04:00
2012-05-24 17:44:54 +04:00
if [ -n "$ALL_NAME" ]; then
2013-03-10 04:21:00 +04:00
PATTERN='[a-zA-Z0-9][a-zA-Z0-9._+-]*'
2012-05-24 17:44:54 +04:00
else
PATTERN="$NAME"
fi
2002-03-25 23:37:46 +03:00
# truncate if required
[ -n "$APPEND" ] || :>"$OUTFILE"
echo '%defattr(644,root,root,755)' >>"$OUTFILE"
if [ -n "$FIND_MO" ]; then
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type f |sed -e '
2002-03-25 23:37:46 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-10 04:21:00 +04:00
s:\(.*/locale/'"$RLOCALE"'/\([^/]\+/\)*'"$PATTERN"'\.mo\)$:%lang(\2) \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type l |sed -e '
2004-02-25 01:30:18 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-10 04:21:00 +04:00
s:\(.*/locale/'"$RLOCALE"'/\([^/]\+/\)*'"$PATTERN"'\.mo\)$:%lang(\2) %attr(-,root,root) \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2013-03-08 19:05:35 +04:00
fi >> "$OUTFILE"
2002-03-25 23:37:46 +03:00
if [ -n "$FIND_MAN" ]; then
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type f |sed -e '
2002-03-25 23:37:46 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 01:49:30 +04:00
s:\(.*/share/man/'"$RLOCALE"'/[^/]\+/'"$PATTERN"'\.[0-9a-z]\+\)\(\.[^/]\+\)\?$:%lang(\2) \1*:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2004-10-31 15:00:06 +03:00
find "$TOPDIR" -type l |sed -e '
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 01:49:30 +04:00
s:\(.*/share/man/'"$RLOCALE"'/[^/]\+/'"$PATTERN"'\.[0-9a-z]\+\)\(\.[^/]\+\)\?$:%lang(\2) %attr(-,root,root) \1*:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2013-03-08 19:05:35 +04:00
fi >> "$OUTFILE"
2002-03-25 23:37:46 +03:00
if [ -n "$FIND_GNOME" ]; then
2011-10-07 00:38:04 +04:00
# GNOME starting with version 3.2 stores its help files in $RPM_DATADIR/help/%lang/$NAME
2004-06-29 19:27:48 +04:00
find $TOPDIR -type d |sed -e '
2002-03-25 23:37:46 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 02:38:28 +04:00
s:^\('"$RPM_DATADIR"'/help/'"$RCLOCALE"'/'"$PATTERN"'\(/.*\)\?\)$:%lang(\2) %dir \1:
2012-05-24 17:44:54 +04:00
s:\(.*/gnome/help/'"$PATTERN"'\)$:%dir \1:
2013-03-12 03:13:27 +04:00
s:\(.*/gnome/help/'"$PATTERN"'/'"$RCLOCALE"'\(/.*\)\?\)$:%lang(\2) %dir \1:
2012-05-24 17:44:54 +04:00
s:\(.*/share/omf/'"$PATTERN"'\)$:%dir \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(\(en\|C\)) ::
/^$/d
'
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type f |sed -e '
2002-03-25 23:37:46 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 02:38:28 +04:00
s:^\('"$RPM_DATADIR"'/help/'"$RCLOCALE"'/'"$PATTERN"'/\):%lang(\2) \1:
s:\(.*/gnome/help/'"$PATTERN"'/'"$RCLOCALE"'\(/.*\)\?\)$:%lang(\2) \1:
s:\(.*/share/omf/'"$PATTERN"'/[^/]*-'"$RCLOCALE"'\.omf\)$:%lang(\2) \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(\(en\|C\)) ::
/^$/d
'
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type l |sed -e '
2003-02-01 21:39:30 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 02:38:28 +04:00
s:^\('"$RPM_DATADIR"'/help/'"$RCLOCALE"'/'"$PATTERN"'/\):%lang(\2) %attr(-,root,root) \1:
s:\(.*/gnome/help/'"$PATTERN"'/'"$RCLOCALE"'\(/.*\)\?\)$:%lang(\2) %attr(-,root,root) \1:
s:\(.*/share/omf/'"$PATTERN"'/[^/]*-'"$RCLOCALE"'\.omf\)$:%lang(\2) %attr(-,root,root) \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(\(en\|C\)) ::
/^$/d
'
2013-03-08 19:05:35 +04:00
fi >> "$OUTFILE"
2002-03-25 23:37:46 +03:00
2004-01-04 16:06:40 +03:00
if [ -n "$FIND_KDE" ]; then
2004-06-29 19:27:48 +04:00
find $TOPDIR -type d |sed -e '
2004-01-04 16:06:40 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 02:50:38 +04:00
s:\(.*/share/\([^/]\+/\)\?doc/HTML/'"$RLOCALE"'/'"$PATTERN"'\(/.*\)\?\)$:%lang(\3) %dir \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type f |sed -e '
2004-01-04 16:06:40 +03:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 02:50:38 +04:00
s:\(.*/share/\([^/]\+/\)\?doc/HTML/'"$RLOCALE"'/'"$PATTERN"'/\):%lang(\3) \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type l |sed -e '
2004-05-17 19:23:20 +04:00
s:'"$TOPDIR"'::
2013-03-08 19:05:35 +04:00
s:^[^/].*::
2013-03-12 02:50:38 +04:00
s:\(.*/share/\([^/]\+/\)\?doc/HTML/'"$RLOCALE"'/'"$PATTERN"'/\):%lang(\3) %attr(-,root,root) \1:
2013-03-08 19:05:35 +04:00
s:^[^%].*::
2013-03-12 03:13:27 +04:00
s:^%lang(en) ::
/^$/d
'
2013-03-08 19:05:35 +04:00
fi >> "$OUTFILE"
2004-06-29 19:27:48 +04:00
2013-03-08 21:07:49 +04:00
if [ -n "$FIND_QT" ]; then
find "$TOPDIR" -type f |sed -e '
s:'"$TOPDIR"'::
s:^[^/].*::
2013-03-12 03:04:17 +04:00
s:^\(/.*/'"$PATTERN"'/.\+/'"$RLOCALE"'/[a-z][a-z0-9]*\.qm\)$:%lang(\2) \1:
s:^\(/.*/'"$PATTERN"'[_./-]'"$RLOCALE"'\.qm\)$:%lang(\2) \1:
s:^\(/.*/'"$PATTERN"'/.\+/\([a-zA-Z0-9][a-zA-Z0-9._+-]*[_.-]\)\?'"$RLOCALE"'\.qm\)$:%lang(\3) \1:
2013-03-08 21:07:49 +04:00
s:^[^%].*::
s:^%lang(en) ::
2013-03-12 03:13:27 +04:00
/^$/d
'
2013-03-08 21:07:49 +04:00
find "$TOPDIR" -type l |sed -e '
s:'"$TOPDIR"'::
s:^[^/].*::
2013-03-12 03:04:17 +04:00
s:^\(/.*/'"$PATTERN"'/.\+/'"$RLOCALE"'/[a-z][a-z0-9]*\.qm\)$:%lang(\2) %attr(-,root,root) \1:
s:^\(/.*/'"$PATTERN"'[_./-]'"$RLOCALE"'\.qm\)$:%lang(\2) %attr(-,root,root) \1:
s:^\(/.*/'"$PATTERN"'/.\+/\([a-zA-Z0-9][a-zA-Z0-9._+-]*[_.-]\)\?'"$RLOCALE"'\.qm\)$:%lang(\3) %attr(-,root,root) \1:
2013-03-08 21:07:49 +04:00
s:^[^%].*::
s:^%lang(en) ::
2013-03-12 03:13:27 +04:00
/^$/d
'
2013-03-08 21:07:49 +04:00
fi >> "$OUTFILE"
2004-06-29 19:27:48 +04:00
if [ -n "$CUSTOM_DIR_SCRIPT" ]; then
2004-11-01 14:40:25 +03:00
[ -r "$CUSTOM_DIR_SCRIPT" ] && custom_opt=f || custom_opt=e
2004-06-29 19:27:48 +04:00
find $TOPDIR -type d |
2004-11-01 12:47:06 +03:00
sed -e "s:$TOPDIR::" -$custom_opt "$CUSTOM_DIR_SCRIPT" |
2004-06-29 19:27:48 +04:00
grep -v '^$' >> "$OUTFILE" ||:
fi
if [ -n "$CUSTOM_FILE_SCRIPT" ]; then
2004-11-01 14:40:25 +03:00
[ -r "$CUSTOM_FILE_SCRIPT" ] && custom_opt=f || custom_opt=e
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type f |
2004-11-01 12:47:06 +03:00
sed -e "s:$TOPDIR::" -$custom_opt "$CUSTOM_FILE_SCRIPT" |
2004-06-29 19:27:48 +04:00
grep -v '^$' >> "$OUTFILE" ||:
fi
if [ -n "$CUSTOM_LINK_SCRIPT" ]; then
2004-11-01 14:40:25 +03:00
[ -r "$CUSTOM_LINK_SCRIPT" ] && custom_opt=f || custom_opt=e
2004-06-29 19:27:48 +04:00
find "$TOPDIR" -type l |
2004-11-01 12:47:06 +03:00
sed -e "s:$TOPDIR::" -$custom_opt "$CUSTOM_LINK_SCRIPT" |
2004-06-29 19:27:48 +04:00
grep -v '^$' >> "$OUTFILE" ||:
fi
2002-03-25 23:37:46 +03:00
}
for NAME in "$@"; do
if [ -n "$OUTPUT" ]; then
OUTFILE="$OUTPUT"
[ "$NAME" = "$1" ] || APPEND=1
else
OUTFILE="$NAME.lang"
fi
FindLang
done