]> git.pld-linux.org Git - packages/rpm-build-macros.git/blob - rpm-find-lang
- v1.654: extend _noautoreq with language specific macros
[packages/rpm-build-macros.git] / rpm-find-lang
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 # 2006-08-28 Elan Ruusamäe <glen@pld-linux.org>
18 #   * fixed --all-name which got broken with last change.
19 # 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
20 #   * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
21 # 2001-01-08 Micha³ Kochanowicz <mkochano@pld.org.pl>
22 #   * --all-name support for KDE.
23 # 2000-11-28 Rafa³ Cygnarowski <pascalek@pld.org.pl>
24 #   * next simple rule for KDE
25 # 2000-11-12 Rafa³ Cygnarowski <pascalek@pld.org.pl>
26 #   * simple rules for KDE help files
27 # 2000-06-05 Micha³ Kochanowicz <mkochano@pld.org.pl>
28 #   * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
29 #     no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
30 # 2000-04-17 Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
31 #   * exit 1 when no files found
32 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
33 #   * added support for GNOME help files
34 #   * start support for KDE help files
35
36 PROG=${0##*/}
37 VERSION=1.35
38
39 usage () {
40 cat <<EOF
41 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
42
43 where TOP_DIR is
44 the top of the tree containing the files to be processed--should be
45 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
46 PACKAGE_NAME is the %{name} of the package. This should also be
47 the basename of the .mo files.  the output is written to
48 PACKAGE_NAME.lang unless \$3 is given in which case output is written
49 to \$3.
50 Additional options:
51   --with-gnome          find GNOME help files
52   --with-kde            find KDE help files
53   --with-omf            find OMF files
54   --with-qm                     find QT .qm files
55   --all-name            match all package/domain names
56   --without-mo          skip *.mo locale files
57   -o NAME                       output will be saved to NAME
58   -a NAME                       output will be appended to NAME
59 EOF
60 exit 1
61 }
62
63 if [ -z "$1" ]; then
64         usage
65 elif [ $1 = / ]; then
66         echo >&2 "$PROG: expects non-/ argument for '$1'"
67         exit 1
68 elif [ ! -d $1 ]; then
69         echo >&2 "$PROG: $1: No such directory"
70         exit 1
71 else
72         TOP_DIR="${1%/}"
73 fi
74 shift
75
76 if [ -z "$1" ]; then
77         usage
78 else
79         NAME=$1
80 fi
81 shift
82
83 GNOME='#'
84 KDE='#'
85 OMF='#'
86 QM='#'
87 MO=''
88 OUTPUT=$NAME.lang
89 ALL_NAME='#'
90 NO_ALL_NAME=''
91 APPEND=''
92 while test $# -gt 0; do
93     case "$1" in
94         --with-gnome)
95                 GNOME=''
96                 echo "$PROG: Enabling with GNOME"
97                 shift
98                 ;;
99         --with-kde)
100                 echo "$PROG: Enabling with KDE"
101                 KDE=''
102                 shift
103                 ;;
104         --with-omf)
105                 echo "$PROG: Enabling with OMF"
106                 OMF=''
107                 shift
108                 ;;
109         --with-qm)
110                 echo "$PROG: Enabling with Qt QM"
111                 QM=''
112                 shift
113                 ;;
114         --without-mo)
115                 echo "$PROG: Disabling .mo files"
116                 MO='#'
117                 shift
118                 ;;
119         --all-name)
120                 echo "$PROG: Enabling with all names"
121                 ALL_NAME=''
122                 NO_ALL_NAME='#'
123                 shift
124                 ;;
125         -o)
126                 shift
127                 OUTPUT=$1
128                 shift
129                 ;;
130         -a)
131                 shift
132                 OUTPUT=$1
133                 APPEND='>'
134                 shift
135                 ;;
136         *)
137                 OUTPUT=$1
138                 shift
139                 ;;
140     esac
141 done
142
143 echo "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
144
145 MO_NAME=.$OUTPUT.tmp~
146 echo '%defattr(644,root,root,755)' > $MO_NAME
147
148 # .mo
149 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
150         find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
151         sed -e '
152                 /, 1 messages$/d
153                 s/:.*//
154                 s:'"$TOP_DIR"'::' > __find.files
155 else
156         echo "$PROG: Using cached __find.files"
157 fi
158
159 # .omf
160 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
161         find $TOP_DIR -type f -name '*.omf' | \
162         sed -e '
163                 s:'"$TOP_DIR"'::' > __omf.files
164 else
165         echo "$PROG: Using cached __omf.files"
166 fi
167
168 # .qm
169 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
170         find $TOP_DIR -type f -name '*.qm' | \
171         sed -e '
172                 s:'"$TOP_DIR"'::' > __qm.files
173 else
174         echo "$PROG: Using cached __qm.files"
175 fi
176
177 # .mo
178 (
179         if [ "$ALL_NAME" ]; then
180                 fgrep $NAME __find.files
181         else
182                 cat __find.files
183         fi
184 ) | sed '
185 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
186 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
187 /^[^%]/d
188 s:%lang(C) ::' >> $MO_NAME
189
190 # .omf
191 (
192         if [ "$ALL_NAME" ]; then
193                 fgrep $NAME __omf.files
194         else
195                 cat __omf.files
196         fi
197 ) | sed '
198 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
199 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
200 /^[^%]/d
201 s:%lang(C) ::' >> $MO_NAME
202
203 # .qm
204 (
205         if [ "$ALL_NAME" ]; then
206                 fgrep $NAME __qm.files
207         else
208                 cat __qm.files
209         fi
210 ) | sed '
211 '"$ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.qm$\):%lang(\2\4) \1\2\3\4\5:
212 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
213 /^[^%]/d
214 s:%lang(C) ::' >> $MO_NAME
215
216 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
217         find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
218 else
219         echo "$PROG: Using cached __find.dirs"
220 fi
221
222 # gnome
223 (
224         if [ "$ALL_NAME" ]; then
225                 fgrep $NAME __find.dirs
226         else
227                 cat __find.dirs
228         fi
229 ) | sed '
230 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
231 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
232 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
233 '"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
234 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
235 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
236 /^[^%]/d
237 s:%lang(C) ::' >> $MO_NAME
238
239 # kde
240 (
241         if [ "$ALL_NAME" ]; then
242                 fgrep $NAME __find.dirs
243         else
244                 cat __find.dirs
245         fi
246 ) | sed '
247 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
248 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
249 /^[^%]/d
250 s:%lang(C) ::' >> $MO_NAME
251
252 (
253         if [ "$ALL_NAME" ]; then
254                 fgrep $NAME __find.dirs
255         else
256                 cat __find.dirs
257         fi
258 ) | sed '
259 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
260 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
261 /^[^%]/d
262 s:%lang(C) ::' >> $MO_NAME
263
264 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
265         echo >&2 "$PROG: Error: international files not found for '$NAME'!"
266         exit 1
267 fi
268
269 if [ "$APPEND" ]; then
270         cat $MO_NAME >> $OUTPUT
271         rm -f $MO_NAME
272 else
273         mv -f $MO_NAME $OUTPUT
274 fi
This page took 0.054836 seconds and 3 git commands to generate.