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