]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-find-lang
- typo
[packages/rpm.git] / rpm-find-lang
1 #!/bin/sh
2 # $Id$
3
4 # findlang - 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   --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 MO=''
87 OUTPUT=$NAME.lang
88 ALL_NAME='#'
89 NO_ALL_NAME=''
90 APPEND=''
91 while test $# -gt 0 ; do
92     case "$1" in
93         --with-gnome)
94                 GNOME=''
95                 echo "$PROG: Enabling with GNOME"
96                 shift
97                 ;;
98         --with-kde)
99                 echo "$PROG: Enabling with KDE"
100                 KDE=''
101                 shift
102                 ;;
103         --with-omf)
104                 echo "$PROG: Enabling with OMF"
105                 OMF=''
106                 shift
107                 ;;
108         --without-mo)
109                 echo "$PROG: Disabling .mo files"
110                 MO='#'
111                 shift
112                 ;;
113         --all-name)
114                 echo "$PROG: Enabling with all names"
115                 ALL_NAME=''
116                 NO_ALL_NAME='#'
117                 shift
118                 ;;
119         -o)
120                 shift
121                 OUTPUT=$1
122                 shift
123                 ;;
124         -a)
125                 shift
126                 OUTPUT=$1
127                 APPEND='>'
128                 shift
129                 ;;
130         *)
131                 OUTPUT=$1
132                 shift
133                 ;;
134     esac
135 done
136
137 echo "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
138
139 MO_NAME=.$OUTPUT.tmp~
140 echo '%defattr(644,root,root,755)' > $MO_NAME
141
142 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
143         find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
144         sed -e '
145                 /, 1 messages$/d
146                 s/:.*//
147                 s:'"$TOP_DIR"'::' > __find.files
148 else
149         echo "$PROG: Using cached __find.files"
150 fi
151
152 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
153         find $TOP_DIR -type f -name '*.omf' | \
154         sed -e '
155                 s:'"$TOP_DIR"'::' > __omf.files
156 else
157         echo "$PROG: Using cached __omf.files"
158 fi
159
160 (
161         if [ "$ALL_NAME" ]; then
162                 fgrep $NAME __find.files
163         else
164                 cat __find.files
165         fi
166 ) | sed '
167 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
168 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
169 /^[^%]/d
170 s:%lang(C) ::' >> $MO_NAME
171
172 (
173         if [ "$ALL_NAME" ]; then
174                 fgrep $NAME __omf.files
175         else
176                 cat __omf.files
177         fi
178 ) | sed '
179 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
180 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
181 /^[^%]/d
182 s:%lang(C) ::' >> $MO_NAME
183
184 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
185         find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
186 else
187         echo "$PROG: Using cached __find.dirs"
188 fi
189
190 (
191         if [ "$ALL_NAME" ]; then
192                 fgrep $NAME __find.dirs
193         else
194                 cat __find.dirs
195         fi
196 ) | sed '
197 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
198 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
199 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
200 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
201 /^[^%]/d
202 s:%lang(C) ::' >> $MO_NAME
203
204 (
205         if [ "$ALL_NAME" ]; then
206                 fgrep $NAME __find.dirs
207         else
208                 cat __find.dirs
209         fi
210 ) | sed '
211 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
212 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
213 /^[^%]/d
214 s:%lang(C) ::' >> $MO_NAME
215
216 (
217         if [ "$ALL_NAME" ]; then
218                 fgrep $NAME __find.dirs
219         else
220                 cat __find.dirs
221         fi
222 ) | sed '
223 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
224 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
225 /^[^%]/d
226 s:%lang(C) ::' >> $MO_NAME
227
228 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
229         echo >&2 "$PROG: Error: international files not found for '$NAME'!"
230         exit 1
231 fi
232
233 if [ "$APPEND" ]; then
234         cat $MO_NAME >> $OUTPUT
235         rm -f $MO_NAME
236 else
237         mv -f $MO_NAME $OUTPUT
238 fi
This page took 0.037665 seconds and 3 git commands to generate.