2 #findlang - automagically generate list of language specific files
3 #for inclusion in an rpm spec file.
4 #This does assume that the *.mo files are under .../share/locale/...
5 #Run with no arguments gets a usage message.
7 #findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
9 #Redistribution and use of this software are hereby permitted for any
10 #purpose as long as this notice and the above copyright notice remain
11 #in tact and are included with any redistribution of this file or any
12 #work based on this file.
16 # 2006-08-28 Elan Ruusamäe <glen@pld-linux.org>
17 # * fixed --all-name which got broken with last change.
18 # 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
19 # * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
20 # 2001-01-08 Micha³ Kochanowicz <mkochano@pld.org.pl>
21 # * --all-name support for KDE.
22 # 2000-11-28 Rafa³ Cygnarowski <pascalek@pld.org.pl>
23 # * next simple rule for KDE
24 # 2000-11-12 Rafa³ Cygnarowski <pascalek@pld.org.pl>
25 # * simple rules for KDE help files
26 # 2000-06-05 Micha³ Kochanowicz <mkochano@pld.org.pl>
27 # * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
28 # no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
29 # 2000-04-17 Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
30 # * exit 1 when no files found
31 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
32 # * added support for GNOME help files
33 # * start support for KDE help files
40 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
43 the top of the tree containing the files to be processed--should be
44 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
45 PACKAGE_NAME is the %{name} of the package. This should also be
46 the basename of the .mo files. the output is written to
47 PACKAGE_NAME.lang unless \$3 is given in which case output is written
50 --with-gnome find GNOME help files
51 --with-kde find KDE help files
52 --with-omf find OMF files
53 --all-name match all package/domain names
54 --without-mo skip *.mo locale files
62 echo >&2 "$PROG: expects non-/ argument for '$1'"
64 elif [ ! -d $1 ]; then
65 echo >&2 "$PROG: $1: No such directory"
86 while test $# -gt 0 ; do
90 echo "$PROG: Enabling with GNOME"
94 echo "$PROG: Enabling with KDE"
99 echo "$PROG: Enabling with OMF"
104 echo "$PROG: Disabling .mo files"
109 echo "$PROG: Enabling with all names"
121 echo '%defattr(644,root,root,755)' > $MO_NAME
123 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
124 find $TOP_DIR -type f -name '*.mo' | xargs -r file | egrep -v ', 1 messages$' | \
127 s:'"$TOP_DIR"'::' > __find.files
129 echo "$PROG: Using cached __find.files"
132 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
133 find $TOP_DIR -type f -name '*.omf' | \
135 s:'"$TOP_DIR"'::' > __omf.files
137 echo "$PROG: Using cached __omf.files"
141 if [ "$ALL_NAME" ]; then
142 fgrep $NAME __find.files
147 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*\.mo$\):%lang(\2) \1\2\3:
148 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/]\+\)\(.*/'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
151 s:^\$::' | egrep -v '^$' >> $MO_NAME
154 if [ "$ALL_NAME" ]; then
155 fgrep $NAME __omf.files
160 '"$ALL_NAME$OMF"'s:\(.*/omf/[a-zA-Z0-9.\_\-]\+\)\(.*\-\)\(.*\)\(.*\.omf\):%lang(\3) \1\2\3\4:
161 '"$NO_ALL_NAME$OMF"'s:\(.*/omf/'"$NAME"'\)\(.*\-\)\(.*\)\(.*\.omf\):%lang(\3) \1\2\3\4:
164 s:^\$::' | egrep -v '^$' >> $MO_NAME
166 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
167 find $TOP_DIR -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
169 echo "$PROG: Using cached __find.dirs"
173 if [ "$ALL_NAME" ]; then
174 fgrep $NAME __find.dirs
179 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
180 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/[a-zA-Z0-9.\_\-]/.\+\)::
181 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'\/\)\([^/]\+\):%lang(\2) \1\2:
182 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
183 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]/.\+\)::
184 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+\/\)\([^/]\+\):%lang(\2) \1\2:
185 s:%lang(.*) .*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+/.*::
187 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
190 if [ "$ALL_NAME" ]; then
191 fgrep $NAME __find.dirs
196 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
197 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
198 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
199 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
201 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
204 if [ "$ALL_NAME" ]; then
205 fgrep $NAME __find.dirs
210 '"$NO_ALL_NAME$OMF"'s:\(.*/omf/'"$NAME"'$\):%dir \1:
211 '"$ALL_NAME$OMF"'s:\(.*/omf/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
213 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
215 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
216 echo >&2 "Error: international files not found for $NAME!"