]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-find-lang
- use popt 1.10.8, db 4.5.20
[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   --all-name            match all package/domain names
53   --without-mo          skip *.mo locale files
54 EOF
55 exit 1
56 }
57
58 if [ -z "$1" ]; then
59         usage
60 elif [ $1 = / ]; then
61         echo >&2 "$PROG: expects non-/ argument for '$1'"
62         exit 1
63 elif [ ! -d $1 ]; then
64         echo >&2 "$PROG: $1: No such directory"
65         exit 1
66 else
67         TOP_DIR="${1%/}"
68 fi
69 shift
70
71 if [ -z "$1" ]; then
72         usage
73 else
74         NAME=$1
75 fi
76 shift
77
78 GNOME='#'
79 KDE='#'
80 MO=''
81 MO_NAME=$NAME.lang
82 ALL_NAME='#'
83 NO_ALL_NAME=''
84 while test $# -gt 0 ; do
85     case "$1" in
86         --with-gnome)
87                 GNOME=''
88                 echo "$PROG: Enabling with GNOME"
89                 shift
90                 ;;
91         --with-kde)
92                 echo "$PROG: Enabling with KDE"
93                 KDE=''
94                 shift
95                 ;;
96         --without-mo)
97                 echo "$PROG: Disabling .mo files"
98                 MO='#'
99                 shift
100                 ;;
101         --all-name)
102                 echo "$PROG: Enabling with all names"
103                 ALL_NAME=''
104                 NO_ALL_NAME='#'
105                 shift
106                 ;;
107         * )
108                 MO_NAME=$1
109                 shift
110                 ;;
111     esac
112 done    
113
114 echo '%defattr(644,root,root,755)' > $MO_NAME
115
116 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
117         find $TOP_DIR -type f -name '*.mo' | xargs -r file | egrep -v ', 1 messages$' | \
118         sed -e '
119                 s/:.*//
120                 s:'"$TOP_DIR"'::' > __find.files
121 else
122         echo "$PROG: Using cached __find.files"
123 fi
124
125 (
126         if [ "$ALL_NAME" ]; then
127                 fgrep $NAME __find.files
128         else
129                 cat __find.files
130         fi
131 ) | sed '
132 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*\.mo$\):%lang(\2) \1\2\3:
133 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/]\+\)\(.*/'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
134 s:^\([^%].*\)::
135 s:%lang(C) ::
136 s:^\$::' | egrep -v '^$' >> $MO_NAME
137
138 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
139         find $TOP_DIR -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
140 else
141         echo "$PROG: Using cached __find.dirs"
142 fi
143
144 (
145         if [ "$ALL_NAME" ]; then
146                 fgrep $NAME __find.dirs
147         else
148                 cat __find.dirs
149         fi
150 ) | sed '
151 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
152 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/[a-zA-Z0-9.\_\-]/.\+\)::
153 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'\/\)\([^/]\+\):%lang(\2) \1\2:
154 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
155 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]/.\+\)::
156 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+\/\)\([^/]\+\):%lang(\2) \1\2:
157 s:%lang(.*) .*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+/.*::
158 s:^\([^%].*\)::
159 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
160
161 (
162         if [ "$ALL_NAME" ]; then
163                 fgrep $NAME __find.dirs
164         else
165                 cat __find.dirs
166         fi
167 ) | sed '
168 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
169 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
170 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
171 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
172 s:^\([^%].*\)::
173 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
174
175 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
176         echo 'Error: international files not found !'
177         exit 1
178 fi
This page took 0.054745 seconds and 3 git commands to generate.