4 # find-lang - automagically generate list of language specific files
5 # for inclusion in an rpm spec file.
6 # This does assume that the *.mo files are under .../share/locale/...
7 # Run with no arguments gets a usage message.
9 # findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
11 # Redistribution and use of this software are hereby permitted for any
12 # purpose as long as this notice and the above copyright notice remain
13 # in tact and are included with any redistribution of this file or any
14 # work based on this file.
18 # 2006-08-28 Elan Ruusamäe <glen@pld-linux.org>
19 # * fixed --all-name which got broken with last change.
20 # 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
21 # * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
22 # 2001-01-08 Micha³ Kochanowicz <mkochano@pld.org.pl>
23 # * --all-name support for KDE.
24 # 2000-11-28 Rafa³ Cygnarowski <pascalek@pld.org.pl>
25 # * next simple rule for KDE
26 # 2000-11-12 Rafa³ Cygnarowski <pascalek@pld.org.pl>
27 # * simple rules for KDE help files
28 # 2000-06-05 Micha³ Kochanowicz <mkochano@pld.org.pl>
29 # * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
30 # no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
31 # 2000-04-17 Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
32 # * exit 1 when no files found
33 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
34 # * added support for GNOME help files
35 # * start support for KDE help files
38 VERSION=$(set -- $Revision$; echo $2)
42 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
45 the top of the tree containing the files to be processed--should be
46 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
47 PACKAGE_NAME is the %{name} of the package. This should also be
48 the basename of the .mo files. the output is written to
49 PACKAGE_NAME.lang unless \$3 is given in which case output is written
52 --with-gnome find GNOME help files
53 --with-kde find KDE help files
54 --with-omf find OMF files
55 --with-qm find QT .qm files
56 --all-name match all package/domain names
57 --without-mo skip *.mo locale files
58 -o NAME output will be saved to NAME
59 -a NAME output will be appended to NAME
67 echo >&2 "$PROG: expects non-/ argument for '$1'"
69 elif [ ! -d $1 ]; then
70 echo >&2 "$PROG: $1: No such directory"
93 while test $# -gt 0; do
97 echo "$PROG: Enabling with GNOME"
101 echo "$PROG: Enabling with KDE"
106 echo "$PROG: Enabling with OMF"
111 echo "$PROG: Enabling with Qt QM"
116 echo "$PROG: Disabling .mo files"
121 echo "$PROG: Enabling with all names"
144 echo "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
146 MO_NAME=.$OUTPUT.tmp~
147 echo '%defattr(644,root,root,755)' > $MO_NAME
150 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
151 find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
155 s:'"$TOP_DIR"'::' > __find.files
157 echo "$PROG: Using cached __find.files"
161 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
162 find $TOP_DIR -type f -name '*.omf' | \
164 s:'"$TOP_DIR"'::' > __omf.files
166 echo "$PROG: Using cached __omf.files"
170 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
171 find $TOP_DIR -type f -name '*.qm' | \
173 s:'"$TOP_DIR"'::' > __qm.files
175 echo "$PROG: Using cached __qm.files"
180 if [ "$ALL_NAME" ]; then
181 fgrep $NAME __find.files
186 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
187 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
189 s:%lang(C) ::' >> $MO_NAME
193 if [ "$ALL_NAME" ]; then
194 fgrep $NAME __omf.files
199 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
200 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
202 s:%lang(C) ::' >> $MO_NAME
206 if [ "$ALL_NAME" ]; then
207 fgrep $NAME __qm.files
212 '"$ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.qm$\):%lang(\2\4) \1\2\3\4\5:
213 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
215 s:%lang(C) ::' >> $MO_NAME
217 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
218 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
220 echo "$PROG: Using cached __find.dirs"
225 if [ "$ALL_NAME" ]; then
226 fgrep $NAME __find.dirs
231 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
232 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
233 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
234 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
236 s:%lang(C) ::' >> $MO_NAME
240 if [ "$ALL_NAME" ]; then
241 fgrep $NAME __find.dirs
246 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
247 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
249 s:%lang(C) ::' >> $MO_NAME
252 if [ "$ALL_NAME" ]; then
253 fgrep $NAME __find.dirs
258 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
259 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
261 s:%lang(C) ::' >> $MO_NAME
263 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
264 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
268 if [ "$APPEND" ]; then
269 cat $MO_NAME >> $OUTPUT
272 mv -f $MO_NAME $OUTPUT