]> git.pld-linux.org Git - packages/rpm-pld-macros.git/blame - find-lang.sh
in %cmake set processor x86_64 for x32; rel 3
[packages/rpm-pld-macros.git] / find-lang.sh
CommitLineData
d26ea5ec 1#!/bin/sh
d26ea5ec 2
2475a48e 3# find-lang - automagically generate list of language specific files
5dc8fe06
ER
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.
d26ea5ec 7
5dc8fe06 8# findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
d26ea5ec 9
5dc8fe06
ER
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#
91511b26
ER
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>
20884491 20# * fixed --all-name which got broken with last change.
91511b26 21# 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
401c60fa 22# * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
91511b26 23# 2001-01-08 Michał Kochanowicz <mkochano@pld.org.pl>
d26ea5ec 24# * --all-name support for KDE.
91511b26 25# 2000-11-28 Rafał Cygnarowski <pascalek@pld.org.pl>
d26ea5ec 26# * next simple rule for KDE
91511b26 27# 2000-11-12 Rafał Cygnarowski <pascalek@pld.org.pl>
d26ea5ec 28# * simple rules for KDE help files
91511b26 29# 2000-06-05 Michał Kochanowicz <mkochano@pld.org.pl>
d26ea5ec
AM
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.
91511b26 32# 2000-04-17 Arkadiusz Miśkiewicz <misiek@pld.org.pl>
d26ea5ec
AM
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
ebe840a3 38PROG=${0##*/}
93423c0a 39VERSION=1.41
ebe840a3 40
d26ea5ec
AM
41usage () {
42cat <<EOF
ebe840a3 43Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
d26ea5ec
AM
44
45where TOP_DIR is
46the 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.
48PACKAGE_NAME is the %{name} of the package. This should also be
49the basename of the .mo files. the output is written to
50PACKAGE_NAME.lang unless \$3 is given in which case output is written
51to \$3.
52Additional options:
53 --with-gnome find GNOME help files
91511b26 54 --with-mate find MATE help files
fbf60387 55 --with-kde find KDE help files
8542f272 56 --with-omf find OMF files
2475a48e 57 --with-qm find QT .qm files
1378be66 58 --with-django find translations in Django project
9c6566fd 59 --with-dokuwiki find translations in dokuwiki plugins/templates
fbf60387
JB
60 --all-name match all package/domain names
61 --without-mo skip *.mo locale files
4b717e5d
ER
62 -o NAME output will be saved to NAME
63 -a NAME output will be appended to NAME
d26ea5ec
AM
64EOF
65exit 1
66}
67
401c60fa
ER
68if [ -z "$1" ]; then
69 usage
70elif [ $1 = / ]; then
ebe840a3 71 echo >&2 "$PROG: expects non-/ argument for '$1'"
faff2764 72 exit 1
401c60fa 73elif [ ! -d $1 ]; then
faff2764 74 echo >&2 "$PROG: $1: No such directory"
401c60fa
ER
75 exit 1
76else
77 TOP_DIR="${1%/}"
d26ea5ec
AM
78fi
79shift
80
401c60fa
ER
81if [ -z "$1" ]; then
82 usage
83else
84 NAME=$1
d26ea5ec
AM
85fi
86shift
87
401c60fa 88GNOME='#'
91511b26 89MATE='#'
401c60fa 90KDE='#'
8542f272 91OMF='#'
2475a48e 92QM='#'
1378be66 93DJANGO='#'
9c6566fd 94DOKUWIKI=false
401c60fa 95MO=''
fbbbe492 96OUTPUT=$NAME.lang
401c60fa
ER
97ALL_NAME='#'
98NO_ALL_NAME=''
4b717e5d 99APPEND=''
2475a48e 100while test $# -gt 0; do
401c60fa 101 case "$1" in
9c6566fd
ER
102 --with-dokuwiki)
103 DOKUWIKI=true
104 echo >&2 "$PROG: Enabling with Dokuwiki"
105 shift
106 ;;
401c60fa
ER
107 --with-gnome)
108 GNOME=''
88cb0d99 109 echo >&2 "$PROG: Enabling with GNOME"
d26ea5ec
AM
110 shift
111 ;;
91511b26
ER
112 --with-mate)
113 MATE=''
88cb0d99 114 echo >&2 "$PROG: Enabling with MATE"
91511b26
ER
115 shift
116 ;;
401c60fa 117 --with-kde)
88cb0d99 118 echo >&2 "$PROG: Enabling with KDE"
401c60fa 119 KDE=''
d26ea5ec
AM
120 shift
121 ;;
8542f272 122 --with-omf)
88cb0d99 123 echo >&2 "$PROG: Enabling with OMF"
8542f272
MB
124 OMF=''
125 shift
126 ;;
2475a48e 127 --with-qm)
88cb0d99 128 echo >&2 "$PROG: Enabling with Qt QM"
2475a48e
ER
129 QM=''
130 shift
131 ;;
1378be66
ER
132 --with-django)
133 echo >&2 "$PROG: Enabling with Django"
134 DJANGO=''
135 shift
136 ;;
401c60fa 137 --without-mo)
88cb0d99 138 echo >&2 "$PROG: Disabling .mo files"
401c60fa 139 MO='#'
d26ea5ec
AM
140 shift
141 ;;
401c60fa 142 --all-name)
88cb0d99 143 echo >&2 "$PROG: Enabling with all names"
401c60fa
ER
144 ALL_NAME=''
145 NO_ALL_NAME='#'
d26ea5ec
AM
146 shift
147 ;;
4b717e5d
ER
148 -o)
149 shift
fbbbe492 150 OUTPUT=$1
4b717e5d
ER
151 shift
152 ;;
153 -a)
154 shift
fbbbe492 155 OUTPUT=$1
4b717e5d
ER
156 APPEND='>'
157 shift
158 ;;
159 *)
fbbbe492 160 OUTPUT=$1
d26ea5ec
AM
161 shift
162 ;;
163 esac
4b717e5d
ER
164done
165
9c6566fd
ER
166if $DOKUWIKI; then
167 exec /usr/lib/rpm/dokuwiki-find-lang.sh "$TOP_DIR" "$NAME"
168 echo >&2 "$PROG: ERROR: Unable to execute dokuwiki-find-lang"
169 exit 2
170fi
171
88cb0d99 172echo >&2 "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
d26ea5ec 173
fbbbe492
ER
174MO_NAME=.$OUTPUT.tmp~
175echo '%defattr(644,root,root,755)' > $MO_NAME
b8398d71 176
2475a48e 177# .mo
a569a064 178if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
6b3f3313 179 find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
401c60fa 180 sed -e '
96d010e9 181 /, 1 message/d
401c60fa
ER
182 s/:.*//
183 s:'"$TOP_DIR"'::' > __find.files
ebe840a3 184else
88cb0d99 185 echo >&2 "$PROG: Using cached __find.files"
401c60fa
ER
186fi
187
2475a48e 188# .omf
8542f272
MB
189if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
190 find $TOP_DIR -type f -name '*.omf' | \
191 sed -e '
8542f272
MB
192 s:'"$TOP_DIR"'::' > __omf.files
193else
88cb0d99 194 echo >&2 "$PROG: Using cached __omf.files"
8542f272
MB
195fi
196
2475a48e
ER
197# .qm
198if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
199 find $TOP_DIR -type f -name '*.qm' | \
200 sed -e '
201 s:'"$TOP_DIR"'::' > __qm.files
202else
88cb0d99 203 echo >&2 "$PROG: Using cached __qm.files"
2475a48e
ER
204fi
205
206# .mo
bff718e8
ER
207(
208 if [ "$ALL_NAME" ]; then
c99222d1 209 grep -F $NAME __find.files
bff718e8
ER
210 else
211 cat __find.files
212 fi
213) | sed '
1378be66 214'"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
5dc8fe06 215'"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
6b3f3313
JB
216/^[^%]/d
217s:%lang(C) ::' >> $MO_NAME
d26ea5ec 218
2475a48e 219# .omf
8542f272
MB
220(
221 if [ "$ALL_NAME" ]; then
c99222d1 222 grep -F $NAME __omf.files
8542f272
MB
223 else
224 cat __omf.files
225 fi
226) | sed '
6b3f3313
JB
227'"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
228'"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
229/^[^%]/d
230s:%lang(C) ::' >> $MO_NAME
8542f272 231
2475a48e
ER
232# .qm
233(
234 if [ "$ALL_NAME" ]; then
c99222d1 235 grep -F $NAME __qm.files
2475a48e
ER
236 else
237 cat __qm.files
238 fi
239) | sed '
59c9ed8f 240'"$NO_ALL_NAME$QM"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\([_@].*\)\?\)\.qm$\):%lang(\2) \1:
a19af47f 241'"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
59c9ed8f
ER
242'"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
243'"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
244'"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
245'"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
246s:^[^%].*::
2475a48e
ER
247/^[^%]/d
248s:%lang(C) ::' >> $MO_NAME
249
a569a064 250if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
6b3f3313 251 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
ebe840a3 252else
88cb0d99 253 echo >&2 "$PROG: Using cached __find.dirs"
401c60fa 254fi
bff718e8 255
2475a48e 256# gnome
bff718e8
ER
257(
258 if [ "$ALL_NAME" ]; then
c99222d1 259 grep -F $NAME __find.dirs
bff718e8
ER
260 else
261 cat __find.dirs
262 fi
263) | sed '
2a89e270 264'"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
d26ea5ec 265'"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
6b3f3313 266'"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
2a89e270 267'"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
6b3f3313
JB
268'"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
269'"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
270/^[^%]/d
271s:%lang(C) ::' >> $MO_NAME
d26ea5ec 272
91511b26
ER
273# mate
274(
275 if [ "$ALL_NAME" ]; then
c99222d1 276 grep -F $NAME __find.dirs
91511b26
ER
277 else
278 cat __find.dirs
279 fi
280) | sed '
281'"$NO_ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
282'"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'$\):%dir \1:
283'"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
284'"$ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
285'"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+$\):%dir \1:
286'"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
287/^[^%]/d
288s:%lang(C) ::' >> $MO_NAME
289
2475a48e 290# kde
a65ff95c
ER
291(
292 if [ "$ALL_NAME" ]; then
c99222d1 293 grep -F $NAME __find.dirs
a65ff95c
ER
294 else
295 cat __find.dirs
296 fi
297) | sed '
6b3f3313
JB
298'"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
299'"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
300/^[^%]/d
301s:%lang(C) ::' >> $MO_NAME
d26ea5ec 302
21e8065a 303# OMF
8542f272
MB
304(
305 if [ "$ALL_NAME" ]; then
c99222d1 306 grep -F $NAME __find.dirs
8542f272
MB
307 else
308 cat __find.dirs
309 fi
310) | sed '
6b3f3313
JB
311'"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
312'"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
313/^[^%]/d
314s:%lang(C) ::' >> $MO_NAME
8542f272 315
21e8065a
ER
316# Django
317cat __find.dirs | sed -r -e '
318'"$DJANGO"'s:(.+/share/python.+/locale/)([^/@]+)(@quot|@boldquot)?(@[^/]*)?$:%lang(\2\4) \1\2\3\4:
319/^[^%]/d
320s:%lang(C) ::' >> $MO_NAME
321
c99222d1 322if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
68d353c2 323 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
401c60fa 324 exit 1
d26ea5ec 325fi
fbbbe492
ER
326
327if [ "$APPEND" ]; then
328 cat $MO_NAME >> $OUTPUT
329 rm -f $MO_NAME
330else
331 mv -f $MO_NAME $OUTPUT
332fi
This page took 0.255614 seconds and 4 git commands to generate.