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