3 # find-lang - automagically generate list of language specific files
4 # for inclusion in an rpm spec file.
5 # This does assume that the *.mo files are under .../share/locale/...
6 # Run with no arguments gets a usage message.
8 # findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
10 # Redistribution and use of this software are hereby permitted for any
11 # purpose as long as this notice and the above copyright notice remain
12 # in tact and are included with any redistribution of this file or any
13 # work based on this file.
17 # 2006-08-28 Elan Ruusamäe <glen@pld-linux.org>
18 # * fixed --all-name which got broken with last change.
19 # 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
20 # * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
21 # 2001-01-08 Micha³ Kochanowicz <mkochano@pld.org.pl>
22 # * --all-name support for KDE.
23 # 2000-11-28 Rafa³ Cygnarowski <pascalek@pld.org.pl>
24 # * next simple rule for KDE
25 # 2000-11-12 Rafa³ Cygnarowski <pascalek@pld.org.pl>
26 # * simple rules for KDE help files
27 # 2000-06-05 Micha³ Kochanowicz <mkochano@pld.org.pl>
28 # * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
29 # no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
30 # 2000-04-17 Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
31 # * exit 1 when no files found
32 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
33 # * added support for GNOME help files
34 # * start support for KDE help files
41 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
44 the top of the tree containing the files to be processed--should be
45 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
46 PACKAGE_NAME is the %{name} of the package. This should also be
47 the basename of the .mo files. the output is written to
48 PACKAGE_NAME.lang unless \$3 is given in which case output is written
51 --with-gnome find GNOME help files
52 --with-kde find KDE help files
53 --with-omf find OMF files
54 --with-qm find QT .qm files
55 --all-name match all package/domain names
56 --without-mo skip *.mo locale files
57 -o NAME output will be saved to NAME
58 -a NAME output will be appended to NAME
66 echo >&2 "$PROG: expects non-/ argument for '$1'"
68 elif [ ! -d $1 ]; then
69 echo >&2 "$PROG: $1: No such directory"
92 while test $# -gt 0; do
96 echo "$PROG: Enabling with GNOME"
100 echo "$PROG: Enabling with KDE"
105 echo "$PROG: Enabling with OMF"
110 echo "$PROG: Enabling with Qt QM"
115 echo "$PROG: Disabling .mo files"
120 echo "$PROG: Enabling with all names"
143 echo "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
145 MO_NAME=.$OUTPUT.tmp~
146 echo '%defattr(644,root,root,755)' > $MO_NAME
149 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
150 find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
154 s:'"$TOP_DIR"'::' > __find.files
156 echo "$PROG: Using cached __find.files"
160 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
161 find $TOP_DIR -type f -name '*.omf' | \
163 s:'"$TOP_DIR"'::' > __omf.files
165 echo "$PROG: Using cached __omf.files"
169 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
170 find $TOP_DIR -type f -name '*.qm' | \
172 s:'"$TOP_DIR"'::' > __qm.files
174 echo "$PROG: Using cached __qm.files"
179 if [ "$ALL_NAME" ]; then
180 fgrep $NAME __find.files
185 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
186 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
188 s:%lang(C) ::' >> $MO_NAME
192 if [ "$ALL_NAME" ]; then
193 fgrep $NAME __omf.files
198 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
199 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
201 s:%lang(C) ::' >> $MO_NAME
205 if [ "$ALL_NAME" ]; then
206 fgrep $NAME __qm.files
211 '"$ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.qm$\):%lang(\2\4) \1\2\3\4\5:
212 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
214 s:%lang(C) ::' >> $MO_NAME
216 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
217 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
219 echo "$PROG: Using cached __find.dirs"
224 if [ "$ALL_NAME" ]; then
225 fgrep $NAME __find.dirs
230 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
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:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
234 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
235 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
237 s:%lang(C) ::' >> $MO_NAME
241 if [ "$ALL_NAME" ]; then
242 fgrep $NAME __find.dirs
247 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
248 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
250 s:%lang(C) ::' >> $MO_NAME
253 if [ "$ALL_NAME" ]; then
254 fgrep $NAME __find.dirs
259 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
260 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
262 s:%lang(C) ::' >> $MO_NAME
264 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
265 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
269 if [ "$APPEND" ]; then
270 cat $MO_NAME >> $OUTPUT
273 mv -f $MO_NAME $OUTPUT