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 # 2012-12-22 Elan Ruusamäe <glen@pld-linux.org>
19 # 2006-08-28 Elan Ruusamäe <glen@pld-linux.org>
20 # * fixed --all-name which got broken with last change.
21 # 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
22 # * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
23 # 2001-01-08 Michał Kochanowicz <mkochano@pld.org.pl>
24 # * --all-name support for KDE.
25 # 2000-11-28 Rafał Cygnarowski <pascalek@pld.org.pl>
26 # * next simple rule for KDE
27 # 2000-11-12 Rafał Cygnarowski <pascalek@pld.org.pl>
28 # * simple rules for KDE help files
29 # 2000-06-05 Michał Kochanowicz <mkochano@pld.org.pl>
30 # * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
31 # no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
32 # 2000-04-17 Arkadiusz Miśkiewicz <misiek@pld.org.pl>
33 # * exit 1 when no files found
34 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
35 # * added support for GNOME help files
36 # * start support for KDE help files
43 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
46 the top of the tree containing the files to be processed--should be
47 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
48 PACKAGE_NAME is the %{name} of the package. This should also be
49 the basename of the .mo files. the output is written to
50 PACKAGE_NAME.lang unless \$3 is given in which case output is written
53 --with-gnome find GNOME help files
54 --with-mate find MATE help files
55 --with-kde find KDE help files
56 --with-omf find OMF files
57 --with-qm find QT .qm files
58 --all-name match all package/domain names
59 --without-mo skip *.mo locale files
60 -o NAME output will be saved to NAME
61 -a NAME output will be appended to NAME
69 echo >&2 "$PROG: expects non-/ argument for '$1'"
71 elif [ ! -d $1 ]; then
72 echo >&2 "$PROG: $1: No such directory"
96 while test $# -gt 0; do
100 echo "$PROG: Enabling with GNOME"
105 echo "$PROG: Enabling with MATE"
109 echo "$PROG: Enabling with KDE"
114 echo "$PROG: Enabling with OMF"
119 echo "$PROG: Enabling with Qt QM"
124 echo "$PROG: Disabling .mo files"
129 echo "$PROG: Enabling with all names"
152 echo "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
154 MO_NAME=.$OUTPUT.tmp~
155 echo '%defattr(644,root,root,755)' > $MO_NAME
158 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
159 find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
163 s:'"$TOP_DIR"'::' > __find.files
165 echo "$PROG: Using cached __find.files"
169 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
170 find $TOP_DIR -type f -name '*.omf' | \
172 s:'"$TOP_DIR"'::' > __omf.files
174 echo "$PROG: Using cached __omf.files"
178 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
179 find $TOP_DIR -type f -name '*.qm' | \
181 s:'"$TOP_DIR"'::' > __qm.files
183 echo "$PROG: Using cached __qm.files"
188 if [ "$ALL_NAME" ]; then
189 grep -F $NAME __find.files
194 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
195 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
197 s:%lang(C) ::' >> $MO_NAME
201 if [ "$ALL_NAME" ]; then
202 grep -F $NAME __omf.files
207 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
208 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
210 s:%lang(C) ::' >> $MO_NAME
214 if [ "$ALL_NAME" ]; then
215 grep -F $NAME __qm.files
220 '"$ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.qm$\):%lang(\2\4) \1\2\3\4\5:
221 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
223 s:%lang(C) ::' >> $MO_NAME
225 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
226 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
228 echo "$PROG: Using cached __find.dirs"
233 if [ "$ALL_NAME" ]; then
234 grep -F $NAME __find.dirs
239 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
240 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
241 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
242 '"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
243 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
244 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
246 s:%lang(C) ::' >> $MO_NAME
250 if [ "$ALL_NAME" ]; then
251 grep -F $NAME __find.dirs
256 '"$NO_ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
257 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'$\):%dir \1:
258 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
259 '"$ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
260 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+$\):%dir \1:
261 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
263 s:%lang(C) ::' >> $MO_NAME
267 if [ "$ALL_NAME" ]; then
268 grep -F $NAME __find.dirs
273 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
274 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
276 s:%lang(C) ::' >> $MO_NAME
279 if [ "$ALL_NAME" ]; then
280 grep -F $NAME __find.dirs
285 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
286 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
288 s:%lang(C) ::' >> $MO_NAME
290 if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
291 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
295 if [ "$APPEND" ]; then
296 cat $MO_NAME >> $OUTPUT
299 mv -f $MO_NAME $OUTPUT