]> git.pld-linux.org Git - packages/rpm-build-macros.git/blob - rpm-find-lang
- expand revision
[packages/rpm-build-macros.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 REVISION='$Revision$'
39
40 usage () {
41 cat <<EOF
42
43 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
44
45 where TOP_DIR is
46 the 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.
48 PACKAGE_NAME is the %{name} of the package. This should also be
49 the basename of the .mo files.  the output is written to
50 PACKAGE_NAME.lang unless \$3 is given in which case output is written
51 to \$3.
52 Additional options:
53   --with-gnome          find GNOME help files
54   --with-kde            find KDE help files
55   --with-omf            find OMF files
56   --all-name            match all package/domain names
57   --without-mo          skip *.mo locale files
58 EOF
59 exit 1
60 }
61
62 if [ -z "$1" ]; then
63         usage
64 elif [ $1 = / ]; then
65         echo >&2 "$PROG: expects non-/ argument for '$1'"
66         exit 1
67 elif [ ! -d $1 ]; then
68         echo >&2 "$PROG: $1: No such directory"
69         exit 1
70 else
71         TOP_DIR="${1%/}"
72 fi
73 shift
74
75 if [ -z "$1" ]; then
76         usage
77 else
78         NAME=$1
79 fi
80 shift
81
82 GNOME='#'
83 KDE='#'
84 OMF='#'
85 MO=''
86 MO_NAME=$NAME.lang
87 ALL_NAME='#'
88 NO_ALL_NAME=''
89 while test $# -gt 0 ; do
90     case "$1" in
91         --with-gnome)
92                 GNOME=''
93                 echo "$PROG: Enabling with GNOME"
94                 shift
95                 ;;
96         --with-kde)
97                 echo "$PROG: Enabling with KDE"
98                 KDE=''
99                 shift
100                 ;;
101         --with-omf)
102                 echo "$PROG: Enabling with OMF"
103                 OMF=''
104                 shift
105                 ;;
106         --without-mo)
107                 echo "$PROG: Disabling .mo files"
108                 MO='#'
109                 shift
110                 ;;
111         --all-name)
112                 echo "$PROG: Enabling with all names"
113                 ALL_NAME=''
114                 NO_ALL_NAME='#'
115                 shift
116                 ;;
117         * )
118                 MO_NAME=$1
119                 shift
120                 ;;
121     esac
122 done    
123
124 echo '%defattr(644,root,root,755)' > $MO_NAME
125
126 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
127         find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
128         sed -e '
129                 /, 1 messages$/d
130                 s/:.*//
131                 s:'"$TOP_DIR"'::' > __find.files
132 else
133         echo "$PROG: Using cached __find.files"
134 fi
135
136 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
137         find $TOP_DIR -type f -name '*.omf' | \
138         sed -e '
139                 s:'"$TOP_DIR"'::' > __omf.files
140 else
141         echo "$PROG: Using cached __omf.files"
142 fi
143
144 (
145         if [ "$ALL_NAME" ]; then
146                 fgrep $NAME __find.files
147         else
148                 cat __find.files
149         fi
150 ) | sed '
151 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
152 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
153 /^[^%]/d
154 s:%lang(C) ::' >> $MO_NAME
155
156 (
157         if [ "$ALL_NAME" ]; then
158                 fgrep $NAME __omf.files
159         else
160                 cat __omf.files
161         fi
162 ) | sed '
163 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
164 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
165 /^[^%]/d
166 s:%lang(C) ::' >> $MO_NAME
167
168 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
169         find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
170 else
171         echo "$PROG: Using cached __find.dirs"
172 fi
173
174 (
175         if [ "$ALL_NAME" ]; then
176                 fgrep $NAME __find.dirs
177         else
178                 cat __find.dirs
179         fi
180 ) | sed '
181 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
182 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
183 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
184 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
185 /^[^%]/d
186 s:%lang(C) ::' >> $MO_NAME
187
188 (
189         if [ "$ALL_NAME" ]; then
190                 fgrep $NAME __find.dirs
191         else
192                 cat __find.dirs
193         fi
194 ) | sed '
195 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
196 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
197 /^[^%]/d
198 s:%lang(C) ::' >> $MO_NAME
199
200 (
201         if [ "$ALL_NAME" ]; then
202                 fgrep $NAME __find.dirs
203         else
204                 cat __find.dirs
205         fi
206 ) | sed '
207 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
208 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
209 /^[^%]/d
210 s:%lang(C) ::' >> $MO_NAME
211
212 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
213         echo >&2 "Error: international files not found for $NAME!"
214         exit 1
215 fi
This page took 0.041495 seconds and 4 git commands to generate.