]> git.pld-linux.org Git - packages/rpm-build-macros.git/blame - find-lang.sh
- 1.740; fix regex for build root
[packages/rpm-build-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##*/}
1378be66 39VERSION=1.40
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
fbf60387
JB
59 --all-name match all package/domain names
60 --without-mo skip *.mo locale files
4b717e5d
ER
61 -o NAME output will be saved to NAME
62 -a NAME output will be appended to NAME
d26ea5ec
AM
63EOF
64exit 1
65}
66
401c60fa
ER
67if [ -z "$1" ]; then
68 usage
69elif [ $1 = / ]; then
ebe840a3 70 echo >&2 "$PROG: expects non-/ argument for '$1'"
faff2764 71 exit 1
401c60fa 72elif [ ! -d $1 ]; then
faff2764 73 echo >&2 "$PROG: $1: No such directory"
401c60fa
ER
74 exit 1
75else
76 TOP_DIR="${1%/}"
d26ea5ec
AM
77fi
78shift
79
401c60fa
ER
80if [ -z "$1" ]; then
81 usage
82else
83 NAME=$1
d26ea5ec
AM
84fi
85shift
86
401c60fa 87GNOME='#'
91511b26 88MATE='#'
401c60fa 89KDE='#'
8542f272 90OMF='#'
2475a48e 91QM='#'
1378be66 92DJANGO='#'
401c60fa 93MO=''
fbbbe492 94OUTPUT=$NAME.lang
401c60fa
ER
95ALL_NAME='#'
96NO_ALL_NAME=''
4b717e5d 97APPEND=''
2475a48e 98while test $# -gt 0; do
401c60fa
ER
99 case "$1" in
100 --with-gnome)
101 GNOME=''
88cb0d99 102 echo >&2 "$PROG: Enabling with GNOME"
d26ea5ec
AM
103 shift
104 ;;
91511b26
ER
105 --with-mate)
106 MATE=''
88cb0d99 107 echo >&2 "$PROG: Enabling with MATE"
91511b26
ER
108 shift
109 ;;
401c60fa 110 --with-kde)
88cb0d99 111 echo >&2 "$PROG: Enabling with KDE"
401c60fa 112 KDE=''
d26ea5ec
AM
113 shift
114 ;;
8542f272 115 --with-omf)
88cb0d99 116 echo >&2 "$PROG: Enabling with OMF"
8542f272
MB
117 OMF=''
118 shift
119 ;;
2475a48e 120 --with-qm)
88cb0d99 121 echo >&2 "$PROG: Enabling with Qt QM"
2475a48e
ER
122 QM=''
123 shift
124 ;;
1378be66
ER
125 --with-django)
126 echo >&2 "$PROG: Enabling with Django"
127 DJANGO=''
128 shift
129 ;;
401c60fa 130 --without-mo)
88cb0d99 131 echo >&2 "$PROG: Disabling .mo files"
401c60fa 132 MO='#'
d26ea5ec
AM
133 shift
134 ;;
401c60fa 135 --all-name)
88cb0d99 136 echo >&2 "$PROG: Enabling with all names"
401c60fa
ER
137 ALL_NAME=''
138 NO_ALL_NAME='#'
d26ea5ec
AM
139 shift
140 ;;
4b717e5d
ER
141 -o)
142 shift
fbbbe492 143 OUTPUT=$1
4b717e5d
ER
144 shift
145 ;;
146 -a)
147 shift
fbbbe492 148 OUTPUT=$1
4b717e5d
ER
149 APPEND='>'
150 shift
151 ;;
152 *)
fbbbe492 153 OUTPUT=$1
d26ea5ec
AM
154 shift
155 ;;
156 esac
4b717e5d
ER
157done
158
88cb0d99 159echo >&2 "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
d26ea5ec 160
fbbbe492
ER
161MO_NAME=.$OUTPUT.tmp~
162echo '%defattr(644,root,root,755)' > $MO_NAME
b8398d71 163
2475a48e 164# .mo
a569a064 165if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
6b3f3313 166 find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
401c60fa 167 sed -e '
96d010e9 168 /, 1 message/d
401c60fa
ER
169 s/:.*//
170 s:'"$TOP_DIR"'::' > __find.files
ebe840a3 171else
88cb0d99 172 echo >&2 "$PROG: Using cached __find.files"
401c60fa
ER
173fi
174
2475a48e 175# .omf
8542f272
MB
176if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
177 find $TOP_DIR -type f -name '*.omf' | \
178 sed -e '
8542f272
MB
179 s:'"$TOP_DIR"'::' > __omf.files
180else
88cb0d99 181 echo >&2 "$PROG: Using cached __omf.files"
8542f272
MB
182fi
183
2475a48e
ER
184# .qm
185if [ ! -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
189else
88cb0d99 190 echo >&2 "$PROG: Using cached __qm.files"
2475a48e
ER
191fi
192
193# .mo
bff718e8
ER
194(
195 if [ "$ALL_NAME" ]; then
c99222d1 196 grep -F $NAME __find.files
bff718e8
ER
197 else
198 cat __find.files
199 fi
200) | sed '
1378be66 201'"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
5dc8fe06 202'"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
6b3f3313
JB
203/^[^%]/d
204s:%lang(C) ::' >> $MO_NAME
d26ea5ec 205
2475a48e 206# .omf
8542f272
MB
207(
208 if [ "$ALL_NAME" ]; then
c99222d1 209 grep -F $NAME __omf.files
8542f272
MB
210 else
211 cat __omf.files
212 fi
213) | sed '
6b3f3313
JB
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
217s:%lang(C) ::' >> $MO_NAME
8542f272 218
2475a48e
ER
219# .qm
220(
221 if [ "$ALL_NAME" ]; then
c99222d1 222 grep -F $NAME __qm.files
2475a48e
ER
223 else
224 cat __qm.files
225 fi
226) | sed '
59c9ed8f 227'"$NO_ALL_NAME$QM"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\([_@].*\)\?\)\.qm$\):%lang(\2) \1:
a19af47f 228'"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
59c9ed8f
ER
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:
233s:^[^%].*::
2475a48e
ER
234/^[^%]/d
235s:%lang(C) ::' >> $MO_NAME
236
a569a064 237if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
6b3f3313 238 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
ebe840a3 239else
88cb0d99 240 echo >&2 "$PROG: Using cached __find.dirs"
401c60fa 241fi
bff718e8 242
2475a48e 243# gnome
bff718e8
ER
244(
245 if [ "$ALL_NAME" ]; then
c99222d1 246 grep -F $NAME __find.dirs
bff718e8
ER
247 else
248 cat __find.dirs
249 fi
250) | sed '
2a89e270 251'"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
d26ea5ec 252'"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
6b3f3313 253'"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
2a89e270 254'"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
6b3f3313
JB
255'"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
256'"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
257/^[^%]/d
258s:%lang(C) ::' >> $MO_NAME
d26ea5ec 259
91511b26
ER
260# mate
261(
262 if [ "$ALL_NAME" ]; then
c99222d1 263 grep -F $NAME __find.dirs
91511b26
ER
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
275s:%lang(C) ::' >> $MO_NAME
276
2475a48e 277# kde
a65ff95c
ER
278(
279 if [ "$ALL_NAME" ]; then
c99222d1 280 grep -F $NAME __find.dirs
a65ff95c
ER
281 else
282 cat __find.dirs
283 fi
284) | sed '
6b3f3313
JB
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
288s:%lang(C) ::' >> $MO_NAME
d26ea5ec 289
21e8065a 290# OMF
8542f272
MB
291(
292 if [ "$ALL_NAME" ]; then
c99222d1 293 grep -F $NAME __find.dirs
8542f272
MB
294 else
295 cat __find.dirs
296 fi
297) | sed '
6b3f3313
JB
298'"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
299'"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
300/^[^%]/d
301s:%lang(C) ::' >> $MO_NAME
8542f272 302
21e8065a
ER
303# Django
304cat __find.dirs | sed -r -e '
305'"$DJANGO"'s:(.+/share/python.+/locale/)([^/@]+)(@quot|@boldquot)?(@[^/]*)?$:%lang(\2\4) \1\2\3\4:
306/^[^%]/d
307s:%lang(C) ::' >> $MO_NAME
308
c99222d1 309if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
68d353c2 310 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
401c60fa 311 exit 1
d26ea5ec 312fi
fbbbe492
ER
313
314if [ "$APPEND" ]; then
315 cat $MO_NAME >> $OUTPUT
316 rm -f $MO_NAME
317else
318 mv -f $MO_NAME $OUTPUT
319fi
This page took 0.094026 seconds and 4 git commands to generate.