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