]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
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. | |
7 | ||
8 | # findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu> | |
9 | ||
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. | |
14 | ||
15 | # Changes: | |
16 | # | |
17 | # 2012-12-22 Elan Ruusamäe <glen@pld-linux.org> | |
18 | # * added --with-mate | |
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 | |
37 | ||
38 | PROG=${0##*/} | |
39 | VERSION=1.36 | |
40 | ||
41 | usage () { | |
42 | cat <<EOF | |
43 | Usage: $PROG TOP_DIR PACKAGE_NAME [prefix] | |
44 | ||
45 | where TOP_DIR is | |
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 | |
51 | to \$3. | |
52 | Additional options: | |
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 | |
62 | EOF | |
63 | exit 1 | |
64 | } | |
65 | ||
66 | if [ -z "$1" ]; then | |
67 | usage | |
68 | elif [ $1 = / ]; then | |
69 | echo >&2 "$PROG: expects non-/ argument for '$1'" | |
70 | exit 1 | |
71 | elif [ ! -d $1 ]; then | |
72 | echo >&2 "$PROG: $1: No such directory" | |
73 | exit 1 | |
74 | else | |
75 | TOP_DIR="${1%/}" | |
76 | fi | |
77 | shift | |
78 | ||
79 | if [ -z "$1" ]; then | |
80 | usage | |
81 | else | |
82 | NAME=$1 | |
83 | fi | |
84 | shift | |
85 | ||
86 | GNOME='#' | |
87 | MATE='#' | |
88 | KDE='#' | |
89 | OMF='#' | |
90 | QM='#' | |
91 | MO='' | |
92 | OUTPUT=$NAME.lang | |
93 | ALL_NAME='#' | |
94 | NO_ALL_NAME='' | |
95 | APPEND='' | |
96 | while test $# -gt 0; do | |
97 | case "$1" in | |
98 | --with-gnome) | |
99 | GNOME='' | |
100 | echo "$PROG: Enabling with GNOME" | |
101 | shift | |
102 | ;; | |
103 | --with-mate) | |
104 | MATE='' | |
105 | echo "$PROG: Enabling with MATE" | |
106 | shift | |
107 | ;; | |
108 | --with-kde) | |
109 | echo "$PROG: Enabling with KDE" | |
110 | KDE='' | |
111 | shift | |
112 | ;; | |
113 | --with-omf) | |
114 | echo "$PROG: Enabling with OMF" | |
115 | OMF='' | |
116 | shift | |
117 | ;; | |
118 | --with-qm) | |
119 | echo "$PROG: Enabling with Qt QM" | |
120 | QM='' | |
121 | shift | |
122 | ;; | |
123 | --without-mo) | |
124 | echo "$PROG: Disabling .mo files" | |
125 | MO='#' | |
126 | shift | |
127 | ;; | |
128 | --all-name) | |
129 | echo "$PROG: Enabling with all names" | |
130 | ALL_NAME='' | |
131 | NO_ALL_NAME='#' | |
132 | shift | |
133 | ;; | |
134 | -o) | |
135 | shift | |
136 | OUTPUT=$1 | |
137 | shift | |
138 | ;; | |
139 | -a) | |
140 | shift | |
141 | OUTPUT=$1 | |
142 | APPEND='>' | |
143 | shift | |
144 | ;; | |
145 | *) | |
146 | OUTPUT=$1 | |
147 | shift | |
148 | ;; | |
149 | esac | |
150 | done | |
151 | ||
152 | echo "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT" | |
153 | ||
154 | MO_NAME=.$OUTPUT.tmp~ | |
155 | echo '%defattr(644,root,root,755)' > $MO_NAME | |
156 | ||
157 | # .mo | |
158 | if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then | |
159 | find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \ | |
160 | sed -e ' | |
161 | /, 1 messages$/d | |
162 | s/:.*// | |
163 | s:'"$TOP_DIR"'::' > __find.files | |
164 | else | |
165 | echo "$PROG: Using cached __find.files" | |
166 | fi | |
167 | ||
168 | # .omf | |
169 | if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then | |
170 | find $TOP_DIR -type f -name '*.omf' | \ | |
171 | sed -e ' | |
172 | s:'"$TOP_DIR"'::' > __omf.files | |
173 | else | |
174 | echo "$PROG: Using cached __omf.files" | |
175 | fi | |
176 | ||
177 | # .qm | |
178 | if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then | |
179 | find $TOP_DIR -type f -name '*.qm' | \ | |
180 | sed -e ' | |
181 | s:'"$TOP_DIR"'::' > __qm.files | |
182 | else | |
183 | echo "$PROG: Using cached __qm.files" | |
184 | fi | |
185 | ||
186 | # .mo | |
187 | ( | |
188 | if [ "$ALL_NAME" ]; then | |
189 | grep -F $NAME __find.files | |
190 | else | |
191 | cat __find.files | |
192 | fi | |
193 | ) | sed ' | |
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: | |
196 | /^[^%]/d | |
197 | s:%lang(C) ::' >> $MO_NAME | |
198 | ||
199 | # .omf | |
200 | ( | |
201 | if [ "$ALL_NAME" ]; then | |
202 | grep -F $NAME __omf.files | |
203 | else | |
204 | cat __omf.files | |
205 | fi | |
206 | ) | sed ' | |
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: | |
209 | /^[^%]/d | |
210 | s:%lang(C) ::' >> $MO_NAME | |
211 | ||
212 | # .qm | |
213 | ( | |
214 | if [ "$ALL_NAME" ]; then | |
215 | grep -F $NAME __qm.files | |
216 | else | |
217 | cat __qm.files | |
218 | fi | |
219 | ) | sed ' | |
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: | |
222 | /^[^%]/d | |
223 | s:%lang(C) ::' >> $MO_NAME | |
224 | ||
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 | |
227 | else | |
228 | echo "$PROG: Using cached __find.dirs" | |
229 | fi | |
230 | ||
231 | # gnome | |
232 | ( | |
233 | if [ "$ALL_NAME" ]; then | |
234 | grep -F $NAME __find.dirs | |
235 | else | |
236 | cat __find.dirs | |
237 | fi | |
238 | ) | sed ' | |
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: | |
245 | /^[^%]/d | |
246 | s:%lang(C) ::' >> $MO_NAME | |
247 | ||
248 | # mate | |
249 | ( | |
250 | if [ "$ALL_NAME" ]; then | |
251 | grep -F $NAME __find.dirs | |
252 | else | |
253 | cat __find.dirs | |
254 | fi | |
255 | ) | sed ' | |
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: | |
262 | /^[^%]/d | |
263 | s:%lang(C) ::' >> $MO_NAME | |
264 | ||
265 | # kde | |
266 | ( | |
267 | if [ "$ALL_NAME" ]; then | |
268 | grep -F $NAME __find.dirs | |
269 | else | |
270 | cat __find.dirs | |
271 | fi | |
272 | ) | sed ' | |
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: | |
275 | /^[^%]/d | |
276 | s:%lang(C) ::' >> $MO_NAME | |
277 | ||
278 | ( | |
279 | if [ "$ALL_NAME" ]; then | |
280 | grep -F $NAME __find.dirs | |
281 | else | |
282 | cat __find.dirs | |
283 | fi | |
284 | ) | sed ' | |
285 | '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1: | |
286 | '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1: | |
287 | /^[^%]/d | |
288 | s:%lang(C) ::' >> $MO_NAME | |
289 | ||
290 | if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then | |
291 | echo >&2 "$PROG: Error: international files not found for '$NAME'!" | |
292 | exit 1 | |
293 | fi | |
294 | ||
295 | if [ "$APPEND" ]; then | |
296 | cat $MO_NAME >> $OUTPUT | |
297 | rm -f $MO_NAME | |
298 | else | |
299 | mv -f $MO_NAME $OUTPUT | |
300 | fi |