]> TLD Linux GIT Repositories - packages/rpm-tld-macros.git/blob - find-lang.sh
- merged 2.030 from PLD, re-enabled PHP dependency generators
[packages/rpm-tld-macros.git] / find-lang.sh
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.40
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   --with-django         find translations in Django project
59   --all-name            match all package/domain names
60   --without-mo          skip *.mo locale files
61   -o NAME                       output will be saved to NAME
62   -a NAME                       output will be appended to NAME
63 EOF
64 exit 1
65 }
66
67 if [ -z "$1" ]; then
68         usage
69 elif [ $1 = / ]; then
70         echo >&2 "$PROG: expects non-/ argument for '$1'"
71         exit 1
72 elif [ ! -d $1 ]; then
73         echo >&2 "$PROG: $1: No such directory"
74         exit 1
75 else
76         TOP_DIR="${1%/}"
77 fi
78 shift
79
80 if [ -z "$1" ]; then
81         usage
82 else
83         NAME=$1
84 fi
85 shift
86
87 GNOME='#'
88 MATE='#'
89 KDE='#'
90 OMF='#'
91 QM='#'
92 DJANGO='#'
93 MO=''
94 OUTPUT=$NAME.lang
95 ALL_NAME='#'
96 NO_ALL_NAME=''
97 APPEND=''
98 while test $# -gt 0; do
99     case "$1" in
100         --with-gnome)
101                 GNOME=''
102                 echo >&2 "$PROG: Enabling with GNOME"
103                 shift
104                 ;;
105         --with-mate)
106                 MATE=''
107                 echo >&2 "$PROG: Enabling with MATE"
108                 shift
109                 ;;
110         --with-kde)
111                 echo >&2 "$PROG: Enabling with KDE"
112                 KDE=''
113                 shift
114                 ;;
115         --with-omf)
116                 echo >&2 "$PROG: Enabling with OMF"
117                 OMF=''
118                 shift
119                 ;;
120         --with-qm)
121                 echo >&2 "$PROG: Enabling with Qt QM"
122                 QM=''
123                 shift
124                 ;;
125         --with-django)
126                 echo >&2 "$PROG: Enabling with Django"
127                 DJANGO=''
128                 shift
129                 ;;
130         --without-mo)
131                 echo >&2 "$PROG: Disabling .mo files"
132                 MO='#'
133                 shift
134                 ;;
135         --all-name)
136                 echo >&2 "$PROG: Enabling with all names"
137                 ALL_NAME=''
138                 NO_ALL_NAME='#'
139                 shift
140                 ;;
141         -o)
142                 shift
143                 OUTPUT=$1
144                 shift
145                 ;;
146         -a)
147                 shift
148                 OUTPUT=$1
149                 APPEND='>'
150                 shift
151                 ;;
152         *)
153                 OUTPUT=$1
154                 shift
155                 ;;
156     esac
157 done
158
159 echo >&2 "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
160
161 MO_NAME=.$OUTPUT.tmp~
162 echo '%defattr(644,root,root,755)' > $MO_NAME
163
164 # .mo
165 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
166         find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
167         sed -e '
168                 /, 1 message/d
169                 s/:.*//
170                 s:'"$TOP_DIR"'::' > __find.files
171 else
172         echo >&2 "$PROG: Using cached __find.files"
173 fi
174
175 # .omf
176 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
177         find $TOP_DIR -type f -name '*.omf' | \
178         sed -e '
179                 s:'"$TOP_DIR"'::' > __omf.files
180 else
181         echo >&2 "$PROG: Using cached __omf.files"
182 fi
183
184 # .qm
185 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
186         find $TOP_DIR -type f -name '*.qm' | \
187         sed -e '
188                 s:'"$TOP_DIR"'::' > __qm.files
189 else
190         echo >&2 "$PROG: Using cached __qm.files"
191 fi
192
193 # .mo
194 (
195         if [ "$ALL_NAME" ]; then
196                 grep -F $NAME __find.files
197         else
198                 cat __find.files
199         fi
200 ) | sed '
201 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
202 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
203 /^[^%]/d
204 s:%lang(C) ::' >> $MO_NAME
205
206 # .omf
207 (
208         if [ "$ALL_NAME" ]; then
209                 grep -F $NAME __omf.files
210         else
211                 cat __omf.files
212         fi
213 ) | sed '
214 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
215 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
216 /^[^%]/d
217 s:%lang(C) ::' >> $MO_NAME
218
219 # .qm
220 (
221         if [ "$ALL_NAME" ]; then
222                 grep -F $NAME __qm.files
223         else
224                 cat __qm.files
225         fi
226 ) | sed '
227 '"$NO_ALL_NAME$QM"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\([_@].*\)\?\)\.qm$\):%lang(\2) \1:
228 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
229 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
230 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
231 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
232 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
233 s:^[^%].*::
234 /^[^%]/d
235 s:%lang(C) ::' >> $MO_NAME
236
237 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
238         find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
239 else
240         echo >&2 "$PROG: Using cached __find.dirs"
241 fi
242
243 # gnome
244 (
245         if [ "$ALL_NAME" ]; then
246                 grep -F $NAME __find.dirs
247         else
248                 cat __find.dirs
249         fi
250 ) | sed '
251 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
252 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
253 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
254 '"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
255 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
256 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
257 /^[^%]/d
258 s:%lang(C) ::' >> $MO_NAME
259
260 # mate
261 (
262         if [ "$ALL_NAME" ]; then
263                 grep -F $NAME __find.dirs
264         else
265                 cat __find.dirs
266         fi
267 ) | sed '
268 '"$NO_ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
269 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'$\):%dir \1:
270 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
271 '"$ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
272 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+$\):%dir \1:
273 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
274 /^[^%]/d
275 s:%lang(C) ::' >> $MO_NAME
276
277 # kde
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$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
286 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
287 /^[^%]/d
288 s:%lang(C) ::' >> $MO_NAME
289
290 # OMF
291 (
292         if [ "$ALL_NAME" ]; then
293                 grep -F $NAME __find.dirs
294         else
295                 cat __find.dirs
296         fi
297 ) | sed '
298 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
299 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
300 /^[^%]/d
301 s:%lang(C) ::' >> $MO_NAME
302
303 # Django
304 cat __find.dirs | sed -r -e '
305 '"$DJANGO"'s:(.+/share/python.+/locale/)([^/@]+)(@quot|@boldquot)?(@[^/]*)?$:%lang(\2\4) \1\2\3\4:
306 /^[^%]/d
307 s:%lang(C) ::' >> $MO_NAME
308
309 if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
310         echo >&2 "$PROG: Error: international files not found for '$NAME'!"
311         exit 1
312 fi
313
314 if [ "$APPEND" ]; then
315         cat $MO_NAME >> $OUTPUT
316         rm -f $MO_NAME
317 else
318         mv -f $MO_NAME $OUTPUT
319 fi