]> git.pld-linux.org Git - packages/rpm-build-macros.git/blob - find-lang.sh
don't hide output; refs 3303369
[packages/rpm-build-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.38
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 >&2 "$PROG: Enabling with GNOME"
101                 shift
102                 ;;
103         --with-mate)
104                 MATE=''
105                 echo >&2 "$PROG: Enabling with MATE"
106                 shift
107                 ;;
108         --with-kde)
109                 echo >&2 "$PROG: Enabling with KDE"
110                 KDE=''
111                 shift
112                 ;;
113         --with-omf)
114                 echo >&2 "$PROG: Enabling with OMF"
115                 OMF=''
116                 shift
117                 ;;
118         --with-qm)
119                 echo >&2 "$PROG: Enabling with Qt QM"
120                 QM=''
121                 shift
122                 ;;
123         --without-mo)
124                 echo >&2 "$PROG: Disabling .mo files"
125                 MO='#'
126                 shift
127                 ;;
128         --all-name)
129                 echo >&2 "$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 >&2 "$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 >&2 "$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 >&2 "$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 >&2 "$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 '"$NO_ALL_NAME$QM"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\([_@].*\)\?\)\.qm$\):%lang(\2) \1:
221 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
222 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
223 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
224 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
225 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
226 s:^[^%].*::
227 /^[^%]/d
228 s:%lang(C) ::' >> $MO_NAME
229
230 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
231         find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
232 else
233         echo >&2 "$PROG: Using cached __find.dirs"
234 fi
235
236 # gnome
237 (
238         if [ "$ALL_NAME" ]; then
239                 grep -F $NAME __find.dirs
240         else
241                 cat __find.dirs
242         fi
243 ) | sed '
244 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
245 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
246 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
247 '"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
248 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
249 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
250 /^[^%]/d
251 s:%lang(C) ::' >> $MO_NAME
252
253 # mate
254 (
255         if [ "$ALL_NAME" ]; then
256                 grep -F $NAME __find.dirs
257         else
258                 cat __find.dirs
259         fi
260 ) | sed '
261 '"$NO_ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
262 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'$\):%dir \1:
263 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
264 '"$ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
265 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+$\):%dir \1:
266 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
267 /^[^%]/d
268 s:%lang(C) ::' >> $MO_NAME
269
270 # kde
271 (
272         if [ "$ALL_NAME" ]; then
273                 grep -F $NAME __find.dirs
274         else
275                 cat __find.dirs
276         fi
277 ) | sed '
278 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
279 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
280 /^[^%]/d
281 s:%lang(C) ::' >> $MO_NAME
282
283 (
284         if [ "$ALL_NAME" ]; then
285                 grep -F $NAME __find.dirs
286         else
287                 cat __find.dirs
288         fi
289 ) | sed '
290 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
291 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
292 /^[^%]/d
293 s:%lang(C) ::' >> $MO_NAME
294
295 if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
296         echo >&2 "$PROG: Error: international files not found for '$NAME'!"
297         exit 1
298 fi
299
300 if [ "$APPEND" ]; then
301         cat $MO_NAME >> $OUTPUT
302         rm -f $MO_NAME
303 else
304         mv -f $MO_NAME $OUTPUT
305 fi
This page took 0.069559 seconds and 3 git commands to generate.