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